diff --git a/src/app/qt/graphics/QtStraightLineItem.cpp b/src/app/qt/graphics/QtStraightLineItem.cpp index edb6ef4f..1c7bcac1 100644 --- a/src/app/qt/graphics/QtStraightLineItem.cpp +++ b/src/app/qt/graphics/QtStraightLineItem.cpp @@ -126,7 +126,7 @@ void QtStraightLineItem::updateLine( QColor color(style.color.c_str()); - this->setPen(QPen(QBrush(color), number + style.width, Qt::SolidLine, Qt::RoundCap)); + this->setPen(QPen(QBrush(color), style.width, Qt::SolidLine, Qt::RoundCap)); color = color.darker(110); diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index 2eccd3aa..a27d4bf9 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -339,7 +339,7 @@ void GraphController::setActiveAndVisibility(const std::vector& activeTokenI for (DummyEdge& edge : m_dummyEdges) { - if (!edge.data || edge.data->isType(Edge::EDGE_AGGREGATION)) + if (!edge.data) { continue; } @@ -361,43 +361,9 @@ void GraphController::setActiveAndVisibility(const std::vector& activeTokenI } } - for (DummyEdge& edge : m_dummyEdges) - { - if (!edge.data || !edge.data->isType(Edge::EDGE_AGGREGATION)) - { - continue; - } - - DummyNode* from = findTopLevelDummyNodeRecursive(m_dummyNodes, edge.ownerId); - DummyNode* to = findTopLevelDummyNodeRecursive(m_dummyNodes, edge.targetId); - - if (from && to && (from->active || to->active)) - { - TokenComponentAggregation* component = edge.data->getComponent(); - std::set ids = component->getAggregationIds(); - for (Id id : ids) - { - for (DummyEdge& e : m_dummyEdges) - { - if (e.visible && e.data && e.data->getId() == id) - { - component->removeAggregationId(id); - } - } - } - - if (component->getAggregationCount() > 0) - { - edge.visible = true; - from->aggregated = true; - to->aggregated = true; - } - } - } - for (DummyNode& node : m_dummyNodes) { - setNodeVisibilityRecursiveBottomUp(node, false); + setNodeVisibilityRecursiveBottomUp(node); } } @@ -416,7 +382,7 @@ void GraphController::setNodeActiveRecursive(DummyNode& node, const std::vector< } } -bool GraphController::setNodeVisibilityRecursiveBottomUp(DummyNode& node, bool aggregated) const +bool GraphController::setNodeVisibilityRecursiveBottomUp(DummyNode& node) const { node.visible = false; node.childVisible = false; @@ -434,13 +400,13 @@ bool GraphController::setNodeVisibilityRecursiveBottomUp(DummyNode& node, bool a for (DummyNode& subNode : node.subNodes) { - if (setNodeVisibilityRecursiveBottomUp(subNode, aggregated | node.aggregated)) + if (setNodeVisibilityRecursiveBottomUp(subNode)) { node.childVisible = true; } } - if (node.active || node.connected || node.childVisible || (!aggregated && node.aggregated)) + if (node.active || node.connected || node.childVisible) { setNodeVisibilityRecursiveTopDown(node, false); } diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h index 736dae64..00ac58f6 100644 --- a/src/lib/component/controller/GraphController.h +++ b/src/lib/component/controller/GraphController.h @@ -59,7 +59,7 @@ private: void setActiveAndVisibility(const std::vector& activeTokenIds); void setNodeActiveRecursive(DummyNode& node, const std::vector& activeTokenIds) const; - bool setNodeVisibilityRecursiveBottomUp(DummyNode& node, bool aggregated) const; + bool setNodeVisibilityRecursiveBottomUp(DummyNode& node) const; void setNodeVisibilityRecursiveTopDown(DummyNode& node, bool parentExpanded) const; void splitNamespaceNodes(); diff --git a/src/lib/component/controller/helper/DummyNode.h b/src/lib/component/controller/helper/DummyNode.h index 125fe00b..afd761c0 100644 --- a/src/lib/component/controller/helper/DummyNode.h +++ b/src/lib/component/controller/helper/DummyNode.h @@ -20,7 +20,6 @@ public: , data(nullptr) , active(false) , connected(false) - , aggregated(false) , expanded(false) , hasNamespace(false) , accessType(TokenComponentAccess::ACCESS_NONE) @@ -117,7 +116,6 @@ public: const Node* data; bool active; bool connected; - bool aggregated; bool expanded; bool hasNamespace; diff --git a/src/lib/component/view/GraphViewStyle.cpp b/src/lib/component/view/GraphViewStyle.cpp index 61bfaf81..b8f52978 100644 --- a/src/lib/component/view/GraphViewStyle.cpp +++ b/src/lib/component/view/GraphViewStyle.cpp @@ -445,7 +445,7 @@ GraphViewStyle::EdgeStyle GraphViewStyle::getStyleForEdgeType(Edge::EdgeType typ { case Edge::EDGE_AGGREGATION: style.isStraight = true; - style.width = 1; + style.width = 4; style.zValue = isActive ? -2 : -5; break; case Edge::EDGE_CALL: diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index 23b47465..d8284b81 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -398,7 +398,8 @@ Id Storage::onTemplateArgumentTypeParsed( } Id Storage::onTemplateDefaultArgumentTypeParsed( - const ParseTypeUsage& defaultArgumentTypeUsage, const NameHierarchy& templateArgumentTypeNameHierarchy // actually this is the template parameter??? + const ParseTypeUsage& defaultArgumentTypeUsage, + const NameHierarchy& templateArgumentTypeNameHierarchy // actually this is the template parameter??? ){ Id defaultArgumentNodeId = addNodeHierarchy(Node::NODE_UNDEFINED_TYPE, defaultArgumentTypeUsage.dataType->getTypeNameHierarchy()); // TODO add location for defarg @@ -601,15 +602,8 @@ std::shared_ptr Storage::getGraphForActiveTokenIds(const std::vector& std::vector edges = m_sqliteStorage.getEdgesBySourceId(node.id); utility::append(edges, m_sqliteStorage.getEdgesByTargetId(node.id)); - const Node::NodeTypeMask nodeTypeMask = Node::NODE_STRUCT | Node::NODE_CLASS; - const Edge::EdgeTypeMask edgeTypeMask = Edge::EDGE_TYPE_USAGE | Edge::EDGE_TYPE_OF; - for (size_t i = 0; i < edges.size(); i++) { - if ((node.type & nodeTypeMask) > 0 && (edges[i].type & edgeTypeMask) > 0) - { - continue; - } addEdgeAndAllChildrenToGraph(edges[i].id, graph); } @@ -640,7 +634,8 @@ std::shared_ptr Storage::getGraphForActiveTokenIds(const std::vector& return g; } -std::vector Storage::getActiveTokenIdsForId(Id tokenId, Id* declarationId) const // TODO: rename: getActiveElementIdsForId; TODO: make separate function for declarationId +// TODO: rename: getActiveElementIdsForId; TODO: make separate function for declarationId +std::vector Storage::getActiveTokenIdsForId(Id tokenId, Id* declarationId) const { std::vector activeTokenIds; @@ -905,7 +900,7 @@ const SearchIndex& Storage::getSearchIndex() const return m_tokenIndex; } -Id Storage::addNodeHierarchy(Node::NodeType type, NameHierarchy nameHierarchy) +Id Storage::addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy) { addNameHierarchyElements(nameHierarchy); @@ -913,6 +908,8 @@ Id Storage::addNodeHierarchy(Node::NodeType type, NameHierarchy nameHierarchy) Id parentNodeId = 0; for (size_t i = 0; i < nameHierarchy.size(); i++) { + Node::NodeType type = (i == nameHierarchy.size() - 1 ? nodeType : Node::NODE_UNDEFINED); + Id nameHierarchyElementId = 0; if (parentNameHierarchyElementId == 0) { @@ -920,7 +917,8 @@ Id Storage::addNodeHierarchy(Node::NodeType type, NameHierarchy nameHierarchy) } else { - nameHierarchyElementId = m_sqliteStorage.getNameHierarchyElementIdByName(nameHierarchy[i]->getFullName(), parentNameHierarchyElementId); + nameHierarchyElementId = + m_sqliteStorage.getNameHierarchyElementIdByName(nameHierarchy[i]->getFullName(), parentNameHierarchyElementId); } const StorageNode node = m_sqliteStorage.getNodeByNameId(nameHierarchyElementId); @@ -1069,13 +1067,20 @@ std::vector Storage::getDirectChildNodeIds(const Id nodeId) const std::vector Storage::getAllChildNodeIds(const Id nodeId) const { std::vector childNodeIds; + std::queue parents; - std::vector directChildNodeIds = getDirectChildNodeIds(nodeId); - for (size_t i = 0; i < directChildNodeIds.size(); i++) + parents.push(nodeId); + while (parents.size()) { - Id id = directChildNodeIds[i]; - childNodeIds.push_back(id); - utility::append(directChildNodeIds, getAllChildNodeIds(id)); + Id parentId = parents.front(); + parents.pop(); + + std::vector childs = getDirectChildNodeIds(parentId); + for (Id childId : childs) + { + childNodeIds.push_back(childId); + parents.push(childId); + } } return childNodeIds; @@ -1094,11 +1099,12 @@ void Storage::addEdgeAndAllChildrenToGraph(const Id edgeId, Graph* graph) const graph->createEdge(edgeId, Edge::intToType(storageEdge.type), sourceNode, targetNode); } -void Storage::addNodeAndAllChildrenToGraph(const Id nodeId, Graph* graph) const +Node* Storage::addNodeAndAllChildrenToGraph(const Id nodeId, Graph* graph) const { + Node* node = nullptr; if (!graph->getNodeById(nodeId)) { - addNodeToGraph(nodeId, graph); + node = addNodeToGraph(nodeId, graph); } std::queue unprocessedEdges; @@ -1137,6 +1143,8 @@ void Storage::addNodeAndAllChildrenToGraph(const Id nodeId, Graph* graph) const } } } + + return node; } void Storage::addAggregationEdgesToGraph(const Id nodeId, Graph* graph) const @@ -1195,32 +1203,24 @@ void Storage::addAggregationEdgesToGraph(const Id nodeId, Graph* graph) const if (currentNodeId == nodeId) { needsAdd = false; - continue; + break; } std::vector memberEdges = m_sqliteStorage.getEdgesByTargetType(currentNodeId, Edge::EDGE_MEMBER); - - if (memberEdges.size() > 0) + if (memberEdges.size() == 1) { - if (m_sqliteStorage.getNodeById(memberEdges[0].sourceNodeId).type != Node::NodeType::NODE_NAMESPACE) + Node::NodeType type = Node::intToType(m_sqliteStorage.getNodeById(memberEdges[0].sourceNodeId).type); + + if (type != Node::NODE_UNDEFINED && type != Node::NODE_NAMESPACE) { parentNodeId = memberEdges[0].sourceNodeId; } } } - int type = m_sqliteStorage.getNodeById(currentNodeId).type; - Node::NodeTypeMask mask = - Node::NODE_UNDEFINED | - Node::NODE_UNDEFINED_FUNCTION | - Node::NODE_UNDEFINED_TYPE | - Node::NODE_UNDEFINED_VARIABLE; - - Node::NodeTypeMask mask2 = ~mask; - - if (needsAdd && ((type & mask2) > 0)) + if (needsAdd && currentNodeId) { - connectedParentNodeIds[currentNodeId] = it->second; + utility::append(connectedParentNodeIds[currentNodeId], it->second); } } @@ -1236,7 +1236,11 @@ void Storage::addAggregationEdgesToGraph(const Id nodeId, Graph* graph) const Node* targetNode = graph->getNodeById(aggregationTargetNodeId); if (!targetNode) { - targetNode = addNodeToGraph(aggregationTargetNodeId, graph); + targetNode = addNodeAndAllChildrenToGraph(getLastParentNodeId(aggregationTargetNodeId), graph); + if (targetNode->isType(Node::NODE_UNDEFINED | Node::NODE_NAMESPACE)) + { + targetNode = addNodeToGraph(aggregationTargetNodeId, graph); + } } std::shared_ptr componentAggregation = std::make_shared(); @@ -1245,7 +1249,7 @@ void Storage::addAggregationEdgesToGraph(const Id nodeId, Graph* graph) const componentAggregation->addAggregationId(edgeInfo.edgeId, edgeInfo.forward); } - Edge* edge = graph->createEdge(0, Edge::EDGE_AGGREGATION, sourceNode, targetNode); + Edge* edge = graph->createEdge(*componentAggregation->getAggregationIds().begin(), Edge::EDGE_AGGREGATION, sourceNode, targetNode); edge->addComponentAggregation(componentAggregation); } } diff --git a/src/lib/data/Storage.h b/src/lib/data/Storage.h index 2ca923e4..32637c4c 100644 --- a/src/lib/data/Storage.h +++ b/src/lib/data/Storage.h @@ -139,7 +139,7 @@ public: const SearchIndex& getSearchIndex() const; private: - Id addNodeHierarchy(Node::NodeType type, NameHierarchy nameHierarchy); + Id addNodeHierarchy(Node::NodeType nodeType, NameHierarchy nameHierarchy); Id addNodeHierarchyWithDistinctSignature(Node::NodeType type, const ParseFunction& function); Id addNameHierarchyElements(NameHierarchy nameHierarchy); int addSourceLocation(int elementNodeId, const ParseLocation& location, bool isScope = false); @@ -150,7 +150,7 @@ private: std::vector getAllChildNodeIds(const Id nodeId) const; void addEdgeAndAllChildrenToGraph(const Id edgeId, Graph* graph) const; - void addNodeAndAllChildrenToGraph(const Id nodeId, Graph* graph) const; + Node* addNodeAndAllChildrenToGraph(const Id nodeId, Graph* graph) const; void addAggregationEdgesToGraph(const Id nodeId, Graph* graph) const; Node* addNodeToGraph(const Id nodeId, Graph* graph) const;