QGIS API Documentation  3.4.15-Madeira (e83d02e274)
Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Properties | Friends | List of all members
QgsFieldExpressionWidget Class Reference

The QgsFieldExpressionWidget class reates a widget to choose fields and edit expressions It contains a combo boxto display the fields and expression and a button to open the expression dialog. More...

#include <qgsfieldexpressionwidget.h>

Inheritance diagram for QgsFieldExpressionWidget:
Inheritance graph
[legend]

Public Slots

void setExpression (const QString &expression)
 Sets the current expression text and if applicable also the field. More...
 
void setField (const QString &fieldName)
 sets the current field or expression in the widget More...
 
void setLayer (QgsMapLayer *layer)
 Sets the layer used to display the fields and expression. More...
 
void setRow (int row)
 sets the current row in the widget More...
 

Signals

void allowEvalErrorsChanged ()
 Allow accepting expressions with evaluation errors. More...
 
void fieldChanged (const QString &fieldName)
 the signal is emitted when the currently selected field changes More...
 
void fieldChanged (const QString &fieldName, bool isValid)
 fieldChanged signal with indication of the validity of the expression More...
 

Public Member Functions

 QgsFieldExpressionWidget (QWidget *parent=nullptr)
 QgsFieldExpressionWidget creates a widget with a combo box to display the fields and expression and a button to open the expression dialog. More...
 
bool allowEmptyFieldName () const
 Returns true if the combo box allows the empty field ("not set") choice. More...
 
bool allowEvalErrors () const
 Allow accepting expressions with evaluation errors. More...
 
void appendScope (QgsExpressionContextScope *scope)
 Appends a scope to the current expression context. More...
 
QString asExpression () const
 Returns the currently selected field or expression. More...
 
QString currentField (bool *isExpression=nullptr, bool *isValid=nullptr) const
 currentField returns the currently selected field or expression if allowed More...
 
QString currentText () const
 Returns the current text that is set in the expression area. More...
 
QString expression () const
 Returns the currently selected field or expression. More...
 
const QString expressionDialogTitle ()
 Returns the title used for the expression dialog. More...
 
QgsFieldProxyModel::Filters filters () const
 currently used filter on list of fields More...
 
bool isExpression () const
 If the content is not just a simple field this method will return true. More...
 
bool isValidExpression (QString *expressionError=nullptr) const
 Returns true if the current expression is valid. More...
 
QgsVectorLayerlayer () const
 Returns the layer currently associated with the widget. More...
 
void registerExpressionContextGenerator (const QgsExpressionContextGenerator *generator)
 Register an expression context generator class that will be used to retrieve an expression context for the widget. More...
 
void setAllowEmptyFieldName (bool allowEmpty)
 Sets whether an optional empty field ("not set") option is shown in the combo box. More...
 
void setAllowEvalErrors (bool allowEvalErrors)
 Allow accepting expressions with evaluation errors. More...
 
void setExpressionDialogTitle (const QString &title)
 define the title used in the expression dialog More...
 
void setFilters (QgsFieldProxyModel::Filters filters)
 setFilters allows fitering according to the type of field More...
 
void setGeomCalculator (const QgsDistanceArea &da)
 Sets the geometry calculator used in the expression dialog. More...
 
void setLeftHandButtonStyle (bool isLeft)
 

Protected Slots

void currentFieldChanged ()
 
void editExpression ()
 open the expression dialog to edit the current or add a new expression More...
 
void expressionEdited (const QString &expression)
 when expression is edited by the user in the line edit, it will be checked for validity More...
 
void expressionEditingFinished ()
 when expression has been edited (finished) it will be added to the model More...
 
bool isExpressionValid (const QString &expressionStr)
 
void updateLineEditStyle (const QString &expression=QString())
 updateLineEditStyle will re-style (color/font) the line edit depending on content and status More...
 

Protected Member Functions

void changeEvent (QEvent *event) override
 
bool eventFilter (QObject *watched, QEvent *event) override
 

Properties

bool allowEmptyFieldName
 
bool allowEvalErrors
 
QString expressionDialogTitle
 
QgsFieldProxyModel::Filters filters
 

