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.

Parameters

parent

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.

Return type

bool

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.

Return type

str

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.

New in version 2.12.

Return type

QgsExpressionContext

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.

Return type

str

Returns

The expression as a string. *

focusInEvent()
focusNextChild()
focusNextPrevChild()
focusOutEvent()
focusPreviousChild()
hideEvent()
initPainter()
inputMethodEvent()
isExpressionValid(self) → bool
Return type

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

Parameters

path (str) –

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.

Parameters

fieldValues (Dict[str) –

loadFunctionCode(self, code: str)

Load code into the function editor

Parameters

code (str) –

loadRecent(self, collection: str = '')

Loads the recent expressions from the given collection. By default it is loaded from the collection “generic”.

Parameters

collection (str = '') –

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.

Return type

QStandardItemModel

mouseDoubleClickEvent()
mouseMoveEvent()
mousePressEvent()
mouseReleaseEvent()
moveEvent()
nativeEvent()
newFunctionFile(self, fileName: str = '')

Create a new file in the function editor

Parameters

fileName (str = '') –

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.

Return type

bool

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

setProject()

New in version 3.0.

Return type

QgsProject

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 (str) – The group the item will be show in the tree view. If the group doesn’t exsit it will be created.

  • label (str) – The label that is show to the user for the item in the tree.

  • expressionText (str) – The text that is inserted into the expression area when the user double clicks on the item.

  • helpText (str = '') – The help text that the user will see when item is selected.

  • type (QgsExpressionItem.ItemType = QgsExpressionItem.ExpressionNode) – The type of the expression item.

  • highlightedItem (bool = False) – set to true to make the item highlighted, which inserts a bold copy of the item at the top level

  • sortOrder (int = 1) – sort ranking for item

  • icon (QIcon = QIcon()) – custom icon to show for item

resizeEvent()
saveFunctionFile(self, fileName: str)

Save the current function editor text to the given file.

Parameters

fileName (str) –

saveToRecent(self, collection: str = '')

Adds the current expression to the given collection. By default it is saved to the collection “generic”.

Parameters

collection (str = '') –

sender()
senderSignalIndex()
setAutoSave(self, enabled: bool)

Enabled or disable auto saving. When enabled Python scripts will be auto saved when text changes.

Parameters

enabled (bool) – 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 (str) – 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 (QgsExpressionContext) – expression context

New in version 2.12.

setExpressionText(self, expression: str)

Sets the expression string for the widget

Parameters

expression (str) –

setGeomCalculator(self, da: QgsDistanceArea)

Sets geometry calculator used in distance/area calculations.

Parameters

da (QgsDistanceArea) –

setLayer(self, layer: QgsVectorLayer)

Sets layer in order to get the fields and values

Note

this needs to be called before calling loadFieldNames().

Parameters

layer (QgsVectorLayer) –

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

project()

New in version 3.0.

Parameters

project (QgsProject) –

sharedPainter()
showEvent(self, e: QShowEvent)
Parameters

e (QShowEvent) –

tabletEvent()
timerEvent()
updateFunctionFileList(self, path: str)

Update the list of function files found at the given path

Parameters

path (str) –

updateMicroFocus()
wheelEvent()