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