Skip to content

Commit 02c0174

Browse files
committedMay 23, 2016
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

Lines changed: 15 additions & 8 deletions
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

Lines changed: 32 additions & 11 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 22 deletions
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

Lines changed: 16 additions & 9 deletions
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

Lines changed: 2 additions & 5 deletions
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 );

‎src/gui/qgsattributeformeditorwidget.cpp

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#include "qgssearchwidgettoolbutton.h"
2020
#include "qgseditorwidgetwrapper.h"
2121
#include "qgssearchwidgetwrapper.h"
22+
#include "qgseditorwidgetconfig.h"
23+
#include "qgsattributeeditorcontext.h"
24+
#include "qgseditorwidgetregistry.h"
2225
#include <QLayout>
2326
#include <QLabel>
2427
#include <QStackedWidget>
@@ -27,7 +30,6 @@ QgsAttributeFormEditorWidget::QgsAttributeFormEditorWidget( QgsEditorWidgetWrapp
2730
QgsAttributeForm* form )
2831
: QWidget( form )
2932
, mWidget( editorWidget )
30-
, mSearchWidget( nullptr )
3133
, mForm( form )
3234
, mMode( DefaultMode )
3335
, mMultiEditButton( new QgsMultiEditToolButton() )
@@ -54,6 +56,8 @@ QgsAttributeFormEditorWidget::QgsAttributeFormEditorWidget( QgsEditorWidgetWrapp
5456
mSearchPage->setLayout( l );
5557
l->addWidget( mSearchFrame, 1 );
5658
mSearchWidgetToolButton = new QgsSearchWidgetToolButton();
59+
connect( mSearchWidgetToolButton, SIGNAL( activeFlagsChanged( QgsSearchWidgetWrapper::FilterFlags ) ),
60+
this, SLOT( searchWidgetFlagsChanged( QgsSearchWidgetWrapper::FilterFlags ) ) );
5761
l->addWidget( mSearchWidgetToolButton, 0 );
5862

5963

@@ -91,11 +95,42 @@ QgsAttributeFormEditorWidget::~QgsAttributeFormEditorWidget()
9195
delete mMultiEditButton;
9296
}
9397

98+
void QgsAttributeFormEditorWidget::createSearchWidgetWrappers( const QString& widgetId, int fieldIdx, const QgsEditorWidgetConfig& config, const QgsAttributeEditorContext& context )
99+
{
100+
QgsSearchWidgetWrapper* sww = QgsEditorWidgetRegistry::instance()->createSearchWidget( widgetId, layer(), fieldIdx, config,
101+
mSearchFrame, context );
102+
setSearchWidgetWrapper( sww );
103+
if ( sww->supportedFlags() & QgsSearchWidgetWrapper::Between )
104+
{
105+
// create secondary widget for between type searches
106+
QgsSearchWidgetWrapper* sww2 = QgsEditorWidgetRegistry::instance()->createSearchWidget( widgetId, layer(), fieldIdx, config,
107+
mSearchFrame, context );
108+
mSearchWidgets << sww2;
109+
mSearchFrame->layout()->addWidget( sww2->widget() );
110+
sww2->widget()->hide();
111+
}
112+
}
113+
94114
void QgsAttributeFormEditorWidget::setSearchWidgetWrapper( QgsSearchWidgetWrapper* wrapper )
95115
{
96-
mSearchWidget = wrapper;
116+
mSearchWidgets.clear();
117+
mSearchWidgets << wrapper;
97118
mSearchFrame->layout()->addWidget( wrapper->widget() );
98-
mSearchWidgetToolButton->setSearchWidgetWrapper( wrapper );
119+
mSearchWidgetToolButton->setAvailableFlags( wrapper->supportedFlags() );
120+
mSearchWidgetToolButton->setActiveFlags( QgsSearchWidgetWrapper::FilterFlags() );
121+
mSearchWidgetToolButton->setDefaultFlags( wrapper->defaultFlags() );
122+
connect( wrapper, SIGNAL( valueChanged() ), mSearchWidgetToolButton, SLOT( searchWidgetValueChanged() ) );
123+
connect( wrapper, SIGNAL( valueCleared() ), mSearchWidgetToolButton, SLOT( setInactive() ) );
124+
}
125+
126+
QWidget*QgsAttributeFormEditorWidget::searchWidgetFrame()
127+
{
128+
return mSearchFrame;
129+
}
130+
131+
QList< QgsSearchWidgetWrapper* > QgsAttributeFormEditorWidget::searchWidgetWrappers()
132+
{
133+
return mSearchWidgets;
99134
}
100135

