2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
class QgsVectorDataProvider : QgsDataProvider
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsvectordataprovider.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// If you add to this, please also add to capabilitiesString()
|
|
|
|
/**
|
|
|
|
* enumeration with capabilities that providers might implement
|
|
|
|
*/
|
|
|
|
enum Capability
|
|
|
|
{
|
|
|
|
NoCapabilities = 0,
|
|
|
|
AddFeatures = 1,
|
|
|
|
DeleteFeatures = 2,
|
|
|
|
ChangeAttributeValues = 4,
|
|
|
|
AddAttributes = 8,
|
|
|
|
DeleteAttributes = 16,
|
|
|
|
SaveAsShapefile = 32,
|
|
|
|
CreateSpatialIndex = 64,
|
|
|
|
SelectAtId = 128,
|
|
|
|
ChangeGeometries = 256,
|
|
|
|
SelectGeometryAtId = 512,
|
|
|
|
RandomSelectGeometryAtId = 1024,
|
|
|
|
SequentialSelectGeometryAtId = 2048
|
|
|
|
};
|
|
|
|
|
2008-11-25 23:37:13 +00:00
|
|
|
/** bitmask of all provider's editing capabilities */
|
|
|
|
static const int EditingCapabilities;
|
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
/**
|
|
|
|
* Constructor of the vector provider
|
|
|
|
* @param uri uniform resource locator (URI) for a dataset
|
|
|
|
*/
|
|
|
|
QgsVectorDataProvider(QString uri = QString());
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
virtual ~QgsVectorDataProvider();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the permanent storage type for this layer as a friendly name.
|
|
|
|
*/
|
|
|
|
virtual QString storageType() const;
|
|
|
|
|
2008-10-07 07:36:24 +00:00
|
|
|
/** Select features based on a bounding rectangle. Features can be retrieved with calls to nextFeature.
|
2007-04-11 11:46:35 +00:00
|
|
|
* @param fetchAttributes list of attributes which should be fetched
|
|
|
|
* @param rect spatial filter
|
|
|
|
* @param fetchGeometry true if the feature geometry should be fetched
|
|
|
|
* @param useIntersect true if an accurate intersection test should be used,
|
|
|
|
* false if a test based on bounding box is sufficient
|
2007-01-09 02:39:15 +00:00
|
|
|
*/
|
2007-04-11 11:46:35 +00:00
|
|
|
virtual void select(QList<int> fetchAttributes = QList<int>(),
|
2008-11-09 00:14:12 +00:00
|
|
|
QgsRectangle rect = QgsRectangle(),
|
2007-04-11 11:46:35 +00:00
|
|
|
bool fetchGeometry = true,
|
|
|
|
bool useIntersect = false) = 0;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the feature count based on current spatial filter. If not
|
|
|
|
* overridden in the data provider this function returns -1
|
|
|
|
*/
|
|
|
|
virtual long updateFeatureCount();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the feature at the given feature ID.
|
|
|
|
* @param featureId id of the feature
|
|
|
|
* @param feature feature which will receive the data
|
|
|
|
* @param fetchGeoemtry if true, geometry will be fetched from the provider
|
|
|
|
* @param fetchAttributes a list containing the indexes of the attribute fields to copy
|
|
|
|
* @return True when feature was found, otherwise false
|
|
|
|
*/
|
2008-10-07 07:36:24 +00:00
|
|
|
virtual bool featureAtId(int featureId,
|
2007-01-09 02:39:15 +00:00
|
|
|
QgsFeature& feature,
|
|
|
|
bool fetchGeometry = true,
|
|
|
|
QList<int> fetchAttributes = QList<int>());
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the next feature resulting from a select operation.
|
|
|
|
* @param feature feature which will receive data from the provider
|
|
|
|
* @return true when there was a feature to fetch, false when end was hit
|
|
|
|
*/
|
2008-10-07 07:36:24 +00:00
|
|
|
virtual bool nextFeature(QgsFeature& feature) = 0;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get feature type.
|
|
|
|
* @return int representing the feature type
|
|
|
|
*/
|
2008-10-10 20:02:22 +00:00
|
|
|
virtual QGis::WkbType geometryType() const = 0;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of features in the layer
|
|
|
|
* @return long containing number of features
|
|
|
|
*/
|
|
|
|
virtual long featureCount() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of attribute fields for a feature in the layer
|
|
|
|
*/
|
|
|
|
virtual uint fieldCount() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a map of indexes with field names for this layer
|
|
|
|
* @return map of fields
|
|
|
|
*/
|
|
|
|
virtual const QMap<int, QgsField> & fields() const = 0;
|
|
|
|
|
2007-04-11 11:46:35 +00:00
|
|
|
/**
|
|
|
|
* Return a short comment for the data that this provider is
|
|
|
|
* providing access to (e.g. the comment for postgres table).
|
2007-01-09 02:39:15 +00:00
|
|
|
*/
|
2007-04-11 11:46:35 +00:00
|
|
|
virtual QString dataComment() const;
|
|
|
|
|
|
|
|
/** Restart reading features from previous select operation */
|
2008-11-08 00:49:59 +00:00
|
|
|
virtual void rewind() = 0;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the minimum value of an attributs
|
2007-04-11 11:46:35 +00:00
|
|
|
* @param index the index of the attribute
|
|
|
|
*
|
|
|
|
* Default implementation walks all numeric attributes and caches minimal
|
2008-07-16 09:21:41 +00:00
|
|
|
* and maximal values. If provider has facilities to retrieve minimal
|
2007-04-11 11:46:35 +00:00
|
|
|
* value directly, override this function.
|
2007-01-09 02:39:15 +00:00
|
|
|
*/
|
2008-08-23 09:19:49 +00:00
|
|
|
virtual QVariant minimumValue(int index);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the maximum value of an attributs
|
2007-04-11 11:46:35 +00:00
|
|
|
* @param index the index of the attribute
|
|
|
|
*
|
|
|
|
* Default implementation walks all numeric attributes and caches minimal
|
2008-07-16 09:21:41 +00:00
|
|
|
* and maximal values. If provider has facilities to retrieve maximal
|
2007-04-11 11:46:35 +00:00
|
|
|
* value directly, override this function.
|
2007-01-09 02:39:15 +00:00
|
|
|
*/
|
2008-08-27 22:13:27 +00:00
|
|
|
virtual QVariant maximumValue(int index);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2008-03-16 16:52:11 +00:00
|
|
|
/**
|
|
|
|
* Return unique values of an attribute
|
|
|
|
* @param index the index of the attribute
|
|
|
|
* @param values reference to the list to fill
|
|
|
|
*
|
|
|
|
* Default implementation simply iterates the features
|
|
|
|
*/
|
2008-11-21 22:55:58 +00:00
|
|
|
virtual void uniqueValues(int index, QList<QVariant> &uniqueValues /Out/);
|
2008-03-16 16:52:11 +00:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
/**
|
|
|
|
* Adds a list of features
|
|
|
|
* @return true in case of success and false in case of failure
|
|
|
|
*/
|
2008-06-03 15:25:22 +00:00
|
|
|
virtual bool addFeatures(QList<QgsFeature> & flist /In,Out/);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a feature
|
|
|
|
* @param id list containing feature ids to delete
|
|
|
|
* @return true in case of success and false in case of failure
|
|
|
|
*/
|
|
|
|
virtual bool deleteFeatures(const QSet<int> & id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds new attributes
|
|
|
|
* @param attributes map with attribute name as key and type as value
|
|
|
|
* @return true in case of success and false in case of failure
|
|
|
|
*/
|
|
|
|
virtual bool addAttributes(const QMap<QString, QString> & attributes);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes existing attributes
|
|
|
|
* @param attributes a set containing indexes of attributes
|
|
|
|
* @return true in case of success and false in case of failure
|
|
|
|
*/
|
|
|
|
virtual bool deleteAttributes(const QSet<int> & attributes);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes attribute values of existing features.
|
|
|
|
* @param attr_map a map containing changed attributes
|
|
|
|
* @return true in case of success and false in case of failure
|
|
|
|
*/
|
2007-03-24 22:40:10 +00:00
|
|
|
virtual bool changeAttributeValues(const QMap<int, QMap<int, QVariant> > & attr_map);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
2007-03-24 22:40:10 +00:00
|
|
|
* Returns the default value for field specified by @c fieldId
|
2007-01-09 02:39:15 +00:00
|
|
|
*/
|
2008-10-07 07:36:24 +00:00
|
|
|
virtual QVariant defaultValue(int fieldId);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes geometries of existing features
|
|
|
|
* @param geometry_map A std::map containing the feature IDs to change the geometries of.
|
|
|
|
* the second map parameter being the new geometries themselves
|
|
|
|
* @return true in case of success and false in case of failure
|
|
|
|
*/
|
|
|
|
virtual bool changeGeometryValues(QMap<int, QgsGeometry> & geometry_map);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a spatial index on the datasource (if supported by the provider type).
|
|
|
|
* @return true in case of success
|
|
|
|
*/
|
|
|
|
virtual bool createSpatialIndex();
|
|
|
|
|
|
|
|
/** Returns a bitmask 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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the above in friendly format.
|
|
|
|
*/
|
|
|
|
QString capabilitiesString() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set encoding used for accessing data from layer
|
|
|
|
*/
|
|
|
|
virtual void setEncoding(const QString& e);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get encoding which is used for accessing data
|
|
|
|
*/
|
|
|
|
QString encoding() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the index of a field name or -1 if the field does not exist
|
|
|
|
*/
|
2008-08-30 09:28:54 +00:00
|
|
|
int fieldNameIndex(const QString& fieldName) const;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-07 07:36:24 +00:00
|
|
|
* Return list of indexes to fetch all attributes in nextFeature()
|
2007-01-09 02:39:15 +00:00
|
|
|
*/
|
2008-10-07 07:36:24 +00:00
|
|
|
QList<int> attributeIndexes();
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2007-04-11 11:46:35 +00:00
|
|
|
/**Returns the names of the numerical types*/
|
handling vector data geometry and attribute updates refactored
QgsVectorLayer:
- move attribute part of editing to vector layer class and unify with geometry handling:
* remove commitAttributeChanges(), addedFeatures(), deletedFeatureIds(), changedAttributes()
and replace with changeAttributeValue(), deleteFeature(), addAttribute()
and deleteAttribute()
* add pendingFields(), pendingAttributeList(), pendingFeatureCount()
* emit signals on start editing and commit, change of attribute values, adding/deleting of
attributes and layer or feature removal (currently used in the attribute table)
- new commitErrors() method to query errors from commitChanges()
- replaced featuresInRectangle with select/getNextFeature combo
- edit types added to support more input widgets and input constraints
QgsFeature:
- remove update aware ctor
- unify geometry handling in ctors
QgsVectorDataProvider:
- add QVariant::Type to supportNativeTypes()
QgisApp:
- add instance() method to query QgisApp object
- replace code at various place to use it instead of passing the pointer
arround or searching it in the widget tree.
- move toggleEditing() code from the legend here
QgsAttributeTable/QgsAttributeTableDisplay:
- move attribute table creation legend here
- make attribute table dockable (from Tim)
- most editing logic moved to QgsVectorLayer
- adding/deleting attributes moved to QgsVectorLayerProperties
QgsIdentifyResults:
- add support for attribute editing when it edit mode
QgsVectorLayerProperties:
add a new tab to show attribute list:
* start/stop editing
* add/delete attributes
* assign edit type to attributes (unique values, value map, ranges)
QgsAttributeDialog:
add support for attribute edit types:
* selection from unique value render classes (combobox)
* selection from unique values of existing features (combobox or line edits with completion)
* spinboxes for ranges
QgsPostgresProvider:
- use read-only connection for cursors and read-write connection for updates
- updated native types
QgsOgrProvider:
- remove unused references to GEOS geometry factory
- updated native types
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9092 c8812cc2-4d05-0410-92ff-de0c093fc19c
2008-08-20 12:15:14 +00:00
|
|
|
const QMap<QString,QVariant::Type> &supportedNativeTypes() const;
|
2007-04-11 11:46:35 +00:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
/**
|
|
|
|
* Set whether provider should return also features that don't have
|
|
|
|
* associated geometry. FALSE by default
|
|
|
|
*/
|
2008-08-30 09:28:54 +00:00
|
|
|
void enableGeometrylessFeatures(bool fetch);
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
};
|