Skip to content

Commit

Permalink
Const correctness for numerous data provider methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 14, 2016
1 parent fd42ed3 commit 1bafa80
Show file tree
Hide file tree
Showing 44 changed files with 375 additions and 555 deletions.
15 changes: 15 additions & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ This page tries to maintain a list with incompatible changes that happened in pr

\section qgis_api_break_3_0 QGIS 3.0

\subsection qgis_api_break_3_0_DataProviders Data Providers

<ul>
<li>Many methods in QgsDataProvider, QgsVectorDataProvider and QgsRasterDataProvider have been made const-correct.
This has no effect on PyQGIS code, but c++ code implementing third-party providers will need to update the
signatures of these methods to match. Affected methods are:
<ul>
<li>QgsDataProvider: crs(), extent(), isValid(), supportsSubsetString(), subsetString()</li>
<li>QgsVectorDataProvider: getFeatures(), minimumValue(), maximumValue(), uniqueValues(), enumValues(), defaultValue(),
attributeIndexes(), pkAttributeIndexes(), isSaveAndLoadStyleToDBSupported()</li>
<li>QgsRasterInterface: extent()</li>
</ul
</li>
</ul>

\subsection qgis_api_break_3_0_QgsVectorFileWriter QgsVectorFileWriter

<ul>
Expand Down
25 changes: 12 additions & 13 deletions python/core/qgsdataprovider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ class QgsDataProvider : QObject
virtual ~QgsDataProvider();


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


/**
Expand All @@ -82,21 +81,21 @@ class QgsDataProvider : QObject


/**
* Get the extent of the layer
* Returns the extent of the layer.
* @return QgsRectangle containing the extent of the layer
*/
virtual QgsRectangle extent() = 0;
virtual QgsRectangle extent() const = 0;


/**
* Returns true if this is a valid layer. It is up to individual providers
* to determine what constitutes a valid layer
* to determine what constitutes a valid layer.
*/
virtual bool isValid() = 0;
virtual bool isValid() const = 0;


/**
* Update the extents of the layer. Not implemented by default
* Update the extents of the layer. Not implemented by default.
*/
virtual void updateExtents();

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

/** Provider supports setting of subset strings */
virtual bool supportsSubsetString();
/** Returns true if the provider supports setting of subset strings. */
virtual bool supportsSubsetString() const;

/**
* Returns the subset definition string (typically sql) currently in
* use by the layer and used by the provider to limit the feature set.
* Must be overridden in the dataprovider, otherwise returns a null
* QString.
*/
virtual QString subsetString();
virtual QString subsetString() const;


/**
Expand Down
32 changes: 18 additions & 14 deletions python/core/qgsvectordataprovider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ class QgsVectorDataProvider : QgsDataProvider

/**
* Query the provider for features specified in request.
* @param request feature request describing parameters of features to return
* @returns iterator for matching features from provider
*/
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0;
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) const = 0;

/**
* Get feature type.
Expand Down Expand Up @@ -134,7 +136,7 @@ class QgsVectorDataProvider : QgsDataProvider
* and maximal values. If provider has facilities to retrieve minimal
* value directly, override this function.
*/
virtual QVariant minimumValue( int index );
virtual QVariant minimumValue( int index ) const;

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

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

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

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

/**
* Adds a list of features
Expand Down Expand Up @@ -236,7 +238,7 @@ class QgsVectorDataProvider : QgsDataProvider
/**
* Returns the default value for field specified by @c fieldId
*/
virtual QVariant defaultValue( int fieldId );
virtual QVariant defaultValue( int fieldId ) const;

/**
* Changes geometries of existing features
Expand Down Expand Up @@ -291,12 +293,12 @@ class QgsVectorDataProvider : QgsDataProvider
/**
* Return list of indexes to fetch all attributes in nextFeature()
*/
virtual QList<int> attributeIndexes();
virtual QList<int> attributeIndexes() const;

/**
* Return list of indexes of fields that make up the primary key
*/
virtual QList<int> pkAttributeIndexes();
virtual QList<int> pkAttributeIndexes() const;

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

/** Returns a list of available encodings */
static const QStringList &availableEncodings();
static QStringList availableEncodings();

/**
* Provider has errors to report
*/
bool hasErrors();
bool hasErrors() const;

/**
* Clear recorded errors
Expand All @@ -348,14 +350,14 @@ class QgsVectorDataProvider : QgsDataProvider
/**
* Get recorded errors
*/
QStringList errors();
QStringList errors() const;


/**
* It returns false by default.
* Must be implemented by providers that support saving and loading styles to db returning true
*/
virtual bool isSaveAndLoadStyleToDBSupported();
virtual bool isSaveAndLoadStyleToDBSupported() const;

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

Expand Down Expand Up @@ -384,7 +386,9 @@ class QgsVectorDataProvider : QgsDataProvider

protected:
void clearMinMaxCache();
void fillMinMaxCache();

//! Populates the cache of minimum and maximum attribute values.
void fillMinMaxCache() const;

void pushError( const QString& msg );

Expand Down
4 changes: 2 additions & 2 deletions python/core/raster/qgsrasterdataprovider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
/** Get the extent of the data source.
* @return QgsRectangle containing the extent of the layer
*/
virtual QgsRectangle extent() = 0;
virtual QgsRectangle extent() const = 0;

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

protected:
/** Read block of data
Expand Down
2 changes: 1 addition & 1 deletion python/core/raster/qgsrasterinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class QgsRasterInterface
* Get the extent of the interface.
* @return QgsRectangle containing the extent of the layer
*/
virtual QgsRectangle extent();
virtual QgsRectangle extent() const;

int dataTypeSize( int bandNo );

Expand Down
26 changes: 13 additions & 13 deletions src/core/qgsdataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,11 @@ class CORE_EXPORT QgsDataProvider : public QObject
virtual ~QgsDataProvider() {}


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


/**
Expand Down Expand Up @@ -126,21 +125,21 @@ class CORE_EXPORT QgsDataProvider : public QObject


/**
* Get the extent of the layer
* Returns the extent of the layer
* @return QgsRectangle containing the extent of the layer
*/
virtual QgsRectangle extent() = 0;
virtual QgsRectangle extent() const = 0;


/**
* Returns true if this is a valid layer. It is up to individual providers
* to determine what constitutes a valid layer
* to determine what constitutes a valid layer.
*/
virtual bool isValid() = 0;
virtual bool isValid() const = 0;


/**
* Update the extents of the layer. Not implemented by default
* Update the extents of the layer. Not implemented by default.
*/
virtual void updateExtents()
{
Expand All @@ -163,16 +162,17 @@ class CORE_EXPORT QgsDataProvider : public QObject
}


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

/**
* Returns the subset definition string (typically sql) currently in
* use by the layer and used by the provider to limit the feature set.
* Must be overridden in the dataprovider, otherwise returns a null
* QString.
*/
virtual QString subsetString()
virtual QString subsetString() const
{
return QString::null;
}
Expand Down
20 changes: 10 additions & 10 deletions src/core/qgsvectordataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ bool QgsVectorDataProvider::changeAttributeValues( const QgsChangedAttributesMap
return false;
}

QVariant QgsVectorDataProvider::defaultValue( int fieldId )
QVariant QgsVectorDataProvider::defaultValue( int fieldId ) const
{
Q_UNUSED( fieldId );
return QVariant();
Expand Down Expand Up @@ -275,7 +275,7 @@ QMap<QString, int> QgsVectorDataProvider::fieldNameMap() const
return resultMap;
}

QgsAttributeList QgsVectorDataProvider::attributeIndexes()
QgsAttributeList QgsVectorDataProvider::attributeIndexes() const
{
return fields().allAttributesList();
}
Expand Down Expand Up @@ -353,7 +353,7 @@ bool QgsVectorDataProvider::supportedType( const QgsField &field ) const
return false;
}

QVariant QgsVectorDataProvider::minimumValue( int index )
QVariant QgsVectorDataProvider::minimumValue( int index ) const
{
if ( index < 0 || index >= fields().count() )
{
Expand All @@ -369,7 +369,7 @@ QVariant QgsVectorDataProvider::minimumValue( int index )
return mCacheMinValues[index];
}

QVariant QgsVectorDataProvider::maximumValue( int index )
QVariant QgsVectorDataProvider::maximumValue( int index ) const
{
if ( index < 0 || index >= fields().count() )
{
Expand All @@ -385,7 +385,7 @@ QVariant QgsVectorDataProvider::maximumValue( int index )
return mCacheMaxValues[index];
}

void QgsVectorDataProvider::uniqueValues( int index, QList<QVariant> &values, int limit )
void QgsVectorDataProvider::uniqueValues( int index, QList<QVariant> &values, int limit ) const
{
QgsFeature f;
QgsAttributeList keys;
Expand All @@ -409,7 +409,7 @@ void QgsVectorDataProvider::uniqueValues( int index, QList<QVariant> &values, in
}

QVariant QgsVectorDataProvider::aggregate( QgsAggregateCalculator::Aggregate aggregate, int index,
const QgsAggregateCalculator::AggregateParameters& parameters, QgsExpressionContext* context, bool& ok )
const QgsAggregateCalculator::AggregateParameters& parameters, QgsExpressionContext* context, bool& ok ) const
{
//base implementation does nothing
Q_UNUSED( aggregate );
Expand All @@ -426,7 +426,7 @@ void QgsVectorDataProvider::clearMinMaxCache()
mCacheMinMaxDirty = true;
}

void QgsVectorDataProvider::fillMinMaxCache()
void QgsVectorDataProvider::fillMinMaxCache() const
{
if ( !mCacheMinMaxDirty )
return;
Expand Down Expand Up @@ -527,7 +527,7 @@ static bool _compareEncodings( const QString& s1, const QString& s2 )
return s1.toLower() < s2.toLower();
}

const QStringList &QgsVectorDataProvider::availableEncodings()
QStringList QgsVectorDataProvider::availableEncodings()
{
if ( smEncodings.isEmpty() )
{
Expand Down Expand Up @@ -595,12 +595,12 @@ void QgsVectorDataProvider::clearErrors()
mErrors.clear();
}

bool QgsVectorDataProvider::hasErrors()
bool QgsVectorDataProvider::hasErrors() const
{
return !mErrors.isEmpty();
}

QStringList QgsVectorDataProvider::errors()
QStringList QgsVectorDataProvider::errors() const
{
return mErrors;
}
Expand Down
Loading

0 comments on commit 1bafa80

Please sign in to comment.