101136
void QgsAttributeFormEditorWidget::setMode( QgsAttributeFormEditorWidget::Mode mode )
@@ -125,8 +160,10 @@ void QgsAttributeFormEditorWidget::changesCommitted()
125160
void QgsAttributeFormEditorWidget::resetSearch()
126161
{
127162
mSearchWidgetToolButton->setInactive();
128-
if ( mSearchWidget )
129-
mSearchWidget->clearWidget();
163+
Q_FOREACH ( QgsSearchWidgetWrapper* widget, mSearchWidgets )
164+
{
165+
widget->clearWidget();
166+
}
130167
}
131168

132169
void QgsAttributeFormEditorWidget::initialize( const QVariant& initialValue, bool mixedValues )
@@ -150,15 +187,21 @@ QVariant QgsAttributeFormEditorWidget::currentValue() const
150187

151188
QString QgsAttributeFormEditorWidget::currentFilterExpression() const
152189
{
190+
if ( mSearchWidgets.isEmpty() )
191+
return QString();
192+
153193
if ( !mSearchWidgetToolButton->isActive() )
154194
return QString();
155195

156-
return mSearchWidget->createExpression( mSearchWidgetToolButton->activeFlags() );
157-
}
196+
if ( mSearchWidgetToolButton->activeFlags() & QgsSearchWidgetWrapper::Between )
197+
{
198+
// special case: Between search
199+
QString filter1 = mSearchWidgets.at( 0 )->createExpression( QgsSearchWidgetWrapper::GreaterThanOrEqualTo );
200+
QString filter2 = mSearchWidgets.at( 1 )->createExpression( QgsSearchWidgetWrapper::LessThanOrEqualTo );
201+
return QString( "%1 AND %2" ).arg( filter1, filter2 );
202+
}
158203

159-
QWidget* QgsAttributeFormEditorWidget::searchWidgetFrame()
160-
{
161-
return mSearchFrame;
204+
return mSearchWidgets.at( 0 )->createExpression( mSearchWidgetToolButton->activeFlags() );
162205
}
163206

164207
void QgsAttributeFormEditorWidget::editorWidgetChanged( const QVariant& value )
@@ -208,6 +251,23 @@ void QgsAttributeFormEditorWidget::setFieldTriggered()
208251
mIsChanged = true;
209252
}
210253

