QGIS API Documentation 3.41.0-Master (3440c17df1d)
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
34
35#ifndef SIP_RUN
36
40class GUI_EXPORT QgsQueryResultItemDelegate: public QStyledItemDelegate
41{
42 Q_OBJECT
43
44 // QStyledItemDelegate interface
45 public:
46
47 explicit QgsQueryResultItemDelegate( QObject *parent = nullptr );
48
49 QString displayText( const QVariant &value, const QLocale &locale ) const override;
50};
51
56class GUI_EXPORT QgsConnectionsApiFetcher: public QObject
57{
58 Q_OBJECT
59
60 public:
61
63 QgsConnectionsApiFetcher( const QString &uri, const QString &providerKey )
64 : mUri( uri )
65 , mProviderKey( providerKey )
66 {}
67
69 void fetchTokens();
70
72 void stopFetching();
73
74 signals:
75
77 void tokensReady( const QStringList &newTokens );
78
80 void fetchingFinished();
81
82 private:
83
84 QString mUri;
85 QString mProviderKey;
86 QAtomicInt mStopFetching = 0;
87 std::unique_ptr< QgsFeedback > mFeedback;
88
89};
90
91#endif
92
94
110class GUI_EXPORT QgsQueryResultWidget: public QWidget, private Ui::QgsQueryResultWidgetBase
111{
112 Q_OBJECT
113
114 public:
115
116
120 enum class QueryWidgetMode : int SIP_ENUM_BASETYPE( IntFlag )
121 {
122 SqlQueryMode = 1 << 0,
123 QueryLayerUpdateMode = 1 << 1,
124 };
125 Q_ENUM( QueryWidgetMode )
126
127
130 QgsQueryResultWidget( QWidget *parent = nullptr, QgsAbstractDatabaseProviderConnection *connection SIP_TRANSFER = nullptr );
131
132 virtual ~QgsQueryResultWidget();
133
137 void setSqlVectorLayerOptions( const QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions &options );
138
142 void setWidgetMode( QueryWidgetMode widgetMode );
143
147 void setConnection( QgsAbstractDatabaseProviderConnection *connection SIP_TRANSFER );
148
152 void setQuery( const QString &sql );
153
154
155 public slots:
156
160 void notify( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::MessageLevel::Info );
161
165 void executeQuery();
166
171 void showError( const QString &title, const QString &message, bool isSqlError = false );
172
176 void tokensReady( const QStringList &tokens );
177
183 void copyResults();
184
190 void copyResults( int fromRow, int toRow, int fromColumn, int toColumn );
191
192 signals:
193
200 void createSqlVectorLayer( const QString &providerKey, const QString &connectionUri, const QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions &options );
201
206 void firstResultBatchFetched();
207
208 private slots:
209
213 void updateButtons();
214
215 void showCellContextMenu( QPoint point );
216
217 void copySelection();
218
219 private:
220
221 QgsCodeEditorWidget *mCodeEditorWidget = nullptr;
222 QgsCodeEditorSQL *mSqlEditor = nullptr;
223
224 std::unique_ptr<QgsAbstractDatabaseProviderConnection> mConnection;
225 std::unique_ptr<QgsQueryResultModel> mModel;
226 std::unique_ptr<QgsFeedback> mFeedback;
227
228 QPointer< QgsConnectionsApiFetcher > mApiFetcher;
229
230 bool mWasCanceled = false;
232 bool mFirstRowFetched = false;
233 QFutureWatcher<QgsAbstractDatabaseProviderConnection::QueryResult> mQueryResultWatcher;
234 QString mSqlErrorMessage;
235 long long mActualRowCount = -1;
236 long long mFetchedRowsBatchCount = 0;
237 QueryWidgetMode mQueryWidgetMode = QueryWidgetMode::SqlQueryMode;
238 long long mCurrentHistoryEntryId = -1;
239
243 void updateSqlLayerColumns();
244
248 void cancelRunningQuery();
249
253 void cancelApiFetcher();
254
258 void startFetching();
259
264
265
266 friend class TestQgsQueryResultWidget;
267
268};
269
270#endif // QGSQUERYRESULTWIDGET_H
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:154
@ Info
Information message.
Definition qgis.h:155
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
A SQL editor based on QScintilla2.
A widget which wraps a QgsCodeEditor in additional functionality.
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_TRANSFER
Definition qgis_sip.h:36
The SqlVectorLayerOptions stores all information required to create a SQL (query) layer.