#include "conceptview.h" #include "SensitiveCore.h" #include #include using namespace Components; using namespace Core; using namespace Parse::Result; ConceptView::ConceptView(Core::AppCore *core, QWidget *parent) : QWidget(parent), core_ins(core), tree_view(new QTreeView(this)), model_base(new QStandardItemModel(this)), details_view(new QTextBrowser(this)) { tree_view->setHeaderHidden(true); auto layout = new QVBoxLayout(this); layout->setMargin(0); auto splitter = new QSplitter(Qt::Vertical, this); layout->addWidget(splitter); splitter->addWidget(tree_view); splitter->addWidget(details_view); tree_view->setModel(model_base); details_view->setReadOnly(true); connect(tree_view, &QTreeView::clicked, this, &ConceptView::show_node_description); connect(tree_view, &QTreeView::doubleClicked, this, &ConceptView::click_to); } void ConceptView::refresh() { model_base->clear(); auto units = core_ins->parseCore()->allStoryConcept(); for(auto &unit : units){ auto unit_node = new QStandardItem(static_cast(unit)->name()[0]); unit_node->setEditable(false); model_base->appendRow(unit_node); auto children = unit->children(); for(auto &frag : children){ if(frag->typeValue() == NODE_STORYSTRONGPOINT){ auto frag_node = new QStandardItem(static_cast(frag)->name()[0]); frag_node->setEditable(false); unit_node->appendRow(frag_node); } } } } void ConceptView::show_node_description(const QModelIndex &curr) { if(!curr.isValid()) return; details_view->clear(); auto item = model_base->itemFromIndex(curr); if(item->parent() == nullptr){ auto node = core_ins->parseCore()->queryStoryConcept(item->text()); auto children = node.first()->children(); for(auto &it : children){ if(it->typeValue() != NODE_STORYSTRONGPOINT){ details_view->append(it->toString()); } } } else{ auto node = core_ins->parseCore()->queryStoryConcept(item->parent()->text()); auto point = core_ins->parseCore()->queryStoryStrongPoint(node.first(), item->text()); auto children = point.first()->children(); for(auto &it : children){ details_view->append(it->toString()); } } } void ConceptView::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 unit_ins = this->core_ins->parseCore()->queryStoryConcept(path[0]).first(); auto chain_doc = unit_ins->doc(); this->core_ins->openTextDocument(chain_doc->filePath(), chain_doc->docName()); auto present = this->core_ins->getFramework()->queryTextComponent(QFileInfo(chain_doc->filePath())); if(path.size()){ present->jumpTo(path); } }