summaryrefslogtreecommitdiffstats
path: root/examples/widgets/tools/undo/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/tools/undo/mainwindow.cpp')
-rw-r--r--examples/widgets/tools/undo/mainwindow.cpp53
1 files changed, 27 insertions, 26 deletions
diff --git a/examples/widgets/tools/undo/mainwindow.cpp b/examples/widgets/tools/undo/mainwindow.cpp
index 118d604742..9d83e3067a 100644
--- a/examples/widgets/tools/undo/mainwindow.cpp
+++ b/examples/widgets/tools/undo/mainwindow.cpp
@@ -48,6 +48,10 @@
**
****************************************************************************/
+#include "mainwindow.h"
+#include "document.h"
+#include "commands.h"
+
#include <QUndoGroup>
#include <QUndoStack>
#include <QFileDialog>
@@ -55,9 +59,6 @@
#include <QRandomGenerator>
#include <QTextStream>
#include <QToolButton>
-#include "document.h"
-#include "mainwindow.h"
-#include "commands.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
@@ -122,17 +123,17 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::updateActions()
{
Document *doc = currentDocument();
- m_undoGroup->setActiveStack(doc == 0 ? 0 : doc->undoStack());
- QString shapeName = doc == 0 ? QString() : doc->currentShapeName();
-
- actionAddRobot->setEnabled(doc != 0);
- actionAddSnowman->setEnabled(doc != 0);
- actionAddCircle->setEnabled(doc != 0);
- actionAddRectangle->setEnabled(doc != 0);
- actionAddTriangle->setEnabled(doc != 0);
- actionClose->setEnabled(doc != 0);
- actionSave->setEnabled(doc != 0 && !doc->undoStack()->isClean());
- undoLimit->setEnabled(doc != 0 && doc->undoStack()->count() == 0);
+ m_undoGroup->setActiveStack(doc == nullptr ? nullptr : doc->undoStack());
+ QString shapeName = doc == nullptr ? QString() : doc->currentShapeName();
+
+ actionAddRobot->setEnabled(doc != nullptr);
+ actionAddSnowman->setEnabled(doc != nullptr);
+ actionAddCircle->setEnabled(doc != nullptr);
+ actionAddRectangle->setEnabled(doc != nullptr);
+ actionAddTriangle->setEnabled(doc != nullptr);
+ actionClose->setEnabled(doc != nullptr);
+ actionSave->setEnabled(doc != nullptr && !doc->undoStack()->isClean());
+ undoLimit->setEnabled(doc != nullptr && doc->undoStack()->count() == 0);
if (shapeName.isEmpty()) {
actionRed->setEnabled(false);
@@ -147,7 +148,7 @@ void MainWindow::updateActions()
actionRemoveShape->setEnabled(true);
}
- if (doc != 0) {
+ if (doc != nullptr) {
int index = documentTabs->indexOf(doc);
Q_ASSERT(index != -1);
static const QIcon unsavedIcon(":/icons/filesave.png");
@@ -264,7 +265,7 @@ void MainWindow::removeDocument(Document *doc)
void MainWindow::saveDocument()
{
Document *doc = currentDocument();
- if (doc == 0)
+ if (doc == nullptr)
return;
for (;;) {
@@ -298,7 +299,7 @@ void MainWindow::saveDocument()
void MainWindow::closeDocument()
{
Document *doc = currentDocument();
- if (doc == 0)
+ if (doc == nullptr)
return;
if (!doc->undoStack()->isClean()) {
@@ -338,10 +339,10 @@ static QRect randomRect(const QSize &s)
{
QSize min = Shape::minSize;
- int left = (int) ((0.0 + s.width() - min.width())*(QRandomGenerator::global()->bounded(1.0)));
- int top = (int) ((0.0 + s.height() - min.height())*(QRandomGenerator::global()->bounded(1.0)));
- int width = (int) ((0.0 + s.width() - left - min.width())*(QRandomGenerator::global()->bounded(1.0))) + min.width();
- int height = (int) ((0.0 + s.height() - top - min.height())*(QRandomGenerator::global()->bounded(1.0))) + min.height();
+ int left = qRound((s.width() - min.width()) * (QRandomGenerator::global()->bounded(1.0)));
+ int top = qRound((s.height() - min.height()) * (QRandomGenerator::global()->bounded(1.0)));
+ int width = qRound((s.width() - left - min.width()) * (QRandomGenerator::global()->bounded(1.0))) + min.width();
+ int height = qRound((s.height() - top - min.height()) * (QRandomGenerator::global()->bounded(1.0))) + min.height();
return QRect(left, top, width, height);
}
@@ -349,7 +350,7 @@ static QRect randomRect(const QSize &s)
void MainWindow::addShape()
{
Document *doc = currentDocument();
- if (doc == 0)
+ if (doc == nullptr)
return;
Shape::Type type;
@@ -369,7 +370,7 @@ void MainWindow::addShape()
void MainWindow::removeShape()
{
Document *doc = currentDocument();
- if (doc == 0)
+ if (doc == nullptr)
return;
QString shapeName = doc->currentShapeName();
@@ -382,7 +383,7 @@ void MainWindow::removeShape()
void MainWindow::setShapeColor()
{
Document *doc = currentDocument();
- if (doc == 0)
+ if (doc == nullptr)
return;
QString shapeName = doc->currentShapeName();
@@ -409,7 +410,7 @@ void MainWindow::setShapeColor()
void MainWindow::addSnowman()
{
Document *doc = currentDocument();
- if (doc == 0)
+ if (doc == nullptr)
return;
// Create a macro command using beginMacro() and endMacro()
@@ -427,7 +428,7 @@ void MainWindow::addSnowman()
void MainWindow::addRobot()
{
Document *doc = currentDocument();
- if (doc == 0)
+ if (doc == nullptr)
return;
// Compose a macro command by explicitly adding children to a parent command