From 836c6279ebbb43e09d7754f3f43bfa29f9613315 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Wed, 19 Oct 2011 15:40:04 +0200 Subject: [PATCH] Update calls for keyToValue and keysToValue They are from QMetaEnum and changed recently Task-number: QTBUG-21672 Change-Id: I46698ec7eb4a1b23068146593ee93f71fc53a815 Reviewed-by: Kent Hansen Reviewed-by: Aaron Kennedy Reviewed-by: Liang Qi --- src/declarative/qml/qdeclarativecompiler.cpp | 26 +++++++++++++++----------- src/declarative/qml/qdeclarativeproperty.cpp | 7 +++++-- src/declarative/qml/v8/qv8typewrapper.cpp | 5 +++-- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 06d543a..5762f42 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -214,12 +214,13 @@ bool QDeclarativeCompiler::testLiteralAssignment(QDeclarativeScript::Property *p if (prop->core.isEnum()) { QMetaProperty p = prop->parent->metaObject()->property(prop->index); int enumValue; + bool ok; if (p.isFlagType()) { - enumValue = p.enumerator().keysToValue(value.asString().toUtf8().constData()); + enumValue = p.enumerator().keysToValue(value.asString().toUtf8().constData(), &ok); } else - enumValue = p.enumerator().keyToValue(value.asString().toUtf8().constData()); + enumValue = p.enumerator().keyToValue(value.asString().toUtf8().constData(), &ok); - if (enumValue == -1) + if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: unknown enumeration")); v->value = QDeclarativeScript::Variant((double)enumValue); @@ -2407,27 +2408,29 @@ bool QDeclarativeCompiler::testQualifiedEnumAssignment(const QMetaProperty &prop return true; QString enumValue = parts.at(1); - int value = -1; + int value; + bool ok; if (objTypeName == type->qmlTypeName()) { // When these two match, we can short cut the search if (prop.isFlagType()) { - value = prop.enumerator().keysToValue(enumValue.toUtf8().constData()); + value = prop.enumerator().keysToValue(enumValue.toUtf8().constData(), &ok); } else { - value = prop.enumerator().keyToValue(enumValue.toUtf8().constData()); + value = prop.enumerator().keyToValue(enumValue.toUtf8().constData(), &ok); } } else { // Otherwise we have to search the whole type // This matches the logic in QV8TypeWrapper QByteArray enumName = enumValue.toUtf8(); const QMetaObject *metaObject = type->baseMetaObject(); - for (int ii = metaObject->enumeratorCount() - 1; value == -1 && ii >= 0; --ii) { + ok = false; + for (int ii = metaObject->enumeratorCount() - 1; !ok && ii >= 0; --ii) { QMetaEnum e = metaObject->enumerator(ii); - value = e.keyToValue(enumName.constData()); + value = e.keyToValue(enumName.constData(), &ok); } } - if (value == -1) + if (!ok) return true; v->type = Value::Literal; @@ -2457,8 +2460,9 @@ int QDeclarativeCompiler::evaluateEnum(const QByteArray& script) const const char *key = script.constData() + dot+1; int i = mo->enumeratorCount(); while (i--) { - int v = mo->enumerator(i).keyToValue(key); - if (v >= 0) + bool ok; + int v = mo->enumerator(i).keyToValue(key, &ok); + if (ok) return v; } } diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp index 7a43ef1..9e4770f 100644 --- a/src/declarative/qml/qdeclarativeproperty.cpp +++ b/src/declarative/qml/qdeclarativeproperty.cpp @@ -1055,10 +1055,13 @@ bool QDeclarativePropertyPrivate::writeEnumProperty(const QMetaProperty &prop, i || v.userType() == QVariant::CString #endif ) { + bool ok; if (prop.isFlagType()) - v = QVariant(menum.keysToValue(value.toByteArray())); + v = QVariant(menum.keysToValue(value.toByteArray(), &ok)); else - v = QVariant(menum.keyToValue(value.toByteArray())); + v = QVariant(menum.keyToValue(value.toByteArray(), &ok)); + if (!ok) + return false; } else if (v.userType() != QVariant::Int && v.userType() != QVariant::UInt) { int enumMetaTypeId = QMetaType::type(QByteArray(menum.scope() + QByteArray("::") + menum.name())); if ((enumMetaTypeId == 0) || (v.userType() != enumMetaTypeId) || !v.constData()) diff --git a/src/declarative/qml/v8/qv8typewrapper.cpp b/src/declarative/qml/v8/qv8typewrapper.cpp index c89d5ab..0023afc 100644 --- a/src/declarative/qml/v8/qv8typewrapper.cpp +++ b/src/declarative/qml/v8/qv8typewrapper.cpp @@ -223,8 +223,9 @@ v8::Handle QV8TypeWrapper::Getter(v8::Local property, const QMetaObject *metaObject = moduleApi->qobjectApi->metaObject(); for (int ii = metaObject->enumeratorCount() - 1; ii >= 0; --ii) { QMetaEnum e = metaObject->enumerator(ii); - int value = e.keyToValue(enumName.constData()); - if (value != -1) + bool ok; + int value = e.keyToValue(enumName.constData(), &ok); + if (ok) return v8::Integer::New(value); } } -- 1.7.2.5