storychainpresent懒加载

This commit is contained in:
玉宇清音 2022-12-01 21:54:04 +08:00
parent 04f6aaa3a5
commit c9d4b1374c
7 changed files with 129 additions and 117 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.15.0, 2022-11-29T01:19:02. -->
<!-- Written by QtCreator 4.15.0, 2022-12-01T15:03:57. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -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<bool ()> judge, std::function<void (bool)> 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<bool ()> proc)
{
widget_trigger_map[tar] = proc;
}
void StatusSyncCore::registerActionSync(QAction *tar, std::function<bool ()> proc)
{
action_trigger_map[tar] = proc;
}
void StatusSyncCore::registerAutoRun(std::function<bool ()> judge, std::function<void (bool)> exec)
{
auto run = new Run(false, judge, exec);
alltriggers << run;
}
Run *StatusSyncCore::registerManualRun(std::function<bool ()> judge, std::function<void (bool)> 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();
}
}

View File

@ -16,39 +16,7 @@
#include "ContentPresent.h"
#include "storyboardspresent.h"
#include "storyconceptspresent.h"
class Run
{
public:
Run(bool manual_flag, std::function<bool()> judge, std::function<void(bool)> execution);
void exec();
private:
bool manual;
std::function<bool()> judgement;
std::function<void(bool)> execution;
};
class StatusSyncCore : public QObject
{
public:
explicit StatusSyncCore(QObject *p = nullptr);
virtual ~StatusSyncCore() = default;
void registerWidgetSync(QWidget* tar, std::function<bool()> proc);
void registerActionSync(QAction* tar, std::function<bool()> proc);
void registerAutoRun(std::function<bool()> judge, std::function<void(bool)> exec);
Run* registerManualRun(std::function<bool()> judge, std::function<void (bool)> exec);
void sync();
private:
QHash<QWidget*, std::function<bool()>> widget_trigger_map;
QHash<QAction*, std::function<bool()>> action_trigger_map;
QList<Run*> 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;

View File

@ -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<DesNode*>(
model_base,
[](DesNode *const &d, QStandardItem *it)->bool
{ return static_cast<NamedNode*>(d)->name().first() == it->text();},
[](DesNode *const &d, QStandardItem *it)
{ it->setText(static_cast<NamedNode*>(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<NamedNode*>(chain)->name()[0]);
chain_node->setEditable(false);
model_base->appendRow(chain_node);
auto children = chain->children();
for(auto &point : children){
sync_tools->presentSync([this](DesNode *p)->QList<DesNode*>{
if(p){
QList<DesNode*> retv;
for(auto &point : p->children()){
if(point->typeValue() == NODE_STORYPOINT){
auto point_node = new QStandardItem(static_cast<NamedNode*>(point)->name()[0]);
point_node->setEditable(false);
chain_node->appendRow(point_node);
retv << point;
}
}
return retv;
}
else
return this->core_ins->parseCore()->allStoryChains();
});
}
void StoryChainsPresent::action_details_show(const QModelIndex &curr)

View File

@ -2,6 +2,7 @@
#define STORYCHAINSPRESENT_H
#include "appcore.h"
#include "tools.h"
#include <QPlainTextEdit>
#include <QStandardItemModel>
@ -26,6 +27,7 @@ namespace Components {
QStandardItemModel *const model_base;
QTreeView *const tree_view;
QPlainTextEdit *const details_show;
Tools::ModelSyncs<Parse::Result::DesNode*> *const sync_tools;
void action_details_show(const QModelIndex &curr);

View File

@ -1 +1,62 @@
#include "tools.h"
#include <QWidget>
#include <QAction>
using namespace Tools;
Run::Run(bool manual_flag, std::function<bool ()> judge, std::function<void (bool)> 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<bool ()> proc)
{
widget_trigger_map[tar] = proc;
}
void StatusSyncCore::registerActionSync(QAction *tar, std::function<bool ()> proc)
{
action_trigger_map[tar] = proc;
}
void StatusSyncCore::registerAutoRun(std::function<bool ()> judge, std::function<void (bool)> exec)
{
auto run = new Run(false, judge, exec);
alltriggers << run;
}
Run *StatusSyncCore::registerManualRun(std::function<bool ()> judge, std::function<void (bool)> 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();
}
}

View File

@ -7,6 +7,38 @@
namespace Tools {
class Run
{
public:
Run(bool manual_flag, std::function<bool()> judge, std::function<void(bool)> execution);
void exec();
private:
bool manual;
std::function<bool()> judgement;
std::function<void(bool)> execution;
};
class StatusSyncCore : public QObject
{
public:
explicit StatusSyncCore(QObject *p = nullptr);
virtual ~StatusSyncCore() = default;
void registerWidgetSync(QWidget* tar, std::function<bool()> proc);
void registerActionSync(QAction* tar, std::function<bool()> proc);
void registerAutoRun(std::function<bool()> judge, std::function<void(bool)> exec);
Run* registerManualRun(std::function<bool()> judge, std::function<void (bool)> exec);
void sync();
private:
QHash<QWidget*, std::function<bool()>> widget_trigger_map;
QHash<QAction*, std::function<bool()>> action_trigger_map;
QList<Run*> alltriggers;
};
template<class BaseType>
class ModelSyncs
{