2022-11-18 23:47:32 +00:00
|
|
|
#include "storyunitspresent.h"
|
2022-12-31 13:05:58 +00:00
|
|
|
#include "DocsManager.h"
|
2022-11-18 23:47:32 +00:00
|
|
|
|
|
|
|
#include <QSplitter>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
using namespace Components;
|
|
|
|
using namespace Parse::Result;
|
|
|
|
|
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 13:01:19 +00:00
|
|
|
void StoryunitsPresentModel::refresh() {
|
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 13:01:19 +00:00
|
|
|
void StoryunitsPresentModel::show_node_description(const QModelIndex &curr) {
|
|
|
|
if (!curr.isValid())
|
2022-11-18 23:47:32 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
details_show->clear();
|
|
|
|
auto item = model_ins->itemFromIndex(curr);
|
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) {
|
2022-11-18 23:47:32 +00:00
|
|
|
details_show->appendPlainText(it->toString());
|
|
|
|
}
|
|
|
|
}
|
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) {
|
2022-11-18 23:47:32 +00:00
|
|
|
details_show->appendPlainText(it->toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
void StoryunitsPresentModel::click_to(const QModelIndex &curr) {
|
|
|
|
if (!curr.isValid())
|
2022-11-22 06:15:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
auto pnode = this->model_ins->itemFromIndex(curr);
|
|
|
|
QList<QString> path;
|
|
|
|
while (pnode) {
|
|
|
|
path.insert(0, pnode->text());
|
|
|
|
pnode = pnode->parent();
|
|
|
|
}
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
auto unit_ins =
|
|
|
|
this->core_ins->parseCore()->queryStoryUnit(path[0]).first();
|
2022-11-22 06:15:36 +00:00
|
|
|
auto chain_doc = unit_ins->doc();
|
2023-03-10 13:01:19 +00:00
|
|
|
this->core_ins->getDocsManager()->openTextDocument(chain_doc->filePath(),
|
|
|
|
chain_doc->docName());
|
|
|
|
auto present = this->core_ins->getDocsManager()->queryTextComponent(
|
|
|
|
QFileInfo(chain_doc->filePath()));
|
2022-11-22 06:15:36 +00:00
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
if (path.size()) {
|
2022-11-22 06:15:36 +00:00
|
|
|
present->jumpTo(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
StoryunitsPresent::StoryunitsPresent(Schedule::CommandsDispatcher *core,
|
|
|
|
QWidget *parent)
|
|
|
|
: QWidget(parent), core_ins(core), units_view(new QTreeView(this)),
|
|
|
|
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); }
|