From 59a09022f3a6b773f73c21054b7a6c52434a8939 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 6 Nov 2018 09:54:45 +0100 Subject: Windows QPA: Extend the debug operator for IShellItem Output URL string and file system name, too. Task-number: QTBUG-67932 Change-Id: Ic5d1927d70d98f7c081bee06af85b9f3a2a09812 Reviewed-by: Andre de la Rocha --- src/plugins/platforms/windows/qwindowsdialoghelpers.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp index 681b35eb7c..b629cc00a3 100644 --- a/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp +++ b/src/plugins/platforms/windows/qwindowsdialoghelpers.cpp @@ -558,6 +558,10 @@ public: SFGAOF attributes() const { return m_attributes; } QString normalDisplay() const // base name, usually { return displayName(m_item, SIGDN_NORMALDISPLAY); } + QString urlString() const + { return displayName(m_item, SIGDN_URL); } + QString fileSysPath() const + { return displayName(m_item, SIGDN_FILESYSPATH); } QString desktopAbsoluteParsing() const { return displayName(m_item, SIGDN_DESKTOPABSOLUTEPARSING); } QString path() const; // Only set for 'FileSystem' (SFGAO_FILESYSTEM) items @@ -734,7 +738,8 @@ void QWindowsShellItem::format(QDebug &d) const if (canCopy()) d << " [copyable]"; d << ", normalDisplay=\"" << normalDisplay() - << "\", desktopAbsoluteParsing=\"" << desktopAbsoluteParsing() << '"'; + << "\", desktopAbsoluteParsing=\"" << desktopAbsoluteParsing() + << "\", urlString=\"" << urlString() << "\", fileSysPath=\"" << fileSysPath() << '"'; const QString pathS = path(); if (!pathS.isEmpty()) d << ", path=\"" << pathS << '"'; -- cgit v1.2.3 From fbbe8aba9d70a3c13d1cd7797eb4dbbd1f05ade5 Mon Sep 17 00:00:00 2001 From: Thomas Miller Date: Mon, 15 Oct 2018 11:20:10 -0700 Subject: Add Windows Desktop arm64 target to Qtbase Allows a qt build to be configured to target arm64 desktop apps cross platform and build them with nmake. Change-Id: I99fed12047b45a504a1644201bcc19b18c69f3e6 Reviewed-by: Oswald Buddenhagen Reviewed-by: Oliver Wolff --- mkspecs/win32-arm64-msvc2017/qmake.conf | 15 ++++++ mkspecs/win32-arm64-msvc2017/qplatformdefs.h | 40 ++++++++++++++ qmake/generators/win32/msvc_nmake.cpp | 46 +++++++++++----- src/3rdparty/angle/src/common/mathutil.h | 8 +-- src/3rdparty/angle/src/common/platform.h | 2 +- .../patches/0011-ANGLE-Fix-build-for-ARM64.patch | 63 ++++++++++++++++++++++ src/corelib/global/qprocessordetection.h | 9 ++-- 7 files changed, 162 insertions(+), 21 deletions(-) create mode 100644 mkspecs/win32-arm64-msvc2017/qmake.conf create mode 100644 mkspecs/win32-arm64-msvc2017/qplatformdefs.h create mode 100644 src/angle/patches/0011-ANGLE-Fix-build-for-ARM64.patch diff --git a/mkspecs/win32-arm64-msvc2017/qmake.conf b/mkspecs/win32-arm64-msvc2017/qmake.conf new file mode 100644 index 0000000000..ee10f9cc40 --- /dev/null +++ b/mkspecs/win32-arm64-msvc2017/qmake.conf @@ -0,0 +1,15 @@ +# +# qmake configuration for win32-arm64-msvc2017 +# +# Written for Microsoft C/C++ Optimizing Compiler targeting arm64. +# + +include(../common/msvc-desktop.conf) + +WINSDK_VER = 10.0 +VCPROJ_ARCH = ARM64 + +DEFINES += WIN64 +QMAKE_COMPILER_DEFINES += _WIN64 + +load(qt_config) diff --git a/mkspecs/win32-arm64-msvc2017/qplatformdefs.h b/mkspecs/win32-arm64-msvc2017/qplatformdefs.h new file mode 100644 index 0000000000..8a3afa7630 --- /dev/null +++ b/mkspecs/win32-arm64-msvc2017/qplatformdefs.h @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the qmake spec 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 "../win32-msvc/qplatformdefs.h" diff --git a/qmake/generators/win32/msvc_nmake.cpp b/qmake/generators/win32/msvc_nmake.cpp index f2cd7c633b..306ae57871 100644 --- a/qmake/generators/win32/msvc_nmake.cpp +++ b/qmake/generators/win32/msvc_nmake.cpp @@ -71,18 +71,28 @@ NmakeMakefileGenerator::writeMakefile(QTextStream &t) return MakefileGenerator::writeStubMakefile(t); #endif if (!project->isHostBuild()) { + const QString msvcVer = project->first("MSVC_VER").toQString(); + if (msvcVer.isEmpty()) { + fprintf(stderr, "Mkspec does not specify MSVC_VER. Cannot continue.\n"); + return false; + } + + bool winrtBuild = false; + bool crossPlatformDesktopBuild = false; + QString arch = project->first("VCPROJ_ARCH").toQString().toLower(); if (project->isActiveConfig(QStringLiteral("winrt"))) { - QString arch = project->first("VCPROJ_ARCH").toQString().toLower(); + winrtBuild = true; + + // Only add explicit support for arm64 cross-platform desktop builds. + } else if ((arch == QLatin1String("arm64")) && (msvcVer == QStringLiteral("15.0"))) { + crossPlatformDesktopBuild = true; + } + + if (winrtBuild || crossPlatformDesktopBuild) { QString compiler; QString compilerArch; - const QString msvcVer = project->first("MSVC_VER").toQString(); - if (msvcVer.isEmpty()) { - fprintf(stderr, "Mkspec does not specify MSVC_VER. Cannot continue.\n"); - return false; - } - + const ProStringList hostArch = project->values("QMAKE_TARGET.arch"); if (msvcVer == QStringLiteral("15.0")) { - const ProStringList hostArch = project->values("QMAKE_TARGET.arch"); if (hostArch.contains("x86_64")) compiler = QStringLiteral("HostX64/"); else @@ -93,6 +103,9 @@ NmakeMakefileGenerator::writeMakefile(QTextStream &t) } else if (arch == QLatin1String("x64")) { compiler += QStringLiteral("x64"); compilerArch = QStringLiteral("amd64"); + } else if (arch == QLatin1String("arm64")) { + compiler += QStringLiteral("arm64"); + compilerArch = QStringLiteral("arm64"); } else { arch = QStringLiteral("x86"); compiler += QStringLiteral("x86"); @@ -119,7 +132,7 @@ NmakeMakefileGenerator::writeMakefile(QTextStream &t) return false; } const QString targetVer = project->first("WINTARGET_VER").toQString(); - if (targetVer.isEmpty()) { + if (targetVer.isEmpty() && winrtBuild) { fprintf(stderr, "Mkspec does not specify WINTARGET_VER. Cannot continue.\n"); return false; } @@ -181,10 +194,19 @@ NmakeMakefileGenerator::writeMakefile(QTextStream &t) incDirs << crtInclude + QStringLiteral("/shared"); incDirs << crtInclude + QStringLiteral("/winrt"); - incDirs << kitDir + QStringLiteral("Extension SDKs/WindowsMobile/") - + crtVersion + QStringLiteral("/Include/WinRT"); + if (winrtBuild) { + // Only use mobile-specific headers and link against store-specific libs for + // winrt builds. + incDirs << kitDir + QStringLiteral("Extension SDKs/WindowsMobile/") + + crtVersion + QStringLiteral("/Include/WinRT"); - libDirs << toolsInstallDir + QStringLiteral("lib/") + arch + QStringLiteral("/store"); + libDirs << toolsInstallDir + QStringLiteral("lib/") + arch + QStringLiteral("/store"); + } else { + // Desktop projects may require the atl headers and libs. + incDirs << toolsInstallDir + QStringLiteral("atlmfc/include"); + libDirs << toolsInstallDir + QStringLiteral("atlmfc/lib/") + compilerArch; + libDirs << toolsInstallDir + QStringLiteral("lib/") + arch; + } libDirs << vcInstallDir + QStringLiteral("VC/Auxiliary/VS/lib/") + arch; diff --git a/src/3rdparty/angle/src/common/mathutil.h b/src/3rdparty/angle/src/common/mathutil.h index 372e432066..88aedddfe8 100644 --- a/src/3rdparty/angle/src/common/mathutil.h +++ b/src/3rdparty/angle/src/common/mathutil.h @@ -150,7 +150,7 @@ inline bool supportsSSE2() return supports; } -#if defined(ANGLE_PLATFORM_WINDOWS) && !defined(_M_ARM) +#if defined(ANGLE_PLATFORM_WINDOWS) && !defined(_M_ARM) && !defined(_M_ARM64) { int info[4]; __cpuid(info, 0); @@ -162,7 +162,7 @@ inline bool supportsSSE2() supports = (info[3] >> 26) & 1; } } -#endif // defined(ANGLE_PLATFORM_WINDOWS) && !defined(_M_ARM) +#endif // defined(ANGLE_PLATFORM_WINDOWS) && !defined(_M_ARM) && !defined(_M_ARM64) checked = true; return supports; #else // defined(ANGLE_USE_SSE) @@ -884,14 +884,14 @@ inline uint32_t BitfieldReverse(uint32_t value) // Count the 1 bits. #if defined(ANGLE_PLATFORM_WINDOWS) -#if defined(_M_ARM) +#if defined(_M_ARM) || defined(_M_ARM64) inline int BitCount(uint32_t bits) { bits = bits - ((bits >> 1) & 0x55555555); bits = (bits & 0x33333333) + ((bits >> 2) & 0x33333333); return (((bits + (bits >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24; } -#else // _M_ARM +#else // _M_ARM || _M_ARM64 inline int BitCount(uint32_t bits) { return static_cast(__popcnt(bits)); diff --git a/src/3rdparty/angle/src/common/platform.h b/src/3rdparty/angle/src/common/platform.h index 47cd57b999..fb251da579 100644 --- a/src/3rdparty/angle/src/common/platform.h +++ b/src/3rdparty/angle/src/common/platform.h @@ -83,7 +83,7 @@ # undef far #endif -#if defined(_MSC_VER) && !defined(_M_ARM) +#if defined(_MSC_VER) && !defined(_M_ARM) && !defined(_M_ARM64) #include #define ANGLE_USE_SSE #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) && !defined(__MINGW32__) diff --git a/src/angle/patches/0011-ANGLE-Fix-build-for-ARM64.patch b/src/angle/patches/0011-ANGLE-Fix-build-for-ARM64.patch new file mode 100644 index 0000000000..3a43894a8a --- /dev/null +++ b/src/angle/patches/0011-ANGLE-Fix-build-for-ARM64.patch @@ -0,0 +1,63 @@ +From 416fb93dae5009bb51da9f6720a95918a2c79e78 Mon Sep 17 00:00:00 2001 +From: Thomas Miller +Date: Tue Oct 16 08:29:58 2018 -0700 +Subject: [PATCH] ANGLE: Fix build for ARM64 + +__popcnt, SSE, and intrin.h are not available when building for ARM64. +--- + src/3rdparty/angle/src/common/mathutil.h | 8 ++++---- + src/3rdparty/angle/src/common/platform.h | 2 +- + 2 files changed, 5 insertions(+), 5 deletions(-) + +diff --git a/src/3rdparty/angle/src/common/mathutil.h b/src/3rdparty/angle/src/common/mathutil.h +index 372e432066..88aedddfe8 100644 +--- a/src/3rdparty/angle/src/common/mathutil.h ++++ b/src/3rdparty/angle/src/common/mathutil.h +@@ -150,7 +150,7 @@ inline bool supportsSSE2() + return supports; + } + +-#if defined(ANGLE_PLATFORM_WINDOWS) && !defined(_M_ARM) ++#if defined(ANGLE_PLATFORM_WINDOWS) && !defined(_M_ARM) && !defined(_M_ARM64) + { + int info[4]; + __cpuid(info, 0); +@@ -162,7 +162,7 @@ inline bool supportsSSE2() + supports = (info[3] >> 26) & 1; + } + } +-#endif // defined(ANGLE_PLATFORM_WINDOWS) && !defined(_M_ARM) ++#endif // defined(ANGLE_PLATFORM_WINDOWS) && !defined(_M_ARM) && !defined(_M_ARM64) + checked = true; + return supports; + #else // defined(ANGLE_USE_SSE) +@@ -884,14 +884,14 @@ inline uint32_t BitfieldReverse(uint32_t value) + + // Count the 1 bits. + #if defined(ANGLE_PLATFORM_WINDOWS) +-#if defined(_M_ARM) ++#if defined(_M_ARM) || defined(_M_ARM64) + inline int BitCount(uint32_t bits) + { + bits = bits - ((bits >> 1) & 0x55555555); + bits = (bits & 0x33333333) + ((bits >> 2) & 0x33333333); + return (((bits + (bits >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24; + } +-#else // _M_ARM ++#else // _M_ARM || _M_ARM64 + inline int BitCount(uint32_t bits) + { + return static_cast(__popcnt(bits)); +diff --git a/src/3rdparty/angle/src/common/platform.h b/src/3rdparty/angle/src/common/platform.h +index 47cd57b999..fb251da579 100644 +--- a/src/3rdparty/angle/src/common/platform.h ++++ b/src/3rdparty/angle/src/common/platform.h +@@ -83,7 +83,7 @@ + # undef far + #endif + +-#if defined(_MSC_VER) && !defined(_M_ARM) ++#if defined(_MSC_VER) && !defined(_M_ARM) && !defined(_M_ARM64) + #include + #define ANGLE_USE_SSE + #elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) && !defined(__MINGW32__) diff --git a/src/corelib/global/qprocessordetection.h b/src/corelib/global/qprocessordetection.h index aaa27dff4a..77b3ba36b0 100644 --- a/src/corelib/global/qprocessordetection.h +++ b/src/corelib/global/qprocessordetection.h @@ -94,8 +94,8 @@ ARM is bi-endian, detect using __ARMEL__ or __ARMEB__, falling back to auto-detection implemented below. */ -#if defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM) || defined(__aarch64__) || defined(__ARM64__) -# if defined(__aarch64__) || defined(__ARM64__) +#if defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM) || defined(_M_ARM64) || defined(__aarch64__) || defined(__ARM64__) +# if defined(__aarch64__) || defined(__ARM64__) || defined(_M_ARM64) # define Q_PROCESSOR_ARM_64 # define Q_PROCESSOR_WORDSIZE 8 # else @@ -110,7 +110,8 @@ # elif defined(__ARM64_ARCH_8__) \ || defined(__aarch64__) \ || defined(__ARMv8__) \ - || defined(__ARMv8_A__) + || defined(__ARMv8_A__) \ + || defined(_M_ARM64) # define Q_PROCESSOR_ARM 8 # elif defined(__ARM_ARCH_7__) \ || defined(__ARM_ARCH_7A__) \ @@ -148,7 +149,7 @@ # else # error "ARM architecture too old" # endif -# if defined(__ARMEL__) +# if defined(__ARMEL__) || defined(_M_ARM64) # define Q_BYTE_ORDER Q_LITTLE_ENDIAN # elif defined(__ARMEB__) # define Q_BYTE_ORDER Q_BIG_ENDIAN -- cgit v1.2.3 From 8802826de6d8a87ad6f29b98eff1eb36964c3e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Tue, 25 Sep 2018 12:20:37 +0200 Subject: Make grabWindow return pixmap with correct dpr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The devicePixelRatio on the returned pixmap should be the product of the Qt and platform scale factors. This handles the corner case of setting QT_SCALE_FACTOR on macOS with a high-dpi display. Change-Id: I3600165d47c03c4e043bcc5e375932cc3fc0c544 Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qscreen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp index 479e228e27..0ff439abea 100644 --- a/src/gui/kernel/qscreen.cpp +++ b/src/gui/kernel/qscreen.cpp @@ -748,7 +748,7 @@ QPixmap QScreen::grabWindow(WId window, int x, int y, int width, int height) QPixmap result = platformScreen->grabWindow(window, nativePos.x(), nativePos.y(), nativeSize.width(), nativeSize.height()); - result.setDevicePixelRatio(factor); + result.setDevicePixelRatio(result.devicePixelRatio() * factor); return result; } -- cgit v1.2.3 From ae5f440c3393f086a27241b69c4f9dddaf91ce73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Tue, 25 Sep 2018 12:25:10 +0200 Subject: macOS: set dpr on pixmap returned by grabWindow() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This matches the behavior of QScreen::grabWindow(), and gives the caller direct access to the scale factor. Change-Id: Ia3ed165a62eaa0f386f8b508ea6b1128ba6be604 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoascreen.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/platforms/cocoa/qcocoascreen.mm b/src/plugins/platforms/cocoa/qcocoascreen.mm index f82ef202b1..5b6b2c13be 100644 --- a/src/plugins/platforms/cocoa/qcocoascreen.mm +++ b/src/plugins/platforms/cocoa/qcocoascreen.mm @@ -466,6 +466,7 @@ QPixmap QCocoaScreen::grabWindow(WId window, int x, int y, int width, int height const qreal dpr = devicePixelRatio(); QPixmap windowPixmap(windowSize * dpr); + windowPixmap.setDevicePixelRatio(dpr); windowPixmap.fill(Qt::transparent); for (uint i = 0; i < displayCount; ++i) { -- cgit v1.2.3 From 98c789eb0fb36493254d60cddce4a1eaa6a1665b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Tue, 25 Sep 2018 12:54:09 +0200 Subject: macOS: Make QScreen::grabWindow() work again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 17b73b0d2b8 introduced a regression where the grab rect position was added to the size when bounding to the display size. This is incorrect. Change-Id: I11d7ba7f53b96badfdead190ef9ddb525ed4ba99 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoascreen.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoascreen.mm b/src/plugins/platforms/cocoa/qcocoascreen.mm index 5b6b2c13be..0d6567070e 100644 --- a/src/plugins/platforms/cocoa/qcocoascreen.mm +++ b/src/plugins/platforms/cocoa/qcocoascreen.mm @@ -474,8 +474,8 @@ QPixmap QCocoaScreen::grabWindow(WId window, int x, int y, int width, int height // Calculate the position and size of the requested area QPoint pos(qAbs(bounds.origin.x - x), qAbs(bounds.origin.y - y)); - QSize size(qMin(pos.x() + width, qRound(bounds.size.width)), - qMin(pos.y() + height, qRound(bounds.size.height))); + QSize size(qMin(width, qRound(bounds.size.width)), + qMin(height, qRound(bounds.size.height))); pos *= dpr; size *= dpr; -- cgit v1.2.3 From e72613000edc46f3f2b354a698202ac0a4a32fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 3 Oct 2018 14:14:23 +0200 Subject: wasm: skip examples by default This removes the need for specifying "-nomake examples" on the configure line. We are using static builds; building all of the examples is too space and time consuming (especially time). Change-Id: Iff23239ca7304b1d1cf734c8bf69ad3f8ef31844 Reviewed-by: Oswald Buddenhagen Reviewed-by: Lorn Potter --- config_help.txt | 3 ++- configure.json | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/config_help.txt b/config_help.txt index 5b32eb183f..44dccfb8da 100644 --- a/config_help.txt +++ b/config_help.txt @@ -213,7 +213,8 @@ Component selection: [libs and examples, also tools if not cross-building, also tests if -developer-build] -nomake ....... Exclude from the list of parts to be built. - -compile-examples .... When unset, install only the sources of examples [yes] + -compile-examples .... When unset, install only the sources of examples + [no on WebAssembly, otherwise yes] -gui ................. Build the Qt GUI module and dependencies [yes] -widgets ............. Build the Qt Widgets module and dependencies [yes] -no-dbus ............. Do not build the Qt D-Bus module diff --git a/configure.json b/configure.json index 522bd34e9b..7c79b5c582 100644 --- a/configure.json +++ b/configure.json @@ -1203,6 +1203,7 @@ }, "compile_examples": { "label": "Compile examples", + "autoDetect": "!config.wasm", "output": [ "privateConfig" ] }, "incredibuild_xge": { -- cgit v1.2.3 From f018e315fd654dcc0a22209e5a3506b4c8838e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 19 Oct 2018 12:30:16 +0200 Subject: QWidgetBackingStore: Don't flush foreign windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Foreign windows do not have Qt backingstore content, and are also not capable of accepting Qt content. Change-Id: I959c7cdc32e6f4322497e132a436ce7d610a4106 Fixes: QTBUG-71183 Reviewed-by: Tor Arne Vestbø --- src/widgets/kernel/qwidgetbackingstore.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/widgets/kernel/qwidgetbackingstore.cpp b/src/widgets/kernel/qwidgetbackingstore.cpp index b40c2d12ad..a32eb2a03b 100644 --- a/src/widgets/kernel/qwidgetbackingstore.cpp +++ b/src/widgets/kernel/qwidgetbackingstore.cpp @@ -101,6 +101,13 @@ void QWidgetBackingStore::qt_flush(QWidget *widget, const QRegion ®ion, QBack if (tlw->testAttribute(Qt::WA_DontShowOnScreen) || widget->testAttribute(Qt::WA_DontShowOnScreen)) return; + + // Foreign Windows do not have backing store content and must not be flushed + if (QWindow *widgetWindow = widget->windowHandle()) { + if (widgetWindow->type() == Qt::ForeignWindow) + return; + } + static bool fpsDebug = qEnvironmentVariableIntValue("QT_DEBUG_FPS"); if (fpsDebug) { if (!widgetBackingStore->perfFrames++) -- cgit v1.2.3 From 6f251c567c8b388d6594575c365c0e9d48bb6541 Mon Sep 17 00:00:00 2001 From: Sven Erdem Date: Tue, 9 Oct 2018 18:32:55 +0200 Subject: Use timeout error for TCP timeouts on unix When a TCP connection timed out a QAbstractSocket::NetworkError was set. To enable a more precise error handling for timeouts QAbstractSocket::SocketTimeoutError is now set instead. Separated ETIMEDOUT from other errors in nativeRead() and take over responsibility for setting the error, which was previously handled by read(). Change-Id: Iccd45bdbb3d944cd160ae50c257d3256e05b1ae5 Reviewed-by: Edward Welbourne Reviewed-by: David Faure --- src/network/socket/qnativesocketengine_unix.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/network/socket/qnativesocketengine_unix.cpp b/src/network/socket/qnativesocketengine_unix.cpp index b380b0f7d6..24c17124dc 100644 --- a/src/network/socket/qnativesocketengine_unix.cpp +++ b/src/network/socket/qnativesocketengine_unix.cpp @@ -1383,20 +1383,24 @@ qint64 QNativeSocketEnginePrivate::nativeRead(char *data, qint64 maxSize) // No data was available for reading r = -2; break; - case EBADF: - case EINVAL: - case EIO: - //error string is now set in read(), not here in nativeRead() - break; case ECONNRESET: #if defined(Q_OS_VXWORKS) case ESHUTDOWN: #endif r = 0; break; + case ETIMEDOUT: + socketError = QAbstractSocket::SocketTimeoutError; + break; default: + socketError = QAbstractSocket::NetworkError; break; } + + if (r == -1) { + hasSetSocketError = true; + socketErrorString = qt_error_string(); + } } #if defined (QNATIVESOCKETENGINE_DEBUG) -- cgit v1.2.3 From c7275f6723089b0ba5f305fe8f3b51cb6f1eb845 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Thu, 25 Oct 2018 12:21:35 +0200 Subject: Doc: fix formatting error in QLineF This is a whitespace-only change; removing a couple of newlines that broke qdoc formatting of the enum values documentation. Change-Id: Id371a4519922c71d79a11f3cda131e6683812696 Reviewed-by: Venugopal Shivashankar --- src/corelib/tools/qline.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/qline.cpp b/src/corelib/tools/qline.cpp index 9704a00b85..949f63ea15 100644 --- a/src/corelib/tools/qline.cpp +++ b/src/corelib/tools/qline.cpp @@ -387,10 +387,9 @@ QDataStream &operator>>(QDataStream &stream, QLine &line) \value UnboundedIntersection The two lines intersect, but not within the range defined by their lengths. This will be the case - if the lines are not parallel. - - intersect() will also return this value if the intersect point is - within the start and end point of only one of the lines. + if the lines are not parallel. intersect() will also return this + value if the intersect point is within the start and end point of + only one of the lines. \value BoundedIntersection The two lines intersect with each other within the start and end points of each line. -- cgit v1.2.3 From 508b9b49b9d178db959d2e2066b8d4b9f5173573 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 2 Nov 2018 11:48:55 +0100 Subject: Fix image grab when XCB is rgb-swapping The rgbSwap produces an image that fits the X-server, but not one that fits our internal image definitions, so instead return our internal image. Task-number: QTBUG-56806 Change-Id: I25aedf7279bcd86792213b11dbd07a77b49538de Reviewed-by: Gatis Paeglis --- src/plugins/platforms/xcb/qxcbbackingstore.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/plugins/platforms/xcb/qxcbbackingstore.cpp b/src/plugins/platforms/xcb/qxcbbackingstore.cpp index c8c806749f..ba9a3e68ee 100644 --- a/src/plugins/platforms/xcb/qxcbbackingstore.cpp +++ b/src/plugins/platforms/xcb/qxcbbackingstore.cpp @@ -837,6 +837,9 @@ void QXcbBackingStore::endPaint() QImage QXcbBackingStore::toImage() const { + // If the backingstore is rgbSwapped, return the internal image type here. + if (!m_rgbImage.isNull()) + return m_rgbImage; return m_image && m_image->image() ? *m_image->image() : QImage(); } -- cgit v1.2.3 From 6857cd60dd884a763af26e43863187e9157fe32c Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Tue, 6 Nov 2018 11:03:42 +0100 Subject: win32: Fix text prediction with on screen keyboard When the on-screen keyboard completes a word via text prediction, the message contains VK_PACKET as identifier for a character sequence. While each character is send, the code only contains the first character of the sequence. Hence, resolve the actual code manually in case of a sequence. This does not modify the virtual key, so that users are able to distinguish between manual and predictive input. Fixes: QTBUG-71210 Change-Id: I787f1f2d83acaf124dfbbab6c4614a1bfe7bb2eb Reviewed-by: Andre de la Rocha Reviewed-by: Friedemann Kleint --- src/plugins/platforms/windows/qwindowskeymapper.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/plugins/platforms/windows/qwindowskeymapper.cpp b/src/plugins/platforms/windows/qwindowskeymapper.cpp index 9e6101b758..96abfdb9d7 100644 --- a/src/plugins/platforms/windows/qwindowskeymapper.cpp +++ b/src/plugins/platforms/windows/qwindowskeymapper.cpp @@ -1263,6 +1263,13 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, MSG msg, } #endif // !QT_NO_SHORTCUT key_recorder.storeKey(int(msg.wParam), a, state, text); + + // QTBUG-71210 + // VK_PACKET specifies multiple characters. The system only sends the first + // character of this sequence for each. + if (msg.wParam == VK_PACKET) + code = asciiToKeycode(char(uch.cell()), state); + QWindowSystemInterface::handleExtendedKeyEvent(receiver, QEvent::KeyPress, code, modifiers, scancode, quint32(msg.wParam), nModifiers, text, false); result =true; -- cgit v1.2.3 From ee91993997161635b8288aa95d9ecf8af5ecd589 Mon Sep 17 00:00:00 2001 From: Vitaly Fanaskov Date: Thu, 8 Nov 2018 10:16:00 +0100 Subject: Change the wording for license type in the About Qt box "the GNU LGPL version 3" -> "GNU (L)GPL" because some parts of Qt are GPL v3 (Qt Charts, Qt VirtualKeyboard, etc.). Fixes: QTBUG-57697 Change-Id: Iceb88244e28b6900c5282b070468fb65b2bf52d2 Reviewed-by: Lars Knoll --- src/widgets/dialogs/qmessagebox.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 99157747dd..d8cd19ef1a 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1844,10 +1844,10 @@ void QMessageBox::aboutQt(QWidget *parent, const QString &title) "

