QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
32class 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
84
101
107 QgsDataProvider( const QString &uri = QString(),
110
117
123 virtual void setDataSourceUri( const QString &uri )
124 {
125 mDataSourceURI = uri;
126 }
127
137 virtual QString dataSourceUri( bool expandAuthConfig = false ) const
138 {
139 if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
140 {
141 const QgsDataSourceUri uri( mDataSourceURI );
142 return uri.uri( expandAuthConfig );
143 }
144 else
145 {
146 return mDataSourceURI;
147 }
148 }
149
157 virtual QString dataComment() const { return QString(); };
158
164 virtual QString htmlMetadata() const;
165
178 virtual QVariantMap metadata() const { return QVariantMap(); }
179
185 {
186 mDataSourceURI = uri.uri( true );
187 }
188
194 void setUri( const QString &uri )
195 {
196 mDataSourceURI = uri;
197 }
198
204 {
205 return QgsDataSourceUri( mDataSourceURI );
206 }
207
213 virtual Qgis::DataProviderFlags flags() const;
214
222 virtual QgsDataProviderTemporalCapabilities *temporalCapabilities();
223
231 virtual const QgsDataProviderTemporalCapabilities *temporalCapabilities() const SIP_SKIP;
232
240 virtual QgsDataProviderElevationProperties *elevationProperties();
241
249 virtual const QgsDataProviderElevationProperties *elevationProperties() const SIP_SKIP;
250
259 virtual QgsRectangle extent() const = 0;
260
271 virtual QgsBox3D extent3D() const
272 {
273 return extent().toBox3d( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN() );
274 }
275
280 virtual bool isValid() const = 0;
281
285 virtual void updateExtents()
286 {
287 // NOP by default
288 }
289
301 virtual QString subsetStringDialect() const;
302
314 virtual QString subsetStringHelpUrl() const;
315
331 virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true );
332
339 virtual bool supportsSubsetString() const;
340
357 virtual QString subsetString() const;
358
367 virtual QStringList subLayers() const
368 {
369 return QStringList(); // Empty
370 }
371
379 virtual QStringList subLayerStyles() const
380 {
381 return QStringList(); // Empty
382 }
383
384
388 virtual uint subLayerCount() const
389 {
390 return 0;
391 }
392
393
399 virtual void setLayerOrder( const QStringList &layers )
400 {
401 //prevent unused var warnings
402 if ( layers.count() < 1 )
403 {
404 return;
405 }
406 // NOOP
407 }
408
409
413 virtual void setSubLayerVisibility( const QString &name, bool vis )
414 {
415 //prevent unused var warnings
416 if ( name.isEmpty() || !vis )
417 {
418 return;
419 }
420 // NOOP
421 }
422
423
424 // TODO? Instead of being pure virtual, might be better to generalize this
425 // behavior and presume that none of the sub-classes are going to do
426 // anything strange with regards to their name or description?
427
436 virtual QString name() const = 0;
437
438
444 virtual QString description() const = 0;
445
446
455 virtual QString fileVectorFilters() const
456 {
457 return QString();
458 }
459
460
469 virtual QString fileRasterFilters() const
470 {
471 return QString();
472 }
473
474 // TODO QGIS 4 -> Make `reloadData()` non virtual. This should be implemented in `reloadProviderData()`.
475
483 virtual void reloadData();
484
486 virtual QDateTime timestamp() const { return mTimestamp; }
487
489 virtual QDateTime dataTimestamp() const { return QDateTime(); }
490
496 virtual QgsError error() const { return mError; }
497
501 virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ) }
502
524 virtual bool enterUpdateMode() { return true; }
525
542 virtual bool leaveUpdateMode() { return true; }
543
549 void setProviderProperty( ProviderProperty property, const QVariant &value );
550
556 void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
557
563 QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
564
570 QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
571
581 virtual void setListening( bool isListening );
582
583#ifndef SIP_RUN
584
597#endif
598
610 virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
611
619 virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
620
628 virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ) return false; }
629
637 QgsCoordinateTransformContext transformContext() const SIP_SKIP;
638
649 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) SIP_SKIP;
650
657 static QString sublayerSeparator();
658
664 virtual Qgis::ProviderStyleStorageCapabilities styleStorageCapabilities() const;
665
666 signals:
667
675
689
696 void notify( const QString &msg );
697
698
699 protected:
700
704 QDateTime mTimestamp;
705
708
710 void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
711
713 void setError( const QgsError &error ) { mError = error;}
714
717
718 private:
719
724 QString mDataSourceURI;
725
727
728 QMap< int, QVariant > mProviderProperties;
729
733 mutable QMutex mOptionsMutex;
734
739 virtual void reloadProviderData() {}
740
741 friend class TestQgsProject;
742};
743
744#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
QFlags< DataProviderFlag > DataProviderFlags
Data provider flags.
Definition qgis.h:2315
static const int MAXIMUM_LAYER_PREVIEW_TIME_MS
Maximum rendering time for a layer of a preview job.
Definition qgis.h:6252
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:486
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:42
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:33
A container for error messages.
Definition qgserror.h:81
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.