return true;
}
+struct StaticQtMetaObject : public QObject
+{
+ static const QMetaObject *get()
+ { return &static_cast<StaticQtMetaObject*> (0)->staticQtMetaObject; }
+};
+
bool QQmlCompiler::testQualifiedEnumAssignment(QQmlScript::Property *prop,
QQmlScript::Object *obj,
QQmlScript::Value *v,
QQmlType *type = 0;
unit->imports().resolveType(typeName, &type, 0, 0, 0, 0);
- if (!type)
+ if (!type && typeName != QLatin1String("Qt"))
return true;
int value = 0;
bool ok;
- if (toQmlType(obj) == type) {
+ if (type && toQmlType(obj) == type) {
// When these two match, we can short cut the search
if (mprop.isFlagType()) {
value = mprop.enumerator().keysToValue(enumValue.toUtf8().constData(), &ok);
// Otherwise we have to search the whole type
// This matches the logic in QV8TypeWrapper
QByteArray enumName = enumValue.toUtf8();
- const QMetaObject *metaObject = type->baseMetaObject();
+ const QMetaObject *metaObject = type ? type->baseMetaObject() : StaticQtMetaObject::get();
ok = false;
for (int ii = metaObject->enumeratorCount() - 1; !ok && ii >= 0; --ii) {
QMetaEnum e = metaObject->enumerator(ii);
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 QQmlCompiler::evaluateEnum(const QHashedStringRef &scope, const QByteArray& enumValue) const
{
MyTypeObject {
flagProperty: "FlagVal1 | FlagVal3"
enumProperty: "EnumVal2"
+ qtEnumProperty: Qt.RichText
+ mirroredEnumProperty: Qt.AlignHCenter
stringProperty: "Hello World!"
uintProperty: 10
intProperty: -19
urlProperty: "main.qml?with%3cencoded%3edata"
objectProperty: MyTypeObject { intProperty: 8 }
+
+ property bool qtEnumTriggeredChange: false
+ onQtEnumPropertyChanged: qtEnumTriggeredChange = true
+
+ property bool mirroredEnumTriggeredChange: false
+ onMirroredEnumPropertyChanged: mirroredEnumTriggeredChange = true
}
{
Q_OBJECT
Q_ENUMS(MyEnum)
+ Q_ENUMS(MyMirroredEnum)
Q_FLAGS(MyFlags)
Q_PROPERTY(QString id READ id WRITE setId)
Q_PROPERTY(MyFlags flagProperty READ flagProperty WRITE setFlagProperty NOTIFY flagPropertyChanged)
Q_PROPERTY(MyEnum enumProperty READ enumProperty WRITE setEnumProperty NOTIFY enumPropertyChanged)
Q_PROPERTY(MyEnum readOnlyEnumProperty READ readOnlyEnumProperty)
+ Q_PROPERTY(Qt::TextFormat qtEnumProperty READ qtEnumProperty WRITE setQtEnumProperty NOTIFY qtEnumPropertyChanged)
+ Q_PROPERTY(MyMirroredEnum mirroredEnumProperty READ mirroredEnumProperty WRITE setMirroredEnumProperty NOTIFY mirroredEnumPropertyChanged)
Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringPropertyChanged)
Q_PROPERTY(uint uintProperty READ uintProperty WRITE setUintProperty NOTIFY uintPropertyChanged)
Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty NOTIFY intPropertyChanged)
return EnumVal1;
}
+ Qt::TextFormat qtEnumPropertyValue;
+ Qt::TextFormat qtEnumProperty() const {
+ return qtEnumPropertyValue;
+ }
+ void setQtEnumProperty(Qt::TextFormat v) {
+ qtEnumPropertyValue = v;
+ emit qtEnumPropertyChanged();
+ }
+
+ enum MyMirroredEnum {
+ MirroredEnumVal1 = Qt::AlignLeft,
+ MirroredEnumVal2 = Qt::AlignRight,
+ MirroredEnumVal3 = Qt::AlignHCenter };
+ MyMirroredEnum mirroredEnumPropertyValue;
+ MyMirroredEnum mirroredEnumProperty() const {
+ return mirroredEnumPropertyValue;
+ }
+ void setMirroredEnumProperty(MyMirroredEnum v) {
+ mirroredEnumPropertyValue = v;
+ emit mirroredEnumPropertyChanged();
+ }
+
QString stringPropertyValue;
QString stringProperty() const {
return stringPropertyValue;
void objectPropertyChanged();
void flagPropertyChanged();
void enumPropertyChanged();
+ void qtEnumPropertyChanged();
+ void mirroredEnumPropertyChanged();
void stringPropertyChanged();
void uintPropertyChanged();
void intPropertyChanged();
QVERIFY(object != 0);
QCOMPARE(object->flagProperty(), MyTypeObject::FlagVal1 | MyTypeObject::FlagVal3);
QCOMPARE(object->enumProperty(), MyTypeObject::EnumVal2);
+ QCOMPARE(object->qtEnumProperty(), Qt::RichText);
+ QCOMPARE(object->mirroredEnumProperty(), MyTypeObject::MirroredEnumVal3);
QCOMPARE(object->stringProperty(), QString("Hello World!"));
QCOMPARE(object->uintProperty(), uint(10));
QCOMPARE(object->intProperty(), -19);
MyTypeObject *child = qobject_cast<MyTypeObject *>(object->objectProperty());
QVERIFY(child != 0);
QCOMPARE(child->intProperty(), 8);
+
+ //these used to go via script. Ensure they no longer do
+ QCOMPARE(object->property("qtEnumTriggeredChange").toBool(), false);
+ QCOMPARE(object->property("mirroredEnumTriggeredChange").toBool(), false);
}
// Test edge case type assignments