Skip to content

Commit

Permalink
Const correctness for QgsVectorLayer methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 14, 2016
1 parent 0d84ca7 commit 2d50895
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 64 deletions.
7 changes: 7 additions & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ plugins calling this method will need to be updated.</li>
plugins calling this method will need to be updated.</li>
</ul>

\subsection qgis_api_break_3_0_QgsVectorLayer QgsVectorLayer

<ul>
<li>commitErrors() now returns an object, rather than a reference. This has no effect on PyQGIS code.</li>
<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>
</ul>

\subsection qgis_api_break_3_0_QgsVectorFileWriter QgsVectorFileWriter

<ul>
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgsaggregatecalculator.sip
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ class QgsAggregateCalculator
/** Constructor for QgsAggregateCalculator.
* @param layer vector layer to calculate aggregate from
*/
QgsAggregateCalculator( QgsVectorLayer* layer );
QgsAggregateCalculator( const QgsVectorLayer* layer );

/** Returns the associated vector layer.
*/
QgsVectorLayer* layer() const;
const QgsVectorLayer* layer() const;

/** Sets all aggregate parameters from a parameter bundle.
* @param parameters aggregate parameters
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsrelationmanager.sip
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class QgsRelationManager : QObject
*
* @return A list of relations matching the given layer and fieldIdx.
*/
QList<QgsRelation> referencingRelations( QgsVectorLayer *layer = 0, int fieldIdx = -2 ) const;
QList<QgsRelation> referencingRelations( const QgsVectorLayer *layer = 0, int fieldIdx = -2 ) const;

/**
* Get all relations where this layer is the referenced part (i.e. the parent table with the primary key being referenced from another layer).
Expand Down
36 changes: 18 additions & 18 deletions python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class QgsVectorLayer : QgsMapLayer
*
* @return The expression which will be used to preview features for this layer
*/
const QString displayExpression();
QString displayExpression() const;

/** Returns the data provider */
QgsVectorDataProvider* dataProvider();
Expand Down Expand Up @@ -269,7 +269,7 @@ class QgsVectorLayer : QgsMapLayer
*
* @note added in 2.9
*/
const QString expressionField( int index );
QString expressionField( int index ) const;

/**
* Changes the expression used to define an expression based (virtual) field
Expand Down Expand Up @@ -297,7 +297,7 @@ class QgsVectorLayer : QgsMapLayer
*
* @return See description
*/
int selectedFeatureCount();
int selectedFeatureCount() const;

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

/** Get all feature Ids */
QgsFeatureIds allFeatureIds();
QgsFeatureIds allFeatureIds() const;

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

/**
* Get an iterator of the selected features
Expand All @@ -396,7 +396,7 @@ class QgsVectorLayer : QgsMapLayer
* @see selectedFeaturesIds()
* @see selectedFeatures()
*/
QgsFeatureIterator selectedFeaturesIterator( QgsFeatureRequest request = QgsFeatureRequest() );
QgsFeatureIterator selectedFeaturesIterator( QgsFeatureRequest request = QgsFeatureRequest() ) const;

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

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

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

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

/**
* Query the layer for features specified in request.
Expand Down Expand Up @@ -1085,7 +1085,7 @@ class QgsVectorLayer : QgsMapLayer
* that the user has some chance of repairing the damage cleanly.
*/
bool commitChanges();
const QStringList &commitErrors();
QStringList commitErrors() const;

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

/** Access value relation widget data */
ValueRelationData valueRelation( int idx );
ValueRelationData valueRelation( int idx ) const;

/**
* Get relations, where the foreign key is on this layer
*
* @param idx Only get relations, where idx forms part of the foreign key
* @return A list of relations
*/
QList<QgsRelation> referencingRelations( int idx );
QList<QgsRelation> referencingRelations( int idx ) const;

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

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

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

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

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

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

/** Set the blending mode used for rendering each feature */
void setFeatureBlendMode( QPainter::CompositionMode blendMode );
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsaggregatecalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@



QgsAggregateCalculator::QgsAggregateCalculator( QgsVectorLayer* layer )
QgsAggregateCalculator::QgsAggregateCalculator( const QgsVectorLayer* layer )
: mLayer( layer )
{

}

QgsVectorLayer*QgsAggregateCalculator::layer() const
const QgsVectorLayer* QgsAggregateCalculator::layer() const
{
return mLayer;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsaggregatecalculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ class CORE_EXPORT QgsAggregateCalculator
/** Constructor for QgsAggregateCalculator.
* @param layer vector layer to calculate aggregate from
*/
QgsAggregateCalculator( QgsVectorLayer* layer );
QgsAggregateCalculator( const QgsVectorLayer* layer );

/** Returns the associated vector layer.
*/
QgsVectorLayer* layer() const;
const QgsVectorLayer* layer() const;

/** Sets all aggregate parameters from a parameter bundle.
* @param parameters aggregate parameters
Expand Down Expand Up @@ -140,7 +140,7 @@ class CORE_EXPORT QgsAggregateCalculator
private:

//! Source layer
QgsVectorLayer* mLayer;
const QgsVectorLayer* mLayer;

//! Filter expression, or empty for no filter
QString mFilterExpression;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsrelationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void QgsRelationManager::clear()
emit changed();
}

QList<QgsRelation> QgsRelationManager::referencingRelations( QgsVectorLayer* layer, int fieldIdx ) const
QList<QgsRelation> QgsRelationManager::referencingRelations( const QgsVectorLayer* layer, int fieldIdx ) const
{
if ( !layer )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsrelationmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class CORE_EXPORT QgsRelationManager : public QObject
*
* @return A list of relations matching the given layer and fieldIdx.
*/
QList<QgsRelation> referencingRelations( QgsVectorLayer *layer = nullptr, int fieldIdx = -2 ) const;
QList<QgsRelation> referencingRelations( const QgsVectorLayer* layer = nullptr, int fieldIdx = -2 ) const;

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

0 comments on commit 2d50895

Please sign in to comment.