summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorSamuel Gaist <samuel.gaist@idiap.ch>2018-07-19 00:22:15 +0200
committerSamuel Gaist <samuel.gaist@idiap.ch>2018-08-19 04:03:49 +0000
commit5dd9616f6d4f4b010958dc4869881f597f3d4d0c (patch)
tree8914377068ffa7860f8489e0f12d4c1166423b7a /src/widgets
parenta2c85bffbeaa027e98fb6c23b2d7919adc8d28b7 (diff)
Replace QRegExp by QRegularExpression in QFileSystemModel
[ChangeLog][Widgets][Dialogs] QFileSystemModel now uses QRegularExpression internally for wildcard matching. Note that QRegularExpression might not give the exact same result as QRegExp as its implementation follows strictly the glob patterns definition for wildcard expressions. Change-Id: I6ca893833ff7b5b7f678221bb9bc623fd17c1cfa Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/dialogs/qfilesystemmodel.cpp37
-rw-r--r--src/widgets/dialogs/qfilesystemmodel_p.h4
2 files changed, 22 insertions, 19 deletions
diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp
index 33b8b51216..b67335822b 100644
--- a/src/widgets/dialogs/qfilesystemmodel.cpp
+++ b/src/widgets/dialogs/qfilesystemmodel.cpp
@@ -48,6 +48,9 @@
#endif
#include <qapplication.h>
#include <QtCore/qcollator.h>
+#if QT_CONFIG(regularexpression)
+# include <QtCore/qregularexpression.h>
+#endif
#include <algorithm>
@@ -1580,7 +1583,7 @@ bool QFileSystemModel::nameFilterDisables() const
void QFileSystemModel::setNameFilters(const QStringList &filters)
{
// Prep the regexp's ahead of time
-#ifndef QT_NO_REGEXP
+#if QT_CONFIG(regularexpression)
Q_D(QFileSystemModel);
if (!d->bypassFilters.isEmpty()) {
@@ -1601,11 +1604,7 @@ void QFileSystemModel::setNameFilters(const QStringList &filters)
}
}
- d->nameFilters.clear();
- const Qt::CaseSensitivity caseSensitive =
- (filter() & QDir::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive;
- for (const auto &filter : filters)
- d->nameFilters << QRegExp(filter, caseSensitive, QRegExp::Wildcard);
+ d->nameFilters = filters;
d->forceSort = true;
d->delayedSort();
#endif
@@ -1616,16 +1615,12 @@ void QFileSystemModel::setNameFilters(const QStringList &filters)
*/
QStringList QFileSystemModel::nameFilters() const
{
+#if QT_CONFIG(regularexpression)
Q_D(const QFileSystemModel);
- QStringList filters;
-#ifndef QT_NO_REGEXP
- const int numNameFilters = d->nameFilters.size();
- filters.reserve(numNameFilters);
- for (int i = 0; i < numNameFilters; ++i) {
- filters << d->nameFilters.at(i).pattern();
- }
+ return d->nameFilters;
+#else
+ return QStringList();
#endif
- return filters;
}
/*!
@@ -2026,15 +2021,23 @@ bool QFileSystemModelPrivate::filtersAcceptsNode(const QFileSystemNode *node) co
*/
bool QFileSystemModelPrivate::passNameFilters(const QFileSystemNode *node) const
{
-#ifndef QT_NO_REGEXP
+#if QT_CONFIG(regularexpression)
if (nameFilters.isEmpty())
return true;
// Check the name regularexpression filters
if (!(node->isDir() && (filters & QDir::AllDirs))) {
+ const QRegularExpression::PatternOptions options =
+ (filters & QDir::CaseSensitive) ? QRegularExpression::NoPatternOption
+ : QRegularExpression::CaseInsensitiveOption;
+
for (const auto &nameFilter : nameFilters) {
- QRegExp copy = nameFilter;
- if (copy.exactMatch(node->fileName))
+ const QString wildcard = QLatin1String("\\A(?:")
+ + QRegularExpression::wildcardToRegularExpression(nameFilter)
+ + QLatin1String(")\\z");
+ QRegularExpression rx(wildcard, options);
+ QRegularExpressionMatch match = rx.match(node->fileName);
+ if (match.hasMatch())
return true;
}
return false;
diff --git a/src/widgets/dialogs/qfilesystemmodel_p.h b/src/widgets/dialogs/qfilesystemmodel_p.h
index 1e72bb69a8..9c432e1ae6 100644
--- a/src/widgets/dialogs/qfilesystemmodel_p.h
+++ b/src/widgets/dialogs/qfilesystemmodel_p.h
@@ -315,8 +315,8 @@ public:
//It enable a sort which is not recursive, it means
//we sort only what we see.
bool disableRecursiveSort;
-#ifndef QT_NO_REGEXP
- QList<QRegExp> nameFilters;
+#if QT_CONFIG(regularexpression)
+ QStringList nameFilters;
#endif
QHash<QString, QString> resolvedSymLinks;