Qt licensed under our commercial license agreement is appropriate " "for development of proprietary/commercial software where you do not " "want to share any source code with third parties or otherwise cannot " - "comply with the terms of the GNU LGPL version 3.

" - "

Qt licensed under the GNU LGPL version 3 is appropriate for the " + "comply with the terms of GNU (L)GPL.

" + "

Qt licensed under GNU (L)GPL is appropriate for the " "development of Qt applications provided you can comply with the terms " - "and conditions of the GNU LGPL version 3.

" + "and conditions of the respective licenses.

" "

Please see %2 " "for an overview of Qt licensing.

" "

Copyright (C) %1 The Qt Company Ltd and other " -- cgit v1.2.3 From 45764e07eb16fc75cc91de6772415c3da4c450fe Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 22 Oct 2018 17:31:21 +0200 Subject: Document provenance and version of sha3_keccak Task-number: QTBUG-71327 Change-Id: Iccfda0320d61e60df53ba30c12b4ffd0fc60d1ef Reviewed-by: Lars Knoll --- src/3rdparty/sha3/qt_attribution.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/3rdparty/sha3/qt_attribution.json b/src/3rdparty/sha3/qt_attribution.json index 4866be32ea..5e6e993e19 100644 --- a/src/3rdparty/sha3/qt_attribution.json +++ b/src/3rdparty/sha3/qt_attribution.json @@ -17,9 +17,11 @@ "Name": "Secure Hash Algorithm SHA-3 - Keccak", "QDocModule": "qtcore", "QtUsage": "Used in Qt Core (QCryptographicHash).", + "Files": "https://keccak.team/obsolete/KeccakReferenceAndOptimized-3.2.zip - but it's obsolete", "Files": "KeccakF-1600-32-rvk.macros KeccakF-1600-32.macros KeccakF-1600-64.macros KeccakF-1600-interface.h KeccakF-1600-opt32.c KeccakF-1600-opt64.c KeccakF-1600-unrolling.macros KeccakNISTInterface.c KeccakNISTInterface.h KeccakSponge.c KeccakSponge.h", "Description": "SHA-3, originally known as Keccak, is a cryptographic hash function.", + "Version": "3.2", "License": "Creative Commons Zero v1.0 Universal", "LicenseId": "CC0-1.0", "LicenseFile": "CC0_LICENSE", -- cgit v1.2.3 From d38f635355dded964ce14de6160fb897e5d6b40d Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 19 Oct 2018 15:33:34 +0200 Subject: Clean up and update Unicode character data 3rd-party infrastructure Document how to do an update, fix the bit-rot that had crept into main.cpp since last it was compiled, correct the qt_attribution.json to use the actual version number of UCD (its Revision number) instead of the (admittedly correlated) Unicode release number. Updated to Release 22 (which came with Unicode 11.0.0) in the process; but this doesn't change our actual qunicodetables.cpp (so is incidental). Task-number: QTBUG-71281 Change-Id: Ieb7a6e1a4d49f639993f76ff82c8f12a572db3c3 Reviewed-by: Thiago Macieira Reviewed-by: Lars Knoll --- src/corelib/tools/qt_attribution.json | 4 +++- util/unicode/README | 31 +++++++++++++++++++++++++++++++ util/unicode/main.cpp | 11 ++++------- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/corelib/tools/qt_attribution.json b/src/corelib/tools/qt_attribution.json index 5bb95c9f5b..a842d9467b 100644 --- a/src/corelib/tools/qt_attribution.json +++ b/src/corelib/tools/qt_attribution.json @@ -4,12 +4,14 @@ "Name": "Unicode Character Database (UCD)", "QDocModule": "qtcore", "QtUsage": "Qt Core uses data obtained from UCD files for working with characters and strings.", + "Files": "For update, see qtbase/util/unicode/README", "Files": "qunicodetables_p.h qunicodetables.cpp", "Description": "The Unicode Character Database (UCD) is a set of files that define the Unicode character properties and internal mappings.", "Homepage": "https://www.unicode.org/ucd/", - "Version": "10.0.0", + "Version": "Don't use the Unicode standard version; UCD has its own 'Revision' numbers", + "Version": "20", "License": "Unicode License Agreement - Data Files and Software (2016)", "LicenseId": "Unicode-DFS-2016", "LicenseFile": "UNICODE_LICENSE.txt", diff --git a/util/unicode/README b/util/unicode/README index ca34266a36..e52f26175a 100644 --- a/util/unicode/README +++ b/util/unicode/README @@ -1 +1,32 @@ Unicode is used to generate the unicode data in src/corelib/tools. + +To update: +* Find the data (UAX #44, UCD; not the XML version) at + ftp://www.unicode.org/Public/zipped/$Version/ +* Unpack the zip file; for each file in data/, replace with the new + version; find the *BreakProperty.txt in auxiliary/. (These last are + only in the zip, not in the web-space's unpacked versions.) +* If needed, add an entry to enum QChar::UnicodeVersion for the new + Unicode version +* In that case, also update main.cpp's initAgeMap and DATA_VERSION_S* + to match +* Build this project. Its binary, unicode, ignores command-line + options and assumes it is being run from this directory. When run, + it produces lots of output. Hopefully that doesn't matter. +* Assertions may trigger: if so, study code and understand what's more + complicated about this update; talk to folk named in the git logs, + maybe push a WIP to gerrit to solicit advice. Some bit-field may + need to be expanded, for example. In some cases QChar may need + additions to some of its enums. +* Build with the modified code, fix any compilation issues. +* That may have updated qtbase/src/corelib/tools/qunicodetables.cpp; + if so the update matters; be sure to commit the changes to data/ at + the same time and update tools/qt_attribution.json to match; use the + UCD Revision number, rather than the Unicode standard number, as the + Version, for all that qunicodetables.cpp uses the latter. + +The script writingSystems.sh generates a list of writing systems, +ostensibly as a the basis for updating QFontDatabase::WritingSystem +enum; however, the Release 20 output of it contains many more writing +systems than are present in that enum, suggesting it has not been run +in a very long time. Further research needed. diff --git a/util/unicode/main.cpp b/util/unicode/main.cpp index 0c3c0b2ee1..00c69de008 100644 --- a/util/unicode/main.cpp +++ b/util/unicode/main.cpp @@ -78,7 +78,6 @@ static void initAgeMap() } } - static QHash categoryMap; static void initCategoryMap() @@ -778,7 +777,6 @@ static void initScriptMap() { QChar::Script_Soyombo, "Soyombo" }, { QChar::Script_ZanabazarSquare, "ZanabazarSquare" }, - // unhandled { QChar::Script_Unknown, 0 } }; @@ -789,7 +787,6 @@ static void initScriptMap() } } - // Keep this one in sync with the code in createPropertyInfo static const char *property_string = "struct Properties {\n" @@ -2473,9 +2470,9 @@ static QByteArray createPropertyInfo() out += ", "; out += QByteArray::number( p.lowerCaseDiff ); out += ", "; - out += "#ifdef Q_OS_WASM \n" + out += "#ifdef Q_OS_WASM \n"; // " unsigned char : 0; //wasm 64 packing trick QTBUG-65259\n" - out += "#endif \n" + out += "#endif \n"; out += ", "; // " ushort upperCaseSpecial : 1;\n" // " signed short upperCaseDiff : 15;\n" @@ -2501,9 +2498,9 @@ static QByteArray createPropertyInfo() // " ushort nfQuickCheck : 8;\n" out += QByteArray::number( p.nfQuickCheck ); out += ", "; - out += "#ifdef Q_OS_WASM \n" + out += "#ifdef Q_OS_WASM \n"; // " unsigned char : 0; //wasm 64 packing trick QTBUG-65259\n" - out += "#endif \n" + out += "#endif \n"; out += ", "; // " ushort graphemeBreakClass : 5; /* 5 used */\n" // " ushort wordBreakClass : 5; /* 5 used */\n" -- cgit v1.2.3 From b26ce2f0bffc5b1fedc5935c90df62e621abd9c7 Mon Sep 17 00:00:00 2001 From: Luca Weiss Date: Sun, 23 Sep 2018 19:33:18 +0200 Subject: qdbuscpp2xml: Don't silently ignore unregistered property types Change-Id: Icf23804cc4992314785f07cdc6aaf76eeea56465 Reviewed-by: Thiago Macieira --- src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp b/src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp index 2115a14adf..738905a9a0 100644 --- a/src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp +++ b/src/tools/qdbuscpp2xml/qdbuscpp2xml.cpp @@ -212,8 +212,11 @@ static QString generateInterfaceXml(const ClassDef *mo) access |= 2; int typeId = QMetaType::type(mp.type.constData()); - if (!typeId) + if (!typeId) { + fprintf(stderr, PROGRAMNAME ": unregistered type: '%s', ignoring\n", + mp.type.constData()); continue; + } const char *signature = QDBusMetaType::typeToSignature(typeId); if (!signature) continue; -- cgit v1.2.3 From c9f375f4e3d90e1296d8159f98f003c7570f902f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Tue, 25 Sep 2018 13:37:20 +0200 Subject: Document QScreen::grabWindow high-DPI behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib32510ff30e907365e64921fda14e686a495c77c Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qscreen.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp index 0ff439abea..f208eb02be 100644 --- a/src/gui/kernel/qscreen.cpp +++ b/src/gui/kernel/qscreen.cpp @@ -701,6 +701,11 @@ void QScreenPrivate::updatePrimaryOrientation() border of the window. If \a height is negative, the function copies everything to the bottom of the window. + The offset and size arguments are specified in device independent + pixels. The returned pixmap may be larger than the requested size + when grabbing from a high-DPI screen. Call QPixmap::devicePixelRatio() + to determine if this is the case. + The window system identifier (\c WId) can be retrieved using the QWidget::winId() function. The rationale for using a window identifier and not a QWidget, is to enable grabbing of windows -- cgit v1.2.3 From 74828aa657bda447c4a3f232688819333eb422df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 8 Nov 2018 15:53:12 +0100 Subject: macOS: Disable main thread checker for Xcode test target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: If9bf63a94b8f2ca1846a502879af5bada9918cd7 Fixes: QTBUG-71636 Reviewed-by: Morten Johan Sørvig --- mkspecs/macx-xcode/default.xcscheme | 1 + 1 file changed, 1 insertion(+) diff --git a/mkspecs/macx-xcode/default.xcscheme b/mkspecs/macx-xcode/default.xcscheme index bd2cb0e565..170174ed2b 100644 --- a/mkspecs/macx-xcode/default.xcscheme +++ b/mkspecs/macx-xcode/default.xcscheme @@ -26,6 +26,7 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "NO" + disableMainThreadChecker = "YES" buildConfiguration = "Debug"> Date: Tue, 6 Nov 2018 14:16:05 +0100 Subject: macOS: Remove blacklist entries for no longer supported OS versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iae6552f1fdcf1dea07a03d3788d378af9140d1a7 Reviewed-by: Morten Johan Sørvig --- tests/auto/corelib/io/qsettings/BLACKLIST | 2 -- tests/auto/gui/kernel/qwindow/BLACKLIST | 1 - tests/auto/other/macnativeevents/BLACKLIST | 1 - tests/auto/testlib/selftests/test/BLACKLIST | 3 --- tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST | 4 ---- tests/auto/widgets/kernel/qwidget/BLACKLIST | 1 - tests/auto/widgets/widgets/qmenu/BLACKLIST | 1 - 7 files changed, 13 deletions(-) delete mode 100644 tests/auto/corelib/io/qsettings/BLACKLIST delete mode 100644 tests/auto/testlib/selftests/test/BLACKLIST diff --git a/tests/auto/corelib/io/qsettings/BLACKLIST b/tests/auto/corelib/io/qsettings/BLACKLIST deleted file mode 100644 index 36d68bd918..0000000000 --- a/tests/auto/corelib/io/qsettings/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[isWritable:native] -osx-10.11 diff --git a/tests/auto/gui/kernel/qwindow/BLACKLIST b/tests/auto/gui/kernel/qwindow/BLACKLIST index f54865b841..caf39742f6 100644 --- a/tests/auto/gui/kernel/qwindow/BLACKLIST +++ b/tests/auto/gui/kernel/qwindow/BLACKLIST @@ -26,7 +26,6 @@ osx # QTBUG-69163 android [visibility] -osx-10.11 ci osx-10.12 ci [testInputEvents] diff --git a/tests/auto/other/macnativeevents/BLACKLIST b/tests/auto/other/macnativeevents/BLACKLIST index 32e0b1d50b..2922e22d9f 100644 --- a/tests/auto/other/macnativeevents/BLACKLIST +++ b/tests/auto/other/macnativeevents/BLACKLIST @@ -32,7 +32,6 @@ osx osx # QTQAINFRA-1292 [testPushButtonPressRelease] -osx-10.11 ci osx-10.12 ci # QTQAINFRA-1292 diff --git a/tests/auto/testlib/selftests/test/BLACKLIST b/tests/auto/testlib/selftests/test/BLACKLIST deleted file mode 100644 index 2d4adf1feb..0000000000 --- a/tests/auto/testlib/selftests/test/BLACKLIST +++ /dev/null @@ -1,3 +0,0 @@ -#QTBUG-55155 -[runSubTest:maxwarnings all loggers] -osx-10.11 diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST index 0e7a1b451f..b8b427b3dd 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST @@ -1,10 +1,6 @@ -[removeItem] -# QTBUG-60754, QTest::mouseMove is not always respected, or the CI moves the cursor -osx-10.11 ci [isActive] opensuse-42.3 ci [removeFullyTransparentItem] -osx-10.11 osx-10.12 [tabFocus_sceneWithNestedFocusWidgets] opensuse diff --git a/tests/auto/widgets/kernel/qwidget/BLACKLIST b/tests/auto/widgets/kernel/qwidget/BLACKLIST index d8654e5768..1f68308bbe 100644 --- a/tests/auto/widgets/kernel/qwidget/BLACKLIST +++ b/tests/auto/widgets/kernel/qwidget/BLACKLIST @@ -32,7 +32,6 @@ osx [render_systemClip] osx [showMinimizedKeepsFocus] -osx-10.11 ci osx-10.12 ci osx-10.13 ci [maskedUpdate] diff --git a/tests/auto/widgets/widgets/qmenu/BLACKLIST b/tests/auto/widgets/widgets/qmenu/BLACKLIST index 89d12a259f..bac14ea225 100644 --- a/tests/auto/widgets/widgets/qmenu/BLACKLIST +++ b/tests/auto/widgets/widgets/qmenu/BLACKLIST @@ -1,7 +1,6 @@ [task258920_mouseBorder] osx [submenuTearOffDontClose] -osx-10.11 ci osx-10.12 ci [layoutDirection] # Fails when enabling synchronous expose events QTBUG-62092 -- cgit v1.2.3 From a6a5e81cd6a627108382270c482df8a5e7939f7d Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 9 Nov 2018 09:36:12 +0100 Subject: Fix a typo in the docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I0f1b015a34b8caffa3b60927cedbccf7db50b383 Reviewed-by: Topi Reiniö --- src/gui/text/qtextdocument.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 6ca4bc8209..008f695da0 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -1912,7 +1912,7 @@ static void printPage(int index, QPainter *painter, const QTextDocument *doc, co } /*! - Prints the document to the given \a printer. The QPageablePaintDevice must be + Prints the document to the given \a printer. The QPagedPaintDevice must be set up before being used with this function. This is only a convenience method to print the whole document to the printer. -- cgit v1.2.3 From 75818581488c88454cf69e6326f5172734592729 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 25 Sep 2018 15:40:48 +0200 Subject: Make QThreadPool::waitForDone more atomic Avoid having the reset in waitForDone interfere with other uses of the thread-pool by locking the mutex higher, and maintaining the state so the queues doesn't have threads not in allThreads. Task-number: QTBUG-62865 Change-Id: I17ee95d5f0e138ec15e785c6d61bb0fe064d3659 Reviewed-by: Edward Welbourne --- src/corelib/thread/qthreadpool.cpp | 79 +++++++++++++++++++------------------- src/corelib/thread/qthreadpool_p.h | 6 ++- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp index ea2c611082..4d2389f699 100644 --- a/src/corelib/thread/qthreadpool.cpp +++ b/src/corelib/thread/qthreadpool.cpp @@ -39,7 +39,7 @@ #include "qthreadpool.h" #include "qthreadpool_p.h" -#include "qelapsedtimer.h" +#include "qdeadlinetimer.h" #include @@ -130,11 +130,6 @@ void QThreadPoolThread::run() } } while (true); - if (manager->isExiting) { - registerThreadInactive(); - break; - } - // if too many threads are active, expire this thread bool expired = manager->tooManyThreadsActive(); if (!expired) { @@ -145,6 +140,10 @@ void QThreadPoolThread::run() ++manager->activeThreads; if (manager->waitingThreads.removeOne(this)) expired = true; + if (!manager->allThreads.contains(this)) { + registerThreadInactive(); + break; + } } if (expired) { manager->expiredThreads.enqueue(this); @@ -267,7 +266,7 @@ void QThreadPoolPrivate::startThread(QRunnable *runnable) QScopedPointer thread(new QThreadPoolThread(this)); thread->setObjectName(QLatin1String("Thread (pooled)")); Q_ASSERT(!allThreads.contains(thread.data())); // if this assert hits, we have an ABA problem (deleted threads don't get removed here) - allThreads.append(thread.data()); + allThreads.insert(thread.data()); ++activeThreads; if (runnable->autoDelete()) @@ -278,49 +277,54 @@ void QThreadPoolPrivate::startThread(QRunnable *runnable) /*! \internal - Makes all threads exit, waits for each thread to exit and deletes it. + + Helper function only to be called from waitForDone(int) */ void QThreadPoolPrivate::reset() { - QMutexLocker locker(&mutex); - isExiting = true; - - while (!allThreads.empty()) { - // move the contents of the set out so that we can iterate without the lock - QList allThreadsCopy; - allThreadsCopy.swap(allThreads); - locker.unlock(); + // move the contents of the set out so that we can iterate without the lock + QSet allThreadsCopy; + allThreadsCopy.swap(allThreads); + expiredThreads.clear(); + waitingThreads.clear(); + mutex.unlock(); - for (QThreadPoolThread *thread : qAsConst(allThreadsCopy)) { + for (QThreadPoolThread *thread: qAsConst(allThreadsCopy)) { + if (!thread->isFinished()) { thread->runnableReady.wakeAll(); thread->wait(); - delete thread; } - - locker.relock(); - // repeat until all newly arrived threads have also completed + delete thread; } - waitingThreads.clear(); - expiredThreads.clear(); + mutex.lock(); +} + +/*! + \internal - isExiting = false; + Helper function only to be called from waitForDone(int) +*/ +bool QThreadPoolPrivate::waitForDone(const QDeadlineTimer &timer) +{ + while (!(queue.isEmpty() && activeThreads == 0) && !timer.hasExpired()) + noActiveThreads.wait(&mutex, timer); + + return queue.isEmpty() && activeThreads == 0; } bool QThreadPoolPrivate::waitForDone(int msecs) { QMutexLocker locker(&mutex); - if (msecs < 0) { - while (!(queue.isEmpty() && activeThreads == 0)) - noActiveThreads.wait(locker.mutex()); - } else { - QElapsedTimer timer; - timer.start(); - int t; - while (!(queue.isEmpty() && activeThreads == 0) && - ((t = msecs - timer.elapsed()) > 0)) - noActiveThreads.wait(locker.mutex(), t); - } + QDeadlineTimer timer(msecs); + do { + if (!waitForDone(timer)) + return false; + reset(); + // More threads can be started during reset(), in that case continue + // waiting if we still have time left. + } while ((!queue.isEmpty() || activeThreads) && !timer.hasExpired()); + return queue.isEmpty() && activeThreads == 0; } @@ -686,10 +690,7 @@ void QThreadPool::releaseThread() bool QThreadPool::waitForDone(int msecs) { Q_D(QThreadPool); - bool rc = d->waitForDone(msecs); - if (rc) - d->reset(); - return rc; + return d->waitForDone(msecs); } /*! diff --git a/src/corelib/thread/qthreadpool_p.h b/src/corelib/thread/qthreadpool_p.h index 0e6a00d243..952e02ef20 100644 --- a/src/corelib/thread/qthreadpool_p.h +++ b/src/corelib/thread/qthreadpool_p.h @@ -63,6 +63,8 @@ QT_REQUIRE_CONFIG(thread); QT_BEGIN_NAMESPACE +class QDeadlineTimer; + class QueuePage { public: enum { @@ -163,12 +165,13 @@ public: void startThread(QRunnable *runnable = 0); void reset(); bool waitForDone(int msecs); + bool waitForDone(const QDeadlineTimer &timer); void clear(); void stealAndRunRunnable(QRunnable *runnable); void deletePageIfFinished(QueuePage *page); mutable QMutex mutex; - QList allThreads; + QSet allThreads; QQueue waitingThreads; QQueue expiredThreads; QVector queue; @@ -179,7 +182,6 @@ public: int reservedThreads = 0; int activeThreads = 0; uint stackSize = 0; - bool isExiting = false; }; QT_END_NAMESPACE -- cgit v1.2.3 From 49bbc9df99e1927b6e377054add05599587f88d3 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Fri, 9 Nov 2018 14:23:23 +0100 Subject: QMacStyle: remove weird frame translation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Numbers look completely out of thin air, and while I trust it was not an error back then it was introduced, today we end up with QComboBox vertically translated and thus misaligned. Task-number: QTBUG-69908 Change-Id: I784e06f00e4c92c4af67e9bd885b86648183f2e0 Reviewed-by: Morten Johan Sørvig --- src/plugins/styles/mac/qmacstyle_mac.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 0204bd6104..1fd3420899 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -1512,7 +1512,7 @@ QRectF QMacStylePrivate::CocoaControl::adjustedControlFrame(const QRectF &rect) frameRect = frameRect.translated(rect.topLeft()); if (type == QMacStylePrivate::Button_PullDown || type == QMacStylePrivate::Button_PopupButton) { if (size == QStyleHelper::SizeLarge) - frameRect = frameRect.adjusted(0, 0, -6, 0).translated(3, -1); + frameRect = frameRect.adjusted(0, 0, -6, 0).translated(3, 0); else if (size == QStyleHelper::SizeSmall) frameRect = frameRect.adjusted(0, 0, -4, 0).translated(2, 1); else if (size == QStyleHelper::SizeMini) -- cgit v1.2.3 From 79ed504f10ba49b19fe9122ae3de4cf652130320 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 9 Nov 2018 12:59:38 +0100 Subject: Manual dialogs test: Add option to turn off the printer panel On Linux, the printer panel impacts the application startup time,which can be annoying when testing other dialogs. Change-Id: Id13446047cf50765951a6bb5182ee50cae983457 Reviewed-by: Shawn Rutledge --- tests/manual/dialogs/main.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/manual/dialogs/main.cpp b/tests/manual/dialogs/main.cpp index 83089e684c..fc4adebcc0 100644 --- a/tests/manual/dialogs/main.cpp +++ b/tests/manual/dialogs/main.cpp @@ -44,6 +44,8 @@ #include #include +static bool optNoPrinter = false; + // Test for dialogs, allowing to play with all dialog options for implementing native dialogs. // Compiles with Qt 4.8 and Qt 5. @@ -109,7 +111,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) tabWidget->addTab(new WizardPanel, tr("QWizard")); tabWidget->addTab(new MessageBoxPanel, tr("QMessageBox")); #ifndef QT_NO_PRINTER - tabWidget->addTab(new PrintDialogPanel, tr("QPrintDialog")); + if (!optNoPrinter) + tabWidget->addTab(new PrintDialogPanel, tr("QPrintDialog")); #endif setCentralWidget(tabWidget); } @@ -123,14 +126,16 @@ void MainWindow::aboutDialog() int main(int argc, char *argv[]) { -#if QT_VERSION >= 0x050700 for (int a = 1; a < argc; ++a) { if (!qstrcmp(argv[a], "-n")) { qDebug("AA_DontUseNativeDialogs"); +#if QT_VERSION >= 0x050700 QCoreApplication::setAttribute(Qt::AA_DontUseNativeDialogs); +#endif + } else if (!qstrcmp(argv[a], "-p")) { + optNoPrinter = true; // Avoid startup slowdown by printer code } } -#endif // Qt 5 QApplication a(argc, argv); MainWindow w; -- cgit v1.2.3 From ac4f075274414aac1b6cf2e8e854f0f21fee0761 Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Mon, 5 Nov 2018 15:56:47 +0100 Subject: Make sure mouse release events are delivered to correct widget The initial mouse press should create an implicit mouse grab so that all subsequent mouse events are delivered to the widget that was pressed first. After commit a4f7bb8733e0, every mouse press would reset the implicit grab. This change checks the previous button state, and does not reset the mouse grab if other buttons are already pressed. Fixes: QTBUG-70816 Change-Id: Icdd215c2f4aaee3c3f34607d68c1d8878155ec17 Reviewed-by: Shawn Rutledge --- src/widgets/kernel/qwidgetwindow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 0b2d72f330..279c6c0282 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -642,7 +642,8 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) if (!widget) widget = m_widget; - if (event->type() == QEvent::MouseButtonPress) + const bool initialPress = event->buttons() == event->button(); + if (event->type() == QEvent::MouseButtonPress && initialPress) qt_button_down = widget; QWidget *receiver = QApplicationPrivate::pickMouseReceiver(m_widget, event->windowPos().toPoint(), &mapped, event->type(), event->buttons(), -- cgit v1.2.3 From 104200d688650db02f1447f73a499784115d897d Mon Sep 17 00:00:00 2001 From: Filippo Cucchetto Date: Sun, 21 Oct 2018 10:36:17 +0200 Subject: Fix QFileSystemWatcher::removePath after move operations Foreword: - During a file or directory move the inotify id for an entity is not changed. - QFileSystemWatcher implementation uses a QMultiHash for mapping an id to its path. Suppose this filesystem hypothetical directory structure - A |--> B and user watches both A and B directories. Suppose that the B directory gets moved by calling "mv B B1". The user receives a directoryChanged event for parent directory A and scan filesystem for changes. During this scan the user notices: - a new directory B1 - a deleted directory B The user simply invoke QFileSystemWatcher::addPath(B1) and QFileSystemWatcher::removePath(B). With the actual implementation the second operation could fail: - The call QFileSystemWatcher::addPath(B1) insert a duplicated records in the QFileSystemWatcher::idToPath multihash ( {0, "A"}, {1, "A/B"} {1, "A/B1"} - The call QFileSystemWatcher::removePath(B) fails because - it first retrieves the the id for path B ---> pathToId("A/B") <-- return 1 - Then it calls idToPath.take with the id obtain in the previous step <--- idToPath.take(1) This last operation could take the record {1, "A/B1"} instead of the {1, "A/B"} (because both have the same key) meaning that the next check "x != path" evaluates to true (making the removePath function fail). This patch fixes the problem in the following way: - Use idToPath.equal_range in order to obtain all paths with the given id - Remove the correct record that match (id, path) - Prevent the removal of the inotify watch if another record with the same id is still present in the multihash (like a simple reference counting). Change-Id: I9c8480b2a869d91e500af5c4aded596b9aa53b46 Reviewed-by: Edward Welbourne --- src/corelib/io/qfilesystemwatcher_inotify.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp index 3b7135e582..a5e629b646 100644 --- a/src/corelib/io/qfilesystemwatcher_inotify.cpp +++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp @@ -330,13 +330,24 @@ QStringList QInotifyFileSystemWatcherEngine::removePaths(const QStringList &path while (it.hasNext()) { QString path = it.next(); int id = pathToID.take(path); - QString x = idToPath.take(id); - if (x.isEmpty() || x != path) + + // Multiple paths could be associated to the same watch descriptor + // when a file is moved and added with the new name. + // So we should find and delete the correct one by using + // both id and path + auto path_range = idToPath.equal_range(id); + auto path_it = std::find(path_range.first, path_range.second, path); + if (path_it == idToPath.end()) continue; - int wd = id < 0 ? -id : id; - // qDebug() << "removing watch for path" << path << "wd" << wd; - inotify_rm_watch(inotifyFd, wd); + const ssize_t num_elements = std::distance(path_range.first, path_range.second); + idToPath.erase(path_it); + + // If there was only one path associated to the given id we should remove the watch + if (num_elements == 1) { + int wd = id < 0 ? -id : id; + inotify_rm_watch(inotifyFd, wd); + } it.remove(); if (id < 0) { -- cgit v1.2.3 From 178bc49ac2b80b80f75829f3add5d7e66fd08240 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Fri, 5 Oct 2018 23:26:08 +0200 Subject: QImageWriter: improve documentation regarding use of resources QImageWriter's plugin can open devices while operating and only free them on destruction which means that if one wants to act on the file written if must first destroy the writer's instance. This patch adds the suggestion to use a scope to avoid that problem. Change-Id: I239157ea86c4a93faab237fe1860312a3c7ac7a2 Reviewed-by: Eirik Aavitsland --- src/gui/doc/snippets/qimagewriter/main.cpp | 71 ++++++++++++++++++++++++++++++ src/gui/image/qimagewriter.cpp | 10 +++++ 2 files changed, 81 insertions(+) create mode 100644 src/gui/doc/snippets/qimagewriter/main.cpp diff --git a/src/gui/doc/snippets/qimagewriter/main.cpp b/src/gui/doc/snippets/qimagewriter/main.cpp new file mode 100644 index 0000000000..3758110356 --- /dev/null +++ b/src/gui/doc/snippets/qimagewriter/main.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2018 Samuel Gaist +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + +//! [0] + QString imagePath(QStringLiteral("path/image.jpeg")); + QImage image(64, 64, QImage::Format_RGB32); + image.fill(Qt::red); + { + QImageWriter writer(imagePath); + writer.write(image); + } + + QFile::rename(imagePath, + QStringLiteral("path/other_image.jpeg")); +//! [0] + + return 0; +} diff --git a/src/gui/image/qimagewriter.cpp b/src/gui/image/qimagewriter.cpp index 5ce7e309bb..d3f9a9b881 100644 --- a/src/gui/image/qimagewriter.cpp +++ b/src/gui/image/qimagewriter.cpp @@ -71,6 +71,16 @@ formats, in addition to any image format plugins that support writing. + \note QImageWriter assumes exclusive control over the file or + device that is assigned. Any attempts to modify the assigned file + or device during the lifetime of the QImageWriter object will + yield undefined results. If immediate access to a resource is + desired, the use of a scope is the recommended method. + + For example: + + \snippet qimagewriter/main.cpp 0 + \sa QImageReader, QImageIOHandler, QImageIOPlugin */ -- cgit v1.2.3 From 1c957bb8e57adf7674716f40b67c5d6877b32f86 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Sun, 11 Nov 2018 23:44:27 +0300 Subject: Fix ambiguous definition of atime/mtime/ctime on alpha MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit One of the implementations is enabled when the stat struct has ::st_atim member, another — when it has ::st_atimensec member. On alpha, the stat struct has both members, defined as union here: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/alpha/bits/stat.h#l48 and then used here: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/alpha/bits/stat.h#l92 This commit forcefully disables the second implementation on alpha. Change-Id: Ifc284d72b68b9bac590b518f31960288df3a087d Done-with: Michael Cree Reviewed-by: Thiago Macieira --- src/corelib/io/qfilesystemengine_unix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 5a5a3a82c6..b2d81066db 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -285,7 +285,7 @@ mtime(const T &statBuffer, int) { return timespecToMSecs(statBuffer.st_mtimespec); } #endif -#ifndef st_mtimensec +#if !defined(st_mtimensec) && !defined(__alpha__) // Xtimensec template Q_DECL_UNUSED static typename std::enable_if<(&T::st_atimensec, true), qint64>::type -- cgit v1.2.3 From 8c685b765bf4ceba3c4cf8fdd9c9d680f338b7a9 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 20 Oct 2018 21:48:28 +0200 Subject: Itemviews: Cleanup examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cleanup some minor issues in the chart example: - remove unused members - use initializer list for members - pass a proper role to dataChanged() - honor roles parameter in PieView::dataChanged() - use nullptr instead 0 - use new-style connect - fix indentation and other whitespaces Change-Id: Idb212b07c006fe3ae31bee9cd9b1ba4d03043b5e Reviewed-by: André Hartmann Reviewed-by: Paul Wicking --- .../widgets/itemviews/addressbook/tablemodel.cpp | 2 +- examples/widgets/itemviews/chart/mainwindow.cpp | 18 +++---- examples/widgets/itemviews/chart/mainwindow.h | 8 ++-- examples/widgets/itemviews/chart/pieview.cpp | 56 ++++++++++------------ examples/widgets/itemviews/chart/pieview.h | 14 +++--- .../itemviews/editabletreemodel/treemodel.cpp | 2 +- .../tutorials/modelview/1_readonly/main.cpp | 8 ++-- .../tutorials/modelview/1_readonly/mymodel.cpp | 5 +- .../tutorials/modelview/1_readonly/mymodel.h | 4 +- .../tutorials/modelview/2_formatting/main.cpp | 8 ++-- .../tutorials/modelview/2_formatting/mymodel.cpp | 24 +++------- .../tutorials/modelview/2_formatting/mymodel.h | 4 +- .../tutorials/modelview/3_changingmodel/main.cpp | 6 +-- .../modelview/3_changingmodel/mymodel.cpp | 23 ++++----- .../tutorials/modelview/3_changingmodel/mymodel.h | 7 ++- .../widgets/tutorials/modelview/4_headers/main.cpp | 10 ++-- .../tutorials/modelview/4_headers/mymodel.cpp | 25 ++++------ .../tutorials/modelview/4_headers/mymodel.h | 4 +- .../widgets/tutorials/modelview/5_edit/main.cpp | 2 +- .../tutorials/modelview/5_edit/mainwindow.cpp | 14 +++--- .../tutorials/modelview/5_edit/mainwindow.h | 8 ++-- .../widgets/tutorials/modelview/5_edit/mymodel.cpp | 30 +++++------- .../widgets/tutorials/modelview/5_edit/mymodel.h | 8 ++-- .../tutorials/modelview/6_treeview/main.cpp | 2 +- .../tutorials/modelview/6_treeview/mainwindow.cpp | 23 +++++---- .../tutorials/modelview/6_treeview/mainwindow.h | 12 ++--- .../tutorials/modelview/7_selections/main.cpp | 2 +- .../modelview/7_selections/mainwindow.cpp | 18 +++---- .../tutorials/modelview/7_selections/mainwindow.h | 6 +-- 29 files changed, 161 insertions(+), 192 deletions(-) diff --git a/examples/widgets/itemviews/addressbook/tablemodel.cpp b/examples/widgets/itemviews/addressbook/tablemodel.cpp index 674e312753..b3704f857e 100644 --- a/examples/widgets/itemviews/addressbook/tablemodel.cpp +++ b/examples/widgets/itemviews/addressbook/tablemodel.cpp @@ -164,7 +164,7 @@ bool TableModel::setData(const QModelIndex &index, const QVariant &value, int ro return false; contacts.replace(row, contact); - emit(dataChanged(index, index)); + emit dataChanged(index, index, {role}); return true; } diff --git a/examples/widgets/itemviews/chart/mainwindow.cpp b/examples/widgets/itemviews/chart/mainwindow.cpp index 91e535a006..53f57fbb49 100644 --- a/examples/widgets/itemviews/chart/mainwindow.cpp +++ b/examples/widgets/itemviews/chart/mainwindow.cpp @@ -48,12 +48,13 @@ ** ****************************************************************************/ -#include - #include "pieview.h" #include "mainwindow.h" -MainWindow::MainWindow() +#include + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) { QMenu *fileMenu = new QMenu(tr("&File"), this); QAction *openAction = fileMenu->addAction(tr("&Open...")); @@ -124,17 +125,18 @@ void MainWindow::loadFile(const QString &fileName) return; QTextStream stream(&file); - QString line; model->removeRows(0, model->rowCount(QModelIndex()), QModelIndex()); int row = 0; - do { - line = stream.readLine(); + while (!stream.atEnd()) { + const QString line = stream.readLine(); if (!line.isEmpty()) { model->insertRows(row, 1, QModelIndex()); - QStringList pieces = line.split(',', QString::SkipEmptyParts); + const QStringList pieces = line.split(',', QString::SkipEmptyParts); + if (pieces.size() < 3) + continue; model->setData(model->index(row, 0, QModelIndex()), pieces.value(0)); model->setData(model->index(row, 1, QModelIndex()), @@ -143,7 +145,7 @@ void MainWindow::loadFile(const QString &fileName) QColor(pieces.value(2)), Qt::DecorationRole); row++; } - } while (!line.isEmpty()); + }; file.close(); statusBar()->showMessage(tr("Loaded %1").arg(fileName), 2000); diff --git a/examples/widgets/itemviews/chart/mainwindow.h b/examples/widgets/itemviews/chart/mainwindow.h index 058f5c7e90..51176d261b 100644 --- a/examples/widgets/itemviews/chart/mainwindow.h +++ b/examples/widgets/itemviews/chart/mainwindow.h @@ -56,7 +56,6 @@ QT_BEGIN_NAMESPACE class QAbstractItemModel; class QAbstractItemView; -class QItemSelectionModel; QT_END_NAMESPACE class MainWindow : public QMainWindow @@ -64,7 +63,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - MainWindow(); + MainWindow(QWidget *parent = nullptr); private slots: void openFile(); @@ -75,9 +74,8 @@ private: void setupViews(); void loadFile(const QString &path); - QAbstractItemModel *model; - QAbstractItemView *pieChart; - QItemSelectionModel *selectionModel; + QAbstractItemModel *model = nullptr; + QAbstractItemView *pieChart = nullptr; }; #endif // MAINWINDOW_H diff --git a/examples/widgets/itemviews/chart/pieview.cpp b/examples/widgets/itemviews/chart/pieview.cpp index 3f85e397ee..457ed8b4ec 100644 --- a/examples/widgets/itemviews/chart/pieview.cpp +++ b/examples/widgets/itemviews/chart/pieview.cpp @@ -48,30 +48,25 @@ ** ****************************************************************************/ -#include -#include -#include #include "pieview.h" +#include + PieView::PieView(QWidget *parent) : QAbstractItemView(parent) { horizontalScrollBar()->setRange(0, 0); verticalScrollBar()->setRange(0, 0); - - margin = 8; - totalSize = 300; - pieSize = totalSize - 2 * margin; - validItems = 0; - totalValue = 0.0; - rubberBand = 0; } void PieView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, - const QVector &) + const QVector &roles) { - QAbstractItemView::dataChanged(topLeft, bottomRight); + QAbstractItemView::dataChanged(topLeft, bottomRight, roles); + + if (!roles.contains(Qt::DisplayRole)) + return; validItems = 0; totalValue = 0.0; @@ -79,7 +74,7 @@ void PieView::dataChanged(const QModelIndex &topLeft, for (int row = 0; row < model()->rowCount(rootIndex()); ++row) { QModelIndex index = model()->index(row, 1, rootIndex()); - double value = model()->data(index).toDouble(); + double value = model()->data(index, Qt::DisplayRole).toDouble(); if (value > 0.0) { totalValue += value; @@ -197,15 +192,14 @@ QRect PieView::itemRect(const QModelIndex &index) const listItem++; } - double itemHeight; - switch (index.column()) { - case 0: - itemHeight = QFontMetrics(viewOptions().font).height(); + case 0: { + const qreal itemHeight = QFontMetricsF(viewOptions().font).height(); return QRect(totalSize, - int(margin + listItem*itemHeight), - totalSize - margin, int(itemHeight)); + qRound(margin + listItem * itemHeight), + totalSize - margin, qRound(itemHeight)); + } case 1: return viewport()->rect(); } @@ -235,7 +229,7 @@ QRegion PieView::itemRegion(const QModelIndex &index) const if (sliceIndex == index) { QPainterPath slicePath; slicePath.moveTo(totalSize / 2, totalSize / 2); - slicePath.arcTo(margin, margin, margin+pieSize, margin+pieSize, + slicePath.arcTo(margin, margin, margin + pieSize, margin + pieSize, startAngle, angle); slicePath.closeSubpath(); @@ -342,7 +336,7 @@ void PieView::paintEvent(QPaintEvent *event) double value = model()->data(index).toDouble(); if (value > 0.0) { - double angle = 360*value/totalValue; + double angle = 360 * value / totalValue; QModelIndex colorIndex = model()->index(row, 0, rootIndex()); QColor color = QColor(model()->data(colorIndex, Qt::DecorationRole).toString()); @@ -480,16 +474,16 @@ void PieView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlag } if (indexes.size() > 0) { - int firstRow = indexes[0].row(); - int lastRow = indexes[0].row(); - int firstColumn = indexes[0].column(); - int lastColumn = indexes[0].column(); + int firstRow = indexes.at(0).row(); + int lastRow = firstRow; + int firstColumn = indexes.at(0).column(); + int lastColumn = firstColumn; for (int i = 1; i < indexes.size(); ++i) { - firstRow = qMin(firstRow, indexes[i].row()); - lastRow = qMax(lastRow, indexes[i].row()); - firstColumn = qMin(firstColumn, indexes[i].column()); - lastColumn = qMax(lastColumn, indexes[i].column()); + firstRow = qMin(firstRow, indexes.at(i).row()); + lastRow = qMax(lastRow, indexes.at(i).row()); + firstColumn = qMin(firstColumn, indexes.at(i).column()); + lastColumn = qMax(lastColumn, indexes.at(i).column()); } QItemSelection selection( @@ -508,7 +502,7 @@ void PieView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFlag void PieView::updateGeometries() { horizontalScrollBar()->setPageStep(viewport()->width()); - horizontalScrollBar()->setRange(0, qMax(0, 2*totalSize - viewport()->width())); + horizontalScrollBar()->setRange(0, qMax(0, 2 * totalSize - viewport()->width())); verticalScrollBar()->setPageStep(viewport()->height()); verticalScrollBar()->setRange(0, qMax(0, totalSize - viewport()->height())); } @@ -546,7 +540,7 @@ QRegion PieView::visualRegionForSelection(const QItemSelection &selection) const QRegion region; for (int i = 0; i < ranges; ++i) { - QItemSelectionRange range = selection.at(i); + const QItemSelectionRange &range = selection.at(i); for (int row = range.top(); row <= range.bottom(); ++row) { for (int col = range.left(); col <= range.right(); ++col) { QModelIndex index = model()->index(row, col, rootIndex()); diff --git a/examples/widgets/itemviews/chart/pieview.h b/examples/widgets/itemviews/chart/pieview.h index aa397e6d55..22c74dde81 100644 --- a/examples/widgets/itemviews/chart/pieview.h +++ b/examples/widgets/itemviews/chart/pieview.h @@ -59,7 +59,7 @@ class PieView : public QAbstractItemView Q_OBJECT public: - PieView(QWidget *parent = 0); + PieView(QWidget *parent = nullptr); QRect visualRect(const QModelIndex &index) const override; void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override; @@ -100,13 +100,13 @@ private: int rows(const QModelIndex &index = QModelIndex()) const; void updateGeometries() override; - int margin; - int totalSize; - int pieSize; - int validItems; - double totalValue; + int margin = 0; + int totalSize = 300; + int pieSize = totalSize - 2 * margin; + int validItems = 0; + double totalValue = 0.0; + QRubberBand *rubberBand = nullptr; QPoint origin; - QRubberBand *rubberBand; }; //! [0] diff --git a/examples/widgets/itemviews/editabletreemodel/treemodel.cpp b/examples/widgets/itemviews/editabletreemodel/treemodel.cpp index dbd53df1e6..72818372d7 100644 --- a/examples/widgets/itemviews/editabletreemodel/treemodel.cpp +++ b/examples/widgets/itemviews/editabletreemodel/treemodel.cpp @@ -225,7 +225,7 @@ bool TreeModel::setData(const QModelIndex &index, const QVariant &value, int rol bool result = item->setData(index.column(), value); if (result) - emit dataChanged(index, index); + emit dataChanged(index, index, {role}); return result; } diff --git a/examples/widgets/tutorials/modelview/1_readonly/main.cpp b/examples/widgets/tutorials/modelview/1_readonly/main.cpp index 80383f8c94..ea571d3699 100644 --- a/examples/widgets/tutorials/modelview/1_readonly/main.cpp +++ b/examples/widgets/tutorials/modelview/1_readonly/main.cpp @@ -50,16 +50,16 @@ //! [Quoting ModelView Tutorial] // main.cpp -#include -#include +#include +#include #include "mymodel.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); QTableView tableView; - MyModel myModel(0); - tableView.setModel( &myModel ); + MyModel myModel; + tableView.setModel(&myModel); tableView.show(); return a.exec(); } diff --git a/examples/widgets/tutorials/modelview/1_readonly/mymodel.cpp b/examples/widgets/tutorials/modelview/1_readonly/mymodel.cpp index 82ec53c665..2b36565bc6 100644 --- a/examples/widgets/tutorials/modelview/1_readonly/mymodel.cpp +++ b/examples/widgets/tutorials/modelview/1_readonly/mymodel.cpp @@ -53,7 +53,7 @@ #include "mymodel.h" MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) + : QAbstractTableModel(parent) { } @@ -70,11 +70,10 @@ int MyModel::columnCount(const QModelIndex & /*parent*/) const QVariant MyModel::data(const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) - { return QString("Row%1, Column%2") .arg(index.row() + 1) .arg(index.column() +1); - } + return QVariant(); } //! [Quoting ModelView Tutorial] diff --git a/examples/widgets/tutorials/modelview/1_readonly/mymodel.h b/examples/widgets/tutorials/modelview/1_readonly/mymodel.h index e675cc6bc2..8761322896 100644 --- a/examples/widgets/tutorials/modelview/1_readonly/mymodel.h +++ b/examples/widgets/tutorials/modelview/1_readonly/mymodel.h @@ -59,8 +59,8 @@ class MyModel : public QAbstractTableModel { Q_OBJECT public: - MyModel(QObject *parent); - int rowCount(const QModelIndex &parent = QModelIndex()) const override ; + MyModel(QObject *parent = nullptr); + int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; }; diff --git a/examples/widgets/tutorials/modelview/2_formatting/main.cpp b/examples/widgets/tutorials/modelview/2_formatting/main.cpp index 80383f8c94..ea571d3699 100644 --- a/examples/widgets/tutorials/modelview/2_formatting/main.cpp +++ b/examples/widgets/tutorials/modelview/2_formatting/main.cpp @@ -50,16 +50,16 @@ //! [Quoting ModelView Tutorial] // main.cpp -#include -#include +#include +#include #include "mymodel.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); QTableView tableView; - MyModel myModel(0); - tableView.setModel( &myModel ); + MyModel myModel; + tableView.setModel(&myModel); tableView.show(); return a.exec(); } diff --git a/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp b/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp index 9511648392..938597a34e 100644 --- a/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp +++ b/examples/widgets/tutorials/modelview/2_formatting/mymodel.cpp @@ -48,13 +48,14 @@ ** ****************************************************************************/ +#include "mymodel.h" + #include #include -#include "mymodel.h" #include MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) + : QAbstractTableModel(parent) { } @@ -78,7 +79,7 @@ QVariant MyModel::data(const QModelIndex &index, int role) const qDebug() << QString("row %1, col%2, role %3") .arg(row).arg(col).arg(role); - switch(role){ + switch (role) { case Qt::DisplayRole: if (row == 0 && col == 1) return QString("<--left"); if (row == 1 && col == 1) return QString("right-->"); @@ -86,36 +87,25 @@ QVariant MyModel::data(const QModelIndex &index, int role) const return QString("Row%1, Column%2") .arg(row + 1) .arg(col +1); - break; case Qt::FontRole: - if (row == 0 && col == 0) //change font only for cell(0,0) - { + if (row == 0 && col == 0) { //change font only for cell(0,0) QFont boldFont; boldFont.setBold(true); return boldFont; } break; case Qt::BackgroundRole: - if (row == 1 && col == 2) //change background only for cell(1,2) - { - QBrush redBackground(Qt::red); - return redBackground; - } + return QBrush(Qt::red); break; case Qt::TextAlignmentRole: - if (row == 1 && col == 1) //change text alignment only for cell(1,1) - { return Qt::AlignRight + Qt::AlignVCenter; - } break; case Qt::CheckStateRole: - if (row == 1 && col == 0) //add a checkbox to cell(1,0) - { return Qt::Checked; - } + break; } return QVariant(); } diff --git a/examples/widgets/tutorials/modelview/2_formatting/mymodel.h b/examples/widgets/tutorials/modelview/2_formatting/mymodel.h index 9c12f98ba9..e8ae673f62 100644 --- a/examples/widgets/tutorials/modelview/2_formatting/mymodel.h +++ b/examples/widgets/tutorials/modelview/2_formatting/mymodel.h @@ -57,8 +57,8 @@ class MyModel : public QAbstractTableModel { Q_OBJECT public: - MyModel(QObject *parent); - int rowCount(const QModelIndex &parent = QModelIndex()) const override ; + MyModel(QObject *parent = nullptr); + int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; }; diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp b/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp index c03019a910..2330019f93 100644 --- a/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp +++ b/examples/widgets/tutorials/modelview/3_changingmodel/main.cpp @@ -48,8 +48,8 @@ ** ****************************************************************************/ -#include -#include +#include +#include #include "mymodel.h" int main(int argc, char *argv[]) @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); QTableView tableView; MyModel myModel(0); - tableView.setModel( &myModel ); + tableView.setModel(&myModel); tableView.show(); return a.exec(); } diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp index e4580a0e01..f289d9abda 100644 --- a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp +++ b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.cpp @@ -48,18 +48,17 @@ ** ****************************************************************************/ -#include -#include #include "mymodel.h" +#include + //! [quoting mymodel_a] MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) + : QAbstractTableModel(parent) + , timer(new QTimer(this)) { -// selectedCell = 0; - timer = new QTimer(this); timer->setInterval(1000); - connect(timer, SIGNAL(timeout()) , this, SLOT(timerHit())); + connect(timer, &QTimer::timeout , this, &MyModel::timerHit); timer->start(); } //! [quoting mymodel_a] @@ -82,13 +81,9 @@ QVariant MyModel::data(const QModelIndex &index, int role) const int row = index.row(); int col = index.column(); - if (role == Qt::DisplayRole) - { - if (row == 0 && col == 0) - { - return QTime::currentTime().toString(); - } - } + if (role == Qt::DisplayRole && row == 0 && col == 0) + return QTime::currentTime().toString(); + return QVariant(); } //! [quoting mymodel_QVariant ] @@ -99,6 +94,6 @@ void MyModel::timerHit() //we identify the top left cell QModelIndex topLeft = createIndex(0,0); //emit a signal to make the view reread identified data - emit dataChanged(topLeft, topLeft); + emit dataChanged(topLeft, topLeft, {Qt::DisplayRole}); } //! [quoting mymodel_b ] diff --git a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h index dfcf0f6239..2ef0e480c2 100644 --- a/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h +++ b/examples/widgets/tutorials/modelview/3_changingmodel/mymodel.h @@ -58,13 +58,12 @@ class MyModel : public QAbstractTableModel { Q_OBJECT public: - MyModel(QObject *parent); - int rowCount(const QModelIndex &parent = QModelIndex()) const override ; + MyModel(QObject *parent = nullptr); + int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - QTimer *timer; private: - int selectedCell; + QTimer *timer; private slots: void timerHit(); }; diff --git a/examples/widgets/tutorials/modelview/4_headers/main.cpp b/examples/widgets/tutorials/modelview/4_headers/main.cpp index 82d493345d..90a8c6e894 100644 --- a/examples/widgets/tutorials/modelview/4_headers/main.cpp +++ b/examples/widgets/tutorials/modelview/4_headers/main.cpp @@ -48,16 +48,16 @@ ** ****************************************************************************/ -#include -#include +#include +#include #include "mymodel.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); QTableView tableView; - MyModel myModel(0); - tableView.setModel( &myModel ); + MyModel myModel; + tableView.setModel(&myModel); tableView.show(); return a.exec(); -} \ No newline at end of file +} diff --git a/examples/widgets/tutorials/modelview/4_headers/mymodel.cpp b/examples/widgets/tutorials/modelview/4_headers/mymodel.cpp index 35e3463b7f..0084475374 100644 --- a/examples/widgets/tutorials/modelview/4_headers/mymodel.cpp +++ b/examples/widgets/tutorials/modelview/4_headers/mymodel.cpp @@ -51,7 +51,7 @@ #include "mymodel.h" MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) + : QAbstractTableModel(parent) { } @@ -70,8 +70,7 @@ int MyModel::columnCount(const QModelIndex & /*parent*/) const //------------------------------------------------------- QVariant MyModel::data(const QModelIndex &index, int role) const { - if (role == Qt::DisplayRole) - { + if (role == Qt::DisplayRole) { return QString("Row%1, Column%2") .arg(index.row() + 1) .arg(index.column() +1); @@ -82,18 +81,14 @@ QVariant MyModel::data(const QModelIndex &index, int role) const //! [quoting mymodel_c] QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const { - if (role == Qt::DisplayRole) - { - if (orientation == Qt::Horizontal) { - switch (section) - { - case 0: - return QString("first"); - case 1: - return QString("second"); - case 2: - return QString("third"); - } + if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { + switch (section) { + case 0: + return QString("first"); + case 1: + return QString("second"); + case 2: + return QString("third"); } } return QVariant(); diff --git a/examples/widgets/tutorials/modelview/4_headers/mymodel.h b/examples/widgets/tutorials/modelview/4_headers/mymodel.h index fb2d7aa940..6d8477dae2 100644 --- a/examples/widgets/tutorials/modelview/4_headers/mymodel.h +++ b/examples/widgets/tutorials/modelview/4_headers/mymodel.h @@ -57,8 +57,8 @@ class MyModel : public QAbstractTableModel { Q_OBJECT public: - MyModel(QObject *parent); - int rowCount(const QModelIndex &parent = QModelIndex()) const override ; + MyModel(QObject *parent = nullptr); + int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; diff --git a/examples/widgets/tutorials/modelview/5_edit/main.cpp b/examples/widgets/tutorials/modelview/5_edit/main.cpp index e1b46339b1..315875a627 100644 --- a/examples/widgets/tutorials/modelview/5_edit/main.cpp +++ b/examples/widgets/tutorials/modelview/5_edit/main.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" int main(int argc, char *argv[]) diff --git a/examples/widgets/tutorials/modelview/5_edit/mainwindow.cpp b/examples/widgets/tutorials/modelview/5_edit/mainwindow.cpp index e0b6ea7b1f..d8dfc33212 100644 --- a/examples/widgets/tutorials/modelview/5_edit/mainwindow.cpp +++ b/examples/widgets/tutorials/modelview/5_edit/mainwindow.cpp @@ -48,23 +48,25 @@ ** ****************************************************************************/ -#include #include "mainwindow.h" #include "mymodel.h" +#include + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) + , tableView(new QTableView(this)) { - tableView = new QTableView(this); setCentralWidget(tableView); - QAbstractTableModel *myModel = new MyModel(this); + MyModel *myModel = new MyModel(this); tableView->setModel(myModel); //transfer changes to the model to the window title - connect(myModel, SIGNAL(editCompleted(const QString &)), this, SLOT(setWindowTitle(const QString &))); + connect(myModel, &MyModel::editCompleted, + this, &MainWindow::showWindowTitle); } -void MainWindow::showWindowTitle(const QString & title) +void MainWindow::showWindowTitle(const QString &title) { -setWindowTitle(title); + setWindowTitle(title); } diff --git a/examples/widgets/tutorials/modelview/5_edit/mainwindow.h b/examples/widgets/tutorials/modelview/5_edit/mainwindow.h index 7915b29cdf..104f06f82e 100644 --- a/examples/widgets/tutorials/modelview/5_edit/mainwindow.h +++ b/examples/widgets/tutorials/modelview/5_edit/mainwindow.h @@ -51,9 +51,9 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include +#include -QT_BEGIN_NAMESPACE // QT_BEGIN_NAMESPACE / QT_END_NAMESPACE are not needed in Qt user code +QT_BEGIN_NAMESPACE class QTableView; //forward declaration QT_END_NAMESPACE @@ -64,9 +64,9 @@ class MainWindow : public QMainWindow private: QTableView *tableView; public: - MainWindow(QWidget *parent = 0); + MainWindow(QWidget *parent = nullptr); public slots: - void showWindowTitle(const QString & title); + void showWindowTitle(const QString &title); }; #endif // MAINWINDOW_H diff --git a/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp b/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp index fb2954baf2..eeca2ce0a0 100644 --- a/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp +++ b/examples/widgets/tutorials/modelview/5_edit/mymodel.cpp @@ -48,12 +48,10 @@ ** ****************************************************************************/ - #include "mymodel.h" - MyModel::MyModel(QObject *parent) - :QAbstractTableModel(parent) + : QAbstractTableModel(parent) { } @@ -72,33 +70,31 @@ int MyModel::columnCount(const QModelIndex & /*parent*/) const //----------------------------------------------------------------- QVariant MyModel::data(const QModelIndex &index, int role) const { - if (role == Qt::DisplayRole) - { - return m_gridData[index.row()][index.column()]; - } + if (role == Qt::DisplayRole && checkIndex(index)) + return m_gridData[index.row()][index.column()]; + return QVariant(); } //----------------------------------------------------------------- //! [quoting mymodel_e] -bool MyModel::setData(const QModelIndex & index, const QVariant & value, int role) +bool MyModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if (role == Qt::EditRole) - { + if (role == Qt::EditRole) { + if (!checkIndex(index)) + return false; //save value from editor to member m_gridData m_gridData[index.row()][index.column()] = value.toString(); //for presentation purposes only: build and emit a joined string QString result; - for (int row= 0; row < ROWS; row++) - { - for(int col= 0; col < COLS; col++) - { + for (int row = 0; row < ROWS; row++) { + for (int col= 0; col < COLS; col++) result += m_gridData[row][col] + ' '; - } } - emit editCompleted( result ); + emit editCompleted(result); + return true; } - return true; + return false; } //! [quoting mymodel_e] diff --git a/examples/widgets/tutorials/modelview/5_edit/mymodel.h b/examples/widgets/tutorials/modelview/5_edit/mymodel.h index dd0d4f5066..ce462351af 100644 --- a/examples/widgets/tutorials/modelview/5_edit/mymodel.h +++ b/examples/widgets/tutorials/modelview/5_edit/mymodel.h @@ -64,12 +64,12 @@ class MyModel : public QAbstractTableModel { Q_OBJECT public: - MyModel(QObject *parent); - int rowCount(const QModelIndex &parent = QModelIndex()) const override ; + MyModel(QObject *parent = nullptr); + int rowCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override; - Qt::ItemFlags flags(const QModelIndex & index) const override ; + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; + Qt::ItemFlags flags(const QModelIndex &index) const override; private: QString m_gridData[ROWS][COLS]; //holds text entered into QTableView signals: diff --git a/examples/widgets/tutorials/modelview/6_treeview/main.cpp b/examples/widgets/tutorials/modelview/6_treeview/main.cpp index e1b46339b1..315875a627 100644 --- a/examples/widgets/tutorials/modelview/6_treeview/main.cpp +++ b/examples/widgets/tutorials/modelview/6_treeview/main.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" int main(int argc, char *argv[]) diff --git a/examples/widgets/tutorials/modelview/6_treeview/mainwindow.cpp b/examples/widgets/tutorials/modelview/6_treeview/mainwindow.cpp index 1016afba07..ae4a343680 100644 --- a/examples/widgets/tutorials/modelview/6_treeview/mainwindow.cpp +++ b/examples/widgets/tutorials/modelview/6_treeview/mainwindow.cpp @@ -50,24 +50,25 @@ //! [Quoting ModelView Tutorial] // modelview.cpp +#include "mainwindow.h" + #include #include #include -#include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) + , treeView(new QTreeView(this)) + , standardModel(new QStandardItemModel(this)) { - treeView = new QTreeView(this); setCentralWidget(treeView); - standardModel = new QStandardItemModel ; - QList preparedRow =prepareRow("first", "second", "third"); + QList preparedRow = prepareRow("first", "second", "third"); QStandardItem *item = standardModel->invisibleRootItem(); // adding a row to the invisible root item produces a root element item->appendRow(preparedRow); - QList secondRow =prepareRow("111", "222", "333"); + QList secondRow = prepareRow("111", "222", "333"); // adding a row to an item starts a subtree preparedRow.first()->appendRow(secondRow); @@ -76,13 +77,11 @@ MainWindow::MainWindow(QWidget *parent) } QList MainWindow::prepareRow(const QString &first, - const QString &second, - const QString &third) + const QString &second, + const QString &third) const { - QList rowItems; - rowItems << new QStandardItem(first); - rowItems << new QStandardItem(second); - rowItems << new QStandardItem(third); - return rowItems; + return {new QStandardItem(first), + new QStandardItem(second), + new QStandardItem(third)}; } //! [Quoting ModelView Tutorial] diff --git a/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h b/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h index d625d5991d..65d9c18658 100644 --- a/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h +++ b/examples/widgets/tutorials/modelview/6_treeview/mainwindow.h @@ -51,9 +51,9 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include +#include -QT_BEGIN_NAMESPACE // QT_BEGIN_NAMESPACE / QT_END_NAMESPACE are not needed in Qt user code +QT_BEGIN_NAMESPACE class QTreeView; //forward declarations class QStandardItemModel; class QStandardItem; @@ -66,11 +66,11 @@ class MainWindow : public QMainWindow private: QTreeView *treeView; QStandardItemModel *standardModel; - QList prepareRow( const QString &first, - const QString &second, - const QString &third ); + QList prepareRow(const QString &first, + const QString &second, + const QString &third) const; public: - MainWindow(QWidget *parent = 0); + MainWindow(QWidget *parent = nullptr); }; #endif // MAINWINDOW_H diff --git a/examples/widgets/tutorials/modelview/7_selections/main.cpp b/examples/widgets/tutorials/modelview/7_selections/main.cpp index e1b46339b1..315875a627 100644 --- a/examples/widgets/tutorials/modelview/7_selections/main.cpp +++ b/examples/widgets/tutorials/modelview/7_selections/main.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include "mainwindow.h" int main(int argc, char *argv[]) diff --git a/examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp b/examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp index 200751ee6d..2b10071a68 100644 --- a/examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp +++ b/examples/widgets/tutorials/modelview/7_selections/mainwindow.cpp @@ -49,17 +49,18 @@ ****************************************************************************/ //! [quoting modelview_a] +#include "mainwindow.h" + #include #include #include -#include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) + , treeView(new QTreeView(this)) + , standardModel(new QStandardItemModel(this)) { - treeView = new QTreeView(this); setCentralWidget(treeView); - standardModel = new QStandardItemModel ; QStandardItem *rootNode = standardModel->invisibleRootItem(); @@ -88,9 +89,9 @@ MainWindow::MainWindow(QWidget *parent) treeView->expandAll(); //selection changes shall trigger a slot - QItemSelectionModel *selectionModel= treeView->selectionModel(); - connect(selectionModel, SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &)), - this, SLOT(selectionChangedSlot(const QItemSelection &, const QItemSelection &))); + QItemSelectionModel *selectionModel = treeView->selectionModel(); + connect(selectionModel, &QItemSelectionModel::selectionChanged, + this, &MainWindow::selectionChangedSlot); } //! [quoting modelview_a] @@ -103,10 +104,9 @@ void MainWindow::selectionChangedSlot(const QItemSelection & /*newSelection*/, c const QModelIndex index = treeView->selectionModel()->currentIndex(); QString selectedText = index.data(Qt::DisplayRole).toString(); //find out the hierarchy level of the selected item - int hierarchyLevel=1; + int hierarchyLevel = 1; QModelIndex seekRoot = index; - while(seekRoot.parent() != QModelIndex()) - { + while (seekRoot.parent() != QModelIndex()) { seekRoot = seekRoot.parent(); hierarchyLevel++; } diff --git a/examples/widgets/tutorials/modelview/7_selections/mainwindow.h b/examples/widgets/tutorials/modelview/7_selections/mainwindow.h index 13ca7dbc30..c9761dd3d9 100644 --- a/examples/widgets/tutorials/modelview/7_selections/mainwindow.h +++ b/examples/widgets/tutorials/modelview/7_selections/mainwindow.h @@ -51,9 +51,9 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include +#include -QT_BEGIN_NAMESPACE // QT_BEGIN_NAMESPACE / QT_END_NAMESPACE are not needed in Qt user code +QT_BEGIN_NAMESPACE class QTreeView; //forward declarations class QStandardItemModel; class QItemSelection; @@ -67,7 +67,7 @@ private: QTreeView *treeView; QStandardItemModel *standardModel; private slots: - void selectionChangedSlot(const QItemSelection & newSelection, const QItemSelection & oldSelection); + void selectionChangedSlot(const QItemSelection &newSelection, const QItemSelection &oldSelection); public: MainWindow(QWidget *parent = 0); }; -- cgit v1.2.3