From 6f4af90e1317b170141a0ca944597b435fe6eb15 Mon Sep 17 00:00:00 2001 From: Denes Matetelki Date: Sun, 26 Jun 2011 18:58:15 +0200 Subject: [PATCH] do not allow adding new node outside of the scene --- include/argumentparser.h | 3 +-- src/argumentparser.cpp | 10 +--------- src/graphwidget.cpp | 20 ++++++++++++++++---- src/main.cpp | 7 +++---- src/node.cpp | 1 - 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/include/argumentparser.h b/include/argumentparser.h index ab4efa7..13be63d 100644 --- a/include/argumentparser.h +++ b/include/argumentparser.h @@ -16,10 +16,9 @@ public: , m_filePath() {} /** parse QCoreApplication::arguments and put data to priv. members - * @param successful true if cannot continue but it is not an error * @return true if the program can continue */ - bool parseCmdLineArgs(bool &successful); + bool parseCmdLineArgs(); bool isSystemTray(); bool isShowMinimized(); diff --git a/src/argumentparser.cpp b/src/argumentparser.cpp index e4dd9a6..560b35d 100644 --- a/src/argumentparser.cpp +++ b/src/argumentparser.cpp @@ -27,7 +27,7 @@ void ArgumentParser::printUsage() } -bool ArgumentParser::parseCmdLineArgs(bool &successful) +bool ArgumentParser::parseCmdLineArgs() { QStringList cmdlineArgs = QCoreApplication::arguments(); cmdlineArgs.removeFirst(); @@ -36,7 +36,6 @@ bool ArgumentParser::parseCmdLineArgs(bool &successful) if (!cmdlineArgs.filter(help).isEmpty()) { printUsage(); - successful = true; return false; } @@ -62,17 +61,13 @@ bool ArgumentParser::parseCmdLineArgs(bool &successful) std::cerr << tr("Unkown options: ").toStdString() << others.join(" ").toStdString() << std::endl; printUsage(); - successful = false; return false; } if (others.size()==1) { if (others.first().at(0)=='-') - { - successful = false; return false; - } /// @note filecheck shall be done elsewhere? m_filePath = others.first(); @@ -82,7 +77,6 @@ bool ArgumentParser::parseCmdLineArgs(bool &successful) std::cerr << tr("File: ").toStdString() << m_filePath.toStdString() << tr(" does not exists.").toStdString() << std::endl; - successful = false; return false; } if (!fileInfo.isFile()) @@ -90,7 +84,6 @@ bool ArgumentParser::parseCmdLineArgs(bool &successful) std::cerr << tr("File: ").toStdString() << m_filePath.toStdString() << tr(" is not a file.").toStdString() << std::endl; - successful = false; return false; } if (!fileInfo.isReadable()) @@ -98,7 +91,6 @@ bool ArgumentParser::parseCmdLineArgs(bool &successful) std::cerr << tr("File: ").toStdString() << m_filePath.toStdString() << tr(" is not readable.").toStdString() << std::endl; - successful = false; return false; } } diff --git a/src/graphwidget.cpp b/src/graphwidget.cpp index 312eb8d..b1d4d37 100644 --- a/src/graphwidget.cpp +++ b/src/graphwidget.cpp @@ -284,11 +284,23 @@ void GraphWidget::insertNode() node->setTextColor(m_activeNode->textColor()); node->setHtml(QString("")); m_scene->addItem(node); - node->setPos(m_activeNode->sceneBoundingRect().center() + - pos - - node->boundingRect().center()); - m_nodeList.append(node); + QPointF newPos(m_activeNode->sceneBoundingRect().center() + + pos - + node->boundingRect().center()); + QRectF rect (scene()->sceneRect().topLeft(), + scene()->sceneRect().bottomRight() - + node->boundingRect().bottomRight()); + + if (!rect.contains(newPos)) + { + delete node; + m_parent->statusBarMsg(tr("New node would be placed outside of the scene")); + return; + } + + node->setPos(newPos); + m_nodeList.append(node); addEdge(m_activeNode, node); // set it the active Node and editable, so the user can edit it at once diff --git a/src/main.cpp b/src/main.cpp index 53ba785..96c565d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#include // EXIT_SUCCESS +#include // EXIT_FAILURE #include // cerr #include @@ -32,9 +32,8 @@ int main(int argc, char *argv[]) // parse args ArgumentParser argParser; - bool success; - if (!argParser.parseCmdLineArgs(success)) - return success ? EXIT_SUCCESS : EXIT_FAILURE; + if (!argParser.parseCmdLineArgs()) + return EXIT_FAILURE; // system tray? MainWindow w; diff --git a/src/node.cpp b/src/node.cpp index d7dab68..c93c810 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -412,7 +412,6 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value) case ItemPositionChange: { // Node is about to move, check borders - QPointF newPos = value.toPointF(); // the fence is reduced with the size of the node