logic: refactored GraphAccess and GraphController to use single call that returns Graph

This change refactors the GraphController to use the GraphAccess only with a single call that returns a Graph. The Graph
contains all information for visually representing the active Token with all parent and child nodes and edges. This
reduces coupling of the data and logic tiers.
This commit is contained in:
Eberhard Graether
2014-09-10 01:07:26 +02:00
parent 9a546b4312
commit 760e5ffafd
18 changed files with 164 additions and 544 deletions
+1
View File
@@ -6,6 +6,7 @@
#include <QGraphicsView>
#include "qt/utility/utilityQt.h"
#include "qt/view/QtViewWidgetWrapper.h"
#include "qt/view/graphElements/QtGraphEdge.h"
#include "qt/view/graphElements/QtGraphNode.h"
+2 -1
View File
@@ -1,11 +1,12 @@
#ifndef QT_GRAPH_VIEW_H
#define QT_GRAPH_VIEW_H
#include "component/view/GraphView.h"
#include "qt/utility/QtThreadedFunctor.h"
#include "utility/math/Vector4.h"
#include "utility/types.h"
#include "component/view/GraphView.h"
struct DummyEdge;
struct DummyNode;
class QGraphicsView;
@@ -28,6 +28,7 @@ QtGraphEdge::QtGraphEdge(const std::weak_ptr<GraphNode>& owner, const std::weak_
blackPen.setWidth(2);
this->setPen(blackPen);
this->setZValue(1); // Used to draw edges always on top of nodes.
}
QtGraphEdge::~QtGraphEdge()
+2 -1
View File
@@ -5,9 +5,10 @@
#include <QGraphicsItem>
#include "component/view/graphElements/GraphEdge.h"
#include "utility/messaging/type/MessageActivateToken.h"
#include "component/view/graphElements/GraphEdge.h"
class GraphNode;
class QtGraphEdge
@@ -73,7 +73,7 @@ bool QtGraphNode::addOutEdge(const std::shared_ptr<GraphEdge>& edge)
bool QtGraphNode::addInEdge(const std::weak_ptr<GraphEdge>& edge)
{
for (std::list<std::weak_ptr<GraphEdge> >::iterator it = m_inEdges.begin(); it != m_inEdges.end(); it++)
for (std::list<std::weak_ptr<GraphEdge>>::iterator it = m_inEdges.begin(); it != m_inEdges.end(); it++)
{
std::shared_ptr<GraphEdge> existingEdge = it->lock();
if (existingEdge != NULL)
@@ -92,7 +92,7 @@ bool QtGraphNode::addInEdge(const std::weak_ptr<GraphEdge>& edge)
void QtGraphNode::removeOutEdge(GraphEdge* edge)
{
std::list<std::shared_ptr<GraphEdge> >::iterator it = m_outEdges.begin();
std::list<std::shared_ptr<GraphEdge>>::iterator it = m_outEdges.begin();
while (it != m_outEdges.end())
{
if ((*it).get() == edge)
@@ -105,7 +105,7 @@ void QtGraphNode::removeOutEdge(GraphEdge* edge)
}
}
std::list<std::shared_ptr<GraphNode> > QtGraphNode::getSubNodes() const
std::list<std::shared_ptr<GraphNode>> QtGraphNode::getSubNodes() const
{
return m_subNodes;
}
@@ -128,12 +128,12 @@ void QtGraphNode::notifyParentMoved()
void QtGraphNode::notifyEdgesAfterMove()
{
for (std::list<std::shared_ptr<GraphEdge> >::iterator it = m_outEdges.begin(); it != m_outEdges.end(); it++)
for (std::list<std::shared_ptr<GraphEdge>>::iterator it = m_outEdges.begin(); it != m_outEdges.end(); it++)
{
(*it)->ownerMoved();
}
std::list<std::weak_ptr<GraphEdge> >::iterator it2 = m_inEdges.begin();
std::list<std::weak_ptr<GraphEdge>>::iterator it2 = m_inEdges.begin();
while (it2 != m_inEdges.end())
{
std::shared_ptr<GraphEdge> edge = it2->lock();
@@ -148,7 +148,7 @@ void QtGraphNode::notifyEdgesAfterMove()
}
}
for (std::list<std::shared_ptr<GraphNode> >::iterator it3 = m_subNodes.begin(); it3 != m_subNodes.end(); it3++)
for (std::list<std::shared_ptr<GraphNode>>::iterator it3 = m_subNodes.begin(); it3 != m_subNodes.end(); it3++)
{
(*it3)->notifyParentMoved();
}
+7 -6
View File
@@ -3,9 +3,10 @@
#include <QGraphicsItem>
#include "component/view/graphElements/GraphNode.h"
#include "utility/messaging/type/MessageActivateToken.h"
#include "utility/math/Vector2.h"
#include "utility/messaging/type/MessageActivateToken.h"
#include "component/view/graphElements/GraphNode.h"
class QtGraphEdge;
@@ -26,7 +27,7 @@ public:
virtual void removeOutEdge(GraphEdge* edge);
virtual std::list<std::shared_ptr<GraphNode> > getSubNodes() const;
virtual std::list<std::shared_ptr<GraphNode>> getSubNodes() const;
virtual void addSubNode(const std::shared_ptr<GraphNode>& node);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event);
@@ -36,13 +37,13 @@ public:
protected:
void notifyEdgesAfterMove();
std::list<std::shared_ptr<GraphEdge> > m_outEdges;
std::list<std::weak_ptr<GraphEdge> > m_inEdges;
std::list<std::shared_ptr<GraphEdge>> m_outEdges;
std::list<std::weak_ptr<GraphEdge>> m_inEdges;
private:
QGraphicsTextItem* m_text;
std::list<std::shared_ptr<GraphNode> > m_subNodes;
std::list<std::shared_ptr<GraphNode>> m_subNodes;
};
#endif // QT_GRAPH_NODE_H