From 0357533025a7e4066def7665f3c77337f1ab21db Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Thu, 2 Jul 2009 15:07:01 +0200 Subject: implement string-->enum conversion --- src/script/bridge/qscriptqobject.cpp | 10 +++++++++- tests/auto/qscriptqobject/tst_qscriptqobject.cpp | 2 -- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp index 716a0e4..8a77018 100644 --- a/src/script/bridge/qscriptqobject.cpp +++ b/src/script/bridge/qscriptqobject.cpp @@ -1254,7 +1254,15 @@ void QObjectWrapperObject::put(JSC::ExecState* exec, const JSC::Identifier& prop if (prop.isScriptable()) { if (!(opt & QScriptEngine::ExcludeSuperClassProperties) || (index >= meta->propertyOffset())) { - QVariant v = eng->jscValueToVariant(value, prop.userType()); + QVariant v; + if (prop.isEnumType() && value.isString() + && !eng->hasDemarshalFunction(prop.userType())) { + // give QMetaProperty::write() a chance to convert from + // string to enum value + v = qtStringFromJSCUString(value.toString(exec)); + } else { + v = eng->jscValueToVariant(value, prop.userType()); + } (void)prop.write(qobject, v); return; } diff --git a/tests/auto/qscriptqobject/tst_qscriptqobject.cpp b/tests/auto/qscriptqobject/tst_qscriptqobject.cpp index 89dbd3d..f471edb 100644 --- a/tests/auto/qscriptqobject/tst_qscriptqobject.cpp +++ b/tests/auto/qscriptqobject/tst_qscriptqobject.cpp @@ -807,11 +807,9 @@ void tst_QScriptExtQObject::getSetStaticProperty() m_engine->evaluate("myObject.enumProperty = 2"); QCOMPARE(m_myObject->enumProperty(), MyQObject::BazPolicy); m_engine->evaluate("myObject.enumProperty = 'BarPolicy'"); - QEXPECT_FAIL("", "Doesn't work yet", Continue); QCOMPARE(m_myObject->enumProperty(), MyQObject::BarPolicy); m_engine->evaluate("myObject.enumProperty = 'ScoobyDoo'"); // ### ouch! Shouldn't QMetaProperty::write() rather not change the value...? - QEXPECT_FAIL("", "Doesn't work yet", Continue); QCOMPARE(m_myObject->enumProperty(), (MyQObject::Policy)-1); // enum property with custom conversion qScriptRegisterMetaType(m_engine, policyToScriptValue, policyFromScriptValue); -- cgit v0.12