Allow Qt enum values in ListElement.
authorMichael Brasser <michael.brasser@nokia.com>
Wed, 27 Jul 2011 00:19:26 +0000 (10:19 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 28 Jul 2011 09:27:26 +0000 (11:27 +0200)
Task-number: QTBUG-16547
Change-Id: Id215cea5cdaaaef8ff8a06a0bde682f95c91e416
Reviewed-by: Aaron Kennedy
Reviewed-on: http://codereview.qt.nokia.com/2227
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>

src/declarative/qml/qdeclarativecompiler.cpp
tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp

index 0f0acba..a0b1d8f 100644 (file)
@@ -2294,16 +2294,23 @@ bool QDeclarativeCompiler::testQualifiedEnumAssignment(const QMetaProperty &prop
     return true;
 }
 
+struct StaticQtMetaObject : public QObject
+{
+    static const QMetaObject *get()
+        { return &static_cast<StaticQtMetaObject*> (0)->staticQtMetaObject; }
+};
+
 // Similar logic to above, but not knowing target property.
 int QDeclarativeCompiler::evaluateEnum(const QByteArray& script) const
 {
     int dot = script.indexOf('.');
     if (dot > 0) {
+        const QByteArray &scope = script.left(dot);
         QDeclarativeType *type = 0;
-        unit->imports().resolveType(script.left(dot), &type, 0, 0, 0, 0);
-        if (!type)
+        unit->imports().resolveType(scope, &type, 0, 0, 0, 0);
+        if (!type && scope != "Qt")
             return -1;
-        const QMetaObject *mo = type->metaObject();
+        const QMetaObject *mo = type ? type->metaObject() : StaticQtMetaObject::get();
         const char *key = script.constData() + dot+1;
         int i = mo->enumeratorCount();
         while (i--) {
index 1016e5d..fd68933 100644 (file)
@@ -171,6 +171,10 @@ void tst_qdeclarativelistmodel::static_types_data()
     QTest::newRow("enum")
         << "ListElement { foo: Text.AlignHCenter }"
         << QVariant(double(QSGText::AlignHCenter));
+
+    QTest::newRow("Qt enum")
+        << "ListElement { foo: Qt.AlignBottom }"
+        << QVariant(double(Qt::AlignBottom));
 }
 
 void tst_qdeclarativelistmodel::static_types()