Skip to content

Commit 1bafa80

Browse files
committed
Const correctness for numerous data provider methods
1 parent fd42ed3 commit 1bafa80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+375
-555
lines changed

doc/api_break.dox

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ This page tries to maintain a list with incompatible changes that happened in pr
1818

1919
\section qgis_api_break_3_0 QGIS 3.0
2020

21+
\subsection qgis_api_break_3_0_DataProviders Data Providers
22+
23+
<ul>
24+
<li>Many methods in QgsDataProvider, QgsVectorDataProvider and QgsRasterDataProvider have been made const-correct.
25+
This has no effect on PyQGIS code, but c++ code implementing third-party providers will need to update the
26+
signatures of these methods to match. Affected methods are:
27+
<ul>
28+
<li>QgsDataProvider: crs(), extent(), isValid(), supportsSubsetString(), subsetString()</li>
29+
<li>QgsVectorDataProvider: getFeatures(), minimumValue(), maximumValue(), uniqueValues(), enumValues(), defaultValue(),
30+
attributeIndexes(), pkAttributeIndexes(), isSaveAndLoadStyleToDBSupported()</li>
31+
<li>QgsRasterInterface: extent()</li>
32+
</ul
33+
</li>
34+
</ul>
35+
2136
\subsection qgis_api_break_3_0_QgsVectorFileWriter QgsVectorFileWriter
2237

2338
<ul>

python/core/qgsdataprovider.sip

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ class QgsDataProvider : QObject
5454
virtual ~QgsDataProvider();
5555

5656

57-
/** Get the QgsCoordinateReferenceSystem for this layer
58-
* @note Must be reimplemented by each provider.
59-
* If the provider isn't capable of returning
60-
* its projection an empty srs will be return, ti will return 0
57+
/* Returns the coordinate system for the data source.
58+
* If the provider isn't capable of returning its projection then an invalid
59+
* QgsCoordinateReferenceSystem will be returned.
6160
*/
62-
virtual QgsCoordinateReferenceSystem crs() = 0;
61+
virtual QgsCoordinateReferenceSystem crs() const = 0;
6362

6463

6564
/**
@@ -82,21 +81,21 @@ class QgsDataProvider : QObject
8281

8382

8483
/**
85-
* Get the extent of the layer
84+
* Returns the extent of the layer.
8685
* @return QgsRectangle containing the extent of the layer
8786
*/
88-
virtual QgsRectangle extent() = 0;
87+
virtual QgsRectangle extent() const = 0;
8988

9089

9190
/**
9291
* Returns true if this is a valid layer. It is up to individual providers
93-
* to determine what constitutes a valid layer
92+
* to determine what constitutes a valid layer.
9493
*/
95-
virtual bool isValid() = 0;
94+
virtual bool isValid() const = 0;
9695

9796

9897
/**
99-
* Update the extents of the layer. Not implemented by default
98+
* Update the extents of the layer. Not implemented by default.
10099
*/
101100
virtual void updateExtents();
102101

@@ -109,16 +108,16 @@ class QgsDataProvider : QObject
109108
*/
110109
virtual bool setSubsetString( const QString& subset, bool updateFeatureCount = true );
111110

112-
/** Provider supports setting of subset strings */
113-
virtual bool supportsSubsetString();
111+
/** Returns true if the provider supports setting of subset strings. */
112+
virtual bool supportsSubsetString() const;
114113

115114
/**
116115
* Returns the subset definition string (typically sql) currently in
117116
* use by the layer and used by the provider to limit the feature set.
118117
* Must be overridden in the dataprovider, otherwise returns a null
119118
* QString.
120119
*/
121-
virtual QString subsetString();
120+
virtual QString subsetString() const;
122121

123122

124123
/**

python/core/qgsvectordataprovider.sip

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ class QgsVectorDataProvider : QgsDataProvider
9898

9999
/**
100100
* Query the provider for features specified in request.
101+
* @param request feature request describing parameters of features to return
102+
* @returns iterator for matching features from provider
101103
*/
102-
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0;
104+
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) const = 0;
103105

