diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h index d1e627d506..5865e0a27d 100644 --- a/src/gui/kernel/qplatformdialoghelper.h +++ b/src/gui/kernel/qplatformdialoghelper.h @@ -291,6 +291,9 @@ public: const QSharedPointer &options() const; void setOptions(const QSharedPointer &options); + static QStringList cleanFilterList(const QString &filter); + static const char *filterRegExp; + Q_SIGNALS: void fileSelected(const QString &file); void filesSelected(const QStringList &files); diff --git a/src/gui/kernel/qplatformdialoghelper_qpa.cpp b/src/gui/kernel/qplatformdialoghelper_qpa.cpp index f00437f69b..f71c5e58de 100644 --- a/src/gui/kernel/qplatformdialoghelper_qpa.cpp +++ b/src/gui/kernel/qplatformdialoghelper_qpa.cpp @@ -577,4 +577,18 @@ void QPlatformFileDialogHelper::setOptions(const QSharedPointer\\$%&=^~:\\|]*)\\)$"; + +// Makes a list of filters from a normal filter string "Image Files (*.png *.jpg)" +QStringList QPlatformFileDialogHelper::cleanFilterList(const QString &filter) +{ + QRegExp regexp(QString::fromLatin1(filterRegExp)); + QString f = filter; + int i = regexp.indexIn(f); + if (i >= 0) + f = regexp.cap(2); + return f.split(QLatin1Char(' '), QString::SkipEmptyParts); +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index 30f4cabfae..05149a8098 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -444,7 +444,7 @@ typedef QSharedPointer SharedPointerFileDialogOptions; - (QString)removeExtensions:(const QString &)filter { - QRegExp regExp(QT_PREPEND_NAMESPACE(QString::fromLatin1)(QT_PREPEND_NAMESPACE(QFileDialogPrivate::qt_file_dialog_filter_reg_exp))); + QRegExp regExp(QT_PREPEND_NAMESPACE(QString::fromLatin1)(QT_PREPEND_NAMESPACE(QPlatformFileDialogHelper::filterRegExp))); if (regExp.indexIn(filter) != -1) return regExp.cap(1).trimmed(); return filter; @@ -487,7 +487,7 @@ typedef QSharedPointer SharedPointerFileDialogOptions; { for (int i=0; isize(); ++i) { if (mNameFilterDropDownList->at(i).startsWith(name)) - return QFileDialogPrivate::qt_clean_filter_list(mNameFilterDropDownList->at(i)); + return QPlatformFileDialogHelper::cleanFilterList(mNameFilterDropDownList->at(i)); } return QStringList(); } diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 18b98b50f3..5b49aec243 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -401,9 +401,6 @@ QList QFileDialog::sidebarUrls() const static const qint32 QFileDialogMagic = 0xbe; -const char *QFileDialogPrivate::qt_file_dialog_filter_reg_exp = -"^(.*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$"; - /*! \since 4.3 Saves the state of the dialog's layout, history and current directory. @@ -1137,7 +1134,7 @@ bool QFileDialog::isNameFilterDetailsVisible() const QStringList qt_strip_filters(const QStringList &filters) { QStringList strippedFilters; - QRegExp r(QString::fromLatin1(QFileDialogPrivate::qt_file_dialog_filter_reg_exp)); + QRegExp r(QString::fromLatin1(QPlatformFileDialogHelper::filterRegExp)); for (int i = 0; i < filters.count(); ++i) { QString filterName; int index = r.indexIn(filters[i]); @@ -2993,17 +2990,6 @@ void QFileDialogPrivate::_q_goToDirectory(const QString &path) } } -// Makes a list of filters from a normal filter string "Image Files (*.png *.jpg)" -QStringList QFileDialogPrivate::qt_clean_filter_list(const QString &filter) -{ - QRegExp regexp(QString::fromLatin1(qt_file_dialog_filter_reg_exp)); - QString f = filter; - int i = regexp.indexIn(f); - if (i >= 0) - f = regexp.cap(2); - return f.split(QLatin1Char(' '), QString::SkipEmptyParts); -} - /*! \internal @@ -3020,7 +3006,7 @@ void QFileDialogPrivate::_q_useNameFilter(int index) } QString nameFilter = nameFilters.at(index); - QStringList newNameFilters = qt_clean_filter_list(nameFilter); + QStringList newNameFilters = QPlatformFileDialogHelper::cleanFilterList(nameFilter); if (q_func()->acceptMode() == QFileDialog::AcceptSave) { QString newNameFilterExtension; if (newNameFilters.count() > 0) diff --git a/src/widgets/dialogs/qfiledialog_p.h b/src/widgets/dialogs/qfiledialog_p.h index d7b5ce6527..4760c615cd 100644 --- a/src/widgets/dialogs/qfiledialog_p.h +++ b/src/widgets/dialogs/qfiledialog_p.h @@ -211,9 +211,6 @@ public: void _q_rowsInserted(const QModelIndex & parent); void _q_fileRenamed(const QString &path, const QString oldName, const QString newName); - static QStringList qt_clean_filter_list(const QString &filter); - static const char *qt_file_dialog_filter_reg_exp; - // layout #ifndef QT_NO_PROXYMODEL QAbstractProxyModel *proxyModel;