From b947ebf2adac1f5a51b29d7c37cace22e88c2d61 Mon Sep 17 00:00:00 2001 From: Denes Matetelki Date: Tue, 14 Jun 2011 11:41:02 +0200 Subject: [PATCH] cannot remove not existing edges --- graphwidget.cpp | 20 +++++++++++++++++--- graphwidget.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/graphwidget.cpp b/graphwidget.cpp index f734c42..cec0084 100644 --- a/graphwidget.cpp +++ b/graphwidget.cpp @@ -295,7 +295,7 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) } if (m_edgeDeleting) { - m_activeNode->removeEdge(m_hintNode); + removeEdge(m_activeNode, m_hintNode); m_edgeDeleting = false; } else // selecting @@ -511,7 +511,7 @@ void GraphWidget::showingNodeNumbersBeginWithNumber(const int &number, } if (m_edgeDeleting) { - m_activeNode->removeEdge(m_hintNode); + removeEdge(m_activeNode, m_hintNode); m_edgeDeleting = false; } else // selecting @@ -552,7 +552,7 @@ void GraphWidget::nodeSelected(Node *node) } if (m_edgeDeleting) { - m_activeNode->removeEdge(node); + removeEdge(m_activeNode, node); m_edgeDeleting = false; } else @@ -574,3 +574,17 @@ void GraphWidget::addEdge(const Node *source, const Node *destination) m_scene->addItem(new Edge(m_activeNode, m_hintNode)); } } + +void GraphWidget::removeEdge(Node *source, Node *destination) +{ + if (!source->isConnected(destination)) + { + dynamic_cast(m_parent)->getStatusBar()->showMessage( + tr("There no edge between these two nodes."), + 5000); // millisec + } + else + { + source->removeEdge(destination); + } +} diff --git a/graphwidget.h b/graphwidget.h index da12478..b1e9e4c 100644 --- a/graphwidget.h +++ b/graphwidget.h @@ -38,6 +38,7 @@ private: bool numberStartsWithNumber(const int &number, const int &prefix); qreal calculateBiggestAngle(Node *node); void addEdge(const Node *source, const Node *destination); + void removeEdge(Node* source, Node *destination); QList m_nodeList; QWidget *m_parent;