src: refactoring of GraphNode and GraphEdge classes

* common base class QtGraphNode
* derived class QtGraphNodeData for nodes representing the data model
* removed GraphNode and GraphEdge interface classes
* moved and renamed files for DummyNode and DummyEdge
* refactored includes throughout Graph UI related files
This commit is contained in:
Eberhard Graether
2015-05-22 13:54:50 +02:00
parent 1e8d8cece0
commit bd5de1d271
25 changed files with 328 additions and 373 deletions
+2
View File
@@ -59,6 +59,8 @@ add_files(
qt/view/graphElements/QtGraphNode.h
qt/view/graphElements/QtGraphNodeAccess.cpp
qt/view/graphElements/QtGraphNodeAccess.h
qt/view/graphElements/QtGraphNodeData.cpp
qt/view/graphElements/QtGraphNodeData.h
qt/view/graphElements/QtGraphNodeExpandToggle.cpp
qt/view/graphElements/QtGraphNodeExpandToggle.h
+6 -4
View File
@@ -1,4 +1,4 @@
#include "QtGraphView.h"
#include "qt/view/QtGraphView.h"
#include <QBoxLayout>
#include <QFrame>
@@ -8,6 +8,9 @@
#include <QParallelAnimationGroup>
#include <QSequentialAnimationGroup>
#include "component/controller/helper/DummyEdge.h"
#include "component/controller/helper/DummyNode.h"
#include "qt/utility/QtGraphPostprocessor.h"
#include "qt/utility/utilityQt.h"
@@ -15,7 +18,7 @@
#include "qt/view/graphElements/nodeComponents/QtGraphNodeComponentClickable.h"
#include "qt/view/graphElements/nodeComponents/QtGraphNodeComponentMoveable.h"
#include "qt/view/graphElements/QtGraphEdge.h"
#include "qt/view/graphElements/QtGraphNode.h"
#include "qt/view/graphElements/QtGraphNodeData.h"
#include "qt/view/graphElements/QtGraphNodeAccess.h"
#include "qt/view/graphElements/QtGraphNodeExpandToggle.h"
@@ -27,7 +30,6 @@ QtGraphView::QtGraphView(ViewLayout* viewLayout)
, m_resizeFunctor(std::bind(&QtGraphView::doResize, this))
, m_focusInFunctor(std::bind(&QtGraphView::doFocusIn, this, std::placeholders::_1))
, m_focusOutFunctor(std::bind(&QtGraphView::doFocusOut, this, std::placeholders::_1))
{
}
@@ -245,7 +247,7 @@ std::shared_ptr<QtGraphNode> QtGraphView::createNodeRecursive(
std::shared_ptr<QtGraphNode> newNode;
if (node.isGraphNode())
{
newNode = std::make_shared<QtGraphNode>(node.data, node.childVisible);
newNode = std::make_shared<QtGraphNodeData>(node.data, node.childVisible);
}
else if (node.isAccessNode())
{
+2 -3
View File
@@ -3,11 +3,10 @@
#include <QPointF>
#include "qt/utility/QtThreadedFunctor.h"
#include "utility/math/MatrixDynamicBase.h"
#include "utility/math/Vector4.h"
#include "utility/types.h"
#include "qt/utility/QtThreadedFunctor.h"
#include "component/view/GraphView.h"
struct DummyEdge;
+25 -21
View File
@@ -1,21 +1,20 @@
#include "qt/view/graphElements/QtGraphEdge.h"
#include <QGraphicsScene>
#include <QGraphicsSceneEvent>
#include <QPen>
#include "utility/messaging/type/MessageActivateTokens.h"
#include "utility/messaging/type/MessageFocusIn.h"
#include "utility/messaging/type/MessageFocusOut.h"
#include "component/view/graphElements/GraphNode.h"
#include "component/view/GraphViewStyle.h"
#include "data/graph/Edge.h"
#include "data/graph/token_component/TokenComponentAggregation.h"
#include "qt/graphics/QtAngledLineItem.h"
#include "qt/graphics/QtStraightLineItem.h"
#include "qt/view/graphElements/QtGraphNode.h"
QtGraphEdge::QtGraphEdge(const std::weak_ptr<GraphNode>& owner, const std::weak_ptr<GraphNode>& target, const Edge* data)
: GraphEdge(data)
QtGraphEdge::QtGraphEdge(const std::weak_ptr<QtGraphNode>& owner, const std::weak_ptr<QtGraphNode>& target, const Edge* data)
: m_data(data)
, m_owner(owner)
, m_target(target)
, m_child(nullptr)
@@ -30,20 +29,25 @@ QtGraphEdge::~QtGraphEdge()
{
}
std::weak_ptr<GraphNode> QtGraphEdge::getOwner()
const Edge* QtGraphEdge::getData() const
{
return m_data;
}
std::weak_ptr<QtGraphNode> QtGraphEdge::getOwner()
{
return m_owner;
}
std::weak_ptr<GraphNode> QtGraphEdge::getTarget()
std::weak_ptr<QtGraphNode> QtGraphEdge::getTarget()
{
return m_target;
}
void QtGraphEdge::updateLine()
{
std::shared_ptr<GraphNode> owner = m_owner.lock();
std::shared_ptr<GraphNode> target = m_target.lock();
std::shared_ptr<QtGraphNode> owner = m_owner.lock();
std::shared_ptr<QtGraphNode> target = m_target.lock();
if (owner == NULL || target == NULL)
{
@@ -114,6 +118,18 @@ void QtGraphEdge::onClick()
}
}
void QtGraphEdge::focusIn()
{
bool isActive = m_isActive;
this->setIsActive(true);
m_isActive = isActive;
}
void QtGraphEdge::focusOut()
{
this->setIsActive(m_isActive);
}
void QtGraphEdge::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
m_mousePos = Vec2i(event->scenePos().x(), event->scenePos().y());
@@ -147,15 +163,3 @@ void QtGraphEdge::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{
MessageFocusOut(getData()->getId()).dispatch();
}
void QtGraphEdge::focusIn()
{
bool isActive = m_isActive;
this->setIsActive(true);
m_isActive = isActive;
}
void QtGraphEdge::focusOut()
{
this->setIsActive(m_isActive);
}
+11 -9
View File
@@ -7,24 +7,24 @@
#include "utility/math/Vector2.h"
#include "component/view/graphElements/GraphEdge.h"
class GraphNode;
class Edge;
class QtGraphNode;
class QtGraphEdge
: public QObject
, public GraphEdge
, public QGraphicsItemGroup
{
Q_OBJECT
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
public:
QtGraphEdge(const std::weak_ptr<GraphNode>& owner, const std::weak_ptr<GraphNode>& target, const Edge* data);
QtGraphEdge(const std::weak_ptr<QtGraphNode>& owner, const std::weak_ptr<QtGraphNode>& target, const Edge* data);
virtual ~QtGraphEdge();
virtual std::weak_ptr<GraphNode> getOwner();
virtual std::weak_ptr<GraphNode> getTarget();
const Edge* getData() const;
virtual std::weak_ptr<QtGraphNode> getOwner();
virtual std::weak_ptr<QtGraphNode> getTarget();
virtual void updateLine();
@@ -45,8 +45,10 @@ protected:
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
private:
std::weak_ptr<GraphNode> m_owner;
std::weak_ptr<GraphNode> m_target;
const Edge* m_data;
std::weak_ptr<QtGraphNode> m_owner;
std::weak_ptr<QtGraphNode> m_target;
QGraphicsLineItem* m_child;
+76 -121
View File
@@ -1,14 +1,10 @@
#include "qt/view/graphElements/QtGraphNode.h"
#include <QBrush>
#include <QFont>
#include <QGraphicsSceneEvent>
#include <QPen>
#include "utility/messaging/type/MessageActivateTokens.h"
#include "utility/messaging/type/MessageGraphNodeMove.h"
#include "utility/messaging/type/MessageFocusIn.h"
#include "utility/messaging/type/MessageFocusOut.h"
#include "qt/graphics/QtRoundedRectItem.h"
#include "qt/utility/QtDeviceScaledPixmap.h"
#include "qt/utility/QtGraphPostprocessor.h"
@@ -43,11 +39,9 @@ QFont QtGraphNode::getFontForNodeType(Node::NodeType type)
}
QtGraphNode::QtGraphNode()
: GraphNode(nullptr)
, m_undefinedRect(nullptr)
: m_undefinedRect(nullptr)
, m_isActive(false)
, m_isHovering(false)
, m_childVisible(false)
{
this->setPen(QPen(Qt::transparent));
@@ -55,45 +49,29 @@ QtGraphNode::QtGraphNode()
m_text = new QGraphicsSimpleTextItem(this);
}
QtGraphNode::QtGraphNode(const Node* data, bool childVisible)
: GraphNode(data)
, m_undefinedRect(nullptr)
, m_isActive(false)
, m_isHovering(false)
, m_childVisible(childVisible)
{
this->setPen(QPen(Qt::transparent));
m_rect = new QtRoundedRectItem(this);
m_text = new QGraphicsSimpleTextItem(this);
this->setAcceptHoverEvents(true);
this->setName(data->getName());
}
QtGraphNode::~QtGraphNode()
{
}
std::string QtGraphNode::getName() const
QtGraphNode* QtGraphNode::getParent() const
{
return m_text->text().toStdString();
return m_parentNode.lock().get();
}
void QtGraphNode::setName(const std::string& name)
void QtGraphNode::setParent(std::weak_ptr<QtGraphNode> parentNode)
{
m_text->setText(QString::fromStdString(name));
m_parentNode = parentNode;
std::shared_ptr<QtGraphNode> parent = parentNode.lock();
if (parent != NULL)
{
QGraphicsRectItem::setParentItem(parent.get());
}
}
bool QtGraphNode::isAccessNode() const
std::list<std::shared_ptr<QtGraphNode>> QtGraphNode::getSubNodes() const
{
return false;
}
bool QtGraphNode::isExpandToggleNode() const
{
return false;
return m_subNodes;
}
Vec2i QtGraphNode::getPosition() const
@@ -116,16 +94,6 @@ bool QtGraphNode::setPosition(const Vec2i& position)
return false;
}
void QtGraphNode::moved()
{
QtGraphPostprocessor::alignNodeOnRaster(this);
if (m_data)
{
MessageGraphNodeMove(m_data->getId(), getPosition()).dispatch();
}
}
Vec2i QtGraphNode::getSize() const
{
return m_size;
@@ -144,6 +112,16 @@ void QtGraphNode::setSize(const Vec2i& size)
}
}
QSize QtGraphNode::size() const
{
return QSize(m_size.x, m_size.y);
}
void QtGraphNode::setSize(const QSize& size)
{
setSize(Vec2i(size.width(), size.height()));
}
Vec4i QtGraphNode::getBoundingRect() const
{
Vec2i pos = getPosition();
@@ -167,12 +145,12 @@ Vec4i QtGraphNode::getParentBoundingRect() const
return node->getBoundingRect();
}
void QtGraphNode::addOutEdge(const std::shared_ptr<GraphEdge>& edge)
void QtGraphNode::addOutEdge(const std::shared_ptr<QtGraphEdge>& edge)
{
m_outEdges.push_back(edge);
}
void QtGraphNode::addInEdge(const std::weak_ptr<GraphEdge>& edge)
void QtGraphNode::addInEdge(const std::weak_ptr<QtGraphEdge>& edge)
{
m_inEdges.push_back(edge);
}
@@ -187,16 +165,6 @@ size_t QtGraphNode::getInEdgeCount() const
return m_inEdges.size();
}
QSize QtGraphNode::size() const
{
return QSize(m_size.x, m_size.y);
}
void QtGraphNode::setSize(const QSize& size)
{
setSize(Vec2i(size.width(), size.height()));
}
bool QtGraphNode::getIsActive() const
{
return m_isActive;
@@ -209,20 +177,14 @@ void QtGraphNode::setIsActive(bool isActive)
updateStyle();
}
QtGraphNode* QtGraphNode::getParent() const
std::string QtGraphNode::getName() const
{
return m_parentNode.lock().get();
return m_text->text().toStdString();
}
void QtGraphNode::setParent(std::weak_ptr<QtGraphNode> parentNode)
void QtGraphNode::setName(const std::string& name)
{
m_parentNode = parentNode;
std::shared_ptr<QtGraphNode> parent = parentNode.lock();
if (parent != NULL)
{
QGraphicsRectItem::setParentItem(parent.get());
}
m_text->setText(QString::fromStdString(name));
}
void QtGraphNode::addComponent(const std::shared_ptr<QtGraphNodeComponent>& component)
@@ -230,16 +192,6 @@ void QtGraphNode::addComponent(const std::shared_ptr<QtGraphNodeComponent>& comp
m_components.push_back(component);
}
std::list<std::shared_ptr<QtGraphNode>> QtGraphNode::getSubNodes() const
{
return m_subNodes;
}
void QtGraphNode::addSubNode(const std::shared_ptr<QtGraphNode>& node)
{
m_subNodes.push_back(node);
}
void QtGraphNode::setShadowEnabledRecursive(bool enabled)
{
m_rect->setShadowEnabled(enabled);
@@ -250,14 +202,6 @@ void QtGraphNode::setShadowEnabledRecursive(bool enabled)
}
}
void QtGraphNode::onClick()
{
if (!m_isActive && m_data && !m_data->isType(Node::NODE_UNDEFINED | Node::NODE_NAMESPACE))
{
MessageActivateTokens(m_data->getId()).dispatch();
}
}
void QtGraphNode::hoverEnter()
{
hoverEnterEvent(nullptr);
@@ -269,11 +213,50 @@ void QtGraphNode::hoverEnter()
}
}
void QtGraphNode::updateStyle()
void QtGraphNode::focusIn()
{
m_isHovering = true;
updateStyle();
}
void QtGraphNode::focusOut()
{
m_isHovering = false;
updateStyle();
}
bool QtGraphNode::isDataNode() const
{
return false;
}
bool QtGraphNode::isAccessNode() const
{
return false;
}
bool QtGraphNode::isExpandToggleNode() const
{
return false;
}
Id QtGraphNode::getTokenId() const
{
return 0;
}
void QtGraphNode::addSubNode(const std::shared_ptr<QtGraphNode>& node)
{
m_subNodes.push_back(node);
}
void QtGraphNode::moved()
{
QtGraphPostprocessor::alignNodeOnRaster(this);
}
void QtGraphNode::onClick()
{
GraphViewStyle::NodeStyle style =
GraphViewStyle::getStyleForNodeType(m_data->getType(), m_isActive, m_isHovering, m_childVisible);
setStyle(style);
}
void QtGraphNode::mousePressEvent(QGraphicsSceneMouseEvent* event)
@@ -333,44 +316,16 @@ void QtGraphNode::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
}
}
void QtGraphNode::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
if(m_data)
{
MessageFocusIn(m_data->getId()).dispatch();
}
}
void QtGraphNode::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{
if(m_data)
{
MessageFocusOut(m_data->getId()).dispatch();
}
}
void QtGraphNode::focusIn()
{
m_isHovering = true;
updateStyle();
}
void QtGraphNode::focusOut()
{
m_isHovering = false;
updateStyle();
}
void QtGraphNode::notifyEdgesAfterMove()
{
for (const std::shared_ptr<GraphEdge>& edge : m_outEdges)
for (const std::shared_ptr<QtGraphEdge>& edge : m_outEdges)
{
edge->updateLine();
}
for (const std::weak_ptr<GraphEdge>& e : m_inEdges)
for (const std::weak_ptr<QtGraphEdge>& e : m_inEdges)
{
std::shared_ptr<GraphEdge> edge = e.lock();
std::shared_ptr<QtGraphEdge> edge = e.lock();
if (edge)
{
edge->updateLine();
+44 -47
View File
@@ -1,20 +1,17 @@
#ifndef QT_GRAPH_NODE_H
#define QT_GRAPH_NODE_H
#include <QFontMetrics>
#include <QGraphicsItem>
#include "component/view/graphElements/GraphNode.h"
#include "component/view/GraphViewStyle.h"
#include "utility/messaging/MessageListener.h"
class QFont;
class QtGraphEdge;
class QtRoundedRectItem;
class QtGraphNodeComponent;
class QtGraphNode
: public QObject
, public GraphNode
, public QGraphicsRectItem
{
Q_OBJECT
@@ -33,69 +30,70 @@ public:
static QFont getFontForNodeType(Node::NodeType type);
QtGraphNode();
QtGraphNode(const Node* data, bool childVisible);
virtual ~QtGraphNode();
virtual std::string getName() const;
void setName(const std::string& name);
virtual bool isAccessNode() const;
virtual bool isExpandToggleNode() const;
virtual Vec2i getPosition() const;
virtual bool setPosition(const Vec2i& position);
virtual void moved();
virtual Vec2i getSize() const;
virtual void setSize(const Vec2i& size);
virtual Vec4i getBoundingRect() const;
virtual Vec4i getParentBoundingRect() const;
virtual void addOutEdge(const std::shared_ptr<GraphEdge>& edge);
virtual void addInEdge(const std::weak_ptr<GraphEdge>& edge);
virtual size_t getOutEdgeCount() const;
virtual size_t getInEdgeCount() const;
QSize size() const;
void setSize(const QSize& size);
bool getIsActive() const;
void setIsActive(bool isActive);
QtGraphNode* getParent() const;
void setParent(std::weak_ptr<QtGraphNode> parentNode);
void addComponent(const std::shared_ptr<QtGraphNodeComponent>& component);
std::list<std::shared_ptr<QtGraphNode>> getSubNodes() const;
virtual void addSubNode(const std::shared_ptr<QtGraphNode>& node);
Vec2i getPosition() const;
bool setPosition(const Vec2i& position);
Vec2i getSize() const;
void setSize(const Vec2i& size);
QSize size() const;
void setSize(const QSize& size);
Vec4i getBoundingRect() const;
Vec4i getParentBoundingRect() const;
void addOutEdge(const std::shared_ptr<QtGraphEdge>& edge);
void addInEdge(const std::weak_ptr<QtGraphEdge>& edge);
size_t getOutEdgeCount() const;
size_t getInEdgeCount() const;
bool getIsActive() const;
void setIsActive(bool isActive);
std::string getName() const;
void setName(const std::string& name);
void addComponent(const std::shared_ptr<QtGraphNodeComponent>& component);
void setShadowEnabledRecursive(bool enabled);
virtual void onClick();
void hoverEnter();
void focusIn();
void focusOut();
virtual void updateStyle();
virtual bool isDataNode() const;
virtual bool isAccessNode() const;
virtual bool isExpandToggleNode() const;
virtual Id getTokenId() const;
virtual void addSubNode(const std::shared_ptr<QtGraphNode>& node);
virtual void onClick();
virtual void moved();
virtual void updateStyle() = 0;
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
void notifyEdgesAfterMove();
void setStyle(const GraphViewStyle::NodeStyle& style);
std::list<std::shared_ptr<GraphEdge>> m_outEdges;
std::list<std::weak_ptr<GraphEdge>> m_inEdges;
std::list<std::shared_ptr<QtGraphEdge>> m_outEdges;
std::list<std::weak_ptr<QtGraphEdge>> m_inEdges;
std::weak_ptr<QtGraphNode> m_parentNode;
std::list<std::shared_ptr<QtGraphNode>> m_subNodes;
@@ -106,12 +104,11 @@ protected:
Vec2i m_size;
private:
std::list<std::shared_ptr<QtGraphNodeComponent>> m_components;
bool m_isActive;
bool m_isHovering;
bool m_childVisible;
private:
std::list<std::shared_ptr<QtGraphNodeComponent>> m_components;
};
#endif // QT_GRAPH_NODE_H
@@ -27,16 +27,16 @@ QtGraphNodeAccess::~QtGraphNodeAccess()
{
}
bool QtGraphNodeAccess::isAccessNode() const
{
return true;
}
TokenComponentAccess::AccessType QtGraphNodeAccess::getAccessType() const
{
return m_access;
}
bool QtGraphNodeAccess::isAccessNode() const
{
return true;
}
void QtGraphNodeAccess::addSubNode(const std::shared_ptr<QtGraphNode>& node)
{
QtGraphNode::addSubNode(node);
@@ -11,11 +11,12 @@ public:
QtGraphNodeAccess(TokenComponentAccess::AccessType accessType);
virtual ~QtGraphNodeAccess();
virtual bool isAccessNode() const;
TokenComponentAccess::AccessType getAccessType() const;
virtual void addSubNode(const std::shared_ptr<QtGraphNode>& node);
// QtGraphNode implementation
virtual bool isAccessNode() const;
virtual void addSubNode(const std::shared_ptr<QtGraphNode>& node);
virtual void updateStyle();
void hideLabel();
@@ -0,0 +1,66 @@
#include "qt/view/graphElements/QtGraphNodeData.h"
#include "utility/messaging/type/MessageActivateTokens.h"
#include "utility/messaging/type/MessageFocusIn.h"
#include "utility/messaging/type/MessageFocusOut.h"
#include "utility/messaging/type/MessageGraphNodeMove.h"
QtGraphNodeData::QtGraphNodeData(const Node* data, bool childVisible)
: m_data(data)
, m_childVisible(childVisible)
{
this->setAcceptHoverEvents(true);
this->setName(data->getName());
}
QtGraphNodeData::~QtGraphNodeData()
{
}
const Node* QtGraphNodeData::getData() const
{
return m_data;
}
bool QtGraphNodeData::isDataNode() const
{
return true;
}
Id QtGraphNodeData::getTokenId() const
{
return m_data->getId();
}
void QtGraphNodeData::onClick()
{
if (!m_isActive && !m_data->isType(Node::NODE_UNDEFINED | Node::NODE_NAMESPACE))
{
MessageActivateTokens(m_data->getId()).dispatch();
}
}
void QtGraphNodeData::moved()
{
QtGraphNode::moved();
MessageGraphNodeMove(m_data->getId(), getPosition()).dispatch();
}
void QtGraphNodeData::updateStyle()
{
GraphViewStyle::NodeStyle style =
GraphViewStyle::getStyleForNodeType(m_data->getType(), m_isActive, m_isHovering, m_childVisible);
setStyle(style);
}
void QtGraphNodeData::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
MessageFocusIn(m_data->getId()).dispatch();
}
void QtGraphNodeData::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{
MessageFocusOut(m_data->getId()).dispatch();
}
@@ -0,0 +1,33 @@
#ifndef QT_GRAPH_NODE_DATA_H
#define QT_GRAPH_NODE_DATA_H
#include "qt/view/graphElements/QtGraphNode.h"
class QtGraphNodeData
: public QtGraphNode
{
public:
QtGraphNodeData(const Node* data, bool childVisible);
virtual ~QtGraphNodeData();
const Node* getData() const;
// QtGraphNode implementation
virtual bool isDataNode() const;
virtual Id getTokenId() const;
virtual void onClick();
virtual void moved();
virtual void updateStyle();
protected:
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
private:
const Node* m_data;
bool m_childVisible;
};
#endif // QT_GRAPH_NODE_DATA_H
@@ -1,10 +1,13 @@
#include "qt/view/graphElements/QtGraphNodeExpandToggle.h"
#include <QFontMetrics>
#include "utility/logging/logging.h"
#include "utility/messaging/type/MessageGraphNodeExpand.h"
#include "qt/graphics/QtRoundedRectItem.h"
#include "qt/utility/QtDeviceScaledPixmap.h"
#include "qt/view/graphElements/QtGraphNodeData.h"
QtGraphNodeExpandToggle::QtGraphNodeExpandToggle(bool expanded, int invisibleSubNodeCount)
: m_allVisible(invisibleSubNodeCount == 0)
@@ -47,9 +50,9 @@ void QtGraphNodeExpandToggle::onClick()
{
QtGraphNode* parent = getParent();
if (parent && parent->getData())
if (parent && parent->getTokenId())
{
MessageGraphNodeExpand(parent->getData()->getId()).dispatch();
MessageGraphNodeExpand(parent->getTokenId()).dispatch();
}
}
@@ -12,6 +12,7 @@ public:
QtGraphNodeExpandToggle(bool expanded, int invisibleSubNodeCount);
virtual ~QtGraphNodeExpandToggle();
// QtGraphNode implementation
virtual bool isExpandToggleNode() const;
virtual void onClick();
@@ -16,7 +16,7 @@ QtGraphNodeComponentMoveable::~QtGraphNodeComponentMoveable()
void QtGraphNodeComponentMoveable::nodeMousePressEvent(QGraphicsSceneMouseEvent* event)
{
std::shared_ptr<GraphNode> node = m_graphNode.lock();
std::shared_ptr<QtGraphNode> node = m_graphNode.lock();
if (node != NULL)
{
m_mouseOffset.x = event->scenePos().x() - node->getPosition().x;
@@ -28,7 +28,7 @@ void QtGraphNodeComponentMoveable::nodeMousePressEvent(QGraphicsSceneMouseEvent*
void QtGraphNodeComponentMoveable::nodeMouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
std::shared_ptr<GraphNode> node = m_graphNode.lock();
std::shared_ptr<QtGraphNode> node = m_graphNode.lock();
if (node != NULL)
{
node->setPosition(Vec2i(event->scenePos().x() - m_mouseOffset.x, event->scenePos().y() - m_mouseOffset.y));
+2 -5
View File
@@ -35,6 +35,8 @@ add_files(
add_files(
LIB_FILES
component/controller/helper/DummyEdge.h
component/controller/helper/DummyNode.h
component/controller/helper/SnippetMerger.cpp
component/controller/helper/SnippetMerger.h
@@ -55,11 +57,6 @@ add_files(
component/controller/UndoRedoController.cpp
component/controller/UndoRedoController.h
component/view/graphElements/GraphEdge.cpp
component/view/graphElements/GraphEdge.h
component/view/graphElements/GraphNode.cpp
component/view/graphElements/GraphNode.h
component/view/CodeView.cpp
component/view/CodeView.h
component/view/CompositeView.cpp
@@ -4,8 +4,8 @@
#include "utility/logging/logging.h"
#include "component/view/graphElements/GraphEdge.h"
#include "component/view/graphElements/GraphNode.h"
#include "component/controller/helper/DummyEdge.h"
#include "component/controller/helper/DummyNode.h"
#include "component/view/GraphView.h"
#include "component/view/GraphViewStyle.h"
#include "data/access/StorageAccess.h"
@@ -1,16 +1,14 @@
#include "component/controller/GraphLayouter.h"
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include "component/view/graphElements/GraphEdge.h"
#include "component/view/graphElements/GraphNode.h"
#include "utility/math/MatrixDynamicBase.h"
#include "component/controller/helper/DummyEdge.h"
#include "component/controller/helper/DummyNode.h"
// for prototyping, remove when done
#include "Eigen/Dense"
#include "Eigen/Eigenvalues"
@@ -151,10 +149,7 @@ void GraphLayouter::layoutSpectralPrototype(std::vector<DummyNode>& nodes, const
nodes[i].position.x = newPos.x;
nodes[i].position.y = newPos.y;
//std::cout << newPos << std::endl;
}
//std::cout << "=================" << std::endl;
}
}
@@ -0,0 +1,29 @@
#ifndef DUMMY_EDGE_H
#define DUMMY_EDGE_H
#include "utility/types.h"
class Edge;
// temporary data structure for (visual) graph creation process
struct DummyEdge
{
DummyEdge(const Id ownerId, const Id targetId, const Edge* data)
: ownerId(ownerId)
, targetId(targetId)
, data(data)
, visible(false)
, active(false)
{
}
Id ownerId;
Id targetId;
const Edge* data;
bool visible;
bool active;
};
#endif // DUMMY_EDGE_H
@@ -1,51 +1,14 @@
#ifndef GRAPH_NODE_H
#define GRAPH_NODE_H
#include <list>
#include <memory>
#ifndef DUMMY_NODE_H
#define DUMMY_NODE_H
#include "utility/math/Vector2.h"
#include "utility/math/Vector4.h"
#include "utility/types.h"
#include "data/graph/Node.h"
#include "data/graph/token_component/TokenComponentAccess.h"
class GraphEdge;
class GraphNode
{
public:
GraphNode(const Node* data);
virtual ~GraphNode();
virtual std::string getName() const = 0;
Id getTokenId() const;
const Node* getData() const;
void setData(const Node* data);
virtual bool isAccessNode() const = 0;
virtual Vec2i getPosition() const = 0;
virtual bool setPosition(const Vec2i& position) = 0;
virtual Vec2i getSize() const = 0;
virtual void setSize(const Vec2i& size) = 0;
virtual Vec4i getBoundingRect() const = 0;
virtual Vec4i getParentBoundingRect() const = 0;
virtual void addOutEdge(const std::shared_ptr<GraphEdge>& edge) = 0;
virtual void addInEdge(const std::weak_ptr<GraphEdge>& edge) = 0;
virtual size_t getOutEdgeCount() const = 0;
virtual size_t getInEdgeCount() const = 0;
protected:
const Node* m_data;
};
class Node;
// temporary data structure for (visual) graph creation process
struct DummyNode
{
public:
@@ -111,4 +74,4 @@ public:
size_t invisibleSubNodeCount;
};
#endif // GRAPH_NODE_H
#endif // DUMMY_NODE_H
-4
View File
@@ -1,10 +1,6 @@
#ifndef GRAPH_VIEW_H
#define GRAPH_VIEW_H
#include <list>
#include <memory>
#include "utility/math/Vector2.h"
#include "utility/types.h"
#include "component/view/View.h"
@@ -2,6 +2,7 @@
#include "utility/logging/logging.h"
#include "component/view/GraphViewStyleImpl.h"
#include "settings/ApplicationSettings.h"
GraphViewStyle::NodeMargins::NodeMargins()
+5 -2
View File
@@ -4,11 +4,14 @@
#include <map>
#include <memory>
#include "component/view/graphElements/GraphNode.h"
#include "component/view/GraphViewStyleImpl.h"
#include "utility/math/Vector2.h"
#include "utility/math/Vector4.h"
#include "data/graph/Node.h"
#include "data/graph/token_component/TokenComponentAccess.h"
class GraphViewStyleImpl;
class GraphViewStyle
{
public:
@@ -1,15 +0,0 @@
#include "component/view/graphElements/GraphEdge.h"
GraphEdge::GraphEdge(const Edge* data)
: m_data(data)
{
}
GraphEdge::~GraphEdge()
{
}
const Edge* GraphEdge::getData() const
{
return m_data;
}
@@ -1,50 +0,0 @@
#ifndef GRAPH_EDGE_H
#define GRAPH_EDGE_H
#include <memory>
#include "data/graph/Edge.h"
#include "utility/math/Vector4.h"
#include "utility/types.h"
class GraphNode;
class GraphEdge
{
public:
GraphEdge(const Edge* data);
virtual ~GraphEdge();
virtual std::weak_ptr<GraphNode> getOwner() = 0;
virtual std::weak_ptr<GraphNode> getTarget() = 0;
virtual void updateLine() = 0;
const Edge* getData() const;
private:
const Edge* m_data;
};
// temporary data structure for (visual) graph creation process
struct DummyEdge
{
DummyEdge(const Id o, const Id t, const Edge* data)
: ownerId(o)
, targetId(t)
, data(data)
, visible(false)
, active(false)
{
}
Id ownerId;
Id targetId;
const Edge* data;
bool visible;
bool active;
};
#endif // GRAPH_EDGE_H
@@ -1,29 +0,0 @@
#include "component/view/graphElements/GraphNode.h"
GraphNode::GraphNode(const Node* data)
: m_data(data)
{
}
GraphNode::~GraphNode()
{
}
Id GraphNode::getTokenId() const
{
if (m_data)
{
return m_data->getId();
}
return 0;
}
const Node* GraphNode::getData() const
{
return m_data;
}
void GraphNode::setData(const Node* data)
{
m_data = data;
}