QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsqueryresultwidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsqueryresultwidget.h - QgsQueryResultWidget
3
4 ---------------------
5 begin : 14.1.2021
6 copyright : (C) 2021 by elpaso
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSQUERYRESULTWIDGET_H
17#define QGSQUERYRESULTWIDGET_H
18
19#include "qgis_gui.h"
20#include "qgis_sip.h"
21#include "ui_qgsqueryresultwidgetbase.h"
23#include "qgsqueryresultmodel.h"
24#include "qgsfeedback.h"
25
26#include <QWidget>
27#include <QThread>
28#include <QtConcurrent>
29#include <QStyledItemDelegate>
30
32
33#ifndef SIP_RUN
34
38class GUI_EXPORT QgsQueryResultItemDelegate: public QStyledItemDelegate
39{
40 Q_OBJECT
41
42 // QStyledItemDelegate interface
43 public:
44
45 explicit QgsQueryResultItemDelegate( QObject *parent = nullptr );
46
47 QString displayText( const QVariant &value, const QLocale &locale ) const override;
48};
49
54class GUI_EXPORT QgsConnectionsApiFetcher: public QObject
55{
56 Q_OBJECT
57
58 public:
59
61 QgsConnectionsApiFetcher( const QString &uri, const QString &providerKey )
62 : mUri( uri )
63 , mProviderKey( providerKey )
64 {}
65
67 void fetchTokens();
68
70 void stopFetching();
71
72 signals:
73
75 void tokensReady( const QStringList &newTokens );
76
78 void fetchingFinished();
79
80 private:
81
82 QString mUri;
83 QString mProviderKey;
84 QAtomicInt mStopFetching = 0;
85 std::unique_ptr< QgsFeedback > mFeedback;
86
87};
88
89#endif
90
92
108class GUI_EXPORT QgsQueryResultWidget: public QWidget, private Ui::QgsQueryResultWidgetBase
109{
110 Q_OBJECT
111
112 public:
113
114
118 enum class QueryWidgetMode : int
119 {
120 SqlQueryMode = 1 << 0,
121 QueryLayerUpdateMode = 1 << 1,
122 };
123 Q_ENUM( QueryWidgetMode )
124
125
128 QgsQueryResultWidget( QWidget *parent = nullptr, QgsAbstractDatabaseProviderConnection *connection SIP_TRANSFER = nullptr );
129
130 virtual ~QgsQueryResultWidget();
131
135 void setSqlVectorLayerOptions( const QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions &options );
136
140 void setWidgetMode( QueryWidgetMode widgetMode );
141
145 void setConnection( QgsAbstractDatabaseProviderConnection *connection SIP_TRANSFER );
146
150 void setQuery( const QString &sql );
151
152
153 public slots:
154
158 void notify( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::MessageLevel::Info );
159
163 void executeQuery();
164
169 void showError( const QString &title, const QString &message, bool isSqlError = false );
170
174 void tokensReady( const QStringList &tokens );
175
181 void copyResults();
182
188 void copyResults( int fromRow, int toRow, int fromColumn, int toColumn );
189
190 signals:
191
198 void createSqlVectorLayer( const QString &providerKey, const QString &connectionUri, const QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions &options );
199
204 void firstResultBatchFetched();
205
206 private slots:
207
211 void updateButtons();
212
213 void showCellContextMenu( QPoint point );
214
215 void copySelection();
216
217 private:
218
219 std::unique_ptr<QgsAbstractDatabaseProviderConnection> mConnection;
220 std::unique_ptr<QgsQueryResultModel> mModel;
221 std::unique_ptr<QgsFeedback> mFeedback;
222
223 QPointer< QgsConnectionsApiFetcher > mApiFetcher;
224
225 bool mWasCanceled = false;
227 bool mFirstRowFetched = false;
228 QFutureWatcher<QgsAbstractDatabaseProviderConnection::QueryResult> mQueryResultWatcher;
229 QString mSqlErrorMessage;
230 long long mActualRowCount = -1;
231 long long mFetchedRowsBatchCount = 0;
232 QueryWidgetMode mQueryWidgetMode = QueryWidgetMode::SqlQueryMode;
233 long long mCurrentHistoryEntryId = -1;
234
238 void updateSqlLayerColumns();
239
243 void cancelRunningQuery();
244
248 void cancelApiFetcher();
249
253 void startFetching();
254
259
260
261 friend class TestQgsQueryResultWidget;
262
263};
264
265#endif // QGSQUERYRESULTWIDGET_H
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:99
@ Info
Information message.
Definition qgis.h:100
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
#define SIP_TRANSFER
Definition qgis_sip.h:36
The SqlVectorLayerOptions stores all information required to create a SQL (query) layer.