QmlPuppet: move allPropertyNames() to QmlPrivateGate

This patch also fixes a memory leak.
The inspectedObjects in the default case were never deleted.
We now use a pointer to an object on the stack instead.

Change-Id: I07490e26b956e6c04911cb3e5e051704b2c2c35d
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
Thomas Hartmann
2015-05-19 10:04:50 +02:00
committed by Thomas Hartmann
parent 868c8e3fe7
commit d2e58eeeec
3 changed files with 54 additions and 37 deletions
@@ -683,44 +683,10 @@ QVariant ObjectNodeInstance::property(const PropertyName &name) const
return property.read();
}
PropertyNameList allPropertyNames(QObject *object, const PropertyName &baseName = PropertyName(), QObjectList *inspectedObjects = new QObjectList)
{
PropertyNameList propertyNameList;
if (inspectedObjects== 0 || inspectedObjects->contains(object))
return propertyNameList;
inspectedObjects->append(object);
const QMetaObject *metaObject = object->metaObject();
for (int index = 0; index < metaObject->propertyCount(); ++index) {
QMetaProperty metaProperty = metaObject->property(index);
QQmlProperty declarativeProperty(object, QLatin1String(metaProperty.name()));
if (declarativeProperty.isValid() && declarativeProperty.propertyTypeCategory() == QQmlProperty::Object) {
if (declarativeProperty.name() != "parent") {
QObject *childObject = QQmlMetaType::toQObject(declarativeProperty.read());
if (childObject)
propertyNameList.append(allPropertyNames(childObject, baseName + PropertyName(metaProperty.name()) + '.', inspectedObjects));
}
} else if (QQmlValueTypeFactory::valueType(metaProperty.userType())) {
QQmlValueType *valueType = QQmlValueTypeFactory::valueType(metaProperty.userType());
valueType->setValue(metaProperty.read(object));
propertyNameList.append(baseName + PropertyName(metaProperty.name()));
propertyNameList.append(allPropertyNames(valueType, baseName + PropertyName(metaProperty.name()) + '.', inspectedObjects));
} else {
propertyNameList.append(baseName + PropertyName(metaProperty.name()));
}
}
return propertyNameList;
}
PropertyNameList ObjectNodeInstance::propertyNames() const
{
if (isValid())
return allPropertyNames(object());
return QmlPrivateGate::allPropertyNames(object());
return PropertyNameList();
}