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 <thomas.hartmann@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2020-03-19 16:35:40 +02:00
parent ddca92fc93
commit ea16d20804

View File

@@ -38,6 +38,7 @@
#include <QUrl>
#include <QDebug>
#include <QtCore/qregularexpression.h>
namespace QmlDesigner {
@@ -45,10 +46,13 @@ static ModelNode createNodeFromNode(const ModelNode &modelNode,const QHash<QStri
static QString fixExpression(const QString &expression, const QHash<QString, QString> &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;
}