Skip to content

Commit 02c0174

Browse files
committed
Add a "Between" type search/filter in filter form mode
When Between searches are selected, two search widget wrappers will be created to allow entry of the minimum/maximum allowed values.
1 parent 026e352 commit 02c0174

10 files changed

+211
-82
lines changed

python/gui/editorwidgets/qgssearchwidgettoolbutton.sip

+15-8
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ class QgsSearchWidgetToolButton : QToolButton
1717
*/
1818
explicit QgsSearchWidgetToolButton( QWidget *parent /TransferThis/ = nullptr );
1919

20-
/** Sets the search widget wrapper associated with this button.
21-
* Calling this will automatically set the available flags to match those
22-
* supported by the wrapper and reset the active flags to match the wrapper's
23-
* default flags.
24-
* @param wrapper search wrapper. Ownership is not transferred.
25-
*/
26-
void setSearchWidgetWrapper( QgsSearchWidgetWrapper* wrapper );
27-
2820
/** Sets the available filter flags to show in the widget. Any active flags
2921
* (see activeFlags()) which are not present in the new available filter
3022
* flags will be cleared;
3123
* @param flags available flags to show in widget
3224
* @see availableFlags()
3325
* @see setActiveFlags()
26+
* @see setDefaultFlags()
3427
*/
3528
void setAvailableFlags( QgsSearchWidgetWrapper::FilterFlags flags );
3629

30+
/** Sets the default filter flags to show in the widget.
31+
* @param flags default flags to show in widget
32+
* @see setAvailableFlags()
33+
* @see setActiveFlags()
34+
*/
35+
void setDefaultFlags( QgsSearchWidgetWrapper::FilterFlags flags );
36+
3737
/** Returns the available filter flags shown in the widget.
3838
* @see setAvailableFlags()
3939
* @see activeFlags()
@@ -87,4 +87,11 @@ class QgsSearchWidgetToolButton : QToolButton
8787
*/
8888
void setActive();
8989

90+
signals:
91+
92+
/** Emitted when the active flags selected in the widget is changed
93+
* @param flags active flags
94+
*/
95+
void activeFlagsChanged( QgsSearchWidgetWrapper::FilterFlags flags );
96+
9097
};

python/gui/qgsattributeformeditorwidget.sip

+32-11
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,16 @@ class QgsAttributeFormEditorWidget : QWidget
3030
QgsAttributeForm* form /TransferThis/ );
3131
~QgsAttributeFormEditorWidget();
3232

33-
/** Sets the search widget wrapper for the widget used when the form is in
33+
/** Creates the search widget wrappers for the widget used when the form is in
3434
* search mode.
35-
* @param wrapper search widget wrapper.
36-
* @note the search widget wrapper should be created using searchWidgetFrame()
37-
* as its parent
38-
*/
39-
void setSearchWidgetWrapper( QgsSearchWidgetWrapper* wrapper );
40-
41-
/** Returns the widget which should be used as a parent during construction
42-
* of the search widget wrapper.
43-
* @see setSearchWidgetWrapper()
35+
* @param widgetId id of the widget type to create a search wrapper for
36+
* @param fieldIdx index of field associated with widget
37+
* @param config configuration which should be used for the widget creation
38+
* @param context editor context (not available in python bindings)
4439
*/
45-
QWidget* searchWidgetFrame();
40+
void createSearchWidgetWrappers( const QString& widgetId, int fieldIdx,
41+
const QgsEditorWidgetConfig& config,
42+
const QgsAttributeEditorContext &context = QgsAttributeEditorContext() );
4643

4744
/** Sets the current mode for the widget. The widget will adapt its state and visible widgets to
4845
* reflect the updated mode. Eg, showing multi edit tool buttons if the mode is set to MultiEditMode.
@@ -106,4 +103,28 @@ class QgsAttributeFormEditorWidget : QWidget
106103
*/
107104
QgsSearchWidgetToolButton* searchWidgetToolButton();
108105

106+
/** Sets the search widget wrapper for the widget used when the form is in
107+
* search mode.
108+
* @param wrapper search widget wrapper.
109+
* @note the search widget wrapper should be created using searchWidgetFrame()
110+
* as its parent
111+
* @note this method is in place for unit testing only, and is not considered
112+
* stable AP
113+
*/
114+
void setSearchWidgetWrapper( QgsSearchWidgetWrapper* wrapper );
115+
116+
/** Returns the widget which should be used as a parent during construction
117+
* of the search widget wrapper.
118+
* @note this method is in place for unit testing only, and is not considered
119+
* stable AP
120+
*/
121+
QWidget* searchWidgetFrame();
122+
123+
/** Returns the search widget wrapper used in this widget. The wrapper must
124+
* first be created using createSearchWidgetWrapper()
125+
* @note this method is in place for unit testing only, and is not considered
126+
* stable AP
127+
*/
128+
QList< QgsSearchWidgetWrapper* > searchWidgetWrappers();
129+
109130
};

