diff --git a/src/plugins/qmldesigner/designercore/filemanager/addpropertyvisitor.cpp b/src/plugins/qmldesigner/designercore/filemanager/addpropertyvisitor.cpp index df647e181f9..37af895cea9 100644 --- a/src/plugins/qmldesigner/designercore/filemanager/addpropertyvisitor.cpp +++ b/src/plugins/qmldesigner/designercore/filemanager/addpropertyvisitor.cpp @@ -42,13 +42,15 @@ AddPropertyVisitor::AddPropertyVisitor(QmlDesigner::TextModifier &modifier, const QmlDesigner::PropertyName &name, const QString &value, QmlRefactoring::PropertyType propertyType, - const PropertyNameList &propertyOrder): + const PropertyNameList &propertyOrder, + const QmlDesigner::TypeName &dynamicTypeName) : QMLRewriter(modifier), m_parentLocation(parentLocation), m_name(name), m_value(value), m_propertyType(propertyType), - m_propertyOrder(propertyOrder) + m_propertyOrder(propertyOrder), + m_dynamicTypeName(dynamicTypeName) { } @@ -147,6 +149,9 @@ void AddPropertyVisitor::addInMembers(QmlJS::AST::UiObjectInitializer *initializ Q_ASSERT(!"unknown property type"); } + if (!m_dynamicTypeName.isEmpty()) + newPropertyTemplate.prepend(QString(QLatin1String("property %1 ")).arg(QString::fromUtf8(m_dynamicTypeName))); + if (isOneLiner) { if (needsPreceedingSemicolon) newPropertyTemplate.prepend(QLatin1Char(';')); diff --git a/src/plugins/qmldesigner/designercore/filemanager/addpropertyvisitor.h b/src/plugins/qmldesigner/designercore/filemanager/addpropertyvisitor.h index c5da91fbaa9..869edf50030 100644 --- a/src/plugins/qmldesigner/designercore/filemanager/addpropertyvisitor.h +++ b/src/plugins/qmldesigner/designercore/filemanager/addpropertyvisitor.h @@ -45,7 +45,8 @@ public: const QmlDesigner::PropertyName &name, const QString &value, QmlDesigner::QmlRefactoring::PropertyType propertyType, - const PropertyNameList &propertyOrder); + const PropertyNameList &propertyOrder, + const QmlDesigner::TypeName &dynamicTypeName); protected: virtual bool visit(QmlJS::AST::UiObjectDefinition *ast); @@ -60,6 +61,7 @@ private: QString m_value; QmlRefactoring::PropertyType m_propertyType; PropertyNameList m_propertyOrder; + QmlDesigner::TypeName m_dynamicTypeName; }; } // namespace Internal diff --git a/src/plugins/qmldesigner/designercore/filemanager/qmlrefactoring.cpp b/src/plugins/qmldesigner/designercore/filemanager/qmlrefactoring.cpp index a5646cdd02d..674e2a1aa7f 100644 --- a/src/plugins/qmldesigner/designercore/filemanager/qmlrefactoring.cpp +++ b/src/plugins/qmldesigner/designercore/filemanager/qmlrefactoring.cpp @@ -103,12 +103,16 @@ bool QmlRefactoring::addToObjectMemberList(int parentLocation, const QString &co return visit(qmlDocument->qmlProgram()); } -bool QmlRefactoring::addProperty(int parentLocation, const PropertyName &name, const QString &value, PropertyType propertyType) +bool QmlRefactoring::addProperty(int parentLocation, + const PropertyName &name, + const QString &value, + PropertyType propertyType, + const TypeName &dynamicTypeName) { if (parentLocation < 0) return false; - AddPropertyVisitor visit(*textModifier, (quint32) parentLocation, name, value, propertyType, m_propertyOrder); + AddPropertyVisitor visit(*textModifier, (quint32) parentLocation, name, value, propertyType, m_propertyOrder, dynamicTypeName); return visit(qmlDocument->qmlProgram()); } diff --git a/src/plugins/qmldesigner/designercore/filemanager/qmlrefactoring.h b/src/plugins/qmldesigner/designercore/filemanager/qmlrefactoring.h index 62359333791..c6376cfbf41 100644 --- a/src/plugins/qmldesigner/designercore/filemanager/qmlrefactoring.h +++ b/src/plugins/qmldesigner/designercore/filemanager/qmlrefactoring.h @@ -60,7 +60,11 @@ public: bool addToArrayMemberList(int parentLocation, const PropertyName &propertyName, const QString &content); bool addToObjectMemberList(int parentLocation, const QString &content); - bool addProperty(int parentLocation, const PropertyName &name, const QString &value, PropertyType propertyType); + bool addProperty(int parentLocation, + const PropertyName &name, + const QString &value, + PropertyType propertyType, + const TypeName &dynamicTypeName = TypeName()); bool changeProperty(int parentLocation, const PropertyName &name, const QString &value, PropertyType propertyType); bool changeObjectType(int nodeLocation, const QString &newType); diff --git a/src/plugins/qmldesigner/designercore/model/qmltextgenerator.cpp b/src/plugins/qmldesigner/designercore/model/qmltextgenerator.cpp index 1fe6d0e0272..4fa4a8b82ba 100644 --- a/src/plugins/qmldesigner/designercore/model/qmltextgenerator.cpp +++ b/src/plugins/qmldesigner/designercore/model/qmltextgenerator.cpp @@ -230,10 +230,21 @@ QString QmlTextGenerator::propertyToQml(const AbstractProperty &property, int in { QString result; - if (property.isDefaultProperty()) + if (property.isDefaultProperty()) { result = toQml(property, indentDepth); - else - result = QString(indentDepth, QLatin1Char(' ')) + property.name() + QLatin1String(": ") + toQml(property, indentDepth); + } else { + if (property.isDynamic()) { + result = QString(indentDepth, QLatin1Char(' ')) + + QLatin1String("property ") + + property.dynamicTypeName() + + QLatin1String(" ") + + property.name() + + QLatin1String(": ") + + toQml(property, indentDepth); + } else { + result = QString(indentDepth, QLatin1Char(' ')) + property.name() + QLatin1String(": ") + toQml(property, indentDepth); + } + } result += QLatin1Char('\n'); diff --git a/src/plugins/qmldesigner/designercore/model/rewriteaction.cpp b/src/plugins/qmldesigner/designercore/model/rewriteaction.cpp index 91875e09797..41abf3d2cb7 100644 --- a/src/plugins/qmldesigner/designercore/model/rewriteaction.cpp +++ b/src/plugins/qmldesigner/designercore/model/rewriteaction.cpp @@ -107,7 +107,7 @@ bool AddPropertyRewriteAction::execute(QmlRefactoring &refactoring, ModelNodePos << info(); } } else { - result = refactoring.addProperty(nodeLocation, m_property.name(), m_valueText, m_propertyType); + result = refactoring.addProperty(nodeLocation, m_property.name(), m_valueText, m_propertyType, m_property.dynamicTypeName()); if (!result) { qDebug() << "*** AddPropertyRewriteAction::execute failed in addProperty("