From 269506c99ca6d5197a6ef1684f60220384b38e94 Mon Sep 17 00:00:00 2001 From: Kai Koehne <kai.koehne@nokia.com> Date: Thu, 28 Jan 2010 17:12:07 +0100 Subject: [PATCH] Add new JavaScriptFiles & ImageFiles element to .qmlproject file format --- .../fileformat/filefilteritems.cpp | 22 ++++++++++ .../fileformat/filefilteritems.h | 18 +++++++++ .../fileformat/qmlprojectitem.cpp | 16 ++++---- .../fileformat/qmlprojectitem.h | 2 +- src/plugins/qmlprojectmanager/qmlproject.cpp | 4 +- .../fileformat/data/image.gif | 0 .../fileformat/data/script.js | 0 .../fileformat/tst_fileformat.cpp | 40 ++++++++++++++++--- 8 files changed, 85 insertions(+), 17 deletions(-) create mode 100644 tests/auto/qml/qmlprojectmanager/fileformat/data/image.gif create mode 100644 tests/auto/qml/qmlprojectmanager/fileformat/data/script.js diff --git a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.cpp index 89a2fde5d48..de9a7469d86 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 e696b0bc9c3..ed69fe92338 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 3a4de7f6347..c765acffc1b 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 47a1353bfab..4e2bf780947 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 8b1c28f289e..2a25f9a91bc 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 00000000000..e69de29bb2d 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 00000000000..e69de29bb2d diff --git a/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp b/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp index a5ea548e44f..78539bfae55 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()); + } } -- GitLab