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 <morten.sorvig@nokia.com>
This commit is contained in:
parent
2d990ccba6
commit
66e68b79c2
@ -291,6 +291,9 @@ public:
|
||||
const QSharedPointer<QFileDialogOptions> &options() const;
|
||||
void setOptions(const QSharedPointer<QFileDialogOptions> &options);
|
||||
|
||||
static QStringList cleanFilterList(const QString &filter);
|
||||
static const char *filterRegExp;
|
||||
|
||||
Q_SIGNALS:
|
||||
void fileSelected(const QString &file);
|
||||
void filesSelected(const QStringList &files);
|
||||
|
@ -577,4 +577,18 @@ void QPlatformFileDialogHelper::setOptions(const QSharedPointer<QFileDialogOptio
|
||||
m_options = options;
|
||||
}
|
||||
|
||||
const char *QPlatformFileDialogHelper::filterRegExp =
|
||||
"^(.*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";
|
||||
|
||||
// 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
|
||||
|
@ -444,7 +444,7 @@ typedef QSharedPointer<QFileDialogOptions> 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<QFileDialogOptions> SharedPointerFileDialogOptions;
|
||||
{
|
||||
for (int i=0; i<mNameFilterDropDownList->size(); ++i) {
|
||||
if (mNameFilterDropDownList->at(i).startsWith(name))
|
||||
return QFileDialogPrivate::qt_clean_filter_list(mNameFilterDropDownList->at(i));
|
||||
return QPlatformFileDialogHelper::cleanFilterList(mNameFilterDropDownList->at(i));
|
||||
}
|
||||
return QStringList();
|
||||
}
|
||||
|
@ -401,9 +401,6 @@ QList<QUrl> 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)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user