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"
|
#include "qdirmodel.h"
|
||||||
|
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 15)
|
||||||
|
|
||||||
#include <qfile.h>
|
#include <qfile.h>
|
||||||
#include <qfilesystemmodel.h>
|
#include <qfilesystemmodel.h>
|
||||||
#include <qurl.h>
|
#include <qurl.h>
|
||||||
@ -1372,3 +1374,5 @@ QFileInfo QDirModelPrivate::resolvedInfo(QFileInfo info)
|
|||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
#include "moc_qdirmodel.cpp"
|
#include "moc_qdirmodel.cpp"
|
||||||
|
|
||||||
|
#endif // QT_DEPRECATED_SINCE(5, 15)
|
||||||
|
@ -45,6 +45,8 @@
|
|||||||
#include <QtCore/qdir.h>
|
#include <QtCore/qdir.h>
|
||||||
#include <QtWidgets/qfileiconprovider.h>
|
#include <QtWidgets/qfileiconprovider.h>
|
||||||
|
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 15)
|
||||||
|
|
||||||
QT_REQUIRE_CONFIG(dirmodel);
|
QT_REQUIRE_CONFIG(dirmodel);
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -65,9 +67,10 @@ public:
|
|||||||
FileNameRole
|
FileNameRole
|
||||||
};
|
};
|
||||||
|
|
||||||
QDirModel(const QStringList &nameFilters, QDir::Filters filters,
|
QT_DEPRECATED_VERSION_X_5_15("Use QFileSystemModel") QDirModel(const QStringList &nameFilters,
|
||||||
QDir::SortFlags sort, QObject *parent = nullptr);
|
QDir::Filters filters, QDir::SortFlags sort,
|
||||||
explicit QDirModel(QObject *parent = nullptr);
|
QObject *parent = nullptr);
|
||||||
|
QT_DEPRECATED_VERSION_X_5_15("Use QFileSystemModel") explicit QDirModel(QObject *parent = nullptr);
|
||||||
~QDirModel();
|
~QDirModel();
|
||||||
|
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||||
@ -144,4 +147,6 @@ private:
|
|||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // QT_DEPRECATED_SINCE(5, 15)
|
||||||
|
|
||||||
#endif // QDIRMODEL_H
|
#endif // QDIRMODEL_H
|
||||||
|
@ -473,7 +473,7 @@ QMatchData QCompletionEngine::filterHistory()
|
|||||||
if (curParts.count() <= 1 || c->proxy->showAll || !source)
|
if (curParts.count() <= 1 || c->proxy->showAll || !source)
|
||||||
return QMatchData();
|
return QMatchData();
|
||||||
|
|
||||||
#if QT_CONFIG(dirmodel)
|
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||||
const bool isDirModel = (qobject_cast<QDirModel *>(source) != nullptr);
|
const bool isDirModel = (qobject_cast<QDirModel *>(source) != nullptr);
|
||||||
#else
|
#else
|
||||||
const bool isDirModel = false;
|
const bool isDirModel = false;
|
||||||
@ -903,7 +903,7 @@ void QCompleterPrivate::_q_complete(QModelIndex index, bool highlighted)
|
|||||||
QModelIndex si = proxy->mapToSource(index);
|
QModelIndex si = proxy->mapToSource(index);
|
||||||
si = si.sibling(si.row(), column); // for clicked()
|
si = si.sibling(si.row(), column); // for clicked()
|
||||||
completion = q->pathFromIndex(si);
|
completion = q->pathFromIndex(si);
|
||||||
#if QT_CONFIG(dirmodel)
|
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||||
// add a trailing separator in inline
|
// add a trailing separator in inline
|
||||||
if (mode == QCompleter::InlineCompletion) {
|
if (mode == QCompleter::InlineCompletion) {
|
||||||
if (qobject_cast<QDirModel *>(proxy->sourceModel()) && QFileInfo(completion).isDir())
|
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
|
setPopup(d->popup); // set the model and make new connections
|
||||||
if (oldModel && oldModel->QObject::parent() == this)
|
if (oldModel && oldModel->QObject::parent() == this)
|
||||||
delete oldModel;
|
delete oldModel;
|
||||||
#if QT_CONFIG(dirmodel)
|
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||||
if (qobject_cast<QDirModel *>(model)) {
|
if (qobject_cast<QDirModel *>(model)) {
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
setCaseSensitivity(Qt::CaseInsensitive);
|
setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
@ -1846,7 +1846,7 @@ QString QCompleter::pathFromIndex(const QModelIndex& index) const
|
|||||||
return QString();
|
return QString();
|
||||||
bool isDirModel = false;
|
bool isDirModel = false;
|
||||||
bool isFsModel = 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;
|
isDirModel = qobject_cast<QDirModel *>(d->proxy->sourceModel()) != nullptr;
|
||||||
#endif
|
#endif
|
||||||
#if QT_CONFIG(filesystemmodel)
|
#if QT_CONFIG(filesystemmodel)
|
||||||
@ -1895,7 +1895,7 @@ QStringList QCompleter::splitPath(const QString& path) const
|
|||||||
{
|
{
|
||||||
bool isDirModel = false;
|
bool isDirModel = false;
|
||||||
bool isFsModel = false;
|
bool isFsModel = false;
|
||||||
#if QT_CONFIG(dirmodel)
|
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||||
Q_D(const QCompleter);
|
Q_D(const QCompleter);
|
||||||
isDirModel = qobject_cast<QDirModel *>(d->proxy->sourceModel()) != nullptr;
|
isDirModel = qobject_cast<QDirModel *>(d->proxy->sourceModel()) != nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
@ -90,7 +90,9 @@ ModelsToTest::ModelsToTest()
|
|||||||
{
|
{
|
||||||
setupDatabase();
|
setupDatabase();
|
||||||
|
|
||||||
|
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||||
tests.append(test("QDirModel", ReadOnly, HasData));
|
tests.append(test("QDirModel", ReadOnly, HasData));
|
||||||
|
#endif
|
||||||
tests.append(test("QStringListModel", ReadWrite, HasData));
|
tests.append(test("QStringListModel", ReadWrite, HasData));
|
||||||
tests.append(test("QStringListModelEmpty", ReadWrite, Empty));
|
tests.append(test("QStringListModelEmpty", ReadWrite, Empty));
|
||||||
|
|
||||||
@ -165,11 +167,16 @@ QAbstractItemModel *ModelsToTest::createModel(const QString &modelType)
|
|||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||||
|
QT_WARNING_PUSH
|
||||||
|
QT_WARNING_DISABLE_DEPRECATED
|
||||||
if (modelType == "QDirModel") {
|
if (modelType == "QDirModel") {
|
||||||
QDirModel *model = new QDirModel();
|
QDirModel *model = new QDirModel();
|
||||||
model->setReadOnly(false);
|
model->setReadOnly(false);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
QT_WARNING_POP
|
||||||
|
#endif
|
||||||
|
|
||||||
if (modelType == "QSqlQueryModel") {
|
if (modelType == "QSqlQueryModel") {
|
||||||
QSqlQueryModel *model = new QSqlQueryModel();
|
QSqlQueryModel *model = new QSqlQueryModel();
|
||||||
@ -287,6 +294,7 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model)
|
|||||||
return returnIndex;
|
return returnIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||||
if (QDirModel *dirModel = qobject_cast<QDirModel *>(model)) {
|
if (QDirModel *dirModel = qobject_cast<QDirModel *>(model)) {
|
||||||
m_dirModelTempDir.reset(new QTemporaryDir);
|
m_dirModelTempDir.reset(new QTemporaryDir);
|
||||||
if (!m_dirModelTempDir->isValid())
|
if (!m_dirModelTempDir->isValid())
|
||||||
@ -303,6 +311,7 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model)
|
|||||||
}
|
}
|
||||||
return dirModel->index(tempDir.path());
|
return dirModel->index(tempDir.path());
|
||||||
}
|
}
|
||||||
|
#endif // QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||||
|
|
||||||
if (QSqlQueryModel *queryModel = qobject_cast<QSqlQueryModel *>(model)) {
|
if (QSqlQueryModel *queryModel = qobject_cast<QSqlQueryModel *>(model)) {
|
||||||
QSqlQuery q;
|
QSqlQuery q;
|
||||||
@ -359,11 +368,12 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model)
|
|||||||
*/
|
*/
|
||||||
void ModelsToTest::cleanupTestArea(QAbstractItemModel *model)
|
void ModelsToTest::cleanupTestArea(QAbstractItemModel *model)
|
||||||
{
|
{
|
||||||
if (qobject_cast<QDirModel *>(model)) {
|
if (qobject_cast<QSqlQueryModel *>(model))
|
||||||
m_dirModelTempDir.reset();
|
|
||||||
} else if (qobject_cast<QSqlQueryModel *>(model)) {
|
|
||||||
QSqlQuery q("DROP TABLE test");
|
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()
|
void ModelsToTest::setupDatabase()
|
||||||
|
@ -34,6 +34,8 @@
|
|||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include "emulationdetector.h"
|
#include "emulationdetector.h"
|
||||||
|
|
||||||
|
QT_WARNING_DISABLE_DEPRECATED
|
||||||
|
|
||||||
class tst_QDirModel : public QObject
|
class tst_QDirModel : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -107,8 +107,10 @@ private slots:
|
|||||||
void csMatchingOnCiSortedModel_data();
|
void csMatchingOnCiSortedModel_data();
|
||||||
void csMatchingOnCiSortedModel();
|
void csMatchingOnCiSortedModel();
|
||||||
|
|
||||||
|
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||||
void directoryModel_data();
|
void directoryModel_data();
|
||||||
void directoryModel();
|
void directoryModel();
|
||||||
|
#endif
|
||||||
void fileSystemModel_data();
|
void fileSystemModel_data();
|
||||||
void fileSystemModel();
|
void fileSystemModel();
|
||||||
|
|
||||||
@ -224,9 +226,14 @@ void tst_QCompleter::setSourceModel(ModelType type)
|
|||||||
parent->setText(completionColumn, QLatin1String("p2,c4p2"));
|
parent->setText(completionColumn, QLatin1String("p2,c4p2"));
|
||||||
break;
|
break;
|
||||||
case DIRECTORY_MODEL:
|
case DIRECTORY_MODEL:
|
||||||
|
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||||
|
QT_WARNING_PUSH
|
||||||
|
QT_WARNING_DISABLE_DEPRECATED
|
||||||
completer->setCsvCompletion(false);
|
completer->setCsvCompletion(false);
|
||||||
completer->setModel(new QDirModel(completer));
|
completer->setModel(new QDirModel(completer));
|
||||||
completer->setCompletionColumn(0);
|
completer->setCompletionColumn(0);
|
||||||
|
QT_WARNING_POP
|
||||||
|
#endif // QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||||
break;
|
break;
|
||||||
case FILESYSTEM_MODEL:
|
case FILESYSTEM_MODEL:
|
||||||
completer->setCsvCompletion(false);
|
completer->setCsvCompletion(false);
|
||||||
@ -590,6 +597,7 @@ void tst_QCompleter::csMatchingOnCiSortedModel()
|
|||||||
filter();
|
filter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||||
void tst_QCompleter::directoryModel_data()
|
void tst_QCompleter::directoryModel_data()
|
||||||
{
|
{
|
||||||
delete completer;
|
delete completer;
|
||||||
@ -639,6 +647,7 @@ void tst_QCompleter::directoryModel()
|
|||||||
#endif
|
#endif
|
||||||
filter();
|
filter();
|
||||||
}
|
}
|
||||||
|
#endif // QT_CONFIG(dirmodel) && QT_DEPRECATED_SINCE(5, 15)
|
||||||
|
|
||||||
void tst_QCompleter::fileSystemModel_data()
|
void tst_QCompleter::fileSystemModel_data()
|
||||||
{
|
{
|
||||||
@ -1057,15 +1066,15 @@ void tst_QCompleter::setters()
|
|||||||
delete completer;
|
delete completer;
|
||||||
completer = new CsvCompleter;
|
completer = new CsvCompleter;
|
||||||
QVERIFY(completer->popup() != nullptr);
|
QVERIFY(completer->popup() != nullptr);
|
||||||
QPointer<QDirModel> dirModel = new QDirModel(completer);
|
QPointer<QStandardItemModel> itemModel(new QStandardItemModel(1, 0, completer));
|
||||||
QAbstractItemModel *oldModel = completer->model();
|
QAbstractItemModel *oldModel = completer->model();
|
||||||
completer->setModel(dirModel);
|
completer->setModel(itemModel.data());
|
||||||
QVERIFY(completer->popup()->model() != oldModel);
|
QVERIFY(completer->popup()->model() != oldModel);
|
||||||
QCOMPARE(completer->popup()->model(), completer->completionModel());
|
QCOMPARE(completer->popup()->model(), completer->completionModel());
|
||||||
completer->setPopup(new QListView);
|
completer->setPopup(new QListView);
|
||||||
QCOMPARE(completer->popup()->model(), completer->completionModel());
|
QCOMPARE(completer->popup()->model(), completer->completionModel());
|
||||||
completer->setModel(new QStringListModel(completer));
|
completer->setModel(new QStringListModel(completer));
|
||||||
QVERIFY(dirModel == nullptr); // must have been deleted
|
QVERIFY(itemModel.isNull()); // must have been deleted
|
||||||
|
|
||||||
completer->setModel(nullptr);
|
completer->setModel(nullptr);
|
||||||
completer->setWidget(nullptr);
|
completer->setWidget(nullptr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user