diff --git a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp index 89a2fde5d482f4da7339399f6d263c8456c95a3f..de9a7469d86162bb4197e177f061275fbf7be83b 100644 --- a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp +++ b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp @@ -1,5 +1,6 @@ #include "filefilteritems.h" #include <qdebug.h> +#include <QtGui/QImageReader> namespace QmlProjectManager { @@ -167,6 +168,27 @@ QmlFileFilterItem::QmlFileFilterItem(QObject *parent) setFilter(QLatin1String("*.qml")); } + +JsFileFilterItem::JsFileFilterItem(QObject *parent) + : FileFilterBaseItem(parent) +{ + setFilter(QLatin1String("*.js")); +} + +ImageFileFilterItem::ImageFileFilterItem(QObject *parent) + : FileFilterBaseItem(parent) +{ + QString filter; + // supported image formats according to + QList<QByteArray> extensions = QImageReader::supportedImageFormats(); + foreach (const QByteArray &extension, extensions) { + filter.append(QString("*.%1;").arg(QString::fromAscii(extension))); + } + setFilter(filter); +} + } // namespace QmlProjectManager QML_DEFINE_TYPE(QmlProject,1,0,QmlFiles,QmlProjectManager::QmlFileFilterItem) +QML_DEFINE_TYPE(QmlProject,1,0,JavaScriptFiles,QmlProjectManager::JsFileFilterItem) +QML_DEFINE_TYPE(QmlProject,1,0,ImageFiles,QmlProjectManager::ImageFileFilterItem) diff --git a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h index e696b0bc9c3dba3c5bcea0e363f46e0fcdf39bb1..ed69fe923389363d8a16694c4624262fcb76c59f 100644 --- a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h +++ b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h @@ -76,8 +76,26 @@ public: QmlFileFilterItem(QObject *parent = 0); }; +class JsFileFilterItem : public FileFilterBaseItem { + Q_OBJECT + Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged()) + +public: + JsFileFilterItem(QObject *parent = 0); +}; + +class ImageFileFilterItem : public FileFilterBaseItem { + Q_OBJECT + Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged()) + +public: + ImageFileFilterItem(QObject *parent = 0); +}; + } // namespace QmlProjectManager QML_DECLARE_TYPE(QmlProjectManager::QmlFileFilterItem) +QML_DECLARE_TYPE(QmlProjectManager::JsFileFilterItem) +QML_DECLARE_TYPE(QmlProjectManager::ImageFileFilterItem) #endif // FILEFILTERITEMS_HPROJECTITEM_H diff --git a/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.cpp b/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.cpp index 3a4de7f6347f02353642bcc6a1b516d4b561987e..c765acffc1b8ae8a71e36eb0c63cab826a189f27 100644 --- a/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.cpp +++ b/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.cpp @@ -79,22 +79,22 @@ void QmlProjectItem::setSourceDirectory(const QString &directoryPath) } /* Returns list of absolute paths */ -QStringList QmlProjectItem::qmlFiles() const +QStringList QmlProjectItem::files() const { const Q_D(QmlProjectItem); - QStringList qmlFiles; + QStringList files; for (int i = 0; i < d->content.size(); ++i) { QmlProjectContentItem *contentElement = d->content.at(i); - QmlFileFilterItem *qmlFileFilter = qobject_cast<QmlFileFilterItem*>(contentElement); - if (qmlFileFilter) { - foreach (const QString &file, qmlFileFilter->files()) { - if (!qmlFiles.contains(file)) - qmlFiles << file; + FileFilterBaseItem *fileFilter = qobject_cast<FileFilterBaseItem*>(contentElement); + if (fileFilter) { + foreach (const QString &file, fileFilter->files()) { + if (!files.contains(file)) + files << file; } } } - return qmlFiles; + return files; } } // namespace QmlProjectManager diff --git a/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.h b/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.h index 47a1353bfabc2a80420405e3642dc8e6028b6999..4e2bf780947a4d03ceed668857ff050c91dee41c 100644 --- a/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.h +++ b/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.h @@ -35,7 +35,7 @@ public: QString sourceDirectory() const; void setSourceDirectory(const QString &directoryPath); - QStringList qmlFiles() const; + QStringList files() const; signals: void qmlFilesChanged(); diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp index 8b1c28f289e4f3921636980bae768b6beda98906..2a25f9a91bc458bb049558aee12c39328b4cfe58 100644 --- a/src/plugins/qmlprojectmanager/qmlproject.cpp +++ b/src/plugins/qmlprojectmanager/qmlproject.cpp @@ -155,7 +155,7 @@ void QmlProject::parseProject(RefreshOptions options) } if (m_projectItem) { m_projectItem.data()->setSourceDirectory(projectDir().path()); - m_modelManager->updateSourceFiles(m_projectItem.data()->qmlFiles()); + m_modelManager->updateSourceFiles(m_projectItem.data()->files()); } m_rootNode->refresh(); } @@ -196,7 +196,7 @@ QStringList QmlProject::files() const { QStringList files; if (m_projectItem) { - files = m_projectItem.data()->qmlFiles(); + files = m_projectItem.data()->files(); } else { files = m_files; } diff --git a/tests/auto/qml/qmlprojectmanager/fileformat/data/image.gif b/tests/auto/qml/qmlprojectmanager/fileformat/data/image.gif new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/auto/qml/qmlprojectmanager/fileformat/data/script.js b/tests/auto/qml/qmlprojectmanager/fileformat/data/script.js new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp b/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp index a5ea548e44f8b61f61b2a4aebec5ec8cc86f0fcb..78539bfae558028ecbbcceff3f9b8e979fa685eb 100644 --- a/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp +++ b/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp @@ -51,7 +51,7 @@ void TestProject::testQmlFileFilter() QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml" << testDataDir + "/file2.qml"); - QCOMPARE(project->qmlFiles().toSet(), expectedFiles.toSet()); + QCOMPARE(project->files().toSet(), expectedFiles.toSet()); } // @@ -81,7 +81,7 @@ void TestProject::testQmlFileFilter() QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml" << testDataDir + "/file2.qml" << testDataDir + "/subdir/file3.qml"); - QCOMPARE(project->qmlFiles().toSet(), expectedFiles.toSet()); + QCOMPARE(project->files().toSet(), expectedFiles.toSet()); } // @@ -107,7 +107,7 @@ void TestProject::testQmlFileFilter() project->setSourceDirectory(testDataDir); QStringList expectedFiles(QStringList() << testDataDir + "/subdir/file3.qml"); - QCOMPARE(project->qmlFiles().toSet(), expectedFiles.toSet()); + QCOMPARE(project->files().toSet(), expectedFiles.toSet()); } // @@ -140,8 +140,8 @@ void TestProject::testQmlFileFilter() QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml" << testDataDir + "/file2.qml" << testDataDir + "/subdir/file3.qml"); - QCOMPARE(project->qmlFiles().size(), 3); - QCOMPARE(project->qmlFiles().toSet(), expectedFiles.toSet()); + QCOMPARE(project->files().size(), 3); + QCOMPARE(project->files().toSet(), expectedFiles.toSet()); } // @@ -171,9 +171,37 @@ void TestProject::testQmlFileFilter() QStringList expectedFiles(QStringList() << testDataDir + "/file1.qml" << testDataDir + "/file2.qml"); - QCOMPARE(project->qmlFiles().toSet(), expectedFiles.toSet()); + QCOMPARE(project->files().toSet(), expectedFiles.toSet()); } + // + // include specific list + // + projectFile = QLatin1String( + "import QmlProject 1.0\n" + "Project {\n" + " ImageFiles {\n" + " directory: \".\"\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 + "/image.gif"); + qDebug() << project->files().toSet() << expectedFiles.toSet(); + QCOMPARE(project->files().toSet(), expectedFiles.toSet()); + } }