Skip to content

Commit

Permalink
Merge pull request #3335 from nyalldawson/vector_layer
Browse files Browse the repository at this point in the history
QgsVectorDataProvider::Capability improvements
  • Loading branch information
nyalldawson authored Jul 28, 2016
2 parents d87f2ab + 58856fe commit 429fe2d
Show file tree
Hide file tree
Showing 30 changed files with 65 additions and 73 deletions.
5 changes: 4 additions & 1 deletion doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,15 @@ attributeIndexes(), pkAttributeIndexes(), isSaveAndLoadStyleToDBSupported()</li>
<li>QgsGroupWMSDataDialo has been renamed to QgsGroupWmsDataDialog</li>
</ul>

\subsection qgis_api_break_3_0_DataProviders Data Providers
\subsection qgis_api_break_3_0_QgsVectorDataProvider QgsVectorDataProvider

<ul>
<li>QgsVectorDataProvider::fields() now returns a copy, rather than a const reference. Since QgsFields
objects are implicitly shared, returning a copy helps simplify and make code more robust. This change
only affects third party c++ providers, and does not affect PyQGIS scripts.</li>
<li>The SaveAsShapefile, SelectGeometryAtId, RandomSelectGeometryAtId and SequentialSelectGeometryAtId
capabilities have been removed, as they were unused and had no effect.</li>
<li>capabilities() now returns a typesafe QgsVectorDataProvider::Capabilities object, not an integer.</li>
</ul>

\subsection qgis_api_break_3_0_QgsLabelingEngineInterface QgsLabelingEngineInterface
Expand Down
15 changes: 5 additions & 10 deletions python/core/qgsvectordataprovider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,13 @@ class QgsVectorDataProvider : QgsDataProvider
AddAttributes,
/** Allows deletion of attributes (fields) */
DeleteAttributes,
/** DEPRECATED - do not use */
SaveAsShapefile,
/** Allows creation of spatial index */
CreateSpatialIndex,
/** Fast access to features using their ID */
SelectAtId,
/** Allows modifications of geometries */
ChangeGeometries,
/** DEPRECATED - do not use */
SelectGeometryAtId,
/** DEPRECATED - do not use */
RandomSelectGeometryAtId,
/** DEPRECATED - do not use */
SequentialSelectGeometryAtId,
/** DEPRECATED - do not use */
CreateAttributeIndex,
/** Allows user to select encoding */
SelectEncoding,
Expand All @@ -58,6 +50,7 @@ class QgsVectorDataProvider : QgsDataProvider
/** Supports renaming attributes (fields). Added in QGIS 2.16 */
RenameAttributes,
};
typedef QFlags<QgsVectorDataProvider::Capability> Capabilities;

/** Bitmask of all provider's editing capabilities */
static const int EditingCapabilities;
Expand Down Expand Up @@ -257,11 +250,11 @@ class QgsVectorDataProvider : QgsDataProvider
virtual bool createAttributeIndex( int field );

/** Returns a bitmask containing the supported capabilities
Note, some capabilities may change depending on whether
@note, some capabilities may change depending on whether
a spatial filter is active on this provider, so it may
be prudent to check this value per intended operation.
*/
virtual int capabilities() const;
virtual Capabilities capabilities() const;

/**
* Returns the above in friendly format.
Expand Down Expand Up @@ -394,3 +387,5 @@ class QgsVectorDataProvider : QgsDataProvider
@return the converted geometry or nullptr if no conversion was necessary or possible*/
QgsGeometry* convertToProviderType( const QgsGeometry* geom ) const /Factory/;
};

QFlags<QgsVectorDataProvider::Capability> operator|(QgsVectorDataProvider::Capability f1, QFlags<QgsVectorDataProvider::Capability> f2);
2 changes: 1 addition & 1 deletion src/core/qgsvectordataprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ bool QgsVectorDataProvider::createAttributeIndex( int field )
return true;
}

int QgsVectorDataProvider::capabilities() const
QgsVectorDataProvider::Capabilities QgsVectorDataProvider::capabilities() const
{
return QgsVectorDataProvider::NoCapabilities;
}
Expand Down
22 changes: 9 additions & 13 deletions src/core/qgsvectordataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,16 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
AddAttributes = 1 << 3,
/** Allows deletion of attributes (fields) */
DeleteAttributes = 1 << 4,
/** DEPRECATED - do not use */
SaveAsShapefile = 1 << 5,
/** Allows creation of spatial index */
CreateSpatialIndex = 1 << 6,
/** Fast access to features using their ID */
SelectAtId = 1 << 7,
/** Allows modifications of geometries */
ChangeGeometries = 1 << 8,
/** DEPRECATED - do not use */
SelectGeometryAtId = 1 << 9,
/** DEPRECATED - do not use */
RandomSelectGeometryAtId = 1 << 10,
/** DEPRECATED - do not use */
SequentialSelectGeometryAtId = 1 << 11,
/** DEPRECATED - do not use */
CreateAttributeIndex = 1 << 12,
/** Allows user to select encoding */
SelectEncoding = 1 << 13,
/** DEPRECATED - do not use */
CreateAttributeIndex = 1 << 12,
/** Supports simplification of geometries on provider side according to a distance tolerance */
SimplifyGeometries = 1 << 14,
/** Supports topological simplification of geometries on provider side according to a distance tolerance */
Expand All @@ -105,6 +97,8 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
RenameAttributes = 1 << 19,
};

Q_DECLARE_FLAGS( Capabilities, Capability )

/** Bitmask of all provider's editing capabilities */
const static int EditingCapabilities = AddFeatures | DeleteFeatures |
ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes |
Expand Down Expand Up @@ -304,12 +298,12 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
/** Create an attribute index on the datasource*/
virtual bool createAttributeIndex( int field );

/** Returns a bitmask containing the supported capabilities
Note, some capabilities may change depending on whether
/** Returns flags containing the supported capabilities
@note, some capabilities may change depending on whether
a spatial filter is active on this provider, so it may
be prudent to check this value per intended operation.
*/
virtual int capabilities() const;
virtual Capabilities capabilities() const;

/**
* Returns the above in friendly format.
Expand Down Expand Up @@ -484,5 +478,7 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider

};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsVectorDataProvider::Capabilities )


#endif
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsafsprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class QgsAfsProvider : public QgsVectorDataProvider
bool changeAttributeValues( const QgsChangedAttributesMap &attr_map ) override{ return false; }
bool changeGeometryValues( QgsGeometryMap & geometry_map ) override{ return false; }
*/
int capabilities() const override { return QgsVectorDataProvider::NoCapabilities; }
QgsVectorDataProvider::Capabilities capabilities() const override { return QgsVectorDataProvider::NoCapabilities; }
QgsAttributeList pkAttributeIndexes() const override { return QgsAttributeList() << mObjectIdFieldIdx; }
QgsAttrPalIndexNameHash palAttributeIndexNames() const override { return QgsAttrPalIndexNameHash(); }

Expand Down
6 changes: 3 additions & 3 deletions src/providers/db2/qgsdb2provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1179,9 +1179,9 @@ bool QgsDb2Provider::addFeatures( QgsFeatureList & flist )
return true;
}

int QgsDb2Provider::capabilities() const
QgsVectorDataProvider::Capabilities QgsDb2Provider::capabilities() const
{
int cap = AddFeatures;
QgsVectorDataProvider::Capabilities cap = AddFeatures;
bool hasGeom = false;
if ( !mGeometryColName.isEmpty() )
{
Expand All @@ -1194,7 +1194,7 @@ int QgsDb2Provider::capabilities() const
else
{
if ( hasGeom )
cap |= ChangeGeometries | QgsVectorDataProvider::SelectGeometryAtId;
cap |= ChangeGeometries;

return cap | DeleteFeatures | ChangeAttributeValues |
QgsVectorDataProvider::SelectAtId;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/db2/qgsdb2provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class QgsDb2Provider : public QgsVectorDataProvider
a spatial filter is active on this provider, so it may
be prudent to check this value per intended operation.
*/
virtual int capabilities() const override;
virtual QgsVectorDataProvider::Capabilities capabilities() const override;

/** Writes a list of features to the database*/
virtual bool addFeatures( QgsFeatureList & flist ) override;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ bool QgsDelimitedTextProvider::isValid() const
return mLayerValid;
}

int QgsDelimitedTextProvider::capabilities() const
QgsVectorDataProvider::Capabilities QgsDelimitedTextProvider::capabilities() const
{
return SelectAtId | CreateSpatialIndex | CircularGeometries;
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/delimitedtext/qgsdelimitedtextprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class QgsDelimitedTextProvider : public QgsVectorDataProvider
* a spatial filter is active on this provider, so it may
* be prudent to check this value per intended operation.
*/
virtual int capabilities() const override;
virtual QgsVectorDataProvider::Capabilities capabilities() const override;

/** Creates a spatial index on the data
* @return indexCreated Returns true if a spatial index is created
Expand Down
2 changes: 1 addition & 1 deletion src/providers/gpx/qgsgpxprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ QString QgsGPXProvider::storageType() const
return tr( "GPS eXchange file" );
}

int QgsGPXProvider::capabilities() const
QgsVectorDataProvider::Capabilities QgsGPXProvider::capabilities() const
{
return QgsVectorDataProvider::AddFeatures |
QgsVectorDataProvider::DeleteFeatures |
Expand Down
2 changes: 1 addition & 1 deletion src/providers/gpx/qgsgpxprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class QgsGPXProvider : public QgsVectorDataProvider
*/
virtual bool changeAttributeValues( const QgsChangedAttributesMap & attr_map ) override;

virtual int capabilities() const override;
virtual QgsVectorDataProvider::Capabilities capabilities() const override;

virtual QVariant defaultValue( int fieldId ) const override;

Expand Down
2 changes: 1 addition & 1 deletion src/providers/grass/qgsgrassprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ QgsGrassProvider::~QgsGrassProvider()
}
}

int QgsGrassProvider::capabilities() const
QgsVectorDataProvider::Capabilities QgsGrassProvider::capabilities() const
{
// Because of bug in GRASS https://trac.osgeo.org/grass/ticket/2775 it is not possible
// close db drivers in random order on Unix and probably Mac -> disable editing if another layer is edited
Expand Down
2 changes: 1 addition & 1 deletion src/providers/grass/qgsgrassprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class GRASS_LIB_EXPORT QgsGrassProvider : public QgsVectorDataProvider

virtual ~QgsGrassProvider();

virtual int capabilities() const override;
virtual QgsVectorDataProvider::Capabilities capabilities() const override;

virtual QgsAbstractFeatureSource* featureSource() const override;

Expand Down
4 changes: 2 additions & 2 deletions src/providers/memory/qgsmemoryprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,11 @@ bool QgsMemoryProvider::createSpatialIndex()
return true;
}

int QgsMemoryProvider::capabilities() const
QgsVectorDataProvider::Capabilities QgsMemoryProvider::capabilities() const
{
return AddFeatures | DeleteFeatures | ChangeGeometries |
ChangeAttributeValues | AddAttributes | DeleteAttributes | RenameAttributes | CreateSpatialIndex |
SelectAtId | SelectGeometryAtId | CircularGeometries;
SelectAtId | CircularGeometries;
}


Expand Down
2 changes: 1 addition & 1 deletion src/providers/memory/qgsmemoryprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class QgsMemoryProvider : public QgsVectorDataProvider
a spatial filter is active on this provider, so it may
be prudent to check this value per intended operation.
*/
virtual int capabilities() const override;
virtual QgsVectorDataProvider::Capabilities capabilities() const override;

/* Implementation of functions from QgsDataProvider */

Expand Down
6 changes: 3 additions & 3 deletions src/providers/mssql/qgsmssqlprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,9 +1310,9 @@ bool QgsMssqlProvider::deleteFeatures( const QgsFeatureIds & id )
return true;
}

