17#include "moc_qgssearchwidgettoolbutton.cpp"
22 : QToolButton( parent )
28 setFocusPolicy( Qt::StrongFocus );
29 setPopupMode( QToolButton::InstantPopup );
31 mMenu =
new QMenu(
this );
32 connect( mMenu, &QMenu::aboutToShow,
this, &QgsSearchWidgetToolButton::aboutToShowMenu );
41 mFilterFlags &= flags;
42 mAvailableFilterFlags = flags;
43 mDefaultFilterFlags = mDefaultFilterFlags & flags;
49 mDefaultFilterFlags = flags & mAvailableFilterFlags;
61 if ( !( mAvailableFilterFlags & flag ) )
75 if ( !( mAvailableFilterFlags & flag ) )
85 mFilterFlags = newFlags;
92 if ( !( flag & mAvailableFilterFlags ) )
97 if ( flag & mFilterFlags )
98 mFilterFlags &= ~flag;
100 mFilterFlags |= flag;
108 mFilterFlags &= ~exclusiveFlag;
111 mFilterFlags |= flag;
122 if ( mFilterFlags & flag )
128void QgsSearchWidgetToolButton::aboutToShowMenu()
131 bool fieldActive =
false;
135 if ( !( mAvailableFilterFlags & flag ) )
142 connect( action, &QAction::triggered,
this, &QgsSearchWidgetToolButton::actionSelected );
143 action->setData( flag );
144 action->setCheckable(
true );
145 if ( mFilterFlags & flag )
148 action->setChecked(
true );
152 QAction *clearAction = mMenu->addAction( tr(
"Exclude Field" ) );
154 clearAction->setCheckable(
true );
155 clearAction->setChecked( !fieldActive );
156 if ( mMenu->actions().count() > 0 )
158 mMenu->insertAction( mMenu->actions().at( 0 ), clearAction );
159 mMenu->insertSeparator( mMenu->actions().at( 1 ) );
162 mMenu->addAction( clearAction );
164 mMenu->addSeparator();
169 if ( !( mAvailableFilterFlags & flag ) )
176 connect( action, &QAction::triggered,
this, &QgsSearchWidgetToolButton::actionSelected );
177 action->setData( flag );
178 action->setCheckable(
true );
179 if ( mFilterFlags & flag )
180 action->setChecked(
true );
184void QgsSearchWidgetToolButton::actionSelected()
190void QgsSearchWidgetToolButton::searchWidgetValueChanged()
204 if ( !( mAvailableFilterFlags & flag ) || !( mFilterFlags & flag ) )
208 mFilterFlags = newFlags;
220 if ( mDefaultFilterFlags & flag )
228void QgsSearchWidgetToolButton::updateState()
231 QStringList toolTips;
235 if ( mFilterFlags & flag )
244 if ( mFilterFlags & flag )
252 const QString text = toolTips.join( QLatin1String(
", " ) );
258 setText( tr(
"Exclude Field" ) );
259 setToolTip( QString() );