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¶
Base classes¶
Interface for a dialog that can edit subset strings. |
|
Methods
Returns the code editor widget for the SQL. |
|
Load query from the XML file |
|
Save query to the XML file |
|
Set the sql statement to display in the dialog. |
|
Returns the sql statement entered in the dialog. |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsQueryBuilder. See the FAQ for more details.
The default implementation tests that the constructed sql statement to see if the vector layer data provider likes it. |
Static Methods
Load query from the XML file |
|
Save query to the XML file |
- 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
- codeEditorWidget(self) QgsCodeEditor | None [source]¶
Returns the code editor widget for the SQL.
Added in version 3.18.
- Return type:
Optional[QgsCodeEditor]
- 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
- 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
- setSql(self, sqlStatement: str | None)[source]¶
Set the sql statement to display in the dialog.
- Parameters:
sqlStatement (Optional[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
- QgsQueryBuilder.test(*) from ..." query to test the SQL statement.
test(*) from …” query to test the SQL statement.