Class: QgsExpressionBuilderWidget¶
-
class
qgis.gui.
QgsExpressionBuilderWidget
(parent: QWidget = None)¶ Bases:
PyQt5.QtWidgets.QWidget
Create a new expression builder widget with an optional parent.
A reusable widget that can be used to build a expression string. See QgsExpressionBuilderDialog for example of usage.
Enums
Methods
Auto save the current Python function code.
Will be set to true if the current expression text reported an eval error with the context.
The set expected format string.
Returns the expression context for the widget.
Gets the expression string that has been set in the expression area.
Load all unique values from the set layer into the sample area
Load code from the given file into the function editor
Loads all the field names from the layer.
Loads field names and values from the specified map.
Load code into the function editor
Loads the recent expressions from the given collection.
Load sample values into the sample value area
Returns a pointer to the dialog’s function item model.
Create a new file in the function editor
Will be set to true if the current expression text reports a parser error with the context.
Returns the project currently associated with the widget.
Registers a node item for the expression builder.
Save the current function editor text to the given file.
Adds the current expression to the given collection.
Enabled or disable auto saving.
The set expected format string.
Sets the expression context for the widget.
Sets the expression string for the widget
Sets geometry calculator used in distance/area calculations.
Sets layer in order to get the fields and values
Sets the
project
currently associated with the widget.Update the list of function files found at the given path
Signals
Will be set to true if the current expression text reported an eval error with the context.
Emitted when the user changes the expression in the widget.
Will be set to true if the current expression text reported a parser error with the context.
Attributes
-
actionEvent
()¶
-
autosave
(self)¶ Auto save the current Python function code.
-
changeEvent
()¶
-
childEvent
()¶
-
closeEvent
()¶
-
connectNotify
()¶
-
contextMenuEvent
()¶
-
create
()¶
-
customEvent
()¶
-
destroy
()¶
-
disconnectNotify
()¶
-
dragEnterEvent
()¶
-
dragLeaveEvent
()¶
-
dragMoveEvent
()¶
-
dropEvent
()¶
-
enterEvent
()¶
-
evalError
(self) → bool¶ Will be set to true if the current expression text reported an eval error with the context.
New in version 3.0.
-
evalErrorChanged
¶ Will be set to true if the current expression text reported an eval error with the context.
New in version 3.0: [signal]
-
event
()¶
-
expectedOutputFormat
(self) → str¶ The set expected format string. This is pure text format and no expression validation is done against it.
- Returns
The expected value format.
-
expressionContext
(self) → QgsExpressionContext¶ Returns the expression context for the widget. The context is used for the expression preview result and for populating the list of available functions and variables.
See also
New in version 2.12.
-
expressionParsed
¶ Emitted when the user changes the expression in the widget. Users of this widget should connect to this signal to decide if to let the user continue.
- Parameters
isValid – Is true if the expression the user has typed is valid. [signal]
-
expressionText
(self) → str¶ Gets the expression string that has been set in the expression area.
- Returns
The expression as a string. *
-
focusInEvent
()¶
-
focusNextChild
()¶
-
focusNextPrevChild
()¶
-
focusOutEvent
()¶
-
focusPreviousChild
()¶
-
hideEvent
()¶
-
initPainter
()¶
-
inputMethodEvent
()¶
-
isExpressionValid
(self) → bool¶
-
isSignalConnected
()¶
-
keyPressEvent
()¶
-
keyReleaseEvent
()¶
-
leaveEvent
()¶
-
loadAllValues
(self)¶ Load all unique values from the set layer into the sample area
-
loadCodeFromFile
(self, path: str)¶ Load code from the given file into the function editor
-
loadFieldNames
(self)¶ Loads all the field names from the layer. @remarks Should this really be public couldn’t we just do this for the user?
loadFieldNames(self, fields: QgsFields)
-
loadFieldsAndValues
(self, fieldValues: Dict[str, Iterable[str]])¶ Loads field names and values from the specified map.
Note
The field values must be quoted appropriately if they are strings.
New in version 2.12.
-
loadFunctionCode
(self, code: str)¶ Load code into the function editor
-
loadRecent
(self, collection: str = '')¶ Loads the recent expressions from the given collection. By default it is loaded from the collection “generic”.
-
loadSampleValues
(self)¶ Load sample values into the sample value area
-
metric
()¶
-
model
(self) → QStandardItemModel¶ Returns a pointer to the dialog’s function item model. This method is exposed for testing purposes only - it should not be used to modify the model.
New in version 3.0.
-
mouseDoubleClickEvent
()¶
-
mouseMoveEvent
()¶
-
mousePressEvent
()¶
-
mouseReleaseEvent
()¶
-
moveEvent
()¶
-
nativeEvent
()¶
-
newFunctionFile
(self, fileName: str = '')¶ Create a new file in the function editor
-
paintEvent
()¶
-
parserError
(self) → bool¶ Will be set to true if the current expression text reports a parser error with the context.
New in version 3.0.
-
parserErrorChanged
¶ Will be set to true if the current expression text reported a parser error with the context.
New in version 3.0: [signal]
-
project
(self) → QgsProject¶ Returns the project currently associated with the widget.
See also
New in version 3.0.
-
receivers
()¶
-
registerItem
(self, group: str, label: str, expressionText: str, helpText: str = '', type: QgsExpressionItem.ItemType = QgsExpressionItem.ExpressionNode, highlightedItem: bool = False, sortOrder: int = 1, icon: QIcon = QIcon())¶ Registers a node item for the expression builder.
- Parameters
group – The group the item will be show in the tree view. If the group doesn’t exsit it will be created.
label – The label that is show to the user for the item in the tree.
expressionText – The text that is inserted into the expression area when the user double clicks on the item.
helpText – The help text that the user will see when item is selected.
type – The type of the expression item.
highlightedItem – set to true to make the item highlighted, which inserts a bold copy of the item at the top level
sortOrder – sort ranking for item
icon – custom icon to show for item
-
resizeEvent
()¶
-
saveFunctionFile
(self, fileName: str)¶ Save the current function editor text to the given file.
-
saveToRecent
(self, collection: str = '')¶ Adds the current expression to the given collection. By default it is saved to the collection “generic”.
-
sender
()¶
-
senderSignalIndex
()¶
-
setAutoSave
(self, enabled: bool)¶ Enabled or disable auto saving. When enabled Python scripts will be auto saved when text changes.
- Parameters
enabled – True to enable auto saving.
-
setExpectedOutputFormat
(self, expected: str)¶ The set expected format string. This is pure text format and no expression validation is done against it.
- Parameters
expected – The expected value format for the expression.
Note
Only a UI hint and not used for expression validation.
-
setExpressionContext
(self, context: QgsExpressionContext)¶ Sets the expression context for the widget. The context is used for the expression preview result and for populating the list of available functions and variables.
- Parameters
context – expression context
See also
New in version 2.12.
-
setExpressionText
(self, expression: str)¶ Sets the expression string for the widget
-
setGeomCalculator
(self, da: QgsDistanceArea)¶ Sets geometry calculator used in distance/area calculations.
-
setLayer
(self, layer: QgsVectorLayer)¶ Sets layer in order to get the fields and values
Note
this needs to be called before calling loadFieldNames().
-
setProject
(self, project: QgsProject)¶ Sets the
project
currently associated with the widget. This controls which layers and relations and other project-specific items are shown in the widget.See also
New in version 3.0.
-
showEvent
(self, e: QShowEvent)¶
-
tabletEvent
()¶
-
timerEvent
()¶
-
updateFunctionFileList
(self, path: str)¶ Update the list of function files found at the given path
-
updateMicroFocus
()¶
-
wheelEvent
()¶
-