QmlDesigner.Instances: blacklist certain properties

For those properties the QQmlProperty constructor does crash.

Change-Id: Ia78583e080ced936d98517ce0d3244d3040f8ceb
Reviewed-by: Marco Bubke <marco.bubke@digia.com>
This commit is contained in:
Thomas Hartmann
2013-04-10 15:34:50 +02:00
parent 02e11c6cd7
commit 8a9fc63555

View File

@@ -54,6 +54,17 @@
#include <private/qqmltimer_p.h> #include <private/qqmltimer_p.h>
#include <private/qqmlengine_p.h> #include <private/qqmlengine_p.h>
static bool isPropertyBlackListed(const QmlDesigner::PropertyName &propertyName)
{
if (propertyName.contains(".") && propertyName.contains("__"))
return true;
if (propertyName.count(".") > 1)
return true;
return false;
}
namespace QmlDesigner { namespace QmlDesigner {
namespace Internal { namespace Internal {
@@ -536,6 +547,9 @@ void ObjectNodeInstance::refreshProperty(const PropertyName &name)
bool ObjectNodeInstance::hasBindingForProperty(const PropertyName &name, bool *hasChanged) const bool ObjectNodeInstance::hasBindingForProperty(const PropertyName &name, bool *hasChanged) const
{ {
if (isPropertyBlackListed(name))
return false;
QQmlProperty property(object(), name, context()); QQmlProperty property(object(), name, context());
bool hasBinding = QQmlPropertyPrivate::binding(property); bool hasBinding = QQmlPropertyPrivate::binding(property);
@@ -604,6 +618,9 @@ QVariant ObjectNodeInstance::property(const PropertyName &name) const
// TODO: handle model nodes // TODO: handle model nodes
if (isPropertyBlackListed(name))
return QVariant();
QQmlProperty property(object(), name, context()); QQmlProperty property(object(), name, context());
if (property.property().isEnumType()) { if (property.property().isEnumType()) {
QVariant value = property.read(); QVariant value = property.read();
@@ -666,6 +683,9 @@ PropertyNameList ObjectNodeInstance::propertyNames() const
QString ObjectNodeInstance::instanceType(const PropertyName &name) const QString ObjectNodeInstance::instanceType(const PropertyName &name) const
{ {
if (isPropertyBlackListed(name))
return QLatin1String("undefined");
QQmlProperty property(object(), name, context()); QQmlProperty property(object(), name, context());
if (!property.isValid()) if (!property.isValid())
return QLatin1String("undefined"); return QLatin1String("undefined");
@@ -785,7 +805,13 @@ static void disableTiledBackingStore(QObject *object)
Q_UNUSED(object); Q_UNUSED(object);
} }
PropertyNameList propertyNameForWritableProperties(QObject *object, const PropertyName &baseName = PropertyName(), QObjectList *inspectedObjects = new QObjectList()) static void addToPropertyNameListIfNotBlackListed(PropertyNameList *propertyNameList, const PropertyName &propertyName)
{
if (!isPropertyBlackListed(propertyName))
propertyNameList->append(propertyName);
}
PropertyNameList propertyNameListForWritableProperties(QObject *object, const PropertyName &baseName = PropertyName(), QObjectList *inspectedObjects = new QObjectList())
{ {
PropertyNameList propertyNameList; PropertyNameList propertyNameList;
@@ -802,16 +828,16 @@ PropertyNameList propertyNameForWritableProperties(QObject *object, const Proper
if (declarativeProperty.name() != "parent") { if (declarativeProperty.name() != "parent") {
QObject *childObject = QQmlMetaType::toQObject(declarativeProperty.read()); QObject *childObject = QQmlMetaType::toQObject(declarativeProperty.read());
if (childObject) if (childObject)
propertyNameList.append(propertyNameForWritableProperties(childObject, baseName + PropertyName(metaProperty.name()) + '.', inspectedObjects)); propertyNameList.append(propertyNameListForWritableProperties(childObject, baseName + PropertyName(metaProperty.name()) + '.', inspectedObjects));
} }
} else if (QQmlValueTypeFactory::valueType(metaProperty.userType())) { } else if (QQmlValueTypeFactory::valueType(metaProperty.userType())) {
QQmlValueType *valueType = QQmlValueTypeFactory::valueType(metaProperty.userType()); QQmlValueType *valueType = QQmlValueTypeFactory::valueType(metaProperty.userType());
valueType->setValue(metaProperty.read(object)); valueType->setValue(metaProperty.read(object));
propertyNameList.append(propertyNameForWritableProperties(valueType, baseName + PropertyName(metaProperty.name()) + '.', inspectedObjects)); propertyNameList.append(propertyNameListForWritableProperties(valueType, baseName + PropertyName(metaProperty.name()) + '.', inspectedObjects));
} }
if (metaProperty.isReadable() && metaProperty.isWritable()) { if (metaProperty.isReadable() && metaProperty.isWritable()) {
propertyNameList.append(baseName + PropertyName(metaProperty.name())); addToPropertyNameListIfNotBlackListed(&propertyNameList, baseName + PropertyName(metaProperty.name()));
} }
} }
@@ -823,7 +849,7 @@ static void fixResourcePathsForObject(QObject *object)
if (qgetenv("QMLDESIGNER_RC_PATHS").isEmpty()) if (qgetenv("QMLDESIGNER_RC_PATHS").isEmpty())
return; return;
PropertyNameList propertyNameList = propertyNameForWritableProperties(object); PropertyNameList propertyNameList = propertyNameListForWritableProperties(object);
foreach (const PropertyName &propertyName, propertyNameList) { foreach (const PropertyName &propertyName, propertyNameList) {
QQmlProperty property(object, propertyName, QQmlEngine::contextForObject(object)); QQmlProperty property(object, propertyName, QQmlEngine::contextForObject(object));
@@ -1039,7 +1065,7 @@ void ObjectNodeInstance::deactivateState()
void ObjectNodeInstance::populateResetHashes() void ObjectNodeInstance::populateResetHashes()
{ {
PropertyNameList propertyNameList = propertyNameForWritableProperties(object()); PropertyNameList propertyNameList = propertyNameListForWritableProperties(object());
foreach (const PropertyName &propertyName, propertyNameList) { foreach (const PropertyName &propertyName, propertyNameList) {
QQmlProperty property(object(), propertyName, QQmlEngine::contextForObject(object())); QQmlProperty property(object(), propertyName, QQmlEngine::contextForObject(object()));