ui: Improved graph layouting to properly place and resize subnodes

This change moves the toplevel node resizing from the QtPostProcessor to the GraphController to place and resize their
subnodes accordingly as well.
This commit is contained in:
Eberhard Graether
2015-04-30 16:25:24 +02:00
parent 749b1647e4
commit aa0c40b213
6 changed files with 102 additions and 37 deletions
@@ -375,6 +375,11 @@ void GraphController::layoutNesting()
{
layoutNestingRecursive(node);
}
for (DummyNode& node : m_dummyNodes)
{
layoutToGrid(node);
}
}
void GraphController::layoutNestingRecursive(DummyNode& node) const
@@ -387,7 +392,7 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const
}
else if (node.isAccessNode())
{
margins = GraphViewStyle::getMarginsOfAccessNode();
margins = GraphViewStyle::getMarginsOfAccessNode(node.accessType);
}
else if (node.isExpandToggleNode())
{
@@ -474,7 +479,16 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const
for (DummyNode& subNode : node.subNodes)
{
if (subNode.isExpandToggleNode())
if (!subNode.visible)
{
continue;
}
if (subNode.isAccessNode())
{
subNode.size.x = width;
}
else if (subNode.isExpandToggleNode())
{
subNode.position.x = margins.left + width - subNode.size.x;
subNode.position.y = 6;
@@ -512,6 +526,48 @@ void GraphController::addExpandToggleNode(DummyNode& node) const
node.subNodes.push_back(expandNode);
}
void GraphController::layoutToGrid(DummyNode& node) const
{
if (!node.isGraphNode())
{
LOG_ERROR("Only GraphNodes can be layouted to the grid");
return;
}
size_t width = GraphViewStyle::toGridSize(node.size.x);
size_t height = GraphViewStyle::toGridSize(node.size.y);
size_t incX = width - node.size.x;
size_t incY = height - node.size.y;
node.size.x = width;
node.size.y = height;
DummyNode* lastAccessNode = nullptr;
for (DummyNode& subNode : node.subNodes)
{
if (!subNode.visible)
{
continue;
}
if (subNode.isAccessNode())
{
subNode.size.x = subNode.size.x + incX;
lastAccessNode = &subNode;
}
else if (subNode.isExpandToggleNode())
{
subNode.position.x = subNode.position.x + incX;
}
}
if (lastAccessNode)
{
lastAccessNode->size.y = lastAccessNode->size.y + incY;
}
}
DummyNode* GraphController::findDummyNodeRecursive(std::vector<DummyNode>& nodes, Id tokenId)
{
for (DummyNode& node : nodes)
@@ -54,6 +54,7 @@ private:
void layoutNesting();
void layoutNestingRecursive(DummyNode& node) const;
void addExpandToggleNode(DummyNode& node) const;
void layoutToGrid(DummyNode& node) const;
DummyNode* findDummyNodeRecursive(std::vector<DummyNode>& nodes, Id tokenId);
DummyNode* findDummyNodeAccessRecursive(std::vector<DummyNode>& nodes, Id parentId, TokenComponentAccess::AccessType type);
+32 -3
View File
@@ -125,7 +125,7 @@ std::string GraphViewStyle::getFontNameOfExpandToggleNode()
GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType type, bool hasChildren)
{
NodeMargins margins;
margins.spacingX = 12;
margins.spacingX = 6;
margins.spacingY = 8;
switch (type)
@@ -178,7 +178,7 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType
return margins;
}
GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfAccessNode()
GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfAccessNode(TokenComponentAccess::AccessType type)
{
NodeMargins margins;
margins.spacingX = margins.spacingY = 8;
@@ -187,7 +187,21 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfAccessNode()
margins.top = 40;
margins.bottom = 10;
margins.minWidth = 82;
switch (type)
{
case TokenComponentAccess::ACCESS_NONE:
margins.minWidth = 30;
break;
case TokenComponentAccess::ACCESS_PUBLIC:
margins.minWidth = 56;
break;
case TokenComponentAccess::ACCESS_PROTECTED:
margins.minWidth = 80;
break;
case TokenComponentAccess::ACCESS_PRIVATE:
margins.minWidth = 64;
break;
}
return margins;
}
@@ -402,5 +416,20 @@ GraphViewStyle::EdgeStyle GraphViewStyle::getStyleForEdgeType(Edge::EdgeType typ
return style;
}
size_t GraphViewStyle::toGridSize(size_t x)
{
size_t r = s_gridCellSize;
while (r < x - 1)
{
r += s_gridCellPadding + s_gridCellSize;
}
return r;
}
size_t GraphViewStyle::s_gridCellSize = 5;
size_t GraphViewStyle::s_gridCellPadding = 10;
std::map<Node::NodeType, float> GraphViewStyle::s_charWidths;
std::shared_ptr<GraphViewStyleImpl> GraphViewStyle::s_impl;
+7 -1
View File
@@ -7,6 +7,7 @@
#include "component/view/graphElements/GraphNode.h"
#include "component/view/GraphViewStyleImpl.h"
#include "data/graph/Node.h"
#include "data/graph/token_component/TokenComponentAccess.h"
class GraphViewStyle
{
@@ -88,7 +89,7 @@ public:
static std::string getFontNameOfExpandToggleNode();
static NodeMargins getMarginsForNodeType(Node::NodeType type, bool hasChildren);
static NodeMargins getMarginsOfAccessNode();
static NodeMargins getMarginsOfAccessNode(TokenComponentAccess::AccessType type);
static NodeMargins getMarginsOfExpandToggleNode();
static NodeStyle getStyleForNodeType(Node::NodeType type, bool isActive, bool isFocused, bool hasChildren);
@@ -97,6 +98,11 @@ public:
static EdgeStyle getStyleForEdgeType(Edge::EdgeType type, bool isActive, bool isFocused);
static size_t toGridSize(size_t x);
static size_t s_gridCellSize;
static size_t s_gridCellPadding;
private:
static std::map<Node::NodeType, float> s_charWidths;
static std::shared_ptr<GraphViewStyleImpl> s_impl;