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()
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)
{
#ifndef NO_DECLARATIVE_BACKEND
......
......@@ -442,6 +442,7 @@ public:
// QML objects
ObjectValue *newQmlObject(const QString &name);
const ObjectValue *qmlKeysObject();
const Value *defaultValueForBuiltinType(const QString &typeName) const;
// global object
ObjectValue *globalObject() const;
......
......@@ -134,15 +134,7 @@ static Interpreter::ObjectValue *newComponent(Interpreter::Engine *engine, const
const QString propName = prop->name->asString();
const QString propType = prop->memberType->asString();
// ### generalize
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());
object->setProperty(propName, engine->defaultValueForBuiltinType(propType));
}
}
}
......@@ -867,13 +859,7 @@ int QmlCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
const QString propName = prop->name->asString();
const QString propType = prop->memberType->asString();
// ### TODO: generalize
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());
interp.globalObject()->setProperty(propName, interp.defaultValueForBuiltinType(propType));
}
// 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