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