Skip to content

Commit

Permalink
providers: deprecated some overlapping capabilities and added doxygen…
Browse files Browse the repository at this point in the history
… docs for them.

All providers should have now correctly set capability for fast access to features by id (SelectAtId).

Until now, attribute table was using memory model for Postgres provider (i.e. very slow open)
From now it uses the "good" model, so the attribute table opens much faster.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11137 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jul 21, 2009
1 parent 3a8592b commit 2f68613
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 33 deletions.
6 changes: 5 additions & 1 deletion src/app/attributetable/qgsattributetableview.cpp
Expand Up @@ -48,7 +48,11 @@ QgsAttributeTableView::QgsAttributeTableView( QWidget* parent )

void QgsAttributeTableView::setLayer( QgsVectorLayer* layer )
{
if ( layer->dataProvider()->capabilities() & QgsVectorDataProvider::RandomSelectGeometryAtId )
// in case the provider allows fast access to features
// we will use the model that calls featureAtId() to fetch only the
// features in the current view. Otherwise we'll have to store
// everything in the memory because using featureAtId() would be too slow
if ( layer->dataProvider()->capabilities() & QgsVectorDataProvider::SelectAtId )
mModel = new QgsAttributeTableModel( layer );
else
mModel = new QgsAttributeTableMemoryModel( layer );
Expand Down
23 changes: 1 addition & 22 deletions src/core/qgsvectordataprovider.cpp
Expand Up @@ -198,8 +198,7 @@ QString QgsVectorDataProvider::capabilitiesString() const

if ( abilities & QgsVectorDataProvider::SelectAtId )
{
// Not really meaningful to the user.
// abilitiesList += "Select at ID";
abilitiesList += "Fast Access to Features at ID";
QgsDebugMsg( "Capability: Select at ID" );
}

Expand All @@ -209,26 +208,6 @@ QString QgsVectorDataProvider::capabilitiesString() const
QgsDebugMsg( "Capability: Change Geometries" );
}

if ( abilities & QgsVectorDataProvider::SelectGeometryAtId )
{

if ( abilities & QgsVectorDataProvider::RandomSelectGeometryAtId )
{
abilitiesList += "Select Geometries by ID (random access)";
QgsDebugMsg( "Capability: Select Geometries by ID (random access)" );
}
else if ( abilities & QgsVectorDataProvider::SequentialSelectGeometryAtId )
{
abilitiesList += "Select Geometries by ID (sequential access)";
QgsDebugMsg( "Capability: Select Geometries by ID (sequential access)" );
}
else
{
abilitiesList += "Select Geometries by ID (unknown access method)";
QgsDebugMsg( "Capability: Select Geometries by ID (unknown access method)" );
}
}

return abilitiesList.join( ", " );

}
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsvectordataprovider.h
Expand Up @@ -47,18 +47,31 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
*/
enum Capability
{
/** provider has no capabilities */
NoCapabilities = 0,
/** allows adding features */
AddFeatures = 1,
/** allows deletion of features */
DeleteFeatures = 1 << 1,
/** allows modification of attribute values */
ChangeAttributeValues = 1 << 2,
/** allows addition of new attributes (fields) */
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
};

Expand Down
2 changes: 1 addition & 1 deletion src/providers/delimitedtext/qgsdelimitedtextprovider.cpp
Expand Up @@ -506,7 +506,7 @@ bool QgsDelimitedTextProvider::boundsCheck( double x, double y )

int QgsDelimitedTextProvider::capabilities() const
{
return 0;
return NoCapabilities;
}


Expand Down
2 changes: 1 addition & 1 deletion src/providers/memory/qgsmemoryprovider.cpp
Expand Up @@ -360,7 +360,7 @@ int QgsMemoryProvider::capabilities() const
{
return AddFeatures | DeleteFeatures | ChangeGeometries |
ChangeAttributeValues | AddAttributes | DeleteAttributes | CreateSpatialIndex |
SelectAtId | SelectGeometryAtId | RandomSelectGeometryAtId | SequentialSelectGeometryAtId;
SelectAtId | SelectGeometryAtId;
}


Expand Down
8 changes: 2 additions & 6 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -896,13 +896,9 @@ int QgsOgrProvider::capabilities() const
// TODO: Perhaps influence if QGIS caches into memory
// (vs read from disk every time) based on this setting.
{
ability |= QgsVectorDataProvider::RandomSelectGeometryAtId;
// the latter flag is here just for compatibility
ability |= QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
}
else
{
ability |= QgsVectorDataProvider::SequentialSelectGeometryAtId;
}
ability |= QgsVectorDataProvider::SelectGeometryAtId;

if ( OGR_L_TestCapability( ogrLayer, "SequentialWrite" ) )
// TRUE if the CreateFeature() method works for this layer.
Expand Down
4 changes: 3 additions & 1 deletion src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -131,7 +131,9 @@ QgsPostgresProvider::QgsPostgresProvider( QString const & uri )
return;
}

enabledCapabilities = QgsVectorDataProvider::SelectGeometryAtId;
// postgres has fast access to features at id (thanks to primary key / unique index)
// the latter flag is here just for compatibility
enabledCapabilities = QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;

if ( QString::fromUtf8( PQgetvalue( testAccess, 0, 0 ) ) == "t" )
{
Expand Down
2 changes: 1 addition & 1 deletion src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -71,7 +71,7 @@ QgsSpatiaLiteProvider::QgsSpatiaLiteProvider( QString const &uri ): QgsVectorDat
}
sqliteHandle = handle->handle();

enabledCapabilities = QgsVectorDataProvider::SelectGeometryAtId;
enabledCapabilities = QgsVectorDataProvider::SelectAtId | QgsVectorDataProvider::SelectGeometryAtId;
enabledCapabilities |= QgsVectorDataProvider::DeleteFeatures;
enabledCapabilities |= QgsVectorDataProvider::ChangeGeometries;
enabledCapabilities |= QgsVectorDataProvider::ChangeAttributeValues;
Expand Down

0 comments on commit 2f68613

Please sign in to comment.