summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/qmlprojectmanager/fileformat/filefilteritems.h8
-rw-r--r--src/plugins/qmlprojectmanager/fileformat/qmlprojectfileformat.cpp106
-rw-r--r--src/plugins/qmlprojectmanager/fileformat/qmlprojectfileformat.h9
-rw-r--r--src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.cpp12
-rw-r--r--src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.h11
-rw-r--r--src/plugins/qmlprojectmanager/qmlproject.cpp30
-rw-r--r--src/plugins/qmlprojectmanager/qmlproject.h3
-rw-r--r--src/plugins/qmlprojectmanager/qmlprojectmanager.pro2
-rw-r--r--src/plugins/qmlprojectmanager/qmlprojectplugin.cpp2
9 files changed, 119 insertions, 64 deletions
diff --git a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h
index b3d2093a01..7f5cea6423 100644
--- a/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h
+++ b/src/plugins/qmlprojectmanager/fileformat/filefilteritems.h
@@ -36,8 +36,6 @@
#include <QSet>
#include <QTimer>
-#include <qdeclarative.h>
-
QT_FORWARD_DECLARE_CLASS(QDir)
namespace Utils {
@@ -181,10 +179,4 @@ public:
} // namespace QmlProjectManager
-QML_DECLARE_TYPE(QmlProjectManager::QmlFileFilterItem)
-QML_DECLARE_TYPE(QmlProjectManager::JsFileFilterItem)
-QML_DECLARE_TYPE(QmlProjectManager::ImageFileFilterItem)
-QML_DECLARE_TYPE(QmlProjectManager::CssFileFilterItem)
-QML_DECLARE_TYPE(QmlProjectManager::OtherFileFilterItem)
-
#endif // FILEFILTERITEMS_HPROJECTITEM_H
diff --git a/src/plugins/qmlprojectmanager/fileformat/qmlprojectfileformat.cpp b/src/plugins/qmlprojectmanager/fileformat/qmlprojectfileformat.cpp
index a78b35cf65..b23f090e8b 100644
--- a/src/plugins/qmlprojectmanager/fileformat/qmlprojectfileformat.cpp
+++ b/src/plugins/qmlprojectmanager/fileformat/qmlprojectfileformat.cpp
@@ -30,26 +30,102 @@
#include "qmlprojectfileformat.h"
#include "qmlprojectitem.h"
#include "filefilteritems.h"
+#include <qmljs/qmljssimplereader.h>
-#include <qdeclarative.h>
+enum {
+ debug = false
+};
+
+namespace {
+
+void setupFileFilterItem(QmlProjectManager::FileFilterBaseItem *fileFilterItem, const QmlJS::SimpleReaderNode::Ptr &node)
+{
+ const QVariant directoryProperty = node->property(QLatin1String("directory"));
+ if (directoryProperty.isValid())
+ fileFilterItem->setDirectory(directoryProperty.toString());
+
+ const QVariant recursiveProperty = node->property(QLatin1String("recursive"));
+ if (recursiveProperty.isValid())
+ fileFilterItem->setRecursive(recursiveProperty.toBool());
+
+ const QVariant pathsProperty = node->property(QLatin1String("paths"));
+ if (pathsProperty.isValid())
+ fileFilterItem->setPathsProperty(pathsProperty.toStringList());
+
+ if (debug)
+ qDebug() << "directory:" << directoryProperty << "recursive" << recursiveProperty << "paths" << pathsProperty;
+}
+
+} //namespace
namespace QmlProjectManager {
-void QmlProjectFileFormat::registerDeclarativeTypes()
+QmlProjectItem *QmlProjectFileFormat::parseProjectFile(const QString &fileName, QString *errorMessage)
{
- qmlRegisterType<QmlProjectManager::QmlProjectContentItem>();
- qmlRegisterType<QmlProjectManager::QmlProjectItem>("QmlProject",1,0,"Project");
- qmlRegisterType<QmlProjectManager::QmlProjectItem>("QmlProject",1,1,"Project");
-
- qmlRegisterType<QmlProjectManager::QmlFileFilterItem>("QmlProject",1,0,"QmlFiles");
- qmlRegisterType<QmlProjectManager::QmlFileFilterItem>("QmlProject",1,1,"QmlFiles");
- qmlRegisterType<QmlProjectManager::JsFileFilterItem>("QmlProject",1,0,"JavaScriptFiles");
- qmlRegisterType<QmlProjectManager::JsFileFilterItem>("QmlProject",1,1,"JavaScriptFiles");
- qmlRegisterType<QmlProjectManager::ImageFileFilterItem>("QmlProject",1,0,"ImageFiles");
- qmlRegisterType<QmlProjectManager::ImageFileFilterItem>("QmlProject",1,1,"ImageFiles");
- qmlRegisterType<QmlProjectManager::CssFileFilterItem>("QmlProject",1,0,"CssFiles");
- qmlRegisterType<QmlProjectManager::CssFileFilterItem>("QmlProject",1,1,"CssFiles");
- qmlRegisterType<QmlProjectManager::OtherFileFilterItem>("QmlProject",1,1,"Files");
+ QmlJS::SimpleReader simpleQmlJSReader;
+
+ const QmlJS::SimpleReaderNode::Ptr rootNode = simpleQmlJSReader.readFile(fileName);
+
+ if (!simpleQmlJSReader.errors().isEmpty() || !rootNode->isValid()) {
+ qWarning() << "unable to parse:" << fileName;
+ qWarning() << simpleQmlJSReader.errors();
+ if (errorMessage)
+ *errorMessage = simpleQmlJSReader.errors().join(QLatin1String(", "));
+ return 0;
+ }
+
+ if (rootNode->name() == QLatin1String("Project")) {
+ QmlProjectItem *projectItem = new QmlProjectItem();
+
+ const QVariant mainFileProperty = rootNode->property(QLatin1String("mainFile"));
+ if (mainFileProperty.isValid())
+ projectItem->setMainFile(mainFileProperty.toString());
+
+ const QVariant importPathsProperty = rootNode->property(QLatin1String("importPaths"));
+ if (importPathsProperty.isValid())
+ projectItem->setImportPaths(importPathsProperty.toStringList());
+
+ if (debug) {
+ qDebug() << "importPath:" << importPathsProperty << "mainFile:" << mainFileProperty;
+ }
+
+ foreach (const QmlJS::SimpleReaderNode::Ptr &childNode, rootNode->children()) {
+ if (childNode->name() == QLatin1String("QmlFiles")) {
+ if (debug)
+ qDebug() << "QmlFiles";
+ QmlFileFilterItem *qmlFileFilterItem = new QmlFileFilterItem(projectItem);
+ setupFileFilterItem(qmlFileFilterItem, childNode);
+ projectItem->appendContent(qmlFileFilterItem);
+ } else if (childNode->name() == QLatin1String("JavaScriptFiles")) {
+ if (debug)
+ qDebug() << "JavaScriptFiles";
+ JsFileFilterItem *jsFileFilterItem = new JsFileFilterItem(projectItem);
+ setupFileFilterItem(jsFileFilterItem, childNode);
+ projectItem->appendContent(jsFileFilterItem);
+ } else if (childNode->name() == QLatin1String("ImageFiles")) {
+ if (debug)
+ qDebug() << "ImageFiles";
+ ImageFileFilterItem *imageFileFilterItem = new ImageFileFilterItem(projectItem);
+ setupFileFilterItem(imageFileFilterItem, childNode);
+ projectItem->appendContent(imageFileFilterItem);
+
+ } else if (childNode->name() == QLatin1String("CssFiles")) {
+ if (debug)
+ qDebug() << "CssFiles";
+ CssFileFilterItem *cssFileFilterItem = new CssFileFilterItem(projectItem);
+ setupFileFilterItem(cssFileFilterItem, childNode);
+ projectItem->appendContent(cssFileFilterItem);
+ } else {
+ qWarning() << "Unkwown type:" << childNode->name();
+ }
+ }
+ return projectItem;
+ }
+
+ if (errorMessage)
+ *errorMessage = tr("Invalid root element: %1").arg(rootNode->name());
+
+ return 0;
}
} // namespace QmlProjectManager
diff --git a/src/plugins/qmlprojectmanager/fileformat/qmlprojectfileformat.h b/src/plugins/qmlprojectmanager/fileformat/qmlprojectfileformat.h
index 89f8cc1e98..782239b682 100644
--- a/src/plugins/qmlprojectmanager/fileformat/qmlprojectfileformat.h
+++ b/src/plugins/qmlprojectmanager/fileformat/qmlprojectfileformat.h
@@ -32,9 +32,14 @@
namespace QmlProjectManager {
-class QmlProjectFileFormat {
+class QmlProjectItem;
+
+class QmlProjectFileFormat
+{
+ Q_DECLARE_TR_FUNCTIONS(QmlProjectManager::QmlProjectFileFormat);
+
public:
- static void registerDeclarativeTypes();
+ static QmlProjectItem *parseProjectFile(const QString &fileName, QString *errorMessage = 0);
};
} // namespace QmlProjectManager
diff --git a/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.cpp b/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.cpp
index 7b6eef9e2a..8ac084271e 100644
--- a/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.cpp
+++ b/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.cpp
@@ -77,12 +77,6 @@ QmlProjectItem::~QmlProjectItem()
delete d_ptr;
}
-QDeclarativeListProperty<QmlProjectContentItem> QmlProjectItem::content()
-{
- Q_D(QmlProjectItem);
- return QDeclarativeListProperty<QmlProjectContentItem>(this, d->content);
-}
-
QString QmlProjectItem::sourceDirectory() const
{
Q_D(const QmlProjectItem);
@@ -194,6 +188,12 @@ void QmlProjectItem::setMainFile(const QString &mainFilePath)
emit mainFileChanged();
}
+void QmlProjectItem::appendContent(QmlProjectContentItem *contentItem)
+{
+ Q_D(QmlProjectItem);
+ d->content.append(contentItem);
+}
+
} // namespace QmlProjectManager
#include "qmlprojectitem.moc"
diff --git a/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.h b/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.h
index e4b78ffe22..af73e0b17a 100644
--- a/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.h
+++ b/src/plugins/qmlprojectmanager/fileformat/qmlprojectitem.h
@@ -33,7 +33,6 @@
#include <QObject>
#include <QSet>
#include <QStringList>
-#include <qdeclarative.h>
namespace QmlProjectManager {
@@ -52,19 +51,14 @@ class QmlProjectItem : public QObject
Q_OBJECT
Q_DECLARE_PRIVATE(QmlProjectItem)
- Q_PROPERTY(QDeclarativeListProperty<QmlProjectManager::QmlProjectContentItem> content READ content DESIGNABLE false)
Q_PROPERTY(QString sourceDirectory READ sourceDirectory NOTIFY sourceDirectoryChanged)
Q_PROPERTY(QStringList importPaths READ importPaths WRITE setImportPaths NOTIFY importPathsChanged)
Q_PROPERTY(QString mainFile READ mainFile WRITE setMainFile NOTIFY mainFileChanged)
- Q_CLASSINFO("DefaultProperty", "content")
-
public:
QmlProjectItem(QObject *parent = 0);
~QmlProjectItem();
- QDeclarativeListProperty<QmlProjectContentItem> content();
-
QString sourceDirectory() const;
void setSourceDirectory(const QString &directoryPath);
@@ -77,6 +71,7 @@ public:
QString mainFile() const;
void setMainFile(const QString &mainFilePath);
+ void appendContent(QmlProjectContentItem* contentItem);
signals:
void qmlFilesChanged(const QSet<QString> &, const QSet<QString> &);
@@ -90,8 +85,4 @@ protected:
} // namespace QmlProjectManager
-QML_DECLARE_TYPE(QmlProjectManager::QmlProjectItem)
-QML_DECLARE_TYPE(QmlProjectManager::QmlProjectContentItem)
-Q_DECLARE_METATYPE(QList<QmlProjectManager::QmlProjectContentItem *>)
-
#endif // QMLPROJECTITEM_H
diff --git a/src/plugins/qmlprojectmanager/qmlproject.cpp b/src/plugins/qmlprojectmanager/qmlproject.cpp
index 6c791b5c45..afdf42aeac 100644
--- a/src/plugins/qmlprojectmanager/qmlproject.cpp
+++ b/src/plugins/qmlprojectmanager/qmlproject.cpp
@@ -29,6 +29,7 @@
#include "qmlproject.h"
#include "qmlprojectfile.h"
+#include "fileformat/qmlprojectfileformat.h"
#include "fileformat/qmlprojectitem.h"
#include "qmlprojectrunconfiguration.h"
#include "qmlprojectconstants.h"
@@ -46,13 +47,14 @@
#include <projectexplorer/target.h>
#include <qtsupport/qtsupportconstants.h>
-#include <QDeclarativeComponent>
#include <QDebug>
namespace QmlProjectManager {
namespace Internal {
+
+
class QmlProjectKitMatcher : public ProjectExplorer::KitMatcher
{
public:
@@ -182,22 +184,16 @@ void QmlProject::parseProject(RefreshOptions options)
if (options & ProjectFile)
delete m_projectItem.data();
if (!m_projectItem) {
- Utils::FileReader reader;
- if (reader.fetch(m_fileName)) {
- QDeclarativeComponent *component = new QDeclarativeComponent(&m_engine, this);
- component->setData(reader.data(), QUrl::fromLocalFile(m_fileName));
- if (component->isReady()
- && qobject_cast<QmlProjectItem*>(component->create())) {
- m_projectItem = qobject_cast<QmlProjectItem*>(component->create());
- connect(m_projectItem.data(), SIGNAL(qmlFilesChanged(QSet<QString>,QSet<QString>)),
- this, SLOT(refreshFiles(QSet<QString>,QSet<QString>)));
- } else {
- messageManager->printToOutputPane(tr("Error while loading project file %1.").arg(m_fileName), Core::MessageManager::NoModeSwitch);
- messageManager->printToOutputPane(component->errorString(), Core::MessageManager::NoModeSwitch);
- }
- } else {
- messageManager->printToOutputPane(tr("QML project: %1").arg(reader.errorString()), Core::MessageManager::NoModeSwitch);
- }
+ QString errorMessage;
+ m_projectItem = QmlProjectFileFormat::parseProjectFile(m_fileName, &errorMessage);
+ if (m_projectItem) {
+ connect(m_projectItem.data(), SIGNAL(qmlFilesChanged(QSet<QString>,QSet<QString>)),
+ this, SLOT(refreshFiles(QSet<QString>,QSet<QString>)));
+
+ } else {
+ messageManager->printToOutputPane(tr("Error while loading project file %1.").arg(m_fileName), Core::MessageManager::NoModeSwitch);
+ messageManager->printToOutputPane(errorMessage, Core::MessageManager::NoModeSwitch);
+ }
}
if (m_projectItem) {
m_projectItem.data()->setSourceDirectory(projectDir().path());
diff --git a/src/plugins/qmlprojectmanager/qmlproject.h b/src/plugins/qmlprojectmanager/qmlproject.h
index cc34f18f65..01b6ccb589 100644
--- a/src/plugins/qmlprojectmanager/qmlproject.h
+++ b/src/plugins/qmlprojectmanager/qmlproject.h
@@ -34,7 +34,6 @@
#include <projectexplorer/project.h>
-#include <QDeclarativeEngine>
#include <QPointer>
namespace ProjectExplorer { class RunConfiguration; }
@@ -119,8 +118,6 @@ private:
// plain format
QStringList m_files;
- // qml based, new format
- QDeclarativeEngine m_engine;
QPointer<QmlProjectItem> m_projectItem;
Internal::QmlProjectNode *m_rootNode;
diff --git a/src/plugins/qmlprojectmanager/qmlprojectmanager.pro b/src/plugins/qmlprojectmanager/qmlprojectmanager.pro
index 28888a726b..cd42fc753f 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectmanager.pro
+++ b/src/plugins/qmlprojectmanager/qmlprojectmanager.pro
@@ -1,4 +1,4 @@
-QT += network declarative
+QT += network
include(../../qtcreatorplugin.pri)
include(fileformat/fileformat.pri)
diff --git a/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp b/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp
index fa4d7cb8e6..00470d2c22 100644
--- a/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp
+++ b/src/plugins/qmlprojectmanager/qmlprojectplugin.cpp
@@ -76,8 +76,6 @@ bool QmlProjectPlugin::initialize(const QStringList &, QString *errorMessage)
Internal::QmlApplicationWizard::createInstances(this);
- QmlProjectFileFormat::registerDeclarativeTypes();
-
Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
iconProvider->registerIconOverlayForSuffix(QIcon(QLatin1String(":/qmlproject/images/qmlproject.png")),
QLatin1String("qmlproject"));