脉络视图及其基础构建
This commit is contained in:
parent
c1f17f4be2
commit
dbbdece7fe
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.15.0, 2022-11-17T13:44:35. -->
|
||||
<!-- Written by QtCreator 4.15.0, 2022-11-18T11:14:33. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
@ -99,7 +99,7 @@
|
|||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.51211.win64_msvc2017_64_kit</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">2</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||
<value type="int" key="EnableQmlDebugging">0</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\Projects\Cpp\build-QtNovelDesc-Desktop_Qt_5_12_11_MSVC2017_64bit-Debug</value>
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
#include "SourceEditView.h"
|
||||
#include "chainhightlighter.h"
|
||||
#include "keywordshightlighter.h"
|
||||
#include <QMenu>
|
||||
|
||||
using namespace Components;
|
||||
using namespace Parse::Result;
|
||||
using namespace Enhancement;
|
||||
|
||||
StoryChainSourceEdit::StoryChainSourceEdit(const QFileInfo &file, QWidget *parent)
|
||||
: MakeTools::VariedTextView(file,parent), edit_square(new QTextEdit(parent)),
|
||||
highter_ins(new Enhancement::ChainHightlighter(this)),
|
||||
highter_ins(new KeywordsHightlighter(this)),
|
||||
core_ins(nullptr)
|
||||
{
|
||||
connect(edit_square, &QTextEdit::textChanged, [this](){
|
||||
|
@ -14,6 +16,14 @@ StoryChainSourceEdit::StoryChainSourceEdit(const QFileInfo &file, QWidget *paren
|
|||
});
|
||||
|
||||
highter_ins->setDocument(this->edit_square->document());
|
||||
|
||||
edit_square->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(edit_square, &QTextEdit::customContextMenuRequested, [this](const QPoint &pos){
|
||||
auto menu = edit_square->createStandardContextMenu();
|
||||
menu->addSeparator();
|
||||
menu->addAction("刷新", [this](){highter_ins->rehighlight();});
|
||||
menu->exec(edit_square->mapToGlobal(pos));
|
||||
});
|
||||
}
|
||||
|
||||
void StoryChainSourceEdit::modeReset(const QString &) const{}
|
||||
|
@ -36,7 +46,7 @@ QString StoryChainSourceEdit::title() const
|
|||
void StoryChainSourceEdit::reset(Parse::Result::DocCore *syntax_base)
|
||||
{
|
||||
this->core_ins = syntax_base;
|
||||
static_cast<Enhancement::ChainHightlighter*>(this->highter_ins)->reset(core_ins);
|
||||
static_cast<Enhancement::KeywordsHightlighter*>(this->highter_ins)->reset(core_ins);
|
||||
}
|
||||
|
||||
QWidget *StoryChainSourceEdit::textView() const
|
||||
|
|
|
@ -12,20 +12,22 @@ SOURCES += \
|
|||
ContentPresent.cpp \
|
||||
SensitiveCore.cpp \
|
||||
SourceEditView.cpp \
|
||||
chainhightlighter.cpp \
|
||||
keywordshightlighter.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
messagepresent.cpp \
|
||||
projectview.cpp
|
||||
projectview.cpp \
|
||||
storychainspresent.cpp
|
||||
|
||||
HEADERS += \
|
||||
ContentPresent.h \
|
||||
SensitiveCore.h \
|
||||
SourceEditView.h \
|
||||
chainhightlighter.h \
|
||||
keywordshightlighter.h \
|
||||
mainwindow.h \
|
||||
messagepresent.h \
|
||||
projectview.h
|
||||
projectview.h \
|
||||
storychainspresent.h
|
||||
|
||||
TRANSLATIONS += \
|
||||
WordsIDE_zh_CN.ts
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
#include "chainhightlighter.h"
|
||||
#include "keywordshightlighter.h"
|
||||
#include <QDebug>
|
||||
|
||||
using namespace Parse;
|
||||
using namespace Enhancement;
|
||||
|
||||
ChainHightlighter::ChainHightlighter(QObject *parent)
|
||||
KeywordsHightlighter::KeywordsHightlighter(QObject *parent)
|
||||
: QSyntaxHighlighter(parent), parse_core(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ChainHightlighter::reset(Parse::Result::DocCore *base)
|
||||
void KeywordsHightlighter::reset(Parse::Result::DocCore *base)
|
||||
{
|
||||
this->parse_core = base;
|
||||
}
|
||||
|
||||
void ChainHightlighter::highlightBlock(const QString &text)
|
||||
void KeywordsHightlighter::highlightBlock(const QString &text)
|
||||
{
|
||||
if(parse_core == nullptr)
|
||||
return;
|
|
@ -11,10 +11,10 @@ namespace Enhancement {
|
|||
/**
|
||||
* @brief 词语语法高亮
|
||||
*/
|
||||
class ChainHightlighter : public QSyntaxHighlighter
|
||||
class KeywordsHightlighter : public QSyntaxHighlighter
|
||||
{
|
||||
public:
|
||||
ChainHightlighter(QObject *parent = nullptr);
|
||||
KeywordsHightlighter(QObject *parent = nullptr);
|
||||
void reset(Parse::Result::DocCore *base);
|
||||
|
||||
private:
|
|
@ -28,9 +28,11 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
center_funcs(new QTabWidget(this)),
|
||||
bottom_funcs(new QTabWidget(this)),
|
||||
project_manager(new XMLProjectManager(this)),
|
||||
syntax_core(new ParseCore()),
|
||||
make_tool(new StoryTool(syntax_core)),
|
||||
parse_core(new ParseCore()),
|
||||
make_tool(new StoryTool(parse_core)),
|
||||
project_list(new QListView(this)),
|
||||
project_view(new ProjectView(project_manager, this)),
|
||||
chains_view(new StoryChainsPresent(parse_core, this)),
|
||||
errors_present(new MessagePresent(make_tool, this)),
|
||||
framework(new SensitiveCore(make_tool))
|
||||
{
|
||||
|
@ -193,7 +195,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
this->vertical_split->addWidget(bottom_funcs);
|
||||
setCentralWidget(this->horizontal_split);
|
||||
|
||||
center_funcs->addTab(new QTextEdit(this), "编辑区域");
|
||||
center_funcs->addTab(project_list, "欢迎界面");
|
||||
left_funcs->addTab(project_view, "项目管理");
|
||||
connect(project_view, &ProjectView::activeDocument, [this](const QString &file_path, const QString &name){
|
||||
if(framework->contains(file_path)){
|
||||
|
@ -206,7 +208,11 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
if(file_path.endsWith("storychain")){
|
||||
tview = new Components::StoryChainSourceEdit(QFileInfo(file_path), this);
|
||||
framework->addPerceptionList(tview);
|
||||
auto doc = syntax_core->queryDocument(QFileInfo(file_path));
|
||||
auto doc = parse_core->queryDocument(QFileInfo(file_path));
|
||||
if(doc == nullptr){
|
||||
this->make_tool->compile(QFileInfo(file_path));
|
||||
doc = parse_core->queryDocument(QFileInfo(file_path));
|
||||
}
|
||||
tview->reset(doc);
|
||||
}
|
||||
else if(file_path.endsWith("storyunit")){
|
||||
|
@ -244,7 +250,12 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
center_funcs->setCurrentWidget(tview->textView());
|
||||
});
|
||||
bottom_funcs->addTab(errors_present, "错误列表");
|
||||
framework->addProcTrigger([this](){ errors_present->refresh(); });
|
||||
right_funcs->addTab(chains_view, "脉络展示");
|
||||
|
||||
framework->addProcTrigger([this](){
|
||||
errors_present->refresh();
|
||||
chains_view->refresh();
|
||||
});
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -273,6 +284,7 @@ void MainWindow::build_internal(bool all_from_disk)
|
|||
make_tool->compile(it);
|
||||
|
||||
errors_present->refresh();
|
||||
chains_view->refresh();
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
|
|
|
@ -7,8 +7,10 @@
|
|||
#include <ProjectManager.h>
|
||||
#include <StoryTool.h>
|
||||
#include <QTreeView>
|
||||
#include <QListView>
|
||||
#include "SensitiveCore.h"
|
||||
#include "messagepresent.h"
|
||||
#include "storychainspresent.h"
|
||||
#include "projectview.h"
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
|
@ -30,10 +32,12 @@ private:
|
|||
|
||||
|
||||
Project::ProjectManager *const project_manager;
|
||||
Parse::Result::ParseCore *const syntax_core;
|
||||
Parse::Result::ParseCore *const parse_core;
|
||||
MakeTools::StoryTool *const make_tool;
|
||||
|
||||
QListView *const project_list;
|
||||
Components::ProjectView *const project_view;
|
||||
Components::StoryChainsPresent *const chains_view;
|
||||
Components::MessagePresent *const errors_present;
|
||||
|
||||
MakeTools::SensitiveCore *const framework;
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
#include "storychainspresent.h"
|
||||
|
||||
#include <QSplitter>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
using namespace Components;
|
||||
using namespace Parse;
|
||||
using namespace Parse::Result;
|
||||
|
||||
StoryChainsPresent::StoryChainsPresent(Parse::Result::ParseCore *core, QWidget *parent)
|
||||
: QWidget(parent), core_ins(core), model_base(new QStandardItemModel(this)),
|
||||
tree_view(new QTreeView(this)), details_show(new QPlainTextEdit(this))
|
||||
{
|
||||
tree_view->setModel(model_base);
|
||||
tree_view->setHeaderHidden(true);
|
||||
|
||||
auto layoutx = new QVBoxLayout(this);
|
||||
layoutx->setMargin(0);
|
||||
auto split = new QSplitter(Qt::Vertical, this);
|
||||
layoutx->addWidget(split);
|
||||
split->addWidget(tree_view);
|
||||
split->addWidget(details_show);
|
||||
details_show->setReadOnly(true);
|
||||
|
||||
connect(tree_view, &QTreeView::clicked, this, &StoryChainsPresent::action_details_show);
|
||||
}
|
||||
|
||||
void StoryChainsPresent::refresh()
|
||||
{
|
||||
model_base->clear();
|
||||
auto list = core_ins->allStoryChains();
|
||||
for(auto &chain : list){
|
||||
auto chain_node = new QStandardItem(static_cast<NamedNode*>(chain)->name());
|
||||
chain_node->setEditable(false);
|
||||
model_base->appendRow(chain_node);
|
||||
|
||||
auto children = chain->children();
|
||||
for(auto &point : children){
|
||||
if(point->typeValue() == NODE_STORYPOINT){
|
||||
auto point_node = new QStandardItem(static_cast<NamedNode*>(point)->name());
|
||||
point_node->setEditable(false);
|
||||
chain_node->appendRow(point_node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StoryChainsPresent::action_details_show(const QModelIndex &curr)
|
||||
{
|
||||
if(!curr.isValid())
|
||||
return;
|
||||
|
||||
details_show->clear();
|
||||
auto item = model_base->itemFromIndex(curr);
|
||||
if(item->parent() == nullptr){
|
||||
auto node = core_ins->queryStoryChain(item->text());
|
||||
|
||||
auto children = node.first()->children();
|
||||
for(auto &it : children){
|
||||
if(it->typeValue() != NODE_STORYPOINT){
|
||||
details_show->appendPlainText(it->toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
auto node = core_ins->queryStoryChain(item->parent()->text());
|
||||
auto point = core_ins->queryStoryPoint(node.first(), item->text());
|
||||
|
||||
auto children = point.first()->children();
|
||||
for(auto &it : children){
|
||||
details_show->appendPlainText(it->toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef STORYCHAINSPRESENT_H
|
||||
#define STORYCHAINSPRESENT_H
|
||||
|
||||
#include <QPlainTextEdit>
|
||||
#include <QStandardItemModel>
|
||||
#include <QTreeView>
|
||||
#include <QWidget>
|
||||
#include <libParse.h>
|
||||
|
||||
namespace Components {
|
||||
|
||||
class StoryChainsPresent : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit StoryChainsPresent(Parse::Result::ParseCore *core, QWidget *parent = nullptr);
|
||||
|
||||
void refresh();
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
Parse::Result::ParseCore *const core_ins;
|
||||
QStandardItemModel *const model_base;
|
||||
QTreeView *const tree_view;
|
||||
QPlainTextEdit *const details_show;
|
||||
|
||||
void action_details_show(const QModelIndex &curr);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // STORYCHAINSPRESENT_H
|
|
@ -48,6 +48,7 @@ QList<QString> StoryTool::compile(const QFileInfo &file)
|
|||
results.append(parser.analysis(doc_core, file.absoluteFilePath()));
|
||||
}
|
||||
|
||||
parse_core->registerDoc(doc_core);
|
||||
for(auto n : results)
|
||||
parse_core->registerNode(doc_core, n);
|
||||
|
||||
|
|
|
@ -160,17 +160,26 @@ void ParseCore::deleteDocument(DocCore *ins)
|
|||
delete ins;
|
||||
}
|
||||
|
||||
QList<Result::DesNode*> ParseCore::queryStoryChain(const QString &name) const
|
||||
QList<DesNode *> ParseCore::allStoryChains() const
|
||||
{
|
||||
QList<Result::DesNode*> retlist;
|
||||
auto keys = nodes_map.keys();
|
||||
for(auto &k : keys)
|
||||
if(k->docType() == DocType::STORYCHAIN)
|
||||
for(auto &n : *nodes_map[k]){
|
||||
if(n->typeValue()==NODE_STORYCHAIN &&
|
||||
static_cast<NamedNode*>(n)->name() == name)
|
||||
for(auto &n : *nodes_map[k])
|
||||
if(n->typeValue()==NODE_STORYCHAIN)
|
||||
retlist << n;
|
||||
}
|
||||
|
||||
return retlist;
|
||||
}
|
||||
|
||||
QList<Result::DesNode*> ParseCore::queryStoryChain(const QString &name) const
|
||||
{
|
||||
QList<Result::DesNode*> retlist;
|
||||
|
||||
for(auto &xnode : allStoryChains())
|
||||
if(static_cast<NamedNode*>(xnode)->name() == name)
|
||||
retlist << xnode;
|
||||
|
||||
return retlist;
|
||||
}
|
||||
|
|
|
@ -305,6 +305,7 @@ namespace Parse
|
|||
virtual Result::DocCore* queryDocument(const QFileInfo &file_src) const;
|
||||
virtual void deleteDocument(Result::DocCore *ins);
|
||||
|
||||
virtual QList<Result::DesNode*> allStoryChains() const;
|
||||
virtual QList<Result::DesNode*> queryStoryChain(const QString & name) const;
|
||||
virtual QList<Result::DesNode*> queryStoryPoint(Result::DesNode* chain, const QString &name) const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue