QmlJS: Fix lookup for enums.

* Also look for enums in prototypes.
* Report back which QmlObjectValue had the enum.
* Fix a bug where enum lookup was always skipped.

Change-Id: I9c9fd8f8cf9bd8cc5f1bb5688fef5786267cd794
Reviewed-on: http://codereview.qt.nokia.com/4192
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
This commit is contained in:
Christian Kamm
2011-09-05 13:35:16 +02:00
parent b8b8f167b1
commit 312d43f215
3 changed files with 48 additions and 50 deletions

View File

@@ -269,46 +269,42 @@ const Value *QmlObjectValue::propertyValue(const FakeMetaProperty &prop) const
return objectValue;
}
const Value *value = valueOwner()->undefinedValue();
if (typeName == QLatin1String("QByteArray")
|| typeName == QLatin1String("string")
|| typeName == QLatin1String("QString")) {
value = valueOwner()->stringValue();
return valueOwner()->stringValue();
} else if (typeName == QLatin1String("QUrl")) {
value = valueOwner()->urlValue();
return valueOwner()->urlValue();
} else if (typeName == QLatin1String("bool")) {
value = valueOwner()->booleanValue();
return valueOwner()->booleanValue();
} else if (typeName == QLatin1String("int")
|| typeName == QLatin1String("long")) {
value = valueOwner()->intValue();
return valueOwner()->intValue();
} else if (typeName == QLatin1String("float")
|| typeName == QLatin1String("double")
|| typeName == QLatin1String("qreal")) {
// ### Review: more types here?
value = valueOwner()->realValue();
return valueOwner()->realValue();
} else if (typeName == QLatin1String("QFont")) {
value = valueOwner()->qmlFontObject();
return valueOwner()->qmlFontObject();
} else if (typeName == QLatin1String("QPoint")
|| typeName == QLatin1String("QPointF")
|| typeName == QLatin1String("QVector2D")) {
value = valueOwner()->qmlPointObject();
return valueOwner()->qmlPointObject();
} else if (typeName == QLatin1String("QSize")
|| typeName == QLatin1String("QSizeF")) {
value = valueOwner()->qmlSizeObject();
return valueOwner()->qmlSizeObject();
} else if (typeName == QLatin1String("QRect")
|| typeName == QLatin1String("QRectF")) {
value = valueOwner()->qmlRectObject();
return valueOwner()->qmlRectObject();
} else if (typeName == QLatin1String("QVector3D")) {
value = valueOwner()->qmlVector3DObject();
return valueOwner()->qmlVector3DObject();
} else if (typeName == QLatin1String("QColor")) {
value = valueOwner()->colorValue();
return valueOwner()->colorValue();
} else if (typeName == QLatin1String("QDeclarativeAnchorLine")) {
value = valueOwner()->anchorLineValue();
return valueOwner()->anchorLineValue();
}
if (value)
return value;
// might be an enum
const QmlObjectValue *base = this;
const QStringList components = typeName.split(QLatin1String("::"));
@@ -317,10 +313,11 @@ const Value *QmlObjectValue::propertyValue(const FakeMetaProperty &prop) const
typeName = components.last();
}
if (base) {
value = base->getEnumValue(typeName);
if (const QmlEnumValue *value = base->getEnumValue(typeName))
return value;
}
return value;
return valueOwner()->undefinedValue();
}
const QmlObjectValue *QmlObjectValue::prototype() const
@@ -377,18 +374,34 @@ bool QmlObjectValue::isListProperty(const QString &propertyName) const
return false;
}
FakeMetaEnum QmlObjectValue::getEnum(const QString &typeName) const
FakeMetaEnum QmlObjectValue::getEnum(const QString &typeName, const QmlObjectValue **foundInScope) const
{
const int index = _metaObject->enumeratorIndex(typeName);
if (index == -1)
return FakeMetaEnum();
return _metaObject->enumerator(index);
for (const QmlObjectValue *it = this; it; it = it->prototype()) {
FakeMetaObject::ConstPtr iter = it->_metaObject;
const int index = iter->enumeratorIndex(typeName);
if (index != -1) {
if (foundInScope)
*foundInScope = it;
return iter->enumerator(index);
}
}
if (foundInScope)
*foundInScope = 0;
return FakeMetaEnum();
}
const QmlEnumValue *QmlObjectValue::getEnumValue(const QString &typeName) const
const QmlEnumValue *QmlObjectValue::getEnumValue(const QString &typeName, const QmlObjectValue **foundInScope) const
{
return _enums.value(typeName, 0);
for (const QmlObjectValue *it = this; it; it = it->prototype()) {
if (const QmlEnumValue *e = it->_enums.value(typeName)) {
if (foundInScope)
*foundInScope = it;
return e;
}
}
if (foundInScope)
*foundInScope = 0;
return 0;
}
bool QmlObjectValue::isWritable(const QString &propertyName) const