int QgsMssqlProvider::capabilities() const
QgsVectorDataProvider::Capabilities QgsMssqlProvider::capabilities() const
{
int cap = CreateAttributeIndex | AddFeatures | AddAttributes;
QgsVectorDataProvider::Capabilities cap = CreateAttributeIndex | AddFeatures | AddAttributes;
bool hasGeom = false;
if ( !mGeometryColName.isEmpty() )
{
Expand All @@ -1325,7 +1325,7 @@ int QgsMssqlProvider::capabilities() const
else
{
if ( hasGeom )
cap |= ChangeGeometries | QgsVectorDataProvider::SelectGeometryAtId;
cap |= ChangeGeometries;

return cap | DeleteFeatures | ChangeAttributeValues | DeleteAttributes |
QgsVectorDataProvider::SelectAtId;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/mssql/qgsmssqlprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class QgsMssqlProvider : public QgsVectorDataProvider
a spatial filter is active on this provider, so it may
be prudent to check this value per intended operation.
*/
virtual int capabilities() const override;
virtual QgsVectorDataProvider::Capabilities capabilities() const override;


/* Implementation of functions from QgsDataProvider */
Expand Down
6 changes: 3 additions & 3 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1738,14 +1738,14 @@ bool QgsOgrProvider::doInitialActionsForEdition()
return true;
}

int QgsOgrProvider::capabilities() const
QgsVectorDataProvider::Capabilities QgsOgrProvider::capabilities() const
{
return mCapabilities;
}

void QgsOgrProvider::computeCapabilities()
{
int ability = 0;
QgsVectorDataProvider::Capabilities ability = 0;

// collect abilities reported by OGR
if ( ogrLayer )
Expand All @@ -1763,7 +1763,7 @@ void QgsOgrProvider::computeCapabilities()
// (vs read from disk every time) based on this setting.
{
// the latter flag is here just for compatibility
ability |= QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
ability |= QgsVectorDataProvider::SelectAtId;
}

if ( mWriteAccessPossible && OGR_L_TestCapability( ogrLayer, "SequentialWrite" ) )
Expand Down
4 changes: 2 additions & 2 deletions src/providers/ogr/qgsogrprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class QgsOgrProvider : public QgsVectorDataProvider
be prudent to check this value per intended operation.
See the OGRLayer::TestCapability API for details.
*/
virtual int capabilities() const override;
virtual QgsVectorDataProvider::Capabilities capabilities() const override;

virtual void setEncoding( const QString& e ) override;

Expand Down Expand Up @@ -369,7 +369,7 @@ class QgsOgrProvider : public QgsVectorDataProvider

void computeCapabilities();

int mCapabilities;
QgsVectorDataProvider::Capabilities mCapabilities;

bool doInitialActionsForEdition();
};
Expand Down
4 changes: 2 additions & 2 deletions src/providers/oracle/qgsoracleprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ bool QgsOracleProvider::hasSufficientPermsAndCapabilities()
{
QgsDebugMsg( "Checking for permissions on the relation" );

mEnabledCapabilities = QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
mEnabledCapabilities = QgsVectorDataProvider::SelectAtId;

QSqlQuery qry( *mConnection );
if ( !mIsQuery )
Expand Down Expand Up @@ -2064,7 +2064,7 @@ bool QgsOracleProvider::changeGeometryValues( const QgsGeometryMap &geometry_map
return returnvalue;
}

int QgsOracleProvider::capabilities() const
QgsVectorDataProvider::Capabilities QgsOracleProvider::capabilities() const
{
return mEnabledCapabilities;
}
Expand Down
4 changes: 2 additions & 2 deletions src/providers/oracle/qgsoracleprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class QgsOracleProvider : public QgsVectorDataProvider
virtual bool supportsSubsetString() const override { return true; }

/** Returns a bitmask containing the supported capabilities*/
int capabilities() const override;
QgsVectorDataProvider::Capabilities capabilities() const override;

/** Return a provider name
*
Expand Down Expand Up @@ -350,7 +350,7 @@ class QgsOracleProvider : public QgsVectorDataProvider
mutable QgsRectangle mLayerExtent; //! Rectangle that contains the extent (bounding box) of the layer
mutable long mFeaturesCounted; //! Number of features in the layer
int mSrid; //! srid of column
int mEnabledCapabilities; //! capabilities of layer
QgsVectorDataProvider::Capabilities mEnabledCapabilities; //! capabilities of layer

Qgis::WkbType mDetectedGeomType; //! geometry type detected in the database
Qgis::WkbType mRequestedGeomType; //! geometry type requested in the uri
Expand Down
6 changes: 3 additions & 3 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ bool QgsPostgresProvider::hasSufficientPermsAndCapabilities()
// the latter flag is here just for compatibility
if ( !mSelectAtIdDisabled )
{
mEnabledCapabilities = QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
mEnabledCapabilities = QgsVectorDataProvider::SelectAtId;
}

if ( !inRecovery )
Expand Down Expand Up @@ -1209,7 +1209,7 @@ bool QgsPostgresProvider::hasSufficientPermsAndCapabilities()

if ( !mSelectAtIdDisabled )
{
mEnabledCapabilities = QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
mEnabledCapabilities = QgsVectorDataProvider::SelectAtId;
}
}

Expand Down Expand Up @@ -2829,7 +2829,7 @@ QgsAttributeList QgsPostgresProvider::attributeIndexes() const
return lst;
}

int QgsPostgresProvider::capabilities() const
QgsVectorDataProvider::Capabilities QgsPostgresProvider::capabilities() const
{
return mEnabledCapabilities;
}
Expand Down
Loading

0 comments on commit 429fe2d

Please sign in to comment.