QGIS API Documentation  2.99.0-Master (dcec6bb)
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  QgsDebugMsg( "Capability: Add Features" );
213  }
214 
215  if ( abilities & QgsVectorDataProvider::DeleteFeatures )
216  {
217  abilitiesList += tr( "Delete Features" );
218  QgsDebugMsg( "Capability: Delete Features" );
219  }
220 
222  {
223  abilitiesList += tr( "Change Attribute Values" );
224  QgsDebugMsg( "Capability: Change Attribute Values" );
225  }
226 
227  if ( abilities & QgsVectorDataProvider::AddAttributes )
228  {
229  abilitiesList += tr( "Add Attributes" );
230  QgsDebugMsg( "Capability: Add Attributes" );
231  }
232 
233  if ( abilities & QgsVectorDataProvider::DeleteAttributes )
234  {
235  abilitiesList += tr( "Delete Attributes" );
236  QgsDebugMsg( "Capability: Delete Attributes" );
237  }
238 
239  if ( abilities & QgsVectorDataProvider::RenameAttributes )
240  {
241  abilitiesList += tr( "Rename Attributes" );
242  QgsDebugMsg( "Capability: Rename Attributes" );
243  }
244 
246  {
247  // TODO: Tighten up this test. See QgsOgrProvider for details.
248  abilitiesList += tr( "Create Spatial Index" );
249  QgsDebugMsg( "Capability: Create Spatial Index" );
250  }
251 
253  {
254  abilitiesList += tr( "Create Attribute Indexes" );
255  QgsDebugMsg( "Capability: Create Attribute Index" );
256  }
257 
258  if ( abilities & QgsVectorDataProvider::SelectAtId )
259  {
260  abilitiesList += tr( "Fast Access to Features at ID" );
261  QgsDebugMsg( "Capability: Select at ID" );
262  }
263 
264  if ( abilities & QgsVectorDataProvider::ChangeGeometries )
265  {
266  abilitiesList += tr( "Change Geometries" );
267  QgsDebugMsg( "Capability: Change Geometries" );
268  }
269 
271  {
272  abilitiesList += tr( "Presimplify Geometries" );
273  QgsDebugMsg( "Capability: Simplify Geometries before fetching the feature" );
274  }
275 
277  {
278  abilitiesList += tr( "Presimplify Geometries with Validity Check" );
279  QgsDebugMsg( "Capability: Simplify Geometries before fetch the feature ensuring that the result is a valid geometry" );
280  }
281 
282  if ( abilities & QgsVectorDataProvider::ChangeFeatures )
283  {
284  abilitiesList += tr( "Simultaneous Geometry and Attribute Updates" );
285  QgsDebugMsg( "Capability: change both feature attributes and geometry at once" );
286  }
287 
289  {
290  abilitiesList += tr( "Transactions" );
291  QgsDebugMsg( "Capability: transactions" );
292  }
293 
295  {
296  abilitiesList += tr( "Curved Geometries" );
297  QgsDebugMsg( "Supports circular geometry types (circularstring, compoundcurve, curvepolygon)" );
298  }
299 
300  return abilitiesList.join( QStringLiteral( ", " ) );
301 }
302 
303 
304 int QgsVectorDataProvider::fieldNameIndex( const QString &fieldName ) const
305 {
306  return fields().lookupField( fieldName );
307 }
308 
309 QMap<QString, int> QgsVectorDataProvider::fieldNameMap() const
310 {
311  QMap<QString, int> resultMap;
312 
313  QgsFields fieldsCopy = fields();
314  for ( int i = 0; i < fieldsCopy.count(); ++i )
315  {
316  resultMap.insert( fieldsCopy.at( i ).name(), i );
317  }
318 
319  return resultMap;
320 }
321 
323 {
324  return fields().allAttributesList();
325 }
326 
328 {
329  return QgsAttributeList();
330 }
331 
332 QList<QgsVectorDataProvider::NativeType> QgsVectorDataProvider::nativeTypes() const
333 {
334  return mNativeTypes;
335 }
336 
338 {
339  return QgsAttrPalIndexNameHash();
340 }
341 
343 {
344  QgsDebugMsgLevel( QString( "field name = %1 type = %2 length = %3 precision = %4" )
345  .arg( field.name(),
346  QVariant::typeToName( field.type() ) )
347  .arg( field.length() )
348  .arg( field.precision() ), 2 );
349 
350  Q_FOREACH ( const NativeType &nativeType, mNativeTypes )
351  {
352  QgsDebugMsgLevel( QString( "native field type = %1 min length = %2 max length = %3 min precision = %4 max precision = %5" )
353  .arg( QVariant::typeToName( nativeType.mType ) )
354  .arg( nativeType.mMinLen )
355  .arg( nativeType.mMaxLen )
356  .arg( nativeType.mMinPrec )
357  .arg( nativeType.mMaxPrec ), 2 );
358 
359  if ( field.type() != nativeType.mType )
360  continue;
361 
362  if ( field.length() == -1 )
363  {
364  // source length unlimited
365  if ( nativeType.mMinLen > -1 || nativeType.mMaxLen > -1 )
366  {
367  // destination limited
368  continue;
369  }
370  }
371  else
372  {
373  // source length limited
374  if ( nativeType.mMinLen > -1 && nativeType.mMaxLen > -1 &&
375  ( field.length() < nativeType.mMinLen || field.length() > nativeType.mMaxLen ) )
376  {
377  // source length exceeds destination limits
378  continue;
379  }
380  }
381 
382  if ( field.precision() == -1 )
383  {
384  // source precision unlimited / n/a
385  if ( nativeType.mMinPrec > -1 || nativeType.mMaxPrec > -1 )
386  {
387  // destination limited
388  continue;
389  }
390  }
391  else
392  {
393  // source precision unlimited / n/a
394  if ( nativeType.mMinPrec > -1 && nativeType.mMaxPrec > -1 &&
395  ( field.precision() < nativeType.mMinPrec || field.precision() > nativeType.mMaxPrec ) )
396  {
397  // source precision exceeds destination limits
398  continue;
399  }
400  }
401 
402  QgsDebugMsg( "native type matches" );
403  return true;
404  }
405 
406  QgsDebugMsg( "no sufficient native type found" );
407  return false;
408 }
409 
410 QVariant QgsVectorDataProvider::minimumValue( 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 ( !mCacheMinValues.contains( index ) )
421  return QVariant();
422 
423  return mCacheMinValues[index];
424 }
425 
426 QVariant QgsVectorDataProvider::maximumValue( int index ) const
427 {
428  if ( index < 0 || index >= fields().count() )
429  {
430  QgsDebugMsg( "Warning: access requested to invalid field index: " + QString::number( index ) );
431  return QVariant();
432  }
433 
434  fillMinMaxCache();
435 
436  if ( !mCacheMaxValues.contains( index ) )
437  return QVariant();
438 
439  return mCacheMaxValues[index];
440 }
441 
442 
443 QStringList QgsVectorDataProvider::uniqueStringsMatching( int index, const QString &substring, int limit, QgsFeedback *feedback ) const
444 {
445  QgsFeature f;
446  QgsAttributeList keys;
447  keys.append( index );
448 
449  QgsFeatureRequest request;
450  request.setSubsetOfAttributes( keys );
452  QString fieldName = fields().at( index ).name();
453  request.setFilterExpression( QStringLiteral( "\"%1\" ILIKE '%%2%'" ).arg( fieldName, substring ) );
454  QgsFeatureIterator fi = getFeatures( request );
455 
456  QSet<QString> set;
457  QStringList results;
458 
459  while ( fi.nextFeature( f ) )
460  {
461  QString value = f.attribute( index ).toString();
462  if ( !set.contains( value ) )
463  {
464  results.append( value );
465  set.insert( value );
466  }
467 
468  if ( ( limit >= 0 && results.size() >= limit ) || ( feedback && feedback->isCanceled() ) )
469  break;
470  }
471  return results;
472 }
473 
475  const QgsAggregateCalculator::AggregateParameters &parameters, QgsExpressionContext *context, bool &ok ) const
476 {
477  //base implementation does nothing
478  Q_UNUSED( aggregate );
479  Q_UNUSED( index );
480  Q_UNUSED( parameters );
481  Q_UNUSED( context );
482 
483  ok = false;
484  return QVariant();
485 }
486 
488 {
489  mCacheMinMaxDirty = true;
490 }
491 
493 {
494  if ( !mCacheMinMaxDirty )
495  return;
496 
497  QgsFields flds = fields();
498  for ( int i = 0; i < flds.count(); ++i )
499  {
500  if ( flds.at( i ).type() == QVariant::Int )
501  {
502  mCacheMinValues[i] = QVariant( INT_MAX );
503  mCacheMaxValues[i] = QVariant( INT_MIN );
504  }
505  else if ( flds.at( i ).type() == QVariant::LongLong )
506  {
507  mCacheMinValues[i] = QVariant( std::numeric_limits<qlonglong>::max() );
508  mCacheMaxValues[i] = QVariant( std::numeric_limits<qlonglong>::min() );
509  }
510  else if ( flds.at( i ).type() == QVariant::Double )
511  {
512  mCacheMinValues[i] = QVariant( DBL_MAX );
513  mCacheMaxValues[i] = QVariant( -DBL_MAX );
514  }
515  else
516  {
517  mCacheMinValues[i] = QVariant();
518  mCacheMaxValues[i] = QVariant();
519  }
520  }
521 
522  QgsFeature f;
523  QgsAttributeList keys = mCacheMinValues.keys();
524  QgsFeatureIterator fi = getFeatures( QgsFeatureRequest().setSubsetOfAttributes( keys )
525  .setFlags( QgsFeatureRequest::NoGeometry ) );
526 
527  while ( fi.nextFeature( f ) )
528  {
529  QgsAttributes attrs = f.attributes();
530  for ( QgsAttributeList::const_iterator it = keys.begin(); it != keys.end(); ++it )
531  {
532  const QVariant &varValue = attrs.at( *it );
533 
534  if ( varValue.isNull() )
535  continue;
536 
537  if ( flds.at( *it ).type() == QVariant::Int )
538  {
539  int value = varValue.toInt();
540  if ( value < mCacheMinValues[*it].toInt() )
541  mCacheMinValues[*it] = value;
542  if ( value > mCacheMaxValues[*it].toInt() )
543  mCacheMaxValues[*it] = value;
544  }
545  else if ( flds.at( *it ).type() == QVariant::LongLong )
546  {
547  qlonglong value = varValue.toLongLong();
548  if ( value < mCacheMinValues[*it].toLongLong() )
549  mCacheMinValues[*it] = value;
550  if ( value > mCacheMaxValues[*it].toLongLong() )
551  mCacheMaxValues[*it] = value;
552  }
553  else if ( flds.at( *it ).type() == QVariant::Double )
554  {
555  double value = varValue.toDouble();
556  if ( value < mCacheMinValues[*it].toDouble() )
557  mCacheMinValues[*it] = value;
558  if ( value > mCacheMaxValues[*it].toDouble() )
559  mCacheMaxValues[*it] = value;
560  }
561  else
562  {
563  QString value = varValue.toString();
564  if ( mCacheMinValues[*it].isNull() || value < mCacheMinValues[*it].toString() )
565  {
566  mCacheMinValues[*it] = value;
567  }
568  if ( mCacheMaxValues[*it].isNull() || value > mCacheMaxValues[*it].toString() )
569  {
570  mCacheMaxValues[*it] = value;
571  }
572  }
573  }
574  }
575 
576  mCacheMinMaxDirty = false;
577 }
578 
579 QVariant QgsVectorDataProvider::convertValue( QVariant::Type type, const QString &value )
580 {
581  QVariant v( value );
582 
583  if ( !v.convert( type ) || value.isNull() )
584  v = QVariant( type );
585 
586  return v;
587 }
588 
590 {
591  return nullptr;
592 }
593 
595 {
596  emit dataChanged();
597 }
598 
599 static bool _compareEncodings( const QString &s1, const QString &s2 )
600 {
601  return s1.toLower() < s2.toLower();
602 }
603 
605 {
606  if ( sEncodings.isEmpty() )
607  {
608  Q_FOREACH ( const QString &codec, QTextCodec::availableCodecs() )
609  {
610  sEncodings << codec;
611  }
612 #if 0
613  smEncodings << "BIG5";
614  smEncodings << "BIG5-HKSCS";
615  smEncodings << "EUCJP";
616  smEncodings << "EUCKR";
617  smEncodings << "GB2312";
618  smEncodings << "GBK";
619  smEncodings << "GB18030";
620  smEncodings << "JIS7";
621  smEncodings << "SHIFT-JIS";
622  smEncodings << "TSCII";
623  smEncodings << "UTF-8";
624  smEncodings << "UTF-16";
625  smEncodings << "KOI8-R";
626  smEncodings << "KOI8-U";
627  smEncodings << "ISO8859-1";
628  smEncodings << "ISO8859-2";
629  smEncodings << "ISO8859-3";
630  smEncodings << "ISO8859-4";
631  smEncodings << "ISO8859-5";
632  smEncodings << "ISO8859-6";
633  smEncodings << "ISO8859-7";
634  smEncodings << "ISO8859-8";
635  smEncodings << "ISO8859-8-I";
636  smEncodings << "ISO8859-9";
637  smEncodings << "ISO8859-10";
638  smEncodings << "ISO8859-11";
639  smEncodings << "ISO8859-12";
640  smEncodings << "ISO8859-13";
641  smEncodings << "ISO8859-14";
642  smEncodings << "ISO8859-15";
643  smEncodings << "IBM 850";
644  smEncodings << "IBM 866";
645  smEncodings << "CP874";
646  smEncodings << "CP1250";
647  smEncodings << "CP1251";
648  smEncodings << "CP1252";
649  smEncodings << "CP1253";
650  smEncodings << "CP1254";
651  smEncodings << "CP1255";
652  smEncodings << "CP1256";
653  smEncodings << "CP1257";
654  smEncodings << "CP1258";
655  smEncodings << "Apple Roman";
656  smEncodings << "TIS-620";
657  smEncodings << "System";
658 #endif
659  }
660 
661  // Do case-insensitive sorting of encodings
662  std::sort( sEncodings.begin(), sEncodings.end(), _compareEncodings );
663 
664  return sEncodings;
665 }
666 
668 {
669  mErrors.clear();
670 }
671 
673 {
674  return !mErrors.isEmpty();
675 }
676 
677 QStringList QgsVectorDataProvider::errors() const
678 {
679  return mErrors;
680 }
681 
683 {
684  return false;
685 }
686 
688 {
689  return false;
690 }
691 
692 void QgsVectorDataProvider::pushError( const QString &msg ) const
693 {
694  QgsDebugMsg( msg );
695  mErrors << msg;
696  emit raiseError( msg );
697 }
698 
699 QSet<QgsMapLayerDependency> QgsVectorDataProvider::dependencies() const
700 {
701  return QSet<QgsMapLayerDependency>();
702 }
703 
705 {
706  if ( geom.isNull() )
707  {
708  return QgsGeometry();
709  }
710 
711  QgsAbstractGeometry *geometry = geom.geometry();
712  if ( !geometry )
713  {
714  return QgsGeometry();
715  }
716 
717  QgsWkbTypes::Type providerGeomType = wkbType();
718 
719  //geom is already in the provider geometry type
720  if ( geometry->wkbType() == providerGeomType )
721  {
722  return QgsGeometry();
723  }
724 
725  QgsAbstractGeometry *outputGeom = nullptr;
726 
727  //convert compoundcurve to circularstring (possible if compoundcurve consists of one circular string)
729  {
730  QgsCompoundCurve *compoundCurve = static_cast<QgsCompoundCurve *>( geometry );
731  if ( compoundCurve )
732  {
733  if ( compoundCurve->nCurves() == 1 )
734  {
735  const QgsCircularString *circularString = dynamic_cast<const QgsCircularString *>( compoundCurve->curveAt( 0 ) );
736  if ( circularString )
737  {
738  outputGeom = circularString->clone();
739  }
740  }
741  }
742  }
743 
744  //convert to multitype if necessary
745  if ( QgsWkbTypes::isMultiType( providerGeomType ) && !QgsWkbTypes::isMultiType( geometry->wkbType() ) )
746  {
747  outputGeom = QgsGeometryFactory::geomFromWkbType( providerGeomType );
748  QgsGeometryCollection *geomCollection = dynamic_cast<QgsGeometryCollection *>( outputGeom );
749  if ( geomCollection )
750  {
751  geomCollection->addGeometry( geometry->clone() );
752  }
753  }
754 
755  //convert to curved type if necessary
756  if ( !QgsWkbTypes::isCurvedType( geometry->wkbType() ) && QgsWkbTypes::isCurvedType( providerGeomType ) )
757  {
758  QgsAbstractGeometry *curveGeom = outputGeom ? outputGeom->toCurveType() : geometry->toCurveType();
759  if ( curveGeom )
760  {
761  delete outputGeom;
762  outputGeom = curveGeom;
763  }
764  }
765 
766  //convert to linear type from curved type
767  if ( QgsWkbTypes::isCurvedType( geometry->wkbType() ) && !QgsWkbTypes::isCurvedType( providerGeomType ) )
768  {
769  QgsAbstractGeometry *segmentizedGeom = nullptr;
770  segmentizedGeom = outputGeom ? outputGeom->segmentize() : geometry->segmentize();
771  if ( segmentizedGeom )
772  {
773  delete outputGeom;
774  outputGeom = segmentizedGeom;
775  }
776  }
777 
778  //set z/m types
779  if ( QgsWkbTypes::hasZ( providerGeomType ) )
780  {
781  if ( !outputGeom )
782  {
783  outputGeom = geometry->clone();
784  }
785  outputGeom->addZValue();
786  }
787  if ( QgsWkbTypes::hasM( providerGeomType ) )
788  {
789  if ( !outputGeom )
790  {
791  outputGeom = geometry->clone();
792  }
793  outputGeom->addMValue();
794  }
795 
796  if ( outputGeom )
797  {
798  return QgsGeometry( outputGeom );
799  }
800  return QgsGeometry();
801 }
802 
803 void QgsVectorDataProvider::setNativeTypes( const QList<NativeType> &nativeTypes )
804 {
805  mNativeTypes = nativeTypes;
806 }
807 
809 {
810  return mEncoding;
811 }
812 
813 QStringList QgsVectorDataProvider::sEncodings;
814 
815 QList<QgsRelation> QgsVectorDataProvider::discoverRelations( const QgsVectorLayer *, const QList<QgsVectorLayer *> & ) const
816 {
817  return QList<QgsRelation>();
818 }
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.
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
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
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.
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...
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
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
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.
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 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:94
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
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.
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.