diff --git a/QtNovelDesc.pro.user b/QtNovelDesc.pro.user index 8fe42db..6bce140 100644 --- a/QtNovelDesc.pro.user +++ b/QtNovelDesc.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/WordsIDE/mainwindow.cpp b/WordsIDE/mainwindow.cpp index 33fa5ec..daca349 100644 --- a/WordsIDE/mainwindow.cpp +++ b/WordsIDE/mainwindow.cpp @@ -26,6 +26,7 @@ using namespace MakeTools; using namespace Parse::Result; using namespace Components; using namespace Core; +using namespace Tools; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), @@ -531,62 +532,6 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event) -Run::Run(bool manual_flag, std::function judge, std::function execution) - : manual(manual_flag), judgement(judge), execution(execution){} - -void Run::exec() -{ - if(!manual) - execution(judgement()); -} - -StatusSyncCore::StatusSyncCore(QObject *p) - : QObject(p){} - -void StatusSyncCore::registerWidgetSync(QWidget *tar, std::function proc) -{ - widget_trigger_map[tar] = proc; -} - -void StatusSyncCore::registerActionSync(QAction *tar, std::function proc) -{ - action_trigger_map[tar] = proc; -} - -void StatusSyncCore::registerAutoRun(std::function judge, std::function exec) -{ - auto run = new Run(false, judge, exec); - alltriggers << run; -} - -Run *StatusSyncCore::registerManualRun(std::function judge, std::function exec) -{ - auto run = new Run(true, judge, exec); - alltriggers << run; - return run; -} - -void StatusSyncCore::sync() -{ - for(auto &it : widget_trigger_map.keys()){ - auto status = widget_trigger_map[it](); - if(it->isEnabled() != status) - it->setEnabled(status); - } - - for(auto &it : action_trigger_map.keys()){ - auto status = action_trigger_map[it](); - if(it->isEnabled() != status) - it->setEnabled(status); - } - - for(auto &act : alltriggers){ - act->exec(); - } -} - - - diff --git a/WordsIDE/mainwindow.h b/WordsIDE/mainwindow.h index 7b66d88..a8cf670 100644 --- a/WordsIDE/mainwindow.h +++ b/WordsIDE/mainwindow.h @@ -16,39 +16,7 @@ #include "ContentPresent.h" #include "storyboardspresent.h" #include "storyconceptspresent.h" - - -class Run -{ -public: - Run(bool manual_flag, std::function judge, std::function execution); - - void exec(); - -private: - bool manual; - std::function judgement; - std::function execution; -}; - -class StatusSyncCore : public QObject -{ -public: - explicit StatusSyncCore(QObject *p = nullptr); - virtual ~StatusSyncCore() = default; - - - void registerWidgetSync(QWidget* tar, std::function proc); - void registerActionSync(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; -}; +#include "tools.h" class MainWindow : public QMainWindow { @@ -62,7 +30,7 @@ public: private: Core::AppCore *const app_core; - StatusSyncCore *const sync_kernel; + Tools::StatusSyncCore *const sync_kernel; QSplitter *const horizontal_split; QSplitter *const vertical_split; diff --git a/WordsIDE/storychainspresent.cpp b/WordsIDE/storychainspresent.cpp index 76385bc..6f444a5 100644 --- a/WordsIDE/storychainspresent.cpp +++ b/WordsIDE/storychainspresent.cpp @@ -7,44 +7,48 @@ using namespace Components; using namespace Parse; using namespace Parse::Result; +using namespace Tools; StoryChainsPresent::StoryChainsPresent(Core::AppCore *core, QWidget *parent) : QWidget(parent), core_ins(core), model_base(new QStandardItemModel(this)), - tree_view(new QTreeView(this)), details_show(new QPlainTextEdit(this)) + tree_view(new QTreeView(this)), details_show(new QPlainTextEdit(this)), + sync_tools(new ModelSyncs( + model_base, + [](DesNode *const &d, QStandardItem *it)->bool +{ return static_cast(d)->name().first() == it->text();}, + [](DesNode *const &d, QStandardItem *it) +{ it->setText(static_cast(d)->name().first()); })) { - tree_view->setModel(model_base); - tree_view->setHeaderHidden(true); +tree_view->setModel(model_base); +tree_view->setHeaderHidden(true); - auto layoutx = new QVBoxLayout(this); - layoutx->setMargin(0); - auto split = new QSplitter(Qt::Vertical, this); - layoutx->addWidget(split); - split->addWidget(tree_view); - split->addWidget(details_show); - details_show->setReadOnly(true); +auto layoutx = new QVBoxLayout(this); +layoutx->setMargin(0); +auto split = new QSplitter(Qt::Vertical, this); +layoutx->addWidget(split); +split->addWidget(tree_view); +split->addWidget(details_show); +details_show->setReadOnly(true); - connect(tree_view, &QTreeView::clicked, this, &StoryChainsPresent::action_details_show); - connect(tree_view, &QTreeView::doubleClicked, this,&StoryChainsPresent::click_to); +connect(tree_view, &QTreeView::clicked, this, &StoryChainsPresent::action_details_show); +connect(tree_view, &QTreeView::doubleClicked, this,&StoryChainsPresent::click_to); } void StoryChainsPresent::refresh() { - model_base->clear(); - auto list = core_ins->parseCore()->allStoryChains(); - for(auto &chain : list){ - auto chain_node = new QStandardItem(static_cast(chain)->name()[0]); - chain_node->setEditable(false); - model_base->appendRow(chain_node); - - auto children = chain->children(); - for(auto &point : children){ - if(point->typeValue() == NODE_STORYPOINT){ - auto point_node = new QStandardItem(static_cast(point)->name()[0]); - point_node->setEditable(false); - chain_node->appendRow(point_node); + sync_tools->presentSync([this](DesNode *p)->QList{ + if(p){ + QList retv; + for(auto &point : p->children()){ + if(point->typeValue() == NODE_STORYPOINT){ + retv << point; + } } + return retv; } - } + else + return this->core_ins->parseCore()->allStoryChains(); + }); } void StoryChainsPresent::action_details_show(const QModelIndex &curr) diff --git a/WordsIDE/storychainspresent.h b/WordsIDE/storychainspresent.h index 5a8f1d1..426fbab 100644 --- a/WordsIDE/storychainspresent.h +++ b/WordsIDE/storychainspresent.h @@ -2,6 +2,7 @@ #define STORYCHAINSPRESENT_H #include "appcore.h" +#include "tools.h" #include #include @@ -26,6 +27,7 @@ namespace Components { QStandardItemModel *const model_base; QTreeView *const tree_view; QPlainTextEdit *const details_show; + Tools::ModelSyncs *const sync_tools; void action_details_show(const QModelIndex &curr); diff --git a/WordsIDE/tools.cpp b/WordsIDE/tools.cpp index 2fa7e97..c0f4cc7 100644 --- a/WordsIDE/tools.cpp +++ b/WordsIDE/tools.cpp @@ -1 +1,62 @@ #include "tools.h" +#include +#include + +using namespace Tools; + + + +Run::Run(bool manual_flag, std::function judge, std::function execution) + : manual(manual_flag), judgement(judge), execution(execution){} + +void Run::exec() +{ + if(!manual) + execution(judgement()); +} + +StatusSyncCore::StatusSyncCore(QObject *p) + : QObject(p){} + +void StatusSyncCore::registerWidgetSync(QWidget *tar, std::function proc) +{ + widget_trigger_map[tar] = proc; +} + +void StatusSyncCore::registerActionSync(QAction *tar, std::function proc) +{ + action_trigger_map[tar] = proc; +} + +void StatusSyncCore::registerAutoRun(std::function judge, std::function exec) +{ + auto run = new Run(false, judge, exec); + alltriggers << run; +} + +Run *StatusSyncCore::registerManualRun(std::function judge, std::function exec) +{ + auto run = new Run(true, judge, exec); + alltriggers << run; + return run; +} + +void StatusSyncCore::sync() +{ + for(auto &it : widget_trigger_map.keys()){ + auto status = widget_trigger_map[it](); + if(it->isEnabled() != status) + it->setEnabled(status); + } + + for(auto &it : action_trigger_map.keys()){ + auto status = action_trigger_map[it](); + if(it->isEnabled() != status) + it->setEnabled(status); + } + + for(auto &act : alltriggers){ + act->exec(); + } +} + diff --git a/WordsIDE/tools.h b/WordsIDE/tools.h index 47a434f..3c29635 100644 --- a/WordsIDE/tools.h +++ b/WordsIDE/tools.h @@ -7,6 +7,38 @@ namespace Tools { + class Run + { + public: + Run(bool manual_flag, std::function judge, std::function execution); + + void exec(); + + private: + bool manual; + std::function judgement; + std::function execution; + }; + + class StatusSyncCore : public QObject + { + public: + explicit StatusSyncCore(QObject *p = nullptr); + virtual ~StatusSyncCore() = default; + + + void registerWidgetSync(QWidget* tar, std::function proc); + void registerActionSync(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; + }; + template class ModelSyncs {