summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/embedded/flickable/flickable.cpp10
-rw-r--r--examples/embedded/raycasting/raycasting.cpp8
-rw-r--r--examples/gui/openglwindow/main.cpp49
-rw-r--r--examples/gui/openglwindow/openglwindow.cpp11
-rw-r--r--examples/gui/openglwindow/openglwindow.h12
-rw-r--r--examples/opengl/computegles31/glwindow.cpp39
-rw-r--r--examples/opengl/computegles31/glwindow.h22
-rw-r--r--examples/opengl/contextinfo/renderwindow.cpp4
-rw-r--r--examples/opengl/contextinfo/widget.h2
-rw-r--r--examples/opengl/cube/geometryengine.cpp2
-rw-r--r--examples/opengl/cube/mainwidget.cpp10
-rw-r--r--examples/opengl/cube/mainwidget.h8
-rw-r--r--examples/opengl/hellogl2/glwidget.cpp14
-rw-r--r--examples/opengl/hellogl2/glwidget.h18
-rw-r--r--examples/opengl/hellogl2/logo.cpp1
-rw-r--r--examples/opengl/hellogl2/logo.h2
-rw-r--r--examples/opengl/hellogl2/mainwindow.cpp3
-rw-r--r--examples/opengl/hellogl2/window.cpp8
-rw-r--r--examples/opengl/hellogles3/glwindow.cpp32
-rw-r--r--examples/opengl/hellogles3/glwindow.h26
-rw-r--r--examples/opengl/qopenglwidget/bubble.cpp7
-rw-r--r--examples/opengl/qopenglwidget/bubble.h2
-rw-r--r--examples/opengl/qopenglwidget/glwidget.cpp8
-rw-r--r--examples/opengl/qopenglwidget/glwidget.h46
-rw-r--r--examples/opengl/textures/glwidget.cpp11
-rw-r--r--examples/opengl/textures/glwidget.h14
-rw-r--r--examples/opengl/threadedqopenglwidget/glwidget.cpp7
-rw-r--r--examples/opengl/threadedqopenglwidget/glwidget.h18
-rw-r--r--examples/widgets/dialogs/classwizard/classwizard.cpp4
-rw-r--r--examples/widgets/dialogs/classwizard/classwizard.h12
-rw-r--r--examples/widgets/dialogs/classwizard/main.cpp2
-rw-r--r--examples/widgets/dialogs/extension/finddialog.h2
-rw-r--r--examples/widgets/dialogs/findfiles/window.h2
-rw-r--r--examples/widgets/dialogs/licensewizard/licensewizard.h12
-rw-r--r--examples/widgets/dialogs/licensewizard/main.cpp2
-rw-r--r--examples/widgets/dialogs/standarddialogs/dialog.h2
-rw-r--r--examples/widgets/dialogs/standarddialogs/main.cpp2
-rw-r--r--examples/widgets/dialogs/tabdialog/tabdialog.h8
-rw-r--r--examples/widgets/dialogs/trivialwizard/trivialwizard.cpp2
-rw-r--r--examples/widgets/doc/dropsite.qdoc12
-rw-r--r--examples/widgets/doc/src/calculator.qdoc3
-rw-r--r--examples/widgets/doc/src/collidingmice-example.qdoc3
-rw-r--r--examples/widgets/doc/src/diagramscene.qdoc4
-rw-r--r--examples/widgets/doc/src/tooltips.qdoc2
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsitewindow.cpp21
-rw-r--r--examples/widgets/draganddrop/dropsite/dropsitewindow.h2
-rw-r--r--examples/widgets/effects/blurpicker/blurpicker.h2
-rw-r--r--examples/widgets/effects/fademessage/fademessage.h2
-rw-r--r--examples/widgets/gestures/imagegestures/imagewidget.cpp28
-rw-r--r--examples/widgets/gestures/imagegestures/imagewidget.h10
-rw-r--r--examples/widgets/gestures/imagegestures/main.cpp2
-rw-r--r--examples/widgets/gestures/imagegestures/mainwidget.cpp2
-rw-r--r--examples/widgets/gestures/imagegestures/mainwidget.h4
-rw-r--r--examples/widgets/graphicsview/anchorlayout/main.cpp2
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.cpp31
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h9
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/window.h6
-rw-r--r--examples/widgets/graphicsview/boxes/glbuffers.cpp23
-rw-r--r--examples/widgets/graphicsview/boxes/glbuffers.h37
-rw-r--r--examples/widgets/graphicsview/boxes/gltrianglemesh.h3
-rw-r--r--examples/widgets/graphicsview/boxes/main.cpp12
-rw-r--r--examples/widgets/graphicsview/boxes/qtbox.cpp39
-rw-r--r--examples/widgets/graphicsview/boxes/qtbox.h11
-rw-r--r--examples/widgets/graphicsview/boxes/roundedbox.h12
-rw-r--r--examples/widgets/graphicsview/boxes/scene.cpp78
-rw-r--r--examples/widgets/graphicsview/boxes/scene.h23
-rw-r--r--examples/widgets/graphicsview/boxes/trackball.cpp17
-rw-r--r--examples/widgets/graphicsview/boxes/trackball.h25
-rw-r--r--examples/widgets/graphicsview/chip/chip.cpp4
-rw-r--r--examples/widgets/graphicsview/chip/mainwindow.cpp8
-rw-r--r--examples/widgets/graphicsview/chip/mainwindow.h2
-rw-r--r--examples/widgets/graphicsview/chip/view.cpp2
-rw-r--r--examples/widgets/graphicsview/chip/view.h2
-rw-r--r--examples/widgets/graphicsview/collidingmice/main.cpp5
-rw-r--r--examples/widgets/graphicsview/collidingmice/mouse.cpp12
-rw-r--r--examples/widgets/graphicsview/collidingmice/mouse.h6
-rw-r--r--examples/widgets/graphicsview/diagramscene/arrow.cpp12
-rw-r--r--examples/widgets/graphicsview/diagramscene/arrow.h18
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramitem.cpp18
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramitem.h17
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramscene.cpp12
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramscene.h2
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramtextitem.h6
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/coloritem.cpp14
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/main.cpp13
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/robot.cpp15
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/robot.h22
-rw-r--r--examples/widgets/graphicsview/elasticnodes/edge.cpp8
-rw-r--r--examples/widgets/graphicsview/elasticnodes/edge.h2
-rw-r--r--examples/widgets/graphicsview/elasticnodes/graphwidget.cpp6
-rw-r--r--examples/widgets/graphicsview/elasticnodes/graphwidget.h4
-rw-r--r--examples/widgets/graphicsview/elasticnodes/node.cpp2
-rw-r--r--examples/widgets/graphicsview/elasticnodes/node.h9
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp11
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/customproxy.h6
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h2
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.cpp19
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.h6
-rw-r--r--examples/widgets/graphicsview/flowlayout/main.cpp6
-rw-r--r--examples/widgets/graphicsview/flowlayout/window.cpp16
-rw-r--r--examples/widgets/graphicsview/flowlayout/window.h3
-rw-r--r--examples/widgets/graphicsview/padnavigator/flippablepad.cpp4
-rw-r--r--examples/widgets/graphicsview/padnavigator/flippablepad.h4
-rw-r--r--examples/widgets/graphicsview/padnavigator/padnavigator.cpp14
-rw-r--r--examples/widgets/graphicsview/padnavigator/padnavigator.h7
-rw-r--r--examples/widgets/graphicsview/padnavigator/roundrectitem.cpp4
-rw-r--r--examples/widgets/graphicsview/padnavigator/roundrectitem.h4
-rw-r--r--examples/widgets/graphicsview/padnavigator/splashitem.h4
-rw-r--r--examples/widgets/graphicsview/simpleanchorlayout/main.cpp22
-rw-r--r--examples/widgets/graphicsview/weatheranchorlayout/main.cpp20
-rw-r--r--examples/widgets/itemviews/frozencolumn/main.cpp2
-rw-r--r--examples/widgets/itemviews/interview/model.cpp4
-rw-r--r--examples/widgets/itemviews/stardelegate/main.cpp9
-rw-r--r--examples/widgets/painting/deform/pathdeform.cpp2
-rw-r--r--examples/widgets/painting/fontsampler/mainwindow.h2
-rw-r--r--examples/widgets/painting/gradients/gradients.cpp28
-rw-r--r--examples/widgets/painting/gradients/gradients.h2
-rw-r--r--examples/widgets/painting/gradients/main.cpp4
-rw-r--r--examples/widgets/painting/painterpaths/renderarea.h2
-rw-r--r--examples/widgets/painting/pathstroke/pathstroke.cpp87
-rw-r--r--examples/widgets/painting/pathstroke/pathstroke.h2
-rw-r--r--examples/widgets/painting/shared/arthurstyle.h2
-rw-r--r--examples/widgets/painting/shared/arthurwidgets.cpp4
-rw-r--r--examples/widgets/painting/shared/fbopaintdevice.cpp6
-rw-r--r--examples/widgets/painting/shared/fbopaintdevice.h4
-rw-r--r--examples/widgets/painting/shared/hoverpoints.cpp4
-rw-r--r--examples/widgets/painting/transformations/renderarea.h2
-rw-r--r--examples/widgets/richtext/textedit/textedit.cpp12
-rw-r--r--examples/widgets/scroller/graphicsview/main.cpp2
-rw-r--r--examples/widgets/statemachine/eventtransitions/main.cpp9
-rw-r--r--examples/widgets/statemachine/factorial/main.cpp9
-rw-r--r--examples/widgets/statemachine/trafficlight/main.cpp14
-rw-r--r--examples/widgets/tools/codecs/mainwindow.cpp20
-rw-r--r--examples/widgets/tools/codecs/mainwindow.h6
-rw-r--r--examples/widgets/tools/codecs/previewform.cpp22
-rw-r--r--examples/widgets/tools/codecs/previewform.h4
-rw-r--r--examples/widgets/tools/completer/fsmodel.h2
-rw-r--r--examples/widgets/tools/completer/mainwindow.cpp41
-rw-r--r--examples/widgets/tools/completer/mainwindow.h21
-rw-r--r--examples/widgets/tools/customcompleter/mainwindow.cpp17
-rw-r--r--examples/widgets/tools/customcompleter/mainwindow.h8
-rw-r--r--examples/widgets/tools/customcompleter/textedit.cpp13
-rw-r--r--examples/widgets/tools/customcompleter/textedit.h4
-rw-r--r--examples/widgets/tools/echoplugin/echowindow/echointerface.h3
-rw-r--r--examples/widgets/tools/echoplugin/echowindow/echowindow.cpp14
-rw-r--r--examples/widgets/tools/echoplugin/echowindow/main.cpp2
-rw-r--r--examples/widgets/tools/echoplugin/plugin/echoplugin.cpp2
-rw-r--r--examples/widgets/tools/i18n/languagechooser.cpp41
-rw-r--r--examples/widgets/tools/i18n/languagechooser.h16
-rw-r--r--examples/widgets/tools/i18n/mainwindow.cpp22
-rw-r--r--examples/widgets/tools/i18n/mainwindow.h2
-rw-r--r--examples/widgets/tools/plugandpaint/app/mainwindow.cpp21
-rw-r--r--examples/widgets/tools/plugandpaint/app/paintarea.cpp5
-rw-r--r--examples/widgets/tools/plugandpaint/app/plugindialog.cpp2
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp6
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h8
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp5
-rw-r--r--examples/widgets/tools/regexp/regexpdialog.h2
-rw-r--r--examples/widgets/tools/regularexpression/regularexpressiondialog.h2
-rw-r--r--examples/widgets/tools/settingseditor/locationdialog.cpp17
-rw-r--r--examples/widgets/tools/settingseditor/locationdialog.h2
-rw-r--r--examples/widgets/tools/settingseditor/mainwindow.cpp18
-rw-r--r--examples/widgets/tools/settingseditor/mainwindow.h12
-rw-r--r--examples/widgets/tools/settingseditor/settingstree.cpp36
-rw-r--r--examples/widgets/tools/settingseditor/settingstree.h13
-rw-r--r--examples/widgets/tools/settingseditor/variantdelegate.cpp18
-rw-r--r--examples/widgets/tools/settingseditor/variantdelegate.h6
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyle.cpp2
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyle.h6
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyleplugin.cpp6
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h7
-rw-r--r--examples/widgets/tools/styleplugin/stylewindow/main.cpp3
-rw-r--r--examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp4
-rw-r--r--examples/widgets/tools/treemodelcompleter/mainwindow.cpp53
-rw-r--r--examples/widgets/tools/treemodelcompleter/mainwindow.h22
-rw-r--r--examples/widgets/tools/treemodelcompleter/treemodelcompleter.cpp12
-rw-r--r--examples/widgets/tools/treemodelcompleter/treemodelcompleter.h4
-rw-r--r--examples/widgets/tools/undo/commands.cpp36
-rw-r--r--examples/widgets/tools/undo/commands.h14
-rw-r--r--examples/widgets/tools/undo/document.cpp30
-rw-r--r--examples/widgets/tools/undo/document.h15
-rw-r--r--examples/widgets/tools/undo/mainwindow.cpp53
-rw-r--r--examples/widgets/tools/undo/mainwindow.h2
-rw-r--r--examples/widgets/tools/undoframework/commands.cpp20
-rw-r--r--examples/widgets/tools/undoframework/commands.h6
-rw-r--r--examples/widgets/tools/undoframework/diagramitem.cpp9
-rw-r--r--examples/widgets/tools/undoframework/diagramitem.h5
-rw-r--r--examples/widgets/tools/undoframework/diagramscene.cpp17
-rw-r--r--examples/widgets/tools/undoframework/diagramscene.h4
-rw-r--r--examples/widgets/tools/undoframework/main.cpp2
-rw-r--r--examples/widgets/tools/undoframework/mainwindow.cpp9
-rw-r--r--examples/widgets/tools/undoframework/mainwindow.h28
-rw-r--r--examples/widgets/touch/fingerpaint/scribblearea.h2
-rw-r--r--examples/widgets/touch/pinchzoom/graphicsview.cpp6
-rw-r--r--examples/widgets/touch/pinchzoom/graphicsview.h4
-rw-r--r--examples/widgets/touch/pinchzoom/main.cpp7
-rw-r--r--examples/widgets/touch/pinchzoom/mouse.cpp10
-rw-r--r--examples/widgets/touch/pinchzoom/mouse.h6
-rw-r--r--examples/widgets/tutorials/addressbook/part1/addressbook.h2
-rw-r--r--examples/widgets/tutorials/addressbook/part2/addressbook.h2
-rw-r--r--examples/widgets/tutorials/addressbook/part3/addressbook.h2
-rw-r--r--examples/widgets/tutorials/addressbook/part4/addressbook.h2
-rw-r--r--examples/widgets/tutorials/addressbook/part5/addressbook.h2
-rw-r--r--examples/widgets/tutorials/addressbook/part5/finddialog.h2
-rw-r--r--examples/widgets/tutorials/addressbook/part6/addressbook.h2
-rw-r--r--examples/widgets/tutorials/addressbook/part6/finddialog.h2
-rw-r--r--examples/widgets/tutorials/addressbook/part7/addressbook.h2
-rw-r--r--examples/widgets/tutorials/addressbook/part7/finddialog.h2
-rw-r--r--examples/widgets/tutorials/modelview/3_changingmodel/main.cpp2
-rw-r--r--examples/widgets/tutorials/modelview/7_selections/mainwindow.h2
-rw-r--r--examples/widgets/tutorials/notepad/notepad.h2
-rw-r--r--examples/widgets/widgets/analogclock/analogclock.cpp4
-rw-r--r--examples/widgets/widgets/calculator/button.cpp2
-rw-r--r--examples/widgets/widgets/calculator/calculator.cpp22
-rw-r--r--examples/widgets/widgets/calendarwidget/main.cpp2
-rw-r--r--examples/widgets/widgets/calendarwidget/window.cpp19
-rw-r--r--examples/widgets/widgets/charactermap/characterwidget.cpp37
-rw-r--r--examples/widgets/widgets/charactermap/characterwidget.h6
-rw-r--r--examples/widgets/widgets/charactermap/mainwindow.cpp22
-rw-r--r--examples/widgets/widgets/codeeditor/codeeditor.cpp11
-rw-r--r--examples/widgets/widgets/codeeditor/codeeditor.h13
-rw-r--r--examples/widgets/widgets/codeeditor/main.cpp2
-rw-r--r--examples/widgets/widgets/digitalclock/digitalclock.cpp3
-rw-r--r--examples/widgets/widgets/groupbox/window.cpp9
-rw-r--r--examples/widgets/widgets/icons/iconpreviewarea.cpp3
-rw-r--r--examples/widgets/widgets/icons/iconsizespinbox.cpp2
-rw-r--r--examples/widgets/widgets/icons/imagedelegate.cpp2
-rw-r--r--examples/widgets/widgets/icons/mainwindow.cpp23
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.cpp23
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.h2
-rw-r--r--examples/widgets/widgets/lineedits/window.cpp13
-rw-r--r--examples/widgets/widgets/movie/movieplayer.cpp10
-rw-r--r--examples/widgets/widgets/scribble/mainwindow.cpp27
-rw-r--r--examples/widgets/widgets/scribble/scribblearea.cpp11
-rw-r--r--examples/widgets/widgets/scribble/scribblearea.h8
-rw-r--r--examples/widgets/widgets/shapedclock/shapedclock.cpp9
-rw-r--r--examples/widgets/widgets/sliders/slidersgroup.cpp5
-rw-r--r--examples/widgets/widgets/sliders/window.cpp9
-rw-r--r--examples/widgets/widgets/spinboxes/window.cpp10
-rw-r--r--examples/widgets/widgets/styles/norwegianwoodstyle.cpp5
-rw-r--r--examples/widgets/widgets/styles/widgetgallery.cpp19
-rw-r--r--examples/widgets/widgets/stylesheet/main.cpp2
-rw-r--r--examples/widgets/widgets/stylesheet/mainwindow.cpp4
-rw-r--r--examples/widgets/widgets/stylesheet/mainwindow.h2
-rw-r--r--examples/widgets/widgets/stylesheet/stylesheeteditor.cpp4
-rw-r--r--examples/widgets/widgets/tablet/main.cpp2
-rw-r--r--examples/widgets/widgets/tablet/mainwindow.cpp11
-rw-r--r--examples/widgets/widgets/tablet/mainwindow.h2
-rw-r--r--examples/widgets/widgets/tablet/tabletapplication.cpp2
-rw-r--r--examples/widgets/widgets/tablet/tabletcanvas.cpp29
-rw-r--r--examples/widgets/widgets/tablet/tabletcanvas.h25
-rw-r--r--examples/widgets/widgets/tetrix/tetrixboard.cpp10
-rw-r--r--examples/widgets/widgets/tetrix/tetrixpiece.cpp2
-rw-r--r--examples/widgets/widgets/tetrix/tetrixwindow.cpp15
-rw-r--r--examples/widgets/widgets/tooltips/main.cpp2
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.cpp14
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.h2
-rw-r--r--examples/widgets/widgets/validators/validatorwidget.cpp2
-rw-r--r--examples/widgets/widgets/wiggly/wigglywidget.cpp9
-rw-r--r--examples/widgets/widgets/windowflags/controllerwindow.cpp30
-rw-r--r--examples/widgets/widgets/windowflags/previewwindow.cpp21
-rw-r--r--examples/widgets/windowcontainer/windowcontainer.cpp53
262 files changed, 1451 insertions, 1442 deletions
diff --git a/examples/embedded/flickable/flickable.cpp b/examples/embedded/flickable/flickable.cpp
index fff4bac0e6..c57ec3d111 100644
--- a/examples/embedded/flickable/flickable.cpp
+++ b/examples/embedded/flickable/flickable.cpp
@@ -98,7 +98,7 @@ public:
QPoint delta;
QPoint speed;
FlickableTicker *ticker;
- QTime timeStamp;
+ QElapsedTimer timeStamp;
QWidget *target;
QList<QEvent*> ignoreList;
};
@@ -109,7 +109,7 @@ Flickable::Flickable()
d->state = FlickablePrivate::Steady;
d->threshold = 10;
d->ticker = new FlickableTicker(this);
- d->timeStamp = QTime::currentTime();
+ d->timeStamp.start();
d->target = 0;
}
@@ -208,7 +208,7 @@ void Flickable::handleMouseRelease(QMouseEvent *event)
event->accept();
delta = event->pos() - d->pressPos;
if (d->timeStamp.elapsed() > 100) {
- d->timeStamp = QTime::currentTime();
+ d->timeStamp.start();
d->speed = delta - d->delta;
d->delta = delta;
}
@@ -253,7 +253,7 @@ void Flickable::handleMouseMove(QMouseEvent *event)
delta = event->pos() - d->pressPos;
if (delta.x() > d->threshold || delta.x() < -d->threshold ||
delta.y() > d->threshold || delta.y() < -d->threshold) {
- d->timeStamp = QTime::currentTime();
+ d->timeStamp.start();
d->state = FlickablePrivate::ManualScroll;
d->delta = QPoint(0, 0);
d->pressPos = event->pos();
@@ -266,7 +266,7 @@ void Flickable::handleMouseMove(QMouseEvent *event)
delta = event->pos() - d->pressPos;
setScrollOffset(d->offset - delta);
if (d->timeStamp.elapsed() > 100) {
- d->timeStamp = QTime::currentTime();
+ d->timeStamp.start();
d->speed = delta - d->delta;
d->delta = delta;
}
diff --git a/examples/embedded/raycasting/raycasting.cpp b/examples/embedded/raycasting/raycasting.cpp
index 7213811213..c0a1e48fa6 100644
--- a/examples/embedded/raycasting/raycasting.cpp
+++ b/examples/embedded/raycasting/raycasting.cpp
@@ -92,7 +92,7 @@ public:
}
void updatePlayer() {
- int interval = qBound(20, watch.elapsed(), 250);
+ int interval = qBound(20ll, watch.elapsed(), 250ll);
watch.start();
angle += angleDelta * interval / 1000;
qreal step = moveDelta * interval / 1000;
@@ -106,10 +106,10 @@ public:
}
void showFps() {
- static QTime frameTick;
+ static QElapsedTimer frameTick;
static int totalFrame = 0;
if (!(totalFrame & 31)) {
- int elapsed = frameTick.elapsed();
+ const qint64 elapsed = frameTick.elapsed();
frameTick.start();
int fps = 32 * 1000 / (1 + elapsed);
setWindowTitle(QString("Raycasting (%1 FPS)").arg(fps));
@@ -355,7 +355,7 @@ protected:
}
private:
- QTime watch;
+ QElapsedTimer watch;
QBasicTimer ticker;
QImage buffer;
qreal angle;
diff --git a/examples/gui/openglwindow/main.cpp b/examples/gui/openglwindow/main.cpp
index 90c93f0d37..03a6ece06f 100644
--- a/examples/gui/openglwindow/main.cpp
+++ b/examples/gui/openglwindow/main.cpp
@@ -50,36 +50,30 @@
#include "openglwindow.h"
-#include <QtGui/QGuiApplication>
-#include <QtGui/QMatrix4x4>
-#include <QtGui/QOpenGLShaderProgram>
-#include <QtGui/QScreen>
+#include <QGuiApplication>
+#include <QMatrix4x4>
+#include <QOpenGLShaderProgram>
+#include <QScreen>
+#include <QtMath>
-#include <QtCore/qmath.h>
//! [1]
class TriangleWindow : public OpenGLWindow
{
public:
- TriangleWindow();
+ using OpenGLWindow::OpenGLWindow;
void initialize() override;
void render() override;
private:
- GLuint m_posAttr;
- GLuint m_colAttr;
- GLuint m_matrixUniform;
+ GLint m_posAttr = 0;
+ GLint m_colAttr = 0;
+ GLint m_matrixUniform = 0;
- QOpenGLShaderProgram *m_program;
- int m_frame;
+ QOpenGLShaderProgram *m_program = nullptr;
+ int m_frame = 0;
};
-
-TriangleWindow::TriangleWindow()
- : m_program(0)
- , m_frame(0)
-{
-}
//! [1]
//! [2]
@@ -128,8 +122,11 @@ void TriangleWindow::initialize()
m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
m_program->link();
m_posAttr = m_program->attributeLocation("posAttr");
+ Q_ASSERT(m_posAttr != -1);
m_colAttr = m_program->attributeLocation("colAttr");
+ Q_ASSERT(m_colAttr != -1);
m_matrixUniform = m_program->uniformLocation("matrix");
+ Q_ASSERT(m_matrixUniform != -1);
}
//! [4]
@@ -144,19 +141,19 @@ void TriangleWindow::render()
m_program->bind();
QMatrix4x4 matrix;
- matrix.perspective(60.0f, 4.0f/3.0f, 0.1f, 100.0f);
+ matrix.perspective(60.0f, 4.0f / 3.0f, 0.1f, 100.0f);
matrix.translate(0, 0, -2);
matrix.rotate(100.0f * m_frame / screen()->refreshRate(), 0, 1, 0);
m_program->setUniformValue(m_matrixUniform, matrix);
- GLfloat vertices[] = {
- 0.0f, 0.707f,
+ static const GLfloat vertices[] = {
+ 0.0f, 0.707f,
-0.5f, -0.5f,
- 0.5f, -0.5f
+ 0.5f, -0.5f
};
- GLfloat colors[] = {
+ static const GLfloat colors[] = {
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f
@@ -165,13 +162,13 @@ void TriangleWindow::render()
glVertexAttribPointer(m_posAttr, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glVertexAttribPointer(m_colAttr, 3, GL_FLOAT, GL_FALSE, 0, colors);
- glEnableVertexAttribArray(0);
- glEnableVertexAttribArray(1);
+ glEnableVertexAttribArray(m_posAttr);
+ glEnableVertexAttribArray(m_colAttr);
glDrawArrays(GL_TRIANGLES, 0, 3);
- glDisableVertexAttribArray(1);
- glDisableVertexAttribArray(0);
+ glDisableVertexAttribArray(m_colAttr);
+ glDisableVertexAttribArray(m_posAttr);
m_program->release();
diff --git a/examples/gui/openglwindow/openglwindow.cpp b/examples/gui/openglwindow/openglwindow.cpp
index a0c85006bd..bac887dca0 100644
--- a/examples/gui/openglwindow/openglwindow.cpp
+++ b/examples/gui/openglwindow/openglwindow.cpp
@@ -50,18 +50,13 @@
#include "openglwindow.h"
-#include <QtCore/QCoreApplication>
-
-#include <QtGui/QOpenGLContext>
-#include <QtGui/QOpenGLPaintDevice>
-#include <QtGui/QPainter>
+#include <QOpenGLContext>
+#include <QOpenGLPaintDevice>
+#include <QPainter>
//! [1]
OpenGLWindow::OpenGLWindow(QWindow *parent)
: QWindow(parent)
- , m_animating(false)
- , m_context(0)
- , m_device(0)
{
setSurfaceType(QWindow::OpenGLSurface);
}
diff --git a/examples/gui/openglwindow/openglwindow.h b/examples/gui/openglwindow/openglwindow.h
index 6e6c1d7449..8db943ddde 100644
--- a/examples/gui/openglwindow/openglwindow.h
+++ b/examples/gui/openglwindow/openglwindow.h
@@ -48,8 +48,8 @@
**
****************************************************************************/
-#include <QtGui/QWindow>
-#include <QtGui/QOpenGLFunctions>
+#include <QWindow>
+#include <QOpenGLFunctions>
QT_BEGIN_NAMESPACE
class QPainter;
@@ -62,7 +62,7 @@ class OpenGLWindow : public QWindow, protected QOpenGLFunctions
{
Q_OBJECT
public:
- explicit OpenGLWindow(QWindow *parent = 0);
+ explicit OpenGLWindow(QWindow *parent = nullptr);
~OpenGLWindow();
virtual void render(QPainter *painter);
@@ -82,10 +82,10 @@ protected:
void exposeEvent(QExposeEvent *event) override;
private:
- bool m_animating;
+ bool m_animating = false;
- QOpenGLContext *m_context;
- QOpenGLPaintDevice *m_device;
+ QOpenGLContext *m_context = nullptr;
+ QOpenGLPaintDevice *m_device = nullptr;
};
//! [1]
diff --git a/examples/opengl/computegles31/glwindow.cpp b/examples/opengl/computegles31/glwindow.cpp
index 7a14cba66d..2194137cfd 100644
--- a/examples/opengl/computegles31/glwindow.cpp
+++ b/examples/opengl/computegles31/glwindow.cpp
@@ -73,15 +73,6 @@
#endif
GLWindow::GLWindow()
- : m_texImageInput(0),
- m_texImageTmp(0),
- m_texImageProcessed(0),
- m_shaderDisplay(0),
- m_shaderComputeV(0),
- m_shaderComputeH(0),
- m_blurRadius(0.0f),
- m_animate(true),
- m_vao(0)
{
const float animationStart = 0.0;
const float animationEnd = 10.0;
@@ -324,27 +315,18 @@ void GLWindow::initializeGL()
<< ((ctx->format().renderableType() == QSurfaceFormat::OpenGLES) ? (" GLES") : (" GL"))
<< " context";
- if (m_texImageInput) {
- delete m_texImageInput;
- m_texImageInput = 0;
- }
QImage img(":/Qt-logo-medium.png");
Q_ASSERT(!img.isNull());
+ delete m_texImageInput;
m_texImageInput = new QOpenGLTexture(img.convertToFormat(QImage::Format_RGBA8888).mirrored());
- if (m_texImageTmp) {
- delete m_texImageTmp;
- m_texImageTmp = 0;
- }
+ delete m_texImageTmp;
m_texImageTmp = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_texImageTmp->setFormat(m_texImageInput->format());
m_texImageTmp->setSize(m_texImageInput->width(),m_texImageInput->height());
m_texImageTmp->allocateStorage(QOpenGLTexture::RGBA,QOpenGLTexture::UInt8); // WTF?
- if (m_texImageProcessed) {
- delete m_texImageProcessed;
- m_texImageProcessed = 0;
- }
+ delete m_texImageProcessed;
m_texImageProcessed = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_texImageProcessed->setFormat(m_texImageInput->format());
m_texImageProcessed->setSize(m_texImageInput->width(),m_texImageInput->height());
@@ -354,10 +336,7 @@ void GLWindow::initializeGL()
m_texImageProcessed->setMinificationFilter(QOpenGLTexture::Linear);
m_texImageProcessed->setWrapMode(QOpenGLTexture::ClampToEdge);
- if (m_shaderDisplay) {
- delete m_shaderDisplay;
- m_shaderDisplay = 0;
- }
+ delete m_shaderDisplay;
m_shaderDisplay = new QOpenGLShaderProgram;
// Prepend the correct version directive to the sources. The rest is the
// same, thanks to the common GLSL syntax.
@@ -365,18 +344,12 @@ void GLWindow::initializeGL()
m_shaderDisplay->addShaderFromSourceCode(QOpenGLShader::Fragment, versionedShaderCode(fsDisplaySource));
m_shaderDisplay->link();
- if (m_shaderComputeV) {
- delete m_shaderComputeV;
- m_shaderComputeV = 0;
- }
+ delete m_shaderComputeV;
m_shaderComputeV = new QOpenGLShaderProgram;
m_shaderComputeV->addShaderFromSourceCode(QOpenGLShader::Compute, versionedShaderCode(csComputeSourceV));
m_shaderComputeV->link();
- if (m_shaderComputeH) {
- delete m_shaderComputeH;
- m_shaderComputeH = 0;
- }
+ delete m_shaderComputeH;
m_shaderComputeH = new QOpenGLShaderProgram;
m_shaderComputeH->addShaderFromSourceCode(QOpenGLShader::Compute, versionedShaderCode(csComputeSourceH));
m_shaderComputeH->link();
diff --git a/examples/opengl/computegles31/glwindow.h b/examples/opengl/computegles31/glwindow.h
index f243858a45..5375fbb488 100644
--- a/examples/opengl/computegles31/glwindow.h
+++ b/examples/opengl/computegles31/glwindow.h
@@ -90,21 +90,21 @@ protected:
void setAnimating(bool animate);
private:
- QPropertyAnimation *m_animationForward;
- QPropertyAnimation *m_animationBackward;
+ QPropertyAnimation *m_animationForward = nullptr;
+ QPropertyAnimation *m_animationBackward = nullptr;
QSequentialAnimationGroup *m_animationGroup;
- QOpenGLTexture *m_texImageInput;
- QOpenGLTexture *m_texImageTmp;
- QOpenGLTexture *m_texImageProcessed;
- QOpenGLShaderProgram *m_shaderDisplay;
- QOpenGLShaderProgram *m_shaderComputeV;
- QOpenGLShaderProgram *m_shaderComputeH;
+ QOpenGLTexture *m_texImageInput = nullptr;
+ QOpenGLTexture *m_texImageTmp = nullptr;
+ QOpenGLTexture *m_texImageProcessed = nullptr;
+ QOpenGLShaderProgram *m_shaderDisplay = nullptr;
+ QOpenGLShaderProgram *m_shaderComputeV = nullptr;
+ QOpenGLShaderProgram *m_shaderComputeH = nullptr;
QMatrix4x4 m_proj;
QSizeF m_quadSize;
- int m_blurRadius;
- bool m_animate;
- QOpenGLVertexArrayObject *m_vao;
+ int m_blurRadius = 0;
+ bool m_animate = true;
+ QOpenGLVertexArrayObject *m_vao = nullptr;
};
#endif
diff --git a/examples/opengl/contextinfo/renderwindow.cpp b/examples/opengl/contextinfo/renderwindow.cpp
index 21b7434be6..ea9a7a24cb 100644
--- a/examples/opengl/contextinfo/renderwindow.cpp
+++ b/examples/opengl/contextinfo/renderwindow.cpp
@@ -56,7 +56,7 @@
#include <QOpenGLFunctions>
RenderWindow::RenderWindow(const QSurfaceFormat &format)
- : m_context(0),
+ : m_context(nullptr),
m_initialized(false),
m_forceGLSL110(false),
m_angle(0.0f)
@@ -67,7 +67,7 @@ RenderWindow::RenderWindow(const QSurfaceFormat &format)
m_context->setFormat(requestedFormat());
if (!m_context->create()) {
delete m_context;
- m_context = 0;
+ m_context = nullptr;
}
}
diff --git a/examples/opengl/contextinfo/widget.h b/examples/opengl/contextinfo/widget.h
index 72abe0e647..85d181a229 100644
--- a/examples/opengl/contextinfo/widget.h
+++ b/examples/opengl/contextinfo/widget.h
@@ -64,7 +64,7 @@ class Widget : public QWidget
Q_OBJECT
public:
- explicit Widget(QWidget *parent = 0);
+ explicit Widget(QWidget *parent = nullptr);
private slots:
void start();
diff --git a/examples/opengl/cube/geometryengine.cpp b/examples/opengl/cube/geometryengine.cpp
index 1f9e16a935..24e014201e 100644
--- a/examples/opengl/cube/geometryengine.cpp
+++ b/examples/opengl/cube/geometryengine.cpp
@@ -174,6 +174,6 @@ void GeometryEngine::drawCubeGeometry(QOpenGLShaderProgram *program)
program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData));
// Draw cube geometry using indices from VBO 1
- glDrawElements(GL_TRIANGLE_STRIP, 34, GL_UNSIGNED_SHORT, 0);
+ glDrawElements(GL_TRIANGLE_STRIP, 34, GL_UNSIGNED_SHORT, nullptr);
}
//! [2]
diff --git a/examples/opengl/cube/mainwidget.cpp b/examples/opengl/cube/mainwidget.cpp
index 292a4245fa..558ecd1299 100644
--- a/examples/opengl/cube/mainwidget.cpp
+++ b/examples/opengl/cube/mainwidget.cpp
@@ -52,15 +52,7 @@
#include <QMouseEvent>
-#include <math.h>
-
-MainWidget::MainWidget(QWidget *parent) :
- QOpenGLWidget(parent),
- geometries(0),
- texture(0),
- angularSpeed(0)
-{
-}
+#include <cmath>
MainWidget::~MainWidget()
{
diff --git a/examples/opengl/cube/mainwidget.h b/examples/opengl/cube/mainwidget.h
index cd2f8098ad..b6a03d454a 100644
--- a/examples/opengl/cube/mainwidget.h
+++ b/examples/opengl/cube/mainwidget.h
@@ -69,7 +69,7 @@ class MainWidget : public QOpenGLWidget, protected QOpenGLFunctions
Q_OBJECT
public:
- explicit MainWidget(QWidget *parent = 0);
+ using QOpenGLWidget::QOpenGLWidget;
~MainWidget();
protected:
@@ -87,15 +87,15 @@ protected:
private:
QBasicTimer timer;
QOpenGLShaderProgram program;
- GeometryEngine *geometries;
+ GeometryEngine *geometries = nullptr;
- QOpenGLTexture *texture;
+ QOpenGLTexture *texture = nullptr;
QMatrix4x4 projection;
QVector2D mousePressPosition;
QVector3D rotationAxis;
- qreal angularSpeed;
+ qreal angularSpeed = 0;
QQuaternion rotation;
};
diff --git a/examples/opengl/hellogl2/glwidget.cpp b/examples/opengl/hellogl2/glwidget.cpp
index 318adb5043..543e70f8ac 100644
--- a/examples/opengl/hellogl2/glwidget.cpp
+++ b/examples/opengl/hellogl2/glwidget.cpp
@@ -57,11 +57,7 @@
bool GLWidget::m_transparent = false;
GLWidget::GLWidget(QWidget *parent)
- : QOpenGLWidget(parent),
- m_xRot(0),
- m_yRot(0),
- m_zRot(0),
- m_program(0)
+ : QOpenGLWidget(parent)
{
m_core = QSurfaceFormat::defaultFormat().profile() == QSurfaceFormat::CoreProfile;
// --transparent causes the clear color to be transparent. Therefore, on systems that
@@ -133,7 +129,7 @@ void GLWidget::cleanup()
makeCurrent();
m_logoVbo.destroy();
delete m_program;
- m_program = 0;
+ m_program = nullptr;
doneCurrent();
}
@@ -250,8 +246,10 @@ void GLWidget::setupVertexAttribs()
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
f->glEnableVertexAttribArray(0);
f->glEnableVertexAttribArray(1);
- f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0);
- f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), reinterpret_cast<void *>(3 * sizeof(GLfloat)));
+ f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
+ nullptr);
+ f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
+ reinterpret_cast<void *>(3 * sizeof(GLfloat)));
m_logoVbo.release();
}
diff --git a/examples/opengl/hellogl2/glwidget.h b/examples/opengl/hellogl2/glwidget.h
index 21dd200dc7..f8526fb7ae 100644
--- a/examples/opengl/hellogl2/glwidget.h
+++ b/examples/opengl/hellogl2/glwidget.h
@@ -65,7 +65,7 @@ class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
Q_OBJECT
public:
- GLWidget(QWidget *parent = 0);
+ GLWidget(QWidget *parent = nullptr);
~GLWidget();
static bool isTransparent() { return m_transparent; }
@@ -96,18 +96,18 @@ private:
void setupVertexAttribs();
bool m_core;
- int m_xRot;
- int m_yRot;
- int m_zRot;
+ int m_xRot = 0;
+ int m_yRot = 0;
+ int m_zRot = 0;
QPoint m_lastPos;
Logo m_logo;
QOpenGLVertexArrayObject m_vao;
QOpenGLBuffer m_logoVbo;
- QOpenGLShaderProgram *m_program;
- int m_projMatrixLoc;
- int m_mvMatrixLoc;
- int m_normalMatrixLoc;
- int m_lightPosLoc;
+ QOpenGLShaderProgram *m_program = nullptr;
+ int m_projMatrixLoc = 0;
+ int m_mvMatrixLoc = 0;
+ int m_normalMatrixLoc = 0;
+ int m_lightPosLoc = 0;
QMatrix4x4 m_proj;
QMatrix4x4 m_camera;
QMatrix4x4 m_world;
diff --git a/examples/opengl/hellogl2/logo.cpp b/examples/opengl/hellogl2/logo.cpp
index a1ec8eaebe..6fcece16d4 100644
--- a/examples/opengl/hellogl2/logo.cpp
+++ b/examples/opengl/hellogl2/logo.cpp
@@ -52,7 +52,6 @@
#include <qmath.h>
Logo::Logo()
- : m_count(0)
{
m_data.resize(2500 * 6);
diff --git a/examples/opengl/hellogl2/logo.h b/examples/opengl/hellogl2/logo.h
index 9e04a57e86..2f3dc7e649 100644
--- a/examples/opengl/hellogl2/logo.h
+++ b/examples/opengl/hellogl2/logo.h
@@ -69,7 +69,7 @@ private:
void add(const QVector3D &v, const QVector3D &n);
QVector<GLfloat> m_data;
- int m_count;
+ int m_count = 0;
};
#endif // LOGO_H
diff --git a/examples/opengl/hellogl2/mainwindow.cpp b/examples/opengl/hellogl2/mainwindow.cpp
index 6bfdee7785..aa20cd678c 100644
--- a/examples/opengl/hellogl2/mainwindow.cpp
+++ b/examples/opengl/hellogl2/mainwindow.cpp
@@ -72,5 +72,6 @@ void MainWindow::onAddNew()
if (!centralWidget())
setCentralWidget(new Window(this));
else
- QMessageBox::information(0, tr("Cannot add new window"), tr("Already occupied. Undock first."));
+ QMessageBox::information(nullptr, tr("Cannot add new window"),
+ tr("Already occupied. Undock first."));
}
diff --git a/examples/opengl/hellogl2/window.cpp b/examples/opengl/hellogl2/window.cpp
index c3cd10cbfd..5534f2edea 100644
--- a/examples/opengl/hellogl2/window.cpp
+++ b/examples/opengl/hellogl2/window.cpp
@@ -121,7 +121,7 @@ void Window::keyPressEvent(QKeyEvent *e)
void Window::dockUndock()
{
if (parent()) {
- setParent(0);
+ setParent(nullptr);
setAttribute(Qt::WA_DeleteOnClose);
move(QApplication::desktop()->width() / 2 - width() / 2,
QApplication::desktop()->height() / 2 - height() / 2);
@@ -134,10 +134,12 @@ void Window::dockUndock()
dockBtn->setText(tr("Undock"));
mainWindow->setCentralWidget(this);
} else {
- QMessageBox::information(0, tr("Cannot dock"), tr("Main window already closed"));
+ QMessageBox::information(nullptr, tr("Cannot dock"),
+ tr("Main window already closed"));
}
} else {
- QMessageBox::information(0, tr("Cannot dock"), tr("Main window already occupied"));
+ QMessageBox::information(nullptr, tr("Cannot dock"),
+ tr("Main window already occupied"));
}
}
}
diff --git a/examples/opengl/hellogles3/glwindow.cpp b/examples/opengl/hellogles3/glwindow.cpp
index 9458b74810..c644faa9a6 100644
--- a/examples/opengl/hellogles3/glwindow.cpp
+++ b/examples/opengl/hellogles3/glwindow.cpp
@@ -57,19 +57,10 @@
#include <QOpenGLVertexArrayObject>
#include <QOpenGLExtraFunctions>
#include <QPropertyAnimation>
-#include <QPauseAnimation>
#include <QSequentialAnimationGroup>
#include <QTimer>
GLWindow::GLWindow()
- : m_texture(0),
- m_program(0),
- m_vbo(0),
- m_vao(0),
- m_target(0, 0, -1),
- m_uniformsDirty(true),
- m_r(0),
- m_r2(0)
{
m_world.setToIdentity();
m_world.translate(0, 0, -1);
@@ -197,18 +188,12 @@ void GLWindow::initializeGL()
{
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
- if (m_texture) {
- delete m_texture;
- m_texture = 0;
- }
QImage img(":/qtlogo.png");
Q_ASSERT(!img.isNull());
+ delete m_texture;
m_texture = new QOpenGLTexture(img.scaled(32, 36).mirrored());
- if (m_program) {
- delete m_program;
- m_program = 0;
- }
+ delete m_program;
m_program = new QOpenGLShaderProgram;
// Prepend the correct version directive to the sources. The rest is the
// same, thanks to the common GLSL syntax.
@@ -223,26 +208,21 @@ void GLWindow::initializeGL()
m_lightPosLoc = m_program->uniformLocation("lightPos");
// Create a VAO. Not strictly required for ES 3, but it is for plain OpenGL.
- if (m_vao) {
- delete m_vao;
- m_vao = 0;
- }
+ delete m_vao;
m_vao = new QOpenGLVertexArrayObject;
if (m_vao->create())
m_vao->bind();
- if (m_vbo) {
- delete m_vbo;
- m_vbo = 0;
- }
m_program->bind();
+ delete m_vbo;
m_vbo = new QOpenGLBuffer;
m_vbo->create();
m_vbo->bind();
m_vbo->allocate(m_logo.constData(), m_logo.count() * sizeof(GLfloat));
f->glEnableVertexAttribArray(0);
f->glEnableVertexAttribArray(1);
- f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0);
+ f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
+ nullptr);
f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
reinterpret_cast<void *>(3 * sizeof(GLfloat)));
m_vbo->release();
diff --git a/examples/opengl/hellogles3/glwindow.h b/examples/opengl/hellogles3/glwindow.h
index fba997bee4..dfa0680714 100644
--- a/examples/opengl/hellogles3/glwindow.h
+++ b/examples/opengl/hellogles3/glwindow.h
@@ -90,23 +90,23 @@ public:
private slots:
void startSecondStage();
private:
- QOpenGLTexture *m_texture;
- QOpenGLShaderProgram *m_program;
- QOpenGLBuffer *m_vbo;
- QOpenGLVertexArrayObject *m_vao;
+ QOpenGLTexture *m_texture = nullptr;
+ QOpenGLShaderProgram *m_program = nullptr;
+ QOpenGLBuffer *m_vbo = nullptr;
+ QOpenGLVertexArrayObject *m_vao = nullptr;
Logo m_logo;
- int m_projMatrixLoc;
- int m_camMatrixLoc;
- int m_worldMatrixLoc;
- int m_myMatrixLoc;
- int m_lightPosLoc;
+ int m_projMatrixLoc = 0;
+ int m_camMatrixLoc = 0;
+ int m_worldMatrixLoc = 0;
+ int m_myMatrixLoc = 0;
+ int m_lightPosLoc = 0;
QMatrix4x4 m_proj;
QMatrix4x4 m_world;
QVector3D m_eye;
- QVector3D m_target;
- bool m_uniformsDirty;
- float m_r;
- float m_r2;
+ QVector3D m_target = {0, 0, -1};
+ bool m_uniformsDirty = true;
+ float m_r = 0;
+ float m_r2 = 0;
};
#endif
diff --git a/examples/opengl/qopenglwidget/bubble.cpp b/examples/opengl/qopenglwidget/bubble.cpp
index dbaf460f6f..7e69aac3e7 100644
--- a/examples/opengl/qopenglwidget/bubble.cpp
+++ b/examples/opengl/qopenglwidget/bubble.cpp
@@ -57,15 +57,13 @@ Bubble::Bubble(const QPointF &position, qreal radius, const QPointF &velocity)
{
innerColor = randomColor();
outerColor = randomColor();
- cache = 0;
updateBrush();
}
//! [0]
void Bubble::updateCache()
{
- if (cache)
- delete cache;
+ delete cache;
cache = new QImage(qRound(radius * 2 + 2), qRound(radius * 2 + 2), QImage::Format_ARGB32_Premultiplied);
cache->fill(0x00000000);
QPainter p(cache);
@@ -80,8 +78,7 @@ void Bubble::updateCache()
Bubble::~Bubble()
{
- if (cache)
- delete cache;
+ delete cache;
}
void Bubble::updateBrush()
diff --git a/examples/opengl/qopenglwidget/bubble.h b/examples/opengl/qopenglwidget/bubble.h
index 7170803b40..833ea02288 100644
--- a/examples/opengl/qopenglwidget/bubble.h
+++ b/examples/opengl/qopenglwidget/bubble.h
@@ -80,7 +80,7 @@ private:
qreal radius;
QColor innerColor;
QColor outerColor;
- QImage *cache;
+ QImage *cache = nullptr;
};
#endif
diff --git a/examples/opengl/qopenglwidget/glwidget.cpp b/examples/opengl/qopenglwidget/glwidget.cpp
index 5057291f12..89c8469662 100644
--- a/examples/opengl/qopenglwidget/glwidget.cpp
+++ b/examples/opengl/qopenglwidget/glwidget.cpp
@@ -68,14 +68,6 @@ const int bubbleNum = 8;
GLWidget::GLWidget(MainWindow *mw, bool button, const QColor &background)
: m_mainWindow(mw),
- m_showBubbles(true),
- m_qtLogo(true),
- m_frames(0),
- m_program1(0),
- m_program2(0),
- m_texture(0),
- m_transparent(false),
- m_btn(0),
m_hasButton(button),
m_background(background)
{
diff --git a/examples/opengl/qopenglwidget/glwidget.h b/examples/opengl/qopenglwidget/glwidget.h
index 0ad2581cb8..99288261c0 100644
--- a/examples/opengl/qopenglwidget/glwidget.h
+++ b/examples/opengl/qopenglwidget/glwidget.h
@@ -98,34 +98,34 @@ private:
void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
MainWindow *m_mainWindow;
- qreal m_fAngle;
- qreal m_fScale;
- bool m_showBubbles;
+ qreal m_fAngle = 0;
+ qreal m_fScale = 1;
+ bool m_showBubbles = true;
QVector<QVector3D> m_vertices;
QVector<QVector3D> m_normals;
- bool m_qtLogo;
- QList<Bubble *> m_bubbles;
- int m_frames;
+ bool m_qtLogo = true;
+ QVector<Bubble *> m_bubbles;
+ int m_frames = 0;
QElapsedTimer m_time;
- QOpenGLShader *m_vshader1;
- QOpenGLShader *m_fshader1;
- QOpenGLShader *m_vshader2;
- QOpenGLShader *m_fshader2;
- QOpenGLShaderProgram *m_program1;
- QOpenGLShaderProgram *m_program2;
- QOpenGLTexture *m_texture;
+ QOpenGLShader *m_vshader1 = nullptr;
+ QOpenGLShader *m_fshader1 = nullptr;
+ QOpenGLShader *m_vshader2 = nullptr;
+ QOpenGLShader *m_fshader2 = nullptr;
+ QOpenGLShaderProgram *m_program1 = nullptr;
+ QOpenGLShaderProgram *m_program2 = nullptr;
+ QOpenGLTexture *m_texture = nullptr;
QOpenGLBuffer m_vbo1;
QOpenGLBuffer m_vbo2;
- int m_vertexAttr1;
- int m_normalAttr1;
- int m_matrixUniform1;
- int m_vertexAttr2;
- int m_normalAttr2;
- int m_texCoordAttr2;
- int m_matrixUniform2;
- int m_textureUniform2;
- bool m_transparent;
- QPushButton *m_btn;
+ int m_vertexAttr1 = 0;
+ int m_normalAttr1 = 0;
+ int m_matrixUniform1 = 0;
+ int m_vertexAttr2 = 0;
+ int m_normalAttr2 = 0;
+ int m_texCoordAttr2 = 0;
+ int m_matrixUniform2 = 0;
+ int m_textureUniform2 = 0;
+ bool m_transparent = false;
+ QPushButton *m_btn = nullptr;
bool m_hasButton;
QColor m_background;
};
diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp
index 1644233614..307190f308 100644
--- a/examples/opengl/textures/glwidget.cpp
+++ b/examples/opengl/textures/glwidget.cpp
@@ -53,17 +53,6 @@
#include <QOpenGLTexture>
#include <QMouseEvent>
-GLWidget::GLWidget(QWidget *parent)
- : QOpenGLWidget(parent),
- clearColor(Qt::black),
- xRot(0),
- yRot(0),
- zRot(0),
- program(0)
-{
- memset(textures, 0, sizeof(textures));
-}
-
GLWidget::~GLWidget()
{
makeCurrent();
diff --git a/examples/opengl/textures/glwidget.h b/examples/opengl/textures/glwidget.h
index 0db2695c6a..585d44dbfe 100644
--- a/examples/opengl/textures/glwidget.h
+++ b/examples/opengl/textures/glwidget.h
@@ -63,7 +63,7 @@ class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
Q_OBJECT
public:
- explicit GLWidget(QWidget *parent = 0);
+ using QOpenGLWidget::QOpenGLWidget;
~GLWidget();
QSize minimumSizeHint() const override;
@@ -85,13 +85,13 @@ protected:
private:
void makeObject();
- QColor clearColor;
+ QColor clearColor = Qt::black;
QPoint lastPos;
- int xRot;
- int yRot;
- int zRot;
- QOpenGLTexture *textures[6];
- QOpenGLShaderProgram *program;
+ int xRot = 0;
+ int yRot = 0;
+ int zRot = 0;
+ QOpenGLTexture *textures[6] = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
+ QOpenGLShaderProgram *program = nullptr;
QOpenGLBuffer vbo;
};
diff --git a/examples/opengl/threadedqopenglwidget/glwidget.cpp b/examples/opengl/threadedqopenglwidget/glwidget.cpp
index cc528a734a..2101575fd4 100644
--- a/examples/opengl/threadedqopenglwidget/glwidget.cpp
+++ b/examples/opengl/threadedqopenglwidget/glwidget.cpp
@@ -115,12 +115,7 @@ void GLWidget::grabContext()
m_renderer->unlockRenderer();
}
-Renderer::Renderer(GLWidget *w)
- : m_inited(false),
- m_glwidget(w),
- m_exiting(false)
-{
-}
+Renderer::Renderer(GLWidget *w) : m_glwidget(w) {}
void Renderer::paintQtLogo()
{
diff --git a/examples/opengl/threadedqopenglwidget/glwidget.h b/examples/opengl/threadedqopenglwidget/glwidget.h
index c33f7e51a7..8dc84dd0b1 100644
--- a/examples/opengl/threadedqopenglwidget/glwidget.h
+++ b/examples/opengl/threadedqopenglwidget/glwidget.h
@@ -88,29 +88,29 @@ private:
void quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4);
void extrude(qreal x1, qreal y1, qreal x2, qreal y2);
- bool m_inited;
- qreal m_fAngle;
- qreal m_fScale;
+ bool m_inited = false;
+ qreal m_fAngle = 0;
+ qreal m_fScale = 1;
QVector<QVector3D> vertices;
QVector<QVector3D> normals;
QOpenGLShaderProgram program;
QOpenGLBuffer vbo;
- int vertexAttr;
- int normalAttr;
- int matrixUniform;
- GLWidget *m_glwidget;
+ int vertexAttr = 0;
+ int normalAttr = 0;
+ int matrixUniform = 0;
+ GLWidget *m_glwidget = nullptr;
QMutex m_renderMutex;
QElapsedTimer m_elapsed;
QMutex m_grabMutex;
QWaitCondition m_grabCond;
- bool m_exiting;
+ bool m_exiting = false;
};
class GLWidget : public QOpenGLWidget
{
Q_OBJECT
public:
- explicit GLWidget(QWidget *parent = 0);
+ explicit GLWidget(QWidget *parent = nullptr);
~GLWidget();
protected:
diff --git a/examples/widgets/dialogs/classwizard/classwizard.cpp b/examples/widgets/dialogs/classwizard/classwizard.cpp
index 81adf85b0d..8421289eab 100644
--- a/examples/widgets/dialogs/classwizard/classwizard.cpp
+++ b/examples/widgets/dialogs/classwizard/classwizard.cpp
@@ -118,9 +118,9 @@ void ClassWizard::accept()
block += "public:\n";
if (field("qobjectCtor").toBool()) {
- block += " " + className + "(QObject *parent = 0);\n";
+ block += " " + className + "(QObject *parent = nullptr);\n";
} else if (field("qwidgetCtor").toBool()) {
- block += " " + className + "(QWidget *parent = 0);\n";
+ block += " " + className + "(QWidget *parent = nullptr);\n";
} else if (field("defaultCtor").toBool()) {
block += " " + className + "();\n";
if (field("copyCtor").toBool()) {
diff --git a/examples/widgets/dialogs/classwizard/classwizard.h b/examples/widgets/dialogs/classwizard/classwizard.h
index fee0f6df66..0c386f0553 100644
--- a/examples/widgets/dialogs/classwizard/classwizard.h
+++ b/examples/widgets/dialogs/classwizard/classwizard.h
@@ -67,7 +67,7 @@ class ClassWizard : public QWizard
Q_OBJECT
public:
- ClassWizard(QWidget *parent = 0);
+ ClassWizard(QWidget *parent = nullptr);
void accept() override;
};
@@ -79,7 +79,7 @@ class IntroPage : public QWizardPage
Q_OBJECT
public:
- IntroPage(QWidget *parent = 0);
+ IntroPage(QWidget *parent = nullptr);
private:
QLabel *label;
@@ -92,7 +92,7 @@ class ClassInfoPage : public QWizardPage
Q_OBJECT
public:
- ClassInfoPage(QWidget *parent = 0);
+ ClassInfoPage(QWidget *parent = nullptr);
private:
QLabel *classNameLabel;
@@ -114,7 +114,7 @@ class CodeStylePage : public QWizardPage
Q_OBJECT
public:
- CodeStylePage(QWidget *parent = 0);
+ CodeStylePage(QWidget *parent = nullptr);
protected:
void initializePage() override;
@@ -135,7 +135,7 @@ class OutputFilesPage : public QWizardPage
Q_OBJECT
public:
- OutputFilesPage(QWidget *parent = 0);
+ OutputFilesPage(QWidget *parent = nullptr);
protected:
void initializePage() override;
@@ -154,7 +154,7 @@ class ConclusionPage : public QWizardPage
Q_OBJECT
public:
- ConclusionPage(QWidget *parent = 0);
+ ConclusionPage(QWidget *parent = nullptr);
protected:
void initializePage() override;
diff --git a/examples/widgets/dialogs/classwizard/main.cpp b/examples/widgets/dialogs/classwizard/main.cpp
index 03ffe97a23..221e81aae4 100644
--- a/examples/widgets/dialogs/classwizard/main.cpp
+++ b/examples/widgets/dialogs/classwizard/main.cpp
@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
#ifndef QT_NO_TRANSLATION
- QString translatorFileName = QLatin1String("qt_");
+ QString translatorFileName = QLatin1String("qtbase_");
translatorFileName += QLocale::system().name();
QTranslator *translator = new QTranslator(&app);
if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
diff --git a/examples/widgets/dialogs/extension/finddialog.h b/examples/widgets/dialogs/extension/finddialog.h
index 858e1c929b..9b4b5b5f3d 100644
--- a/examples/widgets/dialogs/extension/finddialog.h
+++ b/examples/widgets/dialogs/extension/finddialog.h
@@ -68,7 +68,7 @@ class FindDialog : public QDialog
Q_OBJECT
public:
- FindDialog(QWidget *parent = 0);
+ FindDialog(QWidget *parent = nullptr);
private:
QLabel *label;
diff --git a/examples/widgets/dialogs/findfiles/window.h b/examples/widgets/dialogs/findfiles/window.h
index 949df704bb..b74ba5e70c 100644
--- a/examples/widgets/dialogs/findfiles/window.h
+++ b/examples/widgets/dialogs/findfiles/window.h
@@ -68,7 +68,7 @@ class Window : public QWidget
Q_OBJECT
public:
- Window(QWidget *parent = 0);
+ Window(QWidget *parent = nullptr);
private slots:
void browse();
diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.h b/examples/widgets/dialogs/licensewizard/licensewizard.h
index c7709d88b3..e2890e484f 100644
--- a/examples/widgets/dialogs/licensewizard/licensewizard.h
+++ b/examples/widgets/dialogs/licensewizard/licensewizard.h
@@ -72,7 +72,7 @@ public:
Page_Conclusion };
//! [2]
- LicenseWizard(QWidget *parent = 0);
+ LicenseWizard(QWidget *parent = nullptr);
private slots:
void showHelp();
@@ -86,7 +86,7 @@ class IntroPage : public QWizardPage
Q_OBJECT
public:
- IntroPage(QWidget *parent = 0);
+ IntroPage(QWidget *parent = nullptr);
int nextId() const override;
@@ -103,7 +103,7 @@ class EvaluatePage : public QWizardPage
Q_OBJECT
public:
- EvaluatePage(QWidget *parent = 0);
+ EvaluatePage(QWidget *parent = nullptr);
int nextId() const override;
@@ -120,7 +120,7 @@ class RegisterPage : public QWizardPage
Q_OBJECT
public:
- RegisterPage(QWidget *parent = 0);
+ RegisterPage(QWidget *parent = nullptr);
int nextId() const override;
@@ -136,7 +136,7 @@ class DetailsPage : public QWizardPage
Q_OBJECT
public:
- DetailsPage(QWidget *parent = 0);
+ DetailsPage(QWidget *parent = nullptr);
int nextId() const override;
@@ -155,7 +155,7 @@ class ConclusionPage : public QWizardPage
Q_OBJECT
public:
- ConclusionPage(QWidget *parent = 0);
+ ConclusionPage(QWidget *parent = nullptr);
void initializePage() override;
int nextId() const override;
diff --git a/examples/widgets/dialogs/licensewizard/main.cpp b/examples/widgets/dialogs/licensewizard/main.cpp
index ed46e792d0..112fcc7aa0 100644
--- a/examples/widgets/dialogs/licensewizard/main.cpp
+++ b/examples/widgets/dialogs/licensewizard/main.cpp
@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
#ifndef QT_NO_TRANSLATION
- QString translatorFileName = QLatin1String("qt_");
+ QString translatorFileName = QLatin1String("qtbase_");
translatorFileName += QLocale::system().name();
QTranslator *translator = new QTranslator(&app);
if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
diff --git a/examples/widgets/dialogs/standarddialogs/dialog.h b/examples/widgets/dialogs/standarddialogs/dialog.h
index 0d1c8d3e54..6d9cbdc07a 100644
--- a/examples/widgets/dialogs/standarddialogs/dialog.h
+++ b/examples/widgets/dialogs/standarddialogs/dialog.h
@@ -66,7 +66,7 @@ class Dialog : public QWidget
Q_OBJECT
public:
- Dialog(QWidget *parent = 0);
+ Dialog(QWidget *parent = nullptr);
private slots:
void setInteger();
diff --git a/examples/widgets/dialogs/standarddialogs/main.cpp b/examples/widgets/dialogs/standarddialogs/main.cpp
index a0cded4f47..f7417f0e45 100644
--- a/examples/widgets/dialogs/standarddialogs/main.cpp
+++ b/examples/widgets/dialogs/standarddialogs/main.cpp
@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
QGuiApplication::setApplicationDisplayName(Dialog::tr("Standard Dialogs"));
#ifndef QT_NO_TRANSLATION
- QString translatorFileName = QLatin1String("qt_");
+ QString translatorFileName = QLatin1String("qtbase_");
translatorFileName += QLocale::system().name();
QTranslator *translator = new QTranslator(&app);
if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
diff --git a/examples/widgets/dialogs/tabdialog/tabdialog.h b/examples/widgets/dialogs/tabdialog/tabdialog.h
index 2db47c9ddd..b7c6c5b8da 100644
--- a/examples/widgets/dialogs/tabdialog/tabdialog.h
+++ b/examples/widgets/dialogs/tabdialog/tabdialog.h
@@ -65,7 +65,7 @@ class GeneralTab : public QWidget
Q_OBJECT
public:
- explicit GeneralTab(const QFileInfo &fileInfo, QWidget *parent = 0);
+ explicit GeneralTab(const QFileInfo &fileInfo, QWidget *parent = nullptr);
};
//! [0]
@@ -76,7 +76,7 @@ class PermissionsTab : public QWidget
Q_OBJECT
public:
- explicit PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = 0);
+ explicit PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = nullptr);
};
//! [1]
@@ -87,7 +87,7 @@ class ApplicationsTab : public QWidget
Q_OBJECT
public:
- explicit ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = 0);
+ explicit ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = nullptr);
};
//! [2]
@@ -98,7 +98,7 @@ class TabDialog : public QDialog
Q_OBJECT
public:
- explicit TabDialog(const QString &fileName, QWidget *parent = 0);
+ explicit TabDialog(const QString &fileName, QWidget *parent = nullptr);
private:
QTabWidget *tabWidget;
diff --git a/examples/widgets/dialogs/trivialwizard/trivialwizard.cpp b/examples/widgets/dialogs/trivialwizard/trivialwizard.cpp
index ce13a59b0c..75a373f990 100644
--- a/examples/widgets/dialogs/trivialwizard/trivialwizard.cpp
+++ b/examples/widgets/dialogs/trivialwizard/trivialwizard.cpp
@@ -128,7 +128,7 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
#ifndef QT_NO_TRANSLATION
- QString translatorFileName = QLatin1String("qt_");
+ QString translatorFileName = QLatin1String("qtbase_");
translatorFileName += QLocale::system().name();
QTranslator *translator = new QTranslator(&app);
if (translator->load(translatorFileName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
diff --git a/examples/widgets/doc/dropsite.qdoc b/examples/widgets/doc/dropsite.qdoc
index af8766a308..d8d09612f6 100644
--- a/examples/widgets/doc/dropsite.qdoc
+++ b/examples/widgets/doc/dropsite.qdoc
@@ -176,16 +176,16 @@
\snippet draganddrop/dropsite/dropsitewindow.cpp constructor part3
- Two QPushButton objects, \c clearButton and \c quitButton, are instantiated
- and added to \c buttonBox - a QDialogButtonBox object. We use
- QDialogButtonBox here to ensure that the push buttons are presented in a
+ Three QPushButton objects, \c clearButton, \c copyButton, and \c quitButton,
+ are instantiated and added to \c buttonBox - a QDialogButtonBox object. We
+ use QDialogButtonBox here to ensure that the push buttons are presented in a
layout that conforms to the platform's style.
\snippet draganddrop/dropsite/dropsitewindow.cpp constructor part4
- The \l{QPushButton::clicked()}{clicked()} signals for \c quitButton and
- \c clearButton are connected to \l{QWidget::close()}{close()} and
- \c clear(), respectively.
+ The \l{QPushButton::clicked()}{clicked()} signals for \c copyButton,
+ \c clearButton, and \c quitButton are connected to \c copy(),
+ \c clear() and \l{QWidget::close()}{close()}, respectively.
For the layout, we use a QVBoxLayout, \c mainLayout, to arrange our widgets
vertically. We also set the window title to "Drop Site" and the minimum
diff --git a/examples/widgets/doc/src/calculator.qdoc b/examples/widgets/doc/src/calculator.qdoc
index e8f8030207..7d34a86c19 100644
--- a/examples/widgets/doc/src/calculator.qdoc
+++ b/examples/widgets/doc/src/calculator.qdoc
@@ -142,6 +142,9 @@
pendingAdditiveOperator and \c pendingMultiplicativeOperator
variables don't need to be initialized explicitly, because the
QString constructor initializes them to empty strings.
+ It is also possible to initialize those variable directly in the
+ header. This is called \c member-initializaton and avoids a long
+ initialization list.
\snippet widgets/calculator/calculator.cpp 1
\snippet widgets/calculator/calculator.cpp 2
diff --git a/examples/widgets/doc/src/collidingmice-example.qdoc b/examples/widgets/doc/src/collidingmice-example.qdoc
index 657c416218..984d3244f9 100644
--- a/examples/widgets/doc/src/collidingmice-example.qdoc
+++ b/examples/widgets/doc/src/collidingmice-example.qdoc
@@ -75,7 +75,8 @@
\section1 Mouse Class Definition
When constructing a mouse item, we first ensure that all the item's
- private variables are properly initialized:
+ private variables which were no yet initialized directly in the class
+ are properly initialized:
\snippet graphicsview/collidingmice/mouse.cpp 0
diff --git a/examples/widgets/doc/src/diagramscene.qdoc b/examples/widgets/doc/src/diagramscene.qdoc
index 860dcc5cb9..1a94d53162 100644
--- a/examples/widgets/doc/src/diagramscene.qdoc
+++ b/examples/widgets/doc/src/diagramscene.qdoc
@@ -643,7 +643,9 @@
This function is called when the item is removed from the scene
and removes all arrows that are connected to this item. The arrow
must be removed from the \c arrows list of both its start and end
- item.
+ item. Since either the start or the end item is the object where
+ this function is currently called, we have to make sure to work on
+ a copy of arrows since removeArrow() is modifying this container.
Here is the \c addArrow() function:
diff --git a/examples/widgets/doc/src/tooltips.qdoc b/examples/widgets/doc/src/tooltips.qdoc
index a278215503..35e3b1e29f 100644
--- a/examples/widgets/doc/src/tooltips.qdoc
+++ b/examples/widgets/doc/src/tooltips.qdoc
@@ -95,7 +95,7 @@
\snippet widgets/tooltips/sortingbox.h 2
- We keep all the shape items in a QList, and we keep three
+ We keep all the shape items in a QVector, and we keep three
QPainterPath objects holding the shapes of a circle, a square and
a triangle. We also need to have a pointer to an item when it is
moving, and we need to know its previous position.
diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
index 2dae83bb22..a937e24a4c 100644
--- a/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
+++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.cpp
@@ -82,14 +82,21 @@ DropSiteWindow::DropSiteWindow()
//! [constructor part4]
clearButton = new QPushButton(tr("Clear"));
+ copyButton = new QPushButton(tr("Copy"));
quitButton = new QPushButton(tr("Quit"));
buttonBox = new QDialogButtonBox;
buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole);
+ buttonBox->addButton(copyButton, QDialogButtonBox::ActionRole);
+#if !QT_CONFIG(clipboard)
+ copyButton->setVisible(false);
+#endif
+
buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole);
connect(quitButton, &QAbstractButton::clicked, this, &QWidget::close);
connect(clearButton, &QAbstractButton::clicked, dropArea, &DropArea::clear);
+ connect(copyButton, &QAbstractButton::clicked, this, &DropSiteWindow::copy);
//! [constructor part4]
//! [constructor part5]
@@ -108,6 +115,7 @@ DropSiteWindow::DropSiteWindow()
void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
{
formatsTable->setRowCount(0);
+ copyButton->setEnabled(false);
if (!mimeData)
return;
//! [updateFormatsTable() part1]
@@ -145,5 +153,18 @@ void DropSiteWindow::updateFormatsTable(const QMimeData *mimeData)
}
formatsTable->resizeColumnToContents(0);
+#if QT_CONFIG(clipboard)
+ copyButton->setEnabled(formatsTable->rowCount() > 0);
+#endif
}
//! [updateFormatsTable() part4]
+
+void DropSiteWindow::copy()
+{
+#if QT_CONFIG(clipboard)
+ QString text;
+ for (int row = 0, rowCount = formatsTable->rowCount(); row < rowCount; ++row)
+ text += formatsTable->item(row, 0)->text() + ": " + formatsTable->item(row, 1)->text() + '\n';
+ QGuiApplication::clipboard()->setText(text);
+#endif
+}
diff --git a/examples/widgets/draganddrop/dropsite/dropsitewindow.h b/examples/widgets/draganddrop/dropsite/dropsitewindow.h
index d80476f369..a40b481637 100644
--- a/examples/widgets/draganddrop/dropsite/dropsitewindow.h
+++ b/examples/widgets/draganddrop/dropsite/dropsitewindow.h
@@ -72,6 +72,7 @@ public:
public slots:
void updateFormatsTable(const QMimeData *mimeData);
+ void copy();
private:
DropArea *dropArea;
@@ -79,6 +80,7 @@ private:
QTableWidget *formatsTable;
QPushButton *clearButton;
+ QPushButton *copyButton;
QPushButton *quitButton;
QDialogButtonBox *buttonBox;
};
diff --git a/examples/widgets/effects/blurpicker/blurpicker.h b/examples/widgets/effects/blurpicker/blurpicker.h
index 3f444419a8..dc7fc4dabb 100644
--- a/examples/widgets/effects/blurpicker/blurpicker.h
+++ b/examples/widgets/effects/blurpicker/blurpicker.h
@@ -63,7 +63,7 @@ class BlurPicker: public QGraphicsView
Q_PROPERTY(qreal index READ index WRITE setIndex)
public:
- BlurPicker(QWidget *parent = 0);
+ BlurPicker(QWidget *parent = nullptr);
qreal index() const;
void setIndex(qreal);
diff --git a/examples/widgets/effects/fademessage/fademessage.h b/examples/widgets/effects/fademessage/fademessage.h
index d17a1616ce..4d84c4ed21 100644
--- a/examples/widgets/effects/fademessage/fademessage.h
+++ b/examples/widgets/effects/fademessage/fademessage.h
@@ -62,7 +62,7 @@ class FadeMessage: public QGraphicsView
Q_OBJECT
public:
- FadeMessage(QWidget *parent = 0);
+ FadeMessage(QWidget *parent = nullptr);
private:
void setupScene();
diff --git a/examples/widgets/gestures/imagegestures/imagewidget.cpp b/examples/widgets/gestures/imagegestures/imagewidget.cpp
index 0a6b963559..fb5351f949 100644
--- a/examples/widgets/gestures/imagegestures/imagewidget.cpp
+++ b/examples/widgets/gestures/imagegestures/imagewidget.cpp
@@ -50,26 +50,23 @@
#include "imagewidget.h"
-#include <QtWidgets>
+#include <QDir>
+#include <QImageReader>
+#include <QGestureEvent>
+#include <QPainter>
Q_LOGGING_CATEGORY(lcExample, "qt.examples.imagegestures")
//! [constructor]
ImageWidget::ImageWidget(QWidget *parent)
- : QWidget(parent),
- position(0),
- horizontalOffset(0),
- verticalOffset(0),
- rotationAngle(0),
- scaleFactor(1),
- currentStepScaleFactor(1)
-
+ : QWidget(parent), position(0), horizontalOffset(0), verticalOffset(0)
+ , rotationAngle(0), scaleFactor(1), currentStepScaleFactor(1)
{
- setMinimumSize(QSize(100,100));
+ setMinimumSize(QSize(100, 100));
}
//! [constructor]
-void ImageWidget::grabGestures(const QList<Qt::GestureType> &gestures)
+void ImageWidget::grabGestures(const QVector<Qt::GestureType> &gestures)
{
//! [enable gestures]
for (Qt::GestureType gesture : gestures)
@@ -96,11 +93,11 @@ void ImageWidget::paintEvent(QPaintEvent*)
const qreal wh = height();
const qreal ww = width();
- p.translate(ww/2, wh/2);
+ p.translate(ww / 2, wh / 2);
p.translate(horizontalOffset, verticalOffset);
p.rotate(rotationAngle);
p.scale(currentStepScaleFactor * scaleFactor, currentStepScaleFactor * scaleFactor);
- p.translate(-iw/2, -ih/2);
+ p.translate(-iw / 2, -ih / 2);
p.drawImage(0, 0, currentImage);
}
//! [paint method]
@@ -198,8 +195,7 @@ void ImageWidget::openDirectory(const QString &path)
{
this->path = path;
QDir dir(path);
- QStringList nameFilters;
- nameFilters << "*.jpg" << "*.png";
+ const QStringList nameFilters{"*.jpg", "*.png"};
files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name);
position = 0;
@@ -207,7 +203,7 @@ void ImageWidget::openDirectory(const QString &path)
update();
}
-QImage ImageWidget::loadImage(const QString &fileName)
+QImage ImageWidget::loadImage(const QString &fileName) const
{
QImageReader reader(fileName);
reader.setAutoTransform(true);
diff --git a/examples/widgets/gestures/imagegestures/imagewidget.h b/examples/widgets/gestures/imagegestures/imagewidget.h
index 5e92541067..ae5eb7bc2b 100644
--- a/examples/widgets/gestures/imagegestures/imagewidget.h
+++ b/examples/widgets/gestures/imagegestures/imagewidget.h
@@ -51,9 +51,9 @@
#ifndef IMAGEWIDGET_H
#define IMAGEWIDGET_H
-#include <QWidget>
#include <QImage>
-#include <QtWidgets>
+#include <QLoggingCategory>
+#include <QWidget>
QT_BEGIN_NAMESPACE
class QGestureEvent;
@@ -70,9 +70,9 @@ class ImageWidget : public QWidget
Q_OBJECT
public:
- ImageWidget(QWidget *parent = 0);
+ ImageWidget(QWidget *parent = nullptr);
void openDirectory(const QString &path);
- void grabGestures(const QList<Qt::GestureType> &gestures);
+ void grabGestures(const QVector<Qt::GestureType> &gestures);
protected:
bool event(QEvent *event) override;
@@ -87,7 +87,7 @@ private:
void swipeTriggered(QSwipeGesture*);
//! [class definition begin]
- QImage loadImage(const QString &fileName);
+ QImage loadImage(const QString &fileName) const;
void loadImage();
void goNextImage();
void goPrevImage();
diff --git a/examples/widgets/gestures/imagegestures/main.cpp b/examples/widgets/gestures/imagegestures/main.cpp
index ecd7462bd3..4f8d4ec15e 100644
--- a/examples/widgets/gestures/imagegestures/main.cpp
+++ b/examples/widgets/gestures/imagegestures/main.cpp
@@ -102,7 +102,7 @@ int main(int argc, char *argv[])
return -1;
}
- QList<Qt::GestureType> gestures;
+ QVector<Qt::GestureType> gestures;
if (!commandLineParser.isSet(disablePanOption))
gestures << Qt::PanGesture;
if (!commandLineParser.isSet(disablePinchOption))
diff --git a/examples/widgets/gestures/imagegestures/mainwidget.cpp b/examples/widgets/gestures/imagegestures/mainwidget.cpp
index c4e63e9e7d..d1c786a93a 100644
--- a/examples/widgets/gestures/imagegestures/mainwidget.cpp
+++ b/examples/widgets/gestures/imagegestures/mainwidget.cpp
@@ -72,7 +72,7 @@ void MainWidget::openDirectory(const QString &path)
imageWidget->openDirectory(path);
}
-void MainWidget::grabGestures(const QList<Qt::GestureType> &gestures)
+void MainWidget::grabGestures(const QVector<Qt::GestureType> &gestures)
{
imageWidget->grabGestures(gestures);
}
diff --git a/examples/widgets/gestures/imagegestures/mainwidget.h b/examples/widgets/gestures/imagegestures/mainwidget.h
index f3763ffffc..1600597251 100644
--- a/examples/widgets/gestures/imagegestures/mainwidget.h
+++ b/examples/widgets/gestures/imagegestures/mainwidget.h
@@ -60,8 +60,8 @@ class MainWidget : public QMainWindow
Q_OBJECT
public:
- MainWidget(QWidget *parent = 0);
- void grabGestures(const QList<Qt::GestureType> &gestures);
+ MainWidget(QWidget *parent = nullptr);
+ void grabGestures(const QVector<Qt::GestureType> &gestures);
public slots:
void openDirectory(const QString &path);
diff --git a/examples/widgets/graphicsview/anchorlayout/main.cpp b/examples/widgets/graphicsview/anchorlayout/main.cpp
index 59ced72018..98dacfb5fb 100644
--- a/examples/widgets/graphicsview/anchorlayout/main.cpp
+++ b/examples/widgets/graphicsview/anchorlayout/main.cpp
@@ -88,7 +88,7 @@ int main(int argc, char **argv)
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
l->setSpacing(0);
- QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window);
+ QGraphicsWidget *w = new QGraphicsWidget(nullptr, Qt::Window);
w->setPos(20, 20);
w->setLayout(l);
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.cpp b/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.cpp
index 804db2f9be..2fbc232b20 100644
--- a/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.cpp
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.cpp
@@ -51,33 +51,26 @@
#include "layoutitem.h"
#include <QGradient>
-#include <QGraphicsLinearLayout>
#include <QPainter>
//! [0]
-LayoutItem::LayoutItem(QGraphicsItem *parent/* = 0*/)
- : QGraphicsLayoutItem(), QGraphicsItem(parent)
+LayoutItem::LayoutItem(QGraphicsItem *parent)
+ : QGraphicsLayoutItem(), QGraphicsItem(parent),
+ m_pix(QPixmap(QLatin1String(":/images/block.png")))
{
- m_pix = new QPixmap(QLatin1String(":/images/block.png"));
setGraphicsItem(this);
}
//! [0]
-LayoutItem::~LayoutItem()
-{
- delete m_pix;
-}
-
//! [1]
-void LayoutItem::paint(QPainter *painter,
- const QStyleOptionGraphicsItem *option, QWidget *widget /*= 0*/)
+void LayoutItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
{
Q_UNUSED(widget);
Q_UNUSED(option);
- QRectF frame(QPointF(0,0), geometry().size());
- qreal w = m_pix->width();
- qreal h = m_pix->height();
+ QRectF frame(QPointF(0, 0), geometry().size());
+ const QSize pmSize = m_pix.size();
QGradientStops stops;
//! [1]
@@ -94,8 +87,8 @@ void LayoutItem::paint(QPainter *painter,
painter->drawRoundedRect(frame, 10.0, 10.0);
// paint a rect around the pixmap (with gradient)
- QPointF pixpos = frame.center() - (QPointF(w, h) / 2);
- QRectF innerFrame(pixpos, QSizeF(w, h));
+ QPointF pixpos = frame.center() - (QPointF(pmSize.width(), pmSize.height()) / 2);
+ QRectF innerFrame(pixpos, pmSize);
innerFrame.adjust(-4, -4, 4, 4);
gradient.setStart(innerFrame.topLeft());
gradient.setFinalStop(innerFrame.bottomRight());
@@ -106,14 +99,14 @@ void LayoutItem::paint(QPainter *painter,
gradient.setStops(stops);
painter->setBrush(QBrush(gradient));
painter->drawRoundedRect(innerFrame, 10.0, 10.0);
- painter->drawPixmap(pixpos, *m_pix);
+ painter->drawPixmap(pixpos, m_pix);
}
//! [2]
//! [3]
QRectF LayoutItem::boundingRect() const
{
- return QRectF(QPointF(0,0), geometry().size());
+ return QRectF(QPointF(0, 0), geometry().size());
}
//! [3]
@@ -133,7 +126,7 @@ QSizeF LayoutItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
case Qt::MinimumSize:
case Qt::PreferredSize:
// Do not allow a size smaller than the pixmap with two frames around it.
- return m_pix->size() + QSize(12, 12);
+ return m_pix.size() + QSize(12, 12);
case Qt::MaximumSize:
return QSizeF(1000,1000);
default:
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h b/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h
index 3535a26670..3dc431d513 100644
--- a/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h
@@ -53,23 +53,24 @@
#include <QGraphicsLayoutItem>
#include <QGraphicsItem>
+#include <QPixmap>
//! [0]
class LayoutItem : public QGraphicsLayoutItem, public QGraphicsItem
{
public:
- LayoutItem(QGraphicsItem *parent = 0);
- ~LayoutItem();
+ LayoutItem(QGraphicsItem *parent = nullptr);
+
// Inherited from QGraphicsLayoutItem
void setGeometry(const QRectF &geom) override;
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
// Inherited from QGraphicsItem
QRectF boundingRect() const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
private:
- QPixmap *m_pix;
+ QPixmap m_pix;
};
//! [0]
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/window.h b/examples/widgets/graphicsview/basicgraphicslayouts/window.h
index dfe04ed196..c46082e552 100644
--- a/examples/widgets/graphicsview/basicgraphicslayouts/window.h
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/window.h
@@ -54,11 +54,11 @@
#include <QGraphicsWidget>
//! [0]
-class Window : public QGraphicsWidget {
+class Window : public QGraphicsWidget
+{
Q_OBJECT
-
public:
- Window(QGraphicsWidget *parent = 0);
+ Window(QGraphicsWidget *parent = nullptr);
};
//! [0]
diff --git a/examples/widgets/graphicsview/boxes/glbuffers.cpp b/examples/widgets/graphicsview/boxes/glbuffers.cpp
index b52b26c4ef..91de336af3 100644
--- a/examples/widgets/graphicsview/boxes/glbuffers.cpp
+++ b/examples/widgets/graphicsview/boxes/glbuffers.cpp
@@ -49,8 +49,6 @@
****************************************************************************/
#include "glbuffers.h"
-#include <QtGui/qmatrix4x4.h>
-#include <QtCore/qmath.h>
void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{
@@ -65,7 +63,7 @@ void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zF
// GLTexture //
//============================================================================//
-GLTexture::GLTexture() : m_texture(0), m_failed(false)
+GLTexture::GLTexture()
{
glGenTextures(1, &m_texture);
}
@@ -83,7 +81,7 @@ GLTexture2D::GLTexture2D(int width, int height)
{
glBindTexture(GL_TEXTURE_2D, m_texture);
glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0,
- GL_BGRA, GL_UNSIGNED_BYTE, 0);
+ GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
@@ -95,7 +93,7 @@ GLTexture2D::GLTexture2D(int width, int height)
}
-GLTexture2D::GLTexture2D(const QString& fileName, int width, int height)
+GLTexture2D::GLTexture2D(const QString &fileName, int width, int height)
{
// TODO: Add error handling.
QImage image(fileName);
@@ -162,7 +160,7 @@ GLTexture3D::GLTexture3D(int width, int height, int depth)
glBindTexture(GL_TEXTURE_3D, m_texture);
glTexImage3D(GL_TEXTURE_3D, 0, 4, width, height, depth, 0,
- GL_BGRA, GL_UNSIGNED_BYTE, 0);
+ GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
@@ -206,7 +204,7 @@ GLTextureCube::GLTextureCube(int size)
for (int i = 0; i < 6; ++i)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 4, size, size, 0,
- GL_BGRA, GL_UNSIGNED_BYTE, 0);
+ GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
@@ -252,7 +250,7 @@ GLTextureCube::GLTextureCube(const QStringList &fileNames, int size)
// Clear remaining faces.
while (index < 6) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, 4, size, size, 0,
- GL_BGRA, GL_UNSIGNED_BYTE, 0);
+ GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
++index;
}
@@ -291,11 +289,8 @@ void GLTextureCube::unbind()
//============================================================================//
GLFrameBufferObject::GLFrameBufferObject(int width, int height)
- : m_fbo(0)
- , m_depthBuffer(0)
- , m_width(width)
+ : m_width(width)
, m_height(height)
- , m_failed(false)
{
GLBUFFERS_ASSERT_OPENGL("GLFrameBufferObject::GLFrameBufferObject",
glGenFramebuffersEXT && glGenRenderbuffersEXT && glBindRenderbufferEXT && glRenderbufferStorageEXT, return)
@@ -373,7 +368,7 @@ void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face)
return;
}
- static int perm[6][3] = {
+ static constexpr int perm[6][3] = {
{2, 1, 0},
{2, 1, 0},
{0, 2, 1},
@@ -382,7 +377,7 @@ void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face)
{0, 1, 2},
};
- static float signs[6][3] = {
+ static constexpr float signs[6][3] = {
{-1.0f, -1.0f, -1.0f},
{+1.0f, -1.0f, +1.0f},
{+1.0f, +1.0f, -1.0f},
diff --git a/examples/widgets/graphicsview/boxes/glbuffers.h b/examples/widgets/graphicsview/boxes/glbuffers.h
index e2363d561e..4318e8ac24 100644
--- a/examples/widgets/graphicsview/boxes/glbuffers.h
+++ b/examples/widgets/graphicsview/boxes/glbuffers.h
@@ -58,7 +58,7 @@
#include <QtOpenGL>
#define BUFFER_OFFSET(i) ((char*)0 + (i))
-#define SIZE_OF_MEMBER(cls, member) sizeof(static_cast<cls *>(0)->member)
+#define SIZE_OF_MEMBER(cls, member) sizeof(static_cast<cls *>(nullptr)->member)
#define GLBUFFERS_ASSERT_OPENGL(prefix, assertion, returnStatement) \
if (m_failed || !(assertion)) { \
@@ -82,8 +82,8 @@ public:
virtual void unbind() = 0;
virtual bool failed() const {return m_failed;}
protected:
- GLuint m_texture;
- bool m_failed;
+ GLuint m_texture = 0;
+ bool m_failed = false;
};
class GLFrameBufferObject
@@ -98,17 +98,17 @@ public:
virtual bool failed() const {return m_failed;}
protected:
void setAsRenderTarget(bool state = true);
- GLuint m_fbo;
- GLuint m_depthBuffer;
+ GLuint m_fbo = 0;
+ GLuint m_depthBuffer = 0;
int m_width, m_height;
- bool m_failed;
+ bool m_failed = false;
};
class GLTexture2D : public GLTexture
{
public:
GLTexture2D(int width, int height);
- explicit GLTexture2D(const QString& fileName, int width = 0, int height = 0);
+ explicit GLTexture2D(const QString &fileName, int width = 0, int height = 0);
void load(int width, int height, QRgb *data);
void bind() override;
void unbind() override;
@@ -197,11 +197,7 @@ template<class T>
class GLVertexBuffer
{
public:
- GLVertexBuffer(int length, const T *data = 0, int mode = GL_STATIC_DRAW)
- : m_length(0)
- , m_mode(mode)
- , m_buffer(0)
- , m_failed(false)
+ GLVertexBuffer(int length, const T *data = nullptr, int mode = GL_STATIC_DRAW)
{
GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::GLVertexBuffer", glGenBuffers && glBindBuffer && glBufferData, return)
@@ -275,12 +271,12 @@ public:
T *lock()
{
- GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::lock", glBindBuffer && glMapBuffer, return 0)
+ GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::lock", glBindBuffer && glMapBuffer, return nullptr)
glBindBuffer(GL_ARRAY_BUFFER, m_buffer);
//glBufferData(GL_ARRAY_BUFFER, m_length, NULL, m_mode);
GLvoid* buffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
- m_failed = (buffer == 0);
+ m_failed = (buffer == nullptr);
return reinterpret_cast<T *>(buffer);
}
@@ -298,16 +294,17 @@ public:
}
private:
- int m_length, m_mode;
- GLuint m_buffer;
- bool m_failed;
+ int m_length = 0;
+ int m_mode = 0;
+ GLuint m_buffer = 0;
+ bool m_failed = false;
};
template<class T>
class GLIndexBuffer
{
public:
- GLIndexBuffer(int length, const T *data = 0, int mode = GL_STATIC_DRAW)
+ GLIndexBuffer(int length, const T *data = nullptr, int mode = GL_STATIC_DRAW)
: m_length(0)
, m_mode(mode)
, m_buffer(0)
@@ -345,11 +342,11 @@ public:
T *lock()
{
- GLBUFFERS_ASSERT_OPENGL("GLIndexBuffer::lock", glBindBuffer && glMapBuffer, return 0)
+ GLBUFFERS_ASSERT_OPENGL("GLIndexBuffer::lock", glBindBuffer && glMapBuffer, return nullptr)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_buffer);
GLvoid* buffer = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_READ_WRITE);
- m_failed = (buffer == 0);
+ m_failed = (buffer == nullptr);
return reinterpret_cast<T *>(buffer);
}
diff --git a/examples/widgets/graphicsview/boxes/gltrianglemesh.h b/examples/widgets/graphicsview/boxes/gltrianglemesh.h
index 716c4de62e..e5c4f51514 100644
--- a/examples/widgets/graphicsview/boxes/gltrianglemesh.h
+++ b/examples/widgets/graphicsview/boxes/gltrianglemesh.h
@@ -51,13 +51,12 @@
#ifndef GLTRIANGLEMESH_H
#define GLTRIANGLEMESH_H
-//#include <GL/glew.h>
+#include "glbuffers.h"
#include "glextensions.h"
#include <QtWidgets>
#include <QtOpenGL>
-#include "glbuffers.h"
template<class TVertex, class TIndex>
class GLTriangleMesh
diff --git a/examples/widgets/graphicsview/boxes/main.cpp b/examples/widgets/graphicsview/boxes/main.cpp
index b7242d529b..2b3e6d3389 100644
--- a/examples/widgets/graphicsview/boxes/main.cpp
+++ b/examples/widgets/graphicsview/boxes/main.cpp
@@ -48,13 +48,11 @@
**
****************************************************************************/
-//#include <GL/glew.h>
#include "glextensions.h"
-
#include "scene.h"
-#include <QtWidgets>
#include <QGLWidget>
+#include <QtWidgets>
class GraphicsView : public QGraphicsView
{
@@ -114,7 +112,7 @@ int main(int argc, char **argv)
QApplication app(argc, argv);
if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_5) == 0) {
- QMessageBox::critical(0, "OpenGL features missing",
+ QMessageBox::critical(nullptr, "OpenGL features missing",
"OpenGL version 1.5 or higher is required to run this demo.\n"
"The program will now exit.");
return -1;
@@ -125,7 +123,7 @@ int main(int argc, char **argv)
widget->makeCurrent();
if (!necessaryExtensionsSupported()) {
- QMessageBox::critical(0, "OpenGL features missing",
+ QMessageBox::critical(nullptr, "OpenGL features missing",
"The OpenGL extensions required to run this demo are missing.\n"
"The program will now exit.");
delete widget;
@@ -134,7 +132,7 @@ int main(int argc, char **argv)
// Check if all the necessary functions are resolved.
if (!getGLExtensionFunctions().resolve(widget->context())) {
- QMessageBox::critical(0, "OpenGL features missing",
+ QMessageBox::critical(nullptr, "OpenGL features missing",
"Failed to resolve OpenGL functions required to run this demo.\n"
"The program will now exit.");
delete widget;
@@ -142,7 +140,7 @@ int main(int argc, char **argv)
}
// TODO: Make conditional for final release
- QMessageBox::information(0, "For your information",
+ QMessageBox::information(nullptr, "For your information",
"This demo can be GPU and CPU intensive and may\n"
"work poorly or not at all on your system.");
diff --git a/examples/widgets/graphicsview/boxes/qtbox.cpp b/examples/widgets/graphicsview/boxes/qtbox.cpp
index 68d5c251f4..8713aac05d 100644
--- a/examples/widgets/graphicsview/boxes/qtbox.cpp
+++ b/examples/widgets/graphicsview/boxes/qtbox.cpp
@@ -50,28 +50,23 @@
#include "qtbox.h"
-const qreal ROTATE_SPEED_X = 30.0 / 1000.0;
-const qreal ROTATE_SPEED_Y = 20.0 / 1000.0;
-const qreal ROTATE_SPEED_Z = 40.0 / 1000.0;
-const int MAX_ITEM_SIZE = 512;
-const int MIN_ITEM_SIZE = 16;
+constexpr qreal ROTATE_SPEED_X = 30.0 / 1000.0;
+constexpr qreal ROTATE_SPEED_Y = 20.0 / 1000.0;
+constexpr qreal ROTATE_SPEED_Z = 40.0 / 1000.0;
+constexpr int MAX_ITEM_SIZE = 512;
+constexpr int MIN_ITEM_SIZE = 16;
//============================================================================//
// ItemBase //
//============================================================================//
-ItemBase::ItemBase(int size, int x, int y) : m_size(size), m_isResizing(false)
+ItemBase::ItemBase(int size, int x, int y) : m_size(size), m_startTime(QTime::currentTime())
{
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemIsFocusable, true);
setAcceptHoverEvents(true);
setPos(x, y);
- m_startTime = QTime::currentTime();
-}
-
-ItemBase::~ItemBase()
-{
}
QRectF ItemBase::boundingRect() const
@@ -252,10 +247,7 @@ void ItemBase::wheelEvent(QGraphicsSceneWheelEvent *event)
{
prepareGeometryChange();
m_size = int(m_size * qExp(-event->delta() / 600.0));
- if (m_size > MAX_ITEM_SIZE)
- m_size = MAX_ITEM_SIZE;
- else if (m_size < MIN_ITEM_SIZE)
- m_size = MIN_ITEM_SIZE;
+ m_size = qBound(MIN_ITEM_SIZE, m_size, MAX_ITEM_SIZE);
}
int ItemBase::type() const
@@ -273,7 +265,7 @@ bool ItemBase::isInResizeArea(const QPointF &pos)
// QtBox //
//============================================================================//
-QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y), m_texture(0)
+QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y)
{
for (int i = 0; i < 8; ++i) {
m_vertices[i].setX(i & 1 ? 0.5f : -0.5f);
@@ -294,8 +286,7 @@ QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y), m_texture(0)
QtBox::~QtBox()
{
- if (m_texture)
- delete m_texture;
+ delete m_texture;
}
ItemBase *QtBox::createNew(int size, int x, int y)
@@ -337,7 +328,7 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_NORMALIZE);
- if(m_texture == 0)
+ if (m_texture == nullptr)
m_texture = new GLTexture2D(":/res/boxes/qt-logo.jpg", 64, 64);
m_texture->bind();
glEnable(GL_TEXTURE_2D);
@@ -405,9 +396,8 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
//============================================================================//
CircleItem::CircleItem(int size, int x, int y) : ItemBase(size, x, y)
-{
- m_color = QColor::fromHsv(QRandomGenerator::global()->bounded(360), 255, 255);
-}
+ , m_color(QColor::fromHsv(QRandomGenerator::global()->bounded(360), 255, 255))
+{}
void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
@@ -455,9 +445,8 @@ ItemBase *CircleItem::createNew(int size, int x, int y)
//============================================================================//
SquareItem::SquareItem(int size, int x, int y) : ItemBase(size, x, y)
-{
- m_image = QPixmap(":/res/boxes/square.jpg");
-}
+ , m_image(QPixmap(":/res/boxes/square.jpg"))
+{}
void SquareItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
diff --git a/examples/widgets/graphicsview/boxes/qtbox.h b/examples/widgets/graphicsview/boxes/qtbox.h
index f8ee9bdb0a..84c8cb1d93 100644
--- a/examples/widgets/graphicsview/boxes/qtbox.h
+++ b/examples/widgets/graphicsview/boxes/qtbox.h
@@ -51,18 +51,17 @@
#ifndef QTBOX_H
#define QTBOX_H
-#include <QtWidgets>
-
-#include <QtGui/qvector3d.h>
#include "glbuffers.h"
+#include <QtWidgets>
+#include <QVector3D>
+
class ItemBase : public QGraphicsItem
{
public:
enum { Type = UserType + 1 };
ItemBase(int size, int x, int y);
- virtual ~ItemBase();
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
protected:
@@ -84,7 +83,7 @@ protected:
int m_size;
QTime m_startTime;
- bool m_isResizing;
+ bool m_isResizing = false;
};
class QtBox : public ItemBase
@@ -99,7 +98,7 @@ private:
QVector3D m_vertices[8];
QVector3D m_texCoords[4];
QVector3D m_normals[6];
- GLTexture *m_texture;
+ GLTexture *m_texture = nullptr;
};
class CircleItem : public ItemBase
diff --git a/examples/widgets/graphicsview/boxes/roundedbox.h b/examples/widgets/graphicsview/boxes/roundedbox.h
index ebc2dbd36e..a1f15cd631 100644
--- a/examples/widgets/graphicsview/boxes/roundedbox.h
+++ b/examples/widgets/graphicsview/boxes/roundedbox.h
@@ -51,16 +51,12 @@
#ifndef ROUNDEDBOX_H
#define ROUNDEDBOX_H
-//#include <GL/glew.h>
+#include "glbuffers.h"
#include "glextensions.h"
-
-#include <QtWidgets>
-#include <QtOpenGL>
-
#include "gltrianglemesh.h"
-#include <QtGui/qvector3d.h>
-#include <QtGui/qvector2d.h>
-#include "glbuffers.h"
+
+#include <QVector2D>
+#include <QVector3D>
struct P3T2N3Vertex
{
diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp
index a9995efa27..b344f65561 100644
--- a/examples/widgets/graphicsview/boxes/scene.cpp
+++ b/examples/widgets/graphicsview/boxes/scene.cpp
@@ -48,45 +48,15 @@
**
****************************************************************************/
-#include <QDebug>
#include "scene.h"
-#include <QtCore/QRandomGenerator>
-#include <QtGui/qmatrix4x4.h>
-#include <QtGui/qvector3d.h>
+
+#include <QMatrix4x4>
+#include <QRandomGenerator>
+#include <QVector3D>
#include <qmath.h>
#include "3rdparty/fbm.h"
-void checkGLErrors(const QString& prefix)
-{
- switch (glGetError()) {
- case GL_NO_ERROR:
- //qDebug() << prefix << tr("No error.");
- break;
- case GL_INVALID_ENUM:
- qDebug() << prefix << QObject::tr("Invalid enum.");
- break;
- case GL_INVALID_VALUE:
- qDebug() << prefix << QObject::tr("Invalid value.");
- break;
- case GL_INVALID_OPERATION:
- qDebug() << prefix << QObject::tr("Invalid operation.");
- break;
- case GL_STACK_OVERFLOW:
- qDebug() << prefix << QObject::tr("Stack overflow.");
- break;
- case GL_STACK_UNDERFLOW:
- qDebug() << prefix << QObject::tr("Stack underflow.");
- break;
- case GL_OUT_OF_MEMORY:
- qDebug() << prefix << QObject::tr("Out of memory.");
- break;
- default:
- qDebug() << prefix << QObject::tr("Unknown error.");
- break;
- }
-}
-
//============================================================================//
// ColorEdit //
//============================================================================//
@@ -126,7 +96,7 @@ void ColorEdit::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
QColor color(m_color);
- QColorDialog dialog(color, 0);
+ QColorDialog dialog(color, nullptr);
dialog.setOption(QColorDialog::ShowAlphaChannel, true);
dialog.move(280, 120);
if (dialog.exec() == QDialog::Rejected)
@@ -179,17 +149,6 @@ void FloatEdit::editDone()
//============================================================================//
// TwoSidedGraphicsWidget //
//============================================================================//
-
-TwoSidedGraphicsWidget::TwoSidedGraphicsWidget(QGraphicsScene *scene)
- : QObject(scene)
- , m_current(0)
- , m_angle(0)
- , m_delta(0)
-{
- for (int i = 0; i < 2; ++i)
- m_proxyWidgets[i] = 0;
-}
-
void TwoSidedGraphicsWidget::setWidget(int index, QWidget *widget)
{
if (index < 0 || index >= 2)
@@ -201,8 +160,7 @@ void TwoSidedGraphicsWidget::setWidget(int index, QWidget *widget)
GraphicsWidget *proxy = new GraphicsWidget;
proxy->setWidget(widget);
- if (m_proxyWidgets[index])
- delete m_proxyWidgets[index];
+ delete m_proxyWidgets[index];
m_proxyWidgets[index] = proxy;
proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache);
@@ -219,7 +177,7 @@ QWidget *TwoSidedGraphicsWidget::widget(int index)
if (index < 0 || index >= 2)
{
qWarning("TwoSidedGraphicsWidget::widget: Index out of bounds, index == %d", index);
- return 0;
+ return nullptr;
}
return m_proxyWidgets[index]->widget();
}
@@ -289,7 +247,7 @@ void GraphicsWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
//============================================================================//
RenderOptionsDialog::RenderOptionsDialog()
- : QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
+ : QDialog(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
{
setWindowOpacity(0.75);
setWindowTitle(tr("Options (double click to flip)"));
@@ -423,7 +381,7 @@ void RenderOptionsDialog::mouseDoubleClickEvent(QMouseEvent *event)
//============================================================================//
ItemDialog::ItemDialog()
- : QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
+ : QDialog(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
{
setWindowTitle(tr("Items (double click to flip)"));
setWindowOpacity(0.75);
@@ -487,10 +445,10 @@ Scene::Scene(int width, int height, int maxTextureSize)
, m_currentTexture(0)
, m_dynamicCubemap(false)
, m_updateAllCubemaps(true)
- , m_box(0)
- , m_vertexShader(0)
- , m_environmentShader(0)
- , m_environmentProgram(0)
+ , m_box(nullptr)
+ , m_vertexShader(nullptr)
+ , m_environmentShader(nullptr)
+ , m_environmentProgram(nullptr)
{
setSceneRect(0, 0, width, height);
@@ -564,9 +522,8 @@ void Scene::initGL()
const int NOISE_SIZE = 128; // for a different size, B and BM in fbm.c must also be changed
m_noise = new GLTexture3D(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE);
- QRgb *data = new QRgb[NOISE_SIZE * NOISE_SIZE * NOISE_SIZE];
- memset(data, 0, NOISE_SIZE * NOISE_SIZE * NOISE_SIZE * sizeof(QRgb));
- QRgb *p = data;
+ QVector<QRgb> data(NOISE_SIZE * NOISE_SIZE * NOISE_SIZE, QRgb(0));
+ QRgb *p = data.data();
float pos[3];
for (int k = 0; k < NOISE_SIZE; ++k) {
pos[2] = k * (0x20 / (float)NOISE_SIZE);
@@ -581,8 +538,7 @@ void Scene::initGL()
}
}
}
- m_noise->load(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE, data);
- delete[] data;
+ m_noise->load(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE, data.data());
m_mainCubemap = new GLRenderTargetCube(512);
@@ -634,7 +590,7 @@ void Scene::initGL()
m_renderOptions->addShader(file.baseName());
program->bind();
- m_cubemaps << ((program->uniformLocation("env") != -1) ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : 0);
+ m_cubemaps << ((program->uniformLocation("env") != -1) ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : nullptr);
program->release();
}
diff --git a/examples/widgets/graphicsview/boxes/scene.h b/examples/widgets/graphicsview/boxes/scene.h
index ffff01358f..5d65dc71e2 100644
--- a/examples/widgets/graphicsview/boxes/scene.h
+++ b/examples/widgets/graphicsview/boxes/scene.h
@@ -51,17 +51,12 @@
#ifndef SCENE_H
#define SCENE_H
-//#include <GL/glew.h>
+#include "glbuffers.h"
#include "glextensions.h"
-
-#include <QtWidgets>
-#include <QtOpenGL>
-
-#include "roundedbox.h"
#include "gltrianglemesh.h"
-#include "trackball.h"
-#include "glbuffers.h"
#include "qtbox.h"
+#include "roundedbox.h"
+#include "trackball.h"
QT_BEGIN_NAMESPACE
class QMatrix4x4;
@@ -116,7 +111,7 @@ private:
class GraphicsWidget : public QGraphicsProxyWidget
{
public:
- GraphicsWidget() : QGraphicsProxyWidget(0, Qt::Window) {}
+ GraphicsWidget() : QGraphicsProxyWidget(nullptr, Qt::Window) {}
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
void resizeEvent(QGraphicsSceneResizeEvent *event) override;
@@ -127,7 +122,7 @@ class TwoSidedGraphicsWidget : public QObject
{
Q_OBJECT
public:
- TwoSidedGraphicsWidget(QGraphicsScene *scene);
+ using QObject::QObject;
void setWidget(int index, QWidget *widget);
QWidget *widget(int index);
public slots:
@@ -135,10 +130,10 @@ public slots:
protected slots:
void animateFlip();
private:
- GraphicsWidget *m_proxyWidgets[2];
- int m_current;
- int m_angle; // angle in degrees
- int m_delta;
+ GraphicsWidget *m_proxyWidgets[2] = {nullptr, nullptr};
+ int m_current = 0;
+ int m_angle = 0; // angle in degrees
+ int m_delta = 0;
};
class RenderOptionsDialog : public QDialog
diff --git a/examples/widgets/graphicsview/boxes/trackball.cpp b/examples/widgets/graphicsview/boxes/trackball.cpp
index 794ce7ac37..b9dfc1fc7f 100644
--- a/examples/widgets/graphicsview/boxes/trackball.cpp
+++ b/examples/widgets/graphicsview/boxes/trackball.cpp
@@ -50,34 +50,21 @@
#include "trackball.h"
#include "scene.h"
-#include <qmath.h>
-#include <cmath>
//============================================================================//
// TrackBall //
//============================================================================//
TrackBall::TrackBall(TrackMode mode)
- : m_angularVelocity(0)
- , m_paused(false)
- , m_pressed(false)
- , m_mode(mode)
+ : TrackBall(0, QVector3D(0, 1, 0), mode)
{
- m_axis = QVector3D(0, 1, 0);
- m_rotation = QQuaternion();
- m_lastTime = QTime::currentTime();
}
TrackBall::TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode)
: m_axis(axis)
, m_angularVelocity(angularVelocity)
- , m_paused(false)
- , m_pressed(false)
, m_mode(mode)
-{
- m_rotation = QQuaternion();
- m_lastTime = QTime::currentTime();
-}
+{}
void TrackBall::push(const QPointF& p, const QQuaternion &)
{
diff --git a/examples/widgets/graphicsview/boxes/trackball.h b/examples/widgets/graphicsview/boxes/trackball.h
index e65080e089..af90e4d842 100644
--- a/examples/widgets/graphicsview/boxes/trackball.h
+++ b/examples/widgets/graphicsview/boxes/trackball.h
@@ -51,10 +51,9 @@
#ifndef TRACKBALL_H
#define TRACKBALL_H
-#include <QtWidgets>
-
-#include <QtGui/qvector3d.h>
-#include <QtGui/qquaternion.h>
+#include <QQuaternion>
+#include <QTime>
+#include <QVector3D>
class TrackBall
{
@@ -65,24 +64,24 @@ public:
Sphere,
};
TrackBall(TrackMode mode = Sphere);
- TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode = Sphere);
+ TrackBall(float angularVelocity, const QVector3D &axis, TrackMode mode = Sphere);
// coordinates in [-1,1]x[-1,1]
- void push(const QPointF& p, const QQuaternion &transformation);
- void move(const QPointF& p, const QQuaternion &transformation);
- void release(const QPointF& p, const QQuaternion &transformation);
+ void push(const QPointF &p, const QQuaternion &transformation);
+ void move(const QPointF &p, const QQuaternion &transformation);
+ void release(const QPointF &p, const QQuaternion &transformation);
void start(); // starts clock
void stop(); // stops clock
QQuaternion rotation() const;
private:
QQuaternion m_rotation;
- QVector3D m_axis;
- float m_angularVelocity;
+ QVector3D m_axis = QVector3D(0, 1, 0);
+ float m_angularVelocity = 0;
QPointF m_lastPos;
- QTime m_lastTime;
- bool m_paused;
- bool m_pressed;
+ QTime m_lastTime = QTime::currentTime();
TrackMode m_mode;
+ bool m_paused = false;
+ bool m_pressed = false;
};
#endif
diff --git a/examples/widgets/graphicsview/chip/chip.cpp b/examples/widgets/graphicsview/chip/chip.cpp
index 3d2bbdfcef..25f4ccc2e9 100644
--- a/examples/widgets/graphicsview/chip/chip.cpp
+++ b/examples/widgets/graphicsview/chip/chip.cpp
@@ -50,7 +50,9 @@
#include "chip.h"
-#include <QtWidgets>
+#include <QGraphicsSceneMouseEvent>
+#include <QPainter>
+#include <QStyleOptionGraphicsItem>
Chip::Chip(const QColor &color, int x, int y)
{
diff --git a/examples/widgets/graphicsview/chip/mainwindow.cpp b/examples/widgets/graphicsview/chip/mainwindow.cpp
index b6e1313eb2..f2f89c8722 100644
--- a/examples/widgets/graphicsview/chip/mainwindow.cpp
+++ b/examples/widgets/graphicsview/chip/mainwindow.cpp
@@ -56,13 +56,11 @@
#include <QSplitter>
MainWindow::MainWindow(QWidget *parent)
- : QWidget(parent)
+ : QWidget(parent), scene(new QGraphicsScene(this))
+ , h1Splitter(new QSplitter(this)), h2Splitter(new QSplitter(this))
{
populateScene();
- h1Splitter = new QSplitter;
- h2Splitter = new QSplitter;
-
QSplitter *vSplitter = new QSplitter;
vSplitter->setOrientation(Qt::Vertical);
vSplitter->addWidget(h1Splitter);
@@ -93,8 +91,6 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::populateScene()
{
- scene = new QGraphicsScene(this);
-
QImage image(":/qt4logo.png");
// Populate scene
diff --git a/examples/widgets/graphicsview/chip/mainwindow.h b/examples/widgets/graphicsview/chip/mainwindow.h
index 9417d12d7a..3f91b2efb4 100644
--- a/examples/widgets/graphicsview/chip/mainwindow.h
+++ b/examples/widgets/graphicsview/chip/mainwindow.h
@@ -62,7 +62,7 @@ class MainWindow : public QWidget
{
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
+ MainWindow(QWidget *parent = nullptr);
private:
void setupMatrix();
diff --git a/examples/widgets/graphicsview/chip/view.cpp b/examples/widgets/graphicsview/chip/view.cpp
index 7d5fd699a4..21998dc2df 100644
--- a/examples/widgets/graphicsview/chip/view.cpp
+++ b/examples/widgets/graphicsview/chip/view.cpp
@@ -62,7 +62,7 @@
#else
#include <QtWidgets>
#endif
-#include <qmath.h>
+#include <QtMath>
#if QT_CONFIG(wheelevent)
void GraphicsView::wheelEvent(QWheelEvent *e)
diff --git a/examples/widgets/graphicsview/chip/view.h b/examples/widgets/graphicsview/chip/view.h
index 89b2e813f1..ea7bd414f5 100644
--- a/examples/widgets/graphicsview/chip/view.h
+++ b/examples/widgets/graphicsview/chip/view.h
@@ -81,7 +81,7 @@ class View : public QFrame
{
Q_OBJECT
public:
- explicit View(const QString &name, QWidget *parent = 0);
+ explicit View(const QString &name, QWidget *parent = nullptr);
QGraphicsView *view() const;
diff --git a/examples/widgets/graphicsview/collidingmice/main.cpp b/examples/widgets/graphicsview/collidingmice/main.cpp
index dfb20815b9..ef6d6cca64 100644
--- a/examples/widgets/graphicsview/collidingmice/main.cpp
+++ b/examples/widgets/graphicsview/collidingmice/main.cpp
@@ -48,13 +48,12 @@
**
****************************************************************************/
+#include <QtMath>
#include <QtWidgets>
-#include <math.h>
-
#include "mouse.h"
-static const int MouseCount = 7;
+static constexpr int MouseCount = 7;
//! [0]
int main(int argc, char **argv)
diff --git a/examples/widgets/graphicsview/collidingmice/mouse.cpp b/examples/widgets/graphicsview/collidingmice/mouse.cpp
index a8fcc05d76..8375092c39 100644
--- a/examples/widgets/graphicsview/collidingmice/mouse.cpp
+++ b/examples/widgets/graphicsview/collidingmice/mouse.cpp
@@ -54,10 +54,10 @@
#include <QPainter>
#include <QRandomGenerator>
#include <QStyleOption>
-#include <qmath.h>
+#include <QtMath>
-const qreal Pi = M_PI;
-const qreal TwoPi = 2 * M_PI;
+constexpr qreal Pi = M_PI;
+constexpr qreal TwoPi = 2 * M_PI;
static qreal normalizeAngle(qreal angle)
{
@@ -69,9 +69,9 @@ static qreal normalizeAngle(qreal angle)
}
//! [0]
-Mouse::Mouse()
- : angle(0), speed(0), mouseEyeDirection(0),
- color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
+Mouse::Mouse() : color(QRandomGenerator::global()->bounded(256),
+ QRandomGenerator::global()->bounded(256),
+ QRandomGenerator::global()->bounded(256))
{
setRotation(QRandomGenerator::global()->bounded(360 * 16));
}
diff --git a/examples/widgets/graphicsview/collidingmice/mouse.h b/examples/widgets/graphicsview/collidingmice/mouse.h
index bd9e592242..4b165fced6 100644
--- a/examples/widgets/graphicsview/collidingmice/mouse.h
+++ b/examples/widgets/graphicsview/collidingmice/mouse.h
@@ -68,9 +68,9 @@ protected:
void advance(int step) override;
private:
- qreal angle;
- qreal speed;
- qreal mouseEyeDirection;
+ qreal angle = 0;
+ qreal speed = 0;
+ qreal mouseEyeDirection = 0;
QColor color;
};
//! [0]
diff --git a/examples/widgets/graphicsview/diagramscene/arrow.cpp b/examples/widgets/graphicsview/diagramscene/arrow.cpp
index 525e0b3fbb..9b2472bb33 100644
--- a/examples/widgets/graphicsview/diagramscene/arrow.cpp
+++ b/examples/widgets/graphicsview/diagramscene/arrow.cpp
@@ -50,19 +50,17 @@
#include "arrow.h"
+#include "diagramitem.h"
-#include <qmath.h>
-#include <QPen>
#include <QPainter>
+#include <QPen>
+#include <QtMath>
//! [0]
Arrow::Arrow(DiagramItem *startItem, DiagramItem *endItem, QGraphicsItem *parent)
- : QGraphicsLineItem(parent)
+ : QGraphicsLineItem(parent), myStartItem(startItem), myEndItem(endItem)
{
- myStartItem = startItem;
- myEndItem = endItem;
setFlag(QGraphicsItem::ItemIsSelectable, true);
- myColor = Qt::black;
setPen(QPen(myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
}
//! [0]
@@ -98,7 +96,7 @@ void Arrow::updatePosition()
//! [4]
void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
- QWidget *)
+ QWidget *)
{
if (myStartItem->collidesWithItem(myEndItem))
return;
diff --git a/examples/widgets/graphicsview/diagramscene/arrow.h b/examples/widgets/graphicsview/diagramscene/arrow.h
index e0fa389d53..13001959bd 100644
--- a/examples/widgets/graphicsview/diagramscene/arrow.h
+++ b/examples/widgets/graphicsview/diagramscene/arrow.h
@@ -53,16 +53,7 @@
#include <QGraphicsLineItem>
-#include "diagramitem.h"
-
-QT_BEGIN_NAMESPACE
-class QGraphicsPolygonItem;
-class QGraphicsLineItem;
-class QGraphicsScene;
-class QRectF;
-class QGraphicsSceneMouseEvent;
-class QPainterPath;
-QT_END_NAMESPACE
+class DiagramItem;
//! [0]
class Arrow : public QGraphicsLineItem
@@ -71,7 +62,7 @@ public:
enum { Type = UserType + 4 };
Arrow(DiagramItem *startItem, DiagramItem *endItem,
- QGraphicsItem *parent = 0);
+ QGraphicsItem *parent = nullptr);
int type() const override { return Type; }
QRectF boundingRect() const override;
@@ -83,13 +74,14 @@ public:
void updatePosition();
protected:
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget = nullptr) override;
private:
DiagramItem *myStartItem;
DiagramItem *myEndItem;
- QColor myColor;
QPolygonF arrowHead;
+ QColor myColor = Qt::black;
};
//! [0]
diff --git a/examples/widgets/graphicsview/diagramscene/diagramitem.cpp b/examples/widgets/graphicsview/diagramscene/diagramitem.cpp
index 3aa685635e..8ec577170b 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramitem.cpp
+++ b/examples/widgets/graphicsview/diagramscene/diagramitem.cpp
@@ -58,12 +58,10 @@
//! [0]
DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
- QGraphicsItem *parent)
- : QGraphicsPolygonItem(parent)
+ QGraphicsItem *parent)
+ : QGraphicsPolygonItem(parent), myDiagramType(diagramType)
+ , myContextMenu(contextMenu)
{
- myDiagramType = diagramType;
- myContextMenu = contextMenu;
-
QPainterPath path;
switch (myDiagramType) {
case StartEnd:
@@ -101,17 +99,17 @@ DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
//! [1]
void DiagramItem::removeArrow(Arrow *arrow)
{
- int index = arrows.indexOf(arrow);
-
- if (index != -1)
- arrows.removeAt(index);
+ arrows.removeAll(arrow);
}
//! [1]
//! [2]
void DiagramItem::removeArrows()
{
- for (Arrow *arrow : qAsConst(arrows)) {
+ // need a copy here since removeArrow() will
+ // modify the arrows container
+ const auto arrowsCopy = arrows;
+ for (Arrow *arrow : arrowsCopy) {
arrow->startItem()->removeArrow(arrow);
arrow->endItem()->removeArrow(arrow);
scene()->removeItem(arrow);
diff --git a/examples/widgets/graphicsview/diagramscene/diagramitem.h b/examples/widgets/graphicsview/diagramscene/diagramitem.h
index 3a43ec57fc..ffaea4b7a8 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramitem.h
+++ b/examples/widgets/graphicsview/diagramscene/diagramitem.h
@@ -52,19 +52,12 @@
#define DIAGRAMITEM_H
#include <QGraphicsPixmapItem>
-#include <QList>
+#include <QVector>
QT_BEGIN_NAMESPACE
class QPixmap;
-class QGraphicsItem;
-class QGraphicsScene;
-class QTextEdit;
-class QGraphicsSceneMouseEvent;
-class QMenu;
class QGraphicsSceneContextMenuEvent;
-class QPainter;
-class QStyleOptionGraphicsItem;
-class QWidget;
+class QMenu;
class QPolygonF;
QT_END_NAMESPACE
@@ -77,7 +70,7 @@ public:
enum { Type = UserType + 15 };
enum DiagramType { Step, Conditional, StartEnd, Io };
- DiagramItem(DiagramType diagramType, QMenu *contextMenu, QGraphicsItem *parent = 0);
+ DiagramItem(DiagramType diagramType, QMenu *contextMenu, QGraphicsItem *parent = nullptr);
void removeArrow(Arrow *arrow);
void removeArrows();
@@ -85,7 +78,7 @@ public:
QPolygonF polygon() const { return myPolygon; }
void addArrow(Arrow *arrow);
QPixmap image() const;
- int type() const override { return Type;}
+ int type() const override { return Type; }
protected:
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
@@ -95,7 +88,7 @@ private:
DiagramType myDiagramType;
QPolygonF myPolygon;
QMenu *myContextMenu;
- QList<Arrow *> arrows;
+ QVector<Arrow *> arrows;
};
//! [0]
diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.cpp b/examples/widgets/graphicsview/diagramscene/diagramscene.cpp
index 40272834c3..d0688d8552 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramscene.cpp
+++ b/examples/widgets/graphicsview/diagramscene/diagramscene.cpp
@@ -51,8 +51,8 @@
#include "diagramscene.h"
#include "arrow.h"
-#include <QTextCursor>
#include <QGraphicsSceneMouseEvent>
+#include <QTextCursor>
//! [0]
DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
@@ -61,8 +61,8 @@ DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
myItemMenu = itemMenu;
myMode = MoveItem;
myItemType = DiagramItem::Step;
- line = 0;
- textItem = 0;
+ line = nullptr;
+ textItem = nullptr;
myItemColor = Qt::white;
myTextColor = Qt::black;
myLineColor = Qt::black;
@@ -188,7 +188,7 @@ void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
//! [10]
void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
- if (myMode == InsertLine && line != 0) {
+ if (myMode == InsertLine && line != nullptr) {
QLineF newLine(line->line().p1(), mouseEvent->scenePos());
line->setLine(newLine);
} else if (myMode == MoveItem) {
@@ -200,7 +200,7 @@ void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
//! [11]
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
- if (line != 0 && myMode == InsertLine) {
+ if (line != nullptr && myMode == InsertLine) {
QList<QGraphicsItem *> startItems = items(line->line().p1());
if (startItems.count() && startItems.first() == line)
startItems.removeFirst();
@@ -228,7 +228,7 @@ void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
}
}
//! [12] //! [13]
- line = 0;
+ line = nullptr;
QGraphicsScene::mouseReleaseEvent(mouseEvent);
}
//! [13]
diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.h b/examples/widgets/graphicsview/diagramscene/diagramscene.h
index 15063d58b7..5682468ef6 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramscene.h
+++ b/examples/widgets/graphicsview/diagramscene/diagramscene.h
@@ -74,7 +74,7 @@ class DiagramScene : public QGraphicsScene
public:
enum Mode { InsertItem, InsertLine, InsertText, MoveItem };
- explicit DiagramScene(QMenu *itemMenu, QObject *parent = 0);
+ explicit DiagramScene(QMenu *itemMenu, QObject *parent = nullptr);
QFont font() const { return myFont; }
QColor textColor() const { return myTextColor; }
QColor itemColor() const { return myItemColor; }
diff --git a/examples/widgets/graphicsview/diagramscene/diagramtextitem.h b/examples/widgets/graphicsview/diagramscene/diagramtextitem.h
index f5d3d3b95e..7809609e24 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramtextitem.h
+++ b/examples/widgets/graphicsview/diagramscene/diagramtextitem.h
@@ -52,12 +52,8 @@
#define DIAGRAMTEXTITEM_H
#include <QGraphicsTextItem>
-#include <QPen>
QT_BEGIN_NAMESPACE
-class QFocusEvent;
-class QGraphicsItem;
-class QGraphicsScene;
class QGraphicsSceneMouseEvent;
QT_END_NAMESPACE
@@ -69,7 +65,7 @@ class DiagramTextItem : public QGraphicsTextItem
public:
enum { Type = UserType + 3 };
- DiagramTextItem(QGraphicsItem *parent = 0);
+ DiagramTextItem(QGraphicsItem *parent = nullptr);
int type() const override { return Type; }
diff --git a/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp b/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp
index 262e18a317..23fb5fda50 100644
--- a/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp
+++ b/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp
@@ -48,10 +48,18 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "coloritem.h"
+#include <QApplication>
+#include <QBitmap>
+#include <QCursor>
+#include <QDrag>
+#include <QGraphicsSceneMouseEvent>
+#include <QMimeData>
+#include <QPainter>
+#include <QRandomGenerator>
+#include <QWidget>
+
//! [0]
ColorItem::ColorItem()
: color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
@@ -128,7 +136,7 @@ void ColorItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
QPainter painter(&pixmap);
painter.translate(15, 15);
painter.setRenderHint(QPainter::Antialiasing);
- paint(&painter, 0, 0);
+ paint(&painter, nullptr, nullptr);
painter.end();
pixmap.setMask(pixmap.createHeuristicMask());
diff --git a/examples/widgets/graphicsview/dragdroprobot/main.cpp b/examples/widgets/graphicsview/dragdroprobot/main.cpp
index 045e184569..b00e9705d4 100644
--- a/examples/widgets/graphicsview/dragdroprobot/main.cpp
+++ b/examples/widgets/graphicsview/dragdroprobot/main.cpp
@@ -48,19 +48,20 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
+#include <QGraphicsScene>
+#include <QGraphicsView>
#include "coloritem.h"
#include "robot.h"
-#include <math.h>
+#include <cmath>
+
class GraphicsView : public QGraphicsView
{
public:
- GraphicsView(QGraphicsScene *scene) : QGraphicsView(scene)
- {
- }
+ using QGraphicsView::QGraphicsView;
protected:
void resizeEvent(QResizeEvent *) override
@@ -96,7 +97,7 @@ int main(int argc, char **argv)
view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view.setBackgroundBrush(QColor(230, 200, 167));
view.setWindowTitle("Drag and Drop Robot");
- view.show();
+ view.show();
return app.exec();
}
diff --git a/examples/widgets/graphicsview/dragdroprobot/robot.cpp b/examples/widgets/graphicsview/dragdroprobot/robot.cpp
index cc70366872..7457dabf8a 100644
--- a/examples/widgets/graphicsview/dragdroprobot/robot.cpp
+++ b/examples/widgets/graphicsview/dragdroprobot/robot.cpp
@@ -48,13 +48,17 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "robot.h"
+#include <QGraphicsSceneDragDropEvent>
+#include <QMimeData>
+#include <QPainter>
+#include <QParallelAnimationGroup>
+#include <QPropertyAnimation>
+
//! [0]
RobotPart::RobotPart(QGraphicsItem *parent)
- : QGraphicsObject(parent), color(Qt::lightGray), dragOver(false)
+ : QGraphicsObject(parent), color(Qt::lightGray)
{
setAcceptDrops(true);
}
@@ -157,11 +161,6 @@ void RobotHead::dropEvent(QGraphicsSceneDragDropEvent *event)
}
//! [8]
-RobotTorso::RobotTorso(QGraphicsItem *parent)
- : RobotPart(parent)
-{
-}
-
QRectF RobotTorso::boundingRect() const
{
return QRectF(-30, -20, 60, 60);
diff --git a/examples/widgets/graphicsview/dragdroprobot/robot.h b/examples/widgets/graphicsview/dragdroprobot/robot.h
index e25966c7c4..67f6bb4100 100644
--- a/examples/widgets/graphicsview/dragdroprobot/robot.h
+++ b/examples/widgets/graphicsview/dragdroprobot/robot.h
@@ -62,15 +62,15 @@ QT_END_NAMESPACE
class RobotPart : public QGraphicsObject
{
public:
- RobotPart(QGraphicsItem *parent = 0);
+ RobotPart(QGraphicsItem *parent = nullptr);
protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override;
void dropEvent(QGraphicsSceneDragDropEvent *event) override;
- QColor color;
- bool dragOver;
+ QColor color = Qt::lightGray;
+ bool dragOver = false;
};
//! [0]
@@ -78,10 +78,10 @@ protected:
class RobotHead : public RobotPart
{
public:
- RobotHead(QGraphicsItem *parent = 0);
+ RobotHead(QGraphicsItem *parent = nullptr);
QRectF boundingRect() const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
@@ -96,10 +96,10 @@ private:
class RobotTorso : public RobotPart
{
public:
- RobotTorso(QGraphicsItem *parent = 0);
+ using RobotPart::RobotPart;
QRectF boundingRect() const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
};
//! [2]
@@ -107,10 +107,10 @@ public:
class RobotLimb : public RobotPart
{
public:
- RobotLimb(QGraphicsItem *parent = 0);
+ RobotLimb(QGraphicsItem *parent = nullptr);
QRectF boundingRect() const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
};
//! [3]
@@ -118,10 +118,10 @@ public:
class Robot : public RobotPart
{
public:
- Robot(QGraphicsItem *parent = 0);
+ Robot(QGraphicsItem *parent = nullptr);
QRectF boundingRect() const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
};
//! [4]
diff --git a/examples/widgets/graphicsview/elasticnodes/edge.cpp b/examples/widgets/graphicsview/elasticnodes/edge.cpp
index aec12b4225..9ca8b37f3d 100644
--- a/examples/widgets/graphicsview/elasticnodes/edge.cpp
+++ b/examples/widgets/graphicsview/elasticnodes/edge.cpp
@@ -51,16 +51,14 @@
#include "edge.h"
#include "node.h"
-#include <qmath.h>
#include <QPainter>
+#include <QtMath>
//! [0]
Edge::Edge(Node *sourceNode, Node *destNode)
- : arrowSize(10)
+ : source(sourceNode), dest(destNode)
{
- setAcceptedMouseButtons(0);
- source = sourceNode;
- dest = destNode;
+ setAcceptedMouseButtons(Qt::NoButton);
source->addEdge(this);
dest->addEdge(this);
adjust();
diff --git a/examples/widgets/graphicsview/elasticnodes/edge.h b/examples/widgets/graphicsview/elasticnodes/edge.h
index 19072b8b33..048d3ffd02 100644
--- a/examples/widgets/graphicsview/elasticnodes/edge.h
+++ b/examples/widgets/graphicsview/elasticnodes/edge.h
@@ -78,7 +78,7 @@ private:
QPointF sourcePoint;
QPointF destPoint;
- qreal arrowSize;
+ qreal arrowSize = 10;
};
//! [0]
diff --git a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
index 9341d77f8d..a067f82ad7 100644
--- a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
+++ b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
@@ -59,7 +59,7 @@
//! [0]
GraphWidget::GraphWidget(QWidget *parent)
- : QGraphicsView(parent), timerId(0)
+ : QGraphicsView(parent)
{
QGraphicsScene *scene = new QGraphicsScene(this);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
@@ -163,7 +163,7 @@ void GraphWidget::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event);
- QList<Node *> nodes;
+ QVector<Node *> nodes;
const QList<QGraphicsItem *> items = scene()->items();
for (QGraphicsItem *item : items) {
if (Node *node = qgraphicsitem_cast<Node *>(item))
@@ -190,7 +190,7 @@ void GraphWidget::timerEvent(QTimerEvent *event)
//! [5]
void GraphWidget::wheelEvent(QWheelEvent *event)
{
- scaleView(pow((double)2, -event->angleDelta().y() / 240.0));
+ scaleView(pow(2., -event->angleDelta().y() / 240.0));
}
//! [5]
#endif
diff --git a/examples/widgets/graphicsview/elasticnodes/graphwidget.h b/examples/widgets/graphicsview/elasticnodes/graphwidget.h
index 5ed6aed452..6d241fa9f1 100644
--- a/examples/widgets/graphicsview/elasticnodes/graphwidget.h
+++ b/examples/widgets/graphicsview/elasticnodes/graphwidget.h
@@ -61,7 +61,7 @@ class GraphWidget : public QGraphicsView
Q_OBJECT
public:
- GraphWidget(QWidget *parent = 0);
+ GraphWidget(QWidget *parent = nullptr);
void itemMoved();
@@ -81,7 +81,7 @@ protected:
void scaleView(qreal scaleFactor);
private:
- int timerId;
+ int timerId = 0;
Node *centerNode;
};
//! [0]
diff --git a/examples/widgets/graphicsview/elasticnodes/node.cpp b/examples/widgets/graphicsview/elasticnodes/node.cpp
index 8d44a167fa..a67e21c4b3 100644
--- a/examples/widgets/graphicsview/elasticnodes/node.cpp
+++ b/examples/widgets/graphicsview/elasticnodes/node.cpp
@@ -75,7 +75,7 @@ void Node::addEdge(Edge *edge)
edge->adjust();
}
-QList<Edge *> Node::edges() const
+QVector<Edge *> Node::edges() const
{
return edgeList;
}
diff --git a/examples/widgets/graphicsview/elasticnodes/node.h b/examples/widgets/graphicsview/elasticnodes/node.h
index 43ea1fb24b..b160ff37cc 100644
--- a/examples/widgets/graphicsview/elasticnodes/node.h
+++ b/examples/widgets/graphicsview/elasticnodes/node.h
@@ -52,13 +52,10 @@
#define NODE_H
#include <QGraphicsItem>
-#include <QList>
+#include <QVector>
class Edge;
class GraphWidget;
-QT_BEGIN_NAMESPACE
-class QGraphicsSceneMouseEvent;
-QT_END_NAMESPACE
//! [0]
class Node : public QGraphicsItem
@@ -67,7 +64,7 @@ public:
Node(GraphWidget *graphWidget);
void addEdge(Edge *edge);
- QList<Edge *> edges() const;
+ QVector<Edge *> edges() const;
enum { Type = UserType + 1 };
int type() const override { return Type; }
@@ -86,7 +83,7 @@ protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
private:
- QList<Edge *> edgeList;
+ QVector<Edge *> edgeList;
QPointF newPos;
GraphWidget *graph;
};
diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp b/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp
index f510ebc07f..6eda94e8ba 100644
--- a/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp
+++ b/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp
@@ -50,14 +50,13 @@
#include "customproxy.h"
-#include <QStyleOptionGraphicsItem>
-#include <QPainter>
#include <QGraphicsScene>
+#include <QPainter>
+#include <QStyleOptionGraphicsItem>
CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags)
- : QGraphicsProxyWidget(parent, wFlags), popupShown(false), currentPopup(nullptr)
+ : QGraphicsProxyWidget(parent, wFlags), timeLine(new QTimeLine(250, this))
{
- timeLine = new QTimeLine(250, this);
connect(timeLine, &QTimeLine::valueChanged,
this, &CustomProxy::updateStep);
connect(timeLine, &QTimeLine::stateChanged,
@@ -99,7 +98,7 @@ void CustomProxy::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
QGraphicsProxyWidget::hoverEnterEvent(event);
scene()->setActiveWindow(this);
- if (timeLine->currentValue() != 1)
+ if (qFuzzyCompare(timeLine->currentValue(), 1))
zoomIn();
}
@@ -107,7 +106,7 @@ void CustomProxy::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
QGraphicsProxyWidget::hoverLeaveEvent(event);
if (!popupShown
- && (timeLine->direction() != QTimeLine::Backward || timeLine->currentValue() != 0)) {
+ && (timeLine->direction() != QTimeLine::Backward || qFuzzyIsNull(timeLine->currentValue()))) {
zoomOut();
}
}
diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
index 36209b7073..d7df2b7b4b 100644
--- a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
+++ b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
@@ -59,7 +59,7 @@ class CustomProxy : public QGraphicsProxyWidget
Q_OBJECT
public:
- explicit CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
+ explicit CustomProxy(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = nullptr);
QRectF boundingRect() const override;
void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
@@ -79,8 +79,8 @@ private slots:
private:
QTimeLine *timeLine;
- bool popupShown;
- QGraphicsItem *currentPopup;
+ QGraphicsItem *currentPopup = nullptr;
+ bool popupShown = false;
};
#endif // CUSTOMPROXY_H
diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h
index 29daaa58c1..c2d87a5660 100644
--- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h
+++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h
@@ -64,7 +64,7 @@ class EmbeddedDialog : public QDialog
Q_OBJECT
public:
- EmbeddedDialog(QWidget *parent = 0);
+ EmbeddedDialog(QWidget *parent = nullptr);
~EmbeddedDialog();
private slots:
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.cpp b/examples/widgets/graphicsview/flowlayout/flowlayout.cpp
index ab6bbb7aa4..03cf320568 100644
--- a/examples/widgets/graphicsview/flowlayout/flowlayout.cpp
+++ b/examples/widgets/graphicsview/flowlayout/flowlayout.cpp
@@ -50,14 +50,10 @@
#include "flowlayout.h"
-#include <qmath.h>
+#include <QtMath>
-#include <QWidget>
-
-FlowLayout::FlowLayout()
+FlowLayout::FlowLayout(QGraphicsLayoutItem *parent) : QGraphicsLayout(parent)
{
- m_spacing[0] = 6;
- m_spacing[1] = 6;
QSizePolicy sp = sizePolicy();
sp.setHeightForWidth(true);
setSizePolicy(sp);
@@ -66,7 +62,7 @@ FlowLayout::FlowLayout()
void FlowLayout::insertItem(int index, QGraphicsLayoutItem *item)
{
item->setParentLayoutItem(this);
- if (uint(index) > uint(m_items.count()))
+ if (index > m_items.count() || index < 0)
index = m_items.count();
m_items.insert(index, item);
invalidate();
@@ -117,15 +113,14 @@ qreal FlowLayout::doLayout(const QRectF &geom, bool applyNewGeometry) const
qreal y = 0;
qreal maxRowHeight = 0;
QSizeF pref;
- for (int i = 0; i < m_items.count(); ++i) {
- QGraphicsLayoutItem *item = m_items.at(i);
+ for (QGraphicsLayoutItem *item : m_items) {
pref = item->effectiveSizeHint(Qt::PreferredSize);
maxRowHeight = qMax(maxRowHeight, pref.height());
qreal next_x;
next_x = x + pref.width();
if (next_x > maxw) {
- if (x == 0) {
+ if (qFuzzyIsNull(x)) {
pref.setWidth(maxw);
} else {
x = 0;
@@ -156,7 +151,7 @@ QSizeF FlowLayout::minSize(const QSizeF &constraint) const
} else {
for (const QGraphicsLayoutItem *item : qAsConst(m_items))
size = size.expandedTo(item->effectiveSizeHint(Qt::MinimumSize));
- size += QSize(left + right, top + bottom);
+ size += QSizeF(left + right, top + bottom);
}
return size;
}
@@ -164,7 +159,7 @@ QSizeF FlowLayout::minSize(const QSizeF &constraint) const
QSizeF FlowLayout::prefSize() const
{
qreal left, right;
- getContentsMargins(&left, 0, &right, 0);
+ getContentsMargins(&left, nullptr, &right, nullptr);
qreal maxh = 0;
qreal totalWidth = 0;
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.h b/examples/widgets/graphicsview/flowlayout/flowlayout.h
index 808f5d2c77..c6758414d6 100644
--- a/examples/widgets/graphicsview/flowlayout/flowlayout.h
+++ b/examples/widgets/graphicsview/flowlayout/flowlayout.h
@@ -53,7 +53,7 @@
class FlowLayout : public QGraphicsLayout
{
public:
- FlowLayout();
+ FlowLayout(QGraphicsLayoutItem *parent = nullptr);
inline void addItem(QGraphicsLayoutItem *item);
void insertItem(int index, QGraphicsLayoutItem *item);
void setSpacing(Qt::Orientations o, qreal spacing);
@@ -75,8 +75,8 @@ private:
QSizeF prefSize() const;
QSizeF maxSize() const;
- QList<QGraphicsLayoutItem*> m_items;
- qreal m_spacing[2];
+ QVector<QGraphicsLayoutItem*> m_items;
+ qreal m_spacing[2] = {6, 6};
};
diff --git a/examples/widgets/graphicsview/flowlayout/main.cpp b/examples/widgets/graphicsview/flowlayout/main.cpp
index 74c03b9bce..dbfed51bb3 100644
--- a/examples/widgets/graphicsview/flowlayout/main.cpp
+++ b/examples/widgets/graphicsview/flowlayout/main.cpp
@@ -59,12 +59,12 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
QGraphicsScene scene;
- QGraphicsView *view = new QGraphicsView(&scene);
+ QGraphicsView view(&scene);
Window *w = new Window;
scene.addItem(w);
- view->resize(400, 300);
- view->show();
+ view.resize(400, 300);
+ view.show();
return app.exec();
}
diff --git a/examples/widgets/graphicsview/flowlayout/window.cpp b/examples/widgets/graphicsview/flowlayout/window.cpp
index 34d0d71b44..8fe06d0e11 100644
--- a/examples/widgets/graphicsview/flowlayout/window.cpp
+++ b/examples/widgets/graphicsview/flowlayout/window.cpp
@@ -48,23 +48,21 @@
**
****************************************************************************/
-#include "flowlayout.h"
#include "window.h"
+#include "flowlayout.h"
#include <QGraphicsProxyWidget>
#include <QLabel>
-Window::Window()
-: QGraphicsWidget(0, Qt::Window)
+Window::Window(QGraphicsItem *parent) : QGraphicsWidget(parent, Qt::Window)
{
FlowLayout *lay = new FlowLayout;
- QLatin1String wiseWords("I am not bothered by the fact that I am unknown."
- " I am bothered when I do not know others. (Confucius)");
- QString sentence(wiseWords);
- QStringList words = sentence.split(QLatin1Char(' '), QString::SkipEmptyParts);
- for (int i = 0; i < words.count(); ++i) {
+ const QString sentence(QLatin1String("I am not bothered by the fact that I am unknown."
+ " I am bothered when I do not know others. (Confucius)"));
+ const QVector<QStringRef> words = sentence.splitRef(QLatin1Char(' '), QString::SkipEmptyParts);
+ for (const QStringRef &word : words) {
QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this);
- QLabel *label = new QLabel(words.at(i));
+ QLabel *label = new QLabel(word.toString());
label->setFrameStyle(QFrame::Box | QFrame::Plain);
proxy->setWidget(label);
lay->addItem(proxy);
diff --git a/examples/widgets/graphicsview/flowlayout/window.h b/examples/widgets/graphicsview/flowlayout/window.h
index 7f37c447d1..24a7cf908b 100644
--- a/examples/widgets/graphicsview/flowlayout/window.h
+++ b/examples/widgets/graphicsview/flowlayout/window.h
@@ -53,7 +53,6 @@
class Window : public QGraphicsWidget
{
Q_OBJECT
-
public:
- Window();
+ Window(QGraphicsItem *parent = nullptr);
};
diff --git a/examples/widgets/graphicsview/padnavigator/flippablepad.cpp b/examples/widgets/graphicsview/padnavigator/flippablepad.cpp
index e5de331597..6a9097a736 100644
--- a/examples/widgets/graphicsview/padnavigator/flippablepad.cpp
+++ b/examples/widgets/graphicsview/padnavigator/flippablepad.cpp
@@ -75,8 +75,8 @@ FlippablePad::FlippablePad(const QSize &size, QGraphicsItem *parent)
//! [2]
//! [3]
int numIcons = size.width() * size.height();
- QList<QPixmap> pixmaps;
- QDirIterator it(":/images", QStringList() << "*.png");
+ QVector<QPixmap> pixmaps;
+ QDirIterator it(":/images", {"*.png"});
while (it.hasNext() && pixmaps.size() < numIcons)
pixmaps << it.next();
//! [3]
diff --git a/examples/widgets/graphicsview/padnavigator/flippablepad.h b/examples/widgets/graphicsview/padnavigator/flippablepad.h
index 323ace4372..ef757c47fb 100644
--- a/examples/widgets/graphicsview/padnavigator/flippablepad.h
+++ b/examples/widgets/graphicsview/padnavigator/flippablepad.h
@@ -53,15 +53,13 @@
#include "roundrectitem.h"
-#include <QGraphicsObject>
-#include <QLinearGradient>
#include <QVector>
//! [0]
class FlippablePad : public RoundRectItem
{
public:
- explicit FlippablePad(const QSize &size, QGraphicsItem *parent = 0);
+ explicit FlippablePad(const QSize &size, QGraphicsItem *parent = nullptr);
RoundRectItem *iconAt(int column, int row) const;
diff --git a/examples/widgets/graphicsview/padnavigator/padnavigator.cpp b/examples/widgets/graphicsview/padnavigator/padnavigator.cpp
index ef0b0b4510..b9ce2a47ca 100644
--- a/examples/widgets/graphicsview/padnavigator/padnavigator.cpp
+++ b/examples/widgets/graphicsview/padnavigator/padnavigator.cpp
@@ -52,10 +52,18 @@
#include "padnavigator.h"
#include "splashitem.h"
+#include <QEventTransition>
+#include <QGraphicsProxyWidget>
+#include <QGraphicsRotation>
+#include <QHistoryState>
+#include <QKeyEventTransition>
+#include <QParallelAnimationGroup>
+#include <QPropertyAnimation>
+#include <QSequentialAnimationGroup>
+#include <QStateMachine>
+
#ifndef QT_NO_OPENGL
-#include <QtOpenGL>
-#else
-#include <QtWidgets>
+#include <QOpenGLWidget>
#endif
//! [0]
diff --git a/examples/widgets/graphicsview/padnavigator/padnavigator.h b/examples/widgets/graphicsview/padnavigator/padnavigator.h
index 00cf2c0212..0fe9ad045d 100644
--- a/examples/widgets/graphicsview/padnavigator/padnavigator.h
+++ b/examples/widgets/graphicsview/padnavigator/padnavigator.h
@@ -54,17 +54,12 @@
#include <QGraphicsView>
#include "ui_form.h"
-QT_BEGIN_NAMESPACE
-class QState;
-class QStateMachine;
-QT_END_NAMESPACE
-
//! [0]
class PadNavigator : public QGraphicsView
{
Q_OBJECT
public:
- explicit PadNavigator(const QSize &size, QWidget *parent = 0);
+ explicit PadNavigator(const QSize &size, QWidget *parent = nullptr);
protected:
void resizeEvent(QResizeEvent *event) override;
diff --git a/examples/widgets/graphicsview/padnavigator/roundrectitem.cpp b/examples/widgets/graphicsview/padnavigator/roundrectitem.cpp
index 82205050ec..b4ea489069 100644
--- a/examples/widgets/graphicsview/padnavigator/roundrectitem.cpp
+++ b/examples/widgets/graphicsview/padnavigator/roundrectitem.cpp
@@ -50,7 +50,7 @@
#include "roundrectitem.h"
-#include <QApplication>
+#include <QGuiApplication>
#include <QPainter>
#include <QPalette>
@@ -98,7 +98,7 @@ void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
//! [3]
//! [4]
if (fillRect)
- painter->setBrush(QApplication::palette().brush(QPalette::Window));
+ painter->setBrush(QGuiApplication::palette().brush(QPalette::Window));
else
painter->setBrush(gradient);
painter->setPen(QPen(Qt::black, 1));
diff --git a/examples/widgets/graphicsview/padnavigator/roundrectitem.h b/examples/widgets/graphicsview/padnavigator/roundrectitem.h
index e76862c08c..91b3e6542e 100644
--- a/examples/widgets/graphicsview/padnavigator/roundrectitem.h
+++ b/examples/widgets/graphicsview/padnavigator/roundrectitem.h
@@ -61,13 +61,13 @@ class RoundRectItem : public QGraphicsObject
Q_PROPERTY(bool fill READ fill WRITE setFill)
public:
RoundRectItem(const QRectF &bounds, const QColor &color,
- QGraphicsItem *parent = 0);
+ QGraphicsItem *parent = nullptr);
QPixmap pixmap() const;
void setPixmap(const QPixmap &pixmap);
QRectF boundingRect() const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
bool fill() const;
void setFill(bool fill);
diff --git a/examples/widgets/graphicsview/padnavigator/splashitem.h b/examples/widgets/graphicsview/padnavigator/splashitem.h
index 2ad54f82a1..b8e723db81 100644
--- a/examples/widgets/graphicsview/padnavigator/splashitem.h
+++ b/examples/widgets/graphicsview/padnavigator/splashitem.h
@@ -58,10 +58,10 @@ class SplashItem : public QGraphicsObject
{
Q_OBJECT
public:
- explicit SplashItem(QGraphicsItem *parent = 0);
+ explicit SplashItem(QGraphicsItem *parent = nullptr);
QRectF boundingRect() const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
private:
QString text;
diff --git a/examples/widgets/graphicsview/simpleanchorlayout/main.cpp b/examples/widgets/graphicsview/simpleanchorlayout/main.cpp
index 299a5ad7bd..a5f450c1f9 100644
--- a/examples/widgets/graphicsview/simpleanchorlayout/main.cpp
+++ b/examples/widgets/graphicsview/simpleanchorlayout/main.cpp
@@ -54,7 +54,7 @@ class Widget : public QGraphicsWidget
{
public:
Widget(const QColor &color, const QColor &textColor, const QString &caption,
- QGraphicsItem *parent = 0)
+ QGraphicsItem *parent = nullptr)
: QGraphicsWidget(parent)
, caption(caption)
, color(color)
@@ -62,7 +62,7 @@ public:
{
}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * = 0) override
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override
{
QFont font;
font.setPixelSize(0.75 * qMin(boundingRect().width(), boundingRect().height()));
@@ -85,7 +85,7 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- QGraphicsScene *scene = new QGraphicsScene();
+ QGraphicsScene scene;
Widget *a = new Widget(Qt::blue, Qt::white, "a");
a->setPreferredSize(100, 100);
@@ -94,7 +94,7 @@ int main(int argc, char *argv[])
Widget *c = new Widget(Qt::red, Qt::black, "c");
c->setPreferredSize(100, 100);
- QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout();
+ QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout;
/*
//! [adding a corner anchor in two steps]
layout->addAnchor(a, Qt::AnchorTop, layout, Qt::AnchorTop);
@@ -128,20 +128,20 @@ int main(int argc, char *argv[])
// corner of the layout.
layout->addCornerAnchors(c, Qt::BottomRightCorner, layout, Qt::BottomRightCorner);
- QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
+ auto w = new QGraphicsWidget(nullptr, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
w->setPos(20, 20);
w->setMinimumSize(100, 100);
w->setPreferredSize(320, 240);
w->setLayout(layout);
w->setWindowTitle(QApplication::translate("simpleanchorlayout", "QGraphicsAnchorLayout in use"));
- scene->addItem(w);
+ scene.addItem(w);
- QGraphicsView *view = new QGraphicsView();
- view->setScene(scene);
- view->setWindowTitle(QApplication::translate("simpleanchorlayout", "Simple Anchor Layout"));
+ QGraphicsView view;
+ view.setScene(&scene);
+ view.setWindowTitle(QApplication::translate("simpleanchorlayout", "Simple Anchor Layout"));
- view->resize(360, 320);
- view->show();
+ view.resize(360, 320);
+ view.show();
return app.exec();
}
diff --git a/examples/widgets/graphicsview/weatheranchorlayout/main.cpp b/examples/widgets/graphicsview/weatheranchorlayout/main.cpp
index 81db2780b4..5c623b1d00 100644
--- a/examples/widgets/graphicsview/weatheranchorlayout/main.cpp
+++ b/examples/widgets/graphicsview/weatheranchorlayout/main.cpp
@@ -50,15 +50,14 @@
#include <QApplication>
#include <QLabel>
-#include <QPainter>
-#include <QPushButton>
-
#include <QGraphicsAnchorLayout>
#include <QGraphicsProxyWidget>
#include <QGraphicsScene>
#include <QGraphicsSceneResizeEvent>
#include <QGraphicsView>
#include <QGraphicsWidget>
+#include <QPainter>
+#include <QPushButton>
class GraphicsView : public QGraphicsView
@@ -79,20 +78,18 @@ public:
class PixmapWidget : public QGraphicsLayoutItem
{
-
public:
PixmapWidget(const QPixmap &pix)
- : QGraphicsLayoutItem()
+ : QGraphicsLayoutItem(), original(new QGraphicsPixmapItem(pix))
+ , r(QRectF(QPointF(0, 0), pix.size()))
{
- original = new QGraphicsPixmapItem(pix);
setGraphicsItem(original);
original->show();
- r = QRectF(QPointF(0, 0), pix.size());
}
~PixmapWidget()
{
- setGraphicsItem(0);
+ setGraphicsItem(nullptr);
delete original;
}
@@ -101,7 +98,7 @@ public:
original->setZValue(z);
}
- void setGeometry (const QRectF &rect) override
+ void setGeometry(const QRectF &rect) override
{
original->setTransform(QTransform::fromScale(rect.width() / r.width(),
rect.height() / r.height()), true);
@@ -150,8 +147,7 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{
- QPointF reflection = QPointF();
- reflection.setY(scaled.height() + 2);
+ const QPointF reflection(0, scaled.height() + 2);
painter->drawPixmap(QPointF(), scaled);
@@ -239,7 +235,7 @@ int main(int argc, char *argv[])
layout->setSpacing(0);
// setup the main widget
- QGraphicsWidget *widget = new QGraphicsWidget(0, Qt::Window);
+ QGraphicsWidget *widget = new QGraphicsWidget(nullptr, Qt::Window);
QPalette p;
p.setColor(QPalette::Window, Qt::black);
widget->setPalette(p);
diff --git a/examples/widgets/itemviews/frozencolumn/main.cpp b/examples/widgets/itemviews/frozencolumn/main.cpp
index 6f2b4a8d71..2965617ba1 100644
--- a/examples/widgets/itemviews/frozencolumn/main.cpp
+++ b/examples/widgets/itemviews/frozencolumn/main.cpp
@@ -71,7 +71,7 @@ int main(int argc, char* argv[])
model->setHorizontalHeaderLabels(list);
int row = 0;
- QStandardItem *newItem = 0;
+ QStandardItem *newItem = nullptr;
while (!stream.atEnd()) {
line = stream.readLine();
if (!line.startsWith('#') && line.contains(',')) {
diff --git a/examples/widgets/itemviews/interview/model.cpp b/examples/widgets/itemviews/interview/model.cpp
index feaf8bb98c..519164999d 100644
--- a/examples/widgets/itemviews/interview/model.cpp
+++ b/examples/widgets/itemviews/interview/model.cpp
@@ -132,7 +132,7 @@ bool Model::hasChildren(const QModelIndex &parent) const
Qt::ItemFlags Model::flags(const QModelIndex &index) const
{
if (!index.isValid())
- return 0;
+ return {};
return Qt::ItemIsDragEnabled|QAbstractItemModel::flags(index);
}
@@ -146,7 +146,7 @@ Model::Node *Model::node(int row, Node *parent) const
Model::Node *Model::parent(Node *child) const
{
- return child ? child->parent : 0;
+ return child ? child->parent : nullptr;
}
int Model::row(Node *node) const
diff --git a/examples/widgets/itemviews/stardelegate/main.cpp b/examples/widgets/itemviews/stardelegate/main.cpp
index 452976bba0..5ca85a6151 100644
--- a/examples/widgets/itemviews/stardelegate/main.cpp
+++ b/examples/widgets/itemviews/stardelegate/main.cpp
@@ -48,7 +48,8 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
+#include <QTableWidget>
#include "stardelegate.h"
#include "stareditor.h"
@@ -57,7 +58,7 @@
//! [0]
void populateTableWidget(QTableWidget *tableWidget)
{
- static const struct {
+ static constexpr struct {
const char *title;
const char *genre;
const char *artist;
@@ -70,12 +71,12 @@ void populateTableWidget(QTableWidget *tableWidget)
{ "Sex Bomb", "Pop", "Tom Jones", 3 },
{ "Barbie Girl", "Pop", "Aqua", 5 },
//! [2]
- { 0, 0, 0, 0 }
+ { nullptr, nullptr, nullptr, 0 }
//! [2] //! [3]
};
//! [3] //! [4]
- for (int row = 0; staticData[row].title != 0; ++row) {
+ for (int row = 0; staticData[row].title != nullptr; ++row) {
QTableWidgetItem *item0 = new QTableWidgetItem(staticData[row].title);
QTableWidgetItem *item1 = new QTableWidgetItem(staticData[row].genre);
QTableWidgetItem *item2 = new QTableWidgetItem(staticData[row].artist);
diff --git a/examples/widgets/painting/deform/pathdeform.cpp b/examples/widgets/painting/deform/pathdeform.cpp
index 64e81f8cab..d5c8746247 100644
--- a/examples/widgets/painting/deform/pathdeform.cpp
+++ b/examples/widgets/painting/deform/pathdeform.cpp
@@ -262,7 +262,7 @@ PathDeformWidget::PathDeformWidget(QWidget *parent, bool smallScreen)
QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->addWidget(m_renderer);
- m_controls = new PathDeformControls(0, m_renderer, smallScreen);
+ m_controls = new PathDeformControls(nullptr, m_renderer, smallScreen);
m_controls->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
if (!smallScreen)
diff --git a/examples/widgets/painting/fontsampler/mainwindow.h b/examples/widgets/painting/fontsampler/mainwindow.h
index ffb2839ffa..34e54440d4 100644
--- a/examples/widgets/painting/fontsampler/mainwindow.h
+++ b/examples/widgets/painting/fontsampler/mainwindow.h
@@ -70,7 +70,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindowBase
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
+ MainWindow(QWidget *parent = nullptr);
public slots:
void on_clearAction_triggered();
diff --git a/examples/widgets/painting/gradients/gradients.cpp b/examples/widgets/painting/gradients/gradients.cpp
index a4528ce06f..d62ae93a15 100644
--- a/examples/widgets/painting/gradients/gradients.cpp
+++ b/examples/widgets/painting/gradients/gradients.cpp
@@ -102,9 +102,9 @@ uint ShadeWidget::colorAt(int x)
generateShade();
QPolygonF pts = m_hoverPoints->points();
- for (int i=1; i < pts.size(); ++i) {
- if (pts.at(i-1).x() <= x && pts.at(i).x() >= x) {
- QLineF l(pts.at(i-1), pts.at(i));
+ for (int i = 1; i < pts.size(); ++i) {
+ if (pts.at(i - 1).x() <= x && pts.at(i).x() >= x) {
+ QLineF l(pts.at(i - 1), pts.at(i));
l.setLength(l.length() * ((x - l.x1()) / l.dx()));
return m_shade.pixel(qRound(qMin(l.x2(), (qreal(m_shade.width() - 1)))),
qRound(qMin(l.y2(), qreal(m_shade.height() - 1))));
@@ -118,9 +118,9 @@ void ShadeWidget::setGradientStops(const QGradientStops &stops)
if (m_shade_type == ARGBShade) {
m_alpha_gradient = QLinearGradient(0, 0, width(), 0);
- for (int i=0; i<stops.size(); ++i) {
- QColor c = stops.at(i).second;
- m_alpha_gradient.setColorAt(stops.at(i).first, QColor(c.red(), c.green(), c.blue()));
+ for (const auto &stop : stops) {
+ QColor c = stop.second;
+ m_alpha_gradient.setColorAt(stop.first, QColor(c.red(), c.green(), c.blue()));
}
m_shade = QImage();
@@ -223,13 +223,13 @@ void GradientEditor::pointsUpdated()
std::sort(points.begin(), points.end(), x_less_than);
for (int i = 0; i < points.size(); ++i) {
- qreal x = int(points.at(i).x());
- if (i + 1 < points.size() && x == points.at(i + 1).x())
+ const int x = int(points.at(i).x());
+ if (i + 1 < points.size() && x == int(points.at(i + 1).x()))
continue;
- QColor color((0x00ff0000 & m_red_shade->colorAt(int(x))) >> 16,
- (0x0000ff00 & m_green_shade->colorAt(int(x))) >> 8,
- (0x000000ff & m_blue_shade->colorAt(int(x))),
- (0xff000000 & m_alpha_shade->colorAt(int(x))) >> 24);
+ QColor color((0x00ff0000 & m_red_shade->colorAt(x)) >> 16,
+ (0x0000ff00 & m_green_shade->colorAt(x)) >> 8,
+ (0x000000ff & m_blue_shade->colorAt(x)),
+ (0xff000000 & m_alpha_shade->colorAt(x)) >> 24);
if (x / w > 1)
return;
@@ -568,8 +568,8 @@ void GradientRenderer::paint(QPainter *p)
g = QConicalGradient(pts.at(0), angle);
}
- for (int i = 0; i < m_stops.size(); ++i)
- g.setColorAt(m_stops.at(i).first, m_stops.at(i).second);
+ for (const auto &stop : qAsConst(m_stops))
+ g.setColorAt(stop.first, stop.second);
g.setSpread(m_spread);
diff --git a/examples/widgets/painting/gradients/gradients.h b/examples/widgets/painting/gradients/gradients.h
index c6525d18f8..45ef5d0f93 100644
--- a/examples/widgets/painting/gradients/gradients.h
+++ b/examples/widgets/painting/gradients/gradients.h
@@ -157,7 +157,7 @@ class GradientWidget : public QWidget
Q_OBJECT
public:
- GradientWidget(QWidget *parent);
+ GradientWidget(QWidget *parent = nullptr);
public slots:
void setDefault1() { setDefault(1); }
diff --git a/examples/widgets/painting/gradients/main.cpp b/examples/widgets/painting/gradients/main.cpp
index 539d67e40e..0ddf7a4579 100644
--- a/examples/widgets/painting/gradients/main.cpp
+++ b/examples/widgets/painting/gradients/main.cpp
@@ -58,8 +58,8 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
- GradientWidget gradientWidget(0);
- QStyle *arthurStyle = new ArthurStyle();
+ GradientWidget gradientWidget;
+ QStyle *arthurStyle = new ArthurStyle;
gradientWidget.setStyle(arthurStyle);
const QList<QWidget *> widgets = gradientWidget.findChildren<QWidget *>();
for (QWidget *w : widgets) {
diff --git a/examples/widgets/painting/painterpaths/renderarea.h b/examples/widgets/painting/painterpaths/renderarea.h
index 5f0874b772..4b3ea5a397 100644
--- a/examples/widgets/painting/painterpaths/renderarea.h
+++ b/examples/widgets/painting/painterpaths/renderarea.h
@@ -60,7 +60,7 @@ class RenderArea : public QWidget
Q_OBJECT
public:
- explicit RenderArea(const QPainterPath &path, QWidget *parent = 0);
+ explicit RenderArea(const QPainterPath &path, QWidget *parent = nullptr);
QSize minimumSizeHint() const override;
QSize sizeHint() const override;
diff --git a/examples/widgets/painting/pathstroke/pathstroke.cpp b/examples/widgets/painting/pathstroke/pathstroke.cpp
index e4009f0b1a..a850ce2672 100644
--- a/examples/widgets/painting/pathstroke/pathstroke.cpp
+++ b/examples/widgets/painting/pathstroke/pathstroke.cpp
@@ -48,11 +48,9 @@
**
****************************************************************************/
+#include "pathstroke.h"
#include "arthurstyle.h"
#include "arthurwidgets.h"
-#include "pathstroke.h"
-
-#include <stdio.h>
extern void draw_round_rect(QPainter *p, const QRect &bounds, int radius);
@@ -164,24 +162,39 @@ void PathStrokeControls::createCommonControls(QWidget* parent)
// Connections
- connect(flatCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setFlatCap);
- connect(squareCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSquareCap);
- connect(roundCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setRoundCap);
-
- connect(bevelJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setBevelJoin);
- connect(miterJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setMiterJoin);
- connect(svgMiterJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSvgMiterJoin);
- connect(roundJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setRoundJoin);
-
- connect(curveMode, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setCurveMode);
- connect(lineMode, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setLineMode);
-
- connect(solidLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSolidLine);
- connect(dashLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashLine);
- connect(dotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDotLine);
- connect(dashDotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashDotLine);
- connect(dashDotDotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashDotDotLine);
- connect(customDashLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setCustomDashLine);
+ connect(flatCap, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setFlatCap);
+ connect(squareCap, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setSquareCap);
+ connect(roundCap, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setRoundCap);
+
+ connect(bevelJoin, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setBevelJoin);
+ connect(miterJoin, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setMiterJoin);
+ connect(svgMiterJoin, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setSvgMiterJoin);
+ connect(roundJoin, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setRoundJoin);
+
+ connect(curveMode, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setCurveMode);
+ connect(lineMode, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setLineMode);
+
+ connect(solidLine, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setSolidLine);
+ connect(dashLine, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setDashLine);
+ connect(dotLine, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setDotLine);
+ connect(dashDotLine, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setDashDotLine);
+ connect(dashDotDotLine, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setDashDotDotLine);
+ connect(customDashLine, &QAbstractButton::clicked,
+ m_renderer, &PathStrokeRenderer::setCustomDashLine);
// Set the defaults:
flatCap->setChecked(true);
@@ -247,15 +260,20 @@ void PathStrokeControls::layoutForDesktop()
// Set up connections
- connect(animated, &QAbstractButton::toggled, m_renderer, &PathStrokeRenderer::setAnimation);
+ connect(animated, &QAbstractButton::toggled,
+ m_renderer, &PathStrokeRenderer::setAnimation);
- connect(penWidth, &QAbstractSlider::valueChanged, m_renderer, &PathStrokeRenderer::setPenWidth);
+ connect(penWidth, &QAbstractSlider::valueChanged,
+ m_renderer, &PathStrokeRenderer::setPenWidth);
- connect(showSourceButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::showSource);
+ connect(showSourceButton, &QAbstractButton::clicked,
+ m_renderer, &ArthurFrame::showSource);
#if QT_CONFIG(opengl)
- connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL);
+ connect(enableOpenGLButton, &QAbstractButton::clicked,
+ m_renderer, &ArthurFrame::enableOpenGL);
#endif
- connect(whatsThisButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::setDescriptionEnabled);
+ connect(whatsThisButton, &QAbstractButton::clicked,
+ m_renderer, &ArthurFrame::setDescriptionEnabled);
connect(m_renderer, &ArthurFrame::descriptionEnabledChanged,
whatsThisButton, &QAbstractButton::setChecked);
@@ -296,11 +314,11 @@ void PathStrokeControls::layoutForSmallScreens()
#endif
// Layouts:
- QHBoxLayout *penWidthLayout = new QHBoxLayout(0);
+ QHBoxLayout *penWidthLayout = new QHBoxLayout;
penWidthLayout->addWidget(penWidthLabel, 0, Qt::AlignRight);
penWidthLayout->addWidget(penWidth);
- QVBoxLayout *leftLayout = new QVBoxLayout(0);
+ QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addWidget(m_capGroup);
leftLayout->addWidget(m_joinGroup);
#if QT_CONFIG(opengl)
@@ -308,7 +326,7 @@ void PathStrokeControls::layoutForSmallScreens()
#endif
leftLayout->addLayout(penWidthLayout);
- QVBoxLayout *rightLayout = new QVBoxLayout(0);
+ QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addWidget(m_styleGroup);
rightLayout->addWidget(m_pathModeGroup);
@@ -356,7 +374,7 @@ PathStrokeWidget::PathStrokeWidget(bool smallScreen)
// Widget construction and property setting
m_renderer = new PathStrokeRenderer(this, smallScreen);
- m_controls = new PathStrokeControls(0, m_renderer, smallScreen);
+ m_controls = new PathStrokeControls(nullptr, m_renderer, smallScreen);
// Layouting
QHBoxLayout *viewLayout = new QHBoxLayout(this);
@@ -383,10 +401,10 @@ void PathStrokeWidget::hideControls()
m_controls->hide();
}
-void PathStrokeWidget::setStyle( QStyle * style )
+void PathStrokeWidget::setStyle(QStyle *style)
{
QWidget::setStyle(style);
- if (m_controls != 0)
+ if (m_controls != nullptr)
{
m_controls->setStyle(style);
@@ -516,7 +534,7 @@ void PathStrokeRenderer::updatePoints()
qreal bottom = height() - pad;
Q_ASSERT(m_points.size() == m_vectors.size());
- for (int i=0; i<m_points.size(); ++i) {
+ for (int i = 0; i < m_points.size(); ++i) {
QPointF pos = m_points.at(i);
QPointF vec = m_vectors.at(i);
pos += vec;
@@ -540,7 +558,7 @@ void PathStrokeRenderer::mousePressEvent(QMouseEvent *e)
setDescriptionEnabled(false);
m_activePoint = -1;
qreal distance = -1;
- for (int i=0; i<m_points.size(); ++i) {
+ for (int i = 0; i < m_points.size(); ++i) {
qreal d = QLineF(e->pos(), m_points.at(i)).length();
if ((distance < 0 && d < 8 * m_pointSize) || d < distance) {
distance = d;
@@ -673,7 +691,6 @@ bool PathStrokeRenderer::event(QEvent *e)
m_fingerPointMapping.clear();
setAnimation(m_wasAnimated);
return true;
- break;
default:
break;
}
diff --git a/examples/widgets/painting/pathstroke/pathstroke.h b/examples/widgets/painting/pathstroke/pathstroke.h
index 7bc7e09003..b559ed2ba0 100644
--- a/examples/widgets/painting/pathstroke/pathstroke.h
+++ b/examples/widgets/painting/pathstroke/pathstroke.h
@@ -169,7 +169,7 @@ class PathStrokeWidget : public QWidget
public:
PathStrokeWidget(bool smallScreen);
- void setStyle ( QStyle * style );
+ void setStyle(QStyle *style);
private:
PathStrokeRenderer *m_renderer;
diff --git a/examples/widgets/painting/shared/arthurstyle.h b/examples/widgets/painting/shared/arthurstyle.h
index 8ea8354bab..64c888b636 100644
--- a/examples/widgets/painting/shared/arthurstyle.h
+++ b/examples/widgets/painting/shared/arthurstyle.h
@@ -63,7 +63,7 @@ public:
void drawHoverRect(QPainter *painter, const QRect &rect) const;
void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
- QPainter *painter, const QWidget *widget = 0) const override;
+ QPainter *painter, const QWidget *widget = nullptr) const override;
void drawControl(ControlElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const override;
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
diff --git a/examples/widgets/painting/shared/arthurwidgets.cpp b/examples/widgets/painting/shared/arthurwidgets.cpp
index 285be99d20..40d712c9e3 100644
--- a/examples/widgets/painting/shared/arthurwidgets.cpp
+++ b/examples/widgets/painting/shared/arthurwidgets.cpp
@@ -136,7 +136,7 @@ void ArthurFrame::createGlWindow()
void ArthurFrame::paintEvent(QPaintEvent *e)
{
- static QImage *static_image = 0;
+ static QImage *static_image = nullptr;
QPainter painter;
@@ -376,7 +376,7 @@ void ArthurFrame::showSource()
const QString html = QStringLiteral("<html><pre>") + contents + QStringLiteral("</pre></html>");
- QTextBrowser *sourceViewer = new QTextBrowser(0);
+ QTextBrowser *sourceViewer = new QTextBrowser;
sourceViewer->setWindowTitle(tr("Source: %1").arg(m_sourceFileName.midRef(5)));
sourceViewer->setParent(this, Qt::Dialog);
sourceViewer->setAttribute(Qt::WA_DeleteOnClose);
diff --git a/examples/widgets/painting/shared/fbopaintdevice.cpp b/examples/widgets/painting/shared/fbopaintdevice.cpp
index 8207090cc8..9368293218 100644
--- a/examples/widgets/painting/shared/fbopaintdevice.cpp
+++ b/examples/widgets/painting/shared/fbopaintdevice.cpp
@@ -53,7 +53,7 @@
#include <QOffscreenSurface>
#include <QOpenGLFunctions>
-QFboPaintDevice::QFboPaintDevice(const QSize& size, bool flipped, bool clearOnInit,
+QFboPaintDevice::QFboPaintDevice(const QSize &size, bool flipped, bool clearOnInit,
QOpenGLFramebufferObject::Attachment attachment)
: QOpenGLPaintDevice(size)
{
@@ -97,8 +97,8 @@ GLuint QFboPaintDevice::takeTexture()
QImage QFboPaintDevice::toImage() const
{
- QOpenGLContext* currentContext = QOpenGLContext::currentContext();
- QSurface* currentSurface = currentContext ? currentContext->surface() : 0;
+ QOpenGLContext *currentContext = QOpenGLContext::currentContext();
+ QSurface *currentSurface = currentContext ? currentContext->surface() : nullptr;
context()->makeCurrent(m_surface);
diff --git a/examples/widgets/painting/shared/fbopaintdevice.h b/examples/widgets/painting/shared/fbopaintdevice.h
index 78451af895..a42bcc756d 100644
--- a/examples/widgets/painting/shared/fbopaintdevice.h
+++ b/examples/widgets/painting/shared/fbopaintdevice.h
@@ -60,7 +60,7 @@
class QFboPaintDevice : public QOpenGLPaintDevice {
public:
- QFboPaintDevice(const QSize&, bool flipped = false, bool clearOnInit = true,
+ QFboPaintDevice(const QSize &size, bool flipped = false, bool clearOnInit = true,
QOpenGLFramebufferObject::Attachment = QOpenGLFramebufferObject::CombinedDepthStencil);
~QFboPaintDevice();
@@ -83,7 +83,7 @@ public:
private:
QOpenGLFramebufferObject *m_framebufferObject;
- QSurface* m_surface;
+ QSurface *m_surface;
};
#endif // QT_NO_OPENGL
diff --git a/examples/widgets/painting/shared/hoverpoints.cpp b/examples/widgets/painting/shared/hoverpoints.cpp
index 2032fb5a2c..2bf3963e9e 100644
--- a/examples/widgets/painting/shared/hoverpoints.cpp
+++ b/examples/widgets/painting/shared/hoverpoints.cpp
@@ -262,8 +262,8 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
case QEvent::Paint:
{
QWidget *that_widget = m_widget;
- m_widget = 0;
- QApplication::sendEvent(object, event);
+ m_widget = nullptr;
+ QCoreApplication::sendEvent(object, event);
m_widget = that_widget;
paintPoints();
return true;
diff --git a/examples/widgets/painting/transformations/renderarea.h b/examples/widgets/painting/transformations/renderarea.h
index 140be27b2b..d4be7cefa4 100644
--- a/examples/widgets/painting/transformations/renderarea.h
+++ b/examples/widgets/painting/transformations/renderarea.h
@@ -70,7 +70,7 @@ class RenderArea : public QWidget
Q_OBJECT
public:
- RenderArea(QWidget *parent = 0);
+ RenderArea(QWidget *parent = nullptr);
void setOperations(const QList<Operation> &operations);
void setShape(const QPainterPath &shape);
diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp
index 996bb8e0a4..85fb83ab89 100644
--- a/examples/widgets/richtext/textedit/textedit.cpp
+++ b/examples/widgets/richtext/textedit/textedit.cpp
@@ -640,7 +640,7 @@ void TextEdit::textStyle(int styleIndex)
{
QTextCursor cursor = textEdit->textCursor();
QTextListFormat::Style style = QTextListFormat::ListStyleUndefined;
- QTextBlockFormat::MarkerType marker = QTextBlockFormat::NoMarker;
+ QTextBlockFormat::MarkerType marker = QTextBlockFormat::MarkerType::NoMarker;
switch (styleIndex) {
case 1:
@@ -657,14 +657,14 @@ void TextEdit::textStyle(int styleIndex)
style = cursor.currentList()->format().style();
else
style = QTextListFormat::ListDisc;
- marker = QTextBlockFormat::Unchecked;
+ marker = QTextBlockFormat::MarkerType::Unchecked;
break;
case 5:
if (cursor.currentList())
style = cursor.currentList()->format().style();
else
style = QTextListFormat::ListDisc;
- marker = QTextBlockFormat::Checked;
+ marker = QTextBlockFormat::MarkerType::Checked;
break;
case 6:
style = QTextListFormat::ListDecimal;
@@ -823,14 +823,14 @@ void TextEdit::cursorPositionChanged()
break;
}
switch (textEdit->textCursor().block().blockFormat().marker()) {
- case QTextBlockFormat::NoMarker:
+ case QTextBlockFormat::MarkerType::NoMarker:
actionToggleCheckState->setChecked(false);
break;
- case QTextBlockFormat::Unchecked:
+ case QTextBlockFormat::MarkerType::Unchecked:
comboStyle->setCurrentIndex(4);
actionToggleCheckState->setChecked(false);
break;
- case QTextBlockFormat::Checked:
+ case QTextBlockFormat::MarkerType::Checked:
comboStyle->setCurrentIndex(5);
actionToggleCheckState->setChecked(true);
break;
diff --git a/examples/widgets/scroller/graphicsview/main.cpp b/examples/widgets/scroller/graphicsview/main.cpp
index d6b2956d50..178c431e6c 100644
--- a/examples/widgets/scroller/graphicsview/main.cpp
+++ b/examples/widgets/scroller/graphicsview/main.cpp
@@ -64,7 +64,7 @@ class RectObject : public QGraphicsObject
public:
- RectObject(const QString &text, qreal x, qreal y, qreal width, qreal height, QBrush brush, QGraphicsItem *parent = 0)
+ RectObject(const QString &text, qreal x, qreal y, qreal width, qreal height, QBrush brush, QGraphicsItem *parent = nullptr)
: QGraphicsObject(parent)
, m_text(text)
, m_rect(x, y, width, height)
diff --git a/examples/widgets/statemachine/eventtransitions/main.cpp b/examples/widgets/statemachine/eventtransitions/main.cpp
index 2de8e5daa3..fe9518092f 100644
--- a/examples/widgets/statemachine/eventtransitions/main.cpp
+++ b/examples/widgets/statemachine/eventtransitions/main.cpp
@@ -48,13 +48,18 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
+#include <QEventTransition>
+#include <QPushButton>
+#include <QStateMachine>
+#include <QVBoxLayout>
+#include <QWidget>
//! [0]
class Window : public QWidget
{
public:
- Window(QWidget *parent = 0)
+ Window(QWidget *parent = nullptr)
: QWidget(parent)
{
QPushButton *button = new QPushButton(this);
diff --git a/examples/widgets/statemachine/factorial/main.cpp b/examples/widgets/statemachine/factorial/main.cpp
index e9431596fe..e6cbdcae29 100644
--- a/examples/widgets/statemachine/factorial/main.cpp
+++ b/examples/widgets/statemachine/factorial/main.cpp
@@ -57,10 +57,7 @@ class Factorial : public QObject
Q_PROPERTY(int x READ x WRITE setX)
Q_PROPERTY(int fac READ fac WRITE setFac)
public:
- Factorial(QObject *parent = 0)
- : QObject(parent), m_x(-1), m_fac(1)
- {
- }
+ using QObject::QObject;
int x() const
{
@@ -89,8 +86,8 @@ Q_SIGNALS:
void xChanged(int value);
private:
- int m_x;
- int m_fac;
+ int m_x = -1;
+ int m_fac = 1;
};
//! [0]
diff --git a/examples/widgets/statemachine/trafficlight/main.cpp b/examples/widgets/statemachine/trafficlight/main.cpp
index a12d2f10d1..dd8bddcb37 100644
--- a/examples/widgets/statemachine/trafficlight/main.cpp
+++ b/examples/widgets/statemachine/trafficlight/main.cpp
@@ -48,7 +48,13 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
+#include <QFinalState>
+#include <QPainter>
+#include <QStateMachine>
+#include <QTimer>
+#include <QVBoxLayout>
+#include <QWidget>
//! [0]
class LightWidget : public QWidget
@@ -56,7 +62,7 @@ class LightWidget : public QWidget
Q_OBJECT
Q_PROPERTY(bool on READ isOn WRITE setOn)
public:
- LightWidget(const QColor &color, QWidget *parent = 0)
+ LightWidget(const QColor &color, QWidget *parent = nullptr)
: QWidget(parent), m_color(color), m_on(false) {}
bool isOn() const
@@ -94,7 +100,7 @@ private:
class TrafficLightWidget : public QWidget
{
public:
- TrafficLightWidget(QWidget *parent = 0)
+ TrafficLightWidget(QWidget *parent = nullptr)
: QWidget(parent)
{
QVBoxLayout *vbox = new QVBoxLayout(this);
@@ -125,7 +131,7 @@ private:
//! [1]
//! [2]
-QState *createLightState(LightWidget *light, int duration, QState *parent = 0)
+QState *createLightState(LightWidget *light, int duration, QState *parent = nullptr)
{
QState *lightState = new QState(parent);
QTimer *timer = new QTimer(lightState);
diff --git a/examples/widgets/tools/codecs/mainwindow.cpp b/examples/widgets/tools/codecs/mainwindow.cpp
index 53db9fe61f..6b601062b6 100644
--- a/examples/widgets/tools/codecs/mainwindow.cpp
+++ b/examples/widgets/tools/codecs/mainwindow.cpp
@@ -48,12 +48,21 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "mainwindow.h"
#include "encodingdialog.h"
#include "previewform.h"
+#include <QAction>
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QFileDialog>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QPlainTextEdit>
+#include <QRegularExpression>
+#include <QTextCodec>
+#include <QTextStream>
+
MainWindow::MainWindow()
{
textEdit = new QPlainTextEdit;
@@ -146,14 +155,14 @@ void MainWindow::findCodecs()
QTextCodec *codec = QTextCodec::codecForMib(mib);
QString sortKey = codec->name().toUpper();
- int rank;
+ char rank;
if (sortKey.startsWith(QLatin1String("UTF-8"))) {
rank = 1;
} else if (sortKey.startsWith(QLatin1String("UTF-16"))) {
rank = 2;
} else if ((match = iso8859RegExp.match(sortKey)).hasMatch()) {
- if (match.captured(1).size() == 1)
+ if (match.capturedRef(1).size() == 1)
rank = 3;
else
rank = 4;
@@ -164,7 +173,8 @@ void MainWindow::findCodecs()
codecMap.insert(sortKey, codec);
}
- codecs = codecMap.values();
+ for (const auto &codec : qAsConst(codecMap))
+ codecs += codec;
}
void MainWindow::createMenus()
diff --git a/examples/widgets/tools/codecs/mainwindow.h b/examples/widgets/tools/codecs/mainwindow.h
index 64494d1960..cf18222520 100644
--- a/examples/widgets/tools/codecs/mainwindow.h
+++ b/examples/widgets/tools/codecs/mainwindow.h
@@ -51,7 +51,7 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
-#include <QList>
+#include <QVector>
#include <QMainWindow>
QT_BEGIN_NAMESPACE
@@ -81,10 +81,10 @@ private:
void findCodecs();
void createMenus();
- QList<QAction *> saveAsActs;
+ QVector<QAction *> saveAsActs;
QPlainTextEdit *textEdit;
PreviewForm *previewForm;
- QList<QTextCodec *> codecs;
+ QVector<QTextCodec *> codecs;
EncodingDialog *m_encodingDialog = nullptr;
};
diff --git a/examples/widgets/tools/codecs/previewform.cpp b/examples/widgets/tools/codecs/previewform.cpp
index 206b5757cd..ec75ebb9fa 100644
--- a/examples/widgets/tools/codecs/previewform.cpp
+++ b/examples/widgets/tools/codecs/previewform.cpp
@@ -48,10 +48,19 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "previewform.h"
+#include <QApplication>
+#include <QComboBox>
+#include <QDesktopWidget>
+#include <QDialogButtonBox>
+#include <QGridLayout>
+#include <QLabel>
+#include <QPlainTextEdit>
+#include <QPushButton>
+#include <QTextCodec>
+#include <QTextStream>
+
// Helpers for creating hex dumps
static void indent(QTextStream &str, int indent)
{
@@ -83,8 +92,7 @@ static void formatHex(QTextStream &str, const QByteArray &data)
static void formatPrintableCharacters(QTextStream &str, const QByteArray &data)
{
- for (int i = 0, size = data.size(); i < size; ++i) {
- const char c = data.at(i);
+ for (const char c : data) {
switch (c) {
case '\0':
str << "\\0";
@@ -179,7 +187,7 @@ PreviewForm::PreviewForm(QWidget *parent)
resize(screenGeometry.width() * 2 / 5, screenGeometry.height() / 2);
}
-void PreviewForm::setCodecList(const QList<QTextCodec *> &list)
+void PreviewForm::setCodecList(const QVector<QTextCodec *> &list)
{
encodingComboBox->clear();
for (const QTextCodec *codec : list) {
@@ -226,10 +234,10 @@ void PreviewForm::updateTextEdit()
statusLabel->setText(message);
statusLabel->setStyleSheet(QStringLiteral("background-color: \"red\";"));
} else if (state.invalidChars) {
- statusLabel->setText(tr("%1: %n invalid characters", 0, state.invalidChars).arg(name));
+ statusLabel->setText(tr("%1: %n invalid characters", nullptr, state.invalidChars).arg(name));
statusLabel->setStyleSheet(QStringLiteral("background-color: \"yellow\";"));
} else {
- statusLabel->setText(tr("%1: %n bytes converted", 0, encodedData.size()).arg(name));
+ statusLabel->setText(tr("%1: %n bytes converted", nullptr, encodedData.size()).arg(name));
statusLabel->setStyleSheet(QString());
}
if (success)
diff --git a/examples/widgets/tools/codecs/previewform.h b/examples/widgets/tools/codecs/previewform.h
index 6335b6539f..02eb3533f3 100644
--- a/examples/widgets/tools/codecs/previewform.h
+++ b/examples/widgets/tools/codecs/previewform.h
@@ -52,7 +52,7 @@
#define PREVIEWFORM_H
#include <QDialog>
-#include <QList>
+#include <QVector>
QT_BEGIN_NAMESPACE
class QComboBox;
@@ -71,7 +71,7 @@ class PreviewForm : public QDialog
public:
explicit PreviewForm(QWidget *parent = nullptr);
- void setCodecList(const QList<QTextCodec *> &list);
+ void setCodecList(const QVector<QTextCodec *> &list);
void setEncodedData(const QByteArray &data);
QString decodedString() const { return decodedStr; }
diff --git a/examples/widgets/tools/completer/fsmodel.h b/examples/widgets/tools/completer/fsmodel.h
index 7b2e7b7dab..587e08b192 100644
--- a/examples/widgets/tools/completer/fsmodel.h
+++ b/examples/widgets/tools/completer/fsmodel.h
@@ -62,7 +62,7 @@
class FileSystemModel : public QFileSystemModel
{
public:
- FileSystemModel(QObject *parent = 0);
+ FileSystemModel(QObject *parent = nullptr);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
};
//! [0]
diff --git a/examples/widgets/tools/completer/mainwindow.cpp b/examples/widgets/tools/completer/mainwindow.cpp
index 114ff0fd7c..b50e0a5456 100644
--- a/examples/widgets/tools/completer/mainwindow.cpp
+++ b/examples/widgets/tools/completer/mainwindow.cpp
@@ -48,13 +48,28 @@
**
****************************************************************************/
-#include <QtWidgets>
-#include "fsmodel.h"
#include "mainwindow.h"
+#include "fsmodel.h"
+
+#include <QAction>
+#include <QApplication>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QCompleter>
+#include <QGridLayout>
+#include <QHeaderView>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QSpinBox>
+#include <QStandardItemModel>
+#include <QStringListModel>
+#include <QTreeView>
//! [0]
MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent), completer(0), lineEdit(0)
+ : QMainWindow(parent)
{
createMenu();
@@ -64,8 +79,8 @@ MainWindow::MainWindow(QWidget *parent)
modelLabel->setText(tr("Model"));
modelCombo = new QComboBox;
- modelCombo->addItem(tr("QFileSytemModel"));
- modelCombo->addItem(tr("QFileSytemModel that shows full path"));
+ modelCombo->addItem(tr("QFileSystemModel"));
+ modelCombo->addItem(tr("QFileSystemModel that shows full path"));
modelCombo->addItem(tr("Country list"));
modelCombo->addItem(tr("Word list"));
modelCombo->setCurrentIndex(0);
@@ -144,17 +159,17 @@ void MainWindow::createMenu()
connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
- QMenu* fileMenu = menuBar()->addMenu(tr("File"));
+ QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(exitAction);
- QMenu* helpMenu = menuBar()->addMenu(tr("About"));
+ QMenu *helpMenu = menuBar()->addMenu(tr("About"));
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
}
//! [4]
//! [5]
-QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
+QAbstractItemModel *MainWindow::modelFromFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QFile::ReadOnly))
@@ -170,7 +185,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
while (!file.atEnd()) {
QByteArray line = file.readLine();
if (!line.isEmpty())
- words << line.trimmed();
+ words << QString::fromUtf8(line.trimmed());
}
#ifndef QT_NO_CURSOR
@@ -191,8 +206,8 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
for (int i = 0; i < words.count(); ++i) {
QModelIndex countryIdx = m->index(i, 0);
QModelIndex symbolIdx = m->index(i, 1);
- QString country = words[i].mid(0, words[i].length() - 2).trimmed();
- QString symbol = words[i].right(2);
+ QString country = words.at(i).mid(0, words[i].length() - 2).trimmed();
+ QString symbol = words.at(i).right(2);
m->setData(countryIdx, country);
m->setData(symbolIdx, symbol);
}
@@ -233,7 +248,7 @@ void MainWindow::changeModel()
case 0:
{ // Unsorted QFileSystemModel
QFileSystemModel *fsModel = new QFileSystemModel(completer);
- fsModel->setRootPath("");
+ fsModel->setRootPath(QString());
completer->setModel(fsModel);
contentsLabel->setText(tr("Enter file path"));
}
@@ -243,7 +258,7 @@ void MainWindow::changeModel()
{ // FileSystemModel that shows full paths
FileSystemModel *fsModel = new FileSystemModel(completer);
completer->setModel(fsModel);
- fsModel->setRootPath("");
+ fsModel->setRootPath(QString());
contentsLabel->setText(tr("Enter file path"));
}
break;
diff --git a/examples/widgets/tools/completer/mainwindow.h b/examples/widgets/tools/completer/mainwindow.h
index 2bb351ec47..6e6238bf32 100644
--- a/examples/widgets/tools/completer/mainwindow.h
+++ b/examples/widgets/tools/completer/mainwindow.h
@@ -59,7 +59,6 @@ class QComboBox;
class QCompleter;
class QLabel;
class QLineEdit;
-class QProgressBar;
class QCheckBox;
class QSpinBox;
QT_END_NAMESPACE
@@ -70,7 +69,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
+ MainWindow(QWidget *parent = nullptr);
private slots:
void about();
@@ -83,16 +82,16 @@ private slots:
//! [1]
private:
void createMenu();
- QAbstractItemModel *modelFromFile(const QString& fileName);
+ QAbstractItemModel *modelFromFile(const QString &fileName);
- QComboBox *caseCombo;
- QComboBox *modeCombo;
- QComboBox *modelCombo;
- QSpinBox *maxVisibleSpinBox;
- QCheckBox *wrapCheckBox;
- QCompleter *completer;
- QLabel *contentsLabel;
- QLineEdit *lineEdit;
+ QComboBox *caseCombo = nullptr;
+ QComboBox *modeCombo = nullptr;
+ QComboBox *modelCombo = nullptr;
+ QSpinBox *maxVisibleSpinBox = nullptr;
+ QCheckBox *wrapCheckBox = nullptr;
+ QCompleter *completer = nullptr;
+ QLabel *contentsLabel = nullptr;
+ QLineEdit *lineEdit = nullptr;
};
//! [1]
diff --git a/examples/widgets/tools/customcompleter/mainwindow.cpp b/examples/widgets/tools/customcompleter/mainwindow.cpp
index 39f5f39617..b8072b505c 100644
--- a/examples/widgets/tools/customcompleter/mainwindow.cpp
+++ b/examples/widgets/tools/customcompleter/mainwindow.cpp
@@ -48,13 +48,20 @@
**
****************************************************************************/
-#include <QtWidgets>
#include "mainwindow.h"
#include "textedit.h"
+#include <QAction>
+#include <QApplication>
+#include <QCompleter>
+#include <QFile>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QStringListModel>
+
//! [0]
MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent), completer(0)
+ : QMainWindow(parent)
{
createMenu();
@@ -83,10 +90,10 @@ void MainWindow::createMenu()
connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
- QMenu* fileMenu = menuBar()->addMenu(tr("File"));
+ QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(exitAction);
- QMenu* helpMenu = menuBar()->addMenu(tr("About"));
+ QMenu *helpMenu = menuBar()->addMenu(tr("About"));
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
}
@@ -107,7 +114,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
while (!file.atEnd()) {
QByteArray line = file.readLine();
if (!line.isEmpty())
- words << line.trimmed();
+ words << QString::fromUtf8(line.trimmed());
}
#ifndef QT_NO_CURSOR
diff --git a/examples/widgets/tools/customcompleter/mainwindow.h b/examples/widgets/tools/customcompleter/mainwindow.h
index 436377cce7..cde553e291 100644
--- a/examples/widgets/tools/customcompleter/mainwindow.h
+++ b/examples/widgets/tools/customcompleter/mainwindow.h
@@ -55,11 +55,7 @@
QT_BEGIN_NAMESPACE
class QAbstractItemModel;
-class QComboBox;
class QCompleter;
-class QLabel;
-class QLineEdit;
-class QProgressBar;
QT_END_NAMESPACE
class TextEdit;
@@ -69,7 +65,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
+ MainWindow(QWidget *parent = nullptr);
private slots:
void about();
@@ -78,7 +74,7 @@ private:
void createMenu();
QAbstractItemModel *modelFromFile(const QString& fileName);
- QCompleter *completer;
+ QCompleter *completer = nullptr;
TextEdit *completingTextEdit;
};
//! [0]
diff --git a/examples/widgets/tools/customcompleter/textedit.cpp b/examples/widgets/tools/customcompleter/textedit.cpp
index d42f7b38bb..0d536fea3c 100644
--- a/examples/widgets/tools/customcompleter/textedit.cpp
+++ b/examples/widgets/tools/customcompleter/textedit.cpp
@@ -60,7 +60,7 @@
//! [0]
TextEdit::TextEdit(QWidget *parent)
-: QTextEdit(parent), c(0)
+ : QTextEdit(parent)
{
setPlainText(tr("This TextEdit provides autocompletions for words that have more than"
" 3 characters. You can trigger autocompletion using ") +
@@ -78,7 +78,7 @@ TextEdit::~TextEdit()
void TextEdit::setCompleter(QCompleter *completer)
{
if (c)
- QObject::disconnect(c, 0, this, 0);
+ c->disconnect(this);
c = completer;
@@ -101,7 +101,7 @@ QCompleter *TextEdit::completer() const
//! [3]
//! [4]
-void TextEdit::insertCompletion(const QString& completion)
+void TextEdit::insertCompletion(const QString &completion)
{
if (c->widget() != this)
return;
@@ -150,18 +150,19 @@ void TextEdit::keyPressEvent(QKeyEvent *e)
}
}
- bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E
+ const bool isShortcut = (e->modifiers().testFlag(Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E
if (!c || !isShortcut) // do not process the shortcut when we have a completer
QTextEdit::keyPressEvent(e);
//! [7]
//! [8]
- const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
+ const bool ctrlOrShift = e->modifiers().testFlag(Qt::ControlModifier) ||
+ e->modifiers().testFlag(Qt::ShiftModifier);
if (!c || (ctrlOrShift && e->text().isEmpty()))
return;
static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word
- bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
+ const bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
QString completionPrefix = textUnderCursor();
if (!isShortcut && (hasModifier || e->text().isEmpty()|| completionPrefix.length() < 3
diff --git a/examples/widgets/tools/customcompleter/textedit.h b/examples/widgets/tools/customcompleter/textedit.h
index d0636ab670..788cb74ae1 100644
--- a/examples/widgets/tools/customcompleter/textedit.h
+++ b/examples/widgets/tools/customcompleter/textedit.h
@@ -63,7 +63,7 @@ class TextEdit : public QTextEdit
Q_OBJECT
public:
- TextEdit(QWidget *parent = 0);
+ TextEdit(QWidget *parent = nullptr);
~TextEdit();
void setCompleter(QCompleter *c);
@@ -80,7 +80,7 @@ private:
QString textUnderCursor() const;
private:
- QCompleter *c;
+ QCompleter *c = nullptr;
};
//! [0]
diff --git a/examples/widgets/tools/echoplugin/echowindow/echointerface.h b/examples/widgets/tools/echoplugin/echowindow/echointerface.h
index 1915330e21..fb07f7fb79 100644
--- a/examples/widgets/tools/echoplugin/echowindow/echointerface.h
+++ b/examples/widgets/tools/echoplugin/echowindow/echointerface.h
@@ -51,13 +51,14 @@
#ifndef ECHOINTERFACE_H
#define ECHOINTERFACE_H
+#include <QObject>
#include <QString>
//! [0]
class EchoInterface
{
public:
- virtual ~EchoInterface() {}
+ virtual ~EchoInterface() = default;
virtual QString echo(const QString &message) = 0;
};
diff --git a/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp b/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp
index 6886a4cd88..dce6bdedc3 100644
--- a/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp
+++ b/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp
@@ -48,10 +48,17 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "echowindow.h"
+#include <QCoreApplication>
+#include <QDir>
+#include <QLabel>
+#include <QLayout>
+#include <QLineEdit>
+#include <QMessageBox>
+#include <QPluginLoader>
+#include <QPushButton>
+
//! [0]
EchoWindow::EchoWindow()
{
@@ -101,7 +108,7 @@ void EchoWindow::createGUI()
//! [3]
bool EchoWindow::loadPlugin()
{
- QDir pluginsDir(qApp->applicationDirPath());
+ QDir pluginsDir(QCoreApplication::applicationDirPath());
#if defined(Q_OS_WIN)
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
pluginsDir.cdUp();
@@ -121,6 +128,7 @@ bool EchoWindow::loadPlugin()
echoInterface = qobject_cast<EchoInterface *>(plugin);
if (echoInterface)
return true;
+ pluginLoader.unload();
}
}
diff --git a/examples/widgets/tools/echoplugin/echowindow/main.cpp b/examples/widgets/tools/echoplugin/echowindow/main.cpp
index 50e3c2763b..d3cf45fcde 100644
--- a/examples/widgets/tools/echoplugin/echowindow/main.cpp
+++ b/examples/widgets/tools/echoplugin/echowindow/main.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
#include "echowindow.h"
#include "echointerface.h"
diff --git a/examples/widgets/tools/echoplugin/plugin/echoplugin.cpp b/examples/widgets/tools/echoplugin/plugin/echoplugin.cpp
index de6b6a4462..c9dd93aab8 100644
--- a/examples/widgets/tools/echoplugin/plugin/echoplugin.cpp
+++ b/examples/widgets/tools/echoplugin/plugin/echoplugin.cpp
@@ -48,8 +48,6 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "echoplugin.h"
//! [0]
diff --git a/examples/widgets/tools/i18n/languagechooser.cpp b/examples/widgets/tools/i18n/languagechooser.cpp
index e61e4432e4..2ce3471873 100644
--- a/examples/widgets/tools/i18n/languagechooser.cpp
+++ b/examples/widgets/tools/i18n/languagechooser.cpp
@@ -48,34 +48,39 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "languagechooser.h"
#include "mainwindow.h"
-LanguageChooser::LanguageChooser(const QString& defaultLang, QWidget *parent)
+#include <QCoreApplication>
+#include <QCheckBox>
+#include <QDialogButtonBox>
+#include <QDir>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QPushButton>
+#include <QTranslator>
+
+LanguageChooser::LanguageChooser(const QString &defaultLang, QWidget *parent)
: QDialog(parent, Qt::WindowStaysOnTopHint)
{
groupBox = new QGroupBox("Languages");
QGridLayout *groupBoxLayout = new QGridLayout;
- QStringList qmFiles = findQmFiles();
+ const QStringList qmFiles = findQmFiles();
for (int i = 0; i < qmFiles.size(); ++i) {
- QCheckBox *checkBox = new QCheckBox(languageName(qmFiles[i]));
- qmFileForCheckBoxMap.insert(checkBox, qmFiles[i]);
- connect(checkBox,
- QOverload<bool>::of(&QCheckBox::toggled),
- this,
- &LanguageChooser::checkBoxToggled);
- if (languageMatch(defaultLang, qmFiles[i]))
- checkBox->setCheckState(Qt::Checked);
+ const QString &qmlFile = qmFiles.at(i);
+ QCheckBox *checkBox = new QCheckBox(languageName(qmlFile));
+ qmFileForCheckBoxMap.insert(checkBox, qmlFile);
+ connect(checkBox, &QCheckBox::toggled,
+ this, &LanguageChooser::checkBoxToggled);
+ if (languageMatch(defaultLang, qmlFile))
+ checkBox->setCheckState(Qt::Checked);
groupBoxLayout->addWidget(checkBox, i / 2, i % 2);
}
groupBox->setLayout(groupBoxLayout);
buttonBox = new QDialogButtonBox;
-
showAllButton = buttonBox->addButton("Show All",
QDialogButtonBox::ActionRole);
hideAllButton = buttonBox->addButton("Hide All",
@@ -92,7 +97,7 @@ LanguageChooser::LanguageChooser(const QString& defaultLang, QWidget *parent)
setWindowTitle("I18N");
}
-bool LanguageChooser::languageMatch(const QString& lang, const QString& qmFile)
+bool LanguageChooser::languageMatch(const QString &lang, const QString &qmFile)
{
//qmFile: i18n_xx.qm
const QString prefix = "i18n_";
@@ -110,21 +115,21 @@ bool LanguageChooser::eventFilter(QObject *object, QEvent *event)
checkBox->setChecked(false);
}
}
- return QWidget::eventFilter(object, event);
+ return QDialog::eventFilter(object, event);
}
void LanguageChooser::closeEvent(QCloseEvent * /* event */)
{
- qApp->quit();
+ QCoreApplication::quit();
}
void LanguageChooser::checkBoxToggled()
{
QCheckBox *checkBox = qobject_cast<QCheckBox *>(sender());
- MainWindow *window = mainWindowForCheckBoxMap[checkBox];
+ MainWindow *window = mainWindowForCheckBoxMap.value(checkBox);
if (!window) {
QTranslator translator;
- translator.load(qmFileForCheckBoxMap[checkBox]);
+ translator.load(qmFileForCheckBoxMap.value(checkBox));
qApp->installTranslator(&translator);
window = new MainWindow;
diff --git a/examples/widgets/tools/i18n/languagechooser.h b/examples/widgets/tools/i18n/languagechooser.h
index 13363c7111..733cc50fd3 100644
--- a/examples/widgets/tools/i18n/languagechooser.h
+++ b/examples/widgets/tools/i18n/languagechooser.h
@@ -52,7 +52,7 @@
#define LANGUAGECHOOSER_H
#include <QDialog>
-#include <QMap>
+#include <QHash>
#include <QStringList>
QT_BEGIN_NAMESPACE
@@ -68,7 +68,7 @@ class LanguageChooser : public QDialog
Q_OBJECT
public:
- explicit LanguageChooser(const QString& defaultLang = QString(), QWidget *parent = 0);
+ explicit LanguageChooser(const QString &defaultLang = QString(), QWidget *parent = nullptr);
protected:
bool eventFilter(QObject *object, QEvent *event) override;
@@ -80,17 +80,17 @@ private slots:
void hideAll();
private:
- QStringList findQmFiles();
- QString languageName(const QString &qmFile);
- QColor colorForLanguage(const QString &language);
- static bool languageMatch(const QString& lang, const QString& qmFile);
+ static QStringList findQmFiles();
+ static QString languageName(const QString &qmFile);
+ static QColor colorForLanguage(const QString &language);
+ static bool languageMatch(const QString &lang, const QString &qmFile);
QGroupBox *groupBox;
QDialogButtonBox *buttonBox;
QAbstractButton *showAllButton;
QAbstractButton *hideAllButton;
- QMap<QCheckBox *, QString> qmFileForCheckBoxMap;
- QMap<QCheckBox *, MainWindow *> mainWindowForCheckBoxMap;
+ QHash<QCheckBox *, QString> qmFileForCheckBoxMap;
+ QHash<QCheckBox *, MainWindow *> mainWindowForCheckBoxMap;
};
#endif
diff --git a/examples/widgets/tools/i18n/mainwindow.cpp b/examples/widgets/tools/i18n/mainwindow.cpp
index 6ebfddfa98..a107a819ca 100644
--- a/examples/widgets/tools/i18n/mainwindow.cpp
+++ b/examples/widgets/tools/i18n/mainwindow.cpp
@@ -48,18 +48,26 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "mainwindow.h"
+#include <QAction>
+#include <QCoreApplication>
+#include <QGroupBox>
+#include <QListWidget>
+#include <QMenuBar>
+#include <QRadioButton>
+#include <QStatusBar>
+#include <QVBoxLayout>
+
static const char * const listEntries[] = {
QT_TRANSLATE_NOOP("MainWindow", "First"),
QT_TRANSLATE_NOOP("MainWindow", "Second"),
QT_TRANSLATE_NOOP("MainWindow", "Third"),
- 0
+ nullptr
};
-MainWindow::MainWindow()
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
{
centralWidget = new QWidget;
setCentralWidget(centralWidget);
@@ -67,8 +75,8 @@ MainWindow::MainWindow()
createGroupBox();
listWidget = new QListWidget;
- for (int i = 0; listEntries[i]; ++i)
- listWidget->addItem(tr(listEntries[i]));
+ for (const char *entry : listEntries)
+ listWidget->addItem(tr(entry));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(groupBox);
@@ -76,7 +84,7 @@ MainWindow::MainWindow()
centralWidget->setLayout(mainLayout);
exitAction = new QAction(tr("E&xit"), this);
- connect(exitAction, &QAction::triggered, qApp, QApplication::quit);
+ connect(exitAction, &QAction::triggered, qApp, QCoreApplication::quit);
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->setPalette(QPalette(Qt::red));
diff --git a/examples/widgets/tools/i18n/mainwindow.h b/examples/widgets/tools/i18n/mainwindow.h
index e011151894..105472d60c 100644
--- a/examples/widgets/tools/i18n/mainwindow.h
+++ b/examples/widgets/tools/i18n/mainwindow.h
@@ -67,7 +67,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow();
+ MainWindow(QWidget *parent = nullptr);
private:
void createGroupBox();
diff --git a/examples/widgets/tools/plugandpaint/app/mainwindow.cpp b/examples/widgets/tools/plugandpaint/app/mainwindow.cpp
index ebe1150eea..ff3b3614af 100644
--- a/examples/widgets/tools/plugandpaint/app/mainwindow.cpp
+++ b/examples/widgets/tools/plugandpaint/app/mainwindow.cpp
@@ -49,8 +49,8 @@
****************************************************************************/
-#include "interfaces.h"
#include "mainwindow.h"
+#include "interfaces.h"
#include "paintarea.h"
#include "plugindialog.h"
@@ -67,9 +67,8 @@
#include <QScrollArea>
#include <QTimer>
-MainWindow::MainWindow() :
- paintArea(new PaintArea),
- scrollArea(new QScrollArea)
+MainWindow::MainWindow() : paintArea(new PaintArea)
+ , scrollArea(new QScrollArea)
{
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(paintArea);
@@ -136,7 +135,11 @@ void MainWindow::brushWidth()
void MainWindow::changeBrush()
{
auto action = qobject_cast<QAction *>(sender());
+ if (!action)
+ return;
auto iBrush = qobject_cast<BrushInterface *>(action->parent());
+ if (!iBrush)
+ return;
const QString brush = action->text();
paintArea->setBrush(iBrush, brush);
@@ -147,7 +150,11 @@ void MainWindow::changeBrush()
void MainWindow::insertShape()
{
auto action = qobject_cast<QAction *>(sender());
+ if (!action)
+ return;
auto iShape = qobject_cast<ShapeInterface *>(action->parent());
+ if (!iShape)
+ return;
const QPainterPath path = iShape->generateShape(action->text(), this);
if (!path.isEmpty())
@@ -159,7 +166,11 @@ void MainWindow::insertShape()
void MainWindow::applyFilter()
{
auto action = qobject_cast<QAction *>(sender());
+ if (!action)
+ return;
auto iFilter = qobject_cast<FilterInterface *>(action->parent());
+ if (!iFilter)
+ return;
const QImage image = iFilter->filterImage(action->text(), paintArea->image(),
this);
@@ -247,7 +258,7 @@ void MainWindow::loadPlugins()
populateMenus(plugin);
//! [4] //! [5]
- pluginsDir = QDir(qApp->applicationDirPath());
+ pluginsDir = QDir(QCoreApplication::applicationDirPath());
#if defined(Q_OS_WIN)
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
diff --git a/examples/widgets/tools/plugandpaint/app/paintarea.cpp b/examples/widgets/tools/plugandpaint/app/paintarea.cpp
index e225d78398..92b8ea4777 100644
--- a/examples/widgets/tools/plugandpaint/app/paintarea.cpp
+++ b/examples/widgets/tools/plugandpaint/app/paintarea.cpp
@@ -49,14 +49,13 @@
****************************************************************************/
-#include "interfaces.h"
#include "paintarea.h"
+#include "interfaces.h"
#include <QMouseEvent>
#include <QPainter>
-PaintArea::PaintArea(QWidget *parent) :
- QWidget(parent)
+PaintArea::PaintArea(QWidget *parent) : QWidget(parent)
{
setAttribute(Qt::WA_StaticContents);
setAttribute(Qt::WA_OpaquePaintEvent);
diff --git a/examples/widgets/tools/plugandpaint/app/plugindialog.cpp b/examples/widgets/tools/plugandpaint/app/plugindialog.cpp
index 84bd364b41..204d6ffec4 100644
--- a/examples/widgets/tools/plugandpaint/app/plugindialog.cpp
+++ b/examples/widgets/tools/plugandpaint/app/plugindialog.cpp
@@ -49,8 +49,8 @@
****************************************************************************/
-#include "interfaces.h"
#include "plugindialog.h"
+#include "interfaces.h"
#include <QDir>
#include <QGridLayout>
diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp
index 3b465565ba..64f9f7a0d9 100644
--- a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp
+++ b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp
@@ -50,10 +50,10 @@
#include "basictoolsplugin.h"
+#include <QInputDialog>
+#include <QPainter>
+#include <QRandomGenerator>
#include <QtMath>
-#include <QtWidgets>
-
-#include <stdlib.h>
//! [0]
QStringList BasicToolsPlugin::brushes() const
diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h
index fd9bb9e5f3..1d9d170daa 100644
--- a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h
+++ b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h
@@ -54,12 +54,12 @@
//! [0]
#include <interfaces.h>
-#include <QRect>
+#include <QImage>
#include <QObject>
-#include <QtPlugin>
-#include <QStringList>
#include <QPainterPath>
-#include <QImage>
+#include <QRect>
+#include <QStringList>
+#include <QtPlugin>
//! [1]
class BasicToolsPlugin : public QObject,
diff --git a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp b/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp
index 48717e34f6..30c616a830 100644
--- a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp
+++ b/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp
@@ -50,10 +50,7 @@
#include "extrafiltersplugin.h"
-#include <QtWidgets>
-
-#include <math.h>
-#include <stdlib.h>
+#include <QInputDialog>
QStringList ExtraFiltersPlugin::filters() const
{
diff --git a/examples/widgets/tools/regexp/regexpdialog.h b/examples/widgets/tools/regexp/regexpdialog.h
index 4bdc18da15..2f701a7228 100644
--- a/examples/widgets/tools/regexp/regexpdialog.h
+++ b/examples/widgets/tools/regexp/regexpdialog.h
@@ -65,7 +65,7 @@ class RegExpDialog : public QDialog
Q_OBJECT
public:
- RegExpDialog(QWidget *parent = 0);
+ RegExpDialog(QWidget *parent = nullptr);
private slots:
void refresh();
diff --git a/examples/widgets/tools/regularexpression/regularexpressiondialog.h b/examples/widgets/tools/regularexpression/regularexpressiondialog.h
index ba5b38b5e3..8fe85afe56 100644
--- a/examples/widgets/tools/regularexpression/regularexpressiondialog.h
+++ b/examples/widgets/tools/regularexpression/regularexpressiondialog.h
@@ -70,7 +70,7 @@ class RegularExpressionDialog : public QDialog
Q_OBJECT
public:
- RegularExpressionDialog(QWidget *parent = 0);
+ RegularExpressionDialog(QWidget *parent = nullptr);
private:
void refresh();
diff --git a/examples/widgets/tools/settingseditor/locationdialog.cpp b/examples/widgets/tools/settingseditor/locationdialog.cpp
index 5b6e2652bb..99c9834a63 100644
--- a/examples/widgets/tools/settingseditor/locationdialog.cpp
+++ b/examples/widgets/tools/settingseditor/locationdialog.cpp
@@ -48,10 +48,20 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "locationdialog.h"
+#include <QBoxLayout>
+#include <QComboBox>
+#include <QDialogButtonBox>
+#include <QDir>
+#include <QPushButton>
+#include <QGroupBox>
+#include <QHeaderView>
+#include <QLabel>
+#include <QLineEdit>
+#include <QTableWidget>
+#include <QTableWidgetItem>
+
LocationDialog::LocationDialog(QWidget *parent)
: QDialog(parent)
{
@@ -91,8 +101,7 @@ LocationDialog::LocationDialog(QWidget *parent)
locationsGroupBox = new QGroupBox(tr("Setting Locations"));
- QStringList labels;
- labels << tr("Location") << tr("Access");
+ const QStringList labels{tr("Location"), tr("Access")};
locationsTable = new QTableWidget;
locationsTable->setSelectionMode(QAbstractItemView::SingleSelection);
diff --git a/examples/widgets/tools/settingseditor/locationdialog.h b/examples/widgets/tools/settingseditor/locationdialog.h
index c25b01effd..cd2efecb0b 100644
--- a/examples/widgets/tools/settingseditor/locationdialog.h
+++ b/examples/widgets/tools/settingseditor/locationdialog.h
@@ -68,7 +68,7 @@ class LocationDialog : public QDialog
Q_OBJECT
public:
- LocationDialog(QWidget *parent = 0);
+ LocationDialog(QWidget *parent = nullptr);
QSettings::Format format() const;
QSettings::Scope scope() const;
diff --git a/examples/widgets/tools/settingseditor/mainwindow.cpp b/examples/widgets/tools/settingseditor/mainwindow.cpp
index a7a1e9b415..b9c2193ccb 100644
--- a/examples/widgets/tools/settingseditor/mainwindow.cpp
+++ b/examples/widgets/tools/settingseditor/mainwindow.cpp
@@ -48,15 +48,23 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "locationdialog.h"
#include "mainwindow.h"
#include "settingstree.h"
-MainWindow::MainWindow()
- : settingsTree(new SettingsTree)
- , locationDialog(nullptr)
+#include <QAction>
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QFileDialog>
+#include <QInputDialog>
+#include <QLineEdit>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QStandardPaths>
+#include <QStatusBar>
+
+MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
+ , settingsTree(new SettingsTree)
{
setCentralWidget(settingsTree);
diff --git a/examples/widgets/tools/settingseditor/mainwindow.h b/examples/widgets/tools/settingseditor/mainwindow.h
index 373c982afe..b1115005a9 100644
--- a/examples/widgets/tools/settingseditor/mainwindow.h
+++ b/examples/widgets/tools/settingseditor/mainwindow.h
@@ -68,7 +68,7 @@ class MainWindow : public QMainWindow
public:
typedef QSharedPointer<QSettings> SettingsPtr;
- MainWindow();
+ MainWindow(QWidget *parent = nullptr);
private slots:
void openSettings();
@@ -81,11 +81,11 @@ private:
void createActions();
void setSettingsObject(const SettingsPtr &settings);
- SettingsTree *settingsTree;
- LocationDialog *locationDialog;
- QAction *refreshAct;
- QAction *autoRefreshAct;
- QAction *fallbacksAct;
+ SettingsTree *settingsTree = nullptr;
+ LocationDialog *locationDialog = nullptr;
+ QAction *refreshAct = nullptr;
+ QAction *autoRefreshAct = nullptr;
+ QAction *fallbacksAct = nullptr;
};
#endif
diff --git a/examples/widgets/tools/settingseditor/settingstree.cpp b/examples/widgets/tools/settingseditor/settingstree.cpp
index 8585792787..b263746847 100644
--- a/examples/widgets/tools/settingseditor/settingstree.cpp
+++ b/examples/widgets/tools/settingseditor/settingstree.cpp
@@ -48,20 +48,20 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "settingstree.h"
#include "variantdelegate.h"
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QHeaderView>
+#include <QSettings>
+
SettingsTree::SettingsTree(QWidget *parent)
: QTreeWidget(parent)
- , autoRefresh(false)
{
setItemDelegate(new VariantDelegate(this));
- QStringList labels;
- labels << tr("Setting") << tr("Type") << tr("Value");
- setHeaderLabels(labels);
+ setHeaderLabels({tr("Setting"), tr("Type"), tr("Value")});
header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(2, QHeaderView::Stretch);
@@ -77,10 +77,6 @@ SettingsTree::SettingsTree(QWidget *parent)
connect(&refreshTimer, &QTimer::timeout, this, &SettingsTree::maybeRefresh);
}
-SettingsTree::~SettingsTree()
-{
-}
-
void SettingsTree::setSettingsObject(const SettingsPtr &newSettings)
{
settings = newSettings;
@@ -137,7 +133,7 @@ void SettingsTree::refresh()
this, &SettingsTree::updateSetting);
settings->sync();
- updateChildItems(0);
+ updateChildItems(nullptr);
connect(this, &QTreeWidget::itemChanged,
this, &SettingsTree::updateSetting);
@@ -228,7 +224,7 @@ void SettingsTree::updateChildItems(QTreeWidgetItem *parent)
QTreeWidgetItem *SettingsTree::createItem(const QString &text,
QTreeWidgetItem *parent, int index)
{
- QTreeWidgetItem *after = 0;
+ QTreeWidgetItem *after = nullptr;
if (index != 0)
after = childAt(parent, index - 1);
@@ -243,24 +239,18 @@ QTreeWidgetItem *SettingsTree::createItem(const QString &text,
return item;
}
-QTreeWidgetItem *SettingsTree::childAt(QTreeWidgetItem *parent, int index)
+QTreeWidgetItem *SettingsTree::childAt(QTreeWidgetItem *parent, int index) const
{
- if (parent)
- return parent->child(index);
- else
- return topLevelItem(index);
+ return (parent ? parent->child(index) : topLevelItem(index));
}
-int SettingsTree::childCount(QTreeWidgetItem *parent)
+int SettingsTree::childCount(QTreeWidgetItem *parent) const
{
- if (parent)
- return parent->childCount();
- else
- return topLevelItemCount();
+ return (parent ? parent->childCount() : topLevelItemCount());
}
int SettingsTree::findChild(QTreeWidgetItem *parent, const QString &text,
- int startIndex)
+ int startIndex) const
{
for (int i = startIndex; i < childCount(parent); ++i) {
if (childAt(parent, i)->text(0) == text)
diff --git a/examples/widgets/tools/settingseditor/settingstree.h b/examples/widgets/tools/settingseditor/settingstree.h
index 15efa0e6aa..3e9e9658ce 100644
--- a/examples/widgets/tools/settingseditor/settingstree.h
+++ b/examples/widgets/tools/settingseditor/settingstree.h
@@ -65,10 +65,9 @@ class SettingsTree : public QTreeWidget
Q_OBJECT
public:
- typedef QSharedPointer<QSettings> SettingsPtr;
+ using SettingsPtr = QSharedPointer<QSettings>;
- SettingsTree(QWidget *parent = 0);
- ~SettingsTree();
+ SettingsTree(QWidget *parent = nullptr);
void setSettingsObject(const SettingsPtr &settings);
QSize sizeHint() const override;
@@ -89,16 +88,16 @@ private:
void updateChildItems(QTreeWidgetItem *parent);
QTreeWidgetItem *createItem(const QString &text, QTreeWidgetItem *parent,
int index);
- QTreeWidgetItem *childAt(QTreeWidgetItem *parent, int index);
- int childCount(QTreeWidgetItem *parent);
- int findChild(QTreeWidgetItem *parent, const QString &text, int startIndex);
+ QTreeWidgetItem *childAt(QTreeWidgetItem *parent, int index) const;
+ int childCount(QTreeWidgetItem *parent) const;
+ int findChild(QTreeWidgetItem *parent, const QString &text, int startIndex) const;
void moveItemForward(QTreeWidgetItem *parent, int oldIndex, int newIndex);
SettingsPtr settings;
QTimer refreshTimer;
- bool autoRefresh;
QIcon groupIcon;
QIcon keyIcon;
+ bool autoRefresh = false;
};
#endif
diff --git a/examples/widgets/tools/settingseditor/variantdelegate.cpp b/examples/widgets/tools/settingseditor/variantdelegate.cpp
index 266754ca4d..9772fe8a41 100644
--- a/examples/widgets/tools/settingseditor/variantdelegate.cpp
+++ b/examples/widgets/tools/settingseditor/variantdelegate.cpp
@@ -48,12 +48,14 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "variantdelegate.h"
+#include <QDateTime>
+#include <QLineEdit>
+#include <QRegularExpressionValidator>
+
VariantDelegate::VariantDelegate(QObject *parent)
- : QItemDelegate(parent)
+ : QStyledItemDelegate(parent)
{
boolExp.setPattern("true|false");
boolExp.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
@@ -82,12 +84,12 @@ void VariantDelegate::paint(QPainter *painter,
if (!isSupportedType(value.type())) {
QStyleOptionViewItem myOption = option;
myOption.state &= ~QStyle::State_Enabled;
- QItemDelegate::paint(painter, myOption, index);
+ QStyledItemDelegate::paint(painter, myOption, index);
return;
}
}
- QItemDelegate::paint(painter, option, index);
+ QStyledItemDelegate::paint(painter, option, index);
}
QWidget *VariantDelegate::createEditor(QWidget *parent,
@@ -95,11 +97,11 @@ QWidget *VariantDelegate::createEditor(QWidget *parent,
const QModelIndex &index) const
{
if (index.column() != 2)
- return 0;
+ return nullptr;
QVariant originalValue = index.model()->data(index, Qt::UserRole);
if (!isSupportedType(originalValue.type()))
- return 0;
+ return nullptr;
QLineEdit *lineEdit = new QLineEdit(parent);
lineEdit->setFrame(false);
@@ -149,7 +151,7 @@ QWidget *VariantDelegate::createEditor(QWidget *parent,
regExp = unsignedIntegerExp;
break;
default:
- ;
+ break;
}
if (regExp.isValid()) {
diff --git a/examples/widgets/tools/settingseditor/variantdelegate.h b/examples/widgets/tools/settingseditor/variantdelegate.h
index 7cd9fa9ee8..68f21fa3f6 100644
--- a/examples/widgets/tools/settingseditor/variantdelegate.h
+++ b/examples/widgets/tools/settingseditor/variantdelegate.h
@@ -51,15 +51,15 @@
#ifndef VARIANTDELEGATE_H
#define VARIANTDELEGATE_H
-#include <QItemDelegate>
+#include <QStyledItemDelegate>
#include <QRegularExpression>
-class VariantDelegate : public QItemDelegate
+class VariantDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
- VariantDelegate(QObject *parent = 0);
+ VariantDelegate(QObject *parent = nullptr);
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp b/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp
index 59da6a8672..765c9c2745 100644
--- a/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp
+++ b/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp
@@ -48,8 +48,6 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "simplestyle.h"
void SimpleStyle::polish(QPalette &palette)
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyle.h b/examples/widgets/tools/styleplugin/plugin/simplestyle.h
index 51d6d5b77e..4f49de8cbc 100644
--- a/examples/widgets/tools/styleplugin/plugin/simplestyle.h
+++ b/examples/widgets/tools/styleplugin/plugin/simplestyle.h
@@ -53,16 +53,12 @@
#include <QProxyStyle>
-QT_BEGIN_NAMESPACE
-class QPalette;
-QT_END_NAMESPACE
-
class SimpleStyle : public QProxyStyle
{
Q_OBJECT
public:
- SimpleStyle() {};
+ SimpleStyle() = default;
void polish(QPalette &palette) override;
};
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.cpp b/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.cpp
index 344e46061c..cbe7c15cc0 100644
--- a/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.cpp
+++ b/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.cpp
@@ -48,15 +48,13 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "simplestyleplugin.h"
#include "simplestyle.h"
//! [0]
QStringList SimpleStylePlugin::keys() const
{
- return QStringList() << "SimpleStyle";
+ return {"SimpleStyle"};
}
//! [0]
@@ -65,6 +63,6 @@ QStyle *SimpleStylePlugin::create(const QString &key)
{
if (key.toLower() == "simplestyle")
return new SimpleStyle;
- return 0;
+ return nullptr;
}
//! [1]
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h b/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h
index 88805d4887..3ce37410eb 100644
--- a/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h
+++ b/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h
@@ -53,11 +53,6 @@
#include <QStylePlugin>
-QT_BEGIN_NAMESPACE
-class QStringList;
-class QStyle;
-QT_END_NAMESPACE
-
//! [0]
class SimpleStylePlugin : public QStylePlugin
{
@@ -65,7 +60,7 @@ class SimpleStylePlugin : public QStylePlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "simplestyle.json")
public:
- SimpleStylePlugin() {}
+ SimpleStylePlugin() = default;
QStringList keys() const;
QStyle *create(const QString &key) override;
diff --git a/examples/widgets/tools/styleplugin/stylewindow/main.cpp b/examples/widgets/tools/styleplugin/stylewindow/main.cpp
index 93816d393d..ff29eb119e 100644
--- a/examples/widgets/tools/styleplugin/stylewindow/main.cpp
+++ b/examples/widgets/tools/styleplugin/stylewindow/main.cpp
@@ -48,7 +48,8 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
+#include <QStyleFactory>
#include "stylewindow.h"
diff --git a/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp b/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp
index 7a05a3ae92..90413ed12e 100644
--- a/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp
+++ b/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp
@@ -48,7 +48,9 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QPushButton>
#include "stylewindow.h"
diff --git a/examples/widgets/tools/treemodelcompleter/mainwindow.cpp b/examples/widgets/tools/treemodelcompleter/mainwindow.cpp
index dec3cb0496..302ccc436c 100644
--- a/examples/widgets/tools/treemodelcompleter/mainwindow.cpp
+++ b/examples/widgets/tools/treemodelcompleter/mainwindow.cpp
@@ -48,13 +48,28 @@
**
****************************************************************************/
-#include <QtWidgets>
-#include "treemodelcompleter.h"
#include "mainwindow.h"
+#include "treemodelcompleter.h"
+
+#include <QAbstractProxyModel>
+#include <QAction>
+#include <QApplication>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QFile>
+#include <QGridLayout>
+#include <QHeaderView>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QStandardItemModel>
+#include <QStringListModel>
+#include <QTreeView>
//! [0]
MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent), completer(0), lineEdit(0)
+ : QMainWindow(parent)
{
createMenu();
@@ -151,10 +166,10 @@ void MainWindow::createMenu()
connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
- QMenu* fileMenu = menuBar()->addMenu(tr("File"));
+ QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(exitAction);
- QMenu* helpMenu = menuBar()->addMenu(tr("About"));
+ QMenu *helpMenu = menuBar()->addMenu(tr("About"));
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
}
@@ -175,7 +190,7 @@ void MainWindow::changeMode(int index)
}
//! [5]
-QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
+QAbstractItemModel *MainWindow::modelFromFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QFile::ReadOnly))
@@ -184,39 +199,35 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
#ifndef QT_NO_CURSOR
QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
#endif
- QStringList words;
QStandardItemModel *model = new QStandardItemModel(completer);
QVector<QStandardItem *> parents(10);
parents[0] = model->invisibleRootItem();
+ QRegularExpression re("^\\s+");
while (!file.atEnd()) {
- QString line = file.readLine();
- QString trimmedLine = line.trimmed();
- if (line.isEmpty() || trimmedLine.isEmpty())
+ const QString line = QString::fromUtf8(file.readLine()).trimmed();
+ const QString trimmedLine = line.trimmed();
+ if (trimmedLine.isEmpty())
continue;
- QRegularExpression re("^\\s+");
- QRegularExpressionMatch match = re.match(line);
+ const QRegularExpressionMatch match = re.match(line);
int nonws = match.capturedStart();
int level = 0;
if (nonws == -1) {
level = 0;
} else {
- if (line.startsWith("\t")) {
- level = match.capturedLength();
- } else {
- level = match.capturedLength()/4;
- }
+ const int capLen = match.capturedLength();
+ level = line.startsWith(QLatin1Char('\t')) ? capLen / 4 : capLen;
}
- if (level+1 >= parents.size())
- parents.resize(parents.size()*2);
+ if (level + 1 >= parents.size())
+ parents.resize(parents.size() * 2);
QStandardItem *item = new QStandardItem;
item->setText(trimmedLine);
parents[level]->appendRow(item);
- parents[level+1] = item;
+ parents[level + 1] = item;
}
#ifndef QT_NO_CURSOR
@@ -252,7 +263,7 @@ void MainWindow::changeCase(int cs)
}
//! [7]
-void MainWindow::updateContentsLabel(const QString& sep)
+void MainWindow::updateContentsLabel(const QString &sep)
{
contentsLabel->setText(tr("Type path from model above with items at each level separated by a '%1'").arg(sep));
}
diff --git a/examples/widgets/tools/treemodelcompleter/mainwindow.h b/examples/widgets/tools/treemodelcompleter/mainwindow.h
index 2edcd5aab0..87f492c4ac 100644
--- a/examples/widgets/tools/treemodelcompleter/mainwindow.h
+++ b/examples/widgets/tools/treemodelcompleter/mainwindow.h
@@ -60,8 +60,6 @@ class QAbstractItemModel;
class QComboBox;
class QLabel;
class QLineEdit;
-class QProgressBar;
-class QCheckBox;
class QTreeView;
QT_END_NAMESPACE
@@ -71,27 +69,27 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
+ MainWindow(QWidget *parent = nullptr);
private slots:
void about();
void changeCase(int);
void changeMode(int);
- void highlight(const QModelIndex&);
- void updateContentsLabel(const QString&);
+ void highlight(const QModelIndex &index);
+ void updateContentsLabel(const QString &sep);
//! [0]
//! [1]
private:
void createMenu();
- QAbstractItemModel *modelFromFile(const QString& fileName);
+ QAbstractItemModel *modelFromFile(const QString &fileName);
- QTreeView *treeView;
- QComboBox *caseCombo;
- QComboBox *modeCombo;
- QLabel *contentsLabel;
- TreeModelCompleter *completer;
- QLineEdit *lineEdit;
+ QTreeView *treeView = nullptr;
+ QComboBox *caseCombo = nullptr;
+ QComboBox *modeCombo = nullptr;
+ QLabel *contentsLabel = nullptr;
+ TreeModelCompleter *completer = nullptr;
+ QLineEdit *lineEdit = nullptr;
};
//! [1]
diff --git a/examples/widgets/tools/treemodelcompleter/treemodelcompleter.cpp b/examples/widgets/tools/treemodelcompleter/treemodelcompleter.cpp
index cab0476e3c..8930c815d5 100644
--- a/examples/widgets/tools/treemodelcompleter/treemodelcompleter.cpp
+++ b/examples/widgets/tools/treemodelcompleter/treemodelcompleter.cpp
@@ -80,26 +80,20 @@ QString TreeModelCompleter::separator() const
//! [3]
QStringList TreeModelCompleter::splitPath(const QString &path) const
{
- if (sep.isNull()) {
- return QCompleter::splitPath(path);
- }
-
- return path.split(sep);
+ return (sep.isNull() ? QCompleter::splitPath(path) : path.split(sep));
}
//! [3]
//! [4]
QString TreeModelCompleter::pathFromIndex(const QModelIndex &index) const
{
- if (sep.isNull()) {
+ if (sep.isNull())
return QCompleter::pathFromIndex(index);
- }
// navigate up and accumulate data
QStringList dataList;
- for (QModelIndex i = index; i.isValid(); i = i.parent()) {
+ for (QModelIndex i = index; i.isValid(); i = i.parent())
dataList.prepend(model()->data(i, completionRole()).toString());
- }
return dataList.join(sep);
}
diff --git a/examples/widgets/tools/treemodelcompleter/treemodelcompleter.h b/examples/widgets/tools/treemodelcompleter/treemodelcompleter.h
index 1d28fddee0..d7d1852cc7 100644
--- a/examples/widgets/tools/treemodelcompleter/treemodelcompleter.h
+++ b/examples/widgets/tools/treemodelcompleter/treemodelcompleter.h
@@ -60,8 +60,8 @@ class TreeModelCompleter : public QCompleter
Q_PROPERTY(QString separator READ separator WRITE setSeparator)
public:
- explicit TreeModelCompleter(QObject *parent = 0);
- explicit TreeModelCompleter(QAbstractItemModel *model, QObject *parent = 0);
+ explicit TreeModelCompleter(QObject *parent = nullptr);
+ explicit TreeModelCompleter(QAbstractItemModel *model, QObject *parent = nullptr);
QString separator() const;
public slots:
diff --git a/examples/widgets/tools/undo/commands.cpp b/examples/widgets/tools/undo/commands.cpp
index 81561d2421..97204f9d2f 100644
--- a/examples/widgets/tools/undo/commands.cpp
+++ b/examples/widgets/tools/undo/commands.cpp
@@ -50,18 +50,16 @@
#include "commands.h"
-static const int setShapeRectCommandId = 1;
-static const int setShapeColorCommandId = 2;
+static constexpr int setShapeRectCommandId = 1;
+static constexpr int setShapeColorCommandId = 2;
/******************************************************************************
** AddShapeCommand
*/
AddShapeCommand::AddShapeCommand(Document *doc, const Shape &shape, QUndoCommand *parent)
- : QUndoCommand(parent)
+ : QUndoCommand(parent), m_doc(doc), m_shape(shape)
{
- m_doc = doc;
- m_shape = shape;
}
void AddShapeCommand::undo()
@@ -81,13 +79,11 @@ void AddShapeCommand::redo()
*/
RemoveShapeCommand::RemoveShapeCommand(Document *doc, const QString &shapeName,
- QUndoCommand *parent)
- : QUndoCommand(parent)
+ QUndoCommand *parent)
+ : QUndoCommand(parent), m_doc(doc), m_shape(doc->shape(shapeName))
+ , m_shapeName(shapeName)
{
setText(QObject::tr("Remove %1").arg(shapeName));
- m_doc = doc;
- m_shape = doc->shape(shapeName);
- m_shapeName = shapeName;
}
void RemoveShapeCommand::undo()
@@ -105,15 +101,11 @@ void RemoveShapeCommand::redo()
*/
SetShapeColorCommand::SetShapeColorCommand(Document *doc, const QString &shapeName,
- const QColor &color, QUndoCommand *parent)
- : QUndoCommand(parent)
+ const QColor &color, QUndoCommand *parent)
+ : QUndoCommand(parent), m_doc(doc), m_shapeName(shapeName)
+ , m_oldColor(doc->shape(shapeName).color()), m_newColor(color)
{
setText(QObject::tr("Set %1's color").arg(shapeName));
-
- m_doc = doc;
- m_shapeName = shapeName;
- m_oldColor = doc->shape(shapeName).color();
- m_newColor = color;
}
void SetShapeColorCommand::undo()
@@ -149,15 +141,11 @@ int SetShapeColorCommand::id() const
*/
SetShapeRectCommand::SetShapeRectCommand(Document *doc, const QString &shapeName,
- const QRect &rect, QUndoCommand *parent)
- : QUndoCommand(parent)
+ const QRect &rect, QUndoCommand *parent)
+ : QUndoCommand(parent), m_doc(doc), m_shapeName(shapeName)
+ , m_oldRect(doc->shape(shapeName).rect()), m_newRect(rect)
{
setText(QObject::tr("Change %1's geometry").arg(shapeName));
-
- m_doc = doc;
- m_shapeName = shapeName;
- m_oldRect = doc->shape(shapeName).rect();
- m_newRect = rect;
}
void SetShapeRectCommand::undo()
diff --git a/examples/widgets/tools/undo/commands.h b/examples/widgets/tools/undo/commands.h
index de3bebd740..ccb550fdd4 100644
--- a/examples/widgets/tools/undo/commands.h
+++ b/examples/widgets/tools/undo/commands.h
@@ -57,7 +57,8 @@
class AddShapeCommand : public QUndoCommand
{
public:
- AddShapeCommand(Document *doc, const Shape &shape, QUndoCommand *parent = 0);
+ AddShapeCommand(Document *doc, const Shape &shape,
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
@@ -70,7 +71,8 @@ private:
class RemoveShapeCommand : public QUndoCommand
{
public:
- RemoveShapeCommand(Document *doc, const QString &shapeName, QUndoCommand *parent = 0);
+ RemoveShapeCommand(Document *doc, const QString &shapeName,
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
@@ -83,8 +85,8 @@ private:
class SetShapeColorCommand : public QUndoCommand
{
public:
- SetShapeColorCommand(Document *doc, const QString &shapeName, const QColor &color,
- QUndoCommand *parent = 0);
+ SetShapeColorCommand(Document *doc, const QString &shapeName,
+ const QColor &color, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
@@ -102,8 +104,8 @@ private:
class SetShapeRectCommand : public QUndoCommand
{
public:
- SetShapeRectCommand(Document *doc, const QString &shapeName, const QRect &rect,
- QUndoCommand *parent = 0);
+ SetShapeRectCommand(Document *doc, const QString &shapeName,
+ const QRect &rect, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
diff --git a/examples/widgets/tools/undo/document.cpp b/examples/widgets/tools/undo/document.cpp
index 8935f98a7a..2deed83a99 100644
--- a/examples/widgets/tools/undo/document.cpp
+++ b/examples/widgets/tools/undo/document.cpp
@@ -48,14 +48,15 @@
**
****************************************************************************/
-#include <qevent.h>
+#include "document.h"
+#include "commands.h"
+
#include <QPainter>
+#include <QPaintEvent>
#include <QTextStream>
#include <QUndoStack>
-#include "document.h"
-#include "commands.h"
-static const int resizeHandleWidth = 6;
+static constexpr int resizeHandleWidth = 6;
/******************************************************************************
** Shape
@@ -96,26 +97,21 @@ QRect Shape::resizeHandle() const
QString Shape::typeToString(Type type)
{
- QString result;
-
switch (type) {
case Rectangle:
- result = QLatin1String("Rectangle");
- break;
+ return QLatin1String("Rectangle");
case Circle:
- result = QLatin1String("Circle");
- break;
+ return QLatin1String("Circle");
case Triangle:
- result = QLatin1String("Triangle");
- break;
+ return QLatin1String("Triangle");
}
- return result;
+ return QString();
}
Shape::Type Shape::stringToType(const QString &s, bool *ok)
{
- if (ok != 0)
+ if (ok != nullptr)
*ok = true;
if (s == QLatin1String("Rectangle"))
@@ -125,7 +121,7 @@ Shape::Type Shape::stringToType(const QString &s, bool *ok)
if (s == QLatin1String("Triangle"))
return Triangle;
- if (ok != 0)
+ if (ok != nullptr)
*ok = false;
return Rectangle;
}
@@ -135,10 +131,8 @@ Shape::Type Shape::stringToType(const QString &s, bool *ok)
*/
Document::Document(QWidget *parent)
- : QWidget(parent), m_currentIndex(-1), m_mousePressIndex(-1), m_resizeHandlePressed(false)
+ : QWidget(parent), m_undoStack(new QUndoStack(this))
{
- m_undoStack = new QUndoStack(this);
-
setAutoFillBackground(true);
setBackgroundRole(QPalette::Base);
diff --git a/examples/widgets/tools/undo/document.h b/examples/widgets/tools/undo/document.h
index 8076d7185c..01447ef541 100644
--- a/examples/widgets/tools/undo/document.h
+++ b/examples/widgets/tools/undo/document.h
@@ -70,7 +70,7 @@ public:
QColor color() const;
static QString typeToString(Type type);
- static Type stringToType(const QString &s, bool *ok = 0);
+ static Type stringToType(const QString &s, bool *ok = nullptr);
static const QSize minSize;
@@ -88,7 +88,7 @@ class Document : public QWidget
Q_OBJECT
public:
- Document(QWidget *parent = 0);
+ Document(QWidget *parent = nullptr);
QString addShape(const Shape &shape);
void deleteShape(const QString &shapeName);
@@ -121,14 +121,13 @@ private:
int indexAt(const QPoint &pos) const;
QString uniqueName(const QString &name) const;
- QList<Shape> m_shapeList;
- int m_currentIndex;
- int m_mousePressIndex;
+ QVector<Shape> m_shapeList;
QPoint m_mousePressOffset;
- bool m_resizeHandlePressed;
QString m_fileName;
-
- QUndoStack *m_undoStack;
+ QUndoStack *m_undoStack = nullptr;
+ int m_currentIndex = -1;
+ int m_mousePressIndex = -1;
+ bool m_resizeHandlePressed = false;
};
#endif // DOCUMENT_H
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
diff --git a/examples/widgets/tools/undo/mainwindow.h b/examples/widgets/tools/undo/mainwindow.h
index 57c1f87ab2..87ee3084fb 100644
--- a/examples/widgets/tools/undo/mainwindow.h
+++ b/examples/widgets/tools/undo/mainwindow.h
@@ -61,7 +61,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindow
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
+ MainWindow(QWidget *parent = nullptr);
void addDocument(Document *doc);
void removeDocument(Document *doc);
diff --git a/examples/widgets/tools/undoframework/commands.cpp b/examples/widgets/tools/undoframework/commands.cpp
index c3e7383de1..077d7eccaa 100644
--- a/examples/widgets/tools/undoframework/commands.cpp
+++ b/examples/widgets/tools/undoframework/commands.cpp
@@ -48,19 +48,17 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "commands.h"
#include "diagramitem.h"
+#include <QGraphicsScene>
+
//! [0]
MoveCommand::MoveCommand(DiagramItem *diagramItem, const QPointF &oldPos,
- QUndoCommand *parent)
- : QUndoCommand(parent)
+ QUndoCommand *parent)
+ : QUndoCommand(parent), myDiagramItem(diagramItem)
+ , myOldPos(oldPos), newPos(diagramItem->pos())
{
- myDiagramItem = diagramItem;
- newPos = diagramItem->pos();
- myOldPos = oldPos;
}
//! [0]
@@ -71,7 +69,7 @@ bool MoveCommand::mergeWith(const QUndoCommand *command)
DiagramItem *item = moveCommand->myDiagramItem;
if (myDiagramItem != item)
- return false;
+ return false;
newPos = item->pos();
setText(QObject::tr("Move %1")
@@ -102,9 +100,8 @@ void MoveCommand::redo()
//! [4]
DeleteCommand::DeleteCommand(QGraphicsScene *scene, QUndoCommand *parent)
- : QUndoCommand(parent)
+ : QUndoCommand(parent), myGraphicsScene(scene)
{
- myGraphicsScene = scene;
QList<QGraphicsItem *> list = myGraphicsScene->selectedItems();
list.first()->setSelected(false);
myDiagramItem = static_cast<DiagramItem *>(list.first());
@@ -131,11 +128,10 @@ void DeleteCommand::redo()
//! [7]
AddCommand::AddCommand(DiagramItem::DiagramType addType,
QGraphicsScene *scene, QUndoCommand *parent)
- : QUndoCommand(parent)
+ : QUndoCommand(parent), myGraphicsScene(scene)
{
static int itemCount = 0;
- myGraphicsScene = scene;
myDiagramItem = new DiagramItem(addType);
initialPosition = QPointF((itemCount * 15) % int(scene->width()),
(itemCount * 15) % int(scene->height()));
diff --git a/examples/widgets/tools/undoframework/commands.h b/examples/widgets/tools/undoframework/commands.h
index dc53c14557..185d36d668 100644
--- a/examples/widgets/tools/undoframework/commands.h
+++ b/examples/widgets/tools/undoframework/commands.h
@@ -62,7 +62,7 @@ public:
enum { Id = 1234 };
MoveCommand(DiagramItem *diagramItem, const QPointF &oldPos,
- QUndoCommand *parent = 0);
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
@@ -80,7 +80,7 @@ private:
class DeleteCommand : public QUndoCommand
{
public:
- explicit DeleteCommand(QGraphicsScene *graphicsScene, QUndoCommand *parent = 0);
+ explicit DeleteCommand(QGraphicsScene *graphicsScene, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
@@ -96,7 +96,7 @@ class AddCommand : public QUndoCommand
{
public:
AddCommand(DiagramItem::DiagramType addType, QGraphicsScene *graphicsScene,
- QUndoCommand *parent = 0);
+ QUndoCommand *parent = nullptr);
~AddCommand();
void undo() override;
diff --git a/examples/widgets/tools/undoframework/diagramitem.cpp b/examples/widgets/tools/undoframework/diagramitem.cpp
index 723645c9b2..91da6538cf 100644
--- a/examples/widgets/tools/undoframework/diagramitem.cpp
+++ b/examples/widgets/tools/undoframework/diagramitem.cpp
@@ -48,10 +48,11 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "diagramitem.h"
+#include <QBrush>
+#include <QRandomGenerator>
+
DiagramItem::DiagramItem(DiagramType diagramType, QGraphicsItem *item)
: QGraphicsPolygonItem(item)
{
@@ -65,7 +66,9 @@ DiagramItem::DiagramItem(DiagramType diagramType, QGraphicsItem *item)
setPolygon(trianglePolygon);
}
- QColor color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256));
+ QColor color(QRandomGenerator::global()->bounded(256),
+ QRandomGenerator::global()->bounded(256),
+ QRandomGenerator::global()->bounded(256));
QBrush brush(color);
setBrush(brush);
setFlag(QGraphicsItem::ItemIsSelectable);
diff --git a/examples/widgets/tools/undoframework/diagramitem.h b/examples/widgets/tools/undoframework/diagramitem.h
index 1638dcbea8..13ff614427 100644
--- a/examples/widgets/tools/undoframework/diagramitem.h
+++ b/examples/widgets/tools/undoframework/diagramitem.h
@@ -66,9 +66,10 @@ public:
enum { Type = UserType + 1 };
enum DiagramType { Box, Triangle };
- explicit DiagramItem(DiagramType diagramType, QGraphicsItem *item = 0);
+ explicit DiagramItem(DiagramType diagramType, QGraphicsItem *item = nullptr);
- DiagramType diagramType() const {
+ DiagramType diagramType() const
+ {
return polygon() == boxPolygon ? Box : Triangle;
}
int type() const override { return Type; }
diff --git a/examples/widgets/tools/undoframework/diagramscene.cpp b/examples/widgets/tools/undoframework/diagramscene.cpp
index 63aad97cb1..65909ab6cb 100644
--- a/examples/widgets/tools/undoframework/diagramscene.cpp
+++ b/examples/widgets/tools/undoframework/diagramscene.cpp
@@ -48,27 +48,24 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "diagramscene.h"
#include "diagramitem.h"
+#include <QGraphicsSceneMouseEvent>
+
DiagramScene::DiagramScene(QObject *parent)
: QGraphicsScene(parent)
-{
- movingItem = 0;
-}
+{}
void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QPointF mousePos(event->buttonDownScenePos(Qt::LeftButton).x(),
event->buttonDownScenePos(Qt::LeftButton).y());
const QList<QGraphicsItem *> itemList = items(mousePos);
- movingItem = itemList.isEmpty() ? 0 : itemList.first();
+ movingItem = itemList.isEmpty() ? nullptr : itemList.first();
- if (movingItem != 0 && event->button() == Qt::LeftButton) {
+ if (movingItem != nullptr && event->button() == Qt::LeftButton)
oldPos = movingItem->pos();
- }
clearSelection();
QGraphicsScene::mousePressEvent(event);
@@ -76,11 +73,11 @@ void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- if (movingItem != 0 && event->button() == Qt::LeftButton) {
+ if (movingItem != nullptr && event->button() == Qt::LeftButton) {
if (oldPos != movingItem->pos())
emit itemMoved(qgraphicsitem_cast<DiagramItem *>(movingItem),
oldPos);
- movingItem = 0;
+ movingItem = nullptr;
}
QGraphicsScene::mouseReleaseEvent(event);
}
diff --git a/examples/widgets/tools/undoframework/diagramscene.h b/examples/widgets/tools/undoframework/diagramscene.h
index b1e2804ba6..205d4162bb 100644
--- a/examples/widgets/tools/undoframework/diagramscene.h
+++ b/examples/widgets/tools/undoframework/diagramscene.h
@@ -66,7 +66,7 @@ class DiagramScene : public QGraphicsScene
Q_OBJECT
public:
- DiagramScene(QObject *parent = 0);
+ DiagramScene(QObject *parent = nullptr);
signals:
void itemMoved(DiagramItem *movedItem, const QPointF &movedFromPosition);
@@ -76,7 +76,7 @@ protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
private:
- QGraphicsItem *movingItem;
+ QGraphicsItem *movingItem = nullptr;
QPointF oldPos;
};
//! [0]
diff --git a/examples/widgets/tools/undoframework/main.cpp b/examples/widgets/tools/undoframework/main.cpp
index 51fb5c53eb..cf090f56eb 100644
--- a/examples/widgets/tools/undoframework/main.cpp
+++ b/examples/widgets/tools/undoframework/main.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
#include "mainwindow.h"
diff --git a/examples/widgets/tools/undoframework/mainwindow.cpp b/examples/widgets/tools/undoframework/mainwindow.cpp
index e95d50d164..583af11a2b 100644
--- a/examples/widgets/tools/undoframework/mainwindow.cpp
+++ b/examples/widgets/tools/undoframework/mainwindow.cpp
@@ -48,13 +48,18 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "mainwindow.h"
#include "diagramscene.h"
#include "diagramitem.h"
#include "commands.h"
+#include <QAction>
+#include <QGraphicsView>
+#include <QMenu>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QUndoView>
+
//! [0]
MainWindow::MainWindow()
{
diff --git a/examples/widgets/tools/undoframework/mainwindow.h b/examples/widgets/tools/undoframework/mainwindow.h
index def2b7d789..c1a56e0770 100644
--- a/examples/widgets/tools/undoframework/mainwindow.h
+++ b/examples/widgets/tools/undoframework/mainwindow.h
@@ -87,22 +87,22 @@ private:
void createMenus();
void createUndoView();
- QAction *deleteAction;
- QAction *addBoxAction;
- QAction *addTriangleAction;
- QAction *undoAction;
- QAction *redoAction;
- QAction *exitAction;
- QAction *aboutAction;
+ QAction *deleteAction = nullptr;
+ QAction *addBoxAction = nullptr;
+ QAction *addTriangleAction = nullptr;
+ QAction *undoAction = nullptr;
+ QAction *redoAction = nullptr;
+ QAction *exitAction = nullptr;
+ QAction *aboutAction = nullptr;
- QMenu *fileMenu;
- QMenu *editMenu;
- QMenu *itemMenu;
- QMenu *helpMenu;
+ QMenu *fileMenu = nullptr;
+ QMenu *editMenu = nullptr;
+ QMenu *itemMenu = nullptr;
+ QMenu *helpMenu = nullptr;
- DiagramScene *diagramScene;
- QUndoStack *undoStack;
- QUndoView *undoView;
+ DiagramScene *diagramScene = nullptr;
+ QUndoStack *undoStack = nullptr;
+ QUndoView *undoView = nullptr;
};
//! [0]
diff --git a/examples/widgets/touch/fingerpaint/scribblearea.h b/examples/widgets/touch/fingerpaint/scribblearea.h
index 5138e3a1ab..fcdde53cc4 100644
--- a/examples/widgets/touch/fingerpaint/scribblearea.h
+++ b/examples/widgets/touch/fingerpaint/scribblearea.h
@@ -62,7 +62,7 @@ class ScribbleArea : public QWidget
Q_OBJECT
public:
- ScribbleArea(QWidget *parent = 0);
+ ScribbleArea(QWidget *parent = nullptr);
bool openImage(const QString &fileName);
bool saveImage(const QString &fileName, const char *fileFormat);
diff --git a/examples/widgets/touch/pinchzoom/graphicsview.cpp b/examples/widgets/touch/pinchzoom/graphicsview.cpp
index 54e134aea2..6412f350a7 100644
--- a/examples/widgets/touch/pinchzoom/graphicsview.cpp
+++ b/examples/widgets/touch/pinchzoom/graphicsview.cpp
@@ -54,7 +54,7 @@
#include <QTouchEvent>
GraphicsView::GraphicsView(QGraphicsScene *scene, QWidget *parent)
- : QGraphicsView(scene, parent), totalScaleFactor(1)
+ : QGraphicsView(scene, parent)
{
viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
setDragMode(ScrollHandDrag);
@@ -83,8 +83,8 @@ bool GraphicsView::viewportEvent(QEvent *event)
totalScaleFactor *= currentScaleFactor;
currentScaleFactor = 1;
}
- setTransform(QTransform().scale(totalScaleFactor * currentScaleFactor,
- totalScaleFactor * currentScaleFactor));
+ setTransform(QTransform::fromScale(totalScaleFactor * currentScaleFactor,
+ totalScaleFactor * currentScaleFactor));
}
return true;
}
diff --git a/examples/widgets/touch/pinchzoom/graphicsview.h b/examples/widgets/touch/pinchzoom/graphicsview.h
index d4e2e32d36..c0faeba444 100644
--- a/examples/widgets/touch/pinchzoom/graphicsview.h
+++ b/examples/widgets/touch/pinchzoom/graphicsview.h
@@ -56,10 +56,10 @@ class GraphicsView : public QGraphicsView
Q_OBJECT
public:
- GraphicsView(QGraphicsScene *scene = 0, QWidget *parent = 0);
+ GraphicsView(QGraphicsScene *scene = nullptr, QWidget *parent = nullptr);
bool viewportEvent(QEvent *event) override;
private:
- qreal totalScaleFactor;
+ qreal totalScaleFactor = 1;
};
diff --git a/examples/widgets/touch/pinchzoom/main.cpp b/examples/widgets/touch/pinchzoom/main.cpp
index 938432600f..2c2ba39a26 100644
--- a/examples/widgets/touch/pinchzoom/main.cpp
+++ b/examples/widgets/touch/pinchzoom/main.cpp
@@ -51,11 +51,10 @@
#include "graphicsview.h"
#include "mouse.h"
-#include <QtWidgets>
+#include <QApplication>
+#include <cmath>
-#include <math.h>
-
-static const int MouseCount = 7;
+static constexpr int MouseCount = 7;
//! [0]
int main(int argc, char **argv)
diff --git a/examples/widgets/touch/pinchzoom/mouse.cpp b/examples/widgets/touch/pinchzoom/mouse.cpp
index 1dfd7d749c..8456a0214d 100644
--- a/examples/widgets/touch/pinchzoom/mouse.cpp
+++ b/examples/widgets/touch/pinchzoom/mouse.cpp
@@ -56,8 +56,8 @@
#include <QStyleOption>
#include <qmath.h>
-const qreal Pi = M_PI;
-const qreal TwoPi = 2 * M_PI;
+constexpr qreal Pi = M_PI;
+constexpr qreal TwoPi = 2 * M_PI;
static qreal normalizeAngle(qreal angle)
{
@@ -69,9 +69,9 @@ static qreal normalizeAngle(qreal angle)
}
//! [0]
-Mouse::Mouse()
- : angle(0), speed(0), mouseEyeDirection(0),
- color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
+Mouse::Mouse() : color(QRandomGenerator::global()->bounded(256),
+ QRandomGenerator::global()->bounded(256),
+ QRandomGenerator::global()->bounded(256))
{
setTransform(QTransform().rotate(QRandomGenerator::global()->bounded(360 * 16)), true);
startTimer(1000 / 33);
diff --git a/examples/widgets/touch/pinchzoom/mouse.h b/examples/widgets/touch/pinchzoom/mouse.h
index 870bfcd6c0..8ac110821e 100644
--- a/examples/widgets/touch/pinchzoom/mouse.h
+++ b/examples/widgets/touch/pinchzoom/mouse.h
@@ -70,9 +70,9 @@ protected:
void timerEvent(QTimerEvent *event) override;
private:
- qreal angle;
- qreal speed;
- qreal mouseEyeDirection;
+ qreal angle = 0;
+ qreal speed = 0;
+ qreal mouseEyeDirection = 0;
QColor color;
};
//! [0]
diff --git a/examples/widgets/tutorials/addressbook/part1/addressbook.h b/examples/widgets/tutorials/addressbook/part1/addressbook.h
index 1d575e1260..4c2b456a41 100644
--- a/examples/widgets/tutorials/addressbook/part1/addressbook.h
+++ b/examples/widgets/tutorials/addressbook/part1/addressbook.h
@@ -65,7 +65,7 @@ class AddressBook : public QWidget
Q_OBJECT
public:
- AddressBook(QWidget *parent = 0);
+ AddressBook(QWidget *parent = nullptr);
private:
QLineEdit *nameLine;
diff --git a/examples/widgets/tutorials/addressbook/part2/addressbook.h b/examples/widgets/tutorials/addressbook/part2/addressbook.h
index 7b1714b443..e690d14244 100644
--- a/examples/widgets/tutorials/addressbook/part2/addressbook.h
+++ b/examples/widgets/tutorials/addressbook/part2/addressbook.h
@@ -66,7 +66,7 @@ class AddressBook : public QWidget
Q_OBJECT
public:
- AddressBook(QWidget *parent = 0);
+ AddressBook(QWidget *parent = nullptr);
//! [slots]
public slots:
diff --git a/examples/widgets/tutorials/addressbook/part3/addressbook.h b/examples/widgets/tutorials/addressbook/part3/addressbook.h
index 746a58a32a..f4a8aaa976 100644
--- a/examples/widgets/tutorials/addressbook/part3/addressbook.h
+++ b/examples/widgets/tutorials/addressbook/part3/addressbook.h
@@ -66,7 +66,7 @@ class AddressBook : public QWidget
Q_OBJECT
public:
- AddressBook(QWidget *parent = 0);
+ AddressBook(QWidget *parent = nullptr);
public slots:
void addContact();
diff --git a/examples/widgets/tutorials/addressbook/part4/addressbook.h b/examples/widgets/tutorials/addressbook/part4/addressbook.h
index a8d4d9fe1d..307df1eb15 100644
--- a/examples/widgets/tutorials/addressbook/part4/addressbook.h
+++ b/examples/widgets/tutorials/addressbook/part4/addressbook.h
@@ -66,7 +66,7 @@ class AddressBook : public QWidget
Q_OBJECT
public:
- AddressBook(QWidget *parent = 0);
+ AddressBook(QWidget *parent = nullptr);
//! [Mode enum]
enum Mode { NavigationMode, AddingMode, EditingMode };
//! [Mode enum]
diff --git a/examples/widgets/tutorials/addressbook/part5/addressbook.h b/examples/widgets/tutorials/addressbook/part5/addressbook.h
index b60929a50c..9dd7ed1d89 100644
--- a/examples/widgets/tutorials/addressbook/part5/addressbook.h
+++ b/examples/widgets/tutorials/addressbook/part5/addressbook.h
@@ -69,7 +69,7 @@ class AddressBook : public QWidget
Q_OBJECT
public:
- AddressBook(QWidget *parent = 0);
+ AddressBook(QWidget *parent = nullptr);
enum Mode { NavigationMode, AddingMode, EditingMode };
public slots:
diff --git a/examples/widgets/tutorials/addressbook/part5/finddialog.h b/examples/widgets/tutorials/addressbook/part5/finddialog.h
index 0fca6be81b..8e63eeee79 100644
--- a/examples/widgets/tutorials/addressbook/part5/finddialog.h
+++ b/examples/widgets/tutorials/addressbook/part5/finddialog.h
@@ -63,7 +63,7 @@ class FindDialog : public QDialog
Q_OBJECT
public:
- FindDialog(QWidget *parent = 0);
+ FindDialog(QWidget *parent = nullptr);
QString getFindText();
public slots:
diff --git a/examples/widgets/tutorials/addressbook/part6/addressbook.h b/examples/widgets/tutorials/addressbook/part6/addressbook.h
index 8d328310f7..fca62c52b7 100644
--- a/examples/widgets/tutorials/addressbook/part6/addressbook.h
+++ b/examples/widgets/tutorials/addressbook/part6/addressbook.h
@@ -68,7 +68,7 @@ class AddressBook : public QWidget
Q_OBJECT
public:
- AddressBook(QWidget *parent = 0);
+ AddressBook(QWidget *parent = nullptr);
enum Mode { NavigationMode, AddingMode, EditingMode };
public slots:
diff --git a/examples/widgets/tutorials/addressbook/part6/finddialog.h b/examples/widgets/tutorials/addressbook/part6/finddialog.h
index 527e0254e9..46f8047a56 100644
--- a/examples/widgets/tutorials/addressbook/part6/finddialog.h
+++ b/examples/widgets/tutorials/addressbook/part6/finddialog.h
@@ -63,7 +63,7 @@ class FindDialog : public QDialog
Q_OBJECT
public:
- FindDialog(QWidget *parent = 0);
+ FindDialog(QWidget *parent = nullptr);
QString getFindText();
public slots:
diff --git a/examples/widgets/tutorials/addressbook/part7/addressbook.h b/examples/widgets/tutorials/addressbook/part7/addressbook.h
index 0f109b2ef1..47a0f3c062 100644
--- a/examples/widgets/tutorials/addressbook/part7/addressbook.h
+++ b/examples/widgets/tutorials/addressbook/part7/addressbook.h
@@ -68,7 +68,7 @@ class AddressBook : public QWidget
Q_OBJECT
public:
- AddressBook(QWidget *parent = 0);
+ AddressBook(QWidget *parent = nullptr);
enum Mode { NavigationMode, AddingMode, EditingMode };
public slots:
diff --git a/examples/widgets/tutorials/addressbook/part7/finddialog.h b/examples/widgets/tutorials/addressbook/part7/finddialog.h
index 527e0254e9..46f8047a56 100644
--- a/examples/widgets/tutorials/addressbook/part7/finddialog.h
+++ b/examples/widgets/tutorials/addressbook/part7/finddialog.h
@@ -63,7 +63,7 @@ class FindDialog : public QDialog
Q_OBJECT
public:
- FindDialog(QWidget *parent = 0);
+ FindDialog(QWidget *parent = nullptr);
QString getFindText();
public slots:
diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp b/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp
index 2330019f93..90a8c6e894 100644
--- a/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp
+++ b/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp
@@ -56,7 +56,7 @@ int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableView tableView;
- MyModel myModel(0);
+ MyModel myModel;
tableView.setModel(&myModel);
tableView.show();
return a.exec();
diff --git a/examples/widgets/tutorials/modelview/7_selections/mainwindow.h b/examples/widgets/tutorials/modelview/7_selections/mainwindow.h
index c9761dd3d9..74906c831d 100644
--- a/examples/widgets/tutorials/modelview/7_selections/mainwindow.h
+++ b/examples/widgets/tutorials/modelview/7_selections/mainwindow.h
@@ -69,7 +69,7 @@ private:
private slots:
void selectionChangedSlot(const QItemSelection &newSelection, const QItemSelection &oldSelection);
public:
- MainWindow(QWidget *parent = 0);
+ MainWindow(QWidget *parent = nullptr);
};
#endif // MAINWINDOW_H
diff --git a/examples/widgets/tutorials/notepad/notepad.h b/examples/widgets/tutorials/notepad/notepad.h
index 9580ab8071..5e44dfeedc 100644
--- a/examples/widgets/tutorials/notepad/notepad.h
+++ b/examples/widgets/tutorials/notepad/notepad.h
@@ -72,7 +72,7 @@ class Notepad : public QMainWindow
//! [4]
public:
- explicit Notepad(QWidget *parent = 0);
+ explicit Notepad(QWidget *parent = nullptr);
//! [4]
//! [5]
~Notepad();
diff --git a/examples/widgets/widgets/analogclock/analogclock.cpp b/examples/widgets/widgets/analogclock/analogclock.cpp
index c7b3f66cca..06e298659d 100644
--- a/examples/widgets/widgets/analogclock/analogclock.cpp
+++ b/examples/widgets/widgets/analogclock/analogclock.cpp
@@ -50,7 +50,9 @@
#include "analogclock.h"
-#include <QtWidgets>
+#include <QPainter>
+#include <QTime>
+#include <QTimer>
//! [0] //! [1]
AnalogClock::AnalogClock(QWidget *parent)
diff --git a/examples/widgets/widgets/calculator/button.cpp b/examples/widgets/widgets/calculator/button.cpp
index a1ce0bf428..cc370a563c 100644
--- a/examples/widgets/widgets/calculator/button.cpp
+++ b/examples/widgets/widgets/calculator/button.cpp
@@ -50,8 +50,6 @@
#include "button.h"
-#include <QtWidgets>
-
//! [0]
Button::Button(const QString &text, QWidget *parent)
: QToolButton(parent)
diff --git a/examples/widgets/widgets/calculator/calculator.cpp b/examples/widgets/widgets/calculator/calculator.cpp
index dd908cf40a..2c3669b7a8 100644
--- a/examples/widgets/widgets/calculator/calculator.cpp
+++ b/examples/widgets/widgets/calculator/calculator.cpp
@@ -48,21 +48,18 @@
**
****************************************************************************/
-#include "button.h"
#include "calculator.h"
+#include "button.h"
-#include <QtWidgets>
-
-#include <cmath>
+#include <QGridLayout>
+#include <QLineEdit>
+#include <QtMath>
//! [0]
Calculator::Calculator(QWidget *parent)
- : QWidget(parent)
+ : QWidget(parent), sumInMemory(0.0), sumSoFar(0.0)
+ , factorSoFar(0.0), waitingForOperand(true)
{
- sumInMemory = 0.0;
- sumSoFar = 0.0;
- factorSoFar = 0.0;
- waitingForOperand = true;
//! [0]
//! [1]
@@ -78,9 +75,8 @@ Calculator::Calculator(QWidget *parent)
//! [2]
//! [4]
- for (int i = 0; i < NumDigitButtons; ++i) {
+ for (int i = 0; i < NumDigitButtons; ++i)
digitButtons[i] = createButton(QString::number(i), SLOT(digitClicked()));
- }
Button *pointButton = createButton(tr("."), SLOT(pointClicked()));
Button *changeSignButton = createButton(tr("\302\261"), SLOT(changeSignClicked()));
@@ -194,6 +190,8 @@ void Calculator::additiveOperatorClicked()
//! [10] //! [11]
{
Button *clickedButton = qobject_cast<Button *>(sender());
+ if (!clickedButton)
+ return;
QString clickedOperator = clickedButton->text();
double operand = display->text().toDouble();
@@ -233,6 +231,8 @@ void Calculator::additiveOperatorClicked()
void Calculator::multiplicativeOperatorClicked()
{
Button *clickedButton = qobject_cast<Button *>(sender());
+ if (!clickedButton)
+ return;
QString clickedOperator = clickedButton->text();
double operand = display->text().toDouble();
diff --git a/examples/widgets/widgets/calendarwidget/main.cpp b/examples/widgets/widgets/calendarwidget/main.cpp
index 2622669f32..2582e83841 100644
--- a/examples/widgets/widgets/calendarwidget/main.cpp
+++ b/examples/widgets/widgets/calendarwidget/main.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
#include "window.h"
diff --git a/examples/widgets/widgets/calendarwidget/window.cpp b/examples/widgets/widgets/calendarwidget/window.cpp
index 64047aaac9..b8a3d03552 100644
--- a/examples/widgets/widgets/calendarwidget/window.cpp
+++ b/examples/widgets/widgets/calendarwidget/window.cpp
@@ -48,10 +48,18 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "window.h"
+#include <QCalendarWidget>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QDateEdit>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QLabel>
+#include <QLocale>
+#include <QTextCharFormat>
+
//! [0]
Window::Window(QWidget *parent)
: QWidget(parent)
@@ -166,13 +174,12 @@ void Window::reformatHeaders()
QString text = headerTextFormatCombo->currentText();
QTextCharFormat format;
- if (text == tr("Bold")) {
+ if (text == tr("Bold"))
format.setFontWeight(QFont::Bold);
- } else if (text == tr("Italic")) {
+ else if (text == tr("Italic"))
format.setFontItalic(true);
- } else if (text == tr("Green")) {
+ else if (text == tr("Green"))
format.setForeground(Qt::green);
- }
calendar->setHeaderTextFormat(format);
}
//! [7]
diff --git a/examples/widgets/widgets/charactermap/characterwidget.cpp b/examples/widgets/widgets/charactermap/characterwidget.cpp
index 061c0164b0..41406b7fb4 100644
--- a/examples/widgets/widgets/charactermap/characterwidget.cpp
+++ b/examples/widgets/widgets/charactermap/characterwidget.cpp
@@ -50,11 +50,14 @@
#include "characterwidget.h"
-#include <QtWidgets>
+#include <QFontDatabase>
+#include <QMouseEvent>
+#include <QPainter>
+#include <QToolTip>
//! [0]
CharacterWidget::CharacterWidget(QWidget *parent)
- : QWidget(parent), columns(16), lastKey(-1)
+ : QWidget(parent)
{
calculateSquareSize();
setMouseTracking(true);
@@ -110,7 +113,7 @@ void CharacterWidget::calculateSquareSize()
//! [3]
QSize CharacterWidget::sizeHint() const
{
- return QSize(columns*squareSize, (65536/columns)*squareSize);
+ return QSize(columns*squareSize, (65536 / columns) * squareSize);
}
//! [3]
@@ -118,7 +121,7 @@ QSize CharacterWidget::sizeHint() const
void CharacterWidget::mouseMoveEvent(QMouseEvent *event)
{
QPoint widgetPosition = mapFromGlobal(event->globalPos());
- uint key = (widgetPosition.y()/squareSize)*columns + widgetPosition.x()/squareSize;
+ uint key = (widgetPosition.y() / squareSize) * columns + widgetPosition.x() / squareSize;
QString text = QString::fromLatin1("<p>Character: <span style=\"font-size: 24pt; font-family: %1\">").arg(displayFont.family())
+ QChar(key)
@@ -132,7 +135,7 @@ void CharacterWidget::mouseMoveEvent(QMouseEvent *event)
void CharacterWidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
- lastKey = (event->y()/squareSize)*columns + event->x()/squareSize;
+ lastKey = (event->y() / squareSize) * columns + event->x() / squareSize;
if (QChar(lastKey).category() != QChar::Other_NotAssigned)
emit characterSelected(QString(QChar(lastKey)));
update();
@@ -152,17 +155,17 @@ void CharacterWidget::paintEvent(QPaintEvent *event)
//! [7]
QRect redrawRect = event->rect();
- int beginRow = redrawRect.top()/squareSize;
- int endRow = redrawRect.bottom()/squareSize;
- int beginColumn = redrawRect.left()/squareSize;
- int endColumn = redrawRect.right()/squareSize;
+ int beginRow = redrawRect.top() / squareSize;
+ int endRow = redrawRect.bottom() / squareSize;
+ int beginColumn = redrawRect.left() / squareSize;
+ int endColumn = redrawRect.right() / squareSize;
//! [7]
//! [8]
painter.setPen(QPen(Qt::gray));
for (int row = beginRow; row <= endRow; ++row) {
for (int column = beginColumn; column <= endColumn; ++column) {
- painter.drawRect(column*squareSize, row*squareSize, squareSize, squareSize);
+ painter.drawRect(column * squareSize, row * squareSize, squareSize, squareSize);
}
//! [8] //! [9]
}
@@ -172,17 +175,17 @@ void CharacterWidget::paintEvent(QPaintEvent *event)
QFontMetrics fontMetrics(displayFont);
painter.setPen(QPen(Qt::black));
for (int row = beginRow; row <= endRow; ++row) {
-
for (int column = beginColumn; column <= endColumn; ++column) {
-
- int key = row*columns + column;
- painter.setClipRect(column*squareSize, row*squareSize, squareSize, squareSize);
+ int key = row * columns + column;
+ painter.setClipRect(column * squareSize, row * squareSize, squareSize, squareSize);
if (key == lastKey)
- painter.fillRect(column*squareSize + 1, row*squareSize + 1, squareSize, squareSize, QBrush(Qt::red));
+ painter.fillRect(column * squareSize + 1, row * squareSize + 1,
+ squareSize, squareSize, QBrush(Qt::red));
- painter.drawText(column*squareSize + (squareSize / 2) - fontMetrics.horizontalAdvance(QChar(key))/2,
- row*squareSize + 4 + fontMetrics.ascent(),
+ painter.drawText(column * squareSize + (squareSize / 2) -
+ fontMetrics.horizontalAdvance(QChar(key)) / 2,
+ row * squareSize + 4 + fontMetrics.ascent(),
QString(QChar(key)));
}
}
diff --git a/examples/widgets/widgets/charactermap/characterwidget.h b/examples/widgets/widgets/charactermap/characterwidget.h
index d12a46aa15..67ac8a30bf 100644
--- a/examples/widgets/widgets/charactermap/characterwidget.h
+++ b/examples/widgets/widgets/charactermap/characterwidget.h
@@ -88,9 +88,9 @@ private:
void calculateSquareSize();
QFont displayFont;
- int columns;
- int lastKey;
- int squareSize;
+ int columns = 16;
+ int lastKey = -1;
+ int squareSize = 0;
};
//! [0]
diff --git a/examples/widgets/widgets/charactermap/mainwindow.cpp b/examples/widgets/widgets/charactermap/mainwindow.cpp
index 77aad145e7..25c4503ddb 100644
--- a/examples/widgets/widgets/charactermap/mainwindow.cpp
+++ b/examples/widgets/widgets/charactermap/mainwindow.cpp
@@ -48,13 +48,27 @@
**
****************************************************************************/
-#include <QtWidgets>
-
-#include "characterwidget.h"
#include "mainwindow.h"
+#include "characterwidget.h"
-//! [0]
+#include <QApplication>
+#include <QBoxLayout>
+#include <QCheckBox>
+#include <QClipboard>
+#include <QDesktopWidget>
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QFontComboBox>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMenuBar>
+#include <QPlainTextEdit>
+#include <QPushButton>
+#include <QScrollArea>
+#include <QStatusBar>
+#include <QTextStream>
+//! [0]
Q_DECLARE_METATYPE(QFontComboBox::FontFilter)
MainWindow::MainWindow(QWidget *parent)
diff --git a/examples/widgets/widgets/codeeditor/codeeditor.cpp b/examples/widgets/widgets/codeeditor/codeeditor.cpp
index 8e29860669..e93a0251e5 100644
--- a/examples/widgets/widgets/codeeditor/codeeditor.cpp
+++ b/examples/widgets/widgets/codeeditor/codeeditor.cpp
@@ -48,10 +48,11 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "codeeditor.h"
+#include <QPainter>
+#include <QTextBlock>
+
//![constructor]
CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent)
@@ -157,8 +158,8 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
//![extraAreaPaintEvent_1]
QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
- int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
- int bottom = top + (int) blockBoundingRect(block).height();
+ int top = qRound(blockBoundingGeometry(block).translated(contentOffset()).top());
+ int bottom = top + qRound(blockBoundingRect(block).height());
//![extraAreaPaintEvent_1]
//![extraAreaPaintEvent_2]
@@ -172,7 +173,7 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent *event)
block = block.next();
top = bottom;
- bottom = top + (int) blockBoundingRect(block).height();
+ bottom = top + qRound(blockBoundingRect(block).height());
++blockNumber;
}
}
diff --git a/examples/widgets/widgets/codeeditor/codeeditor.h b/examples/widgets/widgets/codeeditor/codeeditor.h
index 5a48abafc4..283a4e0bdf 100644
--- a/examples/widgets/widgets/codeeditor/codeeditor.h
+++ b/examples/widgets/widgets/codeeditor/codeeditor.h
@@ -80,7 +80,7 @@ protected:
private slots:
void updateLineNumberAreaWidth(int newBlockCount);
void highlightCurrentLine();
- void updateLineNumberArea(const QRect &, int);
+ void updateLineNumberArea(const QRect &rect, int dy);
private:
QWidget *lineNumberArea;
@@ -92,16 +92,17 @@ private:
class LineNumberArea : public QWidget
{
public:
- LineNumberArea(CodeEditor *editor) : QWidget(editor) {
- codeEditor = editor;
- }
+ LineNumberArea(CodeEditor *editor) : QWidget(editor), codeEditor(editor)
+ {}
- QSize sizeHint() const override {
+ QSize sizeHint() const override
+ {
return QSize(codeEditor->lineNumberAreaWidth(), 0);
}
protected:
- void paintEvent(QPaintEvent *event) override {
+ void paintEvent(QPaintEvent *event) override
+ {
codeEditor->lineNumberAreaPaintEvent(event);
}
diff --git a/examples/widgets/widgets/codeeditor/main.cpp b/examples/widgets/widgets/codeeditor/main.cpp
index e17acb87cd..72d186553a 100644
--- a/examples/widgets/widgets/codeeditor/main.cpp
+++ b/examples/widgets/widgets/codeeditor/main.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
#include "codeeditor.h"
diff --git a/examples/widgets/widgets/digitalclock/digitalclock.cpp b/examples/widgets/widgets/digitalclock/digitalclock.cpp
index 000334f33b..2b130ecda6 100644
--- a/examples/widgets/widgets/digitalclock/digitalclock.cpp
+++ b/examples/widgets/widgets/digitalclock/digitalclock.cpp
@@ -50,7 +50,8 @@
#include "digitalclock.h"
-#include <QtWidgets>
+#include <QTime>
+#include <QTimer>
//! [0]
DigitalClock::DigitalClock(QWidget *parent)
diff --git a/examples/widgets/widgets/groupbox/window.cpp b/examples/widgets/widgets/groupbox/window.cpp
index 230d360372..95c4f216fe 100644
--- a/examples/widgets/widgets/groupbox/window.cpp
+++ b/examples/widgets/widgets/groupbox/window.cpp
@@ -48,10 +48,15 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "window.h"
+#include <QCheckBox>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QMenu>
+#include <QPushButton>
+#include <QRadioButton>
+
//! [0]
Window::Window(QWidget *parent)
: QWidget(parent)
diff --git a/examples/widgets/widgets/icons/iconpreviewarea.cpp b/examples/widgets/widgets/icons/iconpreviewarea.cpp
index 7a73a137cd..96cb6f008e 100644
--- a/examples/widgets/widgets/icons/iconpreviewarea.cpp
+++ b/examples/widgets/widgets/icons/iconpreviewarea.cpp
@@ -50,7 +50,8 @@
#include "iconpreviewarea.h"
-#include <QtWidgets>
+#include <QGridLayout>
+#include <QLabel>
//! [0]
IconPreviewArea::IconPreviewArea(QWidget *parent)
diff --git a/examples/widgets/widgets/icons/iconsizespinbox.cpp b/examples/widgets/widgets/icons/iconsizespinbox.cpp
index e94d943993..8e6c654686 100644
--- a/examples/widgets/widgets/icons/iconsizespinbox.cpp
+++ b/examples/widgets/widgets/icons/iconsizespinbox.cpp
@@ -50,7 +50,7 @@
#include "iconsizespinbox.h"
-#include <QtWidgets>
+#include <QRegularExpression>
//! [0]
IconSizeSpinBox::IconSizeSpinBox(QWidget *parent)
diff --git a/examples/widgets/widgets/icons/imagedelegate.cpp b/examples/widgets/widgets/icons/imagedelegate.cpp
index 786194bae7..39c2e43134 100644
--- a/examples/widgets/widgets/icons/imagedelegate.cpp
+++ b/examples/widgets/widgets/icons/imagedelegate.cpp
@@ -51,7 +51,7 @@
#include "imagedelegate.h"
#include "iconpreviewarea.h"
-#include <QtWidgets>
+#include <QComboBox>
//! [0]
ImageDelegate::ImageDelegate(QObject *parent)
diff --git a/examples/widgets/widgets/icons/mainwindow.cpp b/examples/widgets/widgets/icons/mainwindow.cpp
index 91e98ff896..f342c18c4c 100644
--- a/examples/widgets/widgets/icons/mainwindow.cpp
+++ b/examples/widgets/widgets/icons/mainwindow.cpp
@@ -48,14 +48,29 @@
**
****************************************************************************/
-#include <QtWidgets>
-
+#include "mainwindow.h"
#include "iconpreviewarea.h"
#include "iconsizespinbox.h"
#include "imagedelegate.h"
-#include "mainwindow.h"
-#include <memory>
+#include <QApplication>
+#include <QButtonGroup>
+#include <QCheckBox>
+#include <QFileDialog>
+#include <QHeaderView>
+#include <QFormLayout>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QImageReader>
+#include <QLabel>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QRadioButton>
+#include <QScreen>
+#include <QStandardPaths>
+#include <QStyleFactory>
+#include <QTableWidget>
+#include <QWindow>
//! [40]
enum { OtherSize = QStyle::PM_CustomBase };
diff --git a/examples/widgets/widgets/imageviewer/imageviewer.cpp b/examples/widgets/widgets/imageviewer/imageviewer.cpp
index 2fc8ff63de..83cf8bb7bc 100644
--- a/examples/widgets/widgets/imageviewer/imageviewer.cpp
+++ b/examples/widgets/widgets/imageviewer/imageviewer.cpp
@@ -50,7 +50,24 @@
#include "imageviewer.h"
-#include <QtWidgets>
+#include <QApplication>
+#include <QClipboard>
+#include <QColorSpace>
+#include <QDir>
+#include <QFileDialog>
+#include <QImageReader>
+#include <QImageWriter>
+#include <QLabel>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QMimeData>
+#include <QPainter>
+#include <QScreen>
+#include <QScrollArea>
+#include <QScrollBar>
+#include <QStandardPaths>
+#include <QStatusBar>
+
#if defined(QT_PRINTSUPPORT_LIB)
#include <QtPrintSupport/qtprintsupportglobal.h>
#if QT_CONFIG(printdialog)
@@ -60,8 +77,8 @@
//! [0]
ImageViewer::ImageViewer(QWidget *parent)
- : QMainWindow(parent), imageLabel(new QLabel),
- scrollArea(new QScrollArea), scaleFactor(1)
+ : QMainWindow(parent), imageLabel(new QLabel)
+ , scrollArea(new QScrollArea)
{
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
diff --git a/examples/widgets/widgets/imageviewer/imageviewer.h b/examples/widgets/widgets/imageviewer/imageviewer.h
index 7e53105b33..49c7ac205b 100644
--- a/examples/widgets/widgets/imageviewer/imageviewer.h
+++ b/examples/widgets/widgets/imageviewer/imageviewer.h
@@ -98,7 +98,7 @@ private:
QImage image;
QLabel *imageLabel;
QScrollArea *scrollArea;
- double scaleFactor;
+ double scaleFactor = 1;
#ifndef QT_NO_PRINTER
QPrinter printer;
diff --git a/examples/widgets/widgets/lineedits/window.cpp b/examples/widgets/widgets/lineedits/window.cpp
index 33f09d544d..bb9396411a 100644
--- a/examples/widgets/widgets/lineedits/window.cpp
+++ b/examples/widgets/widgets/lineedits/window.cpp
@@ -48,10 +48,14 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "window.h"
+#include <QComboBox>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QLabel>
+#include <QLineEdit>
+
//! [0]
Window::Window(QWidget *parent)
: QWidget(parent)
@@ -197,6 +201,7 @@ void Window::echoChanged(int index)
break;
case 3:
echoLineEdit->setEchoMode(QLineEdit::NoEcho);
+ break;
}
}
//! [9]
@@ -215,6 +220,7 @@ void Window::validatorChanged(int index)
case 2:
validatorLineEdit->setValidator(new QDoubleValidator(-999.0,
999.0, 2, validatorLineEdit));
+ break;
}
validatorLineEdit->clear();
@@ -233,6 +239,7 @@ void Window::alignmentChanged(int index)
break;
case 2:
alignmentLineEdit->setAlignment(Qt::AlignRight);
+ break;
}
}
//! [11]
@@ -254,6 +261,7 @@ void Window::inputMaskChanged(int index)
break;
case 3:
inputMaskLineEdit->setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#");
+ break;
}
}
//! [12]
@@ -267,6 +275,7 @@ void Window::accessChanged(int index)
break;
case 1:
accessLineEdit->setReadOnly(true);
+ break;
}
}
//! [13]
diff --git a/examples/widgets/widgets/movie/movieplayer.cpp b/examples/widgets/widgets/movie/movieplayer.cpp
index 182b258a82..41cd7923ee 100644
--- a/examples/widgets/widgets/movie/movieplayer.cpp
+++ b/examples/widgets/widgets/movie/movieplayer.cpp
@@ -50,7 +50,15 @@
#include "movieplayer.h"
-#include <QtWidgets>
+#include <QCheckBox>
+#include <QFileDialog>
+#include <QLabel>
+#include <QMovie>
+#include <QSlider>
+#include <QSpinBox>
+#include <QStyle>
+#include <QToolButton>
+#include <QVBoxLayout>
MoviePlayer::MoviePlayer(QWidget *parent)
: QWidget(parent)
diff --git a/examples/widgets/widgets/scribble/mainwindow.cpp b/examples/widgets/widgets/scribble/mainwindow.cpp
index 44afa64b94..c9a34796ac 100644
--- a/examples/widgets/widgets/scribble/mainwindow.cpp
+++ b/examples/widgets/widgets/scribble/mainwindow.cpp
@@ -48,11 +48,18 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "mainwindow.h"
#include "scribblearea.h"
+#include <QApplication>
+#include <QColorDialog>
+#include <QFileDialog>
+#include <QImageWriter>
+#include <QInputDialog>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QCloseEvent>
+
//! [0]
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), scribbleArea(new ScribbleArea(this))
@@ -71,11 +78,10 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::closeEvent(QCloseEvent *event)
//! [1] //! [2]
{
- if (maybeSave()) {
+ if (maybeSave())
event->accept();
- } else {
+ else
event->ignore();
- }
}
//! [2]
@@ -231,11 +237,10 @@ bool MainWindow::maybeSave()
"Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard
| QMessageBox::Cancel);
- if (ret == QMessageBox::Save) {
+ if (ret == QMessageBox::Save)
return saveFile("png");
- } else if (ret == QMessageBox::Cancel) {
+ else if (ret == QMessageBox::Cancel)
return false;
- }
}
return true;
}
@@ -252,10 +257,8 @@ bool MainWindow::saveFile(const QByteArray &fileFormat)
tr("%1 Files (*.%2);;All Files (*)")
.arg(QString::fromLatin1(fileFormat.toUpper()))
.arg(QString::fromLatin1(fileFormat)));
- if (fileName.isEmpty()) {
+ if (fileName.isEmpty())
return false;
- } else {
- return scribbleArea->saveImage(fileName, fileFormat.constData());
- }
+ return scribbleArea->saveImage(fileName, fileFormat.constData());
}
//! [20]
diff --git a/examples/widgets/widgets/scribble/scribblearea.cpp b/examples/widgets/widgets/scribble/scribblearea.cpp
index 13e46f6e1d..75371b523f 100644
--- a/examples/widgets/widgets/scribble/scribblearea.cpp
+++ b/examples/widgets/widgets/scribble/scribblearea.cpp
@@ -50,7 +50,9 @@
#include "scribblearea.h"
-#include <QtWidgets>
+#include <QMouseEvent>
+#include <QPainter>
+
#if defined(QT_PRINTSUPPORT_LIB)
#include <QtPrintSupport/qtprintsupportglobal.h>
#if QT_CONFIG(printdialog)
@@ -64,10 +66,6 @@ ScribbleArea::ScribbleArea(QWidget *parent)
: QWidget(parent)
{
setAttribute(Qt::WA_StaticContents);
- modified = false;
- scribbling = false;
- myPenWidth = 1;
- myPenColor = Qt::blue;
}
//! [0]
@@ -98,9 +96,8 @@ bool ScribbleArea::saveImage(const QString &fileName, const char *fileFormat)
if (visibleImage.save(fileName, fileFormat)) {
modified = false;
return true;
- } else {
- return false;
}
+ return false;
}
//! [4]
diff --git a/examples/widgets/widgets/scribble/scribblearea.h b/examples/widgets/widgets/scribble/scribblearea.h
index 100c45e133..ed3c8a2a15 100644
--- a/examples/widgets/widgets/scribble/scribblearea.h
+++ b/examples/widgets/widgets/scribble/scribblearea.h
@@ -88,10 +88,10 @@ private:
void drawLineTo(const QPoint &endPoint);
void resizeImage(QImage *image, const QSize &newSize);
- bool modified;
- bool scribbling;
- int myPenWidth;
- QColor myPenColor;
+ bool modified = false;
+ bool scribbling = false;
+ int myPenWidth = 1;
+ QColor myPenColor = Qt::blue;
QImage image;
QPoint lastPoint;
};
diff --git a/examples/widgets/widgets/shapedclock/shapedclock.cpp b/examples/widgets/widgets/shapedclock/shapedclock.cpp
index 8e7d831938..3c78f4da89 100644
--- a/examples/widgets/widgets/shapedclock/shapedclock.cpp
+++ b/examples/widgets/widgets/shapedclock/shapedclock.cpp
@@ -48,10 +48,15 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "shapedclock.h"
+#include <QAction>
+#include <QCoreApplication>
+#include <QMouseEvent>
+#include <QPainter>
+#include <QTime>
+#include <QTimer>
+
//! [0]
ShapedClock::ShapedClock(QWidget *parent)
: QWidget(parent, Qt::FramelessWindowHint | Qt::WindowSystemMenuHint)
diff --git a/examples/widgets/widgets/sliders/slidersgroup.cpp b/examples/widgets/widgets/sliders/slidersgroup.cpp
index b4eaf9bb3d..912c9798ce 100644
--- a/examples/widgets/widgets/sliders/slidersgroup.cpp
+++ b/examples/widgets/widgets/sliders/slidersgroup.cpp
@@ -50,7 +50,10 @@
#include "slidersgroup.h"
-#include <QtWidgets>
+#include <QBoxLayout>
+#include <QDial>
+#include <QScrollBar>
+#include <QSlider>
//! [0]
SlidersGroup::SlidersGroup(Qt::Orientation orientation, const QString &title,
diff --git a/examples/widgets/widgets/sliders/window.cpp b/examples/widgets/widgets/sliders/window.cpp
index d73fafec10..4a28a61f3d 100644
--- a/examples/widgets/widgets/sliders/window.cpp
+++ b/examples/widgets/widgets/sliders/window.cpp
@@ -48,11 +48,16 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "slidersgroup.h"
#include "window.h"
+#include <QCheckBox>
+#include <QComboBox>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QSpinBox>
+#include <QStackedWidget>
+
//! [0]
Window::Window(QWidget *parent)
: QWidget(parent)
diff --git a/examples/widgets/widgets/spinboxes/window.cpp b/examples/widgets/widgets/spinboxes/window.cpp
index 82e19527a7..40c02aba70 100644
--- a/examples/widgets/widgets/spinboxes/window.cpp
+++ b/examples/widgets/widgets/spinboxes/window.cpp
@@ -48,10 +48,16 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "window.h"
+#include <QCheckBox>
+#include <QComboBox>
+#include <QDateTimeEdit>
+#include <QGroupBox>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QSpinBox>
+
//! [0]
Window::Window(QWidget *parent)
: QWidget(parent)
diff --git a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
index a178769bd8..0f614a2e9a 100644
--- a/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
+++ b/examples/widgets/widgets/styles/norwegianwoodstyle.cpp
@@ -50,7 +50,10 @@
#include "norwegianwoodstyle.h"
-#include <QtWidgets>
+#include <QComboBox>
+#include <QPainter>
+#include <QPushButton>
+#include <QStyleFactory>
NorwegianWoodStyle::NorwegianWoodStyle() :
QProxyStyle(QStyleFactory::create("windows"))
diff --git a/examples/widgets/widgets/styles/widgetgallery.cpp b/examples/widgets/widgets/styles/widgetgallery.cpp
index 34c010df74..fd8f0ec2d1 100644
--- a/examples/widgets/widgets/styles/widgetgallery.cpp
+++ b/examples/widgets/widgets/styles/widgetgallery.cpp
@@ -51,7 +51,24 @@
#include "widgetgallery.h"
#include "norwegianwoodstyle.h"
-#include <QtWidgets>
+#include <QApplication>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QDateTimeEdit>
+#include <QDial>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QLabel>
+#include <QLineEdit>
+#include <QProgressBar>
+#include <QPushButton>
+#include <QRadioButton>
+#include <QScrollBar>
+#include <QSpinBox>
+#include <QStyleFactory>
+#include <QTableWidget>
+#include <QTextEdit>
+#include <QTimer>
//! [0]
WidgetGallery::WidgetGallery(QWidget *parent)
diff --git a/examples/widgets/widgets/stylesheet/main.cpp b/examples/widgets/widgets/stylesheet/main.cpp
index 1874bceb8c..3b1168398a 100644
--- a/examples/widgets/widgets/stylesheet/main.cpp
+++ b/examples/widgets/widgets/stylesheet/main.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
#include "mainwindow.h"
diff --git a/examples/widgets/widgets/stylesheet/mainwindow.cpp b/examples/widgets/widgets/stylesheet/mainwindow.cpp
index f187c007dd..a8bd20e964 100644
--- a/examples/widgets/widgets/stylesheet/mainwindow.cpp
+++ b/examples/widgets/widgets/stylesheet/mainwindow.cpp
@@ -48,11 +48,11 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "mainwindow.h"
#include "stylesheeteditor.h"
+#include <QMessageBox>
+
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
diff --git a/examples/widgets/widgets/stylesheet/mainwindow.h b/examples/widgets/widgets/stylesheet/mainwindow.h
index 8af4c01da0..ba979a3881 100644
--- a/examples/widgets/widgets/stylesheet/mainwindow.h
+++ b/examples/widgets/widgets/stylesheet/mainwindow.h
@@ -51,7 +51,7 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
-#include <QtWidgets>
+#include <QMainWindow>
#include "ui_mainwindow.h"
diff --git a/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp b/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp
index 0874cc3554..2cc0e969e2 100644
--- a/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp
+++ b/examples/widgets/widgets/stylesheet/stylesheeteditor.cpp
@@ -50,7 +50,9 @@
#include "stylesheeteditor.h"
-#include <QtWidgets>
+#include <QFile>
+#include <QRegularExpression>
+#include <QStyleFactory>
StyleSheetEditor::StyleSheetEditor(QWidget *parent)
: QDialog(parent)
diff --git a/examples/widgets/widgets/tablet/main.cpp b/examples/widgets/widgets/tablet/main.cpp
index 5726e79166..0fec526de0 100644
--- a/examples/widgets/widgets/tablet/main.cpp
+++ b/examples/widgets/widgets/tablet/main.cpp
@@ -48,8 +48,6 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "mainwindow.h"
#include "tabletapplication.h"
#include "tabletcanvas.h"
diff --git a/examples/widgets/widgets/tablet/mainwindow.cpp b/examples/widgets/widgets/tablet/mainwindow.cpp
index a048119533..8bcb9ada63 100644
--- a/examples/widgets/widgets/tablet/mainwindow.cpp
+++ b/examples/widgets/widgets/tablet/mainwindow.cpp
@@ -48,14 +48,19 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "mainwindow.h"
#include "tabletcanvas.h"
+#include <QApplication>
+#include <QColorDialog>
+#include <QDir>
+#include <QFileDialog>
+#include <QMenuBar>
+#include <QMessageBox>
+
//! [0]
MainWindow::MainWindow(TabletCanvas *canvas)
- : m_canvas(canvas), m_colorDialog(nullptr)
+ : m_canvas(canvas)
{
createMenus();
setWindowTitle(tr("Tablet Example"));
diff --git a/examples/widgets/widgets/tablet/mainwindow.h b/examples/widgets/widgets/tablet/mainwindow.h
index 4be28784b5..3ea9af7ccf 100644
--- a/examples/widgets/widgets/tablet/mainwindow.h
+++ b/examples/widgets/widgets/tablet/mainwindow.h
@@ -81,7 +81,7 @@ private:
void createMenus();
TabletCanvas *m_canvas;
- QColorDialog *m_colorDialog;
+ QColorDialog *m_colorDialog = nullptr;
};
//! [0]
diff --git a/examples/widgets/widgets/tablet/tabletapplication.cpp b/examples/widgets/widgets/tablet/tabletapplication.cpp
index 37be018276..a27491a86c 100644
--- a/examples/widgets/widgets/tablet/tabletapplication.cpp
+++ b/examples/widgets/widgets/tablet/tabletapplication.cpp
@@ -50,8 +50,6 @@
#include "tabletapplication.h"
-#include <QtWidgets>
-
//! [0]
bool TabletApplication::event(QEvent *event)
{
diff --git a/examples/widgets/widgets/tablet/tabletcanvas.cpp b/examples/widgets/widgets/tablet/tabletcanvas.cpp
index dc56702142..9a8029486d 100644
--- a/examples/widgets/widgets/tablet/tabletcanvas.cpp
+++ b/examples/widgets/widgets/tablet/tabletcanvas.cpp
@@ -48,21 +48,16 @@
**
****************************************************************************/
-#include <QtWidgets>
-#include <math.h>
-
#include "tabletcanvas.h"
+#include <QCoreApplication>
+#include <QPainter>
+#include <QtMath>
+
//! [0]
TabletCanvas::TabletCanvas()
- : QWidget(nullptr)
- , m_alphaChannelValuator(TangentialPressureValuator)
- , m_colorSaturationValuator(NoValuator)
- , m_lineWidthValuator(PressureValuator)
- , m_color(Qt::red)
- , m_brush(m_color)
- , m_pen(m_brush, 1.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)
- , m_deviceDown(false)
+ : QWidget(nullptr), m_brush(m_color)
+ , m_pen(m_brush, 1.0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)
{
resize(500, 500);
setAutoFillBackground(true);
@@ -138,7 +133,7 @@ void TabletCanvas::tabletEvent(QTabletEvent *event)
void TabletCanvas::initPixmap()
{
qreal dpr = devicePixelRatioF();
- QPixmap newPixmap = QPixmap(width() * dpr, height() * dpr);
+ QPixmap newPixmap = QPixmap(qRound(width() * dpr), qRound(height() * dpr));
newPixmap.setDevicePixelRatio(dpr);
newPixmap.fill(Qt::white);
QPainter painter(&newPixmap);
@@ -208,7 +203,7 @@ void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event)
const QString error(tr("This input device is not supported by the example."));
#if QT_CONFIG(statustip)
QStatusTipEvent status(error);
- QApplication::sendEvent(this, &status);
+ QCoreApplication::sendEvent(this, &status);
#else
qWarning() << error;
#endif
@@ -219,7 +214,7 @@ void TabletCanvas::paintPixmap(QPainter &painter, QTabletEvent *event)
const QString error(tr("Unknown tablet device - treating as stylus"));
#if QT_CONFIG(statustip)
QStatusTipEvent status(error);
- QApplication::sendEvent(this, &status);
+ QCoreApplication::sendEvent(this, &status);
#else
qWarning() << error;
#endif
@@ -261,7 +256,8 @@ void TabletCanvas::updateBrush(const QTabletEvent *event)
m_color.setAlpha(255);
break;
case TiltValuator:
- m_color.setAlpha(maximum(abs(vValue - 127), abs(hValue - 127)));
+ m_color.setAlpha(std::max(std::abs(vValue - 127),
+ std::abs(hValue - 127)));
break;
default:
m_color.setAlpha(255);
@@ -288,7 +284,8 @@ void TabletCanvas::updateBrush(const QTabletEvent *event)
m_pen.setWidthF(pressureToWidth(event->pressure()));
break;
case TiltValuator:
- m_pen.setWidthF(maximum(abs(vValue - 127), abs(hValue - 127)) / 12);
+ m_pen.setWidthF(std::max(std::abs(vValue - 127),
+ std::abs(hValue - 127)) / 12);
break;
default:
m_pen.setWidthF(1);
diff --git a/examples/widgets/widgets/tablet/tabletcanvas.h b/examples/widgets/widgets/tablet/tabletcanvas.h
index c63ef76893..4c10731b0f 100644
--- a/examples/widgets/widgets/tablet/tabletcanvas.h
+++ b/examples/widgets/widgets/tablet/tabletcanvas.h
@@ -51,14 +51,13 @@
#ifndef TABLETCANVAS_H
#define TABLETCANVAS_H
-#include <QWidget>
-#include <QPixmap>
-#include <QPoint>
-#include <QTabletEvent>
-#include <QColor>
#include <QBrush>
+#include <QColor>
#include <QPen>
+#include <QPixmap>
#include <QPoint>
+#include <QTabletEvent>
+#include <QWidget>
QT_BEGIN_NAMESPACE
class QPaintEvent;
@@ -92,8 +91,6 @@ public:
{ return m_color; }
void setTabletDevice(QTabletEvent *event)
{ updateCursor(event); }
- int maximum(int a, int b)
- { return a > b ? a : b; }
protected:
void tabletEvent(QTabletEvent *event) override;
@@ -108,19 +105,19 @@ private:
void updateBrush(const QTabletEvent *event);
void updateCursor(const QTabletEvent *event);
- Valuator m_alphaChannelValuator;
- Valuator m_colorSaturationValuator;
- Valuator m_lineWidthValuator;
- QColor m_color;
+ Valuator m_alphaChannelValuator = TangentialPressureValuator;
+ Valuator m_colorSaturationValuator = NoValuator;
+ Valuator m_lineWidthValuator = PressureValuator;
+ QColor m_color = Qt::red;
QPixmap m_pixmap;
QBrush m_brush;
QPen m_pen;
- bool m_deviceDown;
+ bool m_deviceDown = false;
struct Point {
QPointF pos;
- qreal pressure;
- qreal rotation;
+ qreal pressure = 0;
+ qreal rotation = 0;
} lastPoint;
};
//! [0]
diff --git a/examples/widgets/widgets/tetrix/tetrixboard.cpp b/examples/widgets/widgets/tetrix/tetrixboard.cpp
index ef3ac4fc38..c1192f264d 100644
--- a/examples/widgets/widgets/tetrix/tetrixboard.cpp
+++ b/examples/widgets/widgets/tetrix/tetrixboard.cpp
@@ -50,16 +50,16 @@
#include "tetrixboard.h"
-#include <QtWidgets>
+#include <QKeyEvent>
+#include <QLabel>
+#include <QPainter>
//! [0]
TetrixBoard::TetrixBoard(QWidget *parent)
- : QFrame(parent)
+ : QFrame(parent), isStarted(false), isPaused(false)
{
setFrameStyle(QFrame::Panel | QFrame::Sunken);
setFocusPolicy(Qt::StrongFocus);
- isStarted = false;
- isPaused = false;
clearBoard();
nextPiece.setRandomShape();
@@ -396,7 +396,7 @@ bool TetrixBoard::tryMove(const TetrixPiece &newPiece, int newX, int newY)
//! [36]
void TetrixBoard::drawSquare(QPainter &painter, int x, int y, TetrixShape shape)
{
- static const QRgb colorTable[8] = {
+ static constexpr QRgb colorTable[8] = {
0x000000, 0xCC6666, 0x66CC66, 0x6666CC,
0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00
};
diff --git a/examples/widgets/widgets/tetrix/tetrixpiece.cpp b/examples/widgets/widgets/tetrix/tetrixpiece.cpp
index b1b3ca9a99..9f6f6e863a 100644
--- a/examples/widgets/widgets/tetrix/tetrixpiece.cpp
+++ b/examples/widgets/widgets/tetrix/tetrixpiece.cpp
@@ -62,7 +62,7 @@ void TetrixPiece::setRandomShape()
//! [1]
void TetrixPiece::setShape(TetrixShape shape)
{
- static const int coordsTable[8][4][2] = {
+ static constexpr int coordsTable[8][4][2] = {
{ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
{ { 0, -1 }, { 0, 0 }, { -1, 0 }, { -1, 1 } },
{ { 0, -1 }, { 0, 0 }, { 1, 0 }, { 1, 1 } },
diff --git a/examples/widgets/widgets/tetrix/tetrixwindow.cpp b/examples/widgets/widgets/tetrix/tetrixwindow.cpp
index 970a38c1dc..5aa5c3f615 100644
--- a/examples/widgets/widgets/tetrix/tetrixwindow.cpp
+++ b/examples/widgets/widgets/tetrix/tetrixwindow.cpp
@@ -48,23 +48,24 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "tetrixboard.h"
#include "tetrixwindow.h"
+#include <QCoreApplication>
+#include <QGridLayout>
+#include <QLabel>
+#include <QLCDNumber>
+#include <QPushButton>
+
//! [0]
TetrixWindow::TetrixWindow(QWidget *parent)
- : QWidget(parent)
+ : QWidget(parent), board(new TetrixBoard)
{
- board = new TetrixBoard;
//! [0]
-
nextPieceLabel = new QLabel;
nextPieceLabel->setFrameStyle(QFrame::Box | QFrame::Raised);
nextPieceLabel->setAlignment(Qt::AlignCenter);
board->setNextPieceLabel(nextPieceLabel);
-
//! [1]
scoreLcd = new QLCDNumber(5);
scoreLcd->setSegmentStyle(QLCDNumber::Filled);
@@ -86,7 +87,7 @@ TetrixWindow::TetrixWindow(QWidget *parent)
connect(startButton, &QPushButton::clicked, board, &TetrixBoard::start);
//! [4] //! [5]
- connect(quitButton , &QPushButton::clicked, qApp, &QApplication::quit);
+ connect(quitButton , &QPushButton::clicked, qApp, &QCoreApplication::quit);
connect(pauseButton, &QPushButton::clicked, board, &TetrixBoard::pause);
#if __cplusplus >= 201402L
connect(board, &TetrixBoard::scoreChanged,
diff --git a/examples/widgets/widgets/tooltips/main.cpp b/examples/widgets/widgets/tooltips/main.cpp
index 8276b3dc8d..0890020f77 100644
--- a/examples/widgets/widgets/tooltips/main.cpp
+++ b/examples/widgets/widgets/tooltips/main.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
#include "sortingbox.h"
diff --git a/examples/widgets/widgets/tooltips/sortingbox.cpp b/examples/widgets/widgets/tooltips/sortingbox.cpp
index 685eaa7d1d..f99c38b233 100644
--- a/examples/widgets/widgets/tooltips/sortingbox.cpp
+++ b/examples/widgets/widgets/tooltips/sortingbox.cpp
@@ -50,7 +50,13 @@
#include "sortingbox.h"
-#include <QtWidgets>
+#include <QMouseEvent>
+#include <QIcon>
+#include <QPainter>
+#include <QRandomGenerator>
+#include <QStyle>
+#include <QToolButton>
+#include <QToolTip>
//! [0]
SortingBox::SortingBox(QWidget *parent)
@@ -277,12 +283,12 @@ QToolButton *SortingBox::createToolButton(const QString &toolTip,
QPoint SortingBox::initialItemPosition(const QPainterPath &path)
{
int x;
- int y = (height() - (int)path.controlPointRect().height()) / 2;
+ int y = (height() - qRound(path.controlPointRect().height()) / 2);
if (shapeItems.size() == 0)
- x = ((3 * width()) / 2 - (int)path.controlPointRect().width()) / 2;
+ x = ((3 * width()) / 2 - qRound(path.controlPointRect().width())) / 2;
else
x = (width() / shapeItems.size()
- - (int)path.controlPointRect().width()) / 2;
+ - qRound(path.controlPointRect().width())) / 2;
return QPoint(x, y);
}
diff --git a/examples/widgets/widgets/tooltips/sortingbox.h b/examples/widgets/widgets/tooltips/sortingbox.h
index 3d0cecea2b..785154746e 100644
--- a/examples/widgets/widgets/tooltips/sortingbox.h
+++ b/examples/widgets/widgets/tooltips/sortingbox.h
@@ -99,7 +99,7 @@ private:
const char *member);
//! [2]
- QList<ShapeItem> shapeItems;
+ QVector<ShapeItem> shapeItems;
QPainterPath circlePath;
QPainterPath squarePath;
QPainterPath trianglePath;
diff --git a/examples/widgets/widgets/validators/validatorwidget.cpp b/examples/widgets/widgets/validators/validatorwidget.cpp
index fa0a55aa52..9ddd640924 100644
--- a/examples/widgets/widgets/validators/validatorwidget.cpp
+++ b/examples/widgets/widgets/validators/validatorwidget.cpp
@@ -50,7 +50,7 @@
#include "validatorwidget.h"
-#include <QtWidgets>
+#include <QIntValidator>
ValidatorWidget::ValidatorWidget(QWidget *parent)
: QWidget(parent)
diff --git a/examples/widgets/widgets/wiggly/wigglywidget.cpp b/examples/widgets/widgets/wiggly/wigglywidget.cpp
index 0399fe9056..ab549ef07c 100644
--- a/examples/widgets/widgets/wiggly/wigglywidget.cpp
+++ b/examples/widgets/widgets/wiggly/wigglywidget.cpp
@@ -50,11 +50,13 @@
#include "wigglywidget.h"
-#include <QtWidgets>
+#include <QFontMetrics>
+#include <QPainter>
+#include <QTimerEvent>
//! [0]
WigglyWidget::WigglyWidget(QWidget *parent)
- : QWidget(parent)
+ : QWidget(parent), step(0)
{
setBackgroundRole(QPalette::Midlight);
setAutoFillBackground(true);
@@ -63,7 +65,6 @@ WigglyWidget::WigglyWidget(QWidget *parent)
newFont.setPointSize(newFont.pointSize() + 20);
setFont(newFont);
- step = 0;
timer.start(60, this);
}
//! [0]
@@ -72,7 +73,7 @@ WigglyWidget::WigglyWidget(QWidget *parent)
void WigglyWidget::paintEvent(QPaintEvent * /* event */)
//! [1] //! [2]
{
- static const int sineTable[16] = {
+ static constexpr int sineTable[16] = {
0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38
};
diff --git a/examples/widgets/widgets/windowflags/controllerwindow.cpp b/examples/widgets/widgets/windowflags/controllerwindow.cpp
index e2abad89f4..0e9a916988 100644
--- a/examples/widgets/widgets/windowflags/controllerwindow.cpp
+++ b/examples/widgets/widgets/windowflags/controllerwindow.cpp
@@ -48,10 +48,15 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "controllerwindow.h"
+#include <QCheckBox>
+#include <QCoreApplication>
+#include <QGroupBox>
+#include <QHBoxLayout>
+#include <QPushButton>
+#include <QRadioButton>
+
//! [0]
ControllerWindow::ControllerWindow(QWidget *parent)
: QWidget(parent)
@@ -63,7 +68,7 @@ ControllerWindow::ControllerWindow(QWidget *parent)
quitButton = new QPushButton(tr("&Quit"));
connect(quitButton, &QPushButton::clicked,
- qApp, &QApplication::quit);
+ qApp, &QCoreApplication::quit);
QHBoxLayout *bottomLayout = new QHBoxLayout;
bottomLayout->addStretch();
@@ -83,26 +88,25 @@ ControllerWindow::ControllerWindow(QWidget *parent)
//! [1]
void ControllerWindow::updatePreview()
{
- Qt::WindowFlags flags = 0;
+ Qt::WindowFlags flags;
- if (windowRadioButton->isChecked()) {
+ if (windowRadioButton->isChecked())
flags = Qt::Window;
- } else if (dialogRadioButton->isChecked()) {
+ else if (dialogRadioButton->isChecked())
flags = Qt::Dialog;
- } else if (sheetRadioButton->isChecked()) {
+ else if (sheetRadioButton->isChecked())
flags = Qt::Sheet;
- } else if (drawerRadioButton->isChecked()) {
+ else if (drawerRadioButton->isChecked())
flags = Qt::Drawer;
- } else if (popupRadioButton->isChecked()) {
+ else if (popupRadioButton->isChecked())
flags = Qt::Popup;
- } else if (toolRadioButton->isChecked()) {
+ else if (toolRadioButton->isChecked())
flags = Qt::Tool;
- } else if (toolTipRadioButton->isChecked()) {
+ else if (toolTipRadioButton->isChecked())
flags = Qt::ToolTip;
- } else if (splashScreenRadioButton->isChecked()) {
+ else if (splashScreenRadioButton->isChecked())
flags = Qt::SplashScreen;
//! [1] //! [2]
- }
//! [2] //! [3]
if (msWindowsFixedSizeDialogCheckBox->isChecked())
diff --git a/examples/widgets/widgets/windowflags/previewwindow.cpp b/examples/widgets/widgets/windowflags/previewwindow.cpp
index 8773dccb05..d7ebed7b3c 100644
--- a/examples/widgets/widgets/windowflags/previewwindow.cpp
+++ b/examples/widgets/widgets/windowflags/previewwindow.cpp
@@ -50,7 +50,9 @@
#include "previewwindow.h"
-#include <QtWidgets>
+#include <QPushButton>
+#include <QTextEdit>
+#include <QVBoxLayout>
//! [0]
PreviewWindow::PreviewWindow(QWidget *parent)
@@ -81,23 +83,22 @@ void PreviewWindow::setWindowFlags(Qt::WindowFlags flags)
QString text;
Qt::WindowFlags type = (flags & Qt::WindowType_Mask);
- if (type == Qt::Window) {
+ if (type == Qt::Window)
text = "Qt::Window";
- } else if (type == Qt::Dialog) {
+ else if (type == Qt::Dialog)
text = "Qt::Dialog";
- } else if (type == Qt::Sheet) {
+ else if (type == Qt::Sheet)
text = "Qt::Sheet";
- } else if (type == Qt::Drawer) {
+ else if (type == Qt::Drawer)
text = "Qt::Drawer";
- } else if (type == Qt::Popup) {
+ else if (type == Qt::Popup)
text = "Qt::Popup";
- } else if (type == Qt::Tool) {
+ else if (type == Qt::Tool)
text = "Qt::Tool";
- } else if (type == Qt::ToolTip) {
+ else if (type == Qt::ToolTip)
text = "Qt::ToolTip";
- } else if (type == Qt::SplashScreen) {
+ else if (type == Qt::SplashScreen)
text = "Qt::SplashScreen";
- }
if (flags & Qt::MSWindowsFixedSizeDialogHint)
text += "\n| Qt::MSWindowsFixedSizeDialogHint";
diff --git a/examples/widgets/windowcontainer/windowcontainer.cpp b/examples/widgets/windowcontainer/windowcontainer.cpp
index 9f2124c4e1..b920c85420 100644
--- a/examples/widgets/windowcontainer/windowcontainer.cpp
+++ b/examples/widgets/windowcontainer/windowcontainer.cpp
@@ -50,16 +50,14 @@
#include "openglwindow.h"
-#include <QPainter>
-#include <QMouseEvent>
-#include <QKeyEvent>
-#include <QFocusEvent>
-
#include <QApplication>
-#include <QWidget>
+#include <QFocusEvent>
#include <QHBoxLayout>
+#include <QKeyEvent>
#include <QLineEdit>
-
+#include <QMouseEvent>
+#include <QPainter>
+#include <QWidget>
// Making use of the class from the opengl example in gui.
@@ -67,13 +65,10 @@ class Window : public OpenGLWindow
{
Q_OBJECT
public:
- Window()
- : m_mouseDown(false)
- , m_focus(false)
- {
- }
+ using OpenGLWindow::OpenGLWindow;
- void render(QPainter *p) override {
+ void render(QPainter *p) override
+ {
QLinearGradient g(0, 0, 0, height());
g.setColorAt(0, QColor("lightsteelblue"));
g.setColorAt(1, Qt::black);
@@ -93,15 +88,15 @@ public:
p->restore();
}
- if (m_focus) {
+ if (m_focus)
p->drawText(20, height() - 20, QLatin1String("Window has focus!"));
- }
p->setRenderHint(QPainter::Antialiasing);
p->drawPolyline(m_polygon);
}
- void mousePressEvent(QMouseEvent *e) override {
+ void mousePressEvent(QMouseEvent *e) override
+ {
if (!m_mouseDown) {
m_mouseDown = true;
m_polygon.clear();
@@ -110,14 +105,16 @@ public:
}
}
- void mouseMoveEvent(QMouseEvent *e) override {
+ void mouseMoveEvent(QMouseEvent *e) override
+ {
if (m_mouseDown) {
m_polygon.append(e->pos());
renderLater();
}
}
- void mouseReleaseEvent(QMouseEvent *e) override {
+ void mouseReleaseEvent(QMouseEvent *e) override
+ {
if (m_mouseDown) {
m_mouseDown = false;
m_polygon.append(e->pos());
@@ -125,33 +122,35 @@ public:
}
}
- void focusInEvent(QFocusEvent *) override {
+ void focusInEvent(QFocusEvent *) override
+ {
m_focus = true;
renderLater();
}
- void focusOutEvent(QFocusEvent *) override {
+ void focusOutEvent(QFocusEvent *) override
+ {
m_focus = false;
m_polygon.clear();
renderLater();
}
- void keyPressEvent(QKeyEvent *e) override {
+ void keyPressEvent(QKeyEvent *e) override
+ {
m_key = e->text();
renderLater();
}
- void keyReleaseEvent(QKeyEvent *) override {
+ void keyReleaseEvent(QKeyEvent *) override
+ {
m_key = QString();
renderLater();
}
private:
QPolygon m_polygon;
- bool m_mouseDown;
-
- bool m_focus;
-
QString m_key;
+ bool m_mouseDown = false;
+ bool m_focus = false;
};
@@ -162,7 +161,7 @@ int main(int argc, char *argv[])
QWidget *widget = new QWidget;
QHBoxLayout *layout = new QHBoxLayout(widget);
- Window *window = new Window();
+ Window *window = new Window;
QWidget *container = QWidget::createWindowContainer(window);
container->setMinimumSize(300, 300);