QtNovelUI/WordsIDE/tools.h

46 lines
1.3 KiB
C
Raw Normal View History

2022-11-29 03:47:12 +00:00
#ifndef COMNTOOLS_H
#define COMNTOOLS_H
#include <QAction>
2022-11-29 03:47:12 +00:00
#include <QStandardItemModel>
#include <functional>
namespace Tools {
2023-03-11 04:48:34 +00:00
class Run {
public:
Run(bool manual_flag, std::function<bool()> judge,
std::function<void(bool)> execution);
2022-12-01 13:54:04 +00:00
void exec();
2023-03-11 04:48:34 +00:00
private:
2022-12-01 13:54:04 +00:00
bool manual;
std::function<bool()> judgement;
std::function<void(bool)> execution;
};
2023-03-11 04:48:34 +00:00
class StatusSyncCore : public QObject {
public:
2022-12-01 13:54:04 +00:00
explicit StatusSyncCore(QObject *p = nullptr);
virtual ~StatusSyncCore() = default;
2023-03-17 13:58:38 +00:00
void widgetEnableSync(QWidget *tar, std::function<bool()> proc);
void actionEnableSync(QAction *tar, std::function<bool()> proc);
void actionCheckSync(QAction *tar, std::function<bool()> proc);
void registerTrigger(std::function<bool()> judge,
2023-03-11 04:48:34 +00:00
std::function<void(bool)> exec);
Run *registerManualRun(std::function<bool()> judge,
std::function<void(bool)> exec);
2022-12-01 13:54:04 +00:00
void sync();
2023-03-11 04:48:34 +00:00
private:
QHash<QWidget *, std::function<bool()>> widget_trigger_map;
QHash<QAction *, std::function<bool()>> action_trigger_map;
QList<Run *> alltriggers;
2022-12-01 13:54:04 +00:00
};
2023-03-11 04:48:34 +00:00
} // namespace Tools
2022-11-29 03:47:12 +00:00
#endif // COMNTOOLS_H