Skip to content
Permalink
Browse files

Const correctness for numerous data provider methods

  • Loading branch information
nyalldawson committed Jul 14, 2016
1 parent fd42ed3 commit 1bafa80089c65f6e694d5471665a2c34e3e1c56a
Showing with 375 additions and 555 deletions.
  1. +15 −0 doc/api_break.dox
  2. +12 −13 python/core/qgsdataprovider.sip
  3. +18 −14 python/core/qgsvectordataprovider.sip
  4. +2 −2 python/core/raster/qgsrasterdataprovider.sip
  5. +1 −1 python/core/raster/qgsrasterinterface.sip
  6. +13 −13 src/core/qgsdataprovider.h
  7. +10 −10 src/core/qgsvectordataprovider.cpp
  8. +20 −16 src/core/qgsvectordataprovider.h
  9. +3 −6 src/core/raster/qgsrasterdataprovider.h
  10. +1 −1 src/core/raster/qgsrasterinterface.h
  11. +1 −1 src/providers/arcgisrest/qgsafsprovider.cpp
  12. +5 −5 src/providers/arcgisrest/qgsafsprovider.h
  13. +3 −3 src/providers/arcgisrest/qgsamsprovider.h
  14. +6 −6 src/providers/db2/qgsdb2provider.cpp
  15. +14 −30 src/providers/db2/qgsdb2provider.h
  16. +11 −12 src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
  17. +30 −44 src/providers/delimitedtext/qgsdelimitedtextprovider.h
  18. +3 −3 src/providers/gdal/qgsgdalprovider.cpp
  19. +3 −12 src/providers/gdal/qgsgdalprovider.h
  20. +5 −5 src/providers/gpx/qgsgpxprovider.cpp
  21. +5 −13 src/providers/gpx/qgsgpxprovider.h
  22. +13 −13 src/providers/grass/qgsgrassprovider.cpp
  23. +7 −14 src/providers/grass/qgsgrassprovider.h
  24. +3 −3 src/providers/grass/qgsgrassrasterprovider.cpp
  25. +3 −10 src/providers/grass/qgsgrassrasterprovider.h
  26. +5 −5 src/providers/memory/qgsmemoryprovider.cpp
  27. +6 −14 src/providers/memory/qgsmemoryprovider.h
  28. +10 −10 src/providers/mssql/qgsmssqlprovider.cpp
  29. +17 −60 src/providers/mssql/qgsmssqlprovider.h
  30. +8 −8 src/providers/ogr/qgsogrprovider.cpp
  31. +11 −14 src/providers/ogr/qgsogrprovider.h
  32. +3 −3 src/providers/ows/qgsowsprovider.h
  33. +11 −11 src/providers/postgres/qgspostgresprovider.cpp
  34. +15 −48 src/providers/postgres/qgspostgresprovider.h
  35. +9 −9 src/providers/spatialite/qgsspatialiteprovider.cpp
  36. +11 −33 src/providers/spatialite/qgsspatialiteprovider.h
  37. +6 −6 src/providers/virtual/qgsvirtuallayerprovider.cpp
  38. +7 −14 src/providers/virtual/qgsvirtuallayerprovider.h
  39. +7 −7 src/providers/wcs/qgswcsprovider.cpp
  40. +19 −28 src/providers/wcs/qgswcsprovider.h
  41. +5 −5 src/providers/wfs/qgswfsprovider.cpp
  42. +6 −7 src/providers/wfs/qgswfsprovider.h
  43. +5 −5 src/providers/wms/qgswmsprovider.cpp
  44. +7 −18 src/providers/wms/qgswmsprovider.h
@@ -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>
@@ -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;


/**
@@ -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();

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


/**
@@ -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.
@@ -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
@@ -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
@@ -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.
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 );

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

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

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


/**
@@ -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()
{
@@ -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;
}
@@ -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();
@@ -275,7 +275,7 @@ QMap<QString, int> QgsVectorDataProvider::fieldNameMap() const
return resultMap;
}

QgsAttributeList QgsVectorDataProvider::attributeIndexes()
QgsAttributeList QgsVectorDataProvider::attributeIndexes() const
{
return fields().allAttributesList();
}
@@ -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() )
{
@@ -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() )
{
@@ -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;
@@ -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 );
@@ -426,7 +426,7 @@ void QgsVectorDataProvider::clearMinMaxCache()
mCacheMinMaxDirty = true;
}

void QgsVectorDataProvider::fillMinMaxCache()
void QgsVectorDataProvider::fillMinMaxCache() const
{
if ( !mCacheMinMaxDirty )
return;
@@ -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() )
{
@@ -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;
}

0 comments on commit 1bafa80

Please sign in to comment.
You can’t perform that action at this time.