Skip to content

Commit 2d50895

Browse files
committedJul 14, 2016
Const correctness for QgsVectorLayer methods
1 parent 0d84ca7 commit 2d50895

10 files changed

+71
-64
lines changed
 

‎doc/api_break.dox

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ plugins calling this method will need to be updated.</li>
106106
plugins calling this method will need to be updated.</li>
107107
</ul>
108108

109+
\subsection qgis_api_break_3_0_QgsVectorLayer QgsVectorLayer
110+
111+
<ul>
112+
<li>commitErrors() now returns an object, rather than a reference. This has no effect on PyQGIS code.</li>
113+
<li>subsetString() was made const. This has no effect on PyQGIS code, but c++ code implementing derived layer classes will need to update the signature of this method to match.</li>
114+
</ul>
115+
109116
\subsection qgis_api_break_3_0_QgsVectorFileWriter QgsVectorFileWriter
110117

111118
<ul>

‎python/core/qgsaggregatecalculator.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ class QgsAggregateCalculator
6060
/** Constructor for QgsAggregateCalculator.
6161
* @param layer vector layer to calculate aggregate from
6262
*/
63-
QgsAggregateCalculator( QgsVectorLayer* layer );
63+
QgsAggregateCalculator( const QgsVectorLayer* layer );
6464

6565
/** Returns the associated vector layer.
6666
*/
67-
QgsVectorLayer* layer() const;
67+
const QgsVectorLayer* layer() const;
6868

6969
/** Sets all aggregate parameters from a parameter bundle.
7070
* @param parameters aggregate parameters

‎python/core/qgsrelationmanager.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class QgsRelationManager : QObject
7979
*
8080
* @return A list of relations matching the given layer and fieldIdx.
8181
*/
82-
QList<QgsRelation> referencingRelations( QgsVectorLayer *layer = 0, int fieldIdx = -2 ) const;
82+
QList<QgsRelation> referencingRelations( const QgsVectorLayer *layer = 0, int fieldIdx = -2 ) const;
8383

8484
/**
8585
* Get all relations where this layer is the referenced part (i.e. the parent table with the primary key being referenced from another layer).

‎python/core/qgsvectorlayer.sip

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class QgsVectorLayer : QgsMapLayer
207207
*
208208
* @return The expression which will be used to preview features for this layer
209209
*/
210-
const QString displayExpression();
210+
QString displayExpression() const;
211211

212212
/** Returns the data provider */
213213
QgsVectorDataProvider* dataProvider();
@@ -269,7 +269,7 @@ class QgsVectorLayer : QgsMapLayer
269269
*
270270
* @note added in 2.9
271271
*/
272-
const QString expressionField( int index );
272+
QString expressionField( int index ) const;
273273

274274
/**
275275
* Changes the expression used to define an expression based (virtual) field
@@ -297,7 +297,7 @@ class QgsVectorLayer : QgsMapLayer
297297
*
298298
* @return See description
299299
*/
300-
int selectedFeatureCount();
300+
int selectedFeatureCount() const;
301301

302302
/**
303303
* Select features found within the search rectangle (in layer's coordinates)
@@ -364,7 +364,7 @@ class QgsVectorLayer : QgsMapLayer
364364
void selectAll();
365365

366366
/** Get all feature Ids */
367-
QgsFeatureIds allFeatureIds();
367+
QgsFeatureIds allFeatureIds() const;
368368

369369
/**
370370
* Invert selection of features found within the search rectangle (in layer's coordinates)
@@ -383,7 +383,7 @@ class QgsVectorLayer : QgsMapLayer
383383
* @see selectedFeaturesIds()
384384
* @see selectedFeaturesIterator() which is more memory friendly when handling large selections
385385
*/
386-
QgsFeatureList selectedFeatures();
386+
QgsFeatureList selectedFeatures() const;
387387

