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
(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)¶
-
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. *
-
findExpressions
(self, label: str) → List[QgsExpressionItem]¶ Returns the list of expression items matching a
label
.New in version 3.12.
- 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)¶
-
initPainter
(self, QPainter)¶
-
inputMethodEvent
(self, QInputMethodEvent)¶
-
isExpressionValid
(self) → bool¶ - Return type
bool
-
isSignalConnected
(self, QMetaMethod) → bool¶
-
keyPressEvent
(self, QKeyEvent)¶
-
keyReleaseEvent
(self, QKeyEvent)¶
-
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)¶ 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)¶ 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”.- 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.
New 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.
- 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¶
-
registerItem
(self, group: str, label: str, expressionText: str, helpText: str = '', type: QgsExpressionItem.ItemType = QgsExpressionItem.ExpressionNode, highlightedItem: bool = False, sortOrder: int = 1, icon: QIcon = QIcon(), tags: Iterable[str] = [])¶ 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 exist 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 levelsortOrder (int = 1) – sort ranking for item
icon (QIcon = QIcon()) – custom icon to show for item
tags (Iterable[str] = []) – tags to find function
-
removeFromUserExpressions
(self, label: str)¶ Removes the expression
label
from the user stored expressions.New 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”.- Parameters
collection (str = '') –
-
saveToUserExpressions
(self, label: str, expression: str, helpText: str)¶ Stores the user
expression
with givenlabel
andhelpText
.New 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 for populating 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)¶