Commit 478907e5 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Added method defaultValueForBuiltinType(typeName) to the QML/JS interpreter.

parent 84d72107
...@@ -1680,6 +1680,19 @@ const ObjectValue *Engine::qmlKeysObject() ...@@ -1680,6 +1680,19 @@ const ObjectValue *Engine::qmlKeysObject()
return _qmlKeysObject; return _qmlKeysObject;
} }
const Value *Engine::defaultValueForBuiltinType(const QString &typeName) const
{
if (typeName == QLatin1String("string") || typeName == QLatin1String("url"))
return stringValue();
else if (typeName == QLatin1String("bool"))
return booleanValue();
else if (typeName == QLatin1String("int") || typeName == QLatin1String("real"))
return numberValue();
// ### more types...
return undefinedValue();
}
ObjectValue *Engine::newQmlObject(const QString &name) ObjectValue *Engine::newQmlObject(const QString &name)
{ {
#ifndef NO_DECLARATIVE_BACKEND #ifndef NO_DECLARATIVE_BACKEND
......
...@@ -442,6 +442,7 @@ public: ...@@ -442,6 +442,7 @@ public:
// QML objects // QML objects
ObjectValue *newQmlObject(const QString &name); ObjectValue *newQmlObject(const QString &name);
const ObjectValue *qmlKeysObject(); const ObjectValue *qmlKeysObject();
const Value *defaultValueForBuiltinType(const QString &typeName) const;
// global object // global object
ObjectValue *globalObject() const; ObjectValue *globalObject() const;
......
...@@ -134,15 +134,7 @@ static Interpreter::ObjectValue *newComponent(Interpreter::Engine *engine, const ...@@ -134,15 +134,7 @@ static Interpreter::ObjectValue *newComponent(Interpreter::Engine *engine, const
const QString propName = prop->name->asString(); const QString propName = prop->name->asString();
const QString propType = prop->memberType->asString(); const QString propType = prop->memberType->asString();
// ### generalize object->setProperty(propName, engine->defaultValueForBuiltinType(propType));
if (propType == QLatin1String("string") || propType == QLatin1String("url"))
object->setProperty(propName, engine->stringValue());
else if (propType == QLatin1String("bool"))
object->setProperty(propName, engine->booleanValue());
else if (propType == QLatin1String("int") || propType == QLatin1String("real"))
object->setProperty(propName, engine->numberValue());
else
object->setProperty(propName, engine->undefinedValue());
} }
} }
} }
...@@ -867,13 +859,7 @@ int QmlCodeCompletion::startCompletion(TextEditor::ITextEditable *editor) ...@@ -867,13 +859,7 @@ int QmlCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
const QString propName = prop->name->asString(); const QString propName = prop->name->asString();
const QString propType = prop->memberType->asString(); const QString propType = prop->memberType->asString();
// ### TODO: generalize interp.globalObject()->setProperty(propName, interp.defaultValueForBuiltinType(propType));
if (propType == QLatin1String("string") || propType == QLatin1String("url"))
interp.globalObject()->setProperty(propName, interp.stringValue());
else if (propType == QLatin1String("bool"))
interp.globalObject()->setProperty(propName, interp.booleanValue());
else if (propType == QLatin1String("int") || propType == QLatin1String("real"))
interp.globalObject()->setProperty(propName, interp.numberValue());
} }
// Get the name of the declaring item. // Get the name of the declaring item.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment