QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgsqueryresultmodel.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsqueryresultmodel.h - QgsQueryResultModel
3
4 ---------------------
5 begin : 24.12.2020
6 copyright : (C) 2020 by Alessandro Pasotti
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 QgsQueryResultModel_H
17#define QgsQueryResultModel_H
18
19#include <QAbstractTableModel>
20#include <QThread>
21
22#include "qgis_core.h"
23#include "qgis_sip.h"
24
26
28
29#ifndef SIP_RUN
30
35class QgsQueryResultFetcher: public QObject
36{
37 Q_OBJECT
38
39 public:
40
42 QgsQueryResultFetcher( const QgsAbstractDatabaseProviderConnection::QueryResult *queryResult )
43 : mQueryResult( queryResult )
44 {}
45
47 void fetchRows( long long maxRows = -1 );
48
50 void stopFetching();
51
52 signals:
53
55 void rowsReady( const QList<QList<QVariant>> &newRows );
56
58 void fetchingComplete();
59
60 private:
61
62 const QgsAbstractDatabaseProviderConnection::QueryResult *mQueryResult = nullptr;
63 QAtomicInt mStopFetching = 0;
64 // Number of rows rows to fetch before emitting rowsReady
65 static const int ROWS_BATCH_COUNT;
66
67};
68
69#endif
70
72
73
80class CORE_EXPORT QgsQueryResultModel : public QAbstractTableModel
81{
82 Q_OBJECT
83 public:
84
88 QgsQueryResultModel( const QgsAbstractDatabaseProviderConnection::QueryResult &queryResult, QObject *parent = nullptr );
89
90 ~QgsQueryResultModel();
91
92 // QAbstractItemModel interface
93 public:
94
95 int rowCount( const QModelIndex &parent ) const override;
96 int columnCount( const QModelIndex &parent ) const override;
97 QVariant data( const QModelIndex &index, int role ) const override;
98 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
99
100 void fetchMore( const QModelIndex &parent ) override;
101 bool canFetchMore( const QModelIndex &parent ) const override;
102
104 QStringList columns() const;
105
111
112 public slots:
113
117 void rowsReady( const QList<QList<QVariant> > &rows );
118
122 void cancel();
123
124
125 signals:
126
132 void fetchingComplete();
133
138 void fetchMoreRows( qlonglong maxRows );
139
143 void fetchingStarted();
144
145 private:
146
148 QStringList mColumns;
149 QThread mWorkerThread;
150 std::unique_ptr<QgsQueryResultFetcher> mWorker;
151 QList<QVariantList> mRows;
152
154 static const int FETCH_MORE_ROWS_COUNT;
155
156};
157
158#endif // qgsqueryresultmodel.h
The QueryResult class represents the result of a query executed by execSql()