Skip to content
Snippets Groups Projects
Commit 6622947c authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

QML editor: also check for objectName property when guessing the name.

parent 825562eb
No related branches found
No related tags found
No related merge requests found
...@@ -46,8 +46,23 @@ using namespace QmlJSEditor::Internal; ...@@ -46,8 +46,23 @@ using namespace QmlJSEditor::Internal;
namespace { namespace {
static QString toString(Statement *statement)
{
ExpressionStatement *expStmt = cast<ExpressionStatement *>(statement);
if (!expStmt)
return QString::null;
if (IdentifierExpression *idExp = cast<IdentifierExpression *>(expStmt->expression)) {
return idExp->name->asString();
} else if (StringLiteral *strExp = cast<StringLiteral *>(expStmt->expression)) {
return strExp->value->asString();
}
return QString::null;
}
static QString getIdProperty(UiObjectDefinition *def) static QString getIdProperty(UiObjectDefinition *def)
{ {
QString objectName;
if (def && def->initializer) { if (def && def->initializer) {
for (UiObjectMemberList *iter = def->initializer->members; iter; iter = iter->next) { for (UiObjectMemberList *iter = def->initializer->members; iter; iter = iter->next) {
if (UiScriptBinding *script = cast<UiScriptBinding*>(iter->member)) { if (UiScriptBinding *script = cast<UiScriptBinding*>(iter->member)) {
...@@ -56,22 +71,16 @@ static QString getIdProperty(UiObjectDefinition *def) ...@@ -56,22 +71,16 @@ static QString getIdProperty(UiObjectDefinition *def)
if (script->qualifiedId->next) if (script->qualifiedId->next)
continue; continue;
if (script->qualifiedId->name) { if (script->qualifiedId->name) {
if (script->qualifiedId->name->asString() == QLatin1String("id")) { if (script->qualifiedId->name->asString() == QLatin1String("id"))
ExpressionStatement *expStmt = cast<ExpressionStatement *>(script->statement); return toString(script->statement);
if (!expStmt) if (script->qualifiedId->name->asString() == QLatin1String("objectName"))
continue; objectName = toString(script->statement);
if (IdentifierExpression *idExp = cast<IdentifierExpression *>(expStmt->expression)) {
return idExp->name->asString();
} else if (StringLiteral *strExp = cast<StringLiteral *>(expStmt->expression)) {
return strExp->value->asString();
}
}
} }
} }
} }
} }
return QString(); return objectName;
} }
class Operation: public QmlJSQuickFixOperation class Operation: public QmlJSQuickFixOperation
...@@ -90,7 +99,7 @@ public: ...@@ -90,7 +99,7 @@ public:
if (m_componentName.isEmpty()) { if (m_componentName.isEmpty()) {
setDescription(QCoreApplication::translate("QmlJSEditor::ComponentFromObjectDef", setDescription(QCoreApplication::translate("QmlJSEditor::ComponentFromObjectDef",
"Move Component into separate file'")); "Move Component into separate file"));
} else { } else {
m_componentName[0] = m_componentName.at(0).toUpper(); m_componentName[0] = m_componentName.at(0).toUpper();
setDescription(QCoreApplication::translate("QmlJSEditor::ComponentFromObjectDef", setDescription(QCoreApplication::translate("QmlJSEditor::ComponentFromObjectDef",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment