QGIS API Documentation  2.99.0-Master (ba079d8)
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 <QTextCodec>
17 
18 #include <cfloat> // for DBL_MAX
19 #include <climits>
20 #include <limits>
21 
22 #include "qgsvectordataprovider.h"
23 #include "qgscircularstring.h"
24 #include "qgscompoundcurve.h"
25 #include "qgsfeature.h"
26 #include "qgsfeatureiterator.h"
27 #include "qgsfeaturerequest.h"
28 #include "qgsfeedback.h"
29 #include "qgsfields.h"
30 #include "qgsgeometry.h"
31 #include "qgsgeometrycollection.h"
32 #include "qgsgeometryfactory.h"
33 #include "qgslogger.h"
34 #include "qgsmessagelog.h"
35 #include "qgssettings.h"
36 
38  : QgsDataProvider( uri )
39  , mCacheMinMaxDirty( true )
40 {
41  QgsSettings settings;
42  setEncoding( settings.value( QStringLiteral( "UI/encoding" ), "System" ).toString() );
43 }
44 
46 {
47  return QStringLiteral( "Generic vector file" );
48 }
49 
51 {
52  return crs();
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  if ( !( capabilities() & DeleteFeatures ) )
75  return false;
76 
77  QgsFeatureIds toDelete;
79  QgsFeature f;
80  while ( it.nextFeature( f ) )
81  toDelete << f.id();
82 
83  return deleteFeatures( toDelete );
84 }
85 
86 bool QgsVectorDataProvider::addAttributes( const QList<QgsField> &attributes )
87 {
88  Q_UNUSED( attributes );
89  return false;
90 }
91 
93 {
94  Q_UNUSED( attributes );
95  return false;
96 }
97 
99 {
100  Q_UNUSED( renamedAttributes );
101  return false;
102 }
103 
105 {
106  Q_UNUSED( attr_map );
107  return false;
108 }
109 
110 QVariant QgsVectorDataProvider::defaultValue( int fieldId ) const
111 {
112  Q_UNUSED( fieldId );
113  return QVariant();
114 }
115 
116 QString QgsVectorDataProvider::defaultValueClause( int fieldIndex ) const
117 {
118  Q_UNUSED( fieldIndex );
119  return QString();
120 }
121 
122 QgsFieldConstraints::Constraints QgsVectorDataProvider::fieldConstraints( int fieldIndex ) const
123 {
124  QgsFields f = fields();
125  if ( fieldIndex < 0 || fieldIndex >= f.count() )
126  return 0;
127 
128  return f.at( fieldIndex ).constraints().constraints();
129 }
130 
132 {
133  return false;
134 }
135 
137 {
138  Q_UNUSED( geometry_map );
139  return false;
140 }
141 
143  const QgsGeometryMap &geometry_map )
144 {
146  return false;
147 
148  bool result = true;
149  result = result && changeAttributeValues( attr_map );
150  result = result && changeGeometryValues( geometry_map );
151  return result;
152 }
153 
155 {
156  return false;
157 }
158 
160 {
161  Q_UNUSED( field );
162  return true;
163 }
164 
165 QgsVectorDataProvider::Capabilities QgsVectorDataProvider::capabilities() const
166 {
168 }
169 
170 
171 void QgsVectorDataProvider::setEncoding( const QString &e )
172 {
173  mEncoding = QTextCodec::codecForName( e.toLocal8Bit().constData() );
174 
175  if ( !mEncoding && e != QLatin1String( "System" ) )
176  {
177  QgsMessageLog::logMessage( tr( "Codec %1 not found. Falling back to system locale" ).arg( e ) );
178  mEncoding = QTextCodec::codecForName( "System" );
179  }
180 
181  if ( !mEncoding )
182  mEncoding = QTextCodec::codecForLocale();
183 
184  Q_ASSERT( mEncoding );
185 }
186 
188 {
189  if ( mEncoding )
190  {
191  return mEncoding->name();
192  }
193 
194  return QLatin1String( "" );
195 }
196 
198 {
199  QStringList abilitiesList;
200 
201  int abilities = capabilities();
202 
203  if ( abilities & QgsVectorDataProvider::AddFeatures )
204  {
205  abilitiesList += tr( "Add Features" );
206  QgsDebugMsg( "Capability: Add Features" );
207  }
208 
209  if ( abilities & QgsVectorDataProvider::DeleteFeatures )
210  {
211  abilitiesList += tr( "Delete Features" );
212  QgsDebugMsg( "Capability: Delete Features" );
213  }
214 
216  {
217  abilitiesList += tr( "Change Attribute Values" );
218  QgsDebugMsg( "Capability: Change Attribute Values" );
219  }
220 
221  if ( abilities & QgsVectorDataProvider::AddAttributes )
222  {
223  abilitiesList += tr( "Add Attributes" );
224  QgsDebugMsg( "Capability: Add Attributes" );
225  }
226 
227  if ( abilities & QgsVectorDataProvider::DeleteAttributes )
228  {
229  abilitiesList += tr( "Delete Attributes" );
230  QgsDebugMsg( "Capability: Delete Attributes" );
231  }
232 
233  if ( abilities & QgsVectorDataProvider::RenameAttributes )
234  {
235  abilitiesList += tr( "Rename Attributes" );
236  QgsDebugMsg( "Capability: Rename Attributes" );
237  }
238 
240  {
241  // TODO: Tighten up this test. See QgsOgrProvider for details.
242  abilitiesList += tr( "Create Spatial Index" );
243  QgsDebugMsg( "Capability: Create Spatial Index" );
244  }
245 
247  {
248  abilitiesList += tr( "Create Attribute Indexes" );
249  QgsDebugMsg( "Capability: Create Attribute Index" );
250  }
251 
252  if ( abilities & QgsVectorDataProvider::SelectAtId )
253  {
254  abilitiesList += tr( "Fast Access to Features at ID" );
255  QgsDebugMsg( "Capability: Select at ID" );
256  }
257 
258  if ( abilities & QgsVectorDataProvider::ChangeGeometries )
259  {
260  abilitiesList += tr( "Change Geometries" );
261  QgsDebugMsg( "Capability: Change Geometries" );
262  }
263 
265  {
266  abilitiesList += tr( "Presimplify Geometries" );
267  QgsDebugMsg( "Capability: Simplify Geometries before fetching the feature" );
268  }
269 
271  {
272  abilitiesList += tr( "Presimplify Geometries with Validity Check" );
273  QgsDebugMsg( "Capability: Simplify Geometries before fetch the feature ensuring that the result is a valid geometry" );
274  }
275 
276  if ( abilities & QgsVectorDataProvider::ChangeFeatures )
277  {
278  abilitiesList += tr( "Simultaneous Geometry and Attribute Updates" );
279  QgsDebugMsg( "Capability: change both feature attributes and geometry at once" );
280  }
281 
283  {
284  abilitiesList += tr( "Transactions" );
285  QgsDebugMsg( "Capability: transactions" );
286  }
287 
289  {
290  abilitiesList += tr( "Curved Geometries" );
291  QgsDebugMsg( "Supports circular geometry types (circularstring, compoundcurve, curvepolygon)" );
292  }
293 
294  return abilitiesList.join( QStringLiteral( ", " ) );
295 }
296 
297 
298 int QgsVectorDataProvider::fieldNameIndex( const QString &fieldName ) const
299 {
300  return fields().lookupField( fieldName );
301 }
302 
303 QMap<QString, int> QgsVectorDataProvider::fieldNameMap() const
304 {
305  QMap<QString, int> resultMap;
306 
307  QgsFields fieldsCopy = fields();
308  for ( int i = 0; i < fieldsCopy.count(); ++i )
309  {
310  resultMap.insert( fieldsCopy.at( i ).name(), i );
311  }
312 
313  return resultMap;
314 }
315 
317 {
318  return fields().allAttributesList();
319 }
320 
322 {
323  return QgsAttributeList();
324 }
325 
326 QList<QgsVectorDataProvider::NativeType> QgsVectorDataProvider::nativeTypes() const
327 {
328  return mNativeTypes;
329 }
330 
332 {
333  return QgsAttrPalIndexNameHash();
334 }
335 
337 {
338  QgsDebugMsgLevel( QString( "field name = %1 type = %2 length = %3 precision = %4" )
339  .arg( field.name(),
340  QVariant::typeToName( field.type() ) )
341  .arg( field.length() )
342  .arg( field.precision() ), 2 );
343 
344  Q_FOREACH ( const NativeType &nativeType, mNativeTypes )
345  {
346  QgsDebugMsgLevel( QString( "native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" )
347  .arg( QVariant::typeToName( nativeType.mType ) )
348  .arg( nativeType.mMinLen )
349  .arg( nativeType.mMaxLen )
350  .arg( nativeType.mMinPrec )
351  .arg( nativeType.mMaxPrec ), 2 );
352 
353  if ( field.type() != nativeType.mType )
354  continue;
355 
356  if ( field.length() == -1 )
357  {
358  // source length unlimited
359  if ( nativeType.mMinLen > -1 || nativeType.mMaxLen > -1 )
360  {
361  // destination limited
362  continue;
363  }
364  }
365  else
366  {
367  // source length limited
368  if ( nativeType.mMinLen > -1 && nativeType.mMaxLen > -1 &&
369  ( field.length() < nativeType.mMinLen || field.length() > nativeType.mMaxLen ) )
370  {
371  // source length exceeds destination limits
372  continue;
373  }
374  }
375 
376  if ( field.precision() == -1 )
377  {
378  // source precision unlimited / n/a
379  if ( nativeType.mMinPrec > -1 || nativeType.mMaxPrec > -1 )
380  {
381  // destination limited
382  continue;
383  }
384  }
385  else
386  {
387  // source precision unlimited / n/a
388  if ( nativeType.mMinPrec > -1 && nativeType.mMaxPrec > -1 &&
389  ( field.precision() < nativeType.mMinPrec || field.precision() > nativeType.mMaxPrec ) )
390  {
391  // source precision exceeds destination limits
392  continue;
393  }
394  }
395 
396  QgsDebugMsg( "native type matches" );
397  return true;
398  }
399 
400  QgsDebugMsg( "no sufficient native type found" );
401  return false;
402 }
403 
404 QVariant QgsVectorDataProvider::minimumValue( int index ) const
405 {
406  if ( index < 0 || index >= fields().count() )
407  {
408  QgsDebugMsg( "Warning: access requested to invalid field index: " + QString::number( index ) );
409  return QVariant();
410  }
411 
412  fillMinMaxCache();
413 
414  if ( !mCacheMinValues.contains( index ) )
415  return QVariant();
416 
417  return mCacheMinValues[index];
418 }
419 
420 QVariant QgsVectorDataProvider::maximumValue( int index ) const
421 {
422  if ( index < 0 || index >= fields().count() )
423  {
424  QgsDebugMsg( "Warning: access requested to invalid field index: " + QString::number( index ) );
425  return QVariant();
426  }
427 
428  fillMinMaxCache();
429 
430  if ( !mCacheMaxValues.contains( index ) )
431  return QVariant();
432 
433  return mCacheMaxValues[index];
434 }
435 
436 void QgsVectorDataProvider::uniqueValues( int index, QList<QVariant> &values, int limit ) const
437 {
438  QgsFeature f;
439  QgsAttributeList keys;
440  keys.append( index );
441  QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys ).setFlags( QgsFeatureRequest::NoGeometry ) );
442 
443  QSet<QString> set;
444  values.clear();
445 
446  while ( fi.nextFeature( f ) )
447  {
448  if ( !set.contains( f.attribute( index ).toString() ) )
449  {
450  values.append( f.attribute( index ) );
451  set.insert( f.attribute( index ).toString() );
452  }
453 
454  if ( limit >= 0 && values.size() >= limit )
455  break;
456  }
457 }
458 
459 QStringList QgsVectorDataProvider::uniqueStringsMatching( int index, const QString &substring, int limit, QgsFeedback *feedback ) const
460 {
461  QgsFeature f;
462  QgsAttributeList keys;
463  keys.append( index );
464 
465  QgsFeatureRequest request;
466  request.setSubsetOfAttributes( keys );
468  QString fieldName = fields().at( index ).name();
469  request.setFilterExpression( QStringLiteral( "\"%1\" ILIKE '%%2%'" ).arg( fieldName, substring ) );
470  QgsFeatureIterator fi = getFeatures( request );
471 
472  QSet<QString> set;
473  QStringList results;
474 
475  while ( fi.nextFeature( f ) )
476  {
477  QString value = f.attribute( index ).toString();
478  if ( !set.contains( value ) )
479  {
480  results.append( value );
481  set.insert( value );
482  }
483 
484  if ( ( limit >= 0 && results.size() >= limit ) || ( feedback && feedback->isCanceled() ) )
485  break;
486  }
487  return results;
488 }
489 
491  const QgsAggregateCalculator::AggregateParameters &parameters, QgsExpressionContext *context, bool &ok ) const
492 {
493  //base implementation does nothing
494  Q_UNUSED( aggregate );
495  Q_UNUSED( index );
496  Q_UNUSED( parameters );
497  Q_UNUSED( context );
498 
499  ok = false;
500  return QVariant();
501 }
502 
504 {
505  mCacheMinMaxDirty = true;
506 }
507 
509 {
510  if ( !mCacheMinMaxDirty )
511  return;
512 
513  QgsFields flds = fields();
514  for ( int i = 0; i < flds.count(); ++i )
515  {
516  if ( flds.at( i ).type() == QVariant::Int )
517  {
518  mCacheMinValues[i] = QVariant( INT_MAX );
519  mCacheMaxValues[i] = QVariant( INT_MIN );
520  }
521  else if ( flds.at( i ).type() == QVariant::LongLong )
522  {
523  mCacheMinValues[i] = QVariant( std::numeric_limits<qlonglong>::max() );
524  mCacheMaxValues[i] = QVariant( std::numeric_limits<qlonglong>::min() );
525  }
526  else if ( flds.at( i ).type() == QVariant::Double )
527  {
528  mCacheMinValues[i] = QVariant( DBL_MAX );
529  mCacheMaxValues[i] = QVariant( -DBL_MAX );
530  }
531  else
532  {
533  mCacheMinValues[i] = QVariant();
534  mCacheMaxValues[i] = QVariant();
535  }
536  }
537 
538  QgsFeature f;
539  QgsAttributeList keys = mCacheMinValues.keys();
540  QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys )
541  .setFlags( QgsFeatureRequest::NoGeometry ) );
542 
543  while ( fi.nextFeature( f ) )
544  {
545  QgsAttributes attrs = f.attributes();
546  for ( QgsAttributeList::const_iterator it = keys.begin(); it != keys.end(); ++it )
547  {
548  const QVariant &varValue = attrs.at( *it );
549 
550  if ( varValue.isNull() )
551  continue;
552 
553  if ( flds.at( *it ).type() == QVariant::Int )
554  {
555  int value = varValue.toInt();
556  if ( value < mCacheMinValues[*it].toInt() )
557  mCacheMinValues[*it] = value;
558  if ( value > mCacheMaxValues[*it].toInt() )
559  mCacheMaxValues[*it] = value;
560  }
561  else if ( flds.at( *it ).type() == QVariant::LongLong )
562  {
563  qlonglong value = varValue.toLongLong();
564  if ( value < mCacheMinValues[*it].toLongLong() )
565  mCacheMinValues[*it] = value;
566  if ( value > mCacheMaxValues[*it].toLongLong() )
567  mCacheMaxValues[*it] = value;
568  }
569  else if ( flds.at( *it ).type() == QVariant::Double )
570  {
571  double value = varValue.toDouble();
572  if ( value < mCacheMinValues[*it].toDouble() )
573  mCacheMinValues[*it] = value;
574  if ( value > mCacheMaxValues[*it].toDouble() )
575  mCacheMaxValues[*it] = value;
576  }
577  else
578  {
579  QString value = varValue.toString();
580  if ( mCacheMinValues[*it].isNull() || value < mCacheMinValues[*it].toString() )
581  {
582  mCacheMinValues[*it] = value;
583  }
584  if ( mCacheMaxValues[*it].isNull() || value > mCacheMaxValues[*it].toString() )
585  {
586  mCacheMaxValues[*it] = value;
587  }
588  }
589  }
590  }
591 
592  mCacheMinMaxDirty = false;
593 }
594 
595 QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, const QString &value )
596 {
597  QVariant v( value );
598 
599  if ( !v.convert( type ) || value.isNull() )
600  v = QVariant( type );
601 
602  return v;
603 }
604 
606 {
607  return nullptr;
608 }
609 
611 {
612  emit dataChanged();
613 }
614 
615 static bool _compareEncodings( const QString &s1, const QString &s2 )
616 {
617  return s1.toLower() < s2.toLower();
618 }
619 
621 {
622  if ( sEncodings.isEmpty() )
623  {
624  Q_FOREACH ( const QString &codec, QTextCodec::availableCodecs() )
625  {
626  sEncodings << codec;
627  }
628 #if 0
629  smEncodings << "BIG5";
630  smEncodings << "BIG5-HKSCS";
631  smEncodings << "EUCJP";
632  smEncodings << "EUCKR";
633  smEncodings << "GB2312";
634  smEncodings << "GBK";
635  smEncodings << "GB18030";
636  smEncodings << "JIS7";
637  smEncodings << "SHIFT-JIS";
638  smEncodings << "TSCII";
639  smEncodings << "UTF-8";
640  smEncodings << "UTF-16";
641  smEncodings << "KOI8-R";
642  smEncodings << "KOI8-U";
643  smEncodings << "ISO8859-1";
644  smEncodings << "ISO8859-2";
645  smEncodings << "ISO8859-3";
646  smEncodings << "ISO8859-4";
647  smEncodings << "ISO8859-5";
648  smEncodings << "ISO8859-6";
649  smEncodings << "ISO8859-7";
650  smEncodings << "ISO8859-8";
651  smEncodings << "ISO8859-8-I";
652  smEncodings << "ISO8859-9";
653  smEncodings << "ISO8859-10";
654  smEncodings << "ISO8859-11";
655  smEncodings << "ISO8859-12";
656  smEncodings << "ISO8859-13";
657  smEncodings << "ISO8859-14";
658  smEncodings << "ISO8859-15";
659  smEncodings << "IBM 850";
660  smEncodings << "IBM 866";
661  smEncodings << "CP874";
662  smEncodings << "CP1250";
663  smEncodings << "CP1251";
664  smEncodings << "CP1252";
665  smEncodings << "CP1253";
666  smEncodings << "CP1254";
667  smEncodings << "CP1255";
668  smEncodings << "CP1256";
669  smEncodings << "CP1257";
670  smEncodings << "CP1258";
671  smEncodings << "Apple Roman";
672  smEncodings << "TIS-620";
673  smEncodings << "System";
674 #endif
675  }
676 
677  // Do case-insensitive sorting of encodings
678  std::sort( sEncodings.begin(), sEncodings.end(), _compareEncodings );
679 
680  return sEncodings;
681 }
682 
684 {
685  mErrors.clear();
686 }
687 
689 {
690  return !mErrors.isEmpty();
691 }
692 
693 QStringList QgsVectorDataProvider::errors() const
694 {
695  return mErrors;
696 }
697 
699 {
700  return false;
701 }
702 
704 {
705  return false;
706 }
707 
708 void QgsVectorDataProvider::pushError( const QString &msg ) const
709 {
710  QgsDebugMsg( msg );
711  mErrors << msg;
712  emit raiseError( msg );
713 }
714 
715 QSet<QgsMapLayerDependency> QgsVectorDataProvider::dependencies() const
716 {
717  return QSet<QgsMapLayerDependency>();
718 }
719 
721 {
722  if ( geom.isNull() )
723  {
724  return nullptr;
725  }
726 
727  QgsAbstractGeometry *geometry = geom.geometry();
728  if ( !geometry )
729  {
730  return nullptr;
731  }
732 
733  QgsWkbTypes::Type providerGeomType = wkbType();
734 
735  //geom is already in the provider geometry type
736  if ( geometry->wkbType() == providerGeomType )
737  {
738  return nullptr;
739  }
740 
741  QgsAbstractGeometry *outputGeom = nullptr;
742 
743  //convert compoundcurve to circularstring (possible if compoundcurve consists of one circular string)
745  {
746  QgsCompoundCurve *compoundCurve = static_cast<QgsCompoundCurve *>( geometry );
747  if ( compoundCurve )
748  {
749  if ( compoundCurve->nCurves() == 1 )
750  {
751  const QgsCircularString *circularString = dynamic_cast<const QgsCircularString *>( compoundCurve->curveAt( 0 ) );
752  if ( circularString )
753  {
754  outputGeom = circularString->clone();
755  }
756  }
757  }
758  }
759 
760  //convert to multitype if necessary
761  if ( QgsWkbTypes::isMultiType( providerGeomType ) && !QgsWkbTypes::isMultiType( geometry->wkbType() ) )
762  {
763  outputGeom = QgsGeometryFactory::geomFromWkbType( providerGeomType );
764  QgsGeometryCollection *geomCollection = dynamic_cast<QgsGeometryCollection *>( outputGeom );
765  if ( geomCollection )
766  {
767  geomCollection->addGeometry( geometry->clone() );
768  }
769  }
770 
771  //convert to curved type if necessary
772  if ( !QgsWkbTypes::isCurvedType( geometry->wkbType() ) && QgsWkbTypes::isCurvedType( providerGeomType ) )
773  {
774  QgsAbstractGeometry *curveGeom = outputGeom ? outputGeom->toCurveType() : geometry->toCurveType();
775  if ( curveGeom )
776  {
777  delete outputGeom;
778  outputGeom = curveGeom;
779  }
780  }
781 
782  //convert to linear type from curved type
783  if ( QgsWkbTypes::isCurvedType( geometry->wkbType() ) && !QgsWkbTypes::isCurvedType( providerGeomType ) )
784  {
785  QgsAbstractGeometry *segmentizedGeom = nullptr;
786  segmentizedGeom = outputGeom ? outputGeom->segmentize() : geometry->segmentize();
787  if ( segmentizedGeom )
788  {
789  delete outputGeom;
790  outputGeom = segmentizedGeom;
791  }
792  }
793 
794  //set z/m types
795  if ( QgsWkbTypes::hasZ( providerGeomType ) )
796  {
797  if ( !outputGeom )
798  {
799  outputGeom = geometry->clone();
800  }
801  outputGeom->addZValue();
802  }
803  if ( QgsWkbTypes::hasM( providerGeomType ) )
804  {
805  if ( !outputGeom )
806  {
807  outputGeom = geometry->clone();
808  }
809  outputGeom->addMValue();
810  }
811 
812  if ( outputGeom )
813  {
814  return new QgsGeometry( outputGeom );
815  }
816  return nullptr;
817 }
818 
819 void QgsVectorDataProvider::setNativeTypes( const QList<NativeType> &nativeTypes )
820 {
821  mNativeTypes = nativeTypes;
822 }
823 
825 {
826  return mEncoding;
827 }
828 
829 QStringList QgsVectorDataProvider::sEncodings;
830 
831 QList<QgsRelation> QgsVectorDataProvider::discoverRelations( const QgsVectorLayer *, const QList<QgsVectorLayer *> & ) const
832 {
833  return QList<QgsRelation>();
834 }
int lookupField(const QString &fieldName) const
Look up field&#39;s index from the field name.
Definition: qgsfields.cpp:289
QgsFeatureId id
Definition: qgsfeature.h:70
QString encoding() const
Get encoding which is used for accessing data.
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:512
static QVariant convertValue(QVariant::Type type, const QString &value)
virtual QgsVectorDataProvider::Capabilities capabilities() const
Returns flags containing the supported capabilities.
QMap< QString, int > fieldNameMap() const
Return a map where the key is the name of the field and the value is its index.
QString name
Definition: qgsfield.h:54
int precision
Definition: qgsfield.h:52
virtual bool addAttributes(const QList< QgsField > &attributes)
Adds new attributes to the provider.
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
virtual QVariant aggregate(QgsAggregateCalculator::Aggregate aggregate, int index, const QgsAggregateCalculator::AggregateParameters &parameters, QgsExpressionContext *context, bool &ok) const
Calculates an aggregated value from the layer&#39;s features.
virtual QgsWkbTypes::Type wkbType() const override=0
Returns the geometry type which is returned by this layer.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:54
static bool isMultiType(Type type)
Returns true if the WKB type is a multi type.
Definition: qgswkbtypes.h:550
Constraint
Constraints which may be present on a field.
#define QgsDebugMsg(str)
Definition: qgslogger.h:37
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:519
QgsFieldConstraints::Constraints fieldConstraints(int fieldIndex) const
Returns any constraints which are present at the provider for a specified field index.
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:524
Supports simplification of geometries on provider side according to a distance tolerance.
virtual QSet< QgsMapLayerDependency > dependencies() const
Get the list of layer ids on which this layer depends.
virtual bool deleteFeatures(const QgsFeatureIds &id)
Deletes one or more features from the provider.
virtual void setEncoding(const QString &e)
Set encoding used for accessing data from layer.
virtual QgsAttributeList pkAttributeIndexes() const
Return list of indexes of fields that make up the primary key.
virtual bool renameAttributes(const QgsFieldNameMap &renamedAttributes)
Renames existing attributes.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
void pushError(const QString &msg) const
Push a notification about errors that happened in this providers scope.
void raiseError(const QString &msg) const
Signals an error in this provider.
virtual void uniqueValues(int index, QList< QVariant > &uniqueValues, int limit=-1) const
Return unique values of an attribute.
Container of fields for a vector layer.
Definition: qgsfields.h:41
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:96
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...
Definition: qgsfeature.h:61
QList< QgsVectorDataProvider::NativeType > nativeTypes() const
Returns the names of the supported types.
virtual QgsFields fields() const override=0
Returns the fields associated with this data provider.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
virtual bool addFeatures(QgsFeatureList &flist) override
Adds a list of features to the sink.
int count() const
Return number of items.
Definition: qgsfields.cpp:115
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
Definition: qgswkbtypes.h:755
virtual bool createAttributeIndex(int field)
Create an attribute index on the datasource.
bool supportedType(const QgsField &field) const
check if provider supports type of field
QgsField at(int i) const
Get field at particular index (must be in range 0..N-1)
Definition: qgsfields.cpp:135
int length
Definition: qgsfield.h:51
void dataChanged()
This is emitted whenever an asynchronous operation has finished and the data should be redrawn...
Base class for feedback objects to be used for cancelation of something running in a worker thread...
Definition: qgsfeedback.h:43
virtual bool skipConstraintCheck(int fieldIndex, QgsFieldConstraints::Constraint constraint, const QVariant &value=QVariant()) const
Returns true if a constraint check should be skipped for a specified field (e.g., if the value return...
void setNativeTypes(const QList< QgsVectorDataProvider::NativeType > &nativeTypes)
Set the list of native types supported by this provider.
Allows creation of spatial index.
QSet< int > QgsAttributeIds
virtual bool createSpatialIndex()
Creates a spatial index on the datasource (if supported by the provider type).
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:66
Can create indexes on provider&#39;s fields.
QgsAttributeList allAttributesList() const
Utility function to get list of attribute indexes.
Definition: qgsfields.cpp:316
void fillMinMaxCache() const
Populates the cache of minimum and maximum attribute values.
Allows addition of new attributes (fields)
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:38
void clearMinMaxCache()
Invalidates the min/max cache.
Geometry collection.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
virtual bool changeAttributeValues(const QgsChangedAttributesMap &attr_map)
Changes attribute values of existing features.
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.
QStringList errors() const
Get recorded errors.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
virtual QString defaultValueClause(int fieldIndex) const
Returns any default value clauses which are present at the provider for a specified field index...
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
Allows modifications of geometries.
void clearErrors()
Clear recorded errors.
virtual bool isDeleteStyleFromDatabaseSupported() const
It returns false by default.
virtual QgsTransaction * transaction() const
Returns the transaction this data provider is included in, if any.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:46
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:452
QgsCoordinateReferenceSystem sourceCrs() const override
Returns the coordinate reference system for features in the source.
virtual bool isSaveAndLoadStyleToDatabaseSupported() const
It returns false by default.
Abstract base class for all geometries.
Fast access to features using their ID.
virtual bool changeGeometryValues(const QgsGeometryMap &geometry_map)
Changes geometries of existing features.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const override=0
Query the provider for features specified in request.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:437
QgsVectorDataProvider(const QString &uri=QString())
Constructor of the vector provider.
QMap< int, QString > QgsFieldNameMap
Definition: qgsattributes.h:45
virtual QVariant minimumValue(int index) const
Returns the minimum value of an attribute.
Supports circular geometry types (circularstring, compoundcurve, curvepolygon)
virtual void forceReload()
Forces a reload of the underlying datasource if the provider implements this method.
int nCurves() const
Returns the number of curves in the geometry.
Supports topological simplification of geometries on provider side according to a distance tolerance...
QString capabilitiesString() const
Returns the above in friendly format.
static void logMessage(const QString &message, const QString &tag=QString(), MessageLevel level=QgsMessageLog::WARNING)
add a message to the instance (and create it if necessary)
QgsFieldConstraints constraints
Definition: qgsfield.h:57
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition: qgsfeedback.h:63
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:503
virtual QVariant maximumValue(int index) const
Returns the maximum value of an attribute.
This class allows including a set of layers in a database-side transaction, provided the layer data p...
static bool isCurvedType(Type type)
Returns true if the WKB type is a curved type or can contain curved geometries.
Definition: qgswkbtypes.h:598
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
virtual QgsCircularString * clone() const override
Clones the geometry by performing a deep copy.
bool hasErrors() const
Provider has errors to report.
virtual bool truncate()
Removes all features from the layer.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
static QgsAbstractGeometry * geomFromWkbType(QgsWkbTypes::Type t)
Return empty geometry from wkb type.
virtual QString dataComment() const
Return a short comment for the data that this provider is providing access to (e.g.
This class represents a coordinate reference system (CRS).
virtual QStringList uniqueStringsMatching(int index, const QString &substring, int limit=-1, QgsFeedback *feedback=nullptr) const
Returns unique string values of an attribute which contain a specified subset string.
const QgsCurve * curveAt(int i) const
Returns the curve at the specified index.
virtual QgsAttributeList attributeIndexes() const
Return list of indexes to fetch all attributes in nextFeature()
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes from the provider.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
Definition: qgswkbtypes.h:804
Compound curve geometry type.
Circular string geometry type.
virtual QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
QList< int > QgsAttributeList
Definition: qgsfield.h:27
bool nextFeature(QgsFeature &f)
Provider has no capabilities.
virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const
Return list of indexes to names for QgsPalLabeling fix.
Geometry is not required. It may still be returned if e.g. required for a filter condition.
A vector of attributes.
Definition: qgsattributes.h:57
Represents a vector layer which manages a vector based data sets.
QTextCodec * textEncoding() const
Get this providers encoding.
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
Definition: qgsfield.cpp:94
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Definition: qgsfeature.cpp:255
QgsGeometry * convertToProviderType(const QgsGeometry &geom) const
Converts the geometry to the provider type if possible / necessary.
static Type flatType(Type type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:423
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
QgsAbstractGeometry * geometry() const
Returns the underlying geometry store.
QHash< int, QString > QgsAttrPalIndexNameHash
Allows modification of attribute values.
QgsAttributes attributes
Definition: qgsfeature.h:71
virtual QgsAbstractGeometry * toCurveType() const
Returns the geometry converted to the more generic curve type.
static QStringList availableEncodings()
Returns a list of available encodings.
Aggregate
Available aggregates to calculate.
virtual bool addGeometry(QgsAbstractGeometry *g)
Adds a geometry and takes ownership. Returns true in case of success.
Supports joint updates for attributes and geometry Providers supporting this should still define Chan...
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Set flags that affect how features will be fetched.
A bundle of parameters controlling aggregate calculation.
virtual QVariant defaultValue(int fieldIndex) const
Returns any literal default values which are present at the provider for a specified field index...
virtual QList< QgsRelation > discoverRelations(const QgsVectorLayer *self, const QList< QgsVectorLayer *> &layers) const
Discover the available relations with the given layers.