From 425c59783c960e9f568b6c5e8920774ada9b87e5 Mon Sep 17 00:00:00 2001 From: Kirill Burtsev Date: Mon, 1 Jul 2019 18:44:39 +0200 Subject: Xcb: fix rounding error in reporting screen refresh rate Screen refresh rate might not be just integer but with decimal part like, for example, 59.97 Hz. Fix calculation from raw xcb data and its store type as it is qreal already for QScreen::refreshRate API. Task-number: QTBUG-73911 Change-Id: Ia0494e953176c2854f0ed42c4498a29cfef16106 Reviewed-by: Shawn Rutledge --- src/plugins/platforms/xcb/qxcbscreen.cpp | 2 +- src/plugins/platforms/xcb/qxcbscreen.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index a5a2aeb9aa..0cf0942dab 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -790,7 +790,7 @@ void QXcbScreen::updateRefreshRate(xcb_randr_mode_t mode) xcb_randr_mode_info_t *modeInfo = modesIter.data; if (modeInfo->id == mode) { const uint32_t dotCount = modeInfo->htotal * modeInfo->vtotal; - m_refreshRate = (dotCount != 0) ? modeInfo->dot_clock / dotCount : 0; + m_refreshRate = (dotCount != 0) ? modeInfo->dot_clock / qreal(dotCount) : 0; m_mode = mode; break; } diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h index ec3b07bfb7..914ce6307d 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.h +++ b/src/plugins/platforms/xcb/qxcbscreen.h @@ -226,7 +226,7 @@ private: QRect m_availableGeometry; Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation; QXcbCursor *m_cursor; - int m_refreshRate = 60; + qreal m_refreshRate = 60.0; int m_pixelDensity = 1; QEdidParser m_edid; }; -- cgit v1.2.3 From 56029e1e98b8f019b344ae0c9a01d12a47d29866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Br=C3=BCning?= Date: Mon, 7 Oct 2019 10:22:01 +0200 Subject: Blacklist Desktop GL for Mobile Intel 4 Series Express Chipset Using desktop GL with this graphics card causes crashes e.g. when using Qt WebEngine. Fixes: QTBUG-58772 Change-Id: I90e12aab4475c17be262e391ff0989cebf0b3ec4 Reviewed-by: Laszlo Agocs --- .../platforms/windows/openglblacklists/default.json | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/windows/openglblacklists/default.json b/src/plugins/platforms/windows/openglblacklists/default.json index 3cfa7e3856..e37351f9e0 100644 --- a/src/plugins/platforms/windows/openglblacklists/default.json +++ b/src/plugins/platforms/windows/openglblacklists/default.json @@ -152,6 +152,18 @@ "features": [ "disable_program_cache" ] - } + }, + { + "id": 13, + "description": "Disable DesktopGL on Windows with Mobile Intel(R) 4 Series Express Chipset Family graphics card (QTBUG-58772)", + "vendor_id": "0x8086", + "device_id": [ "0x2A42" ], + "os": { + "type": "win" + }, + "features": [ + "disable_desktopgl" + ] + } ] } -- cgit v1.2.3 From 0c1d23db7bada763f1e5d82cebda0e7738549b48 Mon Sep 17 00:00:00 2001 From: Leena Miettinen Date: Wed, 2 Oct 2019 12:05:32 +0200 Subject: Doc: Add info about QDBusConnection::ExportChildObjects Child objects need QObject::objectName. Fixes: QTBUG-17740 Change-Id: Iebf8bcd7252f8a441d7c265aae3d4dd81b3cfa54 Reviewed-by: Paul Wicking Reviewed-by: Frederik Gladhorn --- src/dbus/qdbusconnection.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/dbus/qdbusconnection.cpp b/src/dbus/qdbusconnection.cpp index 2c2dfc1ff6..296d5b369f 100644 --- a/src/dbus/qdbusconnection.cpp +++ b/src/dbus/qdbusconnection.cpp @@ -870,8 +870,12 @@ bool QDBusConnection::disconnect(const QString &service, const QString &path, co This function does not replace existing objects: if there is already an object registered at path \a path, this function will return false. Use unregisterObject() to unregister it first. + The ExportChildObjects flag exports child objects on D-Bus based on the + path of the registered objects and the QObject::objectName of the child. + Therefore, it is important for the child object to have an object name. + You cannot register an object as a child object of an object that - was registered with QDBusConnection::ExportChildObjects. + was registered with ExportChildObjects. */ bool QDBusConnection::registerObject(const QString &path, QObject *object, RegisterOptions options) { @@ -890,8 +894,12 @@ bool QDBusConnection::registerObject(const QString &path, QObject *object, Regis This function does not replace existing objects: if there is already an object registered at path \a path, this function will return false. Use unregisterObject() to unregister it first. + The ExportChildObjects flag exports child objects on D-Bus based on the + path of the registered objects and the QObject::objectName of the child. + Therefore, it is important for the child object to have an object name. + You cannot register an object as a child object of an object that - was registered with QDBusConnection::ExportChildObjects. + was registered with ExportChildObjects. */ bool QDBusConnection::registerObject(const QString &path, const QString &interface, QObject *object, RegisterOptions options) { -- cgit v1.2.3 From ce2fc51914f809369d5096e7a0621229dd9eaef9 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Mon, 30 Sep 2019 15:27:19 +0200 Subject: Add check for global share context for QOpenGLWidget initialize Fixes: QTBUG-78863 Change-Id: I678f66a2057fb9c98863e19eb09042306e72f68a Reviewed-by: Laszlo Agocs --- src/widgets/kernel/qopenglwidget.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/widgets/kernel/qopenglwidget.cpp b/src/widgets/kernel/qopenglwidget.cpp index 374ea53726..a88054a0d0 100644 --- a/src/widgets/kernel/qopenglwidget.cpp +++ b/src/widgets/kernel/qopenglwidget.cpp @@ -788,10 +788,12 @@ void QOpenGLWidgetPrivate::initialize() if (initialized) return; - // Get our toplevel's context with which we will share in order to make the - // texture usable by the underlying window's backingstore. + // If no global shared context get our toplevel's context with which we + // will share in order to make the texture usable by the underlying window's backingstore. QWidget *tlw = q->window(); - QOpenGLContext *shareContext = get(tlw)->shareContext(); + QOpenGLContext *shareContext = qt_gl_global_share_context(); + if (!shareContext) + shareContext = get(tlw)->shareContext(); // If shareContext is null, showing content on-screen will not work. // However, offscreen rendering and grabFramebuffer() will stay fully functional. -- cgit v1.2.3 From b6ce61f486a06ded273d518d871906f9a53ab7c1 Mon Sep 17 00:00:00 2001 From: Kari Hormi Date: Mon, 7 Oct 2019 16:21:33 +0300 Subject: Fix text not rendering properly after setAlignment call Sometimes when setAlignment is called, the text stops rendering correctly at some point. Adding relayoutDocument call to setAlignment fixes the problem. Fixes: QTBUG-78728 Change-Id: Iab1cf161f0c8d700804448733338c813b5bf9762 Reviewed-by: Ville Voutilainen --- src/widgets/widgets/qtextedit.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index 0ae63f2dd5..2b3a46ae56 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -746,6 +746,7 @@ void QTextEdit::setAlignment(Qt::Alignment a) QTextCursor cursor = d->control->textCursor(); cursor.mergeBlockFormat(fmt); d->control->setTextCursor(cursor); + d->relayoutDocument(); } /*! -- cgit v1.2.3 From 53ac8094b13d52b7da8b029cf4716827241283c3 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 7 Oct 2019 10:25:50 +0200 Subject: Fix PRE_TARGETDEPS for iOS projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This variable was ignored for iOS projects, because the generated Makefile includes xcodebuild.mk that defines its own default target. Export PRE_TARGETDEPS to the Makefile before including xcodebuild.mk and use it there for the dependencies of the generic build targets. Fixes: QTBUG-41325 Change-Id: I5faa82e05570974b5a844ae95b0a012c3badc64a Reviewed-by: Tor Arne Vestbø --- mkspecs/features/uikit/xcodebuild.mk | 4 ++-- mkspecs/features/uikit/xcodebuild.prf | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mkspecs/features/uikit/xcodebuild.mk b/mkspecs/features/uikit/xcodebuild.mk index 0c8d99f4b8..e1156d0e76 100644 --- a/mkspecs/features/uikit/xcodebuild.mk +++ b/mkspecs/features/uikit/xcodebuild.mk @@ -27,8 +27,8 @@ distclean: clean_all $(EXPORT_SUBTARGETS): % : %-build # Generic targets -%_first: $(firstword $(call targets, %)) ; -%_all: $(call targets, %) ; +%_first: $(EXPORT_PRE_TARGETDEPS) $(firstword $(call targets, %)) ; +%_all: $(EXPORT_PRE_TARGETDEPS) $(call targets, %) ; # Actions %-build: ACTION = build diff --git a/mkspecs/features/uikit/xcodebuild.prf b/mkspecs/features/uikit/xcodebuild.prf index 7a6b2acfc2..01022c7b99 100644 --- a/mkspecs/features/uikit/xcodebuild.prf +++ b/mkspecs/features/uikit/xcodebuild.prf @@ -29,6 +29,8 @@ cmd = "$$QMAKE_QMAKE $$system_quote($$_PRO_FILE_) -spec macx-xcode $$args" debug(1, "Generating Xcode project in $$OUT_PWD using '$$cmd'") system("$$QMAKE_CD $$system_quote($$OUT_PWD) && $$cmd") +QMAKE_EXTRA_VARIABLES += PRE_TARGETDEPS + # Subtargets for(build, BUILDS): \ -- cgit v1.2.3 From ca81c884f876d54a21c70b09652f053be4c5b45c Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Tue, 13 Aug 2019 17:25:27 -0600 Subject: Include XDG font locations in QStandardPaths::FontsLocation on Linux ~/.fonts was deprecated in 2012, see https://wiki.archlinux.org/index.php/Font_configuration#Fontconfig_configuration Few people keep fonts there anymore. Change-Id: Ide048e1df2c2db4856a38c574df36663ab684f89 Reviewed-by: David Faure --- src/corelib/io/qstandardpaths.cpp | 2 +- src/corelib/io/qstandardpaths_unix.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp index f56fef7f8e..3b5f2f97da 100644 --- a/src/corelib/io/qstandardpaths.cpp +++ b/src/corelib/io/qstandardpaths.cpp @@ -232,7 +232,7 @@ QT_BEGIN_NAMESPACE \row \li DocumentsLocation \li "~/Documents" \row \li FontsLocation - \li "~/.fonts" + \li "~/.fonts", "~/.local/share/fonts", "/usr/local/share/fonts", "/usr/share/fonts" \row \li ApplicationsLocation \li "~/.local/share/applications", "/usr/local/share/applications", "/usr/share/applications" \row \li MusicLocation diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp index eaa545b4fd..3d4a349c8c 100644 --- a/src/corelib/io/qstandardpaths_unix.cpp +++ b/src/corelib/io/qstandardpaths_unix.cpp @@ -348,6 +348,9 @@ QStringList QStandardPaths::standardLocations(StandardLocation type) break; case FontsLocation: dirs += QDir::homePath() + QLatin1String("/.fonts"); + dirs += xdgDataDirs(); + for (int i = 1; i < dirs.count(); ++i) + dirs[i].append(QLatin1String("/fonts")); break; default: break; -- cgit v1.2.3 From a1ea49878927dfe267416c795b50f3d5bdfa0b84 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 30 Jul 2019 11:07:18 +0200 Subject: configure: Do use pkg-config --libs for static libs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ensures that also linker commands like -pthread are returned. Fixes: QTBUG-77159 Change-Id: If9ab3797ccfb52c6b96a4ab120c59fd8896d5466 Reviewed-by: Jörg Bornemann (cherry picked from commit 4ddc50c0cd16ddd146ea9ea21d6565c8f4a5e2bc) Reviewed-by: Joerg Bornemann --- mkspecs/features/qt_configure.prf | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mkspecs/features/qt_configure.prf b/mkspecs/features/qt_configure.prf index 9be4fb6f1f..81110e9f6d 100644 --- a/mkspecs/features/qt_configure.prf +++ b/mkspecs/features/qt_configure.prf @@ -825,9 +825,7 @@ defineTest(qtConfLibrary_pkgConfig) { !qtConfResolveLibs($${1}.libs, $$libs): \ return(false) contains($${1}.libs, ".*\\.$${QMAKE_EXTENSION_STATICLIB}$") { - qtRunLoggedCommand("$$pkg_config --static --libs-only-L $$args", libpaths)|return(false) - qtRunLoggedCommand("$$pkg_config --static --libs-only-l $$args", libs)|return(false) - eval(libs = $$libpaths $$libs) + qtRunLoggedCommand("$$pkg_config --static --libs $$args", libs)|return(false) !qtConfResolveLibs($${1}.libs, $$libs): \ return(false) } -- cgit v1.2.3 From 8c092570fcd1330dd916f31d46e8472b7817ec80 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 9 Oct 2019 15:21:13 +0200 Subject: Fix warning about out of bounds access in QString::operator[] Fixes runtime warnings that got triggered by change c2d2757bccc68e1b981df059786c2e76f2969530. Change-Id: I50620b179de8608f45d6f2ef053eeb8b1e10ae43 Reviewed-by: Simon Hausmann --- src/gui/text/qtextodfwriter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp index 9721243454..6d23866392 100644 --- a/src/gui/text/qtextodfwriter.cpp +++ b/src/gui/text/qtextodfwriter.cpp @@ -358,7 +358,7 @@ void QTextOdfWriter::writeBlock(QXmlStreamWriter &writer, const QTextBlock &bloc int precedingSpaces = 0; int exportedIndex = 0; for (int i=0; i <= fragmentText.count(); ++i) { - QChar character = fragmentText[i]; + QChar character = (i == fragmentText.count() ? QChar() : fragmentText.at(i)); bool isSpace = character.unicode() == ' '; // find more than one space. -> -- cgit v1.2.3 From ba26496647bca4b37fc2319b553b95966823b941 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 8 Oct 2019 13:16:00 +0200 Subject: Don't crash when calling jumpToFrame() on an empty QMovie Properly return an invalid frame when calling jumpToFrame() with a non existent frame number. Fixes: QTBUG-79029 Change-Id: Ic40f4a6de3106fab42c0bb6c961194be47b04e31 Reviewed-by: Eirik Aavitsland --- src/gui/image/qmovie.cpp | 2 +- tests/auto/gui/image/qmovie/tst_qmovie.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gui/image/qmovie.cpp b/src/gui/image/qmovie.cpp index 79203c7b98..f03c8836df 100644 --- a/src/gui/image/qmovie.cpp +++ b/src/gui/image/qmovie.cpp @@ -416,7 +416,7 @@ QFrameInfo QMoviePrivate::infoForFrame(int frameNumber) } else { // We've read all frames now. Return an end marker haveReadAll = true; - return QFrameInfo::endMarker(); + return frameNumber == greatestFrameNumber + 1 ? QFrameInfo::endMarker() : QFrameInfo(); } } } diff --git a/tests/auto/gui/image/qmovie/tst_qmovie.cpp b/tests/auto/gui/image/qmovie/tst_qmovie.cpp index 4e9e9b8115..c8217b2cec 100644 --- a/tests/auto/gui/image/qmovie/tst_qmovie.cpp +++ b/tests/auto/gui/image/qmovie/tst_qmovie.cpp @@ -62,6 +62,7 @@ private slots: #ifndef QT_NO_WIDGETS void infiniteLoop(); #endif + void emptyMovie(); }; // Testing get/set functions @@ -220,5 +221,13 @@ void tst_QMovie::infiniteLoop() } #endif +void tst_QMovie::emptyMovie() +{ + QMovie movie; + movie.setCacheMode(QMovie::CacheAll); + movie.jumpToFrame(100); + QCOMPARE(movie.currentFrameNumber(), -1); +} + QTEST_MAIN(tst_QMovie) #include "tst_qmovie.moc" -- cgit v1.2.3 From 2d7ec5922a15da44fc5bbcbd9a7b6b7e00820fcd Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Wed, 9 Oct 2019 14:27:21 +0200 Subject: Fix compile with tracing enabled: include QStringList header Change-Id: I40f737338d10a871442bb453fe1eeede9dacec79 Reviewed-by: Simon Hausmann --- src/tools/tracegen/provider.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/tracegen/provider.h b/src/tools/tracegen/provider.h index 9be0c33d89..a4baf56815 100644 --- a/src/tools/tracegen/provider.h +++ b/src/tools/tracegen/provider.h @@ -42,6 +42,7 @@ #include #include +#include #include struct Tracepoint -- cgit v1.2.3 From 63a3b26b6b2dae88a44ad6a4917563b5331823d6 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Wed, 9 Oct 2019 14:48:53 +0200 Subject: Fix QMake build system to support trace points in a cross-compiled build CONFIG(cross_compile) implies CONFIG(force_bootstrap). The latter is errorneously used within qt_tracepoints.prf and to decide when tracegen is to be build. For the tracepoints, we just need to check if etw/lttng trace points are enabled. For tracegen, we don't need to check anything - it doesn't depend on etw or lttng, it is just a code generator similar to moc or rcc and should be handled like these tools. Change-Id: I3784b37db10680efd0ed7ee7860059bdf62b4118 Reviewed-by: Simon Hausmann --- mkspecs/features/qt_tracepoints.prf | 2 +- src/src.pro | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/mkspecs/features/qt_tracepoints.prf b/mkspecs/features/qt_tracepoints.prf index d1b45a47cb..56d315e1cd 100644 --- a/mkspecs/features/qt_tracepoints.prf +++ b/mkspecs/features/qt_tracepoints.prf @@ -16,7 +16,7 @@ PROVIDER_NAME = qt$$lower($$MODULE) INCLUDEPATH += $$absolute_path($$TRACEGEN_DIR, $$OUT_PWD) HEADER_PATH = $$OUT_PWD/$$TRACEGEN_DIR/$${PROVIDER_NAME}_tracepoints_p$${first(QMAKE_EXT_H)} -!force_bootstrap:if(qtConfig(lttng)|qtConfig(etw)) { +if(qtConfig(lttng)|qtConfig(etw)) { SOURCE_PATH = $$OUT_PWD/$$TRACEGEN_DIR/$${PROVIDER_NAME}_tracepoints$${first(QMAKE_EXT_CPP)} isEmpty(BUILDS)|build_pass { diff --git a/src/src.pro b/src/src.pro index b704ccd7ab..ce3db6d783 100644 --- a/src/src.pro +++ b/src/src.pro @@ -70,7 +70,7 @@ src_winmain.depends = sub-corelib # just for the module .pri file src_corelib.subdir = $$PWD/corelib src_corelib.target = sub-corelib -src_corelib.depends = src_tools_moc src_tools_rcc src_tools_qfloat16_tables +src_corelib.depends = src_tools_moc src_tools_rcc src_tools_tracegen src_tools_qfloat16_tables src_xml.subdir = $$PWD/xml src_xml.target = sub-xml @@ -157,17 +157,12 @@ src_android.subdir = $$PWD/android src_3rdparty_freetype.depends += src_corelib } } -SUBDIRS += src_tools_bootstrap src_tools_moc src_tools_rcc src_tools_qfloat16_tables +SUBDIRS += src_tools_bootstrap src_tools_moc src_tools_rcc src_tools_tracegen src_tools_qfloat16_tables qtConfig(regularexpression):pcre2 { SUBDIRS += src_3rdparty_pcre2 src_corelib.depends += src_3rdparty_pcre2 } -TOOLS = src_tools_moc src_tools_rcc src_tools_qlalr src_tools_qfloat16_tables -!force_bootstrap:if(qtConfig(lttng)|qtConfig(etw)) { - SUBDIRS += src_tools_tracegen - src_corelib.depends += src_tools_tracegen - TOOLS += src_tools_tracegen -} +TOOLS = src_tools_moc src_tools_rcc src_tools_tracegen src_tools_qlalr src_tools_qfloat16_tables SUBDIRS += src_corelib src_tools_qlalr win32:SUBDIRS += src_winmain qtConfig(network) { -- cgit v1.2.3 From f7cb11d6f12f7bb353640637719292b95fd21438 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 7 Oct 2019 13:59:13 +0200 Subject: QWidget: Answer question raised in fixme comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a comment for fixme comment added in f1268d137ea7839b320c84314d0c2265f5a629ba. Change-Id: I08cd104442b13925be2aa5a48e64e391c9903099 Reviewed-by: Tor Arne Vestbø --- src/widgets/kernel/qwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index b70a03b311..588bed0366 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -7669,7 +7669,7 @@ void QWidget::show() else if (defaultState == Qt::WindowMaximized) showMaximized(); else - setVisible(true); // FIXME: Why not showNormal(), like QWindow::show()? + setVisible(true); // Don't call showNormal() as not to clobber Qt::Window(Max/Min)imized } /*! \internal -- cgit v1.2.3 From ae7b21898273a83b4b2669b9d30a7f9777a7af99 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 7 Oct 2019 12:28:39 +0200 Subject: Windows QPA: Improve reliability of clipboard retrieval MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clipboard retrieval sometimes fails due to the other application having the clipboard locked. Retry opening the clipboard. The choice of parameters is empirical, they have been observed to prevent failures for MS Office applications at least. Fixes: QTBUG-53979 Change-Id: Icbcaee149f0d377f33b222cdafbb2a21a7f1cf9d Reviewed-by: André de la Rocha Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowsclipboard.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsclipboard.cpp b/src/plugins/platforms/windows/qwindowsclipboard.cpp index b87e43f3f7..4e6d3306e1 100644 --- a/src/plugins/platforms/windows/qwindowsclipboard.cpp +++ b/src/plugins/platforms/windows/qwindowsclipboard.cpp @@ -115,12 +115,21 @@ static QDebug operator<<(QDebug d, const QMimeData *mimeData) IDataObject *QWindowsClipboardRetrievalMimeData::retrieveDataObject() const { + enum : int { attempts = 3 }; IDataObject * pDataObj = nullptr; - if (OleGetClipboard(&pDataObj) == S_OK) { - if (QWindowsContext::verbose > 1) - qCDebug(lcQpaMime) << __FUNCTION__ << pDataObj; - return pDataObj; + // QTBUG-53979, retry in case the other application has clipboard locked + for (int i = 1; i <= attempts; ++i) { + if (SUCCEEDED(OleGetClipboard(&pDataObj))) { + if (QWindowsContext::verbose > 1) + qCDebug(lcQpaMime) << __FUNCTION__ << pDataObj; + return pDataObj; + } + qCWarning(lcQpaMime, i == attempts + ? "Unable to obtain clipboard." + : "Retrying to obtain clipboard."); + QThread::msleep(50); } + return nullptr; } -- cgit v1.2.3 From a6ece9e88a3b227b7359d85d2641e9aab9be1c7b Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 8 Oct 2019 11:35:06 +0200 Subject: Fix relocatable prefix for hardware-specific Linux builds Since Qt 5.3.0 we recommend that Linux distributions place a SSE2-enabled copy of QtCore in a $PREFIX/lib/sse2 subdirectory (see Qt 5.3.0 changelog for details). Same for other hardware capabilities like AVX2 and AVX512. This use case was broken with the introduction of the 'relocatable' feature, because the prefix is determined from the location of libQt5Core.so and the relative path from libdir to prefix, which is baked in at configure time. We now try to locate the libdir below the prefix, and if that fails try again in the upper directories. Fixes: QTBUG-78948 Change-Id: Ieec6e1484974e19335cf08ae0df3ee5c0e316d28 Reviewed-by: Alexandru Croitor --- src/corelib/global/qlibraryinfo.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 6476b7404a..8bcf67e73d 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -569,6 +569,23 @@ static QString getRelocatablePrefix() #error "The chosen platform / config does not support querying for a dynamic prefix." #endif +#if defined(Q_OS_LINUX) && !defined(QT_STATIC) && defined(__GLIBC__) + // QTBUG-78948: libQt5Core.so may be located in subdirectories below libdir. + // See "Hardware capabilities" in the ld.so documentation and the Qt 5.3.0 + // changelog regarding SSE2 support. + const QString libdir = QString::fromLatin1( + qt_configure_strs + qt_configure_str_offsets[QLibraryInfo::LibrariesPath - 1]); + QDir prefixDir(prefixPath); + while (!prefixDir.exists(libdir)) { + prefixDir.cdUp(); + prefixPath = prefixDir.absolutePath(); + if (prefixDir.isRoot()) { + prefixPath.clear(); + break; + } + } +#endif + Q_ASSERT_X(!prefixPath.isEmpty(), "getRelocatablePrefix", "Failed to find the Qt prefix path."); return prefixPath; -- cgit v1.2.3 From f1dd6addda908185f497d299d706b88977dea858 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 2 Oct 2019 12:19:11 +0200 Subject: Make QTextBlockFormat::MarkerType an enum class This came up during API review. Change-Id: I9198e1eb96db0c21e46a226a032919bb62d3ca66 Reviewed-by: Giuseppe D'Angelo --- examples/widgets/richtext/textedit/textedit.cpp | 12 ++++++------ src/gui/text/qabstracttextdocumentlayout.cpp | 2 +- src/gui/text/qtextdocumentlayout.cpp | 4 ++-- src/gui/text/qtextformat.h | 2 +- src/gui/text/qtextmarkdownimporter.cpp | 6 +++--- src/gui/text/qtextmarkdownimporter_p.h | 2 +- src/gui/text/qtextmarkdownwriter.cpp | 4 ++-- src/widgets/widgets/qtextedit.cpp | 2 +- src/widgets/widgets/qwidgettextcontrol.cpp | 8 ++++---- .../gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp index 996bb8e0a4..85fb83ab89 100644 --- a/examples/widgets/richtext/textedit/textedit.cpp +++ b/examples/widgets/richtext/textedit/textedit.cpp @@ -640,7 +640,7 @@ void TextEdit::textStyle(int styleIndex) { QTextCursor cursor = textEdit->textCursor(); QTextListFormat::Style style = QTextListFormat::ListStyleUndefined; - QTextBlockFormat::MarkerType marker = QTextBlockFormat::NoMarker; + QTextBlockFormat::MarkerType marker = QTextBlockFormat::MarkerType::NoMarker; switch (styleIndex) { case 1: @@ -657,14 +657,14 @@ void TextEdit::textStyle(int styleIndex) style = cursor.currentList()->format().style(); else style = QTextListFormat::ListDisc; - marker = QTextBlockFormat::Unchecked; + marker = QTextBlockFormat::MarkerType::Unchecked; break; case 5: if (cursor.currentList()) style = cursor.currentList()->format().style(); else style = QTextListFormat::ListDisc; - marker = QTextBlockFormat::Checked; + marker = QTextBlockFormat::MarkerType::Checked; break; case 6: style = QTextListFormat::ListDecimal; @@ -823,14 +823,14 @@ void TextEdit::cursorPositionChanged() break; } switch (textEdit->textCursor().block().blockFormat().marker()) { - case QTextBlockFormat::NoMarker: + case QTextBlockFormat::MarkerType::NoMarker: actionToggleCheckState->setChecked(false); break; - case QTextBlockFormat::Unchecked: + case QTextBlockFormat::MarkerType::Unchecked: comboStyle->setCurrentIndex(4); actionToggleCheckState->setChecked(false); break; - case QTextBlockFormat::Checked: + case QTextBlockFormat::MarkerType::Checked: comboStyle->setCurrentIndex(5); actionToggleCheckState->setChecked(true); break; diff --git a/src/gui/text/qabstracttextdocumentlayout.cpp b/src/gui/text/qabstracttextdocumentlayout.cpp index 5263ece87c..8b8f3e28ac 100644 --- a/src/gui/text/qabstracttextdocumentlayout.cpp +++ b/src/gui/text/qabstracttextdocumentlayout.cpp @@ -660,7 +660,7 @@ QTextBlock QAbstractTextDocumentLayout::blockWithMarkerAt(const QPointF &pos) co { QTextBlock block = document()->firstBlock(); while (block.isValid()) { - if (block.blockFormat().marker() != QTextBlockFormat::NoMarker) { + if (block.blockFormat().marker() != QTextBlockFormat::MarkerType::NoMarker) { QRectF blockBr = blockBoundingRect(block); QTextBlockFormat blockFmt = block.blockFormat(); QFontMetrics fm(block.charFormat().font()); diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index 1d5afee16b..7be114adf9 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -2194,11 +2194,11 @@ void QTextDocumentLayoutPrivate::drawListItem(const QPointF &offset, QPainter *p QBrush brush = context.palette.brush(QPalette::Text); - bool marker = bl.blockFormat().marker() != QTextBlockFormat::NoMarker; + bool marker = bl.blockFormat().marker() != QTextBlockFormat::MarkerType::NoMarker; if (marker) { int adj = fontMetrics.lineSpacing() / 6; r.adjust(-adj, 0, -adj, 0); - if (bl.blockFormat().marker() == QTextBlockFormat::Checked) { + if (bl.blockFormat().marker() == QTextBlockFormat::MarkerType::Checked) { // ### Qt6: render with QStyle / PE_IndicatorCheckBox. We don't currently // have access to that here, because it would be a widget dependency. painter->setPen(QPen(painter->pen().color(), 2)); diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h index 12f14a1555..28da0fe344 100644 --- a/src/gui/text/qtextformat.h +++ b/src/gui/text/qtextformat.h @@ -627,7 +627,7 @@ public: LineDistanceHeight = 4 }; - enum MarkerType { + enum class MarkerType { NoMarker = 0, Unchecked = 1, Checked = 2 diff --git a/src/gui/text/qtextmarkdownimporter.cpp b/src/gui/text/qtextmarkdownimporter.cpp index b96263f5fc..fe7e422923 100644 --- a/src/gui/text/qtextmarkdownimporter.cpp +++ b/src/gui/text/qtextmarkdownimporter.cpp @@ -190,8 +190,8 @@ int QTextMarkdownImporter::cbEnterBlock(int blockType, void *det) m_listItem = true; MD_BLOCK_LI_DETAIL *detail = static_cast(det); m_markerType = detail->is_task ? - (detail->task_mark == ' ' ? QTextBlockFormat::Unchecked : QTextBlockFormat::Checked) : - QTextBlockFormat::NoMarker; + (detail->task_mark == ' ' ? QTextBlockFormat::MarkerType::Unchecked : QTextBlockFormat::MarkerType::Checked) : + QTextBlockFormat::MarkerType::NoMarker; qCDebug(lcMD) << "LI"; } break; case MD_BLOCK_UL: { @@ -549,7 +549,7 @@ void QTextMarkdownImporter::insertBlock() blockFormat.setTopMargin(m_paragraphMargin); blockFormat.setBottomMargin(m_paragraphMargin); } - if (m_markerType == QTextBlockFormat::NoMarker) + if (m_markerType == QTextBlockFormat::MarkerType::NoMarker) blockFormat.clearProperty(QTextFormat::BlockMarker); else blockFormat.setMarker(m_markerType); diff --git a/src/gui/text/qtextmarkdownimporter_p.h b/src/gui/text/qtextmarkdownimporter_p.h index 1b8c2ca354..35655aff8a 100644 --- a/src/gui/text/qtextmarkdownimporter_p.h +++ b/src/gui/text/qtextmarkdownimporter_p.h @@ -128,7 +128,7 @@ private: Features m_features; QTextImageFormat m_imageFormat; QTextListFormat m_listFormat; - QTextBlockFormat::MarkerType m_markerType = QTextBlockFormat::NoMarker; + QTextBlockFormat::MarkerType m_markerType = QTextBlockFormat::MarkerType::NoMarker; bool m_needsInsertBlock = false; bool m_needsInsertList = false; bool m_listItem = false; // true from the beginning of LI to the end of the first P diff --git a/src/gui/text/qtextmarkdownwriter.cpp b/src/gui/text/qtextmarkdownwriter.cpp index cbfb092485..764c64aead 100644 --- a/src/gui/text/qtextmarkdownwriter.cpp +++ b/src/gui/text/qtextmarkdownwriter.cpp @@ -327,10 +327,10 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign break; } switch (blockFmt.marker()) { - case QTextBlockFormat::Checked: + case QTextBlockFormat::MarkerType::Checked: bullet += " [x]"; break; - case QTextBlockFormat::Unchecked: + case QTextBlockFormat::MarkerType::Unchecked: bullet += " [ ]"; break; default: diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index 0702603648..dd2ea3f18f 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -237,7 +237,7 @@ void QTextEditPrivate::_q_hoveredBlockWithMarkerChanged(const QTextBlock &block) Qt::CursorShape cursor = cursorToRestoreAfterHover; if (block.isValid() && !q->isReadOnly()) { QTextBlockFormat::MarkerType marker = block.blockFormat().marker(); - if (marker != QTextBlockFormat::NoMarker) { + if (marker != QTextBlockFormat::MarkerType::NoMarker) { if (viewport->cursor().shape() != Qt::PointingHandCursor) cursorToRestoreAfterHover = viewport->cursor().shape(); cursor = Qt::PointingHandCursor; diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index fdbaf29dd8..094c59a0c9 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -1810,11 +1810,11 @@ void QWidgetTextControlPrivate::mouseReleaseEvent(QEvent *e, Qt::MouseButton but if (markerBlock == blockWithMarkerUnderMouse) { auto fmt = blockWithMarkerUnderMouse.blockFormat(); switch (fmt.marker()) { - case QTextBlockFormat::Unchecked : - fmt.setMarker(QTextBlockFormat::Checked); + case QTextBlockFormat::MarkerType::Unchecked : + fmt.setMarker(QTextBlockFormat::MarkerType::Checked); break; - case QTextBlockFormat::Checked: - fmt.setMarker(QTextBlockFormat::Unchecked); + case QTextBlockFormat::MarkerType::Checked: + fmt.setMarker(QTextBlockFormat::MarkerType::Unchecked); break; default: break; diff --git a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp index 8d38cbb18a..1e6c354f17 100644 --- a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp +++ b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp @@ -159,7 +159,7 @@ void tst_QTextMarkdownWriter::testWriteNestedBulletLists() QTextCursor cursor(document); QTextBlockFormat blockFmt = cursor.blockFormat(); if (checkbox) { - blockFmt.setMarker(checked ? QTextBlockFormat::Checked : QTextBlockFormat::Unchecked); + blockFmt.setMarker(checked ? QTextBlockFormat::MarkerType::Checked : QTextBlockFormat::MarkerType::Unchecked); cursor.setBlockFormat(blockFmt); } -- cgit v1.2.3 From 65fcd8524da628c99e8cd28f983f0c17fbe157f0 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 8 Oct 2019 16:25:08 +0200 Subject: QAbstractScrollArea: when used as a popup, apply regular popup behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QWidget::mousePressEvent is documented to implement the closing of popups if the widget is a popup. QAbstractScrollArea is one of the QWidget subclasses that might be used as a popup as well, so instead of just ignoring mousePressEvents, pass the event on to the QWidget implementation for regular popup handling. Change-Id: I05f77a334945f3c167f729f30bc022599230379b Fixes: QTBUG-60885 Reviewed-by: Tor Arne Vestbø Reviewed-by: Paul Olav Tvete --- src/widgets/widgets/qabstractscrollarea.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp index b295e66574..d2372a7be9 100644 --- a/src/widgets/widgets/qabstractscrollarea.cpp +++ b/src/widgets/widgets/qabstractscrollarea.cpp @@ -1144,11 +1144,14 @@ void QAbstractScrollArea::paintEvent(QPaintEvent*) mouse press events for the viewport() widget. The event is passed in \a e. + The default implementation calls QWidget::mousePressEvent() for + default popup handling. + \sa QWidget::mousePressEvent() */ void QAbstractScrollArea::mousePressEvent(QMouseEvent *e) { - e->ignore(); + QWidget::mousePressEvent(e); } /*! -- cgit v1.2.3 From 4af00753fad57989a6ae366cc3dbfc56d88508f4 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 6 Sep 2019 23:24:56 +0200 Subject: Cleanup QtWidgets examples Cleanup QtWidgets examples: - use nullptr (clang-tidy) - use member-initialization - adjust the style - fix includes Change-Id: Ic5448606aacc525ea60b615a69227017aa2b821a Reviewed-by: Paul Wicking --- .../widgets/dialogs/classwizard/classwizard.cpp | 4 +- examples/widgets/dialogs/classwizard/classwizard.h | 12 +-- examples/widgets/dialogs/extension/finddialog.h | 2 +- examples/widgets/dialogs/findfiles/window.h | 2 +- .../widgets/dialogs/licensewizard/licensewizard.h | 12 +-- examples/widgets/dialogs/standarddialogs/dialog.h | 2 +- examples/widgets/dialogs/tabdialog/tabdialog.h | 8 +- examples/widgets/effects/blurpicker/blurpicker.h | 2 +- examples/widgets/effects/fademessage/fademessage.h | 2 +- .../widgets/gestures/imagegestures/imagewidget.cpp | 28 +++---- .../widgets/gestures/imagegestures/imagewidget.h | 10 +-- examples/widgets/gestures/imagegestures/main.cpp | 2 +- .../widgets/gestures/imagegestures/mainwidget.cpp | 2 +- .../widgets/gestures/imagegestures/mainwidget.h | 4 +- .../widgets/graphicsview/collidingmice/mouse.cpp | 5 +- examples/widgets/itemviews/frozencolumn/main.cpp | 2 +- examples/widgets/itemviews/interview/model.cpp | 4 +- examples/widgets/itemviews/stardelegate/main.cpp | 9 ++- examples/widgets/painting/deform/pathdeform.cpp | 2 +- examples/widgets/painting/fontsampler/mainwindow.h | 2 +- examples/widgets/painting/gradients/gradients.cpp | 28 +++---- examples/widgets/painting/gradients/gradients.h | 2 +- examples/widgets/painting/gradients/main.cpp | 4 +- .../widgets/painting/painterpaths/renderarea.h | 2 +- .../widgets/painting/pathstroke/pathstroke.cpp | 87 +++++++++++++--------- examples/widgets/painting/pathstroke/pathstroke.h | 2 +- examples/widgets/painting/shared/arthurstyle.h | 2 +- examples/widgets/painting/shared/arthurwidgets.cpp | 4 +- .../widgets/painting/shared/fbopaintdevice.cpp | 6 +- examples/widgets/painting/shared/fbopaintdevice.h | 4 +- examples/widgets/painting/shared/hoverpoints.cpp | 4 +- .../widgets/painting/transformations/renderarea.h | 2 +- examples/widgets/scroller/graphicsview/main.cpp | 2 +- .../widgets/statemachine/eventtransitions/main.cpp | 9 ++- examples/widgets/statemachine/factorial/main.cpp | 9 +-- .../widgets/statemachine/trafficlight/main.cpp | 14 +++- examples/widgets/touch/fingerpaint/scribblearea.h | 2 +- examples/widgets/touch/pinchzoom/graphicsview.cpp | 6 +- examples/widgets/touch/pinchzoom/graphicsview.h | 4 +- examples/widgets/touch/pinchzoom/main.cpp | 7 +- examples/widgets/touch/pinchzoom/mouse.cpp | 10 +-- examples/widgets/touch/pinchzoom/mouse.h | 6 +- .../tutorials/addressbook/part1/addressbook.h | 2 +- .../tutorials/addressbook/part2/addressbook.h | 2 +- .../tutorials/addressbook/part3/addressbook.h | 2 +- .../tutorials/addressbook/part4/addressbook.h | 2 +- .../tutorials/addressbook/part5/addressbook.h | 2 +- .../tutorials/addressbook/part5/finddialog.h | 2 +- .../tutorials/addressbook/part6/addressbook.h | 2 +- .../tutorials/addressbook/part6/finddialog.h | 2 +- .../tutorials/addressbook/part7/addressbook.h | 2 +- .../tutorials/addressbook/part7/finddialog.h | 2 +- .../tutorials/modelview/3_changingmodel/main.cpp | 2 +- .../tutorials/modelview/7_selections/mainwindow.h | 2 +- examples/widgets/tutorials/notepad/notepad.h | 2 +- .../widgets/windowcontainer/windowcontainer.cpp | 53 +++++++------ 56 files changed, 216 insertions(+), 195 deletions(-) diff --git a/examples/widgets/dialogs/classwizard/classwizard.cpp b/examples/widgets/dialogs/classwizard/classwizard.cpp index 81adf85b0d..8421289eab 100644 --- a/examples/widgets/dialogs/classwizard/classwizard.cpp +++ b/examples/widgets/dialogs/classwizard/classwizard.cpp @@ -118,9 +118,9 @@ void ClassWizard::accept() block += "public:\n"; if (field("qobjectCtor").toBool()) { - block += " " + className + "(QObject *parent = 0);\n"; + block += " " + className + "(QObject *parent = nullptr);\n"; } else if (field("qwidgetCtor").toBool()) { - block += " " + className + "(QWidget *parent = 0);\n"; + block += " " + className + "(QWidget *parent = nullptr);\n"; } else if (field("defaultCtor").toBool()) { block += " " + className + "();\n"; if (field("copyCtor").toBool()) { diff --git a/examples/widgets/dialogs/classwizard/classwizard.h b/examples/widgets/dialogs/classwizard/classwizard.h index fee0f6df66..0c386f0553 100644 --- a/examples/widgets/dialogs/classwizard/classwizard.h +++ b/examples/widgets/dialogs/classwizard/classwizard.h @@ -67,7 +67,7 @@ class ClassWizard : public QWizard Q_OBJECT public: - ClassWizard(QWidget *parent = 0); + ClassWizard(QWidget *parent = nullptr); void accept() override; }; @@ -79,7 +79,7 @@ class IntroPage : public QWizardPage Q_OBJECT public: - IntroPage(QWidget *parent = 0); + IntroPage(QWidget *parent = nullptr); private: QLabel *label; @@ -92,7 +92,7 @@ class ClassInfoPage : public QWizardPage Q_OBJECT public: - ClassInfoPage(QWidget *parent = 0); + ClassInfoPage(QWidget *parent = nullptr); private: QLabel *classNameLabel; @@ -114,7 +114,7 @@ class CodeStylePage : public QWizardPage Q_OBJECT public: - CodeStylePage(QWidget *parent = 0); + CodeStylePage(QWidget *parent = nullptr); protected: void initializePage() override; @@ -135,7 +135,7 @@ class OutputFilesPage : public QWizardPage Q_OBJECT public: - OutputFilesPage(QWidget *parent = 0); + OutputFilesPage(QWidget *parent = nullptr); protected: void initializePage() override; @@ -154,7 +154,7 @@ class ConclusionPage : public QWizardPage Q_OBJECT public: - ConclusionPage(QWidget *parent = 0); + ConclusionPage(QWidget *parent = nullptr); protected: void initializePage() override; diff --git a/examples/widgets/dialogs/extension/finddialog.h b/examples/widgets/dialogs/extension/finddialog.h index 858e1c929b..9b4b5b5f3d 100644 --- a/examples/widgets/dialogs/extension/finddialog.h +++ b/examples/widgets/dialogs/extension/finddialog.h @@ -68,7 +68,7 @@ class FindDialog : public QDialog Q_OBJECT public: - FindDialog(QWidget *parent = 0); + FindDialog(QWidget *parent = nullptr); private: QLabel *label; diff --git a/examples/widgets/dialogs/findfiles/window.h b/examples/widgets/dialogs/findfiles/window.h index 949df704bb..b74ba5e70c 100644 --- a/examples/widgets/dialogs/findfiles/window.h +++ b/examples/widgets/dialogs/findfiles/window.h @@ -68,7 +68,7 @@ class Window : public QWidget Q_OBJECT public: - Window(QWidget *parent = 0); + Window(QWidget *parent = nullptr); private slots: void browse(); diff --git a/examples/widgets/dialogs/licensewizard/licensewizard.h b/examples/widgets/dialogs/licensewizard/licensewizard.h index c7709d88b3..e2890e484f 100644 --- a/examples/widgets/dialogs/licensewizard/licensewizard.h +++ b/examples/widgets/dialogs/licensewizard/licensewizard.h @@ -72,7 +72,7 @@ public: Page_Conclusion }; //! [2] - LicenseWizard(QWidget *parent = 0); + LicenseWizard(QWidget *parent = nullptr); private slots: void showHelp(); @@ -86,7 +86,7 @@ class IntroPage : public QWizardPage Q_OBJECT public: - IntroPage(QWidget *parent = 0); + IntroPage(QWidget *parent = nullptr); int nextId() const override; @@ -103,7 +103,7 @@ class EvaluatePage : public QWizardPage Q_OBJECT public: - EvaluatePage(QWidget *parent = 0); + EvaluatePage(QWidget *parent = nullptr); int nextId() const override; @@ -120,7 +120,7 @@ class RegisterPage : public QWizardPage Q_OBJECT public: - RegisterPage(QWidget *parent = 0); + RegisterPage(QWidget *parent = nullptr); int nextId() const override; @@ -136,7 +136,7 @@ class DetailsPage : public QWizardPage Q_OBJECT public: - DetailsPage(QWidget *parent = 0); + DetailsPage(QWidget *parent = nullptr); int nextId() const override; @@ -155,7 +155,7 @@ class ConclusionPage : public QWizardPage Q_OBJECT public: - ConclusionPage(QWidget *parent = 0); + ConclusionPage(QWidget *parent = nullptr); void initializePage() override; int nextId() const override; diff --git a/examples/widgets/dialogs/standarddialogs/dialog.h b/examples/widgets/dialogs/standarddialogs/dialog.h index 0d1c8d3e54..6d9cbdc07a 100644 --- a/examples/widgets/dialogs/standarddialogs/dialog.h +++ b/examples/widgets/dialogs/standarddialogs/dialog.h @@ -66,7 +66,7 @@ class Dialog : public QWidget Q_OBJECT public: - Dialog(QWidget *parent = 0); + Dialog(QWidget *parent = nullptr); private slots: void setInteger(); diff --git a/examples/widgets/dialogs/tabdialog/tabdialog.h b/examples/widgets/dialogs/tabdialog/tabdialog.h index 2db47c9ddd..b7c6c5b8da 100644 --- a/examples/widgets/dialogs/tabdialog/tabdialog.h +++ b/examples/widgets/dialogs/tabdialog/tabdialog.h @@ -65,7 +65,7 @@ class GeneralTab : public QWidget Q_OBJECT public: - explicit GeneralTab(const QFileInfo &fileInfo, QWidget *parent = 0); + explicit GeneralTab(const QFileInfo &fileInfo, QWidget *parent = nullptr); }; //! [0] @@ -76,7 +76,7 @@ class PermissionsTab : public QWidget Q_OBJECT public: - explicit PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = 0); + explicit PermissionsTab(const QFileInfo &fileInfo, QWidget *parent = nullptr); }; //! [1] @@ -87,7 +87,7 @@ class ApplicationsTab : public QWidget Q_OBJECT public: - explicit ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = 0); + explicit ApplicationsTab(const QFileInfo &fileInfo, QWidget *parent = nullptr); }; //! [2] @@ -98,7 +98,7 @@ class TabDialog : public QDialog Q_OBJECT public: - explicit TabDialog(const QString &fileName, QWidget *parent = 0); + explicit TabDialog(const QString &fileName, QWidget *parent = nullptr); private: QTabWidget *tabWidget; diff --git a/examples/widgets/effects/blurpicker/blurpicker.h b/examples/widgets/effects/blurpicker/blurpicker.h index 3f444419a8..dc7fc4dabb 100644 --- a/examples/widgets/effects/blurpicker/blurpicker.h +++ b/examples/widgets/effects/blurpicker/blurpicker.h @@ -63,7 +63,7 @@ class BlurPicker: public QGraphicsView Q_PROPERTY(qreal index READ index WRITE setIndex) public: - BlurPicker(QWidget *parent = 0); + BlurPicker(QWidget *parent = nullptr); qreal index() const; void setIndex(qreal); diff --git a/examples/widgets/effects/fademessage/fademessage.h b/examples/widgets/effects/fademessage/fademessage.h index d17a1616ce..4d84c4ed21 100644 --- a/examples/widgets/effects/fademessage/fademessage.h +++ b/examples/widgets/effects/fademessage/fademessage.h @@ -62,7 +62,7 @@ class FadeMessage: public QGraphicsView Q_OBJECT public: - FadeMessage(QWidget *parent = 0); + FadeMessage(QWidget *parent = nullptr); private: void setupScene(); diff --git a/examples/widgets/gestures/imagegestures/imagewidget.cpp b/examples/widgets/gestures/imagegestures/imagewidget.cpp index 0a6b963559..fb5351f949 100644 --- a/examples/widgets/gestures/imagegestures/imagewidget.cpp +++ b/examples/widgets/gestures/imagegestures/imagewidget.cpp @@ -50,26 +50,23 @@ #include "imagewidget.h" -#include +#include +#include +#include +#include Q_LOGGING_CATEGORY(lcExample, "qt.examples.imagegestures") //! [constructor] ImageWidget::ImageWidget(QWidget *parent) - : QWidget(parent), - position(0), - horizontalOffset(0), - verticalOffset(0), - rotationAngle(0), - scaleFactor(1), - currentStepScaleFactor(1) - + : QWidget(parent), position(0), horizontalOffset(0), verticalOffset(0) + , rotationAngle(0), scaleFactor(1), currentStepScaleFactor(1) { - setMinimumSize(QSize(100,100)); + setMinimumSize(QSize(100, 100)); } //! [constructor] -void ImageWidget::grabGestures(const QList &gestures) +void ImageWidget::grabGestures(const QVector &gestures) { //! [enable gestures] for (Qt::GestureType gesture : gestures) @@ -96,11 +93,11 @@ void ImageWidget::paintEvent(QPaintEvent*) const qreal wh = height(); const qreal ww = width(); - p.translate(ww/2, wh/2); + p.translate(ww / 2, wh / 2); p.translate(horizontalOffset, verticalOffset); p.rotate(rotationAngle); p.scale(currentStepScaleFactor * scaleFactor, currentStepScaleFactor * scaleFactor); - p.translate(-iw/2, -ih/2); + p.translate(-iw / 2, -ih / 2); p.drawImage(0, 0, currentImage); } //! [paint method] @@ -198,8 +195,7 @@ void ImageWidget::openDirectory(const QString &path) { this->path = path; QDir dir(path); - QStringList nameFilters; - nameFilters << "*.jpg" << "*.png"; + const QStringList nameFilters{"*.jpg", "*.png"}; files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name); position = 0; @@ -207,7 +203,7 @@ void ImageWidget::openDirectory(const QString &path) update(); } -QImage ImageWidget::loadImage(const QString &fileName) +QImage ImageWidget::loadImage(const QString &fileName) const { QImageReader reader(fileName); reader.setAutoTransform(true); diff --git a/examples/widgets/gestures/imagegestures/imagewidget.h b/examples/widgets/gestures/imagegestures/imagewidget.h index 5e92541067..ae5eb7bc2b 100644 --- a/examples/widgets/gestures/imagegestures/imagewidget.h +++ b/examples/widgets/gestures/imagegestures/imagewidget.h @@ -51,9 +51,9 @@ #ifndef IMAGEWIDGET_H #define IMAGEWIDGET_H -#include #include -#include +#include +#include QT_BEGIN_NAMESPACE class QGestureEvent; @@ -70,9 +70,9 @@ class ImageWidget : public QWidget Q_OBJECT public: - ImageWidget(QWidget *parent = 0); + ImageWidget(QWidget *parent = nullptr); void openDirectory(const QString &path); - void grabGestures(const QList &gestures); + void grabGestures(const QVector &gestures); protected: bool event(QEvent *event) override; @@ -87,7 +87,7 @@ private: void swipeTriggered(QSwipeGesture*); //! [class definition begin] - QImage loadImage(const QString &fileName); + QImage loadImage(const QString &fileName) const; void loadImage(); void goNextImage(); void goPrevImage(); diff --git a/examples/widgets/gestures/imagegestures/main.cpp b/examples/widgets/gestures/imagegestures/main.cpp index ecd7462bd3..4f8d4ec15e 100644 --- a/examples/widgets/gestures/imagegestures/main.cpp +++ b/examples/widgets/gestures/imagegestures/main.cpp @@ -102,7 +102,7 @@ int main(int argc, char *argv[]) return -1; } - QList gestures; + QVector gestures; if (!commandLineParser.isSet(disablePanOption)) gestures << Qt::PanGesture; if (!commandLineParser.isSet(disablePinchOption)) diff --git a/examples/widgets/gestures/imagegestures/mainwidget.cpp b/examples/widgets/gestures/imagegestures/mainwidget.cpp index c4e63e9e7d..d1c786a93a 100644 --- a/examples/widgets/gestures/imagegestures/mainwidget.cpp +++ b/examples/widgets/gestures/imagegestures/mainwidget.cpp @@ -72,7 +72,7 @@ void MainWidget::openDirectory(const QString &path) imageWidget->openDirectory(path); } -void MainWidget::grabGestures(const QList &gestures) +void MainWidget::grabGestures(const QVector &gestures) { imageWidget->grabGestures(gestures); } diff --git a/examples/widgets/gestures/imagegestures/mainwidget.h b/examples/widgets/gestures/imagegestures/mainwidget.h index f3763ffffc..1600597251 100644 --- a/examples/widgets/gestures/imagegestures/mainwidget.h +++ b/examples/widgets/gestures/imagegestures/mainwidget.h @@ -60,8 +60,8 @@ class MainWidget : public QMainWindow Q_OBJECT public: - MainWidget(QWidget *parent = 0); - void grabGestures(const QList &gestures); + MainWidget(QWidget *parent = nullptr); + void grabGestures(const QVector &gestures); public slots: void openDirectory(const QString &path); diff --git a/examples/widgets/graphicsview/collidingmice/mouse.cpp b/examples/widgets/graphicsview/collidingmice/mouse.cpp index 556e58d19b..8375092c39 100644 --- a/examples/widgets/graphicsview/collidingmice/mouse.cpp +++ b/examples/widgets/graphicsview/collidingmice/mouse.cpp @@ -69,8 +69,9 @@ static qreal normalizeAngle(qreal angle) } //! [0] -Mouse::Mouse() - : color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)) +Mouse::Mouse() : color(QRandomGenerator::global()->bounded(256), + QRandomGenerator::global()->bounded(256), + QRandomGenerator::global()->bounded(256)) { setRotation(QRandomGenerator::global()->bounded(360 * 16)); } diff --git a/examples/widgets/itemviews/frozencolumn/main.cpp b/examples/widgets/itemviews/frozencolumn/main.cpp index 6f2b4a8d71..2965617ba1 100644 --- a/examples/widgets/itemviews/frozencolumn/main.cpp +++ b/examples/widgets/itemviews/frozencolumn/main.cpp @@ -71,7 +71,7 @@ int main(int argc, char* argv[]) model->setHorizontalHeaderLabels(list); int row = 0; - QStandardItem *newItem = 0; + QStandardItem *newItem = nullptr; while (!stream.atEnd()) { line = stream.readLine(); if (!line.startsWith('#') && line.contains(',')) { diff --git a/examples/widgets/itemviews/interview/model.cpp b/examples/widgets/itemviews/interview/model.cpp index feaf8bb98c..519164999d 100644 --- a/examples/widgets/itemviews/interview/model.cpp +++ b/examples/widgets/itemviews/interview/model.cpp @@ -132,7 +132,7 @@ bool Model::hasChildren(const QModelIndex &parent) const Qt::ItemFlags Model::flags(const QModelIndex &index) const { if (!index.isValid()) - return 0; + return {}; return Qt::ItemIsDragEnabled|QAbstractItemModel::flags(index); } @@ -146,7 +146,7 @@ Model::Node *Model::node(int row, Node *parent) const Model::Node *Model::parent(Node *child) const { - return child ? child->parent : 0; + return child ? child->parent : nullptr; } int Model::row(Node *node) const diff --git a/examples/widgets/itemviews/stardelegate/main.cpp b/examples/widgets/itemviews/stardelegate/main.cpp index 452976bba0..5ca85a6151 100644 --- a/examples/widgets/itemviews/stardelegate/main.cpp +++ b/examples/widgets/itemviews/stardelegate/main.cpp @@ -48,7 +48,8 @@ ** ****************************************************************************/ -#include +#include +#include #include "stardelegate.h" #include "stareditor.h" @@ -57,7 +58,7 @@ //! [0] void populateTableWidget(QTableWidget *tableWidget) { - static const struct { + static constexpr struct { const char *title; const char *genre; const char *artist; @@ -70,12 +71,12 @@ void populateTableWidget(QTableWidget *tableWidget) { "Sex Bomb", "Pop", "Tom Jones", 3 }, { "Barbie Girl", "Pop", "Aqua", 5 }, //! [2] - { 0, 0, 0, 0 } + { nullptr, nullptr, nullptr, 0 } //! [2] //! [3] }; //! [3] //! [4] - for (int row = 0; staticData[row].title != 0; ++row) { + for (int row = 0; staticData[row].title != nullptr; ++row) { QTableWidgetItem *item0 = new QTableWidgetItem(staticData[row].title); QTableWidgetItem *item1 = new QTableWidgetItem(staticData[row].genre); QTableWidgetItem *item2 = new QTableWidgetItem(staticData[row].artist); diff --git a/examples/widgets/painting/deform/pathdeform.cpp b/examples/widgets/painting/deform/pathdeform.cpp index 64e81f8cab..d5c8746247 100644 --- a/examples/widgets/painting/deform/pathdeform.cpp +++ b/examples/widgets/painting/deform/pathdeform.cpp @@ -262,7 +262,7 @@ PathDeformWidget::PathDeformWidget(QWidget *parent, bool smallScreen) QHBoxLayout *mainLayout = new QHBoxLayout(this); mainLayout->addWidget(m_renderer); - m_controls = new PathDeformControls(0, m_renderer, smallScreen); + m_controls = new PathDeformControls(nullptr, m_renderer, smallScreen); m_controls->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); if (!smallScreen) diff --git a/examples/widgets/painting/fontsampler/mainwindow.h b/examples/widgets/painting/fontsampler/mainwindow.h index ffb2839ffa..34e54440d4 100644 --- a/examples/widgets/painting/fontsampler/mainwindow.h +++ b/examples/widgets/painting/fontsampler/mainwindow.h @@ -70,7 +70,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindowBase Q_OBJECT public: - MainWindow(QWidget *parent = 0); + MainWindow(QWidget *parent = nullptr); public slots: void on_clearAction_triggered(); diff --git a/examples/widgets/painting/gradients/gradients.cpp b/examples/widgets/painting/gradients/gradients.cpp index a4528ce06f..d62ae93a15 100644 --- a/examples/widgets/painting/gradients/gradients.cpp +++ b/examples/widgets/painting/gradients/gradients.cpp @@ -102,9 +102,9 @@ uint ShadeWidget::colorAt(int x) generateShade(); QPolygonF pts = m_hoverPoints->points(); - for (int i=1; i < pts.size(); ++i) { - if (pts.at(i-1).x() <= x && pts.at(i).x() >= x) { - QLineF l(pts.at(i-1), pts.at(i)); + for (int i = 1; i < pts.size(); ++i) { + if (pts.at(i - 1).x() <= x && pts.at(i).x() >= x) { + QLineF l(pts.at(i - 1), pts.at(i)); l.setLength(l.length() * ((x - l.x1()) / l.dx())); return m_shade.pixel(qRound(qMin(l.x2(), (qreal(m_shade.width() - 1)))), qRound(qMin(l.y2(), qreal(m_shade.height() - 1)))); @@ -118,9 +118,9 @@ void ShadeWidget::setGradientStops(const QGradientStops &stops) if (m_shade_type == ARGBShade) { m_alpha_gradient = QLinearGradient(0, 0, width(), 0); - for (int i=0; icolorAt(int(x))) >> 16, - (0x0000ff00 & m_green_shade->colorAt(int(x))) >> 8, - (0x000000ff & m_blue_shade->colorAt(int(x))), - (0xff000000 & m_alpha_shade->colorAt(int(x))) >> 24); + QColor color((0x00ff0000 & m_red_shade->colorAt(x)) >> 16, + (0x0000ff00 & m_green_shade->colorAt(x)) >> 8, + (0x000000ff & m_blue_shade->colorAt(x)), + (0xff000000 & m_alpha_shade->colorAt(x)) >> 24); if (x / w > 1) return; @@ -568,8 +568,8 @@ void GradientRenderer::paint(QPainter *p) g = QConicalGradient(pts.at(0), angle); } - for (int i = 0; i < m_stops.size(); ++i) - g.setColorAt(m_stops.at(i).first, m_stops.at(i).second); + for (const auto &stop : qAsConst(m_stops)) + g.setColorAt(stop.first, stop.second); g.setSpread(m_spread); diff --git a/examples/widgets/painting/gradients/gradients.h b/examples/widgets/painting/gradients/gradients.h index c6525d18f8..45ef5d0f93 100644 --- a/examples/widgets/painting/gradients/gradients.h +++ b/examples/widgets/painting/gradients/gradients.h @@ -157,7 +157,7 @@ class GradientWidget : public QWidget Q_OBJECT public: - GradientWidget(QWidget *parent); + GradientWidget(QWidget *parent = nullptr); public slots: void setDefault1() { setDefault(1); } diff --git a/examples/widgets/painting/gradients/main.cpp b/examples/widgets/painting/gradients/main.cpp index 539d67e40e..0ddf7a4579 100644 --- a/examples/widgets/painting/gradients/main.cpp +++ b/examples/widgets/painting/gradients/main.cpp @@ -58,8 +58,8 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); - GradientWidget gradientWidget(0); - QStyle *arthurStyle = new ArthurStyle(); + GradientWidget gradientWidget; + QStyle *arthurStyle = new ArthurStyle; gradientWidget.setStyle(arthurStyle); const QList widgets = gradientWidget.findChildren(); for (QWidget *w : widgets) { diff --git a/examples/widgets/painting/painterpaths/renderarea.h b/examples/widgets/painting/painterpaths/renderarea.h index 5f0874b772..4b3ea5a397 100644 --- a/examples/widgets/painting/painterpaths/renderarea.h +++ b/examples/widgets/painting/painterpaths/renderarea.h @@ -60,7 +60,7 @@ class RenderArea : public QWidget Q_OBJECT public: - explicit RenderArea(const QPainterPath &path, QWidget *parent = 0); + explicit RenderArea(const QPainterPath &path, QWidget *parent = nullptr); QSize minimumSizeHint() const override; QSize sizeHint() const override; diff --git a/examples/widgets/painting/pathstroke/pathstroke.cpp b/examples/widgets/painting/pathstroke/pathstroke.cpp index e4009f0b1a..a850ce2672 100644 --- a/examples/widgets/painting/pathstroke/pathstroke.cpp +++ b/examples/widgets/painting/pathstroke/pathstroke.cpp @@ -48,11 +48,9 @@ ** ****************************************************************************/ +#include "pathstroke.h" #include "arthurstyle.h" #include "arthurwidgets.h" -#include "pathstroke.h" - -#include extern void draw_round_rect(QPainter *p, const QRect &bounds, int radius); @@ -164,24 +162,39 @@ void PathStrokeControls::createCommonControls(QWidget* parent) // Connections - connect(flatCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setFlatCap); - connect(squareCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSquareCap); - connect(roundCap, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setRoundCap); - - connect(bevelJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setBevelJoin); - connect(miterJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setMiterJoin); - connect(svgMiterJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSvgMiterJoin); - connect(roundJoin, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setRoundJoin); - - connect(curveMode, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setCurveMode); - connect(lineMode, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setLineMode); - - connect(solidLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setSolidLine); - connect(dashLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashLine); - connect(dotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDotLine); - connect(dashDotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashDotLine); - connect(dashDotDotLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setDashDotDotLine); - connect(customDashLine, &QAbstractButton::clicked, m_renderer, &PathStrokeRenderer::setCustomDashLine); + connect(flatCap, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setFlatCap); + connect(squareCap, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setSquareCap); + connect(roundCap, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setRoundCap); + + connect(bevelJoin, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setBevelJoin); + connect(miterJoin, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setMiterJoin); + connect(svgMiterJoin, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setSvgMiterJoin); + connect(roundJoin, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setRoundJoin); + + connect(curveMode, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setCurveMode); + connect(lineMode, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setLineMode); + + connect(solidLine, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setSolidLine); + connect(dashLine, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setDashLine); + connect(dotLine, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setDotLine); + connect(dashDotLine, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setDashDotLine); + connect(dashDotDotLine, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setDashDotDotLine); + connect(customDashLine, &QAbstractButton::clicked, + m_renderer, &PathStrokeRenderer::setCustomDashLine); // Set the defaults: flatCap->setChecked(true); @@ -247,15 +260,20 @@ void PathStrokeControls::layoutForDesktop() // Set up connections - connect(animated, &QAbstractButton::toggled, m_renderer, &PathStrokeRenderer::setAnimation); + connect(animated, &QAbstractButton::toggled, + m_renderer, &PathStrokeRenderer::setAnimation); - connect(penWidth, &QAbstractSlider::valueChanged, m_renderer, &PathStrokeRenderer::setPenWidth); + connect(penWidth, &QAbstractSlider::valueChanged, + m_renderer, &PathStrokeRenderer::setPenWidth); - connect(showSourceButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::showSource); + connect(showSourceButton, &QAbstractButton::clicked, + m_renderer, &ArthurFrame::showSource); #if QT_CONFIG(opengl) - connect(enableOpenGLButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::enableOpenGL); + connect(enableOpenGLButton, &QAbstractButton::clicked, + m_renderer, &ArthurFrame::enableOpenGL); #endif - connect(whatsThisButton, &QAbstractButton::clicked, m_renderer, &ArthurFrame::setDescriptionEnabled); + connect(whatsThisButton, &QAbstractButton::clicked, + m_renderer, &ArthurFrame::setDescriptionEnabled); connect(m_renderer, &ArthurFrame::descriptionEnabledChanged, whatsThisButton, &QAbstractButton::setChecked); @@ -296,11 +314,11 @@ void PathStrokeControls::layoutForSmallScreens() #endif // Layouts: - QHBoxLayout *penWidthLayout = new QHBoxLayout(0); + QHBoxLayout *penWidthLayout = new QHBoxLayout; penWidthLayout->addWidget(penWidthLabel, 0, Qt::AlignRight); penWidthLayout->addWidget(penWidth); - QVBoxLayout *leftLayout = new QVBoxLayout(0); + QVBoxLayout *leftLayout = new QVBoxLayout; leftLayout->addWidget(m_capGroup); leftLayout->addWidget(m_joinGroup); #if QT_CONFIG(opengl) @@ -308,7 +326,7 @@ void PathStrokeControls::layoutForSmallScreens() #endif leftLayout->addLayout(penWidthLayout); - QVBoxLayout *rightLayout = new QVBoxLayout(0); + QVBoxLayout *rightLayout = new QVBoxLayout; rightLayout->addWidget(m_styleGroup); rightLayout->addWidget(m_pathModeGroup); @@ -356,7 +374,7 @@ PathStrokeWidget::PathStrokeWidget(bool smallScreen) // Widget construction and property setting m_renderer = new PathStrokeRenderer(this, smallScreen); - m_controls = new PathStrokeControls(0, m_renderer, smallScreen); + m_controls = new PathStrokeControls(nullptr, m_renderer, smallScreen); // Layouting QHBoxLayout *viewLayout = new QHBoxLayout(this); @@ -383,10 +401,10 @@ void PathStrokeWidget::hideControls() m_controls->hide(); } -void PathStrokeWidget::setStyle( QStyle * style ) +void PathStrokeWidget::setStyle(QStyle *style) { QWidget::setStyle(style); - if (m_controls != 0) + if (m_controls != nullptr) { m_controls->setStyle(style); @@ -516,7 +534,7 @@ void PathStrokeRenderer::updatePoints() qreal bottom = height() - pad; Q_ASSERT(m_points.size() == m_vectors.size()); - for (int i=0; ipos(), m_points.at(i)).length(); if ((distance < 0 && d < 8 * m_pointSize) || d < distance) { distance = d; @@ -673,7 +691,6 @@ bool PathStrokeRenderer::event(QEvent *e) m_fingerPointMapping.clear(); setAnimation(m_wasAnimated); return true; - break; default: break; } diff --git a/examples/widgets/painting/pathstroke/pathstroke.h b/examples/widgets/painting/pathstroke/pathstroke.h index 7bc7e09003..b559ed2ba0 100644 --- a/examples/widgets/painting/pathstroke/pathstroke.h +++ b/examples/widgets/painting/pathstroke/pathstroke.h @@ -169,7 +169,7 @@ class PathStrokeWidget : public QWidget public: PathStrokeWidget(bool smallScreen); - void setStyle ( QStyle * style ); + void setStyle(QStyle *style); private: PathStrokeRenderer *m_renderer; diff --git a/examples/widgets/painting/shared/arthurstyle.h b/examples/widgets/painting/shared/arthurstyle.h index 8ea8354bab..64c888b636 100644 --- a/examples/widgets/painting/shared/arthurstyle.h +++ b/examples/widgets/painting/shared/arthurstyle.h @@ -63,7 +63,7 @@ public: void drawHoverRect(QPainter *painter, const QRect &rect) const; void drawPrimitive(PrimitiveElement element, const QStyleOption *option, - QPainter *painter, const QWidget *widget = 0) const override; + QPainter *painter, const QWidget *widget = nullptr) const override; void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override; void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, diff --git a/examples/widgets/painting/shared/arthurwidgets.cpp b/examples/widgets/painting/shared/arthurwidgets.cpp index 285be99d20..40d712c9e3 100644 --- a/examples/widgets/painting/shared/arthurwidgets.cpp +++ b/examples/widgets/painting/shared/arthurwidgets.cpp @@ -136,7 +136,7 @@ void ArthurFrame::createGlWindow() void ArthurFrame::paintEvent(QPaintEvent *e) { - static QImage *static_image = 0; + static QImage *static_image = nullptr; QPainter painter; @@ -376,7 +376,7 @@ void ArthurFrame::showSource() const QString html = QStringLiteral("
") + contents + QStringLiteral("
"); - QTextBrowser *sourceViewer = new QTextBrowser(0); + QTextBrowser *sourceViewer = new QTextBrowser; sourceViewer->setWindowTitle(tr("Source: %1").arg(m_sourceFileName.midRef(5))); sourceViewer->setParent(this, Qt::Dialog); sourceViewer->setAttribute(Qt::WA_DeleteOnClose); diff --git a/examples/widgets/painting/shared/fbopaintdevice.cpp b/examples/widgets/painting/shared/fbopaintdevice.cpp index 8207090cc8..9368293218 100644 --- a/examples/widgets/painting/shared/fbopaintdevice.cpp +++ b/examples/widgets/painting/shared/fbopaintdevice.cpp @@ -53,7 +53,7 @@ #include #include -QFboPaintDevice::QFboPaintDevice(const QSize& size, bool flipped, bool clearOnInit, +QFboPaintDevice::QFboPaintDevice(const QSize &size, bool flipped, bool clearOnInit, QOpenGLFramebufferObject::Attachment attachment) : QOpenGLPaintDevice(size) { @@ -97,8 +97,8 @@ GLuint QFboPaintDevice::takeTexture() QImage QFboPaintDevice::toImage() const { - QOpenGLContext* currentContext = QOpenGLContext::currentContext(); - QSurface* currentSurface = currentContext ? currentContext->surface() : 0; + QOpenGLContext *currentContext = QOpenGLContext::currentContext(); + QSurface *currentSurface = currentContext ? currentContext->surface() : nullptr; context()->makeCurrent(m_surface); diff --git a/examples/widgets/painting/shared/fbopaintdevice.h b/examples/widgets/painting/shared/fbopaintdevice.h index 78451af895..a42bcc756d 100644 --- a/examples/widgets/painting/shared/fbopaintdevice.h +++ b/examples/widgets/painting/shared/fbopaintdevice.h @@ -60,7 +60,7 @@ class QFboPaintDevice : public QOpenGLPaintDevice { public: - QFboPaintDevice(const QSize&, bool flipped = false, bool clearOnInit = true, + QFboPaintDevice(const QSize &size, bool flipped = false, bool clearOnInit = true, QOpenGLFramebufferObject::Attachment = QOpenGLFramebufferObject::CombinedDepthStencil); ~QFboPaintDevice(); @@ -83,7 +83,7 @@ public: private: QOpenGLFramebufferObject *m_framebufferObject; - QSurface* m_surface; + QSurface *m_surface; }; #endif // QT_NO_OPENGL diff --git a/examples/widgets/painting/shared/hoverpoints.cpp b/examples/widgets/painting/shared/hoverpoints.cpp index 2032fb5a2c..2bf3963e9e 100644 --- a/examples/widgets/painting/shared/hoverpoints.cpp +++ b/examples/widgets/painting/shared/hoverpoints.cpp @@ -262,8 +262,8 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event) case QEvent::Paint: { QWidget *that_widget = m_widget; - m_widget = 0; - QApplication::sendEvent(object, event); + m_widget = nullptr; + QCoreApplication::sendEvent(object, event); m_widget = that_widget; paintPoints(); return true; diff --git a/examples/widgets/painting/transformations/renderarea.h b/examples/widgets/painting/transformations/renderarea.h index 140be27b2b..d4be7cefa4 100644 --- a/examples/widgets/painting/transformations/renderarea.h +++ b/examples/widgets/painting/transformations/renderarea.h @@ -70,7 +70,7 @@ class RenderArea : public QWidget Q_OBJECT public: - RenderArea(QWidget *parent = 0); + RenderArea(QWidget *parent = nullptr); void setOperations(const QList &operations); void setShape(const QPainterPath &shape); diff --git a/examples/widgets/scroller/graphicsview/main.cpp b/examples/widgets/scroller/graphicsview/main.cpp index d6b2956d50..178c431e6c 100644 --- a/examples/widgets/scroller/graphicsview/main.cpp +++ b/examples/widgets/scroller/graphicsview/main.cpp @@ -64,7 +64,7 @@ class RectObject : public QGraphicsObject public: - RectObject(const QString &text, qreal x, qreal y, qreal width, qreal height, QBrush brush, QGraphicsItem *parent = 0) + RectObject(const QString &text, qreal x, qreal y, qreal width, qreal height, QBrush brush, QGraphicsItem *parent = nullptr) : QGraphicsObject(parent) , m_text(text) , m_rect(x, y, width, height) diff --git a/examples/widgets/statemachine/eventtransitions/main.cpp b/examples/widgets/statemachine/eventtransitions/main.cpp index 2de8e5daa3..fe9518092f 100644 --- a/examples/widgets/statemachine/eventtransitions/main.cpp +++ b/examples/widgets/statemachine/eventtransitions/main.cpp @@ -48,13 +48,18 @@ ** ****************************************************************************/ -#include +#include +#include +#include +#include +#include +#include //! [0] class Window : public QWidget { public: - Window(QWidget *parent = 0) + Window(QWidget *parent = nullptr) : QWidget(parent) { QPushButton *button = new QPushButton(this); diff --git a/examples/widgets/statemachine/factorial/main.cpp b/examples/widgets/statemachine/factorial/main.cpp index e9431596fe..e6cbdcae29 100644 --- a/examples/widgets/statemachine/factorial/main.cpp +++ b/examples/widgets/statemachine/factorial/main.cpp @@ -57,10 +57,7 @@ class Factorial : public QObject Q_PROPERTY(int x READ x WRITE setX) Q_PROPERTY(int fac READ fac WRITE setFac) public: - Factorial(QObject *parent = 0) - : QObject(parent), m_x(-1), m_fac(1) - { - } + using QObject::QObject; int x() const { @@ -89,8 +86,8 @@ Q_SIGNALS: void xChanged(int value); private: - int m_x; - int m_fac; + int m_x = -1; + int m_fac = 1; }; //! [0] diff --git a/examples/widgets/statemachine/trafficlight/main.cpp b/examples/widgets/statemachine/trafficlight/main.cpp index a12d2f10d1..dd8bddcb37 100644 --- a/examples/widgets/statemachine/trafficlight/main.cpp +++ b/examples/widgets/statemachine/trafficlight/main.cpp @@ -48,7 +48,13 @@ ** ****************************************************************************/ -#include +#include +#include +#include +#include +#include +#include +#include //! [0] class LightWidget : public QWidget @@ -56,7 +62,7 @@ class LightWidget : public QWidget Q_OBJECT Q_PROPERTY(bool on READ isOn WRITE setOn) public: - LightWidget(const QColor &color, QWidget *parent = 0) + LightWidget(const QColor &color, QWidget *parent = nullptr) : QWidget(parent), m_color(color), m_on(false) {} bool isOn() const @@ -94,7 +100,7 @@ private: class TrafficLightWidget : public QWidget { public: - TrafficLightWidget(QWidget *parent = 0) + TrafficLightWidget(QWidget *parent = nullptr) : QWidget(parent) { QVBoxLayout *vbox = new QVBoxLayout(this); @@ -125,7 +131,7 @@ private: //! [1] //! [2] -QState *createLightState(LightWidget *light, int duration, QState *parent = 0) +QState *createLightState(LightWidget *light, int duration, QState *parent = nullptr) { QState *lightState = new QState(parent); QTimer *timer = new QTimer(lightState); diff --git a/examples/widgets/touch/fingerpaint/scribblearea.h b/examples/widgets/touch/fingerpaint/scribblearea.h index 5138e3a1ab..fcdde53cc4 100644 --- a/examples/widgets/touch/fingerpaint/scribblearea.h +++ b/examples/widgets/touch/fingerpaint/scribblearea.h @@ -62,7 +62,7 @@ class ScribbleArea : public QWidget Q_OBJECT public: - ScribbleArea(QWidget *parent = 0); + ScribbleArea(QWidget *parent = nullptr); bool openImage(const QString &fileName); bool saveImage(const QString &fileName, const char *fileFormat); diff --git a/examples/widgets/touch/pinchzoom/graphicsview.cpp b/examples/widgets/touch/pinchzoom/graphicsview.cpp index 54e134aea2..6412f350a7 100644 --- a/examples/widgets/touch/pinchzoom/graphicsview.cpp +++ b/examples/widgets/touch/pinchzoom/graphicsview.cpp @@ -54,7 +54,7 @@ #include GraphicsView::GraphicsView(QGraphicsScene *scene, QWidget *parent) - : QGraphicsView(scene, parent), totalScaleFactor(1) + : QGraphicsView(scene, parent) { viewport()->setAttribute(Qt::WA_AcceptTouchEvents); setDragMode(ScrollHandDrag); @@ -83,8 +83,8 @@ bool GraphicsView::viewportEvent(QEvent *event) totalScaleFactor *= currentScaleFactor; currentScaleFactor = 1; } - setTransform(QTransform().scale(totalScaleFactor * currentScaleFactor, - totalScaleFactor * currentScaleFactor)); + setTransform(QTransform::fromScale(totalScaleFactor * currentScaleFactor, + totalScaleFactor * currentScaleFactor)); } return true; } diff --git a/examples/widgets/touch/pinchzoom/graphicsview.h b/examples/widgets/touch/pinchzoom/graphicsview.h index d4e2e32d36..c0faeba444 100644 --- a/examples/widgets/touch/pinchzoom/graphicsview.h +++ b/examples/widgets/touch/pinchzoom/graphicsview.h @@ -56,10 +56,10 @@ class GraphicsView : public QGraphicsView Q_OBJECT public: - GraphicsView(QGraphicsScene *scene = 0, QWidget *parent = 0); + GraphicsView(QGraphicsScene *scene = nullptr, QWidget *parent = nullptr); bool viewportEvent(QEvent *event) override; private: - qreal totalScaleFactor; + qreal totalScaleFactor = 1; }; diff --git a/examples/widgets/touch/pinchzoom/main.cpp b/examples/widgets/touch/pinchzoom/main.cpp index 938432600f..2c2ba39a26 100644 --- a/examples/widgets/touch/pinchzoom/main.cpp +++ b/examples/widgets/touch/pinchzoom/main.cpp @@ -51,11 +51,10 @@ #include "graphicsview.h" #include "mouse.h" -#include +#include +#include -#include - -static const int MouseCount = 7; +static constexpr int MouseCount = 7; //! [0] int main(int argc, char **argv) diff --git a/examples/widgets/touch/pinchzoom/mouse.cpp b/examples/widgets/touch/pinchzoom/mouse.cpp index 1dfd7d749c..8456a0214d 100644 --- a/examples/widgets/touch/pinchzoom/mouse.cpp +++ b/examples/widgets/touch/pinchzoom/mouse.cpp @@ -56,8 +56,8 @@ #include #include -const qreal Pi = M_PI; -const qreal TwoPi = 2 * M_PI; +constexpr qreal Pi = M_PI; +constexpr qreal TwoPi = 2 * M_PI; static qreal normalizeAngle(qreal angle) { @@ -69,9 +69,9 @@ static qreal normalizeAngle(qreal angle) } //! [0] -Mouse::Mouse() - : angle(0), speed(0), mouseEyeDirection(0), - color(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256)) +Mouse::Mouse() : color(QRandomGenerator::global()->bounded(256), + QRandomGenerator::global()->bounded(256), + QRandomGenerator::global()->bounded(256)) { setTransform(QTransform().rotate(QRandomGenerator::global()->bounded(360 * 16)), true); startTimer(1000 / 33); diff --git a/examples/widgets/touch/pinchzoom/mouse.h b/examples/widgets/touch/pinchzoom/mouse.h index 870bfcd6c0..8ac110821e 100644 --- a/examples/widgets/touch/pinchzoom/mouse.h +++ b/examples/widgets/touch/pinchzoom/mouse.h @@ -70,9 +70,9 @@ protected: void timerEvent(QTimerEvent *event) override; private: - qreal angle; - qreal speed; - qreal mouseEyeDirection; + qreal angle = 0; + qreal speed = 0; + qreal mouseEyeDirection = 0; QColor color; }; //! [0] diff --git a/examples/widgets/tutorials/addressbook/part1/addressbook.h b/examples/widgets/tutorials/addressbook/part1/addressbook.h index 1d575e1260..4c2b456a41 100644 --- a/examples/widgets/tutorials/addressbook/part1/addressbook.h +++ b/examples/widgets/tutorials/addressbook/part1/addressbook.h @@ -65,7 +65,7 @@ class AddressBook : public QWidget Q_OBJECT public: - AddressBook(QWidget *parent = 0); + AddressBook(QWidget *parent = nullptr); private: QLineEdit *nameLine; diff --git a/examples/widgets/tutorials/addressbook/part2/addressbook.h b/examples/widgets/tutorials/addressbook/part2/addressbook.h index 7b1714b443..e690d14244 100644 --- a/examples/widgets/tutorials/addressbook/part2/addressbook.h +++ b/examples/widgets/tutorials/addressbook/part2/addressbook.h @@ -66,7 +66,7 @@ class AddressBook : public QWidget Q_OBJECT public: - AddressBook(QWidget *parent = 0); + AddressBook(QWidget *parent = nullptr); //! [slots] public slots: diff --git a/examples/widgets/tutorials/addressbook/part3/addressbook.h b/examples/widgets/tutorials/addressbook/part3/addressbook.h index 746a58a32a..f4a8aaa976 100644 --- a/examples/widgets/tutorials/addressbook/part3/addressbook.h +++ b/examples/widgets/tutorials/addressbook/part3/addressbook.h @@ -66,7 +66,7 @@ class AddressBook : public QWidget Q_OBJECT public: - AddressBook(QWidget *parent = 0); + AddressBook(QWidget *parent = nullptr); public slots: void addContact(); diff --git a/examples/widgets/tutorials/addressbook/part4/addressbook.h b/examples/widgets/tutorials/addressbook/part4/addressbook.h index a8d4d9fe1d..307df1eb15 100644 --- a/examples/widgets/tutorials/addressbook/part4/addressbook.h +++ b/examples/widgets/tutorials/addressbook/part4/addressbook.h @@ -66,7 +66,7 @@ class AddressBook : public QWidget Q_OBJECT public: - AddressBook(QWidget *parent = 0); + AddressBook(QWidget *parent = nullptr); //! [Mode enum] enum Mode { NavigationMode, AddingMode, EditingMode }; //! [Mode enum] diff --git a/examples/widgets/tutorials/addressbook/part5/addressbook.h b/examples/widgets/tutorials/addressbook/part5/addressbook.h index b60929a50c..9dd7ed1d89 100644 --- a/examples/widgets/tutorials/addressbook/part5/addressbook.h +++ b/examples/widgets/tutorials/addressbook/part5/addressbook.h @@ -69,7 +69,7 @@ class AddressBook : public QWidget Q_OBJECT public: - AddressBook(QWidget *parent = 0); + AddressBook(QWidget *parent = nullptr); enum Mode { NavigationMode, AddingMode, EditingMode }; public slots: diff --git a/examples/widgets/tutorials/addressbook/part5/finddialog.h b/examples/widgets/tutorials/addressbook/part5/finddialog.h index 0fca6be81b..8e63eeee79 100644 --- a/examples/widgets/tutorials/addressbook/part5/finddialog.h +++ b/examples/widgets/tutorials/addressbook/part5/finddialog.h @@ -63,7 +63,7 @@ class FindDialog : public QDialog Q_OBJECT public: - FindDialog(QWidget *parent = 0); + FindDialog(QWidget *parent = nullptr); QString getFindText(); public slots: diff --git a/examples/widgets/tutorials/addressbook/part6/addressbook.h b/examples/widgets/tutorials/addressbook/part6/addressbook.h index 8d328310f7..fca62c52b7 100644 --- a/examples/widgets/tutorials/addressbook/part6/addressbook.h +++ b/examples/widgets/tutorials/addressbook/part6/addressbook.h @@ -68,7 +68,7 @@ class AddressBook : public QWidget Q_OBJECT public: - AddressBook(QWidget *parent = 0); + AddressBook(QWidget *parent = nullptr); enum Mode { NavigationMode, AddingMode, EditingMode }; public slots: diff --git a/examples/widgets/tutorials/addressbook/part6/finddialog.h b/examples/widgets/tutorials/addressbook/part6/finddialog.h index 527e0254e9..46f8047a56 100644 --- a/examples/widgets/tutorials/addressbook/part6/finddialog.h +++ b/examples/widgets/tutorials/addressbook/part6/finddialog.h @@ -63,7 +63,7 @@ class FindDialog : public QDialog Q_OBJECT public: - FindDialog(QWidget *parent = 0); + FindDialog(QWidget *parent = nullptr); QString getFindText(); public slots: diff --git a/examples/widgets/tutorials/addressbook/part7/addressbook.h b/examples/widgets/tutorials/addressbook/part7/addressbook.h index 0f109b2ef1..47a0f3c062 100644 --- a/examples/widgets/tutorials/addressbook/part7/addressbook.h +++ b/examples/widgets/tutorials/addressbook/part7/addressbook.h @@ -68,7 +68,7 @@ class AddressBook : public QWidget Q_OBJECT public: - AddressBook(QWidget *parent = 0); + AddressBook(QWidget *parent = nullptr); enum Mode { NavigationMode, AddingMode, EditingMode }; public slots: diff --git a/examples/widgets/tutorials/addressbook/part7/finddialog.h b/examples/widgets/tutorials/addressbook/part7/finddialog.h index 527e0254e9..46f8047a56 100644 --- a/examples/widgets/tutorials/addressbook/part7/finddialog.h +++ b/examples/widgets/tutorials/addressbook/part7/finddialog.h @@ -63,7 +63,7 @@ class FindDialog : public QDialog Q_OBJECT public: - FindDialog(QWidget *parent = 0); + FindDialog(QWidget *parent = nullptr); QString getFindText(); public slots: diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp b/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp index 2330019f93..90a8c6e894 100644 --- a/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp +++ b/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); QTableView tableView; - MyModel myModel(0); + MyModel myModel; tableView.setModel(&myModel); tableView.show(); return a.exec(); diff --git a/examples/widgets/tutorials/modelview/7_selections/mainwindow.h b/examples/widgets/tutorials/modelview/7_selections/mainwindow.h index c9761dd3d9..74906c831d 100644 --- a/examples/widgets/tutorials/modelview/7_selections/mainwindow.h +++ b/examples/widgets/tutorials/modelview/7_selections/mainwindow.h @@ -69,7 +69,7 @@ private: private slots: void selectionChangedSlot(const QItemSelection &newSelection, const QItemSelection &oldSelection); public: - MainWindow(QWidget *parent = 0); + MainWindow(QWidget *parent = nullptr); }; #endif // MAINWINDOW_H diff --git a/examples/widgets/tutorials/notepad/notepad.h b/examples/widgets/tutorials/notepad/notepad.h index 9580ab8071..5e44dfeedc 100644 --- a/examples/widgets/tutorials/notepad/notepad.h +++ b/examples/widgets/tutorials/notepad/notepad.h @@ -72,7 +72,7 @@ class Notepad : public QMainWindow //! [4] public: - explicit Notepad(QWidget *parent = 0); + explicit Notepad(QWidget *parent = nullptr); //! [4] //! [5] ~Notepad(); diff --git a/examples/widgets/windowcontainer/windowcontainer.cpp b/examples/widgets/windowcontainer/windowcontainer.cpp index 9f2124c4e1..b920c85420 100644 --- a/examples/widgets/windowcontainer/windowcontainer.cpp +++ b/examples/widgets/windowcontainer/windowcontainer.cpp @@ -50,16 +50,14 @@ #include "openglwindow.h" -#include -#include -#include -#include - #include -#include +#include #include +#include #include - +#include +#include +#include // Making use of the class from the opengl example in gui. @@ -67,13 +65,10 @@ class Window : public OpenGLWindow { Q_OBJECT public: - Window() - : m_mouseDown(false) - , m_focus(false) - { - } + using OpenGLWindow::OpenGLWindow; - void render(QPainter *p) override { + void render(QPainter *p) override + { QLinearGradient g(0, 0, 0, height()); g.setColorAt(0, QColor("lightsteelblue")); g.setColorAt(1, Qt::black); @@ -93,15 +88,15 @@ public: p->restore(); } - if (m_focus) { + if (m_focus) p->drawText(20, height() - 20, QLatin1String("Window has focus!")); - } p->setRenderHint(QPainter::Antialiasing); p->drawPolyline(m_polygon); } - void mousePressEvent(QMouseEvent *e) override { + void mousePressEvent(QMouseEvent *e) override + { if (!m_mouseDown) { m_mouseDown = true; m_polygon.clear(); @@ -110,14 +105,16 @@ public: } } - void mouseMoveEvent(QMouseEvent *e) override { + void mouseMoveEvent(QMouseEvent *e) override + { if (m_mouseDown) { m_polygon.append(e->pos()); renderLater(); } } - void mouseReleaseEvent(QMouseEvent *e) override { + void mouseReleaseEvent(QMouseEvent *e) override + { if (m_mouseDown) { m_mouseDown = false; m_polygon.append(e->pos()); @@ -125,33 +122,35 @@ public: } } - void focusInEvent(QFocusEvent *) override { + void focusInEvent(QFocusEvent *) override + { m_focus = true; renderLater(); } - void focusOutEvent(QFocusEvent *) override { + void focusOutEvent(QFocusEvent *) override + { m_focus = false; m_polygon.clear(); renderLater(); } - void keyPressEvent(QKeyEvent *e) override { + void keyPressEvent(QKeyEvent *e) override + { m_key = e->text(); renderLater(); } - void keyReleaseEvent(QKeyEvent *) override { + void keyReleaseEvent(QKeyEvent *) override + { m_key = QString(); renderLater(); } private: QPolygon m_polygon; - bool m_mouseDown; - - bool m_focus; - QString m_key; + bool m_mouseDown = false; + bool m_focus = false; }; @@ -162,7 +161,7 @@ int main(int argc, char *argv[]) QWidget *widget = new QWidget; QHBoxLayout *layout = new QHBoxLayout(widget); - Window *window = new Window(); + Window *window = new Window; QWidget *container = QWidget::createWindowContainer(window); container->setMinimumSize(300, 300); -- cgit v1.2.3 From 60deb69034e3d3ac36213ad8c36042ad57c495f7 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 4 Oct 2019 13:26:27 +0200 Subject: Distinguish invalid datetimes from others A default-constructed QDateTime is invalid, but compared equal to a valid one referencing the start of 1970. This lead to date properties in QML being initialized invalid but not getting an onChange if the first value they're set to is the start of 1970. Fixing that then lead to some tests failing. Indeed, the original equality check involved using toMSecsSinceEpoch(), whose value is undefined unless the datetime is valid, without a prior check on its validity: so ensure all uses of toMSecsSinceEpoch() are guarded with isValid() checks. Reworked tst_QDateTime::toSecsSinceEpoch() to use its bool column (previously unused, after separating from toTime_t(), which uses this column for "out of time_t's range") for validity of the datetime. [ChangeLog][QtCore][QDateTime] Invalid datetimes are now treated as equal and less than all valid ones. They could previously be found equal to valid datetimes. Fixes: QTBUG-79006 Change-Id: Ie72deb8af4350a5e808144d0f6e42dc8eb3ff5ef Reviewed-by: Paul Wicking Reviewed-by: Thiago Macieira --- src/corelib/time/qdatetime.cpp | 40 +++++++++++++++------ .../auto/corelib/time/qdatetime/tst_qdatetime.cpp | 42 +++++++++++----------- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 6ed0efe77d..95a7255a04 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -3861,6 +3861,9 @@ int QDateTime::offsetFromUtc() const QString QDateTime::timeZoneAbbreviation() const { + if (!isValid()) + return QString(); + switch (getSpec(d)) { case Qt::UTC: return QLatin1String("UTC"); @@ -3895,6 +3898,9 @@ QString QDateTime::timeZoneAbbreviation() const bool QDateTime::isDaylightTime() const { + if (!isValid()) + return false; + switch (getSpec(d)) { case Qt::UTC: case Qt::OffsetFromUTC: @@ -4761,17 +4767,24 @@ QDateTime QDateTime::toTimeZone(const QTimeZone &timeZone) const Returns \c true if this datetime is equal to the \a other datetime; otherwise returns \c false. + Since 5.14, all invalid datetimes are equal to one another and differ from + all other datetimes. + \sa operator!=() */ bool QDateTime::operator==(const QDateTime &other) const { - if (getSpec(d) == Qt::LocalTime - && getStatus(d) == getStatus(other.d)) { + if (!isValid()) + return !other.isValid(); + if (!other.isValid()) + return false; + + if (getSpec(d) == Qt::LocalTime && getStatus(d) == getStatus(other.d)) return getMSecs(d) == getMSecs(other.d); - } + // Convert to UTC and compare - return (toMSecsSinceEpoch() == other.toMSecsSinceEpoch()); + return toMSecsSinceEpoch() == other.toMSecsSinceEpoch(); } /*! @@ -4780,8 +4793,9 @@ bool QDateTime::operator==(const QDateTime &other) const Returns \c true if this datetime is different from the \a other datetime; otherwise returns \c false. - Two datetimes are different if either the date, the time, or the - time zone components are different. + Two datetimes are different if either the date, the time, or the time zone + components are different. Since 5.14, any invalid datetime is less than all + valid datetimes. \sa operator==() */ @@ -4793,12 +4807,16 @@ bool QDateTime::operator==(const QDateTime &other) const bool QDateTime::operator<(const QDateTime &other) const { - if (getSpec(d) == Qt::LocalTime - && getStatus(d) == getStatus(other.d)) { + if (!isValid()) + return other.isValid(); + if (!other.isValid()) + return false; + + if (getSpec(d) == Qt::LocalTime && getStatus(d) == getStatus(other.d)) return getMSecs(d) < getMSecs(other.d); - } + // Convert to UTC and compare - return (toMSecsSinceEpoch() < other.toMSecsSinceEpoch()); + return toMSecsSinceEpoch() < other.toMSecsSinceEpoch(); } /*! @@ -5849,7 +5867,7 @@ uint qHash(const QDateTime &key, uint seed) // QDate/QTime/spec/offset because QDateTime::operator== converts both arguments // to the same timezone. If we don't, qHash would return different hashes for // two QDateTimes that are equivalent once converted to the same timezone. - return qHash(key.toMSecsSinceEpoch(), seed); + return key.isValid() ? qHash(key.toMSecsSinceEpoch(), seed) : seed; } /*! \fn uint qHash(const QDate &key, uint seed = 0) diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 99176dc68d..216ae1f79e 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -360,6 +360,7 @@ void tst_QDateTime::ctor() void tst_QDateTime::operator_eq() { + QVERIFY(QDateTime() != QDateTime(QDate(1970, 1, 1), QTime(0, 0))); // QTBUG-79006 QDateTime dt1(QDate(2004, 3, 24), QTime(23, 45, 57), Qt::UTC); QDateTime dt2(QDate(2005, 3, 11), QTime(), Qt::UTC); dt2 = dt1; @@ -1675,29 +1676,30 @@ void tst_QDateTime::currentDateTimeUtc2() void tst_QDateTime::toSecsSinceEpoch_data() { QTest::addColumn("dateTimeStr"); - QTest::addColumn("res"); + QTest::addColumn("valid"); - QTest::newRow( "data1" ) << str( 1800, 1, 1, 12, 0, 0 ) << false; - QTest::newRow( "data2" ) << str( 1969, 1, 1, 12, 0, 0 ) << false; + QTest::newRow( "data1" ) << str( 1800, 1, 1, 12, 0, 0 ) << true; + QTest::newRow( "data2" ) << str( 1969, 1, 1, 12, 0, 0 ) << true; QTest::newRow( "data3" ) << str( 2002, 1, 1, 12, 0, 0 ) << true; QTest::newRow( "data4" ) << str( 2002, 6, 1, 12, 0, 0 ) << true; QTest::newRow( "data5" ) << QString("INVALID") << false; QTest::newRow( "data6" ) << str( 2038, 1, 1, 12, 0, 0 ) << true; QTest::newRow( "data7" ) << str( 2063, 4, 5, 12, 0, 0 ) << true; // the day of First Contact - QTest::newRow( "data8" ) << str( 2107, 1, 1, 12, 0, 0 ) - << bool( sizeof(uint) > 32 && sizeof(time_t) > 32 ); + QTest::newRow( "data8" ) << str( 2107, 1, 1, 12, 0, 0 ) << true; } void tst_QDateTime::toSecsSinceEpoch() { - QFETCH( QString, dateTimeStr ); - QDateTime datetime = dt( dateTimeStr ); - - qint64 asSecsSinceEpoch = datetime.toSecsSinceEpoch(); - QCOMPARE(asSecsSinceEpoch, datetime.toMSecsSinceEpoch() / 1000); + QFETCH(const QString, dateTimeStr); + const QDateTime datetime = dt(dateTimeStr); + QFETCH(const bool, valid); + QCOMPARE(datetime.isValid(), valid); - QDateTime datetime2 = QDateTime::fromSecsSinceEpoch(asSecsSinceEpoch); - QCOMPARE(datetime, datetime2); + if (valid) { + const qint64 asSecsSinceEpoch = datetime.toSecsSinceEpoch(); + QCOMPARE(asSecsSinceEpoch, datetime.toMSecsSinceEpoch() / 1000); + QCOMPARE(QDateTime::fromSecsSinceEpoch(asSecsSinceEpoch), datetime); + } } #if QT_DEPRECATED_SINCE(5, 8) @@ -1725,14 +1727,10 @@ void tst_QDateTime::toTime_t() uint asTime_t = datetime.toTime_t(); QFETCH( bool, res ); if (res) { - QVERIFY( asTime_t != (uint)-1 ); + QVERIFY(asTime_t != uint(-1)); + QCOMPARE(QDateTime::fromTime_t(asTime_t), datetime); } else { - QVERIFY( asTime_t == (uint)-1 ); - } - - if ( asTime_t != (uint) -1 ) { - QDateTime datetime2 = QDateTime::fromTime_t( asTime_t ); - QCOMPARE(datetime, datetime2); + QCOMPARE(asTime_t, uint(-1)); } } #endif @@ -1929,8 +1927,8 @@ void tst_QDateTime::operator_eqeq_data() QDateTime dateTime1(QDate(2012, 6, 20), QTime(14, 33, 2, 500)); QDateTime dateTime1a = dateTime1.addMSecs(1); - QDateTime dateTime2(QDate(2012, 20, 6), QTime(14, 33, 2, 500)); - QDateTime dateTime2a = dateTime2.addMSecs(-1); + QDateTime dateTime2(QDate(2012, 20, 6), QTime(14, 33, 2, 500)); // Invalid + QDateTime dateTime2a = dateTime2.addMSecs(-1); // Still invalid QDateTime dateTime3(QDate(1970, 1, 1), QTime(0, 0, 0, 0), Qt::UTC); // UTC epoch QDateTime dateTime3a = dateTime3.addDays(1); QDateTime dateTime3b = dateTime3.addDays(-1); @@ -1946,7 +1944,7 @@ void tst_QDateTime::operator_eqeq_data() QTest::newRow("data2") << dateTime1a << dateTime1a << true << false; QTest::newRow("data3") << dateTime1 << dateTime2 << false << false; QTest::newRow("data4") << dateTime1 << dateTime1a << false << false; - QTest::newRow("data5") << dateTime2 << dateTime2a << false << false; + QTest::newRow("data5") << dateTime2 << dateTime2a << true << false; QTest::newRow("data6") << dateTime2 << dateTime3 << false << false; QTest::newRow("data7") << dateTime3 << dateTime3a << false << false; QTest::newRow("data8") << dateTime3 << dateTime3b << false << false; -- cgit v1.2.3 From aa3540b7be3dd0f5a96de1df5c4771d789127204 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Wed, 9 Oct 2019 11:28:54 +0200 Subject: QMacStyle - fix the background color for tool button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit when it's in 'ON' state ("inverted" color in 'Dark' appearance). Number are rather arbitrary and extracted with 'Digital Color Meter' app to make it look similar to the native panel (to be honest, this tool button on a toolbar not to be found in many native apps, they use different buttons anyway). Fixes: QTBUG-71526 Change-Id: Ie61e60b77f097f04550006612e4aab6f11bb954b Reviewed-by: Tor Arne Vestbø --- src/plugins/styles/mac/qmacstyle_mac.mm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 0a216e540d..63dc49fd18 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -328,6 +328,20 @@ static const int closeButtonSize = 14; static const qreal closeButtonCornerRadius = 2.0; #endif // QT_CONFIG(tabbar) +#ifndef QT_NO_ACCESSIBILITY // This ifdef to avoid "unused function" warning. +QBrush brushForToolButton(bool isOnKeyWindow) +{ + // When a toolbutton in a toolbar is in the 'ON' state, we draw a + // partially transparent background. The colors must be different + // for 'Aqua' and 'DarkAqua' appearances though. + if (isDarkMode()) + return isOnKeyWindow ? QColor(73, 73, 73, 100) : QColor(56, 56, 56, 100); + + return isOnKeyWindow ? QColor(0, 0, 0, 28) : QColor(0, 0, 0, 21); +} +#endif // QT_NO_ACCESSIBILITY + + static const int headerSectionArrowHeight = 6; static const int headerSectionSeparatorInset = 2; @@ -5603,8 +5617,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex if (view) isKey = [view.window isKeyWindow]; - QBrush brush(isKey ? QColor(0, 0, 0, 28) - : QColor(0, 0, 0, 21)); + QBrush brush(brushForToolButton(isKey)); QPainterPath path; path.addRoundedRect(QRectF(tb->rect.x(), tb->rect.y(), tb->rect.width(), tb->rect.height() + 4), 4, 4); p->setRenderHint(QPainter::Antialiasing); -- cgit v1.2.3 From e4e3be75014dcd34f480811c9d423b1d2123a395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 4 Oct 2019 15:54:03 +0200 Subject: macOS: Simplify reflection delegate handling in QCocoaApplicationDelegate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sending a message to a nil object returns nil, so there's no reason to check the delegate before calling respondsToSelector, and we can use the implicit _cmd argument to pass along the selector for the method we're in. For applicationShouldTerminate, if there's a reflection delegate but it doesn't answer to applicationShouldTerminate it makes no sense to skip our own logic. Change-Id: Iafcd883a5c8cec1b35d2f95238de55eff060d71f Reviewed-by: Morten Johan Sørvig Reviewed-by: Volker Hilsheimer --- .../platforms/cocoa/qcocoaapplicationdelegate.mm | 35 +++++++--------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index 2cf6672da9..da80c6a0e4 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -171,12 +171,8 @@ QT_USE_NAMESPACE // This function will only be called when NSApp is actually running. - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { - // The reflection delegate gets precedence - if (reflectionDelegate) { - if ([reflectionDelegate respondsToSelector:@selector(applicationShouldTerminate:)]) - return [reflectionDelegate applicationShouldTerminate:sender]; - return NSTerminateNow; - } + if ([reflectionDelegate respondsToSelector:_cmd]) + return [reflectionDelegate applicationShouldTerminate:sender]; if ([self canQuit]) { if (!startedQuit) { @@ -282,26 +278,22 @@ QT_USE_NAMESPACE QWindowSystemInterface::handleFileOpenEvent(qtFileName); } - if (reflectionDelegate && - [reflectionDelegate respondsToSelector:@selector(application:openFiles:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) [reflectionDelegate application:sender openFiles:filenames]; } - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { - // If we have a reflection delegate, that will get to call the shots. - if (reflectionDelegate - && [reflectionDelegate respondsToSelector: - @selector(applicationShouldTerminateAfterLastWindowClosed:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) return [reflectionDelegate applicationShouldTerminateAfterLastWindowClosed:sender]; + return NO; // Someday qApp->quitOnLastWindowClosed(); when QApp and NSApp work closer together. } - (void)applicationDidBecomeActive:(NSNotification *)notification { - if (reflectionDelegate - && [reflectionDelegate respondsToSelector:@selector(applicationDidBecomeActive:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) [reflectionDelegate applicationDidBecomeActive:notification]; QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationActive); @@ -309,8 +301,7 @@ QT_USE_NAMESPACE - (void)applicationDidResignActive:(NSNotification *)notification { - if (reflectionDelegate - && [reflectionDelegate respondsToSelector:@selector(applicationDidResignActive:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) [reflectionDelegate applicationDidResignActive:notification]; QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationInactive); @@ -318,10 +309,7 @@ QT_USE_NAMESPACE - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag { - Q_UNUSED(theApplication); - Q_UNUSED(flag); - if (reflectionDelegate - && [reflectionDelegate respondsToSelector:@selector(applicationShouldHandleReopen:hasVisibleWindows:)]) + if ([reflectionDelegate respondsToSelector:_cmd]) return [reflectionDelegate applicationShouldHandleReopen:theApplication hasVisibleWindows:flag]; /* @@ -354,16 +342,13 @@ QT_USE_NAMESPACE - (BOOL)respondsToSelector:(SEL)aSelector { - BOOL result = [super respondsToSelector:aSelector]; - if (!result && reflectionDelegate) - result = [reflectionDelegate respondsToSelector:aSelector]; - return result; + return [super respondsToSelector:aSelector] || [reflectionDelegate respondsToSelector:aSelector]; } - (void)forwardInvocation:(NSInvocation *)invocation { SEL invocationSelector = [invocation selector]; - if (reflectionDelegate && [reflectionDelegate respondsToSelector:invocationSelector]) + if ([reflectionDelegate respondsToSelector:invocationSelector]) [invocation invokeWithTarget:reflectionDelegate]; else [self doesNotRecognizeSelector:invocationSelector]; -- cgit v1.2.3 From 35713ef3fffeb7476a8a72490caeffbda81c4f09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 4 Oct 2019 15:14:56 +0200 Subject: macOS: Don't override event handler for kAEQuitApplication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The implementation of the default handler, [NSApp _handleAEQuit], does a lot more than just terminating the application, including sending NSWorkspaceWillPowerOffNotification if appropriate, and deals appropriately with state restoration. Change-Id: If725838fc0f40d09a0b8885eb3e7239499d8fea0 Fixes: QTBUG-18624 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index da80c6a0e4..2df85c791b 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -223,10 +223,6 @@ QT_USE_NAMESPACE application depends on. */ NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager]; - [eventManager setEventHandler:self - andSelector:@selector(appleEventQuit:withReplyEvent:) - forEventClass:kCoreEventClass - andEventID:kAEQuitApplication]; [eventManager setEventHandler:self andSelector:@selector(getUrl:withReplyEvent:) forEventClass:kInternetEventClass @@ -237,7 +233,6 @@ QT_USE_NAMESPACE - (void)removeAppleEventHandlers { NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager]; - [eventManager removeEventHandlerForEventClass:kCoreEventClass andEventID:kAEQuitApplication]; [eventManager removeEventHandlerForEventClass:kInternetEventClass andEventID:kAEGetURL]; } @@ -360,14 +355,6 @@ QT_USE_NAMESPACE NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; QWindowSystemInterface::handleFileOpenEvent(QUrl(QString::fromNSString(urlString))); } - -- (void)appleEventQuit:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent -{ - Q_UNUSED(event); - Q_UNUSED(replyEvent); - [NSApp terminate:self]; -} - @end @implementation QCocoaApplicationDelegate (Menus) -- cgit v1.2.3 From eaf4911db29a82b3d94826a8ff09afe075a2b636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 12 Sep 2019 13:29:25 +0200 Subject: macOS: Optionally flush sub-layers via sub-image copies of the backingstore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we're flushing the backingstore to sub-views with their own layers we don't want to pay the cost of uploading the whole backingstore to the GPU in the case where we're dealing with a discrete GPU. To work around this we make a copy of the appropriate part of the surfcace. This results in additional copies of the data, and will need further investigation to limit these. Task-number: QTBUG-77447 Change-Id: I318ae80e433dd7b0a55fd5a598b19f114d8bd28e Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoabackingstore.mm | 29 +++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index eb316c53a8..b17302a640 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm @@ -560,17 +560,26 @@ void QCALayerBackingStore::flush(QWindow *flushedWindow, const QRegion ®ion, flushedView.layer.contents = nil; } - qCInfo(lcQpaBackingStore) << "Flushing" << backBufferSurface - << "to" << flushedView.layer << "of" << flushedView; - - flushedView.layer.contents = backBufferSurface; + if (flushedView == backingStoreView) { + qCInfo(lcQpaBackingStore) << "Flushing" << backBufferSurface + << "to" << flushedView.layer << "of" << flushedView; + flushedView.layer.contents = backBufferSurface; + } else { + auto subviewRect = [flushedView convertRect:flushedView.bounds toView:backingStoreView]; + auto scale = flushedView.layer.contentsScale; + subviewRect = CGRectApplyAffineTransform(subviewRect, CGAffineTransformMakeScale(scale, scale)); + + // We make a copy of the image data up front, which means we don't + // need to mark the IOSurface as being in use. FIXME: Investigate + // if there's a cheaper way to get sub-image data to a layer. + m_buffers.back()->lock(QPlatformGraphicsBuffer::SWReadAccess); + QImage subImage = m_buffers.back()->asImage()->copy(QRectF::fromCGRect(subviewRect).toRect()); + m_buffers.back()->unlock(); - if (flushedView != backingStoreView) { - const CGSize backingStoreSize = backingStoreView.bounds.size; - flushedView.layer.contentsRect = CGRectApplyAffineTransform( - [flushedView convertRect:flushedView.bounds toView:backingStoreView], - // The contentsRect is in unit coordinate system - CGAffineTransformMakeScale(1.0 / backingStoreSize.width, 1.0 / backingStoreSize.height)); + qCInfo(lcQpaBackingStore) << "Flushing" << subImage + << "to" << flushedView.layer << "of subview" << flushedView; + QCFType cgImage = subImage.toCGImage(); + flushedView.layer.contents = (__bridge id)static_cast(cgImage); } // Since we may receive multiple flushes before a new frame is started, we do not -- cgit v1.2.3 From c54083ff933830a28f43551b9c3b132bfb11492d Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Wed, 9 Oct 2019 10:29:00 +0200 Subject: Fix QEasingCurve possible imprecision at endpoints Both the spline curves and (most of) the predefines curves are defined as having start value 0.0 and end value 1.0. The spline and In/OutBack functions would sometimes not produce that result precisely, so code could not reliably depend on expressions like (easedValue < 1.0) becoming false. Fix by explicitly handling endpoints. Fixes: QTBUG-76781 Fixes: QTBUG-72630 Change-Id: I21be43af469a76c090154bffef8406a9baf2d0b1 Reviewed-by: Thomas Hartmann --- src/corelib/tools/qeasingcurve.cpp | 12 ++++++++++++ tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/corelib/tools/qeasingcurve.cpp b/src/corelib/tools/qeasingcurve.cpp index 2ae63fe135..52c8d13fe3 100644 --- a/src/corelib/tools/qeasingcurve.cpp +++ b/src/corelib/tools/qeasingcurve.cpp @@ -583,6 +583,13 @@ struct BezierEase : public QEasingCurveFunction qWarning("QEasingCurve: Invalid bezier curve"); return x; } + + // The bezier computation is not always precise on the endpoints, so handle explicitly + if (!(x > 0)) + return 0; + if (!(x < 1)) + return 1; + SingleCubicBezier *singleCubicBezier = 0; getBezierSegment(singleCubicBezier, x); @@ -998,6 +1005,11 @@ struct BackEase : public QEasingCurveFunction qreal value(qreal t) override { + // The *Back() functions are not always precise on the endpoints, so handle explicitly + if (!(t > 0)) + return 0; + if (!(t < 1)) + return 1; qreal o = (_o < 0) ? qreal(1.70158) : _o; switch(_t) { case QEasingCurve::InBack: diff --git a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp index 3af6132695..2a9c1e1e41 100644 --- a/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp +++ b/tests/auto/corelib/tools/qeasingcurve/tst_qeasingcurve.cpp @@ -404,6 +404,11 @@ void tst_QEasingCurve::valueForProgress() const qreal error = qAbs(ex - curve.valueForProgress(at.at(i)/qreal(100))); QVERIFY(error <= errorBound); } + + if (type != QEasingCurve::SineCurve && type != QEasingCurve::CosineCurve) { + QVERIFY( !(curve.valueForProgress(0) > 0) ); + QVERIFY( !(curve.valueForProgress(1) < 1) ); + } #endif } @@ -632,6 +637,9 @@ void tst_QEasingCurve::bezierSpline() QCOMPARE(value, ex); QVERIFY(error <= errorBound); } + + QVERIFY( !(bezierEasingCurve.valueForProgress(0) > 0) ); + QVERIFY( !(bezierEasingCurve.valueForProgress(1) < 1) ); } void tst_QEasingCurve::tcbSpline_data() @@ -691,6 +699,9 @@ void tst_QEasingCurve::tcbSpline() QCOMPARE(value, ex); QVERIFY(error <= errorBound); } + + QVERIFY( !(tcbEasingCurve.valueForProgress(0) > 0) ); + QVERIFY( !(tcbEasingCurve.valueForProgress(1) < 1) ); } /*This is single precision code for a cubic root used inside the spline easing curve. -- cgit v1.2.3 From 23d73208524d3ab2166121d08594da88e6b4460b Mon Sep 17 00:00:00 2001 From: Rainer Keller Date: Thu, 10 Oct 2019 13:32:31 +0200 Subject: Protect global variable g_pointIdMap with mutexes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The evdev touch handler is thread based and calls QWindowSystemInterface::handleTouchEvent. The global variable in qwindowsysteminterface.cpp is used without being protected by mutexes which causes data loss and crashes when multiple touch screens are used. Fixes: QTBUG-63584 Change-Id: I8b5bb04cc517fab96ac428b2bd2bc128b2ca1a54 Reviewed-by: Johan Helsing Reviewed-by: Shawn Rutledge Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qwindowsysteminterface.cpp | 6 ++++++ src/gui/kernel/qwindowsysteminterface_p.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 03be72ca30..5f61853a6d 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -617,6 +617,7 @@ bool QWindowSystemInterface::isTouchDeviceRegistered(const QTouchDevice *device) static int g_nextPointId = 1; // map from device-independent point id (arbitrary) to "Qt point" ids +QMutex QWindowSystemInterfacePrivate::pointIdMapMutex; typedef QMap PointIdMap; Q_GLOBAL_STATIC(PointIdMap, g_pointIdMap) @@ -634,6 +635,8 @@ Q_GLOBAL_STATIC(PointIdMap, g_pointIdMap) */ static int acquireCombinedPointId(quint8 deviceId, int pointId) { + QMutexLocker locker(&QWindowSystemInterfacePrivate::pointIdMapMutex); + quint64 combinedId64 = (quint64(deviceId) << 32) + pointId; auto it = g_pointIdMap->constFind(combinedId64); int uid; @@ -693,6 +696,8 @@ QList } if (states == Qt::TouchPointReleased) { + QMutexLocker locker(&QWindowSystemInterfacePrivate::pointIdMapMutex); + // All points on deviceId have been released. // Remove all points associated with that device from g_pointIdMap. // (On other devices, some touchpoints might still be pressed. @@ -712,6 +717,7 @@ QList void QWindowSystemInterfacePrivate::clearPointIdMap() { + QMutexLocker locker(&QWindowSystemInterfacePrivate::pointIdMapMutex); g_pointIdMap->clear(); g_nextPointId = 1; } diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index 540170f733..55fd181ef0 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -528,6 +528,7 @@ public: static QWaitCondition eventsFlushed; static QMutex flushEventMutex; + static QMutex pointIdMapMutex; static QAtomicInt eventAccepted; static QList -- cgit v1.2.3 From 81a790969395feff73fa600908822765e97424e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 3 Oct 2019 15:04:16 +0200 Subject: Fusion Style: Use high-dpi pixmaps Pass the QWindow as context to QIcon::pixmap(), which enables it to return high-dpi pixmaps when needed. Fixes: QTBUG-74100 Change-Id: I4556f0a98df8b6ba65376778379a03eb8c470d00 Reviewed-by: Friedemann Kleint --- src/widgets/styles/qfusionstyle.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index ba2b6b0ed9..b58dc1660a 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -88,6 +88,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -364,6 +365,11 @@ static void qt_fusion_draw_mdibutton(QPainter *painter, const QStyleOptionTitleB painter->drawPoint(tmp.right() , tmp.bottom() - 1); } +static QWindow *qt_getWindow(const QWidget *widget) +{ + return widget ? QWidgetPrivate::get(widget)->windowHandle(QWidgetPrivate::WindowHandleMode::Closest) : nullptr; +} + /* \internal */ @@ -995,7 +1001,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem, d->tabBarcloseButtonIcon = proxy()->standardIcon(SP_DialogCloseButton, option, widget); if ((option->state & State_Enabled) && (option->state & State_MouseOver)) proxy()->drawPrimitive(PE_PanelButtonCommand, option, painter, widget); - QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(QSize(16, 16), QIcon::Normal, QIcon::On); + QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(qt_getWindow(widget), QSize(16, 16), QIcon::Normal, QIcon::On); proxy()->drawItemPixmap(painter, option->rect, Qt::AlignCenter, pixmap); } break; @@ -1035,7 +1041,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio if (!cb->currentIcon.isNull()) { QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal : QIcon::Disabled; - QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode); + QPixmap pixmap = cb->currentIcon.pixmap(qt_getWindow(widget), cb->iconSize, mode); QRect iconRect(editRect); iconRect.setWidth(cb->iconSize.width() + 4); iconRect = alignedRect(cb->direction, @@ -1647,9 +1653,9 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio iconSize = combo->iconSize(); #endif if (checked) - pixmap = menuItem->icon.pixmap(iconSize, mode, QIcon::On); + pixmap = menuItem->icon.pixmap(qt_getWindow(widget), iconSize, mode, QIcon::On); else - pixmap = menuItem->icon.pixmap(iconSize, mode); + pixmap = menuItem->icon.pixmap(qt_getWindow(widget), iconSize, mode); const int pixw = pixmap.width() / pixmap.devicePixelRatio(); const int pixh = pixmap.height() / pixmap.devicePixelRatio(); @@ -1783,7 +1789,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio if (button->state & State_On) state = QIcon::On; - QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state); + QPixmap pixmap = button->icon.pixmap(qt_getWindow(widget), button->iconSize, mode, state); int w = pixmap.width() / pixmap.devicePixelRatio(); int h = pixmap.height() / pixmap.devicePixelRatio(); -- cgit v1.2.3 From 1748dc3e2d2367f9f01666212a22e6b1dde5dc89 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 7 Oct 2019 16:09:37 +0200 Subject: QGroupBox: always disable children in a checkable, unchecked groupbox The childEvent handler sets the enabled property of children as they are added to the groupbox, but applications might later enable children and check/uncheck the groupbox's checkbox in undefined order. In that case, we would end up with enabled children inside a conceptually disabled groupbox (the groupbox's checkbox represents the logical "disabled" state), which breaks documented QWidget::enabled rules. To make sure that all children are disabled as per the state of the groupbox, we need to run that logic once the UI has been set up, and before it becomes visible. This is what polishing is for, so listen for that event in addition and handle it the same way as adding (which duplicates things, but keeps existing code that might depend on things being updated as they are added working). Adds the case to the existing enabledChildPropagation test case. [ChangeLog][QWidget][QGroupBox] Always disable children of a checkable, unchecked group box before showing. Change-Id: I978bd27b6f1a3f54ec745faeea529a98d0d93619 Fixes: QTBUG-25938 Reviewed-by: Shawn Rutledge --- src/widgets/widgets/qgroupbox.cpp | 8 ++++++-- tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/widgets/widgets/qgroupbox.cpp b/src/widgets/widgets/qgroupbox.cpp index 69eac1ebf7..eec794562a 100644 --- a/src/widgets/widgets/qgroupbox.cpp +++ b/src/widgets/widgets/qgroupbox.cpp @@ -389,9 +389,13 @@ bool QGroupBox::event(QEvent *e) void QGroupBox::childEvent(QChildEvent *c) { Q_D(QGroupBox); - if (c->type() != QEvent::ChildAdded || !c->child()->isWidgetType()) + /* + Children might have been enabled after being added to the group box, in which case + the childEvent handler ran too early, and we need to disabled children again. + */ + if (!(c->added() || c->polished()) || !c->child()->isWidgetType()) return; - QWidget *w = (QWidget*)c->child(); + QWidget *w = static_cast(c->child()); if (w->isWindow()) return; if (d->checkable) { diff --git a/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp b/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp index 420ef56106..1b477fbbd0 100644 --- a/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp +++ b/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp @@ -295,6 +295,12 @@ void tst_QGroupBox::enabledChildPropagation() QVERIFY(!childWidget->isEnabled()); dialog = new QDialog(&testWidget); QVERIFY(dialog->isEnabled()); + + // children that are enabled after adding should still be disabled before + // they are shown + childWidget->setEnabled(true); + testWidget.show(); + QVERIFY(!childWidget->isEnabled()); } void tst_QGroupBox::sizeHint() -- cgit v1.2.3 From 6abbecf9422af043d51cbb8b3d8c2c188ee40fd3 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Thu, 10 Oct 2019 12:45:25 +0200 Subject: evdevtouch: Fix touch device count not being updated When this was refactored in 3bc10fb9bb9 to use unique pointers, a move was added before the connection, so it would essentially always try to connect a nullptr. Change-Id: Iab7fce88bc73afd78e6b63ffaef7358f3f4ce7e3 Reviewed-by: Rainer Keller --- src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp index b280f27fac..bf2df93d11 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp +++ b/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp @@ -98,8 +98,8 @@ void QEvdevTouchManager::addDevice(const QString &deviceNode) qCDebug(qLcEvdevTouch, "evdevtouch: Adding device at %ls", qUtf16Printable(deviceNode)); auto handler = qt_make_unique(deviceNode, m_spec); if (handler) { - m_activeDevices.add(deviceNode, std::move(handler)); connect(handler.get(), &QEvdevTouchScreenHandlerThread::touchDeviceRegistered, this, &QEvdevTouchManager::updateInputDeviceCount); + m_activeDevices.add(deviceNode, std::move(handler)); } else { qWarning("evdevtouch: Failed to open touch device %ls", qUtf16Printable(deviceNode)); } -- cgit v1.2.3 From b43f5ed2da868eab17881872b165ae048d8a1d88 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 6 Oct 2019 18:53:29 +0200 Subject: QMYSQL: remove support for MySql 4.x MySql 5.0 was released 2005 so it's time to remove support for MySql 4.x 14 years later. [ChangeLog][QtSql][QMYSQL] Removed support for MySql < 5.0 since 5.0 was released 14 years ago. Change-Id: I45005accdffefbd9338ac0e710512a4c7ea8e09e Reviewed-by: Andy Shaw --- src/plugins/sqldrivers/mysql/qsql_mysql.cpp | 156 ++++----------------- .../sql/kernel/qsqldatabase/tst_qsqldatabase.cpp | 12 -- tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 21 --- tests/benchmarks/sql/kernel/qsqlquery/main.cpp | 6 - 4 files changed, 26 insertions(+), 169 deletions(-) diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp index febbe58506..0e195cfdb4 100644 --- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp +++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp @@ -65,16 +65,7 @@ Q_DECLARE_METATYPE(MYSQL_RES*) Q_DECLARE_METATYPE(MYSQL*) - -#if MYSQL_VERSION_ID >= 40108 Q_DECLARE_METATYPE(MYSQL_STMT*) -#endif - -#if MYSQL_VERSION_ID >= 40100 -# define Q_CLIENT_MULTI_STATEMENTS CLIENT_MULTI_STATEMENTS -#else -# define Q_CLIENT_MULTI_STATEMENTS 0 -#endif // MySQL above version 8 removed my_bool typedef while MariaDB kept it, // by redefining it we can regain source compatibility. @@ -199,10 +190,8 @@ protected: bool nextResult() override; void detachFromResultSet() override; -#if MYSQL_VERSION_ID >= 40108 bool prepare(const QString &stmt) override; bool exec() override; -#endif }; class QMYSQLResultPrivate: public QSqlResultPrivate @@ -217,9 +206,7 @@ public: result(0), rowsAffected(0), hasBlobs(false) -#if MYSQL_VERSION_ID >= 40108 , stmt(0), meta(0), inBinds(0), outBinds(0) -#endif , preparedQuery(false) { } @@ -247,13 +234,11 @@ public: QVector fields; -#if MYSQL_VERSION_ID >= 40108 MYSQL_STMT* stmt; MYSQL_RES* meta; MYSQL_BIND *inBinds; MYSQL_BIND *outBinds; -#endif bool preparedQuery; }; @@ -261,11 +246,9 @@ public: #if QT_CONFIG(textcodec) static QTextCodec* codec(MYSQL* mysql) { -#if MYSQL_VERSION_ID >= 32321 QTextCodec* heuristicCodec = QTextCodec::codecForName(mysql_character_set_name(mysql)); if (heuristicCodec) return heuristicCodec; -#endif return QTextCodec::codecForLocale(); } #endif // textcodec @@ -350,8 +333,6 @@ static QSqlField qToField(MYSQL_FIELD *field, QTextCodec *tc) return f; } -#if MYSQL_VERSION_ID >= 40108 - static QSqlError qMakeStmtError(const QString& err, QSqlError::ErrorType type, MYSQL_STMT* stmt) { @@ -445,7 +426,6 @@ bool QMYSQLResultPrivate::bindInValues() } return true; } -#endif QMYSQLResult::QMYSQLResult(const QMYSQLDriver* db) : QSqlResult(*new QMYSQLResultPrivate(this, db)) @@ -460,11 +440,9 @@ QMYSQLResult::~QMYSQLResult() QVariant QMYSQLResult::handle() const { Q_D(const QMYSQLResult); -#if MYSQL_VERSION_ID >= 40108 if(d->preparedQuery) return d->meta ? QVariant::fromValue(d->meta) : QVariant::fromValue(d->stmt); else -#endif return QVariant::fromValue(d->result); } @@ -476,15 +454,12 @@ void QMYSQLResult::cleanup() // must iterate trough leftover result sets from multi-selects or stored procedures // if this isn't done subsequent queries will fail with "Commands out of sync" -#if MYSQL_VERSION_ID >= 40100 while (driver() && d->drv_d_func()->mysql && mysql_next_result(d->drv_d_func()->mysql) == 0) { MYSQL_RES *res = mysql_store_result(d->drv_d_func()->mysql); if (res) mysql_free_result(res); } -#endif -#if MYSQL_VERSION_ID >= 40108 if (d->stmt) { if (mysql_stmt_close(d->stmt)) qWarning("QMYSQLResult::cleanup: unable to free statement handle"); @@ -509,7 +484,6 @@ void QMYSQLResult::cleanup() delete[] d->inBinds; d->inBinds = 0; } -#endif d->hasBlobs = false; d->fields.clear(); @@ -536,7 +510,6 @@ bool QMYSQLResult::fetch(int i) if (at() == i) return true; if (d->preparedQuery) { -#if MYSQL_VERSION_ID >= 40108 mysql_stmt_data_seek(d->stmt, i); int nRC = mysql_stmt_fetch(d->stmt); @@ -550,9 +523,6 @@ bool QMYSQLResult::fetch(int i) "Unable to fetch data"), QSqlError::StatementError, d->stmt)); return false; } -#else - return false; -#endif } else { mysql_data_seek(d->result, i); d->row = mysql_fetch_row(d->result); @@ -570,7 +540,6 @@ bool QMYSQLResult::fetchNext() if (!driver()) return false; if (d->preparedQuery) { -#if MYSQL_VERSION_ID >= 40108 int nRC = mysql_stmt_fetch(d->stmt); if (nRC) { #ifdef MYSQL_DATA_TRUNCATED @@ -582,9 +551,6 @@ bool QMYSQLResult::fetchNext() "Unable to fetch data"), QSqlError::StatementError, d->stmt)); return false; } -#else - return false; -#endif } else { d->row = mysql_fetch_row(d->result); if (!d->row) @@ -607,11 +573,7 @@ bool QMYSQLResult::fetchLast() my_ulonglong numRows; if (d->preparedQuery) { -#if MYSQL_VERSION_ID >= 40108 numRows = mysql_stmt_num_rows(d->stmt); -#else - numRows = 0; -#endif } else { numRows = mysql_num_rows(d->result); } @@ -788,11 +750,7 @@ int QMYSQLResult::size() Q_D(const QMYSQLResult); if (driver() && isSelect()) if (d->preparedQuery) -#if MYSQL_VERSION_ID >= 40108 return mysql_stmt_num_rows(d->stmt); -#else - return -1; -#endif else return int(mysql_num_rows(d->result)); else @@ -821,11 +779,9 @@ QVariant QMYSQLResult::lastInsertId() const return QVariant(); if (d->preparedQuery) { -#if MYSQL_VERSION_ID >= 40108 quint64 id = mysql_stmt_insert_id(d->stmt); if (id) return QVariant(id); -#endif } else { quint64 id = mysql_insert_id(d->drv_d_func()->mysql); if (id) @@ -842,11 +798,7 @@ QSqlRecord QMYSQLResult::record() const if (!isActive() || !isSelect() || !driver()) return info; -#if MYSQL_VERSION_ID >= 40108 res = d->preparedQuery ? d->meta : d->result; -#else - res = d->result; -#endif if (!mysql_errno(d->drv_d_func()->mysql)) { mysql_field_seek(res, 0); @@ -865,7 +817,7 @@ bool QMYSQLResult::nextResult() Q_D(QMYSQLResult); if (!driver()) return false; -#if MYSQL_VERSION_ID >= 40100 + setAt(-1); setActive(false); @@ -908,9 +860,6 @@ bool QMYSQLResult::nextResult() setActive(true); return true; -#else - return false; -#endif } void QMYSQLResult::virtual_hook(int id, void *data) @@ -918,9 +867,6 @@ void QMYSQLResult::virtual_hook(int id, void *data) QSqlResult::virtual_hook(id, data); } - -#if MYSQL_VERSION_ID >= 40108 - static MYSQL_TIME *toMySqlDate(QDate date, QTime time, QVariant::Type type) { Q_ASSERT(type == QVariant::Time || type == QVariant::Date @@ -949,7 +895,7 @@ bool QMYSQLResult::prepare(const QString& query) Q_D(QMYSQLResult); if (!driver()) return false; -#if MYSQL_VERSION_ID >= 40108 + cleanup(); if (!d->drv_d_func()->preparedQuerysEnabled) return QSqlResult::prepare(query); @@ -983,9 +929,6 @@ bool QMYSQLResult::prepare(const QString& query) setSelect(d->bindInValues()); d->preparedQuery = true; return true; -#else - return false; -#endif } bool QMYSQLResult::exec() @@ -1155,7 +1098,7 @@ bool QMYSQLResult::exec() setActive(true); return true; } -#endif + ///////////////////////////////////////////////////////// static int qMySqlConnectionCount = 0; @@ -1164,18 +1107,16 @@ static bool qMySqlInitHandledByUser = false; static void qLibraryInit() { #ifndef Q_NO_MYSQL_EMBEDDED -# if MYSQL_VERSION_ID >= 40000 if (qMySqlInitHandledByUser || qMySqlConnectionCount > 1) return; -# if (MYSQL_VERSION_ID >= 40110 && MYSQL_VERSION_ID < 50000) || MYSQL_VERSION_ID >= 50003 +# if MYSQL_VERSION_ID >= 50003 if (mysql_library_init(0, 0, 0)) { # else if (mysql_server_init(0, 0, 0)) { # endif qWarning("QMYSQLDriver::qServerInit: unable to start server."); } -# endif // MYSQL_VERSION_ID #endif // Q_NO_MYSQL_EMBEDDED #if defined(MARIADB_BASE_VERSION) || defined(MARIADB_VERSION_ID) @@ -1187,12 +1128,10 @@ static void qLibraryEnd() { #if !defined(MARIADB_BASE_VERSION) && !defined(MARIADB_VERSION_ID) # if !defined(Q_NO_MYSQL_EMBEDDED) -# if MYSQL_VERSION_ID > 40000 -# if (MYSQL_VERSION_ID >= 40110 && MYSQL_VERSION_ID < 50000) || MYSQL_VERSION_ID >= 50003 - mysql_library_end(); -# else - mysql_server_end(); -# endif +# if MYSQL_VERSION_ID >= 50003 + mysql_library_end(); +# else + mysql_server_end(); # endif # endif #endif @@ -1271,17 +1210,9 @@ bool QMYSQLDriver::hasFeature(DriverFeature f) const return true; case PreparedQueries: case PositionalPlaceholders: -#if MYSQL_VERSION_ID >= 40108 return d->preparedQuerysEnabled; -#else - return false; -#endif case MultipleResultSets: -#if MYSQL_VERSION_ID >= 40100 return true; -#else - return false; -#endif } return false; } @@ -1322,7 +1253,7 @@ bool QMYSQLDriver::open(const QString& db, we have to enable CLIEN_MULTI_STATEMENTS here, otherwise _any_ stored procedure call will fail. */ - unsigned int optionFlags = Q_CLIENT_MULTI_STATEMENTS; + unsigned int optionFlags = CLIENT_MULTI_STATEMENTS; const QStringList opts(connOpts.split(QLatin1Char(';'), QString::SkipEmptyParts)); QString unixSocket; QString sslCert; @@ -1330,12 +1261,10 @@ bool QMYSQLDriver::open(const QString& db, QString sslKey; QString sslCAPath; QString sslCipher; -#if MYSQL_VERSION_ID >= 50000 my_bool reconnect=false; uint connectTimeout = 0; uint readTimeout = 0; uint writeTimeout = 0; -#endif // extract the real options from the string for (int i = 0; i < opts.count(); ++i) { @@ -1346,18 +1275,15 @@ bool QMYSQLDriver::open(const QString& db, QString opt = tmp.left(idx).simplified(); if (opt == QLatin1String("UNIX_SOCKET")) unixSocket = val; -#if MYSQL_VERSION_ID >= 50000 else if (opt == QLatin1String("MYSQL_OPT_RECONNECT")) { if (val == QLatin1String("TRUE") || val == QLatin1String("1") || val.isEmpty()) reconnect = true; - } else if (opt == QLatin1String("MYSQL_OPT_CONNECT_TIMEOUT")) { + } else if (opt == QLatin1String("MYSQL_OPT_CONNECT_TIMEOUT")) connectTimeout = val.toInt(); - } else if (opt == QLatin1String("MYSQL_OPT_READ_TIMEOUT")) { + else if (opt == QLatin1String("MYSQL_OPT_READ_TIMEOUT")) readTimeout = val.toInt(); - } else if (opt == QLatin1String("MYSQL_OPT_WRITE_TIMEOUT")) { + else if (opt == QLatin1String("MYSQL_OPT_WRITE_TIMEOUT")) writeTimeout = val.toInt(); - } -#endif else if (opt == QLatin1String("SSL_KEY")) sslKey = val; else if (opt == QLatin1String("SSL_CERT")) @@ -1442,7 +1368,7 @@ bool QMYSQLDriver::open(const QString& db, return false; } -#if (MYSQL_VERSION_ID >= 40113 && MYSQL_VERSION_ID < 50000) || MYSQL_VERSION_ID >= 50007 +#if MYSQL_VERSION_ID >= 50007 if (mysql_get_client_version() >= 50503 && mysql_get_server_version(d->mysql) >= 50503) { // force the communication to be utf8mb4 (only utf8mb4 supports 4-byte characters) mysql_set_character_set(d->mysql, "utf8mb4"); @@ -1457,20 +1383,15 @@ bool QMYSQLDriver::open(const QString& db, d->tc = codec(d->mysql); #endif } -#endif +#endif // MYSQL_VERSION_ID >= 50007 -#if MYSQL_VERSION_ID >= 40108 d->preparedQuerysEnabled = mysql_get_client_version() >= 40108 && mysql_get_server_version(d->mysql) >= 40100; -#else - d->preparedQuerysEnabled = false; -#endif #if QT_CONFIG(thread) mysql_thread_init(); #endif - setOpen(true); setOpenError(false); return true; @@ -1499,46 +1420,21 @@ QStringList QMYSQLDriver::tables(QSql::TableType type) const { Q_D(const QMYSQLDriver); QStringList tl; -#if MYSQL_VERSION_ID >= 40100 - if( mysql_get_server_version(d->mysql) < 50000) - { -#endif - if (!isOpen()) - return tl; - if (!(type & QSql::Tables)) - return tl; - - MYSQL_RES* tableRes = mysql_list_tables(d->mysql, NULL); - MYSQL_ROW row; - int i = 0; - while (tableRes) { - mysql_data_seek(tableRes, i); - row = mysql_fetch_row(tableRes); - if (!row) - break; - tl.append(toUnicode(d->tc, row[0])); - i++; - } - mysql_free_result(tableRes); -#if MYSQL_VERSION_ID >= 40100 - } else { - QSqlQuery q(createResult()); - if(type & QSql::Tables) { - QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'BASE TABLE'"); - q.exec(sql); + QSqlQuery q(createResult()); + if (type & QSql::Tables) { + QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'BASE TABLE'"); + q.exec(sql); - while(q.next()) - tl.append(q.value(0).toString()); - } - if(type & QSql::Views) { - QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'VIEW'"); - q.exec(sql); + while (q.next()) + tl.append(q.value(0).toString()); + } + if (type & QSql::Views) { + QString sql = QLatin1String("select table_name from information_schema.tables where table_schema = '") + QLatin1String(d->mysql->db) + QLatin1String("' and table_type = 'VIEW'"); + q.exec(sql); - while(q.next()) - tl.append(q.value(0).toString()); - } + while (q.next()) + tl.append(q.value(0).toString()); } -#endif return tl; } diff --git a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp index 6a1f46582e..f726139e08 100644 --- a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp +++ b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp @@ -520,10 +520,6 @@ void tst_QSqlDatabase::tables() bool tempTables = false; QSqlQuery q(db); - if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) - QSKIP( "Test requires MySQL >= 5.0"); - - if (!q.exec("CREATE VIEW " + qtest_view + " as select * from " + qtest)) { qDebug("DBMS '%s' cannot handle VIEWs: %s", qPrintable(tst_Databases::dbToString(db)), @@ -1891,11 +1887,6 @@ void tst_QSqlDatabase::mysql_multiselect() const QString qtest(qTableName("qtest", __FILE__, db)); QSqlQuery q(db); - QString version=tst_Databases::getMySqlVersion( db ); - double ver=version.section(QChar::fromLatin1('.'),0,1).toDouble(); - if (ver < 4.1) - QSKIP("Test requires MySQL >= 4.1"); - QVERIFY_SQL(q, exec("SELECT * FROM " + qtest + "; SELECT * FROM " + qtest)); QVERIFY_SQL(q, next()); QVERIFY_SQL(q, exec("SELECT * FROM " + qtest + "; SELECT * FROM " + qtest)); @@ -2280,9 +2271,6 @@ void tst_QSqlDatabase::mysql_savepointtest() QFETCH(QString, dbName); QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); - if (tst_Databases::getMySqlVersion(db).section(QChar('.'), 0, 1).toDouble() < 4.1) - QSKIP( "Test requires MySQL >= 4.1"); - QSqlQuery q(db); QVERIFY_SQL(q, exec("begin")); QVERIFY_SQL(q, exec("insert into " + qTableName("qtest", __FILE__, db) + " VALUES (54, 'foo', 'foo', 54.54)")); diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 784d0a70d7..ef58d612c9 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -480,10 +480,6 @@ void tst_QSqlQuery::char1SelectUnicode() if ( db.driver()->hasFeature( QSqlDriver::Unicode ) ) { QString uniStr( QChar(0x0915) ); // DEVANAGARI LETTER KA QSqlQuery q( db ); - - if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) - QSKIP( "Test requires MySQL >= 5.0"); - QString createQuery; const QString char1SelectUnicode(qTableName("char1SU", __FILE__, db)); @@ -563,9 +559,6 @@ void tst_QSqlQuery::mysql_outValues() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - if (tst_Databases::getMySqlVersion(db).section(QChar('.'), 0, 0 ).toInt() < 5) - QSKIP( "Test requires MySQL >= 5.0"); - const QString hello(qTableName("hello", __FILE__, db)), qtestproc(qTableName("qtestproc", __FILE__, db)); QSqlQuery q( db ); @@ -2093,10 +2086,6 @@ void tst_QSqlQuery::prepare_bind_exec() bool useUnicode = db.driver()->hasFeature( QSqlDriver::Unicode ); QSqlQuery q( db ); - - if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) - useUnicode = false; - QString createQuery; QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db); if (dbType == QSqlDriver::PostgreSQL) @@ -3068,10 +3057,6 @@ void tst_QSqlQuery::nextResult() QSKIP("DBMS does not support multiple result sets"); QSqlQuery q( db ); - - if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) - QSKIP( "Test requires MySQL >= 5.0"); - const QString tableName(qTableName("more_results", __FILE__, db)); QVERIFY_SQL( q, exec( "CREATE TABLE " + tableName + " (id integer, text varchar(20), num numeric(6, 3), empty varchar(10));" ) ); @@ -3836,9 +3821,6 @@ void tst_QSqlQuery::QTBUG_6852() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - if ( tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) - QSKIP( "Test requires MySQL >= 5.0"); - QSqlQuery q(db); const QString tableName(qTableName("bug6852", __FILE__, db)), procName(qTableName("bug6852_proc", __FILE__, db)); @@ -3870,9 +3852,6 @@ void tst_QSqlQuery::QTBUG_5765() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - if ( tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 1 ).toFloat()<4.1 ) - QSKIP( "Test requires MySQL >= 4.1"); - QSqlQuery q(db); const QString tableName(qTableName("bug5765", __FILE__, db)); diff --git a/tests/benchmarks/sql/kernel/qsqlquery/main.cpp b/tests/benchmarks/sql/kernel/qsqlquery/main.cpp index c5ca6ed669..33875f1837 100644 --- a/tests/benchmarks/sql/kernel/qsqlquery/main.cpp +++ b/tests/benchmarks/sql/kernel/qsqlquery/main.cpp @@ -238,9 +238,6 @@ void tst_QSqlQuery::benchmark() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - if ( tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) - QSKIP( "Test requires MySQL >= 5.0"); - QSqlQuery q(db); const QString tableName(qTableName("benchmark", __FILE__, db)); @@ -266,9 +263,6 @@ void tst_QSqlQuery::benchmarkSelectPrepared() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); - if (tst_Databases::getMySqlVersion(db).section(QChar('.'), 0, 0).toInt() < 5) - QSKIP("Test requires MySQL >= 5.0"); - QSqlQuery q(db); const QString tableName(qTableName("benchmark", __FILE__, db)); -- cgit v1.2.3 From a90899df4330afccd8299fa81754f369e6d12344 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Tue, 8 Oct 2019 15:24:53 +0200 Subject: Default to #!/bin/bash in wrapper scripts on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This gives the user the opportunity to employ BASH_ENV to circumvent macOS System Integrity Protection and set variables like DYLD_FRAMEWORK_PATH. Fixes: QTBUG-57204 Change-Id: Icd99d903a3be76fabd509e204ea61a254a96609c Reviewed-by: Eike Ziller Reviewed-by: Andy Shaw Reviewed-by: Tor Arne Vestbø --- mkspecs/features/qt_functions.prf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mkspecs/features/qt_functions.prf b/mkspecs/features/qt_functions.prf index ee6a4b352a..661b7dd961 100644 --- a/mkspecs/features/qt_functions.prf +++ b/mkspecs/features/qt_functions.prf @@ -159,8 +159,12 @@ defineTest(qtAddToolEnv) { !isEmpty(cmd): cmd = "$$cmd " equals(ds, /) { batch_name = $${batch_name}.sh + equals(QMAKE_HOST.os, Darwin):exists(/bin/bash): \ + shell = /bin/bash + else: \ + shell = /bin/sh batch_cont = \ - "$$LITERAL_HASH!/bin/sh" \ + "$$LITERAL_HASH!$$shell" \ $$batch_sets \ "exec $$cmd\"$@\"" # It would be nicer to use the '.' command (without 'exec' above), -- cgit v1.2.3 From e55a79b022e542a482177c2f34140c23b100b708 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 4 Oct 2019 11:06:06 +0200 Subject: PNG handler: stop using volatile I can only guess: the compression quality was declared volatile to make it survive across a setjmp/longjmp. However, executing a longjmp makes the code never touch the quality variable again, so volatile isn't needed. Change-Id: Iba1559d66200b900fbad55aa0ee3011b2407eead Reviewed-by: Allan Sandfeld Jensen --- src/gui/image/qpnghandler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index 4ab45337b0..d6caf6773a 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -174,7 +174,7 @@ public: void setGamma(float); bool writeImage(const QImage& img, int x, int y); - bool writeImage(const QImage& img, volatile int compression_in, const QString &description, int x, int y); + bool writeImage(const QImage& img, int compression_in, const QString &description, int x, int y); bool writeImage(const QImage& img) { return writeImage(img, 0, 0); } bool writeImage(const QImage& img, int compression, const QString &description) @@ -900,7 +900,7 @@ bool QPNGImageWriter::writeImage(const QImage& image, int off_x, int off_y) return writeImage(image, -1, QString(), off_x, off_y); } -bool QPNGImageWriter::writeImage(const QImage& image, volatile int compression_in, const QString &description, +bool QPNGImageWriter::writeImage(const QImage& image, int compression_in, const QString &description, int off_x_in, int off_y_in) { QPoint offset = image.offset(); -- cgit v1.2.3