aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-01-09 14:09:32 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-25 10:59:58 +0100
commitde00d8e2d287344229ef6da0fdb19e9846ab6dd9 (patch)
tree21ccbd8a9e3b0a603d1fe87b18fa3a8de8b26de5
parent8df8bc5062bf5848a616792c79dddd1626014072 (diff)
Use QMetaType::QVariant as the type for QVariant
Change http://codereview.qt-project.org/#change,12408 in qtbase updates moc and friends to use QMetaType::QVariant instead of the magic -1 / 0xffffffff / QVariant::LastType. This change adapts qtdeclarative accordingly. Change-Id: Ifb120485a4ee1501df6ad42d8ecd590824c85e9f Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com> Reviewed-by: Chris Adams <christopher.adams@nokia.com>
-rw-r--r--src/declarative/qml/ftw/qfastmetabuilder.cpp9
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp14
-rw-r--r--src/declarative/qml/qdeclarativeproperty.cpp5
-rw-r--r--src/declarative/qml/qdeclarativepropertycache.cpp7
-rw-r--r--src/declarative/qml/qdeclarativevmemetaobject.cpp37
5 files changed, 29 insertions, 43 deletions
diff --git a/src/declarative/qml/ftw/qfastmetabuilder.cpp b/src/declarative/qml/ftw/qfastmetabuilder.cpp
index e1cedefe46..d9881851a1 100644
--- a/src/declarative/qml/ftw/qfastmetabuilder.cpp
+++ b/src/declarative/qml/ftw/qfastmetabuilder.cpp
@@ -40,7 +40,6 @@
****************************************************************************/
#include "qfastmetabuilder_p.h"
-#include "qvariant.h"
#include <QtCore/qmetaobject.h>
@@ -260,20 +259,16 @@ void QFastMetaBuilder::setProperty(int index, const StringRef &name, const Strin
QMetaObjectPrivate *p = priv(m_data);
Q_ASSERT(index < p->propertyCount);
- uint qtType = mtype;
- if ((int)qtType == qMetaTypeId<QVariant>())
- qtType = 0xFF; // Special handling for QVariant
-
uint *ptr = fieldPointer(m_data) + p->propertyData + index * PROPERTY_FIELD_COUNT;
// properties: name, type, flags
ptr[0] = name.offset();
ptr[1] = type.offset();
if (notifySignal == -1) {
- ptr[2] = qtType << 24;
+ ptr[2] = mtype << 24;
ptr[2] |= flags | Scriptable | Readable;
*(fieldPointer(m_data) + p->propertyData + p->propertyCount * PROPERTY_FIELD_COUNT + index) = 0;
} else {
- ptr[2] = qtType << 24;
+ ptr[2] = mtype << 24;
ptr[2] |= flags | Scriptable | Readable | Notify;
*(fieldPointer(m_data) + p->propertyData + p->propertyCount * PROPERTY_FIELD_COUNT + index) = notifySignal;
}
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index 07e381c18f..8bf1faa2f1 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -2833,8 +2833,8 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeScript::Object *obj, Dyn
int metaType;
const char *cppType;
} builtinTypes[] = {
- { Object::DynamicProperty::Var, 0, "QVariant" },
- { Object::DynamicProperty::Variant, 0, "QVariant" },
+ { Object::DynamicProperty::Var, QMetaType::QVariant, "QVariant" },
+ { Object::DynamicProperty::Variant, QMetaType::QVariant, "QVariant" },
{ Object::DynamicProperty::Int, QMetaType::Int, "int" },
{ Object::DynamicProperty::Bool, QMetaType::Bool, "bool" },
{ Object::DynamicProperty::Real, QMetaType::Double, "double" },
@@ -2870,8 +2870,6 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeScript::Object *obj, Dyn
if (typeRefs[p->type].isEmpty())
typeRefs[p->type] = builder.newString(strlen(builtinTypes[p->type].cppType));
typeRef = typeRefs[p->type];
- if (p->type == Object::DynamicProperty::Variant)
- propertyType = -1;
} else {
Q_ASSERT(p->type == Object::DynamicProperty::CustomList ||
@@ -2950,11 +2948,11 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeScript::Object *obj, Dyn
QFastMetaBuilder::StringRef typeRef = typeRefs[p->type];
if (buildData) {
vmd->propertyCount++;
- (vmd->propertyData() + effectivePropertyIndex)->propertyType = -1;
+ (vmd->propertyData() + effectivePropertyIndex)->propertyType = QMetaType::QVariant;
}
builder.setProperty(effectivePropertyIndex, p->nameRef, typeRef,
- (QMetaType::Type)-1,
+ QMetaType::QVariant,
p->isReadOnly?QFastMetaBuilder::None:QFastMetaBuilder::Writable,
effectivePropertyIndex);
@@ -3267,8 +3265,8 @@ bool QDeclarativeCompiler::compileAlias(QFastMetaBuilder &builder,
writable = aliasProperty.isWritable() && !prop.isReadOnly;
resettable = aliasProperty.isResettable() && !prop.isReadOnly;
- if (aliasProperty.type() < QVariant::UserType ||
- aliasProperty.type() == QVariant::LastType /* for QVariant */ )
+ if (aliasProperty.type() < QVariant::UserType
+ || uint(aliasProperty.type()) == QMetaType::QVariant)
type = aliasProperty.type();
if (alias.count() == 3) {
diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp
index ff03018f00..408b070cdb 100644
--- a/src/declarative/qml/qdeclarativeproperty.cpp
+++ b/src/declarative/qml/qdeclarativeproperty.cpp
@@ -481,10 +481,7 @@ int QDeclarativePropertyPrivate::propertyType() const
if (isValueType()) {
return core.valueTypePropType;
} else if (type & QDeclarativeProperty::Property) {
- if (core.propType == (int)QVariant::LastType)
- return qMetaTypeId<QVariant>();
- else
- return core.propType;
+ return core.propType;
} else {
return QVariant::Invalid;
}
diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp
index 30f207bede..43240c70d3 100644
--- a/src/declarative/qml/qdeclarativepropertycache.cpp
+++ b/src/declarative/qml/qdeclarativepropertycache.cpp
@@ -146,6 +146,9 @@ void QDeclarativePropertyData::lazyLoad(const QMetaProperty &p, QDeclarativeEngi
if (type == QMetaType::QObjectStar || type == QMetaType::QWidgetStar) {
propType = type;
flags |= QDeclarativePropertyData::IsQObjectDerived;
+ } else if (type == QMetaType::QVariant) {
+ propType = type;
+ flags |= QDeclarativePropertyData::IsQVariant;
} else if (type == QVariant::UserType || type == -1) {
propTypeName = p.typeName();
flags |= QDeclarativePropertyData::NotFullyResolved;
@@ -157,8 +160,6 @@ void QDeclarativePropertyData::lazyLoad(const QMetaProperty &p, QDeclarativeEngi
void QDeclarativePropertyData::load(const QMetaProperty &p, QDeclarativeEngine *engine)
{
propType = p.userType();
- if (QVariant::Type(propType) == QVariant::LastType)
- propType = QMetaType::QVariant;
coreIndex = p.propertyIndex();
notifyIndex = p.notifySignalIndex();
flags = fastFlagsForProperty(p) | flagsForPropertyType(propType, engine);
@@ -549,8 +550,6 @@ void QDeclarativePropertyCache::resolve(QDeclarativePropertyData *data) const
Q_ASSERT(data->notFullyResolved());
data->propType = QMetaType::type(data->propTypeName);
- if (QVariant::Type(data->propType) == QVariant::LastType)
- data->propType = QMetaType::QVariant;
if (!data->isFunction())
data->flags |= flagsForPropertyType(data->propType, engine);
diff --git a/src/declarative/qml/qdeclarativevmemetaobject.cpp b/src/declarative/qml/qdeclarativevmemetaobject.cpp
index f33d2f3cad..a410be1ee4 100644
--- a/src/declarative/qml/qdeclarativevmemetaobject.cpp
+++ b/src/declarative/qml/qdeclarativevmemetaobject.cpp
@@ -527,31 +527,22 @@ int QDeclarativeVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
int t = (metaData->propertyData() + id)->propertyType;
bool needActivate = false;
- if (t == -1) {
-
- if (id >= firstVarPropertyIndex) {
- // the context can be null if accessing var properties from cpp after re-parenting an item.
- QDeclarativeEnginePrivate *ep = (ctxt == 0 || ctxt->engine == 0) ? 0 : QDeclarativeEnginePrivate::get(ctxt->engine);
- QV8Engine *v8e = (ep == 0) ? 0 : ep->v8engine();
- if (v8e) {
- v8::HandleScope handleScope;
- v8::Context::Scope contextScope(v8e->context());
- if (c == QMetaObject::ReadProperty) {
- *reinterpret_cast<QVariant *>(a[0]) = readPropertyAsVariant(id);
- } else if (c == QMetaObject::WriteProperty) {
- writeProperty(id, *reinterpret_cast<QVariant *>(a[0]));
- }
- } else if (c == QMetaObject::ReadProperty) {
- // if the context was disposed, we just return an invalid variant from read.
- *reinterpret_cast<QVariant *>(a[0]) = QVariant();
- }
- } else {
- // don't need to set up v8 scope objects, since not accessing varProperties.
+ if (id >= firstVarPropertyIndex) {
+ Q_ASSERT(t == QMetaType::QVariant);
+ // the context can be null if accessing var properties from cpp after re-parenting an item.
+ QDeclarativeEnginePrivate *ep = (ctxt == 0 || ctxt->engine == 0) ? 0 : QDeclarativeEnginePrivate::get(ctxt->engine);
+ QV8Engine *v8e = (ep == 0) ? 0 : ep->v8engine();
+ if (v8e) {
+ v8::HandleScope handleScope;
+ v8::Context::Scope contextScope(v8e->context());
if (c == QMetaObject::ReadProperty) {
*reinterpret_cast<QVariant *>(a[0]) = readPropertyAsVariant(id);
} else if (c == QMetaObject::WriteProperty) {
writeProperty(id, *reinterpret_cast<QVariant *>(a[0]));
}
+ } else if (c == QMetaObject::ReadProperty) {
+ // if the context was disposed, we just return an invalid variant from read.
+ *reinterpret_cast<QVariant *>(a[0]) = QVariant();
}
} else {
@@ -585,6 +576,9 @@ int QDeclarativeVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
case QMetaType::QObjectStar:
*reinterpret_cast<QObject **>(a[0]) = data[id].asQObject();
break;
+ case QMetaType::QVariant:
+ *reinterpret_cast<QVariant *>(a[0]) = readPropertyAsVariant(id);
+ break;
default:
break;
}
@@ -636,6 +630,9 @@ int QDeclarativeVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
needActivate = *reinterpret_cast<QObject **>(a[0]) != data[id].asQObject();
data[id].setValue(*reinterpret_cast<QObject **>(a[0]));
break;
+ case QMetaType::QVariant:
+ writeProperty(id, *reinterpret_cast<QVariant *>(a[0]));
+ break;
default:
break;
}