From 9773c30fdc85cd337dfd66fee5a83cbc5a4c92fd Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Wed, 7 Feb 2018 23:15:55 +0100 Subject: [PATCH] ui: Improved vertical layout for override and inheritance edges --- src/lib/component/view/GraphViewStyle.cpp | 5 ++ .../messaging/type/MessageScrollSpeedChange.h | 2 +- src/lib_gui/qt/graphics/QtLineItemBase.cpp | 20 +++++-- src/lib_gui/qt/graphics/QtLineItemBase.h | 4 +- .../qt/view/graphElements/QtGraphEdge.cpp | 56 +++++++++++-------- .../qt/view/graphElements/QtGraphEdge.h | 4 -- .../qt/view/graphElements/QtGraphNode.cpp | 18 ++++++ .../qt/view/graphElements/QtGraphNode.h | 1 + 8 files changed, 75 insertions(+), 35 deletions(-) diff --git a/src/lib/component/view/GraphViewStyle.cpp b/src/lib/component/view/GraphViewStyle.cpp index 49d0133d..a5a23945 100644 --- a/src/lib/component/view/GraphViewStyle.cpp +++ b/src/lib/component/view/GraphViewStyle.cpp @@ -575,7 +575,12 @@ GraphViewStyle::EdgeStyle GraphViewStyle::getStyleForEdgeType( style.arrowLength = 20; style.arrowWidth = 14; style.arrowClosed = true; + style.originOffset.x = 7; style.targetOffset.x = 34; + style.originOffset.y = -15; + style.targetOffset.y = 15; + style.verticalOffset = 0; + style.cornerRadius = 7; style.zValue = isActive ? 2 : -3; break; case Edge::EDGE_INCLUDE: diff --git a/src/lib/utility/messaging/type/MessageScrollSpeedChange.h b/src/lib/utility/messaging/type/MessageScrollSpeedChange.h index d2d7400a..fd76aa11 100644 --- a/src/lib/utility/messaging/type/MessageScrollSpeedChange.h +++ b/src/lib/utility/messaging/type/MessageScrollSpeedChange.h @@ -17,7 +17,7 @@ public: return "MessageScrollSpeedChange"; } - virtual void print(std::ostream& os) const + virtual void print(std::wostream& os) const { os << scrollSpeed; } diff --git a/src/lib_gui/qt/graphics/QtLineItemBase.cpp b/src/lib_gui/qt/graphics/QtLineItemBase.cpp index 71897de6..bc27cd40 100644 --- a/src/lib_gui/qt/graphics/QtLineItemBase.cpp +++ b/src/lib_gui/qt/graphics/QtLineItemBase.cpp @@ -8,7 +8,7 @@ QtLineItemBase::QtLineItemBase(QGraphicsItem* parent) , m_showArrow(true) , m_onFront(false) , m_onBack(false) - , m_horizontalIn(false) + , m_earlyBend(false) , m_route(ROUTE_ANY) , m_pivot(PIVOT_THIRD) { @@ -64,9 +64,9 @@ void QtLineItemBase::setOnBack(bool back) m_onBack = back; } -void QtLineItemBase::setHorizontalIn(bool horizontal) +void QtLineItemBase::setEarlyBend(bool earlyBend) { - m_horizontalIn = horizontal; + m_earlyBend = earlyBend; } QPolygon QtLineItemBase::getPath() const @@ -96,6 +96,7 @@ QPolygon QtLineItemBase::getPath() const float dist = -1; std::map dists; + // find start and end points if (m_onFront) { io = 3; @@ -139,6 +140,7 @@ QPolygon QtLineItemBase::getPath() const } } + // start/end and offsetted start/end points Vec2f o[4]; getPivotPoints(o, oR, oR, oOff.y, false); @@ -167,11 +169,12 @@ QPolygon QtLineItemBase::getPath() const case 3: c.setX(c.x() - oOff.x); break; } + // move one offsetted point if (it != io) { if ((it == 1 && b.x() < c.x()) || (io == 1 && b.x() > c.x())) { - if (m_horizontalIn) + if (m_earlyBend) { b.setX(c.x()); } @@ -182,7 +185,14 @@ QPolygon QtLineItemBase::getPath() const } else if ((it == 2 && b.y() < c.y()) || (io == 2 && b.y() > c.y())) { - c.setY(b.y()); + if (m_earlyBend) + { + b.setY(c.y()); + } + else + { + c.setY(b.y()); + } } else if ( (it == 3 && b.x() < c.x()) || (io == 3 && b.x() > c.x()) || diff --git a/src/lib_gui/qt/graphics/QtLineItemBase.h b/src/lib_gui/qt/graphics/QtLineItemBase.h index fe65d6eb..aeed706f 100644 --- a/src/lib_gui/qt/graphics/QtLineItemBase.h +++ b/src/lib_gui/qt/graphics/QtLineItemBase.h @@ -38,7 +38,7 @@ public: void setOnFront(bool front); void setOnBack(bool back); - void setHorizontalIn(bool horizontal); + void setEarlyBend(bool earlyBend); protected: QPolygon getPath() const; @@ -54,7 +54,7 @@ protected: bool m_onFront; bool m_onBack; - bool m_horizontalIn; + bool m_earlyBend; Route m_route; Pivot m_pivot; diff --git a/src/lib_gui/qt/view/graphElements/QtGraphEdge.cpp b/src/lib_gui/qt/view/graphElements/QtGraphEdge.cpp index 599ed5d4..fbabbeab 100644 --- a/src/lib_gui/qt/view/graphElements/QtGraphEdge.cpp +++ b/src/lib_gui/qt/view/graphElements/QtGraphEdge.cpp @@ -37,8 +37,6 @@ QtGraphEdge::QtGraphEdge( , m_target(target) , m_child(nullptr) , m_isActive(isActive) - , m_fromActive(false) - , m_toActive(false) , m_isFocused(false) , m_weight(weight) , m_direction(direction) @@ -55,9 +53,6 @@ QtGraphEdge::QtGraphEdge( m_target = temp; } - m_fromActive = m_owner->getIsActive(); - m_toActive = m_target->getIsActive(); - s_focusedEdge = nullptr; s_focusedBezierEdge = nullptr; } @@ -99,6 +94,12 @@ void QtGraphEdge::updateLine() Edge::EdgeType type = (getData() ? getData()->getType() : Edge::EDGE_AGGREGATION); GraphViewStyle::EdgeStyle style = GraphViewStyle::getStyleForEdgeType(type, m_isActive | m_isFocused, false, m_isTrailEdge); + Vec4i ownerRect = owner->getBoundingRect(); + Vec4i targetRect = target->getBoundingRect(); + + Vec4i ownerParentRect = owner->getParentBoundingRect(); + Vec4i targetParentRect = target->getParentBoundingRect(); + if (m_useBezier) { for (QGraphicsItem* item : childItems()) @@ -110,9 +111,6 @@ void QtGraphEdge::updateLine() style.originOffset.y() = 0; style.targetOffset.y() = 0; - Vec4i ownerRect = owner->getBoundingRect(); - Vec4i ownerParentRect = owner->getParentBoundingRect(); - QtLineItemBase::Route route = m_isHorizontalTrail ? QtLineItemBase::ROUTE_HORIZONTAL : QtLineItemBase::ROUTE_VERTICAL; @@ -140,9 +138,7 @@ void QtGraphEdge::updateLine() bool showArrow = m_direction != TokenComponentAggregation::DIRECTION_NONE; QtLineItemBezier* bezier = new QtLineItemBezier(this); - bezier->updateLine( - ownerRect, target->getBoundingRect(), ownerParentRect, target->getParentBoundingRect(), - style, m_weight, showArrow); + bezier->updateLine(ownerRect, targetRect, ownerParentRect, targetParentRect, style, m_weight, showArrow); bezier->setRoute(route); bezier->setPivot(QtLineItemBase::PIVOT_MIDDLE); @@ -167,32 +163,49 @@ void QtGraphEdge::updateLine() QtLineItemAngled* child = dynamic_cast(m_child); - if (m_fromActive && owner->getLastParent() == target->getLastParent()) + if (owner->getIsActive() && owner->getLastParent() == target->getLastParent()) { child->setOnBack(true); } - if (m_toActive) + if (target->getIsActive()) { - child->setHorizontalIn(true); + child->setEarlyBend(true); - if (owner->getLastParent() == target->getLastParent()) + if (owner->getLastParent() == target->getLastParent() || + (type == Edge::EDGE_OVERRIDE && + targetParentRect.z() + style.targetOffset.x + style.originOffset.x > ownerParentRect.x())) { child->setOnFront(true); } + else + { + child->setOnFront(false); + } } - if (type != Edge::EDGE_INHERITANCE && - (type != Edge::EDGE_AGGREGATION || owner != owner->getLastParent() || target != target->getLastParent())) + if (type == Edge::EDGE_INHERITANCE) + { + child->setRoute(QtLineItemBase::ROUTE_VERTICAL); + + if (target->hasActiveChild()) + { + child->setEarlyBend(true); + } + } + else if (type != Edge::EDGE_AGGREGATION || owner != owner->getLastParent() || target != target->getLastParent()) { child->setRoute(QtLineItemBase::ROUTE_HORIZONTAL); } + if (type == Edge::EDGE_AGGREGATION || type == Edge::EDGE_INHERITANCE) + { + child->setPivot(QtLineItemBase::PIVOT_MIDDLE); + } + bool showArrow = true; if (type == Edge::EDGE_AGGREGATION) { - child->setPivot(QtLineItemBase::PIVOT_MIDDLE); - showArrow = m_direction != TokenComponentAggregation::DIRECTION_NONE; } @@ -205,10 +218,7 @@ void QtGraphEdge::updateLine() } } - child->updateLine( - owner->getBoundingRect(), target->getBoundingRect(), - owner->getParentBoundingRect(), target->getParentBoundingRect(), - style, m_weight, showArrow); + child->updateLine(ownerRect, targetRect, ownerParentRect, targetParentRect, style, m_weight, showArrow); } this->setZValue(style.zValue); diff --git a/src/lib_gui/qt/view/graphElements/QtGraphEdge.h b/src/lib_gui/qt/view/graphElements/QtGraphEdge.h index 14a19129..7d7c98fc 100644 --- a/src/lib_gui/qt/view/graphElements/QtGraphEdge.h +++ b/src/lib_gui/qt/view/graphElements/QtGraphEdge.h @@ -41,7 +41,6 @@ public: bool getIsActive() const; void setIsActive(bool isActive); - void setFromAndToActive(bool fromActive, bool toActive); void setIsFocused(bool isFocused); @@ -81,9 +80,6 @@ private: QGraphicsItem* m_child; bool m_isActive; - bool m_fromActive; - bool m_toActive; - bool m_isFocused; size_t m_weight; diff --git a/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp b/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp index 021732dd..6addf1ff 100644 --- a/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp +++ b/src/lib_gui/qt/view/graphElements/QtGraphNode.cpp @@ -182,6 +182,24 @@ void QtGraphNode::setMultipleActive(bool multipleActive) m_multipleActive = multipleActive; } +bool QtGraphNode::hasActiveChild() const +{ + if (m_isActive) + { + return true; + } + + for (auto subNode : m_subNodes) + { + if (subNode->hasActiveChild()) + { + return true; + } + } + + return false; +} + std::wstring QtGraphNode::getName() const { return m_text->text().toStdWString(); diff --git a/src/lib_gui/qt/view/graphElements/QtGraphNode.h b/src/lib_gui/qt/view/graphElements/QtGraphNode.h index dab7b5d9..1c0e9499 100644 --- a/src/lib_gui/qt/view/graphElements/QtGraphNode.h +++ b/src/lib_gui/qt/view/graphElements/QtGraphNode.h @@ -63,6 +63,7 @@ public: bool getIsActive() const; void setIsActive(bool isActive); void setMultipleActive(bool multipleActive); + bool hasActiveChild() const; std::wstring getName() const; void setName(const std::wstring& name);