diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-07-02 13:07:01 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-07-02 13:07:01 (GMT) |
commit | 0357533025a7e4066def7665f3c77337f1ab21db (patch) | |
tree | a6aee166be2f9642035cba038c7adcb9e9c5aab2 | |
parent | 5d3ae53770a0b6ba0ad8c3271f6fcda72179c68e (diff) | |
download | Qt-0357533025a7e4066def7665f3c77337f1ab21db.zip Qt-0357533025a7e4066def7665f3c77337f1ab21db.tar.gz Qt-0357533025a7e4066def7665f3c77337f1ab21db.tar.bz2 |
implement string-->enum conversion
-rw-r--r-- | src/script/bridge/qscriptqobject.cpp | 10 | ||||
-rw-r--r-- | 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<MyQObject::Policy>(m_engine, policyToScriptValue, policyFromScriptValue); |