格式整理
This commit is contained in:
parent
6def2aa88e
commit
fc7a6ba2e0
121
WordsIDE/tools.h
121
WordsIDE/tools.h
|
@ -7,62 +7,69 @@
|
||||||
|
|
||||||
namespace Tools {
|
namespace Tools {
|
||||||
|
|
||||||
class Run
|
class Run {
|
||||||
{
|
public:
|
||||||
public:
|
Run(bool manual_flag, std::function<bool()> judge,
|
||||||
Run(bool manual_flag, std::function<bool()> judge, std::function<void(bool)> execution);
|
std::function<void(bool)> execution);
|
||||||
|
|
||||||
void exec();
|
void exec();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool manual;
|
bool manual;
|
||||||
std::function<bool()> judgement;
|
std::function<bool()> judgement;
|
||||||
std::function<void(bool)> execution;
|
std::function<void(bool)> execution;
|
||||||
};
|
};
|
||||||
|
|
||||||
class StatusSyncCore : public QObject
|
class StatusSyncCore : public QObject {
|
||||||
{
|
public:
|
||||||
public:
|
|
||||||
explicit StatusSyncCore(QObject *p = nullptr);
|
explicit StatusSyncCore(QObject *p = nullptr);
|
||||||
virtual ~StatusSyncCore() = default;
|
virtual ~StatusSyncCore() = default;
|
||||||
|
|
||||||
|
void widgetSync(QWidget *tar, std::function<bool()> proc);
|
||||||
void widgetSync(QWidget* tar, std::function<bool()> proc);
|
void actionSync(QAction *tar, std::function<bool()> proc);
|
||||||
void actionSync(QAction* tar, std::function<bool()> proc);
|
void registerAutoRun(std::function<bool()> judge,
|
||||||
void registerAutoRun(std::function<bool()> judge, std::function<void(bool)> exec);
|
std::function<void(bool)> exec);
|
||||||
Run* registerManualRun(std::function<bool()> judge, std::function<void (bool)> exec);
|
Run *registerManualRun(std::function<bool()> judge,
|
||||||
|
std::function<void(bool)> exec);
|
||||||
void sync();
|
void sync();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<QWidget*, std::function<bool()>> widget_trigger_map;
|
QHash<QWidget *, std::function<bool()>> widget_trigger_map;
|
||||||
QHash<QAction*, std::function<bool()>> action_trigger_map;
|
QHash<QAction *, std::function<bool()>> action_trigger_map;
|
||||||
QList<Run*> alltriggers;
|
QList<Run *> alltriggers;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class BaseType>
|
template <class BaseType> class TreeSyncs {
|
||||||
class ModelSyncs
|
public:
|
||||||
{
|
TreeSyncs(
|
||||||
public:
|
QStandardItemModel *model_base,
|
||||||
ModelSyncs(QStandardItemModel *model_base, std::function<bool(const BaseType &n, QStandardItem *p)> _equal,
|
std::function<bool(const BaseType &n, QStandardItem *p)> _equal,
|
||||||
std::function<void(const BaseType &n, QStandardItem *p)> sync_proc)
|
std::function<void(const BaseType &n, QStandardItem *p)> sync_proc)
|
||||||
: model_present(model_base), sync_process(sync_proc), compare_process(_equal){}
|
: model_present(model_base), sync_process(sync_proc),
|
||||||
|
compare_process(_equal) {}
|
||||||
|
|
||||||
void presentSync(std::function<QList<BaseType>(const BaseType &pnode)> items_peak)
|
void presentSync(
|
||||||
{
|
std::function<QList<BaseType>(const BaseType &pnode)> items_peak) {
|
||||||
auto default_pdata = BaseType();
|
auto default_pdata = BaseType();
|
||||||
auto datas = items_peak(default_pdata);
|
auto datas = items_peak(default_pdata);
|
||||||
|
|
||||||
Operate::OpStream<QStandardItem*>([this](int &cnt, int idx)->QStandardItem*{
|
Operate::OpStream<QStandardItem *>(
|
||||||
cnt = model_present->rowCount();
|
[this](int &cnt, int idx) -> QStandardItem * {
|
||||||
return model_present->item(idx);
|
cnt = model_present->rowCount();
|
||||||
}).filter([&datas, this](QStandardItem *const &it)->bool{
|
if (cnt <= 0)
|
||||||
for(auto &d : datas)
|
return nullptr;
|
||||||
if(compare_process(d, it))
|
|
||||||
return false;
|
return model_present->item(idx);
|
||||||
return true;
|
})
|
||||||
}).forEach([this](QStandardItem *const &it){
|
.filter([&datas, this](QStandardItem *const &it) -> bool {
|
||||||
model_present->removeRow(it->row());
|
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) {
|
for (auto idx = 0; idx < datas.size(); ++idx) {
|
||||||
if (idx >= model_present->rowCount()) {
|
if (idx >= model_present->rowCount()) {
|
||||||
|
@ -79,28 +86,31 @@ namespace Tools {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
private:
|
|
||||||
QStandardItemModel *model_present;
|
QStandardItemModel *model_present;
|
||||||
std::function<void(const BaseType &n, QStandardItem *p)> sync_process;
|
std::function<void(const BaseType &n, QStandardItem *p)> sync_process;
|
||||||
std::function<bool(const BaseType &n, QStandardItem *p)> compare_process;
|
std::function<bool(const BaseType &n, QStandardItem *p)>
|
||||||
|
compare_process;
|
||||||
|
|
||||||
void layer_items_sync(const BaseType &data, QStandardItem *pnode,
|
void layer_items_sync(
|
||||||
std::function<QList<BaseType>(const BaseType &pnode)> items_peak){
|
const BaseType &data, QStandardItem *pnode,
|
||||||
|
std::function<QList<BaseType>(const BaseType &pnode)> items_peak) {
|
||||||
auto datas = items_peak(data);
|
auto datas = items_peak(data);
|
||||||
|
|
||||||
Operate::OpStream<QStandardItem*>([pnode](int &cnt, int idx)->QStandardItem*{
|
Operate::OpStream<QStandardItem *>(
|
||||||
cnt = pnode->rowCount();
|
[pnode](int &cnt, int idx) -> QStandardItem * {
|
||||||
return pnode->child(idx);
|
cnt = pnode->rowCount();
|
||||||
}).filter([&datas, this](QStandardItem *const &it)->bool{
|
return pnode->child(idx);
|
||||||
for(auto &d : datas)
|
})
|
||||||
if(compare_process(d, it))
|
.filter([&datas, this](QStandardItem *const &it) -> bool {
|
||||||
return false;
|
for (auto &d : datas)
|
||||||
return true;
|
if (compare_process(d, it))
|
||||||
}).forEach([pnode](QStandardItem *const &it){
|
return false;
|
||||||
pnode->removeRow(it->row());
|
return true;
|
||||||
});
|
})
|
||||||
|
.forEach([pnode](QStandardItem *const &it) {
|
||||||
|
pnode->removeRow(it->row());
|
||||||
|
});
|
||||||
|
|
||||||
for (auto idx = 0; idx < datas.size(); ++idx) {
|
for (auto idx = 0; idx < datas.size(); ++idx) {
|
||||||
if (idx >= pnode->rowCount()) {
|
if (idx >= pnode->rowCount()) {
|
||||||
|
@ -117,7 +127,6 @@ namespace Tools {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace Tools
|
||||||
|
|
||||||
|
|
||||||
#endif // COMNTOOLS_H
|
#endif // COMNTOOLS_H
|
||||||
|
|
Loading…
Reference in New Issue