QGIS API Documentation  2.99.0-Master (9caa722)
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 extent();
58 }
59 
61 {
62  return QString();
63 }
64 
66 {
67  Q_UNUSED( flist );
68  Q_UNUSED( flags );
69  return false;
70 }
71 
73 {
74  Q_UNUSED( ids );
75  return false;
76 }
77 
79 {
80  if ( !( capabilities() & DeleteFeatures ) )
81  return false;
82 
83  QgsFeatureIds toDelete;
85  QgsFeature f;
86  while ( it.nextFeature( f ) )
87  toDelete << f.id();
88 
89  return deleteFeatures( toDelete );
90 }
91 
92 bool QgsVectorDataProvider::addAttributes( const QList<QgsField> &attributes )
93 {
94  Q_UNUSED( attributes );
95  return false;
96 }
97 
99 {
100  Q_UNUSED( attributes );
101  return false;
102 }
103 
105 {
106  Q_UNUSED( renamedAttributes );
107  return false;
108 }
109 
111 {
112  Q_UNUSED( attr_map );
113  return false;
114 }
115 
116 QVariant QgsVectorDataProvider::defaultValue( int fieldId ) const
117 {
118  Q_UNUSED( fieldId );
119  return QVariant();
120 }
121 
122 QString QgsVectorDataProvider::defaultValueClause( int fieldIndex ) const
123 {
124  Q_UNUSED( fieldIndex );
125  return QString();
126 }
127 
128 QgsFieldConstraints::Constraints QgsVectorDataProvider::fieldConstraints( int fieldIndex ) const
129 {
130  QgsFields f = fields();
131  if ( fieldIndex < 0 || fieldIndex >= f.count() )
132  return 0;
133 
134  return f.at( fieldIndex ).constraints().constraints();
135 }
136 
138 {
139  return false;
140 }
141 
143 {
144  Q_UNUSED( geometry_map );
145  return false;
146 }
147 
149  const QgsGeometryMap &geometry_map )
150 {
152  return false;
153 
154  bool result = true;
155  result = result && changeAttributeValues( attr_map );
156  result = result && changeGeometryValues( geometry_map );
157  return result;
158 }
159 
161 {
162  return false;
163 }
164 
166 {
167  Q_UNUSED( field );
168  return true;
169 }
170 
171 QgsVectorDataProvider::Capabilities QgsVectorDataProvider::capabilities() const
172 {
174 }
175 
176 
177 void QgsVectorDataProvider::setEncoding( const QString &e )
178 {
179  mEncoding = QTextCodec::codecForName( e.toLocal8Bit().constData() );
180 
181  if ( !mEncoding && e != QLatin1String( "System" ) )
182  {
183  QgsMessageLog::logMessage( tr( "Codec %1 not found. Falling back to system locale" ).arg( e ) );
184  mEncoding = QTextCodec::codecForName( "System" );
185  }
186 
187  if ( !mEncoding )
188  mEncoding = QTextCodec::codecForLocale();
189 
190  Q_ASSERT( mEncoding );
191 }
192 
194 {
195  if ( mEncoding )
196  {
197  return mEncoding->name();
198  }
199 
200  return QLatin1String( "" );
201 }
202 
204 {
205  QStringList abilitiesList;
206 
207  int abilities = capabilities();
208 
209  if ( abilities & QgsVectorDataProvider::AddFeatures )
210  {
211  abilitiesList += tr( "Add Features" );
212  }
213 
214  if ( abilities & QgsVectorDataProvider::DeleteFeatures )
215  {
216  abilitiesList += tr( "Delete Features" );
217  }
218 
220  {
221  abilitiesList += tr( "Change Attribute Values" );
222  }
223 
224  if ( abilities & QgsVectorDataProvider::AddAttributes )
225  {
226  abilitiesList += tr( "Add Attributes" );
227  }
228 
229  if ( abilities & QgsVectorDataProvider::DeleteAttributes )
230  {
231  abilitiesList += tr( "Delete Attributes" );
232  }
233 
234  if ( abilities & QgsVectorDataProvider::RenameAttributes )
235  {
236  abilitiesList += tr( "Rename Attributes" );
237  }
238 
240  {
241  // TODO: Tighten up this test. See QgsOgrProvider for details.
242  abilitiesList += tr( "Create Spatial Index" );
243  }
244 
246  {
247  abilitiesList += tr( "Create Attribute Indexes" );
248  }
249 
250  if ( abilities & QgsVectorDataProvider::SelectAtId )
251  {
252  abilitiesList += tr( "Fast Access to Features at ID" );
253  }
254 
255  if ( abilities & QgsVectorDataProvider::ChangeGeometries )
256  {
257  abilitiesList += tr( "Change Geometries" );
258  }
259 
261  {
262  abilitiesList += tr( "Presimplify Geometries" );
263  }
264 
266  {
267  abilitiesList += tr( "Presimplify Geometries with Validity Check" );
268  }
269 
270  if ( abilities & QgsVectorDataProvider::ChangeFeatures )
271  {
272  abilitiesList += tr( "Simultaneous Geometry and Attribute Updates" );
273  }
274 
276  {
277  abilitiesList += tr( "Transactions" );
278  }
279 
281  {
282  abilitiesList += tr( "Curved Geometries" );
283  }
284 
285  return abilitiesList.join( QStringLiteral( ", " ) );
286 }
287 
288 
289 int QgsVectorDataProvider::fieldNameIndex( const QString &fieldName ) const
290 {
291  return fields().lookupField( fieldName );
292 }
293 
294 QMap<QString, int> QgsVectorDataProvider::fieldNameMap() const
295 {
296  QMap<QString, int> resultMap;
297 
298  QgsFields fieldsCopy = fields();
299  for ( int i = 0; i < fieldsCopy.count(); ++i )
300  {
301  resultMap.insert( fieldsCopy.at( i ).name(), i );
302  }
303 
304  return resultMap;
305 }
306 
308 {
309  return fields().allAttributesList();
310 }
311 
313 {
314  return QgsAttributeList();
315 }
316 
317 QList<QgsVectorDataProvider::NativeType> QgsVectorDataProvider::nativeTypes() const
318 {
319  return mNativeTypes;
320 }
321 
323 {
324  return QgsAttrPalIndexNameHash();
325 }
326 
328 {
329  QgsDebugMsgLevel( QString( "field name = %1 type = %2 length = %3 precision = %4" )
330  .arg( field.name(),
331  QVariant::typeToName( field.type() ) )
332  .arg( field.length() )
333  .arg( field.precision() ), 2 );
334 
335  Q_FOREACH ( const NativeType &nativeType, mNativeTypes )
336  {
337  QgsDebugMsgLevel( QString( "native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" )
338  .arg( QVariant::typeToName( nativeType.mType ) )
339  .arg( nativeType.mMinLen )
340  .arg( nativeType.mMaxLen )
341  .arg( nativeType.mMinPrec )
342  .arg( nativeType.mMaxPrec ), 2 );
343 
344  if ( field.type() != nativeType.mType )
345  continue;
346 
347  if ( field.length() == -1 )
348  {
349  // source length unlimited
350  if ( nativeType.mMinLen > -1 || nativeType.mMaxLen > -1 )
351  {
352  // destination limited
353  continue;
354  }
355  }
356  else
357  {
358  // source length limited
359  if ( nativeType.mMinLen > -1 && nativeType.mMaxLen > -1 &&
360  ( field.length() < nativeType.mMinLen || field.length() > nativeType.mMaxLen ) )
361  {
362  // source length exceeds destination limits
363  continue;
364  }
365  }
366 
367  if ( field.precision() == -1 )
368  {
369  // source precision unlimited / n/a
370  if ( nativeType.mMinPrec > -1 || nativeType.mMaxPrec > -1 )
371  {
372  // destination limited
373  continue;
374  }
375  }
376  else
377  {
378  // source precision unlimited / n/a
379  if ( nativeType.mMinPrec > -1 && nativeType.mMaxPrec > -1 &&
380  ( field.precision() < nativeType.mMinPrec || field.precision() > nativeType.mMaxPrec ) )
381  {
382  // source precision exceeds destination limits
383  continue;
384  }
385  }
386 
387  QgsDebugMsg( "native type matches" );
388  return true;
389  }
390 
391  QgsDebugMsg( "no sufficient native type found" );
392  return false;
393 }
394 
395 QVariant QgsVectorDataProvider::minimumValue( int index ) const
396 {
397  if ( index < 0 || index >= fields().count() )
398  {
399  QgsDebugMsg( "Warning: access requested to invalid field index: " + QString::number( index ) );
400  return QVariant();
401  }
402 
403  fillMinMaxCache();
404 
405  if ( !mCacheMinValues.contains( index ) )
406  return QVariant();
407 
408  return mCacheMinValues[index];
409 }
410 
411 QVariant QgsVectorDataProvider::maximumValue( int index ) const
412 {
413  if ( index < 0 || index >= fields().count() )
414  {
415  QgsDebugMsg( "Warning: access requested to invalid field index: " + QString::number( index ) );
416  return QVariant();
417  }
418 
419  fillMinMaxCache();
420 
421  if ( !mCacheMaxValues.contains( index ) )
422  return QVariant();
423 
424  return mCacheMaxValues[index];
425 }
426 
427 
428 QStringList QgsVectorDataProvider::uniqueStringsMatching( int index, const QString &substring, int limit, QgsFeedback *feedback ) const
429 {
430  QgsFeature f;
431  QgsAttributeList keys;
432  keys.append( index );
433 
434  QgsFeatureRequest request;
435  request.setSubsetOfAttributes( keys );
437  QString fieldName = fields().at( index ).name();
438  request.setFilterExpression( QStringLiteral( "\"%1\" ILIKE '%%2%'" ).arg( fieldName, substring ) );
439  QgsFeatureIterator fi = getFeatures( request );
440 
441  QSet<QString> set;
442  QStringList results;
443 
444  while ( fi.nextFeature( f ) )
445  {
446  QString value = f.attribute( index ).toString();
447  if ( !set.contains( value ) )
448  {
449  results.append( value );
450  set.insert( value );
451  }
452 
453  if ( ( limit >= 0 && results.size() >= limit ) || ( feedback && feedback->isCanceled() ) )
454  break;
455  }
456  return results;
457 }
458 
460  const QgsAggregateCalculator::AggregateParameters &parameters, QgsExpressionContext *context, bool &ok ) const
461 {
462  //base implementation does nothing
463  Q_UNUSED( aggregate );
464  Q_UNUSED( index );
465  Q_UNUSED( parameters );
466  Q_UNUSED( context );
467 
468  ok = false;
469  return QVariant();
470 }
471 
473 {
474  mCacheMinMaxDirty = true;
475 }
476 
478 {
479  if ( !mCacheMinMaxDirty )
480  return;
481 
482  QgsFields flds = fields();
483  for ( int i = 0; i < flds.count(); ++i )
484  {
485  if ( flds.at( i ).type() == QVariant::Int )
486  {
487  mCacheMinValues[i] = QVariant( INT_MAX );
488  mCacheMaxValues[i] = QVariant( INT_MIN );
489  }
490  else if ( flds.at( i ).type() == QVariant::LongLong )
491  {
492  mCacheMinValues[i] = QVariant( std::numeric_limits<qlonglong>::max() );
493  mCacheMaxValues[i] = QVariant( std::numeric_limits<qlonglong>::min() );
494  }
495  else if ( flds.at( i ).type() == QVariant::Double )
496  {
497  mCacheMinValues[i] = QVariant( DBL_MAX );
498  mCacheMaxValues[i] = QVariant( -DBL_MAX );
499  }
500  else
501  {
502  mCacheMinValues[i] = QVariant();
503  mCacheMaxValues[i] = QVariant();
504  }
505  }
506 
507  QgsFeature f;
508  QgsAttributeList keys = mCacheMinValues.keys();
509  QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys )
510  .setFlags( QgsFeatureRequest::NoGeometry ) );
511 
512  while ( fi.nextFeature( f ) )
513  {
514  QgsAttributes attrs = f.attributes();
515  for ( QgsAttributeList::const_iterator it = keys.constBegin(); it != keys.constEnd(); ++it )
516  {
517  const QVariant &varValue = attrs.at( *it );
518 
519  if ( varValue.isNull() )
520  continue;
521 
522  if ( flds.at( *it ).type() == QVariant::Int )
523  {
524  int value = varValue.toInt();
525  if ( value < mCacheMinValues[*it].toInt() )
526  mCacheMinValues[*it] = value;
527  if ( value > mCacheMaxValues[*it].toInt() )
528  mCacheMaxValues[*it] = value;
529  }
530  else if ( flds.at( *it ).type() == QVariant::LongLong )
531  {
532  qlonglong value = varValue.toLongLong();
533  if ( value < mCacheMinValues[*it].toLongLong() )
534  mCacheMinValues[*it] = value;
535  if ( value > mCacheMaxValues[*it].toLongLong() )
536  mCacheMaxValues[*it] = value;
537  }
538  else if ( flds.at( *it ).type() == QVariant::Double )
539  {
540  double value = varValue.toDouble();
541  if ( value < mCacheMinValues[*it].toDouble() )
542  mCacheMinValues[*it] = value;
543  if ( value > mCacheMaxValues[*it].toDouble() )
544  mCacheMaxValues[*it] = value;
545  }
546  else
547  {
548  QString value = varValue.toString();
549  if ( mCacheMinValues[*it].isNull() || value < mCacheMinValues[*it].toString() )
550  {
551  mCacheMinValues[*it] = value;
552  }
553  if ( mCacheMaxValues[*it].isNull() || value > mCacheMaxValues[*it].toString() )
554  {
555  mCacheMaxValues[*it] = value;
556  }
557  }
558  }
559  }
560 
561  mCacheMinMaxDirty = false;
562 }
563 
564 QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, const QString &value )
565 {
566  QVariant v( value );
567 
568  if ( !v.convert( type ) || value.isNull() )
569  v = QVariant( type );
570 
571  return v;
572 }
573 
575 {
576  return nullptr;
577 }
578 
580 {
581  emit dataChanged();
582 }
583 
584 static bool _compareEncodings( const QString &s1, const QString &s2 )
585 {
586  return s1.toLower() < s2.toLower();
587 }
588 
590 {
591  if ( sEncodings.isEmpty() )
592  {
593  Q_FOREACH ( const QString &codec, QTextCodec::availableCodecs() )
594  {
595  sEncodings << codec;
596  }
597 #if 0
598  smEncodings << "BIG5";
599  smEncodings << "BIG5-HKSCS";
600  smEncodings << "EUCJP";
601  smEncodings << "EUCKR";
602  smEncodings << "GB2312";
603  smEncodings << "GBK";
604  smEncodings << "GB18030";
605  smEncodings << "JIS7";
606  smEncodings << "SHIFT-JIS";
607  smEncodings << "TSCII";
608  smEncodings << "UTF-8";
609  smEncodings << "UTF-16";
610  smEncodings << "KOI8-R";
611  smEncodings << "KOI8-U";
612  smEncodings << "ISO8859-1";
613  smEncodings << "ISO8859-2";
614  smEncodings << "ISO8859-3";
615  smEncodings << "ISO8859-4";
616  smEncodings << "ISO8859-5";
617  smEncodings << "ISO8859-6";
618  smEncodings << "ISO8859-7";
619  smEncodings << "ISO8859-8";
620  smEncodings << "ISO8859-8-I";
621  smEncodings << "ISO8859-9";
622  smEncodings << "ISO8859-10";
623  smEncodings << "ISO8859-11";
624  smEncodings << "ISO8859-12";
625  smEncodings << "ISO8859-13";
626  smEncodings << "ISO8859-14";
627  smEncodings << "ISO8859-15";
628  smEncodings << "IBM 850";
629  smEncodings << "IBM 866";
630  smEncodings << "CP874";
631  smEncodings << "CP1250";
632  smEncodings << "CP1251";
633  smEncodings << "CP1252";
634  smEncodings << "CP1253";
635  smEncodings << "CP1254";
636  smEncodings << "CP1255";
637  smEncodings << "CP1256";
638  smEncodings << "CP1257";
639  smEncodings << "CP1258";
640  smEncodings << "Apple Roman";
641  smEncodings << "TIS-620";
642  smEncodings << "System";
643 #endif
644  }
645 
646  // Do case-insensitive sorting of encodings
647  std::sort( sEncodings.begin(), sEncodings.end(), _compareEncodings );
648 
649  return sEncodings;
650 }
651 
653 {
654  mErrors.clear();
655 }
656 
658 {
659  return !mErrors.isEmpty();
660 }
661 
662 QStringList QgsVectorDataProvider::errors() const
663 {
664  return mErrors;
665 }
666 
668 {
669  return false;
670 }
671 
673 {
674  return false;
675 }
676 
677 void QgsVectorDataProvider::pushError( const QString &msg ) const
678 {
679  QgsDebugMsg( msg );
680  mErrors << msg;
681  emit raiseError( msg );
682 }
683 
684 QSet<QgsMapLayerDependency> QgsVectorDataProvider::dependencies() const
685 {
686  return QSet<QgsMapLayerDependency>();
687 }
688 
690 {
691  if ( geom.isNull() )
692  {
693  return QgsGeometry();
694  }
695 
696  QgsAbstractGeometry *geometry = geom.geometry();
697  if ( !geometry )
698  {
699  return QgsGeometry();
700  }
701 
702  QgsWkbTypes::Type providerGeomType = wkbType();
703 
704  //geom is already in the provider geometry type
705  if ( geometry->wkbType() == providerGeomType )
706  {
707  return QgsGeometry();
708  }
709 
710  std::unique_ptr< QgsAbstractGeometry > outputGeom;
711 
712  //convert compoundcurve to circularstring (possible if compoundcurve consists of one circular string)
713  if ( QgsWkbTypes::flatType( providerGeomType ) == QgsWkbTypes::CircularString )
714  {
715  QgsCompoundCurve *compoundCurve = qgsgeometry_cast<QgsCompoundCurve *>( geometry );
716  if ( compoundCurve )
717  {
718  if ( compoundCurve->nCurves() == 1 )
719  {
720  const QgsCircularString *circularString = qgsgeometry_cast<const QgsCircularString *>( compoundCurve->curveAt( 0 ) );
721  if ( circularString )
722  {
723  outputGeom.reset( circularString->clone() );
724  }
725  }
726  }
727  }
728 
729  //convert to multitype if necessary
730  if ( QgsWkbTypes::isMultiType( providerGeomType ) && !QgsWkbTypes::isMultiType( geometry->wkbType() ) )
731  {
732  outputGeom = QgsGeometryFactory::geomFromWkbType( providerGeomType );
733  QgsGeometryCollection *geomCollection = qgsgeometry_cast<QgsGeometryCollection *>( outputGeom.get() );
734  if ( geomCollection )
735  {
736  geomCollection->addGeometry( geometry->clone() );
737  }
738  }
739 
740  //convert to curved type if necessary
741  if ( !QgsWkbTypes::isCurvedType( geometry->wkbType() ) && QgsWkbTypes::isCurvedType( providerGeomType ) )
742  {
743  QgsAbstractGeometry *curveGeom = outputGeom ? outputGeom->toCurveType() : geometry->toCurveType();
744  if ( curveGeom )
745  {
746  outputGeom.reset( curveGeom );
747  }
748  }
749 
750  //convert to linear type from curved type
751  if ( QgsWkbTypes::isCurvedType( geometry->wkbType() ) && !QgsWkbTypes::isCurvedType( providerGeomType ) )
752  {
753  QgsAbstractGeometry *segmentizedGeom = nullptr;
754  segmentizedGeom = outputGeom ? outputGeom->segmentize() : geometry->segmentize();
755  if ( segmentizedGeom )
756  {
757  outputGeom.reset( segmentizedGeom );
758  }
759  }
760 
761  //set z/m types
762  if ( QgsWkbTypes::hasZ( providerGeomType ) )
763  {
764  if ( !outputGeom )
765  {
766  outputGeom.reset( geometry->clone() );
767  }
768  outputGeom->addZValue();
769  }
770  if ( QgsWkbTypes::hasM( providerGeomType ) )
771  {
772  if ( !outputGeom )
773  {
774  outputGeom.reset( geometry->clone() );
775  }
776  outputGeom->addMValue();
777  }
778 
779  if ( outputGeom )
780  {
781  return QgsGeometry( outputGeom.release() );
782  }
783  return QgsGeometry();
784 }
785 
786 void QgsVectorDataProvider::setNativeTypes( const QList<NativeType> &nativeTypes )
787 {
788  mNativeTypes = nativeTypes;
789 }
790 
792 {
793  return mEncoding;
794 }
795 
796 QStringList QgsVectorDataProvider::sEncodings;
797 
798 QList<QgsRelation> QgsVectorDataProvider::discoverRelations( const QgsVectorLayer *, const QList<QgsVectorLayer *> & ) const
799 {
800  return QList<QgsRelation>();
801 }
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)
A rectangle specified with double values.
Definition: qgsrectangle.h:38
virtual QVariant maximumValue(int index) const override
Returns the maximum value of an attribute.
static std::unique_ptr< QgsAbstractGeometry > geomFromWkbType(QgsWkbTypes::Type t)
Return empty geometry from wkb type.
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.
virtual QgsAbstractGeometry * toCurveType() const =0
Returns the geometry converted to the more generic curve type.
QString name
Definition: qgsfield.h:54
virtual QVariant minimumValue(int index) const override
Returns the minimum value of an attribute.
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.
Container of fields for a vector layer.
Definition: qgsfields.h:41
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:92
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.
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.
virtual bool addFeatures(QgsFeatureList &flist, QgsFeatureSink::Flags flags=0) override
Adds a list of features to the sink.
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...
T qgsgeometry_cast(const QgsAbstractGeometry *geom)
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.
QgsGeometry convertToProviderType(const QgsGeometry &geom) const
Converts the geometry to the provider type if possible / necessary.
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
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.
QgsVectorDataProvider(const QString &uri=QString())
Constructor of the vector provider.
QMap< int, QString > QgsFieldNameMap
Definition: qgsattributes.h:45
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
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.
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 QgsRectangle extent() const =0
Returns the extent of the layer.
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:93
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Definition: qgsfeature.cpp:255
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
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.
QgsRectangle sourceExtent() const override
Returns the extent of all geometries from the source.
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.