Class: QgsExpressionBuilderWidget¶
- class qgis.gui.QgsExpressionBuilderWidget¶
Bases:
PyQt5.QtWidgets.QWidget
A reusable widget that can be used to build a expression string. See
QgsExpressionBuilderDialog
for example of usage.QgsExpressionBuilderWidget(parent: QWidget = None) Create a new expression builder widget with an optional parent.
Methods
Auto save the current Python function code.
Edits the selected expression from the stored user expressions, the selected expression must be a user stored expression.
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.
Returns the expression tree
Returns the list of expression items matching a
label
.Initialize without any layer
Initialize with given fields without any layer
Initialize with a layer
Returns if the expression is valid
Returns the current layer or a None.
Load all unique values from the set layer into the sample area.
Load all unique values from the set layer into the sample area.
Loads code from the given file into the function editor
Deprecated since version QGIS: 3.14
Loads field names and values from the specified map.
Loads code into the function editor
Loads the recent expressions from the given
collection
.Load used sample values into the sample value area.
Load sample values into the sample value area.
Loads the user expressions.
Returns a pointer to the dialog's function item model.
Creates 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.
Removes the expression
label
from the user stored expressions.Removes the selected expression from the stored user expressions, the selected expression must be a user stored expression.
Saves the current function editor text to the given file.
Adds the current expression to the given
collection
.Stores the user
expression
with givenlabel
andhelpText
.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.- param e
Adds the current expressions to the stored user expressions.
Updates 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
- class Flag¶
Bases:
int
- baseClass¶
alias of
qgis._gui.QgsExpressionBuilderWidget
- class Flags¶
- class Flags(Union[QgsExpressionBuilderWidget.Flags, QgsExpressionBuilderWidget.Flag]) None
- class Flags(QgsExpressionBuilderWidget.Flags) None
Bases:
sip.wrapper
- LoadAll = 6¶
- LoadNothing = 0¶
- LoadRecent = 2¶
- LoadUserExpressions = 4¶
- actionEvent(self, QActionEvent)¶
- autosave(self)¶
Auto save the current Python function code.
- changeEvent(self, QEvent)¶
- childEvent(self, QChildEvent)¶
- closeEvent(self, QCloseEvent)¶
- connectNotify(self, QMetaMethod)¶
- contextMenuEvent(self, QContextMenuEvent)¶
- create(self, window: sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)¶
- customEvent(self, QEvent)¶
- destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)¶
- disconnectNotify(self, QMetaMethod)¶
- dragEnterEvent(self, QDragEnterEvent)¶
- dragLeaveEvent(self, QDragLeaveEvent)¶
- dragMoveEvent(self, QDragMoveEvent)¶
- dropEvent(self, QDropEvent)¶
- editSelectedUserExpression(self)¶
Edits the selected expression from the stored user expressions, the selected expression must be a user stored expression.
New in version 3.14.
- enterEvent(self, QEvent)¶
- 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(self, QEvent) bool ¶
- 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.
See also
New in version 2.12.
- Return type
- 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 (bool) – 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.
- expressionTree(self) QgsExpressionTreeView ¶
Returns the expression tree
New in version 3.14.
- Return type
- findExpressions(self, label: str) List[QgsExpressionItem] ¶
Returns the list of expression items matching a
label
.New in version 3.12.
Deprecated since version QGIS: 3.14 use
expressionTree()
->findExpressions instead- Parameters
label (str) –
- Return type
List[QgsExpressionItem]
- focusInEvent(self, QFocusEvent)¶
- focusNextChild(self) bool ¶
- focusNextPrevChild(self, bool) bool ¶
- focusOutEvent(self, QFocusEvent)¶
- focusPreviousChild(self) bool ¶
- hideEvent(self, QHideEvent)¶
- init(self, context: QgsExpressionContext = QgsExpressionContext(), recentCollection: str = '', flags: Union[QgsExpressionBuilderWidget.Flags, QgsExpressionBuilderWidget.Flag] = QgsExpressionBuilderWidget.LoadAll)¶
Initialize without any layer
New in version 3.14.
- Parameters
context (
QgsExpressionContext
= QgsExpressionContext()) –recentCollection (str = '') –
flags (Union[QgsExpressionBuilderWidget.Flags) –
- initPainter(self, QPainter)¶
- initWithFields(self, fields: QgsFields, context: QgsExpressionContext = QgsExpressionContext(), recentCollection: str = '', flags: Union[QgsExpressionBuilderWidget.Flags, QgsExpressionBuilderWidget.Flag] = QgsExpressionBuilderWidget.LoadAll)¶
Initialize with given fields without any layer
New in version 3.14.
- Parameters
fields (QgsFields) –
context (
QgsExpressionContext
= QgsExpressionContext()) –recentCollection (str = '') –
flags (Union[QgsExpressionBuilderWidget.Flags) –
- initWithLayer(self, layer: QgsVectorLayer, context: QgsExpressionContext = QgsExpressionContext(), recentCollection: str = '', flags: Union[QgsExpressionBuilderWidget.Flags, QgsExpressionBuilderWidget.Flag] = QgsExpressionBuilderWidget.LoadAll)¶
Initialize with a layer
New in version 3.14.
- Parameters
layer (QgsVectorLayer) –
context (
QgsExpressionContext
= QgsExpressionContext()) –recentCollection (str = '') –
flags (Union[QgsExpressionBuilderWidget.Flags) –
- inputMethodEvent(self, QInputMethodEvent)¶
- isExpressionValid(self) bool ¶
Returns if the expression is valid
- Return type
bool
- isSignalConnected(self, QMetaMethod) bool ¶
- keyPressEvent(self, QKeyEvent)¶
- keyReleaseEvent(self, QKeyEvent)¶
- layer(self) QgsVectorLayer ¶
Returns the current layer or a None.
- Return type
- leaveEvent(self, QEvent)¶
- loadAllUsedValues(self)¶
Load all unique values from the set layer into the sample area. Only the used ones. Without available values, even if the formatter can provide them (eg. RelationReference).
New in version 3.12.
- loadAllValues(self)¶
Load all unique values from the set layer into the sample area. Including all available values, in case the formatter can provide them (eg. RelationReference).
- loadCodeFromFile(self, path: str)¶
Loads code from the given file into the function editor
- Parameters
path (str) –
- loadFieldNames(self)¶
Deprecated since version QGIS: 3.14 this is now done automatically
loadFieldNames(self, fields:
QgsFields
)Deprecated since version QGIS: 3.14 use
expressionTree()
->:py:func:~QgsExpressionBuilderWidget.loadFieldNames instead
- loadFieldsAndValues(self, fieldValues: Dict[str, Iterable[str]])¶
Loads field names and values from the specified map.
New in version 2.12.
Deprecated since version QGIS: 3.14 this will not do anything, use
setLayer()
instead- Parameters
fieldValues (Dict[str) –
- loadFunctionCode(self, code: str)¶
Loads 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”.Deprecated since version QGIS: 3.14 use
expressionTree()
->:py:func:~QgsExpressionBuilderWidget.loadRecent instead- Parameters
collection (str = '') –
- loadSampleUsedValues(self)¶
Load used sample values into the sample value area. Only the used ones. Without available values, even if the formatter can provide them (eg. RelationReference).
New in version 3.12.
- loadSampleValues(self)¶
Load sample values into the sample value area. Including available values, in case the formatter can provide them (eg. RelationReference).
- loadUserExpressions(self)¶
Loads the user expressions.
Deprecated since version QGIS: 3.14 use
expressionTree()
->:py:func:~QgsExpressionBuilderWidget.loadUserExpressions insteadNew in version 3.12.
- metric(self, QPaintDevice.PaintDeviceMetric) int ¶
- 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.
Deprecated since version QGIS: 3.14
- Return type
QStandardItemModel
- mouseDoubleClickEvent(self, QMouseEvent)¶
- mouseMoveEvent(self, QMouseEvent)¶
- mousePressEvent(self, QMouseEvent)¶
- mouseReleaseEvent(self, QMouseEvent)¶
- moveEvent(self, QMoveEvent)¶
- nativeEvent(self, Union[QByteArray, bytes, bytearray], sip.voidptr) Tuple[bool, int] ¶
- newFunctionFile(self, fileName: str = '')¶
Creates a new file in the function editor
- Parameters
fileName (str = '') –
- paintEvent(self, QPaintEvent)¶
- 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
New in version 3.0.
- Return type
- receivers(self, PYQT_SIGNAL) int ¶
- removeFromUserExpressions(self, label: str)¶
Removes the expression
label
from the user stored expressions.Deprecated since version QGIS: 3.14 use
expressionTree()
->:py:func:~QgsExpressionBuilderWidget.removeFromUserExpressions insteadNew in version 3.12.
- Parameters
label (str) –
- removeSelectedUserExpression(self)¶
Removes the selected expression from the stored user expressions, the selected expression must be a user stored expression.
New in version 3.12.
- resizeEvent(self, QResizeEvent)¶
- saveFunctionFile(self, fileName: str)¶
Saves 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”.Deprecated since version QGIS: 3.14 use
expressionTree()
->:py:func:~QgsExpressionBuilderWidget.saveRecent instead- Parameters
collection (str = '') –
- saveToUserExpressions(self, label: str, expression: str, helpText: str)¶
Stores the user
expression
with givenlabel
andhelpText
.Deprecated since version QGIS: 3.14 use
expressionTree()
->:py:func:~QgsExpressionBuilderWidget.saveToUserExpressions insteadNew in version 3.12.
- Parameters
label (str) –
expression (str) –
helpText (str) –
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- 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 to populate the list of available functions and variables.
- Parameters
context (QgsExpressionContext) – expression context
See also
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
New in version 3.0.
- Parameters
project (QgsProject) –
- showEvent(self, e: QShowEvent)¶
- Parameters
e (QShowEvent) –
- storeCurrentUserExpression(self)¶
Adds the current expressions to the stored user expressions.
New in version 3.12.
- tabletEvent(self, QTabletEvent)¶
- timerEvent(self, QTimerEvent)¶
- updateFunctionFileList(self, path: str)¶
Updates the list of function files found at the given path
- Parameters
path (str) –
- updateMicroFocus(self)¶
- wheelEvent(self, QWheelEvent)¶