QGIS API Documentation  3.6.0-Noosa (5873452)
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 
25 //#include "qgsdataitem.h"
26 #include "qgsdatasourceuri.h"
27 #include "qgslayermetadata.h"
28 #include "qgserror.h"
29 
30 typedef int dataCapabilities_t(); // SIP_SKIP
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 
68  {
69  NoDataCapabilities = 0,
70  File = 1,
71  Dir = 1 << 1,
72  Database = 1 << 2,
73  Net = 1 << 3 // Internet source
74  };
75  Q_ENUM( DataCapability )
76 
77 
85  {
87  CustomData = 3000
88  };
89 
90 
96  {
97  int unused;
98  };
99 
105  QgsDataProvider( const QString &uri = QString(), const QgsDataProvider::ProviderOptions &options = QgsDataProvider::ProviderOptions() )
106  : mDataSourceURI( uri )
107  {
108  Q_UNUSED( options );
109  }
110 
116  virtual QgsCoordinateReferenceSystem crs() const = 0;
117 
118 
124  virtual void setDataSourceUri( const QString &uri )
125  {
126  mDataSourceURI = uri;
127  }
128 
138  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
139  {
140  if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
141  {
142  QgsDataSourceUri uri( mDataSourceURI );
143  return uri.uri( expandAuthConfig );
144  }
145  else
146  {
147  return mDataSourceURI;
148  }
149  }
150 
156  void setUri( const QgsDataSourceUri &uri )
157  {
158  mDataSourceURI = uri.uri( true );
159  }
160 
167  {
168  return QgsDataSourceUri( mDataSourceURI );
169  }
170 
175  virtual QgsRectangle extent() const = 0;
176 
177 
182  virtual bool isValid() const = 0;
183 
184 
188  virtual void updateExtents()
189  {
190  // NOP by default
191  }
192 
193 
200  virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
201  {
202  // NOP by default
203  Q_UNUSED( subset );
204  Q_UNUSED( updateFeatureCount );
205  return false;
206  }
207 
208 
212  virtual bool supportsSubsetString() const { return false; }
213 
220  virtual QString subsetString() const
221  {
222  return QString();
223  }
224 
225 
234  virtual QStringList subLayers() const
235  {
236  return QStringList(); // Empty
237  }
238 
244  static QString SUBLAYER_SEPARATOR;
245 
253  virtual QStringList subLayerStyles() const
254  {
255  return QStringList(); // Empty
256  }
257 
258 
262  virtual uint subLayerCount() const
263  {
264  return 0;
265  }
266 
267 
273  virtual void setLayerOrder( const QStringList &layers )
274  {
275  //prevent unused var warnings
276  if ( layers.count() < 1 )
277  {
278  return;
279  }
280  // NOOP
281  }
282 
283 
287  virtual void setSubLayerVisibility( const QString &name, bool vis )
288  {
289  //prevent unused var warnings
290  if ( name.isEmpty() || !vis )
291  {
292  return;
293  }
294  // NOOP
295  }
296 
297 
313  virtual QString name() const = 0;
314 
315 
328  virtual QString description() const = 0;
329 
330 
341  virtual QString fileVectorFilters() const
342  {
343  return QString();
344  }
345 
346 
357  virtual QString fileRasterFilters() const
358  {
359  return QString();
360  }
361 
366  virtual void reloadData() {}
367 
369  virtual QDateTime timestamp() const { return mTimestamp; }
370 
372  virtual QDateTime dataTimestamp() const { return QDateTime(); }
373 
379  virtual QgsError error() const { return mError; }
380 
385  virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ); }
386 
409  virtual bool enterUpdateMode() { return true; }
410 
428  virtual bool leaveUpdateMode() { return true; }
429 
436  void setProviderProperty( ProviderProperty property, const QVariant &value );
437 
444  void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
445 
452  QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
453 
460  QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
461 
472  virtual void setListening( bool isListening );
473 
474 #ifndef SIP_RUN
475 
482  {
484  double lastRenderingTimeMs = -1;
485 
487  double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
488  };
489 #endif
490 
503  virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
504 
513  virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
514 
523  virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ); return false; }
524 
525  signals:
526 
533  void fullExtentCalculated();
534 
547  void dataChanged();
548 
556  void notify( const QString &msg );
557 
558 
559  protected:
560 
564  QDateTime mTimestamp;
565 
568 
570  void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
571 
573  void setError( const QgsError &error ) { mError = error;}
574 
575  private:
576 
581  QString mDataSourceURI;
582 
583  QMap< int, QVariant > mProviderProperties;
584 };
585 
586 
587 #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.
QgsDataProvider(const QString &uri=QString(), const QgsDataProvider::ProviderOptions &options=QgsDataProvider::ProviderOptions())
Create a new dataprovider with the specified in the uri.
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
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider&#39;s source.
virtual QDateTime dataTimestamp() const
Current time stamp of data source.
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:182
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
QString uri(bool expandAuthConfig=true) const
Returns complete uri.
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:165
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 PostgreSQL/RDBMS datasource URI.
virtual void invalidateConnections(const QString &connection)
Invalidate connections corresponding to specified name.
Stores settings related to the context in which a preview job runs.
int dataCapabilities_t()
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.