forked from qt-creator/qt-creator
refactor NodeInstanceMetaObject
Reduce the use of NodeInstanceMetaObject in QtQuickDesigner code to two static methods: - registerNodeInstanceMetaObject - createNewDynamicProperty Change-Id: I0ef8ee96995184e968467b799147c6b4c80fbccc Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
committed by
Thomas Hartmann
parent
8409c6a724
commit
3c9efc3e72
@@ -110,7 +110,13 @@ static QQmlPropertyCache *cacheForObject(QObject *object, QQmlEngine *engine)
|
||||
return QQmlEnginePrivate::get(engine)->cache(object);
|
||||
}
|
||||
|
||||
NodeInstanceMetaObject *NodeInstanceMetaObject::createNodeInstanceMetaObject(const ObjectNodeInstancePointer &nodeInstance)
|
||||
void NodeInstanceMetaObject::registerNodeInstanceMetaObject(const ObjectNodeInstancePointer &nodeInstance)
|
||||
{
|
||||
// we just create one and the ownership goes automatically to the object in nodeinstance see init method
|
||||
getNodeInstanceMetaObject(nodeInstance);
|
||||
}
|
||||
|
||||
NodeInstanceMetaObject* NodeInstanceMetaObject::getNodeInstanceMetaObject(const ObjectNodeInstancePointer &nodeInstance)
|
||||
{
|
||||
//Avoid setting up multiple NodeInstanceMetaObjects on the same QObject
|
||||
QObjectPrivate *op = QObjectPrivate::get(nodeInstance->object());
|
||||
@@ -118,6 +124,7 @@ NodeInstanceMetaObject *NodeInstanceMetaObject::createNodeInstanceMetaObject(con
|
||||
if (nodeInstanceMetaObjectList.contains(parent))
|
||||
return static_cast<NodeInstanceMetaObject *>(parent);
|
||||
|
||||
// we just create one and the ownership goes automatically to the object in nodeinstance see init method
|
||||
return new NodeInstanceMetaObject(nodeInstance, nodeInstance->nodeInstanceServer()->engine());
|
||||
}
|
||||
|
||||
@@ -175,7 +182,12 @@ NodeInstanceMetaObject::~NodeInstanceMetaObject()
|
||||
nodeInstanceMetaObjectList.remove(this);
|
||||
}
|
||||
|
||||
void NodeInstanceMetaObject::createNewProperty(const QString &name)
|
||||
void NodeInstanceMetaObject::createNewDynamicProperty(const ObjectNodeInstancePointer &nodeInstance, const QString &name)
|
||||
{
|
||||
getNodeInstanceMetaObject(nodeInstance)->createNewDynamicProperty(name);
|
||||
}
|
||||
|
||||
void NodeInstanceMetaObject::createNewDynamicProperty(const QString &name)
|
||||
{
|
||||
int id = m_type->createProperty(name.toUtf8());
|
||||
copyTypeMetaObject();
|
||||
|
||||
@@ -51,13 +51,15 @@ struct MetaPropertyData;
|
||||
class NodeInstanceMetaObject : public QQmlVMEMetaObject
|
||||
{
|
||||
public:
|
||||
static NodeInstanceMetaObject *createNodeInstanceMetaObject(const ObjectNodeInstancePointer &nodeInstance);
|
||||
~NodeInstanceMetaObject();
|
||||
void createNewProperty(const QString &name);
|
||||
static void createNewDynamicProperty(const ObjectNodeInstancePointer &nodeInstance, const QString &name);
|
||||
static void registerNodeInstanceMetaObject(const ObjectNodeInstancePointer &nodeInstance);
|
||||
|
||||
protected:
|
||||
NodeInstanceMetaObject(const ObjectNodeInstancePointer &nodeInstance, QQmlEngine *engine);
|
||||
static NodeInstanceMetaObject* getNodeInstanceMetaObject(const ObjectNodeInstancePointer &nodeInstance);
|
||||
|
||||
void createNewDynamicProperty(const QString &name);
|
||||
int openMetaCall(QMetaObject::Call _c, int _id, void **_a);
|
||||
int metaCall(QMetaObject::Call _c, int _id, void **_a);
|
||||
void notifyPropertyChange(int id);
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#include "dummycontextobject.h"
|
||||
|
||||
#include <nodeinstancemetaobject.h>
|
||||
|
||||
#include <propertyabstractcontainer.h>
|
||||
#include <propertybindingcontainer.h>
|
||||
@@ -829,15 +830,13 @@ void NodeInstanceServer::setInstancePropertyBinding(const PropertyBindingContain
|
||||
bool stateBindingWasUpdated = activeStateInstance().updateStateBinding(instance, name, expression);
|
||||
if (!stateBindingWasUpdated) {
|
||||
if (bindingContainer.isDynamic())
|
||||
instance.setPropertyDynamicBinding(name, bindingContainer.dynamicTypeName(), expression);
|
||||
else
|
||||
instance.setPropertyBinding(name, expression);
|
||||
Internal::NodeInstanceMetaObject::createNewDynamicProperty(instance.internalInstance(), name);
|
||||
instance.setPropertyBinding(name, expression);
|
||||
}
|
||||
} else {
|
||||
if (bindingContainer.isDynamic())
|
||||
instance.setPropertyDynamicBinding(name, bindingContainer.dynamicTypeName(), expression);
|
||||
else
|
||||
instance.setPropertyBinding(name, expression);
|
||||
Internal::NodeInstanceMetaObject::createNewDynamicProperty(instance.internalInstance(), name);
|
||||
instance.setPropertyBinding(name, expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -863,15 +862,13 @@ void NodeInstanceServer::setInstancePropertyVariant(const PropertyValueContainer
|
||||
bool stateValueWasUpdated = activeStateInstance().updateStateVariant(instance, name, value);
|
||||
if (!stateValueWasUpdated) {
|
||||
if (valueContainer.isDynamic())
|
||||
instance.setPropertyDynamicVariant(name, valueContainer.dynamicTypeName(), value);
|
||||
else
|
||||
instance.setPropertyVariant(name, value);
|
||||
Internal::NodeInstanceMetaObject::createNewDynamicProperty(instance.internalInstance(), name);
|
||||
instance.setPropertyVariant(name, value);
|
||||
}
|
||||
} else { //base state
|
||||
if (valueContainer.isDynamic())
|
||||
instance.setPropertyDynamicVariant(name, valueContainer.dynamicTypeName(), value);
|
||||
else
|
||||
instance.setPropertyVariant(name, value);
|
||||
Internal::NodeInstanceMetaObject::createNewDynamicProperty(instance.internalInstance(), name);
|
||||
instance.setPropertyVariant(name, value);
|
||||
}
|
||||
|
||||
if (valueContainer.isDynamic() && valueContainer.instanceId() == 0 && engine())
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "objectnodeinstance.h"
|
||||
|
||||
#include <enumeration.h>
|
||||
#include <nodeinstancemetaobject.h>
|
||||
|
||||
#include <QEvent>
|
||||
#include <QQmlContext>
|
||||
@@ -106,7 +107,6 @@ namespace Internal {
|
||||
|
||||
ObjectNodeInstance::ObjectNodeInstance(QObject *object)
|
||||
: m_object(object),
|
||||
m_metaObject(0),
|
||||
m_instanceId(-1),
|
||||
m_deleteHeldInstance(true),
|
||||
m_isInLayoutable(false)
|
||||
@@ -145,7 +145,6 @@ void ObjectNodeInstance::destroy()
|
||||
}
|
||||
}
|
||||
|
||||
m_metaObject = 0;
|
||||
m_instanceId = -1;
|
||||
}
|
||||
|
||||
@@ -171,14 +170,9 @@ void ObjectNodeInstance::setNodeInstanceServer(NodeInstanceServer *server)
|
||||
m_nodeInstanceServer = server;
|
||||
}
|
||||
|
||||
void ObjectNodeInstance::initializePropertyWatcher(const ObjectNodeInstance::Pointer &objectNodeInstance)
|
||||
{
|
||||
m_metaObject = NodeInstanceMetaObject::createNodeInstanceMetaObject(objectNodeInstance);
|
||||
}
|
||||
|
||||
void ObjectNodeInstance::initialize(const ObjectNodeInstance::Pointer &objectNodeInstance)
|
||||
{
|
||||
initializePropertyWatcher(objectNodeInstance);
|
||||
NodeInstanceMetaObject::registerNodeInstanceMetaObject(objectNodeInstance);
|
||||
}
|
||||
|
||||
void ObjectNodeInstance::setId(const QString &id)
|
||||
@@ -1402,16 +1396,6 @@ int ObjectNodeInstance::penWidth() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ObjectNodeInstance::createDynamicProperty(const QString &name, const QString &/*typeName*/)
|
||||
{
|
||||
if (m_metaObject == 0) {
|
||||
qWarning() << "ObjectNodeInstance.createDynamicProperty: No Metaobject.";
|
||||
return;
|
||||
}
|
||||
|
||||
m_metaObject->createNewProperty(name);
|
||||
}
|
||||
|
||||
bool ObjectNodeInstance::updateStateVariant(const ObjectNodeInstance::Pointer &/*target*/, const PropertyName &/*propertyName*/, const QVariant &/*value*/)
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#define OBJECTNODEINSTANCE_H
|
||||
|
||||
#include "nodeinstanceserver.h"
|
||||
#include "nodeinstancemetaobject.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QSharedPointer>
|
||||
@@ -84,7 +83,6 @@ public:
|
||||
|
||||
NodeInstanceServer *nodeInstanceServer() const;
|
||||
void setNodeInstanceServer(NodeInstanceServer *server);
|
||||
virtual void initializePropertyWatcher(const Pointer &objectNodeInstance);
|
||||
virtual void initialize(const Pointer &objectNodeInstance);
|
||||
virtual QImage renderImage() const;
|
||||
virtual QImage renderPreviewImage(const QSize &previewImageSize) const;
|
||||
@@ -142,7 +140,6 @@ public:
|
||||
virtual QList<ServerNodeInstance> childItems() const;
|
||||
virtual QList<QQuickItem*> allItemsRecursive() const;
|
||||
|
||||
void createDynamicProperty(const QString &PropertyName, const QString &typeName);
|
||||
void setDeleteHeldInstance(bool deleteInstance);
|
||||
bool deleteHeldInstance() const;
|
||||
|
||||
@@ -216,7 +213,6 @@ private:
|
||||
PropertyName m_parentProperty;
|
||||
|
||||
QPointer<QObject> m_object;
|
||||
NodeInstanceMetaObject *m_metaObject;
|
||||
qint32 m_instanceId;
|
||||
bool m_deleteHeldInstance;
|
||||
bool m_isInLayoutable;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "qt5nodeinstanceserver.h"
|
||||
|
||||
#include <QQmlProperty>
|
||||
#include <QQmlExpression>
|
||||
#include <QQuickView>
|
||||
#include <cmath>
|
||||
|
||||
@@ -322,23 +322,11 @@ void ServerNodeInstance::setPropertyVariant(const PropertyName &name, const QVar
|
||||
|
||||
}
|
||||
|
||||
void ServerNodeInstance::setPropertyDynamicVariant(const PropertyName &name, const TypeName &typeName, const QVariant &value)
|
||||
{
|
||||
m_nodeInstance->createDynamicProperty(name, typeName);
|
||||
m_nodeInstance->setPropertyVariant(name, value);
|
||||
}
|
||||
|
||||
void ServerNodeInstance::setPropertyBinding(const PropertyName &name, const QString &expression)
|
||||
{
|
||||
m_nodeInstance->setPropertyBinding(name, expression);
|
||||
}
|
||||
|
||||
void ServerNodeInstance::setPropertyDynamicBinding(const PropertyName &name, const TypeName &typeName, const QString &expression)
|
||||
{
|
||||
m_nodeInstance->createDynamicProperty(name, typeName);
|
||||
m_nodeInstance->setPropertyBinding(name, expression);
|
||||
}
|
||||
|
||||
void ServerNodeInstance::resetProperty(const PropertyName &name)
|
||||
{
|
||||
m_nodeInstance->resetProperty(name);
|
||||
|
||||
@@ -172,10 +172,8 @@ private: // functions
|
||||
ServerNodeInstance(const QSharedPointer<Internal::ObjectNodeInstance> &abstractInstance);
|
||||
|
||||
void setPropertyVariant(const PropertyName &name, const QVariant &value);
|
||||
void setPropertyDynamicVariant(const PropertyName &name, const TypeName &typeName, const QVariant &value);
|
||||
|
||||
void setPropertyBinding(const PropertyName &name, const QString &expression);
|
||||
void setPropertyDynamicBinding(const PropertyName &name, const TypeName &typeName, const QString &expression);
|
||||
|
||||
void resetProperty(const PropertyName &name);
|
||||
void refreshProperty(const PropertyName &name);
|
||||
|
||||
Reference in New Issue
Block a user