QFileDialog: remove deprecated mode QFileDialog::DirectoryOnly

Change-Id: Ia06e80c1bbed3e5bb80793aebd0a4780eb81a36b
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Christian Ehrlicher 2020-06-24 22:12:09 +02:00
parent b0772b41c2
commit ab1e0961d4
5 changed files with 9 additions and 66 deletions

View File

@ -210,10 +210,6 @@ Q_GLOBAL_STATIC(QUrl, lastVisitedDir)
directory chooser.
\value ExistingFiles The names of zero or more existing files.
This value is obsolete since Qt 4.5:
\value DirectoryOnly Use \c Directory and setOption(ShowDirsOnly, true) instead.
\sa setFileMode()
*/
@ -598,13 +594,10 @@ void QFileDialogPrivate::retranslateWindowTitle()
return;
if (q->acceptMode() == QFileDialog::AcceptOpen) {
const QFileDialog::FileMode fileMode = q->fileMode();
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
if (fileMode == QFileDialog::DirectoryOnly || fileMode == QFileDialog::Directory)
if (fileMode == QFileDialog::Directory)
q->setWindowTitle(QFileDialog::tr("Find Directory"));
else
q->setWindowTitle(QFileDialog::tr("Open"));
QT_WARNING_POP
} else
q->setWindowTitle(QFileDialog::tr("Save As"));
@ -628,10 +621,6 @@ void QFileDialogPrivate::updateFileNameLabel()
setLabelTextControl(QFileDialog::FileName, options->labelText(QFileDialogOptions::FileName));
} else {
switch (q_func()->fileMode()) {
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
case QFileDialog::DirectoryOnly:
QT_WARNING_POP
case QFileDialog::Directory:
setLabelTextControl(QFileDialog::FileName, QFileDialog::tr("Directory:"));
break;
@ -659,10 +648,6 @@ void QFileDialogPrivate::updateOkButtonText(bool saveAsOnFolder)
return;
} else {
switch (q->fileMode()) {
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
case QFileDialog::DirectoryOnly:
QT_WARNING_POP
case QFileDialog::Directory:
setLabelTextControl(QFileDialog::Accept, QFileDialog::tr("&Choose"));
break;
@ -1713,13 +1698,6 @@ void QFileDialog::setFileMode(QFileDialog::FileMode mode)
{
Q_D(QFileDialog);
d->options->setFileMode(static_cast<QFileDialogOptions::FileMode>(mode));
// keep ShowDirsOnly option in sync with fileMode (BTW, DirectoryOnly is obsolete)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
setOption(ShowDirsOnly, mode == DirectoryOnly);
QT_WARNING_POP
if (!d->usingWidgets())
return;
@ -1736,14 +1714,11 @@ QT_WARNING_POP
// set filter
d->model->setFilter(d->filterForMode(filter()));
// setup file type for directory
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
if (mode == DirectoryOnly || mode == Directory) {
if (mode == Directory) {
d->qFileDialogUi->fileTypeCombo->clear();
d->qFileDialogUi->fileTypeCombo->addItem(tr("Directories"));
d->qFileDialogUi->fileTypeCombo->setEnabled(false);
}
QT_WARNING_POP
d->updateFileNameLabel();
d->updateOkButtonText();
d->qFileDialogUi->fileTypeCombo->setEnabled(!testOption(ShowDirsOnly));
@ -2648,10 +2623,7 @@ QUrl QFileDialog::getExistingDirectoryUrl(QWidget *parent,
args.parent = parent;
args.caption = caption;
args.directory = QFileDialogPrivate::workingDirectory(dir);
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
args.mode = (options & ShowDirsOnly ? DirectoryOnly : Directory);
QT_WARNING_POP
args.mode = Directory;
args.options = options;
QFileDialog dialog(args);
@ -2764,10 +2736,6 @@ void QFileDialog::accept()
}
switch (fileMode()) {
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
case DirectoryOnly:
QT_WARNING_POP
case Directory: {
QString fn = files.first();
QFileInfo info(fn);
@ -3712,10 +3680,6 @@ void QFileDialogPrivate::_q_updateOkButton()
isOpenDirectory = true;
} else {
switch (fileMode) {
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
case QFileDialog::DirectoryOnly:
QT_WARNING_POP
case QFileDialog::Directory: {
QString fn = files.first();
QModelIndex idx = model->index(fn);
@ -3807,15 +3771,11 @@ void QFileDialogPrivate::_q_enterDirectory(const QModelIndex &index)
const QFileDialog::FileMode fileMode = q->fileMode();
q->setDirectory(path);
emit q->directoryEntered(path);
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
if (fileMode == QFileDialog::Directory
|| fileMode == QFileDialog::DirectoryOnly) {
if (fileMode == QFileDialog::Directory) {
// ### find out why you have to do both of these.
lineEdit()->setText(QString());
lineEdit()->clear();
}
QT_WARNING_POP
} else {
// Do not accept when shift-clicking to multi-select a file in environments with single-click-activation (KDE)
if (!q->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, nullptr, qFileDialogUi->treeView)
@ -3907,10 +3867,7 @@ void QFileDialogPrivate::_q_selectionChanged()
{
const QFileDialog::FileMode fileMode = q_func()->fileMode();
const QModelIndexList indexes = qFileDialogUi->listView->selectionModel()->selectedRows();
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
bool stripDirs = (fileMode != QFileDialog::DirectoryOnly && fileMode != QFileDialog::Directory);
QT_WARNING_POP
bool stripDirs = fileMode != QFileDialog::Directory;
QStringList allFiles;
for (const auto &index : indexes) {
@ -3962,9 +3919,7 @@ void QFileDialogPrivate::_q_rowsInserted(const QModelIndex &parent)
void QFileDialogPrivate::_q_fileRenamed(const QString &path, const QString &oldName, const QString &newName)
{
const QFileDialog::FileMode fileMode = q_func()->fileMode();
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
if (fileMode == QFileDialog::Directory || fileMode == QFileDialog::DirectoryOnly) {
if (fileMode == QFileDialog::Directory) {
if (path == rootPath() && lineEdit()->text() == oldName)
lineEdit()->setText(newName);
}

View File

@ -73,8 +73,7 @@ class Q_WIDGETS_EXPORT QFileDialog : public QDialog
public:
enum ViewMode { Detail, List };
Q_ENUM(ViewMode)
enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles,
DirectoryOnly Q_DECL_ENUMERATOR_DEPRECATED_X("Use setOption(ShowDirsOnly, true) instead")};
enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles };
Q_ENUM(FileMode)
enum AcceptMode { AcceptOpen, AcceptSave };
Q_ENUM(AcceptMode)

View File

@ -292,7 +292,6 @@ void tst_QFiledialog::filesSelectedSignal_data()
QTest::newRow("any") << QFileDialog::AnyFile;
QTest::newRow("existing") << QFileDialog::ExistingFile;
QTest::newRow("directory") << QFileDialog::Directory;
QTest::newRow("directoryOnly") << QFileDialog::DirectoryOnly;
QTest::newRow("existingFiles") << QFileDialog::ExistingFiles;
}
@ -317,7 +316,7 @@ void tst_QFiledialog::filesSelectedSignal()
QModelIndex file;
for (int i = 0; i < listView->model()->rowCount(root); ++i) {
file = listView->model()->index(i, 0, root);
if (fileMode == QFileDialog::Directory || fileMode == QFileDialog::DirectoryOnly) {
if (fileMode == QFileDialog::Directory) {
if (listView->model()->hasChildren(file))
break;
} else {
@ -649,8 +648,6 @@ void tst_QFiledialog::fileMode()
QCOMPARE(fd.fileMode(), QFileDialog::ExistingFile);
fd.setFileMode(QFileDialog::Directory);
QCOMPARE(fd.fileMode(), QFileDialog::Directory);
fd.setFileMode(QFileDialog::DirectoryOnly);
QCOMPARE(fd.fileMode(), QFileDialog::DirectoryOnly);
fd.setFileMode(QFileDialog::ExistingFiles);
QCOMPARE(fd.fileMode(), QFileDialog::ExistingFiles);
}

View File

@ -1249,15 +1249,8 @@ void tst_QFileDialog2::QTBUG6558_showDirsOnly()
fd.setOption(QFileDialog::ShowDirsOnly, true);
QTRY_COMPARE(model->rowCount(model->index(dir.absolutePath())), 2);
fd.setFileMode(QFileDialog::DirectoryOnly);
QTRY_COMPARE(model->rowCount(model->index(dir.absolutePath())), 2);
QTRY_COMPARE(bool(fd.options() & QFileDialog::ShowDirsOnly), true);
fd.setFileMode(QFileDialog::AnyFile);
QTRY_COMPARE(model->rowCount(model->index(dir.absolutePath())), 3);
QTRY_COMPARE(bool(fd.options() & QFileDialog::ShowDirsOnly), false);
fd.setDirectory(QDir::homePath());
//We remove the dirs

View File

@ -65,8 +65,7 @@ const FlagData fileModeComboData[] =
{"AnyFile", QFileDialog::AnyFile},
{"ExistingFile", QFileDialog::ExistingFile},
{"ExistingFiles", QFileDialog::ExistingFiles},
{"Directory", QFileDialog::Directory},
{"DirectoryOnly", QFileDialog::DirectoryOnly}
{"Directory", QFileDialog::Directory}
};
static inline QPushButton *addButton(const QString &description, QGridLayout *layout,