QtNovelUI/WordsIDE/storyconceptspresent.cpp

180 lines
5.5 KiB
C++
Raw Normal View History

2022-11-29 03:47:12 +00:00
#include "storyconceptspresent.h"
2022-12-31 13:05:58 +00:00
#include "DocsManager.h"
2023-03-11 04:52:33 +00:00
#include "command_list.h"
2022-11-29 03:47:12 +00:00
#include "opstream.h"
2022-11-25 01:18:54 +00:00
#include <QSplitter>
#include <QVBoxLayout>
2022-11-29 03:47:12 +00:00
using namespace Operate;
2022-11-25 01:18:54 +00:00
using namespace Components;
using namespace Core;
using namespace Parse::Result;
2022-11-29 03:47:12 +00:00
using namespace Tools;
2023-03-11 04:52:33 +00:00
using namespace Schedule;
using namespace CommandList;
2023-03-17 13:58:38 +00:00
using namespace DataModel;
2023-03-11 04:52:33 +00:00
2023-03-17 13:58:38 +00:00
StoryconceptsPresent::StoryconceptsPresent(CommandsDispatcher *core, StoryconceptsPresentModel *backend, QWidget *parent)
: QWidget(parent), core_ins(core), tree_view(new QTreeView(this)), details_view(new QTextBrowser(this)) {
2023-03-11 04:52:33 +00:00
tree_view->setModel(backend->treeModel());
tree_view->setHeaderHidden(true);
details_view->setDocument(backend->detailsBackend());
details_view->setReadOnly(true);
auto layout = new QVBoxLayout(this);
layout->setMargin(0);
auto splitter = new QSplitter(Qt::Vertical, this);
layout->addWidget(splitter);
splitter->addWidget(tree_view);
splitter->addWidget(details_view);
connect(tree_view, &QTreeView::clicked, this,
&StoryconceptsPresent::show_details);
connect(tree_view, &QTreeView::doubleClicked, this,
&StoryconceptsPresent::jump_to);
}
2022-11-25 01:18:54 +00:00
2023-03-11 04:52:33 +00:00
void StoryconceptsPresent::show_details(const QModelIndex &curr) {
if(!curr.isValid())
return;
2022-11-25 01:18:54 +00:00
2023-03-11 04:52:33 +00:00
QList<QString> path;
QModelIndex node = curr;
while (true) {
auto name = node.data().toString();
if (name.isEmpty())
break;
path.insert(0, name);
node = node.parent();
}
2022-11-25 01:18:54 +00:00
2023-03-11 04:52:33 +00:00
core_ins->postCommand(StoryconceptDetailShow(path));
}
void StoryconceptsPresent::jump_to(const QModelIndex &curr) {
if(!curr.isValid())
return;
2022-11-25 01:18:54 +00:00
2023-03-11 04:52:33 +00:00
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));
}
2023-03-11 05:55:16 +00:00
QString StoryconceptsPresent::name() const {
return NAME(StoryconceptsPresent);
}
2023-03-17 13:58:38 +00:00
QWidget *StoryconceptsPresent::widget() const { return (QWidget *)this; }
2023-03-11 07:01:28 +00:00
using namespace DataModel;
2023-03-11 04:52:33 +00:00
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;
}
2022-11-25 01:18:54 +00:00
2023-03-11 04:52:33 +00:00
QStandardItemModel *StoryconceptsPresentModel::treeModel() const {
return model_base;
}
2022-11-25 01:18:54 +00:00
2023-03-11 04:52:33 +00:00
QTextDocument *StoryconceptsPresentModel::detailsBackend() const {
return detail_backend;
2022-11-25 01:18:54 +00:00
}
2023-03-11 04:52:33 +00:00
void StoryconceptsPresentModel::refreshTree() {
this->concept_model->presentSync([this](DesNode *dit) {
if (dit) {
QList<DesNode *> rets;
2022-11-29 03:47:12 +00:00
auto children = dit->children();
2023-03-11 04:52:33 +00:00
for (auto &frag : children) {
if (frag->typeValue() == NODE_STORYSTRONGPOINT) {
2022-11-29 03:47:12 +00:00
rets << frag;
}
2022-11-25 01:18:54 +00:00
}
2022-11-29 03:47:12 +00:00
return rets;
2023-03-11 04:52:33 +00:00
} else {
2022-11-29 03:47:12 +00:00
return core_ins->parseCore()->allStoryConcept();
}
});
2022-11-25 01:18:54 +00:00
}
2023-03-11 04:52:33 +00:00
void StoryconceptsPresentModel::detailsShow(const QList<QString> &path) {
2023-03-17 13:58:38 +00:00
QStandardItem *item = nullptr;
2023-03-11 04:52:33 +00:00
// 迭代路径获取故事链节点
2023-03-17 13:58:38 +00:00
for (auto &it : path) {
auto result = OpStream<QStandardItem *>([this, &item](int &cnt, int idx) -> QStandardItem * {
if (!item) {
cnt = model_base->rowCount();
if (cnt <= 0)
return nullptr;
return model_base->item(idx);
} else {
cnt = item->rowCount();
if (cnt <= 0)
return nullptr;
return item->child(idx);
}
}).filter([it](QStandardItem *const &xit) {
return it == xit->text();
}).toList();
2023-03-11 04:52:33 +00:00
if (!result.size()) {
2023-03-17 13:58:38 +00:00
throw new SimpleException("指定的Storychain路径无效" + path.join("/"));
} else {
item = result.at(0);
2023-03-11 04:52:33 +00:00
}
}
2022-11-25 01:18:54 +00:00
2023-03-11 04:52:33 +00:00
// 填充详细内容
QString contents;
if (item->parent() == nullptr) {
2022-11-25 01:18:54 +00:00
auto node = core_ins->parseCore()->queryStoryConcept(item->text());
auto children = node.first()->children();
2023-03-11 04:52:33 +00:00
for (auto &it : children) {
if (it->typeValue() != NODE_STORYSTRONGPOINT) {
contents += it->toString() + "\n";
2022-11-25 01:18:54 +00:00
}
}
2023-03-11 04:52:33 +00:00
} else {
auto node =
core_ins->parseCore()->queryStoryConcept(item->parent()->text());
auto point = core_ins->parseCore()->queryStoryStrongPoint(node.first(),
item->text());
2022-11-25 01:18:54 +00:00
auto children = point.first()->children();
2023-03-11 04:52:33 +00:00
for (auto &it : children) {
contents += it->toString() + "\n";
2022-11-25 01:18:54 +00:00
}
}
2023-03-11 04:52:33 +00:00
detail_backend->setPlainText(contents);
2022-11-25 01:18:54 +00:00
}
2023-03-11 04:52:33 +00:00
QString StoryconceptsPresentModel::name() const {
return NAME(StoryconceptsPresentModel);
2022-11-25 01:18:54 +00:00
}