QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 <QDateTime>
20 #include <QObject>
21 #include <QString>
22 #include <QStringList>
23 
24 //#include "qgsdataitem.h"
25 #include "qgsdatasourceuri.h"
26 #include "qgserror.h"
27 
28 typedef int dataCapabilities_t();
29 
30 class QgsRectangle;
32 
33 
47 class CORE_EXPORT QgsDataProvider : public QObject
48 {
49  Q_OBJECT
50 
51  public:
52 
53  Q_ENUMS( DataCapability )
54 
56  {
57  NoDataCapabilities = 0,
58  File = 1,
59  Dir = 1 << 1,
60  Database = 1 << 2,
61  Net = 1 << 3 // Internet source
62  };
63 
72  {
74  CustomData = 3000
75  };
76 
77  QgsDataProvider( QString const & uri = "" )
78  : mDataSourceURI( uri )
79  {}
80 
84  virtual ~QgsDataProvider() {}
85 
86 
92  virtual QgsCoordinateReferenceSystem crs() = 0;
93 
94 
100  virtual void setDataSourceUri( const QString & uri )
101  {
102  mDataSourceURI = uri;
103  }
104 
114  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
115  {
116  if ( expandAuthConfig && mDataSourceURI.contains( "authcfg" ) )
117  {
118  QgsDataSourceURI uri( mDataSourceURI );
119  return uri.uri( expandAuthConfig );
120  }
121  else
122  {
123  return mDataSourceURI;
124  }
125  }
126 
127 
132  virtual QgsRectangle extent() = 0;
133 
134 
139  virtual bool isValid() = 0;
140 
141 
145  virtual void updateExtents()
146  {
147  // NOP by default
148  }
149 
150 
157  virtual bool setSubsetString( const QString& subset, bool updateFeatureCount = true )
158  {
159  // NOP by default
160  Q_UNUSED( subset );
161  Q_UNUSED( updateFeatureCount );
162  return false;
163  }
164 
165 
167  virtual bool supportsSubsetString() { return false; }
168 
176  {
177  return QString::null;
178  }
179 
180 
187  virtual QStringList subLayers() const
188  {
189  return QStringList(); // Empty
190  }
191 
192 
200  virtual QStringList subLayerStyles() const
201  {
202  return QStringList(); // Empty
203  }
204 
205 
209  virtual uint subLayerCount() const
210  {
211  return 0;
212  }
213 
214 
220  virtual void setLayerOrder( const QStringList &layers )
221  {
222  //prevent unused var warnings
223  if ( layers.count() < 1 )
224  {
225  return;
226  }
227  // NOOP
228  }
229 
230 
234  virtual void setSubLayerVisibility( const QString &name, bool vis )
235  {
236  //prevent unused var warnings
237  if ( name.isEmpty() || !vis )
238  {
239  return;
240  }
241  // NOOP
242  }
243 
244 
259  virtual QString name() const = 0;
260 
261 
273  virtual QString description() const = 0;
274 
275 
285  virtual QString fileVectorFilters() const
286  {
287  return "";
288  }
289 
290 
300  virtual QString fileRasterFilters() const
301  {
302  return "";
303  }
304 
308  virtual void reloadData() {}
309 
311  virtual QDateTime timestamp() const { return mTimestamp; }
312 
314  virtual QDateTime dataTimestamp() const { return QDateTime(); }
315 
320  virtual QgsError error() const { return mError; }
321 
325  virtual void invalidateConnections( const QString& connection ) { Q_UNUSED( connection ); }
326 
348  virtual bool enterUpdateMode() { return true; }
349 
366  virtual bool leaveUpdateMode() { return true; }
367 
374  void setProviderProperty( ProviderProperty property, const QVariant& value );
375 
382  void setProviderProperty( int property, const QVariant& value );
383 
390  QVariant providerProperty( ProviderProperty property, const QVariant& defaultValue = QVariant() ) const;
391 
398  QVariant providerProperty( int property , const QVariant& defaultValue ) const;
399 
400  signals:
401 
407  void fullExtentCalculated();
408 
416  void dataChanged();
417 
422  void dataChanged( int changed );
423 
424  protected:
429 
432 
434  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
435 
437  void setError( const QgsError & theError ) { mError = theError;}
438 
439  private:
440 
445  QString mDataSourceURI;
446 
447  QMap< int, QVariant > mProviderProperties;
448 };
449 
450 
451 #endif
virtual void setSubLayerVisibility(const QString &name, bool vis)
Set the visibility of the given sublayer name.
virtual QString subsetString()
Returns the subset definition string (typically sql) currently in use by the layer and used by the pr...
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:35
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.
virtual bool supportsSubsetString()
Provider supports setting of subset strings.
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.
void setError(const QgsError &theError)
Set error message.
const char * name() const
int count(const T &value) const
QgsDataProvider(QString const &uri="")
virtual QDateTime dataTimestamp() const
Current time stamp of data source.
bool isEmpty() const
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Get the data source specification.
virtual void setLayerOrder(const QStringList &layers)
Reorder the list of layer names to be rendered by this provider (in order from bottom to top) ...
QString uri(bool expandAuthConfig=true) const
return complete uri
QgsErrorMessage represents single error message.
Definition: qgserror.h:29
virtual void setDataSourceUri(const QString &uri)
Set the data source specification.
Class for storing the component parts of a PostgreSQL/RDBMS datasource 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:80
void append(const QString &theMessage, const QString &theTag)
Append new error message.
Definition: qgserror.cpp:40
virtual QString fileVectorFilters() const
Return vector file filter string.
virtual void reloadData()
Reloads the data from the source.
Class for storing a coordinate reference system (CRS)
QgsError mError
Error.
virtual bool enterUpdateMode()
Enter update mode.
void appendError(const QgsErrorMessage &theMessage)
Add error message.
virtual QStringList subLayerStyles() const
Sub-layer styles for each sub-layer handled by this provider, in order from bottom to top...
virtual void invalidateConnections(const QString &connection)
Invalidate connections corresponding to specified name.
virtual ~QgsDataProvider()
We need this so the subclass destructors get called.
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.