QGIS API Documentation 3.38.0-Grenoble (exported)
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(),
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
262 virtual QgsRectangle extent() const = 0;
263
274 virtual QgsBox3D extent3D() const
275 {
276 return extent().toBox3d( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN() );
277 }
278
283 virtual bool isValid() const = 0;
284
288 virtual void updateExtents()
289 {
290 // NOP by default
291 }
292
293
300 virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
301 {
302 // NOP by default
303 Q_UNUSED( subset )
304 Q_UNUSED( updateFeatureCount )
305 return false;
306 }
307
308
312 virtual bool supportsSubsetString() const { return false; }
313
320 virtual QString subsetString() const
321 {
322 return QString();
323 }
324
325
334 virtual QStringList subLayers() const
335 {
336 return QStringList(); // Empty
337 }
338
346 virtual QStringList subLayerStyles() const
347 {
348 return QStringList(); // Empty
349 }
350
351
355 virtual uint subLayerCount() const
356 {
357 return 0;
358 }
359
360
366 virtual void setLayerOrder( const QStringList &layers )
367 {
368 //prevent unused var warnings
369 if ( layers.count() < 1 )
370 {
371 return;
372 }
373 // NOOP
374 }
375
376
380 virtual void setSubLayerVisibility( const QString &name, bool vis )
381 {
382 //prevent unused var warnings
383 if ( name.isEmpty() || !vis )
384 {
385 return;
386 }
387 // NOOP
388 }
389
390
406 virtual QString name() const = 0;
407
408
421 virtual QString description() const = 0;
422
423
434 virtual QString fileVectorFilters() const
435 {
436 return QString();
437 }
438
439
450 virtual QString fileRasterFilters() const
451 {
452 return QString();
453 }
454
455 // TODO QGIS 4 -> Make `reloadData()` non virtual. This should be implemented in `reloadProviderData()`.
456
464 virtual void reloadData();
465
467 virtual QDateTime timestamp() const { return mTimestamp; }
468
470 virtual QDateTime dataTimestamp() const { return QDateTime(); }
471
477 virtual QgsError error() const { return mError; }
478
482 virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ) }
483
505 virtual bool enterUpdateMode() { return true; }
506
523 virtual bool leaveUpdateMode() { return true; }
524
530 void setProviderProperty( ProviderProperty property, const QVariant &value );
531
537 void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
538
544 QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
545
551 QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
552
562 virtual void setListening( bool isListening );
563
564#ifndef SIP_RUN
565
571 {
573 double lastRenderingTimeMs = -1;
574
576 double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
577 };
578#endif
579
591 virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
592
600 virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
601
609 virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ) return false; }
610
618 QgsCoordinateTransformContext transformContext() const SIP_SKIP;
619
630 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) SIP_SKIP;
631
638 static QString sublayerSeparator();
639
645 virtual Qgis::ProviderStyleStorageCapabilities styleStorageCapabilities() const;
646
647 signals:
648
655 void fullExtentCalculated();
656
669 void dataChanged();
670
677 void notify( const QString &msg );
678
679
680 protected:
681
685 QDateTime mTimestamp;
686
688 QgsError mError;
689
691 void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
692
694 void setError( const QgsError &error ) { mError = error;}
695
698
699 private:
700
705 QString mDataSourceURI;
706
708
709 QMap< int, QVariant > mProviderProperties;
710
714 mutable QMutex mOptionsMutex;
715
720 virtual void reloadProviderData() {}
721
722 friend class TestQgsProject;
723};
724
726
727#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
QFlags< DataProviderFlag > DataProviderFlags
Data provider flags.
Definition qgis.h:1947
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....
QFlags< ReadFlag > ReadFlags
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.