QgsSearchWidgetWrapper class

Shows a search widget on a filter form.

Base classes

class QgsWidgetWrapper
Manages an editor widget Widget and wrapper share the same parent.

Derived classes

class QgsCheckboxSearchWidgetWrapper
Wraps a checkbox edit widget for searching.
class QgsDateTimeSearchWidgetWrapper
Wraps a date/time edit widget for searching.
class QgsDefaultSearchWidgetWrapper
Wraps a search widget.
class QgsRelationAggregateSearchWidgetWrapper
Search widget for the children of a relation.
class QgsRelationReferenceSearchWidgetWrapper
Wraps a relation reference search widget.
class QgsValueMapSearchWidgetWrapper
Wraps a value map search widget.
class QgsValueRelationSearchWidgetWrapper
Wraps a value relation search widget.

Public types

enum FilterFlag { EqualTo = 1 << 1, NotEqualTo = 1 << 2, GreaterThan = 1 << 3, LessThan = 1 << 4, GreaterThanOrEqualTo = 1 << 5, LessThanOrEqualTo = 1 << 6, Between = 1 << 7, CaseInsensitive = 1 << 8, Contains = 1 << 9, DoesNotContain = 1 << 10, IsNull = 1 << 11, IsNotBetween = 1 << 12, IsNotNull = 1 << 13, StartsWith = 1 << 14, EndsWith = 1 << 15 }
Flags which indicate what types of filtering and searching is possible using the widget.

Public static functions

static auto exclusiveFilterFlags() -> QList<QgsSearchWidgetWrapper::FilterFlag>
Returns a list of exclusive filter flags, which cannot be combined with other flags (e.g., EqualTo/NotEqualTo)
static auto nonExclusiveFilterFlags() -> QList<QgsSearchWidgetWrapper::FilterFlag>
Returns a list of non-exclusive filter flags, which can be combined with other flags (e.g., CaseInsensitive)
static auto toString(QgsSearchWidgetWrapper::FilterFlag flag) -> QString
Returns a translated string representing a filter flag.

Constructors, destructors, conversion operators

QgsSearchWidgetWrapper(QgsVectorLayer* vl, int fieldIdx, QWidget* parent = nullptr) explicit
Create a new widget wrapper.

Public functions

auto aggregate() const -> QString
If in AggregateSearch mode, which aggregate should be used to construct the filter expression.
auto applyDirectly() -> bool pure virtual
If this is true, then this search widget should take effect directly when its expression changes.
auto createExpression(FilterFlags flags) const -> QString virtual
Creates a filter expression based on the current state of the search widget and the specified filter flags.
auto createFieldIdentifier() const -> QString
Gets a field name or expression to use as field comparison.
auto defaultFlags() const -> FilterFlags virtual
Returns the filter flags which should be set by default for the search widget.
auto expression() const -> QString pure virtual
Will be used to access the widget's value.
void setAggregate(const QString& aggregate)
If in AggregateSearch mode, which aggregate should be used to construct the filter expression.
auto supportedFlags() const -> FilterFlags virtual
Returns filter flags supported by the search widget.

Signals

void expressionChanged(const QString& exp)
Emitted whenever the expression changes.
void valueChanged()
Emitted when a user changes the value of the search widget.
void valueCleared()
Emitted when a user changes the value of the search widget back to an empty, default state.

Public slots

void clearWidget() virtual
Clears the widget's current value and resets it back to the default state.
void setEnabled(bool enabled) override
Toggles whether the search widget is enabled or disabled.

Protected functions

void clearExpression()
clears the expression to search for all features

Protected slots

void setExpression(const QString& expression) pure virtual
Set the expression which is currently used as filter for this widget.

Enum documentation

enum QgsSearchWidgetWrapper::FilterFlag

Flags which indicate what types of filtering and searching is possible using the widget.

Enumerators
EqualTo

Supports equal to.

NotEqualTo

Supports not equal to.

GreaterThan

Supports greater than.

LessThan

Supports less than.

GreaterThanOrEqualTo

Supports >=.

LessThanOrEqualTo

Supports <=.

Between

Supports searches between two values.

CaseInsensitive

Supports case insensitive searching.

Contains

Supports value "contains" searching.

DoesNotContain

Supports value does not contain searching.

IsNull

Supports searching for null values.

IsNotBetween

Supports searching for values outside of a set range.

IsNotNull

Supports searching for non-null values.

StartsWith

Supports searching for strings that start with.

EndsWith

Supports searching for strings that end with.

Function documentation

static QList<QgsSearchWidgetWrapper::FilterFlag> QgsSearchWidgetWrapper::exclusiveFilterFlags()

Returns a list of exclusive filter flags, which cannot be combined with other flags (e.g., EqualTo/NotEqualTo)

static QList<QgsSearchWidgetWrapper::FilterFlag> QgsSearchWidgetWrapper::nonExclusiveFilterFlags()

Returns a list of non-exclusive filter flags, which can be combined with other flags (e.g., CaseInsensitive)

static QString QgsSearchWidgetWrapper::toString(QgsSearchWidgetWrapper::FilterFlag flag)

Returns a translated string representing a filter flag.

Parameters
flag flag to convert to string

QgsSearchWidgetWrapper::QgsSearchWidgetWrapper(QgsVectorLayer* vl, int fieldIdx, QWidget* parent = nullptr) explicit

Create a new widget wrapper.

Parameters
vl The layer on which the field is
fieldIdx The field which will be controlled
parent A parent widget for this widget wrapper and the created widget.

QString QgsSearchWidgetWrapper::aggregate() const

If in AggregateSearch mode, which aggregate should be used to construct the filter expression.

Is a Null String if none.

QString QgsSearchWidgetWrapper::createExpression(FilterFlags flags) const virtual

Creates a filter expression based on the current state of the search widget and the specified filter flags.

Parameters
flags filter flags
Returns filter expression

QString QgsSearchWidgetWrapper::createFieldIdentifier() const

Gets a field name or expression to use as field comparison.

If in SearchMode returns a quoted field identifier. If in AggregateSearchMode returns an appropriate aggregate expression.

FilterFlags QgsSearchWidgetWrapper::defaultFlags() const virtual

Returns the filter flags which should be set by default for the search widget.

QString QgsSearchWidgetWrapper::expression() const pure virtual

Will be used to access the widget's value.

Returns The current value the widget represents

Read the value from the widget and return it properly formatted to be saved in the attribute.

If an invalid variant is returned this will be interpreted as no change. Be sure to return a NULL QVariant if it should be set to NULL.

void QgsSearchWidgetWrapper::setAggregate(const QString& aggregate)

If in AggregateSearch mode, which aggregate should be used to construct the filter expression.

Is a Null String if none.

FilterFlags QgsSearchWidgetWrapper::supportedFlags() const virtual

Returns filter flags supported by the search widget.

void QgsSearchWidgetWrapper::expressionChanged(const QString& exp) signal

Emitted whenever the expression changes.

Parameters
exp The new search expression

void QgsSearchWidgetWrapper::valueChanged() signal

Emitted when a user changes the value of the search widget.

void QgsSearchWidgetWrapper::valueCleared() signal

Emitted when a user changes the value of the search widget back to an empty, default state.

void QgsSearchWidgetWrapper::clearWidget() virtual public slot

Clears the widget's current value and resets it back to the default state.

void QgsSearchWidgetWrapper::setEnabled(bool enabled) override public slot

Toggles whether the search widget is enabled or disabled.

Parameters
enabled set to true to enable widget