Commit 267e7c63 authored by Elvis Angelaccio's avatar Elvis Angelaccio

Don't ignore initially selected mime type filter

Otherwise QFileDialog::selectMimeTypeFilter() has no effect
if called before show()/initializeDialog() (because the mime
filters are set only in initializeDialog()).

We also need to ignore the initiallySelectedNameFilter() (which is
implicitly set) if we have an initiallySelectedMimeTypeFilter().

Test Plan:
tests/qfiledialogtest --mimeTypeFilter application/json --mimeTypeFilter application/zip --selectMimeTypeFilter application/zip

Moved the show() call in the existing unit test, now it passes.

Reviewers: #plasma, dfaure

Differential Revision: https://phabricator.kde.org/D5957
parent 0dafb940
......@@ -104,11 +104,11 @@ private Q_SLOTS:
QFETCH(QStringList, mimeTypeFilters);
dialog.setMimeTypeFilters(mimeTypeFilters);
dialog.show();
QFETCH(QString, targetMimeTypeFilter);
dialog.selectMimeTypeFilter(targetMimeTypeFilter);
dialog.show();
QCOMPARE(dialog.selectedMimeTypeFilter(), targetMimeTypeFilter);
}
......
......@@ -315,9 +315,17 @@ void KDEPlatformFileDialogHelper::initializeDialog()
dialog->m_fileWidget->setFilter(qt2KdeFilter(nameFilters));
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
if (!options()->initiallySelectedMimeTypeFilter().isEmpty()) {
selectMimeTypeFilter(options()->initiallySelectedMimeTypeFilter());
} else if (!options()->initiallySelectedNameFilter().isEmpty()) {
selectNameFilter(options()->initiallySelectedNameFilter());
}
#else
if (!options()->initiallySelectedNameFilter().isEmpty()) {
selectNameFilter(options()->initiallySelectedNameFilter());
}
#endif
// overwrite option
if (options()->testOption(QFileDialogOptions::FileDialogOption::DontConfirmOverwrite)) {
......
......@@ -37,6 +37,7 @@ int main(int argc, char **argv)
parser.addOption(QCommandLineOption(QStringList(QStringLiteral("nameFilter")), QStringLiteral("Dialog nameFilter, e. g. 'cppfiles (*.cpp *.h *.hpp)', can be specified multiple times"), QStringLiteral("nameFilter"), QStringLiteral("Everything (*)")));
parser.addOption(QCommandLineOption(QStringList(QStringLiteral("mimeTypeFilter")), QStringLiteral("Dialog mimeTypeFilter, e. g. 'application/json', can be specified multiple times"), QStringLiteral("mimeTypeFilter")));
parser.addOption(QCommandLineOption(QStringList(QStringLiteral("selectNameFilter")), QStringLiteral("Initially selected nameFilter"), QStringLiteral("selectNameFilter")));
parser.addOption(QCommandLineOption(QStringList(QStringLiteral("selectMimeTypeFilter")), QStringLiteral("Initially selected mimeTypeFilter"), QStringLiteral("selectMimeTypeFilter")));
parser.addOption(QCommandLineOption(QStringList(QStringLiteral("selectFile")), QStringLiteral("Initially selected file"), QStringLiteral("filename")));
parser.addOption(QCommandLineOption(QStringList(QStringLiteral("selectDirectory")), QStringLiteral("Initially selected directory"), QStringLiteral("dirname")));
parser.addOption(QCommandLineOption(QStringList(QStringLiteral("modal")), QStringLiteral("Test modal dialog"), QStringLiteral("modality"), QStringLiteral("on")));
......@@ -86,8 +87,11 @@ int main(int argc, char **argv)
}
QString selectNameFilter = parser.value(QStringLiteral("selectNameFilter"));
QString selectMimeTypeFilter = parser.value(QStringLiteral("selectMimeTypeFilter"));
if (!selectNameFilter.isEmpty()) {
dialog.selectNameFilter(selectNameFilter);
} else if (!selectMimeTypeFilter.isEmpty()) {
dialog.selectMimeTypeFilter(selectMimeTypeFilter);
}
if (parser.value(QStringLiteral("confirmOverwrite")) == QStringLiteral("off")) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment