diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/qmlbindablevalue.cpp | 104 | ||||
-rw-r--r-- | src/declarative/qml/qmlbindablevalue.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qmlmetaproperty.cpp | 436 | ||||
-rw-r--r-- | src/declarative/qml/qmlproxymetaobject.cpp | 2 | ||||
-rw-r--r-- | src/declarative/qml/qmlvme.cpp | 1 |
5 files changed, 158 insertions, 386 deletions
diff --git a/src/declarative/qml/qmlbindablevalue.cpp b/src/declarative/qml/qmlbindablevalue.cpp index de01387..e1b6961 100644 --- a/src/declarative/qml/qmlbindablevalue.cpp +++ b/src/declarative/qml/qmlbindablevalue.cpp @@ -58,12 +58,6 @@ QmlBindableValuePrivate::QmlBindableValuePrivate() } QML_DEFINE_NOCREATE_TYPE(QmlBindableValue); -QmlBindableValue::QmlBindableValue(QObject *parent) -: QmlPropertyValueSource(*new QmlBindableValuePrivate, parent) -{ - qFatal("QmlBindableValue: Default constructor not supported"); -} - QmlBindableValue::QmlBindableValue(void *data, QmlRefCount *rc, QObject *obj, QObject *parent) : QmlPropertyValueSource(*new QmlBindableValuePrivate, parent), QmlExpression(QmlContext::activeContext(), data, rc, obj) { @@ -125,105 +119,25 @@ void QmlBindableValue::update() if (!d->updating) { d->updating = true; - if (d->property.propertyCategory() == QmlMetaProperty::List) { - QVariant value = this->value(); - int listType = QmlMetaType::listType(d->property.propertyType()); - - if (value.userType() == qMetaTypeId<QList<QObject *> >()) { - const QList<QObject *> &list = - qvariant_cast<QList<QObject *> >(value); - QVariant listVar = d->property.read(); - QmlMetaType::clear(listVar); - for (int ii = 0; ii < list.count(); ++ii) { - QVariant v = QmlMetaType::fromObject(list.at(ii), listType); - QmlMetaType::append(listVar, v); - } - - } else if (value.type() == uint(listType) || - value.userType() == listType) { - QVariant listVar = d->property.read(); - QmlMetaType::clear(listVar); - QmlMetaType::append(listVar, value); - } - } else if (d->property.propertyCategory() == QmlMetaProperty::QmlList) { - // XXX - optimize! - QVariant value = this->value(); - QVariant list = d->property.read(); - QmlPrivate::ListInterface *li = - *(QmlPrivate::ListInterface **)list.constData(); - - int type = li->type(); - - if (QObject *obj = QmlMetaType::toQObject(value)) { - const QMetaObject *mo = - QmlMetaType::rawMetaObjectForType(type); - - const QMetaObject *objMo = obj->metaObject(); - bool found = false; - while(!found && objMo) { - if (objMo == mo) - found = true; - else - objMo = objMo->superClass(); - } - - if (!found) { - qWarning() << "Unable to assign object to list"; - return; - } - - // NOTE: This assumes a cast to QObject does not alter - // the object pointer - void *d = (void *)&obj; - li->append(d); - } - } else if (d->property.propertyCategory() == QmlMetaProperty::Bindable) { - - // NOTE: We assume that only core properties can have - // propertyType == Bindable + if (d->property.propertyCategory() == QmlMetaProperty::Bindable) { + int idx = d->property.coreIndex(); Q_ASSERT(idx != -1); void *a[1]; QmlBindableValue *t = this; a[0] = (void *)&t; - d->property.object()->qt_metacall(QMetaObject::WriteProperty, - idx, a); + QMetaObject::metacall(d->property.object(), + QMetaObject::WriteProperty, + idx, a); - } else if (d->property.propertyCategory() == QmlMetaProperty::Object) { + } else { QVariant value = this->value(); - if ((int)value.type() != qMetaTypeId<QObject *>()) { - if (scriptWarnings()) { - if (!value.isValid()) { - qWarning() << "QmlBindableValue: Unable to assign invalid value to object property"; - } else { - qWarning() << "QmlBindableValue: Unable to assign non-object to object property"; - } - } - return; - } - - // NOTE: This assumes a cast to QObject does not alter the - // object pointer - QObject *obj = *(QObject **)value.data(); - - // NOTE: We assume that only core properties can have - // propertyType == Object - int idx = d->property.coreIndex(); - Q_ASSERT(idx != -1); - - void *a[1]; - a[0] = (void *)&obj; - d->property.object()->qt_metacall(QMetaObject::WriteProperty, - idx, a); - - } else if (d->property.propertyCategory() == QmlMetaProperty::Normal) { - QVariant value = this->value(); - if (d->property.propertyType() == QVariant::Url && value.canConvert(QVariant::String) && !value.isNull()) { - // Must resolve first + if (d->property.propertyType() == QVariant::Url && + value.canConvert(QVariant::String) && !value.isNull()) value.setValue(context()->resolvedUrl(value.toString())); - } + d->property.write(value); } diff --git a/src/declarative/qml/qmlbindablevalue.h b/src/declarative/qml/qmlbindablevalue.h index 71a7051..f54481a 100644 --- a/src/declarative/qml/qmlbindablevalue.h +++ b/src/declarative/qml/qmlbindablevalue.h @@ -62,7 +62,6 @@ class Q_DECLARATIVE_EXPORT QmlBindableValue : public QmlPropertyValueSource, { Q_OBJECT public: - QmlBindableValue(QObject *parent); QmlBindableValue(const QString &, QObject *, QObject *parent=0); QmlBindableValue(void *, QmlRefCount *, QObject *, QObject *parent); ~QmlBindableValue(); diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 4f39ebc..a152807 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -646,159 +646,179 @@ void QmlMetaPropertyPrivate::writeValueProperty(const QVariant &value) v.convert(QVariant::Int); } prop.write(object, v); - } else { - if (!value.isValid()) + return; + } + + if (!value.isValid()) + return; + + int t = propertyType(); + int vt = value.userType(); + int category = propertyCategory(); + + if (vt == t) { + + void *a[1]; + a[0] = (void *)value.constData(); + QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); + + } else if (qMetaTypeId<QVariant>() == t) { + + prop.write(object, value); + + } else if (category == QmlMetaProperty::Object) { + + QObject *o = QmlMetaType::toQObject(value); + + if (!o) return; - int t = propertyType(); - int vt = value.type(); + const QMetaObject *valMo = o->metaObject(); + const QMetaObject *propMo = QmlMetaType::rawMetaObjectForType(t); - if (vt == t || - value.userType() == t) { + while (valMo) { + if (valMo == propMo) + break; + valMo = valMo->superClass(); + } - void *a[1]; - a[0] = (void *)value.constData(); - QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, a); + if (valMo) { - } else if (qMetaTypeId<QVariant>() == t) { + void *args[] = { &o, 0 }; + QMetaObject::metacall(object, QMetaObject::WriteProperty, coreIdx, + args); - prop.write(object, value); + } - } else if (propertyCategory() == QmlMetaProperty::Object) { + } else if (category == QmlMetaProperty::List) { - QObject *o = QmlMetaType::toQObject(value); - if (o) - prop.write(object, QmlMetaType::fromObject(o, propertyType())); + int listType = QmlMetaType::listType(t); - } else if (propertyCategory() == QmlMetaProperty::List) { + if (value.userType() == qMetaTypeId<QList<QObject *> >()) { + const QList<QObject *> &list = + qvariant_cast<QList<QObject *> >(value); + QVariant listVar = prop.read(object); + QmlMetaType::clear(listVar); + for (int ii = 0; ii < list.count(); ++ii) { + QVariant v = QmlMetaType::fromObject(list.at(ii), listType); + QmlMetaType::append(listVar, v); + } - int listType = QmlMetaType::listType(t); - if (value.userType() == qMetaTypeId<QList<QObject *> >()) { - const QList<QObject *> &list = - qvariant_cast<QList<QObject *> >(value); - QVariant listVar = prop.read(object); - QmlMetaType::clear(listVar); - for (int ii = 0; ii < list.count(); ++ii) { - QVariant v = QmlMetaType::fromObject(list.at(ii), listType); - QmlMetaType::append(listVar, v); - } + } else if (vt == listType || + value.userType() == listType) { + QVariant listVar = prop.read(object); + QmlMetaType::clear(listVar); + QmlMetaType::append(listVar, value); + } + } else if (category == QmlMetaProperty::QmlList) { + + // XXX - optimize! + QVariant list = prop.read(object); + QmlPrivate::ListInterface *li = + *(QmlPrivate::ListInterface **)list.constData(); + + int type = li->type(); + + if (QObject *obj = QmlMetaType::toQObject(value)) { + const QMetaObject *mo = + QmlMetaType::rawMetaObjectForType(type); + + const QMetaObject *objMo = obj->metaObject(); + bool found = false; + while(!found && objMo) { + if (objMo == mo) + found = true; + else + objMo = objMo->superClass(); + } - } else if (vt == listType || - value.userType() == listType) { - QVariant listVar = prop.read(object); - if (!QmlMetaType::append(listVar, value)) { - qWarning() << "QmlMetaProperty: Unable to assign object to list"; - } + if (!found) { + qWarning() << "Unable to assign object to list"; + return; } - } else if (propertyCategory() == QmlMetaProperty::QmlList) { - // XXX - optimize! - QVariant list = prop.read(object); - QmlPrivate::ListInterface *li = - *(QmlPrivate::ListInterface **)list.constData(); - - int type = li->type(); - - if (QObject *obj = QmlMetaType::toQObject(value)) { - const QMetaObject *mo = - QmlMetaType::rawMetaObjectForType(type); - - const QMetaObject *objMo = obj->metaObject(); - bool found = false; - while(!found && objMo) { - if (objMo == mo) - found = true; - else - objMo = objMo->superClass(); + + // NOTE: This assumes a cast to QObject does not alter + // the object pointer + void *d = (void *)&obj; + li->append(d); + } + } else if (category == QmlMetaProperty::Normal) { + + switch(t) { + case QVariant::Double: + { + double d; + bool found = true; + if (vt == QVariant::Int) { + d = value.toInt(); + } else if (vt == QVariant::UInt) { + d = value.toUInt(); + } else { + found = false; } - if (!found) { - qWarning() << "Unable to assign object to list"; + if (found) { + void *a[1]; + a[0] = &d; + QMetaObject::metacall(object, + QMetaObject::WriteProperty, + coreIdx, a); return; } - - // NOTE: This assumes a cast to QObject does not alter - // the object pointer - void *d = (void *)&obj; - li->append(d); } - } else if (propertyCategory() == QmlMetaProperty::Normal) { - - switch(t) { - case QVariant::Double: - { - double d; - bool found = true; - if (vt == QVariant::Int) { - d = value.toInt(); - } else if (vt == QVariant::UInt) { - d = value.toUInt(); - } else { - found = false; - } - - if (found) { - void *a[1]; - a[0] = &d; - QMetaObject::metacall(object, - QMetaObject::WriteProperty, - coreIdx, a); - return; - } + break; + + case QVariant::Int: + { + int i; + bool found = true; + if (vt == QVariant::Double) { + i = (int)value.toDouble(); + } else if (vt == QVariant::UInt) { + i = (int)value.toUInt(); + } else { + found = false; } - break; - case QVariant::Int: - { - int i; - bool found = true; - if (vt == QVariant::Double) { - i = (int)value.toDouble(); - } else if (vt == QVariant::UInt) { - i = (int)value.toUInt(); - } else { - found = false; - } - - if (found) { - void *a[1]; - a[0] = &i; - QMetaObject::metacall(object, - QMetaObject::WriteProperty, - coreIdx, a); - return; - } + if (found) { + void *a[1]; + a[0] = &i; + QMetaObject::metacall(object, + QMetaObject::WriteProperty, + coreIdx, a); + return; + } + } + break; + + case QVariant::String: + { + QString s; + bool found = true; + if (vt == QVariant::ByteArray) { + s = QLatin1String(value.toByteArray()); + } else { + found = false; } - break; - case QVariant::String: - { - QString s; - bool found = true; - if (vt == QVariant::ByteArray) { - s = QLatin1String(value.toByteArray()); - } else { - found = false; - } - - if (found) { - void *a[1]; - a[0] = &s; - QMetaObject::metacall(object, - QMetaObject::WriteProperty, - coreIdx, a); - return; - } + if (found) { + void *a[1]; + a[0] = &s; + QMetaObject::metacall(object, + QMetaObject::WriteProperty, + coreIdx, a); + return; } - break; + } + break; - default: - break; - } - prop.write(object, value); + default: + break; } - + prop.write(object, value); } + } /*! @@ -813,168 +833,8 @@ void QmlMetaProperty::write(const QVariant &value) const } else if (prop.name()) { - if (prop.isEnumType()) { - QVariant v = value; - if (value.type() == QVariant::Double) { //enum values come through the script engine as doubles - double integral; - double fractional = modf(value.toDouble(), &integral); - if (qFuzzyCompare(fractional, (double)0.0)) - v.convert(QVariant::Int); - } - prop.write(object(), v); - } else { - if (!value.isValid()) - return; - - int t = propertyType(); - int vt = value.type(); - - if (vt == t || - value.userType() == t) { + d->writeValueProperty(value); - void *a[1]; - a[0] = (void *)value.constData(); - QMetaObject::metacall(object(), QMetaObject::WriteProperty, d->coreIdx, a); - - } else if (qMetaTypeId<QVariant>() == t) { - - prop.write(object(), value); - - } else if (propertyCategory() == Object) { - - QObject *o = QmlMetaType::toQObject(value); - if (o) - prop.write(object(), QmlMetaType::fromObject(o, propertyType())); - - } else if (propertyCategory() == List) { - - int listType = QmlMetaType::listType(t); - if (value.userType() == qMetaTypeId<QList<QObject *> >()) { - const QList<QObject *> &list = - qvariant_cast<QList<QObject *> >(value); - QVariant listVar = prop.read(object()); - QmlMetaType::clear(listVar); - for (int ii = 0; ii < list.count(); ++ii) { - QVariant v = QmlMetaType::fromObject(list.at(ii), listType); - QmlMetaType::append(listVar, v); - } - - } else if (vt == listType || - value.userType() == listType) { - QVariant listVar = prop.read(object()); - if (!QmlMetaType::append(listVar, value)) { - qWarning() << "QmlMetaProperty: Unable to assign object to list"; - } - } - } else if (propertyCategory() == QmlList) { - // XXX - optimize! - QVariant list = prop.read(object()); - QmlPrivate::ListInterface *li = - *(QmlPrivate::ListInterface **)list.constData(); - - int type = li->type(); - - if (QObject *obj = QmlMetaType::toQObject(value)) { - const QMetaObject *mo = - QmlMetaType::rawMetaObjectForType(type); - - const QMetaObject *objMo = obj->metaObject(); - bool found = false; - while(!found && objMo) { - if (objMo == mo) - found = true; - else - objMo = objMo->superClass(); - } - - if (!found) { - qWarning() << "Unable to assign object to list"; - return; - } - - // NOTE: This assumes a cast to QObject does not alter - // the object pointer - void *d = (void *)&obj; - li->append(d); - } - } else if (propertyCategory() == Normal) { - - switch(t) { - case QVariant::Double: - { - double dd; - bool found = true; - if (vt == QVariant::Int) { - dd = value.toInt(); - } else if (vt == QVariant::UInt) { - dd = value.toUInt(); - } else { - found = false; - } - - if (found) { - void *a[1]; - a[0] = ⅆ - QMetaObject::metacall(object(), - QMetaObject::WriteProperty, - d->coreIdx, a); - return; - } - } - break; - - case QVariant::Int: - { - int i; - bool found = true; - if (vt == QVariant::Double) { - i = (int)value.toDouble(); - } else if (vt == QVariant::UInt) { - i = (int)value.toUInt(); - } else { - found = false; - } - - if (found) { - void *a[1]; - a[0] = &i; - QMetaObject::metacall(object(), - QMetaObject::WriteProperty, - d->coreIdx, a); - return; - } - } - break; - - case QVariant::String: - { - QString s; - bool found = true; - if (vt == QVariant::ByteArray) { - s = QLatin1String(value.toByteArray()); - } else { - found = false; - } - - if (found) { - void *a[1]; - a[0] = &s; - QMetaObject::metacall(object(), - QMetaObject::WriteProperty, - d->coreIdx, a); - return; - } - } - break; - - - default: - break; - } - prop.write(object(), value); - } - - } } } diff --git a/src/declarative/qml/qmlproxymetaobject.cpp b/src/declarative/qml/qmlproxymetaobject.cpp index d24c5c4..686c6d7 100644 --- a/src/declarative/qml/qmlproxymetaobject.cpp +++ b/src/declarative/qml/qmlproxymetaobject.cpp @@ -50,7 +50,7 @@ QmlProxyMetaObject::QmlProxyMetaObject(QObject *obj, QList<ProxyData> *mList) qWarning() << "QmlProxyMetaObject" << obj->metaObject()->className(); #endif - *static_cast<QMetaObject *>(this) = *metaObjects->last().metaObject; + *static_cast<QMetaObject *>(this) = *metaObjects->first().metaObject; QObjectPrivate *op = QObjectPrivate::get(obj); if (op->metaObject) diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index cdc6a66..3a66c69 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -541,7 +541,6 @@ QObject *QmlVME::run(QmlContext *ctxt, QmlCompiledComponent *comp, int start, in QFx_setParent_noEvent(bind, target); bind->setTarget(mp); - bind->setSourceLocation(comp->url, instr.line); } break; |