QGIS API Documentation  2.99.0-Master (314842d)
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();
30 
31 class QgsRectangle;
33 
34 
48 class CORE_EXPORT QgsDataProvider : public QObject
49 {
50  Q_OBJECT
51 
52  public:
53 
54  Q_ENUMS( DataCapability )
55 
57  {
58  NoDataCapabilities = 0,
59  File = 1,
60  Dir = 1 << 1,
61  Database = 1 << 2,
62  Net = 1 << 3 // Internet source
63  };
64 
73  {
75  CustomData = 3000
76  };
77 
78  QgsDataProvider( QString const &uri = "" )
79  : mDataSourceURI( uri )
80  {}
81 
86  virtual QgsCoordinateReferenceSystem crs() const = 0;
87 
88 
94  virtual void setDataSourceUri( const QString &uri )
95  {
96  mDataSourceURI = uri;
97  }
98 
108  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
109  {
110  if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
111  {
112  QgsDataSourceUri uri( mDataSourceURI );
113  return uri.uri( expandAuthConfig );
114  }
115  else
116  {
117  return mDataSourceURI;
118  }
119  }
120 
121 
126  virtual QgsRectangle extent() const = 0;
127 
128 
133  virtual bool isValid() const = 0;
134 
135 
139  virtual void updateExtents()
140  {
141  // NOP by default
142  }
143 
144 
151  virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
152  {
153  // NOP by default
154  Q_UNUSED( subset );
155  Q_UNUSED( updateFeatureCount );
156  return false;
157  }
158 
159 
162  virtual bool supportsSubsetString() const { return false; }
163 
170  virtual QString subsetString() const
171  {
172  return QString::null;
173  }
174 
175 
182  virtual QStringList subLayers() const
183  {
184  return QStringList(); // Empty
185  }
186 
187 
195  virtual QStringList subLayerStyles() const
196  {
197  return QStringList(); // Empty
198  }
199 
200 
204  virtual uint subLayerCount() const
205  {
206  return 0;
207  }
208 
209 
215  virtual void setLayerOrder( const QStringList &layers )
216  {
217  //prevent unused var warnings
218  if ( layers.count() < 1 )
219  {
220  return;
221  }
222  // NOOP
223  }
224 
225 
229  virtual void setSubLayerVisibility( const QString &name, bool vis )
230  {
231  //prevent unused var warnings
232  if ( name.isEmpty() || !vis )
233  {
234  return;
235  }
236  // NOOP
237  }
238 
239 
254  virtual QString name() const = 0;
255 
256 
268  virtual QString description() const = 0;
269 
270 
280  virtual QString fileVectorFilters() const
281  {
282  return QLatin1String( "" );
283  }
284 
285 
295  virtual QString fileRasterFilters() const
296  {
297  return QLatin1String( "" );
298  }
299 
303  virtual void reloadData() {}
304 
306  virtual QDateTime timestamp() const { return mTimestamp; }
307 
309  virtual QDateTime dataTimestamp() const { return QDateTime(); }
310 
315  virtual QgsError error() const { return mError; }
316 
320  virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ); }
321 
343  virtual bool enterUpdateMode() { return true; }
344 
361  virtual bool leaveUpdateMode() { return true; }
362 
369  void setProviderProperty( ProviderProperty property, const QVariant &value );
370 
377  void setProviderProperty( int property, const QVariant &value );
378 
385  QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
386 
393  QVariant providerProperty( int property, const QVariant &defaultValue ) const;
394 
395  signals:
396 
402  void fullExtentCalculated();
403 
411  void dataChanged();
412 
413  protected:
414 
418  QDateTime mTimestamp;
419 
422 
424  void appendError( const QgsErrorMessage &message ) { mError.append( message );}
425 
427  void setError( const QgsError &error ) { mError = error;}
428 
429  private:
430 
435  QString mDataSourceURI;
436 
437  QMap< int, QVariant > mProviderProperties;
438 };
439 
440 
441 #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:36
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.
QgsDataProvider(QString const &uri="")
virtual QDateTime dataTimestamp() const
Current time stamp of data source.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Get the data source specification.
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.
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.
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.