src/gui/editorwidgets/qgsdatetimesearchwidgetwrapper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ QVariant QgsDateTimeSearchWidgetWrapper::value() const
5151

5252
QgsSearchWidgetWrapper::FilterFlags QgsDateTimeSearchWidgetWrapper::supportedFlags() const
5353
{
54-
return EqualTo | NotEqualTo | GreaterThan | LessThan | GreaterThanOrEqualTo | LessThanOrEqualTo | IsNull;
54+
return EqualTo | NotEqualTo | GreaterThan | LessThan | GreaterThanOrEqualTo | LessThanOrEqualTo | IsNull | Between;
5555
}
5656

5757
QgsSearchWidgetWrapper::FilterFlags QgsDateTimeSearchWidgetWrapper::defaultFlags() const

src/gui/editorwidgets/qgssearchwidgettoolbutton.cpp

+10-22
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
QgsSearchWidgetToolButton::QgsSearchWidgetToolButton( QWidget* parent )
2121
: QToolButton( parent )
2222
, mAvailableFilterFlags( QgsSearchWidgetWrapper::EqualTo | QgsSearchWidgetWrapper::NotEqualTo | QgsSearchWidgetWrapper::CaseInsensitive )
23+
, mDefaultFilterFlags( QgsSearchWidgetWrapper::EqualTo )
2324
, mFilterFlags( QgsSearchWidgetWrapper::EqualTo )
24-
, mSearchWrapper( nullptr )
2525
, mMenu( nullptr )
2626
{
2727
setFocusPolicy( Qt::StrongFocus );
@@ -35,22 +35,19 @@ QgsSearchWidgetToolButton::QgsSearchWidgetToolButton( QWidget* parent )
3535
updateState();
3636
}
3737

38-
void QgsSearchWidgetToolButton::setSearchWidgetWrapper( QgsSearchWidgetWrapper* wrapper )
39-
{
40-
mSearchWrapper = wrapper;
41-
setAvailableFlags( mSearchWrapper->supportedFlags() );
42-
setActiveFlags( QgsSearchWidgetWrapper::FilterFlags() );
43-
connect( mSearchWrapper, SIGNAL( valueChanged() ), this, SLOT( searchWidgetValueChanged() ) );
44-
connect( mSearchWrapper, SIGNAL( valueCleared() ), this, SLOT( setInactive() ) );
45-
}
46-
4738
void QgsSearchWidgetToolButton::setAvailableFlags( QgsSearchWidgetWrapper::FilterFlags flags )
4839
{
4940
mFilterFlags &= flags;
5041
mAvailableFilterFlags = flags;
42+
mDefaultFilterFlags = mDefaultFilterFlags & flags;
5143
updateState();
5244
}
5345

