ui: improvements on trail layout
* increased spacing around graph * fixed graph lagging on message focus out * fixed level assignment fails * fixed dead ends in cyclic graph removal * improved node positioning by grouping to same average position * fixed graph image export not centering graph * fixed black dot at graph origin * show status updates while creating trails
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "utility/messaging/type/MessageActivateTrail.h"
|
||||
#include "utility/messaging/type/MessageDeactivateEdge.h"
|
||||
#include "utility/messaging/type/MessageScrollGraph.h"
|
||||
#include "utility/messaging/type/MessageStatus.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
#include "qt/graphics/QtGraphicsView.h"
|
||||
@@ -232,16 +233,23 @@ void QtGraphView::finishedTransition()
|
||||
|
||||
void QtGraphView::clickedInEmptySpace()
|
||||
{
|
||||
size_t activeEdgeCount = 0;
|
||||
std::vector<std::shared_ptr<QtGraphEdge>> activeEdges;
|
||||
for (std::shared_ptr<QtGraphEdge> edge : m_oldEdges)
|
||||
{
|
||||
if (edge->getIsActive())
|
||||
{
|
||||
activeEdgeCount++;
|
||||
activeEdges.push_back(edge);
|
||||
}
|
||||
}
|
||||
|
||||
if (activeEdgeCount == 1)
|
||||
if (m_graph && m_graph->getTrailMode() != Graph::TRAIL_NONE)
|
||||
{
|
||||
for (std::shared_ptr<QtGraphEdge> edge : activeEdges)
|
||||
{
|
||||
edge->setIsActive(false);
|
||||
}
|
||||
}
|
||||
else if (activeEdges.size() == 1)
|
||||
{
|
||||
MessageDeactivateEdge(false).dispatch();
|
||||
}
|
||||
@@ -519,6 +527,11 @@ void QtGraphView::switchToNewGraphData()
|
||||
view->update();
|
||||
|
||||
updateTrailButtons();
|
||||
|
||||
if (m_oldGraph && m_oldGraph->getTrailMode() != Graph::TRAIL_NONE)
|
||||
{
|
||||
MessageStatus("Finished graph display").dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
QtGraphicsView* QtGraphView::getView() const
|
||||
@@ -554,6 +567,8 @@ void QtGraphView::doRebuildGraph(
|
||||
|
||||
QGraphicsView* view = getView();
|
||||
|
||||
|
||||
// create nodes
|
||||
size_t activeNodeCount = 0;
|
||||
for (unsigned int i = 0; i < nodes.size(); i++)
|
||||
{
|
||||
@@ -574,31 +589,42 @@ void QtGraphView::doRebuildGraph(
|
||||
}
|
||||
}
|
||||
|
||||
Graph::TrailMode trailMode = m_graph ? m_graph->getTrailMode() : Graph::TRAIL_NONE;
|
||||
if (trailMode == Graph::TRAIL_NONE)
|
||||
{
|
||||
QPointF center = itemsBoundingRect(m_nodes).center();
|
||||
Vec2i o = GraphViewStyle::alignOnRaster(Vec2i(center.x(), center.y()));
|
||||
QPointF offset = QPointF(o.x, o.y);
|
||||
m_sceneRectOffset = offset - center;
|
||||
|
||||
for (const std::shared_ptr<QtGraphNode>& node : m_nodes)
|
||||
{
|
||||
node->setPos(node->pos() - offset);
|
||||
}
|
||||
// move graph to center
|
||||
QPointF center = itemsBoundingRect(m_nodes).center();
|
||||
Vec2i o = GraphViewStyle::alignOnRaster(Vec2i(center.x(), center.y()));
|
||||
QPointF offset = QPointF(o.x, o.y);
|
||||
m_sceneRectOffset = offset - center;
|
||||
|
||||
for (const std::shared_ptr<QtGraphNode>& node : m_nodes)
|
||||
{
|
||||
node->setPos(node->pos() - offset);
|
||||
}
|
||||
|
||||
m_edges.clear();
|
||||
|
||||
std::set<Id> visibleEdgeIds;
|
||||
for (std::shared_ptr<DummyEdge> edge : edges)
|
||||
{
|
||||
for (size_t i = 0; i < edge->path.size(); i++)
|
||||
{
|
||||
edge->path[i].x = edge->path[i].x - offset.x();
|
||||
edge->path[i].z = edge->path[i].z - offset.x();
|
||||
edge->path[i].y = edge->path[i].y - offset.y();
|
||||
edge->path[i].w = edge->path[i].w - offset.y();
|
||||
}
|
||||
}
|
||||
|
||||
// create edges
|
||||
Graph::TrailMode trailMode = m_graph ? m_graph->getTrailMode() : Graph::TRAIL_NONE;
|
||||
std::set<Id> visibleEdgeIds;
|
||||
for (const std::shared_ptr<DummyEdge> edge : edges)
|
||||
{
|
||||
if (!edge->data || !edge->data->isType(Edge::EDGE_AGGREGATION))
|
||||
{
|
||||
createEdge(view, edge.get(), &visibleEdgeIds, trailMode);
|
||||
}
|
||||
}
|
||||
for (std::shared_ptr<DummyEdge> edge : edges)
|
||||
for (const std::shared_ptr<DummyEdge> edge : edges)
|
||||
{
|
||||
if (edge->data && edge->data->isType(Edge::EDGE_AGGREGATION))
|
||||
{
|
||||
@@ -850,7 +876,7 @@ QRectF QtGraphView::getSceneRect(const std::list<std::shared_ptr<QtGraphNode>>&
|
||||
sceneRect |= rect;
|
||||
}
|
||||
|
||||
return sceneRect.adjusted(-25, -25, 25, 25).translated(m_sceneRectOffset);
|
||||
return sceneRect.adjusted(-75, -75, 75, 75).translated(m_sceneRectOffset);
|
||||
}
|
||||
|
||||
void QtGraphView::compareNodesRecursive(
|
||||
@@ -1081,11 +1107,16 @@ void QtGraphView::doFocusOut(const std::vector<Id>& tokenIds)
|
||||
if (node && node->isDataNode())
|
||||
{
|
||||
node->focusOut();
|
||||
continue;
|
||||
}
|
||||
|
||||
for (std::shared_ptr<QtGraphEdge> edge : m_oldEdges)
|
||||
{
|
||||
if (edge->getData() && edge->getData()->getId() == tokenId)
|
||||
{
|
||||
edge->focusOut();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (std::shared_ptr<QtGraphEdge> edge : m_oldEdges)
|
||||
{
|
||||
edge->focusOut();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "qt/view/graphElements/QtGraphEdge.h"
|
||||
|
||||
#include <QGraphicsSceneEvent>
|
||||
#include <QGraphicsItemGroup>
|
||||
#include <QTimer>
|
||||
|
||||
#include "component/view/GraphViewStyle.h"
|
||||
@@ -39,7 +40,8 @@ QtGraphEdge::QtGraphEdge(
|
||||
, m_isHorizontalTrail(false)
|
||||
, m_mousePos(0.0f, 0.0f)
|
||||
, m_mouseMoved(false)
|
||||
, m_willDispatchMessageFocusIn(false)
|
||||
, m_willFocusIn(false)
|
||||
, m_ignoreFocusIn(false)
|
||||
{
|
||||
if (m_direction == TokenComponentAggregation::DIRECTION_BACKWARD)
|
||||
{
|
||||
@@ -104,17 +106,10 @@ void QtGraphEdge::updateLine()
|
||||
|
||||
if (m_isTrailEdge)
|
||||
{
|
||||
if (!m_child)
|
||||
for (QGraphicsItem* item : childItems())
|
||||
{
|
||||
m_child = new QGraphicsLineItem(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (QGraphicsItem* item : m_child->childItems())
|
||||
{
|
||||
item->hide();
|
||||
item->setParentItem(nullptr);
|
||||
}
|
||||
item->hide();
|
||||
item->setParentItem(nullptr);
|
||||
}
|
||||
|
||||
style.originOffset.y() = 0;
|
||||
@@ -128,13 +123,13 @@ void QtGraphEdge::updateLine()
|
||||
|
||||
for (const Vec4i& rect : m_path)
|
||||
{
|
||||
QtLineItemBezier* bezier = new QtLineItemBezier(m_child);
|
||||
QtLineItemBezier* bezier = new QtLineItemBezier(this);
|
||||
bezier->updateLine(ownerRect, rect, ownerParentRect, rect, style, m_weight, false);
|
||||
bezier->setRoute(route);
|
||||
bezier->setPivot(QtLineItemBase::PIVOT_MIDDLE);
|
||||
bezier->setToolTip(toolTip);
|
||||
|
||||
QtLineItemStraight* line = new QtLineItemStraight(m_child);
|
||||
QtLineItemStraight* line = new QtLineItemStraight(this);
|
||||
line->setToolTip(toolTip);
|
||||
if (route == QtLineItemBase::ROUTE_HORIZONTAL)
|
||||
{
|
||||
@@ -151,7 +146,7 @@ void QtGraphEdge::updateLine()
|
||||
|
||||
bool showArrow = m_direction != TokenComponentAggregation::DIRECTION_NONE;
|
||||
|
||||
QtLineItemBezier* bezier = new QtLineItemBezier(m_child);
|
||||
QtLineItemBezier* bezier = new QtLineItemBezier(this);
|
||||
bezier->updateLine(
|
||||
ownerRect, target->getBoundingRect(), ownerParentRect, target->getParentBoundingRect(),
|
||||
style, m_weight, showArrow);
|
||||
@@ -312,43 +307,47 @@ void QtGraphEdge::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
|
||||
|
||||
void QtGraphEdge::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
|
||||
{
|
||||
if (!getData())
|
||||
if (!m_ignoreFocusIn)
|
||||
{
|
||||
focusIn();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_willDispatchMessageFocusIn)
|
||||
{
|
||||
QTimer::singleShot(50, this, SLOT(dispatchMessageFocusIn()));
|
||||
m_willDispatchMessageFocusIn = true;
|
||||
QTimer::singleShot(50, this, SLOT(doFocusIn()));
|
||||
m_ignoreFocusIn = true;
|
||||
m_willFocusIn = true;
|
||||
}
|
||||
}
|
||||
|
||||
void QtGraphEdge::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
|
||||
{
|
||||
m_willFocusIn = false;
|
||||
QTimer::singleShot(100, this, SLOT(doFocusOut()));
|
||||
|
||||
if (!getData())
|
||||
{
|
||||
focusOut();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_willDispatchMessageFocusIn)
|
||||
{
|
||||
m_willDispatchMessageFocusIn = false;
|
||||
return;
|
||||
}
|
||||
|
||||
MessageFocusOut(std::vector<Id>(1, getData()->getId())).dispatch();
|
||||
}
|
||||
|
||||
void QtGraphEdge::dispatchMessageFocusIn()
|
||||
void QtGraphEdge::doFocusIn()
|
||||
{
|
||||
if (m_willDispatchMessageFocusIn)
|
||||
if (!m_willFocusIn)
|
||||
{
|
||||
m_willDispatchMessageFocusIn = false;
|
||||
MessageFocusIn(std::vector<Id>(1, getData()->getId())).dispatch();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!getData() || isTrailEdge())
|
||||
{
|
||||
focusIn();
|
||||
return;
|
||||
}
|
||||
|
||||
MessageFocusIn(std::vector<Id>(1, getData()->getId())).dispatch();
|
||||
}
|
||||
|
||||
void QtGraphEdge::doFocusOut()
|
||||
{
|
||||
m_ignoreFocusIn = false;
|
||||
}
|
||||
|
||||
void QtGraphEdge::setDirection(TokenComponentAggregation::Direction direction)
|
||||
|
||||
@@ -60,7 +60,8 @@ protected:
|
||||
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
|
||||
|
||||
private slots:
|
||||
void dispatchMessageFocusIn();
|
||||
void doFocusIn();
|
||||
void doFocusOut();
|
||||
|
||||
private:
|
||||
const Edge* m_data;
|
||||
@@ -68,7 +69,7 @@ private:
|
||||
std::weak_ptr<QtGraphNode> m_owner;
|
||||
std::weak_ptr<QtGraphNode> m_target;
|
||||
|
||||
QGraphicsLineItem* m_child;
|
||||
QGraphicsItem* m_child;
|
||||
|
||||
bool m_isActive;
|
||||
bool m_fromActive;
|
||||
@@ -87,7 +88,8 @@ private:
|
||||
Vec2i m_mousePos;
|
||||
bool m_mouseMoved;
|
||||
|
||||
bool m_willDispatchMessageFocusIn;
|
||||
bool m_willFocusIn;
|
||||
bool m_ignoreFocusIn;
|
||||
};
|
||||
|
||||
#endif // QT_GRAPH_EDGE_H
|
||||
|
||||
Reference in New Issue
Block a user