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 <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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user