summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/animation/easing/window.cpp7
-rw-r--r--examples/widgets/animation/stickman/animation.cpp18
-rw-r--r--examples/widgets/animation/stickman/animation.h4
-rw-r--r--examples/widgets/animation/stickman/graphicsview.cpp12
-rw-r--r--examples/widgets/animation/stickman/graphicsview.h12
-rw-r--r--examples/widgets/animation/stickman/lifecycle.cpp19
-rw-r--r--examples/widgets/animation/stickman/lifecycle.h11
-rw-r--r--examples/widgets/animation/stickman/node.h4
-rw-r--r--examples/widgets/animation/stickman/rectbutton.cpp7
-rw-r--r--examples/widgets/animation/stickman/rectbutton.h8
-rw-r--r--examples/widgets/animation/stickman/stickman.cpp29
-rw-r--r--examples/widgets/animation/stickman/stickman.h13
-rw-r--r--examples/widgets/animation/sub-attaq/animationmanager.cpp17
-rw-r--r--examples/widgets/animation/sub-attaq/animationmanager.h10
-rw-r--r--examples/widgets/animation/sub-attaq/boat.cpp19
-rw-r--r--examples/widgets/animation/sub-attaq/boat.h7
-rw-r--r--examples/widgets/animation/sub-attaq/boat_p.h20
-rw-r--r--examples/widgets/animation/sub-attaq/bomb.cpp19
-rw-r--r--examples/widgets/animation/sub-attaq/bomb.h6
-rw-r--r--examples/widgets/animation/sub-attaq/graphicsscene.cpp73
-rw-r--r--examples/widgets/animation/sub-attaq/graphicsscene.h21
-rw-r--r--examples/widgets/animation/sub-attaq/mainwindow.cpp7
-rw-r--r--examples/widgets/animation/sub-attaq/mainwindow.h8
-rw-r--r--examples/widgets/animation/sub-attaq/pixmapitem.cpp5
-rw-r--r--examples/widgets/animation/sub-attaq/pixmapitem.h8
-rw-r--r--examples/widgets/animation/sub-attaq/progressitem.cpp7
-rw-r--r--examples/widgets/animation/sub-attaq/progressitem.h8
-rw-r--r--examples/widgets/animation/sub-attaq/qanimationstate.cpp4
-rw-r--r--examples/widgets/animation/sub-attaq/qanimationstate.h10
-rw-r--r--examples/widgets/animation/sub-attaq/states.cpp28
-rw-r--r--examples/widgets/animation/sub-attaq/states.h24
-rw-r--r--examples/widgets/animation/sub-attaq/submarine.cpp26
-rw-r--r--examples/widgets/animation/sub-attaq/submarine.h11
-rw-r--r--examples/widgets/animation/sub-attaq/submarine_p.h9
-rw-r--r--examples/widgets/animation/sub-attaq/textinformationitem.cpp9
-rw-r--r--examples/widgets/animation/sub-attaq/textinformationitem.h6
-rw-r--r--examples/widgets/animation/sub-attaq/torpedo.cpp23
-rw-r--r--examples/widgets/animation/sub-attaq/torpedo.h6
-rw-r--r--examples/widgets/desktop/screenshot/main.cpp5
-rw-r--r--examples/widgets/desktop/screenshot/screenshot.cpp2
-rw-r--r--examples/widgets/dialogs/classwizard/classwizard.cpp4
-rw-r--r--examples/widgets/dialogs/classwizard/classwizard.h12
-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/standarddialogs/dialog.cpp3
-rw-r--r--examples/widgets/dialogs/standarddialogs/dialog.h2
-rw-r--r--examples/widgets/dialogs/standarddialogs/main.cpp4
-rw-r--r--examples/widgets/dialogs/tabdialog/tabdialog.h8
-rw-r--r--examples/widgets/doc/src/application.qdoc9
-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/icons.qdoc7
-rw-r--r--examples/widgets/doc/src/stardelegate.qdoc2
-rw-r--r--examples/widgets/doc/src/tooltips.qdoc2
-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.cpp84
-rw-r--r--examples/widgets/graphicsview/boxes/scene.h25
-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.cpp4
-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.cpp24
-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/diagramscene/mainwindow.cpp4
-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.cpp2
-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/dirview/main.cpp12
-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/mainwindows/application/mainwindow.cpp34
-rw-r--r--examples/widgets/mainwindows/mdi/mainwindow.cpp2
-rw-r--r--examples/widgets/mainwindows/mdi/mdichild.cpp27
-rw-r--r--examples/widgets/mainwindows/sdi/mainwindow.cpp31
-rw-r--r--examples/widgets/painting/affine/xform.cpp7
-rw-r--r--examples/widgets/painting/composition/composition.cpp12
-rw-r--r--examples/widgets/painting/composition/composition.h10
-rw-r--r--examples/widgets/painting/composition/main.cpp6
-rw-r--r--examples/widgets/painting/deform/pathdeform.cpp2
-rw-r--r--examples/widgets/painting/deform/pathdeform.h4
-rw-r--r--examples/widgets/painting/fontsampler/mainwindow.h2
-rw-r--r--examples/widgets/painting/gradients/gradients.cpp34
-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.cpp90
-rw-r--r--examples/widgets/painting/pathstroke/pathstroke.h2
-rw-r--r--examples/widgets/painting/shared/arthurstyle.cpp4
-rw-r--r--examples/widgets/painting/shared/arthurstyle.h2
-rw-r--r--examples/widgets/painting/shared/arthurwidgets.cpp6
-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.cpp7
-rw-r--r--examples/widgets/painting/transformations/renderarea.h2
-rw-r--r--examples/widgets/qnx/foreignwindows/collector.cpp176
-rw-r--r--examples/widgets/qnx/foreignwindows/collector.h75
-rw-r--r--examples/widgets/qnx/foreignwindows/foreignwindows.pro11
-rw-r--r--examples/widgets/qnx/foreignwindows/main.cpp53
-rw-r--r--examples/widgets/richtext/textedit/example.md102
-rw-r--r--examples/widgets/richtext/textedit/images/mac/checkbox-checked.pngbin0 -> 1167 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/checkbox.pngbin0 -> 779 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/format-indent-less.pngbin0 -> 1201 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/format-indent-more.pngbin0 -> 993 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/checkbox-checked.pngbin0 -> 1167 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/checkbox.pngbin0 -> 779 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/format-indent-less.pngbin0 -> 1201 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/format-indent-more.pngbin0 -> 993 bytes
-rw-r--r--examples/widgets/richtext/textedit/main.cpp4
-rw-r--r--examples/widgets/richtext/textedit/textedit.cpp151
-rw-r--r--examples/widgets/richtext/textedit/textedit.h7
-rw-r--r--examples/widgets/richtext/textedit/textedit.qrc8
-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.cpp12
-rw-r--r--examples/widgets/statemachine/trafficlight/main.cpp16
-rw-r--r--examples/widgets/tools/codecs/encodingdialog.cpp2
-rw-r--r--examples/widgets/tools/codecs/mainwindow.cpp24
-rw-r--r--examples/widgets/tools/codecs/mainwindow.h6
-rw-r--r--examples/widgets/tools/codecs/previewform.cpp24
-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.cpp56
-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/interfaces.h6
-rw-r--r--examples/widgets/tools/plugandpaint/app/mainwindow.cpp21
-rw-r--r--examples/widgets/tools/plugandpaint/app/paintarea.cpp7
-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.cpp20
-rw-r--r--examples/widgets/tools/settingseditor/mainwindow.h12
-rw-r--r--examples/widgets/tools/settingseditor/settingstree.cpp38
-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.cpp29
-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.cpp43
-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/main.cpp4
-rw-r--r--examples/widgets/widgets/icons/mainwindow.cpp27
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.cpp25
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.h2
-rw-r--r--examples/widgets/widgets/lineedits/window.cpp13
-rw-r--r--examples/widgets/widgets/mousebuttons/buttontester.cpp11
-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.cpp12
-rw-r--r--examples/widgets/widgets/styles/norwegianwoodstyle.cpp5
-rw-r--r--examples/widgets/widgets/styles/widgetgallery.cpp21
-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.cpp30
-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
305 files changed, 2229 insertions, 1673 deletions
diff --git a/examples/widgets/animation/easing/window.cpp b/examples/widgets/animation/easing/window.cpp
index aa12147388..d1d6348361 100644
--- a/examples/widgets/animation/easing/window.cpp
+++ b/examples/widgets/animation/easing/window.cpp
@@ -55,11 +55,10 @@ Window::Window(QWidget *parent)
m_iconSize(64, 64)
{
m_ui.setupUi(this);
- QButtonGroup *buttonGroup = findChild<QButtonGroup *>(); // ### workaround for uic in 4.4
m_ui.easingCurvePicker->setIconSize(m_iconSize);
m_ui.easingCurvePicker->setMinimumHeight(m_iconSize.height() + 50);
- buttonGroup->setId(m_ui.lineRadio, 0);
- buttonGroup->setId(m_ui.circleRadio, 1);
+ m_ui.buttonGroup->setId(m_ui.lineRadio, 0);
+ m_ui.buttonGroup->setId(m_ui.circleRadio, 1);
QEasingCurve dummy;
m_ui.periodSpinBox->setValue(dummy.period());
@@ -68,7 +67,7 @@ Window::Window(QWidget *parent)
connect(m_ui.easingCurvePicker, &QListWidget::currentRowChanged,
this, &Window::curveChanged);
- connect(buttonGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
+ connect(m_ui.buttonGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
this, &Window::pathChanged);
connect(m_ui.periodSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this, &Window::periodChanged);
diff --git a/examples/widgets/animation/stickman/animation.cpp b/examples/widgets/animation/stickman/animation.cpp
index 5c2d1682af..73d79adc84 100644
--- a/examples/widgets/animation/stickman/animation.cpp
+++ b/examples/widgets/animation/stickman/animation.cpp
@@ -50,16 +50,13 @@
#include "animation.h"
-#include <QPointF>
-#include <QVector>
#include <QIODevice>
#include <QDataStream>
class Frame
{
public:
- Frame() {
- }
+ Frame() = default;
int nodeCount() const
{
@@ -85,9 +82,8 @@ private:
QVector<QPointF> m_nodePositions;
};
-Animation::Animation()
+Animation::Animation() : m_currentFrame(0)
{
- m_currentFrame = 0;
m_frames.append(new Frame);
}
@@ -103,6 +99,8 @@ void Animation::setTotalFrames(int totalFrames)
while (totalFrames < m_frames.size())
delete m_frames.takeLast();
+
+ setCurrentFrame(m_currentFrame);
}
int Animation::totalFrames() const
@@ -112,7 +110,7 @@ int Animation::totalFrames() const
void Animation::setCurrentFrame(int currentFrame)
{
- m_currentFrame = qMax(qMin(currentFrame, totalFrames()-1), 0);
+ m_currentFrame = qBound(0, currentFrame, totalFrames() - 1);
}
int Animation::currentFrame() const
@@ -177,18 +175,16 @@ void Animation::load(QIODevice *device)
int frameCount;
stream >> frameCount;
- for (int i=0; i<frameCount; ++i) {
-
+ for (int i = 0; i < frameCount; ++i) {
int nodeCount;
stream >> nodeCount;
Frame *frame = new Frame;
frame->setNodeCount(nodeCount);
- for (int j=0; j<nodeCount; ++j) {
+ for (int j = 0; j < nodeCount; ++j) {
QPointF pos;
stream >> pos;
-
frame->setNodePos(j, pos);
}
diff --git a/examples/widgets/animation/stickman/animation.h b/examples/widgets/animation/stickman/animation.h
index e57847aeaa..5cc1133ac0 100644
--- a/examples/widgets/animation/stickman/animation.h
+++ b/examples/widgets/animation/stickman/animation.h
@@ -52,8 +52,8 @@
#define ANIMATION_H
#include <QPointF>
-#include <QList>
#include <QString>
+#include <QVector>
class Frame;
QT_BEGIN_NAMESPACE
@@ -85,7 +85,7 @@ public:
private:
QString m_name;
- QList<Frame *> m_frames;
+ QVector<Frame *> m_frames;
int m_currentFrame;
};
diff --git a/examples/widgets/animation/stickman/graphicsview.cpp b/examples/widgets/animation/stickman/graphicsview.cpp
index 7058e15345..0f5800cff3 100644
--- a/examples/widgets/animation/stickman/graphicsview.cpp
+++ b/examples/widgets/animation/stickman/graphicsview.cpp
@@ -51,13 +51,8 @@
#include "graphicsview.h"
#include "stickman.h"
-#include <QtGui/QKeyEvent>
-#include <QtWidgets/QGraphicsScene>
-#include <QtWidgets/QGraphicsView>
-
-GraphicsView::GraphicsView(QWidget *parent)
- : QGraphicsView(parent), m_editor(nullptr)
-{}
+#include <QKeyEvent>
+#include <QGraphicsScene>
void GraphicsView::keyPressEvent(QKeyEvent *e)
{
@@ -66,7 +61,8 @@ void GraphicsView::keyPressEvent(QKeyEvent *e)
emit keyPressed(Qt::Key(e->key()));
}
-void GraphicsView::resizeEvent(QResizeEvent *)
+void GraphicsView::resizeEvent(QResizeEvent *e)
{
fitInView(scene()->sceneRect());
+ QGraphicsView::resizeEvent(e);
}
diff --git a/examples/widgets/animation/stickman/graphicsview.h b/examples/widgets/animation/stickman/graphicsview.h
index 361fee219d..29f4c6237e 100644
--- a/examples/widgets/animation/stickman/graphicsview.h
+++ b/examples/widgets/animation/stickman/graphicsview.h
@@ -51,24 +51,20 @@
#ifndef GRAPHICSVIEW_H
#define GRAPHICSVIEW_H
-#include <QtWidgets/QGraphicsView>
+#include <QGraphicsView>
-class MainWindow;
class GraphicsView: public QGraphicsView
{
Q_OBJECT
public:
- GraphicsView(QWidget *parent = nullptr);
+ using QGraphicsView::QGraphicsView;
protected:
- void resizeEvent(QResizeEvent *event) override;
- void keyPressEvent(QKeyEvent *) override;
+ void resizeEvent(QResizeEvent *e) override;
+ void keyPressEvent(QKeyEvent *e) override;
signals:
void keyPressed(int key);
-
-private:
- MainWindow *m_editor;
};
#endif
diff --git a/examples/widgets/animation/stickman/lifecycle.cpp b/examples/widgets/animation/stickman/lifecycle.cpp
index 046e3f4cd1..5ad284c590 100644
--- a/examples/widgets/animation/stickman/lifecycle.cpp
+++ b/examples/widgets/animation/stickman/lifecycle.cpp
@@ -54,8 +54,15 @@
#include "animation.h"
#include "graphicsview.h"
-#include <QtCore>
-#include <QtWidgets>
+#include <QEventTransition>
+#include <QFile>
+#include <QParallelAnimationGroup>
+#include <QPropertyAnimation>
+#include <QRandomGenerator>
+#include <QSignalTransition>
+#include <QState>
+#include <QStateMachine>
+#include <QTimer>
class KeyPressTransition: public QSignalTransition
{
@@ -107,7 +114,7 @@ LifeCycle::LifeCycle(StickMan *stickMan, GraphicsView *keyReceiver)
// Create animation group to be used for all transitions
m_animationGroup = new QParallelAnimationGroup();
const int stickManNodeCount = m_stickMan->nodeCount();
- for (int i=0; i<stickManNodeCount; ++i) {
+ for (int i = 0; i < stickManNodeCount; ++i) {
QPropertyAnimation *pa = new QPropertyAnimation(m_stickMan->node(i), "pos");
m_animationGroup->addAnimation(pa);
}
@@ -175,7 +182,7 @@ void LifeCycle::addActivity(const QString &fileName, Qt::Key key, QObject *sende
QState *state = makeState(m_alive, fileName);
m_alive->addTransition(new KeyPressTransition(m_keyReceiver, key, state));
- if (sender || signal)
+ if (sender && signal)
m_alive->addTransition(sender, signal, state);
}
@@ -192,13 +199,13 @@ QState *LifeCycle::makeState(QState *parentState, const QString &animationFileNa
const int frameCount = animation.totalFrames();
QState *previousState = nullptr;
- for (int i=0; i<frameCount; ++i) {
+ for (int i = 0; i < frameCount; ++i) {
animation.setCurrentFrame(i);
//! [1]
QState *frameState = new QState(topLevel);
const int nodeCount = animation.nodeCount();
- for (int j=0; j<nodeCount; ++j)
+ for (int j = 0; j < nodeCount; ++j)
frameState->assignProperty(m_stickMan->node(j), "pos", animation.nodePos(j));
//! [1]
diff --git a/examples/widgets/animation/stickman/lifecycle.h b/examples/widgets/animation/stickman/lifecycle.h
index e3f9876676..21ab99276d 100644
--- a/examples/widgets/animation/stickman/lifecycle.h
+++ b/examples/widgets/animation/stickman/lifecycle.h
@@ -53,16 +53,16 @@
#include <Qt>
-class StickMan;
QT_BEGIN_NAMESPACE
-class QStateMachine;
-class QAnimationGroup;
-class QState;
class QAbstractState;
class QAbstractTransition;
+class QAnimationGroup;
class QObject;
+class QState;
+class QStateMachine;
QT_END_NAMESPACE
class GraphicsView;
+class StickMan;
class LifeCycle
{
public:
@@ -70,7 +70,8 @@ public:
~LifeCycle();
void setDeathAnimation(const QString &fileName);
- void addActivity(const QString &fileName, Qt::Key key, QObject *sender = NULL, const char *signal = NULL);
+ void addActivity(const QString &fileName, Qt::Key key,
+ QObject *sender = nullptr, const char *signal = nullptr);
void start();
diff --git a/examples/widgets/animation/stickman/node.h b/examples/widgets/animation/stickman/node.h
index 679999b7e8..2b393c60c1 100644
--- a/examples/widgets/animation/stickman/node.h
+++ b/examples/widgets/animation/stickman/node.h
@@ -51,13 +51,13 @@
#ifndef NODE_H
#define NODE_H
-#include <QGraphicsItem>
+#include <QGraphicsObject>
class Node: public QGraphicsObject
{
Q_OBJECT
public:
- explicit Node(const QPointF &pos, QGraphicsItem *parent = 0);
+ explicit Node(const QPointF &pos, QGraphicsItem *parent = nullptr);
~Node();
QRectF boundingRect() const override;
diff --git a/examples/widgets/animation/stickman/rectbutton.cpp b/examples/widgets/animation/stickman/rectbutton.cpp
index 7eea94ae6f..5174d0aeaf 100644
--- a/examples/widgets/animation/stickman/rectbutton.cpp
+++ b/examples/widgets/animation/stickman/rectbutton.cpp
@@ -51,12 +51,7 @@
#include "rectbutton.h"
#include <QPainter>
-RectButton::RectButton(QString buttonText) : m_ButtonText(buttonText)
-{
-}
-
-
-RectButton::~RectButton()
+RectButton::RectButton(const QString &buttonText) : m_ButtonText(buttonText)
{
}
diff --git a/examples/widgets/animation/stickman/rectbutton.h b/examples/widgets/animation/stickman/rectbutton.h
index ab47bad0f7..ee6cd3f530 100644
--- a/examples/widgets/animation/stickman/rectbutton.h
+++ b/examples/widgets/animation/stickman/rectbutton.h
@@ -57,19 +57,19 @@ class RectButton : public QGraphicsObject
{
Q_OBJECT
public:
- RectButton(QString buttonText);
- ~RectButton();
+ RectButton(const QString &buttonText);
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
protected:
- QString m_ButtonText;
-
void mousePressEvent (QGraphicsSceneMouseEvent *event) override;
signals:
void clicked();
+
+private:
+ QString m_ButtonText;
};
#endif // RECTBUTTON_H
diff --git a/examples/widgets/animation/stickman/stickman.cpp b/examples/widgets/animation/stickman/stickman.cpp
index 5725f64eec..3f373b6b52 100644
--- a/examples/widgets/animation/stickman/stickman.cpp
+++ b/examples/widgets/animation/stickman/stickman.cpp
@@ -52,10 +52,9 @@
#include "node.h"
#include <QPainter>
-#include <QTimer>
-#include <qmath.h>
+#include <QtMath>
-static const qreal Coords[NodeCount * 2] = {
+static constexpr qreal Coords[NodeCount * 2] = {
0.0, -150.0, // head, #0
0.0, -100.0, // body pentagon, top->bottom, left->right, #1 - 5
@@ -81,7 +80,7 @@ static const qreal Coords[NodeCount * 2] = {
};
-static const int Bones[BoneCount * 2] = {
+static constexpr int Bones[BoneCount * 2] = {
0, 1, // neck
1, 2, // body
@@ -117,19 +116,13 @@ static const int Bones[BoneCount * 2] = {
StickMan::StickMan()
{
- m_sticks = true;
- m_isDead = false;
- m_pixmap = QPixmap("images/head.png");
- m_penColor = Qt::white;
- m_fillColor = Qt::black;
-
// Set up start position of limbs
- for (int i=0; i<NodeCount; ++i) {
+ for (int i = 0; i < NodeCount; ++i) {
m_nodes[i] = new Node(QPointF(Coords[i * 2], Coords[i * 2 + 1]), this);
connect(m_nodes[i], &Node::positionChanged, this, &StickMan::childPositionChanged);
}
- for (int i=0; i<BoneCount; ++i) {
+ for (int i = 0; i < BoneCount; ++i) {
int n1 = Bones[i * 2];
int n2 = Bones[i * 2 + 1];
@@ -137,16 +130,12 @@ StickMan::StickMan()
Node *node2 = m_nodes[n2];
QPointF dist = node1->pos() - node2->pos();
- m_perfectBoneLengths[i] = sqrt(pow(dist.x(),2) + pow(dist.y(),2));
+ m_perfectBoneLengths[i] = sqrt(pow(dist.x(), 2) + pow(dist.y(), 2));
}
startTimer(10);
}
-StickMan::~StickMan()
-{
-}
-
void StickMan::childPositionChanged()
{
prepareGeometryChange();
@@ -155,7 +144,7 @@ void StickMan::childPositionChanged()
void StickMan::setDrawSticks(bool on)
{
m_sticks = on;
- for (int i=0;i<nodeCount();++i) {
+ for (int i = 0; i < nodeCount(); ++i) {
Node *node = m_nodes[i];
node->setVisible(on);
}
@@ -188,7 +177,7 @@ void StickMan::stabilize()
{
static const qreal threshold = 0.001;
- for (int i=0; i<BoneCount; ++i) {
+ for (int i = 0; i < BoneCount; ++i) {
int n1 = Bones[i * 2];
int n2 = Bones[i * 2 + 1];
@@ -236,7 +225,7 @@ void StickMan::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge
stabilize();
if (m_sticks) {
painter->setPen(Qt::white);
- for (int i=0; i<BoneCount; ++i) {
+ for (int i = 0; i < BoneCount; ++i) {
int n1 = Bones[i * 2];
int n2 = Bones[i * 2 + 1];
diff --git a/examples/widgets/animation/stickman/stickman.h b/examples/widgets/animation/stickman/stickman.h
index f2311a0358..63c02abc8f 100644
--- a/examples/widgets/animation/stickman/stickman.h
+++ b/examples/widgets/animation/stickman/stickman.h
@@ -57,8 +57,6 @@ static const int NodeCount = 16;
static const int BoneCount = 24;
class Node;
-QT_BEGIN_NAMESPACE
-QT_END_NAMESPACE
class StickMan: public QGraphicsObject
{
Q_OBJECT
@@ -67,7 +65,6 @@ class StickMan: public QGraphicsObject
Q_PROPERTY(bool isDead WRITE setIsDead READ isDead)
public:
StickMan();
- ~StickMan();
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
@@ -101,13 +98,11 @@ private:
Node *m_nodes[NodeCount];
qreal m_perfectBoneLengths[BoneCount];
- uint m_sticks : 1;
- uint m_isDead : 1;
- uint m_reserved : 30;
+ bool m_sticks = true;
+ bool m_isDead = false;
- QPixmap m_pixmap;
- QColor m_penColor;
- QColor m_fillColor;
+ QColor m_penColor = Qt::white;
+ QColor m_fillColor = Qt::black;
};
#endif // STICKMAN_H
diff --git a/examples/widgets/animation/sub-attaq/animationmanager.cpp b/examples/widgets/animation/sub-attaq/animationmanager.cpp
index a611641613..261cbd1e1c 100644
--- a/examples/widgets/animation/sub-attaq/animationmanager.cpp
+++ b/examples/widgets/animation/sub-attaq/animationmanager.cpp
@@ -51,22 +51,13 @@
//Own
#include "animationmanager.h"
-//Qt
-#include <QtCore/QAbstractAnimation>
-#include <QtCore/QDebug>
-
-// the universe's only animation manager
-AnimationManager *AnimationManager::instance = nullptr;
-
-AnimationManager::AnimationManager()
-{
-}
+#include <QAbstractAnimation>
AnimationManager *AnimationManager::self()
{
- if (!instance)
- instance = new AnimationManager;
- return instance;
+ // the universe's only animation manager
+ static AnimationManager s_instance;
+ return &s_instance;
}
void AnimationManager::registerAnimation(QAbstractAnimation *anim)
diff --git a/examples/widgets/animation/sub-attaq/animationmanager.h b/examples/widgets/animation/sub-attaq/animationmanager.h
index 9365fa1f1e..5ddea66e80 100644
--- a/examples/widgets/animation/sub-attaq/animationmanager.h
+++ b/examples/widgets/animation/sub-attaq/animationmanager.h
@@ -51,7 +51,7 @@
#ifndef ANIMATIONMANAGER_H
#define ANIMATIONMANAGER_H
-#include <QtCore/QObject>
+#include <QObject>
QT_BEGIN_NAMESPACE
class QAbstractAnimation;
@@ -59,9 +59,10 @@ QT_END_NAMESPACE
class AnimationManager : public QObject
{
-Q_OBJECT
+ Q_OBJECT
+ AnimationManager() = default;
+ ~AnimationManager() = default;
public:
- AnimationManager();
void registerAnimation(QAbstractAnimation *anim);
void unregisterAnimation(QAbstractAnimation *anim);
void unregisterAllAnimations();
@@ -75,8 +76,7 @@ private slots:
void unregisterAnimation_helper(QObject *obj);
private:
- static AnimationManager *instance;
- QList<QAbstractAnimation *> animations;
+ QVector<QAbstractAnimation *> animations;
};
#endif // ANIMATIONMANAGER_H
diff --git a/examples/widgets/animation/sub-attaq/boat.cpp b/examples/widgets/animation/sub-attaq/boat.cpp
index 9037d54878..d5fa314b60 100644
--- a/examples/widgets/animation/sub-attaq/boat.cpp
+++ b/examples/widgets/animation/sub-attaq/boat.cpp
@@ -52,18 +52,17 @@
#include "boat.h"
#include "boat_p.h"
#include "bomb.h"
-#include "pixmapitem.h"
#include "graphicsscene.h"
#include "animationmanager.h"
#include "qanimationstate.h"
//Qt
-#include <QtCore/QPropertyAnimation>
-#include <QtCore/QStateMachine>
-#include <QtCore/QHistoryState>
-#include <QtCore/QFinalState>
-#include <QtCore/QState>
-#include <QtCore/QSequentialAnimationGroup>
+#include <QFinalState>
+#include <QHistoryState>
+#include <QPropertyAnimation>
+#include <QSequentialAnimationGroup>
+#include <QState>
+#include <QStateMachine>
static QAbstractAnimation *setupDestroyAnimation(Boat *boat)
{
@@ -181,7 +180,7 @@ Boat::Boat()
launchStateLeft->addTransition(historyState);
launchStateRight->addTransition(historyState);
- QFinalState *final = new QFinalState(machine);
+ QFinalState *finalState = new QFinalState(machine);
//This state play the destroyed animation
QAnimationState *destroyedState = new QAnimationState(machine);
@@ -191,10 +190,10 @@ Boat::Boat()
moving->addTransition(this, &Boat::boatDestroyed, destroyedState);
//Transition to final state when the destroyed animation is finished
- destroyedState->addTransition(destroyedState, &QAnimationState::animationFinished, final);
+ destroyedState->addTransition(destroyedState, &QAnimationState::animationFinished, finalState);
//The machine has finished to be executed, then the boat is dead
- connect(machine,&QState::finished, this, &Boat::boatExecutionFinished);
+ connect(machine, &QState::finished, this, &Boat::boatExecutionFinished);
}
diff --git a/examples/widgets/animation/sub-attaq/boat.h b/examples/widgets/animation/sub-attaq/boat.h
index a75e2b1474..22f2f0f7c1 100644
--- a/examples/widgets/animation/sub-attaq/boat.h
+++ b/examples/widgets/animation/sub-attaq/boat.h
@@ -48,12 +48,11 @@
**
****************************************************************************/
-#ifndef __BOAT__H__
-#define __BOAT__H__
+#ifndef BOAT_H
+#define BOAT_H
#include "pixmapitem.h"
-class Bomb;
QT_BEGIN_NAMESPACE
class QVariantAnimation;
class QAbstractAnimation;
@@ -101,4 +100,4 @@ private:
QStateMachine *machine;
};
-#endif //__BOAT__H__
+#endif // BOAT_H
diff --git a/examples/widgets/animation/sub-attaq/boat_p.h b/examples/widgets/animation/sub-attaq/boat_p.h
index 8ebfeb27f5..bb1a783392 100644
--- a/examples/widgets/animation/sub-attaq/boat_p.h
+++ b/examples/widgets/animation/sub-attaq/boat_p.h
@@ -67,7 +67,9 @@
#include "graphicsscene.h"
// Qt
-#include <QtWidgets/QKeyEventTransition>
+#include <QGraphicsRotation>
+#include <QKeyEventTransition>
+#include <QState>
static const int MAX_BOMB = 5;
@@ -88,7 +90,7 @@ protected:
return (boat->currentSpeed() == 1);
}
private:
- Boat * boat;
+ Boat *boat;
};
//These transtion test if we have to move the boat (i.e current speed was 0 or another value)
@@ -118,7 +120,7 @@ protected:
boat->updateBoatMovement();
}
private:
- Boat * boat;
+ Boat *boat;
int key;
};
@@ -139,7 +141,7 @@ protected:
return (boat->bombsLaunched() < MAX_BOMB);
}
private:
- Boat * boat;
+ Boat *boat;
};
//This state is describing when the boat is moving right
@@ -157,7 +159,7 @@ protected:
boat->updateBoatMovement();
}
private:
- Boat * boat;
+ Boat *boat;
};
//This state is describing when the boat is moving left
@@ -175,7 +177,7 @@ protected:
boat->updateBoatMovement();
}
private:
- Boat * boat;
+ Boat *boat;
};
//This state is describing when the boat is in a stand by position
@@ -194,7 +196,7 @@ protected:
boat->updateBoatMovement();
}
private:
- Boat * boat;
+ Boat *boat;
};
//This state is describing the launch of the torpedo on the right
@@ -216,7 +218,7 @@ protected:
boat->setBombsLaunched(boat->bombsLaunched() + 1);
}
private:
- Boat * boat;
+ Boat *boat;
};
//This state is describing the launch of the torpedo on the left
@@ -238,7 +240,7 @@ protected:
boat->setBombsLaunched(boat->bombsLaunched() + 1);
}
private:
- Boat * boat;
+ Boat *boat;
};
#endif // BOAT_P_H
diff --git a/examples/widgets/animation/sub-attaq/bomb.cpp b/examples/widgets/animation/sub-attaq/bomb.cpp
index 2b865137dd..0b9c365662 100644
--- a/examples/widgets/animation/sub-attaq/bomb.cpp
+++ b/examples/widgets/animation/sub-attaq/bomb.cpp
@@ -51,15 +51,14 @@
//Own
#include "bomb.h"
#include "submarine.h"
-#include "pixmapitem.h"
#include "animationmanager.h"
#include "qanimationstate.h"
//Qt
-#include <QtCore/QSequentialAnimationGroup>
-#include <QtCore/QPropertyAnimation>
-#include <QtCore/QStateMachine>
-#include <QtCore/QFinalState>
+#include <QFinalState>
+#include <QPropertyAnimation>
+#include <QSequentialAnimationGroup>
+#include <QStateMachine>
Bomb::Bomb() : PixmapItem(QString("bomb"), GraphicsScene::Big)
{
@@ -83,7 +82,7 @@ void Bomb::launch(Bomb::Direction direction)
anim->setEndValue(QPointF(x() + delta*2,scene()->height()));
anim->setDuration(y()/2*60);
launchAnimation->addAnimation(anim);
- connect(anim,&QVariantAnimation::valueChanged,this,&Bomb::onAnimationLaunchValueChanged);
+ connect(anim, &QVariantAnimation::valueChanged, this, &Bomb::onAnimationLaunchValueChanged);
connect(this, &Bomb::bombExploded, launchAnimation, &QAbstractAnimation::stop);
//We setup the state machine of the bomb
QStateMachine *machine = new QStateMachine(this);
@@ -93,18 +92,18 @@ void Bomb::launch(Bomb::Direction direction)
launched->setAnimation(launchAnimation);
//End
- QFinalState *final = new QFinalState(machine);
+ QFinalState *finalState = new QFinalState(machine);
machine->setInitialState(launched);
//### Add a nice animation when the bomb is destroyed
- launched->addTransition(this, &Bomb::bombExploded,final);
+ launched->addTransition(this, &Bomb::bombExploded, finalState);
//If the animation is finished, then we move to the final state
- launched->addTransition(launched, &QAnimationState::animationFinished, final);
+ launched->addTransition(launched, &QAnimationState::animationFinished, finalState);
//The machine has finished to be executed, then the boat is dead
- connect(machine,&QState::finished,this, &Bomb::bombExecutionFinished);
+ connect(machine,&QState::finished, this, &Bomb::bombExecutionFinished);
machine->start();
diff --git a/examples/widgets/animation/sub-attaq/bomb.h b/examples/widgets/animation/sub-attaq/bomb.h
index 8e893f81e3..9ae54b4d81 100644
--- a/examples/widgets/animation/sub-attaq/bomb.h
+++ b/examples/widgets/animation/sub-attaq/bomb.h
@@ -48,8 +48,8 @@
**
****************************************************************************/
-#ifndef __BOMB__H__
-#define __BOMB__H__
+#ifndef BOMB_H
+#define BOMB_H
#include "pixmapitem.h"
@@ -73,4 +73,4 @@ private slots:
void onAnimationLaunchValueChanged(const QVariant &);
};
-#endif //__BOMB__H__
+#endif // BOMB_H
diff --git a/examples/widgets/animation/sub-attaq/graphicsscene.cpp b/examples/widgets/animation/sub-attaq/graphicsscene.cpp
index 8f0dfc1357..c7e2d269c8 100644
--- a/examples/widgets/animation/sub-attaq/graphicsscene.cpp
+++ b/examples/widgets/animation/sub-attaq/graphicsscene.cpp
@@ -55,38 +55,33 @@
#include "submarine.h"
#include "torpedo.h"
#include "bomb.h"
-#include "pixmapitem.h"
#include "animationmanager.h"
#include "qanimationstate.h"
#include "progressitem.h"
#include "textinformationitem.h"
//Qt
-#include <QtCore/QPropertyAnimation>
-#include <QtCore/QSequentialAnimationGroup>
-#include <QtCore/QParallelAnimationGroup>
-#include <QtCore/QStateMachine>
-#include <QtCore/QFinalState>
-#include <QtCore/QPauseAnimation>
-#include <QtWidgets/QAction>
-#include <QtCore/QDir>
-#include <QtWidgets/QApplication>
-#include <QtWidgets/QMessageBox>
-#include <QtWidgets/QGraphicsView>
-#include <QtWidgets/QGraphicsSceneMouseEvent>
-#include <QtCore/QXmlStreamReader>
-
-GraphicsScene::GraphicsScene(int x, int y, int width, int height, Mode mode)
- : QGraphicsScene(x , y, width, height), mode(mode), boat(new Boat)
+#include <QAction>
+#include <QApplication>
+#include <QFile>
+#include <QFinalState>
+#include <QParallelAnimationGroup>
+#include <QPropertyAnimation>
+#include <QSequentialAnimationGroup>
+#include <QStateMachine>
+#include <QXmlStreamReader>
+
+GraphicsScene::GraphicsScene(int x, int y, int width, int height, Mode mode, QObject *parent)
+ : QGraphicsScene(x, y, width, height, parent), mode(mode), boat(new Boat)
{
- PixmapItem *backgroundItem = new PixmapItem(QString("background"),mode);
+ PixmapItem *backgroundItem = new PixmapItem(QStringLiteral("background"), mode);
backgroundItem->setZValue(1);
backgroundItem->setPos(0,0);
addItem(backgroundItem);
- PixmapItem *surfaceItem = new PixmapItem(QString("surface"),mode);
+ PixmapItem *surfaceItem = new PixmapItem(QStringLiteral("surface"), mode);
surfaceItem->setZValue(3);
- surfaceItem->setPos(0,sealLevel() - surfaceItem->boundingRect().height()/2);
+ surfaceItem->setPos(0, sealLevel() - surfaceItem->boundingRect().height() / 2);
addItem(surfaceItem);
//The item that display score and level
@@ -137,8 +132,8 @@ qreal GraphicsScene::sealLevel() const
void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction)
{
- static const int nLetters = 10;
- static struct {
+ static constexpr int nLetters = 10;
+ static constexpr struct {
char const *pix;
qreal initX, initY;
qreal destX, destY;
@@ -154,8 +149,8 @@ void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction)
{"q", 200, 2000, 510, 250 },
{"excl", 0, 2000, 570, 220 } };
- QSequentialAnimationGroup * lettersGroupMoving = new QSequentialAnimationGroup(this);
- QParallelAnimationGroup * lettersGroupFading = new QParallelAnimationGroup(this);
+ QSequentialAnimationGroup *lettersGroupMoving = new QSequentialAnimationGroup(this);
+ QParallelAnimationGroup *lettersGroupFading = new QParallelAnimationGroup(this);
for (int i = 0; i < nLetters; ++i) {
PixmapItem *logo = new PixmapItem(QLatin1String(":/logo-") + logoData[i].pix, this);
@@ -180,7 +175,7 @@ void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction)
PlayState *gameState = new PlayState(this, machine);
//Final state
- QFinalState *final = new QFinalState(machine);
+ QFinalState *finalState = new QFinalState(machine);
//Animation when the player enter in the game
QAnimationState *lettersMovingState = new QAnimationState(machine);
@@ -198,8 +193,8 @@ void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction)
gameState->addTransition(newAction, &QAction::triggered, gameState);
//Wanna quit, then connect to CTRL+Q
- gameState->addTransition(quitAction, &QAction::triggered, final);
- lettersMovingState->addTransition(quitAction, &QAction::triggered, final);
+ gameState->addTransition(quitAction, &QAction::triggered, finalState);
+ lettersMovingState->addTransition(quitAction, &QAction::triggered, finalState);
//Welcome screen is the initial state
machine->setInitialState(lettersMovingState);
@@ -213,21 +208,24 @@ void GraphicsScene::setupScene(QAction *newAction, QAction *quitAction)
void GraphicsScene::addItem(Bomb *bomb)
{
bombs.insert(bomb);
- connect(bomb,&Bomb::bombExecutionFinished,this, &GraphicsScene::onBombExecutionFinished);
+ connect(bomb, &Bomb::bombExecutionFinished,
+ this, &GraphicsScene::onBombExecutionFinished);
QGraphicsScene::addItem(bomb);
}
void GraphicsScene::addItem(Torpedo *torpedo)
{
torpedos.insert(torpedo);
- connect(torpedo,&Torpedo::torpedoExecutionFinished,this, &GraphicsScene::onTorpedoExecutionFinished);
+ connect(torpedo, &Torpedo::torpedoExecutionFinished,
+ this, &GraphicsScene::onTorpedoExecutionFinished);
QGraphicsScene::addItem(torpedo);
}
void GraphicsScene::addItem(SubMarine *submarine)
{
submarines.insert(submarine);
- connect(submarine,&SubMarine::subMarineExecutionFinished,this, &GraphicsScene::onSubMarineExecutionFinished);
+ connect(submarine, &SubMarine::subMarineExecutionFinished,
+ this, &GraphicsScene::onSubMarineExecutionFinished);
QGraphicsScene::addItem(submarine);
}
@@ -239,15 +237,18 @@ void GraphicsScene::addItem(QGraphicsItem *item)
void GraphicsScene::onBombExecutionFinished()
{
Bomb *bomb = qobject_cast<Bomb *>(sender());
+ if (!bomb)
+ return;
bombs.remove(bomb);
bomb->deleteLater();
- if (boat)
- boat->setBombsLaunched(boat->bombsLaunched() - 1);
+ boat->setBombsLaunched(boat->bombsLaunched() - 1);
}
void GraphicsScene::onTorpedoExecutionFinished()
{
Torpedo *torpedo = qobject_cast<Torpedo *>(sender());
+ if (!torpedo)
+ return;
torpedos.remove(torpedo);
torpedo->deleteLater();
}
@@ -255,6 +256,8 @@ void GraphicsScene::onTorpedoExecutionFinished()
void GraphicsScene::onSubMarineExecutionFinished()
{
SubMarine *submarine = qobject_cast<SubMarine *>(sender());
+ if (!submarine)
+ return;
submarines.remove(submarine);
if (submarines.count() == 0)
emit allSubMarineDestroyed(submarine->points());
@@ -266,16 +269,22 @@ void GraphicsScene::onSubMarineExecutionFinished()
void GraphicsScene::clearScene()
{
for (SubMarine *sub : qAsConst(submarines)) {
+ // make sure to not go into onSubMarineExecutionFinished
+ sub->disconnect(this);
sub->destroy();
sub->deleteLater();
}
for (Torpedo *torpedo : qAsConst(torpedos)) {
+ // make sure to not go into onTorpedoExecutionFinished
+ torpedo->disconnect(this);
torpedo->destroy();
torpedo->deleteLater();
}
for (Bomb *bomb : qAsConst(bombs)) {
+ // make sure to not go into onBombExecutionFinished
+ bomb->disconnect(this);
bomb->destroy();
bomb->deleteLater();
}
diff --git a/examples/widgets/animation/sub-attaq/graphicsscene.h b/examples/widgets/animation/sub-attaq/graphicsscene.h
index 86c3414bbb..dd3719bc10 100644
--- a/examples/widgets/animation/sub-attaq/graphicsscene.h
+++ b/examples/widgets/animation/sub-attaq/graphicsscene.h
@@ -48,13 +48,12 @@
**
****************************************************************************/
-#ifndef __GRAPHICSSCENE__H__
-#define __GRAPHICSSCENE__H__
+#ifndef GRAPHICSSCENE_H
+#define GRAPHICSSCENE_H
//Qt
-#include <QtWidgets/QGraphicsScene>
-#include <QtCore/QSet>
-#include <QtCore/QState>
+#include <QGraphicsScene>
+#include <QSet>
class Boat;
@@ -78,18 +77,18 @@ public:
};
struct SubmarineDescription {
- int type;
- int points;
+ int type = 0;
+ int points = 0;
QString name;
};
struct LevelDescription {
- int id;
+ int id = 0;
QString name;
- QList<QPair<int,int> > submarines;
+ QVector<QPair<int, int>> submarines;
};
- GraphicsScene(int x, int y, int width, int height, Mode mode = Big);
+ GraphicsScene(int x, int y, int width, int height, Mode mode, QObject *parent = nullptr);
qreal sealLevel() const;
void setupScene(QAction *newAction, QAction *quitAction);
void addItem(Bomb *bomb);
@@ -127,5 +126,5 @@ private:
friend class UpdateScoreTransition;
};
-#endif //__GRAPHICSSCENE__H__
+#endif // GRAPHICSSCENE_H
diff --git a/examples/widgets/animation/sub-attaq/mainwindow.cpp b/examples/widgets/animation/sub-attaq/mainwindow.cpp
index a4bb15b383..8f545ecebd 100644
--- a/examples/widgets/animation/sub-attaq/mainwindow.cpp
+++ b/examples/widgets/animation/sub-attaq/mainwindow.cpp
@@ -56,11 +56,10 @@
#include <QGraphicsView>
#include <QApplication>
#include <QMenu>
-#include <QMenuBar>
#include <QLayout>
#ifndef QT_NO_OPENGL
-# include <QtOpenGL/QtOpenGL>
+# include <QtOpenGL>
#endif
MainWindow::MainWindow(QWidget *parent)
@@ -74,10 +73,10 @@ MainWindow::MainWindow(QWidget *parent)
quitAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q));
if (QApplication::arguments().contains("-fullscreen")) {
- scene = new GraphicsScene(0, 0, 750, 400, GraphicsScene::Small);
+ scene = new GraphicsScene(0, 0, 750, 400, GraphicsScene::Small, this);
setWindowState(Qt::WindowFullScreen);
} else {
- scene = new GraphicsScene(0, 0, 880, 630);
+ scene = new GraphicsScene(0, 0, 880, 630, GraphicsScene::Big, this);
layout()->setSizeConstraint(QLayout::SetFixedSize);
}
diff --git a/examples/widgets/animation/sub-attaq/mainwindow.h b/examples/widgets/animation/sub-attaq/mainwindow.h
index c4fb9d324d..660acfaa0a 100644
--- a/examples/widgets/animation/sub-attaq/mainwindow.h
+++ b/examples/widgets/animation/sub-attaq/mainwindow.h
@@ -48,11 +48,11 @@
**
****************************************************************************/
-#ifndef __MAINWINDOW__H__
-#define __MAINWINDOW__H__
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
//Qt
-#include <QtWidgets/QMainWindow>
+#include <QMainWindow>
class GraphicsScene;
QT_BEGIN_NAMESPACE
class QGraphicsView;
@@ -69,4 +69,4 @@ private:
QGraphicsView *view;
};
-#endif //__MAINWINDOW__H__
+#endif // MAINWINDOW_H
diff --git a/examples/widgets/animation/sub-attaq/pixmapitem.cpp b/examples/widgets/animation/sub-attaq/pixmapitem.cpp
index 9475d5c3f8..a8581d881a 100644
--- a/examples/widgets/animation/sub-attaq/pixmapitem.cpp
+++ b/examples/widgets/animation/sub-attaq/pixmapitem.cpp
@@ -54,7 +54,7 @@
//Qt
#include <QPainter>
-PixmapItem::PixmapItem(const QString &fileName,GraphicsScene::Mode mode, QGraphicsItem * parent)
+PixmapItem::PixmapItem(const QString &fileName, GraphicsScene::Mode mode, QGraphicsItem *parent)
: QGraphicsObject(parent)
{
if (mode == GraphicsScene::Big)
@@ -63,7 +63,8 @@ PixmapItem::PixmapItem(const QString &fileName,GraphicsScene::Mode mode, QGraphi
pix = QPixmap(QStringLiteral(":/small/") + fileName);
}
-PixmapItem::PixmapItem(const QString &fileName, QGraphicsScene *scene) : QGraphicsObject(), pix(fileName)
+PixmapItem::PixmapItem(const QString &fileName, QGraphicsScene *scene)
+ : QGraphicsObject(), pix(fileName)
{
scene->addItem(this);
}
diff --git a/examples/widgets/animation/sub-attaq/pixmapitem.h b/examples/widgets/animation/sub-attaq/pixmapitem.h
index ec5c01857f..45e2ca806f 100644
--- a/examples/widgets/animation/sub-attaq/pixmapitem.h
+++ b/examples/widgets/animation/sub-attaq/pixmapitem.h
@@ -48,14 +48,14 @@
**
****************************************************************************/
-#ifndef __PIXMAPITEM__H__
-#define __PIXMAPITEM__H__
+#ifndef PIXMAPITEM_H
+#define PIXMAPITEM_H
//Own
#include "graphicsscene.h"
//Qt
-#include <QtWidgets/QGraphicsObject>
+#include <QGraphicsObject>
class PixmapItem : public QGraphicsObject
{
@@ -69,4 +69,4 @@ private:
QPixmap pix;
};
-#endif //__PIXMAPITEM__H__
+#endif // PIXMAPITEM_H
diff --git a/examples/widgets/animation/sub-attaq/progressitem.cpp b/examples/widgets/animation/sub-attaq/progressitem.cpp
index 8b6b367710..350dbb7bbd 100644
--- a/examples/widgets/animation/sub-attaq/progressitem.cpp
+++ b/examples/widgets/animation/sub-attaq/progressitem.cpp
@@ -49,10 +49,11 @@
****************************************************************************/
#include "progressitem.h"
-#include "pixmapitem.h"
-ProgressItem::ProgressItem (QGraphicsItem * parent)
- : QGraphicsTextItem(parent), currentLevel(1), currentScore(0)
+#include <QFont>
+
+ProgressItem::ProgressItem(QGraphicsItem *parent)
+ : QGraphicsTextItem(parent)
{
setFont(QFont("Comic Sans MS"));
setPos(parentItem()->boundingRect().topRight() - QPointF(180, -5));
diff --git a/examples/widgets/animation/sub-attaq/progressitem.h b/examples/widgets/animation/sub-attaq/progressitem.h
index 23f5407978..f76b168151 100644
--- a/examples/widgets/animation/sub-attaq/progressitem.h
+++ b/examples/widgets/animation/sub-attaq/progressitem.h
@@ -52,19 +52,19 @@
#define PROGRESSITEM_H
//Qt
-#include <QtWidgets/QGraphicsTextItem>
+#include <QGraphicsTextItem>
class ProgressItem : public QGraphicsTextItem
{
public:
- ProgressItem(QGraphicsItem * parent = 0);
+ ProgressItem(QGraphicsItem *parent = nullptr);
void setLevel(int level);
void setScore(int score);
private:
void updateProgress();
- int currentLevel;
- int currentScore;
+ int currentLevel = 1;
+ int currentScore = 0;
};
#endif // PROGRESSITEM_H
diff --git a/examples/widgets/animation/sub-attaq/qanimationstate.cpp b/examples/widgets/animation/sub-attaq/qanimationstate.cpp
index ce99f9080d..6da085561b 100644
--- a/examples/widgets/animation/sub-attaq/qanimationstate.cpp
+++ b/examples/widgets/animation/sub-attaq/qanimationstate.cpp
@@ -50,7 +50,7 @@
#include "qanimationstate.h"
-#include <QtCore/qstate.h>
+#include <QAbstractAnimation>
QT_BEGIN_NAMESPACE
@@ -106,7 +106,7 @@ void QAnimationState::setAnimation(QAbstractAnimation *animation)
return;
//Disconnect from the previous animation if exist
- if(m_animation)
+ if (m_animation)
disconnect(m_animation, &QAbstractAnimation::finished, this, &QAnimationState::animationFinished);
m_animation = animation;
diff --git a/examples/widgets/animation/sub-attaq/qanimationstate.h b/examples/widgets/animation/sub-attaq/qanimationstate.h
index 063b119058..24759851ba 100644
--- a/examples/widgets/animation/sub-attaq/qanimationstate.h
+++ b/examples/widgets/animation/sub-attaq/qanimationstate.h
@@ -51,13 +51,7 @@
#ifndef QANIMATIONSTATE_H
#define QANIMATIONSTATE_H
-#ifndef QT_STATEMACHINE_SOLUTION
-# include <QtCore/qstate.h>
-# include <QtCore/qabstractanimation.h>
-#else
-# include "qstate.h"
-# include "qabstractanimation.h"
-#endif
+#include <QState>
QT_BEGIN_NAMESPACE
@@ -67,7 +61,7 @@ class QAnimationState : public QState
{
Q_OBJECT
public:
- QAnimationState(QState *parent = 0);
+ QAnimationState(QState *parent = nullptr);
~QAnimationState();
void setAnimation(QAbstractAnimation *animation);
diff --git a/examples/widgets/animation/sub-attaq/states.cpp b/examples/widgets/animation/sub-attaq/states.cpp
index cda10ccdaf..c7e2738aad 100644
--- a/examples/widgets/animation/sub-attaq/states.cpp
+++ b/examples/widgets/animation/sub-attaq/states.cpp
@@ -59,12 +59,12 @@
#include "textinformationitem.h"
//Qt
-#include <QtWidgets/QMessageBox>
-#include <QtWidgets/QGraphicsView>
-#include <QtCore/QStateMachine>
-#include <QtWidgets/QKeyEventTransition>
-#include <QtCore/QFinalState>
-#include <QtCore/QRandomGenerator>
+#include <QFinalState>
+#include <QGraphicsView>
+#include <QKeyEventTransition>
+#include <QMessageBox>
+#include <QRandomGenerator>
+#include <QStateMachine>
PlayState::PlayState(GraphicsScene *scene, QState *parent)
: QState(parent), scene(scene), machine(nullptr),
@@ -146,7 +146,7 @@ void PlayState::onEntry(QEvent *)
machine->setInitialState(levelState);
//Final state
- QFinalState *final = new QFinalState(machine);
+ QFinalState *finalState = new QFinalState(machine);
//This transition is triggered when the player press space after completing a level
CustomSpaceTransition *spaceTransition = new CustomSpaceTransition(scene->views().at(0), this, QEvent::KeyPress, Qt::Key_Space);
@@ -154,7 +154,7 @@ void PlayState::onEntry(QEvent *)
winState->addTransition(spaceTransition);
//We lost we should reach the final state
- lostState->addTransition(lostState, &QState::finished, final);
+ lostState->addTransition(lostState, &QState::finished, finalState);
machine->start();
}
@@ -181,11 +181,9 @@ void LevelState::initializeLevel()
scene->progressItem->setScore(game->score);
scene->progressItem->setLevel(game->currentLevel + 1);
- GraphicsScene::LevelDescription currentLevelDescription = scene->levelsData.value(game->currentLevel);
+ const GraphicsScene::LevelDescription currentLevelDescription = scene->levelsData.value(game->currentLevel);
+ for (const QPair<int,int> &subContent : currentLevelDescription.submarines) {
- for (int i = 0; i < currentLevelDescription.submarines.size(); ++i ) {
-
- QPair<int,int> subContent = currentLevelDescription.submarines.at(i);
GraphicsScene::SubmarineDescription submarineDesc = scene->submarinesData.at(subContent.first);
for (int j = 0; j < subContent.second; ++j ) {
@@ -202,9 +200,10 @@ void LevelState::initializeLevel()
}
/** Pause State */
-PauseState::PauseState(GraphicsScene *scene, QState *parent) : QState(parent),scene(scene)
+PauseState::PauseState(GraphicsScene *scene, QState *parent) : QState(parent), scene(scene)
{
}
+
void PauseState::onEntry(QEvent *)
{
AnimationManager::self()->pauseAll();
@@ -324,8 +323,7 @@ bool WinTransition::eventTest(QEvent *event)
/** Space transition */
CustomSpaceTransition::CustomSpaceTransition(QWidget *widget, PlayState *game, QEvent::Type type, int key)
- : QKeyEventTransition(widget, type, key),
- game(game)
+ : QKeyEventTransition(widget, type, key), game(game)
{
}
diff --git a/examples/widgets/animation/sub-attaq/states.h b/examples/widgets/animation/sub-attaq/states.h
index cd68e319c2..b3651e1c82 100644
--- a/examples/widgets/animation/sub-attaq/states.h
+++ b/examples/widgets/animation/sub-attaq/states.h
@@ -52,15 +52,11 @@
#define STATES_H
//Qt
-#include <QtCore/QState>
-#include <QtCore/QSignalTransition>
-#include <QtCore/QPropertyAnimation>
-#include <QtWidgets/QKeyEventTransition>
-#include <QtCore/QSet>
+#include <QKeyEventTransition>
+#include <QSignalTransition>
+#include <QState>
class GraphicsScene;
-class Boat;
-class SubMarine;
QT_BEGIN_NAMESPACE
class QStateMachine;
QT_END_NAMESPACE
@@ -68,7 +64,7 @@ QT_END_NAMESPACE
class PlayState : public QState
{
public:
- explicit PlayState(GraphicsScene *scene, QState *parent = 0);
+ explicit PlayState(GraphicsScene *scene, QState *parent = nullptr);
~PlayState();
protected:
@@ -92,7 +88,7 @@ private :
class LevelState : public QState
{
public:
- LevelState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
+ LevelState(GraphicsScene *scene, PlayState *game, QState *parent = nullptr);
protected:
void onEntry(QEvent *) override;
private :
@@ -104,7 +100,7 @@ private :
class PauseState : public QState
{
public:
- explicit PauseState(GraphicsScene *scene, QState *parent = 0);
+ explicit PauseState(GraphicsScene *scene, QState *parent = nullptr);
protected:
void onEntry(QEvent *) override;
@@ -116,7 +112,7 @@ private :
class LostState : public QState
{
public:
- LostState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
+ LostState(GraphicsScene *scene, PlayState *game, QState *parent = nullptr);
protected:
void onEntry(QEvent *) override;
@@ -129,7 +125,7 @@ private :
class WinState : public QState
{
public:
- WinState(GraphicsScene *scene, PlayState *game, QState *parent = 0);
+ WinState(GraphicsScene *scene, PlayState *game, QState *parent = nullptr);
protected:
void onEntry(QEvent *) override;
@@ -154,7 +150,7 @@ public:
protected:
bool eventTest(QEvent *event) override;
private:
- PlayState * game;
+ PlayState *game;
GraphicsScene *scene;
};
@@ -166,7 +162,7 @@ public:
protected:
bool eventTest(QEvent *event) override;
private:
- PlayState * game;
+ PlayState *game;
GraphicsScene *scene;
};
diff --git a/examples/widgets/animation/sub-attaq/submarine.cpp b/examples/widgets/animation/sub-attaq/submarine.cpp
index 775e75ceed..a4ca376045 100644
--- a/examples/widgets/animation/sub-attaq/submarine.cpp
+++ b/examples/widgets/animation/sub-attaq/submarine.cpp
@@ -52,15 +52,14 @@
#include "submarine.h"
#include "submarine_p.h"
#include "torpedo.h"
-#include "pixmapitem.h"
#include "graphicsscene.h"
#include "animationmanager.h"
#include "qanimationstate.h"
-#include <QtCore/QPropertyAnimation>
-#include <QtCore/QStateMachine>
-#include <QtCore/QFinalState>
-#include <QtCore/QSequentialAnimationGroup>
+#include <QFinalState>
+#include <QPropertyAnimation>
+#include <QStateMachine>
+#include <QSequentialAnimationGroup>
static QAbstractAnimation *setupDestroyAnimation(SubMarine *sub)
{
@@ -86,9 +85,8 @@ SubMarine::SubMarine(int type, const QString &name, int points) : PixmapItem(QSt
graphicsRotation = new QGraphicsRotation(this);
graphicsRotation->setAxis(Qt::YAxis);
- graphicsRotation->setOrigin(QVector3D(size().width()/2, size().height()/2, 0));
- QList<QGraphicsTransform *> r;
- r.append(graphicsRotation);
+ graphicsRotation->setOrigin(QVector3D(size().width() / 2, size().height() / 2, 0));
+ QList<QGraphicsTransform *> r({graphicsRotation});
setTransformations(r);
//We setup the state machine of the submarine
@@ -112,7 +110,7 @@ SubMarine::SubMarine(int type, const QString &name, int points) : PixmapItem(QSt
machine->setInitialState(moving);
//End
- QFinalState *final = new QFinalState(machine);
+ QFinalState *finalState = new QFinalState(machine);
//If the moving animation is finished we move to the return state
movement->addTransition(movement, &QAnimationState::animationFinished, rotation);
@@ -128,7 +126,7 @@ SubMarine::SubMarine(int type, const QString &name, int points) : PixmapItem(QSt
moving->addTransition(this, &SubMarine::subMarineDestroyed, destroyedState);
//Transition to final state when the destroyed animation is finished
- destroyedState->addTransition(destroyedState, &QAnimationState::animationFinished, final);
+ destroyedState->addTransition(destroyedState, &QAnimationState::animationFinished, finalState);
//The machine has finished to be executed, then the submarine is dead
connect(machine,&QState::finished,this, &SubMarine::subMarineExecutionFinished);
@@ -145,9 +143,8 @@ void SubMarine::setCurrentDirection(SubMarine::Movement direction)
{
if (this->direction == direction)
return;
- if (direction == SubMarine::Right && this->direction == SubMarine::None) {
+ if (direction == SubMarine::Right && this->direction == SubMarine::None)
graphicsRotation->setAngle(180);
- }
this->direction = direction;
}
@@ -158,9 +155,8 @@ enum SubMarine::Movement SubMarine::currentDirection() const
void SubMarine::setCurrentSpeed(int speed)
{
- if (speed < 0 || speed > 3) {
+ if (speed < 0 || speed > 3)
qWarning("SubMarine::setCurrentSpeed : The speed is invalid");
- }
this->speed = speed;
emit subMarineStateChanged();
}
@@ -172,7 +168,7 @@ int SubMarine::currentSpeed() const
void SubMarine::launchTorpedo(int speed)
{
- Torpedo * torp = new Torpedo();
+ Torpedo *torp = new Torpedo;
GraphicsScene *scene = static_cast<GraphicsScene *>(this->scene());
scene->addItem(torp);
torp->setPos(pos());
diff --git a/examples/widgets/animation/sub-attaq/submarine.h b/examples/widgets/animation/sub-attaq/submarine.h
index d145c9cbee..256683ec70 100644
--- a/examples/widgets/animation/sub-attaq/submarine.h
+++ b/examples/widgets/animation/sub-attaq/submarine.h
@@ -48,15 +48,12 @@
**
****************************************************************************/
-#ifndef __SUBMARINE__H__
-#define __SUBMARINE__H__
-
-//Qt
-#include <QtWidgets/QGraphicsTransform>
+#ifndef SUBMARINE_H
+#define SUBMARINE_H
#include "pixmapitem.h"
-class Torpedo;
+#include <QGraphicsRotation>
class SubMarine : public PixmapItem
{
@@ -99,4 +96,4 @@ private:
QGraphicsRotation *graphicsRotation;
};
-#endif //__SUBMARINE__H__
+#endif // SUBMARINE_H
diff --git a/examples/widgets/animation/sub-attaq/submarine_p.h b/examples/widgets/animation/sub-attaq/submarine_p.h
index 1c2cb7ceac..36807dade3 100644
--- a/examples/widgets/animation/sub-attaq/submarine_p.h
+++ b/examples/widgets/animation/sub-attaq/submarine_p.h
@@ -68,16 +68,15 @@
#include "qanimationstate.h"
//Qt
-#include <QtCore/QPropertyAnimation>
-#include <QtCore/QRandomGenerator>
-#include <QtWidgets/QGraphicsScene>
+#include <QPropertyAnimation>
+#include <QRandomGenerator>
//This state is describing when the boat is moving right
class MovementState : public QAnimationState
{
Q_OBJECT
public:
- explicit MovementState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent)
+ explicit MovementState(SubMarine *submarine, QState *parent = nullptr) : QAnimationState(parent)
{
movementAnimation = new QPropertyAnimation(submarine, "pos");
connect(movementAnimation, &QPropertyAnimation::valueChanged,
@@ -117,7 +116,7 @@ private:
class ReturnState : public QAnimationState
{
public:
- explicit ReturnState(SubMarine *submarine, QState *parent = 0) : QAnimationState(parent)
+ explicit ReturnState(SubMarine *submarine, QState *parent = nullptr) : QAnimationState(parent)
{
returnAnimation = new QPropertyAnimation(submarine->rotation(), "angle");
returnAnimation->setDuration(500);
diff --git a/examples/widgets/animation/sub-attaq/textinformationitem.cpp b/examples/widgets/animation/sub-attaq/textinformationitem.cpp
index 16f787125d..4d4934f63d 100644
--- a/examples/widgets/animation/sub-attaq/textinformationitem.cpp
+++ b/examples/widgets/animation/sub-attaq/textinformationitem.cpp
@@ -50,14 +50,15 @@
#include "textinformationitem.h"
#include "pixmapitem.h"
-TextInformationItem::TextInformationItem (QGraphicsItem * parent)
+TextInformationItem::TextInformationItem (QGraphicsItem *parent)
: QGraphicsTextItem(parent)
{
setFont(QFont("Comic Sans MS", 15));
}
-#include <QDebug>
-void TextInformationItem::setMessage(const QString& text)
+
+void TextInformationItem::setMessage(const QString &text)
{
setHtml(text);
- setPos(parentItem()->boundingRect().center().x() - boundingRect().size().width()/2 , parentItem()->boundingRect().center().y());
+ setPos(parentItem()->boundingRect().center().x() - boundingRect().size().width() / 2,
+ parentItem()->boundingRect().center().y());
}
diff --git a/examples/widgets/animation/sub-attaq/textinformationitem.h b/examples/widgets/animation/sub-attaq/textinformationitem.h
index aa6f913e48..0a0b618460 100644
--- a/examples/widgets/animation/sub-attaq/textinformationitem.h
+++ b/examples/widgets/animation/sub-attaq/textinformationitem.h
@@ -52,13 +52,13 @@
#define TEXTINFORMATIONITEM_H
//Qt
-#include <QtWidgets/QGraphicsTextItem>
+#include <QGraphicsTextItem>
class TextInformationItem : public QGraphicsTextItem
{
public:
- TextInformationItem(QGraphicsItem * parent = 0);
- void setMessage(const QString& text);
+ TextInformationItem(QGraphicsItem *parent = nullptr);
+ void setMessage(const QString &text);
};
#endif // TEXTINFORMATIONITEM_H
diff --git a/examples/widgets/animation/sub-attaq/torpedo.cpp b/examples/widgets/animation/sub-attaq/torpedo.cpp
index 92a3833452..7395aa39ac 100644
--- a/examples/widgets/animation/sub-attaq/torpedo.cpp
+++ b/examples/widgets/animation/sub-attaq/torpedo.cpp
@@ -50,15 +50,14 @@
//Own
#include "torpedo.h"
-#include "pixmapitem.h"
#include "boat.h"
#include "graphicsscene.h"
#include "animationmanager.h"
#include "qanimationstate.h"
-#include <QtCore/QPropertyAnimation>
-#include <QtCore/QStateMachine>
-#include <QtCore/QFinalState>
+#include <QPropertyAnimation>
+#include <QStateMachine>
+#include <QFinalState>
Torpedo::Torpedo() : PixmapItem(QString::fromLatin1("torpedo"),GraphicsScene::Big),
currentSpeed(0)
@@ -70,11 +69,11 @@ void Torpedo::launch()
{
QPropertyAnimation *launchAnimation = new QPropertyAnimation(this, "pos");
AnimationManager::self()->registerAnimation(launchAnimation);
- launchAnimation->setEndValue(QPointF(x(),qobject_cast<GraphicsScene *>(scene())->sealLevel() - 15));
+ launchAnimation->setEndValue(QPointF(x(), qobject_cast<GraphicsScene *>(scene())->sealLevel() - 15));
launchAnimation->setEasingCurve(QEasingCurve::InQuad);
- launchAnimation->setDuration(y()/currentSpeed*10);
- connect(launchAnimation,&QVariantAnimation::valueChanged,this,&Torpedo::onAnimationLaunchValueChanged);
- connect(this,&Torpedo::torpedoExploded, launchAnimation, &QAbstractAnimation::stop);
+ launchAnimation->setDuration(y() / currentSpeed * 10);
+ connect(launchAnimation, &QVariantAnimation::valueChanged, this, &Torpedo::onAnimationLaunchValueChanged);
+ connect(this, &Torpedo::torpedoExploded, launchAnimation, &QAbstractAnimation::stop);
//We setup the state machine of the torpedo
QStateMachine *machine = new QStateMachine(this);
@@ -84,18 +83,18 @@ void Torpedo::launch()
launched->setAnimation(launchAnimation);
//End
- QFinalState *final = new QFinalState(machine);
+ QFinalState *finalState = new QFinalState(machine);
machine->setInitialState(launched);
//### Add a nice animation when the torpedo is destroyed
- launched->addTransition(this, &Torpedo::torpedoExploded,final);
+ launched->addTransition(this, &Torpedo::torpedoExploded, finalState);
//If the animation is finished, then we move to the final state
- launched->addTransition(launched, &QAnimationState::animationFinished, final);
+ launched->addTransition(launched, &QAnimationState::animationFinished, finalState);
//The machine has finished to be executed, then the boat is dead
- connect(machine,&QState::finished,this, &Torpedo::torpedoExecutionFinished);
+ connect(machine, &QState::finished, this, &Torpedo::torpedoExecutionFinished);
machine->start();
}
diff --git a/examples/widgets/animation/sub-attaq/torpedo.h b/examples/widgets/animation/sub-attaq/torpedo.h
index bd04bd79aa..7ac853d4e9 100644
--- a/examples/widgets/animation/sub-attaq/torpedo.h
+++ b/examples/widgets/animation/sub-attaq/torpedo.h
@@ -48,8 +48,8 @@
**
****************************************************************************/
-#ifndef __TORPEDO__H__
-#define __TORPEDO__H__
+#ifndef TORPEDO_H
+#define TORPEDO_H
#include "pixmapitem.h"
@@ -73,4 +73,4 @@ private:
int currentSpeed;
};
-#endif //__TORPEDO__H__
+#endif // TORPEDO_H
diff --git a/examples/widgets/desktop/screenshot/main.cpp b/examples/widgets/desktop/screenshot/main.cpp
index 825c40b236..96b0d57daa 100644
--- a/examples/widgets/desktop/screenshot/main.cpp
+++ b/examples/widgets/desktop/screenshot/main.cpp
@@ -49,7 +49,7 @@
****************************************************************************/
#include <QApplication>
-#include <QDesktopWidget>
+#include <QScreen>
#include "screenshot.h"
@@ -58,7 +58,8 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
Screenshot screenshot;
- screenshot.move(QApplication::desktop()->availableGeometry(&screenshot).topLeft() + QPoint(20, 20));
+ screenshot.move(screenshot.screen()->availableGeometry().topLeft() + QPoint(20, 20));
screenshot.show();
+
return app.exec();
}
diff --git a/examples/widgets/desktop/screenshot/screenshot.cpp b/examples/widgets/desktop/screenshot/screenshot.cpp
index 715e6c780e..ce5597bbdd 100644
--- a/examples/widgets/desktop/screenshot/screenshot.cpp
+++ b/examples/widgets/desktop/screenshot/screenshot.cpp
@@ -59,7 +59,7 @@ Screenshot::Screenshot()
screenshotLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
screenshotLabel->setAlignment(Qt::AlignCenter);
- const QRect screenGeometry = QApplication::desktop()->screenGeometry(this);
+ const QRect screenGeometry = screen()->geometry();
screenshotLabel->setMinimumSize(screenGeometry.width() / 8, screenGeometry.height() / 8);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
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/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/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp
index 1830b21e8f..df77d03567 100644
--- a/examples/widgets/dialogs/standarddialogs/dialog.cpp
+++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp
@@ -287,7 +287,6 @@ Dialog::Dialog(QWidget *parent)
fileDialogOptionsWidget->addCheckBox(tr("Show directories only"), QFileDialog::ShowDirsOnly);
fileDialogOptionsWidget->addCheckBox(tr("Do not resolve symlinks"), QFileDialog::DontResolveSymlinks);
fileDialogOptionsWidget->addCheckBox(tr("Do not confirm overwrite"), QFileDialog::DontConfirmOverwrite);
- fileDialogOptionsWidget->addCheckBox(tr("Do not use sheet"), QFileDialog::DontUseSheet);
fileDialogOptionsWidget->addCheckBox(tr("Readonly"), QFileDialog::ReadOnly);
fileDialogOptionsWidget->addCheckBox(tr("Hide name filter details"), QFileDialog::HideNameFilterDetails);
fileDialogOptionsWidget->addCheckBox(tr("Do not use custom directory icons (Windows)"), QFileDialog::DontUseCustomDirectoryIcons);
@@ -318,7 +317,7 @@ void Dialog::setInteger()
{
//! [0]
bool ok;
- int i = QInputDialog::getInt(this, tr("QInputDialog::getInteger()"),
+ int i = QInputDialog::getInt(this, tr("QInputDialog::getInt()"),
tr("Percentage:"), 25, 0, 100, 1, &ok);
if (ok)
integerLabel->setText(tr("%1%").arg(i));
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 f7417f0e45..19ed2bf66f 100644
--- a/examples/widgets/dialogs/standarddialogs/main.cpp
+++ b/examples/widgets/dialogs/standarddialogs/main.cpp
@@ -49,8 +49,8 @@
****************************************************************************/
#include <QApplication>
+#include <QScreen>
#include <QStyleHints>
-#include <QDesktopWidget>
#include <QTranslator>
#include <QLocale>
#include <QLibraryInfo>
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
Dialog dialog;
if (!QGuiApplication::styleHints()->showIsFullScreen() && !QGuiApplication::styleHints()->showIsMaximized()) {
- const QRect availableGeometry = QApplication::desktop()->availableGeometry(&dialog);
+ const QRect availableGeometry = dialog.screen()->availableGeometry();
dialog.resize(availableGeometry.width() / 3, availableGeometry.height() * 2 / 3);
dialog.move((availableGeometry.width() - dialog.width()) / 2,
(availableGeometry.height() - dialog.height()) / 2);
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/doc/src/application.qdoc b/examples/widgets/doc/src/application.qdoc
index 040aa171b7..6c37fa67bb 100644
--- a/examples/widgets/doc/src/application.qdoc
+++ b/examples/widgets/doc/src/application.qdoc
@@ -327,9 +327,12 @@
\snippet mainwindows/application/mainwindow.cpp 44
\snippet mainwindows/application/mainwindow.cpp 45
- Saving a file is very similar to loading one. Here, the
- QFile::Text flag ensures that on Windows, "\\n" is converted into
- "\\r\\n" to conform to the Windows convension.
+ Saving a file is similar to loading one. We use QSaveFile to ensure
+ all data are safely written and existing files are not damaged
+ should writing fail.
+ We use the QFile::Text flag to make sure that on Windows, "\\n"
+ is converted into "\\r\\n" to conform to the Windows convention.
+
\snippet mainwindows/application/mainwindow.cpp 46
\snippet mainwindows/application/mainwindow.cpp 47
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/icons.qdoc b/examples/widgets/doc/src/icons.qdoc
index 60cb9062c2..7aae0491d6 100644
--- a/examples/widgets/doc/src/icons.qdoc
+++ b/examples/widgets/doc/src/icons.qdoc
@@ -262,12 +262,7 @@
provides arrays allowing to map from enumeration value to row/column
(by using QVector::indexOf()) and back by using the array index and lists
of the matching strings. Qt's containers can be easily populated by
- using C++ 11 initializer lists. If the compiler does not provide that feature,
- a pattern like
-
- \snippet widgets/icons/iconpreviewarea.cpp 43
-
- can be used.
+ using C++ 11 initializer lists.
We need two public functions to set the current icon and the
icon's size. In addition the class has three private functions: We
diff --git a/examples/widgets/doc/src/stardelegate.qdoc b/examples/widgets/doc/src/stardelegate.qdoc
index 0b91723a51..b33fa3550f 100644
--- a/examples/widgets/doc/src/stardelegate.qdoc
+++ b/examples/widgets/doc/src/stardelegate.qdoc
@@ -269,7 +269,7 @@
\codeline
\snippet itemviews/stardelegate/main.cpp 4
- Notice the call to qVariantFromValue to convert a \c
+ Notice the call to QVariant::fromValue to convert a \c
StarRating to a QVariant.
\section1 Possible Extensions and Suggestions
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/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 7f62ac894b..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,12 +96,8 @@ 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);
-// The ifdef block is a workaround for the beta, TODO: remove when bug 238525 is fixed
-#if 0 // Used to be included in Qt4 for Q_WS_MAC
- dialog.setOption(QColorDialog::DontUseNativeDialog, true);
-#endif
dialog.move(280, 120);
if (dialog.exec() == QDialog::Rejected)
return;
@@ -183,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)
@@ -205,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);
@@ -223,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();
}
@@ -293,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)"));
@@ -427,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);
@@ -491,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);
@@ -533,8 +487,6 @@ Scene::Scene(int width, int height, int maxTextureSize)
m_timer->setInterval(20);
connect(m_timer, &QTimer::timeout, this, [this](){ update(); });
m_timer->start();
-
- m_time.start();
}
Scene::~Scene()
@@ -570,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);
@@ -587,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);
@@ -640,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 ccb6f368cd..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
@@ -220,7 +215,7 @@ private:
void initGL();
QPointF pixelPosToViewPos(const QPointF& p);
- QTime m_time;
+ QTime m_time; // ### Qt 6: remove (unused)
int m_lastTime;
int m_mouseEventTime;
int m_distExp;
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 9676c13ff7..21998dc2df 100644
--- a/examples/widgets/graphicsview/chip/view.cpp
+++ b/examples/widgets/graphicsview/chip/view.cpp
@@ -62,13 +62,13 @@
#else
#include <QtWidgets>
#endif
-#include <qmath.h>
+#include <QtMath>
#if QT_CONFIG(wheelevent)
void GraphicsView::wheelEvent(QWheelEvent *e)
{
if (e->modifiers() & Qt::ControlModifier) {
- if (e->delta() > 0)
+ if (e->angleDelta().y() > 0)
view->zoomIn(6);
else
view->zoomOut(6);
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 88160d9399..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;
@@ -113,15 +111,13 @@ void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
QLineF centerLine(myStartItem->pos(), myEndItem->pos());
QPolygonF endPolygon = myEndItem->polygon();
QPointF p1 = endPolygon.first() + myEndItem->pos();
- QPointF p2;
QPointF intersectPoint;
- QLineF polyLine;
for (int i = 1; i < endPolygon.count(); ++i) {
- p2 = endPolygon.at(i) + myEndItem->pos();
- polyLine = QLineF(p1, p2);
- QLineF::IntersectType intersectType =
- polyLine.intersect(centerLine, &intersectPoint);
- if (intersectType == QLineF::BoundedIntersection)
+ QPointF p2 = endPolygon.at(i) + myEndItem->pos();
+ QLineF polyLine = QLineF(p1, p2);
+ QLineF::IntersectionType intersectionType =
+ polyLine.intersects(centerLine, &intersectPoint);
+ if (intersectionType == QLineF::BoundedIntersection)
break;
p1 = p2;
}
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/diagramscene/mainwindow.cpp b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp
index 07f92f61c1..3327d4d5df 100644
--- a/examples/widgets/graphicsview/diagramscene/mainwindow.cpp
+++ b/examples/widgets/graphicsview/diagramscene/mainwindow.cpp
@@ -473,7 +473,7 @@ void MainWindow::createToolbars()
fontSizeCombo->addItem(QString().setNum(i));
QIntValidator *validator = new QIntValidator(2, 64, this);
fontSizeCombo->setValidator(validator);
- connect(fontSizeCombo, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
+ connect(fontSizeCombo, &QComboBox::currentTextChanged,
this, &MainWindow::fontSizeChanged);
fontColorToolButton = new QToolButton;
@@ -536,7 +536,7 @@ void MainWindow::createToolbars()
scales << tr("50%") << tr("75%") << tr("100%") << tr("125%") << tr("150%");
sceneScaleCombo->addItems(scales);
sceneScaleCombo->setCurrentIndex(2);
- connect(sceneScaleCombo, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
+ connect(sceneScaleCombo, &QComboBox::currentTextChanged,
this, &MainWindow::sceneScaleChanged);
pointerToolbar = addToolBar(tr("Pointer 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 6b817b2a21..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->delta() / 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.cpp b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp
index 0c831360cf..9fa24fcd17 100644
--- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp
+++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.cpp
@@ -73,7 +73,7 @@ EmbeddedDialog::EmbeddedDialog(QWidget *parent)
this, &EmbeddedDialog::spacingChanged);
connect(ui->fontComboBox, &QFontComboBox::currentFontChanged,
this, &EmbeddedDialog::fontChanged);
- connect(ui->style, QOverload<const QString &>::of(&QComboBox::activated),
+ connect(ui->style, &QComboBox::textActivated,
this, &EmbeddedDialog::styleChanged);
}
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/dirview/main.cpp b/examples/widgets/itemviews/dirview/main.cpp
index eefea657f6..fcdf4c7ba4 100644
--- a/examples/widgets/itemviews/dirview/main.cpp
+++ b/examples/widgets/itemviews/dirview/main.cpp
@@ -49,9 +49,9 @@
****************************************************************************/
#include <QApplication>
-#include <QDesktopWidget>
#include <QFileSystemModel>
#include <QFileIconProvider>
+#include <QScreen>
#include <QTreeView>
#include <QCommandLineParser>
#include <QCommandLineOption>
@@ -65,8 +65,10 @@ int main(int argc, char *argv[])
parser.setApplicationDescription("Qt Dir View Example");
parser.addHelpOption();
parser.addVersionOption();
- QCommandLineOption dontUseCustomDirectoryIconsOption("c", "Set QFileIconProvider::DontUseCustomDirectoryIcons");
+ QCommandLineOption dontUseCustomDirectoryIconsOption("c", "Set QFileSystemModel::DontUseCustomDirectoryIcons");
parser.addOption(dontUseCustomDirectoryIconsOption);
+ QCommandLineOption dontWatchOption("w", "Set QFileSystemModel::DontWatch");
+ parser.addOption(dontWatchOption);
parser.addPositionalArgument("directory", "The directory to start in.");
parser.process(app);
const QString rootPath = parser.positionalArguments().isEmpty()
@@ -75,7 +77,9 @@ int main(int argc, char *argv[])
QFileSystemModel model;
model.setRootPath("");
if (parser.isSet(dontUseCustomDirectoryIconsOption))
- model.iconProvider()->setOptions(QFileIconProvider::DontUseCustomDirectoryIcons);
+ model.setOption(QFileSystemModel::DontUseCustomDirectoryIcons);
+ if (parser.isSet(dontWatchOption))
+ model.setOption(QFileSystemModel::DontWatchForChanges);
QTreeView tree;
tree.setModel(&model);
if (!rootPath.isEmpty()) {
@@ -88,7 +92,7 @@ int main(int argc, char *argv[])
tree.setAnimated(false);
tree.setIndentation(20);
tree.setSortingEnabled(true);
- const QSize availableSize = QApplication::desktop()->availableGeometry(&tree).size();
+ const QSize availableSize = tree.screen()->availableGeometry().size();
tree.resize(availableSize / 2);
tree.setColumnWidth(0, tree.width() / 3);
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/mainwindows/application/mainwindow.cpp b/examples/widgets/mainwindows/application/mainwindow.cpp
index 4b639ead18..d0c009427f 100644
--- a/examples/widgets/mainwindows/application/mainwindow.cpp
+++ b/examples/widgets/mainwindows/application/mainwindow.cpp
@@ -281,7 +281,7 @@ void MainWindow::readSettings()
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
const QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray();
if (geometry.isEmpty()) {
- const QRect availableGeometry = QApplication::desktop()->availableGeometry(this);
+ const QRect availableGeometry = screen()->availableGeometry();
resize(availableGeometry.width() / 3, availableGeometry.height() / 2);
move((availableGeometry.width() - width()) / 2,
(availableGeometry.height() - height()) / 2);
@@ -353,23 +353,27 @@ void MainWindow::loadFile(const QString &fileName)
bool MainWindow::saveFile(const QString &fileName)
//! [44] //! [45]
{
- QFile file(fileName);
- if (!file.open(QFile::WriteOnly | QFile::Text)) {
- QMessageBox::warning(this, tr("Application"),
- tr("Cannot write file %1:\n%2.")
- .arg(QDir::toNativeSeparators(fileName),
- file.errorString()));
- return false;
- }
+ QString errorMessage;
- QTextStream out(&file);
-#ifndef QT_NO_CURSOR
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
-#endif
- out << textEdit->toPlainText();
-#ifndef QT_NO_CURSOR
+ QSaveFile file(fileName);
+ if (file.open(QFile::WriteOnly | QFile::Text)) {
+ QTextStream out(&file);
+ out << textEdit->toPlainText();
+ if (!file.commit()) {
+ errorMessage = tr("Cannot write file %1:\n%2.")
+ .arg(QDir::toNativeSeparators(fileName), file.errorString());
+ }
+ } else {
+ errorMessage = tr("Cannot open file %1 for writing:\n%2.")
+ .arg(QDir::toNativeSeparators(fileName), file.errorString());
+ }
QGuiApplication::restoreOverrideCursor();
-#endif
+
+ if (!errorMessage.isEmpty()) {
+ QMessageBox::warning(this, tr("Application"), errorMessage);
+ return false;
+ }
setCurrentFile(fileName);
statusBar()->showMessage(tr("File saved"), 2000);
diff --git a/examples/widgets/mainwindows/mdi/mainwindow.cpp b/examples/widgets/mainwindows/mdi/mainwindow.cpp
index b952d19e2e..ccfa7435d7 100644
--- a/examples/widgets/mainwindows/mdi/mainwindow.cpp
+++ b/examples/widgets/mainwindows/mdi/mainwindow.cpp
@@ -464,7 +464,7 @@ void MainWindow::readSettings()
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
const QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray();
if (geometry.isEmpty()) {
- const QRect availableGeometry = QApplication::desktop()->availableGeometry(this);
+ const QRect availableGeometry = screen()->availableGeometry();
resize(availableGeometry.width() / 3, availableGeometry.height() / 2);
move((availableGeometry.width() - width()) / 2,
(availableGeometry.height() - height()) / 2);
diff --git a/examples/widgets/mainwindows/mdi/mdichild.cpp b/examples/widgets/mainwindows/mdi/mdichild.cpp
index 16f2040de0..727d4f6cfd 100644
--- a/examples/widgets/mainwindows/mdi/mdichild.cpp
+++ b/examples/widgets/mainwindows/mdi/mdichild.cpp
@@ -115,19 +115,28 @@ bool MdiChild::saveAs()
bool MdiChild::saveFile(const QString &fileName)
{
- QFile file(fileName);
- if (!file.open(QFile::WriteOnly | QFile::Text)) {
- QMessageBox::warning(this, tr("MDI"),
- tr("Cannot write file %1:\n%2.")
- .arg(QDir::toNativeSeparators(fileName), file.errorString()));
- return false;
- }
+ QString errorMessage;
- QTextStream out(&file);
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
- out << toPlainText();
+ QSaveFile file(fileName);
+ if (file.open(QFile::WriteOnly | QFile::Text)) {
+ QTextStream out(&file);
+ out << toPlainText();
+ if (!file.commit()) {
+ errorMessage = tr("Cannot write file %1:\n%2.")
+ .arg(QDir::toNativeSeparators(fileName), file.errorString());
+ }
+ } else {
+ errorMessage = tr("Cannot open file %1 for writing:\n%2.")
+ .arg(QDir::toNativeSeparators(fileName), file.errorString());
+ }
QGuiApplication::restoreOverrideCursor();
+ if (!errorMessage.isEmpty()) {
+ QMessageBox::warning(this, tr("MDI"), errorMessage);
+ return false;
+ }
+
setCurrentFile(fileName);
return true;
}
diff --git a/examples/widgets/mainwindows/sdi/mainwindow.cpp b/examples/widgets/mainwindows/sdi/mainwindow.cpp
index 62a74b26e6..c3cd131923 100644
--- a/examples/widgets/mainwindows/sdi/mainwindow.cpp
+++ b/examples/widgets/mainwindows/sdi/mainwindow.cpp
@@ -167,7 +167,7 @@ void MainWindow::tile(const QMainWindow *previous)
if (!topFrameWidth)
topFrameWidth = 40;
const QPoint pos = previous->pos() + 2 * QPoint(topFrameWidth, topFrameWidth);
- if (QApplication::desktop()->availableGeometry(this).contains(rect().bottomRight() + pos))
+ if (screen()->availableGeometry().contains(rect().bottomRight() + pos))
move(pos);
}
@@ -290,7 +290,7 @@ void MainWindow::readSettings()
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
const QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray();
if (geometry.isEmpty()) {
- const QRect availableGeometry = QApplication::desktop()->availableGeometry(this);
+ const QRect availableGeometry = screen()->availableGeometry();
resize(availableGeometry.width() / 3, availableGeometry.height() / 2);
move((availableGeometry.width() - width()) / 2,
(availableGeometry.height() - height()) / 2);
@@ -425,19 +425,28 @@ void MainWindow::openRecentFile()
bool MainWindow::saveFile(const QString &fileName)
{
- QFile file(fileName);
- if (!file.open(QFile::WriteOnly | QFile::Text)) {
- QMessageBox::warning(this, tr("SDI"),
- tr("Cannot write file %1:\n%2.")
- .arg(QDir::toNativeSeparators(fileName), file.errorString()));
- return false;
- }
+ QString errorMessage;
- QTextStream out(&file);
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
- out << textEdit->toPlainText();
+ QSaveFile file(fileName);
+ if (file.open(QFile::WriteOnly | QFile::Text)) {
+ QTextStream out(&file);
+ out << textEdit->toPlainText();
+ if (!file.commit()) {
+ errorMessage = tr("Cannot write file %1:\n%2.")
+ .arg(QDir::toNativeSeparators(fileName), file.errorString());
+ }
+ } else {
+ errorMessage = tr("Cannot open file %1 for writing:\n%2.")
+ .arg(QDir::toNativeSeparators(fileName), file.errorString());
+ }
QGuiApplication::restoreOverrideCursor();
+ if (!errorMessage.isEmpty()) {
+ QMessageBox::warning(this, tr("SDI"), errorMessage);
+ return false;
+ }
+
setCurrentFile(fileName);
statusBar()->showMessage(tr("File saved"), 2000);
return true;
diff --git a/examples/widgets/painting/affine/xform.cpp b/examples/widgets/painting/affine/xform.cpp
index dc01acf453..50acf0f814 100644
--- a/examples/widgets/painting/affine/xform.cpp
+++ b/examples/widgets/painting/affine/xform.cpp
@@ -160,10 +160,7 @@ void XFormView::updateCtrlPoints(const QPolygonF &points)
ctrlPoints = points;
QLineF line(ctrlPoints.at(0), ctrlPoints.at(1));
- m_rotation = line.angle(QLineF(0, 0, 1, 0));
- if (line.dy() < 0)
- m_rotation = 360 - m_rotation;
-
+ m_rotation = 360 - QLineF(0, 0, 1, 0).angleTo(line);
if (trans.isNull())
emit rotationChanged(int(m_rotation*10));
}
@@ -263,7 +260,7 @@ void XFormView::timerEvent(QTimerEvent *e)
#if QT_CONFIG(wheelevent)
void XFormView::wheelEvent(QWheelEvent *e)
{
- m_scale += e->delta() / qreal(600);
+ m_scale += e->angleDelta().y() / qreal(600);
m_scale = qMax(qreal(0.1), qMin(qreal(4), m_scale));
emit scaleChanged(int(m_scale*1000));
}
diff --git a/examples/widgets/painting/composition/composition.cpp b/examples/widgets/painting/composition/composition.cpp
index 9bd71735a0..a220fb42fa 100644
--- a/examples/widgets/painting/composition/composition.cpp
+++ b/examples/widgets/painting/composition/composition.cpp
@@ -224,6 +224,10 @@ CompositionWidget::CompositionWidget(QWidget *parent)
setWindowTitle(tr("Composition Modes"));
}
+CompositionWidget::~CompositionWidget()
+{
+}
+
void CompositionWidget::nextMode()
{
@@ -265,6 +269,10 @@ CompositionRenderer::CompositionRenderer(QWidget *parent)
#endif
}
+CompositionRenderer::~CompositionRenderer()
+{
+}
+
QRectF rectangle_around(const QPointF &p, const QSizeF &size = QSize(250, 200))
{
QRectF rect(p, size);
@@ -371,7 +379,7 @@ void CompositionRenderer::paint(QPainter *painter)
if (size() != m_previous_size) {
m_previous_size = size();
- QPainter p(m_fbo.data());
+ QPainter p(m_fbo.get());
p.setCompositionMode(QPainter::CompositionMode_Source);
p.fillRect(QRect(QPoint(0, 0), size()), Qt::transparent);
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
@@ -382,7 +390,7 @@ void CompositionRenderer::paint(QPainter *painter)
painter->beginNativePainting();
{
- QPainter p(m_fbo.data());
+ QPainter p(m_fbo.get());
p.beginNativePainting();
m_blitter.bind();
const QRect targetRect(QPoint(0, 0), m_fbo->size());
diff --git a/examples/widgets/painting/composition/composition.h b/examples/widgets/painting/composition/composition.h
index 19150e2024..52ca7919b0 100644
--- a/examples/widgets/painting/composition/composition.h
+++ b/examples/widgets/painting/composition/composition.h
@@ -61,6 +61,8 @@
#include <QPainter>
#include <QEvent>
+#include <memory>
+
QT_BEGIN_NAMESPACE
class QPushButton;
class QRadioButton;
@@ -71,7 +73,8 @@ class CompositionWidget : public QWidget
Q_OBJECT
public:
- CompositionWidget(QWidget *parent);
+ explicit CompositionWidget(QWidget *parent = nullptr);
+ ~CompositionWidget();
public slots:
void nextMode();
@@ -117,7 +120,8 @@ class CompositionRenderer : public ArthurFrame
Q_PROPERTY(bool animation READ animationEnabled WRITE setAnimationEnabled)
public:
- CompositionRenderer(QWidget *parent);
+ explicit CompositionRenderer(QWidget *parent = nullptr);
+ ~CompositionRenderer();
void paint(QPainter *) override;
@@ -188,7 +192,7 @@ private:
int m_animationTimer;
#if QT_CONFIG(opengl)
- QScopedPointer<QFboPaintDevice> m_fbo;
+ std::unique_ptr<QFboPaintDevice> m_fbo;
int m_pbuffer_size; // width==height==size of pbuffer
uint m_base_tex;
uint m_compositing_tex;
diff --git a/examples/widgets/painting/composition/main.cpp b/examples/widgets/painting/composition/main.cpp
index 2eaeaba2c5..1ffa29dddc 100644
--- a/examples/widgets/painting/composition/main.cpp
+++ b/examples/widgets/painting/composition/main.cpp
@@ -56,13 +56,13 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
+ QScopedPointer<QStyle> arthurStyle(new ArthurStyle());
CompositionWidget compWidget(nullptr);
- QStyle *arthurStyle = new ArthurStyle();
- compWidget.setStyle(arthurStyle);
+ compWidget.setStyle(arthurStyle.data());
const QList<QWidget *> widgets = compWidget.findChildren<QWidget *>();
for (QWidget *w : widgets)
- w->setStyle(arthurStyle);
+ w->setStyle(arthurStyle.data());
compWidget.show();
return app.exec();
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/deform/pathdeform.h b/examples/widgets/painting/deform/pathdeform.h
index b7c7386e2a..af869badc9 100644
--- a/examples/widgets/painting/deform/pathdeform.h
+++ b/examples/widgets/painting/deform/pathdeform.h
@@ -54,7 +54,7 @@
#include "arthurwidgets.h"
#include <QBasicTimer>
-#include <QDateTime>
+#include <QElapsedTimer>
#include <QPainterPath>
class PathDeformRenderer : public ArthurFrame
@@ -103,7 +103,7 @@ private:
QBasicTimer m_repaintTimer;
// QBasicTimer m_fpsTimer;
// int m_fpsCounter;
- QTime m_repaintTracker;
+ QElapsedTimer m_repaintTracker;
QVector<QPainterPath> m_paths;
QVector<QPointF> m_advances;
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 7abaef771b..d62ae93a15 100644
--- a/examples/widgets/painting/gradients/gradients.cpp
+++ b/examples/widgets/painting/gradients/gradients.cpp
@@ -72,7 +72,7 @@ ShadeWidget::ShadeWidget(ShadeType type, QWidget *parent)
setPalette(pal);
} else {
- setAttribute(Qt::WA_NoBackground);
+ setAttribute(Qt::WA_OpaquePaintEvent);
}
QPolygonF points;
@@ -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;
@@ -564,14 +564,12 @@ void GradientRenderer::paint(QPainter *p)
} else {
QLineF l(pts.at(0), pts.at(1));
- qreal angle = l.angle(QLineF(0, 0, 1, 0));
- if (l.dy() > 0)
- angle = 360 - angle;
+ qreal angle = QLineF(0, 0, 1, 0).angleTo(l);
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 03e55bb2a2..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;
@@ -611,7 +629,8 @@ bool PathStrokeRenderer::event(QEvent *e)
case Qt::TouchPointPressed:
{
// find the point, move it
- QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values());
+ const auto mappedPoints = m_fingerPointMapping.values();
+ QSet<int> activePoints = QSet<int>(mappedPoints.begin(), mappedPoints.end());
int activePoint = -1;
qreal distance = -1;
const int pointsCount = m_points.size();
@@ -672,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.cpp b/examples/widgets/painting/shared/arthurstyle.cpp
index 3fc461bbd2..31be899357 100644
--- a/examples/widgets/painting/shared/arthurstyle.cpp
+++ b/examples/widgets/painting/shared/arthurstyle.cpp
@@ -457,7 +457,7 @@ void ArthurStyle::polish(QWidget *widget)
QPalette pal = widget->palette();
if (widget->isWindow()) {
- pal.setColor(QPalette::Background, QColor(241, 241, 241));
+ pal.setColor(QPalette::Window, QColor(241, 241, 241));
widget->setPalette(pal);
}
@@ -474,7 +474,7 @@ void ArthurStyle::unpolish(QWidget *widget)
void ArthurStyle::polish(QPalette &palette)
{
- palette.setColor(QPalette::Background, QColor(241, 241, 241));
+ palette.setColor(QPalette::Window, QColor(241, 241, 241));
}
QRect ArthurStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
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 bdac5de13c..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;
@@ -153,7 +153,7 @@ void ArthurFrame::paintEvent(QPaintEvent *e)
int o = 10;
- QBrush bg = palette().brush(QPalette::Background);
+ QBrush bg = palette().brush(QPalette::Window);
painter.fillRect(0, 0, o, o, bg);
painter.fillRect(width() - o, 0, o, o, bg);
painter.fillRect(0, height() - o, o, o, bg);
@@ -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 74c78088ad..2bf3963e9e 100644
--- a/examples/widgets/painting/shared/hoverpoints.cpp
+++ b/examples/widgets/painting/shared/hoverpoints.cpp
@@ -180,7 +180,8 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
case Qt::TouchPointPressed:
{
// find the point, move it
- QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values());
+ const auto mappedPoints = m_fingerPointMapping.values();
+ QSet<int> activePoints = QSet<int>(mappedPoints.begin(), mappedPoints.end());
int activePoint = -1;
qreal distance = -1;
const int pointsCount = m_points.size();
@@ -261,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/qnx/foreignwindows/collector.cpp b/examples/widgets/qnx/foreignwindows/collector.cpp
new file mode 100644
index 0000000000..4b9e774945
--- /dev/null
+++ b/examples/widgets/qnx/foreignwindows/collector.cpp
@@ -0,0 +1,176 @@
+/***************************************************************************
+**
+** Copyright (C) 2018 QNX Software Systems. All rights reserved.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+#include <QDebug>
+#include <QHBoxLayout>
+#include <QWindow>
+
+#include <algorithm>
+#include <screen/screen.h>
+
+#include "collector.h"
+
+constexpr int MANAGER_EVENT_NAME_SUGGESTION = 9999;
+
+Collector::Collector(QWidget *parent)
+ : QWidget(parent)
+{
+ QApplication::instance()->installNativeEventFilter(this);
+
+ QLayout *layout = new QHBoxLayout(this);
+ setLayout(layout);
+}
+
+Collector::~Collector()
+{
+ QApplication::instance()->removeNativeEventFilter(this);
+}
+
+bool Collector::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
+{
+ Q_UNUSED(result);
+
+ if (eventType == QByteArrayLiteral("screen_event_t"))
+ return filterQnxScreenEvent(static_cast<screen_event_t>(message));
+
+ return false;
+}
+
+bool Collector::filterQnxScreenEvent(screen_event_t event)
+{
+ int objectType = SCREEN_OBJECT_TYPE_CONTEXT;
+ screen_get_event_property_iv(event, SCREEN_PROPERTY_OBJECT_TYPE, &objectType);
+
+ if (objectType == SCREEN_OBJECT_TYPE_WINDOW)
+ return filterQnxScreenWindowEvent(event);
+
+ return false;
+}
+
+bool Collector::filterQnxScreenWindowEvent(screen_event_t event)
+{
+ int eventType = SCREEN_EVENT_NONE;
+ screen_get_event_property_iv(event, SCREEN_PROPERTY_TYPE, &eventType);
+ screen_window_t window = nullptr;
+ screen_get_event_property_pv(event,
+ SCREEN_PROPERTY_WINDOW,
+ reinterpret_cast<void **>(&window));
+
+ if (eventType == SCREEN_EVENT_CREATE)
+ return filterQnxScreenWindowCreateEvent(window, event);
+ else if (eventType == SCREEN_EVENT_CLOSE)
+ return filterQnxScreenWindowCloseEvent(window, event);
+ else if (eventType == SCREEN_EVENT_MANAGER)
+ return filterQnxScreenWindowManagerEvent(window, event);
+
+ return false;
+}
+
+bool Collector::filterQnxScreenWindowCreateEvent(screen_window_t window, screen_event_t event)
+{
+ Q_UNUSED(event);
+ WId winId = reinterpret_cast<WId>(window);
+
+ QByteArray parentGroup(256, 0);
+ screen_get_window_property_cv(window,
+ SCREEN_PROPERTY_PARENT,
+ parentGroup.length(),
+ parentGroup.data());
+ parentGroup.resize(strlen(parentGroup.constData()));
+
+ QByteArray group(256, 0);
+ screen_get_window_property_cv(reinterpret_cast<screen_window_t>(windowHandle()->winId()),
+ SCREEN_PROPERTY_GROUP,
+ group.length(),
+ group.data());
+ group.resize(strlen(group.constData()));
+
+ if (parentGroup != group)
+ return false;
+
+ Collectible collectible;
+ collectible.window = QWindow::fromWinId(winId);
+ collectible.widget = QWidget::createWindowContainer(collectible.window, this);
+ layout()->addWidget(collectible.widget);
+ m_collectibles.append(collectible);
+
+ return false;
+}
+
+bool Collector::filterQnxScreenWindowCloseEvent(screen_window_t window, screen_event_t event)
+{
+ Q_UNUSED(event);
+ WId winId = reinterpret_cast<WId>(window);
+ auto it = std::find_if(m_collectibles.begin(), m_collectibles.end(),
+ [winId] (const Collectible &collectible) {
+ return collectible.window->winId() == winId;
+ });
+ if (it != m_collectibles.end()) {
+ delete it->widget;
+ // it->window is deleted by it->widget.
+ m_collectibles.erase(it);
+ }
+
+ return false;
+}
+
+bool Collector::filterQnxScreenWindowManagerEvent(screen_window_t window, screen_event_t event)
+{
+ int managerEventType = 0;
+ screen_get_event_property_iv(event, SCREEN_PROPERTY_SUBTYPE, &managerEventType);
+
+ if (managerEventType == MANAGER_EVENT_NAME_SUGGESTION)
+ return filterQnxScreenWindowManagerNameEvent(window, event);
+
+ return false;
+}
+
+bool Collector::filterQnxScreenWindowManagerNameEvent(screen_window_t window, screen_event_t event)
+{
+ Q_UNUSED(window);
+ int dataSize = 0;
+ screen_get_event_property_iv(event, SCREEN_PROPERTY_SIZE, &dataSize);
+ if (dataSize > 0) {
+ QByteArray data(dataSize, 0);
+ screen_get_event_property_cv(event, SCREEN_PROPERTY_USER_DATA, data.size(), data.data());
+ }
+
+ return false;
+}
diff --git a/examples/widgets/qnx/foreignwindows/collector.h b/examples/widgets/qnx/foreignwindows/collector.h
new file mode 100644
index 0000000000..2b1ed499ff
--- /dev/null
+++ b/examples/widgets/qnx/foreignwindows/collector.h
@@ -0,0 +1,75 @@
+/***************************************************************************
+**
+** Copyright (C) 2018 QNX Software Systems. All rights reserved.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef COLLECTOR_H_
+#define COLLECTOR_H_
+
+#include <QAbstractNativeEventFilter>
+#include <QWidget>
+#include <QVector>
+
+#include <screen/screen.h>
+
+class Collector : public QWidget, public QAbstractNativeEventFilter
+{
+public:
+ explicit Collector(QWidget *parent = nullptr);
+ ~Collector() override;
+
+ bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
+
+private:
+ struct Collectible
+ {
+ QWindow *window;
+ QWidget *widget;
+ };
+ QVector<Collectible> m_collectibles;
+
+ bool filterQnxScreenEvent(screen_event_t event);
+ bool filterQnxScreenWindowEvent(screen_event_t event);
+ bool filterQnxScreenWindowCreateEvent(screen_window_t window, screen_event_t event);
+ bool filterQnxScreenWindowCloseEvent(screen_window_t window, screen_event_t event);
+ bool filterQnxScreenWindowManagerEvent(screen_window_t window, screen_event_t event);
+ bool filterQnxScreenWindowManagerNameEvent(screen_window_t window,
+ screen_event_t event);
+};
+
+
+#endif /* COLLECTOR_H_ */
diff --git a/examples/widgets/qnx/foreignwindows/foreignwindows.pro b/examples/widgets/qnx/foreignwindows/foreignwindows.pro
new file mode 100644
index 0000000000..09ff8633eb
--- /dev/null
+++ b/examples/widgets/qnx/foreignwindows/foreignwindows.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+
+HEADERS += collector.h
+SOURCES += main.cpp collector.cpp
+LIBS += -lscreen
+
+QT += widgets
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/widgets/qnx/foreignwindows
+INSTALLS += target
diff --git a/examples/widgets/qnx/foreignwindows/main.cpp b/examples/widgets/qnx/foreignwindows/main.cpp
new file mode 100644
index 0000000000..128e93cf88
--- /dev/null
+++ b/examples/widgets/qnx/foreignwindows/main.cpp
@@ -0,0 +1,53 @@
+/***************************************************************************
+**
+** Copyright (C) 2018 QNX Software Systems. All rights reserved.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "collector.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ Collector collector;
+ collector.resize(640, 480);
+ collector.show();
+
+ return app.exec();
+}
diff --git a/examples/widgets/richtext/textedit/example.md b/examples/widgets/richtext/textedit/example.md
new file mode 100644
index 0000000000..a16a9197b4
--- /dev/null
+++ b/examples/widgets/richtext/textedit/example.md
@@ -0,0 +1,102 @@
+# QTextEdit
+
+The QTextEdit widget is an advanced editor that supports formatted rich text.
+It can be used to display HTML and other rich document formats. Internally,
+QTextEdit uses the QTextDocument class to describe both the high-level
+structure of each document and the low-level formatting of paragraphs.
+
+If you are viewing this document in the textedit example, you can edit this
+document to explore Qt's rich text editing features. We have included some
+comments in each of the following sections to encourage you to experiment.
+
+## Font and Paragraph Styles
+
+QTextEdit supports **bold**, *italic*, &amp; ~~strikethrough~~ font styles, and
+can display <span style="font-size:10pt; font-weight:600;
+color:#00007f;">multicolored</span> text. Font families such as <span
+style="font-family:Times New Roman">Times New Roman</span> and `Courier`
+can also be used directly. *If you place the cursor in a region of styled text,
+the controls in the tool bars will change to reflect the current style.*
+
+Paragraphs can be formatted so that the text is left-aligned, right-aligned,
+centered, or fully justified.
+
+*Try changing the alignment of some text and resize the editor to see how the
+text layout changes.*
+
+## Lists
+
+Different kinds of lists can be included in rich text documents. Standard
+bullet lists can be nested, using different symbols for each level of the list:
+
+- Disc symbols are typically used for top-level list items.
+ * Circle symbols can be used to distinguish between items in lower-level
+ lists.
+ + Square symbols provide a reasonable alternative to discs and circles.
+
+Ordered lists can be created that can be used for tables of contents. Different
+characters can be used to enumerate items, and we can use both Roman and Arabic
+numerals in the same list structure:
+
+1. Introduction
+2. Qt Tools
+ 1) Qt Assistant
+ 2) Qt Designer
+ 1. Form Editor
+ 2. Component Architecture
+ 3) Qt Linguist
+
+The list will automatically be renumbered if you add or remove items. *Try
+adding new sections to the above list or removing existing item to see the
+numbers change.*
+
+Task lists can be used to track progress on projects:
+
+- [ ] This is not yet done
+- This is just a bullet point
+- [x] This is done
+
+## Images
+
+Inline images are treated like ordinary ranges of characters in the text
+editor, so they flow with the surrounding text. Images can also be selected in
+the same way as text, making it easy to cut, copy, and paste them.
+
+![logo](images/logo32.png "logo") *Try to select this image by clicking and
+dragging over it with the mouse, or use the text cursor to select it by holding
+down Shift and using the arrow keys. You can then cut or copy it, and paste it
+into different parts of this document.*
+
+## Tables
+
+QTextEdit can arrange and format tables, supporting features such as row and
+column spans, text formatting within cells, and size constraints for columns.
+
+| | Development Tools | Programming Techniques | Graphical User Interfaces |
+| ------------: | ----------------- | ---------------------- | ------------------------- |
+| 9:00 - 11:00 | Introduction to Qt |||
+| 11:00 - 13:00 | Using qmake | Object-oriented Programming | Layouts in Qt |
+| 13:00 - 15:00 | Qt Designer Tutorial | Extreme Programming | Writing Custom Styles |
+| 15:00 - 17:00 | Qt Linguist and Internationalization | &nbsp; | &nbsp; |
+
+*Try adding text to the cells in the table and experiment with the alignment of
+the paragraphs.*
+
+## Hyperlinks
+
+QTextEdit is designed to support hyperlinks between documents, and this feature
+is used extensively in
+[Qt Assistant](http://doc.qt.io/qt-5/qtassistant-index.html). Hyperlinks are
+automatically created when an HTML file is imported into an editor. Since the
+rich text framework supports hyperlinks natively, they can also be created
+programatically.
+
+## Undo and Redo
+
+Full support for undo and redo operations is built into QTextEdit and the
+underlying rich text framework. Operations on a document can be packaged
+together to make editing a more comfortable experience for the user.
+
+*Try making changes to this document and press `Ctrl+Z` to undo them. You can
+always recover the original contents of the document.*
+
diff --git a/examples/widgets/richtext/textedit/images/mac/checkbox-checked.png b/examples/widgets/richtext/textedit/images/mac/checkbox-checked.png
new file mode 100644
index 0000000000..a072d7fb5c
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/checkbox-checked.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/checkbox.png b/examples/widgets/richtext/textedit/images/mac/checkbox.png
new file mode 100644
index 0000000000..4064909712
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/checkbox.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/format-indent-less.png b/examples/widgets/richtext/textedit/images/mac/format-indent-less.png
new file mode 100644
index 0000000000..e38074e78b
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/format-indent-less.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/format-indent-more.png b/examples/widgets/richtext/textedit/images/mac/format-indent-more.png
new file mode 100644
index 0000000000..1bdeabd354
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/format-indent-more.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/checkbox-checked.png b/examples/widgets/richtext/textedit/images/win/checkbox-checked.png
new file mode 100644
index 0000000000..a072d7fb5c
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/checkbox-checked.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/checkbox.png b/examples/widgets/richtext/textedit/images/win/checkbox.png
new file mode 100644
index 0000000000..4064909712
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/checkbox.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/format-indent-less.png b/examples/widgets/richtext/textedit/images/win/format-indent-less.png
new file mode 100644
index 0000000000..e38074e78b
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/format-indent-less.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/format-indent-more.png b/examples/widgets/richtext/textedit/images/win/format-indent-more.png
new file mode 100644
index 0000000000..1bdeabd354
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/format-indent-more.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/main.cpp b/examples/widgets/richtext/textedit/main.cpp
index aef186aa77..256d183811 100644
--- a/examples/widgets/richtext/textedit/main.cpp
+++ b/examples/widgets/richtext/textedit/main.cpp
@@ -51,9 +51,9 @@
#include "textedit.h"
#include <QApplication>
-#include <QDesktopWidget>
#include <QCommandLineParser>
#include <QCommandLineOption>
+#include <QScreen>
int main(int argc, char *argv[])
{
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
TextEdit mw;
- const QRect availableGeometry = QApplication::desktop()->availableGeometry(&mw);
+ const QRect availableGeometry = mw.screen()->availableGeometry();
mw.resize(availableGeometry.width() / 2, (availableGeometry.height() * 2) / 3);
mw.move((availableGeometry.width() - mw.width()) / 2,
(availableGeometry.height() - mw.height()) / 2);
diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp
index 00ea0325dc..85fb83ab89 100644
--- a/examples/widgets/richtext/textedit/textedit.cpp
+++ b/examples/widgets/richtext/textedit/textedit.cpp
@@ -71,6 +71,7 @@
#include <QCloseEvent>
#include <QMessageBox>
#include <QMimeData>
+#include <QMimeDatabase>
#if defined(QT_PRINTSUPPORT_LIB)
#include <QtPrintSupport/qtprintsupportglobal.h>
#if QT_CONFIG(printer)
@@ -316,6 +317,14 @@ void TextEdit::setupTextActions()
actionAlignJustify->setShortcut(Qt::CTRL + Qt::Key_J);
actionAlignJustify->setCheckable(true);
actionAlignJustify->setPriority(QAction::LowPriority);
+ const QIcon indentMoreIcon = QIcon::fromTheme("format-indent-more", QIcon(rsrcPath + "/format-indent-more.png"));
+ actionIndentMore = menu->addAction(indentMoreIcon, tr("&Indent"), this, &TextEdit::indent);
+ actionIndentMore->setShortcut(Qt::CTRL + Qt::Key_BracketRight);
+ actionIndentMore->setPriority(QAction::LowPriority);
+ const QIcon indentLessIcon = QIcon::fromTheme("format-indent-less", QIcon(rsrcPath + "/format-indent-less.png"));
+ actionIndentLess = menu->addAction(indentLessIcon, tr("&Unindent"), this, &TextEdit::unindent);
+ actionIndentLess->setShortcut(Qt::CTRL + Qt::Key_BracketLeft);
+ actionIndentLess->setPriority(QAction::LowPriority);
// Make sure the alignLeft is always left of the alignRight
QActionGroup *alignGroup = new QActionGroup(this);
@@ -334,6 +343,10 @@ void TextEdit::setupTextActions()
tb->addActions(alignGroup->actions());
menu->addActions(alignGroup->actions());
+ tb->addAction(actionIndentMore);
+ tb->addAction(actionIndentLess);
+ menu->addAction(actionIndentMore);
+ menu->addAction(actionIndentLess);
menu->addSeparator();
@@ -342,6 +355,15 @@ void TextEdit::setupTextActions()
actionTextColor = menu->addAction(pix, tr("&Color..."), this, &TextEdit::textColor);
tb->addAction(actionTextColor);
+ menu->addSeparator();
+
+ const QIcon checkboxIcon = QIcon::fromTheme("status-checkbox-checked", QIcon(rsrcPath + "/checkbox-checked.png"));
+ actionToggleCheckState = menu->addAction(checkboxIcon, tr("Chec&ked"), this, &TextEdit::setChecked);
+ actionToggleCheckState->setShortcut(Qt::CTRL + Qt::Key_K);
+ actionToggleCheckState->setCheckable(true);
+ actionToggleCheckState->setPriority(QAction::LowPriority);
+ tb->addAction(actionToggleCheckState);
+
tb = addToolBar(tr("Format Actions"));
tb->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
addToolBarBreak(Qt::TopToolBarArea);
@@ -353,6 +375,8 @@ void TextEdit::setupTextActions()
comboStyle->addItem("Bullet List (Disc)");
comboStyle->addItem("Bullet List (Circle)");
comboStyle->addItem("Bullet List (Square)");
+ comboStyle->addItem("Task List (Unchecked)");
+ comboStyle->addItem("Task List (Checked)");
comboStyle->addItem("Ordered List (Decimal)");
comboStyle->addItem("Ordered List (Alpha lower)");
comboStyle->addItem("Ordered List (Alpha upper)");
@@ -369,7 +393,7 @@ void TextEdit::setupTextActions()
comboFont = new QFontComboBox(tb);
tb->addWidget(comboFont);
- connect(comboFont, QOverload<const QString &>::of(&QComboBox::activated), this, &TextEdit::textFamily);
+ connect(comboFont, &QComboBox::textActivated, this, &TextEdit::textFamily);
comboSize = new QComboBox(tb);
comboSize->setObjectName("comboSize");
@@ -381,7 +405,7 @@ void TextEdit::setupTextActions()
comboSize->addItem(QString::number(size));
comboSize->setCurrentIndex(standardSizes.indexOf(QApplication::font().pointSize()));
- connect(comboSize, QOverload<const QString &>::of(&QComboBox::activated), this, &TextEdit::textSize);
+ connect(comboSize, &QComboBox::textActivated, this, &TextEdit::textSize);
}
bool TextEdit::load(const QString &f)
@@ -395,11 +419,18 @@ bool TextEdit::load(const QString &f)
QByteArray data = file.readAll();
QTextCodec *codec = Qt::codecForHtml(data);
QString str = codec->toUnicode(data);
+ QUrl baseUrl = (f.front() == QLatin1Char(':') ? QUrl(f) : QUrl::fromLocalFile(f)).adjusted(QUrl::RemoveFilename);
+ textEdit->document()->setBaseUrl(baseUrl);
if (Qt::mightBeRichText(str)) {
textEdit->setHtml(str);
} else {
- str = QString::fromLocal8Bit(data);
- textEdit->setPlainText(str);
+#if QT_CONFIG(textmarkdownreader)
+ QMimeDatabase db;
+ if (db.mimeTypeForFileNameAndData(f, data).name() == QLatin1String("text/markdown"))
+ textEdit->setMarkdown(str);
+ else
+#endif
+ textEdit->setPlainText(QString::fromLocal8Bit(data));
}
setCurrentFileName(f);
@@ -451,7 +482,15 @@ void TextEdit::fileOpen()
QFileDialog fileDialog(this, tr("Open File..."));
fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
fileDialog.setFileMode(QFileDialog::ExistingFile);
- fileDialog.setMimeTypeFilters(QStringList() << "text/html" << "text/plain");
+ fileDialog.setMimeTypeFilters(QStringList()
+#if QT_CONFIG(texthtmlparser)
+ << "text/html"
+#endif
+#if QT_CONFIG(textmarkdownreader)
+
+ << "text/markdown"
+#endif
+ << "text/plain");
if (fileDialog.exec() != QDialog::Accepted)
return;
const QString fn = fileDialog.selectedFiles().first();
@@ -485,9 +524,18 @@ bool TextEdit::fileSaveAs()
QFileDialog fileDialog(this, tr("Save as..."));
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
QStringList mimeTypes;
- mimeTypes << "application/vnd.oasis.opendocument.text" << "text/html" << "text/plain";
+ mimeTypes << "text/plain"
+#if QT_CONFIG(textodfwriter)
+ << "application/vnd.oasis.opendocument.text"
+#endif
+#if QT_CONFIG(textmarkdownwriter)
+ << "text/markdown"
+#endif
+ << "text/html";
fileDialog.setMimeTypeFilters(mimeTypes);
+#if QT_CONFIG(textodfwriter)
fileDialog.setDefaultSuffix("odt");
+#endif
if (fileDialog.exec() != QDialog::Accepted)
return false;
const QString fn = fileDialog.selectedFiles().first();
@@ -592,6 +640,7 @@ void TextEdit::textStyle(int styleIndex)
{
QTextCursor cursor = textEdit->textCursor();
QTextListFormat::Style style = QTextListFormat::ListStyleUndefined;
+ QTextBlockFormat::MarkerType marker = QTextBlockFormat::MarkerType::NoMarker;
switch (styleIndex) {
case 1:
@@ -604,18 +653,32 @@ void TextEdit::textStyle(int styleIndex)
style = QTextListFormat::ListSquare;
break;
case 4:
- style = QTextListFormat::ListDecimal;
+ if (cursor.currentList())
+ style = cursor.currentList()->format().style();
+ else
+ style = QTextListFormat::ListDisc;
+ marker = QTextBlockFormat::MarkerType::Unchecked;
break;
case 5:
- style = QTextListFormat::ListLowerAlpha;
+ if (cursor.currentList())
+ style = cursor.currentList()->format().style();
+ else
+ style = QTextListFormat::ListDisc;
+ marker = QTextBlockFormat::MarkerType::Checked;
break;
case 6:
- style = QTextListFormat::ListUpperAlpha;
+ style = QTextListFormat::ListDecimal;
break;
case 7:
- style = QTextListFormat::ListLowerRoman;
+ style = QTextListFormat::ListLowerAlpha;
break;
case 8:
+ style = QTextListFormat::ListUpperAlpha;
+ break;
+ case 9:
+ style = QTextListFormat::ListLowerRoman;
+ break;
+ case 10:
style = QTextListFormat::ListUpperRoman;
break;
default:
@@ -628,7 +691,7 @@ void TextEdit::textStyle(int styleIndex)
if (style == QTextListFormat::ListStyleUndefined) {
blockFmt.setObjectIndex(-1);
- int headingLevel = styleIndex >= 9 ? styleIndex - 9 + 1 : 0; // H1 to H6, or Standard
+ int headingLevel = styleIndex >= 11 ? styleIndex - 11 + 1 : 0; // H1 to H6, or Standard
blockFmt.setHeadingLevel(headingLevel);
cursor.setBlockFormat(blockFmt);
@@ -640,6 +703,8 @@ void TextEdit::textStyle(int styleIndex)
cursor.mergeCharFormat(fmt);
textEdit->mergeCurrentCharFormat(fmt);
} else {
+ blockFmt.setMarker(marker);
+ cursor.setBlockFormat(blockFmt);
QTextListFormat listFmt;
if (cursor.currentList()) {
listFmt = cursor.currentList()->format();
@@ -678,6 +743,45 @@ void TextEdit::textAlign(QAction *a)
textEdit->setAlignment(Qt::AlignJustify);
}
+void TextEdit::setChecked(bool checked)
+{
+ textStyle(checked ? 5 : 4);
+}
+
+void TextEdit::indent()
+{
+ modifyIndentation(1);
+}
+
+void TextEdit::unindent()
+{
+ modifyIndentation(-1);
+}
+
+void TextEdit::modifyIndentation(int amount)
+{
+ QTextCursor cursor = textEdit->textCursor();
+ cursor.beginEditBlock();
+ if (cursor.currentList()) {
+ QTextListFormat listFmt = cursor.currentList()->format();
+ // See whether the line above is the list we want to move this item into,
+ // or whether we need a new list.
+ QTextCursor above(cursor);
+ above.movePosition(QTextCursor::Up);
+ if (above.currentList() && listFmt.indent() + amount == above.currentList()->format().indent()) {
+ above.currentList()->add(cursor.block());
+ } else {
+ listFmt.setIndent(listFmt.indent() + amount);
+ cursor.createList(listFmt);
+ }
+ } else {
+ QTextBlockFormat blockFmt = cursor.blockFormat();
+ blockFmt.setIndent(blockFmt.indent() + amount);
+ cursor.setBlockFormat(blockFmt);
+ }
+ cursor.endEditBlock();
+}
+
void TextEdit::currentCharFormatChanged(const QTextCharFormat &format)
{
fontChanged(format.font());
@@ -700,27 +804,40 @@ void TextEdit::cursorPositionChanged()
comboStyle->setCurrentIndex(3);
break;
case QTextListFormat::ListDecimal:
- comboStyle->setCurrentIndex(4);
+ comboStyle->setCurrentIndex(6);
break;
case QTextListFormat::ListLowerAlpha:
- comboStyle->setCurrentIndex(5);
+ comboStyle->setCurrentIndex(7);
break;
case QTextListFormat::ListUpperAlpha:
- comboStyle->setCurrentIndex(6);
+ comboStyle->setCurrentIndex(8);
break;
case QTextListFormat::ListLowerRoman:
- comboStyle->setCurrentIndex(7);
+ comboStyle->setCurrentIndex(9);
break;
case QTextListFormat::ListUpperRoman:
- comboStyle->setCurrentIndex(8);
+ comboStyle->setCurrentIndex(10);
break;
default:
comboStyle->setCurrentIndex(-1);
break;
}
+ switch (textEdit->textCursor().block().blockFormat().marker()) {
+ case QTextBlockFormat::MarkerType::NoMarker:
+ actionToggleCheckState->setChecked(false);
+ break;
+ case QTextBlockFormat::MarkerType::Unchecked:
+ comboStyle->setCurrentIndex(4);
+ actionToggleCheckState->setChecked(false);
+ break;
+ case QTextBlockFormat::MarkerType::Checked:
+ comboStyle->setCurrentIndex(5);
+ actionToggleCheckState->setChecked(true);
+ break;
+ }
} else {
int headingLevel = textEdit->textCursor().blockFormat().headingLevel();
- comboStyle->setCurrentIndex(headingLevel ? headingLevel + 8 : 0);
+ comboStyle->setCurrentIndex(headingLevel ? headingLevel + 10 : 0);
}
}
diff --git a/examples/widgets/richtext/textedit/textedit.h b/examples/widgets/richtext/textedit/textedit.h
index ae0b13a4cc..9e50166c6f 100644
--- a/examples/widgets/richtext/textedit/textedit.h
+++ b/examples/widgets/richtext/textedit/textedit.h
@@ -96,6 +96,9 @@ private slots:
void textStyle(int styleIndex);
void textColor();
void textAlign(QAction *a);
+ void setChecked(bool checked);
+ void indent();
+ void unindent();
void currentCharFormatChanged(const QTextCharFormat &format);
void cursorPositionChanged();
@@ -110,6 +113,7 @@ private:
void setupTextActions();
bool maybeSave();
void setCurrentFileName(const QString &fileName);
+ void modifyIndentation(int amount);
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
void fontChanged(const QFont &f);
@@ -125,6 +129,9 @@ private:
QAction *actionAlignCenter;
QAction *actionAlignRight;
QAction *actionAlignJustify;
+ QAction *actionIndentLess;
+ QAction *actionIndentMore;
+ QAction *actionToggleCheckState;
QAction *actionUndo;
QAction *actionRedo;
#ifndef QT_NO_CLIPBOARD
diff --git a/examples/widgets/richtext/textedit/textedit.qrc b/examples/widgets/richtext/textedit/textedit.qrc
index 7d6efd7d67..1641acc207 100644
--- a/examples/widgets/richtext/textedit/textedit.qrc
+++ b/examples/widgets/richtext/textedit/textedit.qrc
@@ -1,6 +1,8 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/">
<file>images/logo32.png</file>
+ <file>images/mac/checkbox.png</file>
+ <file>images/mac/checkbox-checked.png</file>
<file>images/mac/editcopy.png</file>
<file>images/mac/editcut.png</file>
<file>images/mac/editpaste.png</file>
@@ -11,6 +13,8 @@
<file>images/mac/fileopen.png</file>
<file>images/mac/fileprint.png</file>
<file>images/mac/filesave.png</file>
+ <file>images/mac/format-indent-less.png</file>
+ <file>images/mac/format-indent-more.png</file>
<file>images/mac/textbold.png</file>
<file>images/mac/textcenter.png</file>
<file>images/mac/textitalic.png</file>
@@ -20,6 +24,8 @@
<file>images/mac/textunder.png</file>
<file>images/mac/zoomin.png</file>
<file>images/mac/zoomout.png</file>
+ <file>images/win/checkbox.png</file>
+ <file>images/win/checkbox-checked.png</file>
<file>images/win/editcopy.png</file>
<file>images/win/editcut.png</file>
<file>images/win/editpaste.png</file>
@@ -30,6 +36,8 @@
<file>images/win/fileopen.png</file>
<file>images/win/fileprint.png</file>
<file>images/win/filesave.png</file>
+ <file>images/win/format-indent-less.png</file>
+ <file>images/win/format-indent-more.png</file>
<file>images/win/textbold.png</file>
<file>images/win/textcenter.png</file>
<file>images/win/textitalic.png</file>
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 2d25822828..e6cbdcae29 100644
--- a/examples/widgets/statemachine/factorial/main.cpp
+++ b/examples/widgets/statemachine/factorial/main.cpp
@@ -49,7 +49,6 @@
****************************************************************************/
#include <QtCore>
-#include <stdio.h>
//! [0]
class Factorial : public QObject
@@ -58,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
{
@@ -90,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]
@@ -143,7 +139,7 @@ public:
void onTransition(QEvent *) override
{
- fprintf(stdout, "%d\n", m_fact->property("fac").toInt());
+ qInfo() << m_fact->property("fac").toInt();
}
private:
diff --git a/examples/widgets/statemachine/trafficlight/main.cpp b/examples/widgets/statemachine/trafficlight/main.cpp
index 1a7050c28d..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);
@@ -105,7 +111,7 @@ public:
m_green = new LightWidget(Qt::green);
vbox->addWidget(m_green);
QPalette pal = palette();
- pal.setColor(QPalette::Background, Qt::black);
+ pal.setColor(QPalette::Window, Qt::black);
setPalette(pal);
setAutoFillBackground(true);
}
@@ -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/encodingdialog.cpp b/examples/widgets/tools/codecs/encodingdialog.cpp
index ca4b56db9e..aa57d47dc7 100644
--- a/examples/widgets/tools/codecs/encodingdialog.cpp
+++ b/examples/widgets/tools/codecs/encodingdialog.cpp
@@ -248,7 +248,7 @@ static const char *encodingToolTips[]
{
QT_TRANSLATE_NOOP("EncodingDialog", "Unicode points for use with any encoding (C++, Python)"),
QT_TRANSLATE_NOOP("EncodingDialog", "QString::fromUtf8()"),
- QT_TRANSLATE_NOOP("EncodingDialog", "QStringViewLiteral(), wchar_t on Windows"),
+ QT_TRANSLATE_NOOP("EncodingDialog", "wchar_t on Windows, char16_t everywhere"),
QT_TRANSLATE_NOOP("EncodingDialog", "wchar_t on Unix (Ucs4)"),
QT_TRANSLATE_NOOP("EncodingDialog", "QLatin1String")
};
diff --git a/examples/widgets/tools/codecs/mainwindow.cpp b/examples/widgets/tools/codecs/mainwindow.cpp
index 53db9fe61f..dc72fa73b7 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 <QFileDialog>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QPlainTextEdit>
+#include <QRegularExpression>
+#include <QScreen>
+#include <QTextCodec>
+#include <QTextStream>
+
MainWindow::MainWindow()
{
textEdit = new QPlainTextEdit;
@@ -69,7 +78,7 @@ MainWindow::MainWindow()
setWindowTitle(tr("Codecs"));
- const QRect screenGeometry = QApplication::desktop()->screenGeometry(this);
+ const QRect screenGeometry = screen()->geometry();
resize(screenGeometry.width() / 2, screenGeometry.height() * 2 / 3);
}
@@ -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()
@@ -206,7 +216,7 @@ void MainWindow::encodingDialog()
{
if (!m_encodingDialog) {
m_encodingDialog = new EncodingDialog(this);
- const QRect screenGeometry = QApplication::desktop()->screenGeometry(this);
+ const QRect screenGeometry = screen()->geometry();
m_encodingDialog->setMinimumWidth(screenGeometry.width() / 4);
}
m_encodingDialog->show();
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..f48651335a 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 <QDialogButtonBox>
+#include <QGridLayout>
+#include <QLabel>
+#include <QPlainTextEdit>
+#include <QPushButton>
+#include <QScreen>
+#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";
@@ -175,11 +183,11 @@ PreviewForm::PreviewForm(QWidget *parent)
mainLayout->addWidget(statusLabel, 2, 0, 1, 2);
mainLayout->addWidget(buttonBox, 3, 0, 1, 2);
- const QRect screenGeometry = QApplication::desktop()->screenGeometry(this);
+ const QRect screenGeometry = screen()->geometry();
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 f07d0ddee3..2ce3471873 100644
--- a/examples/widgets/tools/i18n/languagechooser.cpp
+++ b/examples/widgets/tools/i18n/languagechooser.cpp
@@ -48,40 +48,39 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "languagechooser.h"
#include "mainwindow.h"
-#if 0 // Used to be included in Qt4 for Q_WS_MAC
-QT_BEGIN_NAMESPACE
-extern void qt_mac_set_menubar_merge(bool merge);
-QT_END_NAMESPACE
-#endif
+#include <QCoreApplication>
+#include <QCheckBox>
+#include <QDialogButtonBox>
+#include <QDir>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QPushButton>
+#include <QTranslator>
-LanguageChooser::LanguageChooser(const QString& defaultLang, QWidget *parent)
+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",
@@ -95,14 +94,10 @@ LanguageChooser::LanguageChooser(const QString& defaultLang, QWidget *parent)
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
-#if 0 // Used to be included in Qt4 for Q_WS_MAC
- qt_mac_set_menubar_merge(false);
-#endif
-
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_";
@@ -120,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;
@@ -163,11 +158,8 @@ QStringList LanguageChooser::findQmFiles()
QDir dir(":/translations");
QStringList fileNames = dir.entryList(QStringList("*.qm"), QDir::Files,
QDir::Name);
- QMutableStringListIterator i(fileNames);
- while (i.hasNext()) {
- i.next();
- i.setValue(dir.filePath(i.value()));
- }
+ for (QString &fileName : fileNames)
+ fileName = dir.filePath(fileName);
return fileNames;
}
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/interfaces.h b/examples/widgets/tools/plugandpaint/app/interfaces.h
index a1e91e13ff..705e578809 100644
--- a/examples/widgets/tools/plugandpaint/app/interfaces.h
+++ b/examples/widgets/tools/plugandpaint/app/interfaces.h
@@ -68,7 +68,7 @@ QT_END_NAMESPACE
class BrushInterface
{
public:
- virtual ~BrushInterface() {}
+ virtual ~BrushInterface() = default;
virtual QStringList brushes() const = 0;
virtual QRect mousePress(const QString &brush, QPainter &painter,
@@ -84,7 +84,7 @@ public:
class ShapeInterface
{
public:
- virtual ~ShapeInterface() {}
+ virtual ~ShapeInterface() = default;
virtual QStringList shapes() const = 0;
virtual QPainterPath generateShape(const QString &shape,
@@ -96,7 +96,7 @@ public:
class FilterInterface
{
public:
- virtual ~FilterInterface() {}
+ virtual ~FilterInterface() = default;
virtual QStringList filters() const = 0;
virtual QImage filterImage(const QString &filter, const QImage &image,
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 4295e04cc0..92b8ea4777 100644
--- a/examples/widgets/tools/plugandpaint/app/paintarea.cpp
+++ b/examples/widgets/tools/plugandpaint/app/paintarea.cpp
@@ -49,17 +49,16 @@
****************************************************************************/
-#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_NoBackground);
+ setAttribute(Qt::WA_OpaquePaintEvent);
theImage.fill(qRgb(255, 255, 255));
}
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..ccca16ffcd 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 <QFileDialog>
+#include <QInputDialog>
+#include <QLineEdit>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QScreen>
+#include <QStandardPaths>
+#include <QStatusBar>
+
+MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
+ , settingsTree(new SettingsTree)
{
setCentralWidget(settingsTree);
@@ -66,7 +74,7 @@ MainWindow::MainWindow()
fallbacksAct->setChecked(true);
setWindowTitle(QCoreApplication::applicationName());
- const QRect availableGeometry = QApplication::desktop()->availableGeometry(this);
+ const QRect availableGeometry = screen()->availableGeometry();
adjustSize();
move((availableGeometry.width() - width()) / 2, (availableGeometry.height() - height()) / 2);
}
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..49d299bf72 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 <QHeaderView>
+#include <QScreen>
+#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;
@@ -97,7 +93,7 @@ void SettingsTree::setSettingsObject(const SettingsPtr &newSettings)
QSize SettingsTree::sizeHint() const
{
- const QRect availableGeometry = QApplication::desktop()->availableGeometry(this);
+ const QRect availableGeometry = screen()->availableGeometry();
return QSize(availableGeometry.width() * 2 / 3, availableGeometry.height() * 2 / 3);
}
@@ -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 e84ded5afb..b0f9705c21 100644
--- a/examples/widgets/widgets/charactermap/mainwindow.cpp
+++ b/examples/widgets/widgets/charactermap/mainwindow.cpp
@@ -48,13 +48,28 @@
**
****************************************************************************/
-#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 <QScreen>
+#include <QScrollArea>
+#include <QStatusBar>
+#include <QTextStream>
+//! [0]
Q_DECLARE_METATYPE(QFontComboBox::FontFilter)
MainWindow::MainWindow(QWidget *parent)
@@ -114,9 +129,9 @@ MainWindow::MainWindow(QWidget *parent)
this, &MainWindow::findSizes);
connect(fontCombo, &QFontComboBox::currentFontChanged,
characterWidget, &CharacterWidget::updateFont);
- connect(sizeCombo, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
+ connect(sizeCombo, &QComboBox::currentTextChanged,
characterWidget, &CharacterWidget::updateSize);
- connect(styleCombo, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
+ connect(styleCombo, &QComboBox::currentTextChanged,
characterWidget, &CharacterWidget::updateStyle);
//! [4] //! [5]
connect(characterWidget, &CharacterWidget::characterSelected,
@@ -288,7 +303,7 @@ QString FontInfoDialog::text() const
void MainWindow::showInfo()
{
- const QRect screenGeometry = QApplication::desktop()->screenGeometry(this);
+ const QRect screenGeometry = screen()->geometry();
FontInfoDialog *dialog = new FontInfoDialog(this);
dialog->setWindowTitle(tr("Fonts"));
dialog->setAttribute(Qt::WA_DeleteOnClose);
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 1a2f514ba8..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)
@@ -79,8 +80,6 @@ IconPreviewArea::IconPreviewArea(QWidget *parent)
}
//! [0]
-#ifdef Q_COMPILER_INITIALIZER_LISTS
-
//! [42]
QVector<QIcon::Mode> IconPreviewArea::iconModes()
{
@@ -107,44 +106,6 @@ QStringList IconPreviewArea::iconStateNames()
}
//! [42]
-#else // Q_COMPILER_INITIALIZER_LISTS
-
-//! [43]
-QVector<QIcon::Mode> IconPreviewArea::iconModes()
-{
- static QVector<QIcon::Mode> result;
- if (result.isEmpty())
- result << QIcon::Normal << QIcon::Active << QIcon::Disabled << QIcon::Selected;
- return result;
-}
-//! [43]
-
-QVector<QIcon::State> IconPreviewArea::iconStates()
-{
- static QVector<QIcon::State> result;
- if (result.isEmpty())
- result << QIcon::Off << QIcon::On;
- return result;
-}
-
-QStringList IconPreviewArea::iconModeNames()
-{
- static QStringList result;
- if (result.isEmpty())
- result << tr("Normal") << tr("Active") << tr("Disabled") << tr("Selected");
- return result;
-}
-
-QStringList IconPreviewArea::iconStateNames()
-{
- static QStringList result;
- if (result.isEmpty())
- result << tr("Off") << tr("On");
- return result;
-}
-
-#endif // !Q_COMPILER_INITIALIZER_LISTS
-
//! [1]
void IconPreviewArea::setIcon(const QIcon &icon)
{
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/main.cpp b/examples/widgets/widgets/icons/main.cpp
index a045ea765a..632795c18c 100644
--- a/examples/widgets/widgets/icons/main.cpp
+++ b/examples/widgets/widgets/icons/main.cpp
@@ -50,7 +50,7 @@
#include <QApplication>
#include <QCommandLineParser>
-#include <QDesktopWidget>
+#include <QScreen>
#include "mainwindow.h"
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
if (!commandLineParser.positionalArguments().isEmpty())
mainWin.loadImages(commandLineParser.positionalArguments());
- const QRect availableGeometry = QApplication::desktop()->availableGeometry(&mainWin);
+ const QRect availableGeometry = mainWin.screen()->availableGeometry();
mainWin.resize(availableGeometry.width() / 2, availableGeometry.height() * 2 / 3);
mainWin.move((availableGeometry.width() - mainWin.width()) / 2, (availableGeometry.height() - mainWin.height()) / 2);
diff --git a/examples/widgets/widgets/icons/mainwindow.cpp b/examples/widgets/widgets/icons/mainwindow.cpp
index 0cf11c978d..f342c18c4c 100644
--- a/examples/widgets/widgets/icons/mainwindow.cpp
+++ b/examples/widgets/widgets/icons/mainwindow.cpp
@@ -48,12 +48,29 @@
**
****************************************************************************/
-#include <QtWidgets>
-
+#include "mainwindow.h"
#include "iconpreviewarea.h"
#include "iconsizespinbox.h"
#include "imagedelegate.h"
-#include "mainwindow.h"
+
+#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 };
@@ -514,8 +531,8 @@ void MainWindow::checkCurrentStyle()
const QList<QAction *> actions = styleActionGroup->actions();
for (QAction *action : actions) {
const QString styleName = action->data().toString();
- QScopedPointer<QStyle> candidate(QStyleFactory::create(styleName));
- Q_ASSERT(!candidate.isNull());
+ const std::unique_ptr<QStyle> candidate{QStyleFactory::create(styleName)};
+ Q_ASSERT(candidate);
if (candidate->metaObject()->className()
== QApplication::style()->metaObject()->className()) {
action->trigger();
diff --git a/examples/widgets/widgets/imageviewer/imageviewer.cpp b/examples/widgets/widgets/imageviewer/imageviewer.cpp
index fed551dade..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);
@@ -106,6 +123,8 @@ bool ImageViewer::loadFile(const QString &fileName)
void ImageViewer::setImage(const QImage &newImage)
{
image = newImage;
+ if (image.colorSpace().isValid())
+ image.convertToColorSpace(QColorSpace::SRgb);
imageLabel->setPixmap(QPixmap::fromImage(image));
//! [4]
scaleFactor = 1.0;
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/mousebuttons/buttontester.cpp b/examples/widgets/widgets/mousebuttons/buttontester.cpp
index 6653221698..88dbbeda45 100644
--- a/examples/widgets/widgets/mousebuttons/buttontester.cpp
+++ b/examples/widgets/widgets/mousebuttons/buttontester.cpp
@@ -93,15 +93,16 @@ void ButtonTester::mouseDoubleClickEvent(QMouseEvent *e)
void ButtonTester::wheelEvent (QWheelEvent *e)
{
QString result;
- if (e->delta() > 0) {
-
- if (e->orientation() == Qt::Vertical) {
+ const bool vertical = qAbs(e->angleDelta().y()) >= qAbs(e->angleDelta().x());
+ const int delta = vertical ? e->angleDelta().y() : e->angleDelta().x();
+ if (delta > 0) {
+ if (vertical) {
result = "Mouse Wheel Event: UP";
} else {
result = "Mouse Wheel Event: LEFT";
}
- } else if (e->delta() < 0) {
- if (e->orientation() == Qt::Vertical) {
+ } else if (delta < 0) {
+ if (vertical) {
result = "Mouse Wheel Event: DOWN";
} else {
result = "Mouse Wheel Event: RIGHT";
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 fd7c5b527e..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)
@@ -176,7 +182,7 @@ void Window::createDateTimeEdits()
formatComboBox->addItem("hh:mm ap");
//! [9] //! [10]
- connect(formatComboBox, QOverload<const QString &>::of(&QComboBox::activated),
+ connect(formatComboBox, &QComboBox::textActivated,
this, &Window::setFormatString);
//! [10]
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 f0a0336a94..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)
@@ -79,7 +96,7 @@ WidgetGallery::WidgetGallery(QWidget *parent)
//! [0]
//! [1]
- connect(styleComboBox, QOverload<const QString &>::of(&QComboBox::activated),
+ connect(styleComboBox, &QComboBox::textActivated,
//! [1] //! [2]
this, &WidgetGallery::changeStyle);
connect(useStylePaletteCheckBox, &QCheckBox::toggled,
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..59ca608cef 100644
--- a/examples/widgets/widgets/tablet/tabletcanvas.cpp
+++ b/examples/widgets/widgets/tablet/tabletcanvas.cpp
@@ -48,21 +48,17 @@
**
****************************************************************************/
-#include <QtWidgets>
-#include <math.h>
-
#include "tabletcanvas.h"
+#include <QCoreApplication>
+#include <QPainter>
+#include <QtMath>
+#include <cstdlib>
+
//! [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 +134,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 +204,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 +215,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 +257,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 +285,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);