\brief The QQmlProperty class abstracts accessing properties on objects created from QML.
As QML uses Qt's meta-type system all of the existing QMetaObject classes can be used to introspect
-and interact with objects created by QML. However, some of the new features provided by QML - such
-as type safety and attached properties - are most easily used through the QQmlProperty class
+and interact with objects created by QML. However, some of the new features provided by QML - such
+as type safety and attached properties - are most easily used through the QQmlProperty class
that simplifies some of their natural complexity.
-Unlike QMetaProperty which represents a property on a class type, QQmlProperty encapsulates
-a property on a specific object instance. To read a property's value, programmers create a
+Unlike QMetaProperty which represents a property on a class type, QQmlProperty encapsulates
+a property on a specific object instance. To read a property's value, programmers create a
QQmlProperty instance and call the read() method. Likewise to write a property value the
write() method is used.
QMetaProperty p = QQmlMetaType::defaultProperty(obj);
core.load(p);
- if (core.isValid())
+ if (core.isValid())
object = obj;
}
Creates a QQmlProperty for the property \a name of \a obj
using the \l{QQmlContext} {context} \a ctxt.
- Creating a QQmlProperty without a context will render some
+ Creating a QQmlProperty without a context will render some
properties - like attached properties - inaccessible.
*/
QQmlProperty::QQmlProperty(QObject *obj, const QString &name, QQmlContext *ctxt)
{
}
-QQmlContextData *QQmlPropertyPrivate::effectiveContext() const
+QQmlContextData *QQmlPropertyPrivate::effectiveContext() const
{
if (context) return context;
else if (engine) return QQmlContextData::get(engine->rootContext());
++ii; r = typeNameCache->query(path.at(ii), r.importNamespace);
if (!r.type) return; // Invalid type in namespace
-
+
QQmlAttachedPropertiesFunc func = r.type->attachedPropertiesFunction();
if (!func) return; // Not an attachable type
if (!property) return; // Not a property
if (property->isFunction())
- return; // Not an object property
+ return; // Not an object property
if (ii == (path.count() - 2) && QQmlValueTypeFactory::isValueType(property->propType)) {
- // We're now at a value type property. We can use a global valuetypes array as we
+ // We're now at a value type property. We can use a global valuetypes array as we
// never actually use the objects, just look up their properties.
QObject *typeObject = (*qmlValueTypes())[property->propType];
if (!typeObject) return; // Not a value type
core.valueTypePropType = vtProp.userType();
core.valueTypeCoreIndex = idx;
- return;
+ return;
} else {
if (!property->isQObject())
return; // Not an object property
return d ? d->propertyTypeCategory() : InvalidCategory;
}
-QQmlProperty::PropertyTypeCategory
+QQmlProperty::PropertyTypeCategory
QQmlPropertyPrivate::propertyTypeCategory() const
{
uint type = this->type();
return QQmlProperty::Object;
else if (core.isQList())
return QQmlProperty::List;
- else
+ else
return QQmlProperty::Normal;
} else {
return QQmlProperty::InvalidCategory;
}
/*!
- Returns true if \a other and this QQmlProperty represent the same
+ Returns true if \a other and this QQmlProperty represent the same
property.
*/
bool QQmlProperty::operator==(const QQmlProperty &other) const
{
if (!d || !other.d)
return false;
- // category is intentially omitted here as it is generated
+ // category is intentially omitted here as it is generated
// from the other members
return d->object == other.d->object &&
d->core.coreIndex == other.d->core.coreIndex &&
}
/*!
- Returns the QVariant type of the property, or QVariant::Invalid if the
+ Returns the QVariant type of the property, or QVariant::Invalid if the
property has no QVariant type.
*/
int QQmlProperty::propertyType() const
}
/*!
- Return the QMetaMethod for this property if it is a SignalProperty,
+ Return the QMetaMethod for this property if it is a SignalProperty,
otherwise returns an invalid QMetaMethod.
*/
QMetaMethod QQmlProperty::method() const
}
/*!
- Returns the binding associated with this property, or 0 if no binding
+ Returns the binding associated with this property, or 0 if no binding
exists.
*/
QQmlAbstractBinding *
-QQmlPropertyPrivate::binding(const QQmlProperty &that)
+QQmlPropertyPrivate::binding(const QQmlProperty &that)
{
if (!that.d || !that.isProperty() || !that.d->object)
return 0;
- return binding(that.d->object, that.d->core.coreIndex,
+ return binding(that.d->object, that.d->core.coreIndex,
that.d->core.getValueTypeCoreIndex());
}
return binding;
}
-void QQmlPropertyPrivate::findAliasTarget(QObject *object, int bindingIndex,
+void QQmlPropertyPrivate::findAliasTarget(QObject *object, int bindingIndex,
QObject **targetObject, int *targetBindingIndex)
{
int coreIndex = bindingIndex & 0xFFFFFF;
Q_ASSERT(valueTypeIndex == -1 || aValueTypeIndex == -1);
int aBindingIndex = aCoreIndex;
- if (aValueTypeIndex != -1)
+ if (aValueTypeIndex != -1)
aBindingIndex |= aValueTypeIndex << 24;
else if (valueTypeIndex != -1)
aBindingIndex |= valueTypeIndex << 24;
}
}
- *targetObject = object;
+ *targetObject = object;
*targetBindingIndex = bindingIndex;
}
if (data && data->hasBindingBit(coreIndex)) {
binding = data->bindings;
- while (binding && binding->propertyIndex() != coreIndex)
+ while (binding && binding->propertyIndex() != coreIndex)
binding = binding->nextBinding();
}
if (valueTypeIndex != -1)
index |= (valueTypeIndex << 24);
- if (binding && valueTypeIndex != -1 && binding->bindingType() == QQmlAbstractBinding::ValueTypeProxy)
+ if (binding && valueTypeIndex != -1 && binding->bindingType() == QQmlAbstractBinding::ValueTypeProxy)
binding = static_cast<QQmlValueTypeProxyBinding *>(binding)->binding(index);
if (binding) {
if (data && data->hasBindingBit(coreIndex)) {
binding = data->bindings;
- while (binding && binding->propertyIndex() != coreIndex)
+ while (binding && binding->propertyIndex() != coreIndex)
binding = binding->nextBinding();
}
if (valueTypeIndex != -1)
index |= (valueTypeIndex << 24);
- if (binding && valueTypeIndex != -1 && binding->bindingType() == QQmlAbstractBinding::ValueTypeProxy)
+ if (binding && valueTypeIndex != -1 && binding->bindingType() == QQmlAbstractBinding::ValueTypeProxy)
binding = static_cast<QQmlValueTypeProxyBinding *>(binding)->binding(index);
- if (binding)
+ if (binding)
binding->removeFromObject();
if (newBinding) {
}
/*!
- Returns the expression associated with this signal property, or 0 if no
+ Returns the expression associated with this signal property, or 0 if no
signal expression exists.
*/
QQmlBoundSignalExpression *
}
/*!
-
+
Return the \a name property value of \a object using the environment
for instantiating QML components that is provided by \a engine. .
This method is equivalent to:
QQmlListProperty<QObject> prop;
void *args[] = { &prop, 0 };
QMetaObject::metacall(object, QMetaObject::ReadProperty, core.coreIndex, args);
- return QVariant::fromValue(QQmlListReferencePrivate::init(prop, core.propType, engine));
+ return QVariant::fromValue(QQmlListReferencePrivate::init(prop, core.propType, engine));
} else if (core.isQObject()) {
return writeValueProperty(object, engine, core, value, effectiveContext(), flags);
}
-bool
+bool
QQmlPropertyPrivate::writeValueProperty(QObject *object, QQmlEngine *engine,
const QQmlPropertyData &core,
- const QVariant &value,
+ const QVariant &value,
QQmlContextData *context, WriteFlags flags)
{
// Remove any existing bindings on this property
if (!(flags & DontRemoveBinding) && object) {
QQmlAbstractBinding *binding = setBinding(object, core.coreIndex,
- core.getValueTypeCoreIndex(),
+ core.getValueTypeCoreIndex(),
0, flags);
if (binding) binding->destroy();
}
bool QQmlPropertyPrivate::write(QObject *object,
const QQmlPropertyData &property,
- const QVariant &value, QQmlContextData *context,
+ const QVariant &value, QQmlContextData *context,
WriteFlags flags)
{
int coreIdx = property.coreIndex;
QMetaProperty prop = object->metaObject()->property(property.coreIndex);
QVariant v = value;
// Enum values come through the script engine as doubles
- if (value.userType() == QVariant::Double) {
+ if (value.userType() == QVariant::Double) {
double integral;
double fractional = modf(value.toDouble(), &integral);
if (qFuzzyIsNull(fractional))
} else if (property.isQObject()) {
QQmlMetaObject valMo = rawMetaObjectForType(enginePriv, value.userType());
-
+
if (valMo.isNull())
return false;
void *args[] = { &o, 0, &status, &flags };
QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, args);
} else if (!o && QQmlMetaObject::canConvert(propMo, valMo)) {
- // In the case of a null QObject, we assign the null if there is
- // any change that the null variant type could be up or down cast to
+ // In the case of a null QObject, we assign the null if there is
+ // any change that the null variant type could be up or down cast to
// the property type.
void *args[] = { &o, 0, &status, &flags };
QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, args);
}
// Returns true if successful, false if an error description was set on expression
-bool QQmlPropertyPrivate::writeBinding(QObject *object,
+bool QQmlPropertyPrivate::writeBinding(QObject *object,
const QQmlPropertyData &core,
QQmlContextData *context,
- QQmlJavaScriptExpression *expression,
+ QQmlJavaScriptExpression *expression,
v8::Handle<v8::Value> result, bool isUndefined,
WriteFlags flags)
{
if (!isUndefined && !core.isValueTypeVirtual()) {
switch (core.propType) {
case QMetaType::Int:
- if (result->IsInt32())
+ if (result->IsInt32())
QUICK_STORE(int, result->Int32Value())
else if (result->IsNumber())
QUICK_STORE(int, qRound(result->NumberValue()))
return false;
} else if (!writeValueProperty(object, engine, core, value, context, flags)) {
- if (watcher.wasDeleted())
+ if (watcher.wasDeleted())
return true;
const char *valueType = 0;
*/
bool QQmlProperty::write(QObject *object,
const QString &name,
- const QVariant &value,
+ const QVariant &value,
QQmlContext *ctxt)
{
QQmlProperty p(object, name, ctxt);
}
/*!
-
+
Writes \a value to the \a name property of \a object using the
environment for instantiating QML components that is provided by
\a engine. This method is equivalent to:
p.write(value);
\endcode
*/
-bool QQmlProperty::write(QObject *object, const QString &name, const QVariant &value,
+bool QQmlProperty::write(QObject *object, const QString &name, const QVariant &value,
QQmlEngine *engine)
{
QQmlProperty p(object, name, engine);
}
bool QQmlPropertyPrivate::write(const QQmlProperty &that,
- const QVariant &value, WriteFlags flags)
+ const QVariant &value, WriteFlags flags)
{
if (!that.d)
return false;
- if (that.d->object && that.type() & QQmlProperty::Property &&
- that.d->core.isValid() && that.isWritable())
+ if (that.d->object && that.type() & QQmlProperty::Property &&
+ that.d->core.isValid() && that.isWritable())
return that.d->writeValueProperty(value, flags);
- else
+ else
return false;
}
Returns true if the property needs a change notifier signal for bindings
to remain upto date, false otherwise.
- Some properties, such as attached properties or those whose value never
+ Some properties, such as attached properties or those whose value never
changes, do not require a change notifier.
*/
bool QQmlProperty::needsNotifySignal() const
}
/*!
-Connect \a sender \a signal_index to \a receiver \a method_index with the specified
+Connect \a sender \a signal_index to \a receiver \a method_index with the specified
\a type and \a types. This behaves identically to QMetaObject::connect() except that
it connects any lazy "proxy" signal connections set up by QML.
#define Q_INT16_MAX 32767
-class QQmlPropertyCacheMethodArguments
+class QQmlPropertyCacheMethodArguments
{
public:
QQmlPropertyCacheMethodArguments *next;
return flags;
}
-// Flags that do depend on the property's QMetaProperty::userType() and thus are slow to
+// Flags that do depend on the property's QMetaProperty::userType() and thus are slow to
// load
static QQmlPropertyData::Flags flagsForPropertyType(int propType, QQmlEngine *engine)
{
} else if (propType == qMetaTypeId<QQmlV8Handle>()) {
flags |= QQmlPropertyData::IsV8Handle;
} else {
- QQmlMetaType::TypeCategory cat =
+ QQmlMetaType::TypeCategory cat =
engine ? QQmlEnginePrivate::get(engine)->typeCategory(propType)
: QQmlMetaType::typeCategory(propType);
return rv;
}
-void QQmlPropertyCache::append(QQmlEngine *engine, const QMetaObject *metaObject,
- int revision,
+void QQmlPropertyCache::append(QQmlEngine *engine, const QMetaObject *metaObject,
+ int revision,
QQmlPropertyData::Flag propertyFlags,
QQmlPropertyData::Flag methodFlags,
QQmlPropertyData::Flag signalFlags)
if (ii == destroyedIdx1 || ii == destroyedIdx2 || ii == deleteLaterIdx)
continue;
QMetaMethod m = metaObject->method(ii);
- if (m.access() == QMetaMethod::Private)
+ if (m.access() == QMetaMethod::Private)
continue;
// Extract method name
data->lazyLoad(p, engine);
data->flags |= propertyFlags;
- if (!dynamicMetaObject)
+ if (!dynamicMetaObject)
data->flags |= QQmlPropertyData::IsDirect;
Q_ASSERT((allowedRevisionCache.count() - 1) < Q_INT16_MAX);
{
if (index < 0 || index >= (propertyIndexCacheStart + propertyIndexCache.count()))
return 0;
-
+
if (index < propertyIndexCacheStart)
return _parent->property(index);
QStringList QQmlPropertyCache::propertyNames() const
{
QStringList keys;
- for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
+ for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter)
keys.append(iter.key());
return keys;
}
if (scopeIdx != -1) {
scope = str.left(scopeIdx);
name = str.mid(scopeIdx + 2);
- } else {
+ } else {
name = str;
}
const QMetaObject *meta;
// Returns an array of the arguments for method \a index. The first entry in the array
// is the number of arguments.
-int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index,
+int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index,
QVarLengthArray<int, 9> &dummy,
QByteArray *unknownTypeError)
{
QQmlPropertyData *rv = const_cast<QQmlPropertyData *>(&c->methodIndexCache.at(index - c->methodIndexCacheStart));
- if (rv->arguments)
+ if (rv->arguments)
return static_cast<A *>(rv->arguments)->arguments;
const QMetaObject *metaObject = c->createMetaObject();
}
QQmlPropertyData *
-QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj,
+QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj,
const QHashedV8String &name, QQmlPropertyData &local)
{
return qQmlPropertyCacheProperty<QHashedV8String>(engine, obj, name, local);