QGIS API Documentation  3.9.0-Master (d9ef585e47)
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;
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
58  {
59  sipType = 0;
60  }
61  SIP_END
62 #endif
63  Q_OBJECT
64 
65  public:
66 
67  // TODO QGIS 4: (re)move DataCapability as this enum is really meant for data items rather than data providers
68 
73  {
74  NoDataCapabilities = 0,
75  File = 1,
76  Dir = 1 << 1,
77  Database = 1 << 2,
78  Net = 1 << 3 // Internet source
79  };
80  Q_DECLARE_FLAGS( DataCapabilities, DataCapability )
81 
82 
90  {
92  CustomData = 3000
93  };
94 
95 
104  {
106  };
107 
113  QgsDataProvider( const QString &uri = QString(), const QgsDataProvider::ProviderOptions &providerOptions = QgsDataProvider::ProviderOptions() );
114 
120  virtual QgsCoordinateReferenceSystem crs() const = 0;
121 
127  virtual void setDataSourceUri( const QString &uri )
128  {
129  mDataSourceURI = uri;
130  }
131 
141  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
142  {
143  if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
144  {
145  QgsDataSourceUri uri( mDataSourceURI );
146  return uri.uri( expandAuthConfig );
147  }
148  else
149  {
150  return mDataSourceURI;
151  }
152  }
153 
159  void setUri( const QgsDataSourceUri &uri )
160  {
161  mDataSourceURI = uri.uri( true );
162  }
163 
170  {
171  return QgsDataSourceUri( mDataSourceURI );
172  }
173 
178  virtual QgsRectangle extent() const = 0;
179 
180 
185  virtual bool isValid() const = 0;
186 
187 
191  virtual void updateExtents()
192  {
193  // NOP by default
194  }
195 
196 
203  virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
204  {
205  // NOP by default
206  Q_UNUSED( subset )
207  Q_UNUSED( updateFeatureCount )
208  return false;
209  }
210 
211 
215  virtual bool supportsSubsetString() const { return false; }
216 
223  virtual QString subsetString() const
224  {
225  return QString();
226  }
227 
228 
237  virtual QStringList subLayers() const
238  {
239  return QStringList(); // Empty
240  }
241 
247  static QString SUBLAYER_SEPARATOR;
248 
256  virtual QStringList subLayerStyles() const
257  {
258  return QStringList(); // Empty
259  }
260 
261 
265  virtual uint subLayerCount() const
266  {
267  return 0;
268  }
269 
270 
276  virtual void setLayerOrder( const QStringList &layers )
277  {
278  //prevent unused var warnings
279  if ( layers.count() < 1 )
280  {
281  return;
282  }
283  // NOOP
284  }
285 
286 
290  virtual void setSubLayerVisibility( const QString &name, bool vis )
291  {
292  //prevent unused var warnings
293  if ( name.isEmpty() || !vis )
294  {
295  return;
296  }
297  // NOOP
298  }
299 
300 
316  virtual QString name() const = 0;
317 
318 
331  virtual QString description() const = 0;
332 
333 
344  virtual QString fileVectorFilters() const
345  {
346  return QString();
347  }
348 
349 
360  virtual QString fileRasterFilters() const
361  {
362  return QString();
363  }
364 
369  virtual void reloadData() {}
370 
372  virtual QDateTime timestamp() const { return mTimestamp; }
373 
375  virtual QDateTime dataTimestamp() const { return QDateTime(); }
376 
382  virtual QgsError error() const { return mError; }
383 
388  virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ) }
389 
412  virtual bool enterUpdateMode() { return true; }
413 
431  virtual bool leaveUpdateMode() { return true; }
432 
439  void setProviderProperty( ProviderProperty property, const QVariant &value );
440 
447  void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
448 
455  QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
456 
463  QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
464 
475  virtual void setListening( bool isListening );
476 
477 #ifndef SIP_RUN
478 
485  {
487  double lastRenderingTimeMs = -1;
488 
490  double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
491  };
492 #endif
493 
506  virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
507 
516  virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
517 
526  virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ) return false; }
527 
535  QgsCoordinateTransformContext transformContext() const SIP_SKIP;
536 
547  virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) SIP_SKIP;
548 
549  signals:
550 
557  void fullExtentCalculated();
558 
571  void dataChanged();
572 
580  void notify( const QString &msg );
581 
582 
583  protected:
584 
588  QDateTime mTimestamp;
589 
592 
594  void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
595 
597  void setError( const QgsError &error ) { mError = error;}
598 
599  private:
600 
605  QString mDataSourceURI;
606 
607  QMap< int, QVariant > mProviderProperties;
608 
610 
614  mutable QMutex mOptionsMutex;
615 
616 };
617 
618 
619 #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...
static QString SUBLAYER_SEPARATOR
String sequence used for separating components of sublayers strings.
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.
QDateTime mTimestamp
Timestamp of data in the moment when the data were loaded by provider.
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.
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:189
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
QString uri(bool expandAuthConfig=true) const
Returns the complete URI as a string.
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.
virtual void reloadData()
Reloads the data from the source.
This class represents a coordinate reference system (CRS).
QgsError mError
Error.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:172
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.