diff --git a/StoryPresent/dag_present.cpp b/StoryPresent/dag_present.cpp index a88b1d1..5251b76 100644 --- a/StoryPresent/dag_present.cpp +++ b/StoryPresent/dag_present.cpp @@ -311,6 +311,7 @@ void dags::DAGActiveView::refreshGraph() // 清除当前视图 this->scene_bind.clear(); this->total_graph_nodes.clear(); + this->highlight_nodelist.clear(); auto total_nodes = _layout_engine->nodeWithLayout(); total_graph_nodes = this->layer_nodes_construction(QHash>(), total_nodes); @@ -331,7 +332,7 @@ void DAGActiveView::mousePressEvent(QMouseEvent* ev) { auto type_item = dynamic_cast(gitem); if (type_item->nodeType() == GraphNodeType::ActivePresentNode) { auto node = static_cast(type_item); - emit this->nodeClicked(ev->pos(), QList() << node->nodeName()); + emit this->nodeClicked(ev->pos(), node->nodeName()); break; } } diff --git a/StoryPresent/dag_present.h b/StoryPresent/dag_present.h index 10cc9ab..91b6337 100644 --- a/StoryPresent/dag_present.h +++ b/StoryPresent/dag_present.h @@ -106,7 +106,7 @@ namespace dags { DAGGraph *const _layout_engine; signals: - void nodeClicked(const QPointF &pos, const QList &node_name); + void nodeClicked(const QPointF &pos, const QString &node_name); public: DAGActiveView(QWidget* parent = nullptr); diff --git a/StoryPresent/storypresent.cpp b/StoryPresent/storypresent.cpp index 0e83064..f2616b2 100644 --- a/StoryPresent/storypresent.cpp +++ b/StoryPresent/storypresent.cpp @@ -20,7 +20,9 @@ StoryPresent::StoryPresent(QWidget* parent) auto layout = mbar->addMenu(u8"布局调整"); layout->addAction(u8"正向布局", this, &StoryPresent::forwardLayout, Qt::CTRL + Qt::Key_F); layout->addAction(u8"逆向布局", this, &StoryPresent::backwardLayout, Qt::CTRL + Qt::Key_B); - layout->addAction(u8"调整布局", this, &StoryPresent::adjustLayout, Qt::CTRL+Qt::Key_A); + //layout->addAction(u8"调整布局", this, &StoryPresent::adjustLayout, Qt::CTRL+Qt::Key_A); + + connect(_story_present, &DAGActiveView::nodeClicked, this, &StoryPresent::nodeClickAccept); } StoryPresent::~StoryPresent() @@ -46,12 +48,14 @@ void StoryPresent::loadXAST(const QString& ast_path) auto frag_temp = story_line->firstChild(); while (frag_temp) { switch (frag_temp->type()) { - case SliceType::FragmentDefines: { + case SliceType::FragmentDefines: + { auto arrow_tail = std::dynamic_pointer_cast(frag_temp)->name() + u8"@" + story_line->name(); arrows << graph_data::Arrow(arrow_start, arrow_tail); arrow_start = arrow_tail; }break; - case SliceType::FragmentRefers: { + case SliceType::FragmentRefers: + { auto conv_refer = std::dynamic_pointer_cast(frag_temp); auto arrow_tail = conv_refer->fragmentRefer() + u8"@" + conv_refer->storyRefer(); arrows << graph_data::Arrow(arrow_start, arrow_tail); @@ -67,6 +71,78 @@ void StoryPresent::loadXAST(const QString& ast_path) } #include +void StoryPresent::nodeClickAccept(const QPointF& pos, const QString& node_name) +{ + // 起始节点 + if (!node_name.contains(u8"@")) { + auto story_line = this->_story_graph[node_name]; + + QList node_names; + node_names << node_name; + + auto temp_node = story_line->firstChild(); + while (temp_node) { + switch (temp_node->type()) { + case SliceType::FragmentDefines: + { + auto fragm = std::dynamic_pointer_cast(temp_node); + node_names << QString(u8"%1@%2").arg(fragm->name(), node_name); + }break; + case SliceType::FragmentRefers: + { + auto frefer = std::dynamic_pointer_cast(temp_node); + node_names << QString(u8"%1@%2").arg(frefer->fragmentRefer(), frefer->storyRefer()); + } + break; + default: + break; + } + temp_node = temp_node->nextSlice(); + } + + QList arrows; + for (auto idx = 1; idx < node_names.size(); ++idx) { + auto from = node_names[idx - 1]; + auto to = node_names[idx]; + + arrows << graph_data::Arrow(from, to); + } + this->_story_present->highlightGraphLink(arrows); + } + else { + auto splits = node_name.split(u8"@", QString::SkipEmptyParts); + auto story_line = this->_story_graph[splits.last()]; + auto fragm_slice = story_line->getFragment(splits.first()); + auto fragm_defn = std::dynamic_pointer_cast(fragm_slice); + + auto refers = fragm_defn->referSlices(); + + if (!refers.size()) { + this->nodeClickAccept(QPointF(), story_line->name()); + return; + } + + QList> parent_slices; + std::transform(refers.begin(), refers.end(), std::back_inserter(parent_slices), + [](std::shared_ptr ins) { return ins->parentSlice().lock(); }); + + decltype(parent_slices) fliter_slices; + std::copy_if(parent_slices.begin(), parent_slices.end(), std::back_inserter(fliter_slices), + [](std::shared_ptr ins) { return ins->type() == SliceType::StoryDefines; }); + + QList> lines = { story_line }; + std::transform(fliter_slices.begin(), fliter_slices.end(), std::back_inserter(lines), + [](std::shared_ptr ins) { return std::dynamic_pointer_cast(ins); }); + + QMenu msep; + for (auto ln : lines) { + msep.addAction(ln->name(), [=](){ + this->nodeClickAccept(QPointF(), ln->name()); + }); + } + msep.exec(this->_story_present->mapToParent(pos.toPoint())); + } +} void StoryPresent::bigger() { _scale_value *= 1.1; diff --git a/StoryPresent/storypresent.h b/StoryPresent/storypresent.h index 79464fb..323cf91 100644 --- a/StoryPresent/storypresent.h +++ b/StoryPresent/storypresent.h @@ -18,6 +18,8 @@ private: dags::DAGActiveView *const _story_present; QHash> _story_graph; + void nodeClickAccept(const QPointF &pos, const QString &node_name); + void bigger(); void lesser();