QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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"
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"
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
80 {
82 CustomData = 3000
83 };
84
101
107 {
108 FlagTrustDataSource = 1 << 0,
109 SkipFeatureCount = 1 << 1,
110 FlagLoadDefaultStyle = 1 << 2,
111 SkipGetExtent = 1 << 3,
112 SkipFullScan = 1 << 4,
113 ForceReadOnly = 1 << 5,
114 SkipCredentialsRequest = 1 << 6,
115 ParallelThreadLoading = 1 << 7,
116 };
117 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
118
119
124 QgsDataProvider( const QString &uri = QString(),
126 QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
127
134
140 virtual void setDataSourceUri( const QString &uri )
141 {
142 mDataSourceURI = uri;
143 }
144
154 virtual QString dataSourceUri( bool expandAuthConfig = false ) const
155 {
156 if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
157 {
158 const QgsDataSourceUri uri( mDataSourceURI );
159 return uri.uri( expandAuthConfig );
160 }
161 else
162 {
163 return mDataSourceURI;
164 }
165 }
166
174 virtual QString dataComment() const { return QString(); };
175
181 virtual QString htmlMetadata() const;
182
187 void setUri( const QgsDataSourceUri &uri )
188 {
189 mDataSourceURI = uri.uri( true );
190 }
191
197 void setUri( const QString &uri )
198 {
199 mDataSourceURI = uri;
200 }
201
207 {
208 return QgsDataSourceUri( mDataSourceURI );
209 }
210
216 virtual Qgis::DataProviderFlags flags() const;
217
225 virtual QgsDataProviderTemporalCapabilities *temporalCapabilities();
226
234 virtual const QgsDataProviderTemporalCapabilities *temporalCapabilities() const SIP_SKIP;
235
243 virtual QgsDataProviderElevationProperties *elevationProperties();
244
252 virtual const QgsDataProviderElevationProperties *elevationProperties() const SIP_SKIP;
253
258 virtual QgsRectangle extent() const = 0;
259
265 virtual QgsBox3D extent3D() const
266 {
267 return extent().toBox3d( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN() );
268 }
269
274 virtual bool isValid() const = 0;
275
279 virtual void updateExtents()
280 {
281 // NOP by default
282 }
283
284
291 virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
292 {
293 // NOP by default
294 Q_UNUSED( subset )
295 Q_UNUSED( updateFeatureCount )
296 return false;
297 }
298
299
303 virtual bool supportsSubsetString() const { return false; }
304
311 virtual QString subsetString() const
312 {
313 return QString();
314 }
315
316
325 virtual QStringList subLayers() const
326 {
327 return QStringList(); // Empty
328 }
329
337 virtual QStringList subLayerStyles() const
338 {
339 return QStringList(); // Empty
340 }
341
342
346 virtual uint subLayerCount() const
347 {
348 return 0;
349 }
350
351
357 virtual void setLayerOrder( const QStringList &layers )
358 {
359 //prevent unused var warnings
360 if ( layers.count() < 1 )
361 {
362 return;
363 }
364 // NOOP
365 }
366
367
371 virtual void setSubLayerVisibility( const QString &name, bool vis )
372 {
373 //prevent unused var warnings
374 if ( name.isEmpty() || !vis )
375 {
376 return;
377 }
378 // NOOP
379 }
380
381
397 virtual QString name() const = 0;
398
399
412 virtual QString description() const = 0;
413
414
425 virtual QString fileVectorFilters() const
426 {
427 return QString();
428 }
429
430
441 virtual QString fileRasterFilters() const
442 {
443 return QString();
444 }
445
446 // TODO QGIS 4 -> Make `reloadData()` non virtual. This should be implemented in `reloadProviderData()`.
447
455 virtual void reloadData();
456
458 virtual QDateTime timestamp() const { return mTimestamp; }
459
461 virtual QDateTime dataTimestamp() const { return QDateTime(); }
462
468 virtual QgsError error() const { return mError; }
469
473 virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ) }
474
496 virtual bool enterUpdateMode() { return true; }
497
514 virtual bool leaveUpdateMode() { return true; }
515
521 void setProviderProperty( ProviderProperty property, const QVariant &value );
522
528 void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
529
535 QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
536
542 QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
543
553 virtual void setListening( bool isListening );
554
555#ifndef SIP_RUN
556
562 {
564 double lastRenderingTimeMs = -1;
565
567 double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
568 };
569#endif
570
582 virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
583
591 virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
592
600 virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ) return false; }
601
609 QgsCoordinateTransformContext transformContext() const SIP_SKIP;
610
621 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) SIP_SKIP;
622
629 static QString sublayerSeparator();
630
636 virtual Qgis::ProviderStyleStorageCapabilities styleStorageCapabilities() const;
637
638 signals:
639
646 void fullExtentCalculated();
647
660 void dataChanged();
661
668 void notify( const QString &msg );
669
670
671 protected:
672
676 QDateTime mTimestamp;
677
679 QgsError mError;
680
682 void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
683
685 void setError( const QgsError &error ) { mError = error;}
686
688 QgsDataProvider::ReadFlags mReadFlags = QgsDataProvider::ReadFlags();
689
690 private:
691
696 QString mDataSourceURI;
697
699
700 QMap< int, QVariant > mProviderProperties;
701
705 mutable QMutex mOptionsMutex;
706
711 virtual void reloadProviderData() {}
712
713 friend class TestQgsProject;
714};
715
716Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataProvider::ReadFlags )
717
718#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:43
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....
void setUri(const QString &uri)
Set the data source specification.
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 bool isValid() const =0
Returns true if this is a valid layer.
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.
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 void updateExtents()
Update the extents of the layer.
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.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_END
Definition qgis_sip.h:208
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
Stores settings related to the context in which a preview job runs.
Setting options for creating vector data providers.
QgsCoordinateTransformContext transformContext
Coordinate transform context.