/
qgsprovidersublayerdetails.h
259 lines (222 loc) · 7.55 KB
/
qgsprovidersublayerdetails.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/***************************************************************************
qgsprovidersublayerdetails.h
----------------------------
begin : May 2021
copyright : (C) 2021 by Nyall Dawson
email : nyall dot dawson at gmail 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 QGSPROVIDERSUBLAYERDETAILS_H
#define QGSPROVIDERSUBLAYERDETAILS_H
#include "qgis_core.h"
#include "qgis.h"
#include "qgswkbtypes.h"
#include "qgscoordinatetransformcontext.h"
#include <QString>
#include <QStringList>
/**
* \class QgsProviderSublayerDetails
* \ingroup core
*
* \brief Contains details about a sub layer available from a dataset.
*
* This class encapsulates the properties of a single sublayer available from a dataset,
* according to a specific data provider.
*
* \note It is possible that multiple data providers may be able to utilize the same underlying
* sub layer in a single dataset, yet will interpret this layer differently. For instance, a layer
* in a GeoPDF document can be interpreted as either a vector layer by the OGR data provider or a raster
* layer by the GDAL provider. The providerKey() property can be used to determine the data provider
* associated with a QgsProviderSubLayerDetails instance.
*
* \since QGIS 3.22
*/
class CORE_EXPORT QgsProviderSublayerDetails
{
public:
/**
* Returns the associated data provider key.
*
* \see setProviderKey()
*/
QString providerKey() const { return mProviderKey; }
/**
* Sets the associated data provider key.
*
* \see providerKey()
*/
void setProviderKey( const QString &key ) { mProviderKey = key; }
/**
* Returns the layer type.
*
* \see setType()
*/
QgsMapLayerType type() const { return mType; }
/**
* Sets the layer \a type.
*
* \see type()
*/
void setType( QgsMapLayerType type ) { mType = type; }
/**
* Returns the layer's URI.
*
* \see setUri()
*/
QString uri() const { return mUri; }
/**
* Sets the layer's \a uri.
*
* \see uri()
*/
void setUri( const QString &uri ) { mUri = uri; }
/**
* Setting options for loading layers.
*/
struct LayerOptions
{
/**
* Constructor for LayerOptions with \a transformContext.
*/
explicit LayerOptions( const QgsCoordinateTransformContext &transformContext )
: transformContext( transformContext )
{}
//! Coordinate transform context
QgsCoordinateTransformContext transformContext;
//! Set to TRUE if the default layer style should be loaded
bool loadDefaultStyle = true;
};
/**
* Creates a new QgsMapLayer object associated with the sublayer.
*
* Caller takes ownership of the returned layer.
*/
QgsMapLayer *toLayer( const LayerOptions &options ) const SIP_FACTORY;
/**
* Returns the layer's name.
*
* \see setName()
*/
QString name() const { return mName; }
/**
* Sets the layer's \a name.
*
* \see name()
*/
void setName( const QString &name ) { mName = name; }
/**
* Returns the layer's description.
*
* \see setDescription()
*/
QString description() const { return mDescription; }
/**
* Sets the layer's \a description.
*
* \see description()
*/
void setDescription( const QString &description ) { mDescription = description; }
/**
* Returns the path to the sublayer.
*
* This is an internal path, relative to the dataset itself. It can be used to encapsulate
* the hierarchy of a dataset which organises layers in schemas or in an internal folder structure.
*
* \see setPath()
*/
QStringList path() const { return mPath; }
/**
* Sets the \a path to the sublayer.
*
* This is an internal path, relative to the dataset itself. It can be used to encapsulate
* the hierarchy of a dataset which organises layers in schemas or in an internal folder structure.
*
* \see path()
*/
void setPath( const QStringList &path ) { mPath = path; }
/**
* Returns the layer's feature count.
*
* Will return Qgis::FeatureCountState::UnknownCount or Qgis::FeatureCountState::Uncounted if no feature count is applicable or available.
*
* \see setFeatureCount()
*/
long long featureCount() const { return mFeatureCount; }
/**
* Sets the layer's feature \a count.
*
* Set to Qgis::FeatureCountState::UnknownCount or Qgis::FeatureCountState::Uncounted if no feature count is applicable or available.
*
* \see featureCount()
*/
void setFeatureCount( long long count ) { mFeatureCount = count; }
/**
* Returns the layer's WKB type, or QgsWkbTypes::Unknown if the WKB type is not application or unknown.
*
* \see setWkbType()
*/
QgsWkbTypes::Type wkbType() const { return mWkbType; }
/**
* Set the layer's WKB \a type.
*
* Set to QgsWkbTypes::Unknown if the WKB type is not application or unknown.
*
* \see wkbType()
*/
void setWkbType( QgsWkbTypes::Type type ) { mWkbType = type; }
/**
* Returns the layer's geometry column name, or an empty string if not applicable.
*
* \see setGeometryColumnName()
*/
QString geometryColumnName() const { return mGeometryColumnName; }
/**
* Sets the layer's geometry column \a name.
*
* Set to an empty string if not applicable.
*
* \see geometryColumnName()
*/
void setGeometryColumnName( const QString &name ) { mGeometryColumnName = name; }
#ifdef SIP_RUN
SIP_PYOBJECT __repr__();
% MethodCode
QString str = QStringLiteral( "<QgsProviderSublayerDetails: %1 - %2>" ).arg( sipCpp->providerKey(), sipCpp->name() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
% End
#endif
/**
* Returns the associated layer number, for providers which order sublayers.
*
* \see setLayerNumber()
*/
int layerNumber() const { return mLayerNumber; }
/**
* Sets the associated layer \a number, for providers which order sublayers.
*
* \see layerNumber()
*/
void setLayerNumber( int number ) { mLayerNumber = number; }
// TODO c++20 - replace with = default
bool operator==( const QgsProviderSublayerDetails &other ) const;
bool operator!=( const QgsProviderSublayerDetails &other ) const;
private:
QString mProviderKey;
QgsMapLayerType mType = QgsMapLayerType::VectorLayer;
QString mUri;
int mLayerNumber = 0;
QString mName;
QString mDescription;
long long mFeatureCount = static_cast< long >( Qgis::FeatureCountState::UnknownCount );
QString mGeometryColumnName;
QStringList mPath;
QgsWkbTypes::Type mWkbType = QgsWkbTypes::Unknown;
};
#endif //QGSPROVIDERSUBLAYERDETAILS_H