From 2c9c83d003d9df268b4ae8183ad42aa925872073 Mon Sep 17 00:00:00 2001 From: Manuel Dobusch Date: Wed, 16 Jul 2014 15:38:54 +0200 Subject: [PATCH] ui: typed edges Edges in the graph view are now colored according to their type. --- src/app/qt/view/QtGraphView.cpp | 55 +++++++++++-------- src/app/qt/view/QtGraphView.h | 3 + src/app/qt/view/graphElements/QtGraphEdge.cpp | 24 +++++++- src/app/qt/view/graphElements/QtGraphEdge.h | 5 ++ .../component/controller/GraphController.cpp | 26 ++++----- .../component/view/graphElements/GraphEdge.h | 11 +++- src/lib/utility/math/Vector2.h | 4 +- src/lib/utility/math/Vector4.h | 11 +++- src/lib/utility/math/VectorBase.h | 4 +- 9 files changed, 94 insertions(+), 49 deletions(-) diff --git a/src/app/qt/view/QtGraphView.cpp b/src/app/qt/view/QtGraphView.cpp index 0ea56f71..48e014eb 100644 --- a/src/app/qt/view/QtGraphView.cpp +++ b/src/app/qt/view/QtGraphView.cpp @@ -19,6 +19,11 @@ QtGraphView::QtGraphView(ViewLayout* viewLayout) , m_rebuildGraph(std::bind(&QtGraphView::doRebuildGraph, this, std::placeholders::_1, std::placeholders::_2)) , m_clear(std::bind(&QtGraphView::doClear, this)) { + m_edgeColors.push_back(Vec4i(100, 100, 100, 255)); // call + m_edgeColors.push_back(Vec4i(66, 230, 103, 255)); // usage + m_edgeColors.push_back(Vec4i(73, 155, 222, 255)); // type + m_edgeColors.push_back(Vec4i(231, 65, 65, 255)); // return + m_edgeColors.push_back(Vec4i(227, 180, 68, 255)); // parameter } QtGraphView::~QtGraphView() @@ -99,24 +104,6 @@ void QtGraphView::doRebuildGraph(const std::vector& nodes, const std: m_edges.push_back(edge); } } - - // create edges - /*for(unsigned int i = 0; i < edges.size(); i++) - { - if (weakNodes.find(edges[i].ownerId) != weakNodes.end() && weakNodes.find(edges[i].targetId) != weakNodes.end()) - { - if (weakNodes[edges[i].ownerId].expired() == false && weakNodes[edges[i].targetId].expired() == false) - { - std::shared_ptr newEdge = std::make_shared(weakNodes[edges[i].ownerId], weakNodes[edges[i].targetId]); - view->scene()->addItem(newEdge.get()); - if(weakNodes[edges[i].ownerId].lock()->addOutEdge(newEdge)) - { - weakNodes[edges[i].targetId].lock()->addInEdge(newEdge); - m_edges.push_back(newEdge); - } - } - } - }*/ } else { @@ -253,12 +240,34 @@ std::shared_ptr QtGraphView::createEdge(QGraphicsView* view, const if(owner != NULL && target != NULL) { - std::shared_ptr edge = std::make_shared(owner, target); - owner->addOutEdge(edge); - target->addInEdge(edge); - view->scene()->addItem(edge.get()); + std::shared_ptr qtEdge = std::make_shared(owner, target); - return edge; + switch(edge.edgeType) + { + case Edge::EdgeType::EDGE_CALL: + qtEdge->setColor(m_edgeColors[0]); + break; + case Edge::EdgeType::EDGE_USAGE: + qtEdge->setColor(m_edgeColors[1]); + break; + case Edge::EdgeType::EDGE_TYPE_OF: + qtEdge->setColor(m_edgeColors[2]); + break; + case Edge::EdgeType::EDGE_RETURN_TYPE_OF: + qtEdge->setColor(m_edgeColors[3]); + break; + case Edge::EdgeType::EDGE_PARAMETER_TYPE_OF: + qtEdge->setColor(m_edgeColors[4]); + break; + default: + qtEdge->setColor(Vec4i(0, 0, 0, 255)); + } + + owner->addOutEdge(qtEdge); + target->addInEdge(qtEdge); + view->scene()->addItem(qtEdge.get()); + + return qtEdge; } else { diff --git a/src/app/qt/view/QtGraphView.h b/src/app/qt/view/QtGraphView.h index d07d2319..5d420b72 100644 --- a/src/app/qt/view/QtGraphView.h +++ b/src/app/qt/view/QtGraphView.h @@ -3,6 +3,7 @@ #include "qt/utility/QtThreadedFunctor.h" +#include "utility/math/Vector4.h" #include "utility/types.h" #include "component/view/GraphView.h" @@ -43,6 +44,8 @@ private: QtThreadedFunctor&, const std::vector&> m_rebuildGraph; QtThreadedFunctor m_clear; + + std::vector m_edgeColors; }; #endif // QT_GRAPH_VIEW_H diff --git a/src/app/qt/view/graphElements/QtGraphEdge.cpp b/src/app/qt/view/graphElements/QtGraphEdge.cpp index 31193700..2b04505c 100644 --- a/src/app/qt/view/graphElements/QtGraphEdge.cpp +++ b/src/app/qt/view/graphElements/QtGraphEdge.cpp @@ -1,5 +1,6 @@ #include "qt/view/graphElements/QtGraphEdge.h" +#include "qgraphicsscene.h" #include "qpen.h" #include "component/view/graphElements/GraphNode.h" @@ -7,13 +8,15 @@ QtGraphEdge::QtGraphEdge(const std::weak_ptr& owner, const std::weak_ptr& target) : m_owner(owner) , m_target(target) + , m_color(0, 0, 0, 0) { std::shared_ptr o = owner.lock(); std::shared_ptr t = target.lock(); if (o != NULL && t != NULL) { - this->setLine(o->getPosition().x, o->getPosition().y,t->getPosition().x, t->getPosition().y); + Vec2i ownerPos = o->getPosition(); + this->setLine(ownerPos.x, ownerPos.y,t->getPosition().x, t->getPosition().y); } else { @@ -21,7 +24,7 @@ QtGraphEdge::QtGraphEdge(const std::weak_ptr& owner, const std::weak_ } QPen blackPen(Qt::black); - blackPen.setWidth(3); + blackPen.setWidth(2); this->setPen(blackPen); } @@ -36,7 +39,8 @@ void QtGraphEdge::ownerMoved() if (node != NULL) { - this->setLine(node->getPosition().x, node->getPosition().y, this->line().x2(), this->line().y2()); + Vec2i pos = node->getPosition(); + this->setLine(pos.x, pos.y, this->line().x2(), this->line().y2()); } else { @@ -81,3 +85,17 @@ std::weak_ptr QtGraphEdge::getTarget() { return m_target; } + +void QtGraphEdge::setColor(const Vec4i& color) +{ + m_color = color; + + QPen pen(QColor(color.x, color.y, color.z, color.w)); + pen.setWidth(2); + this->setPen(pen); +} + +Vec4i QtGraphEdge::getColor() const +{ + return m_color; +} diff --git a/src/app/qt/view/graphElements/QtGraphEdge.h b/src/app/qt/view/graphElements/QtGraphEdge.h index fe130da3..b838a171 100644 --- a/src/app/qt/view/graphElements/QtGraphEdge.h +++ b/src/app/qt/view/graphElements/QtGraphEdge.h @@ -25,9 +25,14 @@ public: virtual std::weak_ptr getOwner(); virtual std::weak_ptr getTarget(); + virtual void setColor(const Vec4i& color); + virtual Vec4i getColor() const; + private: std::weak_ptr m_owner; std::weak_ptr m_target; + + Vec4i m_color; }; #endif // QT_GRAPH_EDGE_H diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index fb80678d..a79211f7 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -211,37 +211,31 @@ std::set GraphController::getNeighbourEdgesOfNode(const DummyNode& no { std::set result; - std::vector> rawEdges; std::vector> callEdges = m_graphAccess->getCallEdgesOfNode(node.tokenId); std::vector> usageEdges = m_graphAccess->getUsageEdgesOfNode(node.tokenId); std::vector> typeOfEdges = m_graphAccess->getTypeOfEdgesOfNode(node.tokenId); std::vector> returnTypeEdges = m_graphAccess->getReturnTypeOfEdgesOfNode(node.tokenId); std::vector> parameterEdges = m_graphAccess->getParameterOfEdgesOfNode(node.tokenId); - if(callEdges.size() > 0) + for(unsigned int i = 0; i < callEdges.size(); i++) { - rawEdges.insert(rawEdges.end(), callEdges.begin(), callEdges.end()); + result.insert(DummyEdge(callEdges[i].first, callEdges[i].second, Edge::EdgeType::EDGE_CALL)); } - if(usageEdges.size() > 0) + for(unsigned int i = 0; i < usageEdges.size(); i++) { - rawEdges.insert(rawEdges.end(), usageEdges.begin(), usageEdges.end()); + result.insert(DummyEdge(usageEdges[i].first, usageEdges[i].second, Edge::EdgeType::EDGE_USAGE)); } - if(typeOfEdges.size() > 0) + for(unsigned int i = 0; i < typeOfEdges.size(); i++) { - rawEdges.insert(rawEdges.end(), typeOfEdges.begin(), typeOfEdges.end()); + result.insert(DummyEdge(typeOfEdges[i].first, typeOfEdges[i].second, Edge::EdgeType::EDGE_TYPE_OF)); } - if(returnTypeEdges.size() > 0) + for(unsigned int i = 0; i < returnTypeEdges.size(); i++) { - rawEdges.insert(rawEdges.end(), returnTypeEdges.begin(), returnTypeEdges.end()); + result.insert(DummyEdge(returnTypeEdges[i].first, returnTypeEdges[i].second, Edge::EdgeType::EDGE_RETURN_TYPE_OF)); } - if(parameterEdges.size() > 0) + for(unsigned int i = 0; i < parameterEdges.size(); i++) { - rawEdges.insert(rawEdges.end(), parameterEdges.begin(), parameterEdges.end()); - } - - for(unsigned int i = 0; i < rawEdges.size(); i++) - { - result.insert(DummyEdge(rawEdges[i].first, rawEdges[i].second)); + result.insert(DummyEdge(parameterEdges[i].first, parameterEdges[i].second, Edge::EdgeType::EDGE_PARAMETER_TYPE_OF)); } for(unsigned int i = 0; i < node.subNodes.size(); i++) diff --git a/src/lib/component/view/graphElements/GraphEdge.h b/src/lib/component/view/graphElements/GraphEdge.h index 7598bbc4..9cbd54cf 100644 --- a/src/lib/component/view/graphElements/GraphEdge.h +++ b/src/lib/component/view/graphElements/GraphEdge.h @@ -3,8 +3,11 @@ #include +#include "utility/math/Vector4.h" #include "utility/types.h" +#include "data/graph/Edge.h" + class GraphNode; class GraphEdge @@ -20,15 +23,19 @@ public: virtual std::weak_ptr getOwner() = 0; virtual std::weak_ptr getTarget() = 0; + + virtual void setColor(const Vec4i& color) = 0; + virtual Vec4i getColor() const = 0; }; // temporary data structure for (visual) graph creation process struct DummyEdge { public: - DummyEdge(const Id o, const Id t) + DummyEdge(const Id o, const Id t, Edge::EdgeType type) : ownerId(o) , targetId(t) + , edgeType(type) { } @@ -66,6 +73,8 @@ public: Id ownerId; Id targetId; + + Edge::EdgeType edgeType; }; #endif // GRAPH_EDGE_H \ No newline at end of file diff --git a/src/lib/utility/math/Vector2.h b/src/lib/utility/math/Vector2.h index 6d504564..19e9adc1 100644 --- a/src/lib/utility/math/Vector2.h +++ b/src/lib/utility/math/Vector2.h @@ -28,7 +28,7 @@ public: Vector2 normalized() const; template - void operator=(Vector2& other); + void operator=(const Vector2& other); protected: static const unsigned int m_xIndex = 0; @@ -131,7 +131,7 @@ Vector2 Vector2::normalized() const template template -void Vector2::operator=(Vector2& other) +void Vector2::operator=(const Vector2& other) { this->assign(other); } diff --git a/src/lib/utility/math/Vector4.h b/src/lib/utility/math/Vector4.h index 18f158ff..f3156915 100644 --- a/src/lib/utility/math/Vector4.h +++ b/src/lib/utility/math/Vector4.h @@ -30,7 +30,7 @@ public: Vector4 normalized() const; template - void operator=(Vector4& other); + void operator=(const Vector4& other); protected: static const unsigned int m_xIndex = 0; @@ -145,9 +145,16 @@ Vector4 Vector4::normalized() const return VectorBase::normalized(); } +//template +//template +//void Vector4::operator=(Vector4& other) +//{ +// this->assign(other); +//} + template template -void Vector4::operator=(Vector4& other) +void Vector4::operator=(const Vector4& other) { this->assign(other); } diff --git a/src/lib/utility/math/VectorBase.h b/src/lib/utility/math/VectorBase.h index ec71ac30..71927ec4 100644 --- a/src/lib/utility/math/VectorBase.h +++ b/src/lib/utility/math/VectorBase.h @@ -57,7 +57,7 @@ public: T operator[](const unsigned int index); template - void operator=(VectorBase& other); + void operator=(const VectorBase& other); template VectorBase operator+(const VectorBase& other) const; @@ -325,7 +325,7 @@ T VectorBase::operator[](const unsigned int index) template template -void VectorBase::operator=(VectorBase& other) +void VectorBase::operator=(const VectorBase& other) { assign(other); }