Commit faa59b75 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.Model: add support for custom parser types

This patch enables us to create objects with custom parsers
like ListModel and XmlListModel.
parent 749d559a
......@@ -169,6 +169,7 @@ void ComponentView::instanceInformationsChange(const QVector<ModelNode> &/*nodeL
void ComponentView::instancesRenderImageChanged(const QVector<ModelNode> &/*nodeList*/) {}
void ComponentView::instancesPreviewImageChanged(const QVector<ModelNode> &/*nodeList*/) {}
void ComponentView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeList*/) {}
void ComponentView::customParserSourceChanged(const ModelNode &, const QString & /*newCustomParserSource*/) {}
void ComponentView::rewriterBeginTransaction() {}
void ComponentView::rewriterEndTransaction() {}
......
......@@ -77,6 +77,7 @@ public:
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void customParserSourceChanged(const ModelNode &modelNode, const QString &newCustomParserSource);
void rewriterBeginTransaction();
void rewriterEndTransaction();
......
......@@ -92,6 +92,10 @@ void DesignDocumentControllerView::instancesChildrenChanged(const QVector<ModelN
}
void DesignDocumentControllerView::customParserSourceChanged(const ModelNode &, const QString & /*newCustomParserSource*/)
{
}
void DesignDocumentControllerView::rewriterBeginTransaction()
{
......
......@@ -68,6 +68,7 @@ public:
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void customParserSourceChanged(const ModelNode &modelNode, const QString &newCustomParserSource);
void rewriterBeginTransaction();
void rewriterEndTransaction();
......
......@@ -172,6 +172,11 @@ void ItemLibraryView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeL
}
void ItemLibraryView::customParserSourceChanged(const ModelNode &, const QString & /*newCustomParserSource*/)
{
}
void ItemLibraryView::rewriterBeginTransaction()
{
}
......
......@@ -84,6 +84,7 @@ public:
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void customParserSourceChanged(const ModelNode &modelNode, const QString &newCustomParserSource);
void rewriterBeginTransaction();
void rewriterEndTransaction();
......
......@@ -235,6 +235,11 @@ void NavigatorView::instancesChildrenChanged(const QVector<ModelNode> &/*nodeLis
}
void NavigatorView::customParserSourceChanged(const ModelNode &, const QString & /*newCustomParserSource*/)
{
}
void NavigatorView::rewriterBeginTransaction()
{
}
......
......@@ -92,6 +92,7 @@ public:
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void customParserSourceChanged(const ModelNode &modelNode, const QString &newCustomParserSource);
void rewriterBeginTransaction();
void rewriterEndTransaction();
......
......@@ -107,6 +107,7 @@ SOURCES += $$PWD/model/abstractview.cpp \
$$PWD/instances/imagecontainer.cpp \
$$PWD/instances/completecomponentcommand.cpp \
$$PWD/instances/componentcompletedcommand.cpp \
$$PWD/instances/changecustomparsersourcecommand.cpp \
$$PWD/instances/addimportcontainer.cpp
HEADERS += $$PWD/include/corelib_global.h \
......@@ -215,6 +216,7 @@ HEADERS += $$PWD/include/corelib_global.h \
$$PWD/instances/imagecontainer.h \
$$PWD/instances/completecomponentcommand.h \
$$PWD/instances/componentcompletedcommand.h \
$$PWD/instances/changecustomparsersourcecommand.h \
$$PWD/instances/addimportcontainer.h
contains(CONFIG, plugin) {
# If core.pri has been included in the qmldesigner plugin
......
......@@ -85,7 +85,8 @@ public:
ModelNode createModelNode(const QString &typeString,
int majorVersion,
int minorVersion,
const PropertyListType &propertyList = PropertyListType());
const PropertyListType &propertyList = PropertyListType(),
const QString &customParserSource = QString());
const ModelNode rootModelNode() const;
ModelNode rootModelNode();
......@@ -140,6 +141,7 @@ public:
virtual void instancesRenderImageChanged(const QVector<ModelNode> &nodeList) = 0;
virtual void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList) = 0;
virtual void instancesChildrenChanged(const QVector<ModelNode> &nodeList) = 0;
virtual void customParserSourceChanged(const ModelNode &modelNode, const QString &newCustomParserSource) = 0;
virtual void rewriterBeginTransaction() = 0;
virtual void rewriterEndTransaction() = 0;
......
......@@ -170,6 +170,9 @@ public:
qint32 internalId() const;
void setCustomParserSource(const QString&);
QString customParserSource() const;
private: // functions
Internal::InternalNodePointer internalNode() const;
QString generateNewId() const;
......
......@@ -54,6 +54,7 @@ class RemovePropertiesCommand;
class ChangeStateCommand;
class AddImportCommand;
class CompleteComponentCommand;
class ChangeCustomParserSourceCommand;
class NodeInstanceServerInterface : public QObject
{
......@@ -79,6 +80,7 @@ public:
virtual void changeState(const ChangeStateCommand &command) = 0;
virtual void addImport(const AddImportCommand &command) = 0;
virtual void completeComponent(const CompleteComponentCommand &command) = 0;
virtual void changeCustomParserSource(ChangeCustomParserSourceCommand &command) = 0;
static void registerCommands();
};
......
......@@ -109,6 +109,7 @@ public:
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
void customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
void customParserSourceChanged(const ModelNode &modelNode, const QString &newCustomParserSource);
void rewriterBeginTransaction();
void rewriterEndTransaction();
......
......@@ -95,6 +95,8 @@ public:
QString componentSource() const;
QString componentFileName() const;
bool hasCustomParser() const;
bool availableInVersion(int majorVersion, int minorVersion) const;
bool isSubclassOf(const QString& type, int majorVersion, int minorVersio) const;
......
......@@ -119,6 +119,7 @@ public:
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList);
void importsChanged(const QList<Import> &addedImports, const QList<Import> &removedImports);
void customParserSourceChanged(const ModelNode &modelNode, const QString &newCustomParserSource);
protected:
NodeInstance instanceForModelNode(const ModelNode &modelNode);
......
......@@ -143,6 +143,7 @@ public:
void instancesRenderImageChanged(const QVector<ModelNode> &nodeList);
void instancesPreviewImageChanged(const QVector<ModelNode> &nodeList);
void instancesChildrenChanged(const QVector<ModelNode> &nodeList);
void customParserSourceChanged(const ModelNode &modelNode, const QString &newCustomParserSource);
void rewriterBeginTransaction();
void rewriterEndTransaction();
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "changecustomparsersourcecommand.h"
namespace QmlDesigner {
ChangeCustomParserSourceCommand::ChangeCustomParserSourceCommand()
{
}
ChangeCustomParserSourceCommand::ChangeCustomParserSourceCommand(qint32 newInstanceId, const QString &newCustomParserSource)
: m_instanceId(newInstanceId), m_customParserSource(newCustomParserSource)
{
}
qint32 ChangeCustomParserSourceCommand::instanceId() const
{
return m_instanceId;
}
QString ChangeCustomParserSourceCommand::customParserSource() const
{
return m_customParserSource;
}
QDataStream &operator<<(QDataStream &out, const ChangeCustomParserSourceCommand &command)
{
out << command.instanceId();
out << command.customParserSource();
return out;
}
QDataStream &operator>>(QDataStream &in, ChangeCustomParserSourceCommand &command)
{
in >> command.m_instanceId;
in >> command.m_customParserSource;
return in;
}
} // namespace QmlDesigner
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef CHANGECUSTOMPARSERSOURCECOMMAND_H
#define CHANGECUSTOMPARSERSOURCECOMMAND_H
#include <QMetaType>
namespace QmlDesigner {
class ChangeCustomParserSourceCommand
{
friend QDataStream &operator>>(QDataStream &in, ChangeCustomParserSourceCommand &command);
public:
ChangeCustomParserSourceCommand();
ChangeCustomParserSourceCommand(qint32 instanceId, const QString &customParserSource);
qint32 instanceId() const;
QString customParserSource() const;
private:
qint32 m_instanceId;
QString m_customParserSource;
};
QDataStream &operator<<(QDataStream &out, const ChangeCustomParserSourceCommand &command);
QDataStream &operator>>(QDataStream &in, ChangeCustomParserSourceCommand &command);
} // namespace QmlDesigner
Q_DECLARE_METATYPE(QmlDesigner::ChangeCustomParserSourceCommand)
#endif // CHANGECUSTOMPARSERSOURCECOMMAND_H
......@@ -73,17 +73,19 @@ bool ComponentNodeInstance::hasContent() const
void ComponentNodeInstance::setPropertyVariant(const QString &name, const QVariant &value)
{
if (name == "__component_data") {
QByteArray data(value.toByteArray());
QByteArray importArray;
foreach(const QString &import, nodeInstanceServer()->imports()) {
importArray.append(import.toUtf8());
}
QByteArray data(value.toByteArray());
data.prepend(importArray);
data.append("\n");
component()->setData(data, nodeInstanceServer()->fileUrl());
component()->setData(data, QUrl(nodeInstanceServer()->fileUrl().toString() + "_"+ id()));
setId(id());
}
if (component()->isError()) {
......
......@@ -39,8 +39,9 @@ InstanceContainer::InstanceContainer()
{
}
InstanceContainer::InstanceContainer(qint32 instanceId, const QString &type, int majorNumber, int minorNumber, const QString &componentPath)
: m_instanceId(instanceId), m_type(type), m_majorNumber(majorNumber), m_minorNumber(minorNumber), m_componentPath(componentPath)
InstanceContainer::InstanceContainer(qint32 instanceId, const QString &type, int majorNumber, int minorNumber, const QString &componentPath, const QString &customParserSource)
: m_instanceId(instanceId), m_type(type), m_majorNumber(majorNumber), m_minorNumber(minorNumber), m_componentPath(componentPath),
m_customParserSource(customParserSource)
{
m_type.replace(QLatin1Char('.'), QLatin1Char('/'));
}
......@@ -70,6 +71,11 @@ QString InstanceContainer::componentPath() const
return m_componentPath;
}
QString InstanceContainer::customParserSource() const
{
return m_customParserSource;
}
QDataStream &operator<<(QDataStream &out, const InstanceContainer &container)
{
out << container.instanceId();
......@@ -77,6 +83,7 @@ QDataStream &operator<<(QDataStream &out, const InstanceContainer &container)
out << container.majorNumber();
out << container.minorNumber();
out << container.componentPath();
out << container.customParserSource();
return out;
}
......@@ -89,6 +96,7 @@ QDataStream &operator>>(QDataStream &in, InstanceContainer &container)
in >> container.m_majorNumber;
in >> container.m_minorNumber;
in >> container.m_componentPath;
in >> container.m_customParserSource;
return in;
}
......
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