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() {}
/** 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();

@ -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;
}
}

@ -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

@ -1,4 +1,4 @@
#include <stdlib.h> // EXIT_SUCCESS
#include <stdlib.h> // EXIT_FAILURE
#include <iostream> // cerr
#include <QtGui>
@ -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;

@ -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

Loading…
Cancel
Save