QGIS API Documentation  2.99.0-Master (ba079d8)
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 
70  Q_ENUMS( DataCapability )
71 
73  {
74  NoDataCapabilities = 0,
75  File = 1,
76  Dir = 1 << 1,
77  Database = 1 << 2,
78  Net = 1 << 3 // Internet source
79  };
80 
89  {
91  CustomData = 3000
92  };
93 
97  QgsDataProvider( const QString &uri = QString() )
98  : mDataSourceURI( uri )
99  {}
100 
105  virtual QgsCoordinateReferenceSystem crs() const = 0;
106 
107 
113  virtual void setDataSourceUri( const QString &uri )
114  {
115  mDataSourceURI = uri;
116  }
117 
127  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
128  {
129  if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
130  {
131  QgsDataSourceUri uri( mDataSourceURI );
132  return uri.uri( expandAuthConfig );
133  }
134  else
135  {
136  return mDataSourceURI;
137  }
138  }
139 
145  void setUri( const QgsDataSourceUri &uri )
146  {
147  mDataSourceURI = uri.uri( true );
148  }
149 
156  {
157  return QgsDataSourceUri( mDataSourceURI );
158  }
159 
164  virtual QgsRectangle extent() const = 0;
165 
166 
171  virtual bool isValid() const = 0;
172 
173 
177  virtual void updateExtents()
178  {
179  // NOP by default
180  }
181 
182 
189  virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
190  {
191  // NOP by default
192  Q_UNUSED( subset );
193  Q_UNUSED( updateFeatureCount );
194  return false;
195  }
196 
197 
200  virtual bool supportsSubsetString() const { return false; }
201 
208  virtual QString subsetString() const
209  {
210  return QString::null;
211  }
212 
213 
220  virtual QStringList subLayers() const
221  {
222  return QStringList(); // Empty
223  }
224 
225 
233  virtual QStringList subLayerStyles() const
234  {
235  return QStringList(); // Empty
236  }
237 
238 
242  virtual uint subLayerCount() const
243  {
244  return 0;
245  }
246 
247 
253  virtual void setLayerOrder( const QStringList &layers )
254  {
255  //prevent unused var warnings
256  if ( layers.count() < 1 )
257  {
258  return;
259  }
260  // NOOP
261  }
262 
263 
267  virtual void setSubLayerVisibility( const QString &name, bool vis )
268  {
269  //prevent unused var warnings
270  if ( name.isEmpty() || !vis )
271  {
272  return;
273  }
274  // NOOP
275  }
276 
277 
292  virtual QString name() const = 0;
293 
294 
306  virtual QString description() const = 0;
307 
308 
318  virtual QString fileVectorFilters() const
319  {
320  return QLatin1String( "" );
321  }
322 
323 
333  virtual QString fileRasterFilters() const
334  {
335  return QLatin1String( "" );
336  }
337 
341  virtual void reloadData() {}
342 
344  virtual QDateTime timestamp() const { return mTimestamp; }
345 
347  virtual QDateTime dataTimestamp() const { return QDateTime(); }
348 
353  virtual QgsError error() const { return mError; }
354 
358  virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ); }
359 
381  virtual bool enterUpdateMode() { return true; }
382 
399  virtual bool leaveUpdateMode() { return true; }
400 
407  void setProviderProperty( ProviderProperty property, const QVariant &value );
408 
415  void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
416 
423  QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
424 
431  QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
432 
433  signals:
434 
440  void fullExtentCalculated();
441 
449  void dataChanged();
450 
451  protected:
452 
456  QDateTime mTimestamp;
457 
460 
462  void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
463 
465  void setError( const QgsError &error ) { mError = error;}
466 
467  private:
468 
473  QString mDataSourceURI;
474 
475  QMap< int, QVariant > mProviderProperties;
476 };
477 
478 
479 #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:148
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:143
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.