QGIS API Documentation  3.17.0-Master (8af46bc54f)
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 if ( qobject_cast<QgsPointCloudDataProvider *>( sipCpp ) )
59  {
60  sipType = sipType_QgsPointCloudDataProvider;
61  }
62  else
63  {
64  sipType = 0;
65  }
66  SIP_END
67 #endif
68  Q_OBJECT
69 
70  public:
71 
72  // TODO QGIS 4: (re)move DataCapability as this enum is really meant for data items rather than data providers
73 
78  {
79  NoDataCapabilities = 0,
80  File = 1,
81  Dir = 1 << 1,
82  Database = 1 << 2,
83  Net = 1 << 3 // Internet source
84  };
85  Q_DECLARE_FLAGS( DataCapabilities, DataCapability )
86 
87 
95  {
97  CustomData = 3000
98  };
99 
100 
109  {
110 
115 
116  };
117 
122  enum ReadFlag
123  {
124  FlagTrustDataSource = 1 << 0,
125  SkipFeatureCount = 1 << 1,
126  };
127  Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
128 
129 
134  QgsDataProvider( const QString &uri = QString(),
136  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
137 
143  virtual QgsCoordinateReferenceSystem crs() const = 0;
144 
150  virtual void setDataSourceUri( const QString &uri )
151  {
152  mDataSourceURI = uri;
153  }
154 
164  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
165  {
166  if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
167  {
168  const QgsDataSourceUri uri( mDataSourceURI );
169  return uri.uri( expandAuthConfig );
170  }
171  else
172  {
173  return mDataSourceURI;
174  }
175  }
176 
184  virtual QString dataComment() const { return QString(); };
185 
186 
192  void setUri( const QgsDataSourceUri &uri )
193  {
194  mDataSourceURI = uri.uri( true );
195  }
196 
203  {
204  return QgsDataSourceUri( mDataSourceURI );
205  }
206 
214  virtual QgsDataProviderTemporalCapabilities *temporalCapabilities();
215 
223  virtual const QgsDataProviderTemporalCapabilities *temporalCapabilities() const SIP_SKIP;
224 
229  virtual QgsRectangle extent() const = 0;
230 
231 
236  virtual bool isValid() const = 0;
237 
238 
242  virtual void updateExtents()
243  {
244  // NOP by default
245  }
246 
247 
254  virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
255  {
256  // NOP by default
257  Q_UNUSED( subset )
258  Q_UNUSED( updateFeatureCount )
259  return false;
260  }
261 
262 
266  virtual bool supportsSubsetString() const { return false; }
267 
274  virtual QString subsetString() const
275  {
276  return QString();
277  }
278 
279 
288  virtual QStringList subLayers() const
289  {
290  return QStringList(); // Empty
291  }
292 
300  virtual QStringList subLayerStyles() const
301  {
302  return QStringList(); // Empty
303  }
304 
305 
309  virtual uint subLayerCount() const
310  {
311  return 0;
312  }
313 
314 
320  virtual void setLayerOrder( const QStringList &layers )
321  {
322  //prevent unused var warnings
323  if ( layers.count() < 1 )
324  {
325  return;
326  }
327  // NOOP
328  }
329 
330 
334  virtual void setSubLayerVisibility( const QString &name, bool vis )
335  {
336  //prevent unused var warnings
337  if ( name.isEmpty() || !vis )
338  {
339  return;
340  }
341  // NOOP
342  }
343 
344 
360  virtual QString name() const = 0;
361 
362 
375  virtual QString description() const = 0;
376 
377 
388  virtual QString fileVectorFilters() const
389  {
390  return QString();
391  }
392 
393 
404  virtual QString fileRasterFilters() const
405  {
406  return QString();
407  }
408 
415  virtual void reloadData();
416 
418  virtual QDateTime timestamp() const { return mTimestamp; }
419 
421  virtual QDateTime dataTimestamp() const { return QDateTime(); }
422 
428  virtual QgsError error() const { return mError; }
429 
434  virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ) }
435 
458  virtual bool enterUpdateMode() { return true; }
459 
477  virtual bool leaveUpdateMode() { return true; }
478 
485  void setProviderProperty( ProviderProperty property, const QVariant &value );
486 
493  void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
494 
501  QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
502 
509  QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
510 
521  virtual void setListening( bool isListening );
522 
523 #ifndef SIP_RUN
524 
531  {
533  double lastRenderingTimeMs = -1;
534 
536  double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
537  };
538 #endif
539 
552  virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
553 
562  virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
563 
572  virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ) return false; }
573 
581  QgsCoordinateTransformContext transformContext() const SIP_SKIP;
582 
593  virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) SIP_SKIP;
594 
601  static QString sublayerSeparator();
602 
603  signals:
604 
611  void fullExtentCalculated();
612 
625  void dataChanged();
626 
634  void notify( const QString &msg );
635 
636 
637  protected:
638 
642  QDateTime mTimestamp;
643 
646 
648  void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
649 
651  void setError( const QgsError &error ) { mError = error;}
652 
654  QgsDataProvider::ReadFlags mReadFlags = QgsDataProvider::ReadFlags();
655 
656  private:
657 
662  QString mDataSourceURI;
663 
665 
666  QMap< int, QVariant > mProviderProperties;
667 
671  mutable QMutex mOptionsMutex;
672 
677  virtual void reloadProviderData() {}
678 };
679 
680 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataProvider::ReadFlags )
681 
682 #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.