ui: Fixed group related issues in graph

* fixed aggregation layout within group
* fixed moving of group did not resize view
* fixed edges behind group could not be hovered
* fixed overlapping lines in sublayout
* fixed use of correct column width in sublayout
This commit is contained in:
Eberhard Graether
2018-04-11 14:11:53 +02:00
parent cbd782d0c1
commit 5f56a167d1
12 changed files with 57 additions and 43 deletions
@@ -100,18 +100,21 @@ void QtGraphEdge::updateLine()
Vec4i ownerParentRect;
Vec4i targetParentRect;
const QtGraphNode* ownerParent = owner->getLastParent();
const QtGraphNode* targetParent = target->getLastParent();
const QtGraphNode* ownerNonGroupParent = owner->getLastNonGroupParent();
const QtGraphNode* targetNonGroupParent = target->getLastNonGroupParent();
if (owner->getLastParent() == target->getLastParent() && owner->getLastParent()->isGroupNode())
if (ownerParent == targetParent && ownerParent->isGroupNode())
{
ownerParentRect = ownerNonGroupParent->getBoundingRect();
targetParentRect = targetNonGroupParent->getBoundingRect();
}
else
{
ownerParentRect = owner->getLastParent()->getBoundingRect();
targetParentRect = target->getLastParent()->getBoundingRect();
ownerParentRect = ownerParent->getBoundingRect();
targetParentRect = targetParent->getBoundingRect();
}
if (m_useBezier)
@@ -168,10 +171,22 @@ void QtGraphEdge::updateLine()
}
else
{
const Vec2i& ownerColumnSize = m_owner->getLastParent()->getColumnSize();
const Vec2i& targetColumnSize = m_target->getLastParent()->getColumnSize();
ownerParentRect.z = std::max(ownerParentRect.x + ownerColumnSize.x, ownerParentRect.z());
targetParentRect.z = std::max(targetParentRect.x + targetColumnSize.x, targetParentRect.z());
const Vec2i* ownerColumnSize;
const Vec2i* targetColumnSize;
if (ownerParent != targetParent)
{
ownerColumnSize = &ownerParent->getColumnSize();
targetColumnSize = &targetParent->getColumnSize();
}
else
{
ownerColumnSize = &ownerNonGroupParent->getColumnSize();
targetColumnSize = &targetNonGroupParent->getColumnSize();
}
ownerParentRect.z = std::max(ownerParentRect.x + ownerColumnSize->x, ownerParentRect.z());
targetParentRect.z = std::max(targetParentRect.x + targetColumnSize->x, targetParentRect.z());
if (!m_child)
{
@@ -202,7 +217,7 @@ void QtGraphEdge::updateLine()
}
if (type == Edge::EDGE_INHERITANCE || (type == Edge::EDGE_TEMPLATE_SPECIALIZATION &&
owner == owner->getLastNonGroupParent() && target == target->getLastNonGroupParent()))
owner == ownerNonGroupParent && target == targetNonGroupParent))
{
child->setRoute(QtLineItemBase::ROUTE_VERTICAL);
@@ -212,7 +227,7 @@ void QtGraphEdge::updateLine()
}
}
else if (type != Edge::EDGE_AGGREGATION ||
owner != owner->getLastNonGroupParent() || target != target->getLastNonGroupParent())
owner != ownerNonGroupParent || target != targetNonGroupParent)
{
child->setRoute(QtLineItemBase::ROUTE_HORIZONTAL);
}
@@ -12,6 +12,7 @@
#include "qt/view/graphElements/nodeComponents/QtGraphNodeComponent.h"
#include "qt/view/graphElements/QtGraphEdge.h"
#include "utility/messaging/type/MessageGraphNodeHide.h"
#include "utility/messaging/type/MessageGraphNodeMove.h"
#include "utility/ResourcePaths.h"
#include "utility/utilityString.h"
@@ -374,6 +375,11 @@ void QtGraphNode::addSubNode(QtGraphNode* node)
void QtGraphNode::moved(const Vec2i& oldPosition)
{
setPosition(GraphViewStyle::alignOnRaster(getPosition()));
if (isDataNode() || isGroupNode() || isBundleNode())
{
MessageGraphNodeMove(getTokenId(), getPosition() - oldPosition).dispatch();
}
}
void QtGraphNode::onClick()
@@ -4,7 +4,6 @@
#include <QPen>
#include "utility/messaging/type/MessageGraphNodeBundleSplit.h"
#include "utility/messaging/type/MessageGraphNodeMove.h"
#include "component/view/GraphViewStyle.h"
#include "qt/graphics/QtCountCircleItem.h"
@@ -47,13 +46,6 @@ void QtGraphNodeBundle::onClick()
).dispatch();
}
void QtGraphNodeBundle::moved(const Vec2i& oldPosition)
{
QtGraphNode::moved(oldPosition);
MessageGraphNodeMove(m_tokenId, getPosition() - oldPosition).dispatch();
}
void QtGraphNodeBundle::updateStyle()
{
GraphViewStyle::NodeStyle style;
@@ -19,7 +19,6 @@ public:
virtual Id getTokenId() const;
virtual void onClick();
virtual void moved(const Vec2i& oldPosition);
virtual void updateStyle();
protected:
@@ -5,7 +5,6 @@
#include "utility/messaging/type/MessageDeactivateEdge.h"
#include "utility/messaging/type/MessageFocusIn.h"
#include "utility/messaging/type/MessageFocusOut.h"
#include "utility/messaging/type/MessageGraphNodeMove.h"
#include "data/graph/token_component/TokenComponentFilePath.h"
@@ -58,13 +57,6 @@ void QtGraphNodeData::onClick()
MessageActivateNodes(m_data->getId()).dispatch();
}
void QtGraphNodeData::moved(const Vec2i& oldPosition)
{
QtGraphNode::moved(oldPosition);
MessageGraphNodeMove(m_data->getId(), getPosition() - oldPosition).dispatch();
}
void QtGraphNodeData::updateStyle()
{
GraphViewStyle::NodeStyle style = GraphViewStyle::getStyleForNodeType(
@@ -22,7 +22,6 @@ public:
virtual Id getTokenId() const;
virtual void onClick();
virtual void moved(const Vec2i& oldPosition);
virtual void updateStyle();
protected:
@@ -25,8 +25,6 @@ QtGraphNodeGroup::QtGraphNodeGroup(
setAcceptHoverEvents(true);
}
setName(name);
if (type == GroupType::FRAMELESS)
{
m_rect->hide();
@@ -38,6 +36,8 @@ QtGraphNodeGroup::QtGraphNodeGroup(
return;
}
setName(name);
m_background = new QGraphicsPolygonItem(this);
m_background->setZValue(-3.f);
@@ -56,6 +56,7 @@ QtGraphNodeGroup::QtGraphNodeGroup(
path.lineTo(width - radius, height);
path.arcTo(width - 2 * radius, height - 2 * radius, 2 * radius, 2 * radius, 270, 90);
path.closeSubpath();
m_path = path;
m_background->setPolygon(path.toFillPolygon());
}
@@ -104,6 +105,16 @@ void QtGraphNodeGroup::updateStyle()
setStyle(style);
}
QPainterPath QtGraphNodeGroup::shape() const
{
if (m_path.isEmpty())
{
m_path.addRect(boundingRect());
}
return m_path;
}
void QtGraphNodeGroup::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{
if (m_type == GroupType::FILE || m_type == GroupType::NAMESPACE)
@@ -5,6 +5,7 @@
#include "qt/view/graphElements/QtGraphNode.h"
class QGraphicsPolygonItem;
class QPainterPath;
class QtGraphNodeGroup
: public QtGraphNode
@@ -21,6 +22,8 @@ public:
virtual void onClick();
virtual void updateStyle();
virtual QPainterPath shape() const;
protected:
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent* event);
@@ -31,6 +34,7 @@ private:
const bool m_interactive;
QGraphicsPolygonItem* m_background = nullptr;
mutable QPainterPath m_path;
};
#endif // QT_GRAPH_NODE_GROUP_H