From e82a1d6b2998b30fc100c4ebf9b98ee18dd3c374 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 16 Aug 2019 11:30:58 +0200 Subject: Deprecate QDirModel Deprecate the constructors, add guards. Use a QStandardItemModel in tst_QCompleter::setters() instead. Task-number: QTBUG-69410 Change-Id: If77298982bb3d0b5321ae1271fab3f33b196101d Reviewed-by: Qt CI Bot Reviewed-by: Richard Moe Gustavsen --- .../corelib/itemmodels/qitemmodel/modelstotest.cpp | 18 ++++++++++++++---- .../auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp | 2 ++ tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp | 15 ++++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp b/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp index 354190e754..d61d45bc52 100644 --- a/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp +++ b/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp @@ -90,7 +90,9 @@ ModelsToTest::ModelsToTest() { setupDatabase(); +#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15) tests.append(test("QDirModel", ReadOnly, HasData)); +#endif tests.append(test("QStringListModel", ReadWrite, HasData)); tests.append(test("QStringListModelEmpty", ReadWrite, Empty)); @@ -165,11 +167,16 @@ QAbstractItemModel *ModelsToTest::createModel(const QString &modelType) return model; } +#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED if (modelType == "QDirModel") { QDirModel *model = new QDirModel(); model->setReadOnly(false); return model; } +QT_WARNING_POP +#endif if (modelType == "QSqlQueryModel") { QSqlQueryModel *model = new QSqlQueryModel(); @@ -287,6 +294,7 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model) return returnIndex; } +#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15) if (QDirModel *dirModel = qobject_cast(model)) { m_dirModelTempDir.reset(new QTemporaryDir); if (!m_dirModelTempDir->isValid()) @@ -303,6 +311,7 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model) } return dirModel->index(tempDir.path()); } +#endif // QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15) if (QSqlQueryModel *queryModel = qobject_cast(model)) { QSqlQuery q; @@ -359,11 +368,12 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model) */ void ModelsToTest::cleanupTestArea(QAbstractItemModel *model) { - if (qobject_cast(model)) { - m_dirModelTempDir.reset(); - } else if (qobject_cast(model)) { + if (qobject_cast(model)) QSqlQuery q("DROP TABLE test"); - } +#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15) + if (qobject_cast(model)) + m_dirModelTempDir.reset(); +#endif } void ModelsToTest::setupDatabase() diff --git a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp index d401154228..5097f2e356 100644 --- a/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp +++ b/tests/auto/widgets/itemviews/qdirmodel/tst_qdirmodel.cpp @@ -34,6 +34,8 @@ #include #include "emulationdetector.h" +QT_WARNING_DISABLE_DEPRECATED + class tst_QDirModel : public QObject { Q_OBJECT diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp index 5a51f15008..4ccbe42353 100644 --- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp @@ -107,8 +107,10 @@ private slots: void csMatchingOnCiSortedModel_data(); void csMatchingOnCiSortedModel(); +#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15) void directoryModel_data(); void directoryModel(); +#endif void fileSystemModel_data(); void fileSystemModel(); @@ -224,9 +226,14 @@ void tst_QCompleter::setSourceModel(ModelType type) parent->setText(completionColumn, QLatin1String("p2,c4p2")); break; case DIRECTORY_MODEL: +#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED completer->setCsvCompletion(false); completer->setModel(new QDirModel(completer)); completer->setCompletionColumn(0); +QT_WARNING_POP +#endif // QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15) break; case FILESYSTEM_MODEL: completer->setCsvCompletion(false); @@ -590,6 +597,7 @@ void tst_QCompleter::csMatchingOnCiSortedModel() filter(); } +#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15) void tst_QCompleter::directoryModel_data() { delete completer; @@ -639,6 +647,7 @@ void tst_QCompleter::directoryModel() #endif filter(); } +#endif // QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15) void tst_QCompleter::fileSystemModel_data() { @@ -1057,15 +1066,15 @@ void tst_QCompleter::setters() delete completer; completer = new CsvCompleter; QVERIFY(completer->popup() != nullptr); - QPointer dirModel = new QDirModel(completer); + QPointer itemModel(new QStandardItemModel(1, 0, completer)); QAbstractItemModel *oldModel = completer->model(); - completer->setModel(dirModel); + completer->setModel(itemModel.data()); QVERIFY(completer->popup()->model() != oldModel); QCOMPARE(completer->popup()->model(), completer->completionModel()); completer->setPopup(new QListView); QCOMPARE(completer->popup()->model(), completer->completionModel()); completer->setModel(new QStringListModel(completer)); - QVERIFY(dirModel == nullptr); // must have been deleted + QVERIFY(itemModel.isNull()); // must have been deleted completer->setModel(nullptr); completer->setWidget(nullptr); -- cgit v1.2.3