summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-09-17 08:32:43 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-09-17 10:53:47 +0200
commit448ced2cba6bc5f72fed481c9f8b8ad74de5a9b5 (patch)
tree668370fb9a2eec50000e371125136921ef4518ab
parentFusion: reduce width of menu items (diff)
parentMerge remote-tracking branch 'origin/5.15' into dev (diff)
downloadqtbase-448ced2cba6bc5f72fed481c9f8b8ad74de5a9b5.tar.xz
qtbase-448ced2cba6bc5f72fed481c9f8b8ad74de5a9b5.zip
Merge "Merge remote-tracking branch 'origin/5.15' into dev"
-rw-r--r--configure.json27
-rw-r--r--configure.pri21
-rw-r--r--dist/changes-5.12.5109
-rw-r--r--dist/changes-5.13.1141
-rw-r--r--doc/doc.pro4
-rw-r--r--doc/global/externalsites/qtcreator.qdoc48
-rw-r--r--examples/widgets/doc/src/collidingmice-example.qdoc3
-rw-r--r--examples/widgets/doc/src/diagramscene.qdoc4
-rw-r--r--examples/widgets/graphicsview/anchorlayout/main.cpp2
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.cpp31
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h9
-rw-r--r--examples/widgets/graphicsview/basicgraphicslayouts/window.h6
-rw-r--r--examples/widgets/graphicsview/boxes/glbuffers.cpp23
-rw-r--r--examples/widgets/graphicsview/boxes/glbuffers.h37
-rw-r--r--examples/widgets/graphicsview/boxes/gltrianglemesh.h3
-rw-r--r--examples/widgets/graphicsview/boxes/main.cpp12
-rw-r--r--examples/widgets/graphicsview/boxes/qtbox.cpp39
-rw-r--r--examples/widgets/graphicsview/boxes/qtbox.h11
-rw-r--r--examples/widgets/graphicsview/boxes/roundedbox.h12
-rw-r--r--examples/widgets/graphicsview/boxes/scene.cpp78
-rw-r--r--examples/widgets/graphicsview/boxes/scene.h23
-rw-r--r--examples/widgets/graphicsview/boxes/trackball.cpp17
-rw-r--r--examples/widgets/graphicsview/boxes/trackball.h25
-rw-r--r--examples/widgets/graphicsview/chip/chip.cpp4
-rw-r--r--examples/widgets/graphicsview/chip/mainwindow.cpp8
-rw-r--r--examples/widgets/graphicsview/chip/mainwindow.h2
-rw-r--r--examples/widgets/graphicsview/chip/view.cpp2
-rw-r--r--examples/widgets/graphicsview/chip/view.h2
-rw-r--r--examples/widgets/graphicsview/collidingmice/main.cpp5
-rw-r--r--examples/widgets/graphicsview/collidingmice/mouse.cpp9
-rw-r--r--examples/widgets/graphicsview/collidingmice/mouse.h6
-rw-r--r--examples/widgets/graphicsview/diagramscene/arrow.cpp12
-rw-r--r--examples/widgets/graphicsview/diagramscene/arrow.h18
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramitem.cpp18
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramitem.h17
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramscene.cpp12
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramscene.h2
-rw-r--r--examples/widgets/graphicsview/diagramscene/diagramtextitem.h6
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/coloritem.cpp14
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/main.cpp13
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/robot.cpp15
-rw-r--r--examples/widgets/graphicsview/dragdroprobot/robot.h22
-rw-r--r--examples/widgets/graphicsview/elasticnodes/edge.cpp8
-rw-r--r--examples/widgets/graphicsview/elasticnodes/edge.h2
-rw-r--r--examples/widgets/graphicsview/elasticnodes/graphwidget.cpp6
-rw-r--r--examples/widgets/graphicsview/elasticnodes/graphwidget.h4
-rw-r--r--examples/widgets/graphicsview/elasticnodes/node.cpp2
-rw-r--r--examples/widgets/graphicsview/elasticnodes/node.h9
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp11
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/customproxy.h6
-rw-r--r--examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h2
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.cpp19
-rw-r--r--examples/widgets/graphicsview/flowlayout/flowlayout.h6
-rw-r--r--examples/widgets/graphicsview/flowlayout/main.cpp6
-rw-r--r--examples/widgets/graphicsview/flowlayout/window.cpp16
-rw-r--r--examples/widgets/graphicsview/flowlayout/window.h3
-rw-r--r--examples/widgets/graphicsview/padnavigator/flippablepad.cpp4
-rw-r--r--examples/widgets/graphicsview/padnavigator/flippablepad.h4
-rw-r--r--examples/widgets/graphicsview/padnavigator/padnavigator.cpp14
-rw-r--r--examples/widgets/graphicsview/padnavigator/padnavigator.h7
-rw-r--r--examples/widgets/graphicsview/padnavigator/roundrectitem.cpp4
-rw-r--r--examples/widgets/graphicsview/padnavigator/roundrectitem.h4
-rw-r--r--examples/widgets/graphicsview/padnavigator/splashitem.h4
-rw-r--r--examples/widgets/graphicsview/simpleanchorlayout/main.cpp22
-rw-r--r--examples/widgets/graphicsview/weatheranchorlayout/main.cpp20
-rw-r--r--examples/widgets/tools/codecs/mainwindow.cpp20
-rw-r--r--examples/widgets/tools/codecs/mainwindow.h6
-rw-r--r--examples/widgets/tools/codecs/previewform.cpp22
-rw-r--r--examples/widgets/tools/codecs/previewform.h4
-rw-r--r--examples/widgets/tools/completer/fsmodel.h2
-rw-r--r--examples/widgets/tools/completer/mainwindow.cpp41
-rw-r--r--examples/widgets/tools/completer/mainwindow.h21
-rw-r--r--examples/widgets/tools/customcompleter/mainwindow.cpp17
-rw-r--r--examples/widgets/tools/customcompleter/mainwindow.h8
-rw-r--r--examples/widgets/tools/customcompleter/textedit.cpp13
-rw-r--r--examples/widgets/tools/customcompleter/textedit.h4
-rw-r--r--examples/widgets/tools/echoplugin/echowindow/echointerface.h3
-rw-r--r--examples/widgets/tools/echoplugin/echowindow/echowindow.cpp14
-rw-r--r--examples/widgets/tools/echoplugin/echowindow/main.cpp2
-rw-r--r--examples/widgets/tools/echoplugin/plugin/echoplugin.cpp2
-rw-r--r--examples/widgets/tools/i18n/languagechooser.cpp41
-rw-r--r--examples/widgets/tools/i18n/languagechooser.h16
-rw-r--r--examples/widgets/tools/i18n/mainwindow.cpp22
-rw-r--r--examples/widgets/tools/i18n/mainwindow.h2
-rw-r--r--examples/widgets/tools/plugandpaint/app/mainwindow.cpp21
-rw-r--r--examples/widgets/tools/plugandpaint/app/paintarea.cpp5
-rw-r--r--examples/widgets/tools/plugandpaint/app/plugindialog.cpp2
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp6
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h8
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp5
-rw-r--r--examples/widgets/tools/regexp/regexpdialog.h2
-rw-r--r--examples/widgets/tools/regularexpression/regularexpressiondialog.h2
-rw-r--r--examples/widgets/tools/settingseditor/locationdialog.cpp17
-rw-r--r--examples/widgets/tools/settingseditor/locationdialog.h2
-rw-r--r--examples/widgets/tools/settingseditor/mainwindow.cpp18
-rw-r--r--examples/widgets/tools/settingseditor/mainwindow.h12
-rw-r--r--examples/widgets/tools/settingseditor/settingstree.cpp36
-rw-r--r--examples/widgets/tools/settingseditor/settingstree.h13
-rw-r--r--examples/widgets/tools/settingseditor/variantdelegate.cpp18
-rw-r--r--examples/widgets/tools/settingseditor/variantdelegate.h6
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyle.cpp2
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyle.h6
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyleplugin.cpp6
-rw-r--r--examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h7
-rw-r--r--examples/widgets/tools/styleplugin/stylewindow/main.cpp3
-rw-r--r--examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp4
-rw-r--r--examples/widgets/tools/treemodelcompleter/mainwindow.cpp53
-rw-r--r--examples/widgets/tools/treemodelcompleter/mainwindow.h22
-rw-r--r--examples/widgets/tools/treemodelcompleter/treemodelcompleter.cpp12
-rw-r--r--examples/widgets/tools/treemodelcompleter/treemodelcompleter.h4
-rw-r--r--examples/widgets/tools/undo/commands.cpp36
-rw-r--r--examples/widgets/tools/undo/commands.h14
-rw-r--r--examples/widgets/tools/undo/document.cpp30
-rw-r--r--examples/widgets/tools/undo/document.h15
-rw-r--r--examples/widgets/tools/undo/mainwindow.cpp53
-rw-r--r--examples/widgets/tools/undo/mainwindow.h2
-rw-r--r--examples/widgets/tools/undoframework/commands.cpp20
-rw-r--r--examples/widgets/tools/undoframework/commands.h6
-rw-r--r--examples/widgets/tools/undoframework/diagramitem.cpp9
-rw-r--r--examples/widgets/tools/undoframework/diagramitem.h5
-rw-r--r--examples/widgets/tools/undoframework/diagramscene.cpp17
-rw-r--r--examples/widgets/tools/undoframework/diagramscene.h4
-rw-r--r--examples/widgets/tools/undoframework/main.cpp2
-rw-r--r--examples/widgets/tools/undoframework/mainwindow.cpp9
-rw-r--r--examples/widgets/tools/undoframework/mainwindow.h28
-rw-r--r--mkspecs/common/mac.conf1
-rw-r--r--mkspecs/common/macx.conf2
-rw-r--r--mkspecs/features/create_cmake.prf6
-rw-r--r--mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in6
-rw-r--r--mkspecs/features/qmake_use.prf2
-rw-r--r--mkspecs/features/qt_configure.prf106
-rw-r--r--qmake/generators/mac/pbuilder_pbx.cpp115
-rw-r--r--qmake/generators/mac/pbuilder_pbx.h2
-rw-r--r--qmake/generators/unix/unixmake2.cpp6
-rw-r--r--qmake/option.cpp5
-rw-r--r--src/corelib/configure.json20
-rw-r--r--src/corelib/corelib.pro2
-rw-r--r--src/corelib/doc/snippets/hellotrmain.cpp4
-rw-r--r--src/corelib/global/qlibraryinfo.cpp208
-rw-r--r--src/corelib/global/qlogging.cpp4
-rw-r--r--src/corelib/global/qnamespace.qdoc2
-rw-r--r--src/corelib/global/qoperatingsystemversion.cpp8
-rw-r--r--src/corelib/global/qoperatingsystemversion.h1
-rw-r--r--src/corelib/global/qrandom.cpp19
-rw-r--r--src/corelib/io/qfilesystemwatcher.cpp13
-rw-r--r--src/corelib/io/qtldurl.cpp8
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp13
-rw-r--r--src/corelib/kernel/qcoreapplication.h3
-rw-r--r--src/corelib/kernel/qeventdispatcher_winrt.cpp23
-rw-r--r--src/corelib/kernel/qpointer.h15
-rw-r--r--src/corelib/plugin/qlibrary.cpp2
-rw-r--r--src/corelib/thread/qbasicatomic.h12
-rw-r--r--src/corelib/thread/qreadwritelock.cpp50
-rw-r--r--src/corelib/thread/qreadwritelock_p.h32
-rw-r--r--src/corelib/time/qcalendar.cpp484
-rw-r--r--src/corelib/time/qdatetime.cpp53
-rw-r--r--src/corelib/time/qhijricalendar.cpp47
-rw-r--r--src/corelib/time/qislamiccivilcalendar.cpp32
-rw-r--r--src/corelib/time/qromancalendar.cpp20
-rw-r--r--src/corelib/time/qtimezone.cpp23
-rw-r--r--src/corelib/time/qtimezoneprivate.cpp48
-rw-r--r--src/corelib/time/qtimezoneprivate_p.h3
-rw-r--r--src/corelib/time/qtimezoneprivate_win.cpp42
-rw-r--r--src/corelib/tools/qcontainertools_impl.h4
-rw-r--r--src/gui/image/qiconloader.cpp2
-rw-r--r--src/gui/image/qimage.cpp2
-rw-r--r--src/gui/image/qimage_conversions.cpp218
-rw-r--r--src/gui/image/qimagereader.cpp6
-rw-r--r--src/gui/image/qpicture.cpp3
-rw-r--r--src/gui/kernel/qguiapplication.cpp19
-rw-r--r--src/gui/kernel/qhighdpiscaling.cpp9
-rw-r--r--src/gui/kernel/qopenglcontext.cpp11
-rw-r--r--src/gui/kernel/qtouchdevice.cpp10
-rw-r--r--src/gui/painting/qcolormatrix_p.h22
-rw-r--r--src/gui/painting/qcolorspace.cpp39
-rw-r--r--src/gui/painting/qcolorspace.h9
-rw-r--r--src/gui/painting/qcolorspace_p.h6
-rw-r--r--src/gui/painting/qcolortransferfunction_p.h4
-rw-r--r--src/gui/painting/qcolortransform.cpp12
-rw-r--r--src/gui/painting/qdrawhelper.cpp6
-rw-r--r--src/gui/painting/qdrawhelper_ssse3.cpp45
-rw-r--r--src/gui/painting/qicc.cpp3
-rw-r--r--src/gui/painting/qplatformbackingstore.cpp20
-rw-r--r--src/gui/painting/qplatformbackingstore.h3
-rw-r--r--src/gui/rhi/cs_tdr.h209
-rw-r--r--src/gui/rhi/qrhi.cpp152
-rw-r--r--src/gui/rhi/qrhi_p.h9
-rw-r--r--src/gui/rhi/qrhi_p_p.h6
-rw-r--r--src/gui/rhi/qrhid3d11.cpp509
-rw-r--r--src/gui/rhi/qrhid3d11_p.h3
-rw-r--r--src/gui/rhi/qrhid3d11_p_p.h27
-rw-r--r--src/gui/rhi/qrhigles2.cpp219
-rw-r--r--src/gui/rhi/qrhigles2_p_p.h7
-rw-r--r--src/gui/rhi/qrhimetal.mm502
-rw-r--r--src/gui/rhi/qrhimetal_p_p.h4
-rw-r--r--src/gui/rhi/qrhinull.cpp13
-rw-r--r--src/gui/rhi/qrhinull_p_p.h4
-rw-r--r--src/gui/rhi/qrhiprofiler.cpp14
-rw-r--r--src/gui/rhi/qrhiprofiler_p_p.h6
-rw-r--r--src/gui/rhi/qrhivulkan.cpp387
-rw-r--r--src/gui/rhi/qrhivulkan_p_p.h5
-rw-r--r--src/gui/rhi/tdr.hlsl9
-rw-r--r--src/gui/text/qtextdocument.cpp5
-rw-r--r--src/gui/text/qtextengine.cpp15
-rw-r--r--src/gui/text/qtextformat.cpp1
-rw-r--r--src/network/access/qhttp2configuration.cpp2
-rw-r--r--src/network/access/qhttp2protocolhandler.cpp25
-rw-r--r--src/network/access/qhttp2protocolhandler_p.h2
-rw-r--r--src/network/access/qhttpnetworkconnection.cpp3
-rw-r--r--src/network/access/qhttpnetworkconnectionchannel.cpp21
-rw-r--r--src/network/access/qhttpthreaddelegate.cpp8
-rw-r--r--src/network/access/qnetworkrequest.cpp13
-rw-r--r--src/network/access/qnetworkrequest.h12
-rw-r--r--src/network/kernel/qnetconmonitor_win.cpp4
-rw-r--r--src/network/ssl/qsslsocket.cpp2
-rw-r--r--src/network/ssl/qsslsocket_openssl11.cpp5
-rw-r--r--src/network/ssl/qsslsocket_schannel.cpp16
-rw-r--r--src/network/ssl/qsslsocket_schannel_p.h1
-rw-r--r--src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm201
-rw-r--r--src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h1
-rw-r--r--src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp2
-rw-r--r--src/plugins/platforms/android/android.pro4
-rw-r--r--src/plugins/platforms/cocoa/qcocoasystemsettings.mm6
-rw-r--r--src/plugins/platforms/cocoa/qnsview_dragging.mm5
-rw-r--r--src/plugins/platforms/cocoa/qnswindow.mm4
-rw-r--r--src/plugins/platforms/eglfs/api/qeglfscursor_p.h4
-rw-r--r--src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h4
-rw-r--r--src/plugins/platforms/windows/qwindowsglcontext.cpp12
-rw-r--r--src/plugins/platforms/windows/qwindowsglcontext.h2
-rw-r--r--src/plugins/platforms/windows/qwindowsopengltester.cpp256
-rw-r--r--src/plugins/platforms/windows/qwindowsscreen.cpp6
-rw-r--r--src/plugins/platforms/windows/qwindowstheme.h3
-rw-r--r--src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp3
-rw-r--r--src/plugins/platforms/windows/windows.pri2
-rw-r--r--src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp12
-rw-r--r--src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp12
-rw-r--r--src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp26
-rw-r--r--src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h2
-rw-r--r--src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp10
-rw-r--r--src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp18
-rw-r--r--src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp18
-rw-r--r--src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp18
-rw-r--r--src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp38
-rw-r--r--src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp21
-rw-r--r--src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp11
-rw-r--r--src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp24
-rw-r--r--src/plugins/sqldrivers/psql/qsql_psql.cpp12
-rw-r--r--src/plugins/styles/windowsvista/main.cpp4
-rw-r--r--src/plugins/styles/windowsvista/qwindowsvistastyle.cpp113
-rw-r--r--src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h2
-rw-r--r--src/plugins/styles/windowsvista/qwindowsxpstyle.cpp158
-rw-r--r--src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h61
-rw-r--r--src/widgets/dialogs/qfilesystemmodel.cpp39
-rw-r--r--src/widgets/doc/snippets/qsplashscreen/main.cpp7
-rw-r--r--src/widgets/graphicsview/qgraphicsview.h4
-rw-r--r--src/widgets/kernel/qshortcut.cpp6
-rw-r--r--src/widgets/styles/qstyleoption.cpp2
-rw-r--r--src/widgets/styles/qwindowsstyle.cpp30
-rw-r--r--src/widgets/styles/qwindowsstyle_p_p.h4
-rw-r--r--src/widgets/widgets/qcombobox.cpp36
-rw-r--r--src/widgets/widgets/qcombobox_p.h10
-rw-r--r--src/widgets/widgets/qmenu.cpp17
-rw-r--r--src/widgets/widgets/qsplashscreen.cpp38
-rw-r--r--src/widgets/widgets/qsplashscreen.h4
-rw-r--r--tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp3
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp7
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp8
-rw-r--r--tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp169
-rw-r--r--tests/auto/gui/kernel/qwindow/tst_qwindow.cpp104
-rw-r--r--tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp7
-rw-r--r--tests/auto/gui/text/qfont/tst_qfont.cpp4
-rw-r--r--tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp17
-rw-r--r--tests/auto/network/access/http2/tst_http2.cpp3
-rw-r--r--tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp4
-rw-r--r--tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp5
-rw-r--r--tests/auto/other/lancelot/paintcommands.cpp10
-rw-r--r--tests/auto/testlib/selftests/tst_selftests.cpp3
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp1845
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp11
-rw-r--r--tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp1371
-rw-r--r--tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp411
-rw-r--r--tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp10
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp14
-rw-r--r--tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp5
-rw-r--r--tests/auto/widgets/widgets/qsplashscreen/tst_qsplashscreen.cpp12
-rw-r--r--tests/baselineserver/shared/qbaselinetest.cpp28
-rw-r--r--tests/benchmarks/corelib/thread/qreadwritelock/qreadwritelock.pro3
-rw-r--r--tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp91
-rw-r--r--tests/benchmarks/gui/image/qimageconversion/tst_qimageconversion.cpp2
-rw-r--r--tests/manual/qgraphicslayout/flicker/window.h2
-rw-r--r--tests/manual/rhi/shared/examplefw.h22
291 files changed, 6542 insertions, 4873 deletions
diff --git a/configure.json b/configure.json
index 5fc35a1658..13cca852f6 100644
--- a/configure.json
+++ b/configure.json
@@ -222,6 +222,21 @@
{ "type": "pkgConfig", "args": "libudev" },
"-ludev"
]
+ },
+ "libdl": {
+ "label": "dlopen()",
+ "test": {
+ "main": [
+ "dlclose(dlopen(0, 0));",
+ "dlsym(RTLD_DEFAULT, 0);",
+ "dlerror();"
+ ]
+ },
+ "headers": "dlfcn.h",
+ "sources": [
+ "",
+ "-ldl"
+ ]
}
},
@@ -1340,6 +1355,17 @@
"autoDetect": false,
"condition": "!features.shared",
"output": [ "publicConfig", "publicQtConfig" ]
+ },
+ "dlopen": {
+ "label": "dlopen()",
+ "condition": "config.unix && libs.libdl",
+ "output": [ "privateFeature" ]
+ },
+ "relocatable": {
+ "label": "Relocatable",
+ "autoDetect": "features.shared",
+ "condition": "features.dlopen || config.win32 || !features.shared",
+ "output": [ "privateFeature" ]
}
},
@@ -1466,6 +1492,7 @@ Configure with '-qreal float' to create a build that is binary-compatible with 5
"args": "enable_gdb_index",
"condition": "config.gcc && !config.clang && (features.debug || features.force_debug_info || features.debug_and_release)"
},
+ "relocatable",
"precompile_header",
"ltcg",
{
diff --git a/configure.pri b/configure.pri
index e26b557705..5f82efbf07 100644
--- a/configure.pri
+++ b/configure.pri
@@ -763,6 +763,11 @@ defineTest(qtConfOutput_preparePaths) {
have_hostprefix = true
}
+ equals(config.input.prefix, $$config.input.extprefix): \
+ qmake_crossbuild = false
+ else: \
+ qmake_crossbuild = true
+
PREFIX_COMPLAINTS =
PREFIX_REMINDER = false
win32: \
@@ -802,6 +807,18 @@ defineTest(qtConfOutput_preparePaths) {
processQtPath(host, hostdatadir, $$config.rel_input.archdatadir)
}
+ win32:$$qtConfEvaluate("features.shared") {
+ # Windows DLLs are in the bin dir.
+ libloc_absolute_path = $$absolute_path($$config.rel_input.bindir, $$config.input.prefix)
+ } else {
+ libloc_absolute_path = $$absolute_path($$config.rel_input.libdir, $$config.input.prefix)
+ }
+ config.input.liblocation_to_prefix = $$relative_path($$config.input.prefix, $$libloc_absolute_path)
+
+ hostbindir_absolute_path = $$absolute_path($$config.rel_input.hostbindir, $$config.input.hostprefix)
+ config.input.hostbindir_to_hostprefix = $$relative_path($$config.input.hostprefix, $$hostbindir_absolute_path)
+ config.input.hostbindir_to_extprefix = $$relative_path($$config.input.extprefix, $$hostbindir_absolute_path)
+
!isEmpty(PREFIX_COMPLAINTS) {
PREFIX_COMPLAINTS = "$$join(PREFIX_COMPLAINTS, "$$escape_expand(\\n)Note: ")"
$$PREFIX_REMINDER: \
@@ -864,9 +881,13 @@ defineTest(qtConfOutput_preparePaths) {
";" \
"" \
"$${LITERAL_HASH}define QT_CONFIGURE_SETTINGS_PATH \"$$config.rel_input.sysconfdir\"" \
+ "$${LITERAL_HASH}define QT_CONFIGURE_LIBLOCATION_TO_PREFIX_PATH \"$$config.input.liblocation_to_prefix\"" \
+ "$${LITERAL_HASH}define QT_CONFIGURE_HOSTBINDIR_TO_EXTPREFIX_PATH \"$$config.input.hostbindir_to_extprefix\"" \
+ "$${LITERAL_HASH}define QT_CONFIGURE_HOSTBINDIR_TO_HOSTPREFIX_PATH \"$$config.input.hostbindir_to_hostprefix\"" \
"" \
"$${LITERAL_HASH}ifdef QT_BUILD_QMAKE" \
"$${LITERAL_HASH} define QT_CONFIGURE_SYSROOTIFY_PREFIX $$qmake_sysrootify" \
+ "$${LITERAL_HASH} define QT_CONFIGURE_CROSSBUILD $$qmake_crossbuild" \
"$${LITERAL_HASH}endif" \
"" \
"$${LITERAL_HASH}define QT_CONFIGURE_PREFIX_PATH qt_configure_prefix_path_str + 12" \
diff --git a/dist/changes-5.12.5 b/dist/changes-5.12.5
new file mode 100644
index 0000000000..c22839db78
--- /dev/null
+++ b/dist/changes-5.12.5
@@ -0,0 +1,109 @@
+Qt 5.12.5 is a bug-fix release. It maintains both forward and backward
+compatibility (source and binary) with Qt 5.12.0 through 5.12.4.
+
+For more details, refer to the online documentation included in this
+distribution. The documentation is also available online:
+
+https://doc.qt.io/qt-5/index.html
+
+The Qt version 5.12 series is binary compatible with the 5.11.x series.
+Applications compiled for 5.11 will continue to run with 5.12.
+
+Some of the changes listed in this file include issue tracking numbers
+corresponding to tasks in the Qt Bug Tracker:
+
+https://bugreports.qt.io/
+
+Each of these identifiers can be entered in the bug tracker to obtain more
+information about a particular change.
+
+****************************************************************************
+* QtCore *
+****************************************************************************
+
+ - QBitArray:
+ * Fixed two bugs that caused QBitArrays created using fromBits() not to
+ compare equal to the equivalent QBitArray created using other methods
+ if the size was zero or not a multiple of 4. If the size modulus 8 was
+ 5, 6, or 7, the data was actually incorrect.
+
+ - QCborStreamReader:
+ * Fixed a bug that caused the QIODevice that the data was being read
+ from not to show the entire CBOR message as consumed. This allows the
+ user to consume data that may follow the CBOR payload.
+
+ - QCryptographicHash:
+ * Fixed a bug that caused the SHA-3 and Keccak algorithms to crash if
+ passed 256 MB of data or more.
+
+ - QObject:
+ * Fixed a resource leak caused by a race condition if multiple QObjects
+ were created at the same time, for the first time in an application,
+ from multiple threads (implies threads not started with QThread).
+
+ - QStorageInfo:
+ * Fixed a bug that caused QStorageInfo to be unable to report all
+ filesystems if the options to mounted filesystems were too long (over
+ 900 characters, roughly), such as those found in Docker overlay
+ mounts.
+
+ - QTimeZone:
+ * The IANA timezone database backend now properly follows symlinks even
+ when they point to variable locations like /run or /var (useful when
+ /etc is mounted read-only).
+
+****************************************************************************
+* QtGui *
+****************************************************************************
+
+ - QImage:
+ * Improve loading time when loading png files that have the same size as
+ the target.
+
+ - QPixmapCache:
+ * [QTBUG-76694][QTBUG-72523] Ignore unsafe access from non-main threads
+
+ - Text:
+ * [QTBUG-76219] Fixed a bug which could cause the font cache to grow
+ larger than it was supposed to.
+ * [QTBUG-55096][QTBUG-74761] Fixed bug where regular text rendered with
+ a color font would always display in black.
+ * [QTBUG-69546] Fixed a crash bug in
+ QTextDocument::clearUndoRedoStacks(QTextDocument::UndoStack).
+
+****************************************************************************
+* QtNetwork *
+****************************************************************************
+
+ - QHostInfo:
+ * Functors used in the lookupHost overloads are now called correctly in
+ the thread of the context object. When used without context object,
+ the thread that initiates the lookup will run the functor, and is
+ required to run an event loop.
+
+ - Windows:
+ * Correctly emit errors when trying to reach unreachable hosts or
+ services
+
+****************************************************************************
+* QtWidgets *
+****************************************************************************
+
+ - QGraphicsView:
+ * Ignore disabled items when setting the mouse cursor.
+
+ - QSplashScreen:
+ * On macOS, lower the splash screen when a modal dialog is shown to make
+ sure the user sees the dialog.
+
+ - QSystemTrayIcon:
+ * On macOS, show the icon passed into showMessage in the notification
+ popup
+
+****************************************************************************
+* Android *
+****************************************************************************
+
+ - [QTBUG-76293] Fix NDK r20 linking.
+ - [QTBUG-76036] Fixed an issue where menus would not work on 64 bit
+ builds.
diff --git a/dist/changes-5.13.1 b/dist/changes-5.13.1
new file mode 100644
index 0000000000..2021b959aa
--- /dev/null
+++ b/dist/changes-5.13.1
@@ -0,0 +1,141 @@
+Qt 5.13.1 is a bug-fix release. It maintains both forward and backward
+compatibility (source and binary) with Qt 5.13.0.
+
+For more details, refer to the online documentation included in this
+distribution. The documentation is also available online:
+
+https://doc.qt.io/qt-5/index.html
+
+The Qt version 5.13 series is binary compatible with the 5.12.x series.
+Applications compiled for 5.12 will continue to run with 5.13.
+
+Some of the changes listed in this file include issue tracking numbers
+corresponding to tasks in the Qt Bug Tracker:
+
+https://bugreports.qt.io/
+
+Each of these identifiers can be entered in the bug tracker to obtain more
+information about a particular change.
+
+****************************************************************************
+* Important Behavior Changes *
+****************************************************************************
+
+ - [QTBUG-76521] RCC's default compression algorithm was changed back to
+ Zlib, as it was in all previous releases until 5.13.0. The default will
+ remain Zlib for all Qt 5.x releases but will change in Qt 6.0. To
+ activate Zstd compression for your resources, either pass the
+ --compress-algo=zstd option to the rcc tool or add the XML attribute
+ compression-algorithm="zstd" to the <file> tags in the .qrc file.
+
+****************************************************************************
+* Android *
+****************************************************************************
+
+ - [QTBUG-76293] Fix NDK r20 linking.
+
+****************************************************************************
+* QtCore *
+****************************************************************************
+
+ - Global:
+ * [QTBUG-72073] Added the QT_NO_FLOAT16_OPERATORS macro in order to work
+ around a Microsoft <= VS2017 compiler bug that is exposed when using
+ std::bitset along with any Qt header that includes <qfloat16.h>.
+
+ - QCborStreamReader:
+ * Fixed a bug that caused the QIODevice that the data was being read
+ from not to show the entire CBOR message as consumed. This allows the
+ user to consume data that may follow the CBOR payload.
+
+ - QDeadlineTimer:
+ * [QTBUG-69750] Fixed integer overflows leading to immediate timeouts.
+
+ - QStorageInfo:
+ * Fixed a bug that caused QStorageInfo to be unable to report all
+ filesystems if the options to mounted filesystems were too long (over
+ 900 characters, roughly), such as those found in Docker overlay
+ mounts.
+
+ - QTextBoundaryFinder:
+ * Sentence breaking now no longer breaks between uppercase letters and
+ comma. This is a deviation from the Unicode specification, but
+ produces less surprising behavior.
+
+ - QTimeZone:
+ * The IANA timezone database backend now properly follows symlinks even
+ when they point to variable locations like /run or /var (useful when
+ /etc is mounted read-only).
+
+ - QVector:
+ * Fixed a regression that caused fill() not to detach, corrupting shared
+ copies.
+
+****************************************************************************
+* QtNetwork *
+****************************************************************************
+
+ - Windows:
+ * Correctly emit errors when trying to reach unreachable hosts or
+ services
+
+ - QNetworkAccessManager:
+ * Fixed QNetworkAccessManager::sendCustomRequest for Qt For WebAssembly.
+
+****************************************************************************
+* QtGui *
+****************************************************************************
+
+ - [QTBUG-73231] QWindow::mapToGlobal()/mapFromGlobal() now handle windows
+ spanning screens correctly.
+
+ - QImage:
+ * Improve loading time when loading png files that have the same size as
+ the target.
+
+ - QPixmapCache:
+ * [QTBUG-76694][QTBUG-72523] Ignore unsafe access from non-main threads
+
+ - Text:
+ * [QTBUG-76219] Fixed a bug which could cause the font cache to grow
+ larger than it was supposed to.
+ * [QTBUG-55096][QTBUG-74761] Fixed bug where regular text rendered with
+ a color font would always display in black.
+
+****************************************************************************
+* QtWidgets *
+****************************************************************************
+
+ - QSystemTrayIcon:
+ * On macOS, show the icon passed into showMessage in the notification
+ popup
+
+ - QDateTimeEdit:
+ * Use the information provided by the locale to determine the AM/PM
+ strings, unless they are already translated.
+
+ - QGraphicsView:
+ * Ignore disabled items when setting the mouse cursor.
+
+ - QMenu:
+ * Shortcuts are again shown by default in context menus, except on
+ macOS. They can be forced off by setting
+ AA_DontShowShortcutsInContextMenus to true.
+
+ - QSplashScreen:
+ * On macOS, lower the splash screen when a modal dialog is shown to make
+ sure the user sees the dialog.
+
+****************************************************************************
+* Third-Party Code *
+****************************************************************************
+
+ - Updated bundled SQLite to version 3.28.0
+ - Updated QLocale's data to CLDR v35.1
+
+****************************************************************************
+* qmake *
+****************************************************************************
+
+ - [QTBUG-75653] The CONFIG value c++latest was added to select the latest
+ C++ standard the currently used toolchain supports.
diff --git a/doc/doc.pro b/doc/doc.pro
index 41ceb7ceae..802bd12222 100644
--- a/doc/doc.pro
+++ b/doc/doc.pro
@@ -1,6 +1,8 @@
TEMPLATE = aux
-global_docs.files = $$PWD/global
+global_docs.files = \
+ $$PWD/global \
+ $$PWD/config
global_docs.path = $$[QT_INSTALL_DOCS]
INSTALLS += global_docs
!prefix_build:!equals(OUT_PWD, $$PWD): \
diff --git a/doc/global/externalsites/qtcreator.qdoc b/doc/global/externalsites/qtcreator.qdoc
index 98a5c9f12b..e283b32360 100644
--- a/doc/global/externalsites/qtcreator.qdoc
+++ b/doc/global/externalsites/qtcreator.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
@@ -62,6 +62,18 @@
\title Qt Creator: User Interface
*/
/*!
+ \externalpage http://doc.qt.io/qtcreator/creator-modes.html
+ \title Qt Creator: Selecting Modes
+*/
+/*!
+ \externalpage http://doc.qt.io/qtcreator/creator-sidebar-views.html
+ \title Qt Creator: Browsing Project Contents
+*/
+/*!
+ \externalpage http://doc.qt.io/qtcreator/creator-output-panes.html
+ \title Qt Creator: Viewing Output
+*/
+/*!
\externalpage http://doc.qt.io/qtcreator/creator-cli.html
\title Qt Creator: Using Command Line Options
*/
@@ -125,7 +137,7 @@
\externalpage http://doc.qt.io/qtcreator/quick-signals.html
\title Qt Creator: Connecting Objects to Signals
*/
-* /*!
+/*!
\externalpage http://doc.qt.io/qtcreator/quick-dynamic-properties.html
\title Qt Creator: Specifying Dynamic Properties
*/
@@ -154,6 +166,10 @@
\title Qt Creator: Using QML Modules with Plugins
*/
/*!
+ \externalpage http://doc.qt.io/qtcreator/quick-converting-ui-projects.html
+ \title Qt Creator: Converting UI Projects to Applications
+*/
+/*!
\externalpage http://doc.qt.io/qtcreator/creator-visual-editor.html
\title Qt Creator: Developing Qt Quick Applications
*/
@@ -554,6 +570,10 @@
\title Qt Creator: Analyzing CPU Usage
*/
/*!
+ \externalpage http://doc.qt.io/qtcreator/creator-cppcheck.html
+ \title Qt Creator: Analyzing Code with Cppcheck
+*/
+/*!
\externalpage http://doc.qt.io/qtcreator/creator-autotest.html
\title Qt Creator: Running Autotests
*/
@@ -581,3 +601,27 @@
\externalpage http://doc.qt.io/qtcreator/creator-scxml.html
\title Qt Creator: Editing State Charts
*/
+/*!
+ \externalpage http://doc.qt.io/qtcreator/studio-timeline.html
+ \title Qt Creator: Creating Animations
+*/
+/*!
+ \externalpage http://doc.qt.io/qtcreator/creator-language-servers.html
+ \title Qt Creator: Using Language Servers
+*/
+/*!
+ \externalpage http://doc.qt.io/qtcreator/qtcreator-toc.html
+ \title Qt Creator: All Topics
+*/
+/*!
+ \externalpage http://doc.qt.io/qtcreator/creator-live-preview.html
+ \title Qt Creator: Previewing
+*/
+/*!
+ \externalpage http://doc.qt.io/qtcreator/creator-live-preview-desktop.html
+ \title Qt Creator: Previewing on Desktop
+*/
+/*!
+ \externalpage http://doc.qt.io/qtcreator/creator-live-preview-devices.html
+ \title Qt Creator: Previewing on Devices
+*/
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/graphicsview/anchorlayout/main.cpp b/examples/widgets/graphicsview/anchorlayout/main.cpp
index 59ced72018..98dacfb5fb 100644
--- a/examples/widgets/graphicsview/anchorlayout/main.cpp
+++ b/examples/widgets/graphicsview/anchorlayout/main.cpp
@@ -88,7 +88,7 @@ int main(int argc, char **argv)
QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
l->setSpacing(0);
- QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window);
+ QGraphicsWidget *w = new QGraphicsWidget(nullptr, Qt::Window);
w->setPos(20, 20);
w->setLayout(l);
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.cpp b/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.cpp
index 804db2f9be..2fbc232b20 100644
--- a/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.cpp
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.cpp
@@ -51,33 +51,26 @@
#include "layoutitem.h"
#include <QGradient>
-#include <QGraphicsLinearLayout>
#include <QPainter>
//! [0]
-LayoutItem::LayoutItem(QGraphicsItem *parent/* = 0*/)
- : QGraphicsLayoutItem(), QGraphicsItem(parent)
+LayoutItem::LayoutItem(QGraphicsItem *parent)
+ : QGraphicsLayoutItem(), QGraphicsItem(parent),
+ m_pix(QPixmap(QLatin1String(":/images/block.png")))
{
- m_pix = new QPixmap(QLatin1String(":/images/block.png"));
setGraphicsItem(this);
}
//! [0]
-LayoutItem::~LayoutItem()
-{
- delete m_pix;
-}
-
//! [1]
-void LayoutItem::paint(QPainter *painter,
- const QStyleOptionGraphicsItem *option, QWidget *widget /*= 0*/)
+void LayoutItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
{
Q_UNUSED(widget);
Q_UNUSED(option);
- QRectF frame(QPointF(0,0), geometry().size());
- qreal w = m_pix->width();
- qreal h = m_pix->height();
+ QRectF frame(QPointF(0, 0), geometry().size());
+ const QSize pmSize = m_pix.size();
QGradientStops stops;
//! [1]
@@ -94,8 +87,8 @@ void LayoutItem::paint(QPainter *painter,
painter->drawRoundedRect(frame, 10.0, 10.0);
// paint a rect around the pixmap (with gradient)
- QPointF pixpos = frame.center() - (QPointF(w, h) / 2);
- QRectF innerFrame(pixpos, QSizeF(w, h));
+ QPointF pixpos = frame.center() - (QPointF(pmSize.width(), pmSize.height()) / 2);
+ QRectF innerFrame(pixpos, pmSize);
innerFrame.adjust(-4, -4, 4, 4);
gradient.setStart(innerFrame.topLeft());
gradient.setFinalStop(innerFrame.bottomRight());
@@ -106,14 +99,14 @@ void LayoutItem::paint(QPainter *painter,
gradient.setStops(stops);
painter->setBrush(QBrush(gradient));
painter->drawRoundedRect(innerFrame, 10.0, 10.0);
- painter->drawPixmap(pixpos, *m_pix);
+ painter->drawPixmap(pixpos, m_pix);
}
//! [2]
//! [3]
QRectF LayoutItem::boundingRect() const
{
- return QRectF(QPointF(0,0), geometry().size());
+ return QRectF(QPointF(0, 0), geometry().size());
}
//! [3]
@@ -133,7 +126,7 @@ QSizeF LayoutItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
case Qt::MinimumSize:
case Qt::PreferredSize:
// Do not allow a size smaller than the pixmap with two frames around it.
- return m_pix->size() + QSize(12, 12);
+ return m_pix.size() + QSize(12, 12);
case Qt::MaximumSize:
return QSizeF(1000,1000);
default:
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h b/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h
index 3535a26670..3dc431d513 100644
--- a/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/layoutitem.h
@@ -53,23 +53,24 @@
#include <QGraphicsLayoutItem>
#include <QGraphicsItem>
+#include <QPixmap>
//! [0]
class LayoutItem : public QGraphicsLayoutItem, public QGraphicsItem
{
public:
- LayoutItem(QGraphicsItem *parent = 0);
- ~LayoutItem();
+ LayoutItem(QGraphicsItem *parent = nullptr);
+
// Inherited from QGraphicsLayoutItem
void setGeometry(const QRectF &geom) override;
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
// Inherited from QGraphicsItem
QRectF boundingRect() const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
private:
- QPixmap *m_pix;
+ QPixmap m_pix;
};
//! [0]
diff --git a/examples/widgets/graphicsview/basicgraphicslayouts/window.h b/examples/widgets/graphicsview/basicgraphicslayouts/window.h
index dfe04ed196..c46082e552 100644
--- a/examples/widgets/graphicsview/basicgraphicslayouts/window.h
+++ b/examples/widgets/graphicsview/basicgraphicslayouts/window.h
@@ -54,11 +54,11 @@
#include <QGraphicsWidget>
//! [0]
-class Window : public QGraphicsWidget {
+class Window : public QGraphicsWidget
+{
Q_OBJECT
-
public:
- Window(QGraphicsWidget *parent = 0);
+ Window(QGraphicsWidget *parent = nullptr);
};
//! [0]
diff --git a/examples/widgets/graphicsview/boxes/glbuffers.cpp b/examples/widgets/graphicsview/boxes/glbuffers.cpp
index b52b26c4ef..91de336af3 100644
--- a/examples/widgets/graphicsview/boxes/glbuffers.cpp
+++ b/examples/widgets/graphicsview/boxes/glbuffers.cpp
@@ -49,8 +49,6 @@
****************************************************************************/
#include "glbuffers.h"
-#include <QtGui/qmatrix4x4.h>
-#include <QtCore/qmath.h>
void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{
@@ -65,7 +63,7 @@ void qgluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zF
// GLTexture //
//============================================================================//
-GLTexture::GLTexture() : m_texture(0), m_failed(false)
+GLTexture::GLTexture()
{
glGenTextures(1, &m_texture);
}
@@ -83,7 +81,7 @@ GLTexture2D::GLTexture2D(int width, int height)
{
glBindTexture(GL_TEXTURE_2D, m_texture);
glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0,
- GL_BGRA, GL_UNSIGNED_BYTE, 0);
+ GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
@@ -95,7 +93,7 @@ GLTexture2D::GLTexture2D(int width, int height)
}
-GLTexture2D::GLTexture2D(const QString& fileName, int width, int height)
+GLTexture2D::GLTexture2D(const QString &fileName, int width, int height)
{
// TODO: Add error handling.
QImage image(fileName);
@@ -162,7 +160,7 @@ GLTexture3D::GLTexture3D(int width, int height, int depth)
glBindTexture(GL_TEXTURE_3D, m_texture);
glTexImage3D(GL_TEXTURE_3D, 0, 4, width, height, depth, 0,
- GL_BGRA, GL_UNSIGNED_BYTE, 0);
+ GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
@@ -206,7 +204,7 @@ GLTextureCube::GLTextureCube(int size)
for (int i = 0; i < 6; ++i)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 4, size, size, 0,
- GL_BGRA, GL_UNSIGNED_BYTE, 0);
+ GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
@@ -252,7 +250,7 @@ GLTextureCube::GLTextureCube(const QStringList &fileNames, int size)
// Clear remaining faces.
while (index < 6) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + index, 0, 4, size, size, 0,
- GL_BGRA, GL_UNSIGNED_BYTE, 0);
+ GL_BGRA, GL_UNSIGNED_BYTE, nullptr);
++index;
}
@@ -291,11 +289,8 @@ void GLTextureCube::unbind()
//============================================================================//
GLFrameBufferObject::GLFrameBufferObject(int width, int height)
- : m_fbo(0)
- , m_depthBuffer(0)
- , m_width(width)
+ : m_width(width)
, m_height(height)
- , m_failed(false)
{
GLBUFFERS_ASSERT_OPENGL("GLFrameBufferObject::GLFrameBufferObject",
glGenFramebuffersEXT && glGenRenderbuffersEXT && glBindRenderbufferEXT && glRenderbufferStorageEXT, return)
@@ -373,7 +368,7 @@ void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face)
return;
}
- static int perm[6][3] = {
+ static constexpr int perm[6][3] = {
{2, 1, 0},
{2, 1, 0},
{0, 2, 1},
@@ -382,7 +377,7 @@ void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face)
{0, 1, 2},
};
- static float signs[6][3] = {
+ static constexpr float signs[6][3] = {
{-1.0f, -1.0f, -1.0f},
{+1.0f, -1.0f, +1.0f},
{+1.0f, +1.0f, -1.0f},
diff --git a/examples/widgets/graphicsview/boxes/glbuffers.h b/examples/widgets/graphicsview/boxes/glbuffers.h
index e2363d561e..4318e8ac24 100644
--- a/examples/widgets/graphicsview/boxes/glbuffers.h
+++ b/examples/widgets/graphicsview/boxes/glbuffers.h
@@ -58,7 +58,7 @@
#include <QtOpenGL>
#define BUFFER_OFFSET(i) ((char*)0 + (i))
-#define SIZE_OF_MEMBER(cls, member) sizeof(static_cast<cls *>(0)->member)
+#define SIZE_OF_MEMBER(cls, member) sizeof(static_cast<cls *>(nullptr)->member)
#define GLBUFFERS_ASSERT_OPENGL(prefix, assertion, returnStatement) \
if (m_failed || !(assertion)) { \
@@ -82,8 +82,8 @@ public:
virtual void unbind() = 0;
virtual bool failed() const {return m_failed;}
protected:
- GLuint m_texture;
- bool m_failed;
+ GLuint m_texture = 0;
+ bool m_failed = false;
};
class GLFrameBufferObject
@@ -98,17 +98,17 @@ public:
virtual bool failed() const {return m_failed;}
protected:
void setAsRenderTarget(bool state = true);
- GLuint m_fbo;
- GLuint m_depthBuffer;
+ GLuint m_fbo = 0;
+ GLuint m_depthBuffer = 0;
int m_width, m_height;
- bool m_failed;
+ bool m_failed = false;
};
class GLTexture2D : public GLTexture
{
public:
GLTexture2D(int width, int height);
- explicit GLTexture2D(const QString& fileName, int width = 0, int height = 0);
+ explicit GLTexture2D(const QString &fileName, int width = 0, int height = 0);
void load(int width, int height, QRgb *data);
void bind() override;
void unbind() override;
@@ -197,11 +197,7 @@ template<class T>
class GLVertexBuffer
{
public:
- GLVertexBuffer(int length, const T *data = 0, int mode = GL_STATIC_DRAW)
- : m_length(0)
- , m_mode(mode)
- , m_buffer(0)
- , m_failed(false)
+ GLVertexBuffer(int length, const T *data = nullptr, int mode = GL_STATIC_DRAW)
{
GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::GLVertexBuffer", glGenBuffers && glBindBuffer && glBufferData, return)
@@ -275,12 +271,12 @@ public:
T *lock()
{
- GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::lock", glBindBuffer && glMapBuffer, return 0)
+ GLBUFFERS_ASSERT_OPENGL("GLVertexBuffer::lock", glBindBuffer && glMapBuffer, return nullptr)
glBindBuffer(GL_ARRAY_BUFFER, m_buffer);
//glBufferData(GL_ARRAY_BUFFER, m_length, NULL, m_mode);
GLvoid* buffer = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
- m_failed = (buffer == 0);
+ m_failed = (buffer == nullptr);
return reinterpret_cast<T *>(buffer);
}
@@ -298,16 +294,17 @@ public:
}
private:
- int m_length, m_mode;
- GLuint m_buffer;
- bool m_failed;
+ int m_length = 0;
+ int m_mode = 0;
+ GLuint m_buffer = 0;
+ bool m_failed = false;
};
template<class T>
class GLIndexBuffer
{
public:
- GLIndexBuffer(int length, const T *data = 0, int mode = GL_STATIC_DRAW)
+ GLIndexBuffer(int length, const T *data = nullptr, int mode = GL_STATIC_DRAW)
: m_length(0)
, m_mode(mode)
, m_buffer(0)
@@ -345,11 +342,11 @@ public:
T *lock()
{
- GLBUFFERS_ASSERT_OPENGL("GLIndexBuffer::lock", glBindBuffer && glMapBuffer, return 0)
+ GLBUFFERS_ASSERT_OPENGL("GLIndexBuffer::lock", glBindBuffer && glMapBuffer, return nullptr)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_buffer);
GLvoid* buffer = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_READ_WRITE);
- m_failed = (buffer == 0);
+ m_failed = (buffer == nullptr);
return reinterpret_cast<T *>(buffer);
}
diff --git a/examples/widgets/graphicsview/boxes/gltrianglemesh.h b/examples/widgets/graphicsview/boxes/gltrianglemesh.h
index 716c4de62e..e5c4f51514 100644
--- a/examples/widgets/graphicsview/boxes/gltrianglemesh.h
+++ b/examples/widgets/graphicsview/boxes/gltrianglemesh.h
@@ -51,13 +51,12 @@
#ifndef GLTRIANGLEMESH_H
#define GLTRIANGLEMESH_H
-//#include <GL/glew.h>
+#include "glbuffers.h"
#include "glextensions.h"
#include <QtWidgets>
#include <QtOpenGL>
-#include "glbuffers.h"
template<class TVertex, class TIndex>
class GLTriangleMesh
diff --git a/examples/widgets/graphicsview/boxes/main.cpp b/examples/widgets/graphicsview/boxes/main.cpp
index b7242d529b..2b3e6d3389 100644
--- a/examples/widgets/graphicsview/boxes/main.cpp
+++ b/examples/widgets/graphicsview/boxes/main.cpp
@@ -48,13 +48,11 @@
**
****************************************************************************/
-//#include <GL/glew.h>
#include "glextensions.h"
-
#include "scene.h"
-#include <QtWidgets>
#include <QGLWidget>
+#include <QtWidgets>
class GraphicsView : public QGraphicsView
{
@@ -114,7 +112,7 @@ int main(int argc, char **argv)
QApplication app(argc, argv);
if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_5) == 0) {
- QMessageBox::critical(0, "OpenGL features missing",
+ QMessageBox::critical(nullptr, "OpenGL features missing",
"OpenGL version 1.5 or higher is required to run this demo.\n"
"The program will now exit.");
return -1;
@@ -125,7 +123,7 @@ int main(int argc, char **argv)
widget->makeCurrent();
if (!necessaryExtensionsSupported()) {
- QMessageBox::critical(0, "OpenGL features missing",
+ QMessageBox::critical(nullptr, "OpenGL features missing",
"The OpenGL extensions required to run this demo are missing.\n"
"The program will now exit.");
delete widget;
@@ -134,7 +132,7 @@ int main(int argc, char **argv)
// Check if all the necessary functions are resolved.
if (!getGLExtensionFunctions().resolve(widget->context())) {
- QMessageBox::critical(0, "OpenGL features missing",
+ QMessageBox::critical(nullptr, "OpenGL features missing",
"Failed to resolve OpenGL functions required to run this demo.\n"
"The program will now exit.");
delete widget;
@@ -142,7 +140,7 @@ int main(int argc, char **argv)
}
// TODO: Make conditional for final release
- QMessageBox::information(0, "For your information",
+ QMessageBox::information(nullptr, "For your information",
"This demo can be GPU and CPU intensive and may\n"
"work poorly or not at all on your system.");
diff --git a/examples/widgets/graphicsview/boxes/qtbox.cpp b/examples/widgets/graphicsview/boxes/qtbox.cpp
index 68d5c251f4..8713aac05d 100644
--- a/examples/widgets/graphicsview/boxes/qtbox.cpp
+++ b/examples/widgets/graphicsview/boxes/qtbox.cpp
@@ -50,28 +50,23 @@
#include "qtbox.h"
-const qreal ROTATE_SPEED_X = 30.0 / 1000.0;
-const qreal ROTATE_SPEED_Y = 20.0 / 1000.0;
-const qreal ROTATE_SPEED_Z = 40.0 / 1000.0;
-const int MAX_ITEM_SIZE = 512;
-const int MIN_ITEM_SIZE = 16;
+constexpr qreal ROTATE_SPEED_X = 30.0 / 1000.0;
+constexpr qreal ROTATE_SPEED_Y = 20.0 / 1000.0;
+constexpr qreal ROTATE_SPEED_Z = 40.0 / 1000.0;
+constexpr int MAX_ITEM_SIZE = 512;
+constexpr int MIN_ITEM_SIZE = 16;
//============================================================================//
// ItemBase //
//============================================================================//
-ItemBase::ItemBase(int size, int x, int y) : m_size(size), m_isResizing(false)
+ItemBase::ItemBase(int size, int x, int y) : m_size(size), m_startTime(QTime::currentTime())
{
setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemIsFocusable, true);
setAcceptHoverEvents(true);
setPos(x, y);
- m_startTime = QTime::currentTime();
-}
-
-ItemBase::~ItemBase()
-{
}
QRectF ItemBase::boundingRect() const
@@ -252,10 +247,7 @@ void ItemBase::wheelEvent(QGraphicsSceneWheelEvent *event)
{
prepareGeometryChange();
m_size = int(m_size * qExp(-event->delta() / 600.0));
- if (m_size > MAX_ITEM_SIZE)
- m_size = MAX_ITEM_SIZE;
- else if (m_size < MIN_ITEM_SIZE)
- m_size = MIN_ITEM_SIZE;
+ m_size = qBound(MIN_ITEM_SIZE, m_size, MAX_ITEM_SIZE);
}
int ItemBase::type() const
@@ -273,7 +265,7 @@ bool ItemBase::isInResizeArea(const QPointF &pos)
// QtBox //
//============================================================================//
-QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y), m_texture(0)
+QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y)
{
for (int i = 0; i < 8; ++i) {
m_vertices[i].setX(i & 1 ? 0.5f : -0.5f);
@@ -294,8 +286,7 @@ QtBox::QtBox(int size, int x, int y) : ItemBase(size, x, y), m_texture(0)
QtBox::~QtBox()
{
- if (m_texture)
- delete m_texture;
+ delete m_texture;
}
ItemBase *QtBox::createNew(int size, int x, int y)
@@ -337,7 +328,7 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_NORMALIZE);
- if(m_texture == 0)
+ if (m_texture == nullptr)
m_texture = new GLTexture2D(":/res/boxes/qt-logo.jpg", 64, 64);
m_texture->bind();
glEnable(GL_TEXTURE_2D);
@@ -405,9 +396,8 @@ void QtBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
//============================================================================//
CircleItem::CircleItem(int size, int x, int y) : ItemBase(size, x, y)
-{
- m_color = QColor::fromHsv(QRandomGenerator::global()->bounded(360), 255, 255);
-}
+ , m_color(QColor::fromHsv(QRandomGenerator::global()->bounded(360), 255, 255))
+{}
void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
@@ -455,9 +445,8 @@ ItemBase *CircleItem::createNew(int size, int x, int y)
//============================================================================//
SquareItem::SquareItem(int size, int x, int y) : ItemBase(size, x, y)
-{
- m_image = QPixmap(":/res/boxes/square.jpg");
-}
+ , m_image(QPixmap(":/res/boxes/square.jpg"))
+{}
void SquareItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
diff --git a/examples/widgets/graphicsview/boxes/qtbox.h b/examples/widgets/graphicsview/boxes/qtbox.h
index f8ee9bdb0a..84c8cb1d93 100644
--- a/examples/widgets/graphicsview/boxes/qtbox.h
+++ b/examples/widgets/graphicsview/boxes/qtbox.h
@@ -51,18 +51,17 @@
#ifndef QTBOX_H
#define QTBOX_H
-#include <QtWidgets>
-
-#include <QtGui/qvector3d.h>
#include "glbuffers.h"
+#include <QtWidgets>
+#include <QVector3D>
+
class ItemBase : public QGraphicsItem
{
public:
enum { Type = UserType + 1 };
ItemBase(int size, int x, int y);
- virtual ~ItemBase();
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
protected:
@@ -84,7 +83,7 @@ protected:
int m_size;
QTime m_startTime;
- bool m_isResizing;
+ bool m_isResizing = false;
};
class QtBox : public ItemBase
@@ -99,7 +98,7 @@ private:
QVector3D m_vertices[8];
QVector3D m_texCoords[4];
QVector3D m_normals[6];
- GLTexture *m_texture;
+ GLTexture *m_texture = nullptr;
};
class CircleItem : public ItemBase
diff --git a/examples/widgets/graphicsview/boxes/roundedbox.h b/examples/widgets/graphicsview/boxes/roundedbox.h
index ebc2dbd36e..a1f15cd631 100644
--- a/examples/widgets/graphicsview/boxes/roundedbox.h
+++ b/examples/widgets/graphicsview/boxes/roundedbox.h
@@ -51,16 +51,12 @@
#ifndef ROUNDEDBOX_H
#define ROUNDEDBOX_H
-//#include <GL/glew.h>
+#include "glbuffers.h"
#include "glextensions.h"
-
-#include <QtWidgets>
-#include <QtOpenGL>
-
#include "gltrianglemesh.h"
-#include <QtGui/qvector3d.h>
-#include <QtGui/qvector2d.h>
-#include "glbuffers.h"
+
+#include <QVector2D>
+#include <QVector3D>
struct P3T2N3Vertex
{
diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp
index a9995efa27..b344f65561 100644
--- a/examples/widgets/graphicsview/boxes/scene.cpp
+++ b/examples/widgets/graphicsview/boxes/scene.cpp
@@ -48,45 +48,15 @@
**
****************************************************************************/
-#include <QDebug>
#include "scene.h"
-#include <QtCore/QRandomGenerator>
-#include <QtGui/qmatrix4x4.h>
-#include <QtGui/qvector3d.h>
+
+#include <QMatrix4x4>
+#include <QRandomGenerator>
+#include <QVector3D>
#include <qmath.h>
#include "3rdparty/fbm.h"
-void checkGLErrors(const QString& prefix)
-{
- switch (glGetError()) {
- case GL_NO_ERROR:
- //qDebug() << prefix << tr("No error.");
- break;
- case GL_INVALID_ENUM:
- qDebug() << prefix << QObject::tr("Invalid enum.");
- break;
- case GL_INVALID_VALUE:
- qDebug() << prefix << QObject::tr("Invalid value.");
- break;
- case GL_INVALID_OPERATION:
- qDebug() << prefix << QObject::tr("Invalid operation.");
- break;
- case GL_STACK_OVERFLOW:
- qDebug() << prefix << QObject::tr("Stack overflow.");
- break;
- case GL_STACK_UNDERFLOW:
- qDebug() << prefix << QObject::tr("Stack underflow.");
- break;
- case GL_OUT_OF_MEMORY:
- qDebug() << prefix << QObject::tr("Out of memory.");
- break;
- default:
- qDebug() << prefix << QObject::tr("Unknown error.");
- break;
- }
-}
-
//============================================================================//
// ColorEdit //
//============================================================================//
@@ -126,7 +96,7 @@ void ColorEdit::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
QColor color(m_color);
- QColorDialog dialog(color, 0);
+ QColorDialog dialog(color, nullptr);
dialog.setOption(QColorDialog::ShowAlphaChannel, true);
dialog.move(280, 120);
if (dialog.exec() == QDialog::Rejected)
@@ -179,17 +149,6 @@ void FloatEdit::editDone()
//============================================================================//
// TwoSidedGraphicsWidget //
//============================================================================//
-
-TwoSidedGraphicsWidget::TwoSidedGraphicsWidget(QGraphicsScene *scene)
- : QObject(scene)
- , m_current(0)
- , m_angle(0)
- , m_delta(0)
-{
- for (int i = 0; i < 2; ++i)
- m_proxyWidgets[i] = 0;
-}
-
void TwoSidedGraphicsWidget::setWidget(int index, QWidget *widget)
{
if (index < 0 || index >= 2)
@@ -201,8 +160,7 @@ void TwoSidedGraphicsWidget::setWidget(int index, QWidget *widget)
GraphicsWidget *proxy = new GraphicsWidget;
proxy->setWidget(widget);
- if (m_proxyWidgets[index])
- delete m_proxyWidgets[index];
+ delete m_proxyWidgets[index];
m_proxyWidgets[index] = proxy;
proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache);
@@ -219,7 +177,7 @@ QWidget *TwoSidedGraphicsWidget::widget(int index)
if (index < 0 || index >= 2)
{
qWarning("TwoSidedGraphicsWidget::widget: Index out of bounds, index == %d", index);
- return 0;
+ return nullptr;
}
return m_proxyWidgets[index]->widget();
}
@@ -289,7 +247,7 @@ void GraphicsWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
//============================================================================//
RenderOptionsDialog::RenderOptionsDialog()
- : QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
+ : QDialog(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
{
setWindowOpacity(0.75);
setWindowTitle(tr("Options (double click to flip)"));
@@ -423,7 +381,7 @@ void RenderOptionsDialog::mouseDoubleClickEvent(QMouseEvent *event)
//============================================================================//
ItemDialog::ItemDialog()
- : QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
+ : QDialog(nullptr, Qt::CustomizeWindowHint | Qt::WindowTitleHint)
{
setWindowTitle(tr("Items (double click to flip)"));
setWindowOpacity(0.75);
@@ -487,10 +445,10 @@ Scene::Scene(int width, int height, int maxTextureSize)
, m_currentTexture(0)
, m_dynamicCubemap(false)
, m_updateAllCubemaps(true)
- , m_box(0)
- , m_vertexShader(0)
- , m_environmentShader(0)
- , m_environmentProgram(0)
+ , m_box(nullptr)
+ , m_vertexShader(nullptr)
+ , m_environmentShader(nullptr)
+ , m_environmentProgram(nullptr)
{
setSceneRect(0, 0, width, height);
@@ -564,9 +522,8 @@ void Scene::initGL()
const int NOISE_SIZE = 128; // for a different size, B and BM in fbm.c must also be changed
m_noise = new GLTexture3D(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE);
- QRgb *data = new QRgb[NOISE_SIZE * NOISE_SIZE * NOISE_SIZE];
- memset(data, 0, NOISE_SIZE * NOISE_SIZE * NOISE_SIZE * sizeof(QRgb));
- QRgb *p = data;
+ QVector<QRgb> data(NOISE_SIZE * NOISE_SIZE * NOISE_SIZE, QRgb(0));
+ QRgb *p = data.data();
float pos[3];
for (int k = 0; k < NOISE_SIZE; ++k) {
pos[2] = k * (0x20 / (float)NOISE_SIZE);
@@ -581,8 +538,7 @@ void Scene::initGL()
}
}
}
- m_noise->load(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE, data);
- delete[] data;
+ m_noise->load(NOISE_SIZE, NOISE_SIZE, NOISE_SIZE, data.data());
m_mainCubemap = new GLRenderTargetCube(512);
@@ -634,7 +590,7 @@ void Scene::initGL()
m_renderOptions->addShader(file.baseName());
program->bind();
- m_cubemaps << ((program->uniformLocation("env") != -1) ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : 0);
+ m_cubemaps << ((program->uniformLocation("env") != -1) ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : nullptr);
program->release();
}
diff --git a/examples/widgets/graphicsview/boxes/scene.h b/examples/widgets/graphicsview/boxes/scene.h
index ffff01358f..5d65dc71e2 100644
--- a/examples/widgets/graphicsview/boxes/scene.h
+++ b/examples/widgets/graphicsview/boxes/scene.h
@@ -51,17 +51,12 @@
#ifndef SCENE_H
#define SCENE_H
-//#include <GL/glew.h>
+#include "glbuffers.h"
#include "glextensions.h"
-
-#include <QtWidgets>
-#include <QtOpenGL>
-
-#include "roundedbox.h"
#include "gltrianglemesh.h"
-#include "trackball.h"
-#include "glbuffers.h"
#include "qtbox.h"
+#include "roundedbox.h"
+#include "trackball.h"
QT_BEGIN_NAMESPACE
class QMatrix4x4;
@@ -116,7 +111,7 @@ private:
class GraphicsWidget : public QGraphicsProxyWidget
{
public:
- GraphicsWidget() : QGraphicsProxyWidget(0, Qt::Window) {}
+ GraphicsWidget() : QGraphicsProxyWidget(nullptr, Qt::Window) {}
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
void resizeEvent(QGraphicsSceneResizeEvent *event) override;
@@ -127,7 +122,7 @@ class TwoSidedGraphicsWidget : public QObject
{
Q_OBJECT
public:
- TwoSidedGraphicsWidget(QGraphicsScene *scene);
+ using QObject::QObject;
void setWidget(int index, QWidget *widget);
QWidget *widget(int index);
public slots:
@@ -135,10 +130,10 @@ public slots:
protected slots:
void animateFlip();
private:
- GraphicsWidget *m_proxyWidgets[2];
- int m_current;
- int m_angle; // angle in degrees
- int m_delta;
+ GraphicsWidget *m_proxyWidgets[2] = {nullptr, nullptr};
+ int m_current = 0;
+ int m_angle = 0; // angle in degrees
+ int m_delta = 0;
};
class RenderOptionsDialog : public QDialog
diff --git a/examples/widgets/graphicsview/boxes/trackball.cpp b/examples/widgets/graphicsview/boxes/trackball.cpp
index 794ce7ac37..b9dfc1fc7f 100644
--- a/examples/widgets/graphicsview/boxes/trackball.cpp
+++ b/examples/widgets/graphicsview/boxes/trackball.cpp
@@ -50,34 +50,21 @@
#include "trackball.h"
#include "scene.h"
-#include <qmath.h>
-#include <cmath>
//============================================================================//
// TrackBall //
//============================================================================//
TrackBall::TrackBall(TrackMode mode)
- : m_angularVelocity(0)
- , m_paused(false)
- , m_pressed(false)
- , m_mode(mode)
+ : TrackBall(0, QVector3D(0, 1, 0), mode)
{
- m_axis = QVector3D(0, 1, 0);
- m_rotation = QQuaternion();
- m_lastTime = QTime::currentTime();
}
TrackBall::TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode)
: m_axis(axis)
, m_angularVelocity(angularVelocity)
- , m_paused(false)
- , m_pressed(false)
, m_mode(mode)
-{
- m_rotation = QQuaternion();
- m_lastTime = QTime::currentTime();
-}
+{}
void TrackBall::push(const QPointF& p, const QQuaternion &)
{
diff --git a/examples/widgets/graphicsview/boxes/trackball.h b/examples/widgets/graphicsview/boxes/trackball.h
index e65080e089..af90e4d842 100644
--- a/examples/widgets/graphicsview/boxes/trackball.h
+++ b/examples/widgets/graphicsview/boxes/trackball.h
@@ -51,10 +51,9 @@
#ifndef TRACKBALL_H
#define TRACKBALL_H
-#include <QtWidgets>
-
-#include <QtGui/qvector3d.h>
-#include <QtGui/qquaternion.h>
+#include <QQuaternion>
+#include <QTime>
+#include <QVector3D>
class TrackBall
{
@@ -65,24 +64,24 @@ public:
Sphere,
};
TrackBall(TrackMode mode = Sphere);
- TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode = Sphere);
+ TrackBall(float angularVelocity, const QVector3D &axis, TrackMode mode = Sphere);
// coordinates in [-1,1]x[-1,1]
- void push(const QPointF& p, const QQuaternion &transformation);
- void move(const QPointF& p, const QQuaternion &transformation);
- void release(const QPointF& p, const QQuaternion &transformation);
+ void push(const QPointF &p, const QQuaternion &transformation);
+ void move(const QPointF &p, const QQuaternion &transformation);
+ void release(const QPointF &p, const QQuaternion &transformation);
void start(); // starts clock
void stop(); // stops clock
QQuaternion rotation() const;
private:
QQuaternion m_rotation;
- QVector3D m_axis;
- float m_angularVelocity;
+ QVector3D m_axis = QVector3D(0, 1, 0);
+ float m_angularVelocity = 0;
QPointF m_lastPos;
- QTime m_lastTime;
- bool m_paused;
- bool m_pressed;
+ QTime m_lastTime = QTime::currentTime();
TrackMode m_mode;
+ bool m_paused = false;
+ bool m_pressed = false;
};
#endif
diff --git a/examples/widgets/graphicsview/chip/chip.cpp b/examples/widgets/graphicsview/chip/chip.cpp
index 3d2bbdfcef..25f4ccc2e9 100644
--- a/examples/widgets/graphicsview/chip/chip.cpp
+++ b/examples/widgets/graphicsview/chip/chip.cpp
@@ -50,7 +50,9 @@
#include "chip.h"
-#include <QtWidgets>
+#include <QGraphicsSceneMouseEvent>
+#include <QPainter>
+#include <QStyleOptionGraphicsItem>
Chip::Chip(const QColor &color, int x, int y)
{
diff --git a/examples/widgets/graphicsview/chip/mainwindow.cpp b/examples/widgets/graphicsview/chip/mainwindow.cpp
index b6e1313eb2..f2f89c8722 100644
--- a/examples/widgets/graphicsview/chip/mainwindow.cpp
+++ b/examples/widgets/graphicsview/chip/mainwindow.cpp
@@ -56,13 +56,11 @@
#include <QSplitter>
MainWindow::MainWindow(QWidget *parent)
- : QWidget(parent)
+ : QWidget(parent), scene(new QGraphicsScene(this))
+ , h1Splitter(new QSplitter(this)), h2Splitter(new QSplitter(this))
{
populateScene();
- h1Splitter = new QSplitter;
- h2Splitter = new QSplitter;
-
QSplitter *vSplitter = new QSplitter;
vSplitter->setOrientation(Qt::Vertical);
vSplitter->addWidget(h1Splitter);
@@ -93,8 +91,6 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::populateScene()
{
- scene = new QGraphicsScene(this);
-
QImage image(":/qt4logo.png");
// Populate scene
diff --git a/examples/widgets/graphicsview/chip/mainwindow.h b/examples/widgets/graphicsview/chip/mainwindow.h
index 9417d12d7a..3f91b2efb4 100644
--- a/examples/widgets/graphicsview/chip/mainwindow.h
+++ b/examples/widgets/graphicsview/chip/mainwindow.h
@@ -62,7 +62,7 @@ class MainWindow : public QWidget
{
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
+ MainWindow(QWidget *parent = nullptr);
private:
void setupMatrix();
diff --git a/examples/widgets/graphicsview/chip/view.cpp b/examples/widgets/graphicsview/chip/view.cpp
index 7d5fd699a4..21998dc2df 100644
--- a/examples/widgets/graphicsview/chip/view.cpp
+++ b/examples/widgets/graphicsview/chip/view.cpp
@@ -62,7 +62,7 @@
#else
#include <QtWidgets>
#endif
-#include <qmath.h>
+#include <QtMath>
#if QT_CONFIG(wheelevent)
void GraphicsView::wheelEvent(QWheelEvent *e)
diff --git a/examples/widgets/graphicsview/chip/view.h b/examples/widgets/graphicsview/chip/view.h
index 89b2e813f1..ea7bd414f5 100644
--- a/examples/widgets/graphicsview/chip/view.h
+++ b/examples/widgets/graphicsview/chip/view.h
@@ -81,7 +81,7 @@ class View : public QFrame
{
Q_OBJECT
public:
- explicit View(const QString &name, QWidget *parent = 0);
+ explicit View(const QString &name, QWidget *parent = nullptr);
QGraphicsView *view() const;
diff --git a/examples/widgets/graphicsview/collidingmice/main.cpp b/examples/widgets/graphicsview/collidingmice/main.cpp
index dfb20815b9..ef6d6cca64 100644
--- a/examples/widgets/graphicsview/collidingmice/main.cpp
+++ b/examples/widgets/graphicsview/collidingmice/main.cpp
@@ -48,13 +48,12 @@
**
****************************************************************************/
+#include <QtMath>
#include <QtWidgets>
-#include <math.h>
-
#include "mouse.h"
-static const int MouseCount = 7;
+static constexpr int MouseCount = 7;
//! [0]
int main(int argc, char **argv)
diff --git a/examples/widgets/graphicsview/collidingmice/mouse.cpp b/examples/widgets/graphicsview/collidingmice/mouse.cpp
index a8fcc05d76..556e58d19b 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)
{
@@ -70,8 +70,7 @@ 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))
+ : color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
{
setRotation(QRandomGenerator::global()->bounded(360 * 16));
}
diff --git a/examples/widgets/graphicsview/collidingmice/mouse.h b/examples/widgets/graphicsview/collidingmice/mouse.h
index bd9e592242..4b165fced6 100644
--- a/examples/widgets/graphicsview/collidingmice/mouse.h
+++ b/examples/widgets/graphicsview/collidingmice/mouse.h
@@ -68,9 +68,9 @@ protected:
void advance(int step) override;
private:
- qreal angle;
- qreal speed;
- qreal mouseEyeDirection;
+ qreal angle = 0;
+ qreal speed = 0;
+ qreal mouseEyeDirection = 0;
QColor color;
};
//! [0]
diff --git a/examples/widgets/graphicsview/diagramscene/arrow.cpp b/examples/widgets/graphicsview/diagramscene/arrow.cpp
index 525e0b3fbb..9b2472bb33 100644
--- a/examples/widgets/graphicsview/diagramscene/arrow.cpp
+++ b/examples/widgets/graphicsview/diagramscene/arrow.cpp
@@ -50,19 +50,17 @@
#include "arrow.h"
+#include "diagramitem.h"
-#include <qmath.h>
-#include <QPen>
#include <QPainter>
+#include <QPen>
+#include <QtMath>
//! [0]
Arrow::Arrow(DiagramItem *startItem, DiagramItem *endItem, QGraphicsItem *parent)
- : QGraphicsLineItem(parent)
+ : QGraphicsLineItem(parent), myStartItem(startItem), myEndItem(endItem)
{
- myStartItem = startItem;
- myEndItem = endItem;
setFlag(QGraphicsItem::ItemIsSelectable, true);
- myColor = Qt::black;
setPen(QPen(myColor, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
}
//! [0]
@@ -98,7 +96,7 @@ void Arrow::updatePosition()
//! [4]
void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
- QWidget *)
+ QWidget *)
{
if (myStartItem->collidesWithItem(myEndItem))
return;
diff --git a/examples/widgets/graphicsview/diagramscene/arrow.h b/examples/widgets/graphicsview/diagramscene/arrow.h
index e0fa389d53..13001959bd 100644
--- a/examples/widgets/graphicsview/diagramscene/arrow.h
+++ b/examples/widgets/graphicsview/diagramscene/arrow.h
@@ -53,16 +53,7 @@
#include <QGraphicsLineItem>
-#include "diagramitem.h"
-
-QT_BEGIN_NAMESPACE
-class QGraphicsPolygonItem;
-class QGraphicsLineItem;
-class QGraphicsScene;
-class QRectF;
-class QGraphicsSceneMouseEvent;
-class QPainterPath;
-QT_END_NAMESPACE
+class DiagramItem;
//! [0]
class Arrow : public QGraphicsLineItem
@@ -71,7 +62,7 @@ public:
enum { Type = UserType + 4 };
Arrow(DiagramItem *startItem, DiagramItem *endItem,
- QGraphicsItem *parent = 0);
+ QGraphicsItem *parent = nullptr);
int type() const override { return Type; }
QRectF boundingRect() const override;
@@ -83,13 +74,14 @@ public:
void updatePosition();
protected:
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget = nullptr) override;
private:
DiagramItem *myStartItem;
DiagramItem *myEndItem;
- QColor myColor;
QPolygonF arrowHead;
+ QColor myColor = Qt::black;
};
//! [0]
diff --git a/examples/widgets/graphicsview/diagramscene/diagramitem.cpp b/examples/widgets/graphicsview/diagramscene/diagramitem.cpp
index 3aa685635e..8ec577170b 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramitem.cpp
+++ b/examples/widgets/graphicsview/diagramscene/diagramitem.cpp
@@ -58,12 +58,10 @@
//! [0]
DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
- QGraphicsItem *parent)
- : QGraphicsPolygonItem(parent)
+ QGraphicsItem *parent)
+ : QGraphicsPolygonItem(parent), myDiagramType(diagramType)
+ , myContextMenu(contextMenu)
{
- myDiagramType = diagramType;
- myContextMenu = contextMenu;
-
QPainterPath path;
switch (myDiagramType) {
case StartEnd:
@@ -101,17 +99,17 @@ DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
//! [1]
void DiagramItem::removeArrow(Arrow *arrow)
{
- int index = arrows.indexOf(arrow);
-
- if (index != -1)
- arrows.removeAt(index);
+ arrows.removeAll(arrow);
}
//! [1]
//! [2]
void DiagramItem::removeArrows()
{
- for (Arrow *arrow : qAsConst(arrows)) {
+ // need a copy here since removeArrow() will
+ // modify the arrows container
+ const auto arrowsCopy = arrows;
+ for (Arrow *arrow : arrowsCopy) {
arrow->startItem()->removeArrow(arrow);
arrow->endItem()->removeArrow(arrow);
scene()->removeItem(arrow);
diff --git a/examples/widgets/graphicsview/diagramscene/diagramitem.h b/examples/widgets/graphicsview/diagramscene/diagramitem.h
index 3a43ec57fc..ffaea4b7a8 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramitem.h
+++ b/examples/widgets/graphicsview/diagramscene/diagramitem.h
@@ -52,19 +52,12 @@
#define DIAGRAMITEM_H
#include <QGraphicsPixmapItem>
-#include <QList>
+#include <QVector>
QT_BEGIN_NAMESPACE
class QPixmap;
-class QGraphicsItem;
-class QGraphicsScene;
-class QTextEdit;
-class QGraphicsSceneMouseEvent;
-class QMenu;
class QGraphicsSceneContextMenuEvent;
-class QPainter;
-class QStyleOptionGraphicsItem;
-class QWidget;
+class QMenu;
class QPolygonF;
QT_END_NAMESPACE
@@ -77,7 +70,7 @@ public:
enum { Type = UserType + 15 };
enum DiagramType { Step, Conditional, StartEnd, Io };
- DiagramItem(DiagramType diagramType, QMenu *contextMenu, QGraphicsItem *parent = 0);
+ DiagramItem(DiagramType diagramType, QMenu *contextMenu, QGraphicsItem *parent = nullptr);
void removeArrow(Arrow *arrow);
void removeArrows();
@@ -85,7 +78,7 @@ public:
QPolygonF polygon() const { return myPolygon; }
void addArrow(Arrow *arrow);
QPixmap image() const;
- int type() const override { return Type;}
+ int type() const override { return Type; }
protected:
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
@@ -95,7 +88,7 @@ private:
DiagramType myDiagramType;
QPolygonF myPolygon;
QMenu *myContextMenu;
- QList<Arrow *> arrows;
+ QVector<Arrow *> arrows;
};
//! [0]
diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.cpp b/examples/widgets/graphicsview/diagramscene/diagramscene.cpp
index 40272834c3..d0688d8552 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramscene.cpp
+++ b/examples/widgets/graphicsview/diagramscene/diagramscene.cpp
@@ -51,8 +51,8 @@
#include "diagramscene.h"
#include "arrow.h"
-#include <QTextCursor>
#include <QGraphicsSceneMouseEvent>
+#include <QTextCursor>
//! [0]
DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
@@ -61,8 +61,8 @@ DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent)
myItemMenu = itemMenu;
myMode = MoveItem;
myItemType = DiagramItem::Step;
- line = 0;
- textItem = 0;
+ line = nullptr;
+ textItem = nullptr;
myItemColor = Qt::white;
myTextColor = Qt::black;
myLineColor = Qt::black;
@@ -188,7 +188,7 @@ void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
//! [10]
void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
- if (myMode == InsertLine && line != 0) {
+ if (myMode == InsertLine && line != nullptr) {
QLineF newLine(line->line().p1(), mouseEvent->scenePos());
line->setLine(newLine);
} else if (myMode == MoveItem) {
@@ -200,7 +200,7 @@ void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
//! [11]
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
- if (line != 0 && myMode == InsertLine) {
+ if (line != nullptr && myMode == InsertLine) {
QList<QGraphicsItem *> startItems = items(line->line().p1());
if (startItems.count() && startItems.first() == line)
startItems.removeFirst();
@@ -228,7 +228,7 @@ void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
}
}
//! [12] //! [13]
- line = 0;
+ line = nullptr;
QGraphicsScene::mouseReleaseEvent(mouseEvent);
}
//! [13]
diff --git a/examples/widgets/graphicsview/diagramscene/diagramscene.h b/examples/widgets/graphicsview/diagramscene/diagramscene.h
index 15063d58b7..5682468ef6 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramscene.h
+++ b/examples/widgets/graphicsview/diagramscene/diagramscene.h
@@ -74,7 +74,7 @@ class DiagramScene : public QGraphicsScene
public:
enum Mode { InsertItem, InsertLine, InsertText, MoveItem };
- explicit DiagramScene(QMenu *itemMenu, QObject *parent = 0);
+ explicit DiagramScene(QMenu *itemMenu, QObject *parent = nullptr);
QFont font() const { return myFont; }
QColor textColor() const { return myTextColor; }
QColor itemColor() const { return myItemColor; }
diff --git a/examples/widgets/graphicsview/diagramscene/diagramtextitem.h b/examples/widgets/graphicsview/diagramscene/diagramtextitem.h
index f5d3d3b95e..7809609e24 100644
--- a/examples/widgets/graphicsview/diagramscene/diagramtextitem.h
+++ b/examples/widgets/graphicsview/diagramscene/diagramtextitem.h
@@ -52,12 +52,8 @@
#define DIAGRAMTEXTITEM_H
#include <QGraphicsTextItem>
-#include <QPen>
QT_BEGIN_NAMESPACE
-class QFocusEvent;
-class QGraphicsItem;
-class QGraphicsScene;
class QGraphicsSceneMouseEvent;
QT_END_NAMESPACE
@@ -69,7 +65,7 @@ class DiagramTextItem : public QGraphicsTextItem
public:
enum { Type = UserType + 3 };
- DiagramTextItem(QGraphicsItem *parent = 0);
+ DiagramTextItem(QGraphicsItem *parent = nullptr);
int type() const override { return Type; }
diff --git a/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp b/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp
index 262e18a317..23fb5fda50 100644
--- a/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp
+++ b/examples/widgets/graphicsview/dragdroprobot/coloritem.cpp
@@ -48,10 +48,18 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "coloritem.h"
+#include <QApplication>
+#include <QBitmap>
+#include <QCursor>
+#include <QDrag>
+#include <QGraphicsSceneMouseEvent>
+#include <QMimeData>
+#include <QPainter>
+#include <QRandomGenerator>
+#include <QWidget>
+
//! [0]
ColorItem::ColorItem()
: color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256))
@@ -128,7 +136,7 @@ void ColorItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
QPainter painter(&pixmap);
painter.translate(15, 15);
painter.setRenderHint(QPainter::Antialiasing);
- paint(&painter, 0, 0);
+ paint(&painter, nullptr, nullptr);
painter.end();
pixmap.setMask(pixmap.createHeuristicMask());
diff --git a/examples/widgets/graphicsview/dragdroprobot/main.cpp b/examples/widgets/graphicsview/dragdroprobot/main.cpp
index 045e184569..b00e9705d4 100644
--- a/examples/widgets/graphicsview/dragdroprobot/main.cpp
+++ b/examples/widgets/graphicsview/dragdroprobot/main.cpp
@@ -48,19 +48,20 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
+#include <QGraphicsScene>
+#include <QGraphicsView>
#include "coloritem.h"
#include "robot.h"
-#include <math.h>
+#include <cmath>
+
class GraphicsView : public QGraphicsView
{
public:
- GraphicsView(QGraphicsScene *scene) : QGraphicsView(scene)
- {
- }
+ using QGraphicsView::QGraphicsView;
protected:
void resizeEvent(QResizeEvent *) override
@@ -96,7 +97,7 @@ int main(int argc, char **argv)
view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
view.setBackgroundBrush(QColor(230, 200, 167));
view.setWindowTitle("Drag and Drop Robot");
- view.show();
+ view.show();
return app.exec();
}
diff --git a/examples/widgets/graphicsview/dragdroprobot/robot.cpp b/examples/widgets/graphicsview/dragdroprobot/robot.cpp
index cc70366872..7457dabf8a 100644
--- a/examples/widgets/graphicsview/dragdroprobot/robot.cpp
+++ b/examples/widgets/graphicsview/dragdroprobot/robot.cpp
@@ -48,13 +48,17 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "robot.h"
+#include <QGraphicsSceneDragDropEvent>
+#include <QMimeData>
+#include <QPainter>
+#include <QParallelAnimationGroup>
+#include <QPropertyAnimation>
+
//! [0]
RobotPart::RobotPart(QGraphicsItem *parent)
- : QGraphicsObject(parent), color(Qt::lightGray), dragOver(false)
+ : QGraphicsObject(parent), color(Qt::lightGray)
{
setAcceptDrops(true);
}
@@ -157,11 +161,6 @@ void RobotHead::dropEvent(QGraphicsSceneDragDropEvent *event)
}
//! [8]
-RobotTorso::RobotTorso(QGraphicsItem *parent)
- : RobotPart(parent)
-{
-}
-
QRectF RobotTorso::boundingRect() const
{
return QRectF(-30, -20, 60, 60);
diff --git a/examples/widgets/graphicsview/dragdroprobot/robot.h b/examples/widgets/graphicsview/dragdroprobot/robot.h
index e25966c7c4..67f6bb4100 100644
--- a/examples/widgets/graphicsview/dragdroprobot/robot.h
+++ b/examples/widgets/graphicsview/dragdroprobot/robot.h
@@ -62,15 +62,15 @@ QT_END_NAMESPACE
class RobotPart : public QGraphicsObject
{
public:
- RobotPart(QGraphicsItem *parent = 0);
+ RobotPart(QGraphicsItem *parent = nullptr);
protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override;
void dropEvent(QGraphicsSceneDragDropEvent *event) override;
- QColor color;
- bool dragOver;
+ QColor color = Qt::lightGray;
+ bool dragOver = false;
};
//! [0]
@@ -78,10 +78,10 @@ protected:
class RobotHead : public RobotPart
{
public:
- RobotHead(QGraphicsItem *parent = 0);
+ RobotHead(QGraphicsItem *parent = nullptr);
QRectF boundingRect() const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
@@ -96,10 +96,10 @@ private:
class RobotTorso : public RobotPart
{
public:
- RobotTorso(QGraphicsItem *parent = 0);
+ using RobotPart::RobotPart;
QRectF boundingRect() const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
};
//! [2]
@@ -107,10 +107,10 @@ public:
class RobotLimb : public RobotPart
{
public:
- RobotLimb(QGraphicsItem *parent = 0);
+ RobotLimb(QGraphicsItem *parent = nullptr);
QRectF boundingRect() const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
};
//! [3]
@@ -118,10 +118,10 @@ public:
class Robot : public RobotPart
{
public:
- Robot(QGraphicsItem *parent = 0);
+ Robot(QGraphicsItem *parent = nullptr);
QRectF boundingRect() const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
};
//! [4]
diff --git a/examples/widgets/graphicsview/elasticnodes/edge.cpp b/examples/widgets/graphicsview/elasticnodes/edge.cpp
index aec12b4225..9ca8b37f3d 100644
--- a/examples/widgets/graphicsview/elasticnodes/edge.cpp
+++ b/examples/widgets/graphicsview/elasticnodes/edge.cpp
@@ -51,16 +51,14 @@
#include "edge.h"
#include "node.h"
-#include <qmath.h>
#include <QPainter>
+#include <QtMath>
//! [0]
Edge::Edge(Node *sourceNode, Node *destNode)
- : arrowSize(10)
+ : source(sourceNode), dest(destNode)
{
- setAcceptedMouseButtons(0);
- source = sourceNode;
- dest = destNode;
+ setAcceptedMouseButtons(Qt::NoButton);
source->addEdge(this);
dest->addEdge(this);
adjust();
diff --git a/examples/widgets/graphicsview/elasticnodes/edge.h b/examples/widgets/graphicsview/elasticnodes/edge.h
index 19072b8b33..048d3ffd02 100644
--- a/examples/widgets/graphicsview/elasticnodes/edge.h
+++ b/examples/widgets/graphicsview/elasticnodes/edge.h
@@ -78,7 +78,7 @@ private:
QPointF sourcePoint;
QPointF destPoint;
- qreal arrowSize;
+ qreal arrowSize = 10;
};
//! [0]
diff --git a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
index 9341d77f8d..a067f82ad7 100644
--- a/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
+++ b/examples/widgets/graphicsview/elasticnodes/graphwidget.cpp
@@ -59,7 +59,7 @@
//! [0]
GraphWidget::GraphWidget(QWidget *parent)
- : QGraphicsView(parent), timerId(0)
+ : QGraphicsView(parent)
{
QGraphicsScene *scene = new QGraphicsScene(this);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
@@ -163,7 +163,7 @@ void GraphWidget::timerEvent(QTimerEvent *event)
{
Q_UNUSED(event);
- QList<Node *> nodes;
+ QVector<Node *> nodes;
const QList<QGraphicsItem *> items = scene()->items();
for (QGraphicsItem *item : items) {
if (Node *node = qgraphicsitem_cast<Node *>(item))
@@ -190,7 +190,7 @@ void GraphWidget::timerEvent(QTimerEvent *event)
//! [5]
void GraphWidget::wheelEvent(QWheelEvent *event)
{
- scaleView(pow((double)2, -event->angleDelta().y() / 240.0));
+ scaleView(pow(2., -event->angleDelta().y() / 240.0));
}
//! [5]
#endif
diff --git a/examples/widgets/graphicsview/elasticnodes/graphwidget.h b/examples/widgets/graphicsview/elasticnodes/graphwidget.h
index 5ed6aed452..6d241fa9f1 100644
--- a/examples/widgets/graphicsview/elasticnodes/graphwidget.h
+++ b/examples/widgets/graphicsview/elasticnodes/graphwidget.h
@@ -61,7 +61,7 @@ class GraphWidget : public QGraphicsView
Q_OBJECT
public:
- GraphWidget(QWidget *parent = 0);
+ GraphWidget(QWidget *parent = nullptr);
void itemMoved();
@@ -81,7 +81,7 @@ protected:
void scaleView(qreal scaleFactor);
private:
- int timerId;
+ int timerId = 0;
Node *centerNode;
};
//! [0]
diff --git a/examples/widgets/graphicsview/elasticnodes/node.cpp b/examples/widgets/graphicsview/elasticnodes/node.cpp
index 8d44a167fa..a67e21c4b3 100644
--- a/examples/widgets/graphicsview/elasticnodes/node.cpp
+++ b/examples/widgets/graphicsview/elasticnodes/node.cpp
@@ -75,7 +75,7 @@ void Node::addEdge(Edge *edge)
edge->adjust();
}
-QList<Edge *> Node::edges() const
+QVector<Edge *> Node::edges() const
{
return edgeList;
}
diff --git a/examples/widgets/graphicsview/elasticnodes/node.h b/examples/widgets/graphicsview/elasticnodes/node.h
index 43ea1fb24b..b160ff37cc 100644
--- a/examples/widgets/graphicsview/elasticnodes/node.h
+++ b/examples/widgets/graphicsview/elasticnodes/node.h
@@ -52,13 +52,10 @@
#define NODE_H
#include <QGraphicsItem>
-#include <QList>
+#include <QVector>
class Edge;
class GraphWidget;
-QT_BEGIN_NAMESPACE
-class QGraphicsSceneMouseEvent;
-QT_END_NAMESPACE
//! [0]
class Node : public QGraphicsItem
@@ -67,7 +64,7 @@ public:
Node(GraphWidget *graphWidget);
void addEdge(Edge *edge);
- QList<Edge *> edges() const;
+ QVector<Edge *> edges() const;
enum { Type = UserType + 1 };
int type() const override { return Type; }
@@ -86,7 +83,7 @@ protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
private:
- QList<Edge *> edgeList;
+ QVector<Edge *> edgeList;
QPointF newPos;
GraphWidget *graph;
};
diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp b/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp
index f510ebc07f..6eda94e8ba 100644
--- a/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp
+++ b/examples/widgets/graphicsview/embeddeddialogs/customproxy.cpp
@@ -50,14 +50,13 @@
#include "customproxy.h"
-#include <QStyleOptionGraphicsItem>
-#include <QPainter>
#include <QGraphicsScene>
+#include <QPainter>
+#include <QStyleOptionGraphicsItem>
CustomProxy::CustomProxy(QGraphicsItem *parent, Qt::WindowFlags wFlags)
- : QGraphicsProxyWidget(parent, wFlags), popupShown(false), currentPopup(nullptr)
+ : QGraphicsProxyWidget(parent, wFlags), timeLine(new QTimeLine(250, this))
{
- timeLine = new QTimeLine(250, this);
connect(timeLine, &QTimeLine::valueChanged,
this, &CustomProxy::updateStep);
connect(timeLine, &QTimeLine::stateChanged,
@@ -99,7 +98,7 @@ void CustomProxy::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
QGraphicsProxyWidget::hoverEnterEvent(event);
scene()->setActiveWindow(this);
- if (timeLine->currentValue() != 1)
+ if (qFuzzyCompare(timeLine->currentValue(), 1))
zoomIn();
}
@@ -107,7 +106,7 @@ void CustomProxy::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
QGraphicsProxyWidget::hoverLeaveEvent(event);
if (!popupShown
- && (timeLine->direction() != QTimeLine::Backward || timeLine->currentValue() != 0)) {
+ && (timeLine->direction() != QTimeLine::Backward || qFuzzyIsNull(timeLine->currentValue()))) {
zoomOut();
}
}
diff --git a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
index 36209b7073..d7df2b7b4b 100644
--- a/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
+++ b/examples/widgets/graphicsview/embeddeddialogs/customproxy.h
@@ -59,7 +59,7 @@ class CustomProxy : public QGraphicsProxyWidget
Q_OBJECT
public:
- explicit CustomProxy(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
+ explicit CustomProxy(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = nullptr);
QRectF boundingRect() const override;
void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option,
@@ -79,8 +79,8 @@ private slots:
private:
QTimeLine *timeLine;
- bool popupShown;
- QGraphicsItem *currentPopup;
+ QGraphicsItem *currentPopup = nullptr;
+ bool popupShown = false;
};
#endif // CUSTOMPROXY_H
diff --git a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h
index 29daaa58c1..c2d87a5660 100644
--- a/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h
+++ b/examples/widgets/graphicsview/embeddeddialogs/embeddeddialog.h
@@ -64,7 +64,7 @@ class EmbeddedDialog : public QDialog
Q_OBJECT
public:
- EmbeddedDialog(QWidget *parent = 0);
+ EmbeddedDialog(QWidget *parent = nullptr);
~EmbeddedDialog();
private slots:
diff --git a/examples/widgets/graphicsview/flowlayout/flowlayout.cpp b/examples/widgets/graphicsview/flowlayout/flowlayout.cpp
index ab6bbb7aa4..54914b3746 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 = 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/tools/codecs/mainwindow.cpp b/examples/widgets/tools/codecs/mainwindow.cpp
index 53db9fe61f..6b601062b6 100644
--- a/examples/widgets/tools/codecs/mainwindow.cpp
+++ b/examples/widgets/tools/codecs/mainwindow.cpp
@@ -48,12 +48,21 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "mainwindow.h"
#include "encodingdialog.h"
#include "previewform.h"
+#include <QAction>
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QFileDialog>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QPlainTextEdit>
+#include <QRegularExpression>
+#include <QTextCodec>
+#include <QTextStream>
+
MainWindow::MainWindow()
{
textEdit = new QPlainTextEdit;
@@ -146,14 +155,14 @@ void MainWindow::findCodecs()
QTextCodec *codec = QTextCodec::codecForMib(mib);
QString sortKey = codec->name().toUpper();
- int rank;
+ char rank;
if (sortKey.startsWith(QLatin1String("UTF-8"))) {
rank = 1;
} else if (sortKey.startsWith(QLatin1String("UTF-16"))) {
rank = 2;
} else if ((match = iso8859RegExp.match(sortKey)).hasMatch()) {
- if (match.captured(1).size() == 1)
+ if (match.capturedRef(1).size() == 1)
rank = 3;
else
rank = 4;
@@ -164,7 +173,8 @@ void MainWindow::findCodecs()
codecMap.insert(sortKey, codec);
}
- codecs = codecMap.values();
+ for (const auto &codec : qAsConst(codecMap))
+ codecs += codec;
}
void MainWindow::createMenus()
diff --git a/examples/widgets/tools/codecs/mainwindow.h b/examples/widgets/tools/codecs/mainwindow.h
index 64494d1960..cf18222520 100644
--- a/examples/widgets/tools/codecs/mainwindow.h
+++ b/examples/widgets/tools/codecs/mainwindow.h
@@ -51,7 +51,7 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
-#include <QList>
+#include <QVector>
#include <QMainWindow>
QT_BEGIN_NAMESPACE
@@ -81,10 +81,10 @@ private:
void findCodecs();
void createMenus();
- QList<QAction *> saveAsActs;
+ QVector<QAction *> saveAsActs;
QPlainTextEdit *textEdit;
PreviewForm *previewForm;
- QList<QTextCodec *> codecs;
+ QVector<QTextCodec *> codecs;
EncodingDialog *m_encodingDialog = nullptr;
};
diff --git a/examples/widgets/tools/codecs/previewform.cpp b/examples/widgets/tools/codecs/previewform.cpp
index 206b5757cd..ec75ebb9fa 100644
--- a/examples/widgets/tools/codecs/previewform.cpp
+++ b/examples/widgets/tools/codecs/previewform.cpp
@@ -48,10 +48,19 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "previewform.h"
+#include <QApplication>
+#include <QComboBox>
+#include <QDesktopWidget>
+#include <QDialogButtonBox>
+#include <QGridLayout>
+#include <QLabel>
+#include <QPlainTextEdit>
+#include <QPushButton>
+#include <QTextCodec>
+#include <QTextStream>
+
// Helpers for creating hex dumps
static void indent(QTextStream &str, int indent)
{
@@ -83,8 +92,7 @@ static void formatHex(QTextStream &str, const QByteArray &data)
static void formatPrintableCharacters(QTextStream &str, const QByteArray &data)
{
- for (int i = 0, size = data.size(); i < size; ++i) {
- const char c = data.at(i);
+ for (const char c : data) {
switch (c) {
case '\0':
str << "\\0";
@@ -179,7 +187,7 @@ PreviewForm::PreviewForm(QWidget *parent)
resize(screenGeometry.width() * 2 / 5, screenGeometry.height() / 2);
}
-void PreviewForm::setCodecList(const QList<QTextCodec *> &list)
+void PreviewForm::setCodecList(const QVector<QTextCodec *> &list)
{
encodingComboBox->clear();
for (const QTextCodec *codec : list) {
@@ -226,10 +234,10 @@ void PreviewForm::updateTextEdit()
statusLabel->setText(message);
statusLabel->setStyleSheet(QStringLiteral("background-color: \"red\";"));
} else if (state.invalidChars) {
- statusLabel->setText(tr("%1: %n invalid characters", 0, state.invalidChars).arg(name));
+ statusLabel->setText(tr("%1: %n invalid characters", nullptr, state.invalidChars).arg(name));
statusLabel->setStyleSheet(QStringLiteral("background-color: \"yellow\";"));
} else {
- statusLabel->setText(tr("%1: %n bytes converted", 0, encodedData.size()).arg(name));
+ statusLabel->setText(tr("%1: %n bytes converted", nullptr, encodedData.size()).arg(name));
statusLabel->setStyleSheet(QString());
}
if (success)
diff --git a/examples/widgets/tools/codecs/previewform.h b/examples/widgets/tools/codecs/previewform.h
index 6335b6539f..02eb3533f3 100644
--- a/examples/widgets/tools/codecs/previewform.h
+++ b/examples/widgets/tools/codecs/previewform.h
@@ -52,7 +52,7 @@
#define PREVIEWFORM_H
#include <QDialog>
-#include <QList>
+#include <QVector>
QT_BEGIN_NAMESPACE
class QComboBox;
@@ -71,7 +71,7 @@ class PreviewForm : public QDialog
public:
explicit PreviewForm(QWidget *parent = nullptr);
- void setCodecList(const QList<QTextCodec *> &list);
+ void setCodecList(const QVector<QTextCodec *> &list);
void setEncodedData(const QByteArray &data);
QString decodedString() const { return decodedStr; }
diff --git a/examples/widgets/tools/completer/fsmodel.h b/examples/widgets/tools/completer/fsmodel.h
index 7b2e7b7dab..587e08b192 100644
--- a/examples/widgets/tools/completer/fsmodel.h
+++ b/examples/widgets/tools/completer/fsmodel.h
@@ -62,7 +62,7 @@
class FileSystemModel : public QFileSystemModel
{
public:
- FileSystemModel(QObject *parent = 0);
+ FileSystemModel(QObject *parent = nullptr);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
};
//! [0]
diff --git a/examples/widgets/tools/completer/mainwindow.cpp b/examples/widgets/tools/completer/mainwindow.cpp
index 114ff0fd7c..b50e0a5456 100644
--- a/examples/widgets/tools/completer/mainwindow.cpp
+++ b/examples/widgets/tools/completer/mainwindow.cpp
@@ -48,13 +48,28 @@
**
****************************************************************************/
-#include <QtWidgets>
-#include "fsmodel.h"
#include "mainwindow.h"
+#include "fsmodel.h"
+
+#include <QAction>
+#include <QApplication>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QCompleter>
+#include <QGridLayout>
+#include <QHeaderView>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QSpinBox>
+#include <QStandardItemModel>
+#include <QStringListModel>
+#include <QTreeView>
//! [0]
MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent), completer(0), lineEdit(0)
+ : QMainWindow(parent)
{
createMenu();
@@ -64,8 +79,8 @@ MainWindow::MainWindow(QWidget *parent)
modelLabel->setText(tr("Model"));
modelCombo = new QComboBox;
- modelCombo->addItem(tr("QFileSytemModel"));
- modelCombo->addItem(tr("QFileSytemModel that shows full path"));
+ modelCombo->addItem(tr("QFileSystemModel"));
+ modelCombo->addItem(tr("QFileSystemModel that shows full path"));
modelCombo->addItem(tr("Country list"));
modelCombo->addItem(tr("Word list"));
modelCombo->setCurrentIndex(0);
@@ -144,17 +159,17 @@ void MainWindow::createMenu()
connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
- QMenu* fileMenu = menuBar()->addMenu(tr("File"));
+ QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(exitAction);
- QMenu* helpMenu = menuBar()->addMenu(tr("About"));
+ QMenu *helpMenu = menuBar()->addMenu(tr("About"));
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
}
//! [4]
//! [5]
-QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
+QAbstractItemModel *MainWindow::modelFromFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QFile::ReadOnly))
@@ -170,7 +185,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
while (!file.atEnd()) {
QByteArray line = file.readLine();
if (!line.isEmpty())
- words << line.trimmed();
+ words << QString::fromUtf8(line.trimmed());
}
#ifndef QT_NO_CURSOR
@@ -191,8 +206,8 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
for (int i = 0; i < words.count(); ++i) {
QModelIndex countryIdx = m->index(i, 0);
QModelIndex symbolIdx = m->index(i, 1);
- QString country = words[i].mid(0, words[i].length() - 2).trimmed();
- QString symbol = words[i].right(2);
+ QString country = words.at(i).mid(0, words[i].length() - 2).trimmed();
+ QString symbol = words.at(i).right(2);
m->setData(countryIdx, country);
m->setData(symbolIdx, symbol);
}
@@ -233,7 +248,7 @@ void MainWindow::changeModel()
case 0:
{ // Unsorted QFileSystemModel
QFileSystemModel *fsModel = new QFileSystemModel(completer);
- fsModel->setRootPath("");
+ fsModel->setRootPath(QString());
completer->setModel(fsModel);
contentsLabel->setText(tr("Enter file path"));
}
@@ -243,7 +258,7 @@ void MainWindow::changeModel()
{ // FileSystemModel that shows full paths
FileSystemModel *fsModel = new FileSystemModel(completer);
completer->setModel(fsModel);
- fsModel->setRootPath("");
+ fsModel->setRootPath(QString());
contentsLabel->setText(tr("Enter file path"));
}
break;
diff --git a/examples/widgets/tools/completer/mainwindow.h b/examples/widgets/tools/completer/mainwindow.h
index 2bb351ec47..6e6238bf32 100644
--- a/examples/widgets/tools/completer/mainwindow.h
+++ b/examples/widgets/tools/completer/mainwindow.h
@@ -59,7 +59,6 @@ class QComboBox;
class QCompleter;
class QLabel;
class QLineEdit;
-class QProgressBar;
class QCheckBox;
class QSpinBox;
QT_END_NAMESPACE
@@ -70,7 +69,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
+ MainWindow(QWidget *parent = nullptr);
private slots:
void about();
@@ -83,16 +82,16 @@ private slots:
//! [1]
private:
void createMenu();
- QAbstractItemModel *modelFromFile(const QString& fileName);
+ QAbstractItemModel *modelFromFile(const QString &fileName);
- QComboBox *caseCombo;
- QComboBox *modeCombo;
- QComboBox *modelCombo;
- QSpinBox *maxVisibleSpinBox;
- QCheckBox *wrapCheckBox;
- QCompleter *completer;
- QLabel *contentsLabel;
- QLineEdit *lineEdit;
+ QComboBox *caseCombo = nullptr;
+ QComboBox *modeCombo = nullptr;
+ QComboBox *modelCombo = nullptr;
+ QSpinBox *maxVisibleSpinBox = nullptr;
+ QCheckBox *wrapCheckBox = nullptr;
+ QCompleter *completer = nullptr;
+ QLabel *contentsLabel = nullptr;
+ QLineEdit *lineEdit = nullptr;
};
//! [1]
diff --git a/examples/widgets/tools/customcompleter/mainwindow.cpp b/examples/widgets/tools/customcompleter/mainwindow.cpp
index 39f5f39617..b8072b505c 100644
--- a/examples/widgets/tools/customcompleter/mainwindow.cpp
+++ b/examples/widgets/tools/customcompleter/mainwindow.cpp
@@ -48,13 +48,20 @@
**
****************************************************************************/
-#include <QtWidgets>
#include "mainwindow.h"
#include "textedit.h"
+#include <QAction>
+#include <QApplication>
+#include <QCompleter>
+#include <QFile>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QStringListModel>
+
//! [0]
MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent), completer(0)
+ : QMainWindow(parent)
{
createMenu();
@@ -83,10 +90,10 @@ void MainWindow::createMenu()
connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
- QMenu* fileMenu = menuBar()->addMenu(tr("File"));
+ QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(exitAction);
- QMenu* helpMenu = menuBar()->addMenu(tr("About"));
+ QMenu *helpMenu = menuBar()->addMenu(tr("About"));
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
}
@@ -107,7 +114,7 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
while (!file.atEnd()) {
QByteArray line = file.readLine();
if (!line.isEmpty())
- words << line.trimmed();
+ words << QString::fromUtf8(line.trimmed());
}
#ifndef QT_NO_CURSOR
diff --git a/examples/widgets/tools/customcompleter/mainwindow.h b/examples/widgets/tools/customcompleter/mainwindow.h
index 436377cce7..cde553e291 100644
--- a/examples/widgets/tools/customcompleter/mainwindow.h
+++ b/examples/widgets/tools/customcompleter/mainwindow.h
@@ -55,11 +55,7 @@
QT_BEGIN_NAMESPACE
class QAbstractItemModel;
-class QComboBox;
class QCompleter;
-class QLabel;
-class QLineEdit;
-class QProgressBar;
QT_END_NAMESPACE
class TextEdit;
@@ -69,7 +65,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
+ MainWindow(QWidget *parent = nullptr);
private slots:
void about();
@@ -78,7 +74,7 @@ private:
void createMenu();
QAbstractItemModel *modelFromFile(const QString& fileName);
- QCompleter *completer;
+ QCompleter *completer = nullptr;
TextEdit *completingTextEdit;
};
//! [0]
diff --git a/examples/widgets/tools/customcompleter/textedit.cpp b/examples/widgets/tools/customcompleter/textedit.cpp
index d42f7b38bb..0d536fea3c 100644
--- a/examples/widgets/tools/customcompleter/textedit.cpp
+++ b/examples/widgets/tools/customcompleter/textedit.cpp
@@ -60,7 +60,7 @@
//! [0]
TextEdit::TextEdit(QWidget *parent)
-: QTextEdit(parent), c(0)
+ : QTextEdit(parent)
{
setPlainText(tr("This TextEdit provides autocompletions for words that have more than"
" 3 characters. You can trigger autocompletion using ") +
@@ -78,7 +78,7 @@ TextEdit::~TextEdit()
void TextEdit::setCompleter(QCompleter *completer)
{
if (c)
- QObject::disconnect(c, 0, this, 0);
+ c->disconnect(this);
c = completer;
@@ -101,7 +101,7 @@ QCompleter *TextEdit::completer() const
//! [3]
//! [4]
-void TextEdit::insertCompletion(const QString& completion)
+void TextEdit::insertCompletion(const QString &completion)
{
if (c->widget() != this)
return;
@@ -150,18 +150,19 @@ void TextEdit::keyPressEvent(QKeyEvent *e)
}
}
- bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E
+ const bool isShortcut = (e->modifiers().testFlag(Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E
if (!c || !isShortcut) // do not process the shortcut when we have a completer
QTextEdit::keyPressEvent(e);
//! [7]
//! [8]
- const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
+ const bool ctrlOrShift = e->modifiers().testFlag(Qt::ControlModifier) ||
+ e->modifiers().testFlag(Qt::ShiftModifier);
if (!c || (ctrlOrShift && e->text().isEmpty()))
return;
static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word
- bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
+ const bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
QString completionPrefix = textUnderCursor();
if (!isShortcut && (hasModifier || e->text().isEmpty()|| completionPrefix.length() < 3
diff --git a/examples/widgets/tools/customcompleter/textedit.h b/examples/widgets/tools/customcompleter/textedit.h
index d0636ab670..788cb74ae1 100644
--- a/examples/widgets/tools/customcompleter/textedit.h
+++ b/examples/widgets/tools/customcompleter/textedit.h
@@ -63,7 +63,7 @@ class TextEdit : public QTextEdit
Q_OBJECT
public:
- TextEdit(QWidget *parent = 0);
+ TextEdit(QWidget *parent = nullptr);
~TextEdit();
void setCompleter(QCompleter *c);
@@ -80,7 +80,7 @@ private:
QString textUnderCursor() const;
private:
- QCompleter *c;
+ QCompleter *c = nullptr;
};
//! [0]
diff --git a/examples/widgets/tools/echoplugin/echowindow/echointerface.h b/examples/widgets/tools/echoplugin/echowindow/echointerface.h
index 1915330e21..fb07f7fb79 100644
--- a/examples/widgets/tools/echoplugin/echowindow/echointerface.h
+++ b/examples/widgets/tools/echoplugin/echowindow/echointerface.h
@@ -51,13 +51,14 @@
#ifndef ECHOINTERFACE_H
#define ECHOINTERFACE_H
+#include <QObject>
#include <QString>
//! [0]
class EchoInterface
{
public:
- virtual ~EchoInterface() {}
+ virtual ~EchoInterface() = default;
virtual QString echo(const QString &message) = 0;
};
diff --git a/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp b/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp
index 6886a4cd88..dce6bdedc3 100644
--- a/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp
+++ b/examples/widgets/tools/echoplugin/echowindow/echowindow.cpp
@@ -48,10 +48,17 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "echowindow.h"
+#include <QCoreApplication>
+#include <QDir>
+#include <QLabel>
+#include <QLayout>
+#include <QLineEdit>
+#include <QMessageBox>
+#include <QPluginLoader>
+#include <QPushButton>
+
//! [0]
EchoWindow::EchoWindow()
{
@@ -101,7 +108,7 @@ void EchoWindow::createGUI()
//! [3]
bool EchoWindow::loadPlugin()
{
- QDir pluginsDir(qApp->applicationDirPath());
+ QDir pluginsDir(QCoreApplication::applicationDirPath());
#if defined(Q_OS_WIN)
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
pluginsDir.cdUp();
@@ -121,6 +128,7 @@ bool EchoWindow::loadPlugin()
echoInterface = qobject_cast<EchoInterface *>(plugin);
if (echoInterface)
return true;
+ pluginLoader.unload();
}
}
diff --git a/examples/widgets/tools/echoplugin/echowindow/main.cpp b/examples/widgets/tools/echoplugin/echowindow/main.cpp
index 50e3c2763b..d3cf45fcde 100644
--- a/examples/widgets/tools/echoplugin/echowindow/main.cpp
+++ b/examples/widgets/tools/echoplugin/echowindow/main.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
#include "echowindow.h"
#include "echointerface.h"
diff --git a/examples/widgets/tools/echoplugin/plugin/echoplugin.cpp b/examples/widgets/tools/echoplugin/plugin/echoplugin.cpp
index de6b6a4462..c9dd93aab8 100644
--- a/examples/widgets/tools/echoplugin/plugin/echoplugin.cpp
+++ b/examples/widgets/tools/echoplugin/plugin/echoplugin.cpp
@@ -48,8 +48,6 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "echoplugin.h"
//! [0]
diff --git a/examples/widgets/tools/i18n/languagechooser.cpp b/examples/widgets/tools/i18n/languagechooser.cpp
index e61e4432e4..2ce3471873 100644
--- a/examples/widgets/tools/i18n/languagechooser.cpp
+++ b/examples/widgets/tools/i18n/languagechooser.cpp
@@ -48,34 +48,39 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "languagechooser.h"
#include "mainwindow.h"
-LanguageChooser::LanguageChooser(const QString& defaultLang, QWidget *parent)
+#include <QCoreApplication>
+#include <QCheckBox>
+#include <QDialogButtonBox>
+#include <QDir>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QPushButton>
+#include <QTranslator>
+
+LanguageChooser::LanguageChooser(const QString &defaultLang, QWidget *parent)
: QDialog(parent, Qt::WindowStaysOnTopHint)
{
groupBox = new QGroupBox("Languages");
QGridLayout *groupBoxLayout = new QGridLayout;
- QStringList qmFiles = findQmFiles();
+ const QStringList qmFiles = findQmFiles();
for (int i = 0; i < qmFiles.size(); ++i) {
- QCheckBox *checkBox = new QCheckBox(languageName(qmFiles[i]));
- qmFileForCheckBoxMap.insert(checkBox, qmFiles[i]);
- connect(checkBox,
- QOverload<bool>::of(&QCheckBox::toggled),
- this,
- &LanguageChooser::checkBoxToggled);
- if (languageMatch(defaultLang, qmFiles[i]))
- checkBox->setCheckState(Qt::Checked);
+ const QString &qmlFile = qmFiles.at(i);
+ QCheckBox *checkBox = new QCheckBox(languageName(qmlFile));
+ qmFileForCheckBoxMap.insert(checkBox, qmlFile);
+ connect(checkBox, &QCheckBox::toggled,
+ this, &LanguageChooser::checkBoxToggled);
+ if (languageMatch(defaultLang, qmlFile))
+ checkBox->setCheckState(Qt::Checked);
groupBoxLayout->addWidget(checkBox, i / 2, i % 2);
}
groupBox->setLayout(groupBoxLayout);
buttonBox = new QDialogButtonBox;
-
showAllButton = buttonBox->addButton("Show All",
QDialogButtonBox::ActionRole);
hideAllButton = buttonBox->addButton("Hide All",
@@ -92,7 +97,7 @@ LanguageChooser::LanguageChooser(const QString& defaultLang, QWidget *parent)
setWindowTitle("I18N");
}
-bool LanguageChooser::languageMatch(const QString& lang, const QString& qmFile)
+bool LanguageChooser::languageMatch(const QString &lang, const QString &qmFile)
{
//qmFile: i18n_xx.qm
const QString prefix = "i18n_";
@@ -110,21 +115,21 @@ bool LanguageChooser::eventFilter(QObject *object, QEvent *event)
checkBox->setChecked(false);
}
}
- return QWidget::eventFilter(object, event);
+ return QDialog::eventFilter(object, event);
}
void LanguageChooser::closeEvent(QCloseEvent * /* event */)
{
- qApp->quit();
+ QCoreApplication::quit();
}
void LanguageChooser::checkBoxToggled()
{
QCheckBox *checkBox = qobject_cast<QCheckBox *>(sender());
- MainWindow *window = mainWindowForCheckBoxMap[checkBox];
+ MainWindow *window = mainWindowForCheckBoxMap.value(checkBox);
if (!window) {
QTranslator translator;
- translator.load(qmFileForCheckBoxMap[checkBox]);
+ translator.load(qmFileForCheckBoxMap.value(checkBox));
qApp->installTranslator(&translator);
window = new MainWindow;
diff --git a/examples/widgets/tools/i18n/languagechooser.h b/examples/widgets/tools/i18n/languagechooser.h
index 13363c7111..733cc50fd3 100644
--- a/examples/widgets/tools/i18n/languagechooser.h
+++ b/examples/widgets/tools/i18n/languagechooser.h
@@ -52,7 +52,7 @@
#define LANGUAGECHOOSER_H
#include <QDialog>
-#include <QMap>
+#include <QHash>
#include <QStringList>
QT_BEGIN_NAMESPACE
@@ -68,7 +68,7 @@ class LanguageChooser : public QDialog
Q_OBJECT
public:
- explicit LanguageChooser(const QString& defaultLang = QString(), QWidget *parent = 0);
+ explicit LanguageChooser(const QString &defaultLang = QString(), QWidget *parent = nullptr);
protected:
bool eventFilter(QObject *object, QEvent *event) override;
@@ -80,17 +80,17 @@ private slots:
void hideAll();
private:
- QStringList findQmFiles();
- QString languageName(const QString &qmFile);
- QColor colorForLanguage(const QString &language);
- static bool languageMatch(const QString& lang, const QString& qmFile);
+ static QStringList findQmFiles();
+ static QString languageName(const QString &qmFile);
+ static QColor colorForLanguage(const QString &language);
+ static bool languageMatch(const QString &lang, const QString &qmFile);
QGroupBox *groupBox;
QDialogButtonBox *buttonBox;
QAbstractButton *showAllButton;
QAbstractButton *hideAllButton;
- QMap<QCheckBox *, QString> qmFileForCheckBoxMap;
- QMap<QCheckBox *, MainWindow *> mainWindowForCheckBoxMap;
+ QHash<QCheckBox *, QString> qmFileForCheckBoxMap;
+ QHash<QCheckBox *, MainWindow *> mainWindowForCheckBoxMap;
};
#endif
diff --git a/examples/widgets/tools/i18n/mainwindow.cpp b/examples/widgets/tools/i18n/mainwindow.cpp
index 6ebfddfa98..a107a819ca 100644
--- a/examples/widgets/tools/i18n/mainwindow.cpp
+++ b/examples/widgets/tools/i18n/mainwindow.cpp
@@ -48,18 +48,26 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "mainwindow.h"
+#include <QAction>
+#include <QCoreApplication>
+#include <QGroupBox>
+#include <QListWidget>
+#include <QMenuBar>
+#include <QRadioButton>
+#include <QStatusBar>
+#include <QVBoxLayout>
+
static const char * const listEntries[] = {
QT_TRANSLATE_NOOP("MainWindow", "First"),
QT_TRANSLATE_NOOP("MainWindow", "Second"),
QT_TRANSLATE_NOOP("MainWindow", "Third"),
- 0
+ nullptr
};
-MainWindow::MainWindow()
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
{
centralWidget = new QWidget;
setCentralWidget(centralWidget);
@@ -67,8 +75,8 @@ MainWindow::MainWindow()
createGroupBox();
listWidget = new QListWidget;
- for (int i = 0; listEntries[i]; ++i)
- listWidget->addItem(tr(listEntries[i]));
+ for (const char *entry : listEntries)
+ listWidget->addItem(tr(entry));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(groupBox);
@@ -76,7 +84,7 @@ MainWindow::MainWindow()
centralWidget->setLayout(mainLayout);
exitAction = new QAction(tr("E&xit"), this);
- connect(exitAction, &QAction::triggered, qApp, QApplication::quit);
+ connect(exitAction, &QAction::triggered, qApp, QCoreApplication::quit);
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->setPalette(QPalette(Qt::red));
diff --git a/examples/widgets/tools/i18n/mainwindow.h b/examples/widgets/tools/i18n/mainwindow.h
index e011151894..105472d60c 100644
--- a/examples/widgets/tools/i18n/mainwindow.h
+++ b/examples/widgets/tools/i18n/mainwindow.h
@@ -67,7 +67,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow();
+ MainWindow(QWidget *parent = nullptr);
private:
void createGroupBox();
diff --git a/examples/widgets/tools/plugandpaint/app/mainwindow.cpp b/examples/widgets/tools/plugandpaint/app/mainwindow.cpp
index ebe1150eea..ff3b3614af 100644
--- a/examples/widgets/tools/plugandpaint/app/mainwindow.cpp
+++ b/examples/widgets/tools/plugandpaint/app/mainwindow.cpp
@@ -49,8 +49,8 @@
****************************************************************************/
-#include "interfaces.h"
#include "mainwindow.h"
+#include "interfaces.h"
#include "paintarea.h"
#include "plugindialog.h"
@@ -67,9 +67,8 @@
#include <QScrollArea>
#include <QTimer>
-MainWindow::MainWindow() :
- paintArea(new PaintArea),
- scrollArea(new QScrollArea)
+MainWindow::MainWindow() : paintArea(new PaintArea)
+ , scrollArea(new QScrollArea)
{
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(paintArea);
@@ -136,7 +135,11 @@ void MainWindow::brushWidth()
void MainWindow::changeBrush()
{
auto action = qobject_cast<QAction *>(sender());
+ if (!action)
+ return;
auto iBrush = qobject_cast<BrushInterface *>(action->parent());
+ if (!iBrush)
+ return;
const QString brush = action->text();
paintArea->setBrush(iBrush, brush);
@@ -147,7 +150,11 @@ void MainWindow::changeBrush()
void MainWindow::insertShape()
{
auto action = qobject_cast<QAction *>(sender());
+ if (!action)
+ return;
auto iShape = qobject_cast<ShapeInterface *>(action->parent());
+ if (!iShape)
+ return;
const QPainterPath path = iShape->generateShape(action->text(), this);
if (!path.isEmpty())
@@ -159,7 +166,11 @@ void MainWindow::insertShape()
void MainWindow::applyFilter()
{
auto action = qobject_cast<QAction *>(sender());
+ if (!action)
+ return;
auto iFilter = qobject_cast<FilterInterface *>(action->parent());
+ if (!iFilter)
+ return;
const QImage image = iFilter->filterImage(action->text(), paintArea->image(),
this);
@@ -247,7 +258,7 @@ void MainWindow::loadPlugins()
populateMenus(plugin);
//! [4] //! [5]
- pluginsDir = QDir(qApp->applicationDirPath());
+ pluginsDir = QDir(QCoreApplication::applicationDirPath());
#if defined(Q_OS_WIN)
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
diff --git a/examples/widgets/tools/plugandpaint/app/paintarea.cpp b/examples/widgets/tools/plugandpaint/app/paintarea.cpp
index e225d78398..92b8ea4777 100644
--- a/examples/widgets/tools/plugandpaint/app/paintarea.cpp
+++ b/examples/widgets/tools/plugandpaint/app/paintarea.cpp
@@ -49,14 +49,13 @@
****************************************************************************/
-#include "interfaces.h"
#include "paintarea.h"
+#include "interfaces.h"
#include <QMouseEvent>
#include <QPainter>
-PaintArea::PaintArea(QWidget *parent) :
- QWidget(parent)
+PaintArea::PaintArea(QWidget *parent) : QWidget(parent)
{
setAttribute(Qt::WA_StaticContents);
setAttribute(Qt::WA_OpaquePaintEvent);
diff --git a/examples/widgets/tools/plugandpaint/app/plugindialog.cpp b/examples/widgets/tools/plugandpaint/app/plugindialog.cpp
index 84bd364b41..204d6ffec4 100644
--- a/examples/widgets/tools/plugandpaint/app/plugindialog.cpp
+++ b/examples/widgets/tools/plugandpaint/app/plugindialog.cpp
@@ -49,8 +49,8 @@
****************************************************************************/
-#include "interfaces.h"
#include "plugindialog.h"
+#include "interfaces.h"
#include <QDir>
#include <QGridLayout>
diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp
index 3b465565ba..64f9f7a0d9 100644
--- a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp
+++ b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp
@@ -50,10 +50,10 @@
#include "basictoolsplugin.h"
+#include <QInputDialog>
+#include <QPainter>
+#include <QRandomGenerator>
#include <QtMath>
-#include <QtWidgets>
-
-#include <stdlib.h>
//! [0]
QStringList BasicToolsPlugin::brushes() const
diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h
index fd9bb9e5f3..1d9d170daa 100644
--- a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h
+++ b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.h
@@ -54,12 +54,12 @@
//! [0]
#include <interfaces.h>
-#include <QRect>
+#include <QImage>
#include <QObject>
-#include <QtPlugin>
-#include <QStringList>
#include <QPainterPath>
-#include <QImage>
+#include <QRect>
+#include <QStringList>
+#include <QtPlugin>
//! [1]
class BasicToolsPlugin : public QObject,
diff --git a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp b/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp
index 48717e34f6..30c616a830 100644
--- a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp
+++ b/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafiltersplugin.cpp
@@ -50,10 +50,7 @@
#include "extrafiltersplugin.h"
-#include <QtWidgets>
-
-#include <math.h>
-#include <stdlib.h>
+#include <QInputDialog>
QStringList ExtraFiltersPlugin::filters() const
{
diff --git a/examples/widgets/tools/regexp/regexpdialog.h b/examples/widgets/tools/regexp/regexpdialog.h
index 4bdc18da15..2f701a7228 100644
--- a/examples/widgets/tools/regexp/regexpdialog.h
+++ b/examples/widgets/tools/regexp/regexpdialog.h
@@ -65,7 +65,7 @@ class RegExpDialog : public QDialog
Q_OBJECT
public:
- RegExpDialog(QWidget *parent = 0);
+ RegExpDialog(QWidget *parent = nullptr);
private slots:
void refresh();
diff --git a/examples/widgets/tools/regularexpression/regularexpressiondialog.h b/examples/widgets/tools/regularexpression/regularexpressiondialog.h
index ba5b38b5e3..8fe85afe56 100644
--- a/examples/widgets/tools/regularexpression/regularexpressiondialog.h
+++ b/examples/widgets/tools/regularexpression/regularexpressiondialog.h
@@ -70,7 +70,7 @@ class RegularExpressionDialog : public QDialog
Q_OBJECT
public:
- RegularExpressionDialog(QWidget *parent = 0);
+ RegularExpressionDialog(QWidget *parent = nullptr);
private:
void refresh();
diff --git a/examples/widgets/tools/settingseditor/locationdialog.cpp b/examples/widgets/tools/settingseditor/locationdialog.cpp
index 5b6e2652bb..99c9834a63 100644
--- a/examples/widgets/tools/settingseditor/locationdialog.cpp
+++ b/examples/widgets/tools/settingseditor/locationdialog.cpp
@@ -48,10 +48,20 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "locationdialog.h"
+#include <QBoxLayout>
+#include <QComboBox>
+#include <QDialogButtonBox>
+#include <QDir>
+#include <QPushButton>
+#include <QGroupBox>
+#include <QHeaderView>
+#include <QLabel>
+#include <QLineEdit>
+#include <QTableWidget>
+#include <QTableWidgetItem>
+
LocationDialog::LocationDialog(QWidget *parent)
: QDialog(parent)
{
@@ -91,8 +101,7 @@ LocationDialog::LocationDialog(QWidget *parent)
locationsGroupBox = new QGroupBox(tr("Setting Locations"));
- QStringList labels;
- labels << tr("Location") << tr("Access");
+ const QStringList labels{tr("Location"), tr("Access")};
locationsTable = new QTableWidget;
locationsTable->setSelectionMode(QAbstractItemView::SingleSelection);
diff --git a/examples/widgets/tools/settingseditor/locationdialog.h b/examples/widgets/tools/settingseditor/locationdialog.h
index c25b01effd..cd2efecb0b 100644
--- a/examples/widgets/tools/settingseditor/locationdialog.h
+++ b/examples/widgets/tools/settingseditor/locationdialog.h
@@ -68,7 +68,7 @@ class LocationDialog : public QDialog
Q_OBJECT
public:
- LocationDialog(QWidget *parent = 0);
+ LocationDialog(QWidget *parent = nullptr);
QSettings::Format format() const;
QSettings::Scope scope() const;
diff --git a/examples/widgets/tools/settingseditor/mainwindow.cpp b/examples/widgets/tools/settingseditor/mainwindow.cpp
index a7a1e9b415..b9c2193ccb 100644
--- a/examples/widgets/tools/settingseditor/mainwindow.cpp
+++ b/examples/widgets/tools/settingseditor/mainwindow.cpp
@@ -48,15 +48,23 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "locationdialog.h"
#include "mainwindow.h"
#include "settingstree.h"
-MainWindow::MainWindow()
- : settingsTree(new SettingsTree)
- , locationDialog(nullptr)
+#include <QAction>
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QFileDialog>
+#include <QInputDialog>
+#include <QLineEdit>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QStandardPaths>
+#include <QStatusBar>
+
+MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
+ , settingsTree(new SettingsTree)
{
setCentralWidget(settingsTree);
diff --git a/examples/widgets/tools/settingseditor/mainwindow.h b/examples/widgets/tools/settingseditor/mainwindow.h
index 373c982afe..b1115005a9 100644
--- a/examples/widgets/tools/settingseditor/mainwindow.h
+++ b/examples/widgets/tools/settingseditor/mainwindow.h
@@ -68,7 +68,7 @@ class MainWindow : public QMainWindow
public:
typedef QSharedPointer<QSettings> SettingsPtr;
- MainWindow();
+ MainWindow(QWidget *parent = nullptr);
private slots:
void openSettings();
@@ -81,11 +81,11 @@ private:
void createActions();
void setSettingsObject(const SettingsPtr &settings);
- SettingsTree *settingsTree;
- LocationDialog *locationDialog;
- QAction *refreshAct;
- QAction *autoRefreshAct;
- QAction *fallbacksAct;
+ SettingsTree *settingsTree = nullptr;
+ LocationDialog *locationDialog = nullptr;
+ QAction *refreshAct = nullptr;
+ QAction *autoRefreshAct = nullptr;
+ QAction *fallbacksAct = nullptr;
};
#endif
diff --git a/examples/widgets/tools/settingseditor/settingstree.cpp b/examples/widgets/tools/settingseditor/settingstree.cpp
index 8585792787..b263746847 100644
--- a/examples/widgets/tools/settingseditor/settingstree.cpp
+++ b/examples/widgets/tools/settingseditor/settingstree.cpp
@@ -48,20 +48,20 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "settingstree.h"
#include "variantdelegate.h"
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QHeaderView>
+#include <QSettings>
+
SettingsTree::SettingsTree(QWidget *parent)
: QTreeWidget(parent)
- , autoRefresh(false)
{
setItemDelegate(new VariantDelegate(this));
- QStringList labels;
- labels << tr("Setting") << tr("Type") << tr("Value");
- setHeaderLabels(labels);
+ setHeaderLabels({tr("Setting"), tr("Type"), tr("Value")});
header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
header()->setSectionResizeMode(2, QHeaderView::Stretch);
@@ -77,10 +77,6 @@ SettingsTree::SettingsTree(QWidget *parent)
connect(&refreshTimer, &QTimer::timeout, this, &SettingsTree::maybeRefresh);
}
-SettingsTree::~SettingsTree()
-{
-}
-
void SettingsTree::setSettingsObject(const SettingsPtr &newSettings)
{
settings = newSettings;
@@ -137,7 +133,7 @@ void SettingsTree::refresh()
this, &SettingsTree::updateSetting);
settings->sync();
- updateChildItems(0);
+ updateChildItems(nullptr);
connect(this, &QTreeWidget::itemChanged,
this, &SettingsTree::updateSetting);
@@ -228,7 +224,7 @@ void SettingsTree::updateChildItems(QTreeWidgetItem *parent)
QTreeWidgetItem *SettingsTree::createItem(const QString &text,
QTreeWidgetItem *parent, int index)
{
- QTreeWidgetItem *after = 0;
+ QTreeWidgetItem *after = nullptr;
if (index != 0)
after = childAt(parent, index - 1);
@@ -243,24 +239,18 @@ QTreeWidgetItem *SettingsTree::createItem(const QString &text,
return item;
}
-QTreeWidgetItem *SettingsTree::childAt(QTreeWidgetItem *parent, int index)
+QTreeWidgetItem *SettingsTree::childAt(QTreeWidgetItem *parent, int index) const
{
- if (parent)
- return parent->child(index);
- else
- return topLevelItem(index);
+ return (parent ? parent->child(index) : topLevelItem(index));
}
-int SettingsTree::childCount(QTreeWidgetItem *parent)
+int SettingsTree::childCount(QTreeWidgetItem *parent) const
{
- if (parent)
- return parent->childCount();
- else
- return topLevelItemCount();
+ return (parent ? parent->childCount() : topLevelItemCount());
}
int SettingsTree::findChild(QTreeWidgetItem *parent, const QString &text,
- int startIndex)
+ int startIndex) const
{
for (int i = startIndex; i < childCount(parent); ++i) {
if (childAt(parent, i)->text(0) == text)
diff --git a/examples/widgets/tools/settingseditor/settingstree.h b/examples/widgets/tools/settingseditor/settingstree.h
index 15efa0e6aa..3e9e9658ce 100644
--- a/examples/widgets/tools/settingseditor/settingstree.h
+++ b/examples/widgets/tools/settingseditor/settingstree.h
@@ -65,10 +65,9 @@ class SettingsTree : public QTreeWidget
Q_OBJECT
public:
- typedef QSharedPointer<QSettings> SettingsPtr;
+ using SettingsPtr = QSharedPointer<QSettings>;
- SettingsTree(QWidget *parent = 0);
- ~SettingsTree();
+ SettingsTree(QWidget *parent = nullptr);
void setSettingsObject(const SettingsPtr &settings);
QSize sizeHint() const override;
@@ -89,16 +88,16 @@ private:
void updateChildItems(QTreeWidgetItem *parent);
QTreeWidgetItem *createItem(const QString &text, QTreeWidgetItem *parent,
int index);
- QTreeWidgetItem *childAt(QTreeWidgetItem *parent, int index);
- int childCount(QTreeWidgetItem *parent);
- int findChild(QTreeWidgetItem *parent, const QString &text, int startIndex);
+ QTreeWidgetItem *childAt(QTreeWidgetItem *parent, int index) const;
+ int childCount(QTreeWidgetItem *parent) const;
+ int findChild(QTreeWidgetItem *parent, const QString &text, int startIndex) const;
void moveItemForward(QTreeWidgetItem *parent, int oldIndex, int newIndex);
SettingsPtr settings;
QTimer refreshTimer;
- bool autoRefresh;
QIcon groupIcon;
QIcon keyIcon;
+ bool autoRefresh = false;
};
#endif
diff --git a/examples/widgets/tools/settingseditor/variantdelegate.cpp b/examples/widgets/tools/settingseditor/variantdelegate.cpp
index 266754ca4d..9772fe8a41 100644
--- a/examples/widgets/tools/settingseditor/variantdelegate.cpp
+++ b/examples/widgets/tools/settingseditor/variantdelegate.cpp
@@ -48,12 +48,14 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "variantdelegate.h"
+#include <QDateTime>
+#include <QLineEdit>
+#include <QRegularExpressionValidator>
+
VariantDelegate::VariantDelegate(QObject *parent)
- : QItemDelegate(parent)
+ : QStyledItemDelegate(parent)
{
boolExp.setPattern("true|false");
boolExp.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
@@ -82,12 +84,12 @@ void VariantDelegate::paint(QPainter *painter,
if (!isSupportedType(value.type())) {
QStyleOptionViewItem myOption = option;
myOption.state &= ~QStyle::State_Enabled;
- QItemDelegate::paint(painter, myOption, index);
+ QStyledItemDelegate::paint(painter, myOption, index);
return;
}
}
- QItemDelegate::paint(painter, option, index);
+ QStyledItemDelegate::paint(painter, option, index);
}
QWidget *VariantDelegate::createEditor(QWidget *parent,
@@ -95,11 +97,11 @@ QWidget *VariantDelegate::createEditor(QWidget *parent,
const QModelIndex &index) const
{
if (index.column() != 2)
- return 0;
+ return nullptr;
QVariant originalValue = index.model()->data(index, Qt::UserRole);
if (!isSupportedType(originalValue.type()))
- return 0;
+ return nullptr;
QLineEdit *lineEdit = new QLineEdit(parent);
lineEdit->setFrame(false);
@@ -149,7 +151,7 @@ QWidget *VariantDelegate::createEditor(QWidget *parent,
regExp = unsignedIntegerExp;
break;
default:
- ;
+ break;
}
if (regExp.isValid()) {
diff --git a/examples/widgets/tools/settingseditor/variantdelegate.h b/examples/widgets/tools/settingseditor/variantdelegate.h
index 7cd9fa9ee8..68f21fa3f6 100644
--- a/examples/widgets/tools/settingseditor/variantdelegate.h
+++ b/examples/widgets/tools/settingseditor/variantdelegate.h
@@ -51,15 +51,15 @@
#ifndef VARIANTDELEGATE_H
#define VARIANTDELEGATE_H
-#include <QItemDelegate>
+#include <QStyledItemDelegate>
#include <QRegularExpression>
-class VariantDelegate : public QItemDelegate
+class VariantDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
- VariantDelegate(QObject *parent = 0);
+ VariantDelegate(QObject *parent = nullptr);
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp b/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp
index 59da6a8672..765c9c2745 100644
--- a/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp
+++ b/examples/widgets/tools/styleplugin/plugin/simplestyle.cpp
@@ -48,8 +48,6 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "simplestyle.h"
void SimpleStyle::polish(QPalette &palette)
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyle.h b/examples/widgets/tools/styleplugin/plugin/simplestyle.h
index 51d6d5b77e..4f49de8cbc 100644
--- a/examples/widgets/tools/styleplugin/plugin/simplestyle.h
+++ b/examples/widgets/tools/styleplugin/plugin/simplestyle.h
@@ -53,16 +53,12 @@
#include <QProxyStyle>
-QT_BEGIN_NAMESPACE
-class QPalette;
-QT_END_NAMESPACE
-
class SimpleStyle : public QProxyStyle
{
Q_OBJECT
public:
- SimpleStyle() {};
+ SimpleStyle() = default;
void polish(QPalette &palette) override;
};
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.cpp b/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.cpp
index 344e46061c..cbe7c15cc0 100644
--- a/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.cpp
+++ b/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.cpp
@@ -48,15 +48,13 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "simplestyleplugin.h"
#include "simplestyle.h"
//! [0]
QStringList SimpleStylePlugin::keys() const
{
- return QStringList() << "SimpleStyle";
+ return {"SimpleStyle"};
}
//! [0]
@@ -65,6 +63,6 @@ QStyle *SimpleStylePlugin::create(const QString &key)
{
if (key.toLower() == "simplestyle")
return new SimpleStyle;
- return 0;
+ return nullptr;
}
//! [1]
diff --git a/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h b/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h
index 88805d4887..3ce37410eb 100644
--- a/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h
+++ b/examples/widgets/tools/styleplugin/plugin/simplestyleplugin.h
@@ -53,11 +53,6 @@
#include <QStylePlugin>
-QT_BEGIN_NAMESPACE
-class QStringList;
-class QStyle;
-QT_END_NAMESPACE
-
//! [0]
class SimpleStylePlugin : public QStylePlugin
{
@@ -65,7 +60,7 @@ class SimpleStylePlugin : public QStylePlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "simplestyle.json")
public:
- SimpleStylePlugin() {}
+ SimpleStylePlugin() = default;
QStringList keys() const;
QStyle *create(const QString &key) override;
diff --git a/examples/widgets/tools/styleplugin/stylewindow/main.cpp b/examples/widgets/tools/styleplugin/stylewindow/main.cpp
index 93816d393d..ff29eb119e 100644
--- a/examples/widgets/tools/styleplugin/stylewindow/main.cpp
+++ b/examples/widgets/tools/styleplugin/stylewindow/main.cpp
@@ -48,7 +48,8 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
+#include <QStyleFactory>
#include "stylewindow.h"
diff --git a/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp b/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp
index 7a05a3ae92..90413ed12e 100644
--- a/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp
+++ b/examples/widgets/tools/styleplugin/stylewindow/stylewindow.cpp
@@ -48,7 +48,9 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QGridLayout>
+#include <QGroupBox>
+#include <QPushButton>
#include "stylewindow.h"
diff --git a/examples/widgets/tools/treemodelcompleter/mainwindow.cpp b/examples/widgets/tools/treemodelcompleter/mainwindow.cpp
index dec3cb0496..302ccc436c 100644
--- a/examples/widgets/tools/treemodelcompleter/mainwindow.cpp
+++ b/examples/widgets/tools/treemodelcompleter/mainwindow.cpp
@@ -48,13 +48,28 @@
**
****************************************************************************/
-#include <QtWidgets>
-#include "treemodelcompleter.h"
#include "mainwindow.h"
+#include "treemodelcompleter.h"
+
+#include <QAbstractProxyModel>
+#include <QAction>
+#include <QApplication>
+#include <QCheckBox>
+#include <QComboBox>
+#include <QFile>
+#include <QGridLayout>
+#include <QHeaderView>
+#include <QLabel>
+#include <QLineEdit>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QStandardItemModel>
+#include <QStringListModel>
+#include <QTreeView>
//! [0]
MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent), completer(0), lineEdit(0)
+ : QMainWindow(parent)
{
createMenu();
@@ -151,10 +166,10 @@ void MainWindow::createMenu()
connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
- QMenu* fileMenu = menuBar()->addMenu(tr("File"));
+ QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(exitAction);
- QMenu* helpMenu = menuBar()->addMenu(tr("About"));
+ QMenu *helpMenu = menuBar()->addMenu(tr("About"));
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
}
@@ -175,7 +190,7 @@ void MainWindow::changeMode(int index)
}
//! [5]
-QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
+QAbstractItemModel *MainWindow::modelFromFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QFile::ReadOnly))
@@ -184,39 +199,35 @@ QAbstractItemModel *MainWindow::modelFromFile(const QString& fileName)
#ifndef QT_NO_CURSOR
QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
#endif
- QStringList words;
QStandardItemModel *model = new QStandardItemModel(completer);
QVector<QStandardItem *> parents(10);
parents[0] = model->invisibleRootItem();
+ QRegularExpression re("^\\s+");
while (!file.atEnd()) {
- QString line = file.readLine();
- QString trimmedLine = line.trimmed();
- if (line.isEmpty() || trimmedLine.isEmpty())
+ const QString line = QString::fromUtf8(file.readLine()).trimmed();
+ const QString trimmedLine = line.trimmed();
+ if (trimmedLine.isEmpty())
continue;
- QRegularExpression re("^\\s+");
- QRegularExpressionMatch match = re.match(line);
+ const QRegularExpressionMatch match = re.match(line);
int nonws = match.capturedStart();
int level = 0;
if (nonws == -1) {
level = 0;
} else {
- if (line.startsWith("\t")) {
- level = match.capturedLength();
- } else {
- level = match.capturedLength()/4;
- }
+ const int capLen = match.capturedLength();
+ level = line.startsWith(QLatin1Char('\t')) ? capLen / 4 : capLen;
}
- if (level+1 >= parents.size())
- parents.resize(parents.size()*2);
+ if (level + 1 >= parents.size())
+ parents.resize(parents.size() * 2);
QStandardItem *item = new QStandardItem;
item->setText(trimmedLine);
parents[level]->appendRow(item);
- parents[level+1] = item;
+ parents[level + 1] = item;
}
#ifndef QT_NO_CURSOR
@@ -252,7 +263,7 @@ void MainWindow::changeCase(int cs)
}
//! [7]
-void MainWindow::updateContentsLabel(const QString& sep)
+void MainWindow::updateContentsLabel(const QString &sep)
{
contentsLabel->setText(tr("Type path from model above with items at each level separated by a '%1'").arg(sep));
}
diff --git a/examples/widgets/tools/treemodelcompleter/mainwindow.h b/examples/widgets/tools/treemodelcompleter/mainwindow.h
index 2edcd5aab0..87f492c4ac 100644
--- a/examples/widgets/tools/treemodelcompleter/mainwindow.h
+++ b/examples/widgets/tools/treemodelcompleter/mainwindow.h
@@ -60,8 +60,6 @@ class QAbstractItemModel;
class QComboBox;
class QLabel;
class QLineEdit;
-class QProgressBar;
-class QCheckBox;
class QTreeView;
QT_END_NAMESPACE
@@ -71,27 +69,27 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
+ MainWindow(QWidget *parent = nullptr);
private slots:
void about();
void changeCase(int);
void changeMode(int);
- void highlight(const QModelIndex&);
- void updateContentsLabel(const QString&);
+ void highlight(const QModelIndex &index);
+ void updateContentsLabel(const QString &sep);
//! [0]
//! [1]
private:
void createMenu();
- QAbstractItemModel *modelFromFile(const QString& fileName);
+ QAbstractItemModel *modelFromFile(const QString &fileName);
- QTreeView *treeView;
- QComboBox *caseCombo;
- QComboBox *modeCombo;
- QLabel *contentsLabel;
- TreeModelCompleter *completer;
- QLineEdit *lineEdit;
+ QTreeView *treeView = nullptr;
+ QComboBox *caseCombo = nullptr;
+ QComboBox *modeCombo = nullptr;
+ QLabel *contentsLabel = nullptr;
+ TreeModelCompleter *completer = nullptr;
+ QLineEdit *lineEdit = nullptr;
};
//! [1]
diff --git a/examples/widgets/tools/treemodelcompleter/treemodelcompleter.cpp b/examples/widgets/tools/treemodelcompleter/treemodelcompleter.cpp
index cab0476e3c..8930c815d5 100644
--- a/examples/widgets/tools/treemodelcompleter/treemodelcompleter.cpp
+++ b/examples/widgets/tools/treemodelcompleter/treemodelcompleter.cpp
@@ -80,26 +80,20 @@ QString TreeModelCompleter::separator() const
//! [3]
QStringList TreeModelCompleter::splitPath(const QString &path) const
{
- if (sep.isNull()) {
- return QCompleter::splitPath(path);
- }
-
- return path.split(sep);
+ return (sep.isNull() ? QCompleter::splitPath(path) : path.split(sep));
}
//! [3]
//! [4]
QString TreeModelCompleter::pathFromIndex(const QModelIndex &index) const
{
- if (sep.isNull()) {
+ if (sep.isNull())
return QCompleter::pathFromIndex(index);
- }
// navigate up and accumulate data
QStringList dataList;
- for (QModelIndex i = index; i.isValid(); i = i.parent()) {
+ for (QModelIndex i = index; i.isValid(); i = i.parent())
dataList.prepend(model()->data(i, completionRole()).toString());
- }
return dataList.join(sep);
}
diff --git a/examples/widgets/tools/treemodelcompleter/treemodelcompleter.h b/examples/widgets/tools/treemodelcompleter/treemodelcompleter.h
index 1d28fddee0..d7d1852cc7 100644
--- a/examples/widgets/tools/treemodelcompleter/treemodelcompleter.h
+++ b/examples/widgets/tools/treemodelcompleter/treemodelcompleter.h
@@ -60,8 +60,8 @@ class TreeModelCompleter : public QCompleter
Q_PROPERTY(QString separator READ separator WRITE setSeparator)
public:
- explicit TreeModelCompleter(QObject *parent = 0);
- explicit TreeModelCompleter(QAbstractItemModel *model, QObject *parent = 0);
+ explicit TreeModelCompleter(QObject *parent = nullptr);
+ explicit TreeModelCompleter(QAbstractItemModel *model, QObject *parent = nullptr);
QString separator() const;
public slots:
diff --git a/examples/widgets/tools/undo/commands.cpp b/examples/widgets/tools/undo/commands.cpp
index 81561d2421..97204f9d2f 100644
--- a/examples/widgets/tools/undo/commands.cpp
+++ b/examples/widgets/tools/undo/commands.cpp
@@ -50,18 +50,16 @@
#include "commands.h"
-static const int setShapeRectCommandId = 1;
-static const int setShapeColorCommandId = 2;
+static constexpr int setShapeRectCommandId = 1;
+static constexpr int setShapeColorCommandId = 2;
/******************************************************************************
** AddShapeCommand
*/
AddShapeCommand::AddShapeCommand(Document *doc, const Shape &shape, QUndoCommand *parent)
- : QUndoCommand(parent)
+ : QUndoCommand(parent), m_doc(doc), m_shape(shape)
{
- m_doc = doc;
- m_shape = shape;
}
void AddShapeCommand::undo()
@@ -81,13 +79,11 @@ void AddShapeCommand::redo()
*/
RemoveShapeCommand::RemoveShapeCommand(Document *doc, const QString &shapeName,
- QUndoCommand *parent)
- : QUndoCommand(parent)
+ QUndoCommand *parent)
+ : QUndoCommand(parent), m_doc(doc), m_shape(doc->shape(shapeName))
+ , m_shapeName(shapeName)
{
setText(QObject::tr("Remove %1").arg(shapeName));
- m_doc = doc;
- m_shape = doc->shape(shapeName);
- m_shapeName = shapeName;
}
void RemoveShapeCommand::undo()
@@ -105,15 +101,11 @@ void RemoveShapeCommand::redo()
*/
SetShapeColorCommand::SetShapeColorCommand(Document *doc, const QString &shapeName,
- const QColor &color, QUndoCommand *parent)
- : QUndoCommand(parent)
+ const QColor &color, QUndoCommand *parent)
+ : QUndoCommand(parent), m_doc(doc), m_shapeName(shapeName)
+ , m_oldColor(doc->shape(shapeName).color()), m_newColor(color)
{
setText(QObject::tr("Set %1's color").arg(shapeName));
-
- m_doc = doc;
- m_shapeName = shapeName;
- m_oldColor = doc->shape(shapeName).color();
- m_newColor = color;
}
void SetShapeColorCommand::undo()
@@ -149,15 +141,11 @@ int SetShapeColorCommand::id() const
*/
SetShapeRectCommand::SetShapeRectCommand(Document *doc, const QString &shapeName,
- const QRect &rect, QUndoCommand *parent)
- : QUndoCommand(parent)
+ const QRect &rect, QUndoCommand *parent)
+ : QUndoCommand(parent), m_doc(doc), m_shapeName(shapeName)
+ , m_oldRect(doc->shape(shapeName).rect()), m_newRect(rect)
{
setText(QObject::tr("Change %1's geometry").arg(shapeName));
-
- m_doc = doc;
- m_shapeName = shapeName;
- m_oldRect = doc->shape(shapeName).rect();
- m_newRect = rect;
}
void SetShapeRectCommand::undo()
diff --git a/examples/widgets/tools/undo/commands.h b/examples/widgets/tools/undo/commands.h
index de3bebd740..ccb550fdd4 100644
--- a/examples/widgets/tools/undo/commands.h
+++ b/examples/widgets/tools/undo/commands.h
@@ -57,7 +57,8 @@
class AddShapeCommand : public QUndoCommand
{
public:
- AddShapeCommand(Document *doc, const Shape &shape, QUndoCommand *parent = 0);
+ AddShapeCommand(Document *doc, const Shape &shape,
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
@@ -70,7 +71,8 @@ private:
class RemoveShapeCommand : public QUndoCommand
{
public:
- RemoveShapeCommand(Document *doc, const QString &shapeName, QUndoCommand *parent = 0);
+ RemoveShapeCommand(Document *doc, const QString &shapeName,
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
@@ -83,8 +85,8 @@ private:
class SetShapeColorCommand : public QUndoCommand
{
public:
- SetShapeColorCommand(Document *doc, const QString &shapeName, const QColor &color,
- QUndoCommand *parent = 0);
+ SetShapeColorCommand(Document *doc, const QString &shapeName,
+ const QColor &color, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
@@ -102,8 +104,8 @@ private:
class SetShapeRectCommand : public QUndoCommand
{
public:
- SetShapeRectCommand(Document *doc, const QString &shapeName, const QRect &rect,
- QUndoCommand *parent = 0);
+ SetShapeRectCommand(Document *doc, const QString &shapeName,
+ const QRect &rect, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
diff --git a/examples/widgets/tools/undo/document.cpp b/examples/widgets/tools/undo/document.cpp
index 8935f98a7a..2deed83a99 100644
--- a/examples/widgets/tools/undo/document.cpp
+++ b/examples/widgets/tools/undo/document.cpp
@@ -48,14 +48,15 @@
**
****************************************************************************/
-#include <qevent.h>
+#include "document.h"
+#include "commands.h"
+
#include <QPainter>
+#include <QPaintEvent>
#include <QTextStream>
#include <QUndoStack>
-#include "document.h"
-#include "commands.h"
-static const int resizeHandleWidth = 6;
+static constexpr int resizeHandleWidth = 6;
/******************************************************************************
** Shape
@@ -96,26 +97,21 @@ QRect Shape::resizeHandle() const
QString Shape::typeToString(Type type)
{
- QString result;
-
switch (type) {
case Rectangle:
- result = QLatin1String("Rectangle");
- break;
+ return QLatin1String("Rectangle");
case Circle:
- result = QLatin1String("Circle");
- break;
+ return QLatin1String("Circle");
case Triangle:
- result = QLatin1String("Triangle");
- break;
+ return QLatin1String("Triangle");
}
- return result;
+ return QString();
}
Shape::Type Shape::stringToType(const QString &s, bool *ok)
{
- if (ok != 0)
+ if (ok != nullptr)
*ok = true;
if (s == QLatin1String("Rectangle"))
@@ -125,7 +121,7 @@ Shape::Type Shape::stringToType(const QString &s, bool *ok)
if (s == QLatin1String("Triangle"))
return Triangle;
- if (ok != 0)
+ if (ok != nullptr)
*ok = false;
return Rectangle;
}
@@ -135,10 +131,8 @@ Shape::Type Shape::stringToType(const QString &s, bool *ok)
*/
Document::Document(QWidget *parent)
- : QWidget(parent), m_currentIndex(-1), m_mousePressIndex(-1), m_resizeHandlePressed(false)
+ : QWidget(parent), m_undoStack(new QUndoStack(this))
{
- m_undoStack = new QUndoStack(this);
-
setAutoFillBackground(true);
setBackgroundRole(QPalette::Base);
diff --git a/examples/widgets/tools/undo/document.h b/examples/widgets/tools/undo/document.h
index 8076d7185c..01447ef541 100644
--- a/examples/widgets/tools/undo/document.h
+++ b/examples/widgets/tools/undo/document.h
@@ -70,7 +70,7 @@ public:
QColor color() const;
static QString typeToString(Type type);
- static Type stringToType(const QString &s, bool *ok = 0);
+ static Type stringToType(const QString &s, bool *ok = nullptr);
static const QSize minSize;
@@ -88,7 +88,7 @@ class Document : public QWidget
Q_OBJECT
public:
- Document(QWidget *parent = 0);
+ Document(QWidget *parent = nullptr);
QString addShape(const Shape &shape);
void deleteShape(const QString &shapeName);
@@ -121,14 +121,13 @@ private:
int indexAt(const QPoint &pos) const;
QString uniqueName(const QString &name) const;
- QList<Shape> m_shapeList;
- int m_currentIndex;
- int m_mousePressIndex;
+ QVector<Shape> m_shapeList;
QPoint m_mousePressOffset;
- bool m_resizeHandlePressed;
QString m_fileName;
-
- QUndoStack *m_undoStack;
+ QUndoStack *m_undoStack = nullptr;
+ int m_currentIndex = -1;
+ int m_mousePressIndex = -1;
+ bool m_resizeHandlePressed = false;
};
#endif // DOCUMENT_H
diff --git a/examples/widgets/tools/undo/mainwindow.cpp b/examples/widgets/tools/undo/mainwindow.cpp
index 118d604742..9d83e3067a 100644
--- a/examples/widgets/tools/undo/mainwindow.cpp
+++ b/examples/widgets/tools/undo/mainwindow.cpp
@@ -48,6 +48,10 @@
**
****************************************************************************/
+#include "mainwindow.h"
+#include "document.h"
+#include "commands.h"
+
#include <QUndoGroup>
#include <QUndoStack>
#include <QFileDialog>
@@ -55,9 +59,6 @@
#include <QRandomGenerator>
#include <QTextStream>
#include <QToolButton>
-#include "document.h"
-#include "mainwindow.h"
-#include "commands.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
@@ -122,17 +123,17 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::updateActions()
{
Document *doc = currentDocument();
- m_undoGroup->setActiveStack(doc == 0 ? 0 : doc->undoStack());
- QString shapeName = doc == 0 ? QString() : doc->currentShapeName();
-
- actionAddRobot->setEnabled(doc != 0);
- actionAddSnowman->setEnabled(doc != 0);
- actionAddCircle->setEnabled(doc != 0);
- actionAddRectangle->setEnabled(doc != 0);
- actionAddTriangle->setEnabled(doc != 0);
- actionClose->setEnabled(doc != 0);
- actionSave->setEnabled(doc != 0 && !doc->undoStack()->isClean());
- undoLimit->setEnabled(doc != 0 && doc->undoStack()->count() == 0);
+ m_undoGroup->setActiveStack(doc == nullptr ? nullptr : doc->undoStack());
+ QString shapeName = doc == nullptr ? QString() : doc->currentShapeName();
+
+ actionAddRobot->setEnabled(doc != nullptr);
+ actionAddSnowman->setEnabled(doc != nullptr);
+ actionAddCircle->setEnabled(doc != nullptr);
+ actionAddRectangle->setEnabled(doc != nullptr);
+ actionAddTriangle->setEnabled(doc != nullptr);
+ actionClose->setEnabled(doc != nullptr);
+ actionSave->setEnabled(doc != nullptr && !doc->undoStack()->isClean());
+ undoLimit->setEnabled(doc != nullptr && doc->undoStack()->count() == 0);
if (shapeName.isEmpty()) {
actionRed->setEnabled(false);
@@ -147,7 +148,7 @@ void MainWindow::updateActions()
actionRemoveShape->setEnabled(true);
}
- if (doc != 0) {
+ if (doc != nullptr) {
int index = documentTabs->indexOf(doc);
Q_ASSERT(index != -1);
static const QIcon unsavedIcon(":/icons/filesave.png");
@@ -264,7 +265,7 @@ void MainWindow::removeDocument(Document *doc)
void MainWindow::saveDocument()
{
Document *doc = currentDocument();
- if (doc == 0)
+ if (doc == nullptr)
return;
for (;;) {
@@ -298,7 +299,7 @@ void MainWindow::saveDocument()
void MainWindow::closeDocument()
{
Document *doc = currentDocument();
- if (doc == 0)
+ if (doc == nullptr)
return;
if (!doc->undoStack()->isClean()) {
@@ -338,10 +339,10 @@ static QRect randomRect(const QSize &s)
{
QSize min = Shape::minSize;
- int left = (int) ((0.0 + s.width() - min.width())*(QRandomGenerator::global()->bounded(1.0)));
- int top = (int) ((0.0 + s.height() - min.height())*(QRandomGenerator::global()->bounded(1.0)));
- int width = (int) ((0.0 + s.width() - left - min.width())*(QRandomGenerator::global()->bounded(1.0))) + min.width();
- int height = (int) ((0.0 + s.height() - top - min.height())*(QRandomGenerator::global()->bounded(1.0))) + min.height();
+ int left = qRound((s.width() - min.width()) * (QRandomGenerator::global()->bounded(1.0)));
+ int top = qRound((s.height() - min.height()) * (QRandomGenerator::global()->bounded(1.0)));
+ int width = qRound((s.width() - left - min.width()) * (QRandomGenerator::global()->bounded(1.0))) + min.width();
+ int height = qRound((s.height() - top - min.height()) * (QRandomGenerator::global()->bounded(1.0))) + min.height();
return QRect(left, top, width, height);
}
@@ -349,7 +350,7 @@ static QRect randomRect(const QSize &s)
void MainWindow::addShape()
{
Document *doc = currentDocument();
- if (doc == 0)
+ if (doc == nullptr)
return;
Shape::Type type;
@@ -369,7 +370,7 @@ void MainWindow::addShape()
void MainWindow::removeShape()
{
Document *doc = currentDocument();
- if (doc == 0)
+ if (doc == nullptr)
return;
QString shapeName = doc->currentShapeName();
@@ -382,7 +383,7 @@ void MainWindow::removeShape()
void MainWindow::setShapeColor()
{
Document *doc = currentDocument();
- if (doc == 0)
+ if (doc == nullptr)
return;
QString shapeName = doc->currentShapeName();
@@ -409,7 +410,7 @@ void MainWindow::setShapeColor()
void MainWindow::addSnowman()
{
Document *doc = currentDocument();
- if (doc == 0)
+ if (doc == nullptr)
return;
// Create a macro command using beginMacro() and endMacro()
@@ -427,7 +428,7 @@ void MainWindow::addSnowman()
void MainWindow::addRobot()
{
Document *doc = currentDocument();
- if (doc == 0)
+ if (doc == nullptr)
return;
// Compose a macro command by explicitly adding children to a parent command
diff --git a/examples/widgets/tools/undo/mainwindow.h b/examples/widgets/tools/undo/mainwindow.h
index 57c1f87ab2..87ee3084fb 100644
--- a/examples/widgets/tools/undo/mainwindow.h
+++ b/examples/widgets/tools/undo/mainwindow.h
@@ -61,7 +61,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindow
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
+ MainWindow(QWidget *parent = nullptr);
void addDocument(Document *doc);
void removeDocument(Document *doc);
diff --git a/examples/widgets/tools/undoframework/commands.cpp b/examples/widgets/tools/undoframework/commands.cpp
index c3e7383de1..077d7eccaa 100644
--- a/examples/widgets/tools/undoframework/commands.cpp
+++ b/examples/widgets/tools/undoframework/commands.cpp
@@ -48,19 +48,17 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "commands.h"
#include "diagramitem.h"
+#include <QGraphicsScene>
+
//! [0]
MoveCommand::MoveCommand(DiagramItem *diagramItem, const QPointF &oldPos,
- QUndoCommand *parent)
- : QUndoCommand(parent)
+ QUndoCommand *parent)
+ : QUndoCommand(parent), myDiagramItem(diagramItem)
+ , myOldPos(oldPos), newPos(diagramItem->pos())
{
- myDiagramItem = diagramItem;
- newPos = diagramItem->pos();
- myOldPos = oldPos;
}
//! [0]
@@ -71,7 +69,7 @@ bool MoveCommand::mergeWith(const QUndoCommand *command)
DiagramItem *item = moveCommand->myDiagramItem;
if (myDiagramItem != item)
- return false;
+ return false;
newPos = item->pos();
setText(QObject::tr("Move %1")
@@ -102,9 +100,8 @@ void MoveCommand::redo()
//! [4]
DeleteCommand::DeleteCommand(QGraphicsScene *scene, QUndoCommand *parent)
- : QUndoCommand(parent)
+ : QUndoCommand(parent), myGraphicsScene(scene)
{
- myGraphicsScene = scene;
QList<QGraphicsItem *> list = myGraphicsScene->selectedItems();
list.first()->setSelected(false);
myDiagramItem = static_cast<DiagramItem *>(list.first());
@@ -131,11 +128,10 @@ void DeleteCommand::redo()
//! [7]
AddCommand::AddCommand(DiagramItem::DiagramType addType,
QGraphicsScene *scene, QUndoCommand *parent)
- : QUndoCommand(parent)
+ : QUndoCommand(parent), myGraphicsScene(scene)
{
static int itemCount = 0;
- myGraphicsScene = scene;
myDiagramItem = new DiagramItem(addType);
initialPosition = QPointF((itemCount * 15) % int(scene->width()),
(itemCount * 15) % int(scene->height()));
diff --git a/examples/widgets/tools/undoframework/commands.h b/examples/widgets/tools/undoframework/commands.h
index dc53c14557..185d36d668 100644
--- a/examples/widgets/tools/undoframework/commands.h
+++ b/examples/widgets/tools/undoframework/commands.h
@@ -62,7 +62,7 @@ public:
enum { Id = 1234 };
MoveCommand(DiagramItem *diagramItem, const QPointF &oldPos,
- QUndoCommand *parent = 0);
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
@@ -80,7 +80,7 @@ private:
class DeleteCommand : public QUndoCommand
{
public:
- explicit DeleteCommand(QGraphicsScene *graphicsScene, QUndoCommand *parent = 0);
+ explicit DeleteCommand(QGraphicsScene *graphicsScene, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
@@ -96,7 +96,7 @@ class AddCommand : public QUndoCommand
{
public:
AddCommand(DiagramItem::DiagramType addType, QGraphicsScene *graphicsScene,
- QUndoCommand *parent = 0);
+ QUndoCommand *parent = nullptr);
~AddCommand();
void undo() override;
diff --git a/examples/widgets/tools/undoframework/diagramitem.cpp b/examples/widgets/tools/undoframework/diagramitem.cpp
index 723645c9b2..91da6538cf 100644
--- a/examples/widgets/tools/undoframework/diagramitem.cpp
+++ b/examples/widgets/tools/undoframework/diagramitem.cpp
@@ -48,10 +48,11 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "diagramitem.h"
+#include <QBrush>
+#include <QRandomGenerator>
+
DiagramItem::DiagramItem(DiagramType diagramType, QGraphicsItem *item)
: QGraphicsPolygonItem(item)
{
@@ -65,7 +66,9 @@ DiagramItem::DiagramItem(DiagramType diagramType, QGraphicsItem *item)
setPolygon(trianglePolygon);
}
- QColor color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256));
+ QColor color(QRandomGenerator::global()->bounded(256),
+ QRandomGenerator::global()->bounded(256),
+ QRandomGenerator::global()->bounded(256));
QBrush brush(color);
setBrush(brush);
setFlag(QGraphicsItem::ItemIsSelectable);
diff --git a/examples/widgets/tools/undoframework/diagramitem.h b/examples/widgets/tools/undoframework/diagramitem.h
index 1638dcbea8..13ff614427 100644
--- a/examples/widgets/tools/undoframework/diagramitem.h
+++ b/examples/widgets/tools/undoframework/diagramitem.h
@@ -66,9 +66,10 @@ public:
enum { Type = UserType + 1 };
enum DiagramType { Box, Triangle };
- explicit DiagramItem(DiagramType diagramType, QGraphicsItem *item = 0);
+ explicit DiagramItem(DiagramType diagramType, QGraphicsItem *item = nullptr);
- DiagramType diagramType() const {
+ DiagramType diagramType() const
+ {
return polygon() == boxPolygon ? Box : Triangle;
}
int type() const override { return Type; }
diff --git a/examples/widgets/tools/undoframework/diagramscene.cpp b/examples/widgets/tools/undoframework/diagramscene.cpp
index 63aad97cb1..65909ab6cb 100644
--- a/examples/widgets/tools/undoframework/diagramscene.cpp
+++ b/examples/widgets/tools/undoframework/diagramscene.cpp
@@ -48,27 +48,24 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "diagramscene.h"
#include "diagramitem.h"
+#include <QGraphicsSceneMouseEvent>
+
DiagramScene::DiagramScene(QObject *parent)
: QGraphicsScene(parent)
-{
- movingItem = 0;
-}
+{}
void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QPointF mousePos(event->buttonDownScenePos(Qt::LeftButton).x(),
event->buttonDownScenePos(Qt::LeftButton).y());
const QList<QGraphicsItem *> itemList = items(mousePos);
- movingItem = itemList.isEmpty() ? 0 : itemList.first();
+ movingItem = itemList.isEmpty() ? nullptr : itemList.first();
- if (movingItem != 0 && event->button() == Qt::LeftButton) {
+ if (movingItem != nullptr && event->button() == Qt::LeftButton)
oldPos = movingItem->pos();
- }
clearSelection();
QGraphicsScene::mousePressEvent(event);
@@ -76,11 +73,11 @@ void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
- if (movingItem != 0 && event->button() == Qt::LeftButton) {
+ if (movingItem != nullptr && event->button() == Qt::LeftButton) {
if (oldPos != movingItem->pos())
emit itemMoved(qgraphicsitem_cast<DiagramItem *>(movingItem),
oldPos);
- movingItem = 0;
+ movingItem = nullptr;
}
QGraphicsScene::mouseReleaseEvent(event);
}
diff --git a/examples/widgets/tools/undoframework/diagramscene.h b/examples/widgets/tools/undoframework/diagramscene.h
index b1e2804ba6..205d4162bb 100644
--- a/examples/widgets/tools/undoframework/diagramscene.h
+++ b/examples/widgets/tools/undoframework/diagramscene.h
@@ -66,7 +66,7 @@ class DiagramScene : public QGraphicsScene
Q_OBJECT
public:
- DiagramScene(QObject *parent = 0);
+ DiagramScene(QObject *parent = nullptr);
signals:
void itemMoved(DiagramItem *movedItem, const QPointF &movedFromPosition);
@@ -76,7 +76,7 @@ protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
private:
- QGraphicsItem *movingItem;
+ QGraphicsItem *movingItem = nullptr;
QPointF oldPos;
};
//! [0]
diff --git a/examples/widgets/tools/undoframework/main.cpp b/examples/widgets/tools/undoframework/main.cpp
index 51fb5c53eb..cf090f56eb 100644
--- a/examples/widgets/tools/undoframework/main.cpp
+++ b/examples/widgets/tools/undoframework/main.cpp
@@ -48,7 +48,7 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
#include "mainwindow.h"
diff --git a/examples/widgets/tools/undoframework/mainwindow.cpp b/examples/widgets/tools/undoframework/mainwindow.cpp
index e95d50d164..583af11a2b 100644
--- a/examples/widgets/tools/undoframework/mainwindow.cpp
+++ b/examples/widgets/tools/undoframework/mainwindow.cpp
@@ -48,13 +48,18 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "mainwindow.h"
#include "diagramscene.h"
#include "diagramitem.h"
#include "commands.h"
+#include <QAction>
+#include <QGraphicsView>
+#include <QMenu>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QUndoView>
+
//! [0]
MainWindow::MainWindow()
{
diff --git a/examples/widgets/tools/undoframework/mainwindow.h b/examples/widgets/tools/undoframework/mainwindow.h
index def2b7d789..c1a56e0770 100644
--- a/examples/widgets/tools/undoframework/mainwindow.h
+++ b/examples/widgets/tools/undoframework/mainwindow.h
@@ -87,22 +87,22 @@ private:
void createMenus();
void createUndoView();
- QAction *deleteAction;
- QAction *addBoxAction;
- QAction *addTriangleAction;
- QAction *undoAction;
- QAction *redoAction;
- QAction *exitAction;
- QAction *aboutAction;
+ QAction *deleteAction = nullptr;
+ QAction *addBoxAction = nullptr;
+ QAction *addTriangleAction = nullptr;
+ QAction *undoAction = nullptr;
+ QAction *redoAction = nullptr;
+ QAction *exitAction = nullptr;
+ QAction *aboutAction = nullptr;
- QMenu *fileMenu;
- QMenu *editMenu;
- QMenu *itemMenu;
- QMenu *helpMenu;
+ QMenu *fileMenu = nullptr;
+ QMenu *editMenu = nullptr;
+ QMenu *itemMenu = nullptr;
+ QMenu *helpMenu = nullptr;
- DiagramScene *diagramScene;
- QUndoStack *undoStack;
- QUndoView *undoView;
+ DiagramScene *diagramScene = nullptr;
+ QUndoStack *undoStack = nullptr;
+ QUndoView *undoView = nullptr;
};
//! [0]
diff --git a/mkspecs/common/mac.conf b/mkspecs/common/mac.conf
index b77494ec9b..61bea952b2 100644
--- a/mkspecs/common/mac.conf
+++ b/mkspecs/common/mac.conf
@@ -14,7 +14,6 @@ include(unix.conf)
QMAKE_RESOURCE = /Developer/Tools/Rez
QMAKE_EXTENSION_SHLIB = dylib
-QMAKE_EXTENSIONS_AUX_SHLIB = tbd
QMAKE_LIBDIR =
# sdk.prf will prefix the proper SDK sysroot
diff --git a/mkspecs/common/macx.conf b/mkspecs/common/macx.conf
index 889027ada5..67552dcc6c 100644
--- a/mkspecs/common/macx.conf
+++ b/mkspecs/common/macx.conf
@@ -8,7 +8,7 @@ QMAKE_MAC_SDK = macosx
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.12
QMAKE_APPLE_DEVICE_ARCHS = x86_64
QT_MAC_SDK_VERSION_MIN = 10.13
-QT_MAC_SDK_VERSION_MAX = 10.14
+QT_MAC_SDK_VERSION_MAX = 10.15
device.sdk = macosx
device.target = device
diff --git a/mkspecs/features/create_cmake.prf b/mkspecs/features/create_cmake.prf
index 5c561042cd..346fbf2467 100644
--- a/mkspecs/features/create_cmake.prf
+++ b/mkspecs/features/create_cmake.prf
@@ -42,6 +42,9 @@ CMAKE_INCLUDE_NAME = $$eval(QT.$${MODULE}.name)
# (or QtCore_{libinfix_suffix}, Foo_{libinfix_suffix} on macos with -framework).
CMAKE_QT_STEM = $${TARGET}
+# ANDROID_ABI is set by the android toolchain file, see https://developer.android.com/ndk/guides/cmake
+android: CMAKE_QT_STEM = $$replace(CMAKE_QT_STEM, "_$${QT_ARCH}", '_\$\{ANDROID_ABI\}')
+
# On macOS when building just a debug configuration which is not part of debug_and_release,
# $${TARGET} already contains a _debug suffix, as per the following call chain:
# qt_module.prf -> qt5LibraryTarget -> qtLibraryTarget -> qtPlatformTargetSuffix.
@@ -297,7 +300,8 @@ mac {
CMAKE_PRL_FILE_LOCATION_RELEASE = lib$${CMAKE_QT_STEM}.prl
} else {
qt_framework {
- CMAKE_LIB_FILE_LOCATION_DEBUG = $${CMAKE_QT_STEM}.framework/$${CMAKE_QT_STEM}_debug
+ # Intentionally there is no '_debug' infix for framework builds.
+ CMAKE_LIB_FILE_LOCATION_DEBUG = $${CMAKE_QT_STEM}.framework/$${CMAKE_QT_STEM}
CMAKE_LIB_FILE_LOCATION_RELEASE = $${CMAKE_QT_STEM}.framework/$${CMAKE_QT_STEM}
CMAKE_BUILD_IS_FRAMEWORK = "true"
} else {
diff --git a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
index 4d3dc1bd35..364c23e750 100644
--- a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
+++ b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
@@ -53,7 +53,11 @@ function(_qt5_$${CMAKE_MODULE_NAME}_process_prl_file prl_file_location Configura
set(_lib_deps)
set(_link_flags)
- get_filename_component(_qt5_install_libs \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/lib\" ABSOLUTE)
+!!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
+ set(_qt5_install_libs \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}\")
+!!ELSE
+ set(_qt5_install_libs \"$${CMAKE_LIB_DIR}\")
+!!ENDIF
if(EXISTS \"${prl_file_location}\")
file(STRINGS \"${prl_file_location}\" _prl_strings REGEX \"QMAKE_PRL_LIBS_FOR_CMAKE[ \\t]*=\")
diff --git a/mkspecs/features/qmake_use.prf b/mkspecs/features/qmake_use.prf
index ecb4f7ed41..8475e4111a 100644
--- a/mkspecs/features/qmake_use.prf
+++ b/mkspecs/features/qmake_use.prf
@@ -22,6 +22,8 @@ for(ever) {
!defined(QMAKE_LIBS_$$nu, var): \
error("Library '$$lower($$replace(nu, _, -))' is not defined.")
+ QMAKE_LIBDIR += $$eval(QMAKE_LIBDIR_$$nu)
+
android {
ABI_LIBS = $$eval(QMAKE_LIBS_$${nu}_$${QT_ARCH})
isEmpty(ABI_LIBS): ABI_LIBS = $$eval(QMAKE_LIBS_$${nu})
diff --git a/mkspecs/features/qt_configure.prf b/mkspecs/features/qt_configure.prf
index 1219fe1443..52baca1fbb 100644
--- a/mkspecs/features/qt_configure.prf
+++ b/mkspecs/features/qt_configure.prf
@@ -537,98 +537,23 @@ defineReplace(qtGccSysrootifiedPaths) {
return($$sysrootified)
}
-# libs-var, libs, in-paths, out-paths-var
+# libs-var, libs, in-paths
defineTest(qtConfResolveLibs) {
- ret = true
- paths = $$3
- out =
- copy = false
- for (l, 2) {
- $$copy {
- copy = false
- out += $$l
- } else: equals(l, "-s") {
- # em++ flag to link libraries from emscripten-ports; passed on literally.
- copy = true
- out += $$l
- } else: contains(l, "^-L.*") {
- lp = $$replace(l, "^-L", )
- gcc: lp = $$qtGccSysrootifiedPath($$lp)
- !exists($$lp/.) {
- qtLog("Library path $$val_escape(lp) is invalid.")
- ret = false
- } else {
- paths += $$lp
- }
- } else: !android: contains(l, "^-l.*") {
- lib = $$replace(l, "^-l", )
- lcan =
- integrity:contains(lib, "^.*\\.a") {
- # INTEGRITY compiler searches for exact filename
- # if -l argument has .a suffix
- lcan += $${lib}
- } else: contains(lib, "^:.*") {
- # Use exact filename when -l:filename syntax is used.
- lib ~= s/^://
- lcan += $${lib}
- } else: unix {
- # Under UNIX, we look for actual shared libraries, in addition
- # to static ones.
- shexts = $$QMAKE_EXTENSION_SHLIB $$QMAKE_EXTENSIONS_AUX_SHLIB
- for (ext, shexts) {
- lcan += $${QMAKE_PREFIX_SHLIB}$${lib}.$${ext}
- }
- lcan += \
- $${QMAKE_PREFIX_STATICLIB}$${lib}.$${QMAKE_EXTENSION_STATICLIB}
- } else {
- # Under Windows, we look only for static libraries, as even for DLLs
- # one actually links against a static import library.
- mingw {
- lcan += \
- # MinGW supports UNIX-style library naming in addition to
- # the MSVC style.
- lib$${lib}.dll.a lib$${lib}.a \
- # Fun fact: prefix-less libraries are also supported.
- $${lib}.dll.a $${lib}.a
- }
- lcan += $${lib}.lib
- }
- l = $$qtConfFindInPathList($$lcan, $$paths $$EXTRA_LIBDIR $$QMAKE_DEFAULT_LIBDIRS)
- isEmpty(l) {
- qtLog("None of [$$val_escape(lcan)] found in [$$val_escape(paths)] and global paths.")
- ret = false
- } else {
- out += $$l
- }
- } else {
- out += $$l
- }
- }
- $$1 = $$out
+ for (path, 3): \
+ pre_lflags += -L$$path
+ $$1 = $$pre_lflags $$2
export($$1)
- !isEmpty(4) {
- $$4 = $$paths
- export($$4)
- }
- return($$ret)
-}
-
-# source-var
-defineTest(qtConfResolveAllLibs) {
- ret = true
- !qtConfResolveLibs($${1}.libs, $$eval($${1}.libs), , $${1}.libdirs): \
- ret = false
- for (b, $${1}.builds._KEYS_): \
- !qtConfResolveLibs($${1}.builds.$${b}, $$eval($${1}.builds.$${b}), $$eval($${1}.libdirs), ): \
- ret = false
- return($$ret)
+ return(true)
}
# libs-var, in-paths, libs
defineTest(qtConfResolvePathLibs) {
ret = true
- gcc: 2 = $$qtGccSysrootifiedPaths($$2)
- for (libdir, 2) {
+ gcc: \
+ local_paths = $$qtGccSysrootifiedPaths($$2)
+ else: \
+ local_paths = $$2
+ for (libdir, local_paths) {
!exists($$libdir/.) {
qtLog("Library path $$val_escape(libdir) is invalid.")
ret = false
@@ -678,8 +603,11 @@ defineReplace(qtConfGetTestIncludes) {
# includes-var, in-paths, test-object-var
defineTest(qtConfResolvePathIncs) {
ret = true
- gcc: 2 = $$qtGccSysrootifiedPaths($$2)
- for (incdir, 2) {
+ gcc: \
+ local_paths = $$qtGccSysrootifiedPaths($$2)
+ else: \
+ local_paths = $$2
+ for (incdir, local_paths) {
!exists($$incdir/.) {
qtLog("Include path $$val_escape(incdir) is invalid.")
ret = false
@@ -773,11 +701,9 @@ defineTest(qtConfLibrary_inline) {
for (ld, libdir): \
libs += -L$$ld
$${1}.libs = $$libs $$eval($${1}.libs)
+ export($${1}.libs)
}
- !qtConfResolveAllLibs($$1): \
- return(false)
-
!qtConfResolvePathIncs($${1}.includedir, $$includes, $$2): \
return(false)
diff --git a/qmake/generators/mac/pbuilder_pbx.cpp b/qmake/generators/mac/pbuilder_pbx.cpp
index 28cf02344d..24e69444c9 100644
--- a/qmake/generators/mac/pbuilder_pbx.cpp
+++ b/qmake/generators/mac/pbuilder_pbx.cpp
@@ -509,6 +509,56 @@ static QList<QVariantMap> provisioningTeams()
return flatTeams;
}
+bool ProjectBuilderMakefileGenerator::replaceLibrarySuffix(const QString &lib_file,
+ const ProString &opt,
+ QString &name, QString &library)
+{
+ /* This isn't real nice, but it is real useful. This looks in a prl
+ for what the library will ultimately be called so we can stick it
+ in the ProjectFile. If the prl format ever changes (not likely) then
+ this will not really work. However, more concerning is that it will
+ encode the version number in the Project file which might be a bad
+ things in days to come? --Sam
+ */
+ if (lib_file.isEmpty())
+ return false;
+
+ QMakeMetaInfo libinfo;
+ if (!libinfo.readLib(lib_file) || libinfo.isEmpty("QMAKE_PRL_TARGET"))
+ return false;
+
+ const QString libDir = fileInfo(lib_file).absolutePath();
+ library = libDir + Option::dir_sep + libinfo.first("QMAKE_PRL_TARGET");
+
+ debug_msg(1, "pbuilder: Found library (%s) via PRL %s (%s)",
+ opt.toLatin1().constData(), lib_file.toLatin1().constData(), library.toLatin1().constData());
+
+ if (project->isActiveConfig("xcode_dynamic_library_suffix")) {
+ QString suffixSetting = project->first("QMAKE_XCODE_LIBRARY_SUFFIX_SETTING").toQString();
+ if (!suffixSetting.isEmpty()) {
+ QString librarySuffix = project->first("QMAKE_XCODE_LIBRARY_SUFFIX").toQString();
+ suffixSetting = "$(" + suffixSetting + ")";
+ if (!librarySuffix.isEmpty()) {
+ int pos = library.lastIndexOf(librarySuffix + '.');
+ if (pos == -1) {
+ warn_msg(WarnLogic, "Failed to find expected suffix '%s' for library '%s'.",
+ qPrintable(librarySuffix), qPrintable(library));
+ } else {
+ library.replace(pos, librarySuffix.length(), suffixSetting);
+ if (name.endsWith(librarySuffix))
+ name.chop(librarySuffix.length());
+ }
+ } else {
+ int pos = library.lastIndexOf(name);
+ if (pos != -1)
+ library.insert(pos + name.length(), suffixSetting);
+ }
+ }
+ }
+
+ return true;
+}
+
bool
ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t)
{
@@ -820,6 +870,7 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t)
}
if(!project->isActiveConfig("staticlib")) { //DUMP LIBRARIES
+ const ProStringList defaultLibDirs = project->values("QMAKE_DEFAULT_LIBDIRS");
ProStringList &libdirs = project->values("QMAKE_PBX_LIBPATHS"),
&frameworkdirs = project->values("QMAKE_FRAMEWORKPATH");
static const char * const libs[] = { "LIBS", "LIBS_PRIVATE",
@@ -827,6 +878,7 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t)
for (int i = 0; libs[i]; i++) {
tmp = project->values(libs[i]);
for(int x = 0; x < tmp.count();) {
+ bool libSuffixReplaced = false;
bool remove = false;
QString library, name;
ProString opt = tmp[x];
@@ -839,49 +891,12 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t)
QString lib("lib" + name);
for (ProStringList::Iterator lit = libdirs.begin(); lit != libdirs.end(); ++lit) {
if(project->isActiveConfig("link_prl")) {
- /* This isn't real nice, but it is real useful. This looks in a prl
- for what the library will ultimately be called so we can stick it
- in the ProjectFile. If the prl format ever changes (not likely) then
- this will not really work. However, more concerning is that it will
- encode the version number in the Project file which might be a bad
- things in days to come? --Sam
- */
- QString lib_file = QMakeMetaInfo::checkLib(Option::normalizePath(
- (*lit) + Option::dir_sep + lib + Option::prl_ext));
- if (!lib_file.isEmpty()) {
- QMakeMetaInfo libinfo;
- if(libinfo.readLib(lib_file)) {
- if(!libinfo.isEmpty("QMAKE_PRL_TARGET")) {
- library = (*lit) + Option::dir_sep + libinfo.first("QMAKE_PRL_TARGET");
- debug_msg(1, "pbuilder: Found library (%s) via PRL %s (%s)",
- opt.toLatin1().constData(), lib_file.toLatin1().constData(), library.toLatin1().constData());
- remove = true;
-
- if (project->isActiveConfig("xcode_dynamic_library_suffix")) {
- QString suffixSetting = project->first("QMAKE_XCODE_LIBRARY_SUFFIX_SETTING").toQString();
- if (!suffixSetting.isEmpty()) {
- QString librarySuffix = project->first("QMAKE_XCODE_LIBRARY_SUFFIX").toQString();
- suffixSetting = "$(" + suffixSetting + ")";
- if (!librarySuffix.isEmpty()) {
- int pos = library.lastIndexOf(librarySuffix + '.');
- if (pos == -1) {
- warn_msg(WarnLogic, "Failed to find expected suffix '%s' for library '%s'.",
- qPrintable(librarySuffix), qPrintable(library));
- } else {
- library.replace(pos, librarySuffix.length(), suffixSetting);
- if (name.endsWith(librarySuffix))
- name.chop(librarySuffix.length());
- }
- } else {
- int pos = library.lastIndexOf(name);
- if (pos != -1)
- library.insert(pos + name.length(), suffixSetting);
- }
- }
- }
- }
- }
- }
+ const QString prlFilePath = QMakeMetaInfo::checkLib(
+ Option::normalizePath((*lit) + Option::dir_sep + lib
+ + Option::prl_ext));
+ if (replaceLibrarySuffix(prlFilePath, opt, name, library))
+ remove = true;
+ libSuffixReplaced = true;
}
if(!remove) {
QString extns[] = { ".dylib", ".so", ".a", QString() };
@@ -931,6 +946,16 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t)
}
}
if(!library.isEmpty()) {
+ if (!libSuffixReplaced) {
+ const QFileInfo fi = fileInfo(library);
+ const QString prlFilePath = QMakeMetaInfo::checkLib(
+ Option::normalizePath(fi.absolutePath() + '/' + fi.completeBaseName()
+ + Option::prl_ext));
+ if (!prlFilePath.isEmpty()) {
+ name = fi.completeBaseName().mid(3);
+ replaceLibrarySuffix(prlFilePath, opt, name, library);
+ }
+ }
const int slsh = library.lastIndexOf(Option::dir_sep);
if(name.isEmpty()) {
if(slsh != -1)
@@ -938,8 +963,10 @@ ProjectBuilderMakefileGenerator::writeMakeParts(QTextStream &t)
}
if(slsh != -1) {
const QString path = QFileInfo(library.left(slsh)).absoluteFilePath();
- if(!path.isEmpty() && !libdirs.contains(path))
+ if (!path.isEmpty() && !libdirs.contains(path)
+ && !defaultLibDirs.contains(path)) {
libdirs += path;
+ }
}
library = fileFixify(library, FileFixifyFromOutdir | FileFixifyAbsolute);
QString key = keyFor(library);
diff --git a/qmake/generators/mac/pbuilder_pbx.h b/qmake/generators/mac/pbuilder_pbx.h
index ac0d63606d..1b90a3bbeb 100644
--- a/qmake/generators/mac/pbuilder_pbx.h
+++ b/qmake/generators/mac/pbuilder_pbx.h
@@ -41,6 +41,8 @@ class ProjectBuilderMakefileGenerator : public UnixMakefileGenerator
bool writeSubDirs(QTextStream &);
bool writeMakeParts(QTextStream &);
bool writeMakefile(QTextStream &) override;
+ bool replaceLibrarySuffix(const QString &lib_file, const ProString &opt, QString &name,
+ QString &library);
QString pbxbuild();
QHash<QString, QString> keys;
diff --git a/qmake/generators/unix/unixmake2.cpp b/qmake/generators/unix/unixmake2.cpp
index 8b4f2bf58f..ccb601d4b8 100644
--- a/qmake/generators/unix/unixmake2.cpp
+++ b/qmake/generators/unix/unixmake2.cpp
@@ -1199,8 +1199,10 @@ void UnixMakefileGenerator::init2()
project->values("QMAKE_FRAMEWORK_VERSION").append(project->first("VER_MAJ"));
if (project->first("TEMPLATE") == "aux") {
- project->values("PRL_TARGET") =
- project->values("TARGET").first().prepend(project->first("QMAKE_PREFIX_STATICLIB"));
+ project->values("PRL_TARGET") = {
+ project->first("QMAKE_PREFIX_STATICLIB") +
+ project->first("TARGET")
+ };
} else if (!project->values("QMAKE_APP_FLAG").isEmpty()) {
if(!project->isEmpty("QMAKE_BUNDLE")) {
ProString bundle_loc = project->first("QMAKE_BUNDLE_LOCATION");
diff --git a/qmake/option.cpp b/qmake/option.cpp
index d8143468e6..9ec2fe6411 100644
--- a/qmake/option.cpp
+++ b/qmake/option.cpp
@@ -658,4 +658,9 @@ QString qmake_libraryInfoFile()
return QString();
}
+QString qmake_abslocation()
+{
+ return Option::globals->qmake_abslocation;
+}
+
QT_END_NAMESPACE
diff --git a/src/corelib/configure.json b/src/corelib/configure.json
index f7b6d41534..ae360239c6 100644
--- a/src/corelib/configure.json
+++ b/src/corelib/configure.json
@@ -158,21 +158,6 @@
"-latomic"
]
},
- "libdl": {
- "label": "dlopen()",
- "test": {
- "main": [
- "dlclose(dlopen(0, 0));",
- "dlsym(RTLD_DEFAULT, 0);",
- "dlerror();"
- ]
- },
- "headers": "dlfcn.h",
- "sources": [
- "",
- "-ldl"
- ]
- },
"librt": {
"label": "clock_gettime()",
"test": {
@@ -612,11 +597,6 @@
"condition": "features.clock-gettime && tests.clock-monotonic",
"output": [ "feature" ]
},
- "dlopen": {
- "label": "dlopen()",
- "condition": "config.unix && libs.libdl",
- "output": [ "privateFeature" ]
- },
"doubleconversion": {
"label": "DoubleConversion",
"output": [ "privateFeature", "feature" ]
diff --git a/src/corelib/corelib.pro b/src/corelib/corelib.pro
index 121db51eb5..ba5f5adf8d 100644
--- a/src/corelib/corelib.pro
+++ b/src/corelib/corelib.pro
@@ -21,7 +21,7 @@ CONFIG += simd optimize_full
QMAKE_DOCS = $$PWD/doc/qtcore.qdocconf
ANDROID_LIB_DEPENDENCIES = \
- plugins/platforms/android/libqtforandroid.so
+ plugins/platforms/libqtforandroid.so
ANDROID_BUNDLED_JAR_DEPENDENCIES = \
jar/QtAndroid.jar
ANDROID_PERMISSIONS = \
diff --git a/src/corelib/doc/snippets/hellotrmain.cpp b/src/corelib/doc/snippets/hellotrmain.cpp
index 2fab919a47..721a83240b 100644
--- a/src/corelib/doc/snippets/hellotrmain.cpp
+++ b/src/corelib/doc/snippets/hellotrmain.cpp
@@ -56,13 +56,13 @@ int main(int argc, char *argv[])
QTranslator translator;
// look up e.g. :/translations/myapp_de.qm
if (translator.load(QLocale(), QLatin1String("myapp"), QLatin1String("_"), QLatin1String(":/translations")))
- app.installTranslator(&translator);
+ QCoreApplication::installTranslator(&translator);
QPushButton hello(QCoreApplication::translate("main", "Hello world!"));
hello.resize(100, 30);
hello.show();
- return app.exec();
+ return QCoreApplication::exec();
}
//! [0]
diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp
index 4c1b04f05e..c7357f9d13 100644
--- a/src/corelib/global/qlibraryinfo.cpp
+++ b/src/corelib/global/qlibraryinfo.cpp
@@ -55,15 +55,24 @@ QT_END_NAMESPACE
# include "qcoreapplication.h"
#endif
+#ifndef QT_BUILD_QMAKE_BOOTSTRAP
+# include "private/qglobal_p.h"
+# include "qconfig.cpp"
+#endif
+
#ifdef Q_OS_DARWIN
# include "private/qcore_mac_p.h"
-#endif
+#endif // Q_OS_DARWIN
-#ifndef QT_BUILD_QMAKE_BOOTSTRAP
-# include "qconfig.cpp"
+#include "archdetect.cpp"
+
+#if !defined(QT_BUILD_QMAKE) && QT_CONFIG(relocatable) && QT_CONFIG(dlopen) && !QT_CONFIG(framework)
+# include <dlfcn.h>
#endif
-#include "archdetect.cpp"
+#if !defined(QT_BUILD_QMAKE) && QT_CONFIG(relocatable) && defined(Q_OS_WIN)
+# include <qt_windows.h>
+#endif
QT_BEGIN_NAMESPACE
@@ -453,6 +462,160 @@ void QLibraryInfo::sysrootify(QString *path)
}
#endif // QT_BUILD_QMAKE
+#ifndef QT_BUILD_QMAKE
+static QString prefixFromAppDirHelper()
+{
+ QString appDir;
+
+ if (QCoreApplication::instance()) {
+#ifdef Q_OS_DARWIN
+ CFBundleRef bundleRef = CFBundleGetMainBundle();
+ if (bundleRef) {
+ QCFType<CFURLRef> urlRef = CFBundleCopyBundleURL(bundleRef);
+ if (urlRef) {
+ QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
+#ifdef Q_OS_MACOS
+ QString bundleContentsDir = QString(path) + QLatin1String("/Contents/");
+ if (QDir(bundleContentsDir).exists())
+ return QDir::cleanPath(bundleContentsDir);
+#else
+ return QDir::cleanPath(QString(path)); // iOS
+#endif // Q_OS_MACOS
+ }
+ }
+#endif // Q_OS_DARWIN
+ // We make the prefix path absolute to the executable's directory.
+ appDir = QCoreApplication::applicationDirPath();
+ } else {
+ appDir = QDir::currentPath();
+ }
+
+ return appDir;
+}
+#endif
+
+#if !defined(QT_BUILD_QMAKE) && QT_CONFIG(relocatable)
+static QString prefixFromQtCoreLibraryHelper(const QString &qtCoreLibraryPath)
+{
+ const QString qtCoreLibrary = QDir::fromNativeSeparators(qtCoreLibraryPath);
+ const QString libDir = QFileInfo(qtCoreLibrary).absolutePath();
+ const QString prefixDir = libDir + QLatin1Char('/')
+ + QLatin1String(QT_CONFIGURE_LIBLOCATION_TO_PREFIX_PATH);
+ return QDir::cleanPath(prefixDir);
+}
+
+#if defined(Q_OS_WIN)
+#if defined(Q_OS_WINRT)
+EXTERN_C IMAGE_DOS_HEADER __ImageBase;
+static HMODULE getWindowsModuleHandle()
+{
+ return reinterpret_cast<HMODULE>(&__ImageBase);
+}
+#else // Q_OS_WINRT
+static HMODULE getWindowsModuleHandle()
+{
+ HMODULE hModule = NULL;
+ GetModuleHandleEx(
+ GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
+ (LPCTSTR)&QLibraryInfo::isDebugBuild, &hModule);
+ return hModule;
+}
+#endif // !Q_OS_WINRT
+#endif // Q_OS_WIN
+
+static QString getRelocatablePrefix()
+{
+ QString prefixPath;
+
+ // For static builds, the prefix will be the app directory.
+ // For regular builds, the prefix will be relative to the location of the QtCore shared library.
+#if defined(QT_STATIC)
+ prefixPath = prefixFromAppDirHelper();
+#elif defined(Q_OS_DARWIN) && QT_CONFIG(framework)
+ CFBundleRef qtCoreBundle = CFBundleGetBundleWithIdentifier(
+ CFSTR("org.qt-project.QtCore"));
+ Q_ASSERT(qtCoreBundle);
+
+ QCFType<CFURLRef> qtCorePath = CFBundleCopyBundleURL(qtCoreBundle);
+ Q_ASSERT(qtCorePath);
+
+ QCFType<CFURLRef> qtCorePathAbsolute = CFURLCopyAbsoluteURL(qtCorePath);
+ Q_ASSERT(qtCorePathAbsolute);
+
+ QCFType<CFURLRef> libDirCFPath = CFURLCreateCopyDeletingLastPathComponent(NULL, qtCorePathAbsolute);
+
+ const QCFString libDirCFString = CFURLCopyFileSystemPath(libDirCFPath, kCFURLPOSIXPathStyle);
+
+ const QString prefixDir = QString(libDirCFString) + QLatin1Char('/')
+ + QLatin1String(QT_CONFIGURE_LIBLOCATION_TO_PREFIX_PATH);
+
+ prefixPath = QDir::cleanPath(prefixDir);
+#elif QT_CONFIG(dlopen)
+ Dl_info info;
+ int result = dladdr(reinterpret_cast<void *>(&QLibraryInfo::isDebugBuild), &info);
+ if (result > 0 && info.dli_fname)
+ prefixPath = prefixFromQtCoreLibraryHelper(QString::fromLatin1(info.dli_fname));
+#elif defined(Q_OS_WIN)
+ HMODULE hModule = getWindowsModuleHandle();
+ const int kBufferSize = 4096;
+ wchar_t buffer[kBufferSize];
+ const int pathSize = GetModuleFileName(hModule, buffer, kBufferSize);
+ if (pathSize > 0)
+ prefixPath = prefixFromQtCoreLibraryHelper(QString::fromWCharArray(buffer, pathSize));
+#else
+#error "The chosen platform / config does not support querying for a dynamic prefix."
+#endif
+
+ Q_ASSERT_X(!prefixPath.isEmpty(), "getRelocatablePrefix",
+ "Failed to find the Qt prefix path.");
+ return prefixPath;
+}
+#endif
+
+#if defined(QT_BUILD_QMAKE) && !defined(QT_BUILD_QMAKE_BOOTSTRAP)
+QString qmake_abslocation();
+
+static QString getPrefixFromHostBinDir(const char *hostBinDirToPrefixPath)
+{
+ const QFileInfo qmfi = QFileInfo(qmake_abslocation()).canonicalFilePath();
+ return QDir::cleanPath(qmfi.absolutePath() + QLatin1Char('/')
+ + QLatin1String(hostBinDirToPrefixPath));
+}
+
+static QString getExtPrefixFromHostBinDir()
+{
+ return getPrefixFromHostBinDir(QT_CONFIGURE_HOSTBINDIR_TO_EXTPREFIX_PATH);
+}
+
+static QString getHostPrefixFromHostBinDir()
+{
+ return getPrefixFromHostBinDir(QT_CONFIGURE_HOSTBINDIR_TO_HOSTPREFIX_PATH);
+}
+#endif
+
+#ifndef QT_BUILD_QMAKE_BOOTSTRAP
+static const char *getPrefix(
+#ifdef QT_BUILD_QMAKE
+ QLibraryInfo::PathGroup group
+#endif
+ )
+{
+#if defined(QT_BUILD_QMAKE)
+# if QT_CONFIGURE_CROSSBUILD
+ if (group == QLibraryInfo::DevicePaths)
+ return QT_CONFIGURE_PREFIX_PATH;
+# endif
+ static QByteArray extPrefixPath = getExtPrefixFromHostBinDir().toLatin1();
+ return extPrefixPath.constData();
+#elif QT_CONFIG(relocatable)
+ static QByteArray prefixPath = getRelocatablePrefix().toLatin1();
+ return prefixPath.constData();
+#else
+ return QT_CONFIGURE_PREFIX_PATH;
+#endif
+}
+#endif // QT_BUILD_QMAKE_BOOTSTRAP
+
/*!
Returns the location specified by \a loc.
*/
@@ -564,12 +727,11 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group)
if (!fromConf) {
const char * volatile path = 0;
if (loc == PrefixPath) {
- path =
-# ifdef QT_BUILD_QMAKE
- (group != DevicePaths) ?
- QT_CONFIGURE_EXT_PREFIX_PATH :
-# endif
- QT_CONFIGURE_PREFIX_PATH;
+ path = getPrefix(
+#ifdef QT_BUILD_QMAKE
+ group
+#endif
+ );
} else if (unsigned(loc) <= sizeof(qt_configure_str_offsets)/sizeof(qt_configure_str_offsets[0])) {
path = qt_configure_strs + qt_configure_str_offsets[loc - 1];
#ifndef Q_OS_WIN // On Windows we use the registry
@@ -578,7 +740,8 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group)
#endif
# ifdef QT_BUILD_QMAKE
} else if (loc == HostPrefixPath) {
- path = QT_CONFIGURE_HOST_PREFIX_PATH;
+ static const QByteArray hostPrefixPath = getHostPrefixFromHostBinDir().toLatin1();
+ path = hostPrefixPath.constData();
# endif
}
@@ -612,28 +775,7 @@ QLibraryInfo::rawLocation(LibraryLocation loc, PathGroup group)
}
#else
if (loc == PrefixPath) {
- if (QCoreApplication::instance()) {
-#ifdef Q_OS_DARWIN
- CFBundleRef bundleRef = CFBundleGetMainBundle();
- if (bundleRef) {
- QCFType<CFURLRef> urlRef = CFBundleCopyBundleURL(bundleRef);
- if (urlRef) {
- QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
-#ifdef Q_OS_OSX
- QString bundleContentsDir = QString(path) + QLatin1String("/Contents/");
- if (QDir(bundleContentsDir).exists())
- return QDir::cleanPath(bundleContentsDir + ret);
-#else
- return QDir::cleanPath(QString(path) + QLatin1Char('/') + ret); // iOS
-#endif // Q_OS_OSX
- }
- }
-#endif // Q_OS_DARWIN
- // We make the prefix path absolute to the executable's directory.
- baseDir = QCoreApplication::applicationDirPath();
- } else {
- baseDir = QDir::currentPath();
- }
+ baseDir = prefixFromAppDirHelper();
} else {
// we make any other path absolute to the prefix directory
baseDir = location(PrefixPath);
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index cebab1daef..17f2246082 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -1803,8 +1803,8 @@ static void qt_message_print(QtMsgType msgType, const QMessageLogContext &contex
#ifndef QT_BOOTSTRAPPED
Q_TRACE(qt_message_print, msgType, context.category, context.function, context.file, context.line, message);
- // qDebug, qWarning, ... macros do not check whether category is enabled
- if (isDefaultCategory(context.category)) {
+ // qDebug, qWarning, ... macros do not check whether category is enabledgc
+ if (msgType != QtFatalMsg && isDefaultCategory(context.category)) {
if (QLoggingCategory *defaultCategory = QLoggingCategory::defaultCategory()) {
if (!defaultCategory->isEnabled(msgType))
return;
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc
index 886aedb4f3..cce88782e9 100644
--- a/src/corelib/global/qnamespace.qdoc
+++ b/src/corelib/global/qnamespace.qdoc
@@ -3287,7 +3287,7 @@
the application object is created, or by setting the QT_SCALE_FACTOR_ROUNDING_POLICY
environment variable.
- \sa QGuiApplication::setHighDdpiScaleFactorRoundingPolicy()
+ \sa QGuiApplication::setHighDpiScaleFactorRoundingPolicy()
\sa AA_EnableHighDpiScaling.
\omitvalue Unset
diff --git a/src/corelib/global/qoperatingsystemversion.cpp b/src/corelib/global/qoperatingsystemversion.cpp
index ded86cbc4e..33793ca168 100644
--- a/src/corelib/global/qoperatingsystemversion.cpp
+++ b/src/corelib/global/qoperatingsystemversion.cpp
@@ -356,14 +356,6 @@ bool QOperatingSystemVersion::isAnyOfType(std::initializer_list<OSType> types) c
}
/*!
- \variable QOperatingSystemVersion::WindowsVista
- \brief a version corresponding to Windows Vista (version 6.0).
- \since 6.0
- */
-const QOperatingSystemVersion QOperatingSystemVersion::WindowsVista =
- QOperatingSystemVersion(QOperatingSystemVersion::Windows, 6, 0);
-
-/*!
\variable QOperatingSystemVersion::Windows7
\brief a version corresponding to Windows 7 (version 6.1).
\since 5.9
diff --git a/src/corelib/global/qoperatingsystemversion.h b/src/corelib/global/qoperatingsystemversion.h
index 879bd379b0..f22878de89 100644
--- a/src/corelib/global/qoperatingsystemversion.h
+++ b/src/corelib/global/qoperatingsystemversion.h
@@ -60,7 +60,6 @@ public:
Android
};
- static const QOperatingSystemVersion WindowsVista;
static const QOperatingSystemVersion Windows7;
static const QOperatingSystemVersion Windows8;
static const QOperatingSystemVersion Windows8_1;
diff --git a/src/corelib/global/qrandom.cpp b/src/corelib/global/qrandom.cpp
index 711eb8f4d5..e5b2399566 100644
--- a/src/corelib/global/qrandom.cpp
+++ b/src/corelib/global/qrandom.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 Intel Corporation.
+** Copyright (C) 2019 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -103,17 +103,22 @@ static QT_FUNCTION_TARGET(RDRND) qsizetype qt_random_cpu(void *buffer, qsizetype
{
unsigned *ptr = reinterpret_cast<unsigned *>(buffer);
unsigned *end = ptr + count;
+ int retries = 10;
while (ptr + sizeof(qregisteruint)/sizeof(*ptr) <= end) {
- if (_rdrandXX_step(reinterpret_cast<qregisteruint *>(ptr)) == 0)
+ if (_rdrandXX_step(reinterpret_cast<qregisteruint *>(ptr)))
+ ptr += sizeof(qregisteruint)/sizeof(*ptr);
+ else if (--retries == 0)
goto out;
- ptr += sizeof(qregisteruint)/sizeof(*ptr);
}
- if (sizeof(*ptr) != sizeof(qregisteruint) && ptr != end) {
- if (_rdrand32_step(ptr))
- goto out;
- ++ptr;
+ while (sizeof(*ptr) != sizeof(qregisteruint) && ptr != end) {
+ bool ok = _rdrand32_step(ptr);
+ if (!ok && --retries)
+ continue;
+ if (ok)
+ ++ptr;
+ break;
}
out:
diff --git a/src/corelib/io/qfilesystemwatcher.cpp b/src/corelib/io/qfilesystemwatcher.cpp
index 64c422c55a..a4705136a2 100644
--- a/src/corelib/io/qfilesystemwatcher.cpp
+++ b/src/corelib/io/qfilesystemwatcher.cpp
@@ -41,9 +41,9 @@
#include "qfilesystemwatcher_p.h"
#include <qdatetime.h>
-#include <qdebug.h>
#include <qdir.h>
#include <qfileinfo.h>
+#include <qloggingcategory.h>
#include <qset.h>
#include <qtimer.h>
@@ -67,6 +67,8 @@
QT_BEGIN_NAMESPACE
+Q_LOGGING_CATEGORY(lcWatcher, "qt.core.filesystemwatcher")
+
QFileSystemWatcherEngine *QFileSystemWatcherPrivate::createNativeEngine(QObject *parent)
{
#if defined(Q_OS_WIN)
@@ -137,6 +139,7 @@ void QFileSystemWatcherPrivate::initPollerEngine()
void QFileSystemWatcherPrivate::_q_fileChanged(const QString &path, bool removed)
{
Q_Q(QFileSystemWatcher);
+ qCDebug(lcWatcher) << "file changed" << path << "removed?" << removed << "watching?" << files.contains(path);
if (!files.contains(path)) {
// the path was removed after a change was detected, but before we delivered the signal
return;
@@ -149,6 +152,7 @@ void QFileSystemWatcherPrivate::_q_fileChanged(const QString &path, bool removed
void QFileSystemWatcherPrivate::_q_directoryChanged(const QString &path, bool removed)
{
Q_Q(QFileSystemWatcher);
+ qCDebug(lcWatcher) << "directory changed" << path << "removed?" << removed << "watching?" << directories.contains(path);
if (!directories.contains(path)) {
// perhaps the path was removed after a change was detected, but before we delivered the signal
return;
@@ -355,7 +359,7 @@ QStringList QFileSystemWatcher::addPaths(const QStringList &paths)
qWarning("QFileSystemWatcher::addPaths: list is empty");
return p;
}
-
+ qCDebug(lcWatcher) << "adding" << paths;
const auto selectEngine = [this, d]() -> QFileSystemWatcherEngine* {
#ifdef QT_BUILD_INTERNAL
const QString on = objectName();
@@ -364,11 +368,11 @@ QStringList QFileSystemWatcher::addPaths(const QStringList &paths)
// Autotest override case - use the explicitly selected engine only
const QStringRef forceName = on.midRef(26);
if (forceName == QLatin1String("poller")) {
- qDebug("QFileSystemWatcher: skipping native engine, using only polling engine");
+ qCDebug(lcWatcher, "QFileSystemWatcher: skipping native engine, using only polling engine");
d_func()->initPollerEngine();
return d->poller;
} else if (forceName == QLatin1String("native")) {
- qDebug("QFileSystemWatcher: skipping polling engine, using only native engine");
+ qCDebug(lcWatcher, "QFileSystemWatcher: skipping polling engine, using only native engine");
return d->native;
}
return nullptr;
@@ -431,6 +435,7 @@ QStringList QFileSystemWatcher::removePaths(const QStringList &paths)
qWarning("QFileSystemWatcher::removePaths: list is empty");
return p;
}
+ qCDebug(lcWatcher) << "removing" << paths;
if (d->native)
p = d->native->removePaths(p, &d->files, &d->directories);
diff --git a/src/corelib/io/qtldurl.cpp b/src/corelib/io/qtldurl.cpp
index 912609ec91..fc3e16b241 100644
--- a/src/corelib/io/qtldurl.cpp
+++ b/src/corelib/io/qtldurl.cpp
@@ -125,10 +125,10 @@ Q_CORE_EXPORT bool qIsEffectiveTLD(const QStringRef &domain)
return true;
const int dot = domain.indexOf(QLatin1Char('.'));
- if (dot >= 0) {
- if (containsTLDEntry(domain.mid(dot), SuffixMatch)) // 2
- return !containsTLDEntry(domain, ExceptionMatch); // 3
- }
+ if (dot < 0) // Actual TLD: may be effective if the subject of a wildcard rule:
+ return containsTLDEntry(QString(QLatin1Char('.') + domain), SuffixMatch);
+ if (containsTLDEntry(domain.mid(dot), SuffixMatch)) // 2
+ return !containsTLDEntry(domain, ExceptionMatch); // 3
return false;
}
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 6647ea99f5..c537e8f51b 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -2693,7 +2693,14 @@ Q_GLOBAL_STATIC(QRecursiveMutex, libraryPathMutex)
QStringList QCoreApplication::libraryPaths()
{
QMutexLocker locker(libraryPathMutex());
+ return libraryPathsLocked();
+}
+/*!
+ \internal
+*/
+QStringList QCoreApplication::libraryPathsLocked()
+{
if (coreappdata()->manual_libpaths)
return *(coreappdata()->manual_libpaths);
@@ -2769,7 +2776,7 @@ void QCoreApplication::setLibraryPaths(const QStringList &paths)
// When the application is constructed it should still amend the paths. So we keep the originals
// around, and even create them if they don't exist, yet.
if (!coreappdata()->app_libpaths)
- libraryPaths();
+ libraryPathsLocked();
if (coreappdata()->manual_libpaths)
*(coreappdata()->manual_libpaths) = paths;
@@ -2812,7 +2819,7 @@ void QCoreApplication::addLibraryPath(const QString &path)
return;
} else {
// make sure that library paths are initialized
- libraryPaths();
+ libraryPathsLocked();
QStringList *app_libpaths = coreappdata()->app_libpaths.data();
if (app_libpaths->contains(canonicalPath))
return;
@@ -2851,7 +2858,7 @@ void QCoreApplication::removeLibraryPath(const QString &path)
return;
} else {
// make sure that library paths is initialized
- libraryPaths();
+ libraryPathsLocked();
QStringList *app_libpaths = coreappdata()->app_libpaths.data();
if (!app_libpaths->contains(canonicalPath))
return;
diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h
index b7df004736..71ea124fbe 100644
--- a/src/corelib/kernel/qcoreapplication.h
+++ b/src/corelib/kernel/qcoreapplication.h
@@ -208,6 +208,9 @@ private:
static bool notifyInternal2(QObject *receiver, QEvent *);
static bool forwardEvent(QObject *receiver, QEvent *event, QEvent *originatingEvent = nullptr);
#endif
+#if QT_CONFIG(library)
+ static QStringList libraryPathsLocked();
+#endif
static QCoreApplication *self;
diff --git a/src/corelib/kernel/qeventdispatcher_winrt.cpp b/src/corelib/kernel/qeventdispatcher_winrt.cpp
index 600c6c38fd..f7a1f969a8 100644
--- a/src/corelib/kernel/qeventdispatcher_winrt.cpp
+++ b/src/corelib/kernel/qeventdispatcher_winrt.cpp
@@ -44,12 +44,13 @@
#include <QtCore/QHash>
#include <QtCore/QMutex>
#include <QtCore/QSemaphore>
-#include <QtCore/QSharedPointer>
#include <QtCore/qfunctions_winrt.h>
#include <private/qabstracteventdispatcher_p.h>
#include <private/qcoreapplication_p.h>
#include <functional>
+#include <memory>
+
#include <wrl.h>
#include <windows.foundation.h>
#include <windows.system.threading.h>
@@ -300,19 +301,19 @@ HRESULT QEventDispatcherWinRT::runOnMainThread(const std::function<HRESULT()> &d
if (QThread::currentThread() == QCoreApplication::instance()->thread())
return delegate();
- auto semaphore = QSharedPointer<QSemaphore>(new QSemaphore);
- auto ptrSemaphore = new QSharedPointer<QSemaphore>(semaphore);
- auto result = QSharedPointer<HRESULT>(new HRESULT);
- auto ptrResult = new QSharedPointer<HRESULT>(result);
+ struct State {
+ QSemaphore semaphore;
+ HRESULT result;
+ };
+
+ const auto state = std::make_shared<State>();
- QMetaObject::invokeMethod(QCoreApplication::instance(), [delegate, ptrSemaphore, ptrResult]() {
- **ptrResult = delegate();
- delete ptrResult;
- (*ptrSemaphore)->release();
- delete ptrSemaphore;
+ QMetaObject::invokeMethod(QCoreApplication::instance(), [delegate, state]() {
+ const QSemaphoreReleaser releaser{state->semaphore};
+ state->result = delegate();
}, nullptr);
- return semaphore->tryAcquire(1, timeout) ? *result : E_FAIL;
+ return state->semaphore.tryAcquire(1, timeout) ? state->result : E_FAIL;
}
bool QEventDispatcherWinRT::processEvents(QEventLoop::ProcessEventsFlags flags)
diff --git a/src/corelib/kernel/qpointer.h b/src/corelib/kernel/qpointer.h
index 7052bcf0d4..5efdb0b395 100644
--- a/src/corelib/kernel/qpointer.h
+++ b/src/corelib/kernel/qpointer.h
@@ -54,20 +54,11 @@ class QPointer
{
Q_STATIC_ASSERT_X(!std::is_pointer<T>::value, "QPointer's template type must not be a pointer type");
- template<typename U>
- struct TypeSelector
- {
- typedef QObject Type;
- };
- template<typename U>
- struct TypeSelector<const U>
- {
- typedef const QObject Type;
- };
- typedef typename TypeSelector<T>::Type QObjectType;
+ using QObjectType =
+ typename std::conditional<std::is_const<T>::value, const QObject, QObject>::type;
QWeakPointer<QObjectType> wp;
public:
- inline QPointer() { }
+ QPointer() = default;
inline QPointer(T *p) : wp(p, true) { }
// compiler-generated copy/move ctor/assignment operators are fine!
// compiler-generated dtor is fine!
diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp
index 1ace28c93f..98a198df43 100644
--- a/src/corelib/plugin/qlibrary.cpp
+++ b/src/corelib/plugin/qlibrary.cpp
@@ -74,7 +74,7 @@ QT_BEGIN_NAMESPACE
# define QLIBRARY_AS_DEBUG true
#endif
-#if defined(Q_OS_UNIX) || defined(Q_CC_MINGW)
+#if defined(Q_OS_UNIX)
// We don't use separate debug and release libs on UNIX, so we want
// to allow loading plugins, regardless of how they were built.
# define QT_NO_DEBUG_PLUGIN_CHECK
diff --git a/src/corelib/thread/qbasicatomic.h b/src/corelib/thread/qbasicatomic.h
index dc976819ef..9804e60119 100644
--- a/src/corelib/thread/qbasicatomic.h
+++ b/src/corelib/thread/qbasicatomic.h
@@ -99,8 +99,10 @@ public:
typename Ops::Type _q_value;
// Everything below is either implemented in ../arch/qatomic_XXX.h or (as fallback) in qgenericatomic.h
- T load() const noexcept { return loadRelaxed(); }
- void store(T newValue) noexcept { storeRelaxed(newValue); }
+#if QT_DEPRECATED_SINCE(5, 14)
+ QT_DEPRECATED_VERSION_X_5_14("Use loadRelaxed") T load() const noexcept { return loadRelaxed(); }
+ QT_DEPRECATED_VERSION_X_5_14("Use storeRelaxed") void store(T newValue) noexcept { storeRelaxed(newValue); }
+#endif
T loadRelaxed() const noexcept { return Ops::loadRelaxed(_q_value); }
void storeRelaxed(T newValue) noexcept { Ops::storeRelaxed(_q_value, newValue); }
@@ -238,8 +240,10 @@ public:
AtomicType _q_value;
- Type load() const noexcept { return loadRelaxed(); }
- void store(Type newValue) noexcept { storeRelaxed(newValue); }
+#if QT_DEPRECATED_SINCE(5, 14)
+ QT_DEPRECATED_VERSION_X_5_14("Use loadRelaxed") Type load() const noexcept { return loadRelaxed(); }
+ QT_DEPRECATED_VERSION_X_5_14("Use storeRelaxed") void store(Type newValue) noexcept { storeRelaxed(newValue); }
+#endif
Type loadRelaxed() const noexcept { return Ops::loadRelaxed(_q_value); }
void storeRelaxed(Type newValue) noexcept { Ops::storeRelaxed(_q_value, newValue); }
diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp
index 30e9b95a52..5aba05c1b9 100644
--- a/src/corelib/thread/qreadwritelock.cpp
+++ b/src/corelib/thread/qreadwritelock.cpp
@@ -48,6 +48,9 @@
#include "qreadwritelock_p.h"
#include "qelapsedtimer.h"
#include "private/qfreelist_p.h"
+#include "private/qlocking_p.h"
+
+#include <chrono>
QT_BEGIN_NAMESPACE
@@ -64,6 +67,9 @@ QT_BEGIN_NAMESPACE
*/
namespace {
+
+using ms = std::chrono::milliseconds;
+
enum {
StateMask = 0x3,
StateLockedForRead = 0x1,
@@ -262,7 +268,7 @@ bool QReadWriteLock::tryLockForRead(int timeout)
if (d->recursive)
return d->recursiveLockForRead(timeout);
- QMutexLocker lock(&d->mutex);
+ auto lock = qt_unique_lock(d->mutex);
if (d != d_ptr.loadRelaxed()) {
// d_ptr has changed: this QReadWriteLock was unlocked before we had
// time to lock d->mutex.
@@ -273,7 +279,7 @@ bool QReadWriteLock::tryLockForRead(int timeout)
d = d_ptr.loadAcquire();
continue;
}
- return d->lockForRead(timeout);
+ return d->lockForRead(lock, timeout);
}
}
@@ -369,7 +375,7 @@ bool QReadWriteLock::tryLockForWrite(int timeout)
if (d->recursive)
return d->recursiveLockForWrite(timeout);
- QMutexLocker lock(&d->mutex);
+ auto lock = qt_unique_lock(d->mutex);
if (d != d_ptr.loadRelaxed()) {
// The mutex was unlocked before we had time to lock the mutex.
// We are holding to a mutex within a QReadWriteLockPrivate that is already released
@@ -377,7 +383,7 @@ bool QReadWriteLock::tryLockForWrite(int timeout)
d = d_ptr.loadAcquire();
continue;
}
- return d->lockForWrite(timeout);
+ return d->lockForWrite(lock, timeout);
}
}
@@ -418,7 +424,7 @@ void QReadWriteLock::unlock()
return;
}
- QMutexLocker locker(&d->mutex);
+ const auto lock = qt_scoped_lock(d->mutex);
if (d->writerCount) {
Q_ASSERT(d->writerCount == 1);
Q_ASSERT(d->readerCount == 0);
@@ -460,9 +466,9 @@ QReadWriteLock::StateForWaitCondition QReadWriteLock::stateForWaitCondition() co
}
-bool QReadWriteLockPrivate::lockForRead(int timeout)
+bool QReadWriteLockPrivate::lockForRead(std::unique_lock<std::mutex> &lock, int timeout)
{
- Q_ASSERT(!mutex.tryLock()); // mutex must be locked when entering this function
+ Q_ASSERT(!mutex.try_lock()); // mutex must be locked when entering this function
QElapsedTimer t;
if (timeout > 0)
@@ -476,10 +482,10 @@ bool QReadWriteLockPrivate::lockForRead(int timeout)
if (elapsed > timeout)
return false;
waitingReaders++;
- readerCond.wait(&mutex, timeout - elapsed);
+ readerCond.wait_for(lock, ms{timeout - elapsed});
} else {
waitingReaders++;
- readerCond.wait(&mutex);
+ readerCond.wait(lock);
}
waitingReaders--;
}
@@ -488,9 +494,9 @@ bool QReadWriteLockPrivate::lockForRead(int timeout)
return true;
}
-bool QReadWriteLockPrivate::lockForWrite(int timeout)
+bool QReadWriteLockPrivate::lockForWrite(std::unique_lock<std::mutex> &lock, int timeout)
{
- Q_ASSERT(!mutex.tryLock()); // mutex must be locked when entering this function
+ Q_ASSERT(!mutex.try_lock()); // mutex must be locked when entering this function
QElapsedTimer t;
if (timeout > 0)
@@ -505,15 +511,15 @@ bool QReadWriteLockPrivate::lockForWrite(int timeout)
if (waitingReaders && !waitingWriters && !writerCount) {
// We timed out and now there is no more writers or waiting writers, but some
// readers were queueud (probably because of us). Wake the waiting readers.
- readerCond.wakeAll();
+ readerCond.notify_all();
}
return false;
}
waitingWriters++;
- writerCond.wait(&mutex, timeout - elapsed);
+ writerCond.wait_for(lock, ms{timeout - elapsed});
} else {
waitingWriters++;
- writerCond.wait(&mutex);
+ writerCond.wait(lock);
}
waitingWriters--;
}
@@ -526,17 +532,17 @@ bool QReadWriteLockPrivate::lockForWrite(int timeout)
void QReadWriteLockPrivate::unlock()
{
- Q_ASSERT(!mutex.tryLock()); // mutex must be locked when entering this function
+ Q_ASSERT(!mutex.try_lock()); // mutex must be locked when entering this function
if (waitingWriters)
- writerCond.wakeOne();
+ writerCond.notify_one();
else if (waitingReaders)
- readerCond.wakeAll();
+ readerCond.notify_all();
}
bool QReadWriteLockPrivate::recursiveLockForRead(int timeout)
{
Q_ASSERT(recursive);
- QMutexLocker lock(&mutex);
+ auto lock = qt_unique_lock(mutex);
Qt::HANDLE self = QThread::currentThreadId();
@@ -546,7 +552,7 @@ bool QReadWriteLockPrivate::recursiveLockForRead(int timeout)
return true;
}
- if (!lockForRead(timeout))
+ if (!lockForRead(lock, timeout))
return false;
currentReaders.insert(self, 1);
@@ -556,7 +562,7 @@ bool QReadWriteLockPrivate::recursiveLockForRead(int timeout)
bool QReadWriteLockPrivate::recursiveLockForWrite(int timeout)
{
Q_ASSERT(recursive);
- QMutexLocker lock(&mutex);
+ auto lock = qt_unique_lock(mutex);
Qt::HANDLE self = QThread::currentThreadId();
if (currentWriter == self) {
@@ -564,7 +570,7 @@ bool QReadWriteLockPrivate::recursiveLockForWrite(int timeout)
return true;
}
- if (!lockForWrite(timeout))
+ if (!lockForWrite(lock, timeout))
return false;
currentWriter = self;
@@ -574,7 +580,7 @@ bool QReadWriteLockPrivate::recursiveLockForWrite(int timeout)
void QReadWriteLockPrivate::recursiveUnlock()
{
Q_ASSERT(recursive);
- QMutexLocker lock(&mutex);
+ auto lock = qt_unique_lock(mutex);
Qt::HANDLE self = QThread::currentThreadId();
if (self == currentWriter) {
diff --git a/src/corelib/thread/qreadwritelock_p.h b/src/corelib/thread/qreadwritelock_p.h
index 31da2401c0..b2e782f9ee 100644
--- a/src/corelib/thread/qreadwritelock_p.h
+++ b/src/corelib/thread/qreadwritelock_p.h
@@ -54,7 +54,9 @@
#include <QtCore/private/qglobal_p.h>
#include <QtCore/qhash.h>
-#include <QtCore/qwaitcondition.h>
+
+#include <mutex>
+#include <condition_variable>
QT_REQUIRE_CONFIG(thread);
@@ -63,38 +65,36 @@ QT_BEGIN_NAMESPACE
class QReadWriteLockPrivate
{
public:
- QReadWriteLockPrivate(bool isRecursive = false)
- : readerCount(0), writerCount(0), waitingReaders(0), waitingWriters(0),
- recursive(isRecursive), id(0), currentWriter(nullptr) {}
+ explicit QReadWriteLockPrivate(bool isRecursive = false)
+ : recursive(isRecursive) {}
- QMutex mutex;
- QWaitCondition writerCond;
- QWaitCondition readerCond;
- int readerCount;
- int writerCount;
- int waitingReaders;
- int waitingWriters;
+ std::mutex mutex;
+ std::condition_variable writerCond;
+ std::condition_variable readerCond;
+ int readerCount = 0;
+ int writerCount = 0;
+ int waitingReaders = 0;
+ int waitingWriters = 0;
const bool recursive;
//Called with the mutex locked
- bool lockForWrite(int timeout);
- bool lockForRead(int timeout);
+ bool lockForWrite(std::unique_lock<std::mutex> &lock, int timeout);
+ bool lockForRead(std::unique_lock<std::mutex> &lock, int timeout);
void unlock();
//memory management
- int id;
+ int id = 0;
void release();
static QReadWriteLockPrivate *allocate();
// Recusive mutex handling
- Qt::HANDLE currentWriter;
+ Qt::HANDLE currentWriter = {};
QHash<Qt::HANDLE, int> currentReaders;
// called with the mutex unlocked
bool recursiveLockForWrite(int timeout);
bool recursiveLockForRead(int timeout);
void recursiveUnlock();
-
};
QT_END_NAMESPACE
diff --git a/src/corelib/time/qcalendar.cpp b/src/corelib/time/qcalendar.cpp
index d31eee6632..d706f1d5ab 100644
--- a/src/corelib/time/qcalendar.cpp
+++ b/src/corelib/time/qcalendar.cpp
@@ -201,7 +201,7 @@ QCalendar::System QCalendarBackend::calendarSystem() const
}
/*!
- The primary name of this calendar.
+ The primary name of this calendar.
*/
QString QCalendar::name() const
{
@@ -221,8 +221,8 @@ QString QCalendar::name() const
Calendars with intercallary days may represent these as extra days of the
preceding month, or as short months separate from the usual ones. In the
former case, daysInMonth(month, year) should be the number of ordinary days
- in the month, although \c{isDateValid(year, month, day)} might return \c true for
- some larger values of \c day.
+ in the month, although \c{isDateValid(year, month, day)} might return \c true
+ for some larger values of \c day.
\sa daysInYear(), monthsInYear(), minimumDaysInMonth(), maximumDaysInMonth()
*/
@@ -440,101 +440,104 @@ int QCalendarBackend::dayOfWeek(qint64 jd) const
// Month and week-day name look-ups (implemented in qlocale.cpp):
/*!
- \fn QString QCalendarBackend::monthName(const QLocale &locale, int month, int year,
- QLocale::FormatType format) const
+ \fn QString QCalendarBackend::monthName(const QLocale &locale, int month, int year,
+ QLocale::FormatType format) const
- Returns the name of the specified \a month in the given \a year for the chosen
- \a locale, using the given \a format to determine how complete the name is.
+ Returns the name of the specified \a month in the given \a year for the
+ chosen \a locale, using the given \a format to determine how complete the
+ name is.
- If \a year is Unspecified, return the name for the month that usually has this
- number within a typical year. Calendars with a leap month that isn't always
- the last may need to take account of the year to map the month number to the
- particular year's month with that number.
+ If \a year is Unspecified, return the name for the month that usually has
+ this number within a typical year. Calendars with a leap month that isn't
+ always the last may need to take account of the year to map the month number
+ to the particular year's month with that number.
- \note Backends for which CLDR provides data can configure the default
- implementation of the two month name look-up methods by arranging for
- localeMonthIndexData() and localeMonthData() to provide access to the CLDR
- data (see cldr2qlocalexml.py, qlocalexml2cpp.py and existing backends).
- Conversely, backends that override both month name look-up methods need not
- return anything meaningful from localeMonthIndexData() or localeMonthData().
+ \note Backends for which CLDR provides data can configure the default
+ implementation of the two month name look-up methods by arranging for
+ localeMonthIndexData() and localeMonthData() to provide access to the CLDR
+ data (see cldr2qlocalexml.py, qlocalexml2cpp.py and existing backends).
+ Conversely, backends that override both month name look-up methods need not
+ return anything meaningful from localeMonthIndexData() or localeMonthData().
- \sa standaloneMonthName(), QLocale::monthName()
+ \sa standaloneMonthName(), QLocale::monthName()
*/
/*!
- \fn QString QCalendarBackend::standaloneMonthName(const QLocale &locale, int month, int year
- QLocale::FormatType format) const
+ \fn QString QCalendarBackend::standaloneMonthName(const QLocale &locale, int month, int year
+ QLocale::FormatType format) const
- Returns the standalone name of the specified \a month in the chosen \a locale,
- using the specified \a format to determine how complete the name is.
+ Returns the standalone name of the specified \a month in the chosen \a
+ locale, using the specified \a format to determine how complete the name is.
- If \a year is Unspecified, return the standalone name for the month that
- usually has this number within a typical year. Calendars with a leap month
- that isn't always the last may need to take account of the year to map the
- month number to the particular year's month with that number.
+ If \a year is Unspecified, return the standalone name for the month that
+ usually has this number within a typical year. Calendars with a leap month
+ that isn't always the last may need to take account of the year to map the
+ month number to the particular year's month with that number.
- \sa monthName(), QLocale::standaloneMonthName()
+ \sa monthName(), QLocale::standaloneMonthName()
*/
/*!
- \fn QString QCalendarBackend::weekDayName(const QLocale &locale, int day,
- QLocale::FormatType format) const
+ \fn QString QCalendarBackend::weekDayName(const QLocale &locale, int day,
+ QLocale::FormatType format) const
- Returns the name of the specified \a day of the week in the chosen \a locale,
- using the specified \a format to determine how complete the name is.
+ Returns the name of the specified \a day of the week in the chosen \a
+ locale, using the specified \a format to determine how complete the name is.
- The base implementation handles \a day values from 1 to 7 using the day names
- CLDR provides, which are suitable for calendards that use the same
- (Hebrew-derived) week as the Gregorian calendar.
+ The base implementation handles \a day values from 1 to 7 using the day
+ names CLDR provides, which are suitable for calendards that use the same
+ (Hebrew-derived) week as the Gregorian calendar.
- Calendars whose dayOfWeek() returns a value outside the range from 1 to 7 need
- to reimplement this method to handle such extra week-day values. They can
- assume that \a day is a value returned by the same calendar's dayOfWeek().
+ Calendars whose dayOfWeek() returns a value outside the range from 1 to 7
+ need to reimplement this method to handle such extra week-day values. They
+ can assume that \a day is a value returned by the same calendar's
+ dayOfWeek().
- \sa dayOfWeek(), standaloneWeekDayName(), QLocale::dayName()
+ \sa dayOfWeek(), standaloneWeekDayName(), QLocale::dayName()
*/
/*!
- \fn QString QCalendarBackend::standaloneWeekDayName(const QLocale &locale, int day,
- QLocale::FormatType format) const
+ \fn QString QCalendarBackend::standaloneWeekDayName(const QLocale &locale, int day,
+ QLocale::FormatType format) const
- Returns the standalone name of the specified \a day of the week in the chosen
- \a locale, using the specified \a format to determine how complete the name
- is.
+ Returns the standalone name of the specified \a day of the week in the
+ chosen \a locale, using the specified \a format to determine how complete
+ the name is.
- The base implementation handles \a day values from 1 to 7 using the standalone
- day names CLDR provides, which are suitable for calendards that use the same
- (Hebrew-derived) week as the Gregorian calendar.
+ The base implementation handles \a day values from 1 to 7 using the
+ standalone day names CLDR provides, which are suitable for calendards that
+ use the same (Hebrew-derived) week as the Gregorian calendar.
- Calendars whose dayOfWeek() returns a value outside the range from 1 to 7 need
- to reimplement this method to handle such extra week-day values. They can
- assume that \a day is a value returned by the same calendar's dayOfWeek().
+ Calendars whose dayOfWeek() returns a value outside the range from 1 to 7
+ need to reimplement this method to handle such extra week-day values. They
+ can assume that \a day is a value returned by the same calendar's
+ dayOfWeek().
- \sa dayOfWeek(), weekDayName(), QLocale::standaloneDayName()
+ \sa dayOfWeek(), weekDayName(), QLocale::standaloneDayName()
*/
/*!
- \fn QString QCalendarBackend::dateTimeToString(QStringView format, const QDateTime &datetime,
- const QDate &dateOnly, const QTime &timeOnly,
- const QLocale &locale) const
-
- Returns a string representing a given date, time or date-time.
-
- If \a datetime is specified and valid, it is used and both date and time
- format tokens are converted to appropriate representations of the parts of the
- datetime. Otherwise, if \a dateOnly is valid, only date format tokens are
- converted; else, if \a timeOnly is valid, only time format tokens are
- converted. If none are valid, an empty string is returned.
-
- The specified \a locale influences how some format tokens are converted; for
- example, when substituting day and month names and their short-forms. For the
- supported formatting tokens, see QDate::toString() and QTime::toString(). As
- described above, the provided date, time and date-time determine which of
- these tokens are recognized: where these appear in \a format they are replaced
- by data. Any text in \a format not recognized as a format token is copied
- verbatim into the result string.
-
- \sa QDate::toString(), QTime::toString(), QDateTime::toString()
+ \fn QString QCalendarBackend::dateTimeToString(QStringView format, const QDateTime &datetime,
+ const QDate &dateOnly, const QTime &timeOnly,
+ const QLocale &locale) const
+
+ Returns a string representing a given date, time or date-time.
+
+ If \a datetime is specified and valid, it is used and both date and time
+ format tokens are converted to appropriate representations of the parts of
+ the datetime. Otherwise, if \a dateOnly is valid, only date format tokens
+ are converted; else, if \a timeOnly is valid, only time format tokens are
+ converted. If none are valid, an empty string is returned.
+
+ The specified \a locale influences how some format tokens are converted; for
+ example, when substituting day and month names and their short-forms. For
+ the supported formatting tokens, see QDate::toString() and
+ QTime::toString(). As described above, the provided date, time and date-time
+ determine which of these tokens are recognized: where these appear in \a
+ format they are replaced by data. Any text in \a format not recognized as a
+ format token is copied verbatim into the result string.
+
+ \sa QDate::toString(), QTime::toString(), QDateTime::toString()
*/
// End of methods implemented in qlocale.cpp
@@ -571,16 +574,16 @@ bool QCalendarBackend::registerAlias(const QString &name)
}
/*!
- Returns a pointer to a named calendar backend.
+ Returns a pointer to a named calendar backend.
- If the given \a name is present in availableCalendars(), the backend matching
- it is returned; otherwise, \c nullptr is returned. Matching of names ignores
- case. Note that this won't provoke construction of a calendar backend, it will
- only return ones that have been instantiated (and not yet destroyed) by some
- other means. However, calendars available via the QCalendar::System enum are
- always registered when this is called.
+ If the given \a name is present in availableCalendars(), the backend
+ matching it is returned; otherwise, \c nullptr is returned. Matching of
+ names ignores case. Note that this won't provoke construction of a calendar
+ backend, it will only return ones that have been instantiated (and not yet
+ destroyed) by some other means. However, calendars available via the
+ QCalendar::System enum are always registered when this is called.
- \sa availableCalendars(), registerAlias(), fromEnum()
+ \sa availableCalendars(), registerAlias(), fromEnum()
*/
const QCalendarBackend *QCalendarBackend::fromName(QStringView name)
{
@@ -592,7 +595,7 @@ const QCalendarBackend *QCalendarBackend::fromName(QStringView name)
}
/*!
- \overload
+ \overload
*/
const QCalendarBackend *QCalendarBackend::fromName(QLatin1String name)
{
@@ -604,11 +607,11 @@ const QCalendarBackend *QCalendarBackend::fromName(QLatin1String name)
}
/*!
- Returns a pointer to a calendar backend, specified by enum.
+ Returns a pointer to a calendar backend, specified by enum.
- This will instantiate the indicated calendar (which will enable fromName() to
- return it subsequently), but only for the Qt-supported calendars for which
- (where relevant) the appropriate feature has been enabled.
+ This will instantiate the indicated calendar (which will enable fromName()
+ to return it subsequently), but only for the Qt-supported calendars for
+ which (where relevant) the appropriate feature has been enabled.
*/
const QCalendarBackend *QCalendarBackend::fromEnum(QCalendar::System system)
{
@@ -643,28 +646,29 @@ const QCalendarBackend *QCalendarBackend::fromEnum(QCalendar::System system)
}
/*!
- \since 5.14
-
- \class QCalendar
- \inmodule QtCore
- \reentrant
- \brief The QCalendar class describes calendar systems.
-
- A QCalendar object maps a year, month, and day-number to a specific day
- (ultimately identified by its Julian day number), using the rules of a
- particular system.
+ \since 5.14
- The default QCalendar() is a proleptic Gregorian calendar, which has no year
- zero. Other calendars may be supported by enabling suitable features or
- loading plugins. Calendars supported as features can be constructed by passing
- the QCalendar::System enumeration to the constructor. All supported calendars
- may be constructed by name, once they have been constructed. (Thus plugins
- instantiate their calendar backend to register it.) Built-in backends,
- accessible via QCalendar::System, are also always available by name.
+ \class QCalendar
+ \inmodule QtCore
+ \reentrant
+ \brief The QCalendar class describes calendar systems.
+
+ A QCalendar object maps a year, month, and day-number to a specific day
+ (ultimately identified by its Julian day number), using the rules of a
+ particular system.
+
+ The default QCalendar() is a proleptic Gregorian calendar, which has no year
+ zero. Other calendars may be supported by enabling suitable features or
+ loading plugins. Calendars supported as features can be constructed by
+ passing the QCalendar::System enumeration to the constructor. All supported
+ calendars may be constructed by name, once they have been constructed. (Thus
+ plugins instantiate their calendar backend to register it.) Built-in
+ backends, accessible via QCalendar::System, are also always available by
+ name.
- A QCalendar value is immutable.
+ A QCalendar value is immutable.
- \sa QDate, QDateTime
+ \sa QDate, QDateTime
*/
/*!
@@ -684,20 +688,20 @@ const QCalendarBackend *QCalendarBackend::fromEnum(QCalendar::System system)
*/
/*!
- \fn QCalendar::QCalendar()
- \fn QCalendar::QCalendar(QCalendar::System system)
- \fn QCalendar::QCalendar(QLatin1String name)
- \fn QCalendar::QCalendar(QStringView name)
+ \fn QCalendar::QCalendar()
+ \fn QCalendar::QCalendar(QCalendar::System system)
+ \fn QCalendar::QCalendar(QLatin1String name)
+ \fn QCalendar::QCalendar(QStringView name)
- Constructs a calendar object.
+ Constructs a calendar object.
- The choice of calendar to use may be indicated as \a system, using the
- enumeration QCalendar::System, or by \a name, using a string (either Unicode
- or Latin 1). Construction by name may depend on an instance of the given
- calendar being constructed by other means first. With no argument, the default
- constructor returns the Gregorian calendar.
+ The choice of calendar to use may be indicated as \a system, using the
+ enumeration QCalendar::System, or by \a name, using a string (either Unicode
+ or Latin 1). Construction by name may depend on an instance of the given
+ calendar being constructed by other means first. With no argument, the
+ default constructor returns the Gregorian calendar.
- \sa QCalendar, System
+ \sa QCalendar, System
*/
QCalendar::QCalendar()
@@ -722,12 +726,13 @@ QCalendar::QCalendar(QStringView name)
// Date queries:
/*!
- Returns the number of days in the given \a month of the given \a year.
+ Returns the number of days in the given \a month of the given \a year.
- Months are numbered consecutively, starting with 1 for the first month of each
- year.
+ Months are numbered consecutively, starting with 1 for the first month of
+ each year. If \a year is \c Unspecified (its default, if not passed), the
+ month's length in a normal year is returned.
- \sa maximumDaysInMonth(), minimumDaysInMonth()
+ \sa maximumDaysInMonth(), minimumDaysInMonth()
*/
int QCalendar::daysInMonth(int month, int year) const
{
@@ -735,7 +740,7 @@ int QCalendar::daysInMonth(int month, int year) const
}
/*!
- Returns the number of days in the given \a year.
+ Returns the number of days in the given \a year.
*/
int QCalendar::daysInYear(int year) const
{
@@ -751,12 +756,12 @@ int QCalendar::monthsInYear(int year) const
}
/*!
- Returns \c true precisely if the given \a year, \a month, and \a day specify a
- valid date in this calendar.
+ Returns \c true precisely if the given \a year, \a month, and \a day specify
+ a valid date in this calendar.
- Usually this means 1 <= month <= monthsInYear(year) and 1 <= day <=
- daysInMonth(month, year). However, calendars with intercallary days or months
- may complicate that.
+ Usually this means 1 <= month <= monthsInYear(year) and 1 <= day <=
+ daysInMonth(month, year). However, calendars with intercallary days or
+ months may complicate that.
*/
bool QCalendar::isDateValid(int year, int month, int day) const
{
@@ -776,13 +781,13 @@ bool QCalendar::isGregorian() const
}
/*!
- Returns \c true if the given \a year is a leap year.
+ Returns \c true if the given \a year is a leap year.
- Since the year is not a whole number of days long, some years are longer than
- others. The difference may be a whole month or just a single day; the details
- vary between calendars.
+ Since the year is not a whole number of days long, some years are longer
+ than others. The difference may be a whole month or just a single day; the
+ details vary between calendars.
- \sa isDateValid()
+ \sa isDateValid()
*/
bool QCalendar::isLeapYear(int year) const
{
@@ -790,9 +795,9 @@ bool QCalendar::isLeapYear(int year) const
}
/*!
- Returns \c true if this calendar is a lunar calendar.
+ Returns \c true if this calendar is a lunar calendar.
- A lunar calendar is one based primarily on the phases of the moon.
+ A lunar calendar is one based primarily on the phases of the moon.
*/
bool QCalendar::isLunar() const
{
@@ -800,11 +805,11 @@ bool QCalendar::isLunar() const
}
/*!
- Returns \c true if this calendar is luni-solar.
+ Returns \c true if this calendar is luni-solar.
- A luni-solar calendar expresses the phases of the moon but adapts itself to
- also keep track of the Sun's varying position in the sky, relative to the
- fixed stars.
+ A luni-solar calendar expresses the phases of the moon but adapts itself to
+ also keep track of the Sun's varying position in the sky, relative to the
+ fixed stars.
*/
bool QCalendar::isLuniSolar() const
{
@@ -812,10 +817,10 @@ bool QCalendar::isLuniSolar() const
}
/*!
- Returns \c true if this calendar is solar.
+ Returns \c true if this calendar is solar.
- A solar calendar is based primarily on the Sun's varying position in the sky,
- relative to the fixed stars.
+ A solar calendar is based primarily on the Sun's varying position in the
+ sky, relative to the fixed stars.
*/
bool QCalendar::isSolar() const
{
@@ -823,13 +828,13 @@ bool QCalendar::isSolar() const
}
/*!
- Returns \c true if this calendar is proleptic.
+ Returns \c true if this calendar is proleptic.
- A proleptic calendar is able to describe years arbitrarily long before its
- first. These are represented by negative year numbers and possibly by a year
- zero.
+ A proleptic calendar is able to describe years arbitrarily long before its
+ first. These are represented by negative year numbers and possibly by a year
+ zero.
- \sa hasYearZero()
+ \sa hasYearZero()
*/
bool QCalendar::isProleptic() const
{
@@ -837,29 +842,29 @@ bool QCalendar::isProleptic() const
}
/*!
- Returns \c true if this calendar has a year zero.
-
- A non-proleptic calendar with no year zero represents years from its first
- year onwards but provides no way to describe years before its first; such a
- calendar has no year zero and is not proleptic.
-
- A calendar which represents years before its first may number these years
- simply by following the usual integer counting, so that the year before the
- first is year zero, with negative-numbered years preceding this; such a
- calendar is proleptic and has a year zero. A calendar might also have a year
- zero (for example, the year of some great event, with subsequent years being
- the first year after that event, the second year after, and so on) without
- describing years before its year zero. Such a calendar would have a year zero
- without being proleptic.
-
- Some calendars, however, represent years before their first by an alternate
- numbering; for example, the proleptic Gregorian calendar's first year is 1 CE
- and the year before it is 1 BCE, preceded by 2 BCE and so on. In this case,
- we use negative year numbers, with year -1 as the year before year 1, year -2
- as the year before year -1 and so on. Such a calendar is proleptic but has no
- year zero.
-
- \sa isProleptic()
+ Returns \c true if this calendar has a year zero.
+
+ A calendar may represent years from its first year onwards but provide no
+ way to describe years before its first; such a calendar has no year zero and
+ is not proleptic.
+
+ A calendar which represents years before its first may number these years
+ simply by following the usual integer counting, so that the year before the
+ first is year zero, with negative-numbered years preceding this; such a
+ calendar is proleptic and has a year zero. A calendar might also have a year
+ zero (for example, the year of some great event, with subsequent years being
+ the first year after that event, the second year after, and so on) without
+ describing years before its year zero. Such a calendar would have a year
+ zero without being proleptic.
+
+ Some calendars, however, represent years before their first by an alternate
+ numbering; for example, the proleptic Gregorian calendar's first year is 1
+ CE and the year before it is 1 BCE, preceded by 2 BCE and so on. In this
+ case, we use negative year numbers for this alternate numbering, with year
+ -1 as the year before year 1, year -2 as the year before year -1 and so
+ on. Such a calendar is proleptic but has no year zero.
+
+ \sa isProleptic()
*/
bool QCalendar::hasYearZero() const
{
@@ -867,9 +872,9 @@ bool QCalendar::hasYearZero() const
}
/*!
- Returns the number of days in the longest month in the calendar, in any year.
+ Returns the number of days in the longest month in the calendar, in any year.
- \sa daysInMonth(), minimumDaysInMonth()
+ \sa daysInMonth(), minimumDaysInMonth()
*/
int QCalendar::maximumDaysInMonth() const
{
@@ -877,9 +882,9 @@ int QCalendar::maximumDaysInMonth() const
}
/*!
- Returns the number of days in the shortest month in the calendar, in any year.
+ Returns the number of days in the shortest month in the calendar, in any year.
- \sa daysInMonth(), maximumDaysInMonth()
+ \sa daysInMonth(), maximumDaysInMonth()
*/
int QCalendar::minimumDaysInMonth() const
{
@@ -887,9 +892,9 @@ int QCalendar::minimumDaysInMonth() const
}
/*!
- Returns the largest number of months that any year may contain.
+ Returns the largest number of months that any year may contain.
- \sa monthName(), standaloneMonthName(), monthsInYear()
+ \sa monthName(), standaloneMonthName(), monthsInYear()
*/
int QCalendar::maximumMonthsInYear() const
{
@@ -939,13 +944,13 @@ QCalendar::YearMonthDay QCalendar::partsFromDate(QDate date) const
}
/*!
- Returns the day of the week number for the given \a date.
+ Returns the day of the week number for the given \a date.
- Returns zero if the calendar is unable to represent the indicated date.
- Returns 1 for Monday through 7 for Sunday. Calendars with intercallary days
- may use other numbers to represent these.
+ Returns zero if the calendar is unable to represent the indicated date.
+ Returns 1 for Monday through 7 for Sunday. Calendars with intercallary days
+ may use other numbers to represent these.
- \sa partsFromDate(), Qt::DayOfWeek
+ \sa partsFromDate(), Qt::DayOfWeek
*/
int QCalendar::dayOfWeek(QDate date) const
{
@@ -955,23 +960,23 @@ int QCalendar::dayOfWeek(QDate date) const
// Locale data access
/*!
- Returns a suitably localised name for a month.
+ Returns a suitably localised name for a month.
- The month is indicated by a number, with \a month = 1 meaning the first month
- of the year and subsequent months numbered accordingly. Returns an empty
- string if the \a month number is unrecognized.
+ The month is indicated by a number, with \a month = 1 meaning the first
+ month of the year and subsequent months numbered accordingly. Returns an
+ empty string if the \a month number is unrecognized.
- The \a year may be Unspecified, in which case the mapping from numbers to
- names for a typical year's months should be used. Some calendars have leap
- months that aren't always at the end of the year; their mapping of month
- numbers to names may then depend on the placement of a leap month. Thus the
- year should normally be specified, if known.
+ The \a year may be Unspecified, in which case the mapping from numbers to
+ names for a typical year's months should be used. Some calendars have leap
+ months that aren't always at the end of the year; their mapping of month
+ numbers to names may then depend on the placement of a leap month. Thus the
+ year should normally be specified, if known.
- The name is returned in the form that would normally be used in a full date,
- in the specified \a locale; the \a format determines how fully it shall be
- expressed (i.e. to what extent it is abbreviated).
+ The name is returned in the form that would normally be used in a full date,
+ in the specified \a locale; the \a format determines how fully it shall be
+ expressed (i.e. to what extent it is abbreviated).
- \sa standaloneMonthName(), maximumMonthsInYear(), dateTimeToString()
+ \sa standaloneMonthName(), maximumMonthsInYear(), dateTimeToString()
*/
QString QCalendar::monthName(const QLocale &locale, int month, int year,
QLocale::FormatType format) const
@@ -984,23 +989,23 @@ QString QCalendar::monthName(const QLocale &locale, int month, int year,
}
/*!
- Returns a suitably localised standalone name for a month.
+ Returns a suitably localised standalone name for a month.
- The month is indicated by a number, with \a month = 1 meaning the first month
- of the year and subsequent months numbered accordingly. Returns an empty
- string if the \a month number is unrecognized.
+ The month is indicated by a number, with \a month = 1 meaning the first
+ month of the year and subsequent months numbered accordingly. Returns an
+ empty string if the \a month number is unrecognized.
- The \a year may be Unspecified, in which case the mapping from numbers to
- names for a typical year's months should be used. Some calendars have leap
- months that aren't always at the end of the year; their mapping of month
- numbers to names may then depend on the placement of a leap month. Thus the
- year should normally be specified, if known.
+ The \a year may be Unspecified, in which case the mapping from numbers to
+ names for a typical year's months should be used. Some calendars have leap
+ months that aren't always at the end of the year; their mapping of month
+ numbers to names may then depend on the placement of a leap month. Thus the
+ year should normally be specified, if known.
- The name is returned in the form that would be used in isolation in the
- specified \a locale; the \a format determines how fully it shall be expressed
- (i.e. to what extent it is abbreviated).
+ The name is returned in the form that would be used in isolation in the
+ specified \a locale; the \a format determines how fully it shall be
+ expressed (i.e. to what extent it is abbreviated).
- \sa monthName(), maximumMonthsInYear(), dateTimeToString()
+ \sa monthName(), maximumMonthsInYear(), dateTimeToString()
*/
QString QCalendar::standaloneMonthName(const QLocale &locale, int month, int year,
QLocale::FormatType format) const
@@ -1013,18 +1018,18 @@ QString QCalendar::standaloneMonthName(const QLocale &locale, int month, int yea
}
/*!
- Returns a suitably localised name for a day of the week.
+ Returns a suitably localised name for a day of the week.
- The days of the week are numbered from 1 for Monday through 7 for Sunday. Some
- calendars may support higher numbers for other days (e.g. intercallary days,
- that are not part of any week). Returns an empty string if the \a day number
- is unrecognized.
+ The days of the week are numbered from 1 for Monday through 7 for
+ Sunday. Some calendars may support higher numbers for other days
+ (e.g. intercallary days, that are not part of any week). Returns an empty
+ string if the \a day number is unrecognized.
- The name is returned in the form that would normally be used in a full date,
- in the specified \a locale; the \a format determines how fully it shall be
- expressed (i.e. to what extent it is abbreviated).
+ The name is returned in the form that would normally be used in a full date,
+ in the specified \a locale; the \a format determines how fully it shall be
+ expressed (i.e. to what extent it is abbreviated).
- \sa standaloneWeekDayName(), dayOfWeek()
+ \sa standaloneWeekDayName(), dayOfWeek()
*/
QString QCalendar::weekDayName(const QLocale &locale, int day,
QLocale::FormatType format) const
@@ -1033,19 +1038,20 @@ QString QCalendar::weekDayName(const QLocale &locale, int day,
}
/*!
- Returns a suitably localised standalone name for a day of the week.
+ Returns a suitably localised standalone name for a day of the week.
- The days of the week are numbered from 1 for Monday through 7 for Sunday. Some
- calendars may support higher numbers for other days (e.g. intercallary days,
- that are not part of any week). Returns an empty string if the \a day number
- is unrecognized.
+ The days of the week are numbered from 1 for Monday through 7 for
+ Sunday. Some calendars may support higher numbers for other days
+ (e.g. intercallary days, that are not part of any week). Returns an empty
+ string if the \a day number is unrecognized.
- The name is returned in the form that would be used in isolation (for example
- as a column heading in a calendar's tabular display of a month with successive
- weeks as rows) in the specified \a locale; the \a format determines how fully
- it shall be expressed (i.e. to what extent it is abbreviated).
+ The name is returned in the form that would be used in isolation (for
+ example as a column heading in a calendar's tabular display of a month with
+ successive weeks as rows) in the specified \a locale; the \a format
+ determines how fully it shall be expressed (i.e. to what extent it is
+ abbreviated).
- \sa weekDayName(), dayOfWeek()
+ \sa weekDayName(), dayOfWeek()
*/
QString QCalendar::standaloneWeekDayName(const QLocale &locale, int day,
QLocale::FormatType format) const
@@ -1054,23 +1060,23 @@ QString QCalendar::standaloneWeekDayName(const QLocale &locale, int day,
}
/*!
- Returns a string representing a given date, time or date-time.
-
- If \a datetime is valid, it is represented and format specifiers for both date
- and time fields are recognized; otherwise, if \a dateOnly is valid, it is
- represented and only format specifiers for date fields are recognized;
- finally, if \a timeOnly is valid, it is represented and only format specifiers
- for time fields are recognized. If none of these is valid, an empty string is
- returned.
-
- See QDate::toString and QTime::toString() for the supported field specifiers.
- Characters in \a format that are recognized as field specifiers are replaced
- by text representing appropriate data from the date and/or time being
- represented. The texts to represent them may depend on the \a locale
- specified. Other charagers in \a format are copied verbatim into the returned
- string.
-
- \sa monthName(), weekDayName(), QDate::toString(), QTime::toString()
+ Returns a string representing a given date, time or date-time.
+
+ If \a datetime is valid, it is represented and format specifiers for both
+ date and time fields are recognized; otherwise, if \a dateOnly is valid, it
+ is represented and only format specifiers for date fields are recognized;
+ finally, if \a timeOnly is valid, it is represented and only format
+ specifiers for time fields are recognized. If none of these is valid, an
+ empty string is returned.
+
+ See QDate::toString and QTime::toString() for the supported field
+ specifiers. Characters in \a format that are recognized as field specifiers
+ are replaced by text representing appropriate data from the date and/or time
+ being represented. The texts to represent them may depend on the \a locale
+ specified. Other charagers in \a format are copied verbatim into the
+ returned string.
+
+ \sa monthName(), weekDayName(), QDate::toString(), QTime::toString()
*/
QString QCalendar::dateTimeToString(QStringView format, const QDateTime &datetime,
const QDate &dateOnly, const QTime &timeOnly,
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp
index 8b1665e7dd..13a54c1210 100644
--- a/src/corelib/time/qdatetime.cpp
+++ b/src/corelib/time/qdatetime.cpp
@@ -3432,15 +3432,15 @@ inline qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QT
datetime by adding a number of seconds, days, months, or years.
QDateTime can describe datetimes with respect to \l{Qt::LocalTime}{local
- time}, to \l{Qt::UTC}{UTC}, to a specified \l{Qt::OffsetFromUTC}{offset
- from UTC} or to a specified \l{Qt::TimeZone}{time zone}, in conjunction
- with the QTimeZone class. For example, a time zone of "Europe/Berlin" will
- apply the daylight-saving rules as used in Germany since 1970. In contrast,
- an offset from UTC of +3600 seconds is one hour ahead of UTC (usually
- written in ISO standard notation as "UTC+01:00"), with no daylight-saving
- offset or changes. When using either local time or a specified time zone,
- time-zone transitions such as the starts and ends of daylight-saving time
- (DST) are taken into account. The choice of system used to represent a
+ time}, to \l{Qt::UTC}{UTC}, to a specified \l{Qt::OffsetFromUTC}{offset from
+ UTC} or to a specified \l{Qt::TimeZone}{time zone}, in conjunction with the
+ QTimeZone class. For example, a time zone of "Europe/Berlin" will apply the
+ daylight-saving rules as used in Germany since 1970. In contrast, an offset
+ from UTC of +3600 seconds is one hour ahead of UTC (usually written in ISO
+ standard notation as "UTC+01:00"), with no daylight-saving offset or
+ changes. When using either local time or a specified time zone, time-zone
+ transitions such as the starts and ends of daylight-saving time (DST; but
+ see below) are taken into account. The choice of system used to represent a
datetime is described as its "timespec".
A QDateTime object is typically created either by giving a date and time
@@ -3528,11 +3528,13 @@ inline qint64 QDateTimePrivate::zoneMSecsToEpochMSecs(qint64 zoneMSecs, const QT
The range of valid dates taking DST into account is 1970-01-01 to the
present, and rules are in place for handling DST correctly until 2037-12-31,
- but these could change. For dates falling outside that range, QDateTime
- makes a \e{best guess} using the rules for year 1970 or 2037, but we can't
- guarantee accuracy. This means QDateTime doesn't take into account changes
- in a time zone before 1970, even if the system's time zone database provides
- that information.
+ but these could change. For dates after 2037, QDateTime makes a \e{best
+ guess} using the rules for year 2037, but we can't guarantee accuracy;
+ indeed, for \e{any} future date, the time-zone may change its rules before
+ that date comes around. For dates before 1970, QDateTime doesn't take DST
+ changes into account, even if the system's time zone database provides that
+ information, although it does take into account changes to the time-zone's
+ standard offset, where this information is available.
\section2 Offsets From UTC
@@ -3797,17 +3799,22 @@ QTimeZone QDateTime::timeZone() const
/*!
\since 5.2
- Returns the current Offset From UTC in seconds.
+ Returns this date-time's Offset From UTC in seconds.
- If the timeSpec() is Qt::OffsetFromUTC this will be the value originally set.
-
- If the timeSpec() is Qt::TimeZone this will be the offset effective in the
- Time Zone including any Daylight-Saving Offset.
-
- If the timeSpec() is Qt::LocalTime this will be the difference between the
- Local Time and UTC including any Daylight-Saving Offset.
+ The result depends on timeSpec():
+ \list
+ \li \c Qt::UTC The offset is 0.
+ \li \c Qt::OffsetFromUTC The offset is the value originally set.
+ \li \c Qt::LocalTime The local time's offset from UTC is returned.
+ \li \c Qt::TimeZone The offset used by the time-zone is returned.
+ \endlist
- If the timeSpec() is Qt::UTC this will be 0.
+ For the last two, the offset at this date and time will be returned, taking
+ account of Daylight-Saving Offset unless the date precedes the start of
+ 1970. The offset is the difference between the local time or time in the
+ given time-zone and UTC time; it is positive in time-zones ahead of UTC
+ (East of The Prime Meridian), negative for those behind UTC (West of The
+ Prime Meridian).
\sa setOffsetFromUtc()
*/
diff --git a/src/corelib/time/qhijricalendar.cpp b/src/corelib/time/qhijricalendar.cpp
index 9aabe46570..b5d89fbc5c 100644
--- a/src/corelib/time/qhijricalendar.cpp
+++ b/src/corelib/time/qhijricalendar.cpp
@@ -44,36 +44,37 @@
QT_BEGIN_NAMESPACE
/*!
- \since 5.14
+ \since 5.14
+ \internal
- \class QHijriCalendar
- \inmodule QtCore
- \brief The QHijriCalendar class supports Islamic (Hijri) calendar implementations.
+ \class QHijriCalendar
+ \inmodule QtCore
+ \brief The QHijriCalendar class supports Islamic (Hijri) calendar implementations.
- \section1 Islamic Calendar System
+ \section1 Islamic Calendar System
- The Islamic, Muslim, or Hijri calendar is a lunar calendar consisting of 12
- months in a year of 354 or 355 days. It is used (often alongside the
- Gregorian calendar) to date events in many Muslim countries. It is also used
- by Muslims to determine the proper days of Islamic holidays and rituals,
- such as the annual period of fasting and the proper time for the pilgrimage
- to Mecca.
+ The Islamic, Muslim, or Hijri calendar is a lunar calendar consisting of 12
+ months in a year of 354 or 355 days. It is used (often alongside the
+ Gregorian calendar) to date events in many Muslim countries. It is also used
+ by Muslims to determine the proper days of Islamic holidays and rituals,
+ such as the annual period of fasting and the proper time for the pilgrimage
+ to Mecca.
- Source: \l {https://en.wikipedia.org/wiki/Islamic_calendar}{Wikipedia page on
- Hijri Calendar}
+ Source: \l {https://en.wikipedia.org/wiki/Islamic_calendar}{Wikipedia page
+ on Hijri Calendar}
- \section1 Support for variants
+ \section1 Support for variants
- This base class provides the common details shared by all variants on the
- Islamic calendar. Each year comprises 12 months of 29 or 30 days each; most
- years have as many of 29 as of 30, but leap years extend one 29-day month to
- 30 days. In tabular versions of the calendar (where mathematical rules are
- used to determine the details), odd-numbered months have 30 days, as does the
- last (twelfth) month of a leap year; all other months have 29 days. Other
- versions are based on actual astronomical observations of the moon's phase at
- sunset, which vary from place to place.
+ This base class provides the common details shared by all variants on the
+ Islamic calendar. Each year comprises 12 months of 29 or 30 days each; most
+ years have as many of 29 as of 30, but leap years extend one 29-day month to
+ 30 days. In tabular versions of the calendar (where mathematical rules are
+ used to determine the details), odd-numbered months have 30 days, as does
+ the last (twelfth) month of a leap year; all other months have 29
+ days. Other versions are based on actual astronomical observations of the
+ moon's phase at sunset, which vary from place to place.
- \sa QIslamicCivilCalendar, QCalendar
+ \sa QIslamicCivilCalendar, QCalendar
*/
bool QHijriCalendar::isLunar() const
diff --git a/src/corelib/time/qislamiccivilcalendar.cpp b/src/corelib/time/qislamiccivilcalendar.cpp
index 27c93f5c00..a6a2afd207 100644
--- a/src/corelib/time/qislamiccivilcalendar.cpp
+++ b/src/corelib/time/qislamiccivilcalendar.cpp
@@ -47,27 +47,29 @@ QT_BEGIN_NAMESPACE
using namespace QRoundingDown;
/*!
- \since 5.14
+ \since 5.14
+ \internal
- \class QIslamicCivilCalendar
- \inmodule QtCore
- \brief Implements a commonly-used computed version of the Islamic calendar.
+ \class QIslamicCivilCalendar
+ \inmodule QtCore
+ \brief Implements a commonly-used computed version of the Islamic calendar.
- \section1 Civil Islamic Calendar
+ \section1 Civil Islamic Calendar
- QIslamicCivilCalendar implements a tabular version of the Hijri calendar which
- is known as the Islamic Civil Calendar. It has the same numbering of years and
- months, but the months are determined by arithmetical rules rather than by
- observation or astronomical calculations.
+ QIslamicCivilCalendar implements a tabular version of the Hijri calendar
+ which is known as the Islamic Civil Calendar. It has the same numbering of
+ years and months, but the months are determined by arithmetical rules rather
+ than by observation or astronomical calculations.
- \section2 Calendar Organization
+ \section2 Calendar Organization
- The civil calendar follows the usual tabular scheme of odd-numbered months and
- the last month of each leap year being 30 days long, the rest being 29 days
- long. Its determination of leap years follows a 30-year cycle, in each of
- which the years 2, 5, 7, 10, 13, 16, 18, 21, 24, 26 and 29 are leap years.
+ The civil calendar follows the usual tabular scheme of odd-numbered months
+ and the last month of each leap year being 30 days long, the rest being 29
+ days long. Its determination of leap years follows a 30-year cycle, in each
+ of which the years 2, 5, 7, 10, 13, 16, 18, 21, 24, 26 and 29 are leap
+ years.
- \sa QJijriCalendar, QCalendar
+ \sa QHijriCalendar, QCalendar
*/
QIslamicCivilCalendar::QIslamicCivilCalendar()
diff --git a/src/corelib/time/qromancalendar.cpp b/src/corelib/time/qromancalendar.cpp
index 36cad01b81..c3cd134490 100644
--- a/src/corelib/time/qromancalendar.cpp
+++ b/src/corelib/time/qromancalendar.cpp
@@ -44,20 +44,20 @@
QT_BEGIN_NAMESPACE
/*!
- \since 5.14
+ \since 5.14
- \class QRomanCalendar
- \inmodule QtCore
- \brief The QRomanCalendar class is a shared base for calendars based on the
- ancient Roman calendar.
+ \class QRomanCalendar
+ \inmodule QtCore
+ \brief The QRomanCalendar class is a shared base for calendars based on the
+ ancient Roman calendar.
- \section1
+ \section1
- Calendars based on the ancient Roman calendar share the names of months, whose
- lengths depend in a common way on whether the year is a leap year. They differ
- in how they determine which years are leap years.
+ Calendars based on the ancient Roman calendar share the names of months,
+ whose lengths depend in a common way on whether the year is a leap
+ year. They differ in how they determine which years are leap years.
- \sa QGregorianCalendar, QJulianCalendar, QMilankovicCalendar
+ \sa QGregorianCalendar, QJulianCalendar, QMilankovicCalendar
*/
int QRomanCalendar::daysInMonth(int month, int year) const
diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp
index ef323de14a..410a16e3c5 100644
--- a/src/corelib/time/qtimezone.cpp
+++ b/src/corelib/time/qtimezone.cpp
@@ -325,20 +325,33 @@ QTimeZone::QTimeZone() noexcept
/*!
Creates an instance of the requested time zone \a ianaId.
- The ID must be one of the available system IDs otherwise an invalid
- time zone will be returned.
+ The ID must be one of the available system IDs or a valid UTC-with-offset
+ ID, otherwise an invalid time zone will be returned.
\sa availableTimeZoneIds()
*/
QTimeZone::QTimeZone(const QByteArray &ianaId)
{
- // Try and see if it's a valid UTC offset ID, just as quick to try create as look-up
+ // Try and see if it's a CLDR UTC offset ID - just as quick by creating as
+ // by looking up.
d = new QUtcTimeZonePrivate(ianaId);
- // If not a valid UTC offset ID then try create it with the system backend
- // Relies on backend not creating valid tz with invalid name
+ // If not a CLDR UTC offset ID then try creating it with the system backend.
+ // Relies on backend not creating valid TZ with invalid name.
if (!d->isValid())
d = newBackendTimeZone(ianaId);
+ // Can also handle UTC with arbitrary (valid) offset, but only do so as
+ // fall-back, since either of the above may handle it more informatively.
+ if (!d->isValid()) {
+ qint64 offset = QUtcTimeZonePrivate::offsetFromUtcString(ianaId);
+ if (offset != QTimeZonePrivate::invalidSeconds()) {
+ // Should have abs(offset) < 24 * 60 * 60 = 86400.
+ qint32 seconds = qint32(offset);
+ Q_ASSERT(qint64(seconds) == offset);
+ // NB: this canonicalises the name, so it might not match ianaId
+ d = new QUtcTimeZonePrivate(seconds);
+ }
+ }
}
/*!
diff --git a/src/corelib/time/qtimezoneprivate.cpp b/src/corelib/time/qtimezoneprivate.cpp
index 569b343187..72a0e3c24e 100644
--- a/src/corelib/time/qtimezoneprivate.cpp
+++ b/src/corelib/time/qtimezoneprivate.cpp
@@ -1,5 +1,6 @@
/****************************************************************************
**
+** Copyright (C) 2019 The Qt Company Ltd.
** Copyright (C) 2013 John Layt <jlayt@kde.org>
** Contact: https://www.qt.io/licensing/
**
@@ -761,6 +762,39 @@ QUtcTimeZonePrivate::QUtcTimeZonePrivate(const QByteArray &id)
}
}
+qint64 QUtcTimeZonePrivate::offsetFromUtcString(const QByteArray &id)
+{
+ // Convert reasonable UTC[+-]\d+(:\d+){,2} to offset in seconds.
+ // Assumption: id has already been tried as a CLDR UTC offset ID (notably
+ // including plain "UTC" itself) and a system offset ID; it's neither.
+ if (!id.startsWith("UTC") || id.size() < 5)
+ return invalidSeconds(); // Doesn't match
+ const char signChar = id.at(3);
+ if (signChar != '-' && signChar != '+')
+ return invalidSeconds(); // No sign
+ const int sign = signChar == '-' ? -1 : 1;
+
+ const auto offsets = id.mid(4).split(':');
+ if (offsets.isEmpty() || offsets.size() > 3)
+ return invalidSeconds(); // No numbers, or too many.
+
+ qint32 seconds = 0;
+ int prior = 0; // Number of fields parsed thus far
+ for (const auto &offset : offsets) {
+ bool ok = false;
+ unsigned short field = offset.toUShort(&ok);
+ // Bound hour above at 24, minutes and seconds at 60:
+ if (!ok || field >= (prior ? 60 : 24))
+ return invalidSeconds();
+ seconds = seconds * 60 + field;
+ ++prior;
+ }
+ while (prior++ < 3)
+ seconds *= 60;
+
+ return seconds * sign;
+}
+
// Create offset from UTC
QUtcTimeZonePrivate::QUtcTimeZonePrivate(qint32 offsetSeconds)
{
@@ -874,22 +908,25 @@ QByteArray QUtcTimeZonePrivate::systemTimeZoneId() const
bool QUtcTimeZonePrivate::isTimeZoneIdAvailable(const QByteArray &ianaId) const
{
+ // Only the zone IDs supplied by CLDR and recognized by constructor.
for (int i = 0; i < utcDataTableSize; ++i) {
const QUtcData *data = utcData(i);
- if (utcId(data) == ianaId) {
+ if (utcId(data) == ianaId)
return true;
- }
}
+ // But see offsetFromUtcString(), which lets us accept some "unavailable" IDs.
return false;
}
QList<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds() const
{
+ // Only the zone IDs supplied by CLDR and recognized by constructor.
QList<QByteArray> result;
result.reserve(utcDataTableSize);
for (int i = 0; i < utcDataTableSize; ++i)
result << utcId(utcData(i));
- std::sort(result.begin(), result.end()); // ### or already sorted??
+ // Not guaranteed to be sorted, so sort:
+ std::sort(result.begin(), result.end());
// ### assuming no duplicates
return result;
}
@@ -904,13 +941,16 @@ QList<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds(QLocale::Country cou
QList<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds(qint32 offsetSeconds) const
{
+ // Only if it's present in CLDR. (May get more than one ID: UTC, UTC+00:00
+ // and UTC-00:00 all have the same offset.)
QList<QByteArray> result;
for (int i = 0; i < utcDataTableSize; ++i) {
const QUtcData *data = utcData(i);
if (data->offsetFromUtc == offsetSeconds)
result << utcId(data);
}
- std::sort(result.begin(), result.end()); // ### or already sorted??
+ // Not guaranteed to be sorted, so sort:
+ std::sort(result.begin(), result.end());
// ### assuming no duplicates
return result;
}
diff --git a/src/corelib/time/qtimezoneprivate_p.h b/src/corelib/time/qtimezoneprivate_p.h
index 5f6491ef81..a57f61f381 100644
--- a/src/corelib/time/qtimezoneprivate_p.h
+++ b/src/corelib/time/qtimezoneprivate_p.h
@@ -188,6 +188,9 @@ public:
QUtcTimeZonePrivate(const QUtcTimeZonePrivate &other);
virtual ~QUtcTimeZonePrivate();
+ // Fall-back for UTC[+-]\d+(:\d+){,2} IDs.
+ static qint64 offsetFromUtcString(const QByteArray &id);
+
QUtcTimeZonePrivate *clone() const override;
Data data(qint64 forMSecsSinceEpoch) const override;
diff --git a/src/corelib/time/qtimezoneprivate_win.cpp b/src/corelib/time/qtimezoneprivate_win.cpp
index 1bf2366748..5a480222e0 100644
--- a/src/corelib/time/qtimezoneprivate_win.cpp
+++ b/src/corelib/time/qtimezoneprivate_win.cpp
@@ -371,6 +371,7 @@ QDate calculateTransitionLocalDate(const SYSTEMTIME &rule, int year)
// Otherwise, the rule date is annual and relative:
const int dayOfWeek = rule.wDayOfWeek == 0 ? 7 : rule.wDayOfWeek;
QDate date(year, rule.wMonth, 1);
+ Q_ASSERT(date.isValid());
// How many days before was last dayOfWeek before target month ?
int adjust = dayOfWeek - date.dayOfWeek(); // -6 <= adjust < 7
if (adjust >= 0) // Ensure -7 <= adjust < 0:
@@ -401,6 +402,7 @@ qint64 calculateTransitionForYear(const SYSTEMTIME &rule, int year, int bias)
{
// TODO Consider caching the calculated values - i.e. replace SYSTEMTIME in
// WinTransitionRule; do this in init() once and store the results.
+ Q_ASSERT(year);
const QDate date = calculateTransitionLocalDate(rule, year);
const QTime time = QTime(rule.wHour, rule.wMinute, rule.wSecond);
if (date.isValid() && time.isValid())
@@ -479,6 +481,7 @@ struct TransitionTimePair
int yearEndOffset(const QWinTimeZonePrivate::QWinTransitionRule &rule, int year)
{
+ Q_ASSERT(year);
int offset = rule.standardTimeBias;
// Only needed to help another TransitionTimePair work out year + 1's start
// offset; and the oldYearOffset we use only affects an alleged transition
@@ -743,11 +746,12 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::data(qint64 forMSecsSinceEpoch) cons
const QWinTransitionRule &rule = m_tranRules.at(ruleIndex);
// Does this rule's period include any transition at all ?
if (rule.standardTimeRule.wMonth > 0 || rule.daylightTimeRule.wMonth > 0) {
- const int endYear = qMax(rule.startYear, year - 1);
+ int prior = year == 1 ? -1 : year - 1; // No year 0.
+ const int endYear = qMax(rule.startYear, prior);
while (year >= endYear) {
const int newYearOffset = (year <= rule.startYear && ruleIndex > 0)
- ? yearEndOffset(m_tranRules.at(ruleIndex - 1), year - 1)
- : yearEndOffset(rule, year - 1);
+ ? yearEndOffset(m_tranRules.at(ruleIndex - 1), prior)
+ : yearEndOffset(rule, prior);
const TransitionTimePair pair(rule, year, newYearOffset);
bool isDst = false;
if (pair.std != invalidMSecs() && pair.std <= forMSecsSinceEpoch) {
@@ -755,7 +759,8 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::data(qint64 forMSecsSinceEpoch) cons
} else if (pair.dst != invalidMSecs() && pair.dst <= forMSecsSinceEpoch) {
isDst = true;
} else {
- --year; // Try an earlier year for this rule (once).
+ year = prior; // Try an earlier year for this rule (once).
+ prior = year == 1 ? -1 : year - 1; // No year 0.
continue;
}
return ruleToData(rule, forMSecsSinceEpoch,
@@ -767,8 +772,11 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::data(qint64 forMSecsSinceEpoch) cons
// No transition, no DST, use the year's standard time.
return ruleToData(rule, forMSecsSinceEpoch, QTimeZone::StandardTime);
}
- if (year >= rule.startYear)
+ if (year >= rule.startYear) {
year = rule.startYear - 1; // Seek last transition in new rule.
+ if (!year)
+ --year;
+ }
}
// We don't have relevant data :-(
return invalidData();
@@ -795,9 +803,10 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::nextTransition(qint64 afterMSecsSinc
year = rule.startYear; // Seek first transition in this rule.
const int endYear = ruleIndex + 1 < m_tranRules.count()
? qMin(m_tranRules.at(ruleIndex + 1).startYear, year + 2) : (year + 2);
+ int prior = year == 1 ? -1 : year - 1; // No year 0.
int newYearOffset = (year <= rule.startYear && ruleIndex > 0)
- ? yearEndOffset(m_tranRules.at(ruleIndex - 1), year - 1)
- : yearEndOffset(rule, year - 1);
+ ? yearEndOffset(m_tranRules.at(ruleIndex - 1), prior)
+ : yearEndOffset(rule, prior);
while (year < endYear) {
const TransitionTimePair pair(rule, year, newYearOffset);
bool isDst = false;
@@ -810,7 +819,9 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::nextTransition(qint64 afterMSecsSinc
newYearOffset = rule.standardTimeBias;
if (pair.dst > pair.std)
newYearOffset += rule.daylightTimeBias;
- ++year; // Try a later year for this rule (once).
+ // Try a later year for this rule (once).
+ prior = year;
+ year = year == -1 ? 1 : year + 1; // No year 0
continue;
}
@@ -837,11 +848,12 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::previousTransition(qint64 beforeMSec
const QWinTransitionRule &rule = m_tranRules.at(ruleIndex);
// Does this rule's period include any transition at all ?
if (rule.standardTimeRule.wMonth > 0 || rule.daylightTimeRule.wMonth > 0) {
- const int endYear = qMax(rule.startYear, year - 1);
+ int prior = year == 1 ? -1 : year - 1; // No year 0.
+ const int endYear = qMax(rule.startYear, prior);
while (year >= endYear) {
const int newYearOffset = (year <= rule.startYear && ruleIndex > 0)
- ? yearEndOffset(m_tranRules.at(ruleIndex - 1), year - 1)
- : yearEndOffset(rule, year - 1);
+ ? yearEndOffset(m_tranRules.at(ruleIndex - 1), prior)
+ : yearEndOffset(rule, prior);
const TransitionTimePair pair(rule, year, newYearOffset);
bool isDst = false;
if (pair.std != invalidMSecs() && pair.std < beforeMSecsSinceEpoch) {
@@ -849,7 +861,8 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::previousTransition(qint64 beforeMSec
} else if (pair.dst != invalidMSecs() && pair.dst < beforeMSecsSinceEpoch) {
isDst = true;
} else {
- --year; // Try an earlier year for this rule (once).
+ year = prior; // Try an earlier year for this rule (once).
+ prior = year == 1 ? -1 : year - 1; // No year 0.
continue;
}
if (isDst)
@@ -863,8 +876,11 @@ QTimeZonePrivate::Data QWinTimeZonePrivate::previousTransition(qint64 beforeMSec
// rule:
return ruleToData(rule, startOfTime, QTimeZone::StandardTime, false);
} // else: no transition during rule's period
- if (year >= rule.startYear)
+ if (year >= rule.startYear) {
year = rule.startYear - 1; // Seek last transition in new rule
+ if (!year)
+ --year;
+ }
}
// Apparently no transition before the given time:
return invalidData();
diff --git a/src/corelib/tools/qcontainertools_impl.h b/src/corelib/tools/qcontainertools_impl.h
index 86a16eb32b..3a0c4381f1 100644
--- a/src/corelib/tools/qcontainertools_impl.h
+++ b/src/corelib/tools/qcontainertools_impl.h
@@ -49,8 +49,6 @@
#include <QtCore/qglobal.h>
#include <iterator>
-#ifndef Q_QDOC
-
QT_BEGIN_NAMESPACE
namespace QtPrivate
@@ -131,6 +129,4 @@ using IfAssociativeIteratorHasFirstAndSecond =
QT_END_NAMESPACE
-#endif // Q_QDOC
-
#endif // QCONTAINERTOOLS_IMPL_H
diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp
index 1d0c93f26f..27c82bc09f 100644
--- a/src/gui/image/qiconloader.cpp
+++ b/src/gui/image/qiconloader.cpp
@@ -281,7 +281,7 @@ static quint32 icon_name_hash(const char *p)
QVector<const char *> QIconCacheGtkReader::lookup(const QStringRef &name)
{
QVector<const char *> ret;
- if (!isValid())
+ if (!isValid() || name.isEmpty())
return ret;
QByteArray nameUtf8 = name.toUtf8();
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 86130132a4..dda407181a 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -3370,7 +3370,7 @@ void QImage::mirrored_inplace(bool horizontal, bool vertical)
\sa {QImage#Image Transformations}{Image Transformations}
*/
-inline void rgbSwapped_generic(int width, int height, const QImage *src, QImage *dst, const QPixelLayout* layout)
+static inline void rgbSwapped_generic(int width, int height, const QImage *src, QImage *dst, const QPixelLayout* layout)
{
const RbSwapFunc func = layout->rbSwap;
if (!func) {
diff --git a/src/gui/image/qimage_conversions.cpp b/src/gui/image/qimage_conversions.cpp
index 539bac222a..9e1df7058c 100644
--- a/src/gui/image/qimage_conversions.cpp
+++ b/src/gui/image/qimage_conversions.cpp
@@ -564,6 +564,67 @@ static bool convert_RGBA_to_ARGB_inplace(QImageData *data, Qt::ImageConversionFl
return true;
}
+static void convert_rgbswap_generic(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
+{
+ Q_ASSERT(src->width == dest->width);
+ Q_ASSERT(src->height == dest->height);
+
+ const RbSwapFunc func = qPixelLayouts[src->format].rbSwap;
+ Q_ASSERT(func);
+
+ const qsizetype sbpl = src->bytes_per_line;
+ const qsizetype dbpl = dest->bytes_per_line;
+ const uchar *src_data = src->data;
+ uchar *dest_data = dest->data;
+
+ for (int i = 0; i < src->height; ++i) {
+ func(dest_data, src_data, src->width);
+
+ src_data += sbpl;
+ dest_data += dbpl;
+ }
+}
+
+static bool convert_rgbswap_generic_inplace(QImageData *data, Qt::ImageConversionFlags)
+{
+ const RbSwapFunc func = qPixelLayouts[data->format].rbSwap;
+ Q_ASSERT(func);
+
+ const qsizetype bpl = data->bytes_per_line;
+ uchar *line_data = data->data;
+
+ for (int i = 0; i < data->height; ++i) {
+ func(line_data, line_data, data->width);
+ line_data += bpl;
+ }
+
+ switch (data->format) {
+ case QImage::Format_RGB888:
+ data->format = QImage::Format_BGR888;
+ break;
+ case QImage::Format_BGR888:
+ data->format = QImage::Format_RGB888;
+ break;
+ case QImage::Format_BGR30:
+ data->format = QImage::Format_RGB30;
+ break;
+ case QImage::Format_A2BGR30_Premultiplied:
+ data->format = QImage::Format_A2RGB30_Premultiplied;
+ break;
+ case QImage::Format_RGB30:
+ data->format = QImage::Format_BGR30;
+ break;
+ case QImage::Format_A2RGB30_Premultiplied:
+ data->format = QImage::Format_A2BGR30_Premultiplied;
+ break;
+ default:
+ Q_UNREACHABLE();
+ data->format = QImage::Format_Invalid;
+ return false;
+ }
+ return true;
+}
+
template<QtPixelOrder PixelOrder, bool RGBA>
static void convert_RGB_to_RGB30(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
{
@@ -693,74 +754,10 @@ static bool convert_A2RGB30_PM_to_RGB30_inplace(QImageData *data, Qt::ImageConve
return true;
}
-static void convert_BGR30_to_RGB30(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
-{
- Q_ASSERT(src->format == QImage::Format_RGB30 || src->format == QImage::Format_BGR30 ||
- src->format == QImage::Format_A2RGB30_Premultiplied || src->format == QImage::Format_A2BGR30_Premultiplied);
- Q_ASSERT(dest->format == QImage::Format_RGB30 || dest->format == QImage::Format_BGR30 ||
- dest->format == QImage::Format_A2RGB30_Premultiplied || dest->format == QImage::Format_A2BGR30_Premultiplied);
- Q_ASSERT(src->width == dest->width);
- Q_ASSERT(src->height == dest->height);
-
- const int src_pad = (src->bytes_per_line >> 2) - src->width;
- const int dest_pad = (dest->bytes_per_line >> 2) - dest->width;
- const quint32 *src_data = (quint32 *) src->data;
- quint32 *dest_data = (quint32 *) dest->data;
-
- for (int i = 0; i < src->height; ++i) {
- const quint32 *end = src_data + src->width;
- while (src_data < end) {
- *dest_data = qRgbSwapRgb30(*src_data);
- ++src_data;
- ++dest_data;
- }
- src_data += src_pad;
- dest_data += dest_pad;
- }
-}
-
-static bool convert_BGR30_to_RGB30_inplace(QImageData *data, Qt::ImageConversionFlags)
-{
- Q_ASSERT(data->format == QImage::Format_RGB30 || data->format == QImage::Format_BGR30 ||
- data->format == QImage::Format_A2RGB30_Premultiplied || data->format == QImage::Format_A2BGR30_Premultiplied);
-
- const int pad = (data->bytes_per_line >> 2) - data->width;
- uint *rgb_data = (uint *) data->data;
-
- for (int i = 0; i < data->height; ++i) {
- const uint *end = rgb_data + data->width;
- while (rgb_data < end) {
- *rgb_data = qRgbSwapRgb30(*rgb_data);
- ++rgb_data;
- }
- rgb_data += pad;
- }
-
- switch (data->format) {
- case QImage::Format_BGR30:
- data->format = QImage::Format_RGB30;
- break;
- case QImage::Format_A2BGR30_Premultiplied:
- data->format = QImage::Format_A2RGB30_Premultiplied;
- break;
- case QImage::Format_RGB30:
- data->format = QImage::Format_BGR30;
- break;
- case QImage::Format_A2RGB30_Premultiplied:
- data->format = QImage::Format_A2BGR30_Premultiplied;
- break;
- default:
- Q_UNREACHABLE();
- data->format = QImage::Format_Invalid;
- return false;
- }
- return true;
-}
-
static bool convert_BGR30_to_A2RGB30_inplace(QImageData *data, Qt::ImageConversionFlags flags)
{
Q_ASSERT(data->format == QImage::Format_RGB30 || data->format == QImage::Format_BGR30);
- if (!convert_BGR30_to_RGB30_inplace(data, flags))
+ if (!convert_rgbswap_generic_inplace(data, flags))
return false;
if (data->format == QImage::Format_RGB30)
@@ -1421,69 +1418,6 @@ static void convert_RGBA64_to_gray16(QImageData *dest, const QImageData *src, Qt
}
}
-static void convert_RGB888_to_BGR888(QImageData *dest, const QImageData *src, Qt::ImageConversionFlags)
-{
- Q_ASSERT(src->format == QImage::Format_RGB888 || src->format == QImage::Format_BGR888);
- Q_ASSERT(dest->format == QImage::Format_RGB888 || dest->format == QImage::Format_BGR888);
- Q_ASSERT(src->width == dest->width);
- Q_ASSERT(src->height == dest->height);
-
- const qsizetype sbpl = src->bytes_per_line;
- const qsizetype dbpl = dest->bytes_per_line;
- const uchar *src_data = src->data;
- uchar *dest_data = dest->data;
-
- for (int i = 0; i < src->height; ++i) {
- int pixel = 0;
- // Handle 4 pixels (12 bytes) at a time
- for (; pixel + 3 < src->width; pixel += 4) {
- const uchar *src = src_data + pixel * 3;
- quint32 *dest_packed = (quint32 *) (dest_data + pixel * 3);
- dest_packed[0] = (src[5] << 24) | (src[0] << 16) | (src[1] << 8) | (src[2] << 0);
- dest_packed[1] = (src[7] << 24) | (src[8] << 16) | (src[3] << 8) | (src[4] << 0);
- dest_packed[2] = (src[9] << 24) | (src[10] << 16) | (src[11] << 8) | (src[6] << 0);
- }
-
- // epilog: handle left over pixels
- for (; pixel < src->width; ++pixel) {
- dest_data[pixel * 3 + 0] = src_data[pixel * 3 + 2];
- dest_data[pixel * 3 + 1] = src_data[pixel * 3 + 1];
- dest_data[pixel * 3 + 2] = src_data[pixel * 3 + 0];
- }
-
- src_data += sbpl;
- dest_data += dbpl;
- }
-}
-
-static bool convert_RGB888_to_BGR888_inplace(QImageData *data, Qt::ImageConversionFlags)
-{
- Q_ASSERT(data->format == QImage::Format_RGB888 || data->format == QImage::Format_BGR888);
-
- const qsizetype bpl = data->bytes_per_line;
- uchar *line_data = data->data;
-
- for (int i = 0; i < data->height; ++i) {
- for (int j = 0; j < data->width; ++j)
- qSwap(line_data[j * 3 + 0], line_data[j * 3 + 2]);
- line_data += bpl;
- }
-
- switch (data->format) {
- case QImage::Format_RGB888:
- data->format = QImage::Format_BGR888;
- break;
- case QImage::Format_BGR888:
- data->format = QImage::Format_RGB888;
- break;
- default:
- Q_UNREACHABLE();
- data->format = QImage::Format_Invalid;
- return false;
- }
- return true;
-}
-
static QVector<QRgb> fix_color_table(const QVector<QRgb> &ctbl, QImage::Format format)
{
QVector<QRgb> colorTable = ctbl;
@@ -2635,7 +2569,7 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat
convert_RGB888_to_RGB<true>,
convert_RGB888_to_RGB<true>,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- convert_RGB888_to_BGR888,
+ convert_rgbswap_generic,
}, // Format_RGB888
{
@@ -2781,8 +2715,8 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat
0,
0,
convert_passthrough,
- convert_BGR30_to_RGB30,
- convert_BGR30_to_RGB30,
+ convert_rgbswap_generic,
+ convert_rgbswap_generic,
0, 0,
0, 0, 0, 0, 0
}, // Format_BGR30
@@ -2809,7 +2743,7 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat
convert_A2RGB30_PM_to_RGB30<false>,
0,
convert_A2RGB30_PM_to_RGB30<true>,
- convert_BGR30_to_RGB30,
+ convert_rgbswap_generic,
0, 0,
0, 0, 0, 0, 0
}, // Format_A2BGR30_Premultiplied
@@ -2833,8 +2767,8 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat
0,
0,
0,
- convert_BGR30_to_RGB30,
- convert_BGR30_to_RGB30,
+ convert_rgbswap_generic,
+ convert_rgbswap_generic,
0,
convert_passthrough,
0, 0, 0, 0, 0, 0, 0
@@ -2860,7 +2794,7 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat
convert_A2RGB30_PM_to_ARGB<PixelOrderRGB, true>,
0,
convert_A2RGB30_PM_to_RGB30<true>,
- convert_BGR30_to_RGB30,
+ convert_rgbswap_generic,
convert_A2RGB30_PM_to_RGB30<false>,
0,
0, 0,
@@ -3013,7 +2947,7 @@ Image_Converter qimage_converter_map[QImage::NImageFormats][QImage::NImageFormat
0,
0,
0,
- convert_RGB888_to_BGR888,
+ convert_rgbswap_generic,
0,
0,
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
@@ -3161,7 +3095,7 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma
}, // Format_ARGB8555_Premultiplied
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- convert_RGB888_to_BGR888_inplace
+ convert_rgbswap_generic_inplace
}, // Format_RGB888
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@@ -3267,7 +3201,7 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma
0,
0, // self
convert_passthrough_inplace<QImage::Format_A2BGR30_Premultiplied>,
- convert_BGR30_to_RGB30_inplace,
+ convert_rgbswap_generic_inplace,
convert_BGR30_to_A2RGB30_inplace,
0, 0,
0, 0, 0, 0, 0
@@ -3295,7 +3229,7 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma
convert_A2RGB30_PM_to_RGB30_inplace<false>,
0, // self
convert_A2RGB30_PM_to_RGB30_inplace<true>,
- convert_BGR30_to_RGB30_inplace,
+ convert_rgbswap_generic_inplace,
0, 0, 0, 0, 0, 0, 0
}, // Format_A2BGR30_Premultiplied
{
@@ -3318,7 +3252,7 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma
0,
0,
0,
- convert_BGR30_to_RGB30_inplace,
+ convert_rgbswap_generic_inplace,
convert_BGR30_to_A2RGB30_inplace,
0, // self
convert_passthrough_inplace<QImage::Format_A2RGB30_Premultiplied>,
@@ -3345,7 +3279,7 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma
convert_A2RGB30_PM_to_ARGB_inplace<PixelOrderRGB, true>,
0,
convert_A2RGB30_PM_to_RGB30_inplace<true>,
- convert_BGR30_to_RGB30_inplace,
+ convert_rgbswap_generic_inplace,
convert_A2RGB30_PM_to_RGB30_inplace<false>,
0, // self
0, 0,
@@ -3427,7 +3361,7 @@ InPlace_Image_Converter qimage_inplace_converter_map[QImage::NImageFormats][QIma
}, // Format_Grayscale16
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- convert_RGB888_to_BGR888_inplace,
+ convert_rgbswap_generic_inplace,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}, // Format_BGR888
};
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp
index 6a0763e696..dff24b449a 100644
--- a/src/gui/image/qimagereader.cpp
+++ b/src/gui/image/qimagereader.cpp
@@ -150,7 +150,7 @@
// factory loader
#include <qcoreapplication.h>
#include <private/qfactoryloader_p.h>
-#include <QMutexLocker>
+#include <QtCore/private/qlocking_p.h>
// for qt_getImageText
#include <private/qimage_p.h>
@@ -186,8 +186,8 @@ static QImageIOHandler *createReadHandlerHelper(QIODevice *device,
QByteArray suffix;
#ifndef QT_NO_IMAGEFORMATPLUGIN
- static QMutex mutex;
- QMutexLocker locker(&mutex);
+ static QBasicMutex mutex;
+ const auto locker = qt_scoped_lock(mutex);
typedef QMultiMap<int, QString> PluginKeyMap;
diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp
index 8548f1857e..978a07b9f9 100644
--- a/src/gui/image/qpicture.cpp
+++ b/src/gui/image/qpicture.cpp
@@ -57,6 +57,7 @@
#include "qregexp.h"
#include "qregion.h"
#include "qdebug.h"
+#include <QtCore/private/qlocking_p.h>
#include <algorithm>
@@ -1427,7 +1428,7 @@ void qt_init_picture_plugins()
typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator;
static QBasicMutex mutex;
- QMutexLocker locker(&mutex);
+ const auto locker = qt_scoped_lock(mutex);
static QFactoryLoader loader(QPictureFormatInterface_iid,
QStringLiteral("/pictureformats"));
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index cb7a0b8ac9..a3ef3b2314 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -58,6 +58,7 @@
#include <QtCore/private/qabstracteventdispatcher_p.h>
#include <QtCore/qmutex.h>
#include <QtCore/private/qthread_p.h>
+#include <QtCore/private/qlocking_p.h>
#include <QtCore/qdir.h>
#include <QtCore/qlibraryinfo.h>
#include <QtCore/qnumeric.h>
@@ -2762,7 +2763,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
QWindow *window = e->window.data();
typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints;
QHash<QWindow *, StatesAndTouchPoints> windowsNeedingEvents;
- bool stationaryTouchPointChangedVelocity = false;
+ bool stationaryTouchPointChangedProperty = false;
for (int i = 0; i < e->points.count(); ++i) {
QTouchEvent::TouchPoint touchPoint = e->points.at(i);
@@ -2842,7 +2843,11 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
if (touchPoint.state() == Qt::TouchPointStationary) {
if (touchInfo.touchPoint.velocity() != touchPoint.velocity()) {
touchInfo.touchPoint.setVelocity(touchPoint.velocity());
- stationaryTouchPointChangedVelocity = true;
+ stationaryTouchPointChangedProperty = true;
+ }
+ if (!qFuzzyCompare(touchInfo.touchPoint.pressure(), touchPoint.pressure())) {
+ touchInfo.touchPoint.setPressure(touchPoint.pressure());
+ stationaryTouchPointChangedProperty = true;
}
} else {
touchInfo.touchPoint = touchPoint;
@@ -2883,7 +2888,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
break;
case Qt::TouchPointStationary:
// don't send the event if nothing changed
- if (!stationaryTouchPointChangedVelocity)
+ if (!stationaryTouchPointChangedProperty)
continue;
Q_FALLTHROUGH();
default:
@@ -3301,7 +3306,7 @@ void QGuiApplicationPrivate::applyWindowGeometrySpecificationTo(QWindow *window)
QFont QGuiApplication::font()
{
Q_ASSERT_X(QGuiApplicationPrivate::self, "QGuiApplication::font()", "no QGuiApplication instance");
- QMutexLocker locker(&applicationFontMutex);
+ const auto locker = qt_scoped_lock(applicationFontMutex);
initFontUnlocked();
return *QGuiApplicationPrivate::app_font;
}
@@ -3313,7 +3318,7 @@ QFont QGuiApplication::font()
*/
void QGuiApplication::setFont(const QFont &font)
{
- QMutexLocker locker(&applicationFontMutex);
+ auto locker = qt_unique_lock(applicationFontMutex);
const bool emitChange = !QGuiApplicationPrivate::app_font
|| (*QGuiApplicationPrivate::app_font != font);
if (!QGuiApplicationPrivate::app_font)
@@ -3501,7 +3506,7 @@ Qt::ApplicationState QGuiApplication::applicationState()
\since 5.14
Sets the high-DPI scale factor rounding policy for the application. The
- policy decides how non-integer scale factors (such as Windows 150%) are
+ \a policy decides how non-integer scale factors (such as Windows 150%) are
handled, for applications that have AA_EnableHighDpiScaling enabled.
The two principal options are whether fractional scale factors should
@@ -4077,7 +4082,7 @@ void QGuiApplicationPrivate::notifyThemeChanged()
sendApplicationPaletteChange();
}
if (!(applicationResourceFlags & ApplicationFontExplicitlySet)) {
- QMutexLocker locker(&applicationFontMutex);
+ const auto locker = qt_scoped_lock(applicationFontMutex);
clearFontUnlocked();
initFontUnlocked();
}
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp
index ec4feeba8b..ee54fd4fa1 100644
--- a/src/gui/kernel/qhighdpiscaling.cpp
+++ b/src/gui/kernel/qhighdpiscaling.cpp
@@ -538,7 +538,7 @@ void QHighDpiScaling::updateHighDpiScaling()
++i;
}
}
- m_active = m_globalScalingActive || m_usePixelDensity;
+ m_active = m_globalScalingActive || m_screenFactorSet || m_usePixelDensity;
}
/*
@@ -680,8 +680,11 @@ QDpi QHighDpiScaling::logicalDpi(const QScreen *screen)
if (!screen || !screen->handle())
return QDpi(96, 96);
- if (!m_usePixelDensity)
- return QPlatformScreen::overrideDpi(screen->handle()->logicalDpi());
+ if (!m_usePixelDensity) {
+ const qreal screenScaleFactor = screenSubfactor(screen->handle());
+ const QDpi dpi = QPlatformScreen::overrideDpi(screen->handle()->logicalDpi());
+ return QDpi{ dpi.first / screenScaleFactor, dpi.second / screenScaleFactor };
+ }
const qreal scaleFactor = rawScaleFactor(screen->handle());
const qreal roundedScaleFactor = roundScaleFactor(scaleFactor);
diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp
index 6f51fe3095..638eb1d12f 100644
--- a/src/gui/kernel/qopenglcontext.cpp
+++ b/src/gui/kernel/qopenglcontext.cpp
@@ -45,6 +45,7 @@
#include <QtCore/QThreadStorage>
#include <QtCore/QThread>
+#include <QtCore/private/qlocking_p.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/private/qopengl_p.h>
@@ -1442,7 +1443,7 @@ QOpenGLContextGroup *QOpenGLContextGroup::currentContextGroup()
void QOpenGLContextGroupPrivate::addContext(QOpenGLContext *ctx)
{
- QMutexLocker locker(&m_mutex);
+ const auto locker = qt_scoped_lock(m_mutex);
m_refs.ref();
m_shares << ctx;
}
@@ -1454,7 +1455,7 @@ void QOpenGLContextGroupPrivate::removeContext(QOpenGLContext *ctx)
bool deleteObject = false;
{
- QMutexLocker locker(&m_mutex);
+ const auto locker = qt_scoped_lock(m_mutex);
m_shares.removeOne(ctx);
if (ctx == m_context && !m_shares.isEmpty())
@@ -1502,7 +1503,7 @@ void QOpenGLContextGroupPrivate::cleanup()
void QOpenGLContextGroupPrivate::deletePendingResources(QOpenGLContext *ctx)
{
- QMutexLocker locker(&m_mutex);
+ const auto locker = qt_scoped_lock(m_mutex);
const QList<QOpenGLSharedResource *> pending = m_pendingDeletion;
m_pendingDeletion.clear();
@@ -1543,7 +1544,7 @@ void QOpenGLContextGroupPrivate::deletePendingResources(QOpenGLContext *ctx)
QOpenGLSharedResource::QOpenGLSharedResource(QOpenGLContextGroup *group)
: m_group(group)
{
- QMutexLocker locker(&m_group->d_func()->m_mutex);
+ const auto locker = qt_scoped_lock(m_group->d_func()->m_mutex);
m_group->d_func()->m_sharedResources << this;
}
@@ -1559,7 +1560,7 @@ void QOpenGLSharedResource::free()
return;
}
- QMutexLocker locker(&m_group->d_func()->m_mutex);
+ const auto locker = qt_scoped_lock(m_group->d_func()->m_mutex);
m_group->d_func()->m_sharedResources.removeOne(this);
m_group->d_func()->m_pendingDeletion << this;
diff --git a/src/gui/kernel/qtouchdevice.cpp b/src/gui/kernel/qtouchdevice.cpp
index ea187f54aa..8293fddc59 100644
--- a/src/gui/kernel/qtouchdevice.cpp
+++ b/src/gui/kernel/qtouchdevice.cpp
@@ -228,7 +228,7 @@ TouchDevices::TouchDevices()
*/
QList<const QTouchDevice *> QTouchDevice::devices()
{
- QMutexLocker lock(&devicesMutex);
+ const auto locker = qt_scoped_lock(devicesMutex);
return deviceList->list;
}
@@ -237,13 +237,13 @@ QList<const QTouchDevice *> QTouchDevice::devices()
*/
bool QTouchDevicePrivate::isRegistered(const QTouchDevice *dev)
{
- QMutexLocker locker(&devicesMutex);
+ const auto locker = qt_scoped_lock(devicesMutex);
return deviceList->list.contains(dev);
}
const QTouchDevice *QTouchDevicePrivate::deviceById(quint8 id)
{
- QMutexLocker locker(&devicesMutex);
+ const auto locker = qt_scoped_lock(devicesMutex);
for (const QTouchDevice *dev : qAsConst(deviceList->list))
if (QTouchDevicePrivate::get(const_cast<QTouchDevice *>(dev))->id == id)
return dev;
@@ -255,7 +255,7 @@ const QTouchDevice *QTouchDevicePrivate::deviceById(quint8 id)
*/
void QTouchDevicePrivate::registerDevice(const QTouchDevice *dev)
{
- QMutexLocker lock(&devicesMutex);
+ const auto locker = qt_scoped_lock(devicesMutex);
deviceList->list.append(dev);
}
@@ -264,7 +264,7 @@ void QTouchDevicePrivate::registerDevice(const QTouchDevice *dev)
*/
void QTouchDevicePrivate::unregisterDevice(const QTouchDevice *dev)
{
- QMutexLocker lock(&devicesMutex);
+ const auto locker = qt_scoped_lock(devicesMutex);
deviceList->list.removeOne(dev);
}
diff --git a/src/gui/painting/qcolormatrix_p.h b/src/gui/painting/qcolormatrix_p.h
index 66db95df7e..edb2d32258 100644
--- a/src/gui/painting/qcolormatrix_p.h
+++ b/src/gui/painting/qcolormatrix_p.h
@@ -62,17 +62,16 @@ class QColorVector
{
public:
QColorVector() = default;
- Q_DECL_CONSTEXPR QColorVector(float x, float y, float z) : x(x), y(y), z(z), _unused(0.0f) { }
+ Q_DECL_CONSTEXPR QColorVector(float x, float y, float z) : x(x), y(y), z(z) { }
explicit Q_DECL_CONSTEXPR QColorVector(const QPointF &chr) // from XY chromaticity
: x(chr.x() / chr.y())
, y(1.0f)
, z((1.0 - chr.x() - chr.y()) / chr.y())
- , _unused(0.0f)
{ }
- float x; // X, x or red
- float y; // Y, y or green
- float z; // Z, Y or blue
- float _unused;
+ float x = 0.0f; // X, x or red
+ float y = 0.0f; // Y, y or green
+ float z = 0.0f; // Z, Y or blue
+ float _unused = 0.0f;
friend inline bool operator==(const QColorVector &v1, const QColorVector &v2);
friend inline bool operator!=(const QColorVector &v1, const QColorVector &v2);
@@ -81,7 +80,6 @@ public:
return !x && !y && !z;
}
- static Q_DECL_CONSTEXPR QColorVector null() { return QColorVector(0.0f, 0.0f, 0.0f); }
static bool isValidChromaticity(const QPointF &chr)
{
if (chr.x() < qreal(0.0) || chr.x() > qreal(1.0))
@@ -187,10 +185,6 @@ public:
{ r.z, g.z, b.z } };
}
- static QColorMatrix null()
- {
- return { QColorVector::null(), QColorVector::null(), QColorVector::null() };
- }
static QColorMatrix identity()
{
return { { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } };
@@ -226,12 +220,6 @@ public:
{ 0.1351922452f, 0.7118769884f, 0.0000000000f },
{ 0.0313525312f, 0.0000856627f, 0.8251883388f } };
}
- static QColorMatrix toXyzFromBt2020()
- {
- return QColorMatrix { { 0.6506130099f, 0.2695676684f, -0.0018652577f },
- { 0.1865101457f, 0.6840794086f, 0.0172256753f },
- { 0.1270887405f, 0.0463530831f, 0.8098278046f } };
- }
};
inline bool operator==(const QColorMatrix &m1, const QColorMatrix &m2)
diff --git a/src/gui/painting/qcolorspace.cpp b/src/gui/painting/qcolorspace.cpp
index 39ab358879..937bb505c9 100644
--- a/src/gui/painting/qcolorspace.cpp
+++ b/src/gui/painting/qcolorspace.cpp
@@ -70,12 +70,6 @@ QColorSpacePrimaries::QColorSpacePrimaries(QColorSpace::Primaries primaries)
bluePoint = QPointF(0.150, 0.060);
whitePoint = QColorVector::D65Chromaticity();
break;
- case QColorSpace::Primaries::Bt2020:
- redPoint = QPointF(0.708, 0.292);
- greenPoint = QPointF(0.190, 0.797);
- bluePoint = QPointF(0.131, 0.046);
- whitePoint = QColorVector::D65Chromaticity();
- break;
case QColorSpace::Primaries::AdobeRgb:
redPoint = QPointF(0.640, 0.330);
greenPoint = QPointF(0.210, 0.710);
@@ -152,17 +146,11 @@ QColorMatrix QColorSpacePrimaries::toXyzMatrix() const
}
QColorSpacePrivate::QColorSpacePrivate()
- : primaries(QColorSpace::Primaries::Custom)
- , transferFunction(QColorSpace::TransferFunction::Custom)
- , gamma(0.0f)
- , whitePoint(QColorVector::null())
- , toXyz(QColorMatrix::null())
{
}
QColorSpacePrivate::QColorSpacePrivate(QColorSpace::NamedColorSpace namedColorSpace)
: namedColorSpace(namedColorSpace)
- , gamma(0.0f)
{
switch (namedColorSpace) {
case QColorSpace::SRgb:
@@ -191,11 +179,6 @@ QColorSpacePrivate::QColorSpacePrivate(QColorSpace::NamedColorSpace namedColorSp
transferFunction = QColorSpace::TransferFunction::ProPhotoRgb;
description = QStringLiteral("ProPhoto RGB");
break;
- case QColorSpace::Bt2020:
- primaries = QColorSpace::Primaries::Bt2020;
- transferFunction = QColorSpace::TransferFunction::Bt2020;
- description = QStringLiteral("BT.2020");
- break;
default:
Q_UNREACHABLE();
}
@@ -277,14 +260,6 @@ void QColorSpacePrivate::identifyColorSpace()
}
}
break;
- case QColorSpace::Primaries::Bt2020:
- if (transferFunction == QColorSpace::TransferFunction::Bt2020) {
- namedColorSpace = QColorSpace::Bt2020;
- if (description.isEmpty())
- description = QStringLiteral("BT.2020");
- return;
- }
- break;
default:
break;
}
@@ -301,7 +276,7 @@ void QColorSpacePrivate::initialize()
void QColorSpacePrivate::setToXyzMatrix()
{
if (primaries == QColorSpace::Primaries::Custom) {
- toXyz = QColorMatrix::null();
+ toXyz = QColorMatrix();
whitePoint = QColorVector::D50();
return;
}
@@ -335,12 +310,6 @@ void QColorSpacePrivate::setTransferFunction()
if (qFuzzyIsNull(gamma))
gamma = 1.8f;
break;
- case QColorSpace::TransferFunction::Bt2020:
- trc[0].m_type = QColorTrc::Type::Function;
- trc[0].m_fun = QColorTransferFunction::fromBt2020();
- if (qFuzzyIsNull(gamma))
- gamma = 1.961f;
- break;
case QColorSpace::TransferFunction::Custom:
break;
default:
@@ -415,8 +384,6 @@ QColorTransform QColorSpacePrivate::transformationToColorSpace(const QColorSpace
\l{http://www.color.org/chardata/rgb/DCIP3.xalter}{ICC registration of DCI-P3}
\value ProPhotoRgb The Pro Photo RGB color space, also known as ROMM RGB is a very wide gamut color space.
\l{http://www.color.org/chardata/rgb/rommrgb.xalter}{ICC registration of ROMM RGB}
- \value Bt2020 BT.2020 also known as Rec.2020 is the color space of HDR TVs.
- \l{http://www.color.org/chardata/rgb/BT2020.xalter}{ICC registration of BT.2020}
*/
/*!
@@ -429,7 +396,6 @@ QColorTransform QColorSpacePrivate::transformationToColorSpace(const QColorSpace
\value AdobeRgb The Adobe RGB primaries
\value DciP3D65 The DCI-P3 primaries with the D65 whitepoint
\value ProPhotoRgb The ProPhoto RGB primaries with the D50 whitepoint
- \value Bt2020 The BT.2020 primaries
*/
/*!
@@ -442,7 +408,6 @@ QColorTransform QColorSpacePrivate::transformationToColorSpace(const QColorSpace
\value Gamma A transfer function that is a real gamma curve based on the value of gamma()
\value SRgb The sRGB transfer function, composed of linear and gamma parts
\value ProPhotoRgb The ProPhoto RGB transfer function, composed of linear and gamma parts
- \value Bt2020 The BT.2020 transfer function, composed of linear and gamma parts
*/
/*!
@@ -457,7 +422,7 @@ QColorSpace::QColorSpace()
*/
QColorSpace::QColorSpace(NamedColorSpace namedColorSpace)
{
- static QColorSpacePrivate *predefinedColorspacePrivates[QColorSpace::Bt2020 + 1];
+ static QColorSpacePrivate *predefinedColorspacePrivates[QColorSpace::ProPhotoRgb + 1];
if (!predefinedColorspacePrivates[namedColorSpace]) {
predefinedColorspacePrivates[namedColorSpace] = new QColorSpacePrivate(namedColorSpace);
predefinedColorspacePrivates[namedColorSpace]->ref.ref();
diff --git a/src/gui/painting/qcolorspace.h b/src/gui/painting/qcolorspace.h
index 11987b9a37..e6bc62d58a 100644
--- a/src/gui/painting/qcolorspace.h
+++ b/src/gui/painting/qcolorspace.h
@@ -59,8 +59,7 @@ public:
SRgbLinear,
AdobeRgb,
DisplayP3,
- ProPhotoRgb,
- Bt2020,
+ ProPhotoRgb
};
Q_ENUM(NamedColorSpace)
enum class Primaries {
@@ -68,8 +67,7 @@ public:
SRgb,
AdobeRgb,
DciP3D65,
- ProPhotoRgb,
- Bt2020,
+ ProPhotoRgb
};
Q_ENUM(Primaries)
enum class TransferFunction {
@@ -77,8 +75,7 @@ public:
Linear,
Gamma,
SRgb,
- ProPhotoRgb,
- Bt2020,
+ ProPhotoRgb
};
Q_ENUM(TransferFunction)
diff --git a/src/gui/painting/qcolorspace_p.h b/src/gui/painting/qcolorspace_p.h
index c06681df6b..e7add19ed3 100644
--- a/src/gui/painting/qcolorspace_p.h
+++ b/src/gui/painting/qcolorspace_p.h
@@ -124,9 +124,9 @@ public:
static constexpr QColorSpace::NamedColorSpace Unknown = QColorSpace::NamedColorSpace(0);
QColorSpace::NamedColorSpace namedColorSpace = Unknown;
- QColorSpace::Primaries primaries;
- QColorSpace::TransferFunction transferFunction;
- float gamma;
+ QColorSpace::Primaries primaries = QColorSpace::Primaries::Custom;
+ QColorSpace::TransferFunction transferFunction = QColorSpace::TransferFunction::Custom;
+ float gamma = 0.0f;
QColorVector whitePoint;
QColorTrc trc[3];
diff --git a/src/gui/painting/qcolortransferfunction_p.h b/src/gui/painting/qcolortransferfunction_p.h
index fd7cfa2b2b..0575dbd888 100644
--- a/src/gui/painting/qcolortransferfunction_p.h
+++ b/src/gui/painting/qcolortransferfunction_p.h
@@ -130,10 +130,6 @@ public:
{
return QColorTransferFunction(1.0f / 1.055f, 0.055f / 1.055f, 1.0f / 12.92f, 0.04045f, 0.0f, 0.0f, 2.4f);
}
- static QColorTransferFunction fromBt2020()
- {
- return QColorTransferFunction(1.0f / 1.0993f, 0.0993f / 1.0993f, 1.0f / 4.5f, 0.08145f, 0.0f, 0.0f, 2.2f);
- }
static QColorTransferFunction fromProPhotoRgb()
{
return QColorTransferFunction(1.0f, 0.0f, 1.0f / 16.0f, 16.0f / 512.0f, 0.0f, 0.0f, 1.8f);
diff --git a/src/gui/painting/qcolortransform.cpp b/src/gui/painting/qcolortransform.cpp
index 53fd1dfbaa..10ccefed74 100644
--- a/src/gui/painting/qcolortransform.cpp
+++ b/src/gui/painting/qcolortransform.cpp
@@ -612,6 +612,15 @@ static void storeOpaque(QRgba64 *dst, const QRgba64 *src, const QColorVector *bu
static constexpr qsizetype WorkBlockSize = 256;
+template <typename T, int Count = 1>
+class QUninitialized
+{
+public:
+ operator T*() { return reinterpret_cast<T *>(this); }
+private:
+ alignas(T) char data[sizeof(T) * Count];
+};
+
template<typename T>
void QColorTransformPrivate::apply(T *dst, const T *src, qsizetype count, TransformFlags flags) const
{
@@ -623,7 +632,8 @@ void QColorTransformPrivate::apply(T *dst, const T *src, qsizetype count, Transf
bool doApplyMatrix = (colorMatrix != QColorMatrix::identity());
- QColorVector buffer[WorkBlockSize];
+ QUninitialized<QColorVector, WorkBlockSize> buffer;
+
qsizetype i = 0;
while (i < count) {
const qsizetype len = qMin(count - i, WorkBlockSize);
diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp
index c17bf2ddfd..edb363ac69 100644
--- a/src/gui/painting/qdrawhelper.cpp
+++ b/src/gui/painting/qdrawhelper.cpp
@@ -669,8 +669,7 @@ static void QT_FASTCALL rbSwap_rgb30(uchar *d, const uchar *s, int count)
{
const uint *src = reinterpret_cast<const uint *>(s);
uint *dest = reinterpret_cast<uint *>(d);
- for (int i = 0; i < count; ++i)
- dest[i] = qRgbSwapRgb30(src[i]);
+ UNALIASED_CONVERSION_LOOP(dest, src, count, qRgbSwapRgb30);
}
template<QImage::Format Format> Q_DECL_CONSTEXPR static inline QPixelLayout pixelLayoutRGB()
@@ -6774,6 +6773,9 @@ static void qInitDrawhelperFunctions()
qBlendFunctions[QImage::Format_RGBX8888][QImage::Format_RGBA8888_Premultiplied] = qt_blend_argb32_on_argb32_ssse3;
qBlendFunctions[QImage::Format_RGBA8888_Premultiplied][QImage::Format_RGBA8888_Premultiplied] = qt_blend_argb32_on_argb32_ssse3;
sourceFetchUntransformed[QImage::Format_RGB888] = qt_fetchUntransformed_888_ssse3;
+ extern void QT_FASTCALL rbSwap_888_ssse3(uchar *dst, const uchar *src, int count);
+ qPixelLayouts[QImage::Format_RGB888].rbSwap = rbSwap_888_ssse3;
+ qPixelLayouts[QImage::Format_BGR888].rbSwap = rbSwap_888_ssse3;
}
#endif // SSSE3
diff --git a/src/gui/painting/qdrawhelper_ssse3.cpp b/src/gui/painting/qdrawhelper_ssse3.cpp
index 35d61c3e6c..14d7047bb6 100644
--- a/src/gui/painting/qdrawhelper_ssse3.cpp
+++ b/src/gui/painting/qdrawhelper_ssse3.cpp
@@ -40,7 +40,7 @@
#include <private/qdrawhelper_x86_p.h>
-#ifdef QT_COMPILER_SUPPORTS_SSSE3
+#if defined(QT_COMPILER_SUPPORTS_SSSE3)
#include <private/qdrawingprimitive_sse2_p.h>
@@ -254,6 +254,49 @@ void qt_memfill24_ssse3(quint24 *dest, quint24 color, qsizetype count)
}
}
+void QT_FASTCALL rbSwap_888_ssse3(uchar *dst, const uchar *src, int count)
+{
+ int i = 0;
+
+ const static __m128i shuffleMask1 = _mm_setr_epi8(2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, 9, 14, 13, 12, /*!!*/15);
+ const static __m128i shuffleMask2 = _mm_setr_epi8(0, /*!!*/1, 4, 3, 2, 7, 6, 5, 10, 9, 8, 13, 12, 11, /*!!*/14, 15);
+ const static __m128i shuffleMask3 = _mm_setr_epi8(/*!!*/0, 3, 2, 1, 6, 5, 4, 9, 8, 7, 12, 11, 10, 15, 14, 13);
+
+ for (; i + 15 < count; i += 16) {
+ __m128i s1 = _mm_loadu_si128((const __m128i *)src);
+ __m128i s2 = _mm_loadu_si128((const __m128i *)(src + 16));
+ __m128i s3 = _mm_loadu_si128((const __m128i *)(src + 32));
+ s1 = _mm_shuffle_epi8(s1, shuffleMask1);
+ s2 = _mm_shuffle_epi8(s2, shuffleMask2);
+ s3 = _mm_shuffle_epi8(s3, shuffleMask3);
+ _mm_storeu_si128((__m128i *)dst, s1);
+ _mm_storeu_si128((__m128i *)(dst + 16), s2);
+ _mm_storeu_si128((__m128i *)(dst + 32), s3);
+
+ // Now fix the last four misplaced values
+ std::swap(dst[15], dst[17]);
+ std::swap(dst[30], dst[32]);
+
+ src += 48;
+ dst += 48;
+ }
+
+ if (src != dst) {
+ SIMD_EPILOGUE(i, count, 15) {
+ dst[0] = src[2];
+ dst[1] = src[1];
+ dst[2] = src[0];
+ dst += 3;
+ src += 3;
+ }
+ } else {
+ SIMD_EPILOGUE(i, count, 15) {
+ std::swap(dst[0], dst[2]);
+ dst += 3;
+ }
+ }
+}
+
QT_END_NAMESPACE
#endif // QT_COMPILER_SUPPORTS_SSSE3
diff --git a/src/gui/painting/qicc.cpp b/src/gui/painting/qicc.cpp
index 45b64de960..18f212f8e9 100644
--- a/src/gui/painting/qicc.cpp
+++ b/src/gui/painting/qicc.cpp
@@ -687,9 +687,6 @@ bool fromIccProfile(const QByteArray &data, QColorSpace *colorSpace)
} else if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromDciP3D65()) {
qCDebug(lcIcc) << "fromIccProfile: DCI-P3 D65 primaries detected";
colorspaceDPtr->primaries = QColorSpace::Primaries::DciP3D65;
- } else if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromBt2020()) {
- qCDebug(lcIcc) << "fromIccProfile: BT.2020 primaries detected";
- colorspaceDPtr->primaries = QColorSpace::Primaries::Bt2020;
}
if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromProPhotoRgb()) {
qCDebug(lcIcc) << "fromIccProfile: ProPhoto RGB primaries detected";
diff --git a/src/gui/painting/qplatformbackingstore.cpp b/src/gui/painting/qplatformbackingstore.cpp
index c71d82546a..601dc97be1 100644
--- a/src/gui/painting/qplatformbackingstore.cpp
+++ b/src/gui/painting/qplatformbackingstore.cpp
@@ -446,14 +446,22 @@ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion &regi
d_ptr->blitter->setRedBlueSwizzle(false);
}
- // There is no way to tell if the OpenGL-rendered content is premultiplied or not.
- // For compatibility, assume that it is not, and use normal alpha blend always.
- if (d_ptr->premultiplied)
- funcs->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
-
// Textures for renderToTexture widgets that have WA_AlwaysStackOnTop set.
+ bool blendIsPremultiplied = d_ptr->premultiplied;
for (int i = 0; i < textures->count(); ++i) {
- if (textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop))
+ const QPlatformTextureList::Flags flags = textures->flags(i);
+ if (flags.testFlag(QPlatformTextureList::NeedsPremultipliedAlphaBlending)) {
+ if (!blendIsPremultiplied) {
+ funcs->glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
+ blendIsPremultiplied = true;
+ }
+ } else {
+ if (blendIsPremultiplied) {
+ funcs->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
+ blendIsPremultiplied = false;
+ }
+ }
+ if (flags.testFlag(QPlatformTextureList::StacksOnTop))
blitTextureForWidget(textures, i, window, deviceWindowRect, d_ptr->blitter, offset, canUseSrgb);
}
diff --git a/src/gui/painting/qplatformbackingstore.h b/src/gui/painting/qplatformbackingstore.h
index 414d2bf0de..4f08b0092f 100644
--- a/src/gui/painting/qplatformbackingstore.h
+++ b/src/gui/painting/qplatformbackingstore.h
@@ -81,7 +81,8 @@ class Q_GUI_EXPORT QPlatformTextureList : public QObject
public:
enum Flag {
StacksOnTop = 0x01,
- TextureIsSrgb = 0x02
+ TextureIsSrgb = 0x02,
+ NeedsPremultipliedAlphaBlending = 0x04
};
Q_DECLARE_FLAGS(Flags, Flag)
diff --git a/src/gui/rhi/cs_tdr.h b/src/gui/rhi/cs_tdr.h
new file mode 100644
index 0000000000..f80cb3a498
--- /dev/null
+++ b/src/gui/rhi/cs_tdr.h
@@ -0,0 +1,209 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Gui module
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qglobal.h>
+
+#ifdef Q_OS_WIN
+
+#include <qt_windows.h>
+
+#if 0
+//
+// Generated by Microsoft (R) HLSL Shader Compiler 10.1
+//
+//
+// Buffer Definitions:
+//
+// cbuffer ConstantBuffer
+// {
+//
+// uint zero; // Offset: 0 Size: 4
+//
+// }
+//
+//
+// Resource Bindings:
+//
+// Name Type Format Dim HLSL Bind Count
+// ------------------------------ ---------- ------- ----------- -------------- ------
+// uav UAV uint buf u0 1
+// ConstantBuffer cbuffer NA NA cb0 1
+//
+//
+//
+// Input signature:
+//
+// Name Index Mask Register SysValue Format Used
+// -------------------- ----- ------ -------- -------- ------- ------
+// no Input
+//
+// Output signature:
+//
+// Name Index Mask Register SysValue Format Used
+// -------------------- ----- ------ -------- -------- ------- ------
+// no Output
+cs_5_0
+dcl_globalFlags refactoringAllowed
+dcl_constantbuffer CB0[1], immediateIndexed
+dcl_uav_typed_buffer (uint,uint,uint,uint) u0
+dcl_input vThreadID.x
+dcl_thread_group 256, 1, 1
+loop
+ breakc_nz cb0[0].x
+ store_uav_typed u0.xyzw, vThreadID.xxxx, cb0[0].xxxx
+endloop
+ret
+// Approximately 5 instruction slots used
+#endif
+
+const BYTE g_killDeviceByTimingOut[] =
+{
+ 68, 88, 66, 67, 217, 62,
+ 220, 38, 136, 51, 86, 245,
+ 161, 96, 18, 35, 141, 17,
+ 26, 13, 1, 0, 0, 0,
+ 164, 2, 0, 0, 5, 0,
+ 0, 0, 52, 0, 0, 0,
+ 100, 1, 0, 0, 116, 1,
+ 0, 0, 132, 1, 0, 0,
+ 8, 2, 0, 0, 82, 68,
+ 69, 70, 40, 1, 0, 0,
+ 1, 0, 0, 0, 144, 0,
+ 0, 0, 2, 0, 0, 0,
+ 60, 0, 0, 0, 0, 5,
+ 83, 67, 0, 1, 0, 0,
+ 0, 1, 0, 0, 82, 68,
+ 49, 49, 60, 0, 0, 0,
+ 24, 0, 0, 0, 32, 0,
+ 0, 0, 40, 0, 0, 0,
+ 36, 0, 0, 0, 12, 0,
+ 0, 0, 0, 0, 0, 0,
+ 124, 0, 0, 0, 4, 0,
+ 0, 0, 4, 0, 0, 0,
+ 1, 0, 0, 0, 255, 255,
+ 255, 255, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0,
+ 0, 0, 128, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 1, 0, 0, 0,
+ 0, 0, 0, 0, 117, 97,
+ 118, 0, 67, 111, 110, 115,
+ 116, 97, 110, 116, 66, 117,
+ 102, 102, 101, 114, 0, 171,
+ 128, 0, 0, 0, 1, 0,
+ 0, 0, 168, 0, 0, 0,
+ 16, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 208, 0, 0, 0, 0, 0,
+ 0, 0, 4, 0, 0, 0,
+ 2, 0, 0, 0, 220, 0,
+ 0, 0, 0, 0, 0, 0,
+ 255, 255, 255, 255, 0, 0,
+ 0, 0, 255, 255, 255, 255,
+ 0, 0, 0, 0, 122, 101,
+ 114, 111, 0, 100, 119, 111,
+ 114, 100, 0, 171, 0, 0,
+ 19, 0, 1, 0, 1, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 213, 0, 0, 0, 77, 105,
+ 99, 114, 111, 115, 111, 102,
+ 116, 32, 40, 82, 41, 32,
+ 72, 76, 83, 76, 32, 83,
+ 104, 97, 100, 101, 114, 32,
+ 67, 111, 109, 112, 105, 108,
+ 101, 114, 32, 49, 48, 46,
+ 49, 0, 73, 83, 71, 78,
+ 8, 0, 0, 0, 0, 0,
+ 0, 0, 8, 0, 0, 0,
+ 79, 83, 71, 78, 8, 0,
+ 0, 0, 0, 0, 0, 0,
+ 8, 0, 0, 0, 83, 72,
+ 69, 88, 124, 0, 0, 0,
+ 80, 0, 5, 0, 31, 0,
+ 0, 0, 106, 8, 0, 1,
+ 89, 0, 0, 4, 70, 142,
+ 32, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 156, 8,
+ 0, 4, 0, 224, 17, 0,
+ 0, 0, 0, 0, 68, 68,
+ 0, 0, 95, 0, 0, 2,
+ 18, 0, 2, 0, 155, 0,
+ 0, 4, 0, 1, 0, 0,
+ 1, 0, 0, 0, 1, 0,
+ 0, 0, 48, 0, 0, 1,
+ 3, 0, 4, 4, 10, 128,
+ 32, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 164, 0,
+ 0, 7, 242, 224, 17, 0,
+ 0, 0, 0, 0, 6, 0,
+ 2, 0, 6, 128, 32, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 22, 0, 0, 1,
+ 62, 0, 0, 1, 83, 84,
+ 65, 84, 148, 0, 0, 0,
+ 5, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 2, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0
+};
+
+#endif // Q_OS_WIN
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp
index 4414b61d55..858be0159b 100644
--- a/src/gui/rhi/qrhi.cpp
+++ b/src/gui/rhi/qrhi.cpp
@@ -439,6 +439,18 @@ Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general")
visible in external GPU debugging tools will not be available and functions
like QRhiCommandBuffer::debugMarkBegin() will become a no-op. Avoid
enabling in production builds as it may involve a performance penalty.
+
+ \value PreferSoftwareRenderer Indicates that backends should prefer
+ choosing an adapter or physical device that renders in software on the CPU.
+ For example, with Direct3D there is typically a "Basic Render Driver"
+ adapter available with \c{DXGI_ADAPTER_FLAG_SOFTWARE}. Setting this flag
+ requests the backend to choose that adapter over any other, as long as no
+ specific adapter was forced by other backend-specific means. With Vulkan
+ this maps to preferring physical devices with
+ \c{VK_PHYSICAL_DEVICE_TYPE_CPU}. When not available, or when it is not
+ possible to decide if an adapter/device is software-based, this flag is
+ ignored. It may also be ignored with graphics APIs that have no concept and
+ means of enumerating adapters/devices.
*/
/*!
@@ -455,8 +467,8 @@ Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general")
\value FrameOpDeviceLost The graphics device was lost. This can be
recoverable by attempting to repeat the operation (such as, beginFrame())
- and releasing and reinitializing all objects backed by native graphics
- resources.
+ after releasing and reinitializing all objects backed by native graphics
+ resources. See isDeviceLost().
*/
/*!
@@ -673,7 +685,7 @@ bool operator!=(const QRhiDepthStencilClearValue &a, const QRhiDepthStencilClear
*/
uint qHash(const QRhiDepthStencilClearValue &v, uint seed) Q_DECL_NOTHROW
{
- return seed * (qFloor(v.depthClearValue() * 100) + v.stencilClearValue());
+ return seed * (uint(qFloor(qreal(v.depthClearValue()) * 100)) + v.stencilClearValue());
}
#ifndef QT_NO_DEBUG_STREAM
@@ -768,7 +780,8 @@ bool operator!=(const QRhiViewport &a, const QRhiViewport &b) Q_DECL_NOTHROW
uint qHash(const QRhiViewport &v, uint seed) Q_DECL_NOTHROW
{
const std::array<float, 4> r = v.viewport();
- return seed + r[0] + r[1] + r[2] + r[3] + qFloor(v.minDepth() * 100) + qFloor(v.maxDepth() * 100);
+ return seed + uint(r[0]) + uint(r[1]) + uint(r[2]) + uint(r[3])
+ + uint(qFloor(qreal(v.minDepth()) * 100)) + uint(qFloor(qreal(v.maxDepth()) * 100));
}
#ifndef QT_NO_DEBUG_STREAM
@@ -850,7 +863,7 @@ bool operator!=(const QRhiScissor &a, const QRhiScissor &b) Q_DECL_NOTHROW
uint qHash(const QRhiScissor &v, uint seed) Q_DECL_NOTHROW
{
const std::array<int, 4> r = v.scissor();
- return seed + r[0] + r[1] + r[2] + r[3];
+ return seed + uint(r[0]) + uint(r[1]) + uint(r[2]) + uint(r[3]);
}
#ifndef QT_NO_DEBUG_STREAM
@@ -1136,7 +1149,7 @@ bool operator!=(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribut
*/
uint qHash(const QRhiVertexInputAttribute &v, uint seed) Q_DECL_NOTHROW
{
- return seed + v.binding() + v.location() + v.format() + v.offset();
+ return seed + uint(v.binding()) + uint(v.location()) + uint(v.format()) + v.offset();
}
#ifndef QT_NO_DEBUG_STREAM
@@ -3001,7 +3014,7 @@ bool operator!=(const QRhiShaderResourceBinding &a, const QRhiShaderResourceBind
uint qHash(const QRhiShaderResourceBinding &b, uint seed) Q_DECL_NOTHROW
{
const char *u = reinterpret_cast<const char *>(&b.d->u);
- return seed + b.d->binding + 10 * b.d->stage + 100 * b.d->type
+ return seed + uint(b.d->binding) + 10 * uint(b.d->stage) + 100 * uint(b.d->type)
+ qHash(QByteArray::fromRawData(u, sizeof(b.d->u)), seed);
}
@@ -3457,10 +3470,18 @@ QRhiResource::Type QRhiGraphicsPipeline::resourceType() const
Flag values to describe swapchain properties
\value SurfaceHasPreMulAlpha Indicates that the target surface has
- transparency with premultiplied alpha.
+ transparency with premultiplied alpha. For example, this is what Qt Quick
+ uses when the alpha channel is enabled on the target QWindow, because the
+ scenegraph rendrerer always outputs fragments with alpha multiplied into
+ the red, green, and blue values. To ensure identical behavior across
+ platforms, always set QSurfaceFormat::alphaBufferSize() to a non-zero value
+ on the target QWindow whenever this flag is set on the swapchain.
\value SurfaceHasNonPreMulAlpha Indicates the target surface has
- transparencyt with non-premultiplied alpha.
+ transparency with non-premultiplied alpha. Be aware that this may not be
+ supported on some systems, if the system compositor always expects content
+ with premultiplied alpha. In that case the behavior with this flag set is
+ expected to be equivalent to SurfaceHasPreMulAlpha.
\value sRGB Requests to pick an sRGB format for the swapchain and/or its
render target views, where applicable. Note that this implies that sRGB
@@ -3823,8 +3844,8 @@ void QRhiImplementation::compressedFormatInfo(QRhiTexture::Format format, const
break;
}
- const quint32 wblocks = (size.width() + xdim - 1) / xdim;
- const quint32 hblocks = (size.height() + ydim - 1) / ydim;
+ const quint32 wblocks = uint((size.width() + xdim - 1) / xdim);
+ const quint32 hblocks = uint((size.height() + ydim - 1) / ydim);
if (bpl)
*bpl = wblocks * blockSize;
@@ -3880,9 +3901,9 @@ void QRhiImplementation::textureFormatInfo(QRhiTexture::Format format, const QSi
}
if (bpl)
- *bpl = size.width() * bpc;
+ *bpl = uint(size.width()) * bpc;
if (byteSize)
- *byteSize = size.width() * size.height() * bpc;
+ *byteSize = uint(size.width() * size.height()) * bpc;
}
// Approximate because it excludes subresource alignment or multisampling.
@@ -3892,12 +3913,12 @@ quint32 QRhiImplementation::approxByteSizeForTexture(QRhiTexture::Format format,
quint32 approxSize = 0;
for (int level = 0; level < mipCount; ++level) {
quint32 byteSize = 0;
- const QSize size(qFloor(float(qMax(1, baseSize.width() >> level))),
- qFloor(float(qMax(1, baseSize.height() >> level))));
+ const QSize size(qFloor(qreal(qMax(1, baseSize.width() >> level))),
+ qFloor(qreal(qMax(1, baseSize.height() >> level))));
textureFormatInfo(format, size, nullptr, &byteSize);
approxSize += byteSize;
}
- approxSize *= layerCount;
+ approxSize *= uint(layerCount);
return approxSize;
}
@@ -5001,10 +5022,17 @@ const QRhiNativeHandles *QRhi::nativeHandles()
has to ensure external OpenGL code provided by the application can still
run like it did before with direct usage of OpenGL, as long as the QRhi is
using the OpenGL backend.
+
+ \return false when failed, similarly to QOpenGLContext::makeCurrent(). When
+ the operation failed, isDeviceLost() can be called to determine if there
+ was a loss of context situation. Such a check is equivalent to checking via
+ QOpenGLContext::isValid().
+
+ \sa QOpenGLContext::makeCurrent(), QOpenGLContext::isValid()
*/
-void QRhi::makeThreadLocalNativeContextCurrent()
+bool QRhi::makeThreadLocalNativeContextCurrent()
{
- d->makeThreadLocalNativeContextCurrent();
+ return d->makeThreadLocalNativeContextCurrent();
}
/*!
@@ -5020,6 +5048,70 @@ QRhiProfiler *QRhi::profiler()
}
/*!
+ Attempts to release resources in the backend's caches. This can include both
+ CPU and GPU resources. Only memory and resources that can be recreated
+ automatically are in scope. As an example, if the backend's
+ QRhiGraphicsPipeline implementation maintains a cache of shader compilation
+ results, calling this function leads to emptying that cache, thus
+ potentially freeing up memory and graphics resources.
+
+ Calling this function makes sense in resource constrained environments,
+ where at a certain point there is a need to ensure minimal resource usage,
+ at the expense of performance.
+ */
+void QRhi::releaseCachedResources()
+{
+ d->releaseCachedResources();
+}
+
+/*!
+ \return true if the graphics device was lost.
+
+ The loss of the device is typically detected in beginFrame(), endFrame() or
+ QRhiSwapChain::buildOrResize(), depending on the backend and the underlying
+ native APIs. The most common is endFrame() because that is where presenting
+ happens. With some backends QRhiSwapChain::buildOrResize() can also fail
+ due to a device loss. Therefore this function is provided as a generic way
+ to check if a device loss was detected by a previous operation.
+
+ When the device is lost, no further operations should be done via the QRhi.
+ Rather, all QRhi resources should be released, followed by destroying the
+ QRhi. A new QRhi can then be attempted to be created. If successful, all
+ graphics resources must be reinitialized. If not, try again later,
+ repeatedly.
+
+ While simple applications may decide to not care about device loss,
+ on the commonly used desktop platforms a device loss can happen
+ due to a variety of reasons, including physically disconnecting the
+ graphics adapter, disabling the device or driver, uninstalling or upgrading
+ the graphics driver, or due to errors that lead to a graphics device reset.
+ Some of these can happen under perfectly normal circumstances as well, for
+ example the upgrade of the graphics driver to a newer version is a common
+ task that can happen at any time while a Qt application is running. Users
+ may very well expect applications to be able to survive this, even when the
+ application is actively using an API like OpenGL or Direct3D.
+
+ Qt's own frameworks built on top of QRhi, such as, Qt Quick, can be
+ expected to handle and take appropriate measures when a device loss occurs.
+ If the data for graphics resources, such as textures and buffers, are still
+ available on the CPU side, such an event may not be noticeable on the
+ application level at all since graphics resources can seamlessly be
+ reinitialized then. However, applications and libraries working directly
+ with QRhi are expected to be prepared to check and handle device loss
+ situations themselves.
+
+ \note With OpenGL, applications may need to opt-in to context reset
+ notifications by setting QSurfaceFormat::ResetNotification on the
+ QOpenGLContext. This is typically done by enabling the flag in
+ QRhiGles2InitParams::format. Keep in mind however that some systems may
+ generate context resets situations even when this flag is not set.
+ */
+bool QRhi::isDeviceLost() const
+{
+ return d->isDeviceLost();
+}
+
+/*!
\return a new graphics pipeline resource.
\sa QRhiResource::release()
@@ -5180,7 +5272,17 @@ QRhiSwapChain *QRhi::newSwapChain()
\endlist
- \sa endFrame(), beginOffscreenFrame()
+ \return QRhi::FrameOpSuccess on success, or another QRhi::FrameOpResult
+ value on failure. Some of these should be treated as soft, "try again
+ later" type of errors: When QRhi::FrameOpSwapChainOutOfDate is returned,
+ the swapchain is to be resized or updated by calling
+ QRhiSwapChain::buildOrResize(). The application should then attempt to
+ generate a new frame. QRhi::FrameOpDeviceLost means the graphics device is
+ lost but this may also be recoverable by releasing all resources, including
+ the QRhi itself, and then recreating all resources. See isDeviceLost() for
+ further discussion.
+
+ \sa endFrame(), beginOffscreenFrame(), isDeviceLost()
*/
QRhi::FrameOpResult QRhi::beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags flags)
{
@@ -5205,7 +5307,17 @@ QRhi::FrameOpResult QRhi::beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags f
Passing QRhi::SkipPresent skips queuing the Present command or calling
swapBuffers.
- \sa beginFrame()
+ \return QRhi::FrameOpSuccess on success, or another QRhi::FrameOpResult
+ value on failure. Some of these should be treated as soft, "try again
+ later" type of errors: When QRhi::FrameOpSwapChainOutOfDate is returned,
+ the swapchain is to be resized or updated by calling
+ QRhiSwapChain::buildOrResize(). The application should then attempt to
+ generate a new frame. QRhi::FrameOpDeviceLost means the graphics device is
+ lost but this may also be recoverable by releasing all resources, including
+ the QRhi itself, and then recreating all resources. See isDeviceLost() for
+ further discussion.
+
+ \sa beginFrame(), isDeviceLost()
*/
QRhi::FrameOpResult QRhi::endFrame(QRhiSwapChain *swapChain, EndFrameFlags flags)
{
diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h
index 2d36c19e99..c73f03cf72 100644
--- a/src/gui/rhi/qrhi_p.h
+++ b/src/gui/rhi/qrhi_p.h
@@ -1294,7 +1294,8 @@ public:
enum Flag {
EnableProfiling = 1 << 0,
- EnableDebugMarkers = 1 << 1
+ EnableDebugMarkers = 1 << 1,
+ PreferSoftwareRenderer = 1 << 2
};
Q_DECLARE_FLAGS(Flags, Flag)
@@ -1413,13 +1414,17 @@ public:
int resourceLimit(ResourceLimit limit) const;
const QRhiNativeHandles *nativeHandles();
- void makeThreadLocalNativeContextCurrent();
+ bool makeThreadLocalNativeContextCurrent();
QRhiProfiler *profiler();
static const int MAX_LAYERS = 6; // cubemaps only
static const int MAX_LEVELS = 16; // a width and/or height of 65536 should be enough for everyone
+ void releaseCachedResources();
+
+ bool isDeviceLost() const;
+
protected:
QRhi();
diff --git a/src/gui/rhi/qrhi_p_p.h b/src/gui/rhi/qrhi_p_p.h
index 0914cf268b..63f27b6de4 100644
--- a/src/gui/rhi/qrhi_p_p.h
+++ b/src/gui/rhi/qrhi_p_p.h
@@ -156,7 +156,9 @@ public:
virtual int resourceLimit(QRhi::ResourceLimit limit) const = 0;
virtual const QRhiNativeHandles *nativeHandles() = 0;
virtual void sendVMemStatsToProfiler() = 0;
- virtual void makeThreadLocalNativeContextCurrent() = 0;
+ virtual bool makeThreadLocalNativeContextCurrent() = 0;
+ virtual void releaseCachedResources() = 0;
+ virtual bool isDeviceLost() const = 0;
bool isCompressedFormat(QRhiTexture::Format format) const;
void compressedFormatInfo(QRhiTexture::Format format, const QSize &size,
@@ -205,6 +207,8 @@ public:
QRhi *q;
+ static const int MAX_SHADER_CACHE_ENTRIES = 128;
+
protected:
bool debugMarkers = false;
int currentFrameSlot = 0; // for vk, mtl, and similar. unused by gl and d3d11.
diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp
index 3e136cdb80..1d2f3cfa80 100644
--- a/src/gui/rhi/qrhid3d11.cpp
+++ b/src/gui/rhi/qrhid3d11.cpp
@@ -36,6 +36,7 @@
#include "qrhid3d11_p_p.h"
#include "qshader_p.h"
+#include "cs_tdr.h"
#include <QWindow>
#include <QOperatingSystemVersion>
#include <qmath.h>
@@ -118,10 +119,20 @@ QT_BEGIN_NAMESPACE
\c{ID3D11Texture2D *}.
*/
+// help mingw with its ancient sdk headers
+#ifndef DXGI_ADAPTER_FLAG_SOFTWARE
+#define DXGI_ADAPTER_FLAG_SOFTWARE 2
+#endif
+
QRhiD3D11::QRhiD3D11(QRhiD3D11InitParams *params, QRhiD3D11NativeHandles *importDevice)
- : ofr(this)
+ : ofr(this),
+ deviceCurse(this)
{
debugLayer = params->enableDebugLayer;
+
+ deviceCurse.framesToActivate = params->framesUntilKillingDeviceViaTdr;
+ deviceCurse.permanent = params->repeatDeviceKill;
+
importedDevice = importDevice != nullptr;
if (importedDevice) {
dev = reinterpret_cast<ID3D11Device *>(importDevice->dev);
@@ -155,7 +166,7 @@ static QString comErrorMessage(HRESULT hr)
}
template <class Int>
-static inline Int aligned(Int v, Int byteAlign)
+inline Int aligned(Int v, Int byteAlign)
{
return (v + byteAlign - 1) & ~(byteAlign - 1);
}
@@ -166,7 +177,7 @@ static IDXGIFactory1 *createDXGIFactory2()
if (QOperatingSystemVersion::current() > QOperatingSystemVersion::Windows7) {
using PtrCreateDXGIFactory2 = HRESULT (WINAPI *)(UINT, REFIID, void **);
QSystemLibrary dxgilib(QStringLiteral("dxgi"));
- if (auto createDXGIFactory2 = (PtrCreateDXGIFactory2)dxgilib.resolve("CreateDXGIFactory2")) {
+ if (auto createDXGIFactory2 = reinterpret_cast<PtrCreateDXGIFactory2>(dxgilib.resolve("CreateDXGIFactory2"))) {
const HRESULT hr = createDXGIFactory2(0, IID_IDXGIFactory2, reinterpret_cast<void **>(&result));
if (FAILED(hr)) {
qWarning("CreateDXGIFactory2() failed to create DXGI factory: %s", qPrintable(comErrorMessage(hr)));
@@ -221,11 +232,29 @@ bool QRhiD3D11::create(QRhi::Flags flags)
int requestedAdapterIndex = -1;
if (qEnvironmentVariableIsSet("QT_D3D_ADAPTER_INDEX"))
requestedAdapterIndex = qEnvironmentVariableIntValue("QT_D3D_ADAPTER_INDEX");
- for (int adapterIndex = 0; dxgiFactory->EnumAdapters1(adapterIndex, &adapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex) {
+
+ if (requestedAdapterIndex < 0 && flags.testFlag(QRhi::PreferSoftwareRenderer)) {
+ for (int adapterIndex = 0; dxgiFactory->EnumAdapters1(UINT(adapterIndex), &adapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex) {
+ DXGI_ADAPTER_DESC1 desc;
+ adapter->GetDesc1(&desc);
+ adapter->Release();
+ if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) {
+ requestedAdapterIndex = adapterIndex;
+ break;
+ }
+ }
+ }
+
+ for (int adapterIndex = 0; dxgiFactory->EnumAdapters1(UINT(adapterIndex), &adapter) != DXGI_ERROR_NOT_FOUND; ++adapterIndex) {
DXGI_ADAPTER_DESC1 desc;
adapter->GetDesc1(&desc);
- const QString name = QString::fromUtf16((char16_t *) desc.Description);
- qCDebug(QRHI_LOG_INFO, "Adapter %d: '%s' (flags 0x%x)", adapterIndex, qPrintable(name), desc.Flags);
+ const QString name = QString::fromUtf16(reinterpret_cast<char16_t *>(desc.Description));
+ qCDebug(QRHI_LOG_INFO, "Adapter %d: '%s' (vendor 0x%X device 0x%X flags 0x%X)",
+ adapterIndex,
+ qPrintable(name),
+ desc.VendorId,
+ desc.DeviceId,
+ desc.Flags);
if (!adapterToUse && (requestedAdapterIndex < 0 || requestedAdapterIndex == adapterIndex)) {
adapterToUse = adapter;
qCDebug(QRHI_LOG_INFO, " using this adapter");
@@ -261,16 +290,33 @@ bool QRhiD3D11::create(QRhi::Flags flags)
if (FAILED(context->QueryInterface(IID_ID3DUserDefinedAnnotation, reinterpret_cast<void **>(&annotations))))
annotations = nullptr;
+ deviceLost = false;
+
nativeHandlesStruct.dev = dev;
nativeHandlesStruct.context = context;
+ if (deviceCurse.framesToActivate > 0)
+ deviceCurse.initResources();
+
return true;
}
+void QRhiD3D11::clearShaderCache()
+{
+ for (Shader &s : m_shaderCache)
+ s.s->Release();
+
+ m_shaderCache.clear();
+}
+
void QRhiD3D11::destroy()
{
finishActiveReadbacks();
+ clearShaderCache();
+
+ deviceCurse.releaseResources();
+
if (annotations) {
annotations->Release();
annotations = nullptr;
@@ -322,9 +368,9 @@ DXGI_SAMPLE_DESC QRhiD3D11::effectiveSampleCount(int sampleCount) const
return desc;
}
- desc.Count = s;
+ desc.Count = UINT(s);
if (s > 1)
- desc.Quality = D3D11_STANDARD_MULTISAMPLE_PATTERN;
+ desc.Quality = UINT(D3D11_STANDARD_MULTISAMPLE_PATTERN);
else
desc.Quality = 0;
@@ -456,9 +502,20 @@ void QRhiD3D11::sendVMemStatsToProfiler()
// nothing to do here
}
-void QRhiD3D11::makeThreadLocalNativeContextCurrent()
+bool QRhiD3D11::makeThreadLocalNativeContextCurrent()
{
- // nothing to do here
+ // not applicable
+ return false;
+}
+
+void QRhiD3D11::releaseCachedResources()
+{
+ clearShaderCache();
+}
+
+bool QRhiD3D11::isDeviceLost() const
+{
+ return deviceLost;
}
QRhiRenderBuffer *QRhiD3D11::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize,
@@ -640,7 +697,7 @@ void QRhiD3D11::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBind
uint *p = cmd.args.bindShaderResources.dynamicOffsetPairs;
for (int i = 0; i < dynamicOffsetCount; ++i) {
const QRhiCommandBuffer::DynamicOffset &dynOfs(dynamicOffsets[i]);
- const uint binding = dynOfs.first;
+ const uint binding = uint(dynOfs.first);
Q_ASSERT(aligned(dynOfs.second, quint32(256)) == dynOfs.second);
const uint offsetInConstants = dynOfs.second / 16;
*p++ = binding;
@@ -776,10 +833,10 @@ void QRhiD3D11::setBlendConstants(QRhiCommandBuffer *cb, const QColor &c)
QD3D11CommandBuffer::Command cmd;
cmd.cmd = QD3D11CommandBuffer::Command::BlendConstants;
cmd.args.blendConstants.ps = QRHI_RES(QD3D11GraphicsPipeline, cbD->currentGraphicsPipeline);
- cmd.args.blendConstants.c[0] = c.redF();
- cmd.args.blendConstants.c[1] = c.greenF();
- cmd.args.blendConstants.c[2] = c.blueF();
- cmd.args.blendConstants.c[3] = c.alphaF();
+ cmd.args.blendConstants.c[0] = float(c.redF());
+ cmd.args.blendConstants.c[1] = float(c.greenF());
+ cmd.args.blendConstants.c[2] = float(c.blueF());
+ cmd.args.blendConstants.c[3] = float(c.alphaF());
cbD->commands.append(cmd);
}
@@ -977,8 +1034,14 @@ QRhi::FrameOpResult QRhiD3D11::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrame
if (!flags.testFlag(QRhi::SkipPresent)) {
const UINT presentFlags = 0;
HRESULT hr = swapChainD->swapChain->Present(swapChainD->swapInterval, presentFlags);
- if (FAILED(hr))
+ if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) {
+ qWarning("Device loss detected in Present()");
+ deviceLost = true;
+ return QRhi::FrameOpDeviceLost;
+ } else if (FAILED(hr)) {
qWarning("Failed to present: %s", qPrintable(comErrorMessage(hr)));
+ return QRhi::FrameOpError;
+ }
// move on to the next buffer
swapChainD->currentFrameSlot = (swapChainD->currentFrameSlot + 1) % QD3D11SwapChain::BUFFER_COUNT;
@@ -988,6 +1051,20 @@ QRhi::FrameOpResult QRhiD3D11::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrame
swapChainD->frameCount += 1;
contextState.currentSwapChain = nullptr;
+
+ if (deviceCurse.framesToActivate > 0) {
+ deviceCurse.framesLeft -= 1;
+ if (deviceCurse.framesLeft == 0) {
+ deviceCurse.framesLeft = deviceCurse.framesToActivate;
+ if (!deviceCurse.permanent)
+ deviceCurse.framesToActivate = -1;
+
+ deviceCurse.activate();
+ } else if (deviceCurse.framesLeft % 100 == 0) {
+ qDebug("Impending doom: %d frames left", deviceCurse.framesLeft);
+ }
+ }
+
return QRhi::FrameOpSuccess;
}
@@ -1161,7 +1238,7 @@ QRhi::FrameOpResult QRhiD3D11::finish()
void QRhiD3D11::enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cbD,
int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc)
{
- UINT subres = D3D11CalcSubresource(level, layer, texD->mipLevelCount);
+ UINT subres = D3D11CalcSubresource(UINT(level), UINT(layer), texD->mipLevelCount);
const QPoint dp = subresDesc.destinationTopLeft();
D3D11_BOX box;
box.front = 0;
@@ -1192,13 +1269,13 @@ void QRhiD3D11::enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cb
} else {
cmd.args.updateSubRes.src = cbD->retainImage(img);
}
- box.left = dp.x();
- box.top = dp.y();
- box.right = dp.x() + size.width();
- box.bottom = dp.y() + size.height();
+ box.left = UINT(dp.x());
+ box.top = UINT(dp.y());
+ box.right = UINT(dp.x() + size.width());
+ box.bottom = UINT(dp.y() + size.height());
cmd.args.updateSubRes.hasDstBox = true;
cmd.args.updateSubRes.dstBox = box;
- cmd.args.updateSubRes.srcRowPitch = bpl;
+ cmd.args.updateSubRes.srcRowPitch = UINT(bpl);
} else if (!subresDesc.data().isEmpty() && isCompressedFormat(texD->m_format)) {
const QSize size = subresDesc.sourceSize().isEmpty() ? q->sizeForMipLevel(level, texD->m_pixelSize)
: subresDesc.sourceSize();
@@ -1208,10 +1285,10 @@ void QRhiD3D11::enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cb
// Everything must be a multiple of the block width and
// height, so e.g. a mip level of size 2x2 will be 4x4 when it
// comes to the actual data.
- box.left = aligned(dp.x(), blockDim.width());
- box.top = aligned(dp.y(), blockDim.height());
- box.right = aligned(dp.x() + size.width(), blockDim.width());
- box.bottom = aligned(dp.y() + size.height(), blockDim.height());
+ box.left = UINT(aligned(dp.x(), blockDim.width()));
+ box.top = UINT(aligned(dp.y(), blockDim.height()));
+ box.right = UINT(aligned(dp.x() + size.width(), blockDim.width()));
+ box.bottom = UINT(aligned(dp.y() + size.height(), blockDim.height()));
cmd.args.updateSubRes.hasDstBox = true;
cmd.args.updateSubRes.dstBox = box;
cmd.args.updateSubRes.src = cbD->retainData(subresDesc.data());
@@ -1220,12 +1297,11 @@ void QRhiD3D11::enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cb
const QSize size = subresDesc.sourceSize().isEmpty() ? q->sizeForMipLevel(level, texD->m_pixelSize)
: subresDesc.sourceSize();
quint32 bpl = 0;
- QSize blockDim;
textureFormatInfo(texD->m_format, size, &bpl, nullptr);
- box.left = dp.x();
- box.top = dp.y();
- box.right = dp.x() + size.width();
- box.bottom = dp.y() + size.height();
+ box.left = UINT(dp.x());
+ box.top = UINT(dp.y());
+ box.right = UINT(dp.x() + size.width());
+ box.bottom = UINT(dp.y() + size.height());
cmd.args.updateSubRes.hasDstBox = true;
cmd.args.updateSubRes.dstBox = box;
cmd.args.updateSubRes.src = cbD->retainData(subresDesc.data());
@@ -1247,7 +1323,7 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
for (const QRhiResourceUpdateBatchPrivate::DynamicBufferUpdate &u : ud->dynamicBufferUpdates) {
QD3D11Buffer *bufD = QRHI_RES(QD3D11Buffer, u.buf);
Q_ASSERT(bufD->m_type == QRhiBuffer::Dynamic);
- memcpy(bufD->dynBuf.data() + u.offset, u.data.constData(), u.data.size());
+ memcpy(bufD->dynBuf.data() + u.offset, u.data.constData(), size_t(u.data.size()));
bufD->hasPendingDynamicUpdates = true;
}
@@ -1265,10 +1341,10 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
// since the ID3D11Buffer's size is rounded up to be a multiple of 256
// while the data we have has the original size.
D3D11_BOX box;
- box.left = u.offset;
+ box.left = UINT(u.offset);
box.top = box.front = 0;
box.back = box.bottom = 1;
- box.right = u.offset + u.data.size(); // no -1: right, bottom, back are exclusive, see D3D11_BOX doc
+ box.right = UINT(u.offset + u.data.size()); // no -1: right, bottom, back are exclusive, see D3D11_BOX doc
cmd.args.updateSubRes.hasDstBox = true;
cmd.args.updateSubRes.dstBox = box;
cbD->commands.append(cmd);
@@ -1287,25 +1363,25 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
Q_ASSERT(u.copy.src && u.copy.dst);
QD3D11Texture *srcD = QRHI_RES(QD3D11Texture, u.copy.src);
QD3D11Texture *dstD = QRHI_RES(QD3D11Texture, u.copy.dst);
- UINT srcSubRes = D3D11CalcSubresource(u.copy.desc.sourceLevel(), u.copy.desc.sourceLayer(), srcD->mipLevelCount);
- UINT dstSubRes = D3D11CalcSubresource(u.copy.desc.destinationLevel(), u.copy.desc.destinationLayer(), dstD->mipLevelCount);
+ UINT srcSubRes = D3D11CalcSubresource(UINT(u.copy.desc.sourceLevel()), UINT(u.copy.desc.sourceLayer()), srcD->mipLevelCount);
+ UINT dstSubRes = D3D11CalcSubresource(UINT(u.copy.desc.destinationLevel()), UINT(u.copy.desc.destinationLayer()), dstD->mipLevelCount);
const QPoint dp = u.copy.desc.destinationTopLeft();
const QSize size = u.copy.desc.pixelSize().isEmpty() ? srcD->m_pixelSize : u.copy.desc.pixelSize();
const QPoint sp = u.copy.desc.sourceTopLeft();
D3D11_BOX srcBox;
- srcBox.left = sp.x();
- srcBox.top = sp.y();
+ srcBox.left = UINT(sp.x());
+ srcBox.top = UINT(sp.y());
srcBox.front = 0;
// back, right, bottom are exclusive
- srcBox.right = srcBox.left + size.width();
- srcBox.bottom = srcBox.top + size.height();
+ srcBox.right = srcBox.left + UINT(size.width());
+ srcBox.bottom = srcBox.top + UINT(size.height());
srcBox.back = 1;
QD3D11CommandBuffer::Command cmd;
cmd.cmd = QD3D11CommandBuffer::Command::CopySubRes;
cmd.args.copySubRes.dst = dstD->tex;
cmd.args.copySubRes.dstSubRes = dstSubRes;
- cmd.args.copySubRes.dstX = dp.x();
- cmd.args.copySubRes.dstY = dp.y();
+ cmd.args.copySubRes.dstX = UINT(dp.x());
+ cmd.args.copySubRes.dstY = UINT(dp.y());
cmd.args.copySubRes.src = srcD->tex;
cmd.args.copySubRes.srcSubRes = srcSubRes;
cmd.args.copySubRes.hasSrcBox = true;
@@ -1333,7 +1409,7 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
dxgiFormat = texD->dxgiFormat;
pixelSize = u.read.rb.level() > 0 ? q->sizeForMipLevel(u.read.rb.level(), texD->m_pixelSize) : texD->m_pixelSize;
format = texD->m_format;
- subres = D3D11CalcSubresource(u.read.rb.level(), u.read.rb.layer(), texD->mipLevelCount);
+ subres = D3D11CalcSubresource(UINT(u.read.rb.level()), UINT(u.read.rb.layer()), texD->mipLevelCount);
} else {
Q_ASSERT(contextState.currentSwapChain);
swapChainD = QRHI_RES(QD3D11SwapChain, contextState.currentSwapChain);
@@ -1362,8 +1438,8 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
D3D11_TEXTURE2D_DESC desc;
memset(&desc, 0, sizeof(desc));
- desc.Width = pixelSize.width();
- desc.Height = pixelSize.height();
+ desc.Width = UINT(pixelSize.width());
+ desc.Height = UINT(pixelSize.height());
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = dxgiFormat;
@@ -1376,7 +1452,7 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
qWarning("Failed to create readback staging texture: %s", qPrintable(comErrorMessage(hr)));
return;
}
- QRHI_PROF_F(newReadbackBuffer(quint64(quintptr(stagingTex)),
+ QRHI_PROF_F(newReadbackBuffer(qint64(qintptr(stagingTex)),
texD ? static_cast<QRhiResource *>(texD) : static_cast<QRhiResource *>(swapChainD),
bufSize));
@@ -1419,7 +1495,7 @@ void QRhiD3D11::finishActiveReadbacks()
const QRhiD3D11::ActiveReadback &aRb(activeReadbacks[i]);
aRb.result->format = aRb.format;
aRb.result->pixelSize = aRb.pixelSize;
- aRb.result->data.resize(aRb.bufSize);
+ aRb.result->data.resize(int(aRb.bufSize));
D3D11_MAPPED_SUBRESOURCE mp;
HRESULT hr = context->Map(aRb.stagingTex, 0, D3D11_MAP_READ, 0, &mp);
@@ -1440,7 +1516,7 @@ void QRhiD3D11::finishActiveReadbacks()
context->Unmap(aRb.stagingTex, 0);
aRb.stagingTex->Release();
- QRHI_PROF_F(releaseReadbackBuffer(quint64(quintptr(aRb.stagingTex))));
+ QRHI_PROF_F(releaseReadbackBuffer(qint64(qintptr(aRb.stagingTex))));
if (aRb.result->completed)
completedCallbacks.append(aRb.result->completed);
@@ -1509,10 +1585,10 @@ void QRhiD3D11::beginPass(QRhiCommandBuffer *cb,
if (rtD->dsAttCount && wantsDsClear)
clearCmd.args.clear.mask |= QD3D11CommandBuffer::Command::Depth | QD3D11CommandBuffer::Command::Stencil;
- clearCmd.args.clear.c[0] = colorClearValue.redF();
- clearCmd.args.clear.c[1] = colorClearValue.greenF();
- clearCmd.args.clear.c[2] = colorClearValue.blueF();
- clearCmd.args.clear.c[3] = colorClearValue.alphaF();
+ clearCmd.args.clear.c[0] = float(colorClearValue.redF());
+ clearCmd.args.clear.c[1] = float(colorClearValue.greenF());
+ clearCmd.args.clear.c[2] = float(colorClearValue.blueF());
+ clearCmd.args.clear.c[3] = float(colorClearValue.alphaF());
clearCmd.args.clear.d = depthStencilClearValue.depthClearValue();
clearCmd.args.clear.s = depthStencilClearValue.stencilClearValue();
cbD->commands.append(clearCmd);
@@ -1543,8 +1619,8 @@ void QRhiD3D11::endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resource
QD3D11CommandBuffer::Command cmd;
cmd.cmd = QD3D11CommandBuffer::Command::ResolveSubRes;
cmd.args.resolveSubRes.dst = dstTexD->tex;
- cmd.args.resolveSubRes.dstSubRes = D3D11CalcSubresource(colorAtt.resolveLevel(),
- colorAtt.resolveLayer(),
+ cmd.args.resolveSubRes.dstSubRes = D3D11CalcSubresource(UINT(colorAtt.resolveLevel()),
+ UINT(colorAtt.resolveLayer()),
dstTexD->mipLevelCount);
if (srcTexD) {
cmd.args.resolveSubRes.src = srcTexD->tex;
@@ -1571,7 +1647,7 @@ void QRhiD3D11::endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resource
continue;
}
}
- cmd.args.resolveSubRes.srcSubRes = D3D11CalcSubresource(0, colorAtt.layer(), 1);
+ cmd.args.resolveSubRes.srcSubRes = D3D11CalcSubresource(0, UINT(colorAtt.layer()), 1);
cmd.args.resolveSubRes.format = dstTexD->dxgiFormat;
cbD->commands.append(cmd);
}
@@ -1638,9 +1714,9 @@ void QRhiD3D11::dispatch(QRhiCommandBuffer *cb, int x, int y, int z)
QD3D11CommandBuffer::Command cmd;
cmd.cmd = QD3D11CommandBuffer::Command::Dispatch;
- cmd.args.dispatch.x = x;
- cmd.args.dispatch.y = y;
- cmd.args.dispatch.z = z;
+ cmd.args.dispatch.x = UINT(x);
+ cmd.args.dispatch.y = UINT(y);
+ cmd.args.dispatch.z = UINT(z);
cbD->commands.append(cmd);
}
@@ -1682,11 +1758,11 @@ void QRhiD3D11::updateShaderResourceBindings(QD3D11ShaderResourceBindings *srbD)
// dynamic ubuf offsets are not considered here, those are baked in
// at a later stage, which is good as vsubufoffsets and friends are
// per-srb, not per-setShaderResources call
- const uint offsetInConstants = b->u.ubuf.offset / 16;
+ const uint offsetInConstants = uint(b->u.ubuf.offset) / 16;
// size must be 16 mult. (in constants, i.e. multiple of 256 bytes).
// We can round up if needed since the buffers's actual size
// (ByteWidth) is always a multiple of 256.
- const uint sizeInConstants = aligned(b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size, 256) / 16;
+ const uint sizeInConstants = uint(aligned(b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size, 256) / 16);
if (b->stage.testFlag(QRhiShaderResourceBinding::VertexStage)) {
srbD->vsubufs.feed(b->binding, bufD->buffer);
srbD->vsubufoffsets.feed(b->binding, offsetInConstants);
@@ -1804,7 +1880,7 @@ void QRhiD3D11::executeBufferHostWritesForCurrentFrame(QD3D11Buffer *bufD)
D3D11_MAPPED_SUBRESOURCE mp;
HRESULT hr = context->Map(bufD->buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mp);
if (SUCCEEDED(hr)) {
- memcpy(mp.pData, bufD->dynBuf.constData(), bufD->dynBuf.size());
+ memcpy(mp.pData, bufD->dynBuf.constData(), size_t(bufD->dynBuf.size()));
context->Unmap(bufD->buffer, 0);
} else {
qWarning("Failed to map buffer: %s", qPrintable(comErrorMessage(hr)));
@@ -1817,13 +1893,13 @@ static void applyDynamicOffsets(QVarLengthArray<UINT, 4> *offsets,
QRhiBatchedBindings<UINT> *ubufoffsets,
const uint *dynOfsPairs, int dynOfsPairCount)
{
- const UINT count = ubufs->batches[batchIndex].resources.count();
+ const int count = ubufs->batches[batchIndex].resources.count();
const UINT startBinding = ubufs->batches[batchIndex].startBinding;
*offsets = ubufoffsets->batches[batchIndex].resources;
- for (UINT b = 0; b < count; ++b) {
+ for (int b = 0; b < count; ++b) {
for (int di = 0; di < dynOfsPairCount; ++di) {
const uint binding = dynOfsPairs[2 * di];
- if (binding == startBinding + b) {
+ if (binding == startBinding + UINT(b)) {
const uint offsetInConstants = dynOfsPairs[2 * di + 1];
(*offsets)[b] = offsetInConstants;
break;
@@ -1838,37 +1914,37 @@ void QRhiD3D11::bindShaderResources(QD3D11ShaderResourceBindings *srbD,
{
if (!offsetOnlyChange) {
for (const auto &batch : srbD->vssamplers.batches)
- context->VSSetSamplers(batch.startBinding, batch.resources.count(), batch.resources.constData());
+ context->VSSetSamplers(batch.startBinding, UINT(batch.resources.count()), batch.resources.constData());
for (const auto &batch : srbD->vsshaderresources.batches) {
- context->VSSetShaderResources(batch.startBinding, batch.resources.count(), batch.resources.constData());
+ context->VSSetShaderResources(batch.startBinding, UINT(batch.resources.count()), batch.resources.constData());
contextState.vsHighestActiveSrvBinding = qMax<int>(contextState.vsHighestActiveSrvBinding,
- batch.startBinding + batch.resources.count() - 1);
+ int(batch.startBinding) + batch.resources.count() - 1);
}
for (const auto &batch : srbD->fssamplers.batches)
- context->PSSetSamplers(batch.startBinding, batch.resources.count(), batch.resources.constData());
+ context->PSSetSamplers(batch.startBinding, UINT(batch.resources.count()), batch.resources.constData());
for (const auto &batch : srbD->fsshaderresources.batches) {
- context->PSSetShaderResources(batch.startBinding, batch.resources.count(), batch.resources.constData());
+ context->PSSetShaderResources(batch.startBinding, UINT(batch.resources.count()), batch.resources.constData());
contextState.fsHighestActiveSrvBinding = qMax<int>(contextState.fsHighestActiveSrvBinding,
- batch.startBinding + batch.resources.count() - 1);
+ int(batch.startBinding) + batch.resources.count() - 1);
}
for (const auto &batch : srbD->cssamplers.batches)
- context->CSSetSamplers(batch.startBinding, batch.resources.count(), batch.resources.constData());
+ context->CSSetSamplers(batch.startBinding, UINT(batch.resources.count()), batch.resources.constData());
for (const auto &batch : srbD->csshaderresources.batches) {
- context->CSSetShaderResources(batch.startBinding, batch.resources.count(), batch.resources.constData());
+ context->CSSetShaderResources(batch.startBinding, UINT(batch.resources.count()), batch.resources.constData());
contextState.csHighestActiveSrvBinding = qMax<int>(contextState.csHighestActiveSrvBinding,
- batch.startBinding + batch.resources.count() - 1);
+ int(batch.startBinding) + batch.resources.count() - 1);
}
}
for (int i = 0, ie = srbD->vsubufs.batches.count(); i != ie; ++i) {
if (!dynOfsPairCount) {
context->VSSetConstantBuffers1(srbD->vsubufs.batches[i].startBinding,
- srbD->vsubufs.batches[i].resources.count(),
+ UINT(srbD->vsubufs.batches[i].resources.count()),
srbD->vsubufs.batches[i].resources.constData(),
srbD->vsubufoffsets.batches[i].resources.constData(),
srbD->vsubufsizes.batches[i].resources.constData());
@@ -1876,7 +1952,7 @@ void QRhiD3D11::bindShaderResources(QD3D11ShaderResourceBindings *srbD,
QVarLengthArray<UINT, 4> offsets;
applyDynamicOffsets(&offsets, i, &srbD->vsubufs, &srbD->vsubufoffsets, dynOfsPairs, dynOfsPairCount);
context->VSSetConstantBuffers1(srbD->vsubufs.batches[i].startBinding,
- srbD->vsubufs.batches[i].resources.count(),
+ UINT(srbD->vsubufs.batches[i].resources.count()),
srbD->vsubufs.batches[i].resources.constData(),
offsets.constData(),
srbD->vsubufsizes.batches[i].resources.constData());
@@ -1886,7 +1962,7 @@ void QRhiD3D11::bindShaderResources(QD3D11ShaderResourceBindings *srbD,
for (int i = 0, ie = srbD->fsubufs.batches.count(); i != ie; ++i) {
if (!dynOfsPairCount) {
context->PSSetConstantBuffers1(srbD->fsubufs.batches[i].startBinding,
- srbD->fsubufs.batches[i].resources.count(),
+ UINT(srbD->fsubufs.batches[i].resources.count()),
srbD->fsubufs.batches[i].resources.constData(),
srbD->fsubufoffsets.batches[i].resources.constData(),
srbD->fsubufsizes.batches[i].resources.constData());
@@ -1894,7 +1970,7 @@ void QRhiD3D11::bindShaderResources(QD3D11ShaderResourceBindings *srbD,
QVarLengthArray<UINT, 4> offsets;
applyDynamicOffsets(&offsets, i, &srbD->fsubufs, &srbD->fsubufoffsets, dynOfsPairs, dynOfsPairCount);
context->PSSetConstantBuffers1(srbD->fsubufs.batches[i].startBinding,
- srbD->fsubufs.batches[i].resources.count(),
+ UINT(srbD->fsubufs.batches[i].resources.count()),
srbD->fsubufs.batches[i].resources.constData(),
offsets.constData(),
srbD->fsubufsizes.batches[i].resources.constData());
@@ -1904,7 +1980,7 @@ void QRhiD3D11::bindShaderResources(QD3D11ShaderResourceBindings *srbD,
for (int i = 0, ie = srbD->csubufs.batches.count(); i != ie; ++i) {
if (!dynOfsPairCount) {
context->CSSetConstantBuffers1(srbD->csubufs.batches[i].startBinding,
- srbD->csubufs.batches[i].resources.count(),
+ UINT(srbD->csubufs.batches[i].resources.count()),
srbD->csubufs.batches[i].resources.constData(),
srbD->csubufoffsets.batches[i].resources.constData(),
srbD->csubufsizes.batches[i].resources.constData());
@@ -1912,7 +1988,7 @@ void QRhiD3D11::bindShaderResources(QD3D11ShaderResourceBindings *srbD,
QVarLengthArray<UINT, 4> offsets;
applyDynamicOffsets(&offsets, i, &srbD->csubufs, &srbD->csubufoffsets, dynOfsPairs, dynOfsPairCount);
context->CSSetConstantBuffers1(srbD->csubufs.batches[i].startBinding,
- srbD->csubufs.batches[i].resources.count(),
+ UINT(srbD->csubufs.batches[i].resources.count()),
srbD->csubufs.batches[i].resources.constData(),
offsets.constData(),
srbD->csubufsizes.batches[i].resources.constData());
@@ -1921,13 +1997,13 @@ void QRhiD3D11::bindShaderResources(QD3D11ShaderResourceBindings *srbD,
for (int i = 0, ie = srbD->csUAVs.batches.count(); i != ie; ++i) {
const uint startBinding = srbD->csUAVs.batches[i].startBinding;
- const uint count = srbD->csUAVs.batches[i].resources.count();
+ const uint count = uint(srbD->csUAVs.batches[i].resources.count());
context->CSSetUnorderedAccessViews(startBinding,
count,
srbD->csUAVs.batches[i].resources.constData(),
nullptr);
contextState.csHighestActiveUavBinding = qMax<int>(contextState.csHighestActiveUavBinding,
- startBinding + count - 1);
+ int(startBinding + count - 1));
}
}
@@ -1951,7 +2027,7 @@ void QRhiD3D11::resetShaderResources()
QVarLengthArray<UINT, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> nulloffsets(count);
for (int i = 0; i < count; ++i)
nulloffsets[i] = 0;
- context->IASetVertexBuffers(0, count, nullbufs.constData(), nullstrides.constData(), nulloffsets.constData());
+ context->IASetVertexBuffers(0, UINT(count), nullbufs.constData(), nullstrides.constData(), nulloffsets.constData());
contextState.vsHighestActiveVertexBufferBinding = -1;
}
@@ -1964,15 +2040,15 @@ void QRhiD3D11::resetShaderResources()
for (int i = 0; i < nullsrvs.count(); ++i)
nullsrvs[i] = nullptr;
if (contextState.vsHighestActiveSrvBinding >= 0) {
- context->VSSetShaderResources(0, contextState.vsHighestActiveSrvBinding + 1, nullsrvs.constData());
+ context->VSSetShaderResources(0, UINT(contextState.vsHighestActiveSrvBinding + 1), nullsrvs.constData());
contextState.vsHighestActiveSrvBinding = -1;
}
if (contextState.fsHighestActiveSrvBinding >= 0) {
- context->PSSetShaderResources(0, contextState.fsHighestActiveSrvBinding + 1, nullsrvs.constData());
+ context->PSSetShaderResources(0, UINT(contextState.fsHighestActiveSrvBinding + 1), nullsrvs.constData());
contextState.fsHighestActiveSrvBinding = -1;
}
if (contextState.csHighestActiveSrvBinding >= 0) {
- context->CSSetShaderResources(0, contextState.csHighestActiveSrvBinding + 1, nullsrvs.constData());
+ context->CSSetShaderResources(0, UINT(contextState.csHighestActiveSrvBinding + 1), nullsrvs.constData());
contextState.csHighestActiveSrvBinding = -1;
}
}
@@ -1983,7 +2059,7 @@ void QRhiD3D11::resetShaderResources()
D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT> nulluavs(nulluavCount);
for (int i = 0; i < nulluavCount; ++i)
nulluavs[i] = nullptr;
- context->CSSetUnorderedAccessViews(0, nulluavCount, nulluavs.constData(), nullptr);
+ context->CSSetUnorderedAccessViews(0, UINT(nulluavCount), nulluavs.constData(), nullptr);
contextState.csHighestActiveUavBinding = -1;
}
}
@@ -2005,7 +2081,7 @@ void QRhiD3D11::executeCommandBuffer(QD3D11CommandBuffer *cbD, QD3D11SwapChain *
// writing the first timestamp only afterwards.
context->Begin(tsDisjoint);
QD3D11RenderTargetData *rtD = rtData(&timestampSwapChain->rt);
- context->OMSetRenderTargets(rtD->colorAttCount, rtD->colorAttCount ? rtD->rtv : nullptr, rtD->dsv);
+ context->OMSetRenderTargets(UINT(rtD->colorAttCount), rtD->colorAttCount ? rtD->rtv : nullptr, rtD->dsv);
context->End(tsStart); // just record a timestamp, no Begin needed
}
}
@@ -2018,7 +2094,7 @@ void QRhiD3D11::executeCommandBuffer(QD3D11CommandBuffer *cbD, QD3D11SwapChain *
case QD3D11CommandBuffer::Command::SetRenderTarget:
{
QD3D11RenderTargetData *rtD = rtData(cmd.args.setRenderTarget.rt);
- context->OMSetRenderTargets(rtD->colorAttCount, rtD->colorAttCount ? rtD->rtv : nullptr, rtD->dsv);
+ context->OMSetRenderTargets(UINT(rtD->colorAttCount), rtD->colorAttCount ? rtD->rtv : nullptr, rtD->dsv);
}
break;
case QD3D11CommandBuffer::Command::Clear:
@@ -2034,7 +2110,7 @@ void QRhiD3D11::executeCommandBuffer(QD3D11CommandBuffer *cbD, QD3D11SwapChain *
if (cmd.args.clear.mask & QD3D11CommandBuffer::Command::Stencil)
ds |= D3D11_CLEAR_STENCIL;
if (ds)
- context->ClearDepthStencilView(rtD->dsv, ds, cmd.args.clear.d, cmd.args.clear.s);
+ context->ClearDepthStencilView(rtD->dsv, ds, cmd.args.clear.d, UINT8(cmd.args.clear.s));
}
break;
case QD3D11CommandBuffer::Command::Viewport:
@@ -2064,8 +2140,8 @@ void QRhiD3D11::executeCommandBuffer(QD3D11CommandBuffer *cbD, QD3D11SwapChain *
contextState.vsHighestActiveVertexBufferBinding = qMax<int>(
contextState.vsHighestActiveVertexBufferBinding,
cmd.args.bindVertexBuffers.startSlot + cmd.args.bindVertexBuffers.slotCount - 1);
- context->IASetVertexBuffers(cmd.args.bindVertexBuffers.startSlot,
- cmd.args.bindVertexBuffers.slotCount,
+ context->IASetVertexBuffers(UINT(cmd.args.bindVertexBuffers.startSlot),
+ UINT(cmd.args.bindVertexBuffers.slotCount),
cmd.args.bindVertexBuffers.buffers,
cmd.args.bindVertexBuffers.strides,
cmd.args.bindVertexBuffers.offsets);
@@ -2208,7 +2284,7 @@ static inline uint toD3DBufferUsage(QRhiBuffer::UsageFlags usage)
u |= D3D11_BIND_CONSTANT_BUFFER;
if (usage.testFlag(QRhiBuffer::StorageBuffer))
u |= D3D11_BIND_UNORDERED_ACCESS;
- return u;
+ return uint(u);
}
bool QD3D11Buffer::build()
@@ -2231,7 +2307,7 @@ bool QD3D11Buffer::build()
D3D11_BUFFER_DESC desc;
memset(&desc, 0, sizeof(desc));
- desc.ByteWidth = roundedSize;
+ desc.ByteWidth = UINT(roundedSize);
desc.Usage = m_type == Dynamic ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT;
desc.BindFlags = toD3DBufferUsage(m_usage);
desc.CPUAccessFlags = m_type == Dynamic ? D3D11_CPU_ACCESS_WRITE : 0;
@@ -2250,10 +2326,10 @@ bool QD3D11Buffer::build()
}
if (!m_objectName.isEmpty())
- buffer->SetPrivateData(WKPDID_D3DDebugObjectName, m_objectName.size(), m_objectName.constData());
+ buffer->SetPrivateData(WKPDID_D3DDebugObjectName, UINT(m_objectName.size()), m_objectName.constData());
QRHI_PROF;
- QRHI_PROF_F(newBuffer(this, roundedSize, m_type == Dynamic ? 2 : 1, m_type == Dynamic ? 1 : 0));
+ QRHI_PROF_F(newBuffer(this, quint32(roundedSize), m_type == Dynamic ? 2 : 1, m_type == Dynamic ? 1 : 0));
generation += 1;
rhiD->registerResource(this);
@@ -2271,7 +2347,7 @@ ID3D11UnorderedAccessView *QD3D11Buffer::unorderedAccessView()
desc.Format = DXGI_FORMAT_R32_TYPELESS;
desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
desc.Buffer.FirstElement = 0;
- desc.Buffer.NumElements = aligned(m_size, 4) / 4;
+ desc.Buffer.NumElements = UINT(aligned(m_size, 4) / 4);
desc.Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
QRHI_RES_RHI(QRhiD3D11);
@@ -2332,8 +2408,8 @@ bool QD3D11RenderBuffer::build()
D3D11_TEXTURE2D_DESC desc;
memset(&desc, 0, sizeof(desc));
- desc.Width = m_pixelSize.width();
- desc.Height = m_pixelSize.height();
+ desc.Width = UINT(m_pixelSize.width());
+ desc.Height = UINT(m_pixelSize.height());
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.SampleDesc = sampleDesc;
@@ -2382,10 +2458,10 @@ bool QD3D11RenderBuffer::build()
}
if (!m_objectName.isEmpty())
- tex->SetPrivateData(WKPDID_D3DDebugObjectName, m_objectName.size(), m_objectName.constData());
+ tex->SetPrivateData(WKPDID_D3DDebugObjectName, UINT(m_objectName.size()), m_objectName.constData());
QRHI_PROF;
- QRHI_PROF_F(newRenderBuffer(this, false, false, sampleDesc.Count));
+ QRHI_PROF_F(newRenderBuffer(this, false, false, int(sampleDesc.Count)));
rhiD->registerResource(this);
return true;
@@ -2475,7 +2551,7 @@ bool QD3D11Texture::prepareBuild(QSize *adjustedSize)
QRHI_RES_RHI(QRhiD3D11);
dxgiFormat = toD3DTextureFormat(m_format, m_flags);
- mipLevelCount = hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1;
+ mipLevelCount = uint(hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1);
sampleDesc = rhiD->effectiveSampleCount(m_sampleCount);
if (sampleDesc.Count > 1) {
if (isCube) {
@@ -2561,8 +2637,8 @@ bool QD3D11Texture::build()
D3D11_TEXTURE2D_DESC desc;
memset(&desc, 0, sizeof(desc));
- desc.Width = size.width();
- desc.Height = size.height();
+ desc.Width = UINT(size.width());
+ desc.Height = UINT(size.height());
desc.MipLevels = mipLevelCount;
desc.ArraySize = isCube ? 6 : 1;
desc.Format = dxgiFormat;
@@ -2582,10 +2658,10 @@ bool QD3D11Texture::build()
return false;
if (!m_objectName.isEmpty())
- tex->SetPrivateData(WKPDID_D3DDebugObjectName, m_objectName.size(), m_objectName.constData());
+ tex->SetPrivateData(WKPDID_D3DDebugObjectName, UINT(m_objectName.size()), m_objectName.constData());
QRHI_PROF;
- QRHI_PROF_F(newTexture(this, true, mipLevelCount, isCube ? 6 : 1, sampleDesc.Count));
+ QRHI_PROF_F(newTexture(this, true, int(mipLevelCount), isCube ? 6 : 1, int(sampleDesc.Count)));
owns = true;
rhiD->registerResource(this);
@@ -2607,7 +2683,7 @@ bool QD3D11Texture::buildFrom(const QRhiNativeHandles *src)
return false;
QRHI_PROF;
- QRHI_PROF_F(newTexture(this, false, mipLevelCount, m_flags.testFlag(CubeMap) ? 6 : 1, sampleDesc.Count));
+ QRHI_PROF_F(newTexture(this, false, int(mipLevelCount), m_flags.testFlag(CubeMap) ? 6 : 1, int(sampleDesc.Count)));
owns = false;
QRHI_RES_RHI(QRhiD3D11);
@@ -2631,12 +2707,12 @@ ID3D11UnorderedAccessView *QD3D11Texture::unorderedAccessViewForLevel(int level)
desc.Format = dxgiFormat;
if (isCube) {
desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2DARRAY;
- desc.Texture2DArray.MipSlice = level;
+ desc.Texture2DArray.MipSlice = UINT(level);
desc.Texture2DArray.FirstArraySlice = 0;
desc.Texture2DArray.ArraySize = 6;
} else {
desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
- desc.Texture2D.MipSlice = level;
+ desc.Texture2D.MipSlice = UINT(level);
}
QRHI_RES_RHI(QRhiD3D11);
@@ -2896,15 +2972,15 @@ bool QD3D11TextureRenderTarget::build()
rtvDesc.Format = toD3DTextureFormat(texD->format(), texD->flags());
if (texD->flags().testFlag(QRhiTexture::CubeMap)) {
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
- rtvDesc.Texture2DArray.MipSlice = colorAttachments[i].level();
- rtvDesc.Texture2DArray.FirstArraySlice = colorAttachments[i].layer();
+ rtvDesc.Texture2DArray.MipSlice = UINT(colorAttachments[i].level());
+ rtvDesc.Texture2DArray.FirstArraySlice = UINT(colorAttachments[i].layer());
rtvDesc.Texture2DArray.ArraySize = 1;
} else {
if (texD->sampleDesc.Count > 1) {
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
} else {
rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
- rtvDesc.Texture2D.MipSlice = colorAttachments[i].level();
+ rtvDesc.Texture2D.MipSlice = UINT(colorAttachments[i].level());
}
}
HRESULT hr = rhiD->dev->CreateRenderTargetView(texD->tex, &rtvDesc, &rtv[i]);
@@ -2915,7 +2991,7 @@ bool QD3D11TextureRenderTarget::build()
ownsRtv[i] = true;
if (i == 0) {
d.pixelSize = texD->pixelSize();
- d.sampleCount = texD->sampleDesc.Count;
+ d.sampleCount = int(texD->sampleDesc.Count);
}
} else if (rb) {
QD3D11RenderBuffer *rbD = QRHI_RES(QD3D11RenderBuffer, rb);
@@ -2923,7 +2999,7 @@ bool QD3D11TextureRenderTarget::build()
rtv[i] = rbD->rtv;
if (i == 0) {
d.pixelSize = rbD->pixelSize();
- d.sampleCount = rbD->sampleDesc.Count;
+ d.sampleCount = int(rbD->sampleDesc.Count);
}
}
}
@@ -2945,7 +3021,7 @@ bool QD3D11TextureRenderTarget::build()
}
if (d.colorAttCount == 0) {
d.pixelSize = depthTexD->pixelSize();
- d.sampleCount = depthTexD->sampleDesc.Count;
+ d.sampleCount = int(depthTexD->sampleDesc.Count);
}
} else {
ownsDsv = false;
@@ -2953,7 +3029,7 @@ bool QD3D11TextureRenderTarget::build()
dsv = depthRbD->dsv;
if (d.colorAttCount == 0) {
d.pixelSize = m_desc.depthStencilBuffer()->pixelSize();
- d.sampleCount = depthRbD->sampleDesc.Count;
+ d.sampleCount = int(depthRbD->sampleDesc.Count);
}
}
d.dsAttCount = 1;
@@ -3177,9 +3253,9 @@ static inline D3D11_PRIMITIVE_TOPOLOGY toD3DTopology(QRhiGraphicsPipeline::Topol
}
}
-static inline uint toD3DColorWriteMask(QRhiGraphicsPipeline::ColorMask c)
+static inline UINT8 toD3DColorWriteMask(QRhiGraphicsPipeline::ColorMask c)
{
- uint f = 0;
+ UINT8 f = 0;
if (c.testFlag(QRhiGraphicsPipeline::R))
f |= D3D11_COLOR_WRITE_ENABLE_RED;
if (c.testFlag(QRhiGraphicsPipeline::G))
@@ -3314,22 +3390,22 @@ static QByteArray compileHlslShaderSource(const QShader &shader, QShader::Varian
ID3DBlob *bytecode = nullptr;
ID3DBlob *errors = nullptr;
- HRESULT hr = d3dCompile(hlslSource.shader().constData(), hlslSource.shader().size(),
+ HRESULT hr = d3dCompile(hlslSource.shader().constData(), SIZE_T(hlslSource.shader().size()),
nullptr, nullptr, nullptr,
hlslSource.entryPoint().constData(), target, 0, 0, &bytecode, &errors);
if (FAILED(hr) || !bytecode) {
qWarning("HLSL shader compilation failed: 0x%x", uint(hr));
if (errors) {
*error = QString::fromUtf8(static_cast<const char *>(errors->GetBufferPointer()),
- errors->GetBufferSize());
+ int(errors->GetBufferSize()));
errors->Release();
}
return QByteArray();
}
QByteArray result;
- result.resize(bytecode->GetBufferSize());
- memcpy(result.data(), bytecode->GetBufferPointer(), result.size());
+ result.resize(int(bytecode->GetBufferSize()));
+ memcpy(result.data(), bytecode->GetBufferPointer(), size_t(result.size()));
bytecode->Release();
return result;
}
@@ -3361,8 +3437,8 @@ bool QD3D11GraphicsPipeline::build()
dsDesc.DepthFunc = toD3DCompareOp(m_depthOp);
dsDesc.StencilEnable = m_stencilTest;
if (m_stencilTest) {
- dsDesc.StencilReadMask = m_stencilReadMask;
- dsDesc.StencilWriteMask = m_stencilWriteMask;
+ dsDesc.StencilReadMask = UINT8(m_stencilReadMask);
+ dsDesc.StencilWriteMask = UINT8(m_stencilWriteMask);
dsDesc.FrontFace.StencilFailOp = toD3DStencilOp(m_stencilFront.failOp);
dsDesc.FrontFace.StencilDepthFailOp = toD3DStencilOp(m_stencilFront.depthFailOp);
dsDesc.FrontFace.StencilPassOp = toD3DStencilOp(m_stencilFront.passOp);
@@ -3409,30 +3485,57 @@ bool QD3D11GraphicsPipeline::build()
QByteArray vsByteCode;
for (const QRhiShaderStage &shaderStage : qAsConst(m_shaderStages)) {
- QString error;
- QByteArray bytecode = compileHlslShaderSource(shaderStage.shader(), shaderStage.shaderVariant(), &error);
- if (bytecode.isEmpty()) {
- qWarning("HLSL shader compilation failed: %s", qPrintable(error));
- return false;
- }
- switch (shaderStage.type()) {
- case QRhiShaderStage::Vertex:
- hr = rhiD->dev->CreateVertexShader(bytecode.constData(), bytecode.size(), nullptr, &vs);
- if (FAILED(hr)) {
- qWarning("Failed to create vertex shader: %s", qPrintable(comErrorMessage(hr)));
- return false;
+ auto cacheIt = rhiD->m_shaderCache.constFind(shaderStage);
+ if (cacheIt != rhiD->m_shaderCache.constEnd()) {
+ switch (shaderStage.type()) {
+ case QRhiShaderStage::Vertex:
+ vs = static_cast<ID3D11VertexShader *>(cacheIt->s);
+ vs->AddRef();
+ vsByteCode = cacheIt->bytecode;
+ break;
+ case QRhiShaderStage::Fragment:
+ fs = static_cast<ID3D11PixelShader *>(cacheIt->s);
+ fs->AddRef();
+ break;
+ default:
+ break;
}
- vsByteCode = bytecode;
- break;
- case QRhiShaderStage::Fragment:
- hr = rhiD->dev->CreatePixelShader(bytecode.constData(), bytecode.size(), nullptr, &fs);
- if (FAILED(hr)) {
- qWarning("Failed to create pixel shader: %s", qPrintable(comErrorMessage(hr)));
+ } else {
+ QString error;
+ const QByteArray bytecode = compileHlslShaderSource(shaderStage.shader(), shaderStage.shaderVariant(), &error);
+ if (bytecode.isEmpty()) {
+ qWarning("HLSL shader compilation failed: %s", qPrintable(error));
return false;
}
- break;
- default:
- break;
+
+ if (rhiD->m_shaderCache.count() >= QRhiD3D11::MAX_SHADER_CACHE_ENTRIES) {
+ // Use the simplest strategy: too many cached shaders -> drop them all.
+ rhiD->clearShaderCache();
+ }
+
+ switch (shaderStage.type()) {
+ case QRhiShaderStage::Vertex:
+ hr = rhiD->dev->CreateVertexShader(bytecode.constData(), SIZE_T(bytecode.size()), nullptr, &vs);
+ if (FAILED(hr)) {
+ qWarning("Failed to create vertex shader: %s", qPrintable(comErrorMessage(hr)));
+ return false;
+ }
+ vsByteCode = bytecode;
+ rhiD->m_shaderCache.insert(shaderStage, QRhiD3D11::Shader(vs, bytecode));
+ vs->AddRef();
+ break;
+ case QRhiShaderStage::Fragment:
+ hr = rhiD->dev->CreatePixelShader(bytecode.constData(), SIZE_T(bytecode.size()), nullptr, &fs);
+ if (FAILED(hr)) {
+ qWarning("Failed to create pixel shader: %s", qPrintable(comErrorMessage(hr)));
+ return false;
+ }
+ rhiD->m_shaderCache.insert(shaderStage, QRhiD3D11::Shader(fs, bytecode));
+ fs->AddRef();
+ break;
+ default:
+ break;
+ }
}
}
@@ -3447,20 +3550,21 @@ bool QD3D11GraphicsPipeline::build()
memset(&desc, 0, sizeof(desc));
// the output from SPIRV-Cross uses TEXCOORD<location> as the semantic
desc.SemanticName = "TEXCOORD";
- desc.SemanticIndex = attribute.location();
+ desc.SemanticIndex = UINT(attribute.location());
desc.Format = toD3DAttributeFormat(attribute.format());
- desc.InputSlot = attribute.binding();
+ desc.InputSlot = UINT(attribute.binding());
desc.AlignedByteOffset = attribute.offset();
const QRhiVertexInputBinding &binding(bindings[attribute.binding()]);
if (binding.classification() == QRhiVertexInputBinding::PerInstance) {
desc.InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA;
- desc.InstanceDataStepRate = binding.instanceStepRate();
+ desc.InstanceDataStepRate = UINT(binding.instanceStepRate());
} else {
desc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
}
inputDescs.append(desc);
}
- hr = rhiD->dev->CreateInputLayout(inputDescs.constData(), inputDescs.count(), vsByteCode, vsByteCode.size(), &inputLayout);
+ hr = rhiD->dev->CreateInputLayout(inputDescs.constData(), UINT(inputDescs.count()),
+ vsByteCode, SIZE_T(vsByteCode.size()), &inputLayout);
if (FAILED(hr)) {
qWarning("Failed to create input layout: %s", qPrintable(comErrorMessage(hr)));
return false;
@@ -3502,19 +3606,31 @@ bool QD3D11ComputePipeline::build()
QRHI_RES_RHI(QRhiD3D11);
- QString error;
- QByteArray bytecode = compileHlslShaderSource(m_shaderStage.shader(), m_shaderStage.shaderVariant(), &error);
- if (bytecode.isEmpty()) {
- qWarning("HLSL compute shader compilation failed: %s", qPrintable(error));
- return false;
- }
+ auto cacheIt = rhiD->m_shaderCache.constFind(m_shaderStage);
+ if (cacheIt != rhiD->m_shaderCache.constEnd()) {
+ cs = static_cast<ID3D11ComputeShader *>(cacheIt->s);
+ } else {
+ QString error;
+ const QByteArray bytecode = compileHlslShaderSource(m_shaderStage.shader(), m_shaderStage.shaderVariant(), &error);
+ if (bytecode.isEmpty()) {
+ qWarning("HLSL compute shader compilation failed: %s", qPrintable(error));
+ return false;
+ }
- HRESULT hr = rhiD->dev->CreateComputeShader(bytecode.constData(), bytecode.size(), nullptr, &cs);
- if (FAILED(hr)) {
- qWarning("Failed to create compute shader: %s", qPrintable(comErrorMessage(hr)));
- return false;
+ HRESULT hr = rhiD->dev->CreateComputeShader(bytecode.constData(), SIZE_T(bytecode.size()), nullptr, &cs);
+ if (FAILED(hr)) {
+ qWarning("Failed to create compute shader: %s", qPrintable(comErrorMessage(hr)));
+ return false;
+ }
+
+ if (rhiD->m_shaderCache.count() >= QRhiD3D11::MAX_SHADER_CACHE_ENTRIES)
+ rhiD->clearShaderCache();
+
+ rhiD->m_shaderCache.insert(m_shaderStage, QRhiD3D11::Shader(cs, bytecode));
}
+ cs->AddRef();
+
generation += 1;
rhiD->registerResource(this);
return true;
@@ -3637,8 +3753,8 @@ bool QD3D11SwapChain::newColorBuffer(const QSize &size, DXGI_FORMAT format, DXGI
{
D3D11_TEXTURE2D_DESC desc;
memset(&desc, 0, sizeof(desc));
- desc.Width = size.width();
- desc.Height = size.height();
+ desc.Width = UINT(size.width());
+ desc.Height = UINT(size.height());
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = format;
@@ -3694,11 +3810,23 @@ bool QD3D11SwapChain::buildOrResize()
const UINT swapChainFlags = 0;
QRHI_RES_RHI(QRhiD3D11);
- const bool useFlipDiscard = rhiD->hasDxgi2 && rhiD->supportsFlipDiscardSwapchain;
+ bool useFlipDiscard = rhiD->hasDxgi2 && rhiD->supportsFlipDiscardSwapchain;
if (!swapChain) {
HWND hwnd = reinterpret_cast<HWND>(window->winId());
sampleDesc = rhiD->effectiveSampleCount(m_sampleCount);
+ // Take a shortcut for alpha: our QWindow is OpenGLSurface so whatever
+ // the platform plugin does to enable transparency for OpenGL window
+ // will be sufficient for us too on the legacy (DISCARD) path. For
+ // FLIP_DISCARD we'd need to use DirectComposition (create a
+ // IDCompositionDevice/Target/Visual), avoid that for now.
+ if (m_flags.testFlag(SurfaceHasPreMulAlpha) || m_flags.testFlag(SurfaceHasNonPreMulAlpha)) {
+ useFlipDiscard = false;
+ if (window->requestedFormat().alphaBufferSize() <= 0)
+ qWarning("Swapchain says surface has alpha but the window has no alphaBufferSize set. "
+ "This may lead to problems.");
+ }
+
HRESULT hr;
if (useFlipDiscard) {
// We use FLIP_DISCARD which implies a buffer count of 2 (as opposed to the
@@ -3709,18 +3837,17 @@ bool QD3D11SwapChain::buildOrResize()
DXGI_SWAP_CHAIN_DESC1 desc;
memset(&desc, 0, sizeof(desc));
- desc.Width = pixelSize.width();
- desc.Height = pixelSize.height();
+ desc.Width = UINT(pixelSize.width());
+ desc.Height = UINT(pixelSize.height());
desc.Format = colorFormat;
desc.SampleDesc.Count = 1;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.BufferCount = BUFFER_COUNT;
desc.Scaling = DXGI_SCALING_STRETCH;
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
- if (m_flags.testFlag(SurfaceHasPreMulAlpha))
- desc.AlphaMode = DXGI_ALPHA_MODE_PREMULTIPLIED;
- else if (m_flags.testFlag(SurfaceHasNonPreMulAlpha))
- desc.AlphaMode = DXGI_ALPHA_MODE_STRAIGHT;
+ // Do not bother with AlphaMode, if won't work unless we go through
+ // DirectComposition. Instead, we just take the other (DISCARD)
+ // path for now when alpha is requested.
desc.Flags = swapChainFlags;
IDXGISwapChain1 *sc1;
@@ -3735,8 +3862,8 @@ bool QD3D11SwapChain::buildOrResize()
DXGI_SWAP_CHAIN_DESC desc;
memset(&desc, 0, sizeof(desc));
- desc.BufferDesc.Width = pixelSize.width();
- desc.BufferDesc.Height = pixelSize.height();
+ desc.BufferDesc.Width = UINT(pixelSize.width());
+ desc.BufferDesc.Height = UINT(pixelSize.height());
desc.BufferDesc.RefreshRate.Numerator = 60;
desc.BufferDesc.RefreshRate.Denominator = 1;
desc.BufferDesc.Format = colorFormat;
@@ -3758,9 +3885,13 @@ bool QD3D11SwapChain::buildOrResize()
} else {
releaseBuffers();
const UINT count = useFlipDiscard ? BUFFER_COUNT : 1;
- HRESULT hr = swapChain->ResizeBuffers(count, pixelSize.width(), pixelSize.height(),
+ HRESULT hr = swapChain->ResizeBuffers(count, UINT(pixelSize.width()), UINT(pixelSize.height()),
colorFormat, swapChainFlags);
- if (FAILED(hr)) {
+ if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) {
+ qWarning("Device loss detected in ResizeBuffers()");
+ rhiD->deviceLost = true;
+ return false;
+ } else if (FAILED(hr)) {
qWarning("Failed to resize D3D11 swapchain: %s", qPrintable(comErrorMessage(hr)));
return false;
}
@@ -3821,13 +3952,13 @@ bool QD3D11SwapChain::buildOrResize()
QD3D11ReferenceRenderTarget *rtD = QRHI_RES(QD3D11ReferenceRenderTarget, &rt);
rtD->d.rp = QRHI_RES(QD3D11RenderPassDescriptor, m_renderPassDesc);
rtD->d.pixelSize = pixelSize;
- rtD->d.dpr = window->devicePixelRatio();
- rtD->d.sampleCount = sampleDesc.Count;
+ rtD->d.dpr = float(window->devicePixelRatio());
+ rtD->d.sampleCount = int(sampleDesc.Count);
rtD->d.colorAttCount = 1;
rtD->d.dsAttCount = m_depthStencil ? 1 : 0;
QRHI_PROF;
- QRHI_PROF_F(resizeSwapChain(this, BUFFER_COUNT, sampleDesc.Count > 1 ? BUFFER_COUNT : 0, sampleDesc.Count));
+ QRHI_PROF_F(resizeSwapChain(this, BUFFER_COUNT, sampleDesc.Count > 1 ? BUFFER_COUNT : 0, int(sampleDesc.Count)));
if (rhiP) {
D3D11_QUERY_DESC queryDesc;
memset(&queryDesc, 0, sizeof(queryDesc));
@@ -3861,4 +3992,34 @@ bool QD3D11SwapChain::buildOrResize()
return true;
}
+void QRhiD3D11::DeviceCurse::initResources()
+{
+ framesLeft = framesToActivate;
+
+ HRESULT hr = q->dev->CreateComputeShader(g_killDeviceByTimingOut, sizeof(g_killDeviceByTimingOut), nullptr, &cs);
+ if (FAILED(hr)) {
+ qWarning("Failed to create compute shader: %s", qPrintable(comErrorMessage(hr)));
+ return;
+ }
+}
+
+void QRhiD3D11::DeviceCurse::releaseResources()
+{
+ if (cs) {
+ cs->Release();
+ cs = nullptr;
+ }
+}
+
+void QRhiD3D11::DeviceCurse::activate()
+{
+ if (!cs)
+ return;
+
+ qDebug("Activating Curse. Goodbye Cruel World.");
+
+ q->context->CSSetShader(cs, nullptr, 0);
+ q->context->Dispatch(256, 1, 1);
+}
+
QT_END_NAMESPACE
diff --git a/src/gui/rhi/qrhid3d11_p.h b/src/gui/rhi/qrhid3d11_p.h
index 3e2e492d9c..5df1843b1e 100644
--- a/src/gui/rhi/qrhid3d11_p.h
+++ b/src/gui/rhi/qrhid3d11_p.h
@@ -58,6 +58,9 @@ QT_BEGIN_NAMESPACE
struct Q_GUI_EXPORT QRhiD3D11InitParams : public QRhiInitParams
{
bool enableDebugLayer = false;
+
+ int framesUntilKillingDeviceViaTdr = -1;
+ bool repeatDeviceKill = false;
};
struct Q_GUI_EXPORT QRhiD3D11NativeHandles : public QRhiNativeHandles
diff --git a/src/gui/rhi/qrhid3d11_p_p.h b/src/gui/rhi/qrhid3d11_p_p.h
index 582146315d..cf4808510c 100644
--- a/src/gui/rhi/qrhid3d11_p_p.h
+++ b/src/gui/rhi/qrhid3d11_p_p.h
@@ -631,7 +631,9 @@ public:
int resourceLimit(QRhi::ResourceLimit limit) const override;
const QRhiNativeHandles *nativeHandles() override;
void sendVMemStatsToProfiler() override;
- void makeThreadLocalNativeContextCurrent() override;
+ bool makeThreadLocalNativeContextCurrent() override;
+ void releaseCachedResources() override;
+ bool isDeviceLost() const override;
void enqueueSubresUpload(QD3D11Texture *texD, QD3D11CommandBuffer *cbD,
int layer, int level, const QRhiTextureSubresourceUploadDescription &subresDesc);
@@ -646,6 +648,7 @@ public:
DXGI_SAMPLE_DESC effectiveSampleCount(int sampleCount) const;
void finishActiveReadbacks();
void reportLiveObjects(ID3D11Device *device);
+ void clearShaderCache();
bool debugLayer = false;
bool importedDevice = false;
@@ -656,6 +659,7 @@ public:
IDXGIFactory1 *dxgiFactory = nullptr;
bool hasDxgi2 = false;
bool supportsFlipDiscardSwapchain = false;
+ bool deviceLost = false;
QRhiD3D11NativeHandles nativeHandlesStruct;
struct {
@@ -684,6 +688,27 @@ public:
QRhiTexture::Format format;
};
QVector<ActiveReadback> activeReadbacks;
+
+ struct Shader {
+ Shader() = default;
+ Shader(IUnknown *s, const QByteArray &bytecode) : s(s), bytecode(bytecode) { }
+ IUnknown *s;
+ QByteArray bytecode;
+ };
+ QHash<QRhiShaderStage, Shader> m_shaderCache;
+
+ struct DeviceCurse {
+ DeviceCurse(QRhiD3D11 *impl) : q(impl) { }
+ QRhiD3D11 *q;
+ int framesToActivate = -1;
+ bool permanent = false;
+ int framesLeft = 0;
+ ID3D11ComputeShader *cs = nullptr;
+
+ void initResources();
+ void releaseResources();
+ void activate();
+ } deviceCurse;
};
Q_DECLARE_TYPEINFO(QRhiD3D11::ActiveReadback, Q_MOVABLE_TYPE);
diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp
index f4e711e33e..2d51d892e3 100644
--- a/src/gui/rhi/qrhigles2.cpp
+++ b/src/gui/rhi/qrhigles2.cpp
@@ -371,7 +371,12 @@ bool QRhiGles2::ensureContext(QSurface *surface) const
return true;
if (!ctx->makeCurrent(surface)) {
- qWarning("QRhiGles2: Failed to make context current. Expect bad things to happen.");
+ if (ctx->isValid()) {
+ qWarning("QRhiGles2: Failed to make context current. Expect bad things to happen.");
+ } else {
+ qWarning("QRhiGles2: Context is lost.");
+ contextLost = true;
+ }
return false;
}
@@ -491,6 +496,8 @@ bool QRhiGles2::create(QRhi::Flags flags)
nativeHandlesStruct.context = ctx;
+ contextLost = false;
+
return true;
}
@@ -502,6 +509,10 @@ void QRhiGles2::destroy()
ensureContext();
executeDeferredReleases();
+ for (uint shader : m_shaderCache)
+ f->glDeleteShader(shader);
+ m_shaderCache.clear();
+
if (!importedContext) {
delete ctx;
ctx = nullptr;
@@ -650,7 +661,7 @@ static inline GLenum toGlCompressedTextureFormat(QRhiTexture::Format format, QRh
bool QRhiGles2::isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags) const
{
if (isCompressedFormat(format))
- return supportedCompressedFormats.contains(toGlCompressedTextureFormat(format, flags));
+ return supportedCompressedFormats.contains(GLint(toGlCompressedTextureFormat(format, flags)));
switch (format) {
case QRhiTexture::D16:
@@ -749,12 +760,28 @@ void QRhiGles2::sendVMemStatsToProfiler()
// nothing to do here
}
-void QRhiGles2::makeThreadLocalNativeContextCurrent()
+bool QRhiGles2::makeThreadLocalNativeContextCurrent()
{
if (inFrame && !ofr.active)
- ensureContext(currentSwapChain->surface);
+ return ensureContext(currentSwapChain->surface);
else
- ensureContext();
+ return ensureContext();
+}
+
+void QRhiGles2::releaseCachedResources()
+{
+ if (!ensureContext())
+ return;
+
+ for (uint shader : m_shaderCache)
+ f->glDeleteShader(shader);
+
+ m_shaderCache.clear();
+}
+
+bool QRhiGles2::isDeviceLost() const
+{
+ return contextLost;
}
QRhiRenderBuffer *QRhiGles2::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize,
@@ -915,7 +942,7 @@ void QRhiGles2::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBind
uint *p = cmd.args.bindShaderResources.dynamicOffsetPairs;
for (int i = 0; i < dynamicOffsetCount; ++i) {
const QRhiCommandBuffer::DynamicOffset &dynOfs(dynamicOffsets[i]);
- *p++ = dynOfs.first;
+ *p++ = uint(dynOfs.first);
*p++ = dynOfs.second;
}
} else {
@@ -1008,10 +1035,10 @@ void QRhiGles2::setBlendConstants(QRhiCommandBuffer *cb, const QColor &c)
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::BlendConstants;
- cmd.args.blendConstants.r = c.redF();
- cmd.args.blendConstants.g = c.greenF();
- cmd.args.blendConstants.b = c.blueF();
- cmd.args.blendConstants.a = c.alphaF();
+ cmd.args.blendConstants.r = float(c.redF());
+ cmd.args.blendConstants.g = float(c.greenF());
+ cmd.args.blendConstants.b = float(c.blueF());
+ cmd.args.blendConstants.a = float(c.alphaF());
cbD->commands.append(cmd);
}
@@ -1141,7 +1168,7 @@ QRhi::FrameOpResult QRhiGles2::beginFrame(QRhiSwapChain *swapChain, QRhi::BeginF
QGles2SwapChain *swapChainD = QRHI_RES(QGles2SwapChain, swapChain);
if (!ensureContext(swapChainD->surface))
- return QRhi::FrameOpError;
+ return contextLost ? QRhi::FrameOpDeviceLost : QRhi::FrameOpError;
currentSwapChain = swapChainD;
@@ -1164,7 +1191,7 @@ QRhi::FrameOpResult QRhiGles2::endFrame(QRhiSwapChain *swapChain, QRhi::EndFrame
addBoundaryCommand(&swapChainD->cb, QGles2CommandBuffer::Command::EndFrame);
if (!ensureContext(swapChainD->surface))
- return QRhi::FrameOpError;
+ return contextLost ? QRhi::FrameOpDeviceLost : QRhi::FrameOpError;
executeCommandBuffer(&swapChainD->cb);
@@ -1188,7 +1215,7 @@ QRhi::FrameOpResult QRhiGles2::beginOffscreenFrame(QRhiCommandBuffer **cb, QRhi:
{
Q_UNUSED(flags);
if (!ensureContext())
- return QRhi::FrameOpError;
+ return contextLost ? QRhi::FrameOpDeviceLost : QRhi::FrameOpError;
ofr.active = true;
@@ -1210,7 +1237,7 @@ QRhi::FrameOpResult QRhiGles2::endOffscreenFrame(QRhi::EndFrameFlags flags)
addBoundaryCommand(&ofr.cbWrapper, QGles2CommandBuffer::Command::EndFrame);
if (!ensureContext())
- return QRhi::FrameOpError;
+ return contextLost ? QRhi::FrameOpDeviceLost : QRhi::FrameOpError;
executeCommandBuffer(&ofr.cbWrapper);
@@ -1224,14 +1251,14 @@ QRhi::FrameOpResult QRhiGles2::finish()
Q_ASSERT(!currentSwapChain);
Q_ASSERT(ofr.cbWrapper.recordingPass == QGles2CommandBuffer::NoPass);
if (!ensureContext())
- return QRhi::FrameOpError;
+ return contextLost ? QRhi::FrameOpDeviceLost : QRhi::FrameOpError;
executeCommandBuffer(&ofr.cbWrapper);
ofr.cbWrapper.resetCommands();
} else {
Q_ASSERT(currentSwapChain);
Q_ASSERT(currentSwapChain->cb.recordingPass == QGles2CommandBuffer::NoPass);
if (!ensureContext(currentSwapChain->surface))
- return QRhi::FrameOpError;
+ return contextLost ? QRhi::FrameOpDeviceLost : QRhi::FrameOpError;
executeCommandBuffer(&currentSwapChain->cb);
currentSwapChain->cb.resetCommands();
}
@@ -1299,7 +1326,7 @@ void QRhiGles2::enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cb
}
cmd.args.subImage.target = texD->target;
cmd.args.subImage.texture = texD->texture;
- cmd.args.subImage.faceTarget = faceTargetBase + layer;
+ cmd.args.subImage.faceTarget = faceTargetBase + uint(layer);
cmd.args.subImage.level = level;
cmd.args.subImage.dx = dp.x();
cmd.args.subImage.dy = dp.y();
@@ -1318,7 +1345,7 @@ void QRhiGles2::enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cb
cmd.cmd = QGles2CommandBuffer::Command::CompressedSubImage;
cmd.args.compressedSubImage.target = texD->target;
cmd.args.compressedSubImage.texture = texD->texture;
- cmd.args.compressedSubImage.faceTarget = faceTargetBase + layer;
+ cmd.args.compressedSubImage.faceTarget = faceTargetBase + uint(layer);
cmd.args.compressedSubImage.level = level;
cmd.args.compressedSubImage.dx = dp.x();
cmd.args.compressedSubImage.dy = dp.y();
@@ -1333,7 +1360,7 @@ void QRhiGles2::enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cb
cmd.cmd = QGles2CommandBuffer::Command::CompressedImage;
cmd.args.compressedImage.target = texD->target;
cmd.args.compressedImage.texture = texD->texture;
- cmd.args.compressedImage.faceTarget = faceTargetBase + layer;
+ cmd.args.compressedImage.faceTarget = faceTargetBase + uint(layer);
cmd.args.compressedImage.level = level;
cmd.args.compressedImage.glintformat = texD->glintformat;
cmd.args.compressedImage.w = size.width();
@@ -1351,7 +1378,7 @@ void QRhiGles2::enqueueSubresUpload(QGles2Texture *texD, QGles2CommandBuffer *cb
cmd.cmd = QGles2CommandBuffer::Command::SubImage;
cmd.args.subImage.target = texD->target;
cmd.args.subImage.texture = texD->texture;
- cmd.args.subImage.faceTarget = faceTargetBase + layer;
+ cmd.args.subImage.faceTarget = faceTargetBase + uint(layer);
cmd.args.subImage.level = level;
cmd.args.subImage.dx = dp.x();
cmd.args.subImage.dy = dp.y();
@@ -1379,7 +1406,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, u.buf);
Q_ASSERT(bufD->m_type == QRhiBuffer::Dynamic);
if (bufD->m_usage.testFlag(QRhiBuffer::UniformBuffer)) {
- memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), u.data.size());
+ memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), size_t(u.data.size()));
} else {
trackedBufferBarrier(cbD, bufD, QGles2Buffer::AccessUpdate);
QGles2CommandBuffer::Command cmd;
@@ -1398,7 +1425,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
Q_ASSERT(bufD->m_type != QRhiBuffer::Dynamic);
Q_ASSERT(u.offset + u.data.size() <= bufD->m_size);
if (bufD->m_usage.testFlag(QRhiBuffer::UniformBuffer)) {
- memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), u.data.size());
+ memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), size_t(u.data.size()));
} else {
trackedBufferBarrier(cbD, bufD, QGles2Buffer::AccessUpdate);
QGles2CommandBuffer::Command cmd;
@@ -1443,7 +1470,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::CopyTex;
- cmd.args.copyTex.srcFaceTarget = srcFaceTargetBase + u.copy.desc.sourceLayer();
+ cmd.args.copyTex.srcFaceTarget = srcFaceTargetBase + uint(u.copy.desc.sourceLayer());
cmd.args.copyTex.srcTexture = srcD->texture;
cmd.args.copyTex.srcLevel = u.copy.desc.sourceLevel();
cmd.args.copyTex.srcX = sp.x();
@@ -1451,7 +1478,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
cmd.args.copyTex.dstTarget = dstD->target;
cmd.args.copyTex.dstTexture = dstD->texture;
- cmd.args.copyTex.dstFaceTarget = dstFaceTargetBase + u.copy.desc.destinationLayer();
+ cmd.args.copyTex.dstFaceTarget = dstFaceTargetBase + uint(u.copy.desc.destinationLayer());
cmd.args.copyTex.dstLevel = u.copy.desc.destinationLevel();
cmd.args.copyTex.dstX = dp.x();
cmd.args.copyTex.dstY = dp.y();
@@ -1465,7 +1492,8 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
cmd.cmd = QGles2CommandBuffer::Command::ReadPixels;
cmd.args.readPixels.result = u.read.result;
QGles2Texture *texD = QRHI_RES(QGles2Texture, u.read.rb.texture());
- trackedImageBarrier(cbD, texD, QGles2Texture::AccessRead);
+ if (texD)
+ trackedImageBarrier(cbD, texD, QGles2Texture::AccessRead);
cmd.args.readPixels.texture = texD ? texD->texture : 0;
if (texD) {
cmd.args.readPixels.w = texD->m_pixelSize.width();
@@ -1473,7 +1501,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
cmd.args.readPixels.format = texD->m_format;
const GLenum faceTargetBase = texD->m_flags.testFlag(QRhiTexture::CubeMap)
? GL_TEXTURE_CUBE_MAP_POSITIVE_X : texD->target;
- cmd.args.readPixels.readTarget = faceTargetBase + u.read.rb.layer();
+ cmd.args.readPixels.readTarget = faceTargetBase + uint(u.read.rb.layer());
cmd.args.readPixels.level = u.read.rb.level();
}
cbD->commands.append(cmd);
@@ -1833,7 +1861,7 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
f->glBindVertexArray(0);
break;
case QGles2CommandBuffer::Command::Viewport:
- f->glViewport(cmd.args.viewport.x, cmd.args.viewport.y, cmd.args.viewport.w, cmd.args.viewport.h);
+ f->glViewport(GLint(cmd.args.viewport.x), GLint(cmd.args.viewport.y), GLsizei(cmd.args.viewport.w), GLsizei(cmd.args.viewport.h));
f->glDepthRangef(cmd.args.viewport.d0, cmd.args.viewport.d1);
break;
case QGles2CommandBuffer::Command::Scissor:
@@ -1846,8 +1874,8 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
{
QGles2GraphicsPipeline *psD = QRHI_RES(QGles2GraphicsPipeline, cmd.args.stencilRef.ps);
if (psD) {
- f->glStencilFuncSeparate(GL_FRONT, toGlCompareOp(psD->m_stencilFront.compareOp), cmd.args.stencilRef.ref, psD->m_stencilReadMask);
- f->glStencilFuncSeparate(GL_BACK, toGlCompareOp(psD->m_stencilBack.compareOp), cmd.args.stencilRef.ref, psD->m_stencilReadMask);
+ f->glStencilFuncSeparate(GL_FRONT, toGlCompareOp(psD->m_stencilFront.compareOp), GLint(cmd.args.stencilRef.ref), psD->m_stencilReadMask);
+ f->glStencilFuncSeparate(GL_BACK, toGlCompareOp(psD->m_stencilBack.compareOp), GLint(cmd.args.stencilRef.ref), psD->m_stencilReadMask);
} else {
qWarning("No graphics pipeline active for setStencilRef; ignored");
}
@@ -1867,7 +1895,7 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
// we do not support more than one vertex buffer
f->glBindBuffer(GL_ARRAY_BUFFER, cmd.args.bindVertexBuffer.buffer);
- const int stride = bindings[bindingIdx].stride();
+ const int stride = int(bindings[bindingIdx].stride());
int size = 1;
GLenum type = GL_FLOAT;
bool normalize = false;
@@ -1909,13 +1937,13 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
const int locationIdx = a.location();
quint32 ofs = a.offset() + cmd.args.bindVertexBuffer.offset;
- f->glVertexAttribPointer(locationIdx, size, type, normalize, stride,
+ f->glVertexAttribPointer(GLuint(locationIdx), size, type, normalize, stride,
reinterpret_cast<const GLvoid *>(quintptr(ofs)));
- f->glEnableVertexAttribArray(locationIdx);
+ f->glEnableVertexAttribArray(GLuint(locationIdx));
if (bindings[bindingIdx].classification() == QRhiVertexInputBinding::PerInstance
&& caps.instancing)
{
- f->glVertexAttribDivisor(locationIdx, bindings[bindingIdx].instanceStepRate());
+ f->glVertexAttribDivisor(GLuint(locationIdx), GLuint(bindings[bindingIdx].instanceStepRate()));
}
}
} else {
@@ -1934,10 +1962,10 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
QGles2GraphicsPipeline *psD = QRHI_RES(QGles2GraphicsPipeline, cmd.args.draw.ps);
if (psD) {
if (cmd.args.draw.instanceCount == 1 || !caps.instancing) {
- f->glDrawArrays(psD->drawMode, cmd.args.draw.firstVertex, cmd.args.draw.vertexCount);
+ f->glDrawArrays(psD->drawMode, GLint(cmd.args.draw.firstVertex), GLsizei(cmd.args.draw.vertexCount));
} else {
- f->glDrawArraysInstanced(psD->drawMode, cmd.args.draw.firstVertex, cmd.args.draw.vertexCount,
- cmd.args.draw.instanceCount);
+ f->glDrawArraysInstanced(psD->drawMode, GLint(cmd.args.draw.firstVertex), GLsizei(cmd.args.draw.vertexCount),
+ GLsizei(cmd.args.draw.instanceCount));
}
} else {
qWarning("No graphics pipeline active for draw; ignored");
@@ -1953,30 +1981,30 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
if (cmd.args.drawIndexed.instanceCount == 1 || !caps.instancing) {
if (cmd.args.drawIndexed.baseVertex != 0 && caps.baseVertex) {
f->glDrawElementsBaseVertex(psD->drawMode,
- cmd.args.drawIndexed.indexCount,
+ GLsizei(cmd.args.drawIndexed.indexCount),
indexType,
ofs,
cmd.args.drawIndexed.baseVertex);
} else {
f->glDrawElements(psD->drawMode,
- cmd.args.drawIndexed.indexCount,
+ GLsizei(cmd.args.drawIndexed.indexCount),
indexType,
ofs);
}
} else {
if (cmd.args.drawIndexed.baseVertex != 0 && caps.baseVertex) {
f->glDrawElementsInstancedBaseVertex(psD->drawMode,
- cmd.args.drawIndexed.indexCount,
+ GLsizei(cmd.args.drawIndexed.indexCount),
indexType,
ofs,
- cmd.args.drawIndexed.instanceCount,
+ GLsizei(cmd.args.drawIndexed.instanceCount),
cmd.args.drawIndexed.baseVertex);
} else {
f->glDrawElementsInstanced(psD->drawMode,
- cmd.args.drawIndexed.indexCount,
+ GLsizei(cmd.args.drawIndexed.indexCount),
indexType,
ofs,
- cmd.args.drawIndexed.instanceCount);
+ GLsizei(cmd.args.drawIndexed.instanceCount));
}
}
} else {
@@ -2001,7 +2029,7 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
const int colorAttCount = cmd.args.bindFramebuffer.colorAttCount;
QVarLengthArray<GLenum, 8> bufs;
for (int i = 0; i < colorAttCount; ++i)
- bufs.append(GL_COLOR_ATTACHMENT0 + i);
+ bufs.append(GL_COLOR_ATTACHMENT0 + uint(i));
f->glDrawBuffers(colorAttCount, bufs.constData());
}
} else {
@@ -2029,7 +2057,7 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb)
f->glClearDepthf(cmd.args.clear.d);
}
if (cmd.args.clear.mask & GL_STENCIL_BUFFER_BIT)
- f->glClearStencil(cmd.args.clear.s);
+ f->glClearStencil(GLint(cmd.args.clear.s));
f->glClear(cmd.args.clear.mask);
break;
case QGles2CommandBuffer::Command::BufferSubData:
@@ -2273,7 +2301,7 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiC
if (dynOfsCount) {
for (int j = 0; j < dynOfsCount; ++j) {
if (dynOfsPairs[2 * j] == uint(b->binding)) {
- viewOffset = dynOfsPairs[2 * j + 1];
+ viewOffset = int(dynOfsPairs[2 * j + 1]);
break;
}
}
@@ -2364,20 +2392,20 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiC
for (QGles2SamplerDescription &sampler : samplers) {
if (sampler.binding == b->binding) {
- f->glActiveTexture(GL_TEXTURE0 + texUnit);
+ f->glActiveTexture(GL_TEXTURE0 + uint(texUnit));
f->glBindTexture(texD->target, texD->texture);
if (texD->samplerState != samplerD->d) {
- f->glTexParameteri(texD->target, GL_TEXTURE_MIN_FILTER, samplerD->d.glminfilter);
- f->glTexParameteri(texD->target, GL_TEXTURE_MAG_FILTER, samplerD->d.glmagfilter);
- f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_S, samplerD->d.glwraps);
- f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_T, samplerD->d.glwrapt);
+ f->glTexParameteri(texD->target, GL_TEXTURE_MIN_FILTER, GLint(samplerD->d.glminfilter));
+ f->glTexParameteri(texD->target, GL_TEXTURE_MAG_FILTER, GLint(samplerD->d.glmagfilter));
+ f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_S, GLint(samplerD->d.glwraps));
+ f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_T, GLint(samplerD->d.glwrapt));
// 3D textures not supported by GLES 2.0 or by us atm...
//f->glTexParameteri(texD->target, GL_TEXTURE_WRAP_R, samplerD->d.glwrapr);
if (caps.textureCompareMode) {
if (samplerD->d.gltexcomparefunc != GL_NEVER) {
f->glTexParameteri(texD->target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
- f->glTexParameteri(texD->target, GL_TEXTURE_COMPARE_FUNC, samplerD->d.gltexcomparefunc);
+ f->glTexParameteri(texD->target, GL_TEXTURE_COMPARE_FUNC, GLint(samplerD->d.gltexcomparefunc));
} else {
f->glTexParameteri(texD->target, GL_TEXTURE_COMPARE_MODE, GL_NONE);
}
@@ -2404,7 +2432,7 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiC
access = GL_READ_ONLY;
else if (b->type == QRhiShaderResourceBinding::ImageStore)
access = GL_WRITE_ONLY;
- f->glBindImageTexture(b->binding, texD->texture,
+ f->glBindImageTexture(GLuint(b->binding), texD->texture,
b->u.simage.level, layered, 0,
access, texD->glsizedintformat);
}
@@ -2417,9 +2445,9 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiC
{
QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, b->u.sbuf.buf);
if (b->u.sbuf.offset == 0 && b->u.sbuf.maybeSize == 0)
- f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, b->binding, bufD->buffer);
+ f->glBindBufferBase(GL_SHADER_STORAGE_BUFFER, GLuint(b->binding), bufD->buffer);
else
- f->glBindBufferRange(GL_SHADER_STORAGE_BUFFER, b->binding, bufD->buffer,
+ f->glBindBufferRange(GL_SHADER_STORAGE_BUFFER, GLuint(b->binding), bufD->buffer,
b->u.sbuf.offset, b->u.sbuf.maybeSize ? b->u.sbuf.maybeSize : bufD->m_size);
}
break;
@@ -2541,10 +2569,10 @@ void QRhiGles2::beginPass(QRhiCommandBuffer *cb,
clearCmd.args.clear.mask |= GL_COLOR_BUFFER_BIT;
if (rtD->dsAttCount && wantsDsClear)
clearCmd.args.clear.mask |= GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
- clearCmd.args.clear.c[0] = colorClearValue.redF();
- clearCmd.args.clear.c[1] = colorClearValue.greenF();
- clearCmd.args.clear.c[2] = colorClearValue.blueF();
- clearCmd.args.clear.c[3] = colorClearValue.alphaF();
+ clearCmd.args.clear.c[0] = float(colorClearValue.redF());
+ clearCmd.args.clear.c[1] = float(colorClearValue.greenF());
+ clearCmd.args.clear.c[2] = float(colorClearValue.blueF());
+ clearCmd.args.clear.c[3] = float(colorClearValue.alphaF());
clearCmd.args.clear.d = depthStencilClearValue.depthClearValue();
clearCmd.args.clear.s = depthStencilClearValue.stencilClearValue();
cbD->commands.append(clearCmd);
@@ -2582,7 +2610,7 @@ void QRhiGles2::endPass(QRhiCommandBuffer *cb, QRhiResourceUpdateBatch *resource
QGles2Texture *colorTexD = QRHI_RES(QGles2Texture, colorAtt.resolveTexture());
const GLenum faceTargetBase = colorTexD->m_flags.testFlag(QRhiTexture::CubeMap) ? GL_TEXTURE_CUBE_MAP_POSITIVE_X
: colorTexD->target;
- cmd.args.blitFromRb.target = faceTargetBase + colorAtt.resolveLayer();
+ cmd.args.blitFromRb.target = faceTargetBase + uint(colorAtt.resolveLayer());
cmd.args.blitFromRb.texture = colorTexD->texture;
cmd.args.blitFromRb.dstLevel = colorAtt.resolveLevel();
cbD->commands.append(cmd);
@@ -2649,9 +2677,9 @@ void QRhiGles2::dispatch(QRhiCommandBuffer *cb, int x, int y, int z)
QGles2CommandBuffer::Command cmd;
cmd.cmd = QGles2CommandBuffer::Command::Dispatch;
- cmd.args.dispatch.x = x;
- cmd.args.dispatch.y = y;
- cmd.args.dispatch.z = z;
+ cmd.args.dispatch.x = GLuint(x);
+ cmd.args.dispatch.y = GLuint(y);
+ cmd.args.dispatch.z = GLuint(z);
cbD->commands.append(cmd);
}
@@ -2673,7 +2701,6 @@ static inline GLenum toGlShaderType(QRhiShaderStage::Type type)
bool QRhiGles2::compileShader(GLuint program, const QRhiShaderStage &shaderStage,
QShaderDescription *desc, int *glslVersionUsed)
{
- GLuint shader = f->glCreateShader(toGlShaderType(shaderStage.type()));
const QShader bakedShader = shaderStage.shader();
QVector<int> versionsToTry;
QByteArray source;
@@ -2733,27 +2760,40 @@ bool QRhiGles2::compileShader(GLuint program, const QRhiShaderStage &shaderStage
return false;
}
- const char *srcStr = source.constData();
- const GLint srcLength = source.count();
- f->glShaderSource(shader, 1, &srcStr, &srcLength);
- f->glCompileShader(shader);
- GLint compiled = 0;
- f->glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
- if (!compiled) {
- GLint infoLogLength = 0;
- f->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
- QByteArray log;
- if (infoLogLength > 1) {
- GLsizei length = 0;
- log.resize(infoLogLength);
- f->glGetShaderInfoLog(shader, infoLogLength, &length, log.data());
+ GLuint shader;
+ auto cacheIt = m_shaderCache.constFind(shaderStage);
+ if (cacheIt != m_shaderCache.constEnd()) {
+ shader = *cacheIt;
+ } else {
+ shader = f->glCreateShader(toGlShaderType(shaderStage.type()));
+ const char *srcStr = source.constData();
+ const GLint srcLength = source.count();
+ f->glShaderSource(shader, 1, &srcStr, &srcLength);
+ f->glCompileShader(shader);
+ GLint compiled = 0;
+ f->glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
+ if (!compiled) {
+ GLint infoLogLength = 0;
+ f->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
+ QByteArray log;
+ if (infoLogLength > 1) {
+ GLsizei length = 0;
+ log.resize(infoLogLength);
+ f->glGetShaderInfoLog(shader, infoLogLength, &length, log.data());
+ }
+ qWarning("Failed to compile shader: %s\nSource was:\n%s", log.constData(), source.constData());
+ return false;
}
- qWarning("Failed to compile shader: %s\nSource was:\n%s", log.constData(), source.constData());
- return false;
+ if (m_shaderCache.count() >= MAX_SHADER_CACHE_ENTRIES) {
+ // Use the simplest strategy: too many cached shaders -> drop them all.
+ for (uint shader : m_shaderCache)
+ f->glDeleteShader(shader); // does not actually get released yet when attached to a not-yet-released program
+ m_shaderCache.clear();
+ }
+ m_shaderCache.insert(shaderStage, shader);
}
f->glAttachShader(program, shader);
- f->glDeleteShader(shader);
*desc = bakedShader.description();
return true;
@@ -2791,7 +2831,7 @@ void QRhiGles2::gatherUniforms(GLuint program, const QShaderDescription::Uniform
uniform.glslLocation = f->glGetUniformLocation(program, name.constData());
if (uniform.glslLocation >= 0) {
uniform.binding = ub.binding;
- uniform.offset = blockMember.offset;
+ uniform.offset = uint(blockMember.offset);
uniform.size = blockMember.size;
dst->append(uniform);
}
@@ -2855,7 +2895,7 @@ bool QGles2Buffer::build()
return false;
}
ubuf.resize(nonZeroSize);
- QRHI_PROF_F(newBuffer(this, nonZeroSize, 0, 1));
+ QRHI_PROF_F(newBuffer(this, uint(nonZeroSize), 0, 1));
return true;
}
@@ -2874,7 +2914,7 @@ bool QGles2Buffer::build()
usageState.access = AccessNone;
- QRHI_PROF_F(newBuffer(this, nonZeroSize, 1, 0));
+ QRHI_PROF_F(newBuffer(this, uint(nonZeroSize), 1, 0));
rhiD->registerResource(this);
return true;
}
@@ -3145,13 +3185,13 @@ bool QGles2Texture::build()
for (int layer = 0, layerCount = isCube ? 6 : 1; layer != layerCount; ++layer) {
for (int level = 0; level != mipLevelCount; ++level) {
const QSize mipSize = rhiD->q->sizeForMipLevel(level, size);
- rhiD->f->glTexImage2D(faceTargetBase + layer, level, glintformat,
+ rhiD->f->glTexImage2D(faceTargetBase + uint(layer), level, GLint(glintformat),
mipSize.width(), mipSize.height(), 0,
glformat, gltype, nullptr);
}
}
} else {
- rhiD->f->glTexImage2D(target, 0, glintformat, size.width(), size.height(),
+ rhiD->f->glTexImage2D(target, 0, GLint(glintformat), size.width(), size.height(),
0, glformat, gltype, nullptr);
}
} else {
@@ -3354,14 +3394,15 @@ bool QGles2TextureRenderTarget::build()
QGles2Texture *texD = QRHI_RES(QGles2Texture, texture);
Q_ASSERT(texD->texture && texD->specified);
const GLenum faceTargetBase = texD->flags().testFlag(QRhiTexture::CubeMap) ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : texD->target;
- rhiD->f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, faceTargetBase + colorAtt.layer(), texD->texture, colorAtt.level());
+ rhiD->f->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uint(i), faceTargetBase + uint(colorAtt.layer()),
+ texD->texture, colorAtt.level());
if (i == 0) {
d.pixelSize = texD->pixelSize();
d.sampleCount = 1;
}
} else if (renderBuffer) {
QGles2RenderBuffer *rbD = QRHI_RES(QGles2RenderBuffer, renderBuffer);
- rhiD->f->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_RENDERBUFFER, rbD->renderbuffer);
+ rhiD->f->glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uint(i), GL_RENDERBUFFER, rbD->renderbuffer);
if (i == 0) {
d.pixelSize = rbD->pixelSize();
d.sampleCount = rbD->samples;
@@ -3511,7 +3552,7 @@ bool QGles2GraphicsPipeline::build()
for (auto inVar : vsDesc.inputVariables()) {
const QByteArray name = inVar.name.toUtf8();
- rhiD->f->glBindAttribLocation(program, inVar.location, name.constData());
+ rhiD->f->glBindAttribLocation(program, GLuint(inVar.location), name.constData());
}
if (!rhiD->linkProgram(program))
@@ -3657,7 +3698,7 @@ bool QGles2SwapChain::buildOrResize()
rt.d.rp = QRHI_RES(QGles2RenderPassDescriptor, m_renderPassDesc);
rt.d.pixelSize = pixelSize;
- rt.d.dpr = m_window->devicePixelRatio();
+ rt.d.dpr = float(m_window->devicePixelRatio());
rt.d.sampleCount = qBound(1, m_sampleCount, 64);
rt.d.colorAttCount = 1;
rt.d.dsAttCount = m_depthStencil ? 1 : 0;
diff --git a/src/gui/rhi/qrhigles2_p_p.h b/src/gui/rhi/qrhigles2_p_p.h
index 6da529be92..e7bcb626b6 100644
--- a/src/gui/rhi/qrhigles2_p_p.h
+++ b/src/gui/rhi/qrhigles2_p_p.h
@@ -664,7 +664,9 @@ public:
int resourceLimit(QRhi::ResourceLimit limit) const override;
const QRhiNativeHandles *nativeHandles() override;
void sendVMemStatsToProfiler() override;
- void makeThreadLocalNativeContextCurrent() override;
+ bool makeThreadLocalNativeContextCurrent() override;
+ void releaseCachedResources() override;
+ bool isDeviceLost() const override;
bool ensureContext(QSurface *surface = nullptr) const;
void executeDeferredReleases();
@@ -768,6 +770,7 @@ public:
QVector<GLint> supportedCompressedFormats;
mutable QVector<int> supportedSampleCountList;
QRhiGles2NativeHandles nativeHandlesStruct;
+ mutable bool contextLost = false;
struct DeferredReleaseEntry {
enum Type {
@@ -804,6 +807,8 @@ public:
bool active = false;
QGles2CommandBuffer cbWrapper;
} ofr;
+
+ QHash<QRhiShaderStage, uint> m_shaderCache;
};
Q_DECLARE_TYPEINFO(QRhiGles2::DeferredReleaseEntry, Q_MOVABLE_TYPE);
diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm
index 07753c985c..0b1ab72c2c 100644
--- a/src/gui/rhi/qrhimetal.mm
+++ b/src/gui/rhi/qrhimetal.mm
@@ -138,6 +138,20 @@ QT_BEGIN_NAMESPACE
\l{QRhiCommandBuffer::endPass()}.
*/
+struct QMetalShader
+{
+ id<MTLLibrary> lib = nil;
+ id<MTLFunction> func = nil;
+ std::array<uint, 3> localSize;
+
+ void release() {
+ [lib release];
+ lib = nil;
+ [func release];
+ func = nil;
+ }
+};
+
struct QRhiMetalData
{
QRhiMetalData(QRhiImplementation *rhi) : ofr(rhi) { }
@@ -206,6 +220,8 @@ struct QRhiMetalData
API_AVAILABLE(macos(10.13), ios(11.0)) id<MTLCaptureScope> captureScope = nil;
static const int TEXBUF_ALIGN = 256; // probably not accurate
+
+ QHash<QRhiShaderStage, QMetalShader> shaderCache;
};
Q_DECLARE_TYPEINFO(QRhiMetalData::DeferredReleaseEntry, Q_MOVABLE_TYPE);
@@ -289,17 +305,14 @@ struct QMetalGraphicsPipelineData
MTLPrimitiveType primitiveType;
MTLWinding winding;
MTLCullMode cullMode;
- id<MTLLibrary> vsLib = nil;
- id<MTLFunction> vsFunc = nil;
- id<MTLLibrary> fsLib = nil;
- id<MTLFunction> fsFunc = nil;
+ QMetalShader vs;
+ QMetalShader fs;
};
struct QMetalComputePipelineData
{
id<MTLComputePipelineState> ps = nil;
- id<MTLLibrary> csLib = nil;
- id<MTLFunction> csFunc = nil;
+ QMetalShader cs;
MTLSize localSize;
};
@@ -339,7 +352,8 @@ QRhiMetal::~QRhiMetal()
delete d;
}
-static inline uint aligned(uint v, uint byteAlign)
+template <class Int>
+inline Int aligned(Int v, Int byteAlign)
{
return (v + byteAlign - 1) & ~(byteAlign - 1);
}
@@ -404,6 +418,10 @@ void QRhiMetal::destroy()
executeDeferredReleases(true);
finishActiveReadbacks(true);
+ for (QMetalShader &s : d->shaderCache)
+ s.release();
+ d->shaderCache.clear();
+
if (@available(macOS 10.13, iOS 11.0, *)) {
[d->captureScope release];
d->captureScope = nil;
@@ -565,9 +583,23 @@ void QRhiMetal::sendVMemStatsToProfiler()
// nothing to do here
}
-void QRhiMetal::makeThreadLocalNativeContextCurrent()
+bool QRhiMetal::makeThreadLocalNativeContextCurrent()
{
- // nothing to do here
+ // not applicable
+ return false;
+}
+
+void QRhiMetal::releaseCachedResources()
+{
+ for (QMetalShader &s : d->shaderCache)
+ s.release();
+
+ d->shaderCache.clear();
+}
+
+bool QRhiMetal::isDeviceLost() const
+{
+ return false;
}
QRhiRenderBuffer *QRhiMetal::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize,
@@ -630,7 +662,7 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD
{
QMetalBuffer *bufD = QRHI_RES(QMetalBuffer, b->u.ubuf.buf);
id<MTLBuffer> mtlbuf = bufD->d->buf[bufD->d->slotted ? currentFrameSlot : 0];
- uint offset = b->u.ubuf.offset;
+ uint offset = uint(b->u.ubuf.offset);
for (int i = 0; i < dynamicOffsetCount; ++i) {
const QRhiCommandBuffer::DynamicOffset &dynOfs(dynamicOffsets[i]);
if (dynOfs.first == b->binding) {
@@ -694,7 +726,7 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD
{
QMetalBuffer *bufD = QRHI_RES(QMetalBuffer, b->u.sbuf.buf);
id<MTLBuffer> mtlbuf = bufD->d->buf[0];
- uint offset = b->u.sbuf.offset;
+ uint offset = uint(b->u.sbuf.offset);
if (b->stage.testFlag(QRhiShaderResourceBinding::VertexStage)) {
res[0].buffers.feed(b->binding, mtlbuf);
res[0].bufferOffsets.feed(b->binding, offset);
@@ -726,17 +758,17 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD
case 0:
[cbD->d->currentRenderPassEncoder setVertexBuffers: bufferBatch.resources.constData()
offsets: offsetBatch.resources.constData()
- withRange: NSMakeRange(bufferBatch.startBinding, bufferBatch.resources.count())];
+ withRange: NSMakeRange(bufferBatch.startBinding, NSUInteger(bufferBatch.resources.count()))];
break;
case 1:
[cbD->d->currentRenderPassEncoder setFragmentBuffers: bufferBatch.resources.constData()
offsets: offsetBatch.resources.constData()
- withRange: NSMakeRange(bufferBatch.startBinding, bufferBatch.resources.count())];
+ withRange: NSMakeRange(bufferBatch.startBinding, NSUInteger(bufferBatch.resources.count()))];
break;
case 2:
[cbD->d->currentComputePassEncoder setBuffers: bufferBatch.resources.constData()
offsets: offsetBatch.resources.constData()
- withRange: NSMakeRange(bufferBatch.startBinding, bufferBatch.resources.count())];
+ withRange: NSMakeRange(bufferBatch.startBinding, NSUInteger(bufferBatch.resources.count()))];
break;
default:
Q_UNREACHABLE();
@@ -755,15 +787,15 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD
switch (idx) {
case 0:
[cbD->d->currentRenderPassEncoder setVertexTextures: batch.resources.constData()
- withRange: NSMakeRange(batch.startBinding, batch.resources.count())];
+ withRange: NSMakeRange(batch.startBinding, NSUInteger(batch.resources.count()))];
break;
case 1:
[cbD->d->currentRenderPassEncoder setFragmentTextures: batch.resources.constData()
- withRange: NSMakeRange(batch.startBinding, batch.resources.count())];
+ withRange: NSMakeRange(batch.startBinding, NSUInteger(batch.resources.count()))];
break;
case 2:
[cbD->d->currentComputePassEncoder setTextures: batch.resources.constData()
- withRange: NSMakeRange(batch.startBinding, batch.resources.count())];
+ withRange: NSMakeRange(batch.startBinding, NSUInteger(batch.resources.count()))];
break;
default:
Q_UNREACHABLE();
@@ -775,15 +807,15 @@ void QRhiMetal::enqueueShaderResourceBindings(QMetalShaderResourceBindings *srbD
switch (idx) {
case 0:
[cbD->d->currentRenderPassEncoder setVertexSamplerStates: batch.resources.constData()
- withRange: NSMakeRange(batch.startBinding, batch.resources.count())];
+ withRange: NSMakeRange(batch.startBinding, NSUInteger(batch.resources.count()))];
break;
case 1:
[cbD->d->currentRenderPassEncoder setFragmentSamplerStates: batch.resources.constData()
- withRange: NSMakeRange(batch.startBinding, batch.resources.count())];
+ withRange: NSMakeRange(batch.startBinding, NSUInteger(batch.resources.count()))];
break;
case 2:
[cbD->d->currentComputePassEncoder setSamplerStates: batch.resources.constData()
- withRange: NSMakeRange(batch.startBinding, batch.resources.count())];
+ withRange: NSMakeRange(batch.startBinding, NSUInteger(batch.resources.count()))];
break;
default:
Q_UNREACHABLE();
@@ -981,7 +1013,7 @@ void QRhiMetal::setVertexInput(QRhiCommandBuffer *cb,
[cbD->d->currentRenderPassEncoder setVertexBuffers:
bufferBatch.resources.constData()
offsets: offsetBatch.resources.constData()
- withRange: NSMakeRange(firstVertexBinding + bufferBatch.startBinding, bufferBatch.resources.count())];
+ withRange: NSMakeRange(uint(firstVertexBinding) + bufferBatch.startBinding, NSUInteger(bufferBatch.resources.count()))];
}
}
@@ -997,11 +1029,44 @@ void QRhiMetal::setVertexInput(QRhiCommandBuffer *cb,
}
}
+QSize safeOutputSize(QRhiMetal *rhiD, QMetalCommandBuffer *cbD)
+{
+ QSize size = cbD->currentTarget->pixelSize();
+
+ // So now we have the issue that the texture (drawable) size may have
+ // changed again since swapchain buildOrResize() was called. This can
+ // happen for example when interactively resizing the window a lot in one
+ // go, and command buffer building happens on a dedicated thread (f.ex.
+ // using the threaded render loop of Qt Quick).
+ //
+ // This is only an issue when running in debug mode with XCode because Metal
+ // validation will fail when setting viewport or scissor with the real size
+ // being smaller than what we think it is. So query the drawable size right
+ // here, in debug mode at least.
+ //
+ // In addition, we have to take the smaller of the two widths and heights
+ // to be safe, apparently. In some cases validation seems to think that the
+ // "render pass width" (or height) is the old(?) value.
+
+#ifdef QT_DEBUG
+ if (cbD->currentTarget->resourceType() == QRhiResource::RenderTarget) {
+ Q_ASSERT(rhiD->currentSwapChain);
+ const QSize otherSize = rhiD->currentSwapChain->surfacePixelSize();
+ size.setWidth(qMin(size.width(), otherSize.width()));
+ size.setHeight(qMin(size.height(), otherSize.height()));
+ }
+#else
+ Q_UNUSED(rhiD);
+#endif
+
+ return size;
+}
+
void QRhiMetal::setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport)
{
QMetalCommandBuffer *cbD = QRHI_RES(QMetalCommandBuffer, cb);
Q_ASSERT(cbD->recordingPass == QMetalCommandBuffer::RenderPass);
- const QSize outputSize = cbD->currentTarget->pixelSize();
+ const QSize outputSize = safeOutputSize(this, cbD);
// x,y is top-left in MTLViewportRect but bottom-left in QRhiViewport
float x, y, w, h;
@@ -1009,21 +1074,21 @@ void QRhiMetal::setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport)
return;
MTLViewport vp;
- vp.originX = x;
- vp.originY = y;
- vp.width = w;
- vp.height = h;
- vp.znear = viewport.minDepth();
- vp.zfar = viewport.maxDepth();
+ vp.originX = double(x);
+ vp.originY = double(y);
+ vp.width = double(w);
+ vp.height = double(h);
+ vp.znear = double(viewport.minDepth());
+ vp.zfar = double(viewport.maxDepth());
[cbD->d->currentRenderPassEncoder setViewport: vp];
if (!QRHI_RES(QMetalGraphicsPipeline, cbD->currentGraphicsPipeline)->m_flags.testFlag(QRhiGraphicsPipeline::UsesScissor)) {
MTLScissorRect s;
- s.x = x;
- s.y = y;
- s.width = w;
- s.height = h;
+ s.x = NSUInteger(x);
+ s.y = NSUInteger(y);
+ s.width = NSUInteger(w);
+ s.height = NSUInteger(h);
[cbD->d->currentRenderPassEncoder setScissorRect: s];
}
}
@@ -1033,7 +1098,7 @@ void QRhiMetal::setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor)
QMetalCommandBuffer *cbD = QRHI_RES(QMetalCommandBuffer, cb);
Q_ASSERT(cbD->recordingPass == QMetalCommandBuffer::RenderPass);
Q_ASSERT(QRHI_RES(QMetalGraphicsPipeline, cbD->currentGraphicsPipeline)->m_flags.testFlag(QRhiGraphicsPipeline::UsesScissor));
- const QSize outputSize = cbD->currentTarget->pixelSize();
+ const QSize outputSize = safeOutputSize(this, cbD);
// x,y is top-left in MTLScissorRect but bottom-left in QRhiScissor
int x, y, w, h;
@@ -1041,10 +1106,10 @@ void QRhiMetal::setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor)
return;
MTLScissorRect s;
- s.x = x;
- s.y = y;
- s.width = w;
- s.height = h;
+ s.x = NSUInteger(x);
+ s.y = NSUInteger(y);
+ s.width = NSUInteger(w);
+ s.height = NSUInteger(h);
[cbD->d->currentRenderPassEncoder setScissorRect: s];
}
@@ -1054,7 +1119,8 @@ void QRhiMetal::setBlendConstants(QRhiCommandBuffer *cb, const QColor &c)
QMetalCommandBuffer *cbD = QRHI_RES(QMetalCommandBuffer, cb);
Q_ASSERT(cbD->recordingPass == QMetalCommandBuffer::RenderPass);
- [cbD->d->currentRenderPassEncoder setBlendColorRed: c.redF() green: c.greenF() blue: c.blueF() alpha: c.alphaF()];
+ [cbD->d->currentRenderPassEncoder setBlendColorRed: float(c.redF())
+ green: float(c.greenF()) blue: float(c.blueF()) alpha: float(c.alphaF())];
}
void QRhiMetal::setStencilRef(QRhiCommandBuffer *cb, quint32 refValue)
@@ -1086,7 +1152,7 @@ void QRhiMetal::drawIndexed(QRhiCommandBuffer *cb, quint32 indexCount,
return;
const quint32 indexOffset = cbD->currentIndexOffset + firstIndex * (cbD->currentIndexFormat == QRhiCommandBuffer::IndexUInt16 ? 2 : 4);
- Q_ASSERT(indexOffset == aligned(indexOffset, 4));
+ Q_ASSERT(indexOffset == aligned<quint32>(indexOffset, 4));
QMetalBuffer *ibufD = QRHI_RES(QMetalBuffer, cbD->currentIndexBuffer);
id<MTLBuffer> mtlbuf = ibufD->d->buf[ibufD->d->slotted ? currentFrameSlot : 0];
@@ -1344,7 +1410,7 @@ MTLRenderPassDescriptor *QRhiMetalData::createDefaultRenderPass(bool hasDepthSte
MTLClearColor c = MTLClearColorMake(colorClearValue.redF(), colorClearValue.greenF(), colorClearValue.blueF(),
colorClearValue.alphaF());
- for (int i = 0; i < colorAttCount; ++i) {
+ for (uint i = 0; i < uint(colorAttCount); ++i) {
rp.colorAttachments[i].loadAction = MTLLoadActionClear;
rp.colorAttachments[i].storeAction = MTLStoreActionStore;
rp.colorAttachments[i].clearColor = c;
@@ -1355,7 +1421,7 @@ MTLRenderPassDescriptor *QRhiMetalData::createDefaultRenderPass(bool hasDepthSte
rp.depthAttachment.storeAction = MTLStoreActionDontCare;
rp.stencilAttachment.loadAction = MTLLoadActionClear;
rp.stencilAttachment.storeAction = MTLStoreActionDontCare;
- rp.depthAttachment.clearDepth = depthStencilClearValue.depthClearValue();
+ rp.depthAttachment.clearDepth = double(depthStencilClearValue.depthClearValue());
rp.stencilAttachment.clearStencil = depthStencilClearValue.stencilClearValue();
}
@@ -1368,7 +1434,7 @@ qsizetype QRhiMetal::subresUploadByteSize(const QRhiTextureSubresourceUploadDesc
const qsizetype imageSizeBytes = subresDesc.image().isNull() ?
subresDesc.data().size() : subresDesc.image().sizeInBytes();
if (imageSizeBytes > 0)
- size += aligned(imageSizeBytes, QRhiMetalData::TEXBUF_ALIGN);
+ size += aligned<qsizetype>(imageSizeBytes, QRhiMetalData::TEXBUF_ALIGN);
return size;
}
@@ -1396,31 +1462,31 @@ void QRhiMetal::enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEnc
h = subresDesc.sourceSize().height();
}
if (img.depth() == 32) {
- memcpy(reinterpret_cast<char *>(mp) + *curOfs, img.constBits(), fullImageSizeBytes);
+ memcpy(reinterpret_cast<char *>(mp) + *curOfs, img.constBits(), size_t(fullImageSizeBytes));
srcOffset = sy * bpl + sx * 4;
// bpl remains set to the original image's row stride
} else {
img = img.copy(sx, sy, w, h);
bpl = img.bytesPerLine();
Q_ASSERT(img.sizeInBytes() <= fullImageSizeBytes);
- memcpy(reinterpret_cast<char *>(mp) + *curOfs, img.constBits(), img.sizeInBytes());
+ memcpy(reinterpret_cast<char *>(mp) + *curOfs, img.constBits(), size_t(img.sizeInBytes()));
}
} else {
- memcpy(reinterpret_cast<char *>(mp) + *curOfs, img.constBits(), fullImageSizeBytes);
+ memcpy(reinterpret_cast<char *>(mp) + *curOfs, img.constBits(), size_t(fullImageSizeBytes));
}
[blitEnc copyFromBuffer: texD->d->stagingBuf[currentFrameSlot]
- sourceOffset: *curOfs + srcOffset
- sourceBytesPerRow: bpl
+ sourceOffset: NSUInteger(*curOfs + srcOffset)
+ sourceBytesPerRow: NSUInteger(bpl)
sourceBytesPerImage: 0
- sourceSize: MTLSizeMake(w, h, 1)
+ sourceSize: MTLSizeMake(NSUInteger(w), NSUInteger(h), 1)
toTexture: texD->d->tex
- destinationSlice: layer
- destinationLevel: level
- destinationOrigin: MTLOriginMake(dp.x(), dp.y(), 0)
+ destinationSlice: NSUInteger(layer)
+ destinationLevel: NSUInteger(level)
+ destinationOrigin: MTLOriginMake(NSUInteger(dp.x()), NSUInteger(dp.y()), 0)
options: MTLBlitOptionNone];
- *curOfs += aligned(fullImageSizeBytes, QRhiMetalData::TEXBUF_ALIGN);
+ *curOfs += aligned<qsizetype>(fullImageSizeBytes, QRhiMetalData::TEXBUF_ALIGN);
} else if (!rawData.isEmpty() && isCompressedFormat(texD->m_format)) {
const QSize subresSize = q->sizeForMipLevel(level, texD->m_pixelSize);
const int subresw = subresSize.width();
@@ -1445,17 +1511,17 @@ void QRhiMetal::enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEnc
if (dy + h != subresh)
h = aligned(h, blockDim.height());
- memcpy(reinterpret_cast<char *>(mp) + *curOfs, rawData.constData(), rawData.size());
+ memcpy(reinterpret_cast<char *>(mp) + *curOfs, rawData.constData(), size_t(rawData.size()));
[blitEnc copyFromBuffer: texD->d->stagingBuf[currentFrameSlot]
- sourceOffset: *curOfs
+ sourceOffset: NSUInteger(*curOfs)
sourceBytesPerRow: bpl
sourceBytesPerImage: 0
- sourceSize: MTLSizeMake(w, h, 1)
+ sourceSize: MTLSizeMake(NSUInteger(w), NSUInteger(h), 1)
toTexture: texD->d->tex
- destinationSlice: layer
- destinationLevel: level
- destinationOrigin: MTLOriginMake(dx, dy, 0)
+ destinationSlice: NSUInteger(layer)
+ destinationLevel: NSUInteger(level)
+ destinationOrigin: MTLOriginMake(NSUInteger(dx), NSUInteger(dy), 0)
options: MTLBlitOptionNone];
*curOfs += aligned(rawData.size(), QRhiMetalData::TEXBUF_ALIGN);
@@ -1474,17 +1540,17 @@ void QRhiMetal::enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEnc
quint32 bpl = 0;
textureFormatInfo(texD->m_format, QSize(w, h), &bpl, nullptr);
- memcpy(reinterpret_cast<char *>(mp) + *curOfs, rawData.constData(), rawData.size());
+ memcpy(reinterpret_cast<char *>(mp) + *curOfs, rawData.constData(), size_t(rawData.size()));
[blitEnc copyFromBuffer: texD->d->stagingBuf[currentFrameSlot]
- sourceOffset: *curOfs
+ sourceOffset: NSUInteger(*curOfs)
sourceBytesPerRow: bpl
sourceBytesPerImage: 0
- sourceSize: MTLSizeMake(w, h, 1)
+ sourceSize: MTLSizeMake(NSUInteger(w), NSUInteger(h), 1)
toTexture: texD->d->tex
- destinationSlice: layer
- destinationLevel: level
- destinationOrigin: MTLOriginMake(dp.x(), dp.y(), 0)
+ destinationSlice: NSUInteger(layer)
+ destinationLevel: NSUInteger(level)
+ destinationOrigin: MTLOriginMake(NSUInteger(dp.x()), NSUInteger(dp.y()), 0)
options: MTLBlitOptionNone];
*curOfs += aligned(rawData.size(), QRhiMetalData::TEXBUF_ALIGN);
@@ -1538,9 +1604,9 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
ensureBlit();
Q_ASSERT(!utexD->d->stagingBuf[currentFrameSlot]);
- utexD->d->stagingBuf[currentFrameSlot] = [d->dev newBufferWithLength: stagingSize
+ utexD->d->stagingBuf[currentFrameSlot] = [d->dev newBufferWithLength: NSUInteger(stagingSize)
options: MTLResourceStorageModeShared];
- QRHI_PROF_F(newTextureStagingArea(utexD, currentFrameSlot, stagingSize));
+ QRHI_PROF_F(newTextureStagingArea(utexD, currentFrameSlot, quint32(stagingSize)));
void *mp = [utexD->d->stagingBuf[currentFrameSlot] contents];
qsizetype curOfs = 0;
@@ -1570,14 +1636,14 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
ensureBlit();
[blitEnc copyFromTexture: srcD->d->tex
- sourceSlice: u.copy.desc.sourceLayer()
- sourceLevel: u.copy.desc.sourceLevel()
- sourceOrigin: MTLOriginMake(sp.x(), sp.y(), 0)
- sourceSize: MTLSizeMake(size.width(), size.height(), 1)
+ sourceSlice: NSUInteger(u.copy.desc.sourceLayer())
+ sourceLevel: NSUInteger(u.copy.desc.sourceLevel())
+ sourceOrigin: MTLOriginMake(NSUInteger(sp.x()), NSUInteger(sp.y()), 0)
+ sourceSize: MTLSizeMake(NSUInteger(size.width()), NSUInteger(size.height()), 1)
toTexture: dstD->d->tex
- destinationSlice: u.copy.desc.destinationLayer()
- destinationLevel: u.copy.desc.destinationLevel()
- destinationOrigin: MTLOriginMake(dp.x(), dp.y(), 0)];
+ destinationSlice: NSUInteger(u.copy.desc.destinationLayer())
+ destinationLevel: NSUInteger(u.copy.desc.destinationLevel())
+ destinationOrigin: MTLOriginMake(NSUInteger(dp.x()), NSUInteger(dp.y()), 0)];
srcD->lastActiveFrameSlot = dstD->lastActiveFrameSlot = currentFrameSlot;
} else if (u.type == QRhiResourceUpdateBatchPrivate::TextureOp::Read) {
@@ -1617,16 +1683,16 @@ void QRhiMetal::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
textureFormatInfo(aRb.format, aRb.pixelSize, &bpl, &aRb.bufSize);
aRb.buf = [d->dev newBufferWithLength: aRb.bufSize options: MTLResourceStorageModeShared];
- QRHI_PROF_F(newReadbackBuffer(quint64(quintptr(aRb.buf)),
+ QRHI_PROF_F(newReadbackBuffer(qint64(qintptr(aRb.buf)),
texD ? static_cast<QRhiResource *>(texD) : static_cast<QRhiResource *>(swapChainD),
aRb.bufSize));
ensureBlit();
[blitEnc copyFromTexture: src
- sourceSlice: u.read.rb.layer()
- sourceLevel: u.read.rb.level()
+ sourceSlice: NSUInteger(u.read.rb.layer())
+ sourceLevel: NSUInteger(u.read.rb.level())
sourceOrigin: MTLOriginMake(0, 0, 0)
- sourceSize: MTLSizeMake(srcSize.width(), srcSize.height(), 1)
+ sourceSize: MTLSizeMake(NSUInteger(srcSize.width()), NSUInteger(srcSize.height()), 1)
toBuffer: aRb.buf
destinationOffset: 0
destinationBytesPerRow: bpl
@@ -1664,14 +1730,14 @@ void QRhiMetal::executeBufferHostWritesForCurrentFrame(QMetalBuffer *bufD)
int changeEnd = -1;
for (const QRhiResourceUpdateBatchPrivate::DynamicBufferUpdate &u : updates) {
Q_ASSERT(bufD == QRHI_RES(QMetalBuffer, u.buf));
- memcpy(static_cast<char *>(p) + u.offset, u.data.constData(), u.data.size());
+ memcpy(static_cast<char *>(p) + u.offset, u.data.constData(), size_t(u.data.size()));
if (changeBegin == -1 || u.offset < changeBegin)
changeBegin = u.offset;
if (changeEnd == -1 || u.offset + u.data.size() > changeEnd)
changeEnd = u.offset + u.data.size();
}
if (changeBegin >= 0 && bufD->d->managed)
- [bufD->d->buf[idx] didModifyRange: NSMakeRange(changeBegin, changeEnd - changeBegin)];
+ [bufD->d->buf[idx] didModifyRange: NSMakeRange(NSUInteger(changeBegin), NSUInteger(changeEnd - changeBegin))];
updates.clear();
}
@@ -1728,7 +1794,7 @@ void QRhiMetal::beginPass(QRhiCommandBuffer *cb,
rtD = rtTex->d;
cbD->d->currentPassRpDesc = d->createDefaultRenderPass(rtD->dsAttCount, colorClearValue, depthStencilClearValue, rtD->colorAttCount);
if (rtTex->m_flags.testFlag(QRhiTextureRenderTarget::PreserveColorContents)) {
- for (int i = 0; i < rtD->colorAttCount; ++i)
+ for (uint i = 0; i < uint(rtD->colorAttCount); ++i)
cbD->d->currentPassRpDesc.colorAttachments[i].loadAction = MTLLoadActionLoad;
}
if (rtD->dsAttCount && rtTex->m_flags.testFlag(QRhiTextureRenderTarget::PreserveDepthStencilContents)) {
@@ -1755,15 +1821,15 @@ void QRhiMetal::beginPass(QRhiCommandBuffer *cb,
break;
}
- for (int i = 0; i < rtD->colorAttCount; ++i) {
+ for (uint i = 0; i < uint(rtD->colorAttCount); ++i) {
cbD->d->currentPassRpDesc.colorAttachments[i].texture = rtD->fb.colorAtt[i].tex;
- cbD->d->currentPassRpDesc.colorAttachments[i].slice = rtD->fb.colorAtt[i].layer;
- cbD->d->currentPassRpDesc.colorAttachments[i].level = rtD->fb.colorAtt[i].level;
+ cbD->d->currentPassRpDesc.colorAttachments[i].slice = NSUInteger(rtD->fb.colorAtt[i].layer);
+ cbD->d->currentPassRpDesc.colorAttachments[i].level = NSUInteger(rtD->fb.colorAtt[i].level);
if (rtD->fb.colorAtt[i].resolveTex) {
cbD->d->currentPassRpDesc.colorAttachments[i].storeAction = MTLStoreActionMultisampleResolve;
cbD->d->currentPassRpDesc.colorAttachments[i].resolveTexture = rtD->fb.colorAtt[i].resolveTex;
- cbD->d->currentPassRpDesc.colorAttachments[i].resolveSlice = rtD->fb.colorAtt[i].resolveLayer;
- cbD->d->currentPassRpDesc.colorAttachments[i].resolveLevel = rtD->fb.colorAtt[i].resolveLevel;
+ cbD->d->currentPassRpDesc.colorAttachments[i].resolveSlice = NSUInteger(rtD->fb.colorAtt[i].resolveLayer);
+ cbD->d->currentPassRpDesc.colorAttachments[i].resolveLevel = NSUInteger(rtD->fb.colorAtt[i].resolveLevel);
}
}
@@ -1845,7 +1911,7 @@ void QRhiMetal::dispatch(QRhiCommandBuffer *cb, int x, int y, int z)
Q_ASSERT(cbD->recordingPass == QMetalCommandBuffer::ComputePass);
QMetalComputePipeline *psD = QRHI_RES(QMetalComputePipeline, cbD->currentComputePipeline);
- [cbD->d->currentComputePassEncoder dispatchThreadgroups: MTLSizeMake(x, y, z)
+ [cbD->d->currentComputePassEncoder dispatchThreadgroups: MTLSizeMake(NSUInteger(x), NSUInteger(y), NSUInteger(z))
threadsPerThreadgroup: psD->d->localSize];
}
@@ -1913,12 +1979,12 @@ void QRhiMetal::finishActiveReadbacks(bool forced)
if (forced || currentFrameSlot == aRb.activeFrameSlot || aRb.activeFrameSlot < 0) {
aRb.result->format = aRb.format;
aRb.result->pixelSize = aRb.pixelSize;
- aRb.result->data.resize(aRb.bufSize);
+ aRb.result->data.resize(int(aRb.bufSize));
void *p = [aRb.buf contents];
memcpy(aRb.result->data.data(), p, aRb.bufSize);
[aRb.buf release];
- QRHI_PROF_F(releaseReadbackBuffer(quint64(quintptr(aRb.buf))));
+ QRHI_PROF_F(releaseReadbackBuffer(qint64(qintptr(aRb.buf))));
if (aRb.result->completed)
completedCallbacks.append(aRb.result->completed);
@@ -1977,8 +2043,8 @@ bool QMetalBuffer::build()
return false;
}
- const int nonZeroSize = m_size <= 0 ? 256 : m_size;
- const int roundedSize = m_usage.testFlag(QRhiBuffer::UniformBuffer) ? aligned(nonZeroSize, 256) : nonZeroSize;
+ const uint nonZeroSize = m_size <= 0 ? 256 : uint(m_size);
+ const uint roundedSize = m_usage.testFlag(QRhiBuffer::UniformBuffer) ? aligned<uint>(nonZeroSize, 256) : nonZeroSize;
d->managed = false;
MTLResourceOptions opts = MTLResourceStorageModeShared;
@@ -2065,10 +2131,10 @@ bool QMetalRenderBuffer::build()
MTLTextureDescriptor *desc = [[MTLTextureDescriptor alloc] init];
desc.textureType = samples > 1 ? MTLTextureType2DMultisample : MTLTextureType2D;
- desc.width = m_pixelSize.width();
- desc.height = m_pixelSize.height();
+ desc.width = NSUInteger(m_pixelSize.width());
+ desc.height = NSUInteger(m_pixelSize.height());
if (samples > 1)
- desc.sampleCount = samples;
+ desc.sampleCount = NSUInteger(samples);
desc.resourceOptions = MTLResourceStorageModePrivate;
desc.usage = MTLTextureUsageRenderTarget;
@@ -2335,11 +2401,11 @@ bool QMetalTexture::build()
else
desc.textureType = samples > 1 ? MTLTextureType2DMultisample : MTLTextureType2D;
desc.pixelFormat = d->format;
- desc.width = size.width();
- desc.height = size.height();
- desc.mipmapLevelCount = mipLevelCount;
+ desc.width = NSUInteger(size.width());
+ desc.height = NSUInteger(size.height());
+ desc.mipmapLevelCount = NSUInteger(mipLevelCount);
if (samples > 1)
- desc.sampleCount = samples;
+ desc.sampleCount = NSUInteger(samples);
desc.resourceOptions = MTLResourceStorageModePrivate;
desc.storageMode = MTLStorageModePrivate;
desc.usage = MTLTextureUsageShaderRead;
@@ -2405,7 +2471,7 @@ id<MTLTexture> QMetalTextureData::viewForLevel(int level)
const MTLTextureType type = [tex textureType];
const bool isCube = q->m_flags.testFlag(QRhiTexture::CubeMap);
id<MTLTexture> view = [tex newTextureViewWithPixelFormat: format textureType: type
- levels: NSMakeRange(level, 1) slices: NSMakeRange(0, isCube ? 6 : 1)];
+ levels: NSMakeRange(NSUInteger(level), 1) slices: NSMakeRange(0, isCube ? 6 : 1)];
perLevelViews[level] = view;
return view;
@@ -2615,13 +2681,13 @@ QRhiRenderPassDescriptor *QMetalTextureRenderTarget::newCompatibleRenderPassDesc
for (int i = 0, ie = colorAttachments.count(); i != ie; ++i) {
QMetalTexture *texD = QRHI_RES(QMetalTexture, colorAttachments[i].texture());
QMetalRenderBuffer *rbD = QRHI_RES(QMetalRenderBuffer, colorAttachments[i].renderBuffer());
- rpD->colorFormat[i] = texD ? texD->d->format : rbD->d->format;
+ rpD->colorFormat[i] = int(texD ? texD->d->format : rbD->d->format);
}
if (m_desc.depthTexture())
- rpD->dsFormat = QRHI_RES(QMetalTexture, m_desc.depthTexture())->d->format;
+ rpD->dsFormat = int(QRHI_RES(QMetalTexture, m_desc.depthTexture())->d->format);
else if (m_desc.depthStencilBuffer())
- rpD->dsFormat = QRHI_RES(QMetalRenderBuffer, m_desc.depthStencilBuffer())->d->format;
+ rpD->dsFormat = int(QRHI_RES(QMetalRenderBuffer, m_desc.depthStencilBuffer())->d->format);
return rpD;
}
@@ -2810,36 +2876,17 @@ void QMetalGraphicsPipeline::release()
{
QRHI_RES_RHI(QRhiMetal);
- if (!d->ps)
- return;
-
- if (d->ps) {
- [d->ps release];
- d->ps = nil;
- }
+ d->vs.release();
+ d->fs.release();
- if (d->ds) {
- [d->ds release];
- d->ds = nil;
- }
+ [d->ds release];
+ d->ds = nil;
- if (d->vsFunc) {
- [d->vsFunc release];
- d->vsFunc = nil;
- }
- if (d->vsLib) {
- [d->vsLib release];
- d->vsLib = nil;
- }
+ if (!d->ps)
+ return;
- if (d->fsFunc) {
- [d->fsFunc release];
- d->fsFunc = nil;
- }
- if (d->fsLib) {
- [d->fsLib release];
- d->fsLib = nil;
- }
+ [d->ps release];
+ d->ps = nil;
rhiD->unregisterResource(this);
}
@@ -3040,7 +3087,7 @@ id<MTLLibrary> QRhiMetalData::createMetalLib(const QShader &shader, QShader::Var
QShaderCode mtllib = shader.shader({ QShader::MetalLibShader, 12, shaderVariant });
if (!mtllib.shader().isEmpty()) {
dispatch_data_t data = dispatch_data_create(mtllib.shader().constData(),
- mtllib.shader().size(),
+ size_t(mtllib.shader().size()),
dispatch_get_global_queue(0, 0),
DISPATCH_DATA_DESTRUCTOR_DEFAULT);
NSError *err = nil;
@@ -3100,19 +3147,19 @@ bool QMetalGraphicsPipeline::build()
MTLVertexDescriptor *inputLayout = [MTLVertexDescriptor vertexDescriptor];
const QVector<QRhiVertexInputAttribute> attributes = m_vertexInputLayout.attributes();
for (const QRhiVertexInputAttribute &attribute : attributes) {
- const int loc = attribute.location();
+ const uint loc = uint(attribute.location());
inputLayout.attributes[loc].format = toMetalAttributeFormat(attribute.format());
- inputLayout.attributes[loc].offset = attribute.offset();
- inputLayout.attributes[loc].bufferIndex = firstVertexBinding + attribute.binding();
+ inputLayout.attributes[loc].offset = NSUInteger(attribute.offset());
+ inputLayout.attributes[loc].bufferIndex = NSUInteger(firstVertexBinding + attribute.binding());
}
const QVector<QRhiVertexInputBinding> bindings = m_vertexInputLayout.bindings();
for (int i = 0, ie = bindings.count(); i != ie; ++i) {
const QRhiVertexInputBinding &binding(bindings[i]);
- const int layoutIdx = firstVertexBinding + i;
+ const uint layoutIdx = uint(firstVertexBinding + i);
inputLayout.layouts[layoutIdx].stepFunction =
binding.classification() == QRhiVertexInputBinding::PerInstance
? MTLVertexStepFunctionPerInstance : MTLVertexStepFunctionPerVertex;
- inputLayout.layouts[layoutIdx].stepRate = binding.instanceStepRate();
+ inputLayout.layouts[layoutIdx].stepRate = NSUInteger(binding.instanceStepRate());
inputLayout.layouts[layoutIdx].stride = binding.stride();
}
@@ -3126,34 +3173,66 @@ bool QMetalGraphicsPipeline::build()
// buffers not just the resource binding layout) so leave it at the default
for (const QRhiShaderStage &shaderStage : qAsConst(m_shaderStages)) {
- QString error;
- QByteArray entryPoint;
- id<MTLLibrary> lib = rhiD->d->createMetalLib(shaderStage.shader(), shaderStage.shaderVariant(), &error, &entryPoint);
- if (!lib) {
- qWarning("MSL shader compilation failed: %s", qPrintable(error));
- return false;
- }
- id<MTLFunction> func = rhiD->d->createMSLShaderFunction(lib, entryPoint);
- if (!func) {
- qWarning("MSL function for entry point %s not found", entryPoint.constData());
- [lib release];
- return false;
- }
- switch (shaderStage.type()) {
- case QRhiShaderStage::Vertex:
- rpDesc.vertexFunction = func;
- d->vsLib = lib;
- d->vsFunc = func;
- break;
- case QRhiShaderStage::Fragment:
- rpDesc.fragmentFunction = func;
- d->fsLib = lib;
- d->fsFunc = func;
- break;
- default:
- [func release];
- [lib release];
- break;
+ auto cacheIt = rhiD->d->shaderCache.constFind(shaderStage);
+ if (cacheIt != rhiD->d->shaderCache.constEnd()) {
+ switch (shaderStage.type()) {
+ case QRhiShaderStage::Vertex:
+ d->vs = *cacheIt;
+ [d->vs.lib retain];
+ [d->vs.func retain];
+ rpDesc.vertexFunction = d->vs.func;
+ break;
+ case QRhiShaderStage::Fragment:
+ d->fs = *cacheIt;
+ [d->fs.lib retain];
+ [d->fs.func retain];
+ rpDesc.fragmentFunction = d->fs.func;
+ break;
+ default:
+ break;
+ }
+ } else {
+ QString error;
+ QByteArray entryPoint;
+ id<MTLLibrary> lib = rhiD->d->createMetalLib(shaderStage.shader(), shaderStage.shaderVariant(), &error, &entryPoint);
+ if (!lib) {
+ qWarning("MSL shader compilation failed: %s", qPrintable(error));
+ return false;
+ }
+ id<MTLFunction> func = rhiD->d->createMSLShaderFunction(lib, entryPoint);
+ if (!func) {
+ qWarning("MSL function for entry point %s not found", entryPoint.constData());
+ [lib release];
+ return false;
+ }
+ if (rhiD->d->shaderCache.count() >= QRhiMetal::MAX_SHADER_CACHE_ENTRIES) {
+ // Use the simplest strategy: too many cached shaders -> drop them all.
+ for (QMetalShader &s : rhiD->d->shaderCache)
+ s.release();
+ rhiD->d->shaderCache.clear();
+ }
+ switch (shaderStage.type()) {
+ case QRhiShaderStage::Vertex:
+ d->vs.lib = lib;
+ d->vs.func = func;
+ rhiD->d->shaderCache.insert(shaderStage, d->vs);
+ [d->vs.lib retain];
+ [d->vs.func retain];
+ rpDesc.vertexFunction = func;
+ break;
+ case QRhiShaderStage::Fragment:
+ d->fs.lib = lib;
+ d->fs.func = func;
+ rhiD->d->shaderCache.insert(shaderStage, d->fs);
+ [d->fs.lib retain];
+ [d->fs.func retain];
+ rpDesc.fragmentFunction = func;
+ break;
+ default:
+ [func release];
+ [lib release];
+ break;
+ }
}
}
@@ -3168,8 +3247,8 @@ bool QMetalGraphicsPipeline::build()
Q_ASSERT(m_targetBlends.count() == rpD->colorAttachmentCount
|| (m_targetBlends.isEmpty() && rpD->colorAttachmentCount == 1));
- for (int i = 0, ie = m_targetBlends.count(); i != ie; ++i) {
- const QRhiGraphicsPipeline::TargetBlend &b(m_targetBlends[i]);
+ for (uint i = 0, ie = uint(m_targetBlends.count()); i != ie; ++i) {
+ const QRhiGraphicsPipeline::TargetBlend &b(m_targetBlends[int(i)]);
rpDesc.colorAttachments[i].pixelFormat = MTLPixelFormat(rpD->colorFormat[i]);
rpDesc.colorAttachments[i].blendingEnabled = b.enable;
rpDesc.colorAttachments[i].sourceRGBBlendFactor = toMetalBlendFactor(b.srcColor);
@@ -3191,7 +3270,7 @@ bool QMetalGraphicsPipeline::build()
rpDesc.stencilAttachmentPixelFormat = fmt;
}
- rpDesc.sampleCount = rhiD->effectiveSampleCount(m_sampleCount);
+ rpDesc.sampleCount = NSUInteger(rhiD->effectiveSampleCount(m_sampleCount));
NSError *err = nil;
d->ps = [rhiD->d->dev newRenderPipelineStateWithDescriptor: rpDesc error: &err];
@@ -3253,22 +3332,13 @@ void QMetalComputePipeline::release()
{
QRHI_RES_RHI(QRhiMetal);
- if (d->csFunc) {
- [d->csFunc release];
- d->csFunc = nil;
- }
- if (d->csLib) {
- [d->csLib release];
- d->csLib = nil;
- }
+ d->cs.release();
if (!d->ps)
return;
- if (d->ps) {
- [d->ps release];
- d->ps = nil;
- }
+ [d->ps release];
+ d->ps = nil;
rhiD->unregisterResource(this);
}
@@ -3280,28 +3350,44 @@ bool QMetalComputePipeline::build()
QRHI_RES_RHI(QRhiMetal);
- const QShader shader = m_shaderStage.shader();
- QString error;
- QByteArray entryPoint;
- id<MTLLibrary> lib = rhiD->d->createMetalLib(shader, m_shaderStage.shaderVariant(),
- &error, &entryPoint);
- if (!lib) {
- qWarning("MSL shader compilation failed: %s", qPrintable(error));
- return false;
- }
- id<MTLFunction> func = rhiD->d->createMSLShaderFunction(lib, entryPoint);
- if (!func) {
- qWarning("MSL function for entry point %s not found", entryPoint.constData());
- [lib release];
- return false;
+ auto cacheIt = rhiD->d->shaderCache.constFind(m_shaderStage);
+ if (cacheIt != rhiD->d->shaderCache.constEnd()) {
+ d->cs = *cacheIt;
+ } else {
+ const QShader shader = m_shaderStage.shader();
+ QString error;
+ QByteArray entryPoint;
+ id<MTLLibrary> lib = rhiD->d->createMetalLib(shader, m_shaderStage.shaderVariant(),
+ &error, &entryPoint);
+ if (!lib) {
+ qWarning("MSL shader compilation failed: %s", qPrintable(error));
+ return false;
+ }
+ id<MTLFunction> func = rhiD->d->createMSLShaderFunction(lib, entryPoint);
+ if (!func) {
+ qWarning("MSL function for entry point %s not found", entryPoint.constData());
+ [lib release];
+ return false;
+ }
+ d->cs.lib = lib;
+ d->cs.func = func;
+ d->cs.localSize = shader.description().computeShaderLocalSize();
+
+ if (rhiD->d->shaderCache.count() >= QRhiMetal::MAX_SHADER_CACHE_ENTRIES) {
+ for (QMetalShader &s : rhiD->d->shaderCache)
+ s.release();
+ rhiD->d->shaderCache.clear();
+ }
+ rhiD->d->shaderCache.insert(m_shaderStage, d->cs);
}
- d->csLib = lib;
- d->csFunc = func;
- std::array<uint, 3> localSize = shader.description().computeShaderLocalSize();
- d->localSize = MTLSizeMake(localSize[0], localSize[1], localSize[2]);
+
+ [d->cs.lib retain];
+ [d->cs.func retain];
+
+ d->localSize = MTLSizeMake(d->cs.localSize[0], d->cs.localSize[1], d->cs.localSize[2]);
NSError *err = nil;
- d->ps = [rhiD->d->dev newComputePipelineStateWithFunction: d->csFunc error: &err];
+ d->ps = [rhiD->d->dev newComputePipelineStateWithFunction: d->cs.func error: &err];
if (!d->ps) {
const QString msg = QString::fromNSString(err.localizedDescription);
qWarning("Failed to create render pipeline state: %s", qPrintable(msg));
@@ -3439,7 +3525,7 @@ QSize QMetalSwapChain::surfacePixelSize()
CAMetalLayer *layer = (CAMetalLayer *) [v layer];
if (layer) {
CGSize size = [layer drawableSize];
- return QSize(size.width, size.height);
+ return QSize(int(size.width), int(size.height));
}
}
return QSize();
@@ -3454,7 +3540,7 @@ QRhiRenderPassDescriptor *QMetalSwapChain::newCompatibleRenderPassDescriptor()
rpD->colorAttachmentCount = 1;
rpD->hasDepthStencil = m_depthStencil != nullptr;
- rpD->colorFormat[0] = d->colorFormat;
+ rpD->colorFormat[0] = int(d->colorFormat);
// m_depthStencil may not be built yet so cannot rely on computed fields in it
rpD->dsFormat = rhiD->d->dev.depth24Stencil8PixelFormatSupported
@@ -3511,6 +3597,18 @@ bool QMetalSwapChain::buildOrResize()
}
#endif
+ if (m_flags.testFlag(SurfaceHasPreMulAlpha)) {
+ d->layer.opaque = NO;
+ } else if (m_flags.testFlag(SurfaceHasNonPreMulAlpha)) {
+ // The CoreAnimation compositor is said to expect premultiplied alpha,
+ // so this is then wrong when it comes to the blending operations but
+ // there's nothing we can do. Fortunately Qt Quick always outputs
+ // premultiplied alpha so it is not a problem there.
+ d->layer.opaque = NO;
+ } else {
+ d->layer.opaque = YES;
+ }
+
m_currentPixelSize = surfacePixelSize();
pixelSize = m_currentPixelSize;
@@ -3538,7 +3636,7 @@ bool QMetalSwapChain::buildOrResize()
}
rtWrapper.d->pixelSize = pixelSize;
- rtWrapper.d->dpr = window->devicePixelRatio();
+ rtWrapper.d->dpr = float(window->devicePixelRatio());
rtWrapper.d->sampleCount = samples;
rtWrapper.d->colorAttCount = 1;
rtWrapper.d->dsAttCount = ds ? 1 : 0;
@@ -3549,9 +3647,9 @@ bool QMetalSwapChain::buildOrResize()
MTLTextureDescriptor *desc = [[MTLTextureDescriptor alloc] init];
desc.textureType = MTLTextureType2DMultisample;
desc.pixelFormat = d->colorFormat;
- desc.width = pixelSize.width();
- desc.height = pixelSize.height();
- desc.sampleCount = samples;
+ desc.width = NSUInteger(pixelSize.width());
+ desc.height = NSUInteger(pixelSize.height());
+ desc.sampleCount = NSUInteger(samples);
desc.resourceOptions = MTLResourceStorageModePrivate;
desc.storageMode = MTLStorageModePrivate;
desc.usage = MTLTextureUsageRenderTarget;
diff --git a/src/gui/rhi/qrhimetal_p_p.h b/src/gui/rhi/qrhimetal_p_p.h
index c448865f4d..a08f56072a 100644
--- a/src/gui/rhi/qrhimetal_p_p.h
+++ b/src/gui/rhi/qrhimetal_p_p.h
@@ -416,7 +416,9 @@ public:
int resourceLimit(QRhi::ResourceLimit limit) const override;
const QRhiNativeHandles *nativeHandles() override;
void sendVMemStatsToProfiler() override;
- void makeThreadLocalNativeContextCurrent() override;
+ bool makeThreadLocalNativeContextCurrent() override;
+ void releaseCachedResources() override;
+ bool isDeviceLost() const override;
void executeDeferredReleases(bool forced = false);
void finishActiveReadbacks(bool forced = false);
diff --git a/src/gui/rhi/qrhinull.cpp b/src/gui/rhi/qrhinull.cpp
index dff6e05268..60d620813b 100644
--- a/src/gui/rhi/qrhinull.cpp
+++ b/src/gui/rhi/qrhinull.cpp
@@ -169,11 +169,22 @@ void QRhiNull::sendVMemStatsToProfiler()
// nothing to do here
}
-void QRhiNull::makeThreadLocalNativeContextCurrent()
+bool QRhiNull::makeThreadLocalNativeContextCurrent()
+{
+ // not applicable
+ return false;
+}
+
+void QRhiNull::releaseCachedResources()
{
// nothing to do here
}
+bool QRhiNull::isDeviceLost() const
+{
+ return false;
+}
+
QRhiRenderBuffer *QRhiNull::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize,
int sampleCount, QRhiRenderBuffer::Flags flags)
{
diff --git a/src/gui/rhi/qrhinull_p_p.h b/src/gui/rhi/qrhinull_p_p.h
index bdf0d59724..ee301d247b 100644
--- a/src/gui/rhi/qrhinull_p_p.h
+++ b/src/gui/rhi/qrhinull_p_p.h
@@ -282,7 +282,9 @@ public:
int resourceLimit(QRhi::ResourceLimit limit) const override;
const QRhiNativeHandles *nativeHandles() override;
void sendVMemStatsToProfiler() override;
- void makeThreadLocalNativeContextCurrent() override;
+ bool makeThreadLocalNativeContextCurrent() override;
+ void releaseCachedResources() override;
+ bool isDeviceLost() const override;
QRhiNullNativeHandles nativeHandlesStruct;
QRhiSwapChain *currentSwapChain = nullptr;
diff --git a/src/gui/rhi/qrhiprofiler.cpp b/src/gui/rhi/qrhiprofiler.cpp
index e74e446a1c..1521c0f36e 100644
--- a/src/gui/rhi/qrhiprofiler.cpp
+++ b/src/gui/rhi/qrhiprofiler.cpp
@@ -319,7 +319,7 @@ void QRhiProfilerPrivate::writeFloat(const char *key, float f)
Q_ASSERT(key[0] == 'F');
buf.append(key);
buf.append(',');
- buf.append(QByteArray::number(f));
+ buf.append(QByteArray::number(double(f)));
buf.append(',');
}
@@ -385,7 +385,7 @@ void QRhiProfilerPrivate::newRenderBuffer(QRhiRenderBuffer *rb, bool transientBa
const QRhiTexture::Format assumedFormat = type == QRhiRenderBuffer::DepthStencil ? QRhiTexture::D32F : QRhiTexture::RGBA8;
quint32 byteSize = rhiDWhenEnabled->approxByteSizeForTexture(assumedFormat, sz, 1, 1);
if (sampleCount > 1)
- byteSize *= sampleCount;
+ byteSize *= uint(sampleCount);
startEntry(QRhiProfiler::NewRenderBuffer, ts.elapsed(), rb);
writeInt("type", type);
@@ -416,7 +416,7 @@ void QRhiProfilerPrivate::newTexture(QRhiTexture *tex, bool owns, int mipCount,
const QSize sz = tex->pixelSize();
quint32 byteSize = rhiDWhenEnabled->approxByteSizeForTexture(format, sz, mipCount, layerCount);
if (sampleCount > 1)
- byteSize *= sampleCount;
+ byteSize *= uint(sampleCount);
startEntry(QRhiProfiler::NewTexture, ts.elapsed(), tex);
writeInt("width", sz.width());
@@ -467,7 +467,7 @@ void QRhiProfilerPrivate::resizeSwapChain(QRhiSwapChain *sc, int bufferCount, in
const QSize sz = sc->currentPixelSize();
quint32 byteSize = rhiDWhenEnabled->approxByteSizeForTexture(QRhiTexture::BGRA8, sz, 1, 1);
- byteSize = byteSize * bufferCount + byteSize * msaaBufferCount * sampleCount;
+ byteSize = byteSize * uint(bufferCount) + byteSize * uint(msaaBufferCount) * uint(sampleCount);
startEntry(QRhiProfiler::ResizeSwapChain, ts.elapsed(), sc);
writeInt("width", sz.width());
@@ -569,7 +569,7 @@ void QRhiProfilerPrivate::swapChainFrameGpuTime(QRhiSwapChain *sc, float gpuTime
}
}
-void QRhiProfilerPrivate::newReadbackBuffer(quint64 id, QRhiResource *src, quint32 size)
+void QRhiProfilerPrivate::newReadbackBuffer(qint64 id, QRhiResource *src, quint32 size)
{
if (!outputDevice)
return;
@@ -580,7 +580,7 @@ void QRhiProfilerPrivate::newReadbackBuffer(quint64 id, QRhiResource *src, quint
endEntry();
}
-void QRhiProfilerPrivate::releaseReadbackBuffer(quint64 id)
+void QRhiProfilerPrivate::releaseReadbackBuffer(qint64 id)
{
if (!outputDevice)
return;
@@ -590,7 +590,7 @@ void QRhiProfilerPrivate::releaseReadbackBuffer(quint64 id)
endEntry();
}
-void QRhiProfilerPrivate::vmemStat(int realAllocCount, int subAllocCount, quint32 totalSize, quint32 unusedSize)
+void QRhiProfilerPrivate::vmemStat(uint realAllocCount, uint subAllocCount, quint32 totalSize, quint32 unusedSize)
{
if (!outputDevice)
return;
diff --git a/src/gui/rhi/qrhiprofiler_p_p.h b/src/gui/rhi/qrhiprofiler_p_p.h
index 49c6bd78ed..7d0f183fb1 100644
--- a/src/gui/rhi/qrhiprofiler_p_p.h
+++ b/src/gui/rhi/qrhiprofiler_p_p.h
@@ -79,10 +79,10 @@ public:
void endSwapChainFrame(QRhiSwapChain *sc, int frameCount);
void swapChainFrameGpuTime(QRhiSwapChain *sc, float gpuTimeMs);
- void newReadbackBuffer(quint64 id, QRhiResource *src, quint32 size);
- void releaseReadbackBuffer(quint64 id);
+ void newReadbackBuffer(qint64 id, QRhiResource *src, quint32 size);
+ void releaseReadbackBuffer(qint64 id);
- void vmemStat(int realAllocCount, int subAllocCount, quint32 totalSize, quint32 unusedSize);
+ void vmemStat(uint realAllocCount, uint subAllocCount, quint32 totalSize, quint32 unusedSize);
void startEntry(QRhiProfiler::StreamOp op, qint64 timestamp, QRhiResource *res);
void writeInt(const char *key, qint64 v);
diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp
index dfc85fb853..444c91dd75 100644
--- a/src/gui/rhi/qrhivulkan.cpp
+++ b/src/gui/rhi/qrhivulkan.cpp
@@ -211,7 +211,8 @@ QT_BEGIN_NAMESPACE
\brief Holds the Vulkan render pass object backing a QRhiRenderPassDescriptor.
*/
-static inline VkDeviceSize aligned(VkDeviceSize v, VkDeviceSize byteAlign)
+template <class Int>
+inline Int aligned(Int v, Int byteAlign)
{
return (v + byteAlign - 1) & ~(byteAlign - 1);
}
@@ -370,7 +371,7 @@ bool QRhiVulkan::create(QRhi::Flags flags)
auto queryQueueFamilyProps = [this, &queueFamilyProps] {
uint32_t queueCount = 0;
f->vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, nullptr);
- queueFamilyProps.resize(queueCount);
+ queueFamilyProps.resize(int(queueCount));
f->vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, queueFamilyProps.data());
};
@@ -387,22 +388,42 @@ bool QRhiVulkan::create(QRhi::Flags flags)
qWarning("Failed to enumerate physical devices: %d", err);
return false;
}
+
int physDevIndex = -1;
int requestedPhysDevIndex = -1;
if (qEnvironmentVariableIsSet("QT_VK_PHYSICAL_DEVICE_INDEX"))
requestedPhysDevIndex = qEnvironmentVariableIntValue("QT_VK_PHYSICAL_DEVICE_INDEX");
- for (uint32_t i = 0; i < physDevCount; ++i) {
+
+ if (requestedPhysDevIndex < 0 && flags.testFlag(QRhi::PreferSoftwareRenderer)) {
+ for (int i = 0; i < int(physDevCount); ++i) {
+ f->vkGetPhysicalDeviceProperties(physDevs[i], &physDevProperties);
+ if (physDevProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_CPU) {
+ requestedPhysDevIndex = i;
+ break;
+ }
+ }
+ }
+
+ for (int i = 0; i < int(physDevCount); ++i) {
f->vkGetPhysicalDeviceProperties(physDevs[i], &physDevProperties);
- qCDebug(QRHI_LOG_INFO, "Physical device %d: '%s' %d.%d.%d", i,
+ qCDebug(QRHI_LOG_INFO, "Physical device %d: '%s' %d.%d.%d (api %d.%d.%d vendor 0x%X device 0x%X type %d)",
+ i,
physDevProperties.deviceName,
VK_VERSION_MAJOR(physDevProperties.driverVersion),
VK_VERSION_MINOR(physDevProperties.driverVersion),
- VK_VERSION_PATCH(physDevProperties.driverVersion));
+ VK_VERSION_PATCH(physDevProperties.driverVersion),
+ VK_VERSION_MAJOR(physDevProperties.apiVersion),
+ VK_VERSION_MINOR(physDevProperties.apiVersion),
+ VK_VERSION_PATCH(physDevProperties.apiVersion),
+ physDevProperties.vendorID,
+ physDevProperties.deviceID,
+ physDevProperties.deviceType);
if (physDevIndex < 0 && (requestedPhysDevIndex < 0 || requestedPhysDevIndex == int(i))) {
physDevIndex = i;
qCDebug(QRHI_LOG_INFO, " using this physical device");
}
}
+
if (physDevIndex < 0) {
qWarning("No matching physical device");
return false;
@@ -423,7 +444,7 @@ bool QRhiVulkan::create(QRhi::Flags flags)
i, queueFamilyProps[i].queueFlags, queueFamilyProps[i].queueCount);
if (gfxQueueFamilyIdx == -1
&& (queueFamilyProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
- && (!maybeWindow || inst->supportsPresent(physDev, i, maybeWindow)))
+ && (!maybeWindow || inst->supportsPresent(physDev, uint32_t(i), maybeWindow)))
{
if (queueFamilyProps[i].queueFlags & VK_QUEUE_COMPUTE_BIT)
gfxQueueFamilyIdx = i;
@@ -444,7 +465,7 @@ bool QRhiVulkan::create(QRhi::Flags flags)
const float prio[] = { 0 };
memset(queueInfo, 0, sizeof(queueInfo));
queueInfo[0].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
- queueInfo[0].queueFamilyIndex = gfxQueueFamilyIdx;
+ queueInfo[0].queueFamilyIndex = uint32_t(gfxQueueFamilyIdx);
queueInfo[0].queueCount = 1;
queueInfo[0].pQueuePriorities = prio;
@@ -480,9 +501,9 @@ bool QRhiVulkan::create(QRhi::Flags flags)
devInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
devInfo.queueCreateInfoCount = 1;
devInfo.pQueueCreateInfos = queueInfo;
- devInfo.enabledLayerCount = devLayers.count();
+ devInfo.enabledLayerCount = uint32_t(devLayers.count());
devInfo.ppEnabledLayerNames = devLayers.constData();
- devInfo.enabledExtensionCount = requestedDevExts.count();
+ devInfo.enabledExtensionCount = uint32_t(requestedDevExts.count());
devInfo.ppEnabledExtensionNames = requestedDevExts.constData();
err = f->vkCreateDevice(physDev, &devInfo, nullptr, &dev);
@@ -498,7 +519,7 @@ bool QRhiVulkan::create(QRhi::Flags flags)
VkCommandPoolCreateInfo poolInfo;
memset(&poolInfo, 0, sizeof(poolInfo));
poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
- poolInfo.queueFamilyIndex = gfxQueueFamilyIdx;
+ poolInfo.queueFamilyIndex = uint32_t(gfxQueueFamilyIdx);
VkResult err = df->vkCreateCommandPool(dev, &poolInfo, nullptr, &cmdPool);
if (err != VK_SUCCESS) {
qWarning("Failed to create command pool: %d", err);
@@ -508,7 +529,7 @@ bool QRhiVulkan::create(QRhi::Flags flags)
if (gfxQueueFamilyIdx != -1) {
if (!gfxQueue)
- df->vkGetDeviceQueue(dev, gfxQueueFamilyIdx, 0, &gfxQueue);
+ df->vkGetDeviceQueue(dev, uint32_t(gfxQueueFamilyIdx), 0, &gfxQueue);
if (queueFamilyProps.isEmpty())
queryQueueFamilyProps();
@@ -588,6 +609,8 @@ bool QRhiVulkan::create(QRhi::Flags flags)
vkDebugMarkerSetObjectName = reinterpret_cast<PFN_vkDebugMarkerSetObjectNameEXT>(f->vkGetDeviceProcAddr(dev, "vkDebugMarkerSetObjectNameEXT"));
}
+ deviceLost = false;
+
nativeHandlesStruct.physDev = physDev;
nativeHandlesStruct.dev = dev;
nativeHandlesStruct.gfxQueueFamilyIdx = gfxQueueFamilyIdx;
@@ -603,7 +626,8 @@ void QRhiVulkan::destroy()
if (!df)
return;
- df->vkDeviceWaitIdle(dev);
+ if (!deviceLost)
+ df->vkDeviceWaitIdle(dev);
executeDeferredReleases(true);
finishActiveReadbacks(true);
@@ -691,7 +715,7 @@ bool QRhiVulkan::allocateDescriptorSet(VkDescriptorSetAllocateInfo *allocInfo, V
df->vkResetDescriptorPool(dev, descriptorPools[i].pool, 0);
descriptorPools[i].allocedDescSets = 0;
}
- if (descriptorPools[i].allocedDescSets + allocInfo->descriptorSetCount <= QVK_DESC_SETS_PER_POOL) {
+ if (descriptorPools[i].allocedDescSets + int(allocInfo->descriptorSetCount) <= QVK_DESC_SETS_PER_POOL) {
VkResult err = tryAllocate(i);
if (err == VK_SUCCESS) {
descriptorPools[i].allocedDescSets += allocInfo->descriptorSetCount;
@@ -901,8 +925,8 @@ bool QRhiVulkan::createTransientImage(VkFormat format,
imgInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imgInfo.imageType = VK_IMAGE_TYPE_2D;
imgInfo.format = format;
- imgInfo.extent.width = pixelSize.width();
- imgInfo.extent.height = pixelSize.height();
+ imgInfo.extent.width = uint32_t(pixelSize.width());
+ imgInfo.extent.height = uint32_t(pixelSize.height());
imgInfo.extent.depth = 1;
imgInfo.mipLevels = imgInfo.arrayLayers = 1;
imgInfo.samples = samples;
@@ -925,7 +949,7 @@ bool QRhiVulkan::createTransientImage(VkFormat format,
VkMemoryAllocateInfo memInfo;
memset(&memInfo, 0, sizeof(memInfo));
memInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
- memInfo.allocationSize = aligned(memReq.size, memReq.alignment) * count;
+ memInfo.allocationSize = aligned(memReq.size, memReq.alignment) * VkDeviceSize(count);
uint32_t startIndex = 0;
do {
@@ -1175,7 +1199,7 @@ bool QRhiVulkan::createOffscreenRenderPass(VkRenderPass *rp,
VkSubpassDescription subpassDesc;
memset(&subpassDesc, 0, sizeof(subpassDesc));
subpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
- subpassDesc.colorAttachmentCount = colorRefs.count();
+ subpassDesc.colorAttachmentCount = uint32_t(colorRefs.count());
Q_ASSERT(colorRefs.count() == resolveRefs.count());
subpassDesc.pColorAttachments = !colorRefs.isEmpty() ? colorRefs.constData() : nullptr;
subpassDesc.pDepthStencilAttachment = hasDepthStencil ? &dsRef : nullptr;
@@ -1184,7 +1208,7 @@ bool QRhiVulkan::createOffscreenRenderPass(VkRenderPass *rp,
VkRenderPassCreateInfo rpInfo;
memset(&rpInfo, 0, sizeof(rpInfo));
rpInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
- rpInfo.attachmentCount = attDescs.count();
+ rpInfo.attachmentCount = uint32_t(attDescs.count());
rpInfo.pAttachments = attDescs.constData();
rpInfo.subpassCount = 1;
rpInfo.pSubpasses = &subpassDesc;
@@ -1325,7 +1349,7 @@ bool QRhiVulkan::recreateSwapChain(QRhiSwapChain *swapChain)
}
if (actualSwapChainBufferCount != reqBufferCount)
qCDebug(QRHI_LOG_INFO, "Actual swapchain buffer count is %u", actualSwapChainBufferCount);
- swapChainD->bufferCount = actualSwapChainBufferCount;
+ swapChainD->bufferCount = int(actualSwapChainBufferCount);
VkImage swapChainImages[QVkSwapChain::MAX_BUFFER_COUNT];
err = vkGetSwapchainImagesKHR(dev, swapChainD->sc, &actualSwapChainBufferCount, swapChainImages);
@@ -1424,7 +1448,8 @@ void QRhiVulkan::releaseSwapChainResources(QRhiSwapChain *swapChain)
if (swapChainD->sc == VK_NULL_HANDLE)
return;
- df->vkDeviceWaitIdle(dev);
+ if (!deviceLost)
+ df->vkDeviceWaitIdle(dev);
for (int i = 0; i < QVK_FRAMES_IN_FLIGHT; ++i) {
QVkSwapChain::FrameResources &frame(swapChainD->frameRes[i]);
@@ -1487,15 +1512,6 @@ void QRhiVulkan::releaseSwapChainResources(QRhiSwapChain *swapChain)
// NB! surface and similar must remain intact
}
-static inline bool checkDeviceLost(VkResult err)
-{
- if (err == VK_ERROR_DEVICE_LOST) {
- qWarning("Device lost");
- return true;
- }
- return false;
-}
-
QRhi::FrameOpResult QRhiVulkan::beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags)
{
QVkSwapChain *swapChainD = QRHI_RES(QVkSwapChain, swapChain);
@@ -1522,10 +1538,12 @@ QRhi::FrameOpResult QRhiVulkan::beginFrame(QRhiSwapChain *swapChain, QRhi::Begin
} else if (err == VK_ERROR_OUT_OF_DATE_KHR) {
return QRhi::FrameOpSwapChainOutOfDate;
} else {
- if (checkDeviceLost(err))
+ if (err == VK_ERROR_DEVICE_LOST) {
+ qWarning("Device loss detected in vkAcquireNextImageKHR()");
+ deviceLost = true;
return QRhi::FrameOpDeviceLost;
- else
- qWarning("Failed to acquire next swapchain image: %d", err);
+ }
+ qWarning("Failed to acquire next swapchain image: %d", err);
return QRhi::FrameOpError;
}
}
@@ -1540,12 +1558,12 @@ QRhi::FrameOpResult QRhiVulkan::beginFrame(QRhiSwapChain *swapChain, QRhi::Begin
// will make B wait for A's frame 0 commands, so if a resource is written
// in B's frame or when B checks for pending resource releases, that won't
// mess up A's in-flight commands (as they are not in flight anymore).
- waitCommandCompletion(swapChainD->currentFrameSlot);
+ waitCommandCompletion(int(swapChainD->currentFrameSlot));
// Now is the time to read the timestamps for the previous frame for this slot.
if (frame.timestampQueryIndex >= 0) {
quint64 timestamp[2] = { 0, 0 };
- VkResult err = df->vkGetQueryPoolResults(dev, timestampQueryPool, frame.timestampQueryIndex, 2,
+ VkResult err = df->vkGetQueryPoolResults(dev, timestampQueryPool, uint32_t(frame.timestampQueryIndex), 2,
2 * sizeof(quint64), timestamp, sizeof(quint64),
VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT);
timestampQueryPoolMap.clearBit(frame.timestampQueryIndex / 2);
@@ -1585,10 +1603,10 @@ QRhi::FrameOpResult QRhiVulkan::beginFrame(QRhiSwapChain *swapChain, QRhi::Begin
}
}
if (timestampQueryIdx >= 0) {
- df->vkCmdResetQueryPool(frame.cmdBuf, timestampQueryPool, timestampQueryIdx, 2);
+ df->vkCmdResetQueryPool(frame.cmdBuf, timestampQueryPool, uint32_t(timestampQueryIdx), 2);
// record timestamp at the start of the command buffer
df->vkCmdWriteTimestamp(frame.cmdBuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
- timestampQueryPool, timestampQueryIdx);
+ timestampQueryPool, uint32_t(timestampQueryIdx));
frame.timestampQueryIndex = timestampQueryIdx;
}
@@ -1598,7 +1616,7 @@ QRhi::FrameOpResult QRhiVulkan::beginFrame(QRhiSwapChain *swapChain, QRhi::Begin
QVkSwapChain::ImageResources &image(swapChainD->imageRes[swapChainD->currentImageIndex]);
swapChainD->rtWrapper.d.fb = image.fb;
- currentFrameSlot = swapChainD->currentFrameSlot;
+ currentFrameSlot = int(swapChainD->currentFrameSlot);
currentSwapChain = swapChainD;
if (swapChainD->ds)
swapChainD->ds->lastActiveFrameSlot = currentFrameSlot;
@@ -1653,7 +1671,7 @@ QRhi::FrameOpResult QRhiVulkan::endFrame(QRhiSwapChain *swapChain, QRhi::EndFram
// record another timestamp, when enabled
if (frame.timestampQueryIndex >= 0) {
df->vkCmdWriteTimestamp(frame.cmdBuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
- timestampQueryPool, frame.timestampQueryIndex + 1);
+ timestampQueryPool, uint32_t(frame.timestampQueryIndex + 1));
}
// stop recording and submit to the queue
@@ -1689,10 +1707,12 @@ QRhi::FrameOpResult QRhiVulkan::endFrame(QRhiSwapChain *swapChain, QRhi::EndFram
if (err == VK_ERROR_OUT_OF_DATE_KHR) {
return QRhi::FrameOpSwapChainOutOfDate;
} else if (err != VK_SUBOPTIMAL_KHR) {
- if (checkDeviceLost(err))
+ if (err == VK_ERROR_DEVICE_LOST) {
+ qWarning("Device loss detected in vkQueuePresentKHR()");
+ deviceLost = true;
return QRhi::FrameOpDeviceLost;
- else
- qWarning("Failed to present: %d", err);
+ }
+ qWarning("Failed to present: %d", err);
return QRhi::FrameOpError;
}
}
@@ -1749,10 +1769,12 @@ QRhi::FrameOpResult QRhiVulkan::startPrimaryCommandBuffer(VkCommandBuffer *cb)
VkResult err = df->vkAllocateCommandBuffers(dev, &cmdBufInfo, cb);
if (err != VK_SUCCESS) {
- if (checkDeviceLost(err))
+ if (err == VK_ERROR_DEVICE_LOST) {
+ qWarning("Device loss detected in vkAllocateCommandBuffers()");
+ deviceLost = true;
return QRhi::FrameOpDeviceLost;
- else
- qWarning("Failed to allocate frame command buffer: %d", err);
+ }
+ qWarning("Failed to allocate frame command buffer: %d", err);
return QRhi::FrameOpError;
}
@@ -1762,10 +1784,12 @@ QRhi::FrameOpResult QRhiVulkan::startPrimaryCommandBuffer(VkCommandBuffer *cb)
err = df->vkBeginCommandBuffer(*cb, &cmdBufBeginInfo);
if (err != VK_SUCCESS) {
- if (checkDeviceLost(err))
+ if (err == VK_ERROR_DEVICE_LOST) {
+ qWarning("Device loss detected in vkBeginCommandBuffer()");
+ deviceLost = true;
return QRhi::FrameOpDeviceLost;
- else
- qWarning("Failed to begin frame command buffer: %d", err);
+ }
+ qWarning("Failed to begin frame command buffer: %d", err);
return QRhi::FrameOpError;
}
@@ -1777,10 +1801,12 @@ QRhi::FrameOpResult QRhiVulkan::endAndSubmitPrimaryCommandBuffer(VkCommandBuffer
{
VkResult err = df->vkEndCommandBuffer(cb);
if (err != VK_SUCCESS) {
- if (checkDeviceLost(err))
+ if (err == VK_ERROR_DEVICE_LOST) {
+ qWarning("Device loss detected in vkEndCommandBuffer()");
+ deviceLost = true;
return QRhi::FrameOpDeviceLost;
- else
- qWarning("Failed to end frame command buffer: %d", err);
+ }
+ qWarning("Failed to end frame command buffer: %d", err);
return QRhi::FrameOpError;
}
@@ -1802,10 +1828,12 @@ QRhi::FrameOpResult QRhiVulkan::endAndSubmitPrimaryCommandBuffer(VkCommandBuffer
err = df->vkQueueSubmit(gfxQueue, 1, &submitInfo, cmdFence);
if (err != VK_SUCCESS) {
- if (checkDeviceLost(err))
+ if (err == VK_ERROR_DEVICE_LOST) {
+ qWarning("Device loss detected in vkQueueSubmit()");
+ deviceLost = true;
return QRhi::FrameOpDeviceLost;
- else
- qWarning("Failed to submit to graphics queue: %d", err);
+ }
+ qWarning("Failed to submit to graphics queue: %d", err);
return QRhi::FrameOpError;
}
@@ -1932,8 +1960,8 @@ static inline QRhiPassResourceTracker::UsageState toPassTrackerUsageState(const
{
QRhiPassResourceTracker::UsageState u;
u.layout = 0; // unused with buffers
- u.access = bufUsage.access;
- u.stage = bufUsage.stage;
+ u.access = int(bufUsage.access);
+ u.stage = int(bufUsage.stage);
return u;
}
@@ -1941,8 +1969,8 @@ static inline QRhiPassResourceTracker::UsageState toPassTrackerUsageState(const
{
QRhiPassResourceTracker::UsageState u;
u.layout = texUsage.layout;
- u.access = texUsage.access;
- u.stage = texUsage.stage;
+ u.access = int(texUsage.access);
+ u.stage = int(texUsage.stage);
return u;
}
@@ -2106,8 +2134,8 @@ void QRhiVulkan::beginPass(QRhiCommandBuffer *cb,
rpBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
rpBeginInfo.renderPass = rtD->rp->rp;
rpBeginInfo.framebuffer = rtD->fb;
- rpBeginInfo.renderArea.extent.width = rtD->pixelSize.width();
- rpBeginInfo.renderArea.extent.height = rtD->pixelSize.height();
+ rpBeginInfo.renderArea.extent.width = uint32_t(rtD->pixelSize.width());
+ rpBeginInfo.renderArea.extent.height = uint32_t(rtD->pixelSize.height());
QVarLengthArray<VkClearValue, 4> cvs;
for (int i = 0; i < rtD->colorAttCount; ++i) {
@@ -2127,7 +2155,7 @@ void QRhiVulkan::beginPass(QRhiCommandBuffer *cb,
float(colorClearValue.alphaF()) } };
cvs.append(cv);
}
- rpBeginInfo.clearValueCount = cvs.count();
+ rpBeginInfo.clearValueCount = uint32_t(cvs.count());
QVkCommandBuffer::Command cmd;
cmd.cmd = QVkCommandBuffer::Command::BeginRenderPass;
@@ -2229,7 +2257,7 @@ void QRhiVulkan::dispatch(QRhiCommandBuffer *cb, int x, int y, int z)
Q_ASSERT(cbD->recordingPass == QVkCommandBuffer::ComputePass);
if (cbD->useSecondaryCb) {
- df->vkCmdDispatch(cbD->secondaryCbs.last(), x, y, z);
+ df->vkCmdDispatch(cbD->secondaryCbs.last(), uint32_t(x), uint32_t(y), uint32_t(z));
} else {
QVkCommandBuffer::Command cmd;
cmd.cmd = QVkCommandBuffer::Command::Dispatch;
@@ -2245,7 +2273,7 @@ VkShaderModule QRhiVulkan::createShader(const QByteArray &spirv)
VkShaderModuleCreateInfo shaderInfo;
memset(&shaderInfo, 0, sizeof(shaderInfo));
shaderInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
- shaderInfo.codeSize = spirv.size();
+ shaderInfo.codeSize = size_t(spirv.size());
shaderInfo.pCode = reinterpret_cast<const quint32 *>(spirv.constData());
VkShaderModule shaderModule;
VkResult err = df->vkCreateShaderModule(dev, &shaderInfo, nullptr, &shaderModule);
@@ -2292,7 +2320,7 @@ void QRhiVulkan::updateShaderResourceBindings(QRhiShaderResourceBindings *srb, i
memset(&writeInfo, 0, sizeof(writeInfo));
writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
writeInfo.dstSet = srbD->descSets[frameSlot];
- writeInfo.dstBinding = b->binding;
+ writeInfo.dstBinding = uint32_t(b->binding);
writeInfo.descriptorCount = 1;
switch (b->type) {
@@ -2306,8 +2334,8 @@ void QRhiVulkan::updateShaderResourceBindings(QRhiShaderResourceBindings *srb, i
bd.ubuf.generation = bufD->generation;
VkDescriptorBufferInfo bufInfo;
bufInfo.buffer = bufD->m_type == QRhiBuffer::Dynamic ? bufD->buffers[frameSlot] : bufD->buffers[0];
- bufInfo.offset = b->u.ubuf.offset;
- bufInfo.range = b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size;
+ bufInfo.offset = VkDeviceSize(b->u.ubuf.offset);
+ bufInfo.range = VkDeviceSize(b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size);
// be nice and assert when we know the vulkan device would die a horrible death due to non-aligned reads
Q_ASSERT(aligned(bufInfo.offset, ubufAlign) == bufInfo.offset);
bufferInfos.append(bufInfo);
@@ -2364,8 +2392,8 @@ void QRhiVulkan::updateShaderResourceBindings(QRhiShaderResourceBindings *srb, i
bd.sbuf.generation = bufD->generation;
VkDescriptorBufferInfo bufInfo;
bufInfo.buffer = bufD->m_type == QRhiBuffer::Dynamic ? bufD->buffers[frameSlot] : bufD->buffers[0];
- bufInfo.offset = b->u.ubuf.offset;
- bufInfo.range = b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size;
+ bufInfo.offset = VkDeviceSize(b->u.ubuf.offset);
+ bufInfo.range = VkDeviceSize(b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size);
bufferInfos.append(bufInfo);
writeInfo.pBufferInfo = &bufferInfos.last();
}
@@ -2379,7 +2407,7 @@ void QRhiVulkan::updateShaderResourceBindings(QRhiShaderResourceBindings *srb, i
++frameSlot;
}
- df->vkUpdateDescriptorSets(dev, writeInfos.count(), writeInfos.constData(), 0, nullptr);
+ df->vkUpdateDescriptorSets(dev, uint32_t(writeInfos.count()), writeInfos.constData(), 0, nullptr);
}
static inline bool accessIsWrite(VkAccessFlags access)
@@ -2487,10 +2515,10 @@ void QRhiVulkan::subresourceBarrier(QVkCommandBuffer *cbD, VkImage image,
memset(&barrier, 0, sizeof(barrier));
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- barrier.subresourceRange.baseMipLevel = startLevel;
- barrier.subresourceRange.levelCount = levelCount;
- barrier.subresourceRange.baseArrayLayer = startLayer;
- barrier.subresourceRange.layerCount = layerCount;
+ barrier.subresourceRange.baseMipLevel = uint32_t(startLevel);
+ barrier.subresourceRange.levelCount = uint32_t(levelCount);
+ barrier.subresourceRange.baseArrayLayer = uint32_t(startLayer);
+ barrier.subresourceRange.layerCount = uint32_t(layerCount);
barrier.oldLayout = oldLayout;
barrier.newLayout = newLayout;
barrier.srcAccessMask = srcAccess;
@@ -2511,7 +2539,7 @@ VkDeviceSize QRhiVulkan::subresUploadByteSize(const QRhiTextureSubresourceUpload
const qsizetype imageSizeBytes = subresDesc.image().isNull() ?
subresDesc.data().size() : subresDesc.image().sizeInBytes();
if (imageSizeBytes > 0)
- size += aligned(imageSizeBytes, texbufAlign);
+ size += aligned(VkDeviceSize(imageSizeBytes), texbufAlign);
return size;
}
@@ -2528,8 +2556,8 @@ void QRhiVulkan::prepareUploadSubres(QVkTexture *texD, int layer, int level,
memset(&copyInfo, 0, sizeof(copyInfo));
copyInfo.bufferOffset = *curOfs;
copyInfo.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- copyInfo.imageSubresource.mipLevel = level;
- copyInfo.imageSubresource.baseArrayLayer = layer;
+ copyInfo.imageSubresource.mipLevel = uint32_t(level);
+ copyInfo.imageSubresource.baseArrayLayer = uint32_t(layer);
copyInfo.imageSubresource.layerCount = 1;
copyInfo.imageExtent.depth = 1;
@@ -2544,7 +2572,7 @@ void QRhiVulkan::prepareUploadSubres(QVkTexture *texD, int layer, int level,
// be taken into account for bufferRowLength.
int bpc = qMax(1, image.depth() / 8);
// this is in pixels, not bytes, to make it more complicated...
- copyInfo.bufferRowLength = image.bytesPerLine() / bpc;
+ copyInfo.bufferRowLength = uint32_t(image.bytesPerLine() / bpc);
if (!subresDesc.sourceSize().isEmpty() || !subresDesc.sourceTopLeft().isNull()) {
const int sx = subresDesc.sourceTopLeft().x();
const int sy = subresDesc.sourceTopLeft().y();
@@ -2554,7 +2582,7 @@ void QRhiVulkan::prepareUploadSubres(QVkTexture *texD, int layer, int level,
// The staging buffer will get the full image
// regardless, just adjust the vk
// buffer-to-image copy start offset.
- copyInfo.bufferOffset += sy * image.bytesPerLine() + sx * 4;
+ copyInfo.bufferOffset += VkDeviceSize(sy * image.bytesPerLine() + sx * 4);
// bufferRowLength remains set to the original image's width
} else {
image = image.copy(sx, sy, size.width(), size.height());
@@ -2563,13 +2591,13 @@ void QRhiVulkan::prepareUploadSubres(QVkTexture *texD, int layer, int level,
// space reserved for this mip will be unused.
copySizeBytes = image.sizeInBytes();
bpc = qMax(1, image.depth() / 8);
- copyInfo.bufferRowLength = image.bytesPerLine() / bpc;
+ copyInfo.bufferRowLength = uint32_t(image.bytesPerLine() / bpc);
}
}
copyInfo.imageOffset.x = dp.x();
copyInfo.imageOffset.y = dp.y();
- copyInfo.imageExtent.width = size.width();
- copyInfo.imageExtent.height = size.height();
+ copyInfo.imageExtent.width = uint32_t(size.width());
+ copyInfo.imageExtent.height = uint32_t(size.height());
copyInfos->append(copyInfo);
} else if (!rawData.isEmpty() && isCompressedFormat(texD->m_format)) {
copySizeBytes = imageSizeBytes = rawData.size();
@@ -2588,8 +2616,8 @@ void QRhiVulkan::prepareUploadSubres(QVkTexture *texD, int layer, int level,
copyInfo.imageOffset.y = aligned(dp.y(), blockDim.height());
// width and height must be multiples of the block width and height
// or x + width and y + height must equal the subresource width and height
- copyInfo.imageExtent.width = dp.x() + w == subresw ? w : aligned(w, blockDim.width());
- copyInfo.imageExtent.height = dp.y() + h == subresh ? h : aligned(h, blockDim.height());
+ copyInfo.imageExtent.width = uint32_t(dp.x() + w == subresw ? w : aligned(w, blockDim.width()));
+ copyInfo.imageExtent.height = uint32_t(dp.y() + h == subresh ? h : aligned(h, blockDim.height()));
copyInfos->append(copyInfo);
} else if (!rawData.isEmpty()) {
copySizeBytes = imageSizeBytes = rawData.size();
@@ -2599,15 +2627,15 @@ void QRhiVulkan::prepareUploadSubres(QVkTexture *texD, int layer, int level,
size = subresDesc.sourceSize();
copyInfo.imageOffset.x = dp.x();
copyInfo.imageOffset.y = dp.y();
- copyInfo.imageExtent.width = size.width();
- copyInfo.imageExtent.height = size.height();
+ copyInfo.imageExtent.width = uint32_t(size.width());
+ copyInfo.imageExtent.height = uint32_t(size.height());
copyInfos->append(copyInfo);
} else {
qWarning("Invalid texture upload for %p layer=%d mip=%d", texD, layer, level);
}
- memcpy(reinterpret_cast<char *>(mp) + *curOfs, src, copySizeBytes);
- *curOfs += aligned(imageSizeBytes, texbufAlign);
+ memcpy(reinterpret_cast<char *>(mp) + *curOfs, src, size_t(copySizeBytes));
+ *curOfs += aligned(VkDeviceSize(imageSizeBytes), texbufAlign);
}
void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdateBatch *resourceUpdates)
@@ -2633,7 +2661,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
// must cover the entire buffer - this way multiple, partial updates per frame
// are supported even when the staging buffer is reused (Static)
- bufferInfo.size = bufD->m_size;
+ bufferInfo.size = VkDeviceSize(bufD->m_size);
bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
VmaAllocationCreateInfo allocInfo;
@@ -2645,7 +2673,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
&bufD->stagingBuffers[currentFrameSlot], &allocation, nullptr);
if (err == VK_SUCCESS) {
bufD->stagingAllocations[currentFrameSlot] = allocation;
- QRHI_PROF_F(newBufferStagingArea(bufD, currentFrameSlot, bufD->m_size));
+ QRHI_PROF_F(newBufferStagingArea(bufD, currentFrameSlot, quint32(bufD->m_size)));
} else {
qWarning("Failed to create staging buffer of size %d: %d", bufD->m_size, err);
continue;
@@ -2659,18 +2687,18 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
qWarning("Failed to map buffer: %d", err);
continue;
}
- memcpy(static_cast<uchar *>(p) + u.offset, u.data.constData(), u.data.size());
+ memcpy(static_cast<uchar *>(p) + u.offset, u.data.constData(), size_t(u.data.size()));
vmaUnmapMemory(toVmaAllocator(allocator), a);
- vmaFlushAllocation(toVmaAllocator(allocator), a, u.offset, u.data.size());
+ vmaFlushAllocation(toVmaAllocator(allocator), a, VkDeviceSize(u.offset), VkDeviceSize(u.data.size()));
trackedBufferBarrier(cbD, bufD, 0,
VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
VkBufferCopy copyInfo;
memset(&copyInfo, 0, sizeof(copyInfo));
- copyInfo.srcOffset = u.offset;
- copyInfo.dstOffset = u.offset;
- copyInfo.size = u.data.size();
+ copyInfo.srcOffset = VkDeviceSize(u.offset);
+ copyInfo.dstOffset = VkDeviceSize(u.offset);
+ copyInfo.size = VkDeviceSize(u.data.size());
QVkCommandBuffer::Command cmd;
cmd.cmd = QVkCommandBuffer::Command::CopyBuffer;
@@ -2732,7 +2760,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
continue;
}
utexD->stagingAllocations[currentFrameSlot] = allocation;
- QRHI_PROF_F(newTextureStagingArea(utexD, currentFrameSlot, stagingSize));
+ QRHI_PROF_F(newTextureStagingArea(utexD, currentFrameSlot, quint32(stagingSize)));
BufferImageCopyList copyInfos;
size_t curOfs = 0;
@@ -2799,24 +2827,24 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
memset(&region, 0, sizeof(region));
region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- region.srcSubresource.mipLevel = u.copy.desc.sourceLevel();
- region.srcSubresource.baseArrayLayer = u.copy.desc.sourceLayer();
+ region.srcSubresource.mipLevel = uint32_t(u.copy.desc.sourceLevel());
+ region.srcSubresource.baseArrayLayer = uint32_t(u.copy.desc.sourceLayer());
region.srcSubresource.layerCount = 1;
region.srcOffset.x = u.copy.desc.sourceTopLeft().x();
region.srcOffset.y = u.copy.desc.sourceTopLeft().y();
region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- region.dstSubresource.mipLevel = u.copy.desc.destinationLevel();
- region.dstSubresource.baseArrayLayer = u.copy.desc.destinationLayer();
+ region.dstSubresource.mipLevel = uint32_t(u.copy.desc.destinationLevel());
+ region.dstSubresource.baseArrayLayer = uint32_t(u.copy.desc.destinationLayer());
region.dstSubresource.layerCount = 1;
region.dstOffset.x = u.copy.desc.destinationTopLeft().x();
region.dstOffset.y = u.copy.desc.destinationTopLeft().y();
const QSize size = u.copy.desc.pixelSize().isEmpty() ? srcD->m_pixelSize : u.copy.desc.pixelSize();
- region.extent.width = size.width();
- region.extent.height = size.height();
+ region.extent.width = uint32_t(size.width());
+ region.extent.height = uint32_t(size.height());
region.extent.depth = 1;
trackedImageBarrier(cbD, srcD, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
@@ -2883,7 +2911,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
VkResult err = vmaCreateBuffer(toVmaAllocator(allocator), &bufferInfo, &allocInfo, &aRb.buf, &allocation, nullptr);
if (err == VK_SUCCESS) {
aRb.bufAlloc = allocation;
- QRHI_PROF_F(newReadbackBuffer(quint64(aRb.buf),
+ QRHI_PROF_F(newReadbackBuffer(qint64(aRb.buf),
texD ? static_cast<QRhiResource *>(texD) : static_cast<QRhiResource *>(swapChainD),
aRb.bufSize));
} else {
@@ -2896,11 +2924,11 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
memset(&copyDesc, 0, sizeof(copyDesc));
copyDesc.bufferOffset = 0;
copyDesc.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- copyDesc.imageSubresource.mipLevel = u.read.rb.level();
- copyDesc.imageSubresource.baseArrayLayer = u.read.rb.layer();
+ copyDesc.imageSubresource.mipLevel = uint32_t(u.read.rb.level());
+ copyDesc.imageSubresource.baseArrayLayer = uint32_t(u.read.rb.layer());
copyDesc.imageSubresource.layerCount = 1;
- copyDesc.imageExtent.width = aRb.pixelSize.width();
- copyDesc.imageExtent.height = aRb.pixelSize.height();
+ copyDesc.imageExtent.width = uint32_t(aRb.pixelSize.width());
+ copyDesc.imageExtent.height = uint32_t(aRb.pixelSize.height());
copyDesc.imageExtent.depth = 1;
if (texD) {
@@ -2953,7 +2981,7 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
if (!origStage)
origStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
- for (uint level = 1; level < utexD->mipLevelCount; ++level) {
+ for (int level = 1; level < int(utexD->mipLevelCount); ++level) {
if (level == 1) {
subresourceBarrier(cbD, utexD->image,
origLayout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
@@ -2981,8 +3009,8 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
memset(&region, 0, sizeof(region));
region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- region.srcSubresource.mipLevel = level - 1;
- region.srcSubresource.baseArrayLayer = u.mipgen.layer;
+ region.srcSubresource.mipLevel = uint32_t(level) - 1;
+ region.srcSubresource.baseArrayLayer = uint32_t(u.mipgen.layer);
region.srcSubresource.layerCount = 1;
region.srcOffsets[1].x = qMax(1, w);
@@ -2990,8 +3018,8 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
region.srcOffsets[1].z = 1;
region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- region.dstSubresource.mipLevel = level;
- region.dstSubresource.baseArrayLayer = u.mipgen.layer;
+ region.dstSubresource.mipLevel = uint32_t(level);
+ region.dstSubresource.baseArrayLayer = uint32_t(u.mipgen.layer);
region.dstSubresource.layerCount = 1;
region.dstOffsets[1].x = qMax(1, w >> 1);
@@ -3018,13 +3046,13 @@ void QRhiVulkan::enqueueResourceUpdates(QVkCommandBuffer *cbD, QRhiResourceUpdat
VK_ACCESS_TRANSFER_READ_BIT, origAccess,
VK_PIPELINE_STAGE_TRANSFER_BIT, origStage,
u.mipgen.layer, 1,
- 0, utexD->mipLevelCount - 1);
+ 0, int(utexD->mipLevelCount) - 1);
subresourceBarrier(cbD, utexD->image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, origLayout,
VK_ACCESS_TRANSFER_WRITE_BIT, origAccess,
VK_PIPELINE_STAGE_TRANSFER_BIT, origStage,
u.mipgen.layer, 1,
- utexD->mipLevelCount - 1, 1);
+ int(utexD->mipLevelCount) - 1, 1);
}
utexD->lastActiveFrameSlot = currentFrameSlot;
@@ -3055,7 +3083,7 @@ void QRhiVulkan::executeBufferHostWritesForCurrentFrame(QVkBuffer *bufD)
int changeEnd = -1;
for (const QRhiResourceUpdateBatchPrivate::DynamicBufferUpdate &u : updates) {
Q_ASSERT(bufD == QRHI_RES(QVkBuffer, u.buf));
- memcpy(static_cast<char *>(p) + u.offset, u.data.constData(), u.data.size());
+ memcpy(static_cast<char *>(p) + u.offset, u.data.constData(), size_t(u.data.size()));
if (changeBegin == -1 || u.offset < changeBegin)
changeBegin = u.offset;
if (changeEnd == -1 || u.offset + u.data.size() > changeEnd)
@@ -3063,7 +3091,7 @@ void QRhiVulkan::executeBufferHostWritesForCurrentFrame(QVkBuffer *bufD)
}
vmaUnmapMemory(toVmaAllocator(allocator), a);
if (changeBegin >= 0)
- vmaFlushAllocation(toVmaAllocator(allocator), a, changeBegin, changeEnd - changeBegin);
+ vmaFlushAllocation(toVmaAllocator(allocator), a, VkDeviceSize(changeBegin), VkDeviceSize(changeEnd - changeBegin));
updates.clear();
}
@@ -3164,7 +3192,7 @@ void QRhiVulkan::finishActiveReadbacks(bool forced)
if (forced || currentFrameSlot == aRb.activeFrameSlot || aRb.activeFrameSlot < 0) {
aRb.result->format = aRb.format;
aRb.result->pixelSize = aRb.pixelSize;
- aRb.result->data.resize(aRb.bufSize);
+ aRb.result->data.resize(int(aRb.bufSize));
void *p = nullptr;
VmaAllocation a = toVmaAllocation(aRb.bufAlloc);
VkResult err = vmaMapMemory(toVmaAllocator(allocator), a, &p);
@@ -3176,7 +3204,7 @@ void QRhiVulkan::finishActiveReadbacks(bool forced)
vmaUnmapMemory(toVmaAllocator(allocator), a);
vmaDestroyBuffer(toVmaAllocator(allocator), aRb.buf, a);
- QRHI_PROF_F(releaseReadbackBuffer(quint64(aRb.buf)));
+ QRHI_PROF_F(releaseReadbackBuffer(qint64(aRb.buf)));
if (aRb.result->completed)
completedCallbacks.append(aRb.result->completed);
@@ -3266,7 +3294,7 @@ void QRhiVulkan::recordPrimaryCommandBuffer(QVkCommandBuffer *cbD)
case QVkCommandBuffer::Command::CopyBufferToImage:
df->vkCmdCopyBufferToImage(cbD->cb, cmd.args.copyBufferToImage.src, cmd.args.copyBufferToImage.dst,
cmd.args.copyBufferToImage.dstLayout,
- cmd.args.copyBufferToImage.count,
+ uint32_t(cmd.args.copyBufferToImage.count),
cbD->pools.bufferImageCopy.constData() + cmd.args.copyBufferToImage.bufferImageCopyIndex);
break;
case QVkCommandBuffer::Command::CopyImage:
@@ -3315,13 +3343,13 @@ void QRhiVulkan::recordPrimaryCommandBuffer(QVkCommandBuffer *cbD)
df->vkCmdBindDescriptorSets(cbD->cb, cmd.args.bindDescriptorSet.bindPoint,
cmd.args.bindDescriptorSet.pipelineLayout,
0, 1, &cmd.args.bindDescriptorSet.descSet,
- cmd.args.bindDescriptorSet.dynamicOffsetCount,
+ uint32_t(cmd.args.bindDescriptorSet.dynamicOffsetCount),
offsets);
}
break;
case QVkCommandBuffer::Command::BindVertexBuffer:
- df->vkCmdBindVertexBuffers(cbD->cb, cmd.args.bindVertexBuffer.startBinding,
- cmd.args.bindVertexBuffer.count,
+ df->vkCmdBindVertexBuffers(cbD->cb, uint32_t(cmd.args.bindVertexBuffer.startBinding),
+ uint32_t(cmd.args.bindVertexBuffer.count),
cbD->pools.vertexBuffer.constData() + cmd.args.bindVertexBuffer.vertexBufferIndex,
cbD->pools.vertexBufferOffset.constData() + cmd.args.bindVertexBuffer.vertexBufferOffsetIndex);
break;
@@ -3367,7 +3395,7 @@ void QRhiVulkan::recordPrimaryCommandBuffer(QVkCommandBuffer *cbD)
recordTransitionPassResources(cbD, cbD->passResTrackers[cmd.args.transitionResources.trackerIndex]);
break;
case QVkCommandBuffer::Command::Dispatch:
- df->vkCmdDispatch(cbD->cb, cmd.args.dispatch.x, cmd.args.dispatch.y, cmd.args.dispatch.z);
+ df->vkCmdDispatch(cbD->cb, uint32_t(cmd.args.dispatch.x), uint32_t(cmd.args.dispatch.y), uint32_t(cmd.args.dispatch.z));
break;
case QVkCommandBuffer::Command::ExecuteSecondary:
df->vkCmdExecuteCommands(cbD->cb, 1, &cmd.args.executeSecondary.cb);
@@ -3421,8 +3449,8 @@ static inline VkPipelineStageFlags toVkPipelineStage(QRhiPassResourceTracker::Bu
static inline QVkBuffer::UsageState toVkBufferUsageState(QRhiPassResourceTracker::UsageState usage)
{
QVkBuffer::UsageState u;
- u.access = usage.access;
- u.stage = usage.stage;
+ u.access = VkAccessFlags(usage.access);
+ u.stage = VkPipelineStageFlags(usage.stage);
return u;
}
@@ -3494,8 +3522,8 @@ static inline QVkTexture::UsageState toVkTextureUsageState(QRhiPassResourceTrack
{
QVkTexture::UsageState u;
u.layout = VkImageLayout(usage.layout);
- u.access = usage.access;
- u.stage = usage.stage;
+ u.access = VkAccessFlags(usage.access);
+ u.stage = VkPipelineStageFlags(usage.stage);
return u;
}
@@ -3603,7 +3631,7 @@ QRhiBuffer *QRhiVulkan::createBuffer(QRhiBuffer::Type type, QRhiBuffer::UsageFla
int QRhiVulkan::ubufAlignment() const
{
- return ubufAlign; // typically 256 (bytes)
+ return int(ubufAlign); // typically 256 (bytes)
}
bool QRhiVulkan::isYUpInFramebuffer() const
@@ -3711,9 +3739,9 @@ int QRhiVulkan::resourceLimit(QRhi::ResourceLimit limit) const
case QRhi::TextureSizeMin:
return 1;
case QRhi::TextureSizeMax:
- return physDevProperties.limits.maxImageDimension2D;
+ return int(physDevProperties.limits.maxImageDimension2D);
case QRhi::MaxColorAttachments:
- return physDevProperties.limits.maxColorAttachments;
+ return int(physDevProperties.limits.maxColorAttachments);
case QRhi::FramesInFlight:
return QVK_FRAMES_IN_FLIGHT;
default:
@@ -3736,14 +3764,25 @@ void QRhiVulkan::sendVMemStatsToProfiler()
VmaStats stats;
vmaCalculateStats(toVmaAllocator(allocator), &stats);
QRHI_PROF_F(vmemStat(stats.total.blockCount, stats.total.allocationCount,
- stats.total.usedBytes, stats.total.unusedBytes));
+ quint32(stats.total.usedBytes), quint32(stats.total.unusedBytes)));
+}
+
+bool QRhiVulkan::makeThreadLocalNativeContextCurrent()
+{
+ // not applicable
+ return false;
}
-void QRhiVulkan::makeThreadLocalNativeContextCurrent()
+void QRhiVulkan::releaseCachedResources()
{
// nothing to do here
}
+bool QRhiVulkan::isDeviceLost() const
+{
+ return deviceLost;
+}
+
QRhiRenderBuffer *QRhiVulkan::createRenderBuffer(QRhiRenderBuffer::Type type, const QSize &pixelSize,
int sampleCount, QRhiRenderBuffer::Flags flags)
{
@@ -4003,7 +4042,7 @@ void QRhiVulkan::setShaderResources(QRhiCommandBuffer *cb, QRhiShaderResourceBin
gfxPsD ? VK_PIPELINE_BIND_POINT_GRAPHICS : VK_PIPELINE_BIND_POINT_COMPUTE,
gfxPsD ? gfxPsD->layout : compPsD->layout,
0, 1, &srbD->descSets[descSetIdx],
- dynOfs.count(),
+ uint32_t(dynOfs.count()),
dynOfs.count() ? dynOfs.constData() : nullptr);
} else {
QVkCommandBuffer::Command cmd;
@@ -4073,8 +4112,8 @@ void QRhiVulkan::setVertexInput(QRhiCommandBuffer *cb,
}
if (cbD->useSecondaryCb) {
- df->vkCmdBindVertexBuffers(cbD->secondaryCbs.last(), startBinding,
- bufs.count(), bufs.constData(), ofs.constData());
+ df->vkCmdBindVertexBuffers(cbD->secondaryCbs.last(), uint32_t(startBinding),
+ uint32_t(bufs.count()), bufs.constData(), ofs.constData());
} else {
QVkCommandBuffer::Command cmd;
cmd.cmd = QVkCommandBuffer::Command::BindVertexBuffer;
@@ -4155,10 +4194,10 @@ void QRhiVulkan::setViewport(QRhiCommandBuffer *cb, const QRhiViewport &viewport
if (!QRHI_RES(QVkGraphicsPipeline, cbD->currentGraphicsPipeline)->m_flags.testFlag(QRhiGraphicsPipeline::UsesScissor)) {
VkRect2D *s = &cmd.args.setScissor.scissor;
- s->offset.x = x;
- s->offset.y = y;
- s->extent.width = w;
- s->extent.height = h;
+ s->offset.x = int32_t(x);
+ s->offset.y = int32_t(y);
+ s->extent.width = uint32_t(w);
+ s->extent.height = uint32_t(h);
if (cbD->useSecondaryCb) {
df->vkCmdSetScissor(cbD->secondaryCbs.last(), 0, 1, s);
} else {
@@ -4184,8 +4223,8 @@ void QRhiVulkan::setScissor(QRhiCommandBuffer *cb, const QRhiScissor &scissor)
VkRect2D *s = &cmd.args.setScissor.scissor;
s->offset.x = x;
s->offset.y = y;
- s->extent.width = w;
- s->extent.height = h;
+ s->extent.width = uint32_t(w);
+ s->extent.height = uint32_t(h);
if (cbD->useSecondaryCb) {
df->vkCmdSetScissor(cbD->secondaryCbs.last(), 0, 1, s);
@@ -4206,10 +4245,10 @@ void QRhiVulkan::setBlendConstants(QRhiCommandBuffer *cb, const QColor &c)
} else {
QVkCommandBuffer::Command cmd;
cmd.cmd = QVkCommandBuffer::Command::SetBlendConstants;
- cmd.args.setBlendConstants.c[0] = c.redF();
- cmd.args.setBlendConstants.c[1] = c.greenF();
- cmd.args.setBlendConstants.c[2] = c.blueF();
- cmd.args.setBlendConstants.c[3] = c.alphaF();
+ cmd.args.setBlendConstants.c[0] = float(c.redF());
+ cmd.args.setBlendConstants.c[1] = float(c.greenF());
+ cmd.args.setBlendConstants.c[2] = float(c.blueF());
+ cmd.args.setBlendConstants.c[3] = float(c.alphaF());
cbD->commands.append(cmd);
}
}
@@ -4838,7 +4877,7 @@ bool QVkBuffer::build()
VkBufferCreateInfo bufferInfo;
memset(&bufferInfo, 0, sizeof(bufferInfo));
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
- bufferInfo.size = nonZeroSize;
+ bufferInfo.size = uint32_t(nonZeroSize);
bufferInfo.usage = toVkBufferUsage(m_usage);
VmaAllocationCreateInfo allocInfo;
@@ -4885,7 +4924,7 @@ bool QVkBuffer::build()
}
QRHI_PROF;
- QRHI_PROF_F(newBuffer(this, nonZeroSize, m_type != Dynamic ? 1 : QVK_FRAMES_IN_FLIGHT, 0));
+ QRHI_PROF_F(newBuffer(this, uint(nonZeroSize), m_type != Dynamic ? 1 : QVK_FRAMES_IN_FLIGHT, 0));
lastActiveFrameSlot = -1;
generation += 1;
@@ -5076,7 +5115,7 @@ bool QVkTexture::prepareBuild(QSize *adjustedSize)
const bool isCube = m_flags.testFlag(CubeMap);
const bool hasMipMaps = m_flags.testFlag(MipMapped);
- mipLevelCount = hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1;
+ mipLevelCount = uint(hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1);
const int maxLevels = QRhi::MAX_LEVELS;
if (mipLevelCount > maxLevels) {
qWarning("Too many mip levels (%d, max is %d), truncating mip chain", mipLevelCount, maxLevels);
@@ -5155,8 +5194,8 @@ bool QVkTexture::build()
imageInfo.flags = isCube ? VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0;
imageInfo.imageType = VK_IMAGE_TYPE_2D;
imageInfo.format = vkformat;
- imageInfo.extent.width = size.width();
- imageInfo.extent.height = size.height();
+ imageInfo.extent.width = uint32_t(size.width());
+ imageInfo.extent.height = uint32_t(size.height());
imageInfo.extent.depth = 1;
imageInfo.mipLevels = mipLevelCount;
imageInfo.arrayLayers = isCube ? 6 : 1;
@@ -5197,7 +5236,7 @@ bool QVkTexture::build()
rhiD->setObjectName(uint64_t(image), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, m_objectName);
QRHI_PROF;
- QRHI_PROF_F(newTexture(this, true, mipLevelCount, isCube ? 6 : 1, samples));
+ QRHI_PROF_F(newTexture(this, true, int(mipLevelCount), isCube ? 6 : 1, samples));
owns = true;
rhiD->registerResource(this);
@@ -5219,7 +5258,7 @@ bool QVkTexture::buildFrom(const QRhiNativeHandles *src)
return false;
QRHI_PROF;
- QRHI_PROF_F(newTexture(this, false, mipLevelCount, m_flags.testFlag(CubeMap) ? 6 : 1, samples));
+ QRHI_PROF_F(newTexture(this, false, int(mipLevelCount), m_flags.testFlag(CubeMap) ? 6 : 1, samples));
usageState.layout = h->layout;
@@ -5255,7 +5294,7 @@ VkImageView QVkTexture::imageViewForLevel(int level)
viewInfo.components.b = VK_COMPONENT_SWIZZLE_B;
viewInfo.components.a = VK_COMPONENT_SWIZZLE_A;
viewInfo.subresourceRange.aspectMask = isDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
- viewInfo.subresourceRange.baseMipLevel = level;
+ viewInfo.subresourceRange.baseMipLevel = uint32_t(level);
viewInfo.subresourceRange.levelCount = 1;
viewInfo.subresourceRange.baseArrayLayer = 0;
viewInfo.subresourceRange.layerCount = isCube ? 6 : 1;
@@ -5496,9 +5535,9 @@ bool QVkTextureRenderTarget::build()
viewInfo.components.b = VK_COMPONENT_SWIZZLE_B;
viewInfo.components.a = VK_COMPONENT_SWIZZLE_A;
viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- viewInfo.subresourceRange.baseMipLevel = colorAttachments[i].level();
+ viewInfo.subresourceRange.baseMipLevel = uint32_t(colorAttachments[i].level());
viewInfo.subresourceRange.levelCount = 1;
- viewInfo.subresourceRange.baseArrayLayer = colorAttachments[i].layer();
+ viewInfo.subresourceRange.baseArrayLayer = uint32_t(colorAttachments[i].layer());
viewInfo.subresourceRange.layerCount = 1;
VkResult err = rhiD->df->vkCreateImageView(rhiD->dev, &viewInfo, nullptr, &rtv[i]);
if (err != VK_SUCCESS) {
@@ -5560,9 +5599,9 @@ bool QVkTextureRenderTarget::build()
viewInfo.components.b = VK_COMPONENT_SWIZZLE_B;
viewInfo.components.a = VK_COMPONENT_SWIZZLE_A;
viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
- viewInfo.subresourceRange.baseMipLevel = colorAttachments[i].resolveLevel();
+ viewInfo.subresourceRange.baseMipLevel = uint32_t(colorAttachments[i].resolveLevel());
viewInfo.subresourceRange.levelCount = 1;
- viewInfo.subresourceRange.baseArrayLayer = colorAttachments[i].resolveLayer();
+ viewInfo.subresourceRange.baseArrayLayer = uint32_t(colorAttachments[i].resolveLayer());
viewInfo.subresourceRange.layerCount = 1;
VkResult err = rhiD->df->vkCreateImageView(rhiD->dev, &viewInfo, nullptr, &resrtv[i]);
if (err != VK_SUCCESS) {
@@ -5583,10 +5622,10 @@ bool QVkTextureRenderTarget::build()
memset(&fbInfo, 0, sizeof(fbInfo));
fbInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
fbInfo.renderPass = d.rp->rp;
- fbInfo.attachmentCount = d.colorAttCount + d.dsAttCount + d.resolveAttCount;
+ fbInfo.attachmentCount = uint32_t(d.colorAttCount + d.dsAttCount + d.resolveAttCount);
fbInfo.pAttachments = views.constData();
- fbInfo.width = d.pixelSize.width();
- fbInfo.height = d.pixelSize.height();
+ fbInfo.width = uint32_t(d.pixelSize.width());
+ fbInfo.height = uint32_t(d.pixelSize.height());
fbInfo.layers = 1;
VkResult err = rhiD->df->vkCreateFramebuffer(rhiD->dev, &fbInfo, nullptr, &d.fb);
@@ -5670,7 +5709,7 @@ bool QVkShaderResourceBindings::build()
const QRhiShaderResourceBindingPrivate *b = QRhiShaderResourceBindingPrivate::get(&binding);
VkDescriptorSetLayoutBinding vkbinding;
memset(&vkbinding, 0, sizeof(vkbinding));
- vkbinding.binding = b->binding;
+ vkbinding.binding = uint32_t(b->binding);
vkbinding.descriptorType = toVkDescriptorType(b);
vkbinding.descriptorCount = 1; // no array support yet
vkbinding.stageFlags = toVkShaderStageFlags(b->stage);
@@ -5787,7 +5826,7 @@ bool QVkGraphicsPipeline::build()
shaderStageCreateInfos.append(shaderInfo);
}
}
- pipelineInfo.stageCount = shaderStageCreateInfos.count();
+ pipelineInfo.stageCount = uint32_t(shaderStageCreateInfos.count());
pipelineInfo.pStages = shaderStageCreateInfos.constData();
const QVector<QRhiVertexInputBinding> bindings = m_vertexInputLayout.bindings();
@@ -5828,15 +5867,15 @@ bool QVkGraphicsPipeline::build()
VkPipelineVertexInputStateCreateInfo vertexInputInfo;
memset(&vertexInputInfo, 0, sizeof(vertexInputInfo));
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
- vertexInputInfo.vertexBindingDescriptionCount = vertexBindings.count();
+ vertexInputInfo.vertexBindingDescriptionCount = uint32_t(vertexBindings.count());
vertexInputInfo.pVertexBindingDescriptions = vertexBindings.constData();
- vertexInputInfo.vertexAttributeDescriptionCount = vertexAttributes.count();
+ vertexInputInfo.vertexAttributeDescriptionCount = uint32_t(vertexAttributes.count());
vertexInputInfo.pVertexAttributeDescriptions = vertexAttributes.constData();
VkPipelineVertexInputDivisorStateCreateInfoEXT divisorInfo;
if (!nonOneStepRates.isEmpty()) {
memset(&divisorInfo, 0, sizeof(divisorInfo));
divisorInfo.sType = VkStructureType(1000190001); // VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT
- divisorInfo.vertexBindingDivisorCount = nonOneStepRates.count();
+ divisorInfo.vertexBindingDivisorCount = uint32_t(nonOneStepRates.count());
divisorInfo.pVertexBindingDivisors = nonOneStepRates.constData();
vertexInputInfo.pNext = &divisorInfo;
}
@@ -5853,7 +5892,7 @@ bool QVkGraphicsPipeline::build()
VkPipelineDynamicStateCreateInfo dynamicInfo;
memset(&dynamicInfo, 0, sizeof(dynamicInfo));
dynamicInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
- dynamicInfo.dynamicStateCount = dynEnable.count();
+ dynamicInfo.dynamicStateCount = uint32_t(dynEnable.count());
dynamicInfo.pDynamicStates = dynEnable.constData();
pipelineInfo.pDynamicState = &dynamicInfo;
@@ -5925,7 +5964,7 @@ bool QVkGraphicsPipeline::build()
| VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
vktargetBlends.append(blend);
}
- blendInfo.attachmentCount = vktargetBlends.count();
+ blendInfo.attachmentCount = uint32_t(vktargetBlends.count());
blendInfo.pAttachments = vktargetBlends.constData();
pipelineInfo.pColorBlendState = &blendInfo;
@@ -6126,11 +6165,11 @@ QSize QVkSwapChain::surfacePixelSize()
QRHI_RES_RHI(QRhiVulkan);
rhiD->vkGetPhysicalDeviceSurfaceCapabilitiesKHR(rhiD->physDev, surface, &surfaceCaps);
VkExtent2D bufferSize = surfaceCaps.currentExtent;
- if (bufferSize.width == quint32(-1)) {
- Q_ASSERT(bufferSize.height == quint32(-1));
+ if (bufferSize.width == uint32_t(-1)) {
+ Q_ASSERT(bufferSize.height == uint32_t(-1));
return m_window->size() * m_window->devicePixelRatio();
}
- return QSize(bufferSize.width, bufferSize.height);
+ return QSize(int(bufferSize.width), int(bufferSize.height));
}
QRhiRenderPassDescriptor *QVkSwapChain::newCompatibleRenderPassDescriptor()
@@ -6198,7 +6237,7 @@ bool QVkSwapChain::ensureSurface()
QRHI_RES_RHI(QRhiVulkan);
if (rhiD->gfxQueueFamilyIdx != -1) {
- if (!rhiD->inst->supportsPresent(rhiD->physDev, rhiD->gfxQueueFamilyIdx, m_window)) {
+ if (!rhiD->inst->supportsPresent(rhiD->physDev, uint32_t(rhiD->gfxQueueFamilyIdx), m_window)) {
qWarning("Presenting not supported on this window");
return false;
}
@@ -6227,7 +6266,7 @@ bool QVkSwapChain::ensureSurface()
rhiD->vkGetPhysicalDeviceSurfaceFormatsKHR(rhiD->physDev, surface, &formatCount, formats.data());
const bool srgbRequested = m_flags.testFlag(sRGB);
- for (quint32 i = 0; i < formatCount; ++i) {
+ for (int i = 0; i < int(formatCount); ++i) {
if (formats[i].format != VK_FORMAT_UNDEFINED && srgbRequested == isSrgbFormat(formats[i].format)) {
colorFormat = formats[i].format;
colorSpace = formats[i].colorSpace;
@@ -6288,7 +6327,7 @@ bool QVkSwapChain::buildOrResize()
Q_ASSERT(rtWrapper.d.rp && rtWrapper.d.rp->rp);
rtWrapper.d.pixelSize = pixelSize;
- rtWrapper.d.dpr = window->devicePixelRatio();
+ rtWrapper.d.dpr = float(window->devicePixelRatio());
rtWrapper.d.sampleCount = samples;
rtWrapper.d.colorAttCount = 1;
if (m_depthStencil) {
@@ -6315,10 +6354,10 @@ bool QVkSwapChain::buildOrResize()
memset(&fbInfo, 0, sizeof(fbInfo));
fbInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
fbInfo.renderPass = rtWrapper.d.rp->rp;
- fbInfo.attachmentCount = rtWrapper.d.colorAttCount + rtWrapper.d.dsAttCount + rtWrapper.d.resolveAttCount;
+ fbInfo.attachmentCount = uint32_t(rtWrapper.d.colorAttCount + rtWrapper.d.dsAttCount + rtWrapper.d.resolveAttCount);
fbInfo.pAttachments = views;
- fbInfo.width = pixelSize.width();
- fbInfo.height = pixelSize.height();
+ fbInfo.width = uint32_t(pixelSize.width());
+ fbInfo.height = uint32_t(pixelSize.height());
fbInfo.layers = 1;
VkResult err = rhiD->df->vkCreateFramebuffer(rhiD->dev, &fbInfo, nullptr, &image.fb);
diff --git a/src/gui/rhi/qrhivulkan_p_p.h b/src/gui/rhi/qrhivulkan_p_p.h
index 962a1b8eb7..a390bc3707 100644
--- a/src/gui/rhi/qrhivulkan_p_p.h
+++ b/src/gui/rhi/qrhivulkan_p_p.h
@@ -711,7 +711,9 @@ public:
int resourceLimit(QRhi::ResourceLimit limit) const override;
const QRhiNativeHandles *nativeHandles() override;
void sendVMemStatsToProfiler() override;
- void makeThreadLocalNativeContextCurrent() override;
+ bool makeThreadLocalNativeContextCurrent() override;
+ void releaseCachedResources() override;
+ bool isDeviceLost() const override;
VkResult createDescriptorPool(VkDescriptorPool *pool);
bool allocateDescriptorSet(VkDescriptorSetAllocateInfo *allocInfo, VkDescriptorSet *result, int *resultPoolIndex);
@@ -803,6 +805,7 @@ public:
VkDeviceSize ubufAlign;
VkDeviceSize texbufAlign;
bool hasWideLines = false;
+ bool deviceLost = false;
bool debugMarkersAvailable = false;
bool vertexAttribDivisorAvailable = false;
diff --git a/src/gui/rhi/tdr.hlsl b/src/gui/rhi/tdr.hlsl
new file mode 100644
index 0000000000..f79de91c4a
--- /dev/null
+++ b/src/gui/rhi/tdr.hlsl
@@ -0,0 +1,9 @@
+RWBuffer<uint> uav;
+cbuffer ConstantBuffer { uint zero; }
+
+[numthreads(256, 1, 1)]
+void killDeviceByTimingOut(uint3 id: SV_DispatchThreadID)
+{
+ while (zero == 0)
+ uav[id.x] = zero;
+}
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index c80617f929..3652a180a8 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -2067,8 +2067,9 @@ void QTextDocument::print(QPagedPaintDevice *printer) const
\enum QTextDocument::ResourceType
This enum describes the types of resources that can be loaded by
- QTextDocument's loadResource() function.
+ QTextDocument's loadResource() function or by QTextBrowser::setSource().
+ \value UnknownResource No resource is loaded, or the resource type is not known.
\value HtmlResource The resource contains HTML.
\value ImageResource The resource contains image data.
Currently supported data types are QVariant::Pixmap and
@@ -2082,7 +2083,7 @@ void QTextDocument::print(QPagedPaintDevice *printer) const
\value UserResource The first available value for user defined
resource types.
- \sa loadResource()
+ \sa loadResource(), QTextBrowser::sourceType()
*/
/*!
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index c267ade0c2..b37353bf2c 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -399,6 +399,7 @@ struct QBidiAlgorithm {
analysis[i].bidiDirection = (level & 1) ? QChar::DirR : QChar::DirL;
runHasContent = true;
lastRunWithContent = -1;
+ ++isolatePairPosition;
}
int runBeforeIsolate = runs.size();
ushort newLevel = isRtl ? ((stack.top().level + 1) | 1) : ((stack.top().level + 2) & ~1);
@@ -440,21 +441,19 @@ struct QBidiAlgorithm {
doEmbed(true, true, false);
break;
case QChar::DirLRI:
- Q_ASSERT(isolatePairs.at(isolatePairPosition).start == i);
doEmbed(false, false, true);
- ++isolatePairPosition;
break;
case QChar::DirRLI:
- Q_ASSERT(isolatePairs.at(isolatePairPosition).start == i);
doEmbed(true, false, true);
- ++isolatePairPosition;
break;
case QChar::DirFSI: {
- const auto &pair = isolatePairs.at(isolatePairPosition);
- Q_ASSERT(pair.start == i);
- bool isRtl = QStringView(text + pair.start + 1, pair.end - pair.start - 1).isRightToLeft();
+ bool isRtl = false;
+ if (isolatePairPosition < isolatePairs.size()) {
+ const auto &pair = isolatePairs.at(isolatePairPosition);
+ Q_ASSERT(pair.start == i);
+ isRtl = QStringView(text + pair.start + 1, pair.end - pair.start - 1).isRightToLeft();
+ }
doEmbed(isRtl, false, true);
- ++isolatePairPosition;
break;
}
diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp
index 47a38db3ad..e3bd49a15e 100644
--- a/src/gui/text/qtextformat.cpp
+++ b/src/gui/text/qtextformat.cpp
@@ -650,6 +650,7 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt)
\value TableColumns
\value TableColumnWidthConstraints
\value TableHeaderRowCount
+ \value TableBorderCollapse Specifies the \l QTextTableFormat::borderCollapse property.
Table cell properties
diff --git a/src/network/access/qhttp2configuration.cpp b/src/network/access/qhttp2configuration.cpp
index a32bccfd09..bd4318d4e9 100644
--- a/src/network/access/qhttp2configuration.cpp
+++ b/src/network/access/qhttp2configuration.cpp
@@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE
/*!
\class QHttp2Configuration
- \brief The QHttp2Configuration class controls HTTP/2 parameters and settings
+ \brief The QHttp2Configuration class controls HTTP/2 parameters and settings.
\since 5.14
\reentrant
diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp
index c1053882af..9bf5547f15 100644
--- a/src/network/access/qhttp2protocolhandler.cpp
+++ b/src/network/access/qhttp2protocolhandler.cpp
@@ -58,6 +58,8 @@
#include <QtNetwork/qnetworkproxy.h>
#endif
+#include <qcoreapplication.h>
+
#include <algorithm>
#include <vector>
@@ -195,6 +197,29 @@ QHttp2ProtocolHandler::QHttp2ProtocolHandler(QHttpNetworkConnectionChannel *chan
}
}
+void QHttp2ProtocolHandler::handleConnectionClosure()
+{
+ // The channel has just received RemoteHostClosedError and since it will
+ // not try (for HTTP/2) to re-connect, it's time to finish all replies
+ // with error.
+
+ // Maybe we still have some data to read and can successfully finish
+ // a stream/request?
+ _q_receiveReply();
+
+ // Finish all still active streams. If we previously had GOAWAY frame,
+ // we probably already closed some (or all) streams with ContentReSend
+ // error, but for those still active, not having any data to finish,
+ // we now report RemoteHostClosedError.
+ const auto errorString = QCoreApplication::translate("QHttp", "Connection closed");
+ for (auto it = activeStreams.begin(), eIt = activeStreams.end(); it != eIt; ++it)
+ finishStreamWithError(it.value(), QNetworkReply::RemoteHostClosedError, errorString);
+
+ // Make sure we'll never try to read anything later:
+ activeStreams.clear();
+ goingAway = true;
+}
+
void QHttp2ProtocolHandler::_q_uploadDataReadyRead()
{
if (!sender()) // QueuedConnection, firing after sender (byte device) was deleted.
diff --git a/src/network/access/qhttp2protocolhandler_p.h b/src/network/access/qhttp2protocolhandler_p.h
index 1943827e23..43fdb136cd 100644
--- a/src/network/access/qhttp2protocolhandler_p.h
+++ b/src/network/access/qhttp2protocolhandler_p.h
@@ -92,6 +92,8 @@ public:
QHttp2ProtocolHandler &operator = (const QHttp2ProtocolHandler &rhs) = delete;
QHttp2ProtocolHandler &operator = (QHttp2ProtocolHandler &&rhs) = delete;
+ Q_INVOKABLE void handleConnectionClosure();
+
private slots:
void _q_uploadDataReadyRead();
void _q_replyDestroyed(QObject* reply);
diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
index 13be1aa6b5..21c6359807 100644
--- a/src/network/access/qhttpnetworkconnection.cpp
+++ b/src/network/access/qhttpnetworkconnection.cpp
@@ -1235,7 +1235,8 @@ void QHttpNetworkConnectionPrivate::_q_hostLookupFinished(const QHostInfo &info)
emitReplyError(channels[0].socket, channels[0].reply, QNetworkReply::HostNotFoundError);
networkLayerState = QHttpNetworkConnectionPrivate::Unknown;
} else if (connectionType == QHttpNetworkConnection::ConnectionTypeSPDY
- || connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2) {
+ || connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2
+ || connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2Direct) {
for (const HttpMessagePair &spdyPair : qAsConst(channels[0].spdyRequestsToSend)) {
// emit error for all replies
QHttpNetworkReply *currentReply = spdyPair.second;
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
index 716ea6c8b2..39f392a79b 100644
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
@@ -854,8 +854,11 @@ void QHttpNetworkConnectionChannel::_q_disconnected()
QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
}
state = QHttpNetworkConnectionChannel::IdleState;
-
- requeueCurrentlyPipelinedRequests();
+ if (alreadyPipelinedRequests.length()) {
+ // If nothing was in a pipeline, no need in calling
+ // _q_startNextRequest (which it does):
+ requeueCurrentlyPipelinedRequests();
+ }
pendingEncrypt = false;
}
@@ -977,7 +980,18 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
if (!reply && state == QHttpNetworkConnectionChannel::IdleState) {
// Not actually an error, it is normal for Keep-Alive connections to close after some time if no request
// is sent on them. No need to error the other replies below. Just bail out here.
- // The _q_disconnected will handle the possibly pipelined replies
+ // The _q_disconnected will handle the possibly pipelined replies. HTTP/2 is special for now,
+ // we do not resend, but must report errors if any request is in progress (note, while
+ // not in its sendRequest(), protocol handler switches the channel to IdleState, thus
+ // this check is under this condition in 'if'):
+ if (protocolHandler.data()) {
+ if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2Direct
+ || connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2) {
+ auto h2Handler = static_cast<QHttp2ProtocolHandler *>(protocolHandler.data());
+ h2Handler->handleConnectionClosure();
+ protocolHandler.reset();
+ }
+ }
return;
} else if (state != QHttpNetworkConnectionChannel::IdleState && state != QHttpNetworkConnectionChannel::ReadingState) {
// Try to reconnect/resend before sending an error.
@@ -1094,6 +1108,7 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
|| !connection->d_func()->lowPriorityQueue.isEmpty());
if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2
+ || connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2Direct
#ifndef QT_NO_SSL
|| connection->connectionType() == QHttpNetworkConnection::ConnectionTypeSPDY
#endif
diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp
index 1900397eab..63a3c4f204 100644
--- a/src/network/access/qhttpthreaddelegate.cpp
+++ b/src/network/access/qhttpthreaddelegate.cpp
@@ -297,6 +297,11 @@ void QHttpThreadDelegate::startRequest()
connectionType = QHttpNetworkConnection::ConnectionTypeHTTP2Direct;
}
+#if QT_CONFIG(ssl)
+ // See qnetworkreplyhttpimpl, delegate's initialization code.
+ Q_ASSERT(!ssl || incomingSslConfiguration.data());
+#endif // QT_CONFIG(ssl)
+
const bool isH2 = httpRequest.isHTTP2Allowed() || httpRequest.isHTTP2Direct();
if (isH2) {
#if QT_CONFIG(ssl)
@@ -316,9 +321,6 @@ void QHttpThreadDelegate::startRequest()
}
#ifndef QT_NO_SSL
- if (ssl && !incomingSslConfiguration.data())
- incomingSslConfiguration.reset(new QSslConfiguration);
-
if (!isH2 && httpRequest.isSPDYAllowed() && ssl) {
connectionType = QHttpNetworkConnection::ConnectionTypeSPDY;
urlCopy.setScheme(QStringLiteral("spdy")); // to differentiate SPDY requests from HTTPS requests
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index 118fb6b1fb..cedb1597de 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -277,23 +277,30 @@ QT_BEGIN_NAMESPACE
Indicates whether the QNetworkAccessManager code is
allowed to use SPDY with this request. This applies only
to SSL requests, and depends on the server supporting SPDY.
+ Obsolete, use Http2 instead of Spdy.
\value SpdyWasUsedAttribute
Replies only, type: QMetaType::Bool
Indicates whether SPDY was used for receiving
- this reply.
+ this reply. Obsolete, use Http2 instead of Spdy.
- \value HTTP2AllowedAttribute
+ \value Http2AllowedAttribute
Requests only, type: QMetaType::Bool (default: false)
Indicates whether the QNetworkAccessManager code is
allowed to use HTTP/2 with this request. This applies
to SSL requests or 'cleartext' HTTP/2.
- \value HTTP2WasUsedAttribute
+ \value Http2WasUsedAttribute
Replies only, type: QMetaType::Bool (default: false)
Indicates whether HTTP/2 was used for receiving this reply.
(This value was introduced in 5.9.)
+ \value HTTP2AllowedAttribute
+ Obsolete alias for Http2AllowedAttribute.
+
+ \value HTTP2WasUsedAttribute
+ Obsolete alias for Http2WasUsedAttribute.
+
\value EmitAllUploadProgressSignalsAttribute
Requests only, type: QMetaType::Bool (default: false)
Indicates whether all upload signals should be emitted.
diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h
index e09ff8aaae..72a6555d91 100644
--- a/src/network/access/qnetworkrequest.h
+++ b/src/network/access/qnetworkrequest.h
@@ -89,12 +89,18 @@ public:
DownloadBufferAttribute, // internal
SynchronousRequestAttribute, // internal
BackgroundRequestAttribute,
+#if QT_DEPRECATED_SINCE(5, 15)
SpdyAllowedAttribute,
SpdyWasUsedAttribute,
- EmitAllUploadProgressSignalsAttribute,
+#endif // QT_DEPRECATED_SINCE(5, 15)
+ EmitAllUploadProgressSignalsAttribute = BackgroundRequestAttribute + 3,
FollowRedirectsAttribute,
- HTTP2AllowedAttribute,
- HTTP2WasUsedAttribute,
+ Http2AllowedAttribute,
+ Http2WasUsedAttribute,
+#if QT_DEPRECATED_SINCE(5, 15)
+ HTTP2AllowedAttribute Q_DECL_ENUMERATOR_DEPRECATED_X("Use Http2AllowedAttribute") = Http2AllowedAttribute,
+ HTTP2WasUsedAttribute Q_DECL_ENUMERATOR_DEPRECATED_X("Use Http2WasUsedAttribute"),
+#endif // QT_DEPRECATED_SINCE(5, 15)
OriginalContentLengthAttribute,
RedirectPolicyAttribute,
Http2DirectAttribute,
diff --git a/src/network/kernel/qnetconmonitor_win.cpp b/src/network/kernel/qnetconmonitor_win.cpp
index a010df8e3a..1566e7f914 100644
--- a/src/network/kernel/qnetconmonitor_win.cpp
+++ b/src/network/kernel/qnetconmonitor_win.cpp
@@ -103,7 +103,7 @@ class QNetworkConnectionEvents : public INetworkConnectionEvents
{
public:
QNetworkConnectionEvents(QNetworkConnectionMonitorPrivate *monitor);
- ~QNetworkConnectionEvents();
+ virtual ~QNetworkConnectionEvents();
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override;
@@ -471,7 +471,7 @@ class QNetworkListManagerEvents : public INetworkListManagerEvents
{
public:
QNetworkListManagerEvents(QNetworkStatusMonitorPrivate *monitor);
- ~QNetworkListManagerEvents();
+ virtual ~QNetworkListManagerEvents();
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override;
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp
index ca6c58117d..e302aa1761 100644
--- a/src/network/ssl/qsslsocket.cpp
+++ b/src/network/ssl/qsslsocket.cpp
@@ -1512,7 +1512,7 @@ bool QSslSocket::addDefaultCaCertificates(const QString &path, QSsl::EncodingFor
SSL socket's CA certificate database is initialized to the default
CA certificate database.
- \sa QSslConfiguration::defaultCaCertificates(), addCaCertificates()
+ \sa QSslConfiguration::caCertificates(), addCaCertificates()
*/
void QSslSocket::addDefaultCaCertificate(const QSslCertificate &certificate)
{
diff --git a/src/network/ssl/qsslsocket_openssl11.cpp b/src/network/ssl/qsslsocket_openssl11.cpp
index 28be4f2e79..1d935c5217 100644
--- a/src/network/ssl/qsslsocket_openssl11.cpp
+++ b/src/network/ssl/qsslsocket_openssl11.cpp
@@ -143,13 +143,12 @@ void QSslSocketPrivate::ensureCiphersAndCertsLoaded()
if (!s_loadRootCertsOnDemand)
setDefaultCaCertificates(systemCaCertificates());
#ifdef Q_OS_WIN
- //Enabled for fetching additional root certs from windows update on windows 6+
+ //Enabled for fetching additional root certs from windows update on windows.
//This flag is set false by setDefaultCaCertificates() indicating the app uses
//its own cert bundle rather than the system one.
//Same logic that disables the unix on demand cert loading.
//Unlike unix, we do preload the certificates from the cert store.
- if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista)
- s_loadRootCertsOnDemand = true;
+ s_loadRootCertsOnDemand = true;
#endif
}
diff --git a/src/network/ssl/qsslsocket_schannel.cpp b/src/network/ssl/qsslsocket_schannel.cpp
index 1db26ee9a1..d7fb080b49 100644
--- a/src/network/ssl/qsslsocket_schannel.cpp
+++ b/src/network/ssl/qsslsocket_schannel.cpp
@@ -828,12 +828,17 @@ bool QSslSocketBackendPrivate::acceptContext()
&expiry // ptsTimeStamp
);
+ if (status == SEC_E_INCOMPLETE_MESSAGE) {
+ // Need more data
+ return true;
+ }
+
if (inBuffers[1].BufferType == SECBUFFER_EXTRA) {
// https://docs.microsoft.com/en-us/windows/desktop/secauthn/extra-buffers-returned-by-schannel
// inBuffers[1].cbBuffer indicates the amount of bytes _NOT_ processed, the rest need to
// be stored.
intermediateBuffer = intermediateBuffer.right(int(inBuffers[1].cbBuffer));
- } else if (status != SEC_E_INCOMPLETE_MESSAGE) {
+ } else { /* No 'extra' data, message not incomplete */
intermediateBuffer.clear();
}
@@ -1069,7 +1074,6 @@ bool QSslSocketBackendPrivate::verifyHandshake()
}
schannelState = SchannelState::Done;
- peerCertVerified = true;
return true;
}
@@ -1152,7 +1156,6 @@ void QSslSocketBackendPrivate::reset()
connectionEncrypted = false;
shutdown = false;
- peerCertVerified = false;
renegotiating = false;
}
@@ -1315,7 +1318,9 @@ void QSslSocketBackendPrivate::transmit()
#endif
intermediateBuffer = ciphertext.right(int(dataBuffer[3].cbBuffer));
}
- } else if (status == SEC_E_INCOMPLETE_MESSAGE) {
+ }
+
+ if (status == SEC_E_INCOMPLETE_MESSAGE) {
// Need more data before we can decrypt.. to the buffer it goes!
#ifdef QSSLSOCKET_DEBUG
qCDebug(lcSsl, "We didn't have enough data to decrypt anything, will try again!");
@@ -1360,6 +1365,7 @@ void QSslSocketBackendPrivate::transmit()
#endif
schannelState = SchannelState::Renegotiate;
renegotiating = true;
+
// We need to call 'continueHandshake' or else there's no guarantee it ever gets called
continueHandshake();
break;
@@ -1525,7 +1531,7 @@ void QSslSocketBackendPrivate::continueHandshake()
case SchannelState::VerifyHandshake:
// if we're in shutdown or renegotiating then we might not need to verify
// (since we already did)
- if (!peerCertVerified && !verifyHandshake()) {
+ if (!verifyHandshake()) {
shutdown = true; // Skip sending shutdown alert
q->abort(); // We don't want to send buffered data
disconnectFromHost();
diff --git a/src/network/ssl/qsslsocket_schannel_p.h b/src/network/ssl/qsslsocket_schannel_p.h
index 9879e2fc60..6ab200e1f9 100644
--- a/src/network/ssl/qsslsocket_schannel_p.h
+++ b/src/network/ssl/qsslsocket_schannel_p.h
@@ -147,7 +147,6 @@ private:
ULONG contextAttributes = 0;
bool renegotiating = false;
- bool peerCertVerified = false;
};
QT_END_NAMESPACE
diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
index 047773d8e3..a52e157768 100644
--- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
+++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm
@@ -100,20 +100,6 @@ static const char *languageForWritingSystem[] = {
};
enum { LanguageCount = sizeof(languageForWritingSystem) / sizeof(const char *) };
-#ifdef Q_OS_OSX
-static NSInteger languageMapSort(id obj1, id obj2, void *context)
-{
- NSArray<NSString *> *map1 = reinterpret_cast<NSArray<NSString *> *>(obj1);
- NSArray<NSString *> *map2 = reinterpret_cast<NSArray<NSString *> *>(obj2);
- NSArray<NSString *> *languages = reinterpret_cast<NSArray<NSString *> *>(context);
-
- NSString *lang1 = [map1 objectAtIndex:0];
- NSString *lang2 = [map2 objectAtIndex:0];
-
- return [languages indexOfObject:lang1] - [languages indexOfObject:lang2];
-}
-#endif
-
QCoreTextFontDatabase::QCoreTextFontDatabase()
: m_hasPopulatedAliases(false)
{
@@ -406,142 +392,99 @@ template class QCoreTextFontDatabaseEngineFactory<QCoreTextFontEngine>;
template class QCoreTextFontDatabaseEngineFactory<QFontEngineFT>;
#endif
-QFont::StyleHint styleHintFromNSString(NSString *style)
+QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family)
{
- if ([style isEqual: @"sans-serif"])
- return QFont::SansSerif;
- else if ([style isEqual: @"monospace"])
- return QFont::Monospace;
- else if ([style isEqual: @"cursive"])
- return QFont::Cursive;
- else if ([style isEqual: @"serif"])
- return QFont::Serif;
- else if ([style isEqual: @"fantasy"])
- return QFont::Fantasy;
- else // if ([style isEqual: @"default"])
- return QFont::AnyStyle;
-}
+ if (family.isEmpty())
+ return QStringList();
-#ifdef Q_OS_OSX
-static QString familyNameFromPostScriptName(NSString *psName)
-{
- QCFType<CTFontDescriptorRef> fontDescriptor = (CTFontDescriptorRef) CTFontDescriptorCreateWithNameAndSize((CFStringRef)psName, 12.0);
- QCFString familyName = (CFStringRef) CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontFamilyNameAttribute);
- QString name = QString::fromCFString(familyName);
- if (name.isEmpty())
- qWarning() << "QCoreTextFontDatabase: Failed to resolve family name for PostScript name " << QString::fromCFString((CFStringRef)psName);
+ auto attributes = @{ id(kCTFontFamilyNameAttribute): family.toNSString() };
+ QCFType<CTFontDescriptorRef> fontDescriptor = CTFontDescriptorCreateWithAttributes(CFDictionaryRef(attributes));
+ if (!fontDescriptor) {
+ qWarning() << "Failed to create fallback font descriptor for" << family;
+ return QStringList();
+ }
- return name;
-}
-#endif
+ QCFType<CTFontRef> font = CTFontCreateWithFontDescriptor(fontDescriptor, 12.0, 0);
+ if (!font) {
+ qWarning() << "Failed to create fallback font for" << family;
+ return QStringList();
+ }
-static void addExtraFallbacks(QStringList *fallbackList)
-{
-#if defined(Q_OS_MACOS)
- // Since we are only returning a list of default fonts for the current language, we do not
- // cover all unicode completely. This was especially an issue for some of the common script
- // symbols such as mathematical symbols, currency or geometric shapes. To minimize the risk
- // of missing glyphs, we add Arial Unicode MS as a final fail safe, since this covers most
- // of Unicode 2.1.
- if (!fallbackList->contains(QStringLiteral("Arial Unicode MS")))
- fallbackList->append(QStringLiteral("Arial Unicode MS"));
- // Since some symbols (specifically Braille) are not in Arial Unicode MS, we
- // add Apple Symbols to cover those too.
- if (!fallbackList->contains(QStringLiteral("Apple Symbols")))
- fallbackList->append(QStringLiteral("Apple Symbols"));
-#else
- Q_UNUSED(fallbackList)
-#endif
+ QCFType<CFArrayRef> cascadeList = CFArrayRef(CTFontCopyDefaultCascadeListForLanguages(font,
+ (CFArrayRef)[NSUserDefaults.standardUserDefaults stringArrayForKey:@"AppleLanguages"]));
+ if (!cascadeList) {
+ qWarning() << "Failed to create fallback cascade list for" << family;
+ return QStringList();
+ }
+
+ QStringList fallbackList;
+ const int numCascades = CFArrayGetCount(cascadeList);
+ for (int i = 0; i < numCascades; ++i) {
+ CTFontDescriptorRef fontFallback = CTFontDescriptorRef(CFArrayGetValueAtIndex(cascadeList, i));
+ QCFString fallbackFamilyName = CFStringRef(CTFontDescriptorCopyAttribute(fontFallback, kCTFontFamilyNameAttribute));
+ fallbackList.append(QString::fromCFString(fallbackFamilyName));
+ }
+
+ return fallbackList;
}
QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const
{
Q_UNUSED(style);
- Q_UNUSED(script);
QMacAutoReleasePool pool;
- static QHash<QString, QStringList> fallbackLists;
-
- if (!family.isEmpty()) {
- QCFType<CFMutableDictionaryRef> attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
- CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, QCFString(family));
- if (QCFType<CTFontDescriptorRef> fontDescriptor = CTFontDescriptorCreateWithAttributes(attributes)) {
- if (QCFType<CTFontRef> font = CTFontCreateWithFontDescriptor(fontDescriptor, 12.0, 0)) {
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSArray *languages = [defaults stringArrayForKey: @"AppleLanguages"];
-
- QCFType<CFArrayRef> cascadeList = (CFArrayRef) CTFontCopyDefaultCascadeListForLanguages(font, (CFArrayRef) languages);
- if (cascadeList) {
- QStringList fallbackList;
- const int numCascades = CFArrayGetCount(cascadeList);
- for (int i = 0; i < numCascades; ++i) {
- CTFontDescriptorRef fontFallback = (CTFontDescriptorRef) CFArrayGetValueAtIndex(cascadeList, i);
- QCFString fallbackFamilyName = (CFStringRef) CTFontDescriptorCopyAttribute(fontFallback, kCTFontFamilyNameAttribute);
- fallbackList.append(QString::fromCFString(fallbackFamilyName));
- }
-
- addExtraFallbacks(&fallbackList);
- extern QStringList qt_sort_families_by_writing_system(QChar::Script, const QStringList &);
- fallbackList = qt_sort_families_by_writing_system(script, fallbackList);
-
- return fallbackList;
+ QStringList fallbackList = fallbacksForFamily(family);
+
+ if (fallbackList.isEmpty()) {
+ // We were not able to find a fallback for the specific family,
+ // or the family was empty, so we fall back to the style hint.
+ QString styleFamily = [styleHint]{
+ switch (styleHint) {
+ case QFont::SansSerif: return QStringLiteral("Helvetica");
+ case QFont::Serif: return QStringLiteral("Times New Roman");
+ case QFont::Monospace: return QStringLiteral("Menlo");
+#ifdef Q_OS_MACOS
+ case QFont::Cursive: return QStringLiteral("Apple Chancery");
+#endif
+ case QFont::Fantasy: return QStringLiteral("Zapfino");
+ case QFont::TypeWriter: return QStringLiteral("American Typewriter");
+ case QFont::AnyStyle: Q_FALLTHROUGH();
+ case QFont::System: {
+ QCFType<CTFontRef> font = CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, 12.0, NULL);
+ return static_cast<QString>(QCFString(CTFontCopyFullName(font)));
}
+ default: return QString(); // No matching font on this platform
}
+ }();
+ if (!styleFamily.isEmpty()) {
+ fallbackList = fallbacksForFamily(styleFamily);
+ if (!fallbackList.contains(styleFamily))
+ fallbackList.prepend(styleFamily);
}
}
- // We were not able to find a fallback for the specific family,
- // so we fall back to the stylehint.
-
- static const QString styleLookupKey = QString::fromLatin1(".QFontStyleHint_%1");
-
- static bool didPopulateStyleFallbacks = false;
- if (!didPopulateStyleFallbacks) {
-#if defined(Q_OS_MACX)
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSArray<NSString *> *languages = [defaults stringArrayForKey:@"AppleLanguages"];
-
- NSDictionary<NSString *, id> *fallbackDict = [NSDictionary<NSString *, id> dictionaryWithContentsOfFile:@"/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreText.framework/Resources/DefaultFontFallbacks.plist"];
-
- for (NSString *style in [fallbackDict allKeys]) {
- NSArray *list = [fallbackDict valueForKey:style];
- QFont::StyleHint fallbackStyleHint = styleHintFromNSString(style);
- QStringList fallbackList;
- for (id item in list) {
- // sort the array based on system language preferences
- if ([item isKindOfClass:[NSArray class]]) {
- NSArray *langs = [reinterpret_cast<NSArray *>(item)
- sortedArrayUsingFunction:languageMapSort context:languages];
- for (NSArray<NSString *> *map in langs)
- fallbackList.append(familyNameFromPostScriptName([map objectAtIndex:1]));
- }
- else if ([item isKindOfClass: [NSString class]])
- fallbackList.append(familyNameFromPostScriptName(item));
- }
-
- fallbackList.append(QLatin1String("Apple Color Emoji"));
+ if (fallbackList.isEmpty())
+ return fallbackList;
- addExtraFallbacks(&fallbackList);
- fallbackLists[styleLookupKey.arg(fallbackStyleHint)] = fallbackList;
- }
-#else
- QStringList staticFallbackList;
- staticFallbackList << QString::fromLatin1("Helvetica,Apple Color Emoji,Geeza Pro,Arial Hebrew,Thonburi,Kailasa"
- "Hiragino Kaku Gothic ProN,.Heiti J,Apple SD Gothic Neo,.Heiti K,Heiti SC,Heiti TC"
- "Bangla Sangam MN,Devanagari Sangam MN,Gujarati Sangam MN,Gurmukhi MN,Kannada Sangam MN"
- "Malayalam Sangam MN,Oriya Sangam MN,Sinhala Sangam MN,Tamil Sangam MN,Telugu Sangam MN"
- "Euphemia UCAS,.PhoneFallback").split(QLatin1String(","));
-
- for (int i = QFont::Helvetica; i <= QFont::Fantasy; ++i)
- fallbackLists[styleLookupKey.arg(i)] = staticFallbackList;
+#if defined(Q_OS_MACOS)
+ // Since we are only returning a list of default fonts for the current language, we do not
+ // cover all Unicode completely. This was especially an issue for some of the common script
+ // symbols such as mathematical symbols, currency or geometric shapes. To minimize the risk
+ // of missing glyphs, we add Arial Unicode MS as a final fail safe, since this covers most
+ // of Unicode 2.1.
+ if (!fallbackList.contains(QStringLiteral("Arial Unicode MS")))
+ fallbackList.append(QStringLiteral("Arial Unicode MS"));
+ // Since some symbols (specifically Braille) are not in Arial Unicode MS, we
+ // add Apple Symbols to cover those too.
+ if (!fallbackList.contains(QStringLiteral("Apple Symbols")))
+ fallbackList.append(QStringLiteral("Apple Symbols"));
#endif
- didPopulateStyleFallbacks = true;
- }
+ extern QStringList qt_sort_families_by_writing_system(QChar::Script, const QStringList &);
+ fallbackList = qt_sort_families_by_writing_system(script, fallbackList);
- Q_ASSERT(!fallbackLists.isEmpty());
- return fallbackLists[styleLookupKey.arg(styleHint)];
+ return fallbackList;
}
QStringList QCoreTextFontDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName)
diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h
index 05f6ed641c..45e74b99be 100644
--- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h
+++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h
@@ -92,6 +92,7 @@ protected:
private:
void populateFromDescriptor(CTFontDescriptorRef font, const QString &familyName = QString());
+ static QStringList fallbacksForFamily(const QString &family);
mutable QString defaultFontName;
diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp
index 737d85d5c3..a6e5c9b5ab 100644
--- a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp
+++ b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp
@@ -535,7 +535,7 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data)
m_currentData.state = Qt::TouchPointReleased;
if (m_typeB)
m_contacts[m_currentSlot].maj = m_currentData.maj;
- } else if (data->code == ABS_PRESSURE) {
+ } else if (data->code == ABS_PRESSURE || data->code == ABS_MT_PRESSURE) {
m_currentData.pressure = qBound(hw_pressure_min, data->value, hw_pressure_max);
if (m_typeB || m_singleTouch)
m_contacts[m_currentSlot].pressure = m_currentData.pressure;
diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro
index 78632a9bea..346df84038 100644
--- a/src/plugins/platforms/android/android.pro
+++ b/src/plugins/platforms/android/android.pro
@@ -93,7 +93,3 @@ qtConfig(vulkan) {
PLUGIN_TYPE = platforms
load(qt_plugin)
-
-#Non-standard install directory, QTBUG-29859
-DESTDIR = $$DESTDIR/android
-target.path = $${target.path}/android
diff --git a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm
index 9b6dc94d33..cb25bd7d81 100644
--- a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm
+++ b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
@@ -52,6 +52,8 @@
@property (class, strong, readonly) NSColor *unemphasizedSelectedTextColor NS_AVAILABLE_MAC(10_14);
@property (class, strong, readonly) NSColor *unemphasizedSelectedContentBackgroundColor NS_AVAILABLE_MAC(10_14);
@property (class, strong, readonly) NSArray<NSColor *> *alternatingContentBackgroundColors NS_AVAILABLE_MAC(10_14);
+// Missing from non-Mojave SDKs, even if introduced in 10.10
+@property (class, strong, readonly) NSColor *linkColor NS_AVAILABLE_MAC(10_10);
@end
#endif
@@ -111,6 +113,8 @@ QPalette * qt_mac_createSystemPalette()
palette->setBrush(QPalette::ToolTipBase, qt_mac_toQBrush([NSColor controlColor]));
+ palette->setColor(QPalette::Normal, QPalette::Link, qt_mac_toQColor([NSColor linkColor]));
+
return palette;
}
diff --git a/src/plugins/platforms/cocoa/qnsview_dragging.mm b/src/plugins/platforms/cocoa/qnsview_dragging.mm
index 37e972dba9..41b96b2df6 100644
--- a/src/plugins/platforms/cocoa/qnsview_dragging.mm
+++ b/src/plugins/platforms/cocoa/qnsview_dragging.mm
@@ -270,6 +270,7 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin
// The drag was started from within the application
response = QWindowSystemInterface::handleDrop(target, nativeDrag->dragMimeData(),
point, qtAllowed, buttons, modifiers);
+ nativeDrag->setAcceptedAction(response.acceptedAction());
} else {
QCocoaDropData mimeData(sender.draggingPasteboard);
response = QWindowSystemInterface::handleDrop(target, &mimeData,
@@ -282,6 +283,7 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin
{
Q_UNUSED(session);
Q_UNUSED(screenPoint);
+ Q_UNUSED(operation);
if (!m_platformWindow)
return;
@@ -290,8 +292,7 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin
if (!target)
return;
- QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
- nativeDrag->setAcceptedAction(qt_mac_mapNSDragOperation(operation));
+ QCocoaIntegration::instance()->drag();
// Qt starts drag-and-drop on a mouse button press event. Cococa in
// this case won't send the matching release event, so we have to
diff --git a/src/plugins/platforms/cocoa/qnswindow.mm b/src/plugins/platforms/cocoa/qnswindow.mm
index 68cb270457..6b4e110af2 100644
--- a/src/plugins/platforms/cocoa/qnswindow.mm
+++ b/src/plugins/platforms/cocoa/qnswindow.mm
@@ -255,8 +255,8 @@ static bool isMouseEvent(NSEvent *ev)
- (NSColor *)backgroundColor
{
- return self.styleMask & NSWindowStyleMaskTexturedBackground ?
- [super backgroundColor] : [NSColor clearColor];
+ return self.styleMask == NSWindowStyleMaskBorderless ?
+ [NSColor clearColor] : [super backgroundColor];
}
- (void)sendEvent:(NSEvent*)theEvent
diff --git a/src/plugins/platforms/eglfs/api/qeglfscursor_p.h b/src/plugins/platforms/eglfs/api/qeglfscursor_p.h
index 89c2e89f58..8768f9dd8c 100644
--- a/src/plugins/platforms/eglfs/api/qeglfscursor_p.h
+++ b/src/plugins/platforms/eglfs/api/qeglfscursor_p.h
@@ -59,6 +59,8 @@
#include <QtGui/QOpenGLShaderProgram>
#include <QtGui/private/qinputdevicemanager_p.h>
+#include <QtCore/qvector.h>
+
QT_BEGIN_NAMESPACE
class QOpenGLShaderProgram;
@@ -143,7 +145,7 @@ private:
int cursorsPerRow;
int width, height; // width and height of the atlas
int cursorWidth, cursorHeight; // width and height of cursors inside the atlas
- QList<QPoint> hotSpots;
+ QVector<QPoint> hotSpots;
QImage image; // valid until it's uploaded
} m_cursorAtlas;
diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h
index c96dd585d3..d47b579238 100644
--- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h
+++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_kms/qeglfskmsgbmcursor.h
@@ -41,7 +41,7 @@
#define QEGLFSKMSGBMCURSOR_H
#include <qpa/qplatformcursor.h>
-#include <QtCore/QList>
+#include <QtCore/QVector>
#include <QtGui/QImage>
#include <QtGui/private/qinputdevicemanager_p.h>
@@ -110,7 +110,7 @@ private:
int cursorsPerRow;
int width, height; // width and height of the atlas
int cursorWidth, cursorHeight; // width and height of cursors inside the atlas
- QList<QPoint> hotSpots;
+ QVector<QPoint> hotSpots;
QImage image;
} m_cursorAtlas;
};
diff --git a/src/plugins/platforms/windows/qwindowsglcontext.cpp b/src/plugins/platforms/windows/qwindowsglcontext.cpp
index dcdf9a5622..3591b2c505 100644
--- a/src/plugins/platforms/windows/qwindowsglcontext.cpp
+++ b/src/plugins/platforms/windows/qwindowsglcontext.cpp
@@ -196,6 +196,7 @@ bool QWindowsOpengl32DLL::init(bool softwareRendering)
wglShareLists = reinterpret_cast<BOOL (WINAPI *)(HGLRC, HGLRC)>(resolve("wglShareLists"));
wglSwapBuffers = reinterpret_cast<BOOL (WINAPI *)(HDC)>(resolve("wglSwapBuffers"));
wglSetPixelFormat = reinterpret_cast<BOOL (WINAPI *)(HDC, int, const PIXELFORMATDESCRIPTOR *)>(resolve("wglSetPixelFormat"));
+ wglDescribePixelFormat = reinterpret_cast<int (WINAPI *)(HDC, int, UINT, PIXELFORMATDESCRIPTOR *)>(resolve("wglDescribePixelFormat"));
glGetError = reinterpret_cast<GLenum (APIENTRY *)()>(resolve("glGetError"));
glGetIntegerv = reinterpret_cast<void (APIENTRY *)(GLenum , GLint *)>(resolve("glGetIntegerv"));
@@ -214,6 +215,11 @@ BOOL QWindowsOpengl32DLL::setPixelFormat(HDC dc, int pf, const PIXELFORMATDESCRI
return moduleIsNotOpengl32() ? wglSetPixelFormat(dc, pf, pfd) : SetPixelFormat(dc, pf, pfd);
}
+int QWindowsOpengl32DLL::describePixelFormat(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd)
+{
+ return moduleIsNotOpengl32() ? wglDescribePixelFormat(dc, pf, size, pfd) : DescribePixelFormat(dc, pf, size, pfd);
+}
+
QWindowsOpenGLContext *QOpenGLStaticContext::createContext(QOpenGLContext *context)
{
return new QWindowsGLContext(this, context);
@@ -322,11 +328,11 @@ static inline bool
static void describeFormats(HDC hdc)
{
- const int pfiMax = DescribePixelFormat(hdc, 0, 0, nullptr);
+ const int pfiMax = QOpenGLStaticContext::opengl32.describePixelFormat(hdc, 0, 0, nullptr);
for (int i = 1; i <= pfiMax; i++) {
PIXELFORMATDESCRIPTOR pfd;
initPixelFormatDescriptor(&pfd);
- DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
+ QOpenGLStaticContext::opengl32.describePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
qCDebug(lcQpaGl) << '#' << i << '/' << pfiMax << ':' << pfd;
}
}
@@ -617,7 +623,7 @@ static int choosePixelFormat(HDC hdc,
// Verify if format is acceptable. Note that the returned
// formats have been observed to not contain PFD_SUPPORT_OPENGL, ignore.
initPixelFormatDescriptor(obtainedPfd);
- DescribePixelFormat(hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), obtainedPfd);
+ QOpenGLStaticContext::opengl32.describePixelFormat(hdc, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), obtainedPfd);
if (!isAcceptableFormat(additional, *obtainedPfd, true)) {
qCDebug(lcQpaGl) << __FUNCTION__ << " obtained px #" << pixelFormat
<< " not acceptable=" << *obtainedPfd;
diff --git a/src/plugins/platforms/windows/qwindowsglcontext.h b/src/plugins/platforms/windows/qwindowsglcontext.h
index 1abe2eb390..e962af39c2 100644
--- a/src/plugins/platforms/windows/qwindowsglcontext.h
+++ b/src/plugins/platforms/windows/qwindowsglcontext.h
@@ -107,6 +107,7 @@ struct QWindowsOpengl32DLL
// Wrappers. Always use these instead of SwapBuffers/wglSwapBuffers/etc.
BOOL swapBuffers(HDC dc);
BOOL setPixelFormat(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd);
+ int describePixelFormat(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd);
// WGL
HGLRC (WINAPI * wglCreateContext)(HDC dc);
@@ -130,6 +131,7 @@ private:
// For Mesa llvmpipe shipped with a name other than opengl32.dll
BOOL (WINAPI * wglSwapBuffers)(HDC dc);
BOOL (WINAPI * wglSetPixelFormat)(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd);
+ int (WINAPI * wglDescribePixelFormat)(HDC dc, int pf, UINT size, PIXELFORMATDESCRIPTOR *pfd);
};
class QOpenGLStaticContext : public QWindowsStaticOpenGLContext
diff --git a/src/plugins/platforms/windows/qwindowsopengltester.cpp b/src/plugins/platforms/windows/qwindowsopengltester.cpp
index afc1991e2c..63ecbfe0ea 100644
--- a/src/plugins/platforms/windows/qwindowsopengltester.cpp
+++ b/src/plugins/platforms/windows/qwindowsopengltester.cpp
@@ -47,6 +47,7 @@
#include <QtCore/qfile.h>
#include <QtCore/qfileinfo.h>
#include <QtCore/qstandardpaths.h>
+#include <QtCore/qlibrary.h>
#include <QtCore/qlibraryinfo.h>
#include <QtCore/qhash.h>
@@ -57,6 +58,8 @@
#include <QtCore/qt_windows.h>
#include <private/qsystemlibrary_p.h>
#include <d3d9.h>
+#include <d3d10.h>
+#include <dxgi.h>
QT_BEGIN_NAMESPACE
@@ -80,52 +83,259 @@ static GpuDescription adapterIdentifierToGpuDescription(const D3DADAPTER_IDENTIF
return result;
}
-class QDirect3D9Handle
+class QGraphicsAdapterInfo
{
public:
- Q_DISABLE_COPY_MOVE(QDirect3D9Handle)
+ Q_DISABLE_COPY_MOVE(QGraphicsAdapterInfo)
- QDirect3D9Handle();
- ~QDirect3D9Handle();
+ QGraphicsAdapterInfo();
+ ~QGraphicsAdapterInfo();
- bool isValid() const { return m_direct3D9 != nullptr; }
+ bool isValid() const;
- UINT adapterCount() const { return m_direct3D9 ? m_direct3D9->GetAdapterCount() : 0u; }
+ UINT adapterCount() const;
bool retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const;
private:
+ QSystemLibrary m_dxgilib;
+ IDXGIFactory1 *m_dxgiFactory1 = nullptr;
+
QSystemLibrary m_d3d9lib;
IDirect3D9 *m_direct3D9 = nullptr;
+
+ /* This is a value from the DXGI_ADAPTER_FLAG enum.
+ * However, it's not available in dxgi.h from MinGW,
+ * so define it here in any case. */
+ enum { DXGI_ADAPTER_FLAG_SOFTWARE = 2 };
+
+ UINT adapterCountDXGI() const;
+ bool retrieveAdapterIdentifierDXGI(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const;
+
+ UINT adapterCountD3D9() const;
+ bool retrieveAdapterIdentifierD3D9(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const;
};
-QDirect3D9Handle::QDirect3D9Handle() :
+QGraphicsAdapterInfo::QGraphicsAdapterInfo() :
+ m_dxgilib(QStringLiteral("dxgi")),
m_d3d9lib(QStringLiteral("d3d9"))
{
- using PtrDirect3DCreate9 = IDirect3D9 *(WINAPI *)(UINT);
+ using PtrCreateDXGIFactory1 = HRESULT (WINAPI *)(REFIID, void**);
- if (m_d3d9lib.load()) {
- if (auto direct3DCreate9 = (PtrDirect3DCreate9)m_d3d9lib.resolve("Direct3DCreate9"))
- m_direct3D9 = direct3DCreate9(D3D_SDK_VERSION);
+ if (m_dxgilib.load()) {
+ if (auto createDXGIFactory1 = (PtrCreateDXGIFactory1)m_dxgilib.resolve("CreateDXGIFactory1"))
+ createDXGIFactory1(IID_PPV_ARGS(&m_dxgiFactory1));
+ }
+
+ if (!m_dxgiFactory1) {
+ using PtrDirect3DCreate9 = IDirect3D9 *(WINAPI *)(UINT);
+
+ if (m_d3d9lib.load()) {
+ if (auto direct3DCreate9 = (PtrDirect3DCreate9)m_d3d9lib.resolve("Direct3DCreate9"))
+ m_direct3D9 = direct3DCreate9(D3D_SDK_VERSION);
+ }
}
}
-QDirect3D9Handle::~QDirect3D9Handle()
+QGraphicsAdapterInfo::~QGraphicsAdapterInfo()
{
+ if (m_dxgiFactory1)
+ m_dxgiFactory1->Release();
if (m_direct3D9)
m_direct3D9->Release();
}
-bool QDirect3D9Handle::retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const
+bool QGraphicsAdapterInfo::isValid() const
+{
+ return m_dxgiFactory1 != nullptr || m_direct3D9 != nullptr;
+}
+
+UINT QGraphicsAdapterInfo::adapterCount() const
+{
+ if (m_dxgiFactory1)
+ return adapterCountDXGI();
+ if (m_direct3D9)
+ return adapterCountD3D9();
+ return 0;
+}
+
+bool QGraphicsAdapterInfo::retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const
+{
+ if (m_dxgiFactory1)
+ return retrieveAdapterIdentifierDXGI(n, adapterIdentifier);
+ if (m_direct3D9)
+ return retrieveAdapterIdentifierD3D9(n, adapterIdentifier);
+ return false;
+}
+
+UINT QGraphicsAdapterInfo::adapterCountDXGI() const
+{
+ /* DXGI doesn't have an adapterCount(), instead we have to call EnumAdapters1()
+ * until DXGI_ERROR_NOT_FOUND is returned. */
+ UINT n = 0;
+
+ IDXGIAdapter1 *adapter;
+ while (SUCCEEDED(m_dxgiFactory1->EnumAdapters1(n, &adapter))) {
+ adapter->Release();
+ ++n;
+ }
+
+ return n;
+}
+
+// Detect whether we are running under 64-bit Windows.
+static bool isWow64Process()
+{
+ typedef BOOL (WINAPI *IsWow64ProcessPtr)(HANDLE hProcess, PBOOL Wow64Process);
+ IsWow64ProcessPtr IsWow64Process = (IsWow64ProcessPtr)QLibrary::resolve(
+ QStringLiteral("kernel32.dll"), "IsWow64Process");
+
+ if (IsWow64Process) {
+ BOOL IsWow64 = FALSE;
+ if (IsWow64Process(GetCurrentProcess(), &IsWow64))
+ return IsWow64;
+ }
+ return false;
+}
+
+// Read a string value from registry
+static QString regGetString(HKEY key, const wchar_t* valueName)
+{
+ QVarLengthArray<wchar_t, MAX_PATH> buf (MAX_PATH);
+ LRESULT res;
+ DWORD bufSize = buf.size() * sizeof(wchar_t);
+ res = RegGetValue(key, nullptr, valueName,
+ RRF_RT_REG_SZ | RRF_RT_REG_MULTI_SZ, nullptr,
+ buf.data(), &bufSize);
+ if (res == ERROR_MORE_DATA) {
+ buf.resize(bufSize / sizeof(wchar_t));
+ bufSize = buf.size() * sizeof(wchar_t);
+ res = RegGetValue(key, nullptr, valueName,
+ RRF_RT_REG_SZ | RRF_RT_REG_MULTI_SZ, nullptr,
+ buf.data(), &bufSize);
+ }
+ /* In case of REG_MULTI_SZ, this returns just the first string,
+ * but that is sufficient for our purposes. */
+ if (res == ERROR_SUCCESS)
+ return QString::fromWCharArray(buf.data());
+ return QString();
+}
+
+// Read driver name given a DeviceKey
+static QString retrieveDriverName(const wchar_t *driverKey)
+{
+ /* Kernel-style prefix, maps to HKLM
+ * (see https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/registry-key-object-routines) */
+ static const wchar_t prefixMappingHKLM[] = L"\\Registry\\Machine\\";
+ const size_t prefixMappingHKLMLen = wcslen(prefixMappingHKLM);
+ if (wcsnicmp(driverKey, prefixMappingHKLM, prefixMappingHKLMLen) != 0)
+ return QString();
+
+ driverKey += prefixMappingHKLMLen;
+ QString driverPath;
+ HKEY key;
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, driverKey, 0, KEY_READ | KEY_WOW64_64KEY, &key) == ERROR_SUCCESS) {
+ const wchar_t *valueName =
+ isWow64Process() ? L"UserModeDriverNameWow" : L"UserModeDriverName";
+ driverPath = regGetString(key, valueName);
+ RegCloseKey(key);
+ }
+ if (!driverPath.isEmpty()) {
+ int fileNameSep = driverPath.lastIndexOf(QLatin1Char('\\'));
+ if (fileNameSep >= 0)
+ driverPath = driverPath.mid(fileNameSep + 1);
+ return driverPath;
+ }
+ return QString();
+}
+
+// Retrieve driver name for a display device from registry.
+static QString driverNameForDevice(const wchar_t *displayDevice)
+{
+ QString driverName;
+ DISPLAY_DEVICE dd;
+ memset(&dd, 0, sizeof(dd));
+ dd.cb = sizeof(dd);
+ for (int dev = 0; EnumDisplayDevices(nullptr, dev, &dd, 0); ++dev) {
+ if (wcsicmp(displayDevice, dd.DeviceName) == 0) {
+ // DeviceKey is documented as "internal", but it's a registry key in kernel format
+ driverName = retrieveDriverName(dd.DeviceKey);
+ break;
+ }
+ }
+ if (driverName.isEmpty()) {
+ /* Fall back to driver name from EnumDisplaySettings.
+ * This is only a fallback as on Windows 10 this just returns an device-independent
+ * name. OTOH, it's possible to recognize RDP connections from the driver name. */
+ DEVMODE devMode;
+ if (EnumDisplaySettings(displayDevice, ENUM_CURRENT_SETTINGS, &devMode))
+ driverName = QString::fromWCharArray(devMode.dmDeviceName);
+ }
+ return driverName;
+}
+
+bool QGraphicsAdapterInfo::retrieveAdapterIdentifierDXGI(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const
+{
+ IDXGIAdapter1 *adapter;
+ if (FAILED(m_dxgiFactory1->EnumAdapters1(n, &adapter)))
+ return false;
+
+ bool result = false;
+
+ DXGI_ADAPTER_DESC1 adapterDesc;
+ if (SUCCEEDED(adapter->GetDesc1(&adapterDesc))) {
+ if ((adapterDesc.VendorId != 0) && (adapterDesc.DeviceId != 0) // Don't use adapter description of Software Devices
+ && ((adapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) == 0)) {
+ memset(adapterIdentifier, 0, sizeof(*adapterIdentifier));
+ WideCharToMultiByte(1252, 0, adapterDesc.Description, -1,
+ adapterIdentifier->Description,
+ sizeof(adapterIdentifier->Description), nullptr, nullptr);
+ adapterIdentifier->Description[sizeof(adapterIdentifier->Description) - 1] = 0;
+ adapterIdentifier->VendorId = adapterDesc.VendorId;
+ adapterIdentifier->DeviceId = adapterDesc.DeviceId;
+ adapterIdentifier->SubSysId = adapterDesc.SubSysId;
+ adapterIdentifier->Revision = adapterDesc.Revision;
+
+ LARGE_INTEGER umdVersion;
+ if (SUCCEEDED(adapter->CheckInterfaceSupport(__uuidof(ID3D10Device), &umdVersion))) {
+ adapterIdentifier->DriverVersion = umdVersion;
+ result = true;
+ }
+
+ /* DXGI doesn't expose the driver name, but we can get it from the registry.
+ * But we need a device name to follow. */
+ IDXGIOutput *output = nullptr;
+ if (SUCCEEDED(adapter->EnumOutputs (0, &output))) {
+ DXGI_OUTPUT_DESC outputDesc;
+ if (SUCCEEDED(output->GetDesc (&outputDesc))) {
+ QString driverName = driverNameForDevice(outputDesc.DeviceName);
+ qstrncpy(adapterIdentifier->Driver, driverName.toLatin1().constData(),
+ sizeof(adapterIdentifier->Driver));
+ }
+ output->Release();
+ }
+ }
+ }
+
+ adapter->Release();
+
+ return result;
+}
+
+UINT QGraphicsAdapterInfo::adapterCountD3D9() const
+{
+ return m_direct3D9->GetAdapterCount();
+}
+
+bool QGraphicsAdapterInfo::retrieveAdapterIdentifierD3D9(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const
{
- return m_direct3D9
- && SUCCEEDED(m_direct3D9->GetAdapterIdentifier(n, 0, adapterIdentifier));
+ return SUCCEEDED(m_direct3D9->GetAdapterIdentifier(n, 0, adapterIdentifier));
}
GpuDescription GpuDescription::detect()
{
GpuDescription result;
- QDirect3D9Handle direct3D9;
- if (!direct3D9.isValid())
+ QGraphicsAdapterInfo adapterInfo;
+ if (!adapterInfo.isValid())
return result;
D3DADAPTER_IDENTIFIER9 adapterIdentifier;
@@ -136,7 +346,7 @@ GpuDescription GpuDescription::detect()
// and D3D uses by default. Therefore querying any additional adapters is
// futile and not useful for our purposes in general, except for
// identifying a few special cases later on.
- if (direct3D9.retrieveAdapterIdentifier(0, &adapterIdentifier)) {
+ if (adapterInfo.retrieveAdapterIdentifier(0, &adapterIdentifier)) {
result = adapterIdentifierToGpuDescription(adapterIdentifier);
isAMD = result.vendorId == VENDOR_ID_AMD;
}
@@ -145,9 +355,9 @@ GpuDescription GpuDescription::detect()
// when starting apps on a screen connected to the Intel card) by looking
// for a default AMD adapter and an additional non-AMD one.
if (isAMD) {
- const UINT adapterCount = direct3D9.adapterCount();
+ const UINT adapterCount = adapterInfo.adapterCount();
for (UINT adp = 1; adp < adapterCount; ++adp) {
- if (direct3D9.retrieveAdapterIdentifier(adp, &adapterIdentifier)
+ if (adapterInfo.retrieveAdapterIdentifier(adp, &adapterIdentifier)
&& adapterIdentifier.VendorId != VENDOR_ID_AMD) {
// Bingo. Now figure out the display for the AMD card.
DISPLAY_DEVICE dd;
@@ -172,11 +382,11 @@ GpuDescription GpuDescription::detect()
QVector<GpuDescription> GpuDescription::detectAll()
{
QVector<GpuDescription> result;
- QDirect3D9Handle direct3D9;
- if (const UINT adapterCount = direct3D9.adapterCount()) {
+ QGraphicsAdapterInfo adapterInfo;
+ if (const UINT adapterCount = adapterInfo.adapterCount()) {
for (UINT adp = 0; adp < adapterCount; ++adp) {
D3DADAPTER_IDENTIFIER9 adapterIdentifier;
- if (direct3D9.retrieveAdapterIdentifier(adp, &adapterIdentifier))
+ if (adapterInfo.retrieveAdapterIdentifier(adp, &adapterIdentifier))
result.append(adapterIdentifierToGpuDescription(adapterIdentifier));
}
}
diff --git a/src/plugins/platforms/windows/qwindowsscreen.cpp b/src/plugins/platforms/windows/qwindowsscreen.cpp
index 8cd09a34eb..df63adf558 100644
--- a/src/plugins/platforms/windows/qwindowsscreen.cpp
+++ b/src/plugins/platforms/windows/qwindowsscreen.cpp
@@ -42,6 +42,7 @@
#include "qwindowswindow.h"
#include "qwindowsintegration.h"
#include "qwindowscursor.h"
+#include "qwindowstheme.h"
#include <QtCore/qt_windows.h>
@@ -543,10 +544,13 @@ bool QWindowsScreenManager::handleScreenChanges()
// Look for changed monitors, add new ones
const WindowsScreenDataList newDataList = monitorData();
const bool lockScreen = newDataList.size() == 1 && (newDataList.front().flags & QWindowsScreenData::LockScreen);
+ bool primaryScreenChanged = false;
for (const QWindowsScreenData &newData : newDataList) {
const int existingIndex = indexOfMonitor(m_screens, newData.name);
if (existingIndex != -1) {
m_screens.at(existingIndex)->handleChanges(newData);
+ if (existingIndex == 0)
+ primaryScreenChanged = true;
} else {
auto *newScreen = new QWindowsScreen(newData);
m_screens.push_back(newScreen);
@@ -563,6 +567,8 @@ bool QWindowsScreenManager::handleScreenChanges()
removeScreen(i);
} // for existing screens
} // not lock screen
+ if (primaryScreenChanged)
+ QWindowsTheme::instance()->refreshFonts();
return true;
}
diff --git a/src/plugins/platforms/windows/qwindowstheme.h b/src/plugins/platforms/windows/qwindowstheme.h
index 4e24308445..07120230ce 100644
--- a/src/plugins/platforms/windows/qwindowstheme.h
+++ b/src/plugins/platforms/windows/qwindowstheme.h
@@ -85,6 +85,8 @@ public:
static bool useNativeMenus();
+ void refreshFonts();
+
static const char *name;
private:
@@ -92,7 +94,6 @@ private:
void clearPalettes();
void refreshPalettes();
void clearFonts();
- void refreshFonts();
void refreshIconPixmapSizes();
static QWindowsTheme *m_instance;
diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp
index 8e395669f8..d8b8f7281d 100644
--- a/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp
+++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiatextrangeprovider.cpp
@@ -48,6 +48,7 @@
#include <QtGui/qaccessible.h>
#include <QtCore/qloggingcategory.h>
#include <QtCore/qstring.h>
+#include <QtCore/qvarlengtharray.h>
QT_BEGIN_NAMESPACE
@@ -227,7 +228,7 @@ HRESULT QWindowsUiaTextRangeProvider::GetBoundingRectangles(SAFEARRAY **pRetVal)
return UIA_E_ELEMENTNOTAVAILABLE;
int len = textInterface->characterCount();
- QList<QRect> rectList;
+ QVarLengthArray<QRect> rectList;
if ((m_startOffset >= 0) && (m_endOffset <= len) && (m_startOffset < m_endOffset)) {
int start, end;
diff --git a/src/plugins/platforms/windows/windows.pri b/src/plugins/platforms/windows/windows.pri
index 95ba961df1..7de6369541 100644
--- a/src/plugins/platforms/windows/windows.pri
+++ b/src/plugins/platforms/windows/windows.pri
@@ -12,6 +12,8 @@ LIBS += -lshlwapi -lwtsapi32
QMAKE_USE_PRIVATE += \
advapi32 \
d3d9/nolink \
+ d3d11/nolink \
+ dxgi/nolink \
ole32 \
shell32 \
user32 \
diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp
index 524000b618..355dbf7d20 100644
--- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp
+++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp
@@ -51,6 +51,8 @@
#include <QtCore/QString>
#include <QtCore/private/qeventdispatcher_winrt_p.h>
+#include <memory>
+
QT_BEGIN_NAMESPACE
using namespace QWinRTUiAutomation;
@@ -105,19 +107,17 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaGridItemProvider::get_ContainingGrid(IIRawEle
*value = nullptr;
auto accid = id();
- auto elementId = QSharedPointer<QAccessible::Id>(new QAccessible::Id(0));
- auto ptrElementId = new QSharedPointer<QAccessible::Id>(elementId);
+ auto elementId = std::make_shared<QAccessible::Id>(0);
- if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementId]() {
+ if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId]() {
if (QAccessibleInterface *accessible = accessibleForId(accid)) {
if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) {
if (QAccessibleInterface *table = tableCellInterface->table()) {
- **ptrElementId = idForAccessible(table);
- QWinRTUiaMetadataCache::instance()->load(**ptrElementId);
+ *elementId = idForAccessible(table);
+ QWinRTUiaMetadataCache::instance()->load(*elementId);
}
}
}
- delete ptrElementId;
return S_OK;
}))) {
return E_FAIL;
diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp
index e469991de2..3bd90f6850 100644
--- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp
+++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp
@@ -51,6 +51,8 @@
#include <QtCore/QString>
#include <QtCore/private/qeventdispatcher_winrt_p.h>
+#include <memory>
+
QT_BEGIN_NAMESPACE
using namespace QWinRTUiAutomation;
@@ -104,21 +106,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaGridProvider::GetItem(INT32 row, INT32 column
*returnValue = nullptr;
auto accid = id();
- auto elementId = QSharedPointer<QAccessible::Id>(new QAccessible::Id(0));
- auto ptrElementId = new QSharedPointer<QAccessible::Id>(elementId);
+ auto elementId = std::make_shared<QAccessible::Id>(0);
- if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, row, column, ptrElementId]() {
+ if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, row, column, elementId]() {
if (QAccessibleInterface *accessible = accessibleForId(accid)) {
if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) {
if ((row >= 0) && (row < tableInterface->rowCount()) && (column >= 0) && (column < tableInterface->columnCount())) {
if (QAccessibleInterface *cell = tableInterface->cellAt(row, column)) {
- **ptrElementId = idForAccessible(cell);
- QWinRTUiaMetadataCache::instance()->load(**ptrElementId);
+ *elementId = idForAccessible(cell);
+ QWinRTUiaMetadataCache::instance()->load(*elementId);
}
}
}
}
- delete ptrElementId;
return S_OK;
}))) {
return E_FAIL;
diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp
index 6f3ad6dcd2..0b1db306bd 100644
--- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp
+++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp
@@ -64,6 +64,8 @@
#include <QtCore/qfunctions_winrt.h>
#include <QtCore/private/qeventdispatcher_winrt_p.h>
+#include <memory>
+
using namespace QWinRTUiAutomation;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
@@ -179,7 +181,7 @@ HRESULT QWinRTUiaMainProvider::rawProviderForAccessibleId(QAccessible::Id elemen
}
// Returns an array of IIRawElementProviderSimple instances for a list of accessible interface ids.
-HRESULT QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(const QList<QAccessible::Id> &elementIds,
+HRESULT QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(const QVarLengthArray<QAccessible::Id> &elementIds,
UINT32 *returnValueSize,
IIRawElementProviderSimple ***returnValue)
{
@@ -190,7 +192,7 @@ HRESULT QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(const QList<Q
QList<IIRawElementProviderSimple *> rawProviderList;
- for (auto elementId : qAsConst(elementIds)) {
+ for (auto elementId : elementIds) {
IIRawElementProviderSimple *rawProvider;
if (SUCCEEDED(rawProviderForAccessibleId(elementId, &rawProvider)))
rawProviderList.append(rawProvider);
@@ -515,10 +517,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetChildrenCore(IVector<Automat
*returnValue = nullptr;
auto accid = id();
- auto children = QSharedPointer<QList<QAccessible::Id>>(new QList<QAccessible::Id>);
- auto ptrChildren = new QSharedPointer<QList<QAccessible::Id>>(children);
+ auto children = std::make_shared<QVarLengthArray<QAccessible::Id>>();
- if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrChildren]() {
+ if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, children]() {
if (QAccessibleInterface *accessible = accessibleForId(accid)) {
int childCount = accessible->childCount();
for (int i = 0; i < childCount; ++i) {
@@ -526,11 +527,10 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetChildrenCore(IVector<Automat
QAccessible::Id childId = idForAccessible(childAcc);
QWinRTUiaMetadataCache::instance()->load(childId);
if (!childAcc->state().invisible)
- (*ptrChildren)->append(childId);
+ children->append(childId);
}
}
}
- delete ptrChildren;
return S_OK;
}))) {
return E_FAIL;
@@ -538,7 +538,7 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetChildrenCore(IVector<Automat
ComPtr<IVector<AutomationPeer *>> peerVector = Make<QWinRTUiaPeerVector>();
- for (auto childId : qAsConst(*children)) {
+ for (auto childId : *children) {
if (ComPtr<QWinRTUiaMainProvider> provider = providerForAccessibleId(childId)) {
IAutomationPeer *peer;
if (SUCCEEDED(provider.CopyTo(&peer)))
@@ -750,10 +750,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetPeerFromPointCore(ABI::Windo
// Scale coordinates from High DPI screens?
auto accid = id();
- auto elementId = QSharedPointer<QAccessible::Id>(new QAccessible::Id(0));
- auto ptrElementId = new QSharedPointer<QAccessible::Id>(elementId);
+ auto elementId = std::make_shared<QAccessible::Id>(0);
- if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementId, point]() {
+ if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId, point]() {
// Controls can be embedded within grouping elements. By default returns the innermost control.
QAccessibleInterface *target = accessibleForId(accid);
while (QAccessibleInterface *tmpacc = target->childAt(point.X, point.Y)) {
@@ -761,9 +760,8 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetPeerFromPointCore(ABI::Windo
// For accessibility tools it may be better to return the text element instead of its subcomponents.
if (target->textInterface()) break;
}
- **ptrElementId = idForAccessible(target);
- QWinRTUiaMetadataCache::instance()->load(**ptrElementId);
- delete ptrElementId;
+ *elementId = idForAccessible(target);
+ QWinRTUiaMetadataCache::instance()->load(*elementId);
return S_OK;
}))) {
return E_FAIL;
diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h
index 384a166cf7..23a6e56ae7 100644
--- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h
+++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h
@@ -69,7 +69,7 @@ public:
virtual ~QWinRTUiaMainProvider();
static QWinRTUiaMainProvider *providerForAccessibleId(QAccessible::Id id);
static HRESULT rawProviderForAccessibleId(QAccessible::Id elementId, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple **returnValue);
- static HRESULT rawProviderArrayForAccessibleIdList(const QList<QAccessible::Id> &elementIds, UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue);
+ static HRESULT rawProviderArrayForAccessibleIdList(const QVarLengthArray<QAccessible::Id> &elementIds, UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue);
static void notifyFocusChange(QAccessibleEvent *event);
static void notifyVisibilityChange(QAccessibleEvent *event);
static void notifyStateChange(QAccessibleStateChangeEvent *event);
diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp
index 9bc88272ba..2cb5aa685c 100644
--- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp
+++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp
@@ -51,6 +51,8 @@
#include <QtCore/QString>
#include <QtCore/private/qeventdispatcher_winrt_p.h>
+#include <memory>
+
QT_BEGIN_NAMESPACE
using namespace QWinRTUiAutomation;
@@ -94,21 +96,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionItemProvider::get_SelectionContainer
*value = nullptr;
auto accid = id();
- auto elementId = QSharedPointer<QAccessible::Id>(new QAccessible::Id(0));
- auto ptrElementId = new QSharedPointer<QAccessible::Id>(elementId);
+ auto elementId = std::make_shared<QAccessible::Id>(0);
- if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementId]() {
+ if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId]() {
if (QAccessibleInterface *accessible = accessibleForId(accid)) {
// Radio buttons do not require a container.
if (accessible->role() == QAccessible::ListItem) {
if (QAccessibleInterface *parent = accessible->parent()) {
if (parent->role() == QAccessible::List) {
- **ptrElementId = idForAccessible(parent);
+ *elementId = idForAccessible(parent);
}
}
}
}
- delete ptrElementId;
return S_OK;
}))) {
return E_FAIL;
diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp
index 9e61a8df61..4d825351c8 100644
--- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp
+++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp
@@ -51,6 +51,8 @@
#include <QtCore/QString>
#include <QtCore/private/qeventdispatcher_winrt_p.h>
+#include <memory>
+
QT_BEGIN_NAMESPACE
using namespace QWinRTUiAutomation;
@@ -89,10 +91,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::get_IsSelectionRequired(bo
*value = false;
auto accid = id();
- auto selectionRequired = QSharedPointer<bool>(new bool(false));
- auto ptrSelectionRequired = new QSharedPointer<bool>(selectionRequired);
+ auto selectionRequired = std::make_shared<bool>(false);
- if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrSelectionRequired]() {
+ if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, selectionRequired]() {
// Initially returns false if none are selected. After the first selection, it may be required.
bool anySelected = false;
if (QAccessibleInterface *accessible = accessibleForId(accid)) {
@@ -105,9 +106,8 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::get_IsSelectionRequired(bo
}
}
}
- **ptrSelectionRequired = anySelected && !accessible->state().multiSelectable && !accessible->state().extSelectable;
+ *selectionRequired = anySelected && !accessible->state().multiSelectable && !accessible->state().extSelectable;
}
- delete ptrSelectionRequired;
return S_OK;
}))) {
return E_FAIL;
@@ -128,10 +128,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::GetSelection(UINT32 *retur
*returnValue = nullptr;
auto accid = id();
- auto elementIds = QSharedPointer<QList<QAccessible::Id>>(new QList<QAccessible::Id>);
- auto ptrElementIds = new QSharedPointer<QList<QAccessible::Id>>(elementIds);
+ auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>();
- if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() {
+ if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() {
if (QAccessibleInterface *accessible = accessibleForId(accid)) {
int childCount = accessible->childCount();
for (int i = 0; i < childCount; ++i) {
@@ -139,12 +138,11 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::GetSelection(UINT32 *retur
if (childAcc->state().selected) {
QAccessible::Id childId = idForAccessible(childAcc);
QWinRTUiaMetadataCache::instance()->load(childId);
- (*ptrElementIds)->append(childId);
+ elementIds->append(childId);
}
}
}
}
- delete ptrElementIds;
return S_OK;
}))) {
return E_FAIL;
diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp
index 1af74a8b72..7cd953de87 100644
--- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp
+++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp
@@ -51,6 +51,8 @@
#include <QtCore/QString>
#include <QtCore/private/qeventdispatcher_winrt_p.h>
+#include <memory>
+
QT_BEGIN_NAMESPACE
using namespace QWinRTUiAutomation;
@@ -79,21 +81,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableItemProvider::GetColumnHeaderItems(UINT3
*returnValue = nullptr;
auto accid = id();
- auto elementIds = QSharedPointer<QList<QAccessible::Id>>(new QList<QAccessible::Id>);
- auto ptrElementIds = new QSharedPointer<QList<QAccessible::Id>>(elementIds);
+ auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>();
- if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() {
+ if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() {
if (QAccessibleInterface *accessible = accessibleForId(accid)) {
if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) {
QList<QAccessibleInterface *> headers = tableCellInterface->columnHeaderCells();
for (auto header : qAsConst(headers)) {
QAccessible::Id headerId = idForAccessible(header);
QWinRTUiaMetadataCache::instance()->load(headerId);
- (*ptrElementIds)->append(headerId);
+ elementIds->append(headerId);
}
}
}
- delete ptrElementIds;
return S_OK;
}))) {
return E_FAIL;
@@ -113,21 +113,19 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableItemProvider::GetRowHeaderItems(UINT32 *
*returnValue = nullptr;
auto accid = id();
- auto elementIds = QSharedPointer<QList<QAccessible::Id>>(new QList<QAccessible::Id>);
- auto ptrElementIds = new QSharedPointer<QList<QAccessible::Id>>(elementIds);
+ auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>();
- if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() {
+ if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() {
if (QAccessibleInterface *accessible = accessibleForId(accid)) {
if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) {
QList<QAccessibleInterface *> headers = tableCellInterface->rowHeaderCells();
for (auto header : qAsConst(headers)) {
QAccessible::Id headerId = idForAccessible(header);
QWinRTUiaMetadataCache::instance()->load(headerId);
- (*ptrElementIds)->append(headerId);
+ elementIds->append(headerId);
}
}
}
- delete ptrElementIds;
return S_OK;
}))) {
return E_FAIL;
diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp
index e71ade3c1f..d763b320b1 100644
--- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp
+++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp
@@ -51,6 +51,8 @@
#include <QtCore/QString>
#include <QtCore/private/qeventdispatcher_winrt_p.h>
+#include <memory>
+
QT_BEGIN_NAMESPACE
using namespace QWinRTUiAutomation;
@@ -91,10 +93,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetColumnHeaders(UINT32 *retur
*returnValue = nullptr;
auto accid = id();
- auto elementIds = QSharedPointer<QList<QAccessible::Id>>(new QList<QAccessible::Id>);
- auto ptrElementIds = new QSharedPointer<QList<QAccessible::Id>>(elementIds);
+ auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>();
- if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() {
+ if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() {
if (QAccessibleInterface *accessible = accessibleForId(accid)) {
if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) {
for (int i = 0; i < tableInterface->columnCount(); ++i) {
@@ -105,14 +106,13 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetColumnHeaders(UINT32 *retur
for (auto header : qAsConst(headers)) {
QAccessible::Id headerId = idForAccessible(header);
QWinRTUiaMetadataCache::instance()->load(headerId);
- (*ptrElementIds)->append(headerId);
+ elementIds->append(headerId);
}
}
}
}
}
}
- delete ptrElementIds;
return S_OK;
}))) {
return E_FAIL;
@@ -132,10 +132,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetRowHeaders(UINT32 *returnVa
*returnValue = nullptr;
auto accid = id();
- auto elementIds = QSharedPointer<QList<QAccessible::Id>>(new QList<QAccessible::Id>);
- auto ptrElementIds = new QSharedPointer<QList<QAccessible::Id>>(elementIds);
+ auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>();
- if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrElementIds]() {
+ if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() {
if (QAccessibleInterface *accessible = accessibleForId(accid)) {
if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) {
for (int i = 0; i < tableInterface->rowCount(); ++i) {
@@ -146,14 +145,13 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetRowHeaders(UINT32 *returnVa
for (auto header : qAsConst(headers)) {
QAccessible::Id headerId = idForAccessible(header);
QWinRTUiaMetadataCache::instance()->load(headerId);
- (*ptrElementIds)->append(headerId);
+ elementIds->append(headerId);
}
}
}
}
}
}
- delete ptrElementIds;
return S_OK;
}))) {
return E_FAIL;
diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp
index aa120377df..cd7420f360 100644
--- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp
+++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp
@@ -51,6 +51,8 @@
#include <QtCore/QString>
#include <QtCore/private/qeventdispatcher_winrt_p.h>
+#include <memory>
+
QT_BEGIN_NAMESPACE
using namespace QWinRTUiAutomation;
@@ -104,26 +106,26 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::GetSelection(UINT32 *returnValu
*returnValueSize = 0;
*returnValue = nullptr;
+ struct Selection { int startOffset, endOffset; };
+
auto accid = id();
- auto selections = QSharedPointer<QList<QPair<int,int>>>(new QList<QPair<int,int>>);
- auto ptrSelections = new QSharedPointer<QList<QPair<int,int>>>(selections);
+ auto selections = std::make_shared<QVarLengthArray<Selection>>();
- if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, ptrSelections]() {
+ if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, selections]() {
if (QAccessibleInterface *accessible = accessibleForId(accid)) {
if (QAccessibleTextInterface *textInterface = accessible->textInterface()) {
for (int i = 0; i < textInterface->selectionCount(); ++i) {
- QPair<int,int> sel;
- textInterface->selection(i, &sel.first, &sel.second);
- (*ptrSelections)->append(sel);
+ int startOffset, endOffset;
+ textInterface->selection(i, &startOffset, &endOffset);
+ selections->append({startOffset, endOffset});
}
- if ((*ptrSelections)->size() == 0) {
+ if (selections->size() == 0) {
// If there is no selection, we return an array with a single degenerate (empty) text range at the cursor position.
- QPair<int,int> sel(textInterface->cursorPosition(), textInterface->cursorPosition());
- (*ptrSelections)->append(sel);
+ auto cur = textInterface->cursorPosition();
+ selections->append({cur, cur});
}
}
}
- delete ptrSelections;
return S_OK;
}))) {
return E_FAIL;
@@ -137,9 +139,11 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::GetSelection(UINT32 *returnValu
if (!providerArray)
return E_OUTOFMEMORY;
- for (int i = 0; i < selCount; ++i) {
- ComPtr<QWinRTUiaTextRangeProvider> textRangeProvider = Make<QWinRTUiaTextRangeProvider>(id(), (*selections)[i].first, (*selections)[i].second);
- textRangeProvider.CopyTo(&providerArray[i]);
+ auto dst = providerArray;
+ for (auto sel : *selections) {
+ ComPtr<QWinRTUiaTextRangeProvider> textRangeProvider
+ = Make<QWinRTUiaTextRangeProvider>(id(), sel.startOffset, sel.endOffset);
+ textRangeProvider.CopyTo(dst++);
}
*returnValueSize = selCount;
*returnValue = providerArray;
@@ -184,14 +188,12 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::RangeFromPoint(ABI::Windows::Fo
const QPoint pt(screenLocation.X, screenLocation.Y);
auto accid = id();
- auto offset = QSharedPointer<int>(new int);
- auto ptrOffset = new QSharedPointer<int>(offset);
+ auto offset = std::make_shared<int>();
- if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, pt, ptrOffset]() {
+ if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, pt, offset]() {
if (QAccessibleInterface *accessible = accessibleForId(accid))
if (QAccessibleTextInterface *textInterface = accessible->textInterface())
- **ptrOffset = qBound(0, textInterface->offsetAtPoint(pt), textInterface->characterCount() - 1);
- delete ptrOffset;
+ *offset = qBound(0, textInterface->offsetAtPoint(pt), textInterface->characterCount() - 1);
return S_OK;
}))) {
return E_FAIL;
diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp
index fc3778d652..ca15feaff9 100644
--- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp
+++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp
@@ -51,6 +51,8 @@
#include <QtCore/QString>
#include <QtCore/private/qeventdispatcher_winrt_p.h>
+#include <memory>
+
QT_BEGIN_NAMESPACE
using namespace QWinRTUiAutomation;
@@ -212,10 +214,9 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT
auto accid = id();
auto startOffset = m_startOffset;
auto endOffset = m_endOffset;
- auto rects = QSharedPointer<QList<QRect>>(new QList<QRect>);
- auto ptrRects = new QSharedPointer<QList<QRect>>(rects);
+ auto rects = std::make_shared<QVarLengthArray<QRect>>();
- if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, startOffset, endOffset, ptrRects]() {
+ if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, startOffset, endOffset, rects]() {
if (QAccessibleInterface *accessible = accessibleForId(accid)) {
if (QAccessibleTextInterface *textInterface = accessible->textInterface()) {
int len = textInterface->characterCount();
@@ -233,7 +234,7 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT
qMin(startRect.y(), endRect.y()),
qMax(startRect.x() + startRect.width(), endRect.x() + endRect.width()) - qMin(startRect.x(), endRect.x()),
qMax(startRect.y() + startRect.height(), endRect.y() + endRect.height()) - qMin(startRect.y(), endRect.y()));
- (*ptrRects)->append(lineRect);
+ rects->append(lineRect);
}
if (end >= len) break;
textInterface->textAfterOffset(end + 1, QAccessible::LineBoundary, &start, &end);
@@ -241,7 +242,6 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT
}
}
}
- delete ptrRects;
return S_OK;
}))) {
return E_FAIL;
@@ -251,11 +251,12 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT
if (!doubleArray)
return E_OUTOFMEMORY;
- for (int i = 0; i < rects->size(); ++i) {
- doubleArray[i*4] = (*rects)[i].left();
- doubleArray[i*4+1] = (*rects)[i].top();
- doubleArray[i*4+2] = (*rects)[i].width();
- doubleArray[i*4+3] = (*rects)[i].height();
+ DOUBLE *dst = doubleArray;
+ for (auto rect : *rects) {
+ *dst++ = rect.left();
+ *dst++ = rect.top();
+ *dst++ = rect.width();
+ *dst++ = rect.height();
}
*returnValue = doubleArray;
*returnValueSize = 4 * rects->size();
diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp
index 21389b74d2..255d8ee49e 100644
--- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp
+++ b/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp
@@ -96,24 +96,22 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaValueProvider::SetValue(HSTRING value)
qCDebug(lcQpaUiAutomation) << __FUNCTION__;
auto accid = id();
- auto tmpValue = QSharedPointer<QString>(new QString);
- auto ptrValue = new QSharedPointer<QString>(tmpValue);
- *tmpValue = hStrToQStr(value);
+ QString tmpValue = hStrToQStr(value);
- QEventDispatcherWinRT::runOnMainThread([accid, ptrValue]() {
+ QEventDispatcherWinRT::runOnMainThread([accid, tmpValue]() {
if (QAccessibleInterface *accessible = accessibleForId(accid)) {
// First sets the value as a text.
- accessible->setText(QAccessible::Value, **ptrValue);
+ accessible->setText(QAccessible::Value, tmpValue);
// Then, if the control supports the value interface (range value)
// and the supplied text can be converted to a number, and that number
// lies within the min/max limits, sets it as the control's current (numeric) value.
if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) {
bool ok = false;
- double numval = (*ptrValue)->toDouble(&ok);
+ double numval = tmpValue.toDouble(&ok);
if (ok) {
double minimum = valueInterface->minimumValue().toDouble();
double maximum = valueInterface->maximumValue().toDouble();
@@ -124,7 +122,6 @@ HRESULT STDMETHODCALLTYPE QWinRTUiaValueProvider::SetValue(HSTRING value)
}
}
QWinRTUiaMetadataCache::instance()->load(accid);
- delete ptrValue;
return S_OK;
}, 0);
diff --git a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
index 5e5fefca90..2b77062b16 100644
--- a/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
+++ b/src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp
@@ -63,6 +63,7 @@
QT_BEGIN_NAMESPACE
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
+typedef const GLubyte *(*glGetStringiProc)(GLenum, GLuint);
#ifndef GLX_CONTEXT_CORE_PROFILE_BIT_ARB
#define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
@@ -145,6 +146,27 @@ static inline QByteArray getGlString(GLenum param)
return QByteArray();
}
+static bool hasGlExtension(const QSurfaceFormat &format, const char *ext)
+{
+ if (format.majorVersion() < 3) {
+ auto exts = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
+ return exts && strstr(exts, ext);
+ } else {
+ auto glGetStringi = reinterpret_cast<glGetStringiProc>(
+ glXGetProcAddress(reinterpret_cast<const GLubyte*>("glGetStringi")));
+ if (glGetStringi) {
+ GLint n = 0;
+ glGetIntegerv(GL_NUM_EXTENSIONS, &n);
+ for (GLint i = 0; i < n; ++i) {
+ const char *p = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i));
+ if (p && !strcmp(p, ext))
+ return true;
+ }
+ }
+ return false;
+ }
+}
+
static void updateFormatFromContext(QSurfaceFormat &format)
{
// Update the version, profile, and context bit of the format
@@ -163,7 +185,7 @@ static void updateFormatFromContext(QSurfaceFormat &format)
format.setOption(QSurfaceFormat::StereoBuffers);
if (format.renderableType() == QSurfaceFormat::OpenGL) {
- if (format.version() >= qMakePair(4, 0)) {
+ if (hasGlExtension(format, "GL_ARB_robustness")) {
GLint value = 0;
glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &value);
if (value == GL_LOSE_CONTEXT_ON_RESET_ARB)
diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp
index 0bae45382d..28be7bdc38 100644
--- a/src/plugins/sqldrivers/psql/qsql_psql.cpp
+++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp
@@ -428,12 +428,14 @@ static QVariant::Type qDecodePSQLType(int t)
void QPSQLResultPrivate::deallocatePreparedStmt()
{
- const QString stmt = QStringLiteral("DEALLOCATE ") + preparedStmtId;
- PGresult *result = drv_d_func()->exec(stmt);
+ if (drv_d_func()) {
+ const QString stmt = QStringLiteral("DEALLOCATE ") + preparedStmtId;
+ PGresult *result = drv_d_func()->exec(stmt);
- if (PQresultStatus(result) != PGRES_COMMAND_OK)
- qWarning("Unable to free statement: %s", PQerrorMessage(drv_d_func()->connection));
- PQclear(result);
+ if (PQresultStatus(result) != PGRES_COMMAND_OK)
+ qWarning("Unable to free statement: %s", PQerrorMessage(drv_d_func()->connection));
+ PQclear(result);
+ }
preparedStmtId.clear();
}
diff --git a/src/plugins/styles/windowsvista/main.cpp b/src/plugins/styles/windowsvista/main.cpp
index d5048e45b7..5e7bcf5e6e 100644
--- a/src/plugins/styles/windowsvista/main.cpp
+++ b/src/plugins/styles/windowsvista/main.cpp
@@ -48,7 +48,7 @@ class QWindowsVistaStylePlugin : public QStylePlugin
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "windowsvistastyle.json")
public:
- QStyle *create(const QString &key);
+ QStyle *create(const QString &key) override;
};
QStyle *QWindowsVistaStylePlugin::create(const QString &key)
@@ -56,7 +56,7 @@ QStyle *QWindowsVistaStylePlugin::create(const QString &key)
if (key.compare(QLatin1String("windowsvista"), Qt::CaseInsensitive) == 0)
return new QWindowsVistaStyle();
- return 0;
+ return nullptr;
}
QT_END_NAMESPACE
diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp
index c4ada66ca9..e213d65946 100644
--- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp
+++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp
@@ -44,7 +44,6 @@
#include <qwindow.h>
#include <private/qstyleanimation_p.h>
#include <private/qstylehelper_p.h>
-#include <private/qapplication_p.h>
#include <qpa/qplatformnativeinterface.h>
QT_BEGIN_NAMESPACE
@@ -84,15 +83,14 @@ static const int windowsRightBorder = 15; // right border on windows
*/
bool QWindowsVistaStylePrivate::useVista()
{
- return QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista
- && QWindowsVistaStylePrivate::useXP();
+ return QWindowsVistaStylePrivate::useXP();
}
/* \internal
Checks and returns the style object
*/
inline QObject *styleObject(const QStyleOption *option) {
- return option ? option->styleObject : 0;
+ return option ? option->styleObject : nullptr;
}
/* \internal
@@ -117,7 +115,7 @@ static inline QImage createAnimationBuffer(const QStyleOption *option, const QWi
Used by animations to clone a styleoption and shift its offset
*/
QStyleOption *clonedAnimationStyleOption(const QStyleOption*option) {
- QStyleOption *styleOption = 0;
+ QStyleOption *styleOption = nullptr;
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider*>(option))
styleOption = new QStyleOptionSlider(*slider);
else if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox*>(option))
@@ -298,7 +296,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
int oldState = styleObject->property("_q_stylestate").toInt();
oldRect = styleObject->property("_q_stylerect").toRect();
newRect = option->rect;
- styleObject->setProperty("_q_stylestate", (int)option->state);
+ styleObject->setProperty("_q_stylestate", int(option->state));
styleObject->setProperty("_q_stylerect", option->rect);
bool doTransition = oldState &&
@@ -316,7 +314,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
if (doTransition) {
QStyleOption *styleOption = clonedAnimationStyleOption(option);
- styleOption->state = (QStyle::State)oldState;
+ styleOption->state = QStyle::State(oldState);
QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
QWindowsVistaTransition *t = new QWindowsVistaTransition(styleObject);
@@ -341,7 +339,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
// The end state of the transition is simply the result we would have painted
// if the style was not animated.
- styleOption->styleObject = 0;
+ styleOption->styleObject = nullptr;
styleOption->state = option->state;
proxy()->drawPrimitive(element, styleOption, &endPainter, widget);
@@ -356,7 +354,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
//translate state flags to UXTHEME states :
if (element == PE_FrameLineEdit) {
- theme = OpenThemeData(0, L"Edit");
+ theme = OpenThemeData(nullptr, L"Edit");
partId = EP_EDITBORDER_NOSCROLL;
if (oldState & State_MouseOver)
@@ -374,7 +372,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
toState = ETS_NORMAL;
} else {
- theme = OpenThemeData(0, L"Button");
+ theme = OpenThemeData(nullptr, L"Button");
if (element == PE_IndicatorRadioButton)
partId = BP_RADIOBUTTON;
else if (element == PE_IndicatorCheckBox)
@@ -390,7 +388,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
if (theme
&& SUCCEEDED(GetThemeTransitionDuration(theme, partId, fromState, toState,
TMT_TRANSITIONDURATIONS, &duration))) {
- t->setDuration(duration);
+ t->setDuration(int(duration));
}
t->setStartTime(QTime::currentTime());
@@ -535,7 +533,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
else if (state & State_MouseOver)
stateId = EBS_HOT;
- XPThemeData theme(0, painter, QWindowsXPStylePrivate::EditTheme,
+ XPThemeData theme(nullptr, painter, QWindowsXPStylePrivate::EditTheme,
partId, stateId, rect);
if (!theme.isValid()) {
QWindowsStyle::drawPrimitive(element, option, painter, widget);
@@ -582,27 +580,26 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
p->drawRect(option->rect.adjusted(0, 0, -1, -1));
p->setPen(oldPen);
return;
- } else {
- int stateId = ETS_NORMAL;
- if (!(state & State_Enabled))
- stateId = ETS_DISABLED;
- else if (state & State_ReadOnly)
- stateId = ETS_READONLY;
- else if (state & State_MouseOver)
- stateId = ETS_HOT;
- else if (state & State_HasFocus)
- stateId = ETS_SELECTED;
- XPThemeData theme(widget, painter,
- QWindowsXPStylePrivate::EditTheme,
- EP_EDITBORDER_NOSCROLL, stateId, option->rect);
- theme.noContent = true;
- painter->save();
- QRegion clipRegion = option->rect;
- clipRegion -= option->rect.adjusted(2, 2, -2, -2);
- painter->setClipRegion(clipRegion);
- d->drawBackground(theme);
- painter->restore();
}
+ int stateId = ETS_NORMAL;
+ if (!(state & State_Enabled))
+ stateId = ETS_DISABLED;
+ else if (state & State_ReadOnly)
+ stateId = ETS_READONLY;
+ else if (state & State_MouseOver)
+ stateId = ETS_HOT;
+ else if (state & State_HasFocus)
+ stateId = ETS_SELECTED;
+ XPThemeData theme(widget, painter,
+ QWindowsXPStylePrivate::EditTheme,
+ EP_EDITBORDER_NOSCROLL, stateId, option->rect);
+ theme.noContent = true;
+ painter->save();
+ QRegion clipRegion = option->rect;
+ clipRegion -= option->rect.adjusted(2, 2, -2, -2);
+ painter->setClipRegion(clipRegion);
+ d->drawBackground(theme);
+ painter->restore();
}
break;
@@ -725,7 +722,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
d->drawBackground(theme);
} else {
QWindowsXPStyle::drawPrimitive(PE_PanelItemViewItem, option, painter, widget);
- break;;
+ break;
}
QPixmapCache::insert(key, pixmap);
}
@@ -771,7 +768,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
case PE_Widget:
{
#if QT_CONFIG(dialogbuttonbox)
- const QDialogButtonBox *buttonBox = 0;
+ const QDialogButtonBox *buttonBox = nullptr;
if (qobject_cast<const QMessageBox *> (widget))
buttonBox = widget->findChild<const QDialogButtonBox *>(QLatin1String("qt_msgbox_buttonbox"));
@@ -845,7 +842,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
int oldState = styleObject->property("_q_stylestate").toInt();
oldRect = styleObject->property("_q_stylerect").toRect();
newRect = option->rect;
- styleObject->setProperty("_q_stylestate", (int)option->state);
+ styleObject->setProperty("_q_stylestate", int(option->state));
styleObject->setProperty("_q_stylerect", option->rect);
bool wasDefault = false;
@@ -871,7 +868,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
QWindowsVistaTransition *t = new QWindowsVistaTransition(styleObject);
QWindowsVistaAnimation *anim = qobject_cast<QWindowsVistaAnimation *>(d->animation(styleObject));
QStyleOption *styleOption = clonedAnimationStyleOption(option);
- styleOption->state = (QStyle::State)oldState;
+ styleOption->state = QStyle::State(oldState);
QImage startImage = createAnimationBuffer(option, widget);
QPainter startPainter(&startImage);
@@ -893,12 +890,12 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
DWORD duration = 0;
- const HTHEME theme = OpenThemeData(0, L"Button");
+ const HTHEME theme = OpenThemeData(nullptr, L"Button");
int fromState = buttonStateId(oldState, BP_PUSHBUTTON);
int toState = buttonStateId(option->state, BP_PUSHBUTTON);
if (GetThemeTransitionDuration(theme, BP_PUSHBUTTON, fromState, toState, TMT_TRANSITIONDURATIONS, &duration) == S_OK)
- t->setDuration(duration);
+ t->setDuration(int(duration));
else
t->setDuration(0);
t->setStartTime(QTime::currentTime());
@@ -984,7 +981,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
if (btn->features & QStyleOptionButton::HasMenu) {
int mbiw = 0, mbih = 0;
- XPThemeData theme(widget, 0, QWindowsXPStylePrivate::ToolBarTheme,
+ XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::ToolBarTheme,
TP_DROPDOWNBUTTON);
if (theme.isValid()) {
const QSizeF size = theme.size() * QStyleHelper::dpiScaled(1, option);
@@ -993,7 +990,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
mbih = qRound(size.height());
}
}
- QRect ir = subElementRect(SE_PushButtonContents, option, 0);
+ QRect ir = subElementRect(SE_PushButtonContents, option, nullptr);
QStyleOptionButton newBtn = *btn;
newBtn.rect = QStyle::visualRect(option->direction, option->rect,
QRect(ir.right() - mbiw - 2,
@@ -1138,7 +1135,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
QPalette::ColorRole textRole = disabled ? QPalette::Text : QPalette::ButtonText;
QPixmap pix = mbi->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), QIcon::Normal);
- uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
+ int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget))
alignment |= Qt::TextHideMnemonic;
@@ -1178,7 +1175,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
int checkcol = qRound(qreal(25) * factor);
const int gutterWidth = qRound(qreal(3) * factor);
{
- XPThemeData theme(widget, 0, QWindowsXPStylePrivate::MenuTheme,
+ XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::MenuTheme,
MENU_POPUPCHECKBACKGROUND, MBI_HOT);
XPThemeData themeSize = theme;
themeSize.partId = MENU_POPUPCHECK;
@@ -1395,7 +1392,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
int mw = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, dwOpt, widget);
int fw = proxy()->pixelMetric(PM_DockWidgetFrameWidth, dwOpt, widget);
const QDockWidget *dw = qobject_cast<const QDockWidget *>(widget);
- bool isFloating = dw != 0 && dw->isFloating();
+ bool isFloating = dw && dw->isFloating();
QRect r = option->rect.adjusted(0, 2, -1, -3);
QRect titleRect = r;
@@ -1412,7 +1409,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
if (isFloating) {
titleRect.adjust(0, -fw, 0, 0);
- if (widget != 0 && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey())
+ if (widget && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey())
titleRect.adjust(titleRect.height() + mw, 0, 0, 0);
} else {
titleRect.adjust(mw, 0, 0, 0);
@@ -1518,8 +1515,8 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle
int oldActiveControls = styleObject->property("_q_stylecontrols").toInt();
QRect oldRect = styleObject->property("_q_stylerect").toRect();
- styleObject->setProperty("_q_stylestate", (int)option->state);
- styleObject->setProperty("_q_stylecontrols", (int)option->activeSubControls);
+ styleObject->setProperty("_q_stylestate", int(option->state));
+ styleObject->setProperty("_q_stylecontrols", int(option->activeSubControls));
styleObject->setProperty("_q_stylerect", option->rect);
bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken) ||
@@ -1563,8 +1560,8 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle
// Draw transition source
if (!anim) {
- styleOption->state = (QStyle::State)oldState;
- styleOption->activeSubControls = (QStyle::SubControl)oldActiveControls;
+ styleOption->state = QStyle::State(oldState);
+ styleOption->activeSubControls = QStyle::SubControl(oldActiveControls);
proxy()->drawComplexControl(control, styleOption, &startPainter, widget);
} else {
anim->paint(&startPainter, option);
@@ -1815,7 +1812,7 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle
// That however breaks with QtQuickControls where this results in transparent
// spinbox background, so if there's no "widget" passed (QtQuickControls case),
// let ftheme.noContent be false, which fixes the spinbox rendering in QQC
- ftheme.noContent = (widget != NULL);
+ ftheme.noContent = (widget != nullptr);
d->drawBackground(ftheme);
}
if (sub & SC_SpinBoxUp) {
@@ -1872,7 +1869,7 @@ QSize QWindowsVistaStyle::sizeFromContents(ContentsType type, const QStyleOption
sz = QWindowsXPStyle::sizeFromContents(type, option, size, widget);
int minimumHeight;
{
- XPThemeData theme(widget, 0,
+ XPThemeData theme(widget, nullptr,
QWindowsXPStylePrivate::MenuTheme,
MENU_POPUPCHECKBACKGROUND, MBI_HOT);
XPThemeData themeSize = theme;
@@ -1940,7 +1937,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption
case SE_PushButtonContents:
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
MARGINS borderSize;
- const HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : 0, L"Button");
+ const HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : nullptr, L"Button");
if (theme) {
int stateId = PBS_NORMAL;
if (!(option->state & State_Enabled))
@@ -1955,7 +1952,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption
int border = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget);
rect = option->rect.adjusted(border, border, -border, -border);
- if (SUCCEEDED(GetThemeMargins(theme, NULL, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, NULL, &borderSize))) {
+ if (SUCCEEDED(GetThemeMargins(theme, nullptr, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, nullptr, &borderSize))) {
rect.adjust(borderSize.cxLeftWidth, borderSize.cyTopHeight,
-borderSize.cxRightWidth, -borderSize.cyBottomHeight);
rect = visualRect(option->direction, option->rect, rect);
@@ -1973,7 +1970,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption
int y = option->rect.y();
int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, option, widget);
- XPThemeData theme(widget, 0,
+ XPThemeData theme(widget, nullptr,
QWindowsXPStylePrivate::HeaderTheme,
HP_HEADERSORTARROW, HSAS_SORTEDDOWN, option->rect);
@@ -2046,7 +2043,7 @@ static bool buttonVisible(const QStyle::SubControl sc, const QStyleOptionTitleBa
bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
bool isMaximized = tb->titleBarState & Qt::WindowMaximized;
- const uint flags = tb->titleBarFlags;
+ const auto flags = tb->titleBarFlags;
bool retVal = false;
switch (sc) {
case QStyle::SC_TitleBarContextHelpButton:
@@ -2104,7 +2101,7 @@ int QWindowsVistaStyle::styleHint(StyleHint hint, const QStyleOption *option, co
if (option) {
if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) {
ret = true;
- XPThemeData themeData(widget, 0,
+ XPThemeData themeData(widget, nullptr,
QWindowsXPStylePrivate::ToolTipTheme,
TTP_STANDARD, TTSS_NORMAL, option->rect);
mask->region = d->region(themeData);
@@ -2113,7 +2110,7 @@ int QWindowsVistaStyle::styleHint(StyleHint hint, const QStyleOption *option, co
break;
case SH_Table_GridLineColor:
if (option)
- ret = option->palette.color(QPalette::Base).darker(118).rgb();
+ ret = int(option->palette.color(QPalette::Base).darker(118).rgb());
else
ret = -1;
break;
@@ -2324,7 +2321,7 @@ void QWindowsVistaStyle::polish(QWidget *widget)
//we do not have to care about unpolishing
widget->setContentsMargins(3, 0, 4, 0);
COLORREF bgRef;
- HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : 0, L"TOOLTIP");
+ HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : nullptr, L"TOOLTIP");
if (theme && SUCCEEDED(GetThemeColor(theme, TTP_STANDARD, TTSS_NORMAL, TMT_TEXTCOLOR, &bgRef))) {
QColor textColor = QColor::fromRgb(bgRef);
QPalette pal;
@@ -2464,7 +2461,7 @@ QIcon QWindowsVistaStyle::standardIcon(StandardPixmap standardIcon,
switch(standardIcon) {
case SP_CommandLink:
{
- XPThemeData theme(0, 0,
+ XPThemeData theme(nullptr, nullptr,
QWindowsXPStylePrivate::ButtonTheme,
BP_COMMANDLINKGLYPH, CMDLGS_NORMAL);
if (theme.isValid()) {
diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h
index d66b17e9f8..8fef9f9927 100644
--- a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h
+++ b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h
@@ -162,7 +162,7 @@ class QWindowsVistaAnimation : public QBlendStyleAnimation
public:
QWindowsVistaAnimation(Type type, QObject *target) : QBlendStyleAnimation(type, target) { }
- virtual bool isUpdateNeeded() const;
+ bool isUpdateNeeded() const override;
void paint(QPainter *painter, const QStyleOption *option);
};
diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp
index e2c5bdc924..bf80138b32 100644
--- a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp
+++ b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp
@@ -117,7 +117,7 @@ static inline QBackingStore *backingStoreForWidget(const QWidget *widget)
if (const QWidget *topLevel = widget->nativeParentWidget())
if (QBackingStore *topLevelBackingStore = topLevel->backingStore())
return topLevelBackingStore;
- return 0;
+ return nullptr;
}
static inline HDC hdcForWidgetBackingStore(const QWidget *widget)
@@ -127,7 +127,7 @@ static inline HDC hdcForWidgetBackingStore(const QWidget *widget)
if (nativeInterface)
return static_cast<HDC>(nativeInterface->nativeResourceForBackingStore(QByteArrayLiteral("getDC"), backingStore));
}
- return 0;
+ return nullptr;
}
// Theme data helper ------------------------------------------------------------------------------
@@ -148,7 +148,7 @@ bool XPThemeData::isValid()
HTHEME XPThemeData::handle()
{
if (!QWindowsXPStylePrivate::useXP())
- return 0;
+ return nullptr;
if (!htheme)
htheme = QWindowsXPStylePrivate::createTheme(theme, QWindowsXPStylePrivate::winId(widget));
@@ -175,10 +175,10 @@ RECT XPThemeData::toRECT(const QRect &qr)
HRGN XPThemeData::mask(QWidget *widget)
{
if (!IsThemeBackgroundPartiallyTransparent(handle(), partId, stateId))
- return 0;
+ return nullptr;
HRGN hrgn;
- HDC dc = 0;
+ HDC dc = nullptr;
if (widget)
dc = hdcForWidgetBackingStore(widget);
RECT nativeRect = toRECT(rect);
@@ -188,7 +188,7 @@ HRGN XPThemeData::mask(QWidget *widget)
// QWindowsXPStylePrivate -------------------------------------------------------------------------
// Static initializations
-HWND QWindowsXPStylePrivate::m_vistaTreeViewHelper = 0;
+HWND QWindowsXPStylePrivate::m_vistaTreeViewHelper = nullptr;
HTHEME QWindowsXPStylePrivate::m_themes[NThemes];
bool QWindowsXPStylePrivate::use_xp = false;
QBasicAtomicInt QWindowsXPStylePrivate::ref = Q_BASIC_ATOMIC_INITIALIZER(-1); // -1 based refcounting
@@ -227,7 +227,7 @@ bool QWindowsXPStylePrivate::useXP(bool update)
{
if (!update)
return use_xp;
- return use_xp = IsThemeActive() && (IsAppThemed() || !QApplication::instance());
+ return use_xp = IsThemeActive() && (IsAppThemed() || !QCoreApplication::instance());
}
/* \internal
@@ -241,7 +241,7 @@ void QWindowsXPStylePrivate::init(bool force)
ref.ref();
useXP(true);
- std::fill(m_themes, m_themes + NThemes, HTHEME(0));
+ std::fill(m_themes, m_themes + NThemes, nullptr);
}
/* \internal
@@ -253,12 +253,12 @@ void QWindowsXPStylePrivate::cleanup(bool force)
if (bufferDC && nullBitmap)
SelectObject(bufferDC, nullBitmap);
DeleteObject(bufferBitmap);
- bufferBitmap = 0;
+ bufferBitmap = nullptr;
}
if(bufferDC)
DeleteDC(bufferDC);
- bufferDC = 0;
+ bufferDC = nullptr;
if (ref.deref() && !force)
return;
@@ -282,7 +282,7 @@ void QWindowsXPStylePrivate::cleanup(bool force)
static inline HWND createTreeViewHelperWindow()
{
if (QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface()) {
- void *hwnd = 0;
+ void *hwnd = nullptr;
void *wndProc = reinterpret_cast<void *>(DefWindowProc);
if (QMetaObject::invokeMethod(ni, "createMessageWindow", Qt::DirectConnection,
Q_RETURN_ARG(void*, hwnd),
@@ -292,7 +292,7 @@ static inline HWND createTreeViewHelperWindow()
return reinterpret_cast<HWND>(hwnd);
}
}
- return 0;
+ return nullptr;
}
bool QWindowsXPStylePrivate::initVistaTreeViewTheming()
@@ -305,7 +305,7 @@ bool QWindowsXPStylePrivate::initVistaTreeViewTheming()
qWarning("Unable to create the treeview helper window.");
return false;
}
- if (FAILED(SetWindowTheme(m_vistaTreeViewHelper, L"explorer", NULL))) {
+ if (FAILED(SetWindowTheme(m_vistaTreeViewHelper, L"explorer", nullptr))) {
qErrnoWarning("SetWindowTheme() failed.");
cleanupVistaTreeViewTheming();
return false;
@@ -317,7 +317,7 @@ void QWindowsXPStylePrivate::cleanupVistaTreeViewTheming()
{
if (m_vistaTreeViewHelper) {
DestroyWindow(m_vistaTreeViewHelper);
- m_vistaTreeViewHelper = 0;
+ m_vistaTreeViewHelper = nullptr;
}
}
@@ -328,11 +328,12 @@ void QWindowsXPStylePrivate::cleanupVistaTreeViewTheming()
*/
void QWindowsXPStylePrivate::cleanupHandleMap()
{
- for (int i = 0; i < NThemes; ++i)
- if (m_themes[i]) {
- CloseThemeData(m_themes[i]);
- m_themes[i] = 0;
+ for (auto &theme : m_themes) {
+ if (theme) {
+ CloseThemeData(theme);
+ theme = nullptr;
}
+ }
QWindowsXPStylePrivate::cleanupVistaTreeViewTheming();
}
@@ -340,7 +341,7 @@ HTHEME QWindowsXPStylePrivate::createTheme(int theme, HWND hwnd)
{
if (Q_UNLIKELY(theme < 0 || theme >= NThemes || !hwnd)) {
qWarning("Invalid parameters #%d, %p", theme, hwnd);
- return 0;
+ return nullptr;
}
if (!m_themes[theme]) {
const wchar_t *name = themeNames[theme];
@@ -427,16 +428,16 @@ HBITMAP QWindowsXPStylePrivate::buffer(int w, int h)
if (bufferDC && nullBitmap)
SelectObject(bufferDC, nullBitmap);
DeleteObject(bufferBitmap);
- bufferBitmap = 0;
+ bufferBitmap = nullptr;
}
w = qMax(bufferW, w);
h = qMax(bufferH, h);
if (!bufferDC) {
- HDC displayDC = GetDC(0);
+ HDC displayDC = GetDC(nullptr);
bufferDC = CreateCompatibleDC(displayDC);
- ReleaseDC(0, displayDC);
+ ReleaseDC(nullptr, displayDC);
}
// Define the header
@@ -450,22 +451,22 @@ HBITMAP QWindowsXPStylePrivate::buffer(int w, int h)
bmi.bmiHeader.biCompression = BI_RGB;
// Create the pixmap
- bufferPixels = 0;
- bufferBitmap = CreateDIBSection(bufferDC, &bmi, DIB_RGB_COLORS, (void **) &bufferPixels, 0, 0);
+ bufferPixels = nullptr;
+ bufferBitmap = CreateDIBSection(bufferDC, &bmi, DIB_RGB_COLORS, reinterpret_cast<void **>(&bufferPixels), nullptr, 0);
GdiFlush();
- nullBitmap = (HBITMAP)SelectObject(bufferDC, bufferBitmap);
+ nullBitmap = static_cast<HBITMAP>(SelectObject(bufferDC, bufferBitmap));
if (Q_UNLIKELY(!bufferBitmap)) {
qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() failed.", w, h);
bufferW = 0;
bufferH = 0;
- return 0;
+ return nullptr;
}
if (Q_UNLIKELY(!bufferPixels)) {
qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() did not allocate pixel data.", w, h);
bufferW = 0;
bufferH = 0;
- return 0;
+ return nullptr;
}
bufferW = w;
bufferH = h;
@@ -493,7 +494,7 @@ bool QWindowsXPStylePrivate::isTransparent(XPThemeData &themeData)
*/
QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData)
{
- HRGN hRgn = 0;
+ HRGN hRgn = nullptr;
const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(themeData.widget);
RECT rect = themeData.toRECT(QRect(themeData.rect.topLeft() / factor, themeData.rect.size() / factor));
if (!SUCCEEDED(GetThemeBackgroundRegion(themeData.handle(), bufferHDC(), themeData.partId,
@@ -502,12 +503,12 @@ QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData)
}
HRGN dest = CreateRectRgn(0, 0, 0, 0);
- const bool success = CombineRgn(dest, hRgn, 0, RGN_COPY) != ERROR;
+ const bool success = CombineRgn(dest, hRgn, nullptr, RGN_COPY) != ERROR;
QRegion region;
if (success) {
- int numBytes = GetRegionData(dest, 0, 0);
+ const auto numBytes = GetRegionData(dest, 0, nullptr);
if (numBytes == 0)
return QRegion();
@@ -551,7 +552,7 @@ bool QWindowsXPStylePrivate::hasAlphaChannel(const QRect &rect)
int firstAlpha = -1;
for (int y = startY; y < h/2; ++y) {
- DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW);
+ auto buffer = reinterpret_cast<const DWORD *>(bufferPixels) + (y * bufferW);
for (int x = startX; x < w; ++x, ++buffer) {
int alpha = (*buffer) >> 24;
if (firstAlpha == -1)
@@ -580,7 +581,7 @@ bool QWindowsXPStylePrivate::fixAlphaChannel(const QRect &rect)
bool hasFixedAlphaValue = false;
for (int y = startY; y < h; ++y) {
- DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW);
+ auto buffer = reinterpret_cast<DWORD *>(bufferPixels) + (y * bufferW);
for (int x = startX; x < w; ++x, ++buffer) {
uint pixel = *buffer;
int alpha = qAlpha(pixel);
@@ -612,7 +613,7 @@ bool QWindowsXPStylePrivate::swapAlphaChannel(const QRect &rect, bool allPixels)
// Flip the alphas, so that 255-alpha pixels are 0, and 0-alpha are 255.
for (int y = startY; y < h; ++y) {
- DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW);
+ auto buffer = reinterpret_cast<DWORD *>(bufferPixels) + (y * bufferW);
for (int x = startX; x < w; ++x, ++buffer) {
if (allPixels) {
*buffer |= 0xFF000000;
@@ -668,7 +669,7 @@ bool QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData)
return true;
QPainter *painter = themeData.painter;
- Q_ASSERT_X(painter != 0, "QWindowsXPStylePrivate::drawBackground()", "Trying to draw a theme part without a painter");
+ Q_ASSERT_X(painter != nullptr, "QWindowsXPStylePrivate::drawBackground()", "Trying to draw a theme part without a painter");
if (!painter || !painter->isActive())
return false;
@@ -706,7 +707,7 @@ bool QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData)
}
}
- const HDC dc = canDrawDirectly ? hdcForWidgetBackingStore(themeData.widget) : HDC(0);
+ const HDC dc = canDrawDirectly ? hdcForWidgetBackingStore(themeData.widget) : nullptr;
const bool result = dc
? drawBackgroundDirectly(dc, themeData, aditionalDevicePixelRatio)
: drawBackgroundThruNativeBuffer(themeData, aditionalDevicePixelRatio);
@@ -740,7 +741,7 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(HDC dc, XPThemeData &themeDa
{
QPainter *painter = themeData.painter;
- const auto deviceTransform = painter->deviceTransform();
+ const auto &deviceTransform = painter->deviceTransform();
const QPointF redirectionDelta(deviceTransform.dx(), deviceTransform.dy());
const QRect area = scaleRect(QRectF(themeData.rect), additionalDevicePixelRatio).translated(redirectionDelta).toRect();
@@ -771,7 +772,7 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(HDC dc, XPThemeData &themeDa
| (themeData.mirrorHorizontally ? DTBG_MIRRORDC : 0);
const HRESULT result = DrawThemeBackgroundEx(themeData.handle(), dc, themeData.partId, themeData.stateId, &(drawRECT), &drawOptions);
- SelectClipRgn(dc, 0);
+ SelectClipRgn(dc, nullptr);
DeleteObject(hrgn);
return SUCCEEDED(result);
}
@@ -1099,9 +1100,7 @@ QWindowsXPStyle::QWindowsXPStyle()
/*!
Destroys the style.
*/
-QWindowsXPStyle::~QWindowsXPStyle()
-{
-}
+QWindowsXPStyle::~QWindowsXPStyle() = default;
/*! \reimp */
void QWindowsXPStyle::unpolish(QApplication *app)
@@ -1157,7 +1156,7 @@ void QWindowsXPStyle::polish(QWidget *widget)
if (!d->hasInitColors) {
// Get text color for group box labels
COLORREF cref;
- XPThemeData theme(widget, 0, QWindowsXPStylePrivate::ButtonTheme, 0, 0);
+ XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, 0, 0);
GetThemeColor(theme.handle(), BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, &cref);
d->groupBoxTextColor = qRgb(GetRValue(cref), GetGValue(cref), GetBValue(cref));
GetThemeColor(theme.handle(), BP_GROUPBOX, GBS_DISABLED, TMT_TEXTCOLOR, &cref);
@@ -1270,7 +1269,7 @@ QRect QWindowsXPStyle::subElementRect(SubElement sr, const QStyleOption *option,
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
MARGINS borderSize;
if (widget) {
- XPThemeData buttontheme(widget, 0, QWindowsXPStylePrivate::ButtonTheme);
+ XPThemeData buttontheme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme);
HTHEME theme = buttontheme.handle();
if (theme) {
int stateId;
@@ -1288,7 +1287,7 @@ QRect QWindowsXPStyle::subElementRect(SubElement sr, const QStyleOption *option,
int border = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget);
rect = option->rect.adjusted(border, border, -border, -border);
- if (SUCCEEDED(GetThemeMargins(theme, NULL, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, NULL, &borderSize))) {
+ if (SUCCEEDED(GetThemeMargins(theme, nullptr, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, nullptr, &borderSize))) {
rect.adjust(borderSize.cxLeftWidth, borderSize.cyTopHeight,
-borderSize.cxRightWidth, -borderSize.cyBottomHeight);
rect = visualRect(option->direction, option->rect, rect);
@@ -1468,7 +1467,7 @@ case PE_Frame:
return;
themeNumber = QWindowsXPStylePrivate::ListViewTheme;
partId = LVP_LISTGROUP;
- XPThemeData theme(widget, 0, themeNumber, partId, 0);
+ XPThemeData theme(widget, nullptr, themeNumber, partId);
if (!(flags & State_Enabled))
stateId = ETS_DISABLED;
@@ -1496,9 +1495,9 @@ case PE_Frame:
p->drawRect(QRectF(option->rect).adjusted(0, 0, -topLevelAdjustment, -topLevelAdjustment));
p->setPen(oldPen);
return;
- } else if (fillType == BT_NONE) {
- return;
}
+ if (fillType == BT_NONE)
+ return;
}
break;
}
@@ -1514,7 +1513,8 @@ case PE_Frame:
p->drawRect(option->rect.adjusted(0, 0, -1, -1));
p->setPen(oldPen);
return;
- } else if (qstyleoption_cast<const QStyleOptionFrame *>(option)) {
+ }
+ if (qstyleoption_cast<const QStyleOptionFrame *>(option)) {
themeNumber = QWindowsXPStylePrivate::EditTheme;
partId = EP_EDITTEXT;
noContent = true;
@@ -1538,7 +1538,7 @@ case PE_Frame:
if (QWindowsXPStylePrivate::isLineEditBaseColorSet(option, widget)) {
p->fillRect(panel->rect, panel->palette.brush(QPalette::Base));
} else {
- XPThemeData theme(0, p, themeNumber, partId, stateId, rect);
+ XPThemeData theme(nullptr, p, themeNumber, partId, stateId, rect);
if (!theme.isValid()) {
QWindowsStyle::drawPrimitive(pe, option, p, widget);
return;
@@ -1587,9 +1587,9 @@ case PE_Frame:
wchar_t themeFileName[maxlength];
wchar_t themeColor[maxlength];
// Due to a a scaling issue with the XP Silver theme, tab gradients are not used with it
- if (GetCurrentThemeName(themeFileName, maxlength, themeColor, maxlength, NULL, 0) == S_OK) {
- wchar_t *offset = 0;
- if ((offset = wcsrchr(themeFileName, QChar(QLatin1Char('\\')).unicode())) != NULL) {
+ if (GetCurrentThemeName(themeFileName, maxlength, themeColor, maxlength, nullptr, 0) == S_OK) {
+ wchar_t *offset = nullptr;
+ if ((offset = wcsrchr(themeFileName, QChar(QLatin1Char('\\')).unicode())) != nullptr) {
offset++;
if (!lstrcmp(offset, L"Luna.msstyles") && !lstrcmp(offset, L"Metallic")) {
useGradient = false;
@@ -1820,7 +1820,7 @@ case PE_Frame:
bef_v -= delta;
aft_h += delta;
aft_v += delta;
- XPThemeData theme(0, p, QWindowsXPStylePrivate::XpTreeViewTheme);
+ XPThemeData theme(nullptr, p, QWindowsXPStylePrivate::XpTreeViewTheme);
theme.rect = QRect(bef_h, bef_v, decoration_size, decoration_size);
theme.partId = TVP_GLYPH;
theme.stateId = flags & QStyle::State_Open ? GLPS_OPENED : GLPS_CLOSED;
@@ -1912,7 +1912,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op
{
themeNumber = QWindowsXPStylePrivate::StatusTheme;
partId = SP_GRIPPER;
- XPThemeData theme(0, p, themeNumber, partId, 0);
+ XPThemeData theme(nullptr, p, themeNumber, partId);
QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize();
size.rheight()--;
if (const QStyleOptionSizeGrip *sg = qstyleoption_cast<const QStyleOptionSizeGrip *>(option)) {
@@ -1980,7 +1980,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op
if (btn->features & QStyleOptionButton::HasMenu) {
int mbiw = 0, mbih = 0;
- XPThemeData theme(widget, 0,
+ XPThemeData theme(widget, nullptr,
QWindowsXPStylePrivate::ToolBarTheme,
TP_SPLITBUTTONDROPDOWN);
if (theme.isValid()) {
@@ -2309,7 +2309,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op
if (isFloating) {
titleRect.adjust(0, -fw, 0, 0);
- if (widget != 0 && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey())
+ if (widget != nullptr && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey())
titleRect.adjust(titleRect.height() + mw, 0, 0, 0);
} else {
titleRect.adjust(mw, 0, 0, 0);
@@ -2775,7 +2775,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo
break;
v = nextInterval;
}
- if (lines.size() > 0) {
+ if (!lines.isEmpty()) {
p->save();
p->translate(slrect.topLeft());
p->drawLines(lines.constData(), lines.size());
@@ -2923,7 +2923,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo
p->save();
p->setClipRect(menuarea);
tool.rect = option->rect;
- proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, p, 0);
+ proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, p, nullptr);
p->restore();
}
// Draw arrow
@@ -3223,7 +3223,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo
}
}
-static inline Qt::Orientation progressBarOrientation(const QStyleOption *option = 0)
+static inline Qt::Orientation progressBarOrientation(const QStyleOption *option = nullptr)
{
if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(option))
return pb->orientation;
@@ -3234,27 +3234,27 @@ int QWindowsXPStylePrivate::pixelMetricFromSystemDp(QStyle::PixelMetric pm, cons
{
switch (pm) {
case QStyle::PM_IndicatorWidth:
- return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).width();
+ return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).width();
case QStyle::PM_IndicatorHeight:
- return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).height();
+ return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).height();
case QStyle::PM_ExclusiveIndicatorWidth:
- return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).width();
+ return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).width();
case QStyle::PM_ExclusiveIndicatorHeight:
- return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).height();
+ return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).height();
case QStyle::PM_ProgressBarChunkWidth:
return progressBarOrientation(option) == Qt::Horizontal
- ? XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNK).width()
- : XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNKVERT).height();
+ ? XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNK).width()
+ : XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNKVERT).height();
case QStyle::PM_SliderThickness:
- return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::TrackBarTheme, TKP_THUMB).height();
+ return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::TrackBarTheme, TKP_THUMB).height();
case QStyle::PM_TitleBarHeight:
return widget && (widget->windowType() == Qt::Tool)
? GetSystemMetrics(SM_CYSMCAPTION) + GetSystemMetrics(SM_CXSIZEFRAME)
: GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CXSIZEFRAME);
case QStyle::PM_MdiSubWindowFrameWidth:
- return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_FRAMELEFT, FS_ACTIVE).width();
+ return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_FRAMELEFT, FS_ACTIVE).width();
case QStyle::PM_DockWidgetFrameWidth:
- return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_SMALLFRAMERIGHT, FS_ACTIVE).width();
+ return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLFRAMERIGHT, FS_ACTIVE).width();
default:
break;
}
@@ -3620,7 +3620,7 @@ QSize QWindowsXPStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt
case CT_LineEdit:
case CT_ComboBox:
{
- XPThemeData buttontheme(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_PUSHBUTTON, PBS_NORMAL);
+ XPThemeData buttontheme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_PUSHBUTTON, PBS_NORMAL);
if (buttontheme.isValid()) {
const qreal factor = QWindowsXPStylePrivate::nativeMetricScaleFactor(widget);
const QMarginsF borderSize = buttontheme.margins() * factor;
@@ -3741,11 +3741,11 @@ int QWindowsXPStyle::styleHint(StyleHint hint, const QStyleOption *option, const
titleBarRect.setHeight(tbHeight);
XPThemeData themeData;
if (titlebar->titleBarState & Qt::WindowMinimized) {
- themeData = XPThemeData(widget, 0,
+ themeData = XPThemeData(widget, nullptr,
QWindowsXPStylePrivate::WindowTheme,
WP_MINCAPTION, CS_ACTIVE, titleBarRect);
} else
- themeData = XPThemeData(widget, 0,
+ themeData = XPThemeData(widget, nullptr,
QWindowsXPStylePrivate::WindowTheme,
WP_CAPTION, CS_ACTIVE, titleBarRect);
mask->region = d->region(themeData) +
@@ -3774,10 +3774,8 @@ int QWindowsXPStyle::styleHint(StyleHint hint, const QStyleOption *option, const
/*! \reimp */
QPalette QWindowsXPStyle::standardPalette() const
{
- if (QWindowsXPStylePrivate::useXP() && QApplicationPrivate::sys_pal)
- return *QApplicationPrivate::sys_pal;
- else
- return QWindowsStyle::standardPalette();
+ return QWindowsXPStylePrivate::useXP() && QApplicationPrivate::sys_pal
+ ? *QApplicationPrivate::sys_pal : QWindowsStyle::standardPalette();
}
/*!
@@ -3795,7 +3793,7 @@ QPixmap QWindowsXPStyle::standardPixmap(StandardPixmap standardPixmap, const QSt
if (qstyleoption_cast<const QStyleOptionDockWidget *>(option))
{
if (widget && widget->isWindow()) {
- XPThemeData theme(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL);
+ XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL);
if (theme.isValid()) {
const QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize();
return QIcon(QWindowsStyle::standardPixmap(standardPixmap, option, widget)).pixmap(size);
@@ -3826,9 +3824,9 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon,
if (qstyleoption_cast<const QStyleOptionDockWidget *>(option))
{
if (d->dockFloat.isNull()) {
- XPThemeData themeSize(0, 0, QWindowsXPStylePrivate::WindowTheme,
+ XPThemeData themeSize(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme,
WP_SMALLCLOSEBUTTON, CBS_NORMAL);
- XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme,
+ XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme,
WP_MAXBUTTON, MAXBS_NORMAL);
if (theme.isValid()) {
const QSize size = (themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize();
@@ -3862,7 +3860,7 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon,
if (qstyleoption_cast<const QStyleOptionDockWidget *>(option))
{
if (d->dockClose.isNull()) {
- XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme,
+ XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme,
WP_SMALLCLOSEBUTTON, CBS_NORMAL);
if (theme.isValid()) {
const QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize();
@@ -3896,9 +3894,9 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon,
if (qstyleoption_cast<const QStyleOptionDockWidget *>(option))
{
if (d->dockFloat.isNull()) {
- XPThemeData themeSize(0, 0, QWindowsXPStylePrivate::WindowTheme,
+ XPThemeData themeSize(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme,
WP_SMALLCLOSEBUTTON, CBS_NORMAL);
- XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme,
+ XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme,
WP_RESTOREBUTTON, RBS_NORMAL);
if (theme.isValid()) {
const QSize size = (themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize();
diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h b/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h
index 60f9d7e9b7..ad7754e3d4 100644
--- a/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h
+++ b/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h
@@ -100,11 +100,11 @@ class QDebug;
class XPThemeData
{
public:
- explicit XPThemeData(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1,
+ explicit XPThemeData(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
int part = 0, int state = 0, const QRect &r = QRect())
- : widget(w), painter(p), theme(themeIn), htheme(0), partId(part), stateId(state),
+ : widget(w), painter(p), theme(themeIn), partId(part), stateId(state),
mirrorHorizontally(false), mirrorVertically(false), noBorder(false),
- noContent(false), rotate(0), rect(r)
+ noContent(false), rect(r)
{}
HRGN mask(QWidget *widget);
@@ -117,17 +117,17 @@ public:
QMarginsF margins(const QRect &rect, int propId = TMT_CONTENTMARGINS);
QMarginsF margins(int propId = TMT_CONTENTMARGINS);
- static QSizeF themeSize(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, int part = 0, int state = 0);
- static QMarginsF themeMargins(const QRect &rect, const QWidget *w = 0, QPainter *p = 0, int themeIn = -1,
+ static QSizeF themeSize(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0);
+ static QMarginsF themeMargins(const QRect &rect, const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS);
- static QMarginsF themeMargins(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1,
+ static QMarginsF themeMargins(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1,
int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS);
const QWidget *widget;
QPainter *painter;
int theme;
- HTHEME htheme;
+ HTHEME htheme = nullptr;
int partId;
int stateId;
@@ -135,18 +135,18 @@ public:
uint mirrorVertically : 1;
uint noBorder : 1;
uint noContent : 1;
- uint rotate;
+ uint rotate = 0;
QRect rect;
};
struct ThemeMapKey {
- int theme;
- int partId;
- int stateId;
- bool noBorder;
- bool noContent;
+ int theme = 0;
+ int partId = -1;
+ int stateId = -1;
+ bool noBorder = false;
+ bool noContent = false;
- ThemeMapKey() : partId(-1), stateId(-1) {}
+ ThemeMapKey() = default;
ThemeMapKey(const XPThemeData &data)
: theme(data.theme), partId(data.partId), stateId(data.stateId),
noBorder(data.noBorder), noContent(data.noContent) {}
@@ -171,7 +171,7 @@ enum AlphaChannelType {
};
struct ThemeMapData {
- AlphaChannelType alphaType; // Which type of alpha on part & state
+ AlphaChannelType alphaType = UnknownAlpha; // Which type of alpha on part & state
bool dataValid : 1; // Only used to detect if hash value is ok
bool partIsTransparent : 1;
@@ -217,15 +217,13 @@ public:
};
QWindowsXPStylePrivate()
- : QWindowsStylePrivate(), hasInitColors(false), bufferDC(0), bufferBitmap(0), nullBitmap(0),
- bufferPixels(0), bufferW(0), bufferH(0)
{ init(); }
~QWindowsXPStylePrivate()
{ cleanup(); }
- static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = 0, const QWidget *widget = 0);
- static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option = 0, const QWidget *widget = 0);
+ static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr);
+ static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr);
static HWND winId(const QWidget *widget);
@@ -251,10 +249,10 @@ public:
bool fixAlphaChannel(const QRect &rect);
bool swapAlphaChannel(const QRect &rect, bool allPixels = false);
- QRgb groupBoxTextColor;
- QRgb groupBoxTextColorDisabled;
- QRgb sliderTickColor;
- bool hasInitColors;
+ QRgb groupBoxTextColor = 0;
+ QRgb groupBoxTextColorDisabled = 0;
+ QRgb sliderTickColor = 0;
+ bool hasInitColors = false;
static HTHEME createTheme(int theme, HWND hwnd);
static QString themeName(int theme);
@@ -277,11 +275,12 @@ private:
static bool use_xp;
QHash<ThemeMapKey, ThemeMapData> alphaCache;
- HDC bufferDC;
- HBITMAP bufferBitmap;
- HBITMAP nullBitmap;
- uchar *bufferPixels;
- int bufferW, bufferH;
+ HDC bufferDC = nullptr;
+ HBITMAP bufferBitmap = nullptr;
+ HBITMAP nullBitmap = nullptr;
+ uchar *bufferPixels = nullptr;
+ int bufferW = 0;
+ int bufferH = 0;
static HWND m_vistaTreeViewHelper;
static HTHEME m_themes[NThemes];
@@ -292,7 +291,7 @@ inline QSizeF XPThemeData::size()
QSizeF result(0, 0);
if (isValid()) {
SIZE size;
- if (SUCCEEDED(GetThemePartSize(handle(), 0, partId, stateId, 0, TS_TRUE, &size)))
+ if (SUCCEEDED(GetThemePartSize(handle(), nullptr, partId, stateId, nullptr, TS_TRUE, &size)))
result = QSize(size.cx, size.cy);
}
return result;
@@ -304,7 +303,7 @@ inline QMarginsF XPThemeData::margins(const QRect &qRect, int propId)
if (isValid()) {
MARGINS margins;
RECT rect = XPThemeData::toRECT(qRect);
- if (SUCCEEDED(GetThemeMargins(handle(), 0, partId, stateId, propId, &rect, &margins)))
+ if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, &rect, &margins)))
result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
}
return result;
@@ -315,7 +314,7 @@ inline QMarginsF XPThemeData::margins(int propId)
QMarginsF result(0, 0, 0 ,0);
if (isValid()) {
MARGINS margins;
- if (SUCCEEDED(GetThemeMargins(handle(), 0, partId, stateId, propId, NULL, &margins)))
+ if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, nullptr, &margins)))
result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
}
return result;
diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp
index e9e49e0c33..a04189513a 100644
--- a/src/widgets/dialogs/qfilesystemmodel.cpp
+++ b/src/widgets/dialogs/qfilesystemmodel.cpp
@@ -57,6 +57,9 @@
#ifdef Q_OS_WIN
# include <QtCore/QVarLengthArray>
# include <qt_windows.h>
+# ifndef Q_OS_WINRT
+# include <shlobj.h>
+# endif
#endif
QT_BEGIN_NAMESPACE
@@ -837,8 +840,8 @@ QString QFileSystemModelPrivate::displayName(const QModelIndex &index) const
{
#if defined(Q_OS_WIN)
QFileSystemNode *dirNode = node(index);
- if (!dirNode->volumeName.isNull())
- return dirNode->volumeName + QLatin1String(" (") + name(index) + QLatin1Char(')');
+ if (!dirNode->volumeName.isEmpty())
+ return dirNode->volumeName;
#endif
return name(index);
}
@@ -1773,6 +1776,27 @@ void QFileSystemModelPrivate::_q_directoryChanged(const QString &directory, cons
removeNode(parentNode, toRemove[i]);
}
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
+static QString volumeName(const QString &path)
+{
+ IShellItem *item = nullptr;
+ const QString native = QDir::toNativeSeparators(path);
+ HRESULT hr = SHCreateItemFromParsingName(reinterpret_cast<const wchar_t *>(native.utf16()),
+ nullptr, IID_IShellItem,
+ reinterpret_cast<void **>(&item));
+ if (FAILED(hr))
+ return QString();
+ LPWSTR name = nullptr;
+ hr = item->GetDisplayName(SIGDN_NORMALDISPLAY, &name);
+ if (FAILED(hr))
+ return QString();
+ QString result = QString::fromWCharArray(name);
+ CoTaskMemFree(name);
+ item->Release();
+ return result;
+}
+#endif // Q_OS_WIN && !Q_OS_WINRT
+
/*!
\internal
@@ -1791,15 +1815,8 @@ QFileSystemModelPrivate::QFileSystemNode* QFileSystemModelPrivate::addNode(QFile
#endif
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
//The parentNode is "" so we are listing the drives
- if (parentNode->fileName.isEmpty()) {
- wchar_t name[MAX_PATH + 1];
- //GetVolumeInformation requires to add trailing backslash
- const QString nodeName = fileName + QLatin1String("\\");
- BOOL success = ::GetVolumeInformation((wchar_t *)(nodeName.utf16()),
- name, MAX_PATH + 1, NULL, 0, NULL, NULL, 0);
- if (success && name[0])
- node->volumeName = QString::fromWCharArray(name);
- }
+ if (parentNode->fileName.isEmpty())
+ node->volumeName = volumeName(fileName);
#endif
Q_ASSERT(!parentNode->children.contains(fileName));
parentNode->children.insert(fileName, node);
diff --git a/src/widgets/doc/snippets/qsplashscreen/main.cpp b/src/widgets/doc/snippets/qsplashscreen/main.cpp
index 843932ca83..2512035879 100644
--- a/src/widgets/doc/snippets/qsplashscreen/main.cpp
+++ b/src/widgets/doc/snippets/qsplashscreen/main.cpp
@@ -71,3 +71,10 @@ int main(int argc, char *argv[])
return app.exec();
}
//! [1]
+
+//! [2]
+QScreen *screen = QGuiApplication::screens().at(1);
+QPixmap pixmap(":/splash.png");
+QSplashScreen splash(screen, pixmap);
+splash.show();
+//! [2]
diff --git a/src/widgets/graphicsview/qgraphicsview.h b/src/widgets/graphicsview/qgraphicsview.h
index e02fba69c9..1389796c3f 100644
--- a/src/widgets/graphicsview/qgraphicsview.h
+++ b/src/widgets/graphicsview/qgraphicsview.h
@@ -107,7 +107,9 @@ public:
Q_ENUM(ViewportUpdateMode)
enum OptimizationFlag {
- DontClipPainter = 0x1, // obsolete
+#if QT_DEPRECATED_SINCE(5, 14)
+ DontClipPainter Q_DECL_ENUMERATOR_DEPRECATED_X("This flag is unused") = 0x1, // obsolete
+#endif
DontSavePainterState = 0x2,
DontAdjustForAntialiasing = 0x4,
IndirectPainting = 0x8
diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp
index 39b08dbc1e..eec65c8625 100644
--- a/src/widgets/kernel/qshortcut.cpp
+++ b/src/widgets/kernel/qshortcut.cpp
@@ -659,24 +659,22 @@ int QShortcut::id() const
bool QShortcut::event(QEvent *e)
{
Q_D(QShortcut);
- bool handled = false;
if (d->sc_enabled && e->type() == QEvent::Shortcut) {
auto se = static_cast<QShortcutEvent *>(e);
if (se->shortcutId() == d->sc_id && se->key() == d->sc_sequence){
#if QT_CONFIG(whatsthis)
if (QWhatsThis::inWhatsThisMode()) {
QWhatsThis::showText(QCursor::pos(), d->sc_whatsthis);
- handled = true;
} else
#endif
if (se->isAmbiguous())
emit activatedAmbiguously();
else
emit activated();
- handled = true;
+ return true;
}
}
- return handled;
+ return QObject::event(e);
}
#endif // QT_NO_SHORTCUT
diff --git a/src/widgets/styles/qstyleoption.cpp b/src/widgets/styles/qstyleoption.cpp
index 5b3efd598f..01cadd9a86 100644
--- a/src/widgets/styles/qstyleoption.cpp
+++ b/src/widgets/styles/qstyleoption.cpp
@@ -1760,7 +1760,7 @@ QStyleOptionMenuItem::QStyleOptionMenuItem(int version)
\value Exclusive The item is an exclusive check item (like a radio button).
\value NonExclusive The item is a non-exclusive check item (like a check box).
- \sa checkType, QAction::checkable, QAction::checked, QActionGroup::exclusive
+ \sa checkType, QAction::checkable, QAction::checked, QActionGroup::exclusionPolicy
*/
/*!
diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp
index 72c803cb99..8496a2c223 100644
--- a/src/widgets/styles/qwindowsstyle.cpp
+++ b/src/widgets/styles/qwindowsstyle.cpp
@@ -120,10 +120,7 @@ enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight };
\internal
*/
-QWindowsStylePrivate::QWindowsStylePrivate()
- : alt_down(false), menuBarTimer(0)
-{
-}
+QWindowsStylePrivate::QWindowsStylePrivate() = default;
qreal QWindowsStylePrivate::appDevicePixelRatio()
{
@@ -157,7 +154,7 @@ bool QWindowsStyle::eventFilter(QObject *o, QEvent *e)
QList<QWidget *> l = widget->findChildren<QWidget *>();
auto ignorable = [](QWidget *w) {
return w->isWindow() || !w->isVisible()
- || w->style()->styleHint(SH_UnderlineShortcut, 0, w);
+ || w->style()->styleHint(SH_UnderlineShortcut, nullptr, w);
};
l.erase(std::remove_if(l.begin(), l.end(), ignorable), l.end());
// Update states before repainting
@@ -242,7 +239,7 @@ void QWindowsStyle::polish(QApplication *app)
QCommonStyle::polish(app);
QWindowsStylePrivate *d = const_cast<QWindowsStylePrivate*>(d_func());
// We only need the overhead when shortcuts are sometimes hidden
- if (!proxy()->styleHint(SH_UnderlineShortcut, 0) && app)
+ if (!proxy()->styleHint(SH_UnderlineShortcut, nullptr) && app)
app->installEventFilter(this);
const auto &palette = QGuiApplication::palette();
@@ -343,7 +340,6 @@ int QWindowsStylePrivate::fixedPixelMetric(QStyle::PixelMetric pm)
case QStyle::PM_MenuVMargin:
case QStyle::PM_ToolBarItemMargin:
return 1;
- break;
case QStyle::PM_DockWidgetSeparatorExtent:
return 4;
#if QT_CONFIG(tabbar)
@@ -396,8 +392,6 @@ static QScreen *screenOf(const QWidget *w)
// and account for secondary screens with differing logical DPI.
qreal QWindowsStylePrivate::nativeMetricScaleFactor(const QWidget *widget)
{
- if (!QHighDpiScaling::isActive())
- return 1;
qreal result = qreal(1) / QWindowsStylePrivate::devicePixelRatio(widget);
if (QGuiApplicationPrivate::screen_list.size() > 1) {
const QScreen *primaryScreen = QGuiApplication::primaryScreen();
@@ -698,17 +692,17 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt,
x -= 2;
if (opt->rect.height() > 4) {
qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4,
- opt->palette, false, 1, 0);
+ opt->palette, false, 1, nullptr);
qDrawShadePanel(p, x + 3, 2, 3, opt->rect.height() - 4,
- opt->palette, false, 1, 0);
+ opt->palette, false, 1, nullptr);
}
} else {
if (opt->rect.width() > 4) {
int y = opt->rect.height() / 2 - 4;
qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3,
- opt->palette, false, 1, 0);
+ opt->palette, false, 1, nullptr);
qDrawShadePanel(p, 2, y + 3, opt->rect.width() - 4, 3,
- opt->palette, false, 1, 0);
+ opt->palette, false, 1, nullptr);
}
}
p->restore();
@@ -759,7 +753,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt,
}
} else {
qDrawWinButton(p, opt->rect, opt->palette,
- opt->state & (State_Sunken | State_On), panel ? &fill : 0);
+ opt->state & (State_Sunken | State_On), panel ? &fill : nullptr);
}
} else {
p->fillRect(opt->rect, fill);
@@ -980,7 +974,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt,
if (opt->state & (State_Raised | State_On | State_Sunken)) {
qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On),
- panel ? &fill : 0);
+ panel ? &fill : nullptr);
} else {
if (panel)
p->fillRect(opt->rect, fill);
@@ -1005,7 +999,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt,
#endif // QT_CONFIG(dockwidget)
case PE_FrameStatusBarItem:
- qDrawShadePanel(p, opt->rect, opt->palette, true, 1, 0);
+ qDrawShadePanel(p, opt->rect, opt->palette, true, 1, nullptr);
break;
case PE_IndicatorProgressChunk:
@@ -1043,7 +1037,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt,
break;
case PE_FrameTabWidget: {
- qDrawWinButton(p, opt->rect, opt->palette, false, 0);
+ qDrawWinButton(p, opt->rect, opt->palette, false, nullptr);
break;
}
default:
@@ -1585,6 +1579,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
case QStyleOptionToolBar::Beginning:
case QStyleOptionToolBar::OnlyOne:
paintBottomBorder = false;
+ break;
default:
break;
}
@@ -1600,6 +1595,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
case QStyleOptionToolBar::OnlyOne:
paintRightBorder = false;
paintLeftBorder = false;
+ break;
default:
break;
}
diff --git a/src/widgets/styles/qwindowsstyle_p_p.h b/src/widgets/styles/qwindowsstyle_p_p.h
index e6ea809f11..4f6ffcefc2 100644
--- a/src/widgets/styles/qwindowsstyle_p_p.h
+++ b/src/widgets/styles/qwindowsstyle_p_p.h
@@ -77,9 +77,9 @@ public:
bool hasSeenAlt(const QWidget *widget) const;
bool altDown() const { return alt_down; }
- bool alt_down;
+ bool alt_down = false;
QList<const QWidget *> seenAlt;
- int menuBarTimer;
+ int menuBarTimer = 0;
QColor inactiveCaptionText;
QColor activeCaptionColor;
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index e73c63f657..9a0e969e1c 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -862,6 +862,16 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const
when the choice is not changed. If you need to know when the
choice actually changes, use signal currentIndexChanged().
+ \obsolete Use QComboBox::textActivated() instead
+*/
+/*!
+ \fn void QComboBox::textActivated(const QString &text)
+ \since 5.14
+
+ This signal is sent when the user chooses an item in the combobox.
+ The item's \a text is passed. Note that this signal is sent even
+ when the choice is not changed. If you need to know when the
+ choice actually changes, use signal currentIndexChanged().
*/
/*!
@@ -876,6 +886,15 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const
This signal is sent when an item in the combobox popup list is
highlighted by the user. The item's \a text is passed.
+
+ \obsolete Use textHighlighted() instead
+*/
+/*!
+ \fn void QComboBox::textHighlighted(const QString &text)
+ \since 5.14
+
+ This signal is sent when an item in the combobox popup list is
+ highlighted by the user. The item's \a text is passed.
*/
/*!
@@ -888,7 +907,6 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const
currentIndex was reset.
*/
-#if QT_DEPRECATED_SINCE(5, 13)
/*!
\fn void QComboBox::currentIndexChanged(const QString &text)
\since 4.1
@@ -897,7 +915,6 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const
changes either through user interaction or programmatically. The
item's \a text is passed.
*/
-#endif
/*!
\fn void QComboBox::currentTextChanged(const QString &text)
@@ -2522,21 +2539,6 @@ QSize QComboBox::sizeHint() const
}
#ifdef Q_OS_MAC
-
-namespace {
-struct IndexSetter {
- int index;
- QComboBox *cb;
-
- void operator()(void)
- {
- cb->setCurrentIndex(index);
- emit cb->activated(index);
- emit cb->activated(cb->itemText(index));
- }
-};
-}
-
void QComboBoxPrivate::cleanupNativePopup()
{
if (!m_platformMenu)
diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h
index eadb21628f..5967776a61 100644
--- a/src/widgets/widgets/qcombobox_p.h
+++ b/src/widgets/widgets/qcombobox_p.h
@@ -390,6 +390,16 @@ public:
#ifdef Q_OS_MAC
void cleanupNativePopup();
bool showNativePopup();
+ struct IndexSetter {
+ int index;
+ QComboBox *cb;
+
+ void operator()(void)
+ {
+ cb->setCurrentIndex(index);
+ cb->d_func()->emitActivated(cb->d_func()->currentIndex);
+ }
+ };
#endif
QAbstractItemModel *model;
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index e38490dabd..51b458f03a 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -2332,14 +2332,17 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
// However if the QMenu was constructed with a QDesktopScreenWidget as its parent,
// then initialScreenIndex was set, so we should respect that for the lifetime of this menu.
// Use d->popupScreen to remember, because initialScreenIndex will be reset after the first showing.
- const int screenIndex = d->topData()->initialScreenIndex;
- if (screenIndex >= 0)
- d->popupScreen = screenIndex;
- if (auto s = QGuiApplication::screens().value(d->popupScreen)) {
- if (d->setScreen(s))
+ // However if eventLoop exists, then exec() already did this by calling createWinId(); so leave it alone. (QTBUG-76162)
+ if (!d->eventLoop) {
+ const int screenIndex = d->topData()->initialScreenIndex;
+ if (screenIndex >= 0)
+ d->popupScreen = screenIndex;
+ if (auto s = QGuiApplication::screens().value(d->popupScreen)) {
+ if (d->setScreen(s))
+ d->itemsDirty = true;
+ } else if (d->setScreenForPoint(p)) {
d->itemsDirty = true;
- } else if (d->setScreenForPoint(p)) {
- d->itemsDirty = true;
+ }
}
const bool contextMenu = d->isContextMenu();
diff --git a/src/widgets/widgets/qsplashscreen.cpp b/src/widgets/widgets/qsplashscreen.cpp
index e39ef6d1cd..b7c3426e08 100644
--- a/src/widgets/widgets/qsplashscreen.cpp
+++ b/src/widgets/widgets/qsplashscreen.cpp
@@ -123,6 +123,11 @@ public:
wish to do your own drawing you can get a pointer to the pixmap
used in the splash screen with pixmap(). Alternatively, you can
subclass QSplashScreen and reimplement drawContents().
+
+ In case of having multiple screens, it is also possible to show the
+ splash screen on a different screen than the primary one. For example:
+
+ \snippet qsplashscreen/main.cpp 2
*/
/*!
@@ -139,6 +144,23 @@ QSplashScreen::QSplashScreen(const QPixmap &pixmap, Qt::WindowFlags f)
/*!
\overload
+ \since 5.15
+
+ This function allows you to specify the screen for your splashscreen. The
+ typical use for this constructor is if you have multiple screens and
+ prefer to have the splash screen on a different screen than your primary
+ one. In that case pass the proper \a screen.
+*/
+QSplashScreen::QSplashScreen(QScreen *screen, const QPixmap &pixmap, Qt::WindowFlags f)
+ : QWidget(*(new QSplashScreenPrivate()), nullptr, Qt::SplashScreen | Qt::FramelessWindowHint | f)
+{
+ d_func()->setPixmap(pixmap, screen);
+}
+
+#if QT_DEPRECATED_SINCE(5, 15)
+/*!
+ \overload
+ \obsolete
This function allows you to specify a parent for your splashscreen. The
typical use for this constructor is if you have a multiple screens and
@@ -152,6 +174,7 @@ QSplashScreen::QSplashScreen(QWidget *parent, const QPixmap &pixmap, Qt::WindowF
// is still 0 here due to QWidget's special handling.
d_func()->setPixmap(pixmap, QSplashScreenPrivate::screenFor(parent));
}
+#endif
/*!
Destructor.
@@ -286,26 +309,35 @@ void QSplashScreen::setPixmap(const QPixmap &pixmap)
}
// In setPixmap(), resize and try to position on a screen according to:
-// 1) If a QDesktopScreenWidget is found in the parent hierarchy, use that (see docs on
+// 1) If the screen for the given widget is available, use that
+// 2) If a QDesktopScreenWidget is found in the parent hierarchy, use that (see docs on
// QSplashScreen(QWidget *, QPixmap).
-// 2) If a widget with associated QWindow is found, use that
-// 3) When nothing can be found, try to center it over the cursor
+// 3) If a widget with associated QWindow is found, use that
+// 4) When nothing can be found, try to center it over the cursor
+#if QT_DEPRECATED_SINCE(5, 15)
static inline int screenNumberOf(const QDesktopScreenWidget *dsw)
{
auto desktopWidgetPrivate =
static_cast<QDesktopWidgetPrivate *>(qt_widget_private(QApplication::desktop()));
return desktopWidgetPrivate->screens.indexOf(const_cast<QDesktopScreenWidget *>(dsw));
}
+#endif
const QScreen *QSplashScreenPrivate::screenFor(const QWidget *w)
{
+ if (w && w->screen())
+ return w->screen();
+
for (const QWidget *p = w; p !=nullptr ; p = p->parentWidget()) {
+#if QT_DEPRECATED_SINCE(5, 15)
if (auto dsw = qobject_cast<const QDesktopScreenWidget *>(p))
return QGuiApplication::screens().value(screenNumberOf(dsw));
+#endif
if (QWindow *window = p->windowHandle())
return window->screen();
}
+
#if QT_CONFIG(cursor)
// Note: We could rely on QPlatformWindow::initialGeometry() to center it
// over the cursor, but not all platforms (namely Android) use that.
diff --git a/src/widgets/widgets/qsplashscreen.h b/src/widgets/widgets/qsplashscreen.h
index 8bdf4e7749..1877493fcf 100644
--- a/src/widgets/widgets/qsplashscreen.h
+++ b/src/widgets/widgets/qsplashscreen.h
@@ -55,7 +55,11 @@ class Q_WIDGETS_EXPORT QSplashScreen : public QWidget
Q_OBJECT
public:
explicit QSplashScreen(const QPixmap &pixmap = QPixmap(), Qt::WindowFlags f = Qt::WindowFlags());
+ QSplashScreen(QScreen *screen, const QPixmap &pixmap = QPixmap(), Qt::WindowFlags f = Qt::WindowFlags());
+#if QT_DEPRECATED_SINCE(5, 15)
+ QT_DEPRECATED_VERSION_X_5_15("Use the constructor taking a QScreen *")
QSplashScreen(QWidget *parent, const QPixmap &pixmap = QPixmap(), Qt::WindowFlags f = Qt::WindowFlags());
+#endif
virtual ~QSplashScreen();
void setPixmap(const QPixmap &pixmap);
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
index 921847a087..16fcafa248 100644
--- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
@@ -2098,8 +2098,7 @@ void tst_QFileInfo::owner()
DWORD bufSize = 1024;
if (GetUserNameW(usernameBuf, &bufSize)) {
userName = QString::fromWCharArray(usernameBuf);
- if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista
- && IsUserAdmin()) {
+ if (IsUserAdmin()) {
// Special case : If the user is a member of Administrators group, all files
// created by the current user are owned by the Administrators group.
LPLOCALGROUP_USERS_INFO_0 pBuf = NULL;
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 3123c42326..ef4325d2ea 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -3389,8 +3389,15 @@ void tst_QUrl::acceptEmptyAuthoritySegments()
void tst_QUrl::effectiveTLDs_data()
{
+ // See also: tst_QNetworkCookieJar::setCookiesFromUrl().
+ // in tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
QTest::addColumn<QUrl>("domain");
QTest::addColumn<QString>("TLD");
+ // TODO: autogenerate test-cases from:
+ // https://raw.githubusercontent.com/publicsuffix/list/master/tests/test_psl.txt
+ // checkPublicSuffix(domain, tail) appears in the list if
+ // either tail is null and domain is public or
+ // tail is the "registrable" part of domain; i.e. its minimal non-public tail.
QTest::newRow("yes0") << QUrl::fromEncoded("http://test.co.uk") << ".co.uk";
QTest::newRow("yes1") << QUrl::fromEncoded("http://test.com") << ".com";
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index ac1b903aa1..531ac2995f 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -3352,6 +3352,14 @@ void tst_QDateTime::timeZones() const
QCOMPARE(dt3.timeSpec(), dt1.timeSpec());
QCOMPARE(dt3.timeZone(), dt1.timeZone());
+ // The start of year 1 should be *describable* in any zone (QTBUG-78051)
+ dt3 = QDateTime(QDate(1, 1, 1), QTime(0, 0, 0), ausTz);
+ QVERIFY(dt3.isValid());
+ // Likewise the end of year -1 (a.k.a. 1 BCE).
+ dt3 = dt3.addMSecs(-1);
+ QVERIFY(dt3.isValid());
+ QCOMPARE(dt3, QDateTime(QDate(-1, 12, 31), QTime(23, 59, 59, 999), ausTz));
+
// Check datastream serialises the time zone
QByteArray tmp;
{
diff --git a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
index 9904719f7c..5b1bde8ea3 100644
--- a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
+++ b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -49,6 +49,8 @@ private slots:
void dataStreamTest();
void isTimeZoneIdAvailable();
void availableTimeZoneIds();
+ void utcOffsetId_data();
+ void utcOffsetId();
void specificTransition_data();
void specificTransition();
void transitionEachZone_data();
@@ -375,33 +377,121 @@ void tst_QTimeZone::dataStreamTest()
void tst_QTimeZone::isTimeZoneIdAvailable()
{
QList<QByteArray> available = QTimeZone::availableTimeZoneIds();
- foreach (const QByteArray &id, available)
+ foreach (const QByteArray &id, available) {
QVERIFY(QTimeZone::isTimeZoneIdAvailable(id));
+ QVERIFY(QTimeZone(id).isValid());
+ }
+}
-#ifdef QT_BUILD_INTERNAL
- // a-z, A-Z, 0-9, '.', '-', '_' are valid chars
- // Can't start with '-'
- // Parts separated by '/', each part min 1 and max of 14 chars
- QCOMPARE(QTimeZonePrivate::isValidId("az"), true);
- QCOMPARE(QTimeZonePrivate::isValidId("AZ"), true);
- QCOMPARE(QTimeZonePrivate::isValidId("09"), true);
- QCOMPARE(QTimeZonePrivate::isValidId("a/z"), true);
- QCOMPARE(QTimeZonePrivate::isValidId("a.z"), true);
- QCOMPARE(QTimeZonePrivate::isValidId("a-z"), true);
- QCOMPARE(QTimeZonePrivate::isValidId("a_z"), true);
- QCOMPARE(QTimeZonePrivate::isValidId(".z"), true);
- QCOMPARE(QTimeZonePrivate::isValidId("_z"), true);
- QCOMPARE(QTimeZonePrivate::isValidId("12345678901234"), true);
- QCOMPARE(QTimeZonePrivate::isValidId("12345678901234/12345678901234"), true);
- QCOMPARE(QTimeZonePrivate::isValidId("a z"), false);
- QCOMPARE(QTimeZonePrivate::isValidId("a\\z"), false);
- QCOMPARE(QTimeZonePrivate::isValidId("a,z"), false);
- QCOMPARE(QTimeZonePrivate::isValidId("/z"), false);
- QCOMPARE(QTimeZonePrivate::isValidId("-z"), false);
- QCOMPARE(QTimeZonePrivate::isValidId("123456789012345"), false);
- QCOMPARE(QTimeZonePrivate::isValidId("123456789012345/12345678901234"), false);
- QCOMPARE(QTimeZonePrivate::isValidId("12345678901234/123456789012345"), false);
-#endif // QT_BUILD_INTERNAL
+void tst_QTimeZone::utcOffsetId_data()
+{
+ QTest::addColumn<QByteArray>("id");
+ QTest::addColumn<bool>("valid");
+ QTest::addColumn<int>("offset"); // ignored unless valid
+
+ // Some of these are actual CLDR zone IDs, some are known Windows IDs; the
+ // rest rely on parsing the offset. Since CLDR and Windows may add to their
+ // known IDs, which fall in which category may vary. Only the CLDR and
+ // Windows ones are known to isTimeZoneAvailable() or listed in
+ // availableTimeZoneIds().
+#define ROW(name, valid, offset) \
+ QTest::newRow(name) << QByteArray(name) << valid << offset
+
+ // See qtbase/util/locale_database/cldr2qtimezone.py for source
+ // CLDR v35.1 IDs:
+ ROW("UTC", true, 0);
+ ROW("UTC-14:00", true, -50400);
+ ROW("UTC-13:00", true, -46800);
+ ROW("UTC-12:00", true, -43200);
+ ROW("UTC-11:00", true, -39600);
+ ROW("UTC-10:00", true, -36000);
+ ROW("UTC-09:00", true, -32400);
+ ROW("UTC-08:00", true, -28800);
+ ROW("UTC-07:00", true, -25200);
+ ROW("UTC-06:00", true, -21600);
+ ROW("UTC-05:00", true, -18000);
+ ROW("UTC-04:30", true, -16200);
+ ROW("UTC-04:00", true, -14400);
+ ROW("UTC-03:30", true, -12600);
+ ROW("UTC-03:00", true, -10800);
+ ROW("UTC-02:00", true, -7200);
+ ROW("UTC-01:00", true, -3600);
+ ROW("UTC-00:00", true, 0);
+ ROW("UTC+00:00", true, 0);
+ ROW("UTC+01:00", true, 3600);
+ ROW("UTC+02:00", true, 7200);
+ ROW("UTC+03:00", true, 10800);
+ ROW("UTC+03:30", true, 12600);
+ ROW("UTC+04:00", true, 14400);
+ ROW("UTC+04:30", true, 16200);
+ ROW("UTC+05:00", true, 18000);
+ ROW("UTC+05:30", true, 19800);
+ ROW("UTC+05:45", true, 20700);
+ ROW("UTC+06:00", true, 21600);
+ ROW("UTC+06:30", true, 23400);
+ ROW("UTC+07:00", true, 25200);
+ ROW("UTC+08:00", true, 28800);
+ ROW("UTC+08:30", true, 30600);
+ ROW("UTC+09:00", true, 32400);
+ ROW("UTC+09:30", true, 34200);
+ ROW("UTC+10:00", true, 36000);
+ ROW("UTC+11:00", true, 39600);
+ ROW("UTC+12:00", true, 43200);
+ ROW("UTC+13:00", true, 46800);
+ ROW("UTC+14:00", true, 50400);
+ // Windows IDs known to CLDR v35.1:
+ ROW("UTC-11", true, -39600);
+ ROW("UTC-09", true, -32400);
+ ROW("UTC-08", true, -28800);
+ ROW("UTC-02", true, -7200);
+ ROW("UTC+12", true, 43200);
+ ROW("UTC+13", true, 46800);
+ // Encountered in bug reports:
+ ROW("UTC+10", true, 36000); // QTBUG-77738
+
+ // Bounds:
+ ROW("UTC+23", true, 82800);
+ ROW("UTC-23", true, -82800);
+ ROW("UTC+23:59", true, 86340);
+ ROW("UTC-23:59", true, -86340);
+ ROW("UTC+23:59:59", true, 86399);
+ ROW("UTC-23:59:59", true, -86399);
+
+ // Out of range
+ ROW("UTC+24:0:0", false, 0);
+ ROW("UTC-24:0:0", false, 0);
+ ROW("UTC+0:60:0", false, 0);
+ ROW("UTC-0:60:0", false, 0);
+ ROW("UTC+0:0:60", false, 0);
+ ROW("UTC-0:0:60", false, 0);
+
+ // Malformed
+ ROW("UTC+", false, 0);
+ ROW("UTC-", false, 0);
+ ROW("UTC10", false, 0);
+ ROW("UTC:10", false, 0);
+ ROW("UTC+cabbage", false, 0);
+ ROW("UTC+10:rice", false, 0);
+ ROW("UTC+9:3:oat", false, 0);
+ ROW("UTC+9+3", false, 0);
+ ROW("UTC+9-3", false, 0);
+ ROW("UTC+9:3-4", false, 0);
+ ROW("UTC+9:3:4:more", false, 0);
+ ROW("UTC+9:3:4:5", false, 0);
+}
+
+void tst_QTimeZone::utcOffsetId()
+{
+ QFETCH(QByteArray, id);
+ QFETCH(bool, valid);
+ QTimeZone zone(id);
+ QCOMPARE(zone.isValid(), valid);
+ if (valid) {
+ QDateTime epoch(QDate(1970, 1, 1), QTime(0, 0, 0), Qt::UTC);
+ QFETCH(int, offset);
+ QCOMPARE(zone.offsetFromUtc(epoch), offset);
+ QVERIFY(!zone.hasDaylightTime());
+ }
}
void tst_QTimeZone::specificTransition_data()
@@ -733,10 +823,16 @@ void tst_QTimeZone::isValidId_data()
QTest::newRow(name " middle") << QByteArray("xyz/" section "/xyz") << valid; \
QTest::newRow(name " back") << QByteArray("xyz/xyz/" section) << valid
+ // a-z, A-Z, 0-9, '.', '-', '_' are valid chars
+ // Can't start with '-'
+ // Parts separated by '/', each part min 1 and max of 14 chars
TESTSET("empty", "", false);
TESTSET("minimal", "m", true);
TESTSET("maximal", "12345678901234", true);
+ TESTSET("maximal twice", "12345678901234/12345678901234", true);
TESTSET("too long", "123456789012345", false);
+ TESTSET("too-long/maximal", "123456789012345/12345678901234", false);
+ TESTSET("maximal/too-long", "12345678901234/123456789012345", false);
TESTSET("bad hyphen", "-hyphen", false);
TESTSET("good hyphen", "hy-phen", true);
@@ -752,6 +848,22 @@ void tst_QTimeZone::isValidId_data()
TESTSET("valid char 0", "0", true);
TESTSET("valid char 9", "9", true);
+ TESTSET("valid pair az", "az", true);
+ TESTSET("valid pair AZ", "AZ", true);
+ TESTSET("valid pair 09", "09", true);
+ TESTSET("valid pair .z", ".z", true);
+ TESTSET("valid pair _z", "_z", true);
+ TESTSET("invalid pair -z", "-z", false);
+
+ TESTSET("valid triple a/z", "a/z", true);
+ TESTSET("valid triple a.z", "a.z", true);
+ TESTSET("valid triple a-z", "a-z", true);
+ TESTSET("valid triple a_z", "a_z", true);
+ TESTSET("invalid triple a z", "a z", false);
+ TESTSET("invalid triple a\\z", "a\\z", false);
+ TESTSET("invalid triple a,z", "a,z", false);
+
+ TESTSET("invalid space", " ", false);
TESTSET("invalid char ^", "^", false);
TESTSET("invalid char \"", "\"", false);
TESTSET("invalid char $", "$", false);
@@ -760,6 +872,7 @@ void tst_QTimeZone::isValidId_data()
TESTSET("invalid char (", "(", false);
TESTSET("invalid char )", ")", false);
TESTSET("invalid char =", "=", false);
+ TESTSET("invalid char -", "-", false);
TESTSET("invalid char ?", "?", false);
TESTSET("invalid char ß", "ß", false);
TESTSET("invalid char \\x01", "\x01", false);
@@ -824,10 +937,6 @@ void tst_QTimeZone::utcTest()
QCOMPARE(tz.standardTimeOffset(now), 36000);
QCOMPARE(tz.daylightTimeOffset(now), 0);
- // Test invalid UTC ID, must be in available list
- tz = QTimeZone("UTC+00:01");
- QCOMPARE(tz.isValid(), false);
-
// Test create custom zone
tz = QTimeZone("QST", 123456, "Qt Standard Time", "QST", QLocale::Norway, "Qt Testing");
QCOMPARE(tz.isValid(), true);
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
index 4f26950192..1290347eab 100644
--- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
+++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
@@ -1025,6 +1025,23 @@ public:
Qt::MouseButtons buttonStateInGeneratedMove;
};
+static void simulateMouseClick(QWindow *target, const QPointF &local, const QPointF &global)
+{
+ QWindowSystemInterface::handleMouseEvent(target, local, global,
+ {}, Qt::LeftButton, QEvent::MouseButtonPress);
+ QWindowSystemInterface::handleMouseEvent(target, local, global,
+ Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonRelease);
+}
+
+static void simulateMouseClick(QWindow *target, ulong &timeStamp,
+ const QPointF &local, const QPointF &global)
+{
+ QWindowSystemInterface::handleMouseEvent(target, timeStamp++, local, global,
+ {}, Qt::LeftButton, QEvent::MouseButtonPress);
+ QWindowSystemInterface::handleMouseEvent(target, timeStamp++, local, global,
+ Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonRelease);
+}
+
void tst_QWindow::testInputEvents()
{
InputTestWindow window;
@@ -1066,15 +1083,13 @@ void tst_QWindow::testInputEvents()
window.mousePressButton = window.mouseReleaseButton = 0;
const QPointF nonWindowGlobal(window.geometry().topRight() + QPoint(200, 50)); // not inside the window
const QPointF deviceNonWindowGlobal = QHighDpi::toNativePixels(nonWindowGlobal, window.screen());
- QWindowSystemInterface::handleMouseEvent(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::NoButton);
+ simulateMouseClick(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal);
QCoreApplication::processEvents();
QCOMPARE(window.mousePressButton, 0);
QCOMPARE(window.mouseReleaseButton, 0);
const QPointF windowGlobal = window.mapToGlobal(local.toPoint());
const QPointF deviceWindowGlobal = QHighDpi::toNativePixels(windowGlobal, window.screen());
- QWindowSystemInterface::handleMouseEvent(nullptr, deviceWindowGlobal, deviceWindowGlobal, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(nullptr, deviceWindowGlobal, deviceWindowGlobal, Qt::NoButton);
+ simulateMouseClick(nullptr, deviceWindowGlobal, deviceWindowGlobal);
QCoreApplication::processEvents();
QCOMPARE(window.mousePressButton, int(Qt::LeftButton));
QCOMPARE(window.mouseReleaseButton, int(Qt::LeftButton));
@@ -1198,8 +1213,7 @@ void tst_QWindow::mouseToTouchTranslation()
window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window));
- QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton);
+ QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10));
QCoreApplication::processEvents();
QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false);
@@ -1211,8 +1225,7 @@ void tst_QWindow::mouseToTouchTranslation()
window.ignoreMouse = false;
- QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton);
+ QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10));
QCoreApplication::processEvents();
QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false);
@@ -1223,8 +1236,7 @@ void tst_QWindow::mouseToTouchTranslation()
window.ignoreMouse = true;
- QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton);
+ QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10));
QCoreApplication::processEvents();
// touch event synthesis disabled
@@ -1249,8 +1261,7 @@ void tst_QWindow::mouseToTouchLoop()
window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window));
- QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton);
+ QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10));
QCoreApplication::processEvents();
QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false);
@@ -1545,8 +1556,8 @@ void tst_QWindow::mouseEventSequence()
ulong timestamp = 0;
QPointF local(12, 34);
const QPointF deviceLocal = QHighDpi::toNativePixels(local, &window);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, deviceLocal, deviceLocal, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, deviceLocal, deviceLocal, Qt::NoButton);
+
+ simulateMouseClick(&window, timestamp, deviceLocal, deviceLocal);
QCoreApplication::processEvents();
QCOMPARE(window.mousePressedCount, 1);
QCOMPARE(window.mouseReleasedCount, 1);
@@ -1558,10 +1569,8 @@ void tst_QWindow::mouseEventSequence()
// A double click must result in press, release, press, doubleclick, release.
// Check that no unexpected event suppression occurs and that the order is correct.
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton);
+ simulateMouseClick(&window, timestamp, local, local);
+ simulateMouseClick(&window, timestamp, local, local);
QCoreApplication::processEvents();
QCOMPARE(window.mousePressedCount, 2);
QCOMPARE(window.mouseReleasedCount, 2);
@@ -1572,12 +1581,9 @@ void tst_QWindow::mouseEventSequence()
window.resetCounters();
// Triple click = double + single click
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton);
+ simulateMouseClick(&window, timestamp, local, local);
+ simulateMouseClick(&window, timestamp, local, local);
+ simulateMouseClick(&window, timestamp, local, local);
QCoreApplication::processEvents();
QCOMPARE(window.mousePressedCount, 3);
QCOMPARE(window.mouseReleasedCount, 3);
@@ -1588,14 +1594,10 @@ void tst_QWindow::mouseEventSequence()
window.resetCounters();
// Two double clicks.
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton);
+ simulateMouseClick(&window, timestamp, local, local);
+ simulateMouseClick(&window, timestamp, local, local);
+ simulateMouseClick(&window, timestamp, local, local);
+ simulateMouseClick(&window, timestamp, local, local);
QCoreApplication::processEvents();
QCOMPARE(window.mousePressedCount, 4);
QCOMPARE(window.mouseReleasedCount, 4);
@@ -1606,17 +1608,13 @@ void tst_QWindow::mouseEventSequence()
window.resetCounters();
// Four clicks, none of which qualifies as a double click.
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton);
+ simulateMouseClick(&window, timestamp, local, local);
timestamp += doubleClickInterval;
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton);
+ simulateMouseClick(&window, timestamp, local, local);
timestamp += doubleClickInterval;
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton);
+ simulateMouseClick(&window, timestamp, local, local);
timestamp += doubleClickInterval;
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton);
+ simulateMouseClick(&window, timestamp, local, local);
timestamp += doubleClickInterval;
QCoreApplication::processEvents();
QCOMPARE(window.mousePressedCount, 4);
@@ -1668,10 +1666,13 @@ void tst_QWindow::inputReentrancy()
// Queue three events.
QPointF local(12, 34);
- QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton);
+ QWindowSystemInterface::handleMouseEvent(&window, local, local, {},
+ Qt::LeftButton, QEvent::MouseButtonPress);
local += QPointF(2, 2);
- QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::NoButton);
+ QWindowSystemInterface::handleMouseEvent(&window, local, local,
+ Qt::LeftButton, Qt::LeftButton, QEvent::MouseMove);
+ QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton,
+ Qt::LeftButton, QEvent::MouseButtonRelease);
// Process them. However, the event handler for the press will also call
// processEvents() so the move and release will be delivered before returning
// from mousePressEvent(). The point is that no events should get lost.
@@ -1741,12 +1742,14 @@ void tst_QWindow::tabletEvents()
const QPoint global = window.mapToGlobal(local);
const QPoint deviceLocal = QHighDpi::toNativeLocalPosition(local, &window);
const QPoint deviceGlobal = QHighDpi::toNativePixels(global, window.screen());
- QWindowSystemInterface::handleTabletEvent(&window, true, deviceLocal, deviceGlobal, 1, 2, 0.5, 1, 2, 0.1, 0, 0, 0);
+ QWindowSystemInterface::handleTabletEvent(&window, deviceLocal, deviceGlobal,
+ 1, 2, Qt::LeftButton, 0.5, 1, 2, 0.1, 0, 0, 0);
QCoreApplication::processEvents();
QTRY_VERIFY(window.eventType == QEvent::TabletPress);
QTRY_COMPARE(window.eventGlobal.toPoint(), global);
QTRY_COMPARE(window.eventLocal.toPoint(), local);
- QWindowSystemInterface::handleTabletEvent(&window, false, deviceLocal, deviceGlobal, 1, 2, 0.5, 1, 2, 0.1, 0, 0, 0);
+ QWindowSystemInterface::handleTabletEvent(&window, deviceLocal, deviceGlobal, 1, 2,
+ {}, 0.5, 1, 2, 0.1, 0, 0, 0);
QCoreApplication::processEvents();
QTRY_COMPARE(window.eventType, QEvent::TabletRelease);
@@ -1782,11 +1785,9 @@ void tst_QWindow::windowModality_QTBUG27039()
modalB.setModality(Qt::ApplicationModal);
modalB.show();
- QPointF local(5, 5);
- QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::NoButton);
- QWindowSystemInterface::handleMouseEvent(&modalB, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&modalB, local, local, Qt::NoButton);
+ QPoint local(5, 5);
+ QTest::mouseClick(&modalA, Qt::LeftButton, {}, local);
+ QTest::mouseClick(&modalB, Qt::LeftButton, {}, local);
QCoreApplication::processEvents();
// modal A should be blocked since it was shown first, but modal B should not be blocked
@@ -1794,8 +1795,7 @@ void tst_QWindow::windowModality_QTBUG27039()
QCOMPARE(modalA.mousePressedCount, 0);
modalB.hide();
- QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::LeftButton);
- QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::NoButton);
+ QTest::mouseClick(&modalA, Qt::LeftButton, {}, local);
QCoreApplication::processEvents();
// modal B has been hidden, modal A should be unblocked again
diff --git a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
index d51cfdee2f..531e14d25b 100644
--- a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
+++ b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
@@ -123,9 +123,6 @@ void tst_QColorSpace::namedColorSpaces_data()
QTest::newRow("ProPhoto RGB") << QColorSpace::ProPhotoRgb
<< QColorSpace::Primaries::ProPhotoRgb
<< QColorSpace::TransferFunction::ProPhotoRgb;
- QTest::newRow("BT.2020") << QColorSpace::Bt2020
- << QColorSpace::Primaries::Bt2020
- << QColorSpace::TransferFunction::Bt2020;
}
void tst_QColorSpace::namedColorSpaces()
@@ -220,7 +217,6 @@ void tst_QColorSpace::imageConversion_data()
QTest::newRow("Display-P3 -> sRGB") << QColorSpace::DisplayP3 << QColorSpace::SRgb << 0;
QTest::newRow("Adobe RGB -> sRGB") << QColorSpace::AdobeRgb << QColorSpace::SRgb << 2;
QTest::newRow("Display-P3 -> Adobe RGB") << QColorSpace::DisplayP3 << QColorSpace::AdobeRgb << 2;
- QTest::newRow("Display-P3 -> BT.2020") << QColorSpace::DisplayP3 << QColorSpace::Bt2020 << 4;
QTest::newRow("sRGB -> sRGB Linear") << QColorSpace::SRgb << QColorSpace::SRgbLinear << 0;
}
@@ -351,14 +347,12 @@ void tst_QColorSpace::primariesXyz()
QColorSpace adobeRgb = QColorSpace::AdobeRgb;
QColorSpace displayP3 = QColorSpace::DisplayP3;
QColorSpace proPhotoRgb = QColorSpace::ProPhotoRgb;
- QColorSpace bt2020 = QColorSpace::Bt2020;
// Check if our calculated matrices, match the precalculated ones.
QCOMPARE(QColorSpacePrivate::get(sRgb)->toXyz, QColorMatrix::toXyzFromSRgb());
QCOMPARE(QColorSpacePrivate::get(adobeRgb)->toXyz, QColorMatrix::toXyzFromAdobeRgb());
QCOMPARE(QColorSpacePrivate::get(displayP3)->toXyz, QColorMatrix::toXyzFromDciP3D65());
QCOMPARE(QColorSpacePrivate::get(proPhotoRgb)->toXyz, QColorMatrix::toXyzFromProPhotoRgb());
- QCOMPARE(QColorSpacePrivate::get(bt2020)->toXyz, QColorMatrix::toXyzFromBt2020());
}
#ifdef QT_BUILD_INTERNAL
@@ -370,7 +364,6 @@ void tst_QColorSpace::primaries2_data()
QTest::newRow("DCI-P3 (D65)") << QColorSpace::Primaries::DciP3D65;
QTest::newRow("Adobe RGB (1998)") << QColorSpace::Primaries::AdobeRgb;
QTest::newRow("ProPhoto RGB") << QColorSpace::Primaries::ProPhotoRgb;
- QTest::newRow("BT.2020") << QColorSpace::Primaries::Bt2020;
}
void tst_QColorSpace::primaries2()
diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp
index 96f3b1c1d7..1ee9105cd2 100644
--- a/tests/auto/gui/text/qfont/tst_qfont.cpp
+++ b/tests/auto/gui/text/qfont/tst_qfont.cpp
@@ -539,10 +539,10 @@ void tst_QFont::defaultFamily_data()
QTest::addColumn<QStringList>("acceptableFamilies");
QTest::newRow("serif") << QFont::Serif << (QStringList() << "Times New Roman" << "Times" << "Droid Serif" << getPlatformGenericFont("serif").split(","));
- QTest::newRow("monospace") << QFont::Monospace << (QStringList() << "Courier New" << "Monaco" << "Droid Sans Mono" << getPlatformGenericFont("monospace").split(","));
+ QTest::newRow("monospace") << QFont::Monospace << (QStringList() << "Courier New" << "Monaco" << "Menlo" << "Droid Sans Mono" << getPlatformGenericFont("monospace").split(","));
QTest::newRow("cursive") << QFont::Cursive << (QStringList() << "Comic Sans MS" << "Apple Chancery" << "Roboto" << "Droid Sans" << getPlatformGenericFont("cursive").split(","));
QTest::newRow("fantasy") << QFont::Fantasy << (QStringList() << "Impact" << "Zapfino" << "Roboto" << "Droid Sans" << getPlatformGenericFont("fantasy").split(","));
- QTest::newRow("sans-serif") << QFont::SansSerif << (QStringList() << "Arial" << "Lucida Grande" << "Roboto" << "Droid Sans" << "Segoe UI" << getPlatformGenericFont("sans-serif").split(","));
+ QTest::newRow("sans-serif") << QFont::SansSerif << (QStringList() << "Arial" << "Lucida Grande" << "Helvetica" << "Roboto" << "Droid Sans" << "Segoe UI" << getPlatformGenericFont("sans-serif").split(","));
}
void tst_QFont::defaultFamily()
diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
index aee2f970fe..a474acd790 100644
--- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
+++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
@@ -139,6 +139,7 @@ private slots:
void superscriptCrash_qtbug53911();
void showLineAndParagraphSeparatorsCrash();
void koreanWordWrap();
+ void tooManyDirectionalCharctersCrash_qtbug77819();
private:
QFont testFont;
@@ -2330,5 +2331,21 @@ void tst_QTextLayout::koreanWordWrap()
QCOMPARE(layout.lineAt(1).textLength(), 4);
}
+void tst_QTextLayout::tooManyDirectionalCharctersCrash_qtbug77819()
+{
+ QString data;
+ data += QString::fromUtf8("\xe2\x81\xa8"); // U+2068 FSI character
+ data += QString::fromUtf8("\xe2\x81\xa7"); // U+2067 RLI character
+
+ // duplicating the text
+ for (int i = 0; i < 10; i++)
+ data += data;
+
+ // Nothing to test. It must not crash in beginLayout().
+ QTextLayout tl(data);
+ tl.beginLayout();
+ tl.endLayout();
+}
+
QTEST_MAIN(tst_QTextLayout)
#include "tst_qtextlayout.moc"
diff --git a/tests/auto/network/access/http2/tst_http2.cpp b/tests/auto/network/access/http2/tst_http2.cpp
index e24a06bc34..c264956d7b 100644
--- a/tests/auto/network/access/http2/tst_http2.cpp
+++ b/tests/auto/network/access/http2/tst_http2.cpp
@@ -477,6 +477,9 @@ void tst_Http2::goaway_data()
// - server waits for some time (enough for ur to init several streams on a
// client side); then suddenly it replies with GOAWAY, never processing any
// request.
+ if (clearTextHTTP2)
+ QSKIP("This test requires TLS with ALPN to work");
+
QTest::addColumn<int>("responseTimeoutMS");
QTest::newRow("ImmediateGOAWAY") << 0;
QTest::newRow("DelayedGOAWAY") << 1000;
diff --git a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
index 1ef2c118b9..0924b1e223 100644
--- a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
+++ b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
@@ -166,6 +166,10 @@ void tst_QNetworkCookieJar::setCookiesFromUrl_data()
// 2. anything .ck is an effective TLD ('*.ck'), but 'www.ck' is an exception
result.clear();
preset.clear();
+ cookie.setDomain(".ck");
+ QTest::newRow("effective-tld.ck-denied") << preset << cookie << "http://foo.ck" << result << false;
+ result.clear();
+ preset.clear();
cookie.setDomain(".foo.ck");
result += cookie;
QTest::newRow("effective-tld2-accepted2") << preset << cookie << "http://foo.ck" << result << true;
diff --git a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp
index fc5a7d1fab..849d8b0ed1 100644
--- a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp
+++ b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp
@@ -881,11 +881,6 @@ void tst_QTcpServer::serverAddress_data()
{
QTest::addColumn<QHostAddress>("listenAddress");
QTest::addColumn<QHostAddress>("serverAddress");
-#ifdef Q_OS_WIN
- if (QOperatingSystemVersion::current() < QOperatingSystemVersion::WindowsVista)
- QTest::newRow("Any") << QHostAddress(QHostAddress::Any) << QHostAddress(QHostAddress::AnyIPv4); //windows XP doesn't support dual stack sockets
- else
-#endif
if (QtNetworkSettings::hasIPv6())
QTest::newRow("Any") << QHostAddress(QHostAddress::Any) << QHostAddress(QHostAddress::Any);
else
diff --git a/tests/auto/other/lancelot/paintcommands.cpp b/tests/auto/other/lancelot/paintcommands.cpp
index 032580e0f6..fbf906b55d 100644
--- a/tests/auto/other/lancelot/paintcommands.cpp
+++ b/tests/auto/other/lancelot/paintcommands.cpp
@@ -1010,7 +1010,10 @@ void PaintCommands::command_drawPixmap(QRegularExpressionMatch re)
qPrintable(re.captured(1)), pm.width(), pm.height(), pm.depth(),
tx, ty, tw, th, sx, sy, sw, sh);
- m_painter->drawPixmap(QRectF(tx, ty, tw, th), pm, QRectF(sx, sy, sw, sh));
+ if (!re.capturedLength(4)) // at most two coordinates specified
+ m_painter->drawPixmap(QPointF(tx, ty), pm);
+ else
+ m_painter->drawPixmap(QRectF(tx, ty, tw, th), pm, QRectF(sx, sy, sw, sh));
}
/***************************************************************************************************/
@@ -1057,7 +1060,10 @@ void PaintCommands::command_drawImage(QRegularExpressionMatch re)
printf(" -(lance) drawImage('%s' dim=(%d, %d), (%f, %f, %f, %f), (%f, %f, %f, %f)\n",
qPrintable(re.captured(1)), im.width(), im.height(), tx, ty, tw, th, sx, sy, sw, sh);
- m_painter->drawImage(QRectF(tx, ty, tw, th), im, QRectF(sx, sy, sw, sh), Qt::OrderedDither | Qt::OrderedAlphaDither);
+ if (!re.capturedLength(4)) // at most two coordinates specified
+ m_painter->drawImage(QPointF(tx, ty), im);
+ else
+ m_painter->drawImage(QRectF(tx, ty, tw, th), im, QRectF(sx, sy, sw, sh));
}
/***************************************************************************************************/
diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp
index 1326b96177..331ae48135 100644
--- a/tests/auto/testlib/selftests/tst_selftests.cpp
+++ b/tests/auto/testlib/selftests/tst_selftests.cpp
@@ -685,9 +685,6 @@ static inline QByteArray msgProcessError(const QString &binary, const QStringLis
void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& loggers, QStringList const& arguments, bool crashes)
{
- if (EmulationDetector::isRunningArmOnX86() && (subdir == "crashes"))
- QSKIP("Skipping \"crashes\" due to QTBUG-71915");
-
#if defined(__GNUC__) && defined(__i386) && defined(Q_OS_LINUX)
if (arguments.contains("-callgrind")) {
QProcess checkProcess;
diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
index 0b08586f7d..5d380c899b 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -56,9 +56,16 @@
#include <QLineEdit>
#include <QGraphicsLinearLayout>
#include <QTransform>
+#include <QSharedPointer>
#include <float.h>
#include <QStyleHints>
+using AbstractGraphicsShapeItemPtr = QSharedPointer<QAbstractGraphicsShapeItem>;
+using GraphicsItems = QVector<QGraphicsItem *>;
+using GraphicsItemsList = QList<QGraphicsItem *>;
+
+Q_DECLARE_METATYPE(AbstractGraphicsShapeItemPtr)
+Q_DECLARE_METATYPE(QGraphicsItem::GraphicsItemFlags)
Q_DECLARE_METATYPE(QPainterPath)
Q_DECLARE_METATYPE(QSizeF)
Q_DECLARE_METATYPE(QTransform)
@@ -88,17 +95,17 @@ static void sendMousePress(QGraphicsScene *scene, const QPointF &point, Qt::Mous
event.setScenePos(point);
event.setButton(button);
event.setButtons(button);
- QApplication::sendEvent(scene, &event);
+ QCoreApplication::sendEvent(scene, &event);
}
static void sendMouseMove(QGraphicsScene *scene, const QPointF &point,
- Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons /* buttons */ = 0)
+ Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons /* buttons */ = {})
{
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
event.setScenePos(point);
event.setButton(button);
event.setButtons(button);
- QApplication::sendEvent(scene, &event);
+ QCoreApplication::sendEvent(scene, &event);
}
static void sendMouseRelease(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton)
@@ -106,7 +113,7 @@ static void sendMouseRelease(QGraphicsScene *scene, const QPointF &point, Qt::Mo
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease);
event.setScenePos(point);
event.setButton(button);
- QApplication::sendEvent(scene, &event);
+ QCoreApplication::sendEvent(scene, &event);
}
static void sendMouseClick(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton)
@@ -118,13 +125,13 @@ static void sendMouseClick(QGraphicsScene *scene, const QPointF &point, Qt::Mous
static void sendKeyPress(QGraphicsScene *scene, Qt::Key key)
{
QKeyEvent keyEvent(QEvent::KeyPress, key, Qt::NoModifier);
- QApplication::sendEvent(scene, &keyEvent);
+ QCoreApplication::sendEvent(scene, &keyEvent);
}
static void sendKeyRelease(QGraphicsScene *scene, Qt::Key key)
{
QKeyEvent keyEvent(QEvent::KeyRelease, key, Qt::NoModifier);
- QApplication::sendEvent(scene, &keyEvent);
+ QCoreApplication::sendEvent(scene, &keyEvent);
}
static void sendKeyClick(QGraphicsScene *scene, Qt::Key key)
@@ -138,13 +145,13 @@ class EventSpy : public QGraphicsWidget
Q_OBJECT
public:
EventSpy(QObject *watched, QEvent::Type type)
- : _count(0), spied(type)
+ : spied(type)
{
watched->installEventFilter(this);
}
EventSpy(QGraphicsScene *scene, QGraphicsItem *watched, QEvent::Type type)
- : _count(0), spied(type)
+ : spied(type)
{
scene->addItem(this);
watched->installSceneEventFilter(this);
@@ -153,7 +160,7 @@ public:
int count() const { return _count; }
protected:
- bool eventFilter(QObject *watched, QEvent *event)
+ bool eventFilter(QObject *watched, QEvent *event) override
{
Q_UNUSED(watched);
if (event->type() == spied)
@@ -161,7 +168,7 @@ protected:
return false;
}
- bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
+ bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
{
Q_UNUSED(watched);
if (event->type() == spied)
@@ -169,8 +176,8 @@ protected:
return false;
}
- int _count;
- QEvent::Type spied;
+ int _count = 0;
+ const QEvent::Type spied;
};
class EventSpy2 : public QGraphicsWidget
@@ -191,14 +198,14 @@ public:
QMap<QEvent::Type, int> counts;
protected:
- bool eventFilter(QObject *watched, QEvent *event)
+ bool eventFilter(QObject *watched, QEvent *event) override
{
Q_UNUSED(watched);
++counts[event->type()];
return false;
}
- bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
+ bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
{
Q_UNUSED(watched);
++counts[event->type()];
@@ -209,8 +216,7 @@ protected:
class EventTester : public QGraphicsItem
{
public:
- EventTester(QGraphicsItem *parent = 0) : QGraphicsItem(parent), repaints(0)
- { br = QRectF(-10, -10, 20, 20); }
+ using QGraphicsItem::QGraphicsItem;
void setGeometry(const QRectF &rect)
{
@@ -219,10 +225,10 @@ public:
update();
}
- QRectF boundingRect() const
+ QRectF boundingRect() const override
{ return br; }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *o, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *o, QWidget *) override
{
hints = painter->renderHints();
painter->setBrush(brush);
@@ -231,7 +237,7 @@ public:
++repaints;
}
- bool sceneEvent(QEvent *event)
+ bool sceneEvent(QEvent *event) override
{
events << event->type();
return QGraphicsItem::sceneEvent(event);
@@ -240,32 +246,39 @@ public:
void reset()
{
events.clear();
- hints = QPainter::RenderHints(0);
+ hints = QPainter::RenderHints{};
repaints = 0;
lastExposedRect = QRectF();
}
- QList<QEvent::Type> events;
+ QVector<QEvent::Type> events;
QPainter::RenderHints hints;
- int repaints;
- QRectF br;
+ int repaints = 0;
+ QRectF br = QRectF(-10, -10, 20, 20);
QRectF lastExposedRect;
QBrush brush;
};
class MyGraphicsView : public QGraphicsView
{
+ Q_OBJECT
public:
- int repaints;
QRegion paintedRegion;
- MyGraphicsView(QGraphicsScene *scene, QWidget *parent=0) : QGraphicsView(scene,parent), repaints(0) {}
- void paintEvent(QPaintEvent *e)
+ int repaints = 0;
+
+ using QGraphicsView::QGraphicsView;
+
+ void paintEvent(QPaintEvent *e) override
{
paintedRegion += e->region();
++repaints;
QGraphicsView::paintEvent(e);
}
- void reset() { repaints = 0; paintedRegion = QRegion(); }
+ void reset()
+ {
+ repaints = 0;
+ paintedRegion = QRegion();
+ }
};
class tst_QGraphicsItem : public QObject
@@ -276,6 +289,7 @@ public:
static void initMain();
private slots:
+ void cleanup();
void construction();
void constructionWithParent();
void destruction();
@@ -473,7 +487,7 @@ private slots:
void QTBUG_21618_untransformable_sceneTransform();
private:
- QList<QGraphicsItem *> paintedItems;
+ GraphicsItems paintedItems;
QTouchDevice *m_touchDevice = nullptr;
};
@@ -485,69 +499,76 @@ void tst_QGraphicsItem::initMain()
#endif
}
+void tst_QGraphicsItem::cleanup()
+{
+ QVERIFY(QApplication::topLevelWidgets().isEmpty());
+}
+
+template <class I>
+static inline I *createBlackShapeItem()
+{
+ auto result = new I;
+ result->setPen(QPen(Qt::black, 0));
+ return result;
+}
+
void tst_QGraphicsItem::construction()
{
for (int i = 0; i < 7; ++i) {
QGraphicsItem *item = nullptr;
switch (i) {
case 0:
- item = new QGraphicsEllipseItem;
- ((QGraphicsEllipseItem *)item)->setPen(QPen(Qt::black, 0));
- QCOMPARE(int(item->type()), int(QGraphicsEllipseItem::Type));
- QCOMPARE(qgraphicsitem_cast<QGraphicsEllipseItem *>(item), (QGraphicsEllipseItem *)item);
+ item = createBlackShapeItem<QGraphicsEllipseItem>();
+ QCOMPARE(item->type(), int(QGraphicsEllipseItem::Type));
+ QCOMPARE(qgraphicsitem_cast<QGraphicsEllipseItem *>(item), item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr);
QCOMPARE(item->flags(), 0);
break;
case 1:
- item = new QGraphicsLineItem;
- ((QGraphicsLineItem *)item)->setPen(QPen(Qt::black, 0));
+ item = createBlackShapeItem<QGraphicsLineItem>();
QCOMPARE(int(item->type()), int(QGraphicsLineItem::Type));
- QCOMPARE(qgraphicsitem_cast<QGraphicsLineItem *>(item), (QGraphicsLineItem *)item);
+ QCOMPARE(qgraphicsitem_cast<QGraphicsLineItem *>(item), item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr);
QCOMPARE(item->flags(), 0);
break;
case 2:
- item = new QGraphicsPathItem;
- ((QGraphicsPathItem *)item)->setPen(QPen(Qt::black, 0));
+ item = createBlackShapeItem<QGraphicsPathItem>();
QCOMPARE(int(item->type()), int(QGraphicsPathItem::Type));
- QCOMPARE(qgraphicsitem_cast<QGraphicsPathItem *>(item), (QGraphicsPathItem *)item);
+ QCOMPARE(qgraphicsitem_cast<QGraphicsPathItem *>(item), item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr);
QCOMPARE(item->flags(), 0);
break;
case 3:
item = new QGraphicsPixmapItem;
QCOMPARE(int(item->type()), int(QGraphicsPixmapItem::Type));
- QCOMPARE(qgraphicsitem_cast<QGraphicsPixmapItem *>(item), (QGraphicsPixmapItem *)item);
+ QCOMPARE(qgraphicsitem_cast<QGraphicsPixmapItem *>(item), item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr);
QCOMPARE(item->flags(), 0);
break;
case 4:
- item = new QGraphicsPolygonItem;
- ((QGraphicsPolygonItem *)item)->setPen(QPen(Qt::black, 0));
+ item = createBlackShapeItem<QGraphicsPolygonItem>();
QCOMPARE(int(item->type()), int(QGraphicsPolygonItem::Type));
- QCOMPARE(qgraphicsitem_cast<QGraphicsPolygonItem *>(item), (QGraphicsPolygonItem *)item);
+ QCOMPARE(qgraphicsitem_cast<QGraphicsPolygonItem *>(item), item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr);
QCOMPARE(item->flags(), 0);
break;
case 5:
- item = new QGraphicsRectItem;
- ((QGraphicsRectItem *)item)->setPen(QPen(Qt::black, 0));
+ item = createBlackShapeItem<QGraphicsRectItem>();
QCOMPARE(int(item->type()), int(QGraphicsRectItem::Type));
- QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)item);
+ QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), item);
QCOMPARE(qgraphicsitem_cast<QGraphicsLineItem *>(item), nullptr);
QCOMPARE(item->flags(), 0);
break;
case 6:
item = new QGraphicsTextItem;
QCOMPARE(int(item->type()), int(QGraphicsTextItem::Type));
- QCOMPARE(qgraphicsitem_cast<QGraphicsTextItem *>(item), (QGraphicsTextItem *)item);
+ QCOMPARE(qgraphicsitem_cast<QGraphicsTextItem *>(item), item);
QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr);
// This is the only item that uses an extended style option.
QCOMPARE(item->flags(), QGraphicsItem::GraphicsItemFlags(QGraphicsItem::ItemUsesExtendedStyleOption));
break;
default:
qFatal("You broke the logic, please fix!");
- break;
}
QCOMPARE(item->scene(), nullptr);
@@ -569,10 +590,10 @@ void tst_QGraphicsItem::construction()
QCOMPARE(item->sceneBoundingRect(), QRectF());
QCOMPARE(item->shape(), QPainterPath());
QVERIFY(!item->contains(QPointF(0, 0)));
- QVERIFY(!item->collidesWithItem(0));
+ QVERIFY(!item->collidesWithItem(nullptr));
QVERIFY(item->collidesWithItem(item));
QVERIFY(!item->collidesWithPath(QPainterPath()));
- QVERIFY(!item->isAncestorOf(0));
+ QVERIFY(!item->isAncestorOf(nullptr));
QVERIFY(!item->isAncestorOf(item));
QCOMPARE(item->data(0), QVariant());
delete item;
@@ -582,17 +603,18 @@ void tst_QGraphicsItem::construction()
class BoundingRectItem : public QGraphicsRectItem
{
public:
- BoundingRectItem(QGraphicsItem *parent = 0)
+ BoundingRectItem(QGraphicsItem *parent = nullptr)
: QGraphicsRectItem(0, 0, parent ? 200 : 100, parent ? 200 : 100,
parent)
{
setPen(QPen(Qt::black, 0));
}
- QRectF boundingRect() const
+ QRectF boundingRect() const override
{
QRectF tmp = QGraphicsRectItem::boundingRect();
- foreach (QGraphicsItem *child, childItems())
+ const auto children = childItems();
+ for (QGraphicsItem *child : children)
tmp |= child->boundingRect(); // <- might be pure virtual
return tmp;
}
@@ -608,11 +630,11 @@ void tst_QGraphicsItem::constructionWithParent()
scene.addItem(item0);
scene.addItem(item1);
QGraphicsItem *item2 = new BoundingRectItem(item1);
- QCOMPARE(item1->childItems(), QList<QGraphicsItem *>() << item2);
+ QCOMPARE(item1->childItems(), GraphicsItemsList{item2});
QCOMPARE(item1->boundingRect(), QRectF(0, 0, 200, 200));
item2->setParentItem(item0);
- QCOMPARE(item0->childItems(), QList<QGraphicsItem *>() << item2);
+ QCOMPARE(item0->childItems(), GraphicsItemsList{item2});
QCOMPARE(item0->boundingRect(), QRectF(0, 0, 200, 200));
}
@@ -760,7 +782,7 @@ void tst_QGraphicsItem::destruction()
QGraphicsScene scene;
QGraphicsItem *root = new QGraphicsRectItem;
QGraphicsItem *parent = root;
- QGraphicsItem *middleItem = 0;
+ QGraphicsItem *middleItem = nullptr;
for (int i = 0; i < 99; ++i) {
Item *child = new Item;
child->setParentItem(parent);
@@ -801,7 +823,7 @@ void tst_QGraphicsItem::deleteChildItem()
QGraphicsItem *child3 = new QGraphicsRectItem(rect);
Q_UNUSED(child3);
delete child1;
- child2->setParentItem(0);
+ child2->setParentItem(nullptr);
delete child2;
}
@@ -812,11 +834,11 @@ void tst_QGraphicsItem::scene()
QGraphicsScene scene;
scene.addItem(item);
- QCOMPARE(item->scene(), (QGraphicsScene *)&scene);
+ QCOMPARE(item->scene(), &scene);
QGraphicsScene scene2;
scene2.addItem(item);
- QCOMPARE(item->scene(), (QGraphicsScene *)&scene2);
+ QCOMPARE(item->scene(), &scene2);
scene2.removeItem(item);
QCOMPARE(item->scene(), nullptr);
@@ -830,10 +852,10 @@ void tst_QGraphicsItem::parentItem()
QCOMPARE(item.parentItem(), nullptr);
QGraphicsRectItem *item2 = new QGraphicsRectItem(QRectF(), &item);
- QCOMPARE(item2->parentItem(), (QGraphicsItem *)&item);
+ QCOMPARE(item2->parentItem(), &item);
item2->setParentItem(&item);
- QCOMPARE(item2->parentItem(), (QGraphicsItem *)&item);
- item2->setParentItem(0);
+ QCOMPARE(item2->parentItem(), &item);
+ item2->setParentItem(nullptr);
QCOMPARE(item2->parentItem(), nullptr);
delete item2;
@@ -853,7 +875,7 @@ void tst_QGraphicsItem::setParentItem()
QCOMPARE(child->scene(), &scene);
// This just makes it a toplevel
- child->setParentItem(0);
+ child->setParentItem(nullptr);
QCOMPARE(child->scene(), &scene);
// Add the child back to the parent, then remove the parent from the scene
@@ -869,7 +891,7 @@ void tst_QGraphicsItem::children()
QGraphicsRectItem *item2 = new QGraphicsRectItem(QRectF(), &item);
QCOMPARE(item.childItems().size(), 1);
- QCOMPARE(item.childItems().first(), (QGraphicsItem *)item2);
+ QCOMPARE(item.childItems().constFirst(), item2);
QVERIFY(item2->childItems().isEmpty());
delete item2;
@@ -883,7 +905,7 @@ void tst_QGraphicsItem::flags()
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
scene.addItem(item);
@@ -925,20 +947,20 @@ void tst_QGraphicsItem::flags()
event.setScenePos(QPointF(0, 0));
event.setButton(Qt::LeftButton);
event.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(scene.mouseGrabberItem(), nullptr); // mouse grabber is reset
QGraphicsSceneMouseEvent event2(QEvent::GraphicsSceneMouseMove);
event2.setScenePos(QPointF(10, 10));
event2.setButton(Qt::LeftButton);
event2.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event2);
+ QCoreApplication::sendEvent(&scene, &event2);
QCOMPARE(item->pos(), QPointF());
QGraphicsSceneMouseEvent event3(QEvent::GraphicsSceneMouseRelease);
event3.setScenePos(QPointF(10, 10));
- event3.setButtons(0);
- QApplication::sendEvent(&scene, &event3);
+ event3.setButtons({});
+ QCoreApplication::sendEvent(&scene, &event3);
QCOMPARE(scene.mouseGrabberItem(), nullptr);
item->setFlag(QGraphicsItem::ItemIsMovable, true);
@@ -946,13 +968,13 @@ void tst_QGraphicsItem::flags()
event4.setScenePos(QPointF(0, 0));
event4.setButton(Qt::LeftButton);
event4.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event4);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item);
+ QCoreApplication::sendEvent(&scene, &event4);
+ QCOMPARE(scene.mouseGrabberItem(), item);
QGraphicsSceneMouseEvent event5(QEvent::GraphicsSceneMouseMove);
event5.setScenePos(QPointF(10, 10));
event5.setButton(Qt::LeftButton);
event5.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event5);
+ QCoreApplication::sendEvent(&scene, &event5);
QCOMPARE(item->pos(), QPointF(10, 10));
}
{
@@ -975,8 +997,8 @@ void tst_QGraphicsItem::flags()
class ImhTester : public QGraphicsItem
{
- QRectF boundingRect() const { return QRectF(); }
- void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {}
+ QRectF boundingRect() const override { return QRectF(); }
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override {}
};
void tst_QGraphicsItem::inputMethodHints()
@@ -996,6 +1018,7 @@ void tst_QGraphicsItem::inputMethodHints()
scene.addItem(item2);
QGraphicsView view(&scene);
QApplication::setActiveWindow(&view);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -1045,6 +1068,7 @@ void tst_QGraphicsItem::toolTip()
scene.addItem(item);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.setFixedSize(200, 200);
view.show();
QApplication::setActiveWindow(&view);
@@ -1053,12 +1077,13 @@ void tst_QGraphicsItem::toolTip()
{
QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().topLeft(),
view.viewport()->mapToGlobal(view.viewport()->rect().topLeft()));
- QApplication::sendEvent(view.viewport(), &helpEvent);
+ QCoreApplication::sendEvent(view.viewport(), &helpEvent);
QTest::qWait(250);
bool foundView = false;
bool foundTipLabel = false;
- foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ const auto topLevels = QApplication::topLevelWidgets();
+ for (auto widget : topLevels) {
if (widget == &view)
foundView = true;
if (widget->inherits("QTipLabel"))
@@ -1071,12 +1096,13 @@ void tst_QGraphicsItem::toolTip()
{
QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().center(),
view.viewport()->mapToGlobal(view.viewport()->rect().center()));
- QApplication::sendEvent(view.viewport(), &helpEvent);
+ QCoreApplication::sendEvent(view.viewport(), &helpEvent);
QTest::qWait(250);
bool foundView = false;
bool foundTipLabel = false;
- foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ const auto topLevels = QApplication::topLevelWidgets();
+ for (auto widget : topLevels) {
if (widget == &view)
foundView = true;
if (widget->inherits("QTipLabel"))
@@ -1089,12 +1115,13 @@ void tst_QGraphicsItem::toolTip()
{
QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().topLeft(),
view.viewport()->mapToGlobal(view.viewport()->rect().topLeft()));
- QApplication::sendEvent(view.viewport(), &helpEvent);
+ QCoreApplication::sendEvent(view.viewport(), &helpEvent);
QTest::qWait(1000);
bool foundView = false;
bool foundTipLabel = false;
- foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+ const auto topLevels = QApplication::topLevelWidgets();
+ for (auto widget : topLevels) {
if (widget == &view)
foundView = true;
if (widget->inherits("QTipLabel") && widget->isVisible())
@@ -1117,7 +1144,7 @@ void tst_QGraphicsItem::visible()
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
scene.addItem(item);
QVERIFY(item->isVisible());
@@ -1130,7 +1157,7 @@ void tst_QGraphicsItem::visible()
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress);
event.setButton(Qt::LeftButton);
event.setScenePos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(scene.mouseGrabberItem(), item);
item->setVisible(false);
QCOMPARE(scene.mouseGrabberItem(), nullptr);
@@ -1161,14 +1188,14 @@ void tst_QGraphicsItem::isVisibleTo()
QVERIFY(grandChild->isVisibleTo(grandChild));
QVERIFY(grandChild->isVisibleTo(child));
QVERIFY(grandChild->isVisibleTo(parent));
- QVERIFY(grandChild->isVisibleTo(0));
+ QVERIFY(grandChild->isVisibleTo(nullptr));
QVERIFY(child->isVisible());
QVERIFY(child->isVisibleTo(child));
QVERIFY(child->isVisibleTo(parent));
- QVERIFY(child->isVisibleTo(0));
+ QVERIFY(child->isVisibleTo(nullptr));
QVERIFY(parent->isVisible());
QVERIFY(parent->isVisibleTo(parent));
- QVERIFY(parent->isVisibleTo(0));
+ QVERIFY(parent->isVisibleTo(nullptr));
QVERIFY(!parent->isVisibleTo(child));
QVERIFY(!child->isVisibleTo(grandChild));
QVERIFY(!grandChild->isVisibleTo(stranger));
@@ -1185,14 +1212,14 @@ void tst_QGraphicsItem::isVisibleTo()
QVERIFY(grandChild->isVisibleTo(grandChild));
QVERIFY(grandChild->isVisibleTo(child));
QVERIFY(grandChild->isVisibleTo(parent));
- QVERIFY(!grandChild->isVisibleTo(0));
+ QVERIFY(!grandChild->isVisibleTo(nullptr));
QVERIFY(!child->isVisible());
QVERIFY(child->isVisibleTo(child));
QVERIFY(child->isVisibleTo(parent));
- QVERIFY(!child->isVisibleTo(0));
+ QVERIFY(!child->isVisibleTo(nullptr));
QVERIFY(!parent->isVisible());
QVERIFY(!parent->isVisibleTo(parent));
- QVERIFY(!parent->isVisibleTo(0));
+ QVERIFY(!parent->isVisibleTo(nullptr));
QVERIFY(!parent->isVisibleTo(child));
QVERIFY(!child->isVisibleTo(grandChild));
QVERIFY(!grandChild->isVisibleTo(stranger));
@@ -1210,14 +1237,14 @@ void tst_QGraphicsItem::isVisibleTo()
QVERIFY(grandChild->isVisibleTo(grandChild));
QVERIFY(grandChild->isVisibleTo(child));
QVERIFY(!grandChild->isVisibleTo(parent));
- QVERIFY(!grandChild->isVisibleTo(0));
+ QVERIFY(!grandChild->isVisibleTo(nullptr));
QVERIFY(!child->isVisible());
QVERIFY(!child->isVisibleTo(child));
QVERIFY(!child->isVisibleTo(parent));
- QVERIFY(!child->isVisibleTo(0));
+ QVERIFY(!child->isVisibleTo(nullptr));
QVERIFY(parent->isVisible());
QVERIFY(parent->isVisibleTo(parent));
- QVERIFY(parent->isVisibleTo(0));
+ QVERIFY(parent->isVisibleTo(nullptr));
QVERIFY(!parent->isVisibleTo(child));
QVERIFY(!child->isVisibleTo(grandChild));
QVERIFY(!grandChild->isVisibleTo(stranger));
@@ -1235,14 +1262,14 @@ void tst_QGraphicsItem::isVisibleTo()
QVERIFY(!grandChild->isVisibleTo(grandChild));
QVERIFY(!grandChild->isVisibleTo(child));
QVERIFY(!grandChild->isVisibleTo(parent));
- QVERIFY(!grandChild->isVisibleTo(0));
+ QVERIFY(!grandChild->isVisibleTo(nullptr));
QVERIFY(child->isVisible());
QVERIFY(child->isVisibleTo(child));
QVERIFY(child->isVisibleTo(parent));
- QVERIFY(child->isVisibleTo(0));
+ QVERIFY(child->isVisibleTo(nullptr));
QVERIFY(parent->isVisible());
QVERIFY(parent->isVisibleTo(parent));
- QVERIFY(parent->isVisibleTo(0));
+ QVERIFY(parent->isVisibleTo(nullptr));
QVERIFY(!parent->isVisibleTo(child));
QVERIFY(!child->isVisibleTo(grandChild));
QVERIFY(!grandChild->isVisibleTo(stranger));
@@ -1349,7 +1376,7 @@ void tst_QGraphicsItem::explicitlyVisible()
// Reparent implicitly hidden child to root.
parent2->hide();
QVERIFY(!child->isVisible());
- child->setParentItem(0);
+ child->setParentItem(nullptr);
QVERIFY(child->isVisible());
// Reparent an explicitly hidden child to root.
@@ -1357,7 +1384,7 @@ void tst_QGraphicsItem::explicitlyVisible()
child->setParentItem(parent2);
parent2->show();
QVERIFY(!child->isVisible());
- child->setParentItem(0);
+ child->setParentItem(nullptr);
QVERIFY(!child->isVisible());
}
@@ -1374,7 +1401,7 @@ void tst_QGraphicsItem::enabled()
item->setFlag(QGraphicsItem::ItemIsFocusable);
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
scene.addItem(item);
item->setFocus();
@@ -1388,11 +1415,11 @@ void tst_QGraphicsItem::enabled()
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress);
event.setButton(Qt::LeftButton);
event.setScenePos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(scene.mouseGrabberItem(), nullptr);
item->setEnabled(true);
- QApplication::sendEvent(&scene, &event);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item);
+ QCoreApplication::sendEvent(&scene, &event);
+ QCOMPARE(scene.mouseGrabberItem(), item);
item->setEnabled(false);
QCOMPARE(scene.mouseGrabberItem(), nullptr);
}
@@ -1493,7 +1520,7 @@ void tst_QGraphicsItem::explicitlyEnabled()
// Reparent implicitly hidden child to root.
parent2->setEnabled(false);
QVERIFY(!child->isEnabled());
- child->setParentItem(0);
+ child->setParentItem(nullptr);
QVERIFY(child->isEnabled());
// Reparent an explicitly hidden child to root.
@@ -1501,7 +1528,7 @@ void tst_QGraphicsItem::explicitlyEnabled()
child->setParentItem(parent2);
parent2->setEnabled(true);
QVERIFY(!child->isEnabled());
- child->setParentItem(0);
+ child->setParentItem(nullptr);
QVERIFY(!child->isEnabled());
}
@@ -1509,10 +1536,10 @@ class SelectChangeItem : public QGraphicsRectItem
{
public:
SelectChangeItem() : QGraphicsRectItem(-50, -50, 100, 100) { setBrush(Qt::blue); }
- QList<bool> values;
+ QVector<bool> values;
protected:
- QVariant itemChange(GraphicsItemChange change, const QVariant &value)
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
{
if (change == ItemSelectedChange)
values << value.toBool();
@@ -1528,70 +1555,71 @@ void tst_QGraphicsItem::selected()
QVERIFY(item->values.isEmpty());
item->setSelected(true);
QCOMPARE(item->values.size(), 1);
- QCOMPARE(item->values.last(), true);
+ QCOMPARE(item->values.constLast(), true);
QVERIFY(item->isSelected());
item->setSelected(false);
QCOMPARE(item->values.size(), 2);
- QCOMPARE(item->values.last(), false);
+ QCOMPARE(item->values.constLast(), false);
QVERIFY(!item->isSelected());
item->setSelected(true);
QCOMPARE(item->values.size(), 3);
item->setEnabled(false);
QCOMPARE(item->values.size(), 4);
- QCOMPARE(item->values.last(), false);
+ QCOMPARE(item->values.constLast(), false);
QVERIFY(!item->isSelected());
item->setEnabled(true);
QCOMPARE(item->values.size(), 4);
item->setSelected(true);
QCOMPARE(item->values.size(), 5);
- QCOMPARE(item->values.last(), true);
+ QCOMPARE(item->values.constLast(), true);
QVERIFY(item->isSelected());
item->setVisible(false);
QCOMPARE(item->values.size(), 6);
- QCOMPARE(item->values.last(), false);
+ QCOMPARE(item->values.constLast(), false);
QVERIFY(!item->isSelected());
item->setVisible(true);
QCOMPARE(item->values.size(), 6);
item->setSelected(true);
QCOMPARE(item->values.size(), 7);
- QCOMPARE(item->values.last(), true);
+ QCOMPARE(item->values.constLast(), true);
QVERIFY(item->isSelected());
QGraphicsScene scene(-100, -100, 200, 200);
scene.addItem(item);
- QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>() << item);
+ QCOMPARE(scene.selectedItems(), GraphicsItemsList{item});
item->setSelected(false);
QVERIFY(scene.selectedItems().isEmpty());
item->setSelected(true);
- QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>() << item);
+ QCOMPARE(scene.selectedItems(), GraphicsItemsList{item});
item->setSelected(false);
QVERIFY(scene.selectedItems().isEmpty());
// Interactive selection
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.setFixedSize(250, 250);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
- qApp->processEvents();
- qApp->processEvents();
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents();
scene.clearSelection();
QCOMPARE(item->values.size(), 10);
- QCOMPARE(item->values.last(), false);
+ QCOMPARE(item->values.constLast(), false);
QVERIFY(!item->isSelected());
// Click inside and check that it's selected
QTest::mouseMove(view.viewport());
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos()));
QCOMPARE(item->values.size(), 11);
- QCOMPARE(item->values.last(), true);
+ QCOMPARE(item->values.constLast(), true);
QVERIFY(item->isSelected());
// Click outside and check that it's not selected
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos() + QPointF(item->boundingRect().width(), item->boundingRect().height())));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos() + QPointF(item->boundingRect().width(), item->boundingRect().height())));
QCOMPARE(item->values.size(), 12);
- QCOMPARE(item->values.last(), false);
+ QCOMPARE(item->values.constLast(), false);
QVERIFY(!item->isSelected());
SelectChangeItem *item2 = new SelectChangeItem;
@@ -1600,18 +1628,18 @@ void tst_QGraphicsItem::selected()
scene.addItem(item2);
// Click inside and check that it's selected
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos()));
QCOMPARE(item->values.size(), 13);
- QCOMPARE(item->values.last(), true);
+ QCOMPARE(item->values.constLast(), true);
QVERIFY(item->isSelected());
// Click inside item2 and check that it's selected, and item is not
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item2->scenePos()));
QCOMPARE(item->values.size(), 14);
- QCOMPARE(item->values.last(), false);
+ QCOMPARE(item->values.constLast(), false);
QVERIFY(!item->isSelected());
QCOMPARE(item2->values.size(), 1);
- QCOMPARE(item2->values.last(), true);
+ QCOMPARE(item2->values.constLast(), true);
QVERIFY(item2->isSelected());
}
@@ -1632,7 +1660,7 @@ void tst_QGraphicsItem::selected2()
QGraphicsSceneMouseEvent mousePress(QEvent::GraphicsSceneMousePress);
mousePress.setScenePos(QPointF(50, 50));
mousePress.setButton(Qt::LeftButton);
- QApplication::sendEvent(&scene, &mousePress);
+ QCoreApplication::sendEvent(&scene, &mousePress);
QVERIFY(mousePress.isAccepted());
}
{
@@ -1640,7 +1668,7 @@ void tst_QGraphicsItem::selected2()
mouseMove.setScenePos(QPointF(60, 60));
mouseMove.setButton(Qt::LeftButton);
mouseMove.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &mouseMove);
+ QCoreApplication::sendEvent(&scene, &mouseMove);
QVERIFY(mouseMove.isAccepted());
}
}
@@ -1657,10 +1685,11 @@ void tst_QGraphicsItem::selected_group()
leaf->setFlag(QGraphicsItem::ItemIsSelectable);
leaf->setParentItem(item2);
- QGraphicsItemGroup *group = scene.createItemGroup(QList<QGraphicsItem *>() << item1 << item2);
+ QGraphicsItemGroup *group = scene.createItemGroup(GraphicsItemsList{item1, item2});
QCOMPARE(group->scene(), &scene);
group->setFlag(QGraphicsItem::ItemIsSelectable);
- foreach (QGraphicsItem *item, scene.items()) {
+ const auto items = scene.items();
+ for (QGraphicsItem *item : items) {
if (item == group)
QVERIFY(!item->group());
else
@@ -1673,18 +1702,16 @@ void tst_QGraphicsItem::selected_group()
QVERIFY(!group->isSelected());
group->setSelected(true);
QVERIFY(group->isSelected());
- foreach (QGraphicsItem *item, scene.items())
- QVERIFY(item->isSelected());
+
+ const auto itemIsSelected = [](const QGraphicsItem *item) { return item->isSelected(); };
+ QVERIFY(std::all_of(items.cbegin(), items.cend(), itemIsSelected));
group->setSelected(false);
QVERIFY(!group->isSelected());
- foreach (QGraphicsItem *item, scene.items())
- QVERIFY(!item->isSelected());
+ QVERIFY(std::none_of(items.cbegin(), items.cend(), itemIsSelected));
leaf->setSelected(true);
- foreach (QGraphicsItem *item, scene.items())
- QVERIFY(item->isSelected());
+ QVERIFY(std::all_of(items.cbegin(), items.cend(), itemIsSelected));
leaf->setSelected(false);
- foreach (QGraphicsItem *item, scene.items())
- QVERIFY(!item->isSelected());
+ QVERIFY(std::none_of(items.cbegin(), items.cend(), itemIsSelected));
leaf->setSelected(true);
QGraphicsScene scene2;
@@ -1700,18 +1727,19 @@ void tst_QGraphicsItem::selected_textItem()
text->setFlag(QGraphicsItem::ItemIsSelectable);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QTRY_VERIFY(!text->isSelected());
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0,
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {},
view.mapFromScene(text->mapToScene(0, 0)));
QTRY_VERIFY(text->isSelected());
text->setSelected(false);
text->setTextInteractionFlags(Qt::TextEditorInteraction);
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0,
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {},
view.mapFromScene(text->mapToScene(0, 0)));
QTRY_VERIFY(text->isSelected());
}
@@ -1733,6 +1761,7 @@ void tst_QGraphicsItem::selected_multi()
// Create and show a view
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
view.fitInView(scene.sceneRect());
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -1741,12 +1770,12 @@ void tst_QGraphicsItem::selected_multi()
QVERIFY(!item2->isSelected());
// Click on item1
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos()));
QVERIFY(item1->isSelected());
QVERIFY(!item2->isSelected());
// Click on item2
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item2->scenePos()));
QVERIFY(item2->isSelected());
QVERIFY(!item1->isSelected());
@@ -1766,17 +1795,17 @@ void tst_QGraphicsItem::selected_multi()
QVERIFY(!item1->isSelected());
// Click on item1
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos()));
QVERIFY(item1->isSelected());
QVERIFY(!item2->isSelected());
// Click on scene
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(0, 0));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(0, 0));
QVERIFY(!item1->isSelected());
QVERIFY(!item2->isSelected());
// Click on item1
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos()));
QVERIFY(item1->isSelected());
QVERIFY(!item2->isSelected());
@@ -1786,27 +1815,27 @@ void tst_QGraphicsItem::selected_multi()
QVERIFY(!item2->isSelected());
// Click on scene
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(0, 0));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(0, 0));
QVERIFY(!item1->isSelected());
QVERIFY(!item2->isSelected());
// Click on item1
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos()));
QVERIFY(item1->isSelected());
QVERIFY(!item2->isSelected());
// Press on item2
- QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos()));
+ QTest::mousePress(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item2->scenePos()));
QVERIFY(!item1->isSelected());
QVERIFY(item2->isSelected());
// Release on item2
- QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos()));
+ QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item2->scenePos()));
QVERIFY(!item1->isSelected());
QVERIFY(item2->isSelected());
// Click on item1
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos()));
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos()));
QVERIFY(item1->isSelected());
QVERIFY(!item2->isSelected());
@@ -1824,7 +1853,7 @@ void tst_QGraphicsItem::selected_multi()
// Ctrl-move on item1
const QPoint item1Point = view.mapFromScene(item1->scenePos()) + QPoint(1, 0);
QMouseEvent event(QEvent::MouseMove, item1Point, view.viewport()->mapToGlobal(item1Point), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier);
- QApplication::sendEvent(view.viewport(), &event);
+ QCoreApplication::sendEvent(view.viewport(), &event);
QVERIFY(!item1->isSelected());
QVERIFY(!item2->isSelected());
}
@@ -1846,7 +1875,7 @@ void tst_QGraphicsItem::selected_multi()
// Ctrl-move on item1
const QPoint item1Point = view.mapFromScene(item1->scenePos()) + QPoint(1, 0);
QMouseEvent event(QEvent::MouseMove, item1Point, view.viewport()->mapToGlobal(item1Point), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier);
- QApplication::sendEvent(view.viewport(), &event);
+ QCoreApplication::sendEvent(view.viewport(), &event);
QVERIFY(item1->isSelected());
QVERIFY(!item2->isSelected());
}
@@ -1873,33 +1902,30 @@ void tst_QGraphicsItem::acceptedMouseButtons()
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress);
event.setButton(Qt::LeftButton);
event.setScenePos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &event);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item2);
- item2->setAcceptedMouseButtons(0);
+ QCoreApplication::sendEvent(&scene, &event);
+ QCOMPARE(scene.mouseGrabberItem(), item2);
+ item2->setAcceptedMouseButtons(nullptr);
QCOMPARE(scene.mouseGrabberItem(), nullptr);
- QApplication::sendEvent(&scene, &event);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item1);
+ QCoreApplication::sendEvent(&scene, &event);
+ QCOMPARE(scene.mouseGrabberItem(), item1);
}
class HoverItem : public QGraphicsRectItem
{
public:
- HoverItem(const QRectF &rect)
- : QGraphicsRectItem(rect), hoverInCount(0),
- hoverMoveCount(0), hoverOutCount(0)
- { }
+ HoverItem(const QRectF &rect) : QGraphicsRectItem(rect) { }
- int hoverInCount;
- int hoverMoveCount;
- int hoverOutCount;
+ int hoverInCount = 0;
+ int hoverMoveCount = 0;
+ int hoverOutCount = 0;
protected:
- void hoverEnterEvent(QGraphicsSceneHoverEvent *)
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
{ ++hoverInCount; }
- void hoverMoveEvent(QGraphicsSceneHoverEvent *)
+ void hoverMoveEvent(QGraphicsSceneHoverEvent *) override
{ ++hoverMoveCount; }
- void hoverLeaveEvent(QGraphicsSceneHoverEvent *)
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
{ ++hoverOutCount; }
};
@@ -1919,9 +1945,9 @@ void tst_QGraphicsItem::acceptHoverEvents()
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
event.setScenePos(QPointF(-100, -100));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
event.setScenePos(QPointF(-2.5, -2.5));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item1->hoverInCount, 0);
QCOMPARE(item2->hoverInCount, 1);
@@ -1930,9 +1956,9 @@ void tst_QGraphicsItem::acceptHoverEvents()
item2->setAcceptHoverEvents(false);
event.setScenePos(QPointF(-100, -100));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
event.setScenePos(QPointF(-2.5, -2.5));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item1->hoverInCount, 0);
QCOMPARE(item2->hoverInCount, 1);
@@ -1941,9 +1967,9 @@ void tst_QGraphicsItem::acceptHoverEvents()
item2->setAcceptHoverEvents(false);
event.setScenePos(QPointF(-100, -100));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
event.setScenePos(QPointF(-2.5, -2.5));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item1->hoverInCount, 1);
QCOMPARE(item2->hoverInCount, 1);
@@ -1962,7 +1988,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents()
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
event.setScenePos(QPointF(-100, -100));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item2->hoverInCount, 0);
QCOMPARE(item2->hoverMoveCount, 0);
QCOMPARE(item2->hoverOutCount, 0);
@@ -1971,7 +1997,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents()
QCOMPARE(item1->hoverOutCount, 0);
event.setScenePos(QPointF(-2.5, -2.5));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item2->hoverInCount, 1);
QCOMPARE(item2->hoverMoveCount, 1);
@@ -1981,7 +2007,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents()
QCOMPARE(item1->hoverOutCount, 0);
event.setScenePos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item2->hoverInCount, 1);
QCOMPARE(item2->hoverMoveCount, 2);
@@ -1991,7 +2017,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents()
QCOMPARE(item1->hoverOutCount, 0);
event.setScenePos(QPointF(-7, -7));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item2->hoverInCount, 1);
QCOMPARE(item2->hoverMoveCount, 2);
@@ -2001,7 +2027,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents()
QCOMPARE(item1->hoverOutCount, 0);
event.setScenePos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item2->hoverInCount, 2);
QCOMPARE(item2->hoverMoveCount, 3);
@@ -2016,10 +2042,10 @@ void tst_QGraphicsItem::childAcceptsHoverEvents()
item0->setAcceptHoverEvents(true);
event.setScenePos(QPointF(-100, -100));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
event.setScenePos(QPointF(-15, -15));
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(item2->hoverInCount, 2);
QCOMPARE(item2->hoverMoveCount, 3);
@@ -2041,7 +2067,7 @@ void tst_QGraphicsItem::hasFocus()
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
scene.addItem(line);
@@ -2052,7 +2078,7 @@ void tst_QGraphicsItem::hasFocus()
QVERIFY(line->hasFocus());
QGraphicsScene scene2;
- QApplication::sendEvent(&scene2, &activate);
+ QCoreApplication::sendEvent(&scene2, &activate);
scene2.addItem(line);
QVERIFY(!line->hasFocus());
@@ -2193,13 +2219,13 @@ void tst_QGraphicsItem::sceneTransform()
void tst_QGraphicsItem::setTransform()
{
QGraphicsScene scene;
- QSignalSpy spy(&scene, SIGNAL(changed(QList<QRectF>)));
+ QSignalSpy spy(&scene, &QGraphicsScene::changed);
QRectF unrotatedRect(-12, -34, 56, 78);
- QGraphicsRectItem item(unrotatedRect, 0);
+ QGraphicsRectItem item(unrotatedRect, nullptr);
item.setPen(QPen(Qt::black, 0));
scene.addItem(&item);
scene.update(scene.sceneRect());
- QApplication::instance()->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(spy.count(), 1);
@@ -2207,14 +2233,14 @@ void tst_QGraphicsItem::setTransform()
QRectF rotatedRect = scene.sceneRect();
QVERIFY(unrotatedRect != rotatedRect);
scene.update(scene.sceneRect());
- QApplication::instance()->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(spy.count(), 2);
item.setTransform(QTransform());
scene.update(scene.sceneRect());
- QApplication::instance()->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(spy.count(), 3);
QList<QRectF> rlist = qvariant_cast<QList<QRectF> >(spy.last().at(0));
@@ -2226,15 +2252,18 @@ void tst_QGraphicsItem::setTransform()
QCOMPARE(rlist.at(1), unrotatedRect); // From post-update (update current state)
}
-static QList<QGraphicsItem *> _paintedItems;
+static GraphicsItems _paintedItems;
class PainterItem : public QGraphicsItem
{
protected:
- QRectF boundingRect() const
+ QRectF boundingRect() const override
{ return QRectF(-10, -10, 20, 20); }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
- { _paintedItems << this; painter->fillRect(boundingRect(), Qt::red); }
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
+ {
+ _paintedItems << this;
+ painter->fillRect(boundingRect(), Qt::red);
+ }
};
void tst_QGraphicsItem::zValue()
@@ -2257,6 +2286,7 @@ void tst_QGraphicsItem::zValue()
item3->setZValue(0);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -2467,12 +2497,12 @@ void tst_QGraphicsItem::collidesWith_item()
{
QGraphicsScene scene;
- QGraphicsRectItem rect(20, 20, 100, 100, 0);
+ QGraphicsRectItem rect(20, 20, 100, 100, nullptr);
scene.addItem(&rect);
- QGraphicsRectItem rect2(40, 40, 50, 50, 0);
+ QGraphicsRectItem rect2(40, 40, 50, 50, nullptr);
scene.addItem(&rect2);
rect2.setZValue(1);
- QGraphicsLineItem line(0, 0, 200, 200, 0);
+ QGraphicsLineItem line(0, 0, 200, 200, nullptr);
scene.addItem(&line);
line.setZValue(2);
@@ -2480,18 +2510,18 @@ void tst_QGraphicsItem::collidesWith_item()
QList<QGraphicsItem *> col1 = rect.collidingItems();
QCOMPARE(col1.size(), 2);
- QCOMPARE(col1.first(), static_cast<QGraphicsItem *>(&line));
- QCOMPARE(col1.last(), static_cast<QGraphicsItem *>(&rect2));
+ QCOMPARE(col1.constFirst(), &line);
+ QCOMPARE(col1.constLast(), &rect2);
QList<QGraphicsItem *> col2 = rect2.collidingItems();
QCOMPARE(col2.size(), 2);
- QCOMPARE(col2.first(), static_cast<QGraphicsItem *>(&line));
- QCOMPARE(col2.last(), static_cast<QGraphicsItem *>(&rect));
+ QCOMPARE(col2.constFirst(), &line);
+ QCOMPARE(col2.constLast(), &rect);
QList<QGraphicsItem *> col3 = line.collidingItems();
QCOMPARE(col3.size(), 2);
- QCOMPARE(col3.first(), static_cast<QGraphicsItem *>(&rect2));
- QCOMPARE(col3.last(), static_cast<QGraphicsItem *>(&rect));
+ QCOMPARE(col3.constFirst(), &rect2);
+ QCOMPARE(col3.constLast(), &rect);
}
}
@@ -2574,42 +2604,35 @@ void tst_QGraphicsItem::collidesWithItemWithClip()
class MyItem : public QGraphicsEllipseItem
{
public:
- bool isObscuredBy(const QGraphicsItem *item) const
- {
- const MyItem *myItem = qgraphicsitem_cast<const MyItem *>(item);
- if (myItem) {
- if (item->zValue() > zValue()) {
- QRectF r = rect();
- QPointF topMid = (r.topRight()+r.topLeft())/2;
- QPointF botMid = (r.bottomRight()+r.bottomLeft())/2;
- QPointF leftMid = (r.topLeft()+r.bottomLeft())/2;
- QPointF rightMid = (r.topRight()+r.bottomRight())/2;
-
- QPainterPath mappedShape = item->mapToItem(this, item->opaqueArea());
-
- if (mappedShape.contains(topMid) &&
- mappedShape.contains(botMid) &&
- mappedShape.contains(leftMid) &&
- mappedShape.contains(rightMid))
- return true;
- else
- return false;
- }
- else return false;
- }
- else
- return QGraphicsItem::isObscuredBy(item);
+ bool isObscuredBy(const QGraphicsItem *item) const override
+ {
+ auto myItem = qgraphicsitem_cast<const MyItem *>(item);
+ if (!myItem)
+ return QGraphicsEllipseItem::isObscuredBy(item);
+
+ if (item->zValue() <= zValue())
+ return false;
+
+ QRectF r = rect();
+ QPointF topMid = (r.topRight() + r.topLeft()) / 2;
+ QPointF botMid = (r.bottomRight() + r.bottomLeft()) / 2;
+ QPointF leftMid = (r.topLeft() + r.bottomLeft()) / 2;
+ QPointF rightMid = (r.topRight() + r.bottomRight()) / 2;
+
+ QPainterPath mappedShape = item->mapToItem(this, item->opaqueArea());
+
+ return mappedShape.contains(topMid) && mappedShape.contains(botMid)
+ && mappedShape.contains(leftMid) && mappedShape.contains(rightMid);
}
- QPainterPath opaqueArea() const
+ QPainterPath opaqueArea() const override
{
return shape();
}
- enum {
- Type = UserType+1
- };
- int type() const { return Type; }
+ enum { Type = UserType + 1 };
+
+ int type() const override { return Type; }
};
void tst_QGraphicsItem::isObscuredBy()
@@ -2662,7 +2685,7 @@ void tst_QGraphicsItem::isObscuredBy()
class OpaqueItem : public QGraphicsRectItem
{
protected:
- QPainterPath opaqueArea() const
+ QPainterPath opaqueArea() const override
{
return shape();
}
@@ -2977,14 +3000,14 @@ void tst_QGraphicsItem::mapFromToItem()
QCOMPARE(item3->mapFromItem(item2, 10, -5), QPointF(-190, -5));
QCOMPARE(item4->mapFromItem(item3, 10, -5), QPointF(10, -205));
- QCOMPARE(item1->mapFromItem(0, 10, -5), item1->mapFromScene(10, -5));
- QCOMPARE(item2->mapFromItem(0, 10, -5), item2->mapFromScene(10, -5));
- QCOMPARE(item3->mapFromItem(0, 10, -5), item3->mapFromScene(10, -5));
- QCOMPARE(item4->mapFromItem(0, 10, -5), item4->mapFromScene(10, -5));
- QCOMPARE(item1->mapToItem(0, 10, -5), item1->mapToScene(10, -5));
- QCOMPARE(item2->mapToItem(0, 10, -5), item2->mapToScene(10, -5));
- QCOMPARE(item3->mapToItem(0, 10, -5), item3->mapToScene(10, -5));
- QCOMPARE(item4->mapToItem(0, 10, -5), item4->mapToScene(10, -5));
+ QCOMPARE(item1->mapFromItem(nullptr, 10, -5), item1->mapFromScene(10, -5));
+ QCOMPARE(item2->mapFromItem(nullptr, 10, -5), item2->mapFromScene(10, -5));
+ QCOMPARE(item3->mapFromItem(nullptr, 10, -5), item3->mapFromScene(10, -5));
+ QCOMPARE(item4->mapFromItem(nullptr, 10, -5), item4->mapFromScene(10, -5));
+ QCOMPARE(item1->mapToItem(nullptr, 10, -5), item1->mapToScene(10, -5));
+ QCOMPARE(item2->mapToItem(nullptr, 10, -5), item2->mapToScene(10, -5));
+ QCOMPARE(item3->mapToItem(nullptr, 10, -5), item3->mapToScene(10, -5));
+ QCOMPARE(item4->mapToItem(nullptr, 10, -5), item4->mapToScene(10, -5));
delete item1;
delete item2;
@@ -3079,8 +3102,8 @@ void tst_QGraphicsItem::isAncestorOf()
QGraphicsItem *parent = new QGraphicsRectItem;
QGraphicsItem *child = new QGraphicsRectItem;
- QVERIFY(!parent->isAncestorOf(0));
- QVERIFY(!child->isAncestorOf(0));
+ QVERIFY(!parent->isAncestorOf(nullptr));
+ QVERIFY(!child->isAncestorOf(nullptr));
QVERIFY(!parent->isAncestorOf(child));
QVERIFY(!child->isAncestorOf(parent));
QVERIFY(!parent->isAncestorOf(parent));
@@ -3098,7 +3121,7 @@ void tst_QGraphicsItem::isAncestorOf()
QVERIFY(!parent->isAncestorOf(parent));
QVERIFY(!grandPa->isAncestorOf(grandPa));
- parent->setParentItem(0);
+ parent->setParentItem(nullptr);
delete child;
delete parent;
@@ -3126,7 +3149,7 @@ void tst_QGraphicsItem::commonAncestorItem()
grandPa->setParentItem(ancestor);
QCOMPARE(grandMa->commonAncestorItem(grandMa), grandMa);
- QCOMPARE(grandMa->commonAncestorItem(0), nullptr);
+ QCOMPARE(grandMa->commonAncestorItem(nullptr), nullptr);
QCOMPARE(grandMa->commonAncestorItem(grandPa), ancestor);
QCOMPARE(grandPa->commonAncestorItem(grandMa), ancestor);
QCOMPARE(grandPa->commonAncestorItem(husband), grandPa);
@@ -3230,7 +3253,7 @@ void tst_QGraphicsItem::graphicsitem_cast()
QVERIFY(!qgraphicsitem_cast<const QGraphicsTextItem *>(pPolygonItem));
// and this shouldn't crash
- QGraphicsItem *ptr = 0;
+ QGraphicsItem *ptr = nullptr;
QVERIFY(!qgraphicsitem_cast<QGraphicsTextItem *>(ptr));
QVERIFY(!qgraphicsitem_cast<QGraphicsItem *>(ptr));
}
@@ -3241,6 +3264,7 @@ void tst_QGraphicsItem::hoverEventsGenerateRepaints()
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -3256,48 +3280,48 @@ void tst_QGraphicsItem::hoverEventsGenerateRepaints()
QGraphicsSceneHoverEvent hoverEnterEvent(QEvent::GraphicsSceneHoverEnter);
hoverEnterEvent.setScenePos(QPointF(0, 0));
hoverEnterEvent.setPos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &hoverEnterEvent);
+ QCoreApplication::sendEvent(&scene, &hoverEnterEvent);
// Check that we get a repaint
int npaints = tester->repaints;
- qApp->processEvents();
- qApp->processEvents();
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(tester->events.size(), 2); // enter + move
QCOMPARE(tester->repaints, npaints + 1);
- QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverMove);
+ QCOMPARE(tester->events.constLast(), QEvent::GraphicsSceneHoverMove);
// Send a hover move event
QGraphicsSceneHoverEvent hoverMoveEvent(QEvent::GraphicsSceneHoverMove);
hoverMoveEvent.setScenePos(QPointF(0, 0));
hoverMoveEvent.setPos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &hoverMoveEvent);
+ QCoreApplication::sendEvent(&scene, &hoverMoveEvent);
// Check that we don't get a repaint
- qApp->processEvents();
- qApp->processEvents();
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(tester->events.size(), 3);
QCOMPARE(tester->repaints, npaints + 1);
- QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverMove);
+ QCOMPARE(tester->events.constLast(), QEvent::GraphicsSceneHoverMove);
// Send a hover leave event
QGraphicsSceneHoverEvent hoverLeaveEvent(QEvent::GraphicsSceneHoverLeave);
hoverLeaveEvent.setScenePos(QPointF(-100, -100));
hoverLeaveEvent.setPos(QPointF(0, 0));
- QApplication::sendEvent(&scene, &hoverLeaveEvent);
+ QCoreApplication::sendEvent(&scene, &hoverLeaveEvent);
// Check that we get a repaint
- qApp->processEvents();
- qApp->processEvents();
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(tester->events.size(), 4);
QCOMPARE(tester->repaints, npaints + 2);
- QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverLeave);
+ QCOMPARE(tester->events.constLast(), QEvent::GraphicsSceneHoverLeave);
}
void tst_QGraphicsItem::boundingRects_data()
{
- QTest::addColumn<QGraphicsItem *>("item");
+ QTest::addColumn<AbstractGraphicsShapeItemPtr>("item");
QTest::addColumn<QRectF>("boundingRect");
QRectF rect(0, 0, 100, 100);
@@ -3306,18 +3330,18 @@ void tst_QGraphicsItem::boundingRects_data()
QRectF adjustedRect(-0.5, -0.5, 101, 101);
- QTest::newRow("path") << (QGraphicsItem *)new QGraphicsPathItem(path) << adjustedRect;
- QTest::newRow("rect") << (QGraphicsItem *)new QGraphicsRectItem(rect) << adjustedRect;
- QTest::newRow("ellipse") << (QGraphicsItem *)new QGraphicsEllipseItem(rect) << adjustedRect;
- QTest::newRow("polygon") << (QGraphicsItem *)new QGraphicsPolygonItem(rect) << adjustedRect;
+ QTest::newRow("path") << AbstractGraphicsShapeItemPtr(new QGraphicsPathItem(path)) << adjustedRect;
+ QTest::newRow("rect") << AbstractGraphicsShapeItemPtr(new QGraphicsRectItem(rect)) << adjustedRect;
+ QTest::newRow("ellipse") << AbstractGraphicsShapeItemPtr(new QGraphicsEllipseItem(rect)) << adjustedRect;
+ QTest::newRow("polygon") << AbstractGraphicsShapeItemPtr(new QGraphicsPolygonItem(rect)) << adjustedRect;
}
void tst_QGraphicsItem::boundingRects()
{
- QFETCH(QGraphicsItem *, item);
+ QFETCH(AbstractGraphicsShapeItemPtr, item);
QFETCH(QRectF, boundingRect);
- ((QAbstractGraphicsShapeItem *)item)->setPen(QPen(Qt::black, 1));
+ item->setPen(QPen(Qt::black, 1));
QCOMPARE(item->boundingRect(), boundingRect);
}
@@ -3373,6 +3397,7 @@ void tst_QGraphicsItem::childrenBoundingRect()
scene.addPolygon(parent->mapToScene(parent->boundingRect() | parent->childrenBoundingRect()))->setPen(QPen(Qt::red));;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -3488,6 +3513,7 @@ void tst_QGraphicsItem::childrenBoundingRect4()
rect3->setParentItem(rect);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -3515,6 +3541,7 @@ void tst_QGraphicsItem::childrenBoundingRect5()
child->setPen(QPen(Qt::black, 0));
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -3551,6 +3578,7 @@ void tst_QGraphicsItem::group()
QCOMPARE(child->group(), nullptr);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -3563,7 +3591,7 @@ void tst_QGraphicsItem::group()
QCOMPARE(parent->group(), group);
QCOMPARE(parent->sceneBoundingRect(), parentSceneBoundingRect);
- QCOMPARE(parent->parentItem(), (QGraphicsItem *)group);
+ QCOMPARE(parent->parentItem(), group);
QCOMPARE(group->childItems().size(), 1);
QCOMPARE(scene.items().size(), 4);
QCOMPARE(scene.items(group->sceneBoundingRect()).size(), 3);
@@ -3574,12 +3602,13 @@ void tst_QGraphicsItem::group()
QCOMPARE(parent2->group(), group);
QCOMPARE(parent2->sceneBoundingRect(), parent2SceneBoundingRect);
- QCOMPARE(parent2->parentItem(), (QGraphicsItem *)group);
+ QCOMPARE(parent2->parentItem(), group);
QCOMPARE(group->childItems().size(), 2);
QCOMPARE(scene.items().size(), 4);
QCOMPARE(scene.items(group->sceneBoundingRect()).size(), 4);
- QList<QGraphicsItem *> newItems;
+ GraphicsItems newItems;
+ newItems.reserve(100);
for (int i = 0; i < 100; ++i) {
QGraphicsItem *item = scene.addRect(QRectF(-25, -25, 50, 50), QPen(Qt::black, 0),
QBrush(QColor(QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255),
@@ -3592,7 +3621,7 @@ void tst_QGraphicsItem::group()
view.fitInView(scene.itemsBoundingRect());
- foreach (QGraphicsItem *item, newItems) {
+ for (QGraphicsItem *item : qAsConst(newItems)) {
group->addToGroup(item);
QCOMPARE(item->group(), group);
}
@@ -3608,11 +3637,11 @@ void tst_QGraphicsItem::setGroup()
QCOMPARE(rect->parentItem(), nullptr);
rect->setGroup(&group1);
QCOMPARE(rect->group(), &group1);
- QCOMPARE(rect->parentItem(), (QGraphicsItem *)&group1);
+ QCOMPARE(rect->parentItem(), &group1);
rect->setGroup(&group2);
QCOMPARE(rect->group(), &group2);
- QCOMPARE(rect->parentItem(), (QGraphicsItem *)&group2);
- rect->setGroup(0);
+ QCOMPARE(rect->parentItem(), &group2);
+ rect->setGroup(nullptr);
QCOMPARE(rect->group(), nullptr);
QCOMPARE(rect->parentItem(), nullptr);
}
@@ -3642,7 +3671,7 @@ void tst_QGraphicsItem::setGroup2()
rect->setScale(0.8);
oldSceneTransform = rect->sceneTransform();
- rect->setGroup(0);
+ rect->setGroup(nullptr);
qFuzzyCompare(rect->sceneTransform(), oldSceneTransform);
}
@@ -3715,21 +3744,22 @@ void tst_QGraphicsItem::removeFromGroup()
rect2->setSelected(true);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
- qApp->processEvents(); // index items
- qApp->processEvents(); // emit changed
+ QCoreApplication::processEvents(); // index items
+ QCoreApplication::processEvents(); // emit changed
QGraphicsItemGroup *group = scene.createItemGroup(scene.selectedItems());
QVERIFY(group);
QCOMPARE(group->childItems().size(), 2);
- qApp->processEvents(); // index items
- qApp->processEvents(); // emit changed
+ QCoreApplication::processEvents(); // index items
+ QCoreApplication::processEvents(); // emit changed
scene.destroyItemGroup(group); // calls removeFromGroup.
- qApp->processEvents(); // index items
- qApp->processEvents(); // emit changed
+ QCoreApplication::processEvents(); // index items
+ QCoreApplication::processEvents(); // emit changed
QCOMPARE(scene.items().size(), 2);
QVERIFY(!rect1->group());
@@ -3739,20 +3769,18 @@ void tst_QGraphicsItem::removeFromGroup()
class ChildEventTester : public QGraphicsRectItem
{
public:
- ChildEventTester(const QRectF &rect, QGraphicsItem *parent = 0)
- : QGraphicsRectItem(rect, parent), counter(0)
- { }
+ using QGraphicsRectItem::QGraphicsRectItem;
- int counter;
+ int counter = 0;
protected:
- void focusInEvent(QFocusEvent *event)
+ void focusInEvent(QFocusEvent *event) override
{ ++counter; QGraphicsRectItem::focusInEvent(event); }
- void mousePressEvent(QGraphicsSceneMouseEvent *)
+ void mousePressEvent(QGraphicsSceneMouseEvent *) override
{ ++counter; }
- void mouseMoveEvent(QGraphicsSceneMouseEvent *)
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
{ ++counter; }
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *)
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
{ ++counter; }
};
@@ -3782,16 +3810,17 @@ void tst_QGraphicsItem::handlesChildEvents()
scene.addItem(blue);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
// Pull out the items, closest item first
QList<QGraphicsItem *> items = scene.items(scene.itemsBoundingRect());
- QCOMPARE(items.at(0), (QGraphicsItem *)yellow);
- QCOMPARE(items.at(1), (QGraphicsItem *)gray);
- QCOMPARE(items.at(2), (QGraphicsItem *)green);
- QCOMPARE(items.at(3), (QGraphicsItem *)red);
- QCOMPARE(items.at(4), (QGraphicsItem *)blue);
+ QCOMPARE(items.at(0), yellow);
+ QCOMPARE(items.at(1), gray);
+ QCOMPARE(items.at(2), green);
+ QCOMPARE(items.at(3), red);
+ QCOMPARE(items.at(4), blue);
QCOMPARE(blue->counter, 0);
@@ -3805,8 +3834,8 @@ void tst_QGraphicsItem::handlesChildEvents()
releaseEvent.setButton(Qt::LeftButton);
releaseEvent.setScenePos(blue->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(blue->counter, 2);
@@ -3815,8 +3844,8 @@ void tst_QGraphicsItem::handlesChildEvents()
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
releaseEvent.setScenePos(red->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(blue->counter, 2);
QCOMPARE(red->counter, 2);
@@ -3826,8 +3855,8 @@ void tst_QGraphicsItem::handlesChildEvents()
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
releaseEvent.setScenePos(green->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(blue->counter, 2);
QCOMPARE(red->counter, 2);
@@ -3840,8 +3869,8 @@ void tst_QGraphicsItem::handlesChildEvents()
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
releaseEvent.setScenePos(red->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(blue->counter, 4);
QCOMPARE(red->counter, 2);
@@ -3851,8 +3880,8 @@ void tst_QGraphicsItem::handlesChildEvents()
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
releaseEvent.setScenePos(green->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(blue->counter, 6);
QCOMPARE(red->counter, 2);
@@ -3865,8 +3894,8 @@ void tst_QGraphicsItem::handlesChildEvents()
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
releaseEvent.setScenePos(red->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(blue->counter, 6);
QCOMPARE(red->counter, 4);
@@ -3876,8 +3905,8 @@ void tst_QGraphicsItem::handlesChildEvents()
pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
releaseEvent.setScenePos(green->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(blue->counter, 6);
QCOMPARE(red->counter, 4);
@@ -3905,13 +3934,14 @@ void tst_QGraphicsItem::handlesChildEvents2()
scene.addItem(root);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QApplication::processEvents();
QMouseEvent event(QEvent::MouseButtonPress, view.mapFromScene(5, 5),
- view.viewport()->mapToGlobal(view.mapFromScene(5, 5)), Qt::LeftButton, 0, 0);
- QApplication::sendEvent(view.viewport(), &event);
+ view.viewport()->mapToGlobal(view.mapFromScene(5, 5)), Qt::LeftButton, {}, {});
+ QCoreApplication::sendEvent(view.viewport(), &event);
QTRY_COMPARE(root->counter, 1);
}
@@ -3920,9 +3950,9 @@ void tst_QGraphicsItem::handlesChildEvents3()
{
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
- ChildEventTester *group2 = new ChildEventTester(QRectF(), 0);
+ ChildEventTester *group2 = new ChildEventTester(QRectF(), nullptr);
ChildEventTester *group1 = new ChildEventTester(QRectF(), group2);
ChildEventTester *leaf = new ChildEventTester(QRectF(), group1);
scene.addItem(group2);
@@ -3962,14 +3992,14 @@ void tst_QGraphicsItem::handlesChildEvents3()
class ChildEventFilterTester : public ChildEventTester
{
public:
- ChildEventFilterTester(const QRectF &rect, QGraphicsItem *parent = 0)
- : ChildEventTester(rect, parent), filter(QEvent::None)
+ ChildEventFilterTester(const QRectF &rect, QGraphicsItem *parent = nullptr)
+ : ChildEventTester(rect, parent)
{ }
- QEvent::Type filter;
+ QEvent::Type filter = QEvent::None;
protected:
- bool sceneEventFilter(QGraphicsItem *item, QEvent *event)
+ bool sceneEventFilter(QGraphicsItem *item, QEvent *event) override
{
Q_UNUSED(item);
if (event->type() == filter) {
@@ -3994,6 +4024,7 @@ void tst_QGraphicsItem::filtersChildEvents()
scene.addItem(root);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -4007,8 +4038,8 @@ void tst_QGraphicsItem::filtersChildEvents()
releaseEvent.setButton(Qt::LeftButton);
releaseEvent.setScenePos(QPointF(25, 25));//child->mapToScene(5, 5));
releaseEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos()));
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QTRY_COMPARE(child->counter, 1); // mouse release is not filtered
QCOMPARE(filter->counter, 1); // mouse press is filtered
@@ -4019,8 +4050,8 @@ void tst_QGraphicsItem::filtersChildEvents()
root->filter = QEvent::GraphicsSceneMouseRelease;
// send event to child
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(child->counter, 1);
QCOMPARE(filter->counter, 2); // mouse press is filtered
@@ -4031,8 +4062,8 @@ void tst_QGraphicsItem::filtersChildEvents()
child->setParentItem(parent);
// send event to child
- QApplication::sendEvent(&scene, &pressEvent);
- QApplication::sendEvent(&scene, &releaseEvent);
+ QCoreApplication::sendEvent(&scene, &pressEvent);
+ QCoreApplication::sendEvent(&scene, &releaseEvent);
QCOMPARE(child->counter, 2); // mouse press is _not_ filtered
QCOMPARE(parent->counter, 0);
@@ -4063,14 +4094,15 @@ void tst_QGraphicsItem::filtersChildEvents2()
scene.addItem(root);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QApplication::processEvents();
QMouseEvent event(QEvent::MouseButtonPress, view.mapFromScene(5, 5),
- view.viewport()->mapToGlobal(view.mapFromScene(5, 5)), Qt::LeftButton, 0, 0);
- QApplication::sendEvent(view.viewport(), &event);
+ view.viewport()->mapToGlobal(view.mapFromScene(5, 5)), Qt::LeftButton, {}, {});
+ QCoreApplication::sendEvent(view.viewport(), &event);
QTRY_COMPARE(root->counter, 1);
QCOMPARE(child->counter, 0);
@@ -4082,10 +4114,10 @@ void tst_QGraphicsItem::filtersChildEvents2()
class CustomItem : public QGraphicsItem
{
public:
- QRectF boundingRect() const
+ QRectF boundingRect() const override
{ return QRectF(-110, -110, 220, 220); }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{
for (int x = -100; x <= 100; x += 25)
painter->drawLine(x, -100, x, 100);
@@ -4111,6 +4143,7 @@ void tst_QGraphicsItem::ensureVisible()
scene.addItem(item);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.setFixedSize(300, 300);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -4198,37 +4231,37 @@ void tst_QGraphicsItem::cursor()
QPoint item2Center = view.mapFromScene(item2->sceneBoundingRect().center());
{
- QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, 0, 0);
- QApplication::sendEvent(view.viewport(), &event);
+ QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, {}, {});
+ QCoreApplication::sendEvent(view.viewport(), &event);
}
QCOMPARE(view.viewport()->cursor().shape(), viewportShape);
{
- QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0);
- QApplication::sendEvent(view.viewport(), &event);
+ QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, {}, {});
+ QCoreApplication::sendEvent(view.viewport(), &event);
}
QCOMPARE(view.viewport()->cursor().shape(), item1->cursor().shape());
{
- QMouseEvent event(QEvent::MouseMove, item2Center, view.viewport()->mapToGlobal(item2Center), Qt::NoButton, 0, 0);
- QApplication::sendEvent(view.viewport(), &event);
+ QMouseEvent event(QEvent::MouseMove, item2Center, view.viewport()->mapToGlobal(item2Center), Qt::NoButton, {}, {});
+ QCoreApplication::sendEvent(view.viewport(), &event);
}
QCOMPARE(view.viewport()->cursor().shape(), item2->cursor().shape());
{
- QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, 0, 0);
- QApplication::sendEvent(view.viewport(), &event);
+ QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, {}, {});
+ QCoreApplication::sendEvent(view.viewport(), &event);
}
QCOMPARE(view.viewport()->cursor().shape(), viewportShape);
item1->setEnabled(false);
{
- QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0);
- QApplication::sendEvent(view.viewport(), &event);
+ QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, {}, {});
+ QCoreApplication::sendEvent(view.viewport(), &event);
}
QCOMPARE(view.viewport()->cursor().shape(), viewportShape);
@@ -4342,7 +4375,7 @@ void tst_QGraphicsItem::defaultItemTest_QGraphicsTextItem()
QVERIFY(!text->openExternalLinks());
QVERIFY(text->textCursor().isNull());
QCOMPARE(text->defaultTextColor(), QPalette().color(QPalette::Text));
- QVERIFY(text->document() != 0);
+ QVERIFY(text->document() != nullptr);
QCOMPARE(text->font(), QApplication::font());
QCOMPARE(text->textInteractionFlags(), Qt::TextInteractionFlags(Qt::NoTextInteraction));
QCOMPARE(text->textWidth(), -1.0);
@@ -4358,12 +4391,12 @@ void tst_QGraphicsItem::defaultItemTest_QGraphicsTextItem()
event.setScenePos(QPointF(1, 1));
event.setButton(Qt::LeftButton);
event.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QGraphicsSceneMouseEvent event2(QEvent::GraphicsSceneMouseMove);
event2.setScenePos(QPointF(11, 11));
event2.setButton(Qt::LeftButton);
event2.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event2);
+ QCoreApplication::sendEvent(&scene, &event2);
}
QCOMPARE(text->pos(), QPointF(10, 10));
@@ -4379,7 +4412,7 @@ void tst_QGraphicsItem::defaultItemTest_QGraphicsTextItem()
event2.setScenePos(QPointF(21, 21));
event2.setButton(Qt::LeftButton);
event2.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event2);
+ QCoreApplication::sendEvent(&scene, &event2);
}
QCOMPARE(text->pos(), QPointF(20, 20)); // clicked on edge, item moved
@@ -4420,15 +4453,16 @@ void tst_QGraphicsItem::defaultItemTest_QGraphicsEllipseItem()
class ItemChangeTester : public QGraphicsRectItem
{
public:
- ItemChangeTester()
- { setFlag(ItemSendsGeometryChanges); clear(); }
- ItemChangeTester(QGraphicsItem *parent) : QGraphicsRectItem(parent)
- { setFlag(ItemSendsGeometryChanges); clear(); }
+ ItemChangeTester(QGraphicsItem *parent = nullptr) : QGraphicsRectItem(parent)
+ {
+ setFlag(ItemSendsGeometryChanges);
+ clear();
+ }
void clear()
{
itemChangeReturnValue = QVariant();
- itemSceneChangeTargetScene = 0;
+ itemSceneChangeTargetScene = nullptr;
changes.clear();
values.clear();
oldValues.clear();
@@ -4437,11 +4471,11 @@ public:
QVariant itemChangeReturnValue;
QGraphicsScene *itemSceneChangeTargetScene;
- QList<GraphicsItemChange> changes;
- QList<QVariant> values;
- QList<QVariant> oldValues;
+ QVector<GraphicsItemChange> changes;
+ QVariantList values;
+ QVariantList oldValues;
protected:
- QVariant itemChange(GraphicsItemChange change, const QVariant &value)
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
{
changes << change;
values << value;
@@ -4560,7 +4594,7 @@ QT_WARNING_POP
void tst_QGraphicsItem::itemChange()
{
ItemChangeTester tester;
- tester.itemSceneChangeTargetScene = 0;
+ tester.itemSceneChangeTargetScene = nullptr;
ItemChangeTester testerHelper;
QVERIFY(tester.changes.isEmpty());
@@ -4578,7 +4612,7 @@ void tst_QGraphicsItem::itemChange()
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemEnabledHasChanged);
QCOMPARE(tester.values.at(tester.values.size() - 2), QVariant(false));
QCOMPARE(tester.values.at(tester.values.size() - 1), QVariant(true));
- QCOMPARE(tester.oldValues.last(), QVariant(true));
+ QCOMPARE(tester.oldValues.constLast(), QVariant(true));
QCOMPARE(tester.isEnabled(), true);
}
#if QT_DEPRECATED_SINCE(5, 13)
@@ -4594,10 +4628,10 @@ QT_WARNING_DISABLE_DEPRECATED // QDesktopWidget::screen()
QCOMPARE(int(tester.changes.last()), int(QGraphicsItem::ItemTransformHasChanged));
QCOMPARE(qvariant_cast<QMatrix>(tester.values.at(tester.values.size() - 2)),
QMatrix().translate(50, 0));
- QCOMPARE(tester.values.last(), QVariant(QTransform(QMatrix().rotate(90))));
+ QCOMPARE(tester.values.constLast(), QVariant(QTransform(QMatrix().rotate(90))));
QVariant variant;
variant.setValue<QMatrix>(QMatrix());
- QCOMPARE(tester.oldValues.last(), variant);
+ QCOMPARE(tester.oldValues.constLast(), variant);
QCOMPARE(tester.matrix(), QMatrix().rotate(90));
QT_WARNING_POP
}
@@ -4621,7 +4655,7 @@ QT_WARNING_POP
QTransform().rotate(90));
QVariant variant;
variant.setValue<QTransform>(QTransform());
- QCOMPARE(tester.oldValues.last(), variant);
+ QCOMPARE(tester.oldValues.constLast(), variant);
QCOMPARE(tester.transform(), QTransform().rotate(90));
}
{
@@ -4635,7 +4669,7 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemPositionHasChanged);
QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(QPointF(0, 42)));
QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(QPointF(42, 0)));
- QCOMPARE(tester.oldValues.last(), QVariant(QPointF()));
+ QCOMPARE(tester.oldValues.constLast(), QVariant(QPointF()));
QCOMPARE(tester.pos(), QPointF(42, 0));
}
{
@@ -4649,7 +4683,7 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemZValueHasChanged);
QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(qreal(1.0)));
QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(qreal(2.0)));
- QCOMPARE(tester.oldValues.last(), QVariant(qreal(0.0)));
+ QCOMPARE(tester.oldValues.constLast(), QVariant(qreal(0.0)));
QCOMPARE(tester.zValue(), qreal(2.0));
}
{
@@ -4663,7 +4697,7 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemRotationHasChanged);
QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(qreal(10.0)));
QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(qreal(15.0)));
- QCOMPARE(tester.oldValues.last(), QVariant(qreal(0.0)));
+ QCOMPARE(tester.oldValues.constLast(), QVariant(qreal(0.0)));
QCOMPARE(tester.rotation(), qreal(15.0));
}
{
@@ -4677,7 +4711,7 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemScaleHasChanged);
QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(qreal(1.5)));
QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(qreal(2.0)));
- QCOMPARE(tester.oldValues.last(), QVariant(qreal(1.0)));
+ QCOMPARE(tester.oldValues.constLast(), QVariant(qreal(1.0)));
QCOMPARE(tester.scale(), qreal(2.0));
}
{
@@ -4691,7 +4725,7 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemTransformOriginPointHasChanged);
QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(QPointF(1.0, 1.0)));
QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(QPointF(2.0, 2.0)));
- QCOMPARE(tester.oldValues.last(), QVariant(QPointF(0.0, 0.0)));
+ QCOMPARE(tester.oldValues.constLast(), QVariant(QPointF(0.0, 0.0)));
QCOMPARE(tester.transformOriginPoint(), QPointF(2.0, 2.0));
}
{
@@ -4707,7 +4741,8 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemFlagsHaveChanged);
QVariant expectedFlags = QVariant::fromValue<quint32>(QGraphicsItem::GraphicsItemFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges));
QCOMPARE(tester.values.at(tester.values.size() - 2), expectedFlags);
- QCOMPARE(tester.values.at(tester.values.size() - 1), QVariant::fromValue<quint32>((quint32)QGraphicsItem::ItemIsSelectable));
+ QCOMPARE(tester.values.at(tester.values.size() - 1),
+ QVariant::fromValue<quint32>(quint32(QGraphicsItem::ItemIsSelectable)));
}
{
// ItemSelectedChange
@@ -4722,7 +4757,7 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemSelectedHasChanged);
QCOMPARE(tester.values.at(tester.values.size() - 2), QVariant(true));
QCOMPARE(tester.values.at(tester.values.size() - 1), QVariant(true));
- QCOMPARE(tester.oldValues.last(), QVariant(false));
+ QCOMPARE(tester.oldValues.constLast(), QVariant(false));
QCOMPARE(tester.isSelected(), true);
tester.itemChangeReturnValue = false;
@@ -4754,11 +4789,11 @@ QT_WARNING_POP
}
{
// ItemParentChange
- tester.itemChangeReturnValue.setValue<QGraphicsItem *>(0);
+ tester.itemChangeReturnValue.setValue<QGraphicsItem *>(nullptr);
tester.setParentItem(&testerHelper);
QCOMPARE(tester.changes.size(), ++changeCount);
- QCOMPARE(tester.changes.last(), QGraphicsItem::ItemParentChange);
- QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), (QGraphicsItem *)&testerHelper);
+ QCOMPARE(tester.changes.constLast(), QGraphicsItem::ItemParentChange);
+ QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), &testerHelper);
QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.oldValues.last()), nullptr);
QCOMPARE(tester.parentItem(), nullptr);
}
@@ -4767,7 +4802,7 @@ QT_WARNING_POP
tester.itemChangeReturnValue = 1.0;
tester.setOpacity(0.7);
QCOMPARE(tester.changes.size(), ++changeCount);
- QCOMPARE(tester.changes.last(), QGraphicsItem::ItemOpacityChange);
+ QCOMPARE(tester.changes.constLast(), QGraphicsItem::ItemOpacityChange);
QVERIFY(qFuzzyCompare(qreal(tester.values.last().toDouble()), qreal(0.7)));
QCOMPARE(tester.oldValues.last().toDouble(), double(1.0));
QCOMPARE(tester.opacity(), qreal(1.0));
@@ -4785,19 +4820,19 @@ QT_WARNING_POP
tester.itemChangeReturnValue.clear();
testerHelper.setParentItem(&tester);
QCOMPARE(tester.changes.size(), ++changeCount);
- QCOMPARE(tester.changes.last(), QGraphicsItem::ItemChildAddedChange);
- QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), (QGraphicsItem *)&testerHelper);
+ QCOMPARE(tester.changes.constLast(), QGraphicsItem::ItemChildAddedChange);
+ QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), &testerHelper);
}
{
// ItemChildRemovedChange 1
- testerHelper.setParentItem(0);
+ testerHelper.setParentItem(nullptr);
QCOMPARE(tester.changes.size(), ++changeCount);
- QCOMPARE(tester.changes.last(), QGraphicsItem::ItemChildRemovedChange);
- QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), (QGraphicsItem *)&testerHelper);
+ QCOMPARE(tester.changes.constLast(), QGraphicsItem::ItemChildRemovedChange);
+ QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), &testerHelper);
// ItemChildRemovedChange 1
ItemChangeTester *test = new ItemChangeTester;
- test->itemSceneChangeTargetScene = 0;
+ test->itemSceneChangeTargetScene = nullptr;
int count = 0;
QGraphicsScene *scene = new QGraphicsScene;
scene->addItem(test);
@@ -4806,11 +4841,11 @@ QT_WARNING_POP
QGraphicsRectItem *child = new QGraphicsRectItem(test);
//We received ItemChildAddedChange
QCOMPARE(test->changes.size(), ++count);
- QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildAddedChange);
+ QCOMPARE(test->changes.constLast(), QGraphicsItem::ItemChildAddedChange);
delete child;
- child = 0;
+ child = nullptr;
QCOMPARE(test->changes.size(), ++count);
- QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildRemovedChange);
+ QCOMPARE(test->changes.constLast(), QGraphicsItem::ItemChildRemovedChange);
ItemChangeTester *childTester = new ItemChangeTester(test);
//Changes contains all sceneHasChanged and so on, we don't want to test that
@@ -4820,12 +4855,12 @@ QT_WARNING_POP
child = new QGraphicsRectItem(childTester);
//We received ItemChildAddedChange
QCOMPARE(childTester->changes.size(), ++childCount);
- QCOMPARE(childTester->changes.last(), QGraphicsItem::ItemChildAddedChange);
+ QCOMPARE(childTester->changes.constLast(), QGraphicsItem::ItemChildAddedChange);
//Delete the child of the top level with all its children
delete childTester;
//Only one removal
QCOMPARE(test->changes.size(), ++count);
- QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildRemovedChange);
+ QCOMPARE(test->changes.constLast(), QGraphicsItem::ItemChildRemovedChange);
delete scene;
}
{
@@ -4833,11 +4868,11 @@ QT_WARNING_POP
ItemChangeTester parent;
ItemChangeTester *child = new ItemChangeTester;
child->setParentItem(&parent);
- QCOMPARE(parent.changes.last(), QGraphicsItem::ItemChildAddedChange);
- QCOMPARE(qvariant_cast<QGraphicsItem *>(parent.values.last()), (QGraphicsItem *)child);
+ QCOMPARE(parent.changes.constLast(), QGraphicsItem::ItemChildAddedChange);
+ QCOMPARE(qvariant_cast<QGraphicsItem *>(parent.values.last()), child);
delete child;
- QCOMPARE(parent.changes.last(), QGraphicsItem::ItemChildRemovedChange);
- QCOMPARE(qvariant_cast<QGraphicsItem *>(parent.values.last()), (QGraphicsItem *)child);
+ QCOMPARE(parent.changes.constLast(), QGraphicsItem::ItemChildRemovedChange);
+ QCOMPARE(qvariant_cast<QGraphicsItem *>(parent.values.last()), child);
}
{
// !!! Note: If this test crashes because of double-deletion, there's
@@ -4857,7 +4892,7 @@ QT_WARNING_POP
// Item's old value was 0
// Item's current value is scene
QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.last()), nullptr);
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.last()), (QGraphicsScene *)&scene);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.last()), &scene);
scene2.addItem(&tester);
++changeCount; // ItemSceneChange (0) was: (scene)
++changeCount; // ItemSceneHasChanged (0)
@@ -4873,16 +4908,16 @@ QT_WARNING_POP
// Item's last old value was scene
// Item's last current value is 0
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.at(tester.oldValues.size() - 2)), (QGraphicsScene *)&scene);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.at(tester.oldValues.size() - 2)), &scene);
QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.at(tester.oldValues.size() - 1)), nullptr);
QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 4)), nullptr);
QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 3)), nullptr);
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), (QGraphicsScene *)&scene2);
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), (QGraphicsScene *)&scene2);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), &scene2);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), &scene2);
// Item's last old value was 0
// Item's last current value is scene2
QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.last()), nullptr);
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.last()), (QGraphicsScene *)&scene2);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.last()), &scene2);
scene2.removeItem(&tester);
++changeCount; // ItemSceneChange (0) was: (scene2)
@@ -4894,7 +4929,7 @@ QT_WARNING_POP
QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemSceneHasChanged);
// Item's last old value was scene2
// Item's last current value is 0
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.last()), (QGraphicsScene *)&scene2);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.last()), &scene2);
QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), nullptr);
QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), nullptr);
@@ -4905,12 +4940,12 @@ QT_WARNING_POP
++changeCount; // ItemSceneHasChanged (scene)
QCOMPARE(tester.values.size(), changeCount);
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 3)), (QGraphicsScene *)&scene2);
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), (QGraphicsScene *)&scene);
- QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), (QGraphicsScene *)&scene);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 3)), &scene2);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), &scene);
+ QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), &scene);
QCOMPARE(tester.scene(), &scene);
- tester.itemSceneChangeTargetScene = 0;
+ tester.itemSceneChangeTargetScene = nullptr;
tester.itemChangeReturnValue = QVariant();
scene.removeItem(&tester);
++changeCount; // ItemSceneChange
@@ -4938,23 +4973,20 @@ QT_WARNING_POP
class EventFilterTesterItem : public QGraphicsLineItem
{
public:
- QList<QEvent::Type> filteredEvents;
- QList<QGraphicsItem *> filteredEventReceivers;
- bool handlesSceneEvents;
-
- QList<QEvent::Type> receivedEvents;
-
- EventFilterTesterItem() : handlesSceneEvents(false) {}
+ QVector<QEvent::Type> filteredEvents;
+ GraphicsItems filteredEventReceivers;
+ QVector<QEvent::Type> receivedEvents;
+ bool handlesSceneEvents = false;
protected:
- bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
+ bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
{
filteredEvents << event->type();
filteredEventReceivers << watched;
return handlesSceneEvents;
}
- bool sceneEvent(QEvent *event)
+ bool sceneEvent(QEvent *event) override
{
return QGraphicsLineItem::sceneEvent(event);
}
@@ -4965,6 +4997,7 @@ void tst_QGraphicsItem::sceneEventFilter()
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -5066,16 +5099,16 @@ void tst_QGraphicsItem::prepareGeometryChange()
class PaintTester : public QGraphicsRectItem
{
public:
- PaintTester() : widget(NULL), painted(0) { setRect(QRectF(10, 10, 20, 20));}
+ PaintTester() { setRect(QRectF(10, 10, 20, 20));}
- void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *w)
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *w) override
{
widget = w;
painted++;
}
- QWidget* widget;
- int painted;
+ QWidget *widget = nullptr;
+ int painted = 0;
};
void tst_QGraphicsItem::paint()
@@ -5086,6 +5119,7 @@ void tst_QGraphicsItem::paint()
scene.addItem(&paintTester);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QApplication::processEvents();
@@ -5102,6 +5136,7 @@ void tst_QGraphicsItem::paint()
QGraphicsScene scene2;
QGraphicsView view2(&scene2);
+ view2.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view2.show();
QVERIFY(QTest::qWaitForWindowExposed(&view2));
QCoreApplication::processEvents(); // Process all queued paint events
@@ -5135,194 +5170,194 @@ class HarakiriItem : public QGraphicsRectItem
public:
HarakiriItem(int harakiriPoint)
: QGraphicsRectItem(QRectF(0, 0, 100, 100)), harakiri(harakiriPoint)
- { dead = 0; }
+ { dead = false; }
- static int dead;
+ static bool dead;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
{
QGraphicsRectItem::paint(painter, option, widget);
if (harakiri == 0) {
// delete unsupported since 4.5
/*
- dead = 1;
+ dead = true;
delete this;
*/
}
}
- void advance(int n)
+ void advance(int n) override
{
if (harakiri == 1 && n == 0) {
// delete unsupported
/*
- dead = 1;
+ dead = true;
delete this;
*/
}
if (harakiri == 2 && n == 1) {
- dead = 1;
+ dead = true;
delete this;
}
}
protected:
#ifndef QT_NO_CONTEXTMENU
- void contextMenuEvent(QGraphicsSceneContextMenuEvent *)
+ void contextMenuEvent(QGraphicsSceneContextMenuEvent *) override
{
if (harakiri == 3) {
- dead = 1;
+ dead = true;
delete this;
}
}
#endif // QT_NO_CONTEXTMENU
- void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
+ void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override
{
// ??
QGraphicsRectItem::dragEnterEvent(event);
}
- void dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
+ void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override
{
// ??
QGraphicsRectItem::dragLeaveEvent(event);
}
- void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
+ void dragMoveEvent(QGraphicsSceneDragDropEvent *event) override
{
// ??
QGraphicsRectItem::dragMoveEvent(event);
}
- void dropEvent(QGraphicsSceneDragDropEvent *event)
+ void dropEvent(QGraphicsSceneDragDropEvent *event) override
{
// ??
QGraphicsRectItem::dropEvent(event);
}
- void focusInEvent(QFocusEvent *)
+ void focusInEvent(QFocusEvent *) override
{
if (harakiri == 4) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void focusOutEvent(QFocusEvent *)
+ void focusOutEvent(QFocusEvent *) override
{
if (harakiri == 5) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void hoverEnterEvent(QGraphicsSceneHoverEvent *)
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
{
if (harakiri == 6) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void hoverLeaveEvent(QGraphicsSceneHoverEvent *)
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
{
if (harakiri == 7) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void hoverMoveEvent(QGraphicsSceneHoverEvent *)
+ void hoverMoveEvent(QGraphicsSceneHoverEvent *) override
{
if (harakiri == 8) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void inputMethodEvent(QInputMethodEvent *event)
+ void inputMethodEvent(QInputMethodEvent *event) override
{
// ??
QGraphicsRectItem::inputMethodEvent(event);
}
- QVariant inputMethodQuery(Qt::InputMethodQuery query) const
+ QVariant inputMethodQuery(Qt::InputMethodQuery query) const override
{
// ??
return QGraphicsRectItem::inputMethodQuery(query);
}
- QVariant itemChange(GraphicsItemChange change, const QVariant &value)
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
{
// deletion not supported
return QGraphicsRectItem::itemChange(change, value);
}
- void keyPressEvent(QKeyEvent *)
+ void keyPressEvent(QKeyEvent *) override
{
if (harakiri == 9) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void keyReleaseEvent(QKeyEvent *)
+ void keyReleaseEvent(QKeyEvent *) override
{
if (harakiri == 10) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *)
+ void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override
{
if (harakiri == 11) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void mouseMoveEvent(QGraphicsSceneMouseEvent *)
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
{
if (harakiri == 12) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void mousePressEvent(QGraphicsSceneMouseEvent *)
+ void mousePressEvent(QGraphicsSceneMouseEvent *) override
{
if (harakiri == 13) {
- dead = 1;
+ dead = true;
delete this;
}
}
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *)
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
{
if (harakiri == 14) {
- dead = 1;
+ dead = true;
delete this;
}
}
- bool sceneEvent(QEvent *event)
+ bool sceneEvent(QEvent *event) override
{
// deletion not supported
return QGraphicsRectItem::sceneEvent(event);
}
- bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
+ bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
{
// deletion not supported
return QGraphicsRectItem::sceneEventFilter(watched, event);
}
- void wheelEvent(QGraphicsSceneWheelEvent *)
+ void wheelEvent(QGraphicsSceneWheelEvent *) override
{
if (harakiri == 16) {
- dead = 1;
+ dead = true;
delete this;
}
}
@@ -5331,7 +5366,7 @@ private:
int harakiri;
};
-int HarakiriItem::dead;
+bool HarakiriItem::dead;
void tst_QGraphicsItem::deleteItemInEventHandlers()
{
@@ -5346,44 +5381,45 @@ void tst_QGraphicsItem::deleteItemInEventHandlers()
item->installSceneEventFilter(item); // <- ehey!
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
- qApp->processEvents();
- qApp->processEvents();
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents();
- if (!item->dead)
+ if (!HarakiriItem::dead)
scene.advance();
#ifndef QT_NO_CONTEXTMENU
- if (!item->dead) {
+ if (!HarakiriItem::dead) {
QContextMenuEvent event(QContextMenuEvent::Other,
view.mapFromScene(item->scenePos()));
QCoreApplication::sendEvent(view.viewport(), &event);
}
#endif // QT_NO_CONTEXTMENU
- if (!item->dead)
+ if (!HarakiriItem::dead)
QTest::mouseMove(view.viewport(), view.mapFromScene(item->scenePos()));
- if (!item->dead)
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos()));
- if (!item->dead)
- QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos()));
- if (!item->dead)
- QTest::mouseClick(view.viewport(), Qt::RightButton, 0, view.mapFromScene(item->scenePos()));
- if (!item->dead)
+ if (!HarakiriItem::dead)
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos()));
+ if (!HarakiriItem::dead)
+ QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos()));
+ if (!HarakiriItem::dead)
+ QTest::mouseClick(view.viewport(), Qt::RightButton, {}, view.mapFromScene(item->scenePos()));
+ if (!HarakiriItem::dead)
QTest::mouseMove(view.viewport(), view.mapFromScene(item->scenePos() + QPointF(20, -20)));
- if (!item->dead)
+ if (!HarakiriItem::dead)
item->setFocus();
- if (!item->dead)
+ if (!HarakiriItem::dead)
item->clearFocus();
- if (!item->dead)
+ if (!HarakiriItem::dead)
item->setFocus();
- if (!item->dead)
+ if (!HarakiriItem::dead)
QTest::keyPress(view.viewport(), Qt::Key_A);
- if (!item->dead)
+ if (!HarakiriItem::dead)
QTest::keyRelease(view.viewport(), Qt::Key_A);
- if (!item->dead)
+ if (!HarakiriItem::dead)
QTest::keyPress(view.viewport(), Qt::Key_A);
- if (!item->dead)
+ if (!HarakiriItem::dead)
QTest::keyRelease(view.viewport(), Qt::Key_A);
}
}
@@ -5391,12 +5427,12 @@ void tst_QGraphicsItem::deleteItemInEventHandlers()
class ItemPaintsOutsideShape : public QGraphicsItem
{
public:
- QRectF boundingRect() const
+ QRectF boundingRect() const override
{
return QRectF(0, 0, 100, 100);
}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{
painter->fillRect(-50, -50, 200, 200, Qt::red);
painter->fillRect(0, 0, 100, 100, Qt::blue);
@@ -5492,16 +5528,16 @@ void tst_QGraphicsItem::itemClipsChildrenToShape2()
QGraphicsScene scene;
scene.addItem(parent);
- QCOMPARE(scene.items(QPointF(5, 5)).value(0, nullptr), (QGraphicsItem *)parent);
+ QCOMPARE(scene.items(QPointF(5, 5)).value(0, nullptr), parent);
QVERIFY(scene.items(QPointF(15, 5)).isEmpty());
QVERIFY(scene.items(QPointF(5, 15)).isEmpty());
QVERIFY(scene.items(QPointF(60, 60)).isEmpty());
QVERIFY(scene.items(QPointF(140, 60)).isEmpty());
QVERIFY(scene.items(QPointF(60, 140)).isEmpty());
QVERIFY(scene.items(QPointF(140, 140)).isEmpty());
- QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), (QGraphicsItem *)child2);
- QCOMPARE(scene.items(QPointF(75, 100)).value(0, nullptr), (QGraphicsItem *)child1);
- QCOMPARE(scene.items(QPointF(100, 75)).value(0, nullptr), (QGraphicsItem *)child1);
+ QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), child2);
+ QCOMPARE(scene.items(QPointF(75, 100)).value(0, nullptr), child1);
+ QCOMPARE(scene.items(QPointF(100, 75)).value(0, nullptr), child1);
QImage image(100, 100, QImage::Format_ARGB32_Premultiplied);
image.fill(0);
@@ -5536,9 +5572,9 @@ void tst_QGraphicsItem::itemClipsChildrenToShape3()
grandchild->setPos( 50, 50 );
parent->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
- QCOMPARE(scene.items(QPointF(25, 25)).value(0, nullptr), (QGraphicsItem *)parent);
- QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), (QGraphicsItem *)child);
- QCOMPARE(scene.items(QPointF(125, 125)).value(0, nullptr), (QGraphicsItem *)grandchild);
+ QCOMPARE(scene.items(QPointF(25, 25)).value(0, nullptr), parent);
+ QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), child);
+ QCOMPARE(scene.items(QPointF(125, 125)).value(0, nullptr), grandchild);
QVERIFY(scene.items(QPointF(175, 175)).isEmpty());
// Move child to fully overlap the parent. The grandchild should
@@ -5546,26 +5582,24 @@ void tst_QGraphicsItem::itemClipsChildrenToShape3()
child->prepareGeometryChange();
child->setPos( 0, 0 );
- QCOMPARE(scene.items(QPointF(25, 25)).value(0, nullptr), (QGraphicsItem *)child);
- QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), (QGraphicsItem *)grandchild);
- QCOMPARE(scene.items(QPointF(125, 125)).value(0, nullptr), (QGraphicsItem *)grandchild);
+ QCOMPARE(scene.items(QPointF(25, 25)).value(0, nullptr), child);
+ QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), grandchild);
+ QCOMPARE(scene.items(QPointF(125, 125)).value(0, nullptr), grandchild);
QVERIFY(scene.items(QPointF(175, 175)).isEmpty());
}
class MyProxyWidget : public QGraphicsProxyWidget
{
public:
- MyProxyWidget(QGraphicsItem *parent) : QGraphicsProxyWidget(parent)
- {
- painted = false;
- }
+ using QGraphicsProxyWidget::QGraphicsProxyWidget;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
{
QGraphicsProxyWidget::paint(painter, option, widget);
painted = true;
}
- bool painted;
+
+ bool painted = false;
};
void tst_QGraphicsItem::itemClipsChildrenToShape4()
@@ -5586,8 +5620,9 @@ void tst_QGraphicsItem::itemClipsChildrenToShape4()
//now the label is shown
outerWidget->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false );
QApplication::setActiveWindow(&view);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
- QTRY_COMPARE(QApplication::activeWindow(), (QWidget *)&view);
+ QTRY_COMPARE(QApplication::activeWindow(), &view);
QTRY_COMPARE(innerWidget->painted, true);
}
@@ -5610,10 +5645,9 @@ void tst_QGraphicsItem::itemClipsChildrenToShape5()
class ParentItem : public QGraphicsRectItem
{
public:
- ParentItem(qreal x, qreal y, qreal width, qreal height)
- : QGraphicsRectItem(x, y, width, height) {}
+ using QGraphicsRectItem::QGraphicsRectItem;
- QPainterPath shape() const
+ QPainterPath shape() const override
{
QPainterPath path;
path.addRect(50, 50, 200, 200);
@@ -5668,12 +5702,12 @@ void tst_QGraphicsItem::itemClipsChildrenToShape5()
bottomRightChild->setPos(200, 200);
childRegion += QRect(200, 200, 100, 100);
- QPoint controlPoints[17] = {
- QPoint(5, 5) , QPoint(95, 5) , QPoint(205, 5) , QPoint(295, 5) ,
- QPoint(5, 95) , QPoint(95, 95) , QPoint(205, 95) , QPoint(295, 95) ,
- QPoint(150, 150),
- QPoint(5, 205), QPoint(95, 205), QPoint(205, 205), QPoint(295, 205),
- QPoint(5, 295), QPoint(95, 295), QPoint(205, 295), QPoint(295, 295),
+ const QPoint controlPoints[17] = {
+ {5, 5}, {95, 5}, {205, 5}, {295, 5},
+ {5, 95}, {95, 95}, {205, 95}, {295, 95},
+ {150, 150},
+ {5, 205}, {95, 205}, {205, 205}, {295, 205},
+ {5, 295}, {95, 295}, {205, 295}, {295, 295},
};
const QRegion clippedChildRegion = childRegion & QRect(50, 50, 200, 200);
@@ -5684,8 +5718,7 @@ void tst_QGraphicsItem::itemClipsChildrenToShape5()
QImage sceneImage(300, 300, QImage::Format_ARGB32);
#define VERIFY_CONTROL_POINTS(pRegion, cRegion, gRegion) \
- for (int i = 0; i < 17; ++i) { \
- QPoint controlPoint = controlPoints[i]; \
+ for (const QPoint &controlPoint : controlPoints) { \
QRgb pixel = sceneImage.pixel(controlPoint.x(), controlPoint.y()); \
if (pRegion.contains(controlPoint)) \
QVERIFY(qBlue(pixel) != 0); \
@@ -5711,13 +5744,13 @@ void tst_QGraphicsItem::itemClipsChildrenToShape5()
case 0:
// All children stacked in front.
childString = QLatin1String("ChildrenInFront.png");
- foreach (QGraphicsItem *child, children)
+ for (QGraphicsItem *child : children)
child->setFlag(QGraphicsItem::ItemStacksBehindParent, false);
break;
case 1:
// All children stacked behind.
childString = QLatin1String("ChildrenBehind.png");
- foreach (QGraphicsItem *child, children)
+ for (QGraphicsItem *child : children)
child->setFlag(QGraphicsItem::ItemStacksBehindParent, true);
break;
case 2:
@@ -5821,8 +5854,8 @@ void tst_QGraphicsItem::itemClippingDiscovery()
rightRectItem->setParentItem(clipItem);
// The rects item are both visible at these points.
- QCOMPARE(scene.items(QPointF(10, 10)).value(0, nullptr), (QGraphicsItem *)leftRectItem);
- QCOMPARE(scene.items(QPointF(90, 90)).value(0, nullptr), (QGraphicsItem *)rightRectItem);
+ QCOMPARE(scene.items(QPointF(10, 10)).value(0, nullptr), leftRectItem);
+ QCOMPARE(scene.items(QPointF(90, 90)).value(0, nullptr), rightRectItem);
// The ellipse clips the rects now.
clipItem->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
@@ -5837,13 +5870,15 @@ void tst_QGraphicsItem::itemClippingDiscovery()
class ItemCountsBoundingRectCalls : public QGraphicsRectItem
{
public:
- ItemCountsBoundingRectCalls(const QRectF & rect, QGraphicsItem *parent = 0)
- : QGraphicsRectItem(rect, parent), boundingRectCalls(0) {}
- QRectF boundingRect () const {
+ using QGraphicsRectItem::QGraphicsRectItem;
+
+ QRectF boundingRect () const override
+ {
++boundingRectCalls;
return QGraphicsRectItem::boundingRect();
}
- mutable int boundingRectCalls;
+
+ mutable int boundingRectCalls = 0;
};
void tst_QGraphicsItem::itemContainsChildrenInShape()
@@ -6006,7 +6041,7 @@ void tst_QGraphicsItem::ancestorFlags()
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1);
// Reparent the child to root
- level21->setParentItem(0);
+ level21->setParentItem(nullptr);
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0);
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0);
QCOMPARE(int(level31->d_ptr->ancestorFlags), 1);
@@ -6030,7 +6065,7 @@ void tst_QGraphicsItem::ancestorFlags()
QCOMPARE(int(level32->d_ptr->ancestorFlags), 1);
// Reparenting level31 back to level21.
- level31->setParentItem(0);
+ level31->setParentItem(nullptr);
QCOMPARE(int(level31->d_ptr->ancestorFlags), 0);
level31->setParentItem(level21);
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0);
@@ -6069,7 +6104,6 @@ void tst_QGraphicsItem::ancestorFlags()
break;
default:
qFatal("Unknown ancestor flag, please fix!");
- break;
}
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0);
@@ -6136,7 +6170,7 @@ void tst_QGraphicsItem::ancestorFlags()
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag);
// Reparent the child to root
- level21->setParentItem(0);
+ level21->setParentItem(nullptr);
QCOMPARE(int(level21->d_ptr->ancestorFlags), 0);
QCOMPARE(int(level22->d_ptr->ancestorFlags), 0);
QCOMPARE(int(level31->d_ptr->ancestorFlags), ancestorFlag);
@@ -6160,7 +6194,7 @@ void tst_QGraphicsItem::ancestorFlags()
QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag);
// Reparenting level31 back to level21.
- level31->setParentItem(0);
+ level31->setParentItem(nullptr);
QCOMPARE(int(level31->d_ptr->ancestorFlags), 0);
level31->setParentItem(level21);
QCOMPARE(int(level1->d_ptr->ancestorFlags), 0);
@@ -6191,28 +6225,29 @@ void tst_QGraphicsItem::ancestorFlags()
void tst_QGraphicsItem::untransformable()
{
- QGraphicsItem *item1 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100));
+ auto item1 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100));
item1->setZValue(1);
item1->setFlag(QGraphicsItem::ItemIgnoresTransformations);
item1->setTransform(QTransform().rotate(45), true);
- ((QGraphicsEllipseItem *)item1)->setBrush(Qt::red);
+ item1->setBrush(Qt::red);
- QGraphicsItem *item2 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100));
+ auto item2 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100));
item2->setParentItem(item1);
item2->setTransform(QTransform().rotate(45), true);
item2->setPos(100, 0);
- ((QGraphicsEllipseItem *)item2)->setBrush(Qt::green);
+ item2->setBrush(Qt::green);
- QGraphicsItem *item3 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100));
+ auto item3 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100));
item3->setParentItem(item2);
item3->setPos(100, 0);
- ((QGraphicsEllipseItem *)item3)->setBrush(Qt::blue);
+ item3->setBrush(Qt::blue);
QGraphicsScene scene(-500, -500, 1000, 1000);
scene.addItem(item1);
QWidget topLevel;
QGraphicsView view(&scene,&topLevel);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.resize(300, 300);
topLevel.show();
view.scale(8, 8);
@@ -6257,14 +6292,14 @@ void tst_QGraphicsItem::untransformable()
class ContextMenuItem : public QGraphicsRectItem
{
public:
- ContextMenuItem()
- : ignoreEvent(true), gotEvent(false), eventWasAccepted(false)
- { }
- bool ignoreEvent;
- bool gotEvent;
- bool eventWasAccepted;
+ using QGraphicsRectItem::QGraphicsRectItem;
+
+ bool ignoreEvent = true;
+ bool gotEvent = false;
+ bool eventWasAccepted = false;
+
protected:
- void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
+ void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
{
gotEvent = true;
eventWasAccepted = event->isAccepted();
@@ -6284,6 +6319,7 @@ void tst_QGraphicsItem::contextMenuEventPropagation()
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.setAlignment(Qt::AlignLeft | Qt::AlignTop);
view.show();
view.resize(200, 200);
@@ -6292,14 +6328,14 @@ void tst_QGraphicsItem::contextMenuEventPropagation()
QContextMenuEvent event(QContextMenuEvent::Mouse, QPoint(10, 10),
view.viewport()->mapToGlobal(QPoint(10, 10)));
event.ignore();
- QApplication::sendEvent(view.viewport(), &event);
+ QCoreApplication::sendEvent(view.viewport(), &event);
QVERIFY(!event.isAccepted());
scene.addItem(bottomItem);
topItem->ignoreEvent = true;
bottomItem->ignoreEvent = true;
- QApplication::sendEvent(view.viewport(), &event);
+ QCoreApplication::sendEvent(view.viewport(), &event);
QVERIFY(!event.isAccepted());
QCOMPARE(topItem->gotEvent, true);
QCOMPARE(topItem->eventWasAccepted, true);
@@ -6310,7 +6346,7 @@ void tst_QGraphicsItem::contextMenuEventPropagation()
topItem->gotEvent = false;
bottomItem->gotEvent = false;
- QApplication::sendEvent(view.viewport(), &event);
+ QCoreApplication::sendEvent(view.viewport(), &event);
QVERIFY(event.isAccepted());
QCOMPARE(topItem->gotEvent, true);
QCOMPARE(bottomItem->gotEvent, false);
@@ -6330,34 +6366,34 @@ void tst_QGraphicsItem::itemIsMovable()
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress);
event.setButton(Qt::LeftButton);
event.setButtons(Qt::LeftButton);
- qApp->sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
}
{
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
event.setButton(Qt::LeftButton);
event.setButtons(Qt::LeftButton);
- qApp->sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
}
QCOMPARE(rect->pos(), QPointF(0, 0));
{
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
event.setButtons(Qt::LeftButton);
event.setScenePos(QPointF(10, 10));
- qApp->sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
}
QCOMPARE(rect->pos(), QPointF(10, 10));
{
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
event.setButtons(Qt::RightButton);
event.setScenePos(QPointF(20, 20));
- qApp->sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
}
QCOMPARE(rect->pos(), QPointF(10, 10));
{
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove);
event.setButtons(Qt::LeftButton);
event.setScenePos(QPointF(30, 30));
- qApp->sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
}
QCOMPARE(rect->pos(), QPointF(30, 30));
}
@@ -6368,14 +6404,14 @@ class ItemAddScene : public QGraphicsScene
public:
ItemAddScene()
{
- QTimer::singleShot(500, this, SLOT(newTextItem()));
+ QTimer::singleShot(500, this, &ItemAddScene::newTextItem);
}
public slots:
void newTextItem()
{
// Add a text item
- QGraphicsItem *item = new QGraphicsTextItem("This item will not ensure that it's visible", 0);
+ QGraphicsItem *item = addText("This item will not ensure that it's visible");
item->setPos(.0, .0);
item->show();
}
@@ -6387,6 +6423,7 @@ void tst_QGraphicsItem::task141694_textItemEnsureVisible()
scene.setSceneRect(-1000, -1000, 2000, 2000);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.setFixedSize(200, 200);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -6414,6 +6451,7 @@ void tst_QGraphicsItem::task128696_textItemEnsureMovable()
scene.addItem(item);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.setFixedSize(200, 200);
view.show();
@@ -6421,14 +6459,14 @@ void tst_QGraphicsItem::task128696_textItemEnsureMovable()
event1.setScenePos(QPointF(0, 0));
event1.setButton(Qt::LeftButton);
event1.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event1);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item);
+ QCoreApplication::sendEvent(&scene, &event1);
+ QCOMPARE(scene.mouseGrabberItem(), item);
QGraphicsSceneMouseEvent event2(QEvent::GraphicsSceneMouseMove);
event2.setScenePos(QPointF(10, 10));
event2.setButton(Qt::LeftButton);
event2.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event2);
+ QCoreApplication::sendEvent(&scene, &event2);
QCOMPARE(item->pos(), QPointF(10, 10));
}
@@ -6447,33 +6485,45 @@ void tst_QGraphicsItem::task177918_lineItemUndetected()
void tst_QGraphicsItem::task240400_clickOnTextItem_data()
{
- QTest::addColumn<int>("flags");
- QTest::addColumn<int>("textFlags");
- QTest::newRow("editor, noflags") << 0 << int(Qt::TextEditorInteraction);
- QTest::newRow("editor, movable") << int(QGraphicsItem::ItemIsMovable) << int(Qt::TextEditorInteraction);
- QTest::newRow("editor, selectable") << int(QGraphicsItem::ItemIsSelectable) << int(Qt::TextEditorInteraction);
- QTest::newRow("editor, movable | selectable") << int(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable)
- << int(Qt::TextEditorInteraction);
- QTest::newRow("noninteractive, noflags") << 0 << int(Qt::NoTextInteraction);
- QTest::newRow("noninteractive, movable") << int(QGraphicsItem::ItemIsMovable) << int(Qt::NoTextInteraction);
- QTest::newRow("noninteractive, selectable") << int(QGraphicsItem::ItemIsSelectable) << int(Qt::NoTextInteraction);
- QTest::newRow("noninteractive, movable | selectable") << int(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable)
- << int(Qt::NoTextInteraction);
+ using Flags = QGraphicsItem::GraphicsItemFlags;
+ QTest::addColumn<Flags>("flags");
+ QTest::addColumn<Qt::TextInteractionFlags>("textFlags");
+ QTest::newRow("editor, noflags")
+ << Flags{}
+ << Qt::TextInteractionFlags(Qt::TextEditorInteraction);
+ QTest::newRow("editor, movable")
+ << Flags(QGraphicsItem::ItemIsMovable)
+ << Qt::TextInteractionFlags(Qt::TextEditorInteraction);
+ QTest::newRow("editor, selectable")
+ << Flags(QGraphicsItem::ItemIsSelectable)
+ << Qt::TextInteractionFlags(Qt::TextEditorInteraction);
+ QTest::newRow("editor, movable | selectable")
+ << Flags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable)
+ << Qt::TextInteractionFlags(Qt::TextEditorInteraction);
+ QTest::newRow("noninteractive, noflags")
+ << Flags{} << Qt::TextInteractionFlags(Qt::NoTextInteraction);
+ QTest::newRow("noninteractive, movable")
+ << Flags(QGraphicsItem::ItemIsMovable) << Qt::TextInteractionFlags(Qt::NoTextInteraction);
+ QTest::newRow("noninteractive, selectable")
+ << Flags(QGraphicsItem::ItemIsSelectable) << Qt::TextInteractionFlags(Qt::NoTextInteraction);
+ QTest::newRow("noninteractive, movable | selectable")
+ << Flags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable)
+ << Qt::TextInteractionFlags(Qt::NoTextInteraction);
}
void tst_QGraphicsItem::task240400_clickOnTextItem()
{
- QFETCH(int, flags);
- QFETCH(int, textFlags);
+ QFETCH(QGraphicsItem::GraphicsItemFlags, flags);
+ QFETCH(Qt::TextInteractionFlags, textFlags);
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QGraphicsTextItem *item = scene.addText("Hello");
- item->setFlags(QGraphicsItem::GraphicsItemFlags(flags));
- item->setTextInteractionFlags(Qt::TextInteractionFlags(textFlags));
- bool focusable = (item->flags() & QGraphicsItem::ItemIsFocusable);
+ item->setFlags(flags);
+ item->setTextInteractionFlags(textFlags);
+ const bool focusable = item->flags().testFlag(QGraphicsItem::ItemIsFocusable);
QVERIFY(textFlags ? focusable : !focusable);
int column = item->textCursor().columnNumber();
@@ -6487,25 +6537,25 @@ void tst_QGraphicsItem::task240400_clickOnTextItem()
event.setScenePos(item->sceneBoundingRect().topLeft() + QPointF(0.1, 0.1));
event.setButton(Qt::LeftButton);
event.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
}
if (flags || textFlags)
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item);
+ QCOMPARE(scene.mouseGrabberItem(), item);
else
QCOMPARE(scene.mouseGrabberItem(), nullptr);
{
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease);
event.setScenePos(item->sceneBoundingRect().topLeft() + QPointF(0.1, 0.1));
event.setButton(Qt::LeftButton);
- event.setButtons(0);
- QApplication::sendEvent(&scene, &event);
+ event.setButtons({});
+ QCoreApplication::sendEvent(&scene, &event);
}
if (textFlags)
QVERIFY(item->hasFocus());
else
QVERIFY(!item->hasFocus());
QVERIFY(!scene.mouseGrabberItem());
- bool selectable = (flags & QGraphicsItem::ItemIsSelectable);
+ bool selectable = flags.testFlag(QGraphicsItem::ItemIsSelectable);
QVERIFY(selectable ? item->isSelected() : !item->isSelected());
// Now click in the middle and check that the cursor moved.
@@ -6514,18 +6564,18 @@ void tst_QGraphicsItem::task240400_clickOnTextItem()
event.setScenePos(item->sceneBoundingRect().center());
event.setButton(Qt::LeftButton);
event.setButtons(Qt::LeftButton);
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
}
if (flags || textFlags)
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item);
+ QCOMPARE(scene.mouseGrabberItem(), item);
else
QCOMPARE(scene.mouseGrabberItem(), nullptr);
{
QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease);
event.setScenePos(item->sceneBoundingRect().center());
event.setButton(Qt::LeftButton);
- event.setButtons(0);
- QApplication::sendEvent(&scene, &event);
+ event.setButtons({});
+ QCoreApplication::sendEvent(&scene, &event);
}
if (textFlags)
QVERIFY(item->hasFocus());
@@ -6536,7 +6586,7 @@ void tst_QGraphicsItem::task240400_clickOnTextItem()
QVERIFY(selectable ? item->isSelected() : !item->isSelected());
//
- if (textFlags & Qt::TextEditorInteraction)
+ if (textFlags.testFlag(Qt::TextEditorInteraction))
QVERIFY(item->textCursor().columnNumber() > column);
else
QCOMPARE(item->textCursor().columnNumber(), 0);
@@ -6545,24 +6595,22 @@ void tst_QGraphicsItem::task240400_clickOnTextItem()
class TextItem : public QGraphicsSimpleTextItem
{
public:
- TextItem(const QString& text) : QGraphicsSimpleTextItem(text)
- {
- updates = 0;
- }
+ using QGraphicsSimpleTextItem::QGraphicsSimpleTextItem;
- void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
+ void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) override
{
updates++;
QGraphicsSimpleTextItem::paint(painter, option, widget);
}
- int updates;
+ int updates = 0;
};
void tst_QGraphicsItem::ensureUpdateOnTextItem()
{
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QCoreApplication::processEvents(); // Process all queued paint events
@@ -6836,6 +6884,7 @@ void tst_QGraphicsItem::opacity2()
scene.addItem(parent);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -6910,6 +6959,7 @@ void tst_QGraphicsItem::opacityZeroUpdates()
scene.addItem(parent);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -6939,18 +6989,18 @@ void tst_QGraphicsItem::opacityZeroUpdates()
class StacksBehindParentHelper : public QGraphicsRectItem
{
public:
- StacksBehindParentHelper(QList<QGraphicsItem *> *paintedItems, const QRectF &rect, QGraphicsItem *parent = 0)
- : QGraphicsRectItem(rect, parent), paintedItems(paintedItems)
+ StacksBehindParentHelper(GraphicsItems *paintedItems, const QRectF &rect, QGraphicsItem *parent = nullptr)
+ : QGraphicsRectItem(rect, parent), m_paintedItems(paintedItems)
{ }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
{
QGraphicsRectItem::paint(painter, option, widget);
- paintedItems->append(this);
+ m_paintedItems->append(this);
}
private:
- QList<QGraphicsItem *> *paintedItems;
+ GraphicsItems *m_paintedItems;
};
void tst_QGraphicsItem::itemStacksBehindParent()
@@ -6988,6 +7038,7 @@ void tst_QGraphicsItem::itemStacksBehindParent()
scene.addItem(parent2);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QTRY_VERIFY(!paintedItems.isEmpty());
@@ -6995,55 +7046,47 @@ void tst_QGraphicsItem::itemStacksBehindParent()
view.viewport()->update();
QApplication::processEvents();
QRectF rect(0, 0, 100, 100);
- QTRY_COMPARE(scene.items(rect), (QList<QGraphicsItem *>()
- << grandChild111 << child11
- << grandChild121 << child12 << parent1
- << grandChild211 << child21
- << grandChild221 << child22 << parent2));
- QTRY_COMPARE(paintedItems, QList<QGraphicsItem *>()
- << parent2 << child22 << grandChild221
- << child21 << grandChild211
- << parent1 << child12 << grandChild121
- << child11 << grandChild111);
+ const GraphicsItemsList expected1{grandChild111, child11, grandChild121, child12, parent1,
+ grandChild211, child21, grandChild221, child22, parent2};
+ QTRY_COMPARE(scene.items(rect), expected1);
+
+ const GraphicsItems expected2{parent2, child22, grandChild221, child21, grandChild211,
+ parent1, child12, grandChild121, child11, grandChild111};
+ QTRY_COMPARE(paintedItems, expected2);
child11->setFlag(QGraphicsItem::ItemStacksBehindParent);
scene.update();
paintedItems.clear();
- QTRY_COMPARE(scene.items(rect), (QList<QGraphicsItem *>()
- << grandChild121 << child12 << parent1
- << grandChild111 << child11
- << grandChild211 << child21
- << grandChild221 << child22 << parent2));
- QTRY_COMPARE(paintedItems, QList<QGraphicsItem *>()
- << parent2 << child22 << grandChild221
- << child21 << grandChild211
- << child11 << grandChild111
- << parent1 << child12 << grandChild121);
+ const GraphicsItemsList expected3{grandChild121, child12, parent1, grandChild111, child11,
+ grandChild211, child21, grandChild221, child22, parent2};
+
+ QTRY_COMPARE(scene.items(rect), expected3);
+ const GraphicsItems expected4{parent2, child22, grandChild221, child21, grandChild211, child11, grandChild111,
+ parent1, child12, grandChild121};
+ QTRY_COMPARE(paintedItems, expected4);
child12->setFlag(QGraphicsItem::ItemStacksBehindParent);
paintedItems.clear();
scene.update();
- QTRY_COMPARE(scene.items(rect), (QList<QGraphicsItem *>()
- << parent1 << grandChild111 << child11
- << grandChild121 << child12
- << grandChild211 << child21
- << grandChild221 << child22 << parent2));
- QTRY_COMPARE(paintedItems, QList<QGraphicsItem *>()
- << parent2 << child22 << grandChild221
- << child21 << grandChild211
- << child12 << grandChild121
- << child11 << grandChild111 << parent1);
+ const GraphicsItemsList expected5{parent1, grandChild111, child11, grandChild121, child12,
+ grandChild211, child21, grandChild221, child22, parent2};
+ QTRY_COMPARE(scene.items(rect), expected5);
+
+ const GraphicsItems expected6{parent2, child22, grandChild221, child21, grandChild211,
+ child12, grandChild121, child11, grandChild111, parent1};
+ QTRY_COMPARE(paintedItems, expected6);
}
class ClippingAndTransformsScene : public QGraphicsScene
{
+ Q_OBJECT
public:
- QList<QGraphicsItem *> drawnItems;
+ GraphicsItems drawnItems;
protected:
void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[],
- const QStyleOptionGraphicsItem options[], QWidget *widget = 0)
+ const QStyleOptionGraphicsItem options[], QWidget *widget = nullptr) override
{
drawnItems.clear();
for (int i = 0; i < numItems; ++i)
@@ -7084,11 +7127,11 @@ void tst_QGraphicsItem::nestedClipping()
QGraphicsView view(&scene);
view.setOptimizationFlag(QGraphicsView::IndirectPainting);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
- QList<QGraphicsItem *> expected;
- expected << root << l1 << l2 << l3;
+ GraphicsItems expected{root, l1, l2, l3};
QTRY_COMPARE(scene.drawnItems, expected);
QImage image(200, 200, QImage::Format_ARGB32_Premultiplied);
@@ -7126,7 +7169,7 @@ public:
QTransform x;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget = 0)
+ QWidget *widget = nullptr) override
{
x = painter->worldTransform();
QGraphicsRectItem::paint(painter, option, widget);
@@ -7195,6 +7238,7 @@ void tst_QGraphicsItem::sceneTransformCache()
rect2->setTransform(QTransform().rotate(90), true);
rect->setTransform(QTransform::fromTranslate(0, 50), true);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
rect->setTransform(QTransform::fromTranslate(0, 100), true);
@@ -7271,6 +7315,7 @@ void tst_QGraphicsItem::tabChangesFocus()
layout->addWidget(dial2);
QWidget widget;
+ widget.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
widget.setLayout(layout);
widget.show();
QVERIFY(QTest::qWaitForWindowActive(&widget));
@@ -7301,6 +7346,7 @@ void tst_QGraphicsItem::cacheMode()
{
QGraphicsScene scene(0, 0, 100, 100);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.resize(150, 150);
view.show();
QApplication::setActiveWindow(&view);
@@ -7481,6 +7527,7 @@ void tst_QGraphicsItem::cacheMode2()
{
QGraphicsScene scene(0, 0, 100, 100);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.resize(150, 150);
view.show();
QApplication::setActiveWindow(&view);
@@ -7552,6 +7599,7 @@ void tst_QGraphicsItem::updateCachedItemAfterMove()
QGraphicsScene scene;
scene.addItem(tester);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -7589,7 +7637,7 @@ public:
setAcceptHoverEvents(true);
}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override
{
QGraphicsRectItem::paint(painter, option, widget);
const QString text = QString::number(p.x()) + QLatin1Char('x') + QString::number(p.y())
@@ -7598,7 +7646,7 @@ public:
}
protected:
- void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
+ void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override
{
p = event->pos();
sp = event->widget()->mapFromGlobal(event->screenPos());
@@ -7695,6 +7743,7 @@ void tst_QGraphicsItem::update()
QGraphicsScene scene;
scene.setSceneRect(-100, -100, 200, 200);
QWidget topLevel;
+ topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
MyGraphicsView view(&scene,&topLevel);
topLevel.resize(300, 300);
@@ -7732,7 +7781,7 @@ void tst_QGraphicsItem::update()
view.reset();
item->repaints = 0;
item->update(-15, -15, 5, 5); // Item's brect: (-10, -10, 20, 20)
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 0);
QCOMPARE(view.repaints, 0);
@@ -7741,7 +7790,7 @@ void tst_QGraphicsItem::update()
item->repaints = 0;
item->update(); // Full update; all sub-sequent update requests are discarded.
item->hide(); // visible set to 0. ignoreVisible must be set to 1; the item won't be processed otherwise.
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 0);
QCOMPARE(view.repaints, 1);
// The entire item's bounding rect (adjusted for antialiasing) should have been painted.
@@ -7751,7 +7800,7 @@ void tst_QGraphicsItem::update()
view.reset();
item->repaints = 0;
item->show();
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 1);
QCOMPARE(view.repaints, 1);
// The entire item's bounding rect (adjusted for antialiasing) should have been painted.
@@ -7759,21 +7808,21 @@ void tst_QGraphicsItem::update()
item->repaints = 0;
item->hide();
- qApp->processEvents();
+ QCoreApplication::processEvents();
view.reset();
const QPointF originalPos = item->pos();
item->setPos(5000, 5000);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 0);
QCOMPARE(view.repaints, 0);
- qApp->processEvents();
+ QCoreApplication::processEvents();
item->setPos(originalPos);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 0);
QCOMPARE(view.repaints, 0);
item->show();
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 1);
QCOMPARE(view.repaints, 1);
// The entire item's bounding rect (adjusted for antialiasing) should have been painted.
@@ -7804,14 +7853,14 @@ void tst_QGraphicsItem::update()
view.reset();
item->repaints = 0;
parent->setTransform(QTransform::fromTranslate(-400, 0), true);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 0);
QCOMPARE(view.repaints, 1);
QCOMPARE(view.paintedRegion, expectedRegion);
view.reset();
item->repaints = 0;
parent->setTransform(QTransform::fromTranslate(400, 0), true);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(item->repaints, 1);
QCOMPARE(view.repaints, 1);
QCOMPARE(view.paintedRegion, expectedRegion);
@@ -7933,11 +7982,9 @@ void tst_QGraphicsItem::setTransformProperties()
class MyStyleOptionTester : public QGraphicsRectItem
{
public:
- MyStyleOptionTester(const QRectF &rect)
- : QGraphicsRectItem(rect), startTrack(false)
- {}
+ using QGraphicsRectItem::QGraphicsRectItem;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override
{
++repaints;
if (startTrack) {
@@ -7953,7 +8000,7 @@ public:
}
QGraphicsRectItem::paint(painter, option, widget);
}
- bool startTrack;
+ bool startTrack = false;
int repaints = 0;
};
@@ -7971,6 +8018,7 @@ void tst_QGraphicsItem::itemUsesExtendedStyleOption()
scene.addItem(rect);
rect->setPos(200, 200);
QWidget topLevel;
+ topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
topLevel.resize(200, 200);
QGraphicsView view(&scene, &topLevel);
topLevel.setWindowFlags(Qt::X11BypassWindowManagerHint);
@@ -7998,7 +8046,7 @@ void tst_QGraphicsItem::itemUsesExtendedStyleOption()
void tst_QGraphicsItem::itemSendsGeometryChanges()
{
ItemChangeTester item;
- item.setFlags(0);
+ item.setFlags(nullptr);
item.clear();
QTransform x = QTransform().rotate(45);
@@ -8038,21 +8086,21 @@ void tst_QGraphicsItem::itemSendsGeometryChanges()
QCOMPARE(item.scale(), qreal(1.0));
QCOMPARE(item.transformOriginPoint(), QPointF(0.0, 0.0));
- QCOMPARE(item.changes, QList<QGraphicsItem::GraphicsItemChange>()
- << QGraphicsItem::ItemOpacityChange
- << QGraphicsItem::ItemOpacityHasChanged
- << QGraphicsItem::ItemFlagsChange
- << QGraphicsItem::ItemFlagsHaveChanged
- << QGraphicsItem::ItemTransformChange
- << QGraphicsItem::ItemTransformHasChanged
- << QGraphicsItem::ItemPositionChange
- << QGraphicsItem::ItemPositionHasChanged
- << QGraphicsItem::ItemRotationChange
- << QGraphicsItem::ItemRotationHasChanged
- << QGraphicsItem::ItemScaleChange
- << QGraphicsItem::ItemScaleHasChanged
- << QGraphicsItem::ItemTransformOriginPointChange
- << QGraphicsItem::ItemTransformOriginPointHasChanged);
+ const QVector<QGraphicsItem::GraphicsItemChange> expected{QGraphicsItem::ItemOpacityChange,
+ QGraphicsItem::ItemOpacityHasChanged,
+ QGraphicsItem::ItemFlagsChange,
+ QGraphicsItem::ItemFlagsHaveChanged,
+ QGraphicsItem::ItemTransformChange,
+ QGraphicsItem::ItemTransformHasChanged,
+ QGraphicsItem::ItemPositionChange,
+ QGraphicsItem::ItemPositionHasChanged,
+ QGraphicsItem::ItemRotationChange,
+ QGraphicsItem::ItemRotationHasChanged,
+ QGraphicsItem::ItemScaleChange,
+ QGraphicsItem::ItemScaleHasChanged,
+ QGraphicsItem::ItemTransformOriginPointChange,
+ QGraphicsItem::ItemTransformOriginPointHasChanged};
+ QCOMPARE(item.changes, expected);
}
// Make sure we update moved items correctly.
@@ -8062,6 +8110,7 @@ void tst_QGraphicsItem::moveItem()
scene.setSceneRect(-50, -50, 200, 200);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QCoreApplication::processEvents(); // Process all queued paint events
@@ -8088,7 +8137,7 @@ void tst_QGraphicsItem::moveItem()
.adjusted(-2, -2, 2, 2); // Adjusted for antialiasing.
parent->setPos(20, 20);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(parent->repaints, 1);
QCOMPARE(view.repaints, 1);
QRegion expectedParentRegion = parentDeviceBoundingRect; // old position
@@ -8099,7 +8148,7 @@ void tst_QGraphicsItem::moveItem()
RESET_COUNTERS
child->setPos(20, 20);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(parent->repaints, 1);
QCOMPARE(child->repaints, 1);
QCOMPARE(view.repaints, 1);
@@ -8109,7 +8158,7 @@ void tst_QGraphicsItem::moveItem()
RESET_COUNTERS
grandChild->setPos(20, 20);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(parent->repaints, 1);
QCOMPARE(child->repaints, 1);
QCOMPARE(grandChild->repaints, 1);
@@ -8120,7 +8169,7 @@ void tst_QGraphicsItem::moveItem()
RESET_COUNTERS
parent->setTransform(QTransform::fromTranslate(20, 20), true);
- qApp->processEvents();
+ QCoreApplication::processEvents();
QCOMPARE(parent->repaints, 1);
QCOMPARE(child->repaints, 1);
QCOMPARE(grandChild->repaints, 1);
@@ -8140,6 +8189,7 @@ void tst_QGraphicsItem::moveLineItem()
scene.addItem(item);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -8148,9 +8198,9 @@ void tst_QGraphicsItem::moveLineItem()
QRectF brect = item->boundingRect();
// Do same adjustments as in qgraphicsscene.cpp
- if (!brect.width())
+ if (qFuzzyIsNull(brect.width()))
brect.adjust(qreal(-0.00001), 0, qreal(0.00001), 0);
- if (!brect.height())
+ if (qFuzzyIsNull(brect.height()))
brect.adjust(0, qreal(-0.00001), 0, qreal(0.00001));
const QRect itemDeviceBoundingRect = item->deviceTransform(view.viewportTransform())
.mapRect(brect).toAlignedRect();
@@ -8206,6 +8256,7 @@ void tst_QGraphicsItem::sorting()
scene.addItem(item2);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
// Use Qt::Tool as fully decorated windows have a minimum width of 160 on Windows.
view.setWindowFlags(view.windowFlags() | Qt::Tool);
view.setResizeAnchor(QGraphicsView::NoAnchor);
@@ -8227,13 +8278,13 @@ void tst_QGraphicsItem::sorting()
QTest::qWait(100);
#endif
- QCOMPARE(_paintedItems, QList<QGraphicsItem *>()
- << grid[0][0] << grid[0][1] << grid[0][2] << grid[0][3]
- << grid[1][0] << grid[1][1] << grid[1][2] << grid[1][3]
- << grid[2][0] << grid[2][1] << grid[2][2] << grid[2][3]
- << grid[3][0] << grid[3][1] << grid[3][2] << grid[3][3]
- << grid[4][0] << grid[4][1] << grid[4][2] << grid[4][3]
- << item1 << item2);
+ const GraphicsItems expected{grid[0][0], grid[0][1], grid[0][2], grid[0][3],
+ grid[1][0], grid[1][1], grid[1][2], grid[1][3],
+ grid[2][0], grid[2][1], grid[2][2], grid[2][3],
+ grid[3][0], grid[3][1], grid[3][2], grid[3][3],
+ grid[4][0], grid[4][1], grid[4][2], grid[4][3],
+ item1, item2};
+ QCOMPARE(_paintedItems, expected);
}
void tst_QGraphicsItem::itemHasNoContents()
@@ -8249,6 +8300,7 @@ void tst_QGraphicsItem::itemHasNoContents()
scene.addItem(item1);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
qApp->setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -8264,7 +8316,7 @@ void tst_QGraphicsItem::itemHasNoContents()
QTest::qWait(10);
#endif
- QTRY_COMPARE(_paintedItems, QList<QGraphicsItem *>() << item2);
+ QTRY_COMPARE(_paintedItems, GraphicsItems{item2});
}
void tst_QGraphicsItem::hitTestUntransformableItem()
@@ -8273,6 +8325,7 @@ void tst_QGraphicsItem::hitTestUntransformableItem()
scene.setSceneRect(-100, -100, 200, 200);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -8303,7 +8356,7 @@ void tst_QGraphicsItem::hitTestUntransformableItem()
QList<QGraphicsItem *> items = scene.items(QPointF(80, 80));
QCOMPARE(items.size(), 1);
- QCOMPARE(items.at(0), static_cast<QGraphicsItem*>(item3));
+ QCOMPARE(items.at(0), item3);
scene.setItemIndexMethod(QGraphicsScene::NoIndex);
QTest::qWait(100);
@@ -8319,6 +8372,7 @@ void tst_QGraphicsItem::hitTestGraphicsEffectItem()
scene.setSceneRect(-100, -100, 200, 200);
QWidget toplevel;
+ toplevel.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
QGraphicsView view(&scene, &toplevel);
toplevel.resize(300, 300);
@@ -8379,7 +8433,7 @@ void tst_QGraphicsItem::hitTestGraphicsEffectItem()
QVERIFY(items.isEmpty());
items = scene.items(QPointF(80, 80));
QCOMPARE(items.size(), 1);
- QCOMPARE(items.at(0), static_cast<QGraphicsItem *>(item3));
+ QCOMPARE(items.at(0), item3);
scene.setItemIndexMethod(QGraphicsScene::NoIndex);
QTest::qWait(100);
@@ -8395,7 +8449,7 @@ void tst_QGraphicsItem::focusProxy()
{
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QGraphicsItem *item = scene.addRect(0, 0, 10, 10);
item->setFlag(QGraphicsItem::ItemIsFocusable);
@@ -8414,27 +8468,27 @@ void tst_QGraphicsItem::focusProxy()
QString err;
QTextStream stream(&err);
stream << "QGraphicsItem::setFocusProxy: "
- << (void*)item << " is already in the focus proxy chain" << Qt::flush;
+ << static_cast<const void*>(item) << " is already in the focus proxy chain" << Qt::flush;
QTest::ignoreMessage(QtWarningMsg, err.toLatin1().constData());
item2->setFocusProxy(item); // fails
- QCOMPARE(item->focusProxy(), (QGraphicsItem *)item2);
+ QCOMPARE(item->focusProxy(), item2);
QCOMPARE(item2->focusProxy(), nullptr);
// Try to assign self as focus proxy
QTest::ignoreMessage(QtWarningMsg, "QGraphicsItem::setFocusProxy: cannot assign self as focus proxy");
item->setFocusProxy(item); // fails
- QCOMPARE(item->focusProxy(), (QGraphicsItem *)item2);
+ QCOMPARE(item->focusProxy(), item2);
QCOMPARE(item2->focusProxy(), nullptr);
// Reset the focus proxy
- item->setFocusProxy(0);
+ item->setFocusProxy(nullptr);
QCOMPARE(item->focusProxy(), nullptr);
QVERIFY(!item->hasFocus());
QVERIFY(item2->hasFocus());
// Test deletion
item->setFocusProxy(item2);
- QCOMPARE(item->focusProxy(), (QGraphicsItem *)item2);
+ QCOMPARE(item->focusProxy(), item2);
delete item2;
QCOMPARE(item->focusProxy(), nullptr);
@@ -8485,7 +8539,7 @@ void tst_QGraphicsItem::subFocus()
QVERIFY(!text->hasFocus());
text->setFocus();
QVERIFY(!text->hasFocus());
- QCOMPARE(text->focusItem(), (QGraphicsItem *)text);
+ QCOMPARE(text->focusItem(), text);
// Add a sibling.
QGraphicsTextItem *text2 = new QGraphicsTextItem("Hi");
@@ -8496,7 +8550,7 @@ void tst_QGraphicsItem::subFocus()
// got input focus.
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
scene.addItem(text);
scene.addItem(text2);
@@ -8510,10 +8564,10 @@ void tst_QGraphicsItem::subFocus()
scene.removeItem(text2);
text2->setFocus();
scene.addItem(text2);
- QCOMPARE(text2->focusItem(), (QGraphicsItem *)text2);
+ QCOMPARE(text2->focusItem(), text2);
text2->setParentItem(text);
- QCOMPARE(text->focusItem(), (QGraphicsItem *)text2);
- QCOMPARE(text2->focusItem(), (QGraphicsItem *)text2);
+ QCOMPARE(text->focusItem(), text2);
+ QCOMPARE(text2->focusItem(), text2);
QVERIFY(!text->hasFocus());
QVERIFY(text2->hasFocus());
@@ -8524,12 +8578,12 @@ void tst_QGraphicsItem::subFocus()
QCOMPARE(text->focusItem(), nullptr);
QCOMPARE(text2->focusItem(), nullptr);
text2->setFocus();
- QCOMPARE(text->focusItem(), (QGraphicsItem *)text2);
- QCOMPARE(text2->focusItem(), (QGraphicsItem *)text2);
+ QCOMPARE(text->focusItem(), text2);
+ QCOMPARE(text2->focusItem(), text2);
scene.addItem(text);
// Hiding and showing text should pass focus to text2.
- QCOMPARE(text->focusItem(), (QGraphicsItem *)text2);
+ QCOMPARE(text->focusItem(), text2);
QVERIFY(text2->hasFocus());
// Subfocus should repropagate to root when reparenting.
@@ -8546,15 +8600,15 @@ void tst_QGraphicsItem::subFocus()
rect3->setFocus();
QVERIFY(!rect3->hasFocus());
- QCOMPARE(rect->focusItem(), (QGraphicsItem *)rect3);
- QCOMPARE(rect2->focusItem(), (QGraphicsItem *)rect3);
- QCOMPARE(rect3->focusItem(), (QGraphicsItem *)rect3);
+ QCOMPARE(rect->focusItem(), rect3);
+ QCOMPARE(rect2->focusItem(), rect3);
+ QCOMPARE(rect3->focusItem(), rect3);
rect->setParentItem(text2);
- QCOMPARE(text->focusItem(), (QGraphicsItem *)rect3);
- QCOMPARE(text2->focusItem(), (QGraphicsItem *)rect3);
- QCOMPARE(rect->focusItem(), (QGraphicsItem *)rect3);
- QCOMPARE(rect2->focusItem(), (QGraphicsItem *)rect3);
- QCOMPARE(rect3->focusItem(), (QGraphicsItem *)rect3);
+ QCOMPARE(text->focusItem(), rect3);
+ QCOMPARE(text2->focusItem(), rect3);
+ QCOMPARE(rect->focusItem(), rect3);
+ QCOMPARE(rect2->focusItem(), rect3);
+ QCOMPARE(rect3->focusItem(), rect3);
QVERIFY(!rect->hasFocus());
QVERIFY(!rect2->hasFocus());
QVERIFY(rect3->hasFocus());
@@ -8570,7 +8624,7 @@ void tst_QGraphicsItem::focusProxyDeletion()
QGraphicsRectItem *rect = new QGraphicsRectItem;
QGraphicsRectItem *rect2 = new QGraphicsRectItem;
rect->setFocusProxy(rect2);
- QCOMPARE(rect->focusProxy(), (QGraphicsItem *)rect2);
+ QCOMPARE(rect->focusProxy(), rect2);
delete rect2;
QCOMPARE(rect->focusProxy(), nullptr);
@@ -8595,13 +8649,13 @@ void tst_QGraphicsItem::focusProxyDeletion()
QCOMPARE(rect->focusProxy(), nullptr);
scene->addItem(rect2);
rect->setFocusProxy(rect2);
- QCOMPARE(rect->focusProxy(), (QGraphicsItem *)rect2);
+ QCOMPARE(rect->focusProxy(), rect2);
delete rect; // don't crash
rect = new QGraphicsRectItem;
rect2 = new QGraphicsRectItem;
rect->setFocusProxy(rect2);
- QCOMPARE(rect->focusProxy(), (QGraphicsItem *)rect2);
+ QCOMPARE(rect->focusProxy(), rect2);
scene->addItem(rect);
scene->addItem(rect2);
rect->setFocusProxy(rect2);
@@ -8673,7 +8727,7 @@ void tst_QGraphicsItem::setGraphicsEffect()
// Ensure the existing effect is uninstalled and deleted when setting a null effect
blurEffect = new QGraphicsBlurEffect;
item->setGraphicsEffect(blurEffect);
- item->setGraphicsEffect(0);
+ item->setGraphicsEffect(nullptr);
QVERIFY(!item->graphicsEffect());
QVERIFY(!blurEffect);
@@ -8733,11 +8787,11 @@ void tst_QGraphicsItem::panel()
QEvent activate(QEvent::WindowActivate);
QEvent deactivate(QEvent::WindowDeactivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
// No previous activation, so the scene is active.
QVERIFY(scene.isActive());
- QCOMPARE(scene.activePanel(), (QGraphicsItem *)panel1);
+ QCOMPARE(scene.activePanel(), panel1);
QVERIFY(panel1->isActive());
QVERIFY(!panel2->isActive());
QVERIFY(!panel3->isActive());
@@ -8752,7 +8806,7 @@ void tst_QGraphicsItem::panel()
QCOMPARE(spy_activate_panel4.count(), 0);
// Switch back to scene.
- scene.setActivePanel(0);
+ scene.setActivePanel(nullptr);
QVERIFY(!scene.activePanel());
QVERIFY(!panel1->isActive());
QVERIFY(!panel2->isActive());
@@ -8764,7 +8818,7 @@ void tst_QGraphicsItem::panel()
QCOMPARE(spy_activate_notPanel2.count(), 1);
// Deactivate the scene
- QApplication::sendEvent(&scene, &deactivate);
+ QCoreApplication::sendEvent(&scene, &deactivate);
QVERIFY(!scene.activePanel());
QVERIFY(!panel1->isActive());
QVERIFY(!panel2->isActive());
@@ -8776,7 +8830,7 @@ void tst_QGraphicsItem::panel()
QCOMPARE(spy_deactivate_notPanel2.count(), 1);
// Reactivate the scene
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QVERIFY(!scene.activePanel());
QVERIFY(!panel1->isActive());
QVERIFY(!panel2->isActive());
@@ -8795,23 +8849,23 @@ void tst_QGraphicsItem::panel()
QCOMPARE(spy_activate_panel1.count(), 2);
// Deactivate the scene
- QApplication::sendEvent(&scene, &deactivate);
+ QCoreApplication::sendEvent(&scene, &deactivate);
QVERIFY(!panel1->isActive());
QCOMPARE(spy_deactivate_panel1.count(), 2);
// Reactivate the scene
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QVERIFY(panel1->isActive());
QCOMPARE(spy_activate_panel1.count(), 3);
// Deactivate the scene
- QApplication::sendEvent(&scene, &deactivate);
+ QCoreApplication::sendEvent(&scene, &deactivate);
QVERIFY(!panel1->isActive());
QVERIFY(!scene.activePanel());
- scene.setActivePanel(0);
+ scene.setActivePanel(nullptr);
// Reactivate the scene
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QVERIFY(!panel1->isActive());
}
@@ -8821,12 +8875,18 @@ void tst_QGraphicsItem::panelWithFocusItems()
{
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
bool widget = (i == 1);
- QGraphicsItem *parentPanel = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem;
- QGraphicsItem *parentPanelFocusItem = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem;
- QGraphicsItem *parentPanelFocusItemSibling = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem;
+ auto parentPanel = widget
+ ? static_cast<QGraphicsItem *>(new QGraphicsWidget)
+ : static_cast<QGraphicsItem *>(new QGraphicsRectItem);
+ auto parentPanelFocusItem = widget
+ ? static_cast<QGraphicsItem *>(new QGraphicsWidget)
+ : static_cast<QGraphicsItem *>(new QGraphicsRectItem);
+ auto parentPanelFocusItemSibling = widget
+ ? static_cast<QGraphicsItem *>(new QGraphicsWidget)
+ : static_cast<QGraphicsItem *>(new QGraphicsRectItem);
parentPanel->setFlag(QGraphicsItem::ItemIsPanel);
parentPanelFocusItem->setFlag(QGraphicsItem::ItemIsFocusable);
parentPanelFocusItemSibling->setFlag(QGraphicsItem::ItemIsFocusable);
@@ -8841,21 +8901,28 @@ void tst_QGraphicsItem::panelWithFocusItems()
QVERIFY(parentPanel->isActive());
QVERIFY(parentPanelFocusItem->hasFocus());
- QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
- QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
-
- QGraphicsItem *childPanel = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem;
- QGraphicsItem *childPanelFocusItem = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem;
- QGraphicsItem *grandChildPanelFocusItem = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem;
- QGraphicsItem *grandChildPanelFocusItem2 = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem;
+ QCOMPARE(parentPanel->focusItem(), parentPanelFocusItem);
+ QCOMPARE(parentPanelFocusItem->focusItem(), parentPanelFocusItem);
+
+ auto childPanel = widget
+ ? static_cast<QGraphicsItem *>(new QGraphicsWidget)
+ : static_cast<QGraphicsItem *>(new QGraphicsRectItem);
+ auto childPanelFocusItem = widget
+ ? static_cast<QGraphicsItem *>(new QGraphicsWidget)
+ : static_cast<QGraphicsItem *>(new QGraphicsRectItem);
+ auto grandChildPanelFocusItem = widget
+ ? static_cast<QGraphicsItem *>(new QGraphicsWidget)
+ : static_cast<QGraphicsItem *>(new QGraphicsRectItem);
+ auto grandChildPanelFocusItem2 = widget
+ ? static_cast<QGraphicsItem *>(new QGraphicsWidget)
+ : static_cast<QGraphicsItem *>(new QGraphicsRectItem);
childPanel->setFlag(QGraphicsItem::ItemIsPanel);
childPanelFocusItem->setFlag(QGraphicsItem::ItemIsFocusable);
grandChildPanelFocusItem->setFlag(QGraphicsItem::ItemIsFocusable);
grandChildPanelFocusItem2->setFlag(QGraphicsItem::ItemIsFocusable);
- if (widget)
- {
+ if (widget) {
static_cast<QGraphicsWidget *>(childPanelFocusItem)->setFocusPolicy(Qt::StrongFocus);
static_cast<QGraphicsWidget *>(grandChildPanelFocusItem)->setFocusPolicy(Qt::StrongFocus);
static_cast<QGraphicsWidget *>(grandChildPanelFocusItem2)->setFocusPolicy(Qt::StrongFocus);
@@ -8866,45 +8933,45 @@ void tst_QGraphicsItem::panelWithFocusItems()
grandChildPanelFocusItem->setFocus();
QVERIFY(!grandChildPanelFocusItem->hasFocus());
- QCOMPARE(childPanel->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
- QCOMPARE(childPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
- QCOMPARE(grandChildPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
+ QCOMPARE(childPanel->focusItem(), grandChildPanelFocusItem);
+ QCOMPARE(childPanelFocusItem->focusItem(), grandChildPanelFocusItem);
+ QCOMPARE(grandChildPanelFocusItem->focusItem(), grandChildPanelFocusItem);
childPanel->setParentItem(parentPanel);
QVERIFY(!parentPanel->isActive());
QVERIFY(!parentPanelFocusItem->hasFocus());
- QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
- QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
+ QCOMPARE(parentPanel->focusItem(), parentPanelFocusItem);
+ QCOMPARE(parentPanelFocusItem->focusItem(), parentPanelFocusItem);
QVERIFY(childPanel->isActive());
QVERIFY(!childPanelFocusItem->hasFocus());
QVERIFY(grandChildPanelFocusItem->hasFocus());
- QCOMPARE(childPanel->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
- QCOMPARE(childPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
+ QCOMPARE(childPanel->focusItem(), grandChildPanelFocusItem);
+ QCOMPARE(childPanelFocusItem->focusItem(), grandChildPanelFocusItem);
childPanel->hide();
- QCOMPARE(childPanel->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
+ QCOMPARE(childPanel->focusItem(), grandChildPanelFocusItem);
QVERIFY(!childPanel->focusItem()->hasFocus());
QVERIFY(parentPanel->isActive());
QVERIFY(parentPanelFocusItem->hasFocus());
- QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
- QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
- QCOMPARE(grandChildPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
+ QCOMPARE(parentPanel->focusItem(), parentPanelFocusItem);
+ QCOMPARE(parentPanelFocusItem->focusItem(), parentPanelFocusItem);
+ QCOMPARE(grandChildPanelFocusItem->focusItem(), grandChildPanelFocusItem);
childPanel->show();
QVERIFY(childPanel->isActive());
QVERIFY(grandChildPanelFocusItem->hasFocus());
- QCOMPARE(childPanel->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
- QCOMPARE(childPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
- QCOMPARE(grandChildPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem);
+ QCOMPARE(childPanel->focusItem(), grandChildPanelFocusItem);
+ QCOMPARE(childPanelFocusItem->focusItem(), grandChildPanelFocusItem);
+ QCOMPARE(grandChildPanelFocusItem->focusItem(), grandChildPanelFocusItem);
childPanel->hide();
QVERIFY(parentPanel->isActive());
QVERIFY(parentPanelFocusItem->hasFocus());
- QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
- QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem);
+ QCOMPARE(parentPanel->focusItem(), parentPanelFocusItem);
+ QCOMPARE(parentPanelFocusItem->focusItem(), parentPanelFocusItem);
}
}
@@ -8921,7 +8988,7 @@ void tst_QGraphicsItem::addPanelToActiveScene()
QEvent activate(QEvent::WindowActivate);
QEvent deactivate(QEvent::WindowDeactivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QVERIFY(scene.isActive());
scene.addItem(rect);
QVERIFY(rect->isActive());
@@ -8930,12 +8997,12 @@ void tst_QGraphicsItem::addPanelToActiveScene()
rect->setFlag(QGraphicsItem::ItemIsPanel);
scene.addItem(rect);
QVERIFY(rect->isActive());
- QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect);
+ QCOMPARE(scene.activePanel(), rect);
QGraphicsRectItem *rect2 = new QGraphicsRectItem;
scene.addItem(rect2);
QVERIFY(rect->isActive());
- QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect);
+ QCOMPARE(scene.activePanel(), rect);
}
void tst_QGraphicsItem::activate()
@@ -8947,7 +9014,7 @@ void tst_QGraphicsItem::activate()
QEvent activate(QEvent::WindowActivate);
QEvent deactivate(QEvent::WindowDeactivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
// Non-panel item (active when scene is active).
QVERIFY(rect->isActive());
@@ -8993,14 +9060,14 @@ void tst_QGraphicsItem::activate()
QGraphicsRectItem *rect5 = new QGraphicsRectItem(rect4);
QGraphicsRectItem *rect6 = new QGraphicsRectItem(rect5);
scene.addItem(rect4);
- QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect3);
+ QCOMPARE(scene.activePanel(), rect3);
scene.removeItem(rect4);
rect6->setActive(true);
scene.addItem(rect4);
QVERIFY(rect4->isActive());
QVERIFY(rect5->isActive());
QVERIFY(rect6->isActive());
- QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect4);
+ QCOMPARE(scene.activePanel(), rect4);
scene.removeItem(rect4); // no active panel
rect6->setActive(false);
scene.addItem(rect4);
@@ -9011,11 +9078,11 @@ void tst_QGraphicsItem::activate()
// Controlling auto-activation when the scene changes activation.
rect4->setActive(true);
- QApplication::sendEvent(&scene, &deactivate);
+ QCoreApplication::sendEvent(&scene, &deactivate);
QVERIFY(!scene.isActive());
QVERIFY(!rect4->isActive());
rect4->setActive(false);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QVERIFY(scene.isActive());
QVERIFY(!scene.activePanel());
QVERIFY(!rect4->isActive());
@@ -9047,7 +9114,7 @@ void tst_QGraphicsItem::activationOnShowHide()
{
QGraphicsScene scene;
QEvent activate(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &activate);
+ QCoreApplication::sendEvent(&scene, &activate);
QGraphicsRectItem *rootPanel = scene.addRect(QRectF());
rootPanel->setFlag(QGraphicsItem::ItemIsPanel);
@@ -9109,18 +9176,19 @@ void tst_QGraphicsItem::activationOnShowHide()
class MoveWhileDying : public QGraphicsRectItem
{
public:
- MoveWhileDying(QGraphicsItem *parent = 0)
- : QGraphicsRectItem(parent)
- { }
+ using QGraphicsRectItem::QGraphicsRectItem;
+
~MoveWhileDying()
{
- foreach (QGraphicsItem *c, childItems()) {
- foreach (QGraphicsItem *cc, c->childItems()) {
+ const auto children = childItems();
+ for (QGraphicsItem *c : children) {
+ const auto grandChildren = c->childItems();
+ for (QGraphicsItem *cc : grandChildren)
cc->moveBy(10, 10);
- }
c->moveBy(10, 10);
}
- if (QGraphicsItem *p = parentItem()) { p->moveBy(10, 10); }
+ if (QGraphicsItem *p = parentItem())
+ p->moveBy(10, 10);
}
};
@@ -9134,7 +9202,7 @@ void tst_QGraphicsItem::deactivateInactivePanel()
panel2->setFlag(QGraphicsItem::ItemIsPanel);
QEvent event(QEvent::WindowActivate);
- qApp->sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
panel1->setActive(true);
QVERIFY(scene.isActive());
@@ -9172,6 +9240,7 @@ void tst_QGraphicsItem::moveWhileDeleting()
child = new QGraphicsRectItem(silly);
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -9200,12 +9269,9 @@ class MyRectItem : public QGraphicsWidget
{
Q_OBJECT
public:
- MyRectItem(QGraphicsItem *parent = 0) : QGraphicsWidget(parent)
- {
+ using QGraphicsWidget::QGraphicsWidget;
- }
-
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{
painter->setBrush(brush);
painter->drawRect(boundingRect());
@@ -9216,7 +9282,7 @@ public:
topLevel->collidingItems(Qt::IntersectsItemBoundingRect);
}
public:
- QGraphicsItem *topLevel;
+ QGraphicsItem *topLevel = nullptr;
QBrush brush;
};
@@ -9258,6 +9324,7 @@ void tst_QGraphicsItem::ensureDirtySceneTransform()
child3->brush = QBrush(QColor(Qt::gray));
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -9292,7 +9359,7 @@ void tst_QGraphicsItem::focusScope()
scope3->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope);
scope3->setFocus();
QVERIFY(!scope3->focusScopeItem());
- QCOMPARE(scope3->focusItem(), (QGraphicsItem *)scope3);
+ QCOMPARE(scope3->focusItem(), scope3);
QGraphicsRectItem *scope2 = new QGraphicsRectItem;
scope2->setData(0, "scope2");
@@ -9300,8 +9367,8 @@ void tst_QGraphicsItem::focusScope()
scope2->setFocus();
QVERIFY(!scope2->focusScopeItem());
scope3->setParentItem(scope2);
- QCOMPARE(scope2->focusScopeItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope3);
+ QCOMPARE(scope2->focusScopeItem(), scope3);
+ QCOMPARE(scope2->focusItem(), scope3);
QGraphicsRectItem *scope1 = new QGraphicsRectItem;
scope1->setData(0, "scope1");
@@ -9310,11 +9377,11 @@ void tst_QGraphicsItem::focusScope()
QVERIFY(!scope1->focusScopeItem());
scope2->setParentItem(scope1);
- QCOMPARE(scope1->focusItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope3->focusItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope1->focusScopeItem(), (QGraphicsItem *)scope2);
- QCOMPARE(scope2->focusScopeItem(), (QGraphicsItem *)scope3);
+ QCOMPARE(scope1->focusItem(), scope3);
+ QCOMPARE(scope2->focusItem(), scope3);
+ QCOMPARE(scope3->focusItem(), scope3);
+ QCOMPARE(scope1->focusScopeItem(), scope2);
+ QCOMPARE(scope2->focusScopeItem(), scope3);
QCOMPARE(scope3->focusScopeItem(), nullptr);
scene.addItem(scope1);
@@ -9323,11 +9390,11 @@ void tst_QGraphicsItem::focusScope()
qApp->sendEvent(&scene, &windowActivate);
scene.setFocus();
- QCOMPARE(scope1->focusItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope3->focusItem(), (QGraphicsItem *)scope3);
- QCOMPARE(scope1->focusScopeItem(), (QGraphicsItem *)scope2);
- QCOMPARE(scope2->focusScopeItem(), (QGraphicsItem *)scope3);
+ QCOMPARE(scope1->focusItem(), scope3);
+ QCOMPARE(scope2->focusItem(), scope3);
+ QCOMPARE(scope3->focusItem(), scope3);
+ QCOMPARE(scope1->focusScopeItem(), scope2);
+ QCOMPARE(scope2->focusScopeItem(), scope3);
QCOMPARE(scope3->focusScopeItem(), nullptr);
QVERIFY(scope3->hasFocus());
@@ -9405,10 +9472,10 @@ void tst_QGraphicsItem::focusScope()
rect5->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope);
rect5->setFocus();
rect5->setParentItem(rect4);
- QCOMPARE(scope3->focusScopeItem(), (QGraphicsItem *)rect5);
+ QCOMPARE(scope3->focusScopeItem(), rect5);
QVERIFY(rect5->hasFocus());
- rect4->setParentItem(0);
+ rect4->setParentItem(nullptr);
QVERIFY(rect5->hasFocus());
QCOMPARE(scope3->focusScopeItem(), nullptr);
QCOMPARE(scope3->focusItem(), nullptr);
@@ -9428,7 +9495,7 @@ void tst_QGraphicsItem::focusScope()
scopeA->setFocus();
QVERIFY(scopeB->hasFocus());
- QCOMPARE(scopeB->focusItem(), (QGraphicsItem *)scopeB);
+ QCOMPARE(scopeB->focusItem(), scopeB);
}
void tst_QGraphicsItem::focusScope2()
@@ -9436,7 +9503,7 @@ void tst_QGraphicsItem::focusScope2()
QGraphicsRectItem *child1 = new QGraphicsRectItem;
child1->setFlags(QGraphicsItem::ItemIsFocusable);
child1->setFocus();
- QCOMPARE(child1->focusItem(), (QGraphicsItem *)child1);
+ QCOMPARE(child1->focusItem(), child1);
QGraphicsRectItem *child2 = new QGraphicsRectItem;
child2->setFlags(QGraphicsItem::ItemIsFocusable);
@@ -9444,13 +9511,13 @@ void tst_QGraphicsItem::focusScope2()
QGraphicsRectItem *rootFocusScope = new QGraphicsRectItem;
rootFocusScope->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope);
rootFocusScope->setFocus();
- QCOMPARE(rootFocusScope->focusItem(), (QGraphicsItem *)rootFocusScope);
+ QCOMPARE(rootFocusScope->focusItem(), rootFocusScope);
child1->setParentItem(rootFocusScope);
child2->setParentItem(rootFocusScope);
- QCOMPARE(rootFocusScope->focusScopeItem(), (QGraphicsItem *)child1);
- QCOMPARE(rootFocusScope->focusItem(), (QGraphicsItem *)child1);
+ QCOMPARE(rootFocusScope->focusScopeItem(), child1);
+ QCOMPARE(rootFocusScope->focusItem(), child1);
QGraphicsRectItem *siblingChild1 = new QGraphicsRectItem;
siblingChild1->setFlags(QGraphicsItem::ItemIsFocusable);
@@ -9465,14 +9532,14 @@ void tst_QGraphicsItem::focusScope2()
siblingChild1->setParentItem(siblingFocusScope);
siblingChild2->setParentItem(siblingFocusScope);
- QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild1);
+ QCOMPARE(siblingFocusScope->focusScopeItem(), siblingChild1);
QCOMPARE(siblingFocusScope->focusItem(), nullptr);
QGraphicsItem *root = new QGraphicsRectItem;
rootFocusScope->setParentItem(root);
siblingFocusScope->setParentItem(root);
- QCOMPARE(root->focusItem(), (QGraphicsItem *)child1);
+ QCOMPARE(root->focusItem(), child1);
QGraphicsScene scene;
scene.addItem(root);
@@ -9481,7 +9548,7 @@ void tst_QGraphicsItem::focusScope2()
qApp->sendEvent(&scene, &activate);
scene.setFocus();
- QCOMPARE(scene.focusItem(), (QGraphicsItem *)child1);
+ QCOMPARE(scene.focusItem(), child1);
// You cannot set focus on a descendant of a focus scope directly;
// this will only change the scope's focus scope item pointer. If
@@ -9490,15 +9557,15 @@ void tst_QGraphicsItem::focusScope2()
siblingChild2->setFocus();
QVERIFY(!siblingChild2->hasFocus());
QVERIFY(!siblingChild2->focusItem());
- QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild2);
+ QCOMPARE(siblingFocusScope->focusScopeItem(), siblingChild2);
QCOMPARE(siblingFocusScope->focusItem(), nullptr);
// Set focus on the scope; focus is forwarded to the focus scope item.
siblingFocusScope->setFocus();
QVERIFY(siblingChild2->hasFocus());
QVERIFY(siblingChild2->focusItem());
- QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild2);
- QCOMPARE(siblingFocusScope->focusItem(), (QGraphicsItem *)siblingChild2);
+ QCOMPARE(siblingFocusScope->focusScopeItem(), siblingChild2);
+ QCOMPARE(siblingFocusScope->focusItem(), siblingChild2);
}
class FocusScopeItemPrivate;
@@ -9506,11 +9573,11 @@ class FocusScopeItem : public QGraphicsItem
{
Q_DECLARE_PRIVATE(FocusScopeItem)
public:
- FocusScopeItem(QGraphicsItem *parent = 0);
- QRectF boundingRect() const { return QRectF(); }
- void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) { }
+ FocusScopeItem(QGraphicsItem *parent = nullptr);
+ QRectF boundingRect() const override { return QRectF(); }
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override { }
- int focusScopeChanged;
+ int focusScopeChanged = 0;
FocusScopeItemPrivate *d_ptr;
};
@@ -9518,12 +9585,12 @@ class FocusScopeItemPrivate : QGraphicsItemPrivate
{
Q_DECLARE_PUBLIC(FocusScopeItem)
public:
- void focusScopeItemChange(bool)
+ void focusScopeItemChange(bool) override
{ ++q_func()->focusScopeChanged; }
};
FocusScopeItem::FocusScopeItem(QGraphicsItem *parent)
- : QGraphicsItem(*new FocusScopeItemPrivate, parent), focusScopeChanged(0)
+ : QGraphicsItem(*new FocusScopeItemPrivate, parent)
{
setFlag(ItemIsFocusable);
}
@@ -9540,15 +9607,15 @@ void tst_QGraphicsItem::focusScopeItemChangedWhileScopeDoesntHaveFocus()
QCOMPARE(child1->focusScopeChanged, 0);
QCOMPARE(child2->focusScopeChanged, 0);
child1->setFocus();
- QCOMPARE(rect.focusScopeItem(), (QGraphicsItem *)child1);
+ QCOMPARE(rect.focusScopeItem(), child1);
QCOMPARE(child1->focusScopeChanged, 1);
QCOMPARE(child2->focusScopeChanged, 0);
child2->setFocus();
- QCOMPARE(rect.focusScopeItem(), (QGraphicsItem *)child2);
+ QCOMPARE(rect.focusScopeItem(), child2);
QCOMPARE(child1->focusScopeChanged, 2);
QCOMPARE(child2->focusScopeChanged, 1);
child1->setFocus();
- QCOMPARE(rect.focusScopeItem(), (QGraphicsItem *)child1);
+ QCOMPARE(rect.focusScopeItem(), child1);
QCOMPARE(child1->focusScopeChanged, 3);
QCOMPARE(child2->focusScopeChanged, 2);
child1->clearFocus();
@@ -9564,75 +9631,81 @@ void tst_QGraphicsItem::stackBefore()
QGraphicsRectItem *child2 = new QGraphicsRectItem(QRectF(0, 0, 5, 5), &parent);
QGraphicsRectItem *child3 = new QGraphicsRectItem(QRectF(0, 0, 5, 5), &parent);
QGraphicsRectItem *child4 = new QGraphicsRectItem(QRectF(0, 0, 5, 5), &parent);
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ const GraphicsItemsList expected1234{child1, child2, child3, child4};
+ QCOMPARE(parent.childItems(), expected1234);
child1->setData(0, "child1");
child2->setData(0, "child2");
child3->setData(0, "child3");
child4->setData(0, "child4");
// Remove and append
- child2->setParentItem(0);
+ child2->setParentItem(nullptr);
child2->setParentItem(&parent);
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child3 << child4 << child2));
+ const GraphicsItemsList expected1342{child1, child3, child4, child2};
+ QCOMPARE(parent.childItems(), expected1342);
// Move child2 before child1
child2->stackBefore(child1); // 2134
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
+ const GraphicsItemsList expected2134{child2, child1, child3, child4};
+ QCOMPARE(parent.childItems(), expected2134);
child2->stackBefore(child2); // 2134
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
+ QCOMPARE(parent.childItems(), expected2134);
child1->setZValue(1); // 2341
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1));
+ const GraphicsItemsList expected2341{child2, child3, child4, child1};
+ QCOMPARE(parent.childItems(), expected2341);
child1->stackBefore(child2); // 2341
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1));
+ QCOMPARE(parent.childItems(), expected2341);
child1->setZValue(0); // 1234
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ QCOMPARE(parent.childItems(), expected1234);
child4->stackBefore(child1); // 4123
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child4 << child1 << child2 << child3));
+ const GraphicsItemsList expected4123{child4, child1, child2, child3};
+ QCOMPARE(parent.childItems(), expected4123);
child4->setZValue(1); // 1234 (4123)
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ QCOMPARE(parent.childItems(), expected1234);
child3->stackBefore(child1); // 3124 (4312)
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child3 << child1 << child2 << child4));
+ const GraphicsItemsList expected3124{child3, child1, child2, child4};
+ QCOMPARE(parent.childItems(), expected3124);
child4->setZValue(0); // 4312
- QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child4 << child3 << child1 << child2));
+ const GraphicsItemsList expected4312{child4, child3, child1, child2};
+ QCOMPARE(parent.childItems(), expected4312);
// Make them all toplevels
- child1->setParentItem(0);
- child2->setParentItem(0);
- child3->setParentItem(0);
- child4->setParentItem(0);
+ child1->setParentItem(nullptr);
+ child2->setParentItem(nullptr);
+ child3->setParentItem(nullptr);
+ child4->setParentItem(nullptr);
QGraphicsScene scene;
scene.addItem(child1);
scene.addItem(child2);
scene.addItem(child3);
scene.addItem(child4);
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder),
- (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected1234);
// Remove and append
scene.removeItem(child2);
scene.addItem(child2);
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child3 << child4 << child2));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected1342);
// Move child2 before child1
child2->stackBefore(child1); // 2134
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected2134);
child2->stackBefore(child2); // 2134
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected2134);
child1->setZValue(1); // 2341
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected2341);
child1->stackBefore(child2); // 2341
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected2341);
child1->setZValue(0); // 1234
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected1234);
child4->stackBefore(child1); // 4123
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child4 << child1 << child2 << child3));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected4123);
child4->setZValue(1); // 1234 (4123)
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected1234);
child3->stackBefore(child1); // 3124 (4312)
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child3 << child1 << child2 << child4));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected3124);
child4->setZValue(0); // 4312
- QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child4 << child3 << child1 << child2));
+ QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected4312);
}
void tst_QGraphicsItem::QTBUG_4233_updateCachedWithSceneRect()
@@ -9645,24 +9718,25 @@ void tst_QGraphicsItem::QTBUG_4233_updateCachedWithSceneRect()
scene.setSceneRect(-100, -100, 200, 200); // contains the tester item
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
- QCOMPARE(QApplication::activeWindow(), (QWidget *)&view);
+ QCOMPARE(QApplication::activeWindow(), &view);
QTRY_COMPARE(tester->repaints, 1);
scene.update(); // triggers "updateAll" optimization
- qApp->processEvents();
- qApp->processEvents(); // in 4.6 only one processEvents is necessary
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents(); // in 4.6 only one processEvents is necessary
QCOMPARE(tester->repaints, 1);
scene.update(); // triggers "updateAll" optimization
tester->update();
- qApp->processEvents();
- qApp->processEvents(); // in 4.6 only one processEvents is necessary
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents(); // in 4.6 only one processEvents is necessary
QCOMPARE(tester->repaints, 2);
}
@@ -10203,7 +10277,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0);
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(scene.mouseGrabberItem(), rect1);
// grab lost when rect1 is modally shadowed
rect2->setPanelModality(QGraphicsItem::SceneModal);
@@ -10243,7 +10317,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1);
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1);
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(scene.mouseGrabberItem(), rect1);
// grab lost to rect2 when rect1 is modally shadowed
rect2->setPanelModality(QGraphicsItem::SceneModal);
@@ -10283,7 +10357,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0);
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0);
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(scene.mouseGrabberItem(), rect1);
// grab lost when rect1 is modally shadowed
rect2->setPanelModality(QGraphicsItem::PanelModal);
@@ -10323,7 +10397,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1);
QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1);
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(scene.mouseGrabberItem(), rect1);
// grab lost to rect2 when rect1 is modally shadowed
rect2->setPanelModality(QGraphicsItem::PanelModal);
@@ -10375,7 +10449,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 1);
QCOMPARE(rect3Spy.counts[QEvent::GraphicsSceneMousePress], 1);
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 0);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+ QCOMPARE(scene.mouseGrabberItem(), rect3);
// grab is *not* lost when rect1 is modally shadowed by rect2
rect2->setPanelModality(QGraphicsItem::PanelModal);
@@ -10385,7 +10459,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 1);
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 0);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+ QCOMPARE(scene.mouseGrabberItem(), rect3);
// releasing goes to rect3
sendMouseRelease(&scene, QPoint(150, 50));
@@ -10408,7 +10482,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2);
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+ QCOMPARE(scene.mouseGrabberItem(), rect3);
// grab is not lost
rect2->setPanelModality(QGraphicsItem::PanelModal);
@@ -10418,7 +10492,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2);
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+ QCOMPARE(scene.mouseGrabberItem(), rect3);
// grab stays on rect3
rect2->setPanelModality(QGraphicsItem::NonModal);
@@ -10428,7 +10502,7 @@ void tst_QGraphicsItem::modality_mouseGrabber()
QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0);
QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2);
QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1);
- QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3);
+ QCOMPARE(scene.mouseGrabberItem(), rect3);
// release goes to rect3
sendMouseRelease(&scene, QPoint(150, 50));
@@ -10458,18 +10532,18 @@ void tst_QGraphicsItem::modality_clickFocus()
rect2->setData(0, "rect2");
QEvent windowActivateEvent(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &windowActivateEvent);
+ QCoreApplication::sendEvent(&scene, &windowActivateEvent);
EventSpy2 rect1Spy(&scene, rect1);
EventSpy2 rect2Spy(&scene, rect2);
// activate rect1, it should get focus
rect1->setActive(true);
- QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(scene.focusItem(), rect1);
// focus stays when rect2 becomes modal
rect2->setPanelModality(QGraphicsItem::SceneModal);
- QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(scene.focusItem(), rect1);
QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1);
QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0);
QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 0);
@@ -10487,7 +10561,7 @@ void tst_QGraphicsItem::modality_clickFocus()
// clicking on rect2 gives it focus
rect2->setActive(true);
sendMouseClick(&scene, QPointF(75, 75));
- QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect2);
+ QCOMPARE(scene.focusItem(), rect2);
QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1);
QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 1);
QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1);
@@ -10513,7 +10587,7 @@ void tst_QGraphicsItem::modality_clickFocus()
// click on rect1, it should get focus now
sendMouseClick(&scene, QPointF(-25, -25));
- QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1);
+ QCOMPARE(scene.focusItem(), rect1);
QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 3);
QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 2);
QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1);
@@ -10546,7 +10620,7 @@ void tst_QGraphicsItem::modality_keyEvents()
rect2child->setData(0, "rect2child1");
QEvent windowActivateEvent(QEvent::WindowActivate);
- QApplication::sendEvent(&scene, &windowActivateEvent);
+ QCoreApplication::sendEvent(&scene, &windowActivateEvent);
EventSpy2 rect1Spy(&scene, rect1);
EventSpy2 rect1childSpy(&scene, rect1child);
@@ -10556,11 +10630,11 @@ void tst_QGraphicsItem::modality_keyEvents()
// activate rect1 and give it rect1child focus
rect1->setActive(true);
rect1child->setFocus();
- QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child);
+ QCOMPARE(scene.focusItem(), rect1child);
// focus stays on rect1child when rect2 becomes modal
rect2->setPanelModality(QGraphicsItem::SceneModal);
- QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child);
+ QCOMPARE(scene.focusItem(), rect1child);
// but key events to rect1child should be neither delivered nor propagated
sendKeyClick(&scene, Qt::Key_A);
@@ -10574,7 +10648,7 @@ void tst_QGraphicsItem::modality_keyEvents()
// change to panel modality, rect1child1 keeps focus
rect2->setPanelModality(QGraphicsItem::PanelModal);
- QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child);
+ QCOMPARE(scene.focusItem(), rect1child);
// still no key events
sendKeyClick(&scene, Qt::Key_J);
@@ -10629,14 +10703,7 @@ void tst_QGraphicsItem::itemIsInFront()
QCOMPARE(qt_closestItemFirst(rect1child1_2, rect2child1), false);
}
-class ScenePosChangeTester : public ItemChangeTester
-{
-public:
- ScenePosChangeTester()
- { }
- ScenePosChangeTester(QGraphicsItem *parent) : ItemChangeTester(parent)
- { }
-};
+using ScenePosChangeTester = ItemChangeTester;
void tst_QGraphicsItem::scenePosChange()
{
@@ -10695,7 +10762,7 @@ void tst_QGraphicsItem::scenePosChange()
// remove
scene.removeItem(grandChild1.data());
- delete grandChild2; grandChild2 = 0;
+ delete grandChild2; grandChild2 = nullptr;
QCoreApplication::processEvents(); // QGraphicsScenePrivate::_q_updateScenePosDescendants()
root->moveBy(1.0, 1.0);
QCOMPARE(child1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 4);
@@ -10716,13 +10783,13 @@ void tst_QGraphicsItem::scenePosChange()
void tst_QGraphicsItem::textItem_shortcuts()
{
QWidget w;
- QVBoxLayout l;
- w.setLayout(&l);
+ w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
+ auto l = new QVBoxLayout(&w);
QGraphicsScene scene;
QGraphicsView view(&scene);
- l.addWidget(&view);
+ l->addWidget(&view);
QPushButton b("Push Me");
- l.addWidget(&b);
+ l->addWidget(&b);
QGraphicsTextItem *item = scene.addText("Troll Text");
item->setFlag(QGraphicsItem::ItemIsFocusable);
@@ -10776,6 +10843,7 @@ void tst_QGraphicsItem::scroll()
scene.addItem(item2);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.setFrameStyle(0);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -10859,7 +10927,7 @@ void tst_QGraphicsItem::focusHandling()
{
public:
MyItem() : QGraphicsRectItem(0, 0, 100, 100) {}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{
painter->fillRect(boundingRect(), hasFocus() ? QBrush(Qt::red) : brush());
}
@@ -10924,6 +10992,8 @@ void tst_QGraphicsItem::focusHandling()
class TouchEventTestee : public QGraphicsRectItem
{
public:
+ using TouchPoints = QVector<QTouchEvent::TouchPoint>;
+
TouchEventTestee(const QSizeF &size = QSizeF(100, 100)) :
QGraphicsRectItem(QRectF(QPointF(), size))
{
@@ -10931,10 +11001,10 @@ public:
setFlag(QGraphicsItem::ItemIsFocusable, false);
}
- QList<QTouchEvent::TouchPoint> touchBeginPoints() const { return m_touchBeginPoints; }
+ TouchPoints touchBeginPoints() const { return m_touchBeginPoints; }
int touchBeginEventCount() const { return m_touchBeginPoints.size(); }
- QList<QTouchEvent::TouchPoint> touchUpdatePoints() const { return m_touchUpdatePoints; }
+ TouchPoints touchUpdatePoints() const { return m_touchUpdatePoints; }
int touchUpdateEventCount() const { return m_touchUpdatePoints.size(); }
protected:
@@ -10957,8 +11027,8 @@ protected:
}
private:
- QList<QTouchEvent::TouchPoint> m_touchBeginPoints;
- QList<QTouchEvent::TouchPoint> m_touchUpdatePoints;
+ TouchPoints m_touchBeginPoints;
+ TouchPoints m_touchUpdatePoints;
};
static QList<QTouchEvent::TouchPoint>
@@ -11157,6 +11227,7 @@ void tst_QGraphicsItem::deviceCoordinateCache_simpleRotations()
scene.addItem(item);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
QTRY_VERIFY(view.repaints > 0);
@@ -11224,7 +11295,7 @@ void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor()
struct Item : public QGraphicsTextItem
{
int painted;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid) override
{
painted++;
QGraphicsTextItem::paint(painter, opt, wid);
@@ -11237,6 +11308,7 @@ void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor()
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
scene.addItem(i);
@@ -11264,9 +11336,9 @@ void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor()
for (int x = 0; x < image.width(); ++x) {
// Because of antialiasing we allow a certain range of errors here.
QRgb pixel = image.pixel(x, y);
- if (qAbs((int)(pixel & 0xff) - (int)(rgb & 0xff)) +
- qAbs((int)((pixel & 0xff00) >> 8) - (int)((rgb & 0xff00) >> 8)) +
- qAbs((int)((pixel & 0xff0000) >> 16) - (int)((rgb & 0xff0000) >> 16)) <= 50) {
+ if (qAbs(int(pixel & 0xff) - int(rgb & 0xff)) +
+ qAbs(int((pixel & 0xff00) >> 8) - int((rgb & 0xff00) >> 8)) +
+ qAbs(int((pixel & 0xff0000) >> 16) - int((rgb & 0xff0000) >> 16)) <= 50) {
if (++numRedPixel >= 10) {
return;
}
@@ -11299,6 +11371,7 @@ void tst_QGraphicsItem::QTBUG_6738_missingUpdateWithSetParent()
scene.addItem(parent);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
view.show();
qApp->setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -11332,6 +11405,7 @@ void tst_QGraphicsItem::QT_2653_fullUpdateDiscardingOpacityUpdate()
{
QGraphicsScene scene(0, 0, 200, 200);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
EventTester *parentGreen = new EventTester();
parentGreen->setGeometry(QRectF(20, 20, 100, 100));
@@ -11373,6 +11447,7 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2()
{
QGraphicsScene scene(0, 0, 200, 200);
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
MyGraphicsView origView(&scene);
EventTester *parentGreen = new EventTester();
@@ -11423,26 +11498,26 @@ void tst_QGraphicsItem::QT_2649_focusScope()
QGraphicsRectItem *subFocusItem = new QGraphicsRectItem;
subFocusItem->setFlags(QGraphicsItem::ItemIsFocusable);
subFocusItem->setFocus();
- QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(subFocusItem->focusItem(), subFocusItem);
QGraphicsRectItem *scope = new QGraphicsRectItem;
scope->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope);
scope->setFocus();
subFocusItem->setParentItem(scope);
- QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(subFocusItem->focusItem(), subFocusItem);
QCOMPARE(subFocusItem->focusScopeItem(), nullptr);
- QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem);
- QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(scope->focusItem(), subFocusItem);
+ QCOMPARE(scope->focusScopeItem(), subFocusItem);
QGraphicsRectItem *rootItem = new QGraphicsRectItem;
rootItem->setFlags(QGraphicsItem::ItemIsFocusable);
scope->setParentItem(rootItem);
- QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(rootItem->focusItem(), subFocusItem);
QCOMPARE(rootItem->focusScopeItem(), nullptr);
- QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(subFocusItem->focusItem(), subFocusItem);
QCOMPARE(subFocusItem->focusScopeItem(), nullptr);
- QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem);
- QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(scope->focusItem(), subFocusItem);
+ QCOMPARE(scope->focusScopeItem(), subFocusItem);
scene->addItem(rootItem);
@@ -11450,11 +11525,11 @@ void tst_QGraphicsItem::QT_2649_focusScope()
qApp->sendEvent(scene, &windowActivate);
scene->setFocus();
- QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem);
- QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem);
- QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(rootItem->focusItem(), subFocusItem);
+ QCOMPARE(scope->focusItem(), subFocusItem);
+ QCOMPARE(subFocusItem->focusItem(), subFocusItem);
QCOMPARE(rootItem->focusScopeItem(), nullptr);
- QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(scope->focusScopeItem(), subFocusItem);
QCOMPARE(subFocusItem->focusScopeItem(), nullptr);
QVERIFY(subFocusItem->hasFocus());
@@ -11464,17 +11539,17 @@ void tst_QGraphicsItem::QT_2649_focusScope()
QCOMPARE(scope->focusItem(), nullptr);
QCOMPARE(subFocusItem->focusItem(), nullptr);
QCOMPARE(rootItem->focusScopeItem(), nullptr);
- QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(scope->focusScopeItem(), subFocusItem);
QCOMPARE(subFocusItem->focusScopeItem(), nullptr);
QVERIFY(!subFocusItem->hasFocus());
scope->show();
- QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem);
- QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem);
- QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(rootItem->focusItem(), subFocusItem);
+ QCOMPARE(scope->focusItem(), subFocusItem);
+ QCOMPARE(subFocusItem->focusItem(), subFocusItem);
QCOMPARE(rootItem->focusScopeItem(), nullptr);
- QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem);
+ QCOMPARE(scope->focusScopeItem(), subFocusItem);
QCOMPARE(subFocusItem->focusScopeItem(), nullptr);
QVERIFY(subFocusItem->hasFocus());
@@ -11486,16 +11561,14 @@ void tst_QGraphicsItem::QT_2649_focusScope()
class MyGraphicsItemWithItemChange : public QGraphicsWidget
{
public:
- MyGraphicsItemWithItemChange(QGraphicsItem *parent = 0) : QGraphicsWidget(parent)
- {}
+ using QGraphicsWidget::QGraphicsWidget;
- QVariant itemChange(GraphicsItemChange change, const QVariant &value)
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
{
if (change == QGraphicsItem::ItemSceneHasChanged) {
- foreach (QGraphicsView *view, scene()->views()) {
- //We trigger a sort of unindexed items in the BSP
+ const auto views = scene()->views();
+ for (QGraphicsView *view : views) // We trigger a sort of unindexed items in the BSP
view->sceneRect();
- }
}
return QGraphicsWidget::itemChange(change, value);
}
@@ -11520,8 +11593,8 @@ void tst_QGraphicsItem::doNotMarkFullUpdateIfNotInScene()
{
struct Item : public QGraphicsTextItem
{
- int painted;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid)
+ int painted = 0;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid) override
{
painted++;
QGraphicsTextItem::paint(painter, opt, wid);
@@ -11529,15 +11602,13 @@ void tst_QGraphicsItem::doNotMarkFullUpdateIfNotInScene()
};
QGraphicsScene scene;
MyGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
Item *item = new Item;
- item->painted = 0;
item->setPlainText("Grandparent");
Item *item2 = new Item;
item2->setPlainText("parent");
- item2->painted = 0;
Item *item3 = new Item;
item3->setPlainText("child");
- item3->painted = 0;
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect;
effect->setOpacity(0.5);
item2->setGraphicsEffect(effect);
@@ -11572,6 +11643,7 @@ void tst_QGraphicsItem::itemDiesDuringDraggingOperation()
{
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(0, 0, 100, 100));
item->setFlag(QGraphicsItem::ItemIsMovable);
item->setAcceptDrops(true);
@@ -11580,13 +11652,13 @@ void tst_QGraphicsItem::itemDiesDuringDraggingOperation()
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
- QCOMPARE(QApplication::activeWindow(), (QWidget *)&view);
+ QCOMPARE(QApplication::activeWindow(), &view);
QGraphicsSceneDragDropEvent dragEnter(QEvent::GraphicsSceneDragEnter);
dragEnter.setScenePos(item->boundingRect().center());
- QApplication::sendEvent(&scene, &dragEnter);
+ QCoreApplication::sendEvent(&scene, &dragEnter);
QGraphicsSceneDragDropEvent event(QEvent::GraphicsSceneDragMove);
event.setScenePos(item->boundingRect().center());
- QApplication::sendEvent(&scene, &event);
+ QCoreApplication::sendEvent(&scene, &event);
QCOMPARE(QGraphicsScenePrivate::get(&scene)->dragDropItem, item);
delete item;
QVERIFY(!QGraphicsScenePrivate::get(&scene)->dragDropItem);
@@ -11596,6 +11668,7 @@ void tst_QGraphicsItem::QTBUG_12112_focusItem()
{
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
QGraphicsRectItem *item1 = new QGraphicsRectItem(0, 0, 20, 20);
item1->setFlag(QGraphicsItem::ItemIsFocusable);
QGraphicsRectItem *item2 = new QGraphicsRectItem(20, 20, 20, 20);
@@ -11608,7 +11681,7 @@ void tst_QGraphicsItem::QTBUG_12112_focusItem()
QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
- QCOMPARE(QApplication::activeWindow(), (QWidget *)&view);
+ QCOMPARE(QApplication::activeWindow(), &view);
QVERIFY(item1->focusItem());
QVERIFY(!item2->focusItem());
@@ -11644,11 +11717,11 @@ void tst_QGraphicsItem::QTBUG_13473_sceneposchange()
QCOMPARE(child->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 2);
}
-class MyGraphicsWidget : public QGraphicsWidget {
-Q_OBJECT
+class MyGraphicsWidget : public QGraphicsWidget
+{
+ Q_OBJECT
public:
- MyGraphicsWidget()
- : QGraphicsWidget(0)
+ MyGraphicsWidget() : QGraphicsWidget(nullptr)
{
QGraphicsLinearLayout *lay = new QGraphicsLinearLayout(Qt::Vertical);
QLatin1String wiseWords("AZ BUKI VEDI");
@@ -11660,21 +11733,19 @@ public:
proxy->setWidget(label);
proxy->setFocusPolicy(Qt::StrongFocus);
proxy->setFlag(QGraphicsItem::ItemAcceptsInputMethod, true);
- if (i%2 == 0)
+ if (i % 2 == 0)
proxy->setVisible(false);
proxy->setFocus();
lay->addItem(proxy);
}
setLayout(lay);
}
-
};
class MyWidgetWindow : public QGraphicsWidget
{
public:
- MyWidgetWindow()
- : QGraphicsWidget(0, Qt::Window)
+ MyWidgetWindow() : QGraphicsWidget(nullptr, Qt::Window)
{
QGraphicsLinearLayout *lay = new QGraphicsLinearLayout(Qt::Vertical);
MyGraphicsWidget *widget = new MyGraphicsWidget();
@@ -11687,6 +11758,7 @@ void tst_QGraphicsItem::QTBUG_16374_crashInDestructor()
{
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
MyWidgetWindow win;
scene.addItem(&win);
@@ -11699,6 +11771,7 @@ void tst_QGraphicsItem::QTBUG_20699_focusScopeCrash()
{
QGraphicsScene scene;
QGraphicsView view(&scene);
+ view.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
QGraphicsPixmapItem fs;
fs.setFlags(QGraphicsItem::ItemIsFocusScope | QGraphicsItem::ItemIsFocusable);
scene.addItem(&fs);
diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
index 5ac3834aef..e21b1b889a 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
@@ -2610,11 +2610,6 @@ void tst_QGraphicsView::optimizationFlags()
QGraphicsView view;
QVERIFY(!view.optimizationFlags());
- view.setOptimizationFlag(QGraphicsView::DontClipPainter);
- QVERIFY(view.optimizationFlags() & QGraphicsView::DontClipPainter);
- view.setOptimizationFlag(QGraphicsView::DontClipPainter, false);
- QVERIFY(!view.optimizationFlags());
-
view.setOptimizationFlag(QGraphicsView::DontSavePainterState);
QVERIFY(view.optimizationFlags() & QGraphicsView::DontSavePainterState);
view.setOptimizationFlag(QGraphicsView::DontSavePainterState, false);
@@ -2625,10 +2620,8 @@ void tst_QGraphicsView::optimizationFlags()
view.setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing, false);
QVERIFY(!view.optimizationFlags());
- view.setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing
- | QGraphicsView::DontClipPainter);
- QCOMPARE(view.optimizationFlags(), QGraphicsView::OptimizationFlags(QGraphicsView::DontAdjustForAntialiasing
- | QGraphicsView::DontClipPainter));
+ view.setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing);
+ QCOMPARE(view.optimizationFlags(), QGraphicsView::OptimizationFlags(QGraphicsView::DontAdjustForAntialiasing));
}
class MessUpPainterItem : public QGraphicsRectItem
diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
index 35c0c6c606..09990ab70a 100644
--- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
+++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp
@@ -26,19 +26,24 @@
**
****************************************************************************/
-
-#include <QtGui/QtGui>
-#include <QtWidgets/QtWidgets>
+#include <QIdentityProxyModel>
+#include <QLabel>
+#include <QLineEdit>
+#include <QScrollBar>
+#include <QSignalSpy>
+#include <QSortFilterProxyModel>
+#include <QStandardItemModel>
+#include <QStringListModel>
+#include <QStyledItemDelegate>
+#include <QTableView>
+#include <QTest>
+#include <private/qapplication_p.h>
#include <private/qtablewidget_p.h>
-#include <QtTest/QtTest>
-#include "private/qapplication_p.h"
+#include <private/qtesthelpers_p.h>
#if QT_CONFIG(textmarkdownwriter)
-#include "private/qtextmarkdownwriter_p.h"
+#include <private/qtextmarkdownwriter_p.h>
#endif
-#include <algorithm>
-
-#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
@@ -49,14 +54,241 @@ using namespace QTestPrivate;
#define VERIFY_SPANS_CONSISTENCY(TEST_VIEW_) (void)false
#endif
-typedef QList<int> IntList;
+Q_DECLARE_METATYPE(Qt::Key);
+Q_DECLARE_METATYPE(Qt::KeyboardModifier);
+Q_DECLARE_METATYPE(QItemSelectionModel::SelectionFlag);
+using BoolList = QVector<bool>;
+using IntList = QVector<int>;
+using KeyList = QVector<Qt::Key>;
+using SpanList = QVector<QRect>;
+
+class QtTestTableModel: public QAbstractTableModel
+{
+ Q_OBJECT
+
+signals:
+ void invalidIndexEncountered() const;
+
+public slots:
+ bool submit() override { ++submit_count; return QAbstractTableModel::submit(); }
+
+public:
+ QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = nullptr)
+ : QAbstractTableModel(parent), row_count(rows), column_count(columns)
+ {}
+
+ int rowCount(const QModelIndex& = QModelIndex()) const override
+ {
+ return row_count;
+ }
+
+ int columnCount(const QModelIndex& = QModelIndex()) const override
+ {
+ return column_count;
+ }
+
+ bool isEditable(const QModelIndex &) const { return true; }
+
+ Qt::ItemFlags flags(const QModelIndex &index) const override
+ {
+ Qt::ItemFlags index_flags = QAbstractTableModel::flags(index);
+ if (disabled_rows.contains(index.row())
+ || disabled_columns.contains(index.column()))
+ index_flags &= ~Qt::ItemIsEnabled;
+ return index_flags;
+ }
+
+ void disableRow(int row)
+ {
+ disabled_rows.insert(row);
+ }
+
+ void enableRow(int row)
+ {
+ disabled_rows.remove(row);
+ }
+
+ void disableColumn(int column)
+ {
+ disabled_columns.insert(column);
+ }
+
+ void enableColumn(int column)
+ {
+ disabled_columns.remove(column);
+ }
+
+ QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override
+ {
+ if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) {
+ qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx;
+ emit invalidIndexEncountered();
+ return QVariant();
+ }
+
+ if (role == Qt::DisplayRole || role == Qt::EditRole) {
+ return QLatin1Char('[') + QString::number(idx.row()) + QLatin1Char(',')
+ + QString::number(idx.column()) + QLatin1String(",0]");
+ }
+
+ return QVariant();
+ }
+
+ bool insertRows(int start, int count, const QModelIndex &parent = QModelIndex()) override
+ {
+ if (start < 0 || start > row_count)
+ return false;
+
+ beginInsertRows(parent, start, start + count - 1);
+ row_count += count;
+ endInsertRows();
+ return true;
+ }
+
+ bool removeRows(int start, int count, const QModelIndex &parent = QModelIndex()) override
+ {
+ if (start < 0 || start >= row_count || row_count < count)
+ return false;
+
+ beginRemoveRows(parent, start, start + count - 1);
+ row_count -= count;
+ endRemoveRows();
+ return true;
+ }
+
+ void removeLastRow()
+ {
+ beginRemoveRows(QModelIndex(), row_count - 1, row_count - 1);
+ --row_count;
+ endRemoveRows();
+ }
+
+ void removeAllRows()
+ {
+ beginRemoveRows(QModelIndex(), 0, row_count - 1);
+ row_count = 0;
+ endRemoveRows();
+ }
+
+ bool insertColumns(int start, int count, const QModelIndex &parent = QModelIndex()) override
+ {
+ if (start < 0 || start > column_count)
+ return false;
+
+ beginInsertColumns(parent, start, start + count - 1);
+ column_count += count;
+ endInsertColumns();
+ return true;
+ }
+
+ bool removeColumns(int start, int count, const QModelIndex &parent = QModelIndex()) override
+ {
+ if (start < 0 || start >= column_count || column_count < count)
+ return false;
+
+ beginRemoveColumns(parent, start, start + count - 1);
+ column_count -= count;
+ endRemoveColumns();
+ return true;
+ }
+
+ void removeLastColumn()
+ {
+ beginRemoveColumns(QModelIndex(), column_count - 1, column_count - 1);
+ --column_count;
+ endRemoveColumns();
+ }
+
+ void removeAllColumns()
+ {
+ beginRemoveColumns(QModelIndex(), 0, column_count - 1);
+ column_count = 0;
+ endRemoveColumns();
+ }
+
+ bool canFetchMore(const QModelIndex &) const override
+ {
+ return can_fetch_more;
+ }
+
+ void fetchMore(const QModelIndex &) override
+ {
+ ++fetch_more_count;
+ }
-typedef QList<bool> BoolList;
+ QSet<int> disabled_rows;
+ QSet<int> disabled_columns;
+ int row_count;
+ int column_count;
+ int submit_count = 0;
+ int fetch_more_count = 0;
+ bool can_fetch_more = false;
+};
+
+class QtTestTableView : public QTableView
+{
+ Q_OBJECT
+public:
+ using QTableView::QTableView;
+
+ void setModel(QAbstractItemModel *model) override
+ {
+ QTableView::setModel(model);
+ connect(selectionModel(), &QItemSelectionModel::currentChanged,
+ this, &QtTestTableView::slotCurrentChanged);
+ connect(selectionModel(), &QItemSelectionModel::selectionChanged,
+ this, &QtTestTableView::itemSelectionChanged);
+ // Allow small sections in this test, since this test was made before we correctly enforced minimum sizes.
+ horizontalHeader()->setMinimumSectionSize(0);
+ verticalHeader()->setMinimumSectionSize(0);
+ }
+
+ using QTableView::moveCursor;
+ using QTableView::isIndexHidden;
+ using QTableView::setSelection;
+ using QTableView::selectedIndexes;
+ using QTableView::sizeHintForRow;
+ using QTableView::viewOptions;
+
+ bool checkSignalOrder = false;
+public slots:
+ void slotCurrentChanged(QModelIndex, QModelIndex) {
+ hasCurrentChanged++;
+ if (checkSignalOrder)
+ QVERIFY(hasCurrentChanged > hasSelectionChanged);
+ }
+
+ void itemSelectionChanged(QItemSelection , QItemSelection ) {
+ hasSelectionChanged++;
+ if (checkSignalOrder)
+ QVERIFY(hasCurrentChanged >= hasSelectionChanged);
+ }
+private:
+ int hasCurrentChanged = 0;
+ int hasSelectionChanged = 0;
+
+ friend class tst_QTableView;
+ friend struct QMetaTypeId<QtTestTableView::CursorAction>;
+};
+Q_DECLARE_METATYPE(QtTestTableView::CursorAction);
+
+class QtTestItemDelegate : public QStyledItemDelegate
+{
+public:
+ QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const override
+ {
+ return hint;
+ }
+
+ QSize hint;
+};
class tst_QTableView : public QObject
{
Q_OBJECT
+private:
+ using CursorActionList = QVector<QtTestTableView::CursorAction>;
private slots:
void getSetCheck();
@@ -236,14 +468,14 @@ void tst_QTableView::getSetCheck()
QHeaderView *var1 = new QHeaderView(Qt::Horizontal);
obj1.setHorizontalHeader(var1);
QCOMPARE(var1, obj1.horizontalHeader());
- obj1.setHorizontalHeader((QHeaderView *)0);
+ obj1.setHorizontalHeader(nullptr);
QCOMPARE(var1, obj1.horizontalHeader());
delete var1;
QHeaderView *var2 = new QHeaderView(Qt::Vertical);
obj1.setVerticalHeader(var2);
QCOMPARE(var2, obj1.verticalHeader());
- obj1.setVerticalHeader((QHeaderView *)0);
+ obj1.setVerticalHeader(nullptr);
QCOMPARE(var2, obj1.verticalHeader());
delete var2;
@@ -251,283 +483,12 @@ void tst_QTableView::getSetCheck()
obj1.setCornerButtonEnabled(false);
QCOMPARE(obj1.isCornerButtonEnabled(), false);
}
-
-class QtTestTableModel: public QAbstractTableModel
-{
- Q_OBJECT
-
-signals:
- void invalidIndexEncountered() const;
-
-public slots:
- bool submit() { ++submit_count; return QAbstractTableModel::submit(); }
-
-public:
- QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0)
- : QAbstractTableModel(parent),
- row_count(rows),
- column_count(columns),
- submit_count(0),
- can_fetch_more(false),
- fetch_more_count(0),
- disabled_rows(),
- disabled_columns() {}
-
- int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; }
- int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; }
- bool isEditable(const QModelIndex &) const { return true; }
-
- Qt::ItemFlags flags(const QModelIndex &index) const
- {
- Qt::ItemFlags index_flags = QAbstractTableModel::flags(index);
- if (disabled_rows.contains(index.row())
- || disabled_columns.contains(index.column()))
- index_flags &= ~Qt::ItemIsEnabled;
- return index_flags;
- }
-
- void disableRow(int row)
- {
- disabled_rows.insert(row);
- }
-
- void enableRow(int row)
- {
- disabled_rows.remove(row);
- }
-
- void disableColumn(int column)
- {
- disabled_columns.insert(column);
- }
-
- void enableColumn(int column)
- {
- disabled_columns.remove(column);
- }
-
- QVariant data(const QModelIndex &idx, int role) const
- {
- if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) {
- qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx;
- emit invalidIndexEncountered();
- return QVariant();
- }
-
- if (role == Qt::DisplayRole || role == Qt::EditRole) {
- return QLatin1Char('[') + QString::number(idx.row()) + QLatin1Char(',')
- + QString::number(idx.column()) + QLatin1String(",0]");
- }
-
- return QVariant();
- }
-
- bool insertRows(int start, int count, const QModelIndex &parent = QModelIndex())
- {
- if (start < 0 || start > row_count)
- return false;
-
- beginInsertRows(parent, start, start + count - 1);
- row_count += count;
- endInsertRows();
- return true;
- }
-
- bool removeRows(int start, int count, const QModelIndex &parent = QModelIndex())
- {
- if (start < 0 || start >= row_count || row_count < count)
- return false;
-
- beginRemoveRows(parent, start, start + count - 1);
- row_count -= count;
- endRemoveRows();
- return true;
- }
-
- void removeLastRow()
- {
- beginRemoveRows(QModelIndex(), row_count - 1, row_count - 1);
- --row_count;
- endRemoveRows();
- }
-
- void removeAllRows()
- {
- beginRemoveRows(QModelIndex(), 0, row_count - 1);
- row_count = 0;
- endRemoveRows();
- }
-
- bool insertColumns(int start, int count, const QModelIndex &parent = QModelIndex())
- {
- if (start < 0 || start > column_count)
- return false;
-
- beginInsertColumns(parent, start, start + count - 1);
- column_count += count;
- endInsertColumns();
- return true;
- }
-
- bool removeColumns(int start, int count, const QModelIndex &parent = QModelIndex())
- {
- if (start < 0 || start >= column_count || column_count < count)
- return false;
-
- beginRemoveColumns(parent, start, start + count - 1);
- column_count -= count;
- endRemoveColumns();
- return true;
- }
-
- void removeLastColumn()
- {
- beginRemoveColumns(QModelIndex(), column_count - 1, column_count - 1);
- --column_count;
- endRemoveColumns();
- }
-
- void removeAllColumns()
- {
- beginRemoveColumns(QModelIndex(), 0, column_count - 1);
- column_count = 0;
- endRemoveColumns();
- }
-
- bool canFetchMore(const QModelIndex &) const
- {
- return can_fetch_more;
- }
-
- void fetchMore(const QModelIndex &)
- {
- ++fetch_more_count;
- }
-
- void reset()
- {
- beginResetModel();
- endResetModel();
- }
-
- int row_count;
- int column_count;
- int submit_count;
- bool can_fetch_more;
- int fetch_more_count;
- QSet<int> disabled_rows;
- QSet<int> disabled_columns;
-};
-
-class QtTestTableView : public QTableView
-{
-Q_OBJECT
-
-public:
- QtTestTableView(QWidget *parent = 0) : QTableView(parent), checkSignalOrder(false), hasCurrentChanged(0), hasSelectionChanged(0) {}
-
- void setModel(QAbstractItemModel *model)
- {
- QTableView::setModel(model);
- connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
- this, SLOT(slotCurrentChanged(QModelIndex,QModelIndex)));
- connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
- this, SLOT(itemSelectionChanged(QItemSelection,QItemSelection)));
- // Allow small sections in this test, since this test was made before we correctly enforced minimum sizes.
- horizontalHeader()->setMinimumSectionSize(0);
- verticalHeader()->setMinimumSectionSize(0);
- }
-
- // enum CursorAction and moveCursor() are protected in QTableView.
- enum CursorAction {
- MoveUp = QAbstractItemView::MoveUp,
- MoveDown = QAbstractItemView::MoveDown,
- MoveLeft = QAbstractItemView::MoveLeft,
- MoveRight = QAbstractItemView::MoveRight,
- MoveHome = QAbstractItemView::MoveHome,
- MoveEnd = QAbstractItemView::MoveEnd,
- MovePageUp = QAbstractItemView::MovePageUp,
- MovePageDown = QAbstractItemView::MovePageDown,
- MoveNext = QAbstractItemView::MoveNext,
- MovePrevious = QAbstractItemView::MovePrevious
- };
-
- QModelIndex doMoveCursor(QtTestTableView::CursorAction cursorAction,
- Qt::KeyboardModifiers modifiers)
- {
- return QTableView::moveCursor((QAbstractItemView::CursorAction)cursorAction, modifiers);
- }
-
- int columnWidthHint(int column) const
- {
- return sizeHintForColumn(column);
- }
-
- int rowHeightHint(int row) const
- {
- return sizeHintForRow(row);
- }
-
- bool isIndexHidden(const QModelIndex &index) const
- {
- return QTableView::isIndexHidden(index);
- }
-
- void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command)
- {
- QTableView::setSelection(rect, command);
- }
-
- QModelIndexList selectedIndexes() const
- {
- return QTableView::selectedIndexes();
- }
-
- int sizeHintForRow(int row) const
- {
- return QTableView::sizeHintForRow(row);
- }
-
- QStyleOptionViewItem viewOptions() const {
- return QTableView::viewOptions();
- }
-
- bool checkSignalOrder;
-public slots:
- void slotCurrentChanged(QModelIndex, QModelIndex) {
- hasCurrentChanged++;
- if (checkSignalOrder)
- QVERIFY(hasCurrentChanged > hasSelectionChanged);
- }
-
- void itemSelectionChanged(QItemSelection , QItemSelection ) {
- hasSelectionChanged++;
- if (checkSignalOrder)
- QVERIFY(hasCurrentChanged >= hasSelectionChanged);
- }
-private:
- int hasCurrentChanged;
- int hasSelectionChanged;
-
-};
-
-class QtTestItemDelegate : public QItemDelegate
-{
-public:
- QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const
- {
- return hint;
- }
-
- QSize hint;
-};
-
void tst_QTableView::noDelegate()
{
QtTestTableModel model(3, 3);
QTableView view;
view.setModel(&model);
- view.setItemDelegate(0);
+ view.setItemDelegate(nullptr);
view.show();
}
@@ -541,7 +502,7 @@ void tst_QTableView::emptyModel()
{
QtTestTableModel model;
QTableView view;
- QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered()));
+ QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered);
view.setModel(&model);
view.show();
QCOMPARE(spy.count(), 0);
@@ -562,7 +523,7 @@ void tst_QTableView::removeRows()
QFETCH(int, columnCount);
QtTestTableModel model(rowCount, columnCount);
- QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered()));
+ QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered);
QTableView view;
view.setModel(&model);
@@ -590,7 +551,7 @@ void tst_QTableView::removeColumns()
QFETCH(int, columnCount);
QtTestTableModel model(rowCount, columnCount);
- QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered()));
+ QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered);
QTableView view;
view.setModel(&model);
@@ -608,58 +569,18 @@ void tst_QTableView::keyboardNavigation_data()
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
QTest::addColumn<bool>("tabKeyNavigation");
- QTest::addColumn<IntList>("keyPresses");
-
- QTest::newRow("16x16 model") << 16 << 16 << true
- << (IntList()
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Right
- << Qt::Key_Right
- << Qt::Key_Up
- << Qt::Key_Left
- << Qt::Key_Left
- << Qt::Key_Up
- << Qt::Key_Down
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Left
- << Qt::Key_Left
- << Qt::Key_Up
- << Qt::Key_Down
- << Qt::Key_Down
- << Qt::Key_Tab
- << Qt::Key_Backtab);
-
-
- QTest::newRow("no tab") << 8 << 8 << false
- << (IntList()
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Right
- << Qt::Key_Right
- << Qt::Key_Up
- << Qt::Key_Left
- << Qt::Key_Left
- << Qt::Key_Up
- << Qt::Key_Down
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Up
- << Qt::Key_Left
- << Qt::Key_Left
- << Qt::Key_Up
- << Qt::Key_Down
- << Qt::Key_Down
- << Qt::Key_Tab
- << Qt::Key_Backtab);
+ QTest::addColumn<KeyList>("keyPresses");
+
+ const KeyList keyList {
+ Qt::Key_Up, Qt::Key_Up, Qt::Key_Right, Qt::Key_Right,
+ Qt::Key_Up, Qt::Key_Left, Qt::Key_Left, Qt::Key_Up,
+ Qt::Key_Down, Qt::Key_Up, Qt::Key_Up, Qt::Key_Up,
+ Qt::Key_Up, Qt::Key_Up, Qt::Key_Up, Qt::Key_Left,
+ Qt::Key_Left, Qt::Key_Up, Qt::Key_Down, Qt::Key_Down,
+ Qt::Key_Tab, Qt::Key_Backtab};
+
+ QTest::newRow("16x16 model") << 16 << 16 << true << keyList;
+ QTest::newRow("no tab") << 8 << 8 << false << keyList;
}
void tst_QTableView::keyboardNavigation()
@@ -667,7 +588,7 @@ void tst_QTableView::keyboardNavigation()
QFETCH(int, rowCount);
QFETCH(int, columnCount);
QFETCH(bool, tabKeyNavigation);
- QFETCH(IntList, keyPresses);
+ QFETCH(const KeyList, keyPresses);
QtTestTableModel model(rowCount, columnCount);
QTableView view;
@@ -678,14 +599,12 @@ void tst_QTableView::keyboardNavigation()
view.setCurrentIndex(index);
view.show();
- qApp->setActiveWindow(&view);
+ QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
int row = rowCount - 1;
int column = columnCount - 1;
- for (int i = 0; i < keyPresses.count(); ++i) {
-
- Qt::Key key = (Qt::Key)keyPresses.at(i);
+ for (Qt::Key key : keyPresses) {
switch (key) {
case Qt::Key_Up:
@@ -785,8 +704,8 @@ void tst_QTableView::moveCursor_data()
QTest::addColumn<int>("startRow");
QTest::addColumn<int>("startColumn");
- QTest::addColumn<int>("cursorMoveAction");
- QTest::addColumn<int>("modifier");
+ QTest::addColumn<QtTestTableView::CursorAction>("cursorMoveAction");
+ QTest::addColumn<Qt::KeyboardModifier>("modifier");
QTest::addColumn<int>("expectedRow");
QTest::addColumn<int>("expectedColumn");
@@ -797,346 +716,346 @@ void tst_QTableView::moveCursor_data()
QTest::newRow("MoveRight (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveRight (3,0)")
<< 4 << 4 << -1 << -1
<< 3 << 0
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 3 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveRight (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0); // ###
QTest::newRow("MoveRight, hidden column 1 (0,0)")
<< 4 << 4 << -1 << 1
<< 0 << 0
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveRight, hidden column 3 (0,2)")
<< 4 << 4 << -1 << 3
<< 0 << 2
- << int(QtTestTableView::MoveRight) << int(Qt::NoModifier)
+ << QtTestTableView::MoveRight << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0); // ###
// MoveNext should in addition wrap
QTest::newRow("MoveNext (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext (0,2)")
<< 4 << 4 << -1 << -1
<< 0 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap (0,3)")
<< 4 << 4 << -1 << -1
<< 0 << 3
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, hidden column 1 (0,0)")
<< 4 << 4 << -1 << 1
<< 0 << 0
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap, hidden column 3 (0,2)")
<< 4 << 4 << -1 << 3
<< 0 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap, hidden column 3 (3,2)")
<< 4 << 4 << -1 << 3
<< 3 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrapy, wrapx, hidden column 3, hidden row 3 (2,2)")
<< 4 << 4 << 3 << 3
<< 2 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveNext, wrap, hidden column 2, moved column from 3 to 0. (0,2)")
<< 4 << 4 << -1 << 2
<< 0 << 2
- << int(QtTestTableView::MoveNext) << int(Qt::NoModifier)
+ << QtTestTableView::MoveNext << Qt::NoModifier
<< 1 << 3 << IntPair(0,0) << IntPair(3,0);
// MoveLeft
QTest::newRow("MoveLeft (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveLeft (0,3)")
<< 4 << 4 << -1 << -1
<< 0 << 3
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveLeft (1,0)")
<< 4 << 4 << -1 << -1
<< 1 << 0
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveLeft, hidden column 0 (0,2)")
<< 4 << 4 << -1 << 1
<< 0 << 2
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveLeft, hidden column 0 (0,1)")
<< 4 << 4 << -1 << 0
<< 0 << 1
- << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier)
+ << QtTestTableView::MoveLeft << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
// MovePrevious should in addition wrap
QTest::newRow("MovePrevious (0,3)")
<< 4 << 4 << -1 << -1
<< 0 << 3
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious (0,1)")
<< 4 << 4 << -1 << -1
<< 0 << 1
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap (1,0)")
<< 4 << 4 << -1 << -1
<< 1 << 0
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap, (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, hidden column 1 (0,2)")
<< 4 << 4 << -1 << 1
<< 0 << 2
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap, hidden column 3 (0,2)")
<< 4 << 4 << -1 << 3
<< 0 << 2
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrapy, hidden column 0 (0,1)")
<< 4 << 4 << -1 << 0
<< 0 << 1
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap, hidden column 0, hidden row 0 (1,1)")
<< 4 << 4 << 0 << 0
<< 1 << 1
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePrevious, wrap, hidden column 1, moved column from 0 to 3. (1,2)")
<< 4 << 4 << -1 << 1
<< 1 << 2
- << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier)
+ << QtTestTableView::MovePrevious << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,3);
// MoveDown
QTest::newRow("MoveDown (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown (3,0)")
<< 4 << 4 << -1 << -1
<< 3 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 3 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown, hidden row 1 (0,0)")
<< 4 << 4 << 1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 2 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown, hidden row 3 (2,0)")
<< 4 << 4 << 3 << -1
<< 2 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 2 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveDown, hidden row 0 hidden column 0 (0,0)")
<< 4 << 4 << 0 << 0
<< 0 << 0
- << int(QtTestTableView::MoveDown) << int(Qt::NoModifier)
+ << QtTestTableView::MoveDown << Qt::NoModifier
<< 1 << 1 << IntPair(0,0) << IntPair(0,0);
// MoveUp
QTest::newRow("MoveUp (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveUp (3, 0)")
<< 4 << 4 << -1 << -1
<< 3 << 0
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 2 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveUp (0,1)")
<< 4 << 4 << -1 << -1
<< 0 << 1
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 0 << 1 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveUp, hidden row 1 (2,0)")
<< 4 << 4 << 1 << -1
<< 2 << 0
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveUp, hidden row (1,0)")
<< 4 << 4 << 0 << -1
<< 1 << 0
- << int(QtTestTableView::MoveUp) << int(Qt::NoModifier)
+ << QtTestTableView::MoveUp << Qt::NoModifier
<< 1 << 0 << IntPair(0,0) << IntPair(0,0);
// MoveHome
QTest::newRow("MoveHome (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveHome) << int(Qt::NoModifier)
+ << QtTestTableView::MoveHome << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveHome (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveHome) << int(Qt::NoModifier)
+ << QtTestTableView::MoveHome << Qt::NoModifier
<< 3 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveHome, hidden column 0 (3,3)")
<< 4 << 4 << -1 << 0
<< 3 << 3
- << int(QtTestTableView::MoveHome) << int(Qt::NoModifier)
+ << QtTestTableView::MoveHome << Qt::NoModifier
<< 3 << 1 << IntPair(0,0) << IntPair(0,0);
// Use Ctrl modifier
QTest::newRow("MoveHome + Ctrl (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveHome << Qt::ControlModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveHome + Ctrl (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveHome << Qt::ControlModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveHome + Ctrl, hidden column 0, hidden row 0 (3,3)")
<< 4 << 4 << 0 << 0
<< 3 << 3
- << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveHome << Qt::ControlModifier
<< 1 << 1 << IntPair(0,0) << IntPair(0,0);
// MoveEnd
QTest::newRow("MoveEnd (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier)
+ << QtTestTableView::MoveEnd << Qt::NoModifier
<< 0 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier)
+ << QtTestTableView::MoveEnd << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd, hidden column (0,0)")
<< 4 << 4 << -1 << 3
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier)
+ << QtTestTableView::MoveEnd << Qt::NoModifier
<< 0<< 2 << IntPair(0,0) << IntPair(0,0);
// Use Ctrl modifier
QTest::newRow("MoveEnd + Ctrl (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveEnd << Qt::ControlModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd + Ctrl (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveEnd << Qt::ControlModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd + Ctrl, hidden column 3 (0,0)")
<< 4 << 4 << -1 << 3
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveEnd << Qt::ControlModifier
<< 3 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MoveEnd + Ctrl, hidden column 3, hidden row 3 (0,0)")
<< 4 << 4 << 3 << 3
<< 0 << 0
- << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier)
+ << QtTestTableView::MoveEnd << Qt::ControlModifier
<< 2 << 2 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePageUp (0,0)")
<< 4 << 4 << -1 << -1
<< 0 << 0
- << int(QtTestTableView::MovePageUp) << 0
+ << QtTestTableView::MovePageUp << Qt::NoModifier
<< 0 << 0 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePageUp (3,3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MovePageUp) << 0
+ << QtTestTableView::MovePageUp << Qt::NoModifier
<< 0 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePageDown (3, 3)")
<< 4 << 4 << -1 << -1
<< 3 << 3
- << int(QtTestTableView::MovePageDown) << 0
+ << QtTestTableView::MovePageDown << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
QTest::newRow("MovePageDown (0, 3)")
<< 4 << 4 << -1 << -1
<< 0 << 3
- << int(QtTestTableView::MovePageDown) << 0
+ << QtTestTableView::MovePageDown << Qt::NoModifier
<< 3 << 3 << IntPair(0,0) << IntPair(0,0);
}
@@ -1148,8 +1067,8 @@ void tst_QTableView::moveCursor()
QFETCH(int, hideColumn);
QFETCH(int, startRow);
QFETCH(int, startColumn);
- QFETCH(int, cursorMoveAction);
- QFETCH(int, modifier);
+ QFETCH(QtTestTableView::CursorAction, cursorMoveAction);
+ QFETCH(Qt::KeyboardModifier, modifier);
QFETCH(int, expectedRow);
QFETCH(int, expectedColumn);
QFETCH(IntPair, moveRow);
@@ -1174,8 +1093,7 @@ void tst_QTableView::moveCursor()
QModelIndex index = model.index(startRow, startColumn);
view.setCurrentIndex(index);
- QModelIndex newIndex = view.doMoveCursor((QtTestTableView::CursorAction)cursorMoveAction,
- (Qt::KeyboardModifiers)modifier);
+ QModelIndex newIndex = view.moveCursor(cursorMoveAction, modifier);
// expected fails, task 119433
if(newIndex.row() == -1)
return;
@@ -1193,7 +1111,7 @@ void tst_QTableView::moveCursorStrikesBack_data()
QTest::addColumn<int>("startRow");
QTest::addColumn<int>("startColumn");
- QTest::addColumn<IntList>("cursorMoveActions");
+ QTest::addColumn<CursorActionList>("cursorMoveActions");
QTest::addColumn<int>("expectedRow");
QTest::addColumn<int>("expectedColumn");
@@ -1201,70 +1119,84 @@ void tst_QTableView::moveCursorStrikesBack_data()
<< IntList()
<< (IntList() << 6)
<< QRect()
- << 0 << 5 << (IntList() << int(QtTestTableView::MoveNext))
+ << 0 << 5
+ << CursorActionList{QtTestTableView::MoveNext}
<< 1 << 0;
QTest::newRow("Last column disabled 2. Task QTBUG-3878") << -1 << -1
<< IntList()
<< (IntList() << 6)
<< QRect()
- << 1 << 0 << (IntList() << int(QtTestTableView::MovePrevious))
+ << 1 << 0
+ << CursorActionList{QtTestTableView::MovePrevious}
<< 0 << 5;
QTest::newRow("Span, anchor column hidden") << -1 << 1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext))
+ << 2 << 0
+ << CursorActionList{QtTestTableView::MoveNext}
<< 2 << 1;
QTest::newRow("Span, anchor column disabled") << -1 << -1
<< IntList()
<< (IntList() << 1)
<< QRect(1, 2, 2, 3)
- << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext))
+ << 2 << 0
+ << CursorActionList{QtTestTableView::MoveNext}
<< 2 << 1;
QTest::newRow("Span, anchor row hidden") << 2 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown))
+ << 1 << 2
+ << CursorActionList{QtTestTableView::MoveDown}
<< 2 << 1;
QTest::newRow("Span, anchor row disabled") << -1 << -1
<< (IntList() << 2)
<< IntList()
<< QRect(1, 2, 2, 3)
- << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown))
+ << 1 << 2
+ << CursorActionList{QtTestTableView::MoveDown}
<< 2 << 1;
QTest::newRow("Move through span right") << -1 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 3 << 0 << (IntList() << int(QtTestTableView::MoveRight) << int(QtTestTableView::MoveRight))
+ << 3 << 0
+ << CursorActionList{QtTestTableView::MoveRight,
+ QtTestTableView::MoveRight}
<< 3 << 3;
QTest::newRow("Move through span left") << -1 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 3 << 3 << (IntList() << int(QtTestTableView::MoveLeft) << int(QtTestTableView::MoveLeft))
+ << 3 << 3
+ << CursorActionList{QtTestTableView::MoveLeft,
+ QtTestTableView::MoveLeft}
<< 3 << 0;
QTest::newRow("Move through span down") << -1 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown) << int(QtTestTableView::MoveDown))
+ << 1 << 2
+ << CursorActionList{QtTestTableView::MoveDown,
+ QtTestTableView::MoveDown}
<< 5 << 2;
QTest::newRow("Move through span up") << -1 << -1
<< IntList()
<< IntList()
<< QRect(1, 2, 2, 3)
- << 5 << 2 << (IntList() << int(QtTestTableView::MoveUp) << int(QtTestTableView::MoveUp))
+ << 5 << 2
+ << CursorActionList{QtTestTableView::MoveUp,
+ QtTestTableView::MoveUp}
<< 1 << 2;
IntList fullList;
@@ -1275,42 +1207,48 @@ void tst_QTableView::moveCursorStrikesBack_data()
<< fullList
<< fullList
<< QRect()
- << 1 << 0 << (IntList() << int(QtTestTableView::MoveNext))
+ << 1 << 0
+ << CursorActionList{QtTestTableView::MoveNext}
<< -1 << -1;
QTest::newRow("All disabled, wrap backwards. => invalid index") << -1 << -1
<< fullList
<< fullList
<< QRect()
- << 1 << 0 << (IntList() << int(QtTestTableView::MovePrevious))
+ << 1 << 0
+ << CursorActionList{QtTestTableView::MovePrevious}
<< -1 << -1;
QTest::newRow("Last column disabled, MoveEnd. QTBUG-72400") << -1 << -1
<< IntList()
<< (IntList() << 6)
<< QRect()
- << 0 << 0 << (IntList() << int(QtTestTableView::MoveEnd))
+ << 0 << 0
+ << CursorActionList{QtTestTableView::MoveEnd}
<< 0 << 5;
QTest::newRow("First column disabled, MoveHome. QTBUG-72400") << -1 << -1
<< IntList()
<< (IntList() << 0)
<< QRect()
- << 0 << 6 << (IntList() << int(QtTestTableView::MoveHome))
+ << 0 << 6
+ << CursorActionList{QtTestTableView::MoveHome}
<< 0 << 1;
QTest::newRow("First row disabled, MovePageUp. QTBUG-72400") << -1 << -1
<< (IntList() << 0)
<< IntList()
<< QRect()
- << 2 << 0 << (IntList() << int(QtTestTableView::MovePageUp))
+ << 2 << 0
+ << CursorActionList{QtTestTableView::MovePageUp}
<< 1 << 0;
QTest::newRow("Last row disabled, MovePageDown. QTBUG-72400") << -1 << -1
<< (IntList() << 6)
<< IntList()
<< QRect()
- << 4 << 0 << (IntList() << int(QtTestTableView::MovePageDown))
+ << 4 << 0
+ << CursorActionList{QtTestTableView::MovePageDown}
<< 5 << 0;
}
@@ -1318,13 +1256,13 @@ void tst_QTableView::moveCursorStrikesBack()
{
QFETCH(int, hideRow);
QFETCH(int, hideColumn);
- QFETCH(IntList, disableRows);
- QFETCH(IntList, disableColumns);
+ QFETCH(const IntList, disableRows);
+ QFETCH(const IntList, disableColumns);
QFETCH(QRect, span);
QFETCH(int, startRow);
QFETCH(int, startColumn);
- QFETCH(IntList, cursorMoveActions);
+ QFETCH(const CursorActionList, cursorMoveActions);
QFETCH(int, expectedRow);
QFETCH(int, expectedColumn);
@@ -1344,15 +1282,15 @@ void tst_QTableView::moveCursorStrikesBack()
QModelIndex index = model.index(startRow, startColumn);
view.setCurrentIndex(index);
- foreach (int row, disableRows)
+ for (int row : disableRows)
model.disableRow(row);
- foreach (int column, disableColumns)
+ for (int column : disableColumns)
model.disableColumn(column);
int newRow = -1;
int newColumn = -1;
- foreach (int cursorMoveAction, cursorMoveActions) {
- QModelIndex newIndex = view.doMoveCursor((QtTestTableView::CursorAction)cursorMoveAction, 0);
+ for (auto cursorMoveAction : cursorMoveActions) {
+ QModelIndex newIndex = view.moveCursor(cursorMoveAction, nullptr);
view.setCurrentIndex(newIndex);
newRow = newIndex.row();
newColumn = newIndex.column();
@@ -1523,7 +1461,7 @@ void tst_QTableView::selection_data()
QTest::addColumn<int>("y");
QTest::addColumn<int>("width");
QTest::addColumn<int>("height");
- QTest::addColumn<int>("command");
+ QTest::addColumn<QItemSelectionModel::SelectionFlag>("command");
QTest::addColumn<int>("selectedCount"); // ### make this more detailed
QTest::newRow("no span, no hidden, no moved, 3x3 select")
@@ -1535,7 +1473,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
QTest::newRow("row span, no hidden, no moved, 3x3 select")
@@ -1547,7 +1485,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 8; // selected count
QTest::newRow("col span, no hidden, no moved, 3x3 select")
@@ -1559,7 +1497,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 8; // selected count
QTest::newRow("no span, row hidden, no moved, 3x3 select")
@@ -1571,7 +1509,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
QTest::newRow("no span, col hidden, no moved, 3x3 select")
@@ -1583,7 +1521,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
QTest::newRow("no span, no hidden, row moved, 3x3 select")
@@ -1595,7 +1533,7 @@ void tst_QTableView::selection_data()
<< -1 << -1 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
QTest::newRow("no span, no hidden, col moved, 3x3 select")
@@ -1607,7 +1545,7 @@ void tst_QTableView::selection_data()
<< 1 << 3 // move col
<< 40 << 40 // cell size
<< 20 << 20 << 80 << 80 // rect
- << int(QItemSelectionModel::Select) // command
+ << QItemSelectionModel::Select // command
<< 9; // selected count
}
@@ -1631,7 +1569,7 @@ void tst_QTableView::selection()
QFETCH(int, y);
QFETCH(int, width);
QFETCH(int, height);
- QFETCH(int, command);
+ QFETCH(QItemSelectionModel::SelectionFlag, command);
QFETCH(int, selectedCount);
QtTestTableModel model(rowCount, columnCount);
@@ -1653,8 +1591,7 @@ void tst_QTableView::selection()
for (int c = 0; c < columnCount; ++c)
view.setColumnWidth(c, columnWidth);
- view.setSelection(QRect(x, y, width, height),
- QItemSelectionModel::SelectionFlags(command));
+ view.setSelection(QRect(x, y, width, height), command);
QCOMPARE(view.selectedIndexes().count(), selectedCount);
}
@@ -1664,92 +1601,92 @@ void tst_QTableView::selectRow_data()
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
QTest::addColumn<int>("row");
- QTest::addColumn<int>("mode");
- QTest::addColumn<int>("behavior");
+ QTest::addColumn<QAbstractItemView::SelectionMode>("mode");
+ QTest::addColumn<QAbstractItemView::SelectionBehavior>("behavior");
QTest::addColumn<int>("selectedItems");
QTest::newRow("SingleSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectItems
<< 0;
QTest::newRow("SingleSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectRows
<< 10;
QTest::newRow("SingleSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectColumns
<< 0;
QTest::newRow("MultiSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("MultiSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectRows
<< 10;
QTest::newRow("MultiSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectColumns
<< 0;
QTest::newRow("ExtendedSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("ExtendedSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectRows
<< 10;
QTest::newRow("ExtendedSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectColumns
<< 0;
QTest::newRow("ContiguousSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("ContiguousSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectRows
<< 10;
QTest::newRow("ContiguousSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectColumns
<< 0;
}
@@ -1758,16 +1695,16 @@ void tst_QTableView::selectRow()
QFETCH(int, rowCount);
QFETCH(int, columnCount);
QFETCH(int, row);
- QFETCH(int, mode);
- QFETCH(int, behavior);
+ QFETCH(QAbstractItemView::SelectionMode, mode);
+ QFETCH(QAbstractItemView::SelectionBehavior, behavior);
QFETCH(int, selectedItems);
QtTestTableModel model(rowCount, columnCount);
QTableView view;
view.setModel(&model);
- view.setSelectionMode((QAbstractItemView::SelectionMode)mode);
- view.setSelectionBehavior((QAbstractItemView::SelectionBehavior)behavior);
+ view.setSelectionMode(mode);
+ view.setSelectionBehavior(behavior);
QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0);
@@ -1785,92 +1722,92 @@ void tst_QTableView::selectColumn_data()
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
QTest::addColumn<int>("column");
- QTest::addColumn<int>("mode");
- QTest::addColumn<int>("behavior");
+ QTest::addColumn<QAbstractItemView::SelectionMode>("mode");
+ QTest::addColumn<QAbstractItemView::SelectionBehavior>("behavior");
QTest::addColumn<int>("selectedItems");
QTest::newRow("SingleSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectItems
<< 0;
QTest::newRow("SingleSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectRows
<< 0;
QTest::newRow("SingleSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::SingleSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::SingleSelection
+ << QAbstractItemView::SelectColumns
<< 10;
QTest::newRow("MultiSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("MultiSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectRows
<< 0;
QTest::newRow("MultiSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::MultiSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::MultiSelection
+ << QAbstractItemView::SelectColumns
<< 10;
QTest::newRow("ExtendedSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("ExtendedSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectRows
<< 0;
QTest::newRow("ExtendedSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ExtendedSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::ExtendedSelection
+ << QAbstractItemView::SelectColumns
<< 10;
QTest::newRow("ContiguousSelection and SelectItems")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectItems
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectItems
<< 10;
QTest::newRow("ContiguousSelection and SelectRows")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectRows
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectRows
<< 0;
QTest::newRow("ContiguousSelection and SelectColumns")
<< 10 << 10
<< 0
- << (int)QAbstractItemView::ContiguousSelection
- << (int)QAbstractItemView::SelectColumns
+ << QAbstractItemView::ContiguousSelection
+ << QAbstractItemView::SelectColumns
<< 10;
}
@@ -1879,16 +1816,16 @@ void tst_QTableView::selectColumn()
QFETCH(int, rowCount);
QFETCH(int, columnCount);
QFETCH(int, column);
- QFETCH(int, mode);
- QFETCH(int, behavior);
+ QFETCH(QAbstractItemView::SelectionMode, mode);
+ QFETCH(QAbstractItemView::SelectionBehavior, behavior);
QFETCH(int, selectedItems);
QtTestTableModel model(rowCount, columnCount);
QTableView view;
view.setModel(&model);
- view.setSelectionMode((QAbstractItemView::SelectionMode)mode);
- view.setSelectionBehavior((QAbstractItemView::SelectionBehavior)behavior);
+ view.setSelectionMode(mode);
+ view.setSelectionBehavior(behavior);
QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0);
@@ -1988,9 +1925,9 @@ void tst_QTableView::selectall_data()
<< 100; // selected count
}
-void QTest__keySequence(QWidget* widget, QKeySequence ks)
+void QTest__keySequence(QWidget* widget, const QKeySequence &ks)
{
- for (int i=0; i<ks.count(); ++i)
+ for (int i = 0; i < ks.count(); ++i)
{
Qt::Key key = Qt::Key(ks[i] & ~Qt::KeyboardModifierMask);
Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers(ks[i] & Qt::KeyboardModifierMask);
@@ -2228,7 +2165,7 @@ void tst_QTableView::resizeRowsToContents()
QFETCH(int, cellHeight);
QFETCH(int, rowHeight);
QFETCH(int, columnWidth);
- Q_UNUSED(columnWidth);
+ Q_UNUSED(columnWidth)
QtTestTableModel model(rowCount, columnCount);
QtTestTableView view;
@@ -2240,13 +2177,12 @@ void tst_QTableView::resizeRowsToContents()
delegate.hint = QSize(cellWidth, cellHeight);
- QSignalSpy resizedSpy(view.verticalHeader(), SIGNAL(sectionResized(int,int,int)));
+ QSignalSpy resizedSpy(view.verticalHeader(), &QHeaderView::sectionResized);
view.resizeRowsToContents();
QCOMPARE(resizedSpy.count(), model.rowCount());
- for (int r = 0; r < model.rowCount(); ++r) {
+ for (int r = 0; r < model.rowCount(); ++r)
QCOMPARE(view.rowHeight(r), rowHeight);
- }
}
void tst_QTableView::resizeColumnsToContents_data()
@@ -2275,7 +2211,7 @@ void tst_QTableView::resizeColumnsToContents()
QFETCH(int, cellHeight);
QFETCH(int, rowHeight);
QFETCH(int, columnWidth);
- Q_UNUSED(rowHeight);
+ Q_UNUSED(rowHeight)
QtTestTableModel model(rowCount, columnCount);
QtTestTableView view;
@@ -2287,7 +2223,7 @@ void tst_QTableView::resizeColumnsToContents()
delegate.hint = QSize(cellWidth, cellHeight);
- QSignalSpy resizedSpy(view.horizontalHeader(), SIGNAL(sectionResized(int,int,int)));
+ QSignalSpy resizedSpy(view.horizontalHeader(), &QHeaderView::sectionResized);
view.resizeColumnsToContents();
QCOMPARE(resizedSpy.count(), model.columnCount());
@@ -2300,51 +2236,51 @@ void tst_QTableView::rowViewportPosition_data()
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("rowHeight");
QTest::addColumn<int>("row");
- QTest::addColumn<int>("verticalScrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("verticalScrollMode");
QTest::addColumn<int>("verticalScrollValue");
QTest::addColumn<int>("rowViewportPosition");
QTest::newRow("row 0, scroll per item 0")
- << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerItem) << 0 << 0;
+ << 10 << 40 << 0 << QAbstractItemView::ScrollPerItem << 0 << 0;
QTest::newRow("row 1, scroll per item, 0")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 0 << 1 * 40;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 0 << 1 * 40;
QTest::newRow("row 1, scroll per item, 1")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 1 << 0;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 1 << 0;
QTest::newRow("row 5, scroll per item, 0")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 0 << 5 * 40;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 0 << 5 * 40;
QTest::newRow("row 5, scroll per item, 5")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 5 << 0;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 5 << 0;
QTest::newRow("row 9, scroll per item, 0")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 0 << 9 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 0 << 9 * 40;
QTest::newRow("row 9, scroll per item, 5")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 5 << 4 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 5 << 4 * 40;
QTest::newRow("row 0, scroll per pixel 0")
- << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerPixel) << 0 << 0;
+ << 10 << 40 << 0 << QAbstractItemView::ScrollPerPixel << 0 << 0;
QTest::newRow("row 1, scroll per pixel, 0")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 0 << 1 * 40;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 0 << 1 * 40;
QTest::newRow("row 1, scroll per pixel, 1")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 1 * 40 << 0;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 1 * 40 << 0;
QTest::newRow("row 5, scroll per pixel, 0")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 0 << 5 * 40;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 0 << 5 * 40;
QTest::newRow("row 5, scroll per pixel, 5")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 0;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 0;
QTest::newRow("row 9, scroll per pixel, 0")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 0 << 9 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 0 << 9 * 40;
QTest::newRow("row 9, scroll per pixel, 5")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 4 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 4 * 40;
}
void tst_QTableView::rowViewportPosition()
@@ -2352,7 +2288,7 @@ void tst_QTableView::rowViewportPosition()
QFETCH(int, rowCount);
QFETCH(int, rowHeight);
QFETCH(int, row);
- QFETCH(int, verticalScrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, verticalScrollMode);
QFETCH(int, verticalScrollValue);
QFETCH(int, rowViewportPosition);
@@ -2366,7 +2302,7 @@ void tst_QTableView::rowViewportPosition()
for (int r = 0; r < rowCount; ++r)
view.setRowHeight(r, rowHeight);
- view.setVerticalScrollMode((QAbstractItemView::ScrollMode)verticalScrollMode);
+ view.setVerticalScrollMode(verticalScrollMode);
view.verticalScrollBar()->setValue(verticalScrollValue);
#ifdef Q_OS_WINRT
@@ -2471,51 +2407,51 @@ void tst_QTableView::columnViewportPosition_data()
QTest::addColumn<int>("columnCount");
QTest::addColumn<int>("columnWidth");
QTest::addColumn<int>("column");
- QTest::addColumn<int>("horizontalScrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("horizontalScrollMode");
QTest::addColumn<int>("horizontalScrollValue");
QTest::addColumn<int>("columnViewportPosition");
QTest::newRow("column 0, scroll per item 0")
- << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerItem) << 0 << 0;
+ << 10 << 40 << 0 << QAbstractItemView::ScrollPerItem << 0 << 0;
QTest::newRow("column 1, scroll per item, 0")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 0 << 1 * 40;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 0 << 1 * 40;
QTest::newRow("column 1, scroll per item, 1")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 1 << 0;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 1 << 0;
QTest::newRow("column 5, scroll per item, 0")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 0 << 5 * 40;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 0 << 5 * 40;
QTest::newRow("column 5, scroll per item, 5")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 5 << 0;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 5 << 0;
QTest::newRow("column 9, scroll per item, 0")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 0 << 9 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 0 << 9 * 40;
QTest::newRow("column 9, scroll per item, 5")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 5 << 4 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 5 << 4 * 40;
QTest::newRow("column 0, scroll per pixel 0")
- << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerPixel) << 0 << 0;
+ << 10 << 40 << 0 << QAbstractItemView::ScrollPerPixel << 0 << 0;
QTest::newRow("column 1, scroll per pixel 0")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 0 << 1 * 40;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 0 << 1 * 40;
QTest::newRow("column 1, scroll per pixel 1")
- << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 1 * 40 << 0;
+ << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 1 * 40 << 0;
QTest::newRow("column 5, scroll per pixel 0")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 0 << 5 * 40;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 0 << 5 * 40;
QTest::newRow("column 5, scroll per pixel 5")
- << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 0;
+ << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 0;
QTest::newRow("column 9, scroll per pixel 0")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 0 << 9 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 0 << 9 * 40;
QTest::newRow("column 9, scroll per pixel 5")
- << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 4 * 40;
+ << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 4 * 40;
}
void tst_QTableView::columnViewportPosition()
@@ -2523,7 +2459,7 @@ void tst_QTableView::columnViewportPosition()
QFETCH(int, columnCount);
QFETCH(int, columnWidth);
QFETCH(int, column);
- QFETCH(int, horizontalScrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, horizontalScrollMode);
QFETCH(int, horizontalScrollValue);
QFETCH(int, columnViewportPosition);
@@ -2537,7 +2473,7 @@ void tst_QTableView::columnViewportPosition()
for (int c = 0; c < columnCount; ++c)
view.setColumnWidth(c, columnWidth);
- view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)horizontalScrollMode);
+ view.setHorizontalScrollMode(horizontalScrollMode);
view.horizontalScrollBar()->setValue(horizontalScrollValue);
#ifdef Q_OS_WINRT
@@ -2737,8 +2673,8 @@ void tst_QTableView::sortingEnabled()
void tst_QTableView::scrollTo_data()
{
- QTest::addColumn<int>("verticalScrollMode");
- QTest::addColumn<int>("horizontalScrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("verticalScrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("horizontalScrollMode");
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
QTest::addColumn<int>("rowHeight");
@@ -2751,51 +2687,51 @@ void tst_QTableView::scrollTo_data()
QTest::addColumn<int>("columnSpan");
QTest::addColumn<int>("horizontalScroll");
QTest::addColumn<int>("verticalScroll");
- QTest::addColumn<int>("scrollHint");
+ QTest::addColumn<QAbstractItemView::ScrollHint>("scrollHint");
QTest::addColumn<int>("expectedHorizontalScroll");
QTest::addColumn<int>("expectedVerticalScroll");
QTest::newRow("no hidden, no span, no scroll, per item")
- << (int)QAbstractItemView::ScrollPerItem
- << (int)QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
<< 10 << 10 // table
<< 80 << 80 // size
<< -1 << -1 // hide
<< 0 << 0 // cell
<< 1 << 1 // span
<< 0 << 0 // scroll
- << (int)QAbstractItemView::PositionAtTop
+ << QAbstractItemView::PositionAtTop
<< 0 << 0; // expected
QTest::newRow("no hidden, no span, no scroll, per pixel")
- << (int)QAbstractItemView::ScrollPerPixel
- << (int)QAbstractItemView::ScrollPerPixel
+ << QAbstractItemView::ScrollPerPixel
+ << QAbstractItemView::ScrollPerPixel
<< 10 << 10 // table
<< 80 << 80 // size
<< -1 << -1 // hide
<< 0 << 0 // cell
<< 1 << 1 // span
<< 0 << 0 // scroll
- << (int)QAbstractItemView::PositionAtTop
+ << QAbstractItemView::PositionAtTop
<< 0 << 0; // expected
QTest::newRow("hidden, no span, no scroll, per item")
- << (int)QAbstractItemView::ScrollPerItem
- << (int)QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
<< 10 << 10 // table
<< 80 << 80 // size
<< 3 << 3 // hide
<< 5 << 5 // cell
<< 1 << 1 // span
<< 0 << 0 // scroll
- << (int)QAbstractItemView::PositionAtTop
+ << QAbstractItemView::PositionAtTop
<< 4 << 4; // expected
}
void tst_QTableView::scrollTo()
{
- QFETCH(int, horizontalScrollMode);
- QFETCH(int, verticalScrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, horizontalScrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, verticalScrollMode);
QFETCH(int, rowCount);
QFETCH(int, columnCount);
QFETCH(int, rowHeight);
@@ -2808,7 +2744,7 @@ void tst_QTableView::scrollTo()
QFETCH(int, columnSpan);
QFETCH(int, horizontalScroll);
QFETCH(int, verticalScroll);
- QFETCH(int, scrollHint);
+ QFETCH(QAbstractItemView::ScrollHint, scrollHint);
QFETCH(int, expectedHorizontalScroll);
QFETCH(int, expectedVerticalScroll);
@@ -2828,8 +2764,8 @@ void tst_QTableView::scrollTo()
view.setSpan(row, column, rowSpan, columnSpan);
view.hideRow(hiddenRow);
view.hideColumn(hiddenColumn);
- view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)horizontalScrollMode);
- view.setVerticalScrollMode((QAbstractItemView::ScrollMode)verticalScrollMode);
+ view.setHorizontalScrollMode(horizontalScrollMode);
+ view.setVerticalScrollMode(verticalScrollMode);
for (int r = 0; r < rowCount; ++r)
view.setRowHeight(r, rowHeight);
@@ -2841,7 +2777,7 @@ void tst_QTableView::scrollTo()
QModelIndex index = model.index(row, column);
QVERIFY(index.isValid());
- view.scrollTo(index, (QAbstractItemView::ScrollHint)scrollHint);
+ view.scrollTo(index, scrollHint);
QTRY_COMPARE(view.verticalScrollBar()->value(), expectedVerticalScroll);
QTRY_COMPARE(view.horizontalScrollBar()->value(), expectedHorizontalScroll);
}
@@ -3146,8 +3082,6 @@ void tst_QTableView::span()
VERIFY_SPANS_CONSISTENCY(&view);
}
-typedef QVector<QRect> SpanList;
-
void tst_QTableView::spans_data()
{
QTest::addColumn<int>("rows");
@@ -3275,7 +3209,7 @@ void tst_QTableView::spans()
{
QFETCH(int, rows);
QFETCH(int, columns);
- QFETCH(SpanList, spans);
+ QFETCH(const SpanList, spans);
QFETCH(bool, hideRowLastRowOfFirstSpan);
QFETCH(QPoint, pos);
QFETCH(int, expectedRowSpan);
@@ -3287,10 +3221,8 @@ void tst_QTableView::spans()
view.setModel(&model);
view.show();
- for (int i = 0; i < spans.count(); ++i) {
- QRect sp = spans.at(i);
+ for (const auto &sp : spans)
view.setSpan(sp.x(), sp.y(), sp.width(), sp.height());
- }
if (hideRowLastRowOfFirstSpan) {
view.setRowHidden(spans.at(0).bottom(), true);
@@ -3384,32 +3316,34 @@ void tst_QTableView::spansAfterRowRemoval()
QtTestTableView view;
view.setModel(&model);
- QList<QRect> spans;
- spans << QRect(0, 1, 1, 2)
- << QRect(1, 2, 1, 2)
- << QRect(2, 2, 1, 5)
- << QRect(2, 8, 1, 2)
- << QRect(3, 4, 1, 2)
- << QRect(4, 4, 1, 4)
- << QRect(5, 6, 1, 3)
- << QRect(6, 7, 1, 3);
- foreach (QRect span, spans)
+ static const QRect spans[] = {
+ {0, 1, 1, 2},
+ {1, 2, 1, 2},
+ {2, 2, 1, 5},
+ {2, 8, 1, 2},
+ {3, 4, 1, 2},
+ {4, 4, 1, 4},
+ {5, 6, 1, 3},
+ {6, 7, 1, 3}
+ };
+ for (const QRect &span : spans)
view.setSpan(span.top(), span.left(), span.height(), span.width());
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
view.model()->removeRows(3, 3);
- QList<QRect> expectedSpans;
- expectedSpans << QRect(0, 1, 1, 2)
- << QRect(1, 2, 1, 1)
- << QRect(2, 2, 1, 2)
- << QRect(2, 5, 1, 2)
- << QRect(3, 4, 1, 1)
- << QRect(4, 3, 1, 2)
- << QRect(5, 3, 1, 3)
- << QRect(6, 4, 1, 3);
- foreach (QRect span, expectedSpans) {
+ static const QRect expectedSpans[] = {
+ {0, 1, 1, 2},
+ {1, 2, 1, 1},
+ {2, 2, 1, 2},
+ {2, 5, 1, 2},
+ {3, 4, 1, 1},
+ {4, 3, 1, 2},
+ {5, 3, 1, 3},
+ {6, 4, 1, 3}
+ };
+ for (const QRect &span : expectedSpans) {
QCOMPARE(view.columnSpan(span.top(), span.left()), span.width());
QCOMPARE(view.rowSpan(span.top(), span.left()), span.height());
}
@@ -3424,32 +3358,34 @@ void tst_QTableView::spansAfterColumnRemoval()
view.setModel(&model);
// Same set as above just swapping columns and rows.
- QList<QRect> spans;
- spans << QRect(0, 1, 1, 2)
- << QRect(1, 2, 1, 2)
- << QRect(2, 2, 1, 5)
- << QRect(2, 8, 1, 2)
- << QRect(3, 4, 1, 2)
- << QRect(4, 4, 1, 4)
- << QRect(5, 6, 1, 3)
- << QRect(6, 7, 1, 3);
- foreach (QRect span, spans)
- view.setSpan(span.left(), span.top(), span.width(), span.height());
+ static const QRect spans[] = {
+ {0, 1, 1, 2},
+ {1, 2, 1, 2},
+ {2, 2, 1, 5},
+ {2, 8, 1, 2},
+ {3, 4, 1, 2},
+ {4, 4, 1, 4},
+ {5, 6, 1, 3},
+ {6, 7, 1, 3}
+ };
+ for (const QRect &span : spans)
+ view.setSpan(span.left(), span.top(), span.width(), span.height());
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
view.model()->removeColumns(3, 3);
- QList<QRect> expectedSpans;
- expectedSpans << QRect(0, 1, 1, 2)
- << QRect(1, 2, 1, 1)
- << QRect(2, 2, 1, 2)
- << QRect(2, 5, 1, 2)
- << QRect(3, 4, 1, 1)
- << QRect(4, 3, 1, 2)
- << QRect(5, 3, 1, 3)
- << QRect(6, 4, 1, 3);
- foreach (QRect span, expectedSpans) {
+ static const QRect expectedSpans[] = {
+ {0, 1, 1, 2},
+ {1, 2, 1, 1},
+ {2, 2, 1, 2},
+ {2, 5, 1, 2},
+ {3, 4, 1, 1},
+ {4, 3, 1, 2},
+ {5, 3, 1, 3},
+ {6, 4, 1, 3}
+ };
+ for (const QRect &span : expectedSpans) {
QCOMPARE(view.columnSpan(span.left(), span.top()), span.height());
QCOMPARE(view.rowSpan(span.left(), span.top()), span.width());
}
@@ -3457,12 +3393,10 @@ void tst_QTableView::spansAfterColumnRemoval()
VERIFY_SPANS_CONSISTENCY(&view);
}
-Q_DECLARE_METATYPE(Qt::Key)
-
void tst_QTableView::editSpanFromDirections_data()
{
- QTest::addColumn<QList<Qt::Key> >("keyPresses");
- QTest::addColumn<QSharedPointer<QStandardItemModel> >("model");
+ QTest::addColumn<KeyList>("keyPresses");
+ QTest::addColumn<QSharedPointer<QStandardItemModel>>("model");
QTest::addColumn<int>("row");
QTest::addColumn<int>("column");
QTest::addColumn<int>("rowSpan");
@@ -3481,8 +3415,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+
| | ^ |
+---+---+ */
- QList<Qt::Key> keyPresses;
- keyPresses << Qt::Key_Right << Qt::Key_PageDown << Qt::Key_Up;
+ KeyList keyPresses {Qt::Key_Right, Qt::Key_PageDown, Qt::Key_Up};
QSharedPointer<QStandardItemModel> model(new QStandardItemModel(4, 2));
QTest::newRow("row span, bottom up")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(2, 1) << model->index(1, 1);
@@ -3496,8 +3429,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+
| | |
+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_Right << Qt::Key_Down;
+ keyPresses = {Qt::Key_Right, Qt::Key_Down};
model = QSharedPointer<QStandardItemModel>::create(4, 2);
QTest::newRow("row span, top down")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(1, 1) << model->index(1, 1);
@@ -3509,8 +3441,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+ +---+
| | | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_End << Qt::Key_Down << Qt::Key_Left;
+ keyPresses = {Qt::Key_End, Qt::Key_Down, Qt::Key_Left};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("row span, right to left")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(1, 1) << model->index(1, 1);
@@ -3522,8 +3453,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+ +---+
| > | c | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_PageDown << Qt::Key_Right;
+ keyPresses = {Qt::Key_PageDown, Qt::Key_Right};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("row span, left to right")
<< keyPresses << model << 1 << 1 << 2 << 1 << model->index(2, 1) << model->index(1, 1);
@@ -3535,8 +3465,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+---+
| ^ | | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_PageDown << Qt::Key_Up;
+ keyPresses = {Qt::Key_PageDown, Qt::Key_Up};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("col span, bottom up")
<< keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 0) << model->index(1, 0);
@@ -3548,8 +3477,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+---+
| | ^ | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_PageDown << Qt::Key_Right << Qt::Key_Up;
+ keyPresses = {Qt::Key_PageDown, Qt::Key_Right, Qt::Key_Up};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("col span, bottom up #2")
<< keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 1) << model->index(1, 0);
@@ -3561,8 +3489,7 @@ void tst_QTableView::editSpanFromDirections_data()
+---+---+---+
| | | |
+---+---+---+ */
- keyPresses.clear();
- keyPresses << Qt::Key_End << Qt::Key_Down;
+ keyPresses = {Qt::Key_End, Qt::Key_Down};
model = QSharedPointer<QStandardItemModel>::create(3, 3);
QTest::newRow("col span, top down")
<< keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 2) << model->index(1, 0);
@@ -3571,12 +3498,10 @@ void tst_QTableView::editSpanFromDirections_data()
class TableViewWithCursorExposed : public QTableView
{
public:
- TableViewWithCursorExposed() :
- QTableView() {
- }
+ using QTableView::QTableView;
-public:
- QModelIndex visualCursorIndex() {
+ QModelIndex visualCursorIndex()
+ {
QTableViewPrivate *d = static_cast<QTableViewPrivate*>(qt_widget_private(this));
return d->model->index(d->visualCursor.y(), d->visualCursor.x());
}
@@ -3584,7 +3509,7 @@ public:
void tst_QTableView::editSpanFromDirections()
{
- QFETCH(QList<Qt::Key>, keyPresses);
+ QFETCH(const KeyList, keyPresses);
QFETCH(QSharedPointer<QStandardItemModel>, model);
QFETCH(int, row);
QFETCH(int, column);
@@ -3602,9 +3527,8 @@ void tst_QTableView::editSpanFromDirections()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- foreach (Qt::Key key, keyPresses) {
+ for (Qt::Key key : keyPresses)
QTest::keyClick(&view, key);
- }
QCOMPARE(view.visualCursorIndex(), expectedVisualCursorIndex);
QCOMPARE(view.selectionModel()->currentIndex(), expectedEditedIndex);
@@ -3613,21 +3537,21 @@ void tst_QTableView::editSpanFromDirections()
QTRY_COMPARE(view.model()->data(expectedEditedIndex).toString(), QLatin1String("x"));
}
-class Model : public QAbstractTableModel {
-
-Q_OBJECT
-
+class Model : public QAbstractTableModel
+{
+ Q_OBJECT
public:
- Model(QObject * parent = 0) : QAbstractTableModel(parent) {
- }
+ using QAbstractTableModel::QAbstractTableModel;
- int rowCount(const QModelIndex &) const {
+ int rowCount(const QModelIndex &) const override
+ {
return rows;
}
- int columnCount(const QModelIndex &) const {
+ int columnCount(const QModelIndex &) const override
+ {
return columns;
}
- QVariant data(const QModelIndex &, int) const
+ QVariant data(const QModelIndex &, int) const override
{
return QVariant();
}
@@ -3637,8 +3561,8 @@ public:
endResetModel();
}
- int rows;
- int columns;
+ int rows = 0;
+ int columns = 0;
};
void tst_QTableView::checkHeaderReset()
@@ -3662,7 +3586,7 @@ void tst_QTableView::checkHeaderMinSize()
//viewport.
QTableView view;
QStringListModel m;
- m.setStringList( QStringList() << QLatin1String("one cell is enough"));
+ m.setStringList({QLatin1String("one cell is enough")});
view.setModel(&m);
//setting the minimum height on the horizontal header
@@ -3693,31 +3617,29 @@ void tst_QTableView::resizeToContents()
table2.verticalHeader()->setVisible(false);
- for(int i = 0;i<table.columnCount();i++) {
+ for (int i = 0; i < table.columnCount(); i++)
table.resizeColumnToContents(i);
- }
- for(int i = 0;i<table.rowCount();i++) {
+ for (int i = 0; i < table.rowCount(); i++)
table.resizeRowToContents(i);
- }
table2.resizeColumnsToContents();
table2.resizeRowsToContents();
table3.resizeColumnsToContents();
table3.resizeRowsToContents();
//now let's check the row/col sizes
- for(int i = 0;i<table.columnCount();i++) {
- QCOMPARE( table.columnWidth(i), table2.columnWidth(i));
- QCOMPARE( table2.columnWidth(i), table3.columnWidth(i));
+ for (int i = 0; i < table.columnCount(); i++) {
+ QCOMPARE(table.columnWidth(i), table2.columnWidth(i));
+ QCOMPARE(table2.columnWidth(i), table3.columnWidth(i));
}
- for(int i = 0;i<table.rowCount();i++) {
- QCOMPARE( table.rowHeight(i), table2.rowHeight(i));
- QCOMPARE( table2.rowHeight(i), table3.rowHeight(i));
+ for (int i = 0; i < table.rowCount(); i++) {
+ QCOMPARE(table.rowHeight(i), table2.rowHeight(i));
+ QCOMPARE(table2.rowHeight(i), table3.rowHeight(i));
}
}
QT_BEGIN_NAMESPACE
-extern bool Q_GUI_EXPORT qt_tab_all_widgets(); // qapplication.cpp
+extern bool Q_WIDGETS_EXPORT qt_tab_all_widgets(); // qapplication.cpp
QT_END_NAMESPACE
void tst_QTableView::tabFocus()
@@ -3747,57 +3669,57 @@ void tst_QTableView::tabFocus()
for (int i = 0; i < 2; ++i) {
// tab to view
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
QTRY_VERIFY(!window.hasFocus());
QVERIFY(view->hasFocus());
QVERIFY(!edit->hasFocus());
// tab to edit
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
QTRY_VERIFY(edit->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!view->hasFocus());
}
// backtab to view
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(view->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!edit->hasFocus());
// backtab to edit
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(edit->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!view->hasFocus());
- QStandardItemModel *model = new QStandardItemModel;
- view->setModel(model);
+ QStandardItemModel model;
+ view->setModel(&model);
// backtab to view
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(view->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!edit->hasFocus());
// backtab to edit
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(edit->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!view->hasFocus());
- model->insertRow(0, new QStandardItem("Hei"));
- model->insertRow(0, new QStandardItem("Hei"));
- model->insertRow(0, new QStandardItem("Hei"));
+ model.insertRow(0, new QStandardItem("Hei"));
+ model.insertRow(0, new QStandardItem("Hei"));
+ model.insertRow(0, new QStandardItem("Hei"));
// backtab to view
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(view->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!edit->hasFocus());
// backtab to edit doesn't work
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QVERIFY(!window.hasFocus());
QVERIFY(view->hasFocus());
QVERIFY(!edit->hasFocus());
@@ -3805,41 +3727,38 @@ void tst_QTableView::tabFocus()
view->setTabKeyNavigation(false);
// backtab to edit
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab);
QTRY_VERIFY(edit->hasFocus());
QVERIFY(!window.hasFocus());
QVERIFY(!view->hasFocus());
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
QTRY_VERIFY(view->hasFocus());
- QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab);
+ QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab);
QTRY_VERIFY(edit->hasFocus());
-
- delete model;
}
class BigModel : public QAbstractTableModel
{
Q_OBJECT
public:
- virtual QVariant data(const QModelIndex &index,
- int role = Qt::DisplayRole) const
+ QVariant data(const QModelIndex &index,
+ int role = Qt::DisplayRole) const override
{
if (role == Qt::DisplayRole)
return QString::number(index.column()) + QLatin1String(" - ") + QString::number(index.row());
return QVariant();
}
-
- int rowCount(const QModelIndex & parent = QModelIndex()) const
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override
{
- Q_UNUSED(parent);
+ Q_UNUSED(parent)
return 10000000;
}
- int columnCount(const QModelIndex & parent = QModelIndex()) const
+ int columnCount(const QModelIndex &parent = QModelIndex()) const override
{
- Q_UNUSED(parent);
+ Q_UNUSED(parent)
return 20000000;
}
};
@@ -3868,7 +3787,7 @@ void tst_QTableView::selectionSignal()
view.resize(200, 200);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(2, 0)).center());
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(model.index(2, 0)).center());
}
void tst_QTableView::setCurrentIndex()
@@ -3894,14 +3813,14 @@ void tst_QTableView::setCurrentIndex()
class task173773_EventFilter : public QObject
{
- int paintEventCount_;
+ int paintEventCount_ = 0;
public:
- task173773_EventFilter() : paintEventCount_(0) {}
+ using QObject::QObject;
int paintEventCount() const { return paintEventCount_; }
private:
- bool eventFilter(QObject *obj, QEvent *e)
+ bool eventFilter(QObject *obj, QEvent *e) override
{
- Q_UNUSED(obj);
+ Q_UNUSED(obj)
if (e->type() == QEvent::Paint)
++paintEventCount_;
return false;
@@ -4030,25 +3949,25 @@ void tst_QTableView::task248688_autoScrollNavigation()
#if QT_CONFIG(wheelevent)
void tst_QTableView::mouseWheel_data()
{
- QTest::addColumn<int>("scrollMode");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("scrollMode");
QTest::addColumn<int>("delta");
QTest::addColumn<int>("horizontalPositon");
QTest::addColumn<int>("verticalPosition");
QTest::newRow("scroll up per item")
- << int(QAbstractItemView::ScrollPerItem) << 120
- << 10 - qApp->wheelScrollLines() << 10 - qApp->wheelScrollLines();
+ << QAbstractItemView::ScrollPerItem << 120
+ << 10 - QApplication::wheelScrollLines() << 10 - QApplication::wheelScrollLines();
QTest::newRow("scroll down per item")
- << int(QAbstractItemView::ScrollPerItem) << -120
- << 10 + qApp->wheelScrollLines() << 10 + qApp->wheelScrollLines();
+ << QAbstractItemView::ScrollPerItem << -120
+ << 10 + QApplication::wheelScrollLines() << 10 + QApplication::wheelScrollLines();
QTest::newRow("scroll down per pixel")
- << int(QAbstractItemView::ScrollPerPixel) << -120
- << 10 + qApp->wheelScrollLines() * 91 << 10 + qApp->wheelScrollLines() * 46;
+ << QAbstractItemView::ScrollPerPixel << -120
+ << 10 + QApplication::wheelScrollLines() * 91 << 10 + QApplication::wheelScrollLines() * 46;
}
void tst_QTableView::mouseWheel()
{
- QFETCH(int, scrollMode);
+ QFETCH(QAbstractItemView::ScrollMode, scrollMode);
QFETCH(int, delta);
QFETCH(int, horizontalPositon);
QFETCH(int, verticalPosition);
@@ -4068,8 +3987,8 @@ void tst_QTableView::mouseWheel()
for (int c = 0; c < 100; ++c)
view.setColumnWidth(c, 100);
- view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)scrollMode);
- view.setVerticalScrollMode((QAbstractItemView::ScrollMode)scrollMode);
+ view.setHorizontalScrollMode(scrollMode);
+ view.setVerticalScrollMode(scrollMode);
view.horizontalScrollBar()->setValue(10);
view.verticalScrollBar()->setValue(10);
@@ -4168,15 +4087,15 @@ void tst_QTableView::task191545_dragSelectRows()
QWidget *vHeaderVp = vHeader->viewport();
QPoint rowPos(cellRect.center());
QMouseEvent rowPressEvent(QEvent::MouseButtonPress, rowPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(vHeaderVp, &rowPressEvent);
+ QCoreApplication::sendEvent(vHeaderVp, &rowPressEvent);
for (int i = 0; i < 4; ++i) {
rowPos.setY(rowPos.y() + cellRect.height());
QMouseEvent moveEvent(QEvent::MouseMove, rowPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
- qApp->sendEvent(vHeaderVp, &moveEvent);
+ QCoreApplication::sendEvent(vHeaderVp, &moveEvent);
}
QMouseEvent rowReleaseEvent(QEvent::MouseButtonRelease, rowPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(vHeaderVp, &rowReleaseEvent);
+ QCoreApplication::sendEvent(vHeaderVp, &rowReleaseEvent);
for (int i = 0; i < 4; ++i) {
QModelIndex index = model.index(3 + i, 0, table.rootIndex());
@@ -4190,15 +4109,15 @@ void tst_QTableView::task191545_dragSelectRows()
QWidget *hHeaderVp = hHeader->viewport();
QPoint colPos((cellRect.left() + cellRect.right()) / 2, 5);
QMouseEvent colPressEvent(QEvent::MouseButtonPress, colPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(hHeaderVp, &colPressEvent);
+ QCoreApplication::sendEvent(hHeaderVp, &colPressEvent);
for (int i = 0; i < 4; ++i) {
colPos.setX(colPos.x() + cellRect.width());
QMouseEvent moveEvent(QEvent::MouseMove, colPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
- qApp->sendEvent(hHeaderVp, &moveEvent);
+ QCoreApplication::sendEvent(hHeaderVp, &moveEvent);
}
QMouseEvent colReleaseEvent(QEvent::MouseButtonRelease, colPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(hHeaderVp, &colReleaseEvent);
+ QCoreApplication::sendEvent(hHeaderVp, &colReleaseEvent);
for (int i = 0; i < 4; ++i) {
QModelIndex index = model.index(0, 3 + i, table.rootIndex());
@@ -4211,22 +4130,23 @@ void tst_QTableView::task191545_dragSelectRows()
QWidget *tableVp = table.viewport();
QPoint cellPos = cellRect.center();
QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &cellPressEvent);
+ QCoreApplication::sendEvent(tableVp, &cellPressEvent);
for (int i = 0; i < 6; ++i) {
cellPos.setX(cellPos.x() + cellRect.width());
cellPos.setY(cellPos.y() + cellRect.height());
QMouseEvent moveEvent(QEvent::MouseMove, cellPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &moveEvent);
+ QCoreApplication::sendEvent(tableVp, &moveEvent);
}
QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &cellReleaseEvent);
+ QCoreApplication::sendEvent(tableVp, &cellReleaseEvent);
- for (int i = 0; i < 6; ++i)
+ for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 6; ++j) {
QModelIndex index = model.index(2 + i, 2 + j, table.rootIndex());
QVERIFY(table.selectionModel()->isSelected(index));
}
+ }
}
{
@@ -4234,23 +4154,24 @@ void tst_QTableView::task191545_dragSelectRows()
QWidget *tableVp = table.viewport();
QPoint cellPos = cellRect.center();
QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &cellPressEvent);
+ QCoreApplication::sendEvent(tableVp, &cellPressEvent);
for (int i = 0; i < 6; ++i) {
cellPos.setX(cellPos.x() + cellRect.width());
cellPos.setY(cellPos.y() + cellRect.height());
QMouseEvent moveEvent(QEvent::MouseMove, cellPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &moveEvent);
+ QCoreApplication::sendEvent(tableVp, &moveEvent);
}
QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier);
- qApp->sendEvent(tableVp, &cellReleaseEvent);
+ QCoreApplication::sendEvent(tableVp, &cellReleaseEvent);
QTest::qWait(200);
- for (int i = 0; i < 6; ++i)
+ for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 6; ++j) {
QModelIndex index = model.index(3 + i, 3 + j, table.rootIndex());
QVERIFY(!table.selectionModel()->isSelected(index));
}
+ }
}
}
@@ -4328,8 +4249,6 @@ void tst_QTableView::taskQTBUG_4516_clickOnRichTextLabel()
QTest::mouseClick(&label, Qt::LeftButton);
QCOMPARE(view.currentIndex(), model.index(1,1));
-
-
}
@@ -4371,14 +4290,14 @@ void tst_QTableView::taskQTBUG_5237_wheelEventOnHeader()
}
#endif
-class TestTableView : public QTableView {
-Q_OBJECT
+class TestTableView : public QTableView
+{
+ Q_OBJECT
public:
- TestTableView(QWidget *parent = 0) : QTableView(parent)
+ TestTableView(QWidget *parent = nullptr) : QTableView(parent)
{
- connect(this, SIGNAL(entered(QModelIndex)), this, SLOT(openEditor(QModelIndex)));
+ connect(this, &QTableView::entered, this, &TestTableView::openPersistentEditor);
}
- ~TestTableView(){}
public slots:
void onDataChanged()
{
@@ -4386,9 +4305,6 @@ public slots:
setRowHidden(i, model()->data(model()->index(i, 0)).toBool());
}
}
-
- void openEditor(const QModelIndex& index)
- { openPersistentEditor(index); }
};
@@ -4396,15 +4312,13 @@ void tst_QTableView::taskQTBUG_8585_crashForNoGoodReason()
{
QStandardItemModel model;
model.insertColumn(0, QModelIndex());
- for(int i = 0; i < 20; i++)
- {
+ for (int i = 0; i < 20; i++)
model.insertRow(i);
- }
TestTableView w;
w.setMouseTracking(true);
w.setModel(&model);
- connect(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), &w, SLOT(onDataChanged()));
+ connect(&model, &QStandardItemModel::dataChanged, &w, &TestTableView::onDataChanged);
w.show();
QVERIFY(QTest::qWaitForWindowExposed(&w));
for (int i = 0; i < 10; i++)
@@ -4418,10 +4332,7 @@ void tst_QTableView::taskQTBUG_8585_crashForNoGoodReason()
class TableView7774 : public QTableView
{
public:
- QRegion visualRegionForSelection(const QItemSelection &selection) const
- {
- return QTableView::visualRegionForSelection(selection);
- }
+ using QTableView::visualRegionForSelection;
};
void tst_QTableView::taskQTBUG_7774_RtoLVisualRegionForSelection()
diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
index 6184962d93..f640996690 100644
--- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
+++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp
@@ -26,15 +26,12 @@
**
****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <qeventloop.h>
-#include <qlist.h>
-#include <qpair.h>
-#include <qheaderview.h>
-#include <qlineedit.h>
-
-#include <qtablewidget.h>
+#include <QHeaderView>
+#include <QLineEdit>
+#include <QMimeData>
+#include <QSignalSpy>
+#include <QTableWidget>
+#include <QTest>
class QObjectTableItem : public QObject, public QTableWidgetItem
{
@@ -46,11 +43,10 @@ class tst_QTableWidget : public QObject
Q_OBJECT
public:
- tst_QTableWidget();
+ using QObject::QObject;
private slots:
void initTestCase();
- void cleanupTestCase();
void init();
void getSetCheck();
void clear();
@@ -97,12 +93,12 @@ private slots:
#endif
private:
- QTableWidget *testWidget;
+ std::unique_ptr<QTableWidget> testWidget;
};
-typedef QPair<int, int> IntPair;
-typedef QList<int> IntList;
-typedef QList<IntPair> IntIntList;
+using IntPair = QPair<int, int>;
+using IntList = QVector<int>;
+using IntIntList = QVector<IntPair>;
Q_DECLARE_METATYPE(QTableWidgetSelectionRange)
@@ -143,45 +139,36 @@ void tst_QTableWidget::getSetCheck()
obj1.setItem(3, 3, new QTableWidgetItem("3,3"));
obj1.setCurrentItem(var3);
QCOMPARE(var3, obj1.currentItem());
- obj1.setCurrentItem((QTableWidgetItem *)0);
- QCOMPARE((QTableWidgetItem *)0, obj1.currentItem());
- obj1.setItem(0, 0, 0);
- QCOMPARE((QTableWidgetItem *)0, obj1.item(0, 0));
+ obj1.setCurrentItem(nullptr);
+ QCOMPARE(obj1.currentItem(), nullptr);
+ obj1.setItem(0, 0, nullptr);
+ QCOMPARE(obj1.item(0, 0), nullptr);
// const QTableWidgetItem * QTableWidget::itemPrototype()
// void QTableWidget::setItemPrototype(const QTableWidgetItem *)
const QTableWidgetItem *var4 = new QTableWidgetItem;
obj1.setItemPrototype(var4);
QCOMPARE(var4, obj1.itemPrototype());
- obj1.setItemPrototype((QTableWidgetItem *)0);
- QCOMPARE((const QTableWidgetItem *)0, obj1.itemPrototype());
-}
-
-tst_QTableWidget::tst_QTableWidget(): testWidget(0)
-{
+ obj1.setItemPrototype(nullptr);
+ QCOMPARE(obj1.itemPrototype(), nullptr);
}
void tst_QTableWidget::initTestCase()
{
- testWidget = new QTableWidget();
+ testWidget.reset(new QTableWidget);
testWidget->show();
QApplication::setKeyboardInputInterval(100);
}
-void tst_QTableWidget::cleanupTestCase()
-{
- delete testWidget;
-}
-
void tst_QTableWidget::init()
{
testWidget->clear();
testWidget->setRowCount(5);
testWidget->setColumnCount(5);
- for (int row=0; row < testWidget->rowCount(); ++row)
+ for (int row = 0; row < testWidget->rowCount(); ++row)
testWidget->showRow(row);
- for (int column=0; column < testWidget->columnCount(); ++column)
+ for (int column = 0; column < testWidget->columnCount(); ++column)
testWidget->showColumn(column);
}
@@ -319,13 +306,15 @@ void tst_QTableWidget::item()
QCOMPARE(testWidget->rowCount(), rowCount);
QCOMPARE(testWidget->columnCount(), columnCount);
- for (int r = 0; r < testWidget->rowCount(); ++r)
+ for (int r = 0; r < testWidget->rowCount(); ++r) {
for (int c = 0; c < testWidget->columnCount(); ++c)
testWidget->setItem(r, c, new QTableWidgetItem(QString::number(r * c + c)));
+ }
- for (int r = 0; r < testWidget->rowCount(); ++r)
+ for (int r = 0; r < testWidget->rowCount(); ++r) {
for (int c = 0; c < testWidget->columnCount(); ++c)
QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c));
+ }
QTableWidgetItem *item = testWidget->item(row, column);
QCOMPARE(!!item, expectItem);
@@ -361,15 +350,17 @@ void tst_QTableWidget::takeItem()
QCOMPARE(testWidget->rowCount(), rowCount);
QCOMPARE(testWidget->columnCount(), columnCount);
- for (int r = 0; r < testWidget->rowCount(); ++r)
+ for (int r = 0; r < testWidget->rowCount(); ++r) {
for (int c = 0; c < testWidget->columnCount(); ++c)
testWidget->setItem(r, c, new QTableWidgetItem(QString::number(r * c + c)));
+ }
- for (int r = 0; r < testWidget->rowCount(); ++r)
+ for (int r = 0; r < testWidget->rowCount(); ++r) {
for (int c = 0; c < testWidget->columnCount(); ++c)
QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c));
+ }
- QSignalSpy spy(testWidget, &QTableWidget::cellChanged);
+ QSignalSpy spy(testWidget.get(), &QTableWidget::cellChanged);
QTableWidgetItem *item = testWidget->takeItem(row, column);
QCOMPARE(!!item, expectItem);
if (expectItem) {
@@ -516,11 +507,11 @@ void tst_QTableWidget::selectedItems()
{
QFETCH(int, rowCount);
QFETCH(int, columnCount);
- QFETCH(IntIntList, createItems);
- QFETCH(IntList, hiddenRows);
- QFETCH(IntList, hiddenColumns);
- QFETCH(QTableWidgetSelectionRange, selectionRange);
- QFETCH(IntIntList, expectedItems);
+ QFETCH(const IntIntList, createItems);
+ QFETCH(const IntList, hiddenRows);
+ QFETCH(const IntList, hiddenColumns);
+ QFETCH(const QTableWidgetSelectionRange, selectionRange);
+ QFETCH(const IntIntList, expectedItems);
// set dimensions and test they are ok
testWidget->setRowCount(rowCount);
@@ -529,15 +520,15 @@ void tst_QTableWidget::selectedItems()
QCOMPARE(testWidget->columnCount(), columnCount);
// create and set items
- foreach (IntPair intPair, createItems) {
+ for (const auto &intPair : createItems) {
testWidget->setItem(intPair.first, intPair.second,
new QTableWidgetItem(QString("Item %1 %2")
.arg(intPair.first).arg(intPair.second)));
}
// hide rows/columns
- foreach (int row, hiddenRows)
+ for (int row : hiddenRows)
testWidget->setRowHidden(row, true);
- foreach (int column, hiddenColumns)
+ for (int column : hiddenColumns)
testWidget->setColumnHidden(column, true);
// make sure we don't have any previous selections hanging around
@@ -557,31 +548,18 @@ void tst_QTableWidget::selectedItems()
}
// check that the correct number of items and the expected items are there
- QList<QTableWidgetItem *> selectedItems = testWidget->selectedItems();
+ const QList<QTableWidgetItem *> selectedItems = testWidget->selectedItems();
QCOMPARE(selectedItems.count(), expectedItems.count());
- foreach (IntPair intPair, expectedItems)
+ for (const auto &intPair : expectedItems)
QVERIFY(selectedItems.contains(testWidget->item(intPair.first, intPair.second)));
// check that setItemSelected agrees with selectedItems
- for (int row = 0; row<testWidget->rowCount(); ++row) {
- bool hidden = false;
- foreach (int hiddenRow, hiddenRows){
- if(hiddenRow == row){
- hidden = true;
- break;
- }
- }
- if (hidden)
+ for (int row = 0; row < testWidget->rowCount(); ++row) {
+ if (hiddenRows.contains(row))
continue;
- for (int column = 0; column<testWidget->columnCount(); ++column) {
- foreach (int hiddenColumn, hiddenColumns){
- if(hiddenColumn == column){
- hidden = true;
- break;
- }
- }
- if (hidden)
+ for (int column = 0; column < testWidget->columnCount(); ++column) {
+ if (hiddenColumns.contains(column))
continue;
QTableWidgetItem *item = testWidget->item(row, column);
@@ -621,11 +599,13 @@ void tst_QTableWidget::removeRow()
QCOMPARE(testWidget->columnCount(), columnCount);
// fill table with items
- for (int r = 0; r < rowCount; ++r)
- for (int c = 0; c < columnCount; ++c)
+ for (int r = 0; r < rowCount; ++r) {
+ const QString rRow = QString::number(r) + QLatin1Char(':');
+ for (int c = 0; c < columnCount; ++c) {
testWidget->setItem(r, c,
- new QTableWidgetItem(
- QString::number(r) + ":" + QString::number(c)));
+ new QTableWidgetItem(rRow + QString::number(c)));
+ }
+ }
// remove and compare the results
testWidget->removeRow(row);
@@ -633,14 +613,18 @@ void tst_QTableWidget::removeRow()
QCOMPARE(testWidget->columnCount(), expectedColumnCount);
// check if the correct items were removed
- for (int r = 0; r < expectedRowCount; ++r)
- for (int c = 0; c < expectedColumnCount; ++c)
+ for (int r = 0; r < expectedRowCount; ++r) {
+ const QString rRow = QString::number(r < row ? r : r + 1) +
+ QLatin1Char(':');
+ for (int c = 0; c < expectedColumnCount; ++c) {
if (r < row)
QCOMPARE(testWidget->item(r, c)->text(),
- QString::number(r) + ":" + QString::number(c));
+ rRow + QString::number(c));
else
QCOMPARE(testWidget->item(r, c)->text(),
- QString::number(r + 1) + ":" + QString::number(c));
+ rRow + QString::number(c));
+ }
+ }
}
void tst_QTableWidget::removeColumn_data()
@@ -673,11 +657,14 @@ void tst_QTableWidget::removeColumn()
QCOMPARE(testWidget->columnCount(), columnCount);
// fill table with items
- for (int r = 0; r < rowCount; ++r)
- for (int c = 0; c < columnCount; ++c)
+ for (int r = 0; r < rowCount; ++r) {
+ const QString rStr = QString::number(r) + QLatin1Char(':');
+ for (int c = 0; c < columnCount; ++c) {
testWidget->setItem(r, c,
new QTableWidgetItem(
- QString::number(r) + ":" + QString::number(c)));
+ rStr + QString::number(c)));
+ }
+ }
// remove and compare the results
testWidget->removeColumn(column);
@@ -686,14 +673,17 @@ void tst_QTableWidget::removeColumn()
// check if the correct items were removed
- for (int r = 0; r < expectedRowCount; ++r)
- for (int c = 0; c < expectedColumnCount; ++c)
+ for (int r = 0; r < expectedRowCount; ++r) {
+ const QString rStr = QString::number(r) + QLatin1Char(':');
+ for (int c = 0; c < expectedColumnCount; ++c) {
if (c < column)
QCOMPARE(testWidget->item(r, c)->text(),
- QString::number(r) + ":" + QString::number(c));
+ rStr + QString::number(c));
else
QCOMPARE(testWidget->item(r, c)->text(),
- QString::number(r) + ":" + QString::number(c + 1));
+ rStr + QString::number(c + 1));
+ }
+ }
}
void tst_QTableWidget::insertRow_data()
@@ -819,7 +809,7 @@ void tst_QTableWidget::itemOwnership()
item = new QObjectTableItem();
testWidget->setItem(0, 0, item);
delete item;
- QCOMPARE(testWidget->item(0, 0), (QTableWidgetItem *)0);
+ QCOMPARE(testWidget->item(0, 0), nullptr);
//delete vertical headeritem from outside
headerItem = new QObjectTableItem();
@@ -887,7 +877,7 @@ void tst_QTableWidget::sortItems_data()
{
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
- QTest::addColumn<int>("sortOrder");
+ QTest::addColumn<Qt::SortOrder>("sortOrder");
QTest::addColumn<int>("sortColumn");
QTest::addColumn<QStringList>("initial");
QTest::addColumn<QStringList>("expected");
@@ -897,7 +887,7 @@ void tst_QTableWidget::sortItems_data()
QTest::newRow("ascending")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
<< "0" << "a" << "o" << "8" << "k"
@@ -915,7 +905,7 @@ void tst_QTableWidget::sortItems_data()
QTest::newRow("descending")
<< 4 << 5
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< 0
<< (QStringList()
<< "0" << "a" << "o" << "8" << "k"
@@ -933,154 +923,151 @@ void tst_QTableWidget::sortItems_data()
QTest::newRow("empty table")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< (QStringList()
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< IntList()
<< IntList()
<< IntList();
-
QTest::newRow("half-empty table")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << "0" << 0 << 0 << 0 << 0
- << "3" << "d" << 0 << 0 << 0
- << "2" << "c" << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << "0" << QString() << QString() << QString() << QString()
+ << "3" << "d" << QString() << QString() << QString()
+ << "2" << "c" << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< (QStringList()
- << "0" << 0 << 0 << 0 << 0
- << "2" << "c" << 0 << 0 << 0
- << "3" << "d" << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << "0" << QString() << QString() << QString() << QString()
+ << "2" << "c" << QString() << QString() << QString()
+ << "3" << "d" << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< (IntList() << 0 << 2 << 1)
<< IntList()
<< IntList();
QTest::newRow("empty column, should not sort.")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 3
<< (QStringList()
- << "0" << 0 << 0 << 0 << 0
- << "3" << "d" << 0 << 0 << 0
- << "2" << "c" << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << "0" << QString() << QString() << QString() << QString()
+ << "3" << "d" << QString() << QString() << QString()
+ << "2" << "c" << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< (QStringList()
- << "0" << 0 << 0 << 0 << 0
- << "3" << "d" << 0 << 0 << 0
- << "2" << "c" << 0 << 0 << 0
- << 0 << 0 << 0 << 0 << 0)
+ << "0" << QString() << QString() << QString() << QString()
+ << "3" << "d" << QString() << QString() << QString()
+ << "2" << "c" << QString() << QString() << QString()
+ << QString() << QString() << QString() << QString() << QString())
<< IntList()
<< IntList()
<< IntList();
QTest::newRow("descending with null cell, the null cell should be placed at the bottom")
<< 4 << 5
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< 0
<< (QStringList()
- << "0" << "a" << "o" << "8" << "k"
- << "3" << "d" << "k" << "o" << "6"
- << "2" << "c" << "9" << "y" << "8"
- << 0 << "b" << "7" << "3" << "u")
+ << "0" << "a" << "o" << "8" << "k"
+ << "3" << "d" << "k" << "o" << "6"
+ << "2" << "c" << "9" << "y" << "8"
+ << QString() << "b" << "7" << "3" << "u")
<< (QStringList()
- << "3" << "d" << "k" << "o" << "6"
- << "2" << "c" << "9" << "y" << "8"
- << "0" << "a" << "o" << "8" << "k"
- << 0 << "b" << "7" << "3" << "u")
+ << "3" << "d" << "k" << "o" << "6"
+ << "2" << "c" << "9" << "y" << "8"
+ << "0" << "a" << "o" << "8" << "k"
+ << QString() << "b" << "7" << "3" << "u")
<< (IntList() << 2 << 0 << 1)
<< IntList()
<< IntList();
QTest::newRow("ascending with null cell, the null cell should be placed at the bottom")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << "0" << "a" << "o" << "8" << "k"
- << "3" << "d" << "k" << "o" << "6"
- << "2" << "c" << "9" << "y" << "8"
- << 0 << "b" << "7" << "3" << "u")
+ << "0" << "a" << "o" << "8" << "k"
+ << "3" << "d" << "k" << "o" << "6"
+ << "2" << "c" << "9" << "y" << "8"
+ << QString() << "b" << "7" << "3" << "u")
<< (QStringList()
- << "0" << "a" << "o" << "8" << "k"
- << "2" << "c" << "9" << "y" << "8"
- << "3" << "d" << "k" << "o" << "6"
- << 0 << "b" << "7" << "3" << "u")
+ << "0" << "a" << "o" << "8" << "k"
+ << "2" << "c" << "9" << "y" << "8"
+ << "3" << "d" << "k" << "o" << "6"
+ << QString() << "b" << "7" << "3" << "u")
<< (IntList() << 0 << 2 << 1)
<< IntList()
<< IntList();
QTest::newRow("ascending with null cells, the null cells should be placed at the bottom")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << "3" << "d" << "k" << "o" << "6"
- << "0" << "a" << "o" << "8" << "k"
- << 0 << "c" << "9" << "y" << "8"
- << 0 << "b" << "7" << "3" << "u")
+ << "3" << "d" << "k" << "o" << "6"
+ << "0" << "a" << "o" << "8" << "k"
+ << QString() << "c" << "9" << "y" << "8"
+ << QString() << "b" << "7" << "3" << "u")
<< (QStringList()
- << "0" << "a" << "o" << "8" << "k"
- << "3" << "d" << "k" << "o" << "6"
- << 0 << "c" << "9" << "y" << "8"
- << 0 << "b" << "7" << "3" << "u")
+ << "0" << "a" << "o" << "8" << "k"
+ << "3" << "d" << "k" << "o" << "6"
+ << QString() << "c" << "9" << "y" << "8"
+ << QString() << "b" << "7" << "3" << "u")
<< (IntList() << 1 << 0)
<< IntList()
<< IntList();
QTest::newRow("ascending... Check a bug in PersistentIndexes")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
<< "3" << "c" << "9" << "y" << "8"
<< "2" << "b" << "7" << "3" << "u"
<< "4" << "d" << "k" << "o" << "6"
- << "1" << "a" << "o" << "8" << "k"
- )
+ << "1" << "a" << "o" << "8" << "k")
<< (QStringList()
<< "1" << "a" << "o" << "8" << "k"
<< "2" << "b" << "7" << "3" << "u"
<< "3" << "c" << "9" << "y" << "8"
- << "4" << "d" << "k" << "o" << "6"
- )
+ << "4" << "d" << "k" << "o" << "6")
<< (IntList() << 2 << 1 << 3 << 0)
<< IntList()
<< IntList();
QTest::newRow("ascending with some null cells inbetween")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
- << 0 << "a" << "o" << "8" << "k"
- << "2" << "c" << "9" << "y" << "8"
- << 0 << "d" << "k" << "o" << "6"
- << "1" << "b" << "7" << "3" << "u")
+ << QString() << "a" << "o" << "8" << "k"
+ << "2" << "c" << "9" << "y" << "8"
+ << QString() << "d" << "k" << "o" << "6"
+ << "1" << "b" << "7" << "3" << "u")
<< (QStringList()
- << "1" << "b" << "7" << "3" << "u"
- << "2" << "c" << "9" << "y" << "8"
- << 0 << "a" << "o" << "8" << "k"
- << 0 << "d" << "k" << "o" << "6")
+ << "1" << "b" << "7" << "3" << "u"
+ << "2" << "c" << "9" << "y" << "8"
+ << QString() << "a" << "o" << "8" << "k"
+ << QString() << "d" << "k" << "o" << "6")
<< (IntList() << 1 << 0)
<< IntList()
<< IntList();
QTest::newRow("ascending hidden")
<< 4 << 5
- << static_cast<int>(Qt::AscendingOrder)
+ << Qt::AscendingOrder
<< 0
<< (QStringList()
<< "0" << "a" << "o" << "8" << "k"
@@ -1098,7 +1085,7 @@ void tst_QTableWidget::sortItems_data()
QTest::newRow("descending hidden")
<< 4 << 5
- << static_cast<int>(Qt::DescendingOrder)
+ << Qt::DescendingOrder
<< 0
<< (QStringList()
<< "0" << "a" << "o" << "8" << "k"
@@ -1119,7 +1106,7 @@ void tst_QTableWidget::sortItems()
{
QFETCH(int, rowCount);
QFETCH(int, columnCount);
- QFETCH(int, sortOrder);
+ QFETCH(Qt::SortOrder, sortOrder);
QFETCH(int, sortColumn);
QFETCH(QStringList, initial);
QFETCH(QStringList, expected);
@@ -1131,13 +1118,13 @@ void tst_QTableWidget::sortItems()
testWidget->setColumnCount(columnCount);
QAbstractItemModel *model = testWidget->model();
- QList<QPersistentModelIndex> persistent;
+ QVector<QPersistentModelIndex> persistent;
int ti = 0;
for (int r = 0; r < rowCount; ++r) {
for (int c = 0; c < columnCount; ++c) {
- QString str = initial.at(ti++);
- if (!str.isNull()) {
+ QString str = initial.at(ti++);
+ if (!str.isEmpty()) {
testWidget->setItem(r, c, new QTableWidgetItem(str));
}
}
@@ -1150,7 +1137,7 @@ void tst_QTableWidget::sortItems()
QCOMPARE(testWidget->verticalHeader()->hiddenSectionCount(), initialHidden.count());
- testWidget->sortItems(sortColumn, static_cast<Qt::SortOrder>(sortOrder));
+ testWidget->sortItems(sortColumn, sortOrder);
int te = 0;
for (int i = 0; i < rows.count(); ++i) {
@@ -1175,7 +1162,7 @@ void tst_QTableWidget::setItemWithSorting_data()
{
QTest::addColumn<int>("rowCount");
QTest::addColumn<int>("columnCount");
- QTest::addColumn<int>("sortOrder");
+ QTest::addColumn<Qt::SortOrder>("sortOrder");
QTest::addColumn<int>("sortColumn");
QTest::addColumn<QStringList>("initialValues");
QTest::addColumn<int>("row");
@@ -1187,7 +1174,7 @@ void tst_QTableWidget::setItemWithSorting_data()
QTest::newRow("2x1 no change (ascending)")
<< 2 << 1
- << static_cast<int>(Qt::AscendingOrder) << 0
+ << Qt::AscendingOrder << 0
<< (QStringList() << "0" << "1")
<< 1 << 0 << "2"
<< (QStringList() << "0" << "2")
@@ -1195,7 +1182,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< false;
QTest::newRow("2x1 no change (descending)")
<< 2 << 1
- << static_cast<int>(Qt::DescendingOrder) << 0
+ << Qt::DescendingOrder << 0
<< (QStringList() << "1" << "0")
<< 0 << 0 << "2"
<< (QStringList() << "2" << "0")
@@ -1203,7 +1190,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< false;
QTest::newRow("2x1 reorder (ascending)")
<< 2 << 1
- << static_cast<int>(Qt::AscendingOrder) << 0
+ << Qt::AscendingOrder << 0
<< (QStringList() << "0" << "1")
<< 0 << 0 << "2"
<< (QStringList() << "1" << "2")
@@ -1211,7 +1198,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< true;
QTest::newRow("2x1 reorder (descending)")
<< 2 << 1
- << static_cast<int>(Qt::DescendingOrder) << 0
+ << Qt::DescendingOrder << 0
<< (QStringList() << "1" << "0")
<< 1 << 0 << "2"
<< (QStringList() << "2" << "1")
@@ -1219,7 +1206,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< true;
QTest::newRow("2x2 no change (ascending)")
<< 2 << 2
- << static_cast<int>(Qt::AscendingOrder) << 0
+ << Qt::AscendingOrder << 0
<< (QStringList()
<< "0" << "00"
<< "1" << "11")
@@ -1231,7 +1218,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< false;
QTest::newRow("2x2 reorder (ascending)")
<< 2 << 2
- << static_cast<int>(Qt::AscendingOrder) << 0
+ << Qt::AscendingOrder << 0
<< (QStringList()
<< "0" << "00"
<< "1" << "11")
@@ -1243,7 +1230,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< true;
QTest::newRow("2x2 reorder (ascending, sortColumn = 1)")
<< 2 << 2
- << static_cast<int>(Qt::AscendingOrder) << 1
+ << Qt::AscendingOrder << 1
<< (QStringList()
<< "00" << "0"
<< "11" << "1")
@@ -1255,7 +1242,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< true;
QTest::newRow("2x2 no change (column != sortColumn)")
<< 2 << 2
- << static_cast<int>(Qt::AscendingOrder) << 1
+ << Qt::AscendingOrder << 1
<< (QStringList()
<< "00" << "0"
<< "11" << "1")
@@ -1267,7 +1254,7 @@ void tst_QTableWidget::setItemWithSorting_data()
<< false;
QTest::newRow("8x4 reorder (ascending, sortColumn = 3)")
<< 8 << 4
- << static_cast<int>(Qt::AscendingOrder) << 3
+ << Qt::AscendingOrder << 3
<< (QStringList()
<< "q" << "v" << "u" << "0"
<< "e" << "j" << "i" << "10"
@@ -1293,9 +1280,13 @@ void tst_QTableWidget::setItemWithSorting_data()
void tst_QTableWidget::setItemWithSorting()
{
+ static int dummy1 = qRegisterMetaType<QList<QPersistentModelIndex>>();
+ static int dummy2 = qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>();
+ Q_UNUSED(dummy1);
+ Q_UNUSED(dummy2);
QFETCH(int, rowCount);
QFETCH(int, columnCount);
- QFETCH(int, sortOrder);
+ QFETCH(Qt::SortOrder, sortOrder);
QFETCH(int, sortColumn);
QFETCH(QStringList, initialValues);
QFETCH(int, row);
@@ -1309,7 +1300,7 @@ void tst_QTableWidget::setItemWithSorting()
QTableWidget w(rowCount, columnCount);
QAbstractItemModel *model = w.model();
- QList<QPersistentModelIndex> persistent;
+ QVector<QPersistentModelIndex> persistent;
int ti = 0;
for (int r = 0; r < rowCount; ++r) {
@@ -1320,11 +1311,11 @@ void tst_QTableWidget::setItemWithSorting()
persistent << model->index(r, sortColumn);
}
- w.sortItems(sortColumn, static_cast<Qt::SortOrder>(sortOrder));
+ w.sortItems(sortColumn, sortOrder);
w.setSortingEnabled(true);
- QSignalSpy dataChangedSpy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
- QSignalSpy layoutChangedSpy(model, SIGNAL(layoutChanged()));
+ QSignalSpy dataChangedSpy(model, &QAbstractItemModel::dataChanged);
+ QSignalSpy layoutChangedSpy(model, &QAbstractItemModel::layoutChanged);
if (i == 0) {
// set a new item
@@ -1376,7 +1367,7 @@ public:
void tst_QTableWidget::itemData()
{
QTableWidgetDataChanged widget(2, 2);
- widget.setItem(0, 0, new QTableWidgetItem());
+ widget.setItem(0, 0, new QTableWidgetItem);
QTableWidgetItem *item = widget.item(0, 0);
QVERIFY(item);
item->setFlags(item->flags() | Qt::ItemIsEditable);
@@ -1399,7 +1390,7 @@ void tst_QTableWidget::setItemData()
{
QTableWidgetDataChanged table(10, 10);
table.setSortingEnabled(false);
- QSignalSpy dataChangedSpy(table.model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)));
+ QSignalSpy dataChangedSpy(table.model(), &QAbstractItemModel::dataChanged);
QTableWidgetItem *item = new QTableWidgetItem;
table.setItem(0, 0, item);
@@ -1432,11 +1423,11 @@ void tst_QTableWidget::cellWidget()
QTableWidget table(10, 10);
QWidget widget;
- QCOMPARE(table.cellWidget(5, 5), static_cast<QWidget*>(0));
+ QCOMPARE(table.cellWidget(5, 5), nullptr);
table.setCellWidget(5, 5, &widget);
QCOMPARE(table.cellWidget(5, 5), &widget);
table.removeCellWidget(5, 5);
- QCOMPARE(table.cellWidget(5, 5), static_cast<QWidget*>(0));
+ QCOMPARE(table.cellWidget(5, 5), nullptr);
}
void tst_QTableWidget::cellWidgetGeometry()
@@ -1463,27 +1454,29 @@ void tst_QTableWidget::cellWidgetGeometry()
void tst_QTableWidget::sizeHint_data()
{
- QTest::addColumn<int>("scrollBarPolicy");
+ QTest::addColumn<Qt::ScrollBarPolicy>("scrollBarPolicy");
QTest::addColumn<QSize>("viewSize");
- QTest::newRow("ScrollBarAlwaysOn") << static_cast<int>(Qt::ScrollBarAlwaysOn) << QSize();
- QTest::newRow("ScrollBarAlwaysOff") << static_cast<int>(Qt::ScrollBarAlwaysOff) << QSize();
+ QTest::newRow("ScrollBarAlwaysOn") << Qt::ScrollBarAlwaysOn << QSize();
+ QTest::newRow("ScrollBarAlwaysOff") << Qt::ScrollBarAlwaysOff << QSize();
// make sure the scrollbars are shown by resizing the view to 40x40
- QTest::newRow("ScrollBarAsNeeded (40x40)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(40, 40);
- QTest::newRow("ScrollBarAsNeeded (1000x1000)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(1000, 1000);
+ QTest::newRow("ScrollBarAsNeeded (40x40)") << Qt::ScrollBarAsNeeded << QSize(40, 40);
+ QTest::newRow("ScrollBarAsNeeded (1000x1000)") << Qt::ScrollBarAsNeeded << QSize(1000, 1000);
}
void tst_QTableWidget::sizeHint()
{
- QFETCH(int, scrollBarPolicy);
+ QFETCH(Qt::ScrollBarPolicy, scrollBarPolicy);
QFETCH(QSize, viewSize);
QTableWidget view(2, 2);
view.setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
- view.setVerticalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy));
- view.setHorizontalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy));
- for (int r = 0 ; r < view.rowCount(); ++r)
+ view.setVerticalScrollBarPolicy(scrollBarPolicy);
+ view.setHorizontalScrollBarPolicy(scrollBarPolicy);
+ for (int r = 0 ; r < view.rowCount(); ++r) {
+ const QString rStr = QString::number(r) + QLatin1Char('/');
for (int c = 0 ; c < view.columnCount(); ++c)
- view.setItem(r, c, new QTableWidgetItem(QString("%1/%2").arg(r).arg(c)));
+ view.setItem(r, c, new QTableWidgetItem(rStr + QString::number(c)));
+ }
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
@@ -1520,7 +1513,7 @@ void tst_QTableWidget::task231094()
if (y == 1)
twi->setFlags(Qt::ItemIsEnabled);
else
- twi->setFlags(0);
+ twi->setFlags({});
tw.setItem(y, x, twi);
}
}
@@ -1558,15 +1551,15 @@ void tst_QTableWidget::task262056_sortDuplicate()
testWidget->setColumnCount(2);
testWidget->setRowCount(8);
testWidget->setSortingEnabled(true);
- QStringList items = (QStringList() << "AAA" << "BBB" << "CCC" << "CCC" << "DDD"\
- << "EEE" << "FFF" << "GGG");
- for (int i = 0; i<8; i++ ) {
+ const QStringList items({"AAA", "BBB", "CCC", "CCC", "DDD",
+ "EEE", "FFF", "GGG"});
+ for (int i = 0; i < 8; i++ ) {
QTableWidgetItem *twi = new QTableWidgetItem(items.at(i));
- testWidget->setItem(i,0,twi);
- testWidget->setItem(i,1,new QTableWidgetItem(QLatin1String("item ") + QString::number(i)));
+ testWidget->setItem(i, 0, twi);
+ testWidget->setItem(i, 1, new QTableWidgetItem(QLatin1String("item ") + QString::number(i)));
}
testWidget->sortItems(0, Qt::AscendingOrder);
- QSignalSpy layoutChangedSpy(testWidget->model(), SIGNAL(layoutChanged()));
+ QSignalSpy layoutChangedSpy(testWidget->model(), &QAbstractItemModel::layoutChanged);
testWidget->item(3,0)->setBackground(Qt::red);
QCOMPARE(layoutChangedSpy.count(),0);
@@ -1586,18 +1579,14 @@ void tst_QTableWidget::itemWithHeaderItems()
QTableWidgetItem *item1_0 = new QTableWidgetItem(QTableWidgetItem::UserType);
table.setItem(1, 0, item1_0);
- QCOMPARE(table.item(0, 1), static_cast<QTableWidgetItem *>(0));
+ QCOMPARE(table.item(0, 1), nullptr);
}
class TestTableWidget : public QTableWidget
{
Q_OBJECT
public:
- TestTableWidget(int rows, int columns, QWidget *parent = 0)
- : QTableWidget(rows, columns, parent)
- {
- }
-
+ using QTableWidget::QTableWidget;
using QTableWidget::mimeData;
using QTableWidget::indexFromItem;
using QTableWidget::keyPressEvent;
@@ -1661,18 +1650,19 @@ void tst_QTableWidget::selectedRowAfterSorting()
{
TestTableWidget table(3,3);
table.setSelectionBehavior(QAbstractItemView::SelectRows);
- for (int r = 0; r < 3; r++)
+ for (int r = 0; r < 3; r++) {
for (int c = 0; c < 3; c++)
- table.setItem(r,c,new QTableWidgetItem(QStringLiteral("0")));
+ table.setItem(r, c, new QTableWidgetItem(QStringLiteral("0")));
+ }
QHeaderView *localHorizontalHeader = table.horizontalHeader();
localHorizontalHeader->setSortIndicator(1,Qt::DescendingOrder);
table.setProperty("sortingEnabled",true);
table.selectRow(1);
table.item(1,1)->setText("9");
QCOMPARE(table.selectedItems().count(),3);
- foreach (QTableWidgetItem *item, table.selectedItems()) {
- QCOMPARE(item->row(),0);
- }
+ const auto selectedItems = table.selectedItems();
+ for (QTableWidgetItem *item : selectedItems)
+ QCOMPARE(item->row(), 0);
}
void tst_QTableWidget::search()
@@ -1717,10 +1707,11 @@ void tst_QTableWidget::search()
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void tst_QTableWidget::clearItemData()
{
- QTableWidget table(3,3);
- for (int r = 0; r < 3; r++)
+ QTableWidget table(3, 3);
+ for (int r = 0; r < 3; r++) {
for (int c = 0; c < 3; c++)
- table.setItem(r,c,new QTableWidgetItem(QStringLiteral("0")));
+ table.setItem(r, c, new QTableWidgetItem(QStringLiteral("0")));
+ }
QSignalSpy dataChangeSpy(table.model(), &QAbstractItemModel::dataChanged);
QVERIFY(dataChangeSpy.isValid());
QVERIFY(!table.model()->clearItemData(QModelIndex()));
diff --git a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
index 8c262ff3a5..84120c70e9 100644
--- a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
+++ b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp
@@ -115,6 +115,7 @@ private slots:
void context();
void duplicatedShortcutOverride();
void shortcutToFocusProxy();
+ void deleteLater();
protected:
static Qt::KeyboardModifiers toButtons( int key );
@@ -1263,5 +1264,14 @@ void tst_QShortcut::shortcutToFocusProxy()
QCOMPARE(le.text(), QString());
}
+void tst_QShortcut::deleteLater()
+{
+ QWidget w;
+ QPointer<QShortcut> sc(new QShortcut(QKeySequence(Qt::Key_1), &w));
+ sc->deleteLater();
+ QTRY_VERIFY(!sc);
+}
+
+
QTEST_MAIN(tst_QShortcut)
#include "tst_qshortcut.moc"
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 51049ecd81..3e372b76f5 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -7704,9 +7704,7 @@ void tst_QWidget::moveWindowInShowEvent()
void tst_QWidget::repaintWhenChildDeleted()
{
#ifdef Q_OS_WIN
- if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista) {
- QTest::qWait(1000);
- }
+ QTest::qWait(1000);
#endif
ColorWidget w(nullptr, Qt::FramelessWindowHint, Qt::red);
w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
@@ -8903,13 +8901,13 @@ void tst_QWidget::translucentWidget()
#ifdef Q_OS_WIN
QWidget *desktopWidget = QApplication::desktop()->screen(0);
- if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista)
- widgetSnapshot = grabWindow(desktopWidget->windowHandle(), labelPos.x(), labelPos.y(), label.width(), label.height());
- else
+ widgetSnapshot = grabWindow(desktopWidget->windowHandle(), labelPos.x(), labelPos.y(), label.width(), label.height());
+#else
+ widgetSnapshot = label.grab(QRect(QPoint(0, 0), label.size()));
#endif
- widgetSnapshot = label.grab(QRect(QPoint(0, 0), label.size()));
const QImage actual = widgetSnapshot.toImage().convertToFormat(QImage::Format_RGB32);
- const QImage expected = pm.toImage().scaled(label.devicePixelRatioF() * pm.size());
+ QImage expected = pm.toImage().scaled(label.devicePixelRatioF() * pm.size());
+ expected.setDevicePixelRatio(label.devicePixelRatioF());
if (m_platform == QStringLiteral("winrt"))
QEXPECT_FAIL("", "WinRT: This fails. QTBUG-68297.", Abort);
QCOMPARE(actual.size(),expected.size());
diff --git a/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp b/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp
index 3408fc0946..f2f9cfc009 100644
--- a/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp
+++ b/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp
@@ -171,11 +171,8 @@ void tst_QProgressBar::format()
bar.setFormat("%v of %m (%p%)");
qApp->processEvents();
-#ifndef Q_OS_MAC
+#if !defined(Q_OS_MACOS) && !defined(Q_OS_WIN)
// Animated scroll bars get paint events all the time
-#ifdef Q_OS_WIN
- if (QOperatingSystemVersion::current() < QOperatingSystemVersion::WindowsVista)
-#endif
QVERIFY(!bar.repainted);
#endif
diff --git a/tests/auto/widgets/widgets/qsplashscreen/tst_qsplashscreen.cpp b/tests/auto/widgets/widgets/qsplashscreen/tst_qsplashscreen.cpp
index 91a9c49b00..64e4582366 100644
--- a/tests/auto/widgets/widgets/qsplashscreen/tst_qsplashscreen.cpp
+++ b/tests/auto/widgets/widgets/qsplashscreen/tst_qsplashscreen.cpp
@@ -36,6 +36,7 @@ class tst_QSplashScreen : public QObject
private slots:
void checkCloseTime();
+ void checkScreenConstructor();
};
class CloseEventSplash : public QSplashScreen
@@ -69,5 +70,16 @@ void tst_QSplashScreen::checkCloseTime()
QVERIFY(w.windowHandle()->isExposed());
}
+void tst_QSplashScreen::checkScreenConstructor()
+{
+ for (const auto screen : QGuiApplication::screens()) {
+ QSplashScreen splash(screen);
+ splash.show();
+ QCOMPARE(splash.screen(), screen);
+ QVERIFY(splash.windowHandle());
+ QCOMPARE(splash.windowHandle()->screen(), screen);
+ }
+}
+
QTEST_MAIN(tst_QSplashScreen)
#include "tst_qsplashscreen.moc"
diff --git a/tests/baselineserver/shared/qbaselinetest.cpp b/tests/baselineserver/shared/qbaselinetest.cpp
index 11fb208f20..3587cd01ea 100644
--- a/tests/baselineserver/shared/qbaselinetest.cpp
+++ b/tests/baselineserver/shared/qbaselinetest.cpp
@@ -28,10 +28,8 @@
#include "qbaselinetest.h"
#include "baselineprotocol.h"
-#if QT_CONFIG(process)
-# include <QtCore/QProcess>
-#endif
#include <QtCore/QDir>
+#include <QFile>
#define MAXCMDLINEARGS 128
@@ -146,20 +144,15 @@ void addClientProperty(const QString& key, const QString& value)
*/
void fetchCustomClientProperties()
{
-#if !QT_CONFIG(process)
- QSKIP("This test requires QProcess support");
-#else
- QString script = "hostinfo.sh"; //### TBD: Windows implementation (hostinfo.bat)
-
- QProcess runScript;
- runScript.setWorkingDirectory(QCoreApplication::applicationDirPath());
- runScript.start("sh", QStringList() << script, QIODevice::ReadOnly);
- if (!runScript.waitForFinished(5000) || runScript.error() != QProcess::UnknownError) {
- qWarning() << "QBaselineTest: Error running script" << runScript.workingDirectory() + QDir::separator() + script << ":" << runScript.errorString();
- qDebug() << " stderr:" << runScript.readAllStandardError().trimmed();
- }
- while (!runScript.atEnd()) {
- QByteArray line = runScript.readLine().trimmed(); // ###local8bit? utf8?
+ QFile file("hostinfo.txt");
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
+ return;
+ QTextStream in(&file);
+
+ while (!in.atEnd()) {
+ QString line = in.readLine().trimmed(); // ###local8bit? utf8?
+ if (line.startsWith(QLatin1Char('#'))) // Ignore comments in file
+ continue;
QString key, val;
int colonPos = line.indexOf(':');
if (colonPos > 0) {
@@ -171,7 +164,6 @@ void fetchCustomClientProperties()
else
qDebug() << "Unparseable script output ignored:" << line;
}
-#endif // QT_CONFIG(process)
}
diff --git a/tests/benchmarks/corelib/thread/qreadwritelock/qreadwritelock.pro b/tests/benchmarks/corelib/thread/qreadwritelock/qreadwritelock.pro
index 86102adecd..a1827d0276 100644
--- a/tests/benchmarks/corelib/thread/qreadwritelock/qreadwritelock.pro
+++ b/tests/benchmarks/corelib/thread/qreadwritelock/qreadwritelock.pro
@@ -1,6 +1,7 @@
TEMPLATE = app
TARGET = tst_bench_qreadwritelock
-QT = core testlib
+QT = core-private testlib
SOURCES += tst_qreadwritelock.cpp
CONFIG += c++14 # for std::shared_timed_mutex
+CONFIG += c++1z # for std::shared_mutex
diff --git a/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp b/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp
index fcf600a059..1d47d98657 100644
--- a/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp
+++ b/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp
@@ -28,12 +28,14 @@
#include <QtCore/QtCore>
#include <QtTest/QtTest>
+#include <QtCore/private/qmemory_p.h>
#include <mutex>
#if QT_HAS_INCLUDE(<shared_mutex>)
#if __cplusplus > 201103L
#include <shared_mutex>
#endif
#endif
+#include <vector>
// Wrapers that take pointers instead of reference to have the same interface as Qt
template <typename T>
@@ -63,6 +65,8 @@ private slots:
void uncontended();
void readOnly_data();
void readOnly();
+ void writeOnly_data();
+ void writeOnly();
// void readWrite();
};
@@ -106,6 +110,14 @@ void tst_QReadWriteLock::uncontended_data()
<< FunctionPtrHolder(testUncontended<QReadWriteLock, QWriteLocker>);
QTest::newRow("std::mutex") << FunctionPtrHolder(
testUncontended<std::mutex, LockerWrapper<std::unique_lock<std::mutex>>>);
+#ifdef __cpp_lib_shared_mutex
+ QTest::newRow("std::shared_mutex, read") << FunctionPtrHolder(
+ testUncontended<std::shared_mutex,
+ LockerWrapper<std::shared_lock<std::shared_mutex>>>);
+ QTest::newRow("std::shared_mutex, write") << FunctionPtrHolder(
+ testUncontended<std::shared_mutex,
+ LockerWrapper<std::unique_lock<std::shared_mutex>>>);
+#endif
#if defined __cpp_lib_shared_timed_mutex
QTest::newRow("std::shared_timed_mutex, read") << FunctionPtrHolder(
testUncontended<std::shared_timed_mutex,
@@ -130,7 +142,7 @@ void testReadOnly()
struct Thread : QThread
{
Mutex *lock;
- void run()
+ void run() override
{
for (int i = 0; i < Iterations; ++i) {
QString s = QString::number(i); // Do something outside the lock
@@ -140,21 +152,20 @@ void testReadOnly()
}
};
Mutex lock;
- QVector<QThread *> threads;
+ std::vector<std::unique_ptr<Thread>> threads;
for (int i = 0; i < threadCount; ++i) {
- auto t = new Thread;
+ auto t = qt_make_unique<Thread>();
t->lock = &lock;
- threads.append(t);
+ threads.push_back(std::move(t));
}
QBENCHMARK {
- for (auto t : threads) {
+ for (auto &t : threads) {
t->start();
}
- for (auto t : threads) {
+ for (auto &t : threads) {
t->wait();
}
}
- qDeleteAll(threads);
}
void tst_QReadWriteLock::readOnly_data()
@@ -166,6 +177,11 @@ void tst_QReadWriteLock::readOnly_data()
QTest::newRow("QReadWriteLock") << FunctionPtrHolder(testReadOnly<QReadWriteLock, QReadLocker>);
QTest::newRow("std::mutex") << FunctionPtrHolder(
testReadOnly<std::mutex, LockerWrapper<std::unique_lock<std::mutex>>>);
+#ifdef __cpp_lib_shared_mutex
+ QTest::newRow("std::shared_mutex") << FunctionPtrHolder(
+ testReadOnly<std::shared_mutex,
+ LockerWrapper<std::shared_lock<std::shared_mutex>>>);
+#endif
#if defined __cpp_lib_shared_timed_mutex
QTest::newRow("std::shared_timed_mutex") << FunctionPtrHolder(
testReadOnly<std::shared_timed_mutex,
@@ -179,5 +195,66 @@ void tst_QReadWriteLock::readOnly()
holder.value();
}
+static QString global_string;
+
+template <typename Mutex, typename Locker>
+void testWriteOnly()
+{
+ struct Thread : QThread
+ {
+ Mutex *lock;
+ void run() override
+ {
+ for (int i = 0; i < Iterations; ++i) {
+ QString s = QString::number(i); // Do something outside the lock
+ Locker locker(lock);
+ global_string = s;
+ }
+ }
+ };
+ Mutex lock;
+ std::vector<std::unique_ptr<Thread>> threads;
+ for (int i = 0; i < threadCount; ++i) {
+ auto t = qt_make_unique<Thread>();
+ t->lock = &lock;
+ threads.push_back(std::move(t));
+ }
+ QBENCHMARK {
+ for (auto &t : threads) {
+ t->start();
+ }
+ for (auto &t : threads) {
+ t->wait();
+ }
+ }
+}
+
+void tst_QReadWriteLock::writeOnly_data()
+{
+ QTest::addColumn<FunctionPtrHolder>("holder");
+
+ // QTest::newRow("nothing") << FunctionPtrHolder(testWriteOnly<int, FakeLock>);
+ QTest::newRow("QMutex") << FunctionPtrHolder(testWriteOnly<QMutex, QMutexLocker>);
+ QTest::newRow("QReadWriteLock") << FunctionPtrHolder(testWriteOnly<QReadWriteLock, QWriteLocker>);
+ QTest::newRow("std::mutex") << FunctionPtrHolder(
+ testWriteOnly<std::mutex, LockerWrapper<std::unique_lock<std::mutex>>>);
+#ifdef __cpp_lib_shared_mutex
+ QTest::newRow("std::shared_mutex") << FunctionPtrHolder(
+ testWriteOnly<std::shared_mutex,
+ LockerWrapper<std::unique_lock<std::shared_mutex>>>);
+#endif
+#if defined __cpp_lib_shared_timed_mutex
+ QTest::newRow("std::shared_timed_mutex") << FunctionPtrHolder(
+ testWriteOnly<std::shared_timed_mutex,
+ LockerWrapper<std::unique_lock<std::shared_timed_mutex>>>);
+#endif
+}
+
+void tst_QReadWriteLock::writeOnly()
+{
+ QFETCH(FunctionPtrHolder, holder);
+ holder.value();
+}
+
QTEST_MAIN(tst_QReadWriteLock)
#include "tst_qreadwritelock.moc"
diff --git a/tests/benchmarks/gui/image/qimageconversion/tst_qimageconversion.cpp b/tests/benchmarks/gui/image/qimageconversion/tst_qimageconversion.cpp
index b88669e9ce..b8afb3bc05 100644
--- a/tests/benchmarks/gui/image/qimageconversion/tst_qimageconversion.cpp
+++ b/tests/benchmarks/gui/image/qimageconversion/tst_qimageconversion.cpp
@@ -342,6 +342,7 @@ void tst_QImageConversion::convertGenericInplace_data()
QImage argb6666 = argb32.convertToFormat(QImage::Format_ARGB6666_Premultiplied);
QImage argb4444 = argb32.convertToFormat(QImage::Format_ARGB4444_Premultiplied);
QImage rgb16 = argb32.convertToFormat(QImage::Format_RGB16);
+ QImage rgb30 = argb32.convertToFormat(QImage::Format_RGB30);
QImage rgb888 = argb32.convertToFormat(QImage::Format_RGB888);
QTest::newRow("argb32 -> argb32pm -> argb32") << argb32 << QImage::Format_ARGB32_Premultiplied;
@@ -370,6 +371,7 @@ void tst_QImageConversion::convertGenericInplace_data()
QTest::newRow("rgb16 -> rgb444 -> rgb16") << rgb16 << QImage::Format_RGB444;
QTest::newRow("rgb16 -> argb4444pm -> rgb16") << rgb16 << QImage::Format_ARGB4444_Premultiplied;
+ QTest::newRow("rgb30 -> bgr30 -> rgb30") << rgb30 << QImage::Format_BGR30;
QTest::newRow("rgb888 -> bgr888 -> rgb888") << rgb888 << QImage::Format_BGR888;
}
diff --git a/tests/manual/qgraphicslayout/flicker/window.h b/tests/manual/qgraphicslayout/flicker/window.h
index 3e7bc61731..c49b82704e 100644
--- a/tests/manual/qgraphicslayout/flicker/window.h
+++ b/tests/manual/qgraphicslayout/flicker/window.h
@@ -107,7 +107,7 @@ public:
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setBrush(m_brush);
- painter->drawRoundedRect(rect(), Qt::RelativeSize);
+ painter->drawRoundedRect(rect(), 25, 25, Qt::RelativeSize);
painter->drawLine(rect().topLeft(), rect().bottomRight());
painter->drawLine(rect().bottomLeft(), rect().topRight());
}
diff --git a/tests/manual/rhi/shared/examplefw.h b/tests/manual/rhi/shared/examplefw.h
index 1a29ef5f7e..4bd087473b 100644
--- a/tests/manual/rhi/shared/examplefw.h
+++ b/tests/manual/rhi/shared/examplefw.h
@@ -126,6 +126,7 @@ int sampleCount = 1;
QRhiSwapChain::Flags scFlags = 0;
QRhi::BeginFrameFlags beginFrameFlags = 0;
QRhi::EndFrameFlags endFrameFlags = 0;
+int framesUntilTdr = -1;
class Window : public QWindow
{
@@ -278,6 +279,10 @@ void Window::init()
if (graphicsApi == D3D11) {
QRhiD3D11InitParams params;
params.enableDebugLayer = true;
+ if (framesUntilTdr > 0) {
+ params.framesUntilKillingDeviceViaTdr = framesUntilTdr;
+ params.repeatDeviceKill = true;
+ }
m_r = QRhi::create(QRhi::D3D11, &params, rhiFlags);
}
#endif
@@ -461,8 +466,17 @@ int main(int argc, char **argv)
// Testing cleanup both with QWindow::close() (hitting X or Alt-F4) and
// QCoreApplication::quit() (e.g. what a menu widget would do) is important.
// Use this parameter for the latter.
- QCommandLineOption sdOption({ "s", "self-destruct" }, QLatin1String("Self destruct after 5 seconds"));
+ QCommandLineOption sdOption({ "s", "self-destruct" }, QLatin1String("Self-destruct after 5 seconds."));
cmdLineParser.addOption(sdOption);
+ // Attempt testing device lost situations on D3D at least.
+ QCommandLineOption tdrOption(QLatin1String("curse"), QLatin1String("Curse the graphics device. "
+ "(generate a device reset every <count> frames when on D3D11)"),
+ QLatin1String("count"));
+ cmdLineParser.addOption(tdrOption);
+ // Allow testing preferring the software adapter (D3D).
+ QCommandLineOption swOption(QLatin1String("software"), QLatin1String("Prefer a software renderer when choosing the adapter. "
+ "Only applicable with some APIs and platforms."));
+ cmdLineParser.addOption(swOption);
cmdLineParser.process(app);
if (cmdLineParser.isSet(nullOption))
@@ -521,6 +535,12 @@ int main(int argc, char **argv)
}
#endif
+ if (cmdLineParser.isSet(tdrOption))
+ framesUntilTdr = cmdLineParser.value(tdrOption).toInt();
+
+ if (cmdLineParser.isSet(swOption))
+ rhiFlags |= QRhi::PreferSoftwareRenderer;
+
// Create and show the window.
Window w;
#if QT_CONFIG(vulkan)