Skip to content

Commit

Permalink
Include variable name in result
Browse files Browse the repository at this point in the history
(cherry picked from commit f618993)
  • Loading branch information
nyalldawson committed Oct 25, 2024
1 parent e0fd657 commit 4d0578a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/core/qgsexpressioncontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ QString QgsExpressionContext::uniqueHash( bool &ok, const QSet<QString> &variabl
for ( const QString &variableName : std::as_const( sortedVars ) )
{
const QVariant value = variable( variableName );
hash.append( variableName + "=" );
if ( QgsVariantUtils::isNull( value ) )
{
hash.append( delimiter );
Expand Down
8 changes: 4 additions & 4 deletions tests/src/core/testqgsexpressioncontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4d0578a

Please sign in to comment.