| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | /**************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-01-11 16:28:15 +01:00
										 |  |  | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** Contact: Nokia Corporation (info@qt.nokia.com) | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** 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.
 | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** In addition, as a special exception, Nokia gives you certain additional | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** rights. These rights are described in the Nokia Qt LGPL Exception | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2011-04-13 08:42:33 +02:00
										 |  |  | ** Other Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Alternatively, this file may be used in accordance with the terms and | 
					
						
							|  |  |  | ** conditions contained in a signed written agreement between you and Nokia. | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-12-17 16:01:08 +01:00
										 |  |  | ** If you have questions regarding the use of this file, please contact | 
					
						
							| 
									
										
										
										
											2011-05-06 15:05:37 +02:00
										 |  |  | ** Nokia at info@qt.nokia.com. | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | **************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "objectnodeinstance.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-29 15:11:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QEvent>
 | 
					
						
							|  |  |  | #include <QGraphicsScene>
 | 
					
						
							| 
									
										
										
										
											2010-02-26 14:47:44 +01:00
										 |  |  | #include <QDeclarativeContext>
 | 
					
						
							|  |  |  | #include <QDeclarativeError>
 | 
					
						
							|  |  |  | #include <QDeclarativeEngine>
 | 
					
						
							|  |  |  | #include <QDeclarativeProperty>
 | 
					
						
							| 
									
										
										
										
											2010-02-15 17:05:20 +01:00
										 |  |  | #include <QSharedPointer>
 | 
					
						
							| 
									
										
										
										
											2010-03-24 17:07:32 +01:00
										 |  |  | #include <QFileInfo>
 | 
					
						
							|  |  |  | #include <QFileSystemWatcher>
 | 
					
						
							|  |  |  | #include <QPixmapCache>
 | 
					
						
							| 
									
										
										
										
											2010-10-08 12:57:45 +02:00
										 |  |  | #ifndef QT_NO_WEBKIT
 | 
					
						
							| 
									
										
										
										
											2010-10-05 13:21:41 +02:00
										 |  |  | #include <QGraphicsWebView>
 | 
					
						
							| 
									
										
										
										
											2010-10-08 12:57:45 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | #include <QGraphicsObject>
 | 
					
						
							| 
									
										
										
										
											2010-01-29 15:11:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-13 19:39:23 +02:00
										 |  |  | #include <QTextDocument>
 | 
					
						
							| 
									
										
										
										
											2011-06-14 12:26:08 +02:00
										 |  |  | #include <QLibraryInfo>
 | 
					
						
							| 
									
										
										
										
											2010-04-13 19:39:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-26 14:47:44 +01:00
										 |  |  | #include <private/qdeclarativebinding_p.h>
 | 
					
						
							| 
									
										
										
										
											2010-03-19 11:52:48 +01:00
										 |  |  | #include <private/qdeclarativemetatype_p.h>
 | 
					
						
							|  |  |  | #include <private/qdeclarativevaluetype_p.h>
 | 
					
						
							| 
									
										
										
										
											2010-04-13 19:39:23 +02:00
										 |  |  | #include <private/qdeclarativetext_p.h>
 | 
					
						
							|  |  |  | #include <private/qdeclarativetext_p_p.h>
 | 
					
						
							| 
									
										
										
										
											2010-06-09 18:00:34 +02:00
										 |  |  | #include <private/qdeclarativetransition_p.h>
 | 
					
						
							|  |  |  | #include <private/qdeclarativeanimation_p.h>
 | 
					
						
							|  |  |  | #include <private/qdeclarativetimer_p.h>
 | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace QmlDesigner { | 
					
						
							|  |  |  | namespace Internal { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ObjectNodeInstance::ObjectNodeInstance(QObject *object) | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     : m_instanceId(-1), | 
					
						
							|  |  |  |     m_deleteHeldInstance(true), | 
					
						
							| 
									
										
										
										
											2010-02-04 14:28:19 +01:00
										 |  |  |     m_object(object), | 
					
						
							| 
									
										
										
										
											2010-09-28 14:51:05 +02:00
										 |  |  |     m_metaObject(0), | 
					
						
							|  |  |  |     m_isInPositioner(false) | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-02-15 17:05:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ObjectNodeInstance::~ObjectNodeInstance() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     destroy(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::destroy() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-13 17:11:39 +01:00
										 |  |  |     if (deleteHeldInstance()) { | 
					
						
							|  |  |  |         // Remove from old property
 | 
					
						
							| 
									
										
										
										
											2010-05-12 21:50:58 +02:00
										 |  |  |         if (object()) { | 
					
						
							| 
									
										
										
										
											2010-04-26 14:27:53 +02:00
										 |  |  |             setId(QString()); | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |             if (m_instanceId >= 0) { | 
					
						
							|  |  |  |                 reparent(parentInstance(), m_parentProperty, ObjectNodeInstance::Pointer(), QString()); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-13 17:11:39 +01:00
										 |  |  |         if (object()) { | 
					
						
							|  |  |  |             QObject *obj = object(); | 
					
						
							|  |  |  |             m_object.clear(); | 
					
						
							|  |  |  |             delete obj; | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-04-06 16:39:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     m_metaObject = 0; | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     m_instanceId = -1; | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | void ObjectNodeInstance::setInstanceId(qint32 id) | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     m_instanceId = id; | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | qint32 ObjectNodeInstance::instanceId() const | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     return m_instanceId; | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | NodeInstanceServer *ObjectNodeInstance::nodeInstanceServer() const | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     return m_nodeInstanceServer.data(); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | void ObjectNodeInstance::setNodeInstanceServer(NodeInstanceServer *server) | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     Q_ASSERT(!m_nodeInstanceServer.data()); | 
					
						
							| 
									
										
										
										
											2010-02-15 17:05:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     m_nodeInstanceServer = server; | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-15 17:05:20 +01:00
										 |  |  | static bool hasPropertiesWitoutNotifications(const QMetaObject *metaObject) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     for(int propertyIndex = QObject::staticMetaObject.propertyCount(); propertyIndex < metaObject->propertyCount(); propertyIndex++) { | 
					
						
							|  |  |  |         if (!metaObject->property(propertyIndex).hasNotifySignal()) | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::initializePropertyWatcher(const ObjectNodeInstance::Pointer &objectNodeInstance) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     const QMetaObject *metaObject = objectNodeInstance->object()->metaObject(); | 
					
						
							|  |  |  |     m_metaObject = new NodeInstanceMetaObject(objectNodeInstance, nodeInstanceServer()->engine()); | 
					
						
							|  |  |  |     for(int propertyIndex = QObject::staticMetaObject.propertyCount(); propertyIndex < metaObject->propertyCount(); propertyIndex++) { | 
					
						
							|  |  |  |         if (QDeclarativeMetaType::isQObject(metaObject->property(propertyIndex).userType())) { | 
					
						
							|  |  |  |             QObject *propertyObject = QDeclarativeMetaType::toQObject(metaObject->property(propertyIndex).read(objectNodeInstance->object())); | 
					
						
							|  |  |  |             if (propertyObject && hasPropertiesWitoutNotifications(propertyObject->metaObject())) { | 
					
						
							|  |  |  |                 new NodeInstanceMetaObject(objectNodeInstance, propertyObject, metaObject->property(propertyIndex).name(), nodeInstanceServer()->engine()); | 
					
						
							| 
									
										
										
										
											2010-02-15 17:05:20 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_signalSpy.setObjectNodeInstance(objectNodeInstance); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | void ObjectNodeInstance::initialize(const ObjectNodeInstance::Pointer &objectNodeInstance) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     initializePropertyWatcher(objectNodeInstance); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | void ObjectNodeInstance::setId(const QString &id) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-23 19:18:51 +01:00
										 |  |  |     if (!m_id.isEmpty() && context()) { | 
					
						
							| 
									
										
										
										
											2010-01-13 17:11:39 +01:00
										 |  |  |         context()->engine()->rootContext()->setContextProperty(m_id, 0); | 
					
						
							| 
									
										
										
										
											2010-01-12 13:36:28 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-23 19:18:51 +01:00
										 |  |  |     if (!id.isEmpty() && context()) { | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |         context()->engine()->rootContext()->setContextProperty(id, object()); // will also force refresh of all bindings
 | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-01-11 15:52:37 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-13 17:11:39 +01:00
										 |  |  |     m_id = id; | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-23 15:51:01 +02:00
										 |  |  | QString ObjectNodeInstance::id() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_id; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | bool ObjectNodeInstance::isQmlGraphicsItem() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::isGraphicsObject() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::isTransition() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-28 14:51:05 +02:00
										 |  |  | bool ObjectNodeInstance::isPositioner() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | bool ObjectNodeInstance::isSGItem() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | bool ObjectNodeInstance::equalGraphicsItem(QGraphicsItem * /*item*/) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QTransform ObjectNodeInstance::transform() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QTransform(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QTransform ObjectNodeInstance::customTransform() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QTransform(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::hasAnchor(const QString &/*name*/) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-23 15:55:41 +02:00
										 |  |  | bool ObjectNodeInstance::isAnchoredBySibling() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::isAnchoredByChildren() const | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | QPair<QString, ServerNodeInstance> ObjectNodeInstance::anchor(const QString &/*name*/) const | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     return qMakePair(QString(), ServerNodeInstance()); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  | static bool isList(const QDeclarativeProperty &property) | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     return property.propertyTypeCategory() == QDeclarativeProperty::List; | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  | static bool isObject(const QDeclarativeProperty &property) | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-05-06 13:10:25 +02:00
										 |  |  |     return (property.propertyTypeCategory() == QDeclarativeProperty::Object) || | 
					
						
							|  |  |  |             //QVariant can also store QObjects. Lets trust our model.
 | 
					
						
							|  |  |  |            (QLatin1String(property.propertyTypeName()) == QLatin1String("QVariant")); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static QVariant objectToVariant(QObject *object) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-02-09 14:34:35 +01:00
										 |  |  |     return QVariant::fromValue(object); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-07 16:59:25 +02:00
										 |  |  | static bool hasFullImplementedListInterface(const QDeclarativeListReference &list) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return list.isValid() && list.canCount() && list.canAt() && list.canAppend() && list.canClear(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  | static void removeObjectFromList(const QDeclarativeProperty &property, QObject *objectToBeRemoved, QDeclarativeEngine * engine) | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     QDeclarativeListReference listReference(property.object(), property.name().toLatin1(), engine); | 
					
						
							| 
									
										
										
										
											2010-04-07 16:59:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-13 19:39:23 +02:00
										 |  |  |     if (!hasFullImplementedListInterface(listReference)) { | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |         qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!"; | 
					
						
							| 
									
										
										
										
											2010-04-07 16:59:25 +02:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2010-04-13 19:39:23 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-04-07 16:59:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-22 13:18:52 +01:00
										 |  |  |     int count = listReference.count(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QObjectList objectList; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for(int i = 0; i < count; i ++) { | 
					
						
							|  |  |  |         QObject *listItem = listReference.at(i); | 
					
						
							| 
									
										
										
										
											2010-09-15 15:47:24 +02:00
										 |  |  |         if (listItem && listItem != objectToBeRemoved) | 
					
						
							| 
									
										
										
										
											2010-03-22 13:18:52 +01:00
										 |  |  |             objectList.append(listItem); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     listReference.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     foreach(QObject *object, objectList) | 
					
						
							|  |  |  |         listReference.append(object); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::removeFromOldProperty(QObject *object, QObject *oldParent, const QString &oldParentProperty) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     QDeclarativeProperty property(oldParent, oldParentProperty, context()); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     if (!property.isValid()) | 
					
						
							| 
									
										
										
										
											2010-04-07 14:37:14 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     if (isList(property)) { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |         removeObjectFromList(property, object, nodeInstanceServer()->engine()); | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     } else if (isObject(property)) { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |         if (nodeInstanceServer()->hasInstanceForObject(oldParent)) { | 
					
						
							|  |  |  |             nodeInstanceServer()->instanceForObject(oldParent).resetProperty(oldParentProperty); | 
					
						
							| 
									
										
										
										
											2010-04-19 15:16:36 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-09-23 16:04:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (object && object->parent()) | 
					
						
							|  |  |  |         object->setParent(0); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::addToNewProperty(QObject *object, QObject *newParent, const QString &newParentProperty) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     QDeclarativeProperty property(newParent, newParentProperty, context()); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     if (isList(property)) { | 
					
						
							|  |  |  |         QDeclarativeListReference list = qvariant_cast<QDeclarativeListReference>(property.read()); | 
					
						
							| 
									
										
										
										
											2010-04-07 16:59:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-13 19:39:23 +02:00
										 |  |  |         if (!hasFullImplementedListInterface(list)) { | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |             qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!"; | 
					
						
							| 
									
										
										
										
											2010-04-07 16:59:25 +02:00
										 |  |  |             return; | 
					
						
							| 
									
										
										
										
											2010-04-13 19:39:23 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-04-07 16:59:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-23 10:39:44 +01:00
										 |  |  |         list.append(object); | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     } else if (isObject(property)) { | 
					
						
							|  |  |  |         property.write(objectToVariant(object)); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-04-13 19:39:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-23 16:04:16 +02:00
										 |  |  |     QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject*>(object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (object && !(graphicsObject && graphicsObject->parentItem())) | 
					
						
							|  |  |  |         object->setParent(newParent); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     Q_ASSERT(objectToVariant(object).isValid()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | void ObjectNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const QString &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const QString &newParentProperty) | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     if (oldParentInstance) { | 
					
						
							|  |  |  |         removeFromOldProperty(object(), oldParentInstance->object(), oldParentProperty); | 
					
						
							|  |  |  |         m_parentProperty.clear(); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     if (newParentInstance) { | 
					
						
							|  |  |  |         m_parentProperty = newParentProperty; | 
					
						
							|  |  |  |         addToNewProperty(object(), newParentInstance->object(), newParentProperty); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-04 14:28:19 +01:00
										 |  |  | void ObjectNodeInstance::setPropertyVariant(const QString &name, const QVariant &value) | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-23 16:43:26 +01:00
										 |  |  |     QDeclarativeProperty property(object(), name, context()); | 
					
						
							| 
									
										
										
										
											2010-03-24 17:07:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-07 14:37:14 +02:00
										 |  |  |     if (!property.isValid()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-24 17:07:32 +01:00
										 |  |  |     QVariant oldValue = property.read(); | 
					
						
							|  |  |  |     if (oldValue.type() == QVariant::Url) { | 
					
						
							|  |  |  |         QUrl url = oldValue.toUrl(); | 
					
						
							|  |  |  |         QString path = url.toLocalFile(); | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |         if (QFileInfo(path).exists() && nodeInstanceServer() && !path.isEmpty()) | 
					
						
							|  |  |  |             nodeInstanceServer()->removeFilePropertyFromFileSystemWatcher(object(), name, path); | 
					
						
							| 
									
										
										
										
											2010-03-24 17:07:32 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     bool isWritten = property.write(value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!isWritten) | 
					
						
							|  |  |  |         qDebug() << "ObjectNodeInstance.setPropertyVariant: Cannot be written: " << object() << name << value; | 
					
						
							| 
									
										
										
										
											2010-03-24 17:07:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     QVariant newValue = property.read(); | 
					
						
							|  |  |  |     if (newValue.type() == QVariant::Url) { | 
					
						
							|  |  |  |         QUrl url = newValue.toUrl(); | 
					
						
							|  |  |  |         QString path = url.toLocalFile(); | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |         if (QFileInfo(path).exists() && nodeInstanceServer() && !path.isEmpty()) | 
					
						
							|  |  |  |             nodeInstanceServer()->addFilePropertyToFileSystemWatcher(object(), name, path); | 
					
						
							| 
									
										
										
										
											2010-03-24 17:07:32 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::setPropertyBinding(const QString &name, const QString &expression) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     QDeclarativeProperty property(object(), name, context()); | 
					
						
							| 
									
										
										
										
											2010-04-07 14:37:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     if (!property.isValid()) | 
					
						
							| 
									
										
										
										
											2010-04-07 14:37:14 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     if (property.isProperty()) { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |         QDeclarativeBinding *binding = new QDeclarativeBinding(expression, object(), context(), object()); | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |         binding->setTarget(property); | 
					
						
							| 
									
										
										
										
											2010-02-26 14:47:44 +01:00
										 |  |  |         binding->setNotifyOnValueChanged(true); | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |         QDeclarativeAbstractBinding *oldBinding = QDeclarativePropertyPrivate::setBinding(property, binding); | 
					
						
							| 
									
										
										
										
											2010-03-19 15:05:22 +01:00
										 |  |  |         if (oldBinding) | 
					
						
							|  |  |  |             oldBinding->destroy(); | 
					
						
							| 
									
										
										
										
											2010-02-26 14:47:44 +01:00
										 |  |  |         binding->update(); | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |         if (binding->hasError()) | 
					
						
							| 
									
										
										
										
											2011-02-09 13:00:12 +01:00
										 |  |  |             qDebug() <<" ObjectNodeInstance.setPropertyBinding has Error: " << object() << name << expression << binding->error().toString(); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |         qWarning() << "ObjectNodeInstance.setPropertyBinding: Cannot set binding for property" << name << ": property is unknown for type"; | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  | void ObjectNodeInstance::deleteObjectsInList(const QDeclarativeProperty &property) | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     QObjectList objectList; | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     QDeclarativeListReference list = qvariant_cast<QDeclarativeListReference>(property.read()); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-13 19:39:23 +02:00
										 |  |  |     if (!hasFullImplementedListInterface(list)) { | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |         qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!"; | 
					
						
							| 
									
										
										
										
											2010-04-07 16:59:25 +02:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2010-04-13 19:39:23 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-03-25 16:09:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-23 10:39:44 +01:00
										 |  |  |     for(int i = 0; i < list.count(); i++) { | 
					
						
							|  |  |  |         objectList += list.at(i); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-23 10:39:44 +01:00
										 |  |  |     list.clear(); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::resetProperty(const QString &name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-19 15:16:36 +02:00
										 |  |  |     doResetProperty(name); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (name == "font.pixelSize") | 
					
						
							| 
									
										
										
										
											2010-04-19 15:16:36 +02:00
										 |  |  |         doResetProperty("font.pointSize"); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (name == "font.pointSize") | 
					
						
							| 
									
										
										
										
											2010-04-19 15:16:36 +02:00
										 |  |  |         doResetProperty("font.pixelSize"); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-24 17:07:32 +01:00
										 |  |  | void ObjectNodeInstance::refreshProperty(const QString &name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QDeclarativeProperty property(object(), name, context()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-07 14:37:14 +02:00
										 |  |  |     if (!property.isValid()) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-24 17:07:32 +01:00
										 |  |  |     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::FormattingOption(0x100)); | 
					
						
							|  |  |  |         QString pixmapKey = QString::fromLatin1(key.constData(), key.count()); | 
					
						
							|  |  |  |         QPixmapCache::remove(pixmapKey); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     property.write(oldValue); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | bool ObjectNodeInstance::hasBindingForProperty(const QString &name, bool *hasChanged) const | 
					
						
							| 
									
										
										
										
											2010-09-16 10:03:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     QDeclarativeProperty property(object(), name, context()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     bool hasBinding = QDeclarativePropertyPrivate::binding(property); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (hasChanged) { | 
					
						
							|  |  |  |         *hasChanged = hasBinding != m_hasBindingHash.value(name, false); | 
					
						
							|  |  |  |         if (*hasChanged) | 
					
						
							|  |  |  |             m_hasBindingHash.insert(name, hasBinding); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-16 10:03:22 +02:00
										 |  |  |     return QDeclarativePropertyPrivate::binding(property); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-19 15:16:36 +02:00
										 |  |  | void ObjectNodeInstance::doResetProperty(const QString &propertyName) | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     m_modelAbstractPropertyHash.remove(propertyName); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-22 14:58:49 +02:00
										 |  |  |     QDeclarativeProperty property(object(), propertyName, context()); | 
					
						
							| 
									
										
										
										
											2010-03-24 17:07:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-22 14:58:49 +02:00
										 |  |  |     if (!property.isValid()) | 
					
						
							| 
									
										
										
										
											2010-04-07 14:37:14 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-22 14:58:49 +02:00
										 |  |  |     QVariant oldValue = property.read(); | 
					
						
							| 
									
										
										
										
											2010-03-24 17:07:32 +01:00
										 |  |  |     if (oldValue.type() == QVariant::Url) { | 
					
						
							|  |  |  |         QUrl url = oldValue.toUrl(); | 
					
						
							|  |  |  |         QString path = url.toLocalFile(); | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |         if (QFileInfo(path).exists() && nodeInstanceServer()) | 
					
						
							|  |  |  |             nodeInstanceServer()->removeFilePropertyFromFileSystemWatcher(object(), propertyName, path); | 
					
						
							| 
									
										
										
										
											2010-03-24 17:07:32 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-22 14:58:49 +02:00
										 |  |  |     QDeclarativeAbstractBinding *binding = QDeclarativePropertyPrivate::binding(property); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     if (binding) { | 
					
						
							|  |  |  |         binding->setEnabled(false, 0); | 
					
						
							| 
									
										
										
										
											2010-03-19 11:52:48 +01:00
										 |  |  |         binding->destroy(); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-22 14:58:49 +02:00
										 |  |  |     if (property.isResettable()) { | 
					
						
							|  |  |  |         property.reset(); | 
					
						
							|  |  |  |     } else if (property.propertyTypeCategory() == QDeclarativeProperty::List) { | 
					
						
							|  |  |  |         QDeclarativeListReference list = qvariant_cast<QDeclarativeListReference>(property.read()); | 
					
						
							| 
									
										
										
										
											2010-04-13 19:39:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (!hasFullImplementedListInterface(list)) { | 
					
						
							| 
									
										
										
										
											2010-04-22 14:58:49 +02:00
										 |  |  |             qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!"; | 
					
						
							| 
									
										
										
										
											2010-04-07 16:59:25 +02:00
										 |  |  |             return; | 
					
						
							| 
									
										
										
										
											2010-04-13 19:39:23 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-07 16:59:25 +02:00
										 |  |  |         list.clear(); | 
					
						
							| 
									
										
										
										
											2010-04-22 14:58:49 +02:00
										 |  |  |     } else if (property.isWritable()) { | 
					
						
							|  |  |  |         if (property.read() == resetValue(propertyName)) | 
					
						
							| 
									
										
										
										
											2010-04-15 12:33:25 +02:00
										 |  |  |             return; | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-22 14:58:49 +02:00
										 |  |  |         property.write(resetValue(propertyName)); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QVariant ObjectNodeInstance::property(const QString &name) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_modelAbstractPropertyHash.contains(name)) | 
					
						
							|  |  |  |         return QVariant::fromValue(m_modelAbstractPropertyHash.value(name)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // TODO: handle model nodes
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     QDeclarativeProperty property(object(), name, context()); | 
					
						
							|  |  |  |     if (property.property().isEnumType()) { | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |         QVariant value = object()->property(name.toLatin1()); | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |         return property.property().enumerator().valueToKey(value.toInt()); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     if (property.propertyType() == QVariant::Url) { | 
					
						
							|  |  |  |         QUrl url = property.read().toUrl(); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |         if (url.isEmpty()) | 
					
						
							|  |  |  |             return QVariant(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (url.scheme() == "file") { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |             int basePathLength = nodeInstanceServer()->fileUrl().toLocalFile().lastIndexOf('/'); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |             return QUrl(url.toLocalFile().mid(basePathLength + 1)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |     return property.read(); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | QStringList allPropertyNames(QObject *object, const QString &baseName = QString(), QObjectList *inspectedObjects = new QObjectList) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QStringList propertyNameList; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-25 13:05:34 +01:00
										 |  |  |     if (inspectedObjects== 0 || inspectedObjects->contains(object)) | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |         return propertyNameList; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     inspectedObjects->append(object); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const QMetaObject *metaObject = object->metaObject(); | 
					
						
							|  |  |  |     for (int index = 0; index < metaObject->propertyCount(); ++index) { | 
					
						
							|  |  |  |         QMetaProperty metaProperty = metaObject->property(index); | 
					
						
							|  |  |  |         QDeclarativeProperty declarativeProperty(object, QLatin1String(metaProperty.name())); | 
					
						
							|  |  |  |         if (declarativeProperty.isValid() && declarativeProperty.propertyTypeCategory() == QDeclarativeProperty::Object) { | 
					
						
							| 
									
										
										
										
											2010-12-08 16:46:25 +01:00
										 |  |  |             if (declarativeProperty.name() != "parent") { | 
					
						
							|  |  |  |                 QObject *childObject = QDeclarativeMetaType::toQObject(declarativeProperty.read()); | 
					
						
							|  |  |  |                 if (childObject) | 
					
						
							|  |  |  |                     propertyNameList.append(allPropertyNames(childObject, baseName +  QString::fromUtf8(metaProperty.name()) + '.', inspectedObjects)); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |         } else if (QDeclarativeValueTypeFactory::valueType(metaProperty.userType())) { | 
					
						
							|  |  |  |             QDeclarativeValueType *valueType = QDeclarativeValueTypeFactory::valueType(metaProperty.userType()); | 
					
						
							|  |  |  |             valueType->setValue(metaProperty.read(object)); | 
					
						
							|  |  |  |             propertyNameList.append(allPropertyNames(valueType, baseName +  QString::fromUtf8(metaProperty.name()) + '.', inspectedObjects)); | 
					
						
							|  |  |  |         } else  { | 
					
						
							|  |  |  |             propertyNameList.append(baseName + QString::fromUtf8(metaProperty.name())); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return propertyNameList; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QStringList ObjectNodeInstance::propertyNames() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-12-20 14:32:59 +01:00
										 |  |  |     if (isValid()) | 
					
						
							|  |  |  |         return allPropertyNames(object()); | 
					
						
							|  |  |  |     return QStringList(); | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-15 14:23:00 +02:00
										 |  |  | QString ObjectNodeInstance::instanceType(const QString &name) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QDeclarativeProperty property(object(), name, context()); | 
					
						
							|  |  |  |     if (!property.isValid()) | 
					
						
							|  |  |  |         return QLatin1String("undefined"); | 
					
						
							|  |  |  |     return property.propertyTypeName(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-30 17:46:57 +01:00
										 |  |  | QList<ServerNodeInstance> ObjectNodeInstance::childItems() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QList<ServerNodeInstance>(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-12 16:07:31 +01:00
										 |  |  | QList<ServerNodeInstance>  ObjectNodeInstance::stateInstances() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QList<ServerNodeInstance>(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | void ObjectNodeInstance::setNodeSource(const QString & /*source*/) | 
					
						
							| 
									
										
										
										
											2011-06-08 17:02:03 +02:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | void ObjectNodeInstance::setDeleteHeldInstance(bool deleteInstance) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_deleteHeldInstance = deleteInstance; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::deleteHeldInstance() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_deleteHeldInstance; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | ObjectNodeInstance::Pointer ObjectNodeInstance::create(QObject *object) | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     Pointer instance(new ObjectNodeInstance(object)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     instance->populateResetValueHash(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return instance; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-05 13:21:41 +02:00
										 |  |  | static void stopAnimation(QObject *object) | 
					
						
							| 
									
										
										
										
											2010-06-09 18:00:34 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (object == 0) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QDeclarativeTransition *transition = qobject_cast<QDeclarativeTransition*>(object); | 
					
						
							|  |  |  |     QDeclarativeAbstractAnimation *animation = qobject_cast<QDeclarativeAbstractAnimation*>(object); | 
					
						
							|  |  |  |     QDeclarativeScriptAction *scriptAimation = qobject_cast<QDeclarativeScriptAction*>(object); | 
					
						
							|  |  |  |     QDeclarativeTimer *timer = qobject_cast<QDeclarativeTimer*>(object); | 
					
						
							|  |  |  |     if(transition) { | 
					
						
							|  |  |  |        transition->setFromState(""); | 
					
						
							|  |  |  |        transition->setToState(""); | 
					
						
							|  |  |  |     } else if (animation) { | 
					
						
							|  |  |  |         if (scriptAimation) { | 
					
						
							|  |  |  |             scriptAimation->setScript(QDeclarativeScriptString()); | 
					
						
							|  |  |  |         animation->setLoops(1); | 
					
						
							|  |  |  |         animation->complete(); | 
					
						
							|  |  |  |         animation->setDisableUserControl(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } else if (timer) { | 
					
						
							|  |  |  |         timer->blockSignals(true); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-05 13:21:41 +02:00
										 |  |  | void allSubObject(QObject *object, QObjectList &objectList) | 
					
						
							| 
									
										
										
										
											2010-06-09 18:00:34 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-05 13:21:41 +02:00
										 |  |  |     // don't add null pointer and stop if the object is already in the list
 | 
					
						
							|  |  |  |     if (!object || objectList.contains(object)) | 
					
						
							| 
									
										
										
										
											2010-06-09 18:00:34 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-05 13:21:41 +02:00
										 |  |  |     objectList.append(object); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-09 18:00:34 +02:00
										 |  |  |     for (int index = QObject::staticMetaObject.propertyOffset(); | 
					
						
							|  |  |  |          index < object->metaObject()->propertyCount(); | 
					
						
							|  |  |  |          index++) { | 
					
						
							| 
									
										
										
										
											2010-10-05 13:21:41 +02:00
										 |  |  |         QMetaProperty metaProperty = object->metaObject()->property(index); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // search recursive in property objects
 | 
					
						
							|  |  |  |         if (metaProperty.isReadable() | 
					
						
							|  |  |  |                 && metaProperty.isWritable() | 
					
						
							|  |  |  |                 && QDeclarativeMetaType::isQObject(metaProperty.userType())) { | 
					
						
							| 
									
										
										
										
											2010-12-08 16:46:25 +01:00
										 |  |  |             if (metaProperty.name() != QLatin1String("parent")) { | 
					
						
							|  |  |  |                 QObject *propertyObject = QDeclarativeMetaType::toQObject(metaProperty.read(object)); | 
					
						
							|  |  |  |                 allSubObject(propertyObject, objectList); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-10-05 13:21:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // search recursive in property object lists
 | 
					
						
							|  |  |  |         if (metaProperty.isReadable() | 
					
						
							|  |  |  |                 && QDeclarativeMetaType::isList(metaProperty.userType())) { | 
					
						
							|  |  |  |             QDeclarativeListReference 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); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // search recursive in graphics item childItems list
 | 
					
						
							|  |  |  |     QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject*>(object); | 
					
						
							|  |  |  |     if (graphicsObject) { | 
					
						
							|  |  |  |         foreach(QGraphicsItem *item, graphicsObject->childItems()) { | 
					
						
							|  |  |  |             QGraphicsObject *childObject = item->toGraphicsObject(); | 
					
						
							|  |  |  |             allSubObject(childObject, objectList); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void disableTiledBackingStore(QObject *object) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-08 12:57:45 +02:00
										 |  |  | #ifndef QT_NO_WEBKIT
 | 
					
						
							| 
									
										
										
										
											2010-10-05 13:21:41 +02:00
										 |  |  |     QGraphicsWebView *webView = qobject_cast<QGraphicsWebView*>(object); | 
					
						
							|  |  |  |     if (webView) | 
					
						
							|  |  |  |         webView->settings()->setAttribute(QWebSettings::TiledBackingStoreEnabled, false); | 
					
						
							| 
									
										
										
										
											2010-10-08 12:57:45 +02:00
										 |  |  | #else
 | 
					
						
							|  |  |  |     Q_UNUSED(object); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-10-05 13:21:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | void tweakObjects(QObject *object) | 
					
						
							| 
									
										
										
										
											2010-10-05 13:21:41 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     QObjectList objectList; | 
					
						
							|  |  |  |     allSubObject(object, objectList); | 
					
						
							|  |  |  |     foreach(QObject* childObject, objectList) { | 
					
						
							|  |  |  |         disableTiledBackingStore(childObject); | 
					
						
							|  |  |  |         stopAnimation(childObject); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-06-09 18:00:34 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-08 17:02:03 +02:00
										 |  |  | QObject *ObjectNodeInstance::createComponentWrap(const QString &nodeSource, const QStringList &imports, QDeclarativeContext *context) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QDeclarativeComponent *component = new QDeclarativeComponent(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) | 
					
						
							|  |  |  |         QDeclarativeEngine::setContextForObject(object, context); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QDeclarativeEngine::setObjectOwnership(object, QDeclarativeEngine::CppOwnership); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return object; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-06-09 18:00:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-14 12:26:08 +02:00
										 |  |  | //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("import"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (componentPath.contains(importString)) { | 
					
						
							|  |  |  |         int index = componentPath.indexOf(importString) + 7; | 
					
						
							|  |  |  |         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; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return result; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-08 17:02:03 +02:00
										 |  |  | QObject *ObjectNodeInstance::createComponent(const QString &componentPath, QDeclarativeContext *context) | 
					
						
							| 
									
										
										
										
											2011-05-06 13:08:46 +02:00
										 |  |  | {     | 
					
						
							| 
									
										
										
										
											2011-06-14 12:26:08 +02:00
										 |  |  |     QDeclarativeComponent component(context->engine(), QUrl::fromLocalFile(fixComponentPathForIncompatibleQt(componentPath))); | 
					
						
							| 
									
										
										
										
											2011-01-26 14:05:22 +01:00
										 |  |  |     QObject *object = component.beginCreate(context); | 
					
						
							| 
									
										
										
										
											2011-06-14 12:26:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     tweakObjects(object); | 
					
						
							|  |  |  |     component.completeCreate(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-06 13:08:46 +02:00
										 |  |  |     if (component.isError()) { | 
					
						
							|  |  |  |         qDebug() << componentPath; | 
					
						
							|  |  |  |         foreach(const QDeclarativeError &error, component.errors()) | 
					
						
							|  |  |  |             qDebug() << error; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-08 17:02:03 +02:00
										 |  |  |     QDeclarativeEngine::setObjectOwnership(object, QDeclarativeEngine::CppOwnership); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-06 13:08:46 +02:00
										 |  |  |     return object; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-08 17:02:03 +02:00
										 |  |  | QObject *ObjectNodeInstance::createCustomParserObject(const QString &nodeSource, const QStringList &imports, QDeclarativeContext *context) | 
					
						
							| 
									
										
										
										
											2011-05-06 13:08:46 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     QDeclarativeComponent component(context->engine()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QByteArray importArray; | 
					
						
							|  |  |  |     foreach(const QString &import, imports) { | 
					
						
							|  |  |  |         importArray.append(import.toUtf8()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-08 17:02:03 +02:00
										 |  |  |     QByteArray data(nodeSource.toUtf8()); | 
					
						
							| 
									
										
										
										
											2011-05-06 13:08:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     data.prepend(importArray); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     component.setData(data, context->baseUrl().resolved(QUrl("createCustomParserObject.qml"))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QObject *object = component.beginCreate(context); | 
					
						
							|  |  |  |     tweakObjects(object); | 
					
						
							|  |  |  |     component.completeCreate(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-08 17:02:03 +02:00
										 |  |  |     QDeclarativeEngine::setObjectOwnership(object, QDeclarativeEngine::CppOwnership); | 
					
						
							| 
									
										
										
										
											2011-05-06 13:08:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-08 17:02:03 +02:00
										 |  |  |     return object; | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-06-09 18:00:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-08 17:02:03 +02:00
										 |  |  | QObject *ObjectNodeInstance::createPrimitive(const QString &typeName, int majorNumber, int minorNumber, QDeclarativeContext *context) | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-06-09 18:00:34 +02:00
										 |  |  |     QObject *object = 0; | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     QDeclarativeType *type = QDeclarativeMetaType::qmlType(typeName.toUtf8(), majorNumber, minorNumber); | 
					
						
							|  |  |  |     if (type)  { | 
					
						
							| 
									
										
										
										
											2011-01-25 15:47:09 +01:00
										 |  |  |         if (type->typeName() == "QDeclarativeComponent") { | 
					
						
							|  |  |  |             object = new QDeclarativeComponent(context->engine(), 0); | 
					
						
							|  |  |  |         } else  { | 
					
						
							|  |  |  |             object = type->create(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-06-09 18:00:34 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |         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"; | 
					
						
							| 
									
										
										
										
											2010-06-09 18:00:34 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-05 13:21:41 +02:00
										 |  |  |     tweakObjects(object); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     if (object && context) | 
					
						
							|  |  |  |         QDeclarativeEngine::setContextForObject(object, context); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QDeclarativeEngine::setObjectOwnership(object, QDeclarativeEngine::CppOwnership); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return object; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QObject *ObjectNodeInstance::object() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-09-22 16:06:14 +02:00
										 |  |  |         if (!m_object.isNull() && !QObjectPrivate::get(m_object.data())->wasDeleted) | 
					
						
							|  |  |  |             return m_object.data(); | 
					
						
							|  |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::hasContent() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-28 14:51:05 +02:00
										 |  |  | bool ObjectNodeInstance::isResizable() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::isMovable() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ObjectNodeInstance::isInPositioner() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_isInPositioner; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::setInPositioner(bool isInPositioner) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_isInPositioner = isInPositioner; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | void ObjectNodeInstance::updateAnchors() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-26 14:47:44 +01:00
										 |  |  | QDeclarativeContext *ObjectNodeInstance::context() const | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-09 16:30:00 +01:00
										 |  |  |     if (nodeInstanceServer()) | 
					
						
							|  |  |  |         return nodeInstanceServer()->context(); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-09 16:30:00 +01:00
										 |  |  |     qWarning() << "Error: No NodeInstanceServer"; | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-16 09:24:26 +02:00
										 |  |  | QDeclarativeEngine *ObjectNodeInstance::engine() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     return nodeInstanceServer()->engine(); | 
					
						
							| 
									
										
										
										
											2010-09-16 09:24:26 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | void ObjectNodeInstance::paintUpdate() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-11 16:11:06 +01:00
										 |  |  | void ObjectNodeInstance::activateState() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::deactivateState() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | QStringList propertyNameForWritableProperties(QObject *object, const QString &baseName = QString(), QObjectList *inspectedObjects = new QObjectList()) | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     QStringList propertyNameList; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-25 13:05:34 +01:00
										 |  |  |     if (inspectedObjects == 0 || inspectedObjects->contains(object)) | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |         return propertyNameList; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     inspectedObjects->append(object); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     const QMetaObject *metaObject = object->metaObject(); | 
					
						
							|  |  |  |     for (int index = 0; index < metaObject->propertyCount(); ++index) { | 
					
						
							|  |  |  |         QMetaProperty metaProperty = metaObject->property(index); | 
					
						
							| 
									
										
										
										
											2010-10-12 19:33:16 +02:00
										 |  |  |         QDeclarativeProperty declarativeProperty(object, QLatin1String(metaProperty.name())); | 
					
						
							| 
									
										
										
										
											2011-01-24 14:55:22 +01:00
										 |  |  |         if (declarativeProperty.isValid() && !declarativeProperty.isWritable() && declarativeProperty.propertyTypeCategory() == QDeclarativeProperty::Object) { | 
					
						
							| 
									
										
										
										
											2010-12-08 16:46:25 +01:00
										 |  |  |             if (declarativeProperty.name() != "parent") { | 
					
						
							|  |  |  |                 QObject *childObject = QDeclarativeMetaType::toQObject(declarativeProperty.read()); | 
					
						
							|  |  |  |                 if (childObject) | 
					
						
							|  |  |  |                     propertyNameList.append(propertyNameForWritableProperties(childObject, baseName +  QString::fromUtf8(metaProperty.name()) + '.', inspectedObjects)); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-02-26 14:47:44 +01:00
										 |  |  |         } else if (QDeclarativeValueTypeFactory::valueType(metaProperty.userType())) { | 
					
						
							|  |  |  |             QDeclarativeValueType *valueType = QDeclarativeValueTypeFactory::valueType(metaProperty.userType()); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |             valueType->setValue(metaProperty.read(object)); | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |             propertyNameList.append(propertyNameForWritableProperties(valueType, baseName +  QString::fromUtf8(metaProperty.name()) + '.', inspectedObjects)); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |         } else if (metaProperty.isReadable() && metaProperty.isWritable()) { | 
					
						
							|  |  |  |             propertyNameList.append(baseName + QString::fromUtf8(metaProperty.name())); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return propertyNameList; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectNodeInstance::populateResetValueHash() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QStringList propertyNameList = propertyNameForWritableProperties(object()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     foreach(const QString &propertyName, propertyNameList) { | 
					
						
							| 
									
										
										
										
											2011-02-09 16:30:00 +01:00
										 |  |  |         QDeclarativeProperty property(object(), propertyName, QDeclarativeEngine::contextForObject(object())); | 
					
						
							| 
									
										
										
										
											2010-04-20 16:46:33 +02:00
										 |  |  |         if (property.isWritable()) | 
					
						
							|  |  |  |             m_resetValueHash.insert(propertyName, property.read()); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QVariant ObjectNodeInstance::resetValue(const QString &propertyName) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_resetValueHash.value(propertyName); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-05 20:55:31 +02:00
										 |  |  | void ObjectNodeInstance::paint(QPainter * /*painter*/) | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | QImage ObjectNodeInstance::renderImage() const | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     return QImage(); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QObject *ObjectNodeInstance::parent() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (!object()) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return object()->parent(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | QObject *parentObject(QObject *object) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject*>(object); | 
					
						
							|  |  |  |     if (graphicsObject) | 
					
						
							|  |  |  |         return graphicsObject->parentObject(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return object->parent(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ObjectNodeInstance::Pointer ObjectNodeInstance::parentInstance() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QObject *parentHolder = parent(); | 
					
						
							|  |  |  |     if (!nodeInstanceServer()) | 
					
						
							|  |  |  |         return Pointer(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while (parentHolder) { | 
					
						
							|  |  |  |         if (nodeInstanceServer()->hasInstanceForObject(parentHolder)) | 
					
						
							|  |  |  |             return nodeInstanceServer()->instanceForObject(parentHolder).internalInstance(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         parentHolder = parentObject(parentHolder); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return Pointer(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | QRectF ObjectNodeInstance::boundingRect() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QRect(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QPointF ObjectNodeInstance::position() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QPointF(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QSizeF ObjectNodeInstance::size() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return QSizeF(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-11 18:34:58 +01:00
										 |  |  | int ObjectNodeInstance::penWidth() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-04 14:28:19 +01:00
										 |  |  | void ObjectNodeInstance::createDynamicProperty(const QString &name, const QString &/*typeName*/) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-07 18:53:48 +02:00
										 |  |  |     if (m_metaObject == 0) { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |         qWarning() << "ObjectNodeInstance.createDynamicProperty: No Metaobject."; | 
					
						
							| 
									
										
										
										
											2010-04-07 18:53:48 +02:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     m_metaObject->createNewProperty(name); | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | bool ObjectNodeInstance::updateStateVariant(const ObjectNodeInstance::Pointer &/*target*/, const QString &/*propertyName*/, const QVariant &/*value*/) | 
					
						
							| 
									
										
										
										
											2010-03-22 13:18:52 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | bool ObjectNodeInstance::updateStateBinding(const ObjectNodeInstance::Pointer &/*target*/, const QString &/*propertyName*/, const QString &/*expression*/) | 
					
						
							| 
									
										
										
										
											2010-03-22 13:18:52 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | bool ObjectNodeInstance::resetStateProperty(const ObjectNodeInstance::Pointer &/*target*/, const QString &/*propertyName*/, const QVariant &/*resetValue*/) | 
					
						
							| 
									
										
										
										
											2010-03-22 13:18:52 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | void ObjectNodeInstance::doComponentComplete() | 
					
						
							| 
									
										
										
										
											2010-09-20 14:05:22 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | bool ObjectNodeInstance::isRootNodeInstance() const | 
					
						
							| 
									
										
										
										
											2010-09-23 16:04:16 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     return nodeInstanceServer()->rootNodeInstance().isWrappingThisObject(object()); | 
					
						
							| 
									
										
										
										
											2010-09-23 16:04:16 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | bool ObjectNodeInstance::isValid() const | 
					
						
							| 
									
										
										
										
											2010-10-05 20:55:31 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  |     return instanceId() >= 0 && object(); | 
					
						
							| 
									
										
										
										
											2010-10-05 20:55:31 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-11-24 14:52:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-07 12:14:35 +01:00
										 |  |  | } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |