Commit 10dc30fa authored by Kai Koehne's avatar Kai Koehne
Browse files

Add support for 'paths' property in QmlFiles element

parent fc4d82d2
......@@ -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
......
......@@ -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;
......
......@@ -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());
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment