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 whether the expression preview is visible.
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
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
Attributes
- class Flag¶
Bases:
int
- baseClass¶
alias of
QgsExpressionBuilderWidget
- class Flags¶
- class Flags(Union[QgsExpressionBuilderWidget.Flags, QgsExpressionBuilderWidget.Flag])
- class Flags(QgsExpressionBuilderWidget.Flags)
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: PyQt5.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.- Return type:
bool
- evalErrorChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_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
- Return type:
- expressionParsed¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_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: 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: 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: 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.
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.
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], PyQt5.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.- Return type:
bool
- parserErrorChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- project(self) QgsProject ¶
Returns the project currently associated with the widget.
See also
- 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
- setExpressionPreviewVisible(self, isVisible: bool)¶
Sets whether the expression preview is visible.
New in version 3.22.
- Parameters:
isVisible (bool) –
- 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
- 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)¶