From b13094d0c8be0d8f6d6e168a03b2a0071c76cfb0 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Fri, 23 Sep 2016 12:51:52 +0200 Subject: [PATCH] QmlDesigner: Change logic for default id creation We should not append a '1' to the type name and tye the lower case type name first. We do not allow properties of the root item and 'item'. The name 'item' is simply to ambiguous. Change-Id: I31c3ac0c40015ea750d00d274ca0d40fa1444cf9 Reviewed-by: Tim Jenssen --- .../qmldesigner/designercore/model/abstractview.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/model/abstractview.cpp b/src/plugins/qmldesigner/designercore/model/abstractview.cpp index 91a0effec3c..4673b33601a 100644 --- a/src/plugins/qmldesigner/designercore/model/abstractview.cpp +++ b/src/plugins/qmldesigner/designercore/model/abstractview.cpp @@ -467,10 +467,17 @@ QString AbstractView::generateNewId(const QString &prefixName) const { int counter = 1; - QString newId = QString(QStringLiteral("%1%2")).arg(firstCharToLower(prefixName)).arg(counter); + /* First try just the prefixName without number as postfix, then continue with 2 and further as postfix + * until id does not already exist. + * Properties of the root node are not allowed for ids, because they are available in the complete context + * without qualification. + * The id "item" is explicitly not allowed, because it is too likely to clash. + */ + + QString newId = QString(QStringLiteral("%1")).arg(firstCharToLower(prefixName)); newId.remove(QRegExp(QStringLiteral("[^a-zA-Z0-9_]"))); - while (hasId(newId)) { + while (hasId(newId) || rootModelNode().hasProperty(newId.toUtf8()) || newId == "item") { counter += 1; newId = QString(QStringLiteral("%1%2")).arg(firstCharToLower(prefixName)).arg(counter); newId.remove(QRegExp(QStringLiteral("[^a-zA-Z0-9_]")));