ui: typed edges
Edges in the graph view are now colored according to their type.
This commit is contained in:
@@ -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,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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user