25 : QToolButton( parent )
28 mMenu =
new QMenu(
this );
29 mSetExpressionAction =
new QAction( tr(
"Edit Filter Expression…" ), mMenu );
30 connect( mSetExpressionAction, &QAction::triggered,
this, &QgsLegendFilterButton::onSetLegendFilterExpression );
32 mClearExpressionAction =
new QAction( tr(
"Clear Filter Expression" ), mMenu );
33 connect( mClearExpressionAction, &QAction::triggered,
this, &QgsLegendFilterButton::onClearFilterExpression );
34 mClearExpressionAction->setEnabled(
false );
36 mMenu->addAction( mSetExpressionAction );
37 mMenu->addAction( mClearExpressionAction );
41 setPopupMode( QToolButton::MenuButtonPopup );
45 connect(
this, &QAbstractButton::toggled,
this, &QgsLegendFilterButton::onToggle );
48 void QgsLegendFilterButton::onToggle(
bool checked )
54 onSetLegendFilterExpression();
55 blockSignals(
false );
59 void QgsLegendFilterButton::onSetLegendFilterExpression()
66 bool emitSignal =
false;
69 emitSignal = isChecked();
74 emitSignal = !isChecked();
78 emit toggled( isChecked() );
82 void QgsLegendFilterButton::onClearFilterExpression()
84 mClearExpressionAction->setEnabled(
false );
90 void QgsLegendFilterButton::updateMenu()
92 if ( !mExpression.isEmpty() )
94 mClearExpressionAction->setEnabled(
true );
95 mSetExpressionAction->setText( QString( tr(
"Edit filter expression (current: %1)" ) ).arg( mExpression ) );
99 mClearExpressionAction->setEnabled(
false );
100 mSetExpressionAction->setText( tr(
"Edit filter expression" ) );
111 mExpression = expression;