From b080376f70cfa729d2911730276ed943c40f9c96 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 20 Sep 2022 16:44:24 +0300 Subject: [PATCH] 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 --- src/plugins/qmldesigner/designercore/model/model.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/plugins/qmldesigner/designercore/model/model.cpp b/src/plugins/qmldesigner/designercore/model/model.cpp index f6f852bf47d..ef4e3cb2f78 100644 --- a/src/plugins/qmldesigner/designercore/model/model.cpp +++ b/src/plugins/qmldesigner/designercore/model/model.cpp @@ -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);