ui: typed edges

Edges in the graph view are now colored according to their type.
This commit is contained in:
Manuel Dobusch
2014-07-16 15:38:54 +02:00
parent 40ca86a172
commit 2c9c83d003
9 changed files with 94 additions and 49 deletions
+32 -23
View File
@@ -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<DummyNode>& 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<QtGraphEdge> newEdge = std::make_shared<QtGraphEdge>(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<QtGraphEdge> QtGraphView::createEdge(QGraphicsView* view, const
if(owner != NULL && target != NULL)
{
std::shared_ptr<QtGraphEdge> edge = std::make_shared<QtGraphEdge>(owner, target);
owner->addOutEdge(edge);
target->addInEdge(edge);
view->scene()->addItem(edge.get());
std::shared_ptr<QtGraphEdge> qtEdge = std::make_shared<QtGraphEdge>(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
{
+3
View File
@@ -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<DummyNode>&, const std::vector<DummyEdge>&> m_rebuildGraph;
QtThreadedFunctor<void> m_clear;
std::vector<Vec4i> m_edgeColors;
};
#endif // QT_GRAPH_VIEW_H
+21 -3
View File
@@ -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<GraphNode>& owner, const std::weak_ptr<GraphNode>& target)
: m_owner(owner)
, m_target(target)
, m_color(0, 0, 0, 0)
{
std::shared_ptr<GraphNode> o = owner.lock();
std::shared_ptr<GraphNode> 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<GraphNode>& 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<GraphNode> 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;
}
@@ -25,9 +25,14 @@ public:
virtual std::weak_ptr<GraphNode> getOwner();
virtual std::weak_ptr<GraphNode> getTarget();
virtual void setColor(const Vec4i& color);
virtual Vec4i getColor() const;
private:
std::weak_ptr<GraphNode> m_owner;
std::weak_ptr<GraphNode> m_target;
Vec4i m_color;
};
#endif // QT_GRAPH_EDGE_H
@@ -211,37 +211,31 @@ std::set<DummyEdge> GraphController::getNeighbourEdgesOfNode(const DummyNode& no
{
std::set<DummyEdge> result;
std::vector<std::pair<Id, Id>> rawEdges;
std::vector<std::pair<Id, Id>> callEdges = m_graphAccess->getCallEdgesOfNode(node.tokenId);
std::vector<std::pair<Id, Id>> usageEdges = m_graphAccess->getUsageEdgesOfNode(node.tokenId);
std::vector<std::pair<Id, Id>> typeOfEdges = m_graphAccess->getTypeOfEdgesOfNode(node.tokenId);
std::vector<std::pair<Id, Id>> returnTypeEdges = m_graphAccess->getReturnTypeOfEdgesOfNode(node.tokenId);
std::vector<std::pair<Id, Id>> 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++)
@@ -3,8 +3,11 @@
#include <memory>
#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<GraphNode> getOwner() = 0;
virtual std::weak_ptr<GraphNode> 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
+2 -2
View File
@@ -28,7 +28,7 @@ public:
Vector2<T> normalized() const;
template<class U>
void operator=(Vector2<U>& other);
void operator=(const Vector2<U>& other);
protected:
static const unsigned int m_xIndex = 0;
@@ -131,7 +131,7 @@ Vector2<T> Vector2<T>::normalized() const
template<class T>
template<class U>
void Vector2<T>::operator=(Vector2<U>& other)
void Vector2<T>::operator=(const Vector2<U>& other)
{
this->assign(other);
}
+9 -2
View File
@@ -30,7 +30,7 @@ public:
Vector4<T> normalized() const;
template<class U>
void operator=(Vector4<U>& other);
void operator=(const Vector4<U>& other);
protected:
static const unsigned int m_xIndex = 0;
@@ -145,9 +145,16 @@ Vector4<T> Vector4<T>::normalized() const
return VectorBase<T, 4>::normalized();
}
//template<class T>
//template<class U>
//void Vector4<T>::operator=(Vector4<U>& other)
//{
// this->assign(other);
//}
template<class T>
template<class U>
void Vector4<T>::operator=(Vector4<U>& other)
void Vector4<T>::operator=(const Vector4<U>& other)
{
this->assign(other);
}
+2 -2
View File
@@ -57,7 +57,7 @@ public:
T operator[](const unsigned int index);
template<class U>
void operator=(VectorBase<U, N>& other);
void operator=(const VectorBase<U, N>& other);
template<class U>
VectorBase<T, N> operator+(const VectorBase<U, N>& other) const;
@@ -325,7 +325,7 @@ T VectorBase<T, N>::operator[](const unsigned int index)
template<class T, unsigned int N>
template<class U>
void VectorBase<T, N>::operator=(VectorBase<U, N>& other)
void VectorBase<T, N>::operator=(const VectorBase<U, N>& other)
{
assign(other);
}