QGIS API Documentation 3.41.0-Master (57ec4277f5e)
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 explicit QgsQueryResultItemDelegate( QObject *parent = nullptr );
47
48 QString displayText( const QVariant &value, const QLocale &locale ) const override;
49};
50
55class GUI_EXPORT QgsConnectionsApiFetcher : public QObject
56{
57 Q_OBJECT
58
59 public:
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 QString mUri;
82 QString mProviderKey;
83 QAtomicInt mStopFetching = 0;
84 std::unique_ptr<QgsFeedback> mFeedback;
85};
86
87#endif
88
90
106class GUI_EXPORT QgsQueryResultWidget : public QWidget, private Ui::QgsQueryResultWidgetBase
107{
108 Q_OBJECT
109
110 public:
114 enum class QueryWidgetMode : int SIP_ENUM_BASETYPE( IntFlag )
115 {
116 SqlQueryMode = 1 << 0,
117 QueryLayerUpdateMode = 1 << 1,
118 };
119 Q_ENUM( QueryWidgetMode )
120
121
124 QgsQueryResultWidget( QWidget *parent = nullptr, QgsAbstractDatabaseProviderConnection *connection SIP_TRANSFER = nullptr );
125
126 virtual ~QgsQueryResultWidget();
127
131 void setSqlVectorLayerOptions( const QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions &options );
132
136 void setWidgetMode( QueryWidgetMode widgetMode );
137
141 void setConnection( QgsAbstractDatabaseProviderConnection *connection SIP_TRANSFER );
142
146 void setQuery( const QString &sql );
147
148
149 public slots:
150
154 void notify( const QString &title, const QString &text, Qgis::MessageLevel level = Qgis::MessageLevel::Info );
155
159 void executeQuery();
160
165 void showError( const QString &title, const QString &message, bool isSqlError = false );
166
170 void tokensReady( const QStringList &tokens );
171
177 void copyResults();
178
184 void copyResults( int fromRow, int toRow, int fromColumn, int toColumn );
185
186 signals:
187
194 void createSqlVectorLayer( const QString &providerKey, const QString &connectionUri, const QgsAbstractDatabaseProviderConnection::SqlVectorLayerOptions &options );
195
200 void firstResultBatchFetched();
201
202 private slots:
203
207 void updateButtons();
208
209 void showCellContextMenu( QPoint point );
210
211 void copySelection();
212
213 private:
214 QgsCodeEditorWidget *mCodeEditorWidget = nullptr;
215 QgsCodeEditorSQL *mSqlEditor = nullptr;
216
217 std::unique_ptr<QgsAbstractDatabaseProviderConnection> mConnection;
218 std::unique_ptr<QgsQueryResultModel> mModel;
219 std::unique_ptr<QgsFeedback> mFeedback;
220
221 QPointer<QgsConnectionsApiFetcher> mApiFetcher;
222
223 bool mWasCanceled = false;
225 bool mFirstRowFetched = false;
226 QFutureWatcher<QgsAbstractDatabaseProviderConnection::QueryResult> mQueryResultWatcher;
227 QString mSqlErrorMessage;
228 long long mActualRowCount = -1;
229 long long mFetchedRowsBatchCount = 0;
230 QueryWidgetMode mQueryWidgetMode = QueryWidgetMode::SqlQueryMode;
231 long long mCurrentHistoryEntryId = -1;
232
236 void updateSqlLayerColumns();
237
241 void cancelRunningQuery();
242
246 void cancelApiFetcher();
247
251 void startFetching();
252
257
258
259 friend class TestQgsQueryResultWidget;
260};
261
262#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.