do not allow adding new node outside of the scene

master
Denes Matetelki 14 years ago
parent 7b45f784e6
commit 6f4af90e13

@ -16,10 +16,9 @@ public:
, m_filePath() {} , m_filePath() {}
/** parse QCoreApplication::arguments and put data to priv. members /** 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 * @return true if the program can continue
*/ */
bool parseCmdLineArgs(bool &successful); bool parseCmdLineArgs();
bool isSystemTray(); bool isSystemTray();
bool isShowMinimized(); bool isShowMinimized();

@ -27,7 +27,7 @@ void ArgumentParser::printUsage()
} }
bool ArgumentParser::parseCmdLineArgs(bool &successful) bool ArgumentParser::parseCmdLineArgs()
{ {
QStringList cmdlineArgs = QCoreApplication::arguments(); QStringList cmdlineArgs = QCoreApplication::arguments();
cmdlineArgs.removeFirst(); cmdlineArgs.removeFirst();
@ -36,7 +36,6 @@ bool ArgumentParser::parseCmdLineArgs(bool &successful)
if (!cmdlineArgs.filter(help).isEmpty()) if (!cmdlineArgs.filter(help).isEmpty())
{ {
printUsage(); printUsage();
successful = true;
return false; return false;
} }
@ -62,17 +61,13 @@ bool ArgumentParser::parseCmdLineArgs(bool &successful)
std::cerr << tr("Unkown options: ").toStdString() std::cerr << tr("Unkown options: ").toStdString()
<< others.join(" ").toStdString() << std::endl; << others.join(" ").toStdString() << std::endl;
printUsage(); printUsage();
successful = false;
return false; return false;
} }
if (others.size()==1) if (others.size()==1)
{ {
if (others.first().at(0)=='-') if (others.first().at(0)=='-')
{
successful = false;
return false; return false;
}
/// @note filecheck shall be done elsewhere? /// @note filecheck shall be done elsewhere?
m_filePath = others.first(); m_filePath = others.first();
@ -82,7 +77,6 @@ bool ArgumentParser::parseCmdLineArgs(bool &successful)
std::cerr << tr("File: ").toStdString() << std::cerr << tr("File: ").toStdString() <<
m_filePath.toStdString() << m_filePath.toStdString() <<
tr(" does not exists.").toStdString() << std::endl; tr(" does not exists.").toStdString() << std::endl;
successful = false;
return false; return false;
} }
if (!fileInfo.isFile()) if (!fileInfo.isFile())
@ -90,7 +84,6 @@ bool ArgumentParser::parseCmdLineArgs(bool &successful)
std::cerr << tr("File: ").toStdString() << std::cerr << tr("File: ").toStdString() <<
m_filePath.toStdString() << m_filePath.toStdString() <<
tr(" is not a file.").toStdString() << std::endl; tr(" is not a file.").toStdString() << std::endl;
successful = false;
return false; return false;
} }
if (!fileInfo.isReadable()) if (!fileInfo.isReadable())
@ -98,7 +91,6 @@ bool ArgumentParser::parseCmdLineArgs(bool &successful)
std::cerr << tr("File: ").toStdString() << std::cerr << tr("File: ").toStdString() <<
m_filePath.toStdString() << m_filePath.toStdString() <<
tr(" is not readable.").toStdString() << std::endl; tr(" is not readable.").toStdString() << std::endl;
successful = false;
return false; return false;
} }
} }

@ -284,11 +284,23 @@ void GraphWidget::insertNode()
node->setTextColor(m_activeNode->textColor()); node->setTextColor(m_activeNode->textColor());
node->setHtml(QString("")); node->setHtml(QString(""));
m_scene->addItem(node); m_scene->addItem(node);
node->setPos(m_activeNode->sceneBoundingRect().center() +
QPointF newPos(m_activeNode->sceneBoundingRect().center() +
pos - pos -
node->boundingRect().center()); node->boundingRect().center());
m_nodeList.append(node); 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); addEdge(m_activeNode, node);
// set it the active Node and editable, so the user can edit it at once // set it the active Node and editable, so the user can edit it at once

@ -1,4 +1,4 @@
#include <stdlib.h> // EXIT_SUCCESS #include <stdlib.h> // EXIT_FAILURE
#include <iostream> // cerr #include <iostream> // cerr
#include <QtGui> #include <QtGui>
@ -32,9 +32,8 @@ int main(int argc, char *argv[])
// parse args // parse args
ArgumentParser argParser; ArgumentParser argParser;
bool success; if (!argParser.parseCmdLineArgs())
if (!argParser.parseCmdLineArgs(success)) return EXIT_FAILURE;
return success ? EXIT_SUCCESS : EXIT_FAILURE;
// system tray? // system tray?
MainWindow w; MainWindow w;

@ -412,7 +412,6 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
case ItemPositionChange: case ItemPositionChange:
{ {
// Node is about to move, check borders // Node is about to move, check borders
QPointF newPos = value.toPointF(); QPointF newPos = value.toPointF();
// the fence is reduced with the size of the node // the fence is reduced with the size of the node

Loading…
Cancel
Save