diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-08-03 16:17:19 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2016-08-09 08:06:16 +0000 |
commit | 107a52b8a7019b66b4cb3279e7bf070d5b57c2e0 (patch) | |
tree | c633860d4345d6629fa066d56b99fe9335dba474 /src/qml/qml/qqmlproperty.cpp | |
parent | c3cbbf362c769b065fd0586b0510d043cbae92a4 (diff) |
QML: Split off value type information from property data
Change-Id: I2ae2fb0f18af9b866cc9482fd4f42d9d4269f8cb
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlproperty.cpp')
-rw-r--r-- | src/qml/qml/qqmlproperty.cpp | 90 |
1 files changed, 22 insertions, 68 deletions
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 33f3b96389..ffa9bfa3a7 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -306,10 +306,9 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name) object = currentObject; core = *property; - core.setAsValueTypeVirtual(); - core.valueTypeFlags = QQmlPropertyData::flagsForProperty(vtProp); - core.valueTypePropType = vtProp.userType(); - core.valueTypeCoreIndex = idx; + valueTypeData.setFlags(QQmlPropertyData::flagsForProperty(vtProp)); + valueTypeData.propType = vtProp.userType(); + valueTypeData.coreIndex = idx; return; } else { @@ -473,7 +472,7 @@ const char *QQmlProperty::propertyTypeName() const if (d->isValueType()) { const QMetaObject *valueTypeMetaObject = QQmlValueTypeFactory::metaObjectForMetaType(d->core.propType); Q_ASSERT(valueTypeMetaObject); - return valueTypeMetaObject->property(d->core.valueTypeCoreIndex).typeName(); + return valueTypeMetaObject->property(d->valueTypeData.coreIndex).typeName(); } else if (d->object && type() & Property && d->core.isValid()) { return d->object->metaObject()->property(d->core.coreIndex).typeName(); } else { @@ -493,10 +492,7 @@ bool QQmlProperty::operator==(const QQmlProperty &other) const // from the other members return d->object == other.d->object && d->core.coreIndex == other.d->core.coreIndex && - d->core.isValueTypeVirtual() == other.d->core.isValueTypeVirtual() && - (!d->core.isValueTypeVirtual() || - (d->core.valueTypeCoreIndex == other.d->core.valueTypeCoreIndex && - d->core.valueTypePropType == other.d->core.valueTypePropType)); + d->valueTypeData.coreIndex == other.d->valueTypeData.coreIndex; } /*! @@ -510,14 +506,14 @@ int QQmlProperty::propertyType() const bool QQmlPropertyPrivate::isValueType() const { - return core.isValueTypeVirtual(); + return valueTypeData.isValid(); } int QQmlPropertyPrivate::propertyType() const { uint type = this->type(); if (isValueType()) { - return core.valueTypePropType; + return valueTypeData.propType; } else if (type & QQmlProperty::Property) { return core.propType; } else { @@ -653,7 +649,7 @@ QString QQmlProperty::name() const const QMetaObject *valueTypeMetaObject = QQmlValueTypeFactory::metaObjectForMetaType(d->core.propType); Q_ASSERT(valueTypeMetaObject); - const char *vtName = valueTypeMetaObject->property(d->core.valueTypeCoreIndex).name(); + const char *vtName = valueTypeMetaObject->property(d->valueTypeData.coreIndex).name(); rv += QString::fromUtf8(vtName); d->nameCache = rv; @@ -708,7 +704,8 @@ QQmlPropertyPrivate::binding(const QQmlProperty &that) if (!that.d || !that.isProperty() || !that.d->object) return 0; - return binding(that.d->object, that.d->core.encodedIndex()); + QQmlPropertyIndex thatIndex(that.d->core.coreIndex, that.d->valueTypeData.coreIndex); + return binding(that.d->object, thatIndex); } /*! @@ -791,7 +788,7 @@ void QQmlPropertyPrivate::removeBinding(const QQmlProperty &that) if (!that.d || !that.isProperty() || !that.d->object) return; - removeBinding(that.d->object, that.d->core.encodedIndex()); + removeBinding(that.d->object, that.d->encodedIndex()); } QQmlAbstractBinding * @@ -1030,7 +1027,7 @@ QVariant QQmlPropertyPrivate::readValueProperty() QQmlValueType *valueType = QQmlValueTypeFactory::valueType(core.propType); Q_ASSERT(valueType); valueType->read(object, core.coreIndex); - return valueType->metaObject()->property(core.valueTypeCoreIndex).read(valueType); + return valueType->metaObject()->property(valueTypeData.coreIndex).read(valueType); } else if (core.isQList()) { @@ -1148,38 +1145,28 @@ bool QQmlPropertyPrivate::writeEnumProperty(const QMetaProperty &prop, int idx, bool QQmlPropertyPrivate::writeValueProperty(const QVariant &value, QQmlPropertyData::WriteFlags flags) { - return writeValueProperty(object, core, value, effectiveContext(), flags); + return writeValueProperty(object, core, valueTypeData, value, effectiveContext(), flags); } bool QQmlPropertyPrivate::writeValueProperty(QObject *object, const QQmlPropertyData &core, + const QQmlPropertyData &valueTypeData, const QVariant &value, QQmlContextData *context,QQmlPropertyData::WriteFlags flags) { // Remove any existing bindings on this property if (!(flags & QQmlPropertyData::DontRemoveBinding) && object) - removeBinding(object, core.encodedIndex()); + removeBinding(object, encodedIndex(core, valueTypeData)); bool rv = false; - if (core.isValueTypeVirtual()) { - + if (valueTypeData.isValid()) { QQmlValueType *writeBack = QQmlValueTypeFactory::valueType(core.propType); writeBack->read(object, core.coreIndex); - - QQmlPropertyData data = core; - data.setFlags(core.valueTypeFlags); - data.coreIndex = core.valueTypeCoreIndex; - data.propType = core.valueTypePropType; - - rv = write(writeBack, data, value, context, flags); - + rv = write(writeBack, valueTypeData, value, context, flags); writeBack->write(object, core.coreIndex, flags); - } else { - rv = write(object, core, value, context, flags); - } return rv; @@ -1603,56 +1590,23 @@ int QQmlProperty::index() const QQmlPropertyIndex QQmlPropertyPrivate::propertyIndex(const QQmlProperty &that) { - return that.d ? that.d->core.encodedIndex() : QQmlPropertyIndex(); -} - -/*! - Returns the "property index" for use in bindings. The top 16 bits are the value type - offset, and 0 otherwise. The bottom 16 bits are the regular property index. -*/ -int QQmlPropertyPrivate::bindingIndex(const QQmlProperty &that) -{ - if (!that.d) - return -1; - return bindingIndex(that.d->core); -} - -int QQmlPropertyPrivate::bindingIndex(const QQmlPropertyData &that) -{ - int rv = that.coreIndex; - if (rv != -1 && that.isValueTypeVirtual()) - rv = rv | (that.valueTypeCoreIndex << 16); - return rv; -} - -QQmlPropertyData -QQmlPropertyPrivate::saveValueType(const QQmlPropertyData &base, - const QMetaObject *subObject, int subIndex, - QQmlEngine *) -{ - QMetaProperty subProp = subObject->property(subIndex); - - QQmlPropertyData core = base; - core.setAsValueTypeVirtual(); - core.valueTypeFlags = QQmlPropertyData::flagsForProperty(subProp); - core.valueTypeCoreIndex = subIndex; - core.valueTypePropType = subProp.userType(); - - return core; + return that.d ? that.d->encodedIndex() : QQmlPropertyIndex(); } QQmlProperty QQmlPropertyPrivate::restore(QObject *object, const QQmlPropertyData &data, - QQmlContextData *ctxt) + const QQmlPropertyData *valueTypeData, QQmlContextData *ctxt) { QQmlProperty prop; prop.d = new QQmlPropertyPrivate; prop.d->object = object; prop.d->context = ctxt; - prop.d->engine = ctxt?ctxt->engine:0; + prop.d->engine = ctxt ? ctxt->engine : nullptr; prop.d->core = data; + if (valueTypeData) + prop.d->valueTypeData = *valueTypeData; return prop; } |