diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index 3ecd21a0..bcb6b58f 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -91,8 +91,7 @@ void CodeController::handleMessage(MessageActivateTokens* message) CodeView* view = getView(); view->setErrorMessages(std::vector()); - std::vector activeTokenIds = - (message->originalTokenIds.size() > 0 ? message->originalTokenIds : message->tokenIds); + std::vector activeTokenIds = message->tokenIds; Id declarationId = 0; // 0 means that no token is found. if (!message->isAggregation) @@ -106,11 +105,6 @@ void CodeController::handleMessage(MessageActivateTokens* message) activeTokenIds = m_storageAccess->getActiveTokenIdsForId(activeTokenIds[0], &declarationId); } - if (message->originalTokenIds.size() > 0) - { - declarationId = 0; - } - if (message->isEdge) { view->showFirstActiveSnippet(activeTokenIds, message->isLast()); @@ -305,7 +299,7 @@ std::vector CodeController::getSnippetsForActiveTokenLocation } ); - if (isDeclarationFile || collection->getTokenLocationFileCount() < 5 || file->isWholeCopy) + if (snippets.size() < 10 && (isDeclarationFile || collection->getTokenLocationFileCount() < 5 || file->isWholeCopy)) { std::vector fileSnippets = getSnippetsForActiveTokenLocationsInFile(file); diff --git a/src/lib/component/controller/FeatureController.cpp b/src/lib/component/controller/FeatureController.cpp index 50fb4b93..b76713eb 100644 --- a/src/lib/component/controller/FeatureController.cpp +++ b/src/lib/component/controller/FeatureController.cpp @@ -65,8 +65,6 @@ void FeatureController::handleMessage(MessageActivateTokenIds* message) void FeatureController::handleMessage(MessageActivateTokenLocations* message) { std::vector nodeIds = m_storageAccess->getNodeIdsForLocationIds(message->locationIds); - nodeIds = m_storageAccess->getActiveTokenIdsForTokenIds(nodeIds); - MessageActivateNodes m; for (Id nodeId : nodeIds) { diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index 78729081..308e0ee1 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -67,16 +67,10 @@ void GraphController::handleMessage(MessageActivateTokens* message) std::vector tokenIds = utility::concat(m_activeNodeIds, m_activeEdgeIds); - std::shared_ptr graph = - m_storageAccess->getGraphForActiveTokenIds(tokenIds, message->originalTokenIds.size() > 0); + std::shared_ptr graph = m_storageAccess->getGraphForActiveTokenIds(tokenIds); createDummyGraphForTokenIds(tokenIds, graph); - if (message->originalTokenIds.size() > 0) - { - deactivateNodesRecursive(&m_dummyNodes); - } - if (m_activeNodeIds.size() == 1) { bundleNodes(); @@ -344,10 +338,13 @@ void GraphController::autoExpandActiveNode(const std::vector& activeTokenIds void GraphController::setActiveAndVisibility(const std::vector& activeTokenIds) { bool noActive = activeTokenIds.size() == 0; - - for (DummyNode& node : m_dummyNodes) + if (activeTokenIds.size() > 0) { - setNodeActiveRecursive(node, activeTokenIds); + noActive = true; + for (DummyNode& node : m_dummyNodes) + { + setNodeActiveRecursive(node, activeTokenIds, &noActive); + } } for (DummyEdge& edge : m_dummyEdges) @@ -382,18 +379,23 @@ void GraphController::setActiveAndVisibility(const std::vector& activeTokenI } } -void GraphController::setNodeActiveRecursive(DummyNode& node, const std::vector& activeTokenIds) const +void GraphController::setNodeActiveRecursive(DummyNode& node, const std::vector& activeTokenIds, bool* noActive) const { node.active = false; if (node.isGraphNode()) { node.active = find(activeTokenIds.begin(), activeTokenIds.end(), node.data->getId()) != activeTokenIds.end(); + + if (node.active) + { + *noActive = false; + } } for (DummyNode& subNode : node.subNodes) { - setNodeActiveRecursive(subNode, activeTokenIds); + setNodeActiveRecursive(subNode, activeTokenIds, noActive); } } @@ -474,15 +476,6 @@ void GraphController::setNodeVisibilityRecursiveTopDown(DummyNode& node, bool pa } } -void GraphController::deactivateNodesRecursive(std::vector* nodes) const -{ - for (DummyNode& node : *nodes) - { - node.active = false; - deactivateNodesRecursive(&node.subNodes); - } -} - void GraphController::bundleNodes() { bundleNodesAndEdgesMatching( diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h index 7baa8431..c7124238 100644 --- a/src/lib/component/controller/GraphController.h +++ b/src/lib/component/controller/GraphController.h @@ -63,11 +63,10 @@ private: void autoExpandActiveNode(const std::vector& activeTokenIds); void setActiveAndVisibility(const std::vector& activeTokenIds); - void setNodeActiveRecursive(DummyNode& node, const std::vector& activeTokenIds) const; + void setNodeActiveRecursive(DummyNode& node, const std::vector& activeTokenIds, bool* noActive) const; void removeImplicitAndUndefinedChildrenRecursive(DummyNode& node); bool setNodeVisibilityRecursiveBottomUp(DummyNode& node, bool noActive) const; void setNodeVisibilityRecursiveTopDown(DummyNode& node, bool parentExpanded) const; - void deactivateNodesRecursive(std::vector* nodes) const; void bundleNodes(); void bundleNodesAndEdgesMatching(std::function matcher, size_t count, const std::string& name); diff --git a/src/lib/component/controller/SearchController.cpp b/src/lib/component/controller/SearchController.cpp index 5493a669..e8fe7e1b 100644 --- a/src/lib/component/controller/SearchController.cpp +++ b/src/lib/component/controller/SearchController.cpp @@ -22,10 +22,7 @@ void SearchController::handleMessage(MessageActivateTokens* message) { if (!message->keepContent() && !message->isFromSearch) { - const std::vector& tokenIds = - (message->originalTokenIds.size() > 0 ? message->originalTokenIds : message->tokenIds); - - getView()->setMatches(m_storageAccess->getSearchMatchesForTokenIds(tokenIds)); + getView()->setMatches(m_storageAccess->getSearchMatchesForTokenIds(message->tokenIds)); } } diff --git a/src/lib/component/controller/helper/ActivationTranslator.cpp b/src/lib/component/controller/helper/ActivationTranslator.cpp index 3458a988..08212ae4 100644 --- a/src/lib/component/controller/helper/ActivationTranslator.cpp +++ b/src/lib/component/controller/helper/ActivationTranslator.cpp @@ -95,11 +95,7 @@ std::shared_ptr ActivationTranslator::translateMessage(co } std::shared_ptr m; - m = std::make_shared(message, m_storageAccess->getActiveTokenIdsForTokenIds(nodeIds)); - if (nodeIds != m->tokenIds) - { - m->originalTokenIds = nodeIds; - } + m = std::make_shared(message, nodeIds); m->isFromSystem = message->isFromSystem; return m; } @@ -135,12 +131,7 @@ std::shared_ptr ActivationTranslator::translateMessage(co std::vector tokenIds = m_storageAccess->getTokenIdsForMatches(matches); - std::shared_ptr m = - std::make_shared(message, m_storageAccess->getActiveTokenIdsForTokenIds(tokenIds)); - if (tokenIds != m->tokenIds) - { - m->originalTokenIds = tokenIds; - } + std::shared_ptr m = std::make_shared(message, tokenIds); if (message->isFresh()) { m->isFromSearch = true; diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index 3ad91384..25c6821b 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -226,7 +226,9 @@ std::vector Storage::getAutocompletionMatches(const std::string& qu if (results[i].elementIds.size() > 0) { StorageNode firstNode(0, 0, "", 0); - for (std::set::const_iterator itElementIds = results[i].elementIds.begin(); itElementIds != results[i].elementIds.end(); itElementIds++) + for (std::set::const_iterator itElementIds = results[i].elementIds.begin(); + itElementIds != results[i].elementIds.end(); + itElementIds++) { Id elementId = *itElementIds; if (elementId != 0) @@ -270,7 +272,8 @@ std::vector Storage::getAutocompletionMatches(const std::string& qu std::vector Storage::getSearchMatchesForTokenIds(const std::vector& elementIds) const { - // todo: what if all these elements share the same node in the searchindex? in that case there should be only one search match. + // todo: what if all these elements share the same node in the searchindex? + // In that case there should be only one search match. std::vector matches; for (Id elementId : elementIds) @@ -309,7 +312,8 @@ std::shared_ptr Storage::getGraphForAll() const std::vector tokenIds; for (StorageNode node: m_sqliteStorage.getAllNodes()) { - if (intToDefinitionType(node.definitionType) != DEFINITION_NONE && (!m_hierarchyCache.isChildOfVisibleNodeOrInvisible(node.id) || + if (intToDefinitionType(node.definitionType) == DEFINITION_EXPLICIT && + (!m_hierarchyCache.isChildOfVisibleNodeOrInvisible(node.id) || Node::intToType(node.type) == Node::NODE_NAMESPACE)) { tokenIds.push_back(node.id); @@ -321,57 +325,86 @@ std::shared_ptr Storage::getGraphForAll() const return graph; } -std::shared_ptr Storage::getGraphForActiveTokenIds(const std::vector& tokenIds, bool activeOnly) const +std::shared_ptr Storage::getGraphForActiveTokenIds(const std::vector& tokenIds) const { std::shared_ptr g = std::make_shared(); Graph* graph = g.get(); + std::vector ids(tokenIds); + bool isNamespace = false; + std::vector nodeIds; std::vector edgeIds; bool addAggregations = false; - if (tokenIds.size() == 1 && !activeOnly) + if (tokenIds.size() == 1) { const Id elementId = tokenIds[0]; + StorageNode node = m_sqliteStorage.getNodeById(elementId); - if (m_sqliteStorage.isNode(elementId)) + if (node.id > 0) { - nodeIds.push_back(elementId); - - std::vector edges = m_sqliteStorage.getEdgesBySourceOrTargetId(elementId); - for (const StorageEdge& edge : edges) + if (Node::intToType(node.type) == Node::NODE_NAMESPACE) { - if (Edge::intToType(edge.type) != Edge::EDGE_MEMBER) - { - edgeIds.push_back(edge.id); - } - } + ids.clear(); + m_hierarchyCache.addFirstVisibleChildIdsForNodeId(elementId, &ids); - addAggregations = true; + isNamespace = true; + } + else + { + nodeIds.push_back(elementId); + + std::vector edges = m_sqliteStorage.getEdgesBySourceOrTargetId(elementId); + for (const StorageEdge& edge : edges) + { + if (Edge::intToType(edge.type) != Edge::EDGE_MEMBER) + { + edgeIds.push_back(edge.id); + } + } + + addAggregations = true; + } } else if (m_sqliteStorage.isEdge(elementId)) { edgeIds.push_back(elementId); } } - else if (tokenIds.size() >= 1) - { - for (size_t i = 0; i < tokenIds.size(); i++) - { - const Id elementId = tokenIds[i]; - if (m_sqliteStorage.isNode(elementId)) + if (ids.size() >= 1 || isNamespace) + { + std::vector nodes = m_sqliteStorage.getNodesByIds(ids); + for (const StorageNode& node : nodes) + { + if (node.id > 0 && (!isNamespace || intToDefinitionType(node.definitionType) == DEFINITION_EXPLICIT)) { - nodeIds.push_back(elementId); + nodeIds.push_back(node.id); } - else + } + + if (nodeIds.size() != ids.size()) + { + std::vector edges = m_sqliteStorage.getEdgesByIds(ids); + for (const StorageEdge& edge : edges) { - edgeIds.push_back(elementId); + if (edge.id > 0) + { + edgeIds.push_back(edge.id); + } } } } - addNodesAndEdgesToGraph(nodeIds, edgeIds, graph); + if (isNamespace) + { + addNodesToGraph(nodeIds, graph); + } + else + { + addNodesWithChildrenAndEdgesToGraph(nodeIds, edgeIds, graph); + } if (addAggregations) { @@ -383,39 +416,6 @@ std::shared_ptr Storage::getGraphForActiveTokenIds(const std::vector& return g; } -std::vector Storage::getActiveTokenIdsForTokenIds(const std::vector& tokenIds) const -{ - bool different = false; - std::vector activeIds; - - for (Id id : tokenIds) - { - if (m_sqliteStorage.isNode(id)) - { - m_hierarchyCache.addFirstVisibleChildIdsForNodeId(id, &activeIds); - if (id != activeIds.back()) - { - different = true; - } - } - else - { - activeIds.push_back(id); - } - } - - if (!different) - { - return tokenIds; - } - - std::set idSet(activeIds.begin(), activeIds.end()); - activeIds.clear(); - activeIds.insert(activeIds.end(), idSet.begin(), idSet.end()); - - return activeIds; -} - // TODO: rename: getActiveElementIdsForId; TODO: make separate function for declarationId std::vector Storage::getActiveTokenIdsForId(Id tokenId, Id* declarationId) const { @@ -815,7 +815,7 @@ void Storage::addEdgesToGraph(const std::vector& edgeIds, Graph* graph) cons } } -void Storage::addNodesAndEdgesToGraph(const std::vector& nodeIds, const std::vector& edgeIds, Graph* graph) const +void Storage::addNodesWithChildrenAndEdgesToGraph(const std::vector& nodeIds, const std::vector& edgeIds, Graph* graph) const { std::set parentNodeIds; @@ -908,7 +908,7 @@ void Storage::addAggregationEdgesToGraph(const Id nodeId, Graph* graph) const nodeIdsToAdd.push_back(aggregationTargetNodeId); } } - addNodesAndEdgesToGraph(nodeIdsToAdd, std::vector(), graph); + addNodesWithChildrenAndEdgesToGraph(nodeIdsToAdd, std::vector(), graph); // create aggregation edges between parents and active node Node* sourceNode = graph->getNodeById(nodeId); diff --git a/src/lib/data/Storage.h b/src/lib/data/Storage.h index 790c5e03..b7d1501c 100644 --- a/src/lib/data/Storage.h +++ b/src/lib/data/Storage.h @@ -57,9 +57,8 @@ public: virtual std::vector getSearchMatchesForTokenIds(const std::vector& elementIds) const; virtual std::shared_ptr getGraphForAll() const; - virtual std::shared_ptr getGraphForActiveTokenIds(const std::vector& tokenIds, bool activeOnly) const; + virtual std::shared_ptr getGraphForActiveTokenIds(const std::vector& tokenIds) const; - virtual std::vector getActiveTokenIdsForTokenIds(const std::vector& tokenIds) const; virtual std::vector getActiveTokenIdsForId(Id tokenId, Id* declarationId) const; virtual std::vector getNodeIdsForLocationIds(const std::vector& locationIds) const; @@ -93,7 +92,7 @@ private: void addNodesToGraph(const std::vector& nodeIds, Graph* graph) const; void addEdgesToGraph(const std::vector& edgeIds, Graph* graph) const; - void addNodesAndEdgesToGraph(const std::vector& nodeIds, const std::vector& edgeIds, Graph* graph) const; + void addNodesWithChildrenAndEdgesToGraph(const std::vector& nodeIds, const std::vector& edgeIds, Graph* graph) const; void addAggregationEdgesToGraph(const Id nodeId, Graph* graph) const; void addComponentAccessToGraph(Graph* graph) const; diff --git a/src/lib/data/access/StorageAccess.h b/src/lib/data/access/StorageAccess.h index 4bd66536..490b06dd 100644 --- a/src/lib/data/access/StorageAccess.h +++ b/src/lib/data/access/StorageAccess.h @@ -39,9 +39,8 @@ public: virtual std::vector getSearchMatchesForTokenIds(const std::vector& tokenIds) const = 0; virtual std::shared_ptr getGraphForAll() const = 0; - virtual std::shared_ptr getGraphForActiveTokenIds(const std::vector& tokenIds, bool activeOnly) const = 0; + virtual std::shared_ptr getGraphForActiveTokenIds(const std::vector& tokenIds) const = 0; - virtual std::vector getActiveTokenIdsForTokenIds(const std::vector& tokenIds) const = 0; virtual std::vector getActiveTokenIdsForId(Id tokenId, Id* declarationId) const = 0; virtual std::vector getNodeIdsForLocationIds(const std::vector& locationIds) const = 0; diff --git a/src/lib/data/access/StorageAccessProxy.cpp b/src/lib/data/access/StorageAccessProxy.cpp index 273da0dd..4a190542 100644 --- a/src/lib/data/access/StorageAccessProxy.cpp +++ b/src/lib/data/access/StorageAccessProxy.cpp @@ -113,26 +113,16 @@ std::shared_ptr StorageAccessProxy::getGraphForAll() const return std::make_shared(); } -std::shared_ptr StorageAccessProxy::getGraphForActiveTokenIds(const std::vector& tokenIds, bool activeOnly) const +std::shared_ptr StorageAccessProxy::getGraphForActiveTokenIds(const std::vector& tokenIds) const { if (hasSubject()) { - return m_subject->getGraphForActiveTokenIds(tokenIds, activeOnly); + return m_subject->getGraphForActiveTokenIds(tokenIds); } return std::make_shared(); } -std::vector StorageAccessProxy::getActiveTokenIdsForTokenIds(const std::vector& tokenIds) const -{ - if (hasSubject()) - { - return m_subject->getActiveTokenIdsForTokenIds(tokenIds); - } - - return std::vector(); -} - std::vector StorageAccessProxy::getActiveTokenIdsForId(Id tokenId, Id* delcarationId) const { if (hasSubject()) diff --git a/src/lib/data/access/StorageAccessProxy.h b/src/lib/data/access/StorageAccessProxy.h index 0a536002..df10e24c 100644 --- a/src/lib/data/access/StorageAccessProxy.h +++ b/src/lib/data/access/StorageAccessProxy.h @@ -26,9 +26,8 @@ public: virtual std::vector getSearchMatchesForTokenIds(const std::vector& tokenIds) const; virtual std::shared_ptr getGraphForAll() const; - virtual std::shared_ptr getGraphForActiveTokenIds(const std::vector& tokenIds, bool activeOnly) const; + virtual std::shared_ptr getGraphForActiveTokenIds(const std::vector& tokenIds) const; - virtual std::vector getActiveTokenIdsForTokenIds(const std::vector& tokenIds) const; virtual std::vector getActiveTokenIdsForId(Id tokenId, Id* declarationId) const; virtual std::vector getNodeIdsForLocationIds(const std::vector& locationIds) const; diff --git a/src/lib/utility/messaging/type/MessageActivateTokens.h b/src/lib/utility/messaging/type/MessageActivateTokens.h index dd40b2eb..a3f0f2be 100644 --- a/src/lib/utility/messaging/type/MessageActivateTokens.h +++ b/src/lib/utility/messaging/type/MessageActivateTokens.h @@ -34,7 +34,6 @@ public: } const std::vector tokenIds; - std::vector originalTokenIds; bool isEdge; bool isAggregation; diff --git a/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp b/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp index 148ff385..2900fb8f 100644 --- a/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp +++ b/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp @@ -105,7 +105,7 @@ bool QtGraphNode::setPosition(const Vec2i& position) Vec2i currentPosition = getPosition(); Vec2i offset = position - currentPosition; - if (offset.getLength() > 0.0f) + if (offset.x != 0 || offset.y != 0) { this->moveBy(offset.x, offset.y); notifyEdgesAfterMove();