From 66a9c4b0b259fe9a61150b7394af0f31ebfd38ac Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Tue, 23 Jul 2019 14:33:31 +0200 Subject: 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 --- .../kernel/qdesktopwidget/tst_qdesktopwidget.cpp | 21 ++++++++++++++++----- tests/manual/qcursor/qcursorhighdpi/main.cpp | 9 +++------ tests/manual/qdesktopwidget/main.cpp | 2 ++ tests/manual/qscreen/main.cpp | 5 ++++- 4 files changed, 25 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp b/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp index 90776dfcb2..a29e8408a3 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 3b18bff91c..017f41eccd 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 f4c82c5f72..978dc62b0e 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 6fba872b12..0728d66bf9 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(); -- cgit v1.2.3 From df91ff555178dd961e27ae11c4cb71811c9308a4 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 11 Oct 2019 09:34:48 +0200 Subject: tst_qgraphicsitem: Don't assume window activation is available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some windowing systems (i.e. Wayland) do not allow applications to steal window focus. Normally, we would just replace qWaitForWindowActive with qWaitForWindowExposed, because that is usually the intent, in this test however, there are many occurrences of both variants right after each other. And, as described in the commit message of 153e8b49a, this may be because window activation may cause repaints, and we want to wait for it to reduce the chance of receiving an extra repaint later (possibly causing tests to be racy). Therefore, I took the conservative approach, and kept the qWaitForWindowActive calls, except when the capability is not available. Hopefully this will not cause flakiness in existing platforms, while also allowing tests to pass on platforms where activation is not supported. Task-number: QTBUG-62188 Change-Id: I15502baa28c464a808d585a5e6d67c9b745b17ae Reviewed-by: Tor Arne Vestbø --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 95 ++++++++++++++++------ 1 file changed, 70 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 5d380c899b..fa3d4a7f23 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -1003,6 +1003,9 @@ class ImhTester : public QGraphicsItem void tst_QGraphicsItem::inputMethodHints() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + ImhTester *item = new ImhTester; item->setFlag(QGraphicsItem::ItemAcceptsInputMethod, true); item->setFlag(QGraphicsItem::ItemIsFocusable, true); @@ -1055,6 +1058,9 @@ void tst_QGraphicsItem::inputMethodHints() void tst_QGraphicsItem::toolTip() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + QString toolTip = "Qt rocks!"; QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(0, 0, 100, 100)); @@ -1764,7 +1770,9 @@ void tst_QGraphicsItem::selected_multi() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); view.fitInView(scene.sceneRect()); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(!item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -3267,7 +3275,8 @@ void tst_QGraphicsItem::hoverEventsGenerateRepaints() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events EventTester *tester = new EventTester; @@ -4994,6 +5003,9 @@ protected: void tst_QGraphicsItem::sceneEventFilter() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + QGraphicsScene scene; QGraphicsView view(&scene); @@ -6887,7 +6899,8 @@ void tst_QGraphicsItem::opacity2() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events QTRY_VERIFY(view.repaints >= 1); @@ -6962,7 +6975,8 @@ void tst_QGraphicsItem::opacityZeroUpdates() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events QTRY_VERIFY(view.repaints > 0); @@ -7297,6 +7311,9 @@ void tst_QGraphicsItem::tabChangesFocus_data() void tst_QGraphicsItem::tabChangesFocus() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + QFETCH(bool, tabChangesFocus); QGraphicsScene scene; @@ -8192,7 +8209,8 @@ void tst_QGraphicsItem::moveLineItem() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events view.reset(); @@ -8264,9 +8282,11 @@ void tst_QGraphicsItem::sorting() view.resize(120, 100); view.setFrameStyle(0); view.show(); - qApp->setActiveWindow(&view); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + qApp->setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(_paintedItems.count() > 0); _paintedItems.clear(); @@ -8302,9 +8322,11 @@ void tst_QGraphicsItem::itemHasNoContents() QGraphicsView view(&scene); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); - qApp->setActiveWindow(&view); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + qApp->setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(!_paintedItems.isEmpty()); _paintedItems.clear(); @@ -9326,10 +9348,12 @@ void tst_QGraphicsItem::ensureDirtySceneTransform() QGraphicsView view(&scene); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); - QApplication::setActiveWindow(&view); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + QApplication::setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + QCOMPARE(QApplication::activeWindow(), static_cast(&view)); + } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); - QCOMPARE(QApplication::activeWindow(), static_cast(&view)); //We move the parent parent->move(); @@ -9710,6 +9734,9 @@ void tst_QGraphicsItem::stackBefore() void tst_QGraphicsItem::QTBUG_4233_updateCachedWithSceneRect() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + EventTester *tester = new EventTester; tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); @@ -10782,6 +10809,9 @@ void tst_QGraphicsItem::scenePosChange() void tst_QGraphicsItem::textItem_shortcuts() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + QWidget w; w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); auto l = new QVBoxLayout(&w); @@ -10847,7 +10877,8 @@ void tst_QGraphicsItem::scroll() view.setFrameStyle(0); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(view.repaints > 0); view.reset(); @@ -11373,9 +11404,11 @@ void tst_QGraphicsItem::QTBUG_6738_missingUpdateWithSetParent() MyGraphicsView view(&scene); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); - qApp->setActiveWindow(&view); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + qApp->setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events QTRY_VERIFY(view.repaints > 0); @@ -11426,7 +11459,8 @@ void tst_QGraphicsItem::QT_2653_fullUpdateDiscardingOpacityUpdate() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events view.reset(); @@ -11461,7 +11495,9 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() scene.addItem(parentGreen); origView.show(); - QVERIFY(QTest::qWaitForWindowActive(&origView)); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QVERIFY(QTest::qWaitForWindowActive(&origView)); + QVERIFY(QTest::qWaitForWindowExposed(&origView)); QCoreApplication::processEvents(); // Process all queued paint events origView.setGeometry(origView.x() + origView.width() + 20, origView.y() + 20, @@ -11475,9 +11511,11 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() QTRY_VERIFY(origView.repaints > 0); view.show(); - qApp->setActiveWindow(&view); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + qApp->setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); view.reset(); origView.reset(); @@ -11591,6 +11629,9 @@ void tst_QGraphicsItem::sortItemsWhileAdding() void tst_QGraphicsItem::doNotMarkFullUpdateIfNotInScene() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); + struct Item : public QGraphicsTextItem { int painted = 0; @@ -11649,10 +11690,12 @@ void tst_QGraphicsItem::itemDiesDuringDraggingOperation() item->setAcceptDrops(true); scene.addItem(item); view.show(); - QApplication::setActiveWindow(&view); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + QApplication::setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + QCOMPARE(QApplication::activeWindow(), &view); + } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); - QCOMPARE(QApplication::activeWindow(), &view); QGraphicsSceneDragDropEvent dragEnter(QEvent::GraphicsSceneDragEnter); dragEnter.setScenePos(item->boundingRect().center()); QCoreApplication::sendEvent(&scene, &dragEnter); @@ -11678,10 +11721,12 @@ void tst_QGraphicsItem::QTBUG_12112_focusItem() scene.addItem(item1); view.show(); - QApplication::setActiveWindow(&view); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + QApplication::setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + QCOMPARE(QApplication::activeWindow(), &view); + } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QVERIFY(QTest::qWaitForWindowActive(&view)); - QCOMPARE(QApplication::activeWindow(), &view); QVERIFY(item1->focusItem()); QVERIFY(!item2->focusItem()); -- cgit v1.2.3 From ffac8995769f27fe0d68d5e0cd75716afd3d1167 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Fri, 11 Oct 2019 10:49:38 +0200 Subject: 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 --- .../itemviews/qheaderview/tst_qheaderview.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index df02815eb2..0b120985ee 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))); -- cgit v1.2.3 From 332c255c696bb15db7a0510dab2a6ac214ecdb19 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 11 Oct 2019 09:43:24 +0200 Subject: tst_qgraphicsitem: Skip tests that fail on Wayland Task-number: QTBUG-62188 Change-Id: If0638d51bffa6ef375476c0a601c387bd05583ae Reviewed-by: Paul Olav Tvete --- tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index fa3d4a7f23..864dd9f590 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -7361,6 +7361,9 @@ void tst_QGraphicsItem::tabChangesFocus() void tst_QGraphicsItem::cacheMode() { + if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) + QSKIP("Wayland: This fails. Figure out why."); + QGraphicsScene scene(0, 0, 100, 100); QGraphicsView view(&scene); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); @@ -7542,6 +7545,9 @@ void tst_QGraphicsItem::cacheMode() void tst_QGraphicsItem::cacheMode2() { + if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) + QSKIP("Wayland: This fails. Figure out why."); + QGraphicsScene scene(0, 0, 100, 100); QGraphicsView view(&scene); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); -- cgit v1.2.3 From 05a829f923a88e69b2ceaa372820a2dcb8c083cd Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 27 Sep 2019 13:36:38 +0200 Subject: 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 --- tests/auto/corelib/global/global.pro | 3 + .../corelib/global/qwinregistry/qwinregistry.pro | 8 +++ .../global/qwinregistry/tst_qwinregistry.cpp | 68 ++++++++++++++++++++++ tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 18 +++--- tests/auto/corelib/io/qsettings/tst_qsettings.cpp | 43 +++++--------- 5 files changed, 99 insertions(+), 41 deletions(-) create mode 100644 tests/auto/corelib/global/qwinregistry/qwinregistry.pro create mode 100644 tests/auto/corelib/global/qwinregistry/tst_qwinregistry.cpp (limited to 'tests') diff --git a/tests/auto/corelib/global/global.pro b/tests/auto/corelib/global/global.pro index 139e073644..0f77d191ee 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 0000000000..eab5df9dc3 --- /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 0000000000..ac811de2a1 --- /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 16fcafa248..0597a7d521 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 289590a233..0f07ba4bb2 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); } } -- cgit v1.2.3 From 9cc040a806fd2e6f1458e801a99311168d594c77 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Mon, 9 Sep 2019 16:11:48 +0200 Subject: 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ø --- tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp | 14 +++++++------- .../graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 2 +- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 12 +++++------- tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp | 4 ++-- tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp | 10 +++------- tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 5 ++--- tests/manual/dialogs/printdialogpanel.cpp | 3 +-- tests/manual/qcursor/qcursorhighdpi/main.cpp | 2 +- 8 files changed, 22 insertions(+), 30 deletions(-) (limited to 'tests') diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp index 13dc924f93..54bb8fe0bd 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 0b08586f7d..af0dd9b0f0 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 3e372b76f5..40377eb946 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 5a51f15008..27ae41fc4f 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 4e16edaca8..b7869a0653 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 d6ba85d61f..417d6e3124 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 8d64d2f6a6..b7447e3d64 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 017f41eccd..e70be333fd 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 } -- cgit v1.2.3 From 80ddac3a0a9984e1dc4da6440912cfcfd210a380 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Fri, 11 Oct 2019 10:01:00 +0200 Subject: tst_qgraphicseffect: Wait for exposed instead of active MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makes the test pass on Wayland. Task-number: QTBUG-62188 Change-Id: I3900925e74d8d940a8c5af87ea64a6ec3c8c3293 Reviewed-by: Tor Arne Vestbø --- .../widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp index c4b6e22c37..19288d07a7 100644 --- a/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp +++ b/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp @@ -311,7 +311,7 @@ void tst_QGraphicsEffect::draw() QGraphicsView view(&scene); view.show(); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_VERIFY(item->numRepaints > 0); QCoreApplication::processEvents(); // Process all queued paint events item->reset(); @@ -668,8 +668,7 @@ void tst_QGraphicsEffect::childrenVisibilityShouldInvalidateCache() scene.addItem(&parent); QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_VERIFY(parent.nbPaint >= 1); //we set an effect on the parent parent.setGraphicsEffect(new QGraphicsDropShadowEffect(&parent)); @@ -694,8 +693,7 @@ void tst_QGraphicsEffect::prepareGeometryChangeInvalidateCache() QGraphicsView view(&scene); view.show(); - qApp->setActiveWindow(&view); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_VERIFY(item->nbPaint >= 1); item->nbPaint = 0; @@ -726,8 +724,7 @@ void tst_QGraphicsEffect::itemHasNoContents() QGraphicsView view(&scene); view.show(); - qApp->setActiveWindow(&view); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_VERIFY(child->nbPaint >= 1); CustomEffect *effect = new CustomEffect; -- cgit v1.2.3 From 8814c5778d7b9ccc64956abed6af9737c4a35d39 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Thu, 7 Jun 2018 13:44:15 +0200 Subject: 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/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp b/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp index a17a9f6c33..01ecfb2ca9 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); -- cgit v1.2.3 From 821c2eb1310e72a1123eac69ef2aab8fc52dd0aa Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Thu, 10 Oct 2019 16:20:01 +0200 Subject: 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(-) (limited to 'tests') diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp index 40eff1e4c3..52354eda42 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(); -- cgit v1.2.3 From c222a9283d94ad1e29334bb2fba0beef7cc716c7 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Tue, 18 Jun 2019 00:07:54 +0200 Subject: 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 --- .../qabstractitemmodel/tst_qabstractitemmodel.cpp | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp index f305edb2c5..9fab36deaa 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; -- cgit v1.2.3