diff --git a/src/libs/qmljs/qmljsinterpreter.cpp b/src/libs/qmljs/qmljsinterpreter.cpp index 26134908bf4d94c5cfc56a6062013756f0c69c38..f8ee91ca4423340d5b2d4086e5d1991ac407dfd8 100644 --- a/src/libs/qmljs/qmljsinterpreter.cpp +++ b/src/libs/qmljs/qmljsinterpreter.cpp @@ -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 diff --git a/src/libs/qmljs/qmljsinterpreter.h b/src/libs/qmljs/qmljsinterpreter.h index 0e7664c9706570447780451b2c76e1dd9d8aace9..ff4beffcf4c0f95d04d4b7df02220cd033f9b950 100644 --- a/src/libs/qmljs/qmljsinterpreter.h +++ b/src/libs/qmljs/qmljsinterpreter.h @@ -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; diff --git a/src/plugins/qmljseditor/qmlcodecompletion.cpp b/src/plugins/qmljseditor/qmlcodecompletion.cpp index a1be0e89ae88980d3b741baff74d2a432d4814d1..851b86eb55a5bee526443a22a3dc4e2186e1c4b8 100644 --- a/src/plugins/qmljseditor/qmlcodecompletion.cpp +++ b/src/plugins/qmljseditor/qmlcodecompletion.cpp @@ -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.