logic: removed namespace splitting from GraphController
Namespace splitting is now handled in active token id retrieval from the Storage, so that namespace nodes are not added to the Graph at all and complexity in the GraphController is reduced.
This commit is contained in:
@@ -95,12 +95,12 @@ void FeatureController::handleMessage(MessageActivateNodes* message)
|
||||
|
||||
void FeatureController::handleMessage(MessageActivateTokenLocations* message)
|
||||
{
|
||||
std::vector<Id> nodeIds;
|
||||
MessageActivateNodes msg;
|
||||
std::vector<Id> nodeIds = m_storageAccess->getNodeIdsForLocationIds(message->locationIds);
|
||||
nodeIds = m_storageAccess->getActiveTokenIdsForTokenIds(nodeIds);
|
||||
|
||||
for (Id locationId : message->locationIds)
|
||||
MessageActivateNodes msg;
|
||||
for (Id nodeId : nodeIds)
|
||||
{
|
||||
Id nodeId = m_storageAccess->getActiveNodeIdForLocationId(locationId);
|
||||
msg.addNode(
|
||||
nodeId,
|
||||
m_storageAccess->getNodeTypeForNodeWithId(nodeId),
|
||||
@@ -112,7 +112,10 @@ void FeatureController::handleMessage(MessageActivateTokenLocations* message)
|
||||
|
||||
void FeatureController::handleMessage(MessageSearch* message)
|
||||
{
|
||||
MessageActivateTokens m(m_storageAccess->getTokenIdsForMatches(message->getMatches()));
|
||||
std::vector<Id> tokenIds = m_storageAccess->getTokenIdsForMatches(message->getMatches());
|
||||
tokenIds = m_storageAccess->getActiveTokenIdsForTokenIds(tokenIds);
|
||||
|
||||
MessageActivateTokens m(tokenIds);
|
||||
m.undoRedoType = message->undoRedoType;
|
||||
m.dispatchImmediately();
|
||||
}
|
||||
|
||||
@@ -174,8 +174,6 @@ void GraphController::createDummyGraphForTokenIds(const std::vector<Id>& tokenId
|
||||
autoExpandActiveNode(tokenIds);
|
||||
setActiveAndVisibility(tokenIds);
|
||||
|
||||
splitNamespaceNodes();
|
||||
|
||||
bundleNodes();
|
||||
|
||||
layoutNesting();
|
||||
@@ -276,45 +274,6 @@ DummyNode GraphController::createDummyNodeTopDown(Node* node)
|
||||
return result;
|
||||
}
|
||||
|
||||
void GraphController::splitNamespaceNodes()
|
||||
{
|
||||
std::vector<DummyNode> nodes;
|
||||
|
||||
for (const DummyNode& node : m_dummyNodes)
|
||||
{
|
||||
std::vector<DummyNode> newNodes = splitNamespaceNodesRecursive(node, false, true);
|
||||
nodes.insert(nodes.end(), newNodes.begin(), newNodes.end());
|
||||
}
|
||||
|
||||
m_dummyNodes = nodes;
|
||||
}
|
||||
|
||||
std::vector<DummyNode> GraphController::splitNamespaceNodesRecursive(const DummyNode& node, bool active, bool topLevel)
|
||||
{
|
||||
std::vector<DummyNode> nodes;
|
||||
active |= node.active;
|
||||
|
||||
if (node.isGraphNode() && node.data->isType(Node::NODE_NOT_VISIBLE))
|
||||
{
|
||||
for (const DummyNode& subNode : node.subNodes)
|
||||
{
|
||||
std::vector<DummyNode> newNodes = splitNamespaceNodesRecursive(subNode, active, false);
|
||||
for (DummyNode& newNode : newNodes)
|
||||
{
|
||||
newNode.hasParent = false;
|
||||
}
|
||||
|
||||
nodes.insert(nodes.end(), newNodes.begin(), newNodes.end());
|
||||
}
|
||||
}
|
||||
else if (topLevel || active || node.connected)
|
||||
{
|
||||
nodes.push_back(node);
|
||||
}
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
void GraphController::autoExpandActiveNode(const std::vector<Id>& activeTokenIds)
|
||||
{
|
||||
DummyNode* node = nullptr;
|
||||
@@ -419,8 +378,7 @@ void GraphController::setNodeVisibilityRecursiveTopDown(DummyNode& node, bool pa
|
||||
|
||||
if ((node.isGraphNode() && node.isExpanded()) ||
|
||||
(node.isAccessNode() && parentExpanded) ||
|
||||
(node.isGraphNode() && node.data->isType(Node::NODE_ENUM)) ||
|
||||
(node.isGraphNode() && node.data->isType(Node::NODE_NOT_VISIBLE)))
|
||||
(node.isGraphNode() && node.data->isType(Node::NODE_ENUM)))
|
||||
{
|
||||
for (DummyNode& subNode : node.subNodes)
|
||||
{
|
||||
@@ -897,20 +855,9 @@ DummyNode* GraphController::findTopLevelDummyNodeRecursive(std::vector<DummyNode
|
||||
{
|
||||
for (DummyNode& node : nodes)
|
||||
{
|
||||
if (node.isGraphNode())
|
||||
if (node.isGraphNode() && node.data->getId() == tokenId)
|
||||
{
|
||||
if (node.data->isType(Node::NODE_NOT_VISIBLE))
|
||||
{
|
||||
DummyNode* result = findDummyNodeRecursive(node.subNodes, tokenId);
|
||||
if (result != nullptr)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if (node.data->getId() == tokenId)
|
||||
{
|
||||
return &node;
|
||||
}
|
||||
return &node;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,9 +51,6 @@ private:
|
||||
void createDummyGraphForTokenIds(const std::vector<Id>& tokenIds);
|
||||
DummyNode createDummyNodeTopDown(Node* node);
|
||||
|
||||
void splitNamespaceNodes();
|
||||
std::vector<DummyNode> splitNamespaceNodesRecursive(const DummyNode& node, bool active, bool topLevel);
|
||||
|
||||
void autoExpandActiveNode(const std::vector<Id>& activeTokenIds);
|
||||
|
||||
void setActiveAndVisibility(const std::vector<Id>& activeTokenIds);
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "component/controller/helper/DummyNode.h"
|
||||
#include "component/view/GraphViewStyle.h"
|
||||
|
||||
const Edge::EdgeTypeMask BucketGrid::s_verticalEdgeMask = Edge::EDGE_INHERITANCE | Edge::EDGE_OVERRIDE;
|
||||
|
||||
Bucket::Bucket()
|
||||
: i(0)
|
||||
, j(0)
|
||||
@@ -157,7 +159,7 @@ void BucketGrid::createBuckets(std::vector<DummyNode>& nodes, const std::vector<
|
||||
}
|
||||
else
|
||||
{
|
||||
bool horizontal = edge->data ? !edge->data->isType(Edge::EDGE_INHERITANCE) : true;
|
||||
bool horizontal = edge->data ? !edge->data->isType(s_verticalEdgeMask) : true;
|
||||
removeEdge = addNode(owner, target, horizontal);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "utility/math/Vector2.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
#include "data/graph/Edge.h"
|
||||
|
||||
struct DummyEdge;
|
||||
struct DummyNode;
|
||||
|
||||
@@ -41,6 +43,8 @@ public:
|
||||
static void layout(std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges, Vec2i viewSize);
|
||||
|
||||
private:
|
||||
static const Edge::EdgeTypeMask s_verticalEdgeMask;
|
||||
|
||||
BucketGrid(Vec2i viewSize);
|
||||
|
||||
void createBuckets(std::vector<DummyNode>& nodes, const std::vector<DummyEdge>& edges);
|
||||
|
||||
@@ -54,6 +54,21 @@ void HierarchyCache::HierarchyNode::addChildIdsRecursive(std::vector<Id>* nodeId
|
||||
}
|
||||
}
|
||||
|
||||
void HierarchyCache::HierarchyNode::addVisibleNodeIdsRecursive(std::vector<Id>* nodeIds) const
|
||||
{
|
||||
if (isVisible())
|
||||
{
|
||||
nodeIds->push_back(getNodeId());
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const HierarchyNode* child : m_children)
|
||||
{
|
||||
child->addVisibleNodeIdsRecursive(nodeIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool HierarchyCache::HierarchyNode::isVisible() const
|
||||
{
|
||||
return m_isVisible;
|
||||
@@ -65,7 +80,6 @@ void HierarchyCache::HierarchyNode::setIsVisible(bool isVisible)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HierarchyCache::clear()
|
||||
{
|
||||
m_nodes.clear();
|
||||
@@ -108,6 +122,19 @@ void HierarchyCache::addAllChildIdsForNodeId(Id nodeId, std::vector<Id>* nodeIds
|
||||
}
|
||||
}
|
||||
|
||||
void HierarchyCache::addFirstVisibleChildIdsForNodeId(Id nodeId, std::vector<Id>* nodeIds) const
|
||||
{
|
||||
HierarchyNode* node = getNode(nodeId);
|
||||
if (node)
|
||||
{
|
||||
node->addVisibleNodeIdsRecursive(nodeIds);
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeIds->push_back(nodeId);
|
||||
}
|
||||
}
|
||||
|
||||
HierarchyCache::HierarchyNode* HierarchyCache::getNode(Id nodeId) const
|
||||
{
|
||||
std::map<Id, std::shared_ptr<HierarchyNode>>::const_iterator it = m_nodes.find(nodeId);
|
||||
|
||||
@@ -15,7 +15,9 @@ public:
|
||||
void createConnection(Id edgeId, Id fromId, Id toId, bool fromVisible);
|
||||
|
||||
Id getLastVisibleParentNodeId(Id nodeId) const;
|
||||
|
||||
void addAllChildIdsForNodeId(Id nodeId, std::vector<Id>* nodeIds, std::vector<Id>* edgeIds) const;
|
||||
void addFirstVisibleChildIdsForNodeId(Id nodeId, std::vector<Id>* nodeIds) const;
|
||||
|
||||
private:
|
||||
class HierarchyNode
|
||||
@@ -33,7 +35,9 @@ private:
|
||||
|
||||
void addChild(HierarchyNode* child);
|
||||
const std::vector<HierarchyNode*>& getChildren() const;
|
||||
|
||||
void addChildIdsRecursive(std::vector<Id>* nodeIds, std::vector<Id>* edgeIds) const;
|
||||
void addVisibleNodeIdsRecursive(std::vector<Id>* nodeIds) const;
|
||||
|
||||
bool isVisible() const;
|
||||
void setIsVisible(bool isVisible);
|
||||
|
||||
@@ -824,6 +824,25 @@ std::shared_ptr<Graph> Storage::getGraphForActiveTokenIds(const std::vector<Id>&
|
||||
return g;
|
||||
}
|
||||
|
||||
std::vector<Id> Storage::getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
std::vector<Id> activeIds;
|
||||
|
||||
for (Id id : tokenIds)
|
||||
{
|
||||
if (m_sqliteStorage.isNode(id))
|
||||
{
|
||||
m_hierarchyCache.addFirstVisibleChildIdsForNodeId(id, &activeIds);
|
||||
}
|
||||
else
|
||||
{
|
||||
activeIds.push_back(id);
|
||||
}
|
||||
}
|
||||
|
||||
return activeIds;
|
||||
}
|
||||
|
||||
// TODO: rename: getActiveElementIdsForId; TODO: make separate function for declarationId
|
||||
std::vector<Id> Storage::getActiveTokenIdsForId(Id tokenId, Id* declarationId) const
|
||||
{
|
||||
@@ -849,16 +868,26 @@ std::vector<Id> Storage::getActiveTokenIdsForId(Id tokenId, Id* declarationId) c
|
||||
return activeTokenIds;
|
||||
}
|
||||
|
||||
Id Storage::getActiveNodeIdForLocationId(Id locationId) const
|
||||
std::vector<Id> Storage::getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const
|
||||
{
|
||||
Id activeElementId = m_sqliteStorage.getElementIdByLocationId(locationId);
|
||||
std::vector<Id> nodeIds;
|
||||
|
||||
StorageEdge edge = m_sqliteStorage.getEdgeById(activeElementId);
|
||||
if (edge.id != 0) // here we test if location is an edge.
|
||||
for (Id locationId : locationIds)
|
||||
{
|
||||
activeElementId = edge.targetNodeId;
|
||||
Id elementId = m_sqliteStorage.getElementIdByLocationId(locationId);
|
||||
|
||||
StorageEdge edge = m_sqliteStorage.getEdgeById(elementId);
|
||||
if (edge.id != 0) // here we test if location is an edge.
|
||||
{
|
||||
nodeIds.push_back(edge.targetNodeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeIds.push_back(elementId);
|
||||
}
|
||||
}
|
||||
return activeElementId;
|
||||
|
||||
return nodeIds;
|
||||
}
|
||||
|
||||
std::vector<Id> Storage::getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const
|
||||
|
||||
@@ -132,8 +132,10 @@ public:
|
||||
|
||||
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const;
|
||||
virtual Id getActiveNodeIdForLocationId(Id locationId) const;
|
||||
|
||||
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
|
||||
virtual std::vector<Id> getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const;
|
||||
virtual Id getTokenIdForFileNode(const FilePath& filePath) const;
|
||||
|
||||
@@ -34,8 +34,10 @@ public:
|
||||
|
||||
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const = 0;
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const = 0;
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const = 0;
|
||||
virtual Id getActiveNodeIdForLocationId(Id locationId) const = 0;
|
||||
|
||||
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const = 0;
|
||||
|
||||
virtual std::vector<Id> getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const = 0;
|
||||
virtual Id getTokenIdForFileNode(const FilePath& filePath) const = 0;
|
||||
|
||||
@@ -103,6 +103,16 @@ std::shared_ptr<Graph> StorageAccessProxy::getGraphForActiveTokenIds(const std::
|
||||
return std::make_shared<Graph>();
|
||||
}
|
||||
|
||||
std::vector<Id> StorageAccessProxy::getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getActiveTokenIdsForTokenIds(tokenIds);
|
||||
}
|
||||
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
std::vector<Id> StorageAccessProxy::getActiveTokenIdsForId(Id tokenId, Id* delcarationId) const
|
||||
{
|
||||
if (hasSubject())
|
||||
@@ -113,14 +123,14 @@ std::vector<Id> StorageAccessProxy::getActiveTokenIdsForId(Id tokenId, Id* delca
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
Id StorageAccessProxy::getActiveNodeIdForLocationId(Id locationId) const
|
||||
std::vector<Id> StorageAccessProxy::getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getActiveNodeIdForLocationId(locationId);
|
||||
return m_subject->getNodeIdsForLocationIds(locationIds);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
std::vector<Id> StorageAccessProxy::getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const
|
||||
|
||||
@@ -25,8 +25,10 @@ public:
|
||||
|
||||
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const;
|
||||
virtual Id getActiveNodeIdForLocationId(Id locationId) const;
|
||||
|
||||
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
|
||||
virtual std::vector<Id> getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const;
|
||||
virtual Id getTokenIdForFileNode(const FilePath& filePath) const;
|
||||
|
||||
@@ -16,14 +16,6 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
MessageActivateTokens(Id tokenId)
|
||||
: tokenIds(1, tokenId)
|
||||
, isEdge(false)
|
||||
, isAggregation(false)
|
||||
, isFromSystem(false)
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageActivateTokens";
|
||||
|
||||
Reference in New Issue
Block a user