diff options
author | Thomas Hartmann <Thomas.Hartmann@theqtcompany.com> | 2016-09-23 12:51:52 +0200 |
---|---|---|
committer | Thomas Hartmann <Thomas.Hartmann@theqtcompany.com> | 2016-09-26 13:04:17 +0000 |
commit | b13094d0c8be0d8f6d6e168a03b2a0071c76cfb0 (patch) | |
tree | 31e879fde9d8c62ba2a9b0176fd851294d0bc99b /src/plugins/qmldesigner/designercore/model/abstractview.cpp | |
parent | 24925519b140ddc11831a3ac1adf9d041f99be07 (diff) | |
download | qt-creator-b13094d0c8be0d8f6d6e168a03b2a0071c76cfb0.tar.gz |
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 <tim.jenssen@qt.io>
Diffstat (limited to 'src/plugins/qmldesigner/designercore/model/abstractview.cpp')
-rw-r--r-- | src/plugins/qmldesigner/designercore/model/abstractview.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/plugins/qmldesigner/designercore/model/abstractview.cpp b/src/plugins/qmldesigner/designercore/model/abstractview.cpp index 91a0effec3..4673b33601 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_]"))); |