90 lines
2.7 KiB
C++
90 lines
2.7 KiB
C++
#include "storyboardspresent.h"
|
|
|
|
#include <QSplitter>
|
|
#include <QVBoxLayout>
|
|
|
|
using namespace Components;
|
|
using namespace Parse::Result;
|
|
|
|
StoryBoardsPresent::StoryBoardsPresent(Core::AppCore *core, QWidget *parent)
|
|
: QWidget(parent), core_ins(core),
|
|
tree_view(new QTreeView(this)), details_view(new QTextEdit(this)),
|
|
model_base(new QStandardItemModel(this))
|
|
{
|
|
tree_view->setModel(model_base);
|
|
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);
|
|
details_view->setReadOnly(true);
|
|
|
|
connect(tree_view, &QTreeView::expanded, [this](){
|
|
tree_view->resizeColumnToContents(0);
|
|
tree_view->resizeColumnToContents(1);
|
|
});
|
|
|
|
connect(tree_view, &QTreeView::clicked, this, &StoryBoardsPresent::show_current_details);
|
|
}
|
|
|
|
void StoryBoardsPresent::refresh()
|
|
{
|
|
model_base->clear();
|
|
model_base->setHorizontalHeaderLabels(QStringList() << "名称" << "单元");
|
|
auto storys = core_ins->parseCore()->allStoryBoards();
|
|
|
|
for(auto &b : storys){
|
|
auto item = new QStandardItem(static_cast<NamedNode*>(b)->name()[0]);
|
|
item->setEditable(false);
|
|
model_base->appendRow(item);
|
|
|
|
auto refers = b->children();
|
|
for(auto &ref : refers){
|
|
if(ref->typeValue() != NODE_FRAGMENTREFERENCE)
|
|
continue;
|
|
|
|
QList<QStandardItem*> row;
|
|
row << new QStandardItem("@"+static_cast<NamedNode*>(ref)->name()[0]);
|
|
row.last()->setEditable(false);
|
|
row << new QStandardItem(static_cast<NamedNode*>(ref)->name()[1]);
|
|
row.last()->setEditable(false);
|
|
|
|
item->appendRow(row);
|
|
}
|
|
}
|
|
|
|
this->tree_view->resizeColumnToContents(0);
|
|
}
|
|
|
|
void StoryBoardsPresent::show_current_details(const QModelIndex &idx)
|
|
{
|
|
if(!idx.isValid())
|
|
return;
|
|
|
|
details_view->clear();
|
|
auto item = model_base->itemFromIndex(idx.sibling(idx.row(), 0));
|
|
if(item->parent() == nullptr){
|
|
auto node = core_ins->parseCore()->queryStoryBoard(item->text());
|
|
|
|
auto children = node.first()->children();
|
|
for(auto &it : children){
|
|
if(it->typeValue() != NODE_FRAGMENTREFERENCE){
|
|
details_view->append(it->toString());
|
|
}
|
|
}
|
|
}
|
|
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();
|
|
for(auto &it : children){
|
|
details_view->append(it->toString());
|
|
}
|
|
}
|
|
|
|
}
|