QGIS API Documentation  3.15.0-Master (61a1801e3d)
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 
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
virtual void setSubLayerVisibility(const QString &name, bool vis)
Set the visibility of the given sublayer name.
virtual bool setSubsetString(const QString &subset, bool updateFeatureCount=true)
Set the subset string used to create a subset of features in the layer.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
virtual QString subsetString() const
Returns the subset definition string (typically sql) currently in use by the layer and used by the pr...
virtual void updateExtents()
Update the extents of the layer.
virtual QgsError error() const
Gets current status error.
virtual QString fileRasterFilters() const
Returns raster file filter string.
virtual QString dataComment() const
Returns a short comment for the data that this provider is providing access to (e.g.
QDateTime mTimestamp
Timestamp of data in the moment when the data were loaded by provider.
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.
virtual QStringList subLayers() const
Sub-layers handled by this provider, in order from bottom to top.
virtual uint subLayerCount() const
Returns the number of layers for the current data source.
Base class for handling properties relating to a data provider&#39;s temporal capabilities.
Abstract base class for spatial data provider implementations.
const QgsCoordinateReferenceSystem & crs
DataCapability
Used in browser model to understand which items for which providers should be populated.
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider&#39;s source.
virtual QDateTime dataTimestamp() const
Current time stamp of data source.
#define SIP_SKIP
Definition: qgis_sip.h:126
void setUri(const QgsDataSourceUri &uri)
Set the data source specification.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
QgsDataSourceUri uri() const
Gets the data source specification.
#define SIP_END
Definition: qgis_sip.h:194
void appendError(const QgsErrorMessage &message)
Add error message.
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 bool supportsSubsetString() const
Returns true if the provider supports setting of subset strings.
QgsErrorMessage represents single error message.
Definition: qgserror.h:32
virtual void setDataSourceUri(const QString &uri)
Set the data source specification.
void append(const QString &message, const QString &tag)
Append new error message.
Definition: qgserror.cpp:39
Contains information about the context in which a coordinate transform is executed.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
QString uri(bool expandAuthConfig=true) const
Returns the complete URI as a string.
ReadFlag
Flags which control dataprovider construction.
A structured metadata store for a map layer.
Setting options for creating vector data providers.
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
QgsError is container for error messages (report).
Definition: qgserror.h:80
virtual QString fileVectorFilters() const
Returns vector file filter string.
void setError(const QgsError &error)
Sets error message.
This class represents a coordinate reference system (CRS).
QgsError mError
Error.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
virtual bool enterUpdateMode()
Enter update mode.
virtual QStringList subLayerStyles() const
Sub-layer styles for each sub-layer handled by this provider, in order from bottom to top...
virtual bool writeLayerMetadata(const QgsLayerMetadata &metadata)
Writes layer metadata to the underlying provider source.
Class for storing the component parts of a RDBMS data source URI (e.g.
virtual void invalidateConnections(const QString &connection)
Invalidate connections corresponding to specified name.
Stores settings related to the context in which a preview job runs.
ProviderProperty
Properties are used to pass custom configuration options into data providers.
Evaluate default values on provider side when calling QgsVectorDataProvider::defaultValue( int index ...
virtual bool leaveUpdateMode()
Leave update mode.