QmlDesigner.NodeInstances: Refactor NodeInstanceServer

NodeInstanceServer is now abstract. The informations are now sent by the
InformationNodeInstanceServer.

Reviewed-By: Thomas Hartmann
This commit is contained in:
Marco Bubke
2011-05-12 16:22:51 +02:00
parent 3dfb402706
commit 1366b12215
10 changed files with 473 additions and 135 deletions
@@ -0,0 +1,284 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "informationnodeinstanceserver.h"
#include <QGraphicsItem>
#include <private/qgraphicsitem_p.h>
#include <private/qgraphicsscene_p.h>
#include <QDeclarativeEngine>
#include <QDeclarativeView>
#include <QFileSystemWatcher>
#include <QUrl>
#include <QSet>
#include <QDir>
#include <QVariant>
#include <QMetaType>
#include <QDeclarativeComponent>
#include <QDeclarativeContext>
#include <private/qlistmodelinterface_p.h>
#include <QAbstractAnimation>
#include <private/qabstractanimation_p.h>
#include "servernodeinstance.h"
#include "childrenchangeeventfilter.h"
#include "propertyabstractcontainer.h"
#include "propertybindingcontainer.h"
#include "propertyvaluecontainer.h"
#include "instancecontainer.h"
#include "createinstancescommand.h"
#include "changefileurlcommand.h"
#include "clearscenecommand.h"
#include "reparentinstancescommand.h"
#include "changevaluescommand.h"
#include "changebindingscommand.h"
#include "changeidscommand.h"
#include "removeinstancescommand.h"
#include "nodeinstanceclientinterface.h"
#include "removepropertiescommand.h"
#include "valueschangedcommand.h"
#include "informationchangedcommand.h"
#include "pixmapchangedcommand.h"
#include "commondefines.h"
#include "childrenchangeeventfilter.h"
#include "changestatecommand.h"
#include "addimportcommand.h"
#include "childrenchangedcommand.h"
#include "completecomponentcommand.h"
#include "componentcompletedcommand.h"
#include "createscenecommand.h"
#include "dummycontextobject.h"
namespace QmlDesigner {
InformationNodeInstanceServer::InformationNodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient) :
NodeInstanceServer(nodeInstanceClient)
{
}
void InformationNodeInstanceServer::collectItemChangesAndSendChangeCommands()
{
static bool inFunction = false;
if (!inFunction) {
inFunction = true;
QSet<ServerNodeInstance> informationChangedInstanceSet;
QVector<InstancePropertyPair> propertyChangedList;
bool adjustSceneRect = false;
if (delcarativeView()) {
foreach (QGraphicsItem *item, delcarativeView()->items()) {
QGraphicsObject *graphicsObject = item->toGraphicsObject();
if (graphicsObject && hasInstanceForObject(graphicsObject)) {
ServerNodeInstance instance = instanceForObject(graphicsObject);
QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(item);
if (d->dirtySceneTransform || d->geometryChanged || d->dirty)
informationChangedInstanceSet.insert(instance);
if (d->geometryChanged) {
if (instance.isRootNodeInstance())
delcarativeView()->scene()->setSceneRect(item->boundingRect());
}
}
}
foreach (const InstancePropertyPair& property, changedPropertyList()) {
const ServerNodeInstance instance = property.first;
const QString propertyName = property.second;
if (instance.isValid()) {
if (instance.isRootNodeInstance() && (propertyName == "width" || propertyName == "height"))
adjustSceneRect = true;
if (propertyName.contains("anchors"))
informationChangedInstanceSet.insert(instance);
if (propertyName == "parent") {
informationChangedInstanceSet.insert(instance);
m_parentChangedSet.insert(instance);
}
propertyChangedList.append(property);
}
}
clearChangedPropertyList();
resetAllItems();
if (!informationChangedInstanceSet.isEmpty())
nodeInstanceClient()->informationChanged(createAllInformationChangedCommand(informationChangedInstanceSet.toList()));
if (!propertyChangedList.isEmpty())
nodeInstanceClient()->valuesChanged(createValuesChangedCommand(propertyChangedList));
if (!m_parentChangedSet.isEmpty()) {
sendChildrenChangedCommand(m_parentChangedSet.toList());
m_parentChangedSet.clear();
}
if (adjustSceneRect) {
QRectF boundingRect = rootNodeInstance().boundingRect();
if (boundingRect.isValid()) {
delcarativeView()->setSceneRect(boundingRect);
}
}
if (!m_completedComponentList.isEmpty()) {
nodeInstanceClient()->componentCompleted(createComponentCompletedCommand(m_completedComponentList));
m_completedComponentList.clear();
}
slowDownRenderTimer();
nodeInstanceClient()->flush();
nodeInstanceClient()->synchronizeWithClientProcess();
}
inFunction = false;
}
}
void InformationNodeInstanceServer::reparentInstances(const ReparentInstancesCommand &command)
{
foreach(const ReparentContainer &container, command.reparentInstances()) {
ServerNodeInstance instance = instanceForId(container.instanceId());
if (instance.isValid()) {
m_parentChangedSet.insert(instance);
}
}
NodeInstanceServer::reparentInstances(command);
}
void InformationNodeInstanceServer::clearScene(const ClearSceneCommand &command)
{
NodeInstanceServer::clearScene(command);
m_parentChangedSet.clear();
m_completedComponentList.clear();
}
void InformationNodeInstanceServer::createScene(const CreateSceneCommand &command)
{
NodeInstanceServer::createScene(command);
QList<ServerNodeInstance> instanceList;
foreach(const InstanceContainer &container, command.instances()) {
ServerNodeInstance instance = instanceForId(container.instanceId());
if (instance.isValid()) {
instanceList.append(instance);
}
}
nodeInstanceClient()->informationChanged(createAllInformationChangedCommand(instanceList, true));
nodeInstanceClient()->valuesChanged(createValuesChangedCommand(instanceList));
sendChildrenChangedCommand(instanceList);
nodeInstanceClient()->componentCompleted(createComponentCompletedCommand(instanceList));
}
void InformationNodeInstanceServer::sendChildrenChangedCommand(const QList<ServerNodeInstance> childList)
{
QSet<ServerNodeInstance> parentSet;
QList<ServerNodeInstance> noParentList;
foreach (const ServerNodeInstance &child, childList) {
if (!child.hasParent())
noParentList.append(child);
else
parentSet.insert(child.parent());
}
foreach (const ServerNodeInstance &parent, parentSet)
nodeInstanceClient()->childrenChanged(createChildrenChangedCommand(parent, parent.childItems()));
if (!noParentList.isEmpty())
nodeInstanceClient()->childrenChanged(createChildrenChangedCommand(ServerNodeInstance(), noParentList));
}
void InformationNodeInstanceServer::completeComponent(const CompleteComponentCommand &command)
{
NodeInstanceServer::completeComponent(command);
QList<ServerNodeInstance> instanceList;
foreach(qint32 instanceId, command.instances()) {
ServerNodeInstance instance = instanceForId(instanceId);
if (instance.isValid()) {
instanceList.append(instance);
}
}
m_completedComponentList.append(instanceList);
nodeInstanceClient()->valuesChanged(createValuesChangedCommand(instanceList));
nodeInstanceClient()->informationChanged(createAllInformationChangedCommand(instanceList, true));
}
} // namespace QmlDesigner
@@ -0,0 +1,94 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef INFORMATIONNODEINSTANCESERVER_H
#define INFORMATIONNODEINSTANCESERVER_H
#include "nodeinstanceserver.h"
namespace QmlDesigner {
class InformationNodeInstanceServer : public NodeInstanceServer
{
Q_OBJECT
public:
explicit InformationNodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient);
void reparentInstances(const ReparentInstancesCommand &command);
void clearScene(const ClearSceneCommand &command);
void createScene(const CreateSceneCommand &command);
void completeComponent(const CompleteComponentCommand &command);
protected:
void collectItemChangesAndSendChangeCommands();
void sendChildrenChangedCommand(const QList<ServerNodeInstance> childList);
private:
QSet<ServerNodeInstance> m_parentChangedSet;
QList<ServerNodeInstance> m_completedComponentList;
};
} // namespace QmlDesigner
#endif // INFORMATIONNODEINSTANCESERVER_H
@@ -3,6 +3,7 @@ INCLUDEPATH += $$PWD/../include
HEADERS += $$PWD/behaviornodeinstance.h
HEADERS += $$PWD/informationnodeinstanceserver.h
HEADERS += $$PWD/dummycontextobject.h
HEADERS += $$PWD/rendernodeinstanceserver.h
HEADERS += $$PWD/synchronizecommand.h
@@ -53,6 +54,7 @@ HEADERS += $$PWD/../include/nodeinstanceserverinterface.h
SOURCES += $$PWD/behaviornodeinstance.cpp
SOURCES += $$PWD/informationnodeinstanceserver.cpp
SOURCES += $$PWD/dummycontextobject.cpp
SOURCES += $$PWD/rendernodeinstanceserver.cpp
SOURCES += $$PWD/synchronizecommand.cpp
@@ -37,7 +37,7 @@
#include <QCoreApplication>
#include <QStringList>
#include "nodeinstanceserver.h"
#include "informationnodeinstanceserver.h"
#include "previewnodeinstanceserver.h"
#include "rendernodeinstanceserver.h"
@@ -82,7 +82,7 @@ NodeInstanceClientProxy::NodeInstanceClientProxy(QObject *parent)
if (QCoreApplication::arguments().at(2) == QLatin1String("previewmode")) {
m_nodeInstanceServer = new PreviewNodeInstanceServer(this);
} else if (QCoreApplication::arguments().at(2) == QLatin1String("editormode")) {
m_nodeInstanceServer = new NodeInstanceServer(this);
m_nodeInstanceServer = new InformationNodeInstanceServer(this);
} else if (QCoreApplication::arguments().at(2) == QLatin1String("rendermode")) {
m_nodeInstanceServer = new RenderNodeInstanceServer(this);
}
@@ -80,9 +80,6 @@
#include "dummycontextobject.h"
#include <iostream>
#include <stdio.h>
namespace QmlDesigner {
@@ -237,12 +234,6 @@ void NodeInstanceServer::createScene(const CreateSceneCommand &command)
refreshBindings();
nodeInstanceClient()->informationChanged(createAllInformationChangedCommand(instanceList, true));
nodeInstanceClient()->valuesChanged(createValuesChangedCommand(instanceList));
sendChildrenChangedCommand(instanceList);
nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(instanceList));
nodeInstanceClient()->componentCompleted(createComponentCompletedCommand(instanceList));
startRenderTimer();
}
@@ -296,7 +287,6 @@ void NodeInstanceServer::reparentInstances(const QVector<ReparentContainer> &con
ServerNodeInstance instance = instanceForId(container.instanceId());
if (instance.isValid()) {
instance.reparent(instanceForId(container.oldParentInstanceId()), container.oldParentProperty(), instanceForId(container.newParentInstanceId()), container.newParentProperty());
m_parentChangedSet.insert(instance);
}
}
@@ -336,13 +326,8 @@ void NodeInstanceServer::completeComponent(const CompleteComponentCommand &comma
}
}
m_completedComponentList.append(instanceList);
refreshBindings();
nodeInstanceClient()->valuesChanged(createValuesChangedCommand(instanceList));
nodeInstanceClient()->informationChanged(createAllInformationChangedCommand(instanceList, true));
nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(instanceList));
startRenderTimer();
}
@@ -763,7 +748,7 @@ void NodeInstanceServer::clearStateInstance()
void NodeInstanceServer::timerEvent(QTimerEvent *event)
{
if (event->timerId() == m_timer) {
findItemChangesAndSendChangeCommands();
collectItemChangesAndSendChangeCommands();
}
NodeInstanceServerInterface::timerEvent(event);
@@ -774,27 +759,6 @@ NodeInstanceClientInterface *NodeInstanceServer::nodeInstanceClient() const
return m_nodeInstanceClient;
}
void NodeInstanceServer::sendChildrenChangedCommand(const QList<ServerNodeInstance> childList)
{
QSet<ServerNodeInstance> parentSet;
QList<ServerNodeInstance> noParentList;
foreach (const ServerNodeInstance &child, childList) {
if (!child.hasParent())
noParentList.append(child);
else
parentSet.insert(child.parent());
}
foreach (const ServerNodeInstance &parent, parentSet)
nodeInstanceClient()->childrenChanged(createChildrenChangedCommand(parent, parent.childItems()));
if (!noParentList.isEmpty())
nodeInstanceClient()->childrenChanged(createChildrenChangedCommand(ServerNodeInstance(), noParentList));
}
ChildrenChangedCommand NodeInstanceServer::createChildrenChangedCommand(const ServerNodeInstance &parentInstance, const QList<ServerNodeInstance> &instanceList) const
{
QVector<qint32> instanceVector;
@@ -1184,90 +1148,8 @@ QList<ServerNodeInstance> NodeInstanceServer::setupScene(const CreateSceneComman
return instanceList;
}
void NodeInstanceServer::findItemChangesAndSendChangeCommands()
{
static bool inFunction = false;
if (!inFunction) {
inFunction = true;
QSet<ServerNodeInstance> informationChangedInstanceSet;
QVector<InstancePropertyPair> propertyChangedList;
bool adjustSceneRect = false;
if (m_declarativeView) {
foreach (QGraphicsItem *item, m_declarativeView->items()) {
QGraphicsObject *graphicsObject = item->toGraphicsObject();
if (graphicsObject && hasInstanceForObject(graphicsObject)) {
ServerNodeInstance instance = instanceForObject(graphicsObject);
QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(item);
if (d->dirtySceneTransform || d->geometryChanged || d->dirty)
informationChangedInstanceSet.insert(instance);
if (d->geometryChanged) {
if (instance.isRootNodeInstance())
m_declarativeView->scene()->setSceneRect(item->boundingRect());
}
}
}
foreach (const InstancePropertyPair& property, m_changedPropertyList) {
const ServerNodeInstance instance = property.first;
const QString propertyName = property.second;
if (instance.isValid()) {
if (instance.isRootNodeInstance() && (propertyName == "width" || propertyName == "height"))
adjustSceneRect = true;
if (propertyName.contains("anchors"))
informationChangedInstanceSet.insert(instance);
if (propertyName == "parent") {
informationChangedInstanceSet.insert(instance);
m_parentChangedSet.insert(instance);
}
propertyChangedList.append(property);
}
}
m_changedPropertyList.clear();
resetAllItems();
if (!informationChangedInstanceSet.isEmpty())
nodeInstanceClient()->informationChanged(createAllInformationChangedCommand(informationChangedInstanceSet.toList()));
if (!propertyChangedList.isEmpty())
nodeInstanceClient()->valuesChanged(createValuesChangedCommand(propertyChangedList));
if (!m_parentChangedSet.isEmpty()) {
sendChildrenChangedCommand(m_parentChangedSet.toList());
m_parentChangedSet.clear();
}
if (adjustSceneRect) {
QRectF boundingRect = m_rootNodeInstance.boundingRect();
if (boundingRect.isValid()) {
m_declarativeView->setSceneRect(boundingRect);
}
}
if (!m_completedComponentList.isEmpty()) {
nodeInstanceClient()->componentCompleted(createComponentCompletedCommand(m_completedComponentList));
m_completedComponentList.clear();
}
slowDownRenderTimer();
nodeInstanceClient()->flush();
nodeInstanceClient()->synchronizeWithClientProcess();
}
inFunction = false;
}
}
}
@@ -146,7 +146,7 @@ protected:
void timerEvent(QTimerEvent *);
bool nonInstanceChildIsDirty(QGraphicsObject *graphicsObject) const;
virtual void findItemChangesAndSendChangeCommands();
virtual void collectItemChangesAndSendChangeCommands() = 0;
void resetAllItems();
ValuesChangedCommand createValuesChangedCommand(const QList<ServerNodeInstance> &instanceList) const;
@@ -155,7 +155,6 @@ protected:
InformationChangedCommand createAllInformationChangedCommand(const QList<ServerNodeInstance> &instanceList, bool initial = false) const;
ChildrenChangedCommand createChildrenChangedCommand(const ServerNodeInstance &parentInstance, const QList<ServerNodeInstance> &instanceList) const;
ComponentCompletedCommand createComponentCompletedCommand(const QList<ServerNodeInstance> &instanceList);
void sendChildrenChangedCommand(const QList<ServerNodeInstance> childList);
void addChangedProperty(const InstancePropertyPair &property);
@@ -206,8 +205,6 @@ private:
int m_slowRenderTimerInterval;
QVector<InstancePropertyPair> m_changedPropertyList;
QStringList m_importList;
QSet<ServerNodeInstance> m_parentChangedSet;
QList<ServerNodeInstance> m_completedComponentList;
QWeakPointer<QObject> m_dummyContextObject;
QWeakPointer<QDeclarativeComponent> m_importComponent;
QWeakPointer<QObject> m_importComponentObject;
@@ -60,7 +60,7 @@ void PreviewNodeInstanceServer::startRenderTimer()
setTimerId(timerId);
}
void PreviewNodeInstanceServer::findItemChangesAndSendChangeCommands()
void PreviewNodeInstanceServer::collectItemChangesAndSendChangeCommands()
{
static bool inFunction = false;
@@ -46,7 +46,7 @@ public:
void changeState(const ChangeStateCommand &command);
protected:
void findItemChangesAndSendChangeCommands();
void collectItemChangesAndSendChangeCommands();
void startRenderTimer();
private:
@@ -32,14 +32,52 @@
#include "rendernodeinstanceserver.h"
#include "nodeinstanceclientinterface.h"
#include "pixmapchangedcommand.h"
#include <QDeclarativeView>
#include <QGraphicsItem>
#include <private/qgraphicsitem_p.h>
#include <private/qgraphicsscene_p.h>
#include <QDeclarativeEngine>
#include <QDeclarativeView>
#include <QFileSystemWatcher>
#include <QUrl>
#include <QSet>
#include <QDir>
#include <QVariant>
#include <QMetaType>
#include <QDeclarativeComponent>
#include <QDeclarativeContext>
#include <private/qlistmodelinterface_p.h>
#include <QAbstractAnimation>
#include <private/qabstractanimation_p.h>
#include "servernodeinstance.h"
#include "childrenchangeeventfilter.h"
#include "propertyabstractcontainer.h"
#include "propertybindingcontainer.h"
#include "propertyvaluecontainer.h"
#include "instancecontainer.h"
#include "createinstancescommand.h"
#include "changefileurlcommand.h"
#include "clearscenecommand.h"
#include "reparentinstancescommand.h"
#include "changevaluescommand.h"
#include "changebindingscommand.h"
#include "changeidscommand.h"
#include "removeinstancescommand.h"
#include "nodeinstanceclientinterface.h"
#include "removepropertiescommand.h"
#include "valueschangedcommand.h"
#include "informationchangedcommand.h"
#include "pixmapchangedcommand.h"
#include "commondefines.h"
#include "childrenchangeeventfilter.h"
#include "changestatecommand.h"
#include "addimportcommand.h"
#include "childrenchangedcommand.h"
#include "completecomponentcommand.h"
#include "componentcompletedcommand.h"
#include "createscenecommand.h"
#include "dummycontextobject.h"
namespace QmlDesigner {
@@ -48,7 +86,7 @@ RenderNodeInstanceServer::RenderNodeInstanceServer(NodeInstanceClientInterface *
{
}
void RenderNodeInstanceServer::findItemChangesAndSendChangeCommands()
void RenderNodeInstanceServer::collectItemChangesAndSendChangeCommands()
{
static bool inFunction = false;
if (!inFunction) {
@@ -109,4 +147,41 @@ void RenderNodeInstanceServer::findItemChangesAndSendChangeCommands()
}
}
void RenderNodeInstanceServer::createScene(const CreateSceneCommand &command)
{
NodeInstanceServer::createScene(command);
QList<ServerNodeInstance> instanceList;
foreach(const InstanceContainer &container, command.instances()) {
ServerNodeInstance instance = instanceForId(container.instanceId());
if (instance.isValid()) {
instanceList.append(instance);
}
}
nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(instanceList));
}
void RenderNodeInstanceServer::clearScene(const ClearSceneCommand &command)
{
NodeInstanceServer::clearScene(command);
m_dirtyInstanceSet.clear();
}
void RenderNodeInstanceServer::completeComponent(const CompleteComponentCommand &command)
{
NodeInstanceServer::completeComponent(command);
QList<ServerNodeInstance> instanceList;
foreach(qint32 instanceId, command.instances()) {
ServerNodeInstance instance = instanceForId(instanceId);
if (instance.isValid()) {
instanceList.append(instance);
}
}
nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(instanceList));
}
} // namespace QmlDesigner
@@ -43,8 +43,12 @@ class RenderNodeInstanceServer : public NodeInstanceServer
public:
explicit RenderNodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient);
void createScene(const CreateSceneCommand &command);
void clearScene(const ClearSceneCommand &command);
void completeComponent(const CompleteComponentCommand &command);
protected:
void findItemChangesAndSendChangeCommands();
void collectItemChangesAndSendChangeCommands();
private:
QSet<ServerNodeInstance> m_dirtyInstanceSet;