QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 "qgis_core.h"
20#include "qgis_sip.h"
22
23#include <QAbstractTableModel>
24#include <QThread>
25
27
28#ifndef SIP_RUN
29
34class QgsQueryResultFetcher : public QObject
35{
36 Q_OBJECT
37
38 public:
40 QgsQueryResultFetcher( const QgsAbstractDatabaseProviderConnection::QueryResult *queryResult )
41 : mQueryResult( queryResult )
42 {}
43
45 void fetchRows( long long maxRows = -1 );
46
48 void stopFetching();
49
50 signals:
51
53 void rowsReady( const QList<QList<QVariant>> &newRows );
54
56 void fetchingComplete();
57
58 private:
59 const QgsAbstractDatabaseProviderConnection::QueryResult *mQueryResult = nullptr;
60 QAtomicInt mStopFetching = 0;
61 // Number of rows rows to fetch before emitting rowsReady
62 static const int ROWS_BATCH_COUNT;
63};
64
65#endif
66
68
69
76class CORE_EXPORT QgsQueryResultModel : public QAbstractTableModel
77{
78 Q_OBJECT
79 public:
83 QgsQueryResultModel( const QgsAbstractDatabaseProviderConnection::QueryResult &queryResult, QObject *parent = nullptr );
84
85 ~QgsQueryResultModel() override;
86
87 // QAbstractItemModel interface
88 public:
89 int rowCount( const QModelIndex &parent ) const override;
90 int columnCount( const QModelIndex &parent ) const override;
91 QVariant data( const QModelIndex &index, int role ) const override;
92 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
93
94 void fetchMore( const QModelIndex &parent ) override;
95 bool canFetchMore( const QModelIndex &parent ) const override;
96
98 QStringList columns() const;
99
104 QgsAbstractDatabaseProviderConnection::QueryResult queryResult() const;
105
106 public slots:
107
111 void rowsReady( const QList<QList<QVariant> > &rows );
112
116 void cancel();
117
118
119 signals:
120
126 void fetchingComplete();
127
132 void fetchMoreRows( qlonglong maxRows );
133
137 void fetchingStarted();
138
139 private:
140 QgsAbstractDatabaseProviderConnection::QueryResult mQueryResult;
141 QStringList mColumns;
142 QThread mWorkerThread;
143 std::unique_ptr<QgsQueryResultFetcher> mWorker;
144 QList<QVariantList> mRows;
145
147 static const int FETCH_MORE_ROWS_COUNT;
148};
149
150#endif // qgsqueryresultmodel.h