Class: QgsExpressionTreeView

A tree view to list all expressions functions, variables and fields that can be used in an expression.

Added in version 3.14.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsExpressionTreeView

Base classes

QTreeView

QAbstractItemView

QAbstractScrollArea

QFrame

QWidget

QObject

QPaintDevice

class qgis.gui.QgsExpressionTreeView[source]

Bases: QTreeView

__init__(parent: QWidget | None = None)

Constructor

Parameters:

parent (Optional[QWidget] = None)

class MenuProvider[source]

Bases: object

Implementation of this interface can be implemented to allow QgsExpressionTreeView instance 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.

Return type:

QgsExpressionContext

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:

List[QgsExpressionItem]

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

setProject()

Return type:

Optional[QgsProject]

refresh(self)[source]

Refreshes the content of the tree

removeFromUserExpressions(self, label: str | None)[source]

Removes the expression label from 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 expression with given label and helpText.

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

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 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()

Parameters:

project (Optional[QgsProject])

setSearchText(self, text: str | None)[source]

Sets the text to filter the expression tree

Parameters:

text (Optional[str])