104106
/**
105107
* Get feature type.
@@ -134,7 +136,7 @@ class QgsVectorDataProvider : QgsDataProvider
134136
* and maximal values. If provider has facilities to retrieve minimal
135137
* value directly, override this function.
136138
*/
137-
virtual QVariant minimumValue( int index );
139+
virtual QVariant minimumValue( int index ) const;
138140

139141
/**
140142
* Returns the maximum value of an attribute
@@ -144,7 +146,7 @@ class QgsVectorDataProvider : QgsDataProvider
144146
* and maximal values. If provider has facilities to retrieve maximal
145147
* value directly, override this function.
146148
*/
147-
virtual QVariant maximumValue( int index );
149+
virtual QVariant maximumValue( int index ) const;
148150

149151
/**
150152
* Return unique values of an attribute
@@ -154,7 +156,7 @@ class QgsVectorDataProvider : QgsDataProvider
154156
*
155157
* Default implementation simply iterates the features
156158
*/
157-
virtual void uniqueValues( int index, QList<QVariant> &uniqueValues /Out/, int limit = -1 );
159+
virtual void uniqueValues( int index, QList<QVariant> &uniqueValues /Out/, int limit = -1 ) const;
158160

159161
/** Calculates an aggregated value from the layer's features. The base implementation does nothing,
160162
* but subclasses can override this method to handoff calculation of aggregates to the provider.
@@ -170,15 +172,15 @@ class QgsVectorDataProvider : QgsDataProvider
170172
int index,
171173
const QgsAggregateCalculator::AggregateParameters& parameters,
172174
QgsExpressionContext* context,
173-
bool& ok );
175+
bool& ok ) const;
174176

175177
/**
176178
* Returns the possible enum values of an attribute. Returns an empty stringlist if a provider does not support enum types
177179
* or if the given attribute is not an enum type.
178180
* @param index the index of the attribute
179181
* @param enumList reference to the list to fill
180182
*/
181-
virtual void enumValues( int index, QStringList& enumList /Out/ );
183+
virtual void enumValues( int index, QStringList& enumList /Out/ ) const;
182184

183185
/**
184186
* Adds a list of features
@@ -236,7 +238,7 @@ class QgsVectorDataProvider : QgsDataProvider
236238
/**
237239
* Returns the default value for field specified by @c fieldId
238240
*/
239-
virtual QVariant defaultValue( int fieldId );
241+
virtual QVariant defaultValue( int fieldId ) const;
240242

241243
/**
242244
* Changes geometries of existing features
@@ -291,12 +293,12 @@ class QgsVectorDataProvider : QgsDataProvider
291293
/**
292294
* Return list of indexes to fetch all attributes in nextFeature()
293295
*/
294-
virtual QList<int> attributeIndexes();
296+
virtual QList<int> attributeIndexes() const;
295297

296298
/**
297299
* Return list of indexes of fields that make up the primary key
298300
*/
299-
virtual QList<int> pkAttributeIndexes();
301+
virtual QList<int> pkAttributeIndexes() const;
300302

301303
/**
302304
* Return list of indexes to names for QgsPalLabeling fix
@@ -333,12 +335,12 @@ class QgsVectorDataProvider : QgsDataProvider
333335
virtual bool doesStrictFeatureTypeCheck() const;
334336

335337
/** Returns a list of available encodings */
336-
static const QStringList &availableEncodings();
338+
static QStringList availableEncodings();
337339

338340
/**
339341
* Provider has errors to report
340342
*/
341-
bool hasErrors();
343+
bool hasErrors() const;
342344

343345
/**
344346
* Clear recorded errors
@@ -348,14 +350,14 @@ class QgsVectorDataProvider : QgsDataProvider
348350
/**
349351
* Get recorded errors
350352
*/
351-
QStringList errors();
353+
QStringList errors() const;
352354

353355

