From d0b83adfe7b1d31db2e3febdd2638da0b1a13a0c Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 10 Oct 2019 11:27:42 +0200 Subject: Make QJsonObject::iterator a true random access iterator Amends and fixes 7236721bf8bacc0978fc872d7e4805c7be7824f0 where the iterator category was changed from bidirectional to random access without adding all the required functions. Fixes: QTBUG-57353 Change-Id: I2c96448facb222c8b8f9ad4423cb0dbd1ed098f4 Reviewed-by: Thiago Macieira --- src/corelib/serialization/qjsonobject.cpp | 101 ++++++++++++++++++++++++++++++ src/corelib/serialization/qjsonobject.h | 22 +++++++ 2 files changed, 123 insertions(+) diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp index 329bc4d2c9..8b095db915 100644 --- a/src/corelib/serialization/qjsonobject.cpp +++ b/src/corelib/serialization/qjsonobject.cpp @@ -1092,6 +1092,23 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const Returns a pointer to a modifiable reference to the current item. */ +/*! \fn QJsonValueRef QJsonObject::iterator::operator[](int j) const + + Returns a modifiable reference to the item at offset \a j from the + item pointed to by this iterator (the item at position \c{*this + j}). + + This function is provided to make QJsonObject iterators behave like C++ + pointers. + + The return value is of type QJsonValueRef, a helper class for QJsonArray + and QJsonObject. When you get an object of type QJsonValueRef, you can + use it as if it were a reference to a QJsonValue. If you assign to it, + the assignment will apply to the element in the QJsonArray or QJsonObject + from which you got the reference. + + \sa operator+() +*/ + /*! \fn bool QJsonObject::iterator::operator==(const iterator &other) const \fn bool QJsonObject::iterator::operator==(const const_iterator &other) const @@ -1112,6 +1129,38 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const \sa operator==() */ +/*! + \fn bool QJsonObject::iterator::operator<(const iterator& other) const + \fn bool QJsonObject::iterator::operator<(const const_iterator& other) const + + Returns \c true if the item pointed to by this iterator is less than + the item pointed to by the \a other iterator. +*/ + +/*! + \fn bool QJsonObject::iterator::operator<=(const iterator& other) const + \fn bool QJsonObject::iterator::operator<=(const const_iterator& other) const + + Returns \c true if the item pointed to by this iterator is less than + or equal to the item pointed to by the \a other iterator. +*/ + +/*! + \fn bool QJsonObject::iterator::operator>(const iterator& other) const + \fn bool QJsonObject::iterator::operator>(const const_iterator& other) const + + Returns \c true if the item pointed to by this iterator is greater + than the item pointed to by the \a other iterator. +*/ + +/*! + \fn bool QJsonObject::iterator::operator>=(const iterator& other) const + \fn bool QJsonObject::iterator::operator>=(const const_iterator& other) const + + Returns \c true if the item pointed to by this iterator is greater + than or equal to the item pointed to by the \a other iterator. +*/ + /*! \fn QJsonObject::iterator QJsonObject::iterator::operator++() The prefix ++ operator, \c{++i}, advances the iterator to the @@ -1185,6 +1234,12 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const \sa operator+=(), operator-() */ +/*! \fn int QJsonObject::iterator::operator-(iterator other) const + + Returns the number of items between the item pointed to by \a + other and the item pointed to by this iterator. +*/ + /*! \class QJsonObject::const_iterator \inmodule QtCore @@ -1288,6 +1343,18 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const Returns a pointer to the current item. */ +/*! \fn QJsonValue QJsonObject::const_iterator::operator[](int j) const + + Returns the item at offset \a j from the item pointed to by this iterator (the item at + position \c{*this + j}). + + This function is provided to make QJsonObject iterators behave like C++ + pointers. + + \sa operator+() +*/ + + /*! \fn bool QJsonObject::const_iterator::operator==(const const_iterator &other) const \fn bool QJsonObject::const_iterator::operator==(const iterator &other) const @@ -1306,6 +1373,34 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const \sa operator==() */ +/*! + \fn bool QJsonObject::const_iterator::operator<(const const_iterator& other) const + + Returns \c true if the item pointed to by this iterator is less than + the item pointed to by the \a other iterator. +*/ + +/*! + \fn bool QJsonObject::const_iterator::operator<=(const const_iterator& other) const + + Returns \c true if the item pointed to by this iterator is less than + or equal to the item pointed to by the \a other iterator. +*/ + +/*! + \fn bool QJsonObject::const_iterator::operator>(const const_iterator& other) const + + Returns \c true if the item pointed to by this iterator is greater + than the item pointed to by the \a other iterator. +*/ + +/*! + \fn bool QJsonObject::const_iterator::operator>=(const const_iterator& other) const + + Returns \c true if the item pointed to by this iterator is greater + than or equal to the item pointed to by the \a other iterator. +*/ + /*! \fn QJsonObject::const_iterator QJsonObject::const_iterator::operator++() The prefix ++ operator, \c{++i}, advances the iterator to the @@ -1386,6 +1481,12 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const \sa operator+=(), operator-() */ +/*! \fn int QJsonObject::const_iterator::operator-(const_iterator other) const + + Returns the number of items between the item pointed to by \a + other and the item pointed to by this iterator. +*/ + /*! \internal diff --git a/src/corelib/serialization/qjsonobject.h b/src/corelib/serialization/qjsonobject.h index 05463f6f36..53db1e1c08 100644 --- a/src/corelib/serialization/qjsonobject.h +++ b/src/corelib/serialization/qjsonobject.h @@ -154,8 +154,14 @@ public: #else inline QJsonValueRefPtr operator->() const { return QJsonValueRefPtr(o, i); } #endif + const QJsonValueRef operator[](int j) { return QJsonValueRef(o, i + j); } + inline bool operator==(const iterator &other) const { return i == other.i; } inline bool operator!=(const iterator &other) const { return i != other.i; } + bool operator<(const iterator& other) const { return i < other.i; } + bool operator<=(const iterator& other) const { return i <= other.i; } + bool operator>(const iterator& other) const { return i > other.i; } + bool operator>=(const iterator& other) const { return i >= other.i; } inline iterator &operator++() { ++i; return *this; } inline iterator operator++(int) { iterator r = *this; ++i; return r; } @@ -166,10 +172,15 @@ public: inline iterator operator-(int j) const { return operator+(-j); } inline iterator &operator+=(int j) { i += j; return *this; } inline iterator &operator-=(int j) { i -= j; return *this; } + int operator-(iterator j) const { return i - j.i; } public: inline bool operator==(const const_iterator &other) const { return i == other.i; } inline bool operator!=(const const_iterator &other) const { return i != other.i; } + bool operator<(const const_iterator& other) const { return i < other.i; } + bool operator<=(const const_iterator& other) const { return i <= other.i; } + bool operator>(const const_iterator& other) const { return i > other.i; } + bool operator>=(const const_iterator& other) const { return i >= other.i; } }; friend class iterator; @@ -200,8 +211,14 @@ public: #else inline QJsonValuePtr operator->() const { return QJsonValuePtr(o->valueAt(i)); } #endif + const QJsonValue operator[](int j) { return o->valueAt(i + j); } + inline bool operator==(const const_iterator &other) const { return i == other.i; } inline bool operator!=(const const_iterator &other) const { return i != other.i; } + bool operator<(const const_iterator& other) const { return i < other.i; } + bool operator<=(const const_iterator& other) const { return i <= other.i; } + bool operator>(const const_iterator& other) const { return i > other.i; } + bool operator>=(const const_iterator& other) const { return i >= other.i; } inline const_iterator &operator++() { ++i; return *this; } inline const_iterator operator++(int) { const_iterator r = *this; ++i; return r; } @@ -212,9 +229,14 @@ public: inline const_iterator operator-(int j) const { return operator+(-j); } inline const_iterator &operator+=(int j) { i += j; return *this; } inline const_iterator &operator-=(int j) { i -= j; return *this; } + int operator-(iterator j) const { return i - j.i; } inline bool operator==(const iterator &other) const { return i == other.i; } inline bool operator!=(const iterator &other) const { return i != other.i; } + bool operator<(const iterator& other) const { return i < other.i; } + bool operator<=(const iterator& other) const { return i <= other.i; } + bool operator>(const iterator& other) const { return i > other.i; } + bool operator>=(const iterator& other) const { return i >= other.i; } }; friend class const_iterator; -- cgit v1.2.3 From df91ff555178dd961e27ae11c4cb71811c9308a4 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 11 Oct 2019 09:34:48 +0200 Subject: tst_qgraphicsitem: Don't assume window activation is available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some windowing systems (i.e. Wayland) do not allow applications to steal window focus. Normally, we would just replace qWaitForWindowActive with qWaitForWindowExposed, because that is usually the intent, in this test however, there are many occurrences of both variants right after each other. And, as described in the commit message of 153e8b49a, this may be because window activation may cause repaints, and we want to wait for it to reduce the chance of receiving an extra repaint later (possibly causing tests to be racy). Therefore, I took the conservative approach, and kept the qWaitForWindowActive calls, except when the capability is not available. Hopefully this will not cause flakiness in existing platforms, while also allowing tests to pass on platforms where activation is not supported. Task-number: QTBUG-62188 Change-Id: I15502baa28c464a808d585a5e6d67c9b745b17ae Reviewed-by: Tor Arne Vestbø --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 95 ++++++++++++++++------ 1 file changed, 70 insertions(+), 25 deletions(-) diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 5d380c899b..fa3d4a7f23 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -1003,6 +1003,9 @@ class ImhTester : public QGraphicsItem void tst_QGraphicsItem::inputMethodHints() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + ImhTester *item = new ImhTester; item->setFlag(QGraphicsItem::ItemAcceptsInputMethod, true); item->setFlag(QGraphicsItem::ItemIsFocusable, true); @@ -1055,6 +1058,9 @@ void tst_QGraphicsItem::inputMethodHints() void tst_QGraphicsItem::toolTip() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + QString toolTip = "Qt rocks!"; QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(0, 0, 100, 100)); @@ -1764,7 +1770,9 @@ void tst_QGraphicsItem::selected_multi() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); view.fitInView(scene.sceneRect()); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(!item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -3267,7 +3275,8 @@ void tst_QGraphicsItem::hoverEventsGenerateRepaints() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events EventTester *tester = new EventTester; @@ -4994,6 +5003,9 @@ protected: void tst_QGraphicsItem::sceneEventFilter() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + QGraphicsScene scene; QGraphicsView view(&scene); @@ -6887,7 +6899,8 @@ void tst_QGraphicsItem::opacity2() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events QTRY_VERIFY(view.repaints >= 1); @@ -6962,7 +6975,8 @@ void tst_QGraphicsItem::opacityZeroUpdates() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events QTRY_VERIFY(view.repaints > 0); @@ -7297,6 +7311,9 @@ void tst_QGraphicsItem::tabChangesFocus_data() void tst_QGraphicsItem::tabChangesFocus() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + QFETCH(bool, tabChangesFocus); QGraphicsScene scene; @@ -8192,7 +8209,8 @@ void tst_QGraphicsItem::moveLineItem() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events view.reset(); @@ -8264,9 +8282,11 @@ void tst_QGraphicsItem::sorting() view.resize(120, 100); view.setFrameStyle(0); view.show(); - qApp->setActiveWindow(&view); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + qApp->setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(_paintedItems.count() > 0); _paintedItems.clear(); @@ -8302,9 +8322,11 @@ void tst_QGraphicsItem::itemHasNoContents() QGraphicsView view(&scene); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); - qApp->setActiveWindow(&view); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + qApp->setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(!_paintedItems.isEmpty()); _paintedItems.clear(); @@ -9326,10 +9348,12 @@ void tst_QGraphicsItem::ensureDirtySceneTransform() QGraphicsView view(&scene); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); - QApplication::setActiveWindow(&view); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + QApplication::setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + QCOMPARE(QApplication::activeWindow(), static_cast(&view)); + } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); - QCOMPARE(QApplication::activeWindow(), static_cast(&view)); //We move the parent parent->move(); @@ -9710,6 +9734,9 @@ void tst_QGraphicsItem::stackBefore() void tst_QGraphicsItem::QTBUG_4233_updateCachedWithSceneRect() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + EventTester *tester = new EventTester; tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); @@ -10782,6 +10809,9 @@ void tst_QGraphicsItem::scenePosChange() void tst_QGraphicsItem::textItem_shortcuts() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + QWidget w; w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); auto l = new QVBoxLayout(&w); @@ -10847,7 +10877,8 @@ void tst_QGraphicsItem::scroll() view.setFrameStyle(0); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(view.repaints > 0); view.reset(); @@ -11373,9 +11404,11 @@ void tst_QGraphicsItem::QTBUG_6738_missingUpdateWithSetParent() MyGraphicsView view(&scene); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); - qApp->setActiveWindow(&view); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + qApp->setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events QTRY_VERIFY(view.repaints > 0); @@ -11426,7 +11459,8 @@ void tst_QGraphicsItem::QT_2653_fullUpdateDiscardingOpacityUpdate() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events view.reset(); @@ -11461,7 +11495,9 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() scene.addItem(parentGreen); origView.show(); - QVERIFY(QTest::qWaitForWindowActive(&origView)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&origView)); + QVERIFY(QTest::qWaitForWindowExposed(&origView)); QCoreApplication::processEvents(); // Process all queued paint events origView.setGeometry(origView.x() + origView.width() + 20, origView.y() + 20, @@ -11475,9 +11511,11 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() QTRY_VERIFY(origView.repaints > 0); view.show(); - qApp->setActiveWindow(&view); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + qApp->setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); view.reset(); origView.reset(); @@ -11591,6 +11629,9 @@ void tst_QGraphicsItem::sortItemsWhileAdding() void tst_QGraphicsItem::doNotMarkFullUpdateIfNotInScene() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + struct Item : public QGraphicsTextItem { int painted = 0; @@ -11649,10 +11690,12 @@ void tst_QGraphicsItem::itemDiesDuringDraggingOperation() item->setAcceptDrops(true); scene.addItem(item); view.show(); - QApplication::setActiveWindow(&view); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + QApplication::setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + QCOMPARE(QApplication::activeWindow(), &view); + } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); - QCOMPARE(QApplication::activeWindow(), &view); QGraphicsSceneDragDropEvent dragEnter(QEvent::GraphicsSceneDragEnter); dragEnter.setScenePos(item->boundingRect().center()); QCoreApplication::sendEvent(&scene, &dragEnter); @@ -11678,10 +11721,12 @@ void tst_QGraphicsItem::QTBUG_12112_focusItem() scene.addItem(item1); view.show(); - QApplication::setActiveWindow(&view); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + QApplication::setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + QCOMPARE(QApplication::activeWindow(), &view); + } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); - QCOMPARE(QApplication::activeWindow(), &view); QVERIFY(item1->focusItem()); QVERIFY(!item2->focusItem()); -- cgit v1.2.3 From 332c255c696bb15db7a0510dab2a6ac214ecdb19 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 11 Oct 2019 09:43:24 +0200 Subject: tst_qgraphicsitem: Skip tests that fail on Wayland Task-number: QTBUG-62188 Change-Id: If0638d51bffa6ef375476c0a601c387bd05583ae Reviewed-by: Paul Olav Tvete --- tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index fa3d4a7f23..864dd9f590 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -7361,6 +7361,9 @@ void tst_QGraphicsItem::tabChangesFocus() void tst_QGraphicsItem::cacheMode() { + if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) + QSKIP("Wayland: This fails. Figure out why."); + QGraphicsScene scene(0, 0, 100, 100); QGraphicsView view(&scene); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); @@ -7542,6 +7545,9 @@ void tst_QGraphicsItem::cacheMode() void tst_QGraphicsItem::cacheMode2() { + if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) + QSKIP("Wayland: This fails. Figure out why."); + QGraphicsScene scene(0, 0, 100, 100); QGraphicsView view(&scene); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); -- cgit v1.2.3 From 51f092905a2cb38feb5fef759b5ac8b417df0996 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 11 Oct 2019 15:19:45 +0200 Subject: QTest: fall back to qWaitForWindowExposed in qWaitForWindowActivated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ...if window activation isn't supported. Task-number: QTBUG-62188 Change-Id: Ia83de59d9a755d95b7150eb5261bc43dd7b60588 Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qtestsupport_gui.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/gui/kernel/qtestsupport_gui.cpp b/src/gui/kernel/qtestsupport_gui.cpp index 7aad4d8c7d..79da26f2ca 100644 --- a/src/gui/kernel/qtestsupport_gui.cpp +++ b/src/gui/kernel/qtestsupport_gui.cpp @@ -37,10 +37,15 @@ ** ****************************************************************************/ +#include + +#include + #include "qtestsupport_gui.h" #include "qwindow.h" #include +#include QT_BEGIN_NAMESPACE @@ -55,6 +60,14 @@ QT_BEGIN_NAMESPACE */ Q_GUI_EXPORT bool QTest::qWaitForWindowActive(QWindow *window, int timeout) { + if (Q_UNLIKELY(!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))) { + qWarning() << "qWaitForWindowActive was called on a platform that doesn't support window" + << "activation. This means there is an error in the test and it should either" + << "check for the WindowActivation platform capability before calling" + << "qWaitForWindowActivate, use qWaitForWindowExposed instead, or skip the test." + << "Falling back to qWaitForWindowExposed."; + return qWaitForWindowExposed(window, timeout); + } return QTest::qWaitFor([&]() { return window->isActive(); }, timeout); } -- cgit v1.2.3 From 80ddac3a0a9984e1dc4da6440912cfcfd210a380 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 11 Oct 2019 10:01:00 +0200 Subject: tst_qgraphicseffect: Wait for exposed instead of active MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makes the test pass on Wayland. Task-number: QTBUG-62188 Change-Id: I3900925e74d8d940a8c5af87ea64a6ec3c8c3293 Reviewed-by: Tor Arne Vestbø --- .../widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp index c4b6e22c37..19288d07a7 100644 --- a/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp +++ b/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp @@ -311,7 +311,7 @@ void tst_QGraphicsEffect::draw() QGraphicsView view(&scene); view.show(); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_VERIFY(item->numRepaints > 0); QCoreApplication::processEvents(); // Process all queued paint events item->reset(); @@ -668,8 +668,7 @@ void tst_QGraphicsEffect::childrenVisibilityShouldInvalidateCache() scene.addItem(&parent); QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_VERIFY(parent.nbPaint >= 1); //we set an effect on the parent parent.setGraphicsEffect(new QGraphicsDropShadowEffect(&parent)); @@ -694,8 +693,7 @@ void tst_QGraphicsEffect::prepareGeometryChangeInvalidateCache() QGraphicsView view(&scene); view.show(); - qApp->setActiveWindow(&view); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_VERIFY(item->nbPaint >= 1); item->nbPaint = 0; @@ -726,8 +724,7 @@ void tst_QGraphicsEffect::itemHasNoContents() QGraphicsView view(&scene); view.show(); - qApp->setActiveWindow(&view); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_VERIFY(child->nbPaint >= 1); CustomEffect *effect = new CustomEffect; -- cgit v1.2.3 From 06ca5c49e7fb6dd23eab3a02de404c82e03bc5db Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 14 Oct 2019 15:23:48 +0200 Subject: Cbor: Avoid QUrl in bootstrap code QUrl is not available when building qmake. Hopefully we can get rid of this mess in Qt 6. Change-Id: Ia234996dd4f27d7f843db227e4cf2db869c92dc1 Reviewed-by: Lars Knoll Reviewed-by: Thiago Macieira --- src/corelib/serialization/qcborvalue.cpp | 8 ++++++++ src/corelib/serialization/qcborvalue.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp index 9053618014..1b170739d2 100644 --- a/src/corelib/serialization/qcborvalue.cpp +++ b/src/corelib/serialization/qcborvalue.cpp @@ -1765,6 +1765,7 @@ QCborValue::QCborValue(const QDateTime &dt) container->elements[1].type = String; } +#ifndef QT_BOOTSTRAPPED /*! Creates a QCborValue object of the URL extended type and containing the value represented by \a url. The value can later be retrieved using toUrl(). @@ -1781,6 +1782,7 @@ QCborValue::QCborValue(const QUrl &url) t = Url; container->elements[1].type = String; } +#endif #if QT_CONFIG(regularexpression) /*! @@ -1934,6 +1936,7 @@ QDateTime QCborValue::toDateTime(const QDateTime &defaultValue) const return QDateTime::fromString(byteData->asLatin1(), Qt::ISODateWithMs); } +#ifndef QT_BOOTSTRAPPED /*! Returns the URL value stored in this QCborValue, if it is of the URL extended type. Otherwise, it returns \a defaultValue. @@ -1954,6 +1957,7 @@ QUrl QCborValue::toUrl(const QUrl &defaultValue) const return QUrl::fromEncoded(byteData->asByteArrayView()); } +#endif #if QT_CONFIG(regularexpression) /*! @@ -2882,8 +2886,10 @@ uint qHash(const QCborValue &value, uint seed) return qHash(value.toDouble(), seed); case QCborValue::DateTime: return qHash(value.toDateTime(), seed); +#ifndef QT_BOOTSTRAPPED case QCborValue::Url: return qHash(value.toUrl(), seed); +#endif #if QT_CONFIG(regularexpression) case QCborValue::RegularExpression: return qHash(value.toRegularExpression(), seed); @@ -2936,8 +2942,10 @@ static QDebug debugContents(QDebug &dbg, const QCborValue &v) } case QCborValue::DateTime: return dbg << v.toDateTime(); +#ifndef QT_BOOTSTRAPPED case QCborValue::Url: return dbg << v.toUrl(); +#endif #if QT_CONFIG(regularexpression) case QCborValue::RegularExpression: return dbg << v.toRegularExpression(); diff --git a/src/corelib/serialization/qcborvalue.h b/src/corelib/serialization/qcborvalue.h index f79fc572c4..3c325b59e7 100644 --- a/src/corelib/serialization/qcborvalue.h +++ b/src/corelib/serialization/qcborvalue.h @@ -161,7 +161,9 @@ public: {} explicit QCborValue(const QDateTime &dt); +#ifndef QT_BOOTSTRAPPED explicit QCborValue(const QUrl &url); +#endif #if QT_CONFIG(regularexpression) explicit QCborValue(const QRegularExpression &rx); #endif @@ -387,8 +389,10 @@ public: { return concrete().toString(defaultValue); } QDateTime toDateTime(const QDateTime &defaultValue = {}) const { return concrete().toDateTime(defaultValue); } +#ifndef QT_BOOTSTRAPPED QUrl toUrl(const QUrl &defaultValue = {}) const { return concrete().toUrl(defaultValue); } +#endif #if QT_CONFIG(regularexpression) QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const { return concrete().toRegularExpression(defaultValue); } -- cgit v1.2.3