| 
									
										
										
										
											2012-11-06 15:35:19 +01:00
										 |  |  | /****************************************************************************
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2013-01-31 17:02:30 +01:00
										 |  |  | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2012-11-06 15:35:19 +01:00
										 |  |  | ** Contact: http://www.qt-project.org/legal
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-11-06 15:35:19 +01:00
										 |  |  | ** This file is part of Qt Creator. | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-11-06 15:35:19 +01:00
										 |  |  | ** Commercial License Usage | 
					
						
							|  |  |  | ** Licensees holding valid commercial Qt licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the commercial license agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							|  |  |  | ** a written agreement between you and Digia.  For licensing terms and | 
					
						
							|  |  |  | ** conditions see http://qt.digia.com/licensing.  For further information
 | 
					
						
							|  |  |  | ** use the contact form at http://qt.digia.com/contact-us.
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							| 
									
										
										
										
											2012-11-06 15:35:19 +01:00
										 |  |  | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
					
						
							|  |  |  | ** General Public License version 2.1 as published by the Free Software | 
					
						
							|  |  |  | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
					
						
							|  |  |  | ** packaging of this file.  Please review the following information to | 
					
						
							|  |  |  | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
					
						
							|  |  |  | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** In addition, as a special exception, Digia gives you certain additional | 
					
						
							|  |  |  | ** rights.  These rights are described in the Digia Qt LGPL Exception | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-11-06 15:35:19 +01:00
										 |  |  | ****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "objectnodeinstance.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QEvent>
 | 
					
						
							|  |  |  | #include <QQmlContext>
 | 
					
						
							|  |  |  | #include <QQmlError>
 | 
					
						
							|  |  |  | #include <QQmlEngine>
 | 
					
						
							|  |  |  | #include <QQmlProperty>
 | 
					
						
							|  |  |  | #include <QQmlComponent>
 | 
					
						
							|  |  |  | #include <QSharedPointer>
 | 
					
						
							|  |  |  | #include <QFileInfo>
 | 
					
						
							|  |  |  | #include <QFileSystemWatcher>
 | 
					
						
							|  |  |  | #include <QPixmapCache>
 | 
					
						
							| 
									
										
										
										
											2012-09-26 14:00:27 +02:00
										 |  |  | #include <QQuickItem>
 | 
					
						
							| 
									
										
										
										
											2013-04-23 18:45:26 +02:00
										 |  |  | #include <QQmlParserStatus>
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | #include <QTextDocument>
 | 
					
						
							|  |  |  | #include <QLibraryInfo>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <private/qqmlbinding_p.h>
 | 
					
						
							|  |  |  | #include <private/qqmlmetatype_p.h>
 | 
					
						
							|  |  |  | #include <private/qqmlvaluetype_p.h>
 | 
					
						
							|  |  |  | #include <private/qquicktransition_p.h>
 | 
					
						
							|  |  |  | #include <private/qquickanimation_p.h>
 | 
					
						
							| 
									
										
										
										
											2012-12-08 21:26:29 +02:00
										 |  |  | #include <private/qqmltimer_p.h>
 | 
					
						
							| 
									
										
										
										
											2012-09-27 15:40:23 +02:00
										 |  |  | #include <private/qqmlengine_p.h>
 | 
					
						
							| 
									
										
										
										
											2013-04-22 17:52:57 +02:00
										 |  |  | #include <designersupport.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | class ComponentCompleteDisabler | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | #if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
 | 
					
						
							|  |  |  |     ComponentCompleteDisabler() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DesignerSupport::disableComponentComplete(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ~ComponentCompleteDisabler() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DesignerSupport::enableComponentComplete(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |     ComponentCompleteDisabler() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     //nothing not available yet
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } //namespace
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-10 15:34:50 +02:00
										 |  |  | static bool isPropertyBlackListed(const QmlDesigner::PropertyName &propertyName) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (propertyName.contains(".") && propertyName.contains("__")) | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (propertyName.count(".") > 1) | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | namespace QmlDesigner { | 
					
						
							|  |  |  | namespace Internal { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ObjectNodeInstance::ObjectNodeInstance(QObject *object) | 
					
						
							| 
									
										
										
										
											2013-02-19 11:40:16 +01:00
										 |  |  |     : m_object(object), | 
					
						
							|  |  |  |       m_metaObject(0), | 
					
						
							|  |  |  |       m_instanceId(-1), | 
					
						
							|  |  |  |       m_deleteHeldInstance(true), | 
					
						
							| 
									
										
										
										
											2013-04-23 11:13:25 +02:00
										 |  |  |       m_isInLayoutable(false) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ObjectNodeInstance::~ObjectNodeInstance() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     destroy(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::destroy() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (deleteHeldInstance()) { | 
					
						
							|  |  |  |         // Remove from old property
 | 
					
						
							|  |  |  |         if (object()) { | 
					
						
							|  |  |  |             setId(QString()); | 
					
						
							|  |  |  |             if (m_instanceId >= 0) { | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  |                 reparent(parentInstance(), m_parentProperty, ObjectNodeInstance::Pointer(), PropertyName()); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (object()) { | 
					
						
							|  |  |  |             QObject *obj = object(); | 
					
						
							|  |  |  |             m_object.clear(); | 
					
						
							|  |  |  |             delete obj; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_metaObject = 0; | 
					
						
							|  |  |  |     m_instanceId = -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::setInstanceId(qint32 id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_instanceId = id; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qint32 ObjectNodeInstance::instanceId() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_instanceId; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NodeInstanceServer *ObjectNodeInstance::nodeInstanceServer() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_nodeInstanceServer.data(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::setNodeInstanceServer(NodeInstanceServer *server) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Q_ASSERT(!m_nodeInstanceServer.data()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_nodeInstanceServer = server; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::initializePropertyWatcher(const ObjectNodeInstance::Pointer &objectNodeInstance) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-23 14:39:18 +02:00
										 |  |  |     m_metaObject = NodeInstanceMetaObject::createNodeInstanceMetaObject(objectNodeInstance, nodeInstanceServer()->engine()); | 
					
						
							| 
									
										
										
										
											2013-05-21 13:00:19 +02:00
										 |  |  |     m_signalSpy.setObjectNodeInstance(objectNodeInstance); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::initialize(const ObjectNodeInstance::Pointer &objectNodeInstance) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     initializePropertyWatcher(objectNodeInstance); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::setId(const QString &id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!m_id.isEmpty() && context()) { | 
					
						
							|  |  |  |         context()->engine()->rootContext()->setContextProperty(m_id, 0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!id.isEmpty() && context()) { | 
					
						
							|  |  |  |         context()->engine()->rootContext()->setContextProperty(id, object()); // will also force refresh of all bindings
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_id = id; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString ObjectNodeInstance::id() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_id; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::isTransition() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::isPositioner() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-25 17:05:00 +02:00
										 |  |  | bool ObjectNodeInstance::isQuickItem() const | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-18 18:22:15 +02:00
										 |  |  | bool ObjectNodeInstance::isQuickWindow() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::isGraphical() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-18 18:42:58 +02:00
										 |  |  | bool ObjectNodeInstance::isLayoutable() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | bool ObjectNodeInstance::equalGraphicsItem(QGraphicsItem * /*item*/) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QTransform ObjectNodeInstance::transform() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QTransform(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-22 13:07:32 +02:00
										 |  |  | QTransform ObjectNodeInstance::contentTransform() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QTransform(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QTransform ObjectNodeInstance::customTransform() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QTransform(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-28 14:14:07 +02:00
										 |  |  | QTransform ObjectNodeInstance::contentItemTransform() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QTransform(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QTransform ObjectNodeInstance::sceneTransform() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QTransform(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | double ObjectNodeInstance::rotation() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return 0.0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | double ObjectNodeInstance::scale() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return 1.0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QList<QGraphicsTransform *> ObjectNodeInstance::transformations() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QList<QGraphicsTransform *> transformationsList; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return transformationsList; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QPointF ObjectNodeInstance::transformOriginPoint() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QPoint(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | double ObjectNodeInstance::zValue() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return 0.0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | double ObjectNodeInstance::opacity() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return 1.0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | bool ObjectNodeInstance::hasAnchor(const PropertyName &/*name*/) const | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::isAnchoredBySibling() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::isAnchoredByChildren() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | QPair<PropertyName, ServerNodeInstance> ObjectNodeInstance::anchor(const PropertyName &/*name*/) const | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  |     return qMakePair(PropertyName(), ServerNodeInstance()); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static bool isList(const QQmlProperty &property) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return property.propertyTypeCategory() == QQmlProperty::List; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static bool isObject(const QQmlProperty &property) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return (property.propertyTypeCategory() == QQmlProperty::Object) || | 
					
						
							|  |  |  |             //QVariant can also store QObjects. Lets trust our model.
 | 
					
						
							|  |  |  |            (QLatin1String(property.propertyTypeName()) == QLatin1String("QVariant")); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static QVariant objectToVariant(QObject *object) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QVariant::fromValue(object); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static bool hasFullImplementedListInterface(const QQmlListReference &list) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return list.isValid() && list.canCount() && list.canAt() && list.canAppend() && list.canClear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void removeObjectFromList(const QQmlProperty &property, QObject *objectToBeRemoved, QQmlEngine * engine) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  |     QQmlListReference listReference(property.object(), property.name().toUtf8(), engine); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (!hasFullImplementedListInterface(listReference)) { | 
					
						
							|  |  |  |         qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!"; | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int count = listReference.count(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QObjectList objectList; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int i = 0; i < count; i ++) { | 
					
						
							|  |  |  |         QObject *listItem = listReference.at(i); | 
					
						
							|  |  |  |         if (listItem && listItem != objectToBeRemoved) | 
					
						
							|  |  |  |             objectList.append(listItem); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     listReference.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     foreach (QObject *object, objectList) | 
					
						
							|  |  |  |         listReference.append(object); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | void ObjectNodeInstance::removeFromOldProperty(QObject *object, QObject *oldParent, const PropertyName &oldParentProperty) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     QQmlProperty property(oldParent, oldParentProperty, context()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!property.isValid()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (isList(property)) { | 
					
						
							|  |  |  |         removeObjectFromList(property, object, nodeInstanceServer()->engine()); | 
					
						
							|  |  |  |     } else if (isObject(property)) { | 
					
						
							|  |  |  |         if (nodeInstanceServer()->hasInstanceForObject(oldParent)) { | 
					
						
							|  |  |  |             nodeInstanceServer()->instanceForObject(oldParent).resetProperty(oldParentProperty); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (object && object->parent()) | 
					
						
							|  |  |  |         object->setParent(0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | void ObjectNodeInstance::addToNewProperty(QObject *object, QObject *newParent, const PropertyName &newParentProperty) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     QQmlProperty property(newParent, newParentProperty, context()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-30 12:40:01 +02:00
										 |  |  |     if (object) | 
					
						
							|  |  |  |         object->setParent(newParent); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     if (isList(property)) { | 
					
						
							|  |  |  |         QQmlListReference list = qvariant_cast<QQmlListReference>(property.read()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!hasFullImplementedListInterface(list)) { | 
					
						
							|  |  |  |             qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!"; | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         list.append(object); | 
					
						
							|  |  |  |     } else if (isObject(property)) { | 
					
						
							|  |  |  |         property.write(objectToVariant(object)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Q_ASSERT(objectToVariant(object).isValid()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | void ObjectNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const PropertyName &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const PropertyName &newParentProperty) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (oldParentInstance) { | 
					
						
							|  |  |  |         removeFromOldProperty(object(), oldParentInstance->object(), oldParentProperty); | 
					
						
							|  |  |  |         m_parentProperty.clear(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (newParentInstance) { | 
					
						
							|  |  |  |         m_parentProperty = newParentProperty; | 
					
						
							|  |  |  |         addToNewProperty(object(), newParentInstance->object(), newParentProperty); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | QVariant ObjectNodeInstance::convertSpecialCharacter(const QVariant& value) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QVariant specialCharacterConvertedValue = value; | 
					
						
							|  |  |  |     if (value.type() == QVariant::String) { | 
					
						
							|  |  |  |         QString string = value.toString(); | 
					
						
							|  |  |  |         string.replace(QLatin1String("\\n"), QLatin1String("\n")); | 
					
						
							|  |  |  |         string.replace(QLatin1String("\\t"), QLatin1String("\t")); | 
					
						
							|  |  |  |         specialCharacterConvertedValue = string; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return specialCharacterConvertedValue; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QVariant ObjectNodeInstance::fixResourcePaths(const QVariant &value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (value.type() == QVariant::Url) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         const QUrl url = value.toUrl(); | 
					
						
							|  |  |  |         if (url.scheme() == QLatin1String("qrc")) { | 
					
						
							|  |  |  |             const QString path = QLatin1String("qrc:") +  url.path(); | 
					
						
							|  |  |  |             QString qrcSearchPath = qgetenv("QMLDESIGNER_RC_PATHS"); | 
					
						
							|  |  |  |             if (!qrcSearchPath.isEmpty()) { | 
					
						
							|  |  |  |                 const QStringList searchPaths = qrcSearchPath.split(QLatin1Char(';')); | 
					
						
							|  |  |  |                 foreach (const QString &qrcPath, searchPaths) { | 
					
						
							|  |  |  |                     const QStringList qrcDefintion = qrcPath.split(QLatin1Char('=')); | 
					
						
							|  |  |  |                     if (qrcDefintion.count() == 2) { | 
					
						
							|  |  |  |                         QString fixedPath = path; | 
					
						
							|  |  |  |                         fixedPath.replace(QLatin1String("qrc:") + qrcDefintion.first(), qrcDefintion.last() + QLatin1Char('/')); | 
					
						
							|  |  |  |                         if (QFileInfo(fixedPath).exists()) { | 
					
						
							|  |  |  |                             fixedPath.replace(QLatin1String("//"), QLatin1String("/")); | 
					
						
							|  |  |  |                             fixedPath.replace(QLatin1Char('\\'), QLatin1Char('/')); | 
					
						
							|  |  |  |                             return QUrl(fixedPath); | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (value.type() == QVariant::String) { | 
					
						
							|  |  |  |         const QString str = value.toString(); | 
					
						
							|  |  |  |         if (str.contains(QLatin1String("qrc:"))) { | 
					
						
							|  |  |  |             QString qrcSearchPath = qgetenv("QMLDESIGNER_RC_PATHS"); | 
					
						
							|  |  |  |             if (!qrcSearchPath.isEmpty()) { | 
					
						
							|  |  |  |                 const QStringList searchPaths = qrcSearchPath.split(QLatin1Char(';')); | 
					
						
							|  |  |  |                 foreach (const QString &qrcPath, searchPaths) { | 
					
						
							|  |  |  |                     const QStringList qrcDefintion = qrcPath.split(QLatin1Char('=')); | 
					
						
							|  |  |  |                     if (qrcDefintion.count() == 2) { | 
					
						
							|  |  |  |                         QString fixedPath = str; | 
					
						
							|  |  |  |                         fixedPath.replace(QLatin1String("qrc:") + qrcDefintion.first(), qrcDefintion.last() + QLatin1Char('/')); | 
					
						
							|  |  |  |                         if (QFileInfo(fixedPath).exists()) { | 
					
						
							|  |  |  |                             fixedPath.replace(QLatin1String("//"), QLatin1String("/")); | 
					
						
							|  |  |  |                             fixedPath.replace(QLatin1Char('\\'), QLatin1Char('/')); | 
					
						
							|  |  |  |                             return fixedPath; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-18 14:57:34 +02:00
										 |  |  | void ObjectNodeInstance::updateAllDirtyNodesRecursive() | 
					
						
							| 
									
										
										
										
											2013-04-15 13:28:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | void ObjectNodeInstance::setPropertyVariant(const PropertyName &name, const QVariant &value) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     QQmlProperty property(object(), name, context()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!property.isValid()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVariant fixedValue = fixResourcePaths(value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVariant oldValue = property.read(); | 
					
						
							|  |  |  |     if (oldValue.type() == QVariant::Url) { | 
					
						
							|  |  |  |         QUrl url = oldValue.toUrl(); | 
					
						
							|  |  |  |         QString path = url.toLocalFile(); | 
					
						
							|  |  |  |         if (QFileInfo(path).exists() && nodeInstanceServer() && !path.isEmpty()) | 
					
						
							|  |  |  |             nodeInstanceServer()->removeFilePropertyFromFileSystemWatcher(object(), name, path); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (hasValidResetBinding(name)) { | 
					
						
							|  |  |  |         QQmlPropertyPrivate::setBinding(property, 0, QQmlPropertyPrivate::BypassInterceptor | QQmlPropertyPrivate::DontRemoveBinding); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool isWritten = property.write(convertSpecialCharacter(fixedValue)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!isWritten) | 
					
						
							|  |  |  |         qDebug() << "ObjectNodeInstance.setPropertyVariant: Cannot be written: " << object() << name << fixedValue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVariant newValue = property.read(); | 
					
						
							|  |  |  |     if (newValue.type() == QVariant::Url) { | 
					
						
							|  |  |  |         QUrl url = newValue.toUrl(); | 
					
						
							|  |  |  |         QString path = url.toLocalFile(); | 
					
						
							|  |  |  |         if (QFileInfo(path).exists() && nodeInstanceServer() && !path.isEmpty()) | 
					
						
							|  |  |  |             nodeInstanceServer()->addFilePropertyToFileSystemWatcher(object(), name, path); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | void ObjectNodeInstance::setPropertyBinding(const PropertyName &name, const QString &expression) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     QQmlProperty property(object(), name, context()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!property.isValid()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (property.isProperty()) { | 
					
						
							|  |  |  |         QQmlBinding *binding = new QQmlBinding(expression, object(), context()); | 
					
						
							|  |  |  |         binding->setTarget(property); | 
					
						
							|  |  |  |         binding->setNotifyOnValueChanged(true); | 
					
						
							|  |  |  |         QQmlAbstractBinding *oldBinding = QQmlPropertyPrivate::setBinding(property, binding); | 
					
						
							|  |  |  |         if (oldBinding && !hasValidResetBinding(name)) | 
					
						
							|  |  |  |             oldBinding->destroy(); | 
					
						
							|  |  |  |         binding->update(); | 
					
						
							|  |  |  |         if (binding->hasError()) { | 
					
						
							|  |  |  |             //qDebug() <<" ObjectNodeInstance.setPropertyBinding has Error: " << object() << name << expression << binding->error(engine()).toString();
 | 
					
						
							|  |  |  |             if (property.property().userType() == QVariant::String) | 
					
						
							|  |  |  |                 property.write(QVariant(QString("#%1#").arg(expression))); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         qWarning() << "ObjectNodeInstance.setPropertyBinding: Cannot set binding for property" << name << ": property is unknown for type"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::deleteObjectsInList(const QQmlProperty &property) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QObjectList objectList; | 
					
						
							|  |  |  |     QQmlListReference list = qvariant_cast<QQmlListReference>(property.read()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!hasFullImplementedListInterface(list)) { | 
					
						
							|  |  |  |         qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!"; | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int i = 0; i < list.count(); i++) { | 
					
						
							|  |  |  |         objectList += list.at(i); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     list.clear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | void ObjectNodeInstance::resetProperty(const PropertyName &name) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     doResetProperty(name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (name == "font.pixelSize") | 
					
						
							|  |  |  |         doResetProperty("font.pointSize"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (name == "font.pointSize") | 
					
						
							|  |  |  |         doResetProperty("font.pixelSize"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | void ObjectNodeInstance::refreshProperty(const PropertyName &name) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     QQmlProperty property(object(), name, context()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!property.isValid()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVariant oldValue(property.read()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (property.isResettable()) | 
					
						
							|  |  |  |         property.reset(); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         property.write(resetValue(name)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (oldValue.type() == QVariant::Url) { | 
					
						
							|  |  |  |         QByteArray key = oldValue.toUrl().toEncoded(QUrl::UrlFormattingOption(0x100)); | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  |         QString pixmapKey = QString::fromUtf8(key.constData(), key.count()); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         QPixmapCache::remove(pixmapKey); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     property.write(oldValue); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | bool ObjectNodeInstance::hasBindingForProperty(const PropertyName &name, bool *hasChanged) const | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-10 15:34:50 +02:00
										 |  |  |     if (isPropertyBlackListed(name)) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     QQmlProperty property(object(), name, context()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool hasBinding = QQmlPropertyPrivate::binding(property); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (hasChanged) { | 
					
						
							|  |  |  |         *hasChanged = hasBinding != m_hasBindingHash.value(name, false); | 
					
						
							|  |  |  |         if (*hasChanged) | 
					
						
							|  |  |  |             m_hasBindingHash.insert(name, hasBinding); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return QQmlPropertyPrivate::binding(property); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | void ObjectNodeInstance::doResetProperty(const PropertyName &propertyName) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     m_modelAbstractPropertyHash.remove(propertyName); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QQmlProperty property(object(), propertyName, context()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!property.isValid()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QVariant oldValue = property.read(); | 
					
						
							|  |  |  |     if (oldValue.type() == QVariant::Url) { | 
					
						
							|  |  |  |         QUrl url = oldValue.toUrl(); | 
					
						
							|  |  |  |         QString path = url.toLocalFile(); | 
					
						
							|  |  |  |         if (QFileInfo(path).exists() && nodeInstanceServer()) | 
					
						
							|  |  |  |             nodeInstanceServer()->removeFilePropertyFromFileSystemWatcher(object(), propertyName, path); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QQmlAbstractBinding *binding = QQmlPropertyPrivate::binding(property); | 
					
						
							|  |  |  |     if (binding && !(hasValidResetBinding(propertyName) && resetBinding(propertyName) == binding)) { | 
					
						
							|  |  |  |         binding->setEnabled(false, 0); | 
					
						
							|  |  |  |         binding->destroy(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (hasValidResetBinding(propertyName)) { | 
					
						
							|  |  |  |         QQmlAbstractBinding *binding = resetBinding(propertyName); | 
					
						
							|  |  |  |         QQmlPropertyPrivate::setBinding(property, binding, QQmlPropertyPrivate::DontRemoveBinding); | 
					
						
							|  |  |  |         binding->update(); | 
					
						
							|  |  |  |     } else if (property.isResettable()) { | 
					
						
							|  |  |  |         property.reset(); | 
					
						
							|  |  |  |     } else if (property.propertyTypeCategory() == QQmlProperty::List) { | 
					
						
							|  |  |  |         QQmlListReference list = qvariant_cast<QQmlListReference>(property.read()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!hasFullImplementedListInterface(list)) { | 
					
						
							|  |  |  |             qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!"; | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         list.clear(); | 
					
						
							|  |  |  |     } else if (property.isWritable()) { | 
					
						
							|  |  |  |         if (property.read() == resetValue(propertyName)) | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         property.write(resetValue(propertyName)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | QVariant ObjectNodeInstance::property(const PropertyName &name) const | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (m_modelAbstractPropertyHash.contains(name)) | 
					
						
							|  |  |  |         return QVariant::fromValue(m_modelAbstractPropertyHash.value(name)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // TODO: handle model nodes
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-10 15:34:50 +02:00
										 |  |  |     if (isPropertyBlackListed(name)) | 
					
						
							|  |  |  |         return QVariant(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     QQmlProperty property(object(), name, context()); | 
					
						
							|  |  |  |     if (property.property().isEnumType()) { | 
					
						
							|  |  |  |         QVariant value = property.read(); | 
					
						
							|  |  |  |         return property.property().enumerator().valueToKey(value.toInt()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (property.propertyType() == QVariant::Url) { | 
					
						
							|  |  |  |         QUrl url = property.read().toUrl(); | 
					
						
							|  |  |  |         if (url.isEmpty()) | 
					
						
							|  |  |  |             return QVariant(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (url.scheme() == "file") { | 
					
						
							|  |  |  |             int basePathLength = nodeInstanceServer()->fileUrl().toLocalFile().lastIndexOf('/'); | 
					
						
							|  |  |  |             return QUrl(url.toLocalFile().mid(basePathLength + 1)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return property.read(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | PropertyNameList allPropertyNames(QObject *object, const PropertyName &baseName = PropertyName(), QObjectList *inspectedObjects = new QObjectList) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  |     PropertyNameList propertyNameList; | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (inspectedObjects== 0 || 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); | 
					
						
							|  |  |  |         QQmlProperty declarativeProperty(object, QLatin1String(metaProperty.name())); | 
					
						
							|  |  |  |         if (declarativeProperty.isValid() && declarativeProperty.propertyTypeCategory() == QQmlProperty::Object) { | 
					
						
							|  |  |  |             if (declarativeProperty.name() != "parent") { | 
					
						
							|  |  |  |                 QObject *childObject = QQmlMetaType::toQObject(declarativeProperty.read()); | 
					
						
							|  |  |  |                 if (childObject) | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  |                     propertyNameList.append(allPropertyNames(childObject, baseName +  PropertyName(metaProperty.name()) + '.', inspectedObjects)); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } else if (QQmlValueTypeFactory::valueType(metaProperty.userType())) { | 
					
						
							|  |  |  |             QQmlValueType *valueType = QQmlValueTypeFactory::valueType(metaProperty.userType()); | 
					
						
							|  |  |  |             valueType->setValue(metaProperty.read(object)); | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  |             propertyNameList.append(allPropertyNames(valueType, baseName +  PropertyName(metaProperty.name()) + '.', inspectedObjects)); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         } else  { | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  |             propertyNameList.append(baseName + PropertyName(metaProperty.name())); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return propertyNameList; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | PropertyNameList ObjectNodeInstance::propertyNames() const | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (isValid()) | 
					
						
							|  |  |  |         return allPropertyNames(object()); | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  |     return PropertyNameList(); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | QString ObjectNodeInstance::instanceType(const PropertyName &name) const | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-10 15:34:50 +02:00
										 |  |  |     if (isPropertyBlackListed(name)) | 
					
						
							|  |  |  |         return QLatin1String("undefined"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     QQmlProperty property(object(), name, context()); | 
					
						
							|  |  |  |     if (!property.isValid()) | 
					
						
							|  |  |  |         return QLatin1String("undefined"); | 
					
						
							|  |  |  |     return property.propertyTypeName(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QList<ServerNodeInstance> ObjectNodeInstance::childItems() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QList<ServerNodeInstance>(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QList<ServerNodeInstance>  ObjectNodeInstance::stateInstances() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QList<ServerNodeInstance>(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::setNodeSource(const QString & /*source*/) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::setDeleteHeldInstance(bool deleteInstance) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_deleteHeldInstance = deleteInstance; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::deleteHeldInstance() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_deleteHeldInstance; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ObjectNodeInstance::Pointer ObjectNodeInstance::create(QObject *object) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Pointer instance(new ObjectNodeInstance(object)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     instance->populateResetHashes(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return instance; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void stopAnimation(QObject *object) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (object == 0) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QQuickTransition *transition = qobject_cast<QQuickTransition*>(object); | 
					
						
							|  |  |  |     QQuickAbstractAnimation *animation = qobject_cast<QQuickAbstractAnimation*>(object); | 
					
						
							| 
									
										
										
										
											2012-12-08 21:26:29 +02:00
										 |  |  |     QQmlTimer *timer = qobject_cast<QQmlTimer*>(object); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     if (transition) { | 
					
						
							|  |  |  |        transition->setFromState(""); | 
					
						
							|  |  |  |        transition->setToState(""); | 
					
						
							|  |  |  |     } else if (animation) { | 
					
						
							|  |  |  | //        QQuickScriptAction *scriptAimation = qobject_cast<QQuickScriptAction*>(animation);
 | 
					
						
							|  |  |  | //        if (scriptAimation) FIXME
 | 
					
						
							|  |  |  | //            scriptAimation->setScript(QQmlScriptString());
 | 
					
						
							|  |  |  |         animation->setLoops(1); | 
					
						
							|  |  |  |         animation->complete(); | 
					
						
							|  |  |  |         animation->setDisableUserControl(); | 
					
						
							|  |  |  |     } else if (timer) { | 
					
						
							|  |  |  |         timer->blockSignals(true); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void allSubObject(QObject *object, QObjectList &objectList) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // don't add null pointer and stop if the object is already in the list
 | 
					
						
							|  |  |  |     if (!object || objectList.contains(object)) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     objectList.append(object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int index = QObject::staticMetaObject.propertyOffset(); | 
					
						
							|  |  |  |          index < object->metaObject()->propertyCount(); | 
					
						
							|  |  |  |          index++) { | 
					
						
							|  |  |  |         QMetaProperty metaProperty = object->metaObject()->property(index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // search recursive in property objects
 | 
					
						
							|  |  |  |         if (metaProperty.isReadable() | 
					
						
							|  |  |  |                 && metaProperty.isWritable() | 
					
						
							|  |  |  |                 && QQmlMetaType::isQObject(metaProperty.userType())) { | 
					
						
							|  |  |  |             if (metaProperty.name() != QLatin1String("parent")) { | 
					
						
							|  |  |  |                 QObject *propertyObject = QQmlMetaType::toQObject(metaProperty.read(object)); | 
					
						
							|  |  |  |                 allSubObject(propertyObject, objectList); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // search recursive in property object lists
 | 
					
						
							|  |  |  |         if (metaProperty.isReadable() | 
					
						
							|  |  |  |                 && QQmlMetaType::isList(metaProperty.userType())) { | 
					
						
							|  |  |  |             QQmlListReference list(object, metaProperty.name()); | 
					
						
							|  |  |  |             if (list.canCount() && list.canAt()) { | 
					
						
							|  |  |  |                 for (int i = 0; i < list.count(); i++) { | 
					
						
							|  |  |  |                     QObject *propertyObject = list.at(i); | 
					
						
							|  |  |  |                     allSubObject(propertyObject, objectList); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // search recursive in object children list
 | 
					
						
							|  |  |  |     foreach (QObject *childObject, object->children()) { | 
					
						
							|  |  |  |         allSubObject(childObject, objectList); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-26 14:00:27 +02:00
										 |  |  |     // search recursive in quick item childItems list
 | 
					
						
							|  |  |  |     QQuickItem *quickItem = qobject_cast<QQuickItem*>(object); | 
					
						
							|  |  |  |     if (quickItem) { | 
					
						
							|  |  |  |         foreach (QQuickItem *childItem, quickItem->childItems()) { | 
					
						
							|  |  |  |             allSubObject(childItem, objectList); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void disableTiledBackingStore(QObject *object) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Q_UNUSED(object); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-10 15:34:50 +02:00
										 |  |  | static void addToPropertyNameListIfNotBlackListed(PropertyNameList *propertyNameList, const PropertyName &propertyName) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!isPropertyBlackListed(propertyName)) | 
					
						
							|  |  |  |         propertyNameList->append(propertyName); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PropertyNameList propertyNameListForWritableProperties(QObject *object, const PropertyName &baseName = PropertyName(), QObjectList *inspectedObjects = new QObjectList()) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  |     PropertyNameList propertyNameList; | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (inspectedObjects == 0 || 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); | 
					
						
							|  |  |  |         QQmlProperty declarativeProperty(object, QLatin1String(metaProperty.name())); | 
					
						
							|  |  |  |         if (declarativeProperty.isValid() && !declarativeProperty.isWritable() && declarativeProperty.propertyTypeCategory() == QQmlProperty::Object) { | 
					
						
							|  |  |  |             if (declarativeProperty.name() != "parent") { | 
					
						
							|  |  |  |                 QObject *childObject = QQmlMetaType::toQObject(declarativeProperty.read()); | 
					
						
							|  |  |  |                 if (childObject) | 
					
						
							| 
									
										
										
										
											2013-04-10 15:34:50 +02:00
										 |  |  |                     propertyNameList.append(propertyNameListForWritableProperties(childObject, baseName +  PropertyName(metaProperty.name()) + '.', inspectedObjects)); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } else if (QQmlValueTypeFactory::valueType(metaProperty.userType())) { | 
					
						
							|  |  |  |             QQmlValueType *valueType = QQmlValueTypeFactory::valueType(metaProperty.userType()); | 
					
						
							|  |  |  |             valueType->setValue(metaProperty.read(object)); | 
					
						
							| 
									
										
										
										
											2013-04-10 15:34:50 +02:00
										 |  |  |             propertyNameList.append(propertyNameListForWritableProperties(valueType, baseName +  PropertyName(metaProperty.name()) + '.', inspectedObjects)); | 
					
						
							| 
									
										
										
										
											2012-11-22 12:13:20 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (metaProperty.isReadable() && metaProperty.isWritable()) { | 
					
						
							| 
									
										
										
										
											2013-04-10 15:34:50 +02:00
										 |  |  |             addToPropertyNameListIfNotBlackListed(&propertyNameList, baseName + PropertyName(metaProperty.name())); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return propertyNameList; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void fixResourcePathsForObject(QObject *object) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (qgetenv("QMLDESIGNER_RC_PATHS").isEmpty()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-10 15:34:50 +02:00
										 |  |  |     PropertyNameList propertyNameList = propertyNameListForWritableProperties(object); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  |     foreach (const PropertyName &propertyName, propertyNameList) { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         QQmlProperty property(object, propertyName, QQmlEngine::contextForObject(object)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const QVariant value  = property.read(); | 
					
						
							|  |  |  |         const QVariant fixedValue = ObjectNodeInstance::fixResourcePaths(value); | 
					
						
							|  |  |  |         if (value != fixedValue) { | 
					
						
							|  |  |  |             property.write(fixedValue); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tweakObjects(QObject *object) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QObjectList objectList; | 
					
						
							|  |  |  |     allSubObject(object, objectList); | 
					
						
							|  |  |  |     foreach (QObject* childObject, objectList) { | 
					
						
							|  |  |  |         disableTiledBackingStore(childObject); | 
					
						
							|  |  |  |         stopAnimation(childObject); | 
					
						
							|  |  |  |         fixResourcePathsForObject(childObject); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QObject *ObjectNodeInstance::createComponentWrap(const QString &nodeSource, const QStringList &imports, QQmlContext *context) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-22 17:52:57 +02:00
										 |  |  |     ComponentCompleteDisabler disableComponentComplete; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Q_UNUSED(disableComponentComplete) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     QQmlComponent *component = new QQmlComponent(context->engine()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QByteArray importArray; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     foreach (const QString &import, imports) { | 
					
						
							|  |  |  |         importArray.append(import.toUtf8()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QByteArray data(nodeSource.toUtf8()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     data.prepend(importArray); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     component->setData(data, context->baseUrl().resolved(QUrl("createComponent.qml"))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QObject *object = component; | 
					
						
							|  |  |  |     tweakObjects(object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (object && context) | 
					
						
							|  |  |  |         QQmlEngine::setContextForObject(object, context); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return object; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //The component might also be shipped with Creator.
 | 
					
						
							|  |  |  | //To avoid trouble with import "." we use the component shipped with Creator.
 | 
					
						
							|  |  |  | static inline QString fixComponentPathForIncompatibleQt(const QString &componentPath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QString result = componentPath; | 
					
						
							|  |  |  |     const QLatin1String importString("/imports/"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (componentPath.contains(importString)) { | 
					
						
							|  |  |  |         int index = componentPath.indexOf(importString) + 8; | 
					
						
							|  |  |  |         const QString relativeImportPath = componentPath.right(componentPath.length() - index); | 
					
						
							|  |  |  |         QString fixedComponentPath = QLibraryInfo::location(QLibraryInfo::ImportsPath) + relativeImportPath; | 
					
						
							|  |  |  |         fixedComponentPath.replace(QLatin1Char('\\'), QLatin1Char('/')); | 
					
						
							|  |  |  |         if (QFileInfo(fixedComponentPath).exists()) | 
					
						
							|  |  |  |             return fixedComponentPath; | 
					
						
							|  |  |  |         QString fixedPath = QFileInfo(fixedComponentPath).path(); | 
					
						
							|  |  |  |         if (fixedPath.endsWith(QLatin1String(".1.0"))) { | 
					
						
							|  |  |  |         //plugin directories might contain the version number
 | 
					
						
							|  |  |  |             fixedPath.chop(4); | 
					
						
							|  |  |  |             fixedPath += QLatin1Char('/') + QFileInfo(componentPath).fileName(); | 
					
						
							|  |  |  |             if (QFileInfo(fixedPath).exists()) | 
					
						
							|  |  |  |                 return fixedPath; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QObject *ObjectNodeInstance::createComponent(const QString &componentPath, QQmlContext *context) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-22 17:52:57 +02:00
										 |  |  |     ComponentCompleteDisabler disableComponentComplete; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Q_UNUSED(disableComponentComplete) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 15:59:45 +02:00
										 |  |  |     QQmlComponent component(context->engine(), fixComponentPathForIncompatibleQt(componentPath)); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     QObject *object = component.beginCreate(context); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     tweakObjects(object); | 
					
						
							|  |  |  |     component.completeCreate(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (component.isError()) { | 
					
						
							|  |  |  |         qDebug() << componentPath; | 
					
						
							|  |  |  |         foreach (const QQmlError &error, component.errors()) | 
					
						
							|  |  |  |             qDebug() << error; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return object; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QObject *ObjectNodeInstance::createCustomParserObject(const QString &nodeSource, const QStringList &imports, QQmlContext *context) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-22 17:52:57 +02:00
										 |  |  |     ComponentCompleteDisabler disableComponentComplete; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Q_UNUSED(disableComponentComplete) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     QQmlComponent component(context->engine()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QByteArray importArray; | 
					
						
							|  |  |  |     foreach (const QString &import, imports) { | 
					
						
							|  |  |  |         importArray.append(import.toUtf8()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QByteArray data(nodeSource.toUtf8()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     data.prepend(importArray); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     component.setData(data, context->baseUrl().resolved(QUrl("createCustomParserObject.qml"))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QObject *object = component.beginCreate(context); | 
					
						
							|  |  |  |     tweakObjects(object); | 
					
						
							|  |  |  |     component.completeCreate(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return object; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QObject *ObjectNodeInstance::createPrimitive(const QString &typeName, int majorNumber, int minorNumber, QQmlContext *context) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QObject *object = 0; | 
					
						
							|  |  |  |     QQmlType *type = QQmlMetaType::qmlType(typeName.toUtf8(), majorNumber, minorNumber); | 
					
						
							|  |  |  |     if (type)  { | 
					
						
							|  |  |  |         if (type->typeName() == "QQmlComponent") { | 
					
						
							|  |  |  |             object = new QQmlComponent(context->engine(), 0); | 
					
						
							|  |  |  |         } else  { | 
					
						
							|  |  |  |             object = type->create(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         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"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     tweakObjects(object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (object && context) | 
					
						
							|  |  |  |         QQmlEngine::setContextForObject(object, context); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return object; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QObject *ObjectNodeInstance::object() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |         if (!m_object.isNull() && !QObjectPrivate::get(m_object.data())->wasDeleted) | 
					
						
							|  |  |  |             return m_object.data(); | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-28 14:14:07 +02:00
										 |  |  | QQuickItem *ObjectNodeInstance::contentItem() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | bool ObjectNodeInstance::hasContent() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::isResizable() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::isMovable() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-18 18:42:58 +02:00
										 |  |  | bool ObjectNodeInstance::isInLayoutable() const | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-18 18:42:58 +02:00
										 |  |  |     return m_isInLayoutable; | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-18 18:42:58 +02:00
										 |  |  | void ObjectNodeInstance::setInLayoutable(bool isInLayoutable) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-18 18:42:58 +02:00
										 |  |  |     m_isInLayoutable = isInLayoutable; | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-18 18:42:58 +02:00
										 |  |  | void ObjectNodeInstance::refreshLayoutable() | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::updateAnchors() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QQmlContext *ObjectNodeInstance::context() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (nodeInstanceServer()) | 
					
						
							|  |  |  |         return nodeInstanceServer()->context(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     qWarning() << "Error: No NodeInstanceServer"; | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QQmlEngine *ObjectNodeInstance::engine() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return nodeInstanceServer()->engine(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::paintUpdate() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::activateState() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::deactivateState() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::populateResetHashes() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-04-10 15:34:50 +02:00
										 |  |  |     PropertyNameList propertyNameList = propertyNameListForWritableProperties(object()); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  |     foreach (const PropertyName &propertyName, propertyNameList) { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         QQmlProperty property(object(), propertyName, QQmlEngine::contextForObject(object())); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QQmlAbstractBinding::Pointer binding = QQmlAbstractBinding::getPointer(QQmlPropertyPrivate::binding(property)); | 
					
						
							|  |  |  |         if (binding) { | 
					
						
							|  |  |  |             m_resetBindingHash.insert(propertyName, binding); | 
					
						
							|  |  |  |         } else if (property.isWritable()) { | 
					
						
							|  |  |  |             m_resetValueHash.insert(propertyName, property.read()); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | QQmlAbstractBinding *ObjectNodeInstance::resetBinding(const PropertyName &propertyName) const | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_resetBindingHash.value(propertyName).data(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | bool ObjectNodeInstance::hasValidResetBinding(const PropertyName &propertyName) const | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_resetBindingHash.contains(propertyName) &&  m_resetBindingHash.value(propertyName).data(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | QVariant ObjectNodeInstance::resetValue(const PropertyName &propertyName) const | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return m_resetValueHash.value(propertyName); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | void ObjectNodeInstance::setResetValue(const PropertyName &propertyName, const QVariant &value) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     m_resetValueHash.insert(propertyName, value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QImage ObjectNodeInstance::renderImage() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QImage(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-15 13:28:48 +02:00
										 |  |  | QImage ObjectNodeInstance::renderPreviewImage(const QSize & /*previewImageSize*/) const | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return QImage(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QObject *ObjectNodeInstance::parent() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!object()) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return object()->parent(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-21 16:49:28 +02:00
										 |  |  | QObject *ObjectNodeInstance::parentObject(QObject *object) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-26 14:00:27 +02:00
										 |  |  |     QQuickItem *quickItem = qobject_cast<QQuickItem*>(object); | 
					
						
							| 
									
										
										
										
											2013-04-18 11:56:23 +02:00
										 |  |  |     if (quickItem && quickItem->parentItem()) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //QQuickRootItem is used by Window and we want to return the Window as parent
 | 
					
						
							|  |  |  |         if (strcmp(quickItem->metaObject()->className(), "QQuickRootItem")) | 
					
						
							|  |  |  |             return object->parent(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-26 14:00:27 +02:00
										 |  |  |         return quickItem->parentItem(); | 
					
						
							| 
									
										
										
										
											2013-04-18 11:56:23 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return object->parent(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-18 14:50:22 +02:00
										 |  |  | void ObjectNodeInstance::doComponentCompleteRecursive(QObject *object, NodeInstanceServer *nodeInstanceServer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (object) { | 
					
						
							|  |  |  |         QQuickItem *item = qobject_cast<QQuickItem*>(object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (item && DesignerSupport::isComponentComplete(item)) | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QList<QObject*> childList = object->children(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (item) { | 
					
						
							|  |  |  |             foreach (QQuickItem *childItem, item->childItems()) { | 
					
						
							|  |  |  |                 if (!childList.contains(childItem)) | 
					
						
							|  |  |  |                     childList.append(childItem); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         foreach (QObject *child, childList) { | 
					
						
							|  |  |  |             if (!nodeInstanceServer->hasInstanceForObject(child)) | 
					
						
							|  |  |  |                 doComponentCompleteRecursive(child, nodeInstanceServer); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (item) { | 
					
						
							|  |  |  |             static_cast<QQmlParserStatus*>(item)->componentComplete(); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             QQmlParserStatus *qmlParserStatus = dynamic_cast< QQmlParserStatus*>(object); | 
					
						
							|  |  |  |             if (qmlParserStatus) | 
					
						
							|  |  |  |                 qmlParserStatus->componentComplete(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | 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 | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-28 14:14:07 +02:00
										 |  |  |     return QRectF(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QRectF ObjectNodeInstance::contentItemBoundingBox() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QRectF(); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QPointF ObjectNodeInstance::position() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QPointF(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QSizeF ObjectNodeInstance::size() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QSizeF(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int ObjectNodeInstance::penWidth() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::createDynamicProperty(const QString &name, const QString &/*typeName*/) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_metaObject == 0) { | 
					
						
							|  |  |  |         qWarning() << "ObjectNodeInstance.createDynamicProperty: No Metaobject."; | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_metaObject->createNewProperty(name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | bool ObjectNodeInstance::updateStateVariant(const ObjectNodeInstance::Pointer &/*target*/, const PropertyName &/*propertyName*/, const QVariant &/*value*/) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | bool ObjectNodeInstance::updateStateBinding(const ObjectNodeInstance::Pointer &/*target*/, const PropertyName &/*propertyName*/, const QString &/*expression*/) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | bool ObjectNodeInstance::resetStateProperty(const ObjectNodeInstance::Pointer &/*target*/, const PropertyName &/*propertyName*/, const QVariant &/*resetValue*/) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::doComponentComplete() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-18 14:50:22 +02:00
										 |  |  |     doComponentCompleteRecursive(object(), nodeInstanceServer()); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::isRootNodeInstance() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return nodeInstanceServer()->rootNodeInstance().isWrappingThisObject(object()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::isValid() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return instanceId() >= 0 && object(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |