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>
This commit is contained in:
Thomas Hartmann
2016-09-23 12:51:52 +02:00
parent 24925519b1
commit b13094d0c8

View File

@@ -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_]")));