46+
void QgsSearchWidgetToolButton::setDefaultFlags( QgsSearchWidgetWrapper::FilterFlags flags )
47+
{
48+
mDefaultFilterFlags = flags & mAvailableFilterFlags;
49+
}
50+
5451
void QgsSearchWidgetToolButton::setActiveFlags( QgsSearchWidgetWrapper::FilterFlags flags )
5552
{
5653
// sanitize list
@@ -194,9 +191,6 @@ void QgsSearchWidgetToolButton::setInactive()
194191
if ( !isActive() )
195192
return;
196193

197-
if ( mSearchWrapper )
198-
mSearchWrapper->clearWidget();
199-
200194
QgsSearchWidgetWrapper::FilterFlags newFlags;
201195
Q_FOREACH ( QgsSearchWidgetWrapper::FilterFlag flag, QgsSearchWidgetWrapper::nonExclusiveFilterFlags() )
202196
{
@@ -215,12 +209,7 @@ void QgsSearchWidgetToolButton::setActive()
215209

216210
Q_FOREACH ( QgsSearchWidgetWrapper::FilterFlag flag, QgsSearchWidgetWrapper::exclusiveFilterFlags() )
217211
{
218-
if ( mSearchWrapper && mSearchWrapper->defaultFlags() & flag )
219-
{
220-
toggleFlag( flag );
221-
return;
222-
}
223-
else if ( !mSearchWrapper && mAvailableFilterFlags & flag )
212+
if ( mDefaultFilterFlags & flag )
224213
{
225214
toggleFlag( flag );
226215
return;
@@ -230,9 +219,6 @@ void QgsSearchWidgetToolButton::setActive()
230219

231220
void QgsSearchWidgetToolButton::updateState()
232221
{
233-
if ( mSearchWrapper )
234-
mSearchWrapper->setEnabled( !( mFilterFlags & QgsSearchWidgetWrapper::IsNull ) );
235-
236222
bool active = false;
237223
QStringList toolTips;
238224
Q_FOREACH ( QgsSearchWidgetWrapper::FilterFlag flag, QgsSearchWidgetWrapper::exclusiveFilterFlags() )
@@ -262,4 +248,6 @@ void QgsSearchWidgetToolButton::updateState()
262248
setText( tr( "Exclude field" ) );
263249
setToolTip( QString() );
264250
}
251+
252+
emit activeFlagsChanged( mFilterFlags );
265253
}

src/gui/editorwidgets/qgssearchwidgettoolbutton.h

+16-9
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@ class GUI_EXPORT QgsSearchWidgetToolButton : public QToolButton
3737
*/
3838
explicit QgsSearchWidgetToolButton( QWidget *parent = nullptr );
3939

40-
/** Sets the search widget wrapper associated with this button.
41-
* Calling this will automatically set the available flags to match those
42-
* supported by the wrapper and reset the active flags to match the wrapper's
43-
* default flags.
44-
* @param wrapper search wrapper. Ownership is not transferred.
45-
*/
46-
void setSearchWidgetWrapper( QgsSearchWidgetWrapper* wrapper );
47-
4840
/** Sets the available filter flags to show in the widget. Any active flags
4941
* (see activeFlags()) which are not present in the new available filter
5042
* flags will be cleared;
5143
* @param flags available flags to show in widget
5244
* @see availableFlags()
5345
* @see setActiveFlags()
46+
* @see setDefaultFlags()
5447
*/
5548
void setAvailableFlags( QgsSearchWidgetWrapper::FilterFlags flags );
5649

50+
/** Sets the default filter flags to show in the widget.
51+
* @param flags default flags to show in widget
52+
* @see setAvailableFlags()
53+
* @see setActiveFlags()
54+
*/
55+
void setDefaultFlags( QgsSearchWidgetWrapper::FilterFlags flags );
56+
5757
/** Returns the available filter flags shown in the widget.
5858
* @see setAvailableFlags()
5959
* @see activeFlags()
@@ -107,6 +107,13 @@ class GUI_EXPORT QgsSearchWidgetToolButton : public QToolButton
107107
*/
108108
void setActive();
109109

110+
signals:
111+
112+
/** Emitted when the active flags selected in the widget is changed
113+
* @param flags active flags
114+
*/
115+
void activeFlagsChanged( QgsSearchWidgetWrapper::FilterFlags flags );
116+
110117
private slots:
111118

112119
void aboutToShowMenu();
@@ -118,8 +125,8 @@ class GUI_EXPORT QgsSearchWidgetToolButton : public QToolButton
118125
private:
119126

120127
QgsSearchWidgetWrapper::FilterFlags mAvailableFilterFlags;
128+
QgsSearchWidgetWrapper::FilterFlags mDefaultFilterFlags;
121129
QgsSearchWidgetWrapper::FilterFlags mFilterFlags;
122-
QgsSearchWidgetWrapper* mSearchWrapper;
123130
QMenu* mMenu;
124131

125132
void updateState();

src/gui/qgsattributeform.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -903,9 +903,7 @@ void QgsAttributeForm::init()
903903
QgsAttributeFormEditorWidget* formWidget = new QgsAttributeFormEditorWidget( eww, this );
904904
w = formWidget;
905905
mFormEditorWidgets.insert( idx, formWidget );
906-
QgsSearchWidgetWrapper* sww = QgsEditorWidgetRegistry::instance()->createSearchWidget( widgetType, mLayer, idx, widgetConfig,
907-
formWidget->searchWidgetFrame(), mContext );
908-
formWidget->setSearchWidgetWrapper( sww );
906+
formWidget->createSearchWidgetWrappers( widgetType, idx, widgetConfig, mContext );
909907
}
910908
else
911909
{
@@ -1162,8 +1160,7 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
11621160
QgsAttributeFormEditorWidget* w = new QgsAttributeFormEditorWidget( eww, this );
11631161
mFormEditorWidgets.insert( fldIdx, w );
11641162

1165-
QgsSearchWidgetWrapper* sww = QgsEditorWidgetRegistry::instance()->createSearchWidget( widgetType, mLayer, fldIdx, widgetConfig, w->searchWidgetFrame(), mContext );
1166-
w->setSearchWidgetWrapper( sww );
1163+
w->createSearchWidgetWrappers( widgetType, fldIdx, widgetConfig, mContext );
11671164

11681165
newWidgetInfo.widget = w;
11691166
addWidgetWrapper( eww );

0 commit comments

Comments
 (0)