Use QMetaType::QVariant as the type for QVariant
authorKent Hansen <kent.hansen@nokia.com>
Mon, 9 Jan 2012 13:09:32 +0000 (14:09 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 25 Jan 2012 09:59:58 +0000 (10:59 +0100)
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>

src/declarative/qml/ftw/qfastmetabuilder.cpp
src/declarative/qml/qdeclarativecompiler.cpp
src/declarative/qml/qdeclarativeproperty.cpp
src/declarative/qml/qdeclarativepropertycache.cpp
src/declarative/qml/qdeclarativevmemetaobject.cpp

index e1cedef..d988185 100644 (file)
@@ -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;
     }
index 07e381c..8bf1faa 100644 (file)
@@ -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) {
index ff03018..408b070 100644 (file)
@@ -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;
     }
index 30f207b..43240c7 100644 (file)
@@ -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);
index f33d2f3..a410be1 100644 (file)
@@ -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;
                         }