QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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"
30 
31 class QgsRectangle;
34 
35 
40 class CORE_EXPORT QgsDataProvider : public QObject
41 {
42 
43 #ifdef SIP_RUN
45  if ( qobject_cast<QgsVectorDataProvider *>( sipCpp ) )
46  {
47  sipType = sipType_QgsVectorDataProvider;
48  }
49  else if ( qobject_cast<QgsRasterDataProvider *>( sipCpp ) )
50  {
51  sipType = sipType_QgsRasterDataProvider;
52  }
53  else if ( qobject_cast<QgsMeshDataProvider *>( sipCpp ) )
54  {
55  sipType = sipType_QgsMeshDataProvider;
56  }
57  else if ( qobject_cast<QgsPointCloudDataProvider *>( sipCpp ) )
58  {
59  sipType = sipType_QgsPointCloudDataProvider;
60  }
61  else
62  {
63  sipType = 0;
64  }
65  SIP_END
66 #endif
67  Q_OBJECT
68 
69  public:
70 
71  // TODO QGIS 4: (re)move DataCapability as this enum is really meant for data items rather than data providers
72 
77  {
78  NoDataCapabilities = 0,
79  File = 1,
80  Dir = 1 << 1,
81  Database = 1 << 2,
82  Net = 1 << 3 // Internet source
83  };
84  Q_DECLARE_FLAGS( DataCapabilities, DataCapability )
85 
86 
94  {
96  CustomData = 3000
97  };
98 
99 
108  {
109 
114 
115  };
116 
121  enum ReadFlag
122  {
123  FlagTrustDataSource = 1 << 0,
124  SkipFeatureCount = 1 << 1,
125  FlagLoadDefaultStyle = 1 << 2,
126  SkipGetExtent = 1 << 3,
127  SkipFullScan = 1 << 4,
128  };
129  Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
130 
131 
136  QgsDataProvider( const QString &uri = QString(),
138  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
139 
145  virtual QgsCoordinateReferenceSystem crs() const = 0;
146 
152  virtual void setDataSourceUri( const QString &uri )
153  {
154  mDataSourceURI = uri;
155  }
156 
166  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
167  {
168  if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
169  {
170  const QgsDataSourceUri uri( mDataSourceURI );
171  return uri.uri( expandAuthConfig );
172  }
173  else
174  {
175  return mDataSourceURI;
176  }
177  }
178 
186  virtual QString dataComment() const { return QString(); };
187 
188 
194  void setUri( const QgsDataSourceUri &uri )
195  {
196  mDataSourceURI = uri.uri( true );
197  }
198 
205  {
206  return QgsDataSourceUri( mDataSourceURI );
207  }
208 
214  virtual Qgis::DataProviderFlags flags() const;
215 
223  virtual QgsDataProviderTemporalCapabilities *temporalCapabilities();
224 
232  virtual const QgsDataProviderTemporalCapabilities *temporalCapabilities() const SIP_SKIP;
233 
238  virtual QgsRectangle extent() const = 0;
239 
240 
245  virtual bool isValid() const = 0;
246 
250  virtual void updateExtents()
251  {
252  // NOP by default
253  }
254 
255 
262  virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
263  {
264  // NOP by default
265  Q_UNUSED( subset )
266  Q_UNUSED( updateFeatureCount )
267  return false;
268  }
269 
270 
274  virtual bool supportsSubsetString() const { return false; }
275 
282  virtual QString subsetString() const
283  {
284  return QString();
285  }
286 
287 
296  virtual QStringList subLayers() const
297  {
298  return QStringList(); // Empty
299  }
300 
308  virtual QStringList subLayerStyles() const
309  {
310  return QStringList(); // Empty
311  }
312 
313 
317  virtual uint subLayerCount() const
318  {
319  return 0;
320  }
321 
322 
328  virtual void setLayerOrder( const QStringList &layers )
329  {
330  //prevent unused var warnings
331  if ( layers.count() < 1 )
332  {
333  return;
334  }
335  // NOOP
336  }
337 
338 
342  virtual void setSubLayerVisibility( const QString &name, bool vis )
343  {
344  //prevent unused var warnings
345  if ( name.isEmpty() || !vis )
346  {
347  return;
348  }
349  // NOOP
350  }
351 
352 
368  virtual QString name() const = 0;
369 
370 
383  virtual QString description() const = 0;
384 
385 
396  virtual QString fileVectorFilters() const
397  {
398  return QString();
399  }
400 
401 
412  virtual QString fileRasterFilters() const
413  {
414  return QString();
415  }
416 
417  // TODO QGIS 4 -> Make `reloadData()` non virtual. This should be implemented in `reloadProviderData()`.
418 
426  virtual void reloadData();
427 
429  virtual QDateTime timestamp() const { return mTimestamp; }
430 
432  virtual QDateTime dataTimestamp() const { return QDateTime(); }
433 
439  virtual QgsError error() const { return mError; }
440 
445  virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ) }
446 
469  virtual bool enterUpdateMode() { return true; }
470 
488  virtual bool leaveUpdateMode() { return true; }
489 
496  void setProviderProperty( ProviderProperty property, const QVariant &value );
497 
504  void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
505 
512  QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
513 
520  QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
521 
532  virtual void setListening( bool isListening );
533 
534 #ifndef SIP_RUN
535 
542  {
544  double lastRenderingTimeMs = -1;
545 
547  double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
548  };
549 #endif
550 
563  virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
564 
573  virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
574 
583  virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ) return false; }
584 
592  QgsCoordinateTransformContext transformContext() const SIP_SKIP;
593 
604  virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) SIP_SKIP;
605 
612  static QString sublayerSeparator();
613 
614  signals:
615 
622  void fullExtentCalculated();
623 
636  void dataChanged();
637 
645  void notify( const QString &msg );
646 
647 
648  protected:
649 
653  QDateTime mTimestamp;
654 
656  QgsError mError;
657 
659  void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
660 
662  void setError( const QgsError &error ) { mError = error;}
663 
665  QgsDataProvider::ReadFlags mReadFlags = QgsDataProvider::ReadFlags();
666 
667  private:
668 
673  QString mDataSourceURI;
674 
676 
677  QMap< int, QVariant > mProviderProperties;
678 
682  mutable QMutex mOptionsMutex;
683 
688  virtual void reloadProviderData() {}
689 };
690 
691 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataProvider::ReadFlags )
692 
693 #endif
QgsDataSourceUri
Class for storing the component parts of a RDBMS data source URI (e.g. a Postgres data source).
Definition: qgsdatasourceuri.h:37
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:308
QgsDataProvider::subLayerCount
virtual uint subLayerCount() const
Returns the number of layers for the current data source.
Definition: qgsdataprovider.h:317
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
QgsDataProvider::supportsSubsetString
virtual bool supportsSubsetString() const
Returns true if the provider supports setting of subset strings.
Definition: qgsdataprovider.h:274
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:107
QgsDataProvider
Abstract base class for spatial data provider implementations.
Definition: qgsdataprovider.h:40
QgsDataProvider::setSubLayerVisibility
virtual void setSubLayerVisibility(const QString &name, bool vis)
Set the visibility of the given sublayer name.
Definition: qgsdataprovider.h:342
qgscoordinatetransformcontext.h
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
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:262
QgsLayerMetadata
A structured metadata store for a map layer.
Definition: qgslayermetadata.h:56
QgsDataProvider::invalidateConnections
virtual void invalidateConnections(const QString &connection)
Invalidate connections corresponding to specified name.
Definition: qgsdataprovider.h:445
QgsDataProvider::error
virtual QgsError error() const
Gets current status error.
Definition: qgsdataprovider.h:439
QgsError
QgsError is container for error messages (report). It may contain chain (sort of traceback) of error ...
Definition: qgserror.h:80
QgsDataProvider::dataSourceUri
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
Definition: qgsdataprovider.h:166
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:93
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsDataProvider::timestamp
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsdataprovider.h:429
QgsDataProviderTemporalCapabilities
Base class for handling properties relating to a data provider's temporal capabilities.
Definition: qgsdataprovidertemporalcapabilities.h:33
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
qgslayermetadata.h
QgsDataProvider::EvaluateDefaultValues
@ EvaluateDefaultValues
Evaluate default values on provider side when calling QgsVectorDataProvider::defaultValue( int index ...
Definition: qgsdataprovider.h:95
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:194
QgsDataProvider::writeLayerMetadata
virtual bool writeLayerMetadata(const QgsLayerMetadata &metadata)
Writes layer metadata to the underlying provider source.
Definition: qgsdataprovider.h:583
QgsDataProvider::enterUpdateMode
virtual bool enterUpdateMode()
Enter update mode.
Definition: qgsdataprovider.h:469
QgsDataProvider::PreviewContext
Stores settings related to the context in which a preview job runs.
Definition: qgsdataprovider.h:541
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:662
QgsErrorMessage
QgsErrorMessage represents single error message.
Definition: qgserror.h:32
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsDataProvider::dataTimestamp
virtual QDateTime dataTimestamp() const
Current time stamp of data source.
Definition: qgsdataprovider.h:432
QgsDataProvider::fileVectorFilters
virtual QString fileVectorFilters() const
Returns vector file filter string.
Definition: qgsdataprovider.h:396
QgsDataProvider::setDataSourceUri
virtual void setDataSourceUri(const QString &uri)
Set the data source specification.
Definition: qgsdataprovider.h:152
QgsDataProvider::ProviderOptions::transformContext
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Definition: qgsdataprovider.h:113
QgsDataSourceUri::uri
QString uri(bool expandAuthConfig=true) const
Returns the complete URI as a string.
Definition: qgsdatasourceuri.cpp:540
QgsDataProvider::uri
QgsDataSourceUri uri() const
Gets the data source specification.
Definition: qgsdataprovider.h:204
QgsDataProvider::leaveUpdateMode
virtual bool leaveUpdateMode()
Leave update mode.
Definition: qgsdataprovider.h:488
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:282
QgsDataProvider::layerMetadata
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider's source.
Definition: qgsdataprovider.h:573
QgsDataProvider::dataComment
virtual QString dataComment() const
Returns a short comment for the data that this provider is providing access to (e....
Definition: qgsdataprovider.h:186
QgsDataProvider::ReadFlag
ReadFlag
Flags which control dataprovider construction.
Definition: qgsdataprovider.h:121
SIP_END
#define SIP_END
Definition: qgis_sip.h:203
QgsDataProvider::DataCapability
DataCapability
Used in browser model to understand which items for which providers should be populated.
Definition: qgsdataprovider.h:76
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:328
QgsDataProvider::fileRasterFilters
virtual QString fileRasterFilters() const
Returns raster file filter string.
Definition: qgsdataprovider.h:412
QgsDataProvider::subLayers
virtual QStringList subLayers() const
Sub-layers handled by this provider, in order from bottom to top.
Definition: qgsdataprovider.h:296