From da74ca1a3e0bba6f115592b269b8f3f94227e8d5 Mon Sep 17 00:00:00 2001 From: Denes Matetelki Date: Thu, 30 Jun 2011 13:36:33 +0200 Subject: [PATCH] removed Node::addEdge call from Edge ctor, called it at Edge creation --- src/edge.cpp | 8 +++----- src/graphwidget.cpp | 13 ++++++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/edge.cpp b/src/edge.cpp index 4c77390..0b99a13 100644 --- a/src/edge.cpp +++ b/src/edge.cpp @@ -12,7 +12,9 @@ const double Edge::m_twoPi = 2.0 * Edge::m_pi; const qreal Edge::m_arrowSize = 7; Edge::Edge(Node *sourceNode, Node *destNode) - : m_angle(-1) + : m_sourceNode(sourceNode) + , m_destNode(destNode) + , m_angle(-1) , m_color(0,0,0) , m_width(1) , m_secondary(false) @@ -21,10 +23,6 @@ Edge::Edge(Node *sourceNode, Node *destNode) setAcceptedMouseButtons(0); setZValue(1); - m_sourceNode = sourceNode; - m_destNode = destNode; - m_sourceNode->addEdge(this,true); - m_destNode->addEdge(this,false); adjust(); } diff --git a/src/graphwidget.cpp b/src/graphwidget.cpp index 132e338..db584ed 100644 --- a/src/graphwidget.cpp +++ b/src/graphwidget.cpp @@ -131,9 +131,13 @@ bool GraphWidget::readContentFromXmlFile(const QString &fileName) QDomElement e = edges.item(i).toElement(); if(!e.isNull()) { - Edge *edge = new Edge( - m_nodeList[e.attribute("source").toInt()], - m_nodeList[e.attribute("destination").toInt()]); + Node *source = m_nodeList[e.attribute("source").toInt()]; + Node *destination = m_nodeList[e.attribute("destination").toInt()]; + + Edge *edge = new Edge(source, destination); + source->addEdge(edge, true); + destination->addEdge(edge, false); + edge->setColor(QColor(e.attribute("red").toFloat(), e.attribute("green").toFloat(), e.attribute("blue").toFloat())); @@ -829,6 +833,9 @@ void GraphWidget::addEdge(Node *source, Node *destination) sec = true; } Edge *edge = new Edge(source, destination); + source->addEdge(edge, true); + destination->addEdge(edge, false); + edge->setColor(destination->color()); edge->setWidth(destination->scale()*2 + 1);