From 4d0578a2ace779e902e47b06465eff8491b085b2 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 11 Oct 2024 11:06:15 +1000 Subject: [PATCH] Include variable name in result (cherry picked from commit f618993f774a2421b7fcda3136530b98aa9526d3) --- src/core/qgsexpressioncontext.cpp | 1 + tests/src/core/testqgsexpressioncontext.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/qgsexpressioncontext.cpp b/src/core/qgsexpressioncontext.cpp index 1301ebc98436..c2d852d20365 100644 --- a/src/core/qgsexpressioncontext.cpp +++ b/src/core/qgsexpressioncontext.cpp @@ -785,6 +785,7 @@ QString QgsExpressionContext::uniqueHash( bool &ok, const QSet &variabl for ( const QString &variableName : std::as_const( sortedVars ) ) { const QVariant value = variable( variableName ); + hash.append( variableName + "=" ); if ( QgsVariantUtils::isNull( value ) ) { hash.append( delimiter ); diff --git a/tests/src/core/testqgsexpressioncontext.cpp b/tests/src/core/testqgsexpressioncontext.cpp index 392d298d0783..0751b59b5c4f 100644 --- a/tests/src/core/testqgsexpressioncontext.cpp +++ b/tests/src/core/testqgsexpressioncontext.cpp @@ -1052,27 +1052,27 @@ void TestQgsExpressionContext::uniqueHash() QSet< QString > vars; vars.insert( QStringLiteral( "var1" ) ); vars.insert( QStringLiteral( "var2" ) ); - QCOMPARE( context.uniqueHash( ok, vars ), QStringLiteral( "||~~||||~~||" ) ); + QCOMPARE( context.uniqueHash( ok, vars ), QStringLiteral( "var1=||~~||var2=||~~||" ) ); QVERIFY( ok ); QgsExpressionContextScope *scope1 = new QgsExpressionContextScope(); context.appendScope( scope1 ); scope1->setVariable( QStringLiteral( "var1" ), QStringLiteral( "a string" ) ); scope1->setVariable( QStringLiteral( "var2" ), 5 ); - QCOMPARE( context.uniqueHash( ok, vars ), QStringLiteral( "a string||~~||5||~~||" ) ); + QCOMPARE( context.uniqueHash( ok, vars ), QStringLiteral( "var1=a string||~~||var2=5||~~||" ) ); QVERIFY( ok ); QgsExpressionContextScope *scope2 = new QgsExpressionContextScope(); context.appendScope( scope2 ); scope2->setVariable( QStringLiteral( "var1" ), QStringLiteral( "b string" ) ); - QCOMPARE( context.uniqueHash( ok, vars ), QStringLiteral( "b string||~~||5||~~||" ) ); + QCOMPARE( context.uniqueHash( ok, vars ), QStringLiteral( "var1=b string||~~||var2=5||~~||" ) ); QVERIFY( ok ); QgsFeature feature; feature.setId( 11 ); feature.setAttributes( QgsAttributes() << 5 << 11 ); context.setFeature( feature ); - QCOMPARE( context.uniqueHash( ok, vars ), QStringLiteral( "11||~~||1566||~~||b string||~~||5||~~||" ) ); + QCOMPARE( context.uniqueHash( ok, vars ), QStringLiteral( "11||~~||1566||~~||var1=b string||~~||var2=5||~~||" ) ); QVERIFY( ok ); // a value which can't be converted to string