storyunitspresent改造完成
This commit is contained in:
parent
4e7354d075
commit
6def2aa88e
|
@ -265,6 +265,7 @@ void StorychainJumpTo::fromText(const QString &line)
|
|||
|
||||
|
||||
#include "storychainspresent.h"
|
||||
#include "storyunitspresent.h"
|
||||
using namespace Components;
|
||||
|
||||
StorychainDetailShow::StorychainDetailShow(const QList<QString> &chain_path)
|
||||
|
@ -294,27 +295,44 @@ void StorychainDetailShow::fromText(const QString &line)
|
|||
chain_path = line.split("/");
|
||||
}
|
||||
|
||||
StoryunitDetailShow::StoryunitDetailShow(const QList<QString> &path) {
|
||||
unit_nav.append(path);
|
||||
}
|
||||
|
||||
QString StoryunitDetailShow::name() const { return NAME(StoryunitDetailShow); }
|
||||
|
||||
void StoryunitDetailShow::run(Schedule::CommandsDispatcher *core) const {
|
||||
auto backend =
|
||||
core->get<StoryunitsPresentModel>(NAME(StoryunitsPresentModel));
|
||||
backend->details_show(unit_nav);
|
||||
}
|
||||
|
||||
QString StoryunitDetailShow::toText() const { return unit_nav.join("/"); }
|
||||
|
||||
void StoryunitDetailShow::fromText(const QString &line) {
|
||||
unit_nav = line.split("/");
|
||||
}
|
||||
|
||||
StoryunitJumpTo::StoryunitJumpTo(const QList<QString> &path) {
|
||||
unit_nav = path;
|
||||
}
|
||||
|
||||
QString StoryunitJumpTo::name() const { return NAME(StoryunitJumpTo); }
|
||||
|
||||
void StoryunitJumpTo::run(Schedule::CommandsDispatcher *core) const {
|
||||
auto core_ins = core->get<AppCore>(NAME(AppCore));
|
||||
auto vmgr = core->get<DocumentsManager>(NAME(DocumentsManager));
|
||||
|
||||
auto unit_ins = core_ins->parseCore()->queryStoryUnit(unit_nav[0]).first();
|
||||
auto index =
|
||||
vmgr->projectManager()->queryIndex(unit_ins->doc()->filePath());
|
||||
auto pjt_path = vmgr->converter(index);
|
||||
vmgr->openFile(pjt_path);
|
||||
vmgr->activePresentOf(pjt_path)->jumpTo(unit_nav);
|
||||
}
|
||||
|
||||
QString StoryunitJumpTo::toText() const { return unit_nav.join("/"); }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void StoryunitJumpTo::fromText(const QString &line) {
|
||||
unit_nav = line.split("/");
|
||||
}
|
||||
|
|
|
@ -150,6 +150,36 @@ namespace CommandList {
|
|||
QList<QString> jump_path;
|
||||
};
|
||||
|
||||
class StoryunitDetailShow : public Schedule::GeCommand {
|
||||
public:
|
||||
StoryunitDetailShow(const QList<QString> &path);
|
||||
|
||||
// GeCommand interface
|
||||
public:
|
||||
virtual QString name() const override;
|
||||
virtual void run(Schedule::CommandsDispatcher *core) const override;
|
||||
virtual QString toText() const override;
|
||||
virtual void fromText(const QString &line) override;
|
||||
|
||||
private:
|
||||
QList<QString> unit_nav;
|
||||
};
|
||||
|
||||
class StoryunitJumpTo : public Schedule::GeCommand {
|
||||
public:
|
||||
StoryunitJumpTo(const QList<QString> &path);
|
||||
|
||||
// GeCommand interface
|
||||
public:
|
||||
virtual QString name() const override;
|
||||
virtual void run(Schedule::CommandsDispatcher *core) const override;
|
||||
virtual QString toText() const override;
|
||||
virtual void fromText(const QString &line) override;
|
||||
|
||||
private:
|
||||
QList<QString> unit_nav;
|
||||
};
|
||||
|
||||
} // namespace CommandList
|
||||
|
||||
#endif // COMMAND_LIST_H
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "storychainspresent.h"
|
||||
#include "DocsManager.h"
|
||||
#include "manager_docs.h"
|
||||
#include "command_list.h"
|
||||
#include "manager_docs.h"
|
||||
|
||||
#include <QSplitter>
|
||||
#include <QVBoxLayout>
|
||||
|
@ -12,110 +12,105 @@ using namespace Parse::Result;
|
|||
using namespace Tools;
|
||||
using namespace CommandList;
|
||||
|
||||
|
||||
|
||||
StorychainsPresentModel::StorychainsPresentModel(Core::AppCore *core)
|
||||
:core_ins(core),
|
||||
model_base(new QStandardItemModel),
|
||||
details_base(new QTextDocument)
|
||||
{
|
||||
sync_tools = new ModelSyncs<DesNode*>(
|
||||
: 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) -> bool {
|
||||
return static_cast<NamedNode *>(d)->name().first() == it->text();
|
||||
},
|
||||
[](DesNode *const &d, QStandardItem *it) {
|
||||
it->setText(static_cast<NamedNode*>(d)->name().first()); });
|
||||
it->setText(static_cast<NamedNode *>(d)->name().first());
|
||||
});
|
||||
}
|
||||
|
||||
StorychainsPresentModel::~StorychainsPresentModel()
|
||||
{
|
||||
StorychainsPresentModel::~StorychainsPresentModel() {
|
||||
delete model_base;
|
||||
delete details_base;
|
||||
delete sync_tools;
|
||||
}
|
||||
|
||||
QStandardItemModel *StorychainsPresentModel::treeModel() const
|
||||
{
|
||||
QStandardItemModel *StorychainsPresentModel::treeModel() const {
|
||||
return model_base;
|
||||
}
|
||||
|
||||
QTextDocument *const StorychainsPresentModel::detailsBackend() const
|
||||
{
|
||||
QTextDocument *const StorychainsPresentModel::detailsBackend() const {
|
||||
return details_base;
|
||||
}
|
||||
|
||||
void StorychainsPresentModel::refreshTree()
|
||||
{
|
||||
sync_tools->presentSync(
|
||||
[this](DesNode *p)->QList<DesNode*>{
|
||||
if(p){
|
||||
QList<DesNode*> retv;
|
||||
for(auto &point : p->children()){
|
||||
if(point->typeValue() == NODE_STORYPOINT){
|
||||
void StorychainsPresentModel::refreshTree() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
return retv;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return this->core_ins->parseCore()->allStoryChains();
|
||||
});
|
||||
}
|
||||
|
||||
using namespace Operate;
|
||||
void StorychainsPresentModel::showDetails(const QList<QString> &chain_path)
|
||||
{
|
||||
void StorychainsPresentModel::showDetails(const QList<QString> &chain_path) {
|
||||
// 获取第一级初始集合
|
||||
QList<QStandardItem*> item_list = \
|
||||
OpStream<QStandardItem*>([this](int &cnt, int idx)->QStandardItem*
|
||||
{
|
||||
QList<QStandardItem *> item_list =
|
||||
OpStream<QStandardItem *>([this](int &cnt, int idx) -> QStandardItem * {
|
||||
cnt = model_base->rowCount();
|
||||
if(cnt <= 0)
|
||||
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();})
|
||||
})
|
||||
.select()
|
||||
.toList();
|
||||
|
||||
if(!result.size()){
|
||||
throw new SimpleException("指定的Storychain路径无效:" + chain_path.join("/"));
|
||||
// 迭代路径获取故事链节点
|
||||
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*
|
||||
{
|
||||
item_list = OpStream<QStandardItem *>(
|
||||
[&result](int &cnt, int idx) -> QStandardItem * {
|
||||
cnt = result[0]->rowCount();
|
||||
if(cnt <= 0)
|
||||
if (cnt <= 0)
|
||||
return nullptr;
|
||||
return result[0]->child(idx);
|
||||
}).select().toList();
|
||||
})
|
||||
.select()
|
||||
.toList();
|
||||
}
|
||||
|
||||
// 填充详细内容
|
||||
auto item = item_list[0];
|
||||
QString text_lines;
|
||||
if(item->parent() == nullptr){
|
||||
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){
|
||||
for (auto &it : children) {
|
||||
if (it->typeValue() != NODE_STORYPOINT) {
|
||||
text_lines += it->toString() + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
auto node = core_ins->parseCore()->queryStoryChain(item->parent()->text());
|
||||
auto point = core_ins->parseCore()->queryStoryPoint(node.first(), item->text());
|
||||
} 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){
|
||||
for (auto &it : children) {
|
||||
text_lines += it->toString() + "\n";
|
||||
}
|
||||
}
|
||||
|
@ -123,25 +118,22 @@ void StorychainsPresentModel::showDetails(const QList<QString> &chain_path)
|
|||
details_base->setPlainText(text_lines);
|
||||
}
|
||||
|
||||
QString StorychainsPresentModel::name() const
|
||||
{
|
||||
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));
|
||||
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);
|
||||
|
@ -149,20 +141,16 @@ StorychainsPresent::StorychainsPresent(Schedule::CommandsDispatcher *disp, QWidg
|
|||
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);
|
||||
connect(tree_view, &QTreeView::clicked, this,
|
||||
&StorychainsPresent::detail_show);
|
||||
connect(tree_view, &QTreeView::doubleClicked, this,
|
||||
&StorychainsPresent::jump_to);
|
||||
}
|
||||
|
||||
QString StorychainsPresent::name() const
|
||||
{
|
||||
return NAME(StorychainsPresent);
|
||||
}
|
||||
QString StorychainsPresent::name() const { return NAME(StorychainsPresent); }
|
||||
|
||||
void StorychainsPresent::jump_to(const QModelIndex &curr)
|
||||
{
|
||||
if(!curr.isValid())
|
||||
void StorychainsPresent::jump_to(const QModelIndex &curr) {
|
||||
if (!curr.isValid())
|
||||
return;
|
||||
|
||||
QList<QString> path;
|
||||
|
@ -179,9 +167,8 @@ void StorychainsPresent::jump_to(const QModelIndex &curr)
|
|||
disp_core->postCommand(StorychainJumpTo(path));
|
||||
}
|
||||
|
||||
void StorychainsPresent::detail_show(const QModelIndex &curr)
|
||||
{
|
||||
if(!curr.isValid())
|
||||
void StorychainsPresent::detail_show(const QModelIndex &curr) {
|
||||
if (!curr.isValid())
|
||||
return;
|
||||
|
||||
QList<QString> path;
|
||||
|
@ -197,16 +184,3 @@ void StorychainsPresent::detail_show(const QModelIndex &curr)
|
|||
|
||||
disp_core->postCommand(StorychainDetailShow(path));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
#include "storyunitspresent.h"
|
||||
#include "DocsManager.h"
|
||||
#include "command_list.h"
|
||||
#include "opstream.h"
|
||||
|
||||
#include <QSplitter>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
using namespace Components;
|
||||
using namespace Parse::Result;
|
||||
using namespace Operate;
|
||||
|
||||
StoryunitsPresentModel::StoryunitsPresentModel(Core::AppCore *core)
|
||||
: core_ins(core), model_ins(new QStandardItemModel),
|
||||
|
@ -24,7 +27,7 @@ QTextDocument *StoryunitsPresentModel::detailsBackend() const {
|
|||
return details_backend;
|
||||
}
|
||||
|
||||
void StoryunitsPresentModel::refresh() {
|
||||
void StoryunitsPresentModel::refreshTree() {
|
||||
model_ins->clear();
|
||||
auto units = core_ins->parseCore()->allStoryUnits();
|
||||
for (auto &unit : units) {
|
||||
|
@ -45,19 +48,49 @@ void StoryunitsPresentModel::refresh() {
|
|||
}
|
||||
}
|
||||
|
||||
void StoryunitsPresentModel::show_node_description(const QModelIndex &curr) {
|
||||
if (!curr.isValid())
|
||||
return;
|
||||
void StoryunitsPresentModel::details_show(const QList<QString> &path) {
|
||||
QList<QStandardItem *> items_list =
|
||||
OpStream<QStandardItem *>([this](int &cnt, int idx) -> QStandardItem * {
|
||||
cnt = model_ins->rowCount();
|
||||
if (cnt <= 0)
|
||||
return nullptr;
|
||||
return model_ins->item(idx);
|
||||
})
|
||||
.select()
|
||||
.toList();
|
||||
|
||||
details_show->clear();
|
||||
auto item = model_ins->itemFromIndex(curr);
|
||||
for (auto &node : path) {
|
||||
auto result = OpStream<QStandardItem *>(items_list)
|
||||
.filter([node](QStandardItem *const &it) {
|
||||
return node == it->text();
|
||||
})
|
||||
.toList();
|
||||
|
||||
if (!result.size())
|
||||
throw new SimpleException("指定的Storyunits路径无效:" +
|
||||
path.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();
|
||||
}
|
||||
|
||||
// 填充详细内容
|
||||
QString contents;
|
||||
auto item = items_list[0];
|
||||
if (item->parent() == nullptr) {
|
||||
auto node = core_ins->parseCore()->queryStoryUnit(item->text());
|
||||
|
||||
auto children = node.first()->children();
|
||||
for (auto &it : children) {
|
||||
if (it->typeValue() != NODE_STORYFRAGMENT) {
|
||||
details_show->appendPlainText(it->toString());
|
||||
contents += it->toString() + "\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -68,38 +101,16 @@ void StoryunitsPresentModel::show_node_description(const QModelIndex &curr) {
|
|||
|
||||
auto children = point.first()->children();
|
||||
for (auto &it : children) {
|
||||
details_show->appendPlainText(it->toString());
|
||||
contents += it->toString() + "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StoryunitsPresentModel::click_to(const QModelIndex &curr) {
|
||||
if (!curr.isValid())
|
||||
return;
|
||||
|
||||
auto pnode = this->model_ins->itemFromIndex(curr);
|
||||
QList<QString> path;
|
||||
while (pnode) {
|
||||
path.insert(0, pnode->text());
|
||||
pnode = pnode->parent();
|
||||
}
|
||||
|
||||
auto unit_ins =
|
||||
this->core_ins->parseCore()->queryStoryUnit(path[0]).first();
|
||||
auto chain_doc = unit_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);
|
||||
}
|
||||
details_backend->setPlainText(contents);
|
||||
}
|
||||
|
||||
StoryunitsPresent::StoryunitsPresent(Schedule::CommandsDispatcher *core,
|
||||
QWidget *parent)
|
||||
: QWidget(parent), core_ins(core), units_view(new QTreeView(this)),
|
||||
: QWidget(parent), disp_core(core), units_view(new QTreeView(this)),
|
||||
details_show(new QTextEdit(this)) {
|
||||
auto backend =
|
||||
core->get<StoryunitsPresentModel>(NAME(StoryunitsPresentModel));
|
||||
|
@ -123,3 +134,32 @@ StoryunitsPresent::StoryunitsPresent(Schedule::CommandsDispatcher *core,
|
|||
}
|
||||
|
||||
QString StoryunitsPresent::name() const { return NAME(StoryunitsPresent); }
|
||||
|
||||
using namespace CommandList;
|
||||
void StoryunitsPresent::jump_to(const QModelIndex &curr) {
|
||||
QList<QString> path;
|
||||
QModelIndex node = curr;
|
||||
while (true) {
|
||||
auto node_name = node.data().toString();
|
||||
if (node_name.isEmpty())
|
||||
break;
|
||||
path.insert(0, node_name);
|
||||
node = node.parent();
|
||||
}
|
||||
|
||||
disp_core->postCommand(StoryunitJumpTo(path));
|
||||
}
|
||||
|
||||
void StoryunitsPresent::show_details(const QModelIndex &curr) {
|
||||
QList<QString> path;
|
||||
QModelIndex node = curr;
|
||||
while (true) {
|
||||
auto node_name = node.data().toString();
|
||||
if (node_name.isEmpty())
|
||||
break;
|
||||
path.insert(0, node_name);
|
||||
node = node.parent();
|
||||
}
|
||||
|
||||
disp_core->postCommand(StoryunitDetailShow(path));
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ namespace Components {
|
|||
QStandardItemModel *treeModel() const;
|
||||
QTextDocument *detailsBackend() const;
|
||||
|
||||
void refresh();
|
||||
void show_node_description(const QModelIndex &curr);
|
||||
void refreshTree();
|
||||
void details_show(const QList<QString> &path);
|
||||
|
||||
// AccessibleObject interface
|
||||
public:
|
||||
|
@ -45,7 +45,7 @@ namespace Components {
|
|||
virtual QString name() const override;
|
||||
|
||||
private:
|
||||
Schedule::CommandsDispatcher *const core_ins;
|
||||
Schedule::CommandsDispatcher *const disp_core;
|
||||
QTreeView *const units_view;
|
||||
QTextEdit *const details_show;
|
||||
|
||||
|
|
Loading…
Reference in New Issue