Skip to content
Permalink
Browse files

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.
  • Loading branch information
nyalldawson committed May 23, 2016
1 parent 026e352 commit 02c0174d41e7703f496a926a066f05ad824a409d
@@ -17,23 +17,23 @@ class QgsSearchWidgetToolButton : QToolButton
*/
explicit QgsSearchWidgetToolButton( QWidget *parent /TransferThis/ = nullptr );

/** Sets the search widget wrapper associated with this button.
* Calling this will automatically set the available flags to match those
* supported by the wrapper and reset the active flags to match the wrapper's
* default flags.
* @param wrapper search wrapper. Ownership is not transferred.
*/
void setSearchWidgetWrapper( QgsSearchWidgetWrapper* wrapper );

/** Sets the available filter flags to show in the widget. Any active flags
* (see activeFlags()) which are not present in the new available filter
* flags will be cleared;
* @param flags available flags to show in widget
* @see availableFlags()
* @see setActiveFlags()
* @see setDefaultFlags()
*/
void setAvailableFlags( QgsSearchWidgetWrapper::FilterFlags flags );

/** Sets the default filter flags to show in the widget.
* @param flags default flags to show in widget
* @see setAvailableFlags()
* @see setActiveFlags()
*/
void setDefaultFlags( QgsSearchWidgetWrapper::FilterFlags flags );

/** Returns the available filter flags shown in the widget.
* @see setAvailableFlags()
* @see activeFlags()
@@ -87,4 +87,11 @@ class QgsSearchWidgetToolButton : QToolButton
*/
void setActive();

signals:

/** Emitted when the active flags selected in the widget is changed
* @param flags active flags
*/
void activeFlagsChanged( QgsSearchWidgetWrapper::FilterFlags flags );

};
@@ -30,19 +30,16 @@ class QgsAttributeFormEditorWidget : QWidget
QgsAttributeForm* form /TransferThis/ );
~QgsAttributeFormEditorWidget();

/** Sets the search widget wrapper for the widget used when the form is in
/** Creates the search widget wrappers for the widget used when the form is in
* search mode.
* @param wrapper search widget wrapper.
* @note the search widget wrapper should be created using searchWidgetFrame()
* as its parent
*/
void setSearchWidgetWrapper( QgsSearchWidgetWrapper* wrapper );

/** Returns the widget which should be used as a parent during construction
* of the search widget wrapper.
* @see setSearchWidgetWrapper()
* @param widgetId id of the widget type to create a search wrapper for
* @param fieldIdx index of field associated with widget
* @param config configuration which should be used for the widget creation
* @param context editor context (not available in python bindings)
*/
QWidget* searchWidgetFrame();
void createSearchWidgetWrappers( const QString& widgetId, int fieldIdx,
const QgsEditorWidgetConfig& config,
const QgsAttributeEditorContext &context = QgsAttributeEditorContext() );

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

/** Sets the search widget wrapper for the widget used when the form is in
* search mode.
* @param wrapper search widget wrapper.
* @note the search widget wrapper should be created using searchWidgetFrame()
* as its parent
* @note this method is in place for unit testing only, and is not considered
* stable AP
*/
void setSearchWidgetWrapper( QgsSearchWidgetWrapper* wrapper );

/** Returns the widget which should be used as a parent during construction
* of the search widget wrapper.
* @note this method is in place for unit testing only, and is not considered
* stable AP
*/
QWidget* searchWidgetFrame();

/** Returns the search widget wrapper used in this widget. The wrapper must
* first be created using createSearchWidgetWrapper()
* @note this method is in place for unit testing only, and is not considered
* stable AP
*/
QList< QgsSearchWidgetWrapper* > searchWidgetWrappers();

};
@@ -51,7 +51,7 @@ QVariant QgsDateTimeSearchWidgetWrapper::value() const

QgsSearchWidgetWrapper::FilterFlags QgsDateTimeSearchWidgetWrapper::supportedFlags() const
{
return EqualTo | NotEqualTo | GreaterThan | LessThan | GreaterThanOrEqualTo | LessThanOrEqualTo | IsNull;
return EqualTo | NotEqualTo | GreaterThan | LessThan | GreaterThanOrEqualTo | LessThanOrEqualTo | IsNull | Between;
}

QgsSearchWidgetWrapper::FilterFlags QgsDateTimeSearchWidgetWrapper::defaultFlags() const
@@ -20,8 +20,8 @@
QgsSearchWidgetToolButton::QgsSearchWidgetToolButton( QWidget* parent )
: QToolButton( parent )
, mAvailableFilterFlags( QgsSearchWidgetWrapper::EqualTo | QgsSearchWidgetWrapper::NotEqualTo | QgsSearchWidgetWrapper::CaseInsensitive )
, mDefaultFilterFlags( QgsSearchWidgetWrapper::EqualTo )
, mFilterFlags( QgsSearchWidgetWrapper::EqualTo )
, mSearchWrapper( nullptr )
, mMenu( nullptr )
{
setFocusPolicy( Qt::StrongFocus );
@@ -35,22 +35,19 @@ QgsSearchWidgetToolButton::QgsSearchWidgetToolButton( QWidget* parent )
updateState();
}

void QgsSearchWidgetToolButton::setSearchWidgetWrapper( QgsSearchWidgetWrapper* wrapper )
{
mSearchWrapper = wrapper;
setAvailableFlags( mSearchWrapper->supportedFlags() );
setActiveFlags( QgsSearchWidgetWrapper::FilterFlags() );
connect( mSearchWrapper, SIGNAL( valueChanged() ), this, SLOT( searchWidgetValueChanged() ) );
connect( mSearchWrapper, SIGNAL( valueCleared() ), this, SLOT( setInactive() ) );
}

