Skip to content
Permalink
Browse files

Add method to retrieve highlighted variable list from QgsExpressionCo…

…ntext
  • Loading branch information
nyalldawson committed Apr 7, 2019
1 parent 702804f commit ee51551baa816eeb411096a899068a1cd3c6ed9f
@@ -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 );
@@ -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;
@@ -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.
@@ -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" ) ) );
@@ -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()

0 comments on commit ee51551

Please sign in to comment.
You can’t perform that action at this time.