diff --git a/include/commands.h b/include/commands.h index 59ce39a..b9c5d95 100644 --- a/include/commands.h +++ b/include/commands.h @@ -41,6 +41,12 @@ public: const char* what() const throw(); }; +class EdgeDoesntExistsBetweenNodesException : public std::exception +{ +public: + const char* what() const throw(); +}; + // commands: diff --git a/other/qtmindmap-0.2.ebuild b/other/qtmindmap-0.2.ebuild index cc55d2d..688cbba 100644 --- a/other/qtmindmap-0.2.ebuild +++ b/other/qtmindmap-0.2.ebuild @@ -8,7 +8,7 @@ inherit qt4-r2 DESCRIPTION="MindMap software written in Qt" HOMEPAGE="https://gitorious.org/qtmindmap" -SRC_URI="http://matetelki.com/qtmindmap/qtmindmap-qtmindmap-master.tar.gz" +SRC_URI="http://matetelki.com/qtmindmap/qtmindmap-0.2.tar.gz" LICENSE="GPL-2" # some functions introduced in qt 4.6 diff --git a/src/commands.cpp b/src/commands.cpp index d73960b..c1824a5 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -34,6 +34,12 @@ const char* EdgeExistsBetweenNodesException::what() const throw() toStdString().c_str(); } +const char* EdgeDoesntExistsBetweenNodesException::what() const throw() +{ + return QObject::tr("There is no edge between these two nodes."). + toStdString().c_str(); +} + InsertNodeCommand::InsertNodeCommand(GraphLogic *graphLogic) : m_graphLogic(graphLogic) @@ -102,7 +108,6 @@ void InsertNodeCommand::redo() m_node->setPos(m_pos); -// m_graphLogic->addEdge(m_activeNode, m_node); m_edge->sourceNode()->addEdge(m_edge,true); m_edge->destNode()->addEdge(m_edge,false); m_graphLogic->m_graphWidget->scene()->addItem(m_edge); @@ -209,9 +214,6 @@ AddEdgeCommand::AddEdgeCommand(GraphLogic *graphLogic, Node *source, Node *desti , m_source(source) , m_destination(destinaion) { - if (!m_activeNode) - throw NoActiveNodeException(); - if (m_destination == m_graphLogic->m_nodeList.first()) throw BaseNodeCannotBeEdgeTargetException(); @@ -272,6 +274,9 @@ RemoveEdgeCommand::RemoveEdgeCommand(GraphLogic *graphLogic, Node *source, Node , m_destination(destinaion) , m_edge(source->edgeTo(destinaion)) { + if (!m_source->isConnected(m_destination)) + throw EdgeDoesntExistsBetweenNodesException(); + setText(QObject::tr("Edge releted between \"").append( m_source->toPlainText()).append( QObject::tr("\" and \"").append( diff --git a/src/graphlogic.cpp b/src/graphlogic.cpp index a396ac9..03f07f4 100644 --- a/src/graphlogic.cpp +++ b/src/graphlogic.cpp @@ -91,6 +91,7 @@ bool GraphLogic::processKeyEvent(QKeyEvent *event) if (m_showingNodeNumbers && event->key() >= Qt::Key_0 && event->key() <= Qt::Key_9) { + /// @todo remove magic number appendNumber(event->key()-48); return true; } @@ -713,22 +714,15 @@ void GraphLogic::addEdge(Node *source, Node *destination) void GraphLogic::removeEdge(Node *source, Node *destination) { - if (!m_activeNode) - { - emit notification(tr("No active node.")); - return; - } - - if (!source->isConnected(destination)) + try { - setActiveNode(destination); - emit notification(tr("There no edge between these two nodes.")); + QUndoCommand *addEdgeCommand = new RemoveEdgeCommand(this, source, destination); + m_undoStack->push(addEdgeCommand); } - else + catch (std::exception &e) { - source->deleteEdge(destination); - setActiveNode(destination); - emit contentChanged(); + emit notification(e.what()); + return; } }