mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-12 00:02:25 -04:00
Highlight legend variables in expression editor
This commit is contained in:
parent
d58f84871d
commit
962ac268c4
@ -1000,7 +1000,6 @@ void QgsLayoutLegendWidget::mExpressionFilterButton_toggled( bool checked )
|
||||
|
||||
void QgsLayoutLegendWidget::mLayerExpressionButton_clicked()
|
||||
{
|
||||
|
||||
if ( !mLegend )
|
||||
{
|
||||
return;
|
||||
@ -1032,6 +1031,7 @@ void QgsLayoutLegendWidget::mLayerExpressionButton_clicked()
|
||||
|
||||
QgsFeatureRenderer *r = vl->renderer();
|
||||
|
||||
QStringList highlighted;
|
||||
if ( r )
|
||||
{
|
||||
const QgsLegendSymbolList legendSymbols = r->legendSymbolItems();
|
||||
@ -1042,16 +1042,20 @@ void QgsLayoutLegendWidget::mLayerExpressionButton_clicked()
|
||||
|
||||
symbolLegendScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "symbol_label" ), legendNode.symbolLabel().remove( QStringLiteral( "[%" ) ).remove( QStringLiteral( "%]" ) ), true ) );
|
||||
symbolLegendScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "symbol_id" ), legendSymbols.first().ruleKey(), true ) );
|
||||
highlighted << QStringLiteral( "symbol_label" ) << QStringLiteral( "symbol_id" );
|
||||
if ( vl )
|
||||
{
|
||||
symbolLegendScope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "symbol_count" ), QVariant::fromValue( vl->featureCount( legendSymbols.first().ruleKey() ) ), true ) );
|
||||
highlighted << QStringLiteral( "symbol_count" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
legendContext.appendScope( symbolLegendScope );
|
||||
|
||||
QgsExpressionBuilderDialog expressiondialog( vl, currentExpression, nullptr, "generic", legendContext );
|
||||
legendContext.setHighlightedVariables( highlighted );
|
||||
|
||||
QgsExpressionBuilderDialog expressiondialog( vl, currentExpression, nullptr, QStringLiteral( "generic" ), legendContext );
|
||||
if ( expressiondialog.exec() )
|
||||
layerNode->setLabelExpression( expressiondialog.expressionText() );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user