388388
/**
389389
* Get an iterator of the selected features
@@ -396,7 +396,7 @@ class QgsVectorLayer : QgsMapLayer
396396
* @see selectedFeaturesIds()
397397
* @see selectedFeatures()
398398
*/
399-
QgsFeatureIterator selectedFeaturesIterator( QgsFeatureRequest request = QgsFeatureRequest() );
399+
QgsFeatureIterator selectedFeaturesIterator( QgsFeatureRequest request = QgsFeatureRequest() ) const;
400400

401401
/**
402402
* Return reference to identifiers of selected features
@@ -417,7 +417,7 @@ class QgsVectorLayer : QgsMapLayer
417417
void setSelectedFeatures( const QgsFeatureIds &ids ) /Deprecated/;
418418

419419
/** Returns the bounding box of the selected features. If there is no selection, QgsRectangle(0,0,0,0) is returned */
420-
QgsRectangle boundingBoxOfSelected();
420+
QgsRectangle boundingBoxOfSelected() const;
421421

422422
/** Returns whether the layer contains labels which are enabled and should be drawn.
423423
* @return true if layer contains enabled labels
@@ -573,7 +573,7 @@ class QgsVectorLayer : QgsMapLayer
573573
* @param symbol the symbol
574574
* @return number of features rendered by symbol or -1 if failed or counts are not available
575575
*/
576-
long featureCount( QgsSymbolV2* symbol );
576+
long featureCount( QgsSymbolV2* symbol ) const;
577577

578578
/**
579579
* Update the data source of the layer. The layer's renderer and legend will be preserved only
@@ -607,7 +607,7 @@ class QgsVectorLayer : QgsMapLayer
607607
* Get the string (typically sql) used to define a subset of the layer
608608
* @return The subset string or QString::null if not implemented by the provider
609609
*/
610-
virtual QString subsetString();
610+
virtual QString subsetString() const;
611611

612612
/**
613613
* Query the layer for features specified in request.
@@ -1085,7 +1085,7 @@ class QgsVectorLayer : QgsMapLayer
10851085
* that the user has some chance of repairing the damage cleanly.
10861086
*/
10871087
bool commitChanges();
1088-
const QStringList &commitErrors();
1088+
QStringList commitErrors() const;
10891089

10901090
/** Stop editing and discard the edits
10911091
* @param deleteBuffer whether to delete editing buffer
@@ -1235,15 +1235,15 @@ class QgsVectorLayer : QgsMapLayer
12351235
RangeData range( int idx ) /Deprecated/;
12361236

12371237
/** Access value relation widget data */
1238-
ValueRelationData valueRelation( int idx );
1238+
ValueRelationData valueRelation( int idx ) const;
12391239

12401240
/**
12411241
* Get relations, where the foreign key is on this layer
12421242
*
12431243
* @param idx Only get relations, where idx forms part of the foreign key
12441244
* @return A list of relations
12451245
*/
1246-
QList<QgsRelation> referencingRelations( int idx );
1246+
QList<QgsRelation> referencingRelations( int idx ) const;
12471247

12481248
/**
12491249
* Access date format
@@ -1324,13 +1324,13 @@ class QgsVectorLayer : QgsMapLayer
13241324
* @param uniqueValues out: result list
13251325
* @param limit maximum number of values to return (-1 if unlimited)
13261326
*/
1327-
void uniqueValues( int index, QList<QVariant> &uniqueValues /Out/, int limit = -1 );
1327+
void uniqueValues( int index, QList<QVariant> &uniqueValues /Out/, int limit = -1 ) const;
13281328

13291329
/** Returns minimum value for an attribute column or invalid variant in case of error */
1330-
QVariant minimumValue( int index );
1330+
QVariant minimumValue( int index ) const;
13311331

13321332
/** Returns maximum value for an attribute column or invalid variant in case of error */
1333-
QVariant maximumValue( int index );
1333+
QVariant maximumValue( int index ) const;
13341334

13351335
/** Calculates an aggregated value from the layer's features.
13361336
* @param aggregate aggregate to calculate
@@ -1345,7 +1345,7 @@ class QgsVectorLayer : QgsMapLayer
13451345
const QString& fieldOrExpression,
13461346
const QgsAggregateCalculator::AggregateParameters& parameters = QgsAggregateCalculator::AggregateParameters(),
13471347
QgsExpressionContext* context = nullptr,
1348-
bool* ok = nullptr );
1348+
bool* ok = nullptr ) const;
13491349

13501350
/** Fetches all values from a specified field name or expression.
13511351
* @param fieldOrExpression field name or an expression string
@@ -1355,7 +1355,7 @@ class QgsVectorLayer : QgsMapLayer
13551355
* @note added in QGIS 2.9
13561356
* @see getDoubleValues
13571357
*/
1358-
QList< QVariant > getValues( const QString &fieldOrExpression, bool &ok, bool selectedOnly = false );
1358+
QList< QVariant > getValues( const QString &fieldOrExpression, bool &ok, bool selectedOnly = false ) const;
13591359

13601360
/** Fetches all double values from a specified field name or expression. Null values or
13611361
* invalid expression results are skipped.
@@ -1367,7 +1367,7 @@ class QgsVectorLayer : QgsMapLayer
13671367
* @note added in QGIS 2.9
13681368
* @see getValues
13691369
*/
1370-
QList< double > getDoubleValues( const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, int* nullCount = 0 );
1370+
QList< double > getDoubleValues( const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, int* nullCount = 0 ) const;
13711371

13721372
/** Set the blending mode used for rendering each feature */
13731373
void setFeatureBlendMode( QPainter::CompositionMode blendMode );

‎src/core/qgsaggregatecalculator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323

2424

2525

26-
QgsAggregateCalculator::QgsAggregateCalculator( QgsVectorLayer* layer )
26+
QgsAggregateCalculator::QgsAggregateCalculator( const QgsVectorLayer* layer )
2727
: mLayer( layer )
2828
{
2929

3030
}
3131

32-
QgsVectorLayer*QgsAggregateCalculator::layer() const
32+
const QgsVectorLayer* QgsAggregateCalculator::layer() const
3333
{
3434
return mLayer;
3535
}

‎src/core/qgsaggregatecalculator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ class CORE_EXPORT QgsAggregateCalculator
8686
/** Constructor for QgsAggregateCalculator.
8787
* @param layer vector layer to calculate aggregate from
8888
*/
89-
QgsAggregateCalculator( QgsVectorLayer* layer );
89+
QgsAggregateCalculator( const QgsVectorLayer* layer );
9090

9191
/** Returns the associated vector layer.
9292
*/
93-
QgsVectorLayer* layer() const;
93+
const QgsVectorLayer* layer() const;
9494

9595
/** Sets all aggregate parameters from a parameter bundle.
9696
* @param parameters aggregate parameters
@@ -140,7 +140,7 @@ class CORE_EXPORT QgsAggregateCalculator
140140
private:
141141

142142
//! Source layer
143-
QgsVectorLayer* mLayer;
143+
const QgsVectorLayer* mLayer;
144144

145145
//! Filter expression, or empty for no filter
146146
QString mFilterExpression;

‎src/core/qgsrelationmanager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void QgsRelationManager::clear()
9393
emit changed();
9494
}
9595

96-
QList<QgsRelation> QgsRelationManager::referencingRelations( QgsVectorLayer* layer, int fieldIdx ) const
96+
QList<QgsRelation> QgsRelationManager::referencingRelations( const QgsVectorLayer* layer, int fieldIdx ) const
9797
{
9898
if ( !layer )
9999
{

‎src/core/qgsrelationmanager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class CORE_EXPORT QgsRelationManager : public QObject
106106
*
107107
* @return A list of relations matching the given layer and fieldIdx.
108108
*/
109-
QList<QgsRelation> referencingRelations( QgsVectorLayer *layer = nullptr, int fieldIdx = -2 ) const;
109+
QList<QgsRelation> referencingRelations( const QgsVectorLayer* layer = nullptr, int fieldIdx = -2 ) const;
110110

111111
/**
112112
* Get all relations where this layer is the referenced part (i.e. the parent table with the primary key being referenced from another layer).

0 commit comments

Comments
 (0)
Please sign in to comment.