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 <qt_ci_bot@qt-project.org> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
efbba1e54a
commit
e82a1d6b29
@ -39,6 +39,8 @@
|
||||
|
||||
#include "qdirmodel.h"
|
||||
|
||||
#if QT_DEPRECATED_SINCE(5, 15)
|
||||
|
||||
#include <qfile.h>
|
||||
#include <qfilesystemmodel.h>
|
||||
#include <qurl.h>
|
||||
@ -1372,3 +1374,5 @@ QFileInfo QDirModelPrivate::resolvedInfo(QFileInfo info)
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "moc_qdirmodel.cpp"
|
||||
|
||||
#endif // QT_DEPRECATED_SINCE(5, 15)
|
||||
|
@ -45,6 +45,8 @@
|
||||
#include <QtCore/qdir.h>
|
||||
#include <QtWidgets/qfileiconprovider.h>
|
||||
|
||||
#if QT_DEPRECATED_SINCE(5, 15)
|
||||
|
||||
QT_REQUIRE_CONFIG(dirmodel);
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -65,9 +67,10 @@ public:
|
||||
FileNameRole
|
||||
};
|
||||
|
||||
QDirModel(const QStringList &nameFilters, QDir::Filters filters,
|
||||
QDir::SortFlags sort, QObject *parent = nullptr);
|
||||
explicit QDirModel(QObject *parent = nullptr);
|
||||
QT_DEPRECATED_VERSION_X_5_15("Use QFileSystemModel") QDirModel(const QStringList &nameFilters,
|
||||
QDir::Filters filters, QDir::SortFlags sort,
|
||||
QObject *parent = nullptr);
|
||||
QT_DEPRECATED_VERSION_X_5_15("Use QFileSystemModel") explicit QDirModel(QObject *parent = nullptr);
|
||||
~QDirModel();
|
||||
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||
@ -144,4 +147,6 @@ private:
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QT_DEPRECATED_SINCE(5, 15)
|
||||
|
||||
#endif // QDIRMODEL_H
|
||||
|
@ -473,7 +473,7 @@ QMatchData QCompletionEngine::filterHistory()
|
||||
if (curParts.count() <= 1 || c->proxy->showAll || !source)
|
||||
return QMatchData();
|
||||
|
||||
#if QT_CONFIG(dirmodel)
|
||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||
const bool isDirModel = (qobject_cast<QDirModel *>(source) != nullptr);
|
||||
#else
|
||||
const bool isDirModel = false;
|
||||
@ -903,7 +903,7 @@ void QCompleterPrivate::_q_complete(QModelIndex index, bool highlighted)
|
||||
QModelIndex si = proxy->mapToSource(index);
|
||||
si = si.sibling(si.row(), column); // for clicked()
|
||||
completion = q->pathFromIndex(si);
|
||||
#if QT_CONFIG(dirmodel)
|
||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||
// add a trailing separator in inline
|
||||
if (mode == QCompleter::InlineCompletion) {
|
||||
if (qobject_cast<QDirModel *>(proxy->sourceModel()) && QFileInfo(completion).isDir())
|
||||
@ -1125,7 +1125,7 @@ void QCompleter::setModel(QAbstractItemModel *model)
|
||||
setPopup(d->popup); // set the model and make new connections
|
||||
if (oldModel && oldModel->QObject::parent() == this)
|
||||
delete oldModel;
|
||||
#if QT_CONFIG(dirmodel)
|
||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||
if (qobject_cast<QDirModel *>(model)) {
|
||||
#if defined(Q_OS_WIN)
|
||||
setCaseSensitivity(Qt::CaseInsensitive);
|
||||
@ -1846,7 +1846,7 @@ QString QCompleter::pathFromIndex(const QModelIndex& index) const
|
||||
return QString();
|
||||
bool isDirModel = false;
|
||||
bool isFsModel = false;
|
||||
#if QT_CONFIG(dirmodel)
|
||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||
isDirModel = qobject_cast<QDirModel *>(d->proxy->sourceModel()) != nullptr;
|
||||
#endif
|
||||
#if QT_CONFIG(filesystemmodel)
|
||||
@ -1895,7 +1895,7 @@ QStringList QCompleter::splitPath(const QString& path) const
|
||||
{
|
||||
bool isDirModel = false;
|
||||
bool isFsModel = false;
|
||||
#if QT_CONFIG(dirmodel)
|
||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||
Q_D(const QCompleter);
|
||||
isDirModel = qobject_cast<QDirModel *>(d->proxy->sourceModel()) != nullptr;
|
||||
#endif
|
||||
|
@ -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<QDirModel *>(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<QSqlQueryModel *>(model)) {
|
||||
QSqlQuery q;
|
||||
@ -359,11 +368,12 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model)
|
||||
*/
|
||||
void ModelsToTest::cleanupTestArea(QAbstractItemModel *model)
|
||||
{
|
||||
if (qobject_cast<QDirModel *>(model)) {
|
||||
m_dirModelTempDir.reset();
|
||||
} else if (qobject_cast<QSqlQueryModel *>(model)) {
|
||||
if (qobject_cast<QSqlQueryModel *>(model))
|
||||
QSqlQuery q("DROP TABLE test");
|
||||
}
|
||||
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||
if (qobject_cast<QDirModel *>(model))
|
||||
m_dirModelTempDir.reset();
|
||||
#endif
|
||||
}
|
||||
|
||||
void ModelsToTest::setupDatabase()
|
||||
|
@ -34,6 +34,8 @@
|
||||
#include <qdebug.h>
|
||||
#include "emulationdetector.h"
|
||||
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
|
||||
class tst_QDirModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -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<QDirModel> dirModel = new QDirModel(completer);
|
||||
QPointer<QStandardItemModel> 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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user