From a65800cc687a603f72385580332ad74e5e2ff565 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 1 Apr 2019 08:02:10 +0200 Subject: [PATCH 1/9] Add a clarification about "characters" to QTextCursor docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function name QTextCursor::positionInBlock() may give users the idea that it can be displayed to the user as the visual position of the cursor in the current block. This becomes confusing with some writing systems, since e.g. a surrogate pair will count as two characters while only representing a single visual grapheme. Since it is an side effect of the encoding that will be unexpected to many, and since it also touches on some linguistic complexities, we add a note to the documentation to make users aware of the consideration needed. Task-number: QTBUG-74725 Change-Id: Iba28ba8a6ad07ee38dbb7e6a5a4b68c93d4da76a Reviewed-by: Lars Knoll Reviewed-by: Konstantin Ritt Reviewed-by: René J.V. Bertin Reviewed-by: Venugopal Shivashankar --- src/gui/text/qtextcursor.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/gui/text/qtextcursor.cpp b/src/gui/text/qtextcursor.cpp index 7719a2e6da5..c88497840ff 100644 --- a/src/gui/text/qtextcursor.cpp +++ b/src/gui/text/qtextcursor.cpp @@ -1145,6 +1145,15 @@ bool QTextCursor::isNull() const \a pos using a \c MoveMode specified by \a m. The cursor is positioned between characters. + \note The "characters" in this case refer to the string of QChar + objects, i.e. 16-bit Unicode characters, and \a pos is considered + an index into this string. This does not necessarily correspond to + individual graphemes in the writing system, as a single grapheme may + be represented by multiple Unicode characters, such as in the case + of surrogate pairs, linguistic ligatures or diacritics. For a more + generic approach to navigating the document, use movePosition(), + which will respect the actual grapheme boundaries in the text. + \sa position(), movePosition(), anchor() */ void QTextCursor::setPosition(int pos, MoveMode m) @@ -1176,6 +1185,13 @@ void QTextCursor::setPosition(int pos, MoveMode m) Returns the absolute position of the cursor within the document. The cursor is positioned between characters. + \note The "characters" in this case refer to the string of QChar + objects, i.e. 16-bit Unicode characters, and the position is considered + an index into this string. This does not necessarily correspond to + individual graphemes in the writing system, as a single grapheme may + be represented by multiple Unicode characters, such as in the case + of surrogate pairs, linguistic ligatures or diacritics. + \sa setPosition(), movePosition(), anchor(), positionInBlock() */ int QTextCursor::position() const @@ -1192,6 +1208,13 @@ int QTextCursor::position() const This is equivalent to \c{ position() - block().position()}. + \note The "characters" in this case refer to the string of QChar + objects, i.e. 16-bit Unicode characters, and the position is considered + an index into this string. This does not necessarily correspond to + individual graphemes in the writing system, as a single grapheme may + be represented by multiple Unicode characters, such as in the case + of surrogate pairs, linguistic ligatures or diacritics. + \sa position() */ int QTextCursor::positionInBlock() const From 05d9195669216038569aff7cf2901bd8e7a71ceb Mon Sep 17 00:00:00 2001 From: Venugopal Shivashankar Date: Thu, 28 Mar 2019 16:06:16 +0100 Subject: [PATCH 2/9] Doc: Use the \nullptr macro instead of 0 This enables overriding the macro so that it translates to 'None' in the Qt for Python context. Change-Id: Ib3cecf57eeb0405a1929309b71e9f012a07f11cf Reviewed-by: Christian Ehrlicher --- src/corelib/animation/qabstractanimation.cpp | 2 +- src/corelib/codecs/qtextcodec.cpp | 2 +- src/corelib/kernel/qabstracteventdispatcher.cpp | 2 +- src/corelib/kernel/qcoreapplication.cpp | 2 +- src/corelib/kernel/qmetaobject.cpp | 4 ++-- src/corelib/kernel/qobject.cpp | 2 +- src/corelib/plugin/qlibrary.cpp | 8 ++++---- src/corelib/plugin/qpluginloader.cpp | 2 +- src/corelib/thread/qthread.cpp | 2 +- src/corelib/tools/qsharedpointer.cpp | 2 +- src/widgets/doc/src/widgets-and-layouts/styles.qdoc | 2 +- src/widgets/itemviews/qtablewidget.cpp | 2 +- 12 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 9dd81b2ecd9..78b79e574a6 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -1083,7 +1083,7 @@ QAbstractAnimation::State QAbstractAnimation::state() const /*! If this animation is part of a QAnimationGroup, this function returns a - pointer to the group; otherwise, it returns 0. + pointer to the group; otherwise, it returns \nullptr. \sa QAnimationGroup::addAnimation() */ diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index 466c575c3e4..eb05446bebf 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -1244,7 +1244,7 @@ QTextCodec *QTextCodec::codecForUtfText(const QByteArray &ba) \obsolete Returns the codec used by QObject::tr() on its argument. If this - function returns 0 (the default), tr() assumes Latin-1. + function returns \nullptr (the default), tr() assumes Latin-1. */ /*! diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp index 8e1b5608747..ea08ff571f3 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.cpp +++ b/src/corelib/kernel/qabstracteventdispatcher.cpp @@ -162,7 +162,7 @@ QAbstractEventDispatcher::~QAbstractEventDispatcher() Returns a pointer to the event dispatcher object for the specified \a thread. If \a thread is zero, the current thread is used. If no event dispatcher exists for the specified thread, this function - returns 0. + returns \nullptr. \b{Note:} If Qt is built without thread support, the \a thread argument is ignored. diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index c637f0c1c93..6d7985c91bf 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -2923,7 +2923,7 @@ bool QCoreApplication::hasPendingEvents() /*! Returns a pointer to the event dispatcher object for the main thread. If no - event dispatcher exists for the thread, this function returns 0. + event dispatcher exists for the thread, this function returns \nullptr. */ QAbstractEventDispatcher *QCoreApplication::eventDispatcher() { diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 5de2717078e..b8b5c0de469 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -349,7 +349,7 @@ bool QMetaObject::inherits(const QMetaObject *metaObject) const Q_DECL_NOEXCEPT \internal Returns \a obj if object \a obj inherits from this - meta-object; otherwise returns 0. + meta-object; otherwise returns \nullptr. */ QObject *QMetaObject::cast(QObject *obj) const { @@ -361,7 +361,7 @@ QObject *QMetaObject::cast(QObject *obj) const \internal Returns \a obj if object \a obj inherits from this - meta-object; otherwise returns 0. + meta-object; otherwise returns \nullptr. */ const QObject *QMetaObject::cast(const QObject *obj) const { diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index cf838b69477..a791d2e8b3b 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -2342,7 +2342,7 @@ static void err_info_about_objects(const char * func, /*! Returns a pointer to the object that sent the signal, if called in - a slot activated by a signal; otherwise it returns 0. The pointer + a slot activated by a signal; otherwise it returns \nullptr. The pointer is valid only during the execution of the slot that calls this function from this object's thread context. diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index aa63ed1a6bb..29ef697fe87 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -999,7 +999,7 @@ void QLibrary::setFileNameAndVersion(const QString &fileName, const QString &ver /*! Returns the address of the exported symbol \a symbol. The library is - loaded if necessary. The function returns 0 if the symbol could + loaded if necessary. The function returns \nullptr if the symbol could not be resolved or if the library could not be loaded. Example: @@ -1032,7 +1032,7 @@ QFunctionPointer QLibrary::resolve(const char *symbol) include the platform-specific file suffix; (see \l{fileName}). The library remains loaded until the application exits. - The function returns 0 if the symbol could not be resolved or if + The function returns \nullptr if the symbol could not be resolved or if the library could not be loaded. \sa resolve() @@ -1052,7 +1052,7 @@ QFunctionPointer QLibrary::resolve(const QString &fileName, const char *symbol) (see \l{fileName}). The library remains loaded until the application exits. \a verNum is ignored on Windows. - The function returns 0 if the symbol could not be resolved or if + The function returns \nullptr if the symbol could not be resolved or if the library could not be loaded. \sa resolve() @@ -1073,7 +1073,7 @@ QFunctionPointer QLibrary::resolve(const QString &fileName, int verNum, const ch (see \l{fileName}). The library remains loaded until the application exits. \a version is ignored on Windows. - The function returns 0 if the symbol could not be resolved or if + The function returns \nullptr if the symbol could not be resolved or if the library could not be loaded. \sa resolve() diff --git a/src/corelib/plugin/qpluginloader.cpp b/src/corelib/plugin/qpluginloader.cpp index 0f94bb6adf8..00480198bd8 100644 --- a/src/corelib/plugin/qpluginloader.cpp +++ b/src/corelib/plugin/qpluginloader.cpp @@ -174,7 +174,7 @@ QPluginLoader::~QPluginLoader() /*! Returns the root component object of the plugin. The plugin is - loaded if necessary. The function returns 0 if the plugin could + loaded if necessary. The function returns \nullptr if the plugin could not be loaded or if the root component object could not be instantiated. diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp index b023ae9ed29..9f60de1f876 100644 --- a/src/corelib/thread/qthread.cpp +++ b/src/corelib/thread/qthread.cpp @@ -920,7 +920,7 @@ QThreadPrivate::~QThreadPrivate() \since 5.0 Returns a pointer to the event dispatcher object for the thread. If no event - dispatcher exists for the thread, this function returns 0. + dispatcher exists for the thread, this function returns \nullptr. */ QAbstractEventDispatcher *QThread::eventDispatcher() const { diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index a1caeeb1351..6ab84cf3d89 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -875,7 +875,7 @@ \b without ensuring that it cannot get deleted. To have that guarantee, use toStrongRef(), which returns a QSharedPointer object. If this function can determine that the pointer has already been deleted, it - returns 0. + returns \nullptr. It is ok to obtain the value of the pointer and using that value itself, like for example in debugging statements: diff --git a/src/widgets/doc/src/widgets-and-layouts/styles.qdoc b/src/widgets/doc/src/widgets-and-layouts/styles.qdoc index a9d95bc02ce..645da5bca2d 100644 --- a/src/widgets/doc/src/widgets-and-layouts/styles.qdoc +++ b/src/widgets/doc/src/widgets-and-layouts/styles.qdoc @@ -286,7 +286,7 @@ QStyleOption to a subclass (e.g., QStyleOptionFocusRect). For safety, you can use qstyleoption_cast() to ensure that the pointer type is correct. If the object isn't of the right type, - qstyleoption_cast() returns 0. For example: + qstyleoption_cast() returns \nullptr. For example: \snippet code/doc_src_qt4-styles.cpp 0 diff --git a/src/widgets/itemviews/qtablewidget.cpp b/src/widgets/itemviews/qtablewidget.cpp index eee3e91ac34..d576d323c3f 100644 --- a/src/widgets/itemviews/qtablewidget.cpp +++ b/src/widgets/itemviews/qtablewidget.cpp @@ -1813,7 +1813,7 @@ void QTableWidgetPrivate::_q_dataChanged(const QModelIndex &topLeft, \fn QTableWidgetItem *QTableWidget::itemAt(int ax, int ay) const Returns the item at the position equivalent to QPoint(\a{ax}, \a{ay}) in - the table widget's coordinate system, or returns 0 if the specified point + the table widget's coordinate system, or returns \nullptr if the specified point is not covered by an item in the table widget. \sa item() From e5f0fec762771733e9cbc9a29cade7533f49d802 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 18 Mar 2019 11:29:16 +0100 Subject: [PATCH 3/9] Fix disabling AUTOMOC and AUTOUIC for generated resource cpp files when using qt5_add_big_resources. The previous approach of just setting SKIP_AUTOMOC and SKIP_AUTOUIC on the generated source files is not enough because if AUTOMOC is globally enabled, AUTOMOC will still run for the rcc_object_{outfilename} target, which ends up creating a mos_compilation.cpp.o file and adding it as a target object to the target. Thus later when $ is passed to the rcc invocation, the expression evaluates to a list of two files: the rcc-related .o file and the mocs_compilation.o file. Obviously that breaks the rcc invocation. The fix is to disable AUTOMOC and AUTOUIC on the whole target, instead of just the source files. This prevents the creation of the mocs_compilation.cpp file. Fixes: QTBUG-74270 Change-Id: I51f757b110e940fe224010acb25b88c52ef612b1 Reviewed-by: Kai Koehne --- src/corelib/Qt5CoreMacros.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/Qt5CoreMacros.cmake b/src/corelib/Qt5CoreMacros.cmake index 620795d2cf5..7ae5e4fd16f 100644 --- a/src/corelib/Qt5CoreMacros.cmake +++ b/src/corelib/Qt5CoreMacros.cmake @@ -321,10 +321,10 @@ function(QT5_ADD_BIG_RESOURCES outfiles ) add_custom_command(OUTPUT ${tmpoutfile} COMMAND ${Qt5Core_RCC_EXECUTABLE} ${rcc_options} --name ${outfilename} --pass 1 --output ${tmpoutfile} ${infile} DEPENDS ${infile} ${_rc_depends} "${out_depends}" VERBATIM) - set_source_files_properties(${tmpoutfile} PROPERTIES SKIP_AUTOMOC ON) - set_source_files_properties(${tmpoutfile} PROPERTIES SKIP_AUTOUIC ON) add_custom_target(big_resources_${outfilename} ALL DEPENDS ${tmpoutfile}) add_library(rcc_object_${outfilename} OBJECT ${tmpoutfile}) + set_target_properties(rcc_object_${outfilename} PROPERTIES AUTOMOC OFF) + set_target_properties(rcc_object_${outfilename} PROPERTIES AUTOUIC OFF) add_dependencies(rcc_object_${outfilename} big_resources_${outfilename}) add_custom_command(OUTPUT ${outfile} COMMAND ${Qt5Core_RCC_EXECUTABLE} From 163a0475ebf403fd39f7a7cc764119b40664da1d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 1 Apr 2019 17:40:29 +0200 Subject: [PATCH 4/9] Windows: Fix QFileSystemEngine::id() for FAT32 drives GetFileInformationByHandleEx() which is used to to obtain the ID, has been found to fail on FAT32 (USB removable drives). Fall back to GetFileInformationByHandle() for these. Fixes: QTBUG-74759 Change-Id: Ib3ef60a6bf9e9edaf41af86bf71666001cb0aa58 Reviewed-by: Thiago Macieira --- src/corelib/io/qfilesystemengine_win.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp index 3f4b46573b2..2020e34f93d 100644 --- a/src/corelib/io/qfilesystemengine_win.cpp +++ b/src/corelib/io/qfilesystemengine_win.cpp @@ -555,7 +555,7 @@ typedef struct _FILE_ID_INFO { #endif // if defined (Q_CC_MINGW) && WINVER < 0x0602 -// File ID for Windows up to version 7. +// File ID for Windows up to version 7 and FAT32 drives static inline QByteArray fileId(HANDLE handle) { #ifndef Q_OS_WINRT @@ -588,6 +588,8 @@ QByteArray fileIdWin8(HANDLE handle) result += ':'; // Note: MinGW-64's definition of FILE_ID_128 differs from the MSVC one. result += QByteArray(reinterpret_cast(&infoEx.FileId), int(sizeof(infoEx.FileId))).toHex(); + } else { + result = fileId(handle); // GetFileInformationByHandleEx() is observed to fail for FAT32, QTBUG-74759 } return result; #else // !QT_BOOTSTRAPPED && !QT_BUILD_QMAKE From accf7ce0248e0efcdef5a3c87f8984817e6eb4ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 26 Mar 2019 15:33:51 +0100 Subject: [PATCH 5/9] macOS: Disable explicit layerContentsPlacement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was needed to allow lazy resize of the backingstore IOSurfaces, but that feature hasn't been enabled yet, and explicitly setting the layer's contents placement to NSViewLayerContentsPlacementTopLeft resulted in the layer animating when the window was moved from screens of different scale factors. We need to investigate this further, but in the meantime fix the visual regression by disabling the explicit layer contents placement. Change-Id: I63ea1eab9cf3fa6480e88844918ed98e6aa72620 Reviewed-by: Timur Pocheptsov Reviewed-by: Morten Johan Sørvig Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qnsview_drawing.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/platforms/cocoa/qnsview_drawing.mm b/src/plugins/platforms/cocoa/qnsview_drawing.mm index 0cebc8d98d0..490dbe8c4cb 100644 --- a/src/plugins/platforms/cocoa/qnsview_drawing.mm +++ b/src/plugins/platforms/cocoa/qnsview_drawing.mm @@ -163,12 +163,14 @@ return NSViewLayerContentsRedrawDuringViewResize; } +#if 0 // Disabled until we enable lazy backingstore resizing - (NSViewLayerContentsPlacement)layerContentsPlacement { // Always place the layer at top left without any automatic scaling, // so that we can re-use larger layers when resizing a window down. return NSViewLayerContentsPlacementTopLeft; } +#endif - (void)updateMetalLayerDrawableSize:(CAMetalLayer *)layer { From 06d753e87b71e6b02bbe937b488c8598c9945521 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 2 Apr 2019 10:17:31 +0200 Subject: [PATCH 6/9] Brush up and stabilize tst_QSizeGrip - Remove unused dummyWidget and thus empty slots initTestCase(), cleanupTestCase(). - Add slot cleanup() checking for an empty top level widgets list and introduce QScopedPointer to ensure it passes. - Use QTRY_VERIFY in hideAndShowOnWindowStateChange(). Flakyness has been observed on openSUSE: FAIL! : tst_QSizeGrip::hideAndShowOnWindowStateChange(Qt::Window) '!sizeGrip->isVisible()' returned FALSE. () Loc: [tst_qsizegrip.cpp(126)] Change-Id: I340fc1892dc00bcff1985e5a8a1e535975736484 Reviewed-by: Christian Ehrlicher --- .../widgets/qsizegrip/tst_qsizegrip.cpp | 59 ++++++++----------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/tests/auto/widgets/widgets/qsizegrip/tst_qsizegrip.cpp b/tests/auto/widgets/widgets/qsizegrip/tst_qsizegrip.cpp index 4cc1810cd48..f4b91265a4d 100644 --- a/tests/auto/widgets/widgets/qsizegrip/tst_qsizegrip.cpp +++ b/tests/auto/widgets/widgets/qsizegrip/tst_qsizegrip.cpp @@ -59,25 +59,22 @@ class tst_QSizeGrip : public QObject { Q_OBJECT public slots: - void initTestCase(); - void cleanupTestCase(); + void cleanup(); private slots: void hideAndShowOnWindowStateChange_data(); void hideAndShowOnWindowStateChange(); void orientation(); void dontCrashOnTLWChange(); - -private: - QLineEdit *dummyWidget; }; class TestWidget : public QWidget { public: - TestWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0) : QWidget(parent, flags) {} - QSize sizeHint() const { return QSize(300, 200); } - void changeEvent(QEvent *event) + using QWidget::QWidget; + + QSize sizeHint() const override { return QSize(300, 200); } + void changeEvent(QEvent *event) override { QWidget::changeEvent(event); if (isWindow() && event->type() == QEvent::WindowStateChange) @@ -85,16 +82,9 @@ public: } }; -void tst_QSizeGrip::initTestCase() +void tst_QSizeGrip::cleanup() { - dummyWidget = new QLineEdit; - dummyWidget->show(); -} - -void tst_QSizeGrip::cleanupTestCase() -{ - delete dummyWidget; - dummyWidget = 0; + QVERIFY(QApplication::topLevelWidgets().isEmpty()); } void tst_QSizeGrip::hideAndShowOnWindowStateChange_data() @@ -111,46 +101,45 @@ void tst_QSizeGrip::hideAndShowOnWindowStateChange() QSKIP("Broken on WinRT - QTBUG-68297"); #endif - QWidget *parentWidget = windowType == Qt::Window ? 0 : new QWidget; - TestWidget *widget = new TestWidget(parentWidget, Qt::WindowFlags(windowType)); - QSizeGrip *sizeGrip = new QSizeGrip(widget); + QScopedPointer parentWidget; + if (windowType != Qt::Window) + parentWidget.reset(new QWidget); + QScopedPointer widget(new TestWidget(parentWidget.data(), Qt::WindowFlags(windowType))); + QSizeGrip *sizeGrip = new QSizeGrip(widget.data()); // Normal. if (parentWidget) parentWidget->show(); else widget->show(); - QVERIFY(sizeGrip->isVisible()); + QTRY_VERIFY(sizeGrip->isVisible()); widget->showFullScreen(); - QVERIFY(!sizeGrip->isVisible()); + QTRY_VERIFY(!sizeGrip->isVisible()); widget->showNormal(); - QVERIFY(sizeGrip->isVisible()); + QTRY_VERIFY(sizeGrip->isVisible()); widget->showMaximized(); #ifndef Q_OS_MAC - QVERIFY(!sizeGrip->isVisible()); + QTRY_VERIFY(!sizeGrip->isVisible()); #else QEXPECT_FAIL("", "QTBUG-23681", Abort); QVERIFY(sizeGrip->isVisible()); #endif widget->showNormal(); - QVERIFY(sizeGrip->isVisible()); + QTRY_VERIFY(sizeGrip->isVisible()); sizeGrip->hide(); - QVERIFY(!sizeGrip->isVisible()); + QTRY_VERIFY(!sizeGrip->isVisible()); widget->showFullScreen(); widget->showNormal(); - QVERIFY(!sizeGrip->isVisible()); + QTRY_VERIFY(!sizeGrip->isVisible()); widget->showMaximized(); widget->showNormal(); - QVERIFY(!sizeGrip->isVisible()); - - delete widget; - delete parentWidget; + QTRY_VERIFY(!sizeGrip->isVisible()); } void tst_QSizeGrip::orientation() @@ -196,10 +185,10 @@ void tst_QSizeGrip::dontCrashOnTLWChange() QMdiArea mdiArea; mdiArea.show(); - QMainWindow *mw = new QMainWindow(); - QMdiSubWindow *mdi = mdiArea.addSubWindow(mw); + QScopedPointer mw(new QMainWindow); + QMdiSubWindow *mdi = mdiArea.addSubWindow(mw.data()); mw->statusBar()->setSizeGripEnabled(true); - mdiArea.removeSubWindow(mw); + mdiArea.removeSubWindow(mw.data()); delete mdi; mw->show(); @@ -209,7 +198,7 @@ void tst_QSizeGrip::dontCrashOnTLWChange() QEXPECT_FAIL("", "Broken on WinRT - QTBUG-68297", Abort); #endif QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); - QVERIFY(QTest::qWaitForWindowExposed(mw)); + QVERIFY(QTest::qWaitForWindowExposed(mw.data())); } QTEST_MAIN(tst_QSizeGrip) From c4d46723eb8cd17b17b87df230d502a071f4ac19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 22 Mar 2019 09:51:11 +0100 Subject: [PATCH 7/9] wasm: disable XDG_RUNTIME_DIR warning XDG is not very relevant on the Web platform. Change-Id: Ibd885e28da15114d0601c73e34dec556e65cbe75 Reviewed-by: David Faure --- src/corelib/io/qstandardpaths_unix.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp index 748ce67dace..eaa545b4fda 100644 --- a/src/corelib/io/qstandardpaths_unix.cpp +++ b/src/corelib/io/qstandardpaths_unix.cpp @@ -134,7 +134,9 @@ QString QStandardPaths::writableLocation(StandardLocation type) return QString(); } } +#ifndef Q_OS_WASM qWarning("QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '%s'", qPrintable(xdgRuntimeDir)); +#endif } else { fileInfo.setFile(xdgRuntimeDir); if (!fileInfo.exists()) { From 7bae1bd5cb131989581eb3940527d29cb8895c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 3 Apr 2019 22:59:57 +0200 Subject: [PATCH 8/9] wasm: hide canvas text caret Another side effect of setting contenteditable on the canvas. Seen on Firefox. Change-Id: I789ba4d7e6fbbdbf14b66fe1ae57183ec04e04bb Reviewed-by: Lorn Potter --- src/plugins/platforms/wasm/qtloader.js | 1 + src/plugins/platforms/wasm/wasm_shell.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/wasm/qtloader.js b/src/plugins/platforms/wasm/qtloader.js index 3cbb1c8aa8b..2db7723ae2e 100644 --- a/src/plugins/platforms/wasm/qtloader.js +++ b/src/plugins/platforms/wasm/qtloader.js @@ -164,6 +164,7 @@ function QtLoader(config) // Set contentEditable in order to enable clipboard events; hide the resulting focus frame. canvas.contentEditable = true; canvas.style.outline = "0px solid transparent"; + canvas.style.caretColor = "transparent"; canvas.style.cursor = "default"; return canvas; diff --git a/src/plugins/platforms/wasm/wasm_shell.html b/src/plugins/platforms/wasm/wasm_shell.html index 6ad7886ed4b..f7c856d63d9 100644 --- a/src/plugins/platforms/wasm/wasm_shell.html +++ b/src/plugins/platforms/wasm/wasm_shell.html @@ -11,7 +11,7 @@ /* The contenteditable property is set to true for the canvas in order to support clipboard events. Hide the resulting focus frame and set the cursor back to the default cursor. */ - canvas { outline: 0px solid transparent; cursor:default } + canvas { outline: 0px solid transparent; caret-color: transparent; cursor:default } From e227c33455ef364353dd9f6d24934b9c35ff15ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Tue, 2 Apr 2019 01:18:29 +0200 Subject: [PATCH 9/9] wasm: improve event coordinate handling targetX and targetY are canvas-local coordinates, while Qt generally works with window-local and global coordinates. Add coordinate mapping calls where needed and make sure we pass correct coordinate types to Qt. This starts mattering when we have canvases which are not located at (0, 0). Change-Id: I28563310ca17d0cc5535317cff99fcd82d3723db Reviewed-by: Lorn Potter --- .../platforms/wasm/qwasmcompositor.cpp | 4 +- src/plugins/platforms/wasm/qwasmcompositor.h | 2 +- .../platforms/wasm/qwasmeventtranslator.cpp | 58 ++++++++++--------- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/plugins/platforms/wasm/qwasmcompositor.cpp b/src/plugins/platforms/wasm/qwasmcompositor.cpp index 90cc20789de..e6a69c4814a 100644 --- a/src/plugins/platforms/wasm/qwasmcompositor.cpp +++ b/src/plugins/platforms/wasm/qwasmcompositor.cpp @@ -193,7 +193,7 @@ void QWasmCompositor::requestRedraw() QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest)); } -QWindow *QWasmCompositor::windowAt(QPoint p, int padding) const +QWindow *QWasmCompositor::windowAt(QPoint globalPoint, int padding) const { int index = m_windowStack.count() - 1; // qDebug() << "window at" << "point" << p << "window count" << index; @@ -205,7 +205,7 @@ QWindow *QWasmCompositor::windowAt(QPoint p, int padding) const QRect geometry = compositedWindow.window->windowFrameGeometry() .adjusted(-padding, -padding, padding, padding); - if (compositedWindow.visible && geometry.contains(p)) + if (compositedWindow.visible && geometry.contains(globalPoint)) return m_windowStack.at(index)->window(); --index; } diff --git a/src/plugins/platforms/wasm/qwasmcompositor.h b/src/plugins/platforms/wasm/qwasmcompositor.h index ed6facdcc39..31045730732 100644 --- a/src/plugins/platforms/wasm/qwasmcompositor.h +++ b/src/plugins/platforms/wasm/qwasmcompositor.h @@ -116,7 +116,7 @@ public: void redrawWindowContent(); void requestRedraw(); - QWindow *windowAt(QPoint p, int padding = 0) const; + QWindow *windowAt(QPoint globalPoint, int padding = 0) const; QWindow *keyWindow() const; bool event(QEvent *event); diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp index 1c4c8cb7e89..f4ca49997ad 100644 --- a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp +++ b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp @@ -549,22 +549,22 @@ void resizeWindow(QWindow *window, QWasmWindow::ResizeMode mode, void QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEvent *mouseEvent) { auto timestamp = mouseEvent->timestamp; - QPoint point(mouseEvent->targetX, mouseEvent->targetY); + QPoint targetPoint(mouseEvent->targetX, mouseEvent->targetY); + QPoint globalPoint = screen()->geometry().topLeft() + targetPoint; QEvent::Type buttonEventType = QEvent::None; - Qt::MouseButton button = translateMouseButton(mouseEvent->button); Qt::KeyboardModifiers modifiers = translateMouseEventModifier(mouseEvent); - QWindow *window2 = screen()->compositor()->windowAt(point, 5); - if (window2 != nullptr) - lastWindow = window2; + QWindow *window2 = screen()->compositor()->windowAt(globalPoint, 5); + if (window2 == nullptr) + return; + lastWindow = window2; + + QPoint localPoint = window2->mapFromGlobal(globalPoint); + bool interior = window2->geometry().contains(globalPoint); QWasmWindow *htmlWindow = static_cast(window2->handle()); - - bool interior = window2 && window2->geometry().contains(point); - - QPoint localPoint(point.x() - window2->geometry().x(), point.y() - window2->geometry().y()); switch (eventType) { case EMSCRIPTEN_EVENT_MOUSEDOWN: { @@ -580,18 +580,18 @@ void QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven pressedWindow = window2; buttonEventType = QEvent::MouseButtonPress; if (!(htmlWindow->m_windowState & Qt::WindowFullScreen) && !(htmlWindow->m_windowState & Qt::WindowMaximized)) { - if (htmlWindow && window2->flags().testFlag(Qt::WindowTitleHint) && htmlWindow->isPointOnTitle(point)) + if (htmlWindow && window2->flags().testFlag(Qt::WindowTitleHint) && htmlWindow->isPointOnTitle(globalPoint)) draggedWindow = window2; - else if (htmlWindow && htmlWindow->isPointOnResizeRegion(point)) { + else if (htmlWindow && htmlWindow->isPointOnResizeRegion(globalPoint)) { draggedWindow = window2; - resizeMode = htmlWindow->resizeModeAtPoint(point); - resizePoint = point; + resizeMode = htmlWindow->resizeModeAtPoint(globalPoint); + resizePoint = globalPoint; resizeStartRect = window2->geometry(); } } } - htmlWindow->injectMousePressed(localPoint, point, button, modifiers); + htmlWindow->injectMousePressed(localPoint, globalPoint, button, modifiers); break; } case EMSCRIPTEN_EVENT_MOUSEUP: @@ -611,7 +611,7 @@ void QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven } if (oldWindow) - oldWindow->injectMouseReleased(localPoint, point, button, modifiers); + oldWindow->injectMouseReleased(localPoint, globalPoint, button, modifiers); break; } case EMSCRIPTEN_EVENT_MOUSEMOVE: // drag event @@ -640,7 +640,7 @@ void QWasmEventTranslator::processMouse(int eventType, const EmscriptenMouseEven } if (window2 && interior) { QWindowSystemInterface::handleMouseEvent( - window2, timestamp, localPoint, point, pressedButtons, button, buttonEventType, modifiers); + window2, timestamp, localPoint, globalPoint, pressedButtons, button, buttonEventType, modifiers); } } @@ -675,11 +675,13 @@ int QWasmEventTranslator::wheel_cb(int eventType, const EmscriptenWheelEvent *wh QWasmEventTranslator *translator = (QWasmEventTranslator*)userData; Qt::KeyboardModifiers modifiers = translator->translateMouseEventModifier(&mouseEvent); auto timestamp = mouseEvent.timestamp; - QPoint globalPoint(mouseEvent.canvasX, mouseEvent.canvasY); + QPoint targetPoint(mouseEvent.targetX, mouseEvent.targetY); + QPoint globalPoint = eventTranslator->screen()->geometry().topLeft() + targetPoint; QWindow *window2 = eventTranslator->screen()->compositor()->windowAt(globalPoint, 5); - - QPoint localPoint(globalPoint.x() - window2->geometry().x(), globalPoint.y() - window2->geometry().y()); + if (!window2) + return 0; + QPoint localPoint = window2->mapFromGlobal(globalPoint); QPoint pixelDelta; @@ -709,24 +711,28 @@ int QWasmEventTranslator::handleTouch(int eventType, const EmscriptenTouchEvent const EmscriptenTouchPoint *touches = &touchEvent->touches[i]; - QPoint point(touches->targetX, touches->targetY); - window2 = this->screen()->compositor()->windowAt(point, 5); + QPoint targetPoint(touches->targetX, touches->targetY); + QPoint globalPoint = screen()->geometry().topLeft() + targetPoint; + + window2 = this->screen()->compositor()->windowAt(globalPoint, 5); + if (window2 == nullptr) + continue; + QWindowSystemInterface::TouchPoint touchPoint; touchPoint.area = QRect(0, 0, 8, 8); touchPoint.id = touches->identifier; touchPoint.pressure = 1.0; - const QPointF screenPos(point); - - touchPoint.area.moveCenter(screenPos); + touchPoint.area.moveCenter(globalPoint); const auto tp = pressedTouchIds.constFind(touchPoint.id); if (tp != pressedTouchIds.constEnd()) touchPoint.normalPosition = tp.value(); - QPointF normalPosition(screenPos.x() / window2->width(), - screenPos.y() / window2->height()); + QPointF localPoint = QPointF(window2->mapFromGlobal(globalPoint)); + QPointF normalPosition(localPoint.x() / window2->width(), + localPoint.y() / window2->height()); const bool stationaryTouchPoint = (normalPosition == touchPoint.normalPosition); touchPoint.normalPosition = normalPosition;