void QgsSearchWidgetToolButton::setAvailableFlags( QgsSearchWidgetWrapper::FilterFlags flags )
{
mFilterFlags &= flags;
mAvailableFilterFlags = flags;
mDefaultFilterFlags = mDefaultFilterFlags & flags;
updateState();
}

void QgsSearchWidgetToolButton::setDefaultFlags( QgsSearchWidgetWrapper::FilterFlags flags )
{
mDefaultFilterFlags = flags & mAvailableFilterFlags;
}

void QgsSearchWidgetToolButton::setActiveFlags( QgsSearchWidgetWrapper::FilterFlags flags )
{
// sanitize list
@@ -194,9 +191,6 @@ void QgsSearchWidgetToolButton::setInactive()
if ( !isActive() )
return;

if ( mSearchWrapper )
mSearchWrapper->clearWidget();

QgsSearchWidgetWrapper::FilterFlags newFlags;
Q_FOREACH ( QgsSearchWidgetWrapper::FilterFlag flag, QgsSearchWidgetWrapper::nonExclusiveFilterFlags() )
{
@@ -215,12 +209,7 @@ void QgsSearchWidgetToolButton::setActive()

Q_FOREACH ( QgsSearchWidgetWrapper::FilterFlag flag, QgsSearchWidgetWrapper::exclusiveFilterFlags() )
{
if ( mSearchWrapper && mSearchWrapper->defaultFlags() & flag )
{
toggleFlag( flag );
return;
}
else if ( !mSearchWrapper && mAvailableFilterFlags & flag )
if ( mDefaultFilterFlags & flag )
{
toggleFlag( flag );
return;
@@ -230,9 +219,6 @@ void QgsSearchWidgetToolButton::setActive()

void QgsSearchWidgetToolButton::updateState()
{
if ( mSearchWrapper )
mSearchWrapper->setEnabled( !( mFilterFlags & QgsSearchWidgetWrapper::IsNull ) );

bool active = false;
QStringList toolTips;
Q_FOREACH ( QgsSearchWidgetWrapper::FilterFlag flag, QgsSearchWidgetWrapper::exclusiveFilterFlags() )
@@ -262,4 +248,6 @@ void QgsSearchWidgetToolButton::updateState()
setText( tr( "Exclude field" ) );
setToolTip( QString() );
}

emit activeFlagsChanged( mFilterFlags );
}
@@ -37,23 +37,23 @@ class GUI_EXPORT QgsSearchWidgetToolButton : public QToolButton
*/
explicit QgsSearchWidgetToolButton( QWidget *parent = nullptr );

/** Sets the search widget wrapper associated with this button.
* Calling this will automatically set the available flags to match those
* supported by the wrapper and reset the active flags to match the wrapper's
* default flags.
* @param wrapper search wrapper. Ownership is not transferred.
*/
void setSearchWidgetWrapper( QgsSearchWidgetWrapper* wrapper );

/** Sets the available filter flags to show in the widget. Any active flags
* (see activeFlags()) which are not present in the new available filter
* flags will be cleared;
* @param flags available flags to show in widget
* @see availableFlags()
* @see setActiveFlags()
* @see setDefaultFlags()
*/
void setAvailableFlags( QgsSearchWidgetWrapper::FilterFlags flags );

/** Sets the default filter flags to show in the widget.
* @param flags default flags to show in widget
* @see setAvailableFlags()
* @see setActiveFlags()
*/
void setDefaultFlags( QgsSearchWidgetWrapper::FilterFlags flags );

/** Returns the available filter flags shown in the widget.
* @see setAvailableFlags()
* @see activeFlags()
@@ -107,6 +107,13 @@ class GUI_EXPORT QgsSearchWidgetToolButton : public QToolButton
*/
void setActive();

signals:

/** Emitted when the active flags selected in the widget is changed
* @param flags active flags
*/
void activeFlagsChanged( QgsSearchWidgetWrapper::FilterFlags flags );

private slots:

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

QgsSearchWidgetWrapper::FilterFlags mAvailableFilterFlags;
QgsSearchWidgetWrapper::FilterFlags mDefaultFilterFlags;
QgsSearchWidgetWrapper::FilterFlags mFilterFlags;
QgsSearchWidgetWrapper* mSearchWrapper;
QMenu* mMenu;

void updateState();
@@ -903,9 +903,7 @@ void QgsAttributeForm::init()
QgsAttributeFormEditorWidget* formWidget = new QgsAttributeFormEditorWidget( eww, this );
w = formWidget;
mFormEditorWidgets.insert( idx, formWidget );
QgsSearchWidgetWrapper* sww = QgsEditorWidgetRegistry::instance()->createSearchWidget( widgetType, mLayer, idx, widgetConfig,
formWidget->searchWidgetFrame(), mContext );
formWidget->setSearchWidgetWrapper( sww );
formWidget->createSearchWidgetWrappers( widgetType, idx, widgetConfig, mContext );
}
else
{
@@ -1162,8 +1160,7 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
QgsAttributeFormEditorWidget* w = new QgsAttributeFormEditorWidget( eww, this );
mFormEditorWidgets.insert( fldIdx, w );

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

newWidgetInfo.widget = w;
addWidgetWrapper( eww );

0 comments on commit 02c0174

Please sign in to comment.
You can’t perform that action at this time.