From 10dc30fa13348eb58bafba63136c95847e377a0a Mon Sep 17 00:00:00 2001 From: Kai Koehne <kai.koehne@nokia.com> Date: Wed, 20 Jan 2010 16:13:44 +0100 Subject: [PATCH] Add support for 'paths' property in QmlFiles element --- .../fileformat/filefilteritems.cpp | 26 +++++++++++++++- .../fileformat/filefilteritems.h | 10 ++++-- .../fileformat/tst_fileformat.cpp | 31 +++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp index bd9ddfd3e17..89a2fde5d48 100644 --- a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp +++ b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp @@ -65,6 +65,21 @@ void FileFilterBaseItem::setRecursive(bool recursive) updateFileList(); } +QString FileFilterBaseItem::pathsProperty() const +{ + return QStringList(m_explicitFiles.toList()).join(","); +} + +void FileFilterBaseItem::setPathsProperty(const QString &path) +{ + // we support listening paths both in an array, and in one string + m_explicitFiles.clear(); + foreach (const QString &subpath, path.split(QLatin1Char(','), QString::SkipEmptyParts)) { + m_explicitFiles += subpath.trimmed(); + } + updateFileList(); +} + QStringList FileFilterBaseItem::files() const { return m_files.toList(); @@ -89,7 +104,16 @@ void FileFilterBaseItem::updateFileList() return; QSet<QString> dirsToBeWatched; - const QSet<QString> newFiles = filesInSubTree(QDir(m_defaultDir), QDir(projectDir), &dirsToBeWatched); + QSet<QString> newFiles; + foreach (const QString &explicitPath, m_explicitFiles) { + if (QFileInfo(explicitPath).isAbsolute()) { + newFiles << explicitPath; + } else { + newFiles << QDir(projectDir).absoluteFilePath(explicitPath); + } + } + if (m_regex.isValid() && m_explicitFiles.isEmpty()) + newFiles += filesInSubTree(QDir(m_defaultDir), QDir(projectDir), &dirsToBeWatched); if (newFiles != m_files) { // update watched files diff --git a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h index d3abe526b25..e696b0bc9c3 100644 --- a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h +++ b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h @@ -16,8 +16,9 @@ class FileFilterBaseItem : public QmlProjectContentItem { Q_PROPERTY(QString directory READ directory WRITE setDirectory NOTIFY directoryChanged) Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged) + Q_PROPERTY(QString paths READ pathsProperty WRITE setPathsProperty NOTIFY pathsPropertyChanged) - Q_PROPERTY(QList<QString> files READ files NOTIFY filesChanged) + Q_PROPERTY(QStringList files READ files NOTIFY filesChanged DESIGNABLE false) public: FileFilterBaseItem(QObject *parent = 0); @@ -33,13 +34,17 @@ public: bool recursive() const; void setRecursive(bool recursive); + QString pathsProperty() const; + void setPathsProperty(const QString &path); + virtual QStringList files() const; signals: void directoryChanged(); void recursiveChanged(); - void filterChanged(); + void pathsPropertyChanged(); void filesChanged(); + void filterChanged(); private slots: void updateFileList(); @@ -55,6 +60,7 @@ private: QString m_filter; QRegExp m_regex; bool m_recursive; + QSet<QString> m_explicitFiles; QFileSystemWatcher m_fsWatcher; diff --git a/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp b/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp index 5a368480c38..a5ea548e44f 100644 --- a/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp +++ b/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp @@ -143,6 +143,37 @@ void TestProject::testQmlFileFilter() QCOMPARE(project->qmlFiles().size(), 3); QCOMPARE(project->qmlFiles().toSet(), expectedFiles.toSet()); } + + // + // include specific list + // + projectFile = QLatin1String( + "import QmlProject 1.0\n" + "Project {\n" + " QmlFiles {\n" + " paths: \"file1.qml,\n" + "file2.qml\"\n" + " }\n" + "}\n"); + + { + QmlEngine engine; + QmlComponent component(&engine); + component.setData(projectFile.toUtf8(), QUrl()); + if (!component.isReady()) + qDebug() << component.errorsString(); + QVERIFY(component.isReady()); + + QmlProjectItem *project = qobject_cast<QmlProjectItem*>(component.create()); + QVERIFY(project); + + project->setSourceDirectory(testDataDir); + + QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml" + << testDataDir + "/file2.qml"); + QCOMPARE(project->qmlFiles().toSet(), expectedFiles.toSet()); + } + } -- GitLab