QmlDesigner: Fix renaming materials

Check for id validity during id generation and try to fix invalid id.

Fixes: QDS-7437
Change-Id: I9d7665cbebdce8ee3395e4abe9ee14b26866f761
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2022-09-20 16:44:24 +03:00
parent 6b8e2fbd49
commit b080376f70

View File

@@ -1577,6 +1577,10 @@ QString Model::generateIdFromName(const QString &name, const QString &fallbackId
newId.prepend('_');
}
// If the new id is not valid (e.g. qml keyword match), try fixing it by prepending underscore
if (!ModelNode::isValidId(newId))
newId.prepend("_");
QRegularExpression rgx("\\d+$"); // matches a number at the end of a string
while (hasId(newId)) { // id exists
QRegularExpressionMatch match = rgx.match(newId);