From ea16d208041cb5cdbf23236b9d93a8dc8ca08e28 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 19 Mar 2020 16:35:40 +0200 Subject: [PATCH] QmlDesigner: Fix id corruption on paste When pasting model nodes, any bound expression referring to a node in the same pasted set gets fixed so that the expression refers to a pasted copy of the node instead. This fix makes it so that only fully matching ids are replaced instead of also partial id matches. The old matching broke e.g. when the paste included both "cube" and "cubeMaterial" and a binding to "cubeMaterial". Without enforcing the full id matching, the binding became "cube1Material1". Change-Id: I3c622ea946c74d59a192157ca06d096467428364 Fixes: QDS-1564 Reviewed-by: Thomas Hartmann Reviewed-by: Mahmoud Badri --- .../qmldesigner/designercore/model/modelmerger.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plugins/qmldesigner/designercore/model/modelmerger.cpp b/src/plugins/qmldesigner/designercore/model/modelmerger.cpp index 8517f9cb827..4034faccdeb 100644 --- a/src/plugins/qmldesigner/designercore/model/modelmerger.cpp +++ b/src/plugins/qmldesigner/designercore/model/modelmerger.cpp @@ -38,6 +38,7 @@ #include #include +#include namespace QmlDesigner { @@ -45,10 +46,13 @@ static ModelNode createNodeFromNode(const ModelNode &modelNode,const QHash &idRenamingHash) { + const QString pattern("\\b%1\\b"); // Match only full ids QString newExpression = expression; - foreach (const QString &id, idRenamingHash.keys()) { - if (newExpression.contains(id)) - newExpression = newExpression.replace(id, idRenamingHash.value(id)); + const auto keys = idRenamingHash.keys(); + for (const QString &id : keys) { + QRegularExpression re(pattern.arg(id)); + if (newExpression.contains(re)) + newExpression = newExpression.replace(re, idRenamingHash.value(id)); } return newExpression; }