254+
void QgsAttributeFormEditorWidget::searchWidgetFlagsChanged( QgsSearchWidgetWrapper::FilterFlags flags )
255+
{
256+
Q_FOREACH ( QgsSearchWidgetWrapper* widget, mSearchWidgets )
257+
{
258+
widget->setEnabled( !( flags & QgsSearchWidgetWrapper::IsNull ) );
259+
if ( !mSearchWidgetToolButton->isActive() )
260+
{
261+
widget->clearWidget();
262+
}
263+
}
264+
265+
if ( mSearchWidgets.count() >= 2 )
266+
{
267+
mSearchWidgets.at( 1 )->widget()->setVisible( flags & QgsSearchWidgetWrapper::Between );
268+
}
269+
}
270+
211271
QgsSearchWidgetToolButton* QgsAttributeFormEditorWidget::searchWidgetToolButton()
212272
{
213273
return mSearchWidgetToolButton;

‎src/gui/qgsattributeformeditorwidget.h

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818

1919
#include <QWidget>
2020
#include <QVariant>
21+
#include "qgseditorwidgetconfig.h"
22+
#include "qgsattributeeditorcontext.h"
23+
#include "qgssearchwidgetwrapper.h"
2124

2225
class QgsAttributeForm;
2326
class QgsEditorWidgetWrapper;
2427
class QgsMultiEditToolButton;
2528
class QgsSearchWidgetToolButton;
2629
class QgsVectorLayer;
27-
class QgsSearchWidgetWrapper;
2830
class QStackedWidget;
31+
class QgsAttributeEditorContext;
2932

3033
/** \ingroup gui
3134
* \class QgsAttributeFormEditorWidget
@@ -58,19 +61,16 @@ class GUI_EXPORT QgsAttributeFormEditorWidget : public QWidget
5861

5962
~QgsAttributeFormEditorWidget();
6063

61-
/** Sets the search widget wrapper for the widget used when the form is in
64+
/** Creates the search widget wrappers for the widget used when the form is in
6265
* search mode.
63-
* @param wrapper search widget wrapper.
64-
* @note the search widget wrapper should be created using searchWidgetFrame()
65-
* as its parent
66+
* @param widgetId id of the widget type to create a search wrapper for
67+
* @param fieldIdx index of field associated with widget
68+
* @param config configuration which should be used for the widget creation
69+
* @param context editor context (not available in python bindings)
6670
*/
67-
void setSearchWidgetWrapper( QgsSearchWidgetWrapper* wrapper );
68-
69-
/** Returns the widget which should be used as a parent during construction
70-
* of the search widget wrapper.
71-
* @see setSearchWidgetWrapper()
72-
*/
73-
QWidget* searchWidgetFrame();
71+
void createSearchWidgetWrappers( const QString& widgetId, int fieldIdx,
72+
const QgsEditorWidgetConfig& config,
73+
const QgsAttributeEditorContext &context = QgsAttributeEditorContext() );
7474

7575
/** Sets the current mode for the widget. The widget will adapt its state and visible widgets to
7676
* reflect the updated mode. Eg, showing multi edit tool buttons if the mode is set to MultiEditMode.
@@ -137,6 +137,9 @@ class GUI_EXPORT QgsAttributeFormEditorWidget : public QWidget
137137
//! Triggered when the multi edit tool button "set field value" action is selected
138138
void setFieldTriggered();
139139

140+
//! Triggered when search button flags are changed
141+
void searchWidgetFlagsChanged( QgsSearchWidgetWrapper::FilterFlags flags );
142+
140143
protected:
141144

142145
/** Returns a pointer to the search widget tool button in the widget.
@@ -145,6 +148,30 @@ class GUI_EXPORT QgsAttributeFormEditorWidget : public QWidget
145148
*/
146149
QgsSearchWidgetToolButton* searchWidgetToolButton();
147150

151+
/** Sets the search widget wrapper for the widget used when the form is in
152+
* search mode.
153+
* @param wrapper search widget wrapper.
154+
* @note the search widget wrapper should be created using searchWidgetFrame()
155+
* as its parent
156+
* @note this method is in place for unit testing only, and is not considered
157+
* stable AP
158+
*/
159+
void setSearchWidgetWrapper( QgsSearchWidgetWrapper* wrapper );
160+
161+
/** Returns the widget which should be used as a parent during construction
162+
* of the search widget wrapper.
163+
* @note this method is in place for unit testing only, and is not considered
164+
* stable AP
165+
*/
166+
QWidget* searchWidgetFrame();
167+
168+
/** Returns the search widget wrapper used in this widget. The wrapper must
169+
* first be created using createSearchWidgetWrapper()
170+
* @note this method is in place for unit testing only, and is not considered
171+
* stable AP
172+
*/
173+
QList< QgsSearchWidgetWrapper* > searchWidgetWrappers();
174+
148175
private:
149176

150177
QWidget* mEditPage;
@@ -153,7 +180,7 @@ class GUI_EXPORT QgsAttributeFormEditorWidget : public QWidget
153180
QWidget* mSearchFrame;
154181

155182
QgsEditorWidgetWrapper* mWidget;
156-
QgsSearchWidgetWrapper* mSearchWidget;
183+
QList< QgsSearchWidgetWrapper* > mSearchWidgets;
157184
QgsAttributeForm* mForm;
158185
Mode mMode;
159186

‎tests/src/python/test_qgsattributeformeditorwidget.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@
1717
from qgis.gui import (QgsSearchWidgetWrapper,
1818
QgsAttributeFormEditorWidget,
1919
QgsSearchWidgetToolButton,
20-
QgsDefaultSearchWidgetWrapper)
20+
QgsDefaultSearchWidgetWrapper,
21+
QgsAttributeForm,
22+
QgsEditorWidgetRegistry
23+
)
2124
from qgis.core import (QgsVectorLayer)
22-
from qgis.PyQt.QtWidgets import QWidget
25+
from qgis.PyQt.QtWidgets import QWidget, QDateTimeEdit
26+
from qgis.PyQt.QtCore import QDateTime, QDate, QTime
2327
from qgis.testing import start_app, unittest
2428

