diff options
Diffstat (limited to 'tests/auto/widgets')
64 files changed, 2561 insertions, 854 deletions
diff --git a/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp b/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp index 6a0ad4b3a4..413b865f04 100644 --- a/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp +++ b/tests/auto/widgets/dialogs/qcolordialog/tst_qcolordialog.cpp @@ -116,10 +116,10 @@ void tst_QColorDialog::testGetRgba() #ifdef Q_OS_MAC QEXPECT_FAIL("", "Sending QTest::keyClick to OSX color dialog helper fails, see QTBUG-24320", Continue); #endif - bool ok = false; - QTimer::singleShot(500, this, SLOT(postKeyReturn())); - QColorDialog::getRgba(0xffffffff, &ok); - QVERIFY(ok); + QTimer::singleShot(500, this, &tst_QColorDialog::postKeyReturn); + const QColor color = QColorDialog::getColor(QColor::fromRgba(0xffffffff), nullptr, QString(), + QColorDialog::ShowAlphaChannel); + QVERIFY(color.isValid()); } void tst_QColorDialog::defaultOkButton() diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp index ae8e4f7e04..f7482bae45 100644 --- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp @@ -620,13 +620,13 @@ void tst_QFiledialog::acceptMode() void tst_QFiledialog::confirmOverwrite() { QFileDialog fd; - QCOMPARE(fd.confirmOverwrite(), true); - fd.setConfirmOverwrite(true); - QCOMPARE(fd.confirmOverwrite(), true); - fd.setConfirmOverwrite(false); - QCOMPARE(fd.confirmOverwrite(), false); - fd.setConfirmOverwrite(true); - QCOMPARE(fd.confirmOverwrite(), true); + QCOMPARE(fd.testOption(QFileDialog::DontConfirmOverwrite), false); + fd.setOption(QFileDialog::DontConfirmOverwrite, false); + QCOMPARE(fd.testOption(QFileDialog::DontConfirmOverwrite), false); + fd.setOption(QFileDialog::DontConfirmOverwrite, true); + QCOMPARE(fd.testOption(QFileDialog::DontConfirmOverwrite), true); + fd.setOption(QFileDialog::DontConfirmOverwrite, false); + QCOMPARE(fd.testOption(QFileDialog::DontConfirmOverwrite), false); } void tst_QFiledialog::defaultSuffix() @@ -808,8 +808,8 @@ void tst_QFiledialog::isReadOnly() //QCOMPARE(renameAction && renameAction->isEnabled(), true); //QCOMPARE(deleteAction && deleteAction->isEnabled(), true); - fd.setReadOnly(true); - QCOMPARE(fd.isReadOnly(), true); + fd.setOption(QFileDialog::ReadOnly, true); + QCOMPARE(fd.testOption(QFileDialog::ReadOnly), true); QCOMPARE(newButton && newButton->isEnabled(), false); QCOMPARE(renameAction && renameAction->isEnabled(), false); @@ -853,11 +853,11 @@ void tst_QFiledialog::resolveSymlinks() QFileDialog fd; // default - QCOMPARE(fd.resolveSymlinks(), true); - fd.setResolveSymlinks(false); - QCOMPARE(fd.resolveSymlinks(), false); - fd.setResolveSymlinks(true); - QCOMPARE(fd.resolveSymlinks(), true); + QCOMPARE(fd.testOption(QFileDialog::DontResolveSymlinks), false); + fd.setOption(QFileDialog::DontResolveSymlinks, true); + QCOMPARE(fd.testOption(QFileDialog::DontResolveSymlinks), true); + fd.setOption(QFileDialog::DontResolveSymlinks, false); + QCOMPARE(fd.testOption(QFileDialog::DontResolveSymlinks), false); // the file dialog doesn't do anything based upon this, just passes it to the model // the model should fully test it, don't test it here @@ -1119,7 +1119,7 @@ void tst_QFiledialog::setNameFilter() QFileDialog fd; fd.setNameFilters(filters); - fd.setNameFilterDetailsVisible(nameFilterDetailsVisible); + fd.setOption(QFileDialog::HideNameFilterDetails, !nameFilterDetailsVisible); fd.selectNameFilter(selectFilter); QCOMPARE(fd.selectedNameFilter(), expectedSelectedFilter); } @@ -1421,6 +1421,16 @@ void tst_QFiledialog::clearLineEdit() QTRY_VERIFY(fd.directory().absolutePath() != workDirPath); QVERIFY(lineEdit->text().isEmpty()); + + // QTBUG-71415: When pressing back, the selection (activated + // directory) should be restored. + QToolButton *backButton = fd.findChild<QToolButton*>("backButton"); + QVERIFY(backButton); + QTreeView *treeView = fd.findChildren<QTreeView*>("treeView").value(0); + QVERIFY(treeView); + backButton->click(); + QTRY_COMPARE(treeView->selectionModel()->selectedIndexes().value(0).data().toString(), + dirName); } void tst_QFiledialog::enableChooseButton() diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp index 8f9a8c11a7..869418371c 100644 --- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp @@ -252,7 +252,7 @@ void tst_QFileDialog2::showNameFilterDetails() QFileDialog fd; QComboBox *filters = fd.findChild<QComboBox*>("fileTypeCombo"); QVERIFY(filters); - QVERIFY(fd.isNameFilterDetailsVisible()); + QVERIFY(!fd.testOption(QFileDialog::HideNameFilterDetails)); QStringList filterChoices; @@ -261,12 +261,12 @@ void tst_QFileDialog2::showNameFilterDetails() << "Any files (*.*)"; fd.setNameFilters(filterChoices); - fd.setNameFilterDetailsVisible(false); + fd.setOption(QFileDialog::HideNameFilterDetails, true); QCOMPARE(filters->itemText(0), QString("Image files")); QCOMPARE(filters->itemText(1), QString("Text files")); QCOMPARE(filters->itemText(2), QString("Any files")); - fd.setNameFilterDetailsVisible(true); + fd.setOption(QFileDialog::HideNameFilterDetails, false); QCOMPARE(filters->itemText(0), filterChoices.at(0)); QCOMPARE(filters->itemText(1), filterChoices.at(1)); QCOMPARE(filters->itemText(2), filterChoices.at(2)); @@ -486,7 +486,7 @@ protected: parentIndex = source_parent; QString path; - path = parentIndex.child(source_row,0).data(Qt::DisplayRole).toString(); + path = sourceModel()->index(source_row, 0, parentIndex).data(Qt::DisplayRole).toString(); do { path = parentIndex.data(Qt::DisplayRole).toString() + QLatin1Char('/') + path; @@ -601,6 +601,11 @@ void tst_QFileDialog2::task227930_correctNavigationKeyboardBehavior() fd.setDirectory(current.absolutePath()); fd.show(); QVERIFY(QTest::qWaitForWindowActive(&fd)); + + // Ensure LayoutRequest event is processed so that the list view + // is sorted correctly to have the directory entires at the top. + QCoreApplication::processEvents(); + QListView *list = fd.findChild<QListView*>("listView"); QVERIFY(list); QTest::keyClick(list, Qt::Key_Down); diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST b/tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST new file mode 100644 index 0000000000..01679eb6ee --- /dev/null +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST @@ -0,0 +1,11 @@ +winrt +[sort:QFileDialog usage] +ubuntu +b2qt +[specialFiles] +ubuntu +b2qt +[dirsBeforeFiles] +ubuntu +b2qt +windows diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/CMakeLists.txt b/tests/auto/widgets/dialogs/qfilesystemmodel/CMakeLists.txt index bf615c6805..336ce4ca15 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/CMakeLists.txt +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/CMakeLists.txt @@ -1,5 +1,31 @@ -add_qt_test("tst_qfilesystemmodel" SOURCES tst_qfilesystemmodel.cpp +# Generated from qfilesystemmodel.pro. + +##################################################################### +## tst_qfilesystemmodel Test: +##################################################################### + +add_qt_test(tst_qfilesystemmodel + SOURCES + ../../../../shared/emulationdetector.h + tst_qfilesystemmodel.cpp + INCLUDE_DIRECTORIES + ../../../../shared LIBRARIES - Qt::WidgetsPrivate Qt::CorePrivate + Qt::WidgetsPrivate + PUBLIC_LIBRARIES + Qt::Core + Qt::Widgets ) + +#### Keys ignored in scope 1:.:.:qfilesystemmodel.pro:<TRUE>: +# CONFIG = "testcase" + +## Scopes: +##################################################################### + +#### Keys ignored in scope 2:.:.:qfilesystemmodel.pro:WIN32: +# testcase.timeout = "900" + +#### Keys ignored in scope 3:.:.:qfilesystemmodel.pro:APPLE_OSX: +# testcase.timeout = "900" diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro b/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro index bc4671f60c..db8cf7de3f 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro @@ -1,3 +1,6 @@ +INCLUDEPATH += ../../../../shared +HEADERS += ../../../../shared/emulationdetector.h + CONFIG += testcase # This testcase can be slow on Windows and OS X, and may interfere with other file system tests. win32:testcase.timeout = 900 @@ -8,5 +11,3 @@ QT += core-private testlib SOURCES += tst_qfilesystemmodel.cpp TARGET = tst_qfilesystemmodel - -CONFIG += insignificant_test # QTBUG-29403 diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index d8a680881a..665a116a3a 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ +#include <emulationdetector.h> #include <QtTest/QtTest> #ifdef QT_BUILD_INTERNAL #include <private/qfilesystemmodel_p.h> @@ -51,10 +52,15 @@ // Will try to wait for the condition while allowing event processing // for a maximum of 5 seconds. -#define TRY_WAIT(expr) \ +#define TRY_WAIT(expr, timedOut) \ do { \ + *timedOut = true; \ const int step = 50; \ - for (int __i = 0; __i < 5000 && !(expr); __i+=step) { \ + for (int __i = 0; __i < 5000; __i += step) { \ + if (expr) { \ + *timedOut = false; \ + break; \ + } \ QTest::qWait(step); \ } \ } while(0) @@ -123,6 +129,8 @@ private slots: protected: bool createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &intial_dirs = QStringList()); + QModelIndex prepareTestModelRoot(const QString &test_path, QSignalSpy **spy2 = nullptr, + QSignalSpy **spy3 = nullptr); private: QFileSystemModel *model; @@ -306,7 +314,11 @@ void tst_QFileSystemModel::iconProvider() bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount, const QStringList &initial_dirs) { //qDebug() << (model->rowCount(model->index(test_path))) << existingFileCount << initial_files; - TRY_WAIT((model->rowCount(model->index(test_path)) == existingFileCount)); + bool timedOut = false; + TRY_WAIT((model->rowCount(model->index(test_path)) == existingFileCount), &timedOut); + if (timedOut) + return false; + for (int i = 0; i < initial_dirs.count(); ++i) { QDir dir(test_path); if (!dir.exists()) { @@ -363,23 +375,45 @@ bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringLi return true; } -void tst_QFileSystemModel::rowCount() +QModelIndex tst_QFileSystemModel::prepareTestModelRoot(const QString &test_path, QSignalSpy **spy2, + QSignalSpy **spy3) { - QString tmp = flatDirTestPath; - QVERIFY(createFiles(tmp, QStringList())); + if (model->rowCount(model->index(test_path)) != 0) + return QModelIndex(); - QSignalSpy spy2(model, SIGNAL(rowsInserted(QModelIndex,int,int))); - QSignalSpy spy3(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int))); + if (spy2) + *spy2 = new QSignalSpy(model, &QFileSystemModel::rowsInserted); + if (spy3) + *spy3 = new QSignalSpy(model, &QFileSystemModel::rowsAboutToBeInserted); - QStringList files = QStringList() << "b" << "d" << "f" << "h" << "j" << ".a" << ".c" << ".e" << ".g"; + QStringList files = { "b", "d", "f", "h", "j", ".a", ".c", ".e", ".g" }; QString l = "b,d,f,h,j,.a,.c,.e,.g"; - QVERIFY(createFiles(tmp, files)); + if (!createFiles(test_path, files)) + return QModelIndex(); - QModelIndex root = model->setRootPath(tmp); - QTRY_COMPARE(model->rowCount(root), 5); - QVERIFY(spy2.count() > 0); - QVERIFY(spy3.count() > 0); + QModelIndex root = model->setRootPath(test_path); + if (!root.isValid()) + return QModelIndex(); + + bool timedOut = false; + TRY_WAIT(model->rowCount(root) == 5, &timedOut); + if (timedOut) + return QModelIndex(); + + return root; +} + +void tst_QFileSystemModel::rowCount() +{ + const QString tmp = flatDirTestPath; + QSignalSpy *spy2 = nullptr; + QSignalSpy *spy3 = nullptr; + QModelIndex root = prepareTestModelRoot(flatDirTestPath, &spy2, &spy3); + QVERIFY(root.isValid()); + + QVERIFY(spy2 && spy2->count() > 0); + QVERIFY(spy3 && spy3->count() > 0); } void tst_QFileSystemModel::rowsInserted_data() @@ -401,9 +435,9 @@ static inline QString lastEntry(const QModelIndex &root) void tst_QFileSystemModel::rowsInserted() { - QString tmp = flatDirTestPath; - rowCount(); - QModelIndex root = model->index(model->rootPath()); + const QString tmp = flatDirTestPath; + QModelIndex root = prepareTestModelRoot(tmp); + QVERIFY(root.isValid()); QFETCH(int, ascending); QFETCH(int, count); @@ -454,9 +488,9 @@ void tst_QFileSystemModel::rowsRemoved_data() void tst_QFileSystemModel::rowsRemoved() { - QString tmp = flatDirTestPath; - rowCount(); - QModelIndex root = model->index(model->rootPath()); + const QString tmp = flatDirTestPath; + QModelIndex root = prepareTestModelRoot(tmp); + QVERIFY(root.isValid()); QFETCH(int, count); QFETCH(int, ascending); @@ -509,9 +543,9 @@ void tst_QFileSystemModel::dataChanged() { QSKIP("This can't be tested right now since we don't watch files, only directories."); - QString tmp = flatDirTestPath; - rowCount(); - QModelIndex root = model->index(model->rootPath()); + const QString tmp = flatDirTestPath; + QModelIndex root = prepareTestModelRoot(tmp); + QVERIFY(root.isValid()); QFETCH(int, count); QFETCH(int, assending); @@ -755,6 +789,9 @@ void tst_QFileSystemModel::sort() MyFriendFileSystemModel *myModel = new MyFriendFileSystemModel(); QTreeView *tree = new QTreeView(); + if (fileDialogMode && EmulationDetector::isRunningArmOnX86()) + QSKIP("Crashes in QEMU. QTBUG-70572"); + #ifdef QT_BUILD_INTERNAL if (fileDialogMode) myModel->d_func()->disableRecursiveSort = true; diff --git a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp index 049468fd7c..76314564f1 100644 --- a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp +++ b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp @@ -38,49 +38,6 @@ #include <qpa/qplatformtheme.h> #include <private/qguiapplication_p.h> -#define CONVENIENCE_FUNC_SYMS(func) \ - { \ - int x1 = QMessageBox::func(0, "Foo", "Bar"); \ - int x3 = QMessageBox::func(0, "Foo", "Bar", "Save"); \ - int x6 = QMessageBox::func(0, "Foo", "Bar", "Save", "Save As"); \ - int x7 = QMessageBox::func(0, "Foo", "Bar", "Save", "Save As", "Dont Save"); \ - int x8 = QMessageBox::func(0, "Foo", "Bar", "Save", "Save As", "Dont Save", 1); \ - int x9 = QMessageBox::func(0, "Foo", "Bar", "Save", "Save As", "Dont Save", 1, 2); \ - int x10 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::YesAll, QMessageBox::Yes); \ - int x11 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::YesAll, QMessageBox::Yes, \ - QMessageBox::No); \ - qDebug("%d %d %d %d %d %d %d %d", x1, x3, x6, x7, x8, x9, x10, x11); \ - { \ - int x4 = QMessageBox::func(0, "Foo", "Bar", (int)QMessageBox::Yes, (int)QMessageBox::No); \ - int x5 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes, (int)QMessageBox::No); \ - int x6 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes | QMessageBox::Default, (int)QMessageBox::No); \ - int x7 = QMessageBox::func(0, "Foo", "Bar", (int)QMessageBox::Yes, QMessageBox::No); \ - int x8 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes, QMessageBox::No); \ - int x9 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No); \ - int x10 = QMessageBox::func(0, "Foo", "Bar", (int)QMessageBox::Yes, (int)QMessageBox::No, (int)QMessageBox::Ok); \ - int x11 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes, (int)QMessageBox::No, (int)QMessageBox::Ok); \ - int x12 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes | QMessageBox::Default, (int)QMessageBox::No, (int)QMessageBox::Ok); \ - int x13 = QMessageBox::func(0, "Foo", "Bar", (int)QMessageBox::Yes, QMessageBox::No, (int)QMessageBox::Ok); \ - int x14 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes, QMessageBox::No, (int)QMessageBox::Ok); \ - int x15 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, (int)QMessageBox::Ok); \ - int x16 = QMessageBox::func(0, "Foo", "Bar", (int)QMessageBox::Yes, (int)QMessageBox::No, QMessageBox::Ok); \ - int x17 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes, (int)QMessageBox::No, QMessageBox::Ok); \ - int x18 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes | QMessageBox::Default, (int)QMessageBox::No, QMessageBox::Ok); \ - int x19 = QMessageBox::func(0, "Foo", "Bar", (int)QMessageBox::Yes, QMessageBox::No, QMessageBox::Ok); \ - int x20 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes, QMessageBox::No, QMessageBox::Ok); \ - int x21 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Ok); \ - qDebug("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21); \ - } \ - } - -#define CONVENIENCE_FUNC_SYMS_EXTRA(func) \ - { \ - int x1 = QMessageBox::func(0, "Foo", "Bar", (int)QMessageBox::Yes); \ - int x2 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes); \ - int x3 = QMessageBox::func(0, "Foo", "Bar", QMessageBox::Yes | QMessageBox::Default); \ - qDebug("%d %d %d", x1, x2, x3); \ - } - class tst_QMessageBox : public QObject { Q_OBJECT @@ -103,13 +60,16 @@ private slots: void staticSourceCompat(); void instanceSourceCompat(); - void testSymbols(); void incorrectDefaultButton(); void updateSize(); void setInformativeText(); void iconPixmap(); + // QTBUG-44131 + void acceptedRejectedSignals(); + void acceptedRejectedSignals_data(); + void cleanup(); }; @@ -210,9 +170,9 @@ void tst_QMessageBox::button() { QMessageBox msgBox; msgBox.addButton("retry", QMessageBox::DestructiveRole); - QVERIFY(msgBox.button(QMessageBox::Ok) == 0); // not added yet + QVERIFY(msgBox.button(QMessageBox::Ok) == nullptr); // not added yet QPushButton *b1 = msgBox.addButton(QMessageBox::Ok); - QCOMPARE(msgBox.button(QMessageBox::Ok), (QAbstractButton *)b1); // just added + QCOMPARE(msgBox.button(QMessageBox::Ok), static_cast<QAbstractButton *>(b1)); // just added QCOMPARE(msgBox.standardButton(b1), QMessageBox::Ok); msgBox.addButton(QMessageBox::Cancel); QCOMPARE(msgBox.standardButtons(), QMessageBox::Ok | QMessageBox::Cancel); @@ -220,12 +180,12 @@ void tst_QMessageBox::button() // remove the cancel, should not exist anymore msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); QVERIFY(!msgBox.button(QMessageBox::Cancel)); - QVERIFY(msgBox.button(QMessageBox::Yes) != 0); + QVERIFY(msgBox.button(QMessageBox::Yes) != nullptr); // should not crash QPushButton *b4 = new QPushButton; msgBox.addButton(b4, QMessageBox::DestructiveRole); - msgBox.addButton(0, QMessageBox::ActionRole); + msgBox.addButton(nullptr, QMessageBox::ActionRole); } void tst_QMessageBox::defaultButton() @@ -237,7 +197,7 @@ void tst_QMessageBox::defaultButton() QVERIFY(!msgBox.defaultButton()); QPushButton pushButton; msgBox.setDefaultButton(&pushButton); - QVERIFY(msgBox.defaultButton() == 0); // we have not added it yet + QVERIFY(msgBox.defaultButton() == nullptr); // we have not added it yet QPushButton *retryButton = msgBox.addButton(QMessageBox::Retry); msgBox.setDefaultButton(retryButton); QCOMPARE(msgBox.defaultButton(), retryButton); @@ -248,11 +208,11 @@ void tst_QMessageBox::defaultButton() closeHelper.start(Qt::Key_Enter, &msgBox); msgBox.exec(); - QCOMPARE(msgBox.clickedButton(), (QAbstractButton *)retryButton); + QCOMPARE(msgBox.clickedButton(), static_cast<QAbstractButton *>(retryButton)); QAbstractButton *okButton = msgBox.button(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok); - QCOMPARE(msgBox.defaultButton(), (QPushButton *)okButton); + QCOMPARE(msgBox.defaultButton(), static_cast<QPushButton *>(okButton)); closeHelper.start(Qt::Key_Enter, &msgBox); msgBox.exec(); QCOMPARE(msgBox.clickedButton(), okButton); @@ -260,7 +220,7 @@ void tst_QMessageBox::defaultButton() QCOMPARE(msgBox.defaultButton(), okButton); msgBox.removeButton(okButton); delete okButton; - okButton = 0; + okButton = nullptr; QVERIFY(!msgBox.defaultButton()); msgBox.setDefaultButton(QMessageBox::Ok); QVERIFY(!msgBox.defaultButton()); @@ -287,7 +247,7 @@ void tst_QMessageBox::escapeButton() QVERIFY(msgBox.clickedButton() == msgBox.button(QMessageBox::Cancel)); // auto detected (cancel) msgBox.setEscapeButton(retryButton); - QCOMPARE(msgBox.escapeButton(), (QAbstractButton *)retryButton); + QCOMPARE(msgBox.escapeButton(), static_cast<QAbstractButton *>(retryButton)); // with escape closeHelper.start(Qt::Key_Escape, &msgBox); @@ -297,7 +257,7 @@ void tst_QMessageBox::escapeButton() // with close closeHelper.start(ExecCloseHelper::CloseWindow, &msgBox); msgBox.exec(); - QCOMPARE(msgBox.clickedButton(), (QAbstractButton *)retryButton); + QCOMPARE(msgBox.clickedButton(), static_cast<QAbstractButton *>(retryButton)); QAbstractButton *okButton = msgBox.button(QMessageBox::Ok); msgBox.setEscapeButton(QMessageBox::Ok); @@ -309,7 +269,7 @@ void tst_QMessageBox::escapeButton() QCOMPARE(msgBox.escapeButton(), okButton); msgBox.removeButton(okButton); delete okButton; - okButton = 0; + okButton = nullptr; QVERIFY(!msgBox.escapeButton()); msgBox.setEscapeButton(QMessageBox::Ok); QVERIFY(!msgBox.escapeButton()); @@ -353,28 +313,28 @@ void tst_QMessageBox::statics() ExecCloseHelper closeHelper; for (int i = 0; i < 4; i++) { closeHelper.start(Qt::Key_Escape); - QMessageBox::StandardButton sb = (*statics[i])(0, "caption", + QMessageBox::StandardButton sb = (*statics[i])(nullptr, "caption", "text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help | QMessageBox::Cancel, QMessageBox::NoButton); QCOMPARE(sb, QMessageBox::Cancel); QVERIFY(closeHelper.done()); closeHelper.start(ExecCloseHelper::CloseWindow); - sb = (*statics[i])(0, "caption", + sb = (*statics[i])(nullptr, "caption", "text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help | QMessageBox::Cancel, QMessageBox::NoButton); QCOMPARE(sb, QMessageBox::Cancel); QVERIFY(closeHelper.done()); closeHelper.start(Qt::Key_Enter); - sb = (*statics[i])(0, "caption", + sb = (*statics[i])(nullptr, "caption", "text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help, QMessageBox::Yes); QCOMPARE(sb, QMessageBox::Yes); QVERIFY(closeHelper.done()); closeHelper.start(Qt::Key_Enter); - sb = (*statics[i])(0, "caption", + sb = (*statics[i])(nullptr, "caption", "text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help, QMessageBox::No); QCOMPARE(sb, QMessageBox::No); @@ -400,7 +360,7 @@ void tst_QMessageBox::about() { ExecCloseHelper closeHelper; closeHelper.start(Qt::Key_Escape); - QMessageBox::about(0, "Caption", "This is an auto test"); + QMessageBox::about(nullptr, "Caption", "This is an auto test"); // On Mac, about and aboutQt are not modal, so we need to // explicitly run the event loop #ifdef Q_OS_MAC @@ -412,7 +372,7 @@ void tst_QMessageBox::about() const int keyToSend = Qt::Key_Enter; closeHelper.start(keyToSend); - QMessageBox::aboutQt(0, "Caption"); + QMessageBox::aboutQt(nullptr, "Caption"); #ifdef Q_OS_MAC QTRY_VERIFY(closeHelper.done()); #else @@ -427,7 +387,7 @@ void tst_QMessageBox::staticSourceCompat() // source compat tests for < 4.2 ExecCloseHelper closeHelper; closeHelper.start(Qt::Key_Enter); - ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes, QMessageBox::No); + ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes, QMessageBox::No); int expectedButton = int(QMessageBox::Yes); if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { const int dialogButtonBoxLayout = theme->themeHint(QPlatformTheme::DialogButtonBoxLayout).toInt(); @@ -439,39 +399,39 @@ void tst_QMessageBox::staticSourceCompat() QVERIFY(closeHelper.done()); closeHelper.start(Qt::Key_Enter); - ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No); + ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No); QCOMPARE(ret, int(QMessageBox::Yes)); QVERIFY(closeHelper.done()); closeHelper.start(Qt::Key_Enter); - ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes, QMessageBox::No | QMessageBox::Default); + ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes, QMessageBox::No | QMessageBox::Default); QCOMPARE(ret, int(QMessageBox::No)); QVERIFY(closeHelper.done()); closeHelper.start(Qt::Key_Enter); - ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape); + ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape); QCOMPARE(ret, int(QMessageBox::Yes)); QVERIFY(closeHelper.done()); closeHelper.start(Qt::Key_Enter); - ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes | QMessageBox::Escape, QMessageBox::No | QMessageBox::Default); + ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Escape, QMessageBox::No | QMessageBox::Default); QCOMPARE(ret, int(QMessageBox::No)); QVERIFY(closeHelper.done()); // the button text versions closeHelper.start(Qt::Key_Enter); - ret = QMessageBox::information(0, "title", "text", "Yes", "No", QString(), 1); + ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 1); QCOMPARE(ret, 1); QVERIFY(closeHelper.done()); if (0) { // don't run these tests since the dialog won't close! closeHelper.start(Qt::Key_Escape); - ret = QMessageBox::information(0, "title", "text", "Yes", "No", QString(), 1); + ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 1); QCOMPARE(ret, -1); QVERIFY(closeHelper.done()); closeHelper.start(Qt::Key_Escape); - ret = QMessageBox::information(0, "title", "text", "Yes", "No", QString(), 0, 1); + ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 0, 1); QCOMPARE(ret, 1); QVERIFY(closeHelper.done()); } @@ -505,96 +465,6 @@ void tst_QMessageBox::instanceSourceCompat() #endif } -void tst_QMessageBox::testSymbols() -{ - return; - - QMessageBox::Icon icon; - icon = QMessageBox::NoIcon; - icon = QMessageBox::Information; - icon = QMessageBox::Warning; - icon = QMessageBox::Critical; - icon = QMessageBox::Question; - - QMessageBox mb1; - QMessageBox mb2(0); - QMessageBox mb3(&mb1); - QMessageBox mb3b("title", "text", QMessageBox::Critical, int(QMessageBox::Yes), - int(QMessageBox::No), int(QMessageBox::Cancel), &mb1, Qt::Dialog); - - QMessageBox::Button button = QMessageBox::NoButton; - button = QMessageBox::Ok; - button = QMessageBox::Cancel; - button = QMessageBox::Yes; - button = QMessageBox::No; - button = QMessageBox::Abort; - button = QMessageBox::Retry; - button = QMessageBox::Ignore; - button = QMessageBox::YesAll; - button = QMessageBox::NoAll; - button = QMessageBox::ButtonMask; - button = QMessageBox::Default; - button = QMessageBox::Escape; - button = QMessageBox::FlagMask; - QVERIFY(button); - - const QString text = QStringLiteral("Foo"); - mb1.setText(text); - QCOMPARE(mb1.text(), text); - - icon = mb1.icon(); - QCOMPARE(icon, QMessageBox::NoIcon); - mb1.setIcon(QMessageBox::Question); - QCOMPARE(mb1.icon(), QMessageBox::Question); - - QPixmap iconPixmap = mb1.iconPixmap(); - mb1.setIconPixmap(iconPixmap); - QCOMPARE(mb1.icon(), QMessageBox::NoIcon); - - QCOMPARE(mb1.buttonText(QMessageBox::Ok), QLatin1String("OK")); - QCOMPARE(mb1.buttonText(QMessageBox::Cancel), QString()); - QCOMPARE(mb1.buttonText(QMessageBox::Ok | QMessageBox::Default), QString()); - - const QString button1 = QStringLiteral("Bar"); - mb2.setButtonText(QMessageBox::Cancel, QStringLiteral("Foo")); - mb2.setButtonText(QMessageBox::Ok, button1); - mb2.setButtonText(QMessageBox::Ok | QMessageBox::Default, QStringLiteral("Baz")); - - QCOMPARE(mb2.buttonText(QMessageBox::Cancel), QString()); - QCOMPARE(mb2.buttonText(QMessageBox::Ok), button1); - - QVERIFY(mb3b.buttonText(QMessageBox::Yes).endsWith("Yes")); - QCOMPARE(mb3b.buttonText(QMessageBox::YesAll), QString()); - QCOMPARE(mb3b.buttonText(QMessageBox::Ok), QString()); - - const QString button2 = QStringLiteral("Blah"); - mb3b.setButtonText(QMessageBox::Yes, button2); - mb3b.setButtonText(QMessageBox::YesAll, QStringLiteral("Zoo")); - mb3b.setButtonText(QMessageBox::Ok, QStringLiteral("Zoo")); - - QCOMPARE(mb3b.buttonText(QMessageBox::Yes), button2); - QCOMPARE(mb3b.buttonText(QMessageBox::YesAll), QString()); - QCOMPARE(mb3b.buttonText(QMessageBox::Ok), QString()); - - QCOMPARE(mb1.textFormat(), Qt::AutoText); - mb1.setTextFormat(Qt::PlainText); - QCOMPARE(mb1.textFormat(), Qt::PlainText); - - CONVENIENCE_FUNC_SYMS(information); - CONVENIENCE_FUNC_SYMS_EXTRA(information); - CONVENIENCE_FUNC_SYMS(question); - CONVENIENCE_FUNC_SYMS_EXTRA(question); - CONVENIENCE_FUNC_SYMS(warning); - CONVENIENCE_FUNC_SYMS(critical); - - QSize sizeHint = mb1.sizeHint(); - QVERIFY(sizeHint.width() > 20 && sizeHint.height() > 20); - - QMessageBox::about(&mb1, "title", "text"); - QMessageBox::aboutQt(&mb1); - QMessageBox::aboutQt(&mb1, "title"); -} - void tst_QMessageBox::detailsText() { QMessageBox box; @@ -618,9 +488,8 @@ void tst_QMessageBox::detailsButtonText() QDialogButtonBox* bb = box.findChild<QDialogButtonBox*>("qt_msgbox_buttonbox"); QVERIFY(bb); //get the detail button - QList<QAbstractButton *> list = bb->buttons(); - QAbstractButton* btn = NULL; - foreach(btn, list) { + auto list = bb->buttons(); + for (auto btn : list) { if (btn && (btn->inherits("QPushButton"))) { if (btn->text().remove(QLatin1Char('&')) != QMessageBox::tr("OK") && btn->text() != QMessageBox::tr("Show Details...")) { @@ -640,12 +509,12 @@ void tst_QMessageBox::expandDetails_QTBUG_32473() QDialogButtonBox* bb = box.findChild<QDialogButtonBox*>("qt_msgbox_buttonbox"); QVERIFY(bb); - QList<QAbstractButton *> list = bb->buttons(); - QAbstractButton* moreButton = NULL; - foreach (QAbstractButton* btn, list) - if (btn && bb->buttonRole(btn) == QDialogButtonBox::ActionRole) - moreButton = btn; - QVERIFY(moreButton); + auto list = bb->buttons(); + auto it = std::find_if(list.rbegin(), list.rend(), [&](QAbstractButton *btn) { + return btn && bb->buttonRole(btn) == QDialogButtonBox::ActionRole; }); + QVERIFY(it != list.rend()); + auto moreButton = *it; + QVERIFY(QTest::qWaitForWindowExposed(&box)); QRect geom = box.geometry(); box.resized = false; @@ -667,19 +536,19 @@ void tst_QMessageBox::incorrectDefaultButton() closeHelper.start(Qt::Key_Escape); //Do not crash here QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); - QMessageBox::question( 0, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save ); + QMessageBox::question(nullptr, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save); QVERIFY(closeHelper.done()); closeHelper.start(Qt::Key_Escape); QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); - QMessageBox::question( 0, "", "I've been hit!",QFlag(QMessageBox::Ok | QMessageBox::Cancel),QMessageBox::Save ); + QMessageBox::question(nullptr, "", "I've been hit!",QFlag(QMessageBox::Ok | QMessageBox::Cancel),QMessageBox::Save); QVERIFY(closeHelper.done()); closeHelper.start(Qt::Key_Escape); QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); //do not crash here -> call old function of QMessageBox in this case - QMessageBox::question( 0, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save | QMessageBox::Cancel,QMessageBox::Ok); + QMessageBox::question(nullptr, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save | QMessageBox::Cancel,QMessageBox::Ok); QVERIFY(closeHelper.done()); } @@ -718,5 +587,96 @@ void tst_QMessageBox::iconPixmap() QCOMPARE(messageBox.iconPixmap(), QPixmap()); } +using SignalSignature = void(QDialog::*)(); +Q_DECLARE_METATYPE(SignalSignature); +Q_DECLARE_METATYPE(QMessageBox::ButtonRole) + +using ButtonsCreator = std::function<QVector<QPushButton*>(QMessageBox &)>; +Q_DECLARE_METATYPE(ButtonsCreator); + +using RoleSet = QSet<QMessageBox::ButtonRole>; +Q_DECLARE_METATYPE(RoleSet); + +void tst_QMessageBox::acceptedRejectedSignals() +{ + QMessageBox messageBox(QMessageBox::Information, "Test window", "Test text"); + + QFETCH(ButtonsCreator, buttonsCreator); + QVERIFY(buttonsCreator); + + const auto buttons = buttonsCreator(messageBox); + QVERIFY(!buttons.isEmpty()); + + QFETCH(RoleSet, roles); + QFETCH(SignalSignature, signalSignature); + for (auto button: buttons) { + QVERIFY(button); + + messageBox.show(); + QVERIFY(QTest::qWaitForWindowExposed(&messageBox)); + + QSignalSpy spy(&messageBox, signalSignature); + QVERIFY(spy.isValid()); + button->click(); + + if (roles.contains(messageBox.buttonRole(button))) + QCOMPARE(spy.count(), 1); + else + QVERIFY(spy.isEmpty()); + } +} + +static void addAcceptedRow(const char *title, ButtonsCreator bc) +{ + QTest::newRow(title) << (RoleSet() << QMessageBox::AcceptRole << QMessageBox::YesRole) + << &QDialog::accepted << bc; +} + +static void addRejectedRow(const char *title, ButtonsCreator bc) +{ + QTest::newRow(title) << (RoleSet() << QMessageBox::RejectRole << QMessageBox::NoRole) + << &QDialog::rejected << bc; +} + +static void addCustomButtonsData() +{ + ButtonsCreator buttonsCreator = [](QMessageBox &messageBox) { + QVector<QPushButton*> buttons(QMessageBox::NRoles); + for (int i = QMessageBox::AcceptRole; i < QMessageBox::NRoles; ++i) { + buttons[i] = messageBox.addButton( + QString("Button role: %1").arg(i), QMessageBox::ButtonRole(i)); + } + + return buttons; + }; + + addAcceptedRow("Accepted_CustomButtons", buttonsCreator); + addRejectedRow("Rejected_CustomButtons", buttonsCreator); +} + +static void addStandardButtonsData() +{ + ButtonsCreator buttonsCreator = [](QMessageBox &messageBox) { + QVector<QPushButton*> buttons; + for (int i = QMessageBox::FirstButton; i <= QMessageBox::LastButton; i <<= 1) + buttons << messageBox.addButton(QMessageBox::StandardButton(i)); + + return buttons; + }; + + addAcceptedRow("Accepted_StandardButtons", buttonsCreator); + addRejectedRow("Rejected_StandardButtons", buttonsCreator); +} + +void tst_QMessageBox::acceptedRejectedSignals_data() +{ + QTest::addColumn<RoleSet>("roles"); + QTest::addColumn<SignalSignature>("signalSignature"); + QTest::addColumn<ButtonsCreator>("buttonsCreator"); + + addStandardButtonsData(); + addCustomButtonsData(); +} + QTEST_MAIN(tst_QMessageBox) #include "tst_qmessagebox.moc" diff --git a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp index 2ada4fedb6..6f527e7b6b 100644 --- a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp +++ b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp @@ -252,7 +252,7 @@ class QTestTranslator : public QTranslator { const QString m_str; public: - explicit QTestTranslator(QString str) : m_str(qMove(str)) {} + explicit QTestTranslator(QString str) : m_str(std::move(str)) {} QString translate(const char *, const char *sourceText, const char *, int) const override { return m_str + sourceText + m_str; } @@ -265,7 +265,7 @@ class QTranslatorGuard { Translator t; public: template <typename Arg> - explicit QTranslatorGuard(Arg a) : t(qMove(a)) + explicit QTranslatorGuard(Arg a) : t(std::move(a)) { qApp->installTranslator(&t); } ~QTranslatorGuard() { qApp->removeTranslator(&t); } diff --git a/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp index 95662a49a0..c4b6e22c37 100644 --- a/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp +++ b/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp @@ -313,6 +313,7 @@ void tst_QGraphicsEffect::draw() view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(item->numRepaints > 0); + QCoreApplication::processEvents(); // Process all queued paint events item->reset(); // Make sure installing the effect triggers a repaint. diff --git a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index 67e1f9ce30..2f5fc597dc 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -91,7 +91,7 @@ public: { Q_UNUSED(option); Q_UNUSED(widget); - painter->drawRoundRect(rect()); + painter->drawRoundedRect(rect(), 25, 25, Qt::RelativeSize); painter->drawLine(rect().topLeft(), rect().bottomRight()); painter->drawLine(rect().bottomLeft(), rect().topRight()); } diff --git a/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp b/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp index e7d26622c9..973a73a4a9 100644 --- a/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp @@ -183,6 +183,7 @@ void tst_QGraphicsEffectSource::init() effect->storeDeviceDependentStuff = false; effect->doNothingInDraw = false; item->reset(); + QCoreApplication::processEvents(); // Process all queued paint events } void tst_QGraphicsEffectSource::graphicsItem() diff --git a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp index 34646a9074..2f0c43552f 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp @@ -125,7 +125,7 @@ public: { Q_UNUSED(option); Q_UNUSED(widget); - painter->drawRoundRect(rect()); + painter->drawRoundedRect(rect(), 25, 25, Qt::RelativeSize); painter->drawLine(rect().topLeft(), rect().bottomRight()); painter->drawLine(rect().bottomLeft(), rect().topRight()); } diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsitem/BLACKLIST new file mode 100644 index 0000000000..e760042def --- /dev/null +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/BLACKLIST @@ -0,0 +1,3 @@ +# QTBUG-74760 +[sorting] +opensuse-42.3 diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 27eac03880..bca664c05b 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -301,8 +301,8 @@ private slots: void pos(); void scenePos(); void matrix(); - void sceneMatrix(); - void setMatrix(); + void sceneTransform(); + void setTransform(); void zValue(); void shape(); void contains(); @@ -552,8 +552,8 @@ void tst_QGraphicsItem::construction() QVERIFY(!item->acceptHoverEvents()); QVERIFY(!item->hasFocus()); QCOMPARE(item->pos(), QPointF()); - QCOMPARE(item->matrix(), QMatrix()); - QCOMPARE(item->sceneMatrix(), QMatrix()); + QCOMPARE(item->transform(), QTransform()); + QCOMPARE(item->sceneTransform(), QTransform()); QCOMPARE(item->zValue(), qreal(0)); QCOMPARE(item->sceneBoundingRect(), QRectF()); QCOMPARE(item->shape(), QPainterPath()); @@ -2116,68 +2116,68 @@ void tst_QGraphicsItem::scenePos() void tst_QGraphicsItem::matrix() { QGraphicsLineItem line; - QCOMPARE(line.matrix(), QMatrix()); - line.setMatrix(QMatrix().rotate(90)); - QCOMPARE(line.matrix(), QMatrix().rotate(90)); - line.setMatrix(QMatrix().rotate(90)); - QCOMPARE(line.matrix(), QMatrix().rotate(90)); - line.setMatrix(QMatrix().rotate(90), true); - QCOMPARE(line.matrix(), QMatrix().rotate(180)); - line.setMatrix(QMatrix().rotate(-90), true); - QCOMPARE(line.matrix(), QMatrix().rotate(90)); - line.resetMatrix(); - QCOMPARE(line.matrix(), QMatrix()); + QCOMPARE(line.transform(), QTransform()); + line.setTransform(QTransform().rotate(90)); + QCOMPARE(line.transform(), QTransform().rotate(90)); + line.setTransform(QTransform().rotate(90)); + QCOMPARE(line.transform(), QTransform().rotate(90)); + line.setTransform(QTransform().rotate(90), true); + QCOMPARE(line.transform(), QTransform().rotate(180)); + line.setTransform(QTransform().rotate(-90), true); + QCOMPARE(line.transform(), QTransform().rotate(90)); + line.resetTransform(); + QCOMPARE(line.transform(), QTransform()); line.setTransform(QTransform().rotate(90), true); - QCOMPARE(line.matrix(), QMatrix().rotate(90)); + QCOMPARE(line.transform(), QTransform().rotate(90)); line.setTransform(QTransform().rotate(90), true); - QCOMPARE(line.matrix(), QMatrix().rotate(90).rotate(90)); - line.resetMatrix(); + QCOMPARE(line.transform(), QTransform().rotate(90).rotate(90)); + line.resetTransform(); line.setTransform(QTransform::fromScale(2, 4), true); - QCOMPARE(line.matrix(), QMatrix().scale(2, 4)); + QCOMPARE(line.transform(), QTransform::fromScale(2, 4)); line.setTransform(QTransform::fromScale(2, 4), true); - QCOMPARE(line.matrix(), QMatrix().scale(2, 4).scale(2, 4)); - line.resetMatrix(); + QCOMPARE(line.transform(), QTransform::fromScale(2, 4).scale(2, 4)); + line.resetTransform(); line.setTransform(QTransform().shear(2, 4), true); - QCOMPARE(line.matrix(), QMatrix().shear(2, 4)); + QCOMPARE(line.transform(), QTransform().shear(2, 4)); line.setTransform(QTransform().shear(2, 4), true); - QCOMPARE(line.matrix(), QMatrix().shear(2, 4).shear(2, 4)); - line.resetMatrix(); + QCOMPARE(line.transform(), QTransform().shear(2, 4).shear(2, 4)); + line.resetTransform(); line.setTransform(QTransform::fromTranslate(10, 10), true); - QCOMPARE(line.matrix(), QMatrix().translate(10, 10)); + QCOMPARE(line.transform(), QTransform::fromTranslate(10, 10)); line.setTransform(QTransform::fromTranslate(10, 10), true); - QCOMPARE(line.matrix(), QMatrix().translate(10, 10).translate(10, 10)); - line.resetMatrix(); + QCOMPARE(line.transform(), QTransform::fromTranslate(10, 10).translate(10, 10)); + line.resetTransform(); } -void tst_QGraphicsItem::sceneMatrix() +void tst_QGraphicsItem::sceneTransform() { QGraphicsLineItem *parent = new QGraphicsLineItem; QGraphicsLineItem *child = new QGraphicsLineItem(QLineF(), parent); - QCOMPARE(parent->sceneMatrix(), QMatrix()); - QCOMPARE(child->sceneMatrix(), QMatrix()); + QCOMPARE(parent->sceneTransform(), QTransform()); + QCOMPARE(child->sceneTransform(), QTransform()); parent->setTransform(QTransform::fromTranslate(10, 10), true); - QCOMPARE(parent->sceneMatrix(), QMatrix().translate(10, 10)); - QCOMPARE(child->sceneMatrix(), QMatrix().translate(10, 10)); + QCOMPARE(parent->sceneTransform(), QTransform().translate(10, 10)); + QCOMPARE(child->sceneTransform(), QTransform().translate(10, 10)); child->setTransform(QTransform::fromTranslate(10, 10), true); - QCOMPARE(parent->sceneMatrix(), QMatrix().translate(10, 10)); - QCOMPARE(child->sceneMatrix(), QMatrix().translate(20, 20)); + QCOMPARE(parent->sceneTransform(), QTransform().translate(10, 10)); + QCOMPARE(child->sceneTransform(), QTransform().translate(20, 20)); parent->setTransform(QTransform().rotate(90), true); - QCOMPARE(parent->sceneMatrix(), QMatrix().translate(10, 10).rotate(90)); - QCOMPARE(child->sceneMatrix(), QMatrix().translate(10, 10).rotate(90).translate(10, 10)); + QCOMPARE(parent->sceneTransform(), QTransform().translate(10, 10).rotate(90)); + QCOMPARE(child->sceneTransform(), QTransform().translate(10, 10).rotate(90).translate(10, 10)); delete child; delete parent; } -void tst_QGraphicsItem::setMatrix() +void tst_QGraphicsItem::setTransform() { QGraphicsScene scene; QSignalSpy spy(&scene, SIGNAL(changed(QList<QRectF>))); @@ -2190,7 +2190,7 @@ void tst_QGraphicsItem::setMatrix() QCOMPARE(spy.count(), 1); - item.setMatrix(QMatrix().rotate(qreal(12.34))); + item.setTransform(QTransform().rotate(qreal(12.34))); QRectF rotatedRect = scene.sceneRect(); QVERIFY(unrotatedRect != rotatedRect); scene.update(scene.sceneRect()); @@ -2198,7 +2198,7 @@ void tst_QGraphicsItem::setMatrix() QCOMPARE(spy.count(), 2); - item.setMatrix(QMatrix()); + item.setTransform(QTransform()); scene.update(scene.sceneRect()); QApplication::instance()->processEvents(); @@ -2485,25 +2485,25 @@ void tst_QGraphicsItem::collidesWith_item() void tst_QGraphicsItem::collidesWith_path_data() { QTest::addColumn<QPointF>("pos"); - QTest::addColumn<QMatrix>("matrix"); + QTest::addColumn<QTransform>("transform"); QTest::addColumn<QPainterPath>("shape"); QTest::addColumn<bool>("rectCollides"); QTest::addColumn<bool>("ellipseCollides"); - QTest::newRow("nothing") << QPointF(0, 0) << QMatrix() << QPainterPath() << false << false; + QTest::newRow("nothing") << QPointF(0, 0) << QTransform() << QPainterPath() << false << false; QPainterPath rect; rect.addRect(0, 0, 20, 20); - QTest::newRow("rect1") << QPointF(0, 0) << QMatrix() << rect << true << true; - QTest::newRow("rect2") << QPointF(0, 0) << QMatrix().translate(21, 21) << rect << false << false; - QTest::newRow("rect3") << QPointF(21, 21) << QMatrix() << rect << false << false; + QTest::newRow("rect1") << QPointF(0, 0) << QTransform() << rect << true << true; + QTest::newRow("rect2") << QPointF(0, 0) << QTransform::fromTranslate(21, 21) << rect << false << false; + QTest::newRow("rect3") << QPointF(21, 21) << QTransform() << rect << false << false; } void tst_QGraphicsItem::collidesWith_path() { QFETCH(QPointF, pos); - QFETCH(QMatrix, matrix); + QFETCH(QTransform, transform); QFETCH(QPainterPath, shape); QFETCH(bool, rectCollides); QFETCH(bool, ellipseCollides); @@ -2512,12 +2512,12 @@ void tst_QGraphicsItem::collidesWith_path() QGraphicsEllipseItem ellipse(QRectF(0, 0, 20, 20)); rect.setPos(pos); - rect.setMatrix(matrix); + rect.setTransform(transform); ellipse.setPos(pos); - ellipse.setMatrix(matrix); + ellipse.setTransform(transform); - QPainterPath mappedShape = rect.sceneMatrix().inverted().map(shape); + QPainterPath mappedShape = rect.sceneTransform().inverted().map(shape); if (rectCollides) QVERIFY(rect.collidesWithPath(mappedShape)); @@ -2742,35 +2742,35 @@ void tst_QGraphicsItem::mapFromToParent() item4->setPos(10, 10); for (int i = 0; i < 4; ++i) { - QMatrix matrix; - matrix.rotate(i * 90); - matrix.translate(i * 100, -i * 100); - matrix.scale(2, 4); - item1->setMatrix(matrix); + QTransform transform; + transform.rotate(i * 90); + transform.translate(i * 100, -i * 100); + transform.scale(2, 4); + item1->setTransform(transform); - QCOMPARE(item1->mapToParent(QPointF(0, 0)), item1->pos() + matrix.map(QPointF(0, 0))); + QCOMPARE(item1->mapToParent(QPointF(0, 0)), item1->pos() + transform.map(QPointF(0, 0))); QCOMPARE(item2->mapToParent(QPointF(0, 0)), item2->pos()); QCOMPARE(item3->mapToParent(QPointF(0, 0)), item3->pos()); QCOMPARE(item4->mapToParent(QPointF(0, 0)), item4->pos()); - QCOMPARE(item1->mapToParent(QPointF(10, -10)), item1->pos() + matrix.map(QPointF(10, -10))); + QCOMPARE(item1->mapToParent(QPointF(10, -10)), item1->pos() + transform.map(QPointF(10, -10))); QCOMPARE(item2->mapToParent(QPointF(10, -10)), item2->pos() + QPointF(10, -10)); QCOMPARE(item3->mapToParent(QPointF(10, -10)), item3->pos() + QPointF(10, -10)); QCOMPARE(item4->mapToParent(QPointF(10, -10)), item4->pos() + QPointF(10, -10)); - QCOMPARE(item1->mapToParent(QPointF(-10, 10)), item1->pos() + matrix.map(QPointF(-10, 10))); + QCOMPARE(item1->mapToParent(QPointF(-10, 10)), item1->pos() + transform.map(QPointF(-10, 10))); QCOMPARE(item2->mapToParent(QPointF(-10, 10)), item2->pos() + QPointF(-10, 10)); QCOMPARE(item3->mapToParent(QPointF(-10, 10)), item3->pos() + QPointF(-10, 10)); QCOMPARE(item4->mapToParent(QPointF(-10, 10)), item4->pos() + QPointF(-10, 10)); - QCOMPARE(item1->mapFromParent(item1->pos()), matrix.inverted().map(QPointF(0, 0))); + QCOMPARE(item1->mapFromParent(item1->pos()), transform.inverted().map(QPointF(0, 0))); QCOMPARE(item2->mapFromParent(item2->pos()), QPointF(0, 0)); QCOMPARE(item3->mapFromParent(item3->pos()), QPointF(0, 0)); QCOMPARE(item4->mapFromParent(item4->pos()), QPointF(0, 0)); QCOMPARE(item1->mapFromParent(item1->pos() + QPointF(10, -10)), - matrix.inverted().map(QPointF(10, -10))); + transform.inverted().map(QPointF(10, -10))); QCOMPARE(item2->mapFromParent(item2->pos() + QPointF(10, -10)), QPointF(10, -10)); QCOMPARE(item3->mapFromParent(item3->pos() + QPointF(10, -10)), QPointF(10, -10)); QCOMPARE(item4->mapFromParent(item4->pos() + QPointF(10, -10)), QPointF(10, -10)); QCOMPARE(item1->mapFromParent(item1->pos() + QPointF(-10, 10)), - matrix.inverted().map(QPointF(-10, 10))); + transform.inverted().map(QPointF(-10, 10))); QCOMPARE(item2->mapFromParent(item2->pos() + QPointF(-10, 10)), QPointF(-10, 10)); QCOMPARE(item3->mapFromParent(item3->pos() + QPointF(-10, 10)), QPointF(-10, 10)); QCOMPARE(item4->mapFromParent(item4->pos() + QPointF(-10, 10)), QPointF(-10, 10)); @@ -2820,8 +2820,8 @@ void tst_QGraphicsItem::mapFromToScene() QCOMPARE(item4->mapFromScene(410, 400), QPointF(10, 0)); // Rotate item1 90 degrees clockwise - QMatrix matrix; matrix.rotate(90); - item1->setMatrix(matrix); + QTransform transform; transform.rotate(90); + item1->setTransform(transform); QCOMPARE(item1->pos(), item1->mapToParent(0, 0)); QCOMPARE(item2->pos(), item2->mapToParent(0, 0)); QCOMPARE(item3->pos(), item3->mapToParent(0, 0)); @@ -2848,7 +2848,7 @@ void tst_QGraphicsItem::mapFromToScene() QCOMPARE(item4->mapFromScene(-200, 410), QPointF(10, 0)); // Rotate item2 90 degrees clockwise - item2->setMatrix(matrix); + item2->setTransform(transform); QCOMPARE(item1->pos(), item1->mapToParent(0, 0)); QCOMPARE(item2->pos(), item2->mapToParent(0, 0)); QCOMPARE(item3->pos(), item3->mapToParent(0, 0)); @@ -2875,10 +2875,10 @@ void tst_QGraphicsItem::mapFromToScene() QCOMPARE(item4->mapFromScene(-210, 0), QPointF(10, 0)); // Translate item3 50 points, then rotate 90 degrees counterclockwise - QMatrix matrix2; - matrix2.translate(50, 0); - matrix2.rotate(-90); - item3->setMatrix(matrix2); + QTransform transform2; + transform2.translate(50, 0); + transform2.rotate(-90); + item3->setTransform(transform2); QCOMPARE(item1->pos(), item1->mapToParent(0, 0)); QCOMPARE(item2->pos(), item2->mapToParent(0, 0)); QCOMPARE(item3->pos(), item3->mapToParent(0, 0) - QPointF(50, 0)); @@ -2928,9 +2928,9 @@ void tst_QGraphicsItem::mapFromToItem() QCOMPARE(item3->mapFromItem(item2, 0, 0), QPointF(0, -200)); QCOMPARE(item4->mapFromItem(item3, 0, 0), QPointF(200, 0)); - QMatrix matrix; - matrix.translate(100, 100); - item1->setMatrix(matrix); + QTransform transform; + transform.translate(100, 100); + item1->setTransform(transform); QCOMPARE(item1->mapFromItem(item2, 0, 0), QPointF(100, -100)); QCOMPARE(item2->mapFromItem(item3, 0, 0), QPointF(0, 200)); @@ -2941,11 +2941,11 @@ void tst_QGraphicsItem::mapFromToItem() QCOMPARE(item3->mapFromItem(item2, 0, 0), QPointF(0, -200)); QCOMPARE(item4->mapFromItem(item3, 0, 0), QPointF(200, 0)); - matrix.rotate(90); - item1->setMatrix(matrix); - item2->setMatrix(matrix); - item3->setMatrix(matrix); - item4->setMatrix(matrix); + transform.rotate(90); + item1->setTransform(transform); + item2->setTransform(transform); + item3->setTransform(transform); + item4->setTransform(transform); QCOMPARE(item1->mapFromItem(item2, 0, 0), QPointF(0, -200)); QCOMPARE(item2->mapFromItem(item3, 0, 0), QPointF(200, 0)); @@ -3231,6 +3231,7 @@ void tst_QGraphicsItem::hoverEventsGenerateRepaints() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); + QCoreApplication::processEvents(); // Process all queued paint events EventTester *tester = new EventTester; scene.addItem(tester); @@ -4147,11 +4148,9 @@ void tst_QGraphicsItem::ensureVisible() void tst_QGraphicsItem::cursor() { QGraphicsScene scene; - QWidget topLevel; - QGraphicsView view(&scene,&topLevel); - topLevel.showMaximized(); - QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); - view.setFixedSize(topLevel.size()); + QGraphicsView view(&scene); + view.showFullScreen(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QGraphicsRectItem *item1 = scene.addRect(QRectF(-100, 0, 50, 50)); QGraphicsRectItem *item2 = scene.addRect(QRectF(50, 0, 50, 50)); @@ -4434,9 +4433,12 @@ protected: case QGraphicsItem::ItemPositionHasChanged: break; case QGraphicsItem::ItemMatrixChange: { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED QVariant variant; variant.setValue<QMatrix>(matrix()); oldValues << variant; +QT_WARNING_POP } break; case QGraphicsItem::ItemTransformChange: { @@ -4557,6 +4559,8 @@ void tst_QGraphicsItem::itemChange() QCOMPARE(tester.isEnabled(), true); } { +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED // QDesktopWidget::screen() // ItemMatrixChange / ItemTransformHasChanged tester.itemChangeReturnValue.setValue<QMatrix>(QMatrix().rotate(90)); tester.setMatrix(QMatrix().translate(50, 0), true); @@ -4571,6 +4575,7 @@ void tst_QGraphicsItem::itemChange() variant.setValue<QMatrix>(QMatrix()); QCOMPARE(tester.oldValues.last(), variant); QCOMPARE(tester.matrix(), QMatrix().rotate(90)); +QT_WARNING_POP } { tester.resetTransform(); @@ -5074,13 +5079,11 @@ void tst_QGraphicsItem::paint() QGraphicsView view2(&scene2); view2.show(); QVERIFY(QTest::qWaitForWindowExposed(&view2)); + QCoreApplication::processEvents(); // Process all queued paint events PaintTester tester2; scene2.addItem(&tester2); -#ifdef Q_OS_WINRT - QEXPECT_FAIL("", "Fails on WinRT. Figure out why - QTBUG-68297", Abort); -#endif //First show one paint QTRY_COMPARE(tester2.painted, 1); @@ -6534,11 +6537,9 @@ void tst_QGraphicsItem::ensureUpdateOnTextItem() QGraphicsView view(&scene); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); + QCoreApplication::processEvents(); // Process all queued paint events TextItem *text1 = new TextItem(QLatin1String("123")); scene.addItem(text1); -#ifdef Q_OS_WINRT - QEXPECT_FAIL("", "Fails on WinRT. Figure out why - QTBUG-68297", Abort); -#endif QTRY_COMPARE(text1->updates,1); //same bouding rect but we have to update @@ -6810,6 +6811,7 @@ void tst_QGraphicsItem::opacity2() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); + QCoreApplication::processEvents(); // Process all queued paint events QTRY_VERIFY(view.repaints >= 1); #define RESET_REPAINT_COUNTERS \ @@ -6883,6 +6885,7 @@ void tst_QGraphicsItem::opacityZeroUpdates() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); + QCoreApplication::processEvents(); // Process all queued paint events QTRY_VERIFY(view.repaints > 0); view.reset(); @@ -7275,6 +7278,7 @@ void tst_QGraphicsItem::cacheMode() QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); + QCoreApplication::processEvents(); // Process all queued paint events EventTester *tester = new EventTester; EventTester *testerChild = new EventTester; @@ -7454,6 +7458,7 @@ void tst_QGraphicsItem::cacheMode2() QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); + QCoreApplication::processEvents(); // Process all queued paint events EventTester *tester = new EventTester; scene.addItem(tester); @@ -7944,6 +7949,7 @@ void tst_QGraphicsItem::itemUsesExtendedStyleOption() rect->startTrack = false; topLevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); + QCoreApplication::processEvents(); // Process all queued paint events QTRY_VERIFY(rect->repaints > 0); rect->repaints = 0; rect->startTrack = true; @@ -8030,6 +8036,7 @@ void tst_QGraphicsItem::moveItem() MyGraphicsView view(&scene); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); + QCoreApplication::processEvents(); // Process all queued paint events EventTester *parent = new EventTester; EventTester *child = new EventTester(parent); @@ -8108,6 +8115,7 @@ void tst_QGraphicsItem::moveLineItem() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); + QCoreApplication::processEvents(); // Process all queued paint events view.reset(); QRectF brect = item->boundingRect(); @@ -8288,6 +8296,7 @@ void tst_QGraphicsItem::hitTestGraphicsEffectItem() toplevel.resize(300, 300); toplevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&toplevel)); + QCoreApplication::processEvents(); // Process all queued paint events // Confuse the BSP with dummy items. QGraphicsRectItem *dummy = new QGraphicsRectItem(0, 0, 20, 20); @@ -11266,6 +11275,7 @@ void tst_QGraphicsItem::QTBUG_6738_missingUpdateWithSetParent() qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); + QCoreApplication::processEvents(); // Process all queued paint events QTRY_VERIFY(view.repaints > 0); // test case #1 @@ -11315,6 +11325,7 @@ void tst_QGraphicsItem::QT_2653_fullUpdateDiscardingOpacityUpdate() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); + QCoreApplication::processEvents(); // Process all queued paint events view.reset(); parentGreen->setOpacity(1.0); @@ -11348,7 +11359,9 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() origView.show(); QVERIFY(QTest::qWaitForWindowActive(&origView)); - origView.setGeometry(origView.width() + 20, 20, + QCoreApplication::processEvents(); // Process all queued paint events + + origView.setGeometry(origView.x() + origView.width() + 20, origView.y() + 20, origView.width(), origView.height()); parentGreen->setFlag(QGraphicsItem::ItemIgnoresTransformations); @@ -11356,9 +11369,6 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() origView.reset(); childYellow->setOpacity(0.0); -#ifdef Q_OS_WINRT - QEXPECT_FAIL("", "Fails on WinRT. Figure out why - QTBUG-68297", Abort); -#endif QTRY_COMPARE(origView.repaints, 1); view.show(); @@ -11370,6 +11380,10 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() childYellow->setOpacity(1.0); +#ifdef Q_OS_WINRT + QEXPECT_FAIL("", "Fails on WinRT. Figure out why - QTBUG-68297", Abort); +#endif + QTRY_COMPARE(origView.repaints, 1); QTRY_COMPARE(view.repaints, 1); } @@ -11505,6 +11519,7 @@ void tst_QGraphicsItem::doNotMarkFullUpdateIfNotInScene() view.show(); QVERIFY(QTest::qWaitForWindowExposed(view.windowHandle())); QVERIFY(QTest::qWaitForWindowActive(view.windowHandle())); + QCoreApplication::processEvents(); // Process all queued paint events view.activateWindow(); QTRY_VERIFY(view.isActiveWindow()); QTRY_VERIFY(view.repaints >= 1); diff --git a/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp b/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp index dfb2752ee0..ed79904ed8 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp @@ -54,9 +54,9 @@ void tst_QGraphicsItemAnimation::construction() QCOMPARE(animation.posAt(0), QPointF()); QCOMPARE(animation.posAt(0.5), QPointF()); QCOMPARE(animation.posAt(1), QPointF()); - QCOMPARE(animation.matrixAt(0), QMatrix()); - QCOMPARE(animation.matrixAt(0.5), QMatrix()); - QCOMPARE(animation.matrixAt(1), QMatrix()); + QCOMPARE(animation.transformAt(0), QTransform()); + QCOMPARE(animation.transformAt(0.5), QTransform()); + QCOMPARE(animation.transformAt(1), QTransform()); QCOMPARE(animation.rotationAt(0), qreal(0.0)); QCOMPARE(animation.rotationAt(0.5), qreal(0.0)); QCOMPARE(animation.rotationAt(1), qreal(0.0)); diff --git a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp index f9b6fe3ebd..9369470ce5 100644 --- a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp @@ -150,7 +150,7 @@ public: Q_UNUSED(option); Q_UNUSED(widget); painter->setBrush(m_brush); - painter->drawRoundRect(rect()); + painter->drawRoundedRect(rect(), 25, 25, Qt::RelativeSize); } void setSizeHint(Qt::SizeHint which, const QSizeF &size) { diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 49afc5f369..4a301337ef 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -140,6 +140,7 @@ private slots: void palettePropagation(); void fontPropagation(); void dontCrashWhenDie(); + void dontCrashNoParent(); void createProxyForChildWidget(); #ifndef QT_NO_CONTEXTMENU void actionsContextMenu(); @@ -2964,6 +2965,20 @@ void tst_QGraphicsProxyWidget::dontCrashWhenDie() qDeleteAll(QApplication::topLevelWidgets()); } +void tst_QGraphicsProxyWidget::dontCrashNoParent() // QTBUG-15442 +{ + QGraphicsProxyWidget *parent(new QGraphicsProxyWidget); + QGraphicsProxyWidget *child(new QGraphicsProxyWidget); + QScopedPointer<QLabel> label0(new QLabel); + QScopedPointer<QLabel> label1(new QLabel); + + child->setParentItem(parent); + // Set the first label as the proxied widget. + parent->setWidget(label0.data()); + // If we attempt to change the proxied widget we get a crash. + parent->setWidget(label1.data()); +} + void tst_QGraphicsProxyWidget::createProxyForChildWidget() { QGraphicsScene scene; diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST index 0e7a1b451f..b8b427b3dd 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST @@ -1,10 +1,6 @@ -[removeItem] -# QTBUG-60754, QTest::mouseMove is not always respected, or the CI moves the cursor -osx-10.11 ci [isActive] opensuse-42.3 ci [removeFullyTransparentItem] -osx-10.11 osx-10.12 [tabFocus_sceneWithNestedFocusWidgets] opensuse diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 838b1f4be6..46f1d5df5c 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -112,14 +112,14 @@ protected: painter->setOpacity(0.75); painter->setPen(Qt::NoPen); painter->setBrush(Qt::darkGray); - painter->drawRoundRect(boundingRect().adjusted(3, 3, -3, -3), Qt::darkGray); + painter->drawRoundedRect(boundingRect().adjusted(3, 3, -3, -3), 25, 25, Qt::RelativeSize); painter->setPen(Qt::black); if (isHovered) { - painter->setBrush(QColor(Qt::blue).light(120)); + painter->setBrush(QColor(Qt::blue).lighter(120)); } else { painter->setBrush(Qt::gray); } - painter->drawRoundRect(boundingRect().adjusted(0, 0, -5, -5)); + painter->drawRoundedRect(boundingRect().adjusted(0, 0, -5, -5), 25, 25, Qt::RelativeSize); } }; @@ -233,7 +233,6 @@ private slots: void tabFocus_sceneWithFocusWidgets(); void tabFocus_sceneWithNestedFocusWidgets(); void style(); - void sorting_data(); void sorting(); void insertionOrder(); void changedSignal_data(); @@ -459,41 +458,41 @@ void tst_QGraphicsScene::items() void tst_QGraphicsScene::itemsBoundingRect_data() { QTest::addColumn<QList<QRectF> >("rects"); - QTest::addColumn<QMatrix>("matrix"); + QTest::addColumn<QTransform>("transform"); QTest::addColumn<QRectF>("boundingRect"); - QMatrix transformationMatrix; - transformationMatrix.translate(50, -50); - transformationMatrix.scale(2, 2); - transformationMatrix.rotate(90); + QTransform transformation; + transformation.translate(50, -50); + transformation.scale(2, 2); + transformation.rotate(90); QTest::newRow("none") << QList<QRectF>() - << QMatrix() + << QTransform() << QRectF(); QTest::newRow("{{0, 0, 10, 10}}") << (QList<QRectF>() << QRectF(0, 0, 10, 10)) - << QMatrix() + << QTransform() << QRectF(0, 0, 10, 10); QTest::newRow("{{-10, -10, 10, 10}}") << (QList<QRectF>() << QRectF(-10, -10, 10, 10)) - << QMatrix() + << QTransform() << QRectF(-10, -10, 10, 10); QTest::newRow("{{-1000, -1000, 1, 1}, {-10, -10, 10, 10}}") << (QList<QRectF>() << QRectF(-1000, -1000, 1, 1) << QRectF(-10, -10, 10, 10)) - << QMatrix() + << QTransform() << QRectF(-1000, -1000, 1000, 1000); QTest::newRow("transformed {{0, 0, 10, 10}}") << (QList<QRectF>() << QRectF(0, 0, 10, 10)) - << transformationMatrix + << transformation << QRectF(30, -50, 20, 20); QTest::newRow("transformed {{-10, -10, 10, 10}}") << (QList<QRectF>() << QRectF(-10, -10, 10, 10)) - << transformationMatrix + << transformation << QRectF(50, -70, 20, 20); QTest::newRow("transformed {{-1000, -1000, 1, 1}, {-10, -10, 10, 10}}") << (QList<QRectF>() << QRectF(-1000, -1000, 1, 1) << QRectF(-10, -10, 10, 10)) - << transformationMatrix + << transformation << QRectF(50, -2050, 2000, 2000); QList<QRectF> all; @@ -501,18 +500,18 @@ void tst_QGraphicsScene::itemsBoundingRect_data() all << QRectF(randomX[i], randomY[i], 10, 10); QTest::newRow("all") << all - << QMatrix() + << QTransform() << QRectF(-980, -994, 1988, 1983); QTest::newRow("transformed all") << all - << transformationMatrix + << transformation << QRectF(-1928, -2010, 3966, 3976); } void tst_QGraphicsScene::itemsBoundingRect() { QFETCH(QList<QRectF>, rects); - QFETCH(QMatrix, matrix); + QFETCH(QTransform, transform); QFETCH(QRectF, boundingRect); QGraphicsScene scene; @@ -522,7 +521,7 @@ void tst_QGraphicsScene::itemsBoundingRect() path.addRect(rect); QGraphicsPathItem *item = scene.addPath(path); item->setPen(QPen(Qt::black, 0)); - item->setMatrix(matrix); + item->setTransform(transform); } QCOMPARE(scene.itemsBoundingRect(), boundingRect); @@ -2502,7 +2501,7 @@ void tst_QGraphicsScene::render_data() QTest::addColumn<QRectF>("targetRect"); QTest::addColumn<QRectF>("sourceRect"); QTest::addColumn<Qt::AspectRatioMode>("aspectRatioMode"); - QTest::addColumn<QMatrix>("matrix"); + QTest::addColumn<QTransform>("transform"); QTest::addColumn<QPainterPath>("clip"); QPainterPath clip_rect; @@ -2512,61 +2511,61 @@ void tst_QGraphicsScene::render_data() clip_ellipse.addEllipse(100,50,150,200); QTest::newRow("all-all-untransformed") << QRectF() << QRectF() - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("all-topleft-untransformed") << QRectF(0, 0, 150, 150) - << QRectF() << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << QRectF() << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("all-topright-untransformed") << QRectF(150, 0, 150, 150) - << QRectF() << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << QRectF() << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("all-bottomleft-untransformed") << QRectF(0, 150, 150, 150) - << QRectF() << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << QRectF() << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("all-bottomright-untransformed") << QRectF(150, 150, 150, 150) - << QRectF() << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << QRectF() << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("topleft-all-untransformed") << QRectF() << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("topright-all-untransformed") << QRectF() << QRectF(0, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("bottomleft-all-untransformed") << QRectF() << QRectF(-10, 0, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("bottomright-all-untransformed") << QRectF() << QRectF(0, 0, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("topleft-topleft-untransformed") << QRectF(0, 0, 150, 150) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("topright-topleft-untransformed") << QRectF(150, 0, 150, 150) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("bottomleft-topleft-untransformed") << QRectF(0, 150, 150, 150) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("bottomright-topleft-untransformed") << QRectF(150, 150, 150, 150) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("top-topleft-untransformed") << QRectF(0, 0, 300, 150) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("bottom-topleft-untransformed") << QRectF(0, 150, 300, 150) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("left-topleft-untransformed") << QRectF(0, 0, 150, 300) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("right-topleft-untransformed") << QRectF(150, 0, 150, 300) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("top-bottomright-untransformed") << QRectF(0, 0, 300, 150) << QRectF(0, 0, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("bottom-bottomright-untransformed") << QRectF(0, 150, 300, 150) << QRectF(0, 0, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("left-bottomright-untransformed") << QRectF(0, 0, 150, 300) << QRectF(0, 0, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("right-bottomright-untransformed") << QRectF(150, 0, 150, 300) << QRectF(0, 0, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform() << QPainterPath(); QTest::newRow("all-all-45-deg-right") << QRectF() << QRectF() - << Qt::IgnoreAspectRatio << QMatrix().rotate(-45) << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform().rotate(-45) << QPainterPath(); QTest::newRow("all-all-45-deg-left") << QRectF() << QRectF() - << Qt::IgnoreAspectRatio << QMatrix().rotate(45) << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform().rotate(45) << QPainterPath(); QTest::newRow("all-all-scale-2x") << QRectF() << QRectF() - << Qt::IgnoreAspectRatio << QMatrix().scale(2, 2) << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform::fromScale(2, 2) << QPainterPath(); QTest::newRow("all-all-translate-50-0") << QRectF() << QRectF() - << Qt::IgnoreAspectRatio << QMatrix().translate(50, 0) << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform::fromTranslate(50, 0) << QPainterPath(); QTest::newRow("all-all-translate-0-50") << QRectF() << QRectF() - << Qt::IgnoreAspectRatio << QMatrix().translate(0, 50) << QPainterPath(); + << Qt::IgnoreAspectRatio << QTransform::fromTranslate(0, 50) << QPainterPath(); QTest::newRow("all-all-untransformed-clip-rect") << QRectF() << QRectF() - << Qt::IgnoreAspectRatio << QMatrix() << clip_rect; + << Qt::IgnoreAspectRatio << QTransform() << clip_rect; QTest::newRow("all-all-untransformed-clip-ellipse") << QRectF() << QRectF() - << Qt::IgnoreAspectRatio << QMatrix() << clip_ellipse; + << Qt::IgnoreAspectRatio << QTransform() << clip_ellipse; } void tst_QGraphicsScene::render() @@ -2574,7 +2573,7 @@ void tst_QGraphicsScene::render() QFETCH(QRectF, targetRect); QFETCH(QRectF, sourceRect); QFETCH(Qt::AspectRatioMode, aspectRatioMode); - QFETCH(QMatrix, matrix); + QFETCH(QTransform, transform); QFETCH(QPainterPath, clip); QPixmap pix(30, 30); @@ -2602,7 +2601,7 @@ void tst_QGraphicsScene::render() painter.setPen(QPen(Qt::darkGray, 2)); painter.drawLine(0, 150, 300, 150); painter.drawLine(150, 0, 150, 300); - painter.setMatrix(matrix); + painter.setTransform(transform); if (!clip.isEmpty()) painter.setClipPath(clip); scene.render(&painter, targetRect, sourceRect, aspectRatioMode); painter.end(); @@ -3519,20 +3518,9 @@ void tst_QGraphicsScene::task250680_childClip() QCOMPARE(scene.items(QRectF(320, 240, 5, 5)).size(), 2); } -void tst_QGraphicsScene::sorting_data() -{ - QTest::addColumn<bool>("cache"); - - QTest::newRow("Normal sorting") << false; - QTest::newRow("Cached sorting") << true; -} - void tst_QGraphicsScene::sorting() { - QFETCH(bool, cache); - QGraphicsScene scene; - scene.setSortCacheEnabled(cache); QGraphicsRectItem *t_1 = new QGraphicsRectItem(0, 0, 50, 50); QGraphicsRectItem *c_1 = new QGraphicsRectItem(0, 0, 40, 40, t_1); @@ -4318,6 +4306,7 @@ void tst_QGraphicsScene::removeFullyTransparentItem() view.show(); qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); + QCoreApplication::processEvents(); // Process all queued paint events // NB! The parent has the ItemHasNoContents flag set, which means // the parent itself doesn't generate any update requests, only the diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 3dc110298a..28df3a3c38 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -1650,6 +1650,7 @@ void tst_QGraphicsView::itemsInRect_cosmeticAdjust() QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(rect->numPaints > 0); + QCoreApplication::processEvents(); // Process all queued paint events rect->numPaints = 0; if (updateRect.isNull()) view.viewport()->update(); @@ -4074,6 +4075,8 @@ void tst_QGraphicsView::update() QTRY_COMPARE(view.lastUpdateRegions.at(0), QRegion(updateRect) & viewportRect); } QTRY_VERIFY(!viewPrivate->fullUpdatePending); +#else + Q_UNUSED(updateRect); #endif } diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index 45c86800d6..6f7dca86eb 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -502,11 +502,6 @@ void tst_QAbstractItemView::basic_tests(QAbstractItemView *view) view->commitData(0); view->editorDestroyed(0); - view->setHorizontalStepsPerItem(2); - view->horizontalStepsPerItem(); - view->setVerticalStepsPerItem(2); - view->verticalStepsPerItem(); - // Will assert as it should // view->setIndexWidget(QModelIndex(), 0); diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index e51a915401..42258c85b9 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -255,11 +255,12 @@ protected: void calculateAndCheck(int cppline, const int precalced_comparedata[]); void testMinMaxSectionSize(bool stretchLastSection); - QWidget *topLevel; - QHeaderView *view; - QStandardItemModel *model; - QTableView *m_tableview; - bool m_using_reset_model; + QWidget *topLevel = nullptr; + QHeaderView *view = nullptr; + QStandardItemModel *model = nullptr; + QTableView *m_tableview = nullptr; + bool m_using_reset_model = false; + bool m_special_prepare = false; QElapsedTimer timer; }; @@ -444,7 +445,13 @@ tst_QHeaderView::tst_QHeaderView() void tst_QHeaderView::initTestCase() { - m_tableview = new QTableView(); + m_tableview = new QTableView; + qDebug().noquote().nospace() + << "default min section size is " + << QString::number(m_tableview->verticalHeader()->minimumSectionSize()) + << QLatin1Char('/') + << m_tableview->horizontalHeader()->minimumSectionSize() + << " (v/h)"; } void tst_QHeaderView::cleanupTestCase() @@ -616,6 +623,27 @@ void tst_QHeaderView::hidden() view->setSectionHidden(1, false); QCOMPARE(view->isSectionHidden(0), false); QCOMPARE(view->sectionSize(0), view->defaultSectionSize()); + + // d->hiddenSectionSize could go out of sync when a new model + // was set which has fewer sections than before and some of them + // were hidden + QStandardItemModel model2(model->rowCount() - 1, model->columnCount()); + + for (int i = 0; i < model->rowCount(); ++i) + view->setSectionHidden(i, true); + view->setModel(&model2); + QVERIFY(view->sectionsHidden()); + for (int i = 0; i < model2.rowCount(); ++i) { + QVERIFY(view->isSectionHidden(i)); + } + + view->setModel(model); + for (int i = 0; i < model2.rowCount(); ++i) { + QVERIFY(view->isSectionHidden(i)); + } + QCOMPARE(view->isSectionHidden(model->rowCount() - 1), false); + for (int i = 0; i < model->rowCount(); ++i) + view->setSectionHidden(i, false); } void tst_QHeaderView::stretch() @@ -1835,9 +1863,14 @@ void tst_QHeaderView::restoreBeforeSetModel() void tst_QHeaderView::defaultSectionSizeTest() { +#if defined Q_OS_WINRT + QSKIP("Fails on WinRT - QTBUG-73309"); +#endif + // Setup QTableView qtv; QHeaderView *hv = qtv.verticalHeader(); + hv->setMinimumSectionSize(10); hv->setDefaultSectionSize(99); // Set it to a value different from defaultSize. QStandardItemModel amodel(4, 4); qtv.setModel(&amodel); @@ -2824,6 +2857,7 @@ void tst_QHeaderView::additionalInit() QFETCH(bool, reset_model); m_using_reset_model = reset_model; + m_special_prepare = special_prepare; if (m_using_reset_model) { XResetModel *m = new XResetModel(); @@ -3037,18 +3071,34 @@ void tst_QHeaderView::mixedTests() view->moveSection(0, 5); for (int u = model->rowCount(); u >= 0; --u) { - if (u % 5 != 0) + if (u % 5 != 0) { view->hideSection(u); - if (u % 3 != 0) + QVERIFY(view->isSectionHidden(u)); + } + if (u % 3 != 0) { view->showSection(u); + QVERIFY(!view->isSectionHidden(u)); + } } model->insertRows(3, 7); model->removeRows(8, 3); model->setRowCount(model->rowCount() - 10); + // the upper is not visible (when m_using_reset_model is true) + // the lower 11 are modified due to insert/removeRows + for (int u = model->rowCount() - 1; u >= 11; --u) { + // when using reset, the hidden rows will *not* move + const int calcMod = m_using_reset_model ? u : u - 4; // 7 added, 3 removed + if (calcMod % 5 != 0 && calcMod % 3 == 0) { + QVERIFY(view->isSectionHidden(u)); + } + if (calcMod % 3 != 0) { + QVERIFY(!view->isSectionHidden(u)); + } + } if (m_using_reset_model) { - const int precalced_results[] = { 898296472, 337096378, -543340640, 1, -1251526424, -568618976, 9250 }; + const int precalced_results[] = { 898296472, 337096378, -543340640, -1964432121, -1251526424, -568618976, 9250 }; calculateAndCheck(__LINE__, precalced_results); } else { const int precalced_results[] = { 1911338224, 1693514365, -613398968, -1912534953, 1582159424, -1851079000, 9300 }; diff --git a/tests/auto/widgets/itemviews/qitemdelegate/BLACKLIST b/tests/auto/widgets/itemviews/qitemdelegate/BLACKLIST index c6aeebc8f8..fea108f3fd 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/BLACKLIST +++ b/tests/auto/widgets/itemviews/qitemdelegate/BLACKLIST @@ -2,7 +2,3 @@ opensuse-42.3 ci [testLineEditValidation] opensuse-42.3 ci -[comboBox] -# QTBUG-67282 -opensuse -opensuse-leap diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp index adedace8b2..7fd1822295 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp @@ -727,6 +727,16 @@ void tst_QItemDelegate::dateTimeEditor_data() << QDate(2006, 10, 31); } +static QDateTimeEdit *findDateTimeEdit(const QWidget *widget) +{ + const auto dateTimeEditors = widget->findChildren<QDateTimeEdit *>(); + for (auto dateTimeEditor : dateTimeEditors) { + if (qstrcmp(dateTimeEditor->metaObject()->className(), "QDateTimeEdit") == 0) + return dateTimeEditor; + } + return nullptr; +} + void tst_QItemDelegate::dateTimeEditor() { QFETCH(QTime, time); @@ -742,17 +752,24 @@ void tst_QItemDelegate::dateTimeEditor() item3->setData(Qt::DisplayRole, QDateTime(date, time)); QTableWidget widget(1, 3); + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + + QLatin1String("::") + + QLatin1String(QTest::currentDataTag())); widget.setItem(0, 0, item1); widget.setItem(0, 1, item2); widget.setItem(0, 2, item3); widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); + QApplication::setActiveWindow(&widget); widget.editItem(item1); QTestEventLoop::instance().enterLoop(1); - QTimeEdit *timeEditor = widget.viewport()->findChild<QTimeEdit *>(); - QVERIFY(timeEditor); + + QTimeEdit *timeEditor = nullptr; + auto viewport = widget.viewport(); + QTRY_VERIFY( (timeEditor = viewport->findChild<QTimeEdit *>()) ); QCOMPARE(timeEditor->time(), time); // The data must actually be different in order for the model // to be updated. @@ -763,8 +780,8 @@ void tst_QItemDelegate::dateTimeEditor() widget.setFocus(); widget.editItem(item2); - QTRY_VERIFY(widget.viewport()->findChild<QDateEdit *>()); - QDateEdit *dateEditor = widget.viewport()->findChild<QDateEdit *>(); + QDateEdit *dateEditor = nullptr; + QTRY_VERIFY( (dateEditor = viewport->findChild<QDateEdit *>()) ); QCOMPARE(dateEditor->date(), date); dateEditor->setDate(date.addDays(60)); @@ -774,12 +791,8 @@ void tst_QItemDelegate::dateTimeEditor() QTestEventLoop::instance().enterLoop(1); - QList<QDateTimeEdit *> dateTimeEditors = widget.findChildren<QDateTimeEdit *>(); - QDateTimeEdit *dateTimeEditor = 0; - foreach(dateTimeEditor, dateTimeEditors) - if (dateTimeEditor->metaObject()->className() == QLatin1String("QDateTimeEdit")) - break; - QVERIFY(dateTimeEditor); + QDateTimeEdit *dateTimeEditor = nullptr; + QTRY_VERIFY( (dateTimeEditor = findDateTimeEdit(viewport)) ); QCOMPARE(dateTimeEditor->date(), date); QCOMPARE(dateTimeEditor->time(), time); dateTimeEditor->setTime(time.addSecs(600)); @@ -1387,6 +1400,7 @@ void tst_QItemDelegate::comboBox() widget.setItem(0, 0, item1); widget.show(); QVERIFY(QTest::qWaitForWindowExposed(&widget)); + QApplication::setActiveWindow(&widget); widget.editItem(item1); diff --git a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp index bbdaac5c6f..071665a5e3 100644 --- a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp +++ b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp @@ -249,7 +249,7 @@ void tst_QItemView::populate() for (int y = 0; y < treeModel->columnCount(); ++y) { QModelIndex index = treeModel->index(x, y, parent); treeModel->setData(index, xS + QLatin1Char('_') + QString::number(y) + QLatin1Char('_') + iS); - treeModel->setData(index, QVariant(QColor(Qt::blue)), Qt::TextColorRole); + treeModel->setData(index, QVariant(QColor(Qt::blue)), Qt::ForegroundRole); } } } diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp index 433b9e55e1..0b828b8484 100644 --- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp +++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp @@ -121,6 +121,7 @@ private slots: void task254449_draggingItemToNegativeCoordinates(); void keyboardSearch(); void shiftSelectionWithNonUniformItemSizes(); + void shiftSelectionWithItemAlignment(); void clickOnViewportClearsSelection(); void task262152_setModelColumnNavigate(); void taskQTBUG_2233_scrollHiddenItems_data(); @@ -380,8 +381,11 @@ void tst_QListView::cursorMove() << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up << Qt::Key_Left << Qt::Key_Left << Qt::Key_Up << Qt::Key_Down; - int displayRow = rows / displayColumns - 1; - int displayColumn = displayColumns - (rows % displayColumns) - 1; + int lastRow = rows / displayColumns - 1; + int lastColumn = displayColumns - 1; + + int displayRow = lastRow; + int displayColumn = lastColumn - (rows % displayColumns); QApplication::instance()->processEvents(); for (int i = 0; i < keymoves.size(); ++i) { @@ -395,10 +399,24 @@ void tst_QListView::cursorMove() displayRow = qMin(rows / displayColumns - 1, displayRow + 1); break; case Qt::Key_Left: - displayColumn = qMax(0, displayColumn - 1); + if (displayColumn > 0) { + displayColumn--; + } else { + if (displayRow > 0) { + displayRow--; + displayColumn = lastColumn; + } + } break; case Qt::Key_Right: - displayColumn = qMin(displayColumns-1, displayColumn + 1); + if (displayColumn < lastColumn) { + displayColumn++; + } else { + if (displayRow < lastRow) { + displayRow++; + displayColumn = 0; + } + } break; default: QVERIFY(false); @@ -1785,6 +1803,51 @@ void tst_QListView::shiftSelectionWithNonUniformItemSizes() } } +void tst_QListView::shiftSelectionWithItemAlignment() +{ + QStringList items; + for (int c = 0; c < 2; c++) { + for (int i = 10; i > 0; i--) + items << QString(i, QLatin1Char('*')); + + for (int i = 1; i < 11; i++) + items << QString(i, QLatin1Char('*')); + } + + QListView view; + view.setFlow(QListView::TopToBottom); + view.setWrapping(true); + view.setItemAlignment(Qt::AlignLeft); + view.setSelectionMode(QAbstractItemView::ExtendedSelection); + + QStringListModel model(items); + view.setModel(&model); + + QFont font = view.font(); + font.setPixelSize(10); + view.setFont(font); + view.resize(300, view.sizeHintForRow(0) * items.size() / 2 + view.horizontalScrollBar()->height()); + + view.show(); + QApplication::setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); + QCOMPARE(static_cast<QWidget *>(&view), QApplication::activeWindow()); + + QModelIndex index1 = view.model()->index(items.size() / 4, 0); + QPoint p = view.visualRect(index1).center(); + QVERIFY(view.viewport()->rect().contains(p)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p); + QCOMPARE(view.currentIndex(), index1); + QCOMPARE(view.selectionModel()->selectedIndexes().size(), 1); + + QModelIndex index2 = view.model()->index(items.size() / 4 * 3, 0); + p = view.visualRect(index2).center(); + QVERIFY(view.viewport()->rect().contains(p)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ShiftModifier, p); + QCOMPARE(view.currentIndex(), index2); + QCOMPARE(view.selectionModel()->selectedIndexes().size(), index2.row() - index1.row() + 1); +} + void tst_QListView::clickOnViewportClearsSelection() { QStringList items; diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp index d8e14df353..30afa69c31 100644 --- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp +++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp @@ -344,7 +344,7 @@ void tst_QListWidget::addItem2() testWidget->addItem(item); QCOMPARE(testWidget->count(), ++count); QCOMPARE(testWidget->item(testWidget->count()-1), item); - QCOMPARE(testWidget->isItemHidden(item), false); + QCOMPARE(item->isHidden(), false); } void tst_QListWidget::addItems() @@ -402,13 +402,18 @@ void tst_QListWidget::closePersistentEditor() void tst_QListWidget::setItemHidden() { +#if QT_DEPRECATED_SINCE(5, 13) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED // Boundary checking - testWidget->setItemHidden(0, true); - testWidget->setItemHidden(0, false); + testWidget->setItemHidden(nullptr, true); + testWidget->setItemHidden(nullptr, false); +QT_WARNING_POP +#endif int totalHidden = 0; for (int i = 0; i < testWidget->model()->rowCount(); ++i) - if (testWidget->isItemHidden(testWidget->item(i))) + if (testWidget->item(i)->isHidden()) totalHidden++; QListWidgetItem *item = new QListWidgetItem(QString::number(testWidget->count())); @@ -417,31 +422,31 @@ void tst_QListWidget::setItemHidden() // Check that nothing else changed int newTotal = 0; for (int i = 0; i < testWidget->model()->rowCount(); ++i) - if (testWidget->isItemHidden(testWidget->item(i))) + if (testWidget->item(i)->isHidden()) newTotal++; QCOMPARE(newTotal, totalHidden); - testWidget->setItemHidden(item, true); - QCOMPARE(testWidget->isItemHidden(item), true); + item->setHidden(true); + QCOMPARE(item->isHidden(), true); // Check that nothing else changed newTotal = 0; for (int i = 0; i < testWidget->model()->rowCount(); ++i) - if (testWidget->isItemHidden(testWidget->item(i))) + if (testWidget->item(i)->isHidden()) newTotal++; QCOMPARE(newTotal, totalHidden + 1); - testWidget->setItemHidden(item, false); - QCOMPARE(testWidget->isItemHidden(item), false); + item->setHidden(false); + QCOMPARE(item->isHidden(), false); // Check that nothing else changed newTotal = 0; for (int i = 0; i < testWidget->model()->rowCount(); ++i) - if (testWidget->isItemHidden(testWidget->item(i))) + if (testWidget->item(i)->isHidden()) newTotal++; QCOMPARE(newTotal, totalHidden); - testWidget->setItemHidden(item, true); + item->setHidden(true); } void tst_QListWidget::setCurrentItem_data() @@ -847,7 +852,7 @@ void tst_QListWidget::selectedItems() testWidget->setSelectionMode(QListWidget::SingleSelection); for (int i=0; i<itemCount; ++i) { QListWidgetItem *item = testWidget->item(i); - testWidget->setItemSelected(item, true); + item->setSelected(true); QVERIFY(item->isSelected()); QCOMPARE(testWidget->selectedItems().count(), 1); } @@ -860,10 +865,10 @@ void tst_QListWidget::selectedItems() QCOMPARE(testWidget->count(), itemCount); // hide items foreach (int row, hiddenRows) - testWidget->setItemHidden(testWidget->item(row), true); + testWidget->item(row)->setHidden(true); // select items foreach (int row, selectedRows) - testWidget->setItemSelected(testWidget->item(row), true); + testWidget->item(row)->setSelected(true); // check that the correct number of items and the expected items are there QList<QListWidgetItem *> selectedItems = testWidget->selectedItems(); @@ -874,7 +879,7 @@ void tst_QListWidget::selectedItems() //check that isSelected agrees with selectedItems for (int i=0; i<itemCount; ++i) { QListWidgetItem *item = testWidget->item(i); - if (testWidget->isItemSelected(item)) + if (item->isSelected()) QVERIFY(selectedItems.contains(item)); } } diff --git a/tests/auto/widgets/itemviews/qtableview/BLACKLIST b/tests/auto/widgets/itemviews/qtableview/BLACKLIST index fc231a4e30..be90475a6f 100644 --- a/tests/auto/widgets/itemviews/qtableview/BLACKLIST +++ b/tests/auto/widgets/itemviews/qtableview/BLACKLIST @@ -1,2 +1,4 @@ [moveCursorBiggerJump] osx +[columnViewportPosition] +winrt # QTBUG-72853 diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index 228d03350a..b1ddc6e7a2 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -1264,19 +1264,47 @@ void tst_QTableView::moveCursorStrikesBack_data() for (int i = 0; i < 7; ++i) fullList << i; - QTest::newRow("All disabled, wrap forward. Timeout => FAIL") << -1 << -1 + QTest::newRow("All disabled, wrap forward. => invalid index") << -1 << -1 << fullList << fullList << QRect() << 1 << 0 << (IntList() << int(QtTestTableView::MoveNext)) - << 1 << 0; + << -1 << -1; - QTest::newRow("All disabled, wrap backwards. Timeout => FAIL") << -1 << -1 + QTest::newRow("All disabled, wrap backwards. => invalid index") << -1 << -1 << fullList << fullList << QRect() << 1 << 0 << (IntList() << int(QtTestTableView::MovePrevious)) + << -1 << -1; + + QTest::newRow("Last column disabled, MoveEnd. QTBUG-72400") << -1 << -1 + << IntList() + << (IntList() << 6) + << QRect() + << 0 << 0 << (IntList() << int(QtTestTableView::MoveEnd)) + << 0 << 5; + + QTest::newRow("First column disabled, MoveHome. QTBUG-72400") << -1 << -1 + << IntList() + << (IntList() << 0) + << QRect() + << 0 << 6 << (IntList() << int(QtTestTableView::MoveHome)) + << 0 << 1; + + QTest::newRow("First row disabled, MovePageUp. QTBUG-72400") << -1 << -1 + << (IntList() << 0) + << IntList() + << QRect() + << 2 << 0 << (IntList() << int(QtTestTableView::MovePageUp)) << 1 << 0; + + QTest::newRow("Last row disabled, MovePageDown. QTBUG-72400") << -1 << -1 + << (IntList() << 6) + << IntList() + << QRect() + << 4 << 0 << (IntList() << int(QtTestTableView::MovePageDown)) + << 5 << 0; } void tst_QTableView::moveCursorStrikesBack() @@ -1302,6 +1330,9 @@ void tst_QTableView::moveCursorStrikesBack() if (span.height() && span.width()) view.setSpan(span.top(), span.left(), span.height(), span.width()); view.show(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + // resize to make sure there are scrollbars + view.resize(view.columnWidth(0) * 7, view.rowHeight(0) * 7); QModelIndex index = model.index(startRow, startColumn); view.setCurrentIndex(index); @@ -1320,9 +1351,6 @@ void tst_QTableView::moveCursorStrikesBack() newColumn = newIndex.column(); } - // expected fails, task 119433 - if(newRow == -1) - return; QCOMPARE(newRow, expectedRow); QCOMPARE(newColumn, expectedColumn); } @@ -4225,7 +4253,7 @@ void tst_QTableView::task234926_setHeaderSorting() QStringList sortedDataA = data; QStringList sortedDataD = data; std::sort(sortedDataA.begin(), sortedDataA.end()); - std::sort(sortedDataD.begin(), sortedDataD.end(), qGreater<QString>()); + std::sort(sortedDataD.begin(), sortedDataD.end(), std::greater<QString>()); model.setStringList(data); QTableView view; view.setModel(&model); diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp index e7b40f5f24..c2de5c2761 100644 --- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp +++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp @@ -91,6 +91,7 @@ private slots: void itemWithHeaderItems(); void mimeData(); void selectedRowAfterSorting(); + void search(); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) void clearItemData(); #endif @@ -164,6 +165,7 @@ void tst_QTableWidget::initTestCase() { testWidget = new QTableWidget(); testWidget->show(); + QApplication::setKeyboardInputInterval(100); } void tst_QTableWidget::cleanupTestCase() @@ -196,10 +198,10 @@ void tst_QTableWidget::clear() { QTableWidgetItem *item = new QTableWidgetItem("foo"); testWidget->setItem(0, 0, item); - testWidget->setItemSelected(item, true); + item->setSelected(true); QVERIFY(testWidget->item(0, 0) == item); - QVERIFY(testWidget->isItemSelected(item)); + QVERIFY(item->isSelected()); QPointer<QObjectTableItem> bla = new QObjectTableItem(); @@ -367,11 +369,18 @@ void tst_QTableWidget::takeItem() for (int c = 0; c < testWidget->columnCount(); ++c) QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c)); + QSignalSpy spy(testWidget, &QTableWidget::cellChanged); QTableWidgetItem *item = testWidget->takeItem(row, column); QCOMPARE(!!item, expectItem); if (expectItem) { QCOMPARE(item->text(), QString::number(row * column + column)); delete item; + + QTRY_COMPARE(spy.count(), 1); + const QList<QVariant> arguments = spy.takeFirst(); + QCOMPARE(arguments.size(), 2); + QCOMPARE(arguments.at(0).toInt(), row); + QCOMPARE(arguments.at(1).toInt(), column); } QVERIFY(!testWidget->takeItem(row, column)); } @@ -576,7 +585,7 @@ void tst_QTableWidget::selectedItems() continue; QTableWidgetItem *item = testWidget->item(row, column); - if (item && testWidget->isItemSelected(item)) + if (item && item->isSelected()) QVERIFY(selectedItems.contains(item)); } } @@ -1558,7 +1567,7 @@ void tst_QTableWidget::task262056_sortDuplicate() } testWidget->sortItems(0, Qt::AscendingOrder); QSignalSpy layoutChangedSpy(testWidget->model(), SIGNAL(layoutChanged())); - testWidget->item(3,0)->setBackgroundColor(Qt::red); + testWidget->item(3,0)->setBackground(Qt::red); QCOMPARE(layoutChangedSpy.count(),0); @@ -1591,6 +1600,7 @@ public: using QTableWidget::mimeData; using QTableWidget::indexFromItem; + using QTableWidget::keyPressEvent; }; void tst_QTableWidget::mimeData() @@ -1665,6 +1675,45 @@ void tst_QTableWidget::selectedRowAfterSorting() } } +void tst_QTableWidget::search() +{ + auto createItem = [](const QString &txt) + { + auto item = new QTableWidgetItem(txt); + item->setFlags(item->flags().setFlag(Qt::ItemIsEditable, false)); + return item; + }; + + auto checkSeries = [](TestTableWidget &tw, const QVector<QPair<QKeyEvent, int>> &series) + { + for (const auto &p : series) { + QKeyEvent e = p.first; + tw.keyPressEvent(&e); + QVERIFY(tw.selectionModel()->isSelected(tw.model()->index(p.second, 0))); + } + }; + TestTableWidget tw(5, 1); + tw.setItem(0, 0, createItem("12")); + tw.setItem(1, 0, createItem("123")); + tw.setItem(2, 0, createItem("123 4")); + tw.setItem(3, 0, createItem("123 5")); + tw.setItem(4, 0, createItem(" ")); + tw.show(); + + QKeyEvent evSpace(QEvent::KeyPress, Qt::Key_Space, Qt::NoModifier, " "); + QKeyEvent ev1(QEvent::KeyPress, Qt::Key_1, Qt::NoModifier, "1"); + QKeyEvent ev2(QEvent::KeyPress, Qt::Key_2, Qt::NoModifier, "2"); + QKeyEvent ev3(QEvent::KeyPress, Qt::Key_3, Qt::NoModifier, "3"); + QKeyEvent ev4(QEvent::KeyPress, Qt::Key_4, Qt::NoModifier, "4"); + QKeyEvent ev5(QEvent::KeyPress, Qt::Key_5, Qt::NoModifier, "5"); + + checkSeries(tw, {{evSpace, 4}, {ev1, 4}}); + QTest::qWait(QApplication::keyboardInputInterval() * 2); + checkSeries(tw, {{ev1, 0}, {ev2, 0}, {ev3, 1}, {evSpace, 2}, {ev5, 3}}); + QTest::qWait(QApplication::keyboardInputInterval() * 2); + checkSeries(tw, {{ev1, 0}, {ev2, 0}, {ev3, 1}, {evSpace, 2}, {ev4, 2}}); +} + #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) void tst_QTableWidget::clearItemData() { diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp index 39051c4969..c31de2ba22 100644 --- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp @@ -69,6 +69,7 @@ public slots: void selectionOrderTest(); private slots: + void initTestCase() { QApplication::setKeyboardInputInterval(100); } void getSetCheck(); // one test per QTreeView property @@ -112,7 +113,7 @@ private slots: void expandAndCollapse(); void expandAndCollapseAll(); void expandWithNoChildren(); -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) void quickExpandCollapse(); #endif void keyboardNavigation(); @@ -199,6 +200,7 @@ private slots: void taskQTBUG_45697_crash(); void taskQTBUG_7232_AllowUserToControlSingleStep(); void taskQTBUG_8376(); + void taskQTBUG_61476(); void testInitialFocus(); }; @@ -1647,50 +1649,96 @@ void tst_QTreeView::expandAndCollapse() } } +static void checkExpandState(const QAbstractItemModel &model, const QTreeView &view, + const QModelIndex &startIdx, bool bIsExpanded, int *count) +{ + *count = 0; + QStack<QModelIndex> parents; + parents.push(startIdx); + if (startIdx.isValid()) { + QCOMPARE(view.isExpanded(startIdx), bIsExpanded); + *count += 1; + } + while (!parents.isEmpty()) { + const QModelIndex p = parents.pop(); + const int rows = model.rowCount(p); + for (int r = 0; r < rows; ++r) { + const QModelIndex c = model.index(r, 0, p); + QCOMPARE(view.isExpanded(c), bIsExpanded); + parents.push(c); + } + *count += rows; + } +} + void tst_QTreeView::expandAndCollapseAll() { - QtTestModel model(3, 2); - model.levels = 2; + QStandardItemModel model; + // QtTestModel has a broken parent/child handling which will break the test + for (int i1 = 0; i1 < 3; ++i1) { + QStandardItem *s1 = new QStandardItem; + s1->setText(QString::number(i1)); + model.appendRow(s1); + for (int i2 = 0; i2 < 3; ++i2) { + QStandardItem *s2 = new QStandardItem; + s2->setText(QStringLiteral("%1 - %2").arg(i1).arg(i2)); + s1->appendRow(s2); + for (int i3 = 0; i3 < 3; ++i3) { + QStandardItem *s3 = new QStandardItem; + s3->setText(QStringLiteral("%1 - %2 - %3").arg(i1).arg(i2).arg(i3)); + s2->appendRow(s3); + } + } + } QTreeView view; view.setUniformRowHeights(true); view.setModel(&model); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); - QSignalSpy expandedSpy(&view, SIGNAL(expanded(QModelIndex))); - QSignalSpy collapsedSpy(&view, SIGNAL(collapsed(QModelIndex))); + QSignalSpy expandedSpy(&view, &QTreeView::expanded); + QSignalSpy collapsedSpy(&view, &QTreeView::collapsed); + int count; view.expandAll(); - view.show(); - + checkExpandState(model, view, QModelIndex(), true, &count); QCOMPARE(collapsedSpy.count(), 0); + QCOMPARE(expandedSpy.count(), 39); // == 3 (first) + 9 (second) + 27 (third level) + QCOMPARE(count, 39); - QStack<QModelIndex> parents; - parents.push(QModelIndex()); - int count = 0; - while (!parents.isEmpty()) { - QModelIndex p = parents.pop(); - int rows = model.rowCount(p); - for (int r = 0; r < rows; ++r) - QVERIFY(view.isExpanded(model.index(r, 0, p))); - count += rows; - for (int r = 0; r < rows; ++r) - parents.push(model.index(r, 0, p)); - } - QCOMPARE(expandedSpy.count(), 12); // == (3+1)*(2+1) from QtTestModel model(3, 2); - + collapsedSpy.clear(); + expandedSpy.clear(); view.collapseAll(); - - parents.push(QModelIndex()); - count = 0; - while (!parents.isEmpty()) { - QModelIndex p = parents.pop(); - int rows = model.rowCount(p); - for (int r = 0; r < rows; ++r) - QVERIFY(!view.isExpanded(model.index(r, 0, p))); - count += rows; - for (int r = 0; r < rows; ++r) - parents.push(model.index(r, 0, p)); - } - QCOMPARE(collapsedSpy.count(), 12); + checkExpandState(model, view, QModelIndex(), false, &count); + QCOMPARE(collapsedSpy.count(), 39); + QCOMPARE(expandedSpy.count(), 0); + QCOMPARE(count, 39); + + collapsedSpy.clear(); + expandedSpy.clear(); + view.expandRecursively(model.index(0, 0)); + QCOMPARE(expandedSpy.count(), 13); // 1 + 3 + 9 + + checkExpandState(model, view, model.index(0, 0), true, &count); + QCOMPARE(count, 13); + checkExpandState(model, view, model.index(1, 0), false, &count); + QCOMPARE(count, 13); + checkExpandState(model, view, model.index(2, 0), false, &count); + QCOMPARE(count, 13); + + expandedSpy.clear(); + view.collapseAll(); + view.expandRecursively(model.index(0, 0), 1); + QCOMPARE(expandedSpy.count(), 4); // 1 + 3 + view.expandRecursively(model.index(0, 0), 2); + QCOMPARE(expandedSpy.count(), 13); // (1 + 3) + 9 + + checkExpandState(model, view, model.index(0, 0), true, &count); + QCOMPARE(count, 13); + checkExpandState(model, view, model.index(1, 0), false, &count); + QCOMPARE(count, 13); + checkExpandState(model, view, model.index(2, 0), false, &count); + QCOMPARE(count, 13); } void tst_QTreeView::expandWithNoChildren() @@ -1749,7 +1797,7 @@ void tst_QTreeView::keyboardNavigation() case Qt::Key_Down: if (view.isExpanded(index)) { row = 0; - index = index.child(row, column); + index = model.index(row, column, index); } else { row = qMin(rows - 1, row + 1); index = index.sibling(row, column); @@ -2746,7 +2794,7 @@ void tst_QTreeView::sortByColumn() view.setSortingEnabled(sortingEnabled); view.setModel(&model); - view.sortByColumn(1); + view.sortByColumn(1, Qt::DescendingOrder); QCOMPARE(view.header()->sortIndicatorSection(), 1); QCOMPARE(view.model()->data(view.model()->index(0,1)).toString(), QString::fromLatin1("h")); QCOMPARE(view.model()->data(view.model()->index(1,1)).toString(), QString::fromLatin1("g")); @@ -3056,7 +3104,7 @@ void tst_QTreeView::evilModel() view.resizeColumnToContents(1); model.change(); - view.sortByColumn(1); + view.sortByColumn(1, Qt::DescendingOrder); model.change(); view.selectAll(); @@ -3900,7 +3948,7 @@ void tst_QTreeView::task254234_proxySort() model.setItem(2,1,new QStandardItem("h")); model.setItem(3,1,new QStandardItem("f")); - view.sortByColumn(1); + view.sortByColumn(1, Qt::DescendingOrder); view.setSortingEnabled(true); QSortFilterProxyModel proxy; @@ -4088,6 +4136,30 @@ void tst_QTreeView::keyboardNavigationWithDisabled() QCOMPARE(view.currentIndex(), model.index(12, 0)); QTest::keyClick(view.viewport(), Qt::Key_Up); QCOMPARE(view.currentIndex(), model.index(6, 0)); + // QTBUG-44746 - when first/last item is disabled, + // Key_PageUp/Down/Home/End will not work as expected. + model.item(0)->setEnabled(false); + model.item(1)->setEnabled(true); + model.item(2)->setEnabled(true); + model.item(model.rowCount() - 1)->setEnabled(false); + model.item(model.rowCount() - 2)->setEnabled(true); + model.item(model.rowCount() - 3)->setEnabled(true); + // PageUp + view.setCurrentIndex(model.index(2, 0)); + QCOMPARE(view.currentIndex(), model.index(2, 0)); + QTest::keyClick(view.viewport(), Qt::Key_PageUp); + QCOMPARE(view.currentIndex(), model.index(1, 0)); + // PageDown + view.setCurrentIndex(model.index(model.rowCount() - 3, 0)); + QCOMPARE(view.currentIndex(), model.index(model.rowCount() - 3, 0)); + QTest::keyClick(view.viewport(), Qt::Key_PageDown); + QCOMPARE(view.currentIndex(), model.index(model.rowCount() - 2, 0)); + // Key_Home + QTest::keyClick(view.viewport(), Qt::Key_Home); + QCOMPARE(view.currentIndex(), model.index(1, 0)); + // Key_End + QTest::keyClick(view.viewport(), Qt::Key_End); + QCOMPARE(view.currentIndex(), model.index(model.rowCount() - 2, 0)); } class RemoveColumnOne : public QSortFilterProxyModel @@ -4419,7 +4491,7 @@ void tst_QTreeView::testInitialFocus() QCOMPARE(treeWidget.currentIndex().column(), 2); } -#ifndef QT_NO_ANIMATION +#if QT_CONFIG(animation) void tst_QTreeView::quickExpandCollapse() { //this unit tests makes sure the state after the animation is restored correctly @@ -4451,7 +4523,7 @@ void tst_QTreeView::quickExpandCollapse() QCOMPARE(tree.state(), initialState); } -#endif +#endif // animation void tst_QTreeView::taskQTBUG_37813_crash() { @@ -4735,5 +4807,58 @@ void tst_QTreeView::taskQTBUG_8376() QCOMPARE(rowHeightLvl1Visible, rowHeightLvl1Visible2); } +void tst_QTreeView::taskQTBUG_61476() +{ + // This checks that if a user clicks on an item to collapse it that it + // does not edit (in this case change the check state) the item that is + // now over the mouse just because it got a release event + QTreeView tv; + QStandardItemModel model; + QStandardItem *lastTopLevel = nullptr; + { + for (int i = 0; i < 4; ++i) { + QStandardItem *item = new QStandardItem(QLatin1String("Row Item")); + item->setCheckable(true); + item->setCheckState(Qt::Checked); + model.appendRow(item); + lastTopLevel = item; + for (int j = 0; j < 2; ++j) { + QStandardItem *childItem = new QStandardItem(QLatin1String("Child row Item")); + childItem->setCheckable(true); + childItem->setCheckState(Qt::Checked); + item->appendRow(childItem); + QStandardItem *grandChild = new QStandardItem(QLatin1String("Grand child row Item")); + grandChild->setCheckable(true); + grandChild->setCheckState(Qt::Checked); + childItem->appendRow(grandChild); + } + } + } + tv.setModel(&model); + tv.expandAll(); + // We need it to be this size so that the effect of the collapsing will + // cause the parent item to move to be under the cursor + tv.resize(200, 200); + tv.show(); + QVERIFY(QTest::qWaitForWindowActive(&tv)); + tv.verticalScrollBar()->setValue(tv.verticalScrollBar()->maximum()); + + // We want to press specifically right around where a checkbox for the + // parent item could be when collapsing + QTreeViewPrivate *priv = static_cast<QTreeViewPrivate*>(qt_widget_private(&tv)); + const QModelIndex mi = lastTopLevel->child(0)->index(); + const QRect rect = priv->itemDecorationRect(mi); + const QPoint pos = rect.center(); + + QTest::mousePress(tv.viewport(), Qt::LeftButton, 0, pos); + if (tv.style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, 0, &tv) == + QEvent::MouseButtonPress) + QTRY_VERIFY(!tv.isExpanded(mi)); + + QTest::mouseRelease(tv.viewport(), Qt::LeftButton, 0, pos); + QTRY_VERIFY(!tv.isExpanded(mi)); + QCOMPARE(lastTopLevel->checkState(), Qt::Checked); +} + QTEST_MAIN(tst_QTreeView) #include "tst_qtreeview.moc" diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp index c5ccbc0d0b..33d4f3bf91 100644 --- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp @@ -99,6 +99,7 @@ private slots: void insertTopLevelItems_data(); void insertTopLevelItems(); void keyboardNavigation(); + void keyboardNavigationWithHidden(); void scrollToItem(); void setSortingEnabled(); void match(); @@ -140,6 +141,7 @@ private slots: void expandAndCallapse(); void itemData(); void setDisabled(); + void setSpanned(); void removeSelectedItem(); void removeCurrentItem(); void removeCurrentItem_task186451(); @@ -608,31 +610,31 @@ void tst_QTreeWidget::setItemHidden() QVERIFY(testWidget->visualItemRect(child).isValid() && testWidget->viewport()->rect().intersects(testWidget->visualItemRect(child))); - QVERIFY(!testWidget->isItemHidden(parent)); - QVERIFY(!testWidget->isItemHidden(child)); + QVERIFY(!parent->isHidden()); + QVERIFY(!child->isHidden()); - testWidget->setItemHidden(parent, true); + parent->setHidden(true); QVERIFY(!(testWidget->visualItemRect(parent).isValid() && testWidget->viewport()->rect().intersects(testWidget->visualItemRect(parent)))); QVERIFY(!(testWidget->visualItemRect(child).isValid() && testWidget->viewport()->rect().intersects(testWidget->visualItemRect(child)))); - QVERIFY(testWidget->isItemHidden(parent)); - QVERIFY(!testWidget->isItemHidden(child)); + QVERIFY(parent->isHidden()); + QVERIFY(!child->isHidden()); // From task 78670 (This caused an core dump) // Check if we can set an item visible if it already is visible. - testWidget->setItemHidden(parent, false); - testWidget->setItemHidden(parent, false); - QVERIFY(!testWidget->isItemHidden(parent)); + parent->setHidden(false); + parent->setHidden(false); + QVERIFY(!parent->isHidden()); // hide, hide and then unhide. - testWidget->setItemHidden(parent, true); - testWidget->setItemHidden(parent, true); - testWidget->setItemHidden(parent, false); - QVERIFY(!testWidget->isItemHidden(parent)); + parent->setHidden(true); + parent->setHidden(true); + parent->setHidden(false); + QVERIFY(!parent->isHidden()); } @@ -658,7 +660,7 @@ void tst_QTreeWidget::setItemHidden2() if (testWidget->topLevelItemCount() > 0) { top = testWidget->topLevelItem(0); - testWidget->setItemExpanded(top, true); + top->setExpanded(true); } if (testWidget->topLevelItemCount() > 0) { @@ -666,8 +668,8 @@ void tst_QTreeWidget::setItemHidden2() for (int i = 0; i < top->childCount(); i++) { leaf = top->child(i); if (leaf->text(0).toInt() % 2 == 0) { - if (!testWidget->isItemHidden(leaf)) { - testWidget->setItemHidden(leaf, true); + if (!leaf->isHidden()) { + leaf->setHidden(true); } } } @@ -821,7 +823,7 @@ void tst_QTreeWidget::selectedItems() else item = item->child(index); } - testWidget->setItemSelected(item, true); + item->setSelected(true); } // hide rows @@ -833,7 +835,7 @@ void tst_QTreeWidget::selectedItems() else item = item->child(index); } - testWidget->setItemHidden(item, true); + item->setHidden(true); } // open/close toplevel @@ -862,18 +864,23 @@ void tst_QTreeWidget::selectedItems() // compare isSelected for (int t=0; t<testWidget->topLevelItemCount(); ++t) { QTreeWidgetItem *top = testWidget->topLevelItem(t); - if (testWidget->isItemSelected(top) && !testWidget->isItemHidden(top)) + if (top->isSelected() && !top->isHidden()) QVERIFY(sel.contains(top)); for (int c=0; c<top->childCount(); ++c) { QTreeWidgetItem *child = top->child(c); - if (testWidget->isItemSelected(child) && !testWidget->isItemHidden(child)) + if (child->isSelected() && !child->isHidden()) QVERIFY(sel.contains(child)); } } +#if QT_DEPRECATED_SINCE(5, 13) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED // Possible to select null without crashing? - testWidget->setItemSelected(0, true); - QVERIFY(!testWidget->isItemSelected(0)); + testWidget->setItemSelected(nullptr, true); + QVERIFY(!testWidget->isItemSelected(nullptr)); +QT_WARNING_POP +#endif // unselect foreach (IntList itemPath, selectedItems) { @@ -884,7 +891,7 @@ void tst_QTreeWidget::selectedItems() else item = item->child(index); } - testWidget->setItemSelected(item, false); + item->setSelected(false); } QCOMPARE(testWidget->selectedItems().count(), 0); } @@ -1010,21 +1017,21 @@ void tst_QTreeWidget::expand() QTreeWidgetItem *topLevelItem = testWidget->topLevelItem(topLevelIndex); QTreeWidgetItem *childItem = topLevelItem->child(childIndex); - QVERIFY(!testWidget->isItemExpanded(topLevelItem)); - testWidget->setItemExpanded(topLevelItem, true); - QVERIFY(testWidget->isItemExpanded(topLevelItem)); + QVERIFY(!topLevelItem->isExpanded()); + topLevelItem->setExpanded(true); + QVERIFY(topLevelItem->isExpanded()); - QVERIFY(!testWidget->isItemExpanded(childItem)); - testWidget->setItemExpanded(childItem, true); - QVERIFY(testWidget->isItemExpanded(childItem)); + QVERIFY(!childItem->isExpanded()); + childItem->setExpanded(true); + QVERIFY(childItem->isExpanded()); - QVERIFY(testWidget->isItemExpanded(topLevelItem)); - testWidget->setItemExpanded(topLevelItem, false); - QVERIFY(!testWidget->isItemExpanded(topLevelItem)); + QVERIFY(topLevelItem->isExpanded()); + topLevelItem->setExpanded(false); + QVERIFY(!topLevelItem->isExpanded()); - QVERIFY(testWidget->isItemExpanded(childItem)); - testWidget->setItemExpanded(childItem, false); - QVERIFY(!testWidget->isItemExpanded(childItem)); + QVERIFY(childItem->isExpanded()); + childItem->setExpanded(false); + QVERIFY(!childItem->isExpanded()); } void tst_QTreeWidget::checkState_data() @@ -1525,7 +1532,7 @@ void tst_QTreeWidget::keyboardNavigation() } break; case Qt::Key_Down: - if (testWidget->isItemExpanded(item)) { + if (item->isExpanded()) { row = 0; item = item->child(row); } else { @@ -1538,7 +1545,7 @@ void tst_QTreeWidget::keyboardNavigation() break; case Qt::Key_Left: if (checkScroll) { - QVERIFY(testWidget->isItemExpanded(item)); + QVERIFY(item->isExpanded()); QCOMPARE(scrollBar->value(), valueBeforeClick - scrollBar->singleStep()); } // windows style right will walk to the parent @@ -1572,6 +1579,33 @@ void tst_QTreeWidget::keyboardNavigation() } } +void tst_QTreeWidget::keyboardNavigationWithHidden() +{ + QTreeWidget tw; + for (int i = 0; i < 1000; ++i) + tw.addTopLevelItem(new QTreeWidgetItem({QString::number(i), QStringLiteral("second col")})); + // QTBUG-34832 - when first/last item is hidden, + // Key_PageUp/Down/Home/End will not work as expected. + tw.topLevelItem(0)->setHidden(true); + tw.topLevelItem(tw.model()->rowCount() - 1)->setHidden(true); + // PageUp + tw.setCurrentIndex(tw.model()->index(2, 0)); + QCOMPARE(tw.currentIndex(), tw.model()->index(2, 0)); + QTest::keyClick(tw.viewport(), Qt::Key_PageUp); + QCOMPARE(tw.currentIndex(), tw.model()->index(1, 0)); + // PageDown + tw.setCurrentIndex(tw.model()->index(tw.model()->rowCount() - 3, 0)); + QCOMPARE(tw.currentIndex(), tw.model()->index(tw.model()->rowCount() - 3, 0)); + QTest::keyClick(tw.viewport(), Qt::Key_PageDown); + QCOMPARE(tw.currentIndex(), tw.model()->index(tw.model()->rowCount() - 2, 0)); + // Key_Home + QTest::keyClick(tw.viewport(), Qt::Key_Home); + QCOMPARE(tw.currentIndex(), tw.model()->index(1, 0)); + // Key_End + QTest::keyClick(tw.viewport(), Qt::Key_End); + QCOMPARE(tw.currentIndex(), tw.model()->index(tw.model()->rowCount() - 2, 0)); +} + void tst_QTreeWidget::scrollToItem() { // Check if all parent nodes of the item found are expanded. @@ -1597,9 +1631,9 @@ void tst_QTreeWidget::scrollToItem() QCOMPARE(search->text(0), QLatin1String("111")); QTreeWidgetItem *par = search->parent(); - QVERIFY(testWidget->isItemExpanded(par)); + QVERIFY(par->isExpanded()); par = par->parent(); - QVERIFY(testWidget->isItemExpanded(par)); + QVERIFY(par->isExpanded()); } // From task #85413 @@ -1845,14 +1879,14 @@ void tst_QTreeWidget::setData() item->setBackground(j, backgroundColor); QCOMPARE(itemChangedSpy.count(), 0); - QColor textColor((i == 1) ? Qt::green : Qt::cyan); - item->setTextColor(j, textColor); - QCOMPARE(item->textColor(j), textColor); + const QColor foregroundColor((i == 1) ? Qt::green : Qt::cyan); + item->setForeground(j, foregroundColor); + QCOMPARE(item->foreground(j), foregroundColor); QCOMPARE(itemChangedSpy.count(), 1); args = itemChangedSpy.takeFirst(); QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); QCOMPARE(qvariant_cast<int>(args.at(1)), j); - item->setTextColor(j, textColor); + item->setForeground(j, foregroundColor); QCOMPARE(itemChangedSpy.count(), 0); Qt::CheckState checkState((i == 1) ? Qt::PartiallyChecked : Qt::Checked); @@ -1874,7 +1908,7 @@ void tst_QTreeWidget::setData() QCOMPARE(item->font(j), font); QCOMPARE(item->textAlignment(j), int(textAlignment)); QCOMPARE(item->background(j).color(), backgroundColor); - QCOMPARE(item->textColor(j), textColor); + QCOMPARE(item->foreground(j), foregroundColor); QCOMPARE(item->checkState(j), checkState); QCOMPARE(qvariant_cast<QString>(item->data(j, Qt::DisplayRole)), text); @@ -1885,9 +1919,8 @@ void tst_QTreeWidget::setData() QCOMPARE(qvariant_cast<QSize>(item->data(j, Qt::SizeHintRole)), sizeHint); QCOMPARE(qvariant_cast<QFont>(item->data(j, Qt::FontRole)), font); QCOMPARE(qvariant_cast<int>(item->data(j, Qt::TextAlignmentRole)), int(textAlignment)); - QCOMPARE(qvariant_cast<QBrush>(item->data(j, Qt::BackgroundColorRole)), QBrush(backgroundColor)); QCOMPARE(qvariant_cast<QBrush>(item->data(j, Qt::BackgroundRole)), QBrush(backgroundColor)); - QCOMPARE(qvariant_cast<QColor>(item->data(j, Qt::TextColorRole)), textColor); + QCOMPARE(qvariant_cast<QColor>(item->data(j, Qt::ForegroundRole)), foregroundColor); QCOMPARE(qvariant_cast<int>(item->data(j, Qt::CheckStateRole)), int(checkState)); item->setBackground(j, pixmap); @@ -1907,8 +1940,8 @@ void tst_QTreeWidget::setData() item->setData(j, Qt::SizeHintRole, QVariant()); item->setData(j, Qt::FontRole, QVariant()); item->setData(j, Qt::TextAlignmentRole, QVariant()); - item->setData(j, Qt::BackgroundColorRole, QVariant()); - item->setData(j, Qt::TextColorRole, QVariant()); + item->setData(j, Qt::BackgroundRole, QVariant()); + item->setData(j, Qt::ForegroundRole, QVariant()); item->setData(j, Qt::CheckStateRole, QVariant()); QCOMPARE(itemChangedSpy.count(), 11); itemChangedSpy.clear(); @@ -1921,9 +1954,8 @@ void tst_QTreeWidget::setData() QCOMPARE(item->data(j, Qt::SizeHintRole), QVariant()); QCOMPARE(item->data(j, Qt::FontRole), QVariant()); QCOMPARE(item->data(j, Qt::TextAlignmentRole), QVariant()); - QCOMPARE(item->data(j, Qt::BackgroundColorRole), QVariant()); QCOMPARE(item->data(j, Qt::BackgroundRole), QVariant()); - QCOMPARE(item->data(j, Qt::TextColorRole), QVariant()); + QCOMPARE(item->data(j, Qt::ForegroundRole), QVariant()); QCOMPARE(item->data(j, Qt::CheckStateRole), QVariant()); } } @@ -2818,6 +2850,28 @@ void tst_QTreeWidget::setDisabled() QCOMPARE(takenChildren.items[1]->isDisabled(), false); } +void tst_QTreeWidget::setSpanned() +{ + QTreeWidget w; + QTreeWidgetItem *i1 = new QTreeWidgetItem(); + QScopedPointer<QTreeWidgetItem> i2(new QTreeWidgetItem()); + + QTreeWidgetItem *top = new QTreeWidgetItem(&w); + top->addChild(i1); + + top->setFirstColumnSpanned(true); + QCOMPARE(top->isFirstColumnSpanned(), true); + QCOMPARE(i1->isFirstColumnSpanned(), false); + QCOMPARE(i2->isFirstColumnSpanned(), false); + + top->setFirstColumnSpanned(false); + i1->setFirstColumnSpanned(true); + i2->setFirstColumnSpanned(true); + QCOMPARE(top->isFirstColumnSpanned(), false); + QCOMPARE(i1->isFirstColumnSpanned(), true); + QCOMPARE(i2->isFirstColumnSpanned(), false); +} + void tst_QTreeWidget::removeSelectedItem() { const QScopedPointer <QTreeWidget> w(new QTreeWidget); @@ -2919,14 +2973,14 @@ void tst_QTreeWidget::randomExpand() QTreeWidgetItem *newItem1 = 0; for (int i = 0; i < 100; i++) { newItem1 = new QTreeWidgetItem(&tree, item1); - tree.setItemExpanded(newItem1, true); - QCOMPARE(tree.isItemExpanded(newItem1), true); + newItem1->setExpanded(true); + QCOMPARE(newItem1->isExpanded(), true); QTreeWidgetItem *x = new QTreeWidgetItem(); - QCOMPARE(tree.isItemExpanded(newItem1), true); + QCOMPARE(newItem1->isExpanded(), true); newItem1->addChild(x); - QCOMPARE(tree.isItemExpanded(newItem1), true); + QCOMPARE(newItem1->isExpanded(), true); } } @@ -2939,19 +2993,19 @@ void tst_QTreeWidget::crashTest() QTreeWidgetItem *item1 = new QTreeWidgetItem(tree); item1->setText(0, "item1"); - tree->setItemExpanded(item1, true); + item1->setExpanded(true); QTreeWidgetItem *item2 = new QTreeWidgetItem(item1); item2->setText(0, "item2"); QTreeWidgetItem *item3 = new QTreeWidgetItem(tree, item1); item3->setText(0, "item3"); - tree->setItemExpanded(item3, true); + item3->setExpanded(true); QTreeWidgetItem *item4 = new QTreeWidgetItem(item3); item4->setText(0, "item4"); QTreeWidgetItem *item5 = new QTreeWidgetItem(tree, item3); item5->setText(0, "item5"); - tree->setItemExpanded(item5, true); + item5->setExpanded(true); QTreeWidgetItem *item6 = new QTreeWidgetItem(item5); item6->setText(0, "item6"); @@ -3417,6 +3471,7 @@ void tst_QTreeWidget::setChildIndicatorPolicy() treeWidget.setItemDelegate(&delegate); treeWidget.show(); QVERIFY(QTest::qWaitForWindowExposed(&treeWidget)); + QCoreApplication::processEvents(); // Process all queued paint events QTreeWidgetItem *item = new QTreeWidgetItem(QStringList("Hello")); treeWidget.insertTopLevelItem(0, item); diff --git a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp index c2c02f3766..76ca148d3f 100644 --- a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp +++ b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp @@ -95,11 +95,11 @@ void tst_QTreeWidgetItemIterator::initTestCase() const QString topS = QLatin1String("top") + QString::number(i); top->setText(0, topS); switch (i) { - case 0: testWidget->setItemHidden(top, true);break; - case 1: testWidget->setItemHidden(top, false);break; + case 0: top->setHidden(true);break; + case 1: top->setHidden(false);break; - case 2: testWidget->setItemSelected(top, true);break; - case 3: testWidget->setItemSelected(top, false);break; + case 2: top->setSelected(true);break; + case 3: top->setSelected(false);break; case 4: top->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);break; case 5: top->setFlags(Qt::ItemIsEnabled);break; @@ -126,11 +126,11 @@ void tst_QTreeWidgetItemIterator::initTestCase() QTreeWidgetItem *child = new QTreeWidgetItem(top); child->setText(0, topS + QLatin1String(",child") + QString::number(j)); switch (j) { - case 0: testWidget->setItemHidden(child, true);break; - case 1: testWidget->setItemHidden(child, false);break; + case 0: child->setHidden(true);break; + case 1: child->setHidden(false);break; - case 2: testWidget->setItemSelected(child, true);break; - case 3: testWidget->setItemSelected(child, false);break; + case 2: child->setSelected(true);break; + case 3: child->setSelected(false);break; case 4: child->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);break; case 5: child->setFlags(Qt::ItemIsEnabled);break; diff --git a/tests/auto/widgets/kernel/kernel.pro b/tests/auto/widgets/kernel/kernel.pro index 0382264eb8..15fcf99765 100644 --- a/tests/auto/widgets/kernel/kernel.pro +++ b/tests/auto/widgets/kernel/kernel.pro @@ -22,5 +22,3 @@ SUBDIRS=\ darwin:SUBDIRS -= \ qgesturerecognizer \ - -SUBDIRS -= qsound diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index d06baed322..e57ac77c39 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -360,8 +360,8 @@ void tst_QApplication::setFont_data() int cnt = 0; QFontDatabase fdb; QStringList families = fdb.families(); - for (QStringList::const_iterator itr = families.begin(); - itr != families.end(); + for (QStringList::const_iterator itr = families.cbegin(); + itr != families.cend(); ++itr) { if (cnt < 3) { QString family = *itr; @@ -2200,8 +2200,6 @@ void tst_QApplication::abortQuitOnShow() void tst_QApplication::staticFunctions() { QApplication::setStyle(QStringLiteral("blub")); - QApplication::colorSpec(); - QApplication::setColorSpec(42); QApplication::allWidgets(); QApplication::topLevelWidgets(); QApplication::desktop(); diff --git a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp index b2650d1f32..fa9769a002 100644 --- a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp +++ b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp @@ -47,6 +47,7 @@ private slots: void sizeConstraints(); void setGeometry(); void setStyleShouldChangeSpacing(); + void widgetSurplus(); void testLayoutEngine_data(); void testLayoutEngine(); @@ -236,6 +237,69 @@ void tst_QBoxLayout::setStyleShouldChangeSpacing() QTRY_COMPARE(spacing(), 10); } +class MarginEatingStyle : public QProxyStyle +{ +public: + MarginEatingStyle() : QProxyStyle(QStyleFactory::create("windows")) + { + } + + virtual QRect subElementRect(SubElement sr, const QStyleOption *opt, + const QWidget *widget) const + { + QRect rect = opt->rect; + switch (sr) { + case SE_GroupBoxLayoutItem: + // this is a simplifed version of what the macOS style does + rect.setTop(rect.top() + 20); + rect.setLeft(rect.left() + 20); + rect.setRight(rect.right() - 20); + rect.setBottom(rect.bottom() - 20); + break; + default: + return QProxyStyle::subElementRect(sr, opt, widget); + } + + return rect; + } +}; + +void tst_QBoxLayout::widgetSurplus() +{ + // Test case for QTBUG-67608 - a style requests space in the margin + + QDialog window; + QScopedPointer<MarginEatingStyle> marginEater(new MarginEatingStyle); + QVBoxLayout *vbox = new QVBoxLayout(&window); + vbox->setMargin(0); + vbox->setSpacing(0); + + QLabel *hiddenLabel = new QLabel(tr("Invisible label")); + hiddenLabel->setVisible(false); + + QGroupBox *groupBox = new QGroupBox(tr("Groupbox Title")); + groupBox->setStyle(marginEater.data()); + groupBox->setObjectName("Test group box"); + QPushButton *button1 = new QPushButton(tr("Button 1")); + QPushButton *button2 = new QPushButton(tr("Button 2")); + QVBoxLayout *groupLayout = new QVBoxLayout; + groupLayout->addWidget(button1); + groupLayout->addWidget(button2); + groupBox->setLayout(groupLayout); + + QLabel *label = new QLabel(tr("Visible label")); + + vbox->addWidget(hiddenLabel); + vbox->addWidget(groupBox); + vbox->addWidget(label); + window.setLayout(vbox); + + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QCOMPARE(groupBox->y(), 0); + QCOMPARE(groupBox->x(), 0); +} + void tst_QBoxLayout::taskQTBUG_7103_minMaxWidthNotRespected() { QLabel *label = new QLabel("Qt uses standard C++, but makes extensive use of the C pre-processor to enrich the language. Qt can also be used in several other programming languages via language bindings. It runs on all major platforms, and has extensive internationalization support. Non-GUI features include SQL database access, XML parsing, thread management, network support and a unified cross-platform API for file handling."); diff --git a/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp b/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp index 6f2847974f..90776dfcb2 100644 --- a/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp +++ b/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp @@ -32,6 +32,9 @@ #include <QtGui/QWindow> #include <QDebug> +// the complete class is deprecated +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED class tst_QDesktopWidget : public QObject { Q_OBJECT @@ -163,7 +166,7 @@ void tst_QDesktopWidget::topLevels() QCOMPARE(topLevelDesktopWidgets, 0); QCOMPARE(topLevelDesktopWindows, 0); } +QT_WARNING_POP QTEST_MAIN(tst_QDesktopWidget) #include "tst_qdesktopwidget.moc" - diff --git a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp index cff3dad35e..ab32643061 100644 --- a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp +++ b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp @@ -52,7 +52,7 @@ using namespace QTestPrivate; Q_CONSTEXPR QFormLayout::ItemRole invalidRole = QFormLayout::ItemRole(3); struct QFormLayoutTakeRowResultHolder { - QFormLayoutTakeRowResultHolder(QFormLayout::TakeRowResult result) Q_DECL_NOTHROW + QFormLayoutTakeRowResultHolder(QFormLayout::TakeRowResult result) noexcept : labelItem(result.labelItem), fieldItem(result.fieldItem) { @@ -66,20 +66,20 @@ struct QFormLayoutTakeRowResultHolder { if (fieldItem) disposer.setItem(0, QFormLayout::FieldRole, fieldItem); } - QFormLayoutTakeRowResultHolder(QFormLayoutTakeRowResultHolder &&other) Q_DECL_NOTHROW + QFormLayoutTakeRowResultHolder(QFormLayoutTakeRowResultHolder &&other) noexcept : labelItem(other.labelItem), fieldItem(other.fieldItem) { other.labelItem = nullptr; other.fieldItem = nullptr; } - QFormLayoutTakeRowResultHolder &operator=(QFormLayoutTakeRowResultHolder &&other) Q_DECL_NOTHROW + QFormLayoutTakeRowResultHolder &operator=(QFormLayoutTakeRowResultHolder &&other) noexcept { swap(other); return *this; } - void swap(QFormLayoutTakeRowResultHolder &other) Q_DECL_NOTHROW + void swap(QFormLayoutTakeRowResultHolder &other) noexcept { qSwap(labelItem, other.labelItem); qSwap(fieldItem, other.fieldItem); diff --git a/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp b/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp index e02573f8e8..3d609d0b9c 100644 --- a/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp +++ b/tests/auto/widgets/kernel/qtooltip/tst_qtooltip.cpp @@ -46,6 +46,7 @@ private slots: void whatsThis(); void setPalette(); void qtbug64550_stylesheet(); + void dontCrashOutsideScreenGeometry(); }; void tst_QToolTip::init() @@ -218,5 +219,11 @@ void tst_QToolTip::qtbug64550_stylesheet() msgSizeTooSmall(toolTipSize, boundingRect.size()).constData()); } +void tst_QToolTip::dontCrashOutsideScreenGeometry() { + QToolTip::showText(QPoint(-10000, -10000), "tip outside monitor", nullptr); + QTRY_VERIFY(QToolTip::isVisible()); + QToolTip::hideText(); +} + QTEST_MAIN(tst_QToolTip) #include "tst_qtooltip.moc" diff --git a/tests/auto/widgets/kernel/qwidget/BLACKLIST b/tests/auto/widgets/kernel/qwidget/BLACKLIST index d8654e5768..3287d67875 100644 --- a/tests/auto/widgets/kernel/qwidget/BLACKLIST +++ b/tests/auto/widgets/kernel/qwidget/BLACKLIST @@ -10,6 +10,7 @@ osx ubuntu-16.04 ubuntu-18.04 rhel-7.4 +rhel-7.6 osx [focusProxyAndInputMethods] linux @@ -32,7 +33,6 @@ osx [render_systemClip] osx [showMinimizedKeepsFocus] -osx-10.11 ci osx-10.12 ci osx-10.13 ci [maskedUpdate] diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 67b326e7ee..0ac8ccdbe7 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -166,6 +166,7 @@ private slots: void getSetCheck(); void fontPropagation(); void fontPropagation2(); + void fontPropagation3(); void palettePropagation(); void palettePropagation2(); void enabledPropagation(); @@ -320,7 +321,9 @@ private slots: void setMaskInResizeEvent(); void moveInResizeEvent(); - void immediateRepaintAfterInvalidateBuffer(); +#ifdef QT_BUILD_INTERNAL + void immediateRepaintAfterInvalidateBackingStore(); +#endif void effectiveWinId(); void effectiveWinId2(); @@ -819,6 +822,18 @@ void tst_QWidget::fontPropagation2() QVERIFY(child5->font().italic()); } +void tst_QWidget::fontPropagation3() +{ + QWidget parent; + QWidget *child = new QWidget(&parent); + parent.setFont(QFont("Monospace", 9)); + QImage image(32, 32, QImage::Format_RGB32); + QPainter p(&image); + p.setFont(child->font()); + QCOMPARE(p.font().family(), child->font().family()); + QCOMPARE(p.font().pointSize(), child->font().pointSize()); +} + void tst_QWidget::palettePropagation() { QScopedPointer<QWidget> testWidget(new QWidget); @@ -6131,7 +6146,11 @@ public: return false; } +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + bool nativeEvent(const QByteArray &eventType, void *message, qintptr *) override +#else bool nativeEvent(const QByteArray &eventType, void *message, long *) override +#endif { if (isMapNotify(eventType, message)) gotExpectedMapNotify = true; @@ -6139,7 +6158,11 @@ public: } // QAbstractNativeEventFilter interface +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *) override +#else bool nativeEventFilter(const QByteArray &eventType, void *message, long *) override +#endif { if (isMapNotify(eventType, message)) gotExpectedGlobalEvent = true; @@ -8202,7 +8225,7 @@ void tst_QWidget::resizeInPaintEvent() widget.resizeInPaintEvent = true; // This will call resize in the paintEvent, which in turn will call - // invalidateBuffer() and a new update request should be posted. + // invalidateBackingStore() and a new update request should be posted. widget.repaint(); QCOMPARE(widget.numPaintEvents, 1); widget.numPaintEvents = 0; @@ -8357,7 +8380,8 @@ void tst_QWidget::moveInResizeEvent() QTRY_COMPARE(testWidget.geometry(), expectedGeometry); } -void tst_QWidget::immediateRepaintAfterInvalidateBuffer() +#ifdef QT_BUILD_INTERNAL +void tst_QWidget::immediateRepaintAfterInvalidateBackingStore() { if (m_platform != QStringLiteral("xcb") && m_platform != QStringLiteral("windows")) QSKIP("We don't support immediate repaint right after show on other platforms."); @@ -8371,7 +8395,7 @@ void tst_QWidget::immediateRepaintAfterInvalidateBuffer() // Marks the area covered by the widget as dirty in the backing store and // posts an UpdateRequest event. - qt_widget_private(widget.data())->invalidateBuffer(widget->rect()); + qt_widget_private(widget.data())->invalidateBackingStore(widget->rect()); QCOMPARE(widget->numPaintEvents, 0); // The entire widget is already dirty, but this time we want to update immediately @@ -8380,6 +8404,7 @@ void tst_QWidget::immediateRepaintAfterInvalidateBuffer() widget->repaint(); QCOMPARE(widget->numPaintEvents, 1); } +#endif void tst_QWidget::effectiveWinId() { @@ -9422,7 +9447,7 @@ QWidgetBackingStore* backingStore(QWidget &widget) void tst_QWidget::rectOutsideCoordinatesLimit_task144779() { #ifndef QT_NO_CURSOR - QApplication::setOverrideCursor(Qt::BlankCursor); //keep the cursor out of screen grabs + QGuiApplication::setOverrideCursor(Qt::BlankCursor); //keep the cursor out of screen grabs #endif QWidget main(0,Qt::FramelessWindowHint); //don't get confused by the size of the window frame QPalette palette; @@ -9459,7 +9484,7 @@ void tst_QWidget::rectOutsideCoordinatesLimit_task144779() QTRY_COMPARE(mainPixmap.toImage().convertToFormat(QImage::Format_RGB32), correct.toImage().convertToFormat(QImage::Format_RGB32)); #ifndef QT_NO_CURSOR - QApplication::restoreOverrideCursor(); + QGuiApplication::restoreOverrideCursor(); #endif } @@ -9615,7 +9640,7 @@ public: { if (!static_cast<QWidgetPrivate*>(d_ptr.data())->maybeBackingStore()) { static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStoreTracker.create(this); - static_cast<QWidgetPrivate*>(d_ptr.data())->invalidateBuffer(this->rect()); + static_cast<QWidgetPrivate*>(d_ptr.data())->invalidateBackingStore(this->rect()); repaint(); } } diff --git a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp index f4da4c3e5f..8b558aa56f 100644 --- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp +++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp @@ -46,6 +46,9 @@ #include <private/qwindow_p.h> #include <private/qguiapplication_p.h> #include <qpa/qplatformintegration.h> +#include <qpa/qwindowsysteminterface.h> +#include <qpa/qplatformdrag.h> +#include <private/qhighdpiscaling_p.h> #include <QtTest/private/qtesthelpers_p.h> @@ -87,6 +90,7 @@ private slots: #if QT_CONFIG(draganddrop) void tst_dnd(); void tst_dnd_events(); + void tst_dnd_propagation(); #endif void tst_qtbug35600(); @@ -470,6 +474,10 @@ static const char *expectedLogC[] = { "Event at 11,241 accepted", "acceptingDropsWidget2::dropEvent at 1,51 action=1 MIME_DATA_ADDRESS 'testmimetext'", "Event at 11,261 accepted", + "acceptingDropsWidget3::dragEnterEvent at 1,21 action=1 MIME_DATA_ADDRESS 'testmimetext'", + "Event at 11,281 accepted", + "acceptingDropsWidget3::dragLeaveEvent QDragLeaveEvent", + "Event at 11,301 ignored", "acceptingDropsWidget1::dragEnterEvent at 10,10 action=1 MIME_DATA_ADDRESS 'testmimetext'", "Event at 0,0 accepted", "acceptingDropsWidget1::dragMoveEvent at 11,11 action=1 MIME_DATA_ADDRESS 'testmimetext'", @@ -482,8 +490,9 @@ static const char *expectedLogC[] = { class DnDEventLoggerWidget : public QWidget { public: - DnDEventLoggerWidget(QStringList *log, QWidget *w = 0) : QWidget(w), m_log(log) {} - + DnDEventLoggerWidget(QStringList *log, QWidget *w = nullptr, bool ignoreDragMove = false) + : QWidget(w), m_log(log), m_ignoreDragMove(ignoreDragMove) + {} protected: void dragEnterEvent(QDragEnterEvent *); void dragMoveEvent(QDragMoveEvent *); @@ -493,6 +502,7 @@ protected: private: void formatDropEvent(const char *function, const QDropEvent *e, QTextStream &str) const; QStringList *m_log; + bool m_ignoreDragMove; }; void DnDEventLoggerWidget::formatDropEvent(const char *function, const QDropEvent *e, QTextStream &str) const @@ -513,6 +523,8 @@ void DnDEventLoggerWidget::dragEnterEvent(QDragEnterEvent *e) void DnDEventLoggerWidget::dragMoveEvent(QDragMoveEvent *e) { + if (m_ignoreDragMove) + return; e->accept(); QString message; QTextStream str(&message); @@ -580,7 +592,17 @@ void tst_QWidget_window::tst_dnd() dropsRefusingWidget2->resize(160, 60); dropsRefusingWidget2->move(10, 10); + QWidget *dropsAcceptingWidget3 = new DnDEventLoggerWidget(&log, &dndTestWidget, true); + dropsAcceptingWidget3->setAcceptDrops(true); + dropsAcceptingWidget3->setObjectName(QLatin1String("acceptingDropsWidget3")); + // 260 + 40 = 300 = widget size, must not be more than that. + // otherwise it will break WinRT because there the tlw is maximized every time + // and this window will receive one more event + dropsAcceptingWidget3->resize(180, 40); + dropsAcceptingWidget3->move(10, 260); + dndTestWidget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&dndTestWidget)); qApp->setActiveWindow(&dndTestWidget); QVERIFY(QTest::qWaitForWindowActive(&dndTestWidget)); @@ -595,16 +617,17 @@ void tst_QWidget_window::tst_dnd() log.push_back(msgEventAccepted(e)); while (true) { position.ry() += 20; - if (position.y() >= 250) { + if (position.y() >= 250 && position.y() < 270) { QDropEvent e(position, Qt::CopyAction, &mimeData, Qt::LeftButton, Qt::NoModifier); qApp->sendEvent(window, &e); log.push_back(msgEventAccepted(e)); - break; } else { QDragMoveEvent e(position, Qt::CopyAction, &mimeData, Qt::LeftButton, Qt::NoModifier); qApp->sendEvent(window, &e); log.push_back(msgEventAccepted(e)); } + if (position.y() > 290) + break; } window = nativeWidget->windowHandle(); @@ -628,6 +651,15 @@ void tst_QWidget_window::tst_dnd() for (int i= 0; i < expectedLogSize; ++i) expectedLog.push_back(QString::fromLatin1(expectedLogC[i]).replace(mimeDataAddressPlaceHolder, mimeDataAddress)); + if (log.size() != expectedLog.size()) { + for (int i = 0; i < log.size() && i < expectedLog.size(); ++i) + QCOMPARE(log.at(i), expectedLog.at(i)); + const int iMin = std::min(log.size(), expectedLog.size()); + for (int i = iMin; i < log.size(); ++i) + qDebug() << "log[" << i << "]:" << log.at(i); + for (int i = iMin; i < expectedLog.size(); ++i) + qDebug() << "exp[" << i << "]:" << log.at(i); + } QCOMPARE(log, expectedLog); } @@ -716,6 +748,77 @@ void tst_QWidget_window::tst_dnd_events() QCOMPARE(dndWidget._dndEvents, expectedDndEvents); } + +class DropTarget : public QWidget +{ +public: + explicit DropTarget() + { + setAcceptDrops(true); + + const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry(); + auto width = availableGeometry.width() / 6; + auto height = availableGeometry.height() / 4; + + setGeometry(availableGeometry.x() + 200, availableGeometry.y() + 200, width, height); + + QLabel *label = new QLabel(QStringLiteral("Test"), this); + label->setGeometry(40, 40, 60, 60); + label->setAcceptDrops(true); + } + + void dragEnterEvent(QDragEnterEvent *event) override + { + event->accept(); + mDndEvents.append("enter "); + } + + void dragMoveEvent(QDragMoveEvent *event) override + { + event->acceptProposedAction(); + } + + void dragLeaveEvent(QDragLeaveEvent *) override + { + mDndEvents.append("leave "); + } + + void dropEvent(QDropEvent *event) override + { + event->accept(); + mDndEvents.append("drop "); + } + + QString mDndEvents; +}; + +void tst_QWidget_window::tst_dnd_propagation() +{ + QMimeData mimeData; + mimeData.setText(QLatin1String("testmimetext")); + + DropTarget target; + target.show(); + QVERIFY(QTest::qWaitForWindowActive(&target)); + + Qt::DropActions supportedActions = Qt::DropAction::CopyAction; + QWindow *window = target.windowHandle(); + + auto posInsideDropTarget = QHighDpi::toNativePixels(QPoint(20, 20), window->screen()); + auto posInsideLabel = QHighDpi::toNativePixels(QPoint(60, 60), window->screen()); + + // Enter DropTarget. + QWindowSystemInterface::handleDrag(window, &mimeData, posInsideDropTarget, supportedActions, 0, 0); + // Enter QLabel. This will propagate because default QLabel does + // not accept the drop event in dragEnterEvent(). + QWindowSystemInterface::handleDrag(window, &mimeData, posInsideLabel, supportedActions, 0, 0); + // Drop on QLabel. DropTarget will get dropEvent(), because it accepted the event. + QWindowSystemInterface::handleDrop(window, &mimeData, posInsideLabel, supportedActions, 0, 0); + + QGuiApplication::processEvents(); + + QCOMPARE(target.mDndEvents, "enter leave enter drop "); +} #endif void tst_QWidget_window::tst_qtbug35600() diff --git a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp index 587e8a080d..a552c91928 100644 --- a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp +++ b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp @@ -197,7 +197,7 @@ void tst_QStyle::drawItemPixmap() const QRgb green = QColor(Qt::green).rgb(); QVERIFY(image.reinterpretAsFormat(QImage::Format_RGB32)); const QRgb *bits = reinterpret_cast<const QRgb *>(image.constBits()); - const QRgb *end = bits + image.byteCount() / sizeof(QRgb); + const QRgb *end = bits + image.sizeInBytes() / sizeof(QRgb); #ifdef Q_OS_WINRT QEXPECT_FAIL("", "QWidget::resize does not work on WinRT", Continue); #endif diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp index bfef9d2ac4..61b1fed1f8 100644 --- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -741,9 +741,9 @@ void tst_QStyleSheetStyle::fontPropagation() QCOMPARE(FONTSIZE(pb), 20); QWidget window; - window.setStyleSheet("* { font-size: 10pt }"); + window.setStyleSheet("* { font-size: 9pt }"); pb.setParent(&window); - QCOMPARE(FONTSIZE(pb), 10); + QCOMPARE(FONTSIZE(pb), 9); window.setStyleSheet(QString()); QCOMPARE(FONTSIZE(pb), buttonFontSize); @@ -2085,7 +2085,8 @@ void tst_QStyleSheetStyle::highdpiImages() QFETCH(QColor, color); QWidget w; - QScreen *screen = QGuiApplication::screenAt(w.pos()); + QScreen *screen = QGuiApplication::primaryScreen(); + w.move(screen->availableGeometry().topLeft()); QHighDpiScaling::setScreenFactor(screen, screenFactor); w.setStyleSheet("QWidget { background-image: url(\":/images/testimage.png\"); }"); w.show(); diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp index ad64f1aef7..8bb16cc9d1 100644 --- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp @@ -1595,27 +1595,16 @@ void tst_QCompleter::task247560_keyboardNavigation() } // Helpers for QTBUG_14292_filesystem: Recursion helper for below recurseTreeModel -template <class Function> -bool recurseTreeModelIndex(const QModelIndex &idx, Function f, int depth = 0) -{ - if (f(idx, depth)) - return true; - const int rowCount = idx.model()->rowCount(idx); - for (int row = 0; row < rowCount; ++row) - if (recurseTreeModelIndex(idx.child(row, 0), f, depth + 1)) - return true; - return false; -} - // Function to recurse over a tree model applying a function // taking index and depth, returning true to terminate recursion. - template <class Function> -bool recurseTreeModel(const QAbstractItemModel &m, Function f) +bool recurseTreeModel(const QAbstractItemModel &m, const QModelIndex &idx, Function f, int depth = 0) { - const int rowCount = m.rowCount(QModelIndex()); + if (idx.isValid() && f(idx, depth)) + return true; + const int rowCount = m.rowCount(idx); for (int row = 0; row < rowCount; ++row) - if (recurseTreeModelIndex(m.index(row, 0, QModelIndex()), f)) + if (recurseTreeModel(m, m.index(row, 0, idx), f, depth + 1)) return true; return false; } @@ -1658,7 +1647,7 @@ QDebug operator<<(QDebug d, const QAbstractItemModel &m) { QDebug dns = d.nospace(); dns << '\n'; - recurseTreeModel(m, DebugFunction(dns)); + recurseTreeModel(m, QModelIndex(), DebugFunction(dns)); return d; } @@ -1671,8 +1660,8 @@ static const char testDir2[] = "holla"; static inline bool testFileSystemReady(const QAbstractItemModel &model) { - return recurseTreeModel(model, SearchFunction(QLatin1String(testDir1), QFileSystemModel::FileNameRole)) - && recurseTreeModel(model, SearchFunction(QLatin1String(testDir2), QFileSystemModel::FileNameRole)); + return recurseTreeModel(model, QModelIndex(), SearchFunction(QLatin1String(testDir1), QFileSystemModel::FileNameRole)) + && recurseTreeModel(model, QModelIndex(), SearchFunction(QLatin1String(testDir2), QFileSystemModel::FileNameRole)); } void tst_QCompleter::QTBUG_14292_filesystem() diff --git a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp index 43063881b2..8bdd4b4783 100644 --- a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp +++ b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp @@ -125,6 +125,7 @@ private slots: void scrollTo(); void scroll(); void overshoot(); + void multipleWindows(); private: QTouchDevice *m_touchScreen = QTest::createTouchDevice(); @@ -347,9 +348,6 @@ void tst_QScroller::scrollerProperties() void tst_QScroller::scrollTo() { -#ifdef Q_OS_MAC - QSKIP("Flakey test - QTBUG-29950"); -#endif { tst_QScrollerWidget *sw = new tst_QScrollerWidget(); sw->scrollArea = QRectF( 0, 0, 1000, 1000 ); @@ -376,10 +374,7 @@ void tst_QScroller::scrollTo() void tst_QScroller::scroll() { -#ifdef Q_OS_MAC - QSKIP("Flakey test - QTBUG-30133"); -#endif -#ifndef QT_NO_GESTURES +#if QT_CONFIG(gestures) && QT_CONFIG(scroller) // -- good case. normal scroll tst_QScrollerWidget *sw = new tst_QScrollerWidget(); sw->scrollArea = QRectF(0, 0, 1000, 1000); @@ -419,10 +414,7 @@ void tst_QScroller::scroll() void tst_QScroller::overshoot() { -#ifdef Q_OS_MAC - QSKIP("Flakey test - QTBUG-29950"); -#endif -#ifndef QT_NO_GESTURES +#if QT_CONFIG(gestures) && QT_CONFIG(scroller) tst_QScrollerWidget *sw = new tst_QScrollerWidget(); sw->scrollArea = QRectF(0, 0, 1000, 1000); QScroller::grabGesture(sw, QScroller::TouchGesture); @@ -513,6 +505,39 @@ void tst_QScroller::overshoot() #endif } +void tst_QScroller::multipleWindows() +{ +#if QT_CONFIG(gestures) && QT_CONFIG(scroller) + QScopedPointer<tst_QScrollerWidget> sw1(new tst_QScrollerWidget()); + sw1->scrollArea = QRectF(0, 0, 1000, 1000); + QScroller::grabGesture(sw1.data(), QScroller::TouchGesture); + sw1->setGeometry(100, 100, 400, 300); + QScroller *s1 = QScroller::scroller(sw1.data()); + kineticScroll(sw1.data(), QPointF(500, 500), QPoint(0, 0), QPoint(100, 100), QPoint(200, 200)); + // now we should be scrolling + QTRY_COMPARE( s1->state(), QScroller::Scrolling ); + + // That was fun! Do it again! + QScopedPointer<tst_QScrollerWidget> sw2(new tst_QScrollerWidget()); + sw2->scrollArea = QRectF(0, 0, 1000, 1000); + QScroller::grabGesture(sw2.data(), QScroller::TouchGesture); + sw2->setGeometry(100, 100, 400, 300); + QScroller *s2 = QScroller::scroller(sw2.data()); + kineticScroll(sw2.data(), QPointF(500, 500), QPoint(0, 0), QPoint(100, 100), QPoint(200, 200)); + // now we should be scrolling + QTRY_COMPARE( s2->state(), QScroller::Scrolling ); + + // wait for both to stop + QTRY_VERIFY(s1->state() != QScroller::Scrolling); + QTRY_VERIFY(s2->state() != QScroller::Scrolling); + + sw1.reset(); // destroy one window + sw2->reset(); // reset the other scroller's internal state + // make sure we can still scroll the remaining one without crashing (QTBUG-71232) + kineticScroll(sw2.data(), QPointF(500, 500), QPoint(0, 0), QPoint(100, 100), QPoint(200, 200)); +#endif +} + QTEST_MAIN(tst_QScroller) #include "tst_qscroller.moc" diff --git a/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp b/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp index 70ae453896..1a0d7a9289 100644 --- a/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp +++ b/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp @@ -467,160 +467,1001 @@ void tst_QAbstractSlider::keyPressed_data() QTest::addColumn<int>("maximum"); QTest::addColumn<int>("stepSize"); QTest::addColumn<int>("pageSize"); + QTest::addColumn<bool>("invertedAppearance"); + QTest::addColumn<bool>("invertedControls"); QTest::addColumn<QList<Qt::Key> >("keySequence"); - QTest::addColumn<int>("expectedSliderPositionHorizontal"); - QTest::addColumn<int>("expectedSliderPositionVertical"); - QTest::addColumn<int>("expectedSliderPositionHorizontalInverted"); // :) - QTest::addColumn<int>("expectedSliderPositionVerticalInverted"); - + QTest::addColumn<int>("expectedSliderPosition"); QList<Qt::Key> list; - list << Qt::Key_Down; - QTest::newRow("Step down once 1") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 3 // single step size - << 0 // page step size - << list // key sequence - << 7 // result in case of horizontal slider - << 7 // result in case of vertical slider - << 13 // result in case of inverted horiz. slider - << 13; // result in case of inverted vertical slider + QTest::newRow("Step down once 1, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step down once 1, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step down once 1, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step down once 1, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step down once 1, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step down once 1, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step down once 1, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step down once 1, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position list = QList<Qt::Key>(); list << Qt::Key_Up; - QTest::newRow("Step down once 2") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 3 // single step size - << 0 // page step size - << list // key sequence - << 13 // result in case of horizontal slider - << 13 // result in case of vertical slider - << 7 // result in case of inverted horiz. slider - << 7; // result in case of inverted vertical slider - + QTest::newRow("Step up once 2, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step up once 2, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step up once 2, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step up once 2, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step up once 2, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step up once 2, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step up once 2, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step up once 2, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position list = QList<Qt::Key>(); list << Qt::Key_Left; - QTest::newRow("Step left once") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 3 // single step size - << 0 // page step size - << list // key sequence - << 7 // result in case of horizontal slider - << 7 // result in case of vertical slider - << 13 // result in case of inverted horiz. slider - << 13; // result in case of inverted vertical slider + QTest::newRow("Step left once 2, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step left once 2, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step left once 2, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step left once 2, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step left once 2, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step left once 2, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step left once 2, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step left once 2, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position list = QList<Qt::Key>(); list << Qt::Key_Right; - QTest::newRow("Step right once") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 3 // single step size - << 0 // page step size - << list // key sequence - << 13 // result in case of horizontal slider - << 13 // result in case of vertical slider - << 7 // result in case of inverted horiz. slider - << 7; // result in case of inverted vertical slider + QTest::newRow("Step right once 2, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step right once 2, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step right once 2, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step right once 2, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step right once 2, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step right once 2, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Step right once 2, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Step right once 2, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 0 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position list = QList<Qt::Key>(); list << Qt::Key_PageDown; - QTest::newRow("Page down once") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 0 // single step size - << 3 // page step size - << list // key sequence - << 7 // result in case of horizontal slider - << 7 // result in case of vertical slider - << 13 // result in case of inverted horiz. slider - << 13; // result in case of inverted vertical slider + QTest::newRow("Page down once, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Page down once, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Page down once, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Page down once, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Page down once, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Page down once, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Page down once, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Page down once, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 13; // expected position list = QList<Qt::Key>(); list << Qt::Key_PageUp; - QTest::newRow("Page up once") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 0 // single step size - << 3 // page step size - << list // key sequence - << 13 // result in case of horizontal slider - << 13 // result in case of vertical slider - << 7 // result in case of inverted horiz. slider - << 7; // result in case of inverted vertical slider + QTest::newRow("Page up once, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Page up once, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Page up once, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Page up once, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Page up once, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Page up once, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 13; // expected position + + QTest::newRow("Page up once, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position + + QTest::newRow("Page up once, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 7; // expected position list = QList<Qt::Key>(); list << Qt::Key_Up << Qt::Key_Up << Qt::Key_PageDown << Qt::Key_PageDown << Qt::Key_Left << Qt::Key_Left << Qt::Key_Right << Qt::Key_Down << Qt::Key_PageUp << Qt::Key_PageUp << Qt::Key_Down << Qt::Key_Right; - QTest::newRow("Symmetric seq") << 50 // initial position - << 0 // minimum - << 100 // maximum - << 3 // single step size - << 3 // page step size - << list // key sequence - << 50 // result in case of horizontal slider - << 50 // result in case of vertical slider - << 50 // result in case of inverted horiz. slider - << 50; // result in case of inverted vertical slider - + QTest::newRow("Symmetric seq, horizontal") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 50; // expected position + + QTest::newRow("Symmetric seq, horizontal, appearance inverted") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 50; // expected position + + QTest::newRow("Symmetric seq, horizontal, controls inverted") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 50; // expected position + + QTest::newRow("Symmetric seq, horizontal, both inverted") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 50; // expected position + + QTest::newRow("Symmetric seq, vertical") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 50; // expected position + + QTest::newRow("Symmetric seq, vertical, appearance inverted") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 50; // expected position + + QTest::newRow("Symmetric seq, vertical, controls inverted") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 50; // expected position + + QTest::newRow("Symmetric seq, vertical, both inverted") + << 50 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 50; // expected position list = QList<Qt::Key>(); list << Qt::Key_Home; - QTest::newRow("Home") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 0 // single step size - << 3 // page step size - << list // key sequence - << 0 // result in case of horizontal slider - << 0 // result in case of vertical slider - << 0 // result in case of inverted horiz. slider - << 0; // result in case of inverted vertical slider + QTest::newRow("Home, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Home, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Home, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Home, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Home, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Home, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Home, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Home, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 0; // expected position list = QList<Qt::Key>(); list << Qt::Key_End; - QTest::newRow("End") << 10 // initial position - << 0 // minimum - << 100 // maximum - << 0 // single step size - << 3 // page step size - << list // key sequence - << 100 // result in case of horizontal slider - << 100 // result in case of vertical slider - << 100 // result in case of inverted horiz. slider - << 100; // result in case of inverted vertical slider + QTest::newRow("End, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("End, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("End, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("End, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("End, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("End, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("End, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("End, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 0 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 100; // expected position list = QList<Qt::Key>(); list << Qt::Key_End << Qt::Key_Up; - QTest::newRow("Past end")<< 10 // initial position - << 0 // minimum - << 100 // maximum - << 3 // single step size - << 3 // page step size - << list // key sequence - << 100 // result in case of horizontal slider - << 100 // result in case of vertical slider - << 97 // result in case of inverted horiz. slider - << 97; // result in case of inverted vertical slider + QTest::newRow("Past end, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("Past end, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("Past end, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 97; // expected position + + QTest::newRow("Past end, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 97; // expected position + + QTest::newRow("Past end, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("Past end, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 100; // expected position + + QTest::newRow("Past end, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 97; // expected position + + QTest::newRow("Past end, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 97; // expected position list = QList<Qt::Key>(); list << Qt::Key_Home << Qt::Key_Down; - QTest::newRow("Past home")<< 10 // initial position - << 0 // minimum - << 100 // maximum - << 3 // single step size - << 3 // page step size - << list // key sequence - << 0 // result in case of horizontal slider - << 0 // result in case of vertical slider - << 3 // result in case of inverted horiz. slider - << 3; // result in case of inverted vertical slider - + QTest::newRow("Past home, horizontal") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Past home, horizontal, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Past home, horizontal, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 3; // expected position + + QTest::newRow("Past home, horizontal, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 3; // expected position + + QTest::newRow("Past home, vertical") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Past home, vertical, appearance inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << false// inverted controls + << list // key sequence + << 0; // expected position + + QTest::newRow("Past home, vertical, controls inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << false// inverted appearance + << true // inverted controls + << list // key sequence + << 3; // expected position + + QTest::newRow("Past home, vertical, both inverted") + << 10 // initial position + << 0 // minimum + << 100 // maximum + << 3 // single step size + << 3 // page step size + << true // inverted appearance + << true // inverted controls + << list // key sequence + << 3; // expected position } void tst_QAbstractSlider::keyPressed() @@ -630,60 +1471,22 @@ void tst_QAbstractSlider::keyPressed() QFETCH(int, maximum); QFETCH(int, stepSize); QFETCH(int, pageSize); + QFETCH(bool, invertedAppearance); + QFETCH(bool, invertedControls); QFETCH(QList<Qt::Key>, keySequence); - QFETCH(int, expectedSliderPositionHorizontal); - QFETCH(int, expectedSliderPositionVertical); - QFETCH(int, expectedSliderPositionHorizontalInverted); - QFETCH(int, expectedSliderPositionVerticalInverted); + QFETCH(int, expectedSliderPosition); - // Horizontal non-inverted slider->setRange(minimum,maximum); slider->setSliderPosition(initialSliderPosition); slider->setSingleStep(stepSize); slider->setPageStep(pageSize); slider->setOrientation(Qt::Horizontal); - slider->setInvertedAppearance(false); - slider->setInvertedControls(false); + slider->setInvertedAppearance(invertedAppearance); + slider->setInvertedControls(invertedControls); for (int i=0;i<keySequence.count();i++) { QTest::keyClick(slider, keySequence.at(i)); } - QCOMPARE(slider->sliderPosition(), expectedSliderPositionHorizontal); - - // Horizontal inverted - slider->setRange(minimum,maximum); - slider->setSliderPosition(initialSliderPosition); - slider->setSingleStep(stepSize); - slider->setPageStep(pageSize); - slider->setOrientation(Qt::Horizontal); - slider->setInvertedAppearance(true); - slider->setInvertedControls(true); - for (int i=0;i<keySequence.count();i++) - QTest::keyPress(slider, keySequence.at(i)); - QCOMPARE(slider->sliderPosition(), expectedSliderPositionHorizontalInverted); - - // Vertical non-inverted - slider->setRange(minimum,maximum); - slider->setSliderPosition(initialSliderPosition); - slider->setSingleStep(stepSize); - slider->setPageStep(pageSize); - slider->setOrientation(Qt::Vertical); - slider->setInvertedAppearance(false); - slider->setInvertedControls(false); - for (int i=0;i<keySequence.count();i++) - QTest::keyPress(slider, keySequence.at(i)); - QCOMPARE(slider->sliderPosition(), expectedSliderPositionVertical); - - // Vertical inverted - slider->setRange(minimum,maximum); - slider->setSliderPosition(initialSliderPosition); - slider->setSingleStep(stepSize); - slider->setPageStep(pageSize); - slider->setOrientation(Qt::Vertical); - slider->setInvertedAppearance(true); - slider->setInvertedControls(true); - for (int i=0;i<keySequence.count();i++) - QTest::keyPress(slider, keySequence.at(i)); - QCOMPARE(slider->sliderPosition(), expectedSliderPositionVerticalInverted); + QCOMPARE(slider->sliderPosition(), expectedSliderPosition); } #if QT_CONFIG(wheelevent) diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 943fb997cd..5b4761ba87 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -1671,6 +1671,13 @@ void tst_QComboBox::setCustomModelAndView() QTRY_VERIFY(combo.view()->isVisible()); const QRect subItemRect = view->visualRect(model->indexFromItem(subItem)); QWidget *window = view->window(); + + // QComboBox sometimes ignores the mouse click event for doubleClickInterval + // depending on which tests have been run previously. On arm this happens + // more often than on x86. Search for maybeIgnoreMouseButtonRelease to see + // why this happens. + QTest::qWait(QApplication::doubleClickInterval()); + QTest::mouseClick(window->windowHandle(), Qt::LeftButton, 0, view->mapTo(window, subItemRect.center())); #ifdef Q_OS_WINRT QEXPECT_FAIL("", "Fails on WinRT - QTBUG-68297", Abort); @@ -3421,6 +3428,11 @@ void tst_QComboBox::task_QTBUG_52027_mapCompleterIndex() model->setFilterFixedString("foobar1"); completer->setModel(model); + if (QGuiApplication::platformName() == "offscreen") { + QWARN("Offscreen platform requires explicit activateWindow()"); + cbox.activateWindow(); + } + QApplication::setActiveWindow(&cbox); QVERIFY(QTest::qWaitForWindowActive(&cbox)); diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp index e2f1307eb1..b5ef454b14 100644 --- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp +++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp @@ -823,7 +823,7 @@ void tst_QDateTimeEdit::displayFormat_data() << QString("31 12 2999::59:59:03") << dt; QTest::newRow("valid-2") << QString("hh-dd-mm-MM-yy") << true << QString("03-31-59-12-99") << dt; QTest::newRow("valid-3") << QString("ddd MM d yyyy::ss:mm:hh") << true - << QDate::shortDayName(2) + " 12 31 2999::59:59:03" << dt; + << QLocale::system().dayName(2, QLocale::ShortFormat) + " 12 31 2999::59:59:03" << dt; QTest::newRow("valid-4") << QString("hh-dd-mm-MM-yyyy") << true << QString("03-31-59-12-2999") << dt; QTest::newRow("invalid-0") << QString("yyyy.MM.yy") << true << QString("2999.12.99") << dt; QTest::newRow("invalid-1") << QString("y") << false << QString() << dt; @@ -2611,9 +2611,13 @@ void tst_QDateTimeEdit::weirdCase() void tst_QDateTimeEdit::newCase() { - if (QDate::shortMonthName(6) != "Jun" || QDate::shortMonthName(7) != "Jul" || - QDate::longMonthName(6) != "June" || QDate::longMonthName(7) != "July") + const auto locale = QLocale::system(); + if (locale.monthName(6, QLocale::ShortFormat) != "Jun" || + locale.monthName(7, QLocale::ShortFormat) != "Jul" || + locale.monthName(6, QLocale::LongFormat) != "June" || + locale.monthName(7, QLocale::LongFormat) != "July") { QSKIP("This test only works in English"); + } testWidget->setDisplayFormat("MMMM'a'MbMMMcMM"); testWidget->setDate(QDate(2005, 6, 1)); @@ -2656,12 +2660,12 @@ void tst_QDateTimeEdit::newCase2() testWidget->setDate(QDate(2005, 8, 8)); QTest::keyClick(testWidget, Qt::Key_Return); QTest::keyClick(testWidget, Qt::Key_Backspace); - QCOMPARE(testWidget->text(), QString(" 2005-08-08 ") + QDate::longMonthName(8)); + QCOMPARE(testWidget->text(), QString(" 2005-08-08 ") + QLocale::system().monthName(8, QLocale::LongFormat)); } void tst_QDateTimeEdit::newCase3() { - if (!QDate::longMonthName(1).startsWith("Januar")) + if (!QLocale::system().monthName(1, QLocale::LongFormat).startsWith("Januar")) QSKIP("This test does not work in this locale"); testWidget->setDisplayFormat("dd MMMM yyyy"); @@ -2681,7 +2685,7 @@ void tst_QDateTimeEdit::newCase3() void tst_QDateTimeEdit::cursorPos() { - if (QDate::longMonthName(1) != "January") + if (QLocale::system().monthName(1, QLocale::LongFormat) != "January") QSKIP("This test only works in English"); testWidget->setDisplayFormat("dd MMMM yyyy"); @@ -3017,7 +3021,7 @@ void tst_QDateTimeEdit::yyTest() testWidget->setDate(testWidget->minimumDate()); testWidget->setCurrentSection(QDateTimeEdit::YearSection); - QString jan = QDate::shortMonthName(1); + QString jan = QLocale::system().monthName(1, QLocale::ShortFormat); QCOMPARE(testWidget->lineEdit()->displayText(), "01-" + jan + "-05"); QTest::keyClick(testWidget, Qt::Key_Up); QCOMPARE(testWidget->lineEdit()->displayText(), "01-" + jan + "-06"); @@ -3130,7 +3134,7 @@ void tst_QDateTimeEdit::ddMMMMyyyy() #ifdef Q_OS_MAC QEXPECT_FAIL("", "QTBUG-23674", Abort); #endif - QCOMPARE(testWidget->lineEdit()->text(), "01." + QDate::longMonthName(1) + ".200"); + QCOMPARE(testWidget->lineEdit()->text(), "01." + QLocale::system().monthName(1, QLocale::LongFormat) + ".200"); } void tst_QDateTimeEdit::wheelEvent_data() @@ -3848,7 +3852,7 @@ void tst_QDateTimeEdit::dateEditCorrectSectionSize_data() << threeDigitDayIssueKeypresses_DayName << QString::fromLatin1("00/2/Tuesday"); QTest::newRow("no fixday, leap, yy/M/ddd") << defaultLocale << defaultDate << QString::fromLatin1("yy/M/ddd") - << threeDigitDayIssueKeypresses_DayName << QString::fromLatin1("00/2/Tue."); + << threeDigitDayIssueKeypresses_DayName << QString::fromLatin1("00/2/Tue"); QTest::newRow("no fixday, leap, yy/MM/dddd") << defaultLocale << defaultDate << QString::fromLatin1("yy/MM/dddd") << threeDigitDayIssueKeypresses_DayName << QString::fromLatin1("00/02/Tuesday"); @@ -3896,13 +3900,13 @@ void tst_QDateTimeEdit::dateEditCorrectSectionSize_data() << threeDigitDayIssueKeypresses_YearDayMonth << QString::fromLatin1("2000/29/2"); QTest::newRow("fixday, leap, yyyy/MMM/dd") << defaultLocale << defaultDate << QString::fromLatin1("yyyy/MMM/dd") - << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("2000/Feb./29"); + << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("2000/Feb/29"); QTest::newRow("fixday, leap, yyyy/MMM/d") << defaultLocale << defaultDate << QString::fromLatin1("yyyy/MMM/d") - << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("2000/Feb./29"); + << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("2000/Feb/29"); QTest::newRow("fixday, leap, yy/MMM/dd") << defaultLocale << defaultDate << QString::fromLatin1("yy/MMM/dd") - << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("00/Feb./29"); + << threeDigitDayIssueKeypresses_ShortMonthName << QString::fromLatin1("00/Feb/29"); QTest::newRow("fixday, leap, yyyy/dddd/M") << defaultLocale << defaultDate << QString::fromLatin1("yyyy/dddd/M") << threeDigitDayIssueKeypresses_DayName_YearDayMonth << QString::fromLatin1("2000/Tuesday/2"); @@ -3977,16 +3981,16 @@ void tst_QDateTimeEdit::dateEditCorrectSectionSize_data() << threeDigitDayIssueKeypresses_MonthYearDay << QString::fromLatin1("02/2000/29"); QTest::newRow("fixday, leap, MMM/yy/d") << defaultLocale << defaultDate << QString::fromLatin1("MMM/yy/d") - << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb./00/29"); + << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb/00/29"); QTest::newRow("fixday, leap, MMM/yyyy/d") << defaultLocale << defaultDate << QString::fromLatin1("MMM/yyyy/d") - << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb./2000/29"); + << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb/2000/29"); QTest::newRow("fixday, MMM/yyyy/d") << defaultLocale << defaultDate.addYears(1) << QString::fromLatin1("MMM/yyyy/d") - << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb./2001/28"); + << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb/2001/28"); QTest::newRow("fixday, leap, MMM/yyyy/dd") << defaultLocale << defaultDate << QString::fromLatin1("MMM/yyyy/dd") - << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb./2000/29"); + << threeDigitDayIssueKeypresses_ShortMonthName_MonthYearDay << QString::fromLatin1("Feb/2000/29"); QTest::newRow("fixday, leap, dddd, dd. MMMM yyyy") << defaultLocale << defaultDate << QString::fromLatin1("dddd, dd. MMMM yyyy") diff --git a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp index 078a3215fd..f8ce6a2c0a 100644 --- a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp @@ -71,6 +71,7 @@ private slots: void restoreStateOfFloating(); void restoreDockWidget(); void restoreStateWhileStillFloating(); + void setWindowTitle(); // task specific tests: void task165177_deleteFocusWidget(); void task169808_setFloating(); @@ -993,7 +994,54 @@ void tst_QDockWidget::taskQTBUG_9758_undockedGeometry() QVERIFY(dock1.y() >= 0); } +void tst_QDockWidget::setWindowTitle() +{ + QMainWindow window; + QDockWidget dock1(&window); + QDockWidget dock2(&window); + const QString dock1Title = QStringLiteral("&Window"); + const QString dock2Title = QStringLiteral("&Modifiable Window [*]"); + + dock1.setWindowTitle(dock1Title); + dock2.setWindowTitle(dock2Title); + window.addDockWidget(Qt::RightDockWidgetArea, &dock1); + window.addDockWidget(Qt::RightDockWidgetArea, &dock2); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QCOMPARE(dock1.windowTitle(), dock1Title); + QCOMPARE(dock2.windowTitle(), dock2Title); + + dock1.setFloating(true); + dock1.show(); + QVERIFY(QTest::qWaitForWindowExposed(&dock1)); + QCOMPARE(dock1.windowTitle(), dock1Title); + dock1.setFloating(false); + QCOMPARE(dock1.windowTitle(), dock1Title); + dock1.setFloating(true); + dock1.show(); + QVERIFY(QTest::qWaitForWindowExposed(&dock1)); + const QString changed = QStringLiteral("Changed "); + dock1.setWindowTitle(QString(changed + dock1Title)); + QCOMPARE(dock1.windowTitle(), QString(changed + dock1Title)); + dock1.setFloating(false); + QCOMPARE(dock1.windowTitle(), QString(changed + dock1Title)); + + dock2.setWindowModified(true); + QCOMPARE(dock2.windowTitle(), dock2Title); + dock2.setFloating(true); + dock2.show(); + QVERIFY(QTest::qWaitForWindowExposed(&dock2)); + QCOMPARE(dock2.windowTitle(), dock2Title); + dock2.setWindowModified(false); + QCOMPARE(dock2.windowTitle(), dock2Title); + dock2.setFloating(false); + QCOMPARE(dock2.windowTitle(), dock2Title); + dock2.setFloating(true); + dock2.show(); + QVERIFY(QTest::qWaitForWindowExposed(&dock2)); + QCOMPARE(dock2.windowTitle(), dock2Title); +} QTEST_MAIN(tst_QDockWidget) #include "tst_qdockwidget.moc" diff --git a/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp b/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp index b1610c297d..b101f47bcd 100644 --- a/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp +++ b/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp @@ -326,14 +326,26 @@ void tst_QDoubleSpinBox::setPrefixSuffix() QDoubleSpinBox spin(0); spin.setDecimals(decimals); + const QSize size1 = spin.sizeHint(); spin.setPrefix(prefix); + const QSize size2 = spin.sizeHint(); spin.setSuffix(suffix); + const QSize size3 = spin.sizeHint(); spin.setValue(value); if (show) spin.show(); QCOMPARE(spin.text(), expectedText); QCOMPARE(spin.cleanText(), expectedCleanText); + + if (!prefix.isEmpty() && !suffix.isEmpty()) { + QVERIFY(size1.width() < size2.width()); + QVERIFY(size2.width() < size3.width()); + spin.setSuffix(QString()); + QCOMPARE(spin.sizeHint(), size2); + spin.setPrefix(QString()); + QCOMPARE(spin.sizeHint(), size1); + } } void tst_QDoubleSpinBox::valueChangedHelper(const QString &text) diff --git a/tests/auto/widgets/widgets/qfocusframe/tst_qfocusframe.cpp b/tests/auto/widgets/widgets/qfocusframe/tst_qfocusframe.cpp index e6e689336a..657a1ea55c 100644 --- a/tests/auto/widgets/widgets/qfocusframe/tst_qfocusframe.cpp +++ b/tests/auto/widgets/widgets/qfocusframe/tst_qfocusframe.cpp @@ -32,6 +32,8 @@ #include <qcoreapplication.h> #include <qdebug.h> #include <qfocusframe.h> +#include <qtableview.h> +#include <qstandarditemmodel.h> class tst_QFocusFrame : public QObject { @@ -43,6 +45,7 @@ public: private slots: void getSetCheck(); + void focusFrameInsideScrollview(); }; tst_QFocusFrame::tst_QFocusFrame() @@ -68,5 +71,41 @@ void tst_QFocusFrame::getSetCheck() delete obj1; } +void tst_QFocusFrame::focusFrameInsideScrollview() +{ + // Make sure that the focus frame follows the widget, even + // if the widget is inside a QAbstractItemView. A QAbstractItemView will scroll + // all the children, including the focus frame, when it scrolls, which + // is why special considerations are taken inside the focus frame to + // prevent the frame to scroll away from the widget it tracks. + + if (qApp->style()->objectName() != QLatin1String("macintosh")) + QSKIP("This test is only valid when using a style that has a focus frame"); + + QWidget window; + window.setGeometry(100, 100, 500, 500); + + QTableView tableView(&window); + tableView.resize(window.size()); + QStandardItemModel *itemModel = new QStandardItemModel(); + for (int i = 0; i < 50; ++i) + itemModel->appendRow(new QStandardItem("Value")); + tableView.setModel(itemModel); + tableView.edit(itemModel->index(8, 0)); + + window.show(); + QFocusFrame *focusFrame = nullptr; + QTRY_VERIFY(focusFrame = window.findChild<QFocusFrame *>()); + const QPoint initialOffset = focusFrame->widget()->mapToGlobal(QPoint()) - focusFrame->mapToGlobal(QPoint()); + + tableView.scrollTo(itemModel->index(40, 0)); + QPoint offsetAfterScroll = focusFrame->widget()->mapToGlobal(QPoint()) - focusFrame->mapToGlobal(QPoint()); + QCOMPARE(offsetAfterScroll, initialOffset); + + tableView.scrollTo(itemModel->index(0, 0)); + offsetAfterScroll = focusFrame->widget()->mapToGlobal(QPoint()) - focusFrame->mapToGlobal(QPoint()); + QCOMPARE(offsetAfterScroll, initialOffset); +} + QTEST_MAIN(tst_QFocusFrame) #include "tst_qfocusframe.moc" diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 448e2030bc..7861065de9 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -3615,6 +3615,14 @@ void tst_QLineEdit::task174640_editingFinished() le2->setFocus(); QTRY_VERIFY(le2->hasFocus()); + // editingFinished will not be emitted anew because no editing happened + QCOMPARE(editingFinishedSpy.count(), 0); + + le1->setFocus(); + QTRY_VERIFY(le1->hasFocus()); + QTest::keyPress(le1, Qt::Key_Plus); + le2->setFocus(); + QTRY_VERIFY(le2->hasFocus()); QCOMPARE(editingFinishedSpy.count(), 1); editingFinishedSpy.clear(); @@ -3632,6 +3640,8 @@ void tst_QLineEdit::task174640_editingFinished() delete testMenu1; QCOMPARE(editingFinishedSpy.count(), 0); QTRY_VERIFY(le1->hasFocus()); + // Ensure le1 has been edited + QTest::keyPress(le1, Qt::Key_Plus); QMenu *testMenu2 = new QMenu(le2); testMenu2->addAction("foo2"); @@ -4451,10 +4461,11 @@ void tst_QLineEdit::clearButtonVisibleAfterSettingText_QTBUG_45518() QTRY_VERIFY(clearButton->opacity() > 0); QTRY_COMPARE(clearButton->cursor().shape(), Qt::ArrowCursor); - QTest::mouseClick(clearButton, Qt::LeftButton, 0, clearButton->rect().center()); + QTest::mouseClick(clearButton, Qt::LeftButton, nullptr, clearButton->rect().center()); QTRY_COMPARE(edit.text(), QString()); QTRY_COMPARE(clearButton->opacity(), qreal(0)); + QVERIFY(clearButton->isHidden()); QTRY_COMPARE(clearButton->cursor().shape(), clearButton->parentWidget()->cursor().shape()); edit.setClearButtonEnabled(false); diff --git a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp index 1acf07301c..ea96322654 100644 --- a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp +++ b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp @@ -1343,8 +1343,10 @@ void tst_QMainWindow::restoreState() { QMainWindow mw; QToolBar tb(&mw); + tb.setObjectName(QLatin1String("toolBar")); mw.addToolBar(Qt::TopToolBarArea, &tb); QDockWidget dw(&mw); + dw.setObjectName(QLatin1String("dock")); mw.addDockWidget(Qt::LeftDockWidgetArea, &dw); QByteArray state; diff --git a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp index 6cc19051d2..046899ce05 100644 --- a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp +++ b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp @@ -333,6 +333,7 @@ void tst_QMdiArea::subWindowActivated() for ( i = 0; i < count; ++i ) { QWidget *widget = new QWidget(workspace, 0); widget->setAttribute(Qt::WA_DeleteOnClose); + widget->setFocus(); workspace->addSubWindow(widget)->show(); widget->show(); qApp->processEvents(); @@ -1689,14 +1690,16 @@ void tst_QMdiArea::tileSubWindows() workspace.setActiveSubWindow(0); QVERIFY(workspace.viewport()->childrenRect() != workspace.viewport()->rect()); - // Make sure the active window is placed in top left corner regardless + // Make sure the active window does not move position after a tile regardless // of whether we have any windows with staysOnTopHint or not. + workspace.tileSubWindows(); windows.at(3)->setWindowFlags(windows.at(3)->windowFlags() | Qt::WindowStaysOnTopHint); QMdiSubWindow *activeSubWindow = windows.at(6); workspace.setActiveSubWindow(activeSubWindow); QCOMPARE(workspace.activeSubWindow(), activeSubWindow); + QPoint pos = activeSubWindow->geometry().topLeft(); workspace.tileSubWindows(); - QCOMPARE(activeSubWindow->geometry().topLeft(), QPoint(0, 0)); + QCOMPARE(activeSubWindow->geometry().topLeft(), pos); // Verify that we try to resize the area such that all sub-windows are visible. // It's important that tiled windows are NOT overlapping. @@ -1713,6 +1716,8 @@ void tst_QMdiArea::tileSubWindows() // Prevent scrollbars from messing up the expected viewport calculation below workspace.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); workspace.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + QCOMPARE(workspace.horizontalScrollBarPolicy(), Qt::ScrollBarAlwaysOff); + QCOMPARE(workspace.verticalScrollBarPolicy(), Qt::ScrollBarAlwaysOff); workspace.tileSubWindows(); // The sub-windows are now tiled like this: @@ -1731,9 +1736,11 @@ void tst_QMdiArea::tileSubWindows() const QSize expectedViewportSize(3 * minSize.width() + spacing, 3 * minSize.height() + spacing); QTRY_COMPARE(workspace.viewport()->rect().size(), expectedViewportSize); - // Restore original scrollbar behavior for test below + // Enable scroll bar for test below (default property for QMdiArea is Qt::ScrollBarAlwaysOff) workspace.setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); workspace.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + QCOMPARE(workspace.horizontalScrollBarPolicy(), Qt::ScrollBarAsNeeded); + QCOMPARE(workspace.verticalScrollBarPolicy(), Qt::ScrollBarAsNeeded); // Not enough space for all sub-windows to be visible -> provide scroll bars. workspace.resize(160, 150); @@ -1754,13 +1761,16 @@ void tst_QMdiArea::tileSubWindows() QCOMPARE(vBar->value(), 0); QCOMPARE(vBar->minimum(), 0); + // Tile windows with scroll bars enabled. workspace.tileSubWindows(); QVERIFY(QTest::qWaitForWindowExposed(&workspace)); qApp->processEvents(); - QTRY_VERIFY(workspace.size() != QSize(150, 150)); - QTRY_VERIFY(!vBar->isVisible()); - QTRY_VERIFY(!hBar->isVisible()); + // Workspace should not have changed size after tile. + QTRY_VERIFY(workspace.size() == QSize(160, 150)); + // Scroll bars should be visible. + QTRY_VERIFY(vBar->isVisible()); + QTRY_VERIFY(hBar->isVisible()); } void tst_QMdiArea::cascadeAndTileSubWindows() @@ -2180,7 +2190,7 @@ void tst_QMdiArea::setActivationOrder_data() list << 2 << 1 << 0 << 1 << 2 << 3 << 4; list2 << 0 << 1 << 2 << 3 << 4; - list3 << 1 << 4 << 3 << 1 << 2 << 0; + list3 << 4 << 3 << 2 << 4 << 1 << 0; // Most recently created window is in top-left position QTest::newRow("CreationOrder") << QMdiArea::CreationOrder << 5 << 3 << 1 << list << list2 << list3; list = QList<int>(); @@ -2188,7 +2198,7 @@ void tst_QMdiArea::setActivationOrder_data() list2 = QList<int>(); list2 << 0 << 2 << 4 << 1 << 3; list3 = QList<int>(); - list3 << 1 << 3 << 4 << 1 << 2 << 0; + list3 << 3 << 1 << 4 << 3 << 2 << 0; // Window with "stays-on-top" flag set will be in the top-left position QTest::newRow("StackingOrder") << QMdiArea::StackingOrder << 5 << 3 << 1 << list << list2 << list3; list = QList<int>(); diff --git a/tests/auto/widgets/widgets/qmenu/BLACKLIST b/tests/auto/widgets/widgets/qmenu/BLACKLIST index 89d12a259f..bac14ea225 100644 --- a/tests/auto/widgets/widgets/qmenu/BLACKLIST +++ b/tests/auto/widgets/widgets/qmenu/BLACKLIST @@ -1,7 +1,6 @@ [task258920_mouseBorder] osx [submenuTearOffDontClose] -osx-10.11 ci osx-10.12 ci [layoutDirection] # Fails when enabling synchronous expose events QTBUG-62092 diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp index 634e258250..3bfbe754ef 100644 --- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp +++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp @@ -1001,7 +1001,7 @@ void tst_QMenu::task258920_mouseBorder() menu.setMouseTracking(true); QAction *action = menu.addAction("test"); - const QPoint center = QApplication::desktop()->availableGeometry().center(); + const QPoint center = QGuiApplication::primaryScreen()->availableGeometry().center(); menu.popup(center); QVERIFY(QTest::qWaitForWindowExposed(&menu)); QRect actionRect = menu.actionGeometry(action); @@ -1073,9 +1073,9 @@ void tst_QMenu::pushButtonPopulateOnAboutToShow() QMenu *buttonMenu= new PopulateOnAboutToShowTestMenu(&b); b.setMenu(buttonMenu); - const int scrNumber = QApplication::desktop()->screenNumber(&b); + const QScreen *scr = QGuiApplication::screenAt(b.pos()); b.show(); - const QRect screen = QApplication::desktop()->screenGeometry(scrNumber); + const QRect screen = scr->geometry(); QRect desiredGeometry = b.geometry(); desiredGeometry.moveTopLeft(QPoint(screen.x() + 10, screen.bottom() - b.height() - 5)); @@ -1450,13 +1450,14 @@ void tst_QMenu::QTBUG_56917_wideMenuScreenNumber() QString longString; longString.fill(QLatin1Char('Q'), 3000); - for (int i = 0; i < QApplication::desktop()->screenCount(); i++) { + const QList<QScreen *> screens = QGuiApplication::screens(); + for (QScreen *screen : screens) { QMenu menu; menu.addAction(longString); - menu.popup(QApplication::desktop()->screen(i)->geometry().center()); + menu.popup(screen->geometry().center()); QVERIFY(QTest::qWaitForWindowExposed(&menu)); QVERIFY(menu.isVisible()); - QCOMPARE(QApplication::desktop()->screenNumber(&menu), i); + QCOMPARE(QGuiApplication::screenAt(menu.pos()), screen); } } @@ -1468,19 +1469,20 @@ void tst_QMenu::QTBUG_56917_wideSubmenuScreenNumber() QString longString; longString.fill(QLatin1Char('Q'), 3000); - for (int i = 0; i < QApplication::desktop()->screenCount(); i++) { + const QList<QScreen *> screens = QGuiApplication::screens(); + for (QScreen *screen : screens) { QMenu menu; QMenu submenu("Submenu"); submenu.addAction(longString); QAction *action = menu.addMenu(&submenu); - menu.popup(QApplication::desktop()->screen(i)->geometry().center()); + menu.popup(screen->geometry().center()); QVERIFY(QTest::qWaitForWindowExposed(&menu)); QVERIFY(menu.isVisible()); QTest::mouseClick(&menu, Qt::LeftButton, 0, menu.actionGeometry(action).center()); QTest::qWait(100); QVERIFY(QTest::qWaitForWindowExposed(&submenu)); QVERIFY(submenu.isVisible()); - QCOMPARE(QApplication::desktop()->screenNumber(&submenu), i); + QCOMPARE(QGuiApplication::screenAt(submenu.pos()), screen); } } @@ -1577,6 +1579,13 @@ void tst_QMenu::menuSize_Scrolling() #ifdef Q_OS_WINRT QEXPECT_FAIL("", "Broken on WinRT - QTBUG-68297", Abort); #endif + if (!QGuiApplication::platformName().compare(QLatin1String("minimal"), Qt::CaseInsensitive) + || !QGuiApplication::platformName().compare(QLatin1String("offscreen"), Qt::CaseInsensitive)) { + QWARN("Skipping test on minimal/offscreen platforms - QTBUG-73522"); + QMenu::showEvent(e); + return; + } + QCOMPARE( s.width(), lastItem.right() + fw + hmargin + rightMargin + 1); QMenu::showEvent(e); } diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index 3063d43aa6..cb829c81a6 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -326,7 +326,7 @@ TestMenu tst_QMenuBar::initComplexMenuBar(QMenuBar *mb) connect(action, SIGNAL(triggered()), this, SLOT(onComplexActionTriggered())); result.actions << action; - qFill(m_complexTriggerCount, m_complexTriggerCount + sizeof(m_complexTriggerCount) / sizeof(int), 0); + std::fill(m_complexTriggerCount, m_complexTriggerCount + sizeof(m_complexTriggerCount) / sizeof(int), 0); return result; } diff --git a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp index be19cbc9d1..2ce75620cf 100644 --- a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp +++ b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp @@ -209,12 +209,12 @@ void tst_QPlainTextEdit::getSetCheck() // int QPlainTextEdit::tabStopWidth() // void QPlainTextEdit::setTabStopWidth(int) - obj1.setTabStopWidth(0); - QCOMPARE(0, obj1.tabStopWidth()); - obj1.setTabStopWidth(INT_MIN); - QCOMPARE(0, obj1.tabStopWidth()); // Makes no sense to set a negative tabstop value - obj1.setTabStopWidth(INT_MAX); - QCOMPARE(INT_MAX, obj1.tabStopWidth()); + obj1.setTabStopDistance(0); + QCOMPARE(0, obj1.tabStopDistance()); + obj1.setTabStopDistance(-1); + QCOMPARE(0, obj1.tabStopDistance()); // Makes no sense to set a negative tabstop value + obj1.setTabStopDistance(std::numeric_limits<qreal>::max()); + QCOMPARE(std::numeric_limits<qreal>::max(), obj1.tabStopDistance()); } class QtTestDocumentLayout : public QAbstractTextDocumentLayout diff --git a/tests/auto/widgets/widgets/qsizegrip/tst_qsizegrip.cpp b/tests/auto/widgets/widgets/qsizegrip/tst_qsizegrip.cpp index 4cc1810cd4..f4b91265a4 100644 --- a/tests/auto/widgets/widgets/qsizegrip/tst_qsizegrip.cpp +++ b/tests/auto/widgets/widgets/qsizegrip/tst_qsizegrip.cpp @@ -59,25 +59,22 @@ class tst_QSizeGrip : public QObject { Q_OBJECT public slots: - void initTestCase(); - void cleanupTestCase(); + void cleanup(); private slots: void hideAndShowOnWindowStateChange_data(); void hideAndShowOnWindowStateChange(); void orientation(); void dontCrashOnTLWChange(); - -private: - QLineEdit *dummyWidget; }; class TestWidget : public QWidget { public: - TestWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0) : QWidget(parent, flags) {} - QSize sizeHint() const { return QSize(300, 200); } - void changeEvent(QEvent *event) + using QWidget::QWidget; + + QSize sizeHint() const override { return QSize(300, 200); } + void changeEvent(QEvent *event) override { QWidget::changeEvent(event); if (isWindow() && event->type() == QEvent::WindowStateChange) @@ -85,16 +82,9 @@ public: } }; -void tst_QSizeGrip::initTestCase() -{ - dummyWidget = new QLineEdit; - dummyWidget->show(); -} - -void tst_QSizeGrip::cleanupTestCase() +void tst_QSizeGrip::cleanup() { - delete dummyWidget; - dummyWidget = 0; + QVERIFY(QApplication::topLevelWidgets().isEmpty()); } void tst_QSizeGrip::hideAndShowOnWindowStateChange_data() @@ -111,46 +101,45 @@ void tst_QSizeGrip::hideAndShowOnWindowStateChange() QSKIP("Broken on WinRT - QTBUG-68297"); #endif - QWidget *parentWidget = windowType == Qt::Window ? 0 : new QWidget; - TestWidget *widget = new TestWidget(parentWidget, Qt::WindowFlags(windowType)); - QSizeGrip *sizeGrip = new QSizeGrip(widget); + QScopedPointer<QWidget> parentWidget; + if (windowType != Qt::Window) + parentWidget.reset(new QWidget); + QScopedPointer<TestWidget> widget(new TestWidget(parentWidget.data(), Qt::WindowFlags(windowType))); + QSizeGrip *sizeGrip = new QSizeGrip(widget.data()); // Normal. if (parentWidget) parentWidget->show(); else widget->show(); - QVERIFY(sizeGrip->isVisible()); + QTRY_VERIFY(sizeGrip->isVisible()); widget->showFullScreen(); - QVERIFY(!sizeGrip->isVisible()); + QTRY_VERIFY(!sizeGrip->isVisible()); widget->showNormal(); - QVERIFY(sizeGrip->isVisible()); + QTRY_VERIFY(sizeGrip->isVisible()); widget->showMaximized(); #ifndef Q_OS_MAC - QVERIFY(!sizeGrip->isVisible()); + QTRY_VERIFY(!sizeGrip->isVisible()); #else QEXPECT_FAIL("", "QTBUG-23681", Abort); QVERIFY(sizeGrip->isVisible()); #endif widget->showNormal(); - QVERIFY(sizeGrip->isVisible()); + QTRY_VERIFY(sizeGrip->isVisible()); sizeGrip->hide(); - QVERIFY(!sizeGrip->isVisible()); + QTRY_VERIFY(!sizeGrip->isVisible()); widget->showFullScreen(); widget->showNormal(); - QVERIFY(!sizeGrip->isVisible()); + QTRY_VERIFY(!sizeGrip->isVisible()); widget->showMaximized(); widget->showNormal(); - QVERIFY(!sizeGrip->isVisible()); - - delete widget; - delete parentWidget; + QTRY_VERIFY(!sizeGrip->isVisible()); } void tst_QSizeGrip::orientation() @@ -196,10 +185,10 @@ void tst_QSizeGrip::dontCrashOnTLWChange() QMdiArea mdiArea; mdiArea.show(); - QMainWindow *mw = new QMainWindow(); - QMdiSubWindow *mdi = mdiArea.addSubWindow(mw); + QScopedPointer<QMainWindow> mw(new QMainWindow); + QMdiSubWindow *mdi = mdiArea.addSubWindow(mw.data()); mw->statusBar()->setSizeGripEnabled(true); - mdiArea.removeSubWindow(mw); + mdiArea.removeSubWindow(mw.data()); delete mdi; mw->show(); @@ -209,7 +198,7 @@ void tst_QSizeGrip::dontCrashOnTLWChange() QEXPECT_FAIL("", "Broken on WinRT - QTBUG-68297", Abort); #endif QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); - QVERIFY(QTest::qWaitForWindowExposed(mw)); + QVERIFY(QTest::qWaitForWindowExposed(mw.data())); } QTEST_MAIN(tst_QSizeGrip) diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp index 37bb28dec9..b9d6888263 100644 --- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp @@ -53,6 +53,8 @@ #include <QStyleOptionSpinBox> #include <QStyle> #include <QProxyStyle> +#include <QScreen> + class SpinBox : public QSpinBox { @@ -204,7 +206,7 @@ private slots: void stepModifierPressAndHold_data(); void stepModifierPressAndHold(); public slots: - void valueChangedHelper(const QString &); + void textChangedHelper(const QString &); void valueChangedHelper(int); private: QStringList actualTexts; @@ -343,6 +345,14 @@ tst_QSpinBox::tst_QSpinBox() void tst_QSpinBox::init() { QLocale::setDefault(QLocale(QLocale::C)); + +#if QT_CONFIG(cursor) + // Ensure mouse cursor was not left by previous tests where widgets + // will appear, as it could cause events and interfere with the tests. + const QScreen *screen = QGuiApplication::primaryScreen(); + const QRect availableGeometry = screen->availableGeometry(); + QCursor::setPos(availableGeometry.topLeft()); +#endif } void tst_QSpinBox::setValue_data() @@ -452,8 +462,11 @@ void tst_QSpinBox::setPrefixSuffix() QFETCH(bool, show); QSpinBox spin(0); + const QSize size1 = spin.sizeHint(); spin.setPrefix(prefix); + const QSize size2 = spin.sizeHint(); spin.setSuffix(suffix); + const QSize size3 = spin.sizeHint(); spin.setValue(value); if (show) spin.show(); @@ -462,9 +475,18 @@ void tst_QSpinBox::setPrefixSuffix() QCOMPARE(spin.suffix(), suffix); QCOMPARE(spin.text(), expectedText); QCOMPARE(spin.cleanText(), expectedCleanText); + + if (!prefix.isEmpty() && !suffix.isEmpty()) { + QVERIFY(size1.width() < size2.width()); + QVERIFY(size2.width() < size3.width()); + spin.setSuffix(QString()); + QCOMPARE(spin.sizeHint(), size2); + spin.setPrefix(QString()); + QCOMPARE(spin.sizeHint(), size1); + } } -void tst_QSpinBox::valueChangedHelper(const QString &text) +void tst_QSpinBox::textChangedHelper(const QString &text) { actualTexts << text; } @@ -542,7 +564,7 @@ void tst_QSpinBox::setTracking() QSpinBox spin(0); spin.setKeyboardTracking(tracking); spin.show(); - connect(&spin, SIGNAL(valueChanged(QString)), this, SLOT(valueChangedHelper(QString))); + connect(&spin, &QSpinBox::textChanged, this, &tst_QSpinBox::textChangedHelper); keys.simulate(&spin); QCOMPARE(actualTexts, texts); diff --git a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp index 5f5cd78215..3669935823 100644 --- a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp +++ b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp @@ -282,12 +282,12 @@ void tst_QTextEdit::getSetCheck() // int QTextEdit::tabStopWidth() // void QTextEdit::setTabStopWidth(int) - obj1.setTabStopWidth(0); - QCOMPARE(0, obj1.tabStopWidth()); - obj1.setTabStopWidth(INT_MIN); - QCOMPARE(0, obj1.tabStopWidth()); // Makes no sense to set a negative tabstop value - obj1.setTabStopWidth(INT_MAX); - QCOMPARE(INT_MAX, obj1.tabStopWidth()); + obj1.setTabStopDistance(0); + QCOMPARE(0, obj1.tabStopDistance()); + obj1.setTabStopDistance(-1); + QCOMPARE(0, obj1.tabStopDistance()); // Makes no sense to set a negative tabstop value + obj1.setTabStopDistance(std::numeric_limits<qreal>::max()); + QCOMPARE(std::numeric_limits<qreal>::max(), obj1.tabStopDistance()); // bool QTextEdit::acceptRichText() // void QTextEdit::setAcceptRichText(bool) diff --git a/tests/auto/widgets/widgets/qtoolbar/tst_qtoolbar.cpp b/tests/auto/widgets/widgets/qtoolbar/tst_qtoolbar.cpp index 301801ed2e..d6c165642e 100644 --- a/tests/auto/widgets/widgets/qtoolbar/tst_qtoolbar.cpp +++ b/tests/auto/widgets/widgets/qtoolbar/tst_qtoolbar.cpp @@ -42,6 +42,7 @@ #include <qlineedit.h> #include <qkeysequence.h> #include <qmenu.h> +#include <qlabel.h> #include <private/qtoolbarextension_p.h> QT_FORWARD_DECLARE_CLASS(QAction) @@ -80,6 +81,8 @@ private slots: void task191727_layout(); void task197996_visibility(); + + void extraCpuConsumption(); // QTBUG-54676 }; @@ -1098,5 +1101,81 @@ void tst_QToolBar::task197996_visibility() QTRY_VERIFY(toolBar->widgetForAction(pAction)->isVisible()); } +class ShowHideEventCounter : public QObject +{ +public: + using QObject::QObject; + + bool eventFilter(QObject *watched, QEvent *event) override + { + if (qobject_cast<QLineEdit*>(watched) && !event->spontaneous()) { + if (event->type() == QEvent::Show) + ++m_showEventsCount; + + if (event->type() == QEvent::Hide) + ++m_hideEventsCount; + } + + return QObject::eventFilter(watched, event); + } + + uint showEventsCount() const { return m_showEventsCount; } + uint hideEventsCount() const { return m_hideEventsCount; } + +private: + uint m_showEventsCount = 0; + uint m_hideEventsCount = 0; +}; + +void tst_QToolBar::extraCpuConsumption() +{ + QMainWindow mainWindow; + + auto tb = new QToolBar(&mainWindow); + tb->setMovable(false); + + auto extensions = tb->findChildren<QToolBarExtension *>(); + QVERIFY(!extensions.isEmpty()); + + auto extensionButton = extensions.at(0); + QVERIFY(extensionButton); + + tb->addWidget(new QLabel("Lorem ipsum dolor sit amet")); + + auto le = new QLineEdit; + le->setClearButtonEnabled(true); + le->setText("Lorem ipsum"); + tb->addWidget(le); + + mainWindow.addToolBar(tb); + mainWindow.show(); + QVERIFY(QTest::qWaitForWindowActive(&mainWindow)); + + auto eventCounter = new ShowHideEventCounter(&mainWindow); + le->installEventFilter(eventCounter); + + auto defaultSize = mainWindow.size(); + + // Line edit should be hidden now and extension button should be displayed + for (double p = 0.7; extensionButton->isHidden() || qFuzzyCompare(p, 0.); p -= 0.01) { + mainWindow.resize(int(defaultSize.width() * p), defaultSize.height()); + } + QVERIFY(!extensionButton->isHidden()); + + // Line edit should be visible, but smaller + for (double p = 0.75; !extensionButton->isHidden() || qFuzzyCompare(p, 1.); p += 0.01) { + mainWindow.resize(int(defaultSize.width() * p), defaultSize.height()); + } + QVERIFY(extensionButton->isHidden()); + + // Dispatch all pending events + qApp->sendPostedEvents(); + qApp->processEvents(); + + QCOMPARE(eventCounter->showEventsCount(), eventCounter->hideEventsCount()); + QCOMPARE(eventCounter->showEventsCount(), uint(1)); + QCOMPARE(eventCounter->hideEventsCount(), uint(1)); +} + QTEST_MAIN(tst_QToolBar) #include "tst_qtoolbar.moc" |