From 33aff14813f866526d4b17643e247ed12357a39b Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Tue, 3 Feb 2015 16:48:32 +0100 Subject: [PATCH] logic: only show edges connected to active node * split active and visible setting for DummyNodes * set and check visible on DummyEdges * include fix for Mac in MatrixDynamicBase * fix for disappearing style and crashes in GraphView * cleaned up DummyNode fortune cookie message = Du stehst kurz davor etwas Neues zu unternehmen. --- src/app/qt/view/QtGraphView.cpp | 9 +-- .../component/controller/GraphController.cpp | 58 ++++++++++++----- .../component/controller/GraphController.h | 4 +- .../component/view/graphElements/GraphNode.h | 64 ++----------------- src/lib/utility/math/MatrixDynamicBase.h | 2 + 5 files changed, 54 insertions(+), 83 deletions(-) diff --git a/src/app/qt/view/QtGraphView.cpp b/src/app/qt/view/QtGraphView.cpp index 200aa9d0..fe9e0af2 100644 --- a/src/app/qt/view/QtGraphView.cpp +++ b/src/app/qt/view/QtGraphView.cpp @@ -1,7 +1,5 @@ #include "QtGraphView.h" -#include - #include #include #include @@ -153,8 +151,6 @@ void QtGraphView::doRebuildGraph( node->hoverEnter(); } } - - m_graph = graph; } void QtGraphView::doClear() @@ -233,6 +229,11 @@ std::shared_ptr QtGraphView::createNodeRecursive( std::shared_ptr QtGraphView::createEdge(QGraphicsView* view, const DummyEdge& edge) { + if (!edge.visible) + { + return NULL; + } + std::shared_ptr owner = findNodeRecursive(m_nodes, edge.ownerId); std::shared_ptr target = findNodeRecursive(m_nodes, edge.targetId); diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index 7596d8ad..7fde96be 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -147,7 +147,8 @@ void GraphController::createDummyGraphForTokenIds(const std::vector& tokenId DummyNode GraphController::createDummyNodeTopDown(Node* node) { - DummyNode result(node); + DummyNode result; + result.data = node; result.tokenId = node->getId(); // there is a global root node with id 0 afaik, so here we actually want the one node below this global root @@ -200,7 +201,9 @@ DummyNode GraphController::createDummyNodeTopDown(Node* node) if (!parent) { - result.subNodes.push_back(DummyNode(accessType)); + DummyNode accessNode; + accessNode.accessType = accessType; + result.subNodes.push_back(accessNode); parent = &result.subNodes.back(); DummyNode* oldParent = findDummyNodeAccessRecursive(m_dummyNodes, node->getId(), accessType); @@ -223,15 +226,6 @@ DummyNode GraphController::createDummyNodeTopDown(Node* node) return; } - if (edge->isType(Edge::EDGE_AGGREGATION)) - { - result.aggregated = true; - } - else - { - result.connected = true; - } - for (const DummyEdge& dummy : m_dummyEdges) { if (dummy.data->getId() == edge->getId()) @@ -273,23 +267,45 @@ void GraphController::setActiveAndVisibility(const std::vector& activeTokenI { for (DummyNode& node : m_dummyNodes) { - setNodeActiveAndVisibilityRecursiveBottomUp(node, activeTokenIds, false); + setNodeActiveRecursive(node, activeTokenIds); } for (DummyEdge& edge : m_dummyEdges) { - edge.visible = true; edge.active = false; if (find(activeTokenIds.begin(), activeTokenIds.end(), edge.data->getId()) != activeTokenIds.end()) { edge.active = true; } + + DummyNode* from = findDummyNodeRecursive(m_dummyNodes, edge.ownerId); + DummyNode* to = findDummyNodeRecursive(m_dummyNodes, edge.targetId); + + if (from && to && (from->active || to->active || edge.active)) + { + edge.visible = true; + + if (edge.data->isType(Edge::EDGE_AGGREGATION)) + { + from->aggregated = true; + to->aggregated = true; + } + else + { + from->connected = true; + to->connected = true; + } + } + } + + for (DummyNode& node : m_dummyNodes) + { + setNodeVisibilityRecursiveBottomUp(node, false); } } -bool GraphController::setNodeActiveAndVisibilityRecursiveBottomUp( - DummyNode& node, const std::vector& activeTokenIds, bool aggregated -) const { +void GraphController::setNodeActiveRecursive(DummyNode& node, const std::vector& activeTokenIds) const +{ node.visible = false; node.active = false; @@ -298,10 +314,18 @@ bool GraphController::setNodeActiveAndVisibilityRecursiveBottomUp( node.active = find(activeTokenIds.begin(), activeTokenIds.end(), node.data->getId()) != activeTokenIds.end(); } + for (DummyNode& subNode : node.subNodes) + { + setNodeActiveRecursive(subNode, activeTokenIds); + } +} + +bool GraphController::setNodeVisibilityRecursiveBottomUp(DummyNode& node, bool aggregated) const +{ bool childVisible = false; for (DummyNode& subNode : node.subNodes) { - if (setNodeActiveAndVisibilityRecursiveBottomUp(subNode, activeTokenIds, aggregated | node.aggregated)) + if (setNodeVisibilityRecursiveBottomUp(subNode, aggregated | node.aggregated)) { childVisible = true; } diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h index 1b29c03d..5f12d881 100644 --- a/src/lib/component/controller/GraphController.h +++ b/src/lib/component/controller/GraphController.h @@ -63,8 +63,8 @@ private: void autoExpandActiveNode(const std::vector& activeTokenIds); void setActiveAndVisibility(const std::vector& activeTokenIds); - bool setNodeActiveAndVisibilityRecursiveBottomUp( - DummyNode& node, const std::vector& activeTokenIds, bool aggregated) const; + void setNodeActiveRecursive(DummyNode& node, const std::vector& activeTokenIds) const; + bool setNodeVisibilityRecursiveBottomUp(DummyNode& node, bool aggregated) const; void setNodeVisibilityRecursiveTopDown(DummyNode& node) const; void layoutNesting(); diff --git a/src/lib/component/view/graphElements/GraphNode.h b/src/lib/component/view/graphElements/GraphNode.h index c9276fd6..1fa9d66e 100644 --- a/src/lib/component/view/graphElements/GraphNode.h +++ b/src/lib/component/view/graphElements/GraphNode.h @@ -58,25 +58,8 @@ public: , autoExpanded(false) , invisibleSubNodeCount(0) , visible(false) - { - } - - DummyNode(const Node* data) - : data(data) - , accessType(TokenComponentAccess::ACCESS_NONE) - { - } - - DummyNode(TokenComponentAccess::AccessType accessType) - : data(nullptr) - , accessType(accessType) - , active(false) - , connected(false) - , aggregated(false) - , expanded(false) - , autoExpanded(false) - , invisibleSubNodeCount(0) - , visible(false) + , topLevelAncestorId(0) + , tokenId(0) { } @@ -85,45 +68,6 @@ public: return expanded || autoExpanded; } - bool operator==(const DummyNode& other) const - { - if (data->getId() == other.data->getId() - && data->getName() == other.data->getName()) - { - return true; - } - return false; - } - - bool operator!=(const DummyNode& other) const - { - return !(*this == other); - } - - bool operator<(const DummyNode& other) const - { - if (data->getId() < other.data->getId()) - { - return true; - } - return false; - } - - bool operator>(const DummyNode& other) const - { - return !(*this < other); - } - - DummyNode& operator=(const DummyNode& other) - { - data = other.data; - subNodes = other.subNodes; - position = other.position; - topLevelAncestorId = other.topLevelAncestorId; - tokenId = other.tokenId; - return *this; - } - const Node* data; TokenComponentAccess::AccessType accessType; @@ -139,10 +83,10 @@ public: size_t invisibleSubNodeCount; bool visible; - + Id topLevelAncestorId; Id tokenId; - + std::vector subNodes; }; diff --git a/src/lib/utility/math/MatrixDynamicBase.h b/src/lib/utility/math/MatrixDynamicBase.h index b36dd568..e35f9fd7 100644 --- a/src/lib/utility/math/MatrixDynamicBase.h +++ b/src/lib/utility/math/MatrixDynamicBase.h @@ -1,6 +1,8 @@ #ifndef MATRIX_DYNAMIC_BASE_H #define MATRIX_DYNAMIC_BASE_H +#include +#include #include #include