2529
start_app()
30+
QgsEditorWidgetRegistry.instance().initEditors()
2631

2732

2833
class PyQgsAttributeFormEditorWidget(unittest.TestCase):
@@ -70,5 +75,21 @@ def testSetActive(self):
7075
# check that correct default flag was taken from search widget wrapper
7176
self.assertTrue(sb.activeFlags() & QgsSearchWidgetWrapper.EqualTo)
7277

78+
def testBetweenFilter(self):
79+
""" Test creating a between type filter """
80+
layer = QgsVectorLayer("Point?field=fldtext:string&field=fldint:integer", "test", "memory")
81+
form = QgsAttributeForm(layer)
82+
af = QgsAttributeFormEditorWidget(None, form)
83+
af.createSearchWidgetWrappers("DateTime", 0, {})
84+
85+
d1 = af.findChildren(QDateTimeEdit)[0]
86+
d2 = af.findChildren(QDateTimeEdit)[1]
87+
d1.setDateTime(QDateTime(QDate(2013, 5, 6), QTime()))
88+
d2.setDateTime(QDateTime(QDate(2013, 5, 16), QTime()))
89+
90+
af.searchWidgetToolButton().setActiveFlags(QgsSearchWidgetWrapper.Between)
91+
self.assertEquals(af.currentFilterExpression(), '"fldtext">=\'2013-05-06\' AND "fldtext"<=\'2013-05-16\'')
92+
93+
7394
if __name__ == '__main__':
7495
unittest.main()

‎tests/src/python/test_qgssearchwidgettoolbutton.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@ def testSetInactive(self):
146146
self.assertFalse(w.isActive())
147147

148148
def testSetActive(self):
149-
""" Test setting the search as active """
149+
""" Test setting the search as active should adopt default flags"""
150150
w = QgsSearchWidgetToolButton()
151151
w.setAvailableFlags(QgsSearchWidgetWrapper.Between |
152152
QgsSearchWidgetWrapper.NotEqualTo |
153153
QgsSearchWidgetWrapper.CaseInsensitive)
154154
w.setActiveFlags(QgsSearchWidgetWrapper.CaseInsensitive)
155+
w.setDefaultFlags(QgsSearchWidgetWrapper.NotEqualTo)
155156
self.assertFalse(w.isActive())
156157
w.setActive()
157158
flags = w.activeFlags()

0 commit comments

Comments
 (0)
Please sign in to comment.