storychainpresent懒加载
This commit is contained in:
parent
04f6aaa3a5
commit
c9d4b1374c
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!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>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
|
|
@ -26,6 +26,7 @@ using namespace MakeTools;
|
||||||
using namespace Parse::Result;
|
using namespace Parse::Result;
|
||||||
using namespace Components;
|
using namespace Components;
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
using namespace Tools;
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,39 +16,7 @@
|
||||||
#include "ContentPresent.h"
|
#include "ContentPresent.h"
|
||||||
#include "storyboardspresent.h"
|
#include "storyboardspresent.h"
|
||||||
#include "storyconceptspresent.h"
|
#include "storyconceptspresent.h"
|
||||||
|
#include "tools.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;
|
|
||||||
};
|
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
|
@ -62,7 +30,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Core::AppCore *const app_core;
|
Core::AppCore *const app_core;
|
||||||
StatusSyncCore *const sync_kernel;
|
Tools::StatusSyncCore *const sync_kernel;
|
||||||
QSplitter *const horizontal_split;
|
QSplitter *const horizontal_split;
|
||||||
QSplitter *const vertical_split;
|
QSplitter *const vertical_split;
|
||||||
|
|
||||||
|
|
|
@ -7,44 +7,48 @@
|
||||||
using namespace Components;
|
using namespace Components;
|
||||||
using namespace Parse;
|
using namespace Parse;
|
||||||
using namespace Parse::Result;
|
using namespace Parse::Result;
|
||||||
|
using namespace Tools;
|
||||||
|
|
||||||
StoryChainsPresent::StoryChainsPresent(Core::AppCore *core, QWidget *parent)
|
StoryChainsPresent::StoryChainsPresent(Core::AppCore *core, QWidget *parent)
|
||||||
: QWidget(parent), core_ins(core), model_base(new QStandardItemModel(this)),
|
: 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->setModel(model_base);
|
||||||
tree_view->setHeaderHidden(true);
|
tree_view->setHeaderHidden(true);
|
||||||
|
|
||||||
auto layoutx = new QVBoxLayout(this);
|
auto layoutx = new QVBoxLayout(this);
|
||||||
layoutx->setMargin(0);
|
layoutx->setMargin(0);
|
||||||
auto split = new QSplitter(Qt::Vertical, this);
|
auto split = new QSplitter(Qt::Vertical, this);
|
||||||
layoutx->addWidget(split);
|
layoutx->addWidget(split);
|
||||||
split->addWidget(tree_view);
|
split->addWidget(tree_view);
|
||||||
split->addWidget(details_show);
|
split->addWidget(details_show);
|
||||||
details_show->setReadOnly(true);
|
details_show->setReadOnly(true);
|
||||||
|
|
||||||
connect(tree_view, &QTreeView::clicked, this, &StoryChainsPresent::action_details_show);
|
connect(tree_view, &QTreeView::clicked, this, &StoryChainsPresent::action_details_show);
|
||||||
connect(tree_view, &QTreeView::doubleClicked, this,&StoryChainsPresent::click_to);
|
connect(tree_view, &QTreeView::doubleClicked, this,&StoryChainsPresent::click_to);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StoryChainsPresent::refresh()
|
void StoryChainsPresent::refresh()
|
||||||
{
|
{
|
||||||
model_base->clear();
|
sync_tools->presentSync([this](DesNode *p)->QList<DesNode*>{
|
||||||
auto list = core_ins->parseCore()->allStoryChains();
|
if(p){
|
||||||
for(auto &chain : list){
|
QList<DesNode*> retv;
|
||||||
auto chain_node = new QStandardItem(static_cast<NamedNode*>(chain)->name()[0]);
|
for(auto &point : p->children()){
|
||||||
chain_node->setEditable(false);
|
if(point->typeValue() == NODE_STORYPOINT){
|
||||||
model_base->appendRow(chain_node);
|
retv << point;
|
||||||
|
}
|
||||||
auto children = chain->children();
|
|
||||||
for(auto &point : 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);
|
|
||||||
}
|
}
|
||||||
|
return retv;
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
return this->core_ins->parseCore()->allStoryChains();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void StoryChainsPresent::action_details_show(const QModelIndex &curr)
|
void StoryChainsPresent::action_details_show(const QModelIndex &curr)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define STORYCHAINSPRESENT_H
|
#define STORYCHAINSPRESENT_H
|
||||||
|
|
||||||
#include "appcore.h"
|
#include "appcore.h"
|
||||||
|
#include "tools.h"
|
||||||
|
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
|
@ -26,6 +27,7 @@ namespace Components {
|
||||||
QStandardItemModel *const model_base;
|
QStandardItemModel *const model_base;
|
||||||
QTreeView *const tree_view;
|
QTreeView *const tree_view;
|
||||||
QPlainTextEdit *const details_show;
|
QPlainTextEdit *const details_show;
|
||||||
|
Tools::ModelSyncs<Parse::Result::DesNode*> *const sync_tools;
|
||||||
|
|
||||||
void action_details_show(const QModelIndex &curr);
|
void action_details_show(const QModelIndex &curr);
|
||||||
|
|
||||||
|
|
|
@ -1 +1,62 @@
|
||||||
#include "tools.h"
|
#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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,38 @@
|
||||||
|
|
||||||
namespace Tools {
|
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>
|
template<class BaseType>
|
||||||
class ModelSyncs
|
class ModelSyncs
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue