diff --git a/include/mainwindow.h b/include/mainwindow.h index d10feec..a8f14b2 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -11,6 +11,11 @@ namespace Ui { class MainWindow; } +/** Responsibilities: + * - taking care of the menu and toolbars, file operations + * - displaying info in statusbar + * - handle content change + */ class MainWindow : public QMainWindow { Q_OBJECT diff --git a/src/graphwidget.cpp b/src/graphwidget.cpp index db584ed..aa9fa55 100644 --- a/src/graphwidget.cpp +++ b/src/graphwidget.cpp @@ -812,6 +812,7 @@ void GraphWidget::addEdge(Node *source, Node *destination) if (destination == m_nodeList.first()) { + setActiveNode(destination); emit notification( tr("Root element cannot be an edge target.")); return; @@ -819,6 +820,7 @@ void GraphWidget::addEdge(Node *source, Node *destination) if (source->isConnected(destination)) { + setActiveNode(destination); emit notification( tr("There is already an edge between these two nodes.")); } @@ -842,8 +844,9 @@ void GraphWidget::addEdge(Node *source, Node *destination) // The Edge is secondary, because the Node already has a parent // (it is already a destination of another Edge) edge->setSecondary(sec); - m_scene->addItem(edge); + + setActiveNode(destination); emit contentChanged(); } } @@ -858,11 +861,13 @@ void GraphWidget::removeEdge(Node *source, Node *destination) if (!source->isConnected(destination)) { + setActiveNode(destination); emit notification(tr("There no edge between these two nodes.")); } else { source->deleteEdge(destination); + setActiveNode(destination); emit contentChanged(); } } @@ -893,7 +898,8 @@ void GraphWidget::setActiveNode(Node *node) m_activeNode->setBorder(false); m_activeNode = node; - m_activeNode->setBorder(); + if (m_activeNode) + m_activeNode->setBorder(); } // re-draw numbers diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2c0f6d9..d5549a2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -53,6 +53,7 @@ void MainWindow::statusBarMsg(const QString &msg) void MainWindow::contentChanged(const bool& changed) { + // only care about the transitions if (m_contentChanged == false && changed == true) { setWindowTitle(windowTitle().prepend("* ")); @@ -276,12 +277,14 @@ void MainWindow::quit() void MainWindow::closeEvent(QCloseEvent * event) { - m_contentChanged && !closeFile() ? event->ignore() : event->accept(); + m_contentChanged && !closeFile() ? + event->ignore() : + event->accept(); } void MainWindow::keyPressEvent(QKeyEvent *event) { - // incative action does not listen to signals + // inactive action does not listen to signals if (event->modifiers() & Qt::ControlModifier) { if (event->key() == Qt::Key_M)