QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
Public Types | Public Slots | Signals | Public Member Functions | Friends | List of all members
QgsQueryResultWidget Class Reference

The QgsQueryResultWidget class allows users to enter and run an SQL query on a DB connection (an instance of QgsAbstractDatabaseProviderConnection). More...

#include <qgsqueryresultwidget.h>

Inheritance diagram for QgsQueryResultWidget:
Inheritance graph
[legend]

Public Types

enum  QueryWidgetMode : int { QueryWidgetMode::SqlQueryMode = 1 << 0, QueryWidgetMode::QueryLayerUpdateMode = 1 << 1 }
 The QueryWidgetMode enum represents various modes for the widget appearance. More...
 

Public Slots

void executeQuery ()
 Starts executing the query. More...
 
void notify (const QString &title, const QString &text, Qgis::MessageLevel level=Qgis::MessageLevel::Info)
 Displays a message with text title and level in the widget's message bar. More...
 
void showError (const QString &title, const QString &message, bool isSqlError=false)
 Hides the result table and shows the error title and message in the message bar or in the SQL error panel is isSqlError is set. More...
 
void tokensReady (const QStringList &tokens)
 Triggered when the threaded API fetcher has new tokens to add. More...
 

Signals

void createSqlVectorLayer (const QString &providerKey, const QString &connectionUri, const QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions &options)
 Emitted when a new vector SQL (query) layer must be created. More...
 
void firstResultBatchFetched ()
 Emitted when the first batch of results has been fetched. More...
 

Public Member Functions

 QgsQueryResultWidget (QWidget *parent=nullptr, QgsAbstractDatabaseProviderConnection *connection=nullptr)
 Creates a QgsQueryResultWidget with the given connection, ownership is transferred to the widget. More...
 
virtual ~QgsQueryResultWidget ()
 
void setConnection (QgsAbstractDatabaseProviderConnection *connection)
 Sets the connection to connection, ownership is transferred to the widget. More...
 
void setQuery (const QString &sql)
 Convenience method to set the SQL editor text to sql. More...
 
void setSqlVectorLayerOptions (const QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions &options)
 Initializes the widget from options. More...
 
void setWidgetMode (QueryWidgetMode widgetMode)
 Sets the widget mode to widgetMode, default is SqlQueryMode. More...
 

Friends

class TestQgsQueryResultWidget
 

Detailed Description

The QgsQueryResultWidget class allows users to enter and run an SQL query on a DB connection (an instance of QgsAbstractDatabaseProviderConnection).

Query results are displayed in a table view. Query execution and result fetching can be interrupted by pressing the "Stop" push button.

The widget supports a few QueryWidgetMode modes that pre-configure the widget appearance to be used in different contexts like when updating the SQL of an existing query layer.

Note
the ownership of the connection is transferred to the widget.
Since
QGIS 3.22

Definition at line 105 of file qgsqueryresultwidget.h.

Member Enumeration Documentation

◆ QueryWidgetMode

The QueryWidgetMode enum represents various modes for the widget appearance.

Enumerator
SqlQueryMode 

Defaults widget mode for SQL execution and SQL query layer creation.

QueryLayerUpdateMode 

SQL query layer update mode: the create SQL layer button is renamed to 'Update' and the SQL layer creation group box is expanded.

Definition at line 129 of file qgsqueryresultwidget.h.

Constructor & Destructor Documentation

◆ QgsQueryResultWidget()

QgsQueryResultWidget::QgsQueryResultWidget ( QWidget *  parent = nullptr,
QgsAbstractDatabaseProviderConnection connection = nullptr 
)

Creates a QgsQueryResultWidget with the given connection, ownership is transferred to the widget.

Definition at line 24 of file qgsqueryresultwidget.cpp.

◆ ~QgsQueryResultWidget()

QgsQueryResultWidget::~QgsQueryResultWidget ( )
virtual

Definition at line 103 of file qgsqueryresultwidget.cpp.

Member Function Documentation

◆ createSqlVectorLayer

void QgsQueryResultWidget::createSqlVectorLayer ( const QString &  providerKey,
const QString &  connectionUri,
const QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions options 
)
signal

Emitted when a new vector SQL (query) layer must be created.

Parameters
providerKeyname of the data provider
connectionUrithe connection URI as returned by QgsAbstractProviderConnection::uri()
options

◆ executeQuery

void QgsQueryResultWidget::executeQuery ( )
slot

Starts executing the query.

Definition at line 151 of file qgsqueryresultwidget.cpp.

◆ firstResultBatchFetched

void QgsQueryResultWidget::firstResultBatchFetched ( )
signal

Emitted when the first batch of results has been fetched.

Note
If the query returns no results this signal is not emitted.

◆ notify

void QgsQueryResultWidget::notify ( const QString &  title,
const QString &  text,
Qgis::MessageLevel  level = Qgis::MessageLevel::Info 
)
slot

Displays a message with text title and level in the widget's message bar.

Definition at line 432 of file qgsqueryresultwidget.cpp.

◆ setConnection()

void QgsQueryResultWidget::setConnection ( QgsAbstractDatabaseProviderConnection connection)

Sets the connection to connection, ownership is transferred to the widget.

Definition at line 389 of file qgsqueryresultwidget.cpp.

◆ setQuery()

void QgsQueryResultWidget::setQuery ( const QString &  sql)

Convenience method to set the SQL editor text to sql.

Definition at line 427 of file qgsqueryresultwidget.cpp.

◆ setSqlVectorLayerOptions()

void QgsQueryResultWidget::setSqlVectorLayerOptions ( const QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions options)

Initializes the widget from options.

Definition at line 109 of file qgsqueryresultwidget.cpp.

◆ setWidgetMode()

void QgsQueryResultWidget::setWidgetMode ( QueryWidgetMode  widgetMode)

Sets the widget mode to widgetMode, default is SqlQueryMode.

Definition at line 133 of file qgsqueryresultwidget.cpp.

◆ showError

void QgsQueryResultWidget::showError ( const QString &  title,
const QString &  message,
bool  isSqlError = false 
)
slot

Hides the result table and shows the error title and message in the message bar or in the SQL error panel is isSqlError is set.

Definition at line 344 of file qgsqueryresultwidget.cpp.

◆ tokensReady

void QgsQueryResultWidget::tokensReady ( const QStringList &  tokens)
slot

Triggered when the threaded API fetcher has new tokens to add.

Definition at line 361 of file qgsqueryresultwidget.cpp.

Friends And Related Function Documentation

◆ TestQgsQueryResultWidget

friend class TestQgsQueryResultWidget
friend

Definition at line 252 of file qgsqueryresultwidget.h.


The documentation for this class was generated from the following files: