QGIS API Documentation  2.99.0-Master (9caa722)
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 
47 class CORE_EXPORT QgsDataProvider : public QObject
48 {
49 
50 #ifdef SIP_RUN
52  if ( qobject_cast<QgsVectorDataProvider *>( sipCpp ) )
53  {
54  sipType = sipType_QgsVectorDataProvider;
55  }
56  else if ( qobject_cast<QgsRasterDataProvider *>( sipCpp ) )
57  {
58  sipType = sipType_QgsRasterDataProvider;
59  }
60  else
61  {
62  sipType = 0;
63  }
64  SIP_END
65 #endif
66  Q_OBJECT
67 
68  public:
69 
71  {
72  NoDataCapabilities = 0,
73  File = 1,
74  Dir = 1 << 1,
75  Database = 1 << 2,
76  Net = 1 << 3 // Internet source
77  };
78  Q_ENUM( DataCapability );
79 
88  {
90  CustomData = 3000
91  };
92 
96  QgsDataProvider( const QString &uri = QString() )
97  : mDataSourceURI( uri )
98  {}
99 
104  virtual QgsCoordinateReferenceSystem crs() const = 0;
105 
106 
112  virtual void setDataSourceUri( const QString &uri )
113  {
114  mDataSourceURI = uri;
115  }
116 
126  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
127  {
128  if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
129  {
130  QgsDataSourceUri uri( mDataSourceURI );
131  return uri.uri( expandAuthConfig );
132  }
133  else
134  {
135  return mDataSourceURI;
136  }
137  }
138 
144  void setUri( const QgsDataSourceUri &uri )
145  {
146  mDataSourceURI = uri.uri( true );
147  }
148 
155  {
156  return QgsDataSourceUri( mDataSourceURI );
157  }
158 
163  virtual QgsRectangle extent() const = 0;
164 
165 
170  virtual bool isValid() const = 0;
171 
172 
176  virtual void updateExtents()
177  {
178  // NOP by default
179  }
180 
181 
188  virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
189  {
190  // NOP by default
191  Q_UNUSED( subset );
192  Q_UNUSED( updateFeatureCount );
193  return false;
194  }
195 
196 
199  virtual bool supportsSubsetString() const { return false; }
200 
207  virtual QString subsetString() const
208  {
209  return QString();
210  }
211 
212 
219  virtual QStringList subLayers() const
220  {
221  return QStringList(); // Empty
222  }
223 
224 
232  virtual QStringList subLayerStyles() const
233  {
234  return QStringList(); // Empty
235  }
236 
237 
241  virtual uint subLayerCount() const
242  {
243  return 0;
244  }
245 
246 
252  virtual void setLayerOrder( const QStringList &layers )
253  {
254  //prevent unused var warnings
255  if ( layers.count() < 1 )
256  {
257  return;
258  }
259  // NOOP
260  }
261 
262 
266  virtual void setSubLayerVisibility( const QString &name, bool vis )
267  {
268  //prevent unused var warnings
269  if ( name.isEmpty() || !vis )
270  {
271  return;
272  }
273  // NOOP
274  }
275 
276 
291  virtual QString name() const = 0;
292 
293 
305  virtual QString description() const = 0;
306 
307 
317  virtual QString fileVectorFilters() const
318  {
319  return QLatin1String( "" );
320  }
321 
322 
332  virtual QString fileRasterFilters() const
333  {
334  return QLatin1String( "" );
335  }
336 
340  virtual void reloadData() {}
341 
343  virtual QDateTime timestamp() const { return mTimestamp; }
344 
346  virtual QDateTime dataTimestamp() const { return QDateTime(); }
347 
352  virtual QgsError error() const { return mError; }
353 
357  virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ); }
358 
380  virtual bool enterUpdateMode() { return true; }
381 
398  virtual bool leaveUpdateMode() { return true; }
399 
406  void setProviderProperty( ProviderProperty property, const QVariant &value );
407 
414  void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
415 
422  QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
423 
430  QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
431 
432  signals:
433 
439  void fullExtentCalculated();
440 
448  void dataChanged();
449 
450  protected:
451 
455  QDateTime mTimestamp;
456 
459 
461  void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
462 
464  void setError( const QgsError &error ) { mError = error;}
465 
466  private:
467 
472  QString mDataSourceURI;
473 
474  QMap< int, QVariant > mProviderProperties;
475 };
476 
477 
478 #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:38
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:31
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:40
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:82
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.