情节列表视图改进完成

This commit is contained in:
玉宇清音 2023-03-11 13:55:16 +08:00
parent 28ac179e8d
commit e53b2a3a49
8 changed files with 120 additions and 77 deletions

View File

@ -18,10 +18,11 @@ using namespace Components;
using namespace Parse::Result; using namespace Parse::Result;
using namespace MakeTools; using namespace MakeTools;
AppCore::AppCore(MainWindow *win, bool record, QObject *parent) AppCore::AppCore(MainWindow *win, QObject *parent)
: QObject(parent), disp_core(new Schedule::CommandsDispatcher(QDir::home(), record)), : QObject(parent), views_holder(win),
views_holder(win), global_config(new Config::XMLConfig(this)), global_config(new Config::XMLConfig(this)),
makes_core(new StoryTool())//, docs_manager(new DocsManager(makes_core, this, win)) makes_core(new StoryTool()) //, docs_manager(new DocsManager(makes_core,
// this, win))
{ {
global_config->loadFile(QDir(QApplication::applicationDirPath()).filePath(".software.xml")); global_config->loadFile(QDir(QApplication::applicationDirPath()).filePath(".software.xml"));
@ -39,7 +40,6 @@ AppCore::AppCore(MainWindow *win, bool record, QObject *parent)
present_types << ins0 << ins1 << ins2 << ins3 << ins4 present_types << ins0 << ins1 << ins2 << ins3 << ins4
<< new DefaultTextPresent(); << new DefaultTextPresent();
} }
void AppCore::registerHighlightType(Enhancement::HighlightFeature *base_type) void AppCore::registerHighlightType(Enhancement::HighlightFeature *base_type)

View File

@ -48,10 +48,8 @@ namespace Core {
*/ */
class AppCore : public QObject, public Schedule::AccessibleObject class AppCore : public QObject, public Schedule::AccessibleObject
{ {
public: public:
Schedule::CommandsDispatcher *const disp_core; AppCore(MainWindow *win, QObject *parent = nullptr);
AppCore(MainWindow *win, bool record, QObject *parent = nullptr);
virtual ~AppCore() = default; virtual ~AppCore() = default;
void registerHighlightType(Enhancement::HighlightFeature *base_type); void registerHighlightType(Enhancement::HighlightFeature *base_type);

View File

@ -382,3 +382,24 @@ QString StoryconceptJumpTo::toText() const { return navi_path.join("/"); }
void StoryconceptJumpTo::fromText(const QString &line) { void StoryconceptJumpTo::fromText(const QString &line) {
navi_path = line.split("/"); navi_path = line.split("/");
} }
StoryfragmentJumpTo::StoryfragmentJumpTo(const QList<QString> &path) {
navi_path.append(path);
}
QString StoryfragmentJumpTo::name() const { return NAME(StoryfragmentJumpTo); }
void StoryfragmentJumpTo::run(Schedule::CommandsDispatcher *core) const {
auto core_ins = core->get<AppCore>(NAME(AppCore));
auto unit_ins = core_ins->parseCore()->queryStoryUnit(navi_path[0]).first();
auto unit_doc = unit_ins->doc();
auto vmgr =
core_ins->disp_core->get<DocumentsManager>(NAME(DocumentsManager));
auto index = vmgr->projectManager()->queryIndex(unit_doc->filePath());
auto route = vmgr->converter(index);
vmgr->openFile(route);
vmgr->activePresentOf(route)->jumpTo(navi_path);
}

View File

@ -210,6 +210,21 @@ namespace CommandList {
QList<QString> navi_path; QList<QString> navi_path;
}; };
class StoryfragmentJumpTo : public Schedule::GeCommand {
public:
StoryfragmentJumpTo(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> navi_path;
};
} // namespace CommandList } // namespace CommandList
#endif // COMMAND_LIST_H #endif // COMMAND_LIST_H

View File

@ -1,87 +1,75 @@
#include "fragmentsorderview.h" #include "fragmentsorderview.h"
#include "DocsManager.h" #include "DocsManager.h"
#include "command_list.h"
#include "manager_docs.h" #include "manager_docs.h"
#include <comdef.h>
#include <StoryUnitDocumentParser.h>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <StoryUnitDocumentParser.h>
#include <comdef.h>
using namespace Components; using namespace Components;
using namespace Parse; using namespace Parse;
FragmentsOrderView::FragmentsOrderView(Core::AppCore *core, QWidget *parent) FragmentsOrderView::FragmentsOrderView(Schedule::CommandsDispatcher *core,
: QWidget(parent), core_ins(core), table_view(new QTableView(this)), QWidget *parent)
table_base(new QStandardItemModel(this)) : QWidget(parent), core_ins(core), table_view(new QTableView(this)) {
{ auto backend =
this->table_view->setModel(table_base); core->get<FragmentsOrderviewModel>(NAME(FragmentsOrderviewModel));
table_base->setHorizontalHeaderLabels(QStringList() << "情节名称" << "单元名称" << "索引值");
this->table_view->setModel(backend->tableModel());
auto layout = new QVBoxLayout(this); auto layout = new QVBoxLayout(this);
layout->addWidget(table_view); layout->addWidget(table_view);
connect(this->table_view, &QTableView::doubleClicked, this, &FragmentsOrderView::double_click); connect(this->table_view, &QTableView::doubleClicked, this, &FragmentsOrderView::double_click);
} }
void FragmentsOrderView::refresh() using namespace CommandList;
{
table_base->clear();
table_base->setHorizontalHeaderLabels(QStringList() << "情节名称" << "单元名称" << "索引值");
auto node_list = core_ins->parseCore()->queryOrdersFragment();
for(auto &ins : node_list){
QList<QStandardItem*> row;
row << new QStandardItem(ins.first->name()[0]);
row << new QStandardItem(ins.first->name()[1]);
row << new QStandardItem(QString("%1").arg(ins.second, 8, 'f'));
for(auto &i : row) i->setEditable(false);
table_base->appendRow(row);
}
}
void FragmentsOrderView::double_click(const QModelIndex &index) void FragmentsOrderView::double_click(const QModelIndex &index)
{ {
if(!index.isValid()) if(!index.isValid())
return; return;
auto frag = table_base->item(index.row());
auto unit = table_base->item(index.row(), 1);
QList<QString> path; QList<QString> path;
path << unit->text() << frag->text(); path << index.sibling(index.row(), 0).data().toString();
path << index.sibling(index.row(), 1).data().toString();
core_ins->postCommand(StoryfragmentJumpTo(path));
}
auto unit_ins = this->core_ins->parseCore()->queryStoryUnit(path[0]).first(); QString FragmentsOrderView::name() const { return NAME(FragmentsOrderView); }
auto unit_doc = unit_ins->doc();
auto vmgr = this->core_ins->disp_core->get<DocumentsManager>(NAME(DocumentsManager)); FragmentsOrderviewModel::FragmentsOrderviewModel(Core::AppCore *core)
index = vmgr->converter(QFileInfo()) : core_ins(core), table_base(new QStandardItemModel) {
this->core_ins->getDocsManager()->openTextDocument(unit_doc->filePath(), unit_doc->docName()); table_base->setHorizontalHeaderLabels(QStringList() << "情节名称"
auto present = this->core_ins->getDocsManager()->queryTextComponent(QFileInfo(unit_doc->filePath())); << "单元名称"
<< "索引值");
}
if(path.size()){ void FragmentsOrderviewModel::refreshTable() {
present->jumpTo(path); table_base->clear();
table_base->setHorizontalHeaderLabels(QStringList() << "情节名称"
<< "单元名称"
<< "索引值");
auto node_list = core_ins->parseCore()->queryOrdersFragment();
for (auto &ins : node_list) {
QList<QStandardItem *> row;
row << new QStandardItem(ins.first->name()[0]);
row << new QStandardItem(ins.first->name()[1]);
row << new QStandardItem(QString("%1").arg(ins.second, 8, 'f'));
for (auto &i : row)
i->setEditable(false);
table_base->appendRow(row);
} }
} }
QString FragmentsOrderView::name() const QStandardItemModel *FragmentsOrderviewModel::tableModel() const {
{ return table_base;
return NAME(FragmentsOrderView);
} }
QString FragmentsOrderviewModel::name() const {
return NAME(FragmentsOrderviewModel);
}

View File

@ -10,27 +10,40 @@
namespace Components { namespace Components {
class FragmentsOrderviewModel : public Schedule::AccessibleObject {
public:
FragmentsOrderviewModel(Core::AppCore *core);
void refreshTable();
QStandardItemModel *tableModel() const;
private:
Core::AppCore *const core_ins;
QStandardItemModel *const table_base;
// AccessibleObject interface
public:
virtual QString name() const override;
};
class FragmentsOrderView : public QWidget, public Schedule::AccessibleObject class FragmentsOrderView : public QWidget, public Schedule::AccessibleObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit FragmentsOrderView(Core::AppCore *core, QWidget *parent = nullptr); explicit FragmentsOrderView(Schedule::CommandsDispatcher *core,
QWidget *parent = nullptr);
void refresh();
void double_click(const QModelIndex &index); void double_click(const QModelIndex &index);
private: private:
Core::AppCore *const core_ins; Schedule::CommandsDispatcher *const core_ins;
QTableView *const table_view; QTableView *const table_view;
QStandardItemModel *const table_base;
// AccessibleObject interface // AccessibleObject interface
public: public:
virtual QString name() const override; virtual QString name() const override;
}; };
} } // namespace Components
#endif // FRAGMENTSORDERVIEW_H #endif // FRAGMENTSORDERVIEW_H

View File

@ -74,6 +74,10 @@ void StoryconceptsPresent::jump_to(const QModelIndex &curr) {
core_ins->postCommand(StoryconceptJumpTo(path)); core_ins->postCommand(StoryconceptJumpTo(path));
} }
QString StoryconceptsPresent::name() const {
return NAME(StoryconceptsPresent);
}
StoryconceptsPresentModel::StoryconceptsPresentModel(Core::AppCore *core) StoryconceptsPresentModel::StoryconceptsPresentModel(Core::AppCore *core)
: core_ins(core), model_base(new QStandardItemModel), : core_ins(core), model_base(new QStandardItemModel),
detail_backend(new QTextDocument) { detail_backend(new QTextDocument) {

View File

@ -46,6 +46,10 @@ namespace Components {
void show_details(const QModelIndex &curr); void show_details(const QModelIndex &curr);
void jump_to(const QModelIndex &curr); void jump_to(const QModelIndex &curr);
// AccessibleObject interface
public:
virtual QString name() const override;
}; };
} }