354356
/**
355357
* It returns false by default.
356358
* Must be implemented by providers that support saving and loading styles to db returning true
357359
*/
358-
virtual bool isSaveAndLoadStyleToDBSupported();
360+
virtual bool isSaveAndLoadStyleToDBSupported() const;
359361

360362
static QVariant convertValue( QVariant::Type type, const QString& value );
361363

@@ -384,7 +386,9 @@ class QgsVectorDataProvider : QgsDataProvider
384386

385387
protected:
386388
void clearMinMaxCache();
387-
void fillMinMaxCache();
389+
390+
//! Populates the cache of minimum and maximum attribute values.
391+
void fillMinMaxCache() const;
388392

389393
void pushError( const QString& msg );
390394

python/core/raster/qgsrasterdataprovider.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
6464
/** Get the extent of the data source.
6565
* @return QgsRectangle containing the extent of the layer
6666
*/
67-
virtual QgsRectangle extent() = 0;
67+
virtual QgsRectangle extent() const = 0;
6868

6969
/** Returns data type for the band specified by number */
7070
virtual QGis::DataType dataType( int bandNo ) const = 0;
@@ -295,7 +295,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
295295
/** Emit a message to be displayed on status bar, usually used by network providers (WMS,WCS)
296296
* @note added in 2.14
297297
*/
298-
void statusChanged( const QString& );
298+
void statusChanged( const QString& ) const;
299299

300300
protected:
301301
/** Read block of data

python/core/raster/qgsrasterinterface.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class QgsRasterInterface
104104
* Get the extent of the interface.
105105
* @return QgsRectangle containing the extent of the layer
106106
*/
107-
virtual QgsRectangle extent();
107+
virtual QgsRectangle extent() const;
108108

109109
int dataTypeSize( int bandNo );
110110

src/core/qgsdataprovider.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,11 @@ class CORE_EXPORT QgsDataProvider : public QObject
8484
virtual ~QgsDataProvider() {}
8585

8686

87-
/** Get the QgsCoordinateReferenceSystem for this layer
88-
* @note Must be reimplemented by each provider.
89-
* If the provider isn't capable of returning
90-
* its projection an empty srs will be return, ti will return 0
87+
/** Returns the coordinate system for the data source.
88+
* If the provider isn't capable of returning its projection then an invalid
89+
* QgsCoordinateReferenceSystem will be returned.
9190
*/
92-
virtual QgsCoordinateReferenceSystem crs() = 0;
91+
virtual QgsCoordinateReferenceSystem crs() const = 0;
9392

9493

9594
/**
@@ -126,21 +125,21 @@ class CORE_EXPORT QgsDataProvider : public QObject
126125

127126

128127
/**
129-
* Get the extent of the layer
128+
* Returns the extent of the layer
130129
* @return QgsRectangle containing the extent of the layer
131130
*/
132-
virtual QgsRectangle extent() = 0;
131+
virtual QgsRectangle extent() const = 0;
133132

134133

135134
/**
136135
* Returns true if this is a valid layer. It is up to individual providers
137-
* to determine what constitutes a valid layer
136+
* to determine what constitutes a valid layer.
138137
*/
139-
virtual bool isValid() = 0;
138+
virtual bool isValid() const = 0;
140139

141140

142141
/**
143-
* Update the extents of the layer. Not implemented by default
142+
* Update the extents of the layer. Not implemented by default.
144143
*/
145144
virtual void updateExtents()
146145
{
@@ -163,16 +162,17 @@ class CORE_EXPORT QgsDataProvider : public QObject
163162
}
164163

165164

166-
/** Provider supports setting of subset strings */
167-
virtual bool supportsSubsetString() { return false; }
165+
/** Returns true if the provider supports setting of subset strings.
166+
*/
167+
virtual bool supportsSubsetString() const { return false; }
168168

169169
/**
170170
* Returns the subset definition string (typically sql) currently in
171171
* use by the layer and used by the provider to limit the feature set.
172172
* Must be overridden in the dataprovider, otherwise returns a null
173173
* QString.
174174
*/
175-
virtual QString subsetString()
175+
virtual QString subsetString() const
176176
{
177177
return QString::null;
178178
}

