QGIS API Documentation  2.99.0-Master (b058df7)
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 "qgserror.h"
28 
29 typedef int dataCapabilities_t(); // SIP_SKIP
30 
31 class QgsRectangle;
33 
34 
48 class CORE_EXPORT QgsDataProvider : public QObject
49 {
50 
51 #ifdef SIP_RUN
53  if ( qobject_cast<QgsVectorDataProvider *>( sipCpp ) )
54  {
55  sipType = sipType_QgsVectorDataProvider;
56  }
57  else if ( qobject_cast<QgsRasterDataProvider *>( sipCpp ) )
58  {
59  sipType = sipType_QgsRasterDataProvider;
60  }
61  else
62  {
63  sipType = 0;
64  }
65  SIP_END
66 #endif
67  Q_OBJECT
68 
69  public:
70 
72  {
73  NoDataCapabilities = 0,
74  File = 1,
75  Dir = 1 << 1,
76  Database = 1 << 2,
77  Net = 1 << 3 // Internet source
78  };
79  Q_ENUM( DataCapability );
80 
89  {
91  CustomData = 3000
92  };
93 
97  QgsDataProvider( const QString &uri = QString() )
98  : mDataSourceURI( uri )
99  {}
100 
106  virtual QgsCoordinateReferenceSystem crs() const = 0;
107 
108 
114  virtual void setDataSourceUri( const QString &uri )
115  {
116  mDataSourceURI = uri;
117  }
118 
128  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
129  {
130  if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
131  {
132  QgsDataSourceUri uri( mDataSourceURI );
133  return uri.uri( expandAuthConfig );
134  }
135  else
136  {
137  return mDataSourceURI;
138  }
139  }
140 
146  void setUri( const QgsDataSourceUri &uri )
147  {
148  mDataSourceURI = uri.uri( true );
149  }
150 
157  {
158  return QgsDataSourceUri( mDataSourceURI );
159  }
160 
165  virtual QgsRectangle extent() const = 0;
166 
167 
172  virtual bool isValid() const = 0;
173 
174 
178  virtual void updateExtents()
179  {
180  // NOP by default
181  }
182 
183 
190  virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
191  {
192  // NOP by default
193  Q_UNUSED( subset );
194  Q_UNUSED( updateFeatureCount );
195  return false;
196  }
197 
198 
202  virtual bool supportsSubsetString() const { return false; }
203 
210  virtual QString subsetString() const
211  {
212  return QString();
213  }
214 
215 
222  virtual QStringList subLayers() const
223  {
224  return QStringList(); // Empty
225  }
226 
227 
235  virtual QStringList subLayerStyles() const
236  {
237  return QStringList(); // Empty
238  }
239 
240 
244  virtual uint subLayerCount() const
245  {
246  return 0;
247  }
248 
249 
255  virtual void setLayerOrder( const QStringList &layers )
256  {
257  //prevent unused var warnings
258  if ( layers.count() < 1 )
259  {
260  return;
261  }
262  // NOOP
263  }
264 
265 
269  virtual void setSubLayerVisibility( const QString &name, bool vis )
270  {
271  //prevent unused var warnings
272  if ( name.isEmpty() || !vis )
273  {
274  return;
275  }
276  // NOOP
277  }
278 
279 
295  virtual QString name() const = 0;
296 
297 
310  virtual QString description() const = 0;
311 
312 
323  virtual QString fileVectorFilters() const
324  {
325  return QLatin1String( "" );
326  }
327 
328 
339  virtual QString fileRasterFilters() const
340  {
341  return QLatin1String( "" );
342  }
343 
348  virtual void reloadData() {}
349 
351  virtual QDateTime timestamp() const { return mTimestamp; }
352 
354  virtual QDateTime dataTimestamp() const { return QDateTime(); }
355 
361  virtual QgsError error() const { return mError; }
362 
367  virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ); }
368 
391  virtual bool enterUpdateMode() { return true; }
392 
410  virtual bool leaveUpdateMode() { return true; }
411 
418  void setProviderProperty( ProviderProperty property, const QVariant &value );
419 
426  void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
427 
434  QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
435 
442  QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
443 
454  virtual void setListening( bool isListening );
455 
456  signals:
457 
463  void fullExtentCalculated();
464 
472  void dataChanged();
473 
481  void notify( const QString &msg );
482 
483 
484  protected:
485 
489  QDateTime mTimestamp;
490 
493 
495  void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
496 
498  void setError( const QgsError &error ) { mError = error;}
499 
500  private:
501 
506  QString mDataSourceURI;
507 
508  QMap< int, QVariant > mProviderProperties;
509 };
510 
511 
512 #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...
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 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
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:83
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...
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.
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.