forked from qt-creator/qt-creator
QmlProjectManager: Replace QRegExp by QRegularExpression
While at it modernize a bit. Task-number: QTCREATORBUG-24098 Change-Id: I5787466333e40e6e9bd3d9c77dc6267fffb970f8 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -33,7 +33,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
namespace QmlProjectManager {
|
namespace QmlProjectManager {
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ void FileFilterBaseItem::setFilter(const QString &filter)
|
|||||||
m_regExpList.clear();
|
m_regExpList.clear();
|
||||||
m_fileSuffixes.clear();
|
m_fileSuffixes.clear();
|
||||||
|
|
||||||
foreach (const QString &pattern, filter.split(QLatin1Char(';'))) {
|
for (const QString &pattern : filter.split(QLatin1Char(';'))) {
|
||||||
if (pattern.isEmpty())
|
if (pattern.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
// decide if it's a canonical pattern like *.x
|
// decide if it's a canonical pattern like *.x
|
||||||
@@ -113,7 +113,7 @@ void FileFilterBaseItem::setFilter(const QString &filter)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_regExpList << QRegExp(pattern, Qt::CaseInsensitive, QRegExp::Wildcard);
|
m_regExpList << QRegularExpression(QRegularExpression::wildcardToRegularExpression(pattern));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFileList();
|
updateFileList();
|
||||||
@@ -171,7 +171,7 @@ QStringList FileFilterBaseItem::files() const
|
|||||||
*/
|
*/
|
||||||
bool FileFilterBaseItem::matchesFile(const QString &filePath) const
|
bool FileFilterBaseItem::matchesFile(const QString &filePath) const
|
||||||
{
|
{
|
||||||
foreach (const QString &explicitFile, m_explicitFiles) {
|
for (const QString &explicitFile : m_explicitFiles) {
|
||||||
if (absolutePath(explicitFile) == filePath)
|
if (absolutePath(explicitFile) == filePath)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ bool FileFilterBaseItem::matchesFile(const QString &filePath) const
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QDir fileDir = QFileInfo(filePath).absoluteDir();
|
const QDir fileDir = QFileInfo(filePath).absoluteDir();
|
||||||
foreach (const QString &watchedDirectory, watchedDirectories()) {
|
for (const QString &watchedDirectory : watchedDirectories()) {
|
||||||
if (QDir(watchedDirectory) == fileDir)
|
if (QDir(watchedDirectory) == fileDir)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -225,9 +225,9 @@ void FileFilterBaseItem::updateFileListNow()
|
|||||||
|
|
||||||
QSet<QString> dirsToBeWatched;
|
QSet<QString> dirsToBeWatched;
|
||||||
QSet<QString> newFiles;
|
QSet<QString> newFiles;
|
||||||
foreach (const QString &explicitPath, m_explicitFiles) {
|
for (const QString &explicitPath : qAsConst(m_explicitFiles))
|
||||||
newFiles << absolutePath(explicitPath);
|
newFiles << absolutePath(explicitPath);
|
||||||
}
|
|
||||||
if ((!m_fileSuffixes.isEmpty() || !m_regExpList.isEmpty()) && m_explicitFiles.isEmpty())
|
if ((!m_fileSuffixes.isEmpty() || !m_regExpList.isEmpty()) && m_explicitFiles.isEmpty())
|
||||||
newFiles += filesInSubTree(QDir(m_defaultDir), QDir(projectDir), &dirsToBeWatched);
|
newFiles += filesInSubTree(QDir(m_defaultDir), QDir(projectDir), &dirsToBeWatched);
|
||||||
|
|
||||||
@@ -258,13 +258,13 @@ void FileFilterBaseItem::updateFileListNow()
|
|||||||
|
|
||||||
bool FileFilterBaseItem::fileMatches(const QString &fileName) const
|
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))
|
if (fileName.endsWith(suffix, Qt::CaseInsensitive))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (QRegExp filter, m_regExpList) {
|
for (const QRegularExpression &filter : qAsConst(m_regExpList)) {
|
||||||
if (filter.exactMatch(fileName))
|
if (filter.match(fileName).hasMatch())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +278,7 @@ QSet<QString> FileFilterBaseItem::filesInSubTree(const QDir &rootDir, const QDir
|
|||||||
if (parsedDirs)
|
if (parsedDirs)
|
||||||
parsedDirs->insert(dir.absolutePath());
|
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();
|
const QString fileName = file.fileName();
|
||||||
|
|
||||||
if (fileMatches(fileName))
|
if (fileMatches(fileName))
|
||||||
@@ -286,7 +286,7 @@ QSet<QString> FileFilterBaseItem::filesInSubTree(const QDir &rootDir, const QDir
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (recursive()) {
|
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);
|
fileSet += filesInSubTree(rootDir, QDir(subDir.absoluteFilePath()), parsedDirs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,10 +298,9 @@ ImageFileFilterItem::ImageFileFilterItem(QObject *parent)
|
|||||||
{
|
{
|
||||||
QString filter;
|
QString filter;
|
||||||
// supported image formats according to
|
// supported image formats according to
|
||||||
QList<QByteArray> extensions = QImageReader::supportedImageFormats();
|
const QList<QByteArray> extensions = QImageReader::supportedImageFormats();
|
||||||
foreach (const QByteArray &extension, extensions) {
|
for (const QByteArray &extension : extensions)
|
||||||
filter.append(QString::fromLatin1("*.%1;").arg(QString::fromLatin1(extension)));
|
filter.append(QString::fromLatin1("*.%1;").arg(QString::fromLatin1(extension)));
|
||||||
}
|
|
||||||
setFilter(filter);
|
setFilter(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
#include "qmlprojectitem.h"
|
#include "qmlprojectitem.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ private:
|
|||||||
QString m_filter;
|
QString m_filter;
|
||||||
// simple "*.png" patterns are stored in m_fileSuffixes, otherwise store in m_regExpList
|
// simple "*.png" patterns are stored in m_fileSuffixes, otherwise store in m_regExpList
|
||||||
QList<QString> m_fileSuffixes;
|
QList<QString> m_fileSuffixes;
|
||||||
QList<QRegExp> m_regExpList;
|
QList<QRegularExpression> m_regExpList;
|
||||||
|
|
||||||
enum RecursiveOption {
|
enum RecursiveOption {
|
||||||
Recurse,
|
Recurse,
|
||||||
|
Reference in New Issue
Block a user