#include "storychainspresent.h" #include "DocsManager.h" #include #include using namespace Components; using namespace Parse; using namespace Parse::Result; using namespace Tools; StoryChainsPresent::StoryChainsPresent(Core::AppCore *core, QWidget *parent) : QWidget(parent), core_ins(core), model_base(new QStandardItemModel(this)), tree_view(new QTreeView(this)), details_show(new QPlainTextEdit(this)), sync_tools(new ModelSyncs( model_base, [](DesNode *const &d, QStandardItem *it)->bool { return static_cast(d)->name().first() == it->text();}, [](DesNode *const &d, QStandardItem *it) { it->setText(static_cast(d)->name().first()); })) { tree_view->setModel(model_base); tree_view->setHeaderHidden(true); auto layoutx = new QVBoxLayout(this); layoutx->setMargin(0); auto split = new QSplitter(Qt::Vertical, this); layoutx->addWidget(split); split->addWidget(tree_view); split->addWidget(details_show); details_show->setReadOnly(true); connect(tree_view, &QTreeView::clicked, this, &StoryChainsPresent::action_details_show); connect(tree_view, &QTreeView::doubleClicked, this,&StoryChainsPresent::click_to); } void StoryChainsPresent::refresh() { sync_tools->presentSync([this](DesNode *p)->QList{ if(p){ QList retv; for(auto &point : p->children()){ if(point->typeValue() == NODE_STORYPOINT){ retv << point; } } return retv; } else return this->core_ins->parseCore()->allStoryChains(); }); } void StoryChainsPresent::action_details_show(const QModelIndex &curr) { if(!curr.isValid()) return; details_show->clear(); auto item = model_base->itemFromIndex(curr); if(item->parent() == nullptr){ auto node = core_ins->parseCore()->queryStoryChain(item->text()); auto children = node.first()->children(); for(auto &it : children){ if(it->typeValue() != NODE_STORYPOINT){ details_show->appendPlainText(it->toString()); } } } else{ auto node = core_ins->parseCore()->queryStoryChain(item->parent()->text()); auto point = core_ins->parseCore()->queryStoryPoint(node.first(), item->text()); auto children = point.first()->children(); for(auto &it : children){ details_show->appendPlainText(it->toString()); } } } void StoryChainsPresent::click_to(const QModelIndex &curr) { if(!curr.isValid()) return; auto pnode = this->model_base->itemFromIndex(curr); QList path; while (pnode) { path.insert(0, pnode->text()); pnode = pnode->parent(); } auto chain_ins = this->core_ins->parseCore()->queryStoryChain(path[0]).first(); auto chain_doc = chain_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); } }