QtNovelUI/WordsIDE/storychainspresent.cpp

117 lines
3.2 KiB
C++
Raw Normal View History

2022-11-18 05:43:27 +00:00
#include "storychainspresent.h"
2022-12-31 13:05:58 +00:00
#include "DocsManager.h"
2022-11-18 05:43:27 +00:00
#include <QSplitter>
#include <QVBoxLayout>
using namespace Components;
using namespace Parse;
using namespace Parse::Result;
2022-12-01 13:54:04 +00:00
using namespace Tools;
2022-11-18 05:43:27 +00:00
StoryChainsPresent::StoryChainsPresent(Core::AppCore *core, QWidget *parent)
2022-11-18 05:43:27 +00:00
: QWidget(parent), core_ins(core), model_base(new QStandardItemModel(this)),
2022-12-01 13:54:04 +00:00
tree_view(new QTreeView(this)), details_show(new QPlainTextEdit(this)),
sync_tools(new ModelSyncs<DesNode*>(
model_base,
[](DesNode *const &d, QStandardItem *it)->bool
{ return static_cast<NamedNode*>(d)->name().first() == it->text();},
[](DesNode *const &d, QStandardItem *it)
{ it->setText(static_cast<NamedNode*>(d)->name().first()); }))
2022-11-18 05:43:27 +00:00
{
2022-12-01 13:54:04 +00:00
tree_view->setModel(model_base);
tree_view->setHeaderHidden(true);
2022-11-18 05:43:27 +00:00
2022-12-01 13:54:04 +00:00
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);
2022-11-18 05:43:27 +00:00
2022-12-01 13:54:04 +00:00
connect(tree_view, &QTreeView::clicked, this, &StoryChainsPresent::action_details_show);
connect(tree_view, &QTreeView::doubleClicked, this,&StoryChainsPresent::click_to);
2022-11-18 05:43:27 +00:00
}
void StoryChainsPresent::refresh()
{
2022-12-01 13:54:04 +00:00
sync_tools->presentSync([this](DesNode *p)->QList<DesNode*>{
if(p){
QList<DesNode*> retv;
for(auto &point : p->children()){
if(point->typeValue() == NODE_STORYPOINT){
retv << point;
}
2022-11-18 05:43:27 +00:00
}
2022-12-01 13:54:04 +00:00
return retv;
2022-11-18 05:43:27 +00:00
}
2022-12-01 13:54:04 +00:00
else
return this->core_ins->parseCore()->allStoryChains();
});
2022-11-18 05:43:27 +00:00
}
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());
2022-11-18 05:43:27 +00:00
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());
2022-11-18 05:43:27 +00:00
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<QString> 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();
2022-12-31 13:05:58 +00:00
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);
}
}
2022-11-18 05:43:27 +00:00