forked from qt-creator/qt-creator
QmlDesigner.Rewriter: Fixing dynamic properties
Dynamic properties were not properly rewritten. Change-Id: Icf2bdd41104aaaeb0473f0616958752dcb19fdb4 Reviewed-by: Marco Bubke <marco.bubke@digia.com>
This commit is contained in:
@@ -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(';'));
|
||||
|
@@ -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
|
||||
|
@@ -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());
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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
|
||||
} 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');
|
||||
|
||||
|
@@ -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("
|
||||
|
Reference in New Issue
Block a user