diff --git a/WordsIDE/tools.h b/WordsIDE/tools.h index ed6a50a..479e333 100644 --- a/WordsIDE/tools.h +++ b/WordsIDE/tools.h @@ -7,62 +7,69 @@ namespace Tools { - class Run - { - public: - Run(bool manual_flag, std::function judge, std::function execution); + class Run { + public: + Run(bool manual_flag, std::function judge, + std::function execution); void exec(); - private: + private: bool manual; std::function judgement; std::function execution; }; - class StatusSyncCore : public QObject - { - public: + class StatusSyncCore : public QObject { + public: explicit StatusSyncCore(QObject *p = nullptr); virtual ~StatusSyncCore() = default; - - void widgetSync(QWidget* tar, std::function proc); - void actionSync(QAction* tar, std::function proc); - void registerAutoRun(std::function judge, std::function exec); - Run* registerManualRun(std::function judge, std::function exec); + void widgetSync(QWidget *tar, std::function proc); + void actionSync(QAction *tar, std::function proc); + void registerAutoRun(std::function judge, + std::function exec); + Run *registerManualRun(std::function judge, + std::function exec); void sync(); - private: - QHash> widget_trigger_map; - QHash> action_trigger_map; - QList alltriggers; + private: + QHash> widget_trigger_map; + QHash> action_trigger_map; + QList alltriggers; }; - template - class ModelSyncs - { - public: - ModelSyncs(QStandardItemModel *model_base, std::function _equal, - std::function sync_proc) - : model_present(model_base), sync_process(sync_proc), compare_process(_equal){} + template class TreeSyncs { + public: + TreeSyncs( + QStandardItemModel *model_base, + std::function _equal, + std::function sync_proc) + : model_present(model_base), sync_process(sync_proc), + compare_process(_equal) {} - void presentSync(std::function(const BaseType &pnode)> items_peak) - { + void presentSync( + std::function(const BaseType &pnode)> items_peak) { auto default_pdata = BaseType(); auto datas = items_peak(default_pdata); - Operate::OpStream([this](int &cnt, int idx)->QStandardItem*{ - cnt = model_present->rowCount(); - return model_present->item(idx); - }).filter([&datas, this](QStandardItem *const &it)->bool{ - for(auto &d : datas) - if(compare_process(d, it)) - return false; - return true; - }).forEach([this](QStandardItem *const &it){ - model_present->removeRow(it->row()); - }); + Operate::OpStream( + [this](int &cnt, int idx) -> QStandardItem * { + cnt = model_present->rowCount(); + if (cnt <= 0) + return nullptr; + + return model_present->item(idx); + }) + .filter([&datas, this](QStandardItem *const &it) -> bool { + for (auto &d : datas) + if (compare_process(d, it)) + return false; + return true; + }) + .forEach([this](QStandardItem *const &it) { + model_present->removeRow(it->row()); + }); for (auto idx = 0; idx < datas.size(); ++idx) { if (idx >= model_present->rowCount()) { @@ -79,28 +86,31 @@ namespace Tools { } } - - - private: + private: QStandardItemModel *model_present; std::function sync_process; - std::function compare_process; + std::function + compare_process; - void layer_items_sync(const BaseType &data, QStandardItem *pnode, - std::function(const BaseType &pnode)> items_peak){ + void layer_items_sync( + const BaseType &data, QStandardItem *pnode, + std::function(const BaseType &pnode)> items_peak) { auto datas = items_peak(data); - Operate::OpStream([pnode](int &cnt, int idx)->QStandardItem*{ - cnt = pnode->rowCount(); - return pnode->child(idx); - }).filter([&datas, this](QStandardItem *const &it)->bool{ - for(auto &d : datas) - if(compare_process(d, it)) - return false; - return true; - }).forEach([pnode](QStandardItem *const &it){ - pnode->removeRow(it->row()); - }); + Operate::OpStream( + [pnode](int &cnt, int idx) -> QStandardItem * { + cnt = pnode->rowCount(); + return pnode->child(idx); + }) + .filter([&datas, this](QStandardItem *const &it) -> bool { + for (auto &d : datas) + if (compare_process(d, it)) + return false; + return true; + }) + .forEach([pnode](QStandardItem *const &it) { + pnode->removeRow(it->row()); + }); for (auto idx = 0; idx < datas.size(); ++idx) { if (idx >= pnode->rowCount()) { @@ -117,7 +127,6 @@ namespace Tools { } } }; -} - +} // namespace Tools #endif // COMNTOOLS_H