32 , mCacheMinMaxDirty( true )
36 setEncoding( settings.value(
"/UI/encoding",
"System" ).toString() );
46 return "Generic vector file";
68 Q_UNUSED( attributes );
74 Q_UNUSED( attributes );
92 Q_UNUSED( geometry_map );
115 QTextCodec* ncodec = QTextCodec::codecForName( e.toLocal8Bit().constData() );
123 mEncoding = QTextCodec::codecForName(
"System" );
126 mEncoding = QTextCodec::codecForLocale();
144 QStringList abilitiesList;
150 abilitiesList +=
tr(
"Add Features" );
156 abilitiesList +=
tr(
"Delete Features" );
162 abilitiesList +=
tr(
"Change Attribute Values" );
163 QgsDebugMsg(
"Capability: Change Attribute Values" );
168 abilitiesList +=
tr(
"Add Attributes" );
174 abilitiesList +=
tr(
"Delete Attributes" );
181 abilitiesList +=
tr(
"Create Spatial Index" );
187 abilitiesList +=
tr(
"Fast Access to Features at ID" );
193 abilitiesList +=
tr(
"Change Geometries" );
199 abilitiesList +=
tr(
"Simplify Geometries" );
200 QgsDebugMsg(
"Capability: Simplify Geometries before fetch the feature" );
205 abilitiesList +=
tr(
"Simplify Geometries with topological validation" );
206 QgsDebugMsg(
"Capability: Simplify Geometries before fetch the feature ensuring that the result is a valid geometry" );
209 return abilitiesList.join(
", " );
218 for (
int i = 0; i < theFields.
count(); ++i )
220 if ( QString::compare( theFields[i].
name(), fieldName, Qt::CaseInsensitive ) == 0 )
230 QMap<QString, int> resultMap;
233 for (
int i = 0; i < theFields.
count(); ++i )
235 resultMap.insert( theFields[i].
name(), i );
254 QgsDebugMsgLevel( QString(
"field name = %1 type = %2 length = %3 precision = %4" )
256 .arg( QVariant::typeToName( field.
type() ) )
261 QgsDebugMsgLevel( QString(
"native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" )
271 if ( field.
length() == -1 )
321 if ( index < 0 || index >=
fields().count() )
323 QgsDebugMsg(
"Warning: access requested to invalid field index: " + QString::number( index ) );
337 if ( index < 0 || index >=
fields().count() )
339 QgsDebugMsg(
"Warning: access requested to invalid field index: " + QString::number( index ) );
355 keys.append( index );
363 if ( !set.contains( f.
attribute( index ).toString() ) )
366 set.insert( f.
attribute( index ).toString() );
369 if ( limit >= 0 && values.size() >= limit )
385 for (
int i = 0; i < flds.
count(); ++i )
387 if ( flds[i].type() == QVariant::Int )
392 else if ( flds[i].type() == QVariant::Double )
411 for ( QgsAttributeList::const_iterator it = keys.begin(); it != keys.end(); ++it )
413 const QVariant& varValue = attrs[*it];
415 if ( flds[*it].type() == QVariant::Int )
417 int value = varValue.toInt();
423 else if ( flds[*it].type() == QVariant::Double )
425 double value = varValue.toDouble();
433 QString value = varValue.toString();
453 if ( !v.convert( type ) || value.isNull() )
454 v = QVariant( type );
461 return s1.toLower() < s2.toLower();
468 foreach ( QString codec, QTextCodec::availableCodecs() )
const QString & name() const
Gets the name of the field.
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
static bool _compareEncodings(const QString &s1, const QString &s2)
virtual bool addAttributes(const QList< QgsField > &attributes)
Adds new attributes.
QString capabilitiesString() const
Returns the above in friendly format.
QSet< QgsFeatureId > QgsFeatureIds
QList< QgsFeature > QgsFeatureList
supports simplification of geometries on provider side according to a distance tolerance ...
virtual QgsAttributeList attributeIndexes()
Return list of indexes to fetch all attributes in nextFeature()
virtual bool deleteFeatures(const QgsFeatureIds &id)
Deletes one or more features.
virtual void setEncoding(const QString &e)
Set encoding used for accessing data from layer.
void pushError(QString msg)
int precision() const
Gets the precision of the field.
virtual void uniqueValues(int index, QList< QVariant > &uniqueValues, int limit=-1)
Return unique values of an attribute.
Container of fields for a vector layer.
QStringList errors()
Get recorded errors.
QgsVectorDataProvider(QString uri=QString())
Constructor of the vector provider.
static QVariant convertValue(QVariant::Type type, QString value)
QMap< int, QVariant > mCacheMaxValues
Abstract base class for spatial data provider implementations.
allows deletion of attributes (fields)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
virtual bool addFeatures(QgsFeatureList &flist)
Adds a list of features.
virtual QString name() const =0
return a provider name
virtual bool createAttributeIndex(int field)
Create an attribute index on the datasource.
static void logMessage(QString message, QString tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
static const QStringList & availableEncodings()
Returns a list of available encodings.
allows creation of spatial index
QString encoding() const
Get encoding which is used for accessing data.
QSet< int > QgsAttributeIds
virtual QVariant maximumValue(int index)
Returns the maximum value of an attribute.
virtual bool createSpatialIndex()
Creates a spatial index on the datasource (if supported by the provider type).
QTextCodec * mEncoding
Encoding.
bool supportedType(const QgsField &field) const
check if provider supports type of field
allows addition of new attributes (fields)
#define QgsDebugMsgLevel(str, level)
virtual QString dataComment() const
Return a short comment for the data that this provider is providing access to (e.g.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities Note, some capabilities may change depending ...
bool hasErrors()
Provider has errors to report.
virtual bool changeAttributeValues(const QgsChangedAttributesMap &attr_map)
Changes attribute values of existing features.
const QList< NativeType > & nativeTypes() const
Returns the names of the supported types.
virtual QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
QList< NativeType > mNativeTypes
The names of the providers native types.
const QgsAttributes & attributes() const
allows modifications of geometries
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())=0
Query the provider for features specified in request.
void clearErrors()
Clear recorded errors.
int count() const
Return number of items.
Encapsulate a field in an attribute table or data source.
fast access to features using their ID
QMap< QString, int > fieldNameMap() const
Return a map where the key is the name of the field and the value is its index.
virtual bool changeGeometryValues(QgsGeometryMap &geometry_map)
Changes geometries of existing features.
supports topological simplification of geometries on provider side according to a distance tolerance ...
QStringList mErrors
list of errors
virtual const QgsFields & fields() const =0
Return a map of indexes with field names for this layer.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
virtual QVariant defaultValue(int fieldId)
Returns the default value for field specified by fieldId.
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
static QStringList smEncodings
QVector< QVariant > QgsAttributes
virtual QVariant minimumValue(int index)
Returns the minimum value of an attribute.
int length() const
Gets the length of the field.
virtual ~QgsVectorDataProvider()
Destructor.
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes.
allows deletion of features
bool nextFeature(QgsFeature &f)
provider has no capabilities
QgsAttributeList allAttributesList() const
Utility function to get list of attribute indexes.
QHash< int, QString > QgsAttrPalIndexNameHash
allows modification of attribute values
bool isNull(const QVariant &v)
QMap< int, QVariant > mCacheMinValues
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.