ui: Click edges in trail to show source location

This commit is contained in:
Eberhard Graether
2017-05-06 22:56:17 +02:00
parent f5979f5ead
commit e5cad53e85
13 changed files with 215 additions and 71 deletions
+59 -27
View File
@@ -200,6 +200,31 @@ void QtGraphView::scrollToValues(int xValue, int yValue)
m_scrollValues = Vec2i(xValue, yValue);
}
void QtGraphView::activateEdge(Id edgeId, bool centerOrigin)
{
m_onQtThread(
[=]()
{
clickedInEmptySpace();
for (std::shared_ptr<QtGraphEdge> edge : m_oldEdges)
{
if (edge->getData() && edge->getData()->getId() == edgeId)
{
edge->setIsActive(true);
if (centerOrigin)
{
centerNode(edge->getOwner().lock().get());
}
break;
}
}
}
);
}
void QtGraphView::updateScrollBars()
{
QGraphicsView* view = getView();
@@ -240,6 +265,8 @@ void QtGraphView::clickedInEmptySpace()
{
activeEdges.push_back(edge);
}
edge->setIsFocused(false);
}
if (m_graph && m_graph->getTrailMode() != Graph::TRAIL_NONE)
@@ -503,17 +530,7 @@ void QtGraphView::switchToNewGraphData()
{
if (m_centerActiveNode)
{
Vec2i pos = m_activeNodes.front()->getPosition();
Vec2i size = m_activeNodes.front()->getSize();
QRectF rect(pos.x, pos.y, size.x, size.y);
if (rect.height() > view->height() - 200)
{
rect.setHeight(view->height() - 200);
}
view->ensureVisibleAnimated(rect, 100, 100);
centerNode(m_activeNodes.front().get());
}
if (m_activeNodes.size() == 1)
@@ -603,17 +620,6 @@ void QtGraphView::doRebuildGraph(
m_edges.clear();
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;
@@ -621,7 +627,7 @@ void QtGraphView::doRebuildGraph(
{
if (!edge->data || !edge->data->isType(Edge::EDGE_AGGREGATION))
{
createEdge(view, edge.get(), &visibleEdgeIds, trailMode);
createEdge(view, edge.get(), &visibleEdgeIds, trailMode, offset);
}
}
for (const std::shared_ptr<DummyEdge> edge : edges)
@@ -784,7 +790,7 @@ std::shared_ptr<QtGraphNode> QtGraphView::createNodeRecursive(
}
std::shared_ptr<QtGraphEdge> QtGraphView::createEdge(
QGraphicsView* view, const DummyEdge* edge, std::set<Id>* visibleEdgeIds, Graph::TrailMode trailMode)
QGraphicsView* view, const DummyEdge* edge, std::set<Id>* visibleEdgeIds, Graph::TrailMode trailMode, QPointF pathOffset)
{
if (!edge->visible)
{
@@ -801,12 +807,21 @@ std::shared_ptr<QtGraphEdge> QtGraphView::createEdge(
if (trailMode != Graph::TRAIL_NONE)
{
for (const Vec4i& rect : edge->path)
std::vector<Vec4i> path = edge->path;
for (size_t i = 0; i < path.size(); i++)
{
path[i].x = path[i].x - pathOffset.x();
path[i].z = path[i].z - pathOffset.x();
path[i].y = path[i].y - pathOffset.y();
path[i].w = path[i].w - pathOffset.y();
}
for (const Vec4i& rect : path)
{
m_virtualNodeRects.push_back(QRectF(QPointF(rect.x(), rect.y()), QPointF(rect.z(), rect.w())));
}
qtEdge->setIsTrailEdge(edge->path, trailMode == Graph::TRAIL_HORIZONTAL);
qtEdge->setIsTrailEdge(path, trailMode == Graph::TRAIL_HORIZONTAL);
}
qtEdge->updateLine();
@@ -854,7 +869,7 @@ std::shared_ptr<QtGraphEdge> QtGraphView::createAggregationEdge(
return NULL;
}
return createEdge(view, edge, visibleEdgeIds, Graph::TRAIL_NONE);
return createEdge(view, edge, visibleEdgeIds, Graph::TRAIL_NONE, QPointF());
}
QRectF QtGraphView::itemsBoundingRect(const std::list<std::shared_ptr<QtGraphNode>>& items) const
@@ -879,6 +894,23 @@ QRectF QtGraphView::getSceneRect(const std::list<std::shared_ptr<QtGraphNode>>&
return sceneRect.adjusted(-75, -75, 75, 75).translated(m_sceneRectOffset);
}
void QtGraphView::centerNode(QtGraphNode* node)
{
QtGraphicsView* view = getView();
Vec2i pos = node->getPosition();
Vec2i size = node->getSize();
QRectF rect(pos.x, pos.y, size.x, size.y);
if (rect.height() > view->height() - 200)
{
rect.setHeight(view->height() - 200);
}
view->ensureVisibleAnimated(rect, 100, 100);
}
void QtGraphView::compareNodesRecursive(
std::list<std::shared_ptr<QtGraphNode>> newSubNodes,
std::list<std::shared_ptr<QtGraphNode>> oldSubNodes,
+6 -1
View File
@@ -55,6 +55,8 @@ public:
virtual void scrollToValues(int xValue, int yValue);
virtual void activateEdge(Id edgeId, bool centerOrigin);
private slots:
void updateScrollBars();
void finishedTransition();
@@ -96,13 +98,15 @@ private:
std::shared_ptr<QtGraphNode> createNodeRecursive(
QGraphicsView* view, std::shared_ptr<QtGraphNode> parentNode, const DummyNode* node, bool multipleActive);
std::shared_ptr<QtGraphEdge> createEdge(
QGraphicsView* view, const DummyEdge* edge, std::set<Id>* visibleEdgeIds, Graph::TrailMode trailMode);
QGraphicsView* view, const DummyEdge* edge, std::set<Id>* visibleEdgeIds, Graph::TrailMode trailMode, QPointF pathOffset);
std::shared_ptr<QtGraphEdge> createAggregationEdge(
QGraphicsView* view, const DummyEdge* edge, std::set<Id>* visibleEdgeIds);
QRectF itemsBoundingRect(const std::list<std::shared_ptr<QtGraphNode>>& items) const;
QRectF getSceneRect(const std::list<std::shared_ptr<QtGraphNode>>& items) const;
void centerNode(QtGraphNode* node);
void compareNodesRecursive(
std::list<std::shared_ptr<QtGraphNode>> newSubNodes,
std::list<std::shared_ptr<QtGraphNode>> oldSubNodes,
@@ -123,6 +127,7 @@ private:
QtThreadedFunctor<void> m_refreshFunctor;
QtThreadedFunctor<const std::vector<Id>&> m_focusInFunctor;
QtThreadedFunctor<const std::vector<Id>&> m_focusOutFunctor;
QtThreadedLambdaFunctor m_onQtThread;
std::shared_ptr<Graph> m_graph;
std::shared_ptr<Graph> m_oldGraph;
@@ -2,7 +2,6 @@
#include <QGraphicsSceneEvent>
#include <QGraphicsItemGroup>
#include <QTimer>
#include "component/view/GraphViewStyle.h"
#include "data/graph/Edge.h"
@@ -12,12 +11,15 @@
#include "qt/graphics/QtLineItemStraight.h"
#include "qt/view/graphElements/QtGraphNode.h"
#include "utility/messaging/type/MessageActivateEdge.h"
#include "utility/messaging/type/MessageActivateTrailEdge.h"
#include "utility/messaging/type/MessageFocusIn.h"
#include "utility/messaging/type/MessageFocusOut.h"
#include "utility/messaging/type/MessageGraphNodeBundleSplit.h"
#include "utility/utility.h"
#include "utility/utilityString.h"
QtGraphEdge* QtGraphEdge::s_focusedTrailEdge = nullptr;
QtGraphEdge::QtGraphEdge(
const std::weak_ptr<QtGraphNode>& owner,
const std::weak_ptr<QtGraphNode>& target,
@@ -40,8 +42,6 @@ QtGraphEdge::QtGraphEdge(
, m_isHorizontalTrail(false)
, m_mousePos(0.0f, 0.0f)
, m_mouseMoved(false)
, m_willFocusIn(false)
, m_ignoreFocusIn(false)
{
if (m_direction == TokenComponentAggregation::DIRECTION_BACKWARD)
{
@@ -50,6 +50,8 @@ QtGraphEdge::QtGraphEdge(
m_fromActive = m_owner.lock()->getIsActive();
m_toActive = m_target.lock()->getIsActive();
s_focusedTrailEdge = nullptr;
}
QtGraphEdge::~QtGraphEdge()
@@ -230,11 +232,25 @@ void QtGraphEdge::setIsActive(bool isActive)
}
}
void QtGraphEdge::setIsFocused(bool isFocused)
{
if (m_isFocused != isFocused)
{
m_isFocused = isFocused;
updateLine();
}
}
void QtGraphEdge::onClick()
{
if (isTrailEdge())
{
setIsActive(!getIsActive());
MessageActivateTrailEdge(
getData()->getId(),
getData()->getType(),
getData()->getFrom()->getNameHierarchy(),
getData()->getTo()->getNameHierarchy()
).dispatch();
return;
}
@@ -307,37 +323,18 @@ void QtGraphEdge::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
void QtGraphEdge::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
if (!m_ignoreFocusIn)
{
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;
}
MessageFocusOut(std::vector<Id>(1, getData()->getId())).dispatch();
}
void QtGraphEdge::doFocusIn()
{
if (!m_willFocusIn)
{
return;
}
if (!getData() || isTrailEdge())
{
if (isTrailEdge())
{
if (s_focusedTrailEdge && s_focusedTrailEdge != this)
{
s_focusedTrailEdge->focusOut();
}
s_focusedTrailEdge = this;
}
focusIn();
return;
}
@@ -345,9 +342,17 @@ void QtGraphEdge::doFocusIn()
MessageFocusIn(std::vector<Id>(1, getData()->getId())).dispatch();
}
void QtGraphEdge::doFocusOut()
void QtGraphEdge::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{
m_ignoreFocusIn = false;
s_focusedTrailEdge = nullptr;
if (!getData() || isTrailEdge())
{
focusOut();
return;
}
MessageFocusOut(std::vector<Id>(1, getData()->getId())).dispatch();
}
void QtGraphEdge::setDirection(TokenComponentAggregation::Direction direction)
@@ -41,6 +41,8 @@ public:
void setIsActive(bool isActive);
void setFromAndToActive(bool fromActive, bool toActive);
void setIsFocused(bool isFocused);
void onClick();
void focusIn();
@@ -59,11 +61,10 @@ protected:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
private slots:
void doFocusIn();
void doFocusOut();
private:
// used to unfocus recent edge, because hover leave event is not always received for trail edges (bezier)
static QtGraphEdge* s_focusedTrailEdge;
const Edge* m_data;
std::weak_ptr<QtGraphNode> m_owner;
@@ -87,9 +88,6 @@ private:
Vec2i m_mousePos;
bool m_mouseMoved;
bool m_willFocusIn;
bool m_ignoreFocusIn;
};
#endif // QT_GRAPH_EDGE_H