Subgroup: Expression

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.

Methods

acceptDrops
accessibleDescription
accessibleName
actionEvent
actions
activateWindow
addAction
addActions
adjustSize
autoFillBackground
autosave Auto save the current Python function code.
backgroundRole
baseSize
blockSignals
changeEvent
childAt childAt(self, int, int) -> QWidget
childEvent
children
childrenRect
childrenRegion
clearFocus
clearMask
close
closeEvent
colorCount
connectNotify
contentsMargins
contentsRect
contextMenuEvent
contextMenuPolicy
create
createWindowContainer
cursor
customEvent
deleteLater
depth
destroy
devType
devicePixelRatio
devicePixelRatioF
devicePixelRatioFScale
disconnect
disconnectNotify
dragEnterEvent
dragLeaveEvent
dragMoveEvent
dropEvent
dumpObjectInfo
dumpObjectTree
dynamicPropertyNames
effectiveWinId
ensurePolished
enterEvent
evalError Will be set to true if the current expression text reported an eval error with the context.
event
eventFilter
expressionContext Returns the expression context for the widget.
expressionText Gets the expression string that has been set in the expression area.
find
findChild findChild(self, Tuple, name: str = ‘’, options: Union[Qt.FindChildOptions, Qt.FindChildOption] = Qt.FindChildrenRecursively) -> QObject
findChildren findChildren(self, Tuple, name: str = ‘’, options: Union[Qt.FindChildOptions, Qt.FindChildOption] = Qt.FindChildrenRecursively) -> List[QObject]
focusInEvent
focusNextChild
focusNextPrevChild
focusOutEvent
focusPolicy
focusPreviousChild
focusProxy
focusWidget
font
fontInfo
fontMetrics
foregroundRole
frameGeometry
frameSize
geometry
getContentsMargins
grab
grabGesture
grabKeyboard
grabMouse grabMouse(self, Union[QCursor, Qt.CursorShape])
grabShortcut
graphicsEffect
graphicsProxyWidget
hasFocus
hasHeightForWidth
hasMouseTracking
hasTabletTracking
height
heightForWidth
heightMM
hide
hideEvent
inherits
initPainter
inputMethodEvent
inputMethodHints
inputMethodQuery
insertAction
insertActions
installEventFilter
isActiveWindow
isAncestorOf
isEnabled
isEnabledTo
isExpressionValid
isFullScreen
isHidden
isLeftToRight
isMaximized
isMinimized
isModal
isRightToLeft
isSignalConnected
isVisible
isVisibleTo
isWidgetType
isWindow
isWindowModified
isWindowType
keyPressEvent
keyReleaseEvent
keyboardGrabber
killTimer
layout
layoutDirection
leaveEvent
loadAllValues Load all unique values from the set layer into the sample area
loadCodeFromFile Load code from the given file into the function editor
loadFieldNames Loads all the field names from the layer.
loadFieldsAndValues Loads field names and values from the specified map.
loadFunctionCode Load code into the function editor
loadRecent Loads the recent expressions from the given collection.
loadSampleValues Load sample values into the sample value area
locale
logicalDpiX
logicalDpiY
lower
mapFrom
mapFromGlobal
mapFromParent
mapTo
mapToGlobal
mapToParent
mask
maximumHeight
maximumSize
maximumWidth
metaObject
metric
minimumHeight
minimumSize
minimumSizeHint
minimumWidth
model Returns a pointer to the dialog’s function item model.
mouseDoubleClickEvent
mouseGrabber
mouseMoveEvent
mousePressEvent
mouseReleaseEvent
move move(self, int, int)
moveEvent
moveToThread
nativeEvent
nativeParentWidget
newFunctionFile Create a new file in the function editor
nextInFocusChain
normalGeometry
objectName
overrideWindowFlags
overrideWindowState
paintEngine
paintEvent
paintingActive
palette
parent
parentWidget
parserError Will be set to true if the current expression text reports a parser error with the context.
physicalDpiX
physicalDpiY
pos
previousInFocusChain
project Returns the project currently associated with the widget.
property
pyqtConfigure Each keyword argument is either the name of a Qt property or a Qt signal.
raise_
receivers
rect
registerItem Registers a node item for the expression builder.
releaseKeyboard
releaseMouse
releaseShortcut
removeAction
removeEventFilter
render render(self, QPainter, targetOffset: QPoint = QPoint(), sourceRegion: QRegion = QRegion(), flags: Union[QWidget.RenderFlags, QWidget.RenderFlag] = QWidget.RenderFlags(QWidget.DrawWindowBackground|QWidget.DrawChildren))
repaint repaint(self, int, int, int, int)
resize resize(self, int, int)
resizeEvent
restoreGeometry
saveFunctionFile Save the current function editor text to the given file.
saveGeometry
saveToRecent Adds the current expression to the given collection.
scroll scroll(self, int, int, QRect)
sender
senderSignalIndex
setAcceptDrops
setAccessibleDescription
setAccessibleName
setAttribute
setAutoFillBackground
setAutoSave Enabled or disable auto saving.
setBackgroundRole
setBaseSize setBaseSize(self, QSize)
setContentsMargins setContentsMargins(self, QMargins)
setContextMenuPolicy
setCursor
setDisabled
setEnabled
setExpressionContext Sets the expression context for the widget.
setExpressionText Sets the expression string for the widget
setFixedHeight
setFixedSize setFixedSize(self, int, int)
setFixedWidth
setFocus setFocus(self, Qt.FocusReason)
setFocusPolicy
setFocusProxy
setFont
setForegroundRole
setGeomCalculator Sets geometry calculator used in distance/area calculations.
setGeometry setGeometry(self, int, int, int, int)
setGraphicsEffect
setHidden
setInputMethodHints
setLayer Sets layer in order to get the fields and values
setLayout
setLayoutDirection
setLocale
setMask setMask(self, QRegion)
setMaximumHeight
setMaximumSize setMaximumSize(self, QSize)
setMaximumWidth
setMinimumHeight
setMinimumSize setMinimumSize(self, QSize)
setMinimumWidth
setMouseTracking
setObjectName
setPalette
setParent setParent(self, QWidget, Union[Qt.WindowFlags, Qt.WindowType])
setProject Sets the project currently associated with the widget.
setProperty
setShortcutAutoRepeat
setShortcutEnabled
setSizeIncrement setSizeIncrement(self, QSize)
setSizePolicy setSizePolicy(self, QSizePolicy.Policy, QSizePolicy.Policy)
setStatusTip
setStyle
setStyleSheet
setTabOrder
setTabletTracking
setToolTip
setToolTipDuration
setUpdatesEnabled
setVisible
setWhatsThis
setWindowFilePath
setWindowFlag
setWindowFlags
setWindowIcon
setWindowIconText
setWindowModality
setWindowModified
setWindowOpacity
setWindowRole
setWindowState
setWindowTitle
sharedPainter
show
showEvent
showFullScreen
showMaximized
showMinimized
showNormal
signalsBlocked
size
sizeHint
sizeIncrement
sizePolicy
stackUnder
startTimer
statusTip
style
styleSheet
tabletEvent
testAttribute
thread
timerEvent
toolTip
toolTipDuration
tr
underMouse
ungrabGesture
unsetCursor
unsetLayoutDirection
unsetLocale
update update(self, QRect)
updateFunctionFileList Update the list of function files found at the given path
updateGeometry
updateMicroFocus
updatesEnabled
visibleRegion
whatsThis
wheelEvent
width
widthMM
winId
window
windowFilePath
windowFlags
windowHandle
windowIcon
windowIconText
windowModality
windowOpacity
windowRole
windowState
windowTitle
windowType
x
y

Attributes

DrawChildren
DrawWindowBackground
IgnoreMask
PdmDepth
PdmDevicePixelRatio
PdmDevicePixelRatioScaled
PdmDpiX
PdmDpiY
PdmHeight
PdmHeightMM
PdmNumColors
PdmPhysicalDpiX
PdmPhysicalDpiY
PdmWidth
PdmWidthMM
customContextMenuRequested customContextMenuRequested(self, QPoint) [signal]
destroyed destroyed(self, QObject = None) [signal]
evalErrorChanged Will be set to true if the current expression text reported an eval error with the context.
expressionParsed Emitted when the user changes the expression in the widget.
objectNameChanged objectNameChanged(self, str) [signal]
parserErrorChanged Will be set to true if the current expression text reported a parser error with the context.
staticMetaObject
windowIconChanged windowIconChanged(self, QIcon) [signal]
windowIconTextChanged windowIconTextChanged(self, str) [signal]
windowTitleChanged windowTitleChanged(self, str) [signal]
actionEvent()
autosave(self)

Auto save the current Python function code.

changeEvent()
childEvent()
closeEvent()
connectNotify()
contextMenuEvent()
create()
customEvent()
destroy()
disconnectNotify()
dragEnterEvent()
dragLeaveEvent()
dragMoveEvent()
dropEvent()
enterEvent()
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.

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

New in version 2.12.

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 – 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.

Returns:The expression as a string. *
focusInEvent()
focusNextChild()
focusNextPrevChild()
focusOutEvent()
focusPreviousChild()
hideEvent()
initPainter()
inputMethodEvent()
isExpressionValid(self) → bool
isSignalConnected()
keyPressEvent()
keyReleaseEvent()
leaveEvent()
loadAllValues(self)

Load all unique values from the set layer into the sample area

loadCodeFromFile(self, path: str)

Load code from the given file into the function editor

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.

loadFunctionCode(self, code: str)

Load code into the function editor

loadRecent(self, collection: str = '')

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

loadSampleValues(self)

Load sample values into the sample value area

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

mouseDoubleClickEvent()
mouseMoveEvent()
mousePressEvent()
mouseReleaseEvent()
moveEvent()
nativeEvent()
newFunctionFile(self, fileName: str = '')

Create a new file in the function editor

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

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

setProject()

New in version 3.0.

receivers()
registerItem(self, group: str, label: str, expressionText: str, helpText: str = '', type: QgsExpressionItem.ItemType = QgsExpressionItem.ExpressionNode, highlightedItem: bool = False, sortOrder: int = 1)

Registers a node item for the expression builder.

Parameters:
  • group – The group the item will be show in the tree view. If the group doesn’t exsit it will be created.
  • label – The label that is show to the user for the item in the tree.
  • expressionText – The text that is inserted into the expression area when the user double clicks on the item.
  • helpText – The help text that the user will see when item is selected.
  • type – The type of the expression item.
  • highlightedItem – set to true to make the item highlighted, which inserts a bold copy of the item at the top level
  • sortOrder – sort ranking for item
resizeEvent()
saveFunctionFile(self, fileName: str)

Save the current function editor text to the given file.

saveToRecent(self, collection: str = '')

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

sender()
senderSignalIndex()
setAutoSave(self, enabled: bool)

Enabled or disable auto saving. When enabled Python scripts will be auto saved when text changes.

Parameters:enabled – True to enable auto saving.
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 – expression context

New in version 2.12.

setExpressionText(self, expression: str)

Sets the expression string for the widget

setGeomCalculator(self, da: QgsDistanceArea)

Sets geometry calculator used in distance/area calculations.

setLayer(self, layer: QgsVectorLayer)

Sets layer in order to get the fields and values

Note

this needs to be called before calling loadFieldNames().

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

New in version 3.0.

sharedPainter()
showEvent(self, e: QShowEvent)
tabletEvent()
timerEvent()
updateFunctionFileList(self, path: str)

Update the list of function files found at the given path

updateMicroFocus()
wheelEvent()