From: Sean Harmer Date: Wed, 23 May 2012 11:01:11 +0000 (+0100) Subject: QPA: Refactor QFileDialogPrivate::qt_clean_filter_list for QPA X-Git-Tag: 071012110112~819 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=66e68b79c276f33f9a161c9eb04a9416b4ec9d9d;p=profile%2Fivi%2Fqtbase.git QPA: Refactor QFileDialogPrivate::qt_clean_filter_list for QPA Allows QFileDialog and QPA plugins to access this helper function. Needed by the Cocoa and QNX plugins. This commit fixes up the Cocoa plugin. The QNX support will be in a follow-up commit. Change-Id: I8dd08a9f3dc27d85edd0dc9dad9629406c1e677a Reviewed-by: Morten Johan Sørvig --- diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h index d1e627d..5865e0a 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 f00437f..f71c5e5 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 30f4cab..05149a8 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 18b98b5..5b49aec 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 d7b5ce6..4760c61 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;