forked from qt-creator/qt-creator
QmlPuppet: Bring back simplified NodeInstanceSignalSpy
A simplified version of NodeInstanceSignalSpy is required to track sub objects. I moved all private API usage to QmlPrivateGate. Change-Id: I86e3e5411eb43777a6b1ab5018a1b8fb9088c666 Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
@@ -13,6 +13,7 @@ HEADERS += $$PWD/childrenchangeeventfilter.h
|
||||
HEADERS += $$PWD/componentnodeinstance.h
|
||||
HEADERS += $$PWD/dummynodeinstance.h
|
||||
HEADERS += $$PWD/nodeinstanceserver.h
|
||||
HEADERS += $$PWD/nodeinstancesignalspy.h
|
||||
HEADERS += $$PWD/objectnodeinstance.h
|
||||
HEADERS += $$PWD/qmlpropertychangesnodeinstance.h
|
||||
HEADERS += $$PWD/qmlstatenodeinstance.h
|
||||
@@ -35,6 +36,7 @@ SOURCES += $$PWD/childrenchangeeventfilter.cpp
|
||||
SOURCES += $$PWD/componentnodeinstance.cpp
|
||||
SOURCES += $$PWD/dummynodeinstance.cpp
|
||||
SOURCES += $$PWD/nodeinstanceserver.cpp
|
||||
SOURCES += $$PWD/nodeinstancesignalspy.cpp
|
||||
SOURCES += $$PWD/objectnodeinstance.cpp
|
||||
SOURCES += $$PWD/qmlpropertychangesnodeinstance.cpp
|
||||
SOURCES += $$PWD/qmlstatenodeinstance.cpp
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Contact: http://www.qt.io/licensing
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms and
|
||||
** conditions see http://www.qt.io/terms-conditions. For further information
|
||||
** use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, The Qt Company gives you certain additional
|
||||
** rights. These rights are described in The Qt Company LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "nodeinstancesignalspy.h"
|
||||
#include "objectnodeinstance.h"
|
||||
|
||||
#include <qmlprivategate.h>
|
||||
|
||||
#include <QMetaProperty>
|
||||
#include <QMetaObject>
|
||||
#include <QDebug>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include <QQmlProperty>
|
||||
|
||||
namespace QmlDesigner {
|
||||
namespace Internal {
|
||||
|
||||
NodeInstanceSignalSpy::NodeInstanceSignalSpy() :
|
||||
QObject()
|
||||
{
|
||||
blockSignals(true);
|
||||
}
|
||||
|
||||
void NodeInstanceSignalSpy::setObjectNodeInstance(const ObjectNodeInstance::Pointer &nodeInstance)
|
||||
{
|
||||
methodeOffset = QObject::staticMetaObject.methodCount() + 1;
|
||||
registerObject(nodeInstance->object());
|
||||
m_objectNodeInstance = nodeInstance;
|
||||
|
||||
}
|
||||
|
||||
void NodeInstanceSignalSpy::registerObject(QObject *spiedObject)
|
||||
{
|
||||
if (m_registeredObjectList.contains(spiedObject)) // prevent cycles
|
||||
return;
|
||||
|
||||
m_registeredObjectList.append(spiedObject);
|
||||
for (int index = QObject::staticMetaObject.propertyOffset();
|
||||
index < spiedObject->metaObject()->propertyCount();
|
||||
index++) {
|
||||
QMetaProperty metaProperty = spiedObject->metaObject()->property(index);
|
||||
|
||||
registerProperty(metaProperty, spiedObject);
|
||||
registerChildObject(metaProperty, spiedObject);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeInstanceSignalSpy::registerProperty(const QMetaProperty &metaProperty, QObject *spiedObject, const PropertyName &propertyPrefix)
|
||||
{
|
||||
if (metaProperty.isReadable()
|
||||
&& metaProperty.isWritable()
|
||||
&& !QmlPrivateGate::isPropertyQObject(metaProperty)
|
||||
&& metaProperty.hasNotifySignal()) {
|
||||
QMetaMethod metaMethod = metaProperty.notifySignal();
|
||||
QMetaObject::connect(spiedObject, metaMethod.methodIndex(), this, methodeOffset, Qt::DirectConnection);
|
||||
|
||||
m_indexPropertyHash.insert(methodeOffset, propertyPrefix + PropertyName(metaProperty.name()));
|
||||
|
||||
|
||||
methodeOffset++;
|
||||
}
|
||||
}
|
||||
|
||||
void NodeInstanceSignalSpy::registerChildObject(const QMetaProperty &metaProperty, QObject *spiedObject)
|
||||
{
|
||||
if (metaProperty.isReadable()
|
||||
&& !metaProperty.isWritable()
|
||||
&& QmlPrivateGate::isPropertyQObject(metaProperty)
|
||||
&& QLatin1String(metaProperty.name()) != "parent") {
|
||||
QObject *childObject = QmlPrivateGate::readQObjectProperty(metaProperty, spiedObject);
|
||||
|
||||
if (childObject) {
|
||||
for (int index = QObject::staticMetaObject.propertyOffset();
|
||||
index < childObject->metaObject()->propertyCount();
|
||||
index++) {
|
||||
QMetaProperty childMetaProperty = childObject->metaObject()->property(index);
|
||||
registerProperty(childMetaProperty, childObject, PropertyName(metaProperty.name()) + '.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int NodeInstanceSignalSpy::qt_metacall(QMetaObject::Call call, int methodId, void **a)
|
||||
{
|
||||
if (call == QMetaObject::InvokeMetaMethod && methodId > QObject::staticMetaObject.methodCount()) {
|
||||
ObjectNodeInstance::Pointer nodeInstance = m_objectNodeInstance.toStrongRef();
|
||||
|
||||
if (nodeInstance && nodeInstance->nodeInstanceServer() && nodeInstance->isValid()) {
|
||||
foreach (const PropertyName &propertyName, m_indexPropertyHash.values(methodId))
|
||||
nodeInstance->nodeInstanceServer()->notifyPropertyChange(nodeInstance->instanceId(), propertyName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return QObject::qt_metacall(call, methodId, a);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlDesigner
|
||||
@@ -0,0 +1,72 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Contact: http://www.qt.io/licensing
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms and
|
||||
** conditions see http://www.qt.io/terms-conditions. For further information
|
||||
** use the contact form at http://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 or version 3 as published by the Free
|
||||
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||
** following information to ensure the GNU Lesser General Public License
|
||||
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, The Qt Company gives you certain additional
|
||||
** rights. These rights are described in The Qt Company LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef NODEINSTANCESIGNALSPY_H
|
||||
#define NODEINSTANCESIGNALSPY_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "nodeinstanceglobal.h"
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class ObjectNodeInstance;
|
||||
typedef QSharedPointer<ObjectNodeInstance> ObjectNodeInstancePointer;
|
||||
typedef QWeakPointer<ObjectNodeInstance> ObjectNodeInstanceWeakPointer;
|
||||
|
||||
class NodeInstanceSignalSpy : public QObject
|
||||
{
|
||||
public:
|
||||
explicit NodeInstanceSignalSpy();
|
||||
|
||||
void setObjectNodeInstance(const ObjectNodeInstancePointer &nodeInstance);
|
||||
|
||||
virtual int qt_metacall(QMetaObject::Call, int, void **);
|
||||
|
||||
protected:
|
||||
void registerObject(QObject *spiedObject);
|
||||
void registerProperty(const QMetaProperty &metaProperty, QObject *spiedObject, const PropertyName &propertyPrefix = PropertyName());
|
||||
void registerChildObject(const QMetaProperty &metaProperty, QObject *spiedObject);
|
||||
|
||||
private:
|
||||
int methodeOffset;
|
||||
QMultiHash<int, PropertyName> m_indexPropertyHash;
|
||||
QObjectList m_registeredObjectList;
|
||||
ObjectNodeInstanceWeakPointer m_objectNodeInstance;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlDesigner
|
||||
|
||||
#endif // NODEINSTANCESIGNALSPY_H
|
||||
@@ -125,8 +125,14 @@ void ObjectNodeInstance::setNodeInstanceServer(NodeInstanceServer *server)
|
||||
m_nodeInstanceServer = server;
|
||||
}
|
||||
|
||||
void ObjectNodeInstance::initializePropertyWatcher(const ObjectNodeInstance::Pointer &objectNodeInstance)
|
||||
{
|
||||
m_signalSpy.setObjectNodeInstance(objectNodeInstance);
|
||||
}
|
||||
|
||||
void ObjectNodeInstance::initialize(const ObjectNodeInstance::Pointer &objectNodeInstance)
|
||||
{
|
||||
initializePropertyWatcher(objectNodeInstance);
|
||||
QmlPrivateGate::registerNodeInstanceMetaObject(objectNodeInstance);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#define OBJECTNODEINSTANCE_H
|
||||
|
||||
#include "nodeinstanceserver.h"
|
||||
#include "nodeinstancesignalspy.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QSharedPointer>
|
||||
@@ -206,6 +207,7 @@ protected:
|
||||
static QObject *parentObject(QObject *object);
|
||||
static QVariant enumationValue(const Enumeration &enumeration);
|
||||
|
||||
void initializePropertyWatcher(const ObjectNodeInstance::Pointer &objectNodeInstance);
|
||||
private:
|
||||
QString m_id;
|
||||
|
||||
@@ -213,6 +215,9 @@ private:
|
||||
PropertyName m_parentProperty;
|
||||
|
||||
QPointer<QObject> m_object;
|
||||
|
||||
NodeInstanceSignalSpy m_signalSpy;
|
||||
|
||||
qint32 m_instanceId;
|
||||
bool m_deleteHeldInstance;
|
||||
bool m_isInLayoutable;
|
||||
|
||||
@@ -42,14 +42,14 @@
|
||||
|
||||
#include <private/qabstractanimation_p.h>
|
||||
#include <private/qobject_p.h>
|
||||
#include <private/qqmltimer_p.h>
|
||||
#include <private/qquickanimation_p.h>
|
||||
#include <private/qquicktransition_p.h>
|
||||
#include <private/qquickbehavior_p.h>
|
||||
#include <private/qquicktext_p.h>
|
||||
#include <private/qquicktextinput_p.h>
|
||||
#include <private/qquicktextedit_p.h>
|
||||
#include <private/qquicktransition_p.h>
|
||||
#include <private/qquickanimation_p.h>
|
||||
#include <private/qqmlmetatype_p.h>
|
||||
#include <private/qqmltimer_p.h>
|
||||
|
||||
#include <designersupport.h>
|
||||
|
||||
@@ -570,6 +570,16 @@ void stopUnifiedTimer()
|
||||
QUnifiedTimer::instance()->setSlowModeEnabled(true);
|
||||
}
|
||||
|
||||
bool isPropertyQObject(const QMetaProperty &metaProperty)
|
||||
{
|
||||
return QQmlMetaType::isQObject(metaProperty.userType());
|
||||
}
|
||||
|
||||
QObject *readQObjectProperty(const QMetaProperty &metaProperty, QObject *object)
|
||||
{
|
||||
return QQmlMetaType::toQObject(metaProperty.read(object));
|
||||
}
|
||||
|
||||
ComponentCompleteDisabler::ComponentCompleteDisabler()
|
||||
{
|
||||
DesignerSupport::disableComponentComplete();
|
||||
|
||||
@@ -86,6 +86,7 @@ public:
|
||||
QVariant getResetValue(QObject *object, const PropertyName &propertyName);
|
||||
void doResetProperty(QObject *object, QQmlContext *context, const PropertyName &propertyName);
|
||||
bool hasValidResetBinding(QObject *object, const PropertyName &propertyName);
|
||||
|
||||
bool hasBindingForProperty(QObject *object, QQmlContext *context, const PropertyName &propertyName, bool *hasChanged);
|
||||
void setPropertyBinding(QObject *object, QQmlContext *context, const PropertyName &propertyName, const QString &expression);
|
||||
void keepBindingFromGettingDeleted(QObject *object, QQmlContext *context, const PropertyName &propertyName);
|
||||
@@ -98,6 +99,9 @@ public:
|
||||
void disableTransition(QObject *object);
|
||||
void disableBehaivour(QObject *object);
|
||||
void stopUnifiedTimer();
|
||||
bool isPropertyQObject(const QMetaProperty &metaProperty);
|
||||
QObject *readQObjectProperty(const QMetaProperty &metaProperty, QObject *object);
|
||||
|
||||
|
||||
} // namespace QmlPrivateGate
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user