Don't show error message if file added to qmlproject is picked up

Check for the case that a new file to be added to a .qmlproject
is also automatically covered e.g. by a wildcard filter. In this
case we don't have to do anything.
This commit is contained in:
Kai Koehne
2010-02-17 11:20:35 +01:00
parent 24a225de40
commit b5646d35da
8 changed files with 115 additions and 7 deletions

View File

@@ -89,6 +89,47 @@ QStringList FileFilterBaseItem::files() const
return m_files.toList();
}
/**
Check whether filter matches a file path - regardless whether the file already exists or not.
@param filePath: absolute file path
*/
bool FileFilterBaseItem::matchesFile(const QString &filePath) const
{
foreach (const QString &explicitFile, m_explicitFiles) {
if (absolutePath(explicitFile) == filePath)
return true;
}
bool regexMatches = false;
const QString &fileName = QFileInfo(filePath).fileName();
foreach (const QRegExp &exp, m_regExpList) {
if (exp.exactMatch(fileName)) {
regexMatches = true;
break;
}
}
if (!regexMatches)
return false;
const QStringList watchedDirectories = m_fsWatcher.directories();
const QDir fileDir = QFileInfo(filePath).absoluteDir();
foreach (const QString &watchedDirectory, watchedDirectories) {
if (QDir(watchedDirectory) == fileDir)
return true;
}
return false;
}
QString FileFilterBaseItem::absolutePath(const QString &path) const
{
if (QFileInfo(path).isAbsolute())
return path;
return QDir(absoluteDir()).absoluteFilePath(path);
}
QString FileFilterBaseItem::absoluteDir() const
{
QString absoluteDir;
@@ -110,11 +151,7 @@ void FileFilterBaseItem::updateFileList()
QSet<QString> dirsToBeWatched;
QSet<QString> newFiles;
foreach (const QString &explicitPath, m_explicitFiles) {
if (QFileInfo(explicitPath).isAbsolute()) {
newFiles << explicitPath;
} else {
newFiles << QDir(projectDir).absoluteFilePath(explicitPath);
}
newFiles << absolutePath(explicitPath);
}
if (!m_regExpList.isEmpty() && m_explicitFiles.isEmpty())
newFiles += filesInSubTree(QDir(m_defaultDir), QDir(projectDir), &dirsToBeWatched);

View File

@@ -38,6 +38,7 @@ public:
void setPathsProperty(const QString &path);
virtual QStringList files() const;
bool matchesFile(const QString &filePath) const;
signals:
void directoryChanged();
@@ -50,6 +51,7 @@ private slots:
void updateFileList();
private:
QString absolutePath(const QString &path) const;
QString absoluteDir() const;
QSet<QString> filesInSubTree(const QDir &rootDir, const QDir &dir, QSet<QString> *parsedDirs = 0);

View File

@@ -115,6 +115,26 @@ QStringList QmlProjectItem::files() const
return files;
}
/**
Check whether the project would include a file path
- regardless whether the file already exists or not.
@param filePath: absolute file path to check
*/
bool QmlProjectItem::matchesFile(const QString &filePath) const
{
const Q_D(QmlProjectItem);
for (int i = 0; i < d->content.size(); ++i) {
QmlProjectContentItem *contentElement = d->content.at(i);
FileFilterBaseItem *fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement);
if (fileFilter) {
if (fileFilter->matchesFile(filePath))
return true;
}
}
return false;
}
} // namespace QmlProjectManager
QML_DEFINE_NOCREATE_TYPE(QmlProjectManager::QmlProjectContentItem)

View File

@@ -40,6 +40,7 @@ public:
void setLibraryPaths(const QStringList &paths);
QStringList files() const;
bool matchesFile(const QString &filePath) const;
signals:
void qmlFilesChanged();