Friends

class TestQgsFieldExpressionWidget
 

Detailed Description

The QgsFieldExpressionWidget class reates a widget to choose fields and edit expressions It contains a combo boxto display the fields and expression and a button to open the expression dialog.

The combo box is editable, allowing expressions to be edited inline. The validity of the expression is checked live on key press, invalid expressions are displayed in red. The expression will be added to the model (and the fieldChanged signals emitted) only when editing in the line edit is finished (focus lost, enter key pressed).

Definition at line 46 of file qgsfieldexpressionwidget.h.

Constructor & Destructor Documentation

QgsFieldExpressionWidget::QgsFieldExpressionWidget ( QWidget *  parent = nullptr)
explicit

QgsFieldExpressionWidget creates a widget with a combo box to display the fields and expression and a button to open the expression dialog.

Definition at line 30 of file qgsfieldexpressionwidget.cpp.

Member Function Documentation

bool QgsFieldExpressionWidget::allowEmptyFieldName ( ) const

Returns true if the combo box allows the empty field ("not set") choice.

See also
setAllowEmptyFieldName()
Since
QGIS 3.4.6
bool QgsFieldExpressionWidget::allowEvalErrors ( ) const

Allow accepting expressions with evaluation errors.

This can be useful when we are not able to provide an expression context of which we are sure it's completely populated.

Since
QGIS 3.0
void QgsFieldExpressionWidget::allowEvalErrorsChanged ( )
signal

Allow accepting expressions with evaluation errors.

This can be useful when we are not able to provide an expression context of which we are sure it's completely populated.

Since
QGIS 3.0
void QgsFieldExpressionWidget::appendScope ( QgsExpressionContextScope scope)

Appends a scope to the current expression context.

Parameters
scopeThe scope to add.
Since
QGIS 3.2

Definition at line 375 of file qgsfieldexpressionwidget.cpp.

QString QgsFieldExpressionWidget::asExpression ( ) const

Returns the currently selected field or expression.

If a field is currently selected, the returned value will be converted to a valid expression referencing this field (ie enclosing the field name with appropriate quotations).

Since
QGIS 2.14

Definition at line 121 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::changeEvent ( QEvent *  event)
overrideprotected

Definition at line 262 of file qgsfieldexpressionwidget.cpp.

QString QgsFieldExpressionWidget::currentField ( bool *  isExpression = nullptr,
bool *  isValid = nullptr 
) const

currentField returns the currently selected field or expression if allowed

Parameters
isExpressiondetermines if the string returned is the name of a field or an expression
isValiddetermines if the expression (or field) returned is valid

Definition at line 142 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::currentFieldChanged ( )
protectedslot

Definition at line 315 of file qgsfieldexpressionwidget.cpp.

QString QgsFieldExpressionWidget::currentText ( ) const

Returns the current text that is set in the expression area.

Definition at line 116 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::editExpression ( )
protectedslot

open the expression dialog to edit the current or add a new expression

Definition at line 224 of file qgsfieldexpressionwidget.cpp.

bool QgsFieldExpressionWidget::eventFilter ( QObject *  watched,
QEvent *  event 
)
overrideprotected

Definition at line 287 of file qgsfieldexpressionwidget.cpp.

QString QgsFieldExpressionWidget::expression ( ) const

Returns the currently selected field or expression.

If a field is currently selected, the returned value will be converted to a valid expression referencing this field (ie enclosing the field name with appropriate quotations).

Alias for asExpression()

Since
QGIS 3.0

Definition at line 126 of file qgsfieldexpressionwidget.cpp.

const QString QgsFieldExpressionWidget::expressionDialogTitle ( )
inline

Returns the title used for the expression dialog.

Definition at line 74 of file qgsfieldexpressionwidget.h.

void QgsFieldExpressionWidget::expressionEdited ( const QString &  expression)
protectedslot

when expression is edited by the user in the line edit, it will be checked for validity

Definition at line 246 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::expressionEditingFinished ( )
protectedslot

when expression has been edited (finished) it will be added to the model

Definition at line 252 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::fieldChanged ( const QString &  fieldName)
signal

the signal is emitted when the currently selected field changes

