QGIS API Documentation  2.17.0-Master (8784312)
qgsvectordataprovider.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectordataprovider.cpp - DataProvider Interface for vector layers
3  --------------------------------------
4  Date : 26-Oct-2004
5  Copyright : (C) 2004 by Marco Hugentobler
6  email : [email protected]
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include <QSettings>
17 #include <QTextCodec>
18 
19 #include <cfloat> // for DBL_MAX
20 #include <climits>
21 #include <limits>
22 
23 #include "qgsvectordataprovider.h"
24 #include "qgscircularstringv2.h"
25 #include "qgscompoundcurvev2.h"
26 #include "qgsfeature.h"
27 #include "qgsfeatureiterator.h"
28 #include "qgsfeaturerequest.h"
29 #include "qgsfield.h"
30 #include "qgsgeometry.h"
32 #include "qgsgeometryfactory.h"
33 #include "qgslogger.h"
34 #include "qgsmessagelog.h"
35 
37  : QgsDataProvider( uri )
38  , mCacheMinMaxDirty( true )
39  , mAttrPalIndexName( QgsAttrPalIndexNameHash() )
40 {
41  QSettings settings;
42  setEncoding( settings.value( "/UI/encoding", "System" ).toString() );
43 }
44 
45 
47 {
48 }
49 
51 {
52  return "Generic vector file";
53 }
54 
56 {
57  return QString();
58 }
59 
61 {
62  Q_UNUSED( flist );
63  return false;
64 }
65 
67 {
68  Q_UNUSED( ids );
69  return false;
70 }
71 
73 {
74  Q_UNUSED( attributes );
75  return false;
76 }
77 
79 {
80  Q_UNUSED( attributes );
81  return false;
82 }
83 
85 {
86  Q_UNUSED( renamedAttributes );
87  return false;
88 }
89 
91 {
92  Q_UNUSED( attr_map );
93  return false;
94 }
95 
97 {
98  Q_UNUSED( fieldId );
99  return QVariant();
100 }
101 
103 {
104  Q_UNUSED( geometry_map );
105  return false;
106 }
107 
109  const QgsGeometryMap &geometry_map )
110 {
111  Q_UNUSED( attr_map );
112  Q_UNUSED( geometry_map );
113  return false;
114 }
115 
117 {
118  return false;
119 }
120 
122 {
123  Q_UNUSED( field );
124  return true;
125 }
126 
128 {
130 }
131 
132 
134 {
136  if ( ncodec )
137  {
138  mEncoding = ncodec;
139  }
140  else
141  {
142  QgsMessageLog::logMessage( tr( "Codec %1 not found. Falling back to system locale" ).arg( e ) );
143  mEncoding = QTextCodec::codecForName( "System" );
144 
145  if ( !mEncoding )
147 
148  Q_ASSERT( mEncoding );
149  }
150 }
151 
153 {
154  if ( mEncoding )
155  {
156  return mEncoding->name();
157  }
158 
159  return "";
160 }
161 
163 {
164  QStringList abilitiesList;
165 
166  int abilities = capabilities();
167 
168  if ( abilities & QgsVectorDataProvider::AddFeatures )
169  {
170  abilitiesList += tr( "Add Features" );
171  QgsDebugMsg( "Capability: Add Features" );
172  }
173 
174  if ( abilities & QgsVectorDataProvider::DeleteFeatures )
175  {
176  abilitiesList += tr( "Delete Features" );
177  QgsDebugMsg( "Capability: Delete Features" );
178  }
179 
181  {
182  abilitiesList += tr( "Change Attribute Values" );
183  QgsDebugMsg( "Capability: Change Attribute Values" );
184  }
185 
186  if ( abilities & QgsVectorDataProvider::AddAttributes )
187  {
188  abilitiesList += tr( "Add Attributes" );
189  QgsDebugMsg( "Capability: Add Attributes" );
190  }
191 
192  if ( abilities & QgsVectorDataProvider::DeleteAttributes )
193  {
194  abilitiesList += tr( "Delete Attributes" );
195  QgsDebugMsg( "Capability: Delete Attributes" );
196  }
197 
198  if ( abilities & QgsVectorDataProvider::RenameAttributes )
199  {
200  abilitiesList += tr( "Rename Attributes" );
201  QgsDebugMsg( "Capability: Rename Attributes" );
202  }
203 
205  {
206  // TODO: Tighten up this test. See QgsOgrProvider for details.
207  abilitiesList += tr( "Create Spatial Index" );
208  QgsDebugMsg( "Capability: Create Spatial Index" );
209  }
210 
212  {
213  abilitiesList += tr( "Create Attribute Indexes" );
214  QgsDebugMsg( "Capability: Create Attribute Index" );
215  }
216 
217  if ( abilities & QgsVectorDataProvider::SelectAtId )
218  {
219  abilitiesList += tr( "Fast Access to Features at ID" );
220  QgsDebugMsg( "Capability: Select at ID" );
221  }
222 
223  if ( abilities & QgsVectorDataProvider::ChangeGeometries )
224  {
225  abilitiesList += tr( "Change Geometries" );
226  QgsDebugMsg( "Capability: Change Geometries" );
227  }
228 
230  {
231  abilitiesList += tr( "Presimplify Geometries" );
232  QgsDebugMsg( "Capability: Simplify Geometries before fetching the feature" );
233  }
234 
236  {
237  abilitiesList += tr( "Presimplify Geometries with Validity Check" );
238  QgsDebugMsg( "Capability: Simplify Geometries before fetch the feature ensuring that the result is a valid geometry" );
239  }
240 
241  if ( abilities & QgsVectorDataProvider::ChangeFeatures )
242  {
243  abilitiesList += tr( "Simultaneous Geometry and Attribute Updates" );
244  QgsDebugMsg( "Capability: change both feature attributes and geometry at once" );
245  }
246 
248  {
249  abilitiesList += tr( "Transactions" );
250  QgsDebugMsg( "Capability: transactions" );
251  }
252 
254  {
255  abilitiesList += tr( "Curved Geometries" );
256  QgsDebugMsg( "Supports circular geometry types (circularstring, compoundcurve, curvepolygon)" );
257  }
258 
259  return abilitiesList.join( ", " );
260 }
261 
262 
263 int QgsVectorDataProvider::fieldNameIndex( const QString& fieldName ) const
264 {
265  return fields().fieldNameIndex( fieldName );
266 }
267 
269 {
270  QMap<QString, int> resultMap;
271 
272  const QgsFields& theFields = fields();
273  for ( int i = 0; i < theFields.count(); ++i )
274  {
275  resultMap.insert( theFields[i].name(), i );
276  }
277 
278  return resultMap;
279 }
280 
282 {
283  return fields().allAttributesList();
284 }
285 
287 {
288  return mNativeTypes;
289 }
290 
292 {
293  int i;
294  QgsDebugMsgLevel( QString( "field name = %1 type = %2 length = %3 precision = %4" )
295  .arg( field.name(),
296  QVariant::typeToName( field.type() ) )
297  .arg( field.length() )
298  .arg( field.precision() ), 2 );
299  for ( i = 0; i < mNativeTypes.size(); i++ )
300  {
301  QgsDebugMsgLevel( QString( "native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" )
302  .arg( QVariant::typeToName( mNativeTypes[i].mType ) )
303  .arg( mNativeTypes[i].mMinLen )
304  .arg( mNativeTypes[i].mMaxLen )
305  .arg( mNativeTypes[i].mMinPrec )
306  .arg( mNativeTypes[i].mMaxPrec ), 2 );
307 
308  if ( field.type() != mNativeTypes[i].mType )
309  continue;
310 
311  if ( field.length() == -1 )
312  {
313  // source length unlimited
314  if ( mNativeTypes[i].mMinLen > -1 || mNativeTypes[i].mMaxLen > -1 )
315  {
316  // destination limited
317  continue;
318  }
319  }
320  else
321  {
322  // source length limited
323  if ( mNativeTypes[i].mMinLen > -1 && mNativeTypes[i].mMaxLen > -1 &&
324  ( field.length() < mNativeTypes[i].mMinLen || field.length() > mNativeTypes[i].mMaxLen ) )
325  {
326  // source length exceeds destination limits
327  continue;
328  }
329  }
330 
331  if ( field.precision() == -1 )
332  {
333  // source precision unlimited / n/a
334  if ( mNativeTypes[i].mMinPrec > -1 || mNativeTypes[i].mMaxPrec > -1 )
335  {
336  // destination limited
337  continue;
338  }
339  }
340  else
341  {
342  // source precision unlimited / n/a
343  if ( mNativeTypes[i].mMinPrec > -1 && mNativeTypes[i].mMaxPrec > -1 &&
344  ( field.precision() < mNativeTypes[i].mMinPrec || field.precision() > mNativeTypes[i].mMaxPrec ) )
345  {
346  // source precision exceeds destination limits
347  continue;
348  }
349  }
350 
351  QgsDebugMsg( "native type matches" );
352  return true;
353  }
354 
355  QgsDebugMsg( "no sufficient native type found" );
356  return false;
357 }
358 
360 {
361  if ( index < 0 || index >= fields().count() )
362  {
363  QgsDebugMsg( "Warning: access requested to invalid field index: " + QString::number( index ) );
364  return QVariant();
365  }
366 
367  fillMinMaxCache();
368 
369  if ( !mCacheMinValues.contains( index ) )
370  return QVariant();
371 
372  return mCacheMinValues[index];
373 }
374 
376 {
377  if ( index < 0 || index >= fields().count() )
378  {
379  QgsDebugMsg( "Warning: access requested to invalid field index: " + QString::number( index ) );
380  return QVariant();
381  }
382 
383  fillMinMaxCache();
384 
385  if ( !mCacheMaxValues.contains( index ) )
386  return QVariant();
387 
388  return mCacheMaxValues[index];
389 }
390 
392 {
393  QgsFeature f;
394  QgsAttributeList keys;
395  keys.append( index );
396  QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys ) );
397 
398  QSet<QString> set;
399  values.clear();
400 
401  while ( fi.nextFeature( f ) )
402  {
403  if ( !set.contains( f.attribute( index ).toString() ) )
404  {
405  values.append( f.attribute( index ) );
406  set.insert( f.attribute( index ).toString() );
407  }
408 
409  if ( limit >= 0 && values.size() >= limit )
410  break;
411  }
412 }
413 
415  const QgsAggregateCalculator::AggregateParameters& parameters, QgsExpressionContext* context, bool& ok )
416 {
417  //base implementation does nothing
418  Q_UNUSED( aggregate );
419  Q_UNUSED( index );
420  Q_UNUSED( parameters );
421  Q_UNUSED( context );
422 
423  ok = false;
424  return QVariant();
425 }
426 
428 {
429  mCacheMinMaxDirty = true;
430 }
431 
433 {
434  if ( !mCacheMinMaxDirty )
435  return;
436 
437  const QgsFields& flds = fields();
438  for ( int i = 0; i < flds.count(); ++i )
439  {
440  if ( flds[i].type() == QVariant::Int )
441  {
442  mCacheMinValues[i] = QVariant( INT_MAX );
443  mCacheMaxValues[i] = QVariant( INT_MIN );
444  }
445  else if ( flds[i].type() == QVariant::LongLong )
446  {
449  }
450  else if ( flds[i].type() == QVariant::Double )
451  {
452  mCacheMinValues[i] = QVariant( DBL_MAX );
453  mCacheMaxValues[i] = QVariant( -DBL_MAX );
454  }
455  else
456  {
457  mCacheMinValues[i] = QVariant();
458  mCacheMaxValues[i] = QVariant();
459  }
460  }
461 
462  QgsFeature f;
464  QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys ) );
465 
466  while ( fi.nextFeature( f ) )
467  {
468  QgsAttributes attrs = f.attributes();
469  for ( QgsAttributeList::const_iterator it = keys.begin(); it != keys.end(); ++it )
470  {
471  const QVariant& varValue = attrs.at( *it );
472 
473  if ( varValue.isNull() )
474  continue;
475 
476  if ( flds[*it].type() == QVariant::Int )
477  {
478  int value = varValue.toInt();
479  if ( value < mCacheMinValues[*it].toInt() )
480  mCacheMinValues[*it] = value;
481  if ( value > mCacheMaxValues[*it].toInt() )
482  mCacheMaxValues[*it] = value;
483  }
484  else if ( flds[*it].type() == QVariant::LongLong )
485  {
486  qlonglong value = varValue.toLongLong();
487  if ( value < mCacheMinValues[*it].toLongLong() )
488  mCacheMinValues[*it] = value;
489  if ( value > mCacheMaxValues[*it].toLongLong() )
490  mCacheMaxValues[*it] = value;
491  }
492  else if ( flds[*it].type() == QVariant::Double )
493  {
494  double value = varValue.toDouble();
495  if ( value < mCacheMinValues[*it].toDouble() )
496  mCacheMinValues[*it] = value;
497  if ( value > mCacheMaxValues[*it].toDouble() )
498  mCacheMaxValues[*it] = value;
499  }
500  else
501  {
502  QString value = varValue.toString();
503  if ( mCacheMinValues[*it].isNull() || value < mCacheMinValues[*it].toString() )
504  {
505  mCacheMinValues[*it] = value;
506  }
507  if ( mCacheMaxValues[*it].isNull() || value > mCacheMaxValues[*it].toString() )
508  {
509  mCacheMaxValues[*it] = value;
510  }
511  }
512  }
513  }
514 
515  mCacheMinMaxDirty = false;
516 }
517 
518 QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, const QString& value )
519 {
520  QVariant v( value );
521 
522  if ( !v.convert( type ) || value.isNull() )
523  v = QVariant( type );
524 
525  return v;
526 }
527 
528 static bool _compareEncodings( const QString& s1, const QString& s2 )
529 {
530  return s1.toLower() < s2.toLower();
531 }
532 
534 {
535  if ( smEncodings.isEmpty() )
536  {
537  Q_FOREACH ( const QString& codec, QTextCodec::availableCodecs() )
538  {
539  smEncodings << codec;
540  }
541 #if 0
542  smEncodings << "BIG5";
543  smEncodings << "BIG5-HKSCS";
544  smEncodings << "EUCJP";
545  smEncodings << "EUCKR";
546  smEncodings << "GB2312";
547  smEncodings << "GBK";
548  smEncodings << "GB18030";
549  smEncodings << "JIS7";
550  smEncodings << "SHIFT-JIS";
551  smEncodings << "TSCII";
552  smEncodings << "UTF-8";
553  smEncodings << "UTF-16";
554  smEncodings << "KOI8-R";
555  smEncodings << "KOI8-U";
556  smEncodings << "ISO8859-1";
557  smEncodings << "ISO8859-2";
558  smEncodings << "ISO8859-3";
559  smEncodings << "ISO8859-4";
560  smEncodings << "ISO8859-5";
561  smEncodings << "ISO8859-6";
562  smEncodings << "ISO8859-7";
563  smEncodings << "ISO8859-8";
564  smEncodings << "ISO8859-8-I";
565  smEncodings << "ISO8859-9";
566  smEncodings << "ISO8859-10";
567  smEncodings << "ISO8859-11";
568  smEncodings << "ISO8859-12";
569  smEncodings << "ISO8859-13";
570  smEncodings << "ISO8859-14";
571  smEncodings << "ISO8859-15";
572  smEncodings << "IBM 850";
573  smEncodings << "IBM 866";
574  smEncodings << "CP874";
575  smEncodings << "CP1250";
576  smEncodings << "CP1251";
577  smEncodings << "CP1252";
578  smEncodings << "CP1253";
579  smEncodings << "CP1254";
580  smEncodings << "CP1255";
581  smEncodings << "CP1256";
582  smEncodings << "CP1257";
583  smEncodings << "CP1258";
584  smEncodings << "Apple Roman";
585  smEncodings << "TIS-620";
586  smEncodings << "System";
587 #endif
588  }
589 
590  // Do case-insensitive sorting of encodings
591  qSort( smEncodings.begin(), smEncodings.end(), _compareEncodings );
592 
593  return smEncodings;
594 }
595 
597 {
598  mErrors.clear();
599 }
600 
602 {
603  return !mErrors.isEmpty();
604 }
605 
607 {
608  return mErrors;
609 }
610 
612 {
613  QgsDebugMsg( msg );
614  mErrors << msg;
615  emit raiseError( msg );
616 }
617 
619 {
620  return QSet<QString>();
621 }
622 
624 {
625  if ( !geom )
626  {
627  return nullptr;
628  }
629 
630  QgsAbstractGeometryV2* geometry = geom->geometry();
631  if ( !geometry )
632  {
633  return nullptr;
634  }
635 
636  QgsWKBTypes::Type providerGeomType = QGis::fromOldWkbType( geometryType() );
637 
638  //geom is already in the provider geometry type
639  if ( geometry->wkbType() == providerGeomType )
640  {
641  return nullptr;
642  }
643 
644  QgsAbstractGeometryV2* outputGeom = nullptr;
645 
646  //convert compoundcurve to circularstring (possible if compoundcurve consists of one circular string)
648  {
649  QgsCompoundCurveV2* compoundCurve = static_cast<QgsCompoundCurveV2*>( geometry );
650  if ( compoundCurve )
651  {
652  if ( compoundCurve->nCurves() == 1 )
653  {
654  const QgsCircularStringV2* circularString = dynamic_cast<const QgsCircularStringV2*>( compoundCurve->curveAt( 0 ) );
655  if ( circularString )
656  {
657  outputGeom = circularString->clone();
658  }
659  }
660  }
661  }
662 
663  //convert to multitype if necessary
664  if ( QgsWKBTypes::isMultiType( providerGeomType ) && !QgsWKBTypes::isMultiType( geometry->wkbType() ) )
665  {
666  outputGeom = QgsGeometryFactory::geomFromWkbType( providerGeomType );
667  QgsGeometryCollectionV2* geomCollection = dynamic_cast<QgsGeometryCollectionV2*>( outputGeom );
668  if ( geomCollection )
669  {
670  geomCollection->addGeometry( geometry->clone() );
671  }
672  }
673 
674  //convert to curved type if necessary
675  if ( !QgsWKBTypes::isCurvedType( geometry->wkbType() ) && QgsWKBTypes::isCurvedType( providerGeomType ) )
676  {
677  QgsAbstractGeometryV2* curveGeom = outputGeom ? outputGeom->toCurveType() : geometry->toCurveType();
678  if ( curveGeom )
679  {
680  delete outputGeom;
681  outputGeom = curveGeom;
682  }
683  }
684 
685  //convert to linear type from curved type
686  if ( QgsWKBTypes::isCurvedType( geometry->wkbType() ) && !QgsWKBTypes::isCurvedType( providerGeomType ) )
687  {
688  QgsAbstractGeometryV2* segmentizedGeom = nullptr;
689  segmentizedGeom = outputGeom ? outputGeom->segmentize() : geometry->segmentize();
690  if ( segmentizedGeom )
691  {
692  delete outputGeom;
693  outputGeom = segmentizedGeom;
694  }
695  }
696 
697  //set z/m types
698  if ( QgsWKBTypes::hasZ( providerGeomType ) )
699  {
700  if ( !outputGeom )
701  {
702  outputGeom = geometry->clone();
703  }
704  outputGeom->addZValue();
705  }
706  if ( QgsWKBTypes::hasM( providerGeomType ) )
707  {
708  if ( !outputGeom )
709  {
710  outputGeom = geometry->clone();
711  }
712  outputGeom->addMValue();
713  }
714 
715  if ( outputGeom )
716  {
717  return new QgsGeometry( outputGeom );
718  }
719  return nullptr;
720 }
721 
722 QStringList QgsVectorDataProvider::smEncodings;
virtual QSet< QString > layerDependencies() const
Get the list of layer ids on which this layer depends.
qlonglong toLongLong(bool *ok) const
void clear()
Wrapper for iterator of features from vector data provider or vector layer.
static unsigned index
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
static QVariant convertValue(QVariant::Type type, const QString &value)
bool contains(const Key &key) const
virtual QByteArray name() const =0
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.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
Definition: qgswkbtypes.h:714
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
QgsGeometry * convertToProviderType(const QgsGeometry *geom) const
Converts the geometry to the provider type if possible / necessary.
QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store.
Circular string geometry type.
Supports simplification of geometries on provider side according to a distance tolerance.
int fieldNameIndex(const QString &fieldName) const
Look up field&#39;s index from name also looks up case-insensitive if there is no match otherwise...
Definition: qgsfield.cpp:534
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.
virtual bool renameAttributes(const QgsFieldNameMap &renamedAttributes)
Renames existing attributes.
static bool isMultiType(Type type)
Returns true if the WKB type is a multi type.
Definition: qgswkbtypes.h:487
int precision() const
Gets the precision of the field.
Definition: qgsfield.cpp:104
Abstract base class for all geometries.
virtual void uniqueValues(int index, QList< QVariant > &uniqueValues, int limit=-1)
Return unique values of an attribute.
Container of fields for a vector layer.
Definition: qgsfield.h:193
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
QStringList errors()
Get recorded errors.
QMap< int, QVariant > mCacheMaxValues
Abstract base class for spatial data provider implementations.
Allows deletion of attributes (fields)
QString join(const QString &separator) const
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
Definition: qgswkbtypes.h:667
virtual bool addFeatures(QgsFeatureList &flist)
Adds a list of features.
QString tr(const char *sourceText, const char *disambiguation, int n)
QTextCodec * codecForLocale()
virtual QString name() const =0
Return a provider name.
virtual bool createAttributeIndex(int field)
Create an attribute index on the datasource.
int size() const
bool isNull() const
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
static const QStringList & availableEncodings()
Returns a list of available encodings.
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
QList< Key > keys() const
Allows creation of spatial index.
static QgsWKBTypes::Type fromOldWkbType(QGis::WkbType type)
Converts from old (pre 2.10) WKB type (OGR) to new WKB type.
Definition: qgis.cpp:106
QString encoding() const
Get encoding which is used for accessing data.
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).
QString number(int n, int base)
void append(const T &value)
QTextCodec * mEncoding
Encoding.
bool supportedType(const QgsField &field) const
check if provider supports type of field
int toInt(bool *ok) const
bool isNull() const
Allows addition of new attributes (fields)
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:34
virtual QString dataComment() const
Return a short comment for the data that this provider is providing access to (e.g.
static bool isCurvedType(Type type)
Returns true if the WKB type is a curved type or can contain curved geometries.
Definition: qgswkbtypes.h:531
QgsAttributes attributes() const
Returns the feature&#39;s attributes.
Definition: qgsfeature.cpp:110
virtual int capabilities() const
Returns a bitmask containing the supported capabilities Note, some capabilities may change depending ...
bool hasErrors()
Provider has errors to report.
QString name() const
Gets the name of the field.
Definition: qgsfield.cpp:84
virtual bool changeAttributeValues(const QgsChangedAttributesMap &attr_map)
Changes attribute values of existing features.
bool isEmpty() const
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
virtual bool changeFeatures(const QgsChangedAttributesMap &attr_map, const QgsGeometryMap &geometry_map)
Changes attribute values and geometries of existing features.
const char * constData() const
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.
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
This class wraps a request for features to a vector layer (or directly its vector data provider)...
virtual QVariant aggregate(QgsAggregateCalculator::Aggregate aggregate, int index, const QgsAggregateCalculator::AggregateParameters &parameters, QgsExpressionContext *context, bool &ok)
Calculates an aggregated value from the layer&#39;s features.
QList< NativeType > mNativeTypes
The names of the providers native types.
Allows modifications of geometries.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())=0
Query the provider for features specified in request.
const QgsCurveV2 * curveAt(int i) const
Returns the curve at the specified index.
void clearErrors()
Clear recorded errors.
int count() const
Return number of items.
Definition: qgsfield.cpp:365
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:44
virtual QGis::WkbType geometryType() const =0
Get feature type.
Fast access to features using their ID.
virtual bool changeGeometryValues(const QgsGeometryMap &geometry_map)
Changes geometries of existing features.
QMap< QString, int > fieldNameMap() const
Return a map where the key is the name of the field and the value is its index.
static QgsAbstractGeometryV2 * geomFromWkbType(QgsWKBTypes::Type t)
Return empty geometry from wkb type.
Compound curve geometry type.
QgsVectorDataProvider(const QString &uri=QString())
Constructor of the vector provider.
iterator end()
QString toLower() const
QByteArray toLocal8Bit() const
void raiseError(const QString &msg)
Signals an error in this provider.
Supports circular geometry types (circularstring, compoundcurve, curvepolygon)
virtual QgsCircularStringV2 * clone() const override
Clones the geometry by performing a deep copy.
Supports joint updates for attributes and geometry Providers supporting this should still define Chan...
Supports topological simplification of geometries on provider side according to a distance tolerance...
const char * typeToName(Type typ)
const T & at(int i) const
QVariant value(const QString &key, const QVariant &defaultValue) const
QList< QByteArray > availableCodecs()
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.
Definition: qgsfeature.cpp:271
virtual QVariant defaultValue(int fieldId)
Returns the default value for field specified by fieldId.
virtual QVariant minimumValue(int index)
Returns the minimum value of an attribute.
QTextCodec * codecForName(const QByteArray &name)
virtual bool addGeometry(QgsAbstractGeometryV2 *g)
Adds a geometry and takes ownership.
int length() const
Gets the length of the field.
Definition: qgsfield.cpp:99
virtual ~QgsVectorDataProvider()
Destructor.
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes.
static Type flatType(Type type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:366
double toDouble(bool *ok) const
iterator insert(const Key &key, const T &value)
void pushError(const QString &msg)
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
bool nextFeature(QgsFeature &f)
Provider has no capabilities.
virtual QgsAbstractGeometryV2 * clone() const =0
Clones the geometry by performing a deep copy.
A vector of attributes.
Definition: qgsfeature.h:115
bool convert(Type t)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString toString() const
QgsAttributeList allAttributesList() const
Utility function to get list of attribute indexes.
Definition: qgsfield.cpp:551
int nCurves() const
Returns the number of curves in the geometry.
iterator begin()
Allows modification of attribute values.
bool isNull(const QVariant &v)
virtual QgsAbstractGeometryV2 * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
Aggregate
Available aggregates to calculate.
QMap< int, QVariant > mCacheMinValues
Supports renaming attributes (fields).
virtual QgsAbstractGeometryV2 * toCurveType() const
Returns the geometry converted to the more generic curve type.
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
Definition: qgsfield.cpp:89
A bundle of parameters controlling aggregate calculation.