Branch data Line data Source code
1 : : /***************************************************************************
2 : : qgsvectordataprovider.h - DataProvider Interface for vector layers
3 : : --------------------------------------
4 : : Date : 23-Sep-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 : : #ifndef QGSVECTORDATAPROVIDER_H
16 : : #define QGSVECTORDATAPROVIDER_H
17 : :
18 : : class QTextCodec;
19 : :
20 : : #include "qgis_core.h"
21 : : #include <QList>
22 : : #include <QSet>
23 : : #include <QMap>
24 : : #include <QHash>
25 : :
26 : : //QGIS Includes
27 : : #include "qgis_sip.h"
28 : : #include "qgsdataprovider.h"
29 : : #include "qgsfeature.h"
30 : : #include "qgsaggregatecalculator.h"
31 : : #include "qgsmaplayerdependency.h"
32 : : #include "qgsrelation.h"
33 : : #include "qgsfeaturesink.h"
34 : : #include "qgsfeaturesource.h"
35 : : #include "qgsfeaturerequest.h"
36 : : #include "qgsvectordataprovidertemporalcapabilities.h"
37 : :
38 : : typedef QList<int> QgsAttributeList SIP_SKIP;
39 : : typedef QSet<int> QgsAttributeIds SIP_SKIP;
40 : : typedef QHash<int, QString> QgsAttrPalIndexNameHash;
41 : :
42 : : class QgsFeatureIterator;
43 : : class QgsTransaction;
44 : : class QgsFeedback;
45 : : class QgsFeatureRenderer;
46 : : class QgsAbstractVectorLayerLabeling;
47 : :
48 : :
49 : : /**
50 : : * \ingroup core
51 : : * \brief This is the base class for vector data providers.
52 : : *
53 : : * Data providers abstract the retrieval and writing (where supported)
54 : : * of feature and attribute information from a spatial datasource.
55 : : *
56 : : *
57 : : */
58 : 0 : class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeatureSink, public QgsFeatureSource
59 : : {
60 : 0 : Q_OBJECT
61 : :
62 : : friend class QgsTransaction;
63 : : friend class QgsVectorLayerEditBuffer;
64 : :
65 : : public:
66 : :
67 : : // If you add to this, please also add to capabilitiesString()
68 : :
69 : : /**
70 : : * enumeration with capabilities that providers might implement
71 : : */
72 : : enum Capability
73 : : {
74 : : NoCapabilities = 0, //!< Provider has no capabilities
75 : : AddFeatures = 1, //!< Allows adding features
76 : : DeleteFeatures = 1 << 1, //!< Allows deletion of features
77 : : ChangeAttributeValues = 1 << 2, //!< Allows modification of attribute values
78 : : AddAttributes = 1 << 3, //!< Allows addition of new attributes (fields)
79 : : DeleteAttributes = 1 << 4, //!< Allows deletion of attributes (fields)
80 : : CreateSpatialIndex = 1 << 6, //!< Allows creation of spatial index
81 : : SelectAtId = 1 << 7, //!< Fast access to features using their ID
82 : : ChangeGeometries = 1 << 8, //!< Allows modifications of geometries
83 : : SelectEncoding = 1 << 13, //!< Allows user to select encoding
84 : : CreateAttributeIndex = 1 << 12, //!< Can create indexes on provider's fields
85 : : SimplifyGeometries = 1 << 14, //!< Supports simplification of geometries on provider side according to a distance tolerance
86 : : SimplifyGeometriesWithTopologicalValidation = 1 << 15, //!< Supports topological simplification of geometries on provider side according to a distance tolerance
87 : : TransactionSupport = 1 << 16, //!< Supports transactions
88 : : CircularGeometries = 1 << 17, //!< Supports circular geometry types (circularstring, compoundcurve, curvepolygon)
89 : : ChangeFeatures = 1 << 18, //!< Supports joint updates for attributes and geometry. Providers supporting this should still define ChangeGeometries | ChangeAttributeValues.
90 : : RenameAttributes = 1 << 19, //!< Supports renaming attributes (fields). Since QGIS 2.16
91 : : FastTruncate = 1 << 20, //!< Supports fast truncation of the layer (removing all features). Since QGIS 3.0
92 : : ReadLayerMetadata = 1 << 21, //!< Provider can read layer metadata from data store. Since QGIS 3.0. See QgsDataProvider::layerMetadata()
93 : : WriteLayerMetadata = 1 << 22, //!< Provider can write layer metadata to the data store. Since QGIS 3.0. See QgsDataProvider::writeLayerMetadata()
94 : : CancelSupport = 1 << 23, //!< Supports interruption of pending queries from a separated thread. Since QGIS 3.2
95 : : CreateRenderer = 1 << 24, //!< Provider can create feature renderers using backend-specific formatting information. Since QGIS 3.2. See QgsVectorDataProvider::createRenderer().
96 : : CreateLabeling = 1 << 25, //!< Provider can set labeling settings using backend-specific formatting information. Since QGIS 3.6. See QgsVectorDataProvider::createLabeling().
97 : : ReloadData = 1 << 26, //!< Provider is able to force reload data
98 : : FeatureSymbology = 1 << 27, //!< Provider is able retrieve embedded symbology associated with individual features. Since QGIS 3.20.
99 : : };
100 : :
101 : : Q_DECLARE_FLAGS( Capabilities, Capability )
102 : :
103 : : //! Bitmask of all provider's editing capabilities
104 : : static const int EditingCapabilities = AddFeatures | DeleteFeatures |
105 : : ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes |
106 : : RenameAttributes;
107 : :
108 : : /**
109 : : * Enumeration of feature count states
110 : : */
111 : : enum FeatureCountState
112 : : {
113 : : //! Feature count not yet computed
114 : : Uncounted = -2,
115 : : //! Provider returned an unknown feature count
116 : : UnknownCount = -1,
117 : : };
118 : :
119 : : /**
120 : : * Constructor for a vector data provider.
121 : : *
122 : : * The \a uri argument specifies the uniform resource locator (URI) for the associated dataset.
123 : : *
124 : : * Additional creation options are specified within the \a options value and since QGIS 3.16 creation flags are specified within the \a flags value.
125 : : */
126 : : QgsVectorDataProvider( const QString &uri = QString(),
127 : : const QgsDataProvider::ProviderOptions &providerOptions = QgsDataProvider::ProviderOptions(),
128 : : QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
129 : :
130 : : /**
131 : : * Returns feature source object that can be used for querying provider's data. The returned feature source
132 : : * is independent from provider - any changes to provider's state (e.g. change of subset string) will not be
133 : : * reflected in the feature source, therefore it can be safely used for processing in background without
134 : : * having to care about possible changes within provider that may happen concurrently. Also, even in the case
135 : : * of provider being deleted, any feature source obtained from the provider will be kept alive and working
136 : : * (they are independent and owned by the caller).
137 : : *
138 : : * Sometimes there are cases when some data needs to be shared between vector data provider and its feature source.
139 : : * In such cases, the implementation must ensure that the data is not susceptible to run condition. For example,
140 : : * if it is possible that both feature source and provider may need reading/writing to some shared data at the
141 : : * same time, some synchronization mechanisms must be used (e.g. mutexes) to prevent data corruption.
142 : : *
143 : : * \returns new instance of QgsAbstractFeatureSource (caller is responsible for deleting it)
144 : : * \since QGIS 2.4
145 : : */
146 : : virtual QgsAbstractFeatureSource *featureSource() const = 0 SIP_FACTORY;
147 : :
148 : : /**
149 : : * Returns the permanent storage type for this layer as a friendly name.
150 : : */
151 : : virtual QString storageType() const;
152 : :
153 : : /**
154 : : * Query the provider for features specified in request.
155 : : * \param request feature request describing parameters of features to return
156 : : * \returns iterator for matching features from provider
157 : : */
158 : : QgsFeatureIterator getFeatures( const QgsFeatureRequest &request = QgsFeatureRequest() ) const override = 0;
159 : :
160 : : /**
161 : : * Returns the geometry type which is returned by this layer
162 : : */
163 : : QgsWkbTypes::Type wkbType() const override = 0;
164 : :
165 : : /**
166 : : * Number of features in the layer
167 : : * \returns long containing number of features
168 : : */
169 : : long featureCount() const override = 0;
170 : :
171 : : /**
172 : : * Returns TRUE if the layer does not contain any feature.
173 : : *
174 : : * \since QGIS 3.4
175 : : */
176 : : virtual bool empty() const;
177 : :
178 : : /**
179 : : * Will always return FeatureAvailability::FeaturesAvailable or
180 : : * FeatureAvailability::NoFeaturesAvailable.
181 : : *
182 : : * Calls empty() internally. Providers should override empty()
183 : : * instead if they provide an optimized version of this call.
184 : : *
185 : : * \see empty()
186 : : * \since QGIS 3.4
187 : : */
188 : : QgsFeatureSource::FeatureAvailability hasFeatures() const override;
189 : :
190 : : /**
191 : : * Returns the fields associated with this data provider.
192 : : */
193 : : QgsFields fields() const override = 0;
194 : :
195 : : QgsCoordinateReferenceSystem sourceCrs() const override;
196 : : QgsRectangle sourceExtent() const override;
197 : : QString sourceName() const override { return QString(); }
198 : :
199 : : /**
200 : : * Returns a short comment for the data that this provider is
201 : : * providing access to (e.g. the comment for postgres table).
202 : : */
203 : : virtual QString dataComment() const override;
204 : :
205 : : /**
206 : : * Returns the minimum value of an attribute
207 : : * \param index the index of the attribute
208 : : *
209 : : * Default implementation walks all numeric attributes and caches minimal
210 : : * and maximal values. If provider has facilities to retrieve minimal
211 : : * value directly, override this function.
212 : : */
213 : : QVariant minimumValue( int index ) const override;
214 : :
215 : : /**
216 : : * Returns the maximum value of an attribute
217 : : * \param index the index of the attribute
218 : : *
219 : : * Default implementation walks all numeric attributes and caches minimal
220 : : * and maximal values. If provider has facilities to retrieve maximal
221 : : * value directly, override this function.
222 : : */
223 : : QVariant maximumValue( int index ) const override;
224 : :
225 : : /**
226 : : * Returns unique string values of an attribute which contain a specified subset string. Subset
227 : : * matching is done in a case-insensitive manner.
228 : : * \param index the index of the attribute
229 : : * \param substring substring to match (case insensitive)
230 : : * \param limit maxmum number of the values to return, or -1 to return all unique values
231 : : * \param feedback optional feedback object for canceling request
232 : : * \returns list of unique strings containing substring
233 : : */
234 : : virtual QStringList uniqueStringsMatching( int index, const QString &substring, int limit = -1,
235 : : QgsFeedback *feedback = nullptr ) const;
236 : :
237 : : /**
238 : : * Calculates an aggregated value from the layer's features. The base implementation does nothing,
239 : : * but subclasses can override this method to handoff calculation of aggregates to the provider.
240 : : * \param aggregate aggregate to calculate
241 : : * \param index the index of the attribute to calculate aggregate over
242 : : * \param parameters parameters controlling aggregate calculation
243 : : * \param context expression context for filter
244 : : * \param ok will be set to TRUE if calculation was successfully performed by the data provider
245 : : * \param fids list of fids to filter, otherwise will use all fids
246 : : * \returns calculated aggregate value
247 : : * \since QGIS 2.16
248 : : */
249 : : virtual QVariant aggregate( QgsAggregateCalculator::Aggregate aggregate,
250 : : int index,
251 : : const QgsAggregateCalculator::AggregateParameters ¶meters,
252 : : QgsExpressionContext *context,
253 : : bool &ok,
254 : : QgsFeatureIds *fids = nullptr ) const;
255 : :
256 : : /**
257 : : * Returns the possible enum values of an attribute. Returns an empty stringlist if a provider does not support enum types
258 : : * or if the given attribute is not an enum type.
259 : : * \param index the index of the attribute
260 : : * \param enumList reference to the list to fill
261 : : */
262 : : virtual void enumValues( int index, QStringList &enumList SIP_OUT ) const { Q_UNUSED( index ) enumList.clear(); }
263 : :
264 : : bool addFeatures( QgsFeatureList &flist SIP_INOUT, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
265 : : QString lastError() const override;
266 : :
267 : : /**
268 : : * Deletes one or more features from the provider. This requires the DeleteFeatures capability.
269 : : * \param id list containing feature ids to delete
270 : : * \returns TRUE in case of success and FALSE in case of failure
271 : : * \see truncate()
272 : : */
273 : : virtual bool deleteFeatures( const QgsFeatureIds &id );
274 : :
275 : : /**
276 : : * Removes all features from the layer. This requires either the FastTruncate or DeleteFeatures capability.
277 : : * Providers with the FastTruncate capability will use an optimised method to truncate the layer.
278 : : * \returns TRUE in case of success and FALSE in case of failure.
279 : : * \see deleteFeatures()
280 : : * \since QGIS 3.0
281 : : */
282 : : virtual bool truncate();
283 : :
284 : : /**
285 : : * Cancels the current reloading of data.
286 : : * \returns TRUE if the reloading has been correctly interrupted, FALSE otherwise
287 : : * \see reloadData()
288 : : * \since QGIS 3.2
289 : : */
290 : : virtual bool cancelReload();
291 : :
292 : : /**
293 : : * Adds new \a attributes to the provider. Returns TRUE in case of success and FALSE in case of failure.
294 : : * If attributes are added using this method then QgsVectorLayer::updateFields() must be called
295 : : * manually to ensure that the layer's field are correctly reported.
296 : : */
297 : : virtual bool addAttributes( const QList<QgsField> &attributes );
298 : :
299 : : /**
300 : : * Deletes existing \a attributes from the provider.
301 : : * If attributes are deleted using this method then QgsVectorLayer::updateFields() must be called
302 : : * manually to ensure that the layer's field are correctly reported.
303 : : * \param attributes a set containing indices of attributes
304 : : * \returns TRUE in case of success and FALSE in case of failure
305 : : */
306 : : virtual bool deleteAttributes( const QgsAttributeIds &attributes );
307 : :
308 : : /**
309 : : * Renames existing attributes.
310 : : * If attributes are renamed using this method then QgsVectorLayer::updateFields() must be called
311 : : * manually to ensure that the layer's field are correctly reported.
312 : : * \param renamedAttributes map of attribute index to new attribute name
313 : : * \returns TRUE in case of success and FALSE in case of failure
314 : : * \since QGIS 2.16
315 : : */
316 : : virtual bool renameAttributes( const QgsFieldNameMap &renamedAttributes );
317 : :
318 : : /**
319 : : * Changes attribute values of existing features. This should
320 : : * succeed if the provider reports the ChangeAttributeValues capability.
321 : : * The method returns FALSE if the provider does not have ChangeAttributeValues
322 : : * capability or if any of the changes could not be successfully applied.
323 : : * \param attr_map a map containing changed attributes
324 : : * \returns TRUE in case of success and FALSE in case of failure
325 : : */
326 : : virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
327 : :
328 : : /**
329 : : * Changes attribute values and geometries of existing features. This should
330 : : * succeed if the provider reports both the ChangeAttributeValues and
331 : : * ChangeGeometries capabilities. Providers which report the ChangeFeatures
332 : : * capability implement an optimised version of this method.
333 : : * \param attr_map a map containing changed attributes
334 : : * \param geometry_map A QgsGeometryMap whose index contains the feature IDs
335 : : * that will have their geometries changed.
336 : : * The second map parameter being the new geometries themselves
337 : : * \returns TRUE in case of success and FALSE in case of failure
338 : : */
339 : : virtual bool changeFeatures( const QgsChangedAttributesMap &attr_map,
340 : : const QgsGeometryMap &geometry_map );
341 : :
342 : : /**
343 : : * Returns any literal default values which are present at the provider for a specified
344 : : * field index. Important - this should ONLY be called when creating an attribute to insert
345 : : * directly into the database. Do not call this method for non-feature creation or modification,
346 : : * e.g., when validating an attribute or to compare it against an existing value, as calling it
347 : : * can cause changes to the underlying data source (e.g., Postgres provider where the default value
348 : : * is calculated as a result of a sequence). It is recommended that you instead use the methods
349 : : * in QgsVectorLayerUtils such as QgsVectorLayerUtils::createFeature()
350 : : * so that default value handling and validation is automatically carried out.
351 : : * \see defaultValueClause()
352 : : */
353 : : virtual QVariant defaultValue( int fieldIndex ) const;
354 : :
355 : : /**
356 : : * Returns any default value clauses which are present at the provider for a specified
357 : : * field index. These clauses are usually SQL fragments which must be evaluated by the
358 : : * provider, e.g., sequence values.
359 : : * \see defaultValue()
360 : : * \since QGIS 3.0
361 : : */
362 : : virtual QString defaultValueClause( int fieldIndex ) const;
363 : :
364 : : /**
365 : : * Returns any constraints which are present at the provider for a specified
366 : : * field index.
367 : : * \see skipConstraintCheck()
368 : : * \since QGIS 3.0
369 : : */
370 : : QgsFieldConstraints::Constraints fieldConstraints( int fieldIndex ) const;
371 : :
372 : : /**
373 : : * Returns TRUE if a constraint check should be skipped for a specified field (e.g., if
374 : : * the value returned by defaultValue() is trusted implicitly. An optional attribute value can be
375 : : * passed which can help refine the skip constraint check.
376 : : * \see fieldConstraints()
377 : : * \since QGIS 3.0
378 : : */
379 : : virtual bool skipConstraintCheck( int fieldIndex, QgsFieldConstraints::Constraint constraint, const QVariant &value = QVariant() ) const;
380 : :
381 : : /**
382 : : * Changes geometries of existing features
383 : : * \param geometry_map A QgsGeometryMap whose index contains the feature IDs
384 : : * that will have their geometries changed.
385 : : * The second map parameter being the new geometries themselves
386 : : * \returns TRUE in case of success and FALSE in case of failure
387 : : */
388 : : virtual bool changeGeometryValues( const QgsGeometryMap &geometry_map );
389 : :
390 : : /**
391 : : * Creates a spatial index on the datasource (if supported by the provider type).
392 : : * \returns TRUE in case of success
393 : : */
394 : : virtual bool createSpatialIndex();
395 : :
396 : : //! Create an attribute index on the datasource
397 : : virtual bool createAttributeIndex( int field );
398 : :
399 : : /**
400 : : * Returns flags containing the supported capabilities
401 : : * \note, some capabilities may change depending on whether
402 : : * a spatial filter is active on this provider, so it may
403 : : * be prudent to check this value per intended operation.
404 : : */
405 : : Q_INVOKABLE virtual QgsVectorDataProvider::Capabilities capabilities() const;
406 : :
407 : : /**
408 : : * Returns the above in friendly format.
409 : : */
410 : : QString capabilitiesString() const;
411 : :
412 : : /**
413 : : * Set encoding used for accessing data from layer.
414 : : *
415 : : * An empty encoding string indicates that the provider should automatically
416 : : * select the most appropriate encoding for the data source.
417 : : *
418 : : * \warning Support for setting the provider encoding depends on the underlying data
419 : : * provider. Check capabilities() for the QgsVectorDataProvider::SelectEncoding
420 : : * capability in order to determine if the provider supports this ability.
421 : : *
422 : : * \see encoding()
423 : : */
424 : : virtual void setEncoding( const QString &e );
425 : :
426 : : /**
427 : : * Returns the encoding which is used for accessing data.
428 : : *
429 : : * \see setEncoding()
430 : : */
431 : : QString encoding() const;
432 : :
433 : : /**
434 : : * Returns the index of a field name or -1 if the field does not exist
435 : : */
436 : : int fieldNameIndex( const QString &fieldName ) const;
437 : :
438 : : /**
439 : : * Returns a map where the key is the name of the field and the value is its index
440 : : */
441 : : QMap<QString, int> fieldNameMap() const;
442 : :
443 : : /**
444 : : * Returns list of indexes to fetch all attributes in nextFeature()
445 : : */
446 : : virtual QgsAttributeList attributeIndexes() const;
447 : :
448 : : /**
449 : : * Returns list of indexes of fields that make up the primary key
450 : : */
451 : : virtual QgsAttributeList pkAttributeIndexes() const;
452 : :
453 : : /**
454 : : * Returns list of indexes to names for QgsPalLabeling fix
455 : : */
456 : : virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const;
457 : :
458 : : /**
459 : : * check if provider supports type of field
460 : : */
461 : : bool supportedType( const QgsField &field ) const;
462 : :
463 : 604 : struct NativeType
464 : : {
465 : 604 : NativeType( const QString &typeDesc, const QString &typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0, QVariant::Type subType = QVariant::Invalid )
466 : 604 : : mTypeDesc( typeDesc )
467 : 604 : , mTypeName( typeName )
468 : 604 : , mType( type )
469 : 604 : , mMinLen( minLen )
470 : 604 : , mMaxLen( maxLen )
471 : 604 : , mMinPrec( minPrec )
472 : 604 : , mMaxPrec( maxPrec )
473 : 604 : , mSubType( subType )
474 : 604 : {}
475 : :
476 : : QString mTypeDesc;
477 : : QString mTypeName;
478 : : QVariant::Type mType;
479 : : int mMinLen;
480 : : int mMaxLen;
481 : : int mMinPrec;
482 : : int mMaxPrec;
483 : : QVariant::Type mSubType;
484 : : };
485 : :
486 : : /**
487 : : * Returns the names of the supported types
488 : : */
489 : : QList< QgsVectorDataProvider::NativeType > nativeTypes() const;
490 : :
491 : : /**
492 : : * Returns TRUE if the provider is strict about the type of inserted features
493 : : * (e.g. no multipolygon in a polygon layer)
494 : : */
495 : : virtual bool doesStrictFeatureTypeCheck() const { return true; }
496 : :
497 : : //! Returns a list of available encodings
498 : : static QStringList availableEncodings();
499 : :
500 : : /**
501 : : * Provider has errors to report
502 : : */
503 : : bool hasErrors() const;
504 : :
505 : : /**
506 : : * Clear recorded errors
507 : : */
508 : : void clearErrors();
509 : :
510 : : /**
511 : : * Gets recorded errors
512 : : */
513 : : QStringList errors() const;
514 : :
515 : : /**
516 : : * It returns FALSE by default.
517 : : * Must be implemented by providers that support saving and loading styles to db returning TRUE
518 : : */
519 : : virtual bool isSaveAndLoadStyleToDatabaseSupported() const;
520 : :
521 : : /**
522 : : * It returns FALSE by default.
523 : : * Must be implemented by providers that support delete styles from db returning TRUE
524 : : */
525 : : virtual bool isDeleteStyleFromDatabaseSupported() const;
526 : :
527 : : /**
528 : : * Creates a new vector layer feature renderer, using provider backend specific information.
529 : : *
530 : : * The \a configuration map can be used to pass provider-specific configuration maps to the provider to
531 : : * allow customization of the returned renderer. Support and format of \a configuration varies by provider.
532 : : *
533 : : * When called with an empty \a configuration map the provider's default renderer will be returned.
534 : : *
535 : : * This method returns a new renderer and the caller takes ownership of the returned object.
536 : : *
537 : : * Only providers which report the CreateRenderer capability will return a feature renderer. Other
538 : : * providers will return NULLPTR.
539 : : *
540 : : * \since QGIS 3.2
541 : : */
542 : : virtual QgsFeatureRenderer *createRenderer( const QVariantMap &configuration = QVariantMap() ) const SIP_FACTORY;
543 : :
544 : : /**
545 : : * Creates labeling settings, using provider backend specific information.
546 : : *
547 : : * The \a configuration map can be used to pass provider-specific configuration maps to the provider to
548 : : * allow customization of the returned labeling object. Support and format of \a configuration varies by provider.
549 : : *
550 : : * When called with an empty \a configuration map the provider's default labeling settings will be returned.
551 : : *
552 : : * This method returns a new labeling settings and the caller takes ownership of the returned object.
553 : : *
554 : : * Only providers which report the CreateLabeling capability will return labeling settings. Other
555 : : * providers will return NULLPTR.
556 : : *
557 : : * \since QGIS 3.6
558 : : */
559 : : virtual QgsAbstractVectorLayerLabeling *createLabeling( const QVariantMap &configuration = QVariantMap() ) const SIP_FACTORY;
560 : :
561 : : static QVariant convertValue( QVariant::Type type, const QString &value );
562 : :
563 : : /**
564 : : * Returns the transaction this data provider is included in, if any.
565 : : */
566 : : virtual QgsTransaction *transaction() const;
567 : :
568 : : /**
569 : : * \deprecated QGIS 3.12 - will be removed in QGIS 4.0 - use reloadData instead
570 : : */
571 : : Q_DECL_DEPRECATED virtual void forceReload() SIP_DEPRECATED { reloadData(); }
572 : :
573 : : /**
574 : : * Gets the list of layer ids on which this layer depends. This in particular determines the order of layer loading.
575 : : */
576 : : virtual QSet<QgsMapLayerDependency> dependencies() const;
577 : :
578 : : /**
579 : : * Discover the available relations with the given layers.
580 : : * \param self the layer using this data provider.
581 : : * \param layers the other layers.
582 : : * \returns the list of N-1 relations from this provider.
583 : : * \since QGIS 3.0
584 : : */
585 : : virtual QList<QgsRelation> discoverRelations( const QgsVectorLayer *self, const QList<QgsVectorLayer *> &layers ) const;
586 : :
587 : : /**
588 : : * Gets metadata, dependent on the provider type, that will be display in the metadata tab of the layer properties.
589 : : * \returns The provider metadata
590 : : */
591 : : virtual QVariantMap metadata() const { return QVariantMap(); }
592 : :
593 : : /**
594 : : * Gets the translated metadata key.
595 : : * \param mdKey The metadata key
596 : : * \returns The translated metadata value
597 : : */
598 : : virtual QString translateMetadataKey( const QString &mdKey ) const { return mdKey; }
599 : :
600 : : /**
601 : : * Gets the translated metadata value.
602 : : * \param mdKey The metadata key
603 : : * \param value The metadata value
604 : : * \returns The translated metadata value
605 : : */
606 : : virtual QString translateMetadataValue( const QString &mdKey, const QVariant &value ) const { Q_UNUSED( mdKey ) return value.toString(); }
607 : :
608 : : /**
609 : : * Returns TRUE if the data source has metadata, FALSE otherwise.
610 : : *
611 : : * \returns TRUE if data source has metadata, FALSE otherwise.
612 : : *
613 : : * \since QGIS 3.0
614 : : */
615 : : virtual bool hasMetadata() const { return true; }
616 : :
617 : : /**
618 : : * Handles any post-clone operations required after this vector data provider was cloned
619 : : * from the \a source provider.
620 : : *
621 : : * \since QGIS 3.8.1
622 : : */
623 : : virtual void handlePostCloneOperations( QgsVectorDataProvider *source );
624 : :
625 : : QgsVectorDataProviderTemporalCapabilities *temporalCapabilities() override;
626 : : const QgsVectorDataProviderTemporalCapabilities *temporalCapabilities() const override SIP_SKIP;
627 : :
628 : : signals:
629 : :
630 : : /**
631 : : * Signals an error in this provider
632 : : *
633 : : * \since QGIS 3.0
634 : : */
635 : : void raiseError( const QString &msg ) const;
636 : :
637 : : protected:
638 : :
639 : : /**
640 : : * Invalidates the min/max cache. This will force the provider to recalculate the
641 : : * cache the next time it is requested.
642 : : */
643 : : void clearMinMaxCache();
644 : :
645 : : /**
646 : : * Populates the cache of minimum and maximum attribute values.
647 : : */
648 : : void fillMinMaxCache() const;
649 : :
650 : : /**
651 : : * Push a notification about errors that happened in this providers scope.
652 : : * Errors should be translated strings that require the users immediate
653 : : * attention.
654 : : *
655 : : * For general debug information use QgsMessageLog::logMessage() instead.
656 : : *
657 : : * \since QGIS 3.0
658 : : */
659 : : void pushError( const QString &msg ) const;
660 : :
661 : : /**
662 : : * Converts the geometry to the provider type if possible / necessary
663 : : * \returns the converted geometry or NULLPTR if no conversion was necessary or possible
664 : : */
665 : : QgsGeometry convertToProviderType( const QgsGeometry &geom ) const;
666 : :
667 : : /**
668 : : * Set the list of native types supported by this provider.
669 : : * Usually done in the constructor.
670 : : *
671 : : * \since QGIS 3.0
672 : : */
673 : : void setNativeTypes( const QList<QgsVectorDataProvider::NativeType> &nativeTypes );
674 : :
675 : : /**
676 : : * Gets this providers encoding
677 : : *
678 : : * \since QGIS 3.0
679 : : */
680 : : QTextCodec *textEncoding() const;
681 : :
682 : : private:
683 : : mutable bool mCacheMinMaxDirty = true;
684 : : mutable QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
685 : :
686 : : //! Encoding
687 : : QTextCodec *mEncoding = nullptr;
688 : :
689 : : //! List of attribute indices to fetch with nextFeature calls
690 : : QgsAttributeList mAttributesToFetch;
691 : :
692 : : //! The names of the providers native types
693 : : QList< NativeType > mNativeTypes;
694 : :
695 : : //! List of errors
696 : : mutable QStringList mErrors;
697 : :
698 : : std::unique_ptr< QgsVectorDataProviderTemporalCapabilities > mTemporalCapabilities;
699 : :
700 : : static QStringList sEncodings;
701 : :
702 : : /**
703 : : * Includes this data provider in the specified transaction. Ownership of transaction is not transferred.
704 : : */
705 : : virtual void setTransaction( QgsTransaction * /*transaction*/ ) {}
706 : : };
707 : :
708 : 60 : Q_DECLARE_OPERATORS_FOR_FLAGS( QgsVectorDataProvider::Capabilities )
709 : :
710 : : #endif
|