QGIS API Documentation 3.99.0-Master (26c88405ac0)
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:
39
41 QgsQueryResultFetcher( const QgsAbstractDatabaseProviderConnection::QueryResult *queryResult )
42 : mQueryResult( queryResult )
43 {}
44
46 void fetchRows( long long maxRows = -1 );
47
49 void stopFetching();
50
51 signals:
52
54 void rowsReady( const QList<QList<QVariant>> &newRows );
55
57 void fetchingComplete();
58
59 private:
60
61 const QgsAbstractDatabaseProviderConnection::QueryResult *mQueryResult = nullptr;
62 QAtomicInt mStopFetching = 0;
63 // Number of rows rows to fetch before emitting rowsReady
64 static const int ROWS_BATCH_COUNT;
65
66};
67
68#endif
69
71
72
79class CORE_EXPORT QgsQueryResultModel : public QAbstractTableModel
80{
81 Q_OBJECT
82 public:
83
87 QgsQueryResultModel( const QgsAbstractDatabaseProviderConnection::QueryResult &queryResult, QObject *parent = nullptr );
88
89 ~QgsQueryResultModel() override;
90
91 // QAbstractItemModel interface
92 public:
93
94 int rowCount( const QModelIndex &parent ) const override;
95 int columnCount( const QModelIndex &parent ) const override;
96 QVariant data( const QModelIndex &index, int role ) const override;
97 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
98
99 void fetchMore( const QModelIndex &parent ) override;
100 bool canFetchMore( const QModelIndex &parent ) const override;
101
103 QStringList columns() const;
104
109 QgsAbstractDatabaseProviderConnection::QueryResult queryResult() const;
110
111 public slots:
112
116 void rowsReady( const QList<QList<QVariant> > &rows );
117
121 void cancel();
122
123
124 signals:
125
131 void fetchingComplete();
132
137 void fetchMoreRows( qlonglong maxRows );
138
142 void fetchingStarted();
143
144 private:
145
146 QgsAbstractDatabaseProviderConnection::QueryResult mQueryResult;
147 QStringList mColumns;
148 QThread mWorkerThread;
149 std::unique_ptr<QgsQueryResultFetcher> mWorker;
150 QList<QVariantList> mRows;
151
153 static const int FETCH_MORE_ROWS_COUNT;
154
155};
156
157#endif // qgsqueryresultmodel.h