Class: QgsExpressionTreeView

class qgis.gui.QgsExpressionTreeView(parent: QWidget = None)

Bases: PyQt5.QtWidgets.QTreeView

Constructor

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

Methods

actionEvent

changeEvent

childEvent

closeEditor

closeEvent

columnCountChanged

columnMoved

columnResized

commitData

connectNotify

contextMenuEvent

create

currentChanged

currentItem

Returns the current item or a None

customEvent

destroy

dirtyRegionOffset

disconnectNotify

dragEnterEvent

dragLeaveEvent

dragMoveEvent

drawBranches

drawFrame

drawRow

drawTree

dropEvent

dropIndicatorPosition

edit

editorDestroyed

enterEvent

event

eventFilter

executeDelayedItemsLayout

exportUserExpressions

Create the expressions JSON document storing all the user expressions to be exported.

expressionContext

Returns the expression context for the widget.

findExpressions

Returns the list of expression items matching a label.

focusInEvent

focusNextChild

focusNextPrevChild

focusOutEvent

focusPreviousChild

hideEvent

horizontalOffset

horizontalScrollbarAction

horizontalScrollbarValueChanged

indexRowSizeHint

initPainter

initStyleOption

inputMethodEvent

isIndexHidden

isSignalConnected

keyPressEvent

keyReleaseEvent

leaveEvent

loadExpressionsFromJson

Load and permanently store the expressions from the expressions JSON document.

loadFieldNames

This allows loading fields without specifying a layer

loadRecent

Loads the recent expressions from the given collection.

loadUserExpressions

Loads the user expressions.

metric

mouseDoubleClickEvent

mouseMoveEvent

mousePressEvent

mouseReleaseEvent

moveCursor

moveEvent

nativeEvent

paintEvent

project

Returns the project currently associated with the widget.

receivers

reexpand

refresh

Refreshes the content of the tree

removeFromUserExpressions

Removes the expression label from the user stored expressions.

resizeEvent

rowHeight

rowsAboutToBeRemoved

rowsInserted

rowsRemoved

saveToRecent

Adds the current expression to the given collection.

saveToUserExpressions

Stores the user expression with given label and helpText.

scheduleDelayedItemsLayout

scrollContentsBy

scrollDirtyRegion

selectedIndexes

selectionChanged

selectionCommand

sender

senderSignalIndex

setDirtyRegion

setExpressionContext

Sets the expression context for the tree view.

setLayer

Sets layer in order to get the fields and values

setMenuProvider

Sets the menu provider.

setProject

Sets the project currently associated with the widget.

setSearchText

Sets the text to filter the expression tree

setSelection

setState

setViewportMargins

sharedPainter

showEvent

sizeHintForColumn

startDrag

state

tabletEvent

timerEvent

updateEditorData

updateEditorGeometries

updateGeometries

updateMicroFocus

verticalOffset

verticalScrollbarAction

verticalScrollbarValueChanged

viewOptions

viewportEvent

viewportMargins

viewportSizeHint

visualRegionForSelection

wheelEvent

Signals

currentExpressionItemChanged

Emitter when the current expression item changed [signal]

expressionItemDoubleClicked

Emitted when a expression item is double clicked [signal]

class MenuProvider

Bases: sip.wrapper

Constructor

QgsExpressionTreeView.MenuProvider(QgsExpressionTreeView.MenuProvider)

Implementation of this interface can be implemented to allow QgsExpressionTreeView instance to provide custom context menus (opened upon right-click).

New in version 3.14.

createContextMenu(self, item: QgsExpressionItem)QMenu

Returns a newly created menu instance

Parameters

item (QgsExpressionItem) –

Return type

QMenu

actionEvent(self, QActionEvent)
changeEvent(self, QEvent)
childEvent(self, QChildEvent)
closeEditor(self, QWidget, QAbstractItemDelegate.EndEditHint)
closeEvent(self, QCloseEvent)
QgsExpressionTreeView.columnCountChanged(self, int, int)
columnMoved(self)
QgsExpressionTreeView.columnResized(self, int, int, int)
commitData(self, QWidget)
connectNotify(self, QMetaMethod)
contextMenuEvent(self, QContextMenuEvent)
create(self, window: sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)
QgsExpressionTreeView.currentChanged(self, QModelIndex, QModelIndex)
currentExpressionItemChanged

Emitter when the current expression item changed [signal]

Parameters

item (QgsExpressionItem) –

currentItem(self)QgsExpressionItem

Returns the current item or a None

Return type

QgsExpressionItem

customEvent(self, QEvent)
destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)
dirtyRegionOffset(self)QPoint
disconnectNotify(self, QMetaMethod)
dragEnterEvent(self, QDragEnterEvent)
dragLeaveEvent(self, QDragLeaveEvent)
dragMoveEvent(self, QDragMoveEvent)
drawBranches(self, QPainter, QRect, QModelIndex)
drawFrame(self, QPainter)
drawRow(self, QPainter, QStyleOptionViewItem, QModelIndex)
drawTree(self, QPainter, QRegion)
dropEvent(self, QDropEvent)
dropIndicatorPosition(self)QAbstractItemView.DropIndicatorPosition
edit(self, QModelIndex)
edit(self, QModelIndex, QAbstractItemView.EditTrigger, QEvent)bool
editorDestroyed(self, QObject)
enterEvent(self, QEvent)
event(self, QEvent)bool
eventFilter(self, QObject, QEvent)bool
executeDelayedItemsLayout(self)
exportUserExpressions(self)QJsonDocument

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

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

expressionItemDoubleClicked

Emitted when a expression item is double clicked [signal]

Parameters

text (str) –

findExpressions(self, label: str)List[QgsExpressionItem]

Returns the list of expression items matching a label.

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)
horizontalOffset(self)int
horizontalScrollbarAction(self, int)
horizontalScrollbarValueChanged(self, int)
indexRowSizeHint(self, QModelIndex)int
initPainter(self, QPainter)
initStyleOption(self, QStyleOptionFrame)
inputMethodEvent(self, QInputMethodEvent)
isIndexHidden(self, QModelIndex)bool
isSignalConnected(self, QMetaMethod)bool
keyPressEvent(self, QKeyEvent)
keyReleaseEvent(self, QKeyEvent)
leaveEvent(self, QEvent)
loadExpressionsFromJson(self, expressionsDocument: QJsonDocument)

Load and permanently store the expressions from the expressions JSON document.

Parameters

expressionsDocument (QJsonDocument) – the parsed expressions JSON file

loadFieldNames(self, fields: QgsFields)

This allows loading fields without specifying a layer

Parameters

fields (QgsFields) –

loadRecent(self, collection: str = '')

Loads the recent expressions from the given collection. By default it is loaded from the collection “generic”.

Parameters

collection (str = '') –

loadUserExpressions(self)

Loads the user expressions. This is done on request since it can be very slow if there are thousands of user expressions

metric(self, QPaintDevice.PaintDeviceMetric)int
mouseDoubleClickEvent(self, QMouseEvent)
mouseMoveEvent(self, QMouseEvent)
mousePressEvent(self, QMouseEvent)
mouseReleaseEvent(self, QMouseEvent)
moveCursor(self, QAbstractItemView.CursorAction, Union[Qt.KeyboardModifiers, Qt.KeyboardModifier])QModelIndex
moveEvent(self, QMoveEvent)
nativeEvent(self, Union[QByteArray, bytes, bytearray], sip.voidptr)Tuple[bool, int]
paintEvent(self, QPaintEvent)
project(self)QgsProject

Returns the project currently associated with the widget.

See also

setProject()

Return type

QgsProject

receivers(self, PYQT_SIGNAL)int
reexpand(self)
refresh(self)

Refreshes the content of the tree

removeFromUserExpressions(self, label: str)

Removes the expression label from the user stored expressions.

Parameters

label (str) –

resizeEvent(self, QResizeEvent)
rowHeight(self, QModelIndex)int
QgsExpressionTreeView.rowsAboutToBeRemoved(self, QModelIndex, int, int)
QgsExpressionTreeView.rowsInserted(self, QModelIndex, int, int)
QgsExpressionTreeView.rowsRemoved(self, QModelIndex, int, int)
saveToRecent(self, expressionText: str, collection: str = '')

Adds the current expression to the given collection. By default it is saved to the collection “generic”.

Parameters
  • expressionText (str) –

  • collection (str = '') –

saveToUserExpressions(self, label: str, expression: str, helpText: str)

Stores the user expression with given label and helpText.

Parameters
  • label (str) –

  • expression (str) –

  • helpText (str) –

scheduleDelayedItemsLayout(self)
QgsExpressionTreeView.scrollContentsBy(self, int, int)
QgsExpressionTreeView.scrollDirtyRegion(self, int, int)
selectedIndexes(self)List[QModelIndex]
QgsExpressionTreeView.selectionChanged(self, QItemSelection, QItemSelection)
selectionCommand(self, QModelIndex, event: QEvent = None)QItemSelectionModel.SelectionFlags
sender(self)QObject
senderSignalIndex(self)int
setDirtyRegion(self, QRegion)
setExpressionContext(self, context: QgsExpressionContext)

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)

Sets layer in order to get the fields and values

Parameters

layer (QgsVectorLayer) –

setMenuProvider(self, provider: QgsExpressionTreeView.MenuProvider)

Sets the menu provider. This does not take ownership of the provider

Parameters

provider (QgsExpressionTreeView.MenuProvider) –

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

project()

Parameters

project (QgsProject) –

setSearchText(self, text: str)

Sets the text to filter the expression tree

Parameters

text (str) –

setSelection(self, QRect, Union[QItemSelectionModel.SelectionFlags, QItemSelectionModel.SelectionFlag])
setState(self, QAbstractItemView.State)
QgsExpressionTreeView.setViewportMargins(self, int, int, int, int)
setViewportMargins(self, QMargins)None
sharedPainter(self)QPainter
showEvent(self, QShowEvent)
sizeHintForColumn(self, int)int
startDrag(self, Union[Qt.DropActions, Qt.DropAction])
state(self)QAbstractItemView.State
tabletEvent(self, QTabletEvent)
timerEvent(self, QTimerEvent)
updateEditorData(self)
updateEditorGeometries(self)
updateGeometries(self)
updateMicroFocus(self)
verticalOffset(self)int
verticalScrollbarAction(self, int)
verticalScrollbarValueChanged(self, int)
viewOptions(self)QStyleOptionViewItem
viewportEvent(self, QEvent)bool
viewportMargins(self)QMargins
viewportSizeHint(self)QSize
visualRegionForSelection(self, QItemSelection)QRegion
wheelEvent(self, QWheelEvent)