Commit 1312a042 authored by Marco Bubke's avatar Marco Bubke

QmlDesigner: Add component complete feature

This notifies the views if the instance has be really instanced.
parent c04797fd
......@@ -435,6 +435,11 @@ void FormEditorView::auxiliaryDataChanged(const ModelNode &node, const QString &
}
}
void FormEditorView::instancesCompleted(const QVector<ModelNode> &completedNodeList)
{
}
void FormEditorView::customNotification(const AbstractView *view, const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data)
{
if (identifier == "__start rewriter transaction__") {
......
......@@ -101,6 +101,8 @@ public:
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 instancesCompleted(const QVector<ModelNode> &completedNodeList);
double margins() const;
double spacing() const;
void deActivateItemCreator();
......
......@@ -161,6 +161,7 @@ void ComponentView::bindingPropertiesChanged(const QList<BindingProperty>& /*pro
void ComponentView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVersion*/, int /*minorVersion*/) {}
void ComponentView::scriptFunctionsChanged(const ModelNode &/*node*/, const QStringList &/*scriptFunctionList*/) {}
void ComponentView::instancePropertyChange(const QList<QPair<ModelNode, QString> > &/*propertyList*/) {};
void ComponentView::instancesCompleted(const QVector<ModelNode> &/*completedNodeList*/) {}
void ComponentView::selectedNodesChanged(const QList<ModelNode> &/*selectedNodeList*/,
......@@ -170,7 +171,6 @@ void ComponentView::fileUrlChanged(const QUrl &/*oldUrl*/, const QUrl &/*newUrl*
void ComponentView::nodeOrderChanged(const NodeListProperty &/*listProperty*/, const ModelNode & /*movedNode*/, int /*oldIndex*/) {}
void ComponentView::importsChanged() {}
void ComponentView::auxiliaryDataChanged(const ModelNode &/*node*/, const QString &/*name*/, const QVariant &/*data*/) {}
......
......@@ -69,6 +69,7 @@ public:
void rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList);
......@@ -77,8 +78,6 @@ public:
void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
void importsChanged();
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);
......
......@@ -65,6 +65,11 @@ void DesignDocumentControllerView::instancePropertyChange(const QList<QPair<Mode
{
}
void DesignDocumentControllerView::instancesCompleted(const QVector<ModelNode> &/*completedNodeList*/)
{
}
static QStringList arrayToStringList(const QByteArray &byteArray)
{
QString str(QString::fromLatin1(byteArray));
......
......@@ -60,7 +60,7 @@ public:
virtual void nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &movedNode, int oldIndex);
virtual void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
ModelNode insertModel(const ModelNode &modelNode)
{ return m_modelMerger.insertModel(modelNode); }
......
......@@ -198,6 +198,10 @@ void NavigatorView::instancePropertyChange(const QList<QPair<ModelNode, QString>
{
}
void NavigatorView::instancesCompleted(const QVector<ModelNode> &/*completedNodeList*/)
{
}
void NavigatorView::nodeOrderChanged(const NodeListProperty &listProperty, const ModelNode &node, int oldIndex)
{
if (m_treeModel->isInTree(node))
......
......@@ -82,6 +82,7 @@ public:
void auxiliaryDataChanged(const ModelNode &node, const QString &name, const QVariant &data);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
private slots:
// void handleChangedItem(QStandardItem * item);
......
......@@ -119,7 +119,9 @@ SOURCES += $$PWD/model/abstractview.cpp \
$$PWD/instances/addimportcommand.cpp \
$$PWD/instances/childrenchangedcommand.cpp \
$$PWD/instances/statepreviewimagechangedcommand.cpp \
$$PWD/instances/imagecontainer.cpp
$$PWD/instances/imagecontainer.cpp \
$$PWD/instances/completecomponentcommand.cpp \
$$PWD/instances/componentcompletedcommand.cpp
HEADERS += $$PWD/include/corelib_global.h \
$$PWD/include/abstractview.h \
$$PWD/include/nodeinstanceview.h \
......@@ -237,7 +239,9 @@ HEADERS += $$PWD/include/corelib_global.h \
$$PWD/instances/addimportcommand.h \
$$PWD/instances/childrenchangedcommand.h \
$$PWD/instances/statepreviewimagechangedcommand.h \
$$PWD/instances/imagecontainer.h
$$PWD/instances/imagecontainer.h \
$$PWD/instances/completecomponentcommand.h \
$$PWD/instances/componentcompletedcommand.h
contains(CONFIG, plugin) {
# If core.pri has been included in the qmldesigner plugin
SOURCES += $$PWD/model/basetexteditmodifier.cpp
......
......@@ -107,6 +107,7 @@ public:
void emitCustomNotification(const QString &identifier, const QList<ModelNode> &nodeList, const QList<QVariant> &data);
void emitInstancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void emitInstancesCompleted(const QVector<ModelNode> &nodeList);
virtual void modelAttached(Model *model);
virtual void modelAboutToBeDetached(Model *model);
......@@ -124,6 +125,8 @@ public:
virtual void rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion) = 0;
virtual void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList) = 0;
virtual void instancesCompleted(const QVector<ModelNode> &completedNodeList) = 0;
virtual void selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList) = 0;
......
......@@ -10,6 +10,7 @@ class PixmapChangedCommand;
class InformationChangedCommand;
class ChildrenChangedCommand;
class StatePreviewImageChangedCommand;
class ComponentCompletedCommand;
class NodeInstanceClientInterface
{
......@@ -19,6 +20,7 @@ public:
virtual void pixmapChanged(const PixmapChangedCommand &command) = 0;
virtual void childrenChanged(const ChildrenChangedCommand &command) = 0;
virtual void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command) = 0;
virtual void componentCompleted(const ComponentCompletedCommand &command) = 0;
virtual void flush() {};
virtual qint64 bytesToWrite() const {return 0;}
......
......@@ -21,6 +21,7 @@ class RemoveInstancesCommand;
class RemovePropertiesCommand;
class ChangeStateCommand;
class AddImportCommand;
class CompleteComponentCommand;
class NodeInstanceServerInterface : public QObject
{
......@@ -40,6 +41,7 @@ public:
virtual void changeIds(const ChangeIdsCommand &command) = 0;
virtual void changeState(const ChangeStateCommand &command) = 0;
virtual void addImport(const AddImportCommand &command) = 0;
virtual void completeComponent(const CompleteComponentCommand &command) = 0;
virtual void setBlockUpdates(bool /*block*/) {}
......
......@@ -63,6 +63,7 @@ class ChangeIdsCommand;
class RemoveInstancesCommand;
class RemovePropertiesCommand;
class AddImportCommand;
class CompleteComponentCommand;
class CORESHARED_EXPORT NodeInstanceView : public AbstractView, public NodeInstanceClientInterface
{
......@@ -94,6 +95,7 @@ public:
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList, const QList<ModelNode> &lastSelectedNodeList);
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
void importAdded(const Import &import);
void importRemoved(const Import &import);
......@@ -118,6 +120,7 @@ public:
void informationChanged(const InformationChangedCommand &command);
void childrenChanged(const ChildrenChangedCommand &command);
void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command);
void componentCompleted(const ComponentCompletedCommand &command);
private: // functions
NodeInstance rootNodeInstance() const;
......@@ -143,6 +146,8 @@ private: // functions
CreateSceneCommand createCreateSceneCommand() const;
ClearSceneCommand createClearSceneCommand() const;
CreateInstancesCommand createCreateInstancesCommand(const QList<NodeInstance> &instanceList) const;
CompleteComponentCommand createComponentCompleteCommand(const QList<NodeInstance> &instanceList) const;
ComponentCompletedCommand createComponentCompletedCommand(const QList<NodeInstance> &instanceList) const;
ReparentInstancesCommand createReparentInstancesCommand(const QList<NodeInstance> &instanceList) const;
ReparentInstancesCommand createReparentInstancesCommand(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent) const;
ChangeFileUrlCommand createChangeFileUrlCommand(const QUrl &fileUrl) const;
......
......@@ -91,6 +91,7 @@ public:
virtual void nodeInstancePropertyChanged(const ModelNode &node, const QString &propertyName);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
void nodeCreated(const ModelNode &createdNode);
void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange);
......
......@@ -135,6 +135,7 @@ public:
void scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList);
void instancePropertyChange(const QList<QPair<ModelNode, QString> > &propertyList);
void instancesCompleted(const QVector<ModelNode> &completedNodeList);
void importAdded(const Import &import);
void importRemoved(const Import &import);
......
#include "completecomponentcommand.h"
namespace QmlDesigner {
CompleteComponentCommand::CompleteComponentCommand()
{
}
CompleteComponentCommand::CompleteComponentCommand(const QVector<qint32> &container)
: m_instanceVector(container)
{
}
QVector<qint32> CompleteComponentCommand::instances() const
{
return m_instanceVector;
}
QDataStream &operator<<(QDataStream &out, const CompleteComponentCommand &command)
{
out << command.instances();
return out;
}
QDataStream &operator>>(QDataStream &in, CompleteComponentCommand &command)
{
in >> command.m_instanceVector;
return in;
}
} // namespace QmlDesigner
#ifndef COMPLETECOMPONENT_H
#define COMPLETECOMPONENT_H
#include <QMetaType>
#include <QVector>
namespace QmlDesigner {
class CompleteComponentCommand
{
friend QDataStream &operator>>(QDataStream &in, CompleteComponentCommand &command);
public:
CompleteComponentCommand();
CompleteComponentCommand(const QVector<qint32> &container);
QVector<qint32> instances() const;
private:
QVector<qint32> m_instanceVector;
};
QDataStream &operator<<(QDataStream &out, const CompleteComponentCommand &command);
QDataStream &operator>>(QDataStream &in, CompleteComponentCommand &command);
} // namespace QmlDesigner
Q_DECLARE_METATYPE(QmlDesigner::CompleteComponentCommand);
#endif // COMPLETECOMPONENT_H
#include "componentcompletedcommand.h"
namespace QmlDesigner {
ComponentCompletedCommand::ComponentCompletedCommand()
{
}
ComponentCompletedCommand::ComponentCompletedCommand(const QVector<qint32> &container)
: m_instanceVector(container)
{
}
QVector<qint32> ComponentCompletedCommand::instances() const
{
return m_instanceVector;
}
QDataStream &operator<<(QDataStream &out, const ComponentCompletedCommand &command)
{
out << command.instances();
return out;
}
QDataStream &operator>>(QDataStream &in, ComponentCompletedCommand &command)
{
in >> command.m_instanceVector;
return in;
}
} // namespace QmlDesigner
#ifndef COMPONENTCOMPLETEDCOMMAND_H
#define COMPONENTCOMPLETEDCOMMAND_H
#include <QMetaType>
#include <QVector>
namespace QmlDesigner {
class ComponentCompletedCommand
{
friend QDataStream &operator>>(QDataStream &in, ComponentCompletedCommand &command);
public:
ComponentCompletedCommand();
ComponentCompletedCommand(const QVector<qint32> &container);
QVector<qint32> instances() const;
private:
QVector<qint32> m_instanceVector;
};
QDataStream &operator<<(QDataStream &out, const ComponentCompletedCommand &command);
QDataStream &operator>>(QDataStream &in, ComponentCompletedCommand &command);
} // namespace QmlDesigner
Q_DECLARE_METATYPE(QmlDesigner::ComponentCompletedCommand);
#endif // COMPONENTCOMPLETEDCOMMAND_H
......@@ -3,6 +3,8 @@ INCLUDEPATH += $$PWD/../include
HEADERS += $$PWD/behaviornodeinstance.h
HEADERS += $$PWD/componentcompletedcommand.h
HEADERS += $$PWD//completecomponentcommand.h
HEADERS += $$PWDstatepreviewimagechangedcommand.h
HEADERS += $$PWD//imagecontainer.h
HEADERS += $$PWD/childrenchangedcommand.h
......@@ -45,6 +47,8 @@ HEADERS += $$PWD/../include/nodeinstanceserverinterface.h
SOURCES += $$PWD/behaviornodeinstance.cpp
SOURCES += $$PWD/componentcompletedcommand.cpp
SOURCES += $$PWD/completecomponentcommand.cpp
SOURCES += $$PWD/statepreviewimagechangedcommand.cpp
SOURCES += $$PWD/imagecontainer.cpp
SOURCES += $$PWD/childrenchangedcommand.cpp
......
......@@ -23,6 +23,7 @@
#include "changeidscommand.h"
#include "changestatecommand.h"
#include "addimportcommand.h"
#include "completecomponentcommand.h"
#include "informationchangedcommand.h"
#include "pixmapchangedcommand.h"
......@@ -30,6 +31,7 @@
#include "childrenchangedcommand.h"
#include "imagecontainer.h"
#include "statepreviewimagechangedcommand.h"
#include "componentcompletedcommand.h"
namespace QmlDesigner {
......@@ -83,6 +85,11 @@ void NodeInstanceClientProxy::statePreviewImagesChanged(const StatePreviewImageC
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::componentCompleted(const ComponentCompletedCommand &command)
{
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceClientProxy::flush()
{
}
......@@ -142,6 +149,7 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
static const int changeIdsCommandType = QMetaType::type("ChangeIdsCommand");
static const int changeStateCommandType = QMetaType::type("ChangeStateCommand");
static const int addImportCommandType = QMetaType::type("AddImportCommand");
static const int completeComponentCommandType = QMetaType::type("CompleteComponentCommand");
if (command.userType() == createInstancesCommandType)
nodeInstanceServer()->createInstances(command.value<CreateInstancesCommand>());
......@@ -167,6 +175,8 @@ void NodeInstanceClientProxy::dispatchCommand(const QVariant &command)
nodeInstanceServer()->changeState(command.value<ChangeStateCommand>());
else if (command.userType() == addImportCommandType)
nodeInstanceServer()->addImport(command.value<AddImportCommand>());
else if (command.userType() == completeComponentCommandType)
nodeInstanceServer()->completeComponent(command.value<CompleteComponentCommand>());
else
Q_ASSERT(false);
}
......
......@@ -25,6 +25,8 @@ public:
void pixmapChanged(const PixmapChangedCommand &command);
void childrenChanged(const ChildrenChangedCommand &command);
void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command);
void componentCompleted(const ComponentCompletedCommand &command);
void flush();
qint64 bytesToWrite() const;
......
......@@ -36,6 +36,8 @@
#include "changestatecommand.h"
#include "addimportcommand.h"
#include "childrenchangedcommand.h"
#include "completecomponentcommand.h"
#include "componentcompletedcommand.h"
#include <iostream>
#include <stdio.h>
......@@ -76,8 +78,6 @@ void NodeInstanceServer::createInstances(const CreateInstancesCommand &command)
}
}
instance.doComponentComplete();
}
nodeInstanceClient()->valuesChanged(createValuesChangedCommand(instanceList));
......@@ -221,6 +221,17 @@ void NodeInstanceServer::changeState(const ChangeStateCommand &command)
startRenderTimer();
}
void NodeInstanceServer::completeComponent(const CompleteComponentCommand &command)
{
foreach(qint32 instanceId, command.instances()) {
if (hasInstanceForId(instanceId)) {
ServerNodeInstance instance = instanceForId(instanceId);
instance.doComponentComplete();
m_componentCompletedVector.append(instanceId);
}
}
}
void NodeInstanceServer::addImport(const AddImportCommand &command)
{
QString importStatement = QString("import ");
......@@ -787,6 +798,10 @@ void NodeInstanceServer::findItemChangesAndSendChangeCommands()
if (!parentChangedSet.isEmpty())
sendChildrenChangedCommand(parentChangedSet.toList());
if (!m_componentCompletedVector.isEmpty())
nodeInstanceClient()->componentCompleted(ComponentCompletedCommand(m_componentCompletedVector));
m_componentCompletedVector.clear();
if (!dirtyInstanceSet.isEmpty())
nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(dirtyInstanceSet.toList()));
......
......@@ -49,6 +49,7 @@ public:
void reparentInstances(const ReparentInstancesCommand &command);
void changeState(const ChangeStateCommand &command);
void addImport(const AddImportCommand &command);
void completeComponent(const CompleteComponentCommand &command);
ServerNodeInstance instanceForId(qint32 id) const;
bool hasInstanceForId(qint32 id) const;
......@@ -127,6 +128,7 @@ private:
int m_timer;
bool m_slowRenderTimer;
QVector<InstancePropertyPair> m_changedPropertyList;
QVector<qint32> m_componentCompletedVector;
QStringList m_importList;
};
......
......@@ -16,6 +16,7 @@
#include "reparentinstancescommand.h"
#include "changeidscommand.h"
#include "changestatecommand.h"
#include "completecomponentcommand.h"
#include "informationchangedcommand.h"
#include "pixmapchangedcommand.h"
......@@ -24,6 +25,7 @@
#include "childrenchangedcommand.h"
#include "imagecontainer.h"
#include "statepreviewimagechangedcommand.h"
#include "componentcompletedcommand.h"
namespace QmlDesigner {
......@@ -117,6 +119,12 @@ void NodeInstanceServerInterface::registerCommands()
qRegisterMetaType<StatePreviewImageChangedCommand>("StatePreviewImageChangedCommand");
qRegisterMetaTypeStreamOperators<StatePreviewImageChangedCommand>("StatePreviewImageChangedCommand");
qRegisterMetaType<CompleteComponentCommand>("CompleteComponentCommand");
qRegisterMetaTypeStreamOperators<CompleteComponentCommand>("CompleteComponentCommand");
qRegisterMetaType<ComponentCompletedCommand>("ComponentCompletedCommand");
qRegisterMetaTypeStreamOperators<ComponentCompletedCommand>("ComponentCompletedCommand");
}
}
......@@ -22,6 +22,7 @@
#include "changeidscommand.h"
#include "changestatecommand.h"
#include "addimportcommand.h"
#include "completecomponentcommand.h"
#include "informationchangedcommand.h"
#include "pixmapchangedcommand.h"
......@@ -29,6 +30,7 @@
#include "childrenchangedcommand.h"
#include "imagecontainer.h"
#include "statepreviewimagechangedcommand.h"
#include "componentcompletedcommand.h"
#include "nodeinstanceview.h"
#include "nodeinstanceclientproxy.h"
......@@ -78,6 +80,7 @@ void NodeInstanceServerProxy::dispatchCommand(const QVariant &command)
static const int pixmapChangedCommandType = QMetaType::type("PixmapChangedCommand");
static const int childrenChangedCommandType = QMetaType::type("ChildrenChangedCommand");
static const int statePreviewImageChangedCommandType = QMetaType::type("StatePreviewImageChangedCommand");
static const int componentCompletedCommandType = QMetaType::type("ComponentCompletedCommand");
if (command.userType() == informationChangedCommandType)
nodeInstanceClient()->informationChanged(command.value<InformationChangedCommand>());
......@@ -89,6 +92,8 @@ void NodeInstanceServerProxy::dispatchCommand(const QVariant &command)
nodeInstanceClient()->childrenChanged(command.value<ChildrenChangedCommand>());
else if (command.userType() == statePreviewImageChangedCommandType)
nodeInstanceClient()->statePreviewImagesChanged(command.value<StatePreviewImageChangedCommand>());
else if (command.userType() == componentCompletedCommandType)
nodeInstanceClient()->componentCompleted(command.value<ComponentCompletedCommand>());
else
Q_ASSERT(false);
}
......@@ -213,4 +218,9 @@ void NodeInstanceServerProxy::addImport(const AddImportCommand &command)
{
writeCommand(QVariant::fromValue(command));
}
void NodeInstanceServerProxy::completeComponent(const CompleteComponentCommand &command)
{
writeCommand(QVariant::fromValue(command));
}
} // namespace QmlDesigner
......@@ -37,6 +37,7 @@ public:
void changeIds(const ChangeIdsCommand &command);
void changeState(const ChangeStateCommand &command);
void addImport(const AddImportCommand &command);
void completeComponent(const CompleteComponentCommand &command);
void setBlockUpdates(bool block);
......
......@@ -73,6 +73,8 @@
#include "childrenchangedcommand.h"
#include "imagecontainer.h"
#include "statepreviewimagechangedcommand.h"
#include "completecomponentcommand.h"
#include "componentcompletedcommand.h"
#include "nodeinstanceserverproxy.h"
......@@ -144,6 +146,7 @@ void NodeInstanceView::modelAttached(Model *model)
nodeInstanceServer()->addImport(createImportCommand(import));
loadNodes(allModelNodes());
setBlockUpdates(false);
}
......@@ -176,6 +179,7 @@ void NodeInstanceView::nodeCreated(const ModelNode &createdNode)
NodeInstance instance = loadNode(createdNode);
nodeInstanceServer()->createInstances(createCreateInstancesCommand(QList<NodeInstance>() << instance));
nodeInstanceServer()->changePropertyValues(createChangeValueCommand(createdNode.variantProperties()));
nodeInstanceServer()->completeComponent(createComponentCompleteCommand(QList<NodeInstance>() << instance));
}
/*! \brief Notifing the view that a node was created.
......@@ -427,6 +431,10 @@ void NodeInstanceView::instancePropertyChange(const QList<QPair<ModelNode, QStri
}
void NodeInstanceView::instancesCompleted(const QVector<ModelNode> &/*completedNodeList*/)
{
}
void NodeInstanceView::importAdded(const Import &import)
{
nodeInstanceServer()->addImport(createImportCommand(import));
......@@ -456,17 +464,12 @@ void NodeInstanceView::loadNodes(const QList<ModelNode> &nodeList)
bindingPropertyList.append(node.bindingProperties());
}
// QListIterator<ModelNode> listIterator(nodeList);