QgsFilterLineEdit class
QLineEdit subclass with built in support for clearing the widget's value and handling custom null value representations.
Contents
When using QgsFilterLineEdit the value(), setValue() and clearValue() methods should be used instead of QLineEdit's text(), setText() and clear() methods, and the valueChanged() signal should be used instead of textChanged().
Derived classes
- class QgsFieldValuesLineEdit
- A line edit with an autocompleter which takes unique values from a vector layer's fields.
Public types
- enum ClearMode { ClearToNull = 0, ClearToDefault }
- Behavior when clearing value of widget.
Constructors, destructors, conversion operators
- QgsFilterLineEdit(QWidget* parent = nullptr, const QString& nullValue = QString())
- Constructor for QgsFilterLineEdit.
Public functions
- auto clearMode() const -> ClearMode
- Returns the clear mode for the widget.
- auto defaultValue() const -> QString
- Returns the default value for the widget.
- auto event(QEvent* event) -> bool override
- Reimplemented to enable/disable the clear action depending on read-only status.
- auto isNull() const -> bool
- Determine if the current text represents null.
- auto nullValue() const -> QString
- Returns the string used for representating null values in the widget.
- auto selectOnFocus() const -> bool
- Will select all text when this widget receives the focus.
- void setClearMode(ClearMode mode)
- Sets the clear mode for the widget.
- void setDefaultValue(const QString& defaultValue)
- Sets the default value for the widget.
- void setNullValue(const QString& nullValue)
- Sets the string representation for null values in the widget.
- void setSelectOnFocus(bool selectOnFocus)
- Will select all text when this widget receives the focus.
- void setShowClearButton(bool visible)
- Sets whether the widget's clear button is visible.
- void setShowSearchIcon(bool visible)
- Define if a search icon shall be shown on the left of the image when no text is entered.
- void setShowSpinner(bool showSpinner)
- Show a spinner icon.
- void setValue(const QString& value)
- Sets the current text for the widget with support for handling null values.
- auto showClearButton() const -> bool
- Returns true if the widget's clear button is visible.
- auto showSearchIcon() const -> bool
- Returns if a search icon shall be shown on the left of the image when no text is entered.
- auto showSpinner() const -> bool
- Show a spinner icon.
- auto value() const -> QString
- Returns the text of this edit with support for handling null values.
Signals
- void cleared()
- Emitted when the widget is cleared.
- void selectOnFocusChanged()
- Will select all text when this widget receives the focus.
- void showSpinnerChanged()
- Show a spinner icon.
- void valueChanged(const QString& value)
- Same as textChanged() but with support for null values.
Public slots
- void clearValue() virtual
- Clears the widget and resets it to the null value.
Enum documentation
enum QgsFilterLineEdit:: ClearMode
Behavior when clearing value of widget.
| Enumerators | |
|---|---|
| ClearToNull |
Reset value to null. |
| ClearToDefault |
Reset value to default value (see defaultValue() ) |
Function documentation
QgsFilterLineEdit:: QgsFilterLineEdit(QWidget* parent = nullptr,
const QString& nullValue = QString())
Constructor for QgsFilterLineEdit.
| Parameters | |
|---|---|
| parent | parent widget |
| nullValue | string for representing null values |
QString QgsFilterLineEdit:: defaultValue() const
Returns the default value for the widget.
The default value is a value which the widget will be reset to if it is cleared and the clearMode() is equal to ClearToDefault.
bool QgsFilterLineEdit:: event(QEvent* event) override
Reimplemented to enable/disable the clear action depending on read-only status.
bool QgsFilterLineEdit:: isNull() const
Determine if the current text represents null.
| Returns | True if the widget's value is null. |
|---|
QString QgsFilterLineEdit:: nullValue() const
Returns the string used for representating null values in the widget.
bool QgsFilterLineEdit:: selectOnFocus() const
Will select all text when this widget receives the focus.
void QgsFilterLineEdit:: setClearMode(ClearMode mode)
Sets the clear mode for the widget.
The clear mode defines the behavior of the widget when its value is cleared. This defaults to ClearToNull.
void QgsFilterLineEdit:: setDefaultValue(const QString& defaultValue)
Sets the default value for the widget.
| Parameters | |
|---|---|
| defaultValue | default value |
The default value is a value which the widget will be reset to if it is cleared and the clearMode() is equal to ClearToDefault.
void QgsFilterLineEdit:: setNullValue(const QString& nullValue)
Sets the string representation for null values in the widget.
| Parameters | |
|---|---|
| nullValue | string to show when widget's value is null |
This does not affect the values returned for null values by value(), rather it only affects the text that is shown to users when the widget's value is null.
void QgsFilterLineEdit:: setSelectOnFocus(bool selectOnFocus)
Will select all text when this widget receives the focus.
void QgsFilterLineEdit:: setShowClearButton(bool visible)
Sets whether the widget's clear button is visible.
| Parameters | |
|---|---|
| visible | set to false to hide the clear button |
void QgsFilterLineEdit:: setShowSearchIcon(bool visible)
Define if a search icon shall be shown on the left of the image when no text is entered.
| Parameters | |
|---|---|
| visible | set to false to hide the search icon |
void QgsFilterLineEdit:: setShowSpinner(bool showSpinner)
Show a spinner icon.
This can be used for search boxes to indicate that something is going on in the background.
void QgsFilterLineEdit:: setValue(const QString& value)
Sets the current text for the widget with support for handling null values.
| Parameters | |
|---|---|
| value | The text to set. If a null string is provided, the text shown in the widget will be set to the current nullValue(). |
bool QgsFilterLineEdit:: showClearButton() const
Returns true if the widget's clear button is visible.
bool QgsFilterLineEdit:: showSearchIcon() const
Returns if a search icon shall be shown on the left of the image when no text is entered.
bool QgsFilterLineEdit:: showSpinner() const
Show a spinner icon.
This can be used for search boxes to indicate that something is going on in the background.
QString QgsFilterLineEdit:: value() const
Returns the text of this edit with support for handling null values.
| Returns | Current text (or null string if it matches the nullValue() property ) |
|---|
If the text in the widget matches the current nullValue() then the returned value will be a null string.
void QgsFilterLineEdit:: cleared() signal
Emitted when the widget is cleared.
void QgsFilterLineEdit:: selectOnFocusChanged() signal
Will select all text when this widget receives the focus.
void QgsFilterLineEdit:: showSpinnerChanged() signal
Show a spinner icon.
This can be used for search boxes to indicate that something is going on in the background.
void QgsFilterLineEdit:: valueChanged(const QString& value) signal
Same as textChanged() but with support for null values.
| Parameters | |
|---|---|
| value | The current text or null string if it matches the nullValue() property. |
void QgsFilterLineEdit:: clearValue() virtual public slot
Clears the widget and resets it to the null value.