类型storyconceptpresent完成改造

This commit is contained in:
玉宇清音 2023-03-11 12:52:33 +08:00
parent 49f7d6121c
commit 28ac179e8d
5 changed files with 250 additions and 79 deletions

View File

@ -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, 2023-03-09T23:20:26. --> <!-- Written by QtCreator 4.15.0, 2023-03-11T00:10:57. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

View File

@ -336,3 +336,49 @@ QString StoryunitJumpTo::toText() const { return unit_nav.join("/"); }
void StoryunitJumpTo::fromText(const QString &line) { void StoryunitJumpTo::fromText(const QString &line) {
unit_nav = line.split("/"); unit_nav = line.split("/");
} }
#include "storyconceptspresent.h"
StoryconceptDetailShow::StoryconceptDetailShow(const QList<QString> &path) {
navi_path.append(path);
}
QString StoryconceptDetailShow::name() const {
return NAME(StoryconceptDetailShow);
}
void StoryconceptDetailShow::run(Schedule::CommandsDispatcher *core) const {
auto vmgr =
core->get<StoryconceptsPresentModel>(NAME(StoryconceptsPresentModel));
vmgr->detailsShow(navi_path);
}
QString StoryconceptDetailShow::toText() const { return navi_path.join("/"); }
void StoryconceptDetailShow::fromText(const QString &line) {
navi_path = line.split("/");
}
StoryconceptJumpTo::StoryconceptJumpTo(const QList<QString> &path) {
navi_path.append(path);
}
QString StoryconceptJumpTo::name() const { return NAME(StoryconceptJumpTo); }
void StoryconceptJumpTo::run(Schedule::CommandsDispatcher *core) const {
auto core_ins = core->get<AppCore>(NAME(AppCore));
auto vmgr = core->get<DocumentsManager>(NAME(DocumentsManager));
auto cept_ins =
core_ins->parseCore()->queryStoryConcept(navi_path[0]).first();
auto cept_doc = cept_ins->doc();
auto idx = vmgr->projectManager()->queryIndex(cept_doc->filePath());
auto route = vmgr->converter(idx);
vmgr->openFile(route);
vmgr->activePresentOf(route)->jumpTo(navi_path);
}
QString StoryconceptJumpTo::toText() const { return navi_path.join("/"); }
void StoryconceptJumpTo::fromText(const QString &line) {
navi_path = line.split("/");
}

View File

@ -180,6 +180,36 @@ namespace CommandList {
QList<QString> unit_nav; QList<QString> unit_nav;
}; };
class StoryconceptDetailShow : public Schedule::GeCommand {
public:
StoryconceptDetailShow(const QList<QString> &path);
// GeCommand interface
public:
virtual QString name() const override;
virtual void run(Schedule::CommandsDispatcher *core) const override;
virtual QString toText() const override;
virtual void fromText(const QString &line) override;
private:
QList<QString> navi_path;
};
class StoryconceptJumpTo : public Schedule::GeCommand {
public:
StoryconceptJumpTo(const QList<QString> &path);
// GeCommand interface
public:
virtual QString name() const override;
virtual void run(Schedule::CommandsDispatcher *core) const override;
virtual QString toText() const override;
virtual void fromText(const QString &line) override;
private:
QList<QString> navi_path;
};
} // namespace CommandList } // namespace CommandList
#endif // COMMAND_LIST_H #endif // COMMAND_LIST_H

View File

