25#include "moc_qgslegendfilterbutton.cpp"
28 : QToolButton( parent )
31 mMenu =
new QMenu(
this );
32 mSetExpressionAction =
new QAction( tr(
"Edit Filter Expression…" ), mMenu );
33 connect( mSetExpressionAction, &QAction::triggered,
this, &QgsLegendFilterButton::onSetLegendFilterExpression );
35 mClearExpressionAction =
new QAction( tr(
"Clear Filter Expression" ), mMenu );
36 connect( mClearExpressionAction, &QAction::triggered,
this, &QgsLegendFilterButton::onClearFilterExpression );
37 mClearExpressionAction->setEnabled(
false );
39 mMenu->addAction( mSetExpressionAction );
40 mMenu->addAction( mClearExpressionAction );
44 setPopupMode( QToolButton::MenuButtonPopup );
48 connect(
this, &QAbstractButton::toggled,
this, &QgsLegendFilterButton::onToggle );
51void QgsLegendFilterButton::onToggle(
bool checked )
57 onSetLegendFilterExpression();
58 blockSignals(
false );
62void QgsLegendFilterButton::onSetLegendFilterExpression()
64 QgsExpressionContext context;
65 if ( mExpressionContextGenerator )
66 context = mExpressionContextGenerator->createExpressionContext();
71 QgsExpressionBuilderDialog dlg( mLayer, mExpression,
nullptr, QStringLiteral(
"generic" ), context );
76 bool emitSignal =
false;
79 emitSignal = isChecked();
84 emitSignal = !isChecked();
88 emit toggled( isChecked() );
94 mExpressionContextGenerator = generator;
97void QgsLegendFilterButton::onClearFilterExpression()
99 mClearExpressionAction->setEnabled(
false );
105void QgsLegendFilterButton::updateMenu()
107 if ( !mExpression.isEmpty() )
109 mClearExpressionAction->setEnabled(
true );
110 mSetExpressionAction->setText( tr(
"Edit Filter Expression (current: %1)" ).arg( mExpression ) );
114 mClearExpressionAction->setEnabled(
false );
115 mSetExpressionAction->setText( tr(
"Edit Filter Expression" ) );
126 mExpression = expression;
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Abstract interface for generating an expression context.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Represents a vector layer which manages a vector based dataset.