116 lines
3.1 KiB
C++
116 lines
3.1 KiB
C++
#include "storyunitspresent.h"
|
|
#include "DocsManager.h"
|
|
|
|
#include <QSplitter>
|
|
#include <QVBoxLayout>
|
|
|
|
using namespace Components;
|
|
using namespace Parse::Result;
|
|
|
|
StoryUnitsPresent::StoryUnitsPresent(Core::AppCore *core, QWidget *parent)
|
|
: QWidget(parent), core_ins(core),
|
|
model_ins(new QStandardItemModel(this)),
|
|
units_view(new QTreeView(this)),
|
|
details_show(new QPlainTextEdit(this))
|
|
{
|
|
units_view->setHeaderHidden(true);
|
|
|
|
auto layout = new QVBoxLayout(this);
|
|
layout->setMargin(0);
|
|
|
|
auto splitter = new QSplitter(Qt::Vertical, this);
|
|
layout->addWidget(splitter);
|
|
|
|
splitter->addWidget(units_view);
|
|
splitter->addWidget(details_show);
|
|
|
|
units_view->setModel(model_ins);
|
|
details_show->setReadOnly(true);
|
|
|
|
connect(units_view, &QTreeView::clicked, this, &StoryUnitsPresent::show_node_description);
|
|
connect(units_view, &QTreeView::doubleClicked, this, &StoryUnitsPresent::click_to);
|
|
}
|
|
|
|
void StoryUnitsPresent::refresh()
|
|
{
|
|
model_ins->clear();
|
|
auto units = core_ins->parseCore()->allStoryUnits();
|
|
for(auto &unit : units){
|
|
auto unit_node = new QStandardItem(static_cast<NamedNode*>(unit)->name()[0]);
|
|
unit_node->setEditable(false);
|
|
model_ins->appendRow(unit_node);
|
|
|
|
auto children = unit->children();
|
|
for(auto &frag : children){
|
|
if(frag->typeValue() == NODE_STORYFRAGMENT){
|
|
auto frag_node = new QStandardItem(static_cast<NamedNode*>(frag)->name()[0]);
|
|
frag_node->setEditable(false);
|
|
unit_node->appendRow(frag_node);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void StoryUnitsPresent::show_node_description(const QModelIndex &curr)
|
|
{
|
|
if(!curr.isValid())
|
|
return;
|
|
|
|
details_show->clear();
|
|
auto item = model_ins->itemFromIndex(curr);
|
|
if(item->parent() == nullptr){
|
|
auto node = core_ins->parseCore()->queryStoryUnit(item->text());
|
|
|
|
auto children = node.first()->children();
|
|
for(auto &it : children){
|
|
if(it->typeValue() != NODE_STORYFRAGMENT){
|
|
details_show->appendPlainText(it->toString());
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
auto node = core_ins->parseCore()->queryStoryUnit(item->parent()->text());
|
|
auto point = core_ins->parseCore()->queryStoryFragment(node.first(), item->text());
|
|
|
|
auto children = point.first()->children();
|
|
for(auto &it : children){
|
|
details_show->appendPlainText(it->toString());
|
|
}
|
|
}
|
|
}
|
|
|
|
void StoryUnitsPresent::click_to(const QModelIndex &curr)
|
|
{
|
|
if(!curr.isValid())
|
|
return;
|
|
|
|
auto pnode = this->model_ins->itemFromIndex(curr);
|
|
QList<QString> path;
|
|
while (pnode) {
|
|
path.insert(0, pnode->text());
|
|
pnode = pnode->parent();
|
|
}
|
|
|
|
auto unit_ins = this->core_ins->parseCore()->queryStoryUnit(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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|