diff options
Diffstat (limited to 'src/gui/dialogs/qfiledialog.cpp')
-rw-r--r-- | src/gui/dialogs/qfiledialog.cpp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index d952c34..3c388de 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -998,6 +998,24 @@ bool QFileDialog::isNameFilterDetailsVisible() const } +/* + Strip the filters by removing the details, e.g. (*.*). +*/ +QStringList qt_strip_filters(const QStringList &filters) +{ + QStringList strippedFilters; + QRegExp r(QString::fromLatin1(qt_file_dialog_filter_reg_exp)); + for (int i = 0; i < filters.count(); ++i) { + QString filterName; + int index = r.indexIn(filters[i]); + if (index >= 0) + filterName = r.cap(1); + strippedFilters.append(filterName.simplified()); + } + return strippedFilters; +} + + /*! \since 4.4 @@ -1024,20 +1042,11 @@ void QFileDialog::setNameFilters(const QStringList &filters) if (cleanedFilters.isEmpty()) return; - if (testOption(HideNameFilterDetails)) { - QStringList strippedFilters; - QRegExp r(QString::fromLatin1(qt_file_dialog_filter_reg_exp)); - for (int i = 0; i < cleanedFilters.count(); ++i) { - QString filterName; - int index = r.indexIn(cleanedFilters[i]); - if (index >= 0) - filterName = r.cap(1); - strippedFilters.append(filterName.simplified()); - } - d->qFileDialogUi->fileTypeCombo->addItems(strippedFilters); - } else { + if (testOption(HideNameFilterDetails)) + d->qFileDialogUi->fileTypeCombo->addItems(qt_strip_filters(cleanedFilters)); + else d->qFileDialogUi->fileTypeCombo->addItems(cleanedFilters); - } + d->_q_useNameFilter(0); } @@ -1088,8 +1097,12 @@ void QFileDialog::selectNameFilter(const QString &filter) d->selectNameFilter_sys(filter); return; } - - int i = d->qFileDialogUi->fileTypeCombo->findText(filter); + int i; + if (testOption(HideNameFilterDetails)) { + i = d->qFileDialogUi->fileTypeCombo->findText(qt_strip_filters(qt_make_filter_list(filter)).first()); + } else { + i = d->qFileDialogUi->fileTypeCombo->findText(filter); + } if (i >= 0) { d->qFileDialogUi->fileTypeCombo->setCurrentIndex(i); d->_q_useNameFilter(d->qFileDialogUi->fileTypeCombo->currentIndex()); |