diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-10 08:51:21 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-10 08:51:21 (GMT) |
commit | d0d89a49a7c1e5f302a8606448fc5defdb327a25 (patch) | |
tree | c01493c5fc2951e794c5e1b6bcaab9ac111ea526 /src/declarative/qml | |
parent | 52ee3d6525e2b271fc50103001f9d71d681b6afe (diff) | |
download | Qt-d0d89a49a7c1e5f302a8606448fc5defdb327a25.zip Qt-d0d89a49a7c1e5f302a8606448fc5defdb327a25.tar.gz Qt-d0d89a49a7c1e5f302a8606448fc5defdb327a25.tar.bz2 |
Minor cleanups
Diffstat (limited to 'src/declarative/qml')
-rw-r--r-- | src/declarative/qml/qmlbindablevalue.cpp | 28 | ||||
-rw-r--r-- | src/declarative/qml/qmlmetaproperty.cpp | 162 |
2 files changed, 13 insertions, 177 deletions
diff --git a/src/declarative/qml/qmlbindablevalue.cpp b/src/declarative/qml/qmlbindablevalue.cpp index de01387..d111bbb 100644 --- a/src/declarative/qml/qmlbindablevalue.cpp +++ b/src/declarative/qml/qmlbindablevalue.cpp @@ -179,34 +179,29 @@ void QmlBindableValue::update() } } else if (d->property.propertyCategory() == QmlMetaProperty::Bindable) { - // NOTE: We assume that only core properties can have - // propertyType == 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) { 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"; - } - } + + QObject *obj = QmlMetaType::toQObject(value); + + if (!obj) { + if (scriptWarnings()) + 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(); + // XXX This isn't type safe // NOTE: We assume that only core properties can have // propertyType == Object @@ -220,7 +215,8 @@ void QmlBindableValue::update() } else if (d->property.propertyCategory() == QmlMetaProperty::Normal) { QVariant value = this->value(); - if (d->property.propertyType() == QVariant::Url && value.canConvert(QVariant::String) && !value.isNull()) { + if (d->property.propertyType() == QVariant::Url && + value.canConvert(QVariant::String) && !value.isNull()) { // Must resolve first value.setValue(context()->resolvedUrl(value.toString())); } diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index 4f39ebc..5cddf3d 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -813,168 +813,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) { - - 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; + d->writeValueProperty(value); - - default: - break; - } - prop.write(object(), value); - } - - } } } |