Class: QgsExpressionTreeView¶
A tree view to list all expressions functions, variables and fields that can be used in an expression.
See also
Added in version 3.14.
Class Hierarchy¶
Base classes¶
- class qgis.gui.QgsExpressionTreeView[source]¶
Bases:
QTreeView- __init__(parent: QWidget | None = None)
Constructor
- Parameters:
parent (Optional[QWidget] = None)
- class MenuProvider[source]¶
Bases:
objectImplementation of this interface can be implemented to allow
QgsExpressionTreeViewinstance to provide custom context menus (opened upon right-click).Added in version 3.14.
- virtual createContextMenu(self, item: QgsExpressionItem | None) QMenu | None[source]¶
Returns a newly created menu instance
- Parameters:
item (Optional[QgsExpressionItem])
- Return type:
Optional[QMenu]
- signal currentExpressionItemChanged[source]¶
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.
- currentItem(self) QgsExpressionItem | None[source]¶
Returns the current item or a None
- Return type:
Optional[QgsExpressionItem]
- exportUserExpressions(self) QJsonDocument[source]¶
Create the expressions JSON document storing all the user expressions to be exported.
- Return type:
QJsonDocument
- Returns:
the created expressions JSON file
- expressionContext(self) QgsExpressionContext[source]¶
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:
- signal expressionItemDoubleClicked[source]¶
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.
- findExpressions(self, label: str | None) List[QgsExpressionItem]¶
Returns the list of expression items matching a
label.- Parameters:
label (Optional[str])
- Return type:
- loadExpressionsFromJson(self, expressionsDocument: QJsonDocument)[source]¶
Load and permanently store the expressions from the expressions JSON document.
- Parameters:
expressionsDocument (QJsonDocument) – the parsed expressions JSON file
- loadFieldNames(self, fields: QgsFields)[source]¶
This allows loading fields without specifying a layer
- Parameters:
fields (QgsFields)
- loadRecent(self, collection: str | None = '')[source]¶
Loads the recent expressions from the given
collection. By default it is loaded from the collection “generic”.- Parameters:
collection (Optional[str] = '')
- loadUserExpressions(self)[source]¶
Loads the user expressions. This is done on request since it can be very slow if there are thousands of user expressions
- project(self) QgsProject | None[source]¶
Returns the project currently associated with the widget.
See also
- Return type:
Optional[QgsProject]
- removeFromUserExpressions(self, label: str | None)[source]¶
Removes the expression
labelfrom the user stored expressions.- Parameters:
label (Optional[str])
- saveToRecent(self, expressionText: str | None, collection: str | None = '')[source]¶
Adds the current expression to the given
collection. By default it is saved to the collection “generic”.- Parameters:
expressionText (Optional[str])
collection (Optional[str] = '')
- saveToUserExpressions(self, label: str | None, expression: str | None, helpText: str | None)[source]¶
Stores the user
expressionwith givenlabelandhelpText.- Parameters:
label (Optional[str])
expression (Optional[str])
helpText (Optional[str])
- setExpressionContext(self, context: QgsExpressionContext)[source]¶
Sets the expression context for the tree view. The context is used to populate the list of available functions and variables.
- Parameters:
context (QgsExpressionContext) – expression context
See also
- setLayer(self, layer: QgsVectorLayer | None)[source]¶
Sets layer in order to get the fields and values
- Parameters:
layer (Optional[QgsVectorLayer])
- setMenuProvider(self, provider: QgsExpressionTreeView.MenuProvider | None)[source]¶
Sets the menu provider. This does not take ownership of the provider
- Parameters:
provider (Optional[QgsExpressionTreeView.MenuProvider])
- setProject(self, project: QgsProject | None)[source]¶
Sets the
projectcurrently associated with the widget. This controls which layers and relations and other project-specific items are shown in the widget.See also
- Parameters:
project (Optional[QgsProject])