src/core/qgsvectordataprovider.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ bool QgsVectorDataProvider::changeAttributeValues( const QgsChangedAttributesMap
9393
return false;
9494
}
9595

96-
QVariant QgsVectorDataProvider::defaultValue( int fieldId )
96+
QVariant QgsVectorDataProvider::defaultValue( int fieldId ) const
9797
{
9898
Q_UNUSED( fieldId );
9999
return QVariant();
@@ -275,7 +275,7 @@ QMap<QString, int> QgsVectorDataProvider::fieldNameMap() const
275275
return resultMap;
276276
}
277277

278-
QgsAttributeList QgsVectorDataProvider::attributeIndexes()
278+
QgsAttributeList QgsVectorDataProvider::attributeIndexes() const
279279
{
280280
return fields().allAttributesList();
281281
}
@@ -353,7 +353,7 @@ bool QgsVectorDataProvider::supportedType( const QgsField &field ) const
353353
return false;
354354
}
355355

356-
QVariant QgsVectorDataProvider::minimumValue( int index )
356+
QVariant QgsVectorDataProvider::minimumValue( int index ) const
357357
{
358358
if ( index < 0 || index >= fields().count() )
359359
{
@@ -369,7 +369,7 @@ QVariant QgsVectorDataProvider::minimumValue( int index )
369369
return mCacheMinValues[index];
370370
}
371371

372-
QVariant QgsVectorDataProvider::maximumValue( int index )
372+
QVariant QgsVectorDataProvider::maximumValue( int index ) const
373373
{
374374
if ( index < 0 || index >= fields().count() )
375375
{
@@ -385,7 +385,7 @@ QVariant QgsVectorDataProvider::maximumValue( int index )
385385
return mCacheMaxValues[index];
386386
}
387387

388-
void QgsVectorDataProvider::uniqueValues( int index, QList<QVariant> &values, int limit )
388+
void QgsVectorDataProvider::uniqueValues( int index, QList<QVariant> &values, int limit ) const
389389
{
390390
QgsFeature f;
391391
QgsAttributeList keys;
@@ -409,7 +409,7 @@ void QgsVectorDataProvider::uniqueValues( int index, QList<QVariant> &values, in
409409
}
410410

411411
QVariant QgsVectorDataProvider::aggregate( QgsAggregateCalculator::Aggregate aggregate, int index,
412-
const QgsAggregateCalculator::AggregateParameters& parameters, QgsExpressionContext* context, bool& ok )
412+
const QgsAggregateCalculator::AggregateParameters& parameters, QgsExpressionContext* context, bool& ok ) const
413413
{
414414
//base implementation does nothing
415415
Q_UNUSED( aggregate );
@@ -426,7 +426,7 @@ void QgsVectorDataProvider::clearMinMaxCache()
426426
mCacheMinMaxDirty = true;
427427
}
428428

429-
void QgsVectorDataProvider::fillMinMaxCache()
429+
void QgsVectorDataProvider::fillMinMaxCache() const
430430
{
431431
if ( !mCacheMinMaxDirty )
432432
return;
@@ -527,7 +527,7 @@ static bool _compareEncodings( const QString& s1, const QString& s2 )
527527
return s1.toLower() < s2.toLower();
528528
}
529529

530-
const QStringList &QgsVectorDataProvider::availableEncodings()
530+
QStringList QgsVectorDataProvider::availableEncodings()
531531
{
532532
if ( smEncodings.isEmpty() )
533533
{
@@ -595,12 +595,12 @@ void QgsVectorDataProvider::clearErrors()
595595
mErrors.clear();
596596
}
597597

598-
bool QgsVectorDataProvider::hasErrors()
598+
bool QgsVectorDataProvider::hasErrors() const
599599
{
600600
return !mErrors.isEmpty();
601601
}
602602

603-
QStringList QgsVectorDataProvider::errors()
603+
QStringList QgsVectorDataProvider::errors() const
604604
{
605605
return mErrors;
606606
}

0 commit comments

Comments
 (0)