Changeset View
Changeset View
Standalone View
Standalone View
tests/qfiledialogtest.cpp
Show All 29 Lines | 27 | { | |||
---|---|---|---|---|---|
30 | QCommandLineParser parser; | 30 | QCommandLineParser parser; | ||
31 | parser.addHelpOption(); | 31 | parser.addHelpOption(); | ||
32 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("staticFunction")), QStringLiteral("Test one of the static convenience function: 'getOpenFileUrl', 'getExistingDirectory'"), QStringLiteral("function name"))); | 32 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("staticFunction")), QStringLiteral("Test one of the static convenience function: 'getOpenFileUrl', 'getExistingDirectory'"), QStringLiteral("function name"))); | ||
33 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("acceptMode")), QStringLiteral("File dialog acceptMode: 'open' or 'save'"), QStringLiteral("type"), QStringLiteral("open"))); | 33 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("acceptMode")), QStringLiteral("File dialog acceptMode: 'open' or 'save'"), QStringLiteral("type"), QStringLiteral("open"))); | ||
34 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("confirmOverwrite")), QStringLiteral("Test overwrite option: 'on' or 'off'"), QStringLiteral("option"), QStringLiteral("on"))); | 34 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("confirmOverwrite")), QStringLiteral("Test overwrite option: 'on' or 'off'"), QStringLiteral("option"), QStringLiteral("on"))); | ||
35 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("nativeDialog")), QStringLiteral("Use the platform native dialog: 'on' or 'off'"), QStringLiteral("option"), QStringLiteral("on"))); | 35 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("nativeDialog")), QStringLiteral("Use the platform native dialog: 'on' or 'off'"), QStringLiteral("option"), QStringLiteral("on"))); | ||
36 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("fileMode")), QStringLiteral("File dialog fileMode: 'AnyFile' or 'ExistingFile' or 'Directory' or 'ExistingFiles'"), QStringLiteral("type"))); | 36 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("fileMode")), QStringLiteral("File dialog fileMode: 'AnyFile' or 'ExistingFile' or 'Directory' or 'ExistingFiles'"), QStringLiteral("type"))); | ||
37 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("nameFilter")), QStringLiteral("Dialog nameFilter, e. g. 'cppfiles (*.cpp *.h *.hpp)', can be specified multiple times"), QStringLiteral("nameFilter"), QStringLiteral("Everything (*)"))); | 37 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("nameFilter")), QStringLiteral("Dialog nameFilter, e. g. 'cppfiles (*.cpp *.h *.hpp)', can be specified multiple times"), QStringLiteral("nameFilter"), QStringLiteral("Everything (*)"))); | ||
38 | // add option mimeTypeFilter later | 38 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("mimeTypeFilter")), QStringLiteral("Dialog mimeTypeFilter, e. g. 'application/json', can be specified multiple times"), QStringLiteral("mimeTypeFilter"))); | ||
39 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("selectNameFilter")), QStringLiteral("Initially selected nameFilter"), QStringLiteral("selectNameFilter"))); | 39 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("selectNameFilter")), QStringLiteral("Initially selected nameFilter"), QStringLiteral("selectNameFilter"))); | ||
40 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("selectFile")), QStringLiteral("Initially selected file"), QStringLiteral("filename"))); | 40 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("selectFile")), QStringLiteral("Initially selected file"), QStringLiteral("filename"))); | ||
41 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("selectDirectory")), QStringLiteral("Initially selected directory"), QStringLiteral("dirname"))); | 41 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("selectDirectory")), QStringLiteral("Initially selected directory"), QStringLiteral("dirname"))); | ||
42 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("modal")), QStringLiteral("Test modal dialog"), QStringLiteral("modality"), QStringLiteral("on"))); | 42 | parser.addOption(QCommandLineOption(QStringList(QStringLiteral("modal")), QStringLiteral("Test modal dialog"), QStringLiteral("modality"), QStringLiteral("on"))); | ||
43 | parser.process(app); | 43 | parser.process(app); | ||
44 | 44 | | |||
45 | const QString staticFunction = parser.value(QStringLiteral("staticFunction")); | 45 | const QString staticFunction = parser.value(QStringLiteral("staticFunction")); | ||
46 | if (staticFunction == QLatin1String("getExistingDirectory")) { | 46 | if (staticFunction == QLatin1String("getExistingDirectory")) { | ||
Show All 28 Lines | |||||
75 | QStringList nameFilterList = parser.values(QStringLiteral("nameFilter")); | 75 | QStringList nameFilterList = parser.values(QStringLiteral("nameFilter")); | ||
76 | if (nameFilterList.size() == 1) { | 76 | if (nameFilterList.size() == 1) { | ||
77 | dialog.setNameFilter(nameFilterList.first()); | 77 | dialog.setNameFilter(nameFilterList.first()); | ||
78 | } | 78 | } | ||
79 | else { | 79 | else { | ||
80 | dialog.setNameFilters(nameFilterList); | 80 | dialog.setNameFilters(nameFilterList); | ||
81 | } | 81 | } | ||
82 | 82 | | |||
83 | const auto mimeFilterList = parser.values(QStringLiteral("mimeTypeFilter")); | ||||
84 | if (!mimeFilterList.isEmpty()) { | ||||
85 | dialog.setMimeTypeFilters(mimeFilterList); | ||||
86 | } | ||||
87 | | ||||
83 | QString selectNameFilter = parser.value(QStringLiteral("selectNameFilter")); | 88 | QString selectNameFilter = parser.value(QStringLiteral("selectNameFilter")); | ||
84 | if (!selectNameFilter.isEmpty()) { | 89 | if (!selectNameFilter.isEmpty()) { | ||
85 | dialog.selectNameFilter(selectNameFilter); | 90 | dialog.selectNameFilter(selectNameFilter); | ||
86 | } | 91 | } | ||
87 | 92 | | |||
88 | if (parser.value(QStringLiteral("confirmOverwrite")) == QStringLiteral("off")) { | 93 | if (parser.value(QStringLiteral("confirmOverwrite")) == QStringLiteral("off")) { | ||
89 | dialog.setOption(QFileDialog::DontConfirmOverwrite, true); | 94 | dialog.setOption(QFileDialog::DontConfirmOverwrite, true); | ||
90 | } | 95 | } | ||
Show All 11 Lines | 105 | if (parser.value(QStringLiteral("modal")) == QStringLiteral("off")) { | |||
102 | ret = app.exec(); | 107 | ret = app.exec(); | ||
103 | } else { | 108 | } else { | ||
104 | ret = dialog.exec(); | 109 | ret = dialog.exec(); | ||
105 | } | 110 | } | ||
106 | 111 | | |||
107 | if (dialog.result() == QDialog::Accepted) { | 112 | if (dialog.result() == QDialog::Accepted) { | ||
108 | qDebug() << "selected files" << dialog.selectedFiles(); | 113 | qDebug() << "selected files" << dialog.selectedFiles(); | ||
109 | qDebug() << "selected urls" << dialog.selectedUrls(); | 114 | qDebug() << "selected urls" << dialog.selectedUrls(); | ||
110 | qDebug() << "selected name nameFilter" << dialog.selectedNameFilter(); | 115 | #if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0) | ||
116 | qDebug() << "selected mime type filter" << dialog.selectedMimeTypeFilter(); | ||||
dfaure: this code looks ok to me, but it will hit the above assert when the -mimeTypeFilter option is… | |||||
elvisangelaccio: Good catch, I'll drop the assert then. | |||||
The problem is that if isMimeFilter() is false we get a name filter instead of a mimetype, which is not expected. if (m_fileWidget->filterWidget()->isMimeFilter()) { return m_fileWidget->filterWidget()->currentFilter(); } else { // detect mimetype of selectedFiles() using QMimeDatabase ... } Does it make sense? elvisangelaccio: The problem is that if `isMimeFilter()` is false we get a name filter instead of a mimetype… | |||||
117 | #endif | ||||
111 | } | 118 | } | ||
119 | | ||||
120 | qDebug() << "mime type filter(s):" << dialog.mimeTypeFilters(); | ||||
121 | | ||||
112 | return ret; | 122 | return ret; | ||
113 | } | 123 | } |
this code looks ok to me, but it will hit the above assert when the -mimeTypeFilter option is absent, no?