QGIS API Documentation  2.13.0-Master
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 
64  QgsDataProvider( QString const & uri = "" )
65  : mDataSourceURI( uri )
66  {}
67 
71  virtual ~QgsDataProvider() {}
72 
73 
79  virtual QgsCoordinateReferenceSystem crs() = 0;
80 
81 
87  virtual void setDataSourceUri( const QString & uri )
88  {
89  mDataSourceURI = uri;
90  }
91 
101  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
102  {
103  if ( expandAuthConfig && mDataSourceURI.contains( "authcfg" ) )
104  {
105  QgsDataSourceURI uri( mDataSourceURI );
106  return uri.uri( expandAuthConfig );
107  }
108  else
109  {
110  return mDataSourceURI;
111  }
112  }
113 
114 
119  virtual QgsRectangle extent() = 0;
120 
121 
126  virtual bool isValid() = 0;
127 
128 
132  virtual void updateExtents()
133  {
134  // NOP by default
135  }
136 
137 
144  virtual bool setSubsetString( const QString& subset, bool updateFeatureCount = true )
145  {
146  // NOP by default
147  Q_UNUSED( subset );
148  Q_UNUSED( updateFeatureCount );
149  return false;
150  }
151 
152 
154  virtual bool supportsSubsetString() { return false; }
155 
163  {
164  return QString::null;
165  }
166 
167 
174  virtual QStringList subLayers() const
175  {
176  return QStringList(); // Empty
177  }
178 
179 
187  virtual QStringList subLayerStyles() const
188  {
189  return QStringList(); // Empty
190  }
191 
192 
196  virtual uint subLayerCount() const
197  {
198  return 0;
199  }
200 
201 
207  virtual void setLayerOrder( const QStringList &layers )
208  {
209  //prevent unused var warnings
210  if ( layers.count() < 1 )
211  {
212  return;
213  }
214  // NOOP
215  }
216 
217 
221  virtual void setSubLayerVisibility( const QString &name, bool vis )
222  {
223  //prevent unused var warnings
224  if ( name.isEmpty() || !vis )
225  {
226  return;
227  }
228  // NOOP
229  }
230 
231 
246  virtual QString name() const = 0;
247 
248 
260  virtual QString description() const = 0;
261 
262 
274  virtual QString fileVectorFilters() const
275  {
276  return "";
277  }
278 
279 
291  virtual QString fileRasterFilters() const
292  {
293  return "";
294  }
295 
298  virtual void reloadData() {}
299 
301  virtual QDateTime timestamp() const { return mTimestamp; }
302 
304  virtual QDateTime dataTimestamp() const { return QDateTime(); }
305 
310  virtual QgsError error() const { return mError; }
311 
312  signals:
313 
319  void fullExtentCalculated();
320 
328  void dataChanged();
329 
334  void dataChanged( int changed );
335 
336  protected:
341 
344 
346  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
347 
349  void setError( const QgsError & theError ) { mError = theError;}
350 
351  private:
352 
357  QString mDataSourceURI;
358 };
359 
360 
361 #endif
virtual uint subLayerCount() const
return the number of layers for the current data source
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 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.
Abstract base class for spatial data provider implementations.
void setError(const QgsError &theError)
Set error message.
virtual QString fileVectorFilters() const
Return vector file filter string.
virtual QDateTime dataTimestamp() const
Current time stamp of data source.
virtual QStringList subLayers() const
Sub-layers handled by this provider, in order from bottom to top.
const char * name() const
int count(const T &value) const
QgsDataProvider(QString const &uri="")
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
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) ...
QgsErrorMessage represents single error message.
Definition: qgserror.h:29
virtual void setDataSourceUri(const QString &uri)
Set the data source specification.
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.
QgsError is container for error messages (report).
Definition: qgserror.h:77
void append(const QString &theMessage, const QString &theTag)
Append new error message.
Definition: qgserror.cpp:40
virtual void reloadData()
Reloads the data from the source.
Class for storing a coordinate reference system (CRS)
QgsError mError
Error.
void appendError(const QgsErrorMessage &theMessage)
Add error message.
virtual ~QgsDataProvider()
We need this so the subclass destructors get called.
QString uri(bool expandAuthConfig=true) const
return complete uri
int dataCapabilities_t()
virtual QgsError error() const
Get current status error.