QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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"
22#include "qgsdatasourceuri.h"
23#include "qgserror.h"
24#include "qgslayermetadata.h"
25
26#include <QDateTime>
27#include <QMutex>
28#include <QObject>
29#include <QString>
30#include <QStringList>
31
32using namespace Qt::StringLiterals;
33
34class QgsRectangle;
37
38
43class CORE_EXPORT QgsDataProvider : public QObject
44{
45
46#ifdef SIP_RUN
48 if ( qobject_cast<QgsVectorDataProvider *>( sipCpp ) )
49 {
50 sipType = sipType_QgsVectorDataProvider;
51 }
52 else if ( qobject_cast<QgsRasterDataProvider *>( sipCpp ) )
53 {
54 sipType = sipType_QgsRasterDataProvider;
55 }
56 else if ( qobject_cast<QgsMeshDataProvider *>( sipCpp ) )
57 {
58 sipType = sipType_QgsMeshDataProvider;
59 }
60 else if ( qobject_cast<QgsPointCloudDataProvider *>( sipCpp ) )
61 {
62 sipType = sipType_QgsPointCloudDataProvider;
63 }
64 else
65 {
66 sipType = 0;
67 }
69#endif
70 Q_OBJECT
71
72 public:
73
86
103
109 QgsDataProvider( const QString &uri = QString(),
112
119
125 virtual void setDataSourceUri( const QString &uri )
126 {
127 mDataSourceURI = uri;
128 }
129
139 virtual QString dataSourceUri( bool expandAuthConfig = false ) const
140 {
141 if ( expandAuthConfig && mDataSourceURI.contains( "authcfg"_L1 ) )
142 {
143 const QgsDataSourceUri uri( mDataSourceURI );
144 return uri.uri( expandAuthConfig );
145 }
146 else
147 {
148 return mDataSourceURI;
149 }
150 }
151
159 virtual QString dataComment() const { return QString(); };
160
166 virtual QString htmlMetadata() const;
167
180 virtual QVariantMap metadata() const { return QVariantMap(); }
181
187 {
188 mDataSourceURI = uri.uri( true );
189 }
190
196 void setUri( const QString &uri )
197 {
198 mDataSourceURI = uri;
199 }
200
206 {
207 return QgsDataSourceUri( mDataSourceURI );
208 }
209
215 virtual Qgis::DataProviderFlags flags() const;
216
224 virtual QgsDataProviderTemporalCapabilities *temporalCapabilities();
225
233 virtual const QgsDataProviderTemporalCapabilities *temporalCapabilities() const SIP_SKIP;
234
242 virtual QgsDataProviderElevationProperties *elevationProperties();
243
251 virtual const QgsDataProviderElevationProperties *elevationProperties() const SIP_SKIP;
252
261 virtual QgsRectangle extent() const = 0;
262
273 virtual QgsBox3D extent3D() const
274 {
275 return extent().toBox3d( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN() );
276 }
277
282 virtual bool isValid() const = 0;
283
287 virtual void updateExtents()
288 {
289 // NOP by default
290 }
291
303 virtual QString subsetStringDialect() const;
304
316 virtual QString subsetStringHelpUrl() const;
317
333 virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true );
334
341 virtual bool supportsSubsetString() const;
342
359 virtual QString subsetString() const;
360
369 virtual QStringList subLayers() const
370 {
371 return QStringList(); // Empty
372 }
373
381 virtual QStringList subLayerStyles() const
382 {
383 return QStringList(); // Empty
384 }
385
386
390 virtual uint subLayerCount() const
391 {
392 return 0;
393 }
394
395
401 virtual void setLayerOrder( const QStringList &layers )
402 {
403 //prevent unused var warnings
404 if ( layers.count() < 1 )
405 {
406 return;
407 }
408 // NOOP
409 }
410
411
415 virtual void setSubLayerVisibility( const QString &name, bool vis )
416 {
417 //prevent unused var warnings
418 if ( name.isEmpty() || !vis )
419 {
420 return;
421 }
422 // NOOP
423 }
424
425
426 // TODO? Instead of being pure virtual, might be better to generalize this
427 // behavior and presume that none of the sub-classes are going to do
428 // anything strange with regards to their name or description?
429
438 virtual QString name() const = 0;
439
440
446 virtual QString description() const = 0;
447
448
457 virtual QString fileVectorFilters() const
458 {
459 return QString();
460 }
461
462
471 virtual QString fileRasterFilters() const
472 {
473 return QString();
474 }
475
476 // TODO QGIS 5 -> Make `reloadData()` non virtual. This should be implemented in `reloadProviderData()`.
477
485 virtual void reloadData();
486
488 virtual QDateTime timestamp() const { return mTimestamp; }
489
491 virtual QDateTime dataTimestamp() const { return QDateTime(); }
492
498 virtual QgsError error() const { return mError; }
499
503 virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ) }
504
526 virtual bool enterUpdateMode() { return true; }
527
544 virtual bool leaveUpdateMode() { return true; }
545
551 void setProviderProperty( ProviderProperty property, const QVariant &value );
552
558 void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
559
565 QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
566
572 QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
573
583 virtual void setListening( bool isListening );
584
585#ifndef SIP_RUN
586
599#endif
600
612 virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
613
621 virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
622
630 virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ) return false; }
631
639 QgsCoordinateTransformContext transformContext() const SIP_SKIP;
640
651 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) SIP_SKIP;
652
659 static QString sublayerSeparator();
660
666 virtual Qgis::ProviderStyleStorageCapabilities styleStorageCapabilities() const;
667
668 signals:
669
677
691
698 void notify( const QString &msg );
699
700
701 protected:
702
706 QDateTime mTimestamp;
707
710
712 void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
713
715 void setError( const QgsError &error ) { mError = error;}
716
719
720 private:
721
726 QString mDataSourceURI;
727
729
730 QMap< int, QVariant > mProviderProperties;
731
735 mutable QMutex mOptionsMutex;
736
741 virtual void reloadProviderData() {}
742
743 friend class TestQgsProject;
744};
745
746#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
QFlags< DataProviderFlag > DataProviderFlags
Data provider flags.
Definition qgis.h:2373
static const int MAXIMUM_LAYER_PREVIEW_TIME_MS
Maximum rendering time for a layer of a preview job.
Definition qgis.h:6529
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:505
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:45
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.
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).
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 Qgis::DataProviderFlags flags() const
Returns the generic data provider flags.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
void dataChanged()
Emitted whenever a change is made to the data provider which may have caused changes in the provider'...
virtual QString dataComment() const
Returns a short comment for the data that this provider is providing access to (e....
virtual QVariantMap metadata() const
Returns provider specific metadata.
void setUri(const QString &uri)
Set the data source specification.
void fullExtentCalculated()
Emitted whenever a deferred extent calculation is completed by the provider.
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 ...
@ CustomData
Custom properties for 3rd party providers or very provider-specific properties which are not expected...
virtual QgsBox3D extent3D() const
Returns the 3D extent of the layer.
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider's source.
virtual bool isValid() const =0
Returns true if this is a valid layer.
QDateTime mTimestamp
Timestamp of data in the moment when the data were loaded by provider.
QgsError mError
Error.
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.
QgsDataProvider(const QString &uri=QString(), const QgsDataProvider::ProviderOptions &providerOptions=QgsDataProvider::ProviderOptions(), Qgis::DataProviderReadFlags flags=Qgis::DataProviderReadFlags())
Create a new dataprovider with the specified in the uri.
virtual QDateTime dataTimestamp() const
Current time stamp of data source.
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.
void notify(const QString &msg)
Emitted when the datasource issues a notification.
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.
Qgis::DataProviderReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when needed.
virtual void updateExtents()
Update the extents of 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 renderInPreview(const QgsDataProvider::PreviewContext &context)
Returns whether the layer must be rendered in preview jobs.
friend class TestQgsProject
virtual bool enterUpdateMode()
Enter update mode.
virtual QgsRectangle extent() const =0
Returns the extent of the layer.
virtual void setSubLayerVisibility(const QString &name, bool vis)
Set the visibility of the given sublayer name.
void appendError(const QgsErrorMessage &message)
Add error message.
Stores the component parts of a data source URI (e.g.
Represents a single error message.
Definition qgserror.h:35
A container for error messages.
Definition qgserror.h:83
A structured metadata store for a map layer.
A rectangle specified with double values.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_END
Definition qgis_sip.h:216
Stores settings related to the context in which a preview job runs.
double maxRenderingTimeMs
Default maximum allowable render time, in ms.
double lastRenderingTimeMs
Previous rendering time for the layer, in ms.
Setting options for creating vector data providers.
QgsCoordinateTransformContext transformContext
Coordinate transform context.