QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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 class  QueryWidgetMode : int { SqlQueryMode = 1 << 0 , QueryLayerUpdateMode = 1 << 1 }
 The QueryWidgetMode enum represents various modes for the widget appearance. More...
 

Public Slots

void copyResults ()
 Copies the query results to the clipboard, as a formatted table. More...
 
void copyResults (int fromRow, int toRow, int fromColumn, int toColumn)
 Copies a range of the query results to the clipboard, as a formatted table. More...
 
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 108 of file qgsqueryresultwidget.h.

Member Enumeration Documentation

◆ QueryWidgetMode

enum class QgsQueryResultWidget::QueryWidgetMode : int
strong

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 118 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 33 of file qgsqueryresultwidget.cpp.

◆ ~QgsQueryResultWidget()

QgsQueryResultWidget::~QgsQueryResultWidget ( )
virtual

Definition at line 118 of file qgsqueryresultwidget.cpp.

Member Function Documentation

◆ copyResults [1/2]

void QgsQueryResultWidget::copyResults ( )
slot

Copies the query results to the clipboard, as a formatted table.

Since
QGIS 3.32

Definition at line 449 of file qgsqueryresultwidget.cpp.

◆ copyResults [2/2]

void QgsQueryResultWidget::copyResults ( int  fromRow,
int  toRow,
int  fromColumn,
int  toColumn 
)
slot

Copies a range of the query results to the clipboard, as a formatted table.

Since
QGIS 3.32

Definition at line 456 of file qgsqueryresultwidget.cpp.

◆ 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 166 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 576 of file qgsqueryresultwidget.cpp.

◆ setConnection()

void QgsQueryResultWidget::setConnection ( QgsAbstractDatabaseProviderConnection connection)

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

Definition at line 528 of file qgsqueryresultwidget.cpp.

◆ setQuery()

void QgsQueryResultWidget::setQuery ( const QString &  sql)

Convenience method to set the SQL editor text to sql.

Definition at line 571 of file qgsqueryresultwidget.cpp.

◆ setSqlVectorLayerOptions()

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

Initializes the widget from options.

Definition at line 124 of file qgsqueryresultwidget.cpp.

◆ setWidgetMode()

void QgsQueryResultWidget::setWidgetMode ( QueryWidgetMode  widgetMode)

Sets the widget mode to widgetMode, default is SqlQueryMode.

Definition at line 148 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 426 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 443 of file qgsqueryresultwidget.cpp.

Friends And Related Function Documentation

◆ TestQgsQueryResultWidget

friend class TestQgsQueryResultWidget
friend

Definition at line 261 of file qgsqueryresultwidget.h.


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