Const correctness for QgsVectorLayer methods

This commit is contained in:
Nyall Dawson 2016-07-11 12:06:06 +10:00
parent 0d84ca74c5
commit 2d50895d04
10 changed files with 71 additions and 64 deletions

View File

@ -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>

View File

@ -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

View File

@ -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).

View File

@ -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();
@ -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
@ -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)
@ -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)
@ -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
@ -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
@ -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
@ -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
@ -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.
@ -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
@ -1235,7 +1235,7 @@ 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
@ -1243,7 +1243,7 @@ class QgsVectorLayer : QgsMapLayer
* @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
@ -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
@ -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
@ -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.
@ -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 );

View File

@ -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;
}

View File

@ -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
@ -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;

View File

@ -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 )
{

View File

@ -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).

View File

@ -581,7 +581,7 @@ void QgsVectorLayer::selectAll()
selectByIds( allFeatureIds() );
}
QgsFeatureIds QgsVectorLayer::allFeatureIds()
QgsFeatureIds QgsVectorLayer::allFeatureIds() const
{
QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
.setFlags( QgsFeatureRequest::NoGeometry )
@ -695,7 +695,7 @@ QGis::WkbType QgsVectorLayer::wkbType() const
return mWkbType;
}
QgsRectangle QgsVectorLayer::boundingBoxOfSelected()
QgsRectangle QgsVectorLayer::boundingBoxOfSelected() const
{
if ( !mValid || mSelectedFeatureIds.isEmpty() ) //no selected features
{
@ -781,7 +781,7 @@ bool QgsVectorLayer::diagramsEnabled() const
return false;
}
long QgsVectorLayer::featureCount( QgsSymbolV2* symbol )
long QgsVectorLayer::featureCount( QgsSymbolV2* symbol ) const
{
if ( !mSymbolFeatureCounted )
return -1;
@ -1052,7 +1052,7 @@ QgsRectangle QgsVectorLayer::extent() const
return rect;
}
QString QgsVectorLayer::subsetString()
QString QgsVectorLayer::subsetString() const
{
if ( !mValid || !mDataProvider )
{
@ -2545,7 +2545,7 @@ bool QgsVectorLayer::commitChanges()
return success;
}
const QStringList &QgsVectorLayer::commitErrors()
QStringList QgsVectorLayer::commitErrors() const
{
return mCommitErrors;
}
@ -2601,7 +2601,7 @@ void QgsVectorLayer::setSelectedFeatures( const QgsFeatureIds& ids )
selectByIds( ids, SetSelection );
}
int QgsVectorLayer::selectedFeatureCount()
int QgsVectorLayer::selectedFeatureCount() const
{
return mSelectedFeatureIds.size();
}
@ -2611,7 +2611,7 @@ const QgsFeatureIds& QgsVectorLayer::selectedFeaturesIds() const
return mSelectedFeatureIds;
}
QgsFeatureList QgsVectorLayer::selectedFeatures()
QgsFeatureList QgsVectorLayer::selectedFeatures() const
{
QgsFeatureList features;
QgsFeature f;
@ -2639,7 +2639,7 @@ QgsFeatureList QgsVectorLayer::selectedFeatures()
return features;
}
QgsFeatureIterator QgsVectorLayer::selectedFeaturesIterator( QgsFeatureRequest request )
QgsFeatureIterator QgsVectorLayer::selectedFeaturesIterator( QgsFeatureRequest request ) const
{
if ( mSelectedFeatureIds.isEmpty() )
return QgsFeatureIterator();
@ -2855,7 +2855,7 @@ void QgsVectorLayer::setDisplayExpression( const QString &displayExpression )
mDisplayExpression = displayExpression;
}
const QString QgsVectorLayer::displayExpression()
QString QgsVectorLayer::displayExpression() const
{
return mDisplayExpression;
}
@ -3084,7 +3084,7 @@ void QgsVectorLayer::removeExpressionField( int index )
emit attributeDeleted( index );
}
QString QgsVectorLayer::expressionField( int index )
QString QgsVectorLayer::expressionField( int index ) const
{
int oi = mUpdatedFields.fieldOriginIndex( index );
return mExpressionFieldBuffer->expressions().value( oi ).expression;
@ -3132,7 +3132,7 @@ void QgsVectorLayer::createJoinCaches() const
}
}
void QgsVectorLayer::uniqueValues( int index, QList<QVariant> &uniqueValues, int limit )
void QgsVectorLayer::uniqueValues( int index, QList<QVariant> &uniqueValues, int limit ) const
{
uniqueValues.clear();
if ( !mDataProvider )
@ -3221,7 +3221,7 @@ void QgsVectorLayer::uniqueValues( int index, QList<QVariant> &uniqueValues, int
Q_ASSERT_X( false, "QgsVectorLayer::uniqueValues()", "Unknown source of the field!" );
}
QVariant QgsVectorLayer::minimumValue( int index )
QVariant QgsVectorLayer::minimumValue( int index ) const
{
if ( !mDataProvider )
{
@ -3281,7 +3281,7 @@ QVariant QgsVectorLayer::minimumValue( int index )
return QVariant();
}
QVariant QgsVectorLayer::maximumValue( int index )
QVariant QgsVectorLayer::maximumValue( int index ) const
{
if ( !mDataProvider )
{
@ -3339,7 +3339,7 @@ QVariant QgsVectorLayer::maximumValue( int index )
}
QVariant QgsVectorLayer::aggregate( QgsAggregateCalculator::Aggregate aggregate, const QString& fieldOrExpression,
const QgsAggregateCalculator::AggregateParameters& parameters, QgsExpressionContext* context, bool* ok )
const QgsAggregateCalculator::AggregateParameters& parameters, QgsExpressionContext* context, bool* ok ) const
{
if ( ok )
*ok = false;
@ -3376,7 +3376,7 @@ QVariant QgsVectorLayer::aggregate( QgsAggregateCalculator::Aggregate aggregate,
return c.calculate( aggregate, fieldOrExpression, context, ok );
}
QList<QVariant> QgsVectorLayer::getValues( const QString &fieldOrExpression, bool& ok, bool selectedOnly )
QList<QVariant> QgsVectorLayer::getValues( const QString &fieldOrExpression, bool& ok, bool selectedOnly ) const
{
QList<QVariant> values;
@ -3441,7 +3441,7 @@ QList<QVariant> QgsVectorLayer::getValues( const QString &fieldOrExpression, boo
return values;
}
QList<double> QgsVectorLayer::getDoubleValues( const QString &fieldOrExpression, bool& ok, bool selectedOnly, int* nullCount )
QList<double> QgsVectorLayer::getDoubleValues( const QString &fieldOrExpression, bool& ok, bool selectedOnly, int* nullCount ) const
{
QList<double> values;
@ -4034,7 +4034,7 @@ void QgsVectorLayer::onFeatureDeleted( QgsFeatureId fid )
emit featureDeleted( fid );
}
QgsVectorLayer::ValueRelationData QgsVectorLayer::valueRelation( int idx )
QgsVectorLayer::ValueRelationData QgsVectorLayer::valueRelation( int idx ) const
{
if ( mEditFormConfig->widgetType( idx ) == "ValueRelation" )
{
@ -4055,7 +4055,7 @@ QgsVectorLayer::ValueRelationData QgsVectorLayer::valueRelation( int idx )
}
}
QList<QgsRelation> QgsVectorLayer::referencingRelations( int idx )
QList<QgsRelation> QgsVectorLayer::referencingRelations( int idx ) const
{
return QgsProject::instance()->relationManager()->referencingRelations( this, idx );
}

View File

@ -572,7 +572,7 @@ class CORE_EXPORT QgsVectorLayer : public 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();
@ -634,7 +634,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*
* @note added in 2.9
*/
QString expressionField( int index );
QString expressionField( int index ) const;
/**
* Changes the expression used to define an expression based (virtual) field
@ -668,7 +668,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*
* @return See description
*/
int selectedFeatureCount();
int selectedFeatureCount() const;
/**
* Select features found within the search rectangle (in layer's coordinates)
@ -735,7 +735,7 @@ class CORE_EXPORT QgsVectorLayer : public 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)
@ -754,7 +754,7 @@ class CORE_EXPORT QgsVectorLayer : public 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
@ -767,7 +767,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
* @see selectedFeaturesIds()
* @see selectedFeatures()
*/
QgsFeatureIterator selectedFeaturesIterator( QgsFeatureRequest request = QgsFeatureRequest() );
QgsFeatureIterator selectedFeaturesIterator( QgsFeatureRequest request = QgsFeatureRequest() ) const;
/**
* Return reference to identifiers of selected features
@ -788,7 +788,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
Q_DECL_DEPRECATED void setSelectedFeatures( const QgsFeatureIds &ids );
/** 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
@ -944,7 +944,7 @@ class CORE_EXPORT QgsVectorLayer : public 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
@ -978,7 +978,7 @@ class CORE_EXPORT QgsVectorLayer : public 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.
@ -1474,7 +1474,7 @@ class CORE_EXPORT QgsVectorLayer : public 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
@ -1624,7 +1624,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
Q_DECL_DEPRECATED RangeData range( int idx );
/** Access value relation widget data */
ValueRelationData valueRelation( int idx );
ValueRelationData valueRelation( int idx ) const;
/**
* Get relations, where the foreign key is on this layer
@ -1632,7 +1632,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
* @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
@ -1717,13 +1717,13 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
* @param uniqueValues out: result list
* @param limit maximum number of values to return (-1 if unlimited)
*/
void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
void uniqueValues( int index, QList<QVariant> &uniqueValues, 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
@ -1738,7 +1738,7 @@ class CORE_EXPORT QgsVectorLayer : public 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
@ -1748,7 +1748,7 @@ class CORE_EXPORT QgsVectorLayer : public 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.
@ -1760,7 +1760,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
* @note added in QGIS 2.9
* @see getValues
*/
QList< double > getDoubleValues( const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, int* nullCount = nullptr );
QList< double > getDoubleValues( const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, int* nullCount = nullptr ) const;
/** Set the blending mode used for rendering each feature */
void setFeatureBlendMode( QPainter::CompositionMode blendMode );