Add rect property type
authorMichael Brasser <michael.brasser@nokia.com>
Thu, 3 May 2012 06:15:35 +0000 (16:15 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 9 May 2012 23:46:17 +0000 (01:46 +0200)
Change-Id: I9a533be414dca7fcf802e767164eeb745a9f6cd0
Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
src/qml/qml/qqmlcompiler.cpp
src/qml/qml/qqmlscript.cpp
src/qml/qml/qqmlscript_p.h
src/qml/qml/qqmlvmemetaobject.cpp

index 7d06ff3..e409544 100644 (file)
@@ -2839,6 +2839,7 @@ bool QQmlCompiler::buildDynamicMeta(QQmlScript::Object *obj, DynamicMetaMode mod
         { Object::DynamicProperty::Time, QMetaType::QTime },
         { Object::DynamicProperty::Date, QMetaType::QDate },
         { Object::DynamicProperty::DateTime, QMetaType::QDateTime },
+        { Object::DynamicProperty::Rect, QMetaType::QRectF },
     };
     static const int builtinTypeCount = sizeof(builtinTypes) / sizeof(TypeData);
 
index 704130d..555eb44 100644 (file)
@@ -924,6 +924,7 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
         // { "time", strlen("time"), Object::DynamicProperty::Time },
         // { "date", strlen("date"), Object::DynamicProperty::Date },
         { "date", strlen("date"), Object::DynamicProperty::DateTime },
+        { "rect", strlen("rect"), Object::DynamicProperty::Rect },
         { "variant", strlen("variant"), Object::DynamicProperty::Variant },
         { "var", strlen("var"), Object::DynamicProperty::Var }
     };
index 0a762d4..65dd406 100644 (file)
@@ -387,7 +387,7 @@ public:
         DynamicProperty();
 
         enum Type { Var, Variant, Int, Bool, Real, String, Url, Color,
-                    Time, Date, DateTime, Alias, Custom, CustomList };
+                    Time, Date, DateTime, Rect, Alias, Custom, CustomList };
 
         quint32 isDefaultProperty:1;
         quint32 isReadOnly:1;
index dd2fe4b..d7e9a28 100644 (file)
@@ -100,6 +100,7 @@ public:
     inline const QTime &asQTime();
     inline const QDate &asQDate();
     inline const QDateTime &asQDateTime();
+    inline const QRectF &asQRectF();
     inline const QJSValue &asQJSValue();
 
     inline void setValue(QObject *v, QQmlVMEMetaObject *target, int index);
@@ -112,6 +113,7 @@ public:
     inline void setValue(const QTime &);
     inline void setValue(const QDate &);
     inline void setValue(const QDateTime &);
+    inline void setValue(const QRectF &);
     inline void setValue(const QJSValue &);
 
     inline void setDataType(int t);
@@ -120,7 +122,7 @@ public:
 
 private:
     int type;
-    void *data[6]; // Large enough to hold all types
+    void *data[8]; // Large enough to hold all types
 
     inline void cleanup();
 };
@@ -171,6 +173,9 @@ void QQmlVMEVariant::cleanup()
     } else if (type == QMetaType::QDateTime) {
         ((QDateTime *)dataPtr())->~QDateTime();
         type = QVariant::Invalid;
+    } else if (type == QMetaType::QRectF) {
+        ((QRectF *)dataPtr())->~QRectF();
+        type = QVariant::Invalid;
     } else if (type == qMetaTypeId<QVariant>()) {
         ((QVariant *)dataPtr())->~QVariant();
         type = QVariant::Invalid;
@@ -284,6 +289,14 @@ const QDateTime &QQmlVMEVariant::asQDateTime()
     return *(QDateTime *)(dataPtr());
 }
 
+const QRectF &QQmlVMEVariant::asQRectF()
+{
+    if (type != QMetaType::QRectF)
+        setValue(QRectF());
+
+    return *(QRectF *)(dataPtr());
+}
+
 const QJSValue &QQmlVMEVariant::asQJSValue()
 {
     if (type != qMetaTypeId<QJSValue>())
@@ -395,6 +408,17 @@ void QQmlVMEVariant::setValue(const QDateTime &v)
     }
 }
 
+void QQmlVMEVariant::setValue(const QRectF &v)
+{
+    if (type != QMetaType::QRectF) {
+        cleanup();
+        type = QMetaType::QRectF;
+        new (dataPtr()) QRectF(v);
+    } else {
+        *(QRectF *)(dataPtr()) = v;
+    }
+}
+
 void QQmlVMEVariant::setValue(const QJSValue &v)
 {
     if (type != qMetaTypeId<QJSValue>()) {
@@ -598,6 +622,9 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
                         case QVariant::DateTime:
                             *reinterpret_cast<QDateTime *>(a[0]) = data[id].asQDateTime();
                             break;
+                        case QVariant::RectF:
+                            *reinterpret_cast<QRectF *>(a[0]) = data[id].asQRectF();
+                            break;
                         case QMetaType::QObjectStar:
                             *reinterpret_cast<QObject **>(a[0]) = data[id].asQObject();
                             break;
@@ -648,6 +675,10 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
                             needActivate = *reinterpret_cast<QDateTime *>(a[0]) != data[id].asQDateTime();
                             data[id].setValue(*reinterpret_cast<QDateTime *>(a[0]));
                             break;
+                        case QVariant::RectF:
+                            needActivate = *reinterpret_cast<QRectF *>(a[0]) != data[id].asQRectF();
+                            data[id].setValue(*reinterpret_cast<QRectF *>(a[0]));
+                            break;
                         case QMetaType::QObjectStar:
                             needActivate = *reinterpret_cast<QObject **>(a[0]) != data[id].asQObject();
                             data[id].setValue(*reinterpret_cast<QObject **>(a[0]), this, id);