QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 "qgsdataitem.h"
27 #include "qgsdatasourceuri.h"
29 #include "qgslayermetadata.h"
30 #include "qgserror.h"
31 
32 class QgsRectangle;
35 
36 
41 class 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
59  {
60  sipType = 0;
61  }
62  SIP_END
63 #endif
64  Q_OBJECT
65 
66  public:
67 
68  // TODO QGIS 4: (re)move DataCapability as this enum is really meant for data items rather than data providers
69 
74  {
75  NoDataCapabilities = 0,
76  File = 1,
77  Dir = 1 << 1,
78  Database = 1 << 2,
79  Net = 1 << 3 // Internet source
80  };
81  Q_DECLARE_FLAGS( DataCapabilities, DataCapability )
82 
83 
91  {
93  CustomData = 3000
94  };
95 
96 
105  {
106 
111 
112  };
113 
118  enum ReadFlag
119  {
120  FlagTrustDataSource = 1 << 0,
121  };
122  Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
123 
124 
129  QgsDataProvider( const QString &uri = QString(),
131  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
132 
138  virtual QgsCoordinateReferenceSystem crs() const = 0;
139 
145  virtual void setDataSourceUri( const QString &uri )
146  {
147  mDataSourceURI = uri;
148  }
149 
159  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
160  {
161  if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
162  {
163  const QgsDataSourceUri uri( mDataSourceURI );
164  return uri.uri( expandAuthConfig );
165  }
166  else
167  {
168  return mDataSourceURI;
169  }
170  }
171 
179  virtual QString dataComment() const { return QString(); };
180 
181 
187  void setUri( const QgsDataSourceUri &uri )
188  {
189  mDataSourceURI = uri.uri( true );
190  }
191 
198  {
199  return QgsDataSourceUri( mDataSourceURI );
200  }
201 
209  virtual QgsDataProviderTemporalCapabilities *temporalCapabilities();
210 
218  virtual const QgsDataProviderTemporalCapabilities *temporalCapabilities() const SIP_SKIP;
219 
224  virtual QgsRectangle extent() const = 0;
225 
226 
231  virtual bool isValid() const = 0;
232 
233 
237  virtual void updateExtents()
238  {
239  // NOP by default
240  }
241 
242 
249  virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
250  {
251  // NOP by default
252  Q_UNUSED( subset )
253  Q_UNUSED( updateFeatureCount )
254  return false;
255  }
256 
257 
261  virtual bool supportsSubsetString() const { return false; }
262 
269  virtual QString subsetString() const
270  {
271  return QString();
272  }
273 
274 
283  virtual QStringList subLayers() const
284  {
285  return QStringList(); // Empty
286  }
287 
295  virtual QStringList subLayerStyles() const
296  {
297  return QStringList(); // Empty
298  }
299 
300 
304  virtual uint subLayerCount() const
305  {
306  return 0;
307  }
308 
309 
315  virtual void setLayerOrder( const QStringList &layers )
316  {
317  //prevent unused var warnings
318  if ( layers.count() < 1 )
319  {
320  return;
321  }
322  // NOOP
323  }
324 
325 
329  virtual void setSubLayerVisibility( const QString &name, bool vis )
330  {
331  //prevent unused var warnings
332  if ( name.isEmpty() || !vis )
333  {
334  return;
335  }
336  // NOOP
337  }
338 
339 
355  virtual QString name() const = 0;
356 
357 
370  virtual QString description() const = 0;
371 
372 
383  virtual QString fileVectorFilters() const
384  {
385  return QString();
386  }
387 
388 
399  virtual QString fileRasterFilters() const
400  {
401  return QString();
402  }
403 
410  virtual void reloadData();
411 
413  virtual QDateTime timestamp() const { return mTimestamp; }
414 
416  virtual QDateTime dataTimestamp() const { return QDateTime(); }
417 
423  virtual QgsError error() const { return mError; }
424 
429  virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ) }
430 
453  virtual bool enterUpdateMode() { return true; }
454 
472  virtual bool leaveUpdateMode() { return true; }
473 
480  void setProviderProperty( ProviderProperty property, const QVariant &value );
481 
488  void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
489 
496  QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
497 
504  QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
505 
516  virtual void setListening( bool isListening );
517 
518 #ifndef SIP_RUN
519 
526  {
528  double lastRenderingTimeMs = -1;
529 
531  double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
532  };
533 #endif
534 
547  virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
548 
557  virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
558 
567  virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ) return false; }
568 
576  QgsCoordinateTransformContext transformContext() const SIP_SKIP;
577 
588  virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) SIP_SKIP;
589 
596  static QString sublayerSeparator();
597 
598  signals:
599 
606  void fullExtentCalculated();
607 
620  void dataChanged();
621 
629  void notify( const QString &msg );
630 
631 
632  protected:
633 
637  QDateTime mTimestamp;
638 
640  QgsError mError;
641 
643  void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
644 
646  void setError( const QgsError &error ) { mError = error;}
647 
649  QgsDataProvider::ReadFlags mReadFlags = QgsDataProvider::ReadFlags();
650 
651  private:
652 
657  QString mDataSourceURI;
658 
660 
661  QMap< int, QVariant > mProviderProperties;
662 
666  mutable QMutex mOptionsMutex;
667 
672  virtual void reloadProviderData() {}
673 };
674 
675 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataProvider::ReadFlags )
676 
677 #endif
QgsDataSourceUri
Class for storing the component parts of a RDBMS data source URI (e.g.
Definition: qgsdatasourceuri.h:36
QgsDataProvider::subLayerStyles
virtual QStringList subLayerStyles() const
Sub-layer styles for each sub-layer handled by this provider, in order from bottom to top.
Definition: qgsdataprovider.h:295
QgsDataProvider::subLayerCount
virtual uint subLayerCount() const
Returns the number of layers for the current data source.
Definition: qgsdataprovider.h:304
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
QgsDataProvider::supportsSubsetString
virtual bool supportsSubsetString() const
Returns true if the provider supports setting of subset strings.
Definition: qgsdataprovider.h:261
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:105
QgsDataProvider
Abstract base class for spatial data provider implementations.
Definition: qgsdataprovider.h:42
QgsDataProvider::setSubLayerVisibility
virtual void setSubLayerVisibility(const QString &name, bool vis)
Set the visibility of the given sublayer name.
Definition: qgsdataprovider.h:329
qgscoordinatetransformcontext.h
QgsDataProvider::setSubsetString
virtual bool setSubsetString(const QString &subset, bool updateFeatureCount=true)
Set the subset string used to create a subset of features in the layer.
Definition: qgsdataprovider.h:249
QgsLayerMetadata
A structured metadata store for a map layer.
Definition: qgslayermetadata.h:57
QgsDataProvider::invalidateConnections
virtual void invalidateConnections(const QString &connection)
Invalidate connections corresponding to specified name.
Definition: qgsdataprovider.h:429
QgsDataProvider::error
virtual QgsError error() const
Gets current status error.
Definition: qgsdataprovider.h:423
QgsError
QgsError is container for error messages (report).
Definition: qgserror.h:81
QgsDataProvider::dataSourceUri
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
Definition: qgsdataprovider.h:159
QgsError::append
void append(const QString &message, const QString &tag)
Append new error message.
Definition: qgserror.cpp:39
QgsDataProvider::ProviderProperty
ProviderProperty
Properties are used to pass custom configuration options into data providers.
Definition: qgsdataprovider.h:91
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsDataProvider::description
virtual QString description() const =0
Returns description.
QgsDataProvider::timestamp
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsdataprovider.h:413
QgsDataProviderTemporalCapabilities
Base class for handling properties relating to a data provider's temporal capabilities.
Definition: qgsdataprovidertemporalcapabilities.h:34
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
qgslayermetadata.h
QgsDataProvider::EvaluateDefaultValues
@ EvaluateDefaultValues
Evaluate default values on provider side when calling QgsVectorDataProvider::defaultValue( int index ...
Definition: qgsdataprovider.h:92
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
qgserror.h
qgsdatasourceuri.h
QgsDataProvider::setUri
void setUri(const QgsDataSourceUri &uri)
Set the data source specification.
Definition: qgsdataprovider.h:187
QgsDataProvider::writeLayerMetadata
virtual bool writeLayerMetadata(const QgsLayerMetadata &metadata)
Writes layer metadata to the underlying provider source.
Definition: qgsdataprovider.h:567
QgsDataProvider::enterUpdateMode
virtual bool enterUpdateMode()
Enter update mode.
Definition: qgsdataprovider.h:453
QgsDataProvider::PreviewContext
Stores settings related to the context in which a preview job runs.
Definition: qgsdataprovider.h:526
Q_DECLARE_OPERATORS_FOR_FLAGS
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.
QgsDataProvider::setError
void setError(const QgsError &error)
Sets error message.
Definition: qgsdataprovider.h:646
QgsErrorMessage
QgsErrorMessage represents single error message.
Definition: qgserror.h:33
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsDataProvider::dataTimestamp
virtual QDateTime dataTimestamp() const
Current time stamp of data source.
Definition: qgsdataprovider.h:416
QgsDataProvider::fileVectorFilters
virtual QString fileVectorFilters() const
Returns vector file filter string.
Definition: qgsdataprovider.h:383
QgsDataProvider::setDataSourceUri
virtual void setDataSourceUri(const QString &uri)
Set the data source specification.
Definition: qgsdataprovider.h:145
QgsDataProvider::ProviderOptions::transformContext
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Definition: qgsdataprovider.h:110
QgsDataSourceUri::uri
QString uri(bool expandAuthConfig=true) const
Returns the complete URI as a string.
Definition: qgsdatasourceuri.cpp:538
QgsDataProvider::uri
QgsDataSourceUri uri() const
Gets the data source specification.
Definition: qgsdataprovider.h:197
QgsDataProvider::leaveUpdateMode
virtual bool leaveUpdateMode()
Leave update mode.
Definition: qgsdataprovider.h:472
QgsDataProvider::subsetString
virtual QString subsetString() const
Returns the subset definition string (typically sql) currently in use by the layer and used by the pr...
Definition: qgsdataprovider.h:269
QgsDataProvider::name
virtual QString name() const =0
Returns a provider name.
QgsDataProvider::layerMetadata
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider's source.
Definition: qgsdataprovider.h:557
QgsDataProvider::dataComment
virtual QString dataComment() const
Returns a short comment for the data that this provider is providing access to (e....
Definition: qgsdataprovider.h:179
QgsDataProvider::ReadFlag
ReadFlag
Flags which control dataprovider construction.
Definition: qgsdataprovider.h:119
SIP_END
#define SIP_END
Definition: qgis_sip.h:194
QgsDataProvider::DataCapability
DataCapability
Used in browser model to understand which items for which providers should be populated.
Definition: qgsdataprovider.h:74
QgsDataProvider::setLayerOrder
virtual void setLayerOrder(const QStringList &layers)
Reorder the list of layer names to be rendered by this provider (in order from bottom to top)
Definition: qgsdataprovider.h:315
QgsDataProvider::fileRasterFilters
virtual QString fileRasterFilters() const
Returns raster file filter string.
Definition: qgsdataprovider.h:399
QgsDataProvider::subLayers
virtual QStringList subLayers() const
Sub-layers handled by this provider, in order from bottom to top.
Definition: qgsdataprovider.h:283
QgsDataProvider::crs
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.