2022-11-18 05:43:27 +00:00
|
|
|
|
#include "storychainspresent.h"
|
2022-12-31 13:05:58 +00:00
|
|
|
|
#include "DocsManager.h"
|
2023-03-10 13:01:19 +00:00
|
|
|
|
#include "command_list.h"
|
2023-03-10 15:18:46 +00:00
|
|
|
|
#include "manager_docs.h"
|
2022-11-18 05:43:27 +00:00
|
|
|
|
|
|
|
|
|
#include <QSplitter>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
using namespace Components;
|
|
|
|
|
using namespace Parse;
|
|
|
|
|
using namespace Parse::Result;
|
2022-12-01 13:54:04 +00:00
|
|
|
|
using namespace Tools;
|
2023-03-10 13:01:19 +00:00
|
|
|
|
using namespace CommandList;
|
2023-03-11 07:01:28 +00:00
|
|
|
|
using namespace DataModel;
|
2022-11-18 05:43:27 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
StorychainsPresentModel::StorychainsPresentModel(Core::AppCore *core)
|
2023-03-10 15:18:46 +00:00
|
|
|
|
: core_ins(core), model_base(new QStandardItemModel),
|
|
|
|
|
details_base(new QTextDocument) {
|
2023-03-11 04:49:38 +00:00
|
|
|
|
sync_tools = new TreeSyncs<DesNode *>(
|
2023-03-10 13:01:19 +00:00
|
|
|
|
model_base,
|
2023-03-10 15:18:46 +00:00
|
|
|
|
[](DesNode *const &d, QStandardItem *it) -> bool {
|
|
|
|
|
return static_cast<NamedNode *>(d)->name().first() == it->text();
|
|
|
|
|
},
|
2023-03-10 13:01:19 +00:00
|
|
|
|
[](DesNode *const &d, QStandardItem *it) {
|
2023-03-10 15:18:46 +00:00
|
|
|
|
it->setText(static_cast<NamedNode *>(d)->name().first());
|
|
|
|
|
});
|
2023-03-10 13:01:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 15:18:46 +00:00
|
|
|
|
StorychainsPresentModel::~StorychainsPresentModel() {
|
2023-03-10 13:01:19 +00:00
|
|
|
|
delete model_base;
|
|
|
|
|
delete details_base;
|
|
|
|
|
delete sync_tools;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 15:18:46 +00:00
|
|
|
|
QStandardItemModel *StorychainsPresentModel::treeModel() const {
|
2023-03-10 13:01:19 +00:00
|
|
|
|
return model_base;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 15:18:46 +00:00
|
|
|
|
QTextDocument *const StorychainsPresentModel::detailsBackend() const {
|
2023-03-10 13:01:19 +00:00
|
|
|
|
return details_base;
|
2022-11-18 05:43:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 15:18:46 +00:00
|
|
|
|
void StorychainsPresentModel::refreshTree() {
|
|
|
|
|
sync_tools->presentSync([this](DesNode *p) -> QList<DesNode *> {
|
|
|
|
|
if (p) {
|
|
|
|
|
QList<DesNode *> retv;
|
|
|
|
|
for (auto &point : p->children()) {
|
|
|
|
|
if (point->typeValue() == NODE_STORYPOINT) {
|
|
|
|
|
retv << point;
|
2022-12-01 13:54:04 +00:00
|
|
|
|
}
|
2022-11-18 05:43:27 +00:00
|
|
|
|
}
|
2023-03-10 15:18:46 +00:00
|
|
|
|
return retv;
|
|
|
|
|
} else
|
|
|
|
|
return this->core_ins->parseCore()->allStoryChains();
|
|
|
|
|
});
|
2022-11-18 05:43:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
using namespace Operate;
|
2023-03-10 15:18:46 +00:00
|
|
|
|
void StorychainsPresentModel::showDetails(const QList<QString> &chain_path) {
|
2023-03-17 13:58:38 +00:00
|
|
|
|
QStandardItem *item = nullptr;
|
2023-03-10 13:01:19 +00:00
|
|
|
|
// 迭代路径获取故事链节点
|
2023-03-17 13:58:38 +00:00
|
|
|
|
for (auto &it : chain_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-10 15:18:46 +00:00
|
|
|
|
|
|
|
|
|
if (!result.size()) {
|
|
|
|
|
throw new SimpleException("指定的Storychain路径无效:" +
|
|
|
|
|
chain_path.join("/"));
|
2023-03-17 13:58:38 +00:00
|
|
|
|
} else {
|
|
|
|
|
item = result.at(0);
|
2023-03-10 13:01:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-18 05:43:27 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
// 填充详细内容
|
|
|
|
|
QString text_lines;
|
2023-03-10 15:18:46 +00:00
|
|
|
|
if (item->parent() == nullptr) {
|
2022-11-22 03:42:48 +00:00
|
|
|
|
auto node = core_ins->parseCore()->queryStoryChain(item->text());
|
2022-11-18 05:43:27 +00:00
|
|
|
|
|
|
|
|
|
auto children = node.first()->children();
|
2023-03-10 15:18:46 +00:00
|
|
|
|
for (auto &it : children) {
|
|
|
|
|
if (it->typeValue() != NODE_STORYPOINT) {
|
2023-03-10 13:01:19 +00:00
|
|
|
|
text_lines += it->toString() + "\n";
|
2022-11-18 05:43:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-10 15:18:46 +00:00
|
|
|
|
} else {
|
|
|
|
|
auto node =
|
|
|
|
|
core_ins->parseCore()->queryStoryChain(item->parent()->text());
|
|
|
|
|
auto point =
|
|
|
|
|
core_ins->parseCore()->queryStoryPoint(node.first(), item->text());
|
2022-11-18 05:43:27 +00:00
|
|
|
|
|
|
|
|
|
auto children = point.first()->children();
|
2023-03-10 15:18:46 +00:00
|
|
|
|
for (auto &it : children) {
|
2023-03-10 13:01:19 +00:00
|
|
|
|
text_lines += it->toString() + "\n";
|
2022-11-18 05:43:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-10 13:01:19 +00:00
|
|
|
|
|
|
|
|
|
details_base->setPlainText(text_lines);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 15:18:46 +00:00
|
|
|
|
QString StorychainsPresentModel::name() const {
|
2023-03-10 13:01:19 +00:00
|
|
|
|
return NAME(StorychainsPresentModel);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
StorychainsPresent::StorychainsPresent(Schedule::CommandsDispatcher *disp, StorychainsPresentModel *backend, QWidget *parent)
|
|
|
|
|
: QWidget(parent), disp_core(disp), tree_view(new QTreeView(this)), details_show(new QTextEdit) {
|
2023-03-10 13:01:19 +00:00
|
|
|
|
|
|
|
|
|
tree_view->setModel(backend->treeModel());
|
|
|
|
|
tree_view->setHeaderHidden(true);
|
|
|
|
|
details_show->setDocument(backend->detailsBackend());
|
|
|
|
|
details_show->setReadOnly(true);
|
|
|
|
|
|
|
|
|
|
auto layoutx = new QVBoxLayout(this);
|
|
|
|
|
auto split = new QSplitter(Qt::Vertical, this);
|
|
|
|
|
layoutx->addWidget(split);
|
|
|
|
|
split->addWidget(tree_view);
|
|
|
|
|
split->addWidget(details_show);
|
|
|
|
|
layoutx->setMargin(0);
|
|
|
|
|
|
2023-03-10 15:18:46 +00:00
|
|
|
|
connect(tree_view, &QTreeView::clicked, this,
|
|
|
|
|
&StorychainsPresent::detail_show);
|
|
|
|
|
connect(tree_view, &QTreeView::doubleClicked, this,
|
|
|
|
|
&StorychainsPresent::jump_to);
|
2023-03-10 13:01:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 15:18:46 +00:00
|
|
|
|
QString StorychainsPresent::name() const { return NAME(StorychainsPresent); }
|
2022-11-18 05:43:27 +00:00
|
|
|
|
|
2023-03-17 13:58:38 +00:00
|
|
|
|
QWidget *StorychainsPresent::widget() const { return (QWidget *)this; }
|
|
|
|
|
|
2023-03-10 15:18:46 +00:00
|
|
|
|
void StorychainsPresent::jump_to(const QModelIndex &curr) {
|
|
|
|
|
if (!curr.isValid())
|
2022-11-22 03:42:48 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QList<QString> path;
|
2023-03-10 13:27:46 +00:00
|
|
|
|
auto node = curr;
|
2023-03-10 13:01:19 +00:00
|
|
|
|
while (true) {
|
2023-03-10 13:27:46 +00:00
|
|
|
|
auto node_name = node.data().toString();
|
2023-03-10 13:01:19 +00:00
|
|
|
|
|
2023-03-10 13:27:46 +00:00
|
|
|
|
if (node_name.isEmpty())
|
2023-03-10 13:01:19 +00:00
|
|
|
|
break;
|
2023-03-10 13:27:46 +00:00
|
|
|
|
path.insert(0, node_name);
|
|
|
|
|
node = node.parent();
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
disp_core->postCommand(StorychainJumpTo(path));
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 15:18:46 +00:00
|
|
|
|
void StorychainsPresent::detail_show(const QModelIndex &curr) {
|
|
|
|
|
if (!curr.isValid())
|
2023-03-10 13:01:19 +00:00
|
|
|
|
return;
|
2022-11-22 06:15:36 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
QList<QString> path;
|
2023-03-10 13:27:46 +00:00
|
|
|
|
auto node = curr;
|
2023-03-10 13:01:19 +00:00
|
|
|
|
while (true) {
|
2023-03-10 13:27:46 +00:00
|
|
|
|
auto node_name = node.data().toString();
|
2023-03-10 13:01:19 +00:00
|
|
|
|
|
2023-03-10 13:27:46 +00:00
|
|
|
|
if (node_name.isEmpty())
|
2023-03-10 13:01:19 +00:00
|
|
|
|
break;
|
2023-03-10 13:27:46 +00:00
|
|
|
|
path.insert(0, node_name);
|
|
|
|
|
node = node.parent();
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
disp_core->postCommand(StorychainDetailShow(path));
|
|
|
|
|
}
|