QGIS API Documentation  3.0.2-Girona (307d082)
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 
49 class CORE_EXPORT QgsDataProvider : public QObject
50 {
51 
52 #ifdef SIP_RUN
54  if ( qobject_cast<QgsVectorDataProvider *>( sipCpp ) )
55  {
56  sipType = sipType_QgsVectorDataProvider;
57  }
58  else if ( qobject_cast<QgsRasterDataProvider *>( sipCpp ) )
59  {
60  sipType = sipType_QgsRasterDataProvider;
61  }
62  else
63  {
64  sipType = 0;
65  }
66  SIP_END
67 #endif
68  Q_OBJECT
69 
70  public:
71 
73  {
74  NoDataCapabilities = 0,
75  File = 1,
76  Dir = 1 << 1,
77  Database = 1 << 2,
78  Net = 1 << 3 // Internet source
79  };
80  Q_ENUM( DataCapability );
81 
90  {
92  CustomData = 3000
93  };
94 
98  QgsDataProvider( const QString &uri = QString() )
99  : mDataSourceURI( uri )
100  {}
101 
107  virtual QgsCoordinateReferenceSystem crs() const = 0;
108 
109 
115  virtual void setDataSourceUri( const QString &uri )
116  {
117  mDataSourceURI = uri;
118  }
119 
129  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
130  {
131  if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
132  {
133  QgsDataSourceUri uri( mDataSourceURI );
134  return uri.uri( expandAuthConfig );
135  }
136  else
137  {
138  return mDataSourceURI;
139  }
140  }
141 
147  void setUri( const QgsDataSourceUri &uri )
148  {
149  mDataSourceURI = uri.uri( true );
150  }
151 
158  {
159  return QgsDataSourceUri( mDataSourceURI );
160  }
161 
166  virtual QgsRectangle extent() const = 0;
167 
168 
173  virtual bool isValid() const = 0;
174 
175 
179  virtual void updateExtents()
180  {
181  // NOP by default
182  }
183 
184 
191  virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
192  {
193  // NOP by default
194  Q_UNUSED( subset );
195  Q_UNUSED( updateFeatureCount );
196  return false;
197  }
198 
199 
203  virtual bool supportsSubsetString() const { return false; }
204 
211  virtual QString subsetString() const
212  {
213  return QString();
214  }
215 
216 
225  virtual QStringList subLayers() const
226  {
227  return QStringList(); // Empty
228  }
229 
235  static QString SUBLAYER_SEPARATOR;
236 
244  virtual QStringList subLayerStyles() const
245  {
246  return QStringList(); // Empty
247  }
248 
249 
253  virtual uint subLayerCount() const
254  {
255  return 0;
256  }
257 
258 
264  virtual void setLayerOrder( const QStringList &layers )
265  {
266  //prevent unused var warnings
267  if ( layers.count() < 1 )
268  {
269  return;
270  }
271  // NOOP
272  }
273 
274 
278  virtual void setSubLayerVisibility( const QString &name, bool vis )
279  {
280  //prevent unused var warnings
281  if ( name.isEmpty() || !vis )
282  {
283  return;
284  }
285  // NOOP
286  }
287 
288 
304  virtual QString name() const = 0;
305 
306 
319  virtual QString description() const = 0;
320 
321 
332  virtual QString fileVectorFilters() const
333  {
334  return QLatin1String( "" );
335  }
336 
337 
348  virtual QString fileRasterFilters() const
349  {
350  return QLatin1String( "" );
351  }
352 
357  virtual void reloadData() {}
358 
360  virtual QDateTime timestamp() const { return mTimestamp; }
361 
363  virtual QDateTime dataTimestamp() const { return QDateTime(); }
364 
370  virtual QgsError error() const { return mError; }
371 
376  virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ); }
377 
400  virtual bool enterUpdateMode() { return true; }
401 
419  virtual bool leaveUpdateMode() { return true; }
420 
427  void setProviderProperty( ProviderProperty property, const QVariant &value );
428 
435  void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
436 
443  QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
444 
451  QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
452 
463  virtual void setListening( bool isListening );
464 
465 #ifndef SIP_RUN
466 
473  {
475  double lastRenderingTimeMs = -1;
476 
478  double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
479  };
480 #endif
481 
494  virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
495 
504  virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
505 
514  virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ); return false; }
515 
516  signals:
517 
523  void fullExtentCalculated();
524 
532  void dataChanged();
533 
541  void notify( const QString &msg );
542 
543 
544  protected:
545 
549  QDateTime mTimestamp;
550 
553 
555  void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
556 
558  void setError( const QgsError &error ) { mError = error;}
559 
560  private:
561 
566  QString mDataSourceURI;
567 
568  QMap< int, QVariant > mProviderProperties;
569 };
570 
571 
572 #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:39
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
Get current status error.
virtual QString fileRasterFilters() const
Return 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
return the number of layers for the current data source
Abstract base class for spatial data provider implementations.
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
Get the data source specification.
QgsDataSourceUri uri() const
Get the data source specification.
#define SIP_END
Definition: qgis_sip.h:175
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
return complete uri
A structured metadata store for a map layer.
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
Return vector file filter string.
void setError(const QgsError &error)
Set 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.
QgsDataProvider(const QString &uri=QString())
Create a new dataprovider with the specified in the uri.
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.