diff options
author | Marco Bubke <marco.bubke@nokia.com> | 2010-11-24 14:52:06 +0100 |
---|---|---|
committer | Marco Bubke <marco.bubke@nokia.com> | 2010-11-24 15:52:22 +0100 |
commit | ed42462889b2835f99c714b84fa0db44780a9a26 (patch) | |
tree | 1b73d7245eef8ac47e2e57b68b03152b5940ea70 | |
parent | f123af08b7ce5842e053e855c375ff82f84377f7 (diff) |
QmlDesigner.Instances: Move instances out of process
The complete qml emulation layer (instances) is moved
into another external process (qmlpuppet).
Summary of architectural changes:
- Asynchronous messaging
Handling commands and data transfer asynchronously reduces the
amount of context switches between processes.
- Proxy classes for client process
This classes abstract the inter process communication
- QVariant based command parsing and serialization
Using LocalSocket in bidirectional manner for communications
of commands and data transfer.
- Integer based identifier instead of ModelNode in client process
The qml emulation layer (instances) has no more depencies to our
internal data model.
- Timer based rendering
Rendering in instances is controlled by a timer. Only dirty items
are updated.
113 files changed, 5447 insertions, 2991 deletions
diff --git a/.gitignore b/.gitignore index 7490f48076..1c232b4c9d 100644 --- a/.gitignore +++ b/.gitignore @@ -78,6 +78,8 @@ bin/*.dll bin/qtcreator bin/qtcreator_process_stub* bin/qtcreator.exe +bin/qmlpuppet +bin/qmlpuppet.exe share/doc/qtcreator/qtcreator.qch src/tools/gen-cpp-ast/generate-ast src/tools/mkvisitor/cplusplus0 diff --git a/src/plugins/qmldesigner/components/formeditor/formeditoritem.cpp b/src/plugins/qmldesigner/components/formeditor/formeditoritem.cpp index c6717ab534..cc19e7221f 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditoritem.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditoritem.cpp @@ -34,7 +34,8 @@ #include <modelnode.h> #include <nodemetainfo.h> -#include <widgetqueryview.h> +#include <qmlanchors.h> + #include <QGraphicsSceneMouseEvent> #include <QDebug> @@ -72,10 +73,7 @@ void FormEditorItem::setup() { if (qmlItemNode().hasInstanceParent()) { setParentItem(scene()->itemForQmlItemNode(qmlItemNode().instanceParent().toQmlItemNode())); - setVisible(true); setOpacity(qmlItemNode().instanceValue("opacity").toDouble()); - } else if (!qmlItemNode().isRootNode()){ - setVisible(false); } setFlag(QGraphicsItem::ItemClipsChildrenToShape, qmlItemNode().instanceValue("clip").toBool()); diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp index 6e0d7b8b24..65eac44dec 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp @@ -144,7 +144,6 @@ void FormEditorScene::synchronizeTransformation(const QmlItemNode &qmlItemNode) { FormEditorItem *item = itemForQmlItemNode(qmlItemNode); item->updateGeometry(); - item->update(); if (qmlItemNode.isRootNode()) { QRectF sceneRect(qmlItemNode.instanceBoundingRect()); @@ -175,8 +174,6 @@ void FormEditorScene::synchronizeOtherProperty(const QmlItemNode &qmlItemNode, c if (propertyName == "visible") item->setContentVisible(qmlItemNode.instanceValue("visible").toBool()); - if (item) - item->update(); } } @@ -344,13 +341,6 @@ void FormEditorScene::reparentItem(const QmlItemNode &node, const QmlItemNode &n if (item->parentItem() != parentItem) { item->setParentItem(parentItem); - if (parentItem) { - item->setVisible(true); - } else { - item->setVisible(false); - } - - item->update(); } } @@ -380,7 +370,6 @@ void FormEditorScene::clearFormEditorItems() foreach (QGraphicsItem *item, itemList) { if (qgraphicsitem_cast<FormEditorItem* >(item)) { item->setParentItem(0); - item->setVisible(false); } } diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp index c91609c24d..585999a4c1 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp +++ b/src/plugins/qmldesigner/components/formeditor/formeditorview.cpp @@ -40,7 +40,6 @@ #include "formeditorscene.h" #include <rewritertransaction.h> #include <modelnode.h> -#include <modelutilities.h> #include <itemlibraryinfo.h> #include <metainfo.h> #include <model.h> @@ -451,6 +450,33 @@ void FormEditorView::customNotification(const AbstractView *view, const QString m_formEditorWidget->setFeedbackNode(QmlItemNode()); } + if (identifier == "__instance information changed__") { + QList<FormEditorItem*> itemNodeList; + + foreach (const ModelNode &node, nodeList) { + QmlItemNode qmlItemNode(node); + if (qmlItemNode.isValid() && scene()->hasItemForQmlItemNode(qmlItemNode)) { + scene()->synchronizeParent(qmlItemNode); + scene()->synchronizeTransformation(qmlItemNode); + itemNodeList.append(scene()->itemForQmlItemNode(qmlItemNode)); + } + } + + m_currentTool->formEditorItemsChanged(itemNodeList); + + } + + if (identifier == "__instance render pixmap changed__") { + QList<FormEditorItem*> itemNodeList; + + foreach (const ModelNode &node, nodeList) { + QmlItemNode qmlItemNode(node); + if (qmlItemNode.isValid() && scene()->hasItemForQmlItemNode(qmlItemNode)) { + scene()->itemForQmlItemNode(qmlItemNode)->update(); + } + } + } + QmlModelView::customNotification(view, identifier, nodeList, data); } @@ -509,26 +535,6 @@ QmlItemNode findRecursiveQmlItemNode(const QmlObjectNode &firstQmlObjectNode) return QmlItemNode(); } -void FormEditorView::transformChanged(const QmlObjectNode &qmlObjectNode, const QString &/*propertyName*/) -{ - QmlItemNode itemNode = qmlObjectNode.toQmlItemNode(); - if (itemNode.isValid() && scene()->hasItemForQmlItemNode(itemNode)) { - m_scene->synchronizeTransformation(itemNode); - m_currentTool->formEditorItemsChanged(QList<FormEditorItem*>() << m_scene->itemForQmlItemNode(itemNode)); - } - - scene()->update(); -} - -void FormEditorView::parentChanged(const QmlObjectNode &qmlObjectNode) -{ - QmlItemNode itemNode = qmlObjectNode.toQmlItemNode(); - if (itemNode.isValid() && scene()->hasItemForQmlItemNode(itemNode)) { - scene()->synchronizeParent(itemNode); - m_currentTool->formEditorItemsChanged(QList<FormEditorItem*>() << m_scene->itemForQmlItemNode(itemNode)); - } -} - void FormEditorView::otherPropertyChanged(const QmlObjectNode &qmlObjectNode, const QString &propertyName) { Q_ASSERT(qmlObjectNode.isValid()); @@ -556,7 +562,6 @@ void FormEditorView::stateChanged(const QmlModelState &newQmlModelState, const Q { QmlModelView::stateChanged(newQmlModelState, oldQmlModelState); - m_formEditorWidget->anchorToolAction()->setEnabled(newQmlModelState.isBaseState()); if (!newQmlModelState.isBaseState() && currentTool() == m_anchorTool) { diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorview.h b/src/plugins/qmldesigner/components/formeditor/formeditorview.h index 7363f79743..2fbf9fec3b 100644 --- a/src/plugins/qmldesigner/components/formeditor/formeditorview.h +++ b/src/plugins/qmldesigner/components/formeditor/formeditorview.h @@ -112,8 +112,6 @@ signals: void ItemCreatorDeActivated(); protected: - void transformChanged(const QmlObjectNode &qmlObjectNode, const QString &propertyName); - void parentChanged(const QmlObjectNode &qmlObjectNode); void otherPropertyChanged(const QmlObjectNode &qmlObjectNode, const QString &propertyName); void stateChanged(const QmlModelState &newQmlModelState, const QmlModelState &oldQmlModelState); diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp index acda0ca8c5..7605b7ea51 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp @@ -81,12 +81,8 @@ void StatesEditorView::setCurrentStateSilent(int index) return; } - nodeInstanceView()->setBlockStatePropertyChanges(true); - QmlModelView::activateState(state); - nodeInstanceView()->setBlockStatePropertyChanges(false); - m_settingSilentState = false; } @@ -478,45 +474,47 @@ void StatesEditorView::selectedNodesChanged(const QList<ModelNode> &/*selectedNo QPixmap StatesEditorView::renderState(int i) { - if (debug) - qDebug() << __FUNCTION__ << i; + return QPixmap(); + +// if (debug) +// qDebug() << __FUNCTION__ << i; - if (!m_attachedToModel) - return QPixmap(); +// if (!m_attachedToModel) +// return QPixmap(); - Q_ASSERT(i >= 0 && i < m_modelStates.size()); - QmlModelState oldState = currentState(); - setCurrentStateSilent(i); +// Q_ASSERT(i >= 0 && i < m_modelStates.size()); +// QmlModelState oldState = currentState(); +// setCurrentStateSilent(i); - Q_ASSERT(nodeInstanceView()); +// Q_ASSERT(nodeInstanceView()); - const int checkerbordSize= 10; - QPixmap tilePixmap(checkerbordSize * 2, checkerbordSize * 2); - tilePixmap.fill(Qt::white); - QPainter tilePainter(&tilePixmap); - QColor color(220, 220, 220); - tilePainter.fillRect(0, 0, checkerbordSize, checkerbordSize, color); - tilePainter.fillRect(checkerbordSize, checkerbordSize, checkerbordSize, checkerbordSize, color); - tilePainter.end(); +// const int checkerbordSize= 10; +// QPixmap tilePixmap(checkerbordSize * 2, checkerbordSize * 2); +// tilePixmap.fill(Qt::white); +// QPainter tilePainter(&tilePixmap); +// QColor color(220, 220, 220); +// tilePainter.fillRect(0, 0, checkerbordSize, checkerbordSize, color); +// tilePainter.fillRect(checkerbordSize, checkerbordSize, checkerbordSize, checkerbordSize, color); +// tilePainter.end(); - QSizeF pixmapSize(nodeInstanceView()->sceneRect().size()); - if (pixmapSize.width() > 100 || pixmapSize.height() > 100) // sensible maximum size - pixmapSize.scale(QSize(100, 100), Qt::KeepAspectRatio); - QSize cutSize(floor(pixmapSize.width()),floor(pixmapSize.height())); - pixmapSize.setWidth(ceil(pixmapSize.width())); - pixmapSize.setHeight(ceil(pixmapSize.height())); - QPixmap pixmap(pixmapSize.toSize()); +// QSizeF pixmapSize(nodeInstanceView()->sceneRect().size()); +// if (pixmapSize.width() > 100 || pixmapSize.height() > 100) // sensible maximum size +// pixmapSize.scale(QSize(100, 100), Qt::KeepAspectRatio); +// QSize cutSize(floor(pixmapSize.width()),floor(pixmapSize.height())); +// pixmapSize.setWidth(ceil(pixmapSize.width())); +// pixmapSize.setHeight(ceil(pixmapSize.height())); +// QPixmap pixmap(pixmapSize.toSize()); - QPainter painter(&pixmap); - painter.drawTiledPixmap(pixmap.rect(), tilePixmap); - nodeInstanceView()->render(&painter, pixmap.rect(), nodeInstanceView()->sceneRect()); +// QPainter painter(&pixmap); +// painter.drawTiledPixmap(pixmap.rect(), tilePixmap); +// nodeInstanceView()->render(&painter, pixmap.rect(), nodeInstanceView()->sceneRect()); - setCurrentStateSilent(m_modelStates.indexOf(oldState)); +// setCurrentStateSilent(m_modelStates.indexOf(oldState)); - Q_ASSERT(oldState == currentState()); +// Q_ASSERT(oldState == currentState()); - return pixmap.copy(0,0,cutSize.width(),cutSize.height()); +// return pixmap.copy(0,0,cutSize.width(),cutSize.height()); } void StatesEditorView::sceneChanged() diff --git a/src/plugins/qmldesigner/designercore/designercore.pri b/src/plugins/qmldesigner/designercore/designercore.pri index 1ab502c61f..6c480b8d17 100644 --- a/src/plugins/qmldesigner/designercore/designercore.pri +++ b/src/plugins/qmldesigner/designercore/designercore.pri @@ -2,7 +2,7 @@ include($$PWD/filemanager/filemanager.pri) include (../config.pri) QT += script \ - declarative + network DEFINES += TEST_EXPORTS INCLUDEPATH += $$PWD \ @@ -27,15 +27,9 @@ SOURCES += $$PWD/model/abstractview.cpp \ $$PWD/model/propertycontainer.cpp \ $$PWD/pluginmanager/widgetpluginmanager.cpp \ $$PWD/pluginmanager/widgetpluginpath.cpp \ - $$PWD/instances/nodeinstance.cpp \ + $$PWD/instances/servernodeinstance.cpp \ $$PWD/instances/objectnodeinstance.cpp \ - $$PWD/instances/widgetnodeinstance.cpp \ - $$PWD/instances/graphicswidgetnodeinstance.cpp \ $$PWD/instances/qmlgraphicsitemnodeinstance.cpp \ - $$PWD/instances/graphicsscenenodeinstance.cpp \ - $$PWD/instances/graphicsviewnodeinstance.cpp \ - $$PWD/instances/proxywidgetnodeinstance.cpp \ - $$PWD/instances/qmlviewnodeinstance.cpp \ $$PWD/instances/dummynodeinstance.cpp \ $$PWD/instances/qmlpropertychangesnodeinstance.cpp \ $$PWD/instances/qmlstatenodeinstance.cpp \ @@ -95,8 +89,35 @@ SOURCES += $$PWD/model/abstractview.cpp \ $$PWD/instances/nodeinstancemetaobject.cpp \ $$PWD/instances/behaviornodeinstance.cpp \ $$PWD/instances/nodeinstancesignalspy.cpp \ - $$PWD/instances/positionernodeinstance.cpp - + $$PWD/instances/positionernodeinstance.cpp \ + $$PWD/instances/nodeinstanceserver.cpp \ + $$PWD/instances/declarativedesignercommunicationinterface.cpp \ + $$PWD/instances/createinstancescommand.cpp \ + $$PWD/instances/nodeinstanceserverinterface.cpp \ + $$PWD/instances/nodeinstance.cpp \ + $$PWD/instances/propertyvaluecontainer.cpp \ + $$PWD/instances/childrenchangeeventfilter.cpp \ + $$PWD/instances/propertybindingcontainer.cpp \ + $$PWD/instances/propertyabstractcontainer.cpp \ + $$PWD/instances/createscenecommand.cpp \ + $$PWD/instances/instancecontainer.cpp \ + $$PWD/instances/changefileurlcommand.cpp \ + $$PWD/instances/clearscenecommand.cpp \ + $$PWD/instances/reparentcontainer.cpp \ + $$PWD/instances/reparentinstancescommand.cpp \ + $$PWD/instances/changevaluescommand.cpp \ + $$PWD/instances/changebindingscommand.cpp \ + $$PWD/instances/changeidscommand.cpp \ + $$PWD/instances/idcontainer.cpp \ + $$PWD/instances/removeinstancescommand.cpp \ + $$PWD/instances/removepropertiescommand.cpp \ + $$PWD/instances/valueschangedcommand.cpp \ + $$PWD/instances/pixmapchangedcommand.cpp \ + $$PWD/instances/informationchangedcommand.cpp \ + $$PWD/instances/informationcontainer.cpp \ + $$PWD/instances/changestatecommand.cpp \ + $$PWD/instances/nodeinstanceserverproxy.cpp \ + $$PWD/instances/nodeinstanceclientproxy.cpp HEADERS += $$PWD/include/corelib_global.h \ $$PWD/include/abstractview.h \ $$PWD/include/nodeinstanceview.h \ @@ -111,7 +132,6 @@ HEADERS += $$PWD/include/corelib_global.h \ $$PWD/include/modelnode.h \ $$PWD/include/model.h \ $$PWD/include/nodeproperty.h \ - $$PWD/include/widgetqueryview.h \ $$PWD/include/subcomponentmanager.h \ $$PWD/include/propertycontainer.h \ $$PWD/model/internalnode_p.h \ @@ -120,15 +140,9 @@ HEADERS += $$PWD/include/corelib_global.h \ $$PWD/model/propertyparser.h \ $$PWD/pluginmanager/widgetpluginmanager.h \ $$PWD/pluginmanager/widgetpluginpath.h \ - $$PWD/include/nodeinstance.h \ + $$PWD/instances/servernodeinstance.h \ $$PWD/instances/objectnodeinstance.h \ - $$PWD/instances/widgetnodeinstance.h \ - $$PWD/instances/graphicswidgetnodeinstance.h \ $$PWD/instances/qmlgraphicsitemnodeinstance.h \ - $$PWD/instances/graphicsscenenodeinstance.h \ - $$PWD/instances/graphicsviewnodeinstance.h \ - $$PWD/instances/proxywidgetnodeinstance.h \ - $$PWD/instances/qmlviewnodeinstance.h \ $$PWD/instances/dummynodeinstance.h \ $$PWD/instances/qmlpropertychangesnodeinstance.h \ $$PWD/instances/qmlstatenodeinstance.h \ @@ -189,12 +203,40 @@ HEADERS += $$PWD/include/corelib_global.h \ $$PWD/instances/nodeinstancemetaobject.h \ $$PWD/instances/behaviornodeinstance.h \ $$PWD/instances/nodeinstancesignalspy.h \ - $$PWD/instances/positionernodeinstance.h + $$PWD/instances/positionernodeinstance.h \ + $$PWD/instances/nodeinstanceserver.h \ + $$PWD/instances/declarativedesignercommunicationinterface.h \ + $$PWD/instances/createinstancescommand.h \ + $$PWD/include/nodeinstanceserverinterface.h \ + $$PWD/include/nodeinstance.h \ + $$PWD/include/propertyvaluecontainer.h \ + $$PWD/instances/childrenchangeeventfilter.h \ + $$PWD/include/propertybindingcontainer.h \ + $$PWD/include/propertyabstractcontainer.h \ + $$PWD/instances/createscenecommand.h \ + $$PWD/instances/instancecontainer.h \ + $$PWD/instances/changefileurlcommand.h \ + $$PWD/instances/clearscenecommand.h \ + $$PWD/instances/reparentcontainer.h \ + $$PWD/instances/reparentinstancescommand.h \ + $$PWD/instances/changevaluescommand.h \ + $$PWD/instances/changebindingscommand.h \ + $$PWD/instances/changeidscommand.h \ + $$PWD/instances/idcontainer.h \ + $$PWD/instances/removeinstancescommand.h \ + $$PWD/instances/removepropertiescommand.h \ + $$PWD/include/nodeinstanceclientinterface.h \ + $$PWD/instances/valueschangedcommand.h \ + $$PWD/instances/pixmapchangedcommand.h \ + $$PWD/instances/informationchangedcommand.h \ + $$PWD/instances/informationcontainer.h \ + $$PWD/include/commondefines.h \ + $$PWD/instances/changestatecommand.h \ + $$PWD/instances/nodeinstanceserverproxy.h \ + $$PWD/instances/nodeinstanceclientproxy.h contains(CONFIG, plugin) { # If core.pri has been included in the qmldesigner plugin SOURCES += $$PWD/model/basetexteditmodifier.cpp HEADERS += $$PWD/include/basetexteditmodifier.h } - - diff --git a/src/plugins/qmldesigner/designercore/exceptions/exceptions.pri b/src/plugins/qmldesigner/designercore/exceptions/exceptions.pri new file mode 100644 index 0000000000..848d7808fc --- /dev/null +++ b/src/plugins/qmldesigner/designercore/exceptions/exceptions.pri @@ -0,0 +1,2 @@ +SOURCES += $$PWD/exception.cpp +SOURCES += $$PWD/invalidnodeinstanceexception.cpp diff --git a/src/plugins/qmldesigner/designercore/include/commondefines.h b/src/plugins/qmldesigner/designercore/include/commondefines.h new file mode 100644 index 0000000000..1cb6dd3d8d --- /dev/null +++ b/src/plugins/qmldesigner/designercore/include/commondefines.h @@ -0,0 +1,32 @@ +#ifndef COMMONDEFINES_H +#define COMMONDEFINES_H + +#include <QMetaType> + +namespace QmlDesigner { + +enum InformationName +{ + NoName, + Size, + BoundingRect, + Transform, + HasAnchor, + Anchor, + InstanceTypeForProperty, + PenWidth, + Position, + IsInPositioner, + SceneTransform, + IsResizable, + IsMovable, + IsAnchoredByChildren, + IsAnchoredBySibling, + HasContent, + HasBindingForProperty, + Parent +}; + +} + +#endif // COMMONDEFINES_H diff --git a/src/plugins/qmldesigner/designercore/include/modelnode.h b/src/plugins/qmldesigner/designercore/include/modelnode.h index 8d0e903320..3f6e318390 100644 --- a/src/plugins/qmldesigner/designercore/include/modelnode.h +++ b/src/plugins/qmldesigner/designercore/include/modelnode.h @@ -61,7 +61,6 @@ class AbstractView; class NodeListProperty; class NodeProperty; class NodeAbstractProperty; -class NodeInstance; class ModelNode; CORESHARED_EXPORT QList<Internal::InternalNodePointer> toInternalNodeList(const QList<ModelNode> &nodeList); diff --git a/src/plugins/qmldesigner/designercore/include/nodeinstance.h b/src/plugins/qmldesigner/designercore/include/nodeinstance.h index bdf7ec5410..4a52ca4ac2 100644 --- a/src/plugins/qmldesigner/designercore/include/nodeinstance.h +++ b/src/plugins/qmldesigner/designercore/include/nodeinstance.h @@ -1,206 +1,69 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ +#ifndef PROXYNODEINSTANCE_H +#define PROXYNODEINSTANCE_H -#ifndef NODEINSTANCE_H -#define NODEINSTANCE_H - -#include "corelib_global.h" #include <QSharedPointer> -#include <QHash> -#include <QRectF> -#include <propertymetainfo.h> -#include <qmlanchors.h> +#include <QTransform> +#include <QPointF> +#include <QSizeF> +#include <QPair> -QT_BEGIN_NAMESPACE -class QPainter; -class QStyleOptionGraphicsItem; -class QDeclarativeContext; -class QGraphicsItem; -class QGraphicsTransform; -QT_END_NAMESPACE +#include "commondefines.h" namespace QmlDesigner { class ModelNode; class NodeInstanceView; -class Preview; -class NodeMetaInfo; -class NodeState; -class WidgetQueryView; - - -namespace Internal { - class ObjectNodeInstance; - class QmlGraphicsItemNodeInstance; - class QmlPropertyChangesNodeInstance; - class GraphicsObjectNodeInstance; - class QmlStateNodeInstance; -} +class ProxyNodeInstanceData; -class CORESHARED_EXPORT NodeInstance +class NodeInstance { - friend class CORESHARED_EXPORT QmlDesigner::WidgetQueryView; - friend CORESHARED_EXPORT class Preview; - friend CORESHARED_EXPORT class NodeInstanceView; - friend class QHash<ModelNode, NodeInstance>; - friend CORESHARED_EXPORT uint qHash(const NodeInstance &instance); - friend CORESHARED_EXPORT bool operator==(const NodeInstance &first, const NodeInstance &second); - friend CORESHARED_EXPORT class NodeMetaInfo; - friend class QmlDesigner::Internal::QmlGraphicsItemNodeInstance; - friend class QmlDesigner::Internal::GraphicsObjectNodeInstance; - friend class QmlDesigner::Internal::ObjectNodeInstance; - friend class QmlDesigner::Internal::QmlPropertyChangesNodeInstance; - friend class QmlDesigner::Internal::QmlStateNodeInstance; - + friend class NodeInstanceView; public: + static NodeInstance create(const ModelNode &node, qint32 instanceId); NodeInstance(); ~NodeInstance(); NodeInstance(const NodeInstance &other); NodeInstance& operator=(const NodeInstance &other); - void paint(QPainter *painter); - - NodeInstance parent() const; - bool hasParent() const; ModelNode modelNode() const; - - - bool isTopLevel() const; - - bool isQmlGraphicsItem() const; - bool isGraphicsScene() const; - bool isGraphicsView() const; - bool isGraphicsWidget() const; - bool isProxyWidget() const; - bool isWidget() const; - bool isQDeclarativeView() const; - bool isGraphicsObject() const; - bool isTransition() const; - bool isPositioner() const; - - bool equalGraphicsItem(QGraphicsItem *item) const; - - QRectF boundingRect() const; - QPointF position() const; - QSizeF size() const; - QTransform transform() const; - QTransform customTransform() const; - QTransform sceneTransform() const; - double rotation() const; - double scale() const; - QList<QGraphicsTransform *> transformations() const; - QPointF transformOriginPoint() const; - double zValue() const; - - double opacity() const; - QVariant property(const QString &name) const; - QVariant defaultValue(const QString &name) const; - QString instanceType(const QString &name) const; - - bool hasBindingForProperty(const QString &name) const; - bool isValid() const; void makeInvalid(); - void renderPixmapNextPaint(); + QRectF boundingRect() const; bool hasContent() const; - bool isResizable() const; - bool isMovable() const; - bool isInPositioner() const; - - bool isWrappingThisObject(QObject *object) const; - - QVariant resetVariant(const QString &name) const; - - bool hasAnchor(const QString &name) const; bool isAnchoredBySibling() const; bool isAnchoredByChildren() const; - QPair<QString, NodeInstance> anchor(const QString &name) const; - + bool isMovable() const; + bool isResizable() const; + QTransform transform() const; + QTransform sceneTransform() const; + bool isInPositioner() const; + QPointF position() const; + QSizeF size() const; int penWidth() const; + void paint(QPainter *painter); - static void registerDeclarativeTypes(); - - void doComponentComplete(); - - QString id() const; - -#ifdef QTCREATOR_TEST - QObject* testHandle() const; - Internal::ObjectNodeInstance* internalInstance() const; -#endif -private: // functions - NodeInstance(const QSharedPointer<Internal::ObjectNodeInstance> &abstractInstance); - - void setModelNode(const ModelNode &node); - - void setPropertyVariant(const QString &name, const QVariant &value); - void setPropertyDynamicVariant(const QString &name, const QString &typeName, const QVariant &value); - - void setPropertyBinding(const QString &name, const QString &expression); - void setPropertyDynamicBinding(const QString &name, const QString &typeName, const QString &expression); - - void resetProperty(const QString &name); - void refreshProperty(const QString &name); - - void activateState(); - void deactivateState(); - void refreshState(); - - bool updateStateVariant(const NodeInstance &target, const QString &propertyName, const QVariant &value); - bool updateStateBinding(const NodeInstance &target, const QString &propertyName, const QString &expression); - bool resetStateProperty(const NodeInstance &target, const QString &propertyName, const QVariant &resetValue); - - static NodeInstance create(NodeInstanceView *nodeInstanceView, const ModelNode &node, QObject *objectToBeWrapped); - static NodeInstance create(NodeInstanceView *nodeInstanceView, const NodeMetaInfo &metaInfo, QDeclarativeContext *context); - - void setDeleteHeldInstance(bool deleteInstance); - void reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty); - - - void setId(const QString &id); - - static QSharedPointer<Internal::ObjectNodeInstance> createInstance(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped); - QSharedPointer<Internal::QmlGraphicsItemNodeInstance> qmlGraphicsItemNodeInstance() const; - - void paintUpdate(); + QVariant property(const QString &name) const; + bool hasBindingForProperty(const QString &name) const; + QPair<QString, qint32> anchor(const QString &name) const; + bool hasAnchor(const QString &name) const; + QString instanceType(const QString &name) const; + qint32 parentId() const; - QObject *internalObject() const; // should be not used outside of the nodeinstances!!!! +protected: + void setProperty(const QString &name, const QVariant &value); + void setInformation(InformationName name, + const QVariant &information, + const QVariant &secondInformation, + const QVariant &thirdInformation); + void setRenderImage(const QImage &image); + NodeInstance(ProxyNodeInstanceData *d); + qint32 instanceId() const; -private: // variables - QSharedPointer<Internal::ObjectNodeInstance> m_nodeInstance; +private: + QSharedPointer<ProxyNodeInstanceData> d; }; -CORESHARED_EXPORT uint qHash(const NodeInstance &instance); -CORESHARED_EXPORT bool operator==(const NodeInstance &first, const NodeInstance &second); } -Q_DECLARE_METATYPE(QmlDesigner::NodeInstance); - -#endif // NODEINSTANCE_H +#endif // PROXYNODEINSTANCE_H diff --git a/src/plugins/qmldesigner/designercore/include/nodeinstanceclientinterface.h b/src/plugins/qmldesigner/designercore/include/nodeinstanceclientinterface.h new file mode 100644 index 0000000000..759ce95214 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/include/nodeinstanceclientinterface.h @@ -0,0 +1,25 @@ +#ifndef NODEINSTANCECLIENTINTERFACE_H +#define NODEINSTANCECLIENTINTERFACE_H + +#include <QtGlobal> + +namespace QmlDesigner { + +class ValuesChangedCommand; +class PixmapChangedCommand; +class InformationChangedCommand; + +class NodeInstanceClientInterface +{ +public: + virtual void informationChanged(const InformationChangedCommand &command) = 0; + virtual void valuesChanged(const ValuesChangedCommand &command) = 0; + virtual void pixmapChanged(const PixmapChangedCommand &command) = 0; + virtual void flush() {}; + virtual qint64 bytesToWrite() const {return 0;} + +}; + +} + +#endif // NODEINSTANCECLIENTINTERFACE_H diff --git a/src/plugins/qmldesigner/designercore/include/nodeinstanceserverinterface.h b/src/plugins/qmldesigner/designercore/include/nodeinstanceserverinterface.h new file mode 100644 index 0000000000..c9d8951999 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/include/nodeinstanceserverinterface.h @@ -0,0 +1,48 @@ +#ifndef NODEINSTANCESERVERINTERFACE_H +#define NODEINSTANCESERVERINTERFACE_H + +#include <QObject> + +namespace QmlDesigner { + +class PropertyAbstractContainer; +class PropertyBindingContainer; +class PropertyValueContainer; + +class ChangeFileUrlCommand; +class ChangeValuesCommand; +class ChangeBindingsCommand; +class CreateSceneCommand; +class CreateInstancesCommand; +class ClearSceneCommand; +class ReparentInstancesCommand; +class ChangeIdsCommand; +class RemoveInstancesCommand; +class RemovePropertiesCommand; +class ChangeStateCommand; + +class NodeInstanceServerInterface : public QObject +{ + Q_OBJECT +public: + explicit NodeInstanceServerInterface(QObject *parent = 0); + + virtual void createInstances(const CreateInstancesCommand &command) = 0; + virtual void changeFileUrl(const ChangeFileUrlCommand &command) = 0; + virtual void createScene(const CreateSceneCommand &command) = 0; + virtual void clearScene(const ClearSceneCommand &command) = 0; + virtual void removeInstances(const RemoveInstancesCommand &command) = 0; + virtual void removeProperties(const RemovePropertiesCommand &command) = 0; + virtual void changePropertyBindings(const ChangeBindingsCommand &command) = 0; + virtual void changePropertyValues(const ChangeValuesCommand &command) = 0; + virtual void reparentInstances(const ReparentInstancesCommand &command) = 0; + virtual void changeIds(const ChangeIdsCommand &command) = 0; + virtual void changeState(const ChangeStateCommand &command) = 0; + + virtual void setBlockUpdates(bool block) {} + + static void registerCommands(); +}; + +} +#endif // NODEINSTANCESERVERINTERFACE_H diff --git a/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h b/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h index 1829c29e56..1c844b381a 100644 --- a/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h +++ b/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h @@ -35,35 +35,42 @@ #include <modelnode.h> #include <nodeinstance.h> +#include <nodeinstanceclientinterface.h> #include <QHash> +#include <QSet> #include <QWeakPointer> +#include <QRectF> QT_BEGIN_NAMESPACE class QDeclarativeEngine; class QGraphicsView; class QFileSystemWatcher; +class QPainter; QT_END_NAMESPACE - namespace QmlDesigner { -namespace Internal { - class ChildrenChangeEventFilter; - class QmlStateNodeInstance; -} - -class CORESHARED_EXPORT NodeInstanceView : public AbstractView +class NodeInstanceServerInterface; +class CreateSceneCommand; +class CreateInstancesCommand; +class ClearSceneCommand; +class ReparentInstancesCommand; +class ChangeFileUrlCommand; +class ChangeValuesCommand; +class ChangeBindingsCommand; +class ChangeIdsCommand; +class RemoveInstancesCommand; +class RemovePropertiesCommand; + +class CORESHARED_EXPORT NodeInstanceView : public AbstractView, public NodeInstanceClientInterface { Q_OBJECT friend class NodeInstance; - friend class Internal::ObjectNodeInstance; - friend class Internal::QmlStateNodeInstance; public: typedef QWeakPointer<NodeInstanceView> Pointer; - typedef QPair<QWeakPointer<QObject>, QString> ObjectPropertyPair; NodeInstanceView(QObject *parent = 0); ~NodeInstanceView(); @@ -73,7 +80,6 @@ public: void nodeCreated(const ModelNode &createdNode); void nodeAboutToBeRemoved(const ModelNode &removedNode); void nodeRemoved(const ModelNode &removedNode, const NodeAbstractProperty &parentProperty, PropertyChangeFlags propertyChange); - void propertiesAdded(const ModelNode &node, const QList<AbstractProperty>& propertyList); void propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList); void propertiesRemoved(const QList<AbstractProperty>& propertyList); void variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags propertyChange); @@ -89,79 +95,87 @@ public: QList<NodeInstance> instances() const; - NodeInstance instanceForNode(const ModelNode &node); - bool hasInstanceForNode(const ModelNode &node); + NodeInstance instanceForNode(const ModelNode &node) const ; + bool hasInstanceForNode(const ModelNode &node) const; - NodeInstance instanceForObject(QObject *object); - bool hasInstanceForObject(QObject *object); + NodeInstance instanceForId(qint32 id) const; + bool hasInstanceForId(qint32 id) const; void render(QPainter *painter, const QRectF &target=QRectF(), const QRectF &source=QRect(), Qt::AspectRatioMode aspectRatioMode=Qt::KeepAspectRatio); QRectF sceneRect() const; - void notifyPropertyChange(const ModelNode &modelNode, const QString &propertyName); - - void setBlockStatePropertyChanges(bool block); + void setBlockUpdates(bool block); NodeInstance activeStateInstance() const; void activateState(const NodeInstance &instance); void activateBaseState(); -private slots: - void emitParentChanged(QObject *child); - void refreshLocalFileProperty(const QString &path); + void valuesChanged(const ValuesChangedCommand &command); + void pixmapChanged(const PixmapChangedCommand &command); + void informationChanged(const InformationChangedCommand &command); private: // functions NodeInstance rootNodeInstance() const; - NodeInstance loadNode(const ModelNode &rootNode, QObject *objectToBeWrapped = 0); - void loadModel(Model *model); + NodeInstance loadNode(const ModelNode &node); + void loadNodes(const QList<ModelNode> &nodeList); void removeAllInstanceNodeRelationships(); void removeRecursiveChildRelationship(const ModelNode &removedNode); - void insertInstanceNodeRelationship(const ModelNode &node, const NodeInstance &instance); + void insertInstanceRelationships(const NodeInstance &instance); void removeInstanceNodeRelationship(const ModelNode &node); - QDeclarativeEngine *engine(); - Internal::ChildrenChangeEventFilter *childrenChangeEventFilter(); void removeInstanceAndSubInstances(const ModelNode &node); - void setInstancePropertyVariant(const VariantProperty &property); - void setInstancePropertyBinding(const BindingProperty &property); - void resetInstanceProperty(const AbstractProperty &property); - void setStateInstance(const NodeInstance &stateInstance); void clearStateInstance(); - QFileSystemWatcher *fileSystemWatcher(); + NodeInstanceServerInterface *nodeInstanceServer() const; - void addFilePropertyToFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path); - void removeFilePropertyFromFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path); + CreateSceneCommand createCreateSceneCommand() const; + ClearSceneCommand createClearSceneCommand() const; + CreateInstancesCommand createCreateInstancesCommand(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; + ChangeValuesCommand createChangeValueCommand(const QList<VariantProperty> &propertyList) const; + ChangeBindingsCommand createChangeBindingCommand(const QList<BindingProperty> &propertyList) const; + ChangeIdsCommand createChangeIdsCommand(const QList<NodeInstance> &instanceList) const; + RemoveInstancesCommand createRemoveInstancesCommand(const QList<ModelNode> &nodeList) const; + RemoveInstancesCommand createRemoveInstancesCommand(const ModelNode &node) const; + RemovePropertiesCommand createRemovePropertiesCommand(const QList<AbstractProperty> &propertyList) const; + + qint32 generateInstanceId(); + + void resetHorizontalAnchors(const ModelNode &node); + void resetVerticalAnchors(const ModelNode &node); + +private slots: + void restartProcess(); private: //variables NodeInstance m_rootNodeInstance; NodeInstance m_activeStateInstance; - QScopedPointer<QGraphicsView> m_graphicsView; QHash<ModelNode, NodeInstance> m_nodeInstanceHash; - QHash<QObject*, NodeInstance> m_objectInstanceHash; // This is purely internal. Might contain dangling pointers! - QMultiHash<QString, ObjectPropertyPair> m_fileSystemWatcherHash; - QWeakPointer<QDeclarativeEngine> m_engine; - QWeakPointer<Internal::ChildrenChangeEventFilter> m_childrenChangeEventFilter; - - QWeakPointer<QmlModelView> m_qmlModelView; - - QWeakPointer<QFileSystemWatcher> m_fileSystemWatcher; + QHash<qint32, NodeInstance> m_idInstanceHash; // This is purely internal. Might contain dangling pointers! - bool m_blockStatePropertyChanges; + QList<QPair<ModelNode, QString> > m_valuePropertyChangeList; + QSet<ModelNode> m_renderImageChangeSet; + QSet<ModelNode> m_informationChangeSet; + uint m_blockUpdates; + QWeakPointer<NodeInstanceServerInterface> m_nodeInstanceServer; + qint32 m_instanceIdCounter; +; }; -} // namespace NodeInstanceView +} // namespace ProxyNodeInstanceView #endif // NODEINSTANCEVIEW_H diff --git a/src/plugins/qmldesigner/designercore/include/propertyabstractcontainer.h b/src/plugins/qmldesigner/designercore/include/propertyabstractcontainer.h new file mode 100644 index 0000000000..44b9a437e7 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/include/propertyabstractcontainer.h @@ -0,0 +1,40 @@ +#ifndef PROPERTYABSTRACTCONTAINER_H +#define PROPERTYABSTRACTCONTAINER_H + +#include <QDataStream> +#include <qmetatype.h> +#include <QString> + + +namespace QmlDesigner { + +class PropertyAbstractContainer; + +QDataStream &operator<<(QDataStream &out, const PropertyAbstractContainer &container); +QDataStream &operator>>(QDataStream &in, PropertyAbstractContainer &container); + +class PropertyAbstractContainer +{ + + friend QDataStream &operator<<(QDataStream &out, const PropertyAbstractContainer &container); + friend QDataStream &operator>>(QDataStream &in, PropertyAbstractContainer &container); +public: + PropertyAbstractContainer(); + PropertyAbstractContainer(qint32 instanceId, const QString &name, const QString &dynamicTypeName); + + qint32 instanceId() const; + QString name() const; + bool isDynamic() const; + QString dynamicTypeName() const; + +private: + qint32 m_instanceId; + QString m_name; + QString m_dynamicTypeName; +}; + + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::PropertyAbstractContainer); +#endif // PROPERTYABSTRACTCONTAINER_H diff --git a/src/plugins/qmldesigner/designercore/include/propertybindingcontainer.h b/src/plugins/qmldesigner/designercore/include/propertybindingcontainer.h new file mode 100644 index 0000000000..6067ecda59 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/include/propertybindingcontainer.h @@ -0,0 +1,38 @@ +#ifndef PROPERTYBINDINGCONTAINER_H +#define PROPERTYBINDINGCONTAINER_H + +#include <QDataStream> +#include <qmetatype.h> +#include <QString> + + +namespace QmlDesigner { + +class PropertyBindingContainer +{ + friend QDataStream &operator>>(QDataStream &in, PropertyBindingContainer &container); + +public: + PropertyBindingContainer(); + PropertyBindingContainer(qint32 instanceId, const QString &name, const QString &expression, const QString &dynamicTypeName); + + qint32 instanceId() const; + QString name() const; + QString expression() const; + bool isDynamic() const; + QString dynamicTypeName() const; + +private: + qint32 m_instanceId; + QString m_name; + QString m_expression; + QString m_dynamicTypeName; +}; + +QDataStream &operator<<(QDataStream &out, const PropertyBindingContainer &container); +QDataStream &operator>>(QDataStream &in, PropertyBindingContainer &container); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::PropertyBindingContainer); +#endif // PROPERTYBINDINGCONTAINER_H diff --git a/src/plugins/qmldesigner/designercore/include/propertyvaluecontainer.h b/src/plugins/qmldesigner/designercore/include/propertyvaluecontainer.h new file mode 100644 index 0000000000..e5db91c789 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/include/propertyvaluecontainer.h @@ -0,0 +1,42 @@ +#ifndef PROPERTYVALUECONTAINER_H +#define PROPERTYVALUECONTAINER_H + +#include <QDataStream> +#include <QMetaType> +#include <QVariant> +#include <QString> + +#include "commondefines.h" + +namespace QmlDesigner { + + +class PropertyValueContainer +{ + friend QDataStream &operator>>(QDataStream &in, PropertyValueContainer &container); + +public: + PropertyValueContainer(); + PropertyValueContainer(qint32 instanceId, const QString &name, const QVariant &value, const QString &dynamicTypeName); + + qint32 instanceId() const; + QString name() const; + QVariant value() const; + bool isDynamic() const; + QString dynamicTypeName() const; + +private: + qint32 m_instanceId; + QString m_name; + QVariant m_value; + QString m_dynamicTypeName; +}; + +QDataStream &operator<<(QDataStream &out, const PropertyValueContainer &container); +QDataStream &operator>>(QDataStream &in, PropertyValueContainer &container); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::PropertyValueContainer); + +#endif // PROPERTYVALUECONTAINER_H diff --git a/src/plugins/qmldesigner/designercore/include/qmlobjectnode.h b/src/plugins/qmldesigner/designercore/include/qmlobjectnode.h index 9300981440..fdf98025b0 100644 --- a/src/plugins/qmldesigner/designercore/include/qmlobjectnode.h +++ b/src/plugins/qmldesigner/designercore/include/qmlobjectnode.h @@ -35,6 +35,8 @@ #include "qmlstate.h" #include "qmlchangeset.h" +#include <nodeinstance.h> + namespace QmlDesigner { class QmlItemNode; diff --git a/src/plugins/qmldesigner/designercore/instances/behaviornodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/behaviornodeinstance.cpp index 7ea3f08fb4..77d82443c7 100644 --- a/src/plugins/qmldesigner/designercore/instances/behaviornodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/behaviornodeinstance.cpp @@ -13,23 +13,15 @@ BehaviorNodeInstance::BehaviorNodeInstance(QObject *object) { } -BehaviorNodeInstance::Pointer BehaviorNodeInstance::create(const NodeMetaInfo &nodeMetaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped) +BehaviorNodeInstance::Pointer BehaviorNodeInstance::create(QObject *object) { - QObject *object = 0; - if (objectToBeWrapped) - object = objectToBeWrapped; - else - object = createObject(nodeMetaInfo, context); - QDeclarativeBehavior* behavior = qobject_cast<QDeclarativeBehavior*>(object); + if (behavior == 0) throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__); Pointer instance(new BehaviorNodeInstance(behavior)); - if (objectToBeWrapped) - instance->setDeleteHeldInstance(false); // the object isn't owned - instance->populateResetValueHash(); behavior->setEnabled(false); diff --git a/src/plugins/qmldesigner/designercore/instances/behaviornodeinstance.h b/src/plugins/qmldesigner/designercore/instances/behaviornodeinstance.h index 9addf049d5..62951653f6 100644 --- a/src/plugins/qmldesigner/designercore/instances/behaviornodeinstance.h +++ b/src/plugins/qmldesigner/designercore/instances/behaviornodeinstance.h @@ -14,7 +14,7 @@ public: BehaviorNodeInstance(QObject *object); - static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped); + static Pointer create(QObject *objectToBeWrapped); void setPropertyVariant(const QString &name, const QVariant &value); void setPropertyBinding(const QString &name, const QString &expression); diff --git a/src/plugins/qmldesigner/designercore/instances/changebindingscommand.cpp b/src/plugins/qmldesigner/designercore/instances/changebindingscommand.cpp new file mode 100644 index 0000000000..9d8c5decc7 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/changebindingscommand.cpp @@ -0,0 +1,32 @@ +#include "changebindingscommand.h" + +namespace QmlDesigner { + +ChangeBindingsCommand::ChangeBindingsCommand() +{ +} + +ChangeBindingsCommand::ChangeBindingsCommand(const QVector<PropertyBindingContainer> &bindingChangeVector) + : m_bindingChangeVector (bindingChangeVector) +{ +} + +QVector<PropertyBindingContainer> ChangeBindingsCommand::bindingChanges() const +{ + return m_bindingChangeVector; +} + +QDataStream &operator<<(QDataStream &out, const ChangeBindingsCommand &command) +{ + out << command.bindingChanges(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, ChangeBindingsCommand &command) +{ + in >> command.m_bindingChangeVector; + + return in; +} +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/changebindingscommand.h b/src/plugins/qmldesigner/designercore/instances/changebindingscommand.h new file mode 100644 index 0000000000..60f680d105 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/changebindingscommand.h @@ -0,0 +1,32 @@ +#ifndef CHANGEBINDINGSCOMMAND_H +#define CHANGEBINDINGSCOMMAND_H + +#include <QMetaType> +#include <QVector> + +#include "propertybindingcontainer.h" + +namespace QmlDesigner { + +class ChangeBindingsCommand +{ + friend QDataStream &operator>>(QDataStream &in, ChangeBindingsCommand &command); + +public: + ChangeBindingsCommand(); + ChangeBindingsCommand(const QVector<PropertyBindingContainer> &bindingChangeVector); + + QVector<PropertyBindingContainer> bindingChanges() const; + +private: + QVector<PropertyBindingContainer> m_bindingChangeVector; +}; + +QDataStream &operator<<(QDataStream &out, const ChangeBindingsCommand &command); +QDataStream &operator>>(QDataStream &in, ChangeBindingsCommand &command); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::ChangeBindingsCommand); + +#endif // CHANGEBINDINGSCOMMAND_H diff --git a/src/plugins/qmldesigner/designercore/instances/changefileurlcommand.cpp b/src/plugins/qmldesigner/designercore/instances/changefileurlcommand.cpp new file mode 100644 index 0000000000..39939102ac --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/changefileurlcommand.cpp @@ -0,0 +1,33 @@ +#include "changefileurlcommand.h" + +namespace QmlDesigner { + +ChangeFileUrlCommand::ChangeFileUrlCommand() +{ +} + +ChangeFileUrlCommand::ChangeFileUrlCommand(const QUrl &fileUrl) + : m_fileUrl(fileUrl) +{ +} + +QUrl ChangeFileUrlCommand::fileUrl() const +{ + return m_fileUrl; +} + +QDataStream &operator<<(QDataStream &out, const ChangeFileUrlCommand &command) +{ + out << command.fileUrl(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, ChangeFileUrlCommand &command) +{ + in >> command.m_fileUrl; + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/changefileurlcommand.h b/src/plugins/qmldesigner/designercore/instances/changefileurlcommand.h new file mode 100644 index 0000000000..dfc735cf09 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/changefileurlcommand.h @@ -0,0 +1,30 @@ +#ifndef CHANGEFILEURLCOMMAND_H +#define CHANGEFILEURLCOMMAND_H + +#include <qmetatype.h> +#include <QUrl> + +namespace QmlDesigner { + +class ChangeFileUrlCommand +{ + friend QDataStream &operator>>(QDataStream &in, ChangeFileUrlCommand &command); +public: + ChangeFileUrlCommand(); + ChangeFileUrlCommand(const QUrl &fileUrl); + + QUrl fileUrl() const; + +private: + QUrl m_fileUrl; +}; + + +QDataStream &operator<<(QDataStream &out, const ChangeFileUrlCommand &command); +QDataStream &operator>>(QDataStream &in, ChangeFileUrlCommand &command); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::ChangeFileUrlCommand); + +#endif // CHANGEFILEURLCOMMAND_H diff --git a/src/plugins/qmldesigner/designercore/instances/changeidscommand.cpp b/src/plugins/qmldesigner/designercore/instances/changeidscommand.cpp new file mode 100644 index 0000000000..0d15a6b2bf --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/changeidscommand.cpp @@ -0,0 +1,33 @@ +#include "changeidscommand.h" + +namespace QmlDesigner { + +ChangeIdsCommand::ChangeIdsCommand() +{ +} + +ChangeIdsCommand::ChangeIdsCommand(const QVector<IdContainer> &idVector) + : m_idVector(idVector) +{ +} + +QVector<IdContainer> ChangeIdsCommand::ids() const +{ + return m_idVector; +} + +QDataStream &operator<<(QDataStream &out, const ChangeIdsCommand &command) +{ + out << command.ids(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, ChangeIdsCommand &command) +{ + in >> command.m_idVector; + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/changeidscommand.h b/src/plugins/qmldesigner/designercore/instances/changeidscommand.h new file mode 100644 index 0000000000..8ca80a4cbb --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/changeidscommand.h @@ -0,0 +1,32 @@ +#ifndef CHANGEIDSCOMMAND_H +#define CHANGEIDSCOMMAND_H + +#include <QMetaType> +#include <QVector> + + +#include "idcontainer.h" + +namespace QmlDesigner { + +class ChangeIdsCommand +{ + friend QDataStream &operator>>(QDataStream &in, ChangeIdsCommand &command); +public: + ChangeIdsCommand(); + ChangeIdsCommand(const QVector<IdContainer> &idVector); + + QVector<IdContainer> ids() const; + +private: + QVector<IdContainer> m_idVector; +}; + +QDataStream &operator<<(QDataStream &out, const ChangeIdsCommand &command); +QDataStream &operator>>(QDataStream &in, ChangeIdsCommand &command); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::ChangeIdsCommand); + +#endif // CHANGEIDSCOMMAND_H diff --git a/src/plugins/qmldesigner/designercore/instances/changestatecommand.cpp b/src/plugins/qmldesigner/designercore/instances/changestatecommand.cpp new file mode 100644 index 0000000000..43f4902b6b --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/changestatecommand.cpp @@ -0,0 +1,34 @@ +#include "changestatecommand.h" + +namespace QmlDesigner { + +ChangeStateCommand::ChangeStateCommand() + : m_stateInstanceId(-1) +{ +} + +ChangeStateCommand::ChangeStateCommand(qint32 stateInstanceId) + : m_stateInstanceId(stateInstanceId) +{ +} + +qint32 ChangeStateCommand::stateInstanceId() const +{ + return m_stateInstanceId; +} + +QDataStream &operator<<(QDataStream &out, const ChangeStateCommand &command) +{ + out << command.stateInstanceId(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, ChangeStateCommand &command) +{ + in >> command.m_stateInstanceId; + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/changestatecommand.h b/src/plugins/qmldesigner/designercore/instances/changestatecommand.h new file mode 100644 index 0000000000..14eb70e619 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/changestatecommand.h @@ -0,0 +1,32 @@ +#ifndef CHANGESTATECOMMAND_H +#define CHANGESTATECOMMAND_H + +#include <QMetaType> +#include <QVector> + +#include "propertyvaluecontainer.h" + +namespace QmlDesigner { + +class ChangeStateCommand +{ + friend QDataStream &operator>>(QDataStream &in, ChangeStateCommand &command); + +public: + ChangeStateCommand(); + ChangeStateCommand(qint32 stateInstanceId); + + qint32 stateInstanceId() const; + +private: + qint32 m_stateInstanceId; +}; + +QDataStream &operator<<(QDataStream &out, const ChangeStateCommand &command); +QDataStream &operator>>(QDataStream &in, ChangeStateCommand &command); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::ChangeStateCommand); + +#endif // CHANGESTATECOMMAND_H diff --git a/src/plugins/qmldesigner/designercore/instances/changevaluescommand.cpp b/src/plugins/qmldesigner/designercore/instances/changevaluescommand.cpp new file mode 100644 index 0000000000..f00ebffa1c --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/changevaluescommand.cpp @@ -0,0 +1,33 @@ +#include "changevaluescommand.h" + +namespace QmlDesigner { + +ChangeValuesCommand::ChangeValuesCommand() +{ +} + +ChangeValuesCommand::ChangeValuesCommand(const QVector<PropertyValueContainer> &valueChangeVector) + : m_valueChangeVector (valueChangeVector) +{ +} + +QVector<PropertyValueContainer> ChangeValuesCommand::valueChanges() const +{ + return m_valueChangeVector; +} + +QDataStream &operator<<(QDataStream &out, const ChangeValuesCommand &command) +{ + out << command.valueChanges(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, ChangeValuesCommand &command) +{ + in >> command.m_valueChangeVector; + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/changevaluescommand.h b/src/plugins/qmldesigner/designercore/instances/changevaluescommand.h new file mode 100644 index 0000000000..b37ab28510 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/changevaluescommand.h @@ -0,0 +1,32 @@ +#ifndef CHANGEVALUESCOMMAND_H +#define CHANGEVALUESCOMMAND_H + +#include <QMetaType> +#include <QVector> + +#include "propertyvaluecontainer.h" + +namespace QmlDesigner { + +class ChangeValuesCommand +{ + friend QDataStream &operator>>(QDataStream &in, ChangeValuesCommand &command); + +public: + ChangeValuesCommand(); + ChangeValuesCommand(const QVector<PropertyValueContainer> &valueChangeVector); + + QVector<PropertyValueContainer> valueChanges() const; + +private: + QVector<PropertyValueContainer> m_valueChangeVector; +}; + +QDataStream &operator<<(QDataStream &out, const ChangeValuesCommand &command); +QDataStream &operator>>(QDataStream &in, ChangeValuesCommand &command); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::ChangeValuesCommand); + +#endif // CHANGEVALUESCOMMAND_H diff --git a/src/plugins/qmldesigner/designercore/instances/childrenchangeeventfilter.cpp b/src/plugins/qmldesigner/designercore/instances/childrenchangeeventfilter.cpp new file mode 100644 index 0000000000..a8fbaf4965 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/childrenchangeeventfilter.cpp @@ -0,0 +1,29 @@ +#include "childrenchangeeventfilter.h" + +#include <QEvent> + +namespace QmlDesigner { +namespace Internal { + +ChildrenChangeEventFilter::ChildrenChangeEventFilter(QObject *parent) + : QObject(parent) +{ +} + + +bool ChildrenChangeEventFilter::eventFilter(QObject * /*object*/, QEvent *event) +{ + switch (event->type()) { + case QEvent::ChildAdded: + case QEvent::ChildRemoved: + { + QChildEvent *childEvent = static_cast<QChildEvent*>(event); + emit childrenChanged(childEvent->child()); break; + } + default: break; + } + + return false; +} +} // namespace Internal +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/childrenchangeeventfilter.h b/src/plugins/qmldesigner/designercore/instances/childrenchangeeventfilter.h new file mode 100644 index 0000000000..59dcc72ed9 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/childrenchangeeventfilter.h @@ -0,0 +1,27 @@ +#ifndef CHILDRENCHANGEEVENTFILTER_H +#define CHILDRENCHANGEEVENTFILTER_H + +#include <QObject> + +namespace QmlDesigner { +namespace Internal { + +class ChildrenChangeEventFilter : public QObject +{ + Q_OBJECT +public: + ChildrenChangeEventFilter(QObject *parent); + + +signals: + void childrenChanged(QObject *object); + +protected: + bool eventFilter(QObject *object, QEvent *event); + +}; + +} // namespace Internal +} // namespace QmlDesigner + +#endif // CHILDRENCHANGEEVENTFILTER_H diff --git a/src/plugins/qmldesigner/designercore/instances/clearscenecommand.cpp b/src/plugins/qmldesigner/designercore/instances/clearscenecommand.cpp new file mode 100644 index 0000000000..21e349fd53 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/clearscenecommand.cpp @@ -0,0 +1,19 @@ +#include "clearscenecommand.h" + +namespace QmlDesigner { + +ClearSceneCommand::ClearSceneCommand() +{ +} + +QDataStream &operator<<(QDataStream &out, const ClearSceneCommand &/*command*/) +{ + return out; +} + +QDataStream &operator>>(QDataStream &in, ClearSceneCommand &/*command*/) +{ + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/clearscenecommand.h b/src/plugins/qmldesigner/designercore/instances/clearscenecommand.h new file mode 100644 index 0000000000..24aa637adf --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/clearscenecommand.h @@ -0,0 +1,21 @@ +#ifndef CLEARSCENECOMMAND_H +#define CLEARSCENECOMMAND_H + +#include <qmetatype.h> + +namespace QmlDesigner { + +class ClearSceneCommand +{ +public: + ClearSceneCommand(); +}; + +QDataStream &operator<<(QDataStream &out, const ClearSceneCommand &command); +QDataStream &operator>>(QDataStream &in, ClearSceneCommand &command); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::ClearSceneCommand); + +#endif // CLEARSCENECOMMAND_H diff --git a/src/plugins/qmldesigner/designercore/instances/componentnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/componentnodeinstance.cpp index 98fcb17865..987f9d6815 100644 --- a/src/plugins/qmldesigner/designercore/instances/componentnodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/componentnodeinstance.cpp @@ -48,23 +48,15 @@ QDeclarativeComponent *ComponentNodeInstance::component() const return static_cast<QDeclarativeComponent*>(object()); } -ComponentNodeInstance::Pointer ComponentNodeInstance::create(const NodeMetaInfo &/*metaInfo*/, QDeclarativeContext *context, QObject *objectToBeWrapped) +ComponentNodeInstance::Pointer ComponentNodeInstance::create(QObject *object) { - QDeclarativeComponent *component = 0; - if (objectToBeWrapped) - component = qobject_cast<QDeclarativeComponent *>(objectToBeWrapped); - else - component = new QDeclarativeComponent(context->engine()); + QDeclarativeComponent *component = component = qobject_cast<QDeclarativeComponent *>(object); if (component == 0) throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__); - Pointer instance(new ComponentNodeInstance(component)); - if (objectToBeWrapped) - instance->setDeleteHeldInstance(false); // the object isn't owned - instance->populateResetValueHash(); return instance; @@ -77,24 +69,25 @@ bool ComponentNodeInstance::hasContent() const void ComponentNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) { - if (name == "__component_data") { - QByteArray data(value.toByteArray()); - QByteArray imports; - foreach(const Import &import, modelNode().model()->imports()) { - imports.append(import.toString(true).toLatin1()); - } +// if (name == "__component_data") { +// QByteArray data(value.toByteArray()); +// QByteArray imports; +// foreach(const Import &import, nodeInstanceServer()->imports()) { +// imports.append(import.toString(true).toLatin1()); +// } - data.prepend(imports); +// data.prepend(imports); - component()->setData(data, nodeInstanceView()->model()->fileUrl()); +// component()->setData(data, nodeInstanceView()->model()->fileUrl()); - } - if (component()->isError()) { - qDebug() << value; - foreach(const QDeclarativeError &error, component()->errors()) - qDebug() << error; - } +// } +// if (component()->isError()) { +// qDebug() << value; +// foreach(const QDeclarativeError &error, component()->errors()) +// qDebug() << error; +// } } + } // Internal } // QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/componentnodeinstance.h b/src/plugins/qmldesigner/designercore/instances/componentnodeinstance.h index e75ab93e96..d050458820 100644 --- a/src/plugins/qmldesigner/designercore/instances/componentnodeinstance.h +++ b/src/plugins/qmldesigner/designercore/instances/componentnodeinstance.h @@ -45,7 +45,7 @@ public: typedef QSharedPointer<ComponentNodeInstance> Pointer; typedef QWeakPointer<ComponentNodeInstance> WeakPointer; ComponentNodeInstance(QDeclarativeComponent *component); - static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped); + static Pointer create(QObject *objectToBeWrapped); void setPropertyVariant(const QString &name, const QVariant &value); diff --git a/src/plugins/qmldesigner/designercore/instances/createinstancescommand.cpp b/src/plugins/qmldesigner/designercore/instances/createinstancescommand.cpp new file mode 100644 index 0000000000..2d1f5ac6f9 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/createinstancescommand.cpp @@ -0,0 +1,35 @@ +#include "createinstancescommand.h" + +#include <QDataStream> + +namespace QmlDesigner { + +CreateInstancesCommand::CreateInstancesCommand() +{ +} + +CreateInstancesCommand::CreateInstancesCommand(const QVector<InstanceContainer> &container) + : m_instanceVector(container) +{ +} + +QVector<InstanceContainer> CreateInstancesCommand::instances() const +{ + return m_instanceVector; +} + +QDataStream &operator<<(QDataStream &out, const CreateInstancesCommand &command) +{ + out << command.instances(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, CreateInstancesCommand &command) +{ + in >> command.m_instanceVector; + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/createinstancescommand.h b/src/plugins/qmldesigner/designercore/instances/createinstancescommand.h new file mode 100644 index 0000000000..655515ebe9 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/createinstancescommand.h @@ -0,0 +1,32 @@ +#ifndef CREATEINSTANCESCOMMAND_H +#define CREATEINSTANCESCOMMAND_H + +#include <QMetaType> +#include <QVector> + +#include "instancecontainer.h" + +namespace QmlDesigner { + +class CreateInstancesCommand +{ + friend QDataStream &operator>>(QDataStream &in, CreateInstancesCommand &command); + +public: + CreateInstancesCommand(); + CreateInstancesCommand(const QVector<InstanceContainer> &container); + + QVector<InstanceContainer> instances() const; + +private: + QVector<InstanceContainer> m_instanceVector; +}; + +QDataStream &operator<<(QDataStream &out, const CreateInstancesCommand &command); +QDataStream &operator>>(QDataStream &in, CreateInstancesCommand &command); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::CreateInstancesCommand); + +#endif // CREATEINSTANCESCOMMAND_H diff --git a/src/plugins/qmldesigner/designercore/instances/createscenecommand.cpp b/src/plugins/qmldesigner/designercore/instances/createscenecommand.cpp new file mode 100644 index 0000000000..a0b91fd80d --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/createscenecommand.cpp @@ -0,0 +1,19 @@ +#include "createscenecommand.h" + +namespace QmlDesigner { + +CreateSceneCommand::CreateSceneCommand() +{ +} + +QDataStream &operator<<(QDataStream &out, const CreateSceneCommand &command) +{ + return out; +} + +QDataStream &operator>>(QDataStream &in, CreateSceneCommand &command) +{ + return in; +} + +} diff --git a/src/plugins/qmldesigner/designercore/instances/createscenecommand.h b/src/plugins/qmldesigner/designercore/instances/createscenecommand.h new file mode 100644 index 0000000000..70e5091c73 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/createscenecommand.h @@ -0,0 +1,23 @@ +#ifndef CREATESCENECOMMAND_H +#define CREATESCENECOMMAND_H + +#include <qmetatype.h> + +namespace QmlDesigner { + +class CreateSceneCommand +{ + friend QDataStream &operator>>(QDataStream &in, CreateSceneCommand &command); + +public: + CreateSceneCommand(); +}; + +QDataStream &operator<<(QDataStream &out, const CreateSceneCommand &command); +QDataStream &operator>>(QDataStream &in, CreateSceneCommand &command); + +} + +Q_DECLARE_METATYPE(QmlDesigner::CreateSceneCommand); + +#endif // CREATESCENECOMMAND_H diff --git a/src/plugins/qmldesigner/designercore/instances/declarativedesignercommunicationinterface.cpp b/src/plugins/qmldesigner/designercore/instances/declarativedesignercommunicationinterface.cpp new file mode 100644 index 0000000000..35c792778d --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/declarativedesignercommunicationinterface.cpp @@ -0,0 +1,6 @@ +#include "declarativedesignercommunicationinterface.h" + +DeclarativeDesignerCommunicationInterface::DeclarativeDesignerCommunicationInterface(QObject *parent) : + QObject(parent) +{ +} diff --git a/src/plugins/qmldesigner/designercore/instances/declarativedesignercommunicationinterface.h b/src/plugins/qmldesigner/designercore/instances/declarativedesignercommunicationinterface.h new file mode 100644 index 0000000000..d22316faad --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/declarativedesignercommunicationinterface.h @@ -0,0 +1,18 @@ +#ifndef DECLARATIVEDESIGNERCOMMUNICATIONINTERFACE_H +#define DECLARATIVEDESIGNERCOMMUNICATIONINTERFACE_H + +#include <QObject> + +class DeclarativeDesignerCommunicationInterface : public QObject +{ + Q_OBJECT +public: + explicit DeclarativeDesignerCommunicationInterface(QObject *parent = 0); + +signals: + +public slots: + +}; + +#endif // DECLARATIVEDESIGNERCOMMUNICATIONINTERFACE_H diff --git a/src/plugins/qmldesigner/designercore/instances/dummynodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/dummynodeinstance.cpp index e6a3e0f8dc..9cfd2efb01 100644 --- a/src/plugins/qmldesigner/designercore/instances/dummynodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/dummynodeinstance.cpp @@ -51,11 +51,6 @@ void DummyNodeInstance::paint(QPainter * /*painter*/) const { } -bool DummyNodeInstance::isTopLevel() const -{ - return false; -} - QRectF DummyNodeInstance::boundingRect() const { return QRectF(); diff --git a/src/plugins/qmldesigner/designercore/instances/dummynodeinstance.h b/src/plugins/qmldesigner/designercore/instances/dummynodeinstance.h index a6087457e6..e3b954b661 100644 --- a/src/plugins/qmldesigner/designercore/instances/dummynodeinstance.h +++ b/src/plugins/qmldesigner/designercore/instances/dummynodeinstance.h @@ -47,8 +47,6 @@ public: void paint(QPainter *painter) const; - bool isTopLevel() const; - QRectF boundingRect() const; QPointF position() const; QSizeF size() const; diff --git a/src/plugins/qmldesigner/designercore/instances/graphicsobjectnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/graphicsobjectnodeinstance.cpp index 5f1f61e753..1854bc2c01 100644 --- a/src/plugins/qmldesigner/designercore/instances/graphicsobjectnodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/graphicsobjectnodeinstance.cpp @@ -40,11 +40,9 @@ namespace QmlDesigner { namespace Internal { -GraphicsObjectNodeInstance::GraphicsObjectNodeInstance(QGraphicsObject *graphicsObject, bool hasContent) +GraphicsObjectNodeInstance::GraphicsObjectNodeInstance(QGraphicsObject *graphicsObject) : ObjectNodeInstance(graphicsObject), - m_hasContent(hasContent), - m_isMovable(true), - m_renderPixmapIsDirty(true) + m_isMovable(true) { } @@ -62,6 +60,11 @@ bool GraphicsObjectNodeInstance::hasContent() const return m_hasContent; } +void GraphicsObjectNodeInstance::setHasContent(bool hasContent) +{ + m_hasContent = hasContent; +} + QPointF GraphicsObjectNodeInstance::position() const { return graphicsObject()->pos(); @@ -74,10 +77,10 @@ QSizeF GraphicsObjectNodeInstance::size() const QTransform GraphicsObjectNodeInstance::transform() const { - if (!nodeInstanceView()->hasInstanceForNode(modelNode())) + if (!nodeInstanceServer()->hasInstanceForObject(object())) return sceneTransform(); - NodeInstance nodeInstanceParent = nodeInstanceView()->instanceForNode(modelNode()).parent(); + ServerNodeInstance nodeInstanceParent = nodeInstanceServer()->instanceForObject(object()).parent(); if (!nodeInstanceParent.isValid()) return sceneTransform(); @@ -142,12 +145,6 @@ QRectF GraphicsObjectNodeInstance::boundingRect() const return graphicsObject()->boundingRect(); } -bool GraphicsObjectNodeInstance::isTopLevel() const -{ - Q_ASSERT(graphicsObject()); - return !graphicsObject()->parentItem(); -} - bool GraphicsObjectNodeInstance::isGraphicsObject() const { return true; @@ -158,6 +155,11 @@ void GraphicsObjectNodeInstance::setPropertyVariant(const QString &name, const Q ObjectNodeInstance::setPropertyVariant(name, value); } +void GraphicsObjectNodeInstance::setPropertyBinding(const QString &name, const QString &expression) +{ + ObjectNodeInstance::setPropertyBinding(name, expression); +} + QVariant GraphicsObjectNodeInstance::property(const QString &name) const { return ObjectNodeInstance::property(name); @@ -174,21 +176,19 @@ void initOption(QGraphicsItem *item, QStyleOptionGraphicsItem *option, const QTr privateItem->initStyleOption(option, transform, QRegion()); } -void GraphicsObjectNodeInstance::renderPixmap() +QImage GraphicsObjectNodeInstance::renderImage() const { QRectF boundingRect = graphicsObject()->boundingRect(); QSize boundingSize = boundingRect.size().toSize(); - if (m_renderPixmap.size() != boundingSize) { - m_renderPixmap = QPixmap(boundingSize); - } + QImage image(boundingSize, QImage::Format_ARGB32); - if (m_renderPixmap.isNull()) - return; + if (image.isNull()) + return image; - m_renderPixmap.fill(Qt::transparent); + image.fill(Qt::transparent); - QPainter painter(&m_renderPixmap); + QPainter painter(&image); painter.translate(-boundingRect.topLeft()); if (hasContent()) { @@ -200,13 +200,15 @@ void GraphicsObjectNodeInstance::renderPixmap() foreach(QGraphicsItem *graphicsItem, graphicsObject()->childItems()) paintRecursively(graphicsItem, &painter); + + return image; } void GraphicsObjectNodeInstance::paintRecursively(QGraphicsItem *graphicsItem, QPainter *painter) const { QGraphicsObject *graphicsObject = graphicsItem->toGraphicsObject(); if (graphicsObject) { - if (nodeInstanceView()->hasInstanceForObject(graphicsObject)) + if (nodeInstanceServer()->hasInstanceForObject(graphicsObject)) return; //we already keep track of this object elsewhere } @@ -224,31 +226,6 @@ void GraphicsObjectNodeInstance::paintRecursively(QGraphicsItem *graphicsItem, Q } } -void GraphicsObjectNodeInstance::paint(QPainter *painter) -{ - if (graphicsObject()) { - if (m_renderPixmapIsDirty) - renderPixmap(); - if (!m_renderPixmap.isNull()) - painter->drawPixmap(graphicsObject()->boundingRect().topLeft(), m_renderPixmap); - } -} - -QPair<QGraphicsObject*, bool> GraphicsObjectNodeInstance::createGraphicsObject(const NodeMetaInfo &metaInfo, QDeclarativeContext *context) -{ - QObject *object = ObjectNodeInstance::createObject(metaInfo, context); - QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject*>(object); - - if (graphicsObject == 0) - throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__); - -// graphicsObject->setCacheMode(QGraphicsItem::ItemCoordinateCache); - bool hasContent = !graphicsObject->flags().testFlag(QGraphicsItem::ItemHasNoContents) || metaInfo.isComponent(); - graphicsObject->setFlag(QGraphicsItem::ItemHasNoContents, false); - - return qMakePair(graphicsObject, hasContent); -} - void GraphicsObjectNodeInstance::paintUpdate() { graphicsObject()->update(); @@ -264,11 +241,5 @@ void GraphicsObjectNodeInstance::setMovable(bool movable) m_isMovable = movable; } -void GraphicsObjectNodeInstance::renderPixmapNextPaint() -{ - if (graphicsObject() && QGraphicsItemPrivate::get(graphicsObject())->dirty /*|| QGraphicsItemPrivate::get(graphicsObject())->dirtyChildren*/) - m_renderPixmapIsDirty = true; -} - } // namespace Internal } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/graphicsobjectnodeinstance.h b/src/plugins/qmldesigner/designercore/instances/graphicsobjectnodeinstance.h index 3aec7833d7..9db1c0b79e 100644 --- a/src/plugins/qmldesigner/designercore/instances/graphicsobjectnodeinstance.h +++ b/src/plugins/qmldesigner/designercore/instances/graphicsobjectnodeinstance.h @@ -42,11 +42,9 @@ namespace Internal { class GraphicsObjectNodeInstance : public ObjectNodeInstance { public: - GraphicsObjectNodeInstance(QGraphicsObject *graphicsObject, bool hasContent); + GraphicsObjectNodeInstance(QGraphicsObject *graphicsObject); + QImage renderImage() const; - void paint(QPainter *painter); - - bool isTopLevel() const; bool isGraphicsObject() const; QRectF boundingRect() const; @@ -68,27 +66,26 @@ public: bool equalGraphicsItem(QGraphicsItem *item) const; void setPropertyVariant(const QString &name, const QVariant &value); + void setPropertyBinding(const QString &name, const QString &expression); QVariant property(const QString &name) const; bool hasContent() const; + void paintUpdate(); bool isMovable() const; void setMovable(bool movable); - void renderPixmapNextPaint(); protected: - void renderPixmap(); + void setHasContent(bool hasContent); QGraphicsObject *graphicsObject() const; void paintRecursively(QGraphicsItem *graphicsItem, QPainter *painter) const; - static QPair<QGraphicsObject*, bool> createGraphicsObject(const NodeMetaInfo &metaInfo, QDeclarativeContext *context); + private: // variables bool m_hasContent; bool m_isMovable; - QPixmap m_renderPixmap; - bool m_renderPixmapIsDirty; }; } // namespace Internal diff --git a/src/plugins/qmldesigner/designercore/instances/graphicsscenenodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/graphicsscenenodeinstance.cpp deleted file mode 100644 index b19bfe60b8..0000000000 --- a/src/plugins/qmldesigner/designercore/instances/graphicsscenenodeinstance.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#include "graphicsscenenodeinstance.h" - -#include "graphicsviewnodeinstance.h" - -#include <invalidnodeinstanceexception.h> -#include <propertymetainfo.h> - -namespace QmlDesigner { -namespace Internal { - -GraphicsSceneNodeInstance::GraphicsSceneNodeInstance(QGraphicsScene *scene) - :ObjectNodeInstance(scene) -{ -} - -GraphicsSceneNodeInstance::~GraphicsSceneNodeInstance() -{ -} - -GraphicsSceneNodeInstance::Pointer GraphicsSceneNodeInstance::create(const NodeMetaInfo &nodeMetaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped) -{ - QObject *object = 0; - if (objectToBeWrapped) - object = objectToBeWrapped; - else - object = createObject(nodeMetaInfo, context); - - QGraphicsScene* scene = qobject_cast<QGraphicsScene*>(object); - if (scene == 0) - throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__); - - Pointer instance(new GraphicsSceneNodeInstance(scene)); - - if (objectToBeWrapped) - instance->setDeleteHeldInstance(false); // the object isn't owned - - instance->populateResetValueHash(); - - return instance; -} - -void GraphicsSceneNodeInstance::paint(QPainter *) const -{ - Q_ASSERT(graphicsScene()); -} - -bool GraphicsSceneNodeInstance::isTopLevel() const -{ - Q_ASSERT(graphicsScene()); - return graphicsScene()->views().isEmpty(); -} - - -void GraphicsSceneNodeInstance::addItem(QGraphicsItem *item) -{ - graphicsScene()->addItem(item); -} - -bool GraphicsSceneNodeInstance::isGraphicsScene() const -{ - return true; -} - -QRectF GraphicsSceneNodeInstance::boundingRect() const -{ - return graphicsScene()->sceneRect(); -} - -QPointF GraphicsSceneNodeInstance::position() const -{ - return graphicsScene()->sceneRect().topLeft(); -} - -QSizeF GraphicsSceneNodeInstance::size() const -{ - return graphicsScene()->sceneRect().size(); -} - -QGraphicsScene *GraphicsSceneNodeInstance::graphicsScene() const -{ - Q_ASSERT(qobject_cast<QGraphicsScene*>(object())); - return static_cast<QGraphicsScene*>(object()); -} - -bool GraphicsSceneNodeInstance::isVisible() const -{ - return false; -} - -void GraphicsSceneNodeInstance::setVisible(bool /*isVisible*/) -{ - -} - - -} -} diff --git a/src/plugins/qmldesigner/designercore/instances/graphicsscenenodeinstance.h b/src/plugins/qmldesigner/designercore/instances/graphicsscenenodeinstance.h deleted file mode 100644 index fb2335e9f1..0000000000 --- a/src/plugins/qmldesigner/designercore/instances/graphicsscenenodeinstance.h +++ /dev/null @@ -1,73 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef GRAPHICSSCENENODEINSTANCE_H -#define GRAPHICSSCENENODEINSTANCE_H - -#include "objectnodeinstance.h" -#include <QGraphicsScene> -#include <QWeakPointer> - -namespace QmlDesigner { -namespace Internal { - -class GraphicsSceneNodeInstance : public ObjectNodeInstance -{ -public: - typedef QSharedPointer<GraphicsSceneNodeInstance> Pointer; - typedef QWeakPointer<GraphicsSceneNodeInstance> WeakPointer; - - ~GraphicsSceneNodeInstance(); - - static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped); - - void paint(QPainter *painter) const; - - bool isTopLevel() const; - - void addItem(QGraphicsItem *item); - - bool isGraphicsScene() const; - - QRectF boundingRect() const; - QPointF position() const; - QSizeF size() const; - - - bool isVisible() const; - void setVisible(bool isVisible); - -protected: - GraphicsSceneNodeInstance(QGraphicsScene *scene); - QGraphicsScene *graphicsScene() const; -}; - -} -} -#endif // GRAPHICSSCENENODEINSTANCE_H diff --git a/src/plugins/qmldesigner/designercore/instances/graphicsviewnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/graphicsviewnodeinstance.cpp deleted file mode 100644 index 866f0ca9d3..0000000000 --- a/src/plugins/qmldesigner/designercore/instances/graphicsviewnodeinstance.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#include "graphicsviewnodeinstance.h" - -#include <QDeclarativeEngine> -#include <invalidnodeinstanceexception.h> - -namespace QmlDesigner { -namespace Internal { - -GraphicsViewNodeInstance::GraphicsViewNodeInstance(QGraphicsView *view) - : WidgetNodeInstance(view) -{ -} - - -GraphicsViewNodeInstance::Pointer GraphicsViewNodeInstance::create(const NodeMetaInfo &nodeMetaInfo, - QDeclarativeContext *context, - QObject *objectToBeWrapped) -{ - QObject *object = 0; - if (objectToBeWrapped) - object = objectToBeWrapped; - else - object = createObject(nodeMetaInfo, context); - - QGraphicsView* view = qobject_cast<QGraphicsView*>(object); - if (view == 0) - throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__); - - Pointer instance(new GraphicsViewNodeInstance(view)); - - if (objectToBeWrapped) - instance->setDeleteHeldInstance(false); // the object isn't owned - - instance->populateResetValueHash(); - - return instance; -} - -QGraphicsView* GraphicsViewNodeInstance::graphicsView() const -{ - QGraphicsView* view = qobject_cast<QGraphicsView*>(widget()); - Q_ASSERT(view); - return view; -} - -void GraphicsViewNodeInstance::setScene(QGraphicsScene *scene) -{ - graphicsView()->setScene(scene); -} - -bool GraphicsViewNodeInstance::isGraphicsView() const -{ - return true; -} - -QSizeF GraphicsViewNodeInstance::size() const -{ - return graphicsView()->scene()->itemsBoundingRect().size(); -} - -QTransform GraphicsViewNodeInstance::transform() const -{ - return graphicsView()->transform(); -} - -void GraphicsViewNodeInstance::paint(QPainter *painter) const -{ - painter->save(); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->setRenderHint(QPainter::TextAntialiasing, true); - painter->setRenderHint(QPainter::SmoothPixmapTransform, true); - painter->setRenderHint(QPainter::HighQualityAntialiasing, true); - painter->setRenderHint(QPainter::NonCosmeticDefaultPen, true); - graphicsView()->render(painter, QRectF(), graphicsView()->scene()->itemsBoundingRect().toRect()); - painter->restore(); -} - -} -} diff --git a/src/plugins/qmldesigner/designercore/instances/graphicsviewnodeinstance.h b/src/plugins/qmldesigner/designercore/instances/graphicsviewnodeinstance.h deleted file mode 100644 index 5c0a9ce578..0000000000 --- a/src/plugins/qmldesigner/designercore/instances/graphicsviewnodeinstance.h +++ /dev/null @@ -1,67 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef GRAPHICSVIEWNODEINSTANCE_H -#define GRAPHICSVIEWNODEINSTANCE_H - -#include <QWeakPointer> -#include <QGraphicsView> - -#include "widgetnodeinstance.h" - -namespace QmlDesigner { -namespace Internal { - -class GraphicsViewNodeInstance : public WidgetNodeInstance -{ -public: - typedef QSharedPointer<GraphicsViewNodeInstance> Pointer; - typedef QWeakPointer<GraphicsViewNodeInstance> WeakPointer; - - static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped); - - void setScene(QGraphicsScene *scene); - - bool isGraphicsView() const; - - QTransform transform() const; - QSizeF size() const; - - - void paint(QPainter *painter) const; - -protected: - GraphicsViewNodeInstance(QGraphicsView *view); - - QGraphicsView* graphicsView() const; -}; - -} -} -#endif // GRAPHICSVIEWNODEINSTANCE_H diff --git a/src/plugins/qmldesigner/designercore/instances/graphicswidgetnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/graphicswidgetnodeinstance.cpp deleted file mode 100644 index de5239ec0a..0000000000 --- a/src/plugins/qmldesigner/designercore/instances/graphicswidgetnodeinstance.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#include "graphicswidgetnodeinstance.h" -#include "graphicsscenenodeinstance.h" - -#include "objectnodeinstance.h" - -#include <invalidnodeinstanceexception.h> -#include <propertymetainfo.h> - -namespace QmlDesigner { -namespace Internal { - -GraphicsWidgetNodeInstance::GraphicsWidgetNodeInstance(QGraphicsWidget *widget) - : ObjectNodeInstance(widget) -{ -} - -GraphicsWidgetNodeInstance::~GraphicsWidgetNodeInstance() -{ -} - -GraphicsWidgetNodeInstance::Pointer GraphicsWidgetNodeInstance::create(const NodeMetaInfo &nodeMetaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped) -{ - QObject *object = 0; - if (objectToBeWrapped) - object = objectToBeWrapped; - else - object = createObject(nodeMetaInfo, context); - - QGraphicsWidget* graphicsWidget = qobject_cast<QGraphicsWidget*>(object); - if (graphicsWidget == 0) - throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__); - - Pointer instance(new GraphicsWidgetNodeInstance(graphicsWidget)); - - if (objectToBeWrapped) - instance->setDeleteHeldInstance(false); // the object isn't owned - - instance->populateResetValueHash(); - - return instance; -} - -void GraphicsWidgetNodeInstance::paint(QPainter *painter) const -{ - graphicsWidget()->show(); - graphicsWidget()->paint(painter, 0); - - paintChildren(painter, graphicsWidget()); -} - -bool GraphicsWidgetNodeInstance::isTopLevel() const -{ - return !graphicsWidget()->parentItem(); -} - - -bool isChildNode(QGraphicsItem *item) -{ - // there should be a better implementation - if (qgraphicsitem_cast<QGraphicsWidget*>(item)) - return false; - else - return true; -} - -void GraphicsWidgetNodeInstance::paintChildren(QPainter *painter, QGraphicsItem *item) const -{ - foreach (QGraphicsItem *childItem, item->childItems()) { - if (!isChildNode(childItem)) { - painter->save(); - painter->setTransform(item->transform(), true); - item->paint(painter, 0); - paintChildren(painter, childItem); - painter->restore(); - } - } -} - -void GraphicsWidgetNodeInstance::setParentItem(QGraphicsItem *item) -{ - graphicsWidget()->setParentItem(item); -} - -QGraphicsWidget* GraphicsWidgetNodeInstance::graphicsWidget() const -{ - return static_cast<QGraphicsWidget*>(object()); -} - -bool GraphicsWidgetNodeInstance::isGraphicsWidget() const -{ - return true; -} - -bool GraphicsWidgetNodeInstance::isGraphicsItem(QGraphicsItem *item) const -{ - return graphicsWidget() == item; -} - -QRectF GraphicsWidgetNodeInstance::boundingRect() const -{ - return graphicsWidget()->boundingRect(); -} - -void GraphicsWidgetNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) -{ - if (name == "x") - graphicsWidget()->setPos(value.toDouble(), graphicsWidget()->y()); - else if (name == "y") - graphicsWidget()->setPos(graphicsWidget()->x(), value.toDouble()); - else if (name == "width") - graphicsWidget()->resize(value.toDouble(), graphicsWidget()->size().height()); - else if (name == "height") - graphicsWidget()->resize(graphicsWidget()->size().width(), value.toDouble()); - else - graphicsWidget()->setProperty(name.toLatin1(), value); -} - -QVariant GraphicsWidgetNodeInstance::property(const QString &name) const -{ - return graphicsWidget()->property(name.toLatin1()); -} - -bool GraphicsWidgetNodeInstance::isVisible() const -{ - return graphicsWidget()->isVisible(); -} - -void GraphicsWidgetNodeInstance::setVisible(bool isVisible) -{ - graphicsWidget()->setVisible(isVisible); -} - -QPointF GraphicsWidgetNodeInstance::position() const -{ - return graphicsWidget()->pos(); -} - -QSizeF GraphicsWidgetNodeInstance::size() const -{ - return graphicsWidget()->size(); -} - -QTransform GraphicsWidgetNodeInstance::transform() const -{ - return graphicsWidget()->transform(); -} - -double GraphicsWidgetNodeInstance::opacity() const -{ - return graphicsWidget()->opacity(); -} - -} -} diff --git a/src/plugins/qmldesigner/designercore/instances/graphicswidgetnodeinstance.h b/src/plugins/qmldesigner/designercore/instances/graphicswidgetnodeinstance.h deleted file mode 100644 index 17fef1f1a7..0000000000 --- a/src/plugins/qmldesigner/designercore/instances/graphicswidgetnodeinstance.h +++ /dev/null @@ -1,80 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef GRAPHICSWIDGETNODEINSTANCE_H -#define GRAPHICSWIDGETNODEINSTANCE_H - -#include <QWeakPointer> -#include <QGraphicsWidget> - -#include "objectnodeinstance.h" - -namespace QmlDesigner { -namespace Internal { - -class GraphicsWidgetNodeInstance : public ObjectNodeInstance -{ -public: - typedef QSharedPointer<GraphicsWidgetNodeInstance> Pointer; - typedef QWeakPointer<GraphicsWidgetNodeInstance> WeakPointer; - - ~GraphicsWidgetNodeInstance(); - - static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped); - - void paint(QPainter *painter) const; - - bool isTopLevel() const; - - bool isGraphicsWidget() const; - bool isGraphicsItem(QGraphicsItem *item) const; - - QRectF boundingRect() const; - QPointF position() const; - QSizeF size() const; - QTransform transform() const; - double opacity() const; - - void setPropertyVariant(const QString &name, const QVariant &value); - QVariant property(const QString &name) const; - - bool isVisible() const; - void setVisible(bool isVisible); - -protected: - GraphicsWidgetNodeInstance(QGraphicsWidget *widget); - void paintChildren(QPainter *painter, QGraphicsItem *item) const; - void setParentItem(QGraphicsItem *item); - QGraphicsWidget* graphicsWidget() const; - -}; - -} -} -#endif // GRAPHICSWIDGETNODEINSTANCE_H diff --git a/src/plugins/qmldesigner/designercore/instances/idcontainer.cpp b/src/plugins/qmldesigner/designercore/instances/idcontainer.cpp new file mode 100644 index 0000000000..691e67e583 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/idcontainer.cpp @@ -0,0 +1,41 @@ +#include "idcontainer.h" + +namespace QmlDesigner { + +IdContainer::IdContainer() + : m_instanceId(-1) +{ +} + +IdContainer::IdContainer(qint32 instanceId, const QString &id) + : m_instanceId(instanceId), + m_id(id) +{ +} + +qint32 IdContainer::instanceId() const +{ + return m_instanceId; +} + +QString IdContainer::id() const +{ + return m_id; +} + +QDataStream &operator<<(QDataStream &out, const IdContainer &container) +{ + out << container.instanceId(); + out << container.id(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, IdContainer &container) +{ + in >> container.m_instanceId; + in >> container.m_id; + + return in; +} +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/idcontainer.h b/src/plugins/qmldesigner/designercore/instances/idcontainer.h new file mode 100644 index 0000000000..ae3a0fe583 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/idcontainer.h @@ -0,0 +1,34 @@ +#ifndef IDCONTAINER_H +#define IDCONTAINER_H + +#include <QDataStream> +#include <qmetatype.h> +#include <QString> + + +namespace QmlDesigner { + +class IdContainer +{ + friend QDataStream &operator>>(QDataStream &in, IdContainer &container); + +public: + IdContainer(); + IdContainer(qint32 instanceId, const QString &id); + + qint32 instanceId() const; + QString id() const; + +private: + qint32 m_instanceId; + QString m_id; +}; + +QDataStream &operator<<(QDataStream &out, const IdContainer &container); +QDataStream &operator>>(QDataStream &in, IdContainer &container); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::IdContainer); + +#endif // IDCONTAINER_H diff --git a/src/plugins/qmldesigner/designercore/instances/informationchangedcommand.cpp b/src/plugins/qmldesigner/designercore/instances/informationchangedcommand.cpp new file mode 100644 index 0000000000..0445769e1a --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/informationchangedcommand.cpp @@ -0,0 +1,37 @@ +#include "informationchangedcommand.h" + +#include <QMetaType> + +#include "propertyvaluecontainer.h" + +namespace QmlDesigner { + +InformationChangedCommand::InformationChangedCommand() +{ +} + +InformationChangedCommand::InformationChangedCommand(const QVector<InformationContainer> &informationVector) + : m_informationVector(informationVector) +{ +} + +QVector<InformationContainer> InformationChangedCommand::informations() const +{ + return m_informationVector; +} + +QDataStream &operator<<(QDataStream &out, const InformationChangedCommand &command) +{ + out << command.informations(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, InformationChangedCommand &command) +{ + in >> command.m_informationVector; + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/informationchangedcommand.h b/src/plugins/qmldesigner/designercore/instances/informationchangedcommand.h new file mode 100644 index 0000000000..91a01ae1c2 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/informationchangedcommand.h @@ -0,0 +1,32 @@ +#ifndef INFORMATIONCHANGEDCOMMAND_H +#define INFORMATIONCHANGEDCOMMAND_H + +#include <QMetaType> +#include <QVector> + +#include "informationcontainer.h" + +namespace QmlDesigner { + +class InformationChangedCommand +{ + friend QDataStream &operator>>(QDataStream &in, InformationChangedCommand &command); + +public: + InformationChangedCommand(); + InformationChangedCommand(const QVector<InformationContainer> &informationVector); + + QVector<InformationContainer> informations() const; + +private: + QVector<InformationContainer> m_informationVector; +}; + +QDataStream &operator<<(QDataStream &out, const InformationChangedCommand &command); +QDataStream &operator>>(QDataStream &in, InformationChangedCommand &command); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::InformationChangedCommand); + +#endif // INFORMATIONCHANGEDCOMMAND_H diff --git a/src/plugins/qmldesigner/designercore/instances/informationcontainer.cpp b/src/plugins/qmldesigner/designercore/instances/informationcontainer.cpp new file mode 100644 index 0000000000..6ca4103527 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/informationcontainer.cpp @@ -0,0 +1,72 @@ +#include "informationcontainer.h" + +namespace QmlDesigner { + +InformationContainer::InformationContainer() + : m_instanceId(-1), + m_name(NoName) +{ +} + +InformationContainer::InformationContainer(qint32 instanceId, + InformationName name, + const QVariant &information, + const QVariant &secondInformation, + const QVariant &thirdInformation) + : m_instanceId(instanceId), + m_name(name), + m_information(information), + m_secondInformation(secondInformation), + m_thirdInformation(thirdInformation) +{ +} + +qint32 InformationContainer::instanceId() const +{ + return m_instanceId; +} + +InformationName InformationContainer::name() const +{ + return InformationName(m_name); +} + +QVariant InformationContainer::information() const +{ + return m_information; +} + +QVariant InformationContainer::secondInformation() const +{ + return m_secondInformation; +} + +QVariant InformationContainer::thirdInformation() const +{ + return m_thirdInformation; +} + +QDataStream &operator<<(QDataStream &out, const InformationContainer &container) +{ + out << container.instanceId();// + out << container.m_name; + out << container.information(); + out << container.secondInformation(); + out << container.thirdInformation(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, InformationContainer &container) +{ + + in >> container.m_instanceId; + in >> container.m_name; + in >> container.m_information; + in >> container.m_secondInformation; + in >> container.m_thirdInformation; + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/informationcontainer.h b/src/plugins/qmldesigner/designercore/instances/informationcontainer.h new file mode 100644 index 0000000000..f69c3a19d2 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/informationcontainer.h @@ -0,0 +1,47 @@ +#ifndef INFORMATIONCONTAINER_H +#define INFORMATIONCONTAINER_H + +#include <QDataStream> +#include <QMetaType> +#include <QVariant> +#include <QString> + +#include "commondefines.h" + +namespace QmlDesigner { + +class InformationContainer +{ + friend QDataStream &operator>>(QDataStream &in, InformationContainer &container); + friend QDataStream &operator<<(QDataStream &out, const InformationContainer &container); + +public: + InformationContainer(); + InformationContainer(qint32 instanceId, + InformationName name, + const QVariant &information, + const QVariant &secondInformation = QVariant(), + const QVariant &thirdInformation = QVariant()); + + qint32 instanceId() const; + InformationName name() const; + QVariant information() const; + QVariant secondInformation() const; + QVariant thirdInformation() const; + +private: + qint32 m_instanceId; + qint32 m_name; + QVariant m_information; + QVariant m_secondInformation; + QVariant m_thirdInformation; +}; + +QDataStream &operator<<(QDataStream &out, const InformationContainer &container); +QDataStream &operator>>(QDataStream &in, InformationContainer &container); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::InformationContainer); + +#endif // INFORMATIONCONTAINER_H diff --git a/src/plugins/qmldesigner/designercore/instances/instancecontainer.cpp b/src/plugins/qmldesigner/designercore/instances/instancecontainer.cpp new file mode 100644 index 0000000000..d0831480e2 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/instancecontainer.cpp @@ -0,0 +1,62 @@ +#include "instancecontainer.h" + +namespace QmlDesigner { + +InstanceContainer::InstanceContainer() + : m_instanceId(-1), m_majorNumber(-1), m_minorNumber(-1) +{ +} + +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) +{ +} + +qint32 InstanceContainer::instanceId() const +{ + return m_instanceId; +} + +QString InstanceContainer::type() const +{ + return m_type; +} + +int InstanceContainer::majorNumber() const +{ + return m_majorNumber; +} + +int InstanceContainer::minorNumber() const +{ + return m_minorNumber; +} + +QString InstanceContainer::componentPath() const +{ + return m_componentPath; +} + +QDataStream &operator<<(QDataStream &out, const InstanceContainer &container) +{ + out << container.instanceId(); + out << container.type(); + out << container.majorNumber(); + out << container.minorNumber(); + out << container.componentPath(); + + return out; +} + + +QDataStream &operator>>(QDataStream &in, InstanceContainer &container) +{ + in >> container.m_instanceId; + in >> container.m_type; + in >> container.m_majorNumber; + in >> container.m_minorNumber; + in >> container.m_componentPath; + + return in; +} +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/instancecontainer.h b/src/plugins/qmldesigner/designercore/instances/instancecontainer.h new file mode 100644 index 0000000000..e153b56188 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/instancecontainer.h @@ -0,0 +1,39 @@ +#ifndef INSTANCECONTAINER_H +#define INSTANCECONTAINER_H + +#include <qmetatype.h> +#include <QString> + +namespace QmlDesigner { + +class InstanceContainer; + +QDataStream &operator<<(QDataStream &out, const InstanceContainer &container); +QDataStream &operator>>(QDataStream &in, InstanceContainer &container); + +class InstanceContainer +{ + friend QDataStream &operator>>(QDataStream &in, InstanceContainer &container); + +public: + InstanceContainer(); + InstanceContainer(qint32 instanceId, const QString &type, int majorNumber, int minorNumber, const QString &componentPath); + + qint32 instanceId() const; + QString type() const; + int majorNumber() const; + int minorNumber() const; + QString componentPath() const; + +private: + qint32 m_instanceId; + QString m_type; + int m_majorNumber; + int m_minorNumber; + QString m_componentPath; +}; + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::InstanceContainer); +#endif // INSTANCECONTAINER_H diff --git a/src/plugins/qmldesigner/designercore/instances/instances.pri b/src/plugins/qmldesigner/designercore/instances/instances.pri new file mode 100644 index 0000000000..0b51ea01e7 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/instances.pri @@ -0,0 +1,81 @@ +INCLUDEPATH += $$PWD/ +INCLUDEPATH += $$PWD/../include + + +HEADERS += $$PWD/behaviornodeinstance.h +HEADERS += $$PWD/changebindingscommand.h +HEADERS += $$PWD/changefileurlcommand.h +HEADERS += $$PWD/changeidscommand.h +HEADERS += $$PWD/changestatecommand.h +HEADERS += $$PWD/changevaluescommand.h +HEADERS += $$PWD/childrenchangeeventfilter.h +HEADERS += $$PWD/clearscenecommand.h +HEADERS += $$PWD/componentnodeinstance.h +HEADERS += $$PWD/createinstancescommand.h +HEADERS += $$PWD/createscenecommand.h +HEADERS += $$PWD/declarativedesignercommunicationinterface.h +HEADERS += $$PWD/dummynodeinstance.h +HEADERS += $$PWD/graphicsobjectnodeinstance.h +HEADERS += $$PWD/idcontainer.h +HEADERS += $$PWD/informationchangedcommand.h +HEADERS += $$PWD/informationcontainer.h +HEADERS += $$PWD/instancecontainer.h +HEADERS += $$PWD/nodeinstanceclientproxy.h +HEADERS += $$PWD/nodeinstancemetaobject.h +HEADERS += $$PWD/nodeinstanceserver.h +HEADERS += $$PWD/nodeinstancesignalspy.h +HEADERS += $$PWD/objectnodeinstance.h +HEADERS += $$PWD/pixmapchangedcommand.h +HEADERS += $$PWD/positionernodeinstance.h +HEADERS += $$PWD/qmlgraphicsitemnodeinstance.h +HEADERS += $$PWD/qmlpropertychangesnodeinstance.h +HEADERS += $$PWD/qmlstatenodeinstance.h +HEADERS += $$PWD/qmltransitionnodeinstance.h +HEADERS += $$PWD/removeinstancescommand.h +HEADERS += $$PWD/removepropertiescommand.h +HEADERS += $$PWD/reparentcontainer.h +HEADERS += $$PWD/reparentinstancescommand.h +HEADERS += $$PWD/servernodeinstance.h +HEADERS += $$PWD/valueschangedcommand.h +HEADERS += $$PWD/../include/nodeinstanceserverinterface.h + + +SOURCES += $$PWD/behaviornodeinstance.cpp +SOURCES += $$PWD/changebindingscommand.cpp +SOURCES += $$PWD/changefileurlcommand.cpp +SOURCES += $$PWD/changeidscommand.cpp +SOURCES += $$PWD/changestatecommand.cpp +SOURCES += $$PWD/changevaluescommand.cpp +SOURCES += $$PWD/childrenchangeeventfilter.cpp +SOURCES += $$PWD/clearscenecommand.cpp +SOURCES += $$PWD/componentnodeinstance.cpp +SOURCES += $$PWD/createinstancescommand.cpp +SOURCES += $$PWD/createscenecommand.cpp +SOURCES += $$PWD/declarativedesignercommunicationinterface.cpp +SOURCES += $$PWD/dummynodeinstance.cpp +SOURCES += $$PWD/graphicsobjectnodeinstance.cpp +SOURCES += $$PWD/idcontainer.cpp +SOURCES += $$PWD/informationchangedcommand.cpp +SOURCES += $$PWD/informationcontainer.cpp +SOURCES += $$PWD/instancecontainer.cpp +SOURCES += $$PWD/nodeinstanceclientproxy.cpp +SOURCES += $$PWD/nodeinstancemetaobject.cpp +SOURCES += $$PWD/nodeinstanceserver.cpp +SOURCES += $$PWD/nodeinstanceserverinterface.cpp +SOURCES += $$PWD/nodeinstancesignalspy.cpp +SOURCES += $$PWD/objectnodeinstance.cpp +SOURCES += $$PWD/pixmapchangedcommand.cpp +SOURCES += $$PWD/positionernodeinstance.cpp +SOURCES += $$PWD/propertyabstractcontainer.cpp +SOURCES += $$PWD/propertybindingcontainer.cpp +SOURCES += $$PWD/propertyvaluecontainer.cpp +SOURCES += $$PWD/qmlgraphicsitemnodeinstance.cpp +SOURCES += $$PWD/qmlpropertychangesnodeinstance.cpp +SOURCES += $$PWD/qmlstatenodeinstance.cpp +SOURCES += $$PWD/qmltransitionnodeinstance.cpp +SOURCES += $$PWD/removeinstancescommand.cpp +SOURCES += $$PWD/removepropertiescommand.cpp +SOURCES += $$PWD/reparentcontainer.cpp +SOURCES += $$PWD/reparentinstancescommand.cpp +SOURCES += $$PWD/servernodeinstance.cpp +SOURCES += $$PWD/valueschangedcommand.cpp diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp index 5476860020..5934d43ff8 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstance.cpp @@ -1,697 +1,311 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - #include "nodeinstance.h" -#include "objectnodeinstance.h" -#include "metainfo.h" -#include "graphicswidgetnodeinstance.h" -#include "widgetnodeinstance.h" -#include "qmlgraphicsitemnodeinstance.h" -#include "graphicsscenenodeinstance.h" -#include "graphicsviewnodeinstance.h" -#include "nodeinstanceview.h" -#include "qmlviewnodeinstance.h" -#include "dummynodeinstance.h" -#include "componentnodeinstance.h" -#include "qmltransitionnodeinstance.h" -#include "qmlpropertychangesnodeinstance.h" -#include "positionernodeinstance.h" -#include "behaviornodeinstance.h" -#include "qmlstatenodeinstance.h" -#include "nodeabstractproperty.h" -#include "variantproperty.h" - -#include <invalidnodeinstanceexception.h> - -#include <QHash> -#include <QSet> - -#include <QtDeclarative/QDeclarativeEngine> - -/*! - \class QmlDesigner::NodeInstance - \ingroup CoreInstance - \brief NodeInstance is a common handle for the actual object representation of a ModelNode. - - NodeInstance abstracts away the differences e.g. in terms of position and size - for QWidget, QGraphicsView, QLayout etc objects. Multiple NodeInstance objects can share - the pointer to the same instance object. The actual instance will be deleted when - the last NodeInstance object referencing to it is deleted. This can be disabled by - setDeleteHeldInstance(). - - \see QmlDesigner::NodeInstanceView -*/ +#include <QPainter> +#include <modelnode.h> +#include "commondefines.h" -namespace QmlDesigner { +#include <QtDebug> -/*! -\brief Constructor - creates a invalid NodeInstance +namespace QmlDesigner { +class ProxyNodeInstanceData +{ +public: + ProxyNodeInstanceData() + : instanceId(-1), + parentInstanceId(-1), + penWidth(1), + isAnchoredBySibling(false), + isAnchoredByChildren(false), + hasContent(false), + isMovable(false), + isResizable(false), + isInPositioner(false) + {} + + qint32 instanceId; + qint32 parentInstanceId; + ModelNode modelNode; + QRectF boundingRect; + QPointF position; + QSizeF size; + QTransform transform; + QTransform sceneTransform; + int penWidth; + bool isAnchoredBySibling; + bool isAnchoredByChildren; + bool hasContent; + bool isMovable; + bool isResizable; + bool isInPositioner; + + + QHash<QString, QVariant> propertyValues; + QHash<QString, bool> hasBindingForProperty; + QHash<QString, bool> hasAnchors; + QHash<QString, QString> instanceTypes; + + QImage renderImage; + QHash<QString, QPair<QString, qint32> > anchors; +}; -\see NodeInstanceView -*/ NodeInstance::NodeInstance() { } -/*! -\brief Destructor - -*/ -NodeInstance::~NodeInstance() -{ -} - -/*! -\brief Constructor - creates a valid NodeInstance - -*/ -NodeInstance::NodeInstance(const Internal::ObjectNodeInstance::Pointer &abstractInstance) - : m_nodeInstance(abstractInstance) +NodeInstance::NodeInstance(ProxyNodeInstanceData *dPointer) + : d(dPointer) { - } - -NodeInstance::NodeInstance(const NodeInstance &other) - : m_nodeInstance(other.m_nodeInstance) +NodeInstance NodeInstance::create(const ModelNode &node, qint32 instanceId) { -} + ProxyNodeInstanceData *d = new ProxyNodeInstanceData; -NodeInstance &NodeInstance::operator=(const NodeInstance &other) -{ - m_nodeInstance = other.m_nodeInstance; - return *this; -} + d->modelNode = node; + d->instanceId = instanceId; -/*! -\brief Paints the NodeInstance with this painter. -\param painter used QPainter -*/ -void NodeInstance::paint(QPainter *painter) -{ - m_nodeInstance->paint(painter); + return NodeInstance(d); } -/*! -\brief Creates a new NodeInstace for this NodeMetaInfo - -\param metaInfo MetaInfo for which a Instance should be created -\param context QDeclarativeContext which should be used -\returns Internal Pointer of a NodeInstance -\see NodeMetaInfo -*/ -Internal::ObjectNodeInstance::Pointer NodeInstance::createInstance(const NodeMetaInfo &metaInfo, - QDeclarativeContext *context, QObject *objectToBeWrapped) +NodeInstance::~NodeInstance() { - Internal::ObjectNodeInstance::Pointer instance; - - qDebug() << __FUNCTION__ << metaInfo.typeName() << metaInfo.directSuperClass().typeName(); - - if (!metaInfo.isValid()) - instance = Internal::DummyNodeInstance::create(); - else if (metaInfo.isSubclassOf("Qt/QWidget", 4, 7)) - instance = Internal::DummyNodeInstance::create(); - else if (metaInfo.isSubclassOf("Qt/QGraphicsView", 4, 7)) - instance = Internal::GraphicsViewNodeInstance::create(metaInfo, context, objectToBeWrapped); - else if (metaInfo.isSubclassOf("Qt/QDeclarativeView", 4, 7)) - instance = Internal::QDeclarativeViewNodeInstance::create(metaInfo, context, objectToBeWrapped); - else if (metaInfo.isSubclassOf("Qt/QGraphicsWidget", 4, 7)) - instance = Internal::GraphicsWidgetNodeInstance::create(metaInfo, context, objectToBeWrapped); - else if (metaInfo.isSubclassOf("QDeclarativeBasePositioner", 4, 7)) - instance = Internal::PositionerNodeInstance::create(metaInfo, context, objectToBeWrapped); - else if (metaInfo.isSubclassOf("Qt/Item", 4, 7)) - instance = Internal::QmlGraphicsItemNodeInstance::create(metaInfo, context, objectToBeWrapped); - else if (metaInfo.isSubclassOf("Qt/QGraphicsScene", 4, 7)) - instance = Internal::GraphicsSceneNodeInstance::create(metaInfo, context, objectToBeWrapped); - else if (metaInfo.isSubclassOf("Qt/Component", 4, 7)) - instance = Internal::ComponentNodeInstance::create(metaInfo, context, objectToBeWrapped); - else if (metaInfo.isSubclassOf("Qt/PropertyChanges", 4, 7)) - instance = Internal::QmlPropertyChangesNodeInstance::create(metaInfo, context, objectToBeWrapped); - else if (metaInfo.isSubclassOf("Qt/State", 4, 7)) - instance = Internal::QmlStateNodeInstance::create(metaInfo, context, objectToBeWrapped); - else if (metaInfo.isSubclassOf("Qt/Transition", 4, 7)) - instance = Internal::QmlTransitionNodeInstance::create(metaInfo, context, objectToBeWrapped); - else if (metaInfo.isSubclassOf("Qt/Behavior", 4, 7)) - instance = Internal::BehaviorNodeInstance::create(metaInfo, context, objectToBeWrapped); - else if (metaInfo.isSubclassOf("Qt/QtObject", 4, 7)) - instance = Internal::ObjectNodeInstance::create(metaInfo, context, objectToBeWrapped); - else - instance = Internal::DummyNodeInstance::create(); - - - return instance; } - - -NodeInstance NodeInstance::create(NodeInstanceView *nodeInstanceView, const ModelNode &node, QObject *objectToBeWrapped) +NodeInstance::NodeInstance(const NodeInstance &other) + : d(other.d) { - Q_ASSERT(node.isValid()); - Q_ASSERT(nodeInstanceView); - - // For the moment just use the root context of the engine - // for all items. However, this is a hack ... ideally we should - // rebuild the same context hierarchy as the qml compiler does - - QDeclarativeContext *context = nodeInstanceView->engine()->rootContext(); - - NodeInstance instance(createInstance(node.metaInfo(), context, objectToBeWrapped)); - - instance.m_nodeInstance->setModelNode(node); - - instance.m_nodeInstance->setNodeInstanceView(nodeInstanceView); - - instance.m_nodeInstance->initializePropertyWatcher(instance.m_nodeInstance); - - instance.setId(node.id()); - - //QObject::connect(instance.internalObject(), SIGNAL(destroyed(QObject*)), nodeInstanceView, SLOT(removeIdFromContext(QObject*))); - - foreach (const VariantProperty &property, node.variantProperties()) { - if (property.isDynamic()) - instance.setPropertyDynamicVariant(property.name(), property.dynamicTypeName(), property.value()); - else - instance.setPropertyVariant(property.name(), property.value()); - } - - return instance; } -NodeInstance NodeInstance::create(NodeInstanceView *nodeInstanceView, const NodeMetaInfo &metaInfo, QDeclarativeContext *context) +NodeInstance &NodeInstance::operator=(const NodeInstance &other) { - NodeInstance instance(createInstance(metaInfo, context, 0)); - instance.m_nodeInstance->setNodeInstanceView(nodeInstanceView); - - return instance; + d = other.d; + return *this; } -/*! -\brief Returns the ModelNode of this NodeInstance. -\returns ModelNode of this NodeState -*/ ModelNode NodeInstance::modelNode() const { - if (m_nodeInstance.isNull()) + if (isValid()) { + return d->modelNode; + } else { return ModelNode(); - - return m_nodeInstance->modelNode(); -} - - -/*! -\brief Changes the NodeState of the ModelNode of this NodeInstance. - All properties are updated. -\param state NodeState of this NodeInstance -*/ -void NodeInstance::setModelNode(const ModelNode &node) -{ - Q_ASSERT(node.isValid()); - if (m_nodeInstance->modelNode() == node) - return; - - m_nodeInstance->setModelNode(node); -} - -/*! -\brief Returns if the NodeInstance is a top level item. -\returns true if this NodeInstance is a top level item -*/ -bool NodeInstance::isTopLevel() const -{ - return m_nodeInstance->isTopLevel(); -} - -void NodeInstance::reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty) -{ - m_nodeInstance->reparent(oldParentInstance, oldParentProperty, newParentInstance, newParentProperty); -} - -/*! -\brief Returns the parent NodeInstance of this NodeInstance. - - If there is not parent than the parent is invalid. - -\returns Parent NodeInstance. -*/ -NodeInstance NodeInstance::parent() const -{ - return m_nodeInstance->nodeInstanceParentForObject(m_nodeInstance->parent()); -} - -bool NodeInstance::hasParent() const -{ - return m_nodeInstance->parent(); -} - -/*! -\brief Returns if the NodeInstance is a QDeclarativeItem. -\returns true if this NodeInstance is a QDeclarativeItem -*/ -bool NodeInstance::isQmlGraphicsItem() const -{ - return m_nodeInstance->isQmlGraphicsItem(); -} - -/*! -\brief Returns if the NodeInstance is a QGraphicsScene. -\returns true if this NodeInstance is a QGraphicsScene -*/ -bool NodeInstance::isGraphicsScene() const -{ - return m_nodeInstance->isGraphicsScene(); -} - -/*! -\brief Returns if the NodeInstance is a QGraphicsView. -\returns true if this NodeInstance is a QGraphicsView -*/ -bool NodeInstance::isGraphicsView() const -{ - return m_nodeInstance->isGraphicsView(); -} - -/*! -\brief Returns if the NodeInstance is a QGraphicsWidget. -\returns true if this NodeInstance is a QGraphicsWidget -*/ -bool NodeInstance::isGraphicsWidget() const -{ - return m_nodeInstance->isGraphicsWidget(); -} - -/*! -\brief Returns if the NodeInstance is a QGraphicsProxyWidget. -\returns true if this NodeInstance is a QGraphicsProxyWidget -*/ -bool NodeInstance::isProxyWidget() const -{ - return m_nodeInstance->isProxyWidget(); -} - -/*! -\brief Returns if the NodeInstance is a QWidget. -\returns true if this NodeInstance is a QWidget -*/ -bool NodeInstance::isWidget() const -{ - return m_nodeInstance->isWidget(); -} - -/*! -\brief Returns if the NodeInstance is a QDeclarativeView. -\returns true if this NodeInstance is a QDeclarativeView -*/ -bool NodeInstance::isQDeclarativeView() const -{ - return m_nodeInstance->isQDeclarativeView(); -} - -bool NodeInstance::isGraphicsObject() const -{ - return m_nodeInstance->isGraphicsObject(); -} - -bool NodeInstance::isTransition() const -{ - return m_nodeInstance->isTransition(); -} - -bool NodeInstance::isPositioner() const -{ - return m_nodeInstance->isPositioner(); -} - -/*! -\brief Returns if the NodeInstance is a QGraphicsItem. -\returns true if this NodeInstance is a QGraphicsItem -*/ -bool NodeInstance::equalGraphicsItem(QGraphicsItem *item) const -{ - return m_nodeInstance->equalGraphicsItem(item); -} - -/*! -\brief Returns the bounding rect of the NodeInstance. -\returns QRectF of the NodeInstance -*/ -QRectF NodeInstance::boundingRect() const -{ - QRectF boundingRect(m_nodeInstance->boundingRect()); - -// -// if (modelNode().isValid()) { // TODO implement recursiv stuff -// if (qFuzzyIsNull(boundingRect.width())) -// boundingRect.setWidth(nodeState().property("width").value().toDouble()); -// -// if (qFuzzyIsNull(boundingRect.height())) -// boundingRect.setHeight(nodeState().property("height").value().toDouble()); -// } - - return boundingRect; -} - -void NodeInstance::setPropertyVariant(const QString &name, const QVariant &value) -{ - m_nodeInstance->setPropertyVariant(name, value); - -} - -void NodeInstance::setPropertyDynamicVariant(const QString &name, const QString &typeName, const QVariant &value) -{ - m_nodeInstance->createDynamicProperty(name, typeName); - m_nodeInstance->setPropertyVariant(name, value); -} - -void NodeInstance::setPropertyBinding(const QString &name, const QString &expression) -{ - m_nodeInstance->setPropertyBinding(name, expression); -} - -void NodeInstance::setPropertyDynamicBinding(const QString &name, const QString &typeName, const QString &expression) -{ - m_nodeInstance->createDynamicProperty(name, typeName); - m_nodeInstance->setPropertyBinding(name, expression); -} - -void NodeInstance::resetProperty(const QString &name) -{ - m_nodeInstance->resetProperty(name); -} - -void NodeInstance::refreshProperty(const QString &name) -{ - m_nodeInstance->refreshProperty(name); -} - -void NodeInstance::setId(const QString &id) -{ - m_nodeInstance->setId(id); -} - -/*! -\brief Returns the property value of the property of this NodeInstance. -\returns QVariant value -*/ -QVariant NodeInstance::property(const QString &name) const -{ - return m_nodeInstance->property(name); -} - -bool NodeInstance::hasBindingForProperty(const QString &name) const -{ - return m_nodeInstance->hasBindingForProperty(name); -} - -/*! -\brief Returns the property default value of the property of this NodeInstance. -\returns QVariant default value which is the reset value to -*/ -QVariant NodeInstance::defaultValue(const QString &name) const -{ - return m_nodeInstance->resetValue(name); + } } -/*! -\brief Returns the type of the property of this NodeInstance. -*/ -QString NodeInstance::instanceType(const QString &name) const +qint32 NodeInstance::instanceId() const { - return m_nodeInstance->instanceType(name); + if (d) { + return d->instanceId; + } else { + return -1; + } } -/*! -\brief Returns if the NodeInstance is valid. -\returns true if the NodeInstance is valid -*/ bool NodeInstance::isValid() const { - return m_nodeInstance && internalObject(); + return instanceId() >= 0; } void NodeInstance::makeInvalid() { - if (m_nodeInstance) - m_nodeInstance->destroy(); - m_nodeInstance.clear(); + if (d) + d->instanceId = -1; } -void NodeInstance::renderPixmapNextPaint() +QRectF NodeInstance::boundingRect() const { - m_nodeInstance->renderPixmapNextPaint(); + if (isValid()) { + return d->boundingRect; + } else { + return QRectF(); + } } bool NodeInstance::hasContent() const { - return m_nodeInstance->hasContent(); -} - -bool NodeInstance::isResizable() const -{ - return m_nodeInstance->isResizable(); -} - -bool NodeInstance::isMovable() const -{ - return m_nodeInstance->isMovable(); -} - -bool NodeInstance::isInPositioner() const -{ - return m_nodeInstance->isInPositioner(); -} - -bool NodeInstance::hasAnchor(const QString &name) const -{ - return m_nodeInstance->hasAnchor(name); -} - -int NodeInstance::penWidth() const -{ - return m_nodeInstance->penWidth(); + if (isValid()) { + return d->hasContent; + } else { + return false; + } } bool NodeInstance::isAnchoredBySibling() const { - return m_nodeInstance->isAnchoredBySibling(); + if (isValid()) { + return d->isAnchoredBySibling; + } else { + return false; + } } bool NodeInstance::isAnchoredByChildren() const { - return m_nodeInstance->isAnchoredByChildren(); -} - -QPair<QString, NodeInstance> NodeInstance::anchor(const QString &name) const -{ - return m_nodeInstance->anchor(name); -} - -uint qHash(const NodeInstance &instance) -{ - return ::qHash(instance.m_nodeInstance.data()); -} - -bool operator==(const NodeInstance &first, const NodeInstance &second) -{ - return first.m_nodeInstance.data() == second.m_nodeInstance.data(); -} - -bool NodeInstance::isWrappingThisObject(QObject *object) const -{ - return internalObject() && internalObject() == object; + if (isValid()) { + return d->isAnchoredByChildren; + } else { + return false; + } } -/*! -\brief Returns the position in parent coordiantes. -\returns QPointF of the position of the instance. -*/ -QPointF NodeInstance::position() const +bool NodeInstance::isMovable() const { - return m_nodeInstance->position(); + if (isValid()) { + return d->isMovable; + } else { + return false; + } } -/*! -\brief Returns the size in local coordiantes. -\returns QSizeF of the size of the instance. -*/ -QSizeF NodeInstance::size() const +bool NodeInstance::isResizable() const { - QSizeF instanceSize = m_nodeInstance->size(); - -// if (nodeState().isValid()) { -// if (qFuzzyIsNull(instanceSize.width())) -// instanceSize.setWidth(nodeState().property("width").value().toDouble()); -// -// if (qFuzzyIsNull(instanceSize.height())) -// instanceSize.setHeight(nodeState().property("height").value().toDouble()); -// } - return instanceSize; + if (isValid()) { + return d->isResizable; + } else { + return false; + } } QTransform NodeInstance::transform() const { - return m_nodeInstance->transform(); -} - -/*! -\brief Returns the transform matrix of the instance. -\returns QTransform of the instance. -*/ -QTransform NodeInstance::customTransform() const -{ - return m_nodeInstance->customTransform(); + if (isValid()) { + return d->transform; + } else { + return QTransform(); + } } - QTransform NodeInstance::sceneTransform() const { - return m_nodeInstance->sceneTransform(); + if (isValid()) { + return d->sceneTransform; + } else { + return QTransform(); + } } - -double NodeInstance::rotation() const +bool NodeInstance::isInPositioner() const { - return m_nodeInstance->rotation(); + if (isValid()) { + return d->isInPositioner; + } else { + return false; + } } -double NodeInstance::scale() const +QPointF NodeInstance::position() const { - return m_nodeInstance->scale(); + if (isValid()) { + return d->position; + } else { + return QPointF(); + } } -QList<QGraphicsTransform *> NodeInstance::transformations() const +QSizeF NodeInstance::size() const { - return m_nodeInstance->transformations(); + if (isValid()) { + return d->size; + } else { + return QSizeF(); + } } -QPointF NodeInstance::transformOriginPoint() const +int NodeInstance::penWidth() const { - return m_nodeInstance->transformOriginPoint(); + if (isValid()) { + return d->penWidth; + } else { + return 1; + } } -double NodeInstance::zValue() const +void NodeInstance::paint(QPainter *painter) { - return m_nodeInstance->zValue(); + if (isValid() && !d->renderImage.isNull()) + painter->drawImage(boundingRect().topLeft(), d->renderImage); } -/*! -\brief Returns the opacity of the instance. -\returns 0.0 mean transparent and 1.0 opaque. -*/ -double NodeInstance::opacity() const +QVariant NodeInstance::property(const QString &name) const { - return m_nodeInstance->opacity(); -} + if (isValid()) + return d->propertyValues.value(name); - -void NodeInstance::setDeleteHeldInstance(bool deleteInstance) -{ - m_nodeInstance->setDeleteHeldInstance(deleteInstance); + return QVariant(); } - -void NodeInstance::paintUpdate() +bool NodeInstance::hasBindingForProperty(const QString &name) const { - m_nodeInstance->paintUpdate(); -} + if (isValid()) + return d->hasBindingForProperty.value(name, false); - -Internal::QmlGraphicsItemNodeInstance::Pointer NodeInstance::qmlGraphicsItemNodeInstance() const -{ - return m_nodeInstance.dynamicCast<Internal::QmlGraphicsItemNodeInstance>(); + return false; } -QObject *NodeInstance::internalObject() const +QString NodeInstance::instanceType(const QString &name) const { - if (m_nodeInstance.isNull()) - return 0; + if (isValid()) + return d->instanceTypes.value(name); - return m_nodeInstance->object(); + return QString(); } -void NodeInstance::activateState() +qint32 NodeInstance::parentId() const { - m_nodeInstance->activateState(); -} - -void NodeInstance::deactivateState() -{ - m_nodeInstance->deactivateState(); + if (isValid()) { + return d->parentInstanceId; + } else { + return false; + } } -bool NodeInstance::updateStateVariant(const NodeInstance &target, const QString &propertyName, const QVariant &value) +bool NodeInstance::hasAnchor(const QString &name) const { - return m_nodeInstance->updateStateVariant(target, propertyName, value); -} + if (isValid()) + return d->hasAnchors.value(name, false); -bool NodeInstance::updateStateBinding(const NodeInstance &target, const QString &propertyName, const QString &expression) -{ - return m_nodeInstance->updateStateBinding(target, propertyName, expression); + return false; } -QVariant NodeInstance::resetVariant(const QString &propertyName) const +QPair<QString, qint32> NodeInstance::anchor(const QString &name) const { - return m_nodeInstance->resetValue(propertyName); -} + if (isValid()) + return d->anchors.value(name, QPair<QString, qint32>(QString(), qint32(-1))); -bool NodeInstance::resetStateProperty(const NodeInstance &target, const QString &propertyName, const QVariant &resetValue) -{ - return m_nodeInstance->resetStateProperty(target, propertyName, resetValue); + return QPair<QString, qint32>(QString(), -1); } -/*! - Makes types used in node instances known to the Qml engine. To be called once at initialization time. -*/ -void NodeInstance::registerDeclarativeTypes() +void NodeInstance::setProperty(const QString &name, const QVariant &value) { -// qmlRegisterType<QmlDesigner::Internal::QmlPropertyChangesObject>(); + d->propertyValues.insert(name, value); } -void NodeInstance::doComponentComplete() +void NodeInstance::setRenderImage(const QImage &image) { - m_nodeInstance->doComponentComplete(); + d->renderImage = image; } -QString NodeInstance::id() const +void NodeInstance::setInformation(InformationName name, const QVariant &information, const QVariant &secondInformation, const QVariant &thirdInformation) { - return m_nodeInstance->id(); + switch (name) { + case Size: d->size = information.toSizeF(); break; + case BoundingRect: d->boundingRect = information.toRectF(); break; + case Transform: d->transform = information.value<QTransform>(); break; + case PenWidth: d->penWidth = information.toInt(); break; + case Position: d->position = information.toPointF(); break; + case IsInPositioner: d->isInPositioner = information.toBool(); break; + case SceneTransform: d->sceneTransform = information.value<QTransform>(); break; + case IsResizable: d->isResizable = information.toBool(); break; + case IsMovable: d->isMovable = information.toBool(); break; + case IsAnchoredByChildren: d->isAnchoredByChildren = information.toBool(); break; + case IsAnchoredBySibling: d->isAnchoredBySibling = information.toBool(); break; + case HasContent: d->hasContent = information.toBool(); break; + case HasAnchor: d->hasAnchors.insert(information.toString(), secondInformation.toBool());break; + case Anchor: d->anchors.insert(information.toString(), qMakePair(secondInformation.toString(), thirdInformation.value<qint32>())); break; + case InstanceTypeForProperty: d->instanceTypes.insert(information.toString(), secondInformation.toString()); break; + case HasBindingForProperty: d->hasBindingForProperty.insert(information.toString(), secondInformation.toBool()); break; + case Parent: d->parentInstanceId = information.toInt(); + case NoName: + default: break; + } } -#ifdef QTCREATOR_TEST -QObject* NodeInstance::testHandle() const -{ - return internalObject(); -} -Internal::ObjectNodeInstance* NodeInstance::internalInstance() const -{ - return m_nodeInstance.data(); } - -#endif - -} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceclientproxy.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceclientproxy.cpp new file mode 100644 index 0000000000..76717f27b4 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceclientproxy.cpp @@ -0,0 +1,156 @@ +#include "nodeinstanceclientproxy.h" + +#include <QLocalSocket> +#include <QVariant> +#include <QCoreApplication> +#include <QStringList> + +#include "nodeinstanceserver.h" + +#include "propertyabstractcontainer.h" +#include "propertyvaluecontainer.h" +#include "propertybindingcontainer.h" +#include "instancecontainer.h" +#include "createinstancescommand.h" +#include "createscenecommand.h" +#include "changevaluescommand.h" +#include "changebindingscommand.h" +#include "changefileurlcommand.h" +#include "removeinstancescommand.h" +#include "clearscenecommand.h" +#include "removepropertiescommand.h" +#include "reparentinstancescommand.h" +#include "changeidscommand.h" +#include "changestatecommand.h" + +#include "informationchangedcommand.h" +#include "pixmapchangedcommand.h" +#include "valueschangedcommand.h" + +namespace QmlDesigner { + +NodeInstanceClientProxy::NodeInstanceClientProxy(QObject *parent) + : QObject(parent), + m_nodeinstanceServer(new NodeInstanceServer(this)), + m_blockSize(0) +{ + m_socket = new QLocalSocket(this); + connect(m_socket, SIGNAL(readyRead()), this, SLOT(readDataStream())); + connect(m_socket, SIGNAL(error(QLocalSocket::LocalSocketError)), QCoreApplication::instance(), SLOT(quit())); + connect(m_socket, SIGNAL(disconnected()), QCoreApplication::instance(), SLOT(quit())); + m_socket->connectToServer(QCoreApplication::arguments().at(1), QIODevice::ReadWrite | QIODevice::Unbuffered); + m_socket->waitForConnected(-1); +} + +void NodeInstanceClientProxy::writeCommand(const QVariant &command) +{ + QByteArray block; + QDataStream out(&block, QIODevice::WriteOnly); + out << quint32(0); + out << command; + out.device()->seek(0); + out << quint32(block.size() - sizeof(quint32)); + + m_socket->write(block); +} + +void NodeInstanceClientProxy::informationChanged(const InformationChangedCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceClientProxy::valuesChanged(const ValuesChangedCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceClientProxy::pixmapChanged(const PixmapChangedCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceClientProxy::flush() +{ +} + +qint64 NodeInstanceClientProxy::bytesToWrite() const +{ + return m_socket->bytesToWrite(); +} + +void NodeInstanceClientProxy::readDataStream() +{ + QList<QVariant> commandList; + + while (!m_socket->atEnd()) { + if (m_socket->bytesAvailable() < int(sizeof(quint32))) + break; + + QDataStream in(m_socket); + + if (m_blockSize == 0) { + in >> m_blockSize; + } + + if (m_socket->bytesAvailable() < m_blockSize) + break; + + QVariant command; + in >> command; + m_blockSize = 0; + + Q_ASSERT(in.status() == QDataStream::Ok); + + commandList.append(command); + } + + foreach (const QVariant &command, commandList) { + dispatchCommand(command); + } +} + +NodeInstanceServerInterface *NodeInstanceClientProxy::nodeInstanceServer() const +{ + return m_nodeinstanceServer; +} + +void NodeInstanceClientProxy::dispatchCommand(const QVariant &command) +{ + static const int createInstancesCommandType = QMetaType::type("CreateInstancesCommand"); + static const int changeFileUrlCommandType = QMetaType::type("ChangeFileUrlCommand"); + static const int createSceneCommandType = QMetaType::type("CreateSceneCommand"); + static const int clearSceneCommandType = QMetaType::type("ClearSceneCommand"); + static const int removeInstancesCommandType = QMetaType::type("RemoveInstancesCommand"); + static const int removePropertiesCommandType = QMetaType::type("RemovePropertiesCommand"); + static const int changeBindingsCommandType = QMetaType::type("ChangeBindingsCommand"); + static const int changeValuesCommandType = QMetaType::type("ChangeValuesCommand"); + static const int reparentInstancesCommandType = QMetaType::type("ReparentInstancesCommand"); + static const int changeIdsCommandType = QMetaType::type("ChangeIdsCommand"); + static const int changeStateCommandType = QMetaType::type("ChangeStateCommand"); + + if (command.userType() == createInstancesCommandType) + nodeInstanceServer()->createInstances(command.value<CreateInstancesCommand>()); + else if (command.userType() == changeFileUrlCommandType) + nodeInstanceServer()->changeFileUrl(command.value<ChangeFileUrlCommand>()); + else if (command.userType() == createSceneCommandType) + nodeInstanceServer()->createScene(command.value<CreateSceneCommand>()); + else if (command.userType() == clearSceneCommandType) + nodeInstanceServer()->clearScene(command.value<ClearSceneCommand>()); + else if (command.userType() == removeInstancesCommandType) + nodeInstanceServer()->removeInstances(command.value<RemoveInstancesCommand>()); + else if (command.userType() == removePropertiesCommandType) + nodeInstanceServer()->removeProperties(command.value<RemovePropertiesCommand>()); + else if (command.userType() == changeBindingsCommandType) + nodeInstanceServer()->changePropertyBindings(command.value<ChangeBindingsCommand>()); + else if (command.userType() == changeValuesCommandType) + nodeInstanceServer()->changePropertyValues(command.value<ChangeValuesCommand>()); + else if (command.userType() == reparentInstancesCommandType) + nodeInstanceServer()->reparentInstances(command.value<ReparentInstancesCommand>()); + else if (command.userType() == changeIdsCommandType) + nodeInstanceServer()->changeIds(command.value<ChangeIdsCommand>()); + else if (command.userType() == changeStateCommandType) + nodeInstanceServer()->changeState(command.value<ChangeStateCommand>()); + else + Q_ASSERT(false); +} +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceclientproxy.h b/src/plugins/qmldesigner/designercore/instances/nodeinstanceclientproxy.h new file mode 100644 index 0000000000..dfc05d60e2 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceclientproxy.h @@ -0,0 +1,45 @@ +#ifndef NODEINSTANCECLIENTPROXY_H +#define NODEINSTANCECLIENTPROXY_H + +#include "nodeinstanceclientinterface.h" + +#include <QObject> + +QT_BEGIN_NAMESPACE +class QLocalSocket; +QT_END_NAMESPACE + +namespace QmlDesigner { + +class NodeInstanceServerInterface; + +class NodeInstanceClientProxy : public QObject, public NodeInstanceClientInterface +{ + Q_OBJECT + +public: + NodeInstanceClientProxy(QObject *parent = 0); + + void informationChanged(const InformationChangedCommand &command); + void valuesChanged(const ValuesChangedCommand &command); + void pixmapChanged(const PixmapChangedCommand &command); + void flush(); + qint64 bytesToWrite() const; + +protected: + void writeCommand(const QVariant &command); + void dispatchCommand(const QVariant &command); + NodeInstanceServerInterface *nodeInstanceServer() const; + +private slots: + void readDataStream(); + +private: + QLocalSocket *m_socket; + NodeInstanceServerInterface *m_nodeinstanceServer; + quint32 m_blockSize; +}; + +} // namespace QmlDesigner + +#endif // NODEINSTANCECLIENTPROXY_H diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstancemetaobject.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstancemetaobject.cpp index 6d0a53514e..c2cb706e97 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstancemetaobject.cpp +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstancemetaobject.cpp @@ -11,7 +11,7 @@ namespace Internal { NodeInstanceMetaObject::NodeInstanceMetaObject(const ObjectNodeInstance::Pointer &nodeInstance, QDeclarativeEngine *engine) : QDeclarativeOpenMetaObject(nodeInstance->object(), new QDeclarativeOpenMetaObjectType(nodeInstance->object()->metaObject(), engine)), m_nodeInstance(nodeInstance), - m_context(nodeInstance->modelNode().isRootNode() ? nodeInstance->context() : 0) + m_context(nodeInstance->isRootNodeInstance() ? nodeInstance->context() : 0) { setCached(true); } @@ -59,55 +59,29 @@ int NodeInstanceMetaObject::metaCall(QMetaObject::Call call, int id, void **a) oldValue = property(id).read(m_nodeInstance->object()); } - if (( call == QMetaObject::ReadProperty || call == QMetaObject::WriteProperty) - && id >= type()->propertyOffset()) { - int propId = id - type()->propertyOffset(); - if (call == QMetaObject::ReadProperty) { - propertyRead(propId); - *reinterpret_cast<QVariant *>(a[0]) = value(propId); - } else if (call == QMetaObject::WriteProperty) { - if (value(propId) != *reinterpret_cast<QVariant *>(a[0])) { - propertyWrite(propId); - setValue(propId, *reinterpret_cast<QVariant *>(a[0])); - dynamicPropertyWritten(propId); - notifyPropertyChange(id); - activate(object(), type()->signalOffset() + propId, 0); - } - } - } else { - if (!QObjectPrivate::get(object())->wasDeleted) { - if (parent()) - metaCallReturnValue = parent()->metaCall(call, id, a); - else - metaCallReturnValue = object()->qt_metacall(call, id, a); - } + if (parent() && id < parent()->propertyOffset()) + metaCallReturnValue = parent()->metaCall(call, id, a); + else + metaCallReturnValue = QDeclarativeOpenMetaObject::metaCall(call, id, a); - if (call == QMetaObject::WriteProperty + if (metaCallReturnValue >= 0 + && call == QMetaObject::WriteProperty && !property(id).hasNotifySignal() && oldValue != property(id).read(m_nodeInstance->object())) - notifyPropertyChange(id); - } + notifyPropertyChange(id); return metaCallReturnValue; - -} - -void NodeInstanceMetaObject::dynamicPropertyWritten(int propertyId) -{ - - if (m_context) - m_context->setContextProperty(name(propertyId), value(propertyId)); } void NodeInstanceMetaObject::notifyPropertyChange(int id) { ObjectNodeInstance::Pointer objectNodeInstance = m_nodeInstance.toStrongRef(); - if (objectNodeInstance && objectNodeInstance->nodeInstanceView()) { + if (objectNodeInstance && objectNodeInstance->nodeInstanceServer()) { if (id < type()->propertyOffset()) { - objectNodeInstance->nodeInstanceView()->notifyPropertyChange(objectNodeInstance->modelNode(), m_prefix + property(id).name()); + objectNodeInstance->nodeInstanceServer()->notifyPropertyChange(objectNodeInstance->instanceId(), m_prefix + property(id).name()); } else { - objectNodeInstance->nodeInstanceView()->notifyPropertyChange(objectNodeInstance->modelNode(), m_prefix + name(id - type()->propertyOffset())); + objectNodeInstance->nodeInstanceServer()->notifyPropertyChange(objectNodeInstance->instanceId(), m_prefix + name(id - type()->propertyOffset())); } } } diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstancemetaobject.h b/src/plugins/qmldesigner/designercore/instances/nodeinstancemetaobject.h index 795c517189..7307cc45b2 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstancemetaobject.h +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstancemetaobject.h @@ -20,7 +20,6 @@ public: protected: int metaCall(QMetaObject::Call _c, int _id, void **_a); - void dynamicPropertyWritten(int); void notifyPropertyChange(int id); private: diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserver.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserver.cpp new file mode 100644 index 0000000000..9fcdc2b565 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserver.cpp @@ -0,0 +1,716 @@ +#include "nodeinstanceserver.h" + +#include <QGraphicsItem> +#include <private/qgraphicsitem_p.h> +#include <private/qgraphicsscene_p.h> +#include <QDeclarativeEngine> +#include <QDeclarativeView> +#include <QFileSystemWatcher> +#include <QUrl> +#include <QSet> +#include <QVariant> +#include <QMetaType> + +#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 <iostream> +#include <stdio.h> + + +namespace QmlDesigner { + +NodeInstanceServer::NodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient) : + NodeInstanceServerInterface(), + m_childrenChangeEventFilter(new Internal::ChildrenChangeEventFilter(this)), + m_nodeInstanceClient(nodeInstanceClient), + m_timer(0) +{ + connect(m_childrenChangeEventFilter.data(), SIGNAL(childrenChanged(QObject*)), this, SLOT(emitParentChanged(QObject*))); +} + +NodeInstanceServer::~NodeInstanceServer() +{ + delete m_declarativeView.data(); +} + +void NodeInstanceServer::createInstances(const CreateInstancesCommand &command) +{ + Q_ASSERT(m_declarativeView); + QList<ServerNodeInstance> instanceList; + foreach(const InstanceContainer &instanceContainer, command.instances()) { + ServerNodeInstance instance = ServerNodeInstance::create(this, instanceContainer); + insertInstanceRelationship(instance); + instanceList.append(instance); + instance.internalObject()->installEventFilter(childrenChangeEventFilter()); + if (instanceContainer.instanceId() == 0) { + m_rootNodeInstance = instance; + QGraphicsObject *rootGraphicsObject = qobject_cast<QGraphicsObject*>(instance.internalObject()); + if (rootGraphicsObject) { + m_declarativeView->scene()->addItem(rootGraphicsObject); + m_declarativeView->setSceneRect(rootGraphicsObject->boundingRect()); + } + + } + + instance.doComponentComplete(); + } + + nodeInstanceClient()->valuesChanged(createValuesChangedCommand(instanceList)); + nodeInstanceClient()->informationChanged(createAllInformationChangedCommand(instanceList, true)); + foreach(const ServerNodeInstance &instance, instanceList) + nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(instance)); + + startRenderTimer(); +} + +ServerNodeInstance NodeInstanceServer::instanceForId(qint32 id) const +{ + if (id < 0) + return ServerNodeInstance(); + + Q_ASSERT(m_idInstanceHash.contains(id)); + return m_idInstanceHash.value(id); +} + +bool NodeInstanceServer::hasInstanceForId(qint32 id) const +{ + if (id < 0) + return false; + + return m_idInstanceHash.contains(id); +} + +ServerNodeInstance NodeInstanceServer::instanceForObject(QObject *object) const +{ + Q_ASSERT(m_objectInstanceHash.contains(object)); + return m_objectInstanceHash.value(object); +} + +bool NodeInstanceServer::hasInstanceForObject(QObject *object) const +{ + if (object == 0) + return false; + + return m_objectInstanceHash.contains(object); +} + +void NodeInstanceServer::startRenderTimer() +{ + if (m_timer == 0) + m_timer = startTimer(16); +} + +void NodeInstanceServer::stopRenderTimer() +{ + if (m_timer) { + killTimer(m_timer); + m_timer = 0; + } +} + +void NodeInstanceServer::createScene(const CreateSceneCommand &/*command*/) +{ + Q_ASSERT(!m_declarativeView); + m_declarativeView = new QDeclarativeView; + m_declarativeView->setAttribute(Qt::WA_DontShowOnScreen, true); + m_declarativeView->setViewportUpdateMode(QGraphicsView::NoViewportUpdate); + m_declarativeView->viewport()->setUpdatesEnabled(false); + m_declarativeView->show(); + + if (!m_fileUrl.isEmpty()) + engine()->setBaseUrl(m_fileUrl); + + static_cast<QGraphicsScenePrivate*>(QObjectPrivate::get(m_declarativeView->scene()))->processDirtyItemsEmitted = true; + + startRenderTimer(); +} + +void NodeInstanceServer::clearScene(const ClearSceneCommand &/*command*/) +{ + stopRenderTimer(); + + removeAllInstanceRelationships(); + m_fileSystemWatcherHash.clear(); + m_rootNodeInstance.makeInvalid(); + m_changedPropertyList.clear(); + m_fileUrl.clear(); + + delete m_declarativeView.data(); +} + +void NodeInstanceServer::removeInstances(const RemoveInstancesCommand &command) +{ + foreach(qint32 instanceId, command.instanceIds()) { + removeInstanceRelationsip(instanceId); + } + + startRenderTimer(); +} + +void NodeInstanceServer::removeProperties(const RemovePropertiesCommand &command) +{ + foreach(const PropertyAbstractContainer &container, command.properties()) + resetInstanceProperty(container); + + startRenderTimer(); +} + +void NodeInstanceServer::reparentInstances(const ReparentInstancesCommand &command) +{ + foreach(const ReparentContainer &container, command.reparentInstances()) { + ServerNodeInstance instance = instanceForId(container.instanceId()); + if (instance.isValid()) { + instance.reparent(instanceForId(container.oldParentInstanceId()), container.oldParentProperty(), instanceForId(container.newParentInstanceId()), container.newParentProperty()); + } + } + + startRenderTimer(); +} + +void NodeInstanceServer::changeState(const ChangeStateCommand &command) +{ + if (hasInstanceForId(command.stateInstanceId())) { + ServerNodeInstance instance = instanceForId(command.stateInstanceId()); + instance.activateState(); + } else { + if (activeStateInstance().isValid()) + activeStateInstance().deactivateState(); + } + + startRenderTimer(); +} + +void NodeInstanceServer::changeFileUrl(const ChangeFileUrlCommand &command) +{ + m_fileUrl = command.fileUrl(); + + if (engine()) + engine()->setBaseUrl(m_fileUrl); + + startRenderTimer(); +} + +void NodeInstanceServer::changePropertyValues(const ChangeValuesCommand &command) +{ + foreach(const PropertyValueContainer &container, command.valueChanges()) + setInstancePropertyVariant(container); + + startRenderTimer(); +} + + +void NodeInstanceServer::changePropertyBindings(const ChangeBindingsCommand &command) +{ + foreach(const PropertyBindingContainer &container, command.bindingChanges()) + setInstancePropertyBinding(container); + + startRenderTimer(); +} + +void NodeInstanceServer::changeIds(const ChangeIdsCommand &command) +{ + foreach(const IdContainer &container, command.ids()) { + if (hasInstanceForId(container.instanceId())) + instanceForId(container.instanceId()).setId(container.id()); + } + + startRenderTimer(); +} + +QDeclarativeEngine *NodeInstanceServer::engine() const +{ + if (m_declarativeView) + return m_declarativeView->engine(); + + return 0; +} + +void NodeInstanceServer::removeAllInstanceRelationships() +{ + // prevent destroyed() signals calling back + + foreach (ServerNodeInstance instance, m_objectInstanceHash.values()) { + if (instance.isValid()) + instance.setId(QString()); + } + + //first the root object + if (rootNodeInstance().internalObject()) + rootNodeInstance().internalObject()->disconnect(); + + rootNodeInstance().makeInvalid(); + + + foreach (ServerNodeInstance instance, m_objectInstanceHash.values()) { + if (instance.internalObject()) + instance.internalObject()->disconnect(); + instance.makeInvalid(); + } + + m_idInstanceHash.clear(); + m_objectInstanceHash.clear(); +} + + +QFileSystemWatcher *NodeInstanceServer::fileSystemWatcher() +{ + if (m_fileSystemWatcher.isNull()) { + m_fileSystemWatcher = new QFileSystemWatcher(this); + connect(m_fileSystemWatcher.data(), SIGNAL(fileChanged(QString)), this, SLOT(refreshLocalFileProperty(QString))); + } + + return m_fileSystemWatcher.data(); +} + +Internal::ChildrenChangeEventFilter *NodeInstanceServer::childrenChangeEventFilter() const +{ + return m_childrenChangeEventFilter.data(); +} + +void NodeInstanceServer::addFilePropertyToFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path) +{ + m_fileSystemWatcherHash.insert(path, ObjectPropertyPair(object, propertyName)); + fileSystemWatcher()->addPath(path); + +} + +void NodeInstanceServer::removeFilePropertyFromFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path) +{ + fileSystemWatcher()->removePath(path); + m_fileSystemWatcherHash.remove(path, ObjectPropertyPair(object, propertyName)); +} + +void NodeInstanceServer::refreshLocalFileProperty(const QString &path) +{ + if (m_fileSystemWatcherHash.contains(path)) { + QList<ObjectPropertyPair> objectPropertyPairList = m_fileSystemWatcherHash.values(); + foreach(const ObjectPropertyPair &objectPropertyPair, objectPropertyPairList) { + QObject *object = objectPropertyPair.first.data(); + QString propertyName = objectPropertyPair.second; + + if (hasInstanceForObject(object)) { + instanceForObject(object).refreshProperty(propertyName); + } + } + } +} + +void NodeInstanceServer::addChangedProperty(const InstancePropertyPair &property) +{ + if (!m_changedPropertyList.contains(property)) + m_changedPropertyList.append(property); +} + +void NodeInstanceServer::emitParentChanged(QObject *child) +{ + if (hasInstanceForObject(child)) { + addChangedProperty(InstancePropertyPair(instanceForObject(child), "parent")); + } +} + +Internal::ChildrenChangeEventFilter *NodeInstanceServer::childrenChangeEventFilter() +{ + if (m_childrenChangeEventFilter.isNull()) { + m_childrenChangeEventFilter = new Internal::ChildrenChangeEventFilter(this); + connect(m_childrenChangeEventFilter.data(), SIGNAL(childrenChanged(QObject*)), this, SLOT(emitParentChanged(QObject*))); + } + + return m_childrenChangeEventFilter.data(); +} + +void NodeInstanceServer::resetInstanceProperty(const PropertyAbstractContainer &propertyContainer) +{ + if (hasInstanceForId(propertyContainer.instanceId())) { // TODO ugly workaround + ServerNodeInstance instance = instanceForId(propertyContainer.instanceId()); + Q_ASSERT(instance.isValid()); + + const QString name = propertyContainer.name(); + + if (activeStateInstance().isValid() && !instance.isSubclassOf("Qt/PropertyChanges")) { + bool statePropertyWasReseted = activeStateInstance().resetStateProperty(instance, name, instance.resetVariant(name)); + if (!statePropertyWasReseted) + instance.resetProperty(name); + } else { + instance.resetProperty(name); + } + } +} + + +void NodeInstanceServer::setInstancePropertyBinding(const PropertyBindingContainer &bindingContainer) +{ + if (hasInstanceForId(bindingContainer.instanceId())) { + ServerNodeInstance instance = instanceForId(bindingContainer.instanceId()); + + const QString name = bindingContainer.name(); + const QString expression = bindingContainer.expression(); + + + if (activeStateInstance().isValid() && !instance.isSubclassOf("Qt/PropertyChanges")) { + bool stateBindingWasUpdated = activeStateInstance().updateStateBinding(instance, name, expression); + if (!stateBindingWasUpdated) { + if (bindingContainer.isDynamic()) + instance.setPropertyDynamicBinding(name, bindingContainer.dynamicTypeName(), expression); + else + instance.setPropertyBinding(name, expression); + } + } else { + if (bindingContainer.isDynamic()) + instance.setPropertyDynamicBinding(name, bindingContainer.dynamicTypeName(), expression); + else + instance.setPropertyBinding(name, expression); + } + } +} + + +void NodeInstanceServer::removeProperties(const QList<PropertyAbstractContainer> &propertyList) +{ + foreach (const PropertyAbstractContainer &property, propertyList) + resetInstanceProperty(property); +} + +void NodeInstanceServer::setInstancePropertyVariant(const PropertyValueContainer &valueContainer) +{ + if (hasInstanceForId(valueContainer.instanceId())) { + ServerNodeInstance instance = instanceForId(valueContainer.instanceId()); + + + const QString name = valueContainer.name(); + const QVariant value = valueContainer.value(); + + + if (activeStateInstance().isValid() && !instance.isSubclassOf("Qt/PropertyChanges")) { + bool stateValueWasUpdated = activeStateInstance().updateStateVariant(instance, name, value); + if (!stateValueWasUpdated) { + if (valueContainer.isDynamic()) + instance.setPropertyDynamicVariant(name, valueContainer.dynamicTypeName(), value); + else + instance.setPropertyVariant(name, value); + } + } else { //base state + if (valueContainer.isDynamic()) + instance.setPropertyDynamicVariant(name, valueContainer.dynamicTypeName(), value); + else + instance.setPropertyVariant(name, value); + } + +// instance.paintUpdate(); + } +} + + +QUrl NodeInstanceServer::fileUrl() const +{ + return m_fileUrl; +} + +ServerNodeInstance NodeInstanceServer::activeStateInstance() const +{ + return m_activeStateInstance; +} + +ServerNodeInstance NodeInstanceServer::rootNodeInstance() const +{ + return m_rootNodeInstance; +} + +void NodeInstanceServer::setStateInstance(const ServerNodeInstance &stateInstance) +{ + m_activeStateInstance = stateInstance; +} + +void NodeInstanceServer::clearStateInstance() +{ + m_activeStateInstance = ServerNodeInstance(); +} + +void NodeInstanceServer::timerEvent(QTimerEvent *event) +{ + if (event->timerId() == m_timer) { + findItemChangesAndSendChangeCommands(); + } + + NodeInstanceServerInterface::timerEvent(event); +} + +NodeInstanceClientInterface *NodeInstanceServer::nodeInstanceClient() const +{ + return m_nodeInstanceClient; +} + +InformationChangedCommand NodeInstanceServer::createAllInformationChangedCommand(const QList<ServerNodeInstance> &instanceList, bool initial) const +{ + QVector<InformationContainer> informationVector; + + foreach(const ServerNodeInstance &instance, instanceList) { + informationVector.append(InformationContainer(instance.instanceId(), Position, instance.position())); + informationVector.append(InformationContainer(instance.instanceId(), Transform, instance.transform())); + informationVector.append(InformationContainer(instance.instanceId(), SceneTransform, instance.sceneTransform())); + informationVector.append(InformationContainer(instance.instanceId(), Size, instance.size())); + informationVector.append(InformationContainer(instance.instanceId(), BoundingRect, instance.boundingRect())); + informationVector.append(InformationContainer(instance.instanceId(), Transform, instance.transform())); + informationVector.append(InformationContainer(instance.instanceId(), HasContent, instance.hasContent())); + informationVector.append(InformationContainer(instance.instanceId(), IsMovable, instance.isMovable())); + informationVector.append(InformationContainer(instance.instanceId(), IsResizable, instance.isResizable())); + informationVector.append(InformationContainer(instance.instanceId(), IsInPositioner, instance.isInPositioner())); + informationVector.append(InformationContainer(instance.instanceId(), PenWidth, instance.penWidth())); + informationVector.append(InformationContainer(instance.instanceId(), Parent, instance.parent().instanceId())); + informationVector.append(InformationContainer(instance.instanceId(), IsAnchoredByChildren, instance.isAnchoredByChildren())); + informationVector.append(InformationContainer(instance.instanceId(), IsAnchoredBySibling, instance.isAnchoredBySibling())); + + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.fill"), instance.hasAnchor("anchors.fill"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.centerIn"), instance.hasAnchor("anchors.centerIn"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.right"), instance.hasAnchor("anchors.right"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.top"), instance.hasAnchor("anchors.top"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.left"), instance.hasAnchor("anchors.left"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.bottom"), instance.hasAnchor("anchors.bottom"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.horizontalCenter"), instance.hasAnchor("anchors.horizontalCenter"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.verticalCenter"), instance.hasAnchor("anchors.verticalCenter"))); + informationVector.append(InformationContainer(instance.instanceId(), HasAnchor, QString("anchors.baseline"), instance.hasAnchor("anchors.baseline"))); + + QPair<QString, ServerNodeInstance> anchorPair = instance.anchor("anchors.fill"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.fill"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.centerIn"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.centerIn"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.right"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.right"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.top"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.top"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.left"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.left"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.bottom"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.bottom"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.horizontalCenter"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.horizontalCenter"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.verticalCenter"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.verticalCenter"), anchorPair.first, anchorPair.second.instanceId())); + + anchorPair = instance.anchor("anchors.baseline"); + informationVector.append(InformationContainer(instance.instanceId(), Anchor, QString("anchors.baseline"), anchorPair.first, anchorPair.second.instanceId())); + + QStringList propertyNames = instance.propertyNames(); + + if (initial) { + foreach (const QString &propertyName,propertyNames) + informationVector.append(InformationContainer(instance.instanceId(), InstanceTypeForProperty, propertyName, instance.instanceType(propertyName))); + } + + foreach (const QString &propertyName,instance.propertyNames()) { + bool hasChanged = false; + bool hasBinding = instance.hasBindingForProperty(propertyName, &hasChanged); + if (hasChanged) + informationVector.append(InformationContainer(instance.instanceId(), HasBindingForProperty, propertyName, hasBinding)); + } + + } + + return InformationChangedCommand(informationVector); +} + +ValuesChangedCommand NodeInstanceServer::createValuesChangedCommand(const QList<ServerNodeInstance> &instanceList) const +{ + QVector<PropertyValueContainer> valueVector; + + foreach(const ServerNodeInstance &instance, instanceList) { + foreach(const QString &propertyName, instance.propertyNames()) { + QVariant propertyValue = instance.property(propertyName); + if (propertyValue.type() < QVariant::UserType) + valueVector.append(PropertyValueContainer(instance.instanceId(), propertyName, propertyValue, QString())); + } + } + + return ValuesChangedCommand(valueVector); +} + +ValuesChangedCommand NodeInstanceServer::createValuesChangedCommand(const QVector<InstancePropertyPair> &propertyList) const +{ + QVector<PropertyValueContainer> valueVector; + + foreach (const InstancePropertyPair &property, propertyList) { + const QString propertyName = property.second; + const ServerNodeInstance instance = property.first; + + if( instance.isValid()) { + QVariant propertyValue = instance.property(propertyName); + if (propertyValue.type() < QVariant::UserType) + valueVector.append(PropertyValueContainer(instance.instanceId(), propertyName, propertyValue, QString())); + } + } + + return ValuesChangedCommand(valueVector); +} + +void NodeInstanceServer::notifyPropertyChange(qint32 instanceid, const QString &propertyName) +{ + if (hasInstanceForId(instanceid)) + addChangedProperty(InstancePropertyPair(instanceForId(instanceid), propertyName)); +} + +void NodeInstanceServer::insertInstanceRelationship(const ServerNodeInstance &instance) +{ + Q_ASSERT(instance.isValid()); + Q_ASSERT(!m_idInstanceHash.contains(instance.instanceId())); + Q_ASSERT(!m_objectInstanceHash.contains(instance.internalObject())); + m_objectInstanceHash.insert(instance.internalObject(), instance); + m_idInstanceHash.insert(instance.instanceId(), instance); +} + +void NodeInstanceServer::removeInstanceRelationsip(qint32 instanceId) +{ + if (hasInstanceForId(instanceId)) { + ServerNodeInstance instance = instanceForId(instanceId); + if (instance.isValid()) + instance.setId(QString()); + m_idInstanceHash.remove(instanceId); + m_objectInstanceHash.remove(instance.internalObject()); + instance.makeInvalid(); + } +} + +PixmapChangedCommand NodeInstanceServer::createPixmapChangedCommand(const ServerNodeInstance &instance) const +{ + return PixmapChangedCommand(instance.instanceId(), instance.renderImage()); +} + +bool NodeInstanceServer::nonInstanceChildIsDirty(QGraphicsObject *graphicsObject) const +{ + QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(graphicsObject); + if (d->dirtyChildren) { + foreach(QGraphicsItem *child, graphicsObject->childItems()) { + QGraphicsObject *childGraphicsObject = child->toGraphicsObject(); + if (hasInstanceForObject(childGraphicsObject)) + continue; + + QGraphicsItemPrivate *childPrivate = QGraphicsItemPrivate::get(child); + if (childPrivate->dirty || childPrivate->dirtyChildren || nonInstanceChildIsDirty(childGraphicsObject)) + return true; + } + } + + return false; +} + +void NodeInstanceServer::resetAllItems() +{ +// m_declarativeView->scene()->update(); +// m_declarativeView->viewport()->repaint(); + static_cast<QGraphicsScenePrivate*>(QObjectPrivate::get(m_declarativeView->scene()))->processDirtyItemsEmitted = true; + + foreach (QGraphicsItem *item, m_declarativeView->items()) + static_cast<QGraphicsScenePrivate*>(QObjectPrivate::get(m_declarativeView->scene()))->resetDirtyItem(item); +} + +void NodeInstanceServer::findItemChangesAndSendChangeCommands() +{ + static bool inFunction = false; + if (!inFunction && nodeInstanceClient()->bytesToWrite() < 100000) { + inFunction = true; + + QSet<ServerNodeInstance> dirtyInstanceSet; + 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->dirty && d->notifyBoundingRectChanged)|| (d->dirty && !d->dirtySceneTransform) || nonInstanceChildIsDirty(graphicsObject)) + dirtyInstanceSet.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.isRootNodeInstance() && (propertyName == "width" || propertyName == "height")) + adjustSceneRect = true; + + if (propertyName.contains("anchors") && informationChangedInstanceSet.contains(instance)) + informationChangedInstanceSet.insert(instance); + + if (propertyName == "width" || propertyName == "height") + dirtyInstanceSet.insert(instance); + + if (propertyName == "parent") { + informationChangedInstanceSet.insert(instance); + } else { + propertyChangedList.append(property); + } + } + + m_changedPropertyList.clear(); + resetAllItems(); + + if (!informationChangedInstanceSet.isEmpty()) + nodeInstanceClient()->informationChanged(createAllInformationChangedCommand(informationChangedInstanceSet.toList())); + + if (!propertyChangedList.isEmpty()) + nodeInstanceClient()->valuesChanged(createValuesChangedCommand(propertyChangedList)); + + foreach(const ServerNodeInstance &instance, dirtyInstanceSet) + nodeInstanceClient()->pixmapChanged(createPixmapChangedCommand(instance)); + + if (adjustSceneRect) { + QRectF boundingRect = m_rootNodeInstance.boundingRect(); + if (boundingRect.isValid()) { + m_declarativeView->setSceneRect(boundingRect); + } + } + + stopRenderTimer(); + nodeInstanceClient()->flush(); + } + + inFunction = false; + } + +} +} + + + diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserver.h b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserver.h new file mode 100644 index 0000000000..3b03d8ec7d --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserver.h @@ -0,0 +1,125 @@ +#ifndef NODEINSTANCESERVER_H +#define NODEINSTANCESERVER_H + +#include <QUrl> +#include <QVector> + +#include <nodeinstanceserverinterface.h> +#include "servernodeinstance.h" + +QT_BEGIN_NAMESPACE +class QFileSystemWatcher; +class QDeclarativeView; +class QDeclarativeEngine; +class QGraphicsObject; +QT_END_NAMESPACE + +namespace QmlDesigner { + +class NodeInstanceClientInterface; +class ValuesChangedCommand; +class PixmapChangedCommand; +class InformationChangedCommand; + +namespace Internal { + class ChildrenChangeEventFilter; +} + +class NodeInstanceServer : public NodeInstanceServerInterface +{ + Q_OBJECT +public: + typedef QPair<QWeakPointer<QObject>, QString> ObjectPropertyPair; + typedef QPair<qint32, QString> IdPropertyPair; + typedef QPair<ServerNodeInstance, QString> InstancePropertyPair; + explicit NodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient); + ~NodeInstanceServer(); + + void createInstances(const CreateInstancesCommand &command); + void changeFileUrl(const ChangeFileUrlCommand &command); + void changePropertyValues(const ChangeValuesCommand &command); + void changePropertyBindings(const ChangeBindingsCommand &command); + void changeIds(const ChangeIdsCommand &command); + void createScene(const CreateSceneCommand &command); + void clearScene(const ClearSceneCommand &command); + void removeInstances(const RemoveInstancesCommand &command); + void removeProperties(const RemovePropertiesCommand &command); + void reparentInstances(const ReparentInstancesCommand &command); + void changeState(const ChangeStateCommand &command); + + + ServerNodeInstance instanceForId(qint32 id) const; + bool hasInstanceForId(qint32 id) const; + + ServerNodeInstance instanceForObject(QObject *object) const; + bool hasInstanceForObject(QObject *object) const; + + QDeclarativeEngine *engine() const; + + void removeAllInstanceRelationships(); + + QFileSystemWatcher *fileSystemWatcher(); + Internal::ChildrenChangeEventFilter *childrenChangeEventFilter() const; + void addFilePropertyToFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path); + void removeFilePropertyFromFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path); + + QUrl fileUrl() const; + + ServerNodeInstance activeStateInstance() const; + void setStateInstance(const ServerNodeInstance &stateInstance); + void clearStateInstance(); + + ServerNodeInstance rootNodeInstance() const; + + void notifyPropertyChange(qint32 instanceid, const QString &propertyName); + +public slots: + void refreshLocalFileProperty(const QString &path); + void emitParentChanged(QObject *child); + +protected: + Internal::ChildrenChangeEventFilter *childrenChangeEventFilter(); + void resetInstanceProperty(const PropertyAbstractContainer &propertyContainer); + void setInstancePropertyBinding(const PropertyBindingContainer &bindingContainer); + void setInstancePropertyVariant(const PropertyValueContainer &valueContainer); + void removeProperties(const QList<PropertyAbstractContainer> &propertyList); + + void insertInstanceRelationship(const ServerNodeInstance &instance); + void removeInstanceRelationsip(qint32 instanceId); + + NodeInstanceClientInterface *nodeInstanceClient() const; + + void timerEvent(QTimerEvent *); + + bool nonInstanceChildIsDirty(QGraphicsObject *graphicsObject) const; + void findItemChangesAndSendChangeCommands(); + void resetAllItems(); + + ValuesChangedCommand createValuesChangedCommand(const QList<ServerNodeInstance> &instanceList) const; + ValuesChangedCommand createValuesChangedCommand(const QVector<InstancePropertyPair> &propertyList) const; + PixmapChangedCommand createPixmapChangedCommand(const ServerNodeInstance &instance) const; + InformationChangedCommand createAllInformationChangedCommand(const QList<ServerNodeInstance> &instanceList, bool initial = false) const; + + void addChangedProperty(const InstancePropertyPair &property); + + void startRenderTimer(); + void stopRenderTimer(); + +private: + ServerNodeInstance m_rootNodeInstance; + ServerNodeInstance m_activeStateInstance; + QHash<qint32, ServerNodeInstance> m_idInstanceHash; + QHash<QObject*, ServerNodeInstance> m_objectInstanceHash; + QMultiHash<QString, ObjectPropertyPair> m_fileSystemWatcherHash; + QWeakPointer<QFileSystemWatcher> m_fileSystemWatcher; + QWeakPointer<QDeclarativeView> m_declarativeView; + QWeakPointer<Internal::ChildrenChangeEventFilter> m_childrenChangeEventFilter; + QUrl m_fileUrl; + NodeInstanceClientInterface *m_nodeInstanceClient; + int m_timer; + QVector<InstancePropertyPair> m_changedPropertyList; +}; + +} + +#endif // NODEINSTANCESERVER_H diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverinterface.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverinterface.cpp new file mode 100644 index 0000000000..f3fcee3b67 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverinterface.cpp @@ -0,0 +1,106 @@ +#include "nodeinstanceserverinterface.h" +#include <qmetatype.h> + +#include "propertyabstractcontainer.h" +#include "propertyvaluecontainer.h" +#include "propertybindingcontainer.h" +#include "instancecontainer.h" +#include "createinstancescommand.h" +#include "createscenecommand.h" +#include "changevaluescommand.h" +#include "changebindingscommand.h" +#include "changefileurlcommand.h" +#include "removeinstancescommand.h" +#include "clearscenecommand.h" +#include "removepropertiescommand.h" +#include "reparentinstancescommand.h" +#include "changeidscommand.h" +#include "changestatecommand.h" + +#include "informationchangedcommand.h" +#include "pixmapchangedcommand.h" +#include "valueschangedcommand.h" + + +namespace QmlDesigner { + +static bool isRegistered=false; + +NodeInstanceServerInterface::NodeInstanceServerInterface(QObject *parent) : + QObject(parent) +{ + registerCommands(); +} + +void NodeInstanceServerInterface::registerCommands() +{ + if (isRegistered) + return; + + isRegistered = true; + + qRegisterMetaType<CreateInstancesCommand>("CreateInstancesCommand"); + qRegisterMetaTypeStreamOperators<CreateInstancesCommand>("CreateInstancesCommand"); + + qRegisterMetaType<ClearSceneCommand>("ClearSceneCommand"); + qRegisterMetaTypeStreamOperators<ClearSceneCommand>("ClearSceneCommand"); + + qRegisterMetaType<CreateSceneCommand>("CreateSceneCommand"); + qRegisterMetaTypeStreamOperators<CreateSceneCommand>("CreateSceneCommand"); + + qRegisterMetaType<ChangeBindingsCommand>("ChangeBindingsCommand"); + qRegisterMetaTypeStreamOperators<ChangeBindingsCommand>("ChangeBindingsCommand"); + + qRegisterMetaType<ChangeValuesCommand>("ChangeValuesCommand"); + qRegisterMetaTypeStreamOperators<ChangeValuesCommand>("ChangeValuesCommand"); + + qRegisterMetaType<ChangeFileUrlCommand>("ChangeFileUrlCommand"); + qRegisterMetaTypeStreamOperators<ChangeFileUrlCommand>("ChangeFileUrlCommand"); + + qRegisterMetaType<ChangeStateCommand>("ChangeStateCommand"); + qRegisterMetaTypeStreamOperators<PropertyAbstractContainer>("ChangeStateCommand"); + + qRegisterMetaType<RemoveInstancesCommand>("RemoveInstancesCommand"); + qRegisterMetaTypeStreamOperators<RemoveInstancesCommand>("RemoveInstancesCommand"); + + qRegisterMetaType<RemovePropertiesCommand>("RemovePropertiesCommand"); + qRegisterMetaTypeStreamOperators<RemovePropertiesCommand>("RemovePropertiesCommand"); + + qRegisterMetaType<ReparentInstancesCommand>("ReparentInstancesCommand"); + qRegisterMetaTypeStreamOperators<ReparentInstancesCommand>("ReparentInstancesCommand"); + + qRegisterMetaType<ChangeIdsCommand>("ChangeIdsCommand"); + qRegisterMetaTypeStreamOperators<ChangeIdsCommand>("ChangeIdsCommand"); + + qRegisterMetaType<ChangeStateCommand>("ChangeStateCommand"); + qRegisterMetaTypeStreamOperators<ChangeStateCommand>("ChangeStateCommand"); + + qRegisterMetaType<InformationChangedCommand>("InformationChangedCommand"); + qRegisterMetaTypeStreamOperators<InformationChangedCommand>("InformationChangedCommand"); + + qRegisterMetaType<ValuesChangedCommand>("ValuesChangedCommand"); + qRegisterMetaTypeStreamOperators<ValuesChangedCommand>("ValuesChangedCommand"); + + qRegisterMetaType<PixmapChangedCommand>("PixmapChangedCommand"); + qRegisterMetaTypeStreamOperators<PixmapChangedCommand>("PixmapChangedCommand"); + + qRegisterMetaType<InformationContainer>("InformationContainer"); + qRegisterMetaTypeStreamOperators<InformationContainer>("InformationContainer"); + + qRegisterMetaType<PropertyValueContainer>("PropertyValueContainer"); + qRegisterMetaTypeStreamOperators<PropertyValueContainer>("PropertyValueContainer"); + + qRegisterMetaType<PropertyBindingContainer>("PropertyBindingContainer"); + qRegisterMetaTypeStreamOperators<PropertyBindingContainer>("PropertyBindingContainer"); + + qRegisterMetaType<PropertyAbstractContainer>("PropertyAbstractContainer"); + qRegisterMetaTypeStreamOperators<PropertyAbstractContainer>("PropertyAbstractContainer"); + + qRegisterMetaType<InstanceContainer>("InstanceContainer"); + qRegisterMetaTypeStreamOperators<InstanceContainer>("InstanceContainer"); + + qRegisterMetaType<IdContainer>("IdContainer"); + qRegisterMetaTypeStreamOperators<IdContainer>("IdContainer"); +} + +} diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.cpp new file mode 100644 index 0000000000..7dda600535 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.cpp @@ -0,0 +1,202 @@ +#include "nodeinstanceserverproxy.h" + +#include <QLocalServer> +#include <QLocalSocket> +#include <QProcess> +#include <QCoreApplication> +#include <QUuid> + +#include "propertyabstractcontainer.h" +#include "propertyvaluecontainer.h" +#include "propertybindingcontainer.h" +#include "instancecontainer.h" +#include "createinstancescommand.h" +#include "createscenecommand.h" +#include "changevaluescommand.h" +#include "changebindingscommand.h" +#include "changefileurlcommand.h" +#include "removeinstancescommand.h" +#include "clearscenecommand.h" +#include "removepropertiescommand.h" +#include "reparentinstancescommand.h" +#include "changeidscommand.h" +#include "changestatecommand.h" + +#include "informationchangedcommand.h" +#include "pixmapchangedcommand.h" +#include "valueschangedcommand.h" + +#include "nodeinstanceview.h" +#include "nodeinstanceclientproxy.h" + +namespace QmlDesigner { + +NodeInstanceServerProxy::NodeInstanceServerProxy(NodeInstanceView *nodeInstanceView) + : NodeInstanceServerInterface(nodeInstanceView), + m_localServer(new QLocalServer(this)), + m_nodeInstanceView(nodeInstanceView), + m_blockSize(0) +{ + QString socketToken(QUuid::createUuid().toString()); + + m_localServer->listen(socketToken); + m_localServer->setMaxPendingConnections(1); + + m_qmlPuppetProcess = new QProcess(QCoreApplication::instance()); + connect(m_qmlPuppetProcess.data(), SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished(int,QProcess::ExitStatus))); + m_qmlPuppetProcess->setProcessChannelMode(QProcess::ForwardedChannels); + m_qmlPuppetProcess->start(QString("%1/%2").arg(QCoreApplication::applicationDirPath()).arg("qmlpuppet"), QStringList() << socketToken); + connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(deleteLater())); + m_qmlPuppetProcess->waitForStarted(); + Q_ASSERT(m_qmlPuppetProcess->state() == QProcess::Running); + + if (!m_localServer->hasPendingConnections()) + m_localServer->waitForNewConnection(-1); + + m_socket = m_localServer->nextPendingConnection(); + Q_ASSERT(m_socket); + connect(m_socket.data(), SIGNAL(readyRead()), this, SLOT(readDataStream())); + m_localServer->close(); +} + +NodeInstanceServerProxy::~NodeInstanceServerProxy() +{ + if (m_qmlPuppetProcess) { + m_qmlPuppetProcess->blockSignals(true); + m_qmlPuppetProcess->terminate(); + } +} + +void NodeInstanceServerProxy::dispatchCommand(const QVariant &command) +{ + static const int informationChangedCommandType = QMetaType::type("InformationChangedCommand"); + static const int valuesChangedCommandType = QMetaType::type("ValuesChangedCommand"); + static const int pixmapChangedCommandType = QMetaType::type("PixmapChangedCommand"); + + if (command.userType() == informationChangedCommandType) + nodeInstanceClient()->informationChanged(command.value<InformationChangedCommand>()); + else if (command.userType() == valuesChangedCommandType) + nodeInstanceClient()->valuesChanged(command.value<ValuesChangedCommand>()); + else if (command.userType() == pixmapChangedCommandType) + nodeInstanceClient()->pixmapChanged(command.value<PixmapChangedCommand>()); + else + Q_ASSERT(false); +} + +NodeInstanceClientInterface *NodeInstanceServerProxy::nodeInstanceClient() const +{ + return m_nodeInstanceView.data(); +} + +void NodeInstanceServerProxy::setBlockUpdates(bool block) +{ + m_socket->blockSignals(block); +} + +void NodeInstanceServerProxy::writeCommand(const QVariant &command) +{ + Q_ASSERT(m_socket.data()); + + QByteArray block; + QDataStream out(&block, QIODevice::WriteOnly); + out << quint32(0); + out << command; + out.device()->seek(0); + out << quint32(block.size() - sizeof(quint32)); + + m_socket->write(block); +} + +void NodeInstanceServerProxy::processFinished(int /*exitCode*/, QProcess::ExitStatus /* exitStatus */) +{ + m_socket->close(); + emit processCrashed(); +} + +void NodeInstanceServerProxy::readDataStream() +{ + QList<QVariant> commandList; + + while (!m_socket->atEnd()) { + if (m_socket->bytesAvailable() < int(sizeof(quint32))) + break; + + QDataStream in(m_socket.data()); + + if (m_blockSize == 0) { + in >> m_blockSize; + } + + if (m_socket->bytesAvailable() < m_blockSize) + break; + + QVariant command; + in >> command; + m_blockSize = 0; + + Q_ASSERT(in.status() == QDataStream::Ok); + + commandList.append(command); + } + + foreach (const QVariant &command, commandList) { + dispatchCommand(command); + } +} + +void NodeInstanceServerProxy::createInstances(const CreateInstancesCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceServerProxy::changeFileUrl(const ChangeFileUrlCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceServerProxy::createScene(const CreateSceneCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceServerProxy::clearScene(const ClearSceneCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceServerProxy::removeInstances(const RemoveInstancesCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceServerProxy::removeProperties(const RemovePropertiesCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceServerProxy::changePropertyBindings(const ChangeBindingsCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceServerProxy::changePropertyValues(const ChangeValuesCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceServerProxy::reparentInstances(const ReparentInstancesCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceServerProxy::changeIds(const ChangeIdsCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +void NodeInstanceServerProxy::changeState(const ChangeStateCommand &command) +{ + writeCommand(QVariant::fromValue(command)); +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.h b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.h new file mode 100644 index 0000000000..6e3fc1cc9d --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserverproxy.h @@ -0,0 +1,64 @@ +#ifndef NODEINSTANCESERVERPROXY_H +#define NODEINSTANCESERVERPROXY_H + +#include "nodeinstanceserverinterface.h" + +#include <QDataStream> +#include <QWeakPointer> +#include <QProcess> + +QT_BEGIN_NAMESPACE +class QLocalServer; +class QLocalSocket; +class QProcess; +QT_END_NAMESPACE + +namespace QmlDesigner { + +class NodeInstanceClientInterface; +class NodeInstanceView; +class NodeInstanceClientProxy; + +class NodeInstanceServerProxy : public NodeInstanceServerInterface +{ + Q_OBJECT +public: + explicit NodeInstanceServerProxy(NodeInstanceView *nodeInstanceView); + ~NodeInstanceServerProxy(); + void createInstances(const CreateInstancesCommand &command); + void changeFileUrl(const ChangeFileUrlCommand &command); + void createScene(const CreateSceneCommand &command); + void clearScene(const ClearSceneCommand &command); + void removeInstances(const RemoveInstancesCommand &command); + void removeProperties(const RemovePropertiesCommand &command); + void changePropertyBindings(const ChangeBindingsCommand &command); + void changePropertyValues(const ChangeValuesCommand &command); + void reparentInstances(const ReparentInstancesCommand &command); + void changeIds(const ChangeIdsCommand &command); + void changeState(const ChangeStateCommand &command); + + void setBlockUpdates(bool block); + +protected: + void writeCommand(const QVariant &command); + void dispatchCommand(const QVariant &command); + NodeInstanceClientInterface *nodeInstanceClient() const; + +signals: + void processCrashed(); + +private slots: + void processFinished(int exitCode, QProcess::ExitStatus exitStatus); + void readDataStream(); + +private: + QWeakPointer<QLocalServer> m_localServer; + QWeakPointer<QLocalSocket> m_socket; + QWeakPointer<NodeInstanceView> m_nodeInstanceView; + QWeakPointer<QProcess> m_qmlPuppetProcess; + quint32 m_blockSize; +}; + +} // namespace QmlDesigner + +#endif // NODEINSTANCESERVERPROXY_H diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstancesignalspy.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstancesignalspy.cpp index 376ce9d1aa..d2ff7586a7 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstancesignalspy.cpp +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstancesignalspy.cpp @@ -79,8 +79,8 @@ int NodeInstanceSignalSpy::qt_metacall(QMetaObject::Call call, int methodId, voi if (call == QMetaObject::InvokeMetaMethod && methodId > QObject::staticMetaObject.methodCount()) { ObjectNodeInstance::Pointer nodeInstance = m_objectNodeInstance.toStrongRef(); - if (nodeInstance && nodeInstance->nodeInstanceView() && nodeInstance->modelNode().isValid()) { - nodeInstance->nodeInstanceView()->notifyPropertyChange(nodeInstance->modelNode(), m_indexPropertyHash.value(methodId)); + if (nodeInstance && nodeInstance->nodeInstanceServer() && nodeInstance->isValid()) { + nodeInstance->nodeInstanceServer()->notifyPropertyChange(nodeInstance->instanceId(), m_indexPropertyHash.value(methodId)); } } diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp index dd0a94983c..cb4925ccec 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp @@ -44,7 +44,6 @@ #include <modelnode.h> #include <propertymetainfo.h> #include <metainfo.h> -#include <nodeinstance.h> #include <typeinfo> #include <iwidgetplugin.h> @@ -55,9 +54,24 @@ #include "nodeabstractproperty.h" #include "nodelistproperty.h" -#include "objectnodeinstance.h" - -#include "qmlmodelview.h" +#include <nodeinstanceserverinterface.h> + +#include "createscenecommand.h" +#include "createinstancescommand.h" +#include "clearscenecommand.h" +#include "changefileurlcommand.h" +#include "reparentinstancescommand.h" +#include "changevaluescommand.h" +#include "changebindingscommand.h" +#include "changeidscommand.h" +#include "removeinstancescommand.h" +#include "removepropertiescommand.h" +#include "valueschangedcommand.h" +#include "pixmapchangedcommand.h" +#include "informationchangedcommand.h" +#include "changestatecommand.h" + +#include "nodeinstanceserverproxy.h" enum { debug = false @@ -91,14 +105,8 @@ d too. */ NodeInstanceView::NodeInstanceView(QObject *parent) : AbstractView(parent), - m_graphicsView(new QGraphicsView), - m_blockStatePropertyChanges(false) + m_blockUpdates(false) { - m_graphicsView->setAttribute(Qt::WA_DontShowOnScreen, true); - m_graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState); - m_graphicsView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); - m_graphicsView->setScene(new QGraphicsScene(m_graphicsView.data())); - m_graphicsView->scene()->setItemIndexMethod(QGraphicsScene::NoIndex); } @@ -108,6 +116,7 @@ NodeInstanceView::NodeInstanceView(QObject *parent) NodeInstanceView::~NodeInstanceView() { removeAllInstanceNodeRelationships(); + delete nodeInstanceServer(); } /*! \name Overloaded Notifiers @@ -122,18 +131,42 @@ NodeInstanceView::~NodeInstanceView() void NodeInstanceView::modelAttached(Model *model) { AbstractView::modelAttached(model); - engine()->setBaseUrl(model->fileUrl()); - loadModel(model); + m_nodeInstanceServer = new NodeInstanceServerProxy(this); + connect(m_nodeInstanceServer.data(), SIGNAL(processCrashed()), this, SLOT(restartProcess())); + m_instanceIdCounter = 1; + + setBlockUpdates(true); + nodeInstanceServer()->createScene(createCreateSceneCommand()); + + nodeInstanceServer()->changeFileUrl(createChangeFileUrlCommand(model->fileUrl())); + + loadNodes(allModelNodes()); + setBlockUpdates(false); } void NodeInstanceView::modelAboutToBeDetached(Model * model) { removeAllInstanceNodeRelationships(); + nodeInstanceServer()->clearScene(createClearSceneCommand()); + delete nodeInstanceServer(); AbstractView::modelAboutToBeDetached(model); - delete m_engine.data(); } +void NodeInstanceView::restartProcess() +{ + setBlockUpdates(true); + Model *oldModel = model(); + if (oldModel) { + oldModel->detachView(this); + m_valuePropertyChangeList.clear(); + m_renderImageChangeSet.clear(); + m_informationChangeSet.clear(); + oldModel->attachView(this); + } + setBlockUpdates(false); +} + /*! \brief Notifing the view that a node was created. A NodeInstance will be created for the new created ModelNode. \param createdNode New created ModelNode. @@ -141,9 +174,8 @@ void NodeInstanceView::modelAboutToBeDetached(Model * model) void NodeInstanceView::nodeCreated(const ModelNode &createdNode) { NodeInstance instance = loadNode(createdNode); - - if (instance.isValid()) - instance.doComponentComplete(); + nodeInstanceServer()->createInstances(createCreateInstancesCommand(QList<NodeInstance>() << instance)); + nodeInstanceServer()->changePropertyValues(createChangeValueCommand(createdNode.variantProperties())); } /*! \brief Notifing the view that a node was created. @@ -151,6 +183,7 @@ void NodeInstanceView::nodeCreated(const ModelNode &createdNode) */ void NodeInstanceView::nodeAboutToBeRemoved(const ModelNode &removedNode) { + nodeInstanceServer()->removeInstances(createRemoveInstancesCommand(removedNode)); removeInstanceAndSubInstances(removedNode); } @@ -158,116 +191,103 @@ void NodeInstanceView::nodeRemoved(const ModelNode &/*removedNode*/, const NodeA { } -/*! \brief Notifing the view that a AbstractProperty was added to a ModelNode. - - The property will be set for the NodeInstance. - -\param state ModelNode to which the Property belongs -\param property AbstractProperty which was added -\see AbstractProperty NodeInstance ModelNode -*/ - -void NodeInstanceView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList) +void NodeInstanceView::resetHorizontalAnchors(const ModelNode &modelNode) { - foreach (const AbstractProperty &property, propertyList) { - resetInstanceProperty(property); + QList<BindingProperty> bindingList; + QList<VariantProperty> valueList; - if (property.isNodeAbstractProperty()) { - foreach (const ModelNode &subNode, property.toNodeAbstractProperty().allSubNodes()) - removeInstanceNodeRelationship(subNode); - } + if (modelNode.hasBindingProperty("x")) { + bindingList.append(modelNode.bindingProperty("x")); + } else if (modelNode.hasVariantProperty("x")) { + valueList.append(modelNode.variantProperty("x")); } -} -void NodeInstanceView::propertiesRemoved(const QList<AbstractProperty>& /*propertyList*/) -{ -} - -void NodeInstanceView::resetInstanceProperty(const AbstractProperty &property) -{ - if (hasInstanceForNode(property.parentModelNode())) { // TODO ugly workaround - NodeInstance instance = instanceForNode(property.parentModelNode()); - Q_ASSERT(instance.isValid()); - const QString name = property.name(); - if (activeStateInstance().isValid() && !property.parentModelNode().metaInfo().isSubclassOf("PropertyChange", 4, 7)) { - bool statePropertyWasReseted = activeStateInstance().resetStateProperty(instance, name, instance.resetVariant(name)); - if (!statePropertyWasReseted) - instance.resetProperty(name); - } else { - instance.resetProperty(name); - } + if (modelNode.hasBindingProperty("width")) { + bindingList.append(modelNode.bindingProperty("width")); + } else if (modelNode.hasVariantProperty("width")) { + valueList.append(modelNode.variantProperty("width")); } -} -void NodeInstanceView::setInstancePropertyBinding(const BindingProperty &property) -{ - NodeInstance instance = instanceForNode(property.parentModelNode()); + if (!valueList.isEmpty()) + nodeInstanceServer()->changePropertyValues(createChangeValueCommand(valueList)); - const QString name = property.name(); - const QString expression = property.expression(); + if (!bindingList.isEmpty()) + nodeInstanceServer()->changePropertyBindings(createChangeBindingCommand(bindingList)); +} - if (activeStateInstance().isValid() && !property.parentModelNode().metaInfo().isSubclassOf("PropertyChange", 4, 7)) { - bool stateBindingWasUpdated = activeStateInstance().updateStateBinding(instance, name, expression); - if (!stateBindingWasUpdated) { - if (property.isDynamic()) - instance.setPropertyDynamicBinding(name, property.dynamicTypeName(), expression); - else - instance.setPropertyBinding(name, expression); - } - } else { - if (property.isDynamic()) - instance.setPropertyDynamicBinding(name, property.dynamicTypeName(), expression); - else - instance.setPropertyBinding(name, expression); - } +void NodeInstanceView::resetVerticalAnchors(const ModelNode &modelNode) +{ + QList<BindingProperty> bindingList; + QList<VariantProperty> valueList; + if (modelNode.hasBindingProperty("yx")) { + bindingList.append(modelNode.bindingProperty("yx")); + } else if (modelNode.hasVariantProperty("y")) { + valueList.append(modelNode.variantProperty("y")); + } - if (property.parentModelNode().isRootNode() - && (name == "width" || name == "height")) { - QGraphicsObject *rootGraphicsObject = qobject_cast<QGraphicsObject*>(instance.internalObject()); - if (rootGraphicsObject) { - m_graphicsView->setSceneRect(rootGraphicsObject->boundingRect()); - } + if (modelNode.hasBindingProperty("height")) { + bindingList.append(modelNode.bindingProperty("height")); + } else if (modelNode.hasVariantProperty("height")) { + valueList.append(modelNode.variantProperty("height")); } - instance.paintUpdate(); + if (!valueList.isEmpty()) + nodeInstanceServer()->changePropertyValues(createChangeValueCommand(valueList)); + if (!bindingList.isEmpty()) + nodeInstanceServer()->changePropertyBindings(createChangeBindingCommand(bindingList)); } -void NodeInstanceView::setInstancePropertyVariant(const VariantProperty &property) +void NodeInstanceView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList) { - NodeInstance instance = instanceForNode(property.parentModelNode()); - - const QString name = property.name(); - const QVariant value = property.value(); + QList<ModelNode> nodeList; + QList<AbstractProperty> nonNodePropertyList; - if (activeStateInstance().isValid() && !property.parentModelNode().metaInfo().isSubclassOf("PropertyChange", 4, 7)) { - bool stateValueWasUpdated = activeStateInstance().updateStateVariant(instance, name, value); - if (!stateValueWasUpdated) { - if (property.isDynamic()) - instance.setPropertyDynamicVariant(name, property.dynamicTypeName(), value); - else - instance.setPropertyVariant(name, value); + foreach (const AbstractProperty &property, propertyList) { + if (property.isNodeAbstractProperty()) { + nodeList.append(property.toNodeAbstractProperty().allSubNodes()); + } else { + nonNodePropertyList.append(property); } - } else { //base state - if (property.isDynamic()) - instance.setPropertyDynamicVariant(name, property.dynamicTypeName(), value); - else - instance.setPropertyVariant(name, value); } + nodeInstanceServer()->removeInstances(createRemoveInstancesCommand(nodeList)); + nodeInstanceServer()->removeProperties(createRemovePropertiesCommand(nonNodePropertyList)); - if (property.parentModelNode().isRootNode() - && (name == "width" || name == "height")) { - QGraphicsObject *rootGraphicsObject = qobject_cast<QGraphicsObject*>(instance.internalObject()); - if (rootGraphicsObject) { - m_graphicsView->setSceneRect(rootGraphicsObject->boundingRect()); + foreach (const AbstractProperty &property, propertyList) { + const QString &name = property.name(); + if (name == "anchors.fill") { + resetHorizontalAnchors(property.parentModelNode()); + resetVerticalAnchors(property.parentModelNode()); + } else if (name == "anchors.centerIn") { + resetHorizontalAnchors(property.parentModelNode()); + resetVerticalAnchors(property.parentModelNode()); + } else if (name == "anchors.top") { + resetVerticalAnchors(property.parentModelNode()); + } else if (name == "anchors.left") { + resetHorizontalAnchors(property.parentModelNode()); + } else if (name == "anchors.right") { + resetHorizontalAnchors(property.parentModelNode()); + } else if (name == "anchors.bottom") { + resetVerticalAnchors(property.parentModelNode()); + } else if (name == "anchors.horizontalCenter") { + resetHorizontalAnchors(property.parentModelNode()); + } else if (name == "anchors.verticalCenter") { + resetVerticalAnchors(property.parentModelNode()); + } else if (name == "anchors.baseline") { + resetVerticalAnchors(property.parentModelNode()); } } - instance.paintUpdate(); + foreach (const ModelNode &node, nodeList) + removeInstanceNodeRelationship(node); +} + +void NodeInstanceView::propertiesRemoved(const QList<AbstractProperty>& /*propertyList*/) +{ } void NodeInstanceView::removeInstanceAndSubInstances(const ModelNode &node) @@ -283,19 +303,20 @@ void NodeInstanceView::removeInstanceAndSubInstances(const ModelNode &node) void NodeInstanceView::rootNodeTypeChanged(const QString &/*type*/, int /*majorVersion*/, int /*minorVersion*/) { + nodeInstanceServer()->clearScene(createClearSceneCommand()); removeAllInstanceNodeRelationships(); QList<ModelNode> nodeList; nodeList.append(allModelNodes()); + nodeInstanceServer()->createScene(createCreateSceneCommand()); loadNodes(nodeList); } void NodeInstanceView::bindingPropertiesChanged(const QList<BindingProperty>& propertyList, PropertyChangeFlags /*propertyChange*/) { - foreach (const BindingProperty &property, propertyList) - setInstancePropertyBinding(property); + nodeInstanceServer()->changePropertyBindings(createChangeBindingCommand(propertyList)); } /*! \brief Notifing the view that a AbstractProperty value was changed to a ModelNode. @@ -311,8 +332,7 @@ void NodeInstanceView::bindingPropertiesChanged(const QList<BindingProperty>& pr void NodeInstanceView::variantPropertiesChanged(const QList<VariantProperty>& propertyList, PropertyChangeFlags /*propertyChange*/) { - foreach (const VariantProperty &property, propertyList) - setInstancePropertyVariant(property); + nodeInstanceServer()->changePropertyValues(createChangeValueCommand(propertyList)); } /*! \brief Notifing the view that a ModelNode has a new Parent. @@ -328,39 +348,54 @@ void NodeInstanceView::variantPropertiesChanged(const QList<VariantProperty>& pr void NodeInstanceView::nodeReparented(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent, AbstractView::PropertyChangeFlags /*propertyChange*/) { - NodeInstance nodeInstance(instanceForNode(node)); - NodeInstance oldParentInstance; - if (hasInstanceForNode(oldPropertyParent.parentModelNode())) - oldParentInstance = instanceForNode(oldPropertyParent.parentModelNode()); - NodeInstance newParentInstance; - if (hasInstanceForNode(newPropertyParent.parentModelNode())) - newParentInstance = instanceForNode(newPropertyParent.parentModelNode()); - nodeInstance.reparent(oldParentInstance, oldPropertyParent.name(), newParentInstance, newPropertyParent.name()); + nodeInstanceServer()->reparentInstances(createReparentInstancesCommand(node, newPropertyParent, oldPropertyParent)); +// NodeInstance nodeInstance(instanceForNode(node)); +// NodeInstance oldParentInstance; +// if (hasInstanceForNode(oldPropertyParent.parentModelNode())) +// oldParentInstance = instanceForNode(oldPropertyParent.parentModelNode()); +// NodeInstance newParentInstance; +// if (hasInstanceForNode(newPropertyParent.parentModelNode())) +// newParentInstance = instanceForNode(newPropertyParent.parentModelNode()); +// nodeInstance.reparent(oldParentInstance, oldPropertyParent.name(), newParentInstance, newPropertyParent.name()); } -void NodeInstanceView::fileUrlChanged(const QUrl &/*oldUrl*/, const QUrl &/*newUrl*/) +void NodeInstanceView::fileUrlChanged(const QUrl &/*oldUrl*/, const QUrl &newUrl) { // TODO: We have to probably reload everything, so that images etc are updated!!! - engine()->setBaseUrl(model()->fileUrl()); + //engine()->setBaseUrl(model()->fileUrl()); + + //TODO reload the whole scene + nodeInstanceServer()->changeFileUrl(createChangeFileUrlCommand(newUrl)); } -void NodeInstanceView::nodeIdChanged(const ModelNode& node, const QString& newId, const QString& /*oldId*/) +void NodeInstanceView::nodeIdChanged(const ModelNode& node, const QString& /*newId*/, const QString& /*oldId*/) { if (hasInstanceForNode(node)) { NodeInstance instance = instanceForNode(node); - - instance.setId(newId); + nodeInstanceServer()->changeIds(createChangeIdsCommand(QList<NodeInstance>() << instance)); } } void NodeInstanceView::nodeOrderChanged(const NodeListProperty & listProperty, const ModelNode & /*movedNode*/, int /*oldIndex*/) { + QVector<ReparentContainer> containerList; + QString propertyName = listProperty.name(); + qint32 containerInstanceId = -1; + ModelNode containerNode = listProperty.parentModelNode(); + if (hasInstanceForNode(containerNode)) + containerInstanceId = instanceForNode(containerNode).instanceId(); + foreach(const ModelNode &node, listProperty.toModelNodeList()) { - NodeInstance instance = instanceForNode(node); - if (instance.isValid()) - instance.reparent(instance.parent(), listProperty.name(), instance.parent(), listProperty.name()); + qint32 instanceId = -1; + if (hasInstanceForNode(node)) { + instanceId = instanceForNode(node).instanceId(); + ReparentContainer container(instanceId, containerInstanceId, propertyName, containerInstanceId, propertyName); + containerList.append(container); + } } + + nodeInstanceServer()->reparentInstances(ReparentInstancesCommand(containerList)); } /*! \brief Notifing the view that the selection has been changed. @@ -393,60 +428,57 @@ void NodeInstanceView::instancePropertyChange(const QList<QPair<ModelNode, QStri void NodeInstanceView::loadNodes(const QList<ModelNode> &nodeList) { + QList<NodeInstance> instanceList; + foreach (const ModelNode &node, nodeList) - loadNode(node); + instanceList.append(loadNode(node)); - foreach (const ModelNode &node, nodeList) { - if (node.hasParentProperty()) - instanceForNode(node).reparent(NodeInstance(), QString(), instanceForNode(node.parentProperty().parentModelNode()), node.parentProperty().name()); - } + + QList<VariantProperty> variantPropertyList; + QList<BindingProperty> bindingPropertyList; foreach (const ModelNode &node, nodeList) { - foreach (const BindingProperty &property, node.bindingProperties()) - instanceForNode(node).setPropertyBinding(property.name(), property.expression()); + variantPropertyList.append(node.variantProperties()); + bindingPropertyList.append(node.bindingProperties()); } - QListIterator<ModelNode> listIterator(nodeList); - listIterator.toBack(); +// QListIterator<ModelNode> listIterator(nodeList); +// listIterator.toBack(); - while (listIterator.hasPrevious()) - instanceForNode(listIterator.previous()).doComponentComplete(); -} +// while (listIterator.hasPrevious()) +// instanceForNode(listIterator.previous()).doComponentComplete(); -// TODO: Set base state as current model state -void NodeInstanceView::loadModel(Model *model) -{ - removeAllInstanceNodeRelationships(); - - engine()->rootContext()->setBaseUrl(model->fileUrl()); - - loadNodes(allModelNodes()); + nodeInstanceServer()->createInstances(createCreateInstancesCommand(instanceList)); + nodeInstanceServer()->reparentInstances(createReparentInstancesCommand(instanceList)); + nodeInstanceServer()->changeIds(createChangeIdsCommand(instanceList)); + nodeInstanceServer()->changePropertyValues(createChangeValueCommand(variantPropertyList)); + nodeInstanceServer()->changePropertyBindings(createChangeBindingCommand(bindingPropertyList)); } void NodeInstanceView::removeAllInstanceNodeRelationships() { // prevent destroyed() signals calling back - foreach (NodeInstance instance, m_objectInstanceHash.values()) { - if (instance.isValid()) - instance.setId(QString()); - } +// foreach (NodeInstance instance, m_objectInstanceHash.values()) { +// if (instance.isValid()) +// instance.setId(QString()); +// } - //first the root object - if (rootNodeInstance().internalObject()) - rootNodeInstance().internalObject()->disconnect(); +// //first the root object +// if (rootNodeInstance().internalObject()) +// rootNodeInstance().internalObject()->disconnect(); - rootNodeInstance().makeInvalid(); +// rootNodeInstance().makeInvalid(); - foreach (NodeInstance instance, m_objectInstanceHash.values()) { - if (instance.internalObject()) - instance.internalObject()->disconnect(); + foreach (NodeInstance instance, m_idInstanceHash.values()) { +// if (instance.internalObject()) +// instance.internalObject()->disconnect(); instance.makeInvalid(); - } + } m_nodeInstanceHash.clear(); - m_objectInstanceHash.clear(); + m_idInstanceHash.clear(); } /*! \brief Returns a List of all NodeInstances @@ -467,7 +499,7 @@ QList<NodeInstance> NodeInstanceView::instances() const \returns NodeStance for ModelNode. \see NodeInstance */ -NodeInstance NodeInstanceView::instanceForNode(const ModelNode &node) +NodeInstance NodeInstanceView::instanceForNode(const ModelNode &node) const { Q_ASSERT(node.isValid()); Q_ASSERT(m_nodeInstanceHash.contains(node)); @@ -475,25 +507,25 @@ NodeInstance NodeInstanceView::instanceForNode(const ModelNode &node) return m_nodeInstanceHash.value(node); } -bool NodeInstanceView::hasInstanceForNode(const ModelNode &node) +bool NodeInstanceView::hasInstanceForNode(const ModelNode &node) const { return m_nodeInstanceHash.contains(node); } -NodeInstance NodeInstanceView::instanceForObject(QObject *object) +NodeInstance NodeInstanceView::instanceForId(qint32 id) const { - if (object == 0) + if (id < 0) return NodeInstance(); - return m_objectInstanceHash.value(object); + return m_idInstanceHash.value(id); } -bool NodeInstanceView::hasInstanceForObject(QObject *object) +bool NodeInstanceView::hasInstanceForId(qint32 id) const { - if (object == 0) + if (id < 0) return false; - return m_objectInstanceHash.contains(object); + return m_idInstanceHash.contains(id); } @@ -536,63 +568,54 @@ NodeInstance NodeInstanceView::rootNodeInstance() const -void NodeInstanceView::insertInstanceNodeRelationship(const ModelNode &node, const NodeInstance &instance) +void NodeInstanceView::insertInstanceRelationships(const NodeInstance &instance) { - instance.internalObject()->installEventFilter(childrenChangeEventFilter()); - - - Q_ASSERT(!m_nodeInstanceHash.contains(node)); - m_nodeInstanceHash.insert(node, instance); - m_objectInstanceHash.insert(instance.internalObject(), instance); -} - -QDeclarativeEngine *NodeInstanceView::engine() -{ - if (m_engine.isNull()) - m_engine = new QDeclarativeEngine(this); - return m_engine.data(); -} - -Internal::ChildrenChangeEventFilter *NodeInstanceView::childrenChangeEventFilter() -{ - if (m_childrenChangeEventFilter.isNull()) { - m_childrenChangeEventFilter = new Internal::ChildrenChangeEventFilter(this); - connect(m_childrenChangeEventFilter.data(), SIGNAL(childrenChanged(QObject*)), this, SLOT(emitParentChanged(QObject*))); - } - - return m_childrenChangeEventFilter.data(); + Q_ASSERT(instance.instanceId() >=0); + Q_ASSERT(!m_nodeInstanceHash.contains(instance.modelNode())); + Q_ASSERT(!m_idInstanceHash.contains(instance.instanceId())); + m_nodeInstanceHash.insert(instance.modelNode(), instance); + m_idInstanceHash.insert(instance.instanceId(), instance); } void NodeInstanceView::removeInstanceNodeRelationship(const ModelNode &node) { Q_ASSERT(m_nodeInstanceHash.contains(node)); NodeInstance instance = instanceForNode(node); - if (instance.isValid()) - instance.setId(QString()); - m_objectInstanceHash.remove(instanceForNode(node).internalObject()); +// if (instance.isValid()) +// instance.setId(QString()); + m_idInstanceHash.remove(instanceForNode(node).instanceId()); m_nodeInstanceHash.remove(node); instance.makeInvalid(); } -void NodeInstanceView::notifyPropertyChange(const ModelNode &node, const QString &propertyName) +void NodeInstanceView::setBlockUpdates(bool block) { - if (m_blockStatePropertyChanges) - return; - - if (!node.isValid()) - return; - - if (hasInstanceForNode(node)) - instanceForNode(node).renderPixmapNextPaint(); + if (m_blockUpdates == 0 && block == true) + m_nodeInstanceServer->setBlockUpdates(true); + if (block) { + m_blockUpdates++; + } else if (m_blockUpdates > 0) { + m_blockUpdates--; + } - emitInstancePropertyChange(QList<QPair<ModelNode, QString> >() << qMakePair(node, propertyName)); -} + if (m_blockUpdates == 0) { + m_nodeInstanceServer->setBlockUpdates(false); + if (!m_valuePropertyChangeList.isEmpty()) { + emitInstancePropertyChange(m_valuePropertyChangeList); + m_valuePropertyChangeList.clear(); + } + if (!m_informationChangeSet.isEmpty()) { + emitCustomNotification("__instance information changed__", m_informationChangeSet.toList()); + m_informationChangeSet.clear(); + } -void NodeInstanceView::setBlockStatePropertyChanges(bool block) -{ - m_blockStatePropertyChanges = block; + if (!m_renderImageChangeSet.isEmpty()) { + emitCustomNotification("__instance render pixmap changed__", m_renderImageChangeSet.toList()); + m_renderImageChangeSet.clear(); + } + } } void NodeInstanceView::setStateInstance(const NodeInstance &stateInstance) @@ -610,26 +633,25 @@ NodeInstance NodeInstanceView::activeStateInstance() const return m_activeStateInstance; } -void NodeInstanceView::emitParentChanged(QObject *child) +NodeInstanceServerInterface *NodeInstanceView::nodeInstanceServer() const { - if (hasInstanceForObject(child)) { - notifyPropertyChange(instanceForObject(child).modelNode(), "parent"); - } + return m_nodeInstanceServer.data(); } -NodeInstance NodeInstanceView::loadNode(const ModelNode &node, QObject *objectToBeWrapped) + +NodeInstance NodeInstanceView::loadNode(const ModelNode &node) { - NodeInstance instance(NodeInstance::create(this, node, objectToBeWrapped)); + qint32 instanceId = 0; + + if (!node.isRootNode()) + instanceId = generateInstanceId(); - insertInstanceNodeRelationship(node, instance); + NodeInstance instance(NodeInstance::create(node, instanceId)); + + insertInstanceRelationships(instance); if (node.isRootNode()) { m_rootNodeInstance = instance; - QGraphicsObject *rootGraphicsObject = qobject_cast<QGraphicsObject*>(instance.internalObject()); - if (rootGraphicsObject) { - m_graphicsView->scene()->addItem(rootGraphicsObject); - m_graphicsView->setSceneRect(rootGraphicsObject->boundingRect()); - } } return instance; @@ -637,22 +659,24 @@ NodeInstance NodeInstanceView::loadNode(const ModelNode &node, QObject *objectTo void NodeInstanceView::activateState(const NodeInstance &instance) { - activateBaseState(); - NodeInstance stateInstance(instance); - stateInstance.activateState(); + nodeInstanceServer()->changeState(ChangeStateCommand(instance.instanceId())); +// activateBaseState(); +// NodeInstance stateInstance(instance); +// stateInstance.activateState(); } void NodeInstanceView::activateBaseState() { - if (activeStateInstance().isValid()) - activeStateInstance().deactivateState(); + nodeInstanceServer()->changeState(ChangeStateCommand(-1)); +// if (activeStateInstance().isValid()) +// activeStateInstance().deactivateState(); } void NodeInstanceView::removeRecursiveChildRelationship(const ModelNode &removedNode) { - if (hasInstanceForNode(removedNode)) { - instanceForNode(removedNode).setId(QString()); - } +// if (hasInstanceForNode(removedNode)) { +// instanceForNode(removedNode).setId(QString()); +// } foreach (const ModelNode &childNode, removedNode.allDirectSubModelNodes()) removeRecursiveChildRelationship(childNode); @@ -662,64 +686,238 @@ void NodeInstanceView::removeRecursiveChildRelationship(const ModelNode &removed void NodeInstanceView::render(QPainter * painter, const QRectF &target, const QRectF &source, Qt::AspectRatioMode aspectRatioMode) { - if (m_graphicsView) { - painter->save(); - painter->setRenderHint(QPainter::Antialiasing, true); - painter->setRenderHint(QPainter::TextAntialiasing, true); - painter->setRenderHint(QPainter::SmoothPixmapTransform, true); - painter->setRenderHint(QPainter::HighQualityAntialiasing, true); - painter->setRenderHint(QPainter::NonCosmeticDefaultPen, true); - m_graphicsView->scene()->render(painter, target, source, aspectRatioMode); - painter->restore(); - } +// if (m_graphicsView) { +// painter->save(); +// painter->setRenderHint(QPainter::Antialiasing, true); +// painter->setRenderHint(QPainter::TextAntialiasing, true); +// painter->setRenderHint(QPainter::SmoothPixmapTransform, true); +// painter->setRenderHint(QPainter::HighQualityAntialiasing, true); +// painter->setRenderHint(QPainter::NonCosmeticDefaultPen, true); +// m_graphicsView->scene()->render(painter, target, source, aspectRatioMode); +// painter->restore(); +// } } QRectF NodeInstanceView::sceneRect() const { - if (m_graphicsView) + if (rootNodeInstance().isValid()) return rootNodeInstance().boundingRect(); return QRectF(); } +CreateSceneCommand NodeInstanceView::createCreateSceneCommand() const +{ + return CreateSceneCommand(); +} +ClearSceneCommand NodeInstanceView::createClearSceneCommand() const +{ + return ClearSceneCommand(); +} -QFileSystemWatcher *NodeInstanceView::fileSystemWatcher() +CreateInstancesCommand NodeInstanceView::createCreateInstancesCommand(const QList<NodeInstance> &instanceList) const { - if (m_fileSystemWatcher.isNull()) { - m_fileSystemWatcher = new QFileSystemWatcher(this); - connect(m_fileSystemWatcher.data(), SIGNAL(fileChanged(QString)), this, SLOT(refreshLocalFileProperty(QString))); + QVector<InstanceContainer> containerList; + foreach(const NodeInstance &instance, instanceList) { + InstanceContainer container(instance.instanceId(), instance.modelNode().type(), instance.modelNode().majorVersion(), instance.modelNode().minorVersion(), instance.modelNode().metaInfo().componentString()); + containerList.append(container); } - return m_fileSystemWatcher.data(); + return CreateInstancesCommand(containerList); } -void NodeInstanceView::addFilePropertyToFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path) +ReparentInstancesCommand NodeInstanceView::createReparentInstancesCommand(const QList<NodeInstance> &instanceList) const { - m_fileSystemWatcherHash.insert(path, ObjectPropertyPair(object, propertyName)); - fileSystemWatcher()->addPath(path); + QVector<ReparentContainer> containerList; + foreach(const NodeInstance &instance, instanceList) { + if (instance.modelNode().hasParentProperty()) { + NodeAbstractProperty parentProperty = instance.modelNode().parentProperty(); + ReparentContainer container(instance.instanceId(), -1, QString(), instanceForNode(parentProperty.parentModelNode()).instanceId(), parentProperty.name()); + containerList.append(container); + } + } + return ReparentInstancesCommand(containerList); } -void NodeInstanceView::removeFilePropertyFromFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path) +ReparentInstancesCommand NodeInstanceView::createReparentInstancesCommand(const ModelNode &node, const NodeAbstractProperty &newPropertyParent, const NodeAbstractProperty &oldPropertyParent) const { - fileSystemWatcher()->removePath(path); - m_fileSystemWatcherHash.remove(path, ObjectPropertyPair(object, propertyName)); + QVector<ReparentContainer> containerList; + + qint32 newParentInstanceId = -1; + qint32 oldParentInstanceId = -1; + + if (newPropertyParent.isValid() && hasInstanceForNode(newPropertyParent.parentModelNode())) + newParentInstanceId = instanceForNode(newPropertyParent.parentModelNode()).instanceId(); + + + if (oldPropertyParent.isValid() && hasInstanceForNode(oldPropertyParent.parentModelNode())) + oldParentInstanceId = instanceForNode(oldPropertyParent.parentModelNode()).instanceId(); + + + ReparentContainer container(instanceForNode(node).instanceId(), oldParentInstanceId, oldPropertyParent.name(), newParentInstanceId, newPropertyParent.name()); + + containerList.append(container); + + return ReparentInstancesCommand(containerList); } -void NodeInstanceView::refreshLocalFileProperty(const QString &path) +ChangeFileUrlCommand NodeInstanceView::createChangeFileUrlCommand(const QUrl &fileUrl) const { - if (m_fileSystemWatcherHash.contains(path)) { - QList<ObjectPropertyPair> objectPropertyPairList = m_fileSystemWatcherHash.values(); - foreach(const ObjectPropertyPair &objectPropertyPair, objectPropertyPairList) { - QObject *object = objectPropertyPair.first.data(); - QString propertyName = objectPropertyPair.second; + return ChangeFileUrlCommand(fileUrl); +} + +ChangeValuesCommand NodeInstanceView::createChangeValueCommand(const QList<VariantProperty>& propertyList) const +{ + QVector<PropertyValueContainer> containerList; + + foreach(const VariantProperty &property, propertyList) { + ModelNode node = property.parentModelNode(); + if (node.isValid() && hasInstanceForNode(node)) { + NodeInstance instance = instanceForNode(node); + PropertyValueContainer container(instance.instanceId(), property.name(), property.value(), property.dynamicTypeName()); + containerList.append(container); + } + + } + + return ChangeValuesCommand(containerList); +} + +ChangeBindingsCommand NodeInstanceView::createChangeBindingCommand(const QList<BindingProperty> &propertyList) const +{ + QVector<PropertyBindingContainer> containerList; + + foreach(const BindingProperty &property, propertyList) { + ModelNode node = property.parentModelNode(); + if (node.isValid() && hasInstanceForNode(node)) { + NodeInstance instance = instanceForNode(node); + PropertyBindingContainer container(instance.instanceId(), property.name(), property.expression(), property.dynamicTypeName()); + containerList.append(container); + } + + } + + return ChangeBindingsCommand(containerList); +} + +ChangeIdsCommand NodeInstanceView::createChangeIdsCommand(const QList<NodeInstance> &instanceList) const +{ + QVector<IdContainer> containerList; + foreach(const NodeInstance &instance, instanceList) { + QString id = instance.modelNode().id(); + if (!id.isEmpty()) { + IdContainer container(instance.instanceId(), id); + containerList.append(container); + } + } + + return ChangeIdsCommand(containerList); +} + - if (hasInstanceForObject(object)) { - instanceForObject(object).refreshProperty(propertyName); + +RemoveInstancesCommand NodeInstanceView::createRemoveInstancesCommand(const QList<ModelNode> &nodeList) const +{ + QVector<qint32> idList; + foreach(const ModelNode &node, nodeList) { + if (node.isValid() && hasInstanceForNode(node)) { + NodeInstance instance = instanceForNode(node); + + if (instance.instanceId() >= 0) { + idList.append(instance.instanceId()); + } + } + } + + return RemoveInstancesCommand(idList); +} + +RemoveInstancesCommand NodeInstanceView::createRemoveInstancesCommand(const ModelNode &node) const +{ + QVector<qint32> idList; + + if (node.isValid() && hasInstanceForNode(node)) + idList.append(instanceForNode(node).instanceId()); + + return RemoveInstancesCommand(idList); +} + +RemovePropertiesCommand NodeInstanceView::createRemovePropertiesCommand(const QList<AbstractProperty> &propertyList) const +{ + QVector<PropertyAbstractContainer> containerList; + + foreach(const AbstractProperty &property, propertyList) { + ModelNode node = property.parentModelNode(); + if (node.isValid() && hasInstanceForNode(node)) { + NodeInstance instance = instanceForNode(node); + PropertyAbstractContainer container(instance.instanceId(), property.name(), property.dynamicTypeName()); + containerList.append(container); + } + + } + + return RemovePropertiesCommand(containerList); +} + +void NodeInstanceView::valuesChanged(const ValuesChangedCommand &command) +{ + foreach(const PropertyValueContainer &container, command.valueChanges()) { + if (hasInstanceForId(container.instanceId())) { + NodeInstance instance = instanceForId(container.instanceId()); + if (instance.isValid()) { + instance.setProperty(container.name(), container.value()); + m_valuePropertyChangeList.append(qMakePair(instance.modelNode(), container.name())); + } + } + } + + if (!m_blockUpdates && !m_valuePropertyChangeList.isEmpty()) { + emitInstancePropertyChange(m_valuePropertyChangeList); + m_valuePropertyChangeList.clear(); + } +} + +void NodeInstanceView::pixmapChanged(const PixmapChangedCommand &command) +{ + + if (hasInstanceForId(command.instanceId())) { + NodeInstance instance = instanceForId(command.instanceId()); + if (instance.isValid()) { + instance.setRenderImage(command.renderImage()); + m_renderImageChangeSet.insert(instance.modelNode()); + } + } + + if (!m_blockUpdates && !m_renderImageChangeSet.isEmpty()) { + emitCustomNotification("__instance render pixmap changed__", m_renderImageChangeSet.toList()); + m_renderImageChangeSet.clear(); + } +} + +void NodeInstanceView::informationChanged(const InformationChangedCommand &command) +{ + foreach(const InformationContainer &container, command.informations()) { + if (hasInstanceForId(container.instanceId())) { + NodeInstance instance = instanceForId(container.instanceId()); + if (instance.isValid()) { + instance.setInformation(container.name(), container.information(), container.secondInformation(), container.thirdInformation()); + m_informationChangeSet.insert(instance.modelNode()); } } } + + if (!m_blockUpdates && !m_informationChangeSet.isEmpty()) { + emitCustomNotification("__instance information changed__", m_informationChangeSet.toList()); + m_informationChangeSet.clear(); + } +} + + +qint32 NodeInstanceView::generateInstanceId() +{ + return m_instanceIdCounter++; } } diff --git a/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.cpp index 24bb3d67e3..b97321f121 100644 --- a/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.cpp @@ -31,12 +31,6 @@ #include "qmlgraphicsitemnodeinstance.h" #include "graphicsobjectnodeinstance.h" -#include "graphicsviewnodeinstance.h" -#include "graphicsscenenodeinstance.h" -#include "graphicswidgetnodeinstance.h" -#include "qmlviewnodeinstance.h" -#include "widgetnodeinstance.h" -#include "proxywidgetnodeinstance.h" #include <invalidreparentingexception.h> #include <invalidnodeinstanceexception.h> @@ -61,6 +55,7 @@ #ifndef QT_NO_WEBKIT #include <QGraphicsWebView> #endif +#include <QGraphicsObject> #include <QTextDocument> @@ -76,30 +71,9 @@ namespace QmlDesigner { namespace Internal { - -ChildrenChangeEventFilter::ChildrenChangeEventFilter(QObject *parent) - : QObject(parent) -{ -} - - -bool ChildrenChangeEventFilter::eventFilter(QObject * /*object*/, QEvent *event) -{ - switch (event->type()) { - case QEvent::ChildAdded: - case QEvent::ChildRemoved: - { - QChildEvent *childEvent = static_cast<QChildEvent*>(event); - emit childrenChanged(childEvent->child()); break; - } - default: break; - } - - return false; -} - ObjectNodeInstance::ObjectNodeInstance(QObject *object) - : m_deleteHeldInstance(true), + : m_instanceId(-1), + m_deleteHeldInstance(true), m_object(object), m_metaObject(0), m_isInPositioner(false) @@ -118,13 +92,8 @@ void ObjectNodeInstance::destroy() // Remove from old property if (object()) { setId(QString()); - if (modelNode().isValid() && modelNode().parentProperty().isValid()) { - NodeAbstractProperty parentProperty = modelNode().parentProperty(); - ModelNode parentNode = parentProperty.parentModelNode(); - if (parentNode.isValid() && nodeInstanceView()->hasInstanceForNode(parentNode)) { - NodeInstance parentInstance = nodeInstanceView()->instanceForNode(parentNode); - reparent(parentInstance, parentProperty.name(), NodeInstance() , QString()); - } + if (m_instanceId >= 0) { + reparent(parentInstance(), m_parentProperty, ObjectNodeInstance::Pointer(), QString()); } } @@ -136,28 +105,29 @@ void ObjectNodeInstance::destroy() } m_metaObject = 0; + m_instanceId = -1; } -ModelNode ObjectNodeInstance::modelNode() const +void ObjectNodeInstance::setInstanceId(qint32 id) { - return m_modelNode; + m_instanceId = id; } -void ObjectNodeInstance::setModelNode(const ModelNode &node) +qint32 ObjectNodeInstance::instanceId() const { - m_modelNode = node; + return m_instanceId; } -NodeInstanceView *ObjectNodeInstance::nodeInstanceView() const +NodeInstanceServer *ObjectNodeInstance::nodeInstanceServer() const { - return m_nodeInstanceView.data(); + return m_nodeInstanceServer.data(); } -void ObjectNodeInstance::setNodeInstanceView(NodeInstanceView *view) +void ObjectNodeInstance::setNodeInstanceServer(NodeInstanceServer *server) { - Q_ASSERT(!m_nodeInstanceView.data()); + Q_ASSERT(!m_nodeInstanceServer.data()); - m_nodeInstanceView = view; + m_nodeInstanceServer = server; } static bool hasPropertiesWitoutNotifications(const QMetaObject *metaObject) @@ -172,19 +142,15 @@ static bool hasPropertiesWitoutNotifications(const QMetaObject *metaObject) void ObjectNodeInstance::initializePropertyWatcher(const ObjectNodeInstance::Pointer &objectNodeInstance) { - if (!objectNodeInstance->modelNode().metaInfo().isComponent()) { // TODO: this is a nasty workaround which needs to be removed - const QMetaObject *metaObject = objectNodeInstance->object()->metaObject(); - m_metaObject = new NodeInstanceMetaObject(objectNodeInstance, nodeInstanceView()->engine()); - for(int propertyIndex = QObject::staticMetaObject.propertyCount(); propertyIndex < metaObject->propertyCount(); propertyIndex++) { - if (QDeclarativeMetaType::isQObject(metaObject->property(propertyIndex).userType())) { - QObject *propertyObject = QDeclarativeMetaType::toQObject(metaObject->property(propertyIndex).read(objectNodeInstance->object())); - if (propertyObject && hasPropertiesWitoutNotifications(propertyObject->metaObject())) { - new NodeInstanceMetaObject(objectNodeInstance, propertyObject, metaObject->property(propertyIndex).name(), nodeInstanceView()->engine()); - } + const QMetaObject *metaObject = objectNodeInstance->object()->metaObject(); + m_metaObject = new NodeInstanceMetaObject(objectNodeInstance, nodeInstanceServer()->engine()); + for(int propertyIndex = QObject::staticMetaObject.propertyCount(); propertyIndex < metaObject->propertyCount(); propertyIndex++) { + if (QDeclarativeMetaType::isQObject(metaObject->property(propertyIndex).userType())) { + QObject *propertyObject = QDeclarativeMetaType::toQObject(metaObject->property(propertyIndex).read(objectNodeInstance->object())); + if (propertyObject && hasPropertiesWitoutNotifications(propertyObject->metaObject())) { + new NodeInstanceMetaObject(objectNodeInstance, propertyObject, metaObject->property(propertyIndex).name(), nodeInstanceServer()->engine()); } } - } else { - qWarning() << "dynamic properties are not supported for components"; } m_signalSpy.setObjectNodeInstance(objectNodeInstance); @@ -213,35 +179,6 @@ bool ObjectNodeInstance::isQmlGraphicsItem() const return false; } -bool ObjectNodeInstance::isGraphicsScene() const -{ - return false; -} - -bool ObjectNodeInstance::isGraphicsView() const -{ - return false; -} - -bool ObjectNodeInstance::isGraphicsWidget() const -{ - return false; -} - -bool ObjectNodeInstance::isProxyWidget() const -{ - return false; -} - -bool ObjectNodeInstance::isWidget() const -{ - return false; -} - -bool ObjectNodeInstance::isQDeclarativeView() const -{ - return false; -} bool ObjectNodeInstance::isGraphicsObject() const { @@ -325,9 +262,9 @@ bool ObjectNodeInstance::isAnchoredByChildren() const return false; } -QPair<QString, NodeInstance> ObjectNodeInstance::anchor(const QString &/*name*/) const +QPair<QString, ServerNodeInstance> ObjectNodeInstance::anchor(const QString &/*name*/) const { - return qMakePair(QString(), NodeInstance()); + return qMakePair(QString(), ServerNodeInstance()); } @@ -384,10 +321,10 @@ void ObjectNodeInstance::removeFromOldProperty(QObject *object, QObject *oldPare return; if (isList(property)) { - removeObjectFromList(property, object, nodeInstanceView()->engine()); + removeObjectFromList(property, object, nodeInstanceServer()->engine()); } else if (isObject(property)) { - if (nodeInstanceView()->hasInstanceForObject(oldParent)) { - nodeInstanceView()->instanceForObject(oldParent).resetProperty(oldParentProperty); + if (nodeInstanceServer()->hasInstanceForObject(oldParent)) { + nodeInstanceServer()->instanceForObject(oldParent).resetProperty(oldParentProperty); } } @@ -420,14 +357,16 @@ void ObjectNodeInstance::addToNewProperty(QObject *object, QObject *newParent, c Q_ASSERT(objectToVariant(object).isValid()); } -void ObjectNodeInstance::reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty) +void ObjectNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const QString &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const QString &newParentProperty) { - if (oldParentInstance.isValid()) { - removeFromOldProperty(object(), oldParentInstance.internalObject(), oldParentProperty); + if (oldParentInstance) { + removeFromOldProperty(object(), oldParentInstance->object(), oldParentProperty); + m_parentProperty.clear(); } - if (newParentInstance.isValid()) { - addToNewProperty(object(), newParentInstance.internalObject(), newParentProperty); + if (newParentInstance) { + m_parentProperty = newParentProperty; + addToNewProperty(object(), newParentInstance->object(), newParentProperty); } refreshBindings(context()->engine()->rootContext()); @@ -444,22 +383,23 @@ void ObjectNodeInstance::setPropertyVariant(const QString &name, const QVariant if (oldValue.type() == QVariant::Url) { QUrl url = oldValue.toUrl(); QString path = url.toLocalFile(); - if (QFileInfo(path).exists() && nodeInstanceView() && !path.isEmpty()) - nodeInstanceView()->removeFilePropertyFromFileSystemWatcher(object(), name, path); + if (QFileInfo(path).exists() && nodeInstanceServer() && !path.isEmpty()) + nodeInstanceServer()->removeFilePropertyFromFileSystemWatcher(object(), name, path); } - property.write(value); + bool isWritten = property.write(value); + + if (!isWritten) + qDebug() << "ObjectNodeInstance.setPropertyVariant: Cannot be written: " << object() << name << value; QVariant newValue = property.read(); if (newValue.type() == QVariant::Url) { QUrl url = newValue.toUrl(); QString path = url.toLocalFile(); - if (QFileInfo(path).exists() && nodeInstanceView() && !path.isEmpty()) - nodeInstanceView()->addFilePropertyToFileSystemWatcher(object(), name, path); + if (QFileInfo(path).exists() && nodeInstanceServer() && !path.isEmpty()) + nodeInstanceServer()->addFilePropertyToFileSystemWatcher(object(), name, path); } - - } void ObjectNodeInstance::setPropertyBinding(const QString &name, const QString &expression) @@ -470,16 +410,17 @@ void ObjectNodeInstance::setPropertyBinding(const QString &name, const QString & return; if (property.isProperty()) { - QDeclarativeBinding *binding = new QDeclarativeBinding(expression, object(), context()); + QDeclarativeBinding *binding = new QDeclarativeBinding(expression, object(), context(), object()); binding->setTarget(property); binding->setNotifyOnValueChanged(true); QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding); if (oldBinding) oldBinding->destroy(); binding->update(); + if (binding->hasError()) + qDebug() <<" ObjectNodeInstance.setPropertyBinding has Error: " << object() << name << expression; } else { - qWarning() << "Cannot set binding for property" << name << ": property is unknown for type" - << (modelNode().isValid() ? modelNode().type() : "unknown"); + qWarning() << "ObjectNodeInstance.setPropertyBinding: Cannot set binding for property" << name << ": property is unknown for type"; } } @@ -511,17 +452,6 @@ void ObjectNodeInstance::resetProperty(const QString &name) doResetProperty("font.pixelSize"); } -NodeInstance ObjectNodeInstance::instanceForNode(const ModelNode &node, const QString &fullname) -{ - if (nodeInstanceView()->hasInstanceForNode(node)) { - return nodeInstanceView()->instanceForNode(node); - } else { - NodeInstance instance(nodeInstanceView()->loadNode(node)); - m_modelAbstractPropertyHash.insert(fullname, instance); - return instance; - } -} - void ObjectNodeInstance::refreshProperty(const QString &name) { QDeclarativeProperty property(object(), name, context()); @@ -545,10 +475,18 @@ void ObjectNodeInstance::refreshProperty(const QString &name) property.write(oldValue); } -bool ObjectNodeInstance::hasBindingForProperty(const QString &name) const +bool ObjectNodeInstance::hasBindingForProperty(const QString &name, bool *hasChanged) const { QDeclarativeProperty property(object(), name, context()); + bool hasBinding = QDeclarativePropertyPrivate::binding(property); + + if (hasChanged) { + *hasChanged = hasBinding != m_hasBindingHash.value(name, false); + if (*hasChanged) + m_hasBindingHash.insert(name, hasBinding); + } + return QDeclarativePropertyPrivate::binding(property); } @@ -565,8 +503,8 @@ void ObjectNodeInstance::doResetProperty(const QString &propertyName) if (oldValue.type() == QVariant::Url) { QUrl url = oldValue.toUrl(); QString path = url.toLocalFile(); - if (QFileInfo(path).exists() && nodeInstanceView()) - nodeInstanceView()->removeFilePropertyFromFileSystemWatcher(object(), propertyName, path); + if (QFileInfo(path).exists() && nodeInstanceServer()) + nodeInstanceServer()->removeFilePropertyFromFileSystemWatcher(object(), propertyName, path); } @@ -590,6 +528,7 @@ void ObjectNodeInstance::doResetProperty(const QString &propertyName) } else if (property.isWritable()) { if (property.read() == resetValue(propertyName)) return; + property.write(resetValue(propertyName)); } } @@ -613,7 +552,7 @@ QVariant ObjectNodeInstance::property(const QString &name) const return QVariant(); if (url.scheme() == "file") { - int basePathLength = nodeInstanceView()->model()->fileUrl().toLocalFile().lastIndexOf('/'); + int basePathLength = nodeInstanceServer()->fileUrl().toLocalFile().lastIndexOf('/'); return QUrl(url.toLocalFile().mid(basePathLength + 1)); } } @@ -621,6 +560,42 @@ QVariant ObjectNodeInstance::property(const QString &name) const return property.read(); } +QStringList allPropertyNames(QObject *object, const QString &baseName = QString(), QObjectList *inspectedObjects = new QObjectList) +{ + QStringList propertyNameList; + + + if (inspectedObjects->contains(object)) + return propertyNameList; + + inspectedObjects->append(object); + + + const QMetaObject *metaObject = object->metaObject(); + for (int index = 0; index < metaObject->propertyCount(); ++index) { + QMetaProperty metaProperty = metaObject->property(index); + QDeclarativeProperty declarativeProperty(object, QLatin1String(metaProperty.name())); + if (declarativeProperty.isValid() && declarativeProperty.propertyTypeCategory() == QDeclarativeProperty::Object) { + QObject *childObject = QDeclarativeMetaType::toQObject(declarativeProperty.read()); + if (childObject) + propertyNameList.append(allPropertyNames(childObject, baseName + QString::fromUtf8(metaProperty.name()) + '.', inspectedObjects)); + } else if (QDeclarativeValueTypeFactory::valueType(metaProperty.userType())) { + QDeclarativeValueType *valueType = QDeclarativeValueTypeFactory::valueType(metaProperty.userType()); + valueType->setValue(metaProperty.read(object)); + propertyNameList.append(allPropertyNames(valueType, baseName + QString::fromUtf8(metaProperty.name()) + '.', inspectedObjects)); + } else { + propertyNameList.append(baseName + QString::fromUtf8(metaProperty.name())); + } + } + + return propertyNameList; +} + +QStringList ObjectNodeInstance::propertyNames() const +{ + return allPropertyNames(object()); +} + QString ObjectNodeInstance::instanceType(const QString &name) const { QDeclarativeProperty property(object(), name, context()); @@ -640,19 +615,10 @@ bool ObjectNodeInstance::deleteHeldInstance() const return m_deleteHeldInstance; } -ObjectNodeInstance::Pointer ObjectNodeInstance::create(const NodeMetaInfo &nodeMetaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped) +ObjectNodeInstance::Pointer ObjectNodeInstance::create(QObject *object) { - QObject *object = 0; - if (objectToBeWrapped) - object = objectToBeWrapped; - else - object = createObject(nodeMetaInfo, context); - Pointer instance(new ObjectNodeInstance(object)); - if (objectToBeWrapped) - instance->setDeleteHeldInstance(false); // the object isn't owned - instance->populateResetValueHash(); return instance; @@ -744,7 +710,7 @@ static void disableTiledBackingStore(QObject *object) #endif } -void ObjectNodeInstance::tweakObjects(QObject *object) +void tweakObjects(QObject *object) { QObjectList objectList; allSubObject(object, objectList); @@ -754,53 +720,49 @@ void ObjectNodeInstance::tweakObjects(QObject *object) } } -/*! - \brief Creates an instance of the qml type in the given qml context. - \throws InvalidArgumentException when the context argument is a null pointer - \throws InvalidMetaInfoException if the object is not valid - */ -QObject *ObjectNodeInstance::createInstance(const NodeMetaInfo &metaInfo, QDeclarativeContext *context) +QObject *createComponent(const QString &componentPath, QDeclarativeContext *context) { - if (!metaInfo.isValid()) { - qWarning() << "NodeMetaInfo is invalid"; - return 0; // maybe we should return a new QObject? - } + QDeclarativeComponent component(context->engine(), QUrl::fromLocalFile(componentPath)); + QDeclarativeContext *newContext = new QDeclarativeContext(context); + QObject *object = component.beginCreate(newContext); + tweakObjects(object); + component.completeCreate(); + newContext->setParent(object); + + return object; +} +QObject *createPrimitive(const QString &typeName, int majorNumber, int minorNumber, QDeclarativeContext *context) +{ QObject *object = 0; - if (metaInfo.isComponent()) { - // qml component - // TODO: This is maybe expensive ... - QDeclarativeComponent component(context->engine(), QUrl::fromLocalFile(metaInfo.componentString())); - QDeclarativeContext *newContext = new QDeclarativeContext(context); - object = component.beginCreate(newContext); - component.completeCreate(); - newContext->setParent(object); + QDeclarativeType *type = QDeclarativeMetaType::qmlType(typeName.toUtf8(), majorNumber, minorNumber); + if (type) { + object = type->create(); } else { - // primitive - QDeclarativeType *type = QDeclarativeMetaType::qmlType(metaInfo.typeName().toAscii(), metaInfo.majorVersion(), metaInfo.minorVersion()); - if (type) { - object = type->create(); - } else { - qWarning() << "QuickDesigner: Cannot create an object of type" - << QString("%1 %2,%3").arg(metaInfo.typeName(), metaInfo.majorVersion(), metaInfo.minorVersion()) - << "- type isn't known to declarative meta type system"; - } - - if (object && context) - QDeclarativeEngine::setContextForObject(object, context); + qWarning() << "QuickDesigner: Cannot create an object of type" + << QString("%1 %2,%3").arg(typeName).arg(majorNumber).arg(minorNumber) + << "- type isn't known to declarative meta type system"; } - QDeclarativeEngine::setObjectOwnership(object, QDeclarativeEngine::CppOwnership); - tweakObjects(object); + if (object && context) + QDeclarativeEngine::setContextForObject(object, context); + return object; } -QObject* ObjectNodeInstance::createObject(const NodeMetaInfo &metaInfo, QDeclarativeContext *context) +QObject* ObjectNodeInstance::createObject(const QString &typeName, int majorNumber, int minorNumber, const QString &componentPath, QDeclarativeContext *context) { - QObject *object = createInstance(metaInfo, context); + QObject *object = 0; + if (componentPath.isEmpty()) { + object = createPrimitive(typeName, majorNumber, minorNumber, context); + } else { + object = createComponent(componentPath, context); + } + + QDeclarativeEngine::setObjectOwnership(object, QDeclarativeEngine::CppOwnership); if (object == 0) throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__); @@ -849,15 +811,15 @@ QDeclarativeContext *ObjectNodeInstance::context() const QDeclarativeContext *context = QDeclarativeEngine::contextForObject(object()); if (context) return context; - else if (nodeInstanceView()) - return nodeInstanceView()->engine()->rootContext(); + else if (nodeInstanceServer()) + return nodeInstanceServer()->engine()->rootContext(); return 0; } QDeclarativeEngine *ObjectNodeInstance::engine() const { - return nodeInstanceView()->engine(); + return nodeInstanceServer()->engine(); } void ObjectNodeInstance::paintUpdate() @@ -872,10 +834,15 @@ void ObjectNodeInstance::deactivateState() { } -QStringList propertyNameForWritableProperties(QObject *object, const QString &baseName = QString()) +QStringList propertyNameForWritableProperties(QObject *object, const QString &baseName = QString(), QObjectList *inspectedObjects = new QObjectList()) { QStringList propertyNameList; + if (inspectedObjects->contains(object)) + return propertyNameList; + + inspectedObjects->append(object); + const QMetaObject *metaObject = object->metaObject(); for (int index = 0; index < metaObject->propertyCount(); ++index) { QMetaProperty metaProperty = metaObject->property(index); @@ -883,11 +850,11 @@ QStringList propertyNameForWritableProperties(QObject *object, const QString &ba if (declarativeProperty.isValid() && declarativeProperty.isWritable() && declarativeProperty.propertyTypeCategory() == QDeclarativeProperty::Object) { QObject *childObject = QDeclarativeMetaType::toQObject(declarativeProperty.read()); if (childObject) - propertyNameList.append(propertyNameForWritableProperties(childObject, baseName + QString::fromUtf8(metaProperty.name()) + '.')); + propertyNameList.append(propertyNameForWritableProperties(childObject, baseName + QString::fromUtf8(metaProperty.name()) + '.', inspectedObjects)); } else if (QDeclarativeValueTypeFactory::valueType(metaProperty.userType())) { QDeclarativeValueType *valueType = QDeclarativeValueTypeFactory::valueType(metaProperty.userType()); valueType->setValue(metaProperty.read(object)); - propertyNameList.append(propertyNameForWritableProperties(valueType, baseName + QString::fromUtf8(metaProperty.name()) + '.')); + propertyNameList.append(propertyNameForWritableProperties(valueType, baseName + QString::fromUtf8(metaProperty.name()) + '.', inspectedObjects)); } else if (metaProperty.isReadable() && metaProperty.isWritable()) { propertyNameList.append(baseName + QString::fromUtf8(metaProperty.name())); } @@ -916,9 +883,9 @@ void ObjectNodeInstance::paint(QPainter * /*painter*/) { } -bool ObjectNodeInstance::isTopLevel() const +QImage ObjectNodeInstance::renderImage() const { - return false; + return QImage(); } QObject *ObjectNodeInstance::parent() const @@ -929,6 +896,31 @@ QObject *ObjectNodeInstance::parent() const return object()->parent(); } +QObject *parentObject(QObject *object) +{ + QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject*>(object); + if (graphicsObject) + return graphicsObject->parentObject(); + + return object->parent(); +} + +ObjectNodeInstance::Pointer ObjectNodeInstance::parentInstance() const +{ + QObject *parentHolder = parent(); + if (!nodeInstanceServer()) + return Pointer(); + + while (parentHolder) { + if (nodeInstanceServer()->hasInstanceForObject(parentHolder)) + return nodeInstanceServer()->instanceForObject(parentHolder).internalInstance(); + + parentHolder = parentObject(parentHolder); + } + + return Pointer(); +} + QRectF ObjectNodeInstance::boundingRect() const { return QRect(); @@ -962,13 +954,11 @@ static bool metaObjectHasNotPropertyName(NodeInstanceMetaObject *metaObject, con void ObjectNodeInstance::createDynamicProperty(const QString &name, const QString &/*typeName*/) { if (m_metaObject == 0) { - qWarning() << "dynamic properties are not supported for components"; + qWarning() << "ObjectNodeInstance.createDynamicProperty: No Metaobject."; return; } - - if (metaObjectHasNotPropertyName(m_metaObject, name)) - m_metaObject->createNewProperty(name); + m_metaObject->createNewProperty(name); } /** @@ -982,54 +972,36 @@ void ObjectNodeInstance::refreshBindings(QDeclarativeContext *context) context->setContextProperty(QString("__dummy_%1").arg(i++), true); } -bool ObjectNodeInstance::updateStateVariant(const NodeInstance &/*target*/, const QString &/*propertyName*/, const QVariant &/*value*/) +bool ObjectNodeInstance::updateStateVariant(const ObjectNodeInstance::Pointer &/*target*/, const QString &/*propertyName*/, const QVariant &/*value*/) { return false; } -bool ObjectNodeInstance::updateStateBinding(const NodeInstance &/*target*/, const QString &/*propertyName*/, const QString &/*expression*/) +bool ObjectNodeInstance::updateStateBinding(const ObjectNodeInstance::Pointer &/*target*/, const QString &/*propertyName*/, const QString &/*expression*/) { return false; } -bool ObjectNodeInstance::resetStateProperty(const NodeInstance &/*target*/, const QString &/*propertyName*/, const QVariant &/*resetValue*/) +bool ObjectNodeInstance::resetStateProperty(const ObjectNodeInstance::Pointer &/*target*/, const QString &/*propertyName*/, const QVariant &/*resetValue*/) { return false; } - -NodeInstance ObjectNodeInstance::nodeInstanceParentForObject(QObject *currentObject) const +void ObjectNodeInstance::doComponentComplete() { - if (!currentObject) //this should not happen! warning? - return NodeInstance(); - - if (nodeInstanceView()->hasInstanceForObject(currentObject)) - return nodeInstanceView()->instanceForObject(currentObject); - - //Maybe the object has been reparented inside a component and we - //do not keep track of the parent? - //In this case we iterate until we find a parent we keep track of, - //parent() gets 0 - QObject* parentObject; - QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject*>(currentObject); - if (graphicsObject) - parentObject = graphicsObject->parentItem()->toGraphicsObject(); - else - parentObject = currentObject->parent(); - - return nodeInstanceParentForObject(parentObject); } -void ObjectNodeInstance::doComponentComplete() +bool ObjectNodeInstance::isRootNodeInstance() const { - + return nodeInstanceServer()->rootNodeInstance().isWrappingThisObject(object()); } -void ObjectNodeInstance::renderPixmapNextPaint() +bool ObjectNodeInstance::isValid() const { - + return instanceId() >= 0 && object(); } + } } diff --git a/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.h b/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.h index aed1bd38a3..12e70ce42e 100644 --- a/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.h +++ b/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.h @@ -32,12 +32,10 @@ #include <QPainter> #include <QStyleOptionGraphicsItem> -#include "modelnode.h" #include <QSharedPointer> #include <QScopedPointer> #include <QWeakPointer> -#include <propertymetainfo.h> -#include <nodeinstanceview.h> +#include "nodeinstanceserver.h" #include "nodeinstancemetaobject.h" #include "nodeinstancesignalspy.h" @@ -52,6 +50,8 @@ QT_END_NAMESPACE namespace QmlDesigner { +class NodeInstanceServer; + namespace Internal { @@ -61,22 +61,6 @@ class GraphicsViewNodeInstance; class GraphicsSceneNodeInstance; class ProxyWidgetNodeInstance; class WidgetNodeInstance; -class QDeclarativeViewNodeInstance; - -class ChildrenChangeEventFilter : public QObject -{ - Q_OBJECT -public: - ChildrenChangeEventFilter(QObject *parent); - - -signals: - void childrenChanged(QObject *object); - -protected: - bool eventFilter(QObject *object, QEvent *event); - -}; class ObjectNodeInstance { @@ -89,32 +73,28 @@ public: void destroy(); //void setModelNode(const ModelNode &node); - static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped); + static Pointer create(QObject *objectToBeWrapped); + static QObject* createObject(const QString &typeName, int majorNumber, int minorNumber, const QString &componentPath, QDeclarativeContext *context); - ModelNode modelNode() const; - void setModelNode(const ModelNode &node); + void setInstanceId(qint32 id); + qint32 instanceId() const; - NodeInstanceView *nodeInstanceView() const; - void setNodeInstanceView(NodeInstanceView *view); + NodeInstanceServer *nodeInstanceServer() const; + void setNodeInstanceServer(NodeInstanceServer *server); virtual void initializePropertyWatcher(const Pointer &objectNodeInstance); virtual void paint(QPainter *painter); - - virtual bool isTopLevel() const; + virtual QImage renderImage() const; virtual QObject *parent() const; - virtual void reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty); + Pointer parentInstance() const; + + virtual void reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const QString &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const QString &newParentProperty); void setId(const QString &id); QString id() const; virtual bool isQmlGraphicsItem() const; - virtual bool isGraphicsScene() const; - virtual bool isGraphicsView() const; - virtual bool isGraphicsWidget() const; - virtual bool isProxyWidget() const; - virtual bool isWidget() const; - virtual bool isQDeclarativeView() const; virtual bool isGraphicsObject() const; virtual bool isTransition() const; virtual bool isPositioner() const; @@ -134,7 +114,7 @@ public: virtual int penWidth() const; virtual bool hasAnchor(const QString &name) const; - virtual QPair<QString, NodeInstance> anchor(const QString &name) const; + virtual QPair<QString, ServerNodeInstance> anchor(const QString &name) const; virtual bool isAnchoredBySibling() const; virtual bool isAnchoredByChildren() const; @@ -150,6 +130,8 @@ public: virtual void resetProperty(const QString &name); virtual void refreshProperty(const QString &name); virtual QString instanceType(const QString &name) const; + QStringList propertyNames() const; + void createDynamicProperty(const QString &name, const QString &typeName); void setDeleteHeldInstance(bool deleteInstance); @@ -172,32 +154,24 @@ public: bool isInPositioner() const; void setInPositioner(bool isInPositioner); - bool hasBindingForProperty(const QString &name) const; + bool hasBindingForProperty(const QString &name, bool *hasChanged = 0) const; QDeclarativeContext *context() const; QDeclarativeEngine *engine() const; - virtual bool updateStateVariant(const NodeInstance &target, const QString &propertyName, const QVariant &value); - virtual bool updateStateBinding(const NodeInstance &target, const QString &propertyName, const QString &expression); - virtual bool resetStateProperty(const NodeInstance &target, const QString &propertyName, const QVariant &resetValue); + virtual bool updateStateVariant(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QVariant &value); + virtual bool updateStateBinding(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QString &expression); + virtual bool resetStateProperty(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QVariant &resetValue); - static void tweakObjects(QObject *object); - - NodeInstance nodeInstanceParentForObject(QObject *currentObject) const; + bool isValid() const; + bool isRootNodeInstance() const; virtual void doComponentComplete(); - virtual void renderPixmapNextPaint(); protected: - static QObject *createInstance(const NodeMetaInfo &metaInfo, QDeclarativeContext *parentContext); - - static QObject* createObject(const NodeMetaInfo &metaInfo, QDeclarativeContext *context); - void doResetProperty(const QString &propertyName); - NodeInstance instanceForNode(const ModelNode &node, const QString &fullname); - void removeFromOldProperty(QObject *object, QObject *oldParent, const QString &oldParentProperty); void addToNewProperty(QObject *object, QObject *newParent, const QString &newParentProperty); void deleteObjectsInList(const QDeclarativeProperty &metaProperty); @@ -206,11 +180,13 @@ private: static void refreshBindings(QDeclarativeContext *context); QHash<QString, QVariant> m_resetValueHash; - QHash<QString, NodeInstance> m_modelAbstractPropertyHash; - ModelNode m_modelNode; + QHash<QString, ServerNodeInstance> m_modelAbstractPropertyHash; + mutable QHash<QString, bool> m_hasBindingHash; + qint32 m_instanceId; QString m_id; - QWeakPointer<NodeInstanceView> m_nodeInstanceView; + QWeakPointer<NodeInstanceServer> m_nodeInstanceServer; + QString m_parentProperty; bool m_deleteHeldInstance; QWeakPointer<QObject> m_object; NodeInstanceMetaObject *m_metaObject; diff --git a/src/plugins/qmldesigner/designercore/instances/pixmapchangedcommand.cpp b/src/plugins/qmldesigner/designercore/instances/pixmapchangedcommand.cpp new file mode 100644 index 0000000000..c0935e9ffa --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/pixmapchangedcommand.cpp @@ -0,0 +1,66 @@ +#include "pixmapchangedcommand.h" + +#include <QtDebug> + +#include <QVarLengthArray> + +namespace QmlDesigner { + +PixmapChangedCommand::PixmapChangedCommand() + : m_instanceId(-1) +{ +} + +PixmapChangedCommand::PixmapChangedCommand(qint32 instanceId, const QImage &image) + : m_image(image), m_instanceId(instanceId) +{ +} + +qint32 PixmapChangedCommand::instanceId() const +{ + return m_instanceId; +} + +QImage PixmapChangedCommand::renderImage() const +{ + return m_image; +} + +QDataStream &operator<<(QDataStream &out, const PixmapChangedCommand &command) +{ + out << command.instanceId(); + + const QImage image = command.renderImage(); + const QByteArray data(reinterpret_cast<const char*>(image.constBits()), image.byteCount()); + + out << qint32(image.bytesPerLine()); + out << image.size(); + out << qint32(image.format()); + out << qint32(image.byteCount()); + out.writeRawData(reinterpret_cast<const char*>(image.constBits()), image.byteCount()); + + return out; +} + +QDataStream &operator>>(QDataStream &in, PixmapChangedCommand &command) +{ + + qint32 byteSize; + qint32 bytesPerLine; + QSize imageSize; + qint32 format; + + in >> command.m_instanceId; + + in >> bytesPerLine; + in >> imageSize; + in >> format; + in >> byteSize; + + command.m_image = QImage(imageSize, QImage::Format(format)); + in.readRawData(reinterpret_cast<char*>(command.m_image.bits()), byteSize); + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/pixmapchangedcommand.h b/src/plugins/qmldesigner/designercore/instances/pixmapchangedcommand.h new file mode 100644 index 0000000000..f7d850f3bc --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/pixmapchangedcommand.h @@ -0,0 +1,31 @@ +#ifndef PIXMAPCHANGEDCOMMAND_H +#define PIXMAPCHANGEDCOMMAND_H + +#include <QMetaType> +#include <QImage> + +namespace QmlDesigner { + +class PixmapChangedCommand +{ + friend QDataStream &operator>>(QDataStream &in, PixmapChangedCommand &command); +public: + PixmapChangedCommand(); + PixmapChangedCommand(qint32 instanceId, const QImage &image); + + qint32 instanceId() const; + QImage renderImage() const; + +private: + QImage m_image; + qint32 m_instanceId; +}; + +QDataStream &operator<<(QDataStream &out, const PixmapChangedCommand &command); +QDataStream &operator>>(QDataStream &in, PixmapChangedCommand &command); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::PixmapChangedCommand); + +#endif // PIXMAPCHANGEDCOMMAND_H diff --git a/src/plugins/qmldesigner/designercore/instances/positionernodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/positionernodeinstance.cpp index ecc8ee3e8f..5d78b025b3 100644 --- a/src/plugins/qmldesigner/designercore/instances/positionernodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/positionernodeinstance.cpp @@ -5,8 +5,8 @@ namespace QmlDesigner { namespace Internal { -PositionerNodeInstance::PositionerNodeInstance(QDeclarativeBasePositioner *item, bool hasContent) - : QmlGraphicsItemNodeInstance(item, hasContent) +PositionerNodeInstance::PositionerNodeInstance(QDeclarativeBasePositioner *item) + : QmlGraphicsItemNodeInstance(item) { } @@ -36,26 +36,19 @@ void PositionerNodeInstance::setPropertyBinding(const QString &name, const QStri QmlGraphicsItemNodeInstance::setPropertyBinding(name, expression); } -PositionerNodeInstance::Pointer PositionerNodeInstance::create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped) -{ - QPair<QGraphicsObject*, bool> objectPair; - - if (objectToBeWrapped) - objectPair = qMakePair(qobject_cast<QGraphicsObject*>(objectToBeWrapped), false); - else - objectPair = GraphicsObjectNodeInstance::createGraphicsObject(metaInfo, context); - - QDeclarativeBasePositioner *positioner = dynamic_cast<QDeclarativeBasePositioner*>(objectPair.first); +PositionerNodeInstance::Pointer PositionerNodeInstance::create(QObject *object) +{ + QDeclarativeBasePositioner *positioner = qobject_cast<QDeclarativeBasePositioner*>(object); if (positioner == 0) throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__); - Pointer instance(new PositionerNodeInstance(positioner, objectPair.second)); + Pointer instance(new PositionerNodeInstance(positioner)); - static_cast<QDeclarativeParserStatus*>(positioner)->classBegin(); + instance->setHasContent(!positioner->flags().testFlag(QGraphicsItem::ItemHasNoContents)); + positioner->setFlag(QGraphicsItem::ItemHasNoContents, false); - if (objectToBeWrapped) - instance->setDeleteHeldInstance(false); // the object isn't owned + static_cast<QDeclarativeParserStatus*>(positioner)->classBegin(); instance->populateResetValueHash(); diff --git a/src/plugins/qmldesigner/designercore/instances/positionernodeinstance.h b/src/plugins/qmldesigner/designercore/instances/positionernodeinstance.h index 628b0d1607..5b6d6e2d41 100644 --- a/src/plugins/qmldesigner/designercore/instances/positionernodeinstance.h +++ b/src/plugins/qmldesigner/designercore/instances/positionernodeinstance.h @@ -16,7 +16,7 @@ public: typedef QSharedPointer<PositionerNodeInstance> Pointer; typedef QWeakPointer<PositionerNodeInstance> WeakPointer; - static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped); + static Pointer create(QObject *objectToBeWrapped); void setPropertyVariant(const QString &name, const QVariant &value); void setPropertyBinding(const QString &name, const QString &expression); @@ -27,7 +27,7 @@ public: protected: - PositionerNodeInstance(QDeclarativeBasePositioner *item, bool hasContent); + PositionerNodeInstance(QDeclarativeBasePositioner *item); }; } // namespace Internal diff --git a/src/plugins/qmldesigner/designercore/instances/propertyabstractcontainer.cpp b/src/plugins/qmldesigner/designercore/instances/propertyabstractcontainer.cpp new file mode 100644 index 0000000000..040cf5833c --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/propertyabstractcontainer.cpp @@ -0,0 +1,55 @@ +#include "propertyabstractcontainer.h" + +namespace QmlDesigner { + +PropertyAbstractContainer::PropertyAbstractContainer() + : m_instanceId(-1) +{ +} + +PropertyAbstractContainer::PropertyAbstractContainer(qint32 instanceId, const QString &name, const QString &dynamicTypeName) + : m_instanceId(instanceId), + m_name(name), + m_dynamicTypeName(dynamicTypeName) +{ +} + +qint32 PropertyAbstractContainer::instanceId() const +{ + return m_instanceId; +} + +QString PropertyAbstractContainer::name() const +{ + return m_name; +} + +bool PropertyAbstractContainer::isDynamic() const +{ + return !m_dynamicTypeName.isEmpty(); +} + +QString PropertyAbstractContainer::dynamicTypeName() const +{ + return m_dynamicTypeName; +} + +QDataStream &operator<<(QDataStream &out, const PropertyAbstractContainer &container) +{ + out << container.instanceId(); + out << container.name(); + out << container.dynamicTypeName(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, PropertyAbstractContainer &container) +{ + in >> container.m_instanceId; + in >> container.m_name; + in >> container.m_dynamicTypeName; + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/propertybindingcontainer.cpp b/src/plugins/qmldesigner/designercore/instances/propertybindingcontainer.cpp new file mode 100644 index 0000000000..966ca22dce --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/propertybindingcontainer.cpp @@ -0,0 +1,64 @@ +#include "propertybindingcontainer.h" + + +namespace QmlDesigner { + +PropertyBindingContainer::PropertyBindingContainer() + : m_instanceId(-1) +{ +} + +PropertyBindingContainer::PropertyBindingContainer(qint32 instanceId, const QString &name, const QString &expression, const QString &dynamicTypeName) + : m_instanceId(instanceId), + m_name(name), + m_expression(expression), + m_dynamicTypeName(dynamicTypeName) +{ +} + +qint32 PropertyBindingContainer::instanceId() const +{ + return m_instanceId; +} + +QString PropertyBindingContainer::name() const +{ + return m_name; +} + +QString PropertyBindingContainer::expression() const +{ + return m_expression; +} + +bool PropertyBindingContainer::isDynamic() const +{ + return !m_dynamicTypeName.isEmpty(); +} + +QString PropertyBindingContainer::dynamicTypeName() const +{ + return m_dynamicTypeName; +} + +QDataStream &operator<<(QDataStream &out, const PropertyBindingContainer &container) +{ + out << container.instanceId(); + out << container.name(); + out << container.expression(); + out << container.dynamicTypeName(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, PropertyBindingContainer &container) +{ + in >> container.m_instanceId; + in >> container.m_name; + in >> container.m_expression; + in >> container.m_dynamicTypeName; + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/propertyvaluecontainer.cpp b/src/plugins/qmldesigner/designercore/instances/propertyvaluecontainer.cpp new file mode 100644 index 0000000000..640e32bfcd --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/propertyvaluecontainer.cpp @@ -0,0 +1,63 @@ +#include "propertyvaluecontainer.h" + +namespace QmlDesigner { + +PropertyValueContainer::PropertyValueContainer() + : m_instanceId(-1) +{ +} + +PropertyValueContainer::PropertyValueContainer(qint32 instanceId, const QString &name, const QVariant &value, const QString &dynamicTypeName) + : m_instanceId(instanceId), + m_name(name), + m_value(value), + m_dynamicTypeName(dynamicTypeName) +{ +} + +qint32 PropertyValueContainer::instanceId() const +{ + return m_instanceId; +} + +QString PropertyValueContainer::name() const +{ + return m_name; +} + +QVariant PropertyValueContainer::value() const +{ + return m_value; +} + +bool PropertyValueContainer::isDynamic() const +{ + return !m_dynamicTypeName.isEmpty(); +} + +QString PropertyValueContainer::dynamicTypeName() const +{ + return m_dynamicTypeName; +} + +QDataStream &operator<<(QDataStream &out, const PropertyValueContainer &container) +{ + out << container.instanceId(); + out << container.name(); + out << container.value(); + out << container.dynamicTypeName(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, PropertyValueContainer &container) +{ + in >> container.m_instanceId; + in >> container.m_name; + in >> container.m_value; + in >> container.m_dynamicTypeName; + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/proxywidgetnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/proxywidgetnodeinstance.cpp deleted file mode 100644 index ecb5ec5ae1..0000000000 --- a/src/plugins/qmldesigner/designercore/instances/proxywidgetnodeinstance.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#include "proxywidgetnodeinstance.h" - -#include <QGraphicsProxyWidget> -#include <private/qdeclarativemetatype_p.h> - -namespace QmlDesigner { -namespace Internal { - - -ProxyWidgetNodeInstance::ProxyWidgetNodeInstance(QGraphicsProxyWidget *widget) - : GraphicsWidgetNodeInstance(widget) -{ -} - - -ProxyWidgetNodeInstance::Pointer ProxyWidgetNodeInstance::create(const QString &typeName) -{ - QObject *object = QDeclarativeMetaType::qmlType(typeName.toLatin1(), 4, 7)->create(); - Q_ASSERT(object); - if (object == 0) - return Pointer(); - - QGraphicsProxyWidget* widget = qobject_cast<QGraphicsProxyWidget*>(object); - Q_ASSERT(widget); - if (widget == 0) - return Pointer(); - - return Pointer(new ProxyWidgetNodeInstance(widget)); -} - -QGraphicsProxyWidget* ProxyWidgetNodeInstance::proxyWidget() const -{ - QGraphicsProxyWidget* proxyWidget = qobject_cast<QGraphicsProxyWidget*>(graphicsWidget()); - Q_ASSERT(proxyWidget); - - return proxyWidget; -} - - -void ProxyWidgetNodeInstance::setWidget(QWidget *widget) -{ - proxyWidget()->setWidget(widget); -} - -bool ProxyWidgetNodeInstance::isProxyWidget() const -{ - return true; -} - - -} -} diff --git a/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.cpp index f126192612..9fe268dafe 100644 --- a/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.cpp @@ -28,9 +28,6 @@ **************************************************************************/ #include "qmlgraphicsitemnodeinstance.h" -#include "qmlviewnodeinstance.h" -#include "graphicsscenenodeinstance.h" - #include <invalidnodeinstanceexception.h> #include <propertymetainfo.h> @@ -55,8 +52,8 @@ namespace QmlDesigner { namespace Internal { -QmlGraphicsItemNodeInstance::QmlGraphicsItemNodeInstance(QDeclarativeItem *item, bool hasContent) - : GraphicsObjectNodeInstance(item, hasContent), +QmlGraphicsItemNodeInstance::QmlGraphicsItemNodeInstance(QDeclarativeItem *item) + : GraphicsObjectNodeInstance(item), m_hasHeight(false), m_hasWidth(false), m_isResizable(true) @@ -67,30 +64,23 @@ QmlGraphicsItemNodeInstance::~QmlGraphicsItemNodeInstance() { } -QmlGraphicsItemNodeInstance::Pointer QmlGraphicsItemNodeInstance::create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped) +QmlGraphicsItemNodeInstance::Pointer QmlGraphicsItemNodeInstance::create(QObject *object) { - QPair<QGraphicsObject*, bool> objectPair; - - if (objectToBeWrapped) - objectPair = qMakePair(qobject_cast<QGraphicsObject*>(objectToBeWrapped), false); - else - objectPair = GraphicsObjectNodeInstance::createGraphicsObject(metaInfo, context); - - QDeclarativeItem *qmlGraphicsItem = dynamic_cast<QDeclarativeItem*>(objectPair.first); + QDeclarativeItem *qmlGraphicsItem = dynamic_cast<QDeclarativeItem*>(object); if (qmlGraphicsItem == 0) throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__); - Pointer instance(new QmlGraphicsItemNodeInstance(qmlGraphicsItem, objectPair.second)); + Pointer instance(new QmlGraphicsItemNodeInstance(qmlGraphicsItem)); + + instance->setHasContent(!qmlGraphicsItem->flags().testFlag(QGraphicsItem::ItemHasNoContents)); + qmlGraphicsItem->setFlag(QGraphicsItem::ItemHasNoContents, false); if (qmlGraphicsItem->inherits("QDeclarativeText")) instance->setResizable(false); static_cast<QDeclarativeParserStatus*>(qmlGraphicsItem)->classBegin(); - if (objectToBeWrapped) - instance->setDeleteHeldInstance(false); // the object isn't owned - instance->populateResetValueHash(); return instance; @@ -103,88 +93,88 @@ bool QmlGraphicsItemNodeInstance::isQmlGraphicsItem() const QSizeF QmlGraphicsItemNodeInstance::size() const { - if (modelNode().isValid()) { - double implicitWidth = qmlGraphicsItem()->implicitWidth(); - if (!m_hasWidth - && implicitWidth // WORKAROUND - && implicitWidth != qmlGraphicsItem()->width() - && !modelNode().hasBindingProperty("width")) { - qmlGraphicsItem()->blockSignals(true); - qmlGraphicsItem()->setWidth(implicitWidth); - qmlGraphicsItem()->blockSignals(false); - } +// if (modelNode().isValid()) { +// double implicitWidth = qmlGraphicsItem()->implicitWidth(); +// if (!m_hasWidth +// && implicitWidth // WORKAROUND +// && implicitWidth != qmlGraphicsItem()->width() +// && !modelNode().hasBindingProperty("width")) { +// qmlGraphicsItem()->blockSignals(true); +// qmlGraphicsItem()->setWidth(implicitWidth); +// qmlGraphicsItem()->blockSignals(false); +// } - double implicitHeight = qmlGraphicsItem()->implicitHeight(); - if (!m_hasHeight - && implicitWidth // WORKAROUND - && implicitHeight != qmlGraphicsItem()->height() - && !modelNode().hasBindingProperty("height")) { - qmlGraphicsItem()->blockSignals(true); - qmlGraphicsItem()->setHeight(implicitHeight); - qmlGraphicsItem()->blockSignals(false); - } +// double implicitHeight = qmlGraphicsItem()->implicitHeight(); +// if (!m_hasHeight +// && implicitWidth // WORKAROUND +// && implicitHeight != qmlGraphicsItem()->height() +// && !modelNode().hasBindingProperty("height")) { +// qmlGraphicsItem()->blockSignals(true); +// qmlGraphicsItem()->setHeight(implicitHeight); +// qmlGraphicsItem()->blockSignals(false); +// } - } +// } - if (modelNode().isRootNode()) { - if (!m_hasWidth) { - qmlGraphicsItem()->blockSignals(true); - if (qmlGraphicsItem()->width() < 10.) - qmlGraphicsItem()->setWidth(100.); - qmlGraphicsItem()->blockSignals(false); - } +// if (modelNode().isRootNode()) { +// if (!m_hasWidth) { +// qmlGraphicsItem()->blockSignals(true); +// if (qmlGraphicsItem()->width() < 10.) +// qmlGraphicsItem()->setWidth(100.); +// qmlGraphicsItem()->blockSignals(false); +// } - if (!m_hasHeight) { - qmlGraphicsItem()->blockSignals(true); - if (qmlGraphicsItem()->height() < 10.) - qmlGraphicsItem()->setHeight(100.); - qmlGraphicsItem()->blockSignals(false); - } - } +// if (!m_hasHeight) { +// qmlGraphicsItem()->blockSignals(true); +// if (qmlGraphicsItem()->height() < 10.) +// qmlGraphicsItem()->setHeight(100.); +// qmlGraphicsItem()->blockSignals(false); +// } +// } return QSizeF(qmlGraphicsItem()->width(), qmlGraphicsItem()->height()); } QRectF QmlGraphicsItemNodeInstance::boundingRect() const { - if (modelNode().isValid()) { - double implicitWidth = qmlGraphicsItem()->implicitWidth(); - if (!m_hasWidth - && implicitWidth // WORKAROUND - && implicitWidth != qmlGraphicsItem()->width() - && !modelNode().hasBindingProperty("width")) { - qmlGraphicsItem()->blockSignals(true); - qmlGraphicsItem()->setWidth(implicitWidth); - qmlGraphicsItem()->blockSignals(false); - } +// if (modelNode().isValid()) { +// double implicitWidth = qmlGraphicsItem()->implicitWidth(); +// if (!m_hasWidth +// && implicitWidth // WORKAROUND +// && implicitWidth != qmlGraphicsItem()->width() +// && !modelNode().hasBindingProperty("width")) { +// qmlGraphicsItem()->blockSignals(true); +// qmlGraphicsItem()->setWidth(implicitWidth); +// qmlGraphicsItem()->blockSignals(false); +// } - double implicitHeight = qmlGraphicsItem()->implicitHeight(); - if (!m_hasHeight - && implicitHeight // WORKAROUND - && implicitHeight != qmlGraphicsItem()->height() - && !modelNode().hasBindingProperty("height")) { - qmlGraphicsItem()->blockSignals(true); - qmlGraphicsItem()->setHeight(implicitHeight); - qmlGraphicsItem()->blockSignals(false); - } +// double implicitHeight = qmlGraphicsItem()->implicitHeight(); +// if (!m_hasHeight +// && implicitHeight // WORKAROUND +// && implicitHeight != qmlGraphicsItem()->height() +// && !modelNode().hasBindingProperty("height")) { +// qmlGraphicsItem()->blockSignals(true); +// qmlGraphicsItem()->setHeight(implicitHeight); +// qmlGraphicsItem()->blockSignals(false); +// } - } +// } - if (modelNode().isRootNode()) { - if (!m_hasWidth) { - qmlGraphicsItem()->blockSignals(true); - if (qmlGraphicsItem()->width() < 10.) - qmlGraphicsItem()->setWidth(100.); - qmlGraphicsItem()->blockSignals(false); - } +// if (modelNode().isRootNode()) { +// if (!m_hasWidth) { +// qmlGraphicsItem()->blockSignals(true); +// if (qmlGraphicsItem()->width() < 10.) +// qmlGraphicsItem()->setWidth(100.); +// qmlGraphicsItem()->blockSignals(false); +// } - if (!m_hasHeight) { - qmlGraphicsItem()->blockSignals(true); - if (qmlGraphicsItem()->height() < 10.) - qmlGraphicsItem()->setHeight(100.); - qmlGraphicsItem()->blockSignals(false); - } - } +// if (!m_hasHeight) { +// qmlGraphicsItem()->blockSignals(true); +// if (qmlGraphicsItem()->height() < 10.) +// qmlGraphicsItem()->setHeight(100.); +// qmlGraphicsItem()->blockSignals(false); +// } +// } if (qmlGraphicsItem()) return qmlGraphicsItem()->boundingRect(); @@ -243,63 +233,68 @@ void QmlGraphicsItemNodeInstance::setPropertyBinding(const QString &name, const QVariant QmlGraphicsItemNodeInstance::property(const QString &name) const { - if (name == "width" && modelNode().isValid() && !modelNode().hasBindingProperty("width")) { - double implicitWidth = qmlGraphicsItem()->implicitWidth(); - if (!m_hasWidth - && implicitWidth // WORKAROUND - && implicitWidth != qmlGraphicsItem()->width()) { - qmlGraphicsItem()->blockSignals(true); - qmlGraphicsItem()->setWidth(implicitWidth); - qmlGraphicsItem()->blockSignals(false); - } - } +// if (name == "width" && modelNode().isValid() && !modelNode().hasBindingProperty("width")) { +// double implicitWidth = qmlGraphicsItem()->implicitWidth(); +// if (!m_hasWidth +// && implicitWidth // WORKAROUND +// && implicitWidth != qmlGraphicsItem()->width()) { +// qmlGraphicsItem()->blockSignals(true); +// qmlGraphicsItem()->setWidth(implicitWidth); +// qmlGraphicsItem()->blockSignals(false); +// } +// } - if (name == "height" && modelNode().isValid() && !modelNode().hasBindingProperty("height")) { - double implicitHeight = qmlGraphicsItem()->implicitHeight(); - if (!m_hasHeight - && implicitHeight // WORKAROUND - && implicitHeight != qmlGraphicsItem()->height()) { - qmlGraphicsItem()->blockSignals(true); - qmlGraphicsItem()->setHeight(implicitHeight); - qmlGraphicsItem()->blockSignals(false); - } - } +// if (name == "height" && modelNode().isValid() && !modelNode().hasBindingProperty("height")) { +// double implicitHeight = qmlGraphicsItem()->implicitHeight(); +// if (!m_hasHeight +// && implicitHeight // WORKAROUND +// && implicitHeight != qmlGraphicsItem()->height()) { +// qmlGraphicsItem()->blockSignals(true); +// qmlGraphicsItem()->setHeight(implicitHeight); +// qmlGraphicsItem()->blockSignals(false); +// } +// } return GraphicsObjectNodeInstance::property(name); } void QmlGraphicsItemNodeInstance::resetHorizontal() { - if (modelNode().hasBindingProperty("x")) - setPropertyBinding("x", modelNode().bindingProperty("x").expression()); - else if (modelNode().hasVariantProperty("x")) - setPropertyVariant("x", modelNode().variantProperty("x").value()); - else - setPropertyVariant("x", 0.0); - - if (modelNode().hasBindingProperty("width")) - setPropertyBinding("width", modelNode().bindingProperty("width").expression()); - else if (modelNode().hasVariantProperty("width")) - setPropertyVariant("width", modelNode().variantProperty("width").value()); - else - setPropertyVariant("width", qmlGraphicsItem()->implicitWidth()); + setPropertyVariant("x", 0.0); + setPropertyVariant("width", qmlGraphicsItem()->implicitWidth()); + +// if (modelNode().hasBindingProperty("x")) +// setPropertyBinding("x", modelNode().bindingProperty("x").expression()); +// else if (modelNode().hasVariantProperty("x")) +// setPropertyVariant("x", modelNode().variantProperty("x").value()); +// else +// setPropertyVariant("x", 0.0); + +// if (modelNode().hasBindingProperty("width")) +// setPropertyBinding("width", modelNode().bindingProperty("width").expression()); +// else if (modelNode().hasVariantProperty("width")) +// setPropertyVariant("width", modelNode().variantProperty("width").value()); +// else +// setPropertyVariant("width", qmlGraphicsItem()->implicitWidth()); } void QmlGraphicsItemNodeInstance::resetVertical() { - if (modelNode().hasBindingProperty("y")) - setPropertyBinding("y", modelNode().bindingProperty("y").expression()); - else if (modelNode().hasVariantProperty("y")) - setPropertyVariant("y", modelNode().variantProperty("y").value()); - else - setPropertyVariant("y", 0.0); - - if (modelNode().hasBindingProperty("height")) - setPropertyBinding("height", modelNode().bindingProperty("height").expression()); - else if (modelNode().hasVariantProperty("height")) - setPropertyVariant("height", modelNode().variantProperty("height").value()); - else - setPropertyVariant("height", qmlGraphicsItem()->implicitHeight()); + setPropertyVariant("y", 0.0); + setPropertyVariant("height", qmlGraphicsItem()->implicitHeight()); +// if (modelNode().hasBindingProperty("y")) +// setPropertyBinding("y", modelNode().bindingProperty("y").expression()); +// else if (modelNode().hasVariantProperty("y")) +// setPropertyVariant("y", modelNode().variantProperty("y").value()); +// else +// setPropertyVariant("y", 0.0); + +// if (modelNode().hasBindingProperty("height")) +// setPropertyBinding("height", modelNode().bindingProperty("height").expression()); +// else if (modelNode().hasVariantProperty("height")) +// setPropertyVariant("height", modelNode().variantProperty("height").value()); +// else +// setPropertyVariant("height", qmlGraphicsItem()->implicitHeight()); } static void repositioning(QDeclarativeItem *item) @@ -328,6 +323,8 @@ void QmlGraphicsItemNodeInstance::doComponentComplete() static_cast<QDeclarativeParserStatus*>(qmlGraphicsItem())->componentComplete(); QGraphicsItemPrivate::get(qmlGraphicsItem())->sendParentChangeNotification = 1; } + + graphicsObject()->update(); } bool QmlGraphicsItemNodeInstance::isResizable() const @@ -358,7 +355,6 @@ void QmlGraphicsItemNodeInstance::resetProperty(const QString &name) m_hasWidth = false; - GraphicsObjectNodeInstance::resetProperty(name); if (name == "anchors.fill") { anchors()->resetFill(); resetHorizontal(); @@ -389,18 +385,20 @@ void QmlGraphicsItemNodeInstance::resetProperty(const QString &name) anchors()->resetBaseline(); resetVertical(); } + + GraphicsObjectNodeInstance::resetProperty(name); } -void QmlGraphicsItemNodeInstance::reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty) +void QmlGraphicsItemNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const QString &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const QString &newParentProperty) { - if (oldParentInstance.isValid() && oldParentInstance.isPositioner()) { + if (oldParentInstance && oldParentInstance->isPositioner()) { setInPositioner(false); setMovable(true); } GraphicsObjectNodeInstance::reparent(oldParentInstance, oldParentProperty, newParentInstance, newParentProperty); - if (newParentInstance.isValid() && newParentInstance.isPositioner()) { + if (newParentInstance && newParentInstance->isPositioner()) { setInPositioner(true); setMovable(false); } @@ -408,120 +406,6 @@ void QmlGraphicsItemNodeInstance::reparent(const NodeInstance &oldParentInstance refresh(); } -//void QmlGraphicsItemNodeInstance::updateAnchors() -//{ -// NodeAnchors anchors(modelNode()); -// -// if (anchors.hasAnchor(AnchorLine::Top)) { -// AnchorLine anchorLine(anchors.anchor(AnchorLine::Top)); -// NodeInstance instance(nodeInstanceView()->instanceForNode(anchorLine.modelNode())); -// -// if (instance.isQmlGraphicsItem()) { -// Pointer qmlGraphicsItemInstance(instance.QmlGraphicsItemNodeInstance()); -// anchors()->setProperty("top", anchorLineFor(qmlGraphicsItemInstance->qmlGraphicsItem(), anchorLine)); -// } -// } else { -// if (anchors()->usedAnchors().testFlag(QDeclarativeAnchors::HasTopAnchor)) { -// anchors()->resetTop(); -// setPropertyValue("y", modelNode().property("y").value()); -// setPropertyValue("height", modelNode().property("height").value()); -// } -// } -// -// -// if (anchors.hasAnchor(AnchorLine::Left)) { -// AnchorLine anchorLine(anchors.anchor(AnchorLine::Left)); -// NodeInstance instance(nodeInstanceView()->instanceForNode(anchorLine.modelNode())); -// -// if (instance.isQmlGraphicsItem()) { -// Pointer qmlGraphicsItemInstance(instance.QmlGraphicsItemNodeInstance()); -// anchors()->setProperty("left", anchorLineFor(qmlGraphicsItemInstance->qmlGraphicsItem(), anchorLine)); -// } -// } else { -// if (anchors()->usedAnchors().testFlag(QDeclarativeAnchors::HasLeftAnchor)) { -// anchors()->resetLeft(); -// setPropertyValue("x", modelNode().property("x").value()); -// setPropertyValue("width", modelNode().property("width").value()); -// } -// } -// -// -// if (anchors.hasAnchor(AnchorLine::Right)) { -// AnchorLine anchorLine(anchors.anchor(AnchorLine::Right)); -// NodeInstance instance(nodeInstanceView()->instanceForNode(anchorLine.modelNode())); -// -// if (instance.isQmlGraphicsItem()) { -// Pointer qmlGraphicsItemInstance(instance.QmlGraphicsItemNodeInstance()); -// anchors()->setProperty("right", anchorLineFor(qmlGraphicsItemInstance->qmlGraphicsItem(), anchorLine)); -// } -// } else { -// if (anchors()->usedAnchors().testFlag(QDeclarativeAnchors::HasRightAnchor)) { -// anchors()->resetRight(); -// setPropertyValue("x", modelNode().property("x").value()); -// setPropertyValue("width", modelNode().property("width").value()); -// } -// } -// -// -// if (anchors.hasAnchor(AnchorLine::Bottom)) { -// AnchorLine anchorLine(anchors.anchor(AnchorLine::Bottom)); -// NodeInstance instance(nodeInstanceView()->instanceForNode(anchorLine.modelNode())); -// -// if (instance.isQmlGraphicsItem()) { -// Pointer qmlGraphicsItemInstance(instance.QmlGraphicsItemNodeInstance()); -// anchors()->setProperty("bottom", anchorLineFor(qmlGraphicsItemInstance->qmlGraphicsItem(), anchorLine)); -// } -// } else { -// if (anchors()->usedAnchors().testFlag(QDeclarativeAnchors::HasBottomAnchor)) { -// anchors()->resetBottom(); -// setPropertyValue("y", modelNode().property("y").value()); -// setPropertyValue("height", modelNode().property("height").value()); -// } -// } -// -// -// if (anchors.hasAnchor(AnchorLine::HorizontalCenter)) { -// AnchorLine anchorLine(anchors.anchor(AnchorLine::HorizontalCenter)); -// NodeInstance instance(nodeInstanceView()->instanceForNode(anchorLine.modelNode())); -// -// if (instance.isQmlGraphicsItem()) { -// Pointer qmlGraphicsItemInstance(instance.QmlGraphicsItemNodeInstance()); -// anchors()->setProperty("horizontalCenter", anchorLineFor(qmlGraphicsItemInstance->qmlGraphicsItem(), anchorLine)); -// } -// } else { -// if (anchors()->usedAnchors().testFlag(QDeclarativeAnchors::HasHCenterAnchor)) { -// anchors()->resetHorizontalCenter(); -// setPropertyValue("x", modelNode().property("x").value()); -// setPropertyValue("width", modelNode().property("width").value()); -// } -// } -// -// -// if (anchors.hasAnchor(AnchorLine::VerticalCenter)) { -// AnchorLine anchorLine(anchors.anchor(AnchorLine::VerticalCenter)); -// NodeInstance instance(nodeInstanceView()->instanceForNode(anchorLine.modelNode())); -// -// if (instance.isQmlGraphicsItem()) { -// Pointer qmlGraphicsItemInstance(instance.QmlGraphicsItemNodeInstance()); -// anchors()->setProperty("verticalCenter",anchorLineFor(qmlGraphicsItemInstance->qmlGraphicsItem(), anchorLine)); -// } -// } else { -// if (anchors()->usedAnchors().testFlag(QDeclarativeAnchors::HasVCenterAnchor)) { -// anchors()->resetVerticalCenter(); -// setPropertyValue("y", modelNode().property("y").value()); -// setPropertyValue("height", modelNode().property("height").value()); -// } -// } -// -// -// anchors()->setTopMargin(anchors.margin(AnchorLine::Top)); -// anchors()->setLeftMargin(anchors.margin(AnchorLine::Left)); -// anchors()->setBottomMargin(anchors.margin(AnchorLine::Bottom)); -// anchors()->setRightMargin(anchors.margin(AnchorLine::Right)); -// anchors()->setHorizontalCenterOffset(anchors.margin(AnchorLine::HorizontalCenter)); -// anchors()->setVerticalCenterOffset(anchors.margin(AnchorLine::VerticalCenter)); -//} - QDeclarativeAnchors::Anchor anchorLineFlagForName(const QString &name) { if (name == "anchors.top") @@ -580,7 +464,7 @@ bool isValidAnchorName(const QString &name) return anchorNameList.contains(name); } -QPair<QString, NodeInstance> QmlGraphicsItemNodeInstance::anchor(const QString &name) const +QPair<QString, ServerNodeInstance> QmlGraphicsItemNodeInstance::anchor(const QString &name) const { if (!isValidAnchorName(name) || !hasAnchor(name)) return GraphicsObjectNodeInstance::anchor(name); @@ -605,8 +489,8 @@ QPair<QString, NodeInstance> QmlGraphicsItemNodeInstance::anchor(const QString & } - if (targetObject && nodeInstanceView()->hasInstanceForObject(targetObject)) { - return qMakePair(targetName, nodeInstanceView()->instanceForObject(targetObject)); + if (targetObject && nodeInstanceServer()->hasInstanceForObject(targetObject)) { + return qMakePair(targetName, nodeInstanceServer()->instanceForObject(targetObject)); } else { return GraphicsObjectNodeInstance::anchor(name); } diff --git a/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.h b/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.h index 9aa68547e9..4fe2178ae4 100644 --- a/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.h +++ b/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.h @@ -46,7 +46,7 @@ public: ~QmlGraphicsItemNodeInstance(); - static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped); + static Pointer create(QObject *objectToBeWrapped); bool isQmlGraphicsItem() const; @@ -60,12 +60,12 @@ public: QVariant property(const QString &name) const; void resetProperty(const QString &name); - void reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty); + void reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const QString &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const QString &newParentProperty); int penWidth() const; bool hasAnchor(const QString &name) const; - QPair<QString, NodeInstance> anchor(const QString &name) const; + QPair<QString, ServerNodeInstance> anchor(const QString &name) const; bool isAnchoredBySibling() const; bool isAnchoredByChildren() const; void doComponentComplete(); @@ -74,7 +74,7 @@ public: void setResizable(bool resizeable); protected: - QmlGraphicsItemNodeInstance(QDeclarativeItem *item, bool hasContent); + QmlGraphicsItemNodeInstance(QDeclarativeItem *item); QDeclarativeItem *qmlGraphicsItem() const; QDeclarativeAnchors *anchors() const; void resetHorizontal(); diff --git a/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.cpp index 372a0cfd7d..2291d788f9 100644 --- a/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.cpp @@ -36,6 +36,8 @@ #include <metainfo.h> #include <QMutableListIterator> +#include "invalidnodeinstanceexception.h" + #include <private/qdeclarativestate_p_p.h> #include <private/qdeclarativepropertychanges_p.h> #include <private/qdeclarativeproperty_p.h> @@ -176,16 +178,17 @@ QmlPropertyChangesNodeInstance::QmlPropertyChangesNodeInstance(QDeclarativePrope { } -QmlPropertyChangesNodeInstance::Pointer - QmlPropertyChangesNodeInstance::create(const NodeMetaInfo & /*metaInfo*/, - QDeclarativeContext *context, - QObject *objectToBeWrapped) +QmlPropertyChangesNodeInstance::Pointer QmlPropertyChangesNodeInstance::create(QObject *object) { - Q_ASSERT(!objectToBeWrapped); + QDeclarativePropertyChanges *propertyChange = qobject_cast<QDeclarativePropertyChanges*>(object); + + if (propertyChange == 0) + throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__); + + Pointer instance(new QmlPropertyChangesNodeInstance(propertyChange)); + + instance->populateResetValueHash(); - QDeclarativePropertyChanges *object = new QDeclarativePropertyChanges; - QDeclarativeEngine::setContextForObject(object, context); - Pointer instance(new QmlPropertyChangesNodeInstance(object)); return instance; } @@ -198,8 +201,8 @@ void QmlPropertyChangesNodeInstance::setPropertyVariant(const QString &name, con } else { changesObject()->changeValue(name.toLatin1(), value); QObject *targetObject = changesObject()->object(); - if (targetObject && nodeInstanceView()->activeStateInstance().isWrappingThisObject(changesObject()->state())) { - NodeInstance targetInstance = nodeInstanceView()->instanceForObject(targetObject); + if (targetObject && nodeInstanceServer()->activeStateInstance().isWrappingThisObject(changesObject()->state())) { + ServerNodeInstance targetInstance = nodeInstanceServer()->instanceForObject(targetObject); targetInstance.setPropertyVariant(name, value); } } @@ -227,11 +230,11 @@ void QmlPropertyChangesNodeInstance::resetProperty(const QString &name) } -void QmlPropertyChangesNodeInstance::reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty) +void QmlPropertyChangesNodeInstance::reparent(const ServerNodeInstance &oldParentInstance, const QString &oldParentProperty, const ServerNodeInstance &newParentInstance, const QString &newParentProperty) { changesObject()->detachFromState(); - ObjectNodeInstance::reparent(oldParentInstance, oldParentProperty, newParentInstance, newParentProperty); + ObjectNodeInstance::reparent(oldParentInstance.internalInstance(), oldParentProperty, newParentInstance.internalInstance(), newParentProperty); changesObject()->attachToState(); } diff --git a/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.h b/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.h index dfd28a9fc6..683691fd5b 100644 --- a/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.h +++ b/src/plugins/qmldesigner/designercore/instances/qmlpropertychangesnodeinstance.h @@ -124,14 +124,14 @@ public: typedef QSharedPointer<QmlPropertyChangesNodeInstance> Pointer; typedef QWeakPointer<QmlPropertyChangesNodeInstance> WeakPointer; - static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped); + static Pointer create(QObject *objectToBeWrapped); virtual void setPropertyVariant(const QString &name, const QVariant &value); virtual void setPropertyBinding(const QString &name, const QString &expression); virtual QVariant property(const QString &name) const; virtual void resetProperty(const QString &name); - void reparent(const NodeInstance &oldParentInstance, const QString &oldParentProperty, const NodeInstance &newParentInstance, const QString &newParentProperty); + void reparent(const ServerNodeInstance &oldParentInstance, const QString &oldParentProperty, const ServerNodeInstance &newParentInstance, const QString &newParentProperty); protected: QmlPropertyChangesNodeInstance(QDeclarativePropertyChanges *object); diff --git a/src/plugins/qmldesigner/designercore/instances/qmlstatenodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/qmlstatenodeinstance.cpp index bab901f985..a9710a4c81 100644 --- a/src/plugins/qmldesigner/designercore/instances/qmlstatenodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/qmlstatenodeinstance.cpp @@ -35,6 +35,8 @@ #include "qmlpropertychangesnodeinstance.h" #include <private/qdeclarativestateoperations_p.h> +#include <invalidnodeinstanceexception.h> + namespace QmlDesigner { namespace Internal { @@ -50,14 +52,12 @@ QmlStateNodeInstance::QmlStateNodeInstance(QDeclarativeState *object) : } QmlStateNodeInstance::Pointer - QmlStateNodeInstance::create(const NodeMetaInfo &metaInfo, - QDeclarativeContext *context, - QObject *objectToBeWrapped) + QmlStateNodeInstance::create(QObject *object) { - Q_ASSERT(!objectToBeWrapped); - QObject *object = createObject(metaInfo, context); QDeclarativeState *stateObject = qobject_cast<QDeclarativeState*>(object); - Q_ASSERT(stateObject); + + if (stateObject == 0) + throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__); Pointer instance(new QmlStateNodeInstance(stateObject)); @@ -70,7 +70,7 @@ void QmlStateNodeInstance::activateState() { if (stateGroup()) { if (!isStateActive()) { - nodeInstanceView()->setStateInstance(nodeInstanceView()->instanceForNode(modelNode())); + nodeInstanceServer()->setStateInstance(nodeInstanceServer()->instanceForObject(object())); stateGroup()->setState(property("name").toString()); } } @@ -80,7 +80,7 @@ void QmlStateNodeInstance::deactivateState() { if (stateGroup()) { if (isStateActive()) { - nodeInstanceView()->clearStateInstance(); + nodeInstanceServer()->clearStateInstance(); stateGroup()->setState(QString()); } } @@ -100,14 +100,19 @@ QDeclarativeStateGroup *QmlStateNodeInstance::stateGroup() const bool QmlStateNodeInstance::isStateActive() const { + qDebug() << stateObject(); + qDebug() << stateGroup(); + if (stateGroup()) + qDebug() << "state name" << stateGroup()->state() << property("name"); return stateObject() && stateGroup() && stateGroup()->state() == property("name"); } void QmlStateNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) { - bool hasParent = modelNode().hasParentProperty(); - bool isStateOfTheRootModelNode = !hasParent || (hasParent && modelNode().parentProperty().parentModelNode().isRootNode()); - if (name == "when" && isStateOfTheRootModelNode) + qDebug() << __FUNCTION__ << stateObject() << name << value; + bool hasParent = parent(); + bool isStateOfTheRootModelNode = parentInstance() && parentInstance()->isRootNodeInstance(); + if (name == "when" && (!hasParent || isStateOfTheRootModelNode)) return; ObjectNodeInstance::setPropertyVariant(name, value); @@ -115,27 +120,27 @@ void QmlStateNodeInstance::setPropertyVariant(const QString &name, const QVarian void QmlStateNodeInstance::setPropertyBinding(const QString &name, const QString &expression) { - bool hasParent = modelNode().hasParentProperty(); - bool isStateOfTheRootModelNode = !hasParent || (hasParent && modelNode().parentProperty().parentModelNode().isRootNode()); - if (name == "when" && isStateOfTheRootModelNode) + bool hasParent = parent(); + bool isStateOfTheRootModelNode = parentInstance() && parentInstance()->isRootNodeInstance(); + if (name == "when" && (!hasParent || isStateOfTheRootModelNode)) return; ObjectNodeInstance::setPropertyBinding(name, expression); } -bool QmlStateNodeInstance::updateStateVariant(const NodeInstance &target, const QString &propertyName, const QVariant &value) +bool QmlStateNodeInstance::updateStateVariant(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QVariant &value) { - return stateObject()->changeValueInRevertList(target.internalObject(), propertyName.toLatin1(), value); + return stateObject()->changeValueInRevertList(target->object(), propertyName.toLatin1(), value); } -bool QmlStateNodeInstance::updateStateBinding(const NodeInstance &target, const QString &propertyName, const QString &expression) +bool QmlStateNodeInstance::updateStateBinding(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QString &expression) { - return stateObject()->changeValueInRevertList(target.internalObject(), propertyName.toLatin1(), expression); + return stateObject()->changeValueInRevertList(target->object(), propertyName.toLatin1(), expression); } -bool QmlStateNodeInstance::resetStateProperty(const NodeInstance &target, const QString &propertyName, const QVariant & /* resetValue */) +bool QmlStateNodeInstance::resetStateProperty(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QVariant & /* resetValue */) { - return stateObject()->removeEntryFromRevertList(target.internalObject(), propertyName.toLatin1()); + return stateObject()->removeEntryFromRevertList(target->object(), propertyName.toLatin1()); } } // namespace Internal diff --git a/src/plugins/qmldesigner/designercore/instances/qmlstatenodeinstance.h b/src/plugins/qmldesigner/designercore/instances/qmlstatenodeinstance.h index a3673e7b1f..8a27393c9e 100644 --- a/src/plugins/qmldesigner/designercore/instances/qmlstatenodeinstance.h +++ b/src/plugins/qmldesigner/designercore/instances/qmlstatenodeinstance.h @@ -47,7 +47,7 @@ public: typedef QSharedPointer<QmlStateNodeInstance> Pointer; typedef QWeakPointer<QmlStateNodeInstance> WeakPointer; - static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped); + static Pointer create(QObject *objectToBeWrapped); void setPropertyVariant(const QString &name, const QVariant &value); void setPropertyBinding(const QString &name, const QString &expression); @@ -55,9 +55,9 @@ public: void activateState(); void deactivateState(); - bool updateStateVariant(const NodeInstance &target, const QString &propertyName, const QVariant &value); - bool updateStateBinding(const NodeInstance &target, const QString &propertyName, const QString &expression); - bool resetStateProperty(const NodeInstance &target, const QString &propertyName, const QVariant &resetValue); + bool updateStateVariant(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QVariant &value); + bool updateStateBinding(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QString &expression); + bool resetStateProperty(const ObjectNodeInstance::Pointer &target, const QString &propertyName, const QVariant &resetValue); protected: diff --git a/src/plugins/qmldesigner/designercore/instances/qmltransitionnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/qmltransitionnodeinstance.cpp index e723f336cf..0a02983632 100644 --- a/src/plugins/qmldesigner/designercore/instances/qmltransitionnodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/qmltransitionnodeinstance.cpp @@ -40,23 +40,14 @@ QmlTransitionNodeInstance::QmlTransitionNodeInstance(QDeclarativeTransition *tra { } -QmlTransitionNodeInstance::Pointer QmlTransitionNodeInstance::create(const NodeMetaInfo &nodeMetaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped) +QmlTransitionNodeInstance::Pointer QmlTransitionNodeInstance::create(QObject *object) { - QObject *object = 0; - if (objectToBeWrapped) - object = objectToBeWrapped; - else - object = createObject(nodeMetaInfo, context); - QDeclarativeTransition *transition = qobject_cast<QDeclarativeTransition*>(object); if (transition == 0) throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__); Pointer instance(new QmlTransitionNodeInstance(transition)); - if (objectToBeWrapped) - instance->setDeleteHeldInstance(false); // the object isn't owned - instance->populateResetValueHash(); transition->setToState("invalidState"); diff --git a/src/plugins/qmldesigner/designercore/instances/qmltransitionnodeinstance.h b/src/plugins/qmldesigner/designercore/instances/qmltransitionnodeinstance.h index 5a4c0bb64c..7da1516f3f 100644 --- a/src/plugins/qmldesigner/designercore/instances/qmltransitionnodeinstance.h +++ b/src/plugins/qmldesigner/designercore/instances/qmltransitionnodeinstance.h @@ -45,7 +45,7 @@ public: typedef QSharedPointer<QmlTransitionNodeInstance> Pointer; typedef QWeakPointer<QmlTransitionNodeInstance> WeakPointer; - static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped); + static Pointer create(QObject *objectToBeWrapped); void setPropertyVariant(const QString &name, const QVariant &value); diff --git a/src/plugins/qmldesigner/designercore/instances/qmlviewnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/qmlviewnodeinstance.cpp deleted file mode 100644 index 516c4d6542..0000000000 --- a/src/plugins/qmldesigner/designercore/instances/qmlviewnodeinstance.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#include "qmlviewnodeinstance.h" - -#include <QDeclarativeView> -#include <QDeclarativeItem> - -#include <invalidnodeinstanceexception.h> - -namespace QmlDesigner { -namespace Internal { - -QDeclarativeViewNodeInstance::QDeclarativeViewNodeInstance(QDeclarativeView *view) - : GraphicsViewNodeInstance(view) -{ -} - - -QDeclarativeViewNodeInstance::Pointer QDeclarativeViewNodeInstance::create(const NodeMetaInfo &nodeMetaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped) -{ - QObject *object = 0; - if (objectToBeWrapped) - object = objectToBeWrapped; - else - createObject(nodeMetaInfo, context); - - QDeclarativeView* view = qobject_cast<QDeclarativeView*>(object); - if (view == 0) - throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__); - - Pointer instance(new QDeclarativeViewNodeInstance(view)); - - if (objectToBeWrapped) - instance->setDeleteHeldInstance(false); // the object isn't owned - - instance->populateResetValueHash(); - - return instance; -} - -QDeclarativeView* QDeclarativeViewNodeInstance::view() const -{ - QDeclarativeView* view = qobject_cast<QDeclarativeView*>(widget()); - Q_ASSERT(view); - return view; -} - -bool QDeclarativeViewNodeInstance::isQDeclarativeView() const -{ - return true; -} - -void QDeclarativeViewNodeInstance::addItem(QDeclarativeItem *item) -{ - QDeclarativeItem *rootItem = qobject_cast<QDeclarativeItem *>(view()->rootObject()); - Q_ASSERT_X(rootItem, Q_FUNC_INFO, "root item is QDeclarativeItem based"); - item->setParent(rootItem); -} - -} -} diff --git a/src/plugins/qmldesigner/designercore/instances/qmlviewnodeinstance.h b/src/plugins/qmldesigner/designercore/instances/qmlviewnodeinstance.h deleted file mode 100644 index b811305a47..0000000000 --- a/src/plugins/qmldesigner/designercore/instances/qmlviewnodeinstance.h +++ /dev/null @@ -1,62 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef QMLVIEWNODEINSTANCE_H -#define QMLVIEWNODEINSTANCE_H - -#include <QWeakPointer> -#include <QDeclarativeView> -#include <QDeclarativeItem> - -#include "graphicsviewnodeinstance.h" - -namespace QmlDesigner { -namespace Internal { - -class QDeclarativeViewNodeInstance : public GraphicsViewNodeInstance -{ -public: - typedef QSharedPointer<QDeclarativeViewNodeInstance> Pointer; - typedef QWeakPointer<QDeclarativeViewNodeInstance> WeakPointer; - - static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped); - - bool isQDeclarativeView() const; - - void addItem(QDeclarativeItem *item); - -protected: - QDeclarativeViewNodeInstance(QDeclarativeView *view); - - QDeclarativeView* view() const; -}; - -} -} -#endif // QMLVIEWNODEINSTANCE_H diff --git a/src/plugins/qmldesigner/designercore/instances/removeinstancescommand.cpp b/src/plugins/qmldesigner/designercore/instances/removeinstancescommand.cpp new file mode 100644 index 0000000000..e235365fee --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/removeinstancescommand.cpp @@ -0,0 +1,33 @@ +#include "removeinstancescommand.h" + +namespace QmlDesigner { + +RemoveInstancesCommand::RemoveInstancesCommand() +{ +} + +RemoveInstancesCommand::RemoveInstancesCommand(const QVector<qint32> &idVector) + : m_instanceIdVector(idVector) +{ +} + +QVector<qint32> RemoveInstancesCommand::instanceIds() const +{ + return m_instanceIdVector; +} + +QDataStream &operator<<(QDataStream &out, const RemoveInstancesCommand &command) +{ + out << command.instanceIds(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, RemoveInstancesCommand &command) +{ + in >> command.m_instanceIdVector; + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/removeinstancescommand.h b/src/plugins/qmldesigner/designercore/instances/removeinstancescommand.h new file mode 100644 index 0000000000..ee7db6b285 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/removeinstancescommand.h @@ -0,0 +1,32 @@ +#ifndef REMOVEINSTANCESCOMMAND_H +#define REMOVEINSTANCESCOMMAND_H + +#include <QMetaType> +#include <QVector> + +#include "instancecontainer.h" + +namespace QmlDesigner { + +class RemoveInstancesCommand +{ + friend QDataStream &operator>>(QDataStream &in, RemoveInstancesCommand &command); + +public: + RemoveInstancesCommand(); + RemoveInstancesCommand(const QVector<qint32> &idVector); + + QVector<qint32> instanceIds() const; + +private: + QVector<qint32> m_instanceIdVector; +}; + +QDataStream &operator<<(QDataStream &out, const RemoveInstancesCommand &command); +QDataStream &operator>>(QDataStream &in, RemoveInstancesCommand &command); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::RemoveInstancesCommand); + +#endif // REMOVEINSTANCESCOMMAND_H diff --git a/src/plugins/qmldesigner/designercore/instances/removepropertiescommand.cpp b/src/plugins/qmldesigner/designercore/instances/removepropertiescommand.cpp new file mode 100644 index 0000000000..08f687e61e --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/removepropertiescommand.cpp @@ -0,0 +1,33 @@ +#include "removepropertiescommand.h" + +namespace QmlDesigner { + +RemovePropertiesCommand::RemovePropertiesCommand() +{ +} + +RemovePropertiesCommand::RemovePropertiesCommand(const QVector<PropertyAbstractContainer> &properties) + : m_properties(properties) +{ +} + +QVector<PropertyAbstractContainer> RemovePropertiesCommand::properties() const +{ + return m_properties; +} + +QDataStream &operator<<(QDataStream &out, const RemovePropertiesCommand &command) +{ + out << command.properties(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, RemovePropertiesCommand &command) +{ + in >> command.m_properties; + + return in; +} + +} diff --git a/src/plugins/qmldesigner/designercore/instances/removepropertiescommand.h b/src/plugins/qmldesigner/designercore/instances/removepropertiescommand.h new file mode 100644 index 0000000000..122fb38f59 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/removepropertiescommand.h @@ -0,0 +1,31 @@ +#ifndef REMOVEPROPERTIESCOMMAND_H +#define REMOVEPROPERTIESCOMMAND_H + +#include <QMetaType> +#include <QVector> + +#include "propertyabstractcontainer.h" + +namespace QmlDesigner { + +class RemovePropertiesCommand +{ + friend QDataStream &operator>>(QDataStream &in, RemovePropertiesCommand &command); +public: + RemovePropertiesCommand(); + RemovePropertiesCommand(const QVector<PropertyAbstractContainer> &properties); + + QVector<PropertyAbstractContainer> properties() const; + +private: + QVector<PropertyAbstractContainer> m_properties; +}; + +QDataStream &operator<<(QDataStream &out, const RemovePropertiesCommand &command); +QDataStream &operator>>(QDataStream &in, RemovePropertiesCommand &command); + +} + +Q_DECLARE_METATYPE(QmlDesigner::RemovePropertiesCommand); + +#endif // REMOVEPROPERTIESCOMMAND_H diff --git a/src/plugins/qmldesigner/designercore/instances/reparentcontainer.cpp b/src/plugins/qmldesigner/designercore/instances/reparentcontainer.cpp new file mode 100644 index 0000000000..f422dfc53a --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/reparentcontainer.cpp @@ -0,0 +1,72 @@ +#include "reparentcontainer.h" + +namespace QmlDesigner { + +ReparentContainer::ReparentContainer() + : m_instanceId(-1), + m_oldParentInstanceId(-1), + m_newParentInstanceId(-1) +{ +} + +ReparentContainer::ReparentContainer(qint32 instanceId, + qint32 oldParentInstanceId, + const QString &oldParentProperty, + qint32 newParentInstanceId, + const QString &newParentProperty) + : m_instanceId(instanceId), + m_oldParentInstanceId(oldParentInstanceId), + m_oldParentProperty(oldParentProperty), + m_newParentInstanceId(newParentInstanceId), + m_newParentProperty(newParentProperty) +{ +} + +qint32 ReparentContainer::instanceId() const +{ + return m_instanceId; +} + +qint32 ReparentContainer::oldParentInstanceId() const +{ + return m_oldParentInstanceId; +} + +QString ReparentContainer::oldParentProperty() const +{ + return m_oldParentProperty; +} + +qint32 ReparentContainer::newParentInstanceId() const +{ + return m_newParentInstanceId; +} + +QString ReparentContainer::newParentProperty() const +{ + return m_newParentProperty; +} + +QDataStream &operator<<(QDataStream &out, const ReparentContainer &container) +{ + out << container.instanceId(); + out << container.oldParentInstanceId(); + out << container.oldParentProperty(); + out << container.newParentInstanceId(); + out << container.newParentProperty(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, ReparentContainer &container) +{ + in >> container.m_instanceId; + in >> container.m_oldParentInstanceId; + in >> container.m_oldParentProperty; + in >> container.m_newParentInstanceId; + in >> container.m_newParentProperty; + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/reparentcontainer.h b/src/plugins/qmldesigner/designercore/instances/reparentcontainer.h new file mode 100644 index 0000000000..2333751574 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/reparentcontainer.h @@ -0,0 +1,38 @@ +#ifndef REPARENTCONTAINER_H +#define REPARENTCONTAINER_H + +#include <qmetatype.h> + +namespace QmlDesigner { + +class ReparentContainer +{ + friend QDataStream &operator>>(QDataStream &in, ReparentContainer &container); +public: + ReparentContainer(); + ReparentContainer(qint32 instanceId, + qint32 oldParentInstanceId, + const QString &oldParentProperty, + qint32 newParentInstanceId, + const QString &newParentProperty); + + qint32 instanceId() const; + qint32 oldParentInstanceId() const; + QString oldParentProperty() const; + qint32 newParentInstanceId() const; + QString newParentProperty() const; + +private: + qint32 m_instanceId; + qint32 m_oldParentInstanceId; + QString m_oldParentProperty; + qint32 m_newParentInstanceId; + QString m_newParentProperty; +}; + +QDataStream &operator<<(QDataStream &out, const ReparentContainer &container); +QDataStream &operator>>(QDataStream &in, ReparentContainer &container); + +} // namespace QmlDesigner + +#endif // REPARENTCONTAINER_H diff --git a/src/plugins/qmldesigner/designercore/instances/reparentinstancescommand.cpp b/src/plugins/qmldesigner/designercore/instances/reparentinstancescommand.cpp new file mode 100644 index 0000000000..52393d8908 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/reparentinstancescommand.cpp @@ -0,0 +1,34 @@ +#include "reparentinstancescommand.h" + +namespace QmlDesigner { + +ReparentInstancesCommand::ReparentInstancesCommand() +{ +} + +ReparentInstancesCommand::ReparentInstancesCommand(const QVector<ReparentContainer> &container) + : m_reparentInstanceVector(container) +{ +} + +QVector<ReparentContainer> ReparentInstancesCommand::reparentInstances() const +{ + return m_reparentInstanceVector; +} + + +QDataStream &operator<<(QDataStream &out, const ReparentInstancesCommand &command) +{ + out << command.reparentInstances(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, ReparentInstancesCommand &command) +{ + in >> command.m_reparentInstanceVector; + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/reparentinstancescommand.h b/src/plugins/qmldesigner/designercore/instances/reparentinstancescommand.h new file mode 100644 index 0000000000..bae137b5cd --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/reparentinstancescommand.h @@ -0,0 +1,32 @@ +#ifndef REPARENTINSTANCESCOMMAND_H +#define REPARENTINSTANCESCOMMAND_H + +#include <QMetaType> +#include <QVector> + +#include "reparentcontainer.h" + +namespace QmlDesigner { + +class ReparentInstancesCommand +{ + friend QDataStream &operator>>(QDataStream &in, ReparentInstancesCommand &command); + +public: + ReparentInstancesCommand(); + ReparentInstancesCommand(const QVector<ReparentContainer> &container); + + QVector<ReparentContainer> reparentInstances() const; + +private: + QVector<ReparentContainer> m_reparentInstanceVector; +}; + +QDataStream &operator<<(QDataStream &out, const ReparentInstancesCommand &command); +QDataStream &operator>>(QDataStream &in, ReparentInstancesCommand &command); + +} // + +Q_DECLARE_METATYPE(QmlDesigner::ReparentInstancesCommand); + +#endif // REPARENTINSTANCESCOMMAND_H diff --git a/src/plugins/qmldesigner/designercore/instances/servernodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/servernodeinstance.cpp new file mode 100644 index 0000000000..c54ca1ac48 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/servernodeinstance.cpp @@ -0,0 +1,593 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ +#include "servernodeinstance.h" + +#include "objectnodeinstance.h" +#include "qmlgraphicsitemnodeinstance.h" +#include "dummynodeinstance.h" +#include "componentnodeinstance.h" +#include "qmltransitionnodeinstance.h" +#include "qmlpropertychangesnodeinstance.h" +#include "positionernodeinstance.h" +#include "behaviornodeinstance.h" +#include "qmlstatenodeinstance.h" + +#include "nodeinstanceserver.h" +#include "instancecontainer.h" + +#include <invalidnodeinstanceexception.h> + +#include <QHash> +#include <QSet> + +#include <QtDeclarative/QDeclarativeEngine> + +/*! + \class QmlDesigner::NodeInstance + \ingroup CoreInstance + \brief NodeInstance is a common handle for the actual object representation of a ModelNode. + + NodeInstance abstracts away the differences e.g. in terms of position and size + for QWidget, QGraphicsView, QLayout etc objects. Multiple NodeInstance objects can share + the pointer to the same instance object. The actual instance will be deleted when + the last NodeInstance object referencing to it is deleted. This can be disabled by + setDeleteHeldInstance(). + + \see QmlDesigner::NodeInstanceView +*/ + +namespace QmlDesigner { + +/*! +\brief Constructor - creates a invalid NodeInstance + + +\see NodeInstanceView +*/ +ServerNodeInstance::ServerNodeInstance() +{ +} + +/*! +\brief Destructor + +*/ +ServerNodeInstance::~ServerNodeInstance() +{ +} + +/*! +\brief Constructor - creates a valid NodeInstance + +*/ +ServerNodeInstance::ServerNodeInstance(const Internal::ObjectNodeInstance::Pointer &abstractInstance) + : m_nodeInstance(abstractInstance) +{ + +} + + +ServerNodeInstance::ServerNodeInstance(const ServerNodeInstance &other) + : m_nodeInstance(other.m_nodeInstance) +{ +} + +ServerNodeInstance &ServerNodeInstance::operator=(const ServerNodeInstance &other) +{ + m_nodeInstance = other.m_nodeInstance; + return *this; +} + +/*! +\brief Paints the NodeInstance with this painter. +\param painter used QPainter +*/ +void ServerNodeInstance::paint(QPainter *painter) +{ + m_nodeInstance->paint(painter); +} + +QImage ServerNodeInstance::renderImage() const +{ + return m_nodeInstance->renderImage(); +} + +bool ServerNodeInstance::isRootNodeInstance() const +{ + return isValid() && m_nodeInstance->isRootNodeInstance(); +} + +bool ServerNodeInstance::isSubclassOf(QObject *object, const QByteArray &superTypeName) +{ + if (object == 0) + return false; + + const QMetaObject *metaObject = object->metaObject(); + + while (metaObject) { + QDeclarativeType *qmlType = QDeclarativeMetaType::qmlType(metaObject); + if (qmlType && qmlType->qmlTypeName() == superTypeName) // ignore version numbers + return true; + + if (metaObject->className() == superTypeName) + return true; + + metaObject = metaObject->superClass(); + } + + return false; +} + +bool ServerNodeInstance::isSubclassOf(const QString &superTypeName) const +{ + return isSubclassOf(internalObject(), superTypeName.toUtf8()); +} + +/*! +\brief Creates a new NodeInstace for this NodeMetaInfo + +\param metaInfo MetaInfo for which a Instance should be created +\param context QDeclarativeContext which should be used +\returns Internal Pointer of a NodeInstance +\see NodeMetaInfo +*/ +Internal::ObjectNodeInstance::Pointer ServerNodeInstance::createInstance(QObject *objectToBeWrapped) +{ + Internal::ObjectNodeInstance::Pointer instance; + + if (objectToBeWrapped == 0) + instance = Internal::DummyNodeInstance::create(); + else if (isSubclassOf(objectToBeWrapped, "QtWebKit/WebView")) + instance = Internal::DummyNodeInstance::create(); + else if (isSubclassOf(objectToBeWrapped, "QDeclarativeBasePositioner")) + instance = Internal::PositionerNodeInstance::create(objectToBeWrapped); + else if (isSubclassOf(objectToBeWrapped, "Qt/Item")) + instance = Internal::QmlGraphicsItemNodeInstance::create(objectToBeWrapped); + else if (isSubclassOf(objectToBeWrapped, "Qt/Component")) + instance = Internal::ComponentNodeInstance::create(objectToBeWrapped); + else if (isSubclassOf(objectToBeWrapped, "Qt/PropertyChanges")) + instance = Internal::QmlPropertyChangesNodeInstance::create(objectToBeWrapped); + else if (isSubclassOf(objectToBeWrapped, "Qt/State")) + instance = Internal::QmlStateNodeInstance::create(objectToBeWrapped); + else if (isSubclassOf(objectToBeWrapped, "Qt/Transition")) + instance = Internal::QmlTransitionNodeInstance::create(objectToBeWrapped); + else if (isSubclassOf(objectToBeWrapped, "Qt/Behavior")) + instance = Internal::BehaviorNodeInstance::create(objectToBeWrapped); + else if (isSubclassOf(objectToBeWrapped, "Qt/QtObject")) + instance = Internal::ObjectNodeInstance::create(objectToBeWrapped); + else + instance = Internal::DummyNodeInstance::create(); + + + return instance; +} + +ServerNodeInstance ServerNodeInstance::create(NodeInstanceServer *nodeInstanceServer, const InstanceContainer &instanceContainer) +{ + Q_ASSERT(instanceContainer.instanceId() != -1); + Q_ASSERT(nodeInstanceServer); + + QDeclarativeContext *context = nodeInstanceServer->engine()->rootContext(); + + QObject *object = Internal::ObjectNodeInstance::createObject(instanceContainer.type(), instanceContainer.majorNumber(), instanceContainer.minorNumber(), instanceContainer.componentPath(), context); + + ServerNodeInstance instance(createInstance(object)); + + instance.internalInstance()->setInstanceId(instanceContainer.instanceId()); + + instance.internalInstance()->setNodeInstanceServer(nodeInstanceServer); + + instance.internalInstance()->initializePropertyWatcher(instance.m_nodeInstance); + + //QObject::connect(instance.internalObject(), SIGNAL(destroyed(QObject*)), nodeInstanceView, SLOT(removeIdFromContext(QObject*))); + + return instance; +} + + +void ServerNodeInstance::reparent(const ServerNodeInstance &oldParentInstance, const QString &oldParentProperty, const ServerNodeInstance &newParentInstance, const QString &newParentProperty) +{ + m_nodeInstance->reparent(oldParentInstance.m_nodeInstance, oldParentProperty, newParentInstance.m_nodeInstance, newParentProperty); +} + +/*! +\brief Returns the parent NodeInstance of this NodeInstance. + + If there is not parent than the parent is invalid. + +\returns Parent NodeInstance. +*/ +ServerNodeInstance ServerNodeInstance::parent() const +{ + return m_nodeInstance->parentInstance(); +} + +bool ServerNodeInstance::hasParent() const +{ + return m_nodeInstance->parent(); +} + +bool ServerNodeInstance::isValid() const +{ + return m_nodeInstance && m_nodeInstance->isValid(); +} + + +/*! +\brief Returns if the NodeInstance is a QGraphicsItem. +\returns true if this NodeInstance is a QGraphicsItem +*/ +bool ServerNodeInstance::equalGraphicsItem(QGraphicsItem *item) const +{ + return m_nodeInstance->equalGraphicsItem(item); +} + +/*! +\brief Returns the bounding rect of the NodeInstance. +\returns QRectF of the NodeInstance +*/ +QRectF ServerNodeInstance::boundingRect() const +{ + QRectF boundingRect(m_nodeInstance->boundingRect()); + +// +// if (modelNode().isValid()) { // TODO implement recursiv stuff +// if (qFuzzyIsNull(boundingRect.width())) +// boundingRect.setWidth(nodeState().property("width").value().toDouble()); +// +// if (qFuzzyIsNull(boundingRect.height())) +// boundingRect.setHeight(nodeState().property("height").value().toDouble()); +// } + + return boundingRect; +} + +void ServerNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) +{ + m_nodeInstance->setPropertyVariant(name, value); + +} + +void ServerNodeInstance::setPropertyDynamicVariant(const QString &name, const QString &typeName, const QVariant &value) +{ + m_nodeInstance->createDynamicProperty(name, typeName); + m_nodeInstance->setPropertyVariant(name, value); +} + +void ServerNodeInstance::setPropertyBinding(const QString &name, const QString &expression) +{ + m_nodeInstance->setPropertyBinding(name, expression); +} + +void ServerNodeInstance::setPropertyDynamicBinding(const QString &name, const QString &typeName, const QString &expression) +{ + m_nodeInstance->createDynamicProperty(name, typeName); + m_nodeInstance->setPropertyBinding(name, expression); +} + +void ServerNodeInstance::resetProperty(const QString &name) +{ + m_nodeInstance->resetProperty(name); +} + +void ServerNodeInstance::refreshProperty(const QString &name) +{ + m_nodeInstance->refreshProperty(name); +} + +void ServerNodeInstance::setId(const QString &id) +{ + m_nodeInstance->setId(id); +} + +/*! +\brief Returns the property value of the property of this NodeInstance. +\returns QVariant value +*/ +QVariant ServerNodeInstance::property(const QString &name) const +{ + return m_nodeInstance->property(name); +} + +QStringList ServerNodeInstance::propertyNames() const +{ + return m_nodeInstance->propertyNames(); +} + +bool ServerNodeInstance::hasBindingForProperty(const QString &name, bool *hasChanged) const +{ + return m_nodeInstance->hasBindingForProperty(name, hasChanged); +} + +/*! +\brief Returns the property default value of the property of this NodeInstance. +\returns QVariant default value which is the reset value to +*/ +QVariant ServerNodeInstance::defaultValue(const QString &name) const +{ + return m_nodeInstance->resetValue(name); +} + +/*! +\brief Returns the type of the property of this NodeInstance. +*/ +QString ServerNodeInstance::instanceType(const QString &name) const +{ + return m_nodeInstance->instanceType(name); +} + +void ServerNodeInstance::makeInvalid() +{ + if (m_nodeInstance) + m_nodeInstance->destroy(); + m_nodeInstance.clear(); +} + +bool ServerNodeInstance::hasContent() const +{ + return m_nodeInstance->hasContent(); +} + +bool ServerNodeInstance::isResizable() const +{ + return m_nodeInstance->isResizable(); +} + +bool ServerNodeInstance::isMovable() const +{ + return m_nodeInstance->isMovable(); +} + +bool ServerNodeInstance::isInPositioner() const +{ + return m_nodeInstance->isInPositioner(); +} + +bool ServerNodeInstance::hasAnchor(const QString &name) const +{ + return m_nodeInstance->hasAnchor(name); +} + +int ServerNodeInstance::penWidth() const +{ + return m_nodeInstance->penWidth(); +} + +bool ServerNodeInstance::isAnchoredBySibling() const +{ + return m_nodeInstance->isAnchoredBySibling(); +} + +bool ServerNodeInstance::isAnchoredByChildren() const +{ + return m_nodeInstance->isAnchoredByChildren(); +} + +QPair<QString, ServerNodeInstance> ServerNodeInstance::anchor(const QString &name) const +{ + return m_nodeInstance->anchor(name); +} + +QDebug operator<<(QDebug debug, const ServerNodeInstance &instance) +{ + if (instance.isValid()) { + debug.nospace() << "ServerNodeInstance(" + << instance.instanceId() << ", " + << instance.internalObject() << ", " + << instance.id() << ", " + << instance.parent() << ')'; + } else { + debug.nospace() << "ServerNodeInstance(invalid)"; + } + + return debug.space(); +} + +uint qHash(const ServerNodeInstance &instance) +{ + return ::qHash(instance.instanceId()); +} + +bool operator==(const ServerNodeInstance &first, const ServerNodeInstance &second) +{ + return first.instanceId() == second.instanceId(); +} + +bool ServerNodeInstance::isWrappingThisObject(QObject *object) const +{ + return internalObject() && internalObject() == object; +} + +/*! +\brief Returns the position in parent coordiantes. +\returns QPointF of the position of the instance. +*/ +QPointF ServerNodeInstance::position() const +{ + return m_nodeInstance->position(); +} + +/*! +\brief Returns the size in local coordiantes. +\returns QSizeF of the size of the instance. +*/ +QSizeF ServerNodeInstance::size() const +{ + QSizeF instanceSize = m_nodeInstance->size(); + + return instanceSize; +} + +QTransform ServerNodeInstance::transform() const +{ + return m_nodeInstance->transform(); +} + +/*! +\brief Returns the transform matrix of the instance. +\returns QTransform of the instance. +*/ +QTransform ServerNodeInstance::customTransform() const +{ + return m_nodeInstance->customTransform(); +} + +QTransform ServerNodeInstance::sceneTransform() const +{ + return m_nodeInstance->sceneTransform(); +} + +double ServerNodeInstance::rotation() const +{ + return m_nodeInstance->rotation(); +} + +double ServerNodeInstance::scale() const +{ + return m_nodeInstance->scale(); +} + +QList<QGraphicsTransform *> ServerNodeInstance::transformations() const +{ + return m_nodeInstance->transformations(); +} + +QPointF ServerNodeInstance::transformOriginPoint() const +{ + return m_nodeInstance->transformOriginPoint(); +} + +double ServerNodeInstance::zValue() const +{ + return m_nodeInstance->zValue(); +} + +/*! +\brief Returns the opacity of the instance. +\returns 0.0 mean transparent and 1.0 opaque. +*/ +double ServerNodeInstance::opacity() const +{ + return m_nodeInstance->opacity(); +} + + +void ServerNodeInstance::setDeleteHeldInstance(bool deleteInstance) +{ + m_nodeInstance->setDeleteHeldInstance(deleteInstance); +} + + +void ServerNodeInstance::paintUpdate() +{ + m_nodeInstance->paintUpdate(); +} + + +Internal::QmlGraphicsItemNodeInstance::Pointer ServerNodeInstance::qmlGraphicsItemNodeInstance() const +{ + return m_nodeInstance.dynamicCast<Internal::QmlGraphicsItemNodeInstance>(); +} + +QObject *ServerNodeInstance::internalObject() const +{ + if (m_nodeInstance.isNull()) + return 0; + + return m_nodeInstance->object(); +} + +void ServerNodeInstance::activateState() +{ + m_nodeInstance->activateState(); +} + +void ServerNodeInstance::deactivateState() +{ + m_nodeInstance->deactivateState(); +} + +bool ServerNodeInstance::updateStateVariant(const ServerNodeInstance &target, const QString &propertyName, const QVariant &value) +{ + return m_nodeInstance->updateStateVariant(target.internalInstance(), propertyName, value); +} + +bool ServerNodeInstance::updateStateBinding(const ServerNodeInstance &target, const QString &propertyName, const QString &expression) +{ + return m_nodeInstance->updateStateBinding(target.internalInstance(), propertyName, expression); +} + +QVariant ServerNodeInstance::resetVariant(const QString &propertyName) const +{ + return m_nodeInstance->resetValue(propertyName); +} + +bool ServerNodeInstance::resetStateProperty(const ServerNodeInstance &target, const QString &propertyName, const QVariant &resetValue) +{ + return m_nodeInstance->resetStateProperty(target.internalInstance(), propertyName, resetValue); +} + +/*! + Makes types used in node instances known to the Qml engine. To be called once at initialization time. +*/ +void ServerNodeInstance::registerDeclarativeTypes() +{ +// qmlRegisterType<QmlDesigner::Internal::QmlPropertyChangesObject>(); +} + +void ServerNodeInstance::doComponentComplete() +{ + m_nodeInstance->doComponentComplete(); +} + +QString ServerNodeInstance::id() const +{ + return m_nodeInstance->id(); +} + +qint32 ServerNodeInstance::instanceId() const +{ + if (isValid()) { + return m_nodeInstance->instanceId(); + } else { + return -1; + } +} + +QObject* ServerNodeInstance::testHandle() const +{ + return internalObject(); +} + +Internal::ObjectNodeInstance::Pointer ServerNodeInstance::internalInstance() const +{ + return m_nodeInstance; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/servernodeinstance.h b/src/plugins/qmldesigner/designercore/instances/servernodeinstance.h new file mode 100644 index 0000000000..51973e3a9b --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/servernodeinstance.h @@ -0,0 +1,191 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef SERVERNODEINSTANCE_H +#define SERVERNODEINSTANCE_H + +#include "corelib_global.h" +#include <QSharedPointer> +#include <QHash> +#include <QRectF> + +#include <nodeinstanceserverinterface.h> +#include <propertyvaluecontainer.h> + +QT_BEGIN_NAMESPACE +class QPainter; +class QStyleOptionGraphicsItem; +class QDeclarativeContext; +class QGraphicsItem; +class QGraphicsTransform; +QT_END_NAMESPACE + +namespace QmlDesigner { + +class NodeInstanceServer; +class InstanceContainer; + +namespace Internal { + class ObjectNodeInstance; + class QmlGraphicsItemNodeInstance; + class QmlPropertyChangesNodeInstance; + class GraphicsObjectNodeInstance; + class QmlStateNodeInstance; +} + +class CORESHARED_EXPORT ServerNodeInstance +{ + friend CORESHARED_EXPORT class NodeInstanceServer; + friend class QHash<qint32, ServerNodeInstance>; + friend CORESHARED_EXPORT uint qHash(const ServerNodeInstance &instance); + friend CORESHARED_EXPORT bool operator==(const ServerNodeInstance &first, const ServerNodeInstance &second); + friend CORESHARED_EXPORT QDebug operator<<(QDebug debug, const ServerNodeInstance &instance); + friend CORESHARED_EXPORT class NodeMetaInfo; + friend class QmlDesigner::Internal::QmlGraphicsItemNodeInstance; + friend class QmlDesigner::Internal::GraphicsObjectNodeInstance; + friend class QmlDesigner::Internal::ObjectNodeInstance; + friend class QmlDesigner::Internal::QmlPropertyChangesNodeInstance; + friend class QmlDesigner::Internal::QmlStateNodeInstance; + +public: + ServerNodeInstance(); + ~ServerNodeInstance(); + ServerNodeInstance(const ServerNodeInstance &other); + ServerNodeInstance& operator=(const ServerNodeInstance &other); + + void paint(QPainter *painter); + QImage renderImage() const; + + ServerNodeInstance parent() const; + bool hasParent() const; + + bool equalGraphicsItem(QGraphicsItem *item) const; + + QRectF boundingRect() const; + QPointF position() const; + QSizeF size() const; + QTransform transform() const; + QTransform customTransform() const; + QTransform sceneTransform() const; + double rotation() const; + double scale() const; + QList<QGraphicsTransform *> transformations() const; + QPointF transformOriginPoint() const; + double zValue() const; + + double opacity() const; + QVariant property(const QString &name) const; + QVariant defaultValue(const QString &name) const; + QString instanceType(const QString &name) const; + QStringList propertyNames() const; + + + bool hasBindingForProperty(const QString &name, bool *hasChanged = 0) const; + + bool isValid() const; + void makeInvalid(); + bool hasContent() const; + bool isResizable() const; + bool isMovable() const; + bool isInPositioner() const; + + bool isSubclassOf(const QString &superTypeName) const; + bool isRootNodeInstance() const; + + bool isWrappingThisObject(QObject *object) const; + + QVariant resetVariant(const QString &name) const; + + bool hasAnchor(const QString &name) const; + bool isAnchoredBySibling() const; + bool isAnchoredByChildren() const; + QPair<QString, ServerNodeInstance> anchor(const QString &name) const; + + int penWidth() const; + + static void registerDeclarativeTypes(); + + void doComponentComplete(); + + QString id() const; + qint32 instanceId() const; + + QObject* testHandle() const; + QSharedPointer<Internal::ObjectNodeInstance> internalInstance() const; + +private: // functions + ServerNodeInstance(const QSharedPointer<Internal::ObjectNodeInstance> &abstractInstance); + + void setPropertyVariant(const QString &name, const QVariant &value); + void setPropertyDynamicVariant(const QString &name, const QString &typeName, const QVariant &value); + + void setPropertyBinding(const QString &name, const QString &expression); + void setPropertyDynamicBinding(const QString &name, const QString &typeName, const QString &expression); + + void resetProperty(const QString &name); + void refreshProperty(const QString &name); + + void activateState(); + void deactivateState(); + void refreshState(); + + bool updateStateVariant(const ServerNodeInstance &target, const QString &propertyName, const QVariant &value); + bool updateStateBinding(const ServerNodeInstance &target, const QString &propertyName, const QString &expression); + bool resetStateProperty(const ServerNodeInstance &target, const QString &propertyName, const QVariant &resetValue); + + static ServerNodeInstance create(NodeInstanceServer *nodeInstanceServer, const InstanceContainer &instanceContainer); + + void setDeleteHeldInstance(bool deleteInstance); + void reparent(const ServerNodeInstance &oldParentInstance, const QString &oldParentProperty, const ServerNodeInstance &newParentInstance, const QString &newParentProperty); + + + void setId(const QString &id); + + static QSharedPointer<Internal::ObjectNodeInstance> createInstance(QObject *objectToBeWrapped); + QSharedPointer<Internal::QmlGraphicsItemNodeInstance> qmlGraphicsItemNodeInstance() const; + + void paintUpdate(); + + static bool isSubclassOf(QObject *object, const QByteArray &superTypeName); + + + QObject *internalObject() const; // should be not used outside of the nodeinstances!!!! + +private: // variables + QSharedPointer<Internal::ObjectNodeInstance> m_nodeInstance; +}; + +CORESHARED_EXPORT uint qHash(const ServerNodeInstance &instance); +CORESHARED_EXPORT bool operator==(const ServerNodeInstance &first, const ServerNodeInstance &second); +CORESHARED_EXPORT QDebug operator<<(QDebug debug, const ServerNodeInstance &instance); +} + +Q_DECLARE_METATYPE(QmlDesigner::ServerNodeInstance); + +#endif // SERVERNODEINSTANCE_H diff --git a/src/plugins/qmldesigner/designercore/instances/valueschangedcommand.cpp b/src/plugins/qmldesigner/designercore/instances/valueschangedcommand.cpp new file mode 100644 index 0000000000..996e167873 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/valueschangedcommand.cpp @@ -0,0 +1,33 @@ +#include "valueschangedcommand.h" + +namespace QmlDesigner { + +ValuesChangedCommand::ValuesChangedCommand() +{ +} + +ValuesChangedCommand::ValuesChangedCommand(const QVector<PropertyValueContainer> &valueChangeVector) + : m_valueChangeVector (valueChangeVector) +{ +} + +QVector<PropertyValueContainer> ValuesChangedCommand::valueChanges() const +{ + return m_valueChangeVector; +} + +QDataStream &operator<<(QDataStream &out, const ValuesChangedCommand &command) +{ + out << command.valueChanges(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, ValuesChangedCommand &command) +{ + in >> command.m_valueChangeVector; + + return in; +} + +} // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/valueschangedcommand.h b/src/plugins/qmldesigner/designercore/instances/valueschangedcommand.h new file mode 100644 index 0000000000..5730726101 --- /dev/null +++ b/src/plugins/qmldesigner/designercore/instances/valueschangedcommand.h @@ -0,0 +1,33 @@ +#ifndef VALUESCHANGEDCOMMAND_H +#define VALUESCHANGEDCOMMAND_H + +#include <QMetaType> +#include <QVector> + +#include "propertyvaluecontainer.h" + +namespace QmlDesigner { + +class ValuesChangedCommand +{ + friend QDataStream &operator>>(QDataStream &in, ValuesChangedCommand &command); + +public: + ValuesChangedCommand(); + ValuesChangedCommand(const QVector<PropertyValueContainer> &valueChangeVector); + + QVector<PropertyValueContainer> valueChanges() const; + +private: + QVector<PropertyValueContainer> m_valueChangeVector; +}; + +QDataStream &operator<<(QDataStream &out, const ValuesChangedCommand &command); +QDataStream &operator>>(QDataStream &in, ValuesChangedCommand &command); + +} // namespace QmlDesigner + +Q_DECLARE_METATYPE(QmlDesigner::ValuesChangedCommand); + + +#endif // VALUESCHANGEDCOMMAND_H diff --git a/src/plugins/qmldesigner/designercore/instances/widgetnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/widgetnodeinstance.cpp deleted file mode 100644 index ab61ee990b..0000000000 --- a/src/plugins/qmldesigner/designercore/instances/widgetnodeinstance.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#include "widgetnodeinstance.h" - -#include "proxywidgetnodeinstance.h" -#include <invalidnodeinstanceexception.h> - -#include <propertymetainfo.h> - -namespace QmlDesigner { -namespace Internal { - -WidgetNodeInstance::WidgetNodeInstance(QWidget* widget) - : ObjectNodeInstance(widget) -{ -} - -WidgetNodeInstance::~WidgetNodeInstance() -{ -} - -WidgetNodeInstance::Pointer WidgetNodeInstance::create(const NodeMetaInfo &nodeMetaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped) -{ - QObject *object = 0; - if (objectToBeWrapped) - object = objectToBeWrapped; - else - object = createObject(nodeMetaInfo, context); - - - QWidget* widget = qobject_cast<QWidget*>(object); - if (widget == 0) - throw InvalidNodeInstanceException(__LINE__, __FUNCTION__, __FILE__); - - Pointer instance(new WidgetNodeInstance(widget)); - - if (objectToBeWrapped) - instance->setDeleteHeldInstance(false); // the object isn't owned - - instance->populateResetValueHash(); - - return instance; -} - -void WidgetNodeInstance::paint(QPainter *painter) const -{ - Q_ASSERT(widget()); - - QWidget::RenderFlags flags; - if (!widget()->children().isEmpty()) - flags = QWidget::DrawChildren; - else - flags = 0; - - if (isTopLevel() && modelNode().isValid()) - widget()->render(painter, QPoint(), QRegion(), QWidget::DrawWindowBackground); - else - widget()->render(painter, QPoint(), QRegion(), flags); -} - -bool WidgetNodeInstance::isTopLevel() const -{ - Q_ASSERT(widget()); - return widget()->isTopLevel(); -} - -QWidget* WidgetNodeInstance::widget() const -{ - return static_cast<QWidget*>(object()); -} - -bool WidgetNodeInstance::isWidget() const -{ - return true; -} - -QRectF WidgetNodeInstance::boundingRect() const -{ - return widget()->frameGeometry(); -} - -void WidgetNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) -{ - if (name == "x") - widget()->move(value.toInt(), widget()->y()); - else if (name == "y") - widget()->move(widget()->x(), value.toInt()); - else if (name == "width") - widget()->resize(value.toInt(), widget()->height()); - else if (name == "height") - widget()->resize(widget()->width(), value.toInt()); - else { - widget()->setProperty(name.toLatin1(), value); - } - - widget()->update(); -} - -QVariant WidgetNodeInstance::property(const QString &name) const -{ - return widget()->property(name.toLatin1()); -} - -bool WidgetNodeInstance::isVisible() const -{ - return widget()->isVisible(); -} - -void WidgetNodeInstance::setVisible(bool isVisible) -{ - widget()->setVisible(isVisible); -} - -QPointF WidgetNodeInstance::position() const -{ - return widget()->pos(); -} - -QSizeF WidgetNodeInstance::size() const -{ - return widget()->size(); -} - -} -} diff --git a/src/plugins/qmldesigner/designercore/instances/widgetnodeinstance.h b/src/plugins/qmldesigner/designercore/instances/widgetnodeinstance.h deleted file mode 100644 index 377e367a94..0000000000 --- a/src/plugins/qmldesigner/designercore/instances/widgetnodeinstance.h +++ /dev/null @@ -1,75 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef WIDGETNODEINSTANCE_H -#define WIDGETNODEINSTANCE_H - -#include "objectnodeinstance.h" -#include <QWeakPointer> - -namespace QmlDesigner { -namespace Internal { - -class WidgetNodeInstance : public ObjectNodeInstance -{ -public: - ~WidgetNodeInstance(); - typedef QSharedPointer<WidgetNodeInstance> Pointer; - typedef QWeakPointer<WidgetNodeInstance> WeakPointer; - - static Pointer create(const NodeMetaInfo &metaInfo, QDeclarativeContext *context, QObject *objectToBeWrapped); - - void paint(QPainter *painter) const; - - bool isTopLevel() const; - - bool isWidget() const; - - QRectF boundingRect() const; - QPointF position() const; - QSizeF size() const; - - void setPropertyVariant(const QString &name, const QVariant &value); - QVariant property(const QString &name) const; - - bool isVisible() const; - void setVisible(bool isVisible); - - QWidget *widget() const; - - void updateProperties(); - -protected: - WidgetNodeInstance(QWidget* widget); - -}; - -} -} -#endif // WIDGETNODEINSTANCE_H diff --git a/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp b/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp index e679f27d70..6078b9438f 100644 --- a/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp +++ b/src/plugins/qmldesigner/designercore/metainfo/nodemetainfo.cpp @@ -30,7 +30,6 @@ #include "nodemetainfo.h" #include "model.h" #include "widgetqueryview.h" -#include "nodeinstance.h" #include "invalidargumentexception.h" #include "metainfo.h" diff --git a/src/plugins/qmldesigner/designercore/model/qmlanchors.cpp b/src/plugins/qmldesigner/designercore/model/qmlanchors.cpp index 57f5368641..e328d709df 100644 --- a/src/plugins/qmldesigner/designercore/model/qmlanchors.cpp +++ b/src/plugins/qmldesigner/designercore/model/qmlanchors.cpp @@ -310,10 +310,10 @@ AnchorLine::Type QmlAnchors::possibleAnchorLines(AnchorLine::Type sourceAnchorLi AnchorLine QmlAnchors::instanceAnchor(AnchorLine::Type sourceAnchorLine) const { - QPair<QString, NodeInstance> targetAnchorLinePair; + QPair<QString, qint32> targetAnchorLinePair; if (qmlItemNode().nodeInstance().hasAnchor("anchors.fill") && (sourceAnchorLine & AnchorLine::Fill)) { targetAnchorLinePair = qmlItemNode().nodeInstance().anchor("anchors.fill"); - targetAnchorLinePair.first = lineTypeToString(sourceAnchorLine); + targetAnchorLinePair.first = lineTypeToString(sourceAnchorLine); // TODO: looks wrong } else if (qmlItemNode().nodeInstance().hasAnchor("anchors.centerIn") && (sourceAnchorLine & AnchorLine::Center)) { targetAnchorLinePair = qmlItemNode().nodeInstance().anchor("anchors.centerIn"); targetAnchorLinePair.first = lineTypeToString(sourceAnchorLine); @@ -326,10 +326,10 @@ AnchorLine QmlAnchors::instanceAnchor(AnchorLine::Type sourceAnchorLine) const if (targetAnchorLine == AnchorLine::Invalid ) return AnchorLine(); - if (!targetAnchorLinePair.second.isValid()) //there might be no node instance for the parent + if (!targetAnchorLinePair.second >= 0) //there might be no node instance for the parent return AnchorLine(); - return AnchorLine(QmlItemNode(qmlItemNode().nodeForInstance(targetAnchorLinePair.second)), targetAnchorLine); + return AnchorLine(QmlItemNode(qmlItemNode().nodeForInstance(qmlItemNode().qmlModelView()->nodeInstanceView()->instanceForId(targetAnchorLinePair.second))), targetAnchorLine); } void QmlAnchors::removeAnchor(AnchorLine::Type sourceAnchorLine) diff --git a/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp b/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp index e237956988..dc86938dd3 100644 --- a/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp +++ b/src/plugins/qmldesigner/designercore/model/qmlobjectnode.cpp @@ -420,7 +420,7 @@ bool QmlObjectNode::hasNodeParent() const bool QmlObjectNode::hasInstanceParent() const { - return nodeInstance().hasParent(); + return nodeInstance().parentId() >= 0 && qmlModelView()->nodeInstanceView()->hasInstanceForId(nodeInstance().parentId()); } @@ -431,7 +431,10 @@ void QmlObjectNode::setParentProperty(const NodeAbstractProperty &parentProeprty QmlObjectNode QmlObjectNode::instanceParent() const { - return nodeForInstance(nodeInstance().parent()); + if (hasInstanceParent()) + return nodeForInstance(qmlModelView()->nodeInstanceView()->instanceForId(nodeInstance().parentId())); + + return QmlObjectNode(); } void QmlObjectNode::setId(const QString &id) diff --git a/src/plugins/qmldesigner/designercore/instances/proxywidgetnodeinstance.h b/src/tools/qmlpuppet/main.cpp index 4adcb11f6b..b483d948e0 100644 --- a/src/plugins/qmldesigner/designercore/instances/proxywidgetnodeinstance.h +++ b/src/tools/qmlpuppet/main.cpp @@ -27,33 +27,25 @@ ** **************************************************************************/ -#ifndef PROXYWIDGETNODEINSTANCE_H -#define PROXYWIDGETNODEINSTANCE_H +#include <QtDebug> +#include <QApplication> +#include <QStringList> -#include "graphicswidgetnodeinstance.h" +#include <nodeinstanceclientproxy.h> -namespace QmlDesigner { -namespace Internal { - -class ProxyWidgetNodeInstance : public GraphicsWidgetNodeInstance +int main(int argc, char *argv[]) { -public: - typedef QSharedPointer<ProxyWidgetNodeInstance> Pointer; - typedef QWeakPointer<ProxyWidgetNodeInstance> WeakPointer; - - static Pointer create(const QString &typeName); + QApplication application(argc, argv); - void setWidget(QWidget *widget); + if (application.arguments().count() != 2) + return -1; - bool isProxyWidget() const; + QCoreApplication::setOrganizationName("Nokia"); + QCoreApplication::setOrganizationDomain("nokia.com"); + QCoreApplication::setApplicationName("QmlPuppet"); -protected: - ProxyWidgetNodeInstance(QGraphicsProxyWidget *widget); + new QmlDesigner::NodeInstanceClientProxy(&application); - QGraphicsProxyWidget* proxyWidget() const; -}; - -} + return application.exec(); } -#endif // PROXYWIDGETNODEINSTANCE_H diff --git a/src/tools/qmlpuppet/qmlpuppet.pro b/src/tools/qmlpuppet/qmlpuppet.pro new file mode 100644 index 0000000000..a5ce001a42 --- /dev/null +++ b/src/tools/qmlpuppet/qmlpuppet.pro @@ -0,0 +1,19 @@ +TARGET = qmlpuppet + +TEMPLATE = app + +QT += core gui declarative network webkit + +DEFINES += QWEAKPOINTER_ENABLE_ARROW + +include(../../../qtcreator.pri) +include(../../private_headers.pri) +DESTDIR = $$IDE_BIN_PATH +include(../../rpath.pri) + +include (../../plugins/qmldesigner/designercore/instances/instances.pri) +include (../../plugins/qmldesigner/designercore/exceptions/exceptions.pri) + +CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/src/tools/tools.pro b/src/tools/tools.pro index 7ff51fb217..4d3423d541 100644 --- a/src/tools/tools.pro +++ b/src/tools/tools.pro @@ -2,6 +2,7 @@ TEMPLATE = subdirs win32:SUBDIRS = qtcdebugger SUBDIRS += qtpromaker +SUBDIRS = qmlpuppet QT_BREAKPAD_ROOT_PATH = $$(QT_BREAKPAD_ROOT_PATH) !isEmpty(QT_BREAKPAD_ROOT_PATH) { |