1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #include "servernodeinstance.h"
27 
28 #include "objectnodeinstance.h"
29 #include "dummynodeinstance.h"
30 #include "componentnodeinstance.h"
31 #include "qmltransitionnodeinstance.h"
32 #include "qmlpropertychangesnodeinstance.h"
33 #include "behaviornodeinstance.h"
34 #include "qmlstatenodeinstance.h"
35 #include "anchorchangesnodeinstance.h"
36 #include "positionernodeinstance.h"
37 #include "layoutnodeinstance.h"
38 #include "debugoutputcommand.h"
39 #include "qt3dpresentationnodeinstance.h"
40 
41 #include "quickitemnodeinstance.h"
42 #include "quick3dnodeinstance.h"
43 #include "quick3dtexturenodeinstance.h"
44 
45 #include "nodeinstanceserver.h"
46 #include "instancecontainer.h"
47 
48 #include <qmlprivategate.h>
49 
50 #include <QHash>
51 #include <QSet>
52 #include <QDebug>
53 #include <QQuickItem>
54 
55 #include <QQmlEngine>
56 
57 /*!
58   \class QmlDesigner::NodeInstance
59   \ingroup CoreInstance
60   \brief NodeInstance is a common handle for the actual object representation of a ModelNode.
61 
62    NodeInstance abstracts away the differences e.g. in terms of position and size
63    for QWidget, QGraphicsView, QLayout etc objects. Multiple NodeInstance objects can share
64    the pointer to the same instance object. The actual instance will be deleted when
65    the last NodeInstance object referencing to it is deleted. This can be disabled by
66    setDeleteHeldInstance().
67 
68    \see QmlDesigner::NodeInstanceView
69 */
70 
71 namespace QmlDesigner {
72 
73 /*!
74 \brief Constructor - creates a invalid NodeInstance
75 
76 
77 \see NodeInstanceView
78 */
ServerNodeInstance()79 ServerNodeInstance::ServerNodeInstance()
80 {
81 }
82 
83 /*!
84 \brief Destructor
85 
86 */
~ServerNodeInstance()87 ServerNodeInstance::~ServerNodeInstance()
88 {
89 }
90 
91 /*!
92 \brief Constructor - creates a valid NodeInstance
93 
94 */
ServerNodeInstance(const Internal::ObjectNodeInstance::Pointer & abstractInstance)95 ServerNodeInstance::ServerNodeInstance(const Internal::ObjectNodeInstance::Pointer &abstractInstance)
96   : m_nodeInstance(abstractInstance)
97 {
98 
99 }
100 
101 
ServerNodeInstance(const ServerNodeInstance & other)102 ServerNodeInstance::ServerNodeInstance(const ServerNodeInstance &other)
103   : m_nodeInstance(other.m_nodeInstance)
104 {
105 }
106 
operator =(const ServerNodeInstance & other)107 ServerNodeInstance &ServerNodeInstance::operator=(const ServerNodeInstance &other)
108 {
109     m_nodeInstance = other.m_nodeInstance;
110     return *this;
111 }
112 
renderImage() const113 QImage ServerNodeInstance::renderImage() const
114 {
115     return m_nodeInstance->renderImage();
116 }
117 
renderPreviewImage(const QSize & previewImageSize) const118 QImage ServerNodeInstance::renderPreviewImage(const QSize &previewImageSize) const
119 {
120     return m_nodeInstance->renderPreviewImage(previewImageSize);
121 }
122 
createGrabResult() const123 QSharedPointer<QQuickItemGrabResult> ServerNodeInstance::createGrabResult() const
124 {
125     return m_nodeInstance->createGrabResult();
126 }
127 
isRootNodeInstance() const128 bool ServerNodeInstance::isRootNodeInstance() const
129 {
130     return isValid() && m_nodeInstance->isRootNodeInstance();
131 }
132 
isSubclassOf(QObject * object,const QByteArray & superTypeName)133 bool ServerNodeInstance::isSubclassOf(QObject *object, const QByteArray &superTypeName)
134 {
135     return  Internal::QmlPrivateGate::isSubclassOf(object, superTypeName);
136 }
137 
setModifiedFlag(bool b)138 void ServerNodeInstance::setModifiedFlag(bool b)
139 {
140     m_nodeInstance->setModifiedFlag(b);
141 }
142 
setNodeSource(const QString & source)143 void ServerNodeInstance::setNodeSource(const QString &source)
144 {
145     m_nodeInstance->setNodeSource(source);
146 }
147 
holdsGraphical() const148 bool ServerNodeInstance::holdsGraphical() const
149 {
150     return m_nodeInstance->isQuickItem();
151 }
152 
updateDirtyNodeRecursive()153 void ServerNodeInstance::updateDirtyNodeRecursive()
154 {
155     m_nodeInstance->updateAllDirtyNodesRecursive();
156 }
157 
isSubclassOf(const QString & superTypeName) const158 bool ServerNodeInstance::isSubclassOf(const QString &superTypeName) const
159 {
160     return isSubclassOf(internalObject(), superTypeName.toUtf8());
161 }
162 
163 /*!
164 \brief Creates a new NodeInstace for this NodeMetaInfo
165 
166 \param metaInfo MetaInfo for which a Instance should be created
167 \param context QQmlContext which should be used
168 \returns Internal Pointer of a NodeInstance
169 \see NodeMetaInfo
170 */
createInstance(QObject * objectToBeWrapped)171 Internal::ObjectNodeInstance::Pointer ServerNodeInstance::createInstance(QObject *objectToBeWrapped)
172 {
173     Internal::ObjectNodeInstance::Pointer instance;
174 
175     if (objectToBeWrapped == nullptr)
176         instance = Internal::DummyNodeInstance::create();
177     else if (isSubclassOf(objectToBeWrapped, "Q3DSPresentationItem"))
178         instance = Internal::Qt3DPresentationNodeInstance::create(objectToBeWrapped);
179     else if (isSubclassOf(objectToBeWrapped, "QQuickBasePositioner"))
180         instance = Internal::PositionerNodeInstance::create(objectToBeWrapped);
181     else if (isSubclassOf(objectToBeWrapped, "QQuickLayout"))
182         instance = Internal::LayoutNodeInstance::create(objectToBeWrapped);
183     else if (isSubclassOf(objectToBeWrapped, "QQuickItem"))
184         instance = Internal::QuickItemNodeInstance::create(objectToBeWrapped);
185     else if (isSubclassOf(objectToBeWrapped, "QQuick3DTexture"))
186         instance = Internal::Quick3DTextureNodeInstance::create(objectToBeWrapped);
187     else if (isSubclassOf(objectToBeWrapped, "QQuick3DNode"))
188         instance = Internal::Quick3DNodeInstance::create(objectToBeWrapped);
189     else if (isSubclassOf(objectToBeWrapped, "QQmlComponent"))
190         instance = Internal::ComponentNodeInstance::create(objectToBeWrapped);
191     else if (objectToBeWrapped->inherits("QQmlAnchorChanges"))
192         instance = Internal::AnchorChangesNodeInstance::create(objectToBeWrapped);
193     else if (isSubclassOf(objectToBeWrapped, "QQuickPropertyChanges"))
194         instance = Internal::QmlPropertyChangesNodeInstance::create(objectToBeWrapped);
195     else if (isSubclassOf(objectToBeWrapped, "QQuickState"))
196         instance = Internal::QmlStateNodeInstance::create(objectToBeWrapped);
197     else if (isSubclassOf(objectToBeWrapped, "QQuickTransition"))
198         instance = Internal::QmlTransitionNodeInstance::create(objectToBeWrapped);
199     else if (isSubclassOf(objectToBeWrapped, "QQuickBehavior"))
200         instance = Internal::BehaviorNodeInstance::create(objectToBeWrapped);
201     else if (isSubclassOf(objectToBeWrapped, "QObject"))
202         instance = Internal::ObjectNodeInstance::create(objectToBeWrapped);
203     else
204         instance = Internal::DummyNodeInstance::create();
205 
206 
207     return instance;
208 }
209 
getErrorString(QQmlEngine * engine,const QString & componentPath)210 QString static getErrorString(QQmlEngine *engine, const QString &componentPath)
211 {
212     QQmlComponent component(engine, componentPath);
213 
214     QObject *o = component.create(nullptr);
215     delete o;
216     QString s;
217     for (const QQmlError &error : component.errors())
218         s.append(error.toString());
219     return s;
220 }
221 
isInPathList(const QStringList & pathList,const QString & componentPath)222 bool isInPathList(const QStringList &pathList, const QString &componentPath)
223 {
224     if (componentPath.indexOf("qml/QtQuick/Controls") > 0)
225         return true;
226 
227     return std::any_of(pathList.begin(), pathList.end(), [&](auto &&path) {
228         return componentPath.startsWith(path);
229     });
230 }
231 
create(NodeInstanceServer * nodeInstanceServer,const InstanceContainer & instanceContainer,ComponentWrap componentWrap)232 ServerNodeInstance ServerNodeInstance::create(NodeInstanceServer *nodeInstanceServer,
233                                               const InstanceContainer &instanceContainer,
234                                               ComponentWrap componentWrap)
235 {
236     Q_ASSERT(instanceContainer.instanceId() != -1);
237     Q_ASSERT(nodeInstanceServer);
238 
239     QObject *object = nullptr;
240     if (componentWrap == WrapAsComponent) {
241         object = Internal::ObjectNodeInstance::createComponentWrap(instanceContainer.nodeSource(), nodeInstanceServer->importCode(), nodeInstanceServer->context());
242     } else if (!instanceContainer.nodeSource().isEmpty()) {
243         object = Internal::ObjectNodeInstance::createCustomParserObject(instanceContainer.nodeSource(), nodeInstanceServer->importCode(), nodeInstanceServer->context());
244         if (object == nullptr)
245             nodeInstanceServer->sendDebugOutput(DebugOutputCommand::ErrorType, QLatin1String("Custom parser object could not be created."), instanceContainer.instanceId());
246     } else if (!instanceContainer.componentPath().isEmpty()
247                && !isInPathList(nodeInstanceServer->engine()->importPathList(),
248                                 instanceContainer.componentPath())) {
249         object = Internal::ObjectNodeInstance::createComponent(instanceContainer.componentPath(), nodeInstanceServer->context());
250         if (object == nullptr) {
251             object = Internal::ObjectNodeInstance::createPrimitive(QString::fromUtf8(instanceContainer.type()), instanceContainer.majorNumber(), instanceContainer.minorNumber(), nodeInstanceServer->context());
252             if (object == nullptr) {
253                 const QString errors = getErrorString(nodeInstanceServer->engine(), instanceContainer.componentPath());
254                 const QString message = QString("Component with path %1 could not be created.\n\n").arg(instanceContainer.componentPath());
255                 nodeInstanceServer->sendDebugOutput(DebugOutputCommand::ErrorType, message + errors, instanceContainer.instanceId());
256             }
257         }
258     } else {
259         object = Internal::ObjectNodeInstance::createPrimitive(QString::fromUtf8(instanceContainer.type()), instanceContainer.majorNumber(), instanceContainer.minorNumber(), nodeInstanceServer->context());
260         if (object == nullptr)
261             nodeInstanceServer->sendDebugOutput(DebugOutputCommand::ErrorType, QLatin1String("Item could not be created."), instanceContainer.instanceId());
262     }
263 
264     if (object == nullptr) {
265         if (instanceContainer.metaType() == InstanceContainer::ItemMetaType) { //If we cannot instanciate the object but we know it has to be an Ttem, we create an Item instead.
266             object = Internal::ObjectNodeInstance::createPrimitive("QtQuick/Item", 2, 0, nodeInstanceServer->context());
267 
268             if (object == nullptr)
269                 object = new QQuickItem;
270         } else {
271             object = Internal::ObjectNodeInstance::createPrimitive("QtQml/QtObject", 2, 0, nodeInstanceServer->context());
272         }
273    }
274 
275     Internal::QmlPrivateGate::getPropertyCache(object, nodeInstanceServer->engine());
276 
277     ServerNodeInstance instance(createInstance(object));
278 
279     instance.internalInstance()->setNodeInstanceServer(nodeInstanceServer);
280 
281     instance.internalInstance()->setInstanceId(instanceContainer.instanceId());
282 
283     instance.internalInstance()->initialize(instance.m_nodeInstance, instanceContainer.metaFlags());
284 
285     // Handle hidden state to initialize pickable state
286     nodeInstanceServer->handleInstanceHidden(instance, false, false);
287 
288     return instance;
289 }
290 
reparent(const ServerNodeInstance & oldParentInstance,const PropertyName & oldParentProperty,const ServerNodeInstance & newParentInstance,const PropertyName & newParentProperty)291 void ServerNodeInstance::reparent(const ServerNodeInstance &oldParentInstance, const PropertyName &oldParentProperty, const ServerNodeInstance &newParentInstance, const PropertyName &newParentProperty)
292 {
293     m_nodeInstance->reparent(oldParentInstance.m_nodeInstance, oldParentProperty, newParentInstance.m_nodeInstance, newParentProperty);
294 }
295 
296 /*!
297 \brief Returns the parent NodeInstance of this NodeInstance.
298 
299     If there is not parent than the parent is invalid.
300 
301 \returns Parent NodeInstance.
302 */
parent() const303 ServerNodeInstance ServerNodeInstance::parent() const
304 {
305     return m_nodeInstance->parentInstance();
306 }
307 
hasParent() const308 bool ServerNodeInstance::hasParent() const
309 {
310     return m_nodeInstance->parent();
311 }
312 
isValid() const313 bool ServerNodeInstance::isValid() const
314 {
315     return m_nodeInstance && m_nodeInstance->isValid();
316 }
317 
318 
319 /*!
320 \brief Returns if the NodeInstance is a QGraphicsItem.
321 \returns true if this NodeInstance is a QGraphicsItem
322 */
equalGraphicsItem(QGraphicsItem * item) const323 bool ServerNodeInstance::equalGraphicsItem(QGraphicsItem *item) const
324 {
325     return m_nodeInstance->equalGraphicsItem(item);
326 }
327 
328 /*!
329 \brief Returns the bounding rect of the NodeInstance.
330 \returns QRectF of the NodeInstance
331 */
boundingRect() const332 QRectF ServerNodeInstance::boundingRect() const
333 {
334     QRectF boundingRect(m_nodeInstance->boundingRect());
335 
336 //
337 //    if (modelNode().isValid()) { // TODO implement recursiv stuff
338 //        if (qFuzzyIsNull(boundingRect.width()))
339 //            boundingRect.setWidth(nodeState().property("width").value().toDouble());
340 //
341 //        if (qFuzzyIsNull(boundingRect.height()))
342 //            boundingRect.setHeight(nodeState().property("height").value().toDouble());
343 //    }
344 
345     return boundingRect;
346 }
347 
contentItemBoundingRect() const348 QRectF ServerNodeInstance::contentItemBoundingRect() const
349 {
350     return m_nodeInstance->contentItemBoundingBox();
351 }
352 
setPropertyVariant(const PropertyName & name,const QVariant & value)353 void ServerNodeInstance::setPropertyVariant(const PropertyName &name, const QVariant &value)
354 {
355     m_nodeInstance->setPropertyVariant(name, value);
356 
357 }
358 
setPropertyBinding(const PropertyName & name,const QString & expression)359 void ServerNodeInstance::setPropertyBinding(const PropertyName &name, const QString &expression)
360 {
361     m_nodeInstance->setPropertyBinding(name, expression);
362 }
363 
setHiddenInEditor(bool b)364 void ServerNodeInstance::setHiddenInEditor(bool b)
365 {
366     m_nodeInstance->setHiddenInEditor(b);
367     m_nodeInstance->nodeInstanceServer()->handleInstanceHidden(*this, b, true);
368 }
369 
setLockedInEditor(bool b)370 void ServerNodeInstance::setLockedInEditor(bool b)
371 {
372     m_nodeInstance->setLockedInEditor(b);
373     m_nodeInstance->nodeInstanceServer()->handleInstanceLocked(*this, b, true);
374 }
375 
resetProperty(const PropertyName & name)376 void ServerNodeInstance::resetProperty(const PropertyName &name)
377 {
378     m_nodeInstance->resetProperty(name);
379 }
380 
refreshProperty(const PropertyName & name)381 void ServerNodeInstance::refreshProperty(const PropertyName &name)
382 {
383     m_nodeInstance->refreshProperty(name);
384 }
385 
setId(const QString & id)386 void ServerNodeInstance::setId(const QString &id)
387 {
388     m_nodeInstance->setId(id);
389 }
390 
391 /*!
392 \brief Returns the property value of the property of this NodeInstance.
393 \returns QVariant value
394 */
property(const PropertyName & name) const395 QVariant ServerNodeInstance::property(const PropertyName &name) const
396 {
397     return m_nodeInstance->property(name);
398 }
399 
propertyNames() const400 PropertyNameList ServerNodeInstance::propertyNames() const
401 {
402     return m_nodeInstance->propertyNames();
403 }
404 
hasBindingForProperty(const PropertyName & name,bool * hasChanged) const405 bool ServerNodeInstance::hasBindingForProperty(const PropertyName &name, bool *hasChanged) const
406 {
407     return m_nodeInstance->hasBindingForProperty(name, hasChanged);
408 }
409 
410 /*!
411 \brief Returns the property default value of the property of this NodeInstance.
412 \returns QVariant default value which is the reset value to
413 */
defaultValue(const PropertyName & name) const414 QVariant ServerNodeInstance::defaultValue(const PropertyName &name) const
415 {
416     return m_nodeInstance->resetValue(name);
417 }
418 
419 /*!
420 \brief Returns the type of the property of this NodeInstance.
421 */
instanceType(const PropertyName & name) const422 QString ServerNodeInstance::instanceType(const PropertyName &name) const
423 {
424     return m_nodeInstance->instanceType(name);
425 }
426 
makeInvalid()427 void ServerNodeInstance::makeInvalid()
428 {
429     if (m_nodeInstance)
430         m_nodeInstance->destroy();
431     m_nodeInstance.clear();
432 }
433 
hasContent() const434 bool ServerNodeInstance::hasContent() const
435 {
436     return m_nodeInstance->hasContent();
437 }
438 
isResizable() const439 bool ServerNodeInstance::isResizable() const
440 {
441     return m_nodeInstance->isResizable();
442 }
443 
isMovable() const444 bool ServerNodeInstance::isMovable() const
445 {
446     return m_nodeInstance->isMovable();
447 }
448 
isInLayoutable() const449 bool ServerNodeInstance::isInLayoutable() const
450 {
451     return m_nodeInstance->isInLayoutable();
452 }
453 
hasAnchor(const PropertyName & name) const454 bool ServerNodeInstance::hasAnchor(const PropertyName &name) const
455 {
456     return m_nodeInstance->hasAnchor(name);
457 }
458 
penWidth() const459 int ServerNodeInstance::penWidth() const
460 {
461     return m_nodeInstance->penWidth();
462 }
463 
isAnchoredBySibling() const464 bool ServerNodeInstance::isAnchoredBySibling() const
465 {
466     return m_nodeInstance->isAnchoredBySibling();
467 }
468 
isAnchoredByChildren() const469 bool ServerNodeInstance::isAnchoredByChildren() const
470 {
471     return m_nodeInstance->isAnchoredByChildren();
472 }
473 
anchor(const PropertyName & name) const474 QPair<PropertyName, ServerNodeInstance> ServerNodeInstance::anchor(const PropertyName &name) const
475 {
476     return m_nodeInstance->anchor(name);
477 }
478 
operator <<(QDebug debug,const ServerNodeInstance & instance)479 QDebug operator <<(QDebug debug, const ServerNodeInstance &instance)
480 {
481     if (instance.isValid()) {
482         debug.nospace() << "ServerNodeInstance("
483                 << instance.instanceId() << ", "
484                 << instance.internalObject() << ", "
485                 << instance.id() << ", "
486                 << instance.parent() << ')';
487     } else {
488         debug.nospace() << "ServerNodeInstance(invalid)";
489     }
490 
491     return debug.space();
492 }
493 
qHash(const ServerNodeInstance & instance)494 uint qHash(const ServerNodeInstance &instance)
495 {
496     return ::qHash(instance.instanceId());
497 }
498 
operator ==(const ServerNodeInstance & first,const ServerNodeInstance & second)499 bool operator ==(const ServerNodeInstance &first, const ServerNodeInstance &second)
500 {
501     return first.instanceId() == second.instanceId();
502 }
503 
operator <(const ServerNodeInstance & first,const ServerNodeInstance & second)504 bool operator <(const ServerNodeInstance &first, const ServerNodeInstance &second)
505 {
506     return first.instanceId() < second.instanceId();
507 }
508 
509 
isWrappingThisObject(QObject * object) const510 bool ServerNodeInstance::isWrappingThisObject(QObject *object) const
511 {
512     return internalObject() && internalObject() == object;
513 }
514 
515 /*!
516 \brief Returns the position in parent coordiantes.
517 \returns QPointF of the position of the instance.
518 */
position() const519 QPointF ServerNodeInstance::position() const
520 {
521     return m_nodeInstance->position();
522 }
523 
524 /*!
525 \brief Returns the size in local coordiantes.
526 \returns QSizeF of the size of the instance.
527 */
size() const528 QSizeF ServerNodeInstance::size() const
529 {
530     QSizeF instanceSize = m_nodeInstance->size();
531 
532     return instanceSize;
533 }
534 
transform() const535 QTransform ServerNodeInstance::transform() const
536 {
537     return m_nodeInstance->transform();
538 }
539 
540 /*!
541 \brief Returns the transform matrix of the instance.
542 \returns QTransform of the instance.
543 */
customTransform() const544 QTransform ServerNodeInstance::customTransform() const
545 {
546     return m_nodeInstance->customTransform();
547 }
548 
sceneTransform() const549 QTransform ServerNodeInstance::sceneTransform() const
550 {
551     return m_nodeInstance->sceneTransform();
552 }
553 
contentTransform() const554 QTransform ServerNodeInstance::contentTransform() const
555 {
556     return m_nodeInstance->contentTransform();
557 }
558 
contentItemTransform() const559 QTransform ServerNodeInstance::contentItemTransform() const
560 {
561     return m_nodeInstance->contentItemTransform();
562 }
563 
rotation() const564 double ServerNodeInstance::rotation() const
565 {
566     return m_nodeInstance->rotation();
567 }
568 
scale() const569 double ServerNodeInstance::scale() const
570 {
571     return m_nodeInstance->scale();
572 }
573 
transformations() const574 QList<QGraphicsTransform *> ServerNodeInstance::transformations() const
575 {
576     return m_nodeInstance->transformations();
577 }
578 
transformOriginPoint() const579 QPointF ServerNodeInstance::transformOriginPoint() const
580 {
581     return m_nodeInstance->transformOriginPoint();
582 }
583 
zValue() const584 double ServerNodeInstance::zValue() const
585 {
586     return m_nodeInstance->zValue();
587 }
588 
589 /*!
590 \brief Returns the opacity of the instance.
591 \returns 0.0 mean transparent and 1.0 opaque.
592 */
opacity() const593 double ServerNodeInstance::opacity() const
594 {
595     return m_nodeInstance->opacity();
596 }
597 
598 
setDeleteHeldInstance(bool deleteInstance)599 void ServerNodeInstance::setDeleteHeldInstance(bool deleteInstance)
600 {
601     m_nodeInstance->setDeleteHeldInstance(deleteInstance);
602 }
603 
604 
paintUpdate()605 void ServerNodeInstance::paintUpdate()
606 {
607     m_nodeInstance->paintUpdate();
608 }
609 
internalObject() const610 QObject *ServerNodeInstance::internalObject() const
611 {
612     if (m_nodeInstance.isNull())
613         return nullptr;
614 
615     return m_nodeInstance->object();
616 }
617 
activateState()618 void ServerNodeInstance::activateState()
619 {
620     m_nodeInstance->activateState();
621 }
622 
deactivateState()623 void ServerNodeInstance::deactivateState()
624 {
625     m_nodeInstance->deactivateState();
626 }
627 
updateStateVariant(const ServerNodeInstance & target,const PropertyName & propertyName,const QVariant & value)628 bool ServerNodeInstance::updateStateVariant(const ServerNodeInstance &target, const PropertyName &propertyName, const QVariant &value)
629 {
630     return m_nodeInstance->updateStateVariant(target.internalInstance(), propertyName, value);
631 }
632 
updateStateBinding(const ServerNodeInstance & target,const PropertyName & propertyName,const QString & expression)633 bool ServerNodeInstance::updateStateBinding(const ServerNodeInstance &target, const PropertyName &propertyName, const QString &expression)
634 {
635     return m_nodeInstance->updateStateBinding(target.internalInstance(), propertyName, expression);
636 }
637 
resetVariant(const PropertyName & propertyName) const638 QVariant ServerNodeInstance::resetVariant(const PropertyName &propertyName) const
639 {
640     return m_nodeInstance->resetValue(propertyName);
641 }
642 
resetStateProperty(const ServerNodeInstance & target,const PropertyName & propertyName,const QVariant & resetValue)643 bool ServerNodeInstance::resetStateProperty(const ServerNodeInstance &target, const PropertyName &propertyName, const QVariant &resetValue)
644 {
645     return m_nodeInstance->resetStateProperty(target.internalInstance(), propertyName, resetValue);
646 }
647 
648 /*!
649  Makes types used in node instances known to the Qml engine. To be called once at initialization time.
650 */
registerQmlTypes()651 void ServerNodeInstance::registerQmlTypes()
652 {
653 //    qmlRegisterType<QmlDesigner::Internal::QmlPropertyChangesObject>();
654 }
655 
doComponentComplete()656 void ServerNodeInstance::doComponentComplete()
657 {
658     m_nodeInstance->doComponentComplete();
659 }
660 
childItems() const661 QList<ServerNodeInstance> ServerNodeInstance::childItems() const
662 {
663     return m_nodeInstance->childItems();
664 }
665 
rootQuickItem() const666 QQuickItem *ServerNodeInstance::rootQuickItem() const
667 {
668     return qobject_cast<QQuickItem*>(internalObject());
669 }
670 
allItemsRecursive() const671 QList<QQuickItem *> ServerNodeInstance::allItemsRecursive() const
672 {
673     return m_nodeInstance->allItemsRecursive();
674 }
675 
id() const676 QString ServerNodeInstance::id() const
677 {
678     if (isValid())
679         return m_nodeInstance->id();
680 
681     return {};
682 }
683 
instanceId() const684 qint32 ServerNodeInstance::instanceId() const
685 {
686     if (isValid())
687         return m_nodeInstance->instanceId();
688 
689     return -1;
690 }
691 
stateInstances() const692 QList<ServerNodeInstance> ServerNodeInstance::stateInstances() const
693 {
694     return m_nodeInstance->stateInstances();
695 }
696 
allStates() const697 QStringList ServerNodeInstance::allStates() const
698 {
699     if (isValid())
700         return m_nodeInstance->allStates();
701 
702     return {};
703 }
704 
internalInstance() const705 Internal::ObjectNodeInstance::Pointer ServerNodeInstance::internalInstance() const
706 {
707     return m_nodeInstance;
708 }
709 
710 } // namespace QmlDesigner
711