Skip to content

Commit ee51551

Browse files
committed
Add method to retrieve highlighted variable list from QgsExpressionContext
1 parent 702804f commit ee51551

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

python/core/auto_generated/qgsexpressioncontext.sip.in

+9
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,15 @@ variable.
448448
.. seealso:: :py:func:`setHighlightedVariables`
449449

450450
.. seealso:: :py:func:`isHighlightedFunction`
451+
%End
452+
453+
QStringList highlightedVariables() const;
454+
%Docstring
455+
Returns the current list of variables highlighted within the context.
456+
457+
.. seealso:: :py:func:`setHighlightedVariables`
458+
459+
.. versionadded:: 3.8
451460
%End
452461

453462
void setHighlightedVariables( const QStringList &variableNames );

src/core/qgsexpressioncontext.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ bool QgsExpressionContext::isHighlightedVariable( const QString &name ) const
318318
return mHighlightedVariables.contains( name );
319319
}
320320

321+
QStringList QgsExpressionContext::highlightedVariables() const
322+
{
323+
return mHighlightedVariables;
324+
}
325+
321326
void QgsExpressionContext::setHighlightedVariables( const QStringList &variableNames )
322327
{
323328
mHighlightedVariables = variableNames;

src/core/qgsexpressioncontext.h

+8
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,14 @@ class CORE_EXPORT QgsExpressionContext
429429
*/
430430
bool isHighlightedVariable( const QString &name ) const;
431431

432+
/**
433+
* Returns the current list of variables highlighted within the context.
434+
*
435+
* \see setHighlightedVariables()
436+
* \since QGIS 3.8
437+
*/
438+
QStringList highlightedVariables() const;
439+
432440
/**
433441
* Sets the list of variable names within the context intended to be highlighted to the user. This
434442
* is used by the expression builder to more prominently display these variables.

tests/src/core/testqgsexpressioncontext.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,14 @@ void TestQgsExpressionContext::highlighted()
551551
QgsExpressionContext context;
552552
QVERIFY( !context.isHighlightedFunction( QStringLiteral( "x" ) ) );
553553
QVERIFY( !context.isHighlightedVariable( QStringLiteral( "x" ) ) );
554+
QVERIFY( context.highlightedVariables().isEmpty() );
554555
context.setHighlightedFunctions( QStringList() << QStringLiteral( "x" ) << QStringLiteral( "y" ) );
555556
QVERIFY( context.isHighlightedFunction( QStringLiteral( "x" ) ) );
556557
QVERIFY( context.isHighlightedFunction( QStringLiteral( "y" ) ) );
557558
QVERIFY( !context.isHighlightedFunction( QStringLiteral( "z" ) ) );
558559
QVERIFY( !context.isHighlightedVariable( QStringLiteral( "x" ) ) );
559560
context.setHighlightedVariables( QStringList() << QStringLiteral( "a" ) << QStringLiteral( "b" ) );
561+
QCOMPARE( context.highlightedVariables(), QStringList() << QStringLiteral( "a" ) << QStringLiteral( "b" ) );
560562
QVERIFY( context.isHighlightedVariable( QStringLiteral( "a" ) ) );
561563
QVERIFY( context.isHighlightedVariable( QStringLiteral( "b" ) ) );
562564
QVERIFY( !context.isHighlightedVariable( QStringLiteral( "c" ) ) );
@@ -565,6 +567,7 @@ void TestQgsExpressionContext::highlighted()
565567
context.setHighlightedVariables( QStringList() );
566568
QVERIFY( !context.isHighlightedFunction( QStringLiteral( "x" ) ) );
567569
QVERIFY( !context.isHighlightedVariable( QStringLiteral( "a" ) ) );
570+
QVERIFY( context.highlightedVariables().isEmpty() );
568571
}
569572

570573
void TestQgsExpressionContext::globalScope()

0 commit comments

Comments
 (0)