Support unregistered Qt namespace enums in QML methods.
This brings the support in line with signal handlers, which should allow us to reuse the implementation there when appropriate. Also adds tests for both registered and unregisted Qt namespace enums. Change-Id: I366846626fc44d6d99b51e93fc9e3cb948c748f9 Reviewed-by: Chris Adams <christopher.adams@nokia.com>
This commit is contained in:
parent
37cd29b2ff
commit
16c1928311
|
@ -682,7 +682,13 @@ QStringList QQmlPropertyCache::propertyNames() const
|
|||
return keys;
|
||||
}
|
||||
|
||||
static int EnumType(const QMetaObject *meta, const QByteArray &str)
|
||||
struct StaticQtMetaObject : public QObject
|
||||
{
|
||||
static const QMetaObject *get()
|
||||
{ return &static_cast<StaticQtMetaObject*> (0)->staticQtMetaObject; }
|
||||
};
|
||||
|
||||
static int EnumType(const QMetaObject *metaobj, const QByteArray &str)
|
||||
{
|
||||
QByteArray scope;
|
||||
QByteArray name;
|
||||
|
@ -693,6 +699,11 @@ static int EnumType(const QMetaObject *meta, const QByteArray &str)
|
|||
} else {
|
||||
name = str;
|
||||
}
|
||||
const QMetaObject *meta;
|
||||
if (scope == "Qt")
|
||||
meta = StaticQtMetaObject::get();
|
||||
else
|
||||
meta = metaobj;
|
||||
for (int i = meta->enumeratorCount() - 1; i >= 0; --i) {
|
||||
QMetaEnum m = meta->enumerator(i);
|
||||
if ((m.name() == name) && (scope.isEmpty() || (m.scope() == scope)))
|
||||
|
|
|
@ -19,13 +19,25 @@ Item {
|
|||
bValue = newValue;
|
||||
}
|
||||
|
||||
onValueCChanged: {
|
||||
cValue = newValue;
|
||||
}
|
||||
|
||||
onValueDChanged: {
|
||||
dValue = newValue;
|
||||
}
|
||||
|
||||
property int aValue: 0
|
||||
property int bValue: 0
|
||||
property int cValue: 0
|
||||
property int dValue: 0
|
||||
}
|
||||
|
||||
function setEnumValues() {
|
||||
enum1Class.setValue(MyEnum1Class.A_13);
|
||||
enumDerivedClass.setValueA(MyEnum1Class.A_11);
|
||||
enumDerivedClass.setValueB(MyEnum2Class.B_37);
|
||||
enumDerivedClass.setValueC(Qt.RichText);
|
||||
enumDerivedClass.setValueD(Qt.ElideMiddle);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -854,17 +854,25 @@ public:
|
|||
|
||||
MyEnum1Class::EnumA getValueA() { return valueA; }
|
||||
EnumB getValueB() { return valueB; }
|
||||
Qt::TextFormat getValueC() { return valueC; }
|
||||
Qt::TextElideMode getValueD() { return valueD; }
|
||||
|
||||
Q_INVOKABLE void setValueA(MyEnum1Class::EnumA v) { valueA = v; emit valueAChanged(v); }
|
||||
Q_INVOKABLE void setValueB(EnumB v) { valueB = v; emit valueBChanged(v); }
|
||||
Q_INVOKABLE void setValueC(Qt::TextFormat v) { valueC = v; emit valueCChanged(v); } //registered
|
||||
Q_INVOKABLE void setValueD(Qt::TextElideMode v) { valueD = v; emit valueDChanged(v); } //unregistered
|
||||
|
||||
signals:
|
||||
void valueAChanged(MyEnum1Class::EnumA newValue);
|
||||
void valueBChanged(MyEnum2Class::EnumB newValue);
|
||||
void valueCChanged(Qt::TextFormat newValue);
|
||||
void valueDChanged(Qt::TextElideMode newValue);
|
||||
|
||||
private:
|
||||
MyEnum1Class::EnumA valueA;
|
||||
EnumB valueB;
|
||||
Qt::TextFormat valueC;
|
||||
Qt::TextElideMode valueD;
|
||||
};
|
||||
|
||||
class MyEnumDerivedClass : public MyEnum2Class
|
||||
|
@ -874,6 +882,7 @@ class MyEnumDerivedClass : public MyEnum2Class
|
|||
|
||||
Q_DECLARE_METATYPE(MyEnum2Class::EnumB)
|
||||
Q_DECLARE_METATYPE(MyEnum1Class::EnumA)
|
||||
Q_DECLARE_METATYPE(Qt::TextFormat)
|
||||
|
||||
QML_DECLARE_TYPE(MyRevisionedBaseClassRegistered)
|
||||
QML_DECLARE_TYPE(MyRevisionedBaseClassUnregistered)
|
||||
|
|
|
@ -2293,6 +2293,7 @@ void tst_qqmllanguage::globalEnums()
|
|||
{
|
||||
qRegisterMetaType<MyEnum1Class::EnumA>();
|
||||
qRegisterMetaType<MyEnum2Class::EnumB>();
|
||||
qRegisterMetaType<Qt::TextFormat>();
|
||||
|
||||
QQmlComponent component(&engine, TEST_FILE("globalEnums.qml"));
|
||||
|
||||
|
@ -2310,6 +2311,8 @@ void tst_qqmllanguage::globalEnums()
|
|||
|
||||
QVERIFY(enum2Class->property("aValue") == 0);
|
||||
QVERIFY(enum2Class->property("bValue") == 0);
|
||||
QVERIFY(enum2Class->property("cValue") == 0);
|
||||
QVERIFY(enum2Class->property("dValue") == 0);
|
||||
|
||||
QSignalSpy signalA(enum2Class, SIGNAL(valueAChanged(MyEnum1Class::EnumA)));
|
||||
QSignalSpy signalB(enum2Class, SIGNAL(valueBChanged(MyEnum2Class::EnumB)));
|
||||
|
@ -2319,12 +2322,16 @@ void tst_qqmllanguage::globalEnums()
|
|||
QVERIFY(enum1Class->getValue() == MyEnum1Class::A_13);
|
||||
QVERIFY(enum2Class->getValueA() == MyEnum1Class::A_11);
|
||||
QVERIFY(enum2Class->getValueB() == MyEnum2Class::B_37);
|
||||
QVERIFY(enum2Class->getValueC() == Qt::RichText);
|
||||
QVERIFY(enum2Class->getValueD() == Qt::ElideMiddle);
|
||||
|
||||
QVERIFY(signalA.count() == 1);
|
||||
QVERIFY(signalB.count() == 1);
|
||||
|
||||
QVERIFY(enum2Class->property("aValue") == MyEnum1Class::A_11);
|
||||
QVERIFY(enum2Class->property("bValue") == 37);
|
||||
QVERIFY(enum2Class->property("cValue") == 1);
|
||||
QVERIFY(enum2Class->property("dValue") == 2);
|
||||
|
||||
delete o;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue