Class: QgsFieldExpressionWidget¶
-
class
qgis.gui.
QgsFieldExpressionWidget
(parent: QWidget = None)¶ Bases:
PyQt5.QtWidgets.QWidget
QgsFieldExpressionWidget creates a widget with a combo box to display the fields and expression and a button to open the expression dialog
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).
Enums
Methods
Returns
True
if the combo box allows the empty field (“not set”) choice.Allow accepting expressions with evaluation errors.
Appends a scope to the current expression context.
Returns the currently selected field or expression.
currentField returns the currently selected field or expression if allowed
Returns the current text that is set in the expression area
open the expression dialog to edit the current or add a new expression
Returns the currently selected field or expression.
Returns the title used for the expression dialog
when expression is edited by the user in the line edit, it will be checked for validity
when expression has been edited (finished) it will be added to the model
currently used filter on list of fields
If the content is not just a simple field this method will return
True
.Returns
True
if the current expression is validReturns the layer currently associated with the widget.
Register an expression context generator class that will be used to retrieve an expression context for the widget.
Sets whether an optional empty field (“not set”) option is shown in the combo box.
Allow accepting expressions with evaluation errors.
Sets the current expression text and if applicable also the field.
define the title used in the expression dialog
sets the current field or expression in the widget
setFilters allows fitering according to the type of field
Sets the geometry calculator used in the expression dialog
Sets the layer used to display the fields and expression.
sets the current row in the widget
updateLineEditStyle will re-style (color/font) the line edit depending on content and status
Signals
Allow accepting expressions with evaluation errors.
Emitted when the currently selected field changes.
Attributes
-
actionEvent
()¶
-
allowEmptyFieldName
(self) → bool¶ Returns
True
if the combo box allows the empty field (“not set”) choice.See also
New in version 3.4.6.
-
allowEvalErrors
(self) → bool¶ 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.
New in version 3.0.
-
allowEvalErrorsChanged
¶ 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.
New in version 3.0: [signal]
-
appendScope
(self, scope: QgsExpressionContextScope)¶ Appends a scope to the current expression context.
- Parameters
scope – The scope to add.
New in version 3.2.
-
asExpression
(self) → str¶ 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).
New in version 2.14.
-
changeEvent
(self, event: QEvent)¶
-
childEvent
()¶
-
closeEvent
()¶
-
connectNotify
()¶
-
contextMenuEvent
()¶
-
create
()¶
-
currentField
(self) → Tuple[str, bool, bool]¶ currentField returns the currently selected field or expression if allowed
- Parameters
isExpression – determines if the string returned is the name of a field or an expression
isValid – determines if the expression (or field) returned is valid
-
currentFieldChanged
(self)¶
-
currentText
(self) → str¶ Returns the current text that is set in the expression area
-
customEvent
()¶
-
destroy
()¶
-
disconnectNotify
()¶
-
dragEnterEvent
()¶
-
dragLeaveEvent
()¶
-
dragMoveEvent
()¶
-
dropEvent
()¶
-
editExpression
(self)¶ open the expression dialog to edit the current or add a new expression
-
enterEvent
()¶
-
event
()¶
-
eventFilter
(self, watched: QObject, event: QEvent) → bool¶
-
expression
(self) → str¶ 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()
New in version 3.0.
-
expressionDialogTitle
(self) → str¶ Returns the title used for the expression dialog
-
expressionEdited
(self, expression: str)¶ when expression is edited by the user in the line edit, it will be checked for validity
-
expressionEditingFinished
(self)¶ when expression has been edited (finished) it will be added to the model
-
fieldChanged
¶ Emitted when the currently selected field changes. [signal] fieldChanged(self, fieldName: str, isValid: bool) fieldChanged signal with indication of the validity of the expression [signal]
-
filters
(self) → QgsFieldProxyModel.Filters¶ currently used filter on list of fields
-
focusInEvent
()¶
-
focusNextChild
()¶
-
focusNextPrevChild
()¶
-
focusOutEvent
()¶
-
focusPreviousChild
()¶
-
hideEvent
()¶
-
initPainter
()¶
-
inputMethodEvent
()¶
-
isExpression
(self) → bool¶ If the content is not just a simple field this method will return
True
.
-
isExpressionValid
(self, expressionStr: str) → bool¶
-
isSignalConnected
()¶
-
isValidExpression
(self, expressionError: str = '') → bool¶ Returns
True
if the current expression is valid
-
keyPressEvent
()¶
-
keyReleaseEvent
()¶
-
layer
(self) → QgsVectorLayer¶ Returns the layer currently associated with the widget.
See also
-
leaveEvent
()¶
-
metric
()¶
-
mouseDoubleClickEvent
()¶
-
mouseMoveEvent
()¶
-
mousePressEvent
()¶
-
mouseReleaseEvent
()¶
-
moveEvent
()¶
-
nativeEvent
()¶
-
paintEvent
()¶
-
receivers
()¶
-
registerExpressionContextGenerator
(self, generator: QgsExpressionContextGenerator)¶ Register an expression context generator class that will be used to retrieve an expression context for the widget.
- Parameters
generator – A QgsExpressionContextGenerator class that will be used to create an expression context when required.
New in version 3.0.
-
resizeEvent
()¶
-
sender
()¶
-
senderSignalIndex
()¶
-
setAllowEmptyFieldName
(self, allowEmpty: bool)¶ Sets whether an optional empty field (“not set”) option is shown in the combo box.
See also
New in version 3.4.6.
-
setAllowEvalErrors
(self, allowEvalErrors: bool)¶ 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.
New in version 3.0.
-
setExpression
(self, expression: str)¶ Sets the current expression text and if applicable also the field. Alias for setField.
New in version 3.0.
-
setExpressionDialogTitle
(self, title: str)¶ define the title used in the expression dialog
-
setField
(self, fieldName: str)¶ sets the current field or expression in the widget
-
setFilters
(self, filters: Union[QgsFieldProxyModel.Filters, QgsFieldProxyModel.Filter])¶ setFilters allows fitering according to the type of field
-
setGeomCalculator
(self, da: QgsDistanceArea)¶ Sets the geometry calculator used in the expression dialog
-
setLayer
(self, layer: QgsMapLayer)¶ Sets the layer used to display the fields and expression.
See also
-
setLeftHandButtonStyle
(self, isLeft: bool)¶
-
setRow
(self, row: int)¶ sets the current row in the widget
-
showEvent
()¶
-
tabletEvent
()¶
-
timerEvent
()¶
-
updateLineEditStyle
(self, expression: str = '')¶ updateLineEditStyle will re-style (color/font) the line edit depending on content and status
- Parameters
expression – if expression is given it will be evaluated for the given string, otherwise it takes current expression from the model
-
updateMicroFocus
()¶
-
wheelEvent
()¶
-