From dbbdece7fefa9ac8a1eaf7fd1cea7ffca1fc5454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=AE=87=E6=B8=85=E9=9F=B3?= <2422523675@qq.com> Date: Fri, 18 Nov 2022 13:43:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=84=89=E7=BB=9C=E8=A7=86=E5=9B=BE=E5=8F=8A?= =?UTF-8?q?=E5=85=B6=E5=9F=BA=E7=A1=80=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QtNovelDesc.pro.user | 4 +- WordsIDE/SourceEditView.cpp | 16 +++- WordsIDE/WordsIDE.pro | 10 ++- ...htlighter.cpp => keywordshightlighter.cpp} | 8 +- ...nhightlighter.h => keywordshightlighter.h} | 4 +- WordsIDE/mainwindow.cpp | 22 +++-- WordsIDE/mainwindow.h | 6 +- WordsIDE/storychainspresent.cpp | 88 +++++++++++++++++++ WordsIDE/storychainspresent.h | 33 +++++++ libParse/StoryTool.cpp | 1 + libParse/libParse.cpp | 19 ++-- libParse/libParse.h | 1 + 12 files changed, 186 insertions(+), 26 deletions(-) rename WordsIDE/{chainhightlighter.cpp => keywordshightlighter.cpp} (81%) rename WordsIDE/{chainhightlighter.h => keywordshightlighter.h} (80%) create mode 100644 WordsIDE/storychainspresent.cpp create mode 100644 WordsIDE/storychainspresent.h diff --git a/QtNovelDesc.pro.user b/QtNovelDesc.pro.user index bd19266..4a29a94 100644 --- a/QtNovelDesc.pro.user +++ b/QtNovelDesc.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -99,7 +99,7 @@ qt.qt5.51211.win64_msvc2017_64_kit 0 0 - 0 + 2 0 D:\Projects\Cpp\build-QtNovelDesc-Desktop_Qt_5_12_11_MSVC2017_64bit-Debug diff --git a/WordsIDE/SourceEditView.cpp b/WordsIDE/SourceEditView.cpp index be3f6c3..5b757bc 100644 --- a/WordsIDE/SourceEditView.cpp +++ b/WordsIDE/SourceEditView.cpp @@ -1,12 +1,14 @@ #include "SourceEditView.h" -#include "chainhightlighter.h" +#include "keywordshightlighter.h" +#include 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(this->highter_ins)->reset(core_ins); + static_cast(this->highter_ins)->reset(core_ins); } QWidget *StoryChainSourceEdit::textView() const diff --git a/WordsIDE/WordsIDE.pro b/WordsIDE/WordsIDE.pro index 36dfab2..dfb127f 100644 --- a/WordsIDE/WordsIDE.pro +++ b/WordsIDE/WordsIDE.pro @@ -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 diff --git a/WordsIDE/chainhightlighter.cpp b/WordsIDE/keywordshightlighter.cpp similarity index 81% rename from WordsIDE/chainhightlighter.cpp rename to WordsIDE/keywordshightlighter.cpp index b3e621e..1005141 100644 --- a/WordsIDE/chainhightlighter.cpp +++ b/WordsIDE/keywordshightlighter.cpp @@ -1,21 +1,21 @@ -#include "chainhightlighter.h" +#include "keywordshightlighter.h" #include 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; diff --git a/WordsIDE/chainhightlighter.h b/WordsIDE/keywordshightlighter.h similarity index 80% rename from WordsIDE/chainhightlighter.h rename to WordsIDE/keywordshightlighter.h index 72051b2..21a200f 100644 --- a/WordsIDE/chainhightlighter.h +++ b/WordsIDE/keywordshightlighter.h @@ -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: diff --git a/WordsIDE/mainwindow.cpp b/WordsIDE/mainwindow.cpp index d723f02..093222a 100644 --- a/WordsIDE/mainwindow.cpp +++ b/WordsIDE/mainwindow.cpp @@ -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) diff --git a/WordsIDE/mainwindow.h b/WordsIDE/mainwindow.h index a4b05af..bbcc804 100644 --- a/WordsIDE/mainwindow.h +++ b/WordsIDE/mainwindow.h @@ -7,8 +7,10 @@ #include #include #include +#include #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; diff --git a/WordsIDE/storychainspresent.cpp b/WordsIDE/storychainspresent.cpp new file mode 100644 index 0000000..3fedee9 --- /dev/null +++ b/WordsIDE/storychainspresent.cpp @@ -0,0 +1,88 @@ +#include "storychainspresent.h" + +#include +#include + +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(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(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()); + } + } +} + + + + + + + + + + + + + + diff --git a/WordsIDE/storychainspresent.h b/WordsIDE/storychainspresent.h new file mode 100644 index 0000000..a9fedad --- /dev/null +++ b/WordsIDE/storychainspresent.h @@ -0,0 +1,33 @@ +#ifndef STORYCHAINSPRESENT_H +#define STORYCHAINSPRESENT_H + +#include +#include +#include +#include +#include + +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 diff --git a/libParse/StoryTool.cpp b/libParse/StoryTool.cpp index 3f28573..9039834 100644 --- a/libParse/StoryTool.cpp +++ b/libParse/StoryTool.cpp @@ -48,6 +48,7 @@ QList 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); diff --git a/libParse/libParse.cpp b/libParse/libParse.cpp index f041c99..e599d91 100644 --- a/libParse/libParse.cpp +++ b/libParse/libParse.cpp @@ -160,17 +160,26 @@ void ParseCore::deleteDocument(DocCore *ins) delete ins; } -QList ParseCore::queryStoryChain(const QString &name) const +QList ParseCore::allStoryChains() const { QList 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(n)->name() == name) + for(auto &n : *nodes_map[k]) + if(n->typeValue()==NODE_STORYCHAIN) retlist << n; - } + + return retlist; +} + +QList ParseCore::queryStoryChain(const QString &name) const +{ + QList retlist; + + for(auto &xnode : allStoryChains()) + if(static_cast(xnode)->name() == name) + retlist << xnode; return retlist; } diff --git a/libParse/libParse.h b/libParse/libParse.h index df2b931..2165971 100644 --- a/libParse/libParse.h +++ b/libParse/libParse.h @@ -305,6 +305,7 @@ namespace Parse virtual Result::DocCore* queryDocument(const QFileInfo &file_src) const; virtual void deleteDocument(Result::DocCore *ins); + virtual QList allStoryChains() const; virtual QList queryStoryChain(const QString & name) const; virtual QList queryStoryPoint(Result::DesNode* chain, const QString &name) const;