Class: QgsQueryBuilder

Query Builder for layers.

The query builder allows interactive creation of a SQL for limiting the features displayed in a vector layer. The fields in the table are displayed and sample values (or all values) can be viewed to aid in constructing the query. A test function returns the number of features that will be returned.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsQueryBuilder

Base classes

QgsSubsetStringEditorInterface

Interface for a dialog that can edit subset strings.

QDialog

QWidget

QObject

QPaintDevice

class qgis.gui.QgsQueryBuilder[source]

Bases: QgsSubsetStringEditorInterface

__init__(layer: QgsVectorLayer | None, parent: QWidget | None = None, fl: Qt.WindowFlags | Qt.WindowType = QgsGuiUtils.ModalDialogFlags)

This constructor is used when the query builder is called from the vector layer properties dialog

Parameters:
  • layer (Optional[QgsVectorLayer]) – existing vector layer

  • parent (Optional[QWidget] = None) – Parent widget

  • fl (Union[Qt.WindowFlags, Qt.WindowType] = QgsGuiUtils.ModalDialogFlags) – dialog flags

clear(self)[source]
codeEditorWidget(self) QgsCodeEditor | None[source]

Returns the code editor widget for the SQL.

Added in version 3.18.

Return type:

Optional[QgsCodeEditor]

loadQuery(self)[source]

Load query from the XML file

Added in version 3.16.

static loadQueryFromFile(subset: str | None) bool[source]

Load query from the XML file

Added in version 3.26.

Parameters:

subset (Optional[str])

Return type:

bool

saveQuery(self)[source]

Save query to the XML file

Added in version 3.16.

static saveQueryToFile(subset: str | None) bool[source]

Save query to the XML file

Added in version 3.26.

Parameters:

subset (Optional[str])

Return type:

bool

setDatasourceDescription(self, uri: str | None)[source]
Parameters:

uri (Optional[str])

setSql(self, sqlStatement: str | None)[source]

Set the sql statement to display in the dialog.

Parameters:

sqlStatement (Optional[str])

sql(self) str[source]

Returns the sql statement entered in the dialog.

Return type:

str

virtual test(self)[source]

The default implementation tests that the constructed sql statement to see if the vector layer data provider likes it. The number of rows that would be returned is displayed in a message box. The test uses a “select count(*) from …” query to test the SQL statement.