26#include "moc_qgslegendfilterbutton.cpp"
28using namespace Qt::StringLiterals;
31 : QToolButton( parent )
34 mMenu =
new QMenu(
this );
35 mSetExpressionAction =
new QAction( tr(
"Edit Filter Expression…" ), mMenu );
36 connect( mSetExpressionAction, &QAction::triggered,
this, &QgsLegendFilterButton::onSetLegendFilterExpression );
38 mClearExpressionAction =
new QAction( tr(
"Clear Filter Expression" ), mMenu );
39 connect( mClearExpressionAction, &QAction::triggered,
this, &QgsLegendFilterButton::onClearFilterExpression );
40 mClearExpressionAction->setEnabled(
false );
42 mMenu->addAction( mSetExpressionAction );
43 mMenu->addAction( mClearExpressionAction );
47 setPopupMode( QToolButton::MenuButtonPopup );
51 connect(
this, &QAbstractButton::toggled,
this, &QgsLegendFilterButton::onToggle );
54void QgsLegendFilterButton::onToggle(
bool checked )
60 onSetLegendFilterExpression();
61 blockSignals(
false );
65void QgsLegendFilterButton::onSetLegendFilterExpression()
67 QgsExpressionContext context;
68 if ( mExpressionContextGenerator )
69 context = mExpressionContextGenerator->createExpressionContext();
74 QgsExpressionBuilderDialog dlg( mLayer, mExpression,
nullptr, u
"generic"_s, context );
79 bool emitSignal =
false;
82 emitSignal = isChecked();
87 emitSignal = !isChecked();
91 emit toggled( isChecked() );
97 mExpressionContextGenerator = generator;
100void QgsLegendFilterButton::onClearFilterExpression()
102 mClearExpressionAction->setEnabled(
false );
108void QgsLegendFilterButton::updateMenu()
110 if ( !mExpression.isEmpty() )
112 mClearExpressionAction->setEnabled(
true );
113 mSetExpressionAction->setText( tr(
"Edit Filter Expression (current: %1)" ).arg( mExpression ) );
117 mClearExpressionAction->setEnabled(
false );
118 mSetExpressionAction->setText( tr(
"Edit Filter Expression" ) );
129 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.