QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
qgsdataprovider.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsdataprovider.h - DataProvider Interface class
3 --------------------------------------
4 Date : 09-Sep-2003
5 Copyright : (C) 2003 by Gary E.Sherman
6 email : sherman at mrcc.com
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#ifndef QQGSDATAPROVIDER_H
17#define QQGSDATAPROVIDER_H
18
19#include "qgis_core.h"
20#include <QDateTime>
21#include <QObject>
22#include <QString>
23#include <QStringList>
24#include <QMutex>
25
26#include "qgsdatasourceuri.h"
28#include "qgslayermetadata.h"
29#include "qgserror.h"
30
31class QgsRectangle;
35
36
41class CORE_EXPORT QgsDataProvider : public QObject
42{
43
44#ifdef SIP_RUN
46 if ( qobject_cast<QgsVectorDataProvider *>( sipCpp ) )
47 {
48 sipType = sipType_QgsVectorDataProvider;
49 }
50 else if ( qobject_cast<QgsRasterDataProvider *>( sipCpp ) )
51 {
52 sipType = sipType_QgsRasterDataProvider;
53 }
54 else if ( qobject_cast<QgsMeshDataProvider *>( sipCpp ) )
55 {
56 sipType = sipType_QgsMeshDataProvider;
57 }
58 else if ( qobject_cast<QgsPointCloudDataProvider *>( sipCpp ) )
59 {
60 sipType = sipType_QgsPointCloudDataProvider;
61 }
62 else
63 {
64 sipType = 0;
65 }
67#endif
68 Q_OBJECT
69
70 public:
71
72 // TODO QGIS 4: (re)move DataCapability as this enum is really meant for data items rather than data providers
73
78 {
79 NoDataCapabilities = 0,
80 File = 1,
81 Dir = 1 << 1,
82 Database = 1 << 2,
83 Net = 1 << 3 // Internet source
84 };
85 Q_DECLARE_FLAGS( DataCapabilities, DataCapability )
86
87
95 {
97 CustomData = 3000
98 };
99
100
109 {
110
115
116 };
117
123 {
124 FlagTrustDataSource = 1 << 0,
125 SkipFeatureCount = 1 << 1,
126 FlagLoadDefaultStyle = 1 << 2,
127 SkipGetExtent = 1 << 3,
128 SkipFullScan = 1 << 4,
129 ForceReadOnly = 1 << 5,
130 SkipCredentialsRequest = 1 << 6,
131 };
132 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
133
134
139 QgsDataProvider( const QString &uri = QString(),
141 QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
142
149
155 virtual void setDataSourceUri( const QString &uri )
156 {
157 mDataSourceURI = uri;
158 }
159
169 virtual QString dataSourceUri( bool expandAuthConfig = false ) const
170 {
171 if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
172 {
173 const QgsDataSourceUri uri( mDataSourceURI );
174 return uri.uri( expandAuthConfig );
175 }
176 else
177 {
178 return mDataSourceURI;
179 }
180 }
181
189 virtual QString dataComment() const { return QString(); };
190
191
197 void setUri( const QgsDataSourceUri &uri )
198 {
199 mDataSourceURI = uri.uri( true );
200 }
201
208 {
209 return QgsDataSourceUri( mDataSourceURI );
210 }
211
217 virtual Qgis::DataProviderFlags flags() const;
218
226 virtual QgsDataProviderTemporalCapabilities *temporalCapabilities();
227
235 virtual const QgsDataProviderTemporalCapabilities *temporalCapabilities() const SIP_SKIP;
236
244 virtual QgsDataProviderElevationProperties *elevationProperties();
245
253 virtual const QgsDataProviderElevationProperties *elevationProperties() const SIP_SKIP;
254
259 virtual QgsRectangle extent() const = 0;
260
261
266 virtual bool isValid() const = 0;
267
271 virtual void updateExtents()
272 {
273 // NOP by default
274 }
275
276
283 virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
284 {
285 // NOP by default
286 Q_UNUSED( subset )
287 Q_UNUSED( updateFeatureCount )
288 return false;
289 }
290
291
295 virtual bool supportsSubsetString() const { return false; }
296
303 virtual QString subsetString() const
304 {
305 return QString();
306 }
307
308
317 virtual QStringList subLayers() const
318 {
319 return QStringList(); // Empty
320 }
321
329 virtual QStringList subLayerStyles() const
330 {
331 return QStringList(); // Empty
332 }
333
334
338 virtual uint subLayerCount() const
339 {
340 return 0;
341 }
342
343
349 virtual void setLayerOrder( const QStringList &layers )
350 {
351 //prevent unused var warnings
352 if ( layers.count() < 1 )
353 {
354 return;
355 }
356 // NOOP
357 }
358
359
363 virtual void setSubLayerVisibility( const QString &name, bool vis )
364 {
365 //prevent unused var warnings
366 if ( name.isEmpty() || !vis )
367 {
368 return;
369 }
370 // NOOP
371 }
372
373
389 virtual QString name() const = 0;
390
391
404 virtual QString description() const = 0;
405
406
417 virtual QString fileVectorFilters() const
418 {
419 return QString();
420 }
421
422
433 virtual QString fileRasterFilters() const
434 {
435 return QString();
436 }
437
438 // TODO QGIS 4 -> Make `reloadData()` non virtual. This should be implemented in `reloadProviderData()`.
439
447 virtual void reloadData();
448
450 virtual QDateTime timestamp() const { return mTimestamp; }
451
453 virtual QDateTime dataTimestamp() const { return QDateTime(); }
454
460 virtual QgsError error() const { return mError; }
461
466 virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ) }
467
490 virtual bool enterUpdateMode() { return true; }
491
509 virtual bool leaveUpdateMode() { return true; }
510
517 void setProviderProperty( ProviderProperty property, const QVariant &value );
518
525 void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
526
533 QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
534
541 QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
542
553 virtual void setListening( bool isListening );
554
555#ifndef SIP_RUN
556
563 {
565 double lastRenderingTimeMs = -1;
566
568 double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
569 };
570#endif
571
584 virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
585
594 virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
595
604 virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ) return false; }
605
613 QgsCoordinateTransformContext transformContext() const SIP_SKIP;
614
625 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) SIP_SKIP;
626
633 static QString sublayerSeparator();
634
635 signals:
636
643 void fullExtentCalculated();
644
657 void dataChanged();
658
666 void notify( const QString &msg );
667
668
669 protected:
670
674 QDateTime mTimestamp;
675
677 QgsError mError;
678
680 void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
681
683 void setError( const QgsError &error ) { mError = error;}
684
686 QgsDataProvider::ReadFlags mReadFlags = QgsDataProvider::ReadFlags();
687
688 private:
689
694 QString mDataSourceURI;
695
697
698 QMap< int, QVariant > mProviderProperties;
699
703 mutable QMutex mOptionsMutex;
704
709 virtual void reloadProviderData() {}
710
711 friend class TestQgsProject;
712};
713
714Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataProvider::ReadFlags )
715
716#endif
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Base class for handling elevation related properties for a data provider.
Base class for handling properties relating to a data provider's temporal capabilities.
Abstract base class for spatial data provider implementations.
virtual void invalidateConnections(const QString &connection)
Invalidate connections corresponding to specified name.
virtual bool leaveUpdateMode()
Leave update mode.
void setUri(const QgsDataSourceUri &uri)
Set the data source specification.
virtual void setLayerOrder(const QStringList &layers)
Reorder the list of layer names to be rendered by this provider (in order from bottom to top)
ReadFlag
Flags which control dataprovider construction.
virtual QString name() const =0
Returns a provider name.
void setError(const QgsError &error)
Sets error message.
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
virtual QString dataComment() const
Returns a short comment for the data that this provider is providing access to (e....
ProviderProperty
Properties are used to pass custom configuration options into data providers.
@ EvaluateDefaultValues
Evaluate default values on provider side when calling QgsVectorDataProvider::defaultValue( int index ...
virtual QString subsetString() const
Returns the subset definition string (typically sql) currently in use by the layer and used by the pr...
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider's source.
virtual void setDataSourceUri(const QString &uri)
Set the data source specification.
virtual QString fileRasterFilters() const
Returns raster file filter string.
virtual QgsError error() const
Gets current status error.
DataCapability
Used in browser model to understand which items for which providers should be populated.
virtual QDateTime dataTimestamp() const
Current time stamp of data source.
virtual bool supportsSubsetString() const
Returns true if the provider supports setting of subset strings.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
virtual QString description() const =0
Returns description.
QgsDataSourceUri uri() const
Gets the data source specification.
virtual QString fileVectorFilters() const
Returns vector file filter string.
virtual QStringList subLayerStyles() const
Sub-layer styles for each sub-layer handled by this provider, in order from bottom to top.
virtual bool setSubsetString(const QString &subset, bool updateFeatureCount=true)
Set the subset string used to create a subset of features in the layer.
virtual uint subLayerCount() const
Returns the number of layers for the current data source.
virtual QStringList subLayers() const
Sub-layers handled by this provider, in order from bottom to top.
virtual bool writeLayerMetadata(const QgsLayerMetadata &metadata)
Writes layer metadata to the underlying provider source.
virtual bool enterUpdateMode()
Enter update mode.
virtual void setSubLayerVisibility(const QString &name, bool vis)
Set the visibility of the given sublayer name.
Class for storing the component parts of a RDBMS data source URI (e.g.
QString uri(bool expandAuthConfig=true) const
Returns the complete URI as a string.
QgsErrorMessage represents single error message.
Definition: qgserror.h:33
QgsError is container for error messages (report).
Definition: qgserror.h:81
void append(const QString &message, const QString &tag)
Append new error message.
Definition: qgserror.cpp:39
A structured metadata store for a map layer.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_END
Definition: qgis_sip.h:203
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
Stores settings related to the context in which a preview job runs.
Setting options for creating vector data providers.
QgsCoordinateTransformContext transformContext
Coordinate transform context.