void QgsFieldExpressionWidget::fieldChanged ( const QString &  fieldName,
bool  isValid 
)
signal

fieldChanged signal with indication of the validity of the expression

QgsFieldProxyModel::Filters QgsFieldExpressionWidget::filters ( ) const
inline

currently used filter on list of fields

Definition at line 96 of file qgsfieldexpressionwidget.h.

bool QgsFieldExpressionWidget::isExpression ( ) const

If the content is not just a simple field this method will return true.

Definition at line 137 of file qgsfieldexpressionwidget.cpp.

bool QgsFieldExpressionWidget::isExpressionValid ( const QString &  expressionStr)
protectedslot

Definition at line 368 of file qgsfieldexpressionwidget.cpp.

bool QgsFieldExpressionWidget::isValidExpression ( QString *  expressionError = nullptr) const

Returns true if the current expression is valid.

Definition at line 131 of file qgsfieldexpressionwidget.cpp.

QgsVectorLayer * QgsFieldExpressionWidget::layer ( ) const

Returns the layer currently associated with the widget.

See also
setLayer()

Definition at line 158 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::registerExpressionContextGenerator ( const QgsExpressionContextGenerator generator)

Register an expression context generator class that will be used to retrieve an expression context for the widget.

Parameters
generatorA QgsExpressionContextGenerator class that will be used to create an expression context when required.
Since
QGIS 3.0

Definition at line 163 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::setAllowEmptyFieldName ( bool  allowEmpty)

Sets whether an optional empty field ("not set") option is shown in the combo box.

See also
allowEmptyFieldName()
Since
QGIS 3.4.6

Definition at line 85 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::setAllowEvalErrors ( bool  allowEvalErrors)

Allow accepting expressions with evaluation errors.

This can be useful when we are not able to provide an expression context of which we are sure it's completely populated.

Since
QGIS 3.0

Definition at line 306 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::setExpression ( const QString &  expression)
slot

Sets the current expression text and if applicable also the field.

Alias for setField.

Since
QGIS 3.0

Definition at line 219 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::setExpressionDialogTitle ( const QString &  title)

define the title used in the expression dialog

Definition at line 75 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::setField ( const QString &  fieldName)
slot

sets the current field or expression in the widget

Definition at line 186 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::setFilters ( QgsFieldProxyModel::Filters  filters)

setFilters allows fitering according to the type of field

Definition at line 80 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::setGeomCalculator ( const QgsDistanceArea da)

Sets the geometry calculator used in the expression dialog.

Definition at line 111 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::setLayer ( QgsMapLayer layer)
slot

Sets the layer used to display the fields and expression.

See also
layer()

Definition at line 168 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::setLeftHandButtonStyle ( bool  isLeft)

Definition at line 96 of file qgsfieldexpressionwidget.cpp.

void QgsFieldExpressionWidget::setRow ( int  row)
inlineslot

sets the current row in the widget

Definition at line 197 of file qgsfieldexpressionwidget.h.

void QgsFieldExpressionWidget::updateLineEditStyle ( const QString &  expression = QString())
protectedslot

updateLineEditStyle will re-style (color/font) the line edit depending on content and status

Parameters
expressionif expression is given it will be evaluated for the given string, otherwise it takes current expression from the model

Definition at line 337 of file qgsfieldexpressionwidget.cpp.

Friends And Related Function Documentation

friend class TestQgsFieldExpressionWidget
friend

Definition at line 253 of file qgsfieldexpressionwidget.h.

Property Documentation

bool QgsFieldExpressionWidget::allowEmptyFieldName
readwrite

Definition at line 51 of file qgsfieldexpressionwidget.h.

bool QgsFieldExpressionWidget::allowEvalErrors
readwrite

Definition at line 52 of file qgsfieldexpressionwidget.h.

QString QgsFieldExpressionWidget::expressionDialogTitle
readwrite

Definition at line 49 of file qgsfieldexpressionwidget.h.

QgsFieldProxyModel::Filters QgsFieldExpressionWidget::filters
readwrite

Definition at line 50 of file qgsfieldexpressionwidget.h.


The documentation for this class was generated from the following files: