From 8577347446bf508454220293ebc26872c79dc37f Mon Sep 17 00:00:00 2001 From: Kai Koehne <kai.koehne@nokia.com> Date: Wed, 3 Feb 2010 08:59:38 +0100 Subject: [PATCH] Add libraryPaths array to Project element (.qmlproject format) Will be passed to qmlviewer with the "-L" option. Storing this in the .qmlproject file format itself (and not in the .user file) is useful in case the libraries are relative/part of the checkout that is shared between users/computers. --- .../components/stateseditor/stateslist.qml | 2 +- .../fileformat/qmlprojectitem.cpp | 18 +++++++++++ .../fileformat/qmlprojectitem.h | 5 +++ .../fileformat/tst_fileformat.cpp | 31 +++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/plugins/qmldesigner/components/stateseditor/stateslist.qml b/src/plugins/qmldesigner/components/stateseditor/stateslist.qml index 1237a672270..f4b11113196 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateslist.qml +++ b/src/plugins/qmldesigner/components/stateseditor/stateslist.qml @@ -433,7 +433,7 @@ Rectangle { // border Rectangle { anchors.fill:parent; - color:"Transparent"; + color:"#000000" border.width:1; border.color:"#8F8F8F"; } diff --git a/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.cpp b/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.cpp index c765acffc1b..6f0e1dcee80 100644 --- a/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.cpp +++ b/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.cpp @@ -9,6 +9,7 @@ class QmlProjectItemPrivate : public QObject { public: QString sourceDirectory; + QStringList libraryPaths; QList<QmlFileFilterItem*> qmlFileFilters() const; @@ -78,6 +79,23 @@ void QmlProjectItem::setSourceDirectory(const QString &directoryPath) emit sourceDirectoryChanged(); } +QStringList QmlProjectItem::libraryPaths() const +{ + const Q_D(QmlProjectItem); + return d->libraryPaths; +} + +void QmlProjectItem::setLibraryPaths(const QStringList &libraryPaths) +{ + Q_D(QmlProjectItem); + + if (d->libraryPaths == libraryPaths) + return; + + d->libraryPaths = libraryPaths; + emit libraryPathsChanged(); +} + /* Returns list of absolute paths */ QStringList QmlProjectItem::files() const { diff --git a/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.h b/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.h index 4e2bf780947..31ad175d05a 100644 --- a/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.h +++ b/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.h @@ -23,6 +23,7 @@ class QmlProjectItem : public QObject { Q_PROPERTY(QmlList<QmlProjectManager::QmlProjectContentItem*> *content READ content DESIGNABLE false) Q_PROPERTY(QString sourceDirectory READ sourceDirectory NOTIFY sourceDirectoryChanged) + Q_PROPERTY(QStringList libraryPaths READ libraryPaths WRITE setLibraryPaths NOTIFY libraryPathsChanged) Q_CLASSINFO("DefaultProperty", "content"); @@ -35,11 +36,15 @@ public: QString sourceDirectory() const; void setSourceDirectory(const QString &directoryPath); + QStringList libraryPaths() const; + void setLibraryPaths(const QStringList &paths); + QStringList files() const; signals: void qmlFilesChanged(); void sourceDirectoryChanged(); + void libraryPathsChanged(); protected: QmlProjectItemPrivate *d_ptr; diff --git a/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp b/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp index d46b86f5553..a12de28f1b3 100644 --- a/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp +++ b/tests/auto/qml/qmlprojectmanager/fileformat/tst_fileformat.cpp @@ -15,6 +15,7 @@ public: private slots: void testFileFilter(); + void testLibraryPaths(); }; TestProject::TestProject() @@ -204,6 +205,36 @@ void TestProject::testFileFilter() } } +void TestProject::testLibraryPaths() +{ + // + // search for qml files in local directory + // + QString projectFile = QLatin1String( + "import QmlProject 1.0\n" + "Project {\n" + " libraryPaths: [ \"../otherLibrary\", \"library\" ]\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 expectedPaths(QStringList() << "../otherLibrary" + << "library"); + QCOMPARE(project->libraryPaths().toSet(), expectedPaths.toSet()); + } +} + QTEST_MAIN(TestProject); #include "tst_fileformat.moc" -- GitLab