2022-11-18 05:43:27 +00:00
|
|
|
|
#include "storychainspresent.h"
|
2022-12-31 13:05:58 +00:00
|
|
|
|
#include "DocsManager.h"
|
2023-03-10 13:01:19 +00:00
|
|
|
|
#include "manager_docs.h"
|
|
|
|
|
#include "command_list.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;
|
2023-03-10 13:01:19 +00:00
|
|
|
|
using namespace CommandList;
|
2022-11-18 05:43:27 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StorychainsPresentModel::StorychainsPresentModel(Core::AppCore *core)
|
|
|
|
|
:core_ins(core),
|
|
|
|
|
model_base(new QStandardItemModel),
|
|
|
|
|
details_base(new QTextDocument)
|
|
|
|
|
{
|
|
|
|
|
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()); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StorychainsPresentModel::~StorychainsPresentModel()
|
|
|
|
|
{
|
|
|
|
|
delete model_base;
|
|
|
|
|
delete details_base;
|
|
|
|
|
delete sync_tools;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStandardItemModel *StorychainsPresentModel::treeModel() const
|
|
|
|
|
{
|
|
|
|
|
return model_base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTextDocument *const StorychainsPresentModel::detailsBackend() const
|
2022-11-18 05:43:27 +00:00
|
|
|
|
{
|
2023-03-10 13:01:19 +00:00
|
|
|
|
return details_base;
|
2022-11-18 05:43:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
void StorychainsPresentModel::refreshTree()
|
2022-11-18 05:43:27 +00:00
|
|
|
|
{
|
2023-03-10 13:01:19 +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-12-01 13:54:04 +00:00
|
|
|
|
}
|
2023-03-10 13:01:19 +00:00
|
|
|
|
return retv;
|
2022-11-18 05:43:27 +00:00
|
|
|
|
}
|
2023-03-10 13:01:19 +00:00
|
|
|
|
else
|
|
|
|
|
return this->core_ins->parseCore()->allStoryChains();
|
|
|
|
|
});
|
2022-11-18 05:43:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
using namespace Operate;
|
|
|
|
|
void StorychainsPresentModel::showDetails(const QList<QString> &chain_path)
|
2022-11-18 05:43:27 +00:00
|
|
|
|
{
|
2023-03-10 13:01:19 +00:00
|
|
|
|
// 获取第一级初始集合
|
|
|
|
|
QList<QStandardItem*> item_list = \
|
|
|
|
|
OpStream<QStandardItem*>([this](int &cnt, int idx)->QStandardItem*
|
|
|
|
|
{
|
|
|
|
|
cnt = model_base->rowCount();
|
|
|
|
|
if(cnt <= 0)
|
|
|
|
|
return nullptr;
|
|
|
|
|
return model_base->item(idx);
|
|
|
|
|
}).select().toList();
|
|
|
|
|
|
|
|
|
|
// 迭代路径获取故事链节点
|
|
|
|
|
for(auto it : chain_path){
|
|
|
|
|
auto result = \
|
|
|
|
|
OpStream<QStandardItem*>(item_list)
|
|
|
|
|
.filter([it](QStandardItem *const &xit)
|
|
|
|
|
{return it == xit->text();})
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
if(!result.size()){
|
|
|
|
|
throw new SimpleException("指定的Storychain路径无效:" + chain_path.join("/"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item_list = \
|
|
|
|
|
OpStream<QStandardItem*>([&result](int &cnt, int idx)->QStandardItem*
|
|
|
|
|
{
|
|
|
|
|
cnt = result[0]->rowCount();
|
|
|
|
|
if(cnt <= 0)
|
|
|
|
|
return nullptr;
|
|
|
|
|
return result[0]->child(idx);
|
|
|
|
|
}).select().toList();
|
|
|
|
|
}
|
2022-11-18 05:43:27 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
// 填充详细内容
|
|
|
|
|
auto item = item_list[0];
|
|
|
|
|
QString text_lines;
|
2022-11-18 05:43:27 +00:00
|
|
|
|
if(item->parent() == nullptr){
|
2022-11-22 03:42:48 +00:00
|
|
|
|
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){
|
2023-03-10 13:01:19 +00:00
|
|
|
|
text_lines += it->toString() + "\n";
|
2022-11-18 05:43:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
2022-11-22 03:42:48 +00:00
|
|
|
|
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){
|
2023-03-10 13:01:19 +00:00
|
|
|
|
text_lines += it->toString() + "\n";
|
2022-11-18 05:43:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-10 13:01:19 +00:00
|
|
|
|
|
|
|
|
|
details_base->setPlainText(text_lines);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString StorychainsPresentModel::name() const
|
|
|
|
|
{
|
|
|
|
|
return NAME(StorychainsPresentModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StorychainsPresent::StorychainsPresent(Schedule::CommandsDispatcher *disp, QWidget *parent)
|
|
|
|
|
: QWidget(parent), disp_core(disp),
|
|
|
|
|
tree_view(new QTreeView(this)), details_show(new QPlainTextEdit)
|
|
|
|
|
{
|
|
|
|
|
auto backend = disp->get<StorychainsPresentModel>(NAME(StorychainsPresentModel));
|
|
|
|
|
|
|
|
|
|
tree_view->setModel(backend->treeModel());
|
|
|
|
|
tree_view->setHeaderHidden(true);
|
|
|
|
|
details_show->setDocument(backend->detailsBackend());
|
|
|
|
|
details_show->setReadOnly(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto layoutx = new QVBoxLayout(this);
|
|
|
|
|
auto split = new QSplitter(Qt::Vertical, this);
|
|
|
|
|
layoutx->addWidget(split);
|
|
|
|
|
split->addWidget(tree_view);
|
|
|
|
|
split->addWidget(details_show);
|
|
|
|
|
layoutx->setMargin(0);
|
|
|
|
|
|
|
|
|
|
connect(tree_view, &QTreeView::clicked,
|
|
|
|
|
this, &StorychainsPresent::details_show);
|
|
|
|
|
connect(tree_view, &QTreeView::doubleClicked,
|
|
|
|
|
this, &StorychainsPresent::jump_to);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString StorychainsPresent::name() const
|
|
|
|
|
{
|
|
|
|
|
return NAME(StorychainsPresent);
|
2022-11-18 05:43:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
void StorychainsPresent::jump_to(const QModelIndex &curr)
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
|
|
|
|
if(!curr.isValid())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QList<QString> path;
|
2023-03-10 13:27:46 +00:00
|
|
|
|
auto node = curr;
|
2023-03-10 13:01:19 +00:00
|
|
|
|
while (true) {
|
2023-03-10 13:27:46 +00:00
|
|
|
|
auto node_name = node.data().toString();
|
2023-03-10 13:01:19 +00:00
|
|
|
|
|
2023-03-10 13:27:46 +00:00
|
|
|
|
if (node_name.isEmpty())
|
2023-03-10 13:01:19 +00:00
|
|
|
|
break;
|
2023-03-10 13:27:46 +00:00
|
|
|
|
path.insert(0, node_name);
|
|
|
|
|
node = node.parent();
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
disp_core->postCommand(StorychainJumpTo(path));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StorychainsPresent::detail_show(const QModelIndex &curr)
|
|
|
|
|
{
|
|
|
|
|
if(!curr.isValid())
|
|
|
|
|
return;
|
2022-11-22 06:15:36 +00:00
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
QList<QString> path;
|
2023-03-10 13:27:46 +00:00
|
|
|
|
auto node = curr;
|
2023-03-10 13:01:19 +00:00
|
|
|
|
while (true) {
|
2023-03-10 13:27:46 +00:00
|
|
|
|
auto node_name = node.data().toString();
|
2023-03-10 13:01:19 +00:00
|
|
|
|
|
2023-03-10 13:27:46 +00:00
|
|
|
|
if (node_name.isEmpty())
|
2023-03-10 13:01:19 +00:00
|
|
|
|
break;
|
2023-03-10 13:27:46 +00:00
|
|
|
|
path.insert(0, node_name);
|
|
|
|
|
node = node.parent();
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 13:01:19 +00:00
|
|
|
|
disp_core->postCommand(StorychainDetailShow(path));
|
|
|
|
|
}
|
2022-11-18 05:43:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|