Commit faa59b75 authored by Thomas Hartmann's avatar Thomas Hartmann

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;
......
......@@ -70,7 +70,7 @@ CORESHARED_EXPORT QList<Internal::InternalNodePointer> toInternalNodeList(const
typedef QList<QPair<QString, QVariant> > PropertyListType;
class CORESHARED_EXPORT ModelNode
class CORESHARED_EXPORT ModelNode
{
friend CORESHARED_EXPORT bool operator ==(const ModelNode &firstNode, const ModelNode &secondNode);
friend CORESHARED_EXPORT bool operator !=(const ModelNode &firstNode, const ModelNode &secondNode);
......@@ -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;
}
......
......@@ -49,13 +49,14 @@ class InstanceContainer
public:
InstanceContainer();
InstanceContainer(qint32 instanceId, const QString &type, int majorNumber, int minorNumber, const QString &componentPath);
InstanceContainer(qint32 instanceId, const QString &type, int majorNumber, int minorNumber, const QString &componentPath, const QString &customParserSource);
qint32 instanceId() const;
QString type() const;
int majorNumber() const;
int minorNumber() const;
QString componentPath() const;
QString customParserSource() const;
private:
qint32 m_instanceId;
......@@ -63,6 +64,7 @@ private:
int m_majorNumber;
int m_minorNumber;
QString m_componentPath;
QString m_customParserSource;
};
} // namespace QmlDesigner
......
......@@ -17,6 +17,7 @@ HEADERS += $$PWD/addimportcommand.h
HEADERS += $$PWD/changebindingscommand.h
HEADERS += $$PWD/changefileurlcommand.h
HEADERS += $$PWD/changeidscommand.h
HEADERS += $$PWD/changecustomparsersourcecommand.h
HEADERS += $$PWD/changestatecommand.h
HEADERS += $$PWD/changevaluescommand.h
HEADERS += $$PWD/childrenchangeeventfilter.h
......@@ -66,6 +67,7 @@ SOURCES += $$PWD/addimportcommand.cpp
SOURCES += $$PWD/changebindingscommand.cpp
SOURCES += $$PWD/changefileurlcommand.cpp
SOURCES += $$PWD/changeidscommand.cpp
SOURCES += $$PWD/changecustomparsersourcecommand.cpp
SOURCES += $$PWD/changestatecommand.cpp
SOURCES += $$PWD/changevaluescommand.cpp
SOURCES += $$PWD/childrenchangeeventfilter.cpp
......
......@@ -67,6 +67,7 @@
#include "imagecontainer.h"
#include "statepreviewimagechangedcommand.h"
#include "componentcompletedcommand.h"
#include "changecustomparsersourcecommand.h"
namespace QmlDesigner {
......@@ -263,6 +264,11 @@ void NodeInstanceClientProxy::completeComponent(const CompleteComponentCommand &
nodeInstanceServer()->completeComponent(command);
}
void NodeInstanceClientProxy::changeCustomParserSource(ChangeCustomParserSourceCommand &command)
{
nodeInstanceServer()->changeCustomParserSource(command);
}
void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
{
static const int createInstancesCommandType = QMetaType::type("CreateInstancesCommand");
......@@ -279,6 +285,7 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
static const int addImportCommandType = QMetaType::type("AddImportCommand");
static const int completeComponentCommandType = QMetaType::type("CompleteComponentCommand");
static const int synchronizeCommandType = QMetaType::type("SynchronizeCommand");
static const int changeCustomParserSourceCommandType = QMetaType::type("ChangeCustomParserSourceCommand");
if (command.userType() == createInstancesCommandType) {
createInstances(command.value<CreateInstancesCommand>());
......@@ -306,6 +313,8 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
addImport(command.value<AddImportCommand>());
else if (command.userType() == completeComponentCommandType)
completeComponent(command.value<CompleteComponentCommand>());
else if (command.userType() == changeCustomParserSourceCommandType)
changeCustomParserSource(command.value<ChangeCustomParserSourceCommand>());
else if (command.userType() == synchronizeCommandType) {
SynchronizeCommand synchronizeCommand = command.value<SynchronizeCommand>();
m_synchronizeId = synchronizeCommand.synchronizeId();
......
......@@ -59,6 +59,7 @@ class RemovePropertiesCommand;
class AddImportCommand;
class CompleteComponentCommand;
class ChangeStateCommand;
class ChangeCustomParserSourceCommand;
class NodeInstanceClientProxy : public QObject, public NodeInstanceClientInterface
{
......@@ -72,7 +73,7 @@ public:
void pixmapChanged(const PixmapChangedCommand &command);
void childrenChanged(const ChildrenChangedCommand &command);
void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command);
void componentCompleted(const ComponentCompletedCommand &command);
void componentCompleted(const ComponentCompletedCommand &command);
void flush();
void synchronizeWithClientProcess();
......@@ -96,6 +97,7 @@ protected:
void changeState(const ChangeStateCommand &command);
void addImport(const AddImportCommand &command);
void completeComponent(const CompleteComponentCommand &command);
void changeCustomParserSource(ChangeCustomParserSourceCommand &command);
private slots:
void readDataStream();
......
......@@ -76,6 +76,7 @@
#include "completecomponentcommand.h"
#include "componentcompletedcommand.h"
#include "createscenecommand.h"
#include "changecustomparsersourcecommand.h"
#include "dummycontextobject.h"
......@@ -345,6 +346,16 @@ void NodeInstanceServer::completeComponent(const CompleteComponentCommand &comma
startRenderTimer();
}
void NodeInstanceServer::changeCustomParserSource(ChangeCustomParserSourceCommand &command)
{
if (hasInstanceForId(command.instanceId())) {
ServerNodeInstance instance = instanceForId(command.instanceId());
;
}
startRenderTimer();
}
void NodeInstanceServer::addImports(const QVector<AddImportContainer> &containerVector)
{
foreach (const AddImportContainer &container, containerVector) {
......
......@@ -90,6 +90,7 @@ public:
void changeState(const ChangeStateCommand &command);
void addImport(const AddImportCommand &command);
void completeComponent(const CompleteComponentCommand &command);
void changeCustomParserSource(ChangeCustomParserSourceCommand &command);
ServerNodeInstance instanceForId(qint32 id) const;
bool hasInstanceForId(qint32 id) const;
......
......@@ -50,6 +50,7 @@
#include "changestatecommand.h"
#include "completecomponentcommand.h"
#include "addimportcontainer.h"
#include "changecustomparsersourcecommand.h"
#include "informationchangedcommand.h"
#include "pixmapchangedcommand.h"
......@@ -165,6 +166,10 @@ void NodeInstanceServerInterface::registerCommands()
qRegisterMetaType<SynchronizeCommand>("SynchronizeCommand");
qRegisterMetaTypeStreamOperators<SynchronizeCommand>("SynchronizeCommand");
qRegisterMetaType<ChangeCustomParserSourceCommand>("ChangeCustomParserSourceCommand");
qRegisterMetaTypeStreamOperators<ChangeCustomParserSourceCommand>("ChangeCustomParserSourceCommand");
}
}
......@@ -55,6 +55,7 @@
#include "changestatecommand.h"
#include "addimportcommand.h"
#include "completecomponentcommand.h"
#include "changecustomparsersourcecommand.h"
#include "informationchangedcommand.h"
#include "pixmapchangedcommand.h"
......@@ -451,4 +452,10 @@ void NodeInstanceServerProxy::completeComponent(const CompleteComponentCommand &
{
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceServerProxy::changeCustomParserSource(ChangeCustomParserSourceCommand &command)
{
writeCommand(QVariant::fromValue(command));
}
} // namespace QmlDesigner
......@@ -70,6 +70,7 @@ public:
void changeState(const ChangeStateCommand &command);
void addImport(const AddImportCommand &command);
void completeComponent(const CompleteComponentCommand &command);
void changeCustomParserSource(ChangeCustomParserSourceCommand &command);
protected:
void writeCommand(const QVariant &command);
......
......@@ -66,6 +66,7 @@
#include "changevaluescommand.h"
#include "changebindingscommand.h"
#include "changeidscommand.h"
#include "changecustomparsersourcecommand.h"
#include "removeinstancescommand.h"
#include "removepropertiescommand.h"
#include "valueschangedcommand.h"
......@@ -515,6 +516,15 @@ void NodeInstanceView::customNotification(const AbstractView *view, const QStrin
restartProcess();
}
void NodeInstanceView::customParserSourceChanged(const ModelNode &node, const QString & newCustomParserSource)
{
if (hasInstanceForNode(node)) {
NodeInstance instance = instanceForNode(node);
ChangeCustomParserSourceCommand changeCustomParserSourceCommand(instance.instanceId(), newCustomParserSource);
nodeInstanceServer()->changeCustomParserSource(changeCustomParserSourceCommand);
}
}
void NodeInstanceView::rewriterBeginTransaction()
{
......@@ -738,7 +748,7 @@ CreateSceneCommand NodeInstanceView::createCreateSceneCommand()
nodeList = filterNodesForSkipItems(nodeList);
QList<VariantProperty> variantPropertyList;
QList<BindingProperty> bindingPropertyList;
QList<BindingProperty> bindingPropertyList;