diff options
author | Christian Stenger <christian.stenger@qt.io> | 2020-06-19 13:25:10 +0200 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2020-06-19 12:28:48 +0000 |
commit | 788926d624f1fb9feca9aab26e7188605bbc33a0 (patch) | |
tree | 0ad4afded56b3d6fae6b445cb21f8e5c4d87eeec | |
parent | 26a9f4a214892464653bf9e7bd5ef77651ee8161 (diff) | |
download | qt-creator-788926d624f1fb9feca9aab26e7188605bbc33a0.tar.gz |
QmlProjectManager: Replace QRegExp by QRegularExpression
While at it modernize a bit.
Task-number: QTCREATORBUG-24098
Change-Id: I5787466333e40e6e9bd3d9c77dc6267fffb970f8
Reviewed-by: hjk <hjk@qt.io>
-rw-r--r-- | src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp | 29 | ||||
-rw-r--r-- | src/plugins/qmlprojectmanager/fileformat/filefilteritems.h | 4 |
2 files changed, 16 insertions, 17 deletions
diff --git a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp index 82190ccde6..3801cb754d 100644 --- a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp +++ b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp @@ -33,7 +33,7 @@ #include <QDebug> #include <QDir> #include <QImageReader> -#include <QRegExp> +#include <QRegularExpression> namespace QmlProjectManager { @@ -100,7 +100,7 @@ void FileFilterBaseItem::setFilter(const QString &filter) m_regExpList.clear(); m_fileSuffixes.clear(); - foreach (const QString &pattern, filter.split(QLatin1Char(';'))) { + for (const QString &pattern : filter.split(QLatin1Char(';'))) { if (pattern.isEmpty()) continue; // decide if it's a canonical pattern like *.x @@ -113,7 +113,7 @@ void FileFilterBaseItem::setFilter(const QString &filter) continue; } } - m_regExpList << QRegExp(pattern, Qt::CaseInsensitive, QRegExp::Wildcard); + m_regExpList << QRegularExpression(QRegularExpression::wildcardToRegularExpression(pattern)); } updateFileList(); @@ -171,7 +171,7 @@ QStringList FileFilterBaseItem::files() const */ bool FileFilterBaseItem::matchesFile(const QString &filePath) const { - foreach (const QString &explicitFile, m_explicitFiles) { + for (const QString &explicitFile : m_explicitFiles) { if (absolutePath(explicitFile) == filePath) return true; } @@ -182,7 +182,7 @@ bool FileFilterBaseItem::matchesFile(const QString &filePath) const return false; const QDir fileDir = QFileInfo(filePath).absoluteDir(); - foreach (const QString &watchedDirectory, watchedDirectories()) { + for (const QString &watchedDirectory : watchedDirectories()) { if (QDir(watchedDirectory) == fileDir) return true; } @@ -225,9 +225,9 @@ void FileFilterBaseItem::updateFileListNow() QSet<QString> dirsToBeWatched; QSet<QString> newFiles; - foreach (const QString &explicitPath, m_explicitFiles) { + for (const QString &explicitPath : qAsConst(m_explicitFiles)) newFiles << absolutePath(explicitPath); - } + if ((!m_fileSuffixes.isEmpty() || !m_regExpList.isEmpty()) && m_explicitFiles.isEmpty()) newFiles += filesInSubTree(QDir(m_defaultDir), QDir(projectDir), &dirsToBeWatched); @@ -258,13 +258,13 @@ void FileFilterBaseItem::updateFileListNow() bool FileFilterBaseItem::fileMatches(const QString &fileName) const { - foreach (const QString &suffix, m_fileSuffixes) { + for (const QString &suffix : qAsConst(m_fileSuffixes)) { if (fileName.endsWith(suffix, Qt::CaseInsensitive)) return true; } - foreach (QRegExp filter, m_regExpList) { - if (filter.exactMatch(fileName)) + for (const QRegularExpression &filter : qAsConst(m_regExpList)) { + if (filter.match(fileName).hasMatch()) return true; } @@ -278,7 +278,7 @@ QSet<QString> FileFilterBaseItem::filesInSubTree(const QDir &rootDir, const QDir if (parsedDirs) parsedDirs->insert(dir.absolutePath()); - foreach (const QFileInfo &file, dir.entryInfoList(QDir::Files)) { + for (const QFileInfo &file : dir.entryInfoList(QDir::Files)) { const QString fileName = file.fileName(); if (fileMatches(fileName)) @@ -286,7 +286,7 @@ QSet<QString> FileFilterBaseItem::filesInSubTree(const QDir &rootDir, const QDir } if (recursive()) { - foreach (const QFileInfo &subDir, dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) { + for (const QFileInfo &subDir : dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) { fileSet += filesInSubTree(rootDir, QDir(subDir.absoluteFilePath()), parsedDirs); } } @@ -298,10 +298,9 @@ ImageFileFilterItem::ImageFileFilterItem(QObject *parent) { QString filter; // supported image formats according to - QList<QByteArray> extensions = QImageReader::supportedImageFormats(); - foreach (const QByteArray &extension, extensions) { + const QList<QByteArray> extensions = QImageReader::supportedImageFormats(); + for (const QByteArray &extension : extensions) filter.append(QString::fromLatin1("*.%1;").arg(QString::fromLatin1(extension))); - } setFilter(filter); } diff --git a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h index 827423e1e0..38ad7262fc 100644 --- a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h +++ b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h @@ -28,7 +28,7 @@ #include "qmlprojectitem.h" #include <QObject> -#include <QRegExp> +#include <QRegularExpression> #include <QSet> #include <QTimer> @@ -91,7 +91,7 @@ private: QString m_filter; // simple "*.png" patterns are stored in m_fileSuffixes, otherwise store in m_regExpList QList<QString> m_fileSuffixes; - QList<QRegExp> m_regExpList; + QList<QRegularExpression> m_regExpList; enum RecursiveOption { Recurse, |