QtNovelUI/WordsIDE/storyboardspresent.cpp

169 lines
5.4 KiB
C++
Raw Normal View History

2022-11-25 01:18:54 +00:00
#include "storyboardspresent.h"
2023-03-11 07:01:28 +00:00
#include "command_list.h"
#include "opstream.h"
2022-11-25 01:18:54 +00:00
#include <QSplitter>
#include <QVBoxLayout>
using namespace Components;
using namespace Parse::Result;
2023-03-11 07:01:28 +00:00
using namespace DataModel;
StoryboardsPresent::StoryboardsPresent(Schedule::CommandsDispatcher *core,
QWidget *parent)
: QWidget(parent), core_ins(core), tree_view(new QTreeView(this)),
details_view(new QTextEdit(this)) {
auto backend =
core->get<StoryboardsPresentModel>(NAME(StoryboardsPresentModel));
tree_view->setModel(backend->treeModel());
details_view->setDocument(backend->detailBackend());
details_view->setReadOnly(true);
2022-11-25 01:18:54 +00:00
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);
connect(tree_view, &QTreeView::expanded, [this](){
tree_view->resizeColumnToContents(0);
tree_view->resizeColumnToContents(1);
});
2023-03-11 07:01:28 +00:00
connect(tree_view, &QTreeView::clicked, this, &StoryboardsPresent::show_current_details);
}
using namespace CommandList;
void StoryboardsPresent::show_current_details(const QModelIndex &idx) {
if (!idx.isValid())
return;
QList<QString> path;
auto node = idx;
while (true) {
auto name = node.data().toString();
if (name.isEmpty())
break;
path.insert(0, name);
node = node.parent();
}
core_ins->postCommand(StoryboardDetailShow(path));
}
void StoryboardsPresent::jump_to(const QModelIndex &idx) {
if (!idx.isValid())
return;
QList<QString> path;
auto node = idx;
while (true) {
auto name = node.data().toString();
if (name.isEmpty())
break;
path.insert(0, name);
node = node.parent();
}
core_ins->postCommand(StoryboardJumpTo(path));
2022-11-25 01:18:54 +00:00
}
2023-03-11 07:01:28 +00:00
QString StoryboardsPresent::name() const { return NAME(StoryboardsPresent); }
DataModel::StoryboardsPresentModel::StoryboardsPresentModel(Core::AppCore *core)
: core_ins(core), model_base(new QStandardItemModel),
detail_backend(new QTextDocument) {}
void DataModel::StoryboardsPresentModel::refresh() {
2022-11-25 01:18:54 +00:00
model_base->clear();
2023-03-11 07:01:28 +00:00
model_base->setHorizontalHeaderLabels(QStringList() << "名称"
<< "单元");
2022-11-25 01:18:54 +00:00
auto storys = core_ins->parseCore()->allStoryBoards();
2023-03-11 07:01:28 +00:00
for (auto &b : storys) {
auto item = new QStandardItem(static_cast<NamedNode *>(b)->name()[0]);
2022-11-25 01:18:54 +00:00
item->setEditable(false);
model_base->appendRow(item);
auto refers = b->children();
2023-03-11 07:01:28 +00:00
for (auto &ref : refers) {
if (ref->typeValue() != NODE_FRAGMENTREFERENCE)
2022-11-25 01:18:54 +00:00
continue;
2023-03-11 07:01:28 +00:00
QList<QStandardItem *> row;
row << new QStandardItem("@" +
static_cast<NamedNode *>(ref)->name()[0]);
2022-11-25 01:18:54 +00:00
row.last()->setEditable(false);
2023-03-11 07:01:28 +00:00
row << new QStandardItem(static_cast<NamedNode *>(ref)->name()[1]);
2022-11-25 01:18:54 +00:00
row.last()->setEditable(false);
item->appendRow(row);
}
}
}
2023-03-11 07:01:28 +00:00
using namespace Operate;
void DataModel::StoryboardsPresentModel::detailShow(
const QList<QString> &navi) {
QList<QStandardItem *> items_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 &node : navi) {
auto result = OpStream<QStandardItem *>(items_list)
.filter([node](QStandardItem *const &it) {
return node == it->text();
})
.toList();
if (!result.size())
throw new SimpleException("指定的Storyunits路径无效" +
navi.join("/"));
items_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();
}
2023-03-11 07:01:28 +00:00
QString contents;
QStandardItem *item = items_list[0];
if (item->parent() == nullptr) {
auto node = core_ins->parseCore()->queryStoryBoard(item->text());
auto children = node.first()->children();
2023-03-11 07:01:28 +00:00
for (auto &it : children) {
if (it->typeValue() != NODE_FRAGMENTREFERENCE) {
contents += it->toString() + "\n";
}
}
2023-03-11 07:01:28 +00:00
} else {
auto node =
core_ins->parseCore()->queryStoryBoard(item->parent()->text());
auto point = core_ins->parseCore()->queryStoryFragmentRefer(
node.first(), item->text().mid(1));
auto children = point.first()->children();
2023-03-11 07:01:28 +00:00
for (auto &it : children) {
contents += it->toString() + "\n";
}
}
2023-03-11 07:01:28 +00:00
detail_backend->setPlainText(contents);
}
QString DataModel::StoryboardsPresentModel::name() const {
return NAME(StoryboardsPresentModel);
2022-11-25 01:18:54 +00:00
}