2022-11-18 23:47:32 +00:00
|
|
|
|
#include "storyunitspresent.h"
|
2022-12-31 13:05:58 +00:00
|
|
|
|
#include "DocsManager.h"
|
2023-03-10 15:18:46 +00:00
|
|
|
|
#include "command_list.h"
|
|
|
|
|
#include "opstream.h"
|
2022-11-18 23:47:32 +00:00
|
|
|
|
|
|
|
|
|
#include <QSplitter>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
using namespace Components;
|
|
|
|
|
using namespace Parse::Result;
|
2023-03-10 15:18:46 +00:00
|
|
|
|
using namespace Operate;
|
2023-03-11 07:01:28 +00:00
|
|
|
|
using namespace DataModel;
|
2022-11-18 23:47:32 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
StoryunitsPresentModel::StoryunitsPresentModel(Core::AppCore *core)
|
|
|
|
|
: core_ins(core), model_ins(new QStandardItemModel),
|
|
|
|
|
details_backend(new QTextDocument) {}
|
2022-11-18 23:47:32 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
StoryunitsPresentModel::~StoryunitsPresentModel() {
|
|
|
|
|
delete model_ins;
|
|
|
|
|
delete details_backend;
|
|
|
|
|
}
|
2022-11-18 23:47:32 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
QStandardItemModel *StoryunitsPresentModel::treeModel() const {
|
|
|
|
|
return model_ins;
|
|
|
|
|
}
|
2022-11-18 23:47:32 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
QTextDocument *StoryunitsPresentModel::detailsBackend() const {
|
|
|
|
|
return details_backend;
|
2022-11-18 23:47:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 15:18:46 +00:00
|
|
|
|
void StoryunitsPresentModel::refreshTree() {
|
2022-11-18 23:47:32 +00:00
|
|
|
|
model_ins->clear();
|
2022-11-22 06:15:36 +00:00
|
|
|
|
auto units = core_ins->parseCore()->allStoryUnits();
|
2023-03-10 13:01:19 +00:00
|
|
|
|
for (auto &unit : units) {
|
|
|
|
|
auto unit_node =
|
|
|
|
|
new QStandardItem(static_cast<NamedNode *>(unit)->name()[0]);
|
2022-11-18 23:47:32 +00:00
|
|
|
|
unit_node->setEditable(false);
|
|
|
|
|
model_ins->appendRow(unit_node);
|
|
|
|
|
|
|
|
|
|
auto children = unit->children();
|
2023-03-10 13:01:19 +00:00
|
|
|
|
for (auto &frag : children) {
|
|
|
|
|
if (frag->typeValue() == NODE_STORYFRAGMENT) {
|
|
|
|
|
auto frag_node = new QStandardItem(
|
|
|
|
|
static_cast<NamedNode *>(frag)->name()[0]);
|
2022-11-18 23:47:32 +00:00
|
|
|
|
frag_node->setEditable(false);
|
|
|
|
|
unit_node->appendRow(frag_node);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 15:18:46 +00:00
|
|
|
|
void StoryunitsPresentModel::details_show(const QList<QString> &path) {
|
|
|
|
|
QList<QStandardItem *> items_list =
|
|
|
|
|
OpStream<QStandardItem *>([this](int &cnt, int idx) -> QStandardItem * {
|
|
|
|
|
cnt = model_ins->rowCount();
|
|
|
|
|
if (cnt <= 0)
|
|
|
|
|
return nullptr;
|
|
|
|
|
return model_ins->item(idx);
|
|
|
|
|
})
|
|
|
|
|
.select()
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
for (auto &node : path) {
|
|
|
|
|
auto result = OpStream<QStandardItem *>(items_list)
|
|
|
|
|
.filter([node](QStandardItem *const &it) {
|
|
|
|
|
return node == it->text();
|
|
|
|
|
})
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
if (!result.size())
|
|
|
|
|
throw new SimpleException("指定的Storyunits路径无效:" +
|
|
|
|
|
path.join("/"));
|
|
|
|
|
|
|
|
|
|
items_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();
|
|
|
|
|
}
|
2022-11-18 23:47:32 +00:00
|
|
|
|
|
2023-03-10 15:18:46 +00:00
|
|
|
|
// 填充详细内容
|
|
|
|
|
QString contents;
|
|
|
|
|
auto item = items_list[0];
|
2023-03-10 13:01:19 +00:00
|
|
|
|
if (item->parent() == nullptr) {
|
2022-11-22 06:15:36 +00:00
|
|
|
|
auto node = core_ins->parseCore()->queryStoryUnit(item->text());
|
2022-11-18 23:47:32 +00:00
|
|
|
|
|
|
|
|
|
auto children = node.first()->children();
|
2023-03-10 13:01:19 +00:00
|
|
|
|
for (auto &it : children) {
|
|
|
|
|
if (it->typeValue() != NODE_STORYFRAGMENT) {
|
2023-03-10 15:18:46 +00:00
|
|
|
|
contents += it->toString() + "\n";
|
2022-11-18 23:47:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-10 13:01:19 +00:00
|
|
|
|
} else {
|
|
|
|
|
auto node =
|
|
|
|
|
core_ins->parseCore()->queryStoryUnit(item->parent()->text());
|
|
|
|
|
auto point = core_ins->parseCore()->queryStoryFragment(node.first(),
|
|
|
|
|
item->text());
|
2022-11-18 23:47:32 +00:00
|
|
|
|
|
|
|
|
|
auto children = point.first()->children();
|
2023-03-10 13:01:19 +00:00
|
|
|
|
for (auto &it : children) {
|
2023-03-10 15:18:46 +00:00
|
|
|
|
contents += it->toString() + "\n";
|
2022-11-18 23:47:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-22 06:15:36 +00:00
|
|
|
|
|
2023-03-10 15:18:46 +00:00
|
|
|
|
details_backend->setPlainText(contents);
|
2022-11-22 06:15:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
StoryunitsPresent::StoryunitsPresent(Schedule::CommandsDispatcher *core,
|
|
|
|
|
QWidget *parent)
|
2023-03-10 15:18:46 +00:00
|
|
|
|
: QWidget(parent), disp_core(core), units_view(new QTreeView(this)),
|
2023-03-10 13:01:19 +00:00
|
|
|
|
details_show(new QTextEdit(this)) {
|
|
|
|
|
auto backend =
|
|
|
|
|
core->get<StoryunitsPresentModel>(NAME(StoryunitsPresentModel));
|
2022-11-18 23:47:32 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
units_view->setHeaderHidden(true);
|
|
|
|
|
units_view->setModel(backend->treeModel());
|
|
|
|
|
details_show->setReadOnly(true);
|
|
|
|
|
details_show->setDocument(backend->detailsBackend());
|
2022-11-18 23:47:32 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
auto layout = new QVBoxLayout(this);
|
|
|
|
|
auto splitter = new QSplitter(Qt::Vertical, this);
|
|
|
|
|
layout->addWidget(splitter);
|
|
|
|
|
splitter->addWidget(units_view);
|
|
|
|
|
splitter->addWidget(details_show);
|
|
|
|
|
layout->setMargin(0);
|
2022-11-18 23:47:32 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
connect(units_view, &QTreeView::clicked, this,
|
|
|
|
|
&StoryunitsPresent::show_details);
|
|
|
|
|
connect(units_view, &QTreeView::doubleClicked, this,
|
|
|
|
|
&StoryunitsPresent::jump_to);
|
|
|
|
|
}
|
2022-11-18 23:47:32 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
QString StoryunitsPresent::name() const { return NAME(StoryunitsPresent); }
|
2023-03-10 15:18:46 +00:00
|
|
|
|
|
|
|
|
|
using namespace CommandList;
|
|
|
|
|
void StoryunitsPresent::jump_to(const QModelIndex &curr) {
|
|
|
|
|
QList<QString> path;
|
|
|
|
|
QModelIndex node = curr;
|
|
|
|
|
while (true) {
|
|
|
|
|
auto node_name = node.data().toString();
|
|
|
|
|
if (node_name.isEmpty())
|
|
|
|
|
break;
|
|
|
|
|
path.insert(0, node_name);
|
|
|
|
|
node = node.parent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
disp_core->postCommand(StoryunitJumpTo(path));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StoryunitsPresent::show_details(const QModelIndex &curr) {
|
|
|
|
|
QList<QString> path;
|
|
|
|
|
QModelIndex node = curr;
|
|
|
|
|
while (true) {
|
|
|
|
|
auto node_name = node.data().toString();
|
|
|
|
|
if (node_name.isEmpty())
|
|
|
|
|
break;
|
|
|
|
|
path.insert(0, node_name);
|
|
|
|
|
node = node.parent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
disp_core->postCommand(StoryunitDetailShow(path));
|
|
|
|
|
}
|