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