From eb18be36ad013c80fe982a77b3eadb9791f96298 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 4 Dec 2019 10:55:42 +0100 Subject: Mark QApplication::globalStrut as deprecated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This property is obsolete with today's user interface reality, and was never consistently implemented in all styles and widgets. Deprecating it for Qt 5.15 as preparating for removing the code for Qt 6. [ChangeLog][QtWidgets][QApplication] The globalStrut property has been deprecated and will be removed from Qt 6 Change-Id: Iaea88e563144481a395de6cf0745a512e386407d Reviewed-by: Tor Arne Vestbø Reviewed-by: Shawn Rutledge Reviewed-by: Simon Hausmann --- src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp | 2 +- src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp | 2 +- src/widgets/kernel/qapplication.cpp | 1 + src/widgets/kernel/qapplication.h | 4 ++++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp index f1f51c0582..138d0dfa1b 100644 --- a/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp +++ b/src/gui/doc/snippets/code/src_gui_kernel_qapplication.cpp @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) //! [3] QSize MyWidget::sizeHint() const { - return QSize(80, 25).expandedTo(QApplication::globalStrut()); + return QSize(80, 25); } //! [3] diff --git a/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp b/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp index 5e1f0883e7..a7bce6d378 100644 --- a/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp +++ b/src/widgets/doc/snippets/code/src_gui_kernel_qapplication.cpp @@ -93,7 +93,7 @@ int main(int argc, char *argv[]) //! [3] QSize MyWidget::sizeHint() const { - return QSize(80, 25).expandedTo(QApplication::globalStrut()); + return QSize(80, 25); } //! [3] diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index eea97b2c0b..842c0ea9e6 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -1224,6 +1224,7 @@ void QApplication::setColorSpec(int spec) \property QApplication::globalStrut \brief the minimum size that any GUI element that the user can interact with should have + \deprecated For example, no button should be resized to be smaller than the global strut size. The strut size should be considered when reimplementing GUI diff --git a/src/widgets/kernel/qapplication.h b/src/widgets/kernel/qapplication.h index 27e743a28d..6de72899f1 100644 --- a/src/widgets/kernel/qapplication.h +++ b/src/widgets/kernel/qapplication.h @@ -79,7 +79,9 @@ class Q_WIDGETS_EXPORT QApplication : public QGuiApplication #if QT_CONFIG(wheelevent) Q_PROPERTY(int wheelScrollLines READ wheelScrollLines WRITE setWheelScrollLines) #endif +#if QT_DEPRECATED_SINCE(5, 15) Q_PROPERTY(QSize globalStrut READ globalStrut WRITE setGlobalStrut) +#endif Q_PROPERTY(int startDragTime READ startDragTime WRITE setStartDragTime) Q_PROPERTY(int startDragDistance READ startDragDistance WRITE setStartDragDistance) #ifndef QT_NO_STYLE_STYLESHEET @@ -158,8 +160,10 @@ public: static void setWheelScrollLines(int); static int wheelScrollLines(); #endif +#if QT_DEPRECATED_SINCE(5, 15) static void setGlobalStrut(const QSize &); static QSize globalStrut(); +#endif static void setStartDragTime(int ms); static int startDragTime(); -- cgit v1.2.3 From 477dc115670d7c122d6590b9be10e076ebff8d08 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 16 Jan 2020 20:26:03 +0100 Subject: QTabBar: fix QStyleOptionTab::position During 556712f511a02ff8101e648d2e6f0090231d4f3d a small regression was introduced which set a wrong value for QStyleOptionTab::position. Fixes: QTBUG-81393 Change-Id: Ie8c66186b1b79c97bf77c7b139e08840233b7b66 Reviewed-by: Timur Pocheptsov --- src/widgets/widgets/qtabbar.cpp | 2 +- tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp | 36 ++++++++++++++++------ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index a7b115a1bc..df480629da 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -208,7 +208,7 @@ void QTabBarPrivate::initBasicStyleOption(QStyleOptionTab *option, int tabIndex) option->selectedPosition = QStyleOptionTab::NotAdjacent; const bool paintBeginning = (tabIndex == firstVisible) || (dragInProgress && tabIndex == pressedIndex + 1); - const bool paintEnd = (tabIndex == lastVisible - 1) || (dragInProgress && tabIndex == pressedIndex - 1); + const bool paintEnd = (tabIndex == lastVisible) || (dragInProgress && tabIndex == pressedIndex - 1); if (paintBeginning) { if (paintEnd) option->position = QStyleOptionTab::OnlyOneTab; diff --git a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp index bc1496d0f6..e27600bad2 100644 --- a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp +++ b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp @@ -33,6 +33,7 @@ #include #include +#include class tst_QTabBar : public QObject { @@ -279,30 +280,53 @@ void tst_QTabBar::hideTab() QTEST(tabbar.currentIndex(), "finalIndex"); } +class TabBar : public QTabBar +{ +public: + using QTabBar::QTabBar; + using QTabBar::initStyleOption; + using QTabBar::moveTab; +}; + void tst_QTabBar::hideAllTabs() { - QTabBar tabbar; + TabBar tabbar; + auto checkPositions = [&tabbar](const QVector &positions) + { + QStyleOptionTab option; + int iPos = 0; + for (int i = 0; i < tabbar.count(); ++i) { + if (!tabbar.isTabVisible(i)) + continue; + tabbar.initStyleOption(&option, i); + QCOMPARE(option.position, positions.at(iPos++)); + } + }; tabbar.addTab("foo"); tabbar.addTab("bar"); tabbar.addTab("baz"); tabbar.setCurrentIndex(0); + checkPositions({QStyleOptionTab::Beginning, QStyleOptionTab::Middle, QStyleOptionTab::End}); // Check we don't crash trying to hide an unexistant tab QSize prevSizeHint = tabbar.sizeHint(); tabbar.setTabVisible(3, false); + checkPositions({QStyleOptionTab::Beginning, QStyleOptionTab::Middle, QStyleOptionTab::End}); QCOMPARE(tabbar.currentIndex(), 0); QSize sizeHint = tabbar.sizeHint(); QVERIFY(sizeHint.width() == prevSizeHint.width()); prevSizeHint = sizeHint; tabbar.setTabVisible(1, false); + checkPositions({QStyleOptionTab::Beginning, QStyleOptionTab::End}); QCOMPARE(tabbar.currentIndex(), 0); sizeHint = tabbar.sizeHint(); QVERIFY(sizeHint.width() < prevSizeHint.width()); prevSizeHint = sizeHint; tabbar.setTabVisible(2, false); + checkPositions({QStyleOptionTab::OnlyOneTab}); QCOMPARE(tabbar.currentIndex(), 0); sizeHint = tabbar.sizeHint(); QVERIFY(sizeHint.width() < prevSizeHint.width()); @@ -571,14 +595,6 @@ void tst_QTabBar::selectionBehaviorOnRemove() QCOMPARE(tabbar.currentIndex(), expected); } -class TabBar : public QTabBar -{ - Q_OBJECT -public: - void callMoveTab(int from, int to){ moveTab(from, to); } -}; - - Q_DECLARE_METATYPE(QTabBar::Shape) void tst_QTabBar::moveTab_data() { @@ -613,7 +629,7 @@ void tst_QTabBar::moveTab() bar.setShape(shape); while(--tabs >= 0) bar.addTab(QString::number(tabs)); - bar.callMoveTab(from, to); + bar.moveTab(from, to); } -- cgit v1.2.3 From 4b875caa6b47df1e22214593acad95865910c5fe Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Mon, 20 Jan 2020 20:33:07 +1000 Subject: wasm: guard nonthreaded builds from using threading.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I2873cb902d17632a923dc3bd1a6e8e01af1693d4 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/wasm/qwasmeventdispatcher.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp b/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp index d89cd78b28..ca8db9b215 100644 --- a/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp +++ b/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp @@ -33,9 +33,11 @@ #include +#if QT_CONFIG(thread) #if (__EMSCRIPTEN_major__ > 1 || __EMSCRIPTEN_minor__ > 38 || __EMSCRIPTEN_minor__ == 38 && __EMSCRIPTEN_tiny__ >= 22) # define EMSCRIPTEN_HAS_ASYNC_RUN_IN_MAIN_RUNTIME_THREAD #endif +#endif #ifdef EMSCRIPTEN_HAS_ASYNC_RUN_IN_MAIN_RUNTIME_THREAD #include -- cgit v1.2.3 From dd23313d66846022894b56ad25b6c2c0fdb54762 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Fri, 17 Jan 2020 16:02:31 +0100 Subject: eglfs: find correct framebuffer index even if device node is symlink Using the Vivante driver on a board with different device trees I found the need to let udev point me to the framebuffer actually connected to HDMI by adding a symlink. Since the extraction of the framebuffer index failed and always returned 0 the GUI still always showed up on the first framebuffer. Change-Id: Ib4aa0fdd6e85d296c17fd977921cbc78e52dcdcf Reviewed-by: Laszlo Agocs --- src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp b/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp index 81bad45cd2..dbfb0e6058 100644 --- a/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp @@ -52,6 +52,7 @@ #include #include #if QT_CONFIG(regularexpression) +# include # include #endif #include @@ -144,7 +145,12 @@ int QEglFSDeviceIntegration::framebufferIndex() const int fbIndex = 0; #if QT_CONFIG(regularexpression) QRegularExpression fbIndexRx(QLatin1String("fb(\\d+)")); - QRegularExpressionMatch match = fbIndexRx.match(QString::fromLocal8Bit(fbDeviceName())); + QFileInfo fbinfo(QString::fromLocal8Bit(fbDeviceName())); + QRegularExpressionMatch match; + if (fbinfo.isSymLink()) + match = fbIndexRx.match(fbinfo.symLinkTarget()); + else + match = fbIndexRx.match(fbinfo.fileName()); if (match.hasMatch()) fbIndex = match.captured(1).toInt(); #endif -- cgit v1.2.3 From e0e7c42a19316c53fd3ab21133223b5ee788ba38 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 17 Jan 2020 15:06:47 +0100 Subject: Introduce VK_KHR_display support for i.MX8 devices The eglfs_viv backend has Vulkan support now. While the support code is common (lives in api/vulkan), we will not expose this for any other integration yet, without the appropriate testing. While putting this to eglfs seems unintuitive at first, it turns out that for Vivante in particular this is very useful, since we can rely on the existing framebuffer device infrastructure to solve certain problems (like the lack of vsync) The VK_KHR_display implementation of Vivante currently exhibits all the known issues of the old, fbdev-style EGL plumbing (presumably since it lives on top of that): - No vsync. This can be fixed by setting QT_QPA_EGLFS_FORCEVSYNC. - May need a manual call to fbset to set the correct resolution before launching the Qt app. - And of course it lacks all the multi-screen features provided by drm. - Plus, it seems the swapchain only supports a min/max buffer count of 1. This needs special handling in QRhi since until now we assumed that there was always at least 2 buffers available. [ChangeLog][Platform Specific Changes][Linux] Vulkan is now supported by eglfs (eglfs_viv backend) on i.MX8 devices with the Vivante graphics stack. This is done via VK_KHR_display so no windowing system is required. Task-number: QTBUG-78754 Change-Id: I7530aa026d4b904b9de83f9bdbdc4897ae770e71 Reviewed-by: Paul Olav Tvete --- src/gui/rhi/qrhivulkan.cpp | 17 +- src/plugins/platforms/eglfs/api/api.pri | 9 + .../eglfs/api/qeglfsdeviceintegration.cpp | 8 + .../eglfs/api/qeglfsdeviceintegration_p.h | 4 + .../platforms/eglfs/api/qeglfsintegration.cpp | 19 +- .../platforms/eglfs/api/qeglfsintegration_p.h | 3 + src/plugins/platforms/eglfs/api/qeglfswindow_p.h | 4 + .../eglfs/api/vulkan/qeglfsvulkaninstance.cpp | 280 +++++++++++++++++++++ .../eglfs/api/vulkan/qeglfsvulkaninstance_p.h | 88 +++++++ .../eglfs/api/vulkan/qeglfsvulkanwindow.cpp | 75 ++++++ .../eglfs/api/vulkan/qeglfsvulkanwindow_p.h | 74 ++++++ .../eglfs_viv/qeglfsvivintegration.cpp | 21 ++ .../eglfs_viv/qeglfsvivintegration.h | 6 + .../platforms/eglfs/eglfsdeviceintegration.pro | 3 + 14 files changed, 602 insertions(+), 9 deletions(-) create mode 100644 src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkaninstance.cpp create mode 100644 src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkaninstance_p.h create mode 100644 src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkanwindow.cpp create mode 100644 src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkanwindow_p.h diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp index f4c72d2cca..e7faa0cadd 100644 --- a/src/gui/rhi/qrhivulkan.cpp +++ b/src/gui/rhi/qrhivulkan.cpp @@ -1351,8 +1351,8 @@ bool QRhiVulkan::recreateSwapChain(QRhiSwapChain *swapChain) quint32 actualSwapChainBufferCount = 0; err = vkGetSwapchainImagesKHR(dev, swapChainD->sc, &actualSwapChainBufferCount, nullptr); - if (err != VK_SUCCESS || actualSwapChainBufferCount < 2) { - qWarning("Failed to get swapchain images: %d (count=%u)", err, actualSwapChainBufferCount); + if (err != VK_SUCCESS || actualSwapChainBufferCount == 0) { + qWarning("Failed to get swapchain images: %d", err); return false; } @@ -1528,7 +1528,8 @@ void QRhiVulkan::releaseSwapChainResources(QRhiSwapChain *swapChain) QRhi::FrameOpResult QRhiVulkan::beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) { QVkSwapChain *swapChainD = QRHI_RES(QVkSwapChain, swapChain); - QVkSwapChain::FrameResources &frame(swapChainD->frameRes[swapChainD->currentFrameSlot]); + const int frameResIndex = swapChainD->bufferCount > 1 ? swapChainD->currentFrameSlot : 0; + QVkSwapChain::FrameResources &frame(swapChainD->frameRes[frameResIndex]); QRhiProfilerPrivate *rhiP = profilerPrivateOrNull(); if (!frame.imageAcquired) { @@ -1571,7 +1572,7 @@ QRhi::FrameOpResult QRhiVulkan::beginFrame(QRhiSwapChain *swapChain, QRhi::Begin // will make B wait for A's frame 0 commands, so if a resource is written // in B's frame or when B checks for pending resource releases, that won't // mess up A's in-flight commands (as they are not in flight anymore). - waitCommandCompletion(int(swapChainD->currentFrameSlot)); + waitCommandCompletion(frameResIndex); // Now is the time to read the timestamps for the previous frame for this slot. if (frame.timestampQueryIndex >= 0) { @@ -1606,7 +1607,7 @@ QRhi::FrameOpResult QRhiVulkan::beginFrame(QRhiSwapChain *swapChain, QRhi::Begin // when profiling is enabled, pick a free query (pair) from the pool int timestampQueryIdx = -1; - if (profilerPrivateOrNull()) { + if (profilerPrivateOrNull() && swapChainD->bufferCount > 1) { // no timestamps if not having at least 2 frames in flight for (int i = 0; i < timestampQueryPoolMap.count(); ++i) { if (!timestampQueryPoolMap.testBit(i)) { timestampQueryPoolMap.setBit(i); @@ -1648,7 +1649,8 @@ QRhi::FrameOpResult QRhiVulkan::endFrame(QRhiSwapChain *swapChain, QRhi::EndFram recordPrimaryCommandBuffer(&swapChainD->cbWrapper); - QVkSwapChain::FrameResources &frame(swapChainD->frameRes[swapChainD->currentFrameSlot]); + int frameResIndex = swapChainD->bufferCount > 1 ? swapChainD->currentFrameSlot : 0; + QVkSwapChain::FrameResources &frame(swapChainD->frameRes[frameResIndex]); QVkSwapChain::ImageResources &image(swapChainD->imageRes[swapChainD->currentImageIndex]); if (image.lastUse != QVkSwapChain::ImageResources::ScImageUseRender) { @@ -1860,7 +1862,8 @@ QRhi::FrameOpResult QRhiVulkan::endAndSubmitPrimaryCommandBuffer(VkCommandBuffer void QRhiVulkan::waitCommandCompletion(int frameSlot) { for (QVkSwapChain *sc : qAsConst(swapchains)) { - QVkSwapChain::FrameResources &frame(sc->frameRes[frameSlot]); + const int frameResIndex = sc->bufferCount > 1 ? frameSlot : 0; + QVkSwapChain::FrameResources &frame(sc->frameRes[frameResIndex]); if (frame.cmdFenceWaitable) { df->vkWaitForFences(dev, 1, &frame.cmdFence, VK_TRUE, UINT64_MAX); df->vkResetFences(dev, 1, &frame.cmdFence); diff --git a/src/plugins/platforms/eglfs/api/api.pri b/src/plugins/platforms/eglfs/api/api.pri index a6d81016b6..68965b58d8 100644 --- a/src/plugins/platforms/eglfs/api/api.pri +++ b/src/plugins/platforms/eglfs/api/api.pri @@ -23,4 +23,13 @@ qtConfig(opengl) { $$PWD/qeglfscontext_p.h } +qtConfig(vulkan) { + SOURCES += \ + $$PWD/vulkan/qeglfsvulkaninstance.cpp \ + $$PWD/vulkan/qeglfsvulkanwindow.cpp + HEADERS += \ + $$PWD/vulkan/qeglfsvulkaninstance_p.h \ + $$PWD/vulkan/qeglfsvulkanwindow_p.h +} + INCLUDEPATH += $$PWD diff --git a/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp b/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp index dbfb0e6058..e3145aa0b0 100644 --- a/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration.cpp @@ -381,6 +381,14 @@ void *QEglFSDeviceIntegration::wlDisplay() const return nullptr; } +#if QT_CONFIG(vulkan) +QPlatformVulkanInstance *QEglFSDeviceIntegration::createPlatformVulkanInstance(QVulkanInstance *instance) +{ + Q_UNUSED(instance); + return nullptr; +} +#endif + EGLConfig QEglFSDeviceIntegration::chooseConfig(EGLDisplay display, const QSurfaceFormat &format) { class Chooser : public QEglConfigChooser { diff --git a/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration_p.h b/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration_p.h index 71ffb4c69a..08447a40ea 100644 --- a/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration_p.h +++ b/src/plugins/platforms/eglfs/api/qeglfsdeviceintegration_p.h @@ -108,6 +108,10 @@ public: virtual void *nativeResourceForScreen(const QByteArray &resource, QScreen *screen); virtual void *wlDisplay() const; +#if QT_CONFIG(vulkan) + virtual QPlatformVulkanInstance *createPlatformVulkanInstance(QVulkanInstance *instance); +#endif + static EGLConfig chooseConfig(EGLDisplay display, const QSurfaceFormat &format); }; diff --git a/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp b/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp index d9a3545a95..e26d984cc1 100644 --- a/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp +++ b/src/plugins/platforms/eglfs/api/qeglfsintegration.cpp @@ -247,6 +247,13 @@ QPlatformOffscreenSurface *QEglFSIntegration::createPlatformOffscreenSurface(QOf } #endif // QT_NO_OPENGL +#if QT_CONFIG(vulkan) +QPlatformVulkanInstance *QEglFSIntegration::createPlatformVulkanInstance(QVulkanInstance *instance) const +{ + return qt_egl_device_integration()->createPlatformVulkanInstance(instance); +} +#endif + bool QEglFSIntegration::hasCapability(QPlatformIntegration::Capability cap) const { // We assume that devices will have more and not less capabilities @@ -283,7 +290,8 @@ enum ResourceType { NativeDisplay, XlibDisplay, WaylandDisplay, - EglSurface + EglSurface, + VkSurface }; static int resourceType(const QByteArray &key) @@ -296,7 +304,8 @@ static int resourceType(const QByteArray &key) QByteArrayLiteral("nativedisplay"), QByteArrayLiteral("display"), QByteArrayLiteral("server_wl_display"), - QByteArrayLiteral("eglsurface") + QByteArrayLiteral("eglsurface"), + QByteArrayLiteral("vksurface") }; const QByteArray *end = names + sizeof(names) / sizeof(names[0]); const QByteArray *result = std::find(names, end, key); @@ -364,6 +373,12 @@ void *QEglFSIntegration::nativeResourceForWindow(const QByteArray &resource, QWi if (window && window->handle()) result = reinterpret_cast(static_cast(window->handle())->surface()); break; +#if QT_CONFIG(vulkan) + case VkSurface: + if (window && window->handle() && window->surfaceType() == QSurface::VulkanSurface) + result = static_cast(window->handle())->vulkanSurfacePtr(); + break; +#endif default: break; } diff --git a/src/plugins/platforms/eglfs/api/qeglfsintegration_p.h b/src/plugins/platforms/eglfs/api/qeglfsintegration_p.h index 898b322834..b293651ce7 100644 --- a/src/plugins/platforms/eglfs/api/qeglfsintegration_p.h +++ b/src/plugins/platforms/eglfs/api/qeglfsintegration_p.h @@ -85,6 +85,9 @@ public: #ifndef QT_NO_OPENGL QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const override; QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const override; +#endif +#if QT_CONFIG(vulkan) + QPlatformVulkanInstance *createPlatformVulkanInstance(QVulkanInstance *instance) const override; #endif bool hasCapability(QPlatformIntegration::Capability cap) const override; diff --git a/src/plugins/platforms/eglfs/api/qeglfswindow_p.h b/src/plugins/platforms/eglfs/api/qeglfswindow_p.h index be2a0630d3..7bf74c25ee 100644 --- a/src/plugins/platforms/eglfs/api/qeglfswindow_p.h +++ b/src/plugins/platforms/eglfs/api/qeglfswindow_p.h @@ -64,6 +64,7 @@ QT_BEGIN_NAMESPACE class QOpenGLCompositorBackingStore; class QPlatformTextureList; + #ifndef QT_NO_OPENGL class Q_EGLFS_EXPORT QEglFSWindow : public QPlatformWindow, public QOpenGLCompositorWindow #else @@ -96,6 +97,9 @@ public: EGLNativeWindowType eglWindow() const; EGLSurface surface() const; QEglFSScreen *screen() const override; +#if QT_CONFIG(vulkan) + virtual void *vulkanSurfacePtr() { return nullptr; } +#endif bool hasNativeWindow() const { return m_flags.testFlag(HasNativeWindow); } diff --git a/src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkaninstance.cpp b/src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkaninstance.cpp new file mode 100644 index 0000000000..a75251ca5f --- /dev/null +++ b/src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkaninstance.cpp @@ -0,0 +1,280 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qeglfsvulkaninstance_p.h" +#include "qeglfswindow_p.h" +#include "qeglfshooks_p.h" +#include + +QT_BEGIN_NAMESPACE + +Q_DECLARE_LOGGING_CATEGORY(qLcEglDevDebug) + +QEglFSVulkanInstance::QEglFSVulkanInstance(QVulkanInstance *instance) + : m_instance(instance) +{ + loadVulkanLibrary(QStringLiteral("vulkan")); +} + +void QEglFSVulkanInstance::createOrAdoptInstance() +{ + qCDebug(qLcEglDevDebug, "Creating Vulkan instance for VK_KHR_display"); + + const QByteArray extName = QByteArrayLiteral("VK_KHR_display"); + initInstance(m_instance, { extName }); + if (!m_vkInst) + return; + if (!enabledExtensions().contains(extName)) { + qWarning("Failed to enable VK_KHR_display extension"); + return; + } + +#if VK_KHR_display + m_getPhysicalDeviceDisplayPropertiesKHR = (PFN_vkGetPhysicalDeviceDisplayPropertiesKHR) + m_vkGetInstanceProcAddr(m_vkInst, "vkGetPhysicalDeviceDisplayPropertiesKHR"); + m_getDisplayModePropertiesKHR = (PFN_vkGetDisplayModePropertiesKHR) + m_vkGetInstanceProcAddr(m_vkInst, "vkGetDisplayModePropertiesKHR"); + m_getPhysicalDeviceDisplayPlanePropertiesKHR = (PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR) + m_vkGetInstanceProcAddr(m_vkInst, "vkGetPhysicalDeviceDisplayPlanePropertiesKHR"); + + m_getDisplayPlaneSupportedDisplaysKHR = (PFN_vkGetDisplayPlaneSupportedDisplaysKHR) + m_vkGetInstanceProcAddr(m_vkInst, "vkGetDisplayPlaneSupportedDisplaysKHR"); + m_getDisplayPlaneCapabilitiesKHR = (PFN_vkGetDisplayPlaneCapabilitiesKHR) + m_vkGetInstanceProcAddr(m_vkInst, "vkGetDisplayPlaneCapabilitiesKHR"); + + m_createDisplayPlaneSurfaceKHR = (PFN_vkCreateDisplayPlaneSurfaceKHR) + m_vkGetInstanceProcAddr(m_vkInst, "vkCreateDisplayPlaneSurfaceKHR"); +#endif + + m_enumeratePhysicalDevices = (PFN_vkEnumeratePhysicalDevices) + m_vkGetInstanceProcAddr(m_vkInst, "vkEnumeratePhysicalDevices"); + + // Use for first physical device, unless overridden by QT_VK_PHYSICAL_DEVICE_INDEX. + // This behavior matches what the Vulkan backend of QRhi would do. + + uint32_t physDevCount = 0; + m_enumeratePhysicalDevices(m_vkInst, &physDevCount, nullptr); + if (!physDevCount) { + qWarning("No physical devices"); + return; + } + QVarLengthArray physDevs(physDevCount); + VkResult err = m_enumeratePhysicalDevices(m_vkInst, &physDevCount, physDevs.data()); + if (err != VK_SUCCESS || !physDevCount) { + qWarning("Failed to enumerate physical devices: %d", err); + return; + } + + if (qEnvironmentVariableIsSet("QT_VK_PHYSICAL_DEVICE_INDEX")) { + int requestedPhysDevIndex = qEnvironmentVariableIntValue("QT_VK_PHYSICAL_DEVICE_INDEX"); + if (requestedPhysDevIndex >= 0 && uint32_t(requestedPhysDevIndex) < physDevCount) + m_physDev = physDevs[requestedPhysDevIndex]; + } + + if (m_physDev == VK_NULL_HANDLE) + m_physDev = physDevs[0]; +} + +bool QEglFSVulkanInstance::supportsPresent(VkPhysicalDevice physicalDevice, + uint32_t queueFamilyIndex, + QWindow *window) +{ + Q_UNUSED(physicalDevice); + Q_UNUSED(queueFamilyIndex); + Q_UNUSED(window); + return true; +} + +VkSurfaceKHR QEglFSVulkanInstance::createSurface(QEglFSWindow *window) +{ +#if VK_KHR_display + qCDebug(qLcEglDevDebug, "Creating VkSurfaceKHR via VK_KHR_display for window %p", (void *) window); + + if (!m_physDev) { + qWarning("No physical device, cannot create surface"); + return VK_NULL_HANDLE; + } + + uint32_t displayCount = 0; + VkResult err = m_getPhysicalDeviceDisplayPropertiesKHR(m_physDev, &displayCount, nullptr); + if (err != VK_SUCCESS) { + qWarning("Failed to get display properties: %d", err); + return VK_NULL_HANDLE; + } + + qCDebug(qLcEglDevDebug, "Display count: %u", displayCount); + + QVarLengthArray displayProps(displayCount); + m_getPhysicalDeviceDisplayPropertiesKHR(m_physDev, &displayCount, displayProps.data()); + + VkDisplayKHR display = VK_NULL_HANDLE; + VkDisplayModeKHR displayMode = VK_NULL_HANDLE; + uint32_t width = 0; + uint32_t height = 0; + + for (uint32_t i = 0; i < displayCount; ++i) { + const VkDisplayPropertiesKHR &disp(displayProps[i]); + qCDebug(qLcEglDevDebug, "Display #%u:\n display: %p\n name: %s\n dimensions: %ux%u\n resolution: %ux%u", + i, (void *) disp.display, disp.displayName, + disp.physicalDimensions.width, disp.physicalDimensions.height, + disp.physicalResolution.width, disp.physicalResolution.height); + + // Just pick the first display and the first mode. + if (i == 0) + display = disp.display; + + uint32_t modeCount = 0; + if (m_getDisplayModePropertiesKHR(m_physDev, disp.display, &modeCount, nullptr) != VK_SUCCESS) { + qWarning("Failed to get modes for display"); + continue; + } + QVarLengthArray modeProps(modeCount); + m_getDisplayModePropertiesKHR(m_physDev, disp.display, &modeCount, modeProps.data()); + for (uint32_t j = 0; j < modeCount; ++j) { + const VkDisplayModePropertiesKHR &mode(modeProps[j]); + qCDebug(qLcEglDevDebug, " Mode #%u:\n mode: %p\n visibleRegion: %ux%u\n refreshRate: %u", + j, (void *) mode.displayMode, + mode.parameters.visibleRegion.width, mode.parameters.visibleRegion.height, + mode.parameters.refreshRate); + if (j == 0) { + displayMode = mode.displayMode; + width = mode.parameters.visibleRegion.width; + height = mode.parameters.visibleRegion.height; + } + } + } + + if (display == VK_NULL_HANDLE || displayMode == VK_NULL_HANDLE) { + qWarning("Failed to choose display and mode"); + return VK_NULL_HANDLE; + } + uint32_t planeCount = 0; + err = m_getPhysicalDeviceDisplayPlanePropertiesKHR(m_physDev, &planeCount, nullptr); + if (err != VK_SUCCESS) { + qWarning("Failed to get plane properties: %d", err); + return VK_NULL_HANDLE; + } + + qCDebug(qLcEglDevDebug, "Plane count: %u", planeCount); + + QVarLengthArray planeProps(planeCount); + m_getPhysicalDeviceDisplayPlanePropertiesKHR(m_physDev, &planeCount, planeProps.data()); + + uint32_t planeIndex = UINT_MAX; + for (uint32_t i = 0; i < planeCount; ++i) { + uint32_t supportedDisplayCount = 0; + err = m_getDisplayPlaneSupportedDisplaysKHR(m_physDev, i, &supportedDisplayCount, nullptr); + if (err != VK_SUCCESS) { + qWarning("Failed to query supported displays for plane: %d", err); + return VK_NULL_HANDLE; + } + + QVarLengthArray supportedDisplays(supportedDisplayCount); + m_getDisplayPlaneSupportedDisplaysKHR(m_physDev, i, &supportedDisplayCount, supportedDisplays.data()); + qCDebug(qLcEglDevDebug, "Plane #%u supports %u displays, currently bound to display %p", + i, supportedDisplayCount, (void *) planeProps[i].currentDisplay); + + VkDisplayPlaneCapabilitiesKHR caps; + err = m_getDisplayPlaneCapabilitiesKHR(m_physDev, displayMode, i, &caps); + if (err != VK_SUCCESS) { + qWarning("Failed to query plane capabilities: %d", err); + return VK_NULL_HANDLE; + } + + qCDebug(qLcEglDevDebug, " supportedAlpha: %d (1=no, 2=global, 4=per pixel, 8=per pixel premul)\n" + " minSrc=%d, %d %ux%u\n" + " maxSrc=%d, %d %ux%u\n" + " minDst=%d, %d %ux%u\n" + " maxDst=%d, %d %ux%u", + int(caps.supportedAlpha), + caps.minSrcPosition.x, caps.minSrcPosition.y, caps.minSrcExtent.width, caps.minSrcExtent.height, + caps.maxSrcPosition.x, caps.maxSrcPosition.y, caps.maxSrcExtent.width, caps.maxSrcExtent.height, + caps.minDstPosition.x, caps.minDstPosition.y, caps.minDstExtent.width, caps.minDstExtent.height, + caps.maxDstPosition.x, caps.maxDstPosition.y, caps.maxDstExtent.width, caps.maxDstExtent.height); + + // if the plane is not in use and supports our chosen display, use that plane + if (supportedDisplays.contains(display) + && (planeProps[i].currentDisplay == VK_NULL_HANDLE || planeProps[i].currentDisplay == display)) + { + planeIndex = i; + } + } + + if (planeIndex == UINT_MAX) { + qWarning("Failed to find a suitable plane"); + return VK_NULL_HANDLE; + } + + qCDebug(qLcEglDevDebug, "Using plane #%u", planeIndex); + + VkDisplaySurfaceCreateInfoKHR surfaceCreateInfo = {}; + surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_DISPLAY_SURFACE_CREATE_INFO_KHR; + surfaceCreateInfo.displayMode = displayMode; + surfaceCreateInfo.planeIndex = planeIndex; + surfaceCreateInfo.planeStackIndex = planeProps[planeIndex].currentStackIndex; + surfaceCreateInfo.transform = VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR; + surfaceCreateInfo.globalAlpha = 1.0f; + surfaceCreateInfo.alphaMode = VK_DISPLAY_PLANE_ALPHA_OPAQUE_BIT_KHR; + surfaceCreateInfo.imageExtent = { width, height }; + + VkSurfaceKHR surface = VK_NULL_HANDLE; + err = m_createDisplayPlaneSurfaceKHR(m_vkInst, &surfaceCreateInfo, nullptr, &surface); + if (err != VK_SUCCESS || surface == VK_NULL_HANDLE) { + qWarning("Failed to create surface: %d", err); + return VK_NULL_HANDLE; + } + + qCDebug(qLcEglDevDebug, "Created surface %p", (void *) surface); + + return surface; + +#else + Q_UNUSED(window); + qWarning("VK_KHR_display support was not compiled in, cannot create surface"); + return VK_NULL_HANDLE; +#endif +} + +void QEglFSVulkanInstance::presentAboutToBeQueued(QWindow *window) +{ + // support QT_QPA_EGLFS_FORCEVSYNC (i.MX8 with eglfs_viv) + qt_egl_device_integration()->waitForVSync(window->handle()); +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkaninstance_p.h b/src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkaninstance_p.h new file mode 100644 index 0000000000..9d6d47f439 --- /dev/null +++ b/src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkaninstance_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QEGLFSVULKANINSTANCE_H +#define QEGLFSVULKANINSTANCE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qeglfsglobal_p.h" +#include + +QT_BEGIN_NAMESPACE + +class QEglFSWindow; + +class Q_EGLFS_EXPORT QEglFSVulkanInstance : public QBasicPlatformVulkanInstance +{ +public: + QEglFSVulkanInstance(QVulkanInstance *instance); + + void createOrAdoptInstance() override; + bool supportsPresent(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, QWindow *window) override; + void presentAboutToBeQueued(QWindow *window) override; + + VkSurfaceKHR createSurface(QEglFSWindow *window); + +private: + QVulkanInstance *m_instance; + VkPhysicalDevice m_physDev = VK_NULL_HANDLE; + PFN_vkEnumeratePhysicalDevices m_enumeratePhysicalDevices = nullptr; +#if VK_KHR_display + PFN_vkGetPhysicalDeviceDisplayPropertiesKHR m_getPhysicalDeviceDisplayPropertiesKHR = nullptr; + PFN_vkGetDisplayModePropertiesKHR m_getDisplayModePropertiesKHR = nullptr; + PFN_vkGetPhysicalDeviceDisplayPlanePropertiesKHR m_getPhysicalDeviceDisplayPlanePropertiesKHR = nullptr; + PFN_vkGetDisplayPlaneSupportedDisplaysKHR m_getDisplayPlaneSupportedDisplaysKHR = nullptr; + PFN_vkGetDisplayPlaneCapabilitiesKHR m_getDisplayPlaneCapabilitiesKHR = nullptr; + PFN_vkCreateDisplayPlaneSurfaceKHR m_createDisplayPlaneSurfaceKHR = nullptr; +#endif +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkanwindow.cpp b/src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkanwindow.cpp new file mode 100644 index 0000000000..ae41ca00b6 --- /dev/null +++ b/src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkanwindow.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qeglfsvulkanwindow_p.h" + +QT_BEGIN_NAMESPACE + +QEglFSVulkanWindow::QEglFSVulkanWindow(QWindow *window) + : QEglFSWindow(window), + m_surface(VK_NULL_HANDLE) +{ +} + +QEglFSVulkanWindow::~QEglFSVulkanWindow() +{ + if (m_surface) { + QVulkanInstance *inst = window()->vulkanInstance(); + if (inst) + static_cast(inst->handle())->destroySurface(m_surface); + } +} + +void *QEglFSVulkanWindow::vulkanSurfacePtr() +{ + if (m_surface) + return &m_surface; + + QVulkanInstance *inst = window()->vulkanInstance(); + if (!inst) { + qWarning("Attempted to create Vulkan surface without an instance; was QWindow::setVulkanInstance() called?"); + return nullptr; + } + QEglFSVulkanInstance *eglfsInst = static_cast(inst->handle()); + m_surface = eglfsInst->createSurface(this); + + return &m_surface; +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkanwindow_p.h b/src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkanwindow_p.h new file mode 100644 index 0000000000..492fb41ca4 --- /dev/null +++ b/src/plugins/platforms/eglfs/api/vulkan/qeglfsvulkanwindow_p.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QEGLFSVULKANWINDOW_H +#define QEGLFSVULKANWINDOW_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qeglfsglobal_p.h" +#include "qeglfswindow_p.h" +#include "qeglfsvulkaninstance_p.h" + +QT_BEGIN_NAMESPACE + +class Q_EGLFS_EXPORT QEglFSVulkanWindow : public QEglFSWindow +{ +public: + QEglFSVulkanWindow(QWindow *window); + ~QEglFSVulkanWindow(); + + void *vulkanSurfacePtr() override; + +private: + VkSurfaceKHR m_surface; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/qeglfsvivintegration.cpp b/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/qeglfsvivintegration.cpp index 2fc076ad0c..5e1d28a353 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/qeglfsvivintegration.cpp +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/qeglfsvivintegration.cpp @@ -41,6 +41,11 @@ #include #include +#if QT_CONFIG(vulkan) +#include "private/qeglfsvulkaninstance_p.h" +#include "private/qeglfsvulkanwindow_p.h" +#endif + #ifdef Q_OS_INTEGRITY extern "C" void VivanteInit(void); #endif @@ -97,4 +102,20 @@ void QEglFSVivIntegration::destroyNativeWindow(EGLNativeWindowType window) fbDestroyWindow(window); } +#if QT_CONFIG(vulkan) + +QEglFSWindow *QEglFSVivIntegration::createWindow(QWindow *window) const +{ + if (window->surfaceType() == QSurface::VulkanSurface) + return new QEglFSVulkanWindow(window); + return QEglFSDeviceIntegration::createWindow(window); +} + +QPlatformVulkanInstance *QEglFSVivIntegration::createPlatformVulkanInstance(QVulkanInstance *instance) +{ + return new QEglFSVulkanInstance(instance); +} + +#endif // vulkan + QT_END_NAMESPACE diff --git a/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/qeglfsvivintegration.h b/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/qeglfsvivintegration.h index 4d1718afcf..02b59c16b5 100644 --- a/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/qeglfsvivintegration.h +++ b/src/plugins/platforms/eglfs/deviceintegration/eglfs_viv/qeglfsvivintegration.h @@ -53,6 +53,12 @@ public: void destroyNativeWindow(EGLNativeWindowType window) override; EGLNativeDisplayType platformDisplay() const override; + // Vulkan support with VK_KHR_display +#if QT_CONFIG(vulkan) + QEglFSWindow *createWindow(QWindow *window) const override; + QPlatformVulkanInstance *createPlatformVulkanInstance(QVulkanInstance *instance) override; +#endif + private: QSize mScreenSize; EGLNativeDisplayType mNativeDisplay; diff --git a/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro b/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro index 8bb7b614f1..bd02aea4d3 100644 --- a/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro +++ b/src/plugins/platforms/eglfs/eglfsdeviceintegration.pro @@ -20,6 +20,9 @@ qtHaveModule(input_support-private): \ qtHaveModule(platformcompositor_support-private): \ QT += platformcompositor_support-private +qtConfig(vulkan): \ + QT += vulkan_support-private + # Avoid X11 header collision, use generic EGL native types DEFINES += QT_EGL_NO_X11 -- cgit v1.2.3 From eecd502ff39cf4de51f3b556280702d6f2e3ec76 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 13 Jan 2020 15:31:01 +0100 Subject: Regenerate qsb files for auto and manual tests They are now version 4, which is hopefully the final format, relying on nothing but QDataStream. Except for the qshader autotest which tests all the 1..4 versions and so needs appropriate test data. Also unifies the batch file naming. Change-Id: Iec478be86d14dbec7ffb9d5f9b62c14fca5d7c9e Reviewed-by: Eirik Aavitsland --- tests/auto/gui/rhi/qrhi/data/buildshaders.bat | 48 +++++++++++++++++++++ tests/auto/gui/rhi/qrhi/data/compile.bat | 48 --------------------- tests/auto/gui/rhi/qrhi/data/simple.frag.qsb | Bin 908 -> 730 bytes tests/auto/gui/rhi/qrhi/data/simple.vert.qsb | Bin 958 -> 791 bytes .../auto/gui/rhi/qrhi/data/simpletextured.frag.qsb | Bin 1479 -> 1208 bytes .../auto/gui/rhi/qrhi/data/simpletextured.vert.qsb | Bin 1195 -> 964 bytes tests/auto/gui/rhi/qrhi/data/textured.frag.qsb | Bin 1997 -> 1574 bytes tests/auto/gui/rhi/qrhi/data/textured.vert.qsb | Bin 1708 -> 1342 bytes tests/manual/rhi/computebuffer/buffer.comp.qsb | Bin 2160 -> 1868 bytes tests/manual/rhi/computebuffer/main.frag.qsb | Bin 672 -> 584 bytes tests/manual/rhi/computebuffer/main.vert.qsb | Bin 852 -> 762 bytes tests/manual/rhi/computeimage/image.comp.qsb | Bin 1811 -> 1594 bytes tests/manual/rhi/cubemap/cubemap.frag.qsb | Bin 1311 -> 1089 bytes tests/manual/rhi/cubemap/cubemap.vert.qsb | Bin 1499 -> 1200 bytes tests/manual/rhi/instancing/inst.frag.qsb | Bin 936 -> 735 bytes tests/manual/rhi/instancing/inst.vert.qsb | Bin 1792 -> 1456 bytes tests/manual/rhi/mrt/mrt.frag.qsb | Bin 1934 -> 1594 bytes tests/manual/rhi/mrt/mrt.vert.qsb | Bin 1633 -> 1299 bytes tests/manual/rhi/shadowmap/buildshaders.sh | 5 --- tests/manual/rhi/shadowmap/main.frag.qsb | Bin 2489 -> 2307 bytes tests/manual/rhi/shadowmap/main.vert.qsb | Bin 1595 -> 1587 bytes tests/manual/rhi/shadowmap/shadowmap.frag.qsb | Bin 408 -> 466 bytes tests/manual/rhi/shadowmap/shadowmap.vert.qsb | Bin 1215 -> 1083 bytes tests/manual/rhi/shared/color.frag.qsb | Bin 1483 -> 1179 bytes tests/manual/rhi/shared/color.vert.qsb | Bin 1648 -> 1318 bytes tests/manual/rhi/shared/texture.frag.qsb | Bin 1710 -> 1345 bytes tests/manual/rhi/shared/texture.vert.qsb | Bin 1897 -> 1574 bytes tests/manual/rhi/shared/texture_ms4.frag.qsb | Bin 1847 -> 1555 bytes 28 files changed, 48 insertions(+), 53 deletions(-) create mode 100644 tests/auto/gui/rhi/qrhi/data/buildshaders.bat delete mode 100644 tests/auto/gui/rhi/qrhi/data/compile.bat delete mode 100755 tests/manual/rhi/shadowmap/buildshaders.sh diff --git a/tests/auto/gui/rhi/qrhi/data/buildshaders.bat b/tests/auto/gui/rhi/qrhi/data/buildshaders.bat new file mode 100644 index 0000000000..5b8a77b833 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/buildshaders.bat @@ -0,0 +1,48 @@ +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: +:: Copyright (C) 2019 The Qt Company Ltd. +:: Contact: https://www.qt.io/licensing/ +:: +:: This file is part of the QtQuick module of the Qt Toolkit. +:: +:: $QT_BEGIN_LICENSE:LGPL$ +:: Commercial License Usage +:: Licensees holding valid commercial Qt licenses may use this file in +:: accordance with the commercial license agreement provided with the +:: Software or, alternatively, in accordance with the terms contained in +:: a written agreement between you and The Qt Company. For licensing terms +:: and conditions see https://www.qt.io/terms-conditions. For further +:: information use the contact form at https://www.qt.io/contact-us. +:: +:: GNU Lesser General Public License Usage +:: Alternatively, this file may be used under the terms of the GNU Lesser +:: General Public License version 3 as published by the Free Software +:: Foundation and appearing in the file LICENSE.LGPL3 included in the +:: packaging of this file. Please review the following information to +:: ensure the GNU Lesser General Public License version 3 requirements +:: will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +:: +:: GNU General Public License Usage +:: Alternatively, this file may be used under the terms of the GNU +:: General Public License version 2.0 or (at your option) the GNU General +:: Public license version 3 or any later version approved by the KDE Free +:: Qt Foundation. The licenses are as published by the Free Software +:: Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +:: included in the packaging of this file. Please review the following +:: information to ensure the GNU General Public License requirements will +:: be met: https://www.gnu.org/licenses/gpl-2.0.html and +:: https://www.gnu.org/licenses/gpl-3.0.html. +:: +:: $QT_END_LICENSE$ +:: +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +:: Note the -c argument: we do not want runtime HLSL compilation since that is +:: not an option on UWP (WinRT). This means that running qsb must happen on Windows. + +qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simple.vert.qsb simple.vert +qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simple.frag.qsb simple.frag +qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simpletextured.vert.qsb simpletextured.vert +qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simpletextured.frag.qsb simpletextured.frag +qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o textured.vert.qsb textured.vert +qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o textured.frag.qsb textured.frag diff --git a/tests/auto/gui/rhi/qrhi/data/compile.bat b/tests/auto/gui/rhi/qrhi/data/compile.bat deleted file mode 100644 index 5b8a77b833..0000000000 --- a/tests/auto/gui/rhi/qrhi/data/compile.bat +++ /dev/null @@ -1,48 +0,0 @@ -::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -:: -:: Copyright (C) 2019 The Qt Company Ltd. -:: Contact: https://www.qt.io/licensing/ -:: -:: This file is part of the QtQuick module of the Qt Toolkit. -:: -:: $QT_BEGIN_LICENSE:LGPL$ -:: Commercial License Usage -:: Licensees holding valid commercial Qt licenses may use this file in -:: accordance with the commercial license agreement provided with the -:: Software or, alternatively, in accordance with the terms contained in -:: a written agreement between you and The Qt Company. For licensing terms -:: and conditions see https://www.qt.io/terms-conditions. For further -:: information use the contact form at https://www.qt.io/contact-us. -:: -:: GNU Lesser General Public License Usage -:: Alternatively, this file may be used under the terms of the GNU Lesser -:: General Public License version 3 as published by the Free Software -:: Foundation and appearing in the file LICENSE.LGPL3 included in the -:: packaging of this file. Please review the following information to -:: ensure the GNU Lesser General Public License version 3 requirements -:: will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -:: -:: GNU General Public License Usage -:: Alternatively, this file may be used under the terms of the GNU -:: General Public License version 2.0 or (at your option) the GNU General -:: Public license version 3 or any later version approved by the KDE Free -:: Qt Foundation. The licenses are as published by the Free Software -:: Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -:: included in the packaging of this file. Please review the following -:: information to ensure the GNU General Public License requirements will -:: be met: https://www.gnu.org/licenses/gpl-2.0.html and -:: https://www.gnu.org/licenses/gpl-3.0.html. -:: -:: $QT_END_LICENSE$ -:: -::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: - -:: Note the -c argument: we do not want runtime HLSL compilation since that is -:: not an option on UWP (WinRT). This means that running qsb must happen on Windows. - -qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simple.vert.qsb simple.vert -qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simple.frag.qsb simple.frag -qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simpletextured.vert.qsb simpletextured.vert -qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simpletextured.frag.qsb simpletextured.frag -qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o textured.vert.qsb textured.vert -qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o textured.frag.qsb textured.frag diff --git a/tests/auto/gui/rhi/qrhi/data/simple.frag.qsb b/tests/auto/gui/rhi/qrhi/data/simple.frag.qsb index 264b71ec0f..c235108d39 100644 Binary files a/tests/auto/gui/rhi/qrhi/data/simple.frag.qsb and b/tests/auto/gui/rhi/qrhi/data/simple.frag.qsb differ diff --git a/tests/auto/gui/rhi/qrhi/data/simple.vert.qsb b/tests/auto/gui/rhi/qrhi/data/simple.vert.qsb index 59080b60c6..68cfeb8f1d 100644 Binary files a/tests/auto/gui/rhi/qrhi/data/simple.vert.qsb and b/tests/auto/gui/rhi/qrhi/data/simple.vert.qsb differ diff --git a/tests/auto/gui/rhi/qrhi/data/simpletextured.frag.qsb b/tests/auto/gui/rhi/qrhi/data/simpletextured.frag.qsb index f302702aa9..397961c238 100644 Binary files a/tests/auto/gui/rhi/qrhi/data/simpletextured.frag.qsb and b/tests/auto/gui/rhi/qrhi/data/simpletextured.frag.qsb differ diff --git a/tests/auto/gui/rhi/qrhi/data/simpletextured.vert.qsb b/tests/auto/gui/rhi/qrhi/data/simpletextured.vert.qsb index e4f12bfb9e..a9067949a5 100644 Binary files a/tests/auto/gui/rhi/qrhi/data/simpletextured.vert.qsb and b/tests/auto/gui/rhi/qrhi/data/simpletextured.vert.qsb differ diff --git a/tests/auto/gui/rhi/qrhi/data/textured.frag.qsb b/tests/auto/gui/rhi/qrhi/data/textured.frag.qsb index 0a039137ec..018d732e2f 100644 Binary files a/tests/auto/gui/rhi/qrhi/data/textured.frag.qsb and b/tests/auto/gui/rhi/qrhi/data/textured.frag.qsb differ diff --git a/tests/auto/gui/rhi/qrhi/data/textured.vert.qsb b/tests/auto/gui/rhi/qrhi/data/textured.vert.qsb index 7853f77943..44454d226e 100644 Binary files a/tests/auto/gui/rhi/qrhi/data/textured.vert.qsb and b/tests/auto/gui/rhi/qrhi/data/textured.vert.qsb differ diff --git a/tests/manual/rhi/computebuffer/buffer.comp.qsb b/tests/manual/rhi/computebuffer/buffer.comp.qsb index b1a666f185..6cb7e58365 100644 Binary files a/tests/manual/rhi/computebuffer/buffer.comp.qsb and b/tests/manual/rhi/computebuffer/buffer.comp.qsb differ diff --git a/tests/manual/rhi/computebuffer/main.frag.qsb b/tests/manual/rhi/computebuffer/main.frag.qsb index f05da411e5..09012b0800 100644 Binary files a/tests/manual/rhi/computebuffer/main.frag.qsb and b/tests/manual/rhi/computebuffer/main.frag.qsb differ diff --git a/tests/manual/rhi/computebuffer/main.vert.qsb b/tests/manual/rhi/computebuffer/main.vert.qsb index 944645ffbf..7eb200a3da 100644 Binary files a/tests/manual/rhi/computebuffer/main.vert.qsb and b/tests/manual/rhi/computebuffer/main.vert.qsb differ diff --git a/tests/manual/rhi/computeimage/image.comp.qsb b/tests/manual/rhi/computeimage/image.comp.qsb index 725629f7ab..41a6225063 100644 Binary files a/tests/manual/rhi/computeimage/image.comp.qsb and b/tests/manual/rhi/computeimage/image.comp.qsb differ diff --git a/tests/manual/rhi/cubemap/cubemap.frag.qsb b/tests/manual/rhi/cubemap/cubemap.frag.qsb index d7cc025554..f63e73e5cb 100644 Binary files a/tests/manual/rhi/cubemap/cubemap.frag.qsb and b/tests/manual/rhi/cubemap/cubemap.frag.qsb differ diff --git a/tests/manual/rhi/cubemap/cubemap.vert.qsb b/tests/manual/rhi/cubemap/cubemap.vert.qsb index fae136337c..39419d6e46 100644 Binary files a/tests/manual/rhi/cubemap/cubemap.vert.qsb and b/tests/manual/rhi/cubemap/cubemap.vert.qsb differ diff --git a/tests/manual/rhi/instancing/inst.frag.qsb b/tests/manual/rhi/instancing/inst.frag.qsb index f19a2f0a71..cd6b948227 100644 Binary files a/tests/manual/rhi/instancing/inst.frag.qsb and b/tests/manual/rhi/instancing/inst.frag.qsb differ diff --git a/tests/manual/rhi/instancing/inst.vert.qsb b/tests/manual/rhi/instancing/inst.vert.qsb index de05eae80f..4b891636e7 100644 Binary files a/tests/manual/rhi/instancing/inst.vert.qsb and b/tests/manual/rhi/instancing/inst.vert.qsb differ diff --git a/tests/manual/rhi/mrt/mrt.frag.qsb b/tests/manual/rhi/mrt/mrt.frag.qsb index 389b6affa3..0c83b71ee6 100644 Binary files a/tests/manual/rhi/mrt/mrt.frag.qsb and b/tests/manual/rhi/mrt/mrt.frag.qsb differ diff --git a/tests/manual/rhi/mrt/mrt.vert.qsb b/tests/manual/rhi/mrt/mrt.vert.qsb index ff8c0e50bb..ecd4a2eb71 100644 Binary files a/tests/manual/rhi/mrt/mrt.vert.qsb and b/tests/manual/rhi/mrt/mrt.vert.qsb differ diff --git a/tests/manual/rhi/shadowmap/buildshaders.sh b/tests/manual/rhi/shadowmap/buildshaders.sh deleted file mode 100755 index 8991bb074a..0000000000 --- a/tests/manual/rhi/shadowmap/buildshaders.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -qsb --glsl "120,300 es" --hlsl 50 --msl 12 shadowmap.vert -o shadowmap.vert.qsb -qsb --glsl "120,300 es" --hlsl 50 --msl 12 shadowmap.frag -o shadowmap.frag.qsb -qsb --glsl "120,300 es" --hlsl 50 --msl 12 main.vert -o main.vert.qsb -qsb --glsl "120,300 es" --hlsl 50 --msl 12 main.frag -o main.frag.qsb diff --git a/tests/manual/rhi/shadowmap/main.frag.qsb b/tests/manual/rhi/shadowmap/main.frag.qsb index 3001908b85..373c62f76d 100644 Binary files a/tests/manual/rhi/shadowmap/main.frag.qsb and b/tests/manual/rhi/shadowmap/main.frag.qsb differ diff --git a/tests/manual/rhi/shadowmap/main.vert.qsb b/tests/manual/rhi/shadowmap/main.vert.qsb index 8b81a93c00..6392d17cd6 100644 Binary files a/tests/manual/rhi/shadowmap/main.vert.qsb and b/tests/manual/rhi/shadowmap/main.vert.qsb differ diff --git a/tests/manual/rhi/shadowmap/shadowmap.frag.qsb b/tests/manual/rhi/shadowmap/shadowmap.frag.qsb index 3cad114cf4..fabeb32e65 100644 Binary files a/tests/manual/rhi/shadowmap/shadowmap.frag.qsb and b/tests/manual/rhi/shadowmap/shadowmap.frag.qsb differ diff --git a/tests/manual/rhi/shadowmap/shadowmap.vert.qsb b/tests/manual/rhi/shadowmap/shadowmap.vert.qsb index 37a5e6ecbf..f224728ff2 100644 Binary files a/tests/manual/rhi/shadowmap/shadowmap.vert.qsb and b/tests/manual/rhi/shadowmap/shadowmap.vert.qsb differ diff --git a/tests/manual/rhi/shared/color.frag.qsb b/tests/manual/rhi/shared/color.frag.qsb index 3a965682eb..51501ad5e6 100644 Binary files a/tests/manual/rhi/shared/color.frag.qsb and b/tests/manual/rhi/shared/color.frag.qsb differ diff --git a/tests/manual/rhi/shared/color.vert.qsb b/tests/manual/rhi/shared/color.vert.qsb index e34eae79a0..e342718fec 100644 Binary files a/tests/manual/rhi/shared/color.vert.qsb and b/tests/manual/rhi/shared/color.vert.qsb differ diff --git a/tests/manual/rhi/shared/texture.frag.qsb b/tests/manual/rhi/shared/texture.frag.qsb index 31bcd7105e..ad11300a59 100644 Binary files a/tests/manual/rhi/shared/texture.frag.qsb and b/tests/manual/rhi/shared/texture.frag.qsb differ diff --git a/tests/manual/rhi/shared/texture.vert.qsb b/tests/manual/rhi/shared/texture.vert.qsb index 1b9e52890d..288cce8176 100644 Binary files a/tests/manual/rhi/shared/texture.vert.qsb and b/tests/manual/rhi/shared/texture.vert.qsb differ diff --git a/tests/manual/rhi/shared/texture_ms4.frag.qsb b/tests/manual/rhi/shared/texture_ms4.frag.qsb index 7f187ce7f0..278313111b 100644 Binary files a/tests/manual/rhi/shared/texture_ms4.frag.qsb and b/tests/manual/rhi/shared/texture_ms4.frag.qsb differ -- cgit v1.2.3 From dd17456a8a69501428f3fdd2d2e25bb4286899da Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 20 Jan 2020 13:00:56 +0100 Subject: Deprecate QFont::ForceIntegerMetrics and QFont::OpenGLCompatible The ForceIntegerMetrics flag was added in Qt 4.7 specifically because of WebKit, which was rounding text metrics and getting mismatches with the underlying font engine whenever it supported fractional advances. For backwards compatibility with how the CoreText engine worked before this, we added a flag to allow rounding all metrics. Rounding advances gives very broken rendering and is hopefully not used by anyone anymore, so lets remove this flag in Qt 6. As for OpenGLCompatible, this flag is not used anywhere. I am not exactly sure what this flag did, but all fonts are "OpenGL-compatible" at this point. [ChangeLog][QtGui][QFont] Deprecated QFont::ForceIntegerMetrics and QFont::OpenGLCompatible, with the intention of removing them in Qt 6.0.0. Change-Id: I0a492c153348023f00d561bab8ab4b5104c6c7c4 Reviewed-by: Lars Knoll --- src/gui/text/qfont.cpp | 8 ++++---- src/gui/text/qfont.h | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 9ede90d8de..2e7d898a70 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -1353,8 +1353,8 @@ QFont::StyleHint QFont::styleHint() const \value NoAntialias don't antialias the fonts. \value NoSubpixelAntialias avoid subpixel antialiasing on the fonts if possible. \value PreferAntialias antialias if possible. - \value OpenGLCompatible forces the use of OpenGL compatible - fonts. + \value OpenGLCompatible This style strategy has been deprecated. All fonts are + OpenGL-compatible by default. \value NoFontMerging If the font selected for a certain writing system does not contain a character requested to draw, then Qt automatically chooses a similar looking font that contains the character. The NoFontMerging flag disables this feature. @@ -1373,8 +1373,8 @@ QFont::StyleHint QFont::styleHint() const \value PreferQuality prefer the best quality font. The font matcher will use the nearest standard point size that the font supports. - \value ForceIntegerMetrics forces the use of integer values in font engines that support fractional - font metrics. + \value ForceIntegerMetrics This style strategy has been deprecated. Use \l QFontMetrics to + retrieve rounded font metrics. */ /*! diff --git a/src/gui/text/qfont.h b/src/gui/text/qfont.h index 683aa3bf65..e5734679ed 100644 --- a/src/gui/text/qfont.h +++ b/src/gui/text/qfont.h @@ -80,8 +80,10 @@ public: PreferQuality = 0x0040, PreferAntialias = 0x0080, NoAntialias = 0x0100, - OpenGLCompatible = 0x0200, - ForceIntegerMetrics = 0x0400, +#if QT_DEPRECATED_SINCE(5, 15) + OpenGLCompatible Q_DECL_ENUMERATOR_DEPRECATED = 0x0200, + ForceIntegerMetrics Q_DECL_ENUMERATOR_DEPRECATED = 0x0400, +#endif NoSubpixelAntialias = 0x0800, PreferNoShaping = 0x1000, NoFontMerging = 0x8000 -- cgit v1.2.3 From 2b78e96d2341dc0bf53ab9ccb22cfa55bf1037e0 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 20 Jan 2020 09:41:51 +0100 Subject: QNAM: Avoid compile error if QT_NO_SSL Change-Id: Iff8a0893cc7aca172c5b3f207a359762b270ed76 Reviewed-by: Jesus Fernandez --- src/network/access/qnetworkaccessmanager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 1f05fd931f..4c2ee138ed 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -1776,6 +1776,8 @@ void QNetworkAccessManagerPrivate::_q_replyEncrypted(QNetworkReply *reply) #ifndef QT_NO_SSL Q_Q(QNetworkAccessManager); emit q->encrypted(reply); +#else + Q_UNUSED(reply); #endif } -- cgit v1.2.3 From ef14e775de9932fecea5443b976b950c311ba938 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 5 Dec 2019 09:02:21 +0100 Subject: QMenu: Move exec(), popup() to private class Task-number: QTBUG-78966 Change-Id: I69257dc52706449a1e0babfc29e5f93f63d9291b Reviewed-by: Volker Hilsheimer Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qmenu.cpp | 180 ++++++++++++++++++++++-------------------- src/widgets/widgets/qmenu_p.h | 2 + 2 files changed, 98 insertions(+), 84 deletions(-) diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 8ba5b98fa9..e3e3b07d71 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -2319,76 +2319,82 @@ QSize QMenu::sizeHint() const void QMenu::popup(const QPoint &p, QAction *atAction) { Q_D(QMenu); - if (d->scroll) { // reset scroll state from last popup - if (d->scroll->scrollOffset) - d->itemsDirty = 1; // sizeHint will be incorrect if there is previous scroll - d->scroll->scrollOffset = 0; - d->scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; + d->popup(p, atAction); +} + +void QMenuPrivate::popup(const QPoint &p, QAction *atAction) +{ + Q_Q(QMenu); + if (scroll) { // reset scroll state from last popup + if (scroll->scrollOffset) + itemsDirty = 1; // sizeHint will be incorrect if there is previous scroll + scroll->scrollOffset = 0; + scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; } - d->tearoffHighlighted = 0; - d->motions = 0; - d->doChildEffects = true; - d->updateLayoutDirection(); + tearoffHighlighted = 0; + motions = 0; + doChildEffects = true; + updateLayoutDirection(); // Ensure that we get correct sizeHints by placing this window on the correct screen. // However if the QMenu was constructed with a QDesktopScreenWidget as its parent, // then initialScreenIndex was set, so we should respect that for the lifetime of this menu. // Use d->popupScreen to remember, because initialScreenIndex will be reset after the first showing. // However if eventLoop exists, then exec() already did this by calling createWinId(); so leave it alone. (QTBUG-76162) - if (!d->eventLoop) { - const int screenIndex = d->topData()->initialScreenIndex; + if (!eventLoop) { + const int screenIndex = topData()->initialScreenIndex; if (screenIndex >= 0) - d->popupScreen = screenIndex; - if (auto s = QGuiApplication::screens().value(d->popupScreen)) { - if (d->setScreen(s)) - d->itemsDirty = true; - } else if (d->setScreenForPoint(p)) { - d->itemsDirty = true; + popupScreen = screenIndex; + if (auto s = QGuiApplication::screens().value(popupScreen)) { + if (setScreen(s)) + itemsDirty = true; + } else if (setScreenForPoint(p)) { + itemsDirty = true; } } - const bool contextMenu = d->isContextMenu(); - if (d->lastContextMenu != contextMenu) { - d->itemsDirty = true; - d->lastContextMenu = contextMenu; + const bool contextMenu = isContextMenu(); + if (lastContextMenu != contextMenu) { + itemsDirty = true; + lastContextMenu = contextMenu; } #if QT_CONFIG(menubar) // if this menu is part of a chain attached to a QMenuBar, set the // _NET_WM_WINDOW_TYPE_DROPDOWN_MENU X11 window type - setAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu, qobject_cast(d->topCausedWidget()) != 0); + q->setAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu, qobject_cast(topCausedWidget()) != nullptr); #endif - ensurePolished(); // Get the right font - emit aboutToShow(); - const bool actionListChanged = d->itemsDirty; + q->ensurePolished(); // Get the right font + emit q->aboutToShow(); + const bool actionListChanged = itemsDirty; QRect screen; #if QT_CONFIG(graphicsview) - bool isEmbedded = !bypassGraphicsProxyWidget(this) && QMenuPrivate::nearestGraphicsProxyWidget(this); + bool isEmbedded = !bypassGraphicsProxyWidget(q) && QMenuPrivate::nearestGraphicsProxyWidget(q); if (isEmbedded) - screen = d->popupGeometry(); + screen = popupGeometry(); else #endif - screen = d->popupGeometry(QDesktopWidgetPrivate::screenNumber(p)); - d->updateActionRects(screen); + screen = popupGeometry(QDesktopWidgetPrivate::screenNumber(p)); + updateActionRects(screen); QPoint pos; - QPushButton *causedButton = qobject_cast(d->causedPopup.widget); + QPushButton *causedButton = qobject_cast(causedPopup.widget); if (actionListChanged && causedButton) pos = QPushButtonPrivate::get(causedButton)->adjustedMenuPosition(); else pos = p; - const QSize menuSizeHint(sizeHint()); + const QSize menuSizeHint(q->sizeHint()); QSize size = menuSizeHint; - const int desktopFrame = style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, nullptr, this); - bool adjustToDesktop = !window()->testAttribute(Qt::WA_DontShowOnScreen); + const int desktopFrame = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, nullptr, q); + bool adjustToDesktop = !q->window()->testAttribute(Qt::WA_DontShowOnScreen); // if the screens have very different geometries and the menu is too big, we have to recalculate if ((size.height() > screen.height() || size.width() > screen.width()) || // Layout is not right, we might be able to save horizontal space - (d->ncols >1 && size.height() < screen.height())) { + (ncols >1 && size.height() < screen.height())) { size.setWidth(qMin(menuSizeHint.width(), screen.width() - desktopFrame * 2)); size.setHeight(qMin(menuSizeHint.height(), screen.height() - desktopFrame * 2)); adjustToDesktop = true; @@ -2397,61 +2403,61 @@ void QMenu::popup(const QPoint &p, QAction *atAction) #ifdef QT_KEYPAD_NAVIGATION if (!atAction && QApplicationPrivate::keypadNavigationEnabled()) { // Try to have one item activated - if (d->defaultAction && d->defaultAction->isEnabled()) { - atAction = d->defaultAction; + if (defaultAction && defaultAction->isEnabled()) { + atAction = defaultAction; // TODO: This works for first level menus, not yet sub menus } else { - for (QAction *action : qAsConst(d->actions)) + for (QAction *action : qAsConst(actions)) if (action->isEnabled()) { atAction = action; break; } } - d->currentAction = atAction; + currentAction = atAction; } #endif - if (d->ncols > 1) { + if (ncols > 1) { pos.setY(screen.top() + desktopFrame); } else if (atAction) { - for (int i = 0, above_height = 0; i < d->actions.count(); i++) { - QAction *action = d->actions.at(i); + for (int i = 0, above_height = 0; i < actions.count(); i++) { + QAction *action = actions.at(i); if (action == atAction) { int newY = pos.y() - above_height; - if (d->scroll && newY < desktopFrame) { - d->scroll->scrollFlags = d->scroll->scrollFlags + if (scroll && newY < desktopFrame) { + scroll->scrollFlags = scroll->scrollFlags | QMenuPrivate::QMenuScroller::ScrollUp; - d->scroll->scrollOffset = newY; + scroll->scrollOffset = newY; newY = desktopFrame; } pos.setY(newY); - if (d->scroll && d->scroll->scrollFlags != QMenuPrivate::QMenuScroller::ScrollNone - && !style()->styleHint(QStyle::SH_Menu_FillScreenWithScroll, nullptr, this)) { - int below_height = above_height + d->scroll->scrollOffset; - for (int i2 = i; i2 < d->actionRects.count(); i2++) - below_height += d->actionRects.at(i2).height(); + if (scroll && scroll->scrollFlags != QMenuPrivate::QMenuScroller::ScrollNone + && !q->style()->styleHint(QStyle::SH_Menu_FillScreenWithScroll, nullptr, q)) { + int below_height = above_height + scroll->scrollOffset; + for (int i2 = i; i2 < actionRects.count(); i2++) + below_height += actionRects.at(i2).height(); size.setHeight(below_height); } break; } else { - above_height += d->actionRects.at(i).height(); + above_height += actionRects.at(i).height(); } } } QPoint mouse = QCursor::pos(); - d->mousePopupPos = mouse; - const bool snapToMouse = !d->causedPopup.widget && (QRect(p.x() - 3, p.y() - 3, 6, 6).contains(mouse)); + mousePopupPos = mouse; + const bool snapToMouse = !causedPopup.widget && (QRect(p.x() - 3, p.y() - 3, 6, 6).contains(mouse)); if (adjustToDesktop) { // handle popup falling "off screen" - if (isRightToLeft()) { + if (q->isRightToLeft()) { if (snapToMouse) // position flowing left from the mouse pos.setX(mouse.x() - size.width()); #if QT_CONFIG(menubar) // if the menu is in a menubar or is a submenu, it should be right-aligned - if (qobject_cast(d->causedPopup.widget) || qobject_cast(d->causedPopup.widget)) + if (qobject_cast(causedPopup.widget) || qobject_cast(causedPopup.widget)) pos.rx() -= size.width(); #endif // QT_CONFIG(menubar) @@ -2475,8 +2481,8 @@ void QMenu::popup(const QPoint &p, QAction *atAction) if (pos.y() < screen.top() + desktopFrame) pos.setY(screen.top() + desktopFrame); if (pos.y() + menuSizeHint.height() - 1 > screen.bottom() - desktopFrame) { - if (d->scroll) { - d->scroll->scrollFlags |= uint(QMenuPrivate::QMenuScroller::ScrollDown); + if (scroll) { + scroll->scrollFlags |= uint(QMenuPrivate::QMenuScroller::ScrollDown); int y = qMax(screen.y(),pos.y()); size.setHeight(screen.bottom() - (desktopFrame * 2) - y); } else { @@ -2485,13 +2491,13 @@ void QMenu::popup(const QPoint &p, QAction *atAction) } } } - const int subMenuOffset = style()->pixelMetric(QStyle::PM_SubMenuOverlap, nullptr, this); - QMenu *caused = qobject_cast(d_func()->causedPopup.widget); + const int subMenuOffset = q->style()->pixelMetric(QStyle::PM_SubMenuOverlap, nullptr, q); + QMenu *caused = qobject_cast(causedPopup.widget); if (caused && caused->geometry().width() + menuSizeHint.width() + subMenuOffset < screen.width()) { QRect parentActionRect(caused->d_func()->actionRect(caused->d_func()->currentAction)); const QPoint actionTopLeft = caused->mapToGlobal(parentActionRect.topLeft()); parentActionRect.moveTopLeft(actionTopLeft); - if (isRightToLeft()) { + if (q->isRightToLeft()) { if ((pos.x() + menuSizeHint.width() > parentActionRect.left() - subMenuOffset) && (pos.x() < parentActionRect.right())) { @@ -2513,61 +2519,61 @@ void QMenu::popup(const QPoint &p, QAction *atAction) } } } - setGeometry(QRect(pos, size)); + q->setGeometry(QRect(pos, size)); #if QT_CONFIG(effects) - int hGuess = isRightToLeft() ? QEffects::LeftScroll : QEffects::RightScroll; + int hGuess = q->isRightToLeft() ? QEffects::LeftScroll : QEffects::RightScroll; int vGuess = QEffects::DownScroll; - if (isRightToLeft()) { + if (q->isRightToLeft()) { if ((snapToMouse && (pos.x() + size.width() / 2 > mouse.x())) || - (qobject_cast(d->causedPopup.widget) && pos.x() + size.width() / 2 > d->causedPopup.widget->x())) + (qobject_cast(causedPopup.widget) && pos.x() + size.width() / 2 > causedPopup.widget->x())) hGuess = QEffects::RightScroll; } else { if ((snapToMouse && (pos.x() + size.width() / 2 < mouse.x())) || - (qobject_cast(d->causedPopup.widget) && pos.x() + size.width() / 2 < d->causedPopup.widget->x())) + (qobject_cast(causedPopup.widget) && pos.x() + size.width() / 2 < causedPopup.widget->x())) hGuess = QEffects::LeftScroll; } #if QT_CONFIG(menubar) if ((snapToMouse && (pos.y() + size.height() / 2 < mouse.y())) || - (qobject_cast(d->causedPopup.widget) && - pos.y() + size.width() / 2 < d->causedPopup.widget->mapToGlobal(d->causedPopup.widget->pos()).y())) + (qobject_cast(causedPopup.widget) && + pos.y() + size.width() / 2 < causedPopup.widget->mapToGlobal(causedPopup.widget->pos()).y())) vGuess = QEffects::UpScroll; #endif if (QApplication::isEffectEnabled(Qt::UI_AnimateMenu)) { bool doChildEffects = true; #if QT_CONFIG(menubar) - if (QMenuBar *mb = qobject_cast(d->causedPopup.widget)) { + if (QMenuBar *mb = qobject_cast(causedPopup.widget)) { doChildEffects = mb->d_func()->doChildEffects; mb->d_func()->doChildEffects = false; } else #endif - if (QMenu *m = qobject_cast(d->causedPopup.widget)) { + if (QMenu *m = qobject_cast(causedPopup.widget)) { doChildEffects = m->d_func()->doChildEffects; m->d_func()->doChildEffects = false; } if (doChildEffects) { if (QApplication::isEffectEnabled(Qt::UI_FadeMenu)) - qFadeEffect(this); - else if (d->causedPopup.widget) - qScrollEffect(this, qobject_cast(d->causedPopup.widget) ? hGuess : vGuess); + qFadeEffect(q); + else if (causedPopup.widget) + qScrollEffect(q, qobject_cast(causedPopup.widget) ? hGuess : vGuess); else - qScrollEffect(this, hGuess | vGuess); + qScrollEffect(q, hGuess | vGuess); } else { // kill any running effect qFadeEffect(nullptr); qScrollEffect(nullptr); - show(); + q->show(); } } else #endif { - show(); + q->show(); } #ifndef QT_NO_ACCESSIBILITY - QAccessibleEvent event(this, QAccessible::PopupMenuStart); + QAccessibleEvent event(q, QAccessible::PopupMenuStart); QAccessible::updateAccessibility(&event); #endif } @@ -2633,20 +2639,26 @@ QAction *QMenu::exec() QAction *QMenu::exec(const QPoint &p, QAction *action) { Q_D(QMenu); - ensurePolished(); - createWinId(); - QEventLoop eventLoop; - d->eventLoop = &eventLoop; + return d->exec(p, action); +} + +QAction *QMenuPrivate::exec(const QPoint &p, QAction *action) +{ + Q_Q(QMenu); + q->ensurePolished(); + q->createWinId(); + QEventLoop evtLoop; + eventLoop = &evtLoop; popup(p, action); - QPointer guard = this; - (void) eventLoop.exec(); + QPointer guard = q; + (void) evtLoop.exec(); if (guard.isNull()) return nullptr; - action = d->syncAction; - d->syncAction = nullptr; - d->eventLoop = nullptr; + action = syncAction; + syncAction = nullptr; + eventLoop = nullptr; return action; } diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index efbbc099a1..7d2d0ab487 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -351,6 +351,8 @@ public: QRect popupGeometry(int screen) const; bool useFullScreenForPopup() const; int getLastVisibleAction() const; + void popup(const QPoint &p, QAction *atAction); + QAction *exec(const QPoint &p, QAction *action); //selection static QMenu *mouseDown; -- cgit v1.2.3 From a78d66743171557d79b16c08be775e3ac15bb4ef Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 5 Dec 2019 09:33:50 +0100 Subject: Fix positioning of dynamically populated QToolButton::MenuButtonPopup's in screen corners The existing code positioning the menu in QToolButtonPrivate::popupTimerDone() had a clause checking whether any receivers were connnected to QMenu::aboutToShow() causing the sizeHint to be -1,-1 in that case (apparently trying to accommodate menus populated in slots). In that case, the checking for screen borders would not work, causing the similar checks in QMenu::popup() to trigger, potentially positioning the menu over the mouse. To solve this dilemma, add a parameter taking a std::function calulating the position of the menu from the sizeHint to QMenuPrivate::exec()/popup() and invoke that in QMenuPrivate::popup() after emitting QMenu::aboutToShow() when the sizeHint is known. Fixes: QTBUG-78966 Change-Id: I180bd2dc7eadcaca6cadca13745ed4a2dd89e412 Reviewed-by: Volker Hilsheimer --- src/widgets/widgets/qmenu.cpp | 10 ++++-- src/widgets/widgets/qmenu_p.h | 8 +++-- src/widgets/widgets/qtoolbutton.cpp | 67 +++++++++++++++++++++---------------- 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index e3e3b07d71..701035fc32 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -2322,7 +2322,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction) d->popup(p, atAction); } -void QMenuPrivate::popup(const QPoint &p, QAction *atAction) +void QMenuPrivate::popup(const QPoint &p, QAction *atAction, PositionFunction positionFunction) { Q_Q(QMenu); if (scroll) { // reset scroll state from last popup @@ -2388,6 +2388,10 @@ void QMenuPrivate::popup(const QPoint &p, QAction *atAction) const QSize menuSizeHint(q->sizeHint()); QSize size = menuSizeHint; + + if (positionFunction) + pos = positionFunction(menuSizeHint); + const int desktopFrame = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, nullptr, q); bool adjustToDesktop = !q->window()->testAttribute(Qt::WA_DontShowOnScreen); @@ -2642,14 +2646,14 @@ QAction *QMenu::exec(const QPoint &p, QAction *action) return d->exec(p, action); } -QAction *QMenuPrivate::exec(const QPoint &p, QAction *action) +QAction *QMenuPrivate::exec(const QPoint &p, QAction *action, PositionFunction positionFunction) { Q_Q(QMenu); q->ensurePolished(); q->createWinId(); QEventLoop evtLoop; eventLoop = &evtLoop; - popup(p, action); + popup(p, action, positionFunction); QPointer guard = q; (void) evtLoop.exec(); diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 7d2d0ab487..02fe9f31a1 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -64,6 +64,8 @@ #include +#include + QT_REQUIRE_CONFIG(menu); QT_BEGIN_NAMESPACE @@ -302,6 +304,8 @@ class QMenuPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QMenu) public: + using PositionFunction = std::function; + QMenuPrivate() : itemsDirty(false), hasCheckableItems(false), @@ -351,8 +355,8 @@ public: QRect popupGeometry(int screen) const; bool useFullScreenForPopup() const; int getLastVisibleAction() const; - void popup(const QPoint &p, QAction *atAction); - QAction *exec(const QPoint &p, QAction *action); + void popup(const QPoint &p, QAction *atAction, PositionFunction positionFunction = {}); + QAction *exec(const QPoint &p, QAction *action, PositionFunction positionFunction = {}); //selection static QMenu *mouseDown; diff --git a/src/widgets/widgets/qtoolbutton.cpp b/src/widgets/widgets/qtoolbutton.cpp index 263fe5d8ce..314c6ab40c 100644 --- a/src/widgets/widgets/qtoolbutton.cpp +++ b/src/widgets/widgets/qtoolbutton.cpp @@ -723,38 +723,12 @@ void QToolButtonPrivate::_q_buttonReleased() popupTimer.stop(); } -void QToolButtonPrivate::popupTimerDone() +static QPoint positionMenu(const QToolButton *q, bool horizontal, + const QSize &sh) { - Q_Q(QToolButton); - popupTimer.stop(); - if (!menuButtonDown && !down) - return; - - menuButtonDown = true; - QPointer actualMenu; - bool mustDeleteActualMenu = false; - if(menuAction) { - actualMenu = menuAction->menu(); - } else if (defaultAction && defaultAction->menu()) { - actualMenu = defaultAction->menu(); - } else { - actualMenu = new QMenu(q); - mustDeleteActualMenu = true; - for(int i = 0; i < actions.size(); i++) - actualMenu->addAction(actions.at(i)); - } - repeat = q->autoRepeat(); - q->setAutoRepeat(false); - bool horizontal = true; -#if QT_CONFIG(toolbar) - QToolBar *tb = qobject_cast(parent); - if (tb && tb->orientation() == Qt::Vertical) - horizontal = false; -#endif QPoint p; const QRect rect = q->rect(); // Find screen via point in case of QGraphicsProxyWidget. QRect screen = QDesktopWidgetPrivate::availableGeometry(q->mapToGlobal(rect.center())); - QSize sh = ((QToolButton*)(QMenu*)actualMenu)->receivers(SIGNAL(aboutToShow()))? QSize() : actualMenu->sizeHint(); if (horizontal) { if (q->isRightToLeft()) { if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.bottom()) { @@ -788,6 +762,37 @@ void QToolButtonPrivate::popupTimerDone() } p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width())); p.ry() += 1; + return p; +} + +void QToolButtonPrivate::popupTimerDone() +{ + Q_Q(QToolButton); + popupTimer.stop(); + if (!menuButtonDown && !down) + return; + + menuButtonDown = true; + QPointer actualMenu; + bool mustDeleteActualMenu = false; + if (menuAction) { + actualMenu = menuAction->menu(); + } else if (defaultAction && defaultAction->menu()) { + actualMenu = defaultAction->menu(); + } else { + actualMenu = new QMenu(q); + mustDeleteActualMenu = true; + for (int i = 0; i < actions.size(); i++) + actualMenu->addAction(actions.at(i)); + } + repeat = q->autoRepeat(); + q->setAutoRepeat(false); + bool horizontal = true; +#if QT_CONFIG(toolbar) + QToolBar *tb = qobject_cast(parent); + if (tb && tb->orientation() == Qt::Vertical) + horizontal = false; +#endif QPointer that = q; actualMenu->setNoReplayFor(q); if (!mustDeleteActualMenu) //only if action are not in this widget @@ -796,7 +801,11 @@ void QToolButtonPrivate::popupTimerDone() actualMenu->d_func()->causedPopup.widget = q; actualMenu->d_func()->causedPopup.action = defaultAction; actionsCopy = q->actions(); //(the list of action may be modified in slots) - actualMenu->exec(p); + + // QTBUG-78966, Delay positioning until after aboutToShow(). + auto positionFunction = [q, horizontal](const QSize &sizeHint) { + return positionMenu(q, horizontal, sizeHint); }; + actualMenu->d_func()->exec({}, nullptr, positionFunction); if (!that) return; -- cgit v1.2.3 From 73d1476fb1397948a4d806bd921fce372bd8d63b Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 2 Dec 2019 17:54:48 +0100 Subject: Replace most use of QVariant::type and occurrences of QVariant::Type I made a clazy automated check that replaced the use of QVariant::Type by the equivalent in QMetaType. This has been deprecated since Qt 5.0, but many uses were not yet removed. In addition, there was some manual changes to fix the compilation errors. Adapted the Private API of QDateTimeParser and QMimeDataPrivate and adjust QDateTimeEdit and QSpinBox. QVariant(QVariant::Invalid) in qstylesheet made no sense. But note that in QVariant::save, we actually wanted to use the non-user type. In the SQL module, many changes were actually reverted because the API still expects QVarient::Type. Change-Id: I98c368490e4ee465ed3a3b63bda8b8eaa50ea67e Reviewed-by: Lars Knoll --- .../serialization/convert/cborconverter.cpp | 4 +- .../serialization/convert/datastreamconverter.cpp | 6 +- .../serialization/convert/textconverter.cpp | 6 +- .../corelib/serialization/convert/xmlconverter.cpp | 20 +- examples/network/torrent/trackerclient.cpp | 2 +- .../itemviews/coloreditorfactory/window.cpp | 2 +- .../mysortfilterproxymodel.cpp | 2 +- .../widgets/tools/settingseditor/settingstree.cpp | 2 +- .../tools/settingseditor/variantdelegate.cpp | 132 +++--- .../widgets/tools/settingseditor/variantdelegate.h | 2 +- src/corelib/animation/qpropertyanimation.cpp | 6 +- src/corelib/io/qsettings.cpp | 34 +- src/corelib/itemmodels/qabstractitemmodel.cpp | 40 +- src/corelib/kernel/qmetaobject.cpp | 12 +- src/corelib/kernel/qmimedata.cpp | 72 +-- src/corelib/kernel/qvariant.cpp | 492 ++++++++++----------- src/corelib/kernel/qvariant_p.h | 4 +- src/corelib/serialization/qjsoncbor.cpp | 38 +- src/corelib/serialization/qjsondocument.cpp | 10 +- src/corelib/serialization/qjsonvalue.cpp | 26 +- src/corelib/text/qlocale.cpp | 6 +- src/corelib/text/qlocale_unix.cpp | 12 +- src/corelib/time/qdatetime.cpp | 6 +- src/corelib/time/qdatetimeparser.cpp | 24 +- src/corelib/time/qdatetimeparser_p.h | 4 +- src/dbus/qdbusabstractinterface.cpp | 2 +- src/dbus/qdbusargument.h | 4 +- src/dbus/qdbusintegrator.cpp | 4 +- src/dbus/qdbusinterface.cpp | 18 +- src/dbus/qdbusmarshaller.cpp | 10 +- src/dbus/qdbusmessage.cpp | 2 +- src/dbus/qdbusmetaobject.cpp | 20 +- src/dbus/qdbusmetatype.cpp | 38 +- src/dbus/qdbusutil.cpp | 8 +- src/dbus/qdbusxmlgenerator.cpp | 6 +- src/gui/image/qbitmap.cpp | 2 +- src/gui/image/qicon.cpp | 2 +- src/gui/image/qimage.cpp | 2 +- src/gui/image/qpixmap.cpp | 2 +- src/gui/itemmodels/qstandarditemmodel.cpp | 2 +- src/gui/kernel/qcursor.cpp | 2 +- src/gui/kernel/qguivariant.cpp | 62 +-- src/gui/kernel/qinternalmimedata.cpp | 13 +- src/gui/kernel/qkeysequence.cpp | 2 +- src/gui/kernel/qpalette.cpp | 2 +- src/gui/math3d/qmatrix4x4.cpp | 2 +- src/gui/math3d/qquaternion.cpp | 2 +- src/gui/math3d/qvector2d.cpp | 2 +- src/gui/math3d/qvector3d.cpp | 2 +- src/gui/math3d/qvector4d.cpp | 2 +- src/gui/painting/qbrush.cpp | 2 +- src/gui/painting/qcolor.cpp | 2 +- src/gui/painting/qmatrix.cpp | 2 +- src/gui/painting/qpen.cpp | 2 +- src/gui/painting/qpolygon.cpp | 2 +- src/gui/painting/qregion.cpp | 2 +- src/gui/painting/qtransform.cpp | 2 +- src/gui/text/qcssparser.cpp | 20 +- src/gui/text/qfont.cpp | 2 +- src/gui/text/qplatformfontdatabase.cpp | 2 +- src/gui/text/qtextdocument.cpp | 6 +- src/gui/text/qtextdocumentlayout.cpp | 2 +- src/gui/text/qtextformat.cpp | 52 +-- src/gui/text/qtexthtmlparser.cpp | 12 +- src/gui/text/qtextimagehandler.cpp | 8 +- src/gui/text/qtextodfwriter.cpp | 4 +- .../accessibility/qaccessiblebridgeutils.cpp | 2 +- .../linuxaccessibility/atspiadaptor.cpp | 2 +- .../themes/genericunix/qgenericunixthemes.cpp | 2 +- src/plugins/generic/tuiotouch/qtuiohandler.cpp | 40 +- src/plugins/platforms/xcb/qxcbclipboard.cpp | 3 +- src/plugins/platforms/xcb/qxcbdrag.cpp | 6 +- src/plugins/platforms/xcb/qxcbmime.cpp | 8 +- src/plugins/platforms/xcb/qxcbmime.h | 4 +- src/plugins/sqldrivers/ibase/qsql_ibase.cpp | 4 +- src/plugins/sqldrivers/mysql/qsql_mysql.cpp | 116 ++--- src/plugins/sqldrivers/odbc/qsql_odbc.cpp | 6 +- src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp | 2 +- src/sql/kernel/qsqldriver.cpp | 22 +- src/sql/kernel/qsqlfield.cpp | 11 +- src/sql/kernel/qsqlfield.h | 2 +- src/sql/kernel/qsqlresult.cpp | 4 +- src/testlib/qtest.h | 2 +- src/testlib/qtestlog.cpp | 4 +- src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp | 6 +- src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp | 2 +- src/widgets/dialogs/qsidebar.cpp | 2 +- src/widgets/graphicsview/qgraphicsitem.cpp | 8 +- src/widgets/graphicsview/qgraphicsproxywidget.cpp | 10 +- src/widgets/graphicsview/qgraphicsscene.cpp | 8 +- src/widgets/graphicsview/qgraphicsview.cpp | 8 +- src/widgets/itemviews/qabstractitemdelegate.cpp | 18 +- src/widgets/itemviews/qabstractitemview.cpp | 2 +- src/widgets/itemviews/qheaderview.cpp | 2 +- src/widgets/itemviews/qitemdelegate.cpp | 22 +- src/widgets/itemviews/qitemeditorfactory.cpp | 34 +- src/widgets/itemviews/qstyleditemdelegate.cpp | 10 +- src/widgets/kernel/qsizepolicy.cpp | 2 +- src/widgets/kernel/qwidgetsvariant.cpp | 12 +- src/widgets/styles/qstylesheetstyle.cpp | 31 +- src/widgets/widgets/qabstractspinbox.cpp | 70 +-- src/widgets/widgets/qabstractspinbox_p.h | 2 +- src/widgets/widgets/qcombobox.cpp | 8 +- src/widgets/widgets/qdatetimeedit.cpp | 32 +- src/widgets/widgets/qdatetimeedit.h | 3 + src/widgets/widgets/qplaintextedit.cpp | 20 +- src/widgets/widgets/qspinbox.cpp | 4 +- src/widgets/widgets/qtextbrowser.cpp | 4 +- src/widgets/widgets/qtextedit.cpp | 24 +- 109 files changed, 947 insertions(+), 936 deletions(-) diff --git a/examples/corelib/serialization/convert/cborconverter.cpp b/examples/corelib/serialization/convert/cborconverter.cpp index 60410ed26a..77df367e50 100644 --- a/examples/corelib/serialization/convert/cborconverter.cpp +++ b/examples/corelib/serialization/convert/cborconverter.cpp @@ -134,7 +134,7 @@ static QVariant convertCborValue(const QCborValue &value) enum TrimFloatingPoint { Double, Float, Float16 }; static QCborValue convertFromVariant(const QVariant &v, TrimFloatingPoint fpTrimming) { - if (v.userType() == QVariant::List) { + if (v.userType() == QMetaType::QVariantList) { const QVariantList list = v.toList(); QCborArray array; for (const QVariant &v : list) @@ -152,7 +152,7 @@ static QCborValue convertFromVariant(const QVariant &v, TrimFloatingPoint fpTrim return map; } - if (v.userType() == QVariant::Double && fpTrimming != Double) { + if (v.userType() == QMetaType::Double && fpTrimming != Double) { float f = float(v.toDouble()); if (fpTrimming == Float16) return float(qfloat16(f)); diff --git a/examples/corelib/serialization/convert/datastreamconverter.cpp b/examples/corelib/serialization/convert/datastreamconverter.cpp index 7e9f5e1bdc..6f0ca41ff5 100644 --- a/examples/corelib/serialization/convert/datastreamconverter.cpp +++ b/examples/corelib/serialization/convert/datastreamconverter.cpp @@ -96,8 +96,8 @@ static QString dumpVariant(const QVariant &v, const QString &indent = QLatin1Str QString indented = indent + QLatin1String(" "); int type = v.userType(); - if (type == qMetaTypeId() || type == QVariant::Map) { - const auto map = (type == QVariant::Map) ? + if (type == qMetaTypeId() || type == QMetaType::QVariantMap) { + const auto map = (type == QMetaType::QVariantMap) ? VariantOrderedMap(v.toMap()) : qvariant_cast(v); result = QLatin1String("Map {"); @@ -109,7 +109,7 @@ static QString dumpVariant(const QVariant &v, const QString &indent = QLatin1Str } result.chop(1); // remove comma result += indent + QLatin1String("},"); - } else if (type == QVariant::List) { + } else if (type == QMetaType::QVariantList) { const QVariantList list = v.toList(); result = QLatin1String("List ["); diff --git a/examples/corelib/serialization/convert/textconverter.cpp b/examples/corelib/serialization/convert/textconverter.cpp index 7aed08f96c..ae03b9a334 100644 --- a/examples/corelib/serialization/convert/textconverter.cpp +++ b/examples/corelib/serialization/convert/textconverter.cpp @@ -56,21 +56,21 @@ static void dumpVariant(QTextStream &out, const QVariant &v) { switch (v.userType()) { - case QVariant::List: { + case QMetaType::QVariantList: { const QVariantList list = v.toList(); for (const QVariant &item : list) dumpVariant(out, item); break; } - case QVariant::String: { + case QMetaType::QString: { const QStringList list = v.toStringList(); for (const QString &s : list) out << s << Qt::endl; break; } - case QVariant::Map: { + case QMetaType::QVariantMap: { const QVariantMap map = v.toMap(); for (auto it = map.begin(); it != map.end(); ++it) { out << it.key() << " => "; diff --git a/examples/corelib/serialization/convert/xmlconverter.cpp b/examples/corelib/serialization/convert/xmlconverter.cpp index d9e724dfe1..42cb10100a 100644 --- a/examples/corelib/serialization/convert/xmlconverter.cpp +++ b/examples/corelib/serialization/convert/xmlconverter.cpp @@ -284,18 +284,18 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options ba.resize(n); result = ba; } else { - int id = QVariant::Invalid; + int id = QMetaType::UnknownType; if (type == QLatin1String("datetime")) - id = QVariant::DateTime; + id = QMetaType::QDateTime; else if (type == QLatin1String("url")) - id = QVariant::Url; + id = QMetaType::QUrl; else if (type == QLatin1String("uuid")) - id = QVariant::Uuid; + id = QMetaType::QUuid; else if (type == QLatin1String("regex")) - id = QVariant::RegularExpression; + id = QMetaType::QRegularExpression; else id = QMetaType::type(type.toLatin1()); - if (id == QVariant::Invalid) { + if (id == QMetaType::UnknownType) { fprintf(stderr, "%lld:%lld: Invalid XML: unknown type '%s'.\n", xml.lineNumber(), xml.columnNumber(), qPrintable(type.toString())); exit(EXIT_FAILURE); @@ -327,14 +327,14 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options static void variantToXml(QXmlStreamWriter &xml, const QVariant &v) { int type = v.userType(); - if (type == QVariant::List) { + if (type == QMetaType::QVariantList) { QVariantList list = v.toList(); xml.writeStartElement("list"); for (const QVariant &v : list) variantToXml(xml, v); xml.writeEndElement(); - } else if (type == QVariant::Map || type == qMetaTypeId()) { - const VariantOrderedMap map = (type == QVariant::Map) ? + } else if (type == QMetaType::QVariantMap || type == qMetaTypeId()) { + const VariantOrderedMap map = (type == QMetaType::QVariantMap) ? VariantOrderedMap(v.toMap()) : qvariant_cast(v); @@ -433,7 +433,7 @@ static void variantToXml(QXmlStreamWriter &xml, const QVariant &v) // does this convert to string? const char *typeName = v.typeName(); QVariant copy = v; - if (copy.convert(QVariant::String)) { + if (copy.convert(QMetaType::QString)) { xml.writeAttribute(typeString, QString::fromLatin1(typeName)); xml.writeCharacters(copy.toString()); } else { diff --git a/examples/network/torrent/trackerclient.cpp b/examples/network/torrent/trackerclient.cpp index 540ab31557..a50a49fd64 100644 --- a/examples/network/torrent/trackerclient.cpp +++ b/examples/network/torrent/trackerclient.cpp @@ -209,7 +209,7 @@ void TrackerClient::httpRequestDone(QNetworkReply *reply) // store it peers.clear(); QVariant peerEntry = dict.value("peers"); - if (peerEntry.type() == QVariant::List) { + if (peerEntry.userType() == QMetaType::QVariantList) { QList peerTmp = peerEntry.toList(); for (int i = 0; i < peerTmp.size(); ++i) { TorrentPeer tmp; diff --git a/examples/widgets/itemviews/coloreditorfactory/window.cpp b/examples/widgets/itemviews/coloreditorfactory/window.cpp index e4a9379d8f..25e196a80c 100644 --- a/examples/widgets/itemviews/coloreditorfactory/window.cpp +++ b/examples/widgets/itemviews/coloreditorfactory/window.cpp @@ -61,7 +61,7 @@ Window::Window() QItemEditorCreatorBase *colorListCreator = new QStandardItemEditorCreator(); - factory->registerEditor(QVariant::Color, colorListCreator); + factory->registerEditor(QMetaType::QColor, colorListCreator); QItemEditorFactory::setDefaultFactory(factory); diff --git a/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp index 4753d04d9b..b0b4017e62 100644 --- a/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp +++ b/examples/widgets/itemviews/customsortfiltermodel/mysortfilterproxymodel.cpp @@ -98,7 +98,7 @@ bool MySortFilterProxyModel::lessThan(const QModelIndex &left, //! [4] //! [6] - if (leftData.type() == QVariant::DateTime) { + if (leftData.userType() == QMetaType::QDateTime) { return leftData.toDateTime() < rightData.toDateTime(); } else { static const QRegularExpression emailPattern("[\\w\\.]*@[\\w\\.]*"); diff --git a/examples/widgets/tools/settingseditor/settingstree.cpp b/examples/widgets/tools/settingseditor/settingstree.cpp index 49d299bf72..9132368e4a 100644 --- a/examples/widgets/tools/settingseditor/settingstree.cpp +++ b/examples/widgets/tools/settingseditor/settingstree.cpp @@ -208,7 +208,7 @@ void SettingsTree::updateChildItems(QTreeWidgetItem *parent) } QVariant value = settings->value(key); - if (value.type() == QVariant::Invalid) { + if (value.userType() == QMetaType::UnknownType) { child->setText(1, "Invalid"); } else { child->setText(1, value.typeName()); diff --git a/examples/widgets/tools/settingseditor/variantdelegate.cpp b/examples/widgets/tools/settingseditor/variantdelegate.cpp index 9772fe8a41..eb822f0dc2 100644 --- a/examples/widgets/tools/settingseditor/variantdelegate.cpp +++ b/examples/widgets/tools/settingseditor/variantdelegate.cpp @@ -81,7 +81,7 @@ void VariantDelegate::paint(QPainter *painter, { if (index.column() == 2) { QVariant value = index.model()->data(index, Qt::UserRole); - if (!isSupportedType(value.type())) { + if (!isSupportedType(value.userType())) { QStyleOptionViewItem myOption = option; myOption.state &= ~QStyle::State_Enabled; QStyledItemDelegate::paint(painter, myOption, index); @@ -100,7 +100,7 @@ QWidget *VariantDelegate::createEditor(QWidget *parent, return nullptr; QVariant originalValue = index.model()->data(index, Qt::UserRole); - if (!isSupportedType(originalValue.type())) + if (!isSupportedType(originalValue.userType())) return nullptr; QLineEdit *lineEdit = new QLineEdit(parent); @@ -108,46 +108,46 @@ QWidget *VariantDelegate::createEditor(QWidget *parent, QRegularExpression regExp; - switch (originalValue.type()) { - case QVariant::Bool: + switch (originalValue.userType()) { + case QMetaType::Bool: regExp = boolExp; break; - case QVariant::ByteArray: + case QMetaType::QByteArray: regExp = byteArrayExp; break; - case QVariant::Char: + case QMetaType::QChar: regExp = charExp; break; - case QVariant::Color: + case QMetaType::QColor: regExp = colorExp; break; - case QVariant::Date: + case QMetaType::QDate: regExp = dateExp; break; - case QVariant::DateTime: + case QMetaType::QDateTime: regExp = dateTimeExp; break; - case QVariant::Double: + case QMetaType::Double: regExp = doubleExp; break; - case QVariant::Int: - case QVariant::LongLong: + case QMetaType::Int: + case QMetaType::LongLong: regExp = signedIntegerExp; break; - case QVariant::Point: + case QMetaType::QPoint: regExp = pointExp; break; - case QVariant::Rect: + case QMetaType::QRect: regExp = rectExp; break; - case QVariant::Size: + case QMetaType::QSize: regExp = sizeExp; break; - case QVariant::Time: + case QMetaType::QTime: regExp = timeExp; break; - case QVariant::UInt: - case QVariant::ULongLong: + case QMetaType::UInt: + case QMetaType::ULongLong: regExp = unsignedIntegerExp; break; default: @@ -189,18 +189,18 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, QVariant value; QRegularExpressionMatch match; - switch (originalValue.type()) { - case QVariant::Char: + switch (originalValue.userType()) { + case QMetaType::QChar: value = text.at(0); break; - case QVariant::Color: + case QMetaType::QColor: match = colorExp.match(text); value = QColor(qMin(match.captured(1).toInt(), 255), qMin(match.captured(2).toInt(), 255), qMin(match.captured(3).toInt(), 255), qMin(match.captured(4).toInt(), 255)); break; - case QVariant::Date: + case QMetaType::QDate: { QDate date = QDate::fromString(text, Qt::ISODate); if (!date.isValid()) @@ -208,7 +208,7 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, value = date; } break; - case QVariant::DateTime: + case QMetaType::QDateTime: { QDateTime dateTime = QDateTime::fromString(text, Qt::ISODate); if (!dateTime.isValid()) @@ -216,23 +216,23 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, value = dateTime; } break; - case QVariant::Point: + case QMetaType::QPoint: match = pointExp.match(text); value = QPoint(match.captured(1).toInt(), match.captured(2).toInt()); break; - case QVariant::Rect: + case QMetaType::QRect: match = rectExp.match(text); value = QRect(match.captured(1).toInt(), match.captured(2).toInt(), match.captured(3).toInt(), match.captured(4).toInt()); break; - case QVariant::Size: + case QMetaType::QSize: match = sizeExp.match(text); value = QSize(match.captured(1).toInt(), match.captured(2).toInt()); break; - case QVariant::StringList: + case QMetaType::QStringList: value = text.split(','); break; - case QVariant::Time: + case QMetaType::QTime: { QTime time = QTime::fromString(text, Qt::ISODate); if (!time.isValid()) @@ -242,33 +242,33 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, break; default: value = text; - value.convert(originalValue.type()); + value.convert(originalValue.userType()); } model->setData(index, displayText(value), Qt::DisplayRole); model->setData(index, value, Qt::UserRole); } -bool VariantDelegate::isSupportedType(QVariant::Type type) +bool VariantDelegate::isSupportedType(int type) { switch (type) { - case QVariant::Bool: - case QVariant::ByteArray: - case QVariant::Char: - case QVariant::Color: - case QVariant::Date: - case QVariant::DateTime: - case QVariant::Double: - case QVariant::Int: - case QVariant::LongLong: - case QVariant::Point: - case QVariant::Rect: - case QVariant::Size: - case QVariant::String: - case QVariant::StringList: - case QVariant::Time: - case QVariant::UInt: - case QVariant::ULongLong: + case QMetaType::Bool: + case QMetaType::QByteArray: + case QMetaType::QChar: + case QMetaType::QColor: + case QMetaType::QDate: + case QMetaType::QDateTime: + case QMetaType::Double: + case QMetaType::Int: + case QMetaType::LongLong: + case QMetaType::QPoint: + case QMetaType::QRect: + case QMetaType::QSize: + case QMetaType::QString: + case QMetaType::QStringList: + case QMetaType::QTime: + case QMetaType::UInt: + case QMetaType::ULongLong: return true; default: return false; @@ -277,50 +277,50 @@ bool VariantDelegate::isSupportedType(QVariant::Type type) QString VariantDelegate::displayText(const QVariant &value) { - switch (value.type()) { - case QVariant::Bool: - case QVariant::ByteArray: - case QVariant::Char: - case QVariant::Double: - case QVariant::Int: - case QVariant::LongLong: - case QVariant::String: - case QVariant::UInt: - case QVariant::ULongLong: + switch (value.userType()) { + case QMetaType::Bool: + case QMetaType::QByteArray: + case QMetaType::QChar: + case QMetaType::Double: + case QMetaType::Int: + case QMetaType::LongLong: + case QMetaType::QString: + case QMetaType::UInt: + case QMetaType::ULongLong: return value.toString(); - case QVariant::Color: + case QMetaType::QColor: { QColor color = qvariant_cast(value); return QString("(%1,%2,%3,%4)") .arg(color.red()).arg(color.green()) .arg(color.blue()).arg(color.alpha()); } - case QVariant::Date: + case QMetaType::QDate: return value.toDate().toString(Qt::ISODate); - case QVariant::DateTime: + case QMetaType::QDateTime: return value.toDateTime().toString(Qt::ISODate); - case QVariant::Invalid: + case QMetaType::UnknownType: return ""; - case QVariant::Point: + case QMetaType::QPoint: { QPoint point = value.toPoint(); return QString("(%1,%2)").arg(point.x()).arg(point.y()); } - case QVariant::Rect: + case QMetaType::QRect: { QRect rect = value.toRect(); return QString("(%1,%2,%3,%4)") .arg(rect.x()).arg(rect.y()) .arg(rect.width()).arg(rect.height()); } - case QVariant::Size: + case QMetaType::QSize: { QSize size = value.toSize(); return QString("(%1,%2)").arg(size.width()).arg(size.height()); } - case QVariant::StringList: + case QMetaType::QStringList: return value.toStringList().join(','); - case QVariant::Time: + case QMetaType::QTime: return value.toTime().toString(Qt::ISODate); default: break; diff --git a/examples/widgets/tools/settingseditor/variantdelegate.h b/examples/widgets/tools/settingseditor/variantdelegate.h index 68f21fa3f6..96e44fd181 100644 --- a/examples/widgets/tools/settingseditor/variantdelegate.h +++ b/examples/widgets/tools/settingseditor/variantdelegate.h @@ -69,7 +69,7 @@ public: void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; - static bool isSupportedType(QVariant::Type type); + static bool isSupportedType(int type); static QString displayText(const QVariant &value); private: diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp index c71a77e073..d014b5c441 100644 --- a/src/corelib/animation/qpropertyanimation.cpp +++ b/src/corelib/animation/qpropertyanimation.cpp @@ -92,7 +92,7 @@ QT_BEGIN_NAMESPACE void QPropertyAnimationPrivate::updateMetaProperty() { if (!target || propertyName.isEmpty()) { - propertyType = QVariant::Invalid; + propertyType = QMetaType::UnknownType; propertyIndex = -1; return; } @@ -102,11 +102,11 @@ void QPropertyAnimationPrivate::updateMetaProperty() propertyType = targetValue->property(propertyName).userType(); propertyIndex = targetValue->metaObject()->indexOfProperty(propertyName); - if (propertyType != QVariant::Invalid) + if (propertyType != QMetaType::UnknownType) convertValues(propertyType); if (propertyIndex == -1) { //there is no Q_PROPERTY on the object - propertyType = QVariant::Invalid; + propertyType = QMetaType::UnknownType; if (!targetValue->dynamicPropertyNames().contains(propertyName)) qWarning("QPropertyAnimation: you're trying to animate a non-existing property %s of your QObject", propertyName.constData()); } else if (!targetValue->metaObject()->property(propertyIndex).isWritable()) { diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 9fc45e307d..b191397e7e 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -396,12 +396,12 @@ QString QSettingsPrivate::variantToString(const QVariant &v) { QString result; - switch (v.type()) { - case QVariant::Invalid: + switch (v.userType()) { + case QMetaType::UnknownType: result = QLatin1String("@Invalid()"); break; - case QVariant::ByteArray: { + case QMetaType::QByteArray: { QByteArray a = v.toByteArray(); result = QLatin1String("@ByteArray(") + QLatin1String(a.constData(), a.size()) @@ -409,14 +409,14 @@ QString QSettingsPrivate::variantToString(const QVariant &v) break; } - case QVariant::String: - case QVariant::LongLong: - case QVariant::ULongLong: - case QVariant::Int: - case QVariant::UInt: - case QVariant::Bool: - case QVariant::Double: - case QVariant::KeySequence: { + case QMetaType::QString: + case QMetaType::LongLong: + case QMetaType::ULongLong: + case QMetaType::Int: + case QMetaType::UInt: + case QMetaType::Bool: + case QMetaType::Double: + case QMetaType::QKeySequence: { result = v.toString(); if (result.contains(QChar::Null)) result = QLatin1String("@String(") + result + QLatin1Char(')'); @@ -425,17 +425,17 @@ QString QSettingsPrivate::variantToString(const QVariant &v) break; } #ifndef QT_NO_GEOM_VARIANT - case QVariant::Rect: { + case QMetaType::QRect: { QRect r = qvariant_cast(v); result = QString::asprintf("@Rect(%d %d %d %d)", r.x(), r.y(), r.width(), r.height()); break; } - case QVariant::Size: { + case QMetaType::QSize: { QSize s = qvariant_cast(v); result = QString::asprintf("@Size(%d %d)", s.width(), s.height()); break; } - case QVariant::Point: { + case QMetaType::QPoint: { QPoint p = qvariant_cast(v); result = QString::asprintf("@Point(%d %d)", p.x(), p.y()); break; @@ -446,7 +446,7 @@ QString QSettingsPrivate::variantToString(const QVariant &v) #ifndef QT_NO_DATASTREAM QDataStream::Version version; const char *typeSpec; - if (v.type() == QVariant::DateTime) { + if (v.userType() == QMetaType::QDateTime) { version = QDataStream::Qt_5_6; typeSpec = "@DateTime("; } else { @@ -1888,8 +1888,8 @@ bool QConfFileSettingsPrivate::writeIniFile(QIODevice &device, const ParsedSetti QVariant(QString("foo")).toList() returns an empty list, not a list containing "foo". */ - if (value.type() == QVariant::StringList - || (value.type() == QVariant::List && value.toList().size() != 1)) { + if (value.userType() == QMetaType::QStringList + || (value.userType() == QMetaType::QVariantList && value.toList().size() != 1)) { iniEscapedStringList(variantListToStringList(value.toList()), block, iniCodec); } else { iniEscapedString(variantToString(value), block, iniCodec); diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 46ac703615..608407c136 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -552,32 +552,32 @@ const QHash &QAbstractItemModelPrivate::defaultRoleNames() bool QAbstractItemModelPrivate::isVariantLessThan(const QVariant &left, const QVariant &right, Qt::CaseSensitivity cs, bool isLocaleAware) { - if (left.userType() == QVariant::Invalid) + if (left.userType() == QMetaType::UnknownType) return false; - if (right.userType() == QVariant::Invalid) + if (right.userType() == QMetaType::UnknownType) return true; switch (left.userType()) { - case QVariant::Int: + case QMetaType::Int: return left.toInt() < right.toInt(); - case QVariant::UInt: + case QMetaType::UInt: return left.toUInt() < right.toUInt(); - case QVariant::LongLong: + case QMetaType::LongLong: return left.toLongLong() < right.toLongLong(); - case QVariant::ULongLong: + case QMetaType::ULongLong: return left.toULongLong() < right.toULongLong(); case QMetaType::Float: return left.toFloat() < right.toFloat(); - case QVariant::Double: + case QMetaType::Double: return left.toDouble() < right.toDouble(); - case QVariant::Char: + case QMetaType::QChar: return left.toChar() < right.toChar(); - case QVariant::Date: + case QMetaType::QDate: return left.toDate() < right.toDate(); - case QVariant::Time: + case QMetaType::QTime: return left.toTime() < right.toTime(); - case QVariant::DateTime: + case QMetaType::QDateTime: return left.toDateTime() < right.toDateTime(); - case QVariant::String: + case QMetaType::QString: default: if (isLocaleAware) return left.toString().localeAwareCompare(right.toString()) < 0; @@ -591,19 +591,19 @@ static uint typeOfVariant(const QVariant &value) { //return 0 for integer, 1 for floating point and 2 for other switch (value.userType()) { - case QVariant::Bool: - case QVariant::Int: - case QVariant::UInt: - case QVariant::LongLong: - case QVariant::ULongLong: - case QVariant::Char: + case QMetaType::Bool: + case QMetaType::Int: + case QMetaType::UInt: + case QMetaType::LongLong: + case QMetaType::ULongLong: + case QMetaType::QChar: case QMetaType::Short: case QMetaType::UShort: case QMetaType::UChar: case QMetaType::ULong: case QMetaType::Long: return 0; - case QVariant::Double: + case QMetaType::Double: case QMetaType::Float: return 1; default: @@ -2379,7 +2379,7 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, } else { // QString or regular expression based matching if (matchType == Qt::MatchRegularExpression) { if (rx.pattern().isEmpty()) { - if (value.type() == QVariant::RegularExpression) { + if (value.userType() == QMetaType::QRegularExpression) { rx = value.toRegularExpression(); } else { rx.setPattern(value.toString()); diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index fad47eee13..347fb1eb87 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -2982,7 +2982,7 @@ int QMetaProperty::userType() const if (type == QMetaType::UnknownType) { type = registerPropertyType(); if (type == QMetaType::UnknownType) - return QVariant::Int; // Match behavior of QMetaType::type() + return QMetaType::Int; // Match behavior of QMetaType::type() } return type; } @@ -3100,7 +3100,7 @@ QVariant QMetaProperty::read(const QObject *object) const if (!object || !mobj) return QVariant(); - uint t = QVariant::Int; + uint t = QMetaType::Int; if (isEnumType()) { /* try to create a QVariant that can be converted to this enum @@ -3177,9 +3177,9 @@ bool QMetaProperty::write(QObject *object, const QVariant &value) const return false; QVariant v = value; - uint t = QVariant::Invalid; + uint t = QMetaType::UnknownType; if (isEnumType()) { - if (v.type() == QVariant::String) { + if (v.userType() == QMetaType::QString) { bool ok; if (isFlagType()) v = QVariant(menum.keysToValue(value.toByteArray(), &ok)); @@ -3187,13 +3187,13 @@ bool QMetaProperty::write(QObject *object, const QVariant &value) const v = QVariant(menum.keyToValue(value.toByteArray(), &ok)); if (!ok) return false; - } else if (v.type() != QVariant::Int && v.type() != QVariant::UInt) { + } else if (v.userType() != QMetaType::Int && v.userType() != QMetaType::UInt) { int enumMetaTypeId = QMetaType::type(qualifiedName(menum)); if ((enumMetaTypeId == QMetaType::UnknownType) || (v.userType() != enumMetaTypeId) || !v.constData()) return false; v = QVariant(*reinterpret_cast(v.constData())); } - v.convert(QVariant::Int); + v.convert(QMetaType::Int); } else { int handle = priv(mobj->d.data)->propertyData + 3*idx; const char *typeName = nullptr; diff --git a/src/corelib/kernel/qmimedata.cpp b/src/corelib/kernel/qmimedata.cpp index 00e5183eb1..fca258c9e3 100644 --- a/src/corelib/kernel/qmimedata.cpp +++ b/src/corelib/kernel/qmimedata.cpp @@ -70,7 +70,7 @@ public: void setData(const QString &format, const QVariant &data); QVariant getData(const QString &format) const; - QVariant retrieveTypedData(const QString &format, QVariant::Type type) const; + QVariant retrieveTypedData(const QString &format, QMetaType::Type type) const; QVector dataList; }; @@ -108,23 +108,23 @@ QVariant QMimeDataPrivate::getData(const QString &format) const return data; } -QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QVariant::Type type) const +QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QMetaType::Type type) const { Q_Q(const QMimeData); - QVariant data = q->retrieveData(format, type); + QVariant data = q->retrieveData(format, QVariant::Type(type)); // Text data requested: fallback to URL data if available if (format == QLatin1String("text/plain") && !data.isValid()) { - data = retrieveTypedData(textUriListLiteral(), QVariant::List); - if (data.type() == QVariant::Url) { + data = retrieveTypedData(textUriListLiteral(), QMetaType::QVariantList); + if (data.userType() == QMetaType::QUrl) { data = QVariant(data.toUrl().toDisplayString()); - } else if (data.type() == QVariant::List) { + } else if (data.userType() == QMetaType::QVariantList) { QString text; int numUrls = 0; const QList list = data.toList(); for (int i = 0; i < list.size(); ++i) { - if (list.at(i).type() == QVariant::Url) { + if (list.at(i).userType() == QMetaType::QUrl) { text += list.at(i).toUrl().toDisplayString() + QLatin1Char('\n'); ++numUrls; } @@ -135,26 +135,26 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QVariant::Ty } } - if (data.type() == type || !data.isValid()) + if (data.userType() == type || !data.isValid()) return data; // provide more conversion possiblities than just what QVariant provides // URLs can be lists as well... - if ((type == QVariant::Url && data.type() == QVariant::List) - || (type == QVariant::List && data.type() == QVariant::Url)) + if ((type == QMetaType::QUrl && data.userType() == QMetaType::QVariantList) + || (type == QMetaType::QVariantList && data.userType() == QMetaType::QUrl)) return data; // images and pixmaps are interchangeable - if ((type == QVariant::Pixmap && data.type() == QVariant::Image) - || (type == QVariant::Image && data.type() == QVariant::Pixmap)) + if ((type == QMetaType::QPixmap && data.userType() == QMetaType::QImage) + || (type == QMetaType::QImage && data.userType() == QMetaType::QPixmap)) return data; - if (data.type() == QVariant::ByteArray) { + if (data.userType() == QMetaType::QByteArray) { // see if we can convert to the requested type switch(type) { #if QT_CONFIG(textcodec) - case QVariant::String: { + case QMetaType::QString: { const QByteArray ba = data.toByteArray(); QTextCodec *codec = QTextCodec::codecForName("utf-8"); if (format == QLatin1String("text/html")) @@ -162,17 +162,17 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QVariant::Ty return codec->toUnicode(ba); } #endif // textcodec - case QVariant::Color: { + case QMetaType::QColor: { QVariant newData = data; - newData.convert(QVariant::Color); + newData.convert(QMetaType::QColor); return newData; } - case QVariant::List: { + case QMetaType::QVariantList: { if (format != QLatin1String("text/uri-list")) break; Q_FALLTHROUGH(); } - case QVariant::Url: { + case QMetaType::QUrl: { QByteArray ba = data.toByteArray(); // Qt 3.x will send text/uri-list with a trailing // null-terminator (that is *not* sent for any other @@ -193,23 +193,23 @@ QVariant QMimeDataPrivate::retrieveTypedData(const QString &format, QVariant::Ty break; } - } else if (type == QVariant::ByteArray) { + } else if (type == QMetaType::QByteArray) { // try to convert to bytearray - switch(data.type()) { - case QVariant::ByteArray: - case QVariant::Color: + switch (data.userType()) { + case QMetaType::QByteArray: + case QMetaType::QColor: return data.toByteArray(); - case QVariant::String: + case QMetaType::QString: return data.toString().toUtf8(); - case QVariant::Url: + case QMetaType::QUrl: return data.toUrl().toEncoded(); - case QVariant::List: { + case QMetaType::QVariantList: { // has to be list of URLs QByteArray result; QList list = data.toList(); for (int i = 0; i < list.size(); ++i) { - if (list.at(i).type() == QVariant::Url) { + if (list.at(i).userType() == QMetaType::QUrl) { result += list.at(i).toUrl().toEncoded(); result += "\r\n"; } @@ -340,14 +340,14 @@ QMimeData::~QMimeData() QList QMimeData::urls() const { Q_D(const QMimeData); - QVariant data = d->retrieveTypedData(textUriListLiteral(), QVariant::List); + QVariant data = d->retrieveTypedData(textUriListLiteral(), QMetaType::QVariantList); QList urls; - if (data.type() == QVariant::Url) + if (data.userType() == QMetaType::QUrl) urls.append(data.toUrl()); - else if (data.type() == QVariant::List) { + else if (data.userType() == QMetaType::QVariantList) { QList list = data.toList(); for (int i = 0; i < list.size(); ++i) { - if (list.at(i).type() == QVariant::Url) + if (list.at(i).userType() == QMetaType::QUrl) urls.append(list.at(i).toUrl()); } } @@ -400,11 +400,11 @@ bool QMimeData::hasUrls() const QString QMimeData::text() const { Q_D(const QMimeData); - QVariant utf8Text = d->retrieveTypedData(textPlainUtf8Literal(), QVariant::String); + QVariant utf8Text = d->retrieveTypedData(textPlainUtf8Literal(), QMetaType::QString); if (!utf8Text.isNull()) return utf8Text.toString(); - QVariant data = d->retrieveTypedData(textPlainLiteral(), QVariant::String); + QVariant data = d->retrieveTypedData(textPlainLiteral(), QMetaType::QString); return data.toString(); } @@ -440,7 +440,7 @@ bool QMimeData::hasText() const QString QMimeData::html() const { Q_D(const QMimeData); - QVariant data = d->retrieveTypedData(textHtmlLiteral(), QVariant::String); + QVariant data = d->retrieveTypedData(textHtmlLiteral(), QMetaType::QString); return data.toString(); } @@ -482,7 +482,7 @@ bool QMimeData::hasHtml() const QVariant QMimeData::imageData() const { Q_D(const QMimeData); - return d->retrieveTypedData(applicationXQtImageLiteral(), QVariant::Image); + return d->retrieveTypedData(applicationXQtImageLiteral(), QMetaType::QImage); } /*! @@ -529,7 +529,7 @@ bool QMimeData::hasImage() const QVariant QMimeData::colorData() const { Q_D(const QMimeData); - return d->retrieveTypedData(applicationXColorLiteral(), QVariant::Color); + return d->retrieveTypedData(applicationXColorLiteral(), QMetaType::QColor); } /*! @@ -564,7 +564,7 @@ bool QMimeData::hasColor() const QByteArray QMimeData::data(const QString &mimeType) const { Q_D(const QMimeData); - QVariant data = d->retrieveTypedData(mimeType, QVariant::ByteArray); + QVariant data = d->retrieveTypedData(mimeType, QMetaType::QByteArray); return data.toByteArray(); } diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index f3ac3fcdba..b417683d2a 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -168,7 +168,7 @@ static qlonglong qMetaTypeNumber(const QVariant::Private *d) return qlonglong(d->data.l); case QMetaType::Float: return qRound64(d->data.f); - case QVariant::Double: + case QMetaType::Double: return qRound64(d->data.d); #ifndef QT_BOOTSTRAPPED case QMetaType::QJsonValue: @@ -184,9 +184,9 @@ static qlonglong qMetaTypeNumber(const QVariant::Private *d) static qulonglong qMetaTypeUNumber(const QVariant::Private *d) { switch (d->type) { - case QVariant::UInt: + case QMetaType::UInt: return d->data.u; - case QVariant::ULongLong: + case QMetaType::ULongLong: return d->data.ull; case QMetaType::UChar: return d->data.uc; @@ -204,13 +204,13 @@ static qlonglong qConvertToNumber(const QVariant::Private *d, bool *ok) *ok = true; switch (uint(d->type)) { - case QVariant::String: + case QMetaType::QString: return v_cast(d)->toLongLong(ok); - case QVariant::Char: + case QMetaType::QChar: return v_cast(d)->unicode(); - case QVariant::ByteArray: + case QMetaType::QByteArray: return v_cast(d)->toLongLong(ok); - case QVariant::Bool: + case QMetaType::Bool: return qlonglong(d->data.b); #ifndef QT_BOOTSTRAPPED case QMetaType::QCborValue: @@ -222,8 +222,8 @@ static qlonglong qConvertToNumber(const QVariant::Private *d, bool *ok) break; Q_FALLTHROUGH(); #endif - case QVariant::Double: - case QVariant::Int: + case QMetaType::Double: + case QMetaType::Int: case QMetaType::Char: case QMetaType::SChar: case QMetaType::Short: @@ -231,8 +231,8 @@ static qlonglong qConvertToNumber(const QVariant::Private *d, bool *ok) case QMetaType::Float: case QMetaType::LongLong: return qMetaTypeNumber(d); - case QVariant::ULongLong: - case QVariant::UInt: + case QMetaType::ULongLong: + case QMetaType::UInt: case QMetaType::UChar: case QMetaType::UShort: case QMetaType::ULong: @@ -262,12 +262,12 @@ static qreal qConvertToRealNumber(const QVariant::Private *d, bool *ok) { *ok = true; switch (uint(d->type)) { - case QVariant::Double: + case QMetaType::Double: return qreal(d->data.d); case QMetaType::Float: return qreal(d->data.f); - case QVariant::ULongLong: - case QVariant::UInt: + case QMetaType::ULongLong: + case QMetaType::UInt: case QMetaType::UChar: case QMetaType::UShort: case QMetaType::ULong: @@ -289,13 +289,13 @@ static qulonglong qConvertToUnsignedNumber(const QVariant::Private *d, bool *ok) *ok = true; switch (uint(d->type)) { - case QVariant::String: + case QMetaType::QString: return v_cast(d)->toULongLong(ok); - case QVariant::Char: + case QMetaType::QChar: return v_cast(d)->unicode(); - case QVariant::ByteArray: + case QMetaType::QByteArray: return v_cast(d)->toULongLong(ok); - case QVariant::Bool: + case QMetaType::Bool: return qulonglong(d->data.b); #ifndef QT_BOOTSTRAPPED case QMetaType::QCborValue: @@ -309,8 +309,8 @@ static qulonglong qConvertToUnsignedNumber(const QVariant::Private *d, bool *ok) break; Q_FALLTHROUGH(); #endif - case QVariant::Double: - case QVariant::Int: + case QMetaType::Double: + case QMetaType::Int: case QMetaType::Char: case QMetaType::SChar: case QMetaType::Short: @@ -318,8 +318,8 @@ static qulonglong qConvertToUnsignedNumber(const QVariant::Private *d, bool *ok) case QMetaType::Float: case QMetaType::LongLong: return qulonglong(qMetaTypeNumber(d)); - case QVariant::ULongLong: - case QVariant::UInt: + case QMetaType::ULongLong: + case QMetaType::UInt: case QMetaType::UChar: case QMetaType::UShort: case QMetaType::ULong: @@ -406,9 +406,9 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) switch (uint(t)) { #ifndef QT_BOOTSTRAPPED - case QVariant::Url: + case QMetaType::QUrl: switch (d->type) { - case QVariant::String: + case QMetaType::QString: *static_cast(result) = QUrl(*v_cast(d)); break; case QMetaType::QCborValue: @@ -423,18 +423,18 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) break; #endif // QT_BOOTSTRAPPED #if QT_CONFIG(itemmodel) - case QVariant::ModelIndex: + case QMetaType::QModelIndex: switch (d->type) { - case QVariant::PersistentModelIndex: + case QMetaType::QPersistentModelIndex: *static_cast(result) = QModelIndex(*v_cast(d)); break; default: return false; } break; - case QVariant::PersistentModelIndex: + case QMetaType::QPersistentModelIndex: switch (d->type) { - case QVariant::ModelIndex: + case QMetaType::QModelIndex: *static_cast(result) = QPersistentModelIndex(*v_cast(d)); break; default: @@ -442,10 +442,10 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) } break; #endif // QT_CONFIG(itemmodel) - case QVariant::String: { + case QMetaType::QString: { QString *str = static_cast(result); switch (d->type) { - case QVariant::Char: + case QMetaType::QChar: *str = *v_cast(d); break; case QMetaType::Char: @@ -455,12 +455,12 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) break; case QMetaType::Short: case QMetaType::Long: - case QVariant::Int: - case QVariant::LongLong: + case QMetaType::Int: + case QMetaType::LongLong: *str = QString::number(qMetaTypeNumber(d)); break; - case QVariant::UInt: - case QVariant::ULongLong: + case QMetaType::UInt: + case QMetaType::ULongLong: case QMetaType::UShort: case QMetaType::ULong: *str = QString::number(qMetaTypeUNumber(d)); @@ -468,32 +468,32 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) case QMetaType::Float: *str = QString::number(d->data.f, 'g', QLocale::FloatingPointShortest); break; - case QVariant::Double: + case QMetaType::Double: *str = QString::number(d->data.d, 'g', QLocale::FloatingPointShortest); break; #if QT_CONFIG(datestring) - case QVariant::Date: + case QMetaType::QDate: *str = v_cast(d)->toString(Qt::ISODate); break; - case QVariant::Time: + case QMetaType::QTime: *str = v_cast(d)->toString(Qt::ISODateWithMs); break; - case QVariant::DateTime: + case QMetaType::QDateTime: *str = v_cast(d)->toString(Qt::ISODateWithMs); break; #endif - case QVariant::Bool: + case QMetaType::Bool: *str = d->data.b ? QStringLiteral("true") : QStringLiteral("false"); break; - case QVariant::ByteArray: + case QMetaType::QByteArray: *str = QString::fromUtf8(v_cast(d)->constData()); break; - case QVariant::StringList: + case QMetaType::QStringList: if (v_cast(d)->count() == 1) *str = v_cast(d)->at(0); break; #ifndef QT_BOOTSTRAPPED - case QVariant::Url: + case QMetaType::QUrl: *str = v_cast(d)->toString(); break; case QMetaType::QJsonValue: @@ -508,7 +508,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) *str = v_cast(d)->toVariant().toString(); break; #endif - case QVariant::Uuid: + case QMetaType::QUuid: *str = v_cast(d)->toString(); break; case QMetaType::Nullptr: @@ -528,11 +528,11 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) } break; } - case QVariant::Char: { + case QMetaType::QChar: { QChar *c = static_cast(result); switch (d->type) { - case QVariant::Int: - case QVariant::LongLong: + case QMetaType::Int: + case QMetaType::LongLong: case QMetaType::Char: case QMetaType::SChar: case QMetaType::Short: @@ -540,8 +540,8 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) case QMetaType::Float: *c = QChar(ushort(qMetaTypeNumber(d))); break; - case QVariant::UInt: - case QVariant::ULongLong: + case QMetaType::UInt: + case QMetaType::ULongLong: case QMetaType::UChar: case QMetaType::UShort: case QMetaType::ULong: @@ -553,10 +553,10 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) break; } #ifndef QT_NO_GEOM_VARIANT - case QVariant::Size: { + case QMetaType::QSize: { QSize *s = static_cast(result); switch (d->type) { - case QVariant::SizeF: + case QMetaType::QSizeF: *s = v_cast(d)->toSize(); break; default: @@ -565,10 +565,10 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) break; } - case QVariant::SizeF: { + case QMetaType::QSizeF: { QSizeF *s = static_cast(result); switch (d->type) { - case QVariant::Size: + case QMetaType::QSize: *s = QSizeF(*(v_cast(d))); break; default: @@ -577,10 +577,10 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) break; } - case QVariant::Line: { + case QMetaType::QLine: { QLine *s = static_cast(result); switch (d->type) { - case QVariant::LineF: + case QMetaType::QLineF: *s = v_cast(d)->toLine(); break; default: @@ -589,10 +589,10 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) break; } - case QVariant::LineF: { + case QMetaType::QLineF: { QLineF *s = static_cast(result); switch (d->type) { - case QVariant::Line: + case QMetaType::QLine: *s = QLineF(*(v_cast(d))); break; default: @@ -601,27 +601,27 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) break; } #endif - case QVariant::StringList: - if (d->type == QVariant::List) { + case QMetaType::QStringList: + if (d->type == QMetaType::QVariantList) { QStringList *slst = static_cast(result); const QVariantList *list = v_cast(d); const int size = list->size(); slst->reserve(size); for (int i = 0; i < size; ++i) slst->append(list->at(i).toString()); - } else if (d->type == QVariant::String) { + } else if (d->type == QMetaType::QString) { QStringList *slst = static_cast(result); *slst = QStringList(*v_cast(d)); } else { return false; } break; - case QVariant::Date: { + case QMetaType::QDate: { QDate *dt = static_cast(result); - if (d->type == QVariant::DateTime) + if (d->type == QMetaType::QDateTime) *dt = v_cast(d)->date(); #if QT_CONFIG(datestring) - else if (d->type == QVariant::String) + else if (d->type == QMetaType::QString) *dt = QDate::fromString(*v_cast(d), Qt::ISODate); #endif else @@ -629,14 +629,14 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) return dt->isValid(); } - case QVariant::Time: { + case QMetaType::QTime: { QTime *t = static_cast(result); switch (d->type) { - case QVariant::DateTime: + case QMetaType::QDateTime: *t = v_cast(d)->time(); break; #if QT_CONFIG(datestring) - case QVariant::String: + case QMetaType::QString: *t = QTime::fromString(*v_cast(d), Qt::ISODate); break; #endif @@ -645,11 +645,11 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) } return t->isValid(); } - case QVariant::DateTime: { + case QMetaType::QDateTime: { QDateTime *dt = static_cast(result); switch (d->type) { #if QT_CONFIG(datestring) - case QVariant::String: + case QMetaType::QString: *dt = QDateTime::fromString(*v_cast(d), Qt::ISODate); break; # ifndef QT_BOOTSTRAPPED @@ -661,7 +661,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) break; # endif #endif - case QVariant::Date: + case QMetaType::QDate: *dt = QDateTime(*v_cast(d)); break; default: @@ -669,13 +669,13 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) } return dt->isValid(); } - case QVariant::ByteArray: { + case QMetaType::QByteArray: { QByteArray *ba = static_cast(result); switch (d->type) { - case QVariant::String: + case QMetaType::QString: *ba = v_cast(d)->toUtf8(); break; - case QVariant::Double: + case QMetaType::Double: *ba = QByteArray::number(d->data.d, 'g', QLocale::FloatingPointShortest); break; case QMetaType::Float: @@ -686,22 +686,22 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) case QMetaType::UChar: *ba = QByteArray(1, d->data.c); break; - case QVariant::Int: - case QVariant::LongLong: + case QMetaType::Int: + case QMetaType::LongLong: case QMetaType::Short: case QMetaType::Long: *ba = QByteArray::number(qMetaTypeNumber(d)); break; - case QVariant::UInt: - case QVariant::ULongLong: + case QMetaType::UInt: + case QMetaType::ULongLong: case QMetaType::UShort: case QMetaType::ULong: *ba = QByteArray::number(qMetaTypeUNumber(d)); break; - case QVariant::Bool: + case QMetaType::Bool: *ba = QByteArray(d->data.b ? "true" : "false"); break; - case QVariant::Uuid: + case QMetaType::QUuid: *ba = v_cast(d)->toByteArray(); break; case QMetaType::Nullptr: @@ -741,16 +741,16 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) case QMetaType::ULong: *static_cast(result) = ulong(qConvertToUnsignedNumber(d, ok)); return *ok; - case QVariant::Int: + case QMetaType::Int: *static_cast(result) = int(qConvertToNumber(d, ok)); return *ok; - case QVariant::UInt: + case QMetaType::UInt: *static_cast(result) = uint(qConvertToUnsignedNumber(d, ok)); return *ok; - case QVariant::LongLong: + case QMetaType::LongLong: *static_cast(result) = qConvertToNumber(d, ok); return *ok; - case QVariant::ULongLong: { + case QMetaType::ULongLong: { *static_cast(result) = qConvertToUnsignedNumber(d, ok); return *ok; } @@ -763,21 +763,21 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) *static_cast(result) = qConvertToUnsignedNumber(d, ok); return *ok; } - case QVariant::Bool: { + case QMetaType::Bool: { bool *b = static_cast(result); switch(d->type) { - case QVariant::ByteArray: + case QMetaType::QByteArray: *b = qt_convertToBool(d); break; - case QVariant::String: + case QMetaType::QString: *b = qt_convertToBool(d); break; - case QVariant::Char: + case QMetaType::QChar: *b = !v_cast(d)->isNull(); break; - case QVariant::Double: - case QVariant::Int: - case QVariant::LongLong: + case QMetaType::Double: + case QMetaType::Int: + case QMetaType::LongLong: case QMetaType::Char: case QMetaType::SChar: case QMetaType::Short: @@ -785,8 +785,8 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) case QMetaType::Float: *b = qMetaTypeNumber(d) != Q_INT64_C(0); break; - case QVariant::UInt: - case QVariant::ULongLong: + case QMetaType::UInt: + case QMetaType::ULongLong: case QMetaType::UChar: case QMetaType::UShort: case QMetaType::ULong: @@ -810,31 +810,31 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) } break; } - case QVariant::Double: { + case QMetaType::Double: { double *f = static_cast(result); switch (d->type) { - case QVariant::String: + case QMetaType::QString: *f = v_cast(d)->toDouble(ok); break; - case QVariant::ByteArray: + case QMetaType::QByteArray: *f = v_cast(d)->toDouble(ok); break; - case QVariant::Bool: + case QMetaType::Bool: *f = double(d->data.b); break; case QMetaType::Float: *f = double(d->data.f); break; - case QVariant::LongLong: - case QVariant::Int: + case QMetaType::LongLong: + case QMetaType::Int: case QMetaType::Char: case QMetaType::SChar: case QMetaType::Short: case QMetaType::Long: *f = double(qMetaTypeNumber(d)); break; - case QVariant::UInt: - case QVariant::ULongLong: + case QMetaType::UInt: + case QMetaType::ULongLong: case QMetaType::UChar: case QMetaType::UShort: case QMetaType::ULong: @@ -861,28 +861,28 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) case QMetaType::Float: { float *f = static_cast(result); switch (d->type) { - case QVariant::String: + case QMetaType::QString: *f = v_cast(d)->toFloat(ok); break; - case QVariant::ByteArray: + case QMetaType::QByteArray: *f = v_cast(d)->toFloat(ok); break; - case QVariant::Bool: + case QMetaType::Bool: *f = float(d->data.b); break; - case QVariant::Double: + case QMetaType::Double: *f = float(d->data.d); break; - case QVariant::LongLong: - case QVariant::Int: + case QMetaType::LongLong: + case QMetaType::Int: case QMetaType::Char: case QMetaType::SChar: case QMetaType::Short: case QMetaType::Long: *f = float(qMetaTypeNumber(d)); break; - case QVariant::UInt: - case QVariant::ULongLong: + case QMetaType::UInt: + case QMetaType::ULongLong: case QMetaType::UChar: case QMetaType::UShort: case QMetaType::ULong: @@ -906,8 +906,8 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) } break; } - case QVariant::List: - if (d->type == QVariant::StringList) { + case QMetaType::QVariantList: + if (d->type == QMetaType::QStringList) { QVariantList *lst = static_cast(result); const QStringList *slist = v_cast(d); const int size = slist->size(); @@ -935,11 +935,11 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) return false; } break; - case QVariant::Map: + case QMetaType::QVariantMap: if (qstrcmp(QMetaType::typeName(d->type), "QMap") == 0) { *static_cast(result) = *static_cast *>(d->data.shared->ptr); - } else if (d->type == QVariant::Hash) { + } else if (d->type == QMetaType::QVariantHash) { QVariantMap *map = static_cast(result); const QVariantHash *hash = v_cast(d); const auto end = hash->end(); @@ -963,11 +963,11 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) return false; } break; - case QVariant::Hash: + case QMetaType::QVariantHash: if (qstrcmp(QMetaType::typeName(d->type), "QHash") == 0) { *static_cast(result) = *static_cast *>(d->data.shared->ptr); - } else if (d->type == QVariant::Map) { + } else if (d->type == QMetaType::QVariantMap) { QVariantHash *hash = static_cast(result); const QVariantMap *map = v_cast(d); const auto end = map->end(); @@ -992,26 +992,26 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) } break; #ifndef QT_NO_GEOM_VARIANT - case QVariant::Rect: - if (d->type == QVariant::RectF) + case QMetaType::QRect: + if (d->type == QMetaType::QRectF) *static_cast(result) = (v_cast(d))->toRect(); else return false; break; - case QVariant::RectF: - if (d->type == QVariant::Rect) + case QMetaType::QRectF: + if (d->type == QMetaType::QRect) *static_cast(result) = *v_cast(d); else return false; break; - case QVariant::PointF: - if (d->type == QVariant::Point) + case QMetaType::QPointF: + if (d->type == QMetaType::QPoint) *static_cast(result) = *v_cast(d); else return false; break; - case QVariant::Point: - if (d->type == QVariant::PointF) + case QMetaType::QPoint: + if (d->type == QMetaType::QPointF) *static_cast(result) = (v_cast(d))->toPoint(); else return false; @@ -1022,12 +1022,12 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) return *ok; } #endif - case QVariant::Uuid: + case QMetaType::QUuid: switch (d->type) { - case QVariant::String: + case QMetaType::QString: *static_cast(result) = QUuid(*v_cast(d)); break; - case QVariant::ByteArray: + case QMetaType::QByteArray: *static_cast(result) = QUuid(*v_cast(d)); break; #ifndef QT_BOOTSTRAPPED @@ -1067,7 +1067,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) case QMetaType::Nullptr: *static_cast(result) = QJsonValue(QJsonValue::Null); break; - case QVariant::Bool: + case QMetaType::Bool: *static_cast(result) = QJsonValue(d->data.b); break; case QMetaType::Int: @@ -1086,19 +1086,19 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) *static_cast(result) = QJsonValue(qConvertToRealNumber(d, ok)); Q_ASSERT(ok); break; - case QVariant::String: + case QMetaType::QString: *static_cast(result) = QJsonValue(*v_cast(d)); break; - case QVariant::StringList: + case QMetaType::QStringList: *static_cast(result) = QJsonValue(QJsonArray::fromStringList(*v_cast(d))); break; - case QVariant::List: + case QMetaType::QVariantList: *static_cast(result) = QJsonValue(QJsonArray::fromVariantList(*v_cast(d))); break; - case QVariant::Map: + case QMetaType::QVariantMap: *static_cast(result) = QJsonValue(QJsonObject::fromVariantMap(*v_cast(d))); break; - case QVariant::Hash: + case QMetaType::QVariantHash: *static_cast(result) = QJsonValue(QJsonObject::fromVariantHash(*v_cast(d))); break; case QMetaType::QJsonObject: @@ -1128,10 +1128,10 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) break; case QMetaType::QJsonArray: switch (d->type) { - case QVariant::StringList: + case QMetaType::QStringList: *static_cast(result) = QJsonArray::fromStringList(*v_cast(d)); break; - case QVariant::List: + case QMetaType::QVariantList: *static_cast(result) = QJsonArray::fromVariantList(*v_cast(d)); break; case QMetaType::QJsonValue: @@ -1158,10 +1158,10 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) break; case QMetaType::QJsonObject: switch (d->type) { - case QVariant::Map: + case QMetaType::QVariantMap: *static_cast(result) = QJsonObject::fromVariantMap(*v_cast(d)); break; - case QVariant::Hash: + case QMetaType::QVariantHash: *static_cast(result) = QJsonObject::fromVariantHash(*v_cast(d)); break; case QMetaType::QJsonValue: @@ -1197,7 +1197,7 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) case QMetaType::Nullptr: *static_cast(result) = QCborValue(QCborValue::Null); break; - case QVariant::Bool: + case QMetaType::Bool: *static_cast(result) = QCborValue(d->data.b); break; case QMetaType::Int: @@ -1219,39 +1219,39 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) *static_cast(result) = QCborValue(qConvertToRealNumber(d, ok)); Q_ASSERT(ok); break; - case QVariant::String: + case QMetaType::QString: *static_cast(result) = *v_cast(d); break; - case QVariant::StringList: + case QMetaType::QStringList: *static_cast(result) = QCborArray::fromStringList(*v_cast(d)); break; - case QVariant::ByteArray: + case QMetaType::QByteArray: *static_cast(result) = *v_cast(d); break; - case QVariant::Date: + case QMetaType::QDate: *static_cast(result) = QCborValue(QDateTime(*v_cast(d))); break; - case QVariant::DateTime: + case QMetaType::QDateTime: *static_cast(result) = QCborValue(*v_cast(d)); break; - case QVariant::Url: + case QMetaType::QUrl: *static_cast(result) = QCborValue(*v_cast(d)); break; #if QT_CONFIG(regularexpression) - case QVariant::RegularExpression: + case QMetaType::QRegularExpression: *static_cast(result) = QCborValue(*v_cast(d)); break; #endif - case QVariant::Uuid: + case QMetaType::QUuid: *static_cast(result) = QCborValue(*v_cast(d)); break; - case QVariant::List: + case QMetaType::QVariantList: *static_cast(result) = QCborArray::fromVariantList(*v_cast(d)); break; - case QVariant::Map: + case QMetaType::QVariantMap: *static_cast(result) = QCborMap::fromVariantMap(*v_cast(d)); break; - case QVariant::Hash: + case QMetaType::QVariantHash: *static_cast(result) = QCborMap::fromVariantHash(*v_cast(d)); break; case QMetaType::QJsonValue: @@ -1287,10 +1287,10 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) break; case QMetaType::QCborArray: switch (d->type) { - case QVariant::StringList: + case QMetaType::QStringList: *static_cast(result) = QCborArray::fromStringList(*v_cast(d)); break; - case QVariant::List: + case QMetaType::QVariantList: *static_cast(result) = QCborArray::fromVariantList(*v_cast(d)); break; case QMetaType::QCborValue: @@ -1317,10 +1317,10 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) break; case QMetaType::QCborMap: switch (d->type) { - case QVariant::Map: + case QMetaType::QVariantMap: *static_cast(result) = QCborMap::fromVariantMap(*v_cast(d)); break; - case QVariant::Hash: + case QMetaType::QVariantHash: *static_cast(result) = QCborMap::fromVariantHash(*v_cast(d)); break; case QMetaType::QCborValue: @@ -1349,10 +1349,10 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) default: #ifndef QT_NO_QOBJECT - if (d->type == QVariant::String || d->type == QVariant::ByteArray) { + if (d->type == QMetaType::QString || d->type == QMetaType::QByteArray) { QMetaEnum en = metaEnumFromType(t); if (en.isValid()) { - QByteArray keys = (d->type == QVariant::String) ? v_cast(d)->toUtf8() : *v_cast(d); + QByteArray keys = (d->type == QMetaType::QString) ? v_cast(d)->toUtf8() : *v_cast(d); int value = en.keysToValue(keys.constData(), ok); if (*ok) { switch (QMetaType::sizeOf(t)) { @@ -1457,7 +1457,7 @@ static void customConstruct(QVariant::Private *d, const void *copy) const uint size = type.sizeOf(); if (!size) { qWarning("Trying to construct an instance of an invalid type, type id: %i", d->type); - d->type = QVariant::Invalid; + d->type = QMetaType::UnknownType; return; } @@ -2438,43 +2438,43 @@ QVariant::Type QVariant::nameToType(const char *name) enum { MapFromThreeCount = 36 }; static const ushort mapIdFromQt3ToCurrent[MapFromThreeCount] = { - QVariant::Invalid, - QVariant::Map, - QVariant::List, - QVariant::String, - QVariant::StringList, - QVariant::Font, - QVariant::Pixmap, - QVariant::Brush, - QVariant::Rect, - QVariant::Size, - QVariant::Color, - QVariant::Palette, + QMetaType::UnknownType, + QMetaType::QVariantMap, + QMetaType::QVariantList, + QMetaType::QString, + QMetaType::QStringList, + QMetaType::QFont, + QMetaType::QPixmap, + QMetaType::QBrush, + QMetaType::QRect, + QMetaType::QSize, + QMetaType::QColor, + QMetaType::QPalette, 0, // ColorGroup - QVariant::Icon, - QVariant::Point, - QVariant::Image, - QVariant::Int, - QVariant::UInt, - QVariant::Bool, - QVariant::Double, + QMetaType::QIcon, + QMetaType::QPoint, + QMetaType::QImage, + QMetaType::Int, + QMetaType::UInt, + QMetaType::Bool, + QMetaType::Double, 0, // Buggy ByteArray, QByteArray never had id == 20 - QVariant::Polygon, - QVariant::Region, - QVariant::Bitmap, - QVariant::Cursor, - QVariant::SizePolicy, - QVariant::Date, - QVariant::Time, - QVariant::DateTime, - QVariant::ByteArray, - QVariant::BitArray, - QVariant::KeySequence, - QVariant::Pen, - QVariant::LongLong, - QVariant::ULongLong, + QMetaType::QPolygon, + QMetaType::QRegion, + QMetaType::QBitmap, + QMetaType::QCursor, + QMetaType::QSizePolicy, + QMetaType::QDate, + QMetaType::QTime, + QMetaType::QDateTime, + QMetaType::QByteArray, + QMetaType::QBitArray, + QMetaType::QKeySequence, + QMetaType::QPen, + QMetaType::LongLong, + QMetaType::ULongLong, #if QT_CONFIG(easingcurve) - QVariant::EasingCurve + QMetaType::QEasingCurve #endif }; @@ -2551,7 +2551,7 @@ void QVariant::load(QDataStream &s) */ void QVariant::save(QDataStream &s) const { - quint32 typeId = type(); + quint32 typeId = d.type >= QMetaType::User ? QMetaType::User : userType(); bool fakeUserType = false; if (s.version() < QDataStream::Qt_4_0) { int i; @@ -3294,80 +3294,80 @@ QVariantList QVariant::toList() const } -static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] = +static const quint32 qCanConvertMatrix[QMetaType::LastCoreType + 1] = { /*Invalid*/ 0, -/*Bool*/ 1 << QVariant::Double | 1 << QVariant::Int | 1 << QVariant::UInt - | 1 << QVariant::LongLong | 1 << QVariant::ULongLong | 1 << QVariant::ByteArray - | 1 << QVariant::String | 1 << QVariant::Char, +/*Bool*/ 1 << QMetaType::Double | 1 << QMetaType::Int | 1 << QMetaType::UInt + | 1 << QMetaType::LongLong | 1 << QMetaType::ULongLong | 1 << QMetaType::QByteArray + | 1 << QMetaType::QString | 1 << QMetaType::QChar, -/*Int*/ 1 << QVariant::UInt | 1 << QVariant::String | 1 << QVariant::Double - | 1 << QVariant::Bool | 1 << QVariant::LongLong | 1 << QVariant::ULongLong - | 1 << QVariant::Char | 1 << QVariant::ByteArray | 1 << QVariant::Int, +/*Int*/ 1 << QMetaType::UInt | 1 << QMetaType::QString | 1 << QMetaType::Double + | 1 << QMetaType::Bool | 1 << QMetaType::LongLong | 1 << QMetaType::ULongLong + | 1 << QMetaType::QChar | 1 << QMetaType::QByteArray | 1 << QMetaType::Int, -/*UInt*/ 1 << QVariant::Int | 1 << QVariant::String | 1 << QVariant::Double - | 1 << QVariant::Bool | 1 << QVariant::LongLong | 1 << QVariant::ULongLong - | 1 << QVariant::Char | 1 << QVariant::ByteArray, +/*UInt*/ 1 << QMetaType::Int | 1 << QMetaType::QString | 1 << QMetaType::Double + | 1 << QMetaType::Bool | 1 << QMetaType::LongLong | 1 << QMetaType::ULongLong + | 1 << QMetaType::QChar | 1 << QMetaType::QByteArray, -/*LLong*/ 1 << QVariant::Int | 1 << QVariant::String | 1 << QVariant::Double - | 1 << QVariant::Bool | 1 << QVariant::UInt | 1 << QVariant::ULongLong - | 1 << QVariant::Char | 1 << QVariant::ByteArray, +/*LLong*/ 1 << QMetaType::Int | 1 << QMetaType::QString | 1 << QMetaType::Double + | 1 << QMetaType::Bool | 1 << QMetaType::UInt | 1 << QMetaType::ULongLong + | 1 << QMetaType::QChar | 1 << QMetaType::QByteArray, -/*ULlong*/ 1 << QVariant::Int | 1 << QVariant::String | 1 << QVariant::Double - | 1 << QVariant::Bool | 1 << QVariant::UInt | 1 << QVariant::LongLong - | 1 << QVariant::Char | 1 << QVariant::ByteArray, +/*ULlong*/ 1 << QMetaType::Int | 1 << QMetaType::QString | 1 << QMetaType::Double + | 1 << QMetaType::Bool | 1 << QMetaType::UInt | 1 << QMetaType::LongLong + | 1 << QMetaType::QChar | 1 << QMetaType::QByteArray, -/*double*/ 1 << QVariant::Int | 1 << QVariant::String | 1 << QVariant::ULongLong - | 1 << QVariant::Bool | 1 << QVariant::UInt | 1 << QVariant::LongLong - | 1 << QVariant::ByteArray, +/*double*/ 1 << QMetaType::Int | 1 << QMetaType::QString | 1 << QMetaType::ULongLong + | 1 << QMetaType::Bool | 1 << QMetaType::UInt | 1 << QMetaType::LongLong + | 1 << QMetaType::QByteArray, -/*QChar*/ 1 << QVariant::Int | 1 << QVariant::UInt | 1 << QVariant::LongLong - | 1 << QVariant::ULongLong, +/*QChar*/ 1 << QMetaType::Int | 1 << QMetaType::UInt | 1 << QMetaType::LongLong + | 1 << QMetaType::ULongLong, /*QMap*/ 0, -/*QList*/ 1 << QVariant::StringList, +/*QList*/ 1 << QMetaType::QStringList, -/*QString*/ 1 << QVariant::StringList | 1 << QVariant::ByteArray | 1 << QVariant::Int - | 1 << QVariant::UInt | 1 << QVariant::Bool | 1 << QVariant::Double - | 1 << QVariant::Date | 1 << QVariant::Time | 1 << QVariant::DateTime - | 1 << QVariant::LongLong | 1 << QVariant::ULongLong | 1 << QVariant::Char - | 1 << QVariant::Url | 1 << QVariant::Uuid, +/*QString*/ 1 << QMetaType::QStringList | 1 << QMetaType::QByteArray | 1 << QMetaType::Int + | 1 << QMetaType::UInt | 1 << QMetaType::Bool | 1 << QMetaType::Double + | 1 << QMetaType::QDate | 1 << QMetaType::QTime | 1 << QMetaType::QDateTime + | 1 << QMetaType::LongLong | 1 << QMetaType::ULongLong | 1 << QMetaType::QChar + | 1 << QMetaType::QUrl | 1 << QMetaType::QUuid, -/*QStringList*/ 1 << QVariant::List | 1 << QVariant::String, +/*QStringList*/ 1 << QMetaType::QVariantList | 1 << QMetaType::QString, -/*QByteArray*/ 1 << QVariant::String | 1 << QVariant::Int | 1 << QVariant::UInt | 1 << QVariant::Bool - | 1 << QVariant::Double | 1 << QVariant::LongLong | 1 << QVariant::ULongLong - | 1 << QVariant::Uuid, +/*QByteArray*/ 1 << QMetaType::QString | 1 << QMetaType::Int | 1 << QMetaType::UInt | 1 << QMetaType::Bool + | 1 << QMetaType::Double | 1 << QMetaType::LongLong | 1 << QMetaType::ULongLong + | 1 << QMetaType::QUuid, /*QBitArray*/ 0, -/*QDate*/ 1 << QVariant::String | 1 << QVariant::DateTime, +/*QDate*/ 1 << QMetaType::QString | 1 << QMetaType::QDateTime, -/*QTime*/ 1 << QVariant::String | 1 << QVariant::DateTime, +/*QTime*/ 1 << QMetaType::QString | 1 << QMetaType::QDateTime, -/*QDateTime*/ 1 << QVariant::String | 1 << QVariant::Date, +/*QDateTime*/ 1 << QMetaType::QString | 1 << QMetaType::QDate, -/*QUrl*/ 1 << QVariant::String, +/*QUrl*/ 1 << QMetaType::QString, /*QLocale*/ 0, -/*QRect*/ 1 << QVariant::RectF, +/*QRect*/ 1 << QMetaType::QRectF, -/*QRectF*/ 1 << QVariant::Rect, +/*QRectF*/ 1 << QMetaType::QRect, -/*QSize*/ 1 << QVariant::SizeF, +/*QSize*/ 1 << QMetaType::QSizeF, -/*QSizeF*/ 1 << QVariant::Size, +/*QSizeF*/ 1 << QMetaType::QSize, -/*QLine*/ 1 << QVariant::LineF, +/*QLine*/ 1 << QMetaType::QLineF, -/*QLineF*/ 1 << QVariant::Line, +/*QLineF*/ 1 << QMetaType::QLine, -/*QPoint*/ 1 << QVariant::PointF, +/*QPoint*/ 1 << QMetaType::QPointF, -/*QPointF*/ 1 << QVariant::Point, +/*QPointF*/ 1 << QMetaType::QPoint, /*QRegExp*/ 0, @@ -3375,7 +3375,7 @@ static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] = /*QEasingCurve*/ 0, -/*QUuid*/ 1 << QVariant::String | 1 << QVariant::ByteArray, +/*QUuid*/ 1 << QMetaType::QString | 1 << QMetaType::QByteArray, }; static const size_t qCanConvertMatrixMaximumTargetType = 8 * sizeof(*qCanConvertMatrix); @@ -3915,7 +3915,7 @@ static bool qIsNumericType(uint tp) static bool qIsFloatingPoint(uint tp) { - return tp == QVariant::Double || tp == QMetaType::Float; + return tp == QMetaType::Double || tp == QMetaType::Float; } static int normalizeLowerRanks(uint tp) @@ -3927,13 +3927,13 @@ static int normalizeLowerRanks(uint tp) Q_UINT64_C(1) << QMetaType::UChar | Q_UINT64_C(1) << QMetaType::Short | Q_UINT64_C(1) << QMetaType::UShort; - return numericTypeBits & (Q_UINT64_C(1) << tp) ? QVariant::Int : tp; + return numericTypeBits & (Q_UINT64_C(1) << tp) ? uint(QMetaType::Int) : tp; } static int normalizeLong(uint tp) { - const uint IntType = sizeof(long) == sizeof(int) ? QVariant::Int : QVariant::LongLong; - const uint UIntType = sizeof(ulong) == sizeof(uint) ? QVariant::UInt : QVariant::ULongLong; + const uint IntType = sizeof(long) == sizeof(int) ? QMetaType::Int : QMetaType::LongLong; + const uint UIntType = sizeof(ulong) == sizeof(uint) ? QMetaType::UInt : QMetaType::ULongLong; return tp == QMetaType::Long ? IntType : tp == QMetaType::ULong ? UIntType : tp; } @@ -3975,13 +3975,13 @@ static int numericTypePromotion(uint t1, uint t2) // if any of the two is ULongLong, then it wins (highest rank, unsigned) // otherwise, if one of the two is LongLong, then the other is either LongLong too or lower-ranked // otherwise, if one of the two is UInt, then the other is either UInt too or Int - if (t1 == QVariant::ULongLong || t2 == QVariant::ULongLong) - return QVariant::ULongLong; - if (t1 == QVariant::LongLong || t2 == QVariant::LongLong) - return QVariant::LongLong; - if (t1 == QVariant::UInt || t2 == QVariant::UInt) - return QVariant::UInt; - return QVariant::Int; + if (t1 == QMetaType::ULongLong || t2 == QMetaType::ULongLong) + return QMetaType::ULongLong; + if (t1 == QMetaType::LongLong || t2 == QMetaType::LongLong) + return QMetaType::LongLong; + if (t1 == QMetaType::UInt || t2 == QMetaType::UInt) + return QMetaType::UInt; + return QMetaType::Int; } static int integralCompare(uint promotedType, const QVariant::Private *d1, const QVariant::Private *d2) @@ -3994,13 +3994,13 @@ static int integralCompare(uint promotedType, const QVariant::Private *d1, const qlonglong l2 = qConvertToNumber(d2, &ok); Q_ASSERT(ok); - if (promotedType == QVariant::Int) + if (promotedType == QMetaType::Int) return int(l1) < int(l2) ? -1 : int(l1) == int(l2) ? 0 : 1; - if (promotedType == QVariant::UInt) + if (promotedType == QMetaType::UInt) return uint(l1) < uint(l2) ? -1 : uint(l1) == uint(l2) ? 0 : 1; - if (promotedType == QVariant::LongLong) + if (promotedType == QMetaType::LongLong) return l1 < l2 ? -1 : l1 == l2 ? 0 : 1; - if (promotedType == QVariant::ULongLong) + if (promotedType == QMetaType::ULongLong) return qulonglong(l1) < qulonglong(l2) ? -1 : qulonglong(l1) == qulonglong(l2) ? 0 : 1; Q_UNREACHABLE(); diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index b8b63b5e6f..94781a9957 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -362,7 +362,7 @@ class QVariantConstructor FilteredConstructor(const QVariantConstructor &tc) { // ignore types that lives outside of the current library - tc.m_x->type = QVariant::Invalid; + tc.m_x->type = QMetaType::UnknownType; } }; public: @@ -430,7 +430,7 @@ public: {} ~QVariantDestructor() { - m_d->type = QVariant::Invalid; + m_d->type = QMetaType::UnknownType; m_d->is_null = true; m_d->is_shared = false; } diff --git a/src/corelib/serialization/qjsoncbor.cpp b/src/corelib/serialization/qjsoncbor.cpp index 5097f4eb81..ee4dd90416 100644 --- a/src/corelib/serialization/qjsoncbor.cpp +++ b/src/corelib/serialization/qjsoncbor.cpp @@ -640,9 +640,9 @@ static void appendVariant(QCborContainerPrivate *d, const QVariant &variant) // Handle strings and byte arrays directly, to avoid creating a temporary // dummy container to hold their data. int type = variant.userType(); - if (type == QVariant::String) { + if (type == QMetaType::QString) { d->append(variant.toString()); - } else if (type == QVariant::ByteArray) { + } else if (type == QMetaType::QByteArray) { QByteArray ba = variant.toByteArray(); d->appendByteData(ba.constData(), ba.size(), QCborValue::ByteArray); } else { @@ -703,45 +703,45 @@ static void appendVariant(QCborContainerPrivate *d, const QVariant &variant) QCborValue QCborValue::fromVariant(const QVariant &variant) { switch (variant.userType()) { - case QVariant::Invalid: + case QMetaType::UnknownType: return {}; case QMetaType::Nullptr: return nullptr; - case QVariant::Bool: + case QMetaType::Bool: return variant.toBool(); case QMetaType::Short: case QMetaType::UShort: - case QVariant::Int: - case QVariant::LongLong: - case QVariant::ULongLong: - case QVariant::UInt: + case QMetaType::Int: + case QMetaType::LongLong: + case QMetaType::ULongLong: + case QMetaType::UInt: return variant.toLongLong(); case QMetaType::Float: - case QVariant::Double: + case QMetaType::Double: return variant.toDouble(); - case QVariant::String: + case QMetaType::QString: return variant.toString(); - case QVariant::StringList: + case QMetaType::QStringList: return QCborArray::fromStringList(variant.toStringList()); - case QVariant::ByteArray: + case QMetaType::QByteArray: return variant.toByteArray(); - case QVariant::DateTime: + case QMetaType::QDateTime: return QCborValue(variant.toDateTime()); #ifndef QT_BOOTSTRAPPED - case QVariant::Url: + case QMetaType::QUrl: return QCborValue(variant.toUrl()); #endif - case QVariant::Uuid: + case QMetaType::QUuid: return QCborValue(variant.toUuid()); - case QVariant::List: + case QMetaType::QVariantList: return QCborArray::fromVariantList(variant.toList()); - case QVariant::Map: + case QMetaType::QVariantMap: return QCborMap::fromVariantMap(variant.toMap()); - case QVariant::Hash: + case QMetaType::QVariantHash: return QCborMap::fromVariantHash(variant.toHash()); #ifndef QT_BOOTSTRAPPED #if QT_CONFIG(regularexpression) - case QVariant::RegularExpression: + case QMetaType::QRegularExpression: return QCborValue(variant.toRegularExpression()); #endif case QMetaType::QJsonValue: diff --git a/src/corelib/serialization/qjsondocument.cpp b/src/corelib/serialization/qjsondocument.cpp index fe0500bdef..0be0fc020d 100644 --- a/src/corelib/serialization/qjsondocument.cpp +++ b/src/corelib/serialization/qjsondocument.cpp @@ -405,17 +405,17 @@ QJsonDocument QJsonDocument::fromVariant(const QVariant &variant) { QJsonDocument doc; - switch (variant.type()) { - case QVariant::Map: + switch (variant.userType()) { + case QMetaType::QVariantMap: doc.setObject(QJsonObject::fromVariantMap(variant.toMap())); break; - case QVariant::Hash: + case QMetaType::QVariantHash: doc.setObject(QJsonObject::fromVariantHash(variant.toHash())); break; - case QVariant::List: + case QMetaType::QVariantList: doc.setArray(QJsonArray::fromVariantList(variant.toList())); break; - case QVariant::StringList: + case QMetaType::QStringList: doc.d = qt_make_unique(); doc.d->value = QCborArray::fromStringList(variant.toStringList()); break; diff --git a/src/corelib/serialization/qjsonvalue.cpp b/src/corelib/serialization/qjsonvalue.cpp index 7b6728d525..caf81c79ef 100644 --- a/src/corelib/serialization/qjsonvalue.cpp +++ b/src/corelib/serialization/qjsonvalue.cpp @@ -447,29 +447,29 @@ QJsonValue QJsonValue::fromVariant(const QVariant &variant) switch (variant.userType()) { case QMetaType::Nullptr: return QJsonValue(Null); - case QVariant::Bool: + case QMetaType::Bool: return QJsonValue(variant.toBool()); - case QVariant::Int: + case QMetaType::Int: case QMetaType::Float: - case QVariant::Double: - case QVariant::LongLong: - case QVariant::ULongLong: - case QVariant::UInt: + case QMetaType::Double: + case QMetaType::LongLong: + case QMetaType::ULongLong: + case QMetaType::UInt: return QJsonValue(variant.toDouble()); - case QVariant::String: + case QMetaType::QString: return QJsonValue(variant.toString()); - case QVariant::StringList: + case QMetaType::QStringList: return QJsonValue(QJsonArray::fromStringList(variant.toStringList())); - case QVariant::List: + case QMetaType::QVariantList: return QJsonValue(QJsonArray::fromVariantList(variant.toList())); - case QVariant::Map: + case QMetaType::QVariantMap: return QJsonValue(QJsonObject::fromVariantMap(variant.toMap())); - case QVariant::Hash: + case QMetaType::QVariantHash: return QJsonValue(QJsonObject::fromVariantHash(variant.toHash())); #ifndef QT_BOOTSTRAPPED - case QVariant::Url: + case QMetaType::QUrl: return QJsonValue(variant.toUrl().toString(QUrl::FullyEncoded)); - case QVariant::Uuid: + case QMetaType::QUuid: return variant.toUuid().toString(QUuid::WithoutBraces); case QMetaType::QJsonValue: return variant.toJsonValue(); diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 93a8abb1ce..fb45b82967 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -2430,7 +2430,7 @@ QTime QLocale::toTime(const QString &string, const QString &format, QCalendar ca { QTime time; #if QT_CONFIG(datetimeparser) - QDateTimeParser dt(QVariant::Time, QDateTimeParser::FromString, cal); + QDateTimeParser dt(QMetaType::QTime, QDateTimeParser::FromString, cal); dt.setDefaultLocale(*this); if (dt.parseFormat(format)) dt.fromString(string, nullptr, &time); @@ -2469,7 +2469,7 @@ QDate QLocale::toDate(const QString &string, const QString &format, QCalendar ca { QDate date; #if QT_CONFIG(datetimeparser) - QDateTimeParser dt(QVariant::Date, QDateTimeParser::FromString, cal); + QDateTimeParser dt(QMetaType::QDate, QDateTimeParser::FromString, cal); dt.setDefaultLocale(*this); if (dt.parseFormat(format)) dt.fromString(string, &date, nullptr); @@ -2510,7 +2510,7 @@ QDateTime QLocale::toDateTime(const QString &string, const QString &format, QCal QTime time; QDate date; - QDateTimeParser dt(QVariant::DateTime, QDateTimeParser::FromString, cal); + QDateTimeParser dt(QMetaType::QDateTime, QDateTimeParser::FromString, cal); dt.setDefaultLocale(*this); if (dt.parseFormat(format) && dt.fromString(string, &date, &time)) return QDateTime(date, time); diff --git a/src/corelib/text/qlocale_unix.cpp b/src/corelib/text/qlocale_unix.cpp index 5e1e47eae7..207331b8ac 100644 --- a/src/corelib/text/qlocale_unix.cpp +++ b/src/corelib/text/qlocale_unix.cpp @@ -234,16 +234,16 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const case CurrencySymbol: return lc_monetary.currencySymbol(QLocale::CurrencySymbolFormat(in.toUInt())); case CurrencyToString: { - switch (in.type()) { - case QVariant::Int: + switch (in.userType()) { + case QMetaType::Int: return lc_monetary.toCurrencyString(in.toInt()); - case QVariant::UInt: + case QMetaType::UInt: return lc_monetary.toCurrencyString(in.toUInt()); - case QVariant::Double: + case QMetaType::Double: return lc_monetary.toCurrencyString(in.toDouble()); - case QVariant::LongLong: + case QMetaType::LongLong: return lc_monetary.toCurrencyString(in.toLongLong()); - case QVariant::ULongLong: + case QMetaType::ULongLong: return lc_monetary.toCurrencyString(in.toULongLong()); default: break; diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 67d37f19d8..80751e60a0 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -1791,7 +1791,7 @@ QDate QDate::fromString(const QString &string, const QString &format, QCalendar { QDate date; #if QT_CONFIG(datetimeparser) - QDateTimeParser dt(QVariant::Date, QDateTimeParser::FromString, cal); + QDateTimeParser dt(QMetaType::QDate, QDateTimeParser::FromString, cal); // dt.setDefaultLocale(QLocale::c()); ### Qt 6 if (dt.parseFormat(format)) dt.fromString(string, &date, nullptr); @@ -2537,7 +2537,7 @@ QTime QTime::fromString(const QString &string, const QString &format) { QTime time; #if QT_CONFIG(datetimeparser) - QDateTimeParser dt(QVariant::Time, QDateTimeParser::FromString, QCalendar()); + QDateTimeParser dt(QMetaType::QTime, QDateTimeParser::FromString, QCalendar()); // dt.setDefaultLocale(QLocale::c()); ### Qt 6 if (dt.parseFormat(format)) dt.fromString(string, nullptr, &time); @@ -5482,7 +5482,7 @@ QDateTime QDateTime::fromString(const QString &string, const QString &format, QC QTime time; QDate date; - QDateTimeParser dt(QVariant::DateTime, QDateTimeParser::FromString, cal); + QDateTimeParser dt(QMetaType::QDateTime, QDateTimeParser::FromString, cal); // dt.setDefaultLocale(QLocale::c()); ### Qt 6 if (dt.parseFormat(format) && dt.fromString(string, &date, &time)) return QDateTime(date, time); diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index 31d8e6cc20..70460ae632 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -425,7 +425,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat) switch (sect) { case 'H': case 'h': - if (parserType != QVariant::Date) { + if (parserType != QMetaType::QDate) { const Section hour = (sect == 'h') ? Hour12Section : Hour24Section; const SectionNode sn = { hour, i - add, countRepeat(newFormat, i, 2), 0 }; newSectionNodes.append(sn); @@ -436,7 +436,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat) } break; case 'm': - if (parserType != QVariant::Date) { + if (parserType != QMetaType::QDate) { const SectionNode sn = { MinuteSection, i - add, countRepeat(newFormat, i, 2), 0 }; newSectionNodes.append(sn); appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote); @@ -446,7 +446,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat) } break; case 's': - if (parserType != QVariant::Date) { + if (parserType != QMetaType::QDate) { const SectionNode sn = { SecondSection, i - add, countRepeat(newFormat, i, 2), 0 }; newSectionNodes.append(sn); appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote); @@ -457,7 +457,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat) break; case 'z': - if (parserType != QVariant::Date) { + if (parserType != QMetaType::QDate) { const SectionNode sn = { MSecSection, i - add, countRepeat(newFormat, i, 3) < 3 ? 1 : 3, 0 }; newSectionNodes.append(sn); appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote); @@ -468,7 +468,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat) break; case 'A': case 'a': - if (parserType != QVariant::Date) { + if (parserType != QMetaType::QDate) { const bool cap = (sect == 'A'); const SectionNode sn = { AmPmSection, i - add, (cap ? 1 : 0), 0 }; newSectionNodes.append(sn); @@ -482,7 +482,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat) } break; case 'y': - if (parserType != QVariant::Time) { + if (parserType != QMetaType::QTime) { const int repeat = countRepeat(newFormat, i, 4); if (repeat >= 2) { const SectionNode sn = { repeat == 4 ? YearSection : YearSection2Digits, @@ -496,7 +496,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat) } break; case 'M': - if (parserType != QVariant::Time) { + if (parserType != QMetaType::QTime) { const SectionNode sn = { MonthSection, i - add, countRepeat(newFormat, i, 4), 0 }; newSectionNodes.append(sn); newSeparators.append(unquote(newFormat.midRef(index, i - index))); @@ -506,7 +506,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat) } break; case 'd': - if (parserType != QVariant::Time) { + if (parserType != QMetaType::QTime) { const int repeat = countRepeat(newFormat, i, 4); const Section sectionType = (repeat == 4 ? DayOfWeekSectionLong : (repeat == 3 ? DayOfWeekSectionShort : DaySection)); @@ -519,7 +519,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat) } break; case 't': - if (parserType != QVariant::Time) { + if (parserType != QMetaType::QTime) { const SectionNode sn = { TimeZoneSection, i - add, countRepeat(newFormat, i, 4), 0 }; newSectionNodes.append(sn); appendSeparator(&newSeparators, newFormat, index, i - index, lastQuote); @@ -1252,7 +1252,7 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, return StateNode(); } - if (parserType != QVariant::Time) { + if (parserType != QMetaType::QTime) { if (year % 100 != year2digits && (isSet & YearSection2Digits)) { if (!(isSet & YearSection)) { year = (year / 100) * 100; @@ -1322,7 +1322,7 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, } } - if (parserType != QVariant::Date) { + if (parserType != QMetaType::QDate) { if (isSet & Hour12Section) { const bool hasHour = isSet & Hour24Section; if (ampm == -1) { @@ -1360,7 +1360,7 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, // If hour wasn't specified, check the default we're using exists on the // given date (which might be a spring-forward, skipping an hour). - if (parserType == QVariant::DateTime && !(isSet & HourSectionMask) && !when.isValid()) { + if (parserType == QMetaType::QDateTime && !(isSet & HourSectionMask) && !when.isValid()) { qint64 msecs = when.toMSecsSinceEpoch(); // Fortunately, that gets a useful answer, even though when is invalid ... const QDateTime replace = diff --git a/src/corelib/time/qdatetimeparser_p.h b/src/corelib/time/qdatetimeparser_p.h index ec4e4e4df2..5c612ef6a4 100644 --- a/src/corelib/time/qdatetimeparser_p.h +++ b/src/corelib/time/qdatetimeparser_p.h @@ -83,7 +83,7 @@ public: FromString, DateTimeEdit }; - QDateTimeParser(QVariant::Type t, Context ctx, const QCalendar &cal = QCalendar()) + QDateTimeParser(QMetaType::Type t, Context ctx, const QCalendar &cal = QCalendar()) : currentSectionIndex(-1), cachedDay(-1), parserType(t), fixday(false), spec(Qt::LocalTime), context(ctx), calendar(cal) { @@ -295,7 +295,7 @@ protected: // for the benefit of QDateTimeEditPrivate QStringList separators; QString displayFormat; QLocale defaultLocale; - QVariant::Type parserType; + QMetaType::Type parserType; bool fixday; Qt::TimeSpec spec; // spec if used by QDateTimeEdit Context context; diff --git a/src/dbus/qdbusabstractinterface.cpp b/src/dbus/qdbusabstractinterface.cpp index 8a11767140..d603264a1e 100644 --- a/src/dbus/qdbusabstractinterface.cpp +++ b/src/dbus/qdbusabstractinterface.cpp @@ -157,7 +157,7 @@ bool QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, void *retu const int type = mp.userType(); // is this metatype registered? const char *expectedSignature = ""; - if (int(mp.type()) != QMetaType::QVariant) { + if (int(mp.userType()) != QMetaType::QVariant) { expectedSignature = QDBusMetaType::typeToSignature(type); if (expectedSignature == nullptr) { qWarning("QDBusAbstractInterface: type %s must be registered with Qt D-Bus before it can be " diff --git a/src/dbus/qdbusargument.h b/src/dbus/qdbusargument.h index 477bd1e8fd..339f8c5dc8 100644 --- a/src/dbus/qdbusargument.h +++ b/src/dbus/qdbusargument.h @@ -330,7 +330,7 @@ inline const QDBusArgument &operator>>(const QDBusArgument &arg, QMap &m inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantMap &map) { - arg.beginMap(QVariant::String, qMetaTypeId()); + arg.beginMap(QMetaType::QString, qMetaTypeId()); QVariantMap::ConstIterator it = map.constBegin(); QVariantMap::ConstIterator end = map.constEnd(); for ( ; it != end; ++it) { @@ -379,7 +379,7 @@ inline const QDBusArgument &operator>>(const QDBusArgument &arg, QHash & inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantHash &map) { - arg.beginMap(QVariant::String, qMetaTypeId()); + arg.beginMap(QMetaType::QString, qMetaTypeId()); QVariantHash::ConstIterator it = map.constBegin(); QVariantHash::ConstIterator end = map.constEnd(); for ( ; it != end; ++it) { diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index bca02be59e..669b330f1d 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -1822,7 +1822,7 @@ void QDBusConnectionPrivate::setConnection(DBusConnection *dbc, const QDBusError hook.service = QDBusUtil::dbusService(); hook.path.clear(); // no matching hook.obj = this; - hook.params << QMetaType::Void << QVariant::String; // both functions take a QString as parameter and return void + hook.params << QMetaType::Void << QMetaType::QString; // both functions take a QString as parameter and return void hook.midx = staticMetaObject.indexOfSlot("registerServiceNoLock(QString)"); Q_ASSERT(hook.midx != -1); @@ -1836,7 +1836,7 @@ void QDBusConnectionPrivate::setConnection(DBusConnection *dbc, const QDBusError // we don't use connectSignal here because the rules are added by connectSignal on a per-need basis hook.params.clear(); hook.params.reserve(4); - hook.params << QMetaType::Void << QVariant::String << QVariant::String << QVariant::String; + hook.params << QMetaType::Void << QMetaType::QString << QMetaType::QString << QMetaType::QString; hook.midx = staticMetaObject.indexOfSlot("serviceOwnerChangedNoLock(QString,QString,QString)"); Q_ASSERT(hook.midx != -1); signalHooks.insert(QLatin1String("NameOwnerChanged:" DBUS_INTERFACE_DBUS), hook); diff --git a/src/dbus/qdbusinterface.cpp b/src/dbus/qdbusinterface.cpp index fb958a8954..c1b0feea37 100644 --- a/src/dbus/qdbusinterface.cpp +++ b/src/dbus/qdbusinterface.cpp @@ -55,7 +55,7 @@ static void copyArgument(void *to, int id, const QVariant &arg) { if (id == arg.userType()) { switch (id) { - case QVariant::Bool: + case QMetaType::Bool: *reinterpret_cast(to) = arg.toBool(); return; @@ -71,35 +71,35 @@ static void copyArgument(void *to, int id, const QVariant &arg) *reinterpret_cast(to) = qvariant_cast(arg); return; - case QVariant::Int: + case QMetaType::Int: *reinterpret_cast(to) = arg.toInt(); return; - case QVariant::UInt: + case QMetaType::UInt: *reinterpret_cast(to) = arg.toUInt(); return; - case QVariant::LongLong: + case QMetaType::LongLong: *reinterpret_cast(to) = arg.toLongLong(); return; - case QVariant::ULongLong: + case QMetaType::ULongLong: *reinterpret_cast(to) = arg.toULongLong(); return; - case QVariant::Double: + case QMetaType::Double: *reinterpret_cast(to) = arg.toDouble(); return; - case QVariant::String: + case QMetaType::QString: *reinterpret_cast(to) = arg.toString(); return; - case QVariant::ByteArray: + case QMetaType::QByteArray: *reinterpret_cast(to) = arg.toByteArray(); return; - case QVariant::StringList: + case QMetaType::QStringList: *reinterpret_cast(to) = arg.toStringList(); return; } diff --git a/src/dbus/qdbusmarshaller.cpp b/src/dbus/qdbusmarshaller.cpp index 46b41d1c07..c80131f41d 100644 --- a/src/dbus/qdbusmarshaller.cpp +++ b/src/dbus/qdbusmarshaller.cpp @@ -190,7 +190,7 @@ inline bool QDBusMarshaller::append(const QDBusVariant &arg) const QVariant &value = arg.variant(); int id = value.userType(); - if (id == QVariant::Invalid) { + if (id == QMetaType::UnknownType) { qWarning("QDBusMarshaller: cannot add a null QDBusVariant"); error(QLatin1String("Variant containing QVariant::Invalid passed in arguments")); return false; @@ -384,7 +384,7 @@ void QDBusMarshaller::error(const QString &msg) bool QDBusMarshaller::appendVariantInternal(const QVariant &arg) { int id = arg.userType(); - if (id == QVariant::Invalid) { + if (id == QMetaType::UnknownType) { qWarning("QDBusMarshaller: cannot add an invalid QVariant"); error(QLatin1String("Variant containing QVariant::Invalid passed in arguments")); return false; @@ -485,12 +485,12 @@ bool QDBusMarshaller::appendVariantInternal(const QVariant &arg) case DBUS_TYPE_ARRAY: // could be many things // find out what kind of array it is - switch (arg.type()) { - case QVariant::StringList: + switch (arg.userType()) { + case QMetaType::QStringList: append( arg.toStringList() ); return true; - case QVariant::ByteArray: + case QMetaType::QByteArray: append( arg.toByteArray() ); return true; diff --git a/src/dbus/qdbusmessage.cpp b/src/dbus/qdbusmessage.cpp index 71cdec93ca..10d2f07d4d 100644 --- a/src/dbus/qdbusmessage.cpp +++ b/src/dbus/qdbusmessage.cpp @@ -276,7 +276,7 @@ QDBusMessage QDBusMessagePrivate::makeLocal(const QDBusConnectionPrivate &conn, for ( ; it != end; ++it) { int id = it->userType(); const char *signature = QDBusMetaType::typeToSignature(id); - if ((id != QVariant::StringList && id != QVariant::ByteArray && + if ((id != QMetaType::QStringList && id != QMetaType::QByteArray && qstrlen(signature) != 1) || id == qMetaTypeId()) { // yes, we are // we must marshall and demarshall again so as to create QDBusArgument diff --git a/src/dbus/qdbusmetaobject.cpp b/src/dbus/qdbusmetaobject.cpp index 3c529ab755..5265568f42 100644 --- a/src/dbus/qdbusmetaobject.cpp +++ b/src/dbus/qdbusmetaobject.cpp @@ -158,10 +158,10 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature, const char *direction, int id) { Type result; - result.id = QVariant::Invalid; + result.id = QMetaType::UnknownType; int type = QDBusMetaType::signatureToType(signature); - if (type == QVariant::Invalid && !qt_dbus_metaobject_skip_annotations) { + if (type == QMetaType::UnknownType && !qt_dbus_metaobject_skip_annotations) { // it's not a type normally handled by our meta type system // it must contain an annotation QString annotationName = QString::fromLatin1("org.qtproject.QtDBus.QtTypeName"); @@ -189,7 +189,7 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature, type = QMetaType::type(typeName); } - if (type == QVariant::Invalid || signature != QDBusMetaType::typeToSignature(type)) { + if (type == QMetaType::UnknownType || signature != QDBusMetaType::typeToSignature(type)) { // type is still unknown or doesn't match back to the signature that it // was expected to, so synthesize a fake type typeName = "QDBusRawType<0x" + signature.toHex() + ">*"; @@ -197,16 +197,16 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature, } result.name = typeName; - } else if (type == QVariant::Invalid) { + } else if (type == QMetaType::UnknownType) { // this case is used only by the qdbus command-line tool // invalid, let's create an impossible type that contains the signature if (signature == "av") { result.name = "QVariantList"; - type = QVariant::List; + type = QMetaType::QVariantList; } else if (signature == "a{sv}") { result.name = "QVariantMap"; - type = QVariant::Map; + type = QMetaType::QVariantMap; } else if (signature == "a{ss}") { result.name = "QMap"; type = qMetaTypeId >(); @@ -246,7 +246,7 @@ void QDBusMetaObjectGenerator::parseMethods() const QDBusIntrospection::Argument &arg = m.inputArgs.at(i); Type type = findType(arg.type.toLatin1(), m.annotations, "In", i); - if (type.id == QVariant::Invalid) { + if (type.id == QMetaType::UnknownType) { ok = false; break; } @@ -265,7 +265,7 @@ void QDBusMetaObjectGenerator::parseMethods() const QDBusIntrospection::Argument &arg = m.outputArgs.at(i); Type type = findType(arg.type.toLatin1(), m.annotations, "Out", i); - if (type.id == QVariant::Invalid) { + if (type.id == QMetaType::UnknownType) { ok = false; break; } @@ -322,7 +322,7 @@ void QDBusMetaObjectGenerator::parseSignals() const QDBusIntrospection::Argument &arg = s.outputArgs.at(i); Type type = findType(arg.type.toLatin1(), s.annotations, "Out", i); - if (type.id == QVariant::Invalid) { + if (type.id == QMetaType::UnknownType) { ok = false; break; } @@ -358,7 +358,7 @@ void QDBusMetaObjectGenerator::parseProperties() const QDBusIntrospection::Property &p = *prop_it; Property mp; Type type = findType(p.type.toLatin1(), p.annotations); - if (type.id == QVariant::Invalid) + if (type.id == QMetaType::UnknownType) continue; QByteArray name = p.name.toLatin1(); diff --git a/src/dbus/qdbusmetatype.cpp b/src/dbus/qdbusmetatype.cpp index e3804f74f8..bcbb22fba6 100644 --- a/src/dbus/qdbusmetatype.cpp +++ b/src/dbus/qdbusmetatype.cpp @@ -325,7 +325,7 @@ int QDBusMetaType::signatureToType(const char *signature) switch (signature[0]) { case DBUS_TYPE_BOOLEAN: - return QVariant::Bool; + return QMetaType::Bool; case DBUS_TYPE_BYTE: return QMetaType::UChar; @@ -337,22 +337,22 @@ int QDBusMetaType::signatureToType(const char *signature) return QMetaType::UShort; case DBUS_TYPE_INT32: - return QVariant::Int; + return QMetaType::Int; case DBUS_TYPE_UINT32: - return QVariant::UInt; + return QMetaType::UInt; case DBUS_TYPE_INT64: - return QVariant::LongLong; + return QMetaType::LongLong; case DBUS_TYPE_UINT64: - return QVariant::ULongLong; + return QMetaType::ULongLong; case DBUS_TYPE_DOUBLE: - return QVariant::Double; + return QMetaType::Double; case DBUS_TYPE_STRING: - return QVariant::String; + return QMetaType::QString; case DBUS_TYPE_OBJECT_PATH: return QDBusMetaTypeId::objectpath(); @@ -369,13 +369,13 @@ int QDBusMetaType::signatureToType(const char *signature) case DBUS_TYPE_ARRAY: // special case switch (signature[1]) { case DBUS_TYPE_BYTE: - return QVariant::ByteArray; + return QMetaType::QByteArray; case DBUS_TYPE_STRING: - return QVariant::StringList; + return QMetaType::QStringList; case DBUS_TYPE_VARIANT: - return QVariant::List; + return QMetaType::QVariantList; case DBUS_TYPE_OBJECT_PATH: return qMetaTypeId >(); @@ -409,7 +409,7 @@ const char *QDBusMetaType::typeToSignature(int type) case QMetaType::UChar: return DBUS_TYPE_BYTE_AS_STRING; - case QVariant::Bool: + case QMetaType::Bool: return DBUS_TYPE_BOOLEAN_AS_STRING; case QMetaType::Short: @@ -418,29 +418,29 @@ const char *QDBusMetaType::typeToSignature(int type) case QMetaType::UShort: return DBUS_TYPE_UINT16_AS_STRING; - case QVariant::Int: + case QMetaType::Int: return DBUS_TYPE_INT32_AS_STRING; - case QVariant::UInt: + case QMetaType::UInt: return DBUS_TYPE_UINT32_AS_STRING; - case QVariant::LongLong: + case QMetaType::LongLong: return DBUS_TYPE_INT64_AS_STRING; - case QVariant::ULongLong: + case QMetaType::ULongLong: return DBUS_TYPE_UINT64_AS_STRING; - case QVariant::Double: + case QMetaType::Double: return DBUS_TYPE_DOUBLE_AS_STRING; - case QVariant::String: + case QMetaType::QString: return DBUS_TYPE_STRING_AS_STRING; - case QVariant::StringList: + case QMetaType::QStringList: return DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING; // as - case QVariant::ByteArray: + case QMetaType::QByteArray: return DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING; // ay } diff --git a/src/dbus/qdbusutil.cpp b/src/dbus/qdbusutil.cpp index 09311d1ad4..b4ee6811ac 100644 --- a/src/dbus/qdbusutil.cpp +++ b/src/dbus/qdbusutil.cpp @@ -82,7 +82,7 @@ static bool variantToString(const QVariant &arg, QString &out) { int argType = arg.userType(); - if (argType == QVariant::StringList) { + if (argType == QMetaType::QStringList) { out += QLatin1Char('{'); const QStringList list = arg.toStringList(); for (const QString &item : list) @@ -90,7 +90,7 @@ static bool variantToString(const QVariant &arg, QString &out) if (!list.isEmpty()) out.chop(2); out += QLatin1Char('}'); - } else if (argType == QVariant::ByteArray) { + } else if (argType == QMetaType::QByteArray) { out += QLatin1Char('{'); QByteArray list = arg.toByteArray(); for (int i = 0; i < list.count(); ++i) { @@ -100,7 +100,7 @@ static bool variantToString(const QVariant &arg, QString &out) if (!list.isEmpty()) out.chop(2); out += QLatin1Char('}'); - } else if (argType == QVariant::List) { + } else if (argType == QMetaType::QVariantList) { out += QLatin1Char('{'); const QList list = arg.toList(); for (const QVariant &item : list) { @@ -148,7 +148,7 @@ static bool variantToString(const QVariant &arg, QString &out) if (!variantToString(v, out)) return false; out += QLatin1Char(']'); - } else if (arg.canConvert(QVariant::String)) { + } else if (arg.canConvert(QMetaType::QString)) { out += QLatin1Char('\"') + arg.toString() + QLatin1Char('\"'); } else { out += QLatin1Char('['); diff --git a/src/dbus/qdbusxmlgenerator.cpp b/src/dbus/qdbusxmlgenerator.cpp index c6b3b90508..7370ce0de3 100644 --- a/src/dbus/qdbusxmlgenerator.cpp +++ b/src/dbus/qdbusxmlgenerator.cpp @@ -113,7 +113,7 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method QLatin1String(signature), accessAsString(mp.isReadable(), mp.isWritable())); - if (QDBusMetaType::signatureToType(signature) == QVariant::Invalid) { + if (QDBusMetaType::signatureToType(signature) == QMetaType::UnknownType) { const char *typeName = QMetaType::typeName(typeId); retval += QLatin1String(">\n \n \n") .arg(typeNameToXml(typeName)); @@ -161,7 +161,7 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method .arg(typeNameToXml(typeName)); // do we need to describe this argument? - if (QDBusMetaType::signatureToType(typeName) == QVariant::Invalid) + if (QDBusMetaType::signatureToType(typeName) == QMetaType::UnknownType) xml += QLatin1String(" \n") .arg(typeNameToXml(QMetaType::typeName(typeId))); } else { @@ -208,7 +208,7 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method qUtf16Printable(name), signature, isOutput ? "out" : "in"); // do we need to describe this argument? - if (QDBusMetaType::signatureToType(signature) == QVariant::Invalid) { + if (QDBusMetaType::signatureToType(signature) == QMetaType::UnknownType) { const char *typeName = QMetaType::typeName(types.at(j)); xml += QString::fromLatin1(" \n") .arg(isOutput ? QLatin1String("Out") : QLatin1String("In")) diff --git a/src/gui/image/qbitmap.cpp b/src/gui/image/qbitmap.cpp index 455045eb57..a44f7151b1 100644 --- a/src/gui/image/qbitmap.cpp +++ b/src/gui/image/qbitmap.cpp @@ -218,7 +218,7 @@ QBitmap::~QBitmap() */ QBitmap::operator QVariant() const { - return QVariant(QVariant::Bitmap, this); + return QVariant(QMetaType::QBitmap, this); } static QBitmap makeBitmap(QImage &&image, Qt::ImageConversionFlags flags) diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 19be066d23..38285dd827 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -782,7 +782,7 @@ QIcon &QIcon::operator=(const QIcon &other) */ QIcon::operator QVariant() const { - return QVariant(QVariant::Icon, this); + return QVariant(QMetaType::QIcon, this); } /*! \fn int QIcon::serialNumber() const diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 3ddc52bed4..62d2d0e948 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -1067,7 +1067,7 @@ int QImage::devType() const */ QImage::operator QVariant() const { - return QVariant(QVariant::Image, this); + return QVariant(QMetaType::QImage, this); } /*! diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 3fce64cb20..e914d7697f 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -402,7 +402,7 @@ QPixmap &QPixmap::operator=(const QPixmap &pixmap) */ QPixmap::operator QVariant() const { - return QVariant(QVariant::Pixmap, this); + return QVariant(QMetaType::QPixmap, this); } /*! diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp index 9bdc22b49e..fc9424763e 100644 --- a/src/gui/itemmodels/qstandarditemmodel.cpp +++ b/src/gui/itemmodels/qstandarditemmodel.cpp @@ -926,7 +926,7 @@ void QStandardItem::setData(const QVariant &value, int role) for (it = d->values.begin(); it != d->values.end(); ++it) { if ((*it).role == role) { if (value.isValid()) { - if ((*it).value.type() == value.type() && (*it).value == value) + if ((*it).value.userType() == value.userType() && (*it).value == value) return; (*it).value = value; } else { diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp index f5a794b642..339284aa30 100644 --- a/src/gui/kernel/qcursor.cpp +++ b/src/gui/kernel/qcursor.cpp @@ -657,7 +657,7 @@ QCursor &QCursor::operator=(const QCursor &c) */ QCursor::operator QVariant() const { - return QVariant(QVariant::Cursor, this); + return QVariant(QMetaType::QCursor, this); } #ifndef QT_NO_DEBUG_STREAM diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index 4ed9d032f6..596b7e44fd 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -178,25 +178,25 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) { switch (t) { - case QVariant::ByteArray: - if (d->type == QVariant::Color) { + case QMetaType::QByteArray: + if (d->type == QMetaType::QColor) { const QColor *c = v_cast(d); *static_cast(result) = c->name(c->alpha() != 255 ? QColor::HexArgb : QColor::HexRgb).toLatin1(); return true; } break; - case QVariant::String: { + case QMetaType::QString: { QString *str = static_cast(result); switch (d->type) { #ifndef QT_NO_SHORTCUT - case QVariant::KeySequence: + case QMetaType::QKeySequence: *str = (*v_cast(d)).toString(QKeySequence::NativeText); return true; #endif - case QVariant::Font: + case QMetaType::QFont: *str = v_cast(d)->toString(); return true; - case QVariant::Color: { + case QMetaType::QColor: { const QColor *c = v_cast(d); *str = c->name(c->alpha() != 255 ? QColor::HexArgb : QColor::HexRgb); return true; @@ -206,85 +206,85 @@ static bool convert(const QVariant::Private *d, int t, } break; } - case QVariant::Pixmap: - if (d->type == QVariant::Image) { + case QMetaType::QPixmap: + if (d->type == QMetaType::QImage) { *static_cast(result) = QPixmap::fromImage(*v_cast(d)); return true; - } else if (d->type == QVariant::Bitmap) { + } else if (d->type == QMetaType::QBitmap) { *static_cast(result) = *v_cast(d); return true; - } else if (d->type == QVariant::Brush) { + } else if (d->type == QMetaType::QBrush) { if (v_cast(d)->style() == Qt::TexturePattern) { *static_cast(result) = v_cast(d)->texture(); return true; } } break; - case QVariant::Image: - if (d->type == QVariant::Pixmap) { + case QMetaType::QImage: + if (d->type == QMetaType::QPixmap) { *static_cast(result) = v_cast(d)->toImage(); return true; - } else if (d->type == QVariant::Bitmap) { + } else if (d->type == QMetaType::QBitmap) { *static_cast(result) = v_cast(d)->toImage(); return true; } break; - case QVariant::Bitmap: - if (d->type == QVariant::Pixmap) { + case QMetaType::QBitmap: + if (d->type == QMetaType::QPixmap) { *static_cast(result) = *v_cast(d); return true; - } else if (d->type == QVariant::Image) { + } else if (d->type == QMetaType::QImage) { *static_cast(result) = QBitmap::fromImage(*v_cast(d)); return true; } break; #ifndef QT_NO_SHORTCUT - case QVariant::Int: - if (d->type == QVariant::KeySequence) { + case QMetaType::Int: + if (d->type == QMetaType::QKeySequence) { const QKeySequence &seq = *v_cast(d); *static_cast(result) = seq.isEmpty() ? 0 : seq[0]; return true; } break; #endif - case QVariant::Font: - if (d->type == QVariant::String) { + case QMetaType::QFont: + if (d->type == QMetaType::QString) { QFont *f = static_cast(result); f->fromString(*v_cast(d)); return true; } break; - case QVariant::Color: - if (d->type == QVariant::String) { + case QMetaType::QColor: + if (d->type == QMetaType::QString) { static_cast(result)->setNamedColor(*v_cast(d)); return static_cast(result)->isValid(); - } else if (d->type == QVariant::ByteArray) { + } else if (d->type == QMetaType::QByteArray) { static_cast(result)->setNamedColor(QLatin1String(*v_cast(d))); return true; - } else if (d->type == QVariant::Brush) { + } else if (d->type == QMetaType::QBrush) { if (v_cast(d)->style() == Qt::SolidPattern) { *static_cast(result) = v_cast(d)->color(); return true; } } break; - case QVariant::Brush: - if (d->type == QVariant::Color) { + case QMetaType::QBrush: + if (d->type == QMetaType::QColor) { *static_cast(result) = QBrush(*v_cast(d)); return true; - } else if (d->type == QVariant::Pixmap) { + } else if (d->type == QMetaType::QPixmap) { *static_cast(result) = QBrush(*v_cast(d)); return true; } break; #ifndef QT_NO_SHORTCUT - case QVariant::KeySequence: { + case QMetaType::QKeySequence: { QKeySequence *seq = static_cast(result); switch (d->type) { - case QVariant::String: + case QMetaType::QString: *seq = QKeySequence(*v_cast(d)); return true; - case QVariant::Int: + case QMetaType::Int: *seq = QKeySequence(d->data.i); return true; default: @@ -294,7 +294,7 @@ static bool convert(const QVariant::Private *d, int t, } #endif #ifndef QT_NO_ICON - case QVariant::Icon: { + case QMetaType::QIcon: { if (ok) *ok = false; return false; diff --git a/src/gui/kernel/qinternalmimedata.cpp b/src/gui/kernel/qinternalmimedata.cpp index 8f4da1afb5..d5cdc743ee 100644 --- a/src/gui/kernel/qinternalmimedata.cpp +++ b/src/gui/kernel/qinternalmimedata.cpp @@ -112,22 +112,23 @@ QVariant QInternalMimeData::retrieveData(const QString &mimeType, QVariant::Type { QVariant data = retrieveData_sys(mimeType, type); if (mimeType == QLatin1String("application/x-qt-image")) { - if (data.isNull() || (data.type() == QVariant::ByteArray && data.toByteArray().isEmpty())) { + if (data.isNull() || (data.userType() == QMetaType::QByteArray && data.toByteArray().isEmpty())) { // try to find an image QStringList imageFormats = imageReadMimeFormats(); for (int i = 0; i < imageFormats.size(); ++i) { data = retrieveData_sys(imageFormats.at(i), type); - if (data.isNull() || (data.type() == QVariant::ByteArray && data.toByteArray().isEmpty())) + if (data.isNull() || (data.userType() == QMetaType::QByteArray && data.toByteArray().isEmpty())) continue; break; } } + int typeId = type; // we wanted some image type, but all we got was a byte array. Convert it to an image. - if (data.type() == QVariant::ByteArray - && (type == QVariant::Image || type == QVariant::Pixmap || type == QVariant::Bitmap)) + if (data.userType() == QMetaType::QByteArray + && (typeId == QMetaType::QImage || typeId == QMetaType::QPixmap || typeId == QMetaType::QBitmap)) data = QImage::fromData(data.toByteArray()); - } else if (mimeType == QLatin1String("application/x-color") && data.type() == QVariant::ByteArray) { + } else if (mimeType == QLatin1String("application/x-color") && data.userType() == QMetaType::QByteArray) { QColor c; QByteArray ba = data.toByteArray(); if (ba.size() == 8) { @@ -140,7 +141,7 @@ QVariant QInternalMimeData::retrieveData(const QString &mimeType, QVariant::Type } else { qWarning("Qt: Invalid color format"); } - } else if (data.type() != type && data.type() == QVariant::ByteArray) { + } else if (data.userType() != int(type) && data.userType() == QMetaType::QByteArray) { // try to use mime data's internal conversion stuf. QInternalMimeData *that = const_cast(this); that->setData(mimeType, data.toByteArray()); diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp index e1244e1006..3a3dd42cae 100644 --- a/src/gui/kernel/qkeysequence.cpp +++ b/src/gui/kernel/qkeysequence.cpp @@ -1404,7 +1404,7 @@ QKeySequence::SequenceMatch QKeySequence::matches(const QKeySequence &seq) const */ QKeySequence::operator QVariant() const { - return QVariant(QVariant::KeySequence, this); + return QVariant(QMetaType::QKeySequence, this); } /*! \fn QKeySequence::operator int () const diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp index fc063bc72c..397c50f3dc 100644 --- a/src/gui/kernel/qpalette.cpp +++ b/src/gui/kernel/qpalette.cpp @@ -714,7 +714,7 @@ QPalette &QPalette::operator=(const QPalette &p) */ QPalette::operator QVariant() const { - return QVariant(QVariant::Palette, this); + return QVariant(QMetaType::QPalette, this); } /*! diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index ad4cdfdbf4..6666eb037f 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -2007,7 +2007,7 @@ void QMatrix4x4::optimize() */ QMatrix4x4::operator QVariant() const { - return QVariant(QVariant::Matrix4x4, this); + return QVariant(QMetaType::QMatrix4x4, this); } #ifndef QT_NO_DEBUG_STREAM diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp index 899ec12eb3..5f15949c5b 100644 --- a/src/gui/math3d/qquaternion.cpp +++ b/src/gui/math3d/qquaternion.cpp @@ -983,7 +983,7 @@ QQuaternion QQuaternion::nlerp */ QQuaternion::operator QVariant() const { - return QVariant(QVariant::Quaternion, this); + return QVariant(QMetaType::QQuaternion, this); } #ifndef QT_NO_DEBUG_STREAM diff --git a/src/gui/math3d/qvector2d.cpp b/src/gui/math3d/qvector2d.cpp index c04f8b1cbf..5f651cf376 100644 --- a/src/gui/math3d/qvector2d.cpp +++ b/src/gui/math3d/qvector2d.cpp @@ -531,7 +531,7 @@ QVector4D QVector2D::toVector4D() const */ QVector2D::operator QVariant() const { - return QVariant(QVariant::Vector2D, this); + return QVariant(QMetaType::QVector2D, this); } #ifndef QT_NO_DEBUG_STREAM diff --git a/src/gui/math3d/qvector3d.cpp b/src/gui/math3d/qvector3d.cpp index 4f72c1da66..08c3de99d2 100644 --- a/src/gui/math3d/qvector3d.cpp +++ b/src/gui/math3d/qvector3d.cpp @@ -706,7 +706,7 @@ QVector4D QVector3D::toVector4D() const */ QVector3D::operator QVariant() const { - return QVariant(QVariant::Vector3D, this); + return QVariant(QMetaType::QVector3D, this); } /*! diff --git a/src/gui/math3d/qvector4d.cpp b/src/gui/math3d/qvector4d.cpp index 3a68bd6cb7..070ea7454e 100644 --- a/src/gui/math3d/qvector4d.cpp +++ b/src/gui/math3d/qvector4d.cpp @@ -608,7 +608,7 @@ QVector3D QVector4D::toVector3DAffine() const */ QVector4D::operator QVariant() const { - return QVariant(QVariant::Vector4D, this); + return QVariant(QMetaType::QVector4D, this); } #ifndef QT_NO_DEBUG_STREAM diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index 83032bdc4f..e84916e063 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -672,7 +672,7 @@ QBrush &QBrush::operator=(const QBrush &b) */ QBrush::operator QVariant() const { - return QVariant(QVariant::Brush, this); + return QVariant(QMetaType::QBrush, this); } /*! diff --git a/src/gui/painting/qcolor.cpp b/src/gui/painting/qcolor.cpp index 8780cce223..917706e8cf 100644 --- a/src/gui/painting/qcolor.cpp +++ b/src/gui/painting/qcolor.cpp @@ -2980,7 +2980,7 @@ bool QColor::operator!=(const QColor &color) const noexcept */ QColor::operator QVariant() const { - return QVariant(QVariant::Color, this); + return QVariant(QMetaType::QColor, this); } /*! \internal diff --git a/src/gui/painting/qmatrix.cpp b/src/gui/painting/qmatrix.cpp index b1f01332b6..890b0079de 100644 --- a/src/gui/painting/qmatrix.cpp +++ b/src/gui/painting/qmatrix.cpp @@ -1087,7 +1087,7 @@ QMatrix &QMatrix::operator=(const QMatrix &matrix) noexcept */ QMatrix::operator QVariant() const { - return QVariant(QVariant::Matrix, this); + return QVariant(QMetaType::QMatrix, this); } Q_GUI_EXPORT QPainterPath operator *(const QPainterPath &p, const QMatrix &m) diff --git a/src/gui/painting/qpen.cpp b/src/gui/painting/qpen.cpp index 1a940443d1..01e581d2ed 100644 --- a/src/gui/painting/qpen.cpp +++ b/src/gui/painting/qpen.cpp @@ -408,7 +408,7 @@ QPen &QPen::operator=(const QPen &p) noexcept */ QPen::operator QVariant() const { - return QVariant(QVariant::Pen, this); + return QVariant(QMetaType::QPen, this); } /*! diff --git a/src/gui/painting/qpolygon.cpp b/src/gui/painting/qpolygon.cpp index 3bf6004fcc..20337477b7 100644 --- a/src/gui/painting/qpolygon.cpp +++ b/src/gui/painting/qpolygon.cpp @@ -716,7 +716,7 @@ QPolygon QPolygonF::toPolygon() const */ QPolygon::operator QVariant() const { - return QVariant(QVariant::Polygon, this); + return QVariant(QMetaType::QPolygon, this); } /***************************************************************************** diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp index 783b02fb93..44ee038194 100644 --- a/src/gui/painting/qregion.cpp +++ b/src/gui/painting/qregion.cpp @@ -599,7 +599,7 @@ QRegion& QRegion::operator^=(const QRegion &r) */ QRegion::operator QVariant() const { - return QVariant(QVariant::Region, this); + return QVariant(QMetaType::QRegion, this); } /*! diff --git a/src/gui/painting/qtransform.cpp b/src/gui/painting/qtransform.cpp index d75b66c50b..279a817ff1 100644 --- a/src/gui/painting/qtransform.cpp +++ b/src/gui/painting/qtransform.cpp @@ -2155,7 +2155,7 @@ QTransform::TransformationType QTransform::type() const */ QTransform::operator QVariant() const { - return QVariant(QVariant::Transform, this); + return QVariant(QMetaType::QTransform, this); } diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index c0b0071e4d..a12eb98528 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -707,7 +707,7 @@ static Qt::Alignment parseAlignment(const QCss::Value *values, int count) static ColorData parseColorValue(QCss::Value v) { if (v.type == Value::Identifier || v.type == Value::String) { - v.variant.convert(QVariant::Color); + v.variant.convert(QMetaType::QColor); v.type = Value::Color; } @@ -1143,7 +1143,7 @@ static bool setFontSizeFromValue(QCss::Value value, QFont *font, int *fontSizeAd } else if (s.endsWith(QLatin1String("px"), Qt::CaseInsensitive)) { s.chop(2); value.variant = s; - if (value.variant.convert(QVariant::Int)) { + if (value.variant.convert(QMetaType::Int)) { font->setPixelSize(value.variant.toInt()); valid = true; } @@ -1420,9 +1420,9 @@ QColor Declaration::colorValue(const QPalette &pal) const return QColor(); if (d->parsed.isValid()) { - if (d->parsed.type() == QVariant::Color) + if (d->parsed.userType() == QMetaType::QColor) return qvariant_cast(d->parsed); - if (d->parsed.type() == QVariant::Int) + if (d->parsed.userType() == QMetaType::Int) return pal.color((QPalette::ColorRole)(d->parsed.toInt())); } @@ -1442,9 +1442,9 @@ QBrush Declaration::brushValue(const QPalette &pal) const return QBrush(); if (d->parsed.isValid()) { - if (d->parsed.type() == QVariant::Brush) + if (d->parsed.userType() == QMetaType::QBrush) return qvariant_cast(d->parsed); - if (d->parsed.type() == QVariant::Int) + if (d->parsed.userType() == QMetaType::Int) return pal.color((QPalette::ColorRole)(d->parsed.toInt())); } @@ -1469,9 +1469,9 @@ void Declaration::brushValues(QBrush *c, const QPalette &pal) const needParse = 0; QList v = d->parsed.toList(); for (i = 0; i < qMin(v.count(), 4); i++) { - if (v.at(i).type() == QVariant::Brush) { + if (v.at(i).userType() == QMetaType::QBrush) { c[i] = qvariant_cast(v.at(i)); - } else if (v.at(i).type() == QVariant::Int) { + } else if (v.at(i).userType() == QMetaType::Int) { c[i] = pal.color((QPalette::ColorRole)(v.at(i).toInt())); } else { needParse |= (1<parsed.isValid()) { QList v = d->parsed.toList(); for (i = 0; i < qMin(d->values.count(), 4); i++) { - if (v.at(i).type() == QVariant::Color) { + if (v.at(i).userType() == QMetaType::QColor) { c[i] = qvariant_cast(v.at(i)); } else { c[i] = pal.color((QPalette::ColorRole)(v.at(i).toInt())); @@ -2723,7 +2723,7 @@ bool Parser::parseTerm(Value *value) switch (lookup()) { case NUMBER: value->type = Value::Number; - value->variant.convert(QVariant::Double); + value->variant.convert(QMetaType::Double); break; case PERCENTAGE: value->type = Value::Percentage; diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 2e7d898a70..8f0d7d9d38 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -1753,7 +1753,7 @@ bool QFont::operator!=(const QFont &f) const */ QFont::operator QVariant() const { - return QVariant(QVariant::Font, this); + return QVariant(QMetaType::QFont, this); } /*! diff --git a/src/gui/text/qplatformfontdatabase.cpp b/src/gui/text/qplatformfontdatabase.cpp index 02e25bb6af..48ba8987f3 100644 --- a/src/gui/text/qplatformfontdatabase.cpp +++ b/src/gui/text/qplatformfontdatabase.cpp @@ -82,7 +82,7 @@ void QPlatformFontDatabase::registerQPF2Font(const QByteArray &dataArray, void * if (!fontName.isEmpty() && pixelSize) { QFont::Weight fontWeight = QFont::Normal; - if (weight.type() == QVariant::Int || weight.type() == QVariant::UInt) + if (weight.userType() == QMetaType::Int || weight.userType() == QMetaType::UInt) fontWeight = QFont::Weight(weight.toInt()); QFont::Style fontStyle = static_cast(style.toInt()); diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 2d7f2bb844..46cfc79643 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2234,7 +2234,7 @@ QVariant QTextDocument::loadResource(int type, const QUrl &name) } if (!r.isNull()) { - if (type == ImageResource && r.type() == QVariant::ByteArray) { + if (type == ImageResource && r.userType() == QMetaType::QByteArray) { if (qApp->thread() != QThread::currentThread()) { // must use images in non-GUI threads QImage image; @@ -3049,12 +3049,12 @@ QString QTextHtmlExporter::findUrlForImage(const QTextDocument *doc, qint64 cach for (; it != priv->cachedResources.constEnd(); ++it) { const QVariant &v = it.value(); - if (v.type() == QVariant::Image && !isPixmap) { + if (v.userType() == QMetaType::QImage && !isPixmap) { if (qvariant_cast(v).cacheKey() == cacheKey) break; } - if (v.type() == QVariant::Pixmap && isPixmap) { + if (v.userType() == QMetaType::QPixmap && isPixmap) { if (qvariant_cast(v).cacheKey() == cacheKey) break; } diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index e21a8d8d52..9d70873590 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -248,7 +248,7 @@ public: if (v.isNull()) { return cellPadding; } else { - Q_ASSERT(v.userType() == QVariant::Double || v.userType() == QMetaType::Float); + Q_ASSERT(v.userType() == QMetaType::Double || v.userType() == QMetaType::Float); return QFixed::fromReal(v.toReal() * deviceScale); } } diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index e3bd49a15e..10b8ade117 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -144,7 +144,7 @@ QT_BEGIN_NAMESPACE */ QTextLength::operator QVariant() const { - return QVariant(QVariant::TextLength, this); + return QVariant(QMetaType::QTextLength, this); } #ifndef QT_NO_DATASTREAM @@ -288,20 +288,20 @@ static inline uint variantHash(const QVariant &variant) { // simple and fast hash functions to differentiate between type and value switch (variant.userType()) { // sorted by occurrence frequency - case QVariant::String: return qHash(variant.toString()); - case QVariant::Double: return qHash(variant.toDouble()); - case QVariant::Int: return 0x811890 + variant.toInt(); - case QVariant::Brush: + case QMetaType::QString: return qHash(variant.toString()); + case QMetaType::Double: return qHash(variant.toDouble()); + case QMetaType::Int: return 0x811890 + variant.toInt(); + case QMetaType::QBrush: return 0x01010101 + hash(qvariant_cast(variant)); - case QVariant::Bool: return 0x371818 + variant.toBool(); - case QVariant::Pen: return 0x02020202 + hash(qvariant_cast(variant)); - case QVariant::List: + case QMetaType::Bool: return 0x371818 + variant.toBool(); + case QMetaType::QPen: return 0x02020202 + hash(qvariant_cast(variant)); + case QMetaType::QVariantList: return 0x8377 + qvariant_cast(variant).count(); - case QVariant::Color: return hash(qvariant_cast(variant)); - case QVariant::TextLength: + case QMetaType::QColor: return hash(qvariant_cast(variant)); + case QMetaType::QTextLength: return 0x377 + hash(qvariant_cast(variant).rawValue()); case QMetaType::Float: return qHash(variant.toFloat()); - case QVariant::Invalid: return 0; + case QMetaType::UnknownType: return 0; default: break; } return qHash(variant.typeName()); @@ -874,7 +874,7 @@ QTextFormat::~QTextFormat() */ QTextFormat::operator QVariant() const { - return QVariant(QVariant::TextFormat, this); + return QVariant(QMetaType::QTextFormat, this); } /*! @@ -984,7 +984,7 @@ bool QTextFormat::boolProperty(int propertyId) const if (!d) return false; const QVariant prop = d->property(propertyId); - if (prop.userType() != QVariant::Bool) + if (prop.userType() != QMetaType::Bool) return false; return prop.toBool(); } @@ -1004,7 +1004,7 @@ int QTextFormat::intProperty(int propertyId) const if (!d) return def; const QVariant prop = d->property(propertyId); - if (prop.userType() != QVariant::Int) + if (prop.userType() != QMetaType::Int) return def; return prop.toInt(); } @@ -1022,7 +1022,7 @@ qreal QTextFormat::doubleProperty(int propertyId) const if (!d) return 0.; const QVariant prop = d->property(propertyId); - if (prop.userType() != QVariant::Double && prop.userType() != QMetaType::Float) + if (prop.userType() != QMetaType::Double && prop.userType() != QMetaType::Float) return 0.; return qvariant_cast(prop); } @@ -1040,7 +1040,7 @@ QString QTextFormat::stringProperty(int propertyId) const if (!d) return QString(); const QVariant prop = d->property(propertyId); - if (prop.userType() != QVariant::String) + if (prop.userType() != QMetaType::QString) return QString(); return prop.toString(); } @@ -1058,7 +1058,7 @@ QColor QTextFormat::colorProperty(int propertyId) const if (!d) return QColor(); const QVariant prop = d->property(propertyId); - if (prop.userType() != QVariant::Color) + if (prop.userType() != QMetaType::QColor) return QColor(); return qvariant_cast(prop); } @@ -1076,7 +1076,7 @@ QPen QTextFormat::penProperty(int propertyId) const if (!d) return QPen(Qt::NoPen); const QVariant prop = d->property(propertyId); - if (prop.userType() != QVariant::Pen) + if (prop.userType() != QMetaType::QPen) return QPen(Qt::NoPen); return qvariant_cast(prop); } @@ -1094,7 +1094,7 @@ QBrush QTextFormat::brushProperty(int propertyId) const if (!d) return QBrush(Qt::NoBrush); const QVariant prop = d->property(propertyId); - if (prop.userType() != QVariant::Brush) + if (prop.userType() != QMetaType::QBrush) return QBrush(Qt::NoBrush); return qvariant_cast(prop); } @@ -1126,13 +1126,13 @@ QVector QTextFormat::lengthVectorProperty(int propertyId) const if (!d) return vector; const QVariant prop = d->property(propertyId); - if (prop.userType() != QVariant::List) + if (prop.userType() != QMetaType::QVariantList) return vector; QList propertyList = prop.toList(); for (int i=0; i(var)); } @@ -1222,7 +1222,7 @@ int QTextFormat::objectIndex() const if (!d) return -1; const QVariant prop = d->property(ObjectIndex); - if (prop.userType() != QVariant::Int) // #### + if (prop.userType() != QMetaType::Int) // #### return -1; return prop.toInt(); } @@ -1859,9 +1859,9 @@ void QTextCharFormat::setUnderlineStyle(UnderlineStyle style) QString QTextCharFormat::anchorName() const { QVariant prop = property(AnchorName); - if (prop.userType() == QVariant::StringList) + if (prop.userType() == QMetaType::QStringList) return prop.toStringList().value(0); - else if (prop.userType() != QVariant::String) + else if (prop.userType() != QMetaType::QString) return QString(); return prop.toString(); } @@ -1878,9 +1878,9 @@ QString QTextCharFormat::anchorName() const QStringList QTextCharFormat::anchorNames() const { QVariant prop = property(AnchorName); - if (prop.userType() == QVariant::StringList) + if (prop.userType() == QMetaType::QStringList) return prop.toStringList(); - else if (prop.userType() != QVariant::String) + else if (prop.userType() != QMetaType::QString) return QStringList(); return QStringList(prop.toString()); } diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index 3b9f2d253e..f003544391 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -1451,19 +1451,19 @@ void QTextHtmlParserNode::applyBackgroundImage(const QString &url, const QTextDo if (QCoreApplication::instance()->thread() != QThread::currentThread()) { // must use images in non-GUI threads - if (val.type() == QVariant::Image) { + if (val.userType() == QMetaType::QImage) { QImage image = qvariant_cast(val); charFormat.setBackground(image); - } else if (val.type() == QVariant::ByteArray) { + } else if (val.userType() == QMetaType::QByteArray) { QImage image; if (image.loadFromData(val.toByteArray())) { charFormat.setBackground(image); } } } else { - if (val.type() == QVariant::Image || val.type() == QVariant::Pixmap) { + if (val.userType() == QMetaType::QImage || val.userType() == QMetaType::QPixmap) { charFormat.setBackground(qvariant_cast(val)); - } else if (val.type() == QVariant::ByteArray) { + } else if (val.userType() == QMetaType::QByteArray) { QPixmap pm; if (pm.loadFromData(val.toByteArray())) { charFormat.setBackground(pm); @@ -1907,9 +1907,9 @@ void QTextHtmlParser::importStyleSheet(const QString &href) QVariant res = resourceProvider->resource(QTextDocument::StyleSheetResource, href); QString css; - if (res.type() == QVariant::String) { + if (res.userType() == QMetaType::QString) { css = res.toString(); - } else if (res.type() == QVariant::ByteArray) { + } else if (res.userType() == QMetaType::QByteArray) { // #### detect @charset css = QString::fromUtf8(res.toByteArray()); } diff --git a/src/gui/text/qtextimagehandler.cpp b/src/gui/text/qtextimagehandler.cpp index 14018f34da..0d87a2135d 100644 --- a/src/gui/text/qtextimagehandler.cpp +++ b/src/gui/text/qtextimagehandler.cpp @@ -88,9 +88,9 @@ static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format, con qreal sourcePixelRatio = 1.0; name = resolveFileName(name, &url, devicePixelRatio, &sourcePixelRatio); const QVariant data = doc->resource(QTextDocument::ImageResource, url); - if (data.type() == QVariant::Pixmap || data.type() == QVariant::Image) { + if (data.userType() == QMetaType::QPixmap || data.userType() == QMetaType::QImage) { pm = qvariant_cast(data); - } else if (data.type() == QVariant::ByteArray) { + } else if (data.userType() == QMetaType::QByteArray) { pm.loadFromData(data.toByteArray()); } @@ -170,9 +170,9 @@ static QImage getImage(QTextDocument *doc, const QTextImageFormat &format, const qreal sourcePixelRatio = 1.0; name = resolveFileName(name, &url, devicePixelRatio, &sourcePixelRatio); const QVariant data = doc->resource(QTextDocument::ImageResource, url); - if (data.type() == QVariant::Image) { + if (data.userType() == QMetaType::QImage) { image = qvariant_cast(data); - } else if (data.type() == QVariant::ByteArray) { + } else if (data.userType() == QMetaType::QByteArray) { image.loadFromData(data.toByteArray()); } diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp index 408e3ec167..155ec43c50 100644 --- a/src/gui/text/qtextodfwriter.cpp +++ b/src/gui/text/qtextodfwriter.cpp @@ -455,9 +455,9 @@ void QTextOdfWriter::writeInlineCharacter(QXmlStreamWriter &writer, const QTextF name.prepend(QLatin1String("qrc")); QUrl url = QUrl(name); const QVariant variant = m_document->resource(QTextDocument::ImageResource, url); - if (variant.type() == QVariant::Image) { + if (variant.userType() == QMetaType::QImage) { image = qvariant_cast(variant); - } else if (variant.type() == QVariant::ByteArray) { + } else if (variant.userType() == QMetaType::QByteArray) { data = variant.toByteArray(); QBuffer buffer(&data); diff --git a/src/platformsupport/accessibility/qaccessiblebridgeutils.cpp b/src/platformsupport/accessibility/qaccessiblebridgeutils.cpp index f280e65c29..a15b93e31e 100644 --- a/src/platformsupport/accessibility/qaccessiblebridgeutils.cpp +++ b/src/platformsupport/accessibility/qaccessiblebridgeutils.cpp @@ -93,7 +93,7 @@ bool performEffectiveAction(QAccessibleInterface *iface, const QString &actionNa if (!success) return false; stepSize = (max - min) / 10; // this is pretty arbitrary, we just need to provide something - const int typ = currentVariant.type(); + const int typ = currentVariant.userType(); if (typ != QMetaType::Float && typ != QMetaType::Double) { // currentValue is an integer. Round it up to ensure stepping in case it was below 1 stepSize = qCeil(stepSize); diff --git a/src/platformsupport/linuxaccessibility/atspiadaptor.cpp b/src/platformsupport/linuxaccessibility/atspiadaptor.cpp index 0f34e1a4ca..012edc82e4 100644 --- a/src/platformsupport/linuxaccessibility/atspiadaptor.cpp +++ b/src/platformsupport/linuxaccessibility/atspiadaptor.cpp @@ -2250,7 +2250,7 @@ bool AtSpiAdaptor::valueInterface(QAccessibleInterface *interface, const QString qCDebug(lcAccessibilityAtspi) << "WARNING: AtSpiAdaptor::valueInterface does not implement " << function << message.path(); return false; } - if (!value.canConvert(QVariant::Double)) { + if (!value.canConvert(QMetaType::Double)) { qCDebug(lcAccessibilityAtspi) << "AtSpiAdaptor::valueInterface: Could not convert to double: " << function; } diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp index 70d5616075..36d9e4e065 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp @@ -517,7 +517,7 @@ QFont *QKdeThemePrivate::kdeFont(const QVariant &fontValue) // causing recursion. QString fontDescription; QString fontFamily; - if (fontValue.type() == QVariant::StringList) { + if (fontValue.userType() == QMetaType::QStringList) { const QStringList list = fontValue.toStringList(); if (!list.isEmpty()) { fontFamily = list.first(); diff --git a/src/plugins/generic/tuiotouch/qtuiohandler.cpp b/src/plugins/generic/tuiotouch/qtuiohandler.cpp index cb82672acd..6ad4597b19 100644 --- a/src/plugins/generic/tuiotouch/qtuiohandler.cpp +++ b/src/plugins/generic/tuiotouch/qtuiohandler.cpp @@ -226,7 +226,7 @@ void QTuioHandler::process2DCurSource(const QOscMessage &message) return; } - if (QMetaType::Type(arguments.at(1).type()) != QMetaType::QByteArray) { + if (QMetaType::Type(arguments.at(1).userType()) != QMetaType::QByteArray) { qCWarning(lcTuioSource, "Ignoring malformed TUIO source message (bad argument type)"); return; } @@ -248,7 +248,7 @@ void QTuioHandler::process2DCurAlive(const QOscMessage &message) QMap newActiveCursors; for (int i = 1; i < arguments.count(); ++i) { - if (QMetaType::Type(arguments.at(i).type()) != QMetaType::Int) { + if (QMetaType::Type(arguments.at(i).userType()) != QMetaType::Int) { qCWarning(lcTuioHandler) << "Ignoring malformed TUIO alive message (bad argument on position" << i << arguments << ')'; return; } @@ -293,12 +293,12 @@ void QTuioHandler::process2DCurSet(const QOscMessage &message) return; } - if (QMetaType::Type(arguments.at(1).type()) != QMetaType::Int || - QMetaType::Type(arguments.at(2).type()) != QMetaType::Float || - QMetaType::Type(arguments.at(3).type()) != QMetaType::Float || - QMetaType::Type(arguments.at(4).type()) != QMetaType::Float || - QMetaType::Type(arguments.at(5).type()) != QMetaType::Float || - QMetaType::Type(arguments.at(6).type()) != QMetaType::Float + if (QMetaType::Type(arguments.at(1).userType()) != QMetaType::Int || + QMetaType::Type(arguments.at(2).userType()) != QMetaType::Float || + QMetaType::Type(arguments.at(3).userType()) != QMetaType::Float || + QMetaType::Type(arguments.at(4).userType()) != QMetaType::Float || + QMetaType::Type(arguments.at(5).userType()) != QMetaType::Float || + QMetaType::Type(arguments.at(6).userType()) != QMetaType::Float ) { qCWarning(lcTuioSet) << "Ignoring malformed TUIO set message with bad types: " << arguments; return; @@ -391,7 +391,7 @@ void QTuioHandler::process2DObjSource(const QOscMessage &message) return; } - if (QMetaType::Type(arguments.at(1).type()) != QMetaType::QByteArray) { + if (QMetaType::Type(arguments.at(1).userType()) != QMetaType::QByteArray) { qCWarning(lcTuioSource, "Ignoring malformed TUIO source message (bad argument type)"); return; } @@ -413,7 +413,7 @@ void QTuioHandler::process2DObjAlive(const QOscMessage &message) QMap newActiveTokens; for (int i = 1; i < arguments.count(); ++i) { - if (QMetaType::Type(arguments.at(i).type()) != QMetaType::Int) { + if (QMetaType::Type(arguments.at(i).userType()) != QMetaType::Int) { qCWarning(lcTuioHandler) << "Ignoring malformed TUIO alive message (bad argument on position" << i << arguments << ')'; return; } @@ -458,16 +458,16 @@ void QTuioHandler::process2DObjSet(const QOscMessage &message) return; } - if (QMetaType::Type(arguments.at(1).type()) != QMetaType::Int || - QMetaType::Type(arguments.at(2).type()) != QMetaType::Int || - QMetaType::Type(arguments.at(3).type()) != QMetaType::Float || - QMetaType::Type(arguments.at(4).type()) != QMetaType::Float || - QMetaType::Type(arguments.at(5).type()) != QMetaType::Float || - QMetaType::Type(arguments.at(6).type()) != QMetaType::Float || - QMetaType::Type(arguments.at(7).type()) != QMetaType::Float || - QMetaType::Type(arguments.at(8).type()) != QMetaType::Float || - QMetaType::Type(arguments.at(9).type()) != QMetaType::Float || - QMetaType::Type(arguments.at(10).type()) != QMetaType::Float) { + if (QMetaType::Type(arguments.at(1).userType()) != QMetaType::Int || + QMetaType::Type(arguments.at(2).userType()) != QMetaType::Int || + QMetaType::Type(arguments.at(3).userType()) != QMetaType::Float || + QMetaType::Type(arguments.at(4).userType()) != QMetaType::Float || + QMetaType::Type(arguments.at(5).userType()) != QMetaType::Float || + QMetaType::Type(arguments.at(6).userType()) != QMetaType::Float || + QMetaType::Type(arguments.at(7).userType()) != QMetaType::Float || + QMetaType::Type(arguments.at(8).userType()) != QMetaType::Float || + QMetaType::Type(arguments.at(9).userType()) != QMetaType::Float || + QMetaType::Type(arguments.at(10).userType()) != QMetaType::Float) { qCWarning(lcTuioSet) << "Ignoring malformed TUIO set message with bad types: " << arguments; return; } diff --git a/src/plugins/platforms/xcb/qxcbclipboard.cpp b/src/plugins/platforms/xcb/qxcbclipboard.cpp index c2d9d060fb..fe9ddfece7 100644 --- a/src/plugins/platforms/xcb/qxcbclipboard.cpp +++ b/src/plugins/platforms/xcb/qxcbclipboard.cpp @@ -123,8 +123,9 @@ protected: return list.contains(format); } - QVariant retrieveData_sys(const QString &fmt, QVariant::Type requestedType) const override + QVariant retrieveData_sys(const QString &fmt, QVariant::Type type) const override { + auto requestedType = QMetaType::Type(type); if (fmt.isEmpty() || isEmpty()) return QByteArray(); diff --git a/src/plugins/platforms/xcb/qxcbdrag.cpp b/src/plugins/platforms/xcb/qxcbdrag.cpp index 47d58fa880..e76fc8bd40 100644 --- a/src/plugins/platforms/xcb/qxcbdrag.cpp +++ b/src/plugins/platforms/xcb/qxcbdrag.cpp @@ -114,7 +114,7 @@ protected: QStringList formats_sys() const override; QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const override; - QVariant xdndObtainData(const QByteArray &format, QVariant::Type requestedType) const; + QVariant xdndObtainData(const QByteArray &format, QMetaType::Type requestedType) const; QXcbDrag *drag; }; @@ -1248,11 +1248,11 @@ QXcbDropData::~QXcbDropData() QVariant QXcbDropData::retrieveData_sys(const QString &mimetype, QVariant::Type requestedType) const { QByteArray mime = mimetype.toLatin1(); - QVariant data = xdndObtainData(mime, requestedType); + QVariant data = xdndObtainData(mime, QMetaType::Type(requestedType)); return data; } -QVariant QXcbDropData::xdndObtainData(const QByteArray &format, QVariant::Type requestedType) const +QVariant QXcbDropData::xdndObtainData(const QByteArray &format, QMetaType::Type requestedType) const { QByteArray result; diff --git a/src/plugins/platforms/xcb/qxcbmime.cpp b/src/plugins/platforms/xcb/qxcbmime.cpp index d611f86a9c..0b3219f792 100644 --- a/src/plugins/platforms/xcb/qxcbmime.cpp +++ b/src/plugins/platforms/xcb/qxcbmime.cpp @@ -159,7 +159,7 @@ QVector QXcbMime::mimeAtomsForFormat(QXcbConnection *connection, con } QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, const QByteArray &d, const QString &format, - QVariant::Type requestedType, const QByteArray &encoding) + QMetaType::Type requestedType, const QByteArray &encoding) { QByteArray data = d; QString atomName = mimeAtomToString(connection, a); @@ -169,7 +169,7 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, && atomName == format + QLatin1String(";charset=") + QLatin1String(encoding)) { #if QT_CONFIG(textcodec) - if (requestedType == QVariant::String) { + if (requestedType == QMetaType::QString) { QTextCodec *codec = QTextCodec::codecForName(encoding); if (codec) return codec->toUnicode(data); @@ -264,7 +264,7 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, return QVariant(); } -xcb_atom_t QXcbMime::mimeAtomForFormat(QXcbConnection *connection, const QString &format, QVariant::Type requestedType, +xcb_atom_t QXcbMime::mimeAtomForFormat(QXcbConnection *connection, const QString &format, QMetaType::Type requestedType, const QVector &atoms, QByteArray *requestedEncoding) { requestedEncoding->clear(); @@ -297,7 +297,7 @@ xcb_atom_t QXcbMime::mimeAtomForFormat(QXcbConnection *connection, const QString // for string/text requests try to use a format with a well-defined charset // first to avoid encoding problems - if (requestedType == QVariant::String + if (requestedType == QMetaType::QString && format.startsWith(QLatin1String("text/")) && !format.contains(QLatin1String("charset="))) { diff --git a/src/plugins/platforms/xcb/qxcbmime.h b/src/plugins/platforms/xcb/qxcbmime.h index f2136ec9f4..dcb4f6b6c6 100644 --- a/src/plugins/platforms/xcb/qxcbmime.h +++ b/src/plugins/platforms/xcb/qxcbmime.h @@ -60,8 +60,8 @@ public: static bool mimeDataForAtom(QXcbConnection *connection, xcb_atom_t a, QMimeData *mimeData, QByteArray *data, xcb_atom_t *atomFormat, int *dataFormat); static QVariant mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a, const QByteArray &data, const QString &format, - QVariant::Type requestedType, const QByteArray &encoding); - static xcb_atom_t mimeAtomForFormat(QXcbConnection *connection, const QString &format, QVariant::Type requestedType, + QMetaType::Type requestedType, const QByteArray &encoding); + static xcb_atom_t mimeAtomForFormat(QXcbConnection *connection, const QString &format, QMetaType::Type requestedType, const QVector &atoms, QByteArray *requestedEncoding); }; diff --git a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp index d0928fe6ab..7bacb59994 100644 --- a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp +++ b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp @@ -730,7 +730,7 @@ static char* createArrayBuffer(char *buffer, const QList &list, if (curDim != dim) { for(i = 0; i < list.size(); ++i) { - if (list.at(i).type() != QVariant::List) { // dimensions mismatch + if (list.at(i).userType() != QVariant::List) { // dimensions mismatch error = QLatin1String("Array dimensons mismatch. Fieldname: %1"); return 0; } @@ -1162,7 +1162,7 @@ bool QIBaseResult::gotoNext(QSqlCachedResult::ValueCache& row, int rowIdx) // null value QVariant v; v.convert(qIBaseTypeName2(d->sqlda->sqlvar[i].sqltype, d->sqlda->sqlvar[i].sqlscale < 0)); - if(v.type() == QVariant::Double) { + if (v.userType() == QVariant::Double) { switch(numericalPrecisionPolicy()) { case QSql::LowPrecisionInt32: v.convert(QVariant::Int); diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp index 0e195cfdb4..90a810d516 100644 --- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp +++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp @@ -223,13 +223,13 @@ public: { QMyField() : outField(0), nullIndicator(false), bufLength(0ul), - myField(0), type(QVariant::Invalid) + myField(0), type(QMetaType::UnknownType) {} char *outField; my_bool nullIndicator; ulong bufLength; MYSQL_FIELD *myField; - QVariant::Type type; + QMetaType::Type type; }; QVector fields; @@ -263,25 +263,25 @@ static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type, } -static QVariant::Type qDecodeMYSQLType(int mysqltype, uint flags) +static QMetaType::Type qDecodeMYSQLType(int mysqltype, uint flags) { - QVariant::Type type; + QMetaType::Type type; switch (mysqltype) { case FIELD_TYPE_TINY : - type = static_cast((flags & UNSIGNED_FLAG) ? QMetaType::UChar : QMetaType::Char); + type = (flags & UNSIGNED_FLAG) ? QMetaType::UChar : QMetaType::Char; break; case FIELD_TYPE_SHORT : - type = static_cast((flags & UNSIGNED_FLAG) ? QMetaType::UShort : QMetaType::Short); + type = (flags & UNSIGNED_FLAG) ? QMetaType::UShort : QMetaType::Short; break; case FIELD_TYPE_LONG : case FIELD_TYPE_INT24 : - type = (flags & UNSIGNED_FLAG) ? QVariant::UInt : QVariant::Int; + type = (flags & UNSIGNED_FLAG) ? QMetaType::UInt : QMetaType::Int; break; case FIELD_TYPE_YEAR : - type = QVariant::Int; + type = QMetaType::Int; break; case FIELD_TYPE_LONGLONG : - type = (flags & UNSIGNED_FLAG) ? QVariant::ULongLong : QVariant::LongLong; + type = (flags & UNSIGNED_FLAG) ? QMetaType::ULongLong : QMetaType::LongLong; break; case FIELD_TYPE_FLOAT : case FIELD_TYPE_DOUBLE : @@ -289,19 +289,19 @@ static QVariant::Type qDecodeMYSQLType(int mysqltype, uint flags) #if defined(FIELD_TYPE_NEWDECIMAL) case FIELD_TYPE_NEWDECIMAL: #endif - type = QVariant::Double; + type = QMetaType::Double; break; case FIELD_TYPE_DATE : - type = QVariant::Date; + type = QMetaType::QDate; break; case FIELD_TYPE_TIME : // A time field can be within the range '-838:59:59' to '838:59:59' so // use QString instead of QTime since QTime is limited to 24 hour clock - type = QVariant::String; + type = QMetaType::QString; break; case FIELD_TYPE_DATETIME : case FIELD_TYPE_TIMESTAMP : - type = QVariant::DateTime; + type = QMetaType::QDateTime; break; case FIELD_TYPE_STRING : case FIELD_TYPE_VAR_STRING : @@ -309,12 +309,12 @@ static QVariant::Type qDecodeMYSQLType(int mysqltype, uint flags) case FIELD_TYPE_TINY_BLOB : case FIELD_TYPE_MEDIUM_BLOB : case FIELD_TYPE_LONG_BLOB : - type = (flags & BINARY_FLAG) ? QVariant::ByteArray : QVariant::String; + type = (flags & BINARY_FLAG) ? QMetaType::QByteArray : QMetaType::QString; break; default: case FIELD_TYPE_ENUM : case FIELD_TYPE_SET : - type = QVariant::String; + type = QMetaType::QString; break; } return type; @@ -323,7 +323,7 @@ static QVariant::Type qDecodeMYSQLType(int mysqltype, uint flags) static QSqlField qToField(MYSQL_FIELD *field, QTextCodec *tc) { QSqlField f(toUnicode(tc, field->name), - qDecodeMYSQLType(int(field->type), field->flags), + QVariant::Type(qDecodeMYSQLType(int(field->type), field->flags)), toUnicode(tc, field->table)); f.setRequired(IS_NOT_NULL(field->flags)); f.setLength(field->length); @@ -610,7 +610,7 @@ QVariant QMYSQLResult::data(int field) QString val; if (d->preparedQuery) { if (f.nullIndicator) - return QVariant(f.type); + return QVariant(QVariant::Type(f.type)); if (qIsInteger(f.type)) { QVariant variant(f.type, f.outField); @@ -622,34 +622,34 @@ QVariant QMYSQLResult::data(int field) return variant; } - if (f.type != QVariant::ByteArray) + if (f.type != QMetaType::QByteArray) val = toUnicode(d->drv_d_func()->tc, f.outField, f.bufLength); } else { if (d->row[field] == NULL) { // NULL value - return QVariant(f.type); + return QVariant(QVariant::Type(f.type)); } fieldLength = mysql_fetch_lengths(d->result)[field]; - if (f.type != QVariant::ByteArray) + if (f.type != QMetaType::QByteArray) val = toUnicode(d->drv_d_func()->tc, d->row[field], fieldLength); } switch (static_cast(f.type)) { - case QVariant::LongLong: + case QMetaType::LongLong: return QVariant(val.toLongLong()); - case QVariant::ULongLong: + case QMetaType::ULongLong: return QVariant(val.toULongLong()); case QMetaType::Char: case QMetaType::Short: - case QVariant::Int: + case QMetaType::Int: return QVariant(val.toInt()); case QMetaType::UChar: case QMetaType::UShort: - case QVariant::UInt: + case QMetaType::UInt: return QVariant(val.toUInt()); - case QVariant::Double: { + case QMetaType::Double: { QVariant v; bool ok=false; double dbl = val.toDouble(&ok); @@ -673,13 +673,13 @@ QVariant QMYSQLResult::data(int field) return v; return QVariant(); } - case QVariant::Date: + case QMetaType::QDate: return qDateFromString(val); - case QVariant::Time: + case QMetaType::QTime: return qTimeFromString(val); - case QVariant::DateTime: + case QMetaType::QDateTime: return qDateTimeFromString(val); - case QVariant::ByteArray: { + case QMetaType::QByteArray: { QByteArray ba; if (d->preparedQuery) { @@ -689,7 +689,7 @@ QVariant QMYSQLResult::data(int field) } return QVariant(ba); } - case QVariant::String: + case QMetaType::QString: default: return QVariant(val); } @@ -867,21 +867,21 @@ void QMYSQLResult::virtual_hook(int id, void *data) QSqlResult::virtual_hook(id, data); } -static MYSQL_TIME *toMySqlDate(QDate date, QTime time, QVariant::Type type) +static MYSQL_TIME *toMySqlDate(QDate date, QTime time, int type) { - Q_ASSERT(type == QVariant::Time || type == QVariant::Date - || type == QVariant::DateTime); + Q_ASSERT(type == QMetaType::QTime || type == QMetaType::QDate + || type == QMetaType::QDateTime); MYSQL_TIME *myTime = new MYSQL_TIME; memset(myTime, 0, sizeof(MYSQL_TIME)); - if (type == QVariant::Time || type == QVariant::DateTime) { + if (type == QMetaType::QTime || type == QMetaType::QDateTime) { myTime->hour = time.hour(); myTime->minute = time.minute(); myTime->second = time.second(); myTime->second_part = time.msec() * 1000; } - if (type == QVariant::Date || type == QVariant::DateTime) { + if (type == QMetaType::QDate || type == QMetaType::QDateTime) { myTime->year = date.year(); myTime->month = date.month(); myTime->day = date.day(); @@ -971,30 +971,30 @@ bool QMYSQLResult::exec() currBind->length = 0; currBind->is_unsigned = 0; - switch (val.type()) { - case QVariant::ByteArray: + switch (val.userType()) { + case QMetaType::QByteArray: currBind->buffer_type = MYSQL_TYPE_BLOB; currBind->buffer = const_cast(val.toByteArray().constData()); currBind->buffer_length = val.toByteArray().size(); break; - case QVariant::Time: - case QVariant::Date: - case QVariant::DateTime: { - MYSQL_TIME *myTime = toMySqlDate(val.toDate(), val.toTime(), val.type()); + case QMetaType::QTime: + case QMetaType::QDate: + case QMetaType::QDateTime: { + MYSQL_TIME *myTime = toMySqlDate(val.toDate(), val.toTime(), val.userType()); timeVector.append(myTime); currBind->buffer = myTime; - switch(val.type()) { - case QVariant::Time: + switch (val.userType()) { + case QMetaType::QTime: currBind->buffer_type = MYSQL_TYPE_TIME; myTime->time_type = MYSQL_TIMESTAMP_TIME; break; - case QVariant::Date: + case QMetaType::QDate: currBind->buffer_type = MYSQL_TYPE_DATE; myTime->time_type = MYSQL_TIMESTAMP_DATE; break; - case QVariant::DateTime: + case QMetaType::QDateTime: currBind->buffer_type = MYSQL_TYPE_DATETIME; myTime->time_type = MYSQL_TIMESTAMP_DATETIME; break; @@ -1004,32 +1004,32 @@ bool QMYSQLResult::exec() currBind->buffer_length = sizeof(MYSQL_TIME); currBind->length = 0; break; } - case QVariant::UInt: - case QVariant::Int: + case QMetaType::UInt: + case QMetaType::Int: currBind->buffer_type = MYSQL_TYPE_LONG; currBind->buffer = data; currBind->buffer_length = sizeof(int); - currBind->is_unsigned = (val.type() != QVariant::Int); + currBind->is_unsigned = (val.userType() != QMetaType::Int); break; - case QVariant::Bool: + case QMetaType::Bool: currBind->buffer_type = MYSQL_TYPE_TINY; currBind->buffer = data; currBind->buffer_length = sizeof(bool); currBind->is_unsigned = false; break; - case QVariant::Double: + case QMetaType::Double: currBind->buffer_type = MYSQL_TYPE_DOUBLE; currBind->buffer = data; currBind->buffer_length = sizeof(double); break; - case QVariant::LongLong: - case QVariant::ULongLong: + case QMetaType::LongLong: + case QMetaType::ULongLong: currBind->buffer_type = MYSQL_TYPE_LONGLONG; currBind->buffer = data; currBind->buffer_length = sizeof(qint64); - currBind->is_unsigned = (val.type() == QVariant::ULongLong); + currBind->is_unsigned = (val.userType() == QMetaType::ULongLong); break; - case QVariant::String: + case QMetaType::QString: default: { QByteArray ba = fromUnicode(d->drv_d_func()->tc, val.toString()); stringVector.append(ba); @@ -1548,16 +1548,16 @@ QString QMYSQLDriver::formatValue(const QSqlField &field, bool trimStrings) cons if (field.isNull()) { r = QStringLiteral("NULL"); } else { - switch(field.type()) { - case QVariant::Double: + switch (+field.type()) { + case QMetaType::Double: r = QString::number(field.value().toDouble(), 'g', field.precision()); break; - case QVariant::String: + case QMetaType::QString: // Escape '\' characters r = QSqlDriver::formatValue(field, trimStrings); r.replace(QLatin1String("\\"), QLatin1String("\\\\")); break; - case QVariant::ByteArray: + case QMetaType::QByteArray: if (isOpen()) { const QByteArray ba = field.value().toByteArray(); // buffer has to be at least length*2+1 bytes diff --git a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp index 7709b13cd1..33bad23e3b 100644 --- a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp +++ b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp @@ -1422,7 +1422,7 @@ bool QODBCResult::exec() SQLLEN *ind = &indicators[i]; if (val.isNull()) *ind = SQL_NULL_DATA; - switch (val.type()) { + switch (val.userType()) { case QVariant::Date: { QByteArray &ba = tmpStorage[i]; ba.resize(sizeof(DATE_STRUCT)); @@ -1694,7 +1694,7 @@ bool QODBCResult::exec() return true; for (i = 0; i < values.count(); ++i) { - switch (values.at(i).type()) { + switch (values.at(i).userType()) { case QVariant::Date: { DATE_STRUCT ds = *((DATE_STRUCT *)const_cast(tmpStorage.at(i).constData())); values[i] = QVariant(QDate(ds.year, ds.month, ds.day)); @@ -1735,7 +1735,7 @@ bool QODBCResult::exec() break; } } if (indicators[i] == SQL_NULL_DATA) - values[i] = QVariant(values[i].type()); + values[i] = QVariant(QVariant::Type(values[i].userType())); } return true; } diff --git a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp index 65d3f0a580..551d762434 100644 --- a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp +++ b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp @@ -505,7 +505,7 @@ bool QSQLiteResult::exec() if (value.isNull()) { res = sqlite3_bind_null(d->stmt, i + 1); } else { - switch (value.type()) { + switch (value.userType()) { case QVariant::ByteArray: { const QByteArray *ba = static_cast(value.constData()); res = sqlite3_bind_blob(d->stmt, i + 1, ba->constData(), diff --git a/src/sql/kernel/qsqldriver.cpp b/src/sql/kernel/qsqldriver.cpp index fcd3c70a04..d1c9057aac 100644 --- a/src/sql/kernel/qsqldriver.cpp +++ b/src/sql/kernel/qsqldriver.cpp @@ -612,30 +612,30 @@ QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const if (field.isNull()) r = nullTxt; else { - switch (field.type()) { - case QVariant::Int: - case QVariant::UInt: - if (field.value().type() == QVariant::Bool) + switch (+field.type()) { + case QMetaType::Int: + case QMetaType::UInt: + if (field.value().userType() == QMetaType::Bool) r = field.value().toBool() ? QLatin1String("1") : QLatin1String("0"); else r = field.value().toString(); break; #if QT_CONFIG(datestring) - case QVariant::Date: + case QMetaType::QDate: if (field.value().toDate().isValid()) r = QLatin1Char('\'') + field.value().toDate().toString(Qt::ISODate) + QLatin1Char('\''); else r = nullTxt; break; - case QVariant::Time: + case QMetaType::QTime: if (field.value().toTime().isValid()) r = QLatin1Char('\'') + field.value().toTime().toString(Qt::ISODate) + QLatin1Char('\''); else r = nullTxt; break; - case QVariant::DateTime: + case QMetaType::QDateTime: if (field.value().toDateTime().isValid()) r = QLatin1Char('\'') + field.value().toDateTime().toString(Qt::ISODate) + QLatin1Char('\''); @@ -643,8 +643,8 @@ QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const r = nullTxt; break; #endif - case QVariant::String: - case QVariant::Char: + case QMetaType::QString: + case QMetaType::QChar: { QString result = field.value().toString(); if (trimStrings) { @@ -658,10 +658,10 @@ QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const r = QLatin1Char('\'') + result + QLatin1Char('\''); break; } - case QVariant::Bool: + case QMetaType::Bool: r = QString::number(field.value().toBool()); break; - case QVariant::ByteArray : { + case QMetaType::QByteArray : { if (hasFeature(BLOB)) { QByteArray ba = field.value().toByteArray(); QString res; diff --git a/src/sql/kernel/qsqlfield.cpp b/src/sql/kernel/qsqlfield.cpp index 5a6d173b3b..86a22bae10 100644 --- a/src/sql/kernel/qsqlfield.cpp +++ b/src/sql/kernel/qsqlfield.cpp @@ -48,7 +48,7 @@ class QSqlFieldPrivate public: QSqlFieldPrivate(const QString &name, QVariant::Type type, const QString &tableName) : - ref(1), nm(name), table(tableName), def(QVariant()), type(type), + ref(1), nm(name), table(tableName), def(QVariant()), type(QMetaType::Type(type)), req(QSqlField::Unknown), len(-1), prec(-1), tp(-1), ro(false), gen(true), autoval(false) {} @@ -86,7 +86,7 @@ public: QString nm; QString table; QVariant def; - QVariant::Type type; + QMetaType::Type type; QSqlField::RequiredStatus req; int len; int prec; @@ -399,7 +399,7 @@ QString QSqlField::name() const */ QVariant::Type QSqlField::type() const { - return d->type; + return QVariant::Type(d->type); } /*! @@ -411,12 +411,11 @@ QVariant::Type QSqlField::type() const void QSqlField::setType(QVariant::Type type) { detach(); - d->type = type; + d->type = QMetaType::Type(type); if (!val.isValid()) val = QVariant(type); } - /*! Returns \c true if the field's value is read-only; otherwise returns false. @@ -526,7 +525,7 @@ bool QSqlField::isGenerated() const */ bool QSqlField::isValid() const { - return d->type != QVariant::Invalid; + return d->type != QMetaType::UnknownType; } #ifndef QT_NO_DEBUG_STREAM diff --git a/src/sql/kernel/qsqlfield.h b/src/sql/kernel/qsqlfield.h index 8650ba8715..892420d26e 100644 --- a/src/sql/kernel/qsqlfield.h +++ b/src/sql/kernel/qsqlfield.h @@ -55,7 +55,7 @@ public: enum RequiredStatus { Unknown = -1, Optional = 0, Required = 1 }; explicit QSqlField(const QString& fieldName = QString(), - QVariant::Type type = QVariant::Invalid); + QVariant::Type type = {}); QSqlField(const QString &fieldName, QVariant::Type type, const QString &tableName); diff --git a/src/sql/kernel/qsqlresult.cpp b/src/sql/kernel/qsqlresult.cpp index cc91c6d0ed..a41b3d8424 100644 --- a/src/sql/kernel/qsqlresult.cpp +++ b/src/sql/kernel/qsqlresult.cpp @@ -645,7 +645,7 @@ bool QSqlResult::exec() for (i = d->holders.count() - 1; i >= 0; --i) { holder = d->holders.at(i).holderName; val = d->values.value(d->indexes.value(holder).value(0,-1)); - QSqlField f(QLatin1String(""), val.type()); + QSqlField f(QLatin1String(""), QVariant::Type(val.userType())); f.setValue(val); query = query.replace(d->holders.at(i).holderPos, holder.length(), driver()->formatValue(f)); @@ -659,7 +659,7 @@ bool QSqlResult::exec() if (i == -1) continue; QVariant var = d->values.value(idx); - QSqlField f(QLatin1String(""), var.type()); + QSqlField f(QLatin1String(""), QVariant::Type(var.userType())); if (var.isNull()) f.clear(); else diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h index 3b1ffb389e..0298ff96e3 100644 --- a/src/testlib/qtest.h +++ b/src/testlib/qtest.h @@ -218,7 +218,7 @@ template<> inline char *toString(const QVariant &v) vstring.append(type); if (!v.isNull()) { vstring.append(','); - if (v.canConvert(QVariant::String)) { + if (v.canConvert(QMetaType::QString)) { vstring.append(v.toString().toLocal8Bit()); } else { diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index f3ebf343c5..2776740784 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -152,7 +152,7 @@ namespace QTest { inline bool matches(QtMsgType tp, const QString &message) const { return tp == type - && (pattern.type() == QVariant::String ? + && (pattern.userType() == QMetaType::QString ? stringsMatch(pattern.toString(), message) : #if QT_CONFIG(regularexpression) pattern.toRegularExpression().match(message).hasMatch()); @@ -292,7 +292,7 @@ void QTestLog::printUnhandledIgnoreMessages() QString message; QTest::IgnoreResultList *list = QTest::ignoreResultList; while (list) { - if (list->pattern.type() == QVariant::String) { + if (list->pattern.userType() == QMetaType::QString) { message = QStringLiteral("Did not receive message: \"") + list->pattern.toString() + QLatin1Char('"'); } else { #if QT_CONFIG(regularexpression) diff --git a/src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp b/src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp index 81ebafad79..768594efb4 100644 --- a/src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp +++ b/src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp @@ -115,7 +115,7 @@ static QString addFunction(const FunctionDef &mm, bool isSignal = false) { .arg(typeNameToXml(typeName)); // do we need to describe this argument? - if (QDBusMetaType::signatureToType(typeName) == QVariant::Invalid) + if (QDBusMetaType::signatureToType(typeName) == QMetaType::UnknownType) xml += QString::fromLatin1(" \n") .arg(typeNameToXml(mm.normalizedType.constData())); } else { @@ -159,7 +159,7 @@ static QString addFunction(const FunctionDef &mm, bool isSignal = false) { isOutput ? QLatin1String("out") : QLatin1String("in")); // do we need to describe this argument? - if (QDBusMetaType::signatureToType(signature) == QVariant::Invalid) { + if (QDBusMetaType::signatureToType(signature) == QMetaType::UnknownType) { const char *typeName = QMetaType::typeName(types.at(j)); xml += QString::fromLatin1(" \n") .arg(isOutput ? QLatin1String("Out") : QLatin1String("In")) @@ -225,7 +225,7 @@ static QString generateInterfaceXml(const ClassDef *mo) QLatin1String(signature), QLatin1String(accessvalues[access])); - if (QDBusMetaType::signatureToType(signature) == QVariant::Invalid) { + if (QDBusMetaType::signatureToType(signature) == QMetaType::UnknownType) { retval += QString::fromLatin1(">\n \n \n") .arg(typeNameToXml(mp.type.constData())); } else { diff --git a/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp b/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp index 9cf753a3f1..9825596f3d 100644 --- a/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp +++ b/src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp @@ -211,7 +211,7 @@ static QString classNameForInterface(const QString &interface, ClassType classTy static QByteArray qtTypeName(const QString &signature, const QDBusIntrospection::Annotations &annotations, int paramId = -1, const char *direction = "Out", bool isSignal = false) { int type = QDBusMetaType::signatureToType(signature.toLatin1()); - if (type == QVariant::Invalid) { + if (type == QMetaType::UnknownType) { QString annotationName = QString::fromLatin1("org.qtproject.QtDBus.QtTypeName"); if (paramId >= 0) annotationName += QString::fromLatin1(".%1%2").arg(QLatin1String(direction)).arg(paramId); diff --git a/src/widgets/dialogs/qsidebar.cpp b/src/widgets/dialogs/qsidebar.cpp index dfb707eda0..4272b612ec 100644 --- a/src/widgets/dialogs/qsidebar.cpp +++ b/src/widgets/dialogs/qsidebar.cpp @@ -163,7 +163,7 @@ bool QUrlModel::dropMimeData(const QMimeData *data, Qt::DropAction action, */ bool QUrlModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if (value.type() == QVariant::Url) { + if (value.userType() == QMetaType::QUrl) { QUrl url = value.toUrl(); QModelIndex dirIndex = fileSystemModel->index(url.toLocalFile()); //On windows the popup display the "C:\", convert to nativeSeparators diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index 6f1eb4b346..a2120e53fe 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -10511,13 +10511,13 @@ QVariant QGraphicsTextItem::inputMethodQuery(Qt::InputMethodQuery query) const v = int(inputMethodHints()); else if (dd->control) v = dd->control->inputMethodQuery(query, QVariant()); - if (v.type() == QVariant::RectF) + if (v.userType() == QMetaType::QRectF) v = v.toRectF().translated(-dd->controlOffset()); - else if (v.type() == QVariant::PointF) + else if (v.userType() == QMetaType::QPointF) v = v.toPointF() - dd->controlOffset(); - else if (v.type() == QVariant::Rect) + else if (v.userType() == QMetaType::QRect) v = v.toRect().translated(-dd->controlOffset().toPoint()); - else if (v.type() == QVariant::Point) + else if (v.userType() == QMetaType::QPoint) v = v.toPoint() - dd->controlOffset().toPoint(); return v; } diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp index 4d4958c674..eb8acf1f27 100644 --- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp +++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp @@ -1441,17 +1441,17 @@ QVariant QGraphicsProxyWidget::inputMethodQuery(Qt::InputMethodQuery query) cons focusWidget = d->widget; QVariant v = focusWidget->inputMethodQuery(query); QPointF focusWidgetPos = subWidgetRect(focusWidget).topLeft(); - switch (v.type()) { - case QVariant::RectF: + switch (v.userType()) { + case QMetaType::QRectF: v = v.toRectF().translated(focusWidgetPos); break; - case QVariant::PointF: + case QMetaType::QPointF: v = v.toPointF() + focusWidgetPos; break; - case QVariant::Rect: + case QMetaType::QRect: v = v.toRect().translated(focusWidgetPos.toPoint()); break; - case QVariant::Point: + case QMetaType::QPoint: v = v.toPoint() + focusWidgetPos.toPoint(); break; default: diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index 1c6e68def1..1cb24f74b6 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -3190,13 +3190,13 @@ QVariant QGraphicsScene::inputMethodQuery(Qt::InputMethodQuery query) const return QVariant(); const QTransform matrix = d->focusItem->sceneTransform(); QVariant value = d->focusItem->inputMethodQuery(query); - if (value.type() == QVariant::RectF) + if (value.userType() == QMetaType::QRectF) value = matrix.mapRect(value.toRectF()); - else if (value.type() == QVariant::PointF) + else if (value.userType() == QMetaType::QPointF) value = matrix.map(value.toPointF()); - else if (value.type() == QVariant::Rect) + else if (value.userType() == QMetaType::QRect) value = matrix.mapRect(value.toRect()); - else if (value.type() == QVariant::Point) + else if (value.userType() == QMetaType::QPoint) value = matrix.map(value.toPoint()); return value; } diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index 7589a1ebbd..e1a829f779 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -2589,13 +2589,13 @@ QVariant QGraphicsView::inputMethodQuery(Qt::InputMethodQuery query) const return QVariant(); QVariant value = d->scene->inputMethodQuery(query); - if (value.type() == QVariant::RectF) + if (value.userType() == QMetaType::QRectF) value = d->mapRectFromScene(value.toRectF()); - else if (value.type() == QVariant::PointF) + else if (value.userType() == QMetaType::QPointF) value = mapFromScene(value.toPointF()); - else if (value.type() == QVariant::Rect) + else if (value.userType() == QMetaType::QRect) value = d->mapRectFromScene(value.toRect()).toRect(); - else if (value.type() == QVariant::Point) + else if (value.userType() == QMetaType::QPoint) value = mapFromScene(value.toPoint()); return value; } diff --git a/src/widgets/itemviews/qabstractitemdelegate.cpp b/src/widgets/itemviews/qabstractitemdelegate.cpp index bb47881c03..c5b22b5667 100644 --- a/src/widgets/itemviews/qabstractitemdelegate.cpp +++ b/src/widgets/itemviews/qabstractitemdelegate.cpp @@ -585,27 +585,27 @@ QString QAbstractItemDelegatePrivate::textForRole(Qt::ItemDataRole role, const Q case QMetaType::Float: text = locale.toString(value.toFloat()); break; - case QVariant::Double: + case QMetaType::Double: text = locale.toString(value.toDouble(), 'g', precision); break; - case QVariant::Int: - case QVariant::LongLong: + case QMetaType::Int: + case QMetaType::LongLong: text = locale.toString(value.toLongLong()); break; - case QVariant::UInt: - case QVariant::ULongLong: + case QMetaType::UInt: + case QMetaType::ULongLong: text = locale.toString(value.toULongLong()); break; - case QVariant::Date: + case QMetaType::QDate: text = locale.toString(value.toDate(), formatType); break; - case QVariant::Time: + case QMetaType::QTime: text = locale.toString(value.toTime(), formatType); break; - case QVariant::DateTime: + case QMetaType::QDateTime: text = locale.toString(value.toDateTime(), formatType); break; - case QVariant::Type(QMetaType::QJsonValue): { + case QMetaType::QJsonValue: { const QJsonValue val = value.toJsonValue(); if (val.isBool()) { text = QVariant(val.toBool()).toString(); diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 0e54cf235f..2524d4acfa 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -2339,7 +2339,7 @@ void QAbstractItemView::keyPressEvent(QKeyEvent *event) QVariant variant; if (d->model) variant = d->model->data(currentIndex(), Qt::DisplayRole); - if (variant.type() == QVariant::String) + if (variant.userType() == QMetaType::QString) QGuiApplication::clipboard()->setText(variant.toString()); event->accept(); } diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 790f305463..84e2fd72a9 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -3660,7 +3660,7 @@ void QHeaderViewPrivate::flipSortIndicator(int section) sortOrder = (sortIndicatorOrder == Qt::DescendingOrder) ? Qt::AscendingOrder : Qt::DescendingOrder; } else { const QVariant value = model->headerData(section, orientation, Qt::InitialSortOrderRole); - if (value.canConvert(QVariant::Int)) + if (value.canConvert(QMetaType::Int)) sortOrder = static_cast(value.toInt()); else sortOrder = Qt::AscendingOrder; diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp index daea907963..4420d39b8e 100644 --- a/src/widgets/itemviews/qitemdelegate.cpp +++ b/src/widgets/itemviews/qitemdelegate.cpp @@ -414,7 +414,7 @@ void QItemDelegate::paint(QPainter *painter, if (value.isValid()) { // ### we need the pixmap to call the virtual function pixmap = decoration(opt, value); - if (value.type() == QVariant::Icon) { + if (value.userType() == QMetaType::QIcon) { d->tmp.icon = qvariant_cast(value); d->tmp.mode = d->iconMode(option.state); d->tmp.state = d->iconState(option.state); @@ -969,12 +969,12 @@ void QItemDelegate::doLayout(const QStyleOptionViewItem &option, QPixmap QItemDelegate::decoration(const QStyleOptionViewItem &option, const QVariant &variant) const { Q_D(const QItemDelegate); - switch (variant.type()) { - case QVariant::Icon: { + switch (variant.userType()) { + case QMetaType::QIcon: { QIcon::Mode mode = d->iconMode(option.state); QIcon::State state = d->iconState(option.state); return qvariant_cast(variant).pixmap(option.decorationSize, mode, state); } - case QVariant::Color: { + case QMetaType::QColor: { static QPixmap pixmap(option.decorationSize); pixmap.fill(qvariant_cast(variant)); return pixmap; } @@ -1060,24 +1060,24 @@ QRect QItemDelegate::rect(const QStyleOptionViewItem &option, if (role == Qt::CheckStateRole) return doCheck(option, option.rect, value); if (value.isValid() && !value.isNull()) { - switch (value.type()) { - case QVariant::Invalid: + switch (value.userType()) { + case QMetaType::UnknownType: break; - case QVariant::Pixmap: { + case QMetaType::QPixmap: { const QPixmap &pixmap = qvariant_cast(value); return QRect(QPoint(0, 0), pixmap.size() / pixmap.devicePixelRatio() ); } - case QVariant::Image: { + case QMetaType::QImage: { const QImage &image = qvariant_cast(value); return QRect(QPoint(0, 0), image.size() / image.devicePixelRatio() ); } - case QVariant::Icon: { + case QMetaType::QIcon: { QIcon::Mode mode = d->iconMode(option.state); QIcon::State state = d->iconState(option.state); QIcon icon = qvariant_cast(value); QSize size = icon.actualSize(option.decorationSize, mode, state); return QRect(QPoint(0, 0), size); } - case QVariant::Color: + case QMetaType::QColor: return QRect(QPoint(0, 0), option.decorationSize); - case QVariant::String: + case QMetaType::QString: default: { const QString text = d->valueToText(value, option); value = index.data(Qt::FontRole); diff --git a/src/widgets/itemviews/qitemeditorfactory.cpp b/src/widgets/itemviews/qitemeditorfactory.cpp index f874597d59..fe9b482122 100644 --- a/src/widgets/itemviews/qitemeditorfactory.cpp +++ b/src/widgets/itemviews/qitemeditorfactory.cpp @@ -241,21 +241,21 @@ QWidget *QDefaultItemEditorFactory::createEditor(int userType, QWidget *parent) { switch (userType) { #if QT_CONFIG(combobox) - case QVariant::Bool: { + case QMetaType::Bool: { QBooleanComboBox *cb = new QBooleanComboBox(parent); cb->setFrame(false); cb->setSizePolicy(QSizePolicy::Ignored, cb->sizePolicy().verticalPolicy()); return cb; } #endif #if QT_CONFIG(spinbox) - case QVariant::UInt: { + case QMetaType::UInt: { QSpinBox *sb = new QUIntSpinBox(parent); sb->setFrame(false); sb->setMinimum(0); sb->setMaximum(INT_MAX); sb->setSizePolicy(QSizePolicy::Ignored, sb->sizePolicy().verticalPolicy()); return sb; } - case QVariant::Int: { + case QMetaType::Int: { QSpinBox *sb = new QSpinBox(parent); sb->setFrame(false); sb->setMinimum(INT_MIN); @@ -264,25 +264,25 @@ QWidget *QDefaultItemEditorFactory::createEditor(int userType, QWidget *parent) return sb; } #endif #if QT_CONFIG(datetimeedit) - case QVariant::Date: { + case QMetaType::QDate: { QDateTimeEdit *ed = new QDateEdit(parent); ed->setFrame(false); return ed; } - case QVariant::Time: { + case QMetaType::QTime: { QDateTimeEdit *ed = new QTimeEdit(parent); ed->setFrame(false); return ed; } - case QVariant::DateTime: { + case QMetaType::QDateTime: { QDateTimeEdit *ed = new QDateTimeEdit(parent); ed->setFrame(false); return ed; } #endif #if QT_CONFIG(label) - case QVariant::Pixmap: + case QMetaType::QPixmap: return new QLabel(parent); #endif #if QT_CONFIG(spinbox) - case QVariant::Double: { + case QMetaType::Double: { QDoubleSpinBox *sb = new QDoubleSpinBox(parent); sb->setFrame(false); sb->setMinimum(-DBL_MAX); @@ -291,7 +291,7 @@ QWidget *QDefaultItemEditorFactory::createEditor(int userType, QWidget *parent) return sb; } #endif #if QT_CONFIG(lineedit) - case QVariant::String: + case QMetaType::QString: default: { // the default editor is a lineedit QExpandingLineEdit *le = new QExpandingLineEdit(parent); @@ -311,24 +311,24 @@ QByteArray QDefaultItemEditorFactory::valuePropertyName(int userType) const { switch (userType) { #if QT_CONFIG(combobox) - case QVariant::Bool: + case QMetaType::Bool: return "currentIndex"; #endif #if QT_CONFIG(spinbox) - case QVariant::UInt: - case QVariant::Int: - case QVariant::Double: + case QMetaType::UInt: + case QMetaType::Int: + case QMetaType::Double: return "value"; #endif #if QT_CONFIG(datetimeedit) - case QVariant::Date: + case QMetaType::QDate: return "date"; - case QVariant::Time: + case QMetaType::QTime: return "time"; - case QVariant::DateTime: + case QMetaType::QDateTime: return "dateTime"; #endif - case QVariant::String: + case QMetaType::QString: default: // the default editor is a lineedit return "text"; diff --git a/src/widgets/itemviews/qstyleditemdelegate.cpp b/src/widgets/itemviews/qstyleditemdelegate.cpp index f42af2ea00..c685cc7f05 100644 --- a/src/widgets/itemviews/qstyleditemdelegate.cpp +++ b/src/widgets/itemviews/qstyleditemdelegate.cpp @@ -302,8 +302,8 @@ void QStyledItemDelegate::initStyleOption(QStyleOptionViewItem *option, value = index.data(Qt::DecorationRole); if (value.isValid() && !value.isNull()) { option->features |= QStyleOptionViewItem::HasDecoration; - switch (value.type()) { - case QVariant::Icon: { + switch (value.userType()) { + case QMetaType::QIcon: { option->icon = qvariant_cast(value); QIcon::Mode mode; if (!(option->state & QStyle::State_Enabled)) @@ -319,19 +319,19 @@ void QStyledItemDelegate::initStyleOption(QStyleOptionViewItem *option, qMin(option->decorationSize.height(), actualSize.height())); break; } - case QVariant::Color: { + case QMetaType::QColor: { QPixmap pixmap(option->decorationSize); pixmap.fill(qvariant_cast(value)); option->icon = QIcon(pixmap); break; } - case QVariant::Image: { + case QMetaType::QImage: { QImage image = qvariant_cast(value); option->icon = QIcon(QPixmap::fromImage(image)); option->decorationSize = image.size() / image.devicePixelRatio(); break; } - case QVariant::Pixmap: { + case QMetaType::QPixmap: { QPixmap pixmap = qvariant_cast(value); option->icon = QIcon(pixmap); option->decorationSize = pixmap.size() / pixmap.devicePixelRatio(); diff --git a/src/widgets/kernel/qsizepolicy.cpp b/src/widgets/kernel/qsizepolicy.cpp index 54bf8fe0dc..c4372a9fbc 100644 --- a/src/widgets/kernel/qsizepolicy.cpp +++ b/src/widgets/kernel/qsizepolicy.cpp @@ -439,7 +439,7 @@ void QSizePolicy::setControlType(ControlType type) noexcept */ QSizePolicy::operator QVariant() const { - return QVariant(QVariant::SizePolicy, this); + return QVariant(QMetaType::QSizePolicy, this); } #ifndef QT_NO_DATASTREAM diff --git a/src/widgets/kernel/qwidgetsvariant.cpp b/src/widgets/kernel/qwidgetsvariant.cpp index 41600d2143..edb166e8d5 100644 --- a/src/widgets/kernel/qwidgetsvariant.cpp +++ b/src/widgets/kernel/qwidgetsvariant.cpp @@ -51,12 +51,12 @@ namespace { static void construct(QVariant::Private *x, const void *copy) { switch (x->type) { - case QVariant::SizePolicy: + case QMetaType::QSizePolicy: v_construct(x, copy); break; default: qWarning("Trying to construct an instance of an invalid type, type id: %i", x->type); - x->type = QVariant::Invalid; + x->type = QMetaType::UnknownType; return; } x->is_null = !copy; @@ -65,7 +65,7 @@ static void construct(QVariant::Private *x, const void *copy) static void clear(QVariant::Private *d) { switch (d->type) { - case QVariant::SizePolicy: + case QMetaType::QSizePolicy: v_clear(d); break; default: @@ -73,7 +73,7 @@ static void clear(QVariant::Private *d) return; } - d->type = QVariant::Invalid; + d->type = QMetaType::UnknownType; d->is_null = true; d->is_shared = false; } @@ -88,7 +88,7 @@ static bool compare(const QVariant::Private *a, const QVariant::Private *b) { Q_ASSERT(a->type == b->type); switch(a->type) { - case QVariant::SizePolicy: + case QMetaType::QSizePolicy: return *v_cast(a) == *v_cast(b); default: Q_ASSERT(false); @@ -111,7 +111,7 @@ static void streamDebug(QDebug dbg, const QVariant &v) { QVariant::Private *d = const_cast(&v.data_ptr()); switch (d->type) { - case QVariant::SizePolicy: + case QMetaType::QSizePolicy: dbg.nospace() << *v_cast(d); break; default: diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 2eccb24431..1e032b237a 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -1547,11 +1547,10 @@ public: } } } - QString valueStr; - if(value.type() == QVariant::StringList || value.type() == QVariant::List) - valueStr = value.toStringList().join(QLatin1Char(' ')); - else - valueStr = value.toString(); + QString valueStr = (value.userType() == QMetaType::QStringList + || value.userType() == QMetaType::QVariantList) + ? value.toStringList().join(QLatin1Char(' ')) + : value.toString(); cache[name] = valueStr; return valueStr; } @@ -2611,16 +2610,16 @@ void QStyleSheetStyle::setProperties(QWidget *w) QVariant v; const QVariant value = w->property(property.toLatin1()); - switch (value.type()) { - case QVariant::Icon: v = decl.iconValue(); break; - case QVariant::Image: v = QImage(decl.uriValue()); break; - case QVariant::Pixmap: v = QPixmap(decl.uriValue()); break; - case QVariant::Rect: v = decl.rectValue(); break; - case QVariant::Size: v = decl.sizeValue(); break; - case QVariant::Color: v = decl.colorValue(); break; - case QVariant::Brush: v = decl.brushValue(); break; + switch (value.userType()) { + case QMetaType::QIcon: v = decl.iconValue(); break; + case QMetaType::QImage: v = QImage(decl.uriValue()); break; + case QMetaType::QPixmap: v = QPixmap(decl.uriValue()); break; + case QMetaType::QRect: v = decl.rectValue(); break; + case QMetaType::QSize: v = decl.sizeValue(); break; + case QMetaType::QColor: v = decl.colorValue(); break; + case QMetaType::QBrush: v = decl.brushValue(); break; #ifndef QT_NO_SHORTCUT - case QVariant::KeySequence: v = QKeySequence(decl.d->values.at(0).variant.toString()); break; + case QMetaType::QKeySequence: v = QKeySequence(decl.d->values.at(0).variant.toString()); break; #endif default: v = decl.d->values.at(0).variant; break; } @@ -4648,7 +4647,7 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op } if (baseStyle()->property("_q_styleSheetRealCloseButton").toBool()) - baseStyle()->setProperty("_q_styleSheetRealCloseButton", QVariant(QVariant::Invalid)); + baseStyle()->setProperty("_q_styleSheetRealCloseButton", QVariant()); } QPixmap QStyleSheetStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap& pixmap, @@ -6128,7 +6127,7 @@ void QStyleSheetStyle::saveWidgetFont(QWidget* w, const QFont& font) const void QStyleSheetStyle::clearWidgetFont(QWidget* w) const { - w->setProperty("_q_styleSheetWidgetFont", QVariant(QVariant::Invalid)); + w->setProperty("_q_styleSheetWidgetFont", QVariant()); } // Polish palette that should be used for a particular widget, with particular states diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index 6a0d2f5019..04176ab5e2 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -570,7 +570,7 @@ void QAbstractSpinBox::clear() QAbstractSpinBox::StepEnabled QAbstractSpinBox::stepEnabled() const { Q_D(const QAbstractSpinBox); - if (d->readOnly || d->type == QVariant::Invalid) + if (d->readOnly || d->type == QMetaType::UnknownType) return StepNone; if (d->wrapping) return StepEnabled(StepUpEnabled | StepDownEnabled); @@ -723,7 +723,7 @@ void QAbstractSpinBox::setLineEdit(QLineEdit *lineEdit) d->edit->setFocusProxy(this); d->edit->setAcceptDrops(false); - if (d->type != QVariant::Invalid) { + if (d->type != QMetaType::UnknownType) { connect(d->edit, SIGNAL(textChanged(QString)), this, SLOT(_q_editorTextChanged(QString))); connect(d->edit, SIGNAL(cursorPositionChanged(int,int)), @@ -1421,7 +1421,7 @@ void QAbstractSpinBox::mouseReleaseEvent(QMouseEvent *event) */ QAbstractSpinBoxPrivate::QAbstractSpinBoxPrivate() - : edit(nullptr), type(QVariant::Invalid), spinClickTimerId(-1), + : edit(nullptr), type(QMetaType::UnknownType), spinClickTimerId(-1), spinClickTimerInterval(100), spinClickThresholdTimerId(-1), spinClickThresholdTimerInterval(-1), effectiveSpinRepeatRate(1), buttonState(None), cachedText(QLatin1String("\x01")), cachedState(QValidator::Invalid), pendingEmit(false), readOnly(false), wrapping(false), @@ -1805,7 +1805,7 @@ void QAbstractSpinBoxPrivate::setValue(const QVariant &val, EmitPolicy ep, void QAbstractSpinBoxPrivate::updateEdit() { Q_Q(QAbstractSpinBox); - if (type == QVariant::Invalid) + if (type == QMetaType::UnknownType) return; const QString newText = specialValue() ? specialValueText : prefix + textFromValue(value) + suffix; if (newText == edit->displayText() || cleared) @@ -1865,8 +1865,8 @@ QVariant QAbstractSpinBoxPrivate::getZeroVariant() const { QVariant ret; switch (type) { - case QVariant::Int: ret = QVariant((int)0); break; - case QVariant::Double: ret = QVariant((double)0.0); break; + case QMetaType::Int: ret = QVariant(0); break; + case QMetaType::Double: ret = QVariant(0.0); break; default: break; } return ret; @@ -1913,7 +1913,7 @@ QVariant QAbstractSpinBoxPrivate::valueFromText(const QString &) const void QAbstractSpinBoxPrivate::interpret(EmitPolicy ep) { Q_Q(QAbstractSpinBox); - if (type == QVariant::Invalid || cleared) + if (type == QMetaType::UnknownType || cleared) return; QVariant v = getZeroVariant(); @@ -2013,11 +2013,11 @@ void QSpinBoxValidator::fixup(QString &input) const QVariant operator+(const QVariant &arg1, const QVariant &arg2) { QVariant ret; - if (Q_UNLIKELY(arg1.type() != arg2.type())) + if (Q_UNLIKELY(arg1.userType() != arg2.userType())) qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, __LINE__); - switch (arg1.type()) { - case QVariant::Int: { + switch (arg1.userType()) { + case QMetaType::Int: { const int int1 = arg1.toInt(); const int int2 = arg2.toInt(); if (int1 > 0 && (int2 >= INT_MAX - int1)) { @@ -2031,9 +2031,9 @@ QVariant operator+(const QVariant &arg1, const QVariant &arg2) } break; } - case QVariant::Double: ret = QVariant(arg1.toDouble() + arg2.toDouble()); break; + case QMetaType::Double: ret = QVariant(arg1.toDouble() + arg2.toDouble()); break; #if QT_CONFIG(datetimeparser) - case QVariant::DateTime: { + case QMetaType::QDateTime: { QDateTime a2 = arg2.toDateTime(); QDateTime a1 = arg1.toDateTime().addDays(QDATETIMEEDIT_DATE_MIN.daysTo(a2.date())); a1.setTime(a1.time().addMSecs(a2.time().msecsSinceStartOfDay())); @@ -2055,13 +2055,13 @@ QVariant operator+(const QVariant &arg1, const QVariant &arg2) QVariant operator-(const QVariant &arg1, const QVariant &arg2) { QVariant ret; - if (Q_UNLIKELY(arg1.type() != arg2.type())) + if (Q_UNLIKELY(arg1.userType() != arg2.userType())) qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, __LINE__); - switch (arg1.type()) { - case QVariant::Int: ret = QVariant(arg1.toInt() - arg2.toInt()); break; - case QVariant::Double: ret = QVariant(arg1.toDouble() - arg2.toDouble()); break; - case QVariant::DateTime: { + switch (arg1.userType()) { + case QMetaType::Int: ret = QVariant(arg1.toInt() - arg2.toInt()); break; + case QMetaType::Double: ret = QVariant(arg1.toDouble() - arg2.toDouble()); break; + case QMetaType::QDateTime: { QDateTime a1 = arg1.toDateTime(); QDateTime a2 = arg2.toDateTime(); int days = a2.daysTo(a1); @@ -2090,13 +2090,13 @@ QVariant operator*(const QVariant &arg1, double multiplier) { QVariant ret; - switch (arg1.type()) { - case QVariant::Int: + switch (arg1.userType()) { + case QMetaType::Int: ret = static_cast(qBound(INT_MIN, arg1.toInt() * multiplier, INT_MAX)); break; - case QVariant::Double: ret = QVariant(arg1.toDouble() * multiplier); break; + case QMetaType::Double: ret = QVariant(arg1.toDouble() * multiplier); break; #if QT_CONFIG(datetimeparser) - case QVariant::DateTime: { + case QMetaType::QDateTime: { double days = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDateTime().date()) * multiplier; const qint64 daysInt = qint64(days); days -= daysInt; @@ -2119,17 +2119,17 @@ double operator/(const QVariant &arg1, const QVariant &arg2) double a1 = 0; double a2 = 0; - switch (arg1.type()) { - case QVariant::Int: + switch (arg1.userType()) { + case QMetaType::Int: a1 = (double)arg1.toInt(); a2 = (double)arg2.toInt(); break; - case QVariant::Double: + case QMetaType::Double: a1 = arg1.toDouble(); a2 = arg2.toDouble(); break; #if QT_CONFIG(datetimeparser) - case QVariant::DateTime: + case QMetaType::QDateTime: a1 = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDate()); a2 = QDATETIMEEDIT_DATE_MIN.daysTo(arg2.toDate()); a1 += arg1.toDateTime().time().msecsSinceStartOfDay() / (36e5 * 24); @@ -2144,9 +2144,9 @@ double operator/(const QVariant &arg1, const QVariant &arg2) int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant &arg2) { - switch (arg2.type()) { - case QVariant::Date: - Q_ASSERT_X(arg1.type() == QVariant::Date, "QAbstractSpinBoxPrivate::variantCompare", + switch (arg2.userType()) { + case QMetaType::QDate: + Q_ASSERT_X(arg1.userType() == QMetaType::QDate, "QAbstractSpinBoxPrivate::variantCompare", qPrintable(QString::fromLatin1("Internal error 1 (%1)"). arg(QString::fromLatin1(arg1.typeName())))); if (arg1.toDate() == arg2.toDate()) { @@ -2156,8 +2156,8 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } else { return 1; } - case QVariant::Time: - Q_ASSERT_X(arg1.type() == QVariant::Time, "QAbstractSpinBoxPrivate::variantCompare", + case QMetaType::QTime: + Q_ASSERT_X(arg1.userType() == QMetaType::QTime, "QAbstractSpinBoxPrivate::variantCompare", qPrintable(QString::fromLatin1("Internal error 2 (%1)"). arg(QString::fromLatin1(arg1.typeName())))); if (arg1.toTime() == arg2.toTime()) { @@ -2169,7 +2169,7 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } - case QVariant::DateTime: + case QMetaType::QDateTime: if (arg1.toDateTime() == arg2.toDateTime()) { return 0; } else if (arg1.toDateTime() < arg2.toDateTime()) { @@ -2177,7 +2177,7 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } else { return 1; } - case QVariant::Int: + case QMetaType::Int: if (arg1.toInt() == arg2.toInt()) { return 0; } else if (arg1.toInt() < arg2.toInt()) { @@ -2185,7 +2185,7 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } else { return 1; } - case QVariant::Double: + case QMetaType::Double: if (arg1.toDouble() == arg2.toDouble()) { return 0; } else if (arg1.toDouble() < arg2.toDouble()) { @@ -2193,8 +2193,8 @@ int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant } else { return 1; } - case QVariant::Invalid: - if (arg2.type() == QVariant::Invalid) + case QMetaType::UnknownType: + if (arg2.userType() == QMetaType::UnknownType) return 0; Q_FALLTHROUGH(); default: diff --git a/src/widgets/widgets/qabstractspinbox_p.h b/src/widgets/widgets/qabstractspinbox_p.h index ad169fde19..63b19c7317 100644 --- a/src/widgets/widgets/qabstractspinbox_p.h +++ b/src/widgets/widgets/qabstractspinbox_p.h @@ -127,7 +127,7 @@ public: QLineEdit *edit; QString prefix, suffix, specialValueText; QVariant value, minimum, maximum, singleStep; - QVariant::Type type; + QMetaType::Type type; int spinClickTimerId, spinClickTimerInterval, spinClickThresholdTimerId, spinClickThresholdTimerInterval; int effectiveSpinRepeatRate; uint buttonState; diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index d786c7ff83..9826cabe50 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -144,11 +144,11 @@ QStyleOptionMenuItem QComboMenuDelegate::getStyleOption(const QStyleOptionViewIt menuOption.menuItemType = QStyleOptionMenuItem::Normal; QVariant variant = index.model()->data(index, Qt::DecorationRole); - switch (variant.type()) { - case QVariant::Icon: + switch (variant.userType()) { + case QMetaType::QIcon: menuOption.icon = qvariant_cast(variant); break; - case QVariant::Color: { + case QMetaType::QColor: { static QPixmap pixmap(option.decorationSize); pixmap.fill(qvariant_cast(variant)); menuOption.icon = pixmap; @@ -1888,7 +1888,7 @@ void QComboBoxPrivate::updateDelegate(bool force) QIcon QComboBoxPrivate::itemIcon(const QModelIndex &index) const { QVariant decoration = model->data(index, Qt::DecorationRole); - if (decoration.type() == QVariant::Pixmap) + if (decoration.userType() == QMetaType::QPixmap) return QIcon(qvariant_cast(decoration)); else return qvariant_cast(decoration); diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index 5f415aca42..63d5ae268e 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -195,11 +195,19 @@ QDateTimeEdit::QDateTimeEdit(const QTime &time, QWidget *parent) d->init(time.isValid() ? time : QDATETIMEEDIT_TIME_MIN); } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) /*! \internal */ - QDateTimeEdit::QDateTimeEdit(const QVariant &var, QVariant::Type parserType, QWidget *parent) + : QDateTimeEdit(var, QMetaType::Type(parserType), parent) +{ } +/*! + \internal +*/ +#endif + +QDateTimeEdit::QDateTimeEdit(const QVariant &var, QMetaType::Type parserType, QWidget *parent) : QAbstractSpinBox(*new QDateTimeEditPrivate, parent) { Q_D(QDateTimeEdit); @@ -1564,7 +1572,7 @@ void QDateTimeEdit::mousePressEvent(QMouseEvent *event) QTimeEdit::QTimeEdit(QWidget *parent) - : QDateTimeEdit(QDATETIMEEDIT_TIME_MIN, QVariant::Time, parent) + : QDateTimeEdit(QDATETIMEEDIT_TIME_MIN, QMetaType::QTime, parent) { connect(this, &QTimeEdit::timeChanged, this, &QTimeEdit::userTimeChanged); } @@ -1575,7 +1583,7 @@ QTimeEdit::QTimeEdit(QWidget *parent) */ QTimeEdit::QTimeEdit(const QTime &time, QWidget *parent) - : QDateTimeEdit(time, QVariant::Time, parent) + : QDateTimeEdit(time, QMetaType::QTime, parent) { connect(this, &QTimeEdit::timeChanged, this, &QTimeEdit::userTimeChanged); } @@ -1634,7 +1642,7 @@ QTimeEdit::~QTimeEdit() */ QDateEdit::QDateEdit(QWidget *parent) - : QDateTimeEdit(QDATETIMEEDIT_DATE_INITIAL, QVariant::Date, parent) + : QDateTimeEdit(QDATETIMEEDIT_DATE_INITIAL, QMetaType::QDate, parent) { connect(this, &QDateEdit::dateChanged, this, &QDateEdit::userDateChanged); } @@ -1645,7 +1653,7 @@ QDateEdit::QDateEdit(QWidget *parent) */ QDateEdit::QDateEdit(const QDate &date, QWidget *parent) - : QDateTimeEdit(date, QVariant::Date, parent) + : QDateTimeEdit(date, QMetaType::QDate, parent) { connect(this, &QDateEdit::dateChanged, this, &QDateEdit::userDateChanged); } @@ -1682,13 +1690,13 @@ QDateEdit::~QDateEdit() QDateTimeEditPrivate::QDateTimeEditPrivate() - : QDateTimeParser(QVariant::DateTime, QDateTimeParser::DateTimeEdit, QCalendar()) + : QDateTimeParser(QMetaType::QDateTime, QDateTimeParser::DateTimeEdit, QCalendar()) { hasHadFocus = false; formatExplicitlySet = false; cacheGuard = false; fixday = true; - type = QVariant::DateTime; + type = QMetaType::QDateTime; sections = { }; cachedDay = -1; currentSectionIndex = FirstSectionIndex; @@ -2430,22 +2438,22 @@ void QDateTimeEdit::initStyleOption(QStyleOptionSpinBox *option) const void QDateTimeEditPrivate::init(const QVariant &var) { Q_Q(QDateTimeEdit); - switch (var.type()) { - case QVariant::Date: + switch (var.userType()) { + case QMetaType::QDate: value = var.toDate().startOfDay(); updateTimeSpec(); q->setDisplayFormat(defaultDateFormat); if (sectionNodes.isEmpty()) // ### safeguard for broken locale q->setDisplayFormat(QLatin1String("dd/MM/yyyy")); break; - case QVariant::DateTime: + case QMetaType::QDateTime: value = var; updateTimeSpec(); q->setDisplayFormat(defaultDateTimeFormat); if (sectionNodes.isEmpty()) // ### safeguard for broken locale q->setDisplayFormat(QLatin1String("dd/MM/yyyy hh:mm:ss")); break; - case QVariant::Time: + case QMetaType::QTime: value = QDateTime(QDATETIMEEDIT_DATE_INITIAL, var.toTime()); updateTimeSpec(); q->setDisplayFormat(defaultTimeFormat); @@ -2524,7 +2532,7 @@ void QDateTimeEditPrivate::updateEditFieldGeometry() QVariant QDateTimeEditPrivate::getZeroVariant() const { - Q_ASSERT(type == QVariant::DateTime); + Q_ASSERT(type == QMetaType::QDateTime); return QDateTime(QDATETIMEEDIT_DATE_INITIAL, QTime(), spec); } diff --git a/src/widgets/widgets/qdatetimeedit.h b/src/widgets/widgets/qdatetimeedit.h index 03994675ae..8905ad4a9c 100644 --- a/src/widgets/widgets/qdatetimeedit.h +++ b/src/widgets/widgets/qdatetimeedit.h @@ -195,7 +195,10 @@ protected: void paintEvent(QPaintEvent *event) override; void initStyleOption(QStyleOptionSpinBox *option) const; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QDateTimeEdit(const QVariant &val, QVariant::Type parserType, QWidget *parent = nullptr); +#endif + QDateTimeEdit(const QVariant &val, QMetaType::Type parserType, QWidget *parent = nullptr); private: Q_DECLARE_PRIVATE(QDateTimeEdit) Q_DISABLE_COPY(QDateTimeEdit) diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index d54c0d0b20..87e8af1382 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -2250,17 +2250,17 @@ QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant a } const QPointF offset = contentOffset(); - switch (argument.type()) { - case QVariant::RectF: + switch (argument.userType()) { + case QMetaType::QRectF: argument = argument.toRectF().translated(-offset); break; - case QVariant::PointF: + case QMetaType::QPointF: argument = argument.toPointF() - offset; break; - case QVariant::Rect: + case QMetaType::QRect: argument = argument.toRect().translated(-offset.toPoint()); break; - case QVariant::Point: + case QMetaType::QPoint: argument = argument.toPoint() - offset; break; default: @@ -2268,14 +2268,14 @@ QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant a } const QVariant v = d->control->inputMethodQuery(query, argument); - switch (v.type()) { - case QVariant::RectF: + switch (v.userType()) { + case QMetaType::QRectF: return v.toRectF().translated(offset); - case QVariant::PointF: + case QMetaType::QPointF: return v.toPointF() + offset; - case QVariant::Rect: + case QMetaType::QRect: return v.toRect().translated(offset.toPoint()); - case QVariant::Point: + case QMetaType::QPoint: return v.toPoint() + offset.toPoint(); default: break; diff --git a/src/widgets/widgets/qspinbox.cpp b/src/widgets/widgets/qspinbox.cpp index 61ea81c892..08428f673e 100644 --- a/src/widgets/widgets/qspinbox.cpp +++ b/src/widgets/widgets/qspinbox.cpp @@ -1081,7 +1081,7 @@ QSpinBoxPrivate::QSpinBoxPrivate() value = minimum; displayIntegerBase = 10; singleStep = QVariant((int)1); - type = QVariant::Int; + type = QMetaType::Int; } /*! @@ -1238,7 +1238,7 @@ QDoubleSpinBoxPrivate::QDoubleSpinBoxPrivate() value = minimum; singleStep = QVariant(1.0); decimals = 2; - type = QVariant::Double; + type = QMetaType::Double; } /*! diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp index d0ccd435b3..0ba74a20e0 100644 --- a/src/widgets/widgets/qtextbrowser.cpp +++ b/src/widgets/widgets/qtextbrowser.cpp @@ -310,9 +310,9 @@ void QTextBrowserPrivate::setSource(const QUrl &url, QTextDocument::ResourceType if (url.isValid() && (newUrlWithoutFragment != currentUrlWithoutFragment || forceLoadOnSourceChange)) { QVariant data = q->loadResource(type, resolveUrl(url)); - if (data.type() == QVariant::String) { + if (data.userType() == QMetaType::QString) { txt = data.toString(); - } else if (data.type() == QVariant::ByteArray) { + } else if (data.userType() == QMetaType::QByteArray) { if (type == QTextDocument::HtmlResource) { #if QT_CONFIG(textcodec) QByteArray ba = data.toByteArray(); diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index 10de7d0b9e..913ca6ec16 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -1502,7 +1502,7 @@ void QTextEdit::resizeEvent(QResizeEvent *e) QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment"); if (!doc->pageSize().isNull() - && alignmentProperty.type() == QVariant::Bool + && alignmentProperty.userType() == QMetaType::Bool && !alignmentProperty.toBool()) { d->_q_adjustScrollbars(); @@ -1547,7 +1547,7 @@ void QTextEditPrivate::relayoutDocument() width = lineWrapColumnOrWidth; else if (lineWrap == QTextEdit::NoWrap) { QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment"); - if (alignmentProperty.type() == QVariant::Bool && !alignmentProperty.toBool()) { + if (alignmentProperty.userType() == QMetaType::Bool && !alignmentProperty.toBool()) { width = 0; } @@ -1835,17 +1835,17 @@ QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argume } const QPointF offset(-d->horizontalOffset(), -d->verticalOffset()); - switch (argument.type()) { - case QVariant::RectF: + switch (argument.userType()) { + case QMetaType::QRectF: argument = argument.toRectF().translated(-offset); break; - case QVariant::PointF: + case QMetaType::QPointF: argument = argument.toPointF() - offset; break; - case QVariant::Rect: + case QMetaType::QRect: argument = argument.toRect().translated(-offset.toPoint()); break; - case QVariant::Point: + case QMetaType::QPoint: argument = argument.toPoint() - offset; break; default: @@ -1853,14 +1853,14 @@ QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argume } const QVariant v = d->control->inputMethodQuery(query, argument); - switch (v.type()) { - case QVariant::RectF: + switch (v.userType()) { + case QMetaType::QRectF: return v.toRectF().translated(offset); - case QVariant::PointF: + case QMetaType::QPointF: return v.toPointF() + offset; - case QVariant::Rect: + case QMetaType::QRect: return v.toRect().translated(offset.toPoint()); - case QVariant::Point: + case QMetaType::QPoint: return v.toPoint() + offset.toPoint(); default: break; -- cgit v1.2.3 From 49f143e19ca11ef48260a3aaaa4ddbe490cf81ab Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Tue, 26 Nov 2019 23:55:01 +0100 Subject: QSslCertificate: migrate to QRegularExpression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is part of the migration of qtbase from QRexExp to QRegularExpression. If support for regular expression is disabled, fixed string can still be used. [ChangeLog][QtCore][QSslCertificate] Add overload of fromPath that does not make use of QRegExp and deprecate the QRegExp variant. Task-number: QTBUG-72587 Change-Id: I507d8941cc7d70166da0948375dc421fe5e7d967 Reviewed-by: Mårten Nordheim --- .../code/src_network_ssl_qsslcertificate.cpp | 8 ++ src/network/ssl/qsslcertificate.cpp | 107 +++++++++++++++- src/network/ssl/qsslcertificate.h | 20 ++- .../ssl/qsslcertificate/tst_qsslcertificate.cpp | 140 ++++++++++++++++----- 4 files changed, 245 insertions(+), 30 deletions(-) diff --git a/src/network/doc/snippets/code/src_network_ssl_qsslcertificate.cpp b/src/network/doc/snippets/code/src_network_ssl_qsslcertificate.cpp index 12691da7a2..b381ae7b6e 100644 --- a/src/network/doc/snippets/code/src_network_ssl_qsslcertificate.cpp +++ b/src/network/doc/snippets/code/src_network_ssl_qsslcertificate.cpp @@ -55,3 +55,11 @@ for (const QSslCertificate &cert : certs) { qDebug() << cert.issuerInfo(QSslCertificate::Organization); } //! [0] + +//! [1] +const auto certs = QSslCertificate::fromPath("C:/ssl/certificate.*.pem", + QSsl::Pem, QSslCertificate::Wildcard); +for (const QSslCertificate &cert : certs) { + qDebug() << cert.issuerInfo(QSslCertificate::Organization); +} +//! [1] diff --git a/src/network/ssl/qsslcertificate.cpp b/src/network/ssl/qsslcertificate.cpp index 4820953468..c179cf9c4a 100644 --- a/src/network/ssl/qsslcertificate.cpp +++ b/src/network/ssl/qsslcertificate.cpp @@ -124,7 +124,9 @@ #if QT_CONFIG(schannel) #include "qsslsocket_schannel_p.h" #endif - +#if QT_CONFIG(regularexpression) +#include "qregularexpression.h" +#endif #include "qssl_p.h" #include "qsslcertificate.h" #include "qsslcertificate_p.h" @@ -462,7 +464,10 @@ QByteArray QSslCertificate::digest(QCryptographicHash::Algorithm algorithm) cons \since 5.0 */ +#if QT_DEPRECATED_SINCE(5,15) /*! + \obsolete + Searches all files in the \a path for certificates encoded in the specified \a format and returns them in a list. \a path must be a file or a pattern matching one or more files, as specified by \a syntax. @@ -537,6 +542,106 @@ QList QSslCertificate::fromPath(const QString &path, } return certs; } +#endif // QT_DEPRECATED_SINCE(5,15) + +/*! + \since 5.15 + + Searches all files in the \a path for certificates encoded in the + specified \a format and returns them in a list. \a path must be a file + or a pattern matching one or more files, as specified by \a syntax. + + Example: + + \snippet code/src_network_ssl_qsslcertificate.cpp 1 + + \sa fromData() +*/ +QList QSslCertificate::fromPath(const QString &path, + QSsl::EncodingFormat format, + PatternSyntax syntax) +{ + // $, (,), *, +, ., ?, [, ,], ^, {, | and }. + + // make sure to use the same path separators on Windows and Unix like systems. + QString sourcePath = QDir::fromNativeSeparators(path); + + // Find the path without the filename + QString pathPrefix = sourcePath.left(sourcePath.lastIndexOf(QLatin1Char('/'))); + + // Check if the path contains any special chars + int pos = -1; + +#if QT_CONFIG(regularexpression) + if (syntax == Wildcard) + pos = pathPrefix.indexOf(QRegularExpression(QLatin1String("[*?[]"))); + else if (syntax == RegExp) + pos = sourcePath.indexOf(QRegularExpression(QLatin1String("[\\$\\(\\)\\*\\+\\.\\?\\[\\]\\^\\{\\}\\|]"))); +#else + if (syntax == Wildcard || syntax == RegExp) + qWarning("Regular expression support is disabled in this build. Only fixed string can be searched"); + return QList(); +#endif + + if (pos != -1) { + // there was a special char in the path so cut of the part containing that char. + pathPrefix = pathPrefix.left(pos); + const int lastIndexOfSlash = pathPrefix.lastIndexOf(QLatin1Char('/')); + if (lastIndexOfSlash != -1) + pathPrefix = pathPrefix.left(lastIndexOfSlash); + else + pathPrefix.clear(); + } else { + // Check if the path is a file. + if (QFileInfo(sourcePath).isFile()) { + QFile file(sourcePath); + QIODevice::OpenMode openMode = QIODevice::ReadOnly; + if (format == QSsl::Pem) + openMode |= QIODevice::Text; + if (file.open(openMode)) + return QSslCertificate::fromData(file.readAll(), format); + return QList(); + } + } + + // Special case - if the prefix ends up being nothing, use "." instead. + int startIndex = 0; + if (pathPrefix.isEmpty()) { + pathPrefix = QLatin1String("."); + startIndex = 2; + } + + // The path can be a file or directory. + QList certs; + +#if QT_CONFIG(regularexpression) + if (syntax == Wildcard) + sourcePath = QRegularExpression::wildcardToRegularExpression(sourcePath); + + QRegularExpression pattern(QRegularExpression::anchoredPattern(sourcePath)); +#endif + + QDirIterator it(pathPrefix, QDir::Files, QDirIterator::FollowSymlinks | QDirIterator::Subdirectories); + while (it.hasNext()) { + QString filePath = startIndex == 0 ? it.next() : it.next().mid(startIndex); + +#if QT_CONFIG(regularexpression) + if (!pattern.match(filePath).hasMatch()) + continue; +#else + if (sourcePath != filePath) + continue; +#endif + + QFile file(filePath); + QIODevice::OpenMode openMode = QIODevice::ReadOnly; + if (format == QSsl::Pem) + openMode |= QIODevice::Text; + if (file.open(openMode)) + certs += QSslCertificate::fromData(file.readAll(), format); + } + return certs; +} /*! Searches for and parses all certificates in \a device that are diff --git a/src/network/ssl/qsslcertificate.h b/src/network/ssl/qsslcertificate.h index 69901b526c..9993769888 100644 --- a/src/network/ssl/qsslcertificate.h +++ b/src/network/ssl/qsslcertificate.h @@ -84,6 +84,13 @@ public: EmailAddress }; + enum PatternSyntax { + RegExp, + Wildcard, + FixedString + }; + + explicit QSslCertificate(QIODevice *device, QSsl::EncodingFormat format = QSsl::Pem); explicit QSslCertificate(const QByteArray &data = QByteArray(), QSsl::EncodingFormat format = QSsl::Pem); QSslCertificate(const QSslCertificate &other); @@ -139,9 +146,20 @@ public: QByteArray toDer() const; QString toText() const; - static QList fromPath( +#if QT_DEPRECATED_SINCE(5,15) + QT_DEPRECATED_X("Use the overload not using QRegExp") static QList fromPath( const QString &path, QSsl::EncodingFormat format = QSsl::Pem, QRegExp::PatternSyntax syntax = QRegExp::FixedString); + + static QList fromPath( + const QString &path, QSsl::EncodingFormat format, + PatternSyntax syntax); +#else + static QList fromPath( + const QString &path, QSsl::EncodingFormat format = QSsl::Pem, + PatternSyntax syntax = FixedString); +#endif + static QList fromDevice( QIODevice *device, QSsl::EncodingFormat format = QSsl::Pem); static QList fromData( diff --git a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp index 14718ad373..a7a81e9f0b 100644 --- a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp +++ b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp @@ -86,6 +86,8 @@ private slots: void fromDevice(); void fromPath_data(); void fromPath(); + void fromPath_qregularexpression_data(); + void fromPath_qregularexpression(); void certInfo(); void certInfoQByteArray(); void task256066toPem(); @@ -434,7 +436,7 @@ void tst_QSslCertificate::subjectAlternativeNames() void tst_QSslCertificate::utf8SubjectNames() { QSslCertificate cert = QSslCertificate::fromPath(testDataDir + "certificates/cert-ss-san-utf8.pem", QSsl::Pem, - QRegExp::FixedString).first(); + QSslCertificate::FixedString).first(); QVERIFY(!cert.isNull()); // O is "Heavy Metal Records" with heavy use of "decorations" like accents, umlauts etc., @@ -625,6 +627,88 @@ void tst_QSslCertificate::fromPath() numCerts); } +void tst_QSslCertificate::fromPath_qregularexpression_data() +{ + QTest::addColumn("path"); + QTest::addColumn("syntax"); + QTest::addColumn("pemencoding"); + QTest::addColumn("numCerts"); + + QTest::newRow("empty fixed pem") << QString() << int(QSslCertificate::FixedString) << true << 0; + QTest::newRow("empty fixed der") << QString() << int(QSslCertificate::FixedString) << false << 0; + QTest::newRow("empty regexp pem") << QString() << int(QSslCertificate::RegExp) << true << 0; + QTest::newRow("empty regexp der") << QString() << int(QSslCertificate::RegExp) << false << 0; + QTest::newRow("empty wildcard pem") << QString() << int(QSslCertificate::Wildcard) << true << 0; + QTest::newRow("empty wildcard der") << QString() << int(QSslCertificate::Wildcard) << false << 0; + QTest::newRow("\"certificates\" fixed pem") << (testDataDir + "certificates") << int(QSslCertificate::FixedString) << true << 0; + QTest::newRow("\"certificates\" fixed der") << (testDataDir + "certificates") << int(QSslCertificate::FixedString) << false << 0; + QTest::newRow("\"certificates\" regexp pem") << (testDataDir + "certificates") << int(QSslCertificate::RegExp) << true << 0; + QTest::newRow("\"certificates\" regexp der") << (testDataDir + "certificates") << int(QSslCertificate::RegExp) << false << 0; + QTest::newRow("\"certificates\" wildcard pem") << (testDataDir + "certificates") << int(QSslCertificate::Wildcard) << true << 0; + QTest::newRow("\"certificates\" wildcard der") << (testDataDir + "certificates") << int(QSslCertificate::Wildcard) << false << 0; + QTest::newRow("\"certificates/cert.pem\" fixed pem") << (testDataDir + "certificates/cert.pem") << int(QSslCertificate::FixedString) << true << 1; + QTest::newRow("\"certificates/cert.pem\" fixed der") << (testDataDir + "certificates/cert.pem") << int(QSslCertificate::FixedString) << false << 0; + QTest::newRow("\"certificates/cert.pem\" regexp pem") << (testDataDir + "certificates/cert.pem") << int(QSslCertificate::RegExp) << true << 1; + QTest::newRow("\"certificates/cert.pem\" regexp der") << (testDataDir + "certificates/cert.pem") << int(QSslCertificate::RegExp) << false << 0; + QTest::newRow("\"certificates/cert.pem\" wildcard pem") << (testDataDir + "certificates/cert.pem") << int(QSslCertificate::Wildcard) << true << 1; + QTest::newRow("\"certificates/cert.pem\" wildcard der") << (testDataDir + "certificates/cert.pem") << int(QSslCertificate::Wildcard) << false << 0; + QTest::newRow("\"certificates/*\" fixed pem") << (testDataDir + "certificates/*") << int(QSslCertificate::FixedString) << true << 0; + QTest::newRow("\"certificates/*\" fixed der") << (testDataDir + "certificates/*") << int(QSslCertificate::FixedString) << false << 0; + QTest::newRow("\"certificates/*\" regexp pem") << (testDataDir + "certificates/*") << int(QSslCertificate::RegExp) << true << 0; + QTest::newRow("\"certificates/*\" regexp der") << (testDataDir + "certificates/*") << int(QSslCertificate::RegExp) << false << 0; + QTest::newRow("\"certificates/*\" wildcard pem") << (testDataDir + "certificates/*") << int(QSslCertificate::Wildcard) << true << 7; + QTest::newRow("\"certificates/ca*\" wildcard pem") << (testDataDir + "certificates/ca*") << int(QSslCertificate::Wildcard) << true << 1; + QTest::newRow("\"certificates/cert*\" wildcard pem") << (testDataDir + "certificates/cert*") << int(QSslCertificate::Wildcard) << true << 4; + QTest::newRow("\"certificates/cert-[sure]*\" wildcard pem") << (testDataDir + "certificates/cert-[sure]*") << int(QSslCertificate::Wildcard) << true << 3; + QTest::newRow("\"certificates/cert-[not]*\" wildcard pem") << (testDataDir + "certificates/cert-[not]*") << int(QSslCertificate::Wildcard) << true << 0; + QTest::newRow("\"certificates/*\" wildcard der") << (testDataDir + "certificates/*") << int(QSslCertificate::Wildcard) << false << 2; + QTest::newRow("\"c*/c*.pem\" fixed pem") << (testDataDir + "c*/c*.pem") << int(QSslCertificate::FixedString) << true << 0; + QTest::newRow("\"c*/c*.pem\" fixed der") << (testDataDir + "c*/c*.pem") << int(QSslCertificate::FixedString) << false << 0; + QTest::newRow("\"c*/c*.pem\" regexp pem") << (testDataDir + "c*/c*.pem") << int(QSslCertificate::RegExp) << true << 0; + QTest::newRow("\"c*/c*.pem\" regexp der") << (testDataDir + "c*/c*.pem") << int(QSslCertificate::RegExp) << false << 0; + QTest::newRow("\"c*/c*.pem\" wildcard pem") << (testDataDir + "c*/c*.pem") << int(QSslCertificate::Wildcard) << true << 5; + QTest::newRow("\"c*/c*.pem\" wildcard der") << (testDataDir + "c*/c*.pem") << int(QSslCertificate::Wildcard) << false << 0; + QTest::newRow("\"d*/c*.pem\" fixed pem") << (testDataDir + "d*/c*.pem") << int(QSslCertificate::FixedString) << true << 0; + QTest::newRow("\"d*/c*.pem\" fixed der") << (testDataDir + "d*/c*.pem") << int(QSslCertificate::FixedString) << false << 0; + QTest::newRow("\"d*/c*.pem\" regexp pem") << (testDataDir + "d*/c*.pem") << int(QSslCertificate::RegExp) << true << 0; + QTest::newRow("\"d*/c*.pem\" regexp der") << (testDataDir + "d*/c*.pem") << int(QSslCertificate::RegExp) << false << 0; + QTest::newRow("\"d*/c*.pem\" wildcard pem") << (testDataDir + "d*/c*.pem") << int(QSslCertificate::Wildcard) << true << 0; + QTest::newRow("\"d*/c*.pem\" wildcard der") << (testDataDir + "d*/c*.pem") << int(QSslCertificate::Wildcard) << false << 0; + QTest::newRow("\"c.*/c.*.pem\" fixed pem") << (testDataDir + "c.*/c.*.pem") << int(QSslCertificate::FixedString) << true << 0; + QTest::newRow("\"c.*/c.*.pem\" fixed der") << (testDataDir + "c.*/c.*.pem") << int(QSslCertificate::FixedString) << false << 0; + QTest::newRow("\"c.*/c.*.pem\" regexp pem") << (testDataDir + "c.*/c.*.pem") << int(QSslCertificate::RegExp) << true << 5; + QTest::newRow("\"c.*/c.*.pem\" regexp der") << (testDataDir + "c.*/c.*.pem") << int(QSslCertificate::RegExp) << false << 0; + QTest::newRow("\"c.*/c.*.pem\" wildcard pem") << (testDataDir + "c.*/c.*.pem") << int(QSslCertificate::Wildcard) << true << 0; + QTest::newRow("\"c.*/c.*.pem\" wildcard der") << (testDataDir + "c.*/c.*.pem") << int(QSslCertificate::Wildcard) << false << 0; + QTest::newRow("\"d.*/c.*.pem\" fixed pem") << (testDataDir + "d.*/c.*.pem") << int(QSslCertificate::FixedString) << true << 0; + QTest::newRow("\"d.*/c.*.pem\" fixed der") << (testDataDir + "d.*/c.*.pem") << int(QSslCertificate::FixedString) << false << 0; + QTest::newRow("\"d.*/c.*.pem\" regexp pem") << (testDataDir + "d.*/c.*.pem") << int(QSslCertificate::RegExp) << true << 0; + QTest::newRow("\"d.*/c.*.pem\" regexp der") << (testDataDir + "d.*/c.*.pem") << int(QSslCertificate::RegExp) << false << 0; + QTest::newRow("\"d.*/c.*.pem\" wildcard pem") << (testDataDir + "d.*/c.*.pem") << int(QSslCertificate::Wildcard) << true << 0; + QTest::newRow("\"d.*/c.*.pem\" wildcard der") << (testDataDir + "d.*/c.*.pem") << int(QSslCertificate::Wildcard) << false << 0; +#ifdef Q_OS_LINUX + QTest::newRow("absolute path wildcard pem") << (testDataDir + "certificates/*.pem") << int(QSslCertificate::Wildcard) << true << 7; +#endif + + QTest::newRow("trailing-whitespace") << (testDataDir + "more-certificates/trailing-whitespace.pem") << int(QSslCertificate::FixedString) << true << 1; + QTest::newRow("no-ending-newline") << (testDataDir + "more-certificates/no-ending-newline.pem") << int(QSslCertificate::FixedString) << true << 1; + QTest::newRow("malformed-just-begin") << (testDataDir + "more-certificates/malformed-just-begin.pem") << int(QSslCertificate::FixedString) << true << 0; + QTest::newRow("malformed-just-begin-no-newline") << (testDataDir + "more-certificates/malformed-just-begin-no-newline.pem") << int(QSslCertificate::FixedString) << true << 0; +} + +void tst_QSslCertificate::fromPath_qregularexpression() +{ + QFETCH(QString, path); + QFETCH(int, syntax); + QFETCH(bool, pemencoding); + QFETCH(int, numCerts); + + QCOMPARE(QSslCertificate::fromPath(path, + pemencoding ? QSsl::Pem : QSsl::Der, + QSslCertificate::PatternSyntax(syntax)).size(), + numCerts); +} + void tst_QSslCertificate::certInfo() { // MD5 Fingerprint=B6:CF:57:34:DA:A9:73:21:82:F7:CF:4D:3D:85:31:88 @@ -711,7 +795,7 @@ void tst_QSslCertificate::certInfo() "55:ba:e7:fb:95:5d:91"; QSslCertificate cert = QSslCertificate::fromPath(testDataDir + "certificates/cert.pem", QSsl::Pem, - QRegExp::FixedString).first(); + QSslCertificate::FixedString).first(); QVERIFY(!cert.isNull()); QCOMPARE(cert.issuerInfo(QSslCertificate::Organization)[0], QString("CryptSoft Pty Ltd")); @@ -768,7 +852,7 @@ void tst_QSslCertificate::certInfo() void tst_QSslCertificate::certInfoQByteArray() { QSslCertificate cert = QSslCertificate::fromPath(testDataDir + "certificates/cert.pem", QSsl::Pem, - QRegExp::FixedString).first(); + QSslCertificate::FixedString).first(); QVERIFY(!cert.isNull()); // in this test, check the bytearray variants before the enum variants to see if @@ -820,7 +904,7 @@ void tst_QSslCertificate::nulInCN() QSKIP("Generic QSslCertificatePrivate fails this test"); #endif QList certList = - QSslCertificate::fromPath(testDataDir + "more-certificates/badguy-nul-cn.crt"); + QSslCertificate::fromPath(testDataDir + "more-certificates/badguy-nul-cn.crt", QSsl::Pem, QSslCertificate::FixedString); QCOMPARE(certList.size(), 1); const QSslCertificate &cert = certList.at(0); @@ -839,7 +923,7 @@ void tst_QSslCertificate::nulInSan() QSKIP("Generic QSslCertificatePrivate fails this test"); #endif QList certList = - QSslCertificate::fromPath(testDataDir + "more-certificates/badguy-nul-san.crt"); + QSslCertificate::fromPath(testDataDir + "more-certificates/badguy-nul-san.crt", QSsl::Pem, QSslCertificate::FixedString); QCOMPARE(certList.size(), 1); const QSslCertificate &cert = certList.at(0); @@ -859,7 +943,7 @@ void tst_QSslCertificate::nulInSan() void tst_QSslCertificate::largeSerialNumber() { QList certList = - QSslCertificate::fromPath(testDataDir + "more-certificates/cert-large-serial-number.pem"); + QSslCertificate::fromPath(testDataDir + "more-certificates/cert-large-serial-number.pem", QSsl::Pem, QSslCertificate::FixedString); QCOMPARE(certList.size(), 1); @@ -871,7 +955,7 @@ void tst_QSslCertificate::largeSerialNumber() void tst_QSslCertificate::largeExpirationDate() // QTBUG-12489 { QList certList = - QSslCertificate::fromPath(testDataDir + "more-certificates/cert-large-expiration-date.pem"); + QSslCertificate::fromPath(testDataDir + "more-certificates/cert-large-expiration-date.pem", QSsl::Pem, QSslCertificate::FixedString); QCOMPARE(certList.size(), 1); @@ -884,7 +968,7 @@ void tst_QSslCertificate::largeExpirationDate() // QTBUG-12489 void tst_QSslCertificate::blacklistedCertificates() { - QList blacklistedCerts = QSslCertificate::fromPath(testDataDir + "more-certificates/blacklisted*.pem", QSsl::Pem, QRegExp::Wildcard); + QList blacklistedCerts = QSslCertificate::fromPath(testDataDir + "more-certificates/blacklisted*.pem", QSsl::Pem, QSslCertificate::Wildcard); QVERIFY(blacklistedCerts.count() > 0); for (int a = 0; a < blacklistedCerts.count(); a++) { QVERIFY(blacklistedCerts.at(a).isBlacklisted()); @@ -893,15 +977,15 @@ void tst_QSslCertificate::blacklistedCertificates() void tst_QSslCertificate::selfsignedCertificates() { - QVERIFY(QSslCertificate::fromPath(testDataDir + "certificates/cert-ss.pem").first().isSelfSigned()); - QVERIFY(!QSslCertificate::fromPath(testDataDir + "certificates/cert.pem").first().isSelfSigned()); + QVERIFY(QSslCertificate::fromPath(testDataDir + "certificates/cert-ss.pem", QSsl::Pem, QSslCertificate::FixedString).first().isSelfSigned()); + QVERIFY(!QSslCertificate::fromPath(testDataDir + "certificates/cert.pem", QSsl::Pem, QSslCertificate::FixedString).first().isSelfSigned()); QVERIFY(!QSslCertificate().isSelfSigned()); } void tst_QSslCertificate::toText() { QList certList = - QSslCertificate::fromPath(testDataDir + "more-certificates/cert-large-expiration-date.pem"); + QSslCertificate::fromPath(testDataDir + "more-certificates/cert-large-expiration-date.pem", QSsl::Pem, QSslCertificate::FixedString); QCOMPARE(certList.size(), 1); const QSslCertificate &cert = certList.at(0); @@ -943,7 +1027,7 @@ void tst_QSslCertificate::toText() void tst_QSslCertificate::multipleCommonNames() { QList certList = - QSslCertificate::fromPath(testDataDir + "more-certificates/test-cn-two-cns-cert.pem"); + QSslCertificate::fromPath(testDataDir + "more-certificates/test-cn-two-cns-cert.pem", QSsl::Pem, QSslCertificate::FixedString); QVERIFY(certList.count() > 0); QStringList commonNames = certList[0].subjectInfo(QSslCertificate::CommonName); @@ -954,14 +1038,14 @@ void tst_QSslCertificate::multipleCommonNames() void tst_QSslCertificate::subjectAndIssuerAttributes() { QList certList = - QSslCertificate::fromPath(testDataDir + "more-certificates/test-cn-with-drink-cert.pem"); + QSslCertificate::fromPath(testDataDir + "more-certificates/test-cn-with-drink-cert.pem", QSsl::Pem, QSslCertificate::FixedString); QVERIFY(certList.count() > 0); QList attributes = certList[0].subjectInfoAttributes(); QVERIFY(attributes.contains(QByteArray("favouriteDrink"))); attributes.clear(); - certList = QSslCertificate::fromPath(testDataDir + "more-certificates/natwest-banking.pem"); + certList = QSslCertificate::fromPath(testDataDir + "more-certificates/natwest-banking.pem", QSsl::Pem, QSslCertificate::FixedString); QVERIFY(certList.count() > 0); QByteArray shortName("1.3.6.1.4.1.311.60.2.1.3"); @@ -996,17 +1080,17 @@ void tst_QSslCertificate::verify() errors.clear(); // Verify a valid cert signed by a CA - QList caCerts = QSslCertificate::fromPath(testDataDir + "verify-certs/cacert.pem"); + QList caCerts = QSslCertificate::fromPath(testDataDir + "verify-certs/cacert.pem", QSsl::Pem, QSslCertificate::FixedString); QSslSocket::addDefaultCaCertificate(caCerts.first()); - toVerify = QSslCertificate::fromPath(testDataDir + "verify-certs/test-ocsp-good-cert.pem"); + toVerify = QSslCertificate::fromPath(testDataDir + "verify-certs/test-ocsp-good-cert.pem", QSsl::Pem, QSslCertificate::FixedString); errors = QSslCertificate::verify(toVerify); VERIFY_VERBOSE(errors.count() == 0); errors.clear(); // Test a blacklisted certificate - toVerify = QSslCertificate::fromPath(testDataDir + "verify-certs/test-addons-mozilla-org-cert.pem"); + toVerify = QSslCertificate::fromPath(testDataDir + "verify-certs/test-addons-mozilla-org-cert.pem", QSsl::Pem, QSslCertificate::FixedString); errors = QSslCertificate::verify(toVerify); bool foundBlack = false; foreach (const QSslError &error, errors) { @@ -1019,7 +1103,7 @@ void tst_QSslCertificate::verify() errors.clear(); // This one is expired and untrusted - toVerify = QSslCertificate::fromPath(testDataDir + "more-certificates/cert-large-serial-number.pem"); + toVerify = QSslCertificate::fromPath(testDataDir + "more-certificates/cert-large-serial-number.pem", QSsl::Pem, QSslCertificate::FixedString); errors = QSslCertificate::verify(toVerify); VERIFY_VERBOSE(errors.contains(QSslError(QSslError::SelfSignedCertificate, toVerify[0]))); VERIFY_VERBOSE(errors.contains(QSslError(QSslError::CertificateExpired, toVerify[0]))); @@ -1027,15 +1111,15 @@ void tst_QSslCertificate::verify() toVerify.clear(); // This one is signed by a valid cert, but the signer is not a valid CA - toVerify << QSslCertificate::fromPath(testDataDir + "verify-certs/test-intermediate-not-ca-cert.pem").first(); - toVerify << QSslCertificate::fromPath(testDataDir + "verify-certs/test-ocsp-good-cert.pem").first(); + toVerify << QSslCertificate::fromPath(testDataDir + "verify-certs/test-intermediate-not-ca-cert.pem", QSsl::Pem, QSslCertificate::FixedString).first(); + toVerify << QSslCertificate::fromPath(testDataDir + "verify-certs/test-ocsp-good-cert.pem", QSsl::Pem, QSslCertificate::FixedString).first(); errors = QSslCertificate::verify(toVerify); VERIFY_VERBOSE(errors.contains(QSslError(QSslError::InvalidCaCertificate, toVerify[1]))); toVerify.clear(); // This one is signed by a valid cert, and the signer is a valid CA - toVerify << QSslCertificate::fromPath(testDataDir + "verify-certs/test-intermediate-is-ca-cert.pem").first(); - toVerify << QSslCertificate::fromPath(testDataDir + "verify-certs/test-intermediate-ca-cert.pem").first(); + toVerify << QSslCertificate::fromPath(testDataDir + "verify-certs/test-intermediate-is-ca-cert.pem", QSsl::Pem, QSslCertificate::FixedString).first(); + toVerify << QSslCertificate::fromPath(testDataDir + "verify-certs/test-intermediate-ca-cert.pem", QSsl::Pem, QSslCertificate::FixedString).first(); errors = QSslCertificate::verify(toVerify); VERIFY_VERBOSE(errors.count() == 0); @@ -1065,7 +1149,7 @@ QString tst_QSslCertificate::toString(const QList& errors) void tst_QSslCertificate::extensions() { QList certList = - QSslCertificate::fromPath(testDataDir + "more-certificates/natwest-banking.pem"); + QSslCertificate::fromPath(testDataDir + "more-certificates/natwest-banking.pem", QSsl::Pem, QSslCertificate::FixedString); QVERIFY(certList.count() > 0); QSslCertificate cert = certList[0]; @@ -1163,7 +1247,7 @@ void tst_QSslCertificate::extensions() void tst_QSslCertificate::extensionsCritical() { QList certList = - QSslCertificate::fromPath(testDataDir + "verify-certs/test-addons-mozilla-org-cert.pem"); + QSslCertificate::fromPath(testDataDir + "verify-certs/test-addons-mozilla-org-cert.pem", QSsl::Pem, QSslCertificate::FixedString); QVERIFY(certList.count() > 0); QSslCertificate cert = certList[0]; @@ -1284,12 +1368,12 @@ void tst_QSslCertificate::version_data() QTest::newRow("null certificate") << QSslCertificate() << QByteArray(); QList certs; - certs << QSslCertificate::fromPath(testDataDir + "verify-certs/test-ocsp-good-cert.pem"); + certs << QSslCertificate::fromPath(testDataDir + "verify-certs/test-ocsp-good-cert.pem", QSsl::Pem, QSslCertificate::FixedString); QTest::newRow("v3 certificate") << certs.first() << QByteArrayLiteral("3"); certs.clear(); - certs << QSslCertificate::fromPath(testDataDir + "certificates/cert.pem"); + certs << QSslCertificate::fromPath(testDataDir + "certificates/cert.pem", QSsl::Pem, QSslCertificate::FixedString); QTest::newRow("v1 certificate") << certs.first() << QByteArrayLiteral("1"); } @@ -1326,7 +1410,7 @@ void tst_QSslCertificate::pkcs12() QVERIFY(ok); f.close(); - QList leafCert = QSslCertificate::fromPath(testDataDir + QLatin1String("pkcs12/leaf.crt")); + QList leafCert = QSslCertificate::fromPath(testDataDir + QLatin1String("pkcs12/leaf.crt"), QSsl::Pem, QSslCertificate::FixedString); QVERIFY(!leafCert.isEmpty()); QCOMPARE(cert, leafCert.first()); @@ -1341,7 +1425,7 @@ void tst_QSslCertificate::pkcs12() QVERIFY(!leafKey.isNull()); QCOMPARE(key, leafKey); - QList caCert = QSslCertificate::fromPath(testDataDir + QLatin1String("pkcs12/inter.crt")); + QList caCert = QSslCertificate::fromPath(testDataDir + QLatin1String("pkcs12/inter.crt"), QSsl::Pem, QSslCertificate::FixedString); QVERIFY(!caCert.isEmpty()); QVERIFY(!caCerts.isEmpty()); -- cgit v1.2.3 From cb3152086c61e7c51ed1c5f8c5946364e19abc4d Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Tue, 21 Jan 2020 15:33:11 +0100 Subject: Introduce Q_PROPERTY attribute REQUIRED This is meant to correspond to required properties in QML. Change-Id: I2645981e13f7423bc86b48370c165b3cfe2aaa62 Task-number: QTBUG-81561 Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../doc/snippets/code/doc_src_properties.cpp | 1 + src/corelib/doc/src/objectmodel/properties.qdoc | 6 ++++++ src/corelib/kernel/qmetaobject.cpp | 15 ++++++++++++++ src/corelib/kernel/qmetaobject.h | 1 + src/corelib/kernel/qmetaobject_p.h | 3 ++- src/tools/moc/generator.cpp | 2 ++ src/tools/moc/moc.cpp | 4 ++++ src/tools/moc/moc.h | 1 + tests/auto/tools/moc/allmocs_baseline_in.json | 13 ++++++++++++ tests/auto/tools/moc/tst_moc.cpp | 24 ++++++++++++++++++++++ 10 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/corelib/doc/snippets/code/doc_src_properties.cpp b/src/corelib/doc/snippets/code/doc_src_properties.cpp index b72c9d13e1..a67945bbcf 100644 --- a/src/corelib/doc/snippets/code/doc_src_properties.cpp +++ b/src/corelib/doc/snippets/code/doc_src_properties.cpp @@ -61,6 +61,7 @@ Q_PROPERTY(type name [USER bool] [CONSTANT] [FINAL]) + [REQUIRED] //! [0] diff --git a/src/corelib/doc/src/objectmodel/properties.qdoc b/src/corelib/doc/src/objectmodel/properties.qdoc index 9ef08cce07..680e5598f0 100644 --- a/src/corelib/doc/src/objectmodel/properties.qdoc +++ b/src/corelib/doc/src/objectmodel/properties.qdoc @@ -144,6 +144,12 @@ optimizations in some cases, but is not enforced by moc. Care must be taken never to override a \c FINAL property. + \li The presence of the \c REQUIRED attribute indicates that the property + should be set by a user of the class. This is not enforced by moc, and is + mostly useful for classes exposed to QML. In QML, classes with REQUIRED + properties cannot be instantiated unless all REQUIRED properties have + been set. + \endlist The \c READ, \c WRITE, and \c RESET functions can be inherited. diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 347fb1eb87..37f5acc5c5 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -3572,6 +3572,21 @@ bool QMetaProperty::isFinal() const return flags & Final; } +/*! + \since 5.15 + Returns \c true if the property is required; otherwise returns \c false. + + A property is final if the \c{Q_PROPERTY()}'s \c REQUIRED attribute + is set. +*/ +bool QMetaProperty::isRequired() const +{ + if (!mobj) + return false; + int flags = mobj->d.data[handle + 2]; + return flags & Required; +} + /*! \obsolete diff --git a/src/corelib/kernel/qmetaobject.h b/src/corelib/kernel/qmetaobject.h index fcd92afd89..beb85becae 100644 --- a/src/corelib/kernel/qmetaobject.h +++ b/src/corelib/kernel/qmetaobject.h @@ -266,6 +266,7 @@ public: bool isUser(const QObject *obj = nullptr) const; bool isConstant() const; bool isFinal() const; + bool isRequired() const; bool isFlagType() const; bool isEnumType() const; diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h index 56e3d6cb44..277109dac4 100644 --- a/src/corelib/kernel/qmetaobject_p.h +++ b/src/corelib/kernel/qmetaobject_p.h @@ -85,7 +85,8 @@ enum PropertyFlags { User = 0x00100000, ResolveUser = 0x00200000, Notify = 0x00400000, - Revisioned = 0x00800000 + Revisioned = 0x00800000, + Required = 0x01000000, }; enum MethodFlags { diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index 034e846918..8d4fb2efc6 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -864,6 +864,8 @@ void Generator::generateProperties() flags |= Constant; if (p.final) flags |= Final; + if (p.required) + flags |= Required; fprintf(out, " %4d, ", stridx(p.name)); generateTypeInfo(p.type); diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index d7a1af0a18..b562416c31 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -1238,6 +1238,9 @@ void Moc::createPropertyDef(PropertyDef &propDef) } else if(l[0] == 'F' && l == "FINAL") { propDef.final = true; continue; + } else if (l[0] == 'R' && l == "REQUIRED") { + propDef.required = true; + continue; } QByteArray v, v2; @@ -1960,6 +1963,7 @@ QJsonObject PropertyDef::toJson() const prop[QLatin1String("constant")] = constant; prop[QLatin1String("final")] = final; + prop[QLatin1String("required")] = required; if (revision > 0) prop[QLatin1String("revision")] = revision; diff --git a/src/tools/moc/moc.h b/src/tools/moc/moc.h index 5d1ae0ad6d..04814b85a1 100644 --- a/src/tools/moc/moc.h +++ b/src/tools/moc/moc.h @@ -137,6 +137,7 @@ struct PropertyDef int revision = 0; bool constant = false; bool final = false; + bool required = false; QJsonObject toJson() const; }; diff --git a/tests/auto/tools/moc/allmocs_baseline_in.json b/tests/auto/tools/moc/allmocs_baseline_in.json index 8cb397190c..48cac07012 100644 --- a/tests/auto/tools/moc/allmocs_baseline_in.json +++ b/tests/auto/tools/moc/allmocs_baseline_in.json @@ -275,6 +275,7 @@ "final": false, "name": "flags", "read": "flags", + "required": false, "scriptable": true, "stored": true, "type": "Flags", @@ -299,6 +300,7 @@ "final": false, "name": "flags", "read": "flags", + "required": false, "scriptable": true, "stored": true, "type": "Foo::Bar::Flags", @@ -311,6 +313,7 @@ "final": false, "name": "flagsList", "read": "flagsList", + "required": false, "scriptable": true, "stored": true, "type": "QList", @@ -1988,6 +1991,7 @@ "final": false, "name": "blah", "read": "blah", + "required": false, "scriptable": true, "stored": true, "type": "A::SomeEnum", @@ -2088,6 +2092,7 @@ "final": false, "name": "blah", "read": "blah", + "required": false, "scriptable": true, "stored": true, "type": "A::SomeEnum", @@ -2257,6 +2262,7 @@ "final": false, "name": "gadgetPoperty", "read": "gadgetPoperty", + "required": false, "scriptable": true, "stored": true, "type": "Gadget::SomeEnum", @@ -2268,6 +2274,7 @@ "final": false, "name": "objectPoperty", "read": "objectPoperty", + "required": false, "scriptable": true, "stored": true, "type": "Object::SomeEnum", @@ -2291,6 +2298,7 @@ "final": false, "name": "nestedGadgetPoperty", "read": "nestedGadgetPoperty", + "required": false, "scriptable": true, "stored": true, "type": "Nested::Gadget::SomeEnum", @@ -2314,6 +2322,7 @@ "final": false, "name": "nestedObjectPoperty", "read": "nestedObjectPoperty", + "required": false, "scriptable": true, "stored": true, "type": "Nested::Object::SomeEnum", @@ -2442,6 +2451,7 @@ "final": false, "name": "gadgetPoperty", "read": "gadgetPoperty", + "required": false, "scriptable": true, "stored": true, "type": "Gadget::SomeEnum", @@ -2453,6 +2463,7 @@ "final": false, "name": "objectPoperty", "read": "objectPoperty", + "required": false, "scriptable": true, "stored": true, "type": "Object::SomeEnum", @@ -2476,6 +2487,7 @@ "final": false, "name": "nestedGadgetPoperty", "read": "nestedGadgetPoperty", + "required": false, "scriptable": true, "stored": true, "type": "Nested::Gadget::SomeEnum", @@ -2499,6 +2511,7 @@ "final": false, "name": "nestedObjectPoperty", "read": "nestedObjectPoperty", + "required": false, "scriptable": true, "stored": true, "type": "Nested::Object::SomeEnum", diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index 6b202f79a6..0f801fe902 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -719,6 +719,7 @@ private slots: void cxx17Namespaces(); void cxxAttributes(); void mocJsonOutput(); + void requiredProperties(); signals: void sigWithUnsignedArg(unsigned foo); @@ -4025,6 +4026,29 @@ void tst_Moc::mocJsonOutput() QVERIFY2(actualOutput == expectedOutput, showPotentialDiff(actualOutput, expectedOutput).constData()); } +class RequiredTest :public QObject +{ + Q_OBJECT + + Q_PROPERTY(int required MEMBER m_required REQUIRED) + Q_PROPERTY(int notRequired MEMBER m_notRequired) + +private: + int m_required; + int m_notRequired; +}; + +void tst_Moc::requiredProperties() +{ + QMetaObject mo = RequiredTest::staticMetaObject; + QMetaProperty required = mo.property(mo.indexOfProperty("required")); + QVERIFY(required.isValid()); + QVERIFY(required.isRequired()); + QMetaProperty notRequired = mo.property(mo.indexOfProperty("notRequired")); + QVERIFY(notRequired.isValid()); + QVERIFY(!notRequired.isRequired()); +} + QTEST_MAIN(tst_Moc) // the generated code must compile with QT_NO_KEYWORDS -- cgit v1.2.3 From 5b9f6862b1aa474a392203c69f6db678d633cecf Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 22 Jan 2020 17:35:06 +0100 Subject: Mac: disable application menu items during modal session MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The default menu items in the application menu are not part of a traversable menu object hierarchy, so we never find a menubar. Since that is only the case for those items, we can disable them during any modal session. Change-Id: Ie8d8db274176237de664c6e5ebfe5015e13800e4 Fixes: QTBUG-80273 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qnsview_menus.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/cocoa/qnsview_menus.mm b/src/plugins/platforms/cocoa/qnsview_menus.mm index a55fd97eb7..b6cd832282 100644 --- a/src/plugins/platforms/cocoa/qnsview_menus.mm +++ b/src/plugins/platforms/cocoa/qnsview_menus.mm @@ -84,7 +84,8 @@ static bool selectorIsCutCopyPaste(SEL selector) menuParent = menuObject->menuParent(); } - if (menubar && menubar->cocoaWindow() != self.platformWindow) + // we have no menubar parent for the application menu items, e.g About and Preferences + if (!menubar || menubar->cocoaWindow() != self.platformWindow) return NO; } -- cgit v1.2.3 From d31910709c568d4f4e01a341196c3bffbeb7aae0 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 22 Jan 2020 16:43:47 +0100 Subject: macOS: Decide enabled state of menu items correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We use automatic menu enabling, so the only property that should define whether the item in the menu is enabled or not is QCocoaMenuItem::enabled, which will then get read from validateMenuItem:, and synced to the native menu item by AppKit. Change-Id: I860d05bf4675c9bc2058d2ede44b5ac3551453b6 Fixes: QTBUG-81375 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoamenu.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/platforms/cocoa/qcocoamenu.mm b/src/plugins/platforms/cocoa/qcocoamenu.mm index 8c4fca0d29..90d5180fed 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.mm +++ b/src/plugins/platforms/cocoa/qcocoamenu.mm @@ -334,7 +334,7 @@ void QCocoaMenu::setEnabled(bool enabled) bool QCocoaMenu::isEnabled() const { - return m_attachedItem ? m_attachedItem.enabled : m_enabled && m_parentEnabled; + return m_enabled && m_parentEnabled; } void QCocoaMenu::setVisible(bool visible) -- cgit v1.2.3 From 39396409656b12940ffe9b715f13e23ac4290eca Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 23 Jan 2020 15:48:15 +0100 Subject: Fix some qdoc-warnings src/corelib/tools/qmap.cpp:1199: (qdoc) warning: Can't link to 'QMultiMap::unite()' src/gui/kernel/qevent.cpp:949: (qdoc) warning: Unknown command '\see' src/gui/painting/qpaintengine_raster.cpp:344: (qdoc) warning: clang found diagnostics parsing \fn Type QRasterPaintEngine::type() const error: unknown type name 'Type' src/gui/doc/src/qtgui.qdoc:45: (qdoc) warning: Can't link to 'Build with CMake' examples/widgets/doc/src/gallery.qdoc:28: (qdoc) warning: Cannot find file 'widgets/gallery/gallery.pro' or 'widgets/gallery/gallery.pyproject' src/widgets/kernel/qwidget.cpp:5950: (qdoc) warning: Can't link to 'setFilePath' src/widgets/kernel/qshortcut.cpp:542: (qdoc) warning: No such parameter 'context' in QShortcut::QShortcut() Change-Id: I2395af854efebef719d4762da466f69f7c5aab9e Reviewed-by: Paul Wicking --- examples/widgets/doc/src/gallery.qdoc | 2 +- src/corelib/tools/qmap.cpp | 2 +- src/gui/doc/src/qtgui.qdoc | 2 +- src/gui/kernel/qevent.cpp | 2 +- src/gui/painting/qpaintengine_raster.cpp | 2 +- src/widgets/kernel/qshortcut.cpp | 2 +- src/widgets/kernel/qwidget.cpp | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/widgets/doc/src/gallery.qdoc b/examples/widgets/doc/src/gallery.qdoc index a262374ce6..455099ddce 100644 --- a/examples/widgets/doc/src/gallery.qdoc +++ b/examples/widgets/doc/src/gallery.qdoc @@ -26,7 +26,7 @@ ****************************************************************************/ /*! - \example widgets/gallery + \example gallery \title Widgets Gallery Example \ingroup examples-widgets \brief The Widgets Gallery example shows widgets relevant for designing UIs. diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index d747a8cda4..a51e59b2b8 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -1203,7 +1203,7 @@ void QMapDataBase::freeData(QMapDataBase *d) key is common to both maps, the resulting map will contain the key multiple times. - \sa QMultiMap::unite() + \sa QMap::unite() */ /*! \typedef QMap::Iterator diff --git a/src/gui/doc/src/qtgui.qdoc b/src/gui/doc/src/qtgui.qdoc index 392b6040cb..f8a3ce84aa 100644 --- a/src/gui/doc/src/qtgui.qdoc +++ b/src/gui/doc/src/qtgui.qdoc @@ -62,7 +62,7 @@ \include module-use.qdocinc using qt module \quotefile overview/using-qt-gui.cmake - See also the \l[QtDoc]{Build with CMake} overview. + See also the \l{Build with CMake} overview. \section2 Building with qmake diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 3362294435..da77290c30 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -946,7 +946,7 @@ QWheelEvent::~QWheelEvent() \li or scrolling has ended and the distance did not change anymore (Qt::ScrollEnd). \endlist - \see pixelDelta() + \sa pixelDelta() */ /*! diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index bc65ed56e3..10920c38fe 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -342,7 +342,7 @@ QRasterPaintEnginePrivate::QRasterPaintEnginePrivate() : */ /*! - \fn Type QRasterPaintEngine::type() const + \fn QPaintEngine::Type QRasterPaintEngine::type() const \reimp */ diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp index d469279ea5..039699a004 100644 --- a/src/widgets/kernel/qshortcut.cpp +++ b/src/widgets/kernel/qshortcut.cpp @@ -545,7 +545,7 @@ QShortcut::QShortcut(QWidget *parent) match the \a key sequence. Depending on the ambiguity of the event, the shortcut will call the \a member function, or the \a ambiguousMember function, if the key press was in the shortcut's - \a context. + \a shortcutContext. */ QShortcut::QShortcut(const QKeySequence &key, QWidget *parent, const char *member, const char *ambiguousMember, diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 954b00eb35..b85bb62917 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -5957,9 +5957,9 @@ void QWidget::setWindowTitle(const QString &title) \note On \macos, window icons represent the active document, and will not be displayed unless a file path has also been - set using setFilePath. + set using setWindowFilePath. - \sa windowTitle, setFilePath + \sa windowTitle, setWindowFilePath */ QIcon QWidget::windowIcon() const { -- cgit v1.2.3 From 16885a6033405e1ed28ac42f9dfec7339975e85e Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 2 Jan 2020 14:16:21 +0100 Subject: De-duplicate the last occurrence of calling a depend_command Use the central callExtraCompilerDependCommand in the last place where the code to call an extra compiler's depend_command was duplicated. Note that this is in the "Bad hack" section. We're making this hack less bad, but the comment still applies. Change-Id: Iaa857af20ca46b2d73053d3e264c63124c87a41b Reviewed-by: Oliver Wolff --- qmake/generators/win32/msvc_vcproj.cpp | 44 +++++++++++++--------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/qmake/generators/win32/msvc_vcproj.cpp b/qmake/generators/win32/msvc_vcproj.cpp index 867b14faea..80f444820a 100644 --- a/qmake/generators/win32/msvc_vcproj.cpp +++ b/qmake/generators/win32/msvc_vcproj.cpp @@ -1481,36 +1481,24 @@ void VcprojGenerator::initResourceFiles() // Bad hack, please look away ------------------------------------- QString rcc_dep_cmd = project->values("rcc.depend_command").join(' '); if(!rcc_dep_cmd.isEmpty()) { - ProStringList qrc_files = project->values("RESOURCES"); + const QStringList qrc_files = project->values("RESOURCES").toQStringList(); QStringList deps; - if(!qrc_files.isEmpty()) { - for (int i = 0; i < qrc_files.count(); ++i) { - char buff[256]; - QString dep_cmd = replaceExtraCompilerVariables( - rcc_dep_cmd, qrc_files.at(i).toQString(), QString(), LocalShell); - - dep_cmd = Option::fixPathToLocalOS(dep_cmd, true, false); - if(canExecute(dep_cmd)) { - dep_cmd.prepend(QLatin1String("cd ") - + IoUtils::shellQuote(Option::fixPathToLocalOS(Option::output_dir, false)) - + QLatin1String(" && ")); - if (FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), QT_POPEN_READ)) { - QString indeps; - while(!feof(proc)) { - int read_in = (int)fread(buff, 1, 255, proc); - if(!read_in) - break; - indeps += QByteArray(buff, read_in); - } - QT_PCLOSE(proc); - if(!indeps.isEmpty()) - deps += fileFixify(indeps.replace('\n', ' ').simplified().split(' '), - FileFixifyFromOutdir); - } - } - } - vcProject.ResourceFiles.addFiles(deps); + const QString rcc_dep_cd_cmd = QLatin1String("cd ") + + IoUtils::shellQuote(Option::fixPathToLocalOS(Option::output_dir, false)) + + QLatin1String(" && "); + for (const QString &qrc_file : qrc_files) { + callExtraCompilerDependCommand("rcc", + rcc_dep_cd_cmd, + rcc_dep_cmd, + qrc_file, + QString(), + true, // dep_lines + &deps, + false, // existingDepsOnly + true // checkCommandavailability + ); } + vcProject.ResourceFiles.addFiles(deps); } // You may look again -------------------------------------------- -- cgit v1.2.3 From 41b919919eb05299cc382de0da7d25892a120dd5 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 2 Jan 2020 14:28:39 +0100 Subject: Purge the dep_cd_cmd parameter from callExtraCompilerDependCommand We always pass the same value. The builtins are also using exactly this "cd command" unconditionally. This deduplicates the code at the call sites of callExtraCompilerDependCommand a bit. Change-Id: I5c412c815d50afdac55e1b45021f37f2545ce8f0 Reviewed-by: Oliver Wolff --- qmake/generators/makefile.cpp | 16 ++++++---------- qmake/generators/makefile.h | 2 +- qmake/generators/win32/msvc_objectmodel.cpp | 5 +---- qmake/generators/win32/msvc_vcproj.cpp | 4 ---- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/qmake/generators/makefile.cpp b/qmake/generators/makefile.cpp index 7e471f126c..8e46da521f 100644 --- a/qmake/generators/makefile.cpp +++ b/qmake/generators/makefile.cpp @@ -1851,7 +1851,6 @@ QString MakefileGenerator::resolveDependency(const QDir &outDir, const QString & } void MakefileGenerator::callExtraCompilerDependCommand(const ProString &extraCompiler, - const QString &dep_cd_cmd, const QString &tmp_dep_cmd, const QString &inpf, const QString &tmp_out, @@ -1864,7 +1863,10 @@ void MakefileGenerator::callExtraCompilerDependCommand(const ProString &extraCom QString dep_cmd = replaceExtraCompilerVariables(tmp_dep_cmd, inpf, tmp_out, LocalShell); if (checkCommandAvailability && !canExecute(dep_cmd)) return; - dep_cmd = dep_cd_cmd + fixEnvVariables(dep_cmd); + dep_cmd = QLatin1String("cd ") + + IoUtils::shellQuote(Option::fixPathToLocalOS(Option::output_dir, false)) + + QLatin1String(" && ") + + fixEnvVariables(dep_cmd); if (FILE *proc = QT_POPEN(dep_cmd.toLatin1().constData(), QT_POPEN_READ)) { QByteArray depData; while (int read_in = feof(proc) ? 0 : (int)fread(buff, 1, 255, proc)) @@ -1916,12 +1918,6 @@ MakefileGenerator::writeExtraCompilerTargets(QTextStream &t) FileFixifyFromOutdir); const QString tmp_cmd = project->values(ProKey(*it + ".commands")).join(' '); const QString tmp_dep_cmd = project->values(ProKey(*it + ".depend_command")).join(' '); - QString dep_cd_cmd; - if (!tmp_dep_cmd.isEmpty()) { - dep_cd_cmd = QLatin1String("cd ") - + IoUtils::shellQuote(Option::fixPathToLocalOS(Option::output_dir, false)) - + QLatin1String(" && "); - } const bool dep_lines = (config.indexOf("dep_lines") != -1); const ProStringList &vars = project->values(ProKey(*it + ".variables")); if(tmp_out.isEmpty() || tmp_cmd.isEmpty()) @@ -2035,7 +2031,7 @@ MakefileGenerator::writeExtraCompilerTargets(QTextStream &t) deps += findDependencies(inpf); inputs += Option::fixPathToTargetOS(inpf, false); if(!tmp_dep_cmd.isEmpty() && doDepends()) { - callExtraCompilerDependCommand(*it, dep_cd_cmd, tmp_dep_cmd, inpf, + callExtraCompilerDependCommand(*it, tmp_dep_cmd, inpf, tmp_out, dep_lines, &deps, existingDepsOnly); } } @@ -2084,7 +2080,7 @@ MakefileGenerator::writeExtraCompilerTargets(QTextStream &t) for (ProStringList::ConstIterator it3 = vars.constBegin(); it3 != vars.constEnd(); ++it3) cmd.replace("$(" + (*it3) + ")", "$(QMAKE_COMP_" + (*it3)+")"); if(!tmp_dep_cmd.isEmpty() && doDepends()) { - callExtraCompilerDependCommand(*it, dep_cd_cmd, tmp_dep_cmd, inpf, + callExtraCompilerDependCommand(*it, tmp_dep_cmd, inpf, tmp_out, dep_lines, &deps, existingDepsOnly); //use the depend system to find includes of these included files QStringList inc_deps; diff --git a/qmake/generators/makefile.h b/qmake/generators/makefile.h index ab970c966f..a96b9c54da 100644 --- a/qmake/generators/makefile.h +++ b/qmake/generators/makefile.h @@ -84,7 +84,7 @@ protected: void writeExtraVariables(QTextStream &t); void writeExtraTargets(QTextStream &t); QString resolveDependency(const QDir &outDir, const QString &file); - void callExtraCompilerDependCommand(const ProString &extraCompiler, const QString &dep_cd_cmd, + void callExtraCompilerDependCommand(const ProString &extraCompiler, const QString &tmp_dep_cmd, const QString &inpf, const QString &tmp_out, bool dep_lines, QStringList *deps, bool existingDepsOnly, diff --git a/qmake/generators/win32/msvc_objectmodel.cpp b/qmake/generators/win32/msvc_objectmodel.cpp index 2b39a4baaa..3002ce889c 100644 --- a/qmake/generators/win32/msvc_objectmodel.cpp +++ b/qmake/generators/win32/msvc_objectmodel.cpp @@ -2351,10 +2351,7 @@ bool VCFilter::addExtraCompiler(const VCFilterFile &info) if (!tmp_dep.isEmpty()) deps = tmp_dep; if (!tmp_dep_cmd.isEmpty()) { - const QString dep_cd_cmd = QLatin1String("cd ") - + IoUtils::shellQuote(Option::fixPathToLocalOS(Option::output_dir, false)) - + QLatin1String(" && "); - Project->callExtraCompilerDependCommand(extraCompilerName, dep_cd_cmd, tmp_dep_cmd, + Project->callExtraCompilerDependCommand(extraCompilerName, tmp_dep_cmd, inFile, out, true, // dep_lines &deps, diff --git a/qmake/generators/win32/msvc_vcproj.cpp b/qmake/generators/win32/msvc_vcproj.cpp index 80f444820a..e117f472e0 100644 --- a/qmake/generators/win32/msvc_vcproj.cpp +++ b/qmake/generators/win32/msvc_vcproj.cpp @@ -1483,12 +1483,8 @@ void VcprojGenerator::initResourceFiles() if(!rcc_dep_cmd.isEmpty()) { const QStringList qrc_files = project->values("RESOURCES").toQStringList(); QStringList deps; - const QString rcc_dep_cd_cmd = QLatin1String("cd ") - + IoUtils::shellQuote(Option::fixPathToLocalOS(Option::output_dir, false)) - + QLatin1String(" && "); for (const QString &qrc_file : qrc_files) { callExtraCompilerDependCommand("rcc", - rcc_dep_cd_cmd, rcc_dep_cmd, qrc_file, QString(), -- cgit v1.2.3 From a11267c5320324cce19496313e2f7f8cdce9d8f7 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Wed, 8 Jan 2020 20:18:17 +0100 Subject: QTextBrowser: deprecate signal highlighted(QString) Deprecate QTextBrowser::highlighted(QString) to avoid the use of qOverloadOf<>. Task-number: QTBUG-80906 Change-Id: I757622c976f7540ecef9225026299ebb0b90d007 Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qtextbrowser.cpp | 37 ++++++++++++++++++------------------ src/widgets/widgets/qtextbrowser.h | 3 +++ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp index 0ba74a20e0..78fde94fad 100644 --- a/src/widgets/widgets/qtextbrowser.cpp +++ b/src/widgets/widgets/qtextbrowser.cpp @@ -152,6 +152,16 @@ public: QTextCursor prevFocus; int lastKeypadScrollValue; #endif + void emitHighlighted(const QUrl &url) + { + Q_Q(QTextBrowser); + emit q->highlighted(url); +#if QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + emit q->highlighted(url.toString()); +#endif + } }; Q_DECLARE_TYPEINFO(QTextBrowserPrivate::HistoryEntry, Q_MOVABLE_TYPE); @@ -256,24 +266,20 @@ void QTextBrowserPrivate::_q_activateAnchor(const QString &href) void QTextBrowserPrivate::_q_highlightLink(const QString &anchor) { - Q_Q(QTextBrowser); if (anchor.isEmpty()) { #ifndef QT_NO_CURSOR if (viewport->cursor().shape() != Qt::PointingHandCursor) oldCursor = viewport->cursor(); viewport->setCursor(oldCursor); #endif - emit q->highlighted(QUrl()); - emit q->highlighted(QString()); + emitHighlighted(QUrl()); } else { #ifndef QT_NO_CURSOR viewport->setCursor(Qt::PointingHandCursor); #endif const QUrl url = resolveUrl(anchor); - emit q->highlighted(url); - // convenience to ease connecting to QStatusBar::showMessage(const QString &) - emit q->highlighted(url.toString()); + emitHighlighted(url); } } @@ -383,8 +389,7 @@ void QTextBrowserPrivate::setSource(const QUrl &url, QTextDocument::ResourceType } #ifdef QT_KEYPAD_NAVIGATION lastKeypadScrollValue = vbar->value(); - emit q->highlighted(QUrl()); - emit q->highlighted(QString()); + emitHighlighted(QUrl()); #endif #ifndef QT_NO_CURSOR @@ -559,8 +564,7 @@ void QTextBrowserPrivate::keypadMove(bool next) // Ensure that the new selection is highlighted. const QString href = control->anchorAtCursor(); QUrl url = resolveUrl(href); - emit q->highlighted(url); - emit q->highlighted(url.toString()); + emitHighlighted(url); } else { // Scroll vbar->setValue(scrollYOffset); @@ -575,8 +579,7 @@ void QTextBrowserPrivate::keypadMove(bool next) hbar->setValue(savedXOffset); vbar->setValue(scrollYOffset); - emit q->highlighted(QUrl()); - emit q->highlighted(QString()); + emitHighlighted(QUrl()); } } #endif @@ -619,8 +622,7 @@ void QTextBrowserPrivate::restoreHistoryEntry(const HistoryEntry &entry) Q_Q(QTextBrowser); const QString href = prevFocus.charFormat().anchorHref(); QUrl url = resolveUrl(href); - emit q->highlighted(url); - emit q->highlighted(url.toString()); + emitHighlighted(url); #endif } @@ -927,6 +929,7 @@ void QTextBrowser::doSetSource(const QUrl &url, QTextDocument::ResourceType type /*! \fn void QTextBrowser::highlighted(const QString &link) \overload + \obsolete Convenience signal that allows connecting to a slot that takes just a QString, like for example QStatusBar's @@ -1127,8 +1130,7 @@ bool QTextBrowser::focusNextPrevChild(bool next) if (d->prevFocus != d->control->textCursor() && d->control->textCursor().hasSelection()) { const QString href = d->control->anchorAtCursor(); QUrl url = d->resolveUrl(href); - emit highlighted(url); - emit highlighted(url.toString()); + emitHighlighted(url); } d->prevFocus = d->control->textCursor(); #endif @@ -1136,8 +1138,7 @@ bool QTextBrowser::focusNextPrevChild(bool next) } else { #ifdef QT_KEYPAD_NAVIGATION // We assume we have no highlight now. - emit highlighted(QUrl()); - emit highlighted(QString()); + emitHighlighted(QUrl()); #endif } return QTextEdit::focusNextPrevChild(next); diff --git a/src/widgets/widgets/qtextbrowser.h b/src/widgets/widgets/qtextbrowser.h index 33e5b3980c..4b3ec491ee 100644 --- a/src/widgets/widgets/qtextbrowser.h +++ b/src/widgets/widgets/qtextbrowser.h @@ -107,7 +107,10 @@ Q_SIGNALS: void historyChanged(); void sourceChanged(const QUrl &); void highlighted(const QUrl &); +#if QT_DEPRECATED_SINCE(5, 15) + QT_DEPRECATED_VERSION_X_5_15("Use QTextBrowser::highlighted(QUrl) instead") void highlighted(const QString &); +#endif void anchorClicked(const QUrl &); protected: -- cgit v1.2.3 From 5c3b5efd40b3ab14cc6406a0dca62dfb14b03d46 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 10 Jan 2020 22:11:12 +0100 Subject: QMenu: don't crash when another popup is closed when a popup is closed When closing a popup (submenu) triggers closing another popup (the menu) programatically it can happen that QApplicationPrivate::popupWidgets is destroyed. Therefore we have to check if popupWidgets is still valid after the focus change event was delivered. Fixes: QTBUG-81222 Change-Id: Ide3a6897e43f389d396a80d8b158f7c8eb04e3aa Reviewed-by: Friedemann Kleint Reviewed-by: Richard Moe Gustavsen --- src/widgets/kernel/qapplication.cpp | 4 +- tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp | 56 ++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 842c0ea9e6..68f6b72d20 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3762,7 +3762,9 @@ void QApplicationPrivate::closePopup(QWidget *popup) if (QWidget *fw = aw->focusWidget()) fw->setFocus(Qt::PopupFocusReason); - if (QApplicationPrivate::popupWidgets->count() == 1) // grab mouse/keyboard + // can become nullptr due to setFocus() above + if (QApplicationPrivate::popupWidgets && + QApplicationPrivate::popupWidgets->count() == 1) // grab mouse/keyboard grabForPopup(aw); } diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp index 3dc7b05af9..d7d3a934f8 100644 --- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp +++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -114,6 +115,7 @@ private slots: void QTBUG30595_rtl_submenu(); void QTBUG20403_nested_popup_on_shortcut_trigger(); void QTBUG47515_widgetActionEnterLeave(); + void QTBUG8122_widgetActionCrashOnClose(); void QTBUG_10735_crashWithDialog(); #ifdef Q_OS_MAC @@ -1352,6 +1354,60 @@ void tst_QMenu::QTBUG47515_widgetActionEnterLeave() } } +void tst_QMenu::QTBUG8122_widgetActionCrashOnClose() +{ + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + if (QGuiApplication::platformName() == QLatin1String("cocoa")) + QSKIP("See QTBUG-63031"); +#ifdef Q_OS_WINRT + QSKIP("WinRT does not support QTest::mouseMove"); +#endif + + const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry(); + QRect geometry(QPoint(), availableGeometry.size() / 3); + geometry.moveCenter(availableGeometry.center()); + QPoint pointOutsideMenu = geometry.bottomRight() - QPoint(5, 5); + + QMainWindow topLevel; + topLevel.setGeometry(geometry); + + auto menuBar = topLevel.menuBar(); + auto menu = menuBar->addMenu("Menu"); + auto wAct = new QWidgetAction(menu); + auto spinBox1 = new QSpinBox(menu); + wAct->setDefaultWidget(spinBox1); + menu->addAction(wAct); + auto subMenu = menu->addMenu("Submenu"); + auto nextMenuAct = menu->addMenu(subMenu); + auto wAct2 = new QWidgetAction(menu); + auto spinBox2 = new QSpinBox(menu); + wAct2->setDefaultWidget(spinBox2); + subMenu->addAction(wAct2); + QObject::connect(spinBox2, &QSpinBox::editingFinished, menu, &QMenu::hide); + + topLevel.show(); + topLevel.setWindowTitle(QTest::currentTestFunction()); + QVERIFY(QTest::qWaitForWindowActive(&topLevel)); + QWindow *topLevelWindow = topLevel.windowHandle(); + QVERIFY(topLevelWindow); + + const QPoint menuActionPos = menuBar->mapTo(&topLevel, menuBar->actionGeometry(menu->menuAction()).center()); + QTest::mouseClick(topLevelWindow, Qt::LeftButton, Qt::KeyboardModifiers(), menuActionPos); + QVERIFY(QTest::qWaitForWindowExposed(menu)); + + QPoint w1Center = topLevel.mapFromGlobal(spinBox1->mapToGlobal(spinBox1->rect().center())); + QTest::mouseClick(topLevelWindow, Qt::LeftButton, Qt::KeyboardModifiers(), w1Center); + menu->setActiveAction(nextMenuAct); + QVERIFY(QTest::qWaitForWindowExposed(subMenu)); + + QPoint w2Center = topLevel.mapFromGlobal(spinBox2->mapToGlobal(spinBox2->rect().center())); + QTest::mouseClick(topLevelWindow, Qt::LeftButton, Qt::KeyboardModifiers(), w2Center); + QTest::mouseMove(topLevelWindow, topLevel.mapFromGlobal(pointOutsideMenu)); + QTRY_VERIFY(menu->isHidden()); +} + + class MyMenu : public QMenu { Q_OBJECT -- cgit v1.2.3 From f3d3c095a6bda505384ef56acab57b985d94fac5 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 6 Dec 2019 16:51:41 +0100 Subject: Register QColorSpace as a QtGui metatype Helps pass it through QVariant, and needed for QML support. Change-Id: Id161ff9b8f81ad55a7ee7a7c4c614bdf74bca4a1 Reviewed-by: Andy Nichols --- src/corelib/kernel/qmetatype.cpp | 1 + src/corelib/kernel/qmetatype.h | 7 ++++--- src/gui/kernel/qguivariant.cpp | 1 + src/gui/painting/qcolorspace.cpp | 9 +++++++++ src/gui/painting/qcolorspace.h | 2 ++ 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index af9a2e0dd2..46900be1a4 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -252,6 +252,7 @@ struct DefinedTypesFilter { \value QPolygon QPolygon \value QPolygonF QPolygonF \value QColor QColor + \value QColorSpace QColorSpace \value QSizeF QSizeF \value QRectF QRectF \value QLine QLine diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 825f767425..4f70eb4c6d 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -175,6 +175,7 @@ inline Q_DECL_CONSTEXPR int qMetaTypeId(); F(QVector4D, 84, QVector4D) \ F(QQuaternion, 85, QQuaternion) \ F(QPolygonF, 86, QPolygonF) \ + F(QColorSpace, 87, QColorSpace) \ #define QT_FOR_EACH_STATIC_WIDGETS_CLASS(F)\ @@ -437,7 +438,7 @@ public: FirstCoreType = Bool, LastCoreType = QCborMap, FirstGuiType = QFont, - LastGuiType = QPolygonF, + LastGuiType = QColorSpace, FirstWidgetsType = QSizePolicy, LastWidgetsType = QSizePolicy, HighestInternalId = LastWidgetsType, @@ -472,12 +473,12 @@ public: QIcon = 69, QImage = 70, QPolygon = 71, QRegion = 72, QBitmap = 73, QCursor = 74, QKeySequence = 75, QPen = 76, QTextLength = 77, QTextFormat = 78, QMatrix = 79, QTransform = 80, QMatrix4x4 = 81, QVector2D = 82, - QVector3D = 83, QVector4D = 84, QQuaternion = 85, QPolygonF = 86, + QVector3D = 83, QVector4D = 84, QQuaternion = 85, QPolygonF = 86, QColorSpace = 87, // Widget types QSizePolicy = 121, LastCoreType = QCborMap, - LastGuiType = QPolygonF, + LastGuiType = QColorSpace, User = 1024 }; #endif diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index 596b7e44fd..215b2b1d74 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -41,6 +41,7 @@ #include "qbitmap.h" #include "qbrush.h" #include "qcolor.h" +#include "qcolorspace.h" #include "qcursor.h" #include "qfont.h" #include "qimage.h" diff --git a/src/gui/painting/qcolorspace.cpp b/src/gui/painting/qcolorspace.cpp index 0fb0e9ee33..7ebd5f1bf4 100644 --- a/src/gui/painting/qcolorspace.cpp +++ b/src/gui/painting/qcolorspace.cpp @@ -744,6 +744,15 @@ QColorTransform QColorSpace::transformationToColorSpace(const QColorSpace &color return d_ptr->transformationToColorSpace(colorspace.d_ptr); } +/*! + Returns the color space as a QVariant. + \since 5.15 +*/ +QColorSpace::operator QVariant() const +{ + return QVariant(QMetaType::QColorSpace, this); +} + /***************************************************************************** QColorSpace stream functions *****************************************************************************/ diff --git a/src/gui/painting/qcolorspace.h b/src/gui/painting/qcolorspace.h index e6bc62d58a..08c9944301 100644 --- a/src/gui/painting/qcolorspace.h +++ b/src/gui/painting/qcolorspace.h @@ -44,6 +44,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -125,6 +126,7 @@ public: QColorTransform transformationToColorSpace(const QColorSpace &colorspace) const; + operator QVariant() const; private: Q_DECLARE_PRIVATE(QColorSpace) -- cgit v1.2.3 From e9a797799ee7e81d1cd113ba56f62705ae150e5c Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 2 Dec 2019 18:03:47 +0100 Subject: CMake: Add Qt6 forward compatible CMake API and targets Create Qt:: versionless targets for libraries and tools. So Qt::Core will link to Qt5::Core. Add additional feature properties to targets, with the same name they have in Qt6: QT_ENABLED_PUBLIC_FEATURES, QT_DISABLED_PUBLIC_FEATURES, QT_ENABLED_PRIVATE_FEATURES, QT_DISABLED_PRIVATE_FEATURES, to be forward-compatible with Qt6. Prefix properties with INTERFACE_ for interface libraries. Create functions with no major version in their prefix, so qt_foo instead of qt5_foo. The non-versioned functions will call the versioned functions, depending on the value of QT_DEFAULT_MAJOR_VERSION, which can be set by an application developer before finding the Qt package. Set QT_DEFAULT_MAJOR_VERSION to 5 if the value has not been defined in the current scope. Application developers can set QT_NO_CREATE_VERSIONLESS_FUNCTIONS to TRUE before calling find_package(Qt5) to suppress creation of the non-versioned functions. Application developers can set QT_NO_CREATE_VERSIONLESS_TARGETS to TRUE before calling find_package(Qt5) to suppress creation of the non-versioned targets. Setting these can be useful when both find_package(Qt5) and find_package(Qt6) are in the same project. If none of these are set by the user, then the first find_package(Qt5) will create versionless targets with the major version being "5", which means the second find_package(Qt6) will not create versionless targets. Handle versionless plugin names in qt_import_plugins, so both Qt::QCocoaIntegrationPlugin and Qt5/6::QCocoaIntegrationPlugin are recognized by the function. Allow specifying multiple types in EXCLUDE_BY_TYPE in qt_import_plugins, to be consitent with the Qt 6 version. Make sure to set the QT_PLUGIN_CLASS_NAME property to compatible with Qt 6. Task-number: QTBUG-74137 Task-number: QTBUG-80477 Change-Id: Ib89d090ea6f7794d7debd64f03f29da963a17ca7 Reviewed-by: Joerg Bornemann --- mkspecs/features/create_cmake.prf | 6 +- .../features/data/cmake/Qt5BasicConfig.cmake.in | 31 ++++++++++ .../features/data/cmake/Qt5PluginTarget.cmake.in | 22 ++++++-- src/corelib/Qt5CoreConfigExtras.cmake.in | 24 ++++++++ src/corelib/Qt5CoreMacros.cmake | 66 +++++++++++++++++++++- src/dbus/Qt5DBusConfigExtras.cmake.in | 11 ++++ src/dbus/Qt5DBusMacros.cmake | 43 ++++++++++++++ src/widgets/Qt5WidgetsConfigExtras.cmake.in | 11 ++++ src/widgets/Qt5WidgetsMacros.cmake | 12 ++++ 9 files changed, 219 insertions(+), 7 deletions(-) diff --git a/mkspecs/features/create_cmake.prf b/mkspecs/features/create_cmake.prf index 346fbf2467..63b4a73660 100644 --- a/mkspecs/features/create_cmake.prf +++ b/mkspecs/features/create_cmake.prf @@ -176,7 +176,7 @@ contains(CONFIG, plugin) { list_plugin_extends = for (p, PLUGIN_EXTENDS) { m = $$cmakeModuleName($$p) - list_plugin_extends += Qt5::$$m + list_plugin_extends += Qt::$$m } CMAKE_PLUGIN_EXTENDS = $$join(list_plugin_extends, ";") } @@ -291,6 +291,10 @@ CMAKE_INTERFACE_MODULE_DEPS = $$join(aux_mod_deps, ";") CMAKE_INTERFACE_QT5_MODULE_DEPS = $$join(aux_lib_deps, ";") CMAKE_MODULE_PLUGIN_TYPES = $$join(QT.$${MODULE}.plugin_types, ";") +# Interface libraries have to have all properties starting with "INTERFACE_". +CMAKE_FEATURE_PROPERTY_PREFIX = "" +equals(TEMPLATE, aux): CMAKE_FEATURE_PROPERTY_PREFIX = "INTERFACE_" + mac { !isEmpty(CMAKE_STATIC_TYPE) { CMAKE_LIB_FILE_LOCATION_DEBUG = lib$${CMAKE_QT_STEM}_debug.a diff --git a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in index 26d4c17e6c..01dda9b0c3 100644 --- a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in +++ b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in @@ -406,6 +406,15 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME}) add_library(Qt5::$${CMAKE_MODULE_NAME} SHARED IMPORTED) !!ENDIF !!ENDIF + + # Add a versionless target, for compatibility with Qt6. + if(NOT \"${QT_NO_CREATE_VERSIONLESS_TARGETS}\" AND NOT TARGET Qt::$${CMAKE_MODULE_NAME}) + add_library(Qt::$${CMAKE_MODULE_NAME} INTERFACE IMPORTED) + set_target_properties(Qt::$${CMAKE_MODULE_NAME} PROPERTIES + INTERFACE_LINK_LIBRARIES \"Qt5::$${CMAKE_MODULE_NAME}\" + ) + endif() + !!IF !equals(TEMPLATE, aux) !!IF !isEmpty(CMAKE_BUILD_IS_FRAMEWORK) set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} PROPERTY FRAMEWORK 1) @@ -420,6 +429,20 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME}) set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} PROPERTY INTERFACE_QT_ENABLED_FEATURES $$join(QT.$${MODULE}.enabled_features, ";")) set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} PROPERTY INTERFACE_QT_DISABLED_FEATURES $$join(QT.$${MODULE}.disabled_features, ";")) + # Qt 6 forward compatible properties. + set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} + PROPERTY $${CMAKE_FEATURE_PROPERTY_PREFIX}QT_ENABLED_PUBLIC_FEATURES + $$join(QT.$${MODULE}.enabled_features, ";")) + set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} + PROPERTY $${CMAKE_FEATURE_PROPERTY_PREFIX}QT_DISABLED_PUBLIC_FEATURES + $$join(QT.$${MODULE}.disabled_features, ";")) + set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} + PROPERTY $${CMAKE_FEATURE_PROPERTY_PREFIX}QT_ENABLED_PRIVATE_FEATURES + $$join(QT.$${MODULE}_private.enabled_features, ";")) + set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} + PROPERTY $${CMAKE_FEATURE_PROPERTY_PREFIX}QT_DISABLED_PRIVATE_FEATURES + $$join(QT.$${MODULE}_private.disabled_features, ";")) + set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} PROPERTY INTERFACE_QT_PLUGIN_TYPES \"$${CMAKE_MODULE_PLUGIN_TYPES}\") set(_Qt5$${CMAKE_MODULE_NAME}_PRIVATE_DIRS_EXIST TRUE) @@ -443,6 +466,14 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME}) set_property(TARGET Qt5::$${CMAKE_MODULE_NAME}Private PROPERTY INTERFACE_LINK_LIBRARIES Qt5::$${CMAKE_MODULE_NAME} ${_Qt5$${CMAKE_MODULE_NAME}_PRIVATEDEPS} ) + + # Add a versionless target, for compatibility with Qt6. + if(NOT \"${QT_NO_CREATE_VERSIONLESS_TARGETS}\" AND NOT TARGET Qt::$${CMAKE_MODULE_NAME}Private) + add_library(Qt::$${CMAKE_MODULE_NAME}Private INTERFACE IMPORTED) + set_target_properties(Qt::$${CMAKE_MODULE_NAME}Private PROPERTIES + INTERFACE_LINK_LIBRARIES \"Qt5::$${CMAKE_MODULE_NAME}Private\" + ) + endif() endif() !!IF !equals(TEMPLATE, aux) diff --git a/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in b/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in index 7b70cfed09..b550a52c60 100644 --- a/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in +++ b/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in @@ -75,19 +75,30 @@ endif() set(_user_specified_genex \"$\" ) +set(_user_specified_genex_versionless + \"$\" +) string(CONCAT _plugin_genex \"$<$,\" \"$,Qt5::$${CMAKE_MODULE_NAME}>,\" + # FIXME: The value of CMAKE_MODULE_NAME seems to be wrong (e.g for Svg plugin + # it should be Qt::Svg instead of Qt::Gui). + \"$,Qt::$${CMAKE_MODULE_NAME}>,\" \"$,>\" \">,\" - \"$>\" + \"$>,\" + \"$>\" \">\" \">:Qt5::$$CMAKE_PLUGIN_NAME>\" ) @@ -100,3 +111,4 @@ set_property(TARGET Qt5::$${CMAKE_PLUGIN_NAME} APPEND PROPERTY INTERFACE_LINK_LI !!ENDIF set_property(TARGET Qt5::$${CMAKE_PLUGIN_NAME} PROPERTY QT_PLUGIN_TYPE \"$$CMAKE_PLUGIN_TYPE\") set_property(TARGET Qt5::$${CMAKE_PLUGIN_NAME} PROPERTY QT_PLUGIN_EXTENDS \"$$CMAKE_PLUGIN_EXTENDS\") +set_property(TARGET Qt5::$${CMAKE_PLUGIN_NAME} PROPERTY QT_PLUGIN_CLASS_NAME \"$$CMAKE_PLUGIN_NAME\") diff --git a/src/corelib/Qt5CoreConfigExtras.cmake.in b/src/corelib/Qt5CoreConfigExtras.cmake.in index 9b672327ef..4c1c3a612b 100644 --- a/src/corelib/Qt5CoreConfigExtras.cmake.in +++ b/src/corelib/Qt5CoreConfigExtras.cmake.in @@ -1,3 +1,6 @@ +if(NOT DEFINED QT_DEFAULT_MAJOR_VERSION) + set(QT_DEFAULT_MAJOR_VERSION 5) +endif() if (NOT TARGET Qt5::qmake) add_executable(Qt5::qmake IMPORTED) @@ -177,3 +180,24 @@ if (ANDROID_PLATFORM) endif() _qt5_Core_check_file_exists(${_Qt5CTestMacros}) + +# Create versionless tool targets. +foreach(__qt_tool qmake moc rcc) + if(NOT \"${QT_NO_CREATE_VERSIONLESS_TARGETS}\" AND NOT TARGET Qt::${__qt_tool} + AND TARGET Qt5::${__qt_tool}) + add_executable(Qt::${__qt_tool} IMPORTED) + get_target_property(__qt_imported_location Qt5::${__qt_tool} IMPORTED_LOCATION) + set_target_properties(Qt::${__qt_tool} + PROPERTIES IMPORTED_LOCATION \"${__qt_imported_location}\") + endif() +endforeach() + +!!IF !isEmpty(CMAKE_WINDOWS_BUILD) +# Add a versionless target for WinMain. +if(NOT \"${QT_NO_CREATE_VERSIONLESS_TARGETS}\" AND NOT TARGET Qt::WinMain) + add_library(Qt::WinMain INTERFACE IMPORTED) + set_target_properties(Qt::WinMain PROPERTIES + INTERFACE_LINK_LIBRARIES \"Qt5::WinMain\" + ) +endif() +!!ENDIF diff --git a/src/corelib/Qt5CoreMacros.cmake b/src/corelib/Qt5CoreMacros.cmake index e298cf7de7..6c21470164 100644 --- a/src/corelib/Qt5CoreMacros.cmake +++ b/src/corelib/Qt5CoreMacros.cmake @@ -157,6 +157,16 @@ function(qt5_generate_moc infile outfile ) qt5_create_moc_command(${abs_infile} ${_outfile} "${moc_flags}" "" "${moc_target}" "") endfunction() +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_generate_moc) + if(QT_DEFAULT_MAJOR_VERSION EQUAL 5) + qt5_generate_moc(${ARGV}) + elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + qt6_generate_moc(${ARGV}) + endif() + endfunction() +endif() + # qt5_wrap_cpp(outfiles inputfile ... ) @@ -184,6 +194,17 @@ function(qt5_wrap_cpp outfiles ) set(${outfiles} ${${outfiles}} PARENT_SCOPE) endfunction() +# This will override the CMake upstream command, because that one is for Qt 3. +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_wrap_cpp outfiles) + if(QT_DEFAULT_MAJOR_VERSION EQUAL 5) + qt5_wrap_cpp("${outfiles}" ${ARGN}) + elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + qt6_wrap_cpp("${outfiles}" ${ARGN}) + endif() + set("${outfiles}" "${${outfiles}}" PARENT_SCOPE) + endfunction() +endif() # _qt5_parse_qrc_file(infile _out_depends _rc_depends) @@ -255,6 +276,16 @@ function(qt5_add_binary_resources target ) add_custom_target(${target} ALL DEPENDS ${rcc_destination}) endfunction() +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_add_binary_resources) + if(QT_DEFAULT_MAJOR_VERSION EQUAL 5) + qt5_add_binary_resources(${ARGV}) + elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + qt6_add_binary_resources(${ARGV}) + endif() + endfunction() +endif() + # qt5_add_resources(outfiles inputfile ... ) @@ -293,6 +324,18 @@ function(qt5_add_resources outfiles ) set(${outfiles} ${${outfiles}} PARENT_SCOPE) endfunction() +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_add_resources outfiles) + if(QT_DEFAULT_MAJOR_VERSION EQUAL 5) + qt5_add_resources("${outfiles}" ${ARGN}) + elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + qt6_add_resources("${outfiles}" ${ARGN}) + endif() + set("${outfiles}" "${${outfiles}}" PARENT_SCOPE) + endfunction() +endif() + + # qt5_add_big_resources(outfiles inputfile ... ) function(qt5_add_big_resources outfiles ) @@ -341,6 +384,18 @@ function(qt5_add_big_resources outfiles ) set(${outfiles} ${${outfiles}} PARENT_SCOPE) endfunction() +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_add_big_resources outfiles) + if(QT_DEFAULT_MAJOR_VERSION EQUAL 5) + qt5_add_big_resources(${outfiles} ${ARGN}) + elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + qt6_add_big_resources(${outfiles} ${ARGN}) + endif() + set("${outfiles}" "${${outfiles}}" PARENT_SCOPE) + endfunction() +endif() + + set(_Qt5_COMPONENT_PATH "${CMAKE_CURRENT_LIST_DIR}/..") macro(qt5_use_modules _target _link_type) @@ -413,10 +468,19 @@ function(qt5_import_plugins TARGET_NAME) elseif(_doing STREQUAL "EXCLUDE_BY_TYPE") string(REGEX REPLACE "[-/]" "_" _plugin_type "${_arg}") set_property(TARGET ${TARGET_NAME} PROPERTY "QT_PLUGINS_${_plugin_type}" -) - set(_doing "") else() message(FATAL_ERROR "Unexpected extra argument: \"${_arg}\"") endif() endif() endforeach() endfunction() + +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_import_plugins) + if(QT_DEFAULT_MAJOR_VERSION EQUAL 5) + qt5_import_plugins(${ARGV}) + elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + qt6_import_plugins(${ARGV}) + endif() + endfunction() +endif() diff --git a/src/dbus/Qt5DBusConfigExtras.cmake.in b/src/dbus/Qt5DBusConfigExtras.cmake.in index 1d947159e2..a814678f7b 100644 --- a/src/dbus/Qt5DBusConfigExtras.cmake.in +++ b/src/dbus/Qt5DBusConfigExtras.cmake.in @@ -31,3 +31,14 @@ endif() set(Qt5DBus_QDBUSCPP2XML_EXECUTABLE Qt5::qdbuscpp2xml) set(Qt5DBus_QDBUSXML2CPP_EXECUTABLE Qt5::qdbusxml2cpp) + +# Create versionless tool targets. +foreach(__qt_tool qdbuscpp2xml qdbusxml2cpp) + if(NOT \"${QT_NO_CREATE_VERSIONLESS_TARGETS}\" AND NOT TARGET Qt::${__qt_tool} + AND TARGET Qt5::${__qt_tool}) + add_executable(Qt::${__qt_tool} IMPORTED) + get_target_property(__qt_imported_location Qt5::${__qt_tool} IMPORTED_LOCATION) + set_target_properties(Qt::${__qt_tool} + PROPERTIES IMPORTED_LOCATION \"${__qt_imported_location}\") + endif() +endforeach() diff --git a/src/dbus/Qt5DBusMacros.cmake b/src/dbus/Qt5DBusMacros.cmake index 9b69e77dc7..1cacccdddd 100644 --- a/src/dbus/Qt5DBusMacros.cmake +++ b/src/dbus/Qt5DBusMacros.cmake @@ -70,6 +70,17 @@ function(qt5_add_dbus_interface _sources _interface _basename) set(${_sources} ${${_sources}} PARENT_SCOPE) endfunction() +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_add_dbus_interface sources) + if(QT_DEFAULT_MAJOR_VERSION EQUAL 5) + qt5_add_dbus_interface("${sources}" ${ARGN}) + elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + qt6_add_dbus_interface("${sources}" ${ARGN}) + endif() + set("${sources}" "${${sources}}" PARENT_SCOPE) + endfunction() +endif() + function(qt5_add_dbus_interfaces _sources) foreach(_current_FILE ${ARGN}) @@ -83,6 +94,17 @@ function(qt5_add_dbus_interfaces _sources) set(${_sources} ${${_sources}} PARENT_SCOPE) endfunction() +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_add_dbus_interfaces sources) + if(QT_DEFAULT_MAJOR_VERSION EQUAL 5) + qt5_add_dbus_interfaces("${sources}" ${ARGN}) + elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + qt6_add_dbus_interfaces("${sources}" ${ARGN}) + endif() + set("${sources}" "${${sources}}" PARENT_SCOPE) + endfunction() +endif() + function(qt5_generate_dbus_interface _header) # _customName OPTIONS -some -options ) set(options) @@ -116,6 +138,16 @@ function(qt5_generate_dbus_interface _header) # _customName OPTIONS -some -optio ) endfunction() +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_generate_dbus_interface) + if(QT_DEFAULT_MAJOR_VERSION EQUAL 5) + qt5_generate_dbus_interface(${ARGV}) + elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + qt6_generate_dbus_interface(${ARGV}) + endif() + endfunction() +endif() + function(qt5_add_dbus_adaptor _sources _xml_file _include _parentClass) # _optionalBasename _optionalClassName) get_filename_component(_infile ${_xml_file} ABSOLUTE) @@ -152,3 +184,14 @@ function(qt5_add_dbus_adaptor _sources _xml_file _include _parentClass) # _optio list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}") set(${_sources} ${${_sources}} PARENT_SCOPE) endfunction() + +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_add_dbus_adaptor sources) + if(QT_DEFAULT_MAJOR_VERSION EQUAL 5) + qt5_add_dbus_adaptor("${sources}" ${ARGN}) + elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + qt6_add_dbus_adaptor("${sources}" ${ARGN}) + endif() + set("${sources}" "${${sources}}" PARENT_SCOPE) + endfunction() +endif() diff --git a/src/widgets/Qt5WidgetsConfigExtras.cmake.in b/src/widgets/Qt5WidgetsConfigExtras.cmake.in index 99d87e2e46..236d1d4159 100644 --- a/src/widgets/Qt5WidgetsConfigExtras.cmake.in +++ b/src/widgets/Qt5WidgetsConfigExtras.cmake.in @@ -17,3 +17,14 @@ endif() include(\"${CMAKE_CURRENT_LIST_DIR}/Qt5Widgets_AccessibleFactory.cmake\" OPTIONAL) set(Qt5Widgets_UIC_EXECUTABLE Qt5::uic) + +# Create versionless tool targets. +foreach(__qt_tool uic) + if(NOT \"${QT_NO_CREATE_VERSIONLESS_TARGETS}\" AND NOT TARGET Qt::${__qt_tool} + AND TARGET Qt5::${__qt_tool}) + add_executable(Qt::${__qt_tool} IMPORTED) + get_target_property(__qt_imported_location Qt5::${__qt_tool} IMPORTED_LOCATION) + set_target_properties(Qt::${__qt_tool} + PROPERTIES IMPORTED_LOCATION \"${__qt_imported_location}\") + endif() +endforeach() diff --git a/src/widgets/Qt5WidgetsMacros.cmake b/src/widgets/Qt5WidgetsMacros.cmake index 21e73d4f0c..35d2a2dc54 100644 --- a/src/widgets/Qt5WidgetsMacros.cmake +++ b/src/widgets/Qt5WidgetsMacros.cmake @@ -66,3 +66,15 @@ function(qt5_wrap_ui outfiles ) endforeach() set(${outfiles} ${${outfiles}} PARENT_SCOPE) endfunction() + +# This will override the CMake upstream command, because that one is for Qt 3. +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_wrap_ui outfiles) + if(QT_DEFAULT_MAJOR_VERSION EQUAL 5) + qt5_wrap_ui("${outfiles}" ${ARGN}) + elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6) + qt6_wrap_ui("${outfiles}" ${ARGN}) + endif() + set("${outfiles}" "${${outfiles}}" PARENT_SCOPE) + endfunction() +endif() -- cgit v1.2.3 From 114ff44f3c42e2575c60e6b5c8459acfea2dc60d Mon Sep 17 00:00:00 2001 From: Sze Howe Koh Date: Mon, 2 Sep 2019 07:32:49 +0800 Subject: QLabel: Allow pixmap() and picture() to return by-value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous versions of these functions that returned by-pointer are held over from Qt 1 times. They are inconsistent with the rest of the Qt API. [ChangeLog][QtWidgets][QLabel] QLabel::pixmap() and QLabel::picture() can now return by-value instead of by-pointer. Task-number: QTBUG-48701 Change-Id: I23ce319a7b1f757e1f4dec697551bb472e92fabf Reviewed-by: André Hartmann --- src/corelib/global/qnamespace.h | 3 ++ src/corelib/global/qnamespace.qdoc | 10 ++++ src/widgets/accessible/simplewidgets.cpp | 15 +++--- src/widgets/dialogs/qmessagebox.cpp | 6 +-- src/widgets/dialogs/qwizard.cpp | 4 +- src/widgets/widgets/qlabel.cpp | 78 ++++++++++++++++++++++++++++++-- src/widgets/widgets/qlabel.h | 20 +++++++- 7 files changed, 117 insertions(+), 19 deletions(-) diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 5b63daec69..8f40393a7e 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1767,6 +1767,9 @@ public: PassThrough }; + // QTBUG-48701 + enum ReturnByValue_t { ReturnByValue }; // ### Qt 7: Remove me + #ifndef Q_QDOC // NOTE: Generally, do not add QT_Q_ENUM if a corresponding Q_Q_FLAG exists. QT_Q_ENUM(ScrollBarPolicy) diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index 6149281904..169c296bcd 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -3319,3 +3319,13 @@ \value RoundPreferFloor Round up for .75 and above. \value PassThrough Don't round. */ + +/*! + \enum Qt::ReturnByValue_t + \since 5.15 + + This is a dummy type, designed to help users transition from certain deprecated APIs to their replacement APIs. + + \sa QLabel::picture() + \sa QLabel::pixmap() +*/ diff --git a/src/widgets/accessible/simplewidgets.cpp b/src/widgets/accessible/simplewidgets.cpp index 9dbbe9c608..107fd729fe 100644 --- a/src/widgets/accessible/simplewidgets.cpp +++ b/src/widgets/accessible/simplewidgets.cpp @@ -76,6 +76,9 @@ #include #include #endif +#ifndef QT_NO_PICTURE +#include +#endif #include #include #include @@ -431,10 +434,10 @@ QAccessible::Role QAccessibleDisplay::role() const #if QT_CONFIG(label) QLabel *l = qobject_cast(object()); if (l) { - if (l->pixmap()) + if (!l->pixmap(Qt::ReturnByValue).isNull()) return QAccessible::Graphic; #ifndef QT_NO_PICTURE - if (l->picture()) + if (!l->picture(Qt::ReturnByValue).isNull()) return QAccessible::Graphic; #endif #if QT_CONFIG(movie) @@ -558,10 +561,7 @@ QSize QAccessibleDisplay::imageSize() const #endif return QSize(); #if QT_CONFIG(label) - const QPixmap *pixmap = label->pixmap(); - if (!pixmap) - return QSize(); - return pixmap->size(); + return label->pixmap(Qt::ReturnByValue).size(); #endif } @@ -574,8 +574,7 @@ QPoint QAccessibleDisplay::imagePosition() const #endif return QPoint(); #if QT_CONFIG(label) - const QPixmap *pixmap = label->pixmap(); - if (!pixmap) + if (label->pixmap(Qt::ReturnByValue).isNull()) return QPoint(); return QPoint(label->mapToGlobal(label->pos())); diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 854fee6e33..4e7a4a65e3 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -305,7 +305,7 @@ void QMessageBoxPrivate::setupLayout() Q_Q(QMessageBox); delete q->layout(); QGridLayout *grid = new QGridLayout; - bool hasIcon = iconLabel->pixmap() && !iconLabel->pixmap()->isNull(); + bool hasIcon = !iconLabel->pixmap(Qt::ReturnByValue).isNull(); if (hasIcon) grid->addWidget(iconLabel, 0, 0, 2, 1, Qt::AlignTop); @@ -1323,9 +1323,7 @@ void QMessageBox::setIcon(Icon icon) QPixmap QMessageBox::iconPixmap() const { Q_D(const QMessageBox); - if (d->iconLabel && d->iconLabel->pixmap()) - return *d->iconLabel->pixmap(); - return QPixmap(); + return d->iconLabel->pixmap(Qt::ReturnByValue); } void QMessageBox::setIconPixmap(const QPixmap &pixmap) diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index a4789f40b1..2f145806cf 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -452,8 +452,8 @@ public: } QSize minimumSizeHint() const override { - if (pixmap() && !pixmap()->isNull()) - return pixmap()->size() / pixmap()->devicePixelRatio(); + if (!pixmap(Qt::ReturnByValue).isNull()) + return pixmap(Qt::ReturnByValue).size() / pixmap(Qt::ReturnByValue).devicePixelRatio(); return QFrame::minimumSizeHint(); } diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp index 77d117775a..2490df58f2 100644 --- a/src/widgets/widgets/qlabel.cpp +++ b/src/widgets/widgets/qlabel.cpp @@ -188,8 +188,13 @@ QLabelPrivate::~QLabelPrivate() */ #ifndef QT_NO_PICTURE +#if QT_DEPRECATED_SINCE(5, 15) /*! - Returns the label's picture or nullptr if the label doesn't have a + \deprecated + + New code should use the other overload which returns QPicture by-value. + + This function returns the label's picture or \c nullptr if the label doesn't have a picture. */ @@ -198,6 +203,37 @@ const QPicture *QLabel::picture() const Q_D(const QLabel); return d->picture; } +#endif // QT_DEPRECATED_SINCE(5, 15) + +/*! + \since 5.15 + Returns the label's picture. + + Previously, Qt provided a version of \c picture() which returned the picture + by-pointer. That version is now deprecated. To maintain compatibility + with old code, you can explicitly differentiate between the by-pointer + function and the by-value function: + + \code + const QPicture *picPtr = label->picture(); + QPicture picVal = label->picture(Qt::ReturnByValue); + \endcode + + If you disable the deprecated version using the QT_DISABLE_DEPRECATED_BEFORE + macro, then you can omit \c Qt::ReturnByValue as shown below: + + \code + QPicture picVal = label->picture(); + \endcode +*/ + +QPicture QLabel::picture(Qt::ReturnByValue_t) const +{ + Q_D(const QLabel); + if (d->picture) + return *(d->picture); + return QPicture(); +} #endif @@ -352,9 +388,27 @@ void QLabel::clear() /*! \property QLabel::pixmap - \brief the label's pixmap + \brief the label's pixmap. - If no pixmap has been set this will return nullptr. + Previously, Qt provided a version of \c pixmap() which returned the pixmap + by-pointer. That version is now deprecated. To maintain compatibility + with old code, you can explicitly differentiate between the by-pointer + function and the by-value function: + + \code + const QPixmap *pixmapPtr = label->pixmap(); + QPixmap pixmapVal = label->pixmap(Qt::ReturnByValue); + \endcode + + If you disable the deprecated version using the QT_DISABLE_DEPRECATED_BEFORE + macro, then you can omit \c Qt::ReturnByValue as shown below: + + \code + QPixmap pixmapVal = label->pixmap(); + \endcode + + If no pixmap has been set, the deprecated getter function will return + \c nullptr. Setting the pixmap clears any previous content. The buddy shortcut, if any, is disabled. @@ -373,11 +427,29 @@ void QLabel::setPixmap(const QPixmap &pixmap) d->updateLabel(); } +#if QT_DEPRECATED_SINCE(5, 15) +/*! + \deprecated + + New code should use the other overload which returns QPixmap by-value. +*/ const QPixmap *QLabel::pixmap() const { Q_D(const QLabel); return d->pixmap; } +#endif // QT_DEPRECATED_SINCE(5, 15) + +/*! + \since 5.15 +*/ +QPixmap QLabel::pixmap(Qt::ReturnByValue_t) const +{ + Q_D(const QLabel); + if (d->pixmap) + return *(d->pixmap); + return QPixmap(); +} #ifndef QT_NO_PICTURE /*! diff --git a/src/widgets/widgets/qlabel.h b/src/widgets/widgets/qlabel.h index 2f5db5a7d3..288022a71e 100644 --- a/src/widgets/widgets/qlabel.h +++ b/src/widgets/widgets/qlabel.h @@ -72,9 +72,25 @@ public: ~QLabel(); QString text() const; - const QPixmap *pixmap() const; + +#if QT_DEPRECATED_SINCE(5,15) + QT_DEPRECATED_VERSION_X(5, 15, "Use the other overload which returns QPixmap by-value") + const QPixmap *pixmap() const; // ### Qt 7: Remove function + + QPixmap pixmap(Qt::ReturnByValue_t) const; +#else + QPixmap pixmap(Qt::ReturnByValue_t = Qt::ReturnByValue) const; // ### Qt 7: Remove arg +#endif // QT_DEPRECATED_SINCE(5,15) + #ifndef QT_NO_PICTURE - const QPicture *picture() const; +# if QT_DEPRECATED_SINCE(5,15) + QT_DEPRECATED_VERSION_X(5, 15, "Use the other overload which returns QPicture by-value") + const QPicture *picture() const; // ### Qt 7: Remove function + + QPicture picture(Qt::ReturnByValue_t) const; +# else + QPicture picture(Qt::ReturnByValue_t = Qt::ReturnByValue) const; // ### Qt 7: Remove arg +# endif // QT_DEPRECATED_SINCE(5,15) #endif #if QT_CONFIG(movie) QMovie *movie() const; -- cgit v1.2.3 From e79a6253813cd67954e371805da547c48ea32d3d Mon Sep 17 00:00:00 2001 From: Sze Howe Koh Date: Sat, 14 Sep 2019 18:47:13 +0800 Subject: QCursor: Allow bitmap() and mask() to return by-value The previous versions of these functions that returned by-pointer are held over from Qt 1 times. They are inconsistent with the rest of the Qt API. [ChangeLog][QtGui][QCursor] QCursor::bitmap() and QCursor::mask() can now return by-value instead of by-pointer. Task-number: QTBUG-48701 Change-Id: I3ca4f0c28d5c831727a60309facfb49c74673bb7 Reviewed-by: Richard Moe Gustavsen --- src/gui/kernel/qcursor.cpp | 76 +++++++++++++++++++++++- src/gui/kernel/qcursor.h | 15 ++++- src/plugins/platforms/windows/qwindowscursor.cpp | 14 ++--- 3 files changed, 95 insertions(+), 10 deletions(-) diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp index 339284aa30..2018d28d92 100644 --- a/src/gui/kernel/qcursor.cpp +++ b/src/gui/kernel/qcursor.cpp @@ -325,7 +325,7 @@ QDataStream &operator<<(QDataStream &s, const QCursor &c) if (isPixmap) s << c.pixmap(); else - s << *c.bitmap() << *c.mask(); + s << c.bitmap(Qt::ReturnByValue) << c.mask(Qt::ReturnByValue); s << c.hotSpot(); } return s; @@ -565,7 +565,12 @@ void QCursor::setShape(Qt::CursorShape shape) } } +#if QT_DEPRECATED_SINCE(5, 15) /*! + \deprecated + + New code should use the other overload which returns QBitmap by-value. + Returns the cursor bitmap, or \nullptr if it is one of the standard cursors. */ @@ -577,6 +582,10 @@ const QBitmap *QCursor::bitmap() const } /*! + \deprecated + + New code should use the other overload which returns QBitmap by-value. + Returns the cursor bitmap mask, or \nullptr if it is one of the standard cursors. */ @@ -587,6 +596,71 @@ const QBitmap *QCursor::mask() const QCursorData::initialize(); return d->bmm; } +#endif // QT_DEPRECATED_SINCE(5, 15) + +/*! + \since 5.15 + + Returns the cursor bitmap, or a null bitmap if it is one of the + standard cursors. + + Previously, Qt provided a version of \c bitmap() which returned the bitmap + by-pointer. That version is now deprecated. To maintain compatibility + with old code, you can explicitly differentiate between the by-pointer + function and the by-value function: + + \code + const QBitmap *bmpPtr = cursor->bitmap(); + QBitmap bmpVal = cursor->bitmap(Qt::ReturnByValue); + \endcode + + If you disable the deprecated version, then you can omit \c Qt::ReturnByValue + as shown below: + + \code + QBitmap bmpVal = cursor->bitmap(); + \endcode +*/ +QBitmap QCursor::bitmap(Qt::ReturnByValue_t) const +{ + if (!QCursorData::initialized) + QCursorData::initialize(); + if (d->bm) + return *(d->bm); + return QBitmap(); +} + +/*! + \since 5.15 + + Returns the cursor bitmap mask, or a null bitmap if it is one of the + standard cursors. + + Previously, Qt provided a version of \c mask() which returned the bitmap + by-pointer. That version is now deprecated. To maintain compatibility + with old code, you can explicitly differentiate between the by-pointer + function and the by-value function: + + \code + const QBitmap *bmpPtr = cursor->mask(); + QBitmap bmpVal = cursor->mask(Qt::ReturnByValue); + \endcode + + If you disable the deprecated version, then you can omit \c Qt::ReturnByValue + as shown below: + + \code + QBitmap bmpVal = cursor->mask(); + \endcode +*/ +QBitmap QCursor::mask(Qt::ReturnByValue_t) const +{ + if (!QCursorData::initialized) + QCursorData::initialize(); + if (d->bmm) + return *(d->bmm); + return QBitmap(); +} /*! Returns the cursor pixmap. This is only valid if the cursor is a diff --git a/src/gui/kernel/qcursor.h b/src/gui/kernel/qcursor.h index 7966e35840..7a11fe59ee 100644 --- a/src/gui/kernel/qcursor.h +++ b/src/gui/kernel/qcursor.h @@ -97,8 +97,19 @@ public: Qt::CursorShape shape() const; void setShape(Qt::CursorShape newShape); - const QBitmap *bitmap() const; - const QBitmap *mask() const; +#if QT_DEPRECATED_SINCE(5, 15) + QT_DEPRECATED_VERSION_X(5, 15, "Use the other overload which returns QBitmap by-value") + const QBitmap *bitmap() const; // ### Qt 7: Remove function + + QT_DEPRECATED_VERSION_X(5, 15, "Use the other overload which returns QBitmap by-value") + const QBitmap *mask() const; // ### Qt 7: Remove function + + QBitmap bitmap(Qt::ReturnByValue_t) const; + QBitmap mask(Qt::ReturnByValue_t) const; +#else + QBitmap bitmap(Qt::ReturnByValue_t = Qt::ReturnByValue) const; // ### Qt 7: Remove arg + QBitmap mask(Qt::ReturnByValue_t = Qt::ReturnByValue) const; // ### Qt 7: Remove arg +#endif // QT_DEPRECATED_SINCE(5, 15) QPixmap pixmap() const; QPoint hotSpot() const; diff --git a/src/plugins/platforms/windows/qwindowscursor.cpp b/src/plugins/platforms/windows/qwindowscursor.cpp index 59457f1720..19de3d5939 100644 --- a/src/plugins/platforms/windows/qwindowscursor.cpp +++ b/src/plugins/platforms/windows/qwindowscursor.cpp @@ -80,10 +80,10 @@ QWindowsPixmapCursorCacheKey::QWindowsPixmapCursorCacheKey(const QCursor &c) : bitmapCacheKey(c.pixmap().cacheKey()), maskCacheKey(0) { if (!bitmapCacheKey) { - Q_ASSERT(c.bitmap()); - Q_ASSERT(c.mask()); - bitmapCacheKey = c.bitmap()->cacheKey(); - maskCacheKey = c.mask()->cacheKey(); + Q_ASSERT(!c.bitmap(Qt::ReturnByValue).isNull()); + Q_ASSERT(!c.mask(Qt::ReturnByValue).isNull()); + bitmapCacheKey = c.bitmap(Qt::ReturnByValue).cacheKey(); + maskCacheKey = c.mask(Qt::ReturnByValue).cacheKey(); } } @@ -169,9 +169,9 @@ static HCURSOR createBitmapCursor(const QImage &bbits, const QImage &mbits, // Create a cursor from image and mask of the format QImage::Format_Mono. static HCURSOR createBitmapCursor(const QCursor &cursor, qreal scaleFactor = 1) { - Q_ASSERT(cursor.shape() == Qt::BitmapCursor && cursor.bitmap()); - QImage bbits = cursor.bitmap()->toImage(); - QImage mbits = cursor.mask()->toImage(); + Q_ASSERT(cursor.shape() == Qt::BitmapCursor && !cursor.bitmap(Qt::ReturnByValue).isNull()); + QImage bbits = cursor.bitmap(Qt::ReturnByValue).toImage(); + QImage mbits = cursor.mask(Qt::ReturnByValue).toImage(); scaleFactor /= bbits.devicePixelRatioF(); if (!qFuzzyCompare(scaleFactor, 1)) { const QSize scaledSize = (QSizeF(bbits.size()) * scaleFactor).toSize(); -- cgit v1.2.3 From 1278995778a3ab576231c372969336a2f6621e02 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 14 Jan 2020 10:08:22 +0100 Subject: Windows QPA: Better disambiguate Window class names Use a standard prefix for Window class names containing version, build and namespace which should reduce conflicts. Task-number: QTBUG-81347 Change-Id: Ia7c20af71d364e362781f791a4e51b77d605c918 Reviewed-by: Oliver Wolff --- .../platforms/windows/qwindowsclipboard.cpp | 2 +- src/plugins/platforms/windows/qwindowscontext.cpp | 26 ++++++++++++++++++---- src/plugins/platforms/windows/qwindowscontext.h | 1 + .../platforms/windows/qwindowsglcontext.cpp | 2 +- .../platforms/windows/qwindowssystemtrayicon.cpp | 2 +- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsclipboard.cpp b/src/plugins/platforms/windows/qwindowsclipboard.cpp index ccd4e50a8b..efcb0b6e6e 100644 --- a/src/plugins/platforms/windows/qwindowsclipboard.cpp +++ b/src/plugins/platforms/windows/qwindowsclipboard.cpp @@ -190,7 +190,7 @@ void QWindowsClipboard::releaseIData() void QWindowsClipboard::registerViewer() { m_clipboardViewer = QWindowsContext::instance()-> - createDummyWindow(QStringLiteral("Qt5ClipboardView"), L"Qt5ClipboardView", + createDummyWindow(QStringLiteral("ClipboardView"), L"QtClipboardView", qClipboardViewerWndProc, WS_OVERLAPPED); // Try format listener API (Vista onwards) first. diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index d31352b854..c85d04b816 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -72,6 +72,7 @@ #include #include +#include #include #include #include @@ -426,7 +427,7 @@ bool QWindowsContext::initPowerNotificationHandler() if (d->m_powerNotification) return false; - d->m_powerDummyWindow = createDummyWindow(QStringLiteral("QtPowerDummyWindow"), L"QtPowerDummyWindow", qWindowsPowerWindowProc); + d->m_powerDummyWindow = createDummyWindow(QStringLiteral("PowerDummyWindow"), L"QtPowerDummyWindow", qWindowsPowerWindowProc); if (!d->m_powerDummyWindow) return false; @@ -536,6 +537,23 @@ void QWindowsContext::setKeyGrabber(QWindow *w) d->m_keyMapper.setKeyGrabber(w); } +QString QWindowsContext::classNamePrefix() +{ + static QString result; + if (result.isEmpty()) { + QTextStream str(&result); + str << "Qt" << QT_VERSION_MAJOR << QT_VERSION_MINOR << QT_VERSION_PATCH; + if (QLibraryInfo::isDebugBuild()) + str << 'd'; +#ifdef QT_NAMESPACE +# define xstr(s) str(s) +# define str(s) #s + str << xstr(QT_NAMESPACE); +#endif + } + return result; +} + // Window class registering code (from qapplication_win.cpp) QString QWindowsContext::registerWindowClass(const QWindow *w) @@ -567,8 +585,8 @@ QString QWindowsContext::registerWindowClass(const QWindow *w) break; } // Create a unique name for the flag combination - QString cname; - cname += QLatin1String("Qt5QWindow"); + QString cname = classNamePrefix(); + cname += QLatin1String("QWindow"); switch (type) { case Qt::Tool: cname += QLatin1String("Tool"); @@ -878,7 +896,7 @@ HWND QWindowsContext::createDummyWindow(const QString &classNameIn, { if (!wndProc) wndProc = DefWindowProc; - QString className = registerWindowClass(classNameIn, wndProc); + QString className = registerWindowClass(classNamePrefix() + classNameIn, wndProc); return CreateWindowEx(0, reinterpret_cast(className.utf16()), windowName, style, CW_USEDEFAULT, CW_USEDEFAULT, diff --git a/src/plugins/platforms/windows/qwindowscontext.h b/src/plugins/platforms/windows/qwindowscontext.h index 8027f09389..43ab8416ab 100644 --- a/src/plugins/platforms/windows/qwindowscontext.h +++ b/src/plugins/platforms/windows/qwindowscontext.h @@ -180,6 +180,7 @@ public: int defaultDPI() const; + static QString classNamePrefix(); QString registerWindowClass(const QWindow *w); QString registerWindowClass(QString cname, WNDPROC proc, unsigned style = 0, HBRUSH brush = nullptr, diff --git a/src/plugins/platforms/windows/qwindowsglcontext.cpp b/src/plugins/platforms/windows/qwindowsglcontext.cpp index f2d31d5783..f5d0a8780a 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsglcontext.cpp @@ -802,7 +802,7 @@ static HGLRC createContext(const QOpenGLStaticContext &staticContext, static inline HWND createDummyGLWindow() { return QWindowsContext::instance()-> - createDummyWindow(QStringLiteral("QtOpenGLDummyWindow"), + createDummyWindow(QStringLiteral("OpenGLDummyWindow"), L"OpenGLDummyWindow", nullptr, WS_OVERLAPPED | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); } diff --git a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp index 66c558df1e..53562c87dd 100644 --- a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp +++ b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp @@ -168,7 +168,7 @@ static inline HWND createTrayIconMessageWindow() return nullptr; // Register window class in the platform plugin. const QString className = - ctx->registerWindowClass(QStringLiteral("QTrayIconMessageWindowClass"), + ctx->registerWindowClass(QWindowsContext::classNamePrefix() + QStringLiteral("TrayIconMessageWindowClass"), qWindowsTrayIconWndProc); const wchar_t windowName[] = L"QTrayIconMessageWindow"; return CreateWindowEx(0, reinterpret_cast(className.utf16()), -- cgit v1.2.3 From 12f085e538a1e3060fc5be3e21cefbb6d4c492b5 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 21 Oct 2019 16:01:47 +0200 Subject: Windows QPA: Add detection of dark mode Read the dark mode setting and make it accessible via native interface. Add a command line option to set the support level. Task-number: QTBUG-72028 Change-Id: I1e9fe296a6b1bda81512d003183038b866b67545 Reviewed-by: Oliver Wolff --- src/gui/kernel/qguiapplication.cpp | 15 +++++++++++++++ src/plugins/platforms/windows/qwindowscontext.cpp | 20 +++++++++++++++++++- src/plugins/platforms/windows/qwindowscontext.h | 2 ++ .../platforms/windows/qwindowsintegration.cpp | 4 ++++ src/plugins/platforms/windows/qwindowsintegration.h | 4 +++- .../platforms/windows/qwindowsnativeinterface.cpp | 12 ++++++++++++ .../platforms/windows/qwindowsnativeinterface.h | 8 ++++++++ src/plugins/platforms/windows/qwindowstheme.cpp | 19 +++++++++++++++++++ src/plugins/platforms/windows/qwindowstheme.h | 2 ++ 9 files changed, 84 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 445ad6b835..1190bd1936 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -592,6 +592,21 @@ static QWindowGeometrySpecification windowGeometrySpecification = Q_WINDOW_GEOME \list \li \c {altgr}, detect the key \c {AltGr} found on some keyboards as Qt::GroupSwitchModifier (since Qt 5.12). + \li \c {darkmode=[1|2]} controls how Qt responds to the activation + of the \e{Dark Mode for applications} introduced in Windows 10 + 1903 (since Qt 5.15). + + A value of 1 causes Qt to switch the window borders to black + when \e{Dark Mode for applications} is activated and no High + Contrast Theme is in use. This is intended for applications + that implement their own theming. + + A value of 2 will in addition cause the Windows Vista style to + be deactivated and switch to the Windows style using a + simplified palette in dark mode. This is currently + experimental pending the introduction of new style that + properly adapts to dark mode. + \li \c {dialogs=[xp|none]}, \c xp uses XP-style native dialogs and \c none disables them. diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index c85d04b816..d322b0e92b 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -42,6 +42,7 @@ #include "qwindowsintegration.h" #include "qwindowswindow.h" #include "qwindowskeymapper.h" +#include "qwindowsnativeinterface.h" #include "qwindowsmousehandler.h" #include "qwindowspointerhandler.h" #include "qtwindowsglobal.h" @@ -277,8 +278,11 @@ struct QWindowsContextPrivate { bool m_asyncExpose = false; HPOWERNOTIFY m_powerNotification = nullptr; HWND m_powerDummyWindow = nullptr; + static bool m_darkMode; }; +bool QWindowsContextPrivate::m_darkMode = false; + QWindowsContextPrivate::QWindowsContextPrivate() : m_oleInitializeResult(OleInitialize(nullptr)) { @@ -293,6 +297,7 @@ QWindowsContextPrivate::QWindowsContextPrivate() m_systemInfo |= QWindowsContext::SI_RTL_Extensions; m_keyMapper.setUseRTLExtensions(true); } + m_darkMode = QWindowsTheme::queryDarkMode(); if (FAILED(m_oleInitializeResult)) { qWarning() << "QWindowsContext: OleInitialize() failed: " << QWindowsContext::comErrorString(m_oleInitializeResult); @@ -485,6 +490,11 @@ void QWindowsContext::setProcessDpiAwareness(QtWindows::ProcessDpiAwareness dpiA } } +bool QWindowsContext::isDarkMode() +{ + return QWindowsContextPrivate::m_darkMode; +} + QWindowsContext *QWindowsContext::instance() { return m_instance; @@ -1203,9 +1213,17 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message, t->displayChanged(); QWindowsWindow::displayChanged(); return d->m_screenManager.handleDisplayChange(wParam, lParam); - case QtWindows::SettingChangedEvent: + case QtWindows::SettingChangedEvent: { QWindowsWindow::settingsChanged(); + const bool darkMode = QWindowsTheme::queryDarkMode(); + if (darkMode != QWindowsContextPrivate::m_darkMode) { + QWindowsContextPrivate::m_darkMode = darkMode; + auto nativeInterface = + static_cast(QWindowsIntegration::instance()->nativeInterface()); + emit nativeInterface->darkModeChanged(darkMode); + } return d->m_screenManager.handleScreenChanges(); + } default: break; } diff --git a/src/plugins/platforms/windows/qwindowscontext.h b/src/plugins/platforms/windows/qwindowscontext.h index 43ab8416ab..1831ac6ec0 100644 --- a/src/plugins/platforms/windows/qwindowscontext.h +++ b/src/plugins/platforms/windows/qwindowscontext.h @@ -226,6 +226,8 @@ public: void setProcessDpiAwareness(QtWindows::ProcessDpiAwareness dpiAwareness); static int processDpiAwareness(); + static bool isDarkMode(); + void setDetectAltGrModifier(bool a); // Returns a combination of SystemInfoFlags diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp index 32bd29a842..4b4047ac0c 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.cpp +++ b/src/plugins/platforms/windows/qwindowsintegration.cpp @@ -219,6 +219,10 @@ static inline unsigned parseOptions(const QStringList ¶mList, options |= QWindowsIntegration::DontUseWMPointer; } else if (param == u"reverse") { options |= QWindowsIntegration::RtlEnabled; + } else if (param == u"darkmode=1") { + options |= QWindowsIntegration::DarkModeWindowFrames; + } else if (param == u"darkmode=2") { + options |= QWindowsIntegration::DarkModeWindowFrames | QWindowsIntegration::DarkModeStyle; } else { qWarning() << "Unknown option" << param; } diff --git a/src/plugins/platforms/windows/qwindowsintegration.h b/src/plugins/platforms/windows/qwindowsintegration.h index b49d21022b..1f16d13769 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.h +++ b/src/plugins/platforms/windows/qwindowsintegration.h @@ -70,7 +70,9 @@ public: NoNativeMenus = 0x200, DontUseWMPointer = 0x400, DetectAltGrModifier = 0x800, - RtlEnabled = 0x1000 + RtlEnabled = 0x1000, + DarkModeWindowFrames = 0x2000, + DarkModeStyle = 0x4000 }; explicit QWindowsIntegration(const QStringList ¶mList); diff --git a/src/plugins/platforms/windows/qwindowsnativeinterface.cpp b/src/plugins/platforms/windows/qwindowsnativeinterface.cpp index d1d181d66e..1195f15a59 100644 --- a/src/plugins/platforms/windows/qwindowsnativeinterface.cpp +++ b/src/plugins/platforms/windows/qwindowsnativeinterface.cpp @@ -47,6 +47,7 @@ #include "qwindowsopengltester.h" #include "qwindowsintegration.h" #include "qwindowsmime.h" +#include "qwindowstheme.h" #include "qwin10helpers.h" #include @@ -316,4 +317,15 @@ QVariant QWindowsNativeInterface::gpuList() const return result; } +bool QWindowsNativeInterface::isDarkMode() const +{ + return QWindowsContext::isDarkMode(); +} + +// Dark mode support level 2 (style) +bool QWindowsNativeInterface::isDarkModeStyle() const +{ + return (QWindowsIntegration::instance()->options() & QWindowsIntegration::DarkModeStyle) != 0; +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/windows/qwindowsnativeinterface.h b/src/plugins/platforms/windows/qwindowsnativeinterface.h index ce395dc5a4..90ba7a44c9 100644 --- a/src/plugins/platforms/windows/qwindowsnativeinterface.h +++ b/src/plugins/platforms/windows/qwindowsnativeinterface.h @@ -65,6 +65,8 @@ class QWindowsNativeInterface : public QPlatformNativeInterface { Q_OBJECT Q_PROPERTY(bool asyncExpose READ asyncExpose WRITE setAsyncExpose) + Q_PROPERTY(bool darkMode READ isDarkMode STORED false NOTIFY darkModeChanged) + Q_PROPERTY(bool darkModeStyle READ isDarkModeStyle STORED false) Q_PROPERTY(QVariant gpu READ gpu STORED false) Q_PROPERTY(QVariant gpuList READ gpuList STORED false) @@ -92,6 +94,9 @@ public: bool asyncExpose() const; void setAsyncExpose(bool value); + bool isDarkMode() const; + bool isDarkModeStyle() const; + QVariant gpu() const; QVariant gpuList() const; @@ -109,6 +114,9 @@ public: QFunctionPointer platformFunction(const QByteArray &function) const override; +Q_SIGNALS: + void darkModeChanged(bool); + private: static QWindowsWindowFunctions::WindowActivationBehavior m_windowActivationBehavior; }; diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 010aea2068..2f9dd0b40b 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include @@ -78,6 +79,7 @@ #include #include #include +#include #include @@ -946,6 +948,23 @@ bool QWindowsTheme::useNativeMenus() return result; } +bool QWindowsTheme::queryDarkMode() +{ + if (QOperatingSystemVersion::current() + < QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 17763) + || queryHighContrast()) { + return false; + } + const auto setting = QWinRegistryKey(HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)") + .dwordValue(L"AppsUseLightTheme"); + return setting.second && setting.first == 0; +} + +bool QWindowsTheme::queryHighContrast() +{ + return booleanSystemParametersInfo(SPI_GETHIGHCONTRAST, false); +} + QPlatformMenuItem *QWindowsTheme::createPlatformMenuItem() const { qCDebug(lcQpaMenus) << __FUNCTION__; diff --git a/src/plugins/platforms/windows/qwindowstheme.h b/src/plugins/platforms/windows/qwindowstheme.h index 7a8c321da4..d557c0b4fd 100644 --- a/src/plugins/platforms/windows/qwindowstheme.h +++ b/src/plugins/platforms/windows/qwindowstheme.h @@ -84,6 +84,8 @@ public: void showPlatformMenuBar() override; static bool useNativeMenus(); + static bool queryDarkMode(); + static bool queryHighContrast(); void refreshFonts(); -- cgit v1.2.3 From eb26563dd5483ab83a7a5addf8f98a4921d1edc1 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 3 Jan 2020 16:10:40 +0100 Subject: Windows QPA: Add setting of dark window borders Implement dark mode support level 1: change the window borders to dark and back, tracking the activation of dark mode. Task-number: QTBUG-72028 Change-Id: I6e8b31e7ee574f4d90438405f361cd940faee7fd Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowscontext.cpp | 5 +++ src/plugins/platforms/windows/qwindowswindow.cpp | 44 +++++++++++++++++++++++ src/plugins/platforms/windows/qwindowswindow.h | 3 ++ 3 files changed, 52 insertions(+) diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index d322b0e92b..5578259399 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -1221,6 +1221,11 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message, auto nativeInterface = static_cast(QWindowsIntegration::instance()->nativeInterface()); emit nativeInterface->darkModeChanged(darkMode); + const auto options = QWindowsIntegration::instance()->options(); + if ((options & QWindowsIntegration::DarkModeWindowFrames) != 0) { + for (QWindowsWindow *w : d->m_windows) + w->setDarkBorder(QWindowsContextPrivate::m_darkMode); + } } return d->m_screenManager.handleScreenChanges(); } diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index a7aad15749..b7536066d0 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -749,6 +749,11 @@ void WindowCreationData::fromWindow(const QWindow *w, const Qt::WindowFlags flag } } +static inline bool shouldApplyDarkFrame(const QWindow *w) +{ + return w->isTopLevel() && !w->flags().testFlag(Qt::FramelessWindowHint); +} + QWindowsWindowData WindowCreationData::create(const QWindow *w, const WindowData &data, QString title) const { @@ -816,6 +821,12 @@ QWindowsWindowData return result; } + if (QWindowsContext::isDarkMode() + && (QWindowsIntegration::instance()->options() & QWindowsIntegration::DarkModeWindowFrames) != 0 + && shouldApplyDarkFrame(w)) { + QWindowsWindow::setDarkBorderToWindow(result.hwnd, true); + } + if (mirrorParentWidth != 0) { context->obtainedPos.setX(mirrorParentWidth - context->obtainedSize.width() - context->obtainedPos.x()); @@ -2892,6 +2903,39 @@ bool QWindowsWindow::isTopLevel() const return window()->isTopLevel() && !m_data.embedded; } +enum : WORD { + DwmwaUseImmersiveDarkMode = 20, + DwmwaUseImmersiveDarkModeBefore20h1 = 19 +}; + +static bool queryDarkBorder(HWND hwnd) +{ + BOOL result = FALSE; + const bool ok = + SUCCEEDED(DwmGetWindowAttribute(hwnd, DwmwaUseImmersiveDarkMode, &result, sizeof(result))) + || SUCCEEDED(DwmGetWindowAttribute(hwnd, DwmwaUseImmersiveDarkModeBefore20h1, &result, sizeof(result))); + if (!ok) + qWarning("%s: Unable to retrieve dark window border setting.", __FUNCTION__); + return result == TRUE; +} + +bool QWindowsWindow::setDarkBorderToWindow(HWND hwnd, bool d) +{ + const BOOL darkBorder = d ? TRUE : FALSE; + const bool ok = + SUCCEEDED(DwmSetWindowAttribute(hwnd, DwmwaUseImmersiveDarkMode, &darkBorder, sizeof(darkBorder))) + || SUCCEEDED(DwmSetWindowAttribute(hwnd, DwmwaUseImmersiveDarkModeBefore20h1, &darkBorder, sizeof(darkBorder))); + if (!ok) + qWarning("%s: Unable to set dark window border.", __FUNCTION__); + return ok; +} + +void QWindowsWindow::setDarkBorder(bool d) +{ + if (shouldApplyDarkFrame(window()) && queryDarkBorder(m_data.hwnd) != d) + setDarkBorderToWindow(m_data.hwnd, d); +} + QWindowsMenuBar *QWindowsWindow::menuBar() const { return m_menuBar.data(); diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 1f8800272b..7c37c6b115 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -287,6 +287,9 @@ public: HWND handle() const override { return m_data.hwnd; } bool isTopLevel() const override; + static bool setDarkBorderToWindow(HWND hwnd, bool d); + void setDarkBorder(bool d); + QWindowsMenuBar *menuBar() const; void setMenuBar(QWindowsMenuBar *mb); -- cgit v1.2.3 From 859307d7a590873d8df5f8094e13043370fccaa7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 25 Sep 2019 15:04:36 +0200 Subject: Windows QPA: Provide an experimental palette for dark mode Provide a simple palette for dark mode, implementing dark mode support level 2. Task-number: QTBUG-72028 Change-Id: I6f71870b251ccb7da30c01abb22c224e600f2b27 Reviewed-by: Oliver Wolff --- src/plugins/platforms/windows/qwindowscontext.cpp | 5 + src/plugins/platforms/windows/qwindowstheme.cpp | 112 ++++++++++++++++----- src/plugins/platforms/windows/qwindowstheme.h | 2 +- .../styles/windowsvista/qwindowsxpstyle.cpp | 8 +- src/widgets/styles/qwindowsstyle.cpp | 17 ++++ src/widgets/styles/qwindowsstyle_p_p.h | 1 + 6 files changed, 118 insertions(+), 27 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index 5578259399..2591966d54 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -1226,6 +1226,11 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message, for (QWindowsWindow *w : d->m_windows) w->setDarkBorder(QWindowsContextPrivate::m_darkMode); } + if ((options & QWindowsIntegration::DarkModeStyle) != 0) { + QWindowsTheme::instance()->refresh(); + for (QWindowsWindow *w : d->m_windows) + QWindowSystemInterface::handleThemeChange(w->window()); + } } return d->m_screenManager.handleScreenChanges(); } diff --git a/src/plugins/platforms/windows/qwindowstheme.cpp b/src/plugins/platforms/windows/qwindowstheme.cpp index 2f9dd0b40b..325956b7ba 100644 --- a/src/plugins/platforms/windows/qwindowstheme.cpp +++ b/src/plugins/platforms/windows/qwindowstheme.cpp @@ -243,6 +243,15 @@ static bool shGetFileInfoBackground(const QString &fileName, DWORD attributes, return result; } +// Dark Mode constants +enum DarkModeColors : QRgb { + darkModeBtnHighlightRgb = 0xc0c0c0, + darkModeBtnShadowRgb = 0x808080, + darkModeHighlightRgb = 0x0055ff, // deviating from 0x800080 + darkModeMenuHighlightRgb = darkModeHighlightRgb, + darkModeGrayTextRgb = 0x00ff00 +}; + // from QStyle::standardPalette static inline QPalette standardPalette() { @@ -260,23 +269,55 @@ static inline QPalette standardPalette() return palette; } -static inline QPalette systemPalette() +static void populateLightSystemBasePalette(QPalette &result) { - QPalette result = standardPalette(); result.setColor(QPalette::WindowText, getSysColor(COLOR_WINDOWTEXT)); - result.setColor(QPalette::Button, getSysColor(COLOR_BTNFACE)); - result.setColor(QPalette::Light, getSysColor(COLOR_BTNHIGHLIGHT)); + const QColor btnFace = getSysColor(COLOR_BTNFACE); + result.setColor(QPalette::Button, btnFace); + const QColor btnHighlight = getSysColor(COLOR_BTNHIGHLIGHT); + result.setColor(QPalette::Light, btnHighlight); result.setColor(QPalette::Dark, getSysColor(COLOR_BTNSHADOW)); result.setColor(QPalette::Mid, result.button().color().darker(150)); result.setColor(QPalette::Text, getSysColor(COLOR_WINDOWTEXT)); - result.setColor(QPalette::BrightText, getSysColor(COLOR_BTNHIGHLIGHT)); + result.setColor(QPalette::BrightText, btnHighlight); result.setColor(QPalette::Base, getSysColor(COLOR_WINDOW)); - result.setColor(QPalette::Window, getSysColor(COLOR_BTNFACE)); + result.setColor(QPalette::Window, btnFace); result.setColor(QPalette::ButtonText, getSysColor(COLOR_BTNTEXT)); result.setColor(QPalette::Midlight, getSysColor(COLOR_3DLIGHT)); result.setColor(QPalette::Shadow, getSysColor(COLOR_3DDKSHADOW)); result.setColor(QPalette::Highlight, getSysColor(COLOR_HIGHLIGHT)); result.setColor(QPalette::HighlightedText, getSysColor(COLOR_HIGHLIGHTTEXT)); +} + +static void populateDarkSystemBasePalette(QPalette &result) +{ + const QColor darkModeWindowText = Qt::white; + result.setColor(QPalette::WindowText, darkModeWindowText); + const QColor darkModebtnFace = Qt::black; + result.setColor(QPalette::Button, darkModebtnFace); + const QColor btnHighlight = QColor(darkModeBtnHighlightRgb); + result.setColor(QPalette::Light, btnHighlight); + result.setColor(QPalette::Dark, QColor(darkModeBtnShadowRgb)); + result.setColor(QPalette::Mid, result.button().color().darker(150)); + result.setColor(QPalette::Text, darkModeWindowText); + result.setColor(QPalette::BrightText, btnHighlight); + result.setColor(QPalette::Base, darkModebtnFace); + result.setColor(QPalette::Window, darkModebtnFace); + result.setColor(QPalette::ButtonText, darkModeWindowText); + result.setColor(QPalette::Midlight, darkModeWindowText); + result.setColor(QPalette::Shadow, darkModeWindowText); + result.setColor(QPalette::Highlight, QColor(darkModeHighlightRgb)); + result.setColor(QPalette::HighlightedText, darkModeWindowText); +} + +static QPalette systemPalette(bool light) +{ + QPalette result = standardPalette(); + if (light) + populateLightSystemBasePalette(result); + else + populateDarkSystemBasePalette(result); + result.setColor(QPalette::Link, Qt::blue); result.setColor(QPalette::LinkVisited, Qt::magenta); result.setColor(QPalette::Inactive, QPalette::Button, result.button().color()); @@ -302,19 +343,19 @@ static inline QPalette systemPalette() result.setColor(QPalette::Disabled, QPalette::Text, disabled); result.setColor(QPalette::Disabled, QPalette::ButtonText, disabled); result.setColor(QPalette::Disabled, QPalette::Highlight, - getSysColor(COLOR_HIGHLIGHT)); + light ? getSysColor(COLOR_HIGHLIGHT) : QColor(darkModeHighlightRgb)); result.setColor(QPalette::Disabled, QPalette::HighlightedText, - getSysColor(COLOR_HIGHLIGHTTEXT)); + light ? getSysColor(COLOR_HIGHLIGHTTEXT) : QColor(Qt::white)); result.setColor(QPalette::Disabled, QPalette::Base, result.window().color()); return result; } -static inline QPalette toolTipPalette(const QPalette &systemPalette) +static inline QPalette toolTipPalette(const QPalette &systemPalette, bool light) { QPalette result(systemPalette); - const QColor tipBgColor(getSysColor(COLOR_INFOBK)); - const QColor tipTextColor(getSysColor(COLOR_INFOTEXT)); + const QColor tipBgColor = light ? getSysColor(COLOR_INFOBK) : QColor(Qt::black); + const QColor tipTextColor = light ? getSysColor(COLOR_INFOTEXT) : QColor(Qt::white); result.setColor(QPalette::All, QPalette::Button, tipBgColor); result.setColor(QPalette::All, QPalette::Window, tipBgColor); @@ -339,12 +380,13 @@ static inline QPalette toolTipPalette(const QPalette &systemPalette) return result; } -static inline QPalette menuPalette(const QPalette &systemPalette) +static inline QPalette menuPalette(const QPalette &systemPalette, bool light) { QPalette result(systemPalette); - const QColor menuColor(getSysColor(COLOR_MENU)); - const QColor menuTextColor(getSysColor(COLOR_MENUTEXT)); - const QColor disabled(getSysColor(COLOR_GRAYTEXT)); + const QColor menuColor = light ? getSysColor(COLOR_MENU) : QColor(Qt::black); + const QColor menuTextColor = light ? getSysColor(COLOR_MENUTEXT) : QColor(Qt::white); + const QColor disabled = light + ? getSysColor(COLOR_GRAYTEXT) : QColor(darkModeGrayTextRgb); // we might need a special color group for the result. result.setColor(QPalette::Active, QPalette::Button, menuColor); result.setColor(QPalette::Active, QPalette::Text, menuTextColor); @@ -353,8 +395,10 @@ static inline QPalette menuPalette(const QPalette &systemPalette) result.setColor(QPalette::Disabled, QPalette::WindowText, disabled); result.setColor(QPalette::Disabled, QPalette::Text, disabled); const bool isFlat = booleanSystemParametersInfo(SPI_GETFLATMENU, false); - result.setColor(QPalette::Disabled, QPalette::Highlight, - getSysColor(isFlat ? COLOR_MENUHILIGHT : COLOR_HIGHLIGHT)); + const QColor highlightColor = light + ? (getSysColor(isFlat ? COLOR_MENUHILIGHT : COLOR_HIGHLIGHT)) + : QColor(darkModeMenuHighlightRgb); + result.setColor(QPalette::Disabled, QPalette::Highlight, highlightColor); result.setColor(QPalette::Disabled, QPalette::HighlightedText, disabled); result.setColor(QPalette::Disabled, QPalette::Button, result.color(QPalette::Active, QPalette::Button)); @@ -375,12 +419,12 @@ static inline QPalette menuPalette(const QPalette &systemPalette) return result; } -static inline QPalette *menuBarPalette(const QPalette &menuPalette) +static inline QPalette *menuBarPalette(const QPalette &menuPalette, bool light) { QPalette *result = nullptr; if (booleanSystemParametersInfo(SPI_GETFLATMENU, false)) { result = new QPalette(menuPalette); - const QColor menubar(getSysColor(COLOR_MENUBAR)); + const QColor menubar(light ? getSysColor(COLOR_MENUBAR) : QColor(Qt::black)); result->setColor(QPalette::Active, QPalette::Button, menubar); result->setColor(QPalette::Disabled, QPalette::Button, menubar); result->setColor(QPalette::Inactive, QPalette::Button, menubar); @@ -487,10 +531,26 @@ void QWindowsTheme::refreshPalettes() if (!QGuiApplication::desktopSettingsAware()) return; - m_palettes[SystemPalette] = new QPalette(systemPalette()); - m_palettes[ToolTipPalette] = new QPalette(toolTipPalette(*m_palettes[SystemPalette])); - m_palettes[MenuPalette] = new QPalette(menuPalette(*m_palettes[SystemPalette])); - m_palettes[MenuBarPalette] = menuBarPalette(*m_palettes[MenuPalette]); + const bool light = + !QWindowsContext::isDarkMode() + || (QWindowsIntegration::instance()->options() & QWindowsIntegration::DarkModeStyle) == 0; + m_palettes[SystemPalette] = new QPalette(systemPalette(light)); + m_palettes[ToolTipPalette] = new QPalette(toolTipPalette(*m_palettes[SystemPalette], light)); + m_palettes[MenuPalette] = new QPalette(menuPalette(*m_palettes[SystemPalette], light)); + m_palettes[MenuBarPalette] = menuBarPalette(*m_palettes[MenuPalette], light); + if (!light) { + m_palettes[ButtonPalette] = new QPalette(*m_palettes[SystemPalette]); + m_palettes[ButtonPalette]->setColor(QPalette::Button, QColor(0x666666u)); + const QColor checkBoxBlue(0x0078d7u); + const QColor white(Qt::white); + m_palettes[CheckBoxPalette] = new QPalette(*m_palettes[SystemPalette]); + m_palettes[CheckBoxPalette]->setColor(QPalette::Window, checkBoxBlue); + m_palettes[CheckBoxPalette]->setColor(QPalette::Base, checkBoxBlue); + m_palettes[CheckBoxPalette]->setColor(QPalette::Button, checkBoxBlue); + m_palettes[CheckBoxPalette]->setColor(QPalette::ButtonText, white); + m_palettes[RadioButtonPalette] = new QPalette(*m_palettes[CheckBoxPalette]); + + } } void QWindowsTheme::clearFonts() @@ -499,6 +559,12 @@ void QWindowsTheme::clearFonts() std::fill(m_fonts, m_fonts + NFonts, nullptr); } +void QWindowsTheme::refresh() +{ + refreshPalettes(); + refreshFonts(); +} + void QWindowsTheme::refreshFonts() { clearFonts(); diff --git a/src/plugins/platforms/windows/qwindowstheme.h b/src/plugins/platforms/windows/qwindowstheme.h index d557c0b4fd..af28f2878c 100644 --- a/src/plugins/platforms/windows/qwindowstheme.h +++ b/src/plugins/platforms/windows/qwindowstheme.h @@ -88,11 +88,11 @@ public: static bool queryHighContrast(); void refreshFonts(); + void refresh(); static const char *name; private: - void refresh() { refreshPalettes(); refreshFonts(); } void clearPalettes(); void refreshPalettes(); void clearFonts(); diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp index 5d2e8efd68..899e7f7c17 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp @@ -225,9 +225,11 @@ static HRGN qt_hrgn_from_qregion(const QRegion ®ion) */ bool QWindowsXPStylePrivate::useXP(bool update) { - if (!update) - return use_xp; - return use_xp = IsThemeActive() && (IsAppThemed() || !QCoreApplication::instance()); + if (update) { + use_xp = IsThemeActive() && (IsAppThemed() || !QCoreApplication::instance()) + && !QWindowsStylePrivate::isDarkMode(); + } + return use_xp; } /* \internal diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 8496a2c223..497afd17e1 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -84,6 +84,7 @@ #include #include #include +#include #include #include @@ -127,6 +128,22 @@ qreal QWindowsStylePrivate::appDevicePixelRatio() return qApp->devicePixelRatio(); } +bool QWindowsStylePrivate::isDarkMode() +{ + bool result = false; +#ifdef Q_OS_WIN + // Windows only: Return whether dark mode style support is desired and + // dark mode is in effect. + if (auto ni = QGuiApplication::platformNativeInterface()) { + const QVariant darkModeStyleP = ni->property("darkModeStyle"); + result = darkModeStyleP.type() == QVariant::Bool + && darkModeStyleP.value() + && ni->property("darkMode").value(); + } +#endif + return result; +} + // Returns \c true if the toplevel parent of \a widget has seen the Alt-key bool QWindowsStylePrivate::hasSeenAlt(const QWidget *widget) const { diff --git a/src/widgets/styles/qwindowsstyle_p_p.h b/src/widgets/styles/qwindowsstyle_p_p.h index 4f6ffcefc2..a25f5c4166 100644 --- a/src/widgets/styles/qwindowsstyle_p_p.h +++ b/src/widgets/styles/qwindowsstyle_p_p.h @@ -74,6 +74,7 @@ public: static qreal devicePixelRatio(const QWidget *widget = nullptr) { return widget ? widget->devicePixelRatioF() : QWindowsStylePrivate::appDevicePixelRatio(); } static qreal nativeMetricScaleFactor(const QWidget *widget = nullptr); + static bool isDarkMode(); bool hasSeenAlt(const QWidget *widget) const; bool altDown() const { return alt_down; } -- cgit v1.2.3 From bf330a8f034a8d6198a78f87d23eafc5ef7e6ffb Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 26 Dec 2019 19:35:55 +0100 Subject: QGestureManager: fix one (of many) inefficient loop(s) I showed QGestureManager to a colleage and I just couldn't avert my eyes... Also remove a pointless container::clear() call (the data member's dtor will do that implicitly). Change-Id: Id2b3f471d62e5ea416e875f28ecee73f8614a469 Reviewed-by: Giuseppe D'Angelo --- src/widgets/kernel/qgesturemanager.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/widgets/kernel/qgesturemanager.cpp b/src/widgets/kernel/qgesturemanager.cpp index 5604391059..541519245e 100644 --- a/src/widgets/kernel/qgesturemanager.cpp +++ b/src/widgets/kernel/qgesturemanager.cpp @@ -105,11 +105,10 @@ QGestureManager::QGestureManager(QObject *parent) QGestureManager::~QGestureManager() { qDeleteAll(m_recognizers); - foreach (QGestureRecognizer *recognizer, m_obsoleteGestures.keys()) { - qDeleteAll(m_obsoleteGestures.value(recognizer)); - delete recognizer; + for (auto it = m_obsoleteGestures.cbegin(), end = m_obsoleteGestures.cend(); it != end; ++it) { + qDeleteAll(it.value()); + delete it.key(); } - m_obsoleteGestures.clear(); } Qt::GestureType QGestureManager::registerGestureRecognizer(QGestureRecognizer *recognizer) -- cgit v1.2.3 From f21a6d409ea0504c64cd72861fc16b6f3e080086 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 18 Dec 2019 15:43:24 +0100 Subject: QStringList: use local storage in removeDuplicates() If available, use a C++17 std::pmr::unordered_set with a monotonic buffer resource and a 256-byte stack buffer to avoid the per-element allocations of QSet. Results on my machine: RESULT : tst_QStringList::removeDuplicates():"empty": - 0.00014 msecs per iteration (total: 74, iterations: 524288) + 0.000031 msecs per iteration (total: 66, iterations: 2097152) RESULT : tst_QStringList::removeDuplicates():"short-dup-0.00": - 0.00043 msecs per iteration (total: 57, iterations: 131072) + 0.00013 msecs per iteration (total: 69, iterations: 524288) RESULT : tst_QStringList::removeDuplicates():"short-dup-0.50": - 0.00049 msecs per iteration (total: 65, iterations: 131072) + 0.00032 msecs per iteration (total: 85, iterations: 262144) RESULT : tst_QStringList::removeDuplicates():"short-dup-0.66": - 0.00057 msecs per iteration (total: 75, iterations: 131072) + 0.00039 msecs per iteration (total: 52, iterations: 131072) RESULT : tst_QStringList::removeDuplicates():"short-dup-0.75": - 0.00064 msecs per iteration (total: 85, iterations: 131072) + 0.00048 msecs per iteration (total: 63, iterations: 131072) RESULT : tst_QStringList::removeDuplicates():"long-dup-0.00": - 0.083 msecs per iteration (total: 85, iterations: 1024) + 0.039 msecs per iteration (total: 80, iterations: 2048) RESULT : tst_QStringList::removeDuplicates():"long-dup-0.50": - 0.11 msecs per iteration (total: 58, iterations: 512) + 0.078 msecs per iteration (total: 80, iterations: 1024) RESULT : tst_QStringList::removeDuplicates():"long-dup-0.66": - 0.13 msecs per iteration (total: 70, iterations: 512) + 0.10 msecs per iteration (total: 53, iterations: 512) RESULT : tst_QStringList::removeDuplicates():"long-dup-0.75": - 0.16 msecs per iteration (total: 86, iterations: 512) + 0.13 msecs per iteration (total: 69, iterations: 512) When interpreting the data, take into account that each iteration contains _also_ a deep copy of the QStringList d/t the detach from 'input'. The pattern is used elsewhere in Qt, so I've put the class that implements the seen set into a private header file and used in some other places I found. Change-Id: I1f71a82008a16d5a3818f91f290ade21d837805e Reviewed-by: Giuseppe D'Angelo --- src/corelib/text/qstringlist.cpp | 10 +-- src/corelib/tools/qduplicatetracker_p.h | 94 ++++++++++++++++++++++ src/corelib/tools/tools.pri | 1 + .../fontconfig/qfontconfigdatabase.cpp | 9 ++- src/widgets/itemviews/qtreewidget.cpp | 7 +- src/xml/dom/qdom.cpp | 8 +- tests/benchmarks/corelib/text/qstringlist/main.cpp | 39 +++++++++ .../corelib/text/qstringlist/qstringlist.pro | 1 + 8 files changed, 153 insertions(+), 16 deletions(-) create mode 100644 src/corelib/tools/qduplicatetracker_p.h diff --git a/src/corelib/text/qstringlist.cpp b/src/corelib/text/qstringlist.cpp index 4bbe424ed2..4b9dcee169 100644 --- a/src/corelib/text/qstringlist.cpp +++ b/src/corelib/text/qstringlist.cpp @@ -43,9 +43,9 @@ #if QT_CONFIG(regularexpression) # include #endif +#include #include - QT_BEGIN_NAMESPACE /*! \typedef QStringListIterator @@ -885,15 +885,13 @@ int QtPrivate::QStringList_removeDuplicates(QStringList *that) { int n = that->size(); int j = 0; - QSet seen; + + QDuplicateTracker seen; seen.reserve(n); - int setSize = 0; for (int i = 0; i < n; ++i) { const QString &s = that->at(i); - seen.insert(s); - if (setSize == seen.size()) // unchanged size => was already seen + if (seen.hasSeen(s)) continue; - ++setSize; if (j != i) that->swapItemsAt(i, j); ++j; diff --git a/src/corelib/tools/qduplicatetracker_p.h b/src/corelib/tools/qduplicatetracker_p.h new file mode 100644 index 0000000000..99068c01a3 --- /dev/null +++ b/src/corelib/tools/qduplicatetracker_p.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QDUPLICATETRACKER_P_H +#define QDUPLICATETRACKER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +#if QT_HAS_INCLUDE() && __cplusplus > 201402L +# include +# include +#else +# include +#endif + +QT_BEGIN_NAMESPACE + +template +class QDuplicateTracker { +#ifdef __cpp_lib_memory_resource + char buffer[Prealloc * sizeof(T)]; + std::pmr::monotonic_buffer_resource res{buffer, sizeof buffer}; + std::pmr::unordered_set set{&res}; +#else + QSet set; + int setSize = 0; +#endif + Q_DISABLE_COPY_MOVE(QDuplicateTracker); +public: + QDuplicateTracker() = default; + void reserve(int n) { set.reserve(n); } + Q_REQUIRED_RESULT bool hasSeen(const T &s) + { + bool inserted; +#ifdef __cpp_lib_memory_resource + inserted = set.insert(s).second; +#else + set.insert(s); + const int n = set.size(); + inserted = qExchange(setSize, n) != n; +#endif + return !inserted; + } +}; + +QT_END_NAMESPACE + +#endif /* QDUPLICATETRACKER_P_H */ diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index 40c84157cd..e078ab4409 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -12,6 +12,7 @@ HEADERS += \ tools/qcontainerfwd.h \ tools/qcontainertools_impl.h \ tools/qcryptographichash.h \ + tools/qduplicatetracker_p.h \ tools/qfreelist_p.h \ tools/qhash.h \ tools/qhashfunctions.h \ diff --git a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp index 7af5490963..af49ad6407 100644 --- a/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp +++ b/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp @@ -56,6 +56,8 @@ #include +#include + #include #if FC_VERSION >= 20402 #include @@ -778,9 +780,9 @@ QStringList QFontconfigDatabase::fallbacksForFamily(const QString &family, QFont FcPatternDestroy(pattern); if (fontSet) { - QSet duplicates; + QDuplicateTracker duplicates; duplicates.reserve(fontSet->nfont + 1); - duplicates.insert(family.toCaseFolded()); + (void)duplicates.hasSeen(family.toCaseFolded()); for (int i = 0; i < fontSet->nfont; i++) { FcChar8 *value = nullptr; if (FcPatternGetString(fontSet->fonts[i], FC_FAMILY, 0, &value) != FcResultMatch) @@ -788,9 +790,8 @@ QStringList QFontconfigDatabase::fallbacksForFamily(const QString &family, QFont // capitalize(value); const QString familyName = QString::fromUtf8((const char *)value); const QString familyNameCF = familyName.toCaseFolded(); - if (!duplicates.contains(familyNameCF)) { + if (!duplicates.hasSeen(familyNameCF)) { fallbackFamilies << familyName; - duplicates.insert(familyNameCF); } } FcFontSetDestroy(fontSet); diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index ddb31523fd..0d4c391e1c 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -48,6 +48,8 @@ #include #include +#include + #include QT_BEGIN_NAMESPACE @@ -3175,13 +3177,12 @@ QList QTreeWidget::selectedItems() const const QModelIndexList indexes = selectionModel()->selectedIndexes(); QList items; items.reserve(indexes.count()); - QSet seen; + QDuplicateTracker seen; seen.reserve(indexes.count()); for (const auto &index : indexes) { QTreeWidgetItem *item = d->item(index); - if (item->isHidden() || seen.contains(item)) + if (item->isHidden() || seen.hasSeen(item)) continue; - seen.insert(item); items.append(item); } return items; diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index bbc877eead..26c1a2122b 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -60,6 +60,9 @@ #include #include #include +#include + + #include QT_BEGIN_NAMESPACE @@ -4081,10 +4084,10 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const } s << '<' << qName << nsDecl; - QSet outputtedPrefixes; /* Write out attributes. */ if (!m_attr->map.isEmpty()) { + QDuplicateTracker outputtedPrefixes; QHash::const_iterator it = m_attr->map.constBegin(); for (; it != m_attr->map.constEnd(); ++it) { s << ' '; @@ -4105,9 +4108,8 @@ void QDomElementPrivate::save(QTextStream& s, int depth, int indent) const * arrive in those situations. */ if((!it.value()->ownerNode || it.value()->ownerNode->prefix != it.value()->prefix) && - !outputtedPrefixes.contains(it.value()->prefix)) { + !outputtedPrefixes.hasSeen(it.value()->prefix)) { s << " xmlns:" << it.value()->prefix << "=\"" << encodeText(it.value()->namespaceURI, s, true, true) << '\"'; - outputtedPrefixes.insert(it.value()->prefix); } } } diff --git a/tests/benchmarks/corelib/text/qstringlist/main.cpp b/tests/benchmarks/corelib/text/qstringlist/main.cpp index ae355a8b89..9f184d0cf5 100644 --- a/tests/benchmarks/corelib/text/qstringlist/main.cpp +++ b/tests/benchmarks/corelib/text/qstringlist/main.cpp @@ -41,6 +41,9 @@ private slots: void join() const; void join_data() const; + void removeDuplicates() const; + void removeDuplicates_data() const; + void split_qlist_qbytearray() const; void split_qlist_qbytearray_data() const { return split_data(); } @@ -116,6 +119,42 @@ void tst_QStringList::join_data() const << QString(); } +void tst_QStringList::removeDuplicates() const +{ + QFETCH(const QStringList, input); + + QBENCHMARK { + auto copy = input; + copy.removeDuplicates(); + } +} + +void tst_QStringList::removeDuplicates_data() const +{ + QTest::addColumn("input"); + + const QStringList s = {"one", "two", "three"}; + + QTest::addRow("empty") << QStringList(); + QTest::addRow("short-dup-0.00") << s; + QTest::addRow("short-dup-0.50") << (s + s); + QTest::addRow("short-dup-0.66") << (s + s + s); + QTest::addRow("short-dup-0.75") << (s + s + s + s); + + const QStringList l = []() { + QStringList result; + const int n = 1000; + result.reserve(n); + for (int i = 0; i < n; ++i) + result.push_back(QString::number(i)); + return result; + }(); + QTest::addRow("long-dup-0.00") << l; + QTest::addRow("long-dup-0.50") << (l + l); + QTest::addRow("long-dup-0.66") << (l + l + l); + QTest::addRow("long-dup-0.75") << (l + l + l + l); +} + void tst_QStringList::split_data() const { QTest::addColumn("input"); diff --git a/tests/benchmarks/corelib/text/qstringlist/qstringlist.pro b/tests/benchmarks/corelib/text/qstringlist/qstringlist.pro index 5803e7da0e..2e7ae058f7 100644 --- a/tests/benchmarks/corelib/text/qstringlist/qstringlist.pro +++ b/tests/benchmarks/corelib/text/qstringlist/qstringlist.pro @@ -1,5 +1,6 @@ TARGET = tst_bench_qstringlist CONFIG -= debug CONFIG += release +CONFIG += benchmark QT = core testlib SOURCES += main.cpp -- cgit v1.2.3 From aec4e05e9e8ad9109d7db15dd0fea477e4574c20 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 25 Jan 2020 20:12:12 +0100 Subject: Doc/QtWidgets: replace some 0 with \nullptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace some 'is 0' or 'are 0' where 0 referes to a nullptr with 'is \nullptr' and 'are \nullptr' Change-Id: I5ff46185b570bdfc7d20d18a47fd9174771ad8e5 Reviewed-by: André Hartmann Reviewed-by: Sze Howe Koh --- src/widgets/dialogs/qwizard.cpp | 2 +- src/widgets/graphicsview/qgraphicsproxywidget.cpp | 4 ++-- src/widgets/graphicsview/qgraphicsview.cpp | 2 +- src/widgets/styles/qdrawutil.cpp | 20 ++++++++++---------- src/widgets/styles/qproxystyle.cpp | 2 +- src/widgets/styles/qstyle.cpp | 6 +++--- src/widgets/util/qundoview.cpp | 10 +++++----- src/widgets/widgets/qabstractscrollarea.cpp | 6 +++--- src/widgets/widgets/qcombobox.cpp | 2 +- src/widgets/widgets/qdialogbuttonbox.cpp | 2 +- src/widgets/widgets/qdockwidget.cpp | 4 ++-- src/widgets/widgets/qmdiarea.cpp | 4 ++-- src/widgets/widgets/qtabwidget.cpp | 2 +- 13 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index 2f145806cf..87f6875c8c 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -2924,7 +2924,7 @@ void QWizard::setDefaultProperty(const char *className, const char *property, or when the watermark is not provided the side widget is displayed on the left side of the wizard. - Passing 0 shows no side widget. + Passing \nullptr shows no side widget. When the \a widget is not \nullptr the wizard reparents it. diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp index eb8acf1f27..a9a57c57fa 100644 --- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp +++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp @@ -570,8 +570,8 @@ QGraphicsProxyWidget::~QGraphicsProxyWidget() After this function returns, QGraphicsProxyWidget will keep its state synchronized with that of \a widget whenever possible. - If a widget is already embedded by this proxy when this function is - called, that widget will first be automatically unembedded. Passing 0 for + If a widget is already embedded by this proxy when this function is called, + that widget will first be automatically unembedded. Passing \nullptr for the \a widget argument will only unembed the widget, and the ownership of the currently embedded widget will be passed on to the caller. Every child widget that are embedded will also be embedded and their proxy diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index e1a829f779..102f3e894f 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -963,7 +963,7 @@ static inline void QRect_unite(QRect *rect, const QRect &other) /* Calling this function results in update rects being clipped to the item's bounding rect. Note that updates prior to this function call is not clipped. - The clip is removed by passing 0. + The clip is removed by passing \nullptr. */ void QGraphicsViewPrivate::setUpdateClip(QGraphicsItem *item) { diff --git a/src/widgets/styles/qdrawutil.cpp b/src/widgets/styles/qdrawutil.cpp index d30b43a679..66729e4dc7 100644 --- a/src/widgets/styles/qdrawutil.cpp +++ b/src/widgets/styles/qdrawutil.cpp @@ -214,7 +214,7 @@ void qDrawShadeLine(QPainter *p, int x1, int y1, int x2, int y2, specifies the line width for each of the lines; it is not the total line width. The \a midLineWidth specifies the width of a middle line drawn in the QPalette::mid() color. The rectangle's - interior is filled with the \a fill brush unless \a fill is 0. + interior is filled with the \a fill brush unless \a fill is \nullptr. The rectangle appears sunken if \a sunken is true, otherwise raised. @@ -331,7 +331,7 @@ void qDrawShadeRect(QPainter *p, int x, int y, int w, int h, The given \a palette specifies the shading colors (\l {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l {QPalette::mid()}{middle} colors). The panel's interior is filled - with the \a fill brush unless \a fill is 0. + with the \a fill brush unless \a fill is \nullptr. The panel appears sunken if \a sunken is true, otherwise raised. @@ -490,7 +490,7 @@ static void qDrawWinShades(QPainter *p, Draws the Windows-style button specified by the given point (\a x, \a y}, \a width and \a height using the provided \a painter with a line width of 2 pixels. The button's interior is filled with the - \a{fill} brush unless \a fill is 0. + \a{fill} brush unless \a fill is \nullptr. The given \a palette specifies the shading colors (\l {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l @@ -528,7 +528,7 @@ void qDrawWinButton(QPainter *p, int x, int y, int w, int h, Draws the Windows-style panel specified by the given point(\a x, \a y), \a width and \a height using the provided \a painter with a line width of 2 pixels. The button's interior is filled with the - \a fill brush unless \a fill is 0. + \a fill brush unless \a fill is \nullptr. The given \a palette specifies the shading colors. The panel appears sunken if \a sunken is true, otherwise raised. @@ -567,7 +567,7 @@ void qDrawWinPanel(QPainter *p, int x, int y, int w, int h, Draws the plain rectangle beginning at (\a x, \a y) with the given \a width and \a height, using the specified \a painter, \a lineColor and \a lineWidth. The rectangle's interior is filled with the \a - fill brush unless \a fill is 0. + fill brush unless \a fill is \nullptr. \warning This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make @@ -676,7 +676,7 @@ void qDrawShadeLine(QPainter *p, const QPoint &p1, const QPoint &p2, specifies the line width for each of the lines; it is not the total line width. The \a midLineWidth specifies the width of a middle line drawn in the QPalette::mid() color. The rectangle's - interior is filled with the \a fill brush unless \a fill is 0. + interior is filled with the \a fill brush unless \a fill is \nullptr. The rectangle appears sunken if \a sunken is true, otherwise raised. @@ -714,7 +714,7 @@ void qDrawShadeRect(QPainter *p, const QRect &r, The given \a palette specifies the shading colors (\l {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l {QPalette::mid()}{middle} colors). The panel's interior is filled - with the \a fill brush unless \a fill is 0. + with the \a fill brush unless \a fill is \nullptr. The panel appears sunken if \a sunken is true, otherwise raised. @@ -746,7 +746,7 @@ void qDrawShadePanel(QPainter *p, const QRect &r, Draws the Windows-style button at the rectangle specified by \a rect using the given \a painter with a line width of 2 pixels. The button's interior - is filled with the \a{fill} brush unless \a fill is 0. + is filled with the \a{fill} brush unless \a fill is \nullptr. The given \a palette specifies the shading colors (\l {QPalette::light()}{light}, \l {QPalette::dark()}{dark} and \l @@ -774,7 +774,7 @@ void qDrawWinButton(QPainter *p, const QRect &r, Draws the Windows-style panel at the rectangle specified by \a rect using the given \a painter with a line width of 2 pixels. The button's interior - is filled with the \a fill brush unless \a fill is 0. + is filled with the \a fill brush unless \a fill is \nullptr. The given \a palette specifies the shading colors. The panel appears sunken if \a sunken is true, otherwise raised. @@ -804,7 +804,7 @@ void qDrawWinPanel(QPainter *p, const QRect &r, Draws the plain rectangle specified by \a rect using the given \a painter, \a lineColor and \a lineWidth. The rectangle's interior is filled with the - \a fill brush unless \a fill is 0. + \a fill brush unless \a fill is \nullptr. \warning This function does not look at QWidget::style() or QApplication::style(). Use the drawing functions in QStyle to make diff --git a/src/widgets/styles/qproxystyle.cpp b/src/widgets/styles/qproxystyle.cpp index cfaa5a2011..0cc235bc84 100644 --- a/src/widgets/styles/qproxystyle.cpp +++ b/src/widgets/styles/qproxystyle.cpp @@ -403,7 +403,7 @@ QIcon QProxyStyle::standardIcon(StandardPixmap standardIcon, orientation specifies whether the controls are laid out side by side or stacked vertically. The \a option parameter can be used to pass extra information about the parent widget. The \a widget parameter - is optional and can also be used if \a option is 0. + is optional and can also be used if \a option is \nullptr. The default implementation returns -1. diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index d2f5ac76f9..72e40d657d 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -2362,14 +2362,14 @@ QPalette QStyle::standardPalette() const \fn int QStyle::layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, - const QStyleOption *option = 0, const QWidget *widget = 0) const + const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const Returns the spacing that should be used between \a control1 and \a control2 in a layout. \a orientation specifies whether the controls are laid out side by side or stacked vertically. The \a option parameter can be used to pass extra information about the parent widget. The \a widget parameter is optional and can also - be used if \a option is 0. + be used if \a option is \nullptr. This function is called by the layout system. It is used only if PM_LayoutHorizontalSpacing or PM_LayoutVerticalSpacing returns a @@ -2386,7 +2386,7 @@ QPalette QStyle::standardPalette() const controls are laid out side by side or stacked vertically. The \a option parameter can be used to pass extra information about the parent widget. The \a widget parameter is optional and can also - be used if \a option is 0. + be used if \a option is \nullptr. \a controls1 and \a controls2 are OR-combination of zero or more \l{QSizePolicy::ControlTypes}{control types}. diff --git a/src/widgets/util/qundoview.cpp b/src/widgets/util/qundoview.cpp index 9ca83a1da2..a39276a2b8 100644 --- a/src/widgets/util/qundoview.cpp +++ b/src/widgets/util/qundoview.cpp @@ -358,8 +358,8 @@ QUndoStack *QUndoView::stack() const } /*! - Sets the stack displayed by this view to \a stack. If \a stack is 0, the view - will be empty. + Sets the stack displayed by this view to \a stack. If \a stack is \nullptr, + the view will be empty. If the view was previously looking at a QUndoGroup, the group is set to \nullptr. @@ -378,10 +378,10 @@ void QUndoView::setStack(QUndoStack *stack) #if QT_CONFIG(undogroup) /*! - Sets the group displayed by this view to \a group. If \a group is 0, the view will - be empty. + Sets the group displayed by this view to \a group. If \a group is \nullptr, + the view will be empty. - The view will update itself autmiatically whenever the active stack of the group changes. + The view will update itself automatically whenever the active stack of the group changes. \sa group(), setStack() */ diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp index 320b3bf7ef..257cffda62 100644 --- a/src/widgets/widgets/qabstractscrollarea.cpp +++ b/src/widgets/widgets/qabstractscrollarea.cpp @@ -512,8 +512,8 @@ QAbstractScrollArea::~QAbstractScrollArea() Sets the viewport to be the given \a widget. The QAbstractScrollArea will take ownership of the given \a widget. - If \a widget is 0, QAbstractScrollArea will assign a new QWidget instance - for the viewport. + If \a widget is \nullptr, QAbstractScrollArea will assign a new QWidget + instance for the viewport. \sa viewport() */ @@ -720,7 +720,7 @@ QWidget *QAbstractScrollArea::cornerWidget() const You will probably also want to set at least one of the scroll bar modes to \c AlwaysOn. - Passing 0 shows no widget in the corner. + Passing \nullptr shows no widget in the corner. Any previous corner widget is hidden. diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 9826cabe50..aa3788c404 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -2044,7 +2044,7 @@ const QValidator *QComboBox::validator() const \since 4.2 Sets the \a completer to use instead of the current completer. - If \a completer is 0, auto completion is disabled. + If \a completer is \nullptr, auto completion is disabled. By default, for an editable combo box, a QCompleter that performs case insensitive inline completion is automatically created. diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index 2e12320bc3..28c4f59d0d 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -699,7 +699,7 @@ QList QDialogButtonBox::buttons() const /*! Returns the button role for the specified \a button. This function returns - \l InvalidRole if \a button is 0 or has not been added to the button box. + \l InvalidRole if \a button is \nullptr or has not been added to the button box. \sa buttons(), addButton() */ diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index 299e5da8d3..1d358c493e 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -1674,8 +1674,8 @@ QAction * QDockWidget::toggleViewAction() const \since 4.3 Sets an arbitrary \a widget as the dock widget's title bar. If \a widget - is 0, any custom title bar widget previously set on the dock widget is - removed, but not deleted, and the default title bar will be used + is \nullptr, any custom title bar widget previously set on the dock widget + is removed, but not deleted, and the default title bar will be used instead. If a title bar widget is set, QDockWidget will not use native window diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp index 3272ac440b..da6eb47372 100644 --- a/src/widgets/widgets/qmdiarea.cpp +++ b/src/widgets/widgets/qmdiarea.cpp @@ -103,8 +103,8 @@ \fn void QMdiArea::subWindowActivated(QMdiSubWindow *window) QMdiArea emits this signal after \a window has been activated. When \a - window is 0, QMdiArea has just deactivated its last active window, and - there are no active windows on the workspace. + window is \nullptr, QMdiArea has just deactivated its last active window, + and there are no active windows on the workspace. \sa QMdiArea::activeSubWindow() */ diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp index f0bfe67e3a..a19dacda52 100644 --- a/src/widgets/widgets/qtabwidget.cpp +++ b/src/widgets/widgets/qtabwidget.cpp @@ -612,7 +612,7 @@ void QTabWidget::setTabVisible(int index, bool visible) Only the horizontal element of the \a corner will be used. - Passing 0 shows no widget in the corner. + Passing \nullptr shows no widget in the corner. Any previously set corner widget is hidden. -- cgit v1.2.3 From ae9056587a52d51c7b41b41f631c6cab8097a7c7 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 25 Jan 2020 21:19:47 +0100 Subject: Doc/QtCore: use new signal/slot signature in snippets Use the new signal/slot syntax in the snippets where possible. Also change some 0 to nullptr. Change-Id: Ie3da2721d3cec33704f73f4d39c06a767717b095 Reviewed-by: Sze Howe Koh --- .../code/src_corelib_kernel_qcoreapplication.cpp | 10 +++--- .../src_corelib_statemachine_qstatemachine.cpp | 2 +- .../code/src_corelib_thread_qfuturewatcher.cpp | 2 +- .../snippets/code/src_corelib_tools_qtimeline.cpp | 4 +-- .../doc/snippets/qsignalmapper/buttonwidget.cpp | 14 ++++----- .../doc/snippets/qsignalmapper/buttonwidget.h | 4 +-- .../doc/snippets/resource-system/mainwindow.cpp | 36 +++++++++++----------- src/corelib/doc/snippets/statemachine/main.cpp | 13 ++++---- src/corelib/doc/snippets/statemachine/main2.cpp | 15 ++++----- src/corelib/doc/snippets/statemachine/main3.cpp | 2 +- src/corelib/doc/snippets/statemachine/main5.cpp | 14 ++++----- src/corelib/doc/snippets/timers/analogclock.cpp | 2 +- src/corelib/doc/snippets/timers/timers.cpp | 6 ++-- src/corelib/doc/src/animation.qdoc | 4 +-- src/corelib/doc/src/statemachine.qdoc | 4 +-- 15 files changed, 67 insertions(+), 65 deletions(-) diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp index aae2456bf1..36b47e6f6e 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp @@ -56,7 +56,7 @@ QApplication::sendEvent(mainWindow, &event); //! [1] QPushButton *quitButton = new QPushButton("Quit"); -connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit()), Qt::QueuedConnection); +connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection); //! [1] @@ -79,12 +79,12 @@ Q_COREAPP_STARTUP_FUNCTION(preRoutineMyDebugTool) //! [4] -static int *global_ptr = 0; +static int *global_ptr = nullptr; static void cleanup_ptr() { delete [] global_ptr; - global_ptr = 0; + global_ptr = nullptr; } void init_ptr() @@ -125,9 +125,9 @@ private: //! [6] static inline QString tr(const char *sourceText, - const char *comment = 0); + const char *comment = nullptr); static inline QString trUtf8(const char *sourceText, - const char *comment = 0); + const char *comment = nullptr); //! [6] diff --git a/src/corelib/doc/snippets/code/src_corelib_statemachine_qstatemachine.cpp b/src/corelib/doc/snippets/code/src_corelib_statemachine_qstatemachine.cpp index a606da1a0c..c756116de4 100644 --- a/src/corelib/doc/snippets/code/src_corelib_statemachine_qstatemachine.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_statemachine_qstatemachine.cpp @@ -56,7 +56,7 @@ QState *s1 = new QState(); s1->assignProperty(&button, "text", "Click me"); QFinalState *s2 = new QFinalState(); -s1->addTransition(&button, SIGNAL(clicked()), s2); +s1->addTransition(&button, &QPushButton::clicked, s2); machine.addState(s1); machine.addState(s2); diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qfuturewatcher.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qfuturewatcher.cpp index 043974b25b..336c1e9c79 100644 --- a/src/corelib/doc/snippets/code/src_corelib_thread_qfuturewatcher.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_thread_qfuturewatcher.cpp @@ -52,7 +52,7 @@ // Instantiate the objects and connect to the finished signal. MyClass myObject; QFutureWatcher watcher; -connect(&watcher, SIGNAL(finished()), &myObject, SLOT(handleFinished())); +connect(&watcher, QFutureWatcher::finished, &myObject, &MyClass::handleFinished); // Start the computation. QFuture future = QtConcurrent::run(...); diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qtimeline.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qtimeline.cpp index 004a810fce..80859d5ba5 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qtimeline.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qtimeline.cpp @@ -56,10 +56,10 @@ progressBar->setRange(0, 100); // Construct a 1-second timeline with a frame range of 0 - 100 QTimeLine *timeLine = new QTimeLine(1000, this); timeLine->setFrameRange(0, 100); -connect(timeLine, SIGNAL(frameChanged(int)), progressBar, SLOT(setValue(int))); +connect(timeLine, &QTimeLine::frameChanged, progressBar, &QProgressBar::setValue); // Clicking the push button will start the progress bar animation pushButton = new QPushButton(tr("Start animation"), this); -connect(pushButton, SIGNAL(clicked()), timeLine, SLOT(start())); +connect(pushButton, &QPushButton::clicked, timeLine, &QTimeLine::start); ... //! [0] diff --git a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp index e91c41b305..84a156bb6d 100644 --- a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp +++ b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp @@ -48,11 +48,10 @@ ** ****************************************************************************/ -#include -#include - #include "buttonwidget.h" +#include + //! [0] ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent) : QWidget(parent) @@ -62,15 +61,16 @@ ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent) QGridLayout *gridLayout = new QGridLayout; for (int i = 0; i < texts.size(); ++i) { QPushButton *button = new QPushButton(texts[i]); - connect(button, SIGNAL(clicked()), signalMapper, SLOT(map())); + connect(button, &QPushButton::clicked, + signalMapper, &QSignalMapper::map); //! [0] //! [1] signalMapper->setMapping(button, texts[i]); gridLayout->addWidget(button, i / 3, i % 3); } - connect(signalMapper, SIGNAL(mapped(QString)), + connect(signalMapper, QOverload::of(&QSignalMapper::mapped), //! [1] //! [2] - this, SIGNAL(clicked(QString))); + this, &ButtonWidget::clicked); setLayout(gridLayout); } @@ -84,7 +84,7 @@ ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent) for (int i = 0; i < texts.size(); ++i) { QString text = texts[i]; QPushButton *button = new QPushButton(text); - connect(button, &QPushButton::clicked, [=] { clicked(text); }); + connect(button, &QPushButton::clicked, [this, text] { clicked(text); }); gridLayout->addWidget(button, i / 3, i % 3); } setLayout(gridLayout); diff --git a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h index f55683c2d5..b9d59f8dd8 100644 --- a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h +++ b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h @@ -51,7 +51,7 @@ #ifndef BUTTONWIDGET_H #define BUTTONWIDGET_H -#include +#include class QSignalMapper; class QString; @@ -63,7 +63,7 @@ class ButtonWidget : public QWidget Q_OBJECT public: - ButtonWidget(const QStringList &texts, QWidget *parent = 0); + ButtonWidget(const QStringList &texts, QWidget *parent = nullptr); signals: void clicked(const QString &text); diff --git a/src/corelib/doc/snippets/resource-system/mainwindow.cpp b/src/corelib/doc/snippets/resource-system/mainwindow.cpp index 86e93aaa62..6dc525304c 100644 --- a/src/corelib/doc/snippets/resource-system/mainwindow.cpp +++ b/src/corelib/doc/snippets/resource-system/mainwindow.cpp @@ -68,10 +68,10 @@ MainWindow::MainWindow() readSettings(); - connect(textEdit->document(), SIGNAL(contentsChanged()), - this, SLOT(documentWasModified())); + connect(textEdit->document(), &QTextEdit::contentsChanged, + this, &QAction::documentWasModified); - setCurrentFile(""); + setCurrentFile(QString()); setUnifiedTitleAndToolBarOnMac(true); } //! [2] @@ -95,7 +95,7 @@ void MainWindow::newFile() { if (maybeSave()) { textEdit->clear(); - setCurrentFile(""); + setCurrentFile(QString()); } } //! [6] @@ -162,31 +162,31 @@ void MainWindow::createActions() newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this); newAct->setShortcuts(QKeySequence::New); newAct->setStatusTip(tr("Create a new file")); - connect(newAct, SIGNAL(triggered()), this, SLOT(newFile())); + connect(newAct, &QAction::triggered, this, &MainWindow::newFile); //! [19] openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this); openAct->setShortcuts(QKeySequence::Open); openAct->setStatusTip(tr("Open an existing file")); - connect(openAct, SIGNAL(triggered()), this, SLOT(open())); + connect(openAct, &QAction::triggered, this, &MainWindow::open); //! [18] //! [19] saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save"), this); saveAct->setShortcuts(QKeySequence::Save); saveAct->setStatusTip(tr("Save the document to disk")); - connect(saveAct, SIGNAL(triggered()), this, SLOT(save())); + connect(saveAct, &QAction::triggered, this, &MainWindow::save); saveAsAct = new QAction(tr("Save &As..."), this); saveAsAct->setShortcuts(QKeySequence::SaveAs); saveAsAct->setStatusTip(tr("Save the document under a new name")); - connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs())); + connect(saveAsAct, &QAction::triggered, this, &MainWindow::saveAs); //! [20] exitAct = new QAction(tr("E&xit"), this); exitAct->setShortcuts(QKeySequence::Quit); //! [20] exitAct->setStatusTip(tr("Exit the application")); - connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + connect(exitAct, &QAction::triggered, this, &MainWindow::close); //! [21] cutAct = new QAction(QIcon(":/images/cut.png"), tr("Cu&t"), this); @@ -194,38 +194,38 @@ void MainWindow::createActions() cutAct->setShortcuts(QKeySequence::Cut); cutAct->setStatusTip(tr("Cut the current selection's contents to the " "clipboard")); - connect(cutAct, SIGNAL(triggered()), textEdit, SLOT(cut())); + connect(cutAct, &QAction::triggered, textEdit, &QTextEdit::cut); copyAct = new QAction(QIcon(":/images/copy.png"), tr("&Copy"), this); copyAct->setShortcuts(QKeySequence::Copy); copyAct->setStatusTip(tr("Copy the current selection's contents to the " "clipboard")); - connect(copyAct, SIGNAL(triggered()), textEdit, SLOT(copy())); + connect(copyAct, &QAction::triggered, textEdit, &QTextEdit::copy); pasteAct = new QAction(QIcon(":/images/paste.png"), tr("&Paste"), this); pasteAct->setShortcuts(QKeySequence::Paste); pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current " "selection")); - connect(pasteAct, SIGNAL(triggered()), textEdit, SLOT(paste())); + connect(pasteAct, &QAction::triggered, textEdit, &QTextEdit::paste); aboutAct = new QAction(tr("&About"), this); aboutAct->setStatusTip(tr("Show the application's About box")); - connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + connect(aboutAct, &QAction::triggered, this, &MainWindow::about); //! [22] aboutQtAct = new QAction(tr("About &Qt"), this); aboutQtAct->setStatusTip(tr("Show the Qt library's About box")); - connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt); //! [22] //! [23] cutAct->setEnabled(false); //! [23] //! [24] copyAct->setEnabled(false); - connect(textEdit, SIGNAL(copyAvailable(bool)), - cutAct, SLOT(setEnabled(bool))); - connect(textEdit, SIGNAL(copyAvailable(bool)), - copyAct, SLOT(setEnabled(bool))); + connect(textEdit, &QTextEdit::copyAvailable, + cutAct, &QAction::setEnabled); + connect(textEdit, &QTextEdit::copyAvailable, + copyAct, &QAction::setEnabled); } //! [24] diff --git a/src/corelib/doc/snippets/statemachine/main.cpp b/src/corelib/doc/snippets/statemachine/main.cpp index 8cd8b69e12..c399f4f199 100644 --- a/src/corelib/doc/snippets/statemachine/main.cpp +++ b/src/corelib/doc/snippets/statemachine/main.cpp @@ -48,13 +48,14 @@ ** ****************************************************************************/ -#include +#include int main(int argv, char **args) { QApplication app(argv, args); QLabel *label = new QLabel; + QPushButton *button = new QPushButton; //![0] QStateMachine machine; @@ -70,14 +71,14 @@ int main(int argv, char **args) //![4] //![5] - QObject::connect(s3, SIGNAL(entered()), button, SLOT(showMaximized())); - QObject::connect(s3, SIGNAL(exited()), button, SLOT(showMinimized())); + QObject::connect(s3, &QState::entered, button, &QPushButton:showMaximized); + QObject::connect(s3, &QState::exited, button, &QPushButton::showMinimized); //![5] //![1] - s1->addTransition(button, SIGNAL(clicked()), s2); - s2->addTransition(button, SIGNAL(clicked()), s3); - s3->addTransition(button, SIGNAL(clicked()), s1); + s1->addTransition(button, &QPushButton::clicked, s2); + s2->addTransition(button, &QPushButton::clicked, s3); + s3->addTransition(button, &QPushButton::clicked, s1); //![1] //![2] diff --git a/src/corelib/doc/snippets/statemachine/main2.cpp b/src/corelib/doc/snippets/statemachine/main2.cpp index 96eb912b14..dedd2d29bf 100644 --- a/src/corelib/doc/snippets/statemachine/main2.cpp +++ b/src/corelib/doc/snippets/statemachine/main2.cpp @@ -48,11 +48,11 @@ ** ****************************************************************************/ -#include +#include int main(int argv, char **args) { - QApplication app(argv, args); + QApplication app(argv, args); QStateMachine machine; @@ -66,16 +66,17 @@ int main(int argv, char **args) //![0] //![2] - s12->addTransition(quitButton, SIGNAL(clicked()), s12); + s12->addTransition(quitButton, &QPushButton::clicked, s12); //![2] //![1] QFinalState *s2 = new QFinalState(); - s1->addTransition(quitButton, SIGNAL(clicked()), s2); + s1->addTransition(quitButton, &QPushButton::clicked, s2); machine.addState(s2); machine.setInitialState(s1); - QObject::connect(&machine, SIGNAL(finished()), QApplication::instance(), SLOT(quit())); + QObject::connect(&machine, &QStateMachine::finished, + QCoreApplication::instance(), &QCoreApplication::quit); //![1] QButton *interruptButton = new QPushButton("Interrupt Button"); @@ -90,11 +91,11 @@ int main(int argv, char **args) mbox->addButton(QMessageBox::Ok); mbox->setText("Interrupted!"); mbox->setIcon(QMessageBox::Information); - QObject::connect(s3, SIGNAL(entered()), mbox, SLOT(exec())); + QObject::connect(s3, &QState::entered, mbox, &QMessageBox::exec); s3->addTransition(s1h); machine.addState(s3); - s1->addTransition(interruptButton, SIGNAL(clicked()), s3); + s1->addTransition(interruptButton, &QPushButton::clicked, s3); //![3] return app.exec(); diff --git a/src/corelib/doc/snippets/statemachine/main3.cpp b/src/corelib/doc/snippets/statemachine/main3.cpp index bc9a0e29c4..b665565aef 100644 --- a/src/corelib/doc/snippets/statemachine/main3.cpp +++ b/src/corelib/doc/snippets/statemachine/main3.cpp @@ -62,7 +62,7 @@ int main(int argv, char **args) //![0] //![1] - s1->addTransition(s1, SIGNAL(finished()), s2); + s1->addTransition(s1, &QState::finished, s2); //![1] return app.exec(); diff --git a/src/corelib/doc/snippets/statemachine/main5.cpp b/src/corelib/doc/snippets/statemachine/main5.cpp index 38bb2cb475..d701f51e2b 100644 --- a/src/corelib/doc/snippets/statemachine/main5.cpp +++ b/src/corelib/doc/snippets/statemachine/main5.cpp @@ -98,7 +98,7 @@ int main(int argv, char **args) s1->assignProperty(button, "geometry", QRectF(0, 0, 50, 50)); s2->assignProperty(button, "geometry", QRectF(0, 0, 100, 100)); - s1->addTransition(button, SIGNAL(clicked()), s2); + s1->addTransition(button, &QPushButton::clicked, s2); //![3] } @@ -111,7 +111,7 @@ int main(int argv, char **args) s1->assignProperty(button, "geometry", QRectF(0, 0, 50, 50)); s2->assignProperty(button, "geometry", QRectF(0, 0, 100, 100)); - QSignalTransition *transition = s1->addTransition(button, SIGNAL(clicked()), s2); + QSignalTransition *transition = s1->addTransition(button, &QPushButton::clicked, s2); transition->addAnimation(new QPropertyAnimation(button, "geometry")); //![4] @@ -130,9 +130,9 @@ int main(int argv, char **args) QState *s2 = new QState(); s2->assignProperty(button, "geometry", QRectF(0, 0, 50, 50)); - connect(s2, SIGNAL(entered()), messageBox, SLOT(exec())); + connect(s2, &QState::entered, messageBox, SLOT(exec())); - s1->addTransition(button, SIGNAL(clicked()), s2); + s1->addTransition(button, &QPushButton::clicked, s2); //![5] } @@ -151,10 +151,10 @@ int main(int argv, char **args) s2->assignProperty(button, "geometry", QRectF(0, 0, 50, 50)); QState *s3 = new QState(); - connect(s3, SIGNAL(entered()), messageBox, SLOT(exec())); + connect(s3, &QState::entered, messageBox, SLOT(exec())); - s1->addTransition(button, SIGNAL(clicked()), s2); - s2->addTransition(s2, SIGNAL(propertiesAssigned()), s3); + s1->addTransition(button, &QPushButton::clicked, s2); + s2->addTransition(s2, &QState::propertiesAssigned, s3); //![6] } diff --git a/src/corelib/doc/snippets/timers/analogclock.cpp b/src/corelib/doc/snippets/timers/analogclock.cpp index 4e1957a450..3edfce3235 100644 --- a/src/corelib/doc/snippets/timers/analogclock.cpp +++ b/src/corelib/doc/snippets/timers/analogclock.cpp @@ -61,7 +61,7 @@ AnalogClock::AnalogClock(QWidget *parent) //! [3] //! [4] QTimer *timer = new QTimer(this); //! [4] //! [5] - connect(timer, SIGNAL(timeout()), this, SLOT(update())); + connect(timer, &QTimer::timeout, this, QOverload<>::of(&AnalogClock::update)); //! [5] //! [6] timer->start(1000); //! [6] diff --git a/src/corelib/doc/snippets/timers/timers.cpp b/src/corelib/doc/snippets/timers/timers.cpp index 5f95899af2..eb0c82c625 100644 --- a/src/corelib/doc/snippets/timers/timers.cpp +++ b/src/corelib/doc/snippets/timers/timers.cpp @@ -61,13 +61,13 @@ Foo::Foo() //! [0] QTimer *timer = new QTimer(this); //! [0] //! [1] - connect(timer, SIGNAL(timeout()), this, SLOT(updateCaption())); + connect(timer, &QTimer::timeout, this, &Foo::updateCaption); //! [1] //! [2] timer->start(1000); //! [2] //! [3] - QTimer::singleShot(200, this, SLOT(updateCaption())); + QTimer::singleShot(200, this, &Foo::updateCaption); //! [3] { @@ -75,7 +75,7 @@ Foo::Foo() //! [4] QTimer *timer = new QTimer(this); //! [4] //! [5] - connect(timer, SIGNAL(timeout()), this, SLOT(processOneThing())); + connect(timer, &QTimer::timeout, this, &Foo::processOneThing); //! [5] //! [6] timer->start(); //! [6] diff --git a/src/corelib/doc/src/animation.qdoc b/src/corelib/doc/src/animation.qdoc index 0c1b2aed17..9cbe50d4a9 100644 --- a/src/corelib/doc/src/animation.qdoc +++ b/src/corelib/doc/src/animation.qdoc @@ -356,11 +356,11 @@ state2->assignProperty(button, "geometry", QRect(250, 250, 100, 30)); QSignalTransition *transition1 = state1->addTransition(button, - SIGNAL(clicked()), state2); + &QPushButton::clicked, state2); transition1->addAnimation(new QPropertyAnimation(button, "geometry")); QSignalTransition *transition2 = state2->addTransition(button, - SIGNAL(clicked()), state1); + &QPushButton::clicked, state1); transition2->addAnimation(new QPropertyAnimation(button, "geometry")); machine->start(); diff --git a/src/corelib/doc/src/statemachine.qdoc b/src/corelib/doc/src/statemachine.qdoc index 43c8497ef2..881a0785c6 100644 --- a/src/corelib/doc/src/statemachine.qdoc +++ b/src/corelib/doc/src/statemachine.qdoc @@ -323,12 +323,12 @@ QState *s1 = new QState(&machine); QPushButton button; - QSignalTransition *trans = new QSignalTransition(&button, SIGNAL(clicked())); + QSignalTransition *trans = new QSignalTransition(&button, &QPushButton::clicked); s1->addTransition(trans); QMessageBox msgBox; msgBox.setText("The button was clicked; carry on."); - QObject::connect(trans, SIGNAL(triggered()), &msgBox, SLOT(exec())); + QObject::connect(trans, QSignalTransition::triggered, &msgBox, &QMessageBox::exec); machine.setInitialState(s1); \endcode -- cgit v1.2.3 From 2e377f29481475e938ab5a1e5857a1d3a88fa397 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 25 Jan 2020 20:16:02 +0100 Subject: Doc/QtBase: replace some 0 with \nullptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace some 'is 0' or 'are 0' where 0 referes to a nullptr with 'is \nullptr' and 'are \nullptr' Change-Id: Ida9af2971924377efe2f49f435d79e109de2bdf4 Reviewed-by: André Hartmann Reviewed-by: Sze Howe Koh --- src/corelib/global/qglobal.cpp | 4 ++-- src/corelib/io/qbuffer.cpp | 2 +- src/corelib/io/qiodevice.cpp | 2 +- src/corelib/kernel/qmetatype.cpp | 2 +- src/corelib/serialization/qtextstream.cpp | 2 +- src/network/access/qftp.cpp | 2 +- src/network/socket/qudpsocket.cpp | 2 +- src/opengl/qglframebufferobject.cpp | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index da69628d2b..0f7ba8580e 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -702,7 +702,7 @@ Q_STATIC_ASSERT((std::is_same::value)); 64-bit integer literals in a platform-independent way. The Q_CHECK_PTR() macro prints a warning containing the source code's file name and line number, saying that the program ran out of - memory, if the pointer is 0. The qPrintable() and qUtf8Printable() + memory, if the pointer is \nullptr. The qPrintable() and qUtf8Printable() macros represent an easy way of printing text. The QT_POINTER_SIZE macro expands to the size of a pointer in bytes. @@ -3263,7 +3263,7 @@ QByteArray QSysInfo::bootUniqueId() \macro void Q_CHECK_PTR(void *pointer) \relates - If \a pointer is 0, prints a message containing the source + If \a pointer is \nullptr, prints a message containing the source code's file name and line number, saying that the program ran out of memory and aborts program execution. It throws \c std::bad_alloc instead if exceptions are enabled. diff --git a/src/corelib/io/qbuffer.cpp b/src/corelib/io/qbuffer.cpp index 8e980733de..595fcd2724 100644 --- a/src/corelib/io/qbuffer.cpp +++ b/src/corelib/io/qbuffer.cpp @@ -227,7 +227,7 @@ QBuffer::~QBuffer() \snippet buffer/buffer.cpp 4 - If \a byteArray is 0, the buffer creates its own internal + If \a byteArray is \nullptr, the buffer creates its own internal QByteArray to work on. This byte array is initially empty. \sa buffer(), setData(), open() diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index b89cab5e3c..f7a86c25cd 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -1829,7 +1829,7 @@ QByteArray QIODevicePrivate::peek(qint64 maxSize) /*! \fn bool QIODevice::getChar(char *c) Reads one character from the device and stores it in \a c. If \a c - is 0, the character is discarded. Returns \c true on success; + is \nullptr, the character is discarded. Returns \c true on success; otherwise returns \c false. \sa read(), putChar(), ungetChar() diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 46900be1a4..a2b7fec5cd 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -457,7 +457,7 @@ struct DefinedTypesFilter { \deprecated Constructs a value of the given type which is a copy of \a copy. - The default value for \a copy is 0. + The default value for \a copy is \nullptr. Deprecated, use the static function QMetaType::create(int type, const void *copy) instead. diff --git a/src/corelib/serialization/qtextstream.cpp b/src/corelib/serialization/qtextstream.cpp index 4d92b1e0da..b8137e0abd 100644 --- a/src/corelib/serialization/qtextstream.cpp +++ b/src/corelib/serialization/qtextstream.cpp @@ -1681,7 +1681,7 @@ QString QTextStream::readLine(qint64 maxlen) \since 5.5 Reads one line of text from the stream into \a line. - If \a line is 0, the read line is not stored. + If \a line is \nullptr, the read line is not stored. The maximum allowed line length is set to \a maxlen. If the stream contains lines longer than this, then the lines will be diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp index 62ae1adbd9..66dd3f9371 100644 --- a/src/network/access/qftp.cpp +++ b/src/network/access/qftp.cpp @@ -1820,7 +1820,7 @@ int QFtp::cd(const QString &dir) \internal Downloads the file \a file from the server. - If \a dev is 0, then the readyRead() signal is emitted when there + If \a dev is \nullptr, then the readyRead() signal is emitted when there is data available to read. You can then read the data with the read() or readAll() functions. diff --git a/src/network/socket/qudpsocket.cpp b/src/network/socket/qudpsocket.cpp index 0e3d516535..9694dfa507 100644 --- a/src/network/socket/qudpsocket.cpp +++ b/src/network/socket/qudpsocket.cpp @@ -479,7 +479,7 @@ QNetworkDatagram QUdpSocket::receiveDatagram(qint64 maxSize) /*! Receives a datagram no larger than \a maxSize bytes and stores it in \a data. The sender's host address and port is stored in - *\a address and *\a port (unless the pointers are 0). + *\a address and *\a port (unless the pointers are \nullptr). Returns the size of the datagram on success; otherwise returns -1. diff --git a/src/opengl/qglframebufferobject.cpp b/src/opengl/qglframebufferobject.cpp index d0f82a85fa..362b3ef189 100644 --- a/src/opengl/qglframebufferobject.cpp +++ b/src/opengl/qglframebufferobject.cpp @@ -1395,7 +1395,7 @@ bool QGLFramebufferObject::hasOpenGLFramebufferBlit() Blits from the \a sourceRect rectangle in the \a source framebuffer object to the \a targetRect rectangle in the \a target framebuffer object. - If \a source or \a target is 0, the default framebuffer will be used + If \a source or \a target is \nullptr, the default framebuffer will be used instead of a framebuffer object as source or target respectively. The \a buffers parameter should be a mask consisting of any combination of -- cgit v1.2.3 From ea4b837fa169c21afb79488b669d30bca2fcb94f Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 25 Jan 2020 20:15:19 +0100 Subject: Doc/QtGui: replace some 0 with \nullptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace some 'is 0' or 'are 0' where 0 referes to a nullptr with 'is \nullptr' and 'are \nullptr' Change-Id: Ic18d0c8bcf64159b4c8fae8c9499839954a98884 Reviewed-by: André Hartmann Reviewed-by: Sze Howe Koh --- src/gui/accessible/qaccessible.cpp | 2 +- src/gui/image/qimage.cpp | 4 ++-- src/gui/image/qpixmap.cpp | 4 ++-- src/gui/kernel/qevent.cpp | 2 +- src/gui/kernel/qopenglcontext.cpp | 2 +- src/gui/text/qfontmetrics.cpp | 4 ++-- src/gui/text/qtextlayout.cpp | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/gui/accessible/qaccessible.cpp b/src/gui/accessible/qaccessible.cpp index 7922d6fb06..a789e65284 100644 --- a/src/gui/accessible/qaccessible.cpp +++ b/src/gui/accessible/qaccessible.cpp @@ -2029,7 +2029,7 @@ QAccessibleTextInterface::~QAccessibleTextInterface() \fn void QAccessibleTextInterface::selection(int selectionIndex, int *startOffset, int *endOffset) const Returns a selection. The size of the selection is returned in \a startOffset and \a endOffset. - If there is no selection both \a startOffset and \a endOffset are 0. + If there is no selection both \a startOffset and \a endOffset are \nullptr. The accessibility APIs support multiple selections. For most widgets though, only one selection is supported with \a selectionIndex equal to 0. diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 62d2d0e948..23facb8517 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -4058,7 +4058,7 @@ void QImage::setText(const QString &key, const QString &value) \obsolete Returns the text recorded for the given \a key in the given \a - language, or in a default language if \a language is 0. + language, or in a default language if \a language is \nullptr. Use text() instead. @@ -4085,7 +4085,7 @@ void QImage::setText(const QString &key, const QString &value) Sets the image text to the given \a text and associate it with the given \a key. The text is recorded in the specified \a language, - or in a default language if \a language is 0. + or in a default language if \a language is \nullptr. Use setText() instead. diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index e914d7697f..adadba2057 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -813,8 +813,8 @@ bool QPixmap::loadFromData(const uchar *buf, uint len, const char *format, Qt::I 0 to obtain small compressed files, 100 for large uncompressed files, and -1 to use the default settings. - If \a format is 0, an image format will be chosen from \a fileName's - suffix. + If \a format is \nullptr, an image format will be chosen from + \a fileName's suffix. \sa {QPixmap#Reading and Writing Image Files}{Reading and Writing Image Files} diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index da77290c30..04970a942b 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3366,7 +3366,7 @@ QWhatsThisClickedEvent::~QWhatsThisClickedEvent() \a action is the action that is changed, added, or removed. If \a type is ActionAdded, the action is to be inserted before the - action \a before. If \a before is 0, the action is appended. + action \a before. If \a before is \nullptr, the action is appended. */ QActionEvent::QActionEvent(int type, QAction *action, QAction *before) : QEvent(static_cast(type)), act(action), bef(before) diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index 124b39f2a9..ac5e279a79 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -941,7 +941,7 @@ GLuint QOpenGLContext::defaultFramebufferObject() const The latter may happen if the surface is not exposed, or the graphics hardware is not available due to e.g. the application being suspended. - If \a surface is 0 this is equivalent to calling doneCurrent(). + If \a surface is \nullptr this is equivalent to calling doneCurrent(). Avoid calling this function from a different thread than the one the QOpenGLContext instance lives in. If you wish to use QOpenGLContext from a diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp index de9cae0c91..73fcc4bc78 100644 --- a/src/gui/text/qfontmetrics.cpp +++ b/src/gui/text/qfontmetrics.cpp @@ -161,7 +161,7 @@ QFontMetrics::QFontMetrics(const QFont &font) Constructs a font metrics object for \a font and \a paintdevice. The font metrics will be compatible with the paintdevice passed. - If the \a paintdevice is 0, the metrics will be screen-compatible, + If the \a paintdevice is \nullptr, the metrics will be screen-compatible, ie. the metrics you get if you use the font for drawing text on a \l{QWidget}{widgets} or \l{QPixmap}{pixmaps}, not on a QPicture or QPrinter. @@ -1154,7 +1154,7 @@ QFontMetricsF::QFontMetricsF(const QFont &font) Constructs a font metrics object for \a font and \a paintdevice. The font metrics will be compatible with the paintdevice passed. - If the \a paintdevice is 0, the metrics will be screen-compatible, + If the \a paintdevice is \nullptr, the metrics will be screen-compatible, ie. the metrics you get if you use the font for drawing text on a \l{QWidget}{widgets} or \l{QPixmap}{pixmaps}, not on a QPicture or QPrinter. diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index fc256d72f3..02c42eaf03 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -350,7 +350,7 @@ QTextLayout::QTextLayout(const QString& text) \a font. All the metric and layout calculations will be done in terms of - the paint device, \a paintdevice. If \a paintdevice is 0 the + the paint device, \a paintdevice. If \a paintdevice is \nullptr the calculations will be done in screen metrics. */ -- cgit v1.2.3 From a4363030bf4efd8ed4d6cd99323a14231189e0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 24 Jan 2020 12:21:46 +0100 Subject: QMultiMap: Add unite documentation I missed copying over the documentation from QMap::unite when deprecating it. Amends 4ec6748c6a30f74e6d8fbb90fc118b306d1fa690 Change-Id: I118382c4645bdc679a378e02a462d104b9af9aad Reviewed-by: Paul Wicking --- src/corelib/tools/qmap.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index a51e59b2b8..e2b7705b55 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -1203,7 +1203,7 @@ void QMapDataBase::freeData(QMapDataBase *d) key is common to both maps, the resulting map will contain the key multiple times. - \sa QMap::unite() + \sa QMultiMap::unite() */ /*! \typedef QMap::Iterator @@ -2128,4 +2128,11 @@ void QMapDataBase::freeData(QMapDataBase *d) once in the returned list. */ +/*! \fn template QMultiMap &QMultiMap::unite(const QMultiMap &other) + + Inserts all the items in the \a other map into this map. If a + key is common to both maps, the resulting map will contain the + key multiple times. +*/ + QT_END_NAMESPACE -- cgit v1.2.3 From 582311d1224cb196d8149bdfd8f178d5239c6b28 Mon Sep 17 00:00:00 2001 From: Sze Howe Koh Date: Mon, 27 Jan 2020 17:11:51 +0800 Subject: Doc: Replace some usages of 0/zero/null with \nullptr Change-Id: Ibe7de11fc6fc41477c35e7d653c6a911855deabb Reviewed-by: Paul Wicking --- examples/sql/doc/src/drilldown.qdoc | 2 +- src/corelib/kernel/qabstracteventdispatcher.cpp | 2 +- src/corelib/kernel/qmetaobject.cpp | 4 ++-- src/corelib/thread/qmutex.cpp | 2 +- src/gui/image/qimage.cpp | 6 +++--- src/gui/rhi/qrhi.cpp | 4 ++-- src/widgets/styles/qproxystyle.cpp | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/sql/doc/src/drilldown.qdoc b/examples/sql/doc/src/drilldown.qdoc index 7a8aa2037a..8beb515a83 100644 --- a/examples/sql/doc/src/drilldown.qdoc +++ b/examples/sql/doc/src/drilldown.qdoc @@ -425,7 +425,7 @@ The \c findWindow() function simply searches through the list of existing windows, returning a pointer to the window that matches - the given item ID, or 0 if the window doesn't exists. + the given item ID, or \nullptr if the window doesn't exists. Finally, let's take a quick look at our custom \c ImageItem class: diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp index 7215b3f2bd..685a0c595a 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.cpp +++ b/src/corelib/kernel/qabstracteventdispatcher.cpp @@ -160,7 +160,7 @@ QAbstractEventDispatcher::~QAbstractEventDispatcher() /*! Returns a pointer to the event dispatcher object for the specified - \a thread. If \a thread is zero, the current thread is used. If no + \a thread. If \a thread is \nullptr, the current thread is used. If no event dispatcher exists for the specified thread, this function returns \nullptr. diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 37f5acc5c5..1661520b78 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -599,7 +599,7 @@ static bool methodMatch(const QMetaObject *m, int handle, * \internal * helper function for indexOf{Method,Slot,Signal}, returns the relative index of the method within * the baseObject -* \a MethodType might be MethodSignal or MethodSlot, or 0 to match everything. +* \a MethodType might be MethodSignal or MethodSlot, or \nullptr to match everything. */ template static inline int indexOfMethodRelative(const QMetaObject **baseObject, @@ -731,7 +731,7 @@ int QMetaObject::indexOfSignal(const char *signal) const \internal Same as QMetaObject::indexOfSignal, but the result is the local offset to the base object. - \a baseObject will be adjusted to the enclosing QMetaObject, or 0 if the signal is not found + \a baseObject will be adjusted to the enclosing QMetaObject, or \nullptr if the signal is not found */ int QMetaObjectPrivate::indexOfSignalRelative(const QMetaObject **baseObject, const QByteArray &name, int argc, diff --git a/src/corelib/thread/qmutex.cpp b/src/corelib/thread/qmutex.cpp index f3883278e3..0508932d68 100644 --- a/src/corelib/thread/qmutex.cpp +++ b/src/corelib/thread/qmutex.cpp @@ -487,7 +487,7 @@ QRecursiveMutex::~QRecursiveMutex() \fn QMutexLocker::QMutexLocker(QMutex *mutex) Constructs a QMutexLocker and locks \a mutex. The mutex will be - unlocked when the QMutexLocker is destroyed. If \a mutex is zero, + unlocked when the QMutexLocker is destroyed. If \a mutex is \nullptr, QMutexLocker does nothing. \sa QMutex::lock() diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 23facb8517..1166eb5023 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -3683,8 +3683,8 @@ QImage QImage::fromData(const uchar *data, int size, const char *format) /*! Saves the image to the file with the given \a fileName, using the given image file \a format and \a quality factor. If \a format is - 0, QImage will attempt to guess the format by looking at \a fileName's - suffix. + \nullptr, QImage will attempt to guess the format by looking at + \a fileName's suffix. The \a quality factor must be in the range 0 to 100 or -1. Specify 0 to obtain small compressed files, 100 for large uncompressed @@ -4099,7 +4099,7 @@ void QImage::setText(const QString &key, const QString &value) \l{http://www.libpng.org/pub/png/spec/1.2/png-1.2-pdg.html#C.Anc-text} {the PNG specification}. \a s can be any text. \a lang should specify the language code (see - \l{http://www.rfc-editor.org/rfc/rfc1766.txt}{RFC 1766}) or 0. + \l{http://www.rfc-editor.org/rfc/rfc1766.txt}{RFC 1766}) or \nullptr. \endomit */ diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index d2c8ae104e..a9c6835687 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -2361,7 +2361,7 @@ QRhiResource::Type QRhiRenderPassDescriptor::resourceType() const /*! \return a pointer to a backend-specific QRhiNativeHandles subclass, such as - QRhiVulkanRenderPassNativeHandles. The returned value is null when exposing + QRhiVulkanRenderPassNativeHandles. The returned value is \nullptr when exposing the underlying native resources is not supported by the backend. \sa QRhiVulkanRenderPassNativeHandles @@ -4933,7 +4933,7 @@ void QRhiCommandBuffer::dispatch(int x, int y, int z) /*! \return a pointer to a backend-specific QRhiNativeHandles subclass, such as - QRhiVulkanCommandBufferNativeHandles. The returned value is null when + QRhiVulkanCommandBufferNativeHandles. The returned value is \nullptr when exposing the underlying native resources is not supported by, or not applicable to, the backend. diff --git a/src/widgets/styles/qproxystyle.cpp b/src/widgets/styles/qproxystyle.cpp index 0cc235bc84..ecad637957 100644 --- a/src/widgets/styles/qproxystyle.cpp +++ b/src/widgets/styles/qproxystyle.cpp @@ -162,7 +162,7 @@ QStyle *QProxyStyle::baseStyle() const Ownership of \a style is transferred to QProxyStyle. - If style is zero, a desktop-dependant style will be + If style is \nullptr, a desktop-dependent style will be assigned automatically. */ void QProxyStyle::setBaseStyle(QStyle *style) -- cgit v1.2.3 From e44de91a2cab6e3c4632523e644fadaa93b89364 Mon Sep 17 00:00:00 2001 From: Sze Howe Koh Date: Sun, 26 Jan 2020 16:39:05 +0800 Subject: Doc: Clarify usage of Qt::ReturnByValue in QCursor Change-Id: I6ce2c658dc0e72beb9e7a2497c6dbdbc71d96bc5 Reviewed-by: Paul Wicking --- src/corelib/global/qnamespace.qdoc | 2 ++ src/gui/kernel/qcursor.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index 169c296bcd..29b58783d5 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -3326,6 +3326,8 @@ This is a dummy type, designed to help users transition from certain deprecated APIs to their replacement APIs. + \sa QCursor::bitmap() + \sa QCursor::mask() \sa QLabel::picture() \sa QLabel::pixmap() */ diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp index 2018d28d92..7f6fdafbd0 100644 --- a/src/gui/kernel/qcursor.cpp +++ b/src/gui/kernel/qcursor.cpp @@ -614,8 +614,8 @@ const QBitmap *QCursor::mask() const QBitmap bmpVal = cursor->bitmap(Qt::ReturnByValue); \endcode - If you disable the deprecated version, then you can omit \c Qt::ReturnByValue - as shown below: + If you disable the deprecated version using the QT_DISABLE_DEPRECATED_BEFORE + macro, then you can omit \c Qt::ReturnByValue as shown below: \code QBitmap bmpVal = cursor->bitmap(); @@ -646,8 +646,8 @@ QBitmap QCursor::bitmap(Qt::ReturnByValue_t) const QBitmap bmpVal = cursor->mask(Qt::ReturnByValue); \endcode - If you disable the deprecated version, then you can omit \c Qt::ReturnByValue - as shown below: + If you disable the deprecated version using the QT_DISABLE_DEPRECATED_BEFORE + macro, then you can omit \c Qt::ReturnByValue as shown below: \code QBitmap bmpVal = cursor->mask(); -- cgit v1.2.3 From be8c257da9a264994243c120231965ff0008ef09 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 27 Jan 2020 13:19:00 +0100 Subject: QThread::setPriority() Warn about invalid parameter on all platforms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit InheritPriority may not be set, but the warning only occurs on Windows. Move the warning to the public class. Change-Id: I51d401300f840e4c1396c2c30182e49ed45d60d2 Reviewed-by: Cristian Maureira-Fredes Reviewed-by: Christian Tismer Reviewed-by: David Faure Reviewed-by: Mårten Nordheim --- src/corelib/thread/qthread.cpp | 6 +++++- src/corelib/thread/qthread_win.cpp | 2 -- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index d3bb372b00..d18056063f 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -614,7 +614,7 @@ void QThread::run() priority. The \a priority argument can be any value in the \c - QThread::Priority enum except for \c InheritPriorty. + QThread::Priority enum except for \c InheritPriority. The effect of the \a priority parameter is dependent on the operating system's scheduling policy. In particular, the \a priority @@ -626,6 +626,10 @@ void QThread::run() */ void QThread::setPriority(Priority priority) { + if (priority == QThread::InheritPriority) { + qWarning("QThread::setPriority: Argument cannot be InheritPriority"); + return; + } Q_D(QThread); QMutexLocker locker(&d->mutex); if (!d->running) { diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 3df7080caf..bc70e3178a 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -715,9 +715,7 @@ void QThreadPrivate::setPriority(QThread::Priority threadPriority) prio = THREAD_PRIORITY_TIME_CRITICAL; break; - case QThread::InheritPriority: default: - qWarning("QThread::setPriority: Argument cannot be InheritPriority"); return; } -- cgit v1.2.3