diff options
Diffstat (limited to 'tests/auto/widgets')
111 files changed, 3625 insertions, 3482 deletions
diff --git a/tests/auto/widgets/dialogs/qdialog/BLACKLIST b/tests/auto/widgets/dialogs/qdialog/BLACKLIST index dd6a8bfff9..72e3dff6dd 100644 --- a/tests/auto/widgets/dialogs/qdialog/BLACKLIST +++ b/tests/auto/widgets/dialogs/qdialog/BLACKLIST @@ -1,4 +1,4 @@ [snapToDefaultButton] -osx +osx-10.14 [showFullScreen] osx-10.13 ci diff --git a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp index c840dabc1a..a494d7119a 100644 --- a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp +++ b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp @@ -52,7 +52,9 @@ class DummyDialog : public QDialog { public: DummyDialog(): QDialog() {} +#if QT_DEPRECATED_SINCE(5, 13) using QDialog::showExtension; +#endif }; class tst_QDialog : public QObject @@ -64,8 +66,10 @@ public: private slots: void cleanup(); void getSetCheck(); +#if QT_DEPRECATED_SINCE(5, 13) void showExtension_data(); void showExtension(); +#endif void defaultButtons(); void showMaximized(); void showMinimized(); @@ -76,6 +80,9 @@ private slots: void deleteInExec(); #if QT_CONFIG(sizegrip) void showSizeGrip(); +#if QT_DEPRECATED_SINCE(5, 13) + void showSizeGrip_deprecated(); +#endif #endif void setVisible(); void reject(); @@ -89,6 +96,7 @@ private slots: void tst_QDialog::getSetCheck() { QDialog obj1; +#if QT_DEPRECATED_SINCE(5, 13) // QWidget* QDialog::extension() // void QDialog::setExtension(QWidget*) QWidget *var1 = new QWidget; @@ -97,6 +105,7 @@ void tst_QDialog::getSetCheck() obj1.setExtension((QWidget *)0); QCOMPARE((QWidget *)0, obj1.extension()); // No delete var1, since setExtension takes ownership +#endif // int QDialog::result() // void QDialog::setResult(int) @@ -146,6 +155,7 @@ void tst_QDialog::cleanup() QVERIFY(QApplication::topLevelWidgets().isEmpty()); } +#if QT_DEPRECATED_SINCE(5, 13) void tst_QDialog::showExtension_data() { QTest::addColumn<QSize>("dlgSize"); @@ -197,6 +207,7 @@ void tst_QDialog::showExtension() testWidget.setExtension( 0 ); } +#endif void tst_QDialog::defaultButtons() { @@ -422,9 +433,37 @@ void tst_QDialog::deleteInExec() } #if QT_CONFIG(sizegrip) + // From Task 124269 void tst_QDialog::showSizeGrip() { + QDialog dialog(nullptr); + dialog.show(); + QWidget *ext = new QWidget(&dialog); + QVERIFY(!dialog.isSizeGripEnabled()); + + dialog.setSizeGripEnabled(true); + QPointer<QSizeGrip> sizeGrip = dialog.findChild<QSizeGrip *>(); + QVERIFY(sizeGrip); + QVERIFY(sizeGrip->isVisible()); + QVERIFY(dialog.isSizeGripEnabled()); + + dialog.setSizeGripEnabled(false); + QVERIFY(!dialog.isSizeGripEnabled()); + + dialog.setSizeGripEnabled(true); + sizeGrip = dialog.findChild<QSizeGrip *>(); + QVERIFY(sizeGrip); + QVERIFY(sizeGrip->isVisible()); + sizeGrip->hide(); + dialog.hide(); + dialog.show(); + QVERIFY(!sizeGrip->isVisible()); +} + +#if QT_DEPRECATED_SINCE(5, 13) +void tst_QDialog::showSizeGrip_deprecated() +{ QDialog dialog(0); dialog.show(); QWidget *ext = new QWidget(&dialog); @@ -476,7 +515,9 @@ void tst_QDialog::showSizeGrip() dialog.show(); QVERIFY(!sizeGrip->isVisible()); } -#endif +#endif // QT_DEPRECATED_SINCE(5, 13) + +#endif // QT_CONFIG(sizegrip) void tst_QDialog::setVisible() { diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp index 748c8aaa84..2131e45f29 100644 --- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp @@ -800,7 +800,10 @@ void tst_QFiledialog::isReadOnly() QAction* renameAction = fd.findChild<QAction*>("qt_rename_action"); QAction* deleteAction = fd.findChild<QAction*>("qt_delete_action"); +#if QT_DEPRECATED_SINCE(5, 13) QCOMPARE(fd.isReadOnly(), false); +#endif + QCOMPARE(fd.testOption(QFileDialog::ReadOnly), false); // This is dependent upon the file/dir, find cross platform way to test //fd.setDirectory(QDir::home()); @@ -1421,6 +1424,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/BLACKLIST b/tests/auto/widgets/dialogs/qfiledialog2/BLACKLIST index e0887d8ad1..875855b59e 100644 --- a/tests/auto/widgets/dialogs/qfiledialog2/BLACKLIST +++ b/tests/auto/widgets/dialogs/qfiledialog2/BLACKLIST @@ -1,2 +1,4 @@ [QTBUG4419_lineEditSelectAll] -osx +osx-10.12 +osx-10.14 +osx-10.13 diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp index 869418371c..40eff1e4c3 100644 --- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp @@ -378,24 +378,24 @@ void tst_QFileDialog2::task143519_deleteAndRenameActionBehavior() // defaults QVERIFY(openContextMenu(fd)); QCOMPARE(fd.selectedFiles(), QStringList(ctx.file.fileName())); - QCOMPARE(rm->isEnabled(), !fd.isReadOnly()); - QCOMPARE(mv->isEnabled(), !fd.isReadOnly()); + QCOMPARE(rm->isEnabled(), !fd.testOption(QFileDialog::ReadOnly)); + QCOMPARE(mv->isEnabled(), !fd.testOption(QFileDialog::ReadOnly)); // change to non-defaults: - fd.setReadOnly(!fd.isReadOnly()); + fd.setOption(QFileDialog::ReadOnly, !fd.testOption(QFileDialog::ReadOnly)); QVERIFY(openContextMenu(fd)); QCOMPARE(fd.selectedFiles().size(), 1); - QCOMPARE(rm->isEnabled(), !fd.isReadOnly()); - QCOMPARE(mv->isEnabled(), !fd.isReadOnly()); + QCOMPARE(rm->isEnabled(), !fd.testOption(QFileDialog::ReadOnly)); + QCOMPARE(mv->isEnabled(), !fd.testOption(QFileDialog::ReadOnly)); // and changed back to defaults: - fd.setReadOnly(!fd.isReadOnly()); + fd.setOption(QFileDialog::ReadOnly, !fd.testOption(QFileDialog::ReadOnly)); QVERIFY(openContextMenu(fd)); QCOMPARE(fd.selectedFiles().size(), 1); - QCOMPARE(rm->isEnabled(), !fd.isReadOnly()); - QCOMPARE(mv->isEnabled(), !fd.isReadOnly()); + QCOMPARE(rm->isEnabled(), !fd.testOption(QFileDialog::ReadOnly)); + QCOMPARE(mv->isEnabled(), !fd.testOption(QFileDialog::ReadOnly)); } #endif // !QT_NO_CONTEXTMENU && !QT_NO_MENU diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST b/tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST index f78d23c6b1..aae2cacc3b 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/BLACKLIST @@ -1,13 +1,16 @@ winrt +[sort] +winrt [sort:QFileDialog usage] ubuntu b2qt [specialFiles] -ubuntu b2qt [dirsBeforeFiles] -ubuntu +winrt b2qt -windows +ubuntu +windows-10 rhel -suse-leap +[drives] +winrt diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index 665a116a3a..f8f40e8488 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -65,18 +65,18 @@ } \ } while(0) -class tst_QFileSystemModel : public QObject { - Q_OBJECT +Q_DECLARE_METATYPE(QDir::Filters) +Q_DECLARE_METATYPE(QFileDevice::Permissions) -public: - tst_QFileSystemModel(); +Q_LOGGING_CATEGORY(lcFileSystemModel, "qt.widgets.tests.qfilesystemmodel") -public Q_SLOTS: - void init(); - void cleanup(); +class tst_QFileSystemModel : public QObject { + Q_OBJECT private slots: void initTestCase(); + void cleanup(); + void indexPath(); void rootPath(); @@ -128,48 +128,33 @@ private slots: void fileInfo(); 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); + bool createFiles(QFileSystemModel *model, const QString &test_path, + const QStringList &initial_files, int existingFileCount = 0, + const QStringList &initial_dirs = QStringList()); + QModelIndex prepareTestModelRoot(QFileSystemModel *model, const QString &test_path, + QSignalSpy **spy2 = nullptr, QSignalSpy **spy3 = nullptr); private: - QFileSystemModel *model; QString flatDirTestPath; QTemporaryDir m_tempDir; }; -tst_QFileSystemModel::tst_QFileSystemModel() : model(0) -{ -} - -void tst_QFileSystemModel::init() -{ - cleanup(); - QCOMPARE(model, nullptr); - model = new QFileSystemModel; -} - void tst_QFileSystemModel::cleanup() { - delete model; - model = 0; - QString tmp = flatDirTestPath; - QDir dir(tmp); - if (dir.exists(tmp)) { - QStringList list = dir.entryList(QDir::AllEntries | QDir::System | QDir::Hidden | QDir::NoDotAndDotDot); - for (int i = 0; i < list.count(); ++i) { - QFileInfo fi(dir.path() + '/' + list.at(i)); - if (fi.exists() && fi.isFile()) { - QFile p(fi.absoluteFilePath()); - p.setPermissions(QFile::ReadUser | QFile::ReadOwner | QFile::ExeOwner | QFile::ExeUser | QFile::WriteUser | QFile::WriteOwner | QFile::WriteOther); - QFile dead(dir.path() + '/' + list.at(i)); - dead.remove(); + QDir dir(flatDirTestPath); + if (dir.exists()) { + const QDir::Filters filters = QDir::AllEntries | QDir::System | QDir::Hidden | QDir::NoDotAndDotDot; + const QFileInfoList list = dir.entryInfoList(filters); + for (const QFileInfo &fi : list) { + if (fi.isDir()) { + QVERIFY(dir.rmdir(fi.fileName())); + } else { + QFile dead(fi.absoluteFilePath()); + dead.setPermissions(QFile::ReadUser | QFile::ReadOwner | QFile::ExeOwner | QFile::ExeUser | QFile::WriteUser | QFile::WriteOwner | QFile::WriteOther); + QVERIFY(dead.remove()); } - if (fi.exists() && fi.isDir()) - QVERIFY(dir.rmdir(list.at(i))); } - list = dir.entryList(QDir::AllEntries | QDir::System | QDir::Hidden | QDir::NoDotAndDotDot); - QCOMPARE(list.count(), 0); + QVERIFY(dir.entryInfoList(filters).isEmpty()); } } @@ -182,6 +167,7 @@ void tst_QFileSystemModel::initTestCase() void tst_QFileSystemModel::indexPath() { #if !defined(Q_OS_WIN) + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); int depth = QDir::currentPath().count('/'); model->setRootPath(QDir::currentPath()); QString backPath; @@ -195,9 +181,10 @@ void tst_QFileSystemModel::indexPath() void tst_QFileSystemModel::rootPath() { + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); QCOMPARE(model->rootPath(), QString(QDir().path())); - QSignalSpy rootChanged(model, SIGNAL(rootPathChanged(QString))); + QSignalSpy rootChanged(model.data(), &QFileSystemModel::rootPathChanged); QModelIndex root = model->setRootPath(model->rootPath()); root = model->setRootPath("this directory shouldn't exist"); QCOMPARE(rootChanged.count(), 0); @@ -243,6 +230,7 @@ void tst_QFileSystemModel::rootPath() void tst_QFileSystemModel::readOnly() { + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); QCOMPARE(model->isReadOnly(), true); QTemporaryFile file(flatDirTestPath + QStringLiteral("/XXXXXX.dat")); QVERIFY2(file.open(), qPrintable(file.errorString())); @@ -263,19 +251,21 @@ void tst_QFileSystemModel::readOnly() class CustomFileIconProvider : public QFileIconProvider { public: - CustomFileIconProvider() : QFileIconProvider() { - mb = qApp->style()->standardIcon(QStyle::SP_MessageBoxCritical); - dvd = qApp->style()->standardIcon(QStyle::SP_DriveDVDIcon); + CustomFileIconProvider() : QFileIconProvider() + { + auto style = QApplication::style(); + mb = style->standardIcon(QStyle::SP_MessageBoxCritical); + dvd = style->standardIcon(QStyle::SP_DriveDVDIcon); } - virtual QIcon icon(const QFileInfo &info) const + QIcon icon(const QFileInfo &info) const override { if (info.isDir()) return mb; return QFileIconProvider::icon(info); } - virtual QIcon icon(IconType type) const + QIcon icon(IconType type) const override { if (type == QFileIconProvider::Folder) return dvd; @@ -289,69 +279,67 @@ private: void tst_QFileSystemModel::iconProvider() { + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); QVERIFY(model->iconProvider()); - QFileIconProvider *p = new QFileIconProvider(); - model->setIconProvider(p); - QCOMPARE(model->iconProvider(), p); - model->setIconProvider(0); - delete p; + QScopedPointer<QFileIconProvider> provider(new QFileIconProvider); + model->setIconProvider(provider.data()); + QCOMPARE(model->iconProvider(), provider.data()); + model->setIconProvider(nullptr); + provider.reset(); - QFileSystemModel *myModel = new QFileSystemModel(); + QScopedPointer<QFileSystemModel> myModel(new QFileSystemModel); const QStringList documentPaths = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); QVERIFY(!documentPaths.isEmpty()); - const QString documentPath = documentPaths.front(); - myModel->setRootPath(documentPath); + myModel->setRootPath(documentPaths.constFirst()); //We change the provider, icons must be updated - CustomFileIconProvider *custom = new CustomFileIconProvider(); - myModel->setIconProvider(custom); + provider.reset(new CustomFileIconProvider); + myModel->setIconProvider(provider.data()); - QPixmap mb = qApp->style()->standardIcon(QStyle::SP_MessageBoxCritical).pixmap(50, 50); + QPixmap mb = QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical).pixmap(50, 50); QCOMPARE(myModel->fileIcon(myModel->index(QDir::homePath())).pixmap(50, 50), mb); - delete myModel; - delete custom; } -bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount, const QStringList &initial_dirs) +bool tst_QFileSystemModel::createFiles(QFileSystemModel *model, const QString &test_path, + const QStringList &initial_files, int existingFileCount, + const QStringList &initial_dirs) { - //qDebug() << (model->rowCount(model->index(test_path))) << existingFileCount << initial_files; + qCDebug(lcFileSystemModel) << (model->rowCount(model->index(test_path))) << existingFileCount << initial_files; 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()) { - qWarning() << "error" << test_path << "doesn't exists"; - return false; - } - if(!dir.mkdir(initial_dirs.at(i))) { - qWarning() << "error" << "failed to make" << initial_dirs.at(i); + QDir dir(test_path); + if (!dir.exists()) { + qWarning() << "error" << test_path << "doesn't exist"; + return false; + } + for (const auto &initial_dir : initial_dirs) { + if (!dir.mkdir(initial_dir)) { + qWarning() << "error" << "failed to make" << initial_dir; return false; } - //qDebug() << test_path + '/' + initial_dirs.at(i) << (QFile::exists(test_path + '/' + initial_dirs.at(i))); + qCDebug(lcFileSystemModel) << test_path + '/' + initial_dir << (QFile::exists(test_path + '/' + initial_dir)); } - for (int i = 0; i < initial_files.count(); ++i) { - QFile file(test_path + '/' + initial_files.at(i)); + for (const auto &initial_file : initial_files) { + QFile file(test_path + '/' + initial_file); if (!file.open(QIODevice::WriteOnly | QIODevice::Append)) { - qDebug() << "failed to open file" << initial_files.at(i); + qDebug() << "failed to open file" << initial_file; return false; } if (!file.resize(1024 + file.size())) { - qDebug() << "failed to resize file" << initial_files.at(i); + qDebug() << "failed to resize file" << initial_file; return false; } if (!file.flush()) { - qDebug() << "failed to flush file" << initial_files.at(i); + qDebug() << "failed to flush file" << initial_file; return false; } file.close(); #if defined(Q_OS_WIN) - if (initial_files.at(i)[0] == '.') { - QString hiddenFile = QDir::toNativeSeparators(file.fileName()); - wchar_t nativeHiddenFile[MAX_PATH]; - memset(nativeHiddenFile, 0, sizeof(nativeHiddenFile)); - hiddenFile.toWCharArray(nativeHiddenFile); + if (initial_file[0] == '.') { + const QString hiddenFile = QDir::toNativeSeparators(file.fileName()); + const auto nativeHiddenFile = reinterpret_cast<const wchar_t *>(hiddenFile.utf16()); #ifndef Q_OS_WINRT DWORD currentAttributes = ::GetFileAttributes(nativeHiddenFile); #else // !Q_OS_WINRT @@ -370,13 +358,13 @@ bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringLi } } #endif - //qDebug() << test_path + '/' + initial_files.at(i) << (QFile::exists(test_path + '/' + initial_files.at(i))); + qCDebug(lcFileSystemModel) << test_path + '/' + initial_file << (QFile::exists(test_path + '/' + initial_file)); } return true; } -QModelIndex tst_QFileSystemModel::prepareTestModelRoot(const QString &test_path, QSignalSpy **spy2, - QSignalSpy **spy3) +QModelIndex tst_QFileSystemModel::prepareTestModelRoot(QFileSystemModel *model, const QString &test_path, + QSignalSpy **spy2, QSignalSpy **spy3) { if (model->rowCount(model->index(test_path)) != 0) return QModelIndex(); @@ -387,9 +375,8 @@ QModelIndex tst_QFileSystemModel::prepareTestModelRoot(const QString &test_path, *spy3 = new QSignalSpy(model, &QFileSystemModel::rowsAboutToBeInserted); QStringList files = { "b", "d", "f", "h", "j", ".a", ".c", ".e", ".g" }; - QString l = "b,d,f,h,j,.a,.c,.e,.g"; - if (!createFiles(test_path, files)) + if (!createFiles(model, test_path, files)) return QModelIndex(); QModelIndex root = model->setRootPath(test_path); @@ -406,10 +393,10 @@ QModelIndex tst_QFileSystemModel::prepareTestModelRoot(const QString &test_path, void tst_QFileSystemModel::rowCount() { - const QString tmp = flatDirTestPath; QSignalSpy *spy2 = nullptr; QSignalSpy *spy3 = nullptr; - QModelIndex root = prepareTestModelRoot(flatDirTestPath, &spy2, &spy3); + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QModelIndex root = prepareTestModelRoot(model.data(), flatDirTestPath, &spy2, &spy3); QVERIFY(root.isValid()); QVERIFY(spy2 && spy2->count() > 0); @@ -419,11 +406,11 @@ void tst_QFileSystemModel::rowCount() void tst_QFileSystemModel::rowsInserted_data() { QTest::addColumn<int>("count"); - QTest::addColumn<int>("ascending"); + QTest::addColumn<Qt::SortOrder>("ascending"); for (int i = 0; i < 4; ++i) { const QByteArray iB = QByteArray::number(i); - QTest::newRow(("Qt::AscendingOrder " + iB).constData()) << i << (int)Qt::AscendingOrder; - QTest::newRow(("Qt::DescendingOrder " + iB).constData()) << i << (int)Qt::DescendingOrder; + QTest::newRow(("Qt::AscendingOrder " + iB).constData()) << i << Qt::AscendingOrder; + QTest::newRow(("Qt::DescendingOrder " + iB).constData()) << i << Qt::DescendingOrder; } } @@ -436,20 +423,21 @@ static inline QString lastEntry(const QModelIndex &root) void tst_QFileSystemModel::rowsInserted() { const QString tmp = flatDirTestPath; - QModelIndex root = prepareTestModelRoot(tmp); + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QModelIndex root = prepareTestModelRoot(model.data(), tmp); QVERIFY(root.isValid()); - QFETCH(int, ascending); + QFETCH(Qt::SortOrder, ascending); QFETCH(int, count); - model->sort(0, (Qt::SortOrder)ascending); + model->sort(0, ascending); - QSignalSpy spy0(model, SIGNAL(rowsInserted(QModelIndex,int,int))); - QSignalSpy spy1(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int))); + QSignalSpy spy0(model.data(), &QAbstractItemModel::rowsInserted); + QSignalSpy spy1(model.data(), &QAbstractItemModel::rowsAboutToBeInserted); int oldCount = model->rowCount(root); QStringList files; for (int i = 0; i < count; ++i) files.append(QLatin1Char('c') + QString::number(i)); - QVERIFY(createFiles(tmp, files, 5)); + QVERIFY(createFiles(model.data(), tmp, files, 5)); QTRY_COMPARE(model->rowCount(root), oldCount + count); int totalRowsInserted = 0; for (int i = 0; i < spy0.count(); ++i) { @@ -469,7 +457,7 @@ void tst_QFileSystemModel::rowsInserted() } if (count == 0) QCOMPARE(spy1.count(), 0); else QVERIFY(spy1.count() >= 1); - QVERIFY(createFiles(tmp, QStringList(".hidden_file"), 5 + count)); + QVERIFY(createFiles(model.data(), tmp, QStringList(".hidden_file"), 5 + count)); if (count != 0) QTRY_VERIFY(spy0.count() >= 1); @@ -489,19 +477,21 @@ void tst_QFileSystemModel::rowsRemoved_data() void tst_QFileSystemModel::rowsRemoved() { const QString tmp = flatDirTestPath; - QModelIndex root = prepareTestModelRoot(tmp); + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QModelIndex root = prepareTestModelRoot(model.data(), tmp); QVERIFY(root.isValid()); QFETCH(int, count); - QFETCH(int, ascending); - model->sort(0, (Qt::SortOrder)ascending); + QFETCH(Qt::SortOrder, ascending); + model->sort(0, ascending); - QSignalSpy spy0(model, SIGNAL(rowsRemoved(QModelIndex,int,int))); - QSignalSpy spy1(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int))); + QSignalSpy spy0(model.data(), &QAbstractItemModel::rowsRemoved); + QSignalSpy spy1(model.data(), &QAbstractItemModel::rowsAboutToBeRemoved); int oldCount = model->rowCount(root); for (int i = count - 1; i >= 0; --i) { - //qDebug() << "removing" << model->index(i, 0, root).data().toString(); - QVERIFY(QFile::remove(tmp + '/' + model->index(i, 0, root).data().toString())); + const QString fileName = model->index(i, 0, root).data().toString(); + qCDebug(lcFileSystemModel) << "removing" << fileName; + QVERIFY(QFile::remove(tmp + QLatin1Char('/') + fileName)); } for (int i = 0 ; i < 10; ++i) { if (count != 0) { @@ -520,18 +510,23 @@ void tst_QFileSystemModel::rowsRemoved() lst.append(model->index(i, 0, root).data().toString()); if (model->rowCount(root) == oldCount - count) break; - qDebug() << "still have:" << lst << QFile::exists(tmp + '/' + QString(".a")); + qCDebug(lcFileSystemModel) << "still have:" << lst << QFile::exists(tmp + QLatin1String("/.a")); QDir tmpLister(tmp); - qDebug() << tmpLister.entryList(); + qCDebug(lcFileSystemModel) << tmpLister.entryList(); } QTRY_COMPARE(model->rowCount(root), oldCount - count); - QVERIFY(QFile::exists(tmp + '/' + QString(".a"))); - QVERIFY(QFile::remove(tmp + '/' + QString(".a"))); - QVERIFY(QFile::remove(tmp + '/' + QString(".c"))); + QVERIFY(QFile::exists(tmp + QLatin1String("/.a"))); + QVERIFY(QFile::remove(tmp + QLatin1String("/.a"))); + QVERIFY(QFile::remove(tmp + QLatin1String("/.c"))); - if (count != 0) QVERIFY(spy0.count() >= 1); else QCOMPARE(spy0.count(), 0); - if (count != 0) QVERIFY(spy1.count() >= 1); else QCOMPARE(spy1.count(), 0); + if (count != 0) { + QVERIFY(spy0.count() >= 1); + QVERIFY(spy1.count() >= 1); + } else { + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + } } void tst_QFileSystemModel::dataChanged_data() @@ -544,18 +539,19 @@ void tst_QFileSystemModel::dataChanged() QSKIP("This can't be tested right now since we don't watch files, only directories."); const QString tmp = flatDirTestPath; - QModelIndex root = prepareTestModelRoot(tmp); + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QModelIndex root = prepareTestModelRoot(model.data(), tmp); QVERIFY(root.isValid()); QFETCH(int, count); - QFETCH(int, assending); - model->sort(0, (Qt::SortOrder)assending); + QFETCH(Qt::SortOrder, ascending); + model->sort(0, ascending); - QSignalSpy spy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex))); + QSignalSpy spy(model.data(), &QAbstractItemModel::dataChanged); QStringList files; for (int i = 0; i < count; ++i) files.append(model->index(i, 0, root).data().toString()); - createFiles(tmp, files); + createFiles(model.data(), tmp, files); QTest::qWait(WAITTIME); @@ -566,64 +562,68 @@ void tst_QFileSystemModel::filters_data() { QTest::addColumn<QStringList>("files"); QTest::addColumn<QStringList>("dirs"); - QTest::addColumn<int>("dirFilters"); + QTest::addColumn<QDir::Filters>("dirFilters"); QTest::addColumn<QStringList>("nameFilters"); QTest::addColumn<int>("rowCount"); - QTest::newRow("no dirs") << (QStringList() << "a" << "b" << "c") << QStringList() << (int)(QDir::Dirs) << QStringList() << 2; - QTest::newRow("no dirs - dot") << (QStringList() << "a" << "b" << "c") << QStringList() << (int)(QDir::Dirs | QDir::NoDot) << QStringList() << 1; - QTest::newRow("no dirs - dotdot") << (QStringList() << "a" << "b" << "c") << QStringList() << (int)(QDir::Dirs | QDir::NoDotDot) << QStringList() << 1; - QTest::newRow("no dirs - dotanddotdot") << (QStringList() << "a" << "b" << "c") << QStringList() << (int)(QDir::Dirs | QDir::NoDotAndDotDot) << QStringList() << 0; - QTest::newRow("one dir - dot") << (QStringList() << "a" << "b" << "c") << (QStringList() << "Z") << (int)(QDir::Dirs | QDir::NoDot) << QStringList() << 2; - QTest::newRow("one dir - dotdot") << (QStringList() << "a" << "b" << "c") << (QStringList() << "Z") << (int)(QDir::Dirs | QDir::NoDotDot) << QStringList() << 2; - QTest::newRow("one dir - dotanddotdot") << (QStringList() << "a" << "b" << "c") << (QStringList() << "Z") << (int)(QDir::Dirs | QDir::NoDotAndDotDot) << QStringList() << 1; - QTest::newRow("one dir") << (QStringList() << "a" << "b" << "c") << (QStringList() << "Z") << (int)(QDir::Dirs) << QStringList() << 3; - QTest::newRow("no dir + hidden") << (QStringList() << "a" << "b" << "c") << QStringList() << (int)(QDir::Dirs | QDir::Hidden) << QStringList() << 2; - QTest::newRow("dir+hid+files") << (QStringList() << "a" << "b" << "c") << QStringList() << - (int)(QDir::Dirs | QDir::Files | QDir::Hidden) << QStringList() << 5; - QTest::newRow("dir+file+hid-dot .A") << (QStringList() << "a" << "b" << "c") << (QStringList() << ".A") << - (int)(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot) << QStringList() << 4; - QTest::newRow("dir+files+hid+dot A") << (QStringList() << "a" << "b" << "c") << (QStringList() << "AFolder") << - (int)(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot) << (QStringList() << "A*") << 2; - QTest::newRow("dir+files+hid+dot+cas1") << (QStringList() << "a" << "b" << "c") << (QStringList() << "Z") << - (int)(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot | QDir::CaseSensitive) << (QStringList() << "Z") << 1; - QTest::newRow("dir+files+hid+dot+cas2") << (QStringList() << "a" << "b" << "c") << (QStringList() << "Z") << - (int)(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot | QDir::CaseSensitive) << (QStringList() << "a") << 1; - QTest::newRow("dir+files+hid+dot+cas+alldir") << (QStringList() << "a" << "b" << "c") << (QStringList() << "Z") << - (int)(QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot | QDir::CaseSensitive | QDir::AllDirs) << (QStringList() << "Z") << 1; - - QTest::newRow("case sensitive") << (QStringList() << "Antiguagdb" << "Antiguamtd" - << "Antiguamtp" << "afghanistangdb" << "afghanistanmtd") - << QStringList() << (int)(QDir::Files) << QStringList() << 5; + + const QStringList abcList{QLatin1String("a"), QLatin1String("b"), QLatin1String("c")}; + const QStringList zList{QLatin1String("Z")}; + + QTest::newRow("no dirs") << abcList << QStringList() << QDir::Filters(QDir::Dirs) << QStringList() << 2; + QTest::newRow("no dirs - dot") << abcList << QStringList() << (QDir::Dirs | QDir::NoDot) << QStringList() << 1; + QTest::newRow("no dirs - dotdot") << abcList << QStringList() << (QDir::Dirs | QDir::NoDotDot) << QStringList() << 1; + QTest::newRow("no dirs - dotanddotdot") << abcList << QStringList() << (QDir::Dirs | QDir::NoDotAndDotDot) << QStringList() << 0; + QTest::newRow("one dir - dot") << abcList << zList << (QDir::Dirs | QDir::NoDot) << QStringList() << 2; + QTest::newRow("one dir - dotdot") << abcList << zList << (QDir::Dirs | QDir::NoDotDot) << QStringList() << 2; + QTest::newRow("one dir - dotanddotdot") << abcList << zList << (QDir::Dirs | QDir::NoDotAndDotDot) << QStringList() << 1; + QTest::newRow("one dir") << abcList << zList << QDir::Filters(QDir::Dirs) << QStringList() << 3; + QTest::newRow("no dir + hidden") << abcList << QStringList() << (QDir::Dirs | QDir::Hidden) << QStringList() << 2; + QTest::newRow("dir+hid+files") << abcList << QStringList() << + (QDir::Dirs | QDir::Files | QDir::Hidden) << QStringList() << 5; + QTest::newRow("dir+file+hid-dot .A") << abcList << QStringList{QLatin1String(".A")} << + (QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot) << QStringList() << 4; + QTest::newRow("dir+files+hid+dot A") << abcList << QStringList{QLatin1String("AFolder")} << + (QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot) << QStringList{QLatin1String("A*")} << 2; + QTest::newRow("dir+files+hid+dot+cas1") << abcList << zList << + (QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot | QDir::CaseSensitive) << zList << 1; + QTest::newRow("dir+files+hid+dot+cas2") << abcList << zList << + (QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot | QDir::CaseSensitive) << QStringList{QLatin1String("a")} << 1; + QTest::newRow("dir+files+hid+dot+cas+alldir") << abcList << zList << + (QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoDotAndDotDot | QDir::CaseSensitive | QDir::AllDirs) << zList << 1; + + QTest::newRow("case sensitive") << QStringList{QLatin1String("Antiguagdb"), QLatin1String("Antiguamtd"), + QLatin1String("Antiguamtp"), QLatin1String("afghanistangdb"), QLatin1String("afghanistanmtd")} + << QStringList() << QDir::Filters(QDir::Files) << QStringList() << 5; } void tst_QFileSystemModel::filters() { QString tmp = flatDirTestPath; - QVERIFY(createFiles(tmp, QStringList())); + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QVERIFY(createFiles(model.data(), tmp, QStringList())); QModelIndex root = model->setRootPath(tmp); QFETCH(QStringList, files); QFETCH(QStringList, dirs); - QFETCH(int, dirFilters); + QFETCH(QDir::Filters, dirFilters); QFETCH(QStringList, nameFilters); QFETCH(int, rowCount); if (nameFilters.count() > 0) model->setNameFilters(nameFilters); model->setNameFilterDisables(false); - model->setFilter((QDir::Filters)dirFilters); + model->setFilter(dirFilters); - QVERIFY(createFiles(tmp, files, 0, dirs)); + QVERIFY(createFiles(model.data(), tmp, files, 0, dirs)); QTRY_COMPARE(model->rowCount(root), rowCount); // Make sure that we do what QDir does QDir xFactor(tmp); - QDir::Filters filters = (QDir::Filters)dirFilters; QStringList dirEntries; if (nameFilters.count() > 0) - dirEntries = xFactor.entryList(nameFilters, filters); + dirEntries = xFactor.entryList(nameFilters, dirFilters); else - dirEntries = xFactor.entryList(filters); + dirEntries = xFactor.entryList(dirFilters); QCOMPARE(dirEntries.count(), rowCount); @@ -667,12 +667,13 @@ void tst_QFileSystemModel::nameFilters() { QStringList list; list << "a" << "b" << "c"; + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); model->setNameFilters(list); model->setNameFilterDisables(false); QCOMPARE(model->nameFilters(), list); QString tmp = flatDirTestPath; - QVERIFY(createFiles(tmp, list)); + QVERIFY(createFiles(model.data(), tmp, list)); QModelIndex root = model->setRootPath(tmp); QTRY_COMPARE(model->rowCount(root), 3); @@ -693,15 +694,17 @@ void tst_QFileSystemModel::setData_data() << QDir::temp().absolutePath() + '/' + "a" << false; */ + + const QStringList abcList{QLatin1String("a"), QLatin1String("b"), QLatin1String("c")}; QTest::newRow("in current dir") << QString() - << (QStringList() << "a" << "b" << "c") + << abcList << "a" << "d" << true; QTest::newRow("in subdir") << "s" - << (QStringList() << "a" << "b" << "c") + << abcList << "a" << "d" << true; @@ -709,7 +712,8 @@ void tst_QFileSystemModel::setData_data() void tst_QFileSystemModel::setData() { - QSignalSpy spy(model, SIGNAL(fileRenamed(QString,QString,QString))); + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QSignalSpy spy(model.data(), &QFileSystemModel::fileRenamed); QFETCH(QString, subdirName); QFETCH(QStringList, files); QFETCH(QString, oldFileName); @@ -722,7 +726,7 @@ void tst_QFileSystemModel::setData() QVERIFY(dir.mkdir(subdirName)); tmp.append('/' + subdirName); } - QVERIFY(createFiles(tmp, files)); + QVERIFY(createFiles(model.data(), tmp, files)); QModelIndex tmpIdx = model->setRootPath(flatDirTestPath); if (!subdirName.isEmpty()) { tmpIdx = model->index(tmp); @@ -760,6 +764,7 @@ void tst_QFileSystemModel::sortPersistentIndex() const QFileInfo fileInfo(file.fileName()); file.close(); QTRY_VERIFY(QDir(flatDirTestPath).entryInfoList().contains(fileInfo)); + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); QModelIndex root = model->setRootPath(flatDirTestPath); QTRY_VERIFY(model->rowCount(root) > 0); @@ -786,8 +791,9 @@ void tst_QFileSystemModel::sort() { QFETCH(bool, fileDialogMode); - MyFriendFileSystemModel *myModel = new MyFriendFileSystemModel(); - QTreeView *tree = new QTreeView(); + QScopedPointer<MyFriendFileSystemModel> myModel(new MyFriendFileSystemModel); + QTreeView tree; + tree.setWindowTitle(QTest::currentTestFunction()); if (fileDialogMode && EmulationDetector::isRunningArmOnX86()) QSKIP("Crashes in QEMU. QTBUG-70572"); @@ -816,24 +822,23 @@ void tst_QFileSystemModel::sort() myModel->setRootPath(""); myModel->setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); - tree->setSortingEnabled(true); - tree->setModel(myModel); - tree->show(); - tree->resize(800, 800); - QVERIFY(QTest::qWaitForWindowActive(tree)); - tree->header()->setSortIndicator(1,Qt::DescendingOrder); - tree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); + tree.setSortingEnabled(true); + tree.setModel(myModel.data()); + tree.show(); + tree.resize(800, 800); + QVERIFY(QTest::qWaitForWindowActive(&tree)); + tree.header()->setSortIndicator(1, Qt::DescendingOrder); + tree.header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); QStringList dirsToOpen; - do - { - dirsToOpen<<dir.absolutePath(); + do { + dirsToOpen << dir.absolutePath(); } while (dir.cdUp()); for (int i = dirsToOpen.size() -1 ; i > 0 ; --i) { QString path = dirsToOpen[i]; - tree->expand(myModel->index(path, 0)); + tree.expand(myModel->index(path, 0)); } - tree->expand(myModel->index(dirPath, 0)); + tree.expand(myModel->index(dirPath, 0)); QModelIndex parent = myModel->index(dirPath, 0); QList<QString> expectedOrder; expectedOrder << tempFile2.fileName() << tempFile.fileName() << dirPath + QChar('/') + ".." << dirPath + QChar('/') + "."; @@ -859,15 +864,13 @@ void tst_QFileSystemModel::sort() QTRY_COMPARE(dirPath + QChar('/') + myModel->index(i, 1, parent).data(QFileSystemModel::FileNameRole).toString(), expectedOrder.at(i)); } } - - delete tree; - delete myModel; } void tst_QFileSystemModel::mkdir() { QString tmp = flatDirTestPath; QString newFolderPath = QDir::toNativeSeparators(tmp + '/' + "NewFoldermkdirtest4"); + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); QModelIndex tmpDir = model->index(tmp); QVERIFY(tmpDir.isValid()); QDir bestatic(newFolderPath); @@ -902,6 +905,7 @@ void tst_QFileSystemModel::deleteFile() qWarning() << "unable to create" << newFilePath; } newFile.close(); + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); QModelIndex idx = model->index(newFilePath); QVERIFY(idx.isValid()); QVERIFY(model->remove(idx)); @@ -963,7 +967,8 @@ void tst_QFileSystemModel::caseSensitivity() QString tmp = flatDirTestPath; QStringList files; files << "a" << "c" << "C"; - QVERIFY(createFiles(tmp, files)); + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QVERIFY(createFiles(model.data(), tmp, files)); QModelIndex root = model->index(tmp); QStringList paths; QModelIndexList indexes; @@ -1013,13 +1018,14 @@ void tst_QFileSystemModel::dirsBeforeFiles() const int itemCount = 3; for (int i = 0; i < itemCount; ++i) { - QLatin1Char c('a' + i); - dir.mkdir(c + QLatin1String("-dir")); + QLatin1Char c('a' + char(i)); + QVERIFY(dir.mkdir(c + QLatin1String("-dir"))); QFile file(flatDirTestPath + QLatin1Char('/') + c + QLatin1String("-file")); - file.open(QIODevice::ReadWrite); + QVERIFY(file.open(QIODevice::ReadWrite)); file.close(); } + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); QModelIndex root = model->setRootPath(flatDirTestPath); // Wait for model to be notified by the file system watcher QTRY_COMPARE(model->rowCount(root), 2 * itemCount); @@ -1073,7 +1079,7 @@ static inline QByteArray permissionRowName(bool readOnly, int permission) void tst_QFileSystemModel::permissions_data() { - QTest::addColumn<int>("permissions"); + QTest::addColumn<QFileDevice::Permissions>("permissions"); QTest::addColumn<bool>("readOnly"); static const int permissions[] = { @@ -1081,22 +1087,23 @@ void tst_QFileSystemModel::permissions_data() QFile::ReadOwner, QFile::WriteOwner|QFile::ReadOwner, }; - for (size_t i = 0; i < sizeof permissions / sizeof *permissions; ++i) { - QTest::newRow(permissionRowName(false, permissions[i]).constData()) << permissions[i] << false; - QTest::newRow(permissionRowName(true, permissions[i]).constData()) << permissions[i] << true; + for (int permission : permissions) { + QTest::newRow(permissionRowName(false, permission).constData()) << QFileDevice::Permissions(permission) << false; + QTest::newRow(permissionRowName(true, permission).constData()) << QFileDevice::Permissions(permission) << true; } } void tst_QFileSystemModel::permissions() // checks QTBUG-20503 { - QFETCH(int, permissions); + QFETCH(QFileDevice::Permissions, permissions); QFETCH(bool, readOnly); const QString tmp = flatDirTestPath; const QString file = tmp + QLatin1String("/f"); - QVERIFY(createFiles(tmp, QStringList() << "f")); + QScopedPointer<QFileSystemModel> model(new QFileSystemModel); + QVERIFY(createFiles(model.data(), tmp, QStringList{QLatin1String("f")})); - QVERIFY(QFile::setPermissions(file, QFile::Permissions(permissions))); + QVERIFY(QFile::setPermissions(file, permissions)); const QModelIndex root = model->setRootPath(tmp); diff --git a/tests/auto/widgets/dialogs/qmessagebox/BLACKLIST b/tests/auto/widgets/dialogs/qmessagebox/BLACKLIST index da52809aad..8d8a7c2105 100644 --- a/tests/auto/widgets/dialogs/qmessagebox/BLACKLIST +++ b/tests/auto/widgets/dialogs/qmessagebox/BLACKLIST @@ -1,2 +1,4 @@ [defaultButton] -* +opensuse-leap +rhel-7.6 +ubuntu diff --git a/tests/auto/widgets/dialogs/qprogressdialog/BLACKLIST b/tests/auto/widgets/dialogs/qprogressdialog/BLACKLIST index 1789f51507..2b784414cd 100644 --- a/tests/auto/widgets/dialogs/qprogressdialog/BLACKLIST +++ b/tests/auto/widgets/dialogs/qprogressdialog/BLACKLIST @@ -1,2 +1,2 @@ [autoShow] -osx ci +osx-10.13 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/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp index 24cbd2e35c..6091975acb 100644 --- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp +++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp @@ -417,7 +417,7 @@ void tst_QWizard::setPixmap() QVERIFY(wizard.pixmap(QWizard::BannerPixmap).isNull()); QVERIFY(wizard.pixmap(QWizard::LogoPixmap).isNull()); QVERIFY(wizard.pixmap(QWizard::WatermarkPixmap).isNull()); - if (QSysInfo::macVersion() <= Q_MV_OSX(10, 13)) + if (QOperatingSystemVersion::current() <= QOperatingSystemVersion::MacOSHighSierra) QVERIFY(!wizard.pixmap(QWizard::BackgroundPixmap).isNull()); else QVERIFY(wizard.pixmap(QWizard::BackgroundPixmap).isNull()); @@ -425,7 +425,7 @@ void tst_QWizard::setPixmap() QVERIFY(page->pixmap(QWizard::BannerPixmap).isNull()); QVERIFY(page->pixmap(QWizard::LogoPixmap).isNull()); QVERIFY(page->pixmap(QWizard::WatermarkPixmap).isNull()); - if (QSysInfo::macVersion() <= Q_MV_OSX(10, 13)) + if (QOperatingSystemVersion::current() <= QOperatingSystemVersion::MacOSHighSierra) QVERIFY(!wizard.pixmap(QWizard::BackgroundPixmap).isNull()); else QVERIFY(page->pixmap(QWizard::BackgroundPixmap).isNull()); diff --git a/tests/auto/widgets/effects/qgraphicseffect/BLACKLIST b/tests/auto/widgets/effects/qgraphicseffect/BLACKLIST index 4833af527f..64a92d18aa 100644 --- a/tests/auto/widgets/effects/qgraphicseffect/BLACKLIST +++ b/tests/auto/widgets/effects/qgraphicseffect/BLACKLIST @@ -1,3 +1,2 @@ [prepareGeometryChangeInvalidateCache] -opensuse -opensuse-leap +opensuse-42.3 diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro b/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro index ae6de48195..16818a98f9 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro @@ -5,4 +5,4 @@ QT += core-private gui-private SOURCES += tst_qgraphicsitem.cpp DEFINES += QT_NO_CAST_TO_ASCII -win32:!winrt: LIBS += -luser32 +win32:!winrt: QMAKE_USE += user32 diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 670dc0b808..af0dd9b0f0 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -272,6 +272,9 @@ class tst_QGraphicsItem : public QObject { Q_OBJECT +public: + static void initMain(); + private slots: void construction(); void constructionWithParent(); @@ -474,6 +477,14 @@ private: QTouchDevice *m_touchDevice = nullptr; }; +void tst_QGraphicsItem::initMain() +{ +#ifdef Q_OS_WIN + // Ensure minimum size constraints of framed windows on High DPI screens + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +#endif +} + void tst_QGraphicsItem::construction() { for (int i = 0; i < 7; ++i) { @@ -4440,15 +4451,19 @@ protected: break; case QGraphicsItem::ItemPositionHasChanged: break; +#if QT_DEPRECATED_SINCE(5, 14) case QGraphicsItem::ItemMatrixChange: { +#if QT_DEPRECATED_SINCE(5, 13) QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED QVariant variant; variant.setValue<QMatrix>(matrix()); oldValues << variant; QT_WARNING_POP +#endif } break; +#endif case QGraphicsItem::ItemTransformChange: { QVariant variant; variant.setValue<QTransform>(transform()); @@ -4566,6 +4581,7 @@ void tst_QGraphicsItem::itemChange() QCOMPARE(tester.oldValues.last(), QVariant(true)); QCOMPARE(tester.isEnabled(), true); } +#if QT_DEPRECATED_SINCE(5, 13) { QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED // QDesktopWidget::screen() @@ -4585,6 +4601,7 @@ QT_WARNING_DISABLE_DEPRECATED // QDesktopWidget::screen() QCOMPARE(tester.matrix(), QMatrix().rotate(90)); QT_WARNING_POP } +#endif { tester.resetTransform(); ++changeCount; @@ -8397,7 +8414,7 @@ void tst_QGraphicsItem::focusProxy() QString err; QTextStream stream(&err); stream << "QGraphicsItem::setFocusProxy: " - << (void*)item << " is already in the focus proxy chain" << flush; + << (void*)item << " is already in the focus proxy chain" << Qt::flush; QTest::ignoreMessage(QtWarningMsg, err.toLatin1().constData()); item2->setFocusProxy(item); // fails QCOMPARE(item->focusProxy(), (QGraphicsItem *)item2); @@ -10960,7 +10977,7 @@ static QList<QTouchEvent::TouchPoint> tp.setStartScreenPos(screenPos); tp.setLastScreenPos(screenPos); tp.setEllipseDiameters(ellipseDiameters); - const QSizeF screenSize = QApplication::desktop()->screenGeometry(&view).size(); + const QSizeF screenSize = view.screen()->geometry().size(); tp.setNormalizedPos(QPointF(screenPos.x() / screenSize.width(), screenPos.y() / screenSize.height())); return QList<QTouchEvent::TouchPoint>() << tp; } 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/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 4a301337ef..a437b05479 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -330,7 +330,7 @@ public: { // Make sure QGraphicsProxyWidget::paint does not modify the render hints set on the painter. painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform - | QPainter::NonCosmeticDefaultPen | QPainter::TextAntialiasing); + | QPainter::TextAntialiasing); const QPainter::RenderHints oldRenderHints = painter->renderHints(); QGraphicsProxyWidget::paint(painter, option, widget); QCOMPARE(painter->renderHints(), oldRenderHints); @@ -463,14 +463,13 @@ void tst_QGraphicsProxyWidget::setWidget() QCOMPARE(proxy->focusPolicy(), Qt::WheelFocus); QVERIFY(proxy->acceptDrops()); QCOMPARE(proxy->acceptHoverEvents(), true); // to get widget enter events - int left, top, right, bottom; - widget->getContentsMargins(&left, &top, &right, &bottom); + const QMarginsF margins = QMarginsF{widget->contentsMargins()}; qreal rleft, rtop, rright, rbottom; proxy->getContentsMargins(&rleft, &rtop, &rright, &rbottom); - QCOMPARE((qreal)left, rleft); - QCOMPARE((qreal)top, rtop); - QCOMPARE((qreal)right, rright); - QCOMPARE((qreal)bottom, rbottom); + QCOMPARE(margins.left(), rleft); + QCOMPARE(margins.top(), rtop); + QCOMPARE(margins.right(), rright); + QCOMPARE(margins.bottom(), rbottom); } else { // proxy shouldn't mess with the widget if it can't insert it. QCOMPARE(proxy->widget(), nullptr); @@ -2769,9 +2768,6 @@ void tst_QGraphicsProxyWidget::windowOpacity() // disabled on platforms without alpha channel support in QPixmap (e.g., // X11 without XRender). int paints = 0; -#if 0 // Used to be included in Qt4 for Q_WS_X11 - paints = !X11->use_xrender; -#endif QTRY_COMPARE(eventSpy.counts[QEvent::UpdateRequest], 0); QTRY_COMPARE(eventSpy.counts[QEvent::Paint], paints); diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST index b8b427b3dd..c3797c9d57 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST @@ -1,13 +1,5 @@ [isActive] opensuse-42.3 ci -[removeFullyTransparentItem] -osx-10.12 [tabFocus_sceneWithNestedFocusWidgets] -opensuse -opensuse-leap -[inputMethod] -opensuse -opensuse-leap -[hoverEvents_parentChild] -ubuntu +opensuse-42.3 diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/qgraphicsscene.pro b/tests/auto/widgets/graphicsview/qgraphicsscene/qgraphicsscene.pro index 351cecd92e..2f648a2212 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/qgraphicsscene.pro +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/qgraphicsscene.pro @@ -4,7 +4,7 @@ QT += widgets widgets-private testlib QT += core-private gui-private SOURCES += tst_qgraphicsscene.cpp RESOURCES += images.qrc -win32:!winrt: LIBS += -luser32 +win32:!winrt: QMAKE_USE += user32 DEFINES += SRCDIR=\\\"$$PWD\\\" DEFINES += QT_NO_CAST_TO_ASCII diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 4f8741a5aa..4d24814724 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -26,11 +26,24 @@ ** ****************************************************************************/ +#include <QtWidgets/QApplication> +#include <QtWidgets/QDial> +#include <QtWidgets/QLabel> +#include <QtWidgets/QLineEdit> +#include <QtWidgets/QGraphicsView> +#include <QtWidgets/QGraphicsScene> +#include <QtWidgets/QGraphicsPixmapItem> +#include <QtWidgets/QStyle> +#include <QtWidgets/QStyleFactory> +#include <QtWidgets/QVBoxLayout> + +#include <QtGui/QScreen> #include <QtTest/QtTest> -#include <QtGui> -#include <QtWidgets> +#include <QtCore/QDebug> +#include <QtCore/QLoggingCategory> + #include <private/qgraphicsscene_p.h> #include <private/qgraphicssceneindex_p.h> #include <math.h> @@ -39,7 +52,7 @@ #include <private/qinputmethod_p.h> #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) -#include <windows.h> +#include <QtCore/qt_windows.h> #define Q_CHECK_PAINTEVENTS \ if (::SwitchDesktop(::GetThreadDesktop(::GetCurrentThreadId())) == 0) \ QSKIP("The Graphics View doesn't get the paint events"); @@ -51,6 +64,7 @@ Q_DECLARE_METATYPE(Qt::FocusReason) Q_DECLARE_METATYPE(QPainterPath) Q_DECLARE_METATYPE(Qt::AspectRatioMode) Q_DECLARE_METATYPE(Qt::ItemSelectionMode) +Q_DECLARE_METATYPE(QGraphicsItem::GraphicsItemFlags) static const int randomX[] = {276, 40, 250, 864, -56, 426, 855, 825, 184, 955, -798, -804, 773, 282, 489, 686, 780, -220, 50, 749, -856, -205, 81, 492, -819, 518, @@ -95,14 +109,16 @@ static const int randomY[] = {603, 70, -318, 843, 450, -637, 199, -527, 407, 964 -588, 864, 234, 225, -303, 493, 246, 153, 338, -378, 377, -819, 140, 136, 467, -849, -326, -533, 166, 252, -994, -699, 904, -566, 621, -752}; +Q_LOGGING_CATEGORY(lcTests, "qt.widgets.tests") + class HoverItem : public QGraphicsRectItem { public: HoverItem() - : QGraphicsRectItem(QRectF(-10, -10, 20, 20)), isHovered(false) + : QGraphicsRectItem(QRectF(-10, -10, 20, 20)) { setAcceptHoverEvents(true); } - bool isHovered; + bool isHovered = false; protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) @@ -128,13 +144,13 @@ class EventSpy : public QGraphicsWidget Q_OBJECT public: EventSpy(QObject *watched, QEvent::Type type) - : _count(0), spied(type) + : spied(type) { watched->installEventFilter(this); } EventSpy(QGraphicsScene *scene, QGraphicsItem *watched, QEvent::Type type) - : _count(0), spied(type) + : spied(type) { scene->addItem(this); watched->installSceneEventFilter(this); @@ -143,7 +159,7 @@ public: int count() const { return _count; } protected: - bool eventFilter(QObject *watched, QEvent *event) + bool eventFilter(QObject *watched, QEvent *event) override { Q_UNUSED(watched); if (event->type() == spied) @@ -151,7 +167,7 @@ protected: return false; } - bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) + bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override { Q_UNUSED(watched); if (event->type() == spied) @@ -159,13 +175,17 @@ protected: return false; } - int _count; - QEvent::Type spied; + int _count = 0; + const QEvent::Type spied; }; class tst_QGraphicsScene : public QObject { Q_OBJECT +public: + tst_QGraphicsScene(); + static void initMain() { QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); } + public slots: void cleanup(); @@ -268,13 +288,26 @@ private slots: void taskQTBUG_15977_renderWithDeviceCoordinateCache(); void taskQTBUG_16401_focusItem(); void taskQTBUG_42915_focusNextPrevChild(); + +private: + QRect m_availableGeometry = QGuiApplication::primaryScreen()->availableGeometry(); + QSize m_testSize; }; +tst_QGraphicsScene::tst_QGraphicsScene() +{ + const int testSize = qMax(200, m_availableGeometry.width() / 10); + m_testSize.setWidth(testSize); + m_testSize.setHeight(testSize); +} + void tst_QGraphicsScene::cleanup() { // ensure not even skipped tests with custom input context leave it dangling - QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); - inputMethodPrivate->testContext = 0; + QInputMethodPrivate *inputMethodPrivate = + QInputMethodPrivate::get(QGuiApplication::inputMethod()); + inputMethodPrivate->testContext = nullptr; + QTRY_VERIFY(QApplication::topLevelWidgets().isEmpty()); } void tst_QGraphicsScene::construction() @@ -287,7 +320,7 @@ void tst_QGraphicsScene::construction() QVERIFY(scene.items(QPolygonF()).isEmpty()); QVERIFY(scene.items(QPainterPath()).isEmpty()); QTest::ignoreMessage(QtWarningMsg, "QGraphicsScene::collidingItems: cannot find collisions for null item"); - QVERIFY(scene.collidingItems(0).isEmpty()); + QVERIFY(scene.collidingItems(nullptr).isEmpty()); QVERIFY(scene.items(QPointF()).isEmpty()); QVERIFY(scene.selectedItems().isEmpty()); QVERIFY(!scene.focusItem()); @@ -301,7 +334,7 @@ static inline const QGraphicsItem *itemAt(const QGraphicsScene &scene, qreal x, void tst_QGraphicsScene::sceneRect() { QGraphicsScene scene; - QSignalSpy sceneRectChanged(&scene, SIGNAL(sceneRectChanged(QRectF))); + QSignalSpy sceneRectChanged(&scene, &QGraphicsScene::sceneRectChanged); QCOMPARE(scene.sceneRect(), QRectF()); QCOMPARE(sceneRectChanged.count(), 0); @@ -435,9 +468,9 @@ void tst_QGraphicsScene::items() scene.removeItem(items.at(5)); delete items.at(5); - QVERIFY(!scene.items().contains(0)); + QVERIFY(!scene.items().contains(nullptr)); delete items.at(7); - QVERIFY(!scene.items().contains(0)); + QVERIFY(!scene.items().contains(nullptr)); } { QGraphicsScene scene; @@ -516,7 +549,7 @@ void tst_QGraphicsScene::itemsBoundingRect() QGraphicsScene scene; - foreach (QRectF rect, rects) { + for (const auto &rect : qAsConst(rects)) { QPainterPath path; path.addRect(rect); QGraphicsPathItem *item = scene.addPath(path); @@ -581,7 +614,7 @@ void tst_QGraphicsScene::items_QPointF() int n = 0; QList<QGraphicsItem *> addedItems; - foreach(QRectF rect, items) { + for (const auto &rect : qAsConst(items)) { QPainterPath path; path.addRect(0, 0, rect.width(), rect.height()); @@ -593,7 +626,8 @@ void tst_QGraphicsScene::items_QPointF() } QList<int> itemIndexes; - foreach (QGraphicsItem *item, scene.items(point)) + const auto &actualItemsAtPoint = scene.items(point); + for (QGraphicsItem *item : actualItemsAtPoint) itemIndexes << addedItems.indexOf(item); QCOMPARE(itemIndexes, itemsAtPoint); @@ -912,12 +946,11 @@ void tst_QGraphicsScene::items_QPainterPath_2() class CustomView : public QGraphicsView { public: - CustomView() : repaints(0) - { } + using QGraphicsView::QGraphicsView; - int repaints; + int repaints = 0; protected: - void paintEvent(QPaintEvent *event) + void paintEvent(QPaintEvent *event) override { ++repaints; QGraphicsView::paintEvent(event); @@ -927,7 +960,7 @@ protected: void tst_QGraphicsScene::selectionChanged() { QGraphicsScene scene(0, 0, 1000, 1000); - QSignalSpy spy(&scene, SIGNAL(selectionChanged())); + QSignalSpy spy(&scene, &QGraphicsScene::selectionChanged); QCOMPARE(spy.count(), 0); QPainterPath path; @@ -997,7 +1030,7 @@ void tst_QGraphicsScene::selectionChanged() void tst_QGraphicsScene::selectionChanged2() { QGraphicsScene scene; - QSignalSpy spy(&scene, SIGNAL(selectionChanged())); + QSignalSpy spy(&scene, &QGraphicsScene::selectionChanged); QGraphicsItem *item1 = scene.addRect(0, 0, 100, 100); QGraphicsItem *item2 = scene.addRect(100, 100, 100, 100); @@ -1009,13 +1042,13 @@ void tst_QGraphicsScene::selectionChanged2() QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); event.setScenePos(QPointF(50, 50)); event.setButton(Qt::LeftButton); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); event.setScenePos(QPointF(50, 50)); event.setButton(Qt::LeftButton); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -1024,13 +1057,13 @@ void tst_QGraphicsScene::selectionChanged2() QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); event.setScenePos(QPointF(150, 150)); event.setButton(Qt::LeftButton); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); event.setScenePos(QPointF(150, 150)); event.setButton(Qt::LeftButton); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } QVERIFY(!item1->isSelected()); QVERIFY(item2->isSelected()); @@ -1040,7 +1073,7 @@ void tst_QGraphicsScene::selectionChanged2() event.setScenePos(QPointF(50, 50)); event.setButton(Qt::LeftButton); event.setModifiers(Qt::ControlModifier); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } QVERIFY(!item1->isSelected()); QVERIFY(item2->isSelected()); @@ -1049,7 +1082,7 @@ void tst_QGraphicsScene::selectionChanged2() QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); event.setScenePos(QPointF(50, 50)); event.setButton(Qt::LeftButton); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -1065,10 +1098,12 @@ void tst_QGraphicsScene::addItem() QGraphicsScene scene; CustomView view; + view.setWindowTitle(QTest::currentTestFunction()); view.setScene(&scene); + view.resize(m_testSize); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - qApp->processEvents(); + QCoreApplication::processEvents(); view.repaints = 0; scene.addItem(path); @@ -1115,14 +1150,14 @@ void tst_QGraphicsScene::addEllipse() QCOMPARE(ellipse->pen(), QPen(Qt::red)); QCOMPARE(ellipse->brush(), QBrush(Qt::blue)); QCOMPARE(ellipse->rect(), QRectF(-10, -10, 20, 20)); - QCOMPARE(itemAt(scene, 0, 0), (QGraphicsItem *)ellipse); + QCOMPARE(itemAt(scene, 0, 0), ellipse); QVERIFY(scene.items(QPointF(-10, -10)).isEmpty()); - QCOMPARE(itemAt(scene, -9.9, 0), (QGraphicsItem *)ellipse); + QCOMPARE(itemAt(scene, -9.9, 0), ellipse); QVERIFY(scene.items(QPointF(-10, 10)).isEmpty()); - QCOMPARE(itemAt(scene, 0, -9.9), (QGraphicsItem *)ellipse); - QCOMPARE(itemAt(scene, 0, 9.9), (QGraphicsItem *)ellipse); + QCOMPARE(itemAt(scene, 0, -9.9), ellipse); + QCOMPARE(itemAt(scene, 0, 9.9), ellipse); QVERIFY(scene.items(QPointF(10, -10)).isEmpty()); - QCOMPARE(itemAt(scene, 9.9, 0), (QGraphicsItem *)ellipse); + QCOMPARE(itemAt(scene, 9.9, 0), ellipse); QVERIFY(scene.items(QPointF(10, 10)).isEmpty()); } @@ -1136,15 +1171,15 @@ void tst_QGraphicsScene::addLine() QCOMPARE(line->pos(), QPointF()); QCOMPARE(line->pen(), pen); QCOMPARE(line->line(), QLineF(-10, -10, 20, 20)); - QCOMPARE(itemAt(scene, 0, 0), (QGraphicsItem *)line); - QCOMPARE(itemAt(scene, -10, -10), (QGraphicsItem *)line); + QCOMPARE(itemAt(scene, 0, 0), line); + QCOMPARE(itemAt(scene, -10, -10), line); QVERIFY(scene.items(QPointF(-9.9, 0)).isEmpty()); QVERIFY(scene.items(QPointF(-10, 10)).isEmpty()); QVERIFY(scene.items(QPointF(0, -9.9)).isEmpty()); QVERIFY(scene.items(QPointF(0, 9.9)).isEmpty()); QVERIFY(scene.items(QPointF(10, -10)).isEmpty()); QVERIFY(scene.items(QPointF(9.9, 0)).isEmpty()); - QCOMPARE(itemAt(scene, 10, 10), (QGraphicsItem *)line); + QCOMPARE(itemAt(scene, 10, 10), line); } void tst_QGraphicsScene::addPath() @@ -1162,16 +1197,16 @@ void tst_QGraphicsScene::addPath() path->setPen(QPen(Qt::red, 0)); - QCOMPARE(itemAt(scene, 0, 0), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, -9.9, 0), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, 9.9, 0), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, 0, -9.9), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, 0, 9.9), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, 0, 30), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, -9.9, 30), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, 9.9, 30), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, 0, 20.1), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, 0, 39.9), (QGraphicsItem *)path); + QCOMPARE(itemAt(scene, 0, 0), path); + QCOMPARE(itemAt(scene, -9.9, 0), path); + QCOMPARE(itemAt(scene, 9.9, 0), path); + QCOMPARE(itemAt(scene, 0, -9.9), path); + QCOMPARE(itemAt(scene, 0, 9.9), path); + QCOMPARE(itemAt(scene, 0, 30), path); + QCOMPARE(itemAt(scene, -9.9, 30), path); + QCOMPARE(itemAt(scene, 9.9, 30), path); + QCOMPARE(itemAt(scene, 0, 20.1), path); + QCOMPARE(itemAt(scene, 0, 39.9), path); QVERIFY(scene.items(QPointF(-10, -10)).isEmpty()); QVERIFY(scene.items(QPointF(10, -10)).isEmpty()); QVERIFY(scene.items(QPointF(-10, 10)).isEmpty()); @@ -1193,10 +1228,10 @@ void tst_QGraphicsScene::addPixmap() QCOMPARE(pixmap->pos(), QPointF()); QCOMPARE(pixmap->pixmap(), pix); - QCOMPARE(itemAt(scene, 0, 0), (QGraphicsItem *)pixmap); - QCOMPARE(itemAt(scene, pix.width() - 1, 0), (QGraphicsItem *)pixmap); - QCOMPARE(itemAt(scene, 0, pix.height() - 1), (QGraphicsItem *)pixmap); - QCOMPARE(itemAt(scene, pix.width() - 1, pix.height() - 1), (QGraphicsItem *)pixmap); + QCOMPARE(itemAt(scene, 0, 0), pixmap); + QCOMPARE(itemAt(scene, pix.width() - 1, 0), pixmap); + QCOMPARE(itemAt(scene, 0, pix.height() - 1), pixmap); + QCOMPARE(itemAt(scene, pix.width() - 1, pix.height() - 1), pixmap); QVERIFY(scene.items(QPointF(-1, -1)).isEmpty()); QVERIFY(scene.items(QPointF(pix.width() - 1, -1)).isEmpty()); @@ -1218,14 +1253,14 @@ void tst_QGraphicsScene::addRect() rect->setPen(QPen(Qt::red, 0)); - QCOMPARE(itemAt(scene, 0, 0), (QGraphicsItem *)rect); - QCOMPARE(itemAt(scene, -10, -10), (QGraphicsItem *)rect); - QCOMPARE(itemAt(scene, -9.9, 0), (QGraphicsItem *)rect); + QCOMPARE(itemAt(scene, 0, 0),rect); + QCOMPARE(itemAt(scene, -10, -10), rect); + QCOMPARE(itemAt(scene, -9.9, 0), rect); QVERIFY(scene.items(QPointF(-10, 10)).isEmpty()); - QCOMPARE(itemAt(scene, 0, -9.9), (QGraphicsItem *)rect); - QCOMPARE(itemAt(scene, 0, 9.9), (QGraphicsItem *)rect); + QCOMPARE(itemAt(scene, 0, -9.9), rect); + QCOMPARE(itemAt(scene, 0, 9.9), rect); QVERIFY(scene.items(QPointF(10, -10)).isEmpty()); - QCOMPARE(itemAt(scene, 9.9, 0), (QGraphicsItem *)rect); + QCOMPARE(itemAt(scene, 9.9, 0), rect); QVERIFY(scene.items(QPointF(10, 10)).isEmpty()); } @@ -1271,6 +1306,7 @@ void tst_QGraphicsScene::removeItem() scene.setSceneRect(-50, -50, 100, 100); QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); view.setFixedSize(150, 150); view.show(); QApplication::setActiveWindow(&view); @@ -1342,7 +1378,7 @@ void tst_QGraphicsScene::focusItem() class FocusItem : public QGraphicsTextItem { protected: - void focusOutEvent(QFocusEvent *) + void focusOutEvent(QFocusEvent *) override { QVERIFY(!scene()->focusItem()); } @@ -1359,14 +1395,14 @@ void tst_QGraphicsScene::focusItemLostFocus() scene.addItem(item); item->setFocus(); - QCOMPARE(scene.focusItem(), (QGraphicsItem *)item); + QCOMPARE(scene.focusItem(), item); item->clearFocus(); } class ClearTestItem : public QGraphicsRectItem { public: - ClearTestItem(QGraphicsItem *parent = 0) : QGraphicsRectItem(parent) {} + using QGraphicsRectItem::QGraphicsRectItem; ~ClearTestItem() { qDeleteAll(items); } QList<QGraphicsItem *> items; }; @@ -1389,7 +1425,7 @@ void tst_QGraphicsScene::clear() scene.setItemIndexMethod(QGraphicsScene::NoIndex); scene.addItem(firstItem); scene.addItem(secondItem); - QCOMPARE(scene.items().at(0), (QGraphicsItem*)firstItem); + QCOMPARE(scene.items().at(0), firstItem); QCOMPARE(scene.items().at(1), secondItem); ClearTestItem *thirdItem = new ClearTestItem(firstItem); @@ -1441,7 +1477,7 @@ void tst_QGraphicsScene::setFocusItem() QVERIFY(item->hasFocus()); QVERIFY(!item2->hasFocus()); - scene.setFocusItem(0); + scene.setFocusItem(nullptr); QVERIFY(!item->hasFocus()); QVERIFY(!item2->hasFocus()); @@ -1562,26 +1598,26 @@ void tst_QGraphicsScene::hoverEvents_siblings() Q_CHECK_PAINTEVENTS QGraphicsScene scene; - QGraphicsItem *lastItem = 0; + QGraphicsItem *lastItem = nullptr; QList<HoverItem *> items; for (int i = 0; i < 15; ++i) { - QGraphicsItem *item = new HoverItem; + auto item = new HoverItem; scene.addItem(item); - items << (HoverItem *)item; - if (lastItem) { + items << item; + if (lastItem) item->setPos(lastItem->pos() + QPointF(sin(i / 3.0) * 17, cos(i / 3.0) * 17)); - } item->setZValue(i); lastItem = item; } QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); view.setRenderHint(QPainter::Antialiasing, true); view.setMinimumSize(400, 300); view.rotate(10); view.scale(1.7, 1.7); view.show(); - qApp->setActiveWindow(&view); + QApplication::setActiveWindow(&view); view.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -1604,8 +1640,8 @@ void tst_QGraphicsScene::hoverEvents_siblings() mouseEvent.setScenePos(items.at(i)->mapToScene(0, 0)); QApplication::sendEvent(&scene, &mouseEvent); - qApp->processEvents(); // this posts updates from the scene to the view - qApp->processEvents(); // which trigger a repaint here + QCoreApplication::processEvents(); // this posts updates from the scene to the view + QCoreApplication::processEvents(); // which trigger a repaint here QTRY_VERIFY(items.at(i)->isHovered); if (j && i > 0) @@ -1621,8 +1657,8 @@ void tst_QGraphicsScene::hoverEvents_siblings() mouseEvent.setScenePos(QPointF(-1000, -1000)); QApplication::sendEvent(&scene, &mouseEvent); - qApp->processEvents(); // this posts updates from the scene to the view - qApp->processEvents(); // which trigger a repaint here + QCoreApplication::processEvents(); // this posts updates from the scene to the view + QCoreApplication::processEvents(); // which trigger a repaint here } } @@ -1631,12 +1667,12 @@ void tst_QGraphicsScene::hoverEvents_parentChild() Q_CHECK_PAINTEVENTS QGraphicsScene scene; - QGraphicsItem *lastItem = 0; + QGraphicsItem *lastItem = nullptr; QList<HoverItem *> items; for (int i = 0; i < 15; ++i) { - QGraphicsItem *item = new HoverItem; + auto item = new HoverItem; scene.addItem(item); - items << (HoverItem *)item; + items << item; if (lastItem) { item->setParentItem(lastItem); item->setPos(sin(i / 3.0) * 17, cos(i / 3.0) * 17); @@ -1645,12 +1681,13 @@ void tst_QGraphicsScene::hoverEvents_parentChild() } QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); view.setRenderHint(QPainter::Antialiasing, true); view.setMinimumSize(400, 300); view.rotate(10); view.scale(1.7, 1.7); view.show(); - qApp->setActiveWindow(&view); + QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); @@ -1669,8 +1706,8 @@ void tst_QGraphicsScene::hoverEvents_parentChild() mouseEvent.setScenePos(items.at(i)->mapToScene(0, 0)); QApplication::sendEvent(&scene, &mouseEvent); - qApp->processEvents(); // this posts updates from the scene to the view - qApp->processEvents(); // which trigger a repaint here + QCoreApplication::processEvents(); // this posts updates from the scene to the view + QCoreApplication::processEvents(); // which trigger a repaint here QTRY_VERIFY(items.at(i)->isHovered); if (i < 14) @@ -1683,8 +1720,8 @@ void tst_QGraphicsScene::hoverEvents_parentChild() mouseEvent.setScenePos(QPointF(-1000, -1000)); QApplication::sendEvent(&scene, &mouseEvent); - qApp->processEvents(); // this posts updates from the scene to the view - qApp->processEvents(); // which trigger a repaint here + QCoreApplication::processEvents(); // this posts updates from the scene to the view + QCoreApplication::processEvents(); // which trigger a repaint here } } @@ -1712,23 +1749,23 @@ void tst_QGraphicsScene::createItemGroup() // All items in children1 are children of parent1 QGraphicsItem *parent1 = scene.addRect(QRectF(-10, -10, 20, 20)); - foreach (QGraphicsItem *item, children1) + for (QGraphicsItem *item : qAsConst(children1)) item->setParentItem(parent1); QGraphicsItemGroup *group = scene.createItemGroup(children1); QCOMPARE(group->parentItem(), parent1); - QCOMPARE(children1.first()->parentItem(), (QGraphicsItem *)group); + QCOMPARE(children1.first()->parentItem(), group); scene.destroyItemGroup(group); QCOMPARE(children1.first()->parentItem(), parent1); group = scene.createItemGroup(children1); QCOMPARE(group->parentItem(), parent1); - QCOMPARE(children1.first()->parentItem(), (QGraphicsItem *)group); + QCOMPARE(children1.first()->parentItem(), group); scene.destroyItemGroup(group); QCOMPARE(children1.first()->parentItem(), parent1); // All items in children2 are children of parent2 QGraphicsItem *parent2 = scene.addRect(QRectF(-10, -10, 20, 20)); - foreach (QGraphicsItem *item, children2) + for (QGraphicsItem *item : qAsConst(children2)) item->setParentItem(parent2); // Now make parent2 a child of parent1, so all children2 are also children @@ -1738,21 +1775,21 @@ void tst_QGraphicsScene::createItemGroup() // The children2 group should still have parent2 as their common ancestor. group = scene.createItemGroup(children2); QCOMPARE(group->parentItem(), parent2); - QCOMPARE(children2.first()->parentItem(), (QGraphicsItem *)group); + QCOMPARE(children2.first()->parentItem(), group); scene.destroyItemGroup(group); QCOMPARE(children2.first()->parentItem(), parent2); // But the set of both children2 and children1 share only parent1. group = scene.createItemGroup(children2 + children1); QCOMPARE(group->parentItem(), parent1); - QCOMPARE(children1.first()->parentItem(), (QGraphicsItem *)group); - QCOMPARE(children2.first()->parentItem(), (QGraphicsItem *)group); + QCOMPARE(children1.first()->parentItem(), group); + QCOMPARE(children2.first()->parentItem(), group); scene.destroyItemGroup(group); QCOMPARE(children1.first()->parentItem(), parent1); QCOMPARE(children2.first()->parentItem(), parent1); // Fixup the parent-child chain - foreach (QGraphicsItem *item, children2) + for (QGraphicsItem *item : qAsConst(children2)) item->setParentItem(parent2); // These share no common parent @@ -1762,7 +1799,7 @@ void tst_QGraphicsScene::createItemGroup() // Make children3 children of parent3 QGraphicsItem *parent3 = scene.addRect(QRectF(-10, -10, 20, 20)); - foreach (QGraphicsItem *item, children3) + for (QGraphicsItem *item : qAsConst(children3)) item->setParentItem(parent3); // These should have parent3 as a parent @@ -1794,15 +1831,14 @@ void tst_QGraphicsScene::createItemGroup() class EventTester : public QGraphicsEllipseItem { public: - EventTester() - : QGraphicsEllipseItem(QRectF(-10, -10, 20, 20)), ignoreMouse(false) + EventTester() : QGraphicsEllipseItem(QRectF(-10, -10, 20, 20)) { } - bool ignoreMouse; - QList<QEvent::Type> eventTypes; + bool ignoreMouse = false; + QVector<QEvent::Type> eventTypes; protected: - bool sceneEvent(QEvent *event) + bool sceneEvent(QEvent *event) override { eventTypes << QEvent::Type(event->type()); switch (event->type()) { @@ -1813,6 +1849,7 @@ protected: event->ignore(); return true; } + break; default: break; } @@ -1867,7 +1904,7 @@ void tst_QGraphicsScene::mouseEventPropagation() QCOMPARE(c->eventTypes.size(), 0); QCOMPARE(b->eventTypes.size(), 0); QCOMPARE(a->eventTypes.size(), 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)d); + QCOMPARE(scene.mouseGrabberItem(), d); // Send a move QApplication::sendEvent(&scene, &moveEvent); @@ -1876,7 +1913,7 @@ void tst_QGraphicsScene::mouseEventPropagation() QCOMPARE(c->eventTypes.size(), 0); QCOMPARE(b->eventTypes.size(), 0); QCOMPARE(a->eventTypes.size(), 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)d); + QCOMPARE(scene.mouseGrabberItem(), d); // Send a release QApplication::sendEvent(&scene, &releaseEvent); @@ -1898,7 +1935,7 @@ void tst_QGraphicsScene::mouseEventPropagation() QCOMPARE(c->eventTypes.at(1), QEvent::GraphicsSceneMousePress); QCOMPARE(b->eventTypes.size(), 0); QCOMPARE(a->eventTypes.size(), 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)c); + QCOMPARE(scene.mouseGrabberItem(), c); // Send another press, with a button that isn't actually accepted QApplication::sendEvent(&scene, &pressEvent); @@ -1908,7 +1945,7 @@ void tst_QGraphicsScene::mouseEventPropagation() QCOMPARE(c->eventTypes.at(2), QEvent::GraphicsSceneMousePress); QCOMPARE(b->eventTypes.size(), 0); QCOMPARE(a->eventTypes.size(), 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)c); + QCOMPARE(scene.mouseGrabberItem(), c); // Send a move QApplication::sendEvent(&scene, &moveEvent); @@ -1917,7 +1954,7 @@ void tst_QGraphicsScene::mouseEventPropagation() QCOMPARE(c->eventTypes.at(3), QEvent::GraphicsSceneMouseMove); QCOMPARE(b->eventTypes.size(), 0); QCOMPARE(a->eventTypes.size(), 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)c); + QCOMPARE(scene.mouseGrabberItem(), c); // Send a release QApplication::sendEvent(&scene, &releaseEvent); @@ -1950,7 +1987,7 @@ void tst_QGraphicsScene::mouseEventPropagation() QCOMPARE(c->eventTypes.at(7), QEvent::GraphicsSceneMousePress); QCOMPARE(b->eventTypes.size(), 0); QCOMPARE(a->eventTypes.size(), 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)c); + QCOMPARE(scene.mouseGrabberItem(), c); // Clicking outside the items removes the mouse grabber } @@ -1999,7 +2036,7 @@ void tst_QGraphicsScene::mouseEventPropagation_ignore() QCOMPARE(d->eventTypes.at(0), QEvent::GrabMouse); QCOMPARE(d->eventTypes.at(1), QEvent::GraphicsSceneMousePress); QCOMPARE(d->eventTypes.at(2), QEvent::UngrabMouse); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)a); + QCOMPARE(scene.mouseGrabberItem(), a); a->ignoreMouse = true; @@ -2115,7 +2152,7 @@ public: QVector<QPointF> mouseMovePoints; protected: - void mouseMoveEvent(QGraphicsSceneMouseEvent *event) + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override { mouseMovePoints << event->scenePos(); } @@ -2140,22 +2177,17 @@ void tst_QGraphicsScene::mouseEventPropagation_mouseMove() class DndTester : public QGraphicsEllipseItem { public: - DndTester(const QRectF &rect) - : QGraphicsEllipseItem(rect), lastEvent(0), - ignoresDragEnter(false), ignoresDragMove(false) - - { - } + using QGraphicsEllipseItem::QGraphicsEllipseItem; ~DndTester() { delete lastEvent; } - QGraphicsSceneDragDropEvent *lastEvent; + QGraphicsSceneDragDropEvent *lastEvent = nullptr; QList<QEvent::Type> eventList; - bool ignoresDragEnter; - bool ignoresDragMove; + bool ignoresDragEnter = false; + bool ignoresDragMove = false; protected: void dragEnterEvent(QGraphicsSceneDragDropEvent *event) @@ -2218,21 +2250,21 @@ void tst_QGraphicsScene::dragAndDrop_simple() QMimeData mimeData; // Initial drag enter for the scene - QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragEnter); QVERIFY(dragEnter.isAccepted()); QCOMPARE(dragEnter.dropAction(), Qt::CopyAction); { // Move outside the item - QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); } { // Move inside the item without setAcceptDrops - QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); @@ -2241,7 +2273,7 @@ void tst_QGraphicsScene::dragAndDrop_simple() item->setAcceptDrops(true); { // Move inside the item with setAcceptDrops - QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); @@ -2255,7 +2287,7 @@ void tst_QGraphicsScene::dragAndDrop_simple() } { // Another move inside the item - QDragMoveEvent dragMove(view.mapFromScene(item->mapToScene(5, 5)), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(item->mapToScene(5, 5)), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); @@ -2268,7 +2300,7 @@ void tst_QGraphicsScene::dragAndDrop_simple() } { // Move outside the item - QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); @@ -2281,7 +2313,7 @@ void tst_QGraphicsScene::dragAndDrop_simple() } { // Move inside the item again - QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); @@ -2295,7 +2327,7 @@ void tst_QGraphicsScene::dragAndDrop_simple() } { // Drop inside the item - QDropEvent drop(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDropEvent drop(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &drop); QVERIFY(drop.isAccepted()); QCOMPARE(drop.dropAction(), Qt::CopyAction); @@ -2322,13 +2354,13 @@ void tst_QGraphicsScene::dragAndDrop_disabledOrInvisible() QMimeData mimeData; // Initial drag enter for the scene - QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragEnter); QVERIFY(dragEnter.isAccepted()); QCOMPARE(dragEnter.dropAction(), Qt::CopyAction); { // Move inside the item - QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); @@ -2338,7 +2370,7 @@ void tst_QGraphicsScene::dragAndDrop_disabledOrInvisible() } { // Move outside the item - QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); @@ -2353,7 +2385,7 @@ void tst_QGraphicsScene::dragAndDrop_disabledOrInvisible() { // Move inside the item - QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); @@ -2369,7 +2401,7 @@ void tst_QGraphicsScene::dragAndDrop_disabledOrInvisible() { // Move inside the item - QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); @@ -2378,7 +2410,7 @@ void tst_QGraphicsScene::dragAndDrop_disabledOrInvisible() } // Dummy drop event to keep the Mac from crashing. - QDropEvent dropEvent(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDropEvent dropEvent(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dropEvent); } @@ -2405,14 +2437,14 @@ void tst_QGraphicsScene::dragAndDrop_propagate() QMimeData mimeData; // Initial drag enter for the scene - QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragEnter); QVERIFY(dragEnter.isAccepted()); QCOMPARE(dragEnter.dropAction(), Qt::CopyAction); { // Move outside the items - QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); @@ -2421,7 +2453,7 @@ void tst_QGraphicsScene::dragAndDrop_propagate() } { // Move inside item1 - QDragMoveEvent dragMove(view.mapFromScene(-5, -5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(-5, -5), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); @@ -2432,7 +2464,7 @@ void tst_QGraphicsScene::dragAndDrop_propagate() { // Move into the intersection item1-item2 - QDragMoveEvent dragMove(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); // move does not propagate, (ignoresDragMove = true) QCOMPARE(item1->eventList.size(), 3); @@ -2443,7 +2475,7 @@ void tst_QGraphicsScene::dragAndDrop_propagate() } { // Move into the item2 - QDragMoveEvent dragMove(view.mapFromScene(15, 15), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(15, 15), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); @@ -2453,7 +2485,7 @@ void tst_QGraphicsScene::dragAndDrop_propagate() } { // Move inside item1 - QDragMoveEvent dragMove(view.mapFromScene(-5, -5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(-5, -5), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); @@ -2467,7 +2499,7 @@ void tst_QGraphicsScene::dragAndDrop_propagate() { item2->ignoresDragEnter = true; // Move into the intersection item1-item2 - QDragMoveEvent dragMove(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(dragMove.isAccepted()); // dragEnter propagates down to item1, which then accepts the move event. QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); @@ -2480,7 +2512,7 @@ void tst_QGraphicsScene::dragAndDrop_propagate() { item2->ignoresDragEnter = false; // Drop on the intersection item1-item2 - QDropEvent drop(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDropEvent drop(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &drop); QVERIFY(drop.isAccepted()); QCOMPARE(drop.dropAction(), Qt::CopyAction); @@ -2491,7 +2523,7 @@ void tst_QGraphicsScene::dragAndDrop_propagate() } // Dummy drop event to keep the Mac from crashing. - QDropEvent dropEvent(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDropEvent dropEvent(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dropEvent); } #endif @@ -2580,6 +2612,8 @@ void tst_QGraphicsScene::render() pix.fill(Qt::blue); QGraphicsView view; + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); QGraphicsScene scene(&view); scene.addEllipse(QRectF(-10, -10, 20, 20), QPen(Qt::black, 0), QBrush(Qt::white)); scene.addEllipse(QRectF(-2, -7, 4, 4), QPen(Qt::black, 0), QBrush(Qt::yellow))->setZValue(1); @@ -2642,6 +2676,7 @@ void tst_QGraphicsScene::render() gridLayout->addWidget(newLabel, 2, 0); QWidget widget; + widget.setWindowTitle(QTest::currentTestFunction()); widget.setLayout(gridLayout); widget.show(); @@ -2660,33 +2695,32 @@ void tst_QGraphicsScene::renderItemsWithNegativeWidthOrHeight() #if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) || defined(Q_OS_WINRT) QSKIP("Test only works on platforms with resizable windows"); #endif - - QGraphicsScene scene(0, 0, 150, 150); + QGraphicsScene scene(0, 0, m_testSize.width(), m_testSize.height()); // Add item with negative width. - QGraphicsRectItem *item1 = new QGraphicsRectItem(0, 0, -150, 50); + QGraphicsRectItem *item1 = new QGraphicsRectItem(0, 0, -m_testSize.width(), 50); item1->setBrush(Qt::red); - item1->setPos(150, 50); + item1->setPos(m_testSize.width(), 50); scene.addItem(item1); // Add item with negative height. - QGraphicsRectItem *item2 = new QGraphicsRectItem(0, 0, 50, -150); + QGraphicsRectItem *item2 = new QGraphicsRectItem(0, 0, 50, -m_testSize.height()); item2->setBrush(Qt::blue); - item2->setPos(50, 150); + item2->setPos(50, m_testSize.height()); scene.addItem(item2); QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); view.setFrameStyle(QFrame::NoFrame); - view.resize(150, 150); view.show(); - QCOMPARE(view.viewport()->size(), QSize(150, 150)); + QTRY_COMPARE(view.viewport()->size(), m_testSize); QImage expected(view.viewport()->size(), QImage::Format_RGB32); view.viewport()->render(&expected); // Make sure the scene background is the same as the viewport background. scene.setBackgroundBrush(view.viewport()->palette().brush(view.viewport()->backgroundRole())); - QImage actual(150, 150, QImage::Format_RGB32); + QImage actual(m_testSize, QImage::Format_RGB32); QPainter painter(&actual); scene.render(&painter); painter.end(); @@ -2710,6 +2744,8 @@ void tst_QGraphicsScene::contextMenuEvent() QVERIFY(scene.hasFocus()); QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); view.show(); view.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -2726,11 +2762,11 @@ void tst_QGraphicsScene::contextMenuEvent() class ContextMenuItem : public QGraphicsRectItem { public: - ContextMenuItem() : QGraphicsRectItem(0, 0, 100, 100) + ContextMenuItem(const QSize &s) : QGraphicsRectItem(0, 0, s.width(), s.height()) { setBrush(Qt::red); } protected: - void contextMenuEvent(QGraphicsSceneContextMenuEvent *) + void contextMenuEvent(QGraphicsSceneContextMenuEvent *) override { /* just accept */ } }; @@ -2740,26 +2776,30 @@ void tst_QGraphicsScene::contextMenuEvent_ItemIgnoresTransformations() QSKIP("Test fails on some Android devices (QTBUG-44430)"); #endif - QGraphicsScene scene(0, 0, 200, 200); - ContextMenuItem *item = new ContextMenuItem; + QGraphicsScene scene(0, 0, m_testSize.width(), m_testSize.height()); + const QSize itemSize = m_testSize / 2; + ContextMenuItem *item = new ContextMenuItem(itemSize); item->setFlag(QGraphicsItem::ItemIgnoresTransformations); scene.addItem(item); QWidget topLevel; + topLevel.setWindowTitle(QTest::currentTestFunction()); + topLevel.resize(m_testSize); QGraphicsView view(&scene, &topLevel); - view.resize(200, 200); topLevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); + + { - QPoint pos(50, 50); + QPoint pos(itemSize.width() / 2, itemSize.height() / 2); QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.viewport()->mapToGlobal(pos)); event.ignore(); QApplication::sendEvent(view.viewport(), &event); QVERIFY(event.isAccepted()); } { - QPoint pos(150, 150); + QPoint pos(itemSize.width() * 3 / 2, itemSize.height() * 3 / 2); QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.viewport()->mapToGlobal(pos)); event.ignore(); QApplication::sendEvent(view.viewport(), &event); @@ -2767,14 +2807,14 @@ void tst_QGraphicsScene::contextMenuEvent_ItemIgnoresTransformations() } view.scale(1.5, 1.5); { - QPoint pos(25, 25); + QPoint pos(itemSize.width() / 4, itemSize.height() / 4); QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.viewport()->mapToGlobal(pos)); event.ignore(); QApplication::sendEvent(view.viewport(), &event); QVERIFY(event.isAccepted()); } { - QPoint pos(55, 55); + QPoint pos(itemSize.width() / 2 + 5, itemSize.height() / 2 + 5); QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.viewport()->mapToGlobal(pos)); event.ignore(); QApplication::sendEvent(view.viewport(), &event); @@ -2790,14 +2830,14 @@ void tst_QGraphicsScene::update() QGraphicsRectItem *rect = new QGraphicsRectItem(0, 0, 100, 100); rect->setPen(QPen(Qt::black, 0)); scene.addItem(rect); - qApp->processEvents(); + QCoreApplication::processEvents(); rect->setPos(-100, -100); // This function forces indexing itemAt(scene, 0, 0); qRegisterMetaType<QList<QRectF> >("QList<QRectF>"); - QSignalSpy spy(&scene, SIGNAL(changed(QList<QRectF>))); + QSignalSpy spy(&scene, &QGraphicsScene::changed); // We update the scene. scene.update(); @@ -2806,12 +2846,13 @@ void tst_QGraphicsScene::update() itemAt(scene, 0, 0); // This will process the pending update - QApplication::instance()->processEvents(); + QCoreApplication::processEvents(); // Check that the update region is correct QCOMPARE(spy.count(), 1); QRectF region; - foreach (QRectF rectF, qvariant_cast<QList<QRectF> >(spy.at(0).at(0))) + const auto &rects = qvariant_cast<QList<QRectF> >(spy.at(0).at(0)); + for (const auto &rectF : rects) region |= rectF; QCOMPARE(region, QRectF(-100, -100, 200, 200)); } @@ -2821,9 +2862,11 @@ void tst_QGraphicsScene::update2() QGraphicsScene scene; scene.setSceneRect(-200, -200, 200, 200); CustomView view; + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); view.setScene(&scene); view.show(); - qApp->setActiveWindow(&view); + QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(view.repaints >= 1); view.repaints = 0; @@ -2831,13 +2874,13 @@ void tst_QGraphicsScene::update2() // Make sure QGraphicsScene::update only requires one event-loop iteration // before the view is updated. scene.update(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTRY_COMPARE(view.repaints, 1); view.repaints = 0; // The same for partial scene updates. scene.update(QRectF(-100, -100, 100, 100)); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(view.repaints, 1); } @@ -2853,7 +2896,7 @@ void tst_QGraphicsScene::views() QCOMPARE(scene.views().size(), 2); QVERIFY(scene.views().contains(&view1)); - view.setScene(0); + view.setScene(nullptr); QCOMPARE(scene.views().size(), 1); QCOMPARE(scene.views().at(0), &view1); @@ -2871,12 +2914,12 @@ void tst_QGraphicsScene::views() class CustomScene : public QGraphicsScene { public: - CustomScene() : gotTimerEvent(false) + CustomScene() { startTimer(10); } - bool gotTimerEvent; + bool gotTimerEvent = false; protected: - void timerEvent(QTimerEvent *) + void timerEvent(QTimerEvent *) override { gotTimerEvent = true; } @@ -2893,7 +2936,7 @@ void tst_QGraphicsScene::testEvent() class DisabledItemTester : public QGraphicsRectItem { public: - DisabledItemTester(const QRectF &rect, QGraphicsItem *parent = 0) + DisabledItemTester(const QRectF &rect, QGraphicsItem *parent = nullptr) : QGraphicsRectItem(rect, parent) { } @@ -2901,13 +2944,13 @@ public: QList<QEvent::Type> receivedSceneEventFilters; protected: - bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) + bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override { receivedSceneEventFilters << event->type(); return QGraphicsRectItem::sceneEventFilter(watched, event); } - bool sceneEvent(QEvent *event) + bool sceneEvent(QEvent *event) override { receivedSceneEvents << event->type(); return QGraphicsRectItem::sceneEvent(event); @@ -2965,11 +3008,9 @@ void tst_QGraphicsScene::eventsToDisabledItems() class ExposedPixmapItem : public QGraphicsPixmapItem { public: - ExposedPixmapItem(QGraphicsItem *item = 0) - : QGraphicsPixmapItem(item) - { } + using QGraphicsPixmapItem::QGraphicsPixmapItem; - void paint(QPainter *, const QStyleOptionGraphicsItem *option, QWidget *) + void paint(QPainter *, const QStyleOptionGraphicsItem *option, QWidget *) override { exposed = option->exposedRect; } @@ -3013,8 +3054,9 @@ void tst_QGraphicsScene::tabFocus_emptyScene() QWidget widget; widget.setLayout(layout); + widget.setWindowTitle(QTest::currentTestFunction()); widget.show(); - qApp->setActiveWindow(&widget); + QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -3060,9 +3102,10 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusableItems() layout->addWidget(dial2); QWidget widget; + widget.setWindowTitle(QTest::currentTestFunction()); widget.setLayout(layout); widget.show(); - qApp->setActiveWindow(&widget); + QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -3112,18 +3155,18 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusableItems() QVERIFY(!view->viewport()->hasFocus()); QVERIFY(!scene.hasFocus()); QVERIFY(!item->hasFocus()); - QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); + QCOMPARE(scene.focusItem(), item); // Check that the correct item regains focus. widget.show(); - qApp->setActiveWindow(&widget); + QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); QVERIFY(view->hasFocus()); QTRY_VERIFY(scene.isActive()); QVERIFY(view->viewport()->hasFocus()); QVERIFY(scene.hasFocus()); - QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); + QCOMPARE(scene.focusItem(), item); QVERIFY(item->hasFocus()); } @@ -3131,14 +3174,13 @@ class FocusWidget : public QGraphicsWidget { Q_OBJECT public: - FocusWidget(QGraphicsItem *parent = 0) - : QGraphicsWidget(parent), tabs(0), backTabs(0) + FocusWidget(QGraphicsItem *parent = nullptr) : QGraphicsWidget(parent) { setFocusPolicy(Qt::StrongFocus); resize(100, 100); } - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) override { if (option->state & QStyle::State_HasFocus) { painter->fillRect(rect(), Qt::blue); @@ -3152,11 +3194,11 @@ public: } } - int tabs; - int backTabs; + int tabs = 0; + int backTabs = 0; protected: - bool sceneEvent(QEvent *event) + bool sceneEvent(QEvent *event) override { if (event->type() == QEvent::KeyPress) { QKeyEvent *k = static_cast<QKeyEvent *>(event); @@ -3168,9 +3210,9 @@ protected: return QGraphicsWidget::sceneEvent(event); } - void focusInEvent(QFocusEvent *) + void focusInEvent(QFocusEvent *) override { update(); } - void focusOutEvent(QFocusEvent *) + void focusOutEvent(QFocusEvent *) override { update(); } }; @@ -3195,9 +3237,10 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusWidgets() layout->addWidget(dial2); QWidget widget; + widget.setWindowTitle(QTest::currentTestFunction()); widget.setLayout(layout); widget.show(); - qApp->setActiveWindow(&widget); + QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -3236,7 +3279,7 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusWidgets() widget.hide(); QTest::qWait(15); widget.show(); - qApp->setActiveWindow(&widget); + QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); QTRY_VERIFY(widget1->hasFocus()); @@ -3279,9 +3322,10 @@ void tst_QGraphicsScene::tabFocus_sceneWithNestedFocusWidgets() layout->addWidget(dial2); QWidget widget; + widget.setWindowTitle(QTest::currentTestFunction()); widget.setLayout(layout); widget.show(); - qApp->setActiveWindow(&widget); + QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -3366,7 +3410,7 @@ void tst_QGraphicsScene::tabFocus_sceneWithNestedFocusWidgets() widget.hide(); QTest::qWait(12); widget.show(); - qApp->setActiveWindow(&widget); + QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); QTRY_VERIFY(widget1->hasFocus()); @@ -3390,11 +3434,11 @@ void tst_QGraphicsScene::style() QCOMPARE(sceneSpy.count(), 1); QCOMPARE(proxySpy.count(), 1); QCOMPARE(editSpy.count(), 1); - QCOMPARE(scene.style(), (QStyle *)windowsStyle); - QCOMPARE(proxy->style(), (QStyle *)windowsStyle); - QCOMPARE(edit->style(), (QStyle *)windowsStyle); + QCOMPARE(scene.style(), windowsStyle.data()); + QCOMPARE(proxy->style(), windowsStyle.data()); + QCOMPARE(edit->style(), windowsStyle.data()); - scene.setStyle(0); + scene.setStyle(nullptr); QCOMPARE(sceneSpy.count(), 2); QCOMPARE(proxySpy.count(), 2); QCOMPARE(editSpy.count(), 2); @@ -3411,11 +3455,12 @@ void tst_QGraphicsScene::task139710_bspTreeCrash() for (int i = 0; i < 2; ++i) { // trigger delayed item indexing - qApp->processEvents(); + QCoreApplication::processEvents(); scene.setSceneRect(0, 0, 10000, 10000); // delete all items in the scene - pointers are now likely to be recycled - foreach (QGraphicsItem *item, scene.items()) { + const auto &items = scene.items(); + for (QGraphicsItem *item : items) { scene.removeItem(item); delete item; } @@ -3427,7 +3472,7 @@ void tst_QGraphicsScene::task139710_bspTreeCrash() } // trigger delayed item indexing for the first 1000 items - qApp->processEvents(); + QCoreApplication::processEvents(); // add 1000 more items - the BSP tree is now resized for (int i = 0; i < 1000; ++i) { @@ -3437,7 +3482,8 @@ void tst_QGraphicsScene::task139710_bspTreeCrash() // get items from the BSP tree and use them. there was junk in the tree // the second time this happened. - foreach (QGraphicsItem *item, scene.items(QRectF(0, 0, 1000, 1000))) + const auto &itemsWithin = scene.items(QRectF(0, 0, 1000, 1000)); + for (QGraphicsItem *item : itemsWithin) item->moveBy(0, 0); } } @@ -3446,7 +3492,7 @@ void tst_QGraphicsScene::task139782_containsItemBoundingRect() { // The item in question has a scene bounding rect of (10, 10, 50, 50) QGraphicsScene scene(0.0, 0.0, 200.0, 200.0); - QGraphicsRectItem *item = new QGraphicsRectItem(0.0, 0.0, 50.0, 50.0, 0); + QGraphicsRectItem *item = new QGraphicsRectItem(0.0, 0.0, 50.0, 50.0, nullptr); scene.addItem(item); item->setPos(10.0, 10.0); @@ -3476,7 +3522,8 @@ void tst_QGraphicsScene::task160653_selectionChanged() QGraphicsScene scene(0, 0, 100, 100); scene.addItem(new QGraphicsRectItem(0, 0, 20, 20)); scene.addItem(new QGraphicsRectItem(30, 30, 20, 20)); - foreach (QGraphicsItem *item, scene.items()) { + const auto &items = scene.items(); + for (QGraphicsItem *item : items) { item->setFlags( item->flags() | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable); item->setSelected(true); @@ -3484,12 +3531,14 @@ void tst_QGraphicsScene::task160653_selectionChanged() QVERIFY(scene.items().size() > 1); QCOMPARE(scene.items().size(), scene.selectedItems().size()); - QSignalSpy spy(&scene, SIGNAL(selectionChanged())); + QSignalSpy spy(&scene, &QGraphicsScene::selectionChanged); QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); QTest::mouseClick( - view.viewport(), Qt::LeftButton, 0, view.mapFromScene(scene.items().first()->scenePos())); + view.viewport(), Qt::LeftButton, {}, view.mapFromScene(scene.items().first()->scenePos())); QCOMPARE(spy.count(), 1); } @@ -3574,17 +3623,21 @@ void tst_QGraphicsScene::sorting() scene.addItem(t_1); - foreach (QGraphicsItem *item, scene.items()) + const auto &items = scene.items(); + for (QGraphicsItem *item : items) item->setFlag(QGraphicsItem::ItemIsSelectable); // QGraphicsView view(&scene); // view.setDragMode(QGraphicsView::RubberBandDrag); // view.show(); - qDebug() << "items: {"; - foreach (QGraphicsItem *item, scene.items(QRectF(32, 31, 4, 55))) - qDebug() << "\t" << item->data(0).toString(); - qDebug() << "}"; + if (lcTests().isDebugEnabled()) { + qCDebug(lcTests) << "items: {"; + const auto &itemsWithin = scene.items(QRectF(32, 31, 4, 55)); + for (QGraphicsItem *item : itemsWithin) + qCDebug(lcTests).nospace() << '\t' << item->data(0).toString(); + qCDebug(lcTests) << '}'; + } QCOMPARE(scene.items(QRectF(32, 31, 4, 55)), QList<QGraphicsItem *>() @@ -3664,11 +3717,11 @@ void tst_QGraphicsScene::changedSignal() QFETCH(bool, withView); QGraphicsScene scene; ChangedListener cl; - connect(&scene, SIGNAL(changed(QList<QRectF>)), &cl, SLOT(changed(QList<QRectF>))); + connect(&scene, &QGraphicsScene::changed, &cl, &ChangedListener::changed); - QGraphicsView *view = 0; + QScopedPointer<QGraphicsView> view; if (withView) - view = new QGraphicsView(&scene); + view.reset(new QGraphicsView(&scene)); QGraphicsRectItem *rect = new QGraphicsRectItem(0, 0, 10, 10); rect->setPen(QPen(Qt::black, 0)); @@ -3682,14 +3735,11 @@ void tst_QGraphicsScene::changedSignal() rect->setPos(20, 0); QCOMPARE(cl.changes.size(), 1); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(cl.changes.size(), 2); QCOMPARE(cl.changes.at(1).size(), 2); QCOMPARE(scene.sceneRect(), QRectF(0, 0, 30, 10)); - - if (withView) - delete view; } void tst_QGraphicsScene::stickyFocus_data() @@ -3716,7 +3766,7 @@ void tst_QGraphicsScene::stickyFocus() QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); event.setScenePos(QPointF(-10, -10)); // outside item event.setButton(Qt::LeftButton); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(text->hasFocus(), sticky); } @@ -3734,43 +3784,51 @@ void tst_QGraphicsScene::sendEvent() void tst_QGraphicsScene::inputMethod_data() { - QTest::addColumn<int>("flags"); + QTest::addColumn<QGraphicsItem::GraphicsItemFlags>("flags"); QTest::addColumn<bool>("callFocusItem"); - QTest::newRow("0") << 0 << false; - QTest::newRow("1") << (int)QGraphicsItem::ItemAcceptsInputMethod << false; - QTest::newRow("2") << (int)QGraphicsItem::ItemIsFocusable << false; + QTest::newRow("0") << QGraphicsItem::GraphicsItemFlags() << false; + QTest::newRow("1") << QGraphicsItem::GraphicsItemFlags(QGraphicsItem::ItemAcceptsInputMethod) << false; + QTest::newRow("2") << QGraphicsItem::GraphicsItemFlags(QGraphicsItem::ItemIsFocusable) << false; QTest::newRow("3") << - (int)(QGraphicsItem::ItemAcceptsInputMethod|QGraphicsItem::ItemIsFocusable) << true; + (QGraphicsItem::ItemAcceptsInputMethod|QGraphicsItem::ItemIsFocusable) << true; } class InputMethodTester : public QGraphicsRectItem { - void inputMethodEvent(QInputMethodEvent *) { ++eventCalls; } - QVariant inputMethodQuery(Qt::InputMethodQuery) const { ++queryCalls; return QVariant(); } + void inputMethodEvent(QInputMethodEvent *) override { ++eventCalls; } + QVariant inputMethodQuery(Qt::InputMethodQuery) const override + { + ++queryCalls; + return QVariant(); + } + public: - int eventCalls; - mutable int queryCalls; + int eventCalls = 0; + mutable int queryCalls = 0; }; void tst_QGraphicsScene::inputMethod() { PlatformInputContext inputContext; - QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + QInputMethodPrivate *inputMethodPrivate = + QInputMethodPrivate::get(QGuiApplication::inputMethod()); inputMethodPrivate->testContext = &inputContext; - QFETCH(int, flags); + QFETCH(QGraphicsItem::GraphicsItemFlags, flags); QFETCH(bool, callFocusItem); InputMethodTester *item = new InputMethodTester; - item->setFlags((QGraphicsItem::GraphicsItemFlags)flags); + item->setFlags(flags); QGraphicsScene scene; QGraphicsView view(&scene); + view.resize(m_testSize); view.show(); + view.setWindowTitle(QTest::currentTestFunction()); QApplication::setActiveWindow(&view); view.setFocus(); QVERIFY(QTest::qWaitForWindowActive(&view)); - QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); + QCOMPARE(QApplication::activeWindow(), &view); inputContext.m_resetCallCount = 0; inputContext.m_commitCallCount = 0; @@ -3782,25 +3840,25 @@ void tst_QGraphicsScene::inputMethod() QCOMPARE(inputContext.m_resetCallCount, 0); item->eventCalls = 0; - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(item->eventCalls, callFocusItem ? 1 : 0); item->queryCalls = 0; - scene.inputMethodQuery((Qt::InputMethodQuery)0); + scene.inputMethodQuery(Qt::InputMethodQuery(0)); QCOMPARE(item->queryCalls, callFocusItem ? 1 : 0); - scene.setFocusItem(0); + scene.setFocusItem(nullptr); // the input context is reset twice, once because an item has lost focus and again because // the Qt::WA_InputMethodEnabled flag is cleared because no item has focus. QCOMPARE(inputContext.m_resetCallCount + inputContext.m_commitCallCount, callFocusItem ? 2 : 0); QCOMPARE(item->queryCalls, callFocusItem ? 1 : 0); // verify that value is unaffected item->eventCalls = 0; - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(item->eventCalls, 0); item->queryCalls = 0; - scene.inputMethodQuery((Qt::InputMethodQuery)0); + scene.inputMethodQuery(Qt::InputMethodQuery(0)); QCOMPARE(item->queryCalls, 0); } @@ -3824,18 +3882,18 @@ void tst_QGraphicsScene::dispatchHoverOnPress() me.setButtons(Qt::LeftButton); QGraphicsSceneMouseEvent me2(QEvent::GraphicsSceneMouseRelease); me2.setButton(Qt::LeftButton); - qApp->sendEvent(&scene, &me); - qApp->sendEvent(&scene, &me2); - QCOMPARE(tester1->eventTypes, QList<QEvent::Type>() + QCoreApplication::sendEvent(&scene, &me); + QCoreApplication::sendEvent(&scene, &me2); + QCOMPARE(tester1->eventTypes, QVector<QEvent::Type>() << QEvent::GraphicsSceneHoverEnter << QEvent::GraphicsSceneHoverMove << QEvent::GrabMouse << QEvent::GraphicsSceneMousePress << QEvent::UngrabMouse); tester1->eventTypes.clear(); - qApp->sendEvent(&scene, &me); - qApp->sendEvent(&scene, &me2); - QCOMPARE(tester1->eventTypes, QList<QEvent::Type>() + QCoreApplication::sendEvent(&scene, &me); + QCoreApplication::sendEvent(&scene, &me2); + QCOMPARE(tester1->eventTypes, QVector<QEvent::Type>() << QEvent::GraphicsSceneHoverMove << QEvent::GrabMouse << QEvent::GraphicsSceneMousePress @@ -3850,21 +3908,21 @@ void tst_QGraphicsScene::dispatchHoverOnPress() me2.setScenePos(QPointF(30, 30)); me2.setButton(Qt::LeftButton); tester1->eventTypes.clear(); - qApp->sendEvent(&scene, &me); - qApp->sendEvent(&scene, &me2); - qDebug() << tester1->eventTypes; - QCOMPARE(tester1->eventTypes, QList<QEvent::Type>() + QCoreApplication::sendEvent(&scene, &me); + QCoreApplication::sendEvent(&scene, &me2); + qCDebug(lcTests) << tester1->eventTypes; + QCOMPARE(tester1->eventTypes, QVector<QEvent::Type>() << QEvent::GraphicsSceneHoverLeave); - QCOMPARE(tester2->eventTypes, QList<QEvent::Type>() + QCOMPARE(tester2->eventTypes, QVector<QEvent::Type>() << QEvent::GraphicsSceneHoverEnter << QEvent::GraphicsSceneHoverMove << QEvent::GrabMouse << QEvent::GraphicsSceneMousePress << QEvent::UngrabMouse); tester2->eventTypes.clear(); - qApp->sendEvent(&scene, &me); - qApp->sendEvent(&scene, &me2); - QCOMPARE(tester2->eventTypes, QList<QEvent::Type>() + QCoreApplication::sendEvent(&scene, &me); + QCoreApplication::sendEvent(&scene, &me2); + QCOMPARE(tester2->eventTypes, QVector<QEvent::Type>() << QEvent::GraphicsSceneHoverMove << QEvent::GrabMouse << QEvent::GraphicsSceneMousePress @@ -3913,7 +3971,7 @@ void tst_QGraphicsScene::initialFocus() if (activeScene) { QEvent windowActivate(QEvent::WindowActivate); - qApp->sendEvent(&scene, &windowActivate); + QCoreApplication::sendEvent(&scene, &windowActivate); scene.setFocus(); } @@ -3921,7 +3979,7 @@ void tst_QGraphicsScene::initialFocus() if (!activeScene) { QEvent windowActivate(QEvent::WindowActivate); - qApp->sendEvent(&scene, &windowActivate); + QCoreApplication::sendEvent(&scene, &windowActivate); scene.setFocus(); } @@ -3931,14 +3989,13 @@ void tst_QGraphicsScene::initialFocus() class PolishItem : public QGraphicsTextItem { public: - PolishItem(QGraphicsItem *parent = 0) - : QGraphicsTextItem(parent), polished(false), deleteChildrenInPolish(true), addChildrenInPolish(false) { } + using QGraphicsTextItem::QGraphicsTextItem; - bool polished; - bool deleteChildrenInPolish; - bool addChildrenInPolish; + bool polished = false; + bool deleteChildrenInPolish = true; + bool addChildrenInPolish = false; protected: - QVariant itemChange(GraphicsItemChange change, const QVariant& value) + QVariant itemChange(GraphicsItemChange change, const QVariant& value) override { if (change == ItemVisibleChange) { polished = true; @@ -3977,19 +4034,19 @@ void tst_QGraphicsScene::polishItems2() // Wait for the polish event to be delivered. QVERIFY(!item->polished); - QApplication::sendPostedEvents(&scene, QEvent::MetaCall); + QCoreApplication::sendPostedEvents(&scene, QEvent::MetaCall); QVERIFY(item->polished); // We deleted the children we added above, but we also // added 10 new children. These should be polished in the next // event loop iteration. - QList<QGraphicsItem *> children = item->childItems(); + const QList<QGraphicsItem *> children = item->childItems(); QCOMPARE(children.count(), 10); - foreach (QGraphicsItem *child, children) + for (QGraphicsItem *child : children) QVERIFY(!static_cast<PolishItem *>(child)->polished); - QApplication::sendPostedEvents(&scene, QEvent::MetaCall); - foreach (QGraphicsItem *child, children) + QCoreApplication::sendPostedEvents(&scene, QEvent::MetaCall); + for (QGraphicsItem *child : children) QVERIFY(static_cast<PolishItem *>(child)->polished); } @@ -4006,6 +4063,8 @@ void tst_QGraphicsScene::isActive() { QWidget toplevel1; + toplevel1.setWindowTitle(QTest::currentTestFunction()); + toplevel1.resize(m_testSize); QHBoxLayout *layout = new QHBoxLayout; toplevel1.setLayout(layout); QGraphicsView *view1 = new QGraphicsView(&scene1); @@ -4071,8 +4130,9 @@ void tst_QGraphicsScene::isActive() { - const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry(); QWidget toplevel2; + toplevel2.setWindowTitle(QTest::currentTestFunction()); + toplevel2.resize(m_testSize); QHBoxLayout *layout = new QHBoxLayout; toplevel2.setLayout(layout); QGraphicsView *view1 = new QGraphicsView(&scene1); @@ -4085,7 +4145,7 @@ void tst_QGraphicsScene::isActive() QVERIFY(!scene1.hasFocus()); QVERIFY(!scene2.hasFocus()); - toplevel2.move(availableGeometry.topLeft() + QPoint(50, 50)); + toplevel2.move(m_availableGeometry.topLeft() + QPoint(50, 50)); toplevel2.show(); QApplication::setActiveWindow(&toplevel2); QVERIFY(QTest::qWaitForWindowActive(&toplevel2)); @@ -4134,12 +4194,13 @@ void tst_QGraphicsScene::isActive() QVERIFY(!scene2.hasFocus()); QGraphicsView topLevelView; - topLevelView.move(availableGeometry.topLeft() + QPoint(500, 50)); + topLevelView.move(toplevel2.geometry().topRight() + QPoint(100, 50)); + topLevelView.resize(m_testSize); topLevelView.show(); QApplication::setActiveWindow(&topLevelView); topLevelView.setFocus(); QVERIFY(QTest::qWaitForWindowActive(&topLevelView)); - QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&topLevelView)); + QCOMPARE(QApplication::activeWindow(), &topLevelView); QVERIFY(!scene1.isActive()); QVERIFY(!scene2.isActive()); @@ -4180,6 +4241,7 @@ void tst_QGraphicsScene::isActive() { QWidget toplevel3; + toplevel3.resize(m_testSize); QHBoxLayout *layout = new QHBoxLayout; toplevel3.setLayout(layout); QGraphicsView *view1 = new QGraphicsView(&scene1); @@ -4209,7 +4271,7 @@ void tst_QGraphicsScene::isActive() QVERIFY(scene1.hasFocus()); QVERIFY(!scene2.hasFocus()); - view1->setParent(0); + view1->setParent(nullptr); QVERIFY(!scene1.isActive()); QVERIFY(scene2.isActive()); QVERIFY(!scene1.hasFocus()); @@ -4241,7 +4303,7 @@ void tst_QGraphicsScene::siblingIndexAlwaysValid() scene.addItem(parent2); //Then we make the child a top level - child->setParentItem(0); + child->setParentItem(nullptr); //This is trigerred by a repaint... QGraphicsScenePrivate::get(&scene)->index->estimateTopLevelItems(QRectF(), Qt::AscendingOrder); @@ -4257,6 +4319,8 @@ void tst_QGraphicsScene::siblingIndexAlwaysValid() scene2.setItemIndexMethod(QGraphicsScene::NoIndex); QGraphicsView view2(&scene2); + view2.setWindowTitle(QTest::currentTestFunction()); + view2.resize(m_testSize); // first add the blue rect QGraphicsRectItem* const item1 = new QGraphicsRectItem(QRect( 10, 10, 10, 10 )); @@ -4300,9 +4364,11 @@ void tst_QGraphicsScene::removeFullyTransparentItem() child->setParentItem(parent); CustomView view; + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); view.setScene(&scene); view.show(); - qApp->setActiveWindow(&view); + QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events @@ -4351,33 +4417,35 @@ void tst_QGraphicsScene::taskQTBUG_5904_crashWithDeviceCoordinateCache() void tst_QGraphicsScene::taskQT657_paintIntoCacheWithTransparentParts() { // Test using DeviceCoordinateCache and opaque item - QWidget *w = new QWidget(); + QScopedPointer<QWidget> w(new QWidget); w->setPalette(QColor(0, 0, 255)); w->setGeometry(0, 0, 50, 50); QGraphicsScene *scene = new QGraphicsScene(); - CustomView *view = new CustomView; - view->setScene(scene); + CustomView view; + view.resize(m_testSize); + view.setWindowTitle(QTest::currentTestFunction()); + view.setScene(scene); - QGraphicsProxyWidget *proxy = scene->addWidget(w); + QGraphicsProxyWidget *proxy = scene->addWidget(w.data()); proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache); proxy->setTransform(QTransform().rotate(15), true); - view->show(); - QVERIFY(QTest::qWaitForWindowExposed(view)); - view->repaints = 0; + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + view.repaints = 0; proxy->update(10, 10, 10, 10); - QTRY_VERIFY(view->repaints > 0); + QTRY_VERIFY(view.repaints > 0); QPixmap pix; QGraphicsItemPrivate* itemp = QGraphicsItemPrivate::get(proxy); - QTRY_VERIFY(QPixmapCache::find(itemp->extraItemCache()->deviceData.value(view->viewport()).key, &pix)); + QTRY_VERIFY(QPixmapCache::find(itemp->extraItemCache()->deviceData.value(view.viewport()).key, &pix)); QTransform t = proxy->sceneTransform(); // Map from scene coordinates to pixmap coordinates. // X origin in the pixmap is the most-left point // of the item's boundingRect in the scene. - qreal adjust = t.mapRect(proxy->boundingRect().toRect()).left(); + const int adjust = t.mapRect(proxy->boundingRect().toRect()).left(); QRect rect = t.mapRect(QRect(10, 10, 10, 10)).adjusted(-adjust, 0, -adjust + 1, 1); QPixmap subpix = pix.copy(rect); @@ -4386,8 +4454,6 @@ void tst_QGraphicsScene::taskQT657_paintIntoCacheWithTransparentParts() for(int j = 0; j < im.height(); j++) QCOMPARE(qAlpha(im.pixel(i, j)), 255); } - - delete w; } void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() @@ -4401,28 +4467,30 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() rectItem->setParentItem(backItem); QGraphicsScene *scene = new QGraphicsScene(); - CustomView *view = new CustomView; - view->setScene(scene); + CustomView view; + view.resize(m_testSize); + view.setWindowTitle(QTest::currentTestFunction()); + view.setScene(scene); scene->addItem(backItem); rectItem->setCacheMode(QGraphicsItem::DeviceCoordinateCache); backItem->setTransform(QTransform().rotate(15), true); - view->show(); - QVERIFY(QTest::qWaitForWindowExposed(view)); - view->repaints = 0; + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + view.repaints = 0; rectItem->update(10, 10, 10, 10); - QTRY_VERIFY(view->repaints > 0); + QTRY_VERIFY(view.repaints > 0); QPixmap pix; QGraphicsItemPrivate* itemp = QGraphicsItemPrivate::get(rectItem); - QTRY_VERIFY(QPixmapCache::find(itemp->extraItemCache()->deviceData.value(view->viewport()).key, &pix)); + QTRY_VERIFY(QPixmapCache::find(itemp->extraItemCache()->deviceData.value(view.viewport()).key, &pix)); QTransform t = rectItem->sceneTransform(); // Map from scene coordinates to pixmap coordinates. // X origin in the pixmap is the most-left point // of the item's boundingRect in the scene. - qreal adjust = t.mapRect(rectItem->boundingRect().toRect()).left(); + const int adjust = t.mapRect(rectItem->boundingRect().toRect()).left(); QRect rect = t.mapRect(QRect(10, 10, 10, 10)).adjusted(-adjust, 0, -adjust + 1, 1); QPixmap subpix = pix.copy(rect); @@ -4432,8 +4500,6 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() QCOMPARE(qAlpha(im.pixel(i, j)), 125); } } - - delete view; } // Test using ItemCoordinateCache and opaque item @@ -4442,18 +4508,20 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() rectItem->setBrush(QColor(0, 0, 255)); QGraphicsScene *scene = new QGraphicsScene(); - CustomView *view = new CustomView; - view->setScene(scene); + CustomView view; + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); + view.setScene(scene); scene->addItem(rectItem); rectItem->setCacheMode(QGraphicsItem::ItemCoordinateCache); rectItem->setTransform(QTransform().rotate(15), true); - view->show(); - QVERIFY(QTest::qWaitForWindowExposed(view)); - view->repaints = 0; + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + view.repaints = 0; rectItem->update(10, 10, 10, 10); - QTRY_VERIFY(view->repaints > 0); + QTRY_VERIFY(view.repaints > 0); QPixmap pix; QGraphicsItemPrivate* itemp = QGraphicsItemPrivate::get(rectItem); @@ -4463,7 +4531,7 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() // Map from scene coordinates to pixmap coordinates. // X origin in the pixmap is the most-left point // of the item's boundingRect in the scene. - qreal adjust = t.mapRect(rectItem->boundingRect().toRect()).left(); + const int adjust = t.mapRect(rectItem->boundingRect().toRect()).left(); QRect rect = t.mapRect(QRect(10, 10, 10, 10)).adjusted(-adjust, 0, -adjust + 1, 1); QPixmap subpix = pix.copy(rect); @@ -4472,8 +4540,6 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() for(int j = 0; j < im.height(); j++) QCOMPARE(qAlpha(im.pixel(i, j)), 255); } - - delete view; } // Test using ItemCoordinateCache and semi-transparent item @@ -4482,18 +4548,20 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() rectItem->setBrush(QColor(0, 0, 255, 125)); QGraphicsScene *scene = new QGraphicsScene(); - CustomView *view = new CustomView; - view->setScene(scene); + CustomView view; + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); + view.setScene(scene); scene->addItem(rectItem); rectItem->setCacheMode(QGraphicsItem::ItemCoordinateCache); rectItem->setTransform(QTransform().rotate(15), true); - view->show(); - QVERIFY(QTest::qWaitForWindowExposed(view)); - view->repaints = 0; + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + view.repaints = 0; rectItem->update(10, 10, 10, 10); - QTRY_VERIFY(view->repaints > 0); + QTRY_VERIFY(view.repaints > 0); QPixmap pix; QGraphicsItemPrivate* itemp = QGraphicsItemPrivate::get(rectItem); @@ -4503,7 +4571,7 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() // Map from scene coordinates to pixmap coordinates. // X origin in the pixmap is the most-left point // of the item's boundingRect in the scene. - qreal adjust = t.mapRect(rectItem->boundingRect().toRect()).left(); + const int adjust = int(t.mapRect(rectItem->boundingRect().toRect()).left()); QRect rect = t.mapRect(QRect(10, 10, 10, 10)).adjusted(-adjust, 0, -adjust + 1, 1); QPixmap subpix = pix.copy(rect); @@ -4512,8 +4580,6 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() for(int j = 0; j < im.height(); j++) QCOMPARE(qAlpha(im.pixel(i, j)), 125); } - - delete view; } } @@ -4544,7 +4610,7 @@ void tst_QGraphicsScene::zeroScale() QGraphicsView view(&scene); ChangedListener cl; - connect(&scene, SIGNAL(changed(QList<QRectF>)), &cl, SLOT(changed(QList<QRectF>))); + connect(&scene, &QGraphicsScene::changed, &cl, &ChangedListener::changed); QGraphicsRectItem *rect1 = new QGraphicsRectItem(0, 0, 0.0000001, 0.00000001); scene.addItem(rect1); @@ -4567,13 +4633,13 @@ void tst_QGraphicsScene::focusItemChangedSignal() qRegisterMetaType<Qt::FocusReason>("Qt::FocusReason"); QGraphicsScene scene; - QSignalSpy spy(&scene, SIGNAL(focusItemChanged(QGraphicsItem *, QGraphicsItem *, Qt::FocusReason))); + QSignalSpy spy(&scene, &QGraphicsScene::focusItemChanged); QVERIFY(spy.isValid()); QCOMPARE(spy.count(), 0); scene.setFocus(); QCOMPARE(spy.count(), 0); QEvent activateEvent(QEvent::WindowActivate); - qApp->sendEvent(&scene, &activateEvent); + QCoreApplication::sendEvent(&scene, &activateEvent); QCOMPARE(spy.count(), 0); QGraphicsRectItem *topLevelItem1 = new QGraphicsRectItem; @@ -4590,7 +4656,7 @@ void tst_QGraphicsScene::focusItemChangedSignal() QCOMPARE(spy.count(), 1); QList<QVariant> arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), topLevelItem2); QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), nullptr); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::OtherFocusReason); QVERIFY(topLevelItem2->hasFocus()); @@ -4600,14 +4666,14 @@ void tst_QGraphicsScene::focusItemChangedSignal() arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), nullptr); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), topLevelItem2); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::OtherFocusReason); scene.setFocus(Qt::MenuBarFocusReason); QCOMPARE(spy.count(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), topLevelItem2); QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), nullptr); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::MenuBarFocusReason); @@ -4615,15 +4681,15 @@ void tst_QGraphicsScene::focusItemChangedSignal() topLevelItem1->setFocus(Qt::TabFocusReason); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)topLevelItem1); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), topLevelItem1); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), topLevelItem2); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::TabFocusReason); topLevelItem2->setFocus(Qt::TabFocusReason); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)topLevelItem2); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)topLevelItem1); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), topLevelItem2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), topLevelItem1); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::TabFocusReason); } @@ -4631,10 +4697,10 @@ void tst_QGraphicsScene::focusItemChangedSignal() // when the scene activation changes) breaks quite a few tests so leave this fix // for some future release. See QTBUG-28346. QEvent deactivateEvent(QEvent::WindowDeactivate); - qApp->sendEvent(&scene, &deactivateEvent); + QCoreApplication::sendEvent(&scene, &deactivateEvent); QEXPECT_FAIL("", "QTBUG-28346", Continue); QCOMPARE(spy.count(), 1); - qApp->sendEvent(&scene, &activateEvent); + QCoreApplication::sendEvent(&scene, &activateEvent); QEXPECT_FAIL("", "QTBUG-28346", Continue); QCOMPARE(spy.count(), 1); @@ -4645,8 +4711,8 @@ void tst_QGraphicsScene::focusItemChangedSignal() QCOMPARE(spy.count(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)panel1); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), panel1); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), topLevelItem2); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::ActiveWindowFocusReason); QGraphicsRectItem *panel2 = new QGraphicsRectItem; @@ -4659,16 +4725,16 @@ void tst_QGraphicsScene::focusItemChangedSignal() QCOMPARE(spy.count(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)panel2); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)panel1); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), panel2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), panel1); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::ActiveWindowFocusReason); scene.setActivePanel(panel1); QCOMPARE(spy.count(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)panel1); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)panel2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), panel1); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), panel2); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::ActiveWindowFocusReason); } @@ -4677,14 +4743,15 @@ void tst_QGraphicsScene::focusItemChangedSignal() class ItemCountsPaintCalls : public QGraphicsRectItem { public: - ItemCountsPaintCalls(const QRectF & rect, QGraphicsItem *parent = 0) - : QGraphicsRectItem(rect, parent), repaints(0) {} - void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ) + using QGraphicsRectItem::QGraphicsRectItem; + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr) override { QGraphicsRectItem::paint(painter, option, widget); ++repaints; } - int repaints; + int repaints = 0; }; void tst_QGraphicsScene::minimumRenderSize() @@ -4698,10 +4765,12 @@ void tst_QGraphicsScene::minimumRenderSize() scene.addItem(bigParent); CustomView view; + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); view.setScene(&scene); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - qApp->processEvents(); + QCoreApplication::processEvents(); // Initially, everything should be repainted the same number of times int viewRepaints = 0; @@ -4714,7 +4783,7 @@ void tst_QGraphicsScene::minimumRenderSize() // Setting a minimum render size should cause a repaint scene.setMinimumRenderSize(0.5); - qApp->processEvents(); + QCoreApplication::processEvents(); QTRY_VERIFY(view.repaints > viewRepaints); viewRepaints = view.repaints; @@ -4725,7 +4794,7 @@ void tst_QGraphicsScene::minimumRenderSize() // Scaling should cause a repaint of big items only. view.scale(0.1, 0.1); - qApp->processEvents(); + QCoreApplication::processEvents(); QTRY_VERIFY(view.repaints > viewRepaints); viewRepaints = view.repaints; @@ -4736,7 +4805,7 @@ void tst_QGraphicsScene::minimumRenderSize() // Scaling further should cause even fewer items to be repainted view.scale(0.1, 0.1); // Stacks with previous scale - qApp->processEvents(); + QCoreApplication::processEvents(); QTRY_VERIFY(view.repaints > viewRepaints); viewRepaints = view.repaints; @@ -4750,6 +4819,8 @@ void tst_QGraphicsScene::focusOnTouch() { QGraphicsScene scene; QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); scene.setSceneRect(0, 0, 100, 100); QGraphicsRectItem *rect = scene.addRect(0, 0, 100, 100); rect->setFlag(QGraphicsItem::ItemIsFocusable, true); @@ -4807,6 +4878,7 @@ void tst_QGraphicsScene::taskQTBUG_16401_focusItem() { QGraphicsScene scene; QGraphicsView view(&scene); + view.resize(m_testSize); QGraphicsRectItem *rect = scene.addRect(0, 0, 100, 100); rect->setFlag(QGraphicsItem::ItemIsFocusable); @@ -4837,6 +4909,8 @@ void tst_QGraphicsScene::taskQTBUG_42915_focusNextPrevChild() { QGraphicsScene scene; QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); scene.setSceneRect(1, 1, 198, 198); view.setFocus(); diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST index ee13a37212..9b76ea02ff 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST +++ b/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST @@ -1,20 +1,16 @@ [task255529_transformationAnchorMouseAndViewportMargins] -xcb +opensuse-leap [cursor] -xcb +opensuse-leap [cursor2] -xcb -windows -[rubberBandExtendSelection] -xcb -[rotated_rubberBand] -xcb +ubuntu-16.04 [sendEvent] -xcb -[forwardMousePress] -xcb +ubuntu-16.04 +opensuse-42.3 [resizeAnchor] -xcb +opensuse-leap +rhel-7.6 +ubuntu [update2] opensuse-42.3 [itemsInRect_cosmeticAdjust] diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 1442219bea..e21b1b889a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -352,8 +352,8 @@ void tst_QGraphicsView::renderHints() view.setScene(&scene); - view.setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing | QPainter::NonCosmeticDefaultPen); - QCOMPARE(view.renderHints(), QPainter::TextAntialiasing | QPainter::Antialiasing | QPainter::NonCosmeticDefaultPen); + view.setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing); + QCOMPARE(view.renderHints(), QPainter::TextAntialiasing | QPainter::Antialiasing); QCOMPARE(item->hints, 0); view.show(); @@ -361,8 +361,8 @@ void tst_QGraphicsView::renderHints() view.repaint(); QTRY_COMPARE(item->hints, view.renderHints()); - view.setRenderHints(QPainter::Antialiasing | QPainter::NonCosmeticDefaultPen); - QCOMPARE(view.renderHints(), QPainter::Antialiasing | QPainter::NonCosmeticDefaultPen); + view.setRenderHints(QPainter::Antialiasing); + QCOMPARE(view.renderHints(), QPainter::Antialiasing); view.repaint(); QTRY_COMPARE(item->hints, view.renderHints()); @@ -2219,7 +2219,7 @@ void tst_QGraphicsView::wheelEvent() { QWheelEvent event(view.mapFromScene(widget->boundingRect().center()), view.mapToGlobal(view.mapFromScene(widget->boundingRect().center())), - 120, 0, 0, Qt::Horizontal); + QPoint(), QPoint(120, 0), Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); QApplication::sendEvent(view.viewport(), &event); QCOMPARE(scene.orientation, Qt::Horizontal); } @@ -2228,7 +2228,7 @@ void tst_QGraphicsView::wheelEvent() { QWheelEvent event(view.mapFromScene(widget->boundingRect().center()), view.mapToGlobal(view.mapFromScene(widget->boundingRect().center())), - 120, 0, 0, Qt::Vertical); + QPoint(), QPoint(0, 120), Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); QApplication::sendEvent(view.viewport(), &event); QCOMPARE(scene.orientation, Qt::Vertical); } @@ -2526,9 +2526,8 @@ void tst_QGraphicsView::viewportUpdateMode2() view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); view.setScene(&dummyScene); view.ensurePolished(); // make sure we get the right content margins - int left, top, right, bottom; - view.getContentsMargins(&left, &top, &right, &bottom); - view.resize(200 + left + right, 200 + top + bottom); + const QMargins margins = view.contentsMargins(); + view.resize(200 + margins.left() + margins.right(), 200 + margins.top() + margins.bottom()); toplevel.show(); qApp->setActiveWindow(&toplevel); QVERIFY(QTest::qWaitForWindowExposed(&toplevel)); @@ -2611,11 +2610,6 @@ void tst_QGraphicsView::optimizationFlags() QGraphicsView view; QVERIFY(!view.optimizationFlags()); - view.setOptimizationFlag(QGraphicsView::DontClipPainter); - QVERIFY(view.optimizationFlags() & QGraphicsView::DontClipPainter); - view.setOptimizationFlag(QGraphicsView::DontClipPainter, false); - QVERIFY(!view.optimizationFlags()); - view.setOptimizationFlag(QGraphicsView::DontSavePainterState); QVERIFY(view.optimizationFlags() & QGraphicsView::DontSavePainterState); view.setOptimizationFlag(QGraphicsView::DontSavePainterState, false); @@ -2626,10 +2620,8 @@ void tst_QGraphicsView::optimizationFlags() view.setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing, false); QVERIFY(!view.optimizationFlags()); - view.setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing - | QGraphicsView::DontClipPainter); - QCOMPARE(view.optimizationFlags(), QGraphicsView::OptimizationFlags(QGraphicsView::DontAdjustForAntialiasing - | QGraphicsView::DontClipPainter)); + view.setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing); + QCOMPARE(view.optimizationFlags(), QGraphicsView::OptimizationFlags(QGraphicsView::DontAdjustForAntialiasing)); } class MessUpPainterItem : public QGraphicsRectItem @@ -4043,9 +4035,8 @@ void tst_QGraphicsView::update() CustomView view(0, &toplevel); view.setScene(&dummyScene); view.ensurePolished(); // must ensure polished to get content margins right - int left, top, right, bottom; - view.getContentsMargins(&left, &top, &right, &bottom); - view.resize(200 + left + right, 200 + top + bottom); + const QMargins margins = view.contentsMargins(); + view.resize(200 + margins.left() + margins.right(), 200 + margins.top() + margins.bottom()); toplevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&toplevel)); @@ -4857,7 +4848,7 @@ void tst_QGraphicsView::QTBUG_16063_microFocusRect() scene.setFocusItem(item); view.setFocus(); - QRectF mfv = view.inputMethodQuery(Qt::ImMicroFocus).toRectF(); + QRectF mfv = view.inputMethodQuery(Qt::ImCursorRectangle).toRectF(); QCOMPARE(mfv, IMItem::mf.translated(-view.mapToScene(view.sceneRect().toRect()).boundingRect().topLeft())); } diff --git a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp index 85b42e54fe..d3477be986 100644 --- a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp @@ -2905,7 +2905,7 @@ public: Q_UNUSED(widget); qreal w = rect().width(); QRectF box(0, 0, w, 2400/w); - painter->drawRoundRect(box); + painter->drawRoundedRect(box, 25, 25, Qt::RelativeSize); painter->drawLine(box.topLeft(), box.bottomRight()); painter->drawLine(box.bottomLeft(), box.topRight()); } diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index 6f7dca86eb..bcfc477733 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -1024,9 +1024,6 @@ void tst_QAbstractItemView::setItemDelegate() centerOnScreen(&v); moveCursorAway(&v); v.show(); -#if 0 // Used to be included in Qt4 for Q_WS_X11 - QCursor::setPos(v.geometry().center()); -#endif QApplication::setActiveWindow(&v); QVERIFY(QTest::qWaitForWindowActive(&v)); diff --git a/tests/auto/widgets/itemviews/qcolumnview/BLACKLIST b/tests/auto/widgets/itemviews/qcolumnview/BLACKLIST deleted file mode 100644 index bda01c700c..0000000000 --- a/tests/auto/widgets/itemviews/qcolumnview/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[scrollTo:reverse] -osx diff --git a/tests/auto/widgets/itemviews/qheaderview/BLACKLIST b/tests/auto/widgets/itemviews/qheaderview/BLACKLIST index efb813f7d2..4eceaae0d3 100644 --- a/tests/auto/widgets/itemviews/qheaderview/BLACKLIST +++ b/tests/auto/widgets/itemviews/qheaderview/BLACKLIST @@ -1,3 +1,2 @@ [stretchAndRestoreLastSection] -opensuse opensuse-leap diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 1b3e1e1f34..0b120985ee 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -85,8 +85,8 @@ class XResetModel : public QStandardItemModel blockSignals(true); bool r = QStandardItemModel::removeRows(row, count, parent); blockSignals(false); - emit beginResetModel(); - emit endResetModel(); + beginResetModel(); + endResetModel(); return r; } virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) @@ -94,8 +94,8 @@ class XResetModel : public QStandardItemModel blockSignals(true); bool r = QStandardItemModel::insertRows(row, count, parent); blockSignals(false); - emit beginResetModel(); - emit endResetModel(); + beginResetModel(); + endResetModel(); return r; } }; @@ -106,6 +106,7 @@ class tst_QHeaderView : public QObject public: tst_QHeaderView(); + static void initMain(); private slots: void initTestCase(); @@ -215,6 +216,7 @@ private slots: void QTBUG14242_hideSectionAutoSize(); void QTBUG50171_visualRegionForSwappedItems(); void QTBUG53221_assertShiftHiddenRow(); + void QTBUG75615_sizeHintWithStylesheet(); void ensureNoIndexAtLength(); void offsetConsistent(); @@ -265,6 +267,14 @@ protected: QElapsedTimer timer; }; +void tst_QHeaderView::initMain() +{ +#ifdef Q_OS_WIN + // Ensure minimum size constraints of framed windows on High DPI screens + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +#endif +} + class QtTestModel: public QAbstractTableModel { @@ -2597,6 +2607,26 @@ void tst_QHeaderView::QTBUG53221_assertShiftHiddenRow() QCOMPARE(tableView.verticalHeader()->isSectionHidden(2), true); } +void tst_QHeaderView::QTBUG75615_sizeHintWithStylesheet() +{ + QTableView tableView; + QStandardItemModel model(1, 1); + tableView.setModel(&model); + tableView.show(); + + const auto headerView = tableView.horizontalHeader(); + const auto oldSizeHint = headerView->sizeHint(); + QVERIFY(oldSizeHint.isValid()); + + tableView.setStyleSheet("QTableView QHeaderView::section { height: 100px;}"); + QCOMPARE(headerView->sizeHint().width(), oldSizeHint.width()); + QCOMPARE(headerView->sizeHint().height(), 100); + + tableView.setStyleSheet("QTableView QHeaderView::section { width: 100px;}"); + QCOMPARE(headerView->sizeHint().height(), oldSizeHint.height()); + QCOMPARE(headerView->sizeHint().width(), 100); +} + void protected_QHeaderView::testVisualRegionForSelection() { QRegion r = visualRegionForSelection(QItemSelection(model()->index(1, 0), model()->index(1, 2))); diff --git a/tests/auto/widgets/itemviews/qitemdelegate/qitemdelegate.pro b/tests/auto/widgets/itemviews/qitemdelegate/qitemdelegate.pro index 10cd1dcc54..916694fd0f 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/qitemdelegate.pro +++ b/tests/auto/widgets/itemviews/qitemdelegate/qitemdelegate.pro @@ -3,4 +3,4 @@ TARGET = tst_qitemdelegate QT += widgets widgets-private testlib SOURCES += tst_qitemdelegate.cpp -win32:!winrt: LIBS += -luser32 +win32:!winrt: QMAKE_USE += user32 diff --git a/tests/auto/widgets/itemviews/qlistview/qlistview.pro b/tests/auto/widgets/itemviews/qlistview/qlistview.pro index 75f45ab432..c3e19adc81 100644 --- a/tests/auto/widgets/itemviews/qlistview/qlistview.pro +++ b/tests/auto/widgets/itemviews/qlistview/qlistview.pro @@ -2,4 +2,4 @@ CONFIG += testcase TARGET = tst_qlistview QT += widgets gui-private widgets-private core-private testlib testlib-private SOURCES += tst_qlistview.cpp -win32:!winrt: LIBS += -luser32 +win32:!winrt: QMAKE_USE += user32 diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp index 0b828b8484..3a60b3b7c6 100644 --- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp +++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp @@ -2516,9 +2516,9 @@ void tst_QListView::horizontalScrollingByVerticalWheelEvents() QPoint globalPos = lv.geometry().center(); QPoint pos = lv.viewport()->geometry().center(); - QWheelEvent wheelDownEvent(pos, globalPos, QPoint(0, 0), QPoint(0, -120), -120, Qt::Vertical, 0, 0); - QWheelEvent wheelUpEvent(pos, globalPos, QPoint(0, 0), QPoint(0, 120), 120, Qt::Vertical, 0, 0); - QWheelEvent wheelLeftDownEvent(pos, globalPos, QPoint(0, 0), QPoint(120, -120), -120, Qt::Vertical, 0, 0); + QWheelEvent wheelDownEvent(pos, globalPos, QPoint(0, 0), QPoint(0, -120), Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); + QWheelEvent wheelUpEvent(pos, globalPos, QPoint(0, 0), QPoint(0, 120), Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); + QWheelEvent wheelLeftDownEvent(pos, globalPos, QPoint(0, 0), QPoint(120, -120), Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); int hValue = lv.horizontalScrollBar()->value(); QApplication::sendEvent(lv.viewport(), &wheelDownEvent); diff --git a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp index 91088aeeca..fe2ede4183 100644 --- a/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp +++ b/tests/auto/widgets/itemviews/qlistwidget/tst_qlistwidget.cpp @@ -1525,11 +1525,11 @@ void tst_QListWidget::itemData() item.setData(Qt::DisplayRole, QString("0")); QCOMPARE(widget.currentRoles, QVector<int>({Qt::DisplayRole, Qt::EditRole})); item.setData(Qt::CheckStateRole, Qt::PartiallyChecked); - QCOMPARE(widget.currentRoles, {Qt::CheckStateRole}); + QCOMPARE(widget.currentRoles, QVector<int>{Qt::CheckStateRole}); for (int i = 0; i < 4; ++i) { item.setData(Qt::UserRole + i, QString::number(i + 1)); - QCOMPARE(widget.currentRoles, {Qt::UserRole + i}); + QCOMPARE(widget.currentRoles, QVector<int>{Qt::UserRole + i}); } QMap<int, QVariant> flags = widget.model()->itemData(widget.model()->index(0, 0)); QCOMPARE(flags.count(), 6); diff --git a/tests/auto/widgets/itemviews/qtableview/BLACKLIST b/tests/auto/widgets/itemviews/qtableview/BLACKLIST index be90475a6f..9648cef3de 100644 --- a/tests/auto/widgets/itemviews/qtableview/BLACKLIST +++ b/tests/auto/widgets/itemviews/qtableview/BLACKLIST @@ -1,4 +1,3 @@ [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 c8eecd3693..09990ab70a 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -26,16 +26,24 @@ ** ****************************************************************************/ - -#include <QtGui/QtGui> -#include <QtWidgets/QtWidgets> +#include <QIdentityProxyModel> +#include <QLabel> +#include <QLineEdit> +#include <QScrollBar> +#include <QSignalSpy> +#include <QSortFilterProxyModel> +#include <QStandardItemModel> +#include <QStringListModel> +#include <QStyledItemDelegate> +#include <QTableView> +#include <QTest> +#include <private/qapplication_p.h> #include <private/qtablewidget_p.h> -#include <QtTest/QtTest> -#include "private/qapplication_p.h" - -#include <algorithm> +#include <private/qtesthelpers_p.h> +#if QT_CONFIG(textmarkdownwriter) +#include <private/qtextmarkdownwriter_p.h> +#endif -#include <QtTest/private/qtesthelpers_p.h> using namespace QTestPrivate; @@ -46,14 +54,241 @@ using namespace QTestPrivate; #define VERIFY_SPANS_CONSISTENCY(TEST_VIEW_) (void)false #endif -typedef QList<int> IntList; +Q_DECLARE_METATYPE(Qt::Key); +Q_DECLARE_METATYPE(Qt::KeyboardModifier); +Q_DECLARE_METATYPE(QItemSelectionModel::SelectionFlag); +using BoolList = QVector<bool>; +using IntList = QVector<int>; +using KeyList = QVector<Qt::Key>; +using SpanList = QVector<QRect>; + +class QtTestTableModel: public QAbstractTableModel +{ + Q_OBJECT + +signals: + void invalidIndexEncountered() const; + +public slots: + bool submit() override { ++submit_count; return QAbstractTableModel::submit(); } + +public: + QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = nullptr) + : QAbstractTableModel(parent), row_count(rows), column_count(columns) + {} + + int rowCount(const QModelIndex& = QModelIndex()) const override + { + return row_count; + } + + int columnCount(const QModelIndex& = QModelIndex()) const override + { + return column_count; + } + + bool isEditable(const QModelIndex &) const { return true; } + + Qt::ItemFlags flags(const QModelIndex &index) const override + { + Qt::ItemFlags index_flags = QAbstractTableModel::flags(index); + if (disabled_rows.contains(index.row()) + || disabled_columns.contains(index.column())) + index_flags &= ~Qt::ItemIsEnabled; + return index_flags; + } + + void disableRow(int row) + { + disabled_rows.insert(row); + } + + void enableRow(int row) + { + disabled_rows.remove(row); + } + + void disableColumn(int column) + { + disabled_columns.insert(column); + } + + void enableColumn(int column) + { + disabled_columns.remove(column); + } + + QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override + { + if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) { + qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx; + emit invalidIndexEncountered(); + return QVariant(); + } + + if (role == Qt::DisplayRole || role == Qt::EditRole) { + return QLatin1Char('[') + QString::number(idx.row()) + QLatin1Char(',') + + QString::number(idx.column()) + QLatin1String(",0]"); + } + + return QVariant(); + } + + bool insertRows(int start, int count, const QModelIndex &parent = QModelIndex()) override + { + if (start < 0 || start > row_count) + return false; + + beginInsertRows(parent, start, start + count - 1); + row_count += count; + endInsertRows(); + return true; + } + + bool removeRows(int start, int count, const QModelIndex &parent = QModelIndex()) override + { + if (start < 0 || start >= row_count || row_count < count) + return false; + + beginRemoveRows(parent, start, start + count - 1); + row_count -= count; + endRemoveRows(); + return true; + } + + void removeLastRow() + { + beginRemoveRows(QModelIndex(), row_count - 1, row_count - 1); + --row_count; + endRemoveRows(); + } + + void removeAllRows() + { + beginRemoveRows(QModelIndex(), 0, row_count - 1); + row_count = 0; + endRemoveRows(); + } + + bool insertColumns(int start, int count, const QModelIndex &parent = QModelIndex()) override + { + if (start < 0 || start > column_count) + return false; + + beginInsertColumns(parent, start, start + count - 1); + column_count += count; + endInsertColumns(); + return true; + } + + bool removeColumns(int start, int count, const QModelIndex &parent = QModelIndex()) override + { + if (start < 0 || start >= column_count || column_count < count) + return false; + + beginRemoveColumns(parent, start, start + count - 1); + column_count -= count; + endRemoveColumns(); + return true; + } + + void removeLastColumn() + { + beginRemoveColumns(QModelIndex(), column_count - 1, column_count - 1); + --column_count; + endRemoveColumns(); + } + + void removeAllColumns() + { + beginRemoveColumns(QModelIndex(), 0, column_count - 1); + column_count = 0; + endRemoveColumns(); + } + + bool canFetchMore(const QModelIndex &) const override + { + return can_fetch_more; + } + + void fetchMore(const QModelIndex &) override + { + ++fetch_more_count; + } + + QSet<int> disabled_rows; + QSet<int> disabled_columns; + int row_count; + int column_count; + int submit_count = 0; + int fetch_more_count = 0; + bool can_fetch_more = false; +}; + +class QtTestTableView : public QTableView +{ + Q_OBJECT +public: + using QTableView::QTableView; + + void setModel(QAbstractItemModel *model) override + { + QTableView::setModel(model); + connect(selectionModel(), &QItemSelectionModel::currentChanged, + this, &QtTestTableView::slotCurrentChanged); + connect(selectionModel(), &QItemSelectionModel::selectionChanged, + this, &QtTestTableView::itemSelectionChanged); + // Allow small sections in this test, since this test was made before we correctly enforced minimum sizes. + horizontalHeader()->setMinimumSectionSize(0); + verticalHeader()->setMinimumSectionSize(0); + } + + using QTableView::moveCursor; + using QTableView::isIndexHidden; + using QTableView::setSelection; + using QTableView::selectedIndexes; + using QTableView::sizeHintForRow; + using QTableView::viewOptions; -typedef QList<bool> BoolList; + bool checkSignalOrder = false; +public slots: + void slotCurrentChanged(QModelIndex, QModelIndex) { + hasCurrentChanged++; + if (checkSignalOrder) + QVERIFY(hasCurrentChanged > hasSelectionChanged); + } + + void itemSelectionChanged(QItemSelection , QItemSelection ) { + hasSelectionChanged++; + if (checkSignalOrder) + QVERIFY(hasCurrentChanged >= hasSelectionChanged); + } +private: + int hasCurrentChanged = 0; + int hasSelectionChanged = 0; + + friend class tst_QTableView; + friend struct QMetaTypeId<QtTestTableView::CursorAction>; +}; +Q_DECLARE_METATYPE(QtTestTableView::CursorAction); + +class QtTestItemDelegate : public QStyledItemDelegate +{ +public: + QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const override + { + return hint; + } + + QSize hint; +}; class tst_QTableView : public QObject { Q_OBJECT +private: + using CursorActionList = QVector<QtTestTableView::CursorAction>; private slots: void getSetCheck(); @@ -196,6 +431,10 @@ private slots: void viewOptions(); void taskQTBUG_7232_AllowUserToControlSingleStep(); + +#if QT_CONFIG(textmarkdownwriter) + void markdownWriter(); +#endif }; // Testing get/set functions @@ -229,14 +468,14 @@ void tst_QTableView::getSetCheck() QHeaderView *var1 = new QHeaderView(Qt::Horizontal); obj1.setHorizontalHeader(var1); QCOMPARE(var1, obj1.horizontalHeader()); - obj1.setHorizontalHeader((QHeaderView *)0); + obj1.setHorizontalHeader(nullptr); QCOMPARE(var1, obj1.horizontalHeader()); delete var1; QHeaderView *var2 = new QHeaderView(Qt::Vertical); obj1.setVerticalHeader(var2); QCOMPARE(var2, obj1.verticalHeader()); - obj1.setVerticalHeader((QHeaderView *)0); + obj1.setVerticalHeader(nullptr); QCOMPARE(var2, obj1.verticalHeader()); delete var2; @@ -244,283 +483,12 @@ void tst_QTableView::getSetCheck() obj1.setCornerButtonEnabled(false); QCOMPARE(obj1.isCornerButtonEnabled(), false); } - -class QtTestTableModel: public QAbstractTableModel -{ - Q_OBJECT - -signals: - void invalidIndexEncountered() const; - -public slots: - bool submit() { ++submit_count; return QAbstractTableModel::submit(); } - -public: - QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0) - : QAbstractTableModel(parent), - row_count(rows), - column_count(columns), - submit_count(0), - can_fetch_more(false), - fetch_more_count(0), - disabled_rows(), - disabled_columns() {} - - int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; } - int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; } - bool isEditable(const QModelIndex &) const { return true; } - - Qt::ItemFlags flags(const QModelIndex &index) const - { - Qt::ItemFlags index_flags = QAbstractTableModel::flags(index); - if (disabled_rows.contains(index.row()) - || disabled_columns.contains(index.column())) - index_flags &= ~Qt::ItemIsEnabled; - return index_flags; - } - - void disableRow(int row) - { - disabled_rows.insert(row); - } - - void enableRow(int row) - { - disabled_rows.remove(row); - } - - void disableColumn(int column) - { - disabled_columns.insert(column); - } - - void enableColumn(int column) - { - disabled_columns.remove(column); - } - - QVariant data(const QModelIndex &idx, int role) const - { - if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) { - qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx; - emit invalidIndexEncountered(); - return QVariant(); - } - - if (role == Qt::DisplayRole || role == Qt::EditRole) { - return QLatin1Char('[') + QString::number(idx.row()) + QLatin1Char(',') - + QString::number(idx.column()) + QLatin1String(",0]"); - } - - return QVariant(); - } - - bool insertRows(int start, int count, const QModelIndex &parent = QModelIndex()) - { - if (start < 0 || start > row_count) - return false; - - beginInsertRows(parent, start, start + count - 1); - row_count += count; - endInsertRows(); - return true; - } - - bool removeRows(int start, int count, const QModelIndex &parent = QModelIndex()) - { - if (start < 0 || start >= row_count || row_count < count) - return false; - - beginRemoveRows(parent, start, start + count - 1); - row_count -= count; - endRemoveRows(); - return true; - } - - void removeLastRow() - { - beginRemoveRows(QModelIndex(), row_count - 1, row_count - 1); - --row_count; - endRemoveRows(); - } - - void removeAllRows() - { - beginRemoveRows(QModelIndex(), 0, row_count - 1); - row_count = 0; - endRemoveRows(); - } - - bool insertColumns(int start, int count, const QModelIndex &parent = QModelIndex()) - { - if (start < 0 || start > column_count) - return false; - - beginInsertColumns(parent, start, start + count - 1); - column_count += count; - endInsertColumns(); - return true; - } - - bool removeColumns(int start, int count, const QModelIndex &parent = QModelIndex()) - { - if (start < 0 || start >= column_count || column_count < count) - return false; - - beginRemoveColumns(parent, start, start + count - 1); - column_count -= count; - endRemoveColumns(); - return true; - } - - void removeLastColumn() - { - beginRemoveColumns(QModelIndex(), column_count - 1, column_count - 1); - --column_count; - endRemoveColumns(); - } - - void removeAllColumns() - { - beginRemoveColumns(QModelIndex(), 0, column_count - 1); - column_count = 0; - endRemoveColumns(); - } - - bool canFetchMore(const QModelIndex &) const - { - return can_fetch_more; - } - - void fetchMore(const QModelIndex &) - { - ++fetch_more_count; - } - - void reset() - { - beginResetModel(); - endResetModel(); - } - - int row_count; - int column_count; - int submit_count; - bool can_fetch_more; - int fetch_more_count; - QSet<int> disabled_rows; - QSet<int> disabled_columns; -}; - -class QtTestTableView : public QTableView -{ -Q_OBJECT - -public: - QtTestTableView(QWidget *parent = 0) : QTableView(parent), checkSignalOrder(false), hasCurrentChanged(0), hasSelectionChanged(0) {} - - void setModel(QAbstractItemModel *model) - { - QTableView::setModel(model); - connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), - this, SLOT(slotCurrentChanged(QModelIndex,QModelIndex))); - connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - this, SLOT(itemSelectionChanged(QItemSelection,QItemSelection))); - // Allow small sections in this test, since this test was made before we correctly enforced minimum sizes. - horizontalHeader()->setMinimumSectionSize(0); - verticalHeader()->setMinimumSectionSize(0); - } - - // enum CursorAction and moveCursor() are protected in QTableView. - enum CursorAction { - MoveUp = QAbstractItemView::MoveUp, - MoveDown = QAbstractItemView::MoveDown, - MoveLeft = QAbstractItemView::MoveLeft, - MoveRight = QAbstractItemView::MoveRight, - MoveHome = QAbstractItemView::MoveHome, - MoveEnd = QAbstractItemView::MoveEnd, - MovePageUp = QAbstractItemView::MovePageUp, - MovePageDown = QAbstractItemView::MovePageDown, - MoveNext = QAbstractItemView::MoveNext, - MovePrevious = QAbstractItemView::MovePrevious - }; - - QModelIndex doMoveCursor(QtTestTableView::CursorAction cursorAction, - Qt::KeyboardModifiers modifiers) - { - return QTableView::moveCursor((QAbstractItemView::CursorAction)cursorAction, modifiers); - } - - int columnWidthHint(int column) const - { - return sizeHintForColumn(column); - } - - int rowHeightHint(int row) const - { - return sizeHintForRow(row); - } - - bool isIndexHidden(const QModelIndex &index) const - { - return QTableView::isIndexHidden(index); - } - - void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) - { - QTableView::setSelection(rect, command); - } - - QModelIndexList selectedIndexes() const - { - return QTableView::selectedIndexes(); - } - - int sizeHintForRow(int row) const - { - return QTableView::sizeHintForRow(row); - } - - QStyleOptionViewItem viewOptions() const { - return QTableView::viewOptions(); - } - - bool checkSignalOrder; -public slots: - void slotCurrentChanged(QModelIndex, QModelIndex) { - hasCurrentChanged++; - if (checkSignalOrder) - QVERIFY(hasCurrentChanged > hasSelectionChanged); - } - - void itemSelectionChanged(QItemSelection , QItemSelection ) { - hasSelectionChanged++; - if (checkSignalOrder) - QVERIFY(hasCurrentChanged >= hasSelectionChanged); - } -private: - int hasCurrentChanged; - int hasSelectionChanged; - -}; - -class QtTestItemDelegate : public QItemDelegate -{ -public: - QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const - { - return hint; - } - - QSize hint; -}; - void tst_QTableView::noDelegate() { QtTestTableModel model(3, 3); QTableView view; view.setModel(&model); - view.setItemDelegate(0); + view.setItemDelegate(nullptr); view.show(); } @@ -534,7 +502,7 @@ void tst_QTableView::emptyModel() { QtTestTableModel model; QTableView view; - QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered())); + QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered); view.setModel(&model); view.show(); QCOMPARE(spy.count(), 0); @@ -555,7 +523,7 @@ void tst_QTableView::removeRows() QFETCH(int, columnCount); QtTestTableModel model(rowCount, columnCount); - QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered())); + QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered); QTableView view; view.setModel(&model); @@ -583,7 +551,7 @@ void tst_QTableView::removeColumns() QFETCH(int, columnCount); QtTestTableModel model(rowCount, columnCount); - QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered())); + QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered); QTableView view; view.setModel(&model); @@ -601,58 +569,18 @@ void tst_QTableView::keyboardNavigation_data() QTest::addColumn<int>("rowCount"); QTest::addColumn<int>("columnCount"); QTest::addColumn<bool>("tabKeyNavigation"); - QTest::addColumn<IntList>("keyPresses"); - - QTest::newRow("16x16 model") << 16 << 16 << true - << (IntList() - << Qt::Key_Up - << Qt::Key_Up - << Qt::Key_Right - << Qt::Key_Right - << Qt::Key_Up - << Qt::Key_Left - << Qt::Key_Left - << Qt::Key_Up - << Qt::Key_Down - << Qt::Key_Up - << 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 - << Qt::Key_Down - << Qt::Key_Tab - << Qt::Key_Backtab); - - - QTest::newRow("no tab") << 8 << 8 << false - << (IntList() - << Qt::Key_Up - << Qt::Key_Up - << Qt::Key_Right - << Qt::Key_Right - << Qt::Key_Up - << Qt::Key_Left - << Qt::Key_Left - << Qt::Key_Up - << Qt::Key_Down - << Qt::Key_Up - << 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 - << Qt::Key_Down - << Qt::Key_Tab - << Qt::Key_Backtab); + QTest::addColumn<KeyList>("keyPresses"); + + const KeyList keyList { + Qt::Key_Up, Qt::Key_Up, Qt::Key_Right, Qt::Key_Right, + Qt::Key_Up, Qt::Key_Left, Qt::Key_Left, Qt::Key_Up, + Qt::Key_Down, Qt::Key_Up, 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, Qt::Key_Down, + Qt::Key_Tab, Qt::Key_Backtab}; + + QTest::newRow("16x16 model") << 16 << 16 << true << keyList; + QTest::newRow("no tab") << 8 << 8 << false << keyList; } void tst_QTableView::keyboardNavigation() @@ -660,7 +588,7 @@ void tst_QTableView::keyboardNavigation() QFETCH(int, rowCount); QFETCH(int, columnCount); QFETCH(bool, tabKeyNavigation); - QFETCH(IntList, keyPresses); + QFETCH(const KeyList, keyPresses); QtTestTableModel model(rowCount, columnCount); QTableView view; @@ -671,14 +599,12 @@ void tst_QTableView::keyboardNavigation() view.setCurrentIndex(index); view.show(); - qApp->setActiveWindow(&view); + QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); int row = rowCount - 1; int column = columnCount - 1; - for (int i = 0; i < keyPresses.count(); ++i) { - - Qt::Key key = (Qt::Key)keyPresses.at(i); + for (Qt::Key key : keyPresses) { switch (key) { case Qt::Key_Up: @@ -778,8 +704,8 @@ void tst_QTableView::moveCursor_data() QTest::addColumn<int>("startRow"); QTest::addColumn<int>("startColumn"); - QTest::addColumn<int>("cursorMoveAction"); - QTest::addColumn<int>("modifier"); + QTest::addColumn<QtTestTableView::CursorAction>("cursorMoveAction"); + QTest::addColumn<Qt::KeyboardModifier>("modifier"); QTest::addColumn<int>("expectedRow"); QTest::addColumn<int>("expectedColumn"); @@ -790,346 +716,346 @@ void tst_QTableView::moveCursor_data() QTest::newRow("MoveRight (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveRight) << int(Qt::NoModifier) + << QtTestTableView::MoveRight << Qt::NoModifier << 0 << 1 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveRight (3,0)") << 4 << 4 << -1 << -1 << 3 << 0 - << int(QtTestTableView::MoveRight) << int(Qt::NoModifier) + << QtTestTableView::MoveRight << Qt::NoModifier << 3 << 1 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveRight (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MoveRight) << int(Qt::NoModifier) + << QtTestTableView::MoveRight << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); // ### QTest::newRow("MoveRight, hidden column 1 (0,0)") << 4 << 4 << -1 << 1 << 0 << 0 - << int(QtTestTableView::MoveRight) << int(Qt::NoModifier) + << QtTestTableView::MoveRight << Qt::NoModifier << 0 << 2 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveRight, hidden column 3 (0,2)") << 4 << 4 << -1 << 3 << 0 << 2 - << int(QtTestTableView::MoveRight) << int(Qt::NoModifier) + << QtTestTableView::MoveRight << Qt::NoModifier << 0 << 2 << IntPair(0,0) << IntPair(0,0); // ### // MoveNext should in addition wrap QTest::newRow("MoveNext (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 0 << 1 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext (0,2)") << 4 << 4 << -1 << -1 << 0 << 2 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 0 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext, wrap (0,3)") << 4 << 4 << -1 << -1 << 0 << 3 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 1 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext, wrap (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext, hidden column 1 (0,0)") << 4 << 4 << -1 << 1 << 0 << 0 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 0 << 2 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext, wrap, hidden column 3 (0,2)") << 4 << 4 << -1 << 3 << 0 << 2 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 1 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext, wrap, hidden column 3 (3,2)") << 4 << 4 << -1 << 3 << 3 << 2 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext, wrapy, wrapx, hidden column 3, hidden row 3 (2,2)") << 4 << 4 << 3 << 3 << 2 << 2 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext, wrap, hidden column 2, moved column from 3 to 0. (0,2)") << 4 << 4 << -1 << 2 << 0 << 2 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 1 << 3 << IntPair(0,0) << IntPair(3,0); // MoveLeft QTest::newRow("MoveLeft (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) + << QtTestTableView::MoveLeft << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveLeft (0,3)") << 4 << 4 << -1 << -1 << 0 << 3 - << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) + << QtTestTableView::MoveLeft << Qt::NoModifier << 0 << 2 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveLeft (1,0)") << 4 << 4 << -1 << -1 << 1 << 0 - << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) + << QtTestTableView::MoveLeft << Qt::NoModifier << 1 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveLeft, hidden column 0 (0,2)") << 4 << 4 << -1 << 1 << 0 << 2 - << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) + << QtTestTableView::MoveLeft << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveLeft, hidden column 0 (0,1)") << 4 << 4 << -1 << 0 << 0 << 1 - << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) + << QtTestTableView::MoveLeft << Qt::NoModifier << 0 << 1 << IntPair(0,0) << IntPair(0,0); // MovePrevious should in addition wrap QTest::newRow("MovePrevious (0,3)") << 4 << 4 << -1 << -1 << 0 << 3 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 0 << 2 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious (0,1)") << 4 << 4 << -1 << -1 << 0 << 1 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious, wrap (1,0)") << 4 << 4 << -1 << -1 << 1 << 0 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 0 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious, wrap, (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious, hidden column 1 (0,2)") << 4 << 4 << -1 << 1 << 0 << 2 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious, wrap, hidden column 3 (0,2)") << 4 << 4 << -1 << 3 << 0 << 2 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 0 << 1 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious, wrapy, hidden column 0 (0,1)") << 4 << 4 << -1 << 0 << 0 << 1 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious, wrap, hidden column 0, hidden row 0 (1,1)") << 4 << 4 << 0 << 0 << 1 << 1 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious, wrap, hidden column 1, moved column from 0 to 3. (1,2)") << 4 << 4 << -1 << 1 << 1 << 2 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,3); // MoveDown QTest::newRow("MoveDown (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveDown) << int(Qt::NoModifier) + << QtTestTableView::MoveDown << Qt::NoModifier << 1 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveDown (3,0)") << 4 << 4 << -1 << -1 << 3 << 0 - << int(QtTestTableView::MoveDown) << int(Qt::NoModifier) + << QtTestTableView::MoveDown << Qt::NoModifier << 3 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveDown (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MoveDown) << int(Qt::NoModifier) + << QtTestTableView::MoveDown << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveDown, hidden row 1 (0,0)") << 4 << 4 << 1 << -1 << 0 << 0 - << int(QtTestTableView::MoveDown) << int(Qt::NoModifier) + << QtTestTableView::MoveDown << Qt::NoModifier << 2 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveDown, hidden row 3 (2,0)") << 4 << 4 << 3 << -1 << 2 << 0 - << int(QtTestTableView::MoveDown) << int(Qt::NoModifier) + << QtTestTableView::MoveDown << Qt::NoModifier << 2 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveDown, hidden row 0 hidden column 0 (0,0)") << 4 << 4 << 0 << 0 << 0 << 0 - << int(QtTestTableView::MoveDown) << int(Qt::NoModifier) + << QtTestTableView::MoveDown << Qt::NoModifier << 1 << 1 << IntPair(0,0) << IntPair(0,0); // MoveUp QTest::newRow("MoveUp (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveUp) << int(Qt::NoModifier) + << QtTestTableView::MoveUp << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveUp (3, 0)") << 4 << 4 << -1 << -1 << 3 << 0 - << int(QtTestTableView::MoveUp) << int(Qt::NoModifier) + << QtTestTableView::MoveUp << Qt::NoModifier << 2 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveUp (0,1)") << 4 << 4 << -1 << -1 << 0 << 1 - << int(QtTestTableView::MoveUp) << int(Qt::NoModifier) + << QtTestTableView::MoveUp << Qt::NoModifier << 0 << 1 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveUp, hidden row 1 (2,0)") << 4 << 4 << 1 << -1 << 2 << 0 - << int(QtTestTableView::MoveUp) << int(Qt::NoModifier) + << QtTestTableView::MoveUp << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveUp, hidden row (1,0)") << 4 << 4 << 0 << -1 << 1 << 0 - << int(QtTestTableView::MoveUp) << int(Qt::NoModifier) + << QtTestTableView::MoveUp << Qt::NoModifier << 1 << 0 << IntPair(0,0) << IntPair(0,0); // MoveHome QTest::newRow("MoveHome (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveHome) << int(Qt::NoModifier) + << QtTestTableView::MoveHome << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveHome (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MoveHome) << int(Qt::NoModifier) + << QtTestTableView::MoveHome << Qt::NoModifier << 3 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveHome, hidden column 0 (3,3)") << 4 << 4 << -1 << 0 << 3 << 3 - << int(QtTestTableView::MoveHome) << int(Qt::NoModifier) + << QtTestTableView::MoveHome << Qt::NoModifier << 3 << 1 << IntPair(0,0) << IntPair(0,0); // Use Ctrl modifier QTest::newRow("MoveHome + Ctrl (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier) + << QtTestTableView::MoveHome << Qt::ControlModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveHome + Ctrl (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier) + << QtTestTableView::MoveHome << Qt::ControlModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveHome + Ctrl, hidden column 0, hidden row 0 (3,3)") << 4 << 4 << 0 << 0 << 3 << 3 - << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier) + << QtTestTableView::MoveHome << Qt::ControlModifier << 1 << 1 << IntPair(0,0) << IntPair(0,0); // MoveEnd QTest::newRow("MoveEnd (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier) + << QtTestTableView::MoveEnd << Qt::NoModifier << 0 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveEnd (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier) + << QtTestTableView::MoveEnd << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveEnd, hidden column (0,0)") << 4 << 4 << -1 << 3 << 0 << 0 - << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier) + << QtTestTableView::MoveEnd << Qt::NoModifier << 0<< 2 << IntPair(0,0) << IntPair(0,0); // Use Ctrl modifier QTest::newRow("MoveEnd + Ctrl (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier) + << QtTestTableView::MoveEnd << Qt::ControlModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveEnd + Ctrl (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier) + << QtTestTableView::MoveEnd << Qt::ControlModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveEnd + Ctrl, hidden column 3 (0,0)") << 4 << 4 << -1 << 3 << 0 << 0 - << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier) + << QtTestTableView::MoveEnd << Qt::ControlModifier << 3 << 2 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveEnd + Ctrl, hidden column 3, hidden row 3 (0,0)") << 4 << 4 << 3 << 3 << 0 << 0 - << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier) + << QtTestTableView::MoveEnd << Qt::ControlModifier << 2 << 2 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePageUp (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MovePageUp) << 0 + << QtTestTableView::MovePageUp << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePageUp (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MovePageUp) << 0 + << QtTestTableView::MovePageUp << Qt::NoModifier << 0 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePageDown (3, 3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MovePageDown) << 0 + << QtTestTableView::MovePageDown << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePageDown (0, 3)") << 4 << 4 << -1 << -1 << 0 << 3 - << int(QtTestTableView::MovePageDown) << 0 + << QtTestTableView::MovePageDown << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); } @@ -1141,8 +1067,8 @@ void tst_QTableView::moveCursor() QFETCH(int, hideColumn); QFETCH(int, startRow); QFETCH(int, startColumn); - QFETCH(int, cursorMoveAction); - QFETCH(int, modifier); + QFETCH(QtTestTableView::CursorAction, cursorMoveAction); + QFETCH(Qt::KeyboardModifier, modifier); QFETCH(int, expectedRow); QFETCH(int, expectedColumn); QFETCH(IntPair, moveRow); @@ -1167,8 +1093,7 @@ void tst_QTableView::moveCursor() QModelIndex index = model.index(startRow, startColumn); view.setCurrentIndex(index); - QModelIndex newIndex = view.doMoveCursor((QtTestTableView::CursorAction)cursorMoveAction, - (Qt::KeyboardModifiers)modifier); + QModelIndex newIndex = view.moveCursor(cursorMoveAction, modifier); // expected fails, task 119433 if(newIndex.row() == -1) return; @@ -1186,7 +1111,7 @@ void tst_QTableView::moveCursorStrikesBack_data() QTest::addColumn<int>("startRow"); QTest::addColumn<int>("startColumn"); - QTest::addColumn<IntList>("cursorMoveActions"); + QTest::addColumn<CursorActionList>("cursorMoveActions"); QTest::addColumn<int>("expectedRow"); QTest::addColumn<int>("expectedColumn"); @@ -1194,70 +1119,84 @@ void tst_QTableView::moveCursorStrikesBack_data() << IntList() << (IntList() << 6) << QRect() - << 0 << 5 << (IntList() << int(QtTestTableView::MoveNext)) + << 0 << 5 + << CursorActionList{QtTestTableView::MoveNext} << 1 << 0; QTest::newRow("Last column disabled 2. Task QTBUG-3878") << -1 << -1 << IntList() << (IntList() << 6) << QRect() - << 1 << 0 << (IntList() << int(QtTestTableView::MovePrevious)) + << 1 << 0 + << CursorActionList{QtTestTableView::MovePrevious} << 0 << 5; QTest::newRow("Span, anchor column hidden") << -1 << 1 << IntList() << IntList() << QRect(1, 2, 2, 3) - << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext)) + << 2 << 0 + << CursorActionList{QtTestTableView::MoveNext} << 2 << 1; QTest::newRow("Span, anchor column disabled") << -1 << -1 << IntList() << (IntList() << 1) << QRect(1, 2, 2, 3) - << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext)) + << 2 << 0 + << CursorActionList{QtTestTableView::MoveNext} << 2 << 1; QTest::newRow("Span, anchor row hidden") << 2 << -1 << IntList() << IntList() << QRect(1, 2, 2, 3) - << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown)) + << 1 << 2 + << CursorActionList{QtTestTableView::MoveDown} << 2 << 1; QTest::newRow("Span, anchor row disabled") << -1 << -1 << (IntList() << 2) << IntList() << QRect(1, 2, 2, 3) - << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown)) + << 1 << 2 + << CursorActionList{QtTestTableView::MoveDown} << 2 << 1; QTest::newRow("Move through span right") << -1 << -1 << IntList() << IntList() << QRect(1, 2, 2, 3) - << 3 << 0 << (IntList() << int(QtTestTableView::MoveRight) << int(QtTestTableView::MoveRight)) + << 3 << 0 + << CursorActionList{QtTestTableView::MoveRight, + QtTestTableView::MoveRight} << 3 << 3; QTest::newRow("Move through span left") << -1 << -1 << IntList() << IntList() << QRect(1, 2, 2, 3) - << 3 << 3 << (IntList() << int(QtTestTableView::MoveLeft) << int(QtTestTableView::MoveLeft)) + << 3 << 3 + << CursorActionList{QtTestTableView::MoveLeft, + QtTestTableView::MoveLeft} << 3 << 0; QTest::newRow("Move through span down") << -1 << -1 << IntList() << IntList() << QRect(1, 2, 2, 3) - << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown) << int(QtTestTableView::MoveDown)) + << 1 << 2 + << CursorActionList{QtTestTableView::MoveDown, + QtTestTableView::MoveDown} << 5 << 2; QTest::newRow("Move through span up") << -1 << -1 << IntList() << IntList() << QRect(1, 2, 2, 3) - << 5 << 2 << (IntList() << int(QtTestTableView::MoveUp) << int(QtTestTableView::MoveUp)) + << 5 << 2 + << CursorActionList{QtTestTableView::MoveUp, + QtTestTableView::MoveUp} << 1 << 2; IntList fullList; @@ -1268,42 +1207,48 @@ void tst_QTableView::moveCursorStrikesBack_data() << fullList << fullList << QRect() - << 1 << 0 << (IntList() << int(QtTestTableView::MoveNext)) + << 1 << 0 + << CursorActionList{QtTestTableView::MoveNext} << -1 << -1; QTest::newRow("All disabled, wrap backwards. => invalid index") << -1 << -1 << fullList << fullList << QRect() - << 1 << 0 << (IntList() << int(QtTestTableView::MovePrevious)) + << 1 << 0 + << CursorActionList{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 << 0 + << CursorActionList{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 << 6 + << CursorActionList{QtTestTableView::MoveHome} << 0 << 1; QTest::newRow("First row disabled, MovePageUp. QTBUG-72400") << -1 << -1 << (IntList() << 0) << IntList() << QRect() - << 2 << 0 << (IntList() << int(QtTestTableView::MovePageUp)) + << 2 << 0 + << CursorActionList{QtTestTableView::MovePageUp} << 1 << 0; QTest::newRow("Last row disabled, MovePageDown. QTBUG-72400") << -1 << -1 << (IntList() << 6) << IntList() << QRect() - << 4 << 0 << (IntList() << int(QtTestTableView::MovePageDown)) + << 4 << 0 + << CursorActionList{QtTestTableView::MovePageDown} << 5 << 0; } @@ -1311,13 +1256,13 @@ void tst_QTableView::moveCursorStrikesBack() { QFETCH(int, hideRow); QFETCH(int, hideColumn); - QFETCH(IntList, disableRows); - QFETCH(IntList, disableColumns); + QFETCH(const IntList, disableRows); + QFETCH(const IntList, disableColumns); QFETCH(QRect, span); QFETCH(int, startRow); QFETCH(int, startColumn); - QFETCH(IntList, cursorMoveActions); + QFETCH(const CursorActionList, cursorMoveActions); QFETCH(int, expectedRow); QFETCH(int, expectedColumn); @@ -1337,15 +1282,15 @@ void tst_QTableView::moveCursorStrikesBack() QModelIndex index = model.index(startRow, startColumn); view.setCurrentIndex(index); - foreach (int row, disableRows) + for (int row : disableRows) model.disableRow(row); - foreach (int column, disableColumns) + for (int column : disableColumns) model.disableColumn(column); int newRow = -1; int newColumn = -1; - foreach (int cursorMoveAction, cursorMoveActions) { - QModelIndex newIndex = view.doMoveCursor((QtTestTableView::CursorAction)cursorMoveAction, 0); + for (auto cursorMoveAction : cursorMoveActions) { + QModelIndex newIndex = view.moveCursor(cursorMoveAction, nullptr); view.setCurrentIndex(newIndex); newRow = newIndex.row(); newColumn = newIndex.column(); @@ -1516,7 +1461,7 @@ void tst_QTableView::selection_data() QTest::addColumn<int>("y"); QTest::addColumn<int>("width"); QTest::addColumn<int>("height"); - QTest::addColumn<int>("command"); + QTest::addColumn<QItemSelectionModel::SelectionFlag>("command"); QTest::addColumn<int>("selectedCount"); // ### make this more detailed QTest::newRow("no span, no hidden, no moved, 3x3 select") @@ -1528,7 +1473,7 @@ void tst_QTableView::selection_data() << -1 << -1 // move col << 40 << 40 // cell size << 20 << 20 << 80 << 80 // rect - << int(QItemSelectionModel::Select) // command + << QItemSelectionModel::Select // command << 9; // selected count QTest::newRow("row span, no hidden, no moved, 3x3 select") @@ -1540,7 +1485,7 @@ void tst_QTableView::selection_data() << -1 << -1 // move col << 40 << 40 // cell size << 20 << 20 << 80 << 80 // rect - << int(QItemSelectionModel::Select) // command + << QItemSelectionModel::Select // command << 8; // selected count QTest::newRow("col span, no hidden, no moved, 3x3 select") @@ -1552,7 +1497,7 @@ void tst_QTableView::selection_data() << -1 << -1 // move col << 40 << 40 // cell size << 20 << 20 << 80 << 80 // rect - << int(QItemSelectionModel::Select) // command + << QItemSelectionModel::Select // command << 8; // selected count QTest::newRow("no span, row hidden, no moved, 3x3 select") @@ -1564,7 +1509,7 @@ void tst_QTableView::selection_data() << -1 << -1 // move col << 40 << 40 // cell size << 20 << 20 << 80 << 80 // rect - << int(QItemSelectionModel::Select) // command + << QItemSelectionModel::Select // command << 9; // selected count QTest::newRow("no span, col hidden, no moved, 3x3 select") @@ -1576,7 +1521,7 @@ void tst_QTableView::selection_data() << -1 << -1 // move col << 40 << 40 // cell size << 20 << 20 << 80 << 80 // rect - << int(QItemSelectionModel::Select) // command + << QItemSelectionModel::Select // command << 9; // selected count QTest::newRow("no span, no hidden, row moved, 3x3 select") @@ -1588,7 +1533,7 @@ void tst_QTableView::selection_data() << -1 << -1 // move col << 40 << 40 // cell size << 20 << 20 << 80 << 80 // rect - << int(QItemSelectionModel::Select) // command + << QItemSelectionModel::Select // command << 9; // selected count QTest::newRow("no span, no hidden, col moved, 3x3 select") @@ -1600,7 +1545,7 @@ void tst_QTableView::selection_data() << 1 << 3 // move col << 40 << 40 // cell size << 20 << 20 << 80 << 80 // rect - << int(QItemSelectionModel::Select) // command + << QItemSelectionModel::Select // command << 9; // selected count } @@ -1624,7 +1569,7 @@ void tst_QTableView::selection() QFETCH(int, y); QFETCH(int, width); QFETCH(int, height); - QFETCH(int, command); + QFETCH(QItemSelectionModel::SelectionFlag, command); QFETCH(int, selectedCount); QtTestTableModel model(rowCount, columnCount); @@ -1646,8 +1591,7 @@ void tst_QTableView::selection() for (int c = 0; c < columnCount; ++c) view.setColumnWidth(c, columnWidth); - view.setSelection(QRect(x, y, width, height), - QItemSelectionModel::SelectionFlags(command)); + view.setSelection(QRect(x, y, width, height), command); QCOMPARE(view.selectedIndexes().count(), selectedCount); } @@ -1657,92 +1601,92 @@ void tst_QTableView::selectRow_data() QTest::addColumn<int>("rowCount"); QTest::addColumn<int>("columnCount"); QTest::addColumn<int>("row"); - QTest::addColumn<int>("mode"); - QTest::addColumn<int>("behavior"); + QTest::addColumn<QAbstractItemView::SelectionMode>("mode"); + QTest::addColumn<QAbstractItemView::SelectionBehavior>("behavior"); QTest::addColumn<int>("selectedItems"); QTest::newRow("SingleSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::SingleSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::SingleSelection + << QAbstractItemView::SelectItems << 0; QTest::newRow("SingleSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::SingleSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::SingleSelection + << QAbstractItemView::SelectRows << 10; QTest::newRow("SingleSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::SingleSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::SingleSelection + << QAbstractItemView::SelectColumns << 0; QTest::newRow("MultiSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::MultiSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::MultiSelection + << QAbstractItemView::SelectItems << 10; QTest::newRow("MultiSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::MultiSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::MultiSelection + << QAbstractItemView::SelectRows << 10; QTest::newRow("MultiSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::MultiSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::MultiSelection + << QAbstractItemView::SelectColumns << 0; QTest::newRow("ExtendedSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::ExtendedSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::ExtendedSelection + << QAbstractItemView::SelectItems << 10; QTest::newRow("ExtendedSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::ExtendedSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::ExtendedSelection + << QAbstractItemView::SelectRows << 10; QTest::newRow("ExtendedSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::ExtendedSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::ExtendedSelection + << QAbstractItemView::SelectColumns << 0; QTest::newRow("ContiguousSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::ContiguousSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::ContiguousSelection + << QAbstractItemView::SelectItems << 10; QTest::newRow("ContiguousSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::ContiguousSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::ContiguousSelection + << QAbstractItemView::SelectRows << 10; QTest::newRow("ContiguousSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::ContiguousSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::ContiguousSelection + << QAbstractItemView::SelectColumns << 0; } @@ -1751,16 +1695,16 @@ void tst_QTableView::selectRow() QFETCH(int, rowCount); QFETCH(int, columnCount); QFETCH(int, row); - QFETCH(int, mode); - QFETCH(int, behavior); + QFETCH(QAbstractItemView::SelectionMode, mode); + QFETCH(QAbstractItemView::SelectionBehavior, behavior); QFETCH(int, selectedItems); QtTestTableModel model(rowCount, columnCount); QTableView view; view.setModel(&model); - view.setSelectionMode((QAbstractItemView::SelectionMode)mode); - view.setSelectionBehavior((QAbstractItemView::SelectionBehavior)behavior); + view.setSelectionMode(mode); + view.setSelectionBehavior(behavior); QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0); @@ -1778,92 +1722,92 @@ void tst_QTableView::selectColumn_data() QTest::addColumn<int>("rowCount"); QTest::addColumn<int>("columnCount"); QTest::addColumn<int>("column"); - QTest::addColumn<int>("mode"); - QTest::addColumn<int>("behavior"); + QTest::addColumn<QAbstractItemView::SelectionMode>("mode"); + QTest::addColumn<QAbstractItemView::SelectionBehavior>("behavior"); QTest::addColumn<int>("selectedItems"); QTest::newRow("SingleSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::SingleSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::SingleSelection + << QAbstractItemView::SelectItems << 0; QTest::newRow("SingleSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::SingleSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::SingleSelection + << QAbstractItemView::SelectRows << 0; QTest::newRow("SingleSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::SingleSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::SingleSelection + << QAbstractItemView::SelectColumns << 10; QTest::newRow("MultiSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::MultiSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::MultiSelection + << QAbstractItemView::SelectItems << 10; QTest::newRow("MultiSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::MultiSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::MultiSelection + << QAbstractItemView::SelectRows << 0; QTest::newRow("MultiSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::MultiSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::MultiSelection + << QAbstractItemView::SelectColumns << 10; QTest::newRow("ExtendedSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::ExtendedSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::ExtendedSelection + << QAbstractItemView::SelectItems << 10; QTest::newRow("ExtendedSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::ExtendedSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::ExtendedSelection + << QAbstractItemView::SelectRows << 0; QTest::newRow("ExtendedSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::ExtendedSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::ExtendedSelection + << QAbstractItemView::SelectColumns << 10; QTest::newRow("ContiguousSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::ContiguousSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::ContiguousSelection + << QAbstractItemView::SelectItems << 10; QTest::newRow("ContiguousSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::ContiguousSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::ContiguousSelection + << QAbstractItemView::SelectRows << 0; QTest::newRow("ContiguousSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::ContiguousSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::ContiguousSelection + << QAbstractItemView::SelectColumns << 10; } @@ -1872,16 +1816,16 @@ void tst_QTableView::selectColumn() QFETCH(int, rowCount); QFETCH(int, columnCount); QFETCH(int, column); - QFETCH(int, mode); - QFETCH(int, behavior); + QFETCH(QAbstractItemView::SelectionMode, mode); + QFETCH(QAbstractItemView::SelectionBehavior, behavior); QFETCH(int, selectedItems); QtTestTableModel model(rowCount, columnCount); QTableView view; view.setModel(&model); - view.setSelectionMode((QAbstractItemView::SelectionMode)mode); - view.setSelectionBehavior((QAbstractItemView::SelectionBehavior)behavior); + view.setSelectionMode(mode); + view.setSelectionBehavior(behavior); QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0); @@ -1981,9 +1925,9 @@ void tst_QTableView::selectall_data() << 100; // selected count } -void QTest__keySequence(QWidget* widget, QKeySequence ks) +void QTest__keySequence(QWidget* widget, const QKeySequence &ks) { - for (int i=0; i<ks.count(); ++i) + for (int i = 0; i < ks.count(); ++i) { Qt::Key key = Qt::Key(ks[i] & ~Qt::KeyboardModifierMask); Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers(ks[i] & Qt::KeyboardModifierMask); @@ -2221,7 +2165,7 @@ void tst_QTableView::resizeRowsToContents() QFETCH(int, cellHeight); QFETCH(int, rowHeight); QFETCH(int, columnWidth); - Q_UNUSED(columnWidth); + Q_UNUSED(columnWidth) QtTestTableModel model(rowCount, columnCount); QtTestTableView view; @@ -2233,13 +2177,12 @@ void tst_QTableView::resizeRowsToContents() delegate.hint = QSize(cellWidth, cellHeight); - QSignalSpy resizedSpy(view.verticalHeader(), SIGNAL(sectionResized(int,int,int))); + QSignalSpy resizedSpy(view.verticalHeader(), &QHeaderView::sectionResized); view.resizeRowsToContents(); QCOMPARE(resizedSpy.count(), model.rowCount()); - for (int r = 0; r < model.rowCount(); ++r) { + for (int r = 0; r < model.rowCount(); ++r) QCOMPARE(view.rowHeight(r), rowHeight); - } } void tst_QTableView::resizeColumnsToContents_data() @@ -2268,7 +2211,7 @@ void tst_QTableView::resizeColumnsToContents() QFETCH(int, cellHeight); QFETCH(int, rowHeight); QFETCH(int, columnWidth); - Q_UNUSED(rowHeight); + Q_UNUSED(rowHeight) QtTestTableModel model(rowCount, columnCount); QtTestTableView view; @@ -2280,7 +2223,7 @@ void tst_QTableView::resizeColumnsToContents() delegate.hint = QSize(cellWidth, cellHeight); - QSignalSpy resizedSpy(view.horizontalHeader(), SIGNAL(sectionResized(int,int,int))); + QSignalSpy resizedSpy(view.horizontalHeader(), &QHeaderView::sectionResized); view.resizeColumnsToContents(); QCOMPARE(resizedSpy.count(), model.columnCount()); @@ -2293,51 +2236,51 @@ void tst_QTableView::rowViewportPosition_data() QTest::addColumn<int>("rowCount"); QTest::addColumn<int>("rowHeight"); QTest::addColumn<int>("row"); - QTest::addColumn<int>("verticalScrollMode"); + QTest::addColumn<QAbstractItemView::ScrollMode>("verticalScrollMode"); QTest::addColumn<int>("verticalScrollValue"); QTest::addColumn<int>("rowViewportPosition"); QTest::newRow("row 0, scroll per item 0") - << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerItem) << 0 << 0; + << 10 << 40 << 0 << QAbstractItemView::ScrollPerItem << 0 << 0; QTest::newRow("row 1, scroll per item, 0") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 0 << 1 * 40; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 0 << 1 * 40; QTest::newRow("row 1, scroll per item, 1") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 1 << 0; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 1 << 0; QTest::newRow("row 5, scroll per item, 0") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 0 << 5 * 40; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 0 << 5 * 40; QTest::newRow("row 5, scroll per item, 5") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 5 << 0; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 5 << 0; QTest::newRow("row 9, scroll per item, 0") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 0 << 9 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 0 << 9 * 40; QTest::newRow("row 9, scroll per item, 5") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 5 << 4 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 5 << 4 * 40; QTest::newRow("row 0, scroll per pixel 0") - << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerPixel) << 0 << 0; + << 10 << 40 << 0 << QAbstractItemView::ScrollPerPixel << 0 << 0; QTest::newRow("row 1, scroll per pixel, 0") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 0 << 1 * 40; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 0 << 1 * 40; QTest::newRow("row 1, scroll per pixel, 1") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 1 * 40 << 0; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 1 * 40 << 0; QTest::newRow("row 5, scroll per pixel, 0") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 0 << 5 * 40; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 0 << 5 * 40; QTest::newRow("row 5, scroll per pixel, 5") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 0; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 0; QTest::newRow("row 9, scroll per pixel, 0") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 0 << 9 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 0 << 9 * 40; QTest::newRow("row 9, scroll per pixel, 5") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 4 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 4 * 40; } void tst_QTableView::rowViewportPosition() @@ -2345,7 +2288,7 @@ void tst_QTableView::rowViewportPosition() QFETCH(int, rowCount); QFETCH(int, rowHeight); QFETCH(int, row); - QFETCH(int, verticalScrollMode); + QFETCH(QAbstractItemView::ScrollMode, verticalScrollMode); QFETCH(int, verticalScrollValue); QFETCH(int, rowViewportPosition); @@ -2359,7 +2302,7 @@ void tst_QTableView::rowViewportPosition() for (int r = 0; r < rowCount; ++r) view.setRowHeight(r, rowHeight); - view.setVerticalScrollMode((QAbstractItemView::ScrollMode)verticalScrollMode); + view.setVerticalScrollMode(verticalScrollMode); view.verticalScrollBar()->setValue(verticalScrollValue); #ifdef Q_OS_WINRT @@ -2464,51 +2407,51 @@ void tst_QTableView::columnViewportPosition_data() QTest::addColumn<int>("columnCount"); QTest::addColumn<int>("columnWidth"); QTest::addColumn<int>("column"); - QTest::addColumn<int>("horizontalScrollMode"); + QTest::addColumn<QAbstractItemView::ScrollMode>("horizontalScrollMode"); QTest::addColumn<int>("horizontalScrollValue"); QTest::addColumn<int>("columnViewportPosition"); QTest::newRow("column 0, scroll per item 0") - << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerItem) << 0 << 0; + << 10 << 40 << 0 << QAbstractItemView::ScrollPerItem << 0 << 0; QTest::newRow("column 1, scroll per item, 0") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 0 << 1 * 40; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 0 << 1 * 40; QTest::newRow("column 1, scroll per item, 1") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 1 << 0; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 1 << 0; QTest::newRow("column 5, scroll per item, 0") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 0 << 5 * 40; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 0 << 5 * 40; QTest::newRow("column 5, scroll per item, 5") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 5 << 0; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 5 << 0; QTest::newRow("column 9, scroll per item, 0") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 0 << 9 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 0 << 9 * 40; QTest::newRow("column 9, scroll per item, 5") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 5 << 4 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 5 << 4 * 40; QTest::newRow("column 0, scroll per pixel 0") - << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerPixel) << 0 << 0; + << 10 << 40 << 0 << QAbstractItemView::ScrollPerPixel << 0 << 0; QTest::newRow("column 1, scroll per pixel 0") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 0 << 1 * 40; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 0 << 1 * 40; QTest::newRow("column 1, scroll per pixel 1") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 1 * 40 << 0; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 1 * 40 << 0; QTest::newRow("column 5, scroll per pixel 0") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 0 << 5 * 40; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 0 << 5 * 40; QTest::newRow("column 5, scroll per pixel 5") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 0; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 0; QTest::newRow("column 9, scroll per pixel 0") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 0 << 9 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 0 << 9 * 40; QTest::newRow("column 9, scroll per pixel 5") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 4 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 4 * 40; } void tst_QTableView::columnViewportPosition() @@ -2516,7 +2459,7 @@ void tst_QTableView::columnViewportPosition() QFETCH(int, columnCount); QFETCH(int, columnWidth); QFETCH(int, column); - QFETCH(int, horizontalScrollMode); + QFETCH(QAbstractItemView::ScrollMode, horizontalScrollMode); QFETCH(int, horizontalScrollValue); QFETCH(int, columnViewportPosition); @@ -2530,7 +2473,7 @@ void tst_QTableView::columnViewportPosition() for (int c = 0; c < columnCount; ++c) view.setColumnWidth(c, columnWidth); - view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)horizontalScrollMode); + view.setHorizontalScrollMode(horizontalScrollMode); view.horizontalScrollBar()->setValue(horizontalScrollValue); #ifdef Q_OS_WINRT @@ -2730,8 +2673,8 @@ void tst_QTableView::sortingEnabled() void tst_QTableView::scrollTo_data() { - QTest::addColumn<int>("verticalScrollMode"); - QTest::addColumn<int>("horizontalScrollMode"); + QTest::addColumn<QAbstractItemView::ScrollMode>("verticalScrollMode"); + QTest::addColumn<QAbstractItemView::ScrollMode>("horizontalScrollMode"); QTest::addColumn<int>("rowCount"); QTest::addColumn<int>("columnCount"); QTest::addColumn<int>("rowHeight"); @@ -2744,51 +2687,51 @@ void tst_QTableView::scrollTo_data() QTest::addColumn<int>("columnSpan"); QTest::addColumn<int>("horizontalScroll"); QTest::addColumn<int>("verticalScroll"); - QTest::addColumn<int>("scrollHint"); + QTest::addColumn<QAbstractItemView::ScrollHint>("scrollHint"); QTest::addColumn<int>("expectedHorizontalScroll"); QTest::addColumn<int>("expectedVerticalScroll"); QTest::newRow("no hidden, no span, no scroll, per item") - << (int)QAbstractItemView::ScrollPerItem - << (int)QAbstractItemView::ScrollPerItem + << QAbstractItemView::ScrollPerItem + << QAbstractItemView::ScrollPerItem << 10 << 10 // table << 80 << 80 // size << -1 << -1 // hide << 0 << 0 // cell << 1 << 1 // span << 0 << 0 // scroll - << (int)QAbstractItemView::PositionAtTop + << QAbstractItemView::PositionAtTop << 0 << 0; // expected QTest::newRow("no hidden, no span, no scroll, per pixel") - << (int)QAbstractItemView::ScrollPerPixel - << (int)QAbstractItemView::ScrollPerPixel + << QAbstractItemView::ScrollPerPixel + << QAbstractItemView::ScrollPerPixel << 10 << 10 // table << 80 << 80 // size << -1 << -1 // hide << 0 << 0 // cell << 1 << 1 // span << 0 << 0 // scroll - << (int)QAbstractItemView::PositionAtTop + << QAbstractItemView::PositionAtTop << 0 << 0; // expected QTest::newRow("hidden, no span, no scroll, per item") - << (int)QAbstractItemView::ScrollPerItem - << (int)QAbstractItemView::ScrollPerItem + << QAbstractItemView::ScrollPerItem + << QAbstractItemView::ScrollPerItem << 10 << 10 // table << 80 << 80 // size << 3 << 3 // hide << 5 << 5 // cell << 1 << 1 // span << 0 << 0 // scroll - << (int)QAbstractItemView::PositionAtTop + << QAbstractItemView::PositionAtTop << 4 << 4; // expected } void tst_QTableView::scrollTo() { - QFETCH(int, horizontalScrollMode); - QFETCH(int, verticalScrollMode); + QFETCH(QAbstractItemView::ScrollMode, horizontalScrollMode); + QFETCH(QAbstractItemView::ScrollMode, verticalScrollMode); QFETCH(int, rowCount); QFETCH(int, columnCount); QFETCH(int, rowHeight); @@ -2801,7 +2744,7 @@ void tst_QTableView::scrollTo() QFETCH(int, columnSpan); QFETCH(int, horizontalScroll); QFETCH(int, verticalScroll); - QFETCH(int, scrollHint); + QFETCH(QAbstractItemView::ScrollHint, scrollHint); QFETCH(int, expectedHorizontalScroll); QFETCH(int, expectedVerticalScroll); @@ -2821,8 +2764,8 @@ void tst_QTableView::scrollTo() view.setSpan(row, column, rowSpan, columnSpan); view.hideRow(hiddenRow); view.hideColumn(hiddenColumn); - view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)horizontalScrollMode); - view.setVerticalScrollMode((QAbstractItemView::ScrollMode)verticalScrollMode); + view.setHorizontalScrollMode(horizontalScrollMode); + view.setVerticalScrollMode(verticalScrollMode); for (int r = 0; r < rowCount; ++r) view.setRowHeight(r, rowHeight); @@ -2834,7 +2777,7 @@ void tst_QTableView::scrollTo() QModelIndex index = model.index(row, column); QVERIFY(index.isValid()); - view.scrollTo(index, (QAbstractItemView::ScrollHint)scrollHint); + view.scrollTo(index, scrollHint); QTRY_COMPARE(view.verticalScrollBar()->value(), expectedVerticalScroll); QTRY_COMPARE(view.horizontalScrollBar()->value(), expectedHorizontalScroll); } @@ -3139,8 +3082,6 @@ void tst_QTableView::span() VERIFY_SPANS_CONSISTENCY(&view); } -typedef QVector<QRect> SpanList; - void tst_QTableView::spans_data() { QTest::addColumn<int>("rows"); @@ -3268,7 +3209,7 @@ void tst_QTableView::spans() { QFETCH(int, rows); QFETCH(int, columns); - QFETCH(SpanList, spans); + QFETCH(const SpanList, spans); QFETCH(bool, hideRowLastRowOfFirstSpan); QFETCH(QPoint, pos); QFETCH(int, expectedRowSpan); @@ -3280,10 +3221,8 @@ void tst_QTableView::spans() view.setModel(&model); view.show(); - for (int i = 0; i < spans.count(); ++i) { - QRect sp = spans.at(i); + for (const auto &sp : spans) view.setSpan(sp.x(), sp.y(), sp.width(), sp.height()); - } if (hideRowLastRowOfFirstSpan) { view.setRowHidden(spans.at(0).bottom(), true); @@ -3377,32 +3316,34 @@ void tst_QTableView::spansAfterRowRemoval() QtTestTableView view; view.setModel(&model); - QList<QRect> spans; - spans << QRect(0, 1, 1, 2) - << QRect(1, 2, 1, 2) - << QRect(2, 2, 1, 5) - << QRect(2, 8, 1, 2) - << QRect(3, 4, 1, 2) - << QRect(4, 4, 1, 4) - << QRect(5, 6, 1, 3) - << QRect(6, 7, 1, 3); - foreach (QRect span, spans) + static const QRect spans[] = { + {0, 1, 1, 2}, + {1, 2, 1, 2}, + {2, 2, 1, 5}, + {2, 8, 1, 2}, + {3, 4, 1, 2}, + {4, 4, 1, 4}, + {5, 6, 1, 3}, + {6, 7, 1, 3} + }; + for (const QRect &span : spans) view.setSpan(span.top(), span.left(), span.height(), span.width()); view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); view.model()->removeRows(3, 3); - QList<QRect> expectedSpans; - expectedSpans << QRect(0, 1, 1, 2) - << QRect(1, 2, 1, 1) - << QRect(2, 2, 1, 2) - << QRect(2, 5, 1, 2) - << QRect(3, 4, 1, 1) - << QRect(4, 3, 1, 2) - << QRect(5, 3, 1, 3) - << QRect(6, 4, 1, 3); - foreach (QRect span, expectedSpans) { + static const QRect expectedSpans[] = { + {0, 1, 1, 2}, + {1, 2, 1, 1}, + {2, 2, 1, 2}, + {2, 5, 1, 2}, + {3, 4, 1, 1}, + {4, 3, 1, 2}, + {5, 3, 1, 3}, + {6, 4, 1, 3} + }; + for (const QRect &span : expectedSpans) { QCOMPARE(view.columnSpan(span.top(), span.left()), span.width()); QCOMPARE(view.rowSpan(span.top(), span.left()), span.height()); } @@ -3417,32 +3358,34 @@ void tst_QTableView::spansAfterColumnRemoval() view.setModel(&model); // Same set as above just swapping columns and rows. - QList<QRect> spans; - spans << QRect(0, 1, 1, 2) - << QRect(1, 2, 1, 2) - << QRect(2, 2, 1, 5) - << QRect(2, 8, 1, 2) - << QRect(3, 4, 1, 2) - << QRect(4, 4, 1, 4) - << QRect(5, 6, 1, 3) - << QRect(6, 7, 1, 3); - foreach (QRect span, spans) - view.setSpan(span.left(), span.top(), span.width(), span.height()); + static const QRect spans[] = { + {0, 1, 1, 2}, + {1, 2, 1, 2}, + {2, 2, 1, 5}, + {2, 8, 1, 2}, + {3, 4, 1, 2}, + {4, 4, 1, 4}, + {5, 6, 1, 3}, + {6, 7, 1, 3} + }; + for (const QRect &span : spans) + view.setSpan(span.left(), span.top(), span.width(), span.height()); view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); view.model()->removeColumns(3, 3); - QList<QRect> expectedSpans; - expectedSpans << QRect(0, 1, 1, 2) - << QRect(1, 2, 1, 1) - << QRect(2, 2, 1, 2) - << QRect(2, 5, 1, 2) - << QRect(3, 4, 1, 1) - << QRect(4, 3, 1, 2) - << QRect(5, 3, 1, 3) - << QRect(6, 4, 1, 3); - foreach (QRect span, expectedSpans) { + static const QRect expectedSpans[] = { + {0, 1, 1, 2}, + {1, 2, 1, 1}, + {2, 2, 1, 2}, + {2, 5, 1, 2}, + {3, 4, 1, 1}, + {4, 3, 1, 2}, + {5, 3, 1, 3}, + {6, 4, 1, 3} + }; + for (const QRect &span : expectedSpans) { QCOMPARE(view.columnSpan(span.left(), span.top()), span.height()); QCOMPARE(view.rowSpan(span.left(), span.top()), span.width()); } @@ -3450,12 +3393,10 @@ void tst_QTableView::spansAfterColumnRemoval() VERIFY_SPANS_CONSISTENCY(&view); } -Q_DECLARE_METATYPE(Qt::Key) - void tst_QTableView::editSpanFromDirections_data() { - QTest::addColumn<QList<Qt::Key> >("keyPresses"); - QTest::addColumn<QSharedPointer<QStandardItemModel> >("model"); + QTest::addColumn<KeyList>("keyPresses"); + QTest::addColumn<QSharedPointer<QStandardItemModel>>("model"); QTest::addColumn<int>("row"); QTest::addColumn<int>("column"); QTest::addColumn<int>("rowSpan"); @@ -3474,8 +3415,7 @@ void tst_QTableView::editSpanFromDirections_data() +---+---+ | | ^ | +---+---+ */ - QList<Qt::Key> keyPresses; - keyPresses << Qt::Key_Right << Qt::Key_PageDown << Qt::Key_Up; + KeyList keyPresses {Qt::Key_Right, Qt::Key_PageDown, Qt::Key_Up}; QSharedPointer<QStandardItemModel> model(new QStandardItemModel(4, 2)); QTest::newRow("row span, bottom up") << keyPresses << model << 1 << 1 << 2 << 1 << model->index(2, 1) << model->index(1, 1); @@ -3489,8 +3429,7 @@ void tst_QTableView::editSpanFromDirections_data() +---+---+ | | | +---+---+ */ - keyPresses.clear(); - keyPresses << Qt::Key_Right << Qt::Key_Down; + keyPresses = {Qt::Key_Right, Qt::Key_Down}; model = QSharedPointer<QStandardItemModel>::create(4, 2); QTest::newRow("row span, top down") << keyPresses << model << 1 << 1 << 2 << 1 << model->index(1, 1) << model->index(1, 1); @@ -3502,8 +3441,7 @@ void tst_QTableView::editSpanFromDirections_data() +---+ +---+ | | | | +---+---+---+ */ - keyPresses.clear(); - keyPresses << Qt::Key_End << Qt::Key_Down << Qt::Key_Left; + keyPresses = {Qt::Key_End, Qt::Key_Down, Qt::Key_Left}; model = QSharedPointer<QStandardItemModel>::create(3, 3); QTest::newRow("row span, right to left") << keyPresses << model << 1 << 1 << 2 << 1 << model->index(1, 1) << model->index(1, 1); @@ -3515,8 +3453,7 @@ void tst_QTableView::editSpanFromDirections_data() +---+ +---+ | > | c | | +---+---+---+ */ - keyPresses.clear(); - keyPresses << Qt::Key_PageDown << Qt::Key_Right; + keyPresses = {Qt::Key_PageDown, Qt::Key_Right}; model = QSharedPointer<QStandardItemModel>::create(3, 3); QTest::newRow("row span, left to right") << keyPresses << model << 1 << 1 << 2 << 1 << model->index(2, 1) << model->index(1, 1); @@ -3528,8 +3465,7 @@ void tst_QTableView::editSpanFromDirections_data() +---+---+---+ | ^ | | | +---+---+---+ */ - keyPresses.clear(); - keyPresses << Qt::Key_PageDown << Qt::Key_Up; + keyPresses = {Qt::Key_PageDown, Qt::Key_Up}; model = QSharedPointer<QStandardItemModel>::create(3, 3); QTest::newRow("col span, bottom up") << keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 0) << model->index(1, 0); @@ -3541,8 +3477,7 @@ void tst_QTableView::editSpanFromDirections_data() +---+---+---+ | | ^ | | +---+---+---+ */ - keyPresses.clear(); - keyPresses << Qt::Key_PageDown << Qt::Key_Right << Qt::Key_Up; + keyPresses = {Qt::Key_PageDown, Qt::Key_Right, Qt::Key_Up}; model = QSharedPointer<QStandardItemModel>::create(3, 3); QTest::newRow("col span, bottom up #2") << keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 1) << model->index(1, 0); @@ -3554,8 +3489,7 @@ void tst_QTableView::editSpanFromDirections_data() +---+---+---+ | | | | +---+---+---+ */ - keyPresses.clear(); - keyPresses << Qt::Key_End << Qt::Key_Down; + keyPresses = {Qt::Key_End, Qt::Key_Down}; model = QSharedPointer<QStandardItemModel>::create(3, 3); QTest::newRow("col span, top down") << keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 2) << model->index(1, 0); @@ -3564,12 +3498,10 @@ void tst_QTableView::editSpanFromDirections_data() class TableViewWithCursorExposed : public QTableView { public: - TableViewWithCursorExposed() : - QTableView() { - } + using QTableView::QTableView; -public: - QModelIndex visualCursorIndex() { + QModelIndex visualCursorIndex() + { QTableViewPrivate *d = static_cast<QTableViewPrivate*>(qt_widget_private(this)); return d->model->index(d->visualCursor.y(), d->visualCursor.x()); } @@ -3577,7 +3509,7 @@ public: void tst_QTableView::editSpanFromDirections() { - QFETCH(QList<Qt::Key>, keyPresses); + QFETCH(const KeyList, keyPresses); QFETCH(QSharedPointer<QStandardItemModel>, model); QFETCH(int, row); QFETCH(int, column); @@ -3595,9 +3527,8 @@ void tst_QTableView::editSpanFromDirections() view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); - foreach (Qt::Key key, keyPresses) { + for (Qt::Key key : keyPresses) QTest::keyClick(&view, key); - } QCOMPARE(view.visualCursorIndex(), expectedVisualCursorIndex); QCOMPARE(view.selectionModel()->currentIndex(), expectedEditedIndex); @@ -3606,21 +3537,21 @@ void tst_QTableView::editSpanFromDirections() QTRY_COMPARE(view.model()->data(expectedEditedIndex).toString(), QLatin1String("x")); } -class Model : public QAbstractTableModel { - -Q_OBJECT - +class Model : public QAbstractTableModel +{ + Q_OBJECT public: - Model(QObject * parent = 0) : QAbstractTableModel(parent) { - } + using QAbstractTableModel::QAbstractTableModel; - int rowCount(const QModelIndex &) const { + int rowCount(const QModelIndex &) const override + { return rows; } - int columnCount(const QModelIndex &) const { + int columnCount(const QModelIndex &) const override + { return columns; } - QVariant data(const QModelIndex &, int) const + QVariant data(const QModelIndex &, int) const override { return QVariant(); } @@ -3630,8 +3561,8 @@ public: endResetModel(); } - int rows; - int columns; + int rows = 0; + int columns = 0; }; void tst_QTableView::checkHeaderReset() @@ -3655,7 +3586,7 @@ void tst_QTableView::checkHeaderMinSize() //viewport. QTableView view; QStringListModel m; - m.setStringList( QStringList() << QLatin1String("one cell is enough")); + m.setStringList({QLatin1String("one cell is enough")}); view.setModel(&m); //setting the minimum height on the horizontal header @@ -3686,31 +3617,29 @@ void tst_QTableView::resizeToContents() table2.verticalHeader()->setVisible(false); - for(int i = 0;i<table.columnCount();i++) { + for (int i = 0; i < table.columnCount(); i++) table.resizeColumnToContents(i); - } - for(int i = 0;i<table.rowCount();i++) { + for (int i = 0; i < table.rowCount(); i++) table.resizeRowToContents(i); - } table2.resizeColumnsToContents(); table2.resizeRowsToContents(); table3.resizeColumnsToContents(); table3.resizeRowsToContents(); //now let's check the row/col sizes - for(int i = 0;i<table.columnCount();i++) { - QCOMPARE( table.columnWidth(i), table2.columnWidth(i)); - QCOMPARE( table2.columnWidth(i), table3.columnWidth(i)); + for (int i = 0; i < table.columnCount(); i++) { + QCOMPARE(table.columnWidth(i), table2.columnWidth(i)); + QCOMPARE(table2.columnWidth(i), table3.columnWidth(i)); } - for(int i = 0;i<table.rowCount();i++) { - QCOMPARE( table.rowHeight(i), table2.rowHeight(i)); - QCOMPARE( table2.rowHeight(i), table3.rowHeight(i)); + for (int i = 0; i < table.rowCount(); i++) { + QCOMPARE(table.rowHeight(i), table2.rowHeight(i)); + QCOMPARE(table2.rowHeight(i), table3.rowHeight(i)); } } QT_BEGIN_NAMESPACE -extern bool Q_GUI_EXPORT qt_tab_all_widgets(); // qapplication.cpp +extern bool Q_WIDGETS_EXPORT qt_tab_all_widgets(); // qapplication.cpp QT_END_NAMESPACE void tst_QTableView::tabFocus() @@ -3740,57 +3669,57 @@ void tst_QTableView::tabFocus() for (int i = 0; i < 2; ++i) { // tab to view - QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); QTRY_VERIFY(!window.hasFocus()); QVERIFY(view->hasFocus()); QVERIFY(!edit->hasFocus()); // tab to edit - QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); QTRY_VERIFY(edit->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!view->hasFocus()); } // backtab to view - QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); QTRY_VERIFY(view->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!edit->hasFocus()); // backtab to edit - QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); QTRY_VERIFY(edit->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!view->hasFocus()); - QStandardItemModel *model = new QStandardItemModel; - view->setModel(model); + QStandardItemModel model; + view->setModel(&model); // backtab to view - QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); QTRY_VERIFY(view->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!edit->hasFocus()); // backtab to edit - QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); QTRY_VERIFY(edit->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!view->hasFocus()); - model->insertRow(0, new QStandardItem("Hei")); - model->insertRow(0, new QStandardItem("Hei")); - model->insertRow(0, new QStandardItem("Hei")); + model.insertRow(0, new QStandardItem("Hei")); + model.insertRow(0, new QStandardItem("Hei")); + model.insertRow(0, new QStandardItem("Hei")); // backtab to view - QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); QTRY_VERIFY(view->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!edit->hasFocus()); // backtab to edit doesn't work - QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); QVERIFY(!window.hasFocus()); QVERIFY(view->hasFocus()); QVERIFY(!edit->hasFocus()); @@ -3798,41 +3727,38 @@ void tst_QTableView::tabFocus() view->setTabKeyNavigation(false); // backtab to edit - QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); QTRY_VERIFY(edit->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!view->hasFocus()); - QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); QTRY_VERIFY(view->hasFocus()); - QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); QTRY_VERIFY(edit->hasFocus()); - - delete model; } class BigModel : public QAbstractTableModel { Q_OBJECT public: - virtual QVariant data(const QModelIndex &index, - int role = Qt::DisplayRole) const + QVariant data(const QModelIndex &index, + int role = Qt::DisplayRole) const override { if (role == Qt::DisplayRole) return QString::number(index.column()) + QLatin1String(" - ") + QString::number(index.row()); return QVariant(); } - - int rowCount(const QModelIndex & parent = QModelIndex()) const + int rowCount(const QModelIndex &parent = QModelIndex()) const override { - Q_UNUSED(parent); + Q_UNUSED(parent) return 10000000; } - int columnCount(const QModelIndex & parent = QModelIndex()) const + int columnCount(const QModelIndex &parent = QModelIndex()) const override { - Q_UNUSED(parent); + Q_UNUSED(parent) return 20000000; } }; @@ -3861,7 +3787,7 @@ void tst_QTableView::selectionSignal() view.resize(200, 200); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(2, 0)).center()); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(model.index(2, 0)).center()); } void tst_QTableView::setCurrentIndex() @@ -3887,14 +3813,14 @@ void tst_QTableView::setCurrentIndex() class task173773_EventFilter : public QObject { - int paintEventCount_; + int paintEventCount_ = 0; public: - task173773_EventFilter() : paintEventCount_(0) {} + using QObject::QObject; int paintEventCount() const { return paintEventCount_; } private: - bool eventFilter(QObject *obj, QEvent *e) + bool eventFilter(QObject *obj, QEvent *e) override { - Q_UNUSED(obj); + Q_UNUSED(obj) if (e->type() == QEvent::Paint) ++paintEventCount_; return false; @@ -4023,25 +3949,25 @@ void tst_QTableView::task248688_autoScrollNavigation() #if QT_CONFIG(wheelevent) void tst_QTableView::mouseWheel_data() { - QTest::addColumn<int>("scrollMode"); + QTest::addColumn<QAbstractItemView::ScrollMode>("scrollMode"); QTest::addColumn<int>("delta"); QTest::addColumn<int>("horizontalPositon"); QTest::addColumn<int>("verticalPosition"); QTest::newRow("scroll up per item") - << int(QAbstractItemView::ScrollPerItem) << 120 - << 10 - qApp->wheelScrollLines() << 10 - qApp->wheelScrollLines(); + << QAbstractItemView::ScrollPerItem << 120 + << 10 - QApplication::wheelScrollLines() << 10 - QApplication::wheelScrollLines(); QTest::newRow("scroll down per item") - << int(QAbstractItemView::ScrollPerItem) << -120 - << 10 + qApp->wheelScrollLines() << 10 + qApp->wheelScrollLines(); + << QAbstractItemView::ScrollPerItem << -120 + << 10 + QApplication::wheelScrollLines() << 10 + QApplication::wheelScrollLines(); QTest::newRow("scroll down per pixel") - << int(QAbstractItemView::ScrollPerPixel) << -120 - << 10 + qApp->wheelScrollLines() * 91 << 10 + qApp->wheelScrollLines() * 46; + << QAbstractItemView::ScrollPerPixel << -120 + << 10 + QApplication::wheelScrollLines() * 91 << 10 + QApplication::wheelScrollLines() * 46; } void tst_QTableView::mouseWheel() { - QFETCH(int, scrollMode); + QFETCH(QAbstractItemView::ScrollMode, scrollMode); QFETCH(int, delta); QFETCH(int, horizontalPositon); QFETCH(int, verticalPosition); @@ -4061,14 +3987,16 @@ void tst_QTableView::mouseWheel() for (int c = 0; c < 100; ++c) view.setColumnWidth(c, 100); - view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)scrollMode); - view.setVerticalScrollMode((QAbstractItemView::ScrollMode)scrollMode); + view.setHorizontalScrollMode(scrollMode); + view.setVerticalScrollMode(scrollMode); view.horizontalScrollBar()->setValue(10); view.verticalScrollBar()->setValue(10); QPoint pos = view.viewport()->geometry().center(); - QWheelEvent verticalEvent(pos, delta, 0, 0, Qt::Vertical); - QWheelEvent horizontalEvent(pos, delta, 0, 0, Qt::Horizontal); + QWheelEvent verticalEvent(pos, view.mapToGlobal(pos), QPoint(), QPoint(0, delta), + Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); + QWheelEvent horizontalEvent(pos, view.mapToGlobal(pos), QPoint(), QPoint(delta, 0), + Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); QApplication::sendEvent(view.viewport(), &horizontalEvent); QVERIFY(qAbs(view.horizontalScrollBar()->value() - horizontalPositon) < 15); QApplication::sendEvent(view.viewport(), &verticalEvent); @@ -4159,15 +4087,15 @@ void tst_QTableView::task191545_dragSelectRows() QWidget *vHeaderVp = vHeader->viewport(); QPoint rowPos(cellRect.center()); QMouseEvent rowPressEvent(QEvent::MouseButtonPress, rowPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(vHeaderVp, &rowPressEvent); + QCoreApplication::sendEvent(vHeaderVp, &rowPressEvent); for (int i = 0; i < 4; ++i) { rowPos.setY(rowPos.y() + cellRect.height()); QMouseEvent moveEvent(QEvent::MouseMove, rowPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); - qApp->sendEvent(vHeaderVp, &moveEvent); + QCoreApplication::sendEvent(vHeaderVp, &moveEvent); } QMouseEvent rowReleaseEvent(QEvent::MouseButtonRelease, rowPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(vHeaderVp, &rowReleaseEvent); + QCoreApplication::sendEvent(vHeaderVp, &rowReleaseEvent); for (int i = 0; i < 4; ++i) { QModelIndex index = model.index(3 + i, 0, table.rootIndex()); @@ -4181,15 +4109,15 @@ void tst_QTableView::task191545_dragSelectRows() QWidget *hHeaderVp = hHeader->viewport(); QPoint colPos((cellRect.left() + cellRect.right()) / 2, 5); QMouseEvent colPressEvent(QEvent::MouseButtonPress, colPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(hHeaderVp, &colPressEvent); + QCoreApplication::sendEvent(hHeaderVp, &colPressEvent); for (int i = 0; i < 4; ++i) { colPos.setX(colPos.x() + cellRect.width()); QMouseEvent moveEvent(QEvent::MouseMove, colPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); - qApp->sendEvent(hHeaderVp, &moveEvent); + QCoreApplication::sendEvent(hHeaderVp, &moveEvent); } QMouseEvent colReleaseEvent(QEvent::MouseButtonRelease, colPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(hHeaderVp, &colReleaseEvent); + QCoreApplication::sendEvent(hHeaderVp, &colReleaseEvent); for (int i = 0; i < 4; ++i) { QModelIndex index = model.index(0, 3 + i, table.rootIndex()); @@ -4202,22 +4130,23 @@ void tst_QTableView::task191545_dragSelectRows() QWidget *tableVp = table.viewport(); QPoint cellPos = cellRect.center(); QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(tableVp, &cellPressEvent); + QCoreApplication::sendEvent(tableVp, &cellPressEvent); for (int i = 0; i < 6; ++i) { cellPos.setX(cellPos.x() + cellRect.width()); cellPos.setY(cellPos.y() + cellRect.height()); QMouseEvent moveEvent(QEvent::MouseMove, cellPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); - qApp->sendEvent(tableVp, &moveEvent); + QCoreApplication::sendEvent(tableVp, &moveEvent); } QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(tableVp, &cellReleaseEvent); + QCoreApplication::sendEvent(tableVp, &cellReleaseEvent); - for (int i = 0; i < 6; ++i) + for (int i = 0; i < 6; ++i) { for (int j = 0; j < 6; ++j) { QModelIndex index = model.index(2 + i, 2 + j, table.rootIndex()); QVERIFY(table.selectionModel()->isSelected(index)); } + } } { @@ -4225,23 +4154,24 @@ void tst_QTableView::task191545_dragSelectRows() QWidget *tableVp = table.viewport(); QPoint cellPos = cellRect.center(); QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(tableVp, &cellPressEvent); + QCoreApplication::sendEvent(tableVp, &cellPressEvent); for (int i = 0; i < 6; ++i) { cellPos.setX(cellPos.x() + cellRect.width()); cellPos.setY(cellPos.y() + cellRect.height()); QMouseEvent moveEvent(QEvent::MouseMove, cellPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); - qApp->sendEvent(tableVp, &moveEvent); + QCoreApplication::sendEvent(tableVp, &moveEvent); } QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(tableVp, &cellReleaseEvent); + QCoreApplication::sendEvent(tableVp, &cellReleaseEvent); QTest::qWait(200); - for (int i = 0; i < 6; ++i) + for (int i = 0; i < 6; ++i) { for (int j = 0; j < 6; ++j) { QModelIndex index = model.index(3 + i, 3 + j, table.rootIndex()); QVERIFY(!table.selectionModel()->isSelected(index)); } + } } } @@ -4319,8 +4249,6 @@ void tst_QTableView::taskQTBUG_4516_clickOnRichTextLabel() QTest::mouseClick(&label, Qt::LeftButton); QCOMPARE(view.currentIndex(), model.index(1,1)); - - } @@ -4353,21 +4281,23 @@ void tst_QTableView::taskQTBUG_5237_wheelEventOnHeader() int sbValueBefore = view.verticalScrollBar()->value(); QHeaderView *header = view.verticalHeader(); QTest::mouseMove(header); - QWheelEvent wheelEvent(header->geometry().center(), -720, 0, 0); + QPoint pos = header->geometry().center(); + QWheelEvent wheelEvent(pos, header->viewport()->mapToGlobal(pos), QPoint(), QPoint(0, -720), + Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); QApplication::sendEvent(header->viewport(), &wheelEvent); int sbValueAfter = view.verticalScrollBar()->value(); QVERIFY(sbValueBefore != sbValueAfter); } #endif -class TestTableView : public QTableView { -Q_OBJECT +class TestTableView : public QTableView +{ + Q_OBJECT public: - TestTableView(QWidget *parent = 0) : QTableView(parent) + TestTableView(QWidget *parent = nullptr) : QTableView(parent) { - connect(this, SIGNAL(entered(QModelIndex)), this, SLOT(openEditor(QModelIndex))); + connect(this, &QTableView::entered, this, &TestTableView::openPersistentEditor); } - ~TestTableView(){} public slots: void onDataChanged() { @@ -4375,9 +4305,6 @@ public slots: setRowHidden(i, model()->data(model()->index(i, 0)).toBool()); } } - - void openEditor(const QModelIndex& index) - { openPersistentEditor(index); } }; @@ -4385,15 +4312,13 @@ void tst_QTableView::taskQTBUG_8585_crashForNoGoodReason() { QStandardItemModel model; model.insertColumn(0, QModelIndex()); - for(int i = 0; i < 20; i++) - { + for (int i = 0; i < 20; i++) model.insertRow(i); - } TestTableView w; w.setMouseTracking(true); w.setModel(&model); - connect(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), &w, SLOT(onDataChanged())); + connect(&model, &QStandardItemModel::dataChanged, &w, &TestTableView::onDataChanged); w.show(); QVERIFY(QTest::qWaitForWindowExposed(&w)); for (int i = 0; i < 10; i++) @@ -4407,10 +4332,7 @@ void tst_QTableView::taskQTBUG_8585_crashForNoGoodReason() class TableView7774 : public QTableView { public: - QRegion visualRegionForSelection(const QItemSelection &selection) const - { - return QTableView::visualRegionForSelection(selection); - } + using QTableView::visualRegionForSelection; }; void tst_QTableView::taskQTBUG_7774_RtoLVisualRegionForSelection() @@ -4570,5 +4492,33 @@ void tst_QTableView::taskQTBUG_50171_selectRowAfterSwapColumns() } } +// This has nothing to do with QTableView, but it's convenient to reuse the QtTestTableModel +#if QT_CONFIG(textmarkdownwriter) + +// #define DEBUG_WRITE_OUTPUT + +void tst_QTableView::markdownWriter() +{ + QtTestTableModel model(2, 3); + QString md; + { + QTextStream stream(&md); + QTextMarkdownWriter writer(stream, QTextDocument::MarkdownDialectGitHub); + writer.writeTable(&model); + } + +#ifdef DEBUG_WRITE_OUTPUT + { + QFile out("/tmp/table.md"); + out.open(QFile::WriteOnly); + out.write(md.toUtf8()); + out.close(); + } +#endif + + QCOMPARE(md, QString::fromLatin1("|1 |2 |3 |\n|-------|-------|-------|\n|[0,0,0]|[0,1,0]|[0,2,0]|\n|[1,0,0]|[1,1,0]|[1,2,0]|\n")); +} +#endif + QTEST_MAIN(tst_QTableView) #include "tst_qtableview.moc" diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp index c2de5c2761..f640996690 100644 --- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp +++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp @@ -26,15 +26,12 @@ ** ****************************************************************************/ - -#include <QtTest/QtTest> -#include <qeventloop.h> -#include <qlist.h> -#include <qpair.h> -#include <qheaderview.h> -#include <qlineedit.h> - -#include <qtablewidget.h> +#include <QHeaderView> +#include <QLineEdit> +#include <QMimeData> +#include <QSignalSpy> +#include <QTableWidget> +#include <QTest> class QObjectTableItem : public QObject, public QTableWidgetItem { @@ -46,11 +43,10 @@ class tst_QTableWidget : public QObject Q_OBJECT public: - tst_QTableWidget(); + using QObject::QObject; private slots: void initTestCase(); - void cleanupTestCase(); void init(); void getSetCheck(); void clear(); @@ -97,12 +93,12 @@ private slots: #endif private: - QTableWidget *testWidget; + std::unique_ptr<QTableWidget> testWidget; }; -typedef QPair<int, int> IntPair; -typedef QList<int> IntList; -typedef QList<IntPair> IntIntList; +using IntPair = QPair<int, int>; +using IntList = QVector<int>; +using IntIntList = QVector<IntPair>; Q_DECLARE_METATYPE(QTableWidgetSelectionRange) @@ -143,45 +139,36 @@ void tst_QTableWidget::getSetCheck() obj1.setItem(3, 3, new QTableWidgetItem("3,3")); obj1.setCurrentItem(var3); QCOMPARE(var3, obj1.currentItem()); - obj1.setCurrentItem((QTableWidgetItem *)0); - QCOMPARE((QTableWidgetItem *)0, obj1.currentItem()); - obj1.setItem(0, 0, 0); - QCOMPARE((QTableWidgetItem *)0, obj1.item(0, 0)); + obj1.setCurrentItem(nullptr); + QCOMPARE(obj1.currentItem(), nullptr); + obj1.setItem(0, 0, nullptr); + QCOMPARE(obj1.item(0, 0), nullptr); // const QTableWidgetItem * QTableWidget::itemPrototype() // void QTableWidget::setItemPrototype(const QTableWidgetItem *) const QTableWidgetItem *var4 = new QTableWidgetItem; obj1.setItemPrototype(var4); QCOMPARE(var4, obj1.itemPrototype()); - obj1.setItemPrototype((QTableWidgetItem *)0); - QCOMPARE((const QTableWidgetItem *)0, obj1.itemPrototype()); -} - -tst_QTableWidget::tst_QTableWidget(): testWidget(0) -{ + obj1.setItemPrototype(nullptr); + QCOMPARE(obj1.itemPrototype(), nullptr); } void tst_QTableWidget::initTestCase() { - testWidget = new QTableWidget(); + testWidget.reset(new QTableWidget); testWidget->show(); QApplication::setKeyboardInputInterval(100); } -void tst_QTableWidget::cleanupTestCase() -{ - delete testWidget; -} - void tst_QTableWidget::init() { testWidget->clear(); testWidget->setRowCount(5); testWidget->setColumnCount(5); - for (int row=0; row < testWidget->rowCount(); ++row) + for (int row = 0; row < testWidget->rowCount(); ++row) testWidget->showRow(row); - for (int column=0; column < testWidget->columnCount(); ++column) + for (int column = 0; column < testWidget->columnCount(); ++column) testWidget->showColumn(column); } @@ -319,13 +306,15 @@ void tst_QTableWidget::item() QCOMPARE(testWidget->rowCount(), rowCount); QCOMPARE(testWidget->columnCount(), columnCount); - for (int r = 0; r < testWidget->rowCount(); ++r) + for (int r = 0; r < testWidget->rowCount(); ++r) { for (int c = 0; c < testWidget->columnCount(); ++c) testWidget->setItem(r, c, new QTableWidgetItem(QString::number(r * c + c))); + } - for (int r = 0; r < testWidget->rowCount(); ++r) + for (int r = 0; r < testWidget->rowCount(); ++r) { for (int c = 0; c < testWidget->columnCount(); ++c) QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c)); + } QTableWidgetItem *item = testWidget->item(row, column); QCOMPARE(!!item, expectItem); @@ -361,15 +350,17 @@ void tst_QTableWidget::takeItem() QCOMPARE(testWidget->rowCount(), rowCount); QCOMPARE(testWidget->columnCount(), columnCount); - for (int r = 0; r < testWidget->rowCount(); ++r) + for (int r = 0; r < testWidget->rowCount(); ++r) { for (int c = 0; c < testWidget->columnCount(); ++c) testWidget->setItem(r, c, new QTableWidgetItem(QString::number(r * c + c))); + } - for (int r = 0; r < testWidget->rowCount(); ++r) + for (int r = 0; r < testWidget->rowCount(); ++r) { for (int c = 0; c < testWidget->columnCount(); ++c) QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c)); + } - QSignalSpy spy(testWidget, &QTableWidget::cellChanged); + QSignalSpy spy(testWidget.get(), &QTableWidget::cellChanged); QTableWidgetItem *item = testWidget->takeItem(row, column); QCOMPARE(!!item, expectItem); if (expectItem) { @@ -516,11 +507,11 @@ void tst_QTableWidget::selectedItems() { QFETCH(int, rowCount); QFETCH(int, columnCount); - QFETCH(IntIntList, createItems); - QFETCH(IntList, hiddenRows); - QFETCH(IntList, hiddenColumns); - QFETCH(QTableWidgetSelectionRange, selectionRange); - QFETCH(IntIntList, expectedItems); + QFETCH(const IntIntList, createItems); + QFETCH(const IntList, hiddenRows); + QFETCH(const IntList, hiddenColumns); + QFETCH(const QTableWidgetSelectionRange, selectionRange); + QFETCH(const IntIntList, expectedItems); // set dimensions and test they are ok testWidget->setRowCount(rowCount); @@ -529,15 +520,15 @@ void tst_QTableWidget::selectedItems() QCOMPARE(testWidget->columnCount(), columnCount); // create and set items - foreach (IntPair intPair, createItems) { + for (const auto &intPair : createItems) { testWidget->setItem(intPair.first, intPair.second, new QTableWidgetItem(QString("Item %1 %2") .arg(intPair.first).arg(intPair.second))); } // hide rows/columns - foreach (int row, hiddenRows) + for (int row : hiddenRows) testWidget->setRowHidden(row, true); - foreach (int column, hiddenColumns) + for (int column : hiddenColumns) testWidget->setColumnHidden(column, true); // make sure we don't have any previous selections hanging around @@ -557,31 +548,18 @@ void tst_QTableWidget::selectedItems() } // check that the correct number of items and the expected items are there - QList<QTableWidgetItem *> selectedItems = testWidget->selectedItems(); + const QList<QTableWidgetItem *> selectedItems = testWidget->selectedItems(); QCOMPARE(selectedItems.count(), expectedItems.count()); - foreach (IntPair intPair, expectedItems) + for (const auto &intPair : expectedItems) QVERIFY(selectedItems.contains(testWidget->item(intPair.first, intPair.second))); // check that setItemSelected agrees with selectedItems - for (int row = 0; row<testWidget->rowCount(); ++row) { - bool hidden = false; - foreach (int hiddenRow, hiddenRows){ - if(hiddenRow == row){ - hidden = true; - break; - } - } - if (hidden) + for (int row = 0; row < testWidget->rowCount(); ++row) { + if (hiddenRows.contains(row)) continue; - for (int column = 0; column<testWidget->columnCount(); ++column) { - foreach (int hiddenColumn, hiddenColumns){ - if(hiddenColumn == column){ - hidden = true; - break; - } - } - if (hidden) + for (int column = 0; column < testWidget->columnCount(); ++column) { + if (hiddenColumns.contains(column)) continue; QTableWidgetItem *item = testWidget->item(row, column); @@ -621,11 +599,13 @@ void tst_QTableWidget::removeRow() QCOMPARE(testWidget->columnCount(), columnCount); // fill table with items - for (int r = 0; r < rowCount; ++r) - for (int c = 0; c < columnCount; ++c) + for (int r = 0; r < rowCount; ++r) { + const QString rRow = QString::number(r) + QLatin1Char(':'); + for (int c = 0; c < columnCount; ++c) { testWidget->setItem(r, c, - new QTableWidgetItem( - QString::number(r) + ":" + QString::number(c))); + new QTableWidgetItem(rRow + QString::number(c))); + } + } // remove and compare the results testWidget->removeRow(row); @@ -633,14 +613,18 @@ void tst_QTableWidget::removeRow() QCOMPARE(testWidget->columnCount(), expectedColumnCount); // check if the correct items were removed - for (int r = 0; r < expectedRowCount; ++r) - for (int c = 0; c < expectedColumnCount; ++c) + for (int r = 0; r < expectedRowCount; ++r) { + const QString rRow = QString::number(r < row ? r : r + 1) + + QLatin1Char(':'); + for (int c = 0; c < expectedColumnCount; ++c) { if (r < row) QCOMPARE(testWidget->item(r, c)->text(), - QString::number(r) + ":" + QString::number(c)); + rRow + QString::number(c)); else QCOMPARE(testWidget->item(r, c)->text(), - QString::number(r + 1) + ":" + QString::number(c)); + rRow + QString::number(c)); + } + } } void tst_QTableWidget::removeColumn_data() @@ -673,11 +657,14 @@ void tst_QTableWidget::removeColumn() QCOMPARE(testWidget->columnCount(), columnCount); // fill table with items - for (int r = 0; r < rowCount; ++r) - for (int c = 0; c < columnCount; ++c) + for (int r = 0; r < rowCount; ++r) { + const QString rStr = QString::number(r) + QLatin1Char(':'); + for (int c = 0; c < columnCount; ++c) { testWidget->setItem(r, c, new QTableWidgetItem( - QString::number(r) + ":" + QString::number(c))); + rStr + QString::number(c))); + } + } // remove and compare the results testWidget->removeColumn(column); @@ -686,14 +673,17 @@ void tst_QTableWidget::removeColumn() // check if the correct items were removed - for (int r = 0; r < expectedRowCount; ++r) - for (int c = 0; c < expectedColumnCount; ++c) + for (int r = 0; r < expectedRowCount; ++r) { + const QString rStr = QString::number(r) + QLatin1Char(':'); + for (int c = 0; c < expectedColumnCount; ++c) { if (c < column) QCOMPARE(testWidget->item(r, c)->text(), - QString::number(r) + ":" + QString::number(c)); + rStr + QString::number(c)); else QCOMPARE(testWidget->item(r, c)->text(), - QString::number(r) + ":" + QString::number(c + 1)); + rStr + QString::number(c + 1)); + } + } } void tst_QTableWidget::insertRow_data() @@ -819,7 +809,7 @@ void tst_QTableWidget::itemOwnership() item = new QObjectTableItem(); testWidget->setItem(0, 0, item); delete item; - QCOMPARE(testWidget->item(0, 0), (QTableWidgetItem *)0); + QCOMPARE(testWidget->item(0, 0), nullptr); //delete vertical headeritem from outside headerItem = new QObjectTableItem(); @@ -887,7 +877,7 @@ void tst_QTableWidget::sortItems_data() { QTest::addColumn<int>("rowCount"); QTest::addColumn<int>("columnCount"); - QTest::addColumn<int>("sortOrder"); + QTest::addColumn<Qt::SortOrder>("sortOrder"); QTest::addColumn<int>("sortColumn"); QTest::addColumn<QStringList>("initial"); QTest::addColumn<QStringList>("expected"); @@ -897,7 +887,7 @@ void tst_QTableWidget::sortItems_data() QTest::newRow("ascending") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() << "0" << "a" << "o" << "8" << "k" @@ -915,7 +905,7 @@ void tst_QTableWidget::sortItems_data() QTest::newRow("descending") << 4 << 5 - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << 0 << (QStringList() << "0" << "a" << "o" << "8" << "k" @@ -933,154 +923,151 @@ void tst_QTableWidget::sortItems_data() QTest::newRow("empty table") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() - << 0 << 0 << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0) + << QString() << QString() << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString()) << (QStringList() - << 0 << 0 << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0) + << QString() << QString() << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString()) << IntList() << IntList() << IntList(); - QTest::newRow("half-empty table") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() - << "0" << 0 << 0 << 0 << 0 - << "3" << "d" << 0 << 0 << 0 - << "2" << "c" << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0) + << "0" << QString() << QString() << QString() << QString() + << "3" << "d" << QString() << QString() << QString() + << "2" << "c" << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString()) << (QStringList() - << "0" << 0 << 0 << 0 << 0 - << "2" << "c" << 0 << 0 << 0 - << "3" << "d" << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0) + << "0" << QString() << QString() << QString() << QString() + << "2" << "c" << QString() << QString() << QString() + << "3" << "d" << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString()) << (IntList() << 0 << 2 << 1) << IntList() << IntList(); QTest::newRow("empty column, should not sort.") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 3 << (QStringList() - << "0" << 0 << 0 << 0 << 0 - << "3" << "d" << 0 << 0 << 0 - << "2" << "c" << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0) + << "0" << QString() << QString() << QString() << QString() + << "3" << "d" << QString() << QString() << QString() + << "2" << "c" << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString()) << (QStringList() - << "0" << 0 << 0 << 0 << 0 - << "3" << "d" << 0 << 0 << 0 - << "2" << "c" << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0) + << "0" << QString() << QString() << QString() << QString() + << "3" << "d" << QString() << QString() << QString() + << "2" << "c" << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString()) << IntList() << IntList() << IntList(); QTest::newRow("descending with null cell, the null cell should be placed at the bottom") << 4 << 5 - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << 0 << (QStringList() - << "0" << "a" << "o" << "8" << "k" - << "3" << "d" << "k" << "o" << "6" - << "2" << "c" << "9" << "y" << "8" - << 0 << "b" << "7" << "3" << "u") + << "0" << "a" << "o" << "8" << "k" + << "3" << "d" << "k" << "o" << "6" + << "2" << "c" << "9" << "y" << "8" + << QString() << "b" << "7" << "3" << "u") << (QStringList() - << "3" << "d" << "k" << "o" << "6" - << "2" << "c" << "9" << "y" << "8" - << "0" << "a" << "o" << "8" << "k" - << 0 << "b" << "7" << "3" << "u") + << "3" << "d" << "k" << "o" << "6" + << "2" << "c" << "9" << "y" << "8" + << "0" << "a" << "o" << "8" << "k" + << QString() << "b" << "7" << "3" << "u") << (IntList() << 2 << 0 << 1) << IntList() << IntList(); QTest::newRow("ascending with null cell, the null cell should be placed at the bottom") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() - << "0" << "a" << "o" << "8" << "k" - << "3" << "d" << "k" << "o" << "6" - << "2" << "c" << "9" << "y" << "8" - << 0 << "b" << "7" << "3" << "u") + << "0" << "a" << "o" << "8" << "k" + << "3" << "d" << "k" << "o" << "6" + << "2" << "c" << "9" << "y" << "8" + << QString() << "b" << "7" << "3" << "u") << (QStringList() - << "0" << "a" << "o" << "8" << "k" - << "2" << "c" << "9" << "y" << "8" - << "3" << "d" << "k" << "o" << "6" - << 0 << "b" << "7" << "3" << "u") + << "0" << "a" << "o" << "8" << "k" + << "2" << "c" << "9" << "y" << "8" + << "3" << "d" << "k" << "o" << "6" + << QString() << "b" << "7" << "3" << "u") << (IntList() << 0 << 2 << 1) << IntList() << IntList(); QTest::newRow("ascending with null cells, the null cells should be placed at the bottom") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() - << "3" << "d" << "k" << "o" << "6" - << "0" << "a" << "o" << "8" << "k" - << 0 << "c" << "9" << "y" << "8" - << 0 << "b" << "7" << "3" << "u") + << "3" << "d" << "k" << "o" << "6" + << "0" << "a" << "o" << "8" << "k" + << QString() << "c" << "9" << "y" << "8" + << QString() << "b" << "7" << "3" << "u") << (QStringList() - << "0" << "a" << "o" << "8" << "k" - << "3" << "d" << "k" << "o" << "6" - << 0 << "c" << "9" << "y" << "8" - << 0 << "b" << "7" << "3" << "u") + << "0" << "a" << "o" << "8" << "k" + << "3" << "d" << "k" << "o" << "6" + << QString() << "c" << "9" << "y" << "8" + << QString() << "b" << "7" << "3" << "u") << (IntList() << 1 << 0) << IntList() << IntList(); QTest::newRow("ascending... Check a bug in PersistentIndexes") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() << "3" << "c" << "9" << "y" << "8" << "2" << "b" << "7" << "3" << "u" << "4" << "d" << "k" << "o" << "6" - << "1" << "a" << "o" << "8" << "k" - ) + << "1" << "a" << "o" << "8" << "k") << (QStringList() << "1" << "a" << "o" << "8" << "k" << "2" << "b" << "7" << "3" << "u" << "3" << "c" << "9" << "y" << "8" - << "4" << "d" << "k" << "o" << "6" - ) + << "4" << "d" << "k" << "o" << "6") << (IntList() << 2 << 1 << 3 << 0) << IntList() << IntList(); QTest::newRow("ascending with some null cells inbetween") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() - << 0 << "a" << "o" << "8" << "k" - << "2" << "c" << "9" << "y" << "8" - << 0 << "d" << "k" << "o" << "6" - << "1" << "b" << "7" << "3" << "u") + << QString() << "a" << "o" << "8" << "k" + << "2" << "c" << "9" << "y" << "8" + << QString() << "d" << "k" << "o" << "6" + << "1" << "b" << "7" << "3" << "u") << (QStringList() - << "1" << "b" << "7" << "3" << "u" - << "2" << "c" << "9" << "y" << "8" - << 0 << "a" << "o" << "8" << "k" - << 0 << "d" << "k" << "o" << "6") + << "1" << "b" << "7" << "3" << "u" + << "2" << "c" << "9" << "y" << "8" + << QString() << "a" << "o" << "8" << "k" + << QString() << "d" << "k" << "o" << "6") << (IntList() << 1 << 0) << IntList() << IntList(); QTest::newRow("ascending hidden") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() << "0" << "a" << "o" << "8" << "k" @@ -1098,7 +1085,7 @@ void tst_QTableWidget::sortItems_data() QTest::newRow("descending hidden") << 4 << 5 - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << 0 << (QStringList() << "0" << "a" << "o" << "8" << "k" @@ -1119,7 +1106,7 @@ void tst_QTableWidget::sortItems() { QFETCH(int, rowCount); QFETCH(int, columnCount); - QFETCH(int, sortOrder); + QFETCH(Qt::SortOrder, sortOrder); QFETCH(int, sortColumn); QFETCH(QStringList, initial); QFETCH(QStringList, expected); @@ -1131,13 +1118,13 @@ void tst_QTableWidget::sortItems() testWidget->setColumnCount(columnCount); QAbstractItemModel *model = testWidget->model(); - QList<QPersistentModelIndex> persistent; + QVector<QPersistentModelIndex> persistent; int ti = 0; for (int r = 0; r < rowCount; ++r) { for (int c = 0; c < columnCount; ++c) { - QString str = initial.at(ti++); - if (!str.isNull()) { + QString str = initial.at(ti++); + if (!str.isEmpty()) { testWidget->setItem(r, c, new QTableWidgetItem(str)); } } @@ -1150,7 +1137,7 @@ void tst_QTableWidget::sortItems() QCOMPARE(testWidget->verticalHeader()->hiddenSectionCount(), initialHidden.count()); - testWidget->sortItems(sortColumn, static_cast<Qt::SortOrder>(sortOrder)); + testWidget->sortItems(sortColumn, sortOrder); int te = 0; for (int i = 0; i < rows.count(); ++i) { @@ -1175,7 +1162,7 @@ void tst_QTableWidget::setItemWithSorting_data() { QTest::addColumn<int>("rowCount"); QTest::addColumn<int>("columnCount"); - QTest::addColumn<int>("sortOrder"); + QTest::addColumn<Qt::SortOrder>("sortOrder"); QTest::addColumn<int>("sortColumn"); QTest::addColumn<QStringList>("initialValues"); QTest::addColumn<int>("row"); @@ -1187,7 +1174,7 @@ void tst_QTableWidget::setItemWithSorting_data() QTest::newRow("2x1 no change (ascending)") << 2 << 1 - << static_cast<int>(Qt::AscendingOrder) << 0 + << Qt::AscendingOrder << 0 << (QStringList() << "0" << "1") << 1 << 0 << "2" << (QStringList() << "0" << "2") @@ -1195,7 +1182,7 @@ void tst_QTableWidget::setItemWithSorting_data() << false; QTest::newRow("2x1 no change (descending)") << 2 << 1 - << static_cast<int>(Qt::DescendingOrder) << 0 + << Qt::DescendingOrder << 0 << (QStringList() << "1" << "0") << 0 << 0 << "2" << (QStringList() << "2" << "0") @@ -1203,7 +1190,7 @@ void tst_QTableWidget::setItemWithSorting_data() << false; QTest::newRow("2x1 reorder (ascending)") << 2 << 1 - << static_cast<int>(Qt::AscendingOrder) << 0 + << Qt::AscendingOrder << 0 << (QStringList() << "0" << "1") << 0 << 0 << "2" << (QStringList() << "1" << "2") @@ -1211,7 +1198,7 @@ void tst_QTableWidget::setItemWithSorting_data() << true; QTest::newRow("2x1 reorder (descending)") << 2 << 1 - << static_cast<int>(Qt::DescendingOrder) << 0 + << Qt::DescendingOrder << 0 << (QStringList() << "1" << "0") << 1 << 0 << "2" << (QStringList() << "2" << "1") @@ -1219,7 +1206,7 @@ void tst_QTableWidget::setItemWithSorting_data() << true; QTest::newRow("2x2 no change (ascending)") << 2 << 2 - << static_cast<int>(Qt::AscendingOrder) << 0 + << Qt::AscendingOrder << 0 << (QStringList() << "0" << "00" << "1" << "11") @@ -1231,7 +1218,7 @@ void tst_QTableWidget::setItemWithSorting_data() << false; QTest::newRow("2x2 reorder (ascending)") << 2 << 2 - << static_cast<int>(Qt::AscendingOrder) << 0 + << Qt::AscendingOrder << 0 << (QStringList() << "0" << "00" << "1" << "11") @@ -1243,7 +1230,7 @@ void tst_QTableWidget::setItemWithSorting_data() << true; QTest::newRow("2x2 reorder (ascending, sortColumn = 1)") << 2 << 2 - << static_cast<int>(Qt::AscendingOrder) << 1 + << Qt::AscendingOrder << 1 << (QStringList() << "00" << "0" << "11" << "1") @@ -1255,7 +1242,7 @@ void tst_QTableWidget::setItemWithSorting_data() << true; QTest::newRow("2x2 no change (column != sortColumn)") << 2 << 2 - << static_cast<int>(Qt::AscendingOrder) << 1 + << Qt::AscendingOrder << 1 << (QStringList() << "00" << "0" << "11" << "1") @@ -1267,7 +1254,7 @@ void tst_QTableWidget::setItemWithSorting_data() << false; QTest::newRow("8x4 reorder (ascending, sortColumn = 3)") << 8 << 4 - << static_cast<int>(Qt::AscendingOrder) << 3 + << Qt::AscendingOrder << 3 << (QStringList() << "q" << "v" << "u" << "0" << "e" << "j" << "i" << "10" @@ -1293,9 +1280,13 @@ void tst_QTableWidget::setItemWithSorting_data() void tst_QTableWidget::setItemWithSorting() { + static int dummy1 = qRegisterMetaType<QList<QPersistentModelIndex>>(); + static int dummy2 = qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>(); + Q_UNUSED(dummy1); + Q_UNUSED(dummy2); QFETCH(int, rowCount); QFETCH(int, columnCount); - QFETCH(int, sortOrder); + QFETCH(Qt::SortOrder, sortOrder); QFETCH(int, sortColumn); QFETCH(QStringList, initialValues); QFETCH(int, row); @@ -1309,7 +1300,7 @@ void tst_QTableWidget::setItemWithSorting() QTableWidget w(rowCount, columnCount); QAbstractItemModel *model = w.model(); - QList<QPersistentModelIndex> persistent; + QVector<QPersistentModelIndex> persistent; int ti = 0; for (int r = 0; r < rowCount; ++r) { @@ -1320,11 +1311,11 @@ void tst_QTableWidget::setItemWithSorting() persistent << model->index(r, sortColumn); } - w.sortItems(sortColumn, static_cast<Qt::SortOrder>(sortOrder)); + w.sortItems(sortColumn, sortOrder); w.setSortingEnabled(true); - QSignalSpy dataChangedSpy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex))); - QSignalSpy layoutChangedSpy(model, SIGNAL(layoutChanged())); + QSignalSpy dataChangedSpy(model, &QAbstractItemModel::dataChanged); + QSignalSpy layoutChangedSpy(model, &QAbstractItemModel::layoutChanged); if (i == 0) { // set a new item @@ -1376,18 +1367,18 @@ public: void tst_QTableWidget::itemData() { QTableWidgetDataChanged widget(2, 2); - widget.setItem(0, 0, new QTableWidgetItem()); + widget.setItem(0, 0, new QTableWidgetItem); QTableWidgetItem *item = widget.item(0, 0); QVERIFY(item); item->setFlags(item->flags() | Qt::ItemIsEditable); item->setData(Qt::DisplayRole, QString("0")); QCOMPARE(widget.currentRoles, QVector<int>({Qt::DisplayRole, Qt::EditRole})); item->setData(Qt::CheckStateRole, Qt::PartiallyChecked); - QCOMPARE(widget.currentRoles, {Qt::CheckStateRole}); + QCOMPARE(widget.currentRoles, QVector<int>{Qt::CheckStateRole}); for (int i = 0; i < 4; ++i) { item->setData(Qt::UserRole + i, QString::number(i + 1)); - QCOMPARE(widget.currentRoles, {Qt::UserRole + i}); + QCOMPARE(widget.currentRoles, QVector<int>{Qt::UserRole + i}); } QMap<int, QVariant> flags = widget.model()->itemData(widget.model()->index(0, 0)); QCOMPARE(flags.count(), 6); @@ -1399,7 +1390,7 @@ void tst_QTableWidget::setItemData() { QTableWidgetDataChanged table(10, 10); table.setSortingEnabled(false); - QSignalSpy dataChangedSpy(table.model(), SIGNAL(dataChanged(QModelIndex,QModelIndex))); + QSignalSpy dataChangedSpy(table.model(), &QAbstractItemModel::dataChanged); QTableWidgetItem *item = new QTableWidgetItem; table.setItem(0, 0, item); @@ -1432,11 +1423,11 @@ void tst_QTableWidget::cellWidget() QTableWidget table(10, 10); QWidget widget; - QCOMPARE(table.cellWidget(5, 5), static_cast<QWidget*>(0)); + QCOMPARE(table.cellWidget(5, 5), nullptr); table.setCellWidget(5, 5, &widget); QCOMPARE(table.cellWidget(5, 5), &widget); table.removeCellWidget(5, 5); - QCOMPARE(table.cellWidget(5, 5), static_cast<QWidget*>(0)); + QCOMPARE(table.cellWidget(5, 5), nullptr); } void tst_QTableWidget::cellWidgetGeometry() @@ -1463,27 +1454,29 @@ void tst_QTableWidget::cellWidgetGeometry() void tst_QTableWidget::sizeHint_data() { - QTest::addColumn<int>("scrollBarPolicy"); + QTest::addColumn<Qt::ScrollBarPolicy>("scrollBarPolicy"); QTest::addColumn<QSize>("viewSize"); - QTest::newRow("ScrollBarAlwaysOn") << static_cast<int>(Qt::ScrollBarAlwaysOn) << QSize(); - QTest::newRow("ScrollBarAlwaysOff") << static_cast<int>(Qt::ScrollBarAlwaysOff) << QSize(); + QTest::newRow("ScrollBarAlwaysOn") << Qt::ScrollBarAlwaysOn << QSize(); + QTest::newRow("ScrollBarAlwaysOff") << Qt::ScrollBarAlwaysOff << QSize(); // make sure the scrollbars are shown by resizing the view to 40x40 - QTest::newRow("ScrollBarAsNeeded (40x40)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(40, 40); - QTest::newRow("ScrollBarAsNeeded (1000x1000)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(1000, 1000); + QTest::newRow("ScrollBarAsNeeded (40x40)") << Qt::ScrollBarAsNeeded << QSize(40, 40); + QTest::newRow("ScrollBarAsNeeded (1000x1000)") << Qt::ScrollBarAsNeeded << QSize(1000, 1000); } void tst_QTableWidget::sizeHint() { - QFETCH(int, scrollBarPolicy); + QFETCH(Qt::ScrollBarPolicy, scrollBarPolicy); QFETCH(QSize, viewSize); QTableWidget view(2, 2); view.setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); - view.setVerticalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy)); - view.setHorizontalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy)); - for (int r = 0 ; r < view.rowCount(); ++r) + view.setVerticalScrollBarPolicy(scrollBarPolicy); + view.setHorizontalScrollBarPolicy(scrollBarPolicy); + for (int r = 0 ; r < view.rowCount(); ++r) { + const QString rStr = QString::number(r) + QLatin1Char('/'); for (int c = 0 ; c < view.columnCount(); ++c) - view.setItem(r, c, new QTableWidgetItem(QString("%1/%2").arg(r).arg(c))); + view.setItem(r, c, new QTableWidgetItem(rStr + QString::number(c))); + } view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -1520,7 +1513,7 @@ void tst_QTableWidget::task231094() if (y == 1) twi->setFlags(Qt::ItemIsEnabled); else - twi->setFlags(0); + twi->setFlags({}); tw.setItem(y, x, twi); } } @@ -1558,15 +1551,15 @@ void tst_QTableWidget::task262056_sortDuplicate() testWidget->setColumnCount(2); testWidget->setRowCount(8); testWidget->setSortingEnabled(true); - QStringList items = (QStringList() << "AAA" << "BBB" << "CCC" << "CCC" << "DDD"\ - << "EEE" << "FFF" << "GGG"); - for (int i = 0; i<8; i++ ) { + const QStringList items({"AAA", "BBB", "CCC", "CCC", "DDD", + "EEE", "FFF", "GGG"}); + for (int i = 0; i < 8; i++ ) { QTableWidgetItem *twi = new QTableWidgetItem(items.at(i)); - testWidget->setItem(i,0,twi); - testWidget->setItem(i,1,new QTableWidgetItem(QLatin1String("item ") + QString::number(i))); + testWidget->setItem(i, 0, twi); + testWidget->setItem(i, 1, new QTableWidgetItem(QLatin1String("item ") + QString::number(i))); } testWidget->sortItems(0, Qt::AscendingOrder); - QSignalSpy layoutChangedSpy(testWidget->model(), SIGNAL(layoutChanged())); + QSignalSpy layoutChangedSpy(testWidget->model(), &QAbstractItemModel::layoutChanged); testWidget->item(3,0)->setBackground(Qt::red); QCOMPARE(layoutChangedSpy.count(),0); @@ -1586,18 +1579,14 @@ void tst_QTableWidget::itemWithHeaderItems() QTableWidgetItem *item1_0 = new QTableWidgetItem(QTableWidgetItem::UserType); table.setItem(1, 0, item1_0); - QCOMPARE(table.item(0, 1), static_cast<QTableWidgetItem *>(0)); + QCOMPARE(table.item(0, 1), nullptr); } class TestTableWidget : public QTableWidget { Q_OBJECT public: - TestTableWidget(int rows, int columns, QWidget *parent = 0) - : QTableWidget(rows, columns, parent) - { - } - + using QTableWidget::QTableWidget; using QTableWidget::mimeData; using QTableWidget::indexFromItem; using QTableWidget::keyPressEvent; @@ -1661,18 +1650,19 @@ void tst_QTableWidget::selectedRowAfterSorting() { TestTableWidget table(3,3); table.setSelectionBehavior(QAbstractItemView::SelectRows); - for (int r = 0; r < 3; r++) + for (int r = 0; r < 3; r++) { for (int c = 0; c < 3; c++) - table.setItem(r,c,new QTableWidgetItem(QStringLiteral("0"))); + table.setItem(r, c, new QTableWidgetItem(QStringLiteral("0"))); + } QHeaderView *localHorizontalHeader = table.horizontalHeader(); localHorizontalHeader->setSortIndicator(1,Qt::DescendingOrder); table.setProperty("sortingEnabled",true); table.selectRow(1); table.item(1,1)->setText("9"); QCOMPARE(table.selectedItems().count(),3); - foreach (QTableWidgetItem *item, table.selectedItems()) { - QCOMPARE(item->row(),0); - } + const auto selectedItems = table.selectedItems(); + for (QTableWidgetItem *item : selectedItems) + QCOMPARE(item->row(), 0); } void tst_QTableWidget::search() @@ -1717,10 +1707,11 @@ void tst_QTableWidget::search() #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) void tst_QTableWidget::clearItemData() { - QTableWidget table(3,3); - for (int r = 0; r < 3; r++) + QTableWidget table(3, 3); + for (int r = 0; r < 3; r++) { for (int c = 0; c < 3; c++) - table.setItem(r,c,new QTableWidgetItem(QStringLiteral("0"))); + table.setItem(r, c, new QTableWidgetItem(QStringLiteral("0"))); + } QSignalSpy dataChangeSpy(table.model(), &QAbstractItemModel::dataChanged); QVERIFY(dataChangeSpy.isValid()); QVERIFY(!table.model()->clearItemData(QModelIndex())); diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp index 2a1163ec66..44195d3b25 100644 --- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp @@ -27,13 +27,28 @@ ****************************************************************************/ #include "../../../../shared/fakedirmodel.h" -#include <qabstractitemview.h> -#include <QtTest/QtTest> -#include <QtGui/QtGui> -#include <QtWidgets/QtWidgets> -#include <private/qtreeview_p.h> -#include <QtTest/private/qtesthelpers_p.h> +#include <QDesktopWidget> +#include <QHeaderView> +#include <QLabel> +#include <QLineEdit> +#include <QMainWindow> +#include <QProxyStyle> +#include <QPushButton> +#include <QScrollBar> +#include <QSignalSpy> +#include <QSortFilterProxyModel> +#include <QStatusBar> +#include <QStringListModel> +#include <QStyledItemDelegate> +#include <QTextEdit> +#include <QTimer> +#include <QToolButton> +#include <QTreeWidget> +#include <QTest> +#include <QVBoxLayout> +#include <private/qtreeview_p.h> +#include <private/qtesthelpers_p.h> using namespace QTestPrivate; @@ -43,6 +58,7 @@ Q_DECLARE_METATYPE(QAbstractItemView::DragDropMode) Q_DECLARE_METATYPE(QAbstractItemView::EditTriggers) Q_DECLARE_METATYPE(QAbstractItemView::EditTrigger) +using IntBounds = std::numeric_limits<int>; static void initStandardTreeModel(QStandardItemModel *model) { QStandardItem *item; @@ -206,18 +222,11 @@ private slots: class QtTestModel: public QAbstractItemModel { + Q_OBJECT public: - QtTestModel(QObject *parent = 0): QAbstractItemModel(parent), - fetched(false), rows(0), cols(0), levels(INT_MAX), wrongIndex(false) { init(); } - - QtTestModel(int _rows, int _cols, QObject *parent = 0): QAbstractItemModel(parent), - fetched(false), rows(_rows), cols(_cols), levels(INT_MAX), wrongIndex(false) { init(); } - - void init() - { - decorationsEnabled = false; - statusTipsEnabled = false; - } + QtTestModel(int _rows, int _cols, QObject *parent = nullptr) + : QAbstractItemModel(parent), rows(_rows), cols(_cols) + {} inline qint32 level(const QModelIndex &index) const { @@ -264,7 +273,7 @@ public: if (row < 0 || column < 0 || (level(parent) > levels) || column >= cols || row >= rows) { return QModelIndex(); } - QModelIndex i = createIndex(row, column, level(parent) + 1); + QModelIndex i = createIndex(row, column, quintptr(level(parent) + 1)); parentHash[i] = parent; return i; } @@ -361,13 +370,14 @@ public: decorationsEnabled = enable; } - mutable bool fetched; - bool decorationsEnabled; - bool statusTipsEnabled; - int rows, cols; - int levels; - mutable bool wrongIndex; mutable QMap<QModelIndex,QModelIndex> parentHash; + int rows = 0; + int cols = 0; + int levels = IntBounds::max(); + mutable bool wrongIndex = false; + mutable bool fetched = false; + bool decorationsEnabled = false; + bool statusTipsEnabled = false; }; // Testing get/set functions @@ -377,14 +387,15 @@ void tst_QTreeView::getSetCheck() // int QTreeView::indentation() // void QTreeView::setIndentation(int) - const int styledIndentation = obj1.style()->pixelMetric(QStyle::PM_TreeViewIndentation, 0, &obj1); + const int styledIndentation = obj1.style()->pixelMetric( + QStyle::PM_TreeViewIndentation, nullptr, &obj1); QCOMPARE(obj1.indentation(), styledIndentation); obj1.setIndentation(0); QCOMPARE(obj1.indentation(), 0); - obj1.setIndentation(INT_MIN); - QCOMPARE(obj1.indentation(), INT_MIN); - obj1.setIndentation(INT_MAX); - QCOMPARE(obj1.indentation(), INT_MAX); + obj1.setIndentation(IntBounds::min()); + QCOMPARE(obj1.indentation(), IntBounds::min()); + obj1.setIndentation(IntBounds::max()); + QCOMPARE(obj1.indentation(), IntBounds::max()); // bool QTreeView::rootIsDecorated() // void QTreeView::setRootIsDecorated(bool) @@ -477,7 +488,8 @@ void tst_QTreeView::construction() QCOMPARE(view.sizeHintForRow(1), -1); QVERIFY(!view.tabKeyNavigation()); QCOMPARE(view.textElideMode(), Qt::ElideRight); - QCOMPARE(static_cast<int>(view.verticalScrollMode()), view.style()->styleHint(QStyle::SH_ItemView_ScrollMode, 0, &view)); + QCOMPARE(static_cast<int>(view.verticalScrollMode()), + view.style()->styleHint(QStyle::SH_ItemView_ScrollMode, nullptr, &view)); QCOMPARE(view.visualRect(QModelIndex()), QRect()); // QTreeView properties @@ -493,8 +505,8 @@ void tst_QTreeView::construction() QCOMPARE(view.columnWidth(0), 0); QCOMPARE(view.columnWidth(1), 0); QVERIFY(view.header()); - const int styledIndentation = view.style()->pixelMetric(QStyle::PM_TreeViewIndentation, 0, &view); - QCOMPARE(view.indentation(), styledIndentation); + QCOMPARE(view.indentation(), + view.style()->pixelMetric(QStyle::PM_TreeViewIndentation, nullptr, &view)); QCOMPARE(view.indexAbove(QModelIndex()), QModelIndex()); QCOMPARE(view.indexBelow(QModelIndex()), QModelIndex()); QVERIFY(!view.isAnimated()); @@ -781,17 +793,17 @@ void tst_QTreeView::editTriggers() break; case QAbstractItemView::DoubleClicked: // Doubleclick the center of the current cell - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(view.model()->index(0, 0)).center()); - QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, + QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(view.model()->index(0, 0)).center()); break; case QAbstractItemView::SelectedClicked: // Click the center of the current cell view.selectionModel()->select(view.model()->index(0, 0), QItemSelectionModel::Select); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(view.model()->index(0, 0)).center()); - QTest::qWait(int(QApplication::doubleClickInterval() * 1.5)); + QTest::qWait(qRound(QApplication::doubleClickInterval() * 1.5)); break; case QAbstractItemView::EditKeyPressed: view.setFocus(); @@ -808,7 +820,7 @@ void tst_QTreeView::editTriggers() } // Check if we got an editor - QTRY_COMPARE(view.findChild<QLineEdit *>(QString()) != 0, editorOpened); + QTRY_COMPARE(view.findChild<QLineEdit *>(QString()) != nullptr, editorOpened); } void tst_QTreeView::hasAutoScroll() @@ -860,11 +872,11 @@ void tst_QTreeView::horizontalScrollMode() class RepaintTreeView : public QTreeView { public: - RepaintTreeView() : repainted(false) { } - bool repainted; + using QTreeView::QTreeView; + bool repainted = false; protected: - void paintEvent(QPaintEvent *event) + void paintEvent(QPaintEvent *event) override { repainted = true; QTreeView::paintEvent(event); } }; @@ -902,8 +914,7 @@ void tst_QTreeView::iconSize() void tst_QTreeView::indexAt() { - QtTestModel model; - model.rows = model.cols = 5; + QtTestModel model(5, 5); QTreeView view; QCOMPARE(view.indexAt(QPoint()), QModelIndex()); @@ -985,21 +996,21 @@ void tst_QTreeView::indexWidget() void tst_QTreeView::itemDelegate() { QPointer<QAbstractItemDelegate> oldDelegate; - QPointer<QItemDelegate> otherItemDelegate; + QPointer<QStyledItemDelegate> otherItemDelegate; { QTreeView view; QVERIFY(qobject_cast<QStyledItemDelegate *>(view.itemDelegate())); QPointer<QAbstractItemDelegate> oldDelegate = view.itemDelegate(); - otherItemDelegate = new QItemDelegate; + otherItemDelegate = new QStyledItemDelegate; view.setItemDelegate(otherItemDelegate); QVERIFY(!otherItemDelegate->parent()); QVERIFY(oldDelegate); - QCOMPARE(view.itemDelegate(), (QAbstractItemDelegate *)otherItemDelegate); + QCOMPARE(view.itemDelegate(), otherItemDelegate); - view.setItemDelegate(0); + view.setItemDelegate(nullptr); QVERIFY(!view.itemDelegate()); // <- view does its own drawing? QVERIFY(otherItemDelegate); } @@ -1038,29 +1049,29 @@ void tst_QTreeView::itemDelegateForColumnOrRow() QCOMPARE(view.itemDelegate(QModelIndex()), defaultDelegate); QCOMPARE(view.itemDelegate(view.model()->index(0, 0)), defaultDelegate); - QPointer<QAbstractItemDelegate> rowDelegate = new QItemDelegate; + QPointer<QAbstractItemDelegate> rowDelegate = new QStyledItemDelegate; view.setItemDelegateForRow(0, rowDelegate); QVERIFY(!rowDelegate->parent()); - QCOMPARE(view.itemDelegateForRow(0), (QAbstractItemDelegate *)rowDelegate); - QCOMPARE(view.itemDelegate(view.model()->index(0, 0)), (QAbstractItemDelegate *)rowDelegate); - QCOMPARE(view.itemDelegate(view.model()->index(0, 1)), (QAbstractItemDelegate *)rowDelegate); + QCOMPARE(view.itemDelegateForRow(0), rowDelegate); + QCOMPARE(view.itemDelegate(view.model()->index(0, 0)), rowDelegate); + QCOMPARE(view.itemDelegate(view.model()->index(0, 1)), rowDelegate); QCOMPARE(view.itemDelegate(view.model()->index(1, 0)), defaultDelegate); QCOMPARE(view.itemDelegate(view.model()->index(1, 1)), defaultDelegate); - QPointer<QAbstractItemDelegate> columnDelegate = new QItemDelegate; + QPointer<QAbstractItemDelegate> columnDelegate = new QStyledItemDelegate; view.setItemDelegateForColumn(1, columnDelegate); QVERIFY(!columnDelegate->parent()); - QCOMPARE(view.itemDelegateForColumn(1), (QAbstractItemDelegate *)columnDelegate); - QCOMPARE(view.itemDelegate(view.model()->index(0, 0)), (QAbstractItemDelegate *)rowDelegate); - QCOMPARE(view.itemDelegate(view.model()->index(0, 1)), (QAbstractItemDelegate *)rowDelegate); // row wins + QCOMPARE(view.itemDelegateForColumn(1), columnDelegate); + QCOMPARE(view.itemDelegate(view.model()->index(0, 0)), rowDelegate); + QCOMPARE(view.itemDelegate(view.model()->index(0, 1)), rowDelegate); // row wins QCOMPARE(view.itemDelegate(view.model()->index(1, 0)), defaultDelegate); - QCOMPARE(view.itemDelegate(view.model()->index(1, 1)), (QAbstractItemDelegate *)columnDelegate); + QCOMPARE(view.itemDelegate(view.model()->index(1, 1)), columnDelegate); - view.setItemDelegateForRow(0, 0); + view.setItemDelegateForRow(0, nullptr); QVERIFY(!view.itemDelegateForRow(0)); QVERIFY(rowDelegate); // <- wasn't deleted - view.setItemDelegateForColumn(1, 0); + view.setItemDelegateForColumn(1, nullptr); QVERIFY(!view.itemDelegateForColumn(1)); QVERIFY(columnDelegate); // <- wasn't deleted @@ -1130,12 +1141,9 @@ void tst_QTreeView::keyboardSearch() QTest::qWait(QApplication::keyboardInputInterval() * 2); model.clear(); view.setCurrentIndex(QModelIndex()); - QList<QStandardItem *> items = { new QStandardItem("Andreas"), new QStandardItem("Alicia") }; - model.appendRow(items); - items = { new QStandardItem("Baldrian"), new QStandardItem("Belinda") }; - model.appendRow(items); - items = { new QStandardItem("Cecilie"), new QStandardItem("Claire") }; - model.appendRow(items); + model.appendRow({ new QStandardItem("Andreas"), new QStandardItem("Alicia") }); + model.appendRow({ new QStandardItem("Baldrian"), new QStandardItem("Belinda") }); + model.appendRow({ new QStandardItem("Cecilie"), new QStandardItem("Claire") }); QVERIFY(!view.selectionModel()->hasSelection()); QVERIFY(!view.selectionModel()->isSelected(model.index(0, 0))); @@ -1166,8 +1174,7 @@ void tst_QTreeView::keyboardSearch() QCOMPARE(view.currentIndex(), model.index(1, 1)); // Test that it wraps round - items = { new QStandardItem("Andy"), new QStandardItem("Adele") }; - model.appendRow(items); + model.appendRow({ new QStandardItem("Andy"), new QStandardItem("Adele") }); QTest::qWait(QApplication::keyboardInputInterval() * 2); view.keyboardSearch(QLatin1String("A")); QVERIFY(view.selectionModel()->isSelected(model.index(3, 1))); @@ -1202,17 +1209,16 @@ void tst_QTreeView::keyboardSearch() void tst_QTreeView::keyboardSearchMultiColumn() { QTreeView view; - QStandardItemModel model(4, 2); model.setItem(0, 0, new QStandardItem("1")); model.setItem(0, 1, new QStandardItem("green")); - model.setItem(1, 0, new QStandardItem("bad")); model.setItem(1, 1, new QStandardItem("eggs")); - model.setItem(2, 0, new QStandardItem("moof")); model.setItem(2, 1, new QStandardItem("and")); - model.setItem(3, 0, new QStandardItem("elf")); model.setItem(3, 1, new QStandardItem("ham")); + model.setItem(1, 0, new QStandardItem("bad")); model.setItem(1, 1, new QStandardItem("eggs")); + model.setItem(2, 0, new QStandardItem("moof")); model.setItem(2, 1, new QStandardItem("and")); + model.setItem(3, 0, new QStandardItem("elf")); model.setItem(3, 1, new QStandardItem("ham")); view.setModel(&model); view.show(); - qApp->setActiveWindow(&view); + QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); view.setCurrentIndex(model.index(0, 1)); @@ -1240,22 +1246,22 @@ void tst_QTreeView::setModel() for (int x = 0; x < 2; ++x) { QtTestModel *model = new QtTestModel(10, 8); QAbstractItemModel *oldModel = view.model(); - QSignalSpy modelDestroyedSpy(oldModel ? oldModel : model, SIGNAL(destroyed())); + QSignalSpy modelDestroyedSpy(oldModel ? oldModel : model, &QObject::destroyed); // set the same model twice for (int i = 0; i < 2; ++i) { QItemSelectionModel *oldSelectionModel = view.selectionModel(); QItemSelectionModel *dummy = new QItemSelectionModel(model); QSignalSpy selectionModelDestroyedSpy( - oldSelectionModel ? oldSelectionModel : dummy, SIGNAL(destroyed())); + oldSelectionModel ? oldSelectionModel : dummy, &QObject::destroyed); view.setModel(model); // QCOMPARE(selectionModelDestroyedSpy.count(), (x == 0 || i == 1) ? 0 : 1); - QCOMPARE(view.model(), (QAbstractItemModel *)model); - QCOMPARE(view.header()->model(), (QAbstractItemModel *)model); + QCOMPARE(view.model(), model); + QCOMPARE(view.header()->model(), model); QCOMPARE(view.selectionModel() != oldSelectionModel, (i == 0)); } QTRY_COMPARE(modelDestroyedSpy.count(), 0); - view.setModel(0); + view.setModel(nullptr); QCOMPARE(view.model(), nullptr); // ### shouldn't selectionModel also be 0 now? // QCOMPARE(view.selectionModel(), nullptr); @@ -1278,7 +1284,7 @@ void tst_QTreeView::openPersistentEditor() view.closePersistentEditor(view.model()->index(0, 0)); QVERIFY(!view.viewport()->findChild<QLineEdit *>()->isVisible()); - qApp->sendPostedEvents(0, QEvent::DeferredDelete); + QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); QVERIFY(!view.viewport()->findChild<QLineEdit *>()); } @@ -1300,21 +1306,20 @@ void tst_QTreeView::rootIndex() void tst_QTreeView::setHeader() { QTreeView view; - QVERIFY(view.header() != 0); + QVERIFY(view.header() != nullptr); QCOMPARE(view.header()->orientation(), Qt::Horizontal); - QCOMPARE(view.header()->parent(), (QObject *)&view); + QCOMPARE(view.header()->parent(), &view); for (int x = 0; x < 2; ++x) { - QSignalSpy destroyedSpy(view.header(), SIGNAL(destroyed())); + QSignalSpy destroyedSpy(view.header(), &QObject::destroyed); Qt::Orientation orient = x ? Qt::Vertical : Qt::Horizontal; QHeaderView *head = new QHeaderView(orient); view.setHeader(head); QCOMPARE(destroyedSpy.count(), 1); - QCOMPARE(head->parent(), (QObject *)&view); + QCOMPARE(head->parent(), &view); QCOMPARE(view.header(), head); view.setHeader(head); QCOMPARE(view.header(), head); - // Itemviews in Qt < 4.2 have asserts for this. Qt >= 4.2 should handle this gracefully - view.setHeader((QHeaderView *)0); + view.setHeader(nullptr); QCOMPARE(view.header(), head); } } @@ -1328,13 +1333,13 @@ void tst_QTreeView::columnHidden() for (int c = 0; c < model.columnCount(); ++c) QCOMPARE(view.isColumnHidden(c), false); // hide even columns - for (int c = 0; c < model.columnCount(); c+=2) + for (int c = 0; c < model.columnCount(); c += 2) view.setColumnHidden(c, true); for (int c = 0; c < model.columnCount(); ++c) QCOMPARE(view.isColumnHidden(c), (c & 1) == 0); view.update(); // hide odd columns too - for (int c = 1; c < model.columnCount(); c+=2) + for (int c = 1; c < model.columnCount(); c += 2) view.setColumnHidden(c, true); for (int c = 0; c < model.columnCount(); ++c) QCOMPARE(view.isColumnHidden(c), true); @@ -1418,7 +1423,7 @@ void tst_QTreeView::noDelegate() QtTestModel model(10, 7); QTreeView view; view.setModel(&model); - view.setItemDelegate(0); + view.setItemDelegate(nullptr); QCOMPARE(view.itemDelegate(), nullptr); } @@ -1427,11 +1432,13 @@ void tst_QTreeView::noModel() QTreeView view; view.show(); view.setRowHidden(0, QModelIndex(), true); + // no model -> not able to hide a row + QVERIFY(!view.isRowHidden(0, QModelIndex())); } void tst_QTreeView::emptyModel() { - QtTestModel model; + QtTestModel model(0, 0); QTreeView view; view.setModel(&model); view.show(); @@ -1486,7 +1493,7 @@ void tst_QTreeView::limitedExpand() QTreeView view; view.setModel(&model); - QSignalSpy spy(&view, SIGNAL(expanded(QModelIndex))); + QSignalSpy spy(&view, &QTreeView::expanded); QVERIFY(spy.isValid()); view.expand(model.index(0, 0)); @@ -1500,7 +1507,7 @@ void tst_QTreeView::limitedExpand() QTreeView view; view.setModel(&model); - QSignalSpy spy(&view, SIGNAL(expanded(QModelIndex))); + QSignalSpy spy(&view, &QTreeView::expanded); QVERIFY(spy.isValid()); view.expand(model.index(0, 0)); @@ -1515,7 +1522,6 @@ void tst_QTreeView::expandAndCollapse_data() QTest::addColumn<bool>("animationEnabled"); QTest::newRow("normal") << false; QTest::newRow("animated") << true; - } void tst_QTreeView::expandAndCollapse() @@ -1533,8 +1539,8 @@ void tst_QTreeView::expandAndCollapse() QModelIndex a = model.index(0, 0, QModelIndex()); QModelIndex b = model.index(0, 0, a); - QSignalSpy expandedSpy(&view, SIGNAL(expanded(QModelIndex))); - QSignalSpy collapsedSpy(&view, SIGNAL(collapsed(QModelIndex))); + QSignalSpy expandedSpy(&view, &QTreeView::expanded); + QSignalSpy collapsedSpy(&view, &QTreeView::collapsed); QVariantList args; for (int y = 0; y < 2; ++y) { @@ -1744,7 +1750,7 @@ void tst_QTreeView::expandAndCollapseAll() void tst_QTreeView::expandWithNoChildren() { QTreeView tree; - QStandardItemModel model(1,1); + QStandardItemModel model(1, 1); tree.setModel(&model); tree.setAnimated(true); tree.doItemsLayout(); @@ -1765,14 +1771,15 @@ void tst_QTreeView::keyboardNavigation() view.setModel(&model); view.show(); - QVector<Qt::Key> keymoves; - keymoves << Qt::Key_Down << Qt::Key_Right << Qt::Key_Right << Qt::Key_Right - << Qt::Key_Down << Qt::Key_Down << Qt::Key_Down << Qt::Key_Down - << Qt::Key_Right << Qt::Key_Right << Qt::Key_Right - << Qt::Key_Left << Qt::Key_Up << Qt::Key_Left << Qt::Key_Left - << Qt::Key_Up << Qt::Key_Down << Qt::Key_Up << 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; + const auto keymoves = { + Qt::Key_Down, Qt::Key_Right, Qt::Key_Right, Qt::Key_Right, + Qt::Key_Down, Qt::Key_Down, Qt::Key_Down, Qt::Key_Down, + Qt::Key_Right, Qt::Key_Right, Qt::Key_Right, + Qt::Key_Left, Qt::Key_Up, Qt::Key_Left, Qt::Key_Left, + Qt::Key_Up, Qt::Key_Down, Qt::Key_Up, 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 row = 0; int column = 0; @@ -1780,8 +1787,7 @@ void tst_QTreeView::keyboardNavigation() view.setCurrentIndex(index); QCOMPARE(view.currentIndex(), index); - for (int i = 0; i < keymoves.size(); ++i) { - Qt::Key key = keymoves.at(i); + for (Qt::Key key : keymoves) { QTest::keyClick(&view, key); switch (key) { @@ -1838,10 +1844,10 @@ void tst_QTreeView::keyboardNavigation() class Dmodel : public QtTestModel { + Q_OBJECT public: - Dmodel() : QtTestModel(10, 10){} - - int columnCount(const QModelIndex &parent) const + using QtTestModel::QtTestModel; + int columnCount(const QModelIndex &parent) const override { if (parent.row() == 5) return 1; @@ -1851,7 +1857,7 @@ public: void tst_QTreeView::headerSections() { - Dmodel model; + Dmodel model(10, 10); QTreeView view; QHeaderView *header = view.header(); @@ -1895,7 +1901,8 @@ void tst_QTreeView::moveCursor() view.setColumnHidden(0, true); QVERIFY(view.isColumnHidden(0)); view.show(); - qApp->setActiveWindow(&view); + QApplication::setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowActive(&view)); //here the first visible index should be selected //because the view got the focus @@ -1938,73 +1945,60 @@ void tst_QTreeView::moveCursor() QCOMPARE(view.currentIndex(), expected); } -class TestDelegate : public QItemDelegate +class TestDelegate : public QStyledItemDelegate { + Q_OBJECT public: - TestDelegate(QObject *parent) : QItemDelegate(parent) {} - QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const { return QSize(200, 50); } + using QStyledItemDelegate::QStyledItemDelegate; + QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const override + { return QSize(200, 50); } }; -typedef QList<QPoint> PointList; +typedef QVector<QPoint> PointList; void tst_QTreeView::setSelection_data() { QTest::addColumn<QRect>("selectionRect"); - QTest::addColumn<int>("selectionMode"); - QTest::addColumn<int>("selectionCommand"); + QTest::addColumn<QAbstractItemView::SelectionMode>("selectionMode"); + QTest::addColumn<QItemSelectionModel::SelectionFlags>("selectionCommand"); QTest::addColumn<PointList>("expectedItems"); QTest::addColumn<int>("verticalOffset"); - QTest::newRow("(0,0,50,20),rows") << QRect(0,0,50,20) - << int(QAbstractItemView::SingleSelection) - << int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows) - << (PointList() - << QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0) - ) - << 0; - - QTest::newRow("(0,0,50,90),rows") << QRect(0,0,50,90) - << int(QAbstractItemView::ExtendedSelection) - << int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows) - << (PointList() - << QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0) - << QPoint(0,1) << QPoint(1,1) << QPoint(2,1) << QPoint(3,1) << QPoint(4,1) - ) - << 0; - - QTest::newRow("(50,0,0,90),rows,invalid rect") << QRect(QPoint(50, 0), QPoint(0, 90)) - << int(QAbstractItemView::ExtendedSelection) - << int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows) - << (PointList() - << QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0) - << QPoint(0,1) << QPoint(1,1) << QPoint(2,1) << QPoint(3,1) << QPoint(4,1) - ) - << 0; - - QTest::newRow("(0,-20,20,50),rows") << QRect(0,-20,20,50) - << int(QAbstractItemView::ExtendedSelection) - << int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows) - << (PointList() - << QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0) - << QPoint(0,1) << QPoint(1,1) << QPoint(2,1) << QPoint(3,1) << QPoint(4,1) - ) - << 1; - QTest::newRow("(0,-50,20,90),rows") << QRect(0,-50,20,90) - << int(QAbstractItemView::ExtendedSelection) - << int(QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows) - << (PointList() - << QPoint(0,0) << QPoint(1,0) << QPoint(2,0) << QPoint(3,0) << QPoint(4,0) - << QPoint(0,1) << QPoint(1,1) << QPoint(2,1) << QPoint(3,1) << QPoint(4,1) - ) - << 1; - + const PointList pl1{QPoint(0, 0), QPoint(1, 0), QPoint(2, 0), QPoint(3, 0), QPoint(4, 0)}; + const PointList pl2{QPoint(0, 0), QPoint(1, 0), QPoint(2, 0), QPoint(3, 0), QPoint(4, 0), + QPoint(0, 1), QPoint(1, 1), QPoint(2, 1), QPoint(3, 1), QPoint(4, 1)}; + const QItemSelectionModel::SelectionFlags selFlags(QItemSelectionModel::ClearAndSelect | + QItemSelectionModel::Rows); + QTest::newRow("(0,0,50,20),rows") + << QRect(0, 0, 50, 20) + << QAbstractItemView::SingleSelection + << selFlags << pl1 << 0; + + QTest::newRow("(0,0,50,90),rows") + << QRect(0, 0, 50, 90) + << QAbstractItemView::ExtendedSelection + << selFlags << pl2 << 0; + + QTest::newRow("(50,0,0,90),rows,invalid rect") + << QRect(QPoint(50, 0), QPoint(0, 90)) + << QAbstractItemView::ExtendedSelection + << selFlags << pl2 << 0; + + QTest::newRow("(0,-20,20,50),rows") + << QRect(0, -20, 20, 50) + << QAbstractItemView::ExtendedSelection + << selFlags << pl2 << 1; + QTest::newRow("(0,-50,20,90),rows") + << QRect(0, -50, 20, 90) + << QAbstractItemView::ExtendedSelection + << selFlags << pl2 << 1; } void tst_QTreeView::setSelection() { QFETCH(QRect, selectionRect); - QFETCH(int, selectionMode); - QFETCH(int, selectionCommand); + QFETCH(QAbstractItemView::SelectionMode, selectionMode); + QFETCH(QItemSelectionModel::SelectionFlags, selectionCommand); QFETCH(PointList, expectedItems); QFETCH(int, verticalOffset); @@ -2016,25 +2010,23 @@ void tst_QTreeView::setSelection() view.show(); view.setRootIsDecorated(false); view.setItemDelegate(new TestDelegate(&view)); - view.setSelectionMode(QAbstractItemView::SelectionMode(selectionMode)); + view.setSelectionMode(selectionMode); view.setModel(&model); view.setUniformRowHeights(true); view.setVerticalScrollMode(QAbstractItemView::ScrollPerItem); view.scrollTo(model.index(verticalOffset, 0), QAbstractItemView::PositionAtTop); - view.setSelection(selectionRect, QItemSelectionModel::SelectionFlags(selectionCommand)); + view.setSelection(selectionRect, selectionCommand); QItemSelectionModel *selectionModel = view.selectionModel(); QVERIFY(selectionModel); - QModelIndexList selectedIndexes = selectionModel->selectedIndexes(); + const QModelIndexList selectedIndexes = selectionModel->selectedIndexes(); #ifdef Q_OS_WINRT QEXPECT_FAIL("(0,-20,20,50),rows", "Fails on WinRT - QTBUG-68297", Abort); QEXPECT_FAIL("(0,-50,20,90),rows", "Fails on WinRT - QTBUG-68297", Abort); #endif QCOMPARE(selectedIndexes.count(), expectedItems.count()); - for (int i = 0; i < selectedIndexes.count(); ++i) { - QModelIndex idx = selectedIndexes.at(i); + for (const QModelIndex &idx : selectedIndexes) QVERIFY(expectedItems.contains(QPoint(idx.column(), idx.row()))); - } } void tst_QTreeView::indexAbove() @@ -2134,7 +2126,7 @@ void tst_QTreeView::clicked() QModelIndex index = view.indexAt(p); if (!index.isValid()) continue; - QSignalSpy spy(&view, SIGNAL(clicked(QModelIndex))); + QSignalSpy spy(&view, &QTreeView::clicked); QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p); QTRY_COMPARE(spy.count(), 1); } @@ -2149,9 +2141,9 @@ void tst_QTreeView::mouseDoubleClick() for (int i = 0; i < model.rowCount(); i++) { QModelIndex index = model.index(i, 0, QModelIndex()); model.insertRows(0, 20, index); - model.insertColumns(0,2,index); + model.insertColumns(0, 2,index); for (int i1 = 0; i1 < model.rowCount(index); i1++) { - (void)model.index(i1, 0, index); + QVERIFY(model.index(i1, 0, index).isValid()); } } @@ -2159,8 +2151,8 @@ void tst_QTreeView::mouseDoubleClick() view.setModel(&model); // make sure the viewport height is smaller than the contents height. - view.resize(200,200); - view.move(0,0); + view.resize(200, 200); + view.move(0, 0); view.show(); QModelIndex index = model.index(0, 0, QModelIndex()); view.setCurrentIndex(index); @@ -2170,9 +2162,8 @@ void tst_QTreeView::mouseDoubleClick() view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); // Make sure all items are collapsed - for (int i = 0; i < model.rowCount(QModelIndex()); i++) { - view.setExpanded(model.index(i,0, QModelIndex()), false); - } + for (int i = 0; i < model.rowCount(QModelIndex()); i++) + view.setExpanded(model.index(i, 0, QModelIndex()), false); int maximum = view.verticalScrollBar()->maximum(); @@ -2210,14 +2201,13 @@ void tst_QTreeView::rowsAboutToBeRemoved() view.setCurrentIndex(index); view.setExpanded(model.index(0,0, QModelIndex()), true); - for (int i = 0; i < model.rowCount(QModelIndex()); i++) { - view.setExpanded(model.index(i,0, QModelIndex()), true); - } + for (int i = 0; i < model.rowCount(QModelIndex()); i++) + view.setExpanded(model.index(i, 0, QModelIndex()), true); - QSignalSpy spy1(&model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int))); + QSignalSpy spy1(&model, &QAbstractItemModel::rowsAboutToBeRemoved); model.removeRows(1,1); - QCOMPARE(int(view.state()), 0); + QCOMPARE((view.state()), 0); // Should not be 5 (or any other number for that sake :) QCOMPARE(spy1.count(), 1); @@ -2241,8 +2231,7 @@ void tst_QTreeView::headerSections_unhideSection() void tst_QTreeView::columnAt() { - QtTestModel model; - model.rows = model.cols = 10; + QtTestModel model(10, 10); QTreeView view; view.resize(500,500); view.setModel(&model); @@ -2256,8 +2245,7 @@ void tst_QTreeView::scrollTo() #define CHECK_VISIBLE(ROW,COL) QVERIFY(QRect(QPoint(),view.viewport()->size()).contains(\ view.visualRect(model.index((ROW),(COL),QModelIndex())))) - QtTestModel model; - model.rows = model.cols = 100; + QtTestModel model(100, 100); QTreeView view; view.setUniformRowHeights(true); view.scrollTo(QModelIndex(), QTreeView::PositionAtTop); @@ -2268,19 +2256,18 @@ void tst_QTreeView::scrollTo() // ### create a data function for this test view.scrollTo(QModelIndex()); - view.scrollTo(model.index(0,0,QModelIndex())); - view.scrollTo(model.index(0,0,QModelIndex()), QTreeView::PositionAtTop); - view.scrollTo(model.index(0,0,QModelIndex()), QTreeView::PositionAtBottom); - - // + view.scrollTo(model.index(0, 0, QModelIndex())); + view.scrollTo(model.index(0, 0, QModelIndex()), QTreeView::PositionAtTop); + view.scrollTo(model.index(0, 0, QModelIndex()), QTreeView::PositionAtBottom); view.show(); view.setVerticalScrollMode(QAbstractItemView::ScrollPerItem); //some styles change that in Polish - view.resize(300, 200); + + QVERIFY(QTest::qWaitForWindowExposed(&view)); //view.verticalScrollBar()->setValue(0); - view.scrollTo(model.index(0,0,QModelIndex())); + view.scrollTo(model.index(0, 0, QModelIndex())); CHECK_VISIBLE(0,0); QCOMPARE(view.verticalScrollBar()->value(), 0); @@ -2305,22 +2292,23 @@ void tst_QTreeView::rowsAboutToBeRemoved_move() QTreeView view; view.setModel(&model); QModelIndex indexThatWantsToLiveButWillDieDieITellYou; - QModelIndex parent = model.index(2, 0 ); + QModelIndex parent = model.index(2, 0); view.expand(parent); for (int i = 0; i < 6; ++i) { model.insertRows(0, 1, parent); model.insertColumns(0, 1, parent); QModelIndex index = model.index(0, 0, parent); view.expand(index); - if ( i == 3 ) + if (i == 3) indexThatWantsToLiveButWillDieDieITellYou = index; model.setData(index, i); parent = index; } view.resize(600,800); view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); view.doItemsLayout(); - static_cast<QTreeView *>(&view)->executeDelayedItemsLayout(); + view.executeDelayedItemsLayout(); parent = indexThatWantsToLiveButWillDieDieITellYou.parent(); QCOMPARE(view.isExpanded(indexThatWantsToLiveButWillDieDieITellYou), true); QCOMPARE(parent.isValid(), true); @@ -2354,7 +2342,8 @@ void tst_QTreeView::resizeColumnToContents() QTreeView view; view.setModel(&model); view.show(); - qApp->processEvents(); //must have this, or else it will not scroll + QVERIFY(QTest::qWaitForWindowExposed(&view)); + view.scrollToBottom(); view.resizeColumnToContents(0); int oldColumnSize = view.header()->sectionSize(0); @@ -2365,11 +2354,12 @@ void tst_QTreeView::resizeColumnToContents() void tst_QTreeView::insertAfterSelect() { - QtTestModel model; - model.rows = model.cols = 10; + QtTestModel model(10, 10); QTreeView view; view.setModel(&model); view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + QModelIndex firstIndex = model.index(0, 0, QModelIndex()); QVERIFY(firstIndex.isValid()); int itemOffset = view.visualRect(firstIndex).width() / 2; @@ -2382,11 +2372,12 @@ void tst_QTreeView::insertAfterSelect() void tst_QTreeView::removeAfterSelect() { - QtTestModel model; - model.rows = model.cols = 10; + QtTestModel model(10, 10); QTreeView view; view.setModel(&model); view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + QModelIndex firstIndex = model.index(0, 0, QModelIndex()); QVERIFY(firstIndex.isValid()); int itemOffset = view.visualRect(firstIndex).width() / 2; @@ -2399,17 +2390,17 @@ void tst_QTreeView::removeAfterSelect() void tst_QTreeView::hiddenItems() { - QtTestModel model; - model.rows = model.cols = 10; + QtTestModel model(10, 10); QTreeView view; view.setModel(&model); view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QModelIndex firstIndex = model.index(1, 0, QModelIndex()); QVERIFY(firstIndex.isValid()); if (model.canFetchMore(firstIndex)) model.fetchMore(firstIndex); - for (int i=0; i < model.rowCount(firstIndex); i++) + for (int i = 0; i < model.rowCount(firstIndex); i++) view.setRowHidden(i , firstIndex, true ); int itemOffset = view.visualRect(firstIndex).width() / 2; @@ -2419,18 +2410,18 @@ void tst_QTreeView::hiddenItems() QTest::mouseDClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p); QCOMPARE(view.isExpanded(firstIndex), false); - p.setX( 5 ); + p.setX(5); QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, p); QCOMPARE(view.isExpanded(firstIndex), false); } void tst_QTreeView::spanningItems() { - QtTestModel model; - model.rows = model.cols = 10; + QtTestModel model(10, 10); QTreeView view; view.setModel(&model); view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); int itemWidth = view.header()->sectionSize(0); int itemHeight = view.visualRect(model.index(0, 0, QModelIndex())).height(); @@ -2470,7 +2461,7 @@ void tst_QTreeView::spanningItems() void tst_QTreeView::selectionOrderTest() { - QVERIFY(((QItemSelectionModel*)sender())->currentIndex().row() != -1); + QVERIFY(static_cast<QItemSelectionModel*>(sender())->currentIndex().row() != -1); } void tst_QTreeView::selection() @@ -2489,12 +2480,11 @@ void tst_QTreeView::selection() treeView.setSelectionBehavior(QAbstractItemView::SelectRows); treeView.setSelectionMode(QAbstractItemView::ExtendedSelection); - connect(treeView.selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - this, SLOT(selectionOrderTest())); - - treeView.show(); + connect(treeView.selectionModel(), &QItemSelectionModel::selectionChanged, + this, &tst_QTreeView::selectionOrderTest); - QTest::mousePress(treeView.viewport(), Qt::LeftButton, 0, treeView.visualRect(m.index(1, 0)).center()); + QTest::mousePress(treeView.viewport(), Qt::LeftButton, {}, + treeView.visualRect(m.index(1, 0)).center()); QTest::keyPress(treeView.viewport(), Qt::Key_Down); auto selectedRows = treeView.selectionModel()->selectedRows(); QCOMPARE(selectedRows.size(), 1); @@ -2509,23 +2499,21 @@ void tst_QTreeView::selection() void tst_QTreeView::selectionWithHiddenItems() { QStandardItemModel model; - for (int i = 0; i < model.rowCount(); ++i) - model.setData(model.index(i,0), QLatin1String("row ") + QString::number(i)); QStandardItem item0("row 0"); QStandardItem item1("row 1"); QStandardItem item2("row 2"); QStandardItem item3("row 3"); - model.appendColumn( QList<QStandardItem*>() << &item0 << &item1 << &item2 << &item3); + model.appendColumn({&item0, &item1, &item2, &item3}); QStandardItem child("child"); - item1.appendRow( &child); + item1.appendRow(&child); QTreeView view; view.setModel(&model); view.setSelectionMode(QAbstractItemView::ExtendedSelection); view.show(); - qApp->processEvents(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); //child should not be selected as it is hidden (its parent is not expanded) view.selectAll(); @@ -2548,12 +2536,11 @@ void tst_QTreeView::selectionWithHiddenItems() //we hide the node with a child (there should then be 3 items selected in 2 ranges) view.setRowHidden(1, QModelIndex(), true); QVERIFY(view.isExpanded(item1.index())); - qApp->processEvents(); view.selectAll(); QCOMPARE(view.selectionModel()->selection().count(), 2); QCOMPARE(view.selectionModel()->selectedRows().count(), 3); - QVERIFY( !view.selectionModel()->isSelected(model.indexFromItem(&item1))); - QVERIFY( !view.selectionModel()->isSelected(model.indexFromItem(&child))); + QVERIFY(!view.selectionModel()->isSelected(model.indexFromItem(&item1))); + QVERIFY(!view.selectionModel()->isSelected(model.indexFromItem(&child))); view.setRowHidden(1, QModelIndex(), false); QVERIFY(view.isExpanded(item1.index())); @@ -2561,7 +2548,6 @@ void tst_QTreeView::selectionWithHiddenItems() //we hide a node without children (there should then be 4 items selected in 3 ranges) view.setRowHidden(2, QModelIndex(), true); - qApp->processEvents(); QVERIFY(view.isExpanded(item1.index())); view.selectAll(); QVERIFY(view.isExpanded(item1.index())); @@ -2575,7 +2561,7 @@ void tst_QTreeView::selectionWithHiddenItems() void tst_QTreeView::selectAll() { - QStandardItemModel model(4,4); + QStandardItemModel model(4, 4); QTreeView view2; view2.setModel(&model); view2.setSelectionMode(QAbstractItemView::ExtendedSelection); @@ -2619,7 +2605,8 @@ void tst_QTreeView::extendedSelection() view.setModel(&model); view.setSelectionMode(QAbstractItemView::ExtendedSelection); topLevel.show(); - QTest::mousePress(view.viewport(), Qt::LeftButton, 0, mousePressPos); + QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); + QTest::mousePress(view.viewport(), Qt::LeftButton, {}, mousePressPos); QCOMPARE(view.selectionModel()->selectedIndexes().count(), selectedCount); } @@ -2627,21 +2614,22 @@ void tst_QTreeView::rowSizeHint() { //tests whether the correct visible columns are taken into account when //calculating the height of a line - QStandardItemModel model(1,3); - model.setData( model.index(0,0), QSize(20,40), Qt::SizeHintRole); - model.setData( model.index(0,1), QSize(20,10), Qt::SizeHintRole); - model.setData( model.index(0,2), QSize(20,10), Qt::SizeHintRole); + QStandardItemModel model(1, 3); + model.setData(model.index(0, 0), QSize(20, 40), Qt::SizeHintRole); + model.setData(model.index(0, 1), QSize(20, 10), Qt::SizeHintRole); + model.setData(model.index(0, 2), QSize(20, 10), Qt::SizeHintRole); QTreeView view; view.setModel(&model); view.header()->moveSection(1, 0); //the 2nd column goes to the 1st place view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); //it must be 40 since the tallest item that defines the height of a line - QCOMPARE( view.visualRect(model.index(0,0)).height(), 40); - QCOMPARE( view.visualRect(model.index(0,1)).height(), 40); - QCOMPARE( view.visualRect(model.index(0,2)).height(), 40); + QCOMPARE(view.visualRect(model.index(0,0)).height(), 40); + QCOMPARE(view.visualRect(model.index(0,1)).height(), 40); + QCOMPARE(view.visualRect(model.index(0,2)).height(), 40); } @@ -2651,7 +2639,7 @@ void tst_QTreeView::rowSizeHint() void tst_QTreeView::setSortingEnabledTopLevel() { QTreeView view; - QStandardItemModel model(1,1); + QStandardItemModel model(1, 1); view.setModel(&model); const int size = view.header()->sectionSize(0); view.setSortingEnabled(true); @@ -2665,7 +2653,7 @@ void tst_QTreeView::setSortingEnabledChild() QMainWindow win; QTreeView view; // two columns to not get in trouble with stretchLastSection - QStandardItemModel model(1,2); + QStandardItemModel model(1, 2); view.setModel(&model); view.header()->setDefaultSectionSize(92); win.setCentralWidget(&view); @@ -2690,16 +2678,18 @@ void tst_QTreeView::headerHidden() class TestTreeViewStyle : public QProxyStyle { + Q_OBJECT public: - TestTreeViewStyle() : indentation(20) {} - int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const override + using QProxyStyle::QProxyStyle; + int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr, + const QWidget *widget = nullptr) const override { if (metric == QStyle::PM_TreeViewIndentation) return indentation; else return QProxyStyle::pixelMetric(metric, option, widget); } - int indentation; + int indentation = 20; }; void tst_QTreeView::indentation() @@ -2745,7 +2735,7 @@ void tst_QTreeView::removeAndInsertExpandedCol0() model.insertColumns(0, 1); view.show(); - qApp->processEvents(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); } void tst_QTreeView::disabledButCheckable() @@ -2782,7 +2772,7 @@ void tst_QTreeView::sortByColumn() { QFETCH(bool, sortingEnabled); QTreeView view; - QStandardItemModel model(4,2); + QStandardItemModel model(4, 2); QSortFilterProxyModel sfpm; // default QStandardItemModel does not support 'unsorted' state sfpm.setSourceModel(&model); model.setItem(0, 0, new QStandardItem("b")); @@ -2825,11 +2815,13 @@ void tst_QTreeView::sortByColumn() */ class EvilModel: public QAbstractItemModel { - + Q_OBJECT public: - class Node { + class Node + { public: - Node(Node *p = 0, int level = 0) : parent(p), isDead(false) { + Node(Node *p = nullptr, int level = 0) : parent(p) + { populate(level); } ~Node() @@ -2838,20 +2830,23 @@ public: qDeleteAll(deadChildren.begin(), deadChildren.end()); } - void populate(int level = 0) { - if (level < 4) + void populate(int level = 0) + { + if (level < 4) { for (int i = 0; i < 5; ++i) children.append(new Node(this, level + 1)); + } } - void kill() { + void kill() + { for (int i = children.count() -1; i >= 0; --i) { children.at(i)->kill(); - if (parent == 0) { + if (parent == nullptr) { deadChildren.append(children.at(i)); children.removeAt(i); } } - if (parent == 0) { + if (parent == nullptr) { if (!children.isEmpty()) qFatal("%s: children should be empty when parent is null", Q_FUNC_INFO); populate(); @@ -2860,17 +2855,16 @@ public: } } - QList<Node*> children; - QList<Node*> deadChildren; + QVector<Node *> children; + QVector<Node *> deadChildren; Node *parent; - bool isDead; + bool isDead = false; }; Node *root; - EvilModel(QObject *parent = 0): QAbstractItemModel(parent), root(new Node) - { - } + EvilModel(QObject *parent = nullptr): QAbstractItemModel(parent), root(new Node) + {} ~EvilModel() { delete root; @@ -2880,7 +2874,7 @@ public: { emit layoutAboutToBeChanged(); QModelIndexList oldList = persistentIndexList(); - QList<QStack<int> > oldListPath; + QVector<QStack<int>> oldListPath; for (int i = 0; i < oldList.count(); ++i) { QModelIndex idx = oldList.at(i); QStack<int> path; @@ -2893,12 +2887,10 @@ public: root->kill(); QModelIndexList newList; - for (int i = 0; i < oldListPath.count(); ++i) { - QStack<int> path = oldListPath[i]; + for (auto path : qAsConst(oldListPath)) { QModelIndex idx; - while(!path.isEmpty()) { + while (!path.isEmpty()) idx = index(path.pop(), 0, idx); - } newList.append(idx); } @@ -2906,7 +2898,8 @@ public: emit layoutChanged(); } - int rowCount(const QModelIndex& parent = QModelIndex()) const { + int rowCount(const QModelIndex &parent = QModelIndex()) const override + { Node *parentNode = root; if (parent.isValid()) { parentNode = static_cast<Node*>(parent.internalPointer()); @@ -2915,13 +2908,12 @@ public: } return parentNode->children.count(); } - int columnCount(const QModelIndex& parent = QModelIndex()) const { - if (parent.column() > 0) - return 0; - return 1; + int columnCount(const QModelIndex &parent = QModelIndex()) const override + { + return parent.column() > 0 ? 0 : 1; } - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override { Node *grandparentNode = static_cast<Node*>(parent.internalPointer()); Node *parentNode = root; @@ -2935,7 +2927,7 @@ public: return createIndex(row, column, parentNode); } - QModelIndex parent(const QModelIndex &index) const + QModelIndex parent(const QModelIndex &index) const override { Node *parent = static_cast<Node*>(index.internalPointer()); Node *grandparent = parent->parent; @@ -2944,7 +2936,7 @@ public: return createIndex(grandparent->children.indexOf(parent), 0, grandparent); } - QVariant data(const QModelIndex &idx, int role) const + QVariant data(const QModelIndex &idx, int role) const override { if (idx.isValid() && role == Qt::DisplayRole) { Node *parentNode = root; @@ -2987,7 +2979,6 @@ void tst_QTreeView::evilModel() view.setRowHidden(0, firstLevel, true); model.change(); - return; view.setFirstColumnSpanned(1, QModelIndex(), true); model.change(); @@ -3167,7 +3158,7 @@ void tst_QTreeView::filterProxyModelCrash() QTreeView view; view.setModel(&proxy); view.show(); - QTest::qWait(30); + QVERIFY(QTest::qWaitForWindowExposed(&view)); proxy.invalidate(); view.verticalScrollBar()->setValue(15); QTest::qWait(20); @@ -3190,7 +3181,7 @@ void tst_QTreeView::renderToPixmap() QStandardItemModel model; model.appendRow(new QStandardItem("Spanning")); - model.appendRow(QList<QStandardItem*>() << new QStandardItem("Not") << new QStandardItem("Spanning")); + model.appendRow({ new QStandardItem("Not"), new QStandardItem("Spanning") }); view.setModel(&model); view.setFirstColumnSpanned(0, QModelIndex(), true); @@ -3211,57 +3202,60 @@ void tst_QTreeView::styleOptionViewItem() { class MyDelegate : public QStyledItemDelegate { - static QString posToString(QStyleOptionViewItem::ViewItemPosition pos) { + static QString posToString(QStyleOptionViewItem::ViewItemPosition pos) + { static const char* s_pos[] = { "Invalid", "Beginning", "Middle", "End", "OnlyOne" }; return s_pos[pos]; } public: - MyDelegate() - : QStyledItemDelegate(), - count(0), - allCollapsed(false) - {} - - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const - { - QStyleOptionViewItem opt(option); - initStyleOption(&opt, index); + using QStyledItemDelegate::QStyledItemDelegate; + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const override + { + QStyleOptionViewItem opt(option); + initStyleOption(&opt, index); - QVERIFY(!opt.text.isEmpty()); - QCOMPARE(opt.index, index); - //qDebug() << index << opt.text; + QVERIFY(!opt.text.isEmpty()); + QCOMPARE(opt.index, index); + //qDebug() << index << opt.text; - if (allCollapsed) - QCOMPARE(!(opt.features & QStyleOptionViewItem::Alternate), !(index.row() % 2)); - QCOMPARE(!(opt.features & QStyleOptionViewItem::HasCheckIndicator), !opt.text.contains("Checkable")); + if (allCollapsed) { + QCOMPARE(!opt.features.testFlag(QStyleOptionViewItem::Alternate), + !(index.row() % 2)); + } + QCOMPARE(!opt.features.testFlag(QStyleOptionViewItem::HasCheckIndicator), + !opt.text.contains("Checkable")); - if (opt.text.contains("Beginning")) - QCOMPARE(posToString(opt.viewItemPosition), posToString(QStyleOptionViewItem::Beginning)); + const QString posStr(posToString(opt.viewItemPosition)); + if (opt.text.contains("Beginning")) + QCOMPARE(posStr, posToString(QStyleOptionViewItem::Beginning)); - if (opt.text.contains("Middle")) - QCOMPARE(posToString(opt.viewItemPosition), posToString(QStyleOptionViewItem::Middle)); + if (opt.text.contains("Middle")) + QCOMPARE(posStr, posToString(QStyleOptionViewItem::Middle)); - if (opt.text.contains("End")) - QCOMPARE(posToString(opt.viewItemPosition), posToString(QStyleOptionViewItem::End)); + if (opt.text.contains("End")) + QCOMPARE(posStr, posToString(QStyleOptionViewItem::End)); - if (opt.text.contains("OnlyOne")) - QCOMPARE(posToString(opt.viewItemPosition), posToString(QStyleOptionViewItem::OnlyOne)); + if (opt.text.contains("OnlyOne")) + QCOMPARE(posStr, posToString(QStyleOptionViewItem::OnlyOne)); - if (opt.text.contains("Checked")) - QCOMPARE(opt.checkState, Qt::Checked); - else - QCOMPARE(opt.checkState, Qt::Unchecked); + if (opt.text.contains("Checked")) + QCOMPARE(opt.checkState, Qt::Checked); + else + QCOMPARE(opt.checkState, Qt::Unchecked); - QCOMPARE(!(opt.state & QStyle::State_Children) , !opt.text.contains("HasChildren")); - QCOMPARE(!!(opt.state & QStyle::State_Sibling) , !opt.text.contains("Last")); + QCOMPARE(!opt.state.testFlag(QStyle::State_Children), + !opt.text.contains("HasChildren")); + QCOMPARE(opt.state.testFlag(QStyle::State_Sibling), + !opt.text.contains("Last")); - QVERIFY(!opt.text.contains("Assert")); + QVERIFY(!opt.text.contains("Assert")); - QStyledItemDelegate::paint(painter, option, index); - count++; - } - mutable int count; - bool allCollapsed; + QStyledItemDelegate::paint(painter, option, index); + count++; + } + mutable int count = 0; + bool allCollapsed = false; }; QTreeView view; @@ -3269,39 +3263,68 @@ void tst_QTreeView::styleOptionViewItem() view.setModel(&model); MyDelegate delegate; view.setItemDelegate(&delegate); - model.appendRow(QList<QStandardItem*>() - << new QStandardItem("Beginning") << new QStandardItem("Hidden") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") ); + model.appendRow({ new QStandardItem("Beginning"), + new QStandardItem("Hidden"), + new QStandardItem("Middle"), + new QStandardItem("Middle"), + new QStandardItem("End") }); QStandardItem *par1 = new QStandardItem("Beginning HasChildren"); - model.appendRow(QList<QStandardItem*>() - << par1 << new QStandardItem("Hidden") << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") ); - model.appendRow(QList<QStandardItem*>() - << new QStandardItem("OnlyOne") << new QStandardItem("Hidden") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Assert") ); + model.appendRow({ par1, + new QStandardItem("Hidden"), + new QStandardItem("Middle HasChildren"), + new QStandardItem("Middle HasChildren"), + new QStandardItem("End HasChildren") }); + model.appendRow({ new QStandardItem("OnlyOne"), + new QStandardItem("Hidden"), + new QStandardItem("Assert"), + new QStandardItem("Assert"), + new QStandardItem("Assert") }); QStandardItem *checkable = new QStandardItem("Checkable"); checkable->setCheckable(true); QStandardItem *checked = new QStandardItem("Checkable Checked"); checked->setCheckable(true); checked->setCheckState(Qt::Checked); - model.appendRow(QList<QStandardItem*>() - << new QStandardItem("Beginning") << new QStandardItem("Hidden") << checkable << checked << new QStandardItem("End") ); - model.appendRow(QList<QStandardItem*>() - << new QStandardItem("Beginning Last") << new QStandardItem("Hidden") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") ); - - par1->appendRow(QList<QStandardItem*>() - << new QStandardItem("Beginning") << new QStandardItem("Hidden") << new QStandardItem("Middle") << new QStandardItem("Middle") << new QStandardItem("End") ); + model.appendRow({ new QStandardItem("Beginning"), + new QStandardItem("Hidden"), + checkable, checked, + new QStandardItem("End") }); + model.appendRow({ new QStandardItem("Beginning Last"), + new QStandardItem("Hidden"), + new QStandardItem("Middle Last"), + new QStandardItem("Middle Last"), + new QStandardItem("End Last") }); + par1->appendRow({ new QStandardItem("Beginning"), + new QStandardItem("Hidden"), + new QStandardItem("Middle"), + new QStandardItem("Middle"), + new QStandardItem("End") }); QStandardItem *par2 = new QStandardItem("Beginning HasChildren"); - par1->appendRow(QList<QStandardItem*>() - << par2 << new QStandardItem("Hidden") << new QStandardItem("Middle HasChildren") << new QStandardItem("Middle HasChildren") << new QStandardItem("End HasChildren") ); - par2->appendRow(QList<QStandardItem*>() - << new QStandardItem("Beginning Last") << new QStandardItem("Hidden") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") ); - + par1->appendRow({ par2, + new QStandardItem("Hidden"), + new QStandardItem("Middle HasChildren"), + new QStandardItem("Middle HasChildren"), + new QStandardItem("End HasChildren") }); + par2->appendRow({ new QStandardItem("Beginning Last"), + new QStandardItem("Hidden"), + new QStandardItem("Middle Last"), + new QStandardItem("Middle Last"), + new QStandardItem("End Last") }); QStandardItem *par3 = new QStandardItem("Beginning Last"); - par1->appendRow(QList<QStandardItem*>() - << par3 << new QStandardItem("Hidden") << new QStandardItem("Middle Last") << new QStandardItem("Middle Last") << new QStandardItem("End Last") ); - par3->appendRow(QList<QStandardItem*>() - << new QStandardItem("Assert") << new QStandardItem("Hidden") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") ); + par1->appendRow({ par3, new QStandardItem("Hidden"), + new QStandardItem("Middle Last"), + new QStandardItem("Middle Last"), + new QStandardItem("End Last") }); + par3->appendRow({ new QStandardItem("Assert"), + new QStandardItem("Hidden"), + new QStandardItem("Assert"), + new QStandardItem("Assert"), + new QStandardItem("Asser") }); view.setRowHidden(0, par3->index(), true); - par1->appendRow(QList<QStandardItem*>() - << new QStandardItem("Assert") << new QStandardItem("Hidden") << new QStandardItem("Assert") << new QStandardItem("Assert") << new QStandardItem("Asser") ); + par1->appendRow({ new QStandardItem("Assert"), + new QStandardItem("Hidden"), + new QStandardItem("Assert"), + new QStandardItem("Assert"), + new QStandardItem("Asser") }); view.setRowHidden(3, par1->index(), true); view.setColumnHidden(1, true); @@ -3331,16 +3354,14 @@ void tst_QTreeView::styleOptionViewItem() delegate.count = 0; delegate.allCollapsed = true; view.showMaximized(); - QApplication::processEvents(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_VERIFY(delegate.count >= 13); delegate.count = 0; delegate.allCollapsed = false; view.expandAll(); - QApplication::processEvents(); QTRY_VERIFY(delegate.count >= 13); delegate.count = 0; view.collapse(par2->index()); - QApplication::processEvents(); QTRY_VERIFY(delegate.count >= 4); // test that the rendering of drag pixmap sets the correct options too (QTBUG-15834) @@ -3360,96 +3381,73 @@ void tst_QTreeView::styleOptionViewItem() delegate.count = 0; QStandardItemModel model2; QStandardItem *item0 = new QStandardItem("OnlyOne Last"); - model2.appendRow(QList<QStandardItem*>() << item0); + model2.appendRow(item0); view.setModel(&model2); - QApplication::processEvents(); QTRY_VERIFY(delegate.count >= 1); - QApplication::processEvents(); QStandardItem *item00 = new QStandardItem("OnlyOne Last"); - item0->appendRow(QList<QStandardItem*>() << item00); + item0->appendRow(item00); item0->setText("OnlyOne Last HasChildren"); - QApplication::processEvents(); delegate.count = 0; view.expandAll(); - QApplication::processEvents(); QTRY_VERIFY(delegate.count >= 2); - QApplication::processEvents(); QStandardItem *item1 = new QStandardItem("OnlyOne Last"); delegate.count = 0; item0->setText("OnlyOne HasChildren"); - model2.appendRow(QList<QStandardItem*>() << item1); - QApplication::processEvents(); + model2.appendRow(item1); QTRY_VERIFY(delegate.count >= 3); - QApplication::processEvents(); QStandardItem *item01 = new QStandardItem("OnlyOne Last"); delegate.count = 0; item00->setText("OnlyOne"); - item0->appendRow(QList<QStandardItem*>() << item01); - QApplication::processEvents(); + item0->appendRow(item01); QTRY_VERIFY(delegate.count >= 4); - QApplication::processEvents(); QStandardItem *item000 = new QStandardItem("OnlyOne Last"); delegate.count = 0; item00->setText("OnlyOne HasChildren"); - item00->appendRow(QList<QStandardItem*>() << item000); - QApplication::processEvents(); + item00->appendRow(item000); QTRY_VERIFY(delegate.count >= 5); - QApplication::processEvents(); delegate.count = 0; item0->removeRow(0); - QApplication::processEvents(); QTRY_VERIFY(delegate.count >= 3); - QApplication::processEvents(); item00 = new QStandardItem("OnlyOne"); - item0->insertRow(0, QList<QStandardItem*>() << item00); - QApplication::processEvents(); + item0->insertRow(0, item00); + delegate.count = 0; view.expandAll(); - QApplication::processEvents(); QTRY_VERIFY(delegate.count >= 4); - QApplication::processEvents(); delegate.count = 0; item0->removeRow(1); item00->setText("OnlyOne Last"); - QApplication::processEvents(); QTRY_VERIFY(delegate.count >= 3); - QApplication::processEvents(); delegate.count = 0; item0->removeRow(0); item0->setText("OnlyOne"); - QApplication::processEvents(); QTRY_VERIFY(delegate.count >= 2); - QApplication::processEvents(); //with hidden items item0->setText("OnlyOne HasChildren"); item00 = new QStandardItem("OnlyOne"); - item0->appendRow(QList<QStandardItem*>() << item00); + item0->appendRow(item00); item01 = new QStandardItem("Assert"); - item0->appendRow(QList<QStandardItem*>() << item01); + item0->appendRow(item01); view.setRowHidden(1, item0->index(), true); view.expandAll(); QStandardItem *item02 = new QStandardItem("OnlyOne Last"); - item0->appendRow(QList<QStandardItem*>() << item02); + item0->appendRow(item02); delegate.count = 0; - QApplication::processEvents(); QTRY_VERIFY(delegate.count >= 4); - QApplication::processEvents(); item0->removeRow(2); item00->setText("OnlyOne Last"); delegate.count = 0; - QApplication::processEvents(); QTRY_VERIFY(delegate.count >= 3); - QApplication::processEvents(); item00->setText("OnlyOne"); item0->insertRow(2, new QStandardItem("OnlyOne Last")); @@ -3457,13 +3455,11 @@ void tst_QTreeView::styleOptionViewItem() item0->removeRow(0); delegate.count = 0; QTRY_VERIFY(delegate.count >= 2); - QApplication::processEvents(); item0->removeRow(1); item0->setText("OnlyOne"); delegate.count = 0; QTRY_VERIFY(delegate.count >= 2); - QApplication::processEvents(); } } @@ -3471,10 +3467,10 @@ class task174627_TreeView : public QTreeView { Q_OBJECT protected slots: - void currentChanged(const QModelIndex ¤t, const QModelIndex &) - { emit currentChanged(current); } + void currentChanged(const QModelIndex ¤t, const QModelIndex &) override + { emit signalCurrentChanged(current); } signals: - void currentChanged(const QModelIndex &); + void signalCurrentChanged(const QModelIndex &); }; void tst_QTreeView::task174627_moveLeftToRoot() @@ -3490,7 +3486,7 @@ void tst_QTreeView::task174627_moveLeftToRoot() view.setRootIndex(item1->index()); view.setCurrentIndex(item2->index()); - QSignalSpy spy(&view, SIGNAL(currentChanged(QModelIndex))); + QSignalSpy spy(&view, &task174627_TreeView::signalCurrentChanged); QTest::keyClick(&view, Qt::Key_Left); QCOMPARE(spy.count(), 0); } @@ -3503,9 +3499,9 @@ void tst_QTreeView::task171902_expandWith1stColHidden() subitem("subitem"), subitem2("subitem"), subsubitem("subsubitem"), subsubitem2("subsubitem"); - model.appendRow( QList<QStandardItem *>() << &root << &root2); - root.appendRow( QList<QStandardItem *>() << &subitem << &subitem2); - subitem.appendRow( QList<QStandardItem *>() << &subsubitem << &subsubitem2); + model.appendRow({ &root, &root2 }); + root.appendRow({ &subitem, &subitem2 }); + subitem.appendRow({ &subsubitem, &subsubitem2 }); QTreeView view; view.setModel(&model); @@ -3523,18 +3519,18 @@ void tst_QTreeView::task171902_expandWith1stColHidden() void tst_QTreeView::task203696_hidingColumnsAndRowsn() { QTreeView view; - QStandardItemModel *model = new QStandardItemModel(0, 3, &view); + QStandardItemModel model(0, 3); for (int i = 0; i < 3; ++i) { const QString prefix = QLatin1String("row ") + QString::number(i) + QLatin1String(" col "); - model->insertRow(model->rowCount()); - for (int j = 0; j < model->columnCount(); ++j) - model->setData(model->index(i, j), prefix + QString::number(j)); + model.insertRow(model.rowCount()); + for (int j = 0; j < model.columnCount(); ++j) + model.setData(model.index(i, j), prefix + QString::number(j)); } - view.setModel(model); + view.setModel(&model); view.show(); view.setColumnHidden(0, true); view.setRowHidden(0, QModelIndex(), true); - QCOMPARE(view.indexAt(QPoint(0, 0)), model->index(1, 1)); + QCOMPARE(view.indexAt(QPoint(0, 0)), model.index(1, 1)); } @@ -3547,27 +3543,23 @@ void tst_QTreeView::addRowsWhileSectionsAreHidden() view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); - int i; - for (i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) { model->insertRow(model->rowCount()); const QString prefix = QLatin1String("row ") + QString::number(i) + QLatin1String(" col "); - for (int j = 0; j < model->columnCount(); ++j) { + for (int j = 0; j < model->columnCount(); ++j) model->setData(model->index(i, j), prefix + QString::number(j)); - } } - int col; - for (col = 0; col < pass; ++col) + for (int col = 0; col < pass; ++col) view.setColumnHidden(col, true); - for (i = 3; i < 6; ++i) + for (int i = 3; i < 6; ++i) { model->insertRow(model->rowCount()); const QString prefix = QLatin1String("row ") + QString::number(i) + QLatin1String(" col "); - for (int j = 0; j < model->columnCount(); ++j) { + for (int j = 0; j < model->columnCount(); ++j) model->setData(model->index(i, j), prefix + QString::number(j)); - } } - for (col = 0; col < pass; ++col) + for (int col = 0; col < pass; ++col) view.setColumnHidden(col, false); auto allVisualRectsValid = [](QTreeView *view, QStandardItemModel *model) { @@ -3585,24 +3577,25 @@ void tst_QTreeView::addRowsWhileSectionsAreHidden() void tst_QTreeView::task216717_updateChildren() { - class Tree : public QTreeWidget { + class Tree : public QTreeWidget + { protected: - void paintEvent(QPaintEvent *e) + void paintEvent(QPaintEvent *e) override { QTreeWidget::paintEvent(e); - refreshed=true; + refreshed = true; } public: - bool refreshed; + bool refreshed = false; } tree; tree.show(); QVERIFY(QTest::qWaitForWindowExposed(&tree)); tree.refreshed = false; - QTreeWidgetItem *parent = new QTreeWidgetItem(QStringList() << "parent"); + QTreeWidgetItem *parent = new QTreeWidgetItem({ "parent" }); tree.addTopLevelItem(parent); QTRY_VERIFY(tree.refreshed); tree.refreshed = false; - parent->addChild(new QTreeWidgetItem(QStringList() << "child")); + parent->addChild(new QTreeWidgetItem({ "child" })); QTRY_VERIFY(tree.refreshed); } @@ -3611,13 +3604,14 @@ void tst_QTreeView::task220298_selectColumns() { //this is a very simple 3x3 model where the internalId of the index are different for each cell class Model : public QAbstractTableModel - { public: - virtual int columnCount ( const QModelIndex & parent = QModelIndex() ) const + { + public: + int columnCount(const QModelIndex & parent = QModelIndex()) const override { return parent.isValid() ? 0 : 3; } - virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const + int rowCount(const QModelIndex & parent = QModelIndex()) const override { return parent.isValid() ? 0 : 3; } - virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const + QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override { if (role == Qt::DisplayRole) { return QVariant(QString::number(index.column()) + QLatin1Char('-') @@ -3626,18 +3620,21 @@ void tst_QTreeView::task220298_selectColumns() return QVariant(); } - virtual QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const + QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const override { - return hasIndex(row, column, parent) ? createIndex(row, column, column*10+row) : QModelIndex(); + return hasIndex(row, column, parent) ? createIndex(row, column, quintptr(column * 10 + row)) : QModelIndex(); } }; - class TreeView : public QTreeView { public: QModelIndexList selectedIndexes () const { return QTreeView::selectedIndexes(); } } view; + class TreeView : public QTreeView { + public: + using QTreeView::selectedIndexes; + } view; Model model; view.setModel(&model); view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(view.model()->index(1, 1)).center()); QTRY_VERIFY(view.selectedIndexes().contains(view.model()->index(1, 2))); QVERIFY(view.selectedIndexes().contains(view.model()->index(1, 1))); @@ -3653,8 +3650,8 @@ void tst_QTreeView::task224091_appendColumns() QTreeView *treeView = new QTreeView(topLevel); treeView->setModel(model); topLevel->show(); - treeView->resize(50,50); - qApp->setActiveWindow(topLevel); + treeView->resize(50, 50); + QApplication::setActiveWindow(topLevel); QVERIFY(QTest::qWaitForWindowActive(topLevel)); QVERIFY(!treeView->verticalScrollBar()->isVisible()); @@ -3705,9 +3702,8 @@ void tst_QTreeView::task211293_removeRootIndex() view.setCurrentIndex(model.indexFromItem(E11314)); view.setExpanded(model.indexFromItem(E11314), true); view.show(); - qApp->processEvents(); - model.removeRows(0, 1); - qApp->processEvents(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + QVERIFY(model.removeRows(0, 1)); } void tst_QTreeView::task225539_deleteModel() @@ -3716,8 +3712,8 @@ void tst_QTreeView::task225539_deleteModel() treeView.show(); QStandardItemModel *model = new QStandardItemModel(&treeView); - QStandardItem* parentItem = model->invisibleRootItem(); - QStandardItem* item = new QStandardItem(QString("item")); + QStandardItem *parentItem = model->invisibleRootItem(); + QStandardItem *item = new QStandardItem(QString("item")); parentItem->appendRow(item); treeView.setModel(model); @@ -3767,7 +3763,7 @@ void tst_QTreeView::task230123_setItemsExpandable() QTest::keyClick(&tree, Qt::Key_Right); QVERIFY(root.isExpanded()); - const bool navToChild = tree.style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, 0, &tree); + const bool navToChild = tree.style()->styleHint(QStyle::SH_ItemView_ArrowKeysNavigateIntoChildren, nullptr, &tree); QTest::keyClick(&tree, Qt::Key_Right); QCOMPARE(tree.currentItem(), navToChild ? &child : &root); @@ -3784,13 +3780,13 @@ void tst_QTreeView::task230123_setItemsExpandable() void tst_QTreeView::task202039_closePersistentEditor() { - QStandardItemModel model(1,1); + QStandardItemModel model(1, 1); QTreeView view; view.setModel(&model); QModelIndex current = model.index(0,0); - QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.visualRect(current).center()); - QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(current).center()); + QTest::mousePress(view.viewport(), Qt::LeftButton, {}, view.visualRect(current).center()); + QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(current).center()); QCOMPARE(view.currentIndex(), current); QVERIFY(view.indexWidget(current)); @@ -3799,8 +3795,8 @@ void tst_QTreeView::task202039_closePersistentEditor() //here was the bug: closing the persistent editor would not reset the state //and it was impossible to go into editinon again - QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.visualRect(current).center()); - QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(current).center()); + QTest::mousePress(view.viewport(), Qt::LeftButton, {}, view.visualRect(current).center()); + QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(current).center()); QCOMPARE(view.currentIndex(), current); QVERIFY(view.indexWidget(current)); } @@ -3824,13 +3820,12 @@ void tst_QTreeView::task238873_avoidAutoReopening() view.expandAll(); QVERIFY(QTest::qWaitForWindowActive(&view)); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(child.index()).center()); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(child.index()).center()); QTRY_COMPARE(view.currentIndex(), child.index()); view.setExpanded(item1.index(), false); - QTest::qWait(500); //enough to trigger the delayedAutoScroll timer - QVERIFY(!view.isExpanded(item1.index())); + QTRY_VERIFY(!view.isExpanded(item1.index())); } void tst_QTreeView::task244304_clickOnDecoration() @@ -3841,39 +3836,38 @@ void tst_QTreeView::task244304_clickOnDecoration() QStandardItem item00("row 0"); item0.appendRow(&item00); QStandardItem item1("row 1"); - model.appendColumn(QList<QStandardItem*>() << &item0 << &item1); + model.appendColumn({ &item0, &item1 }); view.setModel(&model); QVERIFY(!view.currentIndex().isValid()); QRect rect = view.visualRect(item0.index()); //we click on the decoration - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, rect.topLeft()+QPoint(-rect.left()/2,rect.height()/2)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, + rect.topLeft() + QPoint(-rect.left() / 2, rect.height() / 2)); QVERIFY(!view.currentIndex().isValid()); QVERIFY(view.isExpanded(item0.index())); rect = view.visualRect(item1.index()); //the item has no decoration, it should get selected - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, rect.topLeft()+QPoint(-rect.left()/2,rect.height()/2)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, + rect.topLeft() + QPoint(-rect.left() / 2, rect.height() / 2)); QCOMPARE(view.currentIndex(), item1.index()); } void tst_QTreeView::task246536_scrollbarsNotWorking() { - struct MyObject : public QObject + class MyObject : public QObject { - MyObject() : count(0) - { - } - - bool eventFilter(QObject*, QEvent *e) + public: + using QObject::QObject; + bool eventFilter(QObject*, QEvent *e) override { if (e->type() == QEvent::Paint) count++; return false; } - - int count; + int count = 0; }; QTreeView tree; MyObject o; @@ -3883,11 +3877,11 @@ void tst_QTreeView::task246536_scrollbarsNotWorking() tree.show(); QVERIFY(QTest::qWaitForWindowExposed(&tree)); QList<QStandardItem *> items; - for(int i=0; i<100; ++i){ + for (int i = 0; i < 100; ++i) items << new QStandardItem(QLatin1String("item ") + QString::number(i)); - } + o.count = 0; model.invisibleRootItem()->appendColumn(items); - QTest::qWait(100); + QTRY_VERIFY(o.count > 0); o.count = 0; tree.verticalScrollBar()->setValue(50); QTRY_VERIFY(o.count > 0); @@ -3915,12 +3909,12 @@ void tst_QTreeView::task239271_addRowsWithFirstColumnHidden() class MyDelegate : public QStyledItemDelegate { public: - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const override { paintedIndexes << index; QStyledItemDelegate::paint(painter, option, index); } - mutable QSet<QModelIndex> paintedIndexes; }; @@ -3953,15 +3947,15 @@ void tst_QTreeView::task254234_proxySort() //based on tst_QTreeView::sortByColumn // it used not to work when setting the source of a proxy after enabling sorting QTreeView view; - QStandardItemModel model(4,2); - model.setItem(0,0,new QStandardItem("b")); - model.setItem(1,0,new QStandardItem("d")); - model.setItem(2,0,new QStandardItem("c")); - model.setItem(3,0,new QStandardItem("a")); - model.setItem(0,1,new QStandardItem("e")); - model.setItem(1,1,new QStandardItem("g")); - model.setItem(2,1,new QStandardItem("h")); - model.setItem(3,1,new QStandardItem("f")); + QStandardItemModel model(4, 2); + model.setItem(0, 0, new QStandardItem("b")); + model.setItem(1, 0, new QStandardItem("d")); + model.setItem(2, 0, new QStandardItem("c")); + model.setItem(3, 0, new QStandardItem("a")); + model.setItem(0, 1, new QStandardItem("e")); + model.setItem(1, 1, new QStandardItem("g")); + model.setItem(2, 1, new QStandardItem("h")); + model.setItem(3, 1, new QStandardItem("f")); view.sortByColumn(1, Qt::DescendingOrder); view.setSortingEnabled(true); @@ -3971,8 +3965,8 @@ void tst_QTreeView::task254234_proxySort() view.setModel(&proxy); proxy.setSourceModel(&model); 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")); + 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")); } class TreeView : public QTreeView @@ -3984,7 +3978,8 @@ public slots: //let's select the last item QModelIndex idx = model()->index(0, 0); selectionModel()->select(QItemSelection(idx, idx), QItemSelectionModel::Select); - disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(handleSelectionChanged())); + disconnect(selectionModel(), &QItemSelectionModel::selectionChanged, + this, &TreeView::handleSelectionChanged); } }; @@ -3993,12 +3988,14 @@ void tst_QTreeView::task248022_changeSelection() //we check that changing the selection between the mouse press and the mouse release //works correctly TreeView view; - QStringList list = QStringList() << "1" << "2"; + const QStringList list({"1", "2"}); QStringListModel model(list); view.setSelectionMode(QAbstractItemView::ExtendedSelection); view.setModel(&model); - view.connect(view.selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(handleSelectionChanged())); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(1)).center()); + connect(view.selectionModel(), &QItemSelectionModel::selectionChanged, + &view, &TreeView::handleSelectionChanged); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, + view.visualRect(model.index(1)).center()); QCOMPARE(view.selectionModel()->selectedIndexes().count(), list.count()); } @@ -4012,8 +4009,9 @@ void tst_QTreeView::task245654_changeModelAndExpandAll() model->appendRow(top); view.setModel(model.data()); view.expandAll(); - QApplication::processEvents(); - QVERIFY(view.isExpanded(top->index())); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + QTRY_VERIFY(view.isExpanded(top->index())); //now let's try to delete the model //then repopulate and expand again @@ -4024,9 +4022,7 @@ void tst_QTreeView::task245654_changeModelAndExpandAll() model->appendRow(top); view.setModel(model.data()); view.expandAll(); - QApplication::processEvents(); - QVERIFY(view.isExpanded(top->index())); - + QTRY_VERIFY(view.isExpanded(top->index())); } void tst_QTreeView::doubleClickedWithSpans() @@ -4042,10 +4038,10 @@ void tst_QTreeView::doubleClickedWithSpans() QPoint p(10, 10); QCOMPARE(view.indexAt(p), model.index(0, 0)); - QSignalSpy spy(&view, SIGNAL(doubleClicked(QModelIndex))); - QTest::mousePress(view.viewport(), Qt::LeftButton, 0, p); - QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, p); - QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, p); + QSignalSpy spy(&view, &QAbstractItemView::doubleClicked); + QTest::mousePress(view.viewport(), Qt::LeftButton, {}, p); + QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, p); + QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, p); QCOMPARE(spy.count(), 1); //let's click on the 2nd column @@ -4053,10 +4049,10 @@ void tst_QTreeView::doubleClickedWithSpans() QCOMPARE(view.indexAt(p), model.index(0, 0)); //end the previous edition - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p); - QTest::mousePress(view.viewport(), Qt::LeftButton, 0, p); - QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, p); - QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, p); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, p); + QTest::mousePress(view.viewport(), Qt::LeftButton, {}, p); + QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, p); + QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, p); QTRY_COMPARE(spy.count(), 2); } @@ -4069,7 +4065,8 @@ void tst_QTreeView::taskQTBUG_6450_selectAllWith1stColumnHidden() const int nrRows = 10; for (int i = 0; i < nrRows; ++i) { const QString text = QLatin1String("item: ") + QString::number(i); - items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(text))); + items.append(new QTreeWidgetItem(static_cast<QTreeWidget *>(nullptr), + QStringList(text))); items.last()->setText(1, QString("is an item")); } tree.insertTopLevelItems(0, items); @@ -4086,15 +4083,15 @@ class TreeViewQTBUG_9216 : public QTreeView { Q_OBJECT public: - void paintEvent(QPaintEvent *event) + void paintEvent(QPaintEvent *event) override { if (doCompare) QCOMPARE(event->rect(), viewport()->rect()); QTreeView::paintEvent(event); painted++; } - int painted; - bool doCompare; + int painted = 0; + bool doCompare = false; }; void tst_QTreeView::taskQTBUG_9216_setSizeAndUniformRowHeightsWrongRepaint() @@ -4128,7 +4125,7 @@ void tst_QTreeView::keyboardNavigationWithDisabled() QStandardItemModel model(90, 0); for (int i = 0; i < 90; i ++) { model.setItem(i, new QStandardItem(QString::number(i))); - model.item(i)->setEnabled(i%6 == 0); + model.item(i)->setEnabled(i % 6 == 0); } view.setModel(&model); @@ -4179,6 +4176,7 @@ void tst_QTreeView::keyboardNavigationWithDisabled() class RemoveColumnOne : public QSortFilterProxyModel { + Q_OBJECT public: bool filterAcceptsColumn(int source_column, const QModelIndex &) const override { @@ -4200,9 +4198,9 @@ void tst_QTreeView::saveRestoreState() { QStandardItemModel model; for (int i = 0; i < 100; i++) { - QList<QStandardItem *> items; - items << new QStandardItem(QLatin1String("item ") + QString::number(i)) << new QStandardItem(QStringLiteral("hidden by proxy")) << new QStandardItem(QStringLiteral("hidden by user")); - model.appendRow(items); + model.appendRow({new QStandardItem(QStringLiteral("item ") + QString::number(i)), + new QStandardItem(QStringLiteral("hidden by proxy")), + new QStandardItem(QStringLiteral("hidden by user")) }); } QCOMPARE(model.columnCount(), 3); @@ -4233,32 +4231,29 @@ class Model_11466 : public QAbstractItemModel { Q_OBJECT public: - Model_11466(QObject * /* parent */) : - m_block(false) + Model_11466(QObject *parent = nullptr) : QAbstractItemModel(parent) + , m_selectionModel(new QItemSelectionModel(this, this)) { - // set up the model to have two top level items and a few others - m_selectionModel = new QItemSelectionModel(this, this); // owned by this - - connect(m_selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), - this, SLOT(slotCurrentChanged(QModelIndex,QModelIndex))); - }; + connect(m_selectionModel, &QItemSelectionModel::currentChanged, + this, &Model_11466::slotCurrentChanged); + } - int rowCount(const QModelIndex &parent) const + int rowCount(const QModelIndex &parent) const override { if (parent.isValid()) return (parent.internalId() == 0) ? 4 : 0; return 2; // two top level items } - int columnCount(const QModelIndex & /* parent */) const + int columnCount(const QModelIndex & /* parent */) const override { return 2; } - QVariant data(const QModelIndex &index, int role) const + QVariant data(const QModelIndex &index, int role) const override { if (role == Qt::DisplayRole && index.isValid()) { - qint64 parentRowPlusOne = index.internalId(); + qint64 parentRowPlusOne = qint64(index.internalId()); QString str; QTextStream stream(&str); if (parentRowPlusOne > 0) @@ -4270,10 +4265,10 @@ public: return QVariant(); } - QModelIndex parent(const QModelIndex &index) const + QModelIndex parent(const QModelIndex &index) const override { if (index.isValid()) { - qint64 parentRowPlusOne = index.internalId(); + qint64 parentRowPlusOne = qint64(index.internalId()); if (parentRowPlusOne > 0) { int row = static_cast<int>(parentRowPlusOne - 1); return createIndex(row, 0); @@ -4294,9 +4289,9 @@ public: delete oldModel; } - QModelIndex index(int row, int column, const QModelIndex &parent) const + QModelIndex index(int row, int column, const QModelIndex &parent) const override { - return createIndex(row, column, parent.isValid() ? (quintptr)(parent.row() + 1) : (quintptr)0); + return createIndex(row, column, parent.isValid() ? quintptr(parent.row() + 1) : quintptr(0)); } public slots: @@ -4333,7 +4328,7 @@ public slots: } private: - bool m_block; + bool m_block = false; QItemSelectionModel *m_selectionModel; }; @@ -4388,9 +4383,9 @@ void tst_QTreeView::taskQTBUG_25333_adjustViewOptionsForIndex() QStandardItem *data3 = new QStandardItem("Data3"); // Create a treeview - model.appendRow(QList<QStandardItem*>() << item1 << data1 ); - model.appendRow(QList<QStandardItem*>() << item2 << data2 ); - model.appendRow(QList<QStandardItem*>() << item3 << data3 ); + model.appendRow({ item1, data1 }); + model.appendRow({ item2, data2 }); + model.appendRow({ item3, data3 }); view.setModel(&model); @@ -4414,6 +4409,9 @@ void tst_QTreeView::taskQTBUG_25333_adjustViewOptionsForIndex() void tst_QTreeView::taskQTBUG_18539_emitLayoutChanged() { + qRegisterMetaType<QList<QPersistentModelIndex>>(); + qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>(); + QTreeView view; QStandardItem* item = new QStandardItem("Orig"); @@ -4430,14 +4428,14 @@ void tst_QTreeView::taskQTBUG_18539_emitLayoutChanged() replacementItem->setChild(0, 0, replacementChild); - QSignalSpy beforeSpy(&model, SIGNAL(layoutAboutToBeChanged())); - QSignalSpy afterSpy(&model, SIGNAL(layoutChanged())); + QSignalSpy beforeSpy(&model, &QAbstractItemModel::layoutAboutToBeChanged); + QSignalSpy afterSpy(&model, &QAbstractItemModel::layoutChanged); - QSignalSpy beforeRISpy(&model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int))); - QSignalSpy afterRISpy(&model, SIGNAL(rowsInserted(QModelIndex,int,int))); + QSignalSpy beforeRISpy(&model, &QAbstractItemModel::rowsAboutToBeInserted); + QSignalSpy afterRISpy(&model, &QAbstractItemModel::rowsInserted); - QSignalSpy beforeRRSpy(&model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int))); - QSignalSpy afterRRSpy(&model, SIGNAL(rowsRemoved(QModelIndex,int,int))); + QSignalSpy beforeRRSpy(&model, &QAbstractItemModel::rowsAboutToBeRemoved); + QSignalSpy afterRRSpy(&model, &QAbstractItemModel::rowsRemoved); model.setItem(0, 0, replacementItem); @@ -4460,7 +4458,7 @@ void tst_QTreeView::taskQTBUG_8176_emitOnExpandAll() new QTreeWidgetItem(item2, QStringList(QString("item 4"))); QTreeWidgetItem *item5 = new QTreeWidgetItem(&tw, QStringList(QString("item 5"))); new QTreeWidgetItem(item5, QStringList(QString("item 6"))); - QSignalSpy spy(&tw, SIGNAL(expanded(const QModelIndex&))); + QSignalSpy spy(&tw, &QTreeView::expanded); // expand all tw.expandAll(); @@ -4473,7 +4471,7 @@ void tst_QTreeView::taskQTBUG_8176_emitOnExpandAll() QCOMPARE(spy.size(), 5); // collapse all - QSignalSpy spy2(&tw, SIGNAL(collapsed(const QModelIndex&))); + QSignalSpy spy2(&tw, &QTreeView::collapsed); tw.collapseAll(); QCOMPARE(spy2.size(), 6); tw.expandAll(); @@ -4496,14 +4494,13 @@ void tst_QTreeView::testInitialFocus() { QTreeWidget treeWidget; treeWidget.setColumnCount(5); - new QTreeWidgetItem(&treeWidget, QStringList(QString("1;2;3;4;5").split(QLatin1Char(';')))); + new QTreeWidgetItem(&treeWidget, QString("1;2;3;4;5").split(QLatin1Char(';'))); treeWidget.setTreePosition(2); treeWidget.header()->hideSection(0); // make sure we skip hidden section(s) treeWidget.header()->swapSections(1, 2); // make sure that we look for first visual index (and not first logical) treeWidget.show(); QVERIFY(QTest::qWaitForWindowExposed(&treeWidget)); - QApplication::processEvents(); - QCOMPARE(treeWidget.currentIndex().column(), 2); + QTRY_COMPARE(treeWidget.currentIndex().column(), 2); } #if QT_CONFIG(animation) @@ -4534,9 +4531,8 @@ void tst_QTreeView::quickExpandCollapse() tree.collapse(rootIndex); QCOMPARE(tree.state(), QTreeView::AnimatingState); - QTest::qWait(500); //the animation lasts for 250ms max so 500 should be enough - - QCOMPARE(tree.state(), initialState); + //the animation lasts for 250ms max so 5000 (default) should be enough + QTRY_COMPARE(tree.state(), initialState); } #endif // animation @@ -4576,7 +4572,7 @@ class Qtbug45697TestWidget : public QWidget public: static const int columnCount = 3; - explicit Qtbug45697TestWidget(); + explicit Qtbug45697TestWidget(QWidget *parent = nullptr); int timerTick() const { return m_timerTick; } public slots: @@ -4586,14 +4582,13 @@ private: QTreeView *m_treeView; QStandardItemModel *m_model; QSortFilterProxyModel *m_sortFilterProxyModel; - int m_timerTick; + int m_timerTick = 0; }; -Qtbug45697TestWidget::Qtbug45697TestWidget() - : m_treeView(new QTreeView(this)) +Qtbug45697TestWidget::Qtbug45697TestWidget(QWidget *parent) + : QWidget(parent), m_treeView(new QTreeView(this)) , m_model(new QStandardItemModel(0, Qtbug45697TestWidget::columnCount, this)) , m_sortFilterProxyModel(new QSortFilterProxyModel(this)) - , m_timerTick(0) { QVBoxLayout *vBoxLayout = new QVBoxLayout(this); vBoxLayout->addWidget(m_treeView); @@ -4611,7 +4606,7 @@ Qtbug45697TestWidget::Qtbug45697TestWidget() m_treeView->setModel(m_sortFilterProxyModel); QHeaderView *headerView = m_treeView->header(); - for (int s = 1, lastSection = headerView->count() - 1; s < lastSection; ++s ) + for (int s = 1, lastSection = headerView->count() - 1; s < lastSection; ++s) headerView->setSectionResizeMode(s, QHeaderView::ResizeToContents); QTimer *timer = new QTimer(this); @@ -4697,9 +4692,8 @@ void tst_QTreeView::statusTip() { QFETCH(bool, intermediateParent); QMainWindow mw; - QtTestModel model; + QtTestModel model(5, 5); model.statusTipsEnabled = true; - model.rows = model.cols = 5; QTreeView *view = new QTreeView; view->setModel(&model); view->viewport()->setMouseTracking(true); @@ -4717,7 +4711,7 @@ void tst_QTreeView::statusTip() mw.setGeometry(QRect(QPoint(QApplication::desktop()->geometry().center() - QPoint(250, 250)), QSize(500, 500))); mw.show(); - qApp->setActiveWindow(&mw); + QApplication::setActiveWindow(&mw); QVERIFY(QTest::qWaitForWindowActive(&mw)); // Ensure it is moved away first and then moved to the relevant section QTest::mouseMove(mw.windowHandle(), view->mapTo(&mw, view->rect().bottomLeft() + QPoint(20, 20))); @@ -4736,8 +4730,9 @@ void tst_QTreeView::statusTip() class FetchMoreModel : public QStandardItemModel { + Q_OBJECT public: - FetchMoreModel() : QStandardItemModel(), canFetchReady(false) + FetchMoreModel(QObject *parent = nullptr) : QStandardItemModel(parent) { for (int i = 0; i < 20; ++i) { QStandardItem *item = new QStandardItem("Row"); @@ -4757,9 +4752,9 @@ public: { QStandardItem *item = itemFromIndex(parent); for (int i = 0; i < 19; ++i) - item->appendRow(new QStandardItem(QString("New Child %1").arg(i))); + item->appendRow(new QStandardItem(QStringLiteral("New Child ") + QString::number(i))); } - bool canFetchReady; + bool canFetchReady = false; }; void tst_QTreeView::fetchMoreOnScroll() @@ -4865,12 +4860,12 @@ void tst_QTreeView::taskQTBUG_61476() 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) == + QTest::mousePress(tv.viewport(), Qt::LeftButton, {}, pos); + if (tv.style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, nullptr, &tv) == QEvent::MouseButtonPress) QTRY_VERIFY(!tv.isExpanded(mi)); - QTest::mouseRelease(tv.viewport(), Qt::LeftButton, 0, pos); + QTest::mouseRelease(tv.viewport(), Qt::LeftButton, nullptr, pos); QTRY_VERIFY(!tv.isExpanded(mi)); QCOMPARE(lastTopLevel->checkState(), Qt::Checked); } diff --git a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp index 33d4f3bf91..6b8beccbdc 100644 --- a/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp @@ -27,36 +27,22 @@ ****************************************************************************/ -#include <QtTest/QtTest> -#include <qtreewidget.h> -#include <qtreewidgetitemiterator.h> -#include <qapplication.h> -#include <qeventloop.h> -#include <qdebug.h> -#include <qheaderview.h> -#include <qlineedit.h> +#include <QApplication> +#include <QHeaderView> +#include <QLineEdit> #include <QScrollBar> +#include <QSignalSpy> #include <QStyledItemDelegate> - -class CustomTreeWidget : public QTreeWidget -{ - Q_OBJECT -public: - QModelIndex indexFromItem(QTreeWidgetItem *item, int column = 0) const - { return QTreeWidget::indexFromItem(item, column); } - - QMimeData * mimeData(const QList<QTreeWidgetItem*> items) const - { return QTreeWidget::mimeData(items); } -}; +#include <QTreeWidget> +#include <QTreeWidgetItemIterator> +#include <QTest> class tst_QTreeWidget : public QObject { Q_OBJECT public: - tst_QTreeWidget(); - ~tst_QTreeWidget(); - + tst_QTreeWidget() = default; public slots: void initTestCase(); @@ -173,8 +159,25 @@ public slots: void itemSelectionChanged(); void emitDataChanged(); +public: + class PublicTreeWidget : public QTreeWidget + { + public: + using QTreeWidget::indexFromItem; + using QTreeWidget::mimeData; + using QTreeWidget::sizeHintForColumn; + void deleteCurrent() { delete currentItem(); } + }; + + class PublicTreeItem : public QTreeWidgetItem + { + public: + using QTreeWidgetItem::QTreeWidgetItem; + using QTreeWidgetItem::emitDataChanged; + }; + private: - CustomTreeWidget *testWidget; + PublicTreeWidget *testWidget = nullptr; }; // Testing get/set functions @@ -186,7 +189,7 @@ void tst_QTreeWidget::getSetCheck() obj1.setColumnCount(0); QCOMPARE(obj1.columnCount(), 0); - obj1.setColumnCount(INT_MIN); + obj1.setColumnCount(std::numeric_limits<int>::min()); QCOMPARE(obj1.columnCount(), 0); //obj1.setColumnCount(INT_MAX); @@ -202,7 +205,7 @@ void tst_QTreeWidget::getSetCheck() obj1.setHeaderItem(var2); QCOMPARE(obj1.headerItem(), var2); - obj1.setHeaderItem((QTreeWidgetItem *)0); + obj1.setHeaderItem(nullptr); // QCOMPARE(obj1.headerItem(), nullptr); // QTreeWidgetItem * QTreeWidget::currentItem() @@ -211,36 +214,28 @@ void tst_QTreeWidget::getSetCheck() obj1.setCurrentItem(var3); QCOMPARE(obj1.currentItem(), var3); - obj1.setCurrentItem((QTreeWidgetItem *)0); + obj1.setCurrentItem(nullptr); QCOMPARE(obj1.currentItem(), nullptr); } -typedef QList<int> IntList; -typedef QList<IntList> ListIntList; +using IntList = QVector<int>; +using ListIntList = QVector<IntList>; +using PersistentModelIndexVec = QVector<QPersistentModelIndex>; +using TreeItem = QTreeWidgetItem; +using TreeItemList = QVector<TreeItem*>; Q_DECLARE_METATYPE(Qt::Orientation) - -typedef QTreeWidgetItem TreeItem; -typedef QList<TreeItem*> TreeItemList; - Q_DECLARE_METATYPE(QTreeWidgetItem*) Q_DECLARE_METATYPE(TreeItemList) -tst_QTreeWidget::tst_QTreeWidget(): testWidget(0) -{ -} - -tst_QTreeWidget::~tst_QTreeWidget() -{ -} - void tst_QTreeWidget::initTestCase() { - qMetaTypeId<QModelIndex>(); qMetaTypeId<Qt::Orientation>(); qRegisterMetaType<QTreeWidgetItem*>("QTreeWidgetItem*"); + qRegisterMetaType<QList<QPersistentModelIndex>>("QList<QPersistentModelIndex>"); + qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>("QAbstractItemModel::LayoutChangeHint"); - testWidget = new CustomTreeWidget(); + testWidget = new PublicTreeWidget(); testWidget->show(); QVERIFY(QTest::qWaitForWindowExposed(testWidget)); } @@ -261,18 +256,19 @@ void tst_QTreeWidget::cleanup() { } -TreeItem *operator<<(TreeItem *parent, const TreeItemList &children) { - for (int i = 0; i < children.count(); ++i) - parent->addChild(children.at(i)); +TreeItem *operator<<(TreeItem *parent, const TreeItemList &children) +{ + for (TreeItem *child : children) + parent->addChild(child); return parent; } static void populate(QTreeWidget *widget, const TreeItemList &topLevelItems, - TreeItem *headerItem = 0) + TreeItem *headerItem = nullptr) { widget->clear(); widget->setHeaderItem(headerItem); - foreach (TreeItem *item, topLevelItems) + for (TreeItem *item : topLevelItems) widget->addTopLevelItem(item); } @@ -282,12 +278,12 @@ void tst_QTreeWidget::addTopLevelItem() QCOMPARE(tree.topLevelItemCount(), 0); // try to add 0 - tree.addTopLevelItem(0); + tree.addTopLevelItem(nullptr); QCOMPARE(tree.topLevelItemCount(), 0); - QCOMPARE(tree.indexOfTopLevelItem(0), -1); + QCOMPARE(tree.indexOfTopLevelItem(nullptr), -1); // add one at a time - QList<TreeItem*> tops; + QList<TreeItem *> tops; for (int i = 0; i < 10; ++i) { TreeItem *ti = new TreeItem(); QCOMPARE(tree.indexOfTopLevelItem(ti), -1); @@ -362,19 +358,19 @@ void tst_QTreeWidget::currentItem_data() QTest::newRow("only top-level items, 2 columns") << (TreeItemList() - << new TreeItem(QStringList() << "a" << "b") - << new TreeItem(QStringList() << "c" << "d")); + << new TreeItem({"a", "b"}) + << new TreeItem({"c", "d"})); TreeItemList lst; - lst << (new TreeItem(QStringList() << "a" << "b") + lst << (new TreeItem({"a", "b"}) << (TreeItemList() - << new TreeItem(QStringList() << "c" << "d") - << new TreeItem(QStringList() << "c" << "d") + << new TreeItem({"c", "d"}) + << new TreeItem({"c", "d"}) ) ) - << (new TreeItem(QStringList() << "e" << "f") + << (new TreeItem({"e", "f"}) << (TreeItemList() - << new TreeItem(QStringList() << "g" << "h") - << new TreeItem(QStringList() << "g" << "h") + << new TreeItem({"g", "h"}) + << new TreeItem({"g", "h"}) ) ); QTest::newRow("hierarchy, 2 columns") << lst; @@ -386,15 +382,15 @@ void tst_QTreeWidget::currentItem() QTreeWidget tree; tree.show(); - populate(&tree, topLevelItems, new TreeItem(QStringList() << "1" << "2")); - QTreeWidgetItem *previous = 0; + populate(&tree, topLevelItems, new TreeItem({"1", "2"})); + QTreeWidgetItem *previous = nullptr; for (int x = 0; x < 2; ++x) { tree.setSelectionBehavior(x ? QAbstractItemView::SelectItems : QAbstractItemView::SelectRows); QSignalSpy currentItemChangedSpy( - &tree, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*))); + &tree, &QTreeWidget::currentItemChanged); QSignalSpy itemSelectionChangedSpy( - &tree, SIGNAL(itemSelectionChanged())); + &tree, &QTreeWidget::itemSelectionChanged); QTreeWidgetItemIterator it(&tree); // do all items @@ -468,8 +464,7 @@ void tst_QTreeWidget::editItem() tree.show(); QVERIFY(QTest::qWaitForWindowActive(&tree)); - QSignalSpy itemChangedSpy( - &tree, SIGNAL(itemChanged(QTreeWidgetItem*,int))); + QSignalSpy itemChangedSpy(&tree, &QTreeWidget::itemChanged); QTreeWidgetItemIterator it(&tree); while (QTreeWidgetItem *item = (*it++)) { @@ -477,18 +472,18 @@ void tst_QTreeWidget::editItem() if (!(item->flags() & Qt::ItemIsEditable)) QTest::ignoreMessage(QtWarningMsg, "edit: editing failed"); tree.editItem(item, col); - QApplication::instance()->processEvents(); - QApplication::instance()->processEvents(); + QCoreApplication::processEvents(); + QCoreApplication::processEvents(); QLineEdit *editor = tree.findChild<QLineEdit*>(); if (editor) { QVERIFY(item->flags() & Qt::ItemIsEditable); QCOMPARE(editor->selectedText(), editor->text()); QTest::keyClick(editor, Qt::Key_A); QTest::keyClick(editor, Qt::Key_Enter); - QApplication::instance()->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(itemChangedSpy.count(), 1); QVariantList args = itemChangedSpy.takeFirst(); - QCOMPARE(qvariant_cast<QTreeWidgetItem*>(args.at(0)), item); + QCOMPARE(qvariant_cast<QTreeWidgetItem *>(args.at(0)), item); QCOMPARE(qvariant_cast<int>(args.at(1)), col); } else { QVERIFY(!(item->flags() & Qt::ItemIsEditable)); @@ -522,10 +517,10 @@ void tst_QTreeWidget::takeItem() QFETCH(bool, topLevel); QFETCH(bool, outOfBounds); - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { QTreeWidgetItem *top = new QTreeWidgetItem(testWidget); top->setText(0, QStringLiteral("top") + QString::number(i)); - for (int j=0; j<3; ++j) { + for (int j = 0; j < 3; ++j) { QTreeWidgetItem *child = new QTreeWidgetItem(top); child->setText(0, QStringLiteral("child") + QString::number(j)); } @@ -635,27 +630,23 @@ void tst_QTreeWidget::setItemHidden() parent->setHidden(true); parent->setHidden(false); QVERIFY(!parent->isHidden()); - - } void tst_QTreeWidget::setItemHidden2() { // From Task 78587 - QStringList hl; - hl << "ID" << "Desc"; + const QStringList hl({"ID", "Desc"}); testWidget->setColumnCount(hl.count()); testWidget->setHeaderLabels(hl); testWidget->setSortingEnabled(true); QTreeWidgetItem *top = new QTreeWidgetItem(testWidget); - QTreeWidgetItem *leaf = 0; top->setText(0, "ItemList"); for (int i = 1; i <= 4; i++) { - leaf = new QTreeWidgetItem(top); - leaf->setText(0, QString::asprintf("%d", i)); - leaf->setText(1, QString::asprintf("Item %d", i)); + auto leaf = new QTreeWidgetItem(top); + leaf->setText(0, QString::number(i)); + leaf->setText(1, QStringLiteral("Item %1").arg(i)); } if (testWidget->topLevelItemCount() > 0) { @@ -666,11 +657,10 @@ void tst_QTreeWidget::setItemHidden2() if (testWidget->topLevelItemCount() > 0) { top = testWidget->topLevelItem(0); for (int i = 0; i < top->childCount(); i++) { - leaf = top->child(i); + auto leaf = top->child(i); if (leaf->text(0).toInt() % 2 == 0) { - if (!leaf->isHidden()) { + if (!leaf->isHidden()) leaf->setHidden(true); - } } } } @@ -799,25 +789,25 @@ void tst_QTreeWidget::selectedItems() QFETCH(int, topLevel); QFETCH(int, children); QFETCH(bool, closeTopLevel); - QFETCH(ListIntList, selectedItems); - QFETCH(ListIntList, hiddenItems); - QFETCH(ListIntList, expectedItems); + QFETCH(const ListIntList, selectedItems); + QFETCH(const ListIntList, hiddenItems); + QFETCH(const ListIntList, expectedItems); // create items - for (int t=0; t<topLevel; ++t) { + for (int t = 0; t < topLevel; ++t) { QTreeWidgetItem *top = new QTreeWidgetItem(testWidget); const QString topS = QLatin1String("top") + QString::number(t); top->setText(0, topS); - for (int c=0; c<children; ++c) { + for (int c = 0; c < children; ++c) { QTreeWidgetItem *child = new QTreeWidgetItem(top); child->setText(0, topS + QLatin1String("child") + QString::number(c)); } } // set selected - foreach (IntList itemPath, selectedItems) { - QTreeWidgetItem *item = 0; - foreach(int index, itemPath) { + for (const auto &itemPath : selectedItems) { + QTreeWidgetItem *item = nullptr; + for (int index : itemPath) { if (!item) item = testWidget->topLevelItem(index); else @@ -827,9 +817,9 @@ void tst_QTreeWidget::selectedItems() } // hide rows - foreach (IntList itemPath, hiddenItems) { - QTreeWidgetItem *item = 0; - foreach(int index, itemPath) { + for (const auto &itemPath : hiddenItems) { + QTreeWidgetItem *item = nullptr; + for (int index : itemPath) { if (!item) item = testWidget->topLevelItem(index); else @@ -839,7 +829,7 @@ void tst_QTreeWidget::selectedItems() } // open/close toplevel - for (int i=0; i<testWidget->topLevelItemCount(); ++i) { + for (int i = 0; i < testWidget->topLevelItemCount(); ++i) { if (closeTopLevel) testWidget->collapseItem(testWidget->topLevelItem(i)); else @@ -847,26 +837,26 @@ void tst_QTreeWidget::selectedItems() } // check selectedItems - QList<QTreeWidgetItem*> sel = testWidget->selectedItems(); + const auto sel = testWidget->selectedItems(); QCOMPARE(sel.count(), expectedItems.count()); - foreach (IntList itemPath, expectedItems) { - QTreeWidgetItem *item = 0; - foreach(int index, itemPath) { + for (const auto &itemPath : expectedItems) { + QTreeWidgetItem *item = nullptr; + for (int index : itemPath) { if (!item) item = testWidget->topLevelItem(index); else item = item->child(index); } if (item) - QVERIFY(sel.contains(item)); + QVERIFY(sel.contains(item)); } // compare isSelected - for (int t=0; t<testWidget->topLevelItemCount(); ++t) { + for (int t = 0; t < testWidget->topLevelItemCount(); ++t) { QTreeWidgetItem *top = testWidget->topLevelItem(t); if (top->isSelected() && !top->isHidden()) QVERIFY(sel.contains(top)); - for (int c=0; c<top->childCount(); ++c) { + for (int c = 0; c < top->childCount(); ++c) { QTreeWidgetItem *child = top->child(c); if (child->isSelected() && !child->isHidden()) QVERIFY(sel.contains(child)); @@ -883,9 +873,9 @@ QT_WARNING_POP #endif // unselect - foreach (IntList itemPath, selectedItems) { - QTreeWidgetItem *item = 0; - foreach(int index, itemPath) { + for (const auto &itemPath : selectedItems) { + QTreeWidgetItem *item = nullptr; + for (int index : itemPath) { if (!item) item = testWidget->topLevelItem(index); else @@ -903,7 +893,7 @@ void tst_QTreeWidget::itemAssignment() QTreeWidgetItem *parent = new QTreeWidgetItem(&grandParent); parent->setText(0, "foo"); parent->setText(1, "bar"); - for (int i=0; i<5; ++i) { + for (int i = 0; i < 5; ++i) { QTreeWidgetItem *child = new QTreeWidgetItem(parent); child->setText(0, "bingo"); child->setText(1, "bango"); @@ -919,7 +909,7 @@ void tst_QTreeWidget::itemAssignment() QTreeWidgetItem item(testWidget); item.setText(0, "baz"); QVERIFY(!item.parent()); - QCOMPARE(item.treeWidget(), static_cast<QTreeWidget *>(testWidget)); + QCOMPARE(item.treeWidget(), testWidget); QCOMPARE(item.columnCount(), 1); QCOMPARE(item.text(0), QString("baz")); QCOMPARE(item.childCount(), 0); @@ -959,16 +949,16 @@ void tst_QTreeWidget::clone() QFETCH(int, column); QFETCH(int, topLevelIndex); QFETCH(int, childIndex); - QFETCH(QStringList, topLevelText); - QFETCH(QStringList, childText); + QFETCH(const QStringList, topLevelText); + QFETCH(const QStringList, childText); QFETCH(bool, cloneChild); - for (int i = 0; i < topLevelText.count(); ++i) { + for (const QString &tl : topLevelText) { QTreeWidgetItem *item = new QTreeWidgetItem(testWidget); - item->setText(column, topLevelText.at(i)); - for (int j = 0; j < childText.count(); ++j) { + item->setText(column, tl); + for (const QString &cl : childText) { QTreeWidgetItem *child = new QTreeWidgetItem(item); - child->setText(column, childText.at(j)); + child->setText(column, cl); } } @@ -984,7 +974,7 @@ void tst_QTreeWidget::clone() QVERIFY(copiedChild != originalChild); QCOMPARE(copiedChild->text(column), originalChild->text(column)); QCOMPARE(copiedChild->childCount(), originalChild->childCount()); - QCOMPARE(copiedChild->parent(), cloneChild ? 0 : copy); + QCOMPARE(copiedChild->parent(), cloneChild ? nullptr : copy); QVERIFY(!copiedChild->treeWidget()); if (cloneChild) delete copiedChild; @@ -1109,18 +1099,18 @@ void tst_QTreeWidget::findItems_data() void tst_QTreeWidget::findItems() { QFETCH(int, column); - QFETCH(QStringList, topLevelText); - QFETCH(QStringList, childText); + QFETCH(const QStringList, topLevelText); + QFETCH(const QStringList, childText); QFETCH(QString, pattern); QFETCH(int, resultCount); - QFETCH(QStringList, resultText); + QFETCH(const QStringList, resultText); - for (int i = 0; i < topLevelText.count(); ++i) { + for (const QString &tl : topLevelText) { QTreeWidgetItem *item = new QTreeWidgetItem(testWidget); - item->setText(column, topLevelText.at(i)); - for (int j = 0; j < childText.count(); ++j) { + item->setText(column, tl); + for (const QString &cl : childText) { QTreeWidgetItem *child = new QTreeWidgetItem(item); - child->setText(column, childText.at(j)); + child->setText(column, cl); } } @@ -1152,7 +1142,7 @@ void tst_QTreeWidget::findItemsInColumn() void tst_QTreeWidget::sortItems_data() { QTest::addColumn<int>("column"); - QTest::addColumn<int>("order"); + QTest::addColumn<Qt::SortOrder>("order"); QTest::addColumn<QStringList>("topLevelText"); QTest::addColumn<QStringList>("childText"); QTest::addColumn<QStringList>("topLevelResult"); @@ -1162,7 +1152,7 @@ void tst_QTreeWidget::sortItems_data() QTest::newRow("ascending order") << 0 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "c" << "d" << "a" << "b") << (QStringList() << "e" << "h" << "g" << "f") << (QStringList() << "a" << "b" << "c" << "d") @@ -1172,7 +1162,7 @@ void tst_QTreeWidget::sortItems_data() QTest::newRow("descending order") << 0 - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << (QStringList() << "c" << "d" << "a" << "b") << (QStringList() << "e" << "h" << "g" << "f") << (QStringList() << "d" << "c" << "b" << "a") @@ -1184,7 +1174,7 @@ void tst_QTreeWidget::sortItems_data() void tst_QTreeWidget::sortItems() { QFETCH(int, column); - QFETCH(int, order); + QFETCH(Qt::SortOrder, order); QFETCH(QStringList, topLevelText); QFETCH(QStringList, childText); QFETCH(QStringList, topLevelResult); @@ -1193,28 +1183,24 @@ void tst_QTreeWidget::sortItems() QFETCH(IntList, expectedChildRows); testWidget->setSortingEnabled(false); - for (int i = 0; i < topLevelText.count(); ++i) { + for (const QString &tl : topLevelText) { QTreeWidgetItem *item = new QTreeWidgetItem(testWidget); - item->setText(column, topLevelText.at(i)); - for (int j = 0; j < childText.count(); ++j) { + item->setText(column, tl); + for (const QString &cl : childText) { QTreeWidgetItem *child = new QTreeWidgetItem(item); - child->setText(column, childText.at(j)); + child->setText(column, cl); } } QAbstractItemModel *model = testWidget->model(); - QList<QPersistentModelIndex> tops; - for (int r = 0; r < model->rowCount(QModelIndex()); ++r) { - QPersistentModelIndex p = model->index(r, 0, QModelIndex()); - tops << p; - } - QList<QPersistentModelIndex> children; - for (int s = 0; s < model->rowCount(tops.first()); ++s) { - QPersistentModelIndex c = model->index(s, 0, tops.first()); - children << c; - } - - testWidget->sortItems(column, static_cast<Qt::SortOrder>(order)); + PersistentModelIndexVec tops; + for (int r = 0; r < model->rowCount(QModelIndex()); ++r) + tops.push_back(model->index(r, 0, QModelIndex())); + PersistentModelIndexVec children; + for (int s = 0; s < model->rowCount(tops.constFirst()); ++s) + children.push_back(model->index(s, 0, tops.constFirst())); + + testWidget->sortItems(column, order); QCOMPARE(testWidget->sortColumn(), column); for (int k = 0; k < topLevelResult.count(); ++k) { @@ -1382,8 +1368,8 @@ void tst_QTreeWidget::insertTopLevelItems_data() QTest::addColumn<int>("insertChildIndex"); QTest::addColumn<int>("expectedChildIndex"); - QStringList initial = (QStringList() << "foo" << "bar"); - QStringList insert = (QStringList() << "baz"); + const QStringList initial{ "foo", "bar" }; + const QStringList insert{ "baz" }; QTest::newRow("Insert at count") << initial << insert << initial.count() << initial.count() @@ -1434,7 +1420,7 @@ void tst_QTreeWidget::insertTopLevelItems() delete topsy; } else { QTreeWidgetItem *item = testWidget->topLevelItem(expectedTopLevelIndex); - QVERIFY(item != 0); + QVERIFY(item != nullptr); QCOMPARE(item->text(0), insertText.at(0)); QCOMPARE(testWidget->indexOfTopLevelItem(item), expectedTopLevelIndex); } @@ -1442,7 +1428,7 @@ void tst_QTreeWidget::insertTopLevelItems() { // test adding more children QTreeWidgetItem *topLevel = testWidget->topLevelItem(0); - QVERIFY(topLevel != 0); + QVERIFY(topLevel != nullptr); QTreeWidgetItem *child = new QTreeWidgetItem(QStringList(insertText.at(0))); topLevel->insertChild(insertChildIndex, child); if (expectedChildIndex == -1) { @@ -1450,7 +1436,7 @@ void tst_QTreeWidget::insertTopLevelItems() delete child; } else { QTreeWidgetItem *item = topLevel->child(expectedChildIndex); - QVERIFY(item != 0); + QVERIFY(item != nullptr); QCOMPARE(item->text(0), insertText.at(0)); } } @@ -1486,37 +1472,33 @@ void tst_QTreeWidget::keyboardNavigation() fillTreeWidget(testWidget, rows); - QVector<Qt::Key> keymoves; - keymoves << Qt::Key_Down << Qt::Key_Right << Qt::Key_Left - << Qt::Key_Down << Qt::Key_Down << Qt::Key_Down << Qt::Key_Down - << Qt::Key_Right - << Qt::Key_Up << Qt::Key_Left << Qt::Key_Left - << Qt::Key_Up << Qt::Key_Down << Qt::Key_Up << Qt::Key_Up - << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up - << Qt::Key_Down << Qt::Key_Right << Qt::Key_Down << Qt::Key_Down - << Qt::Key_Down << Qt::Key_Right << Qt::Key_Down << Qt::Key_Down - << Qt::Key_Left << Qt::Key_Left << Qt::Key_Up << Qt::Key_Down - << Qt::Key_Up << Qt::Key_Up << Qt::Key_Up << Qt::Key_Left - << Qt::Key_Down << Qt::Key_Right << Qt::Key_Right << Qt::Key_Right - << Qt::Key_Left << Qt::Key_Left << Qt::Key_Right << Qt::Key_Left; - - int row = 0; + const QVector<Qt::Key> keymoves { + Qt::Key_Down, Qt::Key_Right, Qt::Key_Left, + Qt::Key_Down, Qt::Key_Down, Qt::Key_Down, Qt::Key_Down, + Qt::Key_Right, + Qt::Key_Up, Qt::Key_Left, Qt::Key_Left, + Qt::Key_Up, Qt::Key_Down, Qt::Key_Up, Qt::Key_Up, + Qt::Key_Up, Qt::Key_Up, Qt::Key_Up, Qt::Key_Up, + Qt::Key_Down, Qt::Key_Right, Qt::Key_Down, Qt::Key_Down, + Qt::Key_Down, Qt::Key_Right, Qt::Key_Down, Qt::Key_Down, + Qt::Key_Left, Qt::Key_Left, Qt::Key_Up, Qt::Key_Down, + Qt::Key_Up, Qt::Key_Up, Qt::Key_Up, Qt::Key_Left, + Qt::Key_Down, Qt::Key_Right, Qt::Key_Right, Qt::Key_Right, + Qt::Key_Left, Qt::Key_Left, Qt::Key_Right, Qt::Key_Left + }; + + int row = 0; QTreeWidgetItem *item = testWidget->topLevelItem(0); testWidget->setCurrentItem(item); QCOMPARE(testWidget->currentItem(), item); - QApplication::instance()->processEvents(); + QCoreApplication::processEvents(); QScrollBar *scrollBar = testWidget->horizontalScrollBar(); - bool checkScroll = false; - for (int i = 0; i < keymoves.size(); ++i) { - Qt::Key key = keymoves.at(i); + for (const Qt::Key key : keymoves) { int valueBeforeClick = scrollBar->value(); - if (valueBeforeClick >= scrollBar->singleStep()) - checkScroll = true; - else - checkScroll = false; + const bool checkScroll = (valueBeforeClick >= scrollBar->singleStep()); QTest::keyClick(testWidget, key); - QApplication::instance()->processEvents(); + QCoreApplication::processEvents(); switch (key) { case Qt::Key_Up: @@ -1611,15 +1593,15 @@ void tst_QTreeWidget::scrollToItem() // Check if all parent nodes of the item found are expanded. // Reported in task #78761 QTreeWidgetItem *search = nullptr; - for (int i=0; i<2; ++i) { + for (int i = 0; i < 2; ++i) { QTreeWidgetItem *bar = new QTreeWidgetItem(testWidget); bar->setText(0, QString::number(i)); - for (int j=0; j<2; ++j) { + for (int j = 0; j < 2; ++j) { QTreeWidgetItem *foo = new QTreeWidgetItem(bar); foo->setText(0, bar->text(0) + QString::number(j)); - for (int k=0; k<2; ++k) { + for (int k = 0; k < 2; ++k) { search = new QTreeWidgetItem(foo); search->setText(0, foo->text(0) + QString::number(k)); } @@ -1639,8 +1621,7 @@ void tst_QTreeWidget::scrollToItem() // From task #85413 void tst_QTreeWidget::setSortingEnabled() { - QStringList hl; - hl << "ID"; + const QStringList hl{ "ID" }; testWidget->setColumnCount(hl.count()); testWidget->setHeaderLabels(hl); @@ -1682,14 +1663,14 @@ void tst_QTreeWidget::addChild() { QTreeWidget tree; for (int x = 0; x < 2; ++x) { - QTreeWidget *view = x ? &tree : static_cast<QTreeWidget*>(0); - QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)view); + QTreeWidget *view = x ? &tree : static_cast<QTreeWidget*>(nullptr); + QTreeWidgetItem *item = new QTreeWidgetItem(view); QCOMPARE(item->childCount(), 0); // try to add 0 - item->addChild(0); + item->addChild(nullptr); QCOMPARE(item->childCount(), 0); - QCOMPARE(item->indexOfChild(0), -1); + QCOMPARE(item->indexOfChild(nullptr), -1); // add one at a time QList<QTreeWidgetItem*> children; @@ -1762,11 +1743,11 @@ void tst_QTreeWidget::setData() testWidget->setHeaderItem(headerItem); QSignalSpy headerDataChangedSpy( - testWidget->model(), SIGNAL(headerDataChanged(Qt::Orientation,int,int))); + testWidget->model(), &QAbstractItemModel::headerDataChanged); QSignalSpy dataChangedSpy( - testWidget->model(), SIGNAL(dataChanged(QModelIndex,QModelIndex))); + testWidget->model(), &QAbstractItemModel::dataChanged); QSignalSpy itemChangedSpy( - testWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int))); + testWidget, &QTreeWidget::itemChanged); headerItem->setText(0, "test"); QCOMPARE(dataChangedSpy.count(), 0); QCOMPARE(headerDataChangedSpy.count(), 1); @@ -1777,7 +1758,7 @@ void tst_QTreeWidget::setData() { QSignalSpy itemChangedSpy( - testWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int))); + testWidget, &QTreeWidget::itemChanged); QTreeWidgetItem *item = new QTreeWidgetItem(); testWidget->addTopLevelItem(item); for (int x = 0; x < 2; ++x) { @@ -1999,10 +1980,10 @@ void tst_QTreeWidget::itemData() item.setData(0, Qt::DisplayRole, QString("0")); QCOMPARE(widget.currentRoles, QVector<int>({Qt::DisplayRole, Qt::EditRole})); item.setData(0, Qt::CheckStateRole, Qt::PartiallyChecked); - QCOMPARE(widget.currentRoles, {Qt::CheckStateRole}); + QCOMPARE(widget.currentRoles, QVector<int>{Qt::CheckStateRole}); for (int i = 0; i < 4; ++i) { item.setData(0, Qt::UserRole + i, QString::number(i + 1)); - QCOMPARE(widget.currentRoles, {Qt::UserRole + i}); + QCOMPARE(widget.currentRoles, QVector<int>{Qt::UserRole + i}); } QMap<int, QVariant> flags = widget.model()->itemData(widget.model()->index(0, 0)); QCOMPARE(flags.count(), 6); @@ -2069,7 +2050,7 @@ void tst_QTreeWidget::setHeaderLabels() void tst_QTreeWidget::setHeaderItem() { - testWidget->setHeaderItem(0); + testWidget->setHeaderItem(nullptr); QTreeWidgetItem *headerItem = new QTreeWidgetItem(); testWidget->setColumnCount(0); @@ -2118,7 +2099,7 @@ void tst_QTreeWidget::itemWidget() QFETCH(TreeItemList, topLevelItems); QTreeWidget tree; - populate(&tree, topLevelItems, new TreeItem(QStringList() << "1" << "2")); + populate(&tree, topLevelItems, new TreeItem({"1", "2"})); tree.show(); for (int x = 0; x < 2; ++x) { @@ -2126,18 +2107,18 @@ void tst_QTreeWidget::itemWidget() while (QTreeWidgetItem *item = (*it++)) { for (int col = 0; col < item->columnCount(); ++col) { if (x == 0) { - QCOMPARE(tree.itemWidget(item, col), static_cast<QWidget*>(0)); + QCOMPARE(tree.itemWidget(item, col), nullptr); QWidget *editor = new QLineEdit(); tree.setItemWidget(item, col, editor); QCOMPARE(tree.itemWidget(item, col), editor); tree.removeItemWidget(item, col); - QCOMPARE(tree.itemWidget(item, col), static_cast<QWidget*>(0)); + QCOMPARE(tree.itemWidget(item, col), nullptr); } else { // ### should you really be able to open a persistent // editor for an item that isn't editable?? tree.openPersistentEditor(item, col); QWidget *editor = tree.findChild<QLineEdit*>(); - QVERIFY(editor != 0); + QVERIFY(editor != nullptr); tree.closePersistentEditor(item, col); } } @@ -2147,50 +2128,50 @@ void tst_QTreeWidget::itemWidget() void tst_QTreeWidget::insertItemsWithSorting_data() { - QTest::addColumn<int>("sortOrder"); + QTest::addColumn<Qt::SortOrder>("sortOrder"); QTest::addColumn<QStringList>("initialItems"); QTest::addColumn<QStringList>("insertItems"); QTest::addColumn<QStringList>("expectedItems"); QTest::addColumn<IntList>("expectedRows"); QTest::newRow("() + (a) = (a)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << QStringList() << (QStringList() << "a") << (QStringList() << "a") << IntList(); QTest::newRow("() + (c, b, a) = (a, b, c)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << QStringList() << (QStringList() << "c" << "b" << "a") << (QStringList() << "a" << "b" << "c") << IntList(); QTest::newRow("() + (a, b, c) = (c, b, a)") - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << QStringList() << (QStringList() << "a" << "b" << "c") << (QStringList() << "c" << "b" << "a") << IntList(); QTest::newRow("(a) + (b) = (a, b)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << QStringList("a") << (QStringList() << "b") << (QStringList() << "a" << "b") << (IntList() << 0); QTest::newRow("(a) + (b) = (b, a)") - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << QStringList("a") << (QStringList() << "b") << (QStringList() << "b" << "a") << (IntList() << 1); QTest::newRow("(a, c, b) + (d) = (a, b, c, d)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "c" << "b") << (QStringList() << "d") << (QStringList() << "a" << "b" << "c" << "d") << (IntList() << 0 << 1 << 2); QTest::newRow("(b, c, a) + (d) = (d, c, b, a)") - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << (QStringList() << "b" << "c" << "a") << (QStringList() << "d") << (QStringList() << "d" << "c" << "b" << "a") @@ -2200,38 +2181,38 @@ void tst_QTreeWidget::insertItemsWithSorting_data() IntList reverseRows; QStringList ascendingItems; QStringList reverseItems; - for (int i = 'a'; i <= 'z'; ++i) { + for (char i = 'a'; i <= 'z'; ++i) { ascendingItems << QString(1, QLatin1Char(i)); reverseItems << QString(1, QLatin1Char('z' - i + 'a')); ascendingRows << i - 'a'; reverseRows << 'z' - i + 'a'; } QTest::newRow("() + (sorted items) = (sorted items)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << QStringList() << ascendingItems << ascendingItems << IntList(); QTest::newRow("(sorted items) + () = (sorted items)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << ascendingItems << QStringList() << ascendingItems << ascendingRows; QTest::newRow("() + (ascending items) = (reverse items)") - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << QStringList() << ascendingItems << reverseItems << IntList(); QTest::newRow("(reverse items) + () = (ascending items)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << reverseItems << QStringList() << ascendingItems << ascendingRows; QTest::newRow("(reverse items) + () = (reverse items)") - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << reverseItems << QStringList() << reverseItems @@ -2241,57 +2222,57 @@ void tst_QTreeWidget::insertItemsWithSorting_data() void tst_QTreeWidget::insertItemsWithSorting() { - QFETCH(int, sortOrder); - QFETCH(QStringList, initialItems); - QFETCH(QStringList, insertItems); - QFETCH(QStringList, expectedItems); + QFETCH(Qt::SortOrder, sortOrder); + QFETCH(const QStringList, initialItems); + QFETCH(const QStringList, insertItems); + QFETCH(const QStringList, expectedItems); QFETCH(IntList, expectedRows); for (int method = 0; method < 5; ++method) { QTreeWidget w; w.setSortingEnabled(true); - w.sortItems(0, static_cast<Qt::SortOrder>(sortOrder)); - for (int i = 0; i < initialItems.count(); ++i) - w.addTopLevelItem(new QTreeWidgetItem(QStringList() << initialItems.at(i))); + w.sortItems(0, sortOrder); + for (const QString &initialItem : initialItems) + w.addTopLevelItem(new QTreeWidgetItem({initialItem})); QAbstractItemModel *model = w.model(); - QList<QPersistentModelIndex> persistent; + PersistentModelIndexVec persistent; for (int j = 0; j < model->rowCount(QModelIndex()); ++j) persistent << model->index(j, 0, QModelIndex()); switch (method) { case 0: // insert using item constructor - for (int i = 0; i < insertItems.size(); ++i) - new QTreeWidgetItem(&w, QStringList() << insertItems.at(i)); + for (const QString &txt : insertItems) + new QTreeWidgetItem(&w, { txt }); break; case 1: { // insert using insertTopLevelItems() QList<QTreeWidgetItem*> lst; - for (int i = 0; i < insertItems.size(); ++i) - lst << new QTreeWidgetItem(QStringList() << insertItems.at(i)); + for (const QString &txt : insertItems) + lst << new QTreeWidgetItem({ txt }); w.insertTopLevelItems(0, lst); break; } case 2: // insert using insertTopLevelItem() - for (int i = 0; i < insertItems.size(); ++i) - w.insertTopLevelItem(0, new QTreeWidgetItem(QStringList() << insertItems.at(i))); + for (const QString &txt : insertItems) + w.insertTopLevelItem(0, new QTreeWidgetItem({ txt })); break; case 3: { // insert using addTopLevelItems() QList<QTreeWidgetItem*> lst; - for (int i = 0; i < insertItems.size(); ++i) - lst << new QTreeWidgetItem(QStringList() << insertItems.at(i)); + for (const QString &txt : insertItems) + lst << new QTreeWidgetItem({ txt }); w.addTopLevelItems(lst); break; } case 4: // insert using addTopLevelItem() - for (int i = 0; i < insertItems.size(); ++i) - w.addTopLevelItem(new QTreeWidgetItem(QStringList() << insertItems.at(i))); + for (const QString &txt : insertItems) + w.addTopLevelItem(new QTreeWidgetItem({ txt })); break; } QCOMPARE(w.topLevelItemCount(), expectedItems.count()); @@ -2305,8 +2286,8 @@ void tst_QTreeWidget::insertItemsWithSorting() void tst_QTreeWidget::insertExpandedItemsWithSorting_data() { - QTest::addColumn<QStringList>("parentText"); - QTest::addColumn<QStringList>("childText"); + QTest::addColumn<QStringList>("parentTexts"); + QTest::addColumn<QStringList>("childTexts"); QTest::addColumn<QStringList>("parentResult"); QTest::addColumn<QStringList>("childResult"); QTest::newRow("test 1") @@ -2319,36 +2300,36 @@ void tst_QTreeWidget::insertExpandedItemsWithSorting_data() // From Task 134978 void tst_QTreeWidget::insertExpandedItemsWithSorting() { - QFETCH(QStringList, parentText); - QFETCH(QStringList, childText); - QFETCH(QStringList, parentResult); - QFETCH(QStringList, childResult); + QFETCH(const QStringList, parentTexts); + QFETCH(const QStringList, childTexts); + QFETCH(const QStringList, parentResult); + QFETCH(const QStringList, childResult); // create a tree with autosorting enabled - CustomTreeWidget tree; + PublicTreeWidget tree; tree.setSortingEnabled(true); // insert expanded items in unsorted order - QList<QTreeWidgetItem *> items; - for (int i = 0; i < parentText.count(); ++i) { - QTreeWidgetItem *parent = new QTreeWidgetItem(&tree, QStringList(parentText.at(i))); + QVector<QTreeWidgetItem *> items; + for (const QString &text : parentTexts) { + QTreeWidgetItem *parent = new QTreeWidgetItem(&tree, {text}); parent->setExpanded(true); QVERIFY(parent->isExpanded()); items << parent; - for (int j = 0; j < childText.count(); ++j) { - QTreeWidgetItem *child = new QTreeWidgetItem(parent, QStringList(childText.at(j))); + for (const QString &text : childTexts) { + QTreeWidgetItem *child = new QTreeWidgetItem(parent, {text}); items << child; } - QCOMPARE(parent->childCount(), childText.count()); + QCOMPARE(parent->childCount(), childTexts.count()); QVERIFY(parent->isExpanded()); } - QCOMPARE(tree.model()->rowCount(), parentText.count()); + QCOMPARE(tree.model()->rowCount(), parentTexts.count()); // verify that the items are still expanded - foreach (QTreeWidgetItem *item, items) { + for (const QTreeWidgetItem *item : qAsConst(items)) { if (item->childCount() > 0) QVERIFY(item->isExpanded()); - QModelIndex idx = tree.indexFromItem(const_cast<QTreeWidgetItem *>(item)); + QModelIndex idx = tree.indexFromItem(item); QVERIFY(idx.isValid()); //QRect rect = tree.visualRect(idx); //QVERIFY(rect.isValid()); @@ -2357,16 +2338,12 @@ void tst_QTreeWidget::insertExpandedItemsWithSorting() // verify that the tree is sorted QAbstractItemModel *model = tree.model(); - QList<QPersistentModelIndex> parents; - for (int i = 0; i < model->rowCount(QModelIndex()); ++i) { - QPersistentModelIndex parent = model->index(i, 0, QModelIndex()); - parents << parent; - } - QList<QPersistentModelIndex> children; - for (int i = 0; i < model->rowCount(parents.first()); ++i) { - QPersistentModelIndex child = model->index(i, 0, parents.first()); - children << child; - } + PersistentModelIndexVec parents; + for (int i = 0; i < model->rowCount(QModelIndex()); ++i) + parents.push_back(model->index(i, 0, QModelIndex())); + PersistentModelIndexVec children; + for (int i = 0; i < model->rowCount(parents.constFirst()); ++i) + children.push_back(model->index(i, 0, parents.constFirst())); for (int i = 0; i < parentResult.count(); ++i) { QTreeWidgetItem *item = tree.topLevelItem(i); QCOMPARE(item->text(0), parentResult.at(i)); @@ -2377,7 +2354,7 @@ void tst_QTreeWidget::insertExpandedItemsWithSorting() void tst_QTreeWidget::changeDataWithSorting_data() { - QTest::addColumn<int>("sortOrder"); + QTest::addColumn<Qt::SortOrder>("sortOrder"); QTest::addColumn<QStringList>("initialItems"); QTest::addColumn<int>("itemIndex"); QTest::addColumn<QString>("newValue"); @@ -2386,49 +2363,49 @@ void tst_QTreeWidget::changeDataWithSorting_data() QTest::addColumn<bool>("reorderingExpected"); QTest::newRow("change a to b in (a)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a") << 0 << "b" << (QStringList() << "b") << (IntList() << 0) << false; QTest::newRow("change a to b in (a, c)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "c") << 0 << "b" << (QStringList() << "b" << "c") << (IntList() << 0 << 1) << false; QTest::newRow("change a to c in (a, b)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "b") << 0 << "c" << (QStringList() << "b" << "c") << (IntList() << 1 << 0) << true; QTest::newRow("change c to a in (c, b)") - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << (QStringList() << "c" << "b") << 0 << "a" << (QStringList() << "b" << "a") << (IntList() << 1 << 0) << true; QTest::newRow("change e to i in (a, c, e, g)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "c" << "e" << "g") << 2 << "i" << (QStringList() << "a" << "c" << "g" << "i") << (IntList() << 0 << 1 << 3 << 2) << true; QTest::newRow("change e to a in (c, e, g, i)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "c" << "e" << "g" << "i") << 1 << "a" << (QStringList() << "a" << "c" << "g" << "i") << (IntList() << 1 << 0 << 2 << 3) << true; QTest::newRow("change e to f in (c, e, g, i)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "c" << "e" << "g" << "i") << 1 << "f" << (QStringList() << "c" << "f" << "g" << "i") @@ -2438,35 +2415,35 @@ void tst_QTreeWidget::changeDataWithSorting_data() void tst_QTreeWidget::changeDataWithSorting() { - QFETCH(int, sortOrder); - QFETCH(QStringList, initialItems); + QFETCH(Qt::SortOrder, sortOrder); + QFETCH(const QStringList, initialItems); QFETCH(int, itemIndex); - QFETCH(QString, newValue); - QFETCH(QStringList, expectedItems); - QFETCH(IntList, expectedRows); + QFETCH(const QString, newValue); + QFETCH(const QStringList, expectedItems); + QFETCH(const IntList, expectedRows); QFETCH(bool, reorderingExpected); QTreeWidget w; w.setSortingEnabled(true); - w.sortItems(0, static_cast<Qt::SortOrder>(sortOrder)); - for (int i = 0; i < initialItems.count(); ++i) - w.addTopLevelItem(new QTreeWidgetItem(QStringList() << initialItems.at(i))); + w.sortItems(0, sortOrder); + for (const QString &str : initialItems) + w.addTopLevelItem(new QTreeWidgetItem({ str })); QAbstractItemModel *model = w.model(); - QList<QPersistentModelIndex> persistent; + PersistentModelIndexVec persistent; for (int j = 0; j < model->rowCount(QModelIndex()); ++j) persistent << model->index(j, 0, QModelIndex()); - QSignalSpy dataChangedSpy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex))); - QSignalSpy layoutChangedSpy(model, SIGNAL(layoutChanged())); + QSignalSpy dataChangedSpy(model, &QAbstractItemModel::dataChanged); + QSignalSpy layoutChangedSpy(model, &QAbstractItemModel::layoutChanged); QTreeWidgetItem *item = w.topLevelItem(itemIndex); item->setText(0, newValue); for (int i = 0; i < expectedItems.count(); ++i) { QCOMPARE(w.topLevelItem(i)->text(0), expectedItems.at(i)); - for (int j = 0; j < persistent.count(); ++j) { - if (persistent.at(j).row() == i) // the same toplevel row - QCOMPARE(persistent.at(j).internalPointer(), (void *)w.topLevelItem(i)); + for (const QPersistentModelIndex &p : qAsConst(persistent)) { + if (p.row() == i) // the same toplevel row + QCOMPARE(p.internalPointer(), static_cast<void *>(w.topLevelItem(i))); } } @@ -2479,7 +2456,7 @@ void tst_QTreeWidget::changeDataWithSorting() void tst_QTreeWidget::changeDataWithStableSorting_data() { - QTest::addColumn<int>("sortOrder"); + QTest::addColumn<Qt::SortOrder>("sortOrder"); QTest::addColumn<QStringList>("initialItems"); QTest::addColumn<int>("itemIndex"); QTest::addColumn<QString>("newValue"); @@ -2489,7 +2466,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() QTest::addColumn<bool>("forceChange"); QTest::newRow("change a to c in (a, c, c, c, e)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "c" << "c" << "c" << "e") << 0 << "c" << (QStringList() << "c" << "c" << "c" << "c" << "e") @@ -2497,7 +2474,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() << false << false; QTest::newRow("change e to c in (a, c, c, c, e)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "c" << "c" << "c" << "e") << 4 << "c" << (QStringList() << "a" << "c" << "c" << "c" << "c") @@ -2505,7 +2482,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() << false << false; QTest::newRow("change 1st c to c in (a, c, c, c, e)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "c" << "c" << "c" << "e") << 1 << "c" << (QStringList() << "a" << "c" << "c" << "c" << "e") @@ -2513,7 +2490,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() << false << true; QTest::newRow("change 2nd c to c in (a, c, c, c, e)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "c" << "c" << "c" << "e") << 2 << "c" << (QStringList() << "a" << "c" << "c" << "c" << "e") @@ -2521,7 +2498,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() << false << true; QTest::newRow("change 3rd c to c in (a, c, c, c, e)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "c" << "c" << "c" << "e") << 3 << "c" << (QStringList() << "a" << "c" << "c" << "c" << "e") @@ -2529,7 +2506,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() << false << true; QTest::newRow("change 1st c to c in (e, c, c, c, a)") - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << (QStringList() << "e" << "c" << "c" << "c" << "a") << 1 << "c" << (QStringList() << "e" << "c" << "c" << "c" << "a") @@ -2537,7 +2514,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() << false << true; QTest::newRow("change 2nd c to c in (e, c, c, c, a)") - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << (QStringList() << "e" << "c" << "c" << "c" << "a") << 2 << "c" << (QStringList() << "e" << "c" << "c" << "c" << "a") @@ -2545,7 +2522,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() << false << true; QTest::newRow("change 3rd c to c in (e, c, c, c, a)") - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << (QStringList() << "e" << "c" << "c" << "c" << "a") << 3 << "c" << (QStringList() << "e" << "c" << "c" << "c" << "a") @@ -2553,7 +2530,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() << false << true; QTest::newRow("change 1st c to b in (a, c, c, c, e)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "c" << "c" << "c" << "e") << 1 << "b" << (QStringList() << "a" << "b" << "c" << "c" << "e") @@ -2561,7 +2538,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() << false << false; QTest::newRow("change 2nd c to b in (a, c, c, c, e)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "c" << "c" << "c" << "e") << 2 << "b" << (QStringList() << "a" << "b" << "c" << "c" << "e") @@ -2569,7 +2546,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() << true << false; QTest::newRow("change 3rd c to b in (a, c, c, c, e)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "c" << "c" << "c" << "e") << 3 << "b" << (QStringList() << "a" << "b" << "c" << "c" << "e") @@ -2577,7 +2554,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() << true << false; QTest::newRow("change 1st c to d in (a, c, c, c, e)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "c" << "c" << "c" << "e") << 1 << "d" << (QStringList() << "a" << "c" << "c" << "d" << "e") @@ -2585,7 +2562,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() << true << false; QTest::newRow("change 2nd c to d in (a, c, c, c, e)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "c" << "c" << "c" << "e") << 2 << "d" << (QStringList() << "a" << "c" << "c" << "d" << "e") @@ -2593,7 +2570,7 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() << true << false; QTest::newRow("change 3rd c to d in (a, c, c, c, e)") - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << (QStringList() << "a" << "c" << "c" << "c" << "e") << 3 << "d" << (QStringList() << "a" << "c" << "c" << "d" << "e") @@ -2604,47 +2581,38 @@ void tst_QTreeWidget::changeDataWithStableSorting_data() void tst_QTreeWidget::changeDataWithStableSorting() { - QFETCH(int, sortOrder); - QFETCH(QStringList, initialItems); + QFETCH(Qt::SortOrder, sortOrder); + QFETCH(const QStringList, initialItems); QFETCH(int, itemIndex); - QFETCH(QString, newValue); - QFETCH(QStringList, expectedItems); - QFETCH(IntList, expectedRows); + QFETCH(const QString, newValue); + QFETCH(const QStringList, expectedItems); + QFETCH(const IntList, expectedRows); QFETCH(bool, reorderingExpected); QFETCH(bool, forceChange); - class StableItem : public QTreeWidgetItem - { - public: - StableItem(const QStringList &strings) : QTreeWidgetItem(strings, QTreeWidgetItem::UserType) {} - void forceChangeData() { - emitDataChanged(); - } - }; - QTreeWidget w; w.setSortingEnabled(true); - w.sortItems(0, static_cast<Qt::SortOrder>(sortOrder)); - for (int i = 0; i < initialItems.count(); ++i) - w.addTopLevelItem(new StableItem(QStringList() << initialItems.at(i))); + w.sortItems(0, sortOrder); + for (const QString &str : initialItems) + w.addTopLevelItem(new PublicTreeItem({ str })); QAbstractItemModel *model = w.model(); - QList<QPersistentModelIndex> persistent; + PersistentModelIndexVec persistent; for (int j = 0; j < model->rowCount(QModelIndex()); ++j) persistent << model->index(j, 0, QModelIndex()); - QSignalSpy dataChangedSpy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex))); - QSignalSpy layoutChangedSpy(model, SIGNAL(layoutChanged())); + QSignalSpy dataChangedSpy(model, &QAbstractItemModel::dataChanged); + QSignalSpy layoutChangedSpy(model, &QAbstractItemModel::layoutChanged); - StableItem *item = static_cast<StableItem *>(w.topLevelItem(itemIndex)); + auto *item = static_cast<PublicTreeItem *>(w.topLevelItem(itemIndex)); item->setText(0, newValue); if (forceChange) - item->forceChangeData(); + item->emitDataChanged(); for (int i = 0; i < expectedItems.count(); ++i) { QCOMPARE(w.topLevelItem(i)->text(0), expectedItems.at(i)); - for (int j = 0; j < persistent.count(); ++j) { - if (persistent.at(j).row() == i) // the same toplevel row - QCOMPARE(persistent.at(j).internalPointer(), (void *)w.topLevelItem(i)); + for (const QPersistentModelIndex &p : qAsConst(persistent)) { + if (p.row() == i) // the same toplevel row + QCOMPARE(p.internalPointer(), static_cast<void *>(w.topLevelItem(i))); } } @@ -2657,24 +2625,24 @@ void tst_QTreeWidget::changeDataWithStableSorting() void tst_QTreeWidget::sizeHint_data() { - QTest::addColumn<int>("scrollBarPolicy"); + QTest::addColumn<Qt::ScrollBarPolicy>("scrollBarPolicy"); QTest::addColumn<QSize>("viewSize"); - QTest::newRow("ScrollBarAlwaysOn") << static_cast<int>(Qt::ScrollBarAlwaysOn) << QSize(); - QTest::newRow("ScrollBarAlwaysOff") << static_cast<int>(Qt::ScrollBarAlwaysOff) << QSize(); + QTest::newRow("ScrollBarAlwaysOn") << Qt::ScrollBarAlwaysOn << QSize(); + QTest::newRow("ScrollBarAlwaysOff") << Qt::ScrollBarAlwaysOff << QSize(); // make sure the scrollbars are shown by resizing the view to 40x40 - QTest::newRow("ScrollBarAsNeeded (40x40)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(40, 40); - QTest::newRow("ScrollBarAsNeeded (1000x1000)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(1000, 1000); + QTest::newRow("ScrollBarAsNeeded (40x40)") << Qt::ScrollBarAsNeeded << QSize(40, 40); + QTest::newRow("ScrollBarAsNeeded (1000x1000)") << Qt::ScrollBarAsNeeded << QSize(1000, 1000); } void tst_QTreeWidget::sizeHint() { - QFETCH(int, scrollBarPolicy); + QFETCH(Qt::ScrollBarPolicy, scrollBarPolicy); QFETCH(QSize, viewSize); QTreeWidget view; view.setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); - view.setVerticalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy)); - view.setHorizontalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy)); + view.setVerticalScrollBarPolicy(scrollBarPolicy); + view.setHorizontalScrollBarPolicy(scrollBarPolicy); view.setColumnCount(2); for (int i = 0 ; i < view.columnCount(); ++i) view.addTopLevelItem(new QTreeWidgetItem(QStringList{"foo","bar"})); @@ -2726,36 +2694,36 @@ void tst_QTreeWidget::itemOperatorLessThan() void tst_QTreeWidget::sortedIndexOfChild_data() { - QTest::addColumn<int>("sortOrder"); + QTest::addColumn<Qt::SortOrder>("sortOrder"); QTest::addColumn<QStringList>("itemTexts"); - QTest::addColumn<QList<int> >("expectedIndexes"); + QTest::addColumn<IntList>("expectedIndexes"); QTest::newRow("three ascending") - << int(Qt::AscendingOrder) - << (QStringList() << "A" << "B" << "C") - << (QList<int>() << 0 << 1 << 2); + << Qt::AscendingOrder + << (QStringList{"A", "B", "C"}) + << (IntList{0, 1, 2}); QTest::newRow("three descending") - << int(Qt::DescendingOrder) - << (QStringList() << "A" << "B" << "C") - << (QList<int>() << 2 << 1 << 0); + << Qt::DescendingOrder + << (QStringList{"A", "B", "C"}) + << (IntList{2, 1, 0}); } void tst_QTreeWidget::sortedIndexOfChild() { - QFETCH(int, sortOrder); - QFETCH(QStringList, itemTexts); - QFETCH(QList<int>, expectedIndexes); + QFETCH(Qt::SortOrder, sortOrder); + QFETCH(const QStringList, itemTexts); + QFETCH(const IntList, expectedIndexes); QTreeWidget tw; - QList<QTreeWidgetItem*> itms; - QTreeWidgetItem *top = new QTreeWidgetItem(&tw, QStringList() << "top"); + QVector<QTreeWidgetItem *> itms; + auto *top = new QTreeWidgetItem(&tw, {"top"}); - for (int i = 0; i < itemTexts.count(); ++i) - itms << new QTreeWidgetItem(top, QStringList() << itemTexts.at(i)); + for (const QString &str : itemTexts) + itms << new QTreeWidgetItem(top, {str}); - tw.sortItems(0, (Qt::SortOrder)sortOrder); + tw.sortItems(0, sortOrder); tw.expandAll(); QCOMPARE(itms.count(), expectedIndexes.count()); @@ -2773,8 +2741,8 @@ void tst_QTreeWidget::expandAndCallapse() for (int j = 0; j < 10; ++j) new QTreeWidgetItem(p, QStringList(QString::number(j))); } - QSignalSpy spy0(&tw, SIGNAL(itemExpanded(QTreeWidgetItem*))); - QSignalSpy spy1(&tw, SIGNAL(itemCollapsed(QTreeWidgetItem*))); + QSignalSpy spy0(&tw, &QTreeWidget::itemExpanded); + QSignalSpy spy1(&tw, &QTreeWidget::itemCollapsed); tw.expandItem(p); @@ -2909,20 +2877,12 @@ void tst_QTreeWidget::removeSelectedItem() QCOMPARE(selModel->isSelected(w->model()->index(0,0)), false); } -class AnotherTreeWidget : public QTreeWidget -{ - Q_OBJECT -public: - AnotherTreeWidget(QWidget *parent = 0) : QTreeWidget(parent) {} - void deleteCurrent() { if (currentItem()) delete currentItem(); } -}; - void tst_QTreeWidget::removeCurrentItem() { - AnotherTreeWidget widget; - QObject::connect(widget.selectionModel(), - SIGNAL(currentChanged(QModelIndex,QModelIndex)), - &widget, SLOT(clear())); + PublicTreeWidget widget; + connect(widget.selectionModel(), + &QItemSelectionModel::currentChanged, + &widget, &PublicTreeWidget::clear); QTreeWidgetItem *item = new QTreeWidgetItem(&widget); widget.setCurrentItem(item); widget.deleteCurrent(); @@ -2930,9 +2890,9 @@ void tst_QTreeWidget::removeCurrentItem() void tst_QTreeWidget::removeCurrentItem_task186451() { - AnotherTreeWidget widget; - QTreeWidgetItem *item = new QTreeWidgetItem(&widget, QStringList() << "1"); - QTreeWidgetItem *item2 = new QTreeWidgetItem(&widget, QStringList() << "2"); + PublicTreeWidget widget; + QTreeWidgetItem *item = new QTreeWidgetItem(&widget, {"1"}); + QTreeWidgetItem *item2 = new QTreeWidgetItem(&widget, {"2"}); widget.setCurrentItem(item); widget.deleteCurrent(); @@ -2940,19 +2900,6 @@ void tst_QTreeWidget::removeCurrentItem_task186451() QCOMPARE(item2, widget.currentItem()); } - -class TreeWidget : QTreeWidget { - -public: - QModelIndex indexFromItem(QTreeWidgetItem *item, int column = 0) const { - return QTreeWidget::indexFromItem(item, column); - } - QTreeWidgetItem *itemFromIndex(const QModelIndex &index) const { - return QTreeWidget::itemFromIndex(index); - } -}; - - void tst_QTreeWidget::randomExpand() { QTreeWidget tree; @@ -2970,9 +2917,8 @@ void tst_QTreeWidget::randomExpand() \- item4 */ - QTreeWidgetItem *newItem1 = 0; for (int i = 0; i < 100; i++) { - newItem1 = new QTreeWidgetItem(&tree, item1); + auto newItem1 = new QTreeWidgetItem(&tree, item1); newItem1->setExpanded(true); QCOMPARE(newItem1->isExpanded(), true); @@ -2982,35 +2928,34 @@ void tst_QTreeWidget::randomExpand() QCOMPARE(newItem1->isExpanded(), true); } - } void tst_QTreeWidget::crashTest() { - QTreeWidget *tree = new QTreeWidget(); - tree->setColumnCount(1); - tree->show(); + QTreeWidget tree; + tree.setColumnCount(1); + tree.show(); - QTreeWidgetItem *item1 = new QTreeWidgetItem(tree); + QTreeWidgetItem *item1 = new QTreeWidgetItem(&tree); item1->setText(0, "item1"); item1->setExpanded(true); QTreeWidgetItem *item2 = new QTreeWidgetItem(item1); item2->setText(0, "item2"); - QTreeWidgetItem *item3 = new QTreeWidgetItem(tree, item1); + QTreeWidgetItem *item3 = new QTreeWidgetItem(&tree, item1); item3->setText(0, "item3"); item3->setExpanded(true); QTreeWidgetItem *item4 = new QTreeWidgetItem(item3); item4->setText(0, "item4"); - QTreeWidgetItem *item5 = new QTreeWidgetItem(tree, item3); + QTreeWidgetItem *item5 = new QTreeWidgetItem(&tree, item3); item5->setText(0, "item5"); item5->setExpanded(true); QTreeWidgetItem *item6 = new QTreeWidgetItem(item5); item6->setText(0, "item6"); for (int i = 0; i < 1000; i++) { - QTreeWidgetItem *newItem1 = new QTreeWidgetItem(tree, item1); + QTreeWidgetItem *newItem1 = new QTreeWidgetItem(&tree, item1); newItem1->setText(0, "newItem"); QTreeWidgetItem *newItem2 = new QTreeWidgetItem(newItem1); newItem2->setText(0, "subItem1"); @@ -3019,23 +2964,23 @@ void tst_QTreeWidget::crashTest() delete item3; item3 = newItem1; } - QApplication::instance()->processEvents(); - - delete tree; + QCoreApplication::processEvents(); } class CrashWidget : public QTreeWidget { public: - CrashWidget(QWidget *parent = 0) : QTreeWidget(parent), i(0) { + CrashWidget(QWidget *parent = nullptr) : QTreeWidget(parent) + { setSortingEnabled(true); timerId = startTimer(10); } - int i; + int i = 0; protected: - void timerEvent(QTimerEvent * event) { + void timerEvent(QTimerEvent * event) override + { if (event->timerId() == timerId) { - QTreeWidgetItem *newItem = new QTreeWidgetItem((QStringList() << QString::number(i++))); + auto newItem = new QTreeWidgetItem({QString::number(i++)}); m_list.append(newItem); insertTopLevelItem(0, newItem); while (m_list.count() > 10) @@ -3045,7 +2990,7 @@ protected: } private: int timerId; - QList<QTreeWidgetItem*> m_list; + QVector<QTreeWidgetItem*> m_list; }; void tst_QTreeWidget::sortAndSelect() @@ -3068,12 +3013,13 @@ void tst_QTreeWidget::defaultRowSizes() const QScopedPointer<QTreeWidget> tw(new QTreeWidget); tw->setIconSize(QSize(50, 50)); tw->setColumnCount(6); - for (int i=0; i<10; ++i) { + for (int i = 0; i < 10; ++i) { auto it = new QTreeWidgetItem(tw.data()); - for (int j=0; j<tw->columnCount() - 1; ++j) { + for (int j = 0; j < tw->columnCount() - 1; ++j) it->setText(j, "This is a test"); - } - QPixmap icon = tw->style()->standardPixmap((QStyle::StandardPixmap)(i + QStyle::SP_TitleBarMenuButton)); + auto sp = static_cast<QStyle::StandardPixmap>(i + QStyle::SP_TitleBarMenuButton); + QPixmap icon = tw->style()->standardPixmap(sp); + if (icon.isNull()) QSKIP("No pixmap found on current style, skipping this test."); it->setIcon(tw->columnCount() - 1, @@ -3089,8 +3035,8 @@ void tst_QTreeWidget::defaultRowSizes() void tst_QTreeWidget::task191552_rtl() { - Qt::LayoutDirection oldDir = qApp->layoutDirection(); - qApp->setLayoutDirection(Qt::RightToLeft); + Qt::LayoutDirection oldDir = QGuiApplication::layoutDirection(); + QGuiApplication::setLayoutDirection(Qt::RightToLeft); QTreeWidget tw; tw.setColumnCount(1); @@ -3111,7 +3057,7 @@ void tst_QTreeWidget::task191552_rtl() QTest::mouseClick(tw.viewport(), Qt::LeftButton, Qt::NoModifier, checkRect.center()); QCOMPARE(item->checkState(0), Qt::Unchecked); - qApp->setLayoutDirection(oldDir); + QGuiApplication::setLayoutDirection(oldDir); } void tst_QTreeWidget::task203673_selection() @@ -3210,7 +3156,7 @@ void tst_QTreeWidget::task253109_itemHeight() QTreeWidgetItem item(&treeWidget); class MyWidget : public QWidget { - virtual QSize sizeHint() const { return QSize(200,100); } + QSize sizeHint() const override { return QSize(200, 100); } } w; treeWidget.setItemWidget(&item, 0, &w); @@ -3230,24 +3176,23 @@ void tst_QTreeWidget::task206367_duplication() treeWidget.setHeaderHidden(true); treeWidget.setSortingEnabled(true); - QTreeWidgetItem* rootItem = new QTreeWidgetItem( &treeWidget, QStringList("root") ); + QTreeWidgetItem* rootItem = new QTreeWidgetItem(&treeWidget, QStringList("root")); for (int nFile = 0; nFile < 2; nFile++ ) { - QTreeWidgetItem* itemFile = new QTreeWidgetItem(rootItem, QStringList(QString::number(nFile))); + QTreeWidgetItem* itemFile = new QTreeWidgetItem(rootItem, {QString::number(nFile)}); for (int nRecord = 0; nRecord < 2; nRecord++) - new QTreeWidgetItem(itemFile , QStringList(QString::number(nRecord))); + new QTreeWidgetItem(itemFile, {QString::number(nRecord)}); itemFile->setExpanded(true); } rootItem->setExpanded(true); //there should be enough room for 2x2 items. If there is a scrollbar, it means the items are duplicated QTRY_VERIFY(!treeWidget.verticalScrollBar()->isVisible()); - } void tst_QTreeWidget::itemSelectionChanged() { QVERIFY(testWidget); - if(testWidget->topLevelItem(0)) + if (testWidget->topLevelItem(0)) QVERIFY(testWidget->topLevelItem(0)->isSelected()); } @@ -3255,14 +3200,18 @@ void tst_QTreeWidget::selectionOrder() { testWidget->setColumnCount(1); QList<QTreeWidgetItem *> items; - for (int i = 0; i < 10; ++i) - items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QLatin1String("item: ") + QString::number(i)))); + for (int i = 0; i < 10; ++i) { + items.append(new QTreeWidgetItem(static_cast<QTreeWidget *>(nullptr), + {QStringLiteral("item: %1").arg(i)})); + } testWidget->insertTopLevelItems(0, items); - QModelIndex idx = testWidget->indexFromItem(items[0]); - connect(testWidget, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged())); + QModelIndex idx = testWidget->indexFromItem(items.at(0)); + connect(testWidget, &QTreeWidget::itemSelectionChanged, + this, &tst_QTreeWidget::itemSelectionChanged); testWidget->selectionModel()->select(idx, QItemSelectionModel::SelectCurrent); - disconnect(testWidget, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged())); + disconnect(testWidget, &QTreeWidget::itemSelectionChanged, + this, &tst_QTreeWidget::itemSelectionChanged); } void tst_QTreeWidget::setSelectionModel() @@ -3271,7 +3220,7 @@ void tst_QTreeWidget::setSelectionModel() for(int i = 0; i < 3; ++i) new QTreeWidgetItem(&tree, QStringList(QString::number(i))); QItemSelectionModel selection(tree.model()); - selection.select(tree.model()->index(1,0), QItemSelectionModel::Select); + selection.select(tree.model()->index(1, 0), QItemSelectionModel::Select); tree.setSelectionModel(&selection); QCOMPARE(tree.topLevelItem(1)->isSelected(), true); } @@ -3301,9 +3250,9 @@ void tst_QTreeWidget::task217309() void tst_QTreeWidget::nonEditableTristate() { // A tree with checkable items, the parent is tristate - QTreeWidget *tree = new QTreeWidget; - QTreeWidgetItem *item = new QTreeWidgetItem(); - tree->insertTopLevelItem(0, item); + QTreeWidget tree; + QTreeWidgetItem *item = new QTreeWidgetItem; + tree.insertTopLevelItem(0, item); item->setFlags(item->flags() | Qt::ItemIsAutoTristate); item->setCheckState(0, Qt::Unchecked); QTreeWidgetItem *subitem1 = new QTreeWidgetItem(item); @@ -3311,53 +3260,46 @@ void tst_QTreeWidget::nonEditableTristate() QTreeWidgetItem *subitem2 = new QTreeWidgetItem(item); subitem2->setCheckState(0, Qt::Unchecked); QCOMPARE(int(item->checkState(0)), int(Qt::Unchecked)); - tree->show(); + tree.show(); + QVERIFY(QTest::qWaitForWindowExposed(&tree)); // Test clicking on the parent item, it should become Checked (not PartiallyChecked) QStyleOptionViewItem option; - option.rect = tree->visualRect(tree->model()->index(0, 0)); + option.rect = tree.visualRect(tree.model()->index(0, 0)); option.state |= QStyle::State_Enabled; option.features |= QStyleOptionViewItem::HasCheckIndicator | QStyleOptionViewItem::HasDisplay; option.checkState = item->checkState(0); - const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1; - QPoint pos = qApp->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &option, 0).center() + QPoint(checkMargin, 0); - QTest::mouseClick(tree->viewport(), Qt::LeftButton, Qt::NoModifier, pos); - QCOMPARE(int(item->checkState(0)), int(Qt::Checked)); + auto appStyle = QApplication::style(); + const int checkMargin = appStyle->pixelMetric( + QStyle::PM_FocusFrameHMargin, nullptr, nullptr) + 1; + QPoint pos = appStyle->subElementRect( + QStyle::SE_ItemViewItemCheckIndicator, &option, nullptr).center(); + pos.rx() += checkMargin; + QTest::mouseClick(tree.viewport(), Qt::LeftButton, Qt::NoModifier, pos); + QCOMPARE(item->checkState(0), Qt::Checked); // Click again, it should become Unchecked. - QTest::mouseClick(tree->viewport(), Qt::LeftButton, Qt::NoModifier, pos); - QCOMPARE(int(item->checkState(0)), int(Qt::Unchecked)); - - delete tree; + QTest::mouseClick(tree.viewport(), Qt::LeftButton, Qt::NoModifier, pos); + QCOMPARE(item->checkState(0), Qt::Unchecked); } -class TreeWidgetItem : public QTreeWidgetItem -{ - -public: - void _emitDataChanged() { emitDataChanged(); } - -}; - void tst_QTreeWidget::emitDataChanged() { - - QTreeWidget *tree = new QTreeWidget; - QSignalSpy spy(tree, SIGNAL(itemChanged(QTreeWidgetItem*,int))); - TreeWidgetItem *item = new TreeWidgetItem(); - tree->insertTopLevelItem(0, item); - item->_emitDataChanged(); + QTreeWidget tree; + QSignalSpy spy(&tree, &QTreeWidget::itemChanged); + auto item = new PublicTreeItem; + tree.insertTopLevelItem(0, item); + item->emitDataChanged(); QCOMPARE(spy.count(), 1); - } void tst_QTreeWidget::setCurrentItemExpandsParent() { QTreeWidget w; w.setColumnCount(1); - QTreeWidgetItem *i1 = new QTreeWidgetItem(&w, QStringList() << "parent"); - QTreeWidgetItem *i2 = new QTreeWidgetItem(i1, QStringList() << "child"); + QTreeWidgetItem *i1 = new QTreeWidgetItem(&w, {"parent"}); + QTreeWidgetItem *i2 = new QTreeWidgetItem(i1, {"child"}); QVERIFY(!i2->isExpanded()); QVERIFY(!w.currentItem()); w.setCurrentItem(i2); @@ -3373,13 +3315,13 @@ void tst_QTreeWidget::task239150_editorWidth() QStyleOptionFrame opt; opt.init(&tree); const int minWidth = tree.style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(0, 0). - expandedTo(QApplication::globalStrut()), 0).width(); + expandedTo(QApplication::globalStrut()), nullptr).width(); { QTreeWidgetItem item; item.setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ); tree.addTopLevelItem(&item); - QVERIFY(tree.itemWidget(&item, 0) == 0); + QVERIFY(tree.itemWidget(&item, 0) == nullptr); tree.editItem(&item); QVERIFY(tree.itemWidget(&item, 0)); QVERIFY(tree.itemWidget(&item, 0)->width() >= minWidth); @@ -3391,7 +3333,7 @@ void tst_QTreeWidget::task239150_editorWidth() item.setText(0, "foooooooooooooooooooooooo"); item.setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled ); tree.addTopLevelItem(&item); - QVERIFY(tree.itemWidget(&item, 0) == 0); + QVERIFY(tree.itemWidget(&item, 0) == nullptr); tree.editItem(&item); QVERIFY(tree.itemWidget(&item, 0)); QVERIFY(tree.itemWidget(&item, 0)->width() >= minWidth + tree.fontMetrics().horizontalAdvance(item.text(0))); @@ -3408,23 +3350,21 @@ void tst_QTreeWidget::setTextUpdate() class MyItemDelegate : public QStyledItemDelegate { public: - MyItemDelegate() : numPaints(0) { } - void paint(QPainter *painter, - const QStyleOptionViewItem &option, const QModelIndex &index) const + using QStyledItemDelegate::QStyledItemDelegate; + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const override { numPaints++; QStyledItemDelegate::paint(painter, option, index); } - mutable int numPaints; + mutable int numPaints = 0; } delegate; treeWidget.setItemDelegate(&delegate); treeWidget.show(); QVERIFY(QTest::qWaitForWindowExposed(&treeWidget)); - QStringList strList; - strList << "variable1" << "0"; - QTreeWidgetItem *item = new QTreeWidgetItem(strList); + QTreeWidgetItem *item = new QTreeWidgetItem({ "variable1", "0" }); treeWidget.insertTopLevelItem(0, item); QTRY_VERIFY(delegate.numPaints > 0); delegate.numPaints = 0; @@ -3435,7 +3375,7 @@ void tst_QTreeWidget::setTextUpdate() void tst_QTreeWidget::taskQTBUG2844_visualItemRect() { - CustomTreeWidget tree; + PublicTreeWidget tree; tree.resize(150, 100); tree.setColumnCount(3); QTreeWidgetItem item(&tree); @@ -3457,15 +3397,17 @@ void tst_QTreeWidget::setChildIndicatorPolicy() class MyItemDelegate : public QStyledItemDelegate { public: - MyItemDelegate() : numPaints(0), expectChildren(false) { } - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const + using QStyledItemDelegate::QStyledItemDelegate; + void paint(QPainter *painter, + const QStyleOptionViewItem &option, + const QModelIndex &index) const override { numPaints++; QCOMPARE(!(option.state & QStyle::State_Children), !expectChildren); QStyledItemDelegate::paint(painter, option, index); } - mutable int numPaints; - bool expectChildren; + mutable int numPaints = 0; + bool expectChildren = false; } delegate; treeWidget.setItemDelegate(&delegate); @@ -3503,19 +3445,15 @@ void tst_QTreeWidget::setChildIndicatorPolicy() // The test passes simply if it doesn't crash. void tst_QTreeWidget::taskQTBUG_34717_collapseAtBottom() { - struct PublicTreeWidget: public QTreeWidget - { - inline int sizeHintForColumn(int column) const { return QTreeWidget::sizeHintForColumn(column); } - }; PublicTreeWidget treeWidget; treeWidget.header()->setSectionResizeMode(QHeaderView::ResizeToContents); treeWidget.setColumnCount(2); - QTreeWidgetItem *mainItem = new QTreeWidgetItem(&treeWidget, QStringList() << "Root"); + QTreeWidgetItem *mainItem = new QTreeWidgetItem(&treeWidget, { "Root" }); for (int i = 0; i < 200; ++i) { - QTreeWidgetItem *item = new QTreeWidgetItem(mainItem, QStringList(QString("Item"))); - new QTreeWidgetItem(item, QStringList() << "Child" << "1"); - new QTreeWidgetItem(item, QStringList() << "Child" << "2"); - new QTreeWidgetItem(item, QStringList() << "Child" << "3"); + QTreeWidgetItem *item = new QTreeWidgetItem(mainItem, { "Item" }); + new QTreeWidgetItem(item, { "Child", "1" }); + new QTreeWidgetItem(item, { "Child", "2" }); + new QTreeWidgetItem(item, { "Child", "3" }); } treeWidget.show(); treeWidget.expandAll(); @@ -3545,11 +3483,8 @@ void tst_QTreeWidget::task20345_sortChildren() tw.setSortingEnabled(true); tw.show(); - QTreeWidgetItem *rootItem = 0; - QTreeWidgetItem *childItem = 0; - - rootItem = new QTreeWidgetItem(&tw, QStringList("a")); - childItem = new QTreeWidgetItem(rootItem); + auto rootItem = new QTreeWidgetItem(&tw, QStringList("a")); + auto childItem = new QTreeWidgetItem(rootItem); childItem->setText(1, "3"); childItem = new QTreeWidgetItem(rootItem); childItem->setText(1, "1"); @@ -3558,10 +3493,10 @@ void tst_QTreeWidget::task20345_sortChildren() tw.setCurrentItem(tw.topLevelItem(0)); - QTreeWidgetItem * curItem = tw.currentItem(); + QTreeWidgetItem *curItem = tw.currentItem(); int childCount = curItem->childCount() + 1; - QTreeWidgetItem * newItem = new QTreeWidgetItem(curItem); + QTreeWidgetItem *newItem = new QTreeWidgetItem(curItem); newItem->setText(1, QString::number(childCount)); rootItem->sortChildren(1, Qt::AscendingOrder); QVERIFY(1); @@ -3569,7 +3504,7 @@ void tst_QTreeWidget::task20345_sortChildren() void tst_QTreeWidget::getMimeDataWithInvalidItem() { - CustomTreeWidget w; + PublicTreeWidget w; QTest::ignoreMessage(QtWarningMsg, "QTreeWidget::mimeData: Null-item passed"); QMimeData *md = w.mimeData(QList<QTreeWidgetItem*>() << nullptr); QVERIFY(!md); diff --git a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp index 76ca148d3f..68d149fc6e 100644 --- a/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp +++ b/tests/auto/widgets/itemviews/qtreewidgetitemiterator/tst_qtreewidgetitemiterator.cpp @@ -27,20 +27,19 @@ ****************************************************************************/ -#include <QtTest/QtTest> +#include <QTreeWidget> +#include <QTreeWidgetItemIterator> +#include <QTest> -#include <qtreewidget.h> -#include <qtreewidgetitemiterator.h> -#include <qapplication.h> -#include <qeventloop.h> -#include <qdebug.h> +Q_DECLARE_METATYPE(QTreeWidgetItemIterator::IteratorFlag) +Q_DECLARE_METATYPE(QTreeWidgetItemIterator::IteratorFlags) class tst_QTreeWidgetItemIterator : public QObject { Q_OBJECT public: - tst_QTreeWidgetItemIterator(); + using QObject::QObject; private slots: void initTestCase(); @@ -65,13 +64,9 @@ private slots: void initializeIterator(); void sortingEnabled(); private: - QTreeWidget *testWidget; + QTreeWidget *testWidget = nullptr; }; -tst_QTreeWidgetItemIterator::tst_QTreeWidgetItemIterator(): testWidget(0) -{ -} - void tst_QTreeWidgetItemIterator::initTestCase() { testWidget = new QTreeWidget(); @@ -90,7 +85,7 @@ void tst_QTreeWidgetItemIterator::initTestCase() * |Qt::ItemIsDropEnabled * */ - for (int i=0; i <= 16; ++i) { + for (int i = 0; i <= 16; ++i) { QTreeWidgetItem *top = new QTreeWidgetItem(testWidget); const QString topS = QLatin1String("top") + QString::number(i); top->setText(0, topS); @@ -111,9 +106,7 @@ void tst_QTreeWidgetItemIterator::initTestCase() case 9: top->setFlags(Qt::ItemIsEnabled);break; case 10: top->setFlags(Qt::ItemIsEnabled);break; - case 11: - top->setFlags(0); - break; + case 11: top->setFlags({});break; case 12: top->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);break; case 13: top->setFlags(Qt::ItemIsEnabled);break; @@ -142,7 +135,7 @@ void tst_QTreeWidgetItemIterator::initTestCase() case 9: child->setFlags(Qt::ItemIsEnabled);break; case 10: child->setFlags(Qt::ItemIsEnabled);break; - case 11: child->setFlags(0);break; + case 11: child->setFlags({});break; case 12: child->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);break; case 13: child->setFlags(Qt::ItemIsEnabled);break; @@ -188,10 +181,10 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data() NotEditable = 0x00020000 */ QTest::addColumn<int>("start"); - QTest::addColumn<int>("iteratorflags"); + QTest::addColumn<QTreeWidgetItemIterator::IteratorFlags>("iteratorflags"); QTest::addColumn<QStringList>("matches"); - QTest::newRow("Match all") << 0 << (int)QTreeWidgetItemIterator::All + QTest::newRow("Match all") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::All) << (QStringList() << "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3" << "top0,child4" << "top0,child5" << "top0,child6" << "top0,child7" @@ -279,7 +272,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data() << "top16,child12" << "top16,child13" << "top16,child14" << "top16,child15" << "top16,child16"); - QTest::newRow("Match hidden") << 0 << (int)QTreeWidgetItemIterator::Hidden + QTest::newRow("Match hidden") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Hidden) << (QStringList() << "top0" << "top0,child0" // fails due to hidden row << "top1,child0" @@ -299,7 +292,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data() << "top15,child0" << "top16,child0"); - QTest::newRow("Match not hidden") << 0 << (int)QTreeWidgetItemIterator::NotHidden + QTest::newRow("Match not hidden") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::NotHidden) << (QStringList() << "top0,child1" << "top0,child2" << "top0,child3" << "top0,child4" << "top0,child5" << "top0,child6" << "top0,child7" @@ -387,7 +380,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data() << "top16,child12" << "top16,child13" << "top16,child14" << "top16,child15" << "top16,child16"); - QTest::newRow("Match selected") << 0 << (int)QTreeWidgetItemIterator::Selected + QTest::newRow("Match selected") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Selected) << (QStringList() << "top0,child2" << "top1,child2" @@ -407,7 +400,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data() << "top15,child2" << "top16,child2"); - QTest::newRow("Match selectable") << 0 << (int)QTreeWidgetItemIterator::Selectable + QTest::newRow("Match selectable") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Selectable) << (QStringList() << "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3" << "top0,child4" @@ -479,7 +472,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data() << "top16,child16"); - QTest::newRow("Match DragEnabled") << 0 << (int)QTreeWidgetItemIterator::DragEnabled + QTest::newRow("Match DragEnabled") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::DragEnabled) << (QStringList() << "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3" << "top0,child6" @@ -550,7 +543,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data() << "top16,child14" << "top16,child15" << "top16,child16"); - QTest::newRow("Match DragDisabled") << 0 << (int)QTreeWidgetItemIterator::DragDisabled + QTest::newRow("Match DragDisabled") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::DragDisabled) << (QStringList() /* top0 */ @@ -623,7 +616,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data() << "top16,child13" ); - QTest::newRow("Match DropEnabled") << 0 << (int)QTreeWidgetItemIterator::DropEnabled + QTest::newRow("Match DropEnabled") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::DropEnabled) << (QStringList() << "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3" << "top0,child8" @@ -694,12 +687,12 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data() << "top16,child14" << "top16,child15" << "top16,child16"); - QTest::newRow("Match HasChildren") << 0 << (int)QTreeWidgetItemIterator::HasChildren + QTest::newRow("Match HasChildren") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::HasChildren) << (QStringList() << "top0" << "top1" << "top2" << "top3" << "top4" << "top5" << "top6" << "top7" << "top8" << "top9" << "top10" << "top11" << "top12" << "top13" << "top14" << "top15" << "top16"); - QTest::newRow("Match Checked") << 0 << (int)QTreeWidgetItemIterator::Checked + QTest::newRow("Match Checked") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Checked) << (QStringList() << "top0,child14" << "top0,child16" << "top1,child14" << "top1,child16" @@ -721,7 +714,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data() << "top16" << "top16,child14" << "top16,child16"); - QTest::newRow("Match NotChecked") << 0 << (int)QTreeWidgetItemIterator::NotChecked + QTest::newRow("Match NotChecked") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::NotChecked) << (QStringList() << "top0" << "top0,child0" << "top0,child1" << "top0,child2" << "top0,child3" << "top0,child4" << "top0,child5" << "top0,child6" << "top0,child7" @@ -810,7 +803,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data() - QTest::newRow("Match Disabled") << 0 << (int)QTreeWidgetItemIterator::Disabled + QTest::newRow("Match Disabled") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Disabled) << (QStringList() << "top0,child11" << "top1,child11" @@ -848,7 +841,7 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data() << "top15,child11" << "top16,child11"); - QTest::newRow("Match Editable") << 0 << (int)QTreeWidgetItemIterator::Editable + QTest::newRow("Match Editable") << 0 << QTreeWidgetItemIterator::IteratorFlags(QTreeWidgetItemIterator::Editable) << (QStringList() << "top0,child12" << "top1,child12" @@ -869,34 +862,34 @@ void tst_QTreeWidgetItemIterator::iteratorflags_data() << "top15,child12" << "top16,child12"); - QTest::newRow("Match mutually exclusive Hidden|NotHidden") << 0 << (int)(QTreeWidgetItemIterator::Hidden|QTreeWidgetItemIterator::NotHidden) + QTest::newRow("Match mutually exclusive Hidden|NotHidden") << 0 << (QTreeWidgetItemIterator::Hidden|QTreeWidgetItemIterator::NotHidden) << QStringList(); - QTest::newRow("Match mutually exclusive Selected|Unselected") << 0 << (int)(QTreeWidgetItemIterator::Selected|QTreeWidgetItemIterator::Unselected) + QTest::newRow("Match mutually exclusive Selected|Unselected") << 0 << (QTreeWidgetItemIterator::Selected|QTreeWidgetItemIterator::Unselected) << QStringList(); - QTest::newRow("Match mutually exclusive Selectable|NotSelectable") << 0 << (int)(QTreeWidgetItemIterator::Selectable|QTreeWidgetItemIterator::NotSelectable) + QTest::newRow("Match mutually exclusive Selectable|NotSelectable") << 0 << (QTreeWidgetItemIterator::Selectable|QTreeWidgetItemIterator::NotSelectable) << QStringList(); - QTest::newRow("Match mutually exclusive DragEnabled|DragDisabled") << 0 << (int)(QTreeWidgetItemIterator::DragEnabled|QTreeWidgetItemIterator::DragDisabled) + QTest::newRow("Match mutually exclusive DragEnabled|DragDisabled") << 0 << (QTreeWidgetItemIterator::DragEnabled|QTreeWidgetItemIterator::DragDisabled) << QStringList(); - QTest::newRow("Match mutually exclusive DropEnabled|DropDisabled") << 0 << (int)(QTreeWidgetItemIterator::DropEnabled|QTreeWidgetItemIterator::DropDisabled) + QTest::newRow("Match mutually exclusive DropEnabled|DropDisabled") << 0 << (QTreeWidgetItemIterator::DropEnabled|QTreeWidgetItemIterator::DropDisabled) << QStringList(); - QTest::newRow("Match mutually exclusive HasChildren|NoChildren") << 0 << (int)(QTreeWidgetItemIterator::HasChildren|QTreeWidgetItemIterator::NoChildren) + QTest::newRow("Match mutually exclusive HasChildren|NoChildren") << 0 << (QTreeWidgetItemIterator::HasChildren|QTreeWidgetItemIterator::NoChildren) << QStringList(); - QTest::newRow("Match mutually exclusive Checked|NotChecked") << 0 << (int)(QTreeWidgetItemIterator::Checked|QTreeWidgetItemIterator::NotChecked) + QTest::newRow("Match mutually exclusive Checked|NotChecked") << 0 << (QTreeWidgetItemIterator::Checked|QTreeWidgetItemIterator::NotChecked) << QStringList(); - QTest::newRow("Match mutually exclusive Disabled|Enabled") << 0 << (int)(QTreeWidgetItemIterator::Disabled|QTreeWidgetItemIterator::Enabled) + QTest::newRow("Match mutually exclusive Disabled|Enabled") << 0 << (QTreeWidgetItemIterator::Disabled|QTreeWidgetItemIterator::Enabled) << QStringList(); - QTest::newRow("Match mutually exclusive Editable|NotEditable") << 0 << (int)(QTreeWidgetItemIterator::Editable|QTreeWidgetItemIterator::NotEditable) + QTest::newRow("Match mutually exclusive Editable|NotEditable") << 0 << (QTreeWidgetItemIterator::Editable|QTreeWidgetItemIterator::NotEditable) << QStringList(); } void tst_QTreeWidgetItemIterator::iteratorflags() { QFETCH(int, start); - QFETCH(int, iteratorflags); + QFETCH(QTreeWidgetItemIterator::IteratorFlags, iteratorflags); QFETCH(QStringList, matches); - QTreeWidgetItemIterator it(testWidget, QTreeWidgetItemIterator::IteratorFlags(iteratorflags)); - it+=start; + QTreeWidgetItemIterator it(testWidget, iteratorflags); + it += start; int iMatch = 0; while (*it && iMatch < matches.count()) { QTreeWidgetItem *item = *it; @@ -953,26 +946,26 @@ void tst_QTreeWidgetItemIterator::plus_eq_data() { QTest::addColumn<int>("start"); QTest::addColumn<int>("addition"); - QTest::addColumn<int>("iteratorflags"); + QTest::addColumn<QTreeWidgetItemIterator::IteratorFlag>("iteratorflags"); QTest::addColumn<QString>("expecteditem"); - QTest::newRow("+=0") << 0 << 0 << (int)QTreeWidgetItemIterator::All << QString("top0"); - QTest::newRow("+=1") << 0 << 1 << (int)QTreeWidgetItemIterator::All << QString("top0,child0"); - QTest::newRow("+=2") << 0 << 2 << (int)QTreeWidgetItemIterator::All << QString("top0,child1"); - QTest::newRow("+=(-1)") << 1 << -1 << (int)QTreeWidgetItemIterator::All << QString("top0"); - QTest::newRow("+=(-2)") << 3 << -2 << (int)QTreeWidgetItemIterator::All << QString("top0,child0"); + QTest::newRow("+=0") << 0 << 0 << QTreeWidgetItemIterator::All << QString("top0"); + QTest::newRow("+=1") << 0 << 1 << QTreeWidgetItemIterator::All << QString("top0,child0"); + QTest::newRow("+=2") << 0 << 2 << QTreeWidgetItemIterator::All << QString("top0,child1"); + QTest::newRow("+=(-1)") << 1 << -1 << QTreeWidgetItemIterator::All << QString("top0"); + QTest::newRow("+=(-2)") << 3 << -2 << QTreeWidgetItemIterator::All << QString("top0,child0"); } void tst_QTreeWidgetItemIterator::plus_eq() { QFETCH(int, start); QFETCH(int, addition); - QFETCH(int, iteratorflags); + QFETCH(QTreeWidgetItemIterator::IteratorFlag, iteratorflags); QFETCH(QString, expecteditem); - QTreeWidgetItemIterator it(testWidget, QTreeWidgetItemIterator::IteratorFlags(iteratorflags)); - it+=start; - it+=addition; + QTreeWidgetItemIterator it(testWidget, iteratorflags); + it += start; + it += addition; QTreeWidgetItem *item = *it; QVERIFY(item); @@ -984,28 +977,28 @@ void tst_QTreeWidgetItemIterator::minus_eq_data() { QTest::addColumn<int>("start"); QTest::addColumn<int>("subtraction"); - QTest::addColumn<int>("iteratorflags"); + QTest::addColumn<QTreeWidgetItemIterator::IteratorFlag>("iteratorflags"); QTest::addColumn<QString>("expecteditem"); - QTest::newRow("0-=0") << 0 << 0 << (int)QTreeWidgetItemIterator::All << QString("top0"); - QTest::newRow("2-=1") << 2 << 1 << (int)QTreeWidgetItemIterator::All << QString("top0,child0"); - QTest::newRow("4-=2") << 4 << 2 << (int)QTreeWidgetItemIterator::All << QString("top0,child1"); - QTest::newRow("0-=(-1)") << 0 << -1 << (int)QTreeWidgetItemIterator::All << QString("top0,child0"); - QTest::newRow("0-=(-2)") << 0 << -2 << (int)QTreeWidgetItemIterator::All << QString("top0,child1"); - QTest::newRow("18-=1") << 18 << 1 << (int)QTreeWidgetItemIterator::All << QString("top0,child16"); - QTest::newRow("1-=1") << 1 << 1 << (int)QTreeWidgetItemIterator::All << QString("top0"); + QTest::newRow("0-=0") << 0 << 0 << QTreeWidgetItemIterator::All << QString("top0"); + QTest::newRow("2-=1") << 2 << 1 << QTreeWidgetItemIterator::All << QString("top0,child0"); + QTest::newRow("4-=2") << 4 << 2 << QTreeWidgetItemIterator::All << QString("top0,child1"); + QTest::newRow("0-=(-1)") << 0 << -1 << QTreeWidgetItemIterator::All << QString("top0,child0"); + QTest::newRow("0-=(-2)") << 0 << -2 << QTreeWidgetItemIterator::All << QString("top0,child1"); + QTest::newRow("18-=1") << 18 << 1 << QTreeWidgetItemIterator::All << QString("top0,child16"); + QTest::newRow("1-=1") << 1 << 1 << QTreeWidgetItemIterator::All << QString("top0"); } void tst_QTreeWidgetItemIterator::minus_eq() { QFETCH(int, start); QFETCH(int, subtraction); - QFETCH(int, iteratorflags); + QFETCH(QTreeWidgetItemIterator::IteratorFlag, iteratorflags); QFETCH(QString, expecteditem); - QTreeWidgetItemIterator it(testWidget, QTreeWidgetItemIterator::IteratorFlags(iteratorflags)); - it+=start; - it-=subtraction; + QTreeWidgetItemIterator it(testWidget, iteratorflags); + it += start; + it -= subtraction; QTreeWidgetItem *item = *it; // should be the first one QVERIFY(item); @@ -1017,41 +1010,41 @@ void tst_QTreeWidgetItemIterator::updateIfModifiedFromWidget_data() QTest::addColumn<int>("topLevelItems"); QTest::addColumn<int>("childItems"); QTest::addColumn<int>("grandChildItems"); - QTest::addColumn<int>("iteratorflags"); + QTest::addColumn<QTreeWidgetItemIterator::IteratorFlag>("iteratorflags"); QTest::addColumn<int>("removeindex"); QTest::addColumn<int>("expecteditemindex"); QTest::addColumn<QString>("expecteditemvalue"); QTest::addColumn<QString>("expectedUpdatedCurrent"); QTest::addColumn<int>("expecteditemIsNull"); - QTest::newRow("Remove 3, check 1") << 3 << 3 << 0 << (int)QTreeWidgetItemIterator::All + QTest::newRow("Remove 3, check 1") << 3 << 3 << 0 << QTreeWidgetItemIterator::All << 3 << 1 << QString("top0,child0") << QString("top1") << 0; - QTest::newRow("Remove 1, check 0") << 3 << 3 << 0 << (int)QTreeWidgetItemIterator::All + QTest::newRow("Remove 1, check 0") << 3 << 3 << 0 << QTreeWidgetItemIterator::All << 1 << 0 << QString("top0") << QString("top0,child1") << 0; - QTest::newRow("Remove 2, check 2") << 3 << 3 << 0 << (int)QTreeWidgetItemIterator::All + QTest::newRow("Remove 2, check 2") << 3 << 3 << 0 << QTreeWidgetItemIterator::All << 2 << 2 << QString("top0,child2") << QString("top0,child2") << 0; - QTest::newRow("Remove 0, check 0") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All + QTest::newRow("Remove 0, check 0") << 3 << 3 << 3 << QTreeWidgetItemIterator::All << 0 << 0 << QString("top1") << QString("top1") << 0; - QTest::newRow("Remove top1, check top1") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All + QTest::newRow("Remove top1, check top1") << 3 << 3 << 3 << QTreeWidgetItemIterator::All << 13 << 13 << QString("top2") << QString("top2") << 0; - QTest::newRow("Remove top0, check top1") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All + QTest::newRow("Remove top0, check top1") << 3 << 3 << 3 << QTreeWidgetItemIterator::All << 0 << 13 << QString("top1") << QString("top1") << 0; - QTest::newRow("Remove (top0,child1), check (top0,child1)") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All + QTest::newRow("Remove (top0,child1), check (top0,child1)") << 3 << 3 << 3 << QTreeWidgetItemIterator::All << 5 << 5 << QString("top0,child2") << QString("top0,child2") << 0; - QTest::newRow("Remove (t0,c0) check (t0,c0)") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All + QTest::newRow("Remove (t0,c0) check (t0,c0)") << 3 << 3 << 3 << QTreeWidgetItemIterator::All << 1 << 1 << QString("top0,child1") << QString("top0,child1") << 0; - QTest::newRow("Remove (t0,c1) check (t0,c1)") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All + QTest::newRow("Remove (t0,c1) check (t0,c1)") << 3 << 3 << 3 << QTreeWidgetItemIterator::All << 5 << 5 << QString("top0,child2") << QString("top0,child2") << 0; - QTest::newRow("Remove (t0) check (t0,c1)") << 3 << 3 << 0 << (int)QTreeWidgetItemIterator::All + QTest::newRow("Remove (t0) check (t0,c1)") << 3 << 3 << 0 << QTreeWidgetItemIterator::All << 0 << 4 << QString("top1") << QString("top1") << 0; - QTest::newRow("Remove (t0) check (t0,c0,g1)") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All + QTest::newRow("Remove (t0) check (t0,c0,g1)") << 3 << 3 << 3 << QTreeWidgetItemIterator::All << 0 << 3 << QString("top1") << QString("top1") << 0; - QTest::newRow("Remove (top2), check if top2 is null") << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All + QTest::newRow("Remove (top2), check if top2 is null") << 3 << 3 << 3 << QTreeWidgetItemIterator::All << 2*13 << 2*13 << QString() << QString() << 1; QTest::newRow("Remove last item, check if iterator::current returns 0") - << 3 << 0 << 0 << (int)QTreeWidgetItemIterator::All << 2 << 2 << QString() << QString() << 1; + << 3 << 0 << 0 << QTreeWidgetItemIterator::All << 2 << 2 << QString() << QString() << 1; QTest::newRow("remove 1, iterator points to 3, should move to 1") - << 3 << 3 << 3 << (int)QTreeWidgetItemIterator::All << 1 << 3 << QString("top0,child1") << QString("top0,child1") << 0; + << 3 << 3 << 3 << QTreeWidgetItemIterator::All << 1 << 3 << QString("top0,child1") << QString("top0,child1") << 0; } static void populate3Levels(QTreeWidget &tw, int topLevelItems, int childItems, int grandChildItems) @@ -1077,7 +1070,7 @@ void tst_QTreeWidgetItemIterator::updateIfModifiedFromWidget() QFETCH(int, topLevelItems); QFETCH(int, childItems); QFETCH(int, grandChildItems); - QFETCH(int, iteratorflags); + QFETCH(QTreeWidgetItemIterator::IteratorFlag, iteratorflags); QFETCH(int, removeindex); QFETCH(int, expecteditemindex); QFETCH(QString, expecteditemvalue); @@ -1089,12 +1082,11 @@ void tst_QTreeWidgetItemIterator::updateIfModifiedFromWidget() tw.setColumnCount(2); populate3Levels(tw, topLevelItems, childItems, grandChildItems); - QTreeWidgetItemIterator it(&tw, QTreeWidgetItemIterator::IteratorFlags(iteratorflags)); + QTreeWidgetItemIterator it(&tw, iteratorflags); it+=expecteditemindex; - QTreeWidgetItem *item = 0; QTreeWidgetItemIterator itRemove(&tw, QTreeWidgetItemIterator::IteratorFlags(iteratorflags)); itRemove+=removeindex; - item = *itRemove; + QTreeWidgetItem *item = *itRemove; QVERIFY(item); delete item; item = *it; @@ -1104,11 +1096,10 @@ void tst_QTreeWidgetItemIterator::updateIfModifiedFromWidget() QVERIFY(item); QCOMPARE(item->text(0), expecteditemvalue); item = *itRemove; - if (expectedUpdatedCurrent.isNull()) { + if (expectedUpdatedCurrent.isNull()) QVERIFY(!item); - } else { + else QCOMPARE(item->text(0), expectedUpdatedCurrent); - } } } @@ -1152,38 +1143,36 @@ void tst_QTreeWidgetItemIterator::updateIteratorAfterDeletedItem_and_ContinueIte QTreeWidgetItemIterator it(&tw, QTreeWidgetItemIterator::All); it += iterator_initial_index; - QTreeWidgetItem *item = 0; QTreeWidgetItemIterator itRemove(&tw, QTreeWidgetItemIterator::All); itRemove+=removeindex; - item = *itRemove; + QTreeWidgetItem *item = *itRemove; QVERIFY(item); delete item; it+=iterator_advance_after_removal; - if (iterator_new_value.isNull()) { + if (iterator_new_value.isNull()) QCOMPARE((*it), nullptr); - } else { + else QCOMPARE((*it)->text(0), iterator_new_value); - } } void tst_QTreeWidgetItemIterator::constructIteratorWithItem_data() { QTest::addColumn<int>("indextoitem"); - QTest::addColumn<int>("iteratorflags"); + QTest::addColumn<QTreeWidgetItemIterator::IteratorFlag>("iteratorflags"); QTest::addColumn<QString>("expecteditem"); - QTest::newRow("index 0") << 0 << 0 << QString("top0"); - QTest::newRow("index 1") << 1 << 0 << QString("top0,child0"); - QTest::newRow("index 2") << 2 << 0 << QString("top0,child1"); - QTest::newRow("index 30") << 30 << 0 << QString("top1,child11"); - QTest::newRow("305 (last item)") << 305 << 0 << QString("top16,child16"); - QTest::newRow("index 0, advance to next matching node") << 0 << (int)QTreeWidgetItemIterator::NotHidden << QString("top0,child1"); + QTest::newRow("index 0") << 0 << QTreeWidgetItemIterator::All << QString("top0"); + QTest::newRow("index 1") << 1 << QTreeWidgetItemIterator::All << QString("top0,child0"); + QTest::newRow("index 2") << 2 << QTreeWidgetItemIterator::All << QString("top0,child1"); + QTest::newRow("index 30") << 30 << QTreeWidgetItemIterator::All << QString("top1,child11"); + QTest::newRow("305 (last item)") << 305 << QTreeWidgetItemIterator::All << QString("top16,child16"); + QTest::newRow("index 0, advance to next matching node") << 0 << QTreeWidgetItemIterator::NotHidden << QString("top0,child1"); } void tst_QTreeWidgetItemIterator::constructIteratorWithItem() { QFETCH(int, indextoitem); - QFETCH(int, iteratorflags); + QFETCH(QTreeWidgetItemIterator::IteratorFlag, iteratorflags); QFETCH(QString, expecteditem); QTreeWidgetItemIterator it(testWidget); diff --git a/tests/auto/widgets/kernel/kernel.pro b/tests/auto/widgets/kernel/kernel.pro index 73fd934502..af85a2bd13 100644 --- a/tests/auto/widgets/kernel/kernel.pro +++ b/tests/auto/widgets/kernel/kernel.pro @@ -22,5 +22,3 @@ SUBDIRS=\ darwin:SUBDIRS -= \ # Uses native recognizers qgesturerecognizer \ - -SUBDIRS -= qsound diff --git a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp index 3d68e42baf..0d62c2cd4b 100644 --- a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp +++ b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp @@ -70,7 +70,7 @@ private slots: void shortcutFromKeyEvent(); // QTBUG-48325 private: - int m_lastEventType; + QEvent::Type m_lastEventType; const int m_keyboardScheme; QAction *m_lastAction; }; @@ -82,7 +82,7 @@ tst_QAction::tst_QAction() void tst_QAction::init() { - m_lastEventType = 0; + m_lastEventType = QEvent::None; m_lastAction = nullptr; } @@ -94,23 +94,23 @@ void tst_QAction::cleanup() // Testing get/set functions void tst_QAction::getSetCheck() { - QAction obj1(0); + QAction obj1(nullptr); // QActionGroup * QAction::actionGroup() // void QAction::setActionGroup(QActionGroup *) - QActionGroup *var1 = new QActionGroup(0); + QActionGroup *var1 = new QActionGroup(nullptr); obj1.setActionGroup(var1); QCOMPARE(var1, obj1.actionGroup()); - obj1.setActionGroup((QActionGroup *)0); - QCOMPARE((QActionGroup *)0, obj1.actionGroup()); + obj1.setActionGroup(nullptr); + QCOMPARE(obj1.actionGroup(), nullptr); delete var1; // QMenu * QAction::menu() // void QAction::setMenu(QMenu *) - QMenu *var2 = new QMenu(0); + QMenu *var2 = new QMenu(nullptr); obj1.setMenu(var2); QCOMPARE(var2, obj1.menu()); - obj1.setMenu((QMenu *)0); - QCOMPARE((QMenu *)0, obj1.menu()); + obj1.setMenu(nullptr); + QCOMPARE(obj1.menu(), nullptr); delete var2; QCOMPARE(obj1.priority(), QAction::NormalPriority); @@ -148,7 +148,7 @@ void tst_QAction::setText() { QFETCH(QString, text); - QAction action(0); + QAction action(nullptr); action.setText(text); QCOMPARE(action.text(), text); @@ -161,7 +161,7 @@ void tst_QAction::setIconText() { QFETCH(QString, iconText); - QAction action(0); + QAction action(nullptr); action.setIconText(iconText); QCOMPARE(action.iconText(), iconText); @@ -171,7 +171,7 @@ void tst_QAction::setIconText() void tst_QAction::setUnknownFont() // QTBUG-42728 { - QAction action(0); + QAction action(nullptr); QFont font("DoesNotExist", 11); action.setFont(font); @@ -182,17 +182,17 @@ void tst_QAction::setUnknownFont() // QTBUG-42728 void tst_QAction::updateState(QActionEvent *e) { if (!e) { - m_lastEventType = 0; - m_lastAction = 0; + m_lastEventType = QEvent::None; + m_lastAction = nullptr; } else { - m_lastEventType = (int)e->type(); + m_lastEventType = e->type(); m_lastAction = e->action(); } } void tst_QAction::actionEvent() { - QAction a(0); + QAction a(nullptr); a.setText("action text"); // add action @@ -202,33 +202,33 @@ void tst_QAction::actionEvent() testWidget.addAction(&a); qApp->processEvents(); - QCOMPARE(m_lastEventType, (int)QEvent::ActionAdded); + QCOMPARE(m_lastEventType, QEvent::ActionAdded); QCOMPARE(m_lastAction, &a); // change action a.setText("new action text"); qApp->processEvents(); - QCOMPARE(m_lastEventType, (int)QEvent::ActionChanged); + QCOMPARE(m_lastEventType, QEvent::ActionChanged); QCOMPARE(m_lastAction, &a); // remove action testWidget.removeAction(&a); qApp->processEvents(); - QCOMPARE(m_lastEventType, (int)QEvent::ActionRemoved); + QCOMPARE(m_lastEventType, QEvent::ActionRemoved); QCOMPARE(m_lastAction, &a); } //basic testing of standard keys void tst_QAction::setStandardKeys() { - QAction act(0); + QAction act(nullptr); act.setShortcut(QKeySequence("CTRL+L")); QList<QKeySequence> list; act.setShortcuts(list); act.setShortcuts(QKeySequence::Copy); - QCOMPARE(act.shortcut(), act.shortcuts().first()); + QCOMPARE(act.shortcut(), act.shortcuts().constFirst()); QList<QKeySequence> expected; const QKeySequence ctrlC = QKeySequence(QStringLiteral("CTRL+C")); @@ -263,7 +263,7 @@ void tst_QAction::alternateShortcuts() QList<QKeySequence> shlist = QList<QKeySequence>() << QKeySequence("CTRL+P") << QKeySequence("CTRL+A"); act.setShortcuts(shlist); - QSignalSpy spy(&act, SIGNAL(triggered())); + QSignalSpy spy(&act, &QAction::triggered); act.setAutoRepeat(true); QTest::keyClick(&testWidget, Qt::Key_A, Qt::ControlModifier); @@ -322,7 +322,7 @@ void tst_QAction::enabledVisibleInteraction() testWidget.show(); QApplication::setActiveWindow(&testWidget); - QAction act(0); + QAction act(nullptr); // check defaults QVERIFY(act.isEnabled()); QVERIFY(act.isVisible()); @@ -370,7 +370,7 @@ void tst_QAction::task229128TriggeredSignalWithoutActiongroup() { // test without a group const QScopedPointer<QAction> actionWithoutGroup(new QAction("Test", nullptr)); - QSignalSpy spyWithoutGroup(actionWithoutGroup.data(), SIGNAL(triggered(bool))); + QSignalSpy spyWithoutGroup(actionWithoutGroup.data(), QOverload<bool>::of(&QAction::triggered)); QCOMPARE(spyWithoutGroup.count(), 0); actionWithoutGroup->trigger(); // signal should be emitted @@ -388,7 +388,7 @@ void tst_QAction::task229128TriggeredSignalWithoutActiongroup() void tst_QAction::task229128TriggeredSignalWhenInActiongroup() { - QActionGroup ag(0); + QActionGroup ag(nullptr); QAction *action = new QAction("Test", &ag); QAction *checkedAction = new QAction("Test 2", &ag); ag.addAction(action); @@ -397,8 +397,8 @@ void tst_QAction::task229128TriggeredSignalWhenInActiongroup() checkedAction->setCheckable(true); checkedAction->setChecked(true); - QSignalSpy actionSpy(checkedAction, SIGNAL(triggered(bool))); - QSignalSpy actionGroupSpy(&ag, SIGNAL(triggered(QAction*))); + QSignalSpy actionSpy(checkedAction, QOverload<bool>::of(&QAction::triggered)); + QSignalSpy actionGroupSpy(&ag, QOverload<QAction*>::of(&QActionGroup::triggered)); QCOMPARE(actionGroupSpy.count(), 0); QCOMPARE(actionSpy.count(), 0); checkedAction->trigger(); @@ -513,10 +513,10 @@ void tst_QAction::disableShortcutsWithBlockedWidgets() class ShortcutOverrideWidget : public QWidget { public: - ShortcutOverrideWidget(QWidget *parent = 0) : QWidget(parent), shortcutOverrideCount(0) {} - int shortcutOverrideCount; + using QWidget::QWidget; + int shortcutOverrideCount = 0; protected: - bool event(QEvent *e) + bool event(QEvent *e) override { if (e->type() == QEvent::ShortcutOverride) ++shortcutOverrideCount; diff --git a/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp b/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp index 52ca10d31f..524040d003 100644 --- a/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp +++ b/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp @@ -41,6 +41,7 @@ private slots: void enabledPropagation(); void visiblePropagation(); void exclusive(); + void exclusiveOptional(); void separators(); void testActionInTwoQActionGroup(); void unCheckCurrentAction(); @@ -48,11 +49,11 @@ private slots: void tst_QActionGroup::enabledPropagation() { - QActionGroup testActionGroup( 0 ); + QActionGroup testActionGroup(nullptr); QAction* childAction = new QAction( &testActionGroup ); QAction* anotherChildAction = new QAction( &testActionGroup ); - QAction* freeAction = new QAction(0); + QAction* freeAction = new QAction(nullptr); QVERIFY( testActionGroup.isEnabled() ); QVERIFY( childAction->isEnabled() ); @@ -87,11 +88,11 @@ void tst_QActionGroup::enabledPropagation() void tst_QActionGroup::visiblePropagation() { - QActionGroup testActionGroup( 0 ); + QActionGroup testActionGroup(nullptr); QAction* childAction = new QAction( &testActionGroup ); QAction* anotherChildAction = new QAction( &testActionGroup ); - QAction* freeAction = new QAction(0); + QAction* freeAction = new QAction(nullptr); QVERIFY( testActionGroup.isVisible() ); QVERIFY( childAction->isVisible() ); @@ -124,7 +125,7 @@ void tst_QActionGroup::visiblePropagation() void tst_QActionGroup::exclusive() { - QActionGroup group(0); + QActionGroup group(nullptr); group.setExclusive(false); QVERIFY( !group.isExclusive() ); @@ -151,6 +152,52 @@ void tst_QActionGroup::exclusive() QVERIFY( !actThree->isChecked() ); } +void tst_QActionGroup::exclusiveOptional() +{ + QActionGroup group(0); + group.setExclusive(true); + QVERIFY( group.isExclusive() ); + + QAction* actOne = new QAction( &group ); + actOne->setCheckable( true ); + QAction* actTwo = new QAction( &group ); + actTwo->setCheckable( true ); + QAction* actThree = new QAction( &group ); + actThree->setCheckable( true ); + + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actOne->trigger(); + QVERIFY( actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actOne->trigger(); + QVERIFY( actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + group.setExclusionPolicy( QActionGroup::ExclusionPolicy::ExclusiveOptional ); + QVERIFY( group.isExclusive() ); + + actOne->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actTwo->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actTwo->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); +} + void tst_QActionGroup::separators() { QMainWindow mw; @@ -166,26 +213,24 @@ void tst_QActionGroup::separators() separator->setSeparator(true); actGroup.addAction(separator); - QListIterator<QAction*> it(actGroup.actions()); - while (it.hasNext()) - menu.addAction(it.next()); + menu.addActions(actGroup.actions()); - QCOMPARE((int)menu.actions().size(), 2); + QCOMPARE(menu.actions().size(), 2); - it = QListIterator<QAction*>(actGroup.actions()); - while (it.hasNext()) - menu.removeAction(it.next()); + const auto removeActions = [&menu](const QList<QAction *> &actions) { + for (QAction *action : actions) + menu.removeAction(action); + }; + removeActions(actGroup.actions()); - QCOMPARE((int)menu.actions().size(), 0); + QCOMPARE(menu.actions().size(), 0); action = new QAction(&actGroup); action->setText("test two"); - it = QListIterator<QAction*>(actGroup.actions()); - while (it.hasNext()) - menu.addAction(it.next()); + menu.addActions(actGroup.actions()); - QCOMPARE((int)menu.actions().size(), 3); + QCOMPARE(menu.actions().size(), 3); } void tst_QActionGroup::testActionInTwoQActionGroup() @@ -205,7 +250,7 @@ void tst_QActionGroup::testActionInTwoQActionGroup() void tst_QActionGroup::unCheckCurrentAction() { - QActionGroup group(0); + QActionGroup group(nullptr); QAction action1(&group) ,action2(&group); action1.setCheckable(true); action2.setCheckable(true); diff --git a/tests/auto/widgets/kernel/qapplication/BLACKLIST b/tests/auto/widgets/kernel/qapplication/BLACKLIST index d7de7bf16e..c68c7d6b14 100644 --- a/tests/auto/widgets/kernel/qapplication/BLACKLIST +++ b/tests/auto/widgets/kernel/qapplication/BLACKLIST @@ -1,4 +1,3 @@ [touchEventPropagation] # QTBUG-66745 -opensuse opensuse-leap diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index 7ee085b81c..367a5767c4 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -890,7 +890,9 @@ void tst_QApplication::libraryPaths() QStringList actual = QApplication::libraryPaths(); actual.sort(); - QStringList expected = QSet<QString>::fromList((QStringList() << testDir << appDirPath)).toList(); + QStringList expected; + expected << testDir << appDirPath; + expected = QSet<QString>(expected.constBegin(), expected.constEnd()).values(); expected.sort(); QVERIFY2(isPathListIncluded(actual, expected), @@ -907,7 +909,9 @@ void tst_QApplication::libraryPaths() QStringList actual = QApplication::libraryPaths(); actual.sort(); - QStringList expected = QSet<QString>::fromList((QStringList() << installPathPlugins << appDirPath)).toList(); + QStringList expected; + expected << installPathPlugins << appDirPath; + expected = QSet<QString>(expected.constBegin(), expected.constEnd()).values(); expected.sort(); #ifdef Q_OS_WINRT diff --git a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp index b2650d1f32..00bde3cb25 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(); @@ -193,7 +194,7 @@ void tst_QBoxLayout::setGeometry() setFrameless(&toplevel); QWidget w(&toplevel); QVBoxLayout *lay = new QVBoxLayout; - lay->setMargin(0); + lay->setContentsMargins(0, 0, 0, 0); lay->setSpacing(0); QHBoxLayout *lay2 = new QHBoxLayout; QDial *dial = new QDial; @@ -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->setContentsMargins(0, 0, 0, 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."); @@ -507,6 +571,10 @@ void tst_QBoxLayout::replaceWidget() QCOMPARE(boxLayout->indexOf(replaceFrom), 1); QCOMPARE(boxLayout->indexOf(replaceTo), -1); + QCOMPARE(boxLayout->count(), 3); + boxLayout->replaceWidget(replaceFrom, replaceFrom); + QCOMPARE(boxLayout->count(), 3); + delete boxLayout->replaceWidget(replaceFrom, replaceTo); QCOMPARE(boxLayout->indexOf(replaceFrom), -1); diff --git a/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp b/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp index 90776dfcb2..a29e8408a3 100644 --- a/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp +++ b/tests/auto/widgets/kernel/qdesktopwidget/tst_qdesktopwidget.cpp @@ -42,10 +42,12 @@ class tst_QDesktopWidget : public QObject private slots: void cleanup(); +#if QT_DEPRECATED_SINCE(5, 11) void numScreens(); void primaryScreen(); - void screenNumberForQWidget(); void screenNumberForQPoint(); +#endif + void screenNumberForQWidget(); void availableGeometry(); void screenGeometry(); void topLevels(); @@ -56,6 +58,7 @@ void tst_QDesktopWidget::cleanup() QVERIFY(QApplication::topLevelWidgets().isEmpty()); } +#if QT_DEPRECATED_SINCE(5, 11) void tst_QDesktopWidget::numScreens() { QDesktopWidget desktop; @@ -68,14 +71,17 @@ void tst_QDesktopWidget::primaryScreen() QVERIFY(desktop.primaryScreen() >= 0); QVERIFY(desktop.primaryScreen() < desktop.numScreens()); } +#endif void tst_QDesktopWidget::availableGeometry() { QDesktopWidget desktop; QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::availableGeometry(): Attempt " "to get the available geometry of a null widget"); - desktop.availableGeometry((QWidget *)0); + QRect r = desktop.availableGeometry(nullptr); + QVERIFY(r.isNull()); +#if QT_DEPRECATED_SINCE(5, 11) QRect total; QRect available; @@ -90,13 +96,14 @@ void tst_QDesktopWidget::availableGeometry() QVERIFY(total.contains(available)); QCOMPARE(desktop.availableGeometry(desktop.primaryScreen()), available); QCOMPARE(desktop.screenGeometry(desktop.primaryScreen()), total); +#endif } void tst_QDesktopWidget::screenNumberForQWidget() { QDesktopWidget desktop; - QCOMPARE(desktop.screenNumber(0), 0); + QCOMPARE(desktop.screenNumber(nullptr), 0); QWidget widget; widget.show(); @@ -105,9 +112,10 @@ void tst_QDesktopWidget::screenNumberForQWidget() int widgetScreen = desktop.screenNumber(&widget); QVERIFY(widgetScreen > -1); - QVERIFY(widgetScreen < desktop.numScreens()); + QVERIFY(widgetScreen < QGuiApplication::screens().size()); } +#if QT_DEPRECATED_SINCE(5, 11) void tst_QDesktopWidget::screenNumberForQPoint() { // make sure QDesktopWidget::screenNumber(QPoint) returns the correct screen @@ -131,25 +139,28 @@ void tst_QDesktopWidget::screenNumberForQPoint() screen = desktopWidget->screenNumber(allScreens.bottomRight() + QPoint(1, 1)); QVERIFY(screen >= 0 && screen < desktopWidget->numScreens()); } +#endif void tst_QDesktopWidget::screenGeometry() { QDesktopWidget *desktopWidget = QApplication::desktop(); QTest::ignoreMessage(QtWarningMsg, "QDesktopWidget::screenGeometry(): Attempt " "to get the screen geometry of a null widget"); - QRect r = desktopWidget->screenGeometry((QWidget *)0); + QRect r = desktopWidget->screenGeometry(nullptr); QVERIFY(r.isNull()); QWidget widget; widget.show(); QVERIFY(QTest::qWaitForWindowExposed(&widget)); r = desktopWidget->screenGeometry(&widget); +#if QT_DEPRECATED_SINCE(5, 11) QRect total; QRect available; for (int i = 0; i < desktopWidget->screenCount(); ++i) { total = desktopWidget->screenGeometry(i); available = desktopWidget->availableGeometry(i); } +#endif } void tst_QDesktopWidget::topLevels() diff --git a/tests/auto/widgets/kernel/qformlayout/qformlayout.pro b/tests/auto/widgets/kernel/qformlayout/qformlayout.pro index 617183fee6..0766b50f68 100644 --- a/tests/auto/widgets/kernel/qformlayout/qformlayout.pro +++ b/tests/auto/widgets/kernel/qformlayout/qformlayout.pro @@ -1,4 +1,4 @@ CONFIG += testcase TARGET = tst_qformlayout -QT += widgets testlib testlib-private +QT += widgets widgets-private testlib testlib-private SOURCES += tst_qformlayout.cpp diff --git a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp index cff3dad35e..c6760000f4 100644 --- a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp +++ b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp @@ -38,6 +38,9 @@ #include <QtWidgets/QLabel> #include <QtWidgets/QLineEdit> #include <QtWidgets/QPushButton> + +#include <private/qdialog_p.h> + #include <QStyleFactory> #include <QSharedPointer> @@ -52,7 +55,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 +69,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); @@ -1196,22 +1199,20 @@ void tst_QFormLayout::layoutAlone() void tst_QFormLayout::taskQTBUG_27420_takeAtShouldUnparentLayout() { QSharedPointer<QFormLayout> outer(new QFormLayout); - QPointer<QFormLayout> inner = new QFormLayout; + QAutoPointer<QFormLayout> holder{new QFormLayout}; + auto inner = holder.get(); outer->addRow(inner); QCOMPARE(outer->count(), 1); QCOMPARE(inner->parent(), outer.data()); QLayoutItem *item = outer->takeAt(0); - QCOMPARE(item->layout(), inner.data()); + QCOMPARE(item->layout(), inner); QVERIFY(!item->layout()->parent()); outer.reset(); - if (inner) - delete item; // success: a taken item/layout should not be deleted when the old parent is deleted - else - QVERIFY(!inner.isNull()); + QVERIFY(holder); // a taken item/layout should not be deleted when the old parent is deleted } void tst_QFormLayout::taskQTBUG_40609_addingWidgetToItsOwnLayout(){ diff --git a/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp b/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp index 5e0327319b..1d63d140fb 100644 --- a/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp +++ b/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp @@ -219,9 +219,9 @@ void tst_QGridLayout::badDistributionBug() QDialog dialog; Ui::SortDialog ui; ui.setupUi(&dialog); - ui.gridLayout->setMargin(0); + ui.gridLayout->setContentsMargins(0, 0, 0, 0); ui.gridLayout->setSpacing(0); - ui.vboxLayout->setMargin(0); + ui.vboxLayout->setContentsMargins(0, 0, 0, 0); ui.vboxLayout->setSpacing(0); ui.okButton->setFixedHeight(20); ui.moreButton->setFixedHeight(20); @@ -237,7 +237,7 @@ void tst_QGridLayout::setMinAndMaxSize() QWidget widget; setFrameless(&widget); QGridLayout layout(&widget); - layout.setMargin(0); + layout.setContentsMargins(0, 0, 0, 0); layout.setSpacing(0); layout.setSizeConstraint(QLayout::SetMinAndMaxSize); widget.show(); @@ -396,7 +396,7 @@ void tst_QGridLayout::spacingAndSpacers() QWidget widget; setFrameless(&widget); QGridLayout layout(&widget); - layout.setMargin(0); + layout.setContentsMargins(0, 0, 0, 0); layout.setSpacing(0); widget.show(); @@ -1541,7 +1541,7 @@ void tst_QGridLayout::spacerWithSpacing() QWidget window; QGridLayout layout(&window); layout.setSpacing(1); - layout.setMargin(0); + layout.setContentsMargins(0, 0, 0, 0); populate(&layout, 0, i); populate(&layout, 1, j); populate(&layout, 2, k); @@ -1651,7 +1651,7 @@ void tst_QGridLayout::taskQTBUG_52357_spacingWhenItemIsHidden() QWidget widget; setFrameless(&widget); QGridLayout layout(&widget); - layout.setMargin(0); + layout.setContentsMargins(0, 0, 0, 0); layout.setSpacing(5); QPushButton button1; layout.addWidget(&button1, 0, 0); diff --git a/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp b/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp index 936f581d89..140a367afe 100644 --- a/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp +++ b/tests/auto/widgets/kernel/qlayout/tst_qlayout.cpp @@ -308,7 +308,7 @@ void tst_QLayout::controlTypes2() { QWidget main; QVBoxLayout *const layout = new QVBoxLayout(&main); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); QComboBox *combo = new QComboBox(&main); layout->addWidget(combo); QCOMPARE(layout->controlTypes(), QSizePolicy::ComboBox); @@ -319,7 +319,7 @@ void tst_QLayout::adjustSizeShouldMakeSureLayoutIsActivated() QWidget main; QVBoxLayout *const layout = new QVBoxLayout(&main); - layout->setMargin(0); + layout->setContentsMargins(0, 0, 0, 0); SizeHinterFrame *frame = new SizeHinterFrame(QSize(200, 10), QSize(200, 8)); frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); layout->addWidget(frame); diff --git a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp index 53753e195a..84120c70e9 100644 --- a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp +++ b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp @@ -41,7 +41,6 @@ #include <qshortcut.h> #include <qscreen.h> -class AccelForm; QT_BEGIN_NAMESPACE class QMainWindow; class QTextEdit; @@ -51,15 +50,14 @@ class tst_QShortcut : public QObject { Q_OBJECT public: - tst_QShortcut(); - virtual ~tst_QShortcut(); - enum Action { SetupAccel, TestAccel, - ClearAll - } currentAction; + ClearAll, + TestEnd + }; + Q_ENUM(Action) enum Widget { NoWidget, @@ -70,8 +68,8 @@ public: TriggerSlot5, TriggerSlot6, TriggerSlot7, - SendKeyEvent }; + Q_ENUM(Widget) enum Result { NoResult, @@ -84,7 +82,8 @@ public: Slot7Triggered, SentKeyEvent, Ambiguous - } currentResult; + } currentResult = NoResult; + Q_ENUM(Result) public slots: void slotTrig1() { currentResult = Slot1Triggered; } @@ -101,16 +100,9 @@ public slots: void ambigSlot5() { currentResult = Ambiguous; ambigResult = Slot5Triggered; } void ambigSlot6() { currentResult = Ambiguous; ambigResult = Slot6Triggered; } void ambigSlot7() { currentResult = Ambiguous; ambigResult = Slot7Triggered; } - void statusMessage( const QString& message ) { sbText = message; } - void shortcutDestroyed(QObject* obj); - void sendKeyEvent() { sendKeyEvents(edit, Qt::CTRL + Qt::Key_B, 0); currentResult = SentKeyEvent; } - -public slots: - void initTestCase(); - void cleanupTestCase(); - void cleanup() { QCOMPARE(QApplication::topLevelWidgets().size(), 1); } private slots: + void cleanup(); void number_data(); void number(); void text_data(); @@ -129,29 +121,19 @@ protected: static Qt::KeyboardModifiers toButtons( int key ); void defElements(); - void clearAllShortcuts(); - QShortcut *setupShortcut(int testWidget, const QKeySequence &ks); - QShortcut *setupShortcut(int testWidget, const QString &txt, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0); - - QShortcut *setupShortcut(QWidget *parent, const char *name, int testWidget, const QString &txt, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0); - QShortcut *setupShortcut(QWidget *parent, const char *name, int testWidget, const QKeySequence &ks, Qt::ShortcutContext context = Qt::WindowShortcut); + QShortcut *setupShortcut(QWidget *parent, const QString &name, const QKeySequence &ks, + Qt::ShortcutContext context = Qt::WindowShortcut); + QShortcut *setupShortcut(QWidget *parent, const QString &name, Widget testWidget, + const QKeySequence &ks, Qt::ShortcutContext context = Qt::WindowShortcut); - void sendKeyEvents(QWidget *w, int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0); - void sendKeyEvents(int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0); + static void sendKeyEvents(QWidget *w, int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, + int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0); void testElement(); - QMainWindow *mainW; - QList<QShortcut*> shortcuts; - QTextEdit *edit; - QString sbText; Result ambigResult; }; -Q_DECLARE_METATYPE(tst_QShortcut::Widget); -Q_DECLARE_METATYPE(tst_QShortcut::Result); -Q_DECLARE_METATYPE(tst_QShortcut::Action); - class TestEdit : public QTextEdit { Q_OBJECT @@ -163,7 +145,8 @@ public: } protected: - bool event(QEvent *e) { + bool event(QEvent *e) override + { // Make testedit allow any Ctrl+Key as shortcut if (e->type() == QEvent::ShortcutOverride) { QKeyEvent *ke = static_cast<QKeyEvent*>(e); @@ -196,33 +179,28 @@ protected: } }; -tst_QShortcut::tst_QShortcut(): mainW( 0 ) +class MainWindow : public QMainWindow { -} +public: + MainWindow(); -tst_QShortcut::~tst_QShortcut() -{ - clearAllShortcuts(); -} + TestEdit *testEdit() const { return m_testEdit; } -void tst_QShortcut::initTestCase() +private: + TestEdit *m_testEdit; +}; + +MainWindow::MainWindow() { - currentResult = NoResult; - mainW = new QMainWindow(0); - mainW->setWindowFlags(Qt::X11BypassWindowManagerHint); - edit = new TestEdit(mainW, "test_edit"); - mainW->setFixedSize( 200, 200 ); - mainW->setCentralWidget( edit ); - mainW->show(); - mainW->activateWindow(); - QVERIFY(QTest::qWaitForWindowActive(mainW)); - connect( mainW->statusBar(), SIGNAL(messageChanged(QString)), - this, SLOT(statusMessage(QString)) ); + setWindowFlags(Qt::X11BypassWindowManagerHint); + m_testEdit = new TestEdit(this, "test_edit"); + setCentralWidget(m_testEdit); + setFixedSize(200, 200); } -void tst_QShortcut::cleanupTestCase() +void tst_QShortcut::cleanup() { - delete mainW; + QVERIFY(QApplication::topLevelWidgets().size() <= 1); // The data driven tests keep a widget around } Qt::KeyboardModifiers tst_QShortcut::toButtons( int key ) @@ -277,7 +255,7 @@ void tst_QShortcut::number_data() defElements(); // Clear all - QTest::newRow("N00 - clear") << ClearAll << NoWidget <<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<NoResult; + QTest::newRow("N00 - clear") << ClearAll << NoWidget <<QString()<<0<<0<<0<<0<<0<<0<<0<<0<<NoResult; //=========================================== // [Shift + key] on non-shift shortcuts testing @@ -289,15 +267,15 @@ void tst_QShortcut::number_data() Shift + Qt::Key_Plus on Qt::Key_Pluss Qt::Key_Plus on Qt::Key_Pluss */ - QTest::newRow("N001 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N001 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("N001:Shift + M - [M]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N001:M - [M]") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N001 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + //QTest::newRow("N001:Shift + M - [M]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N001:M - [M]") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N001 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("N001:Shift++ [+]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N001:+ [+]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N001 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + //QTest::newRow("N001:Shift++ [+]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N001:+ [+]") << TestAccel << NoWidget << QString() << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N001 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_M on Shift + Qt::Key_M @@ -305,32 +283,32 @@ void tst_QShortcut::number_data() Shift + Qt::Key_Plus on Shift + Qt::Key_Pluss Qt::Key_Plus on Shift + Qt::Key_Pluss */ - QTest::newRow("N002 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::SHIFT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N002:Shift+M - [Shift+M]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N002:M - [Shift+M]") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N002 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N002:Shift++ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N002:+ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N002 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N002 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::SHIFT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N002:Shift+M - [Shift+M]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N002:M - [Shift+M]") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N002 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::SHIFT + Qt::Key_Plus) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N002:Shift++ [Shift++]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N002:+ [Shift++]") << TestAccel << NoWidget << QString() << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N002 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_F1 on Qt::Key_F1 Qt::Key_F1 on Qt::Key_F1 */ - QTest::newRow("N003 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N003 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("N003:Shift+F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N003:F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N003 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + //QTest::newRow("N003:Shift+F1 - [F1]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N003:F1 - [F1]") << TestAccel << NoWidget << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N003 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_F1 on Shift + Qt::Key_F1 Qt::Key_F1 on Shift + Qt::Key_F1 */ - QTest::newRow("N004 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N004:Shift+F1 - [Shift+F1]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N004:F1 - [Shift+F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N004 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N004 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N004:Shift+F1 - [Shift+F1]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N004:F1 - [Shift+F1]") << TestAccel << NoWidget << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N004 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_Tab on Qt::Key_Tab @@ -338,14 +316,14 @@ void tst_QShortcut::number_data() Qt::Key_Backtab on Qt::Key_Tab Shift + Qt::Key_Backtab on Qt::Key_Tab */ - QTest::newRow("N005a - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N005a:Tab - [Tab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N005a - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N005a:Tab - [Tab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("N005a:Shift+Tab - [Tab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + //QTest::newRow("N005a:Shift+Tab - [Tab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; // (Shift+)BackTab != Tab, but Shift+BackTab == Shift+Tab - QTest::newRow("N005a:Backtab - [Tab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N005a:Shift+Backtab - [Tab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N005a - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N005a:Backtab - [Tab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N005a:Shift+Backtab - [Tab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N005a - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_Tab on Shift + Qt::Key_Tab @@ -353,12 +331,12 @@ void tst_QShortcut::number_data() Qt::Key_Backtab on Shift + Qt::Key_Tab Shift + Qt::Key_Backtab on Shift + Qt::Key_Tab */ - QTest::newRow("N005b - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N005b:Tab - [Shift+Tab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N005b:Shift+Tab - [Shift+Tab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N005b:BackTab - [Shift+Tab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N005b:Shift+BackTab - [Shift+Tab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N005b - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N005b - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N005b:Tab - [Shift+Tab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N005b:Shift+Tab - [Shift+Tab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N005b:BackTab - [Shift+Tab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N005b:Shift+BackTab - [Shift+Tab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N005b - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_Tab on Qt::Key_Backtab @@ -366,15 +344,15 @@ void tst_QShortcut::number_data() Qt::Key_Backtab on Qt::Key_Backtab Shift + Qt::Key_Backtab on Qt::Key_Backtab */ - QTest::newRow("N006a - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N006a:Tab - [BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N006a - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N006a:Tab - [BackTab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // This should work, since platform dependent code will transform the // Shift+Tab into a Shift+BackTab, which should trigger the shortcut - QTest::newRow("N006a:Shift+Tab - [BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //XFAIL - QTest::newRow("N006a:BackTab - [BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N006a:Shift+Tab - [BackTab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //XFAIL + QTest::newRow("N006a:BackTab - [BackTab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("N006a:Shift+BackTab - [BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N006a - clear") << ClearAll << NoWidget<< QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + //QTest::newRow("N006a:Shift+BackTab - [BackTab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N006a - clear") << ClearAll << NoWidget<< QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_Tab on Shift + Qt::Key_Backtab @@ -382,12 +360,12 @@ void tst_QShortcut::number_data() Qt::Key_Backtab on Shift + Qt::Key_Backtab Shift + Qt::Key_Backtab on Shift + Qt::Key_Backtab */ - QTest::newRow("N006b - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N006b:Tab - [Shift+BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N006b:Shift+Tab - [Shift+BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N006b:BackTab - [Shift+BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N006b:Shift+BackTab - [Shift+BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //XFAIL - QTest::newRow("N006b - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N006b - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N006b:Tab - [Shift+BackTab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N006b:Shift+Tab - [Shift+BackTab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N006b:BackTab - [Shift+BackTab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N006b:Shift+BackTab - [Shift+BackTab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //XFAIL + QTest::newRow("N006b - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all //=========================================== // [Shift + key] and [key] on shortcuts with @@ -398,11 +376,11 @@ void tst_QShortcut::number_data() Qt::Key_F1 Shift + Qt::Key_F1 */ - QTest::newRow("N007 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N007 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N007:F1") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N007:Shift + F1") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N007 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N007 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N007 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N007:F1") << TestAccel << NoWidget << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N007:Shift + F1") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N007 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_M @@ -410,51 +388,51 @@ void tst_QShortcut::number_data() Ctrl + Qt::Key_M Alt + Qt::Key_M */ - QTest::newRow("N01 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N02 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N03 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N04 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N:Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N:Shift+Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N:Ctrl+Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N:Alt+Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N01 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N02 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N03 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N04 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N:Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N:Shift+Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N:Ctrl+Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N:Alt+Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; /* Testing Single Sequence Ambiguity Qt::Key_M on shortcut2 */ - QTest::newRow("N05 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N:Qt::Key_M on slot") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Ambiguous; - QTest::newRow("N05 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N05 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N:Qt::Key_M on slot") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Ambiguous; + QTest::newRow("N05 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Specialkeys Qt::Key_aring Qt::Key_Aring Qt::UNICODE_ACCEL + Qt::Key_K */ - QTest::newRow("N06 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N07 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N08 - slot2") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::UNICODE_ACCEL + Qt::Key_K) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N06 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N07 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N08 - slot2") << SetupAccel << TriggerSlot1 << QString() << int(Qt::UNICODE_ACCEL + Qt::Key_K) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N:Qt::Key_aring") << TestAccel << NoWidget << QString("") << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N:Qt::Key_Aring") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N:Qt::Key_aring - Text Form") << TestAccel << NoWidget << QString("") << 0 << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N:Qt::Key_Aring - Text Form") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT+0) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N:Qt::UNICODE_ACCEL + Qt::Key_K")<< TestAccel << NoWidget << QString("") << int(Qt::UNICODE_ACCEL + Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N09 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N:Qt::Key_aring") << TestAccel << NoWidget << QString() << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N:Qt::Key_Aring") << TestAccel << NoWidget << QString() << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N:Qt::Key_aring - Text Form") << TestAccel << NoWidget << QString() << 0 << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N:Qt::Key_Aring - Text Form") << TestAccel << NoWidget << QString() << int(Qt::SHIFT+0) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N:Qt::UNICODE_ACCEL + Qt::Key_K")<< TestAccel << NoWidget << QString() << int(Qt::UNICODE_ACCEL + Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N09 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Multiple Sequences Qt::Key_M Qt::Key_I, Qt::Key_M Shift+Qt::Key_I, Qt::Key_M */ - QTest::newRow("N10 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N11 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::Key_I) << 0 << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N12 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::SHIFT + Qt::Key_I) << 0 << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << NoResult; - - QTest::newRow("N:Qt::Key_M (2)") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N:Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N:Shift+Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N13 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N10 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N11 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::Key_I) << 0 << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N12 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::SHIFT + Qt::Key_I) << 0 << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << NoResult; + + QTest::newRow("N:Qt::Key_M (2)") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N:Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N:Shift+Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N:end") << TestEnd << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; } // ------------------------------------------------------------------ @@ -464,7 +442,7 @@ void tst_QShortcut::text_data() { defElements(); // Clear all - QTest::newRow("T00 - clear") << ClearAll << NoWidget <<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<< NoResult; + QTest::newRow("T00 - clear") << ClearAll << NoWidget <<QString()<<0<<0<<0<<0<<0<<0<<0<<0<< NoResult; //=========================================== // [Shift + key] on non-shift shortcuts testing @@ -478,13 +456,13 @@ void tst_QShortcut::text_data() */ QTest::newRow("T001 - slot1") << SetupAccel << TriggerSlot1 << QString("M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("T001:Shift+M - [M]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T001:M - [M]") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + //QTest::newRow("T001:Shift+M - [M]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T001:M - [M]") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("T001 - slot2") << SetupAccel << TriggerSlot2 << QString("+") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("T001:Shift++ [+]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T001:+ [+]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T001 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + //QTest::newRow("T001:Shift++ [+]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T001:+ [+]") << TestAccel << NoWidget << QString() << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T001 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_M on Shift + Qt::Key_M @@ -495,12 +473,12 @@ void tst_QShortcut::text_data() Ctrl + Qt::Key_Plus on Ctrl + Qt::Key_Pluss */ QTest::newRow("T002 - slot1") << SetupAccel << TriggerSlot1 << QString("Shift+M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T002:Shift+M - [Shift+M]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T002:M - [Shift+M]") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("T002:Shift+M - [Shift+M]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T002:M - [Shift+M]") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T002 - slot2") << SetupAccel << TriggerSlot2 << QString("Shift++") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T002:Shift++ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T002:+ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T002 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("T002:Shift++ [Shift++]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T002:+ [Shift++]") << TestAccel << NoWidget << QString() << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("T002 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Ctrl + Qt::Key_Plus on Ctrl + Qt::Key_Plus @@ -509,10 +487,10 @@ void tst_QShortcut::text_data() */ QTest::newRow("T002b - slot1") << SetupAccel << TriggerSlot1 << QString("Ctrl++") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("T002b:Shift+Ctrl++ [Ctrl++]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::CTRL + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T002b:Ctrl++ [Ctrl++]") << TestAccel << NoWidget << QString("") << int(Qt::CTRL + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T002b:+ [Ctrl++]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T002b - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + //QTest::newRow("T002b:Shift+Ctrl++ [Ctrl++]")<< TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::CTRL + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T002b:Ctrl++ [Ctrl++]") << TestAccel << NoWidget << QString() << int(Qt::CTRL + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T002b:+ [Ctrl++]") << TestAccel << NoWidget << QString() << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("T002b - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_F1 on Qt::Key_F1 @@ -520,18 +498,18 @@ void tst_QShortcut::text_data() */ QTest::newRow("T003 - slot1") << SetupAccel << TriggerSlot1 << QString("F1") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("T003:Shift+F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T003:F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T003 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + //QTest::newRow("T003:Shift+F1 - [F1]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T003:F1 - [F1]") << TestAccel << NoWidget << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T003 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_F1 on Shift + Qt::Key_F1 Qt::Key_F1 on Shift + Qt::Key_F1 */ QTest::newRow("T004 - slot1") << SetupAccel << TriggerSlot1 << QString("Shift+F1") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T004:Shift+F1 - [Shift+F1]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T004:F1 - [Shift+F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T004 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("T004:Shift+F1 - [Shift+F1]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T004:F1 - [Shift+F1]") << TestAccel << NoWidget << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("T004 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all //=========================================== // [Shift + key] and [key] on shortcuts with @@ -544,9 +522,9 @@ void tst_QShortcut::text_data() */ QTest::newRow("T007 - slot1") << SetupAccel << TriggerSlot1 << QString("F1") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T007 - slot2") << SetupAccel << TriggerSlot2 << QString("Shift+F1") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T007:F1") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T007:Shift + F1") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T007 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("T007:F1") << TestAccel << NoWidget << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T007:Shift + F1") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T007 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_M @@ -559,17 +537,17 @@ void tst_QShortcut::text_data() QTest::newRow("T03 - slot1") << SetupAccel << TriggerSlot1 << QString("Ctrl+M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T04 - slot2") << SetupAccel << TriggerSlot2 << QString("Alt+M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T:Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T:Shift + Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T:Ctrl + Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T:Alt + Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T:Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T:Shift + Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T:Ctrl + Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T:Alt + Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; /* Testing Single Sequence Ambiguity Qt::Key_M on shortcut2 */ QTest::newRow("T05 - slot2") << SetupAccel << TriggerSlot2 << QString("M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T:Qt::Key_M on TriggerSlot2") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Ambiguous; - QTest::newRow("T06 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("T:Qt::Key_M on TriggerSlot2") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Ambiguous; + QTest::newRow("T06 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Specialkeys Qt::Key_aring @@ -580,12 +558,12 @@ void tst_QShortcut::text_data() QTest::newRow("T06 - slot1") << SetupAccel << TriggerSlot1 << QString::fromLatin1("\x0C5")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T07 - slot2") << SetupAccel << TriggerSlot2 << QString::fromLatin1("Shift+\x0C5")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T08 - slot2") << SetupAccel << TriggerSlot1 << QString("K") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T:Qt::Key_aring") << TestAccel << NoWidget << QString("") << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T:Qt::Key_Aring") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T:Qt::Key_aring - Text Form") << TestAccel << NoWidget << QString("") << 0 << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T:Qt::Key_Aring - Text Form") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT+0) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T:Qt::UNICODE_ACCEL + Qt::Key_K")<< TestAccel << NoWidget << QString("") << int(Qt::UNICODE_ACCEL + Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T09 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("T:Qt::Key_aring") << TestAccel << NoWidget << QString() << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T:Qt::Key_Aring") << TestAccel << NoWidget << QString() << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T:Qt::Key_aring - Text Form") << TestAccel << NoWidget << QString() << 0 << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T:Qt::Key_Aring - Text Form") << TestAccel << NoWidget << QString() << int(Qt::SHIFT+0) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T:Qt::UNICODE_ACCEL + Qt::Key_K")<< TestAccel << NoWidget << QString() << int(Qt::UNICODE_ACCEL + Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T09 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Multiple Sequences Qt::Key_M @@ -595,10 +573,38 @@ void tst_QShortcut::text_data() QTest::newRow("T10 - slot1") << SetupAccel << TriggerSlot1 << QString("M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T11 - slot2") << SetupAccel << TriggerSlot2 << QString("I, M")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T12 - slot1") << SetupAccel << TriggerSlot1 << QString("Shift+I, M")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T:Qt::Key_M (2)") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T:Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T:Shift+Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T13 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("T:Qt::Key_M (2)") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T:Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T:Shift+Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T:end") << TestEnd << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; +} + +class ButtonWidget : public QWidget +{ +public: + ButtonWidget(); + + QPushButton *pushButton1() const { return m_pb1; } + QPushButton *pushButton2() const { return m_pb2; } + +private: + QPushButton *m_pb1; + QPushButton *m_pb2; +}; + +ButtonWidget::ButtonWidget() +{ + // Setup two identical shortcuts on different pushbuttons + QString name = QLatin1String("pushbutton-1"); + m_pb1 = new QPushButton(name, this); + m_pb1->setObjectName(name); + name = QLatin1String("pushbutton-2"); + m_pb2 = new QPushButton(name, this); + m_pb2->setObjectName(name); + auto hLayout = new QHBoxLayout(this); + hLayout->addWidget(m_pb1); + hLayout->addWidget(m_pb2); + hLayout->addStretch(); } // ------------------------------------------------------------------ @@ -606,9 +612,11 @@ void tst_QShortcut::text_data() // ------------------------------------------------------------------ void tst_QShortcut::disabledItems() { - clearAllShortcuts(); - mainW->activateWindow(); - QVERIFY(QTest::qWaitForWindowActive(mainW)); + ButtonWidget mainW; + mainW.setWindowTitle(QTest::currentTestFunction()); + mainW.show(); + mainW.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&mainW)); /* Testing Disabled Shortcuts Qt::Key_M on slot1 @@ -618,27 +626,27 @@ void tst_QShortcut::disabledItems() */ // Setup two identical shortcuts on different pushbuttons - QPushButton pb1(mainW); - QPushButton pb2(mainW); - pb1.setObjectName("pushbutton-1"); - pb2.setObjectName("pushbutton-2"); - pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger - pb2.show(); - - QShortcut *cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "M"); - QShortcut *cut2 = setupShortcut(&pb1, "shortcut2-pb1", TriggerSlot1, "Shift+M"); - QShortcut *cut3 = setupShortcut(&pb2, "shortcut3-pb2", TriggerSlot2, "M"); - QShortcut *cut4 = setupShortcut(&pb2, "shortcut4-pb2", TriggerSlot2, "Shift+M"); + auto pb1 = mainW.pushButton1(); + auto pb2 = mainW.pushButton2(); + const int shiftM = Qt::SHIFT + Qt::Key_M; + QShortcut *cut1 = setupShortcut(pb1, "shortcut1-pb1", TriggerSlot1, + QKeySequence(Qt::Key_M)); + QShortcut *cut2 = setupShortcut(pb1, "shortcut2-pb1", TriggerSlot1, + QKeySequence(shiftM)); + QShortcut *cut3 = setupShortcut(pb2, "shortcut3-pb2", TriggerSlot2, + QKeySequence(Qt::Key_M)); + QShortcut *cut4 = setupShortcut(pb2, "shortcut4-pb2", TriggerSlot2, + QKeySequence(shiftM)); cut3->setEnabled(false); cut4->setEnabled(false); currentResult = NoResult; - sendKeyEvents(Qt::Key_M, 'm'); + sendKeyEvents(&mainW, Qt::Key_M, 'm'); QCOMPARE(currentResult, Slot1Triggered); currentResult = NoResult; - sendKeyEvents(Qt::SHIFT+Qt::Key_M, 'M'); + sendKeyEvents(&mainW, shiftM, 'M'); QCOMPARE(currentResult, Slot1Triggered); cut2->setEnabled(false); @@ -651,11 +659,11 @@ void tst_QShortcut::disabledItems() Shift + Qt::Key_M on slot2 */ currentResult = NoResult; - sendKeyEvents( Qt::Key_M, 'm' ); + sendKeyEvents(&mainW, Qt::Key_M, 'm' ); QCOMPARE( currentResult, Slot1Triggered ); currentResult = NoResult; - sendKeyEvents( Qt::SHIFT+Qt::Key_M, 'M' ); + sendKeyEvents(&mainW, shiftM, 'M' ); QCOMPARE( currentResult, Slot2Triggered ); @@ -663,67 +671,34 @@ void tst_QShortcut::disabledItems() Qt::Key_F5 on slot1 Shift + Qt::Key_F5 on slot2 (disabled) */ - clearAllShortcuts(); - cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "F5"); - cut4 = setupShortcut(&pb2, "shortcut4-pb2", TriggerSlot2, "Shift+F5"); - - cut1->setKey(QKeySequence("F5")); - cut4->setKey(QKeySequence("Shift+F5")); + qDeleteAll(mainW.findChildren<QShortcut *>()); + const int shiftF5 = Qt::SHIFT + Qt::Key_F5; + cut1 = setupShortcut(pb1, "shortcut1-pb1", TriggerSlot1, QKeySequence(Qt::Key_F5)); + cut4 = setupShortcut(pb2, "shortcut4-pb2", TriggerSlot2, QKeySequence(shiftF5)); cut1->setEnabled(true); cut4->setEnabled(false); currentResult = NoResult; - sendKeyEvents( Qt::Key_F5, 0 ); + sendKeyEvents(&mainW, Qt::Key_F5, 0 ); QCOMPARE( currentResult, Slot1Triggered ); currentResult = NoResult; - sendKeyEvents( Qt::SHIFT+Qt::Key_F5, 0 ); - QCOMPARE( currentResult, NoResult ); - -#if 0 - qFatal("Not testing statusbar text feedback yet, since not implemented"); - /* Testing Disabled Accel, and the corresponding statusbar feedback - Ctrl + Qt::Key_K, Ctrl + Qt::Key_L on slot1 - Ctrl + Qt::Key_K, Ctrl + Qt::Key_M on slot2 (disabled) - */ - cut1->setKey(QKeySequence("Ctrl+K, Ctrl+L")); - cut4->setKey(QKeySequence("Ctrl+K, Ctrl+M")); - - cut1->setEnabled(true); - cut4->setEnabled(false); - - currentResult = NoResult; - sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); - sendKeyEvents( Qt::CTRL+Qt::Key_Q, 0 ); - QCOMPARE( currentResult, NoResult ); - if (over_330) - QCOMPARE( sbText, QString("Ctrl+K, Ctrl+Q not defined") ); - - currentResult = NoResult; - sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); - sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 ); + sendKeyEvents(&mainW, shiftF5, 0 ); QCOMPARE( currentResult, NoResult ); - if (over_330) - QCOMPARE( sbText, QString() ); - - currentResult = NoResult; - sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); - sendKeyEvents( Qt::CTRL+Qt::Key_L, 0 ); - QCOMPARE( currentResult, Slot1Triggered ); - if (over_330) - QCOMPARE( sbText, QString() ); -#endif - clearAllShortcuts(); - cut1 = 0; - cut4 = 0; } // ------------------------------------------------------------------ // Ambiguous Elements ----------------------------------------------- // ------------------------------------------------------------------ void tst_QShortcut::ambiguousRotation() { - clearAllShortcuts(); + MainWindow mainW; + const QString name = QLatin1String(QTest::currentTestFunction()); + mainW.setWindowTitle(name); + mainW.show(); + mainW.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&mainW)); + /* Testing Shortcut rotation scheme Ctrl + Qt::Key_A on slot1 (disabled) Ctrl + Qt::Key_A on slot2 (disabled) @@ -733,13 +708,15 @@ void tst_QShortcut::ambiguousRotation() Ctrl + Qt::Key_A on slot6 Ctrl + Qt::Key_A on slot7 (disabled) */ - QShortcut *cut1 = setupShortcut(TriggerSlot1, "Ctrl+A"); - QShortcut *cut2 = setupShortcut(TriggerSlot2, "Ctrl+A"); - QShortcut *cut3 = setupShortcut(TriggerSlot3, "Ctrl+A"); - QShortcut *cut4 = setupShortcut(TriggerSlot4, "Ctrl+A"); - QShortcut *cut5 = setupShortcut(TriggerSlot5, "Ctrl+A"); - QShortcut *cut6 = setupShortcut(TriggerSlot6, "Ctrl+A"); - QShortcut *cut7 = setupShortcut(TriggerSlot7, "Ctrl+A"); + const int ctrlA = Qt::CTRL + Qt::Key_A; + QKeySequence ctrlA_Sequence(ctrlA); + QShortcut *cut1 = setupShortcut(&mainW, name, TriggerSlot1, ctrlA_Sequence); + QShortcut *cut2 = setupShortcut(&mainW, name, TriggerSlot2, ctrlA_Sequence); + QShortcut *cut3 = setupShortcut(&mainW, name, TriggerSlot3, ctrlA_Sequence); + QShortcut *cut4 = setupShortcut(&mainW, name, TriggerSlot4, ctrlA_Sequence); + QShortcut *cut5 = setupShortcut(&mainW, name, TriggerSlot5, ctrlA_Sequence); + QShortcut *cut6 = setupShortcut(&mainW, name, TriggerSlot6, ctrlA_Sequence); + QShortcut *cut7 = setupShortcut(&mainW, name, TriggerSlot7, ctrlA_Sequence); cut1->setEnabled(false); cut2->setEnabled(false); @@ -753,37 +730,37 @@ void tst_QShortcut::ambiguousRotation() // Continue... currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot3Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot4Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot6Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot3Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot4Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot6Triggered); @@ -808,94 +785,87 @@ void tst_QShortcut::ambiguousRotation() currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot1Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot2Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot5Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot7Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot1Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot2Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot5Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot7Triggered); - - clearAllShortcuts(); - cut1 = 0; cut2 = 0; - cut3 = 0; cut4 = 0; - cut5 = 0; cut6 = 0; - cut7 = 0; } void tst_QShortcut::ambiguousItems() { - clearAllShortcuts(); + ButtonWidget mainW; + mainW.setWindowTitle(QTest::currentTestFunction()); + mainW.show(); + mainW.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&mainW)); + /* Testing Ambiguous Shortcuts Qt::Key_M on Pushbutton 1 Qt::Key_M on Pushbutton 2 */ // Setup two identical shortcuts on different pushbuttons - QPushButton pb1(mainW); - QPushButton pb2(mainW); - pb1.setObjectName("pushbutton-1"); - pb2.setObjectName("pushbutton-2"); - pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger - pb2.show(); + auto pb1 = mainW.pushButton1(); + auto pb2 = mainW.pushButton2(); - setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "M"); - setupShortcut(&pb1, "shortcut2-pb2", TriggerSlot2, "M"); + setupShortcut(pb1, "shortcut1-pb1", TriggerSlot1, QKeySequence(Qt::Key_M)); + setupShortcut(pb2, "shortcut2-pb2", TriggerSlot2, QKeySequence(Qt::Key_M)); currentResult = NoResult; - sendKeyEvents( Qt::Key_M, 'm' ); + sendKeyEvents(&mainW, Qt::Key_M, 'm' ); QCOMPARE( currentResult, Ambiguous ); QCOMPARE( ambigResult, Slot1Triggered ); currentResult = NoResult; - sendKeyEvents( Qt::Key_M, 'm' ); + sendKeyEvents(&mainW, Qt::Key_M, 'm' ); QCOMPARE( currentResult, Ambiguous ); QCOMPARE( ambigResult, Slot2Triggered ); currentResult = NoResult; - sendKeyEvents( Qt::Key_M, 'm' ); + sendKeyEvents(&mainW, Qt::Key_M, 'm' ); QCOMPARE( currentResult, Ambiguous ); QCOMPARE( ambigResult, Slot1Triggered ); - - clearAllShortcuts(); } @@ -904,32 +874,31 @@ void tst_QShortcut::ambiguousItems() // ------------------------------------------------------------------ void tst_QShortcut::unicodeCompare() { - clearAllShortcuts(); + ButtonWidget mainW; + mainW.setWindowTitle(QTest::currentTestFunction()); + mainW.show(); + mainW.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&mainW)); + /* Testing Unicode/non-Unicode Shortcuts Qt::Key_M on Pushbutton 1 Qt::Key_M on Pushbutton 2 */ - QPushButton pb1(mainW); - QPushButton pb2(mainW); - pb1.setObjectName("pushbutton-1"); - pb2.setObjectName("pushbutton-2"); - pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger - pb2.show(); + auto pb1 = mainW.pushButton1(); + auto pb2 = mainW.pushButton2(); QKeySequence ks1("Ctrl+M"); // Unicode QKeySequence ks2(Qt::CTRL+Qt::Key_M); // non-Unicode - setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, ks1); - setupShortcut(&pb1, "shortcut2-pb2", TriggerSlot2, ks2); + setupShortcut(pb1, "shortcut1-pb1", TriggerSlot1, ks1); + setupShortcut(pb2, "shortcut2-pb2", TriggerSlot2, ks2); currentResult = NoResult; - sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 ); + sendKeyEvents(&mainW, Qt::CTRL + Qt::Key_M, 0); QCOMPARE( currentResult, Ambiguous ); // They _are_ ambiguous, so the QKeySequence operator== // should indicate the same QVERIFY( ks1 == ks2 ); QVERIFY( !(ks1 != ks2) ); - - clearAllShortcuts(); } // ------------------------------------------------------------------ @@ -937,25 +906,29 @@ void tst_QShortcut::unicodeCompare() // ------------------------------------------------------------------ void tst_QShortcut::keypressConsumption() { - clearAllShortcuts(); - edit->clear(); - QCOMPARE(edit->toPlainText().size(), 0); + MainWindow mainW; + mainW.setWindowTitle(QTest::currentTestFunction()); + mainW.show(); + mainW.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&mainW)); + auto edit = mainW.testEdit(); - QShortcut *cut1 = setupShortcut(edit, "shortcut1-line", TriggerSlot1, "Ctrl+I, A"); - QShortcut *cut2 = setupShortcut(edit, "shortcut1-line", TriggerSlot2, "Ctrl+I, B"); + const int ctrlI = Qt::CTRL + Qt::Key_I; + QShortcut *cut1 = setupShortcut(edit, "shortcut1-line", TriggerSlot1, QKeySequence(ctrlI, Qt::Key_A)); + QShortcut *cut2 = setupShortcut(edit, "shortcut1-line", TriggerSlot2, QKeySequence(ctrlI, Qt::Key_B)); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(edit, Qt::CTRL + Qt::Key_I, 0); // Send key to edit + sendKeyEvents(edit, ctrlI, 0); // Send key to edit QCOMPARE( currentResult, NoResult ); QCOMPARE( ambigResult, NoResult ); - QCOMPARE(edit->toPlainText(), QString("")); + QCOMPARE(edit->toPlainText(), QString()); // Make sure next keypress is eaten (failing multiple keysequence) sendKeyEvents(edit, Qt::Key_C, 'c'); // Send key to edit QCOMPARE( currentResult, NoResult ); QCOMPARE( ambigResult, NoResult ); - QCOMPARE(edit->toPlainText(), QString("")); + QCOMPARE(edit->toPlainText(), QString()); // Next keypress should be normal sendKeyEvents(edit, Qt::Key_C, 'c'); // Send key to edit @@ -983,11 +956,15 @@ void tst_QShortcut::keypressConsumption() QCOMPARE( ambigResult, NoResult ); QVERIFY(edit->toPlainText().endsWith("<Ctrl+I>a")); - clearAllShortcuts(); + qDeleteAll(mainW.findChildren<QShortcut *>()); edit->clear(); QCOMPARE(edit->toPlainText().size(), 0); - setupShortcut(edit, "first", SendKeyEvent, "Ctrl+A"); + auto cut = setupShortcut(edit, QLatin1String("first"), QKeySequence(Qt::CTRL + Qt::Key_A)); + connect(cut, &QShortcut::activated, edit, [this, edit] () { + this->sendKeyEvents(edit, Qt::CTRL + Qt::Key_B, 0); + this->currentResult = tst_QShortcut::SentKeyEvent; + }); // Verify reentrancy when a non-shortcut is triggered as part // of shortcut processing. @@ -996,7 +973,7 @@ void tst_QShortcut::keypressConsumption() sendKeyEvents(edit, Qt::CTRL + Qt::Key_A, 0); QCOMPARE(currentResult, SentKeyEvent); QCOMPARE(ambigResult, NoResult); - QCOMPARE(edit->toPlainText(), QString(QString("<Ctrl+B>"))); + QCOMPARE(edit->toPlainText(), QLatin1String("<Ctrl+B>")); } // ------------------------------------------------------------------ @@ -1004,12 +981,17 @@ void tst_QShortcut::keypressConsumption() // ------------------------------------------------------------------ void tst_QShortcut::context() { - clearAllShortcuts(); + const QString name = QLatin1String(QTest::currentTestFunction()); + MainWindow mainW; + mainW.setWindowTitle(name + QLatin1String("_Helper")); + mainW.show(); + auto edit = mainW.testEdit(); QWidget myBox; - TestEdit *other1 = new TestEdit(&myBox, "test_edit_other1"); - TestEdit *other2 = new TestEdit(&myBox, "test_edit_other2"); - QHBoxLayout *layout = new QHBoxLayout(&myBox); + myBox.setWindowTitle(name); + auto other1 = new TestEdit(&myBox, "test_edit_other1"); + auto other2 = new TestEdit(&myBox, "test_edit_other2"); + auto layout = new QHBoxLayout(&myBox); layout->addWidget(other1); layout->addWidget(other2); myBox.show(); @@ -1034,8 +1016,8 @@ void tst_QShortcut::context() // Focus on 'other1' edit, so Active Window context should trigger other1->activateWindow(); // <--- QApplication::setActiveWindow(other1); - QCOMPARE(qApp->activeWindow(), other1->window()); - QCOMPARE(qApp->focusWidget(), (QWidget *)other1); + QCOMPARE(QApplication::activeWindow(), other1->window()); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(other1)); currentResult = NoResult; ambigResult = NoResult; @@ -1043,13 +1025,13 @@ void tst_QShortcut::context() other1->clear(); other2->clear(); - QCOMPARE(qApp->focusWidget(), (QWidget *)other1); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(other1)); sendKeyEvents(other1, Qt::ALT+Qt::Key_1); QCOMPARE(currentResult, Slot1Triggered); QCOMPARE(ambigResult, NoResult); - QCOMPARE(edit->toPlainText(), QString("")); - QCOMPARE(other1->toPlainText(), QString("")); - QCOMPARE(other2->toPlainText(), QString("")); + QCOMPARE(edit->toPlainText(), QString()); + QCOMPARE(other1->toPlainText(), QString()); + QCOMPARE(other2->toPlainText(), QString()); // ..but not Focus context on 'other2'.. currentResult = NoResult; @@ -1061,9 +1043,9 @@ void tst_QShortcut::context() sendKeyEvents(other1, Qt::ALT+Qt::Key_2); QCOMPARE(currentResult, NoResult); QCOMPARE(ambigResult, NoResult); - QCOMPARE(edit->toPlainText(), QString("")); + QCOMPARE(edit->toPlainText(), QString()); QCOMPARE(other1->toPlainText(), QString("<Alt+2>")); - QCOMPARE(other2->toPlainText(), QString("")); + QCOMPARE(other2->toPlainText(), QString()); // ..however, application global context on 'edit' should.. currentResult = NoResult; @@ -1075,15 +1057,15 @@ void tst_QShortcut::context() sendKeyEvents(other1, Qt::ALT+Qt::Key_3); QCOMPARE(currentResult, Slot3Triggered); QCOMPARE(ambigResult, NoResult); - QCOMPARE(edit->toPlainText(), QString("")); - QCOMPARE(other1->toPlainText(), QString("")); - QCOMPARE(other2->toPlainText(), QString("")); + QCOMPARE(edit->toPlainText(), QString()); + QCOMPARE(other1->toPlainText(), QString()); + QCOMPARE(other2->toPlainText(), QString()); // Changing focus to 'other2' should make the Focus context there work other2->activateWindow(); other2->setFocus(); // ### - QTRY_COMPARE(qApp->activeWindow(), other2->window()); - QCOMPARE(qApp->focusWidget(), (QWidget *)other2); + QTRY_COMPARE(QApplication::activeWindow(), other2->window()); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(other2)); currentResult = NoResult; ambigResult = NoResult; @@ -1094,20 +1076,18 @@ void tst_QShortcut::context() sendKeyEvents(other2, Qt::ALT+Qt::Key_2); QCOMPARE(currentResult, Slot2Triggered); QCOMPARE(ambigResult, NoResult); - QCOMPARE(edit->toPlainText(), QString("")); - QCOMPARE(other1->toPlainText(), QString("")); - QCOMPARE(other2->toPlainText(), QString("")); - - clearAllShortcuts(); + QCOMPARE(edit->toPlainText(), QString()); + QCOMPARE(other1->toPlainText(), QString()); + QCOMPARE(other2->toPlainText(), QString()); } // QTBUG-38986, do not generate duplicated QEvent::ShortcutOverride in event processing. class OverrideCountingWidget : public QWidget { public: - OverrideCountingWidget(QWidget *parent = 0) : QWidget(parent), overrideCount(0) {} + using QWidget::QWidget; - int overrideCount; + int overrideCount = 0; bool event(QEvent *e) override { @@ -1131,95 +1111,55 @@ void tst_QShortcut::duplicatedShortcutOverride() QCOMPARE(w.overrideCount, 1); } -// ------------------------------------------------------------------ -// Element Testing helper functions --------------------------------- -// ------------------------------------------------------------------ -void tst_QShortcut::clearAllShortcuts() -{ - QList<QShortcut *> shortcutsCpy = shortcuts; - qDeleteAll(shortcutsCpy); - shortcuts.clear(); -} - -QShortcut *tst_QShortcut::setupShortcut(int testWidget, const QKeySequence &ks) -{ - return setupShortcut(mainW, QTest::currentDataTag() ? QTest::currentDataTag() : "", testWidget, ks); -} - -QShortcut *tst_QShortcut::setupShortcut(int testWidget, const QString &txt, int k1, int k2, int k3, int k4) -{ - return setupShortcut(mainW, QTest::currentDataTag() ? QTest::currentDataTag() : "", testWidget, - (txt.isEmpty() ? QKeySequence(k1, k2, k3, k4) : QKeySequence(txt))); -} - -QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int testWidget, const QString &txt, int k1, int k2, int k3, int k4) +QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const QString &name, const QKeySequence &ks, Qt::ShortcutContext context) { - return setupShortcut(parent, name, testWidget, - (txt.isEmpty() ? QKeySequence(k1, k2, k3, k4) : QKeySequence(txt))); + // Set up shortcut for next test + auto cut = new QShortcut(ks, parent, nullptr, nullptr, context); + cut->setObjectName(name); + return cut; } -QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int testWidget, +QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const QString &name, Widget testWidget, const QKeySequence &ks, Qt::ShortcutContext context) { // Set up shortcut for next test - QShortcut *cut = new QShortcut(QKeySequence(), parent, 0, 0, context); - cut->setObjectName(name); - cut->setKey(ks); + auto cut = setupShortcut(parent, name, ks, context); - const char *normal = 0; - const char *ambig = 0; - switch(testWidget) - { + switch (testWidget) { case TriggerSlot1: - normal = SLOT(slotTrig1()); - ambig = SLOT(ambigSlot1()); + connect(cut, &QShortcut::activated, this, &tst_QShortcut::slotTrig1); + connect(cut, &QShortcut::activatedAmbiguously, this, &tst_QShortcut::ambigSlot1); break; case TriggerSlot2: - normal = SLOT(slotTrig2()); - ambig = SLOT(ambigSlot2()); + connect(cut, &QShortcut::activated, this, &tst_QShortcut::slotTrig2); + connect(cut, &QShortcut::activatedAmbiguously, this, &tst_QShortcut::ambigSlot2); break; case TriggerSlot3: - normal = SLOT(slotTrig3()); - ambig = SLOT(ambigSlot3()); + connect(cut, &QShortcut::activated, this, &tst_QShortcut::slotTrig3); + connect(cut, &QShortcut::activatedAmbiguously, this, &tst_QShortcut::ambigSlot3); break; case TriggerSlot4: - normal = SLOT(slotTrig4()); - ambig = SLOT(ambigSlot4()); + connect(cut, &QShortcut::activated, this, &tst_QShortcut::slotTrig4); + connect(cut, &QShortcut::activatedAmbiguously, this, &tst_QShortcut::ambigSlot4); break; case TriggerSlot5: - normal = SLOT(slotTrig5()); - ambig = SLOT(ambigSlot5()); + connect(cut, &QShortcut::activated, this, &tst_QShortcut::slotTrig5); + connect(cut, &QShortcut::activatedAmbiguously, this, &tst_QShortcut::ambigSlot5); break; case TriggerSlot6: - normal = SLOT(slotTrig6()); - ambig = SLOT(ambigSlot6()); + connect(cut, &QShortcut::activated, this, &tst_QShortcut::slotTrig6); + connect(cut, &QShortcut::activatedAmbiguously, this, &tst_QShortcut::ambigSlot6); break; case TriggerSlot7: - normal = SLOT(slotTrig7()); - ambig = SLOT(ambigSlot7()); + connect(cut, &QShortcut::activated, this, &tst_QShortcut::slotTrig7); + connect(cut, &QShortcut::activatedAmbiguously, this, &tst_QShortcut::ambigSlot7); + break; + case NoWidget: break; - case SendKeyEvent: - normal = SLOT(sendKeyEvent()); } - connect(cut, SIGNAL(activated()), this, normal); - if (ambig) - connect(cut, SIGNAL(activatedAmbiguously()), this, ambig); - connect(cut, SIGNAL(destroyed(QObject*)), this, SLOT(shortcutDestroyed(QObject*))); - shortcuts.append(cut); return cut; } -void tst_QShortcut::shortcutDestroyed(QObject* obj) -{ - shortcuts.erase(std::remove(shortcuts.begin(), shortcuts.end(), obj), - shortcuts.end()); -} - -void tst_QShortcut::sendKeyEvents(int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4) -{ - sendKeyEvents(mainW, k1, c1, k2, c2, k3, c3, k4, c4); -} - void tst_QShortcut::sendKeyEvents(QWidget *w, int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4) { Qt::KeyboardModifiers b1 = toButtons( k1 ); @@ -1259,6 +1199,8 @@ void tst_QShortcut::sendKeyEvents(QWidget *w, int k1, QChar c1, int k2, QChar c2 void tst_QShortcut::testElement() { + static QScopedPointer<MainWindow> mainW; + currentResult = NoResult; QFETCH(tst_QShortcut::Action, action); QFETCH(tst_QShortcut::Widget, testWidget); @@ -1273,13 +1215,29 @@ void tst_QShortcut::testElement() QFETCH(int, c4); QFETCH(tst_QShortcut::Result, result); - if (action == ClearAll) { - clearAllShortcuts(); - } else if (action == SetupAccel) { - setupShortcut(testWidget, txt, k1, k2, k3, k4); - } else { - sendKeyEvents(k1, c1, k2, c2, k3, c3, k4, c4); - QCOMPARE((int)currentResult, (int)result); + if (mainW.isNull()) { + mainW.reset(new MainWindow); + mainW->setWindowTitle(QTest::currentTestFunction()); + mainW->show(); + mainW->activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(mainW.data())); + } + + switch (action) { + case ClearAll: + qDeleteAll(mainW->findChildren<QShortcut *>()); + break; + case SetupAccel: + setupShortcut(mainW.data(), txt, testWidget, txt.isEmpty() + ? QKeySequence(k1, k2, k3, k4) : QKeySequence::fromString(txt)); + break; + case TestAccel: + sendKeyEvents(mainW.data(), k1, c1, k2, c2, k3, c3, k4, c4); + QCOMPARE(currentResult, result); + break; + case TestEnd: + mainW.reset(); + break; } } diff --git a/tests/auto/widgets/kernel/qwidget/BLACKLIST b/tests/auto/widgets/kernel/qwidget/BLACKLIST index 03bec4286b..26f9ce1b85 100644 --- a/tests/auto/widgets/kernel/qwidget/BLACKLIST +++ b/tests/auto/widgets/kernel/qwidget/BLACKLIST @@ -2,30 +2,31 @@ [normalGeometry] ubuntu-16.04 [saveRestoreGeometry] -xcb +opensuse-leap +ubuntu-16.04 b2qt +opensuse-42.3 [restoreVersion1Geometry] -osx -[updateWhileMinimized] ubuntu-16.04 +[updateWhileMinimized] ubuntu-18.04 rhel-7.4 +ubuntu-16.04 rhel-7.6 -osx [focusProxyAndInputMethods] -linux +rhel-7.6 +opensuse-leap +ubuntu [raise] -# QTBUG-68175 -opensuse opensuse-leap -[setWindowGeometry] -osx -[windowMoveResize] -osx +# QTBUG-68175 +opensuse-42.3 [childEvents] osx ci [renderInvisible] -osx +osx-10.12 +osx-10.11 +osx-10.14 [optimizedResizeMove] osx [optimizedResize_topLevel] @@ -40,12 +41,11 @@ opensuse opensuse-leap [moveInResizeEvent] ubuntu-16.04 -[moveChild:right] -osx -[activateWindow] -osx-10.12 ci [multipleToplevelFocusCheck] -linux +rhel-7.6 +opensuse-leap +ubuntu [windowState] # QTBUG-75270 winrt + diff --git a/tests/auto/widgets/kernel/qwidget/qwidget.pro b/tests/auto/widgets/kernel/qwidget/qwidget.pro index c1908af2a2..d3fbd6d0d9 100644 --- a/tests/auto/widgets/kernel/qwidget/qwidget.pro +++ b/tests/auto/widgets/kernel/qwidget/qwidget.pro @@ -16,4 +16,4 @@ mac { OBJECTIVE_SOURCES += tst_qwidget_mac_helpers.mm } -win32:!winrt: LIBS += -luser32 -lgdi32 +win32:!winrt: QMAKE_USE += user32 gdi32 diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index a95d6e76b3..40377eb946 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -46,6 +46,7 @@ #include <qstylefactory.h> #include <qdesktopwidget.h> #include <private/qwidget_p.h> +#include <private/qwidgetrepaintmanager_p.h> #include <private/qapplication_p.h> #include <private/qhighdpiscaling_p.h> #include <qcalendarwidget.h> @@ -54,6 +55,7 @@ #include <qrandom.h> #include <qtoolbar.h> #include <qtoolbutton.h> +#include <QtCore/qoperatingsystemversion.h> #include <QtGui/qpaintengine.h> #include <QtGui/qbackingstore.h> #include <QtGui/qguiapplication.h> @@ -1137,6 +1139,7 @@ void tst_QWidget::visible() QVERIFY( !childWidget->isVisible() ); testWidget->show(); + QVERIFY(testWidget->screen()); QVERIFY( testWidget->isVisible() ); QVERIFY( childWidget->isVisible() ); @@ -2527,8 +2530,8 @@ void tst_QWidget::showMinimizedKeepsFocus() { if (m_platform == QStringLiteral("xcb")) QSKIP("QTBUG-26424"); - if (m_platform == QStringLiteral("wayland")) - QSKIP("Wayland: This fails. Figure out why."); + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported."); if (m_platform == QStringLiteral("offscreen")) QSKIP("Platform offscreen does not support showMinimized()"); @@ -2739,8 +2742,8 @@ void tst_QWidget::icon() void tst_QWidget::hideWhenFocusWidgetIsChild() { - if (m_platform == QStringLiteral("wayland")) - QSKIP("Wayland: This fails. Figure out why."); + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported."); QScopedPointer<QWidget> testWidget(new QWidget); testWidget->setWindowTitle(__FUNCTION__); @@ -5380,7 +5383,7 @@ void tst_QWidget::moveChild() parent.setStyle(style.data()); ColorWidget child(&parent, Qt::Widget, Qt::blue); - parent.setGeometry(QRect(QPoint(QApplication::desktop()->availableGeometry(&parent).topLeft()) + QPoint(50, 50), + parent.setGeometry(QRect(parent.screen()->availableGeometry().topLeft() + QPoint(50, 50), QSize(200, 200))); child.setGeometry(25, 25, 50, 50); #ifndef QT_NO_CURSOR // Try to make sure the cursor is not in a taskbar area to prevent tooltips or window highlighting @@ -5427,8 +5430,7 @@ void tst_QWidget::showAndMoveChild() const QScopedPointer<QStyle> style(QStyleFactory::create(QLatin1String("Windows"))); parent.setStyle(style.data()); - QDesktopWidget desktop; - QRect desktopDimensions = desktop.availableGeometry(&parent); + QRect desktopDimensions = parent.screen()->availableGeometry(); desktopDimensions = desktopDimensions.adjusted(64, 64, -64, -64); #ifndef QT_NO_CURSOR // Try to make sure the cursor is not in a taskbar area to prevent tooltips or window highlighting @@ -5541,8 +5543,8 @@ void tst_QWidget::multipleToplevelFocusCheck() QSKIP("QTBUG-52974"); #endif - if (m_platform == QStringLiteral("wayland")) - QSKIP("Wayland: This fails. Figure out why."); + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); else if (m_platform == QStringLiteral("winrt")) QSKIP("Winrt: Sometimes crashes in QTextLayout. - QTBUG-68297"); TopLevelFocusCheck w1; @@ -6256,7 +6258,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; @@ -6264,7 +6270,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; @@ -7095,7 +7105,7 @@ void tst_QWidget::renderWithPainter() // Make sure QWidget::render does not modify the render hints set on the painter. painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform - | QPainter::NonCosmeticDefaultPen | QPainter::TextAntialiasing); + | QPainter::TextAntialiasing); QPainter::RenderHints oldRenderHints = painter.renderHints(); widget.render(&painter); QCOMPARE(painter.renderHints(), oldRenderHints); @@ -7693,13 +7703,11 @@ void tst_QWidget::moveWindowInShowEvent() void tst_QWidget::repaintWhenChildDeleted() { #ifdef Q_OS_WIN - if (QSysInfo::WindowsVersion & QSysInfo::WV_VISTA) { - QTest::qWait(1000); - } + QTest::qWait(1000); #endif ColorWidget w(nullptr, Qt::FramelessWindowHint, Qt::red); w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); - QPoint startPoint = QApplication::desktop()->availableGeometry(&w).topLeft(); + QPoint startPoint = w.screen()->availableGeometry().topLeft(); startPoint.rx() += 50; startPoint.ry() += 50; w.setGeometry(QRect(startPoint, QSize(100, 100))); @@ -7724,7 +7732,7 @@ void tst_QWidget::hideOpaqueChildWhileHidden() { ColorWidget w(nullptr, Qt::FramelessWindowHint, Qt::red); w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); - QPoint startPoint = QApplication::desktop()->availableGeometry(&w).topLeft(); + QPoint startPoint = w.screen()->availableGeometry().topLeft(); startPoint.rx() += 50; startPoint.ry() += 50; w.setGeometry(QRect(startPoint, QSize(100, 100))); @@ -8064,7 +8072,7 @@ public: sp.setHeightForWidth(hfwLayout); QVBoxLayout *vbox = new QVBoxLayout; - vbox->setMargin(0); + vbox->setContentsMargins(0, 0, 0, 0); vbox->addWidget(new ASWidget(sizeHint + QSize(30, 20), sp, false, false)); setLayout(vbox); } @@ -8892,13 +8900,13 @@ void tst_QWidget::translucentWidget() #ifdef Q_OS_WIN QWidget *desktopWidget = QApplication::desktop()->screen(0); - if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) - widgetSnapshot = grabWindow(desktopWidget->windowHandle(), labelPos.x(), labelPos.y(), label.width(), label.height()); - else + widgetSnapshot = grabWindow(desktopWidget->windowHandle(), labelPos.x(), labelPos.y(), label.width(), label.height()); +#else + widgetSnapshot = label.grab(QRect(QPoint(0, 0), label.size())); #endif - widgetSnapshot = label.grab(QRect(QPoint(0, 0), label.size())); const QImage actual = widgetSnapshot.toImage().convertToFormat(QImage::Format_RGB32); - const QImage expected = pm.toImage().scaled(label.devicePixelRatioF() * pm.size()); + QImage expected = pm.toImage().scaled(label.devicePixelRatioF() * pm.size()); + expected.setDevicePixelRatio(label.devicePixelRatioF()); if (m_platform == QStringLiteral("winrt")) QEXPECT_FAIL("", "WinRT: This fails. QTBUG-68297.", Abort); QCOMPARE(actual.size(),expected.size()); @@ -9555,7 +9563,7 @@ void tst_QWidget::destroyBackingStore() QTRY_VERIFY(w.numPaintEvents > 0); w.reset(); w.update(); - qt_widget_private(&w)->topData()->backingStoreTracker.create(&w); + qt_widget_private(&w)->topData()->repaintManager.reset(new QWidgetRepaintManager(&w)); w.update(); QApplication::processEvents(); @@ -9570,14 +9578,14 @@ void tst_QWidget::destroyBackingStore() #endif // QT_BUILD_INTERNAL // Helper function -QWidgetBackingStore* backingStore(QWidget &widget) +QWidgetRepaintManager* repaintManager(QWidget &widget) { - QWidgetBackingStore *backingStore = nullptr; + QWidgetRepaintManager *repaintManager = nullptr; #ifdef QT_BUILD_INTERNAL if (QTLWExtra *topExtra = qt_widget_private(&widget)->maybeTopData()) - backingStore = topExtra->backingStoreTracker.data(); + repaintManager = topExtra->repaintManager.get(); #endif - return backingStore; + return repaintManager; } // Tables of 5000 elements do not make sense on Windows Mobile. @@ -9592,8 +9600,7 @@ void tst_QWidget::rectOutsideCoordinatesLimit_task144779() palette.setColor(QPalette::Window, Qt::red); main.setPalette(palette); - QDesktopWidget desktop; - QRect desktopDimensions = desktop.availableGeometry(&main); + QRect desktopDimensions = main.screen()->availableGeometry(); QSize mainSize(400, 400); mainSize = mainSize.boundedTo(desktopDimensions.size()); main.resize(mainSize); @@ -9674,8 +9681,8 @@ void tst_QWidget::setGraphicsEffect() void tst_QWidget::activateWindow() { - if (m_platform == QStringLiteral("wayland")) - QSKIP("Wayland: This fails. Figure out why."); + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported."); // Test case for QTBUG-26711 @@ -9743,8 +9750,8 @@ void tst_QWidget::openModal_taskQTBUG_5804() void tst_QWidget::focusProxyAndInputMethods() { - if (m_platform == QStringLiteral("wayland")) - QSKIP("Wayland: This fails. Figure out why."); + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported."); QScopedPointer<QWidget> toplevel(new QWidget(nullptr, Qt::X11BypassWindowManagerHint)); toplevel->setWindowTitle(QLatin1String(QTest::currentTestFunction())); toplevel->resize(200, 200); @@ -9775,12 +9782,12 @@ class scrollWidgetWBS : public QWidget public: void deleteBackingStore() { - static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStoreTracker.destroy(); + static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->repaintManager.reset(nullptr); } void enableBackingStore() { - if (!static_cast<QWidgetPrivate*>(d_ptr.data())->maybeBackingStore()) { - static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStoreTracker.create(this); + if (!static_cast<QWidgetPrivate*>(d_ptr.data())->maybeRepaintManager()) { + static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->repaintManager.reset(new QWidgetRepaintManager(this)); static_cast<QWidgetPrivate*>(d_ptr.data())->invalidateBackingStore(this->rect()); repaint(); } @@ -10111,7 +10118,7 @@ void tst_QWidget::grabMouse() w.setObjectName(QLatin1String("tst_qwidget_grabMouse")); w.setWindowTitle(w.objectName()); QLayout *layout = new QVBoxLayout(&w); - layout->setMargin(50); + layout->setContentsMargins(50, 50, 50, 50); GrabLoggerWidget *grabber = new GrabLoggerWidget(&log, &w); const QString grabberObjectName = QLatin1String("tst_qwidget_grabMouse_grabber"); grabber->setObjectName(grabberObjectName); diff --git a/tests/auto/widgets/kernel/qwidget_window/BLACKLIST b/tests/auto/widgets/kernel/qwidget_window/BLACKLIST index 934f2e8025..39d7b695f6 100644 --- a/tests/auto/widgets/kernel/qwidget_window/BLACKLIST +++ b/tests/auto/widgets/kernel/qwidget_window/BLACKLIST @@ -2,7 +2,7 @@ # QTBUG-66345 opensuse-42.3 ubuntu-16.04 -ubuntu-18.04 [setWindowState] ubuntu-18.04 -rhel +rhel-7.6 + diff --git a/tests/auto/widgets/styles/qstyle/images/mac/button.png b/tests/auto/widgets/styles/qstyle/images/mac/button.png Binary files differdeleted file mode 100644 index 7b11325e87..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/mac/button.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/images/mac/combobox.png b/tests/auto/widgets/styles/qstyle/images/mac/combobox.png Binary files differdeleted file mode 100644 index ded0b11f29..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/mac/combobox.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/images/mac/lineedit.png b/tests/auto/widgets/styles/qstyle/images/mac/lineedit.png Binary files differdeleted file mode 100644 index 8d2861b65b..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/mac/lineedit.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/images/mac/mdi.png b/tests/auto/widgets/styles/qstyle/images/mac/mdi.png Binary files differdeleted file mode 100644 index 8c09ae4338..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/mac/mdi.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/images/mac/menu.png b/tests/auto/widgets/styles/qstyle/images/mac/menu.png Binary files differdeleted file mode 100644 index 5dd9111d69..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/mac/menu.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/images/mac/radiobutton.png b/tests/auto/widgets/styles/qstyle/images/mac/radiobutton.png Binary files differdeleted file mode 100644 index 8828e220a2..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/mac/radiobutton.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/images/mac/slider.png b/tests/auto/widgets/styles/qstyle/images/mac/slider.png Binary files differdeleted file mode 100644 index fc65035631..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/mac/slider.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/images/mac/spinbox.png b/tests/auto/widgets/styles/qstyle/images/mac/spinbox.png Binary files differdeleted file mode 100644 index ee88441ecb..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/mac/spinbox.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/images/vista/button.png b/tests/auto/widgets/styles/qstyle/images/vista/button.png Binary files differdeleted file mode 100644 index a6c45276ca..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/vista/button.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/images/vista/combobox.png b/tests/auto/widgets/styles/qstyle/images/vista/combobox.png Binary files differdeleted file mode 100644 index 9b82f64d32..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/vista/combobox.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/images/vista/lineedit.png b/tests/auto/widgets/styles/qstyle/images/vista/lineedit.png Binary files differdeleted file mode 100644 index b2c6ac1ae4..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/vista/lineedit.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/images/vista/menu.png b/tests/auto/widgets/styles/qstyle/images/vista/menu.png Binary files differdeleted file mode 100644 index b114099cc3..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/vista/menu.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/images/vista/radiobutton.png b/tests/auto/widgets/styles/qstyle/images/vista/radiobutton.png Binary files differdeleted file mode 100644 index c8aa7864df..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/vista/radiobutton.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/images/vista/slider.png b/tests/auto/widgets/styles/qstyle/images/vista/slider.png Binary files differdeleted file mode 100644 index 7c156ded9d..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/vista/slider.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/images/vista/spinbox.png b/tests/auto/widgets/styles/qstyle/images/vista/spinbox.png Binary files differdeleted file mode 100644 index b8d0823ab2..0000000000 --- a/tests/auto/widgets/styles/qstyle/images/vista/spinbox.png +++ /dev/null diff --git a/tests/auto/widgets/styles/qstyle/qstyle.pro b/tests/auto/widgets/styles/qstyle/qstyle.pro index 9ad0940245..4dc0525c49 100644 --- a/tests/auto/widgets/styles/qstyle/qstyle.pro +++ b/tests/auto/widgets/styles/qstyle/qstyle.pro @@ -2,8 +2,3 @@ CONFIG += testcase TARGET = tst_qstyle QT += widgets testlib testlib-private SOURCES += tst_qstyle.cpp - -android:!android-embedded { - RESOURCES += \ - testdata.qrc -} diff --git a/tests/auto/widgets/styles/qstyle/testdata.qrc b/tests/auto/widgets/styles/qstyle/testdata.qrc deleted file mode 100644 index 29bb46726e..0000000000 --- a/tests/auto/widgets/styles/qstyle/testdata.qrc +++ /dev/null @@ -1,19 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>images/mac/button.png</file> - <file>images/mac/combobox.png</file> - <file>images/mac/lineedit.png</file> - <file>images/mac/mdi.png</file> - <file>images/mac/menu.png</file> - <file>images/mac/radiobutton.png</file> - <file>images/mac/slider.png</file> - <file>images/mac/spinbox.png</file> - <file>images/vista/button.png</file> - <file>images/vista/combobox.png</file> - <file>images/vista/lineedit.png</file> - <file>images/vista/menu.png</file> - <file>images/vista/radiobutton.png</file> - <file>images/vista/slider.png</file> - <file>images/vista/spinbox.png</file> - </qresource> -</RCC> diff --git a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp index a552c91928..ae084310b1 100644 --- a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp +++ b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp @@ -73,7 +73,6 @@ public: private: bool testAllFunctions(QStyle *); bool testScrollBarSubControls(); - void testPainting(QStyle *style, const QString &platform); private slots: void drawItemPixmap(); void init(); @@ -333,138 +332,15 @@ void tst_QStyle::testWindowsStyle() delete wstyle; } -void writeImage(const QString &fileName, QImage image) -{ - QImageWriter imageWriter(fileName); - imageWriter.setFormat("png"); - qDebug() << "result " << imageWriter.write(image); -} - -QImage readImage(const QString &fileName) -{ - QImageReader reader(fileName); - return reader.read(); -} - - #if defined(Q_OS_WIN) && !defined(QT_NO_STYLE_WINDOWSVISTA) && !defined(Q_OS_WINRT) void tst_QStyle::testWindowsVistaStyle() { QStyle *vistastyle = QStyleFactory::create("WindowsVista"); QVERIFY(testAllFunctions(vistastyle)); - - if (QSysInfo::WindowsVersion == QSysInfo::WV_VISTA) - testPainting(vistastyle, "vista"); delete vistastyle; } #endif -void comparePixmap(const QString &filename, const QPixmap &pixmap) -{ - QImage oldFile = readImage(filename); - QPixmap oldPixmap = QPixmap::fromImage(oldFile); - if (!oldFile.isNull()) - QCOMPARE(pixmap, oldPixmap); - else - writeImage(filename, pixmap.toImage()); -} - -void tst_QStyle::testPainting(QStyle *style, const QString &platform) -{ -qDebug("TEST PAINTING"); - //Test Menu - QString fileName = "images/" + platform + "/menu.png"; - QMenu menu; - menu.setStyle(style); - menu.show(); - menu.addAction(new QAction("Test 1", &menu)); - menu.addAction(new QAction("Test 2", &menu)); - QPixmap pixmap = menu.grab(); - comparePixmap(fileName, pixmap); - - //Push button - fileName = "images/" + platform + "/button.png"; - QPushButton button("OK"); - button.setStyle(style); - button.show(); - pixmap = button.grab(); - button.hide(); - comparePixmap(fileName, pixmap); - - //Push button - fileName = "images/" + platform + "/radiobutton.png"; - QRadioButton radiobutton("Check"); - radiobutton.setStyle(style); - radiobutton.show(); - pixmap = radiobutton.grab(); - radiobutton.hide(); - comparePixmap(fileName, pixmap); - - //Combo box - fileName = "images/" + platform + "/combobox.png"; - QComboBox combobox; - combobox.setStyle(style); - combobox.addItem("Test 1"); - combobox.addItem("Test 2"); - combobox.show(); - pixmap = combobox.grab(); - combobox.hide(); - comparePixmap(fileName, pixmap); - - //Spin box - fileName = "images/" + platform + "/spinbox.png"; - QDoubleSpinBox spinbox; - spinbox.setLocale(QLocale(QLocale::English, QLocale::UnitedStates)); - spinbox.setStyle(style); - spinbox.show(); - pixmap = spinbox.grab(); - spinbox.hide(); - comparePixmap(fileName, pixmap); - QLocale::setDefault(QLocale::system()); - - //Slider - fileName = "images/" + platform + "/slider.png"; - QSlider slider; - slider.setStyle(style); - slider.show(); - pixmap = slider.grab(); - slider.hide(); - comparePixmap(fileName, pixmap); - - //Line edit - fileName = "images/" + platform + "/lineedit.png"; - QLineEdit lineedit("Test text"); - lineedit.setStyle(style); - lineedit.show(); - pixmap = lineedit.grab(); - lineedit.hide(); - comparePixmap(fileName, pixmap); - - //MDI - fileName = "images/" + platform + "/mdi.png"; - QMdiArea mdiArea; - mdiArea.addSubWindow(new QWidget(&mdiArea)); - mdiArea.resize(200, 200); - mdiArea.setStyle(style); - mdiArea.show(); - pixmap = mdiArea.grab(); - mdiArea.hide(); - comparePixmap(fileName, pixmap); - - // QToolButton - fileName = "images/" + platform + "/toolbutton.png"; - QToolButton tb; - tb.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - tb.setText("AaQqPpXx"); - tb.setIcon(style->standardPixmap(QStyle::SP_DirHomeIcon)); - tb.setStyle(style); - tb.show(); - pixmap = tb.grab(); - tb.hide(); - comparePixmap(fileName, pixmap); - -} - #ifdef Q_OS_MAC void tst_QStyle::testMacStyle() { diff --git a/tests/auto/widgets/util/qcompleter/BLACKLIST b/tests/auto/widgets/util/qcompleter/BLACKLIST index fdc424b6ac..367270fdf2 100644 --- a/tests/auto/widgets/util/qcompleter/BLACKLIST +++ b/tests/auto/widgets/util/qcompleter/BLACKLIST @@ -1,2 +1,6 @@ [QTBUG_14292_filesystem] -linux +ubuntu-16.04 +opensuse-leap +rhel-7.4 +rhel-6.6 +opensuse-42.3 diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp index 5a51f15008..27ae41fc4f 100644 --- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp @@ -1765,7 +1765,7 @@ void tst_QCompleter::QTBUG_52028_tabAutoCompletes() auto le = new QLineEdit; w.layout()->addWidget(le); - const auto pos = QApplication::desktop()->availableGeometry(&w).topLeft() + QPoint(200,200); + const auto pos = w.screen()->availableGeometry().topLeft() + QPoint(200,200); w.move(pos); w.show(); QApplication::setActiveWindow(&w); @@ -1806,7 +1806,7 @@ void tst_QCompleter::QTBUG_51889_activatedSentTwice() w.layout()->addWidget(new QLineEdit); - const auto pos = QApplication::desktop()->availableGeometry(&w).topLeft() + QPoint(200,200); + const auto pos = w.screen()->availableGeometry().topLeft() + QPoint(200,200); w.move(pos); w.show(); QApplication::setActiveWindow(&w); diff --git a/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp b/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp index 007825d39c..a17a9f6c33 100644 --- a/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp +++ b/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp @@ -124,13 +124,19 @@ void tst_QAbstractScrollArea::scrollBarWidgets() QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList()); QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom), w2List); + auto sort = [](const QWidgetList l) { + QWidgetList list = l; + std::sort(list.begin(), list.end()); + return list; + }; + // two widgets at Bottom. area.addScrollBarWidget(w3, Qt::AlignBottom); - QCOMPARE(area.scrollBarWidgets(all).toSet(), allList.toSet()); + QCOMPARE(sort(area.scrollBarWidgets(all)), sort(allList)); QCOMPARE(area.scrollBarWidgets(Qt::AlignLeft), w1List); QCOMPARE(area.scrollBarWidgets(Qt::AlignRight), QWidgetList()); QCOMPARE(area.scrollBarWidgets(Qt::AlignTop), QWidgetList()); - QCOMPARE(area.scrollBarWidgets(Qt::AlignBottom).toSet(), (w2List + w3List).toSet()); + QCOMPARE(sort(area.scrollBarWidgets(Qt::AlignBottom)), sort(w2List + w3List)); //delete delete w1; diff --git a/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp b/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp index 1a0d7a9289..f77efe036a 100644 --- a/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp +++ b/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp @@ -33,7 +33,7 @@ #include <QSlider> #include <QStyle> #include <QStyleOption> -#include <QTime> +#include <QElapsedTimer> #include <QDebug> #include <QtTest/private/qtesthelpers_p.h> @@ -91,7 +91,7 @@ private slots: void connectedSliders(); private: - void waitUntilTimeElapsed(const QTime& t, int ms); + void waitUntilTimeElapsed(const QElapsedTimer &t, int ms); QWidget *topLevel; Slider *slider; @@ -1662,8 +1662,12 @@ void tst_QAbstractSlider::wheelEvent() slider->setOrientation(sliderOrientation); Qt::KeyboardModifier k = withModifiers ? Qt::ControlModifier : Qt::NoModifier; - QWheelEvent event(slider->rect().bottomRight() + distanceFromBottomRight, WHEEL_DELTA * deltaMultiple, - Qt::NoButton, k, wheelOrientation); + + const QPoint wheelPoint = slider->rect().bottomRight() + distanceFromBottomRight; + const QPoint angleDelta(wheelOrientation == Qt::Horizontal ? WHEEL_DELTA * deltaMultiple : 0, + wheelOrientation == Qt::Vertical ? WHEEL_DELTA * deltaMultiple : 0); + QWheelEvent event(wheelPoint, slider->mapToGlobal(wheelPoint), QPoint(), angleDelta, + Qt::NoButton, k, Qt::NoScrollPhase, false); QVERIFY(applicationInstance->sendEvent(slider,&event)); #ifdef Q_OS_MAC QEXPECT_FAIL("Normal data page", "QTBUG-23679", Continue); @@ -1674,8 +1678,8 @@ void tst_QAbstractSlider::wheelEvent() slider->setSliderPosition(initialSliderPosition); k = withModifiers ? Qt::ShiftModifier : Qt::NoModifier; - event = QWheelEvent(slider->rect().bottomRight() + distanceFromBottomRight, WHEEL_DELTA * deltaMultiple, - Qt::NoButton, k, wheelOrientation); + event = QWheelEvent(wheelPoint, slider->mapToGlobal(wheelPoint), QPoint(), angleDelta, + Qt::NoButton, k, Qt::NoScrollPhase, false); QSignalSpy spy1(slider, SIGNAL(actionTriggered(int))); QSignalSpy spy2(slider, SIGNAL(valueChanged(int))); QVERIFY(applicationInstance->sendEvent(slider,&event)); @@ -1715,16 +1719,16 @@ void tst_QAbstractSlider::fineGrainedWheelEvent() slider->setSliderPosition(0); const int singleStepDelta = invertedControls ? (-WHEEL_DELTA / 3) : (WHEEL_DELTA / 3); - - QWheelEvent eventDown(slider->rect().bottomRight(), singleStepDelta / 2, - Qt::NoButton, Qt::NoModifier, Qt::Vertical); + const QPoint wheelPoint = slider->rect().bottomRight(); + QWheelEvent eventDown(wheelPoint, slider->mapToGlobal(wheelPoint), QPoint(), QPoint(0, singleStepDelta / 2), + Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); QVERIFY(applicationInstance->sendEvent(slider,&eventDown)); QCOMPARE(slider->sliderPosition(), 0); QVERIFY(applicationInstance->sendEvent(slider,&eventDown)); QCOMPARE(slider->sliderPosition(), 1); - QWheelEvent eventUp(slider->rect().bottomRight(), -singleStepDelta / 2, - Qt::NoButton, Qt::NoModifier, Qt::Vertical); + QWheelEvent eventUp(wheelPoint, slider->mapToGlobal(wheelPoint), QPoint(), QPoint(0, -singleStepDelta / 2), + Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); QVERIFY(applicationInstance->sendEvent(slider,&eventUp)); QCOMPARE(slider->sliderPosition(), 1); QVERIFY(applicationInstance->sendEvent(slider,&eventUp)); @@ -2053,11 +2057,11 @@ void tst_QAbstractSlider::setValue() QVERIFY(sliderMovedTimeStamp < valueChangedTimeStamp); } -void tst_QAbstractSlider::waitUntilTimeElapsed(const QTime& t, int ms) +void tst_QAbstractSlider::waitUntilTimeElapsed(const QElapsedTimer &t, int ms) { const int eps = 80; while (t.elapsed() < ms + eps) - QTest::qWait(qMax(ms - t.elapsed() + eps, 25)); + QTest::qWait(qMax(int(ms - t.elapsed() + eps), 25)); } void tst_QAbstractSlider::setRepeatAction() @@ -2073,7 +2077,7 @@ void tst_QAbstractSlider::setRepeatAction() QCOMPARE(spy.count(), 0); QCOMPARE(slider->value(), 55); - QTime t; + QElapsedTimer t; t.start(); QTest::qWait(300); QCOMPARE(spy.count(), 0); diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index a576770811..b7869a0653 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -34,7 +34,6 @@ #include <qpa/qplatformtheme.h> #include <qfontcombobox.h> -#include <qdesktopwidget.h> #include <qapplication.h> #include <qpushbutton.h> #include <qdialog.h> @@ -254,12 +253,22 @@ void tst_QComboBox::getSetCheck() obj1.setMaxCount(INT_MAX); QCOMPARE(INT_MAX, obj1.maxCount()); + // QCompleter *QComboBox::completer() + // void QComboBox::setCompleter(QCompleter *) + obj1.setCompleter(nullptr); + QCOMPARE(nullptr, obj1.completer()); + QCompleter completer; + obj1.setCompleter(&completer); + QVERIFY(obj1.completer() == nullptr); // no QLineEdit is set + +#if QT_DEPRECATED_SINCE(5, 13) // bool QComboBox::autoCompletion() // void QComboBox::setAutoCompletion(bool) obj1.setAutoCompletion(false); QCOMPARE(false, obj1.autoCompletion()); obj1.setAutoCompletion(true); QCOMPARE(true, obj1.autoCompletion()); +#endif // bool QComboBox::duplicatesEnabled() // void QComboBox::setDuplicatesEnabled(bool) @@ -317,6 +326,9 @@ void tst_QComboBox::getSetCheck() QCOMPARE(var8, obj1.lineEdit()); // delete var8; // No delete, since QComboBox takes ownership + // After setting a line edit, completer() should not return nullptr anymore + QVERIFY(obj1.completer() != nullptr); + // const QValidator * QComboBox::validator() // void QComboBox::setValidator(const QValidator *) QIntValidator *var9 = new QIntValidator(0); @@ -777,7 +789,9 @@ void tst_QComboBox::virtualAutocompletion() QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); QComboBox *testWidget = topLevel.comboBox(); testWidget->clear(); +#if QT_DEPRECATED_SINCE(5, 13) testWidget->setAutoCompletion(true); +#endif testWidget->addItem("Foo"); testWidget->addItem("Bar"); testWidget->addItem("Boat"); @@ -837,7 +851,9 @@ void tst_QComboBox::autoCompletionCaseSensitivity() QCOMPARE(qApp->focusWidget(), (QWidget *)testWidget); testWidget->clear(); +#if QT_DEPRECATED_SINCE(5, 13) testWidget->setAutoCompletion(true); +#endif testWidget->addItem("Cow"); testWidget->addItem("irrelevant1"); testWidget->addItem("aww"); @@ -2102,7 +2118,9 @@ void tst_QComboBox::mouseWheel() box.setEditable(i==0?false:true); box.setCurrentIndex(startIndex); - QWheelEvent event = QWheelEvent(box.rect().bottomRight() , WHEEL_DELTA * wheelDirection, Qt::NoButton, Qt::NoModifier); + const QPoint wheelPoint = box.rect().bottomRight(); + QWheelEvent event(wheelPoint, box.mapToGlobal(wheelPoint), QPoint(), QPoint(0, WHEEL_DELTA * wheelDirection), + Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); QVERIFY(applicationInstance->sendEvent(&box,&event)); QCOMPARE(box.currentIndex(), expectedIndex); @@ -2131,7 +2149,9 @@ void tst_QComboBox::popupWheelHandling() comboBox->showPopup(); QTRY_VERIFY(comboBox->view() && comboBox->view()->isVisible()); const QPoint popupPos = comboBox->view()->pos(); - QWheelEvent event(QPointF(10, 10), WHEEL_DELTA, Qt::NoButton, Qt::NoModifier); + const QPoint wheelPoint(10, 10); + QWheelEvent event(wheelPoint, scrollArea.mapToGlobal(wheelPoint), QPoint(), QPoint(0, WHEEL_DELTA), + Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); QVERIFY(QCoreApplication::sendEvent(scrollArea.windowHandle(), &event)); QCoreApplication::processEvents(); QVERIFY(comboBox->view()->isVisible()); @@ -2191,15 +2211,13 @@ void tst_QComboBox::itemListPosition() QFontComboBox combo(&topLevel); layout->addWidget(&combo); - //the code to get the available screen space is copied from QComboBox code - const int scrNumber = QApplication::desktop()->screenNumber(&combo); bool useFullScreenForPopupMenu = false; if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) useFullScreenForPopupMenu = theme->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool(); const QRect screen = useFullScreenForPopupMenu ? - QApplication::screens().at(scrNumber)->geometry() : - QApplication::screens().at(scrNumber)->availableGeometry(); + combo.screen()->geometry() : + combo.screen()->availableGeometry(); topLevel.move(screen.width() - topLevel.sizeHint().width() - 10, 0); //puts the combo to the top-right corner @@ -2419,8 +2437,7 @@ void tst_QComboBox::task248169_popupWithMinimalSize() #if defined QT_BUILD_INTERNAL QFrame *container = comboBox.findChild<QComboBoxPrivateContainer *>(); QVERIFY(container); - QDesktopWidget desktop; - QTRY_VERIFY(desktop.screenGeometry(container).contains(container->geometry())); + QTRY_VERIFY(container->screen()->geometry().contains(container->geometry())); #endif } @@ -3050,7 +3067,9 @@ void tst_QComboBox::task_QTBUG_31146_popupCompletion() { QComboBox comboBox; comboBox.setEditable(true); +#if QT_DEPRECATED_SINCE(5, 13) comboBox.setAutoCompletion(true); +#endif comboBox.setInsertPolicy(QComboBox::NoInsert); comboBox.completer()->setCaseSensitivity(Qt::CaseInsensitive); comboBox.completer()->setCompletionMode(QCompleter::PopupCompletion); diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp index b5ef454b14..26b4b7d020 100644 --- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp +++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp @@ -307,19 +307,19 @@ static QLatin1String modifierToName(Qt::KeyboardModifier modifier) { switch (modifier) { case Qt::NoModifier: - return QLatin1Literal("No"); + return QLatin1String("No"); break; case Qt::ControlModifier: - return QLatin1Literal("Ctrl"); + return QLatin1String("Ctrl"); break; case Qt::ShiftModifier: - return QLatin1Literal("Shift"); + return QLatin1String("Shift"); break; case Qt::AltModifier: - return QLatin1Literal("Alt"); + return QLatin1String("Alt"); break; case Qt::MetaModifier: - return QLatin1Literal("Meta"); + return QLatin1String("Meta"); break; default: qFatal("Unexpected keyboard modifier"); @@ -331,25 +331,24 @@ static QLatin1String sectionToName(const QDateTimeEdit::Section section) { switch (section) { case QDateTimeEdit::SecondSection: - return QLatin1Literal("Second"); + return QLatin1String("Second"); case QDateTimeEdit::MinuteSection: - return QLatin1Literal("Minute"); + return QLatin1String("Minute"); case QDateTimeEdit::HourSection: - return QLatin1Literal("Hours"); + return QLatin1String("Hours"); case QDateTimeEdit::DaySection: - return QLatin1Literal("Day"); + return QLatin1String("Day"); case QDateTimeEdit::MonthSection: - return QLatin1Literal("Month"); + return QLatin1String("Month"); case QDateTimeEdit::YearSection: - return QLatin1Literal("Year"); + return QLatin1String("Year"); default: qFatal("Unexpected section"); return QLatin1String(); } } -static QDate stepDate(const QDate& startDate, const QDateTimeEdit::Section section, - const int steps) +static QDate stepDate(QDate startDate, const QDateTimeEdit::Section section, const int steps) { switch (section) { case QDateTimeEdit::DaySection: @@ -364,8 +363,7 @@ static QDate stepDate(const QDate& startDate, const QDateTimeEdit::Section secti } } -static QTime stepTime(const QTime& startTime, const QDateTimeEdit::Section section, - const int steps) +static QTime stepTime(QTime startTime, const QDateTimeEdit::Section section, const int steps) { switch (section) { case QDateTimeEdit::SecondSection: @@ -3141,7 +3139,6 @@ void tst_QDateTimeEdit::wheelEvent_data() { #if QT_CONFIG(wheelevent) QTest::addColumn<QPoint>("angleDelta"); - QTest::addColumn<int>("qt4Delta"); QTest::addColumn<int>("stepModifier"); QTest::addColumn<Qt::KeyboardModifiers>("modifiers"); QTest::addColumn<Qt::MouseEventSource>("source"); @@ -3217,16 +3214,16 @@ void tst_QDateTimeEdit::wheelEvent_data() QLatin1String sourceName; switch (source) { case Qt::MouseEventNotSynthesized: - sourceName = QLatin1Literal("NotSynthesized"); + sourceName = QLatin1String("NotSynthesized"); break; case Qt::MouseEventSynthesizedBySystem: - sourceName = QLatin1Literal("SynthesizedBySystem"); + sourceName = QLatin1String("SynthesizedBySystem"); break; case Qt::MouseEventSynthesizedByQt: - sourceName = QLatin1Literal("SynthesizedByQt"); + sourceName = QLatin1String("SynthesizedByQt"); break; case Qt::MouseEventSynthesizedByApplication: - sourceName = QLatin1Literal("SynthesizedByApplication"); + sourceName = QLatin1String("SynthesizedByApplication"); break; default: qFatal("Unexpected wheel event source"); @@ -3255,7 +3252,6 @@ void tst_QDateTimeEdit::wheelEvent_data() modifierName.latin1(), sourceName.latin1()) << angleDelta - << units << static_cast<int>(stepModifier) << modifiers << source @@ -3277,7 +3273,6 @@ void tst_QDateTimeEdit::wheelEvent() { #if QT_CONFIG(wheelevent) QFETCH(QPoint, angleDelta); - QFETCH(int, qt4Delta); QFETCH(int, stepModifier); QFETCH(Qt::KeyboardModifiers, modifiers); QFETCH(Qt::MouseEventSource, source); @@ -3294,9 +3289,8 @@ void tst_QDateTimeEdit::wheelEvent() style->stepModifier = static_cast<Qt::KeyboardModifier>(stepModifier); edit.setStyle(style.data()); - QWheelEvent event(QPointF(), QPointF(), QPoint(), angleDelta, qt4Delta, - Qt::Vertical, Qt::NoButton, modifiers, Qt::NoScrollPhase, - source); + QWheelEvent event(QPointF(), QPointF(), QPoint(), angleDelta, + Qt::NoButton, modifiers, Qt::NoScrollPhase, false, source); QCOMPARE(edit.date(), startDate); for (QDate expected : expectedDates) { @@ -3454,7 +3448,7 @@ void tst_QDateTimeEdit::timeSpec() } QVERIFY(edit.minimumTime() != min.time()); QVERIFY(edit.minimumDateTime().timeSpec() != min.timeSpec()); - QCOMPARE(edit.minimumDateTime().toTime_t(), min.toTime_t()); + QCOMPARE(edit.minimumDateTime().toSecsSinceEpoch(), min.toSecsSinceEpoch()); } else { QSKIP("Not tested in the GMT timezone"); } diff --git a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp index f8ce6a2c0a..625116654d 100644 --- a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp @@ -670,7 +670,11 @@ void tst_QDockWidget::dockLocationChanged() spy.clear(); dw.setFloating(true); - QTest::qWait(100); + QTRY_COMPARE(spy.count(), 1); + QCOMPARE(qvariant_cast<Qt::DockWidgetArea>(spy.at(0).at(0)), + Qt::NoDockWidgetArea); + spy.clear(); + dw.setFloating(false); QTRY_COMPARE(spy.count(), 1); QCOMPARE(qvariant_cast<Qt::DockWidgetArea>(spy.at(0).at(0)), diff --git a/tests/auto/widgets/widgets/qdoublespinbox/BLACKLIST b/tests/auto/widgets/widgets/qdoublespinbox/BLACKLIST index c1b6c9693e..8f5648d0f9 100644 --- a/tests/auto/widgets/widgets/qdoublespinbox/BLACKLIST +++ b/tests/auto/widgets/widgets/qdoublespinbox/BLACKLIST @@ -1,2 +1,4 @@ [editingFinished] -* +osx-10.12 +osx-10.14 +osx-10.13 diff --git a/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp b/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp index 954ee6471d..c760d9cc99 100644 --- a/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp +++ b/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp @@ -221,19 +221,19 @@ static QLatin1String modifierToName(Qt::KeyboardModifier modifier) { switch (modifier) { case Qt::NoModifier: - return QLatin1Literal("No"); + return QLatin1String("No"); break; case Qt::ControlModifier: - return QLatin1Literal("Ctrl"); + return QLatin1String("Ctrl"); break; case Qt::ShiftModifier: - return QLatin1Literal("Shift"); + return QLatin1String("Shift"); break; case Qt::AltModifier: - return QLatin1Literal("Alt"); + return QLatin1String("Alt"); break; case Qt::MetaModifier: - return QLatin1Literal("Meta"); + return QLatin1String("Meta"); break; default: qFatal("Unexpected keyboard modifier"); @@ -1377,7 +1377,6 @@ void tst_QDoubleSpinBox::wheelEvents_data() { #if QT_CONFIG(wheelevent) QTest::addColumn<QPoint>("angleDelta"); - QTest::addColumn<int>("qt4Delta"); QTest::addColumn<int>("stepModifier"); QTest::addColumn<Qt::KeyboardModifiers>("modifier"); QTest::addColumn<Qt::MouseEventSource>("source"); @@ -1448,16 +1447,16 @@ void tst_QDoubleSpinBox::wheelEvents_data() QLatin1String sourceName; switch (source) { case Qt::MouseEventNotSynthesized: - sourceName = QLatin1Literal("NotSynthesized"); + sourceName = QLatin1String("NotSynthesized"); break; case Qt::MouseEventSynthesizedBySystem: - sourceName = QLatin1Literal("SynthesizedBySystem"); + sourceName = QLatin1String("SynthesizedBySystem"); break; case Qt::MouseEventSynthesizedByQt: - sourceName = QLatin1Literal("SynthesizedByQt"); + sourceName = QLatin1String("SynthesizedByQt"); break; case Qt::MouseEventSynthesizedByApplication: - sourceName = QLatin1Literal("SynthesizedByApplication"); + sourceName = QLatin1String("SynthesizedByApplication"); break; default: qFatal("Unexpected wheel event source"); @@ -1476,7 +1475,6 @@ void tst_QDoubleSpinBox::wheelEvents_data() modifierName.latin1(), sourceName.latin1()) << angleDelta - << units << static_cast<int>(stepModifier) << modifiers << source @@ -1496,7 +1494,6 @@ void tst_QDoubleSpinBox::wheelEvents() { #if QT_CONFIG(wheelevent) QFETCH(QPoint, angleDelta); - QFETCH(int, qt4Delta); QFETCH(int, stepModifier); QFETCH(Qt::KeyboardModifiers, modifier); QFETCH(Qt::MouseEventSource, source); @@ -1512,9 +1509,8 @@ void tst_QDoubleSpinBox::wheelEvents() style->stepModifier = static_cast<Qt::KeyboardModifier>(stepModifier); spinBox.setStyle(style.data()); - QWheelEvent event(QPointF(), QPointF(), QPoint(), angleDelta, qt4Delta, - Qt::Vertical, Qt::NoButton, modifier, Qt::NoScrollPhase, - source); + QWheelEvent event(QPointF(), QPointF(), QPoint(), angleDelta, + Qt::NoButton, modifier, Qt::NoScrollPhase, false, source); for (int expected : expectedValues) { qApp->sendEvent(&spinBox, &event); QCOMPARE(spinBox.value(), expected); diff --git a/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp b/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp index 1813e5ad5f..5392d36ae0 100644 --- a/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp +++ b/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp @@ -108,7 +108,7 @@ void tst_QFontComboBox::currentFont() QFont oldCurrentFont = box.currentFont(); box.setCurrentFont(currentFont); - QRegExp foundry(" \\[.*\\]"); + QRegularExpression foundry(" \\[.*\\]"); if (!box.currentFont().family().contains(foundry)) { QCOMPARE(box.currentFont(), currentFont); } diff --git a/tests/auto/widgets/widgets/qframe/tst_qframe.cpp b/tests/auto/widgets/widgets/qframe/tst_qframe.cpp index 432f4474c5..05f9cd2e4a 100644 --- a/tests/auto/widgets/widgets/qframe/tst_qframe.cpp +++ b/tests/auto/widgets/widgets/qframe/tst_qframe.cpp @@ -37,6 +37,10 @@ class tst_QFrame : public QObject { Q_OBJECT + +public: + static void initMain() { QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); } + private slots: void testDefaults(); void testInitStyleOption_data(); diff --git a/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp b/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp index 420ef56106..1b477fbbd0 100644 --- a/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp +++ b/tests/auto/widgets/widgets/qgroupbox/tst_qgroupbox.cpp @@ -295,6 +295,12 @@ void tst_QGroupBox::enabledChildPropagation() QVERIFY(!childWidget->isEnabled()); dialog = new QDialog(&testWidget); QVERIFY(dialog->isEnabled()); + + // children that are enabled after adding should still be disabled before + // they are shown + childWidget->setEnabled(true); + testWidget.show(); + QVERIFY(!childWidget->isEnabled()); } void tst_QGroupBox::sizeHint() diff --git a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp index 34862f6810..f599ac73c6 100644 --- a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp +++ b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp @@ -461,7 +461,7 @@ void tst_QLabel::unicodeText() QVBoxLayout *layout = new QVBoxLayout(); QLabel *label = new QLabel(text, &frame); layout->addWidget(label); - layout->setMargin(8); + layout->setContentsMargins(8, 8, 8, 8); frame.setLayout(layout); frame.show(); QVERIFY(QTest::qWaitForWindowExposed(&frame)); diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 27cc385df4..0cfbc651ad 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -3530,6 +3530,13 @@ void tst_QLineEdit::textMargin() centerOnScreen(&tlw); tlw.show(); + const QMargins margins = testWidget.textMargins(); + QCOMPARE(left, margins.left()); + QCOMPARE(top, margins.top()); + QCOMPARE(right, margins.right()); + QCOMPARE(bottom, margins.bottom()); + +#if QT_DEPRECATED_SINCE(5, 14) int l; int t; int r; @@ -3539,6 +3546,7 @@ void tst_QLineEdit::textMargin() QCOMPARE(top, t); QCOMPARE(right, r); QCOMPARE(bottom, b); +#endif QTest::mouseClick(&testWidget, Qt::LeftButton, 0, mousePressPos); QTRY_COMPARE(testWidget.cursorPosition(), cursorPosition); @@ -3615,6 +3623,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 +3648,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"); @@ -3986,7 +4004,7 @@ void tst_QLineEdit::QTBUG7174_inputMaskCursorBlink() edit.setFocus(); edit.setText(QLatin1String("AAAA")); edit.show(); - QRect cursorRect = edit.inputMethodQuery(Qt::ImMicroFocus).toRect(); + QRect cursorRect = edit.inputMethodQuery(Qt::ImCursorRectangle).toRect(); QVERIFY(QTest::qWaitForWindowExposed(&edit)); edit.updateRegion = QRegion(); QTest::qWait(QApplication::cursorFlashTime()); diff --git a/tests/auto/widgets/widgets/qmdiarea/BLACKLIST b/tests/auto/widgets/widgets/qmdiarea/BLACKLIST index b1c8d7dfde..1dd876ea97 100644 --- a/tests/auto/widgets/widgets/qmdiarea/BLACKLIST +++ b/tests/auto/widgets/widgets/qmdiarea/BLACKLIST @@ -1,7 +1,16 @@ -[updateScrollBars] -osx [tileSubWindows] -osx -xcb +ubuntu-16.04 +rhel-7.6 +opensuse-leap +osx-10.11 +osx-10.13 +ubuntu-18.04 +osx-10.14 +rhel-7.4 +osx-10.12 +opensuse-42.3 [resizeTimer] -osx +osx-10.12 +osx-10.14 +osx-10.13 + diff --git a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp index 67b79e3faf..6d38dc262f 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(); @@ -478,9 +479,6 @@ void tst_QMdiArea::subWindowActivated2() // Check that we only emit _one_ signal and the active window // is unchanged after hide/show. mdiArea.hide(); -#if 0 // Used to be included in Qt4 for Q_WS_X11 - qt_x11_wait_for_window_manager(&mdiArea); -#endif QTest::qWait(100); QTRY_COMPARE(spy.count(), 1); QVERIFY(!mdiArea.activeSubWindow()); @@ -879,7 +877,7 @@ void tst_QMdiArea::minimumSizeHint() { QMdiArea workspace; workspace.show(); - QSize expectedSize(workspace.style()->pixelMetric(QStyle::PM_MDIMinimizedWidth), + QSize expectedSize(workspace.style()->pixelMetric(QStyle::PM_MdiSubWindowMinimizedWidth), workspace.style()->pixelMetric(QStyle::PM_TitleBarHeight)); qApp->processEvents(); QAbstractScrollArea dummyScrollArea; diff --git a/tests/auto/widgets/widgets/qmdisubwindow/BLACKLIST b/tests/auto/widgets/widgets/qmdisubwindow/BLACKLIST deleted file mode 100644 index 26d1776b0d..0000000000 --- a/tests/auto/widgets/widgets/qmdisubwindow/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[setOpaqueResizeAndMove] -osx-10.12 diff --git a/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp b/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp index 2b59a227b3..3ee9c72209 100644 --- a/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp +++ b/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp @@ -52,9 +52,7 @@ #include <QVector> QT_BEGIN_NAMESPACE -#if 1 // Used to be excluded in Qt4 for Q_WS_WIN extern bool qt_tab_all_widgets(); -#endif QT_END_NAMESPACE static inline bool tabAllWidgets() @@ -613,7 +611,7 @@ void tst_QMdiSubWindow::showShaded() // Calculate mouse position for bottom right corner and simulate a // vertical resize with the mouse. - int offset = window->style()->pixelMetric(QStyle::PM_MDIFrameWidth) / 2; + int offset = window->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth) / 2; QPoint mousePosition(window->width() - qMax(offset, 2), window->height() - qMax(offset, 2)); QWidget *mouseReceiver = nullptr; #ifdef Q_OS_MAC @@ -759,7 +757,7 @@ void tst_QMdiSubWindow::setOpaqueResizeAndMove() QTRY_COMPARE(priv->resizeTimerId, -1); // Enter resize mode. - int offset = window->style()->pixelMetric(QStyle::PM_MDIFrameWidth) / 2; + int offset = window->style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth) / 2; QPoint mousePosition(mouseReceiver->width() - qMax(offset, 2), mouseReceiver->height() - qMax(offset, 2)); sendMouseMove(mouseReceiver, mousePosition, Qt::NoButton); sendMousePress(mouseReceiver, mousePosition); @@ -1762,7 +1760,8 @@ void tst_QMdiSubWindow::fixedMinMaxSize() int minimizedHeight = subWindow->style()->pixelMetric(QStyle::PM_TitleBarHeight, &options); if (!subWindow->style()->styleHint(QStyle::SH_TitleBar_NoBorder, &options, subWindow)) minimizedHeight += 8; - int minimizedWidth = subWindow->style()->pixelMetric(QStyle::PM_MDIMinimizedWidth, &options); + int minimizedWidth = subWindow->style()->pixelMetric(QStyle::PM_MdiSubWindowMinimizedWidth, + &options); const QSize minimizedSize = QSize(minimizedWidth, minimizedHeight); // Even though the sub window has a minimum size set, it should be possible diff --git a/tests/auto/widgets/widgets/qmenu/BLACKLIST b/tests/auto/widgets/widgets/qmenu/BLACKLIST index bac14ea225..ad6d2f340c 100644 --- a/tests/auto/widgets/widgets/qmenu/BLACKLIST +++ b/tests/auto/widgets/widgets/qmenu/BLACKLIST @@ -1,13 +1,13 @@ [task258920_mouseBorder] -osx -[submenuTearOffDontClose] -osx-10.12 ci +osx-10.14 +osx-10.13 [layoutDirection] +osx-10.12 +osx-10.13 # Fails when enabling synchronous expose events QTBUG-62092 -osx ci [pushButtonPopulateOnAboutToShow] -osx +osx-10.13 [tearOff] -osx +osx-10.14 [activeSubMenuPosition] winrt diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp index 3bfbe754ef..9c40c0bd57 100644 --- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp +++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp @@ -610,7 +610,7 @@ void tst_QMenu::widgetActionFocus() static QMenu *getTornOffMenu() { - foreach (QWidget *w, QApplication::allWidgets()) { + for (QWidget *w : QApplication::allWidgets()) { if (w->isVisible() && w->inherits("QTornOffMenu")) return static_cast<QMenu *>(w); } @@ -948,30 +948,28 @@ void tst_QMenu::menuSizeHint() { QMenu menu; //this is a list of arbitrary strings so that we check the geometry - QStringList list = QStringList() << "trer" << "ezrfgtgvqd" << "sdgzgzerzerzer" << "eerzertz" << "er"; - foreach (QString str, list) + for (auto str : {"trer", "ezrfgtgvqd", "sdgzgzerzerzer", "eerzertz", "er"}) menu.addAction(str); - int left, top, right, bottom; - menu.getContentsMargins(&left, &top, &right, &bottom); + const QMargins cm = menu.contentsMargins(); const int panelWidth = menu.style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, &menu); const int hmargin = menu.style()->pixelMetric(QStyle::PM_MenuHMargin, 0, &menu), vmargin = menu.style()->pixelMetric(QStyle::PM_MenuVMargin, 0, &menu); int maxWidth =0; QRect result; - foreach (QAction *action, menu.actions()) { + for (QAction *action : menu.actions()) { maxWidth = qMax(maxWidth, menu.actionGeometry(action).width()); result |= menu.actionGeometry(action); - QCOMPARE(result.x(), left + hmargin + panelWidth); - QCOMPARE(result.y(), top + vmargin + panelWidth); + QCOMPARE(result.x(), cm.left() + hmargin + panelWidth); + QCOMPARE(result.y(), cm.top() + vmargin + panelWidth); } QStyleOption opt(0); opt.rect = menu.rect(); opt.state = QStyle::State_None; - QSize resSize = QSize(result.x(), result.y()) + result.size() + QSize(hmargin + right + panelWidth, vmargin + top + panelWidth); + QSize resSize = QSize(result.x(), result.y()) + result.size() + QSize(hmargin + cm.right() + panelWidth, vmargin + cm.top() + panelWidth); resSize = menu.style()->sizeFromContents(QStyle::CT_Menu, &opt, resSize.expandedTo(QApplication::globalStrut()), &menu); @@ -1572,8 +1570,7 @@ void tst_QMenu::menuSize_Scrolling() int hmargin = style()->pixelMetric(QStyle::PM_MenuHMargin, nullptr, this); int fw = style()->pixelMetric(QStyle::PM_MenuPanelWidth, nullptr, this); - int leftMargin, topMargin, rightMargin, bottomMargin; - getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin); + const QMargins cm = contentsMargins(); QRect lastItem = actionGeometry(actions().at(actions().length() - 1)); QSize s = size(); #ifdef Q_OS_WINRT @@ -1586,7 +1583,7 @@ void tst_QMenu::menuSize_Scrolling() return; } - QCOMPARE( s.width(), lastItem.right() + fw + hmargin + rightMargin + 1); + QCOMPARE( s.width(), lastItem.right() + fw + hmargin + cm.right() + 1); QMenu::showEvent(e); } diff --git a/tests/auto/widgets/widgets/qmenubar/BLACKLIST b/tests/auto/widgets/widgets/qmenubar/BLACKLIST index f897797f00..c9e15e531c 100644 --- a/tests/auto/widgets/widgets/qmenubar/BLACKLIST +++ b/tests/auto/widgets/widgets/qmenubar/BLACKLIST @@ -3,6 +3,6 @@ ubuntu-16.04 #QTBUG-66255 ubuntu-18.04 [activatedCount] -* +opensuse-42.3 [QTBUG_65488_hiddenActionTriggered] winrt diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index cb829c81a6..417d6e3124 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -34,7 +34,6 @@ #include <qstyle.h> #include <qproxystyle.h> #include <qstylefactory.h> -#include <qdesktopwidget.h> #include <qaction.h> #include <qstyleoption.h> #include <QVBoxLayout> @@ -113,10 +112,7 @@ private slots: void check_escKey(); #endif -#ifndef Q_OS_WINCE void allowActiveAndDisabled(); -#endif - void taskQTBUG56860_focus(); void check_endKey(); void check_homeKey(); @@ -1152,8 +1148,8 @@ void tst_QMenuBar::check_menuPosition() Menu menu; menu.setTitle("&menu"); - QRect availRect = QApplication::desktop()->availableGeometry(&w); - QRect screenRect = QApplication::desktop()->screenGeometry(&w); + QRect availRect = w.screen()->availableGeometry(); + QRect screenRect = w.screen()->geometry(); while(menu.sizeHint().height() < (screenRect.height()*2/3)) { menu.addAction("item"); diff --git a/tests/auto/widgets/widgets/qopenglwidget/BLACKLIST b/tests/auto/widgets/widgets/qopenglwidget/BLACKLIST index b67c8354e8..b281eca3bf 100644 --- a/tests/auto/widgets/widgets/qopenglwidget/BLACKLIST +++ b/tests/auto/widgets/widgets/qopenglwidget/BLACKLIST @@ -1,5 +1,3 @@ -[clearAndGrab] -ubuntu - [stackWidgetOpaqueChildIsVisible] -windows +windows-10 msvc-2017 + diff --git a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp index 21c9f41646..76f8ebc804 100644 --- a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp +++ b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp @@ -49,6 +49,9 @@ class tst_QOpenGLWidget : public QObject { Q_OBJECT +public: + static void initMain() { QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); } + private slots: void initTestCase(); void create(); diff --git a/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp b/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp index df5ff9d448..f2f9cfc009 100644 --- a/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp +++ b/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp @@ -171,11 +171,8 @@ void tst_QProgressBar::format() bar.setFormat("%v of %m (%p%)"); qApp->processEvents(); -#ifndef Q_OS_MAC +#if !defined(Q_OS_MACOS) && !defined(Q_OS_WIN) // Animated scroll bars get paint events all the time -#ifdef Q_OS_WIN - if (QSysInfo::WindowsVersion < QSysInfo::WV_VISTA) -#endif QVERIFY(!bar.repainted); #endif diff --git a/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp b/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp index d1923e4bb0..9f08bd337b 100644 --- a/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp +++ b/tests/auto/widgets/widgets/qscrollarea/tst_qscrollarea.cpp @@ -87,7 +87,7 @@ public: protected: QVariant inputMethodQuery(Qt::InputMethodQuery query) const { - if (query == Qt::ImMicroFocus) + if (query == Qt::ImCursorRectangle) return QRect(width() / 2, height() / 2, 5, 5); return QWidget::inputMethodQuery(query); } @@ -110,7 +110,7 @@ void tst_QScrollArea::ensureMicroFocusVisible_Task_167838() parent->resize(300, 300); scrollArea.setWidget(parent); scrollArea.ensureWidgetVisible(child, 10, 10); - QRect microFocus = child->inputMethodQuery(Qt::ImMicroFocus).toRect(); + QRect microFocus = child->inputMethodQuery(Qt::ImCursorRectangle).toRect(); QPoint p = child->mapTo(scrollArea.viewport(), microFocus.topLeft()); microFocus.translate(p - microFocus.topLeft()); QVERIFY(scrollArea.viewport()->rect().contains(microFocus)); diff --git a/tests/auto/widgets/widgets/qscrollbar/BLACKLIST b/tests/auto/widgets/widgets/qscrollbar/BLACKLIST deleted file mode 100644 index 277ae4d260..0000000000 --- a/tests/auto/widgets/widgets/qscrollbar/BLACKLIST +++ /dev/null @@ -1,3 +0,0 @@ -#QTBUG-66321 -[QTBUG_42871] -macos diff --git a/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp b/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp index 278f5cdd68..339ff293f4 100644 --- a/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp +++ b/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp @@ -151,8 +151,11 @@ void tst_QScrollBar::QTBUG_27308() testWidget.setValue(testWidget.minimum()); testWidget.setEnabled(false); - QWheelEvent event(testWidget.rect().center(), - -WHEEL_DELTA, Qt::NoButton, Qt::NoModifier, testWidget.orientation()); + const QPoint wheelPoint = testWidget.rect().center(); + const QPoint angleDelta(testWidget.orientation() == Qt::Horizontal ? -WHEEL_DELTA : 0, + testWidget.orientation() == Qt::Vertical ? -WHEEL_DELTA : 0); + QWheelEvent event(wheelPoint, testWidget.mapToGlobal(wheelPoint), QPoint(), angleDelta, + Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); qApp->sendEvent(&testWidget, &event); QCOMPARE(testWidget.value(), testWidget.minimum()); } diff --git a/tests/auto/widgets/widgets/qspinbox/BLACKLIST b/tests/auto/widgets/widgets/qspinbox/BLACKLIST index a38511bfb4..96a7732165 100644 --- a/tests/auto/widgets/widgets/qspinbox/BLACKLIST +++ b/tests/auto/widgets/widgets/qspinbox/BLACKLIST @@ -1,3 +1,2 @@ [stepModifierPressAndHold] -opensuse ci # QTBUG-69492 -opensuse-leap ci +opensuse-42.3 diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp index 52d7dad7cf..d75e701d1c 100644 --- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp @@ -206,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; @@ -222,19 +222,19 @@ static QLatin1String modifierToName(Qt::KeyboardModifier modifier) { switch (modifier) { case Qt::NoModifier: - return QLatin1Literal("No"); + return QLatin1String("No"); break; case Qt::ControlModifier: - return QLatin1Literal("Ctrl"); + return QLatin1String("Ctrl"); break; case Qt::ShiftModifier: - return QLatin1Literal("Shift"); + return QLatin1String("Shift"); break; case Qt::AltModifier: - return QLatin1Literal("Alt"); + return QLatin1String("Alt"); break; case Qt::MetaModifier: - return QLatin1Literal("Meta"); + return QLatin1String("Meta"); break; default: qFatal("Unexpected keyboard modifier"); @@ -490,7 +490,7 @@ void tst_QSpinBox::setPrefixSuffix() } } -void tst_QSpinBox::valueChangedHelper(const QString &text) +void tst_QSpinBox::textChangedHelper(const QString &text) { actualTexts << text; } @@ -568,7 +568,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); @@ -1331,7 +1331,6 @@ void tst_QSpinBox::wheelEvents_data() { #if QT_CONFIG(wheelevent) QTest::addColumn<QPoint>("angleDelta"); - QTest::addColumn<int>("qt4Delta"); QTest::addColumn<int>("stepModifier"); QTest::addColumn<Qt::KeyboardModifiers>("modifier"); QTest::addColumn<Qt::MouseEventSource>("source"); @@ -1402,16 +1401,16 @@ void tst_QSpinBox::wheelEvents_data() QLatin1String sourceName; switch (source) { case Qt::MouseEventNotSynthesized: - sourceName = QLatin1Literal("NotSynthesized"); + sourceName = QLatin1String("NotSynthesized"); break; case Qt::MouseEventSynthesizedBySystem: - sourceName = QLatin1Literal("SynthesizedBySystem"); + sourceName = QLatin1String("SynthesizedBySystem"); break; case Qt::MouseEventSynthesizedByQt: - sourceName = QLatin1Literal("SynthesizedByQt"); + sourceName = QLatin1String("SynthesizedByQt"); break; case Qt::MouseEventSynthesizedByApplication: - sourceName = QLatin1Literal("SynthesizedByApplication"); + sourceName = QLatin1String("SynthesizedByApplication"); break; default: qFatal("Unexpected wheel event source"); @@ -1430,7 +1429,6 @@ void tst_QSpinBox::wheelEvents_data() modifierName.latin1(), sourceName.latin1()) << angleDelta - << units << static_cast<int>(stepModifier) << modifiers << source @@ -1450,7 +1448,6 @@ void tst_QSpinBox::wheelEvents() { #if QT_CONFIG(wheelevent) QFETCH(QPoint, angleDelta); - QFETCH(int, qt4Delta); QFETCH(int, stepModifier); QFETCH(Qt::KeyboardModifiers, modifier); QFETCH(Qt::MouseEventSource, source); @@ -1466,9 +1463,8 @@ void tst_QSpinBox::wheelEvents() style->stepModifier = static_cast<Qt::KeyboardModifier>(stepModifier); spinBox.setStyle(style.data()); - QWheelEvent event(QPointF(), QPointF(), QPoint(), angleDelta, qt4Delta, - Qt::Vertical, Qt::NoButton, modifier, Qt::NoScrollPhase, - source); + QWheelEvent event(QPointF(), QPointF(), QPoint(), angleDelta, + Qt::NoButton, modifier, Qt::NoScrollPhase, false, source); for (int expected : expectedValues) { qApp->sendEvent(&spinBox, &event); QCOMPARE(spinBox.value(), expected); diff --git a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp index 8b45ac20b7..cbeb77a25e 100644 --- a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp +++ b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp @@ -599,7 +599,7 @@ void tst_QSplitter::testShowHide() QWidget widget(&topLevel); widget.resize(400 + split->handleWidth(), 200); QVBoxLayout *lay=new QVBoxLayout(&widget); - lay->setMargin(0); + lay->setContentsMargins(0, 0, 0, 0); lay->setSpacing(0); split->addWidget(new QWidget); split->addWidget(new QWidget); diff --git a/tests/auto/widgets/widgets/qtabwidget/qtabwidget.pro b/tests/auto/widgets/widgets/qtabwidget/qtabwidget.pro index 6523209c32..b61cc8fa13 100644 --- a/tests/auto/widgets/widgets/qtabwidget/qtabwidget.pro +++ b/tests/auto/widgets/widgets/qtabwidget/qtabwidget.pro @@ -8,4 +8,4 @@ INCLUDEPATH += ../ HEADERS += SOURCES += tst_qtabwidget.cpp -win32:!winrt: LIBS += -luser32 +win32:!winrt: QMAKE_USE += user32 diff --git a/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp b/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp index cbf5196bb9..feade7d443 100644 --- a/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp +++ b/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp @@ -620,7 +620,7 @@ void tst_QTabWidget::heightForWidth() QWidget *window = new QWidget; QVBoxLayout *lay = new QVBoxLayout(window); - lay->setMargin(0); + lay->setContentsMargins(0, 0, 0, 0); lay->setSpacing(0); QTabWidget *tabWid = new QTabWidget(window); QWidget *w = new QWidget; @@ -637,7 +637,7 @@ void tst_QTabWidget::heightForWidth() ); label->setWordWrap(true); lay2->addWidget(label); - lay2->setMargin(0); + lay2->setContentsMargins(0, 0, 0, 0); lay->addWidget(tabWid); int h = window->heightForWidth(160); diff --git a/tests/auto/widgets/widgets/qtextbrowser/heading.html b/tests/auto/widgets/widgets/qtextbrowser/heading.html new file mode 100644 index 0000000000..8b23807f65 --- /dev/null +++ b/tests/auto/widgets/widgets/qtextbrowser/heading.html @@ -0,0 +1,2 @@ +<h3>this is a heading</h3> +<p>this is a paragraph</p> diff --git a/tests/auto/widgets/widgets/qtextbrowser/markdown.md b/tests/auto/widgets/widgets/qtextbrowser/markdown.md new file mode 100644 index 0000000000..be56aef234 --- /dev/null +++ b/tests/auto/widgets/widgets/qtextbrowser/markdown.md @@ -0,0 +1,2 @@ +### this is a heading +this is a paragraph diff --git a/tests/auto/widgets/widgets/qtextbrowser/markdown.really b/tests/auto/widgets/widgets/qtextbrowser/markdown.really new file mode 100644 index 0000000000..be56aef234 --- /dev/null +++ b/tests/auto/widgets/widgets/qtextbrowser/markdown.really @@ -0,0 +1,2 @@ +### this is a heading +this is a paragraph diff --git a/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro b/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro index 9680ffd871..dfdcf26497 100644 --- a/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro +++ b/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro @@ -4,6 +4,6 @@ SOURCES += tst_qtextbrowser.cpp QT += widgets testlib -TESTDATA += *.html subdir/* +TESTDATA += *.html *.md markdown.really subdir/* builtin_testdata: DEFINES += BUILTIN_TESTDATA diff --git a/tests/auto/widgets/widgets/qtextbrowser/quotesAndFractions.md b/tests/auto/widgets/widgets/qtextbrowser/quotesAndFractions.md new file mode 100644 index 0000000000..6bad9cb95b --- /dev/null +++ b/tests/auto/widgets/widgets/qtextbrowser/quotesAndFractions.md @@ -0,0 +1 @@ +you’ll hope to see ❝quotes❞ ﹠1½ ⅔ ¼ ⅗ ⅚ ⅝ some “vulgar” fractions (pardon my «French») diff --git a/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp b/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp index 8a1b228c71..27bf0ce7be 100644 --- a/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp +++ b/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -38,7 +38,7 @@ class TestBrowser : public QTextBrowser { public: - inline TestBrowser() : htmlLoadAttempts(0) { + inline TestBrowser() { show(); QApplication::setActiveWindow(this); activateWindow(); @@ -47,11 +47,12 @@ public: QVERIFY(hasFocus()); } - virtual QVariant loadResource(int type, const QUrl &name); + QVariant loadResource(int type, const QUrl &name) override; - int htmlLoadAttempts; + int htmlLoadAttempts = 0; QUrl lastResource; QUrl sourceInsideLoadResource; + QUrl baseInsideLoadResource; }; QVariant TestBrowser::loadResource(int type, const QUrl &name) @@ -60,6 +61,7 @@ QVariant TestBrowser::loadResource(int type, const QUrl &name) htmlLoadAttempts++; lastResource = name; sourceInsideLoadResource = source(); + baseInsideLoadResource = document()->baseUrl(); return QTextBrowser::loadResource(type, name); } @@ -90,6 +92,10 @@ private slots: void focusIndicator(); void focusHistory(); void urlEncoding(); + void sourceType_data(); + void sourceType(); + void unicode_data(); + void unicode(); private: TestBrowser *browser; @@ -108,7 +114,7 @@ void tst_QTextBrowser::init() void tst_QTextBrowser::cleanup() { delete browser; - browser = 0; + browser = nullptr; } void tst_QTextBrowser::noReloadOnAnchorJump() @@ -428,11 +434,18 @@ void tst_QTextBrowser::sourceInsideLoadResource() #ifdef Q_OS_WINRT QSKIP("Paths cannot be compared if applications are sandboxed."); #endif - QUrl url = QUrl::fromLocalFile("pagewithimage.html"); + QUrl url = QUrl::fromLocalFile("pagewithimage.html"); // "file://pagewithimage.html" browser->setSource(url); QCOMPARE(browser->lastResource, QUrl::fromLocalFile(QDir::current().filePath("foobar.png"))); + // baseUrl was not set because the source URL was a relative one + QCOMPARE(browser->baseInsideLoadResource, QUrl()); QEXPECT_FAIL("", "This is currently not supported", Continue); QCOMPARE(browser->sourceInsideLoadResource.toString(), url.toString()); + url = QUrl::fromLocalFile(QDir::current().filePath("pagewithimage.html")); // "file:///home/user/path/to/pagewithimage.html" + browser->setSource(url); + QCOMPARE(browser->lastResource, QUrl::fromLocalFile(QDir::current().filePath("foobar.png"))); + // baseUrl has the full path, and that's where relative-path resources come from + QCOMPARE(browser->baseInsideLoadResource, QUrl::fromLocalFile(QDir::currentPath() + QLatin1Char('/'))); } void tst_QTextBrowser::textInteractionFlags_vs_readOnly() @@ -669,5 +682,72 @@ void tst_QTextBrowser::urlEncoding() delete browser; } +void tst_QTextBrowser::sourceType_data() +{ + QTest::addColumn<QString>("sourceFile"); + QTest::addColumn<QTextDocument::ResourceType>("sourceType"); + QTest::addColumn<int>("expectedMaxHeadingLevel"); + QTest::addColumn<QTextDocument::ResourceType>("expectedSourceType"); + +#if QT_CONFIG(textmarkdownreader) + const int maxMdHeadingLevel = 3; + const QTextDocument::ResourceType mdExpectedType = QTextDocument::MarkdownResource; +#else + // If Qt doesn't support markdown, and we read a MD document anyway, it won't have any H3's. + const int maxMdHeadingLevel = 0; + const QTextDocument::ResourceType mdExpectedType = QTextDocument::HtmlResource; +#endif + QTest::newRow("markdown detected") << "markdown.md" << QTextDocument::UnknownResource << maxMdHeadingLevel << mdExpectedType; + QTest::newRow("markdown specified") << "markdown.really" << QTextDocument::MarkdownResource << maxMdHeadingLevel << mdExpectedType; + QTest::newRow("markdown not identified") << "markdown.really" << QTextDocument::UnknownResource << 0 << QTextDocument::HtmlResource; + QTest::newRow("html detected") << "heading.html" << QTextDocument::UnknownResource << 3 << QTextDocument::HtmlResource; + QTest::newRow("html specified") << "heading.html" << QTextDocument::HtmlResource << 3 << QTextDocument::HtmlResource; +} + +void tst_QTextBrowser::sourceType() +{ + QFETCH(QString, sourceFile); + QFETCH(QTextDocument::ResourceType, sourceType); + QFETCH(int, expectedMaxHeadingLevel); + QFETCH(QTextDocument::ResourceType, expectedSourceType); + if (sourceType == QTextDocument::UnknownResource) + // verify that the property setter works, with its default parameter for sourceType + browser->setProperty("source", QUrl::fromLocalFile(QFINDTESTDATA(sourceFile))); + else + browser->setSource(QUrl::fromLocalFile(QFINDTESTDATA(sourceFile)), sourceType); + QCOMPARE(browser->sourceType(), expectedSourceType); + QTextFrame::iterator iterator = browser->document()->rootFrame()->begin(); + int maxHeadingLevel = -1; + while (!iterator.atEnd()) + maxHeadingLevel = qMax(iterator++.currentBlock().blockFormat().intProperty(QTextFormat::HeadingLevel), maxHeadingLevel); + QCOMPARE(maxHeadingLevel, expectedMaxHeadingLevel); +} + +void tst_QTextBrowser::unicode_data() +{ + QTest::addColumn<QString>("sourceFile"); + QTest::addColumn<QTextDocument::ResourceType>("sourceType"); + QTest::addColumn<QString>("expectedText"); + +#if QT_CONFIG(textmarkdownreader) + QTest::newRow("markdown with quotes and fractions") << "quotesAndFractions.md" << QTextDocument::MarkdownResource << + "you\u2019ll hope to see \u275Dquotes\u275E \uFE601\u00BD \u2154 \u00BC \u2157 \u215A \u215D some \u201Cvulgar\u201D fractions (pardon my \u00ABFrench\u00BB)"; +#endif +} + +void tst_QTextBrowser::unicode() +{ + QFETCH(QString, sourceFile); + QFETCH(QTextDocument::ResourceType, sourceType); + QFETCH(QString, expectedText); + browser->setSource(QUrl::fromLocalFile(QFINDTESTDATA(sourceFile)), sourceType); + QTextFrame::iterator iterator = browser->document()->rootFrame()->begin(); + while (!iterator.atEnd()) { + QString blockText = iterator++.currentBlock().text(); + if (!blockText.isEmpty()) + QCOMPARE(blockText, expectedText); + } +} + QTEST_MAIN(tst_QTextBrowser) #include "tst_qtextbrowser.moc" diff --git a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp index 3669935823..b31e230893 100644 --- a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp +++ b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp @@ -160,6 +160,7 @@ private slots: void selectionChanged(); #ifndef QT_NO_CLIPBOARD void copyPasteBackgroundImage(); + void copyPasteForegroundImage(); #endif void setText(); void cursorRect(); @@ -1904,6 +1905,36 @@ void tst_QTextEdit::copyPasteBackgroundImage() ba.texture().cacheKey() == bb.texture().cacheKey()); QFile::remove(QLatin1String("foo.png")); } + +void tst_QTextEdit::copyPasteForegroundImage() +{ + ed->clear(); + + QPixmap pix(20, 20); + pix.fill(Qt::blue); + + QTextCharFormat fmt; + { + QBrush textureBrush; + { + textureBrush.setTexture(pix); + } + textureBrush.setStyle(Qt::TexturePattern); + fmt.setForeground(textureBrush); + } + ed->textCursor().insertText("Foobar", fmt); + + ed->moveCursor(QTextCursor::Start); + ed->moveCursor(QTextCursor::End, QTextCursor::KeepAnchor); + + ed->copy(); + ed->clear(); + ed->paste(); + + QBrush brush = ed->textCursor().charFormat().foreground(); + QCOMPARE(brush.style(), Qt::TexturePattern); + QCOMPARE(brush.texture().cacheKey(), pix.cacheKey()); +} #endif void tst_QTextEdit::setText() @@ -1947,8 +1978,23 @@ void tst_QTextEdit::fullWidthSelection_data() #endif #ifdef QT_BUILD_INTERNAL + +// With the fix for QTBUG-78318 scaling of documentMargin is added. The testing framework +// forces qt_defaultDpi() to always return 96 DPI. For systems where the actual DPI differs +// (typically 72 DPI) this would now cause scaling of the documentMargin when +// drawing QTextEdit into QImage. In order to avoid the need of multiple reference PNGs +// for comparison we disable the Qt::AA_Use96Dpi attribute for these tests. + +struct ForceSystemDpiHelper { + ForceSystemDpiHelper() { QCoreApplication::setAttribute(Qt::AA_Use96Dpi, false); } + ~ForceSystemDpiHelper() { QCoreApplication::setAttribute(Qt::AA_Use96Dpi, old); } + bool old = QCoreApplication::testAttribute(Qt::AA_Use96Dpi); +}; + void tst_QTextEdit::fullWidthSelection() { + ForceSystemDpiHelper useSystemDpi; + QFETCH(int, cursorFrom); QFETCH(int, cursorTo); QFETCH(QString, imageFileName); @@ -2017,6 +2063,8 @@ void tst_QTextEdit::fullWidthSelection() #ifdef QT_BUILD_INTERNAL void tst_QTextEdit::fullWidthSelection2() { + ForceSystemDpiHelper useSystemDpi; + QPalette myPalette; myPalette.setColor(QPalette::All, QPalette::HighlightedText, QColor(0,0,0,0)); myPalette.setColor(QPalette::All, QPalette::Highlight, QColor(239,221,85)); @@ -2638,12 +2686,14 @@ void tst_QTextEdit::wheelEvent() ed.setReadOnly(true); float defaultFontSize = ed.font().pointSizeF(); - QWheelEvent wheelUp(QPointF(), QPointF(), QPoint(), QPoint(0, 120), 120, Qt::Vertical, Qt::NoButton, Qt::ControlModifier); + QWheelEvent wheelUp(QPointF(), QPointF(), QPoint(), QPoint(0, 120), + Qt::NoButton, Qt::ControlModifier, Qt::NoScrollPhase, Qt::MouseEventNotSynthesized); ed.wheelEvent(&wheelUp); QCOMPARE(defaultFontSize + 1, ed.font().pointSizeF()); - QWheelEvent wheelHalfDown(QPointF(), QPointF(), QPoint(), QPoint(0, -60), -60, Qt::Vertical, Qt::NoButton, Qt::ControlModifier); + QWheelEvent wheelHalfDown(QPointF(), QPointF(), QPoint(), QPoint(0, -60), + Qt::NoButton, Qt::ControlModifier, Qt::NoScrollPhase, Qt::MouseEventNotSynthesized); ed.wheelEvent(&wheelHalfDown); QCOMPARE(defaultFontSize + 0.5, ed.font().pointSizeF()); diff --git a/tests/auto/widgets/widgets/qtoolbutton/BLACKLIST b/tests/auto/widgets/widgets/qtoolbutton/BLACKLIST index df4fda196f..52ba36562f 100644 --- a/tests/auto/widgets/widgets/qtoolbutton/BLACKLIST +++ b/tests/auto/widgets/widgets/qtoolbutton/BLACKLIST @@ -1,2 +1,2 @@ [task176137_autoRepeatOfAction] -osx ci +osx-10.13 |