This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathqgsvirtuallayerprovider.h
212 lines (160 loc) · 6.14 KB
/
qgsvirtuallayerprovider.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/***************************************************************************
qgsvirtuallayerprovider.cpp Virtual layer data provider
begin : Jan, 2015
copyright : (C) 2015 Hugo Mercier, Oslandia
email : hugo dot mercier at oslandia dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSVIRTUAL_LAYER_PROVIDER_H
#define QGSVIRTUAL_LAYER_PROVIDER_H
#include <QTemporaryFile>
#include <qgsvectordataprovider.h>
#include "qgsconfig.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsvirtuallayerdefinition.h"
#include "sqlite_helper.h"
class QgsVirtualLayerFeatureIterator;
class QgsVirtualLayerProvider: public QgsVectorDataProvider
{
Q_OBJECT public:
/**
* Constructor of the vector provider
* @param uri uniform resource locator (URI) for a dataset
*/
QgsVirtualLayerProvider( QString const &uri = "" );
//! Destructor
virtual ~ QgsVirtualLayerProvider();
virtual QgsAbstractFeatureSource* featureSource() const override;
/**
* Returns the permanent storage type for this layer as a friendly name.
*/
virtual QString storageType() const override;
/*! Get the QgsCoordinateReferenceSystem for this layer
* @note Must be reimplemented by each provider.
* If the provider isn't capable of returning
* its projection an empty srs will be return, ti will return 0
*/
virtual QgsCoordinateReferenceSystem crs() override;
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request ) override;
/** Accessor for sql where clause used to limit dataset */
virtual QString subsetString() override;
/** mutator for sql where clause used to limit dataset size */
#if VERSION_INT < 21100
virtual bool setSubsetString( QString theSQL, bool updateFeatureCount = true ) override;
#endif
virtual bool supportsSubsetString() override { return true; }
/** Get the feature type. This corresponds to
* WKBPoint,
* WKBLineString,
* WKBPolygon,
* WKBMultiPoint,
* WKBMultiLineString or
* WKBMultiPolygon
* as defined in qgis.h
*/
QGis::WkbType geometryType() const override;
/** return the number of layers for the current data source
*/
size_t layerCount() const;
/**
* Get the number of features in the layer
*/
long featureCount() const override;
/** Return the extent for this data layer
*/
virtual QgsRectangle extent() override;
/** Update the extent for this data layer
*/
virtual void updateExtents() override;
/**
* Get the field information for the layer
* @return vector of QgsField objects
*/
const QgsFields & fields() const override;
/** Returns the minimum value of an attribute
* @param index the index of the attribute */
QVariant minimumValue( int index ) override;
/** Returns the maximum value of an attribute
* @param index the index of the attribute */
QVariant maximumValue( int index ) override;
/** Return the unique values of an attribute
* @param index the index of the attribute
* @param values reference to the list of unique values
* @param limit maximum number of values */
virtual void uniqueValues( int index, QList < QVariant > &uniqueValues, int limit = -1 ) override;
/**Returns true if layer is valid
*/
bool isValid() override;
/**Describes if provider has save and load style support
@return true in case saving style to db is supported by this provider*/
virtual bool isSaveAndLoadStyleToDBSupported() override { return false; }
/**Returns a bitmask containing the supported capabilities*/
int capabilities() const override;
bool supportsNativeTransform()
{
return false;
}
/** return the provider name
*/
QString name() const override;
/** return description
*/
QString description() const override;
/**
* Return list of indexes of fields that make up the primary key
*/
QgsAttributeList pkAttributeIndexes() override;
private:
// file on disk
QString mPath;
QgsScopedSqlite mSqlite;
// underlying vector layers
struct SourceLayer
{
SourceLayer(): layer(0) {}
SourceLayer( QgsVectorLayer *l, const QString& n = "" ) : layer(l), name(n) {}
SourceLayer( const QString& p, const QString& s, const QString& n, const QString& e = "UTF-8" ) :
layer(0), name(n), source(s), provider(p), encoding(e) {}
// non-null if it refers to a live layer
QgsVectorLayer* layer;
QString name;
// non-empty if it is an embedded layer
QString source;
QString provider;
QString encoding;
};
struct SourceLayers : public QVector<SourceLayer>
{
SourceLayers() : QVector<SourceLayer>() {}
};
SourceLayers mLayers;
bool mValid;
// temporary file used for temporary virtual layer
QScopedPointer<QTemporaryFile> mTempFile;
QString mTableName;
QgsFields mFields;
QgsCoordinateReferenceSystem mCrs;
// nonce used for temporary file
static int mNonce;
QgsVirtualLayerDefinition mDefinition;
QString mSubset;
void resetSqlite();
mutable bool mCachedStatistics;
mutable qint64 mFeatureCount;
mutable QgsRectangle mExtent;
void updateStatistics() const;
bool openIt();
bool createIt();
bool loadSourceLayers();
friend class QgsVirtualLayerFeatureIterator;
private slots:
void onLayerDeleted();
};
#endif