Commit 3984c057 authored by Kai Koehne's avatar Kai Koehne

QmlProject file format: Let filters recurse by default

E.g. "QmlFiles {}" now also monitors subdirectories by default, while
"QmlFiles { paths : ["bla.qml"] } does not.

Task-number: BAUHAUS-503
parent 8540effe
......@@ -6,7 +6,7 @@ namespace QmlProjectManager {
FileFilterBaseItem::FileFilterBaseItem(QObject *parent) :
QmlProjectContentItem(parent),
m_recursive(false)
m_recurse(RecurseDefault)
{
connect(&m_fsWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(updateFileList()));
connect(&m_fsWatcher, SIGNAL(fileChanged(QString)), this, SLOT(updateFileList()));
......@@ -58,15 +58,33 @@ void FileFilterBaseItem::setFilter(const QString &filter)
bool FileFilterBaseItem::recursive() const
{
return m_recursive;
bool recursive;
if (m_recurse == Recurse) {
recursive = true;
} else if (m_recurse == DoNotRecurse) {
recursive = false;
} else { // RecurseDefault
if (m_explicitFiles.isEmpty()) {
recursive = true;
} else {
recursive = false;
}
}
return recursive;
}
void FileFilterBaseItem::setRecursive(bool recursive)
void FileFilterBaseItem::setRecursive(bool recurse)
{
if (recursive == m_recursive)
return;
m_recursive = recursive;
updateFileList();
bool oldRecursive = recursive();
if (recurse) {
m_recurse = Recurse;
} else {
m_recurse = DoNotRecurse;
}
if (recurse != oldRecursive)
updateFileList();
}
QStringList FileFilterBaseItem::pathsProperty() const
......@@ -194,7 +212,7 @@ QSet<QString> FileFilterBaseItem::filesInSubTree(const QDir &rootDir, const QDir
}
}
if (m_recursive) {
if (recursive()) {
foreach (const QFileInfo &subDir, dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) {
fileSet += filesInSubTree(rootDir, QDir(subDir.absoluteFilePath()), parsedDirs);
}
......
......@@ -61,7 +61,15 @@ private:
QString m_filter;
QList<QRegExp> m_regExpList;
bool m_recursive;
enum RecursiveOption {
Recurse,
DoNotRecurse,
RecurseDefault // not set explicitly
};
RecursiveOption m_recurse;
QStringList m_explicitFiles;
QFileSystemWatcher m_fsWatcher;
......
......@@ -127,13 +127,13 @@ Core::GeneratedFiles QmlProjectApplicationWizard::generateFiles(const QWizard *w
out
//: Comment added to generated .qmlproject file
<< "// " << tr("File generated by QtCreator", "qmlproject Template") << endl
<< "/* " << tr("File generated by QtCreator", "qmlproject Template") << " */" << endl
<< endl
<< "import QmlProject 1.0" << endl
<< endl
<< "Project {" << endl
//: Comment added to generated .qmlproject file
<< " // " << tr("Scan current directory for .qml, .js, and image files", "qmlproject Template") << endl
<< " /* " << tr("Include .qml, .js, and image files from current directory and subdirectories", "qmlproject Template") << " */" << endl
<< " QmlFiles {" << endl
<< " directory: \".\"" << endl
<< " }" << endl
......@@ -144,13 +144,11 @@ Core::GeneratedFiles QmlProjectApplicationWizard::generateFiles(const QWizard *w
<< " directory: \".\"" << endl
<< " }" << endl
//: Comment added to generated .qmlproject file
<< " // List of plugin directories passed to QML runtime" << endl
//: Comment added to generated .qmlproject file
<< " /* " << tr("List of plugin directories passed to QML runtime", "qmlproject Template") << " */" << endl
<< " // importPaths: [ \" ../exampleplugin \" ]" << endl
<< "}" << endl;
}
Core::GeneratedFile generatedCreatorFile(creatorFileName);
generatedCreatorFile.setContents(projectContents);
Core::GeneratedFiles files;
......
......@@ -142,24 +142,25 @@ Core::GeneratedFiles QmlProjectImportWizard::generateFiles(const QWizard *w,
out
//: Comment added to generated .qmlproject file
<< "// " << tr("File generated by QtCreator", "qmlproject Template") << endl
<< "/* " << tr("File generated by QtCreator", "qmlproject Template") << " */" << endl
<< endl
<< "import QmlProject 1.0" << endl
<< endl
<< "Project {" << endl
<< " // " << tr("Scan current directory and subdirectories for .qml, .js, and image files", "qmlproject Template") << endl
//: Comment added to generated .qmlproject file
<< " /* " << tr("Include .qml, .js, and image files from current directory and subdirectories", "qmlproject Template") << " */" << endl
<< " QmlFiles {" << endl
<< " directory: \".\"" << endl
<< " recursive: true" << endl
<< " }" << endl
<< " JavaScriptFiles {" << endl
<< " directory: \".\"" << endl
<< " recursive: true" << endl
<< " }" << endl
<< " ImageFiles {" << endl
<< " directory: \".\"" << endl
<< " recursive: true" << endl
<< " }" << endl
//: Comment added to generated .qmlproject file
<< " /* " << tr("List of plugin directories passed to QML runtime", "qmlproject Template") << " */" << endl
<< " // importPaths: [ \" ../exampleplugin \" ]" << endl
<< "}" << endl;
}
Core::GeneratedFile generatedCreatorFile(creatorFileName);
......
......@@ -30,7 +30,7 @@ QString testDataDir = QLatin1String(SRCDIR "/data");
void TestProject::testFileFilter()
{
//
// search for qml files in local directory
// Search for qml files in directory + subdirectories
//
QString projectFile = QLatin1String(
"import QmlProject 1.0\n"
......@@ -53,18 +53,19 @@ void TestProject::testFileFilter()
project->setSourceDirectory(testDataDir);
QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml"
<< testDataDir + "/file2.qml");
<< testDataDir + "/file2.qml"
<< testDataDir + "/subdir/file3.qml");
QCOMPARE(project->files().toSet(), expectedFiles.toSet());
}
//
// search for all qml files in all subdirectories
// search for all qml files in directory
//
projectFile = QLatin1String(
"import QmlProject 1.0\n"
"Project {\n"
" QmlFiles {\n"
" recursive: true\n"
" recursive: false\n"
" }\n"
"}\n");
......@@ -82,8 +83,7 @@ void TestProject::testFileFilter()
project->setSourceDirectory(testDataDir);
QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml"
<< testDataDir + "/file2.qml"
<< testDataDir + "/subdir/file3.qml");
<< testDataDir + "/file2.qml");
QCOMPARE(project->files().toSet(), expectedFiles.toSet());
}
......@@ -121,6 +121,7 @@ void TestProject::testFileFilter()
"Project {\n"
" QmlFiles {\n"
" directory: \".\"\n"
" recursive: false\n"
" }"
" QmlFiles {\n"
" directory: \"subdir\"\n"
......
Markdown is supported
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