From 66a9c4b0b259fe9a61150b7394af0f31ebfd38ac Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Tue, 23 Jul 2019 14:33:31 +0200 Subject: [PATCH 01/23] Remove usages of deprecated APIs of QDesktopWidget - Replaced the usages of the following deprecated APIs: * QDesktopWidget::screenCount() -> QGuiApplication::screens().size() * QDesktopWidget::screenGeometry(int) -> QGuiApplication::screens().at() * QDesktopWidget::screenNumber(QPoint) -> QGuiApplication::screenAt(QPoint) - Added notes for the QWidget *QDesktopWidget::screen(int), which currently has no replacement. - Fixed the tests to build conditionally, only when these APIs are enabled. Task-number: QTBUG-76491 Change-Id: I2fdec96d0a6a4fc782c53549b05a5556412b8305 Reviewed-by: Volker Hilsheimer --- src/widgets/kernel/qdesktopwidget.cpp | 2 ++ src/widgets/widgets/qeffects.cpp | 2 +- .../qdesktopwidget/tst_qdesktopwidget.cpp | 21 ++++++++++++++----- tests/manual/qcursor/qcursorhighdpi/main.cpp | 9 +++----- tests/manual/qdesktopwidget/main.cpp | 2 ++ tests/manual/qscreen/main.cpp | 5 ++++- 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/widgets/kernel/qdesktopwidget.cpp b/src/widgets/kernel/qdesktopwidget.cpp index 4fbe6bba3f5..9e90adec468 100644 --- a/src/widgets/kernel/qdesktopwidget.cpp +++ b/src/widgets/kernel/qdesktopwidget.cpp @@ -211,7 +211,9 @@ QDesktopWidget::QDesktopWidget() setObjectName(QLatin1String("desktop")); d->_q_updateScreens(); connect(qApp, SIGNAL(screenAdded(QScreen*)), this, SLOT(_q_updateScreens())); +#if QT_DEPRECATED_SINCE(5, 11) connect(qApp, SIGNAL(primaryScreenChanged(QScreen*)), this, SIGNAL(primaryScreenChanged())); +#endif } QDesktopWidget::~QDesktopWidget() diff --git a/src/widgets/widgets/qeffects.cpp b/src/widgets/widgets/qeffects.cpp index 94636413692..7069ef03685 100644 --- a/src/widgets/widgets/qeffects.cpp +++ b/src/widgets/widgets/qeffects.cpp @@ -99,7 +99,7 @@ static QAlphaWidget* q_blend = 0; Constructs a QAlphaWidget. */ QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED // QDesktopWidget::screen() +QT_WARNING_DISABLE_DEPRECATED // ### Qt 6: Find a replacement for QDesktopWidget::screen() QAlphaWidget::QAlphaWidget(QWidget* w, Qt::WindowFlags f) : QWidget(QApplication::desktop()->screen(QDesktopWidgetPrivate::screenNumber(w)), f) { diff --git a/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp b/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp index 90776dfcb25..a29e8408a30 100644 --- a/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp +++ b/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp @@ -42,10 +42,12 @@ class tst_QDesktopWidget : public QObject private slots: void cleanup(); +#if QT_DEPRECATED_SINCE(5, 11) void numScreens(); void primaryScreen(); - void screenNumberForQWidget(); void screenNumberForQPoint(); +#endif + void screenNumberForQWidget(); void availableGeometry(); void screenGeometry(); void topLevels(); @@ -56,6 +58,7 @@ void tst_QDesktopWidget::cleanup() QVERIFY(QApplication::topLevelWidgets().isEmpty()); } +#if QT_DEPRECATED_SINCE(5, 11) void tst_QDesktopWidget::numScreens() { QDesktopWidget desktop; @@ -68,14 +71,17 @@ void tst_QDesktopWidget::primaryScreen() QVERIFY(desktop.primaryScreen() >= 0); QVERIFY(desktop.primaryScreen() < desktop.numScreens()); } +#endif void tst_QDesktopWidget::availableGeometry() { QDesktopWidget desktop; QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::availableGeometry(): Attempt " "to get the available geometry of a null widget"); - desktop.availableGeometry((QWidget *)0); + QRect r = desktop.availableGeometry(nullptr); + QVERIFY(r.isNull()); +#if QT_DEPRECATED_SINCE(5, 11) QRect total; QRect available; @@ -90,13 +96,14 @@ void tst_QDesktopWidget::availableGeometry() QVERIFY(total.contains(available)); QCOMPARE(desktop.availableGeometry(desktop.primaryScreen()), available); QCOMPARE(desktop.screenGeometry(desktop.primaryScreen()), total); +#endif } void tst_QDesktopWidget::screenNumberForQWidget() { QDesktopWidget desktop; - QCOMPARE(desktop.screenNumber(0), 0); + QCOMPARE(desktop.screenNumber(nullptr), 0); QWidget widget; widget.show(); @@ -105,9 +112,10 @@ void tst_QDesktopWidget::screenNumberForQWidget() int widgetScreen = desktop.screenNumber(&widget); QVERIFY(widgetScreen > -1); - QVERIFY(widgetScreen < desktop.numScreens()); + QVERIFY(widgetScreen < QGuiApplication::screens().size()); } +#if QT_DEPRECATED_SINCE(5, 11) void tst_QDesktopWidget::screenNumberForQPoint() { // make sure QDesktopWidget::screenNumber(QPoint) returns the correct screen @@ -131,25 +139,28 @@ void tst_QDesktopWidget::screenNumberForQPoint() screen = desktopWidget->screenNumber(allScreens.bottomRight() + QPoint(1, 1)); QVERIFY(screen >= 0 && screen < desktopWidget->numScreens()); } +#endif void tst_QDesktopWidget::screenGeometry() { QDesktopWidget *desktopWidget = QApplication::desktop(); QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::screenGeometry(): Attempt " "to get the screen geometry of a null widget"); - QRect r = desktopWidget->screenGeometry((QWidget *)0); + QRect r = desktopWidget->screenGeometry(nullptr); QVERIFY(r.isNull()); QWidget widget; widget.show(); QVERIFY(QTest::qWaitForWindowExposed(&widget)); r = desktopWidget->screenGeometry(&widget); +#if QT_DEPRECATED_SINCE(5, 11) QRect total; QRect available; for (int i = 0; i < desktopWidget->screenCount(); ++i) { total = desktopWidget->screenGeometry(i); available = desktopWidget->availableGeometry(i); } +#endif } void tst_QDesktopWidget::topLevels() diff --git a/tests/manual/qcursor/qcursorhighdpi/main.cpp b/tests/manual/qcursor/qcursorhighdpi/main.cpp index 3b18bff91c9..017f41eccd2 100644 --- a/tests/manual/qcursor/qcursorhighdpi/main.cpp +++ b/tests/manual/qcursor/qcursorhighdpi/main.cpp @@ -356,15 +356,12 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); MainWindowPtrList windows; - - QDesktopWidget *desktopWidget = app.desktop(); - const int lastScreen = arguments.contains("-p") ? 0 // Primary screen only - : desktopWidget->screenCount() - 1; // All screens + : QGuiApplication::screens().size() - 1; // All screens for (int s = lastScreen; s >= 0; --s) { - MainWindowPtr window(new MainWindow(desktopWidget->screen(s))); - const QPoint pos = desktopWidget->screenGeometry(s).center() - QPoint(200, 100); + MainWindowPtr window(new MainWindow()); + const QPoint pos = QGuiApplication::screens().at(s)->geometry().center() - QPoint(200, 100); window->move(pos); windows.append(window); window->show(); diff --git a/tests/manual/qdesktopwidget/main.cpp b/tests/manual/qdesktopwidget/main.cpp index f4c82c5f72c..978dc62b0e1 100644 --- a/tests/manual/qdesktopwidget/main.cpp +++ b/tests/manual/qdesktopwidget/main.cpp @@ -34,6 +34,7 @@ class DesktopView : public QGraphicsView { +#if QT_DEPRECATED_SINCE(5, 11) Q_OBJECT public: DesktopView() @@ -195,6 +196,7 @@ private: QGraphicsScene *scene; QGraphicsRectItem *that; QPoint thatRoot; +#endif }; #include "main.moc" diff --git a/tests/manual/qscreen/main.cpp b/tests/manual/qscreen/main.cpp index 6fba872b12a..0728d66bf9f 100644 --- a/tests/manual/qscreen/main.cpp +++ b/tests/manual/qscreen/main.cpp @@ -61,8 +61,10 @@ public: QLatin1String("Left-click to test QGuiApplication::topLevelAt(click pos)\nRight-click to ungrab\n") : QLatin1String("Left-click to grab mouse\n"); if (!m_cursorPos.isNull()) { + const auto screen = QGuiApplication::screenAt(m_cursorPos); + const auto screenNum = screen ? QGuiApplication::screens().indexOf(screen) : 0; txt += QString(QLatin1String("Current mouse position: %1, %2 on screen %3\n")) - .arg(m_cursorPos.x()).arg(m_cursorPos.y()).arg(QApplication::desktop()->screenNumber(m_cursorPos)); + .arg(m_cursorPos.x()).arg(m_cursorPos.y()).arg(screenNum); if (QGuiApplication::mouseButtons() & Qt::LeftButton) { QWindow *win = QGuiApplication::topLevelAt(m_cursorPos); txt += QString(QLatin1String("Top-level window found? %1\n")) @@ -234,6 +236,7 @@ void screenAdded(QScreen* screen) QList screens = QGuiApplication::screens(); int screenNumber = screens.indexOf(screen); Q_ASSERT(screenNumber >= 0); + // ### Qt 6: Find a replacement for QDesktopWidget::screen() w->setParent(qApp->desktop()->screen(screenNumber)); w->show(); From d0b83adfe7b1d31db2e3febdd2638da0b1a13a0c Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 10 Oct 2019 11:27:42 +0200 Subject: [PATCH 02/23] 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 329bc4d2c9a..8b095db9150 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 05463f6f364..53db1e1c08e 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; From df91ff555178dd961e27ae11c4cb71811c9308a4 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 11 Oct 2019 09:34:48 +0200 Subject: [PATCH 03/23] 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 5d380c899b5..fa3d4a7f230 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()); From 253ce59c12d60ded2278e6d5bb8399e44bd4d302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 3 Oct 2019 16:51:19 +0200 Subject: [PATCH 04/23] CoreText: Use StyleHint as fallback when family is not found Change-Id: I11fb6cafe9d41c38eac6ca0695c89f30f998f257 Reviewed-by: Eskil Abrahamsen Blomfeldt Reviewed-by: Volker Hilsheimer --- .../fontdatabases/mac/qcoretextfontdatabase.mm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 4887a501bac..2e8e726c708 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -444,6 +444,14 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family) return QStringList(); } + // If the font is not available we want to fall back to the style hint. + // By creating a matching font descriptor we can verify whether the font + // is available or not, and avoid CTFontCreateWithFontDescriptor picking + // a default font for us based on incomplete information. + fontDescriptor = CTFontDescriptorCreateMatchingFontDescriptor(fontDescriptor, 0); + if (!fontDescriptor) + return QStringList(); + QCFType font = CTFontCreateWithFontDescriptor(fontDescriptor, 12.0, 0); if (!font) { qCWarning(lcQpaFonts) << "Failed to create fallback font for" << family; @@ -472,6 +480,10 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo { Q_UNUSED(style); + qCDebug(lcQpaFonts).nospace() << "Resolving fallbacks for" + << (!family.isEmpty() ? qPrintable(QLatin1String(" family '%1' with").arg(family)) : "") + << " style hint " << styleHint; + QMacAutoReleasePool pool; QStringList fallbackList = fallbacksForFamily(family); @@ -479,6 +491,9 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo if (fallbackList.isEmpty()) { // We were not able to find a fallback for the specific family, // or the family was empty, so we fall back to the style hint. + if (!family.isEmpty()) + qCDebug(lcQpaFonts) << "No fallbacks found. Using style hint instead"; + QString styleFamily = [styleHint]{ switch (styleHint) { case QFont::SansSerif: return QStringLiteral("Helvetica"); @@ -541,6 +556,8 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo extern QStringList qt_sort_families_by_writing_system(QChar::Script, const QStringList &); fallbackList = qt_sort_families_by_writing_system(script, fallbackList); + qCDebug(lcQpaFonts).nospace() << "Resolved fallbacks ordered by script " << script << ": " << fallbackList; + return fallbackList; } From b03e75670be884eb21a61c336a177a3fcb787426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 7 Oct 2019 15:45:32 +0200 Subject: [PATCH 05/23] CoreText: Preserve font descriptors when resolving fallback families From macOS 10.15 and iOS 13 forward it's not possible to create font descriptors for system fonts such as .AppleSystemUIFont based on the family name. This means we have to preserve the font descriptors we get from CoreText for fallback fonts, so that we can populate them along with the family name. Task-number: QTBUG-78821 Task-number: QTBUG-77467 Change-Id: Ifce01da65f90afb7dc2bc3005c3c5870b9c116de Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../mac/qcoretextfontdatabase.mm | 180 ++++++++++-------- .../mac/qcoretextfontdatabase_p.h | 2 +- 2 files changed, 105 insertions(+), 77 deletions(-) diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm index 2e8e726c708..daa3dc94ea2 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm @@ -432,16 +432,46 @@ template class QCoreTextFontDatabaseEngineFactory; template class QCoreTextFontDatabaseEngineFactory; #endif -QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family) +CTFontDescriptorRef descriptorForFamily(const QString &familyName) +{ + return CTFontDescriptorCreateWithAttributes(CFDictionaryRef(@{ + (id)kCTFontFamilyNameAttribute: familyName.toNSString() + })); +} + +CTFontDescriptorRef descriptorForFamily(const char *familyName) +{ + return descriptorForFamily(QString::fromLatin1(familyName)); +} + +CFArrayRef fallbacksForDescriptor(CTFontDescriptorRef descriptor) +{ + QCFType font = CTFontCreateWithFontDescriptor(descriptor, 0.0, nullptr); + if (!font) { + qCWarning(lcQpaFonts) << "Failed to create fallback font for" << descriptor; + return nullptr; + } + + CFArrayRef cascadeList = CFArrayRef(CTFontCopyDefaultCascadeListForLanguages(font, + (CFArrayRef)[NSUserDefaults.standardUserDefaults stringArrayForKey:@"AppleLanguages"])); + + if (!cascadeList) { + qCWarning(lcQpaFonts) << "Failed to create fallback cascade list for" << descriptor; + return nullptr; + } + + return cascadeList; +} + +CFArrayRef QCoreTextFontDatabase::fallbacksForFamily(const QString &family) { if (family.isEmpty()) - return QStringList(); + return nullptr; - auto attributes = @{ id(kCTFontFamilyNameAttribute): family.toNSString() }; - QCFType fontDescriptor = CTFontDescriptorCreateWithAttributes(CFDictionaryRef(attributes)); + QCFType fontDescriptor = descriptorForFamily(family); if (!fontDescriptor) { qCWarning(lcQpaFonts) << "Failed to create fallback font descriptor for" << family; - return QStringList(); + return nullptr; } // If the font is not available we want to fall back to the style hint. @@ -450,85 +480,94 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family) // a default font for us based on incomplete information. fontDescriptor = CTFontDescriptorCreateMatchingFontDescriptor(fontDescriptor, 0); if (!fontDescriptor) - return QStringList(); + return nullptr; - QCFType font = CTFontCreateWithFontDescriptor(fontDescriptor, 12.0, 0); - if (!font) { - qCWarning(lcQpaFonts) << "Failed to create fallback font for" << family; - return QStringList(); + return fallbacksForDescriptor(fontDescriptor); +} + +CTFontDescriptorRef descriptorForFontType(CTFontUIFontType uiType) +{ + static const CGFloat kDefaultSizeForRequestedUIType = 0.0; + QCFType ctFont = CTFontCreateUIFontForLanguage( + uiType, kDefaultSizeForRequestedUIType, nullptr); + return CTFontCopyFontDescriptor(ctFont); +} + +CTFontDescriptorRef descriptorForStyle(QFont::StyleHint styleHint) +{ + switch (styleHint) { + case QFont::SansSerif: return descriptorForFamily("Helvetica"); + case QFont::Serif: return descriptorForFamily("Times New Roman"); + case QFont::Monospace: return descriptorForFamily("Menlo"); +#ifdef Q_OS_MACOS + case QFont::Cursive: return descriptorForFamily("Apple Chancery"); +#endif + case QFont::Fantasy: return descriptorForFamily("Zapfino"); + case QFont::TypeWriter: return descriptorForFamily("American Typewriter"); + case QFont::AnyStyle: Q_FALLTHROUGH(); + case QFont::System: return descriptorForFontType(kCTFontUIFontSystem); + default: return nullptr; // No matching font on this platform } - - QCFType cascadeList = CFArrayRef(CTFontCopyDefaultCascadeListForLanguages(font, - (CFArrayRef)[NSUserDefaults.standardUserDefaults stringArrayForKey:@"AppleLanguages"])); - if (!cascadeList) { - qCWarning(lcQpaFonts) << "Failed to create fallback cascade list for" << family; - return QStringList(); - } - - QStringList fallbackList; - const int numCascades = CFArrayGetCount(cascadeList); - for (int i = 0; i < numCascades; ++i) { - CTFontDescriptorRef fontFallback = CTFontDescriptorRef(CFArrayGetValueAtIndex(cascadeList, i)); - QCFString fallbackFamilyName = CFStringRef(CTFontDescriptorCopyAttribute(fontFallback, kCTFontFamilyNameAttribute)); - fallbackList.append(QString::fromCFString(fallbackFamilyName)); - } - - return fallbackList; } QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFont::Style style, QFont::StyleHint styleHint, QChar::Script script) const { Q_UNUSED(style); - qCDebug(lcQpaFonts).nospace() << "Resolving fallbacks for" + qCDebug(lcQpaFonts).nospace() << "Resolving fallbacks families for" << (!family.isEmpty() ? qPrintable(QLatin1String(" family '%1' with").arg(family)) : "") << " style hint " << styleHint; QMacAutoReleasePool pool; - QStringList fallbackList = fallbacksForFamily(family); + QStringList fallbackList; - if (fallbackList.isEmpty()) { + QCFType fallbackFonts = fallbacksForFamily(family); + if (!fallbackFonts || !CFArrayGetCount(fallbackFonts)) { // We were not able to find a fallback for the specific family, // or the family was empty, so we fall back to the style hint. if (!family.isEmpty()) qCDebug(lcQpaFonts) << "No fallbacks found. Using style hint instead"; - QString styleFamily = [styleHint]{ - switch (styleHint) { - case QFont::SansSerif: return QStringLiteral("Helvetica"); - case QFont::Serif: return QStringLiteral("Times New Roman"); - case QFont::Monospace: return QStringLiteral("Menlo"); -#ifdef Q_OS_MACOS - case QFont::Cursive: return QStringLiteral("Apple Chancery"); -#endif - case QFont::Fantasy: return QStringLiteral("Zapfino"); - case QFont::TypeWriter: return QStringLiteral("American Typewriter"); - case QFont::AnyStyle: Q_FALLTHROUGH(); - case QFont::System: { - QCFType font = CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, 12.0, NULL); - return static_cast(QCFString(CTFontCopyFullName(font))); - } - default: return QString(); // No matching font on this platform - } - }(); - if (!styleFamily.isEmpty()) { - fallbackList = fallbacksForFamily(styleFamily); - if (!fallbackList.contains(styleFamily)) - fallbackList.prepend(styleFamily); + if (QCFType styleDescriptor = descriptorForStyle(styleHint)) { + CFMutableArrayRef tmp = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); + CFArrayAppendValue(tmp, styleDescriptor); + QCFType styleFallbacks = fallbacksForDescriptor(styleDescriptor); + CFArrayAppendArray(tmp, styleFallbacks, CFRangeMake(0, CFArrayGetCount(styleFallbacks))); + fallbackFonts = tmp; } } - if (fallbackList.isEmpty()) + if (!fallbackFonts) return fallbackList; - // .Apple Symbols Fallback will be at the beginning of the list and we will - // detect that this has glyphs for Arabic and other writing systems. - // Since it is a symbol font, it should be the last resort, so that - // the proper fonts for these writing systems are preferred. - int symbolIndex = fallbackList.indexOf(QLatin1String(".Apple Symbols Fallback")); - if (symbolIndex >= 0) - fallbackList.move(symbolIndex, fallbackList.size() - 1); + const int numberOfFallbacks = CFArrayGetCount(fallbackFonts); + for (int i = 0; i < numberOfFallbacks; ++i) { + auto fallbackDescriptor = CTFontDescriptorRef(CFArrayGetValueAtIndex(fallbackFonts, i)); + auto fallbackFamilyName = QCFString(CTFontDescriptorCopyAttribute(fallbackDescriptor, kCTFontFamilyNameAttribute)); + + if (!isFamilyPopulated(fallbackFamilyName)) { + // We need to populate, or at least register the fallback fonts, + // otherwise the Qt font database may not know they exist. + if (isPrivateFontFamily(fallbackFamilyName)) + const_cast(this)->populateFromDescriptor(fallbackDescriptor); + else + registerFontFamily(fallbackFamilyName); + } + + fallbackList.append(fallbackFamilyName); + } + + // Some fallback fonts will have have an order in the list returned + // by Core Text that would indicate they should be preferred for e.g. + // Arabic, or Emoji, while in reality only supporting a tiny subset + // of the required glyphs, or representing them by question marks. + // Move these to the end, so that the proper fonts are preferred. + for (const char *family : { ".Apple Symbols Fallback", ".Noto Sans Universal" }) { + int index = fallbackList.indexOf(QLatin1String(family)); + if (index >= 0) + fallbackList.move(index, fallbackList.size() - 1); + } #if defined(Q_OS_MACOS) // Since we are only returning a list of default fonts for the current language, we do not @@ -544,19 +583,10 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo fallbackList.append(QStringLiteral("Apple Symbols")); #endif - // Since iOS 13, the cascade list may contain meta-fonts which have not been - // populated to the database, such as ".AppleJapaneseFont". It is important that we - // include this in the fallback list, in order to get fallback support for all - // languages - for (const QString &fallback : fallbackList) { - if (!QPlatformFontDatabase::isFamilyPopulated(fallback)) - const_cast(this)->populateFamily(fallback); - } - extern QStringList qt_sort_families_by_writing_system(QChar::Script, const QStringList &); fallbackList = qt_sort_families_by_writing_system(script, fallbackList); - qCDebug(lcQpaFonts).nospace() << "Resolved fallbacks ordered by script " << script << ": " << fallbackList; + qCDebug(lcQpaFonts).nospace() << "Fallback families ordered by script " << script << ": " << fallbackList; return fallbackList; } @@ -717,10 +747,8 @@ static CTFontDescriptorRef fontDescriptorFromTheme(QPlatformTheme::Font f) } #endif // Q_OS_IOS, Q_OS_TVOS, Q_OS_WATCHOS - // OSX default case and iOS fallback case - CTFontUIFontType fontType = fontTypeFromTheme(f); - QCFType ctFont = CTFontCreateUIFontForLanguage(fontType, 0.0, NULL); - return CTFontCopyFontDescriptor(ctFont); + // macOS default case and iOS fallback case + return descriptorForFontType(fontTypeFromTheme(f)); } const QHash &QCoreTextFontDatabase::themeFonts() const @@ -753,8 +781,8 @@ QFont *QCoreTextFontDatabase::themeFont(QPlatformTheme::Font f) const QFont QCoreTextFontDatabase::defaultFont() const { if (defaultFontName.isEmpty()) { - QCFType font = CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, 12.0, NULL); - defaultFontName = (QString) QCFString(CTFontCopyFullName(font)); + QCFType systemFont = descriptorForFontType(kCTFontUIFontSystem); + defaultFontName = QCFString(CTFontDescriptorCopyAttribute(systemFont, kCTFontFamilyNameAttribute)); } return QFont(defaultFontName); diff --git a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h index 69ff454d1e9..eebb3eb9640 100644 --- a/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h +++ b/src/platformsupport/fontdatabases/mac/qcoretextfontdatabase_p.h @@ -92,7 +92,7 @@ protected: private: void populateFromDescriptor(CTFontDescriptorRef font, const QString &familyName = QString()); - static QStringList fallbacksForFamily(const QString &family); + static CFArrayRef fallbacksForFamily(const QString &family); mutable QString defaultFontName; From 139246faa3322e933b5b66ebfc616bfe05a6ace6 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Fri, 11 Oct 2019 07:36:48 +1000 Subject: [PATCH 06/23] wasm: fix arch detect on windows with WASM_OBJECT_FILES MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: QTBUG-79146 Change-Id: I00188013b98687f34582aeb7b29b6d7439334536 Reviewed-by: Morten Johan Sørvig Reviewed-by: Edward Welbourne --- config.tests/arch/write_info.pri | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/config.tests/arch/write_info.pri b/config.tests/arch/write_info.pri index 666b9e5cbb8..5b43ce1cd53 100644 --- a/config.tests/arch/write_info.pri +++ b/config.tests/arch/write_info.pri @@ -4,10 +4,7 @@ targetinfofile ~= s/pro$/target.txt/ win32 { ext = .exe } else:wasm { - equals(WASM_OBJECT_FILES, 1): \ - ext = .o - else: \ - ext = .wasm + ext = .wasm } content = $${file_prefix}$${TARGET}$${ext} From ffac8995769f27fe0d68d5e0cd75716afd3d1167 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Fri, 11 Oct 2019 10:49:38 +0200 Subject: [PATCH 07/23] Fix the size calculation of QHeaderView when stylesheet is used When calculating the header section size based on its contents when a stylesheet is used, the size hints from the stylesheet are used. In case if the stylesheet specifies only one of the sizes, the other is set to -1. Because of this the actual content size is ignored. The solution is to calculate the size based on the application style, in case if it's not specified in the stylesheet. Fixes: QTBUG-75615 Change-Id: I3453fa623d75b6b32832edf753de6e3e4e7f5a22 Reviewed-by: Frederik Gladhorn --- src/widgets/styles/qstylesheetstyle.cpp | 8 +++++++ .../itemviews/qheaderview/tst_qheaderview.cpp | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 88c6c288e87..3f57992311b 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -5035,6 +5035,14 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op QRenderRule subRule = renderRule(w, opt, PseudoElement_HeaderViewSection); if (subRule.hasGeometry() || subRule.hasBox() || !subRule.hasNativeBorder() || subRule.hasFont) { sz = subRule.adjustSize(csz); + if (!sz.isValid()) { + // Try to set the missing values based on the base style. + const auto baseSize = baseStyle()->sizeFromContents(ct, opt, sz, w); + if (sz.width() < 0) + sz.setWidth(baseSize.width()); + if (sz.height() < 0) + sz.setHeight(baseSize.height()); + } if (!subRule.hasGeometry()) { QSize nativeContentsSize; bool nullIcon = hdr->icon.isNull(); diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index df02815eb2c..0b120985ee9 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -216,6 +216,7 @@ private slots: void QTBUG14242_hideSectionAutoSize(); void QTBUG50171_visualRegionForSwappedItems(); void QTBUG53221_assertShiftHiddenRow(); + void QTBUG75615_sizeHintWithStylesheet(); void ensureNoIndexAtLength(); void offsetConsistent(); @@ -2606,6 +2607,26 @@ void tst_QHeaderView::QTBUG53221_assertShiftHiddenRow() QCOMPARE(tableView.verticalHeader()->isSectionHidden(2), true); } +void tst_QHeaderView::QTBUG75615_sizeHintWithStylesheet() +{ + QTableView tableView; + QStandardItemModel model(1, 1); + tableView.setModel(&model); + tableView.show(); + + const auto headerView = tableView.horizontalHeader(); + const auto oldSizeHint = headerView->sizeHint(); + QVERIFY(oldSizeHint.isValid()); + + tableView.setStyleSheet("QTableView QHeaderView::section { height: 100px;}"); + QCOMPARE(headerView->sizeHint().width(), oldSizeHint.width()); + QCOMPARE(headerView->sizeHint().height(), 100); + + tableView.setStyleSheet("QTableView QHeaderView::section { width: 100px;}"); + QCOMPARE(headerView->sizeHint().height(), oldSizeHint.height()); + QCOMPARE(headerView->sizeHint().width(), 100); +} + void protected_QHeaderView::testVisualRegionForSelection() { QRegion r = visualRegionForSelection(QItemSelection(model()->index(1, 0), model()->index(1, 2))); From 95ac2072bbbcb50ff1f8b2fd9ffbcfb4e1326b27 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 7 Jul 2015 16:18:16 +0200 Subject: [PATCH 08/23] QtWidgets: Suppress QEvent::WindowActivate when minimized Prevent call to activateWindow() for minimized windows in QWidget::setWindowState() by clearing the flag. Fixes: QTBUG-46763 Change-Id: I40389d0906438ffe251fc79f18a523ecb53edb1b Reviewed-by: Andy Shaw Reviewed-by: Richard Moe Gustavsen --- src/widgets/kernel/qwidget.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 588bed03668..74aebd1223d 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -2914,6 +2914,8 @@ void QWidget::setWindowState(Qt::WindowStates newstate) { Q_D(QWidget); Qt::WindowStates oldstate = windowState(); + if (newstate.testFlag(Qt::WindowMinimized)) // QTBUG-46763 + newstate.setFlag(Qt::WindowActive, false); if (oldstate == newstate) return; if (isWindow() && !testAttribute(Qt::WA_WState_Created)) From 332c255c696bb15db7a0510dab2a6ac214ecdb19 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 11 Oct 2019 09:43:24 +0200 Subject: [PATCH 09/23] tst_qgraphicsitem: Skip tests that fail on Wayland Task-number: QTBUG-62188 Change-Id: If0638d51bffa6ef375476c0a601c387bd05583ae Reviewed-by: Paul Olav Tvete --- .../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 fa3d4a7f230..864dd9f5900 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())); From 51f092905a2cb38feb5fef759b5ac8b417df0996 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 11 Oct 2019 15:19:45 +0200 Subject: [PATCH 10/23] 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 7aad4d8c7d4..79da26f2ca0 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); } From 05a829f923a88e69b2ceaa372820a2dcb8c083cd Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 27 Sep 2019 13:36:38 +0200 Subject: [PATCH 11/23] Win32: Consolidate registry code Add a RAII class for registry keys and use it throughout the code base. Change-Id: I666b2fbb790f83436443101d6bc1e3c0525e78df Reviewed-by: Volker Hilsheimer --- src/corelib/global/qglobal.cpp | 29 ++--- src/corelib/io/qsettings_win.cpp | 2 + src/corelib/kernel/kernel.pri | 6 +- src/corelib/kernel/qwinregistry.cpp | 120 ++++++++++++++++++ src/corelib/kernel/qwinregistry_p.h | 89 +++++++++++++ src/corelib/time/qtimezoneprivate_win.cpp | 81 ++++-------- .../windows/qwindowsfontdatabase.cpp | 52 +------- .../windows/qwindowsfontdatabase_p.h | 2 - .../windows/qwindowsfontenginedirectwrite.cpp | 7 +- .../platforms/windows/qwindowscontext.cpp | 26 +--- .../platforms/windows/qwindowsservices.cpp | 27 ++-- src/tools/bootstrap/bootstrap.pro | 1 + tests/auto/corelib/global/global.pro | 3 + .../global/qwinregistry/qwinregistry.pro | 8 ++ .../global/qwinregistry/tst_qwinregistry.cpp | 68 ++++++++++ .../corelib/io/qfileinfo/tst_qfileinfo.cpp | 18 +-- .../corelib/io/qsettings/tst_qsettings.cpp | 43 ++----- 17 files changed, 375 insertions(+), 207 deletions(-) create mode 100644 src/corelib/kernel/qwinregistry.cpp create mode 100644 src/corelib/kernel/qwinregistry_p.h create mode 100644 tests/auto/corelib/global/qwinregistry/qwinregistry.pro create mode 100644 tests/auto/corelib/global/qwinregistry/tst_qwinregistry.cpp diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 17aab17fe48..6ae5bf299ae 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -47,12 +47,11 @@ #include "qoperatingsystemversion.h" #include "qoperatingsystemversion_p.h" #if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN) || defined(Q_OS_WINRT) -#include "qoperatingsystemversion_win_p.h" -# if QT_CONFIG(settings) -# include "qsettings.h" -# include "qvariant.h" +# include "qoperatingsystemversion_win_p.h" +# ifndef Q_OS_WINRT +# include "private/qwinregistry_p.h" # endif -#endif +#endif // Q_OS_WIN || Q_OS_CYGWIN #include #include @@ -2190,28 +2189,25 @@ const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion() QT_WARNING_POP #endif -static QString readRegistryString(const QString &key, const QString &subKey) +static QString readVersionRegistryString(const wchar_t *subKey) { -#if QT_CONFIG(settings) - QSettings settings(key, QSettings::NativeFormat); - return settings.value(subKey).toString(); +#if !defined(QT_BUILD_QMAKE) && !defined(Q_OS_WINRT) + return QWinRegistryKey(HKEY_LOCAL_MACHINE, LR"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)") + .stringValue(subKey); #else - Q_UNUSED(key); - Q_UNUSED(subKey); - return QString(); + Q_UNUSED(subKey); + return QString(); #endif } -static inline QString windowsVersionKey() { return QStringLiteral(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion)"); } - static inline QString windows10ReleaseId() { - return readRegistryString(windowsVersionKey(), QStringLiteral("ReleaseId")); + return readVersionRegistryString(L"ReleaseId"); } static inline QString windows7Build() { - return readRegistryString(windowsVersionKey(), QStringLiteral("CurrentBuild")); + return readVersionRegistryString(L"CurrentBuild"); } static QString winSp_helper() @@ -3078,6 +3074,7 @@ QByteArray QSysInfo::machineUniqueId() } #elif defined(Q_OS_WIN) && !defined(Q_OS_WINRT) // Let's poke at the registry + // ### Qt 6: Use new helpers from qwinregistry.cpp (once bootstrap builds are obsolete) HKEY key = NULL; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography", 0, KEY_READ | KEY_WOW64_64KEY, &key) == ERROR_SUCCESS) { diff --git a/src/corelib/io/qsettings_win.cpp b/src/corelib/io/qsettings_win.cpp index 679212ea216..6eb318006e3 100644 --- a/src/corelib/io/qsettings_win.cpp +++ b/src/corelib/io/qsettings_win.cpp @@ -136,6 +136,8 @@ static void mergeKeySets(NameSet *dest, const QStringList &src) ** Wrappers for the insane windows registry API */ +// ### Qt 6: Use new helpers from qwinregistry.cpp (once bootstrap builds are obsolete) + // Open a key with the specified "perms". // "access" is to explicitly use the 32- or 64-bit branch. static HKEY openKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey, REGSAM access = 0) diff --git a/src/corelib/kernel/kernel.pri b/src/corelib/kernel/kernel.pri index 789bcb79273..bd3cabc01a2 100644 --- a/src/corelib/kernel/kernel.pri +++ b/src/corelib/kernel/kernel.pri @@ -88,8 +88,10 @@ win32 { SOURCES += kernel/qeventdispatcher_winrt.cpp HEADERS += kernel/qeventdispatcher_winrt_p.h } else { - SOURCES += kernel/qeventdispatcher_win.cpp - HEADERS += kernel/qeventdispatcher_win_p.h + SOURCES += kernel/qeventdispatcher_win.cpp \ + kernel/qwinregistry.cpp + HEADERS += kernel/qeventdispatcher_win_p.h \ + kernel/qwinregistry_p.h } !winrt: LIBS_PRIVATE += -lversion diff --git a/src/corelib/kernel/qwinregistry.cpp b/src/corelib/kernel/qwinregistry.cpp new file mode 100644 index 00000000000..6566dd3c763 --- /dev/null +++ b/src/corelib/kernel/qwinregistry.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwinregistry_p.h" + +#include + +#include + +QT_BEGIN_NAMESPACE + +QWinRegistryKey::QWinRegistryKey() : + m_key(nullptr) +{ +} + +// Open a key with the specified permissions (KEY_READ/KEY_WRITE). +// "access" is to explicitly use the 32- or 64-bit branch. +QWinRegistryKey::QWinRegistryKey(HKEY parentHandle, QStringView subKey, + REGSAM permissions, REGSAM access) +{ + if (RegOpenKeyEx(parentHandle, reinterpret_cast(subKey.utf16()), + 0, permissions | access, &m_key) != ERROR_SUCCESS) { + m_key = nullptr; + } +} + +QWinRegistryKey::~QWinRegistryKey() +{ + close(); +} + +void QWinRegistryKey::close() +{ + if (isValid()) { + RegCloseKey(m_key); + m_key = nullptr; + } +} + +QString QWinRegistryKey::stringValue(QStringView subKey) const +{ + QString result; + if (!isValid()) + return result; + DWORD type; + DWORD size; + auto subKeyC = reinterpret_cast(subKey.utf16()); + if (RegQueryValueEx(m_key, subKeyC, nullptr, &type, nullptr, &size) != ERROR_SUCCESS + || (type != REG_SZ && type != REG_EXPAND_SZ) || size <= 2) { + return result; + } + // Reserve more for rare cases where trailing '\0' are missing in registry, + // otherwise chop off the '\0' received. + QString buffer(int(size / sizeof(wchar_t)), Qt::Uninitialized); + if (RegQueryValueEx(m_key, subKeyC, nullptr, &type, + reinterpret_cast(buffer.data()), &size) == ERROR_SUCCESS) { + if (buffer.endsWith(QChar::Null)) + buffer.chop(1); + } else { + buffer.clear(); + } + return buffer; +} + +QPair QWinRegistryKey::dwordValue(QStringView subKey) const +{ + if (!isValid()) + return qMakePair(0, false); + DWORD type; + auto subKeyC = reinterpret_cast(subKey.utf16()); + if (RegQueryValueEx(m_key, subKeyC, nullptr, &type, nullptr, nullptr) != ERROR_SUCCESS + || type != REG_DWORD) { + return qMakePair(0, false); + } + DWORD value = 0; + DWORD size = sizeof(value); + const bool ok = + RegQueryValueEx(m_key, subKeyC, nullptr, nullptr, + reinterpret_cast(&value), &size) == ERROR_SUCCESS; + return qMakePair(value, ok); +} + +QT_END_NAMESPACE diff --git a/src/corelib/kernel/qwinregistry_p.h b/src/corelib/kernel/qwinregistry_p.h new file mode 100644 index 00000000000..d249a97988a --- /dev/null +++ b/src/corelib/kernel/qwinregistry_p.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWINREGISTRY_H +#define QWINREGISTRY_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +class Q_CORE_EXPORT QWinRegistryKey +{ +public: + Q_DISABLE_COPY(QWinRegistryKey) + + QWinRegistryKey(); + explicit QWinRegistryKey(HKEY parentHandle, QStringView subKey, + REGSAM permissions = KEY_READ, REGSAM access = 0); + ~QWinRegistryKey(); + + QWinRegistryKey(QWinRegistryKey &&other) noexcept { swap(other); } + QWinRegistryKey &operator=(QWinRegistryKey &&other) noexcept { swap(other); return *this; } + + void swap(QWinRegistryKey &other) noexcept { qSwap(m_key, other.m_key); } + + bool isValid() const { return m_key != nullptr; } + operator HKEY() const { return m_key; } + void close(); + + QString stringValue(QStringView subKey) const; + QPair dwordValue(QStringView subKey) const; + +private: + HKEY m_key; +}; + +QT_END_NAMESPACE + +#endif // QWINREGISTRY_H diff --git a/src/corelib/time/qtimezoneprivate_win.cpp b/src/corelib/time/qtimezoneprivate_win.cpp index 5a480222e08..0fec5355b2c 100644 --- a/src/corelib/time/qtimezoneprivate_win.cpp +++ b/src/corelib/time/qtimezoneprivate_win.cpp @@ -46,13 +46,14 @@ #include -QT_BEGIN_NAMESPACE - #ifndef Q_OS_WINRT +#include // The registry-based timezone backend is not available on WinRT, which falls back to equivalent APIs. #define QT_USE_REGISTRY_TIMEZONE 1 #endif +QT_BEGIN_NAMESPACE + /* Private @@ -71,8 +72,8 @@ QT_BEGIN_NAMESPACE // Vista introduced support for historic data, see MSDN docs on DYNAMIC_TIME_ZONE_INFORMATION // http://msdn.microsoft.com/en-gb/library/windows/desktop/ms724253%28v=vs.85%29.aspx #ifdef QT_USE_REGISTRY_TIMEZONE -static const char tzRegPath[] = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"; -static const char currTzRegPath[] = "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation"; +static const wchar_t tzRegPath[] = LR"(SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones)"; +static const wchar_t currTzRegPath[] = LR"(SYSTEM\CurrentControlSet\Control\TimeZoneInformation)"; #endif enum { @@ -138,27 +139,6 @@ bool equalTzi(const TIME_ZONE_INFORMATION &tzi1, const TIME_ZONE_INFORMATION &tz } #ifdef QT_USE_REGISTRY_TIMEZONE -bool openRegistryKey(const QString &keyPath, HKEY *key) -{ - return RegOpenKeyEx(HKEY_LOCAL_MACHINE, reinterpret_cast(keyPath.utf16()), - 0, KEY_READ, key) == ERROR_SUCCESS; -} - -QString readRegistryString(const HKEY &key, const wchar_t *value) -{ - wchar_t buffer[MAX_PATH] = {0}; - DWORD size = sizeof(wchar_t) * MAX_PATH; - RegQueryValueEx(key, value, nullptr, nullptr, reinterpret_cast(buffer), &size); - return QString::fromWCharArray(buffer); -} - -int readRegistryValue(const HKEY &key, const wchar_t *value) -{ - DWORD buffer; - DWORD size = sizeof(buffer); - RegQueryValueEx(key, value, nullptr, nullptr, reinterpret_cast(&buffer), &size); - return buffer; -} QWinTimeZonePrivate::QWinTransitionRule readRegistryRule(const HKEY &key, const wchar_t *value, bool *ok) @@ -185,12 +165,11 @@ TIME_ZONE_INFORMATION getRegistryTzi(const QByteArray &windowsId, bool *ok) TIME_ZONE_INFORMATION tzi; REG_TZI_FORMAT regTzi; DWORD regTziSize = sizeof(regTzi); - HKEY key = NULL; - const QString tziKeyPath = QString::fromUtf8(tzRegPath) + QLatin1Char('\\') + const QString tziKeyPath = QString::fromWCharArray(tzRegPath) + QLatin1Char('\\') + QString::fromUtf8(windowsId); - if (openRegistryKey(tziKeyPath, &key)) { - + QWinRegistryKey key(HKEY_LOCAL_MACHINE, tziKeyPath); + if (key.isValid()) { DWORD size = sizeof(tzi.DaylightName); RegQueryValueEx(key, L"Dlt", nullptr, nullptr, reinterpret_cast(tzi.DaylightName), &size); @@ -206,8 +185,6 @@ TIME_ZONE_INFORMATION getRegistryTzi(const QByteArray &windowsId, bool *ok) tzi.DaylightDate = regTzi.DaylightDate; *ok = true; } - - RegCloseKey(key); } return tzi; @@ -299,8 +276,8 @@ QList availableWindowsIds() #ifdef QT_USE_REGISTRY_TIMEZONE // TODO Consider caching results in a global static, very unlikely to change. QList list; - HKEY key = NULL; - if (openRegistryKey(QString::fromUtf8(tzRegPath), &key)) { + QWinRegistryKey key(HKEY_LOCAL_MACHINE, tzRegPath); + if (key.isValid()) { DWORD idCount = 0; if (RegQueryInfoKey(key, 0, 0, 0, &idCount, 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS && idCount > 0) { @@ -311,7 +288,6 @@ QList availableWindowsIds() list.append(QString::fromWCharArray(buffer).toUtf8()); } } - RegCloseKey(key); } return list; #else // QT_USE_REGISTRY_TIMEZONE @@ -325,15 +301,10 @@ QByteArray windowsSystemZoneId() { #ifdef QT_USE_REGISTRY_TIMEZONE // On Vista and later is held in the value TimeZoneKeyName in key currTzRegPath - QString id; - HKEY key = NULL; - QString tziKeyPath = QString::fromUtf8(currTzRegPath); - if (openRegistryKey(tziKeyPath, &key)) { - id = readRegistryString(key, L"TimeZoneKeyName"); - RegCloseKey(key); - if (!id.isEmpty()) - return std::move(id).toUtf8(); - } + const QString id = QWinRegistryKey(HKEY_LOCAL_MACHINE, currTzRegPath) + .stringValue(L"TimeZoneKeyName"); + if (!id.isEmpty()) + return id.toUtf8(); // On XP we have to iterate over the zones until we find a match on // names/offsets with the current data @@ -575,22 +546,22 @@ void QWinTimeZonePrivate::init(const QByteArray &ianaId) if (!m_windowsId.isEmpty()) { #ifdef QT_USE_REGISTRY_TIMEZONE // Open the base TZI for the time zone - HKEY baseKey = NULL; - const QString baseKeyPath = QString::fromUtf8(tzRegPath) + QLatin1Char('\\') + const QString baseKeyPath = QString::fromWCharArray(tzRegPath) + QLatin1Char('\\') + QString::fromUtf8(m_windowsId); - if (openRegistryKey(baseKeyPath, &baseKey)) { + QWinRegistryKey baseKey(HKEY_LOCAL_MACHINE, baseKeyPath); + if (baseKey.isValid()) { // Load the localized names - m_displayName = readRegistryString(baseKey, L"Display"); - m_standardName = readRegistryString(baseKey, L"Std"); - m_daylightName = readRegistryString(baseKey, L"Dlt"); + m_displayName = baseKey.stringValue(L"Display"); + m_standardName = baseKey.stringValue(L"Std"); + m_daylightName = baseKey.stringValue(L"Dlt"); // On Vista and later the optional dynamic key holds historic data const QString dynamicKeyPath = baseKeyPath + QLatin1String("\\Dynamic DST"); - HKEY dynamicKey = NULL; - if (openRegistryKey(dynamicKeyPath, &dynamicKey)) { + QWinRegistryKey dynamicKey(HKEY_LOCAL_MACHINE, dynamicKeyPath); + if (dynamicKey.isValid()) { // Find out the start and end years stored, then iterate over them - int startYear = readRegistryValue(dynamicKey, L"FirstEntry"); - int endYear = readRegistryValue(dynamicKey, L"LastEntry"); - for (int year = startYear; year <= endYear; ++year) { + const auto startYear = dynamicKey.dwordValue(L"FirstEntry"); + const auto endYear = dynamicKey.dwordValue(L"LastEntry"); + for (int year = int(startYear.first); year <= int(endYear.first); ++year) { bool ruleOk; QWinTransitionRule rule = readRegistryRule(dynamicKey, reinterpret_cast(QString::number(year).utf16()), @@ -611,7 +582,6 @@ void QWinTimeZonePrivate::init(const QByteArray &ianaId) m_tranRules.append(rule); } } - RegCloseKey(dynamicKey); } else { // No dynamic data so use the base data bool ruleOk; @@ -620,7 +590,6 @@ void QWinTimeZonePrivate::init(const QByteArray &ianaId) if (ruleOk) m_tranRules.append(rule); } - RegCloseKey(baseKey); } #else // QT_USE_REGISTRY_TIMEZONE if (gTimeZones->isEmpty()) diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp index 79f7eb3d43e..011476cf139 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include @@ -1210,33 +1211,8 @@ static int QT_WIN_CALLBACK populateFontFamilies(const LOGFONT *logFont, const TE void QWindowsFontDatabase::addDefaultEUDCFont() { - QString path; - { - HKEY key; - if (RegOpenKeyEx(HKEY_CURRENT_USER, - L"EUDC\\1252", - 0, - KEY_READ, - &key) != ERROR_SUCCESS) { - return; - } - - WCHAR value[MAX_PATH]; - DWORD bufferSize = sizeof(value); - ZeroMemory(value, bufferSize); - - if (RegQueryValueEx(key, - L"SystemDefaultEUDCFont", - nullptr, - nullptr, - reinterpret_cast(value), - &bufferSize) == ERROR_SUCCESS) { - path = QString::fromWCharArray(value); - } - - RegCloseKey(key); - } - + const QString path = QWinRegistryKey(HKEY_CURRENT_USER, LR"(EUDC\1252)") + .stringValue(L"SystemDefaultEUDCFont"); if (!path.isEmpty()) { QFile file(path); if (!file.open(QIODevice::ReadOnly)) { @@ -2105,28 +2081,6 @@ int QWindowsFontDatabase::defaultVerticalDPI() return vDPI; } -QString QWindowsFontDatabase::readRegistryString(HKEY parentHandle, const wchar_t *keyPath, const wchar_t *keyName) -{ - QString result; - HKEY handle = 0; - if (RegOpenKeyEx(parentHandle, keyPath, 0, KEY_READ, &handle) == ERROR_SUCCESS) { - // get the size and type of the value - DWORD dataType; - DWORD dataSize; - if (RegQueryValueEx(handle, keyName, 0, &dataType, 0, &dataSize) == ERROR_SUCCESS) { - if (dataType == REG_SZ || dataType == REG_EXPAND_SZ) { - dataSize += 2; // '\0' missing? - QVarLengthArray data(dataSize); - data[dataSize - 2] = data[dataSize - 1] = '\0'; - if (RegQueryValueEx(handle, keyName, 0, 0, data.data(), &dataSize) == ERROR_SUCCESS) - result = QString::fromWCharArray(reinterpret_cast(data.data())); - } - } - RegCloseKey(handle); - } - return result; -} - bool QWindowsFontDatabase::isPrivateFontFamily(const QString &family) const { return m_eudcFonts.contains(family) || QPlatformFontDatabase::isPrivateFontFamily(family); diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h index a1cab17a87c..f132e69d4dd 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h @@ -133,8 +133,6 @@ public: static void setFontOptions(unsigned options); static unsigned fontOptions(); - static QString readRegistryString(HKEY parentHandle, const wchar_t *keyPath, const wchar_t *keyName); - private: void removeApplicationFonts(); void addDefaultEUDCFont(); diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp index a4490a66643..e796c18e793 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontenginedirectwrite.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -945,10 +946,10 @@ void QWindowsFontEngineDirectWrite::initFontInfo(const QFontDef &request, QString QWindowsFontEngineDirectWrite::fontNameSubstitute(const QString &familyName) { - const wchar_t key[] = L"Software\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes"; const QString substitute = - QWindowsFontDatabase::readRegistryString(HKEY_LOCAL_MACHINE, key, - reinterpret_cast(familyName.utf16())); + QWinRegistryKey(HKEY_LOCAL_MACHINE, + LR"(Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes)") + .stringValue(familyName); return substitute.isEmpty() ? familyName : substitute; } diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index bb349f08a7a..f7d04b667d1 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -79,6 +79,7 @@ #include #include #include +#include #include @@ -1518,28 +1519,13 @@ QTouchDevice *QWindowsContext::touchDevice() const d->m_pointerHandler.touchDevice() : d->m_mouseHandler.touchDevice(); } -static DWORD readDwordRegistrySetting(const wchar_t *regKey, const wchar_t *subKey, DWORD defaultValue) -{ - DWORD result = defaultValue; - HKEY handle; - if (RegOpenKeyEx(HKEY_CURRENT_USER, regKey, 0, KEY_READ, &handle) == ERROR_SUCCESS) { - DWORD type; - if (RegQueryValueEx(handle, subKey, nullptr, &type, nullptr, nullptr) == ERROR_SUCCESS - && type == REG_DWORD) { - DWORD value; - DWORD size = sizeof(result); - if (RegQueryValueEx(handle, subKey, nullptr, nullptr, reinterpret_cast(&value), &size) == ERROR_SUCCESS) - result = value; - } - RegCloseKey(handle); - } - return result; -} - DWORD QWindowsContext::readAdvancedExplorerSettings(const wchar_t *subKey, DWORD defaultValue) { - return readDwordRegistrySetting(L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", - subKey, defaultValue); + const auto value = + QWinRegistryKey(HKEY_CURRENT_USER, + LR"(Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced)") + .dwordValue(subKey); + return value.second ? value.first : defaultValue; } static inline bool isEmptyRect(const RECT &rect) diff --git a/src/plugins/platforms/windows/qwindowsservices.cpp b/src/plugins/platforms/windows/qwindowsservices.cpp index b2b1dee2322..83b052bb496 100644 --- a/src/plugins/platforms/windows/qwindowsservices.cpp +++ b/src/plugins/platforms/windows/qwindowsservices.cpp @@ -45,6 +45,8 @@ #include #include +#include + #include #include @@ -78,35 +80,24 @@ static inline QString mailCommand() const wchar_t mailUserKey[] = L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\mailto\\UserChoice"; - wchar_t command[MAX_PATH] = {0}; // Check if user has set preference, otherwise use default. - HKEY handle; - QString keyName; - if (!RegOpenKeyEx(HKEY_CURRENT_USER, mailUserKey, 0, KEY_READ, &handle)) { - DWORD bufferSize = BufferSize; - if (!RegQueryValueEx(handle, L"Progid", nullptr, nullptr, reinterpret_cast(command), &bufferSize)) - keyName = QString::fromWCharArray(command); - RegCloseKey(handle); - } + QString keyName = QWinRegistryKey(HKEY_CURRENT_USER, mailUserKey) + .stringValue( L"Progid"); const QLatin1String mailto = keyName.isEmpty() ? QLatin1String("mailto") : QLatin1String(); keyName += mailto + QLatin1String("\\Shell\\Open\\Command"); if (debug) qDebug() << __FUNCTION__ << "keyName=" << keyName; - command[0] = 0; - if (!RegOpenKeyExW(HKEY_CLASSES_ROOT, reinterpret_cast(keyName.utf16()), 0, KEY_READ, &handle)) { - DWORD bufferSize = BufferSize; - RegQueryValueEx(handle, L"", nullptr, nullptr, reinterpret_cast(command), &bufferSize); - RegCloseKey(handle); - } + const QString command = QWinRegistryKey(HKEY_CLASSES_ROOT, keyName).stringValue(L""); // QTBUG-57816: As of Windows 10, if there is no mail client installed, an entry like // "rundll32.exe .. url.dll,MailToProtocolHandler %l" is returned. Launching it // silently fails or brings up a broken dialog after a long time, so exclude it and // fall back to ShellExecute() which brings up the URL assocation dialog. - if (!command[0] || wcsstr(command, L",MailToProtocolHandler") != nullptr) + if (command.isEmpty() || command.contains(QLatin1String(",MailToProtocolHandler"))) return QString(); wchar_t expandedCommand[MAX_PATH] = {0}; - return ExpandEnvironmentStrings(command, expandedCommand, MAX_PATH) ? - QString::fromWCharArray(expandedCommand) : QString::fromWCharArray(command); + return ExpandEnvironmentStrings(reinterpret_cast(command.utf16()), + expandedCommand, MAX_PATH) + ? QString::fromWCharArray(expandedCommand) : command; } static inline bool launchMail(const QUrl &url) diff --git a/src/tools/bootstrap/bootstrap.pro b/src/tools/bootstrap/bootstrap.pro index 09a1c680012..9863ff5e69c 100644 --- a/src/tools/bootstrap/bootstrap.pro +++ b/src/tools/bootstrap/bootstrap.pro @@ -126,6 +126,7 @@ win32:SOURCES += ../../corelib/global/qoperatingsystemversion_win.cpp \ ../../corelib/kernel/qsharedmemory_win.cpp \ ../../corelib/kernel/qsystemsemaphore_win.cpp \ ../../corelib/plugin/qsystemlibrary.cpp \ + ../../corelib/kernel/qwinregistry.cpp \ mac { SOURCES += \ diff --git a/tests/auto/corelib/global/global.pro b/tests/auto/corelib/global/global.pro index 139e0736448..0f77d191ee4 100644 --- a/tests/auto/corelib/global/global.pro +++ b/tests/auto/corelib/global/global.pro @@ -12,3 +12,6 @@ SUBDIRS=\ qtendian \ qglobalstatic \ qhooks + +win32:!winrt: SUBDIRS += \ + qwinregistry diff --git a/tests/auto/corelib/global/qwinregistry/qwinregistry.pro b/tests/auto/corelib/global/qwinregistry/qwinregistry.pro new file mode 100644 index 00000000000..eab5df9dc3f --- /dev/null +++ b/tests/auto/corelib/global/qwinregistry/qwinregistry.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +QT += testlib core-private +QT -= gui + +TARGET = tst_qwinregistry +CONFIG += console + +SOURCES += tst_qwinregistry.cpp diff --git a/tests/auto/corelib/global/qwinregistry/tst_qwinregistry.cpp b/tests/auto/corelib/global/qwinregistry/tst_qwinregistry.cpp new file mode 100644 index 00000000000..ac811de2a1b --- /dev/null +++ b/tests/auto/corelib/global/qwinregistry/tst_qwinregistry.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +#include + +#include + +class tst_QWinRegistry : public QObject +{ + Q_OBJECT + +public Q_SLOTS: + void initTestCase(); + +private Q_SLOTS: + void values(); +}; + +void tst_QWinRegistry::initTestCase() +{ + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows10) + QSKIP("This test requires registry values present in Windows 10"); +} + +void tst_QWinRegistry::values() +{ + QWinRegistryKey key(HKEY_LOCAL_MACHINE, LR"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)"); + QVERIFY(key.isValid()); + QVERIFY(!key.stringValue(L"ProductName").isEmpty()); + QVERIFY(key.stringValue(L"NonExistingKey").isEmpty()); + auto majorVersion = key.dwordValue(L"CurrentMajorVersionNumber"); + QVERIFY(majorVersion.second); + QVERIFY(majorVersion.first > 0); + auto nonExistingValue = key.dwordValue(L"NonExistingKey"); + QVERIFY(!nonExistingValue.second); + QCOMPARE(nonExistingValue.first, 0u); +} + +QTEST_APPLESS_MAIN(tst_QWinRegistry); + +#include "tst_qwinregistry.moc" diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 16fcafa2480..0597a7d5210 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -49,6 +49,7 @@ #ifdef Q_OS_WIN #include #if !defined(Q_OS_WINRT) +#include #include #endif #endif @@ -1243,17 +1244,12 @@ void tst_QFileInfo::fileTimes() //In Vista the last-access timestamp is not updated when the file is accessed/touched (by default). //To enable this the HKLM\SYSTEM\CurrentControlSet\Control\FileSystem\NtfsDisableLastAccessUpdate //is set to 0, in the test machine. - HKEY key; - if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\FileSystem", - 0, KEY_READ, &key)) { - DWORD disabledAccessTimes = 0; - DWORD size = sizeof(DWORD); - LONG error = RegQueryValueEx(key, L"NtfsDisableLastAccessUpdate" - , NULL, NULL, (LPBYTE)&disabledAccessTimes, &size); - if (ERROR_SUCCESS == error && disabledAccessTimes) - noAccessTime = true; - RegCloseKey(key); - } + const auto disabledAccessTimes = + QWinRegistryKey(HKEY_LOCAL_MACHINE, + LR"(SYSTEM\CurrentControlSet\Control\FileSystem)") + .dwordValue(L"NtfsDisableLastAccessUpdate"); + if (disabledAccessTimes.second && disabledAccessTimes.first != 0) + noAccessTime = true; #endif if (noAccessTime) diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 289590a2338..0f07ba4bb2e 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -54,6 +54,9 @@ #if defined(Q_OS_WIN) #include +#ifndef Q_OS_WINRT +# include +#endif #else #include #endif @@ -3623,16 +3626,13 @@ void tst_QSettings::recursionBug() #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) -static DWORD readKeyType(HKEY handle, const QString &rSubKey) +static DWORD readKeyType(HKEY handle, QStringView rSubKey) { DWORD dataType; DWORD dataSize; - LONG res = RegQueryValueEx(handle, reinterpret_cast(rSubKey.utf16()), 0, &dataType, 0, &dataSize); - - if (res == ERROR_SUCCESS) - return dataType; - - return 0; + LONG res = RegQueryValueEx(handle, reinterpret_cast(rSubKey.utf16()), + nullptr, &dataType, nullptr, &dataSize); + return res == ERROR_SUCCESS ? dataType : 0; } // This is a regression test for QTBUG-13249, where QSettings was storing @@ -3652,29 +3652,12 @@ void tst_QSettings::consistentRegistryStorage() QCOMPARE(settings1.value("quint64_value").toULongLong(), (quint64)1024); settings1.sync(); - HKEY handle; - LONG res; - QString keyName = "Software\\software.org\\KillerAPP"; - res = RegOpenKeyEx(HKEY_CURRENT_USER, reinterpret_cast(keyName.utf16()), 0, KEY_READ, &handle); - if (res == ERROR_SUCCESS) - { - DWORD dataType; - dataType = readKeyType(handle, QString("qint32_value")); - if (dataType != 0) { - QCOMPARE((int)REG_DWORD, (int)dataType); - } - dataType = readKeyType(handle, QString("quint32_value")); - if (dataType != 0) { - QCOMPARE((int)REG_DWORD, (int)dataType); - } - dataType = readKeyType(handle, QString("qint64_value")); - if (dataType != 0) { - QCOMPARE((int)REG_QWORD, (int)dataType); - } - dataType = readKeyType(handle, QString("quint64_value")); - if (dataType != 0) { - QCOMPARE((int)REG_QWORD, (int)dataType); - } + QWinRegistryKey handle(HKEY_CURRENT_USER, LR"(Software\software.org\KillerAPP)"); + if (handle.isValid()) { + QCOMPARE(readKeyType(handle, L"qint32_value"), DWORD(REG_DWORD)); + QCOMPARE(readKeyType(handle, L"quint32_value"), DWORD(REG_DWORD)); + QCOMPARE(readKeyType(handle, L"qint64_value"), DWORD(REG_QWORD)); + QCOMPARE(readKeyType(handle, L"quint64_value"), DWORD(REG_QWORD)); RegCloseKey(handle); } } From 3026c0630dedb2fd8744e4cd9505f90c86b1a1cd Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Fri, 4 Oct 2019 10:10:32 +0200 Subject: [PATCH 12/23] pass QSqlDatabase by const & Change-Id: I326c09ab9313098470cb657571f67755fd7810c7 Reviewed-by: Allan Sandfeld Jensen --- src/sql/kernel/qsqlquery.cpp | 6 +++--- src/sql/kernel/qsqlquery.h | 4 ++-- src/sql/models/qsqlrelationaltablemodel.cpp | 6 +++--- src/sql/models/qsqlrelationaltablemodel.h | 2 +- src/sql/models/qsqltablemodel.cpp | 4 ++-- src/sql/models/qsqltablemodel.h | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp index e7c444f5b93..8947ed1084a 100644 --- a/src/sql/kernel/qsqlquery.cpp +++ b/src/sql/kernel/qsqlquery.cpp @@ -258,7 +258,7 @@ QSqlQuery::QSqlQuery(const QSqlQuery& other) /*! \internal */ -static void qInit(QSqlQuery *q, const QString& query, QSqlDatabase db) +static void qInit(QSqlQuery *q, const QString& query, const QSqlDatabase &db) { QSqlDatabase database = db; if (!database.isValid()) @@ -278,7 +278,7 @@ static void qInit(QSqlQuery *q, const QString& query, QSqlDatabase db) \sa QSqlDatabase */ -QSqlQuery::QSqlQuery(const QString& query, QSqlDatabase db) +QSqlQuery::QSqlQuery(const QString& query, const QSqlDatabase &db) { d = QSqlQueryPrivate::shared_null(); qInit(this, query, db); @@ -291,7 +291,7 @@ QSqlQuery::QSqlQuery(const QString& query, QSqlDatabase db) \sa QSqlDatabase */ -QSqlQuery::QSqlQuery(QSqlDatabase db) +QSqlQuery::QSqlQuery(const QSqlDatabase &db) { d = QSqlQueryPrivate::shared_null(); qInit(this, QString(), db); diff --git a/src/sql/kernel/qsqlquery.h b/src/sql/kernel/qsqlquery.h index cbbc25c4ec6..3be04c492c8 100644 --- a/src/sql/kernel/qsqlquery.h +++ b/src/sql/kernel/qsqlquery.h @@ -59,8 +59,8 @@ class Q_SQL_EXPORT QSqlQuery { public: explicit QSqlQuery(QSqlResult *r); - explicit QSqlQuery(const QString& query = QString(), QSqlDatabase db = QSqlDatabase()); - explicit QSqlQuery(QSqlDatabase db); + explicit QSqlQuery(const QString& query = QString(), const QSqlDatabase &db = QSqlDatabase()); + explicit QSqlQuery(const QSqlDatabase &db); QSqlQuery(const QSqlQuery& other); QSqlQuery& operator=(const QSqlQuery& other); ~QSqlQuery(); diff --git a/src/sql/models/qsqlrelationaltablemodel.cpp b/src/sql/models/qsqlrelationaltablemodel.cpp index 34be010474a..b0e26d7378a 100644 --- a/src/sql/models/qsqlrelationaltablemodel.cpp +++ b/src/sql/models/qsqlrelationaltablemodel.cpp @@ -161,7 +161,7 @@ struct QRelation class QRelatedTableModel : public QSqlTableModel { public: - QRelatedTableModel(QRelation *rel, QObject *parent = 0, QSqlDatabase db = QSqlDatabase()); + QRelatedTableModel(QRelation *rel, QObject *parent = 0, const QSqlDatabase &db = QSqlDatabase()); bool select() override; private: bool firstSelect; @@ -245,7 +245,7 @@ bool QRelation::isValid() -QRelatedTableModel::QRelatedTableModel(QRelation *rel, QObject *parent, QSqlDatabase db) : +QRelatedTableModel::QRelatedTableModel(QRelation *rel, QObject *parent, const QSqlDatabase &db) : QSqlTableModel(parent, db), firstSelect(true), relation(rel) { } @@ -410,7 +410,7 @@ void QSqlRelationalTableModelPrivate::clearCache() and the database connection to \a db. If \a db is not valid, the default database connection will be used. */ -QSqlRelationalTableModel::QSqlRelationalTableModel(QObject *parent, QSqlDatabase db) +QSqlRelationalTableModel::QSqlRelationalTableModel(QObject *parent, const QSqlDatabase &db) : QSqlTableModel(*new QSqlRelationalTableModelPrivate, parent, db) { } diff --git a/src/sql/models/qsqlrelationaltablemodel.h b/src/sql/models/qsqlrelationaltablemodel.h index 1929bd320a7..2ebadaabd1f 100644 --- a/src/sql/models/qsqlrelationaltablemodel.h +++ b/src/sql/models/qsqlrelationaltablemodel.h @@ -91,7 +91,7 @@ public: }; explicit QSqlRelationalTableModel(QObject *parent = nullptr, - QSqlDatabase db = QSqlDatabase()); + const QSqlDatabase &db = QSqlDatabase()); virtual ~QSqlRelationalTableModel(); QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const override; diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index 4bc9a8c2f84..a5232590d00 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -291,7 +291,7 @@ bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement, The default edit strategy is \l OnRowChange. */ -QSqlTableModel::QSqlTableModel(QObject *parent, QSqlDatabase db) +QSqlTableModel::QSqlTableModel(QObject *parent, const QSqlDatabase &db) : QSqlQueryModel(*new QSqlTableModelPrivate, parent) { Q_D(QSqlTableModel); @@ -300,7 +300,7 @@ QSqlTableModel::QSqlTableModel(QObject *parent, QSqlDatabase db) /*! \internal */ -QSqlTableModel::QSqlTableModel(QSqlTableModelPrivate &dd, QObject *parent, QSqlDatabase db) +QSqlTableModel::QSqlTableModel(QSqlTableModelPrivate &dd, QObject *parent, const QSqlDatabase &db) : QSqlQueryModel(dd, parent) { Q_D(QSqlTableModel); diff --git a/src/sql/models/qsqltablemodel.h b/src/sql/models/qsqltablemodel.h index eba27e60ec2..1ac8bd9b049 100644 --- a/src/sql/models/qsqltablemodel.h +++ b/src/sql/models/qsqltablemodel.h @@ -62,7 +62,7 @@ class Q_SQL_EXPORT QSqlTableModel: public QSqlQueryModel public: enum EditStrategy {OnFieldChange, OnRowChange, OnManualSubmit}; - explicit QSqlTableModel(QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase()); + explicit QSqlTableModel(QObject *parent = nullptr, const QSqlDatabase &db = QSqlDatabase()); virtual ~QSqlTableModel(); virtual void setTable(const QString &tableName); @@ -127,7 +127,7 @@ Q_SIGNALS: void beforeDelete(int row); protected: - QSqlTableModel(QSqlTableModelPrivate &dd, QObject *parent = nullptr, QSqlDatabase db = QSqlDatabase()); + QSqlTableModel(QSqlTableModelPrivate &dd, QObject *parent = nullptr, const QSqlDatabase &db = QSqlDatabase()); virtual bool updateRowInTable(int row, const QSqlRecord &values); virtual bool insertRowIntoTable(const QSqlRecord &values); From 027d45cb57a7cf20b2714509250a87f1e8842b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sat, 5 Oct 2019 13:22:42 +0200 Subject: [PATCH 13/23] macOS: Simplify Objective-C namespacing We only need to use the QT_MANGLE_NAMESPACE macro when declaring the interface of the class. As long as we couple that with an alias declaration using QT_NAMESPACE_ALIAS_OBJC_CLASS, any further uses of the class name can be un-namespaced, including declaring categories on the class. The only snag with QT_NAMESPACE_ALIAS_OBJC_CLASS is that it can only be used once per class and translation unit, so forward declarations get hairy, but we can avoid that by just including the headers instead. Change-Id: I333bcd18fe1e18d81fbd560b0941c98b1c32460e Reviewed-by: Timur Pocheptsov --- .../bearer/corewlan/qcorewlanengine.mm | 9 ++-- .../platforms/cocoa/qcocoaaccessibility.h | 6 +-- .../cocoa/qcocoaaccessibilityelement.h | 2 - .../platforms/cocoa/qcocoaapplication.mm | 6 +-- .../cocoa/qcocoaapplicationdelegate.h | 10 ++--- .../cocoa/qcocoaapplicationdelegate.mm | 2 +- .../cocoa/qcocoacolordialoghelper.mm | 4 +- .../platforms/cocoa/qcocoafiledialoghelper.h | 10 ++++- .../platforms/cocoa/qcocoafiledialoghelper.mm | 21 --------- .../platforms/cocoa/qcocoafontdialoghelper.mm | 4 +- src/plugins/platforms/cocoa/qcocoamenu.h | 5 +-- src/plugins/platforms/cocoa/qcocoamenubar.mm | 6 +-- src/plugins/platforms/cocoa/qcocoansmenu.h | 13 +----- .../platforms/cocoa/qcocoasystemtrayicon.mm | 11 ++--- src/plugins/platforms/cocoa/qcocoatheme.h | 2 - src/plugins/platforms/cocoa/qnsview.h | 43 ++++++++----------- src/plugins/platforms/cocoa/qnsview.mm | 26 +++++------ .../platforms/cocoa/qnsview_accessibility.mm | 2 +- .../platforms/cocoa/qnsview_complextext.mm | 4 +- .../platforms/cocoa/qnsview_dragging.mm | 2 +- .../platforms/cocoa/qnsview_drawing.mm | 2 +- .../platforms/cocoa/qnsview_gestures.mm | 2 +- src/plugins/platforms/cocoa/qnsview_keys.mm | 4 +- src/plugins/platforms/cocoa/qnsview_menus.mm | 4 +- src/plugins/platforms/cocoa/qnsview_mouse.mm | 8 ++-- src/plugins/platforms/cocoa/qnsview_tablet.mm | 2 +- src/plugins/platforms/cocoa/qnsview_touch.mm | 2 +- .../platforms/cocoa/qprintengine_mac_p.h | 6 +-- 28 files changed, 89 insertions(+), 129 deletions(-) diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index 4644b5af9fb..66f2ed017b7 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -62,12 +62,11 @@ extern "C" { // Otherwise it won't find CWKeychain* symbols at link time #include @interface QT_MANGLE_NAMESPACE(QNSListener) : NSObject - @property (assign) QCoreWlanEngine* engine; - @end +QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSListener); -@implementation QT_MANGLE_NAMESPACE(QNSListener) { +@implementation QNSListener { NSNotificationCenter *notificationCenter; CWWiFiClient *client; QCoreWlanEngine *engine; @@ -88,7 +87,7 @@ extern "C" { // Otherwise it won't find CWKeychain* symbols at link time return self; } -static QT_MANGLE_NAMESPACE(QNSListener) *listener = 0; +static QNSListener *listener = 0; -(void)dealloc { @@ -415,7 +414,7 @@ void QCoreWlanEngine::initialize() QMacAutoReleasePool pool; if ([[CWWiFiClient interfaceNames] count] > 0 && !listener) { - listener = [[QT_MANGLE_NAMESPACE(QNSListener) alloc] init]; + listener = [QNSListener alloc] init]; listener.engine = this; hasWifi = true; } else { diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibility.h b/src/plugins/platforms/cocoa/qcocoaaccessibility.h index 457c158ddc4..539d8760942 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibility.h +++ b/src/plugins/platforms/cocoa/qcocoaaccessibility.h @@ -44,9 +44,9 @@ #include #include -#ifndef QT_NO_ACCESSIBILITY +#include "qcocoaaccessibilityelement.h" -@class QT_MANGLE_NAMESPACE(QMacAccessibilityElement); +#ifndef QT_NO_ACCESSIBILITY QT_BEGIN_NAMESPACE @@ -84,7 +84,7 @@ namespace QCocoaAccessible { NSString *macRole(QAccessibleInterface *interface); NSString *macSubrole(QAccessibleInterface *interface); bool shouldBeIgnored(QAccessibleInterface *interface); -NSArray *unignoredChildren(QAccessibleInterface *interface); +NSArray *unignoredChildren(QAccessibleInterface *interface); NSString *getTranslatedAction(const QString &qtAction); QString translateAction(NSString *nsAction, QAccessibleInterface *interface); bool hasValueAttribute(QAccessibleInterface *interface); diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.h b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.h index 7fbe7293817..141ce6bf1a8 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.h +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.h @@ -50,8 +50,6 @@ #import -@class QT_MANGLE_NAMESPACE(QMacAccessibilityElement); - @interface QT_MANGLE_NAMESPACE(QMacAccessibilityElement) : NSObject - (instancetype)initWithId:(QAccessible::Id)anId; diff --git a/src/plugins/platforms/cocoa/qcocoaapplication.mm b/src/plugins/platforms/cocoa/qcocoaapplication.mm index 340191622a2..c6029bcf03a 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplication.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplication.mm @@ -144,7 +144,7 @@ static void qt_maybeSendKeyEquivalentUpEvent(NSEvent *event) } } -@implementation QT_MANGLE_NAMESPACE(QNSApplication) +@implementation QNSApplication - (void)QT_MANGLE_NAMESPACE(qt_sendEvent_original):(NSEvent *)event { @@ -188,7 +188,7 @@ void qt_redirectNSApplicationSendEvent() // can be unloaded. return; - if ([NSApp isMemberOfClass:[QT_MANGLE_NAMESPACE(QNSApplication) class]]) { + if ([NSApp isMemberOfClass:[QNSApplication class]]) { // No need to change implementation since Qt // already controls a subclass of NSApplication return; @@ -201,7 +201,7 @@ void qt_redirectNSApplicationSendEvent() qt_cocoa_change_implementation( [NSApplication class], @selector(sendEvent:), - [QT_MANGLE_NAMESPACE(QNSApplication) class], + [QNSApplication class], @selector(QT_MANGLE_NAMESPACE(qt_sendEvent_replacement):), @selector(QT_MANGLE_NAMESPACE(qt_sendEvent_original):)); } diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h index 0816730c54a..8ec9d6fbe0b 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h @@ -89,8 +89,7 @@ #include #include - -Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QCocoaNSMenuItem)); +#include "qcocoansmenu.h" @interface QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) : NSObject @property (nonatomic, retain) NSMenu *dockMenu; @@ -100,8 +99,9 @@ Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QCocoaNSMenuItem)); - (bool)inLaunch; @end -@interface QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) (MenuAPI) -- (void)qt_itemFired:(QT_MANGLE_NAMESPACE(QCocoaNSMenuItem) *)item; +QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaApplicationDelegate); + +@interface QCocoaApplicationDelegate (MenuAPI) +- (void)qt_itemFired:(QCocoaNSMenuItem *)item; @end -QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaApplicationDelegate); diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index 2df85c791b0..00f5a1bf09b 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -145,7 +145,7 @@ QT_USE_NAMESPACE [[NSApp mainMenu] cancelTracking]; bool handle_quit = true; - NSMenuItem *quitMenuItem = [[QT_MANGLE_NAMESPACE(QCocoaMenuLoader) sharedMenuLoader] quitMenuItem]; + NSMenuItem *quitMenuItem = [[QCocoaMenuLoader sharedMenuLoader] quitMenuItem]; if (!QGuiApplicationPrivate::instance()->modalWindowList.isEmpty() && [quitMenuItem isEnabled]) { int visible = 0; diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm index d7850b14810..c9fa035d878 100644 --- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm @@ -293,7 +293,7 @@ class QCocoaColorPanel public: QCocoaColorPanel() { - mDelegate = [[QT_MANGLE_NAMESPACE(QNSColorPanelDelegate) alloc] init]; + mDelegate = [[QNSColorPanelDelegate alloc] init]; } ~QCocoaColorPanel() @@ -366,7 +366,7 @@ public: } private: - QT_MANGLE_NAMESPACE(QNSColorPanelDelegate) *mDelegate; + QNSColorPanelDelegate *mDelegate; }; Q_GLOBAL_STATIC(QCocoaColorPanel, sharedColorPanel) diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h index 2ddda142892..dd0afbefe64 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h @@ -43,10 +43,16 @@ #include #include #include +#include + +#import QT_REQUIRE_CONFIG(filedialog); -Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate)); +@interface QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) : NSObject +@end + +QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSOpenSavePanelDelegate); QT_BEGIN_NAMESPACE @@ -84,7 +90,7 @@ public: void QNSOpenSavePanelDelegate_filterSelected(int menuIndex); private: - QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *mDelegate; + QNSOpenSavePanelDelegate *mDelegate; QUrl mDir; }; diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index 03677ef0bcd..6aa21d78d1f 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -76,27 +76,6 @@ QT_USE_NAMESPACE typedef QSharedPointer SharedPointerFileDialogOptions; -@interface QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) - : NSObject - -- (NSString *)strip:(const QString &)label; -- (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url; -- (void)filterChanged:(id)sender; -- (void)showModelessPanel; -- (BOOL)runApplicationModalPanel; -- (void)showWindowModalSheet:(QWindow *)docWidget; -- (void)updateProperties; -- (QStringList)acceptableExtensionsForSave; -- (QString)removeExtensions:(const QString &)filter; -- (void)createTextField; -- (void)createPopUpButton:(const QString &)selectedFilter hideDetails:(BOOL)hideDetails; -- (QStringList)findStrippedFilterWithVisualFilterName:(QString)name; -- (void)createAccessory; - -@end - -QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSOpenSavePanelDelegate); - @implementation QNSOpenSavePanelDelegate { @public NSOpenPanel *mOpenPanel; diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm index 8c0af97a685..7748c304e34 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm @@ -283,7 +283,7 @@ class QCocoaFontPanel public: QCocoaFontPanel() { - mDelegate = [[QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) alloc] init]; + mDelegate = [[QNSFontPanelDelegate alloc] init]; } ~QCocoaFontPanel() @@ -356,7 +356,7 @@ public: } private: - QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *mDelegate; + QNSFontPanelDelegate *mDelegate; }; Q_GLOBAL_STATIC(QCocoaFontPanel, sharedFontPanel) diff --git a/src/plugins/platforms/cocoa/qcocoamenu.h b/src/plugins/platforms/cocoa/qcocoamenu.h index a957710a88c..1dccf0621c8 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.h +++ b/src/plugins/platforms/cocoa/qcocoamenu.h @@ -44,8 +44,7 @@ #include #include #include "qcocoamenuitem.h" - -Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QCocoaNSMenu)); +#include "qcocoansmenu.h" QT_BEGIN_NAMESPACE @@ -107,7 +106,7 @@ private: void scheduleUpdate(); QList m_menuItems; - QT_MANGLE_NAMESPACE(QCocoaNSMenu) *m_nativeMenu; + QCocoaNSMenu *m_nativeMenu; NSMenuItem *m_attachedItem; int m_updateTimer; bool m_enabled:1; diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index 30bff78a364..363defdd280 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -278,12 +278,11 @@ void QCocoaMenuBar::updateMenuBarImmediately() // we still have to update the menubar. if ((win->flags() & Qt::WindowType_Mask) != Qt::Tool) return; - typedef QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) AppDelegate; NSApplication *app = [NSApplication sharedApplication]; - if (![app.delegate isKindOfClass:[AppDelegate class]]) + if (![app.delegate isKindOfClass:[QCocoaApplicationDelegate class]]) return; // We apply this logic _only_ during the startup. - AppDelegate *appDelegate = app.delegate; + QCocoaApplicationDelegate *appDelegate = app.delegate; if (!appDelegate.inLaunch) return; } @@ -403,3 +402,4 @@ QCocoaWindow *QCocoaMenuBar::cocoaWindow() const QT_END_NAMESPACE +#include "moc_qcocoamenubar.cpp" diff --git a/src/plugins/platforms/cocoa/qcocoansmenu.h b/src/plugins/platforms/cocoa/qcocoansmenu.h index 6cbb6e4a015..0c77e2f1aad 100644 --- a/src/plugins/platforms/cocoa/qcocoansmenu.h +++ b/src/plugins/platforms/cocoa/qcocoansmenu.h @@ -59,31 +59,20 @@ QT_FORWARD_DECLARE_CLASS(QCocoaMenu); QT_FORWARD_DECLARE_CLASS(QCocoaMenuItem); @interface QT_MANGLE_NAMESPACE(QCocoaNSMenuDelegate) : NSObject - + (instancetype)sharedMenuDelegate; - -- (NSMenuItem *)findItemInMenu:(NSMenu *)menu - forKey:(NSString *)key - modifiers:(NSUInteger)modifiers; - +- (NSMenuItem *)findItemInMenu:(NSMenu *)menu forKey:(NSString *)key modifiers:(NSUInteger)modifiers; @end @interface QT_MANGLE_NAMESPACE(QCocoaNSMenu) : NSMenu - @property (readonly, nonatomic) QCocoaMenu *platformMenu; - - (instancetype)initWithPlatformMenu:(QCocoaMenu *)menu; - @end @interface QT_MANGLE_NAMESPACE(QCocoaNSMenuItem) : NSMenuItem - @property (nonatomic) QCocoaMenuItem *platformMenuItem; - + (instancetype)separatorItemWithPlatformMenuItem:(QCocoaMenuItem *)menuItem; - (instancetype)initWithPlatformMenuItem:(QCocoaMenuItem *)menuItem; - (instancetype)init; - @end QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaNSMenu); diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm index db64702b8da..a5b42ac4e3a 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm @@ -80,6 +80,8 @@ #include #include +#include + #include "qcocoamenu.h" #include "qt_mac_p.h" @@ -92,8 +94,6 @@ QT_USE_NAMESPACE -@class QT_MANGLE_NAMESPACE(QNSImageView); - @interface QT_MANGLE_NAMESPACE(QNSStatusItem) : NSObject @property (nonatomic, assign) QCocoaMenu *menu; @property (nonatomic, assign) QIcon icon; @@ -104,12 +104,13 @@ QT_USE_NAMESPACE - (void)doubleClickSelector:(id)sender; @end +QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSStatusItem); + @interface QT_MANGLE_NAMESPACE(QNSImageView) : NSImageView @property (nonatomic, assign) BOOL down; -@property (nonatomic, assign) QT_MANGLE_NAMESPACE(QNSStatusItem) *parent; +@property (nonatomic, assign) QNSStatusItem *parent; @end -QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSStatusItem); QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSImageView); QT_BEGIN_NAMESPACE @@ -360,7 +361,7 @@ QT_END_NAMESPACE @implementation QNSStatusItem { QCocoaSystemTrayIcon *systray; NSStatusItem *item; - QT_MANGLE_NAMESPACE(QNSImageView) *imageCell; + QNSImageView *imageCell; } @synthesize menu = menu; diff --git a/src/plugins/platforms/cocoa/qcocoatheme.h b/src/plugins/platforms/cocoa/qcocoatheme.h index 788b616e787..a00cbdfea38 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.h +++ b/src/plugins/platforms/cocoa/qcocoatheme.h @@ -43,8 +43,6 @@ #include #include -Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QCocoaThemeAppAppearanceObserver)); - #include QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qnsview.h b/src/plugins/platforms/cocoa/qnsview.h index b40dfe0d145..74d0735b4c4 100644 --- a/src/plugins/platforms/cocoa/qnsview.h +++ b/src/plugins/platforms/cocoa/qnsview.h @@ -51,37 +51,30 @@ class QCocoaGLContext; class QPointF; QT_END_NAMESPACE -Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper)); -Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QCocoaNSMenuItem)); - @interface QT_MANGLE_NAMESPACE(QNSView) : NSView - @property (nonatomic, retain) NSCursor *cursor; - - (instancetype)initWithCocoaWindow:(QCocoaWindow *)platformWindow; - - (void)convertFromScreen:(NSPoint)mouseLocation toWindowPoint:(QPointF *)qtWindowPoint andScreenPoint:(QPointF *)qtScreenPoint; - -@end - -@interface QT_MANGLE_NAMESPACE(QNSView) (MouseAPI) -- (void)handleFrameStrutMouseEvent:(NSEvent *)theEvent; -- (void)resetMouseButtons; -@end - -@interface QT_MANGLE_NAMESPACE(QNSView) (KeysAPI) -+ (Qt::KeyboardModifiers)convertKeyModifiers:(ulong)modifierFlags; -@end - -@interface QT_MANGLE_NAMESPACE(QNSView) (ComplexTextAPI) -- (void)unmarkText; -- (void)cancelComposingText; -@end - -@interface QT_MANGLE_NAMESPACE(QNSView) (QtExtras) -@property (nonatomic, readonly) QCocoaWindow *platformWindow; @end QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSView); +@interface QNSView (MouseAPI) +- (void)handleFrameStrutMouseEvent:(NSEvent *)theEvent; +- (void)resetMouseButtons; +@end + +@interface QNSView (KeysAPI) ++ (Qt::KeyboardModifiers)convertKeyModifiers:(ulong)modifierFlags; +@end + +@interface QNSView (ComplexTextAPI) +- (void)unmarkText; +- (void)cancelComposingText; +@end + +@interface QNSView (QtExtras) +@property (nonatomic, readonly) QCocoaWindow *platformWindow; +@end + #endif //QNSVIEW_H diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 5309449dceb..a6e5ca5f7bc 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -66,13 +66,13 @@ #include "qcocoaintegration.h" // Private interface -@interface QT_MANGLE_NAMESPACE(QNSView) () +@interface QNSView () - (BOOL)isTransparentForUserInput; @property (assign) NSView* previousSuperview; @property (assign) NSWindow* previousWindow; @end -@interface QT_MANGLE_NAMESPACE(QNSView) (Drawing) +@interface QNSView (Drawing) - (void)initDrawing; @end @@ -84,7 +84,9 @@ - (void)cursorUpdate:(NSEvent *)theEvent; @end -@interface QT_MANGLE_NAMESPACE(QNSView) (Mouse) +QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSViewMouseMoveHelper); + +@interface QNSView (Mouse) - (void)initMouse; - (NSPoint)screenMousePoint:(NSEvent *)theEvent; - (void)mouseMovedImpl:(NSEvent *)theEvent; @@ -92,28 +94,28 @@ - (void)mouseExitedImpl:(NSEvent *)theEvent; @end -@interface QT_MANGLE_NAMESPACE(QNSView) (Touch) +@interface QNSView (Touch) @end -@interface QT_MANGLE_NAMESPACE(QNSView) (Tablet) +@interface QNSView (Tablet) - (bool)handleTabletEvent:(NSEvent *)theEvent; @end -@interface QT_MANGLE_NAMESPACE(QNSView) (Gestures) +@interface QNSView (Gestures) @end -@interface QT_MANGLE_NAMESPACE(QNSView) (Dragging) +@interface QNSView (Dragging) -(void)registerDragTypes; @end -@interface QT_MANGLE_NAMESPACE(QNSView) (Keys) +@interface QNSView (Keys) @end -@interface QT_MANGLE_NAMESPACE(QNSView) (ComplexText) +@interface QNSView (ComplexText) - (void)textInputContextKeyboardSelectionDidChangeNotification:(NSNotification *)textInputContextKeyboardSelectionDidChangeNotification; @end -@implementation QT_MANGLE_NAMESPACE(QNSView) { +@implementation QNSView { QPointer m_platformWindow; Qt::MouseButtons m_buttons; Qt::MouseButtons m_acceptedMouseDowns; @@ -125,7 +127,7 @@ bool m_sendUpAsRightButton; Qt::KeyboardModifiers m_currentWheelModifiers; NSString *m_inputSource; - QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper) *m_mouseMoveHelper; + QNSViewMouseMoveHelper *m_mouseMoveHelper; bool m_resendKeyEvent; bool m_scrolling; bool m_updatingDrag; @@ -379,7 +381,7 @@ // ----------------------------------------------------- -@implementation QT_MANGLE_NAMESPACE(QNSView) (QtExtras) +@implementation QNSView (QtExtras) - (QCocoaWindow*)platformWindow { diff --git a/src/plugins/platforms/cocoa/qnsview_accessibility.mm b/src/plugins/platforms/cocoa/qnsview_accessibility.mm index 32ec0b74d4a..7041e14da73 100644 --- a/src/plugins/platforms/cocoa/qnsview_accessibility.mm +++ b/src/plugins/platforms/cocoa/qnsview_accessibility.mm @@ -47,7 +47,7 @@ #import -@implementation QT_MANGLE_NAMESPACE(QNSView) (Accessibility) +@implementation QNSView (Accessibility) - (id)childAccessibleElement { diff --git a/src/plugins/platforms/cocoa/qnsview_complextext.mm b/src/plugins/platforms/cocoa/qnsview_complextext.mm index 6ff9b26ca42..5926840cf3a 100644 --- a/src/plugins/platforms/cocoa/qnsview_complextext.mm +++ b/src/plugins/platforms/cocoa/qnsview_complextext.mm @@ -39,7 +39,7 @@ // This file is included from qnsview.mm, and only used to organize the code -@implementation QT_MANGLE_NAMESPACE(QNSView) (ComplexTextAPI) +@implementation QNSView (ComplexTextAPI) - (void)cancelComposingText { @@ -80,7 +80,7 @@ @end -@implementation QT_MANGLE_NAMESPACE(QNSView) (ComplexText) +@implementation QNSView (ComplexText) - (void)insertNewline:(id)sender { diff --git a/src/plugins/platforms/cocoa/qnsview_dragging.mm b/src/plugins/platforms/cocoa/qnsview_dragging.mm index 41b96b2df67..650612e7ffa 100644 --- a/src/plugins/platforms/cocoa/qnsview_dragging.mm +++ b/src/plugins/platforms/cocoa/qnsview_dragging.mm @@ -39,7 +39,7 @@ // This file is included from qnsview.mm, and only used to organize the code -@implementation QT_MANGLE_NAMESPACE(QNSView) (Dragging) +@implementation QNSView (Dragging) -(void)registerDragTypes { diff --git a/src/plugins/platforms/cocoa/qnsview_drawing.mm b/src/plugins/platforms/cocoa/qnsview_drawing.mm index ce5488ead02..eb9286519dc 100644 --- a/src/plugins/platforms/cocoa/qnsview_drawing.mm +++ b/src/plugins/platforms/cocoa/qnsview_drawing.mm @@ -39,7 +39,7 @@ // This file is included from qnsview.mm, and only used to organize the code -@implementation QT_MANGLE_NAMESPACE(QNSView) (Drawing) +@implementation QNSView (Drawing) - (void)initDrawing { diff --git a/src/plugins/platforms/cocoa/qnsview_gestures.mm b/src/plugins/platforms/cocoa/qnsview_gestures.mm index f6cd3af4dad..a80261fd6ad 100644 --- a/src/plugins/platforms/cocoa/qnsview_gestures.mm +++ b/src/plugins/platforms/cocoa/qnsview_gestures.mm @@ -43,7 +43,7 @@ Q_LOGGING_CATEGORY(lcQpaGestures, "qt.qpa.input.gestures") -@implementation QT_MANGLE_NAMESPACE(QNSView) (Gestures) +@implementation QNSView (Gestures) - (bool)handleGestureAsBeginEnd:(NSEvent *)event { diff --git a/src/plugins/platforms/cocoa/qnsview_keys.mm b/src/plugins/platforms/cocoa/qnsview_keys.mm index ad751279bb1..847adca2079 100644 --- a/src/plugins/platforms/cocoa/qnsview_keys.mm +++ b/src/plugins/platforms/cocoa/qnsview_keys.mm @@ -39,7 +39,7 @@ // This file is included from qnsview.mm, and only used to organize the code -@implementation QT_MANGLE_NAMESPACE(QNSView) (KeysAPI) +@implementation QNSView (KeysAPI) + (Qt::KeyboardModifiers)convertKeyModifiers:(ulong)modifierFlags { @@ -60,7 +60,7 @@ @end -@implementation QT_MANGLE_NAMESPACE(QNSView) (Keys) +@implementation QNSView (Keys) - (int)convertKeyCode:(QChar)keyChar { diff --git a/src/plugins/platforms/cocoa/qnsview_menus.mm b/src/plugins/platforms/cocoa/qnsview_menus.mm index f0489552aa9..a55fd97eb71 100644 --- a/src/plugins/platforms/cocoa/qnsview_menus.mm +++ b/src/plugins/platforms/cocoa/qnsview_menus.mm @@ -53,11 +53,11 @@ static bool selectorIsCutCopyPaste(SEL selector) || selector == @selector(selectAll:)); } -@interface QT_MANGLE_NAMESPACE(QNSView) (Menus) +@interface QNSView (Menus) - (void)qt_itemFired:(QCocoaNSMenuItem *)item; @end -@implementation QT_MANGLE_NAMESPACE(QNSView) (Menus) +@implementation QNSView (Menus) - (BOOL)validateMenuItem:(NSMenuItem*)item { diff --git a/src/plugins/platforms/cocoa/qnsview_mouse.mm b/src/plugins/platforms/cocoa/qnsview_mouse.mm index 30613eca320..9e2761f850d 100644 --- a/src/plugins/platforms/cocoa/qnsview_mouse.mm +++ b/src/plugins/platforms/cocoa/qnsview_mouse.mm @@ -55,7 +55,7 @@ interact with the responder chain by e.g. calling super if Qt does not accept the mouse event */ -@implementation QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper) { +@implementation QNSViewMouseMoveHelper { QNSView *view; } @@ -89,7 +89,7 @@ @end -@implementation QT_MANGLE_NAMESPACE(QNSView) (MouseAPI) +@implementation QNSView (MouseAPI) - (void)resetMouseButtons { @@ -178,7 +178,7 @@ } @end -@implementation QT_MANGLE_NAMESPACE(QNSView) (Mouse) +@implementation QNSView (Mouse) - (void)initMouse { @@ -193,7 +193,7 @@ m_dontOverrideCtrlLMB = qt_mac_resolveOption(false, m_platformWindow->window(), "_q_platform_MacDontOverrideCtrlLMB", "QT_MAC_DONT_OVERRIDE_CTRL_LMB"); - m_mouseMoveHelper = [[QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper) alloc] initWithView:self]; + m_mouseMoveHelper = [[QNSViewMouseMoveHelper alloc] initWithView:self]; NSUInteger trackingOptions = NSTrackingActiveInActiveApp | NSTrackingMouseEnteredAndExited | NSTrackingCursorUpdate; diff --git a/src/plugins/platforms/cocoa/qnsview_tablet.mm b/src/plugins/platforms/cocoa/qnsview_tablet.mm index 43b0aa0960d..ba1fa558929 100644 --- a/src/plugins/platforms/cocoa/qnsview_tablet.mm +++ b/src/plugins/platforms/cocoa/qnsview_tablet.mm @@ -54,7 +54,7 @@ struct QCocoaTabletDeviceData typedef QHash QCocoaTabletDeviceDataHash; Q_GLOBAL_STATIC(QCocoaTabletDeviceDataHash, tabletDeviceDataHash) -@implementation QT_MANGLE_NAMESPACE(QNSView) (Tablet) +@implementation QNSView (Tablet) - (bool)handleTabletEvent:(NSEvent *)theEvent { diff --git a/src/plugins/platforms/cocoa/qnsview_touch.mm b/src/plugins/platforms/cocoa/qnsview_touch.mm index 9330844aeca..8dfae27c63f 100644 --- a/src/plugins/platforms/cocoa/qnsview_touch.mm +++ b/src/plugins/platforms/cocoa/qnsview_touch.mm @@ -41,7 +41,7 @@ Q_LOGGING_CATEGORY(lcQpaTouch, "qt.qpa.input.touch") -@implementation QT_MANGLE_NAMESPACE(QNSView) (Touch) +@implementation QNSView (Touch) - (bool)shouldSendSingleTouch { diff --git a/src/plugins/platforms/cocoa/qprintengine_mac_p.h b/src/plugins/platforms/cocoa/qprintengine_mac_p.h index 3d94227ae4b..6a1ed2e263a 100644 --- a/src/plugins/platforms/cocoa/qprintengine_mac_p.h +++ b/src/plugins/platforms/cocoa/qprintengine_mac_p.h @@ -64,11 +64,7 @@ #include "qpaintengine_mac_p.h" -#ifdef __OBJC__ -@class NSPrintInfo; -#else -typedef void NSPrintInfo; -#endif +Q_FORWARD_DECLARE_OBJC_CLASS(NSPrintInfo); QT_BEGIN_NAMESPACE From 92b9dcfe2ba602fc396a4806597b9440ed63bded Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 15 Oct 2019 09:58:46 +0200 Subject: [PATCH 14/23] rhi: gl: Do not let external rendering trash our vao Task-number: QTBUG-79221 Change-Id: Ie8e6376f79c816071c12962dc054838aeaabcaa5 Reviewed-by: Paul Olav Tvete --- src/gui/rhi/qrhigles2.cpp | 28 +++++++++++++++++++++------- src/gui/rhi/qrhigles2_p_p.h | 1 + 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index e355979626b..dec28cac9bd 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -525,6 +525,11 @@ void QRhiGles2::destroy() ensureContext(); executeDeferredReleases(); + if (vao) { + f->glDeleteVertexArrays(1, &vao); + vao = 0; + } + for (uint shader : m_shaderCache) f->glDeleteShader(shader); m_shaderCache.clear(); @@ -1151,6 +1156,13 @@ const QRhiNativeHandles *QRhiGles2::nativeHandles(QRhiCommandBuffer *cb) return nullptr; } +static void addBoundaryCommand(QGles2CommandBuffer *cbD, QGles2CommandBuffer::Command::Cmd type) +{ + QGles2CommandBuffer::Command cmd; + cmd.cmd = type; + cbD->commands.append(cmd); +} + void QRhiGles2::beginExternal(QRhiCommandBuffer *cb) { if (ofr.active) { @@ -1166,6 +1178,9 @@ void QRhiGles2::beginExternal(QRhiCommandBuffer *cb) QGles2CommandBuffer *cbD = QRHI_RES(QGles2CommandBuffer, cb); executeCommandBuffer(cbD); cbD->resetCommands(); + + if (vao) + f->glBindVertexArray(0); } void QRhiGles2::endExternal(QRhiCommandBuffer *cb) @@ -1183,17 +1198,12 @@ void QRhiGles2::endExternal(QRhiCommandBuffer *cb) enqueueBarriersForPass(cbD); } + addBoundaryCommand(cbD, QGles2CommandBuffer::Command::ResetFrame); + if (cbD->currentTarget) enqueueBindFramebuffer(cbD->currentTarget, cbD); } -static void addBoundaryCommand(QGles2CommandBuffer *cb, QGles2CommandBuffer::Command::Cmd type) -{ - QGles2CommandBuffer::Command cmd; - cmd.cmd = type; - cb->commands.append(cmd); -} - QRhi::FrameOpResult QRhiGles2::beginFrame(QRhiSwapChain *swapChain, QRhi::BeginFrameFlags flags) { Q_UNUSED(flags); @@ -1913,6 +1923,10 @@ void QRhiGles2::executeCommandBuffer(QRhiCommandBuffer *cb) if (vao) f->glBindVertexArray(0); break; + case QGles2CommandBuffer::Command::ResetFrame: + if (vao) + f->glBindVertexArray(vao); + break; case QGles2CommandBuffer::Command::Viewport: f->glViewport(GLint(cmd.args.viewport.x), GLint(cmd.args.viewport.y), GLsizei(cmd.args.viewport.w), GLsizei(cmd.args.viewport.h)); f->glDepthRangef(cmd.args.viewport.d0, cmd.args.viewport.d1); diff --git a/src/gui/rhi/qrhigles2_p_p.h b/src/gui/rhi/qrhigles2_p_p.h index 8814d9c19da..cc945876e60 100644 --- a/src/gui/rhi/qrhigles2_p_p.h +++ b/src/gui/rhi/qrhigles2_p_p.h @@ -300,6 +300,7 @@ struct QGles2CommandBuffer : public QRhiCommandBuffer enum Cmd { BeginFrame, EndFrame, + ResetFrame, Viewport, Scissor, BlendConstants, From 9cc040a806fd2e6f1458e801a99311168d594c77 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Mon, 9 Sep 2019 16:11:48 +0200 Subject: [PATCH 15/23] Prepare for deprecating the QDesktopWidget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QDesktopWidget is marked as obsolete in docs, but it is not yet completely deprecated, some of its methods are still in use. Replace uses of the following methods marked as obsolete: - QDesktopWidget::screenNumber(QWidget*) -> QWidget::screen() - QDesktopWidget::screenGeometry(QWidget*) -> QWidget::screen()->geometry() - QDesktopWidget::availableGeometry(QWidget*) -> QWidget::screen()->availableGeometry() Task-number: QTBUG-76491 Change-Id: I2cca30f2b4caa6e6848e8190e09f959d2c272f33 Reviewed-by: Tor Arne Vestbø --- .../corelib/mimetypes/mimetypebrowser/main.cpp | 4 ++-- examples/network/http/main.cpp | 4 ++-- examples/opengl/threadedqopenglwidget/main.cpp | 4 ++-- examples/widgets/desktop/screenshot/main.cpp | 5 +++-- examples/widgets/desktop/screenshot/screenshot.cpp | 2 +- examples/widgets/dialogs/standarddialogs/main.cpp | 4 ++-- examples/widgets/itemviews/dirview/main.cpp | 4 ++-- .../widgets/mainwindows/application/mainwindow.cpp | 2 +- examples/widgets/mainwindows/mdi/mainwindow.cpp | 2 +- examples/widgets/mainwindows/sdi/mainwindow.cpp | 4 ++-- examples/widgets/richtext/textedit/main.cpp | 4 ++-- examples/widgets/tools/codecs/mainwindow.cpp | 6 +++--- examples/widgets/tools/codecs/previewform.cpp | 4 ++-- .../widgets/tools/settingseditor/mainwindow.cpp | 4 ++-- .../widgets/tools/settingseditor/settingstree.cpp | 4 ++-- .../widgets/widgets/charactermap/mainwindow.cpp | 3 ++- examples/widgets/widgets/icons/main.cpp | 4 ++-- examples/xml/dombookmarks/mainwindow.cpp | 2 +- examples/xml/saxbookmarks/mainwindow.cpp | 2 +- examples/xml/streambookmarks/mainwindow.cpp | 2 +- src/widgets/util/qscroller.cpp | 3 ++- .../gui/kernel/qtouchevent/tst_qtouchevent.cpp | 14 +++++++------- .../qgraphicsitem/tst_qgraphicsitem.cpp | 2 +- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 12 +++++------- .../widgets/util/qcompleter/tst_qcompleter.cpp | 4 ++-- .../widgets/widgets/qcombobox/tst_qcombobox.cpp | 10 +++------- .../auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 5 ++--- tests/manual/dialogs/printdialogpanel.cpp | 3 +-- tests/manual/qcursor/qcursorhighdpi/main.cpp | 2 +- 29 files changed, 60 insertions(+), 65 deletions(-) diff --git a/examples/corelib/mimetypes/mimetypebrowser/main.cpp b/examples/corelib/mimetypes/mimetypebrowser/main.cpp index cf87004a01f..679d97dc7be 100644 --- a/examples/corelib/mimetypes/mimetypebrowser/main.cpp +++ b/examples/corelib/mimetypes/mimetypebrowser/main.cpp @@ -51,7 +51,7 @@ #include "mainwindow.h" #include -#include +#include #include #include @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) parser.process(app); MainWindow mainWindow; - const QRect availableGeometry = QApplication::desktop()->availableGeometry(&mainWindow); + const QRect availableGeometry = mainWindow.screen()->availableGeometry(); mainWindow.resize(availableGeometry.width() / 3, availableGeometry.height() / 2); mainWindow.show(); diff --git a/examples/network/http/main.cpp b/examples/network/http/main.cpp index b7d254ff227..f126c7846a6 100644 --- a/examples/network/http/main.cpp +++ b/examples/network/http/main.cpp @@ -49,8 +49,8 @@ ****************************************************************************/ #include -#include #include +#include #include "httpwindow.h" @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); HttpWindow httpWin; - const QRect availableSize = QApplication::desktop()->availableGeometry(&httpWin); + const QRect availableSize = httpWin.screen()->availableGeometry(); httpWin.resize(availableSize.width() / 5, availableSize.height() / 5); httpWin.move((availableSize.width() - httpWin.width()) / 2, (availableSize.height() - httpWin.height()) / 2); diff --git a/examples/opengl/threadedqopenglwidget/main.cpp b/examples/opengl/threadedqopenglwidget/main.cpp index 983f608543c..975def030bf 100644 --- a/examples/opengl/threadedqopenglwidget/main.cpp +++ b/examples/opengl/threadedqopenglwidget/main.cpp @@ -50,7 +50,7 @@ #include #include -#include +#include #include #include #include @@ -90,7 +90,7 @@ int main( int argc, char ** argv ) // The rendering for the four QOpenGLWidgets happens on four separate threads. GLWidget topLevelGlWidget; - QPoint pos = QApplication::desktop()->availableGeometry(&topLevelGlWidget).topLeft() + QPoint(200, 200); + QPoint pos = topLevelGlWidget.screen()->availableGeometry().topLeft() + QPoint(200, 200); topLevelGlWidget.setWindowTitle(QStringLiteral("Threaded QOpenGLWidget example top level")); topLevelGlWidget.resize(200, 200); topLevelGlWidget.move(pos); diff --git a/examples/widgets/desktop/screenshot/main.cpp b/examples/widgets/desktop/screenshot/main.cpp index 825c40b2369..96b0d57daa5 100644 --- a/examples/widgets/desktop/screenshot/main.cpp +++ b/examples/widgets/desktop/screenshot/main.cpp @@ -49,7 +49,7 @@ ****************************************************************************/ #include -#include +#include #include "screenshot.h" @@ -58,7 +58,8 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); Screenshot screenshot; - screenshot.move(QApplication::desktop()->availableGeometry(&screenshot).topLeft() + QPoint(20, 20)); + screenshot.move(screenshot.screen()->availableGeometry().topLeft() + QPoint(20, 20)); screenshot.show(); + return app.exec(); } diff --git a/examples/widgets/desktop/screenshot/screenshot.cpp b/examples/widgets/desktop/screenshot/screenshot.cpp index 715e6c780ee..ce5597bbddb 100644 --- a/examples/widgets/desktop/screenshot/screenshot.cpp +++ b/examples/widgets/desktop/screenshot/screenshot.cpp @@ -59,7 +59,7 @@ Screenshot::Screenshot() screenshotLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); screenshotLabel->setAlignment(Qt::AlignCenter); - const QRect screenGeometry = QApplication::desktop()->screenGeometry(this); + const QRect screenGeometry = screen()->geometry(); screenshotLabel->setMinimumSize(screenGeometry.width() / 8, screenGeometry.height() / 8); QVBoxLayout *mainLayout = new QVBoxLayout(this); diff --git a/examples/widgets/dialogs/standarddialogs/main.cpp b/examples/widgets/dialogs/standarddialogs/main.cpp index f7417f0e452..19ed2bf66f3 100644 --- a/examples/widgets/dialogs/standarddialogs/main.cpp +++ b/examples/widgets/dialogs/standarddialogs/main.cpp @@ -49,8 +49,8 @@ ****************************************************************************/ #include +#include #include -#include #include #include #include @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) Dialog dialog; if (!QGuiApplication::styleHints()->showIsFullScreen() && !QGuiApplication::styleHints()->showIsMaximized()) { - const QRect availableGeometry = QApplication::desktop()->availableGeometry(&dialog); + const QRect availableGeometry = dialog.screen()->availableGeometry(); dialog.resize(availableGeometry.width() / 3, availableGeometry.height() * 2 / 3); dialog.move((availableGeometry.width() - dialog.width()) / 2, (availableGeometry.height() - dialog.height()) / 2); diff --git a/examples/widgets/itemviews/dirview/main.cpp b/examples/widgets/itemviews/dirview/main.cpp index 9fecffda400..fcdf4c7ba45 100644 --- a/examples/widgets/itemviews/dirview/main.cpp +++ b/examples/widgets/itemviews/dirview/main.cpp @@ -49,9 +49,9 @@ ****************************************************************************/ #include -#include #include #include +#include #include #include #include @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) tree.setAnimated(false); tree.setIndentation(20); tree.setSortingEnabled(true); - const QSize availableSize = QApplication::desktop()->availableGeometry(&tree).size(); + const QSize availableSize = tree.screen()->availableGeometry().size(); tree.resize(availableSize / 2); tree.setColumnWidth(0, tree.width() / 3); diff --git a/examples/widgets/mainwindows/application/mainwindow.cpp b/examples/widgets/mainwindows/application/mainwindow.cpp index 7886c4afacb..d0c009427ff 100644 --- a/examples/widgets/mainwindows/application/mainwindow.cpp +++ b/examples/widgets/mainwindows/application/mainwindow.cpp @@ -281,7 +281,7 @@ void MainWindow::readSettings() QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName()); const QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray(); if (geometry.isEmpty()) { - const QRect availableGeometry = QApplication::desktop()->availableGeometry(this); + const QRect availableGeometry = screen()->availableGeometry(); resize(availableGeometry.width() / 3, availableGeometry.height() / 2); move((availableGeometry.width() - width()) / 2, (availableGeometry.height() - height()) / 2); diff --git a/examples/widgets/mainwindows/mdi/mainwindow.cpp b/examples/widgets/mainwindows/mdi/mainwindow.cpp index b952d19e2e6..ccfa7435d73 100644 --- a/examples/widgets/mainwindows/mdi/mainwindow.cpp +++ b/examples/widgets/mainwindows/mdi/mainwindow.cpp @@ -464,7 +464,7 @@ void MainWindow::readSettings() QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName()); const QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray(); if (geometry.isEmpty()) { - const QRect availableGeometry = QApplication::desktop()->availableGeometry(this); + const QRect availableGeometry = screen()->availableGeometry(); resize(availableGeometry.width() / 3, availableGeometry.height() / 2); move((availableGeometry.width() - width()) / 2, (availableGeometry.height() - height()) / 2); diff --git a/examples/widgets/mainwindows/sdi/mainwindow.cpp b/examples/widgets/mainwindows/sdi/mainwindow.cpp index a1fb42158e0..c3cd131923d 100644 --- a/examples/widgets/mainwindows/sdi/mainwindow.cpp +++ b/examples/widgets/mainwindows/sdi/mainwindow.cpp @@ -167,7 +167,7 @@ void MainWindow::tile(const QMainWindow *previous) if (!topFrameWidth) topFrameWidth = 40; const QPoint pos = previous->pos() + 2 * QPoint(topFrameWidth, topFrameWidth); - if (QApplication::desktop()->availableGeometry(this).contains(rect().bottomRight() + pos)) + if (screen()->availableGeometry().contains(rect().bottomRight() + pos)) move(pos); } @@ -290,7 +290,7 @@ void MainWindow::readSettings() QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName()); const QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray(); if (geometry.isEmpty()) { - const QRect availableGeometry = QApplication::desktop()->availableGeometry(this); + const QRect availableGeometry = screen()->availableGeometry(); resize(availableGeometry.width() / 3, availableGeometry.height() / 2); move((availableGeometry.width() - width()) / 2, (availableGeometry.height() - height()) / 2); diff --git a/examples/widgets/richtext/textedit/main.cpp b/examples/widgets/richtext/textedit/main.cpp index aef186aa775..256d1838112 100644 --- a/examples/widgets/richtext/textedit/main.cpp +++ b/examples/widgets/richtext/textedit/main.cpp @@ -51,9 +51,9 @@ #include "textedit.h" #include -#include #include #include +#include int main(int argc, char *argv[]) { @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) TextEdit mw; - const QRect availableGeometry = QApplication::desktop()->availableGeometry(&mw); + const QRect availableGeometry = mw.screen()->availableGeometry(); mw.resize(availableGeometry.width() / 2, (availableGeometry.height() * 2) / 3); mw.move((availableGeometry.width() - mw.width()) / 2, (availableGeometry.height() - mw.height()) / 2); diff --git a/examples/widgets/tools/codecs/mainwindow.cpp b/examples/widgets/tools/codecs/mainwindow.cpp index 6b601062b68..dc72fa73b79 100644 --- a/examples/widgets/tools/codecs/mainwindow.cpp +++ b/examples/widgets/tools/codecs/mainwindow.cpp @@ -54,12 +54,12 @@ #include #include -#include #include #include #include #include #include +#include #include #include @@ -78,7 +78,7 @@ MainWindow::MainWindow() setWindowTitle(tr("Codecs")); - const QRect screenGeometry = QApplication::desktop()->screenGeometry(this); + const QRect screenGeometry = screen()->geometry(); resize(screenGeometry.width() / 2, screenGeometry.height() * 2 / 3); } @@ -216,7 +216,7 @@ void MainWindow::encodingDialog() { if (!m_encodingDialog) { m_encodingDialog = new EncodingDialog(this); - const QRect screenGeometry = QApplication::desktop()->screenGeometry(this); + const QRect screenGeometry = screen()->geometry(); m_encodingDialog->setMinimumWidth(screenGeometry.width() / 4); } m_encodingDialog->show(); diff --git a/examples/widgets/tools/codecs/previewform.cpp b/examples/widgets/tools/codecs/previewform.cpp index ec75ebb9faf..f48651335a1 100644 --- a/examples/widgets/tools/codecs/previewform.cpp +++ b/examples/widgets/tools/codecs/previewform.cpp @@ -52,12 +52,12 @@ #include #include -#include #include #include #include #include #include +#include #include #include @@ -183,7 +183,7 @@ PreviewForm::PreviewForm(QWidget *parent) mainLayout->addWidget(statusLabel, 2, 0, 1, 2); mainLayout->addWidget(buttonBox, 3, 0, 1, 2); - const QRect screenGeometry = QApplication::desktop()->screenGeometry(this); + const QRect screenGeometry = screen()->geometry(); resize(screenGeometry.width() * 2 / 5, screenGeometry.height() / 2); } diff --git a/examples/widgets/tools/settingseditor/mainwindow.cpp b/examples/widgets/tools/settingseditor/mainwindow.cpp index b9c2193ccb6..ccca16ffcd7 100644 --- a/examples/widgets/tools/settingseditor/mainwindow.cpp +++ b/examples/widgets/tools/settingseditor/mainwindow.cpp @@ -54,12 +54,12 @@ #include #include -#include #include #include #include #include #include +#include #include #include @@ -74,7 +74,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) fallbacksAct->setChecked(true); setWindowTitle(QCoreApplication::applicationName()); - const QRect availableGeometry = QApplication::desktop()->availableGeometry(this); + const QRect availableGeometry = screen()->availableGeometry(); adjustSize(); move((availableGeometry.width() - width()) / 2, (availableGeometry.height() - height()) / 2); } diff --git a/examples/widgets/tools/settingseditor/settingstree.cpp b/examples/widgets/tools/settingseditor/settingstree.cpp index b263746847f..49d299bf72d 100644 --- a/examples/widgets/tools/settingseditor/settingstree.cpp +++ b/examples/widgets/tools/settingseditor/settingstree.cpp @@ -52,8 +52,8 @@ #include "variantdelegate.h" #include -#include #include +#include #include SettingsTree::SettingsTree(QWidget *parent) @@ -93,7 +93,7 @@ void SettingsTree::setSettingsObject(const SettingsPtr &newSettings) QSize SettingsTree::sizeHint() const { - const QRect availableGeometry = QApplication::desktop()->availableGeometry(this); + const QRect availableGeometry = screen()->availableGeometry(); return QSize(availableGeometry.width() * 2 / 3, availableGeometry.height() * 2 / 3); } diff --git a/examples/widgets/widgets/charactermap/mainwindow.cpp b/examples/widgets/widgets/charactermap/mainwindow.cpp index 25c4503ddb8..b0f9705c211 100644 --- a/examples/widgets/widgets/charactermap/mainwindow.cpp +++ b/examples/widgets/widgets/charactermap/mainwindow.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -302,7 +303,7 @@ QString FontInfoDialog::text() const void MainWindow::showInfo() { - const QRect screenGeometry = QApplication::desktop()->screenGeometry(this); + const QRect screenGeometry = screen()->geometry(); FontInfoDialog *dialog = new FontInfoDialog(this); dialog->setWindowTitle(tr("Fonts")); dialog->setAttribute(Qt::WA_DeleteOnClose); diff --git a/examples/widgets/widgets/icons/main.cpp b/examples/widgets/widgets/icons/main.cpp index a045ea765a5..632795c18c2 100644 --- a/examples/widgets/widgets/icons/main.cpp +++ b/examples/widgets/widgets/icons/main.cpp @@ -50,7 +50,7 @@ #include #include -#include +#include #include "mainwindow.h" @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) if (!commandLineParser.positionalArguments().isEmpty()) mainWin.loadImages(commandLineParser.positionalArguments()); - const QRect availableGeometry = QApplication::desktop()->availableGeometry(&mainWin); + const QRect availableGeometry = mainWin.screen()->availableGeometry(); mainWin.resize(availableGeometry.width() / 2, availableGeometry.height() * 2 / 3); mainWin.move((availableGeometry.width() - mainWin.width()) / 2, (availableGeometry.height() - mainWin.height()) / 2); diff --git a/examples/xml/dombookmarks/mainwindow.cpp b/examples/xml/dombookmarks/mainwindow.cpp index fade2dfc960..b8f2e12918b 100644 --- a/examples/xml/dombookmarks/mainwindow.cpp +++ b/examples/xml/dombookmarks/mainwindow.cpp @@ -63,7 +63,7 @@ MainWindow::MainWindow() statusBar()->showMessage(tr("Ready")); setWindowTitle(tr("DOM Bookmarks")); - const QSize availableSize = QApplication::desktop()->availableGeometry(this).size(); + const QSize availableSize = screen()->availableGeometry().size(); resize(availableSize.width() / 2, availableSize.height() / 3); } diff --git a/examples/xml/saxbookmarks/mainwindow.cpp b/examples/xml/saxbookmarks/mainwindow.cpp index 0583cd82cf0..8b7733081f0 100644 --- a/examples/xml/saxbookmarks/mainwindow.cpp +++ b/examples/xml/saxbookmarks/mainwindow.cpp @@ -74,7 +74,7 @@ MainWindow::MainWindow() statusBar()->showMessage(tr("Ready")); setWindowTitle(tr("SAX Bookmarks")); - const QSize availableSize = QApplication::desktop()->availableGeometry(this).size(); + const QSize availableSize = screen()->availableGeometry().size(); resize(availableSize.width() / 2, availableSize.height() / 3); } diff --git a/examples/xml/streambookmarks/mainwindow.cpp b/examples/xml/streambookmarks/mainwindow.cpp index c9a18fa3c47..d0e7bf30c90 100644 --- a/examples/xml/streambookmarks/mainwindow.cpp +++ b/examples/xml/streambookmarks/mainwindow.cpp @@ -75,7 +75,7 @@ MainWindow::MainWindow() statusBar()->showMessage(tr("Ready")); setWindowTitle(tr("QXmlStream Bookmarks")); - const QSize availableSize = QApplication::desktop()->availableGeometry(this).size(); + const QSize availableSize = screen()->availableGeometry().size(); resize(availableSize.width() / 2, availableSize.height() / 3); } //! [0] diff --git a/src/widgets/util/qscroller.cpp b/src/widgets/util/qscroller.cpp index 1e842372531..df05bbf71c2 100644 --- a/src/widgets/util/qscroller.cpp +++ b/src/widgets/util/qscroller.cpp @@ -1031,7 +1031,8 @@ void QScrollerPrivate::setDpi(const QPointF &dpi) */ void QScrollerPrivate::setDpiFromWidget(QWidget *widget) { - const QScreen *screen = QGuiApplication::screens().at(QApplication::desktop()->screenNumber(widget)); + const QScreen *screen = widget ? widget->screen() : QGuiApplication::primaryScreen(); + Q_ASSERT(screen); setDpi(QPointF(screen->physicalDotsPerInchX(), screen->physicalDotsPerInchY())); } diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp index 13dc924f93d..54bb8fe0bd1 100644 --- a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp +++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp @@ -26,7 +26,7 @@ ** ****************************************************************************/ -#include +#include #include #include #include @@ -617,7 +617,7 @@ void tst_QTouchEvent::basicRawEventTranslation() QPointF pos = touchWidget.rect().center(); QPointF screenPos = touchWidget.mapToGlobal(pos.toPoint()); QPointF delta(10, 10); - QRectF screenGeometry = QApplication::desktop()->screenGeometry(&touchWidget); + QRectF screenGeometry = touchWidget.screen()->geometry(); QTouchEvent::TouchPoint rawTouchPoint; rawTouchPoint.setId(0); @@ -753,7 +753,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen() QPointF leftScreenPos = leftWidget.mapToGlobal(leftPos.toPoint()); QPointF rightScreenPos = rightWidget.mapToGlobal(rightPos.toPoint()); QPointF centerScreenPos = touchWidget.mapToGlobal(centerPos.toPoint()); - QRectF screenGeometry = QApplication::desktop()->screenGeometry(&touchWidget); + QRectF screenGeometry = touchWidget.screen()->geometry(); QList rawTouchPoints; rawTouchPoints.append(QTouchEvent::TouchPoint(0)); @@ -968,7 +968,7 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens() QPointF pos = touchWidget.rect().center(); QPointF screenPos = touchWidget.mapToGlobal(pos.toPoint()); QPointF delta(10, 10); - QRectF screenGeometry = QApplication::desktop()->screenGeometry(&touchWidget); + QRectF screenGeometry = touchWidget.screen()->geometry(); QVector rawTouchPoints(3); rawTouchPoints[0].setId(0); @@ -1131,7 +1131,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad() QPointF leftScreenPos = leftWidget.mapToGlobal(leftPos.toPoint()); QPointF rightScreenPos = rightWidget.mapToGlobal(rightPos.toPoint()); QPointF centerScreenPos = touchWidget.mapToGlobal(centerPos.toPoint()); - QRectF screenGeometry = QApplication::desktop()->screenGeometry(&touchWidget); + QRectF screenGeometry = touchWidget.screen()->geometry(); QList rawTouchPoints; rawTouchPoints.append(QTouchEvent::TouchPoint(0)); @@ -1348,7 +1348,7 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds() screenPos << touchWidget.mapToGlobal(pos[i].toPoint()); } QPointF delta(10, 10); - QRectF screenGeometry = QApplication::desktop()->screenGeometry(&touchWidget); + QRectF screenGeometry = touchWidget.screen()->geometry(); QVector rawPosList; rawPosList << QPointF(12, 34) << QPointF(56, 78); @@ -1629,7 +1629,7 @@ void tst_QTouchEvent::deleteInRawEventTranslation() QPointF leftScreenPos = leftWidget->mapToGlobal(leftPos.toPoint()); QPointF centerScreenPos = centerWidget->mapToGlobal(centerPos.toPoint()); QPointF rightScreenPos = rightWidget->mapToGlobal(rightPos.toPoint()); - QRectF screenGeometry = QApplication::desktop()->screenGeometry(&touchWidget); + QRectF screenGeometry = touchWidget.screen()->geometry(); QList rawTouchPoints; rawTouchPoints.append(QTouchEvent::TouchPoint(0)); diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 0b08586f7d7..af0dd9b0f09 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -10977,7 +10977,7 @@ static QList tp.setStartScreenPos(screenPos); tp.setLastScreenPos(screenPos); tp.setEllipseDiameters(ellipseDiameters); - const QSizeF screenSize = QApplication::desktop()->screenGeometry(&view).size(); + const QSizeF screenSize = view.screen()->geometry().size(); tp.setNormalizedPos(QPointF(screenPos.x() / screenSize.width(), screenPos.y() / screenSize.height())); return QList() << tp; } diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 3e372b76f58..40377eb9462 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -5383,7 +5383,7 @@ void tst_QWidget::moveChild() parent.setStyle(style.data()); ColorWidget child(&parent, Qt::Widget, Qt::blue); - parent.setGeometry(QRect(QPoint(QApplication::desktop()->availableGeometry(&parent).topLeft()) + QPoint(50, 50), + parent.setGeometry(QRect(parent.screen()->availableGeometry().topLeft() + QPoint(50, 50), QSize(200, 200))); child.setGeometry(25, 25, 50, 50); #ifndef QT_NO_CURSOR // Try to make sure the cursor is not in a taskbar area to prevent tooltips or window highlighting @@ -5430,8 +5430,7 @@ void tst_QWidget::showAndMoveChild() const QScopedPointer style(QStyleFactory::create(QLatin1String("Windows"))); parent.setStyle(style.data()); - QDesktopWidget desktop; - QRect desktopDimensions = desktop.availableGeometry(&parent); + QRect desktopDimensions = parent.screen()->availableGeometry(); desktopDimensions = desktopDimensions.adjusted(64, 64, -64, -64); #ifndef QT_NO_CURSOR // Try to make sure the cursor is not in a taskbar area to prevent tooltips or window highlighting @@ -7708,7 +7707,7 @@ void tst_QWidget::repaintWhenChildDeleted() #endif ColorWidget w(nullptr, Qt::FramelessWindowHint, Qt::red); w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); - QPoint startPoint = QApplication::desktop()->availableGeometry(&w).topLeft(); + QPoint startPoint = w.screen()->availableGeometry().topLeft(); startPoint.rx() += 50; startPoint.ry() += 50; w.setGeometry(QRect(startPoint, QSize(100, 100))); @@ -7733,7 +7732,7 @@ void tst_QWidget::hideOpaqueChildWhileHidden() { ColorWidget w(nullptr, Qt::FramelessWindowHint, Qt::red); w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); - QPoint startPoint = QApplication::desktop()->availableGeometry(&w).topLeft(); + QPoint startPoint = w.screen()->availableGeometry().topLeft(); startPoint.rx() += 50; startPoint.ry() += 50; w.setGeometry(QRect(startPoint, QSize(100, 100))); @@ -9601,8 +9600,7 @@ void tst_QWidget::rectOutsideCoordinatesLimit_task144779() palette.setColor(QPalette::Window, Qt::red); main.setPalette(palette); - QDesktopWidget desktop; - QRect desktopDimensions = desktop.availableGeometry(&main); + QRect desktopDimensions = main.screen()->availableGeometry(); QSize mainSize(400, 400); mainSize = mainSize.boundedTo(desktopDimensions.size()); main.resize(mainSize); diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp index 5a51f150087..27ae41fc4f9 100644 --- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp @@ -1765,7 +1765,7 @@ void tst_QCompleter::QTBUG_52028_tabAutoCompletes() auto le = new QLineEdit; w.layout()->addWidget(le); - const auto pos = QApplication::desktop()->availableGeometry(&w).topLeft() + QPoint(200,200); + const auto pos = w.screen()->availableGeometry().topLeft() + QPoint(200,200); w.move(pos); w.show(); QApplication::setActiveWindow(&w); @@ -1806,7 +1806,7 @@ void tst_QCompleter::QTBUG_51889_activatedSentTwice() w.layout()->addWidget(new QLineEdit); - const auto pos = QApplication::desktop()->availableGeometry(&w).topLeft() + QPoint(200,200); + const auto pos = w.screen()->availableGeometry().topLeft() + QPoint(200,200); w.move(pos); w.show(); QApplication::setActiveWindow(&w); diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 4e16edaca83..b7869a0653b 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -34,7 +34,6 @@ #include #include -#include #include #include #include @@ -2212,15 +2211,13 @@ void tst_QComboBox::itemListPosition() QFontComboBox combo(&topLevel); layout->addWidget(&combo); - //the code to get the available screen space is copied from QComboBox code - const int scrNumber = QApplication::desktop()->screenNumber(&combo); bool useFullScreenForPopupMenu = false; if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) useFullScreenForPopupMenu = theme->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool(); const QRect screen = useFullScreenForPopupMenu ? - QApplication::screens().at(scrNumber)->geometry() : - QApplication::screens().at(scrNumber)->availableGeometry(); + combo.screen()->geometry() : + combo.screen()->availableGeometry(); topLevel.move(screen.width() - topLevel.sizeHint().width() - 10, 0); //puts the combo to the top-right corner @@ -2440,8 +2437,7 @@ void tst_QComboBox::task248169_popupWithMinimalSize() #if defined QT_BUILD_INTERNAL QFrame *container = comboBox.findChild(); QVERIFY(container); - QDesktopWidget desktop; - QTRY_VERIFY(desktop.screenGeometry(container).contains(container->geometry())); + QTRY_VERIFY(container->screen()->geometry().contains(container->geometry())); #endif } diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index d6ba85d61fb..417d6e3124e 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -1149,8 +1148,8 @@ void tst_QMenuBar::check_menuPosition() Menu menu; menu.setTitle("&menu"); - QRect availRect = QApplication::desktop()->availableGeometry(&w); - QRect screenRect = QApplication::desktop()->screenGeometry(&w); + QRect availRect = w.screen()->availableGeometry(); + QRect screenRect = w.screen()->geometry(); while(menu.sizeHint().height() < (screenRect.height()*2/3)) { menu.addAction("item"); diff --git a/tests/manual/dialogs/printdialogpanel.cpp b/tests/manual/dialogs/printdialogpanel.cpp index 8d64d2f6a62..b7447e3d643 100644 --- a/tests/manual/dialogs/printdialogpanel.cpp +++ b/tests/manual/dialogs/printdialogpanel.cpp @@ -710,8 +710,7 @@ void PrintDialogPanel::showPreviewDialog() applySettings(m_printer.data()); PrintPreviewDialog dialog(m_printer.data(), this); #if QT_VERSION >= 0x050000 - const int screenNumber = QApplication::desktop()->screenNumber(this); - const QSize availableSize = QGuiApplication::screens().at(screenNumber)->availableSize(); + const QSize availableSize = screen()->availableSize(); #else const QSize availableSize = QApplication::desktop()->availableGeometry().size(); #endif diff --git a/tests/manual/qcursor/qcursorhighdpi/main.cpp b/tests/manual/qcursor/qcursorhighdpi/main.cpp index 017f41eccd2..e70be333fd8 100644 --- a/tests/manual/qcursor/qcursorhighdpi/main.cpp +++ b/tests/manual/qcursor/qcursorhighdpi/main.cpp @@ -218,7 +218,7 @@ protected: VerticalRuler::VerticalRuler(QWidget *parent) : QWidget(parent) { - const int screenWidth = QApplication::desktop()->screenGeometry(this).width(); + const int screenWidth = screen()->geometry().width(); setFixedWidth(screenWidth / 48); // 1920 pixel monitor ->40 } From 80ddac3a0a9984e1dc4da6440912cfcfd210a380 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 11 Oct 2019 10:01:00 +0200 Subject: [PATCH 16/23] 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ø --- .../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 c4b6e22c374..19288d07a79 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; From 06ca5c49e7fb6dd23eab3a02de404c82e03bc5db Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 14 Oct 2019 15:23:48 +0200 Subject: [PATCH 17/23] 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 90536180149..1b170739d29 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 f79fc572c43..3c325b59e75 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); } From 5f160a3699d80d1736f691ad9ef774eb6aa28079 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 14 Oct 2019 15:18:44 +0200 Subject: [PATCH 18/23] Fix static linking when bearer management plugins are built MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bearer plugins include copies of moc generated code that results in duplicate symbols when static linking pulls in multiple bearer plugins. Instead of relying on toolchain defined behavior, this patch moves the code that is shared into the shared library as private API. This way it will exist only once in memory and once at link time, resulting no linking errors about duplicate symbols. Fixes: QTBUG-79211 Change-Id: Iafa45c234e7fdd998971fc9cb7116334d08907bc Reviewed-by: Mårten Nordheim --- src/network/bearer/bearer.pri | 3 +++ .../bearer/qbearerengine_impl_p.h} | 6 +++++- src/{plugins => network}/bearer/qnetworksession_impl.cpp | 8 ++++++-- .../bearer/qnetworksession_impl_p.h} | 8 ++++++-- src/plugins/bearer/android/src/qandroidbearerengine.cpp | 2 +- src/plugins/bearer/android/src/qandroidbearerengine.h | 2 +- src/plugins/bearer/android/src/src.pro | 7 ++----- src/plugins/bearer/connman/connman.pro | 7 ++----- src/plugins/bearer/connman/qconnmanengine.cpp | 2 +- src/plugins/bearer/connman/qconnmanengine.h | 2 +- src/plugins/bearer/corewlan/corewlan.pro | 7 ++----- src/plugins/bearer/corewlan/qcorewlanengine.h | 2 +- src/plugins/bearer/corewlan/qcorewlanengine.mm | 2 +- src/plugins/bearer/generic/generic.pro | 3 --- src/plugins/bearer/generic/qgenericengine.cpp | 2 +- src/plugins/bearer/generic/qgenericengine.h | 2 +- src/plugins/bearer/nativewifi/nativewifi.pro | 7 ++----- src/plugins/bearer/nativewifi/qnativewifiengine.cpp | 2 +- src/plugins/bearer/nativewifi/qnativewifiengine.h | 2 +- src/plugins/bearer/networkmanager/networkmanager.pro | 7 ++----- .../bearer/networkmanager/qnetworkmanagerengine.cpp | 2 +- src/plugins/bearer/networkmanager/qnetworkmanagerengine.h | 2 +- src/plugins/bearer/nla/nla.pro | 7 ++----- src/plugins/bearer/nla/qnlaengine.cpp | 2 +- src/plugins/bearer/nla/qnlaengine.h | 2 +- 25 files changed, 46 insertions(+), 52 deletions(-) rename src/{plugins/bearer/qbearerengine_impl.h => network/bearer/qbearerengine_impl_p.h} (95%) rename src/{plugins => network}/bearer/qnetworksession_impl.cpp (99%) rename src/{plugins/bearer/qnetworksession_impl.h => network/bearer/qnetworksession_impl_p.h} (96%) diff --git a/src/network/bearer/bearer.pri b/src/network/bearer/bearer.pri index d58d5ec1687..bcb7a5971e7 100644 --- a/src/network/bearer/bearer.pri +++ b/src/network/bearer/bearer.pri @@ -6,11 +6,14 @@ HEADERS += bearer/qnetworkconfiguration.h \ bearer/qnetworkconfigmanager_p.h \ bearer/qnetworkconfiguration_p.h \ bearer/qnetworksession_p.h \ + bearer/qnetworksession_impl_p.h \ bearer/qbearerengine_p.h \ + bearer/qbearerengine_impl_p.h \ bearer/qbearerplugin_p.h \ bearer/qsharednetworksession_p.h SOURCES += bearer/qnetworksession.cpp \ + bearer/qnetworksession_impl.cpp \ bearer/qnetworkconfigmanager.cpp \ bearer/qnetworkconfiguration.cpp \ bearer/qnetworkconfigmanager_p.cpp \ diff --git a/src/plugins/bearer/qbearerengine_impl.h b/src/network/bearer/qbearerengine_impl_p.h similarity index 95% rename from src/plugins/bearer/qbearerengine_impl.h rename to src/network/bearer/qbearerengine_impl_p.h index 5c003aaaf66..4221b73276e 100644 --- a/src/plugins/bearer/qbearerengine_impl.h +++ b/src/network/bearer/qbearerengine_impl_p.h @@ -42,9 +42,11 @@ #include +#ifndef QT_NO_BEARERMANAGEMENT + QT_BEGIN_NAMESPACE -class QBearerEngineImpl : public QBearerEngine +class Q_NETWORK_EXPORT QBearerEngineImpl : public QBearerEngine { Q_OBJECT @@ -78,4 +80,6 @@ QT_END_NAMESPACE Q_DECLARE_METATYPE(QBearerEngineImpl::ConnectionError) +#endif // QT_NO_BEARERMANAGEMENT + #endif // QBEARERENGINE_IMPL_H diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/network/bearer/qnetworksession_impl.cpp similarity index 99% rename from src/plugins/bearer/qnetworksession_impl.cpp rename to src/network/bearer/qnetworksession_impl.cpp index c6b678ab208..4b8631d4db0 100644 --- a/src/plugins/bearer/qnetworksession_impl.cpp +++ b/src/network/bearer/qnetworksession_impl.cpp @@ -40,8 +40,8 @@ // see comment in ../platformdefs_win.h. #define WIN32_LEAN_AND_MEAN 1 -#include "qnetworksession_impl.h" -#include "qbearerengine_impl.h" +#include "qnetworksession_impl_p.h" +#include "qbearerengine_impl_p.h" #include #include @@ -51,6 +51,8 @@ #include #include +#ifndef QT_NO_BEARERMANAGEMENT + QT_BEGIN_NAMESPACE static QBearerEngineImpl *getEngineFromId(const QString &id) @@ -433,3 +435,5 @@ void QNetworkSessionPrivateImpl::decrementTimeout() QT_END_NAMESPACE #include "qnetworksession_impl.moc" + +#endif // QT_NO_BEARERMANAGEMENT diff --git a/src/plugins/bearer/qnetworksession_impl.h b/src/network/bearer/qnetworksession_impl_p.h similarity index 96% rename from src/plugins/bearer/qnetworksession_impl.h rename to src/network/bearer/qnetworksession_impl_p.h index 0f8e0149006..b1747601524 100644 --- a/src/plugins/bearer/qnetworksession_impl.h +++ b/src/network/bearer/qnetworksession_impl_p.h @@ -51,16 +51,18 @@ // We mean it. // -#include "qbearerengine_impl.h" +#include "qbearerengine_impl_p.h" #include #include +#ifndef QT_NO_BEARERMANAGEMENT + QT_BEGIN_NAMESPACE class QBearerEngineImpl; -class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate +class Q_NETWORK_EXPORT QNetworkSessionPrivateImpl : public QNetworkSessionPrivate { Q_OBJECT @@ -127,4 +129,6 @@ private: QT_END_NAMESPACE +#endif // QT_NO_BEARERMANAGEMENT + #endif // QNETWORKSESSION_IMPL_H diff --git a/src/plugins/bearer/android/src/qandroidbearerengine.cpp b/src/plugins/bearer/android/src/qandroidbearerengine.cpp index a43ed695708..ad9895e0cf2 100644 --- a/src/plugins/bearer/android/src/qandroidbearerengine.cpp +++ b/src/plugins/bearer/android/src/qandroidbearerengine.cpp @@ -38,7 +38,7 @@ ****************************************************************************/ #include "qandroidbearerengine.h" -#include "../../qnetworksession_impl.h" +#include #include "wrappers/androidconnectivitymanager.h" #ifndef QT_NO_BEARERMANAGEMENT diff --git a/src/plugins/bearer/android/src/qandroidbearerengine.h b/src/plugins/bearer/android/src/qandroidbearerengine.h index 837b02232d6..867d04d8865 100644 --- a/src/plugins/bearer/android/src/qandroidbearerengine.h +++ b/src/plugins/bearer/android/src/qandroidbearerengine.h @@ -40,7 +40,7 @@ #ifndef QANDROIDBEARERENGINE_H #define QANDROIDBEARERENGINE_H -#include "../../qbearerengine_impl.h" +#include #include #include diff --git a/src/plugins/bearer/android/src/src.pro b/src/plugins/bearer/android/src/src.pro index eb0738386c6..fcd599dffe8 100644 --- a/src/plugins/bearer/android/src/src.pro +++ b/src/plugins/bearer/android/src/src.pro @@ -2,13 +2,10 @@ TARGET = qandroidbearer QT = core-private network-private -HEADERS += qandroidbearerengine.h \ - ../../qnetworksession_impl.h \ - ../../qbearerengine_impl.h +HEADERS += qandroidbearerengine.h SOURCES += main.cpp \ - qandroidbearerengine.cpp \ - ../../qnetworksession_impl.cpp + qandroidbearerengine.cpp include(wrappers/wrappers.pri) diff --git a/src/plugins/bearer/connman/connman.pro b/src/plugins/bearer/connman/connman.pro index 065ed11dad3..d6577e9d7ff 100644 --- a/src/plugins/bearer/connman/connman.pro +++ b/src/plugins/bearer/connman/connman.pro @@ -4,15 +4,12 @@ QT = core network-private dbus HEADERS += qconnmanservice_linux_p.h \ ../linux_common/qofonoservice_linux_p.h \ - qconnmanengine.h \ - ../qnetworksession_impl.h \ - ../qbearerengine_impl.h + qconnmanengine.h SOURCES += main.cpp \ qconnmanservice_linux.cpp \ ../linux_common/qofonoservice_linux.cpp \ - qconnmanengine.cpp \ - ../qnetworksession_impl.cpp + qconnmanengine.cpp OTHER_FILES += connman.json diff --git a/src/plugins/bearer/connman/qconnmanengine.cpp b/src/plugins/bearer/connman/qconnmanengine.cpp index 8b2076bd18f..a6738348254 100644 --- a/src/plugins/bearer/connman/qconnmanengine.cpp +++ b/src/plugins/bearer/connman/qconnmanengine.cpp @@ -39,7 +39,7 @@ #include "qconnmanengine.h" #include "qconnmanservice_linux_p.h" -#include "../qnetworksession_impl.h" +#include #include diff --git a/src/plugins/bearer/connman/qconnmanengine.h b/src/plugins/bearer/connman/qconnmanengine.h index ef80d38fa2b..eb79dbec1be 100644 --- a/src/plugins/bearer/connman/qconnmanengine.h +++ b/src/plugins/bearer/connman/qconnmanengine.h @@ -51,7 +51,7 @@ // We mean it. // -#include "../qbearerengine_impl.h" +#include #include "qconnmanservice_linux_p.h" #include "../linux_common/qofonoservice_linux_p.h" diff --git a/src/plugins/bearer/corewlan/corewlan.pro b/src/plugins/bearer/corewlan/corewlan.pro index 1dc09ebdd65..4f08eaba715 100644 --- a/src/plugins/bearer/corewlan/corewlan.pro +++ b/src/plugins/bearer/corewlan/corewlan.pro @@ -7,12 +7,9 @@ qtConfig(corewlan) { LIBS += -framework CoreWLAN -framework Security } -HEADERS += qcorewlanengine.h \ - ../qnetworksession_impl.h \ - ../qbearerengine_impl.h +HEADERS += qcorewlanengine.h -SOURCES += main.cpp \ - ../qnetworksession_impl.cpp +SOURCES += main.cpp OBJECTIVE_SOURCES += qcorewlanengine.mm diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index 6dddee66a41..8775474c091 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -40,7 +40,7 @@ #ifndef QCOREWLANENGINE_H #define QCOREWLANENGINE_H -#include "../qbearerengine_impl.h" +#include #include #include diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index 4644b5af9fb..11798995575 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -38,7 +38,7 @@ ****************************************************************************/ #include "qcorewlanengine.h" -#include "../qnetworksession_impl.h" +#include #include diff --git a/src/plugins/bearer/generic/generic.pro b/src/plugins/bearer/generic/generic.pro index f30bdc4951e..14b858b3016 100644 --- a/src/plugins/bearer/generic/generic.pro +++ b/src/plugins/bearer/generic/generic.pro @@ -3,11 +3,8 @@ TARGET = qgenericbearer QT = core-private network-private HEADERS += qgenericengine.h \ - ../qnetworksession_impl.h \ - ../qbearerengine_impl.h \ ../platformdefs_win.h SOURCES += qgenericengine.cpp \ - ../qnetworksession_impl.cpp \ main.cpp OTHER_FILES += generic.json diff --git a/src/plugins/bearer/generic/qgenericengine.cpp b/src/plugins/bearer/generic/qgenericengine.cpp index b1f28849a7a..a5fba15789e 100644 --- a/src/plugins/bearer/generic/qgenericengine.cpp +++ b/src/plugins/bearer/generic/qgenericengine.cpp @@ -41,7 +41,7 @@ #define WIN32_LEAN_AND_MEAN 1 #include "qgenericengine.h" -#include "../qnetworksession_impl.h" +#include #include diff --git a/src/plugins/bearer/generic/qgenericengine.h b/src/plugins/bearer/generic/qgenericengine.h index 79c71ca7a31..6b8fb4cd0f2 100644 --- a/src/plugins/bearer/generic/qgenericengine.h +++ b/src/plugins/bearer/generic/qgenericengine.h @@ -40,7 +40,7 @@ #ifndef QGENERICENGINE_H #define QGENERICENGINE_H -#include "../qbearerengine_impl.h" +#include #include #include diff --git a/src/plugins/bearer/nativewifi/nativewifi.pro b/src/plugins/bearer/nativewifi/nativewifi.pro index da7f2da353e..41bde993419 100644 --- a/src/plugins/bearer/nativewifi/nativewifi.pro +++ b/src/plugins/bearer/nativewifi/nativewifi.pro @@ -3,13 +3,10 @@ TARGET = qnativewifibearer QT = core-private network-private HEADERS += qnativewifiengine.h \ - platformdefs.h \ - ../qnetworksession_impl.h \ - ../qbearerengine_impl.h + platformdefs.h SOURCES += main.cpp \ - qnativewifiengine.cpp \ - ../qnetworksession_impl.cpp + qnativewifiengine.cpp OTHER_FILES += nativewifi.json diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp index 777b4eea596..ca8700e63b3 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.cpp +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.cpp @@ -39,7 +39,7 @@ #include "qnativewifiengine.h" #include "platformdefs.h" -#include "../qnetworksession_impl.h" +#include #include diff --git a/src/plugins/bearer/nativewifi/qnativewifiengine.h b/src/plugins/bearer/nativewifi/qnativewifiengine.h index ab8d949c9a2..24e97bf6df3 100644 --- a/src/plugins/bearer/nativewifi/qnativewifiengine.h +++ b/src/plugins/bearer/nativewifi/qnativewifiengine.h @@ -51,7 +51,7 @@ // We mean it. // -#include "../qbearerengine_impl.h" +#include #include diff --git a/src/plugins/bearer/networkmanager/networkmanager.pro b/src/plugins/bearer/networkmanager/networkmanager.pro index e71c93f66f0..3fbad07ef52 100644 --- a/src/plugins/bearer/networkmanager/networkmanager.pro +++ b/src/plugins/bearer/networkmanager/networkmanager.pro @@ -4,15 +4,12 @@ QT = core network-private dbus HEADERS += qnetworkmanagerservice.h \ qnetworkmanagerengine.h \ - ../linux_common/qofonoservice_linux_p.h \ - ../qnetworksession_impl.h \ - ../qbearerengine_impl.h + ../linux_common/qofonoservice_linux_p.h SOURCES += main.cpp \ qnetworkmanagerservice.cpp \ qnetworkmanagerengine.cpp \ - ../linux_common/qofonoservice_linux.cpp \ - ../qnetworksession_impl.cpp + ../linux_common/qofonoservice_linux.cpp OTHER_FILES += networkmanager.json diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index e74b1cf7449..d686bc4e51d 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -39,7 +39,7 @@ #include "qnetworkmanagerengine.h" #include "qnetworkmanagerservice.h" -#include "../qnetworksession_impl.h" +#include #include diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h index a95c68abdfc..c6c5280eca9 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h @@ -51,7 +51,7 @@ // We mean it. // -#include "../qbearerengine_impl.h" +#include #include "qnetworkmanagerservice.h" diff --git a/src/plugins/bearer/nla/nla.pro b/src/plugins/bearer/nla/nla.pro index 76f3279d25e..2582dc7cd4d 100644 --- a/src/plugins/bearer/nla/nla.pro +++ b/src/plugins/bearer/nla/nla.pro @@ -5,13 +5,10 @@ QT = core core-private network network-private QMAKE_USE_PRIVATE += ws2_32 HEADERS += qnlaengine.h \ - ../platformdefs_win.h \ - ../qnetworksession_impl.h \ - ../qbearerengine_impl.h + ../platformdefs_win.h SOURCES += main.cpp \ - qnlaengine.cpp \ - ../qnetworksession_impl.cpp + qnlaengine.cpp OTHER_FILES += nla.json diff --git a/src/plugins/bearer/nla/qnlaengine.cpp b/src/plugins/bearer/nla/qnlaengine.cpp index e1e60389f18..ab3c0d0e3ab 100644 --- a/src/plugins/bearer/nla/qnlaengine.cpp +++ b/src/plugins/bearer/nla/qnlaengine.cpp @@ -38,7 +38,7 @@ ****************************************************************************/ #include "qnlaengine.h" -#include "../qnetworksession_impl.h" +#include #include diff --git a/src/plugins/bearer/nla/qnlaengine.h b/src/plugins/bearer/nla/qnlaengine.h index ab014ff776a..90efa50201e 100644 --- a/src/plugins/bearer/nla/qnlaengine.h +++ b/src/plugins/bearer/nla/qnlaengine.h @@ -51,7 +51,7 @@ // We mean it. // -#include "../qbearerengine_impl.h" +#include #include From 8814c5778d7b9ccc64956abed6af9737c4a35d39 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Thu, 7 Jun 2018 13:44:15 +0200 Subject: [PATCH 19/23] tst_QAbstractScrollArea: Use qWaitForWindowExposed 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: I53011ad623e4bdb557d79c136f06ce7ac00a08ee Reviewed-by: Tor Arne Vestbø --- .../widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp b/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp index a17a9f6c33c..01ecfb2ca95 100644 --- a/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp +++ b/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp @@ -356,7 +356,7 @@ void tst_QAbstractScrollArea::patternBackground() widget.resize(600, 600); scrollArea.setWidget(&widget); topLevel.show(); - QVERIFY(QTest::qWaitForWindowActive(&topLevel)); + QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); QLinearGradient linearGrad(QPointF(250, 250), QPointF(300, 300)); linearGrad.setColorAt(0, Qt::yellow); From 821c2eb1310e72a1123eac69ef2aab8fc52dd0aa Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Thu, 10 Oct 2019 16:20:01 +0200 Subject: [PATCH 20/23] tst_qfiledialog2: Don't assume window activation is available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prefer qWaitForWindowExposed over qWaitForWindowActive whenever possible, skip in the other cases. Makes the test pass on Wayland. Task-number: QTBUG-62188 Change-Id: I60b4000c72c3727a2f33b79a5038469055b0fef2 Reviewed-by: Tor Arne Vestbø --- .../dialogs/qfiledialog2/tst_qfiledialog2.cpp | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp index 40eff1e4c37..52354eda42b 100644 --- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp @@ -53,7 +53,10 @@ #include "../../../../../src/widgets/dialogs/qfilesystemmodel_p.h" #include "../../../../../src/widgets/dialogs/qfiledialog_p.h" +#include + #include +#include #if defined(Q_OS_WIN) #include "../../../network-settings.h" @@ -365,7 +368,7 @@ void tst_QFileDialog2::task143519_deleteAndRenameActionBehavior() fd.selectFile(ctx.file.fileName()); fd.show(); - QVERIFY(QTest::qWaitForWindowActive(&fd)); + QVERIFY(QTest::qWaitForWindowExposed(&fd)); // grab some internals: QAction *rm = fd.findChild("qt_delete_action"); @@ -548,7 +551,7 @@ void tst_QFileDialog2::task227304_proxyOnFileDialog() QFileDialog fd(0, "", QDir::currentPath(), 0); fd.setProxyModel(new FilterDirModel(QDir::currentPath())); fd.show(); - QVERIFY(QTest::qWaitForWindowActive(&fd)); + QVERIFY(QTest::qWaitForWindowExposed(&fd)); QLineEdit *edit = fd.findChild("fileNameEdit"); QVERIFY(edit); QTest::keyClick(edit, Qt::Key_T); @@ -558,7 +561,7 @@ void tst_QFileDialog2::task227304_proxyOnFileDialog() CrashDialog *dialog = new CrashDialog(0, QString("crash dialog test"), QDir::homePath(), QString("*") ); dialog->setFileMode(QFileDialog::ExistingFile); dialog->show(); - QVERIFY(QTest::qWaitForWindowActive(dialog)); + QVERIFY(QTest::qWaitForWindowExposed(dialog)); QListView *list = dialog->findChild("listView"); QVERIFY(list); @@ -600,7 +603,7 @@ void tst_QFileDialog2::task227930_correctNavigationKeyboardBehavior() fd.setViewMode(QFileDialog::List); fd.setDirectory(current.absolutePath()); fd.show(); - QVERIFY(QTest::qWaitForWindowActive(&fd)); + QVERIFY(QTest::qWaitForWindowExposed(&fd)); // Ensure LayoutRequest event is processed so that the list view // is sorted correctly to have the directory entires at the top. @@ -765,7 +768,7 @@ void tst_QFileDialog2::task235069_hideOnEscape() fd.setDirectory(current.absolutePath()); fd.setAcceptMode(QFileDialog::AcceptSave); fd.show(); - QVERIFY(QTest::qWaitForWindowActive(&fd)); + QVERIFY(QTest::qWaitForWindowExposed(&fd)); QWidget *child = fd.findChild(childName); QVERIFY(child); child->setFocus(); @@ -787,7 +790,7 @@ void tst_QFileDialog2::task236402_dontWatchDeletedDir() fd.setDirectory(current.absolutePath()); fd.setAcceptMode( QFileDialog::AcceptSave); fd.show(); - QVERIFY(QTest::qWaitForWindowActive(&fd)); + QVERIFY(QTest::qWaitForWindowExposed(&fd)); QListView *list = fd.findChild("listView"); QVERIFY(list); list->setFocus(); @@ -808,7 +811,7 @@ void tst_QFileDialog2::task203703_returnProperSeparator() fd.setViewMode(QFileDialog::List); fd.setFileMode(QFileDialog::Directory); fd.show(); - QVERIFY(QTest::qWaitForWindowActive(&fd)); + QVERIFY(QTest::qWaitForWindowExposed(&fd)); QListView *list = fd.findChild("listView"); QVERIFY(list); list->setFocus(); @@ -844,7 +847,7 @@ void tst_QFileDialog2::task228844_ensurePreviousSorting() fd.setDirectory(current.absolutePath()); fd.setViewMode(QFileDialog::Detail); fd.show(); - QVERIFY(QTest::qWaitForWindowActive(&fd)); + QVERIFY(QTest::qWaitForWindowExposed(&fd)); QTreeView *tree = fd.findChild("treeView"); QVERIFY(tree); tree->header()->setSortIndicator(3,Qt::DescendingOrder); @@ -859,7 +862,7 @@ void tst_QFileDialog2::task228844_ensurePreviousSorting() current.cd("aaaaaaaaaaaaaaaaaa"); fd2.setDirectory(current.absolutePath()); fd2.show(); - QVERIFY(QTest::qWaitForWindowActive(&fd2)); + QVERIFY(QTest::qWaitForWindowExposed(&fd2)); QTreeView *tree2 = fd2.findChild("treeView"); QVERIFY(tree2); tree2->setFocus(); @@ -878,7 +881,7 @@ void tst_QFileDialog2::task228844_ensurePreviousSorting() fd3.restoreState(fd.saveState()); fd3.setFileMode(QFileDialog::Directory); fd3.show(); - QVERIFY(QTest::qWaitForWindowActive(&fd3)); + QVERIFY(QTest::qWaitForWindowExposed(&fd3)); QTreeView *tree3 = fd3.findChild("treeView"); QVERIFY(tree3); tree3->setFocus(); @@ -912,7 +915,7 @@ void tst_QFileDialog2::task239706_editableFilterCombo() QFileDialog d; d.setNameFilter("*.cpp *.h"); d.show(); - QVERIFY(QTest::qWaitForWindowActive(&d)); + QVERIFY(QTest::qWaitForWindowExposed(&d)); QList comboList = d.findChildren(); QComboBox *filterCombo = 0; @@ -963,7 +966,7 @@ void tst_QFileDialog2::task251321_sideBarHiddenEntries() urls << QUrl::fromLocalFile(hiddenSubDir.absolutePath()); fd.setSidebarUrls(urls); fd.show(); - QVERIFY(QTest::qWaitForWindowActive(&fd)); + QVERIFY(QTest::qWaitForWindowExposed(&fd)); QSidebar *sidebar = fd.findChild("sidebar"); QVERIFY(sidebar); @@ -1017,7 +1020,7 @@ void tst_QFileDialog2::task251341_sideBarRemoveEntries() urls << QUrl::fromLocalFile("NotFound"); fd.setSidebarUrls(urls); fd.show(); - QVERIFY(QTest::qWaitForWindowActive(&fd)); + QVERIFY(QTest::qWaitForWindowExposed(&fd)); QSidebar *sidebar = fd.findChild("sidebar"); QVERIFY(sidebar); @@ -1089,7 +1092,7 @@ void tst_QFileDialog2::task254490_selectFileMultipleTimes() fd.selectFile("new_file.txt"); fd.show(); - QVERIFY(QTest::qWaitForWindowActive(&fd)); + QVERIFY(QTest::qWaitForWindowExposed(&fd)); QLineEdit *lineEdit = fd.findChild("fileNameEdit"); QVERIFY(lineEdit); @@ -1133,7 +1136,7 @@ void tst_QFileDialog2::task259105_filtersCornerCases() fd.setNameFilter(QLatin1String("All Files! (*);;Text Files (*.txt)")); fd.setOption(QFileDialog::HideNameFilterDetails, true); fd.show(); - QVERIFY(QTest::qWaitForWindowActive(&fd)); + QVERIFY(QTest::qWaitForWindowExposed(&fd)); //Extensions are hidden QComboBox *filters = fd.findChild("fileTypeCombo"); @@ -1170,6 +1173,9 @@ void tst_QFileDialog2::task259105_filtersCornerCases() void tst_QFileDialog2::QTBUG4419_lineEditSelectAll() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + QString tempPath = tempDir.path(); QTemporaryFile temporaryFile(tempPath + "/tst_qfiledialog2_lineEditSelectAll.XXXXXX"); QVERIFY2(temporaryFile.open(), qPrintable(temporaryFile.errorString())); @@ -1195,6 +1201,9 @@ void tst_QFileDialog2::QTBUG4419_lineEditSelectAll() void tst_QFileDialog2::QTBUG6558_showDirsOnly() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + const QString tempPath = tempDir.path(); QDir dirTemp(tempPath); const QString tempName = QLatin1String("showDirsOnly.") + QString::number(QRandomGenerator::global()->generate()); @@ -1261,6 +1270,9 @@ void tst_QFileDialog2::QTBUG6558_showDirsOnly() void tst_QFileDialog2::QTBUG4842_selectFilterWithHideNameFilterDetails() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + QStringList filtersStr; filtersStr << "Images (*.png *.xpm *.jpg)" << "Text files (*.txt)" << "XML files (*.xml)"; QString chosenFilterString("Text files (*.txt)"); @@ -1301,6 +1313,9 @@ void tst_QFileDialog2::QTBUG4842_selectFilterWithHideNameFilterDetails() void tst_QFileDialog2::dontShowCompleterOnRoot() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + QFileDialog fd(0, "TestFileDialog"); fd.setAcceptMode(QFileDialog::AcceptSave); fd.show(); From 85ed676dff68b4d5cfa62112d758d80fb050594c Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 14 Oct 2019 15:12:02 +0200 Subject: [PATCH 21/23] Provide a feature for CBOR stream I/O We need to turn it off in bootstrap code. Change-Id: I826e49fbc5f6128e56f84b58d29358dd7b0b9dc5 Reviewed-by: Lars Knoll --- src/corelib/configure.json | 8 ++++++++ src/corelib/global/qconfig-bootstrapped.h | 1 + src/corelib/serialization/qcborstream.h | 2 ++ src/corelib/serialization/qcborvalue.cpp | 9 +++++++++ src/corelib/serialization/qcborvalue.h | 4 ++++ src/corelib/serialization/serialization.pri | 10 ++++++++-- 6 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/corelib/configure.json b/src/corelib/configure.json index ae360239c6a..b4b7c4eec3a 100644 --- a/src/corelib/configure.json +++ b/src/corelib/configure.json @@ -1086,6 +1086,14 @@ Mozilla License) is included. The data is then also used in QNetworkCookieJar::v "win32_system_libs": { "label": "Windows System Libraries", "condition": "config.win32 && libs.advapi32 && libs.gdi32 && libs.kernel32 && libs.netapi32 && libs.ole32 && libs.shell32 && libs.uuid && libs.user32 && libs.winmm && libs.ws2_32" + }, + "cborstream": { + "label": "CBOR stream I/O", + "purpose": "Provides support for reading and writing the CBOR binary format. + +Note that this is required for plugin loading. Qt GUI needs QPA plugins for basic operation.", + "section": "Utilities", + "output": [ "publicFeature" ] } }, diff --git a/src/corelib/global/qconfig-bootstrapped.h b/src/corelib/global/qconfig-bootstrapped.h index e6ad80525a0..e9383ca68b9 100644 --- a/src/corelib/global/qconfig-bootstrapped.h +++ b/src/corelib/global/qconfig-bootstrapped.h @@ -74,6 +74,7 @@ #else # define QT_FEATURE_alloca_malloc_h -1 #endif +#define QT_FEATURE_cborstream -1 #define QT_CRYPTOGRAPHICHASH_ONLY_SHA1 #define QT_FEATURE_cxx11_random (QT_HAS_INCLUDE() ? 1 : -1) #define QT_NO_DATASTREAM diff --git a/src/corelib/serialization/qcborstream.h b/src/corelib/serialization/qcborstream.h index 7a451e63ac9..08bf680cca9 100644 --- a/src/corelib/serialization/qcborstream.h +++ b/src/corelib/serialization/qcborstream.h @@ -47,6 +47,8 @@ #include #include +QT_REQUIRE_CONFIG(cborstream); + // See qcborcommon.h for why we check #if defined(QT_X11_DEFINES_FOUND) # undef True diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp index 1b170739d29..b77cfd5c704 100644 --- a/src/corelib/serialization/qcborvalue.cpp +++ b/src/corelib/serialization/qcborvalue.cpp @@ -42,7 +42,10 @@ #include "qdatastream.h" #include "qcborarray.h" #include "qcbormap.h" + +#if QT_CONFIG(cborstream) #include "qcborstream.h" +#endif #include #include @@ -758,6 +761,7 @@ QT_BEGIN_NAMESPACE using namespace QtCbor; +#if QT_CONFIG(cborstream) // in qcborstream.cpp extern void qt_cbor_stream_set_error(QCborStreamReaderPrivate *d, QCborError error); @@ -799,6 +803,7 @@ static void writeDoubleToCbor(QCborStreamWriter &writer, double d, QCborValue::E writer.append(d); } +#endif // QT_CONFIG(cborstream) static inline int typeOrder(Element e1, Element e2) { @@ -1221,6 +1226,7 @@ int QCborMap::compare(const QCborMap &other) const noexcept return compareContainer(d.data(), other.d.data()); } +#if QT_CONFIG(cborstream) static void encodeToCbor(QCborStreamWriter &writer, const QCborContainerPrivate *d, qsizetype idx, QCborValue::EncodingOptions opt) { @@ -1632,6 +1638,7 @@ void QCborContainerPrivate::decodeFromCbor(QCborStreamReader &reader) if (reader.lastError() == QCborError::NoError) reader.leaveContainer(); } +#endif // QT_CONFIG(cborstream) /*! Creates a QCborValue with byte array value \a ba. The value can later be @@ -2330,6 +2337,7 @@ QCborValueRef QCborValue::operator[](qint64 key) return { container, index }; } +#if QT_CONFIG(cborstream) /*! Decodes one item from the CBOR stream found in \a reader and returns the equivalent representation. This function is recursive: if the item is a map @@ -2567,6 +2575,7 @@ void QCborValueRef::toCbor(QCborStreamWriter &writer, QCborValue::EncodingOption { concrete().toCbor(writer, opt); } +#endif // QT_CONFIG(cborstream) void QCborValueRef::assign(QCborValueRef that, const QCborValue &other) { diff --git a/src/corelib/serialization/qcborvalue.h b/src/corelib/serialization/qcborvalue.h index 3c325b59e75..accd0fae8aa 100644 --- a/src/corelib/serialization/qcborvalue.h +++ b/src/corelib/serialization/qcborvalue.h @@ -285,6 +285,7 @@ public: static QCborValue fromJsonValue(const QJsonValue &v); QJsonValue toJsonValue() const; +#if QT_CONFIG(cborstream) static QCborValue fromCbor(QCborStreamReader &reader); static QCborValue fromCbor(const QByteArray &ba, QCborParserError *error = nullptr); static QCborValue fromCbor(const char *data, qsizetype len, QCborParserError *error = nullptr) @@ -293,6 +294,7 @@ public: { return fromCbor(QByteArray(reinterpret_cast(data), int(len)), error); } QByteArray toCbor(EncodingOptions opt = NoTransformation); void toCbor(QCborStreamWriter &writer, EncodingOptions opt = NoTransformation); +#endif QString toDiagnosticNotation(DiagnosticNotationOptions opts = Compact) const; @@ -435,9 +437,11 @@ public: QVariant toVariant() const { return concrete().toVariant(); } QJsonValue toJsonValue() const; +#if QT_CONFIG(cborstream) QByteArray toCbor(QCborValue::EncodingOptions opt = QCborValue::NoTransformation) { return concrete().toCbor(opt); } void toCbor(QCborStreamWriter &writer, QCborValue::EncodingOptions opt = QCborValue::NoTransformation); +#endif QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt = QCborValue::Compact) { return concrete().toDiagnosticNotation(opt); } diff --git a/src/corelib/serialization/serialization.pri b/src/corelib/serialization/serialization.pri index 4f2dc64e4f4..5310fddd672 100644 --- a/src/corelib/serialization/serialization.pri +++ b/src/corelib/serialization/serialization.pri @@ -6,7 +6,6 @@ HEADERS += \ serialization/qcbormap.h \ serialization/qcborvalue.h \ serialization/qcborvalue_p.h \ - serialization/qcborstream.h \ serialization/qdatastream.h \ serialization/qdatastream_p.h \ serialization/qjson_p.h \ @@ -23,7 +22,6 @@ HEADERS += \ serialization/qxmlutils_p.h SOURCES += \ - serialization/qcborstream.cpp \ serialization/qcbordiagnostic.cpp \ serialization/qcborvalue.cpp \ serialization/qdatastream.cpp \ @@ -39,6 +37,14 @@ SOURCES += \ serialization/qxmlstream.cpp \ serialization/qxmlutils.cpp +qtConfig(cborstream): { + SOURCES += \ + serialization/qcborstream.cpp + + HEADERS += \ + serialization/qcborstream.h +} + false: SOURCES += \ serialization/qcborarray.cpp \ serialization/qcbormap.cpp From dc4212b3a694e143595968419ae5ad695ab2aa03 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 16 Oct 2019 16:50:33 +0200 Subject: [PATCH 22/23] Fix duplicate platform plugin definitions androidplatformplugin.cpp and main.cpp both tried to define the platform plugin entry point. That happens to work with the android toolchain by chance, but it's certainly not intentional. Change-Id: Ie92281abfb2335aa3ee83bc0ba660700d3485b2d Reviewed-by: BogDan Vatra --- src/plugins/platforms/android/android.pro | 1 - .../android/androidplatformplugin.cpp | 64 ------------------- src/plugins/platforms/android/main.cpp | 1 + 3 files changed, 1 insertion(+), 65 deletions(-) delete mode 100644 src/plugins/platforms/android/androidplatformplugin.cpp diff --git a/src/plugins/platforms/android/android.pro b/src/plugins/platforms/android/android.pro index 730247cd7fd..61cac51633a 100644 --- a/src/plugins/platforms/android/android.pro +++ b/src/plugins/platforms/android/android.pro @@ -16,7 +16,6 @@ INCLUDEPATH += \ $$QT_SOURCE_TREE/src/3rdparty/android SOURCES += $$PWD/main.cpp \ - $$PWD/androidplatformplugin.cpp \ $$PWD/androidcontentfileengine.cpp \ $$PWD/androiddeadlockprotector.cpp \ $$PWD/androidjnimain.cpp \ diff --git a/src/plugins/platforms/android/androidplatformplugin.cpp b/src/plugins/platforms/android/androidplatformplugin.cpp deleted file mode 100644 index 297e167f47d..00000000000 --- a/src/plugins/platforms/android/androidplatformplugin.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 BogDan Vatra -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include "qandroidplatformintegration.h" - -QT_BEGIN_NAMESPACE - -class QAndroidPlatformIntegrationPlugin: public QPlatformIntegrationPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID QPlatformIntegrationFactoryInterface_iid FILE "android.json") -public: - QPlatformIntegration *create(const QString &key, const QStringList ¶mList) override; -}; - - -QPlatformIntegration *QAndroidPlatformIntegrationPlugin::create(const QString &key, const QStringList ¶mList) -{ - Q_UNUSED(paramList); - if (!key.compare(QLatin1String("android"), Qt::CaseInsensitive)) - return new QAndroidPlatformIntegration(paramList); - return 0; -} - -QT_END_NAMESPACE -#include "androidplatformplugin.moc" - diff --git a/src/plugins/platforms/android/main.cpp b/src/plugins/platforms/android/main.cpp index c304fc8d690..4841d0425c4 100644 --- a/src/plugins/platforms/android/main.cpp +++ b/src/plugins/platforms/android/main.cpp @@ -61,3 +61,4 @@ QPlatformIntegration *QAndroidIntegrationPlugin::create(const QString& system, c } QT_END_NAMESPACE +#include "main.moc" From c222a9283d94ad1e29334bb2fba0beef7cc716c7 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Tue, 18 Jun 2019 00:07:54 +0200 Subject: [PATCH 23/23] QAbstractItemModel: implement QRegularExpression support for match This is part of the migration of qtbase from QRexExp to QRegularExpression. [ChangeLog][QtCore][QAbstractItemModel] The match() method now supports the new Qt::RegularExpression match flag value. This will allow users to use either a string or a fully configured QRegularExpression when doing searches. In the second case, the case sensitivity flag will be ignored if passed. Task-number: QTBUG-72587 Change-Id: I07c8d72a661c48b7f4fcf13ef8e95980bcdcb998 Reviewed-by: Giuseppe D'Angelo --- src/corelib/global/qnamespace.h | 5 ++- src/corelib/global/qnamespace.qdoc | 32 ++++++++++++------- src/corelib/itemmodels/qabstractitemmodel.cpp | 32 ++++++++++++++++--- .../tst_qabstractitemmodel.cpp | 28 ++++++++++++++++ 4 files changed, 80 insertions(+), 17 deletions(-) diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 810c55709ca..047ed8e7b36 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1575,9 +1575,12 @@ public: MatchContains = 1, MatchStartsWith = 2, MatchEndsWith = 3, - MatchRegExp = 4, +#if QT_DEPRECATED_SINCE(5, 15) + MatchRegExp Q_DECL_ENUMERATOR_DEPRECATED_X("MatchRegExp is deprecated. Use MatchRegularExpression instead") = 4, +#endif MatchWildcard = 5, MatchFixedString = 8, + MatchRegularExpression = 9, MatchCaseSensitive = 16, MatchWrap = 32, MatchRecursive = 64 diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index cce88782e95..9896cf6e027 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -2840,24 +2840,32 @@ This enum describes the type of matches that can be used when searching for items in a model. - \value MatchExactly Performs QVariant-based matching. - \value MatchFixedString Performs string-based matching. + \value MatchExactly Performs QVariant-based matching. + \value MatchFixedString Performs string-based matching. String-based comparisons are case-insensitive unless the \c MatchCaseSensitive flag is also specified. - \value MatchContains The search term is contained in the item. - \value MatchStartsWith The search term matches the start of the item. - \value MatchEndsWith The search term matches the end of the item. - \value MatchCaseSensitive The search is case sensitive. - \value MatchRegExp Performs string-based matching using a regular - expression as the search term. - \value MatchWildcard Performs string-based matching using a string with + \value MatchContains The search term is contained in the item. + \value MatchStartsWith The search term matches the start of the item. + \value MatchEndsWith The search term matches the end of the item. + \value MatchCaseSensitive The search is case sensitive. + \value MatchRegExp Performs string-based matching using a regular + expression as the search term. Uses the deprecated QRegExp class. + \e{This enum value is deprecated since Qt 5.15.} + \value MatchRegularExpression Performs string-based matching using a regular + expression as the search term. Uses QRegularExpression. + When using this flag, a QRegularExpression object can be passed as + parameter and will directly be used to perform the search. The case + sensitivity flag will be ignored as the QRegularExpression object is + expected to be fully configured. + This enum value was added in Qt 5.15. + \value MatchWildcard Performs string-based matching using a string with wildcards as the search term. - \value MatchWrap Perform a search that wraps around, so that when + \value MatchWrap Perform a search that wraps around, so that when the search reaches the last item in the model, it begins again at the first item and continues until all items have been examined. - \value MatchRecursive Searches the entire hierarchy. + \value MatchRecursive Searches the entire hierarchy. - \sa QString::compare(), QRegExp + \sa QString::compare(), QRegExp, QRegularExpression */ /*! diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 6e97c2fd396..88555f9572f 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -2358,6 +2359,7 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, bool wrap = flags & Qt::MatchWrap; bool allHits = (hits == -1); QString text; // only convert to a string if it is needed + QRegularExpression rx; // only create it if needed const int column = start.column(); QModelIndex p = parent(start); int from = start.row(); @@ -2374,17 +2376,39 @@ QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, if (matchType == Qt::MatchExactly) { if (value == v) result.append(idx); - } else { // QString based matching - if (text.isEmpty()) // lazy conversion - text = value.toString(); + } else { // QString or regular expression based matching + if (matchType == Qt::MatchRegularExpression) { + if (rx.pattern().isEmpty()) { + if (value.type() == QVariant::RegularExpression) { + rx = value.toRegularExpression(); + } else { + rx.setPattern(value.toString()); + if (cs == Qt::CaseInsensitive) + rx.setPatternOptions(QRegularExpression::CaseInsensitiveOption); + } + } + } else if (matchType == Qt::MatchWildcard) { + if (rx.pattern().isEmpty()) + rx.setPattern(QRegularExpression::wildcardToRegularExpression(value.toString())); + if (cs == Qt::CaseInsensitive) + rx.setPatternOptions(QRegularExpression::CaseInsensitiveOption); + } else { + if (text.isEmpty()) // lazy conversion + text = value.toString(); + } + QString t = v.toString(); switch (matchType) { +#if QT_DEPRECATED_SINCE(5, 15) case Qt::MatchRegExp: if (QRegExp(text, cs).exactMatch(t)) result.append(idx); break; +#endif + case Qt::MatchRegularExpression: + Q_FALLTHROUGH(); case Qt::MatchWildcard: - if (QRegExp(text, cs, QRegExp::Wildcard).exactMatch(t)) + if (t.contains(rx)) result.append(idx); break; case Qt::MatchStartsWith: diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp index f305edb2c51..9fab36deaa8 100644 --- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp @@ -458,6 +458,34 @@ void tst_QAbstractItemModel::match() res = model.match(start, Qt::DisplayRole, QVariant("bat"), -1, Qt::MatchFixedString | Qt::MatchCaseSensitive); QCOMPARE(res.count(), 1); + + res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1, + Qt::MatchRegularExpression); + QCOMPARE(res.count(), 2); + res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1, + Qt::MatchRegularExpression | Qt::MatchCaseSensitive); + QCOMPARE(res.count(), 0); + + res = model.match(start, Qt::DisplayRole, QVariant(QRegularExpression(".*O.*")), + -1, Qt::MatchRegularExpression); + QCOMPARE(res.count(), 0); + res = model.match(start, + Qt::DisplayRole, + QVariant(QRegularExpression(".*O.*", + QRegularExpression::CaseInsensitiveOption)), + -1, + Qt::MatchRegularExpression); + QCOMPARE(res.count(), 2); + + // Ensure that the case sensitivity is properly ignored when passing a + // QRegularExpression object. + res = model.match(start, + Qt::DisplayRole, + QVariant(QRegularExpression(".*O.*", + QRegularExpression::CaseInsensitiveOption)), + -1, + Qt::MatchRegularExpression | Qt::MatchCaseSensitive); + QCOMPARE(res.count(), 2); } typedef QPair Position;