@ -1,5 +1,6 @@
#include "storyconceptspresent.h" #include "storyconceptspresent.h"
#include "DocsManager.h" #include "DocsManager.h"
#include "command_list.h"
#include "opstream.h" #include "opstream.h"
#include <QSplitter> #include <QSplitter>
@ -10,101 +11,176 @@ using namespace Components;
using namespace Core; using namespace Core;
using namespace Parse::Result; using namespace Parse::Result;
using namespace Tools; using namespace Tools;
using namespace Schedule;
using namespace CommandList;
StoryConceptsPresent::StoryConceptsPresent(Core::AppCore *core, QWidget *parent) StoryconceptsPresent::StoryconceptsPresent(CommandsDispatcher *core,
: QWidget(parent), core_ins(core), QWidget *parent)
tree_view(new QTreeView(this)), : QWidget(parent), core_ins(core), tree_view(new QTreeView(this)),
model_base(new QStandardItemModel(this)), details_view(new QTextBrowser(this)) {
details_view(new QTextBrowser(this)), auto backend =
concept_model(new ModelSyncs<DesNode*>( core->get<StoryconceptsPresentModel>(NAME(StoryconceptsPresentModel));
model_base,
[](DesNode* dbase, QStandardItem *it)->bool{ return static_cast<NamedNode*>(dbase)->name()[0] == it->text(); },
[](DesNode* dbase, QStandardItem *it){ it->setText(static_cast<NamedNode*>(dbase)->name()[0]); })){
tree_view->setHeaderHidden(true);
auto layout = new QVBoxLayout(this); tree_view->setModel(backend->treeModel());
layout->setMargin(0); tree_view->setHeaderHidden(true);
details_view->setDocument(backend->detailsBackend());
details_view->setReadOnly(true);
auto splitter = new QSplitter(Qt::Vertical, this); auto layout = new QVBoxLayout(this);
layout->addWidget(splitter); layout->setMargin(0);
splitter->addWidget(tree_view); auto splitter = new QSplitter(Qt::Vertical, this);
splitter->addWidget(details_view); layout->addWidget(splitter);
splitter->addWidget(tree_view);
splitter->addWidget(details_view);
tree_view->setModel(model_base); connect(tree_view, &QTreeView::clicked, this,
details_view->setReadOnly(true); &StoryconceptsPresent::show_details);
connect(tree_view, &QTreeView::doubleClicked, this,
connect(tree_view, &QTreeView::clicked, this, &StoryConceptsPresent::show_node_description); &StoryconceptsPresent::jump_to);
connect(tree_view, &QTreeView::doubleClicked, this, &StoryConceptsPresent::click_to);
} }
void StoryConceptsPresent::refresh() void StoryconceptsPresent::show_details(const QModelIndex &curr) {
{ if(!curr.isValid())
this->concept_model->presentSync([this](DesNode *dit){ return;
if(dit){
QList<DesNode*> rets; QList<QString> path;
QModelIndex node = curr;
while (true) {
auto name = node.data().toString();
if (name.isEmpty())
break;
path.insert(0, name);
node = node.parent();
}
core_ins->postCommand(StoryconceptDetailShow(path));
}
void StoryconceptsPresent::jump_to(const QModelIndex &curr) {
if(!curr.isValid())
return;
QList<QString> path;
QModelIndex node = curr;
while (true) {
auto name = node.data().toString();
if (name.isEmpty())
break;
path.insert(0, name);
node = node.parent();
}
core_ins->postCommand(StoryconceptJumpTo(path));
}
StoryconceptsPresentModel::StoryconceptsPresentModel(Core::AppCore *core)
: core_ins(core), model_base(new QStandardItemModel),
detail_backend(new QTextDocument) {
concept_model = new TreeSyncs<DesNode *>(
model_base,
[](DesNode *dbase, QStandardItem *it) -> bool {
return static_cast<NamedNode *>(dbase)->name()[0] == it->text();
},
[](DesNode *dbase, QStandardItem *it) {
it->setText(static_cast<NamedNode *>(dbase)->name()[0]);
});
}
StoryconceptsPresentModel::~StoryconceptsPresentModel() {
delete model_base;
delete detail_backend;
delete concept_model;
}
QStandardItemModel *StoryconceptsPresentModel::treeModel() const {
return model_base;
}
QTextDocument *StoryconceptsPresentModel::detailsBackend() const {
return detail_backend;
}
void StoryconceptsPresentModel::refreshTree() {
this->concept_model->presentSync([this](DesNode *dit) {
if (dit) {
QList<DesNode *> rets;
auto children = dit->children(); auto children = dit->children();
for(auto &frag : children){ for (auto &frag : children) {
if(frag->typeValue() == NODE_STORYSTRONGPOINT){ if (frag->typeValue() == NODE_STORYSTRONGPOINT) {
rets << frag; rets << frag;
} }
} }
return rets; return rets;
} } else {
else{
return core_ins->parseCore()->allStoryConcept(); return core_ins->parseCore()->allStoryConcept();
} }
}); });
} }
void StoryConceptsPresent::show_node_description(const QModelIndex &curr) void StoryconceptsPresentModel::detailsShow(const QList<QString> &path) {
{ // 获取第一级初始集合
if(!curr.isValid()) QList<QStandardItem *> item_list =
return; OpStream<QStandardItem *>([this](int &cnt, int idx) -> QStandardItem * {
cnt = model_base->rowCount();
if (cnt <= 0)
return nullptr;
return model_base->item(idx);
})
.select()
.toList();
details_view->clear(); // 迭代路径获取故事链节点
auto item = model_base->itemFromIndex(curr); for (auto it : path) {
if(item->parent() == nullptr){ auto result = OpStream<QStandardItem *>(item_list)
.filter([it](QStandardItem *const &xit) {
return it == xit->text();
})
.toList();
if (!result.size()) {
throw new SimpleException("指定的Storychain路径无效" +
path.join("/"));
}
item_list = OpStream<QStandardItem *>(
[&result](int &cnt, int idx) -> QStandardItem * {
cnt = result[0]->rowCount();
if (cnt <= 0)
return nullptr;
return result[0]->child(idx);
})
.select()
.toList();
}
// 填充详细内容
auto item = item_list[0];
QString contents;
if (item->parent() == nullptr) {
auto node = core_ins->parseCore()->queryStoryConcept(item->text()); auto node = core_ins->parseCore()->queryStoryConcept(item->text());
auto children = node.first()->children(); auto children = node.first()->children();
for(auto &it : children){ for (auto &it : children) {
if(it->typeValue() != NODE_STORYSTRONGPOINT){ if (it->typeValue() != NODE_STORYSTRONGPOINT) {
details_view->append(it->toString()); contents += it->toString() + "\n";
} }
} }
} } else {
else{ auto node =
auto node = core_ins->parseCore()->queryStoryConcept(item->parent()->text()); core_ins->parseCore()->queryStoryConcept(item->parent()->text());
auto point = core_ins->parseCore()->queryStoryStrongPoint(node.first(), item->text()); auto point = core_ins->parseCore()->queryStoryStrongPoint(node.first(),
item->text());
auto children = point.first()->children(); auto children = point.first()->children();
for(auto &it : children){ for (auto &it : children) {
details_view->append(it->toString()); contents += it->toString() + "\n";
} }
} }
detail_backend->setPlainText(contents);
} }
void StoryConceptsPresent::click_to(const QModelIndex &curr) QString StoryconceptsPresentModel::name() const {
{ return NAME(StoryconceptsPresentModel);
if(!curr.isValid())
return;
auto pnode = this->model_base->itemFromIndex(curr);
QList<QString> path;
while (pnode) {
path.insert(0, pnode->text());
pnode = pnode->parent();
}
auto unit_ins = this->core_ins->parseCore()->queryStoryConcept(path[0]).first();
auto chain_doc = unit_ins->doc();
this->core_ins->getDocsManager()->openTextDocument(chain_doc->filePath(), chain_doc->docName());
auto present = this->core_ins->getDocsManager()->queryTextComponent(QFileInfo(chain_doc->filePath()));
if(path.size()){
present->jumpTo(path);
}
} }

View File

@ -11,22 +11,41 @@
#include <QWidget> #include <QWidget>
namespace Components { namespace Components {
class StoryConceptsPresent : public QWidget class StoryconceptsPresentModel : public Schedule::AccessibleObject {
{ public:
public: StoryconceptsPresentModel(Core::AppCore *core);
StoryConceptsPresent(Core::AppCore *core, QWidget *parent=nullptr); virtual ~StoryconceptsPresentModel();
virtual void refresh(); QStandardItemModel *treeModel() const;
QTextDocument *detailsBackend() const;
private: void refreshTree();
void detailsShow(const QList<QString> &path);
// AccessibleObject interface
public:
virtual QString name() const override;
private:
Core::AppCore *const core_ins; Core::AppCore *const core_ins;
QTreeView *const tree_view;
QStandardItemModel *const model_base; QStandardItemModel *const model_base;
QTextBrowser *const details_view; QTextDocument *const detail_backend;
Tools::ModelSyncs<Parse::Result::DesNode*> * concept_model; Tools::TreeSyncs<Parse::Result::DesNode *> *concept_model;
};
void show_node_description(const QModelIndex &curr); class StoryconceptsPresent : public QWidget,
void click_to(const QModelIndex &curr); public Schedule::AccessibleObject {
public:
StoryconceptsPresent(Schedule::CommandsDispatcher *core,
QWidget *parent = nullptr);
private:
Schedule::CommandsDispatcher *const core_ins;
QTreeView *const tree_view;
QTextBrowser *const details_view;
void show_details(const QModelIndex &curr);
void jump_to(const QModelIndex &curr);
}; };
} }