QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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  {
107  };
108 
114  QgsDataProvider( const QString &uri = QString(), const QgsDataProvider::ProviderOptions &providerOptions = QgsDataProvider::ProviderOptions() );
115 
121  virtual QgsCoordinateReferenceSystem crs() const = 0;
122 
128  virtual void setDataSourceUri( const QString &uri )
129  {
130  mDataSourceURI = uri;
131  }
132 
142  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
143  {
144  if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
145  {
146  const QgsDataSourceUri uri( mDataSourceURI );
147  return uri.uri( expandAuthConfig );
148  }
149  else
150  {
151  return mDataSourceURI;
152  }
153  }
154 
162  virtual QString dataComment() const { return QString(); };
163 
164 
170  void setUri( const QgsDataSourceUri &uri )
171  {
172  mDataSourceURI = uri.uri( true );
173  }
174 
181  {
182  return QgsDataSourceUri( mDataSourceURI );
183  }
184 
192  virtual QgsDataProviderTemporalCapabilities *temporalCapabilities();
193 
201  virtual const QgsDataProviderTemporalCapabilities *temporalCapabilities() const SIP_SKIP;
202 
207  virtual QgsRectangle extent() const = 0;
208 
209 
214  virtual bool isValid() const = 0;
215 
216 
220  virtual void updateExtents()
221  {
222  // NOP by default
223  }
224 
225 
232  virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
233  {
234  // NOP by default
235  Q_UNUSED( subset )
236  Q_UNUSED( updateFeatureCount )
237  return false;
238  }
239 
240 
244  virtual bool supportsSubsetString() const { return false; }
245 
252  virtual QString subsetString() const
253  {
254  return QString();
255  }
256 
257 
266  virtual QStringList subLayers() const
267  {
268  return QStringList(); // Empty
269  }
270 
278  virtual QStringList subLayerStyles() const
279  {
280  return QStringList(); // Empty
281  }
282 
283 
287  virtual uint subLayerCount() const
288  {
289  return 0;
290  }
291 
292 
298  virtual void setLayerOrder( const QStringList &layers )
299  {
300  //prevent unused var warnings
301  if ( layers.count() < 1 )
302  {
303  return;
304  }
305  // NOOP
306  }
307 
308 
312  virtual void setSubLayerVisibility( const QString &name, bool vis )
313  {
314  //prevent unused var warnings
315  if ( name.isEmpty() || !vis )
316  {
317  return;
318  }
319  // NOOP
320  }
321 
322 
338  virtual QString name() const = 0;
339 
340 
353  virtual QString description() const = 0;
354 
355 
366  virtual QString fileVectorFilters() const
367  {
368  return QString();
369  }
370 
371 
382  virtual QString fileRasterFilters() const
383  {
384  return QString();
385  }
386 
393  virtual void reloadData();
394 
396  virtual QDateTime timestamp() const { return mTimestamp; }
397 
399  virtual QDateTime dataTimestamp() const { return QDateTime(); }
400 
406  virtual QgsError error() const { return mError; }
407 
412  virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ) }
413 
436  virtual bool enterUpdateMode() { return true; }
437 
455  virtual bool leaveUpdateMode() { return true; }
456 
463  void setProviderProperty( ProviderProperty property, const QVariant &value );
464 
471  void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
472 
479  QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
480 
487  QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
488 
499  virtual void setListening( bool isListening );
500 
501 #ifndef SIP_RUN
502 
509  {
511  double lastRenderingTimeMs = -1;
512 
514  double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
515  };
516 #endif
517 
530  virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
531 
540  virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
541 
550  virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ) return false; }
551 
559  QgsCoordinateTransformContext transformContext() const SIP_SKIP;
560 
571  virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) SIP_SKIP;
572 
579  static QString sublayerSeparator();
580 
581  signals:
582 
589  void fullExtentCalculated();
590 
603  void dataChanged();
604 
612  void notify( const QString &msg );
613 
614 
615  protected:
616 
620  QDateTime mTimestamp;
621 
623  QgsError mError;
624 
626  void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
627 
629  void setError( const QgsError &error ) { mError = error;}
630 
631  private:
632 
637  QString mDataSourceURI;
638 
639  QMap< int, QVariant > mProviderProperties;
640 
642 
646  mutable QMutex mOptionsMutex;
647 
652  virtual void reloadProviderData() {}
653 };
654 
655 
656 #endif
QgsDataSourceUri
Definition: qgsdatasourceuri.h:35
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:278
QgsDataProvider::subLayerCount
virtual uint subLayerCount() const
Returns the number of layers for the current data source.
Definition: qgsdataprovider.h:287
QgsCoordinateTransformContext
Definition: qgscoordinatetransformcontext.h:57
QgsDataProvider::supportsSubsetString
virtual bool supportsSubsetString() const
Returns true if the provider supports setting of subset strings.
Definition: qgsdataprovider.h:244
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:104
QgsDataProvider
Definition: qgsdataprovider.h:41
QgsDataProvider::setSubLayerVisibility
virtual void setSubLayerVisibility(const QString &name, bool vis)
Set the visibility of the given sublayer name.
Definition: qgsdataprovider.h:312
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:232
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:412
QgsDataProvider::error
virtual QgsError error() const
Gets current status error.
Definition: qgsdataprovider.h:406
QgsError
Definition: qgserror.h:80
QgsDataProvider::dataSourceUri
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
Definition: qgsdataprovider.h:142
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:90
QgsRectangle
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:396
QgsDataProviderTemporalCapabilities
Definition: qgsdataprovidertemporalcapabilities.h:33
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:172
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:170
QgsDataProvider::writeLayerMetadata
virtual bool writeLayerMetadata(const QgsLayerMetadata &metadata)
Writes layer metadata to the underlying provider source.
Definition: qgsdataprovider.h:550
QgsDataProvider::enterUpdateMode
virtual bool enterUpdateMode()
Enter update mode.
Definition: qgsdataprovider.h:436
QgsDataProvider::PreviewContext
Stores settings related to the context in which a preview job runs.
Definition: qgsdataprovider.h:508
QgsDataProvider::setError
void setError(const QgsError &error)
Sets error message.
Definition: qgsdataprovider.h:629
QgsErrorMessage
Definition: qgserror.h:32
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
QgsDataProvider::dataTimestamp
virtual QDateTime dataTimestamp() const
Current time stamp of data source.
Definition: qgsdataprovider.h:399
QgsDataProvider::fileVectorFilters
virtual QString fileVectorFilters() const
Returns vector file filter string.
Definition: qgsdataprovider.h:366
QgsDataProvider::setDataSourceUri
virtual void setDataSourceUri(const QString &uri)
Set the data source specification.
Definition: qgsdataprovider.h:128
QgsDataProvider::ProviderOptions::transformContext
QgsCoordinateTransformContext transformContext
Definition: qgsdataprovider.h:106
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:180
QgsDataProvider::leaveUpdateMode
virtual bool leaveUpdateMode()
Leave update mode.
Definition: qgsdataprovider.h:455
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:252
QgsDataProvider::layerMetadata
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider's source.
Definition: qgsdataprovider.h:540
QgsDataProvider::dataComment
virtual QString dataComment() const
Returns a short comment for the data that this provider is providing access to (e....
Definition: qgsdataprovider.h:162
SIP_END
#define SIP_END
Definition: qgis_sip.h:189
QgsDataProvider::DataCapability
DataCapability
Used in browser model to understand which items for which providers should be populated.
Definition: qgsdataprovider.h:73
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:298
QgsDataProvider::fileRasterFilters
virtual QString fileRasterFilters() const
Returns raster file filter string.
Definition: qgsdataprovider.h:382
QgsDataProvider::subLayers
virtual QStringList subLayers() const
Sub-layers handled by this provider, in order from bottom to top.
Definition: qgsdataprovider.h:266