Skip to content

Commit

Permalink
Add method to retrieve highlighted variable list from QgsExpressionCo…
Browse files Browse the repository at this point in the history
…ntext
  • Loading branch information
nyalldawson committed Apr 7, 2019
1 parent 702804f commit ee51551
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions python/core/auto_generated/qgsexpressioncontext.sip.in
Expand Up @@ -448,6 +448,15 @@ variable.
.. seealso:: :py:func:`setHighlightedVariables`

.. seealso:: :py:func:`isHighlightedFunction`
%End

QStringList highlightedVariables() const;
%Docstring
Returns the current list of variables highlighted within the context.

.. seealso:: :py:func:`setHighlightedVariables`

.. versionadded:: 3.8
%End

void setHighlightedVariables( const QStringList &variableNames );
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsexpressioncontext.cpp
Expand Up @@ -318,6 +318,11 @@ bool QgsExpressionContext::isHighlightedVariable( const QString &name ) const
return mHighlightedVariables.contains( name );
}

QStringList QgsExpressionContext::highlightedVariables() const
{
return mHighlightedVariables;
}

void QgsExpressionContext::setHighlightedVariables( const QStringList &variableNames )
{
mHighlightedVariables = variableNames;
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsexpressioncontext.h
Expand Up @@ -429,6 +429,14 @@ class CORE_EXPORT QgsExpressionContext
*/
bool isHighlightedVariable( const QString &name ) const;

/**
* Returns the current list of variables highlighted within the context.
*
* \see setHighlightedVariables()
* \since QGIS 3.8
*/
QStringList highlightedVariables() const;

/**
* Sets the list of variable names within the context intended to be highlighted to the user. This
* is used by the expression builder to more prominently display these variables.
Expand Down
3 changes: 3 additions & 0 deletions tests/src/core/testqgsexpressioncontext.cpp
Expand Up @@ -551,12 +551,14 @@ void TestQgsExpressionContext::highlighted()
QgsExpressionContext context;
QVERIFY( !context.isHighlightedFunction( QStringLiteral( "x" ) ) );
QVERIFY( !context.isHighlightedVariable( QStringLiteral( "x" ) ) );
QVERIFY( context.highlightedVariables().isEmpty() );
context.setHighlightedFunctions( QStringList() << QStringLiteral( "x" ) << QStringLiteral( "y" ) );
QVERIFY( context.isHighlightedFunction( QStringLiteral( "x" ) ) );
QVERIFY( context.isHighlightedFunction( QStringLiteral( "y" ) ) );
QVERIFY( !context.isHighlightedFunction( QStringLiteral( "z" ) ) );
QVERIFY( !context.isHighlightedVariable( QStringLiteral( "x" ) ) );
context.setHighlightedVariables( QStringList() << QStringLiteral( "a" ) << QStringLiteral( "b" ) );
QCOMPARE( context.highlightedVariables(), QStringList() << QStringLiteral( "a" ) << QStringLiteral( "b" ) );
QVERIFY( context.isHighlightedVariable( QStringLiteral( "a" ) ) );
QVERIFY( context.isHighlightedVariable( QStringLiteral( "b" ) ) );
QVERIFY( !context.isHighlightedVariable( QStringLiteral( "c" ) ) );
Expand All @@ -565,6 +567,7 @@ void TestQgsExpressionContext::highlighted()
context.setHighlightedVariables( QStringList() );
QVERIFY( !context.isHighlightedFunction( QStringLiteral( "x" ) ) );
QVERIFY( !context.isHighlightedVariable( QStringLiteral( "a" ) ) );
QVERIFY( context.highlightedVariables().isEmpty() );
}

void TestQgsExpressionContext::globalScope()
Expand Down

0 comments on commit ee51551

Please sign in to comment.