forked from qt-creator/qt-creator
Add support for 'paths' property in QmlFiles element
This commit is contained in:
@@ -65,6 +65,21 @@ void FileFilterBaseItem::setRecursive(bool recursive)
|
|||||||
updateFileList();
|
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
|
QStringList FileFilterBaseItem::files() const
|
||||||
{
|
{
|
||||||
return m_files.toList();
|
return m_files.toList();
|
||||||
@@ -89,7 +104,16 @@ void FileFilterBaseItem::updateFileList()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QSet<QString> dirsToBeWatched;
|
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) {
|
if (newFiles != m_files) {
|
||||||
// update watched files
|
// update watched files
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ class FileFilterBaseItem : public QmlProjectContentItem {
|
|||||||
|
|
||||||
Q_PROPERTY(QString directory READ directory WRITE setDirectory NOTIFY directoryChanged)
|
Q_PROPERTY(QString directory READ directory WRITE setDirectory NOTIFY directoryChanged)
|
||||||
Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged)
|
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:
|
public:
|
||||||
FileFilterBaseItem(QObject *parent = 0);
|
FileFilterBaseItem(QObject *parent = 0);
|
||||||
@@ -33,13 +34,17 @@ public:
|
|||||||
bool recursive() const;
|
bool recursive() const;
|
||||||
void setRecursive(bool recursive);
|
void setRecursive(bool recursive);
|
||||||
|
|
||||||
|
QString pathsProperty() const;
|
||||||
|
void setPathsProperty(const QString &path);
|
||||||
|
|
||||||
virtual QStringList files() const;
|
virtual QStringList files() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void directoryChanged();
|
void directoryChanged();
|
||||||
void recursiveChanged();
|
void recursiveChanged();
|
||||||
void filterChanged();
|
void pathsPropertyChanged();
|
||||||
void filesChanged();
|
void filesChanged();
|
||||||
|
void filterChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateFileList();
|
void updateFileList();
|
||||||
@@ -55,6 +60,7 @@ private:
|
|||||||
QString m_filter;
|
QString m_filter;
|
||||||
QRegExp m_regex;
|
QRegExp m_regex;
|
||||||
bool m_recursive;
|
bool m_recursive;
|
||||||
|
QSet<QString> m_explicitFiles;
|
||||||
|
|
||||||
QFileSystemWatcher m_fsWatcher;
|
QFileSystemWatcher m_fsWatcher;
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,37 @@ void TestProject::testQmlFileFilter()
|
|||||||
QCOMPARE(project->qmlFiles().size(), 3);
|
QCOMPARE(project->qmlFiles().size(), 3);
|
||||||
QCOMPARE(project->qmlFiles().toSet(), expectedFiles.toSet());
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user