QGIS API Documentation  2.99.0-Master (6c64c5a)
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 
48 class CORE_EXPORT QgsDataProvider : public QObject
49 {
50 
51 #ifdef SIP_RUN
53  if ( qobject_cast<QgsVectorDataProvider *>( sipCpp ) )
54  {
55  sipType = sipType_QgsVectorDataProvider;
56  }
57  else if ( qobject_cast<QgsRasterDataProvider *>( sipCpp ) )
58  {
59  sipType = sipType_QgsRasterDataProvider;
60  }
61  else
62  {
63  sipType = 0;
64  }
65  SIP_END
66 #endif
67  Q_OBJECT
68 
69  public:
70 
72  {
73  NoDataCapabilities = 0,
74  File = 1,
75  Dir = 1 << 1,
76  Database = 1 << 2,
77  Net = 1 << 3 // Internet source
78  };
79  Q_ENUM( DataCapability );
80 
89  {
91  CustomData = 3000
92  };
93 
97  QgsDataProvider( const QString &uri = QString() )
98  : mDataSourceURI( uri )
99  {}
100 
106  virtual QgsCoordinateReferenceSystem crs() const = 0;
107 
108 
114  virtual void setDataSourceUri( const QString &uri )
115  {
116  mDataSourceURI = uri;
117  }
118 
128  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
129  {
130  if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
131  {
132  QgsDataSourceUri uri( mDataSourceURI );
133  return uri.uri( expandAuthConfig );
134  }
135  else
136  {
137  return mDataSourceURI;
138  }
139  }
140 
146  void setUri( const QgsDataSourceUri &uri )
147  {
148  mDataSourceURI = uri.uri( true );
149  }
150 
157  {
158  return QgsDataSourceUri( mDataSourceURI );
159  }
160 
165  virtual QgsRectangle extent() const = 0;
166 
167 
172  virtual bool isValid() const = 0;
173 
174 
178  virtual void updateExtents()
179  {
180  // NOP by default
181  }
182 
183 
190  virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
191  {
192  // NOP by default
193  Q_UNUSED( subset );
194  Q_UNUSED( updateFeatureCount );
195  return false;
196  }
197 
198 
202  virtual bool supportsSubsetString() const { return false; }
203 
210  virtual QString subsetString() const
211  {
212  return QString();
213  }
214 
215 
224  virtual QStringList subLayers() const
225  {
226  return QStringList(); // Empty
227  }
228 
234  static QString SUBLAYER_SEPARATOR;
235 
243  virtual QStringList subLayerStyles() const
244  {
245  return QStringList(); // Empty
246  }
247 
248 
252  virtual uint subLayerCount() const
253  {
254  return 0;
255  }
256 
257 
263  virtual void setLayerOrder( const QStringList &layers )
264  {
265  //prevent unused var warnings
266  if ( layers.count() < 1 )
267  {
268  return;
269  }
270  // NOOP
271  }
272 
273 
277  virtual void setSubLayerVisibility( const QString &name, bool vis )
278  {
279  //prevent unused var warnings
280  if ( name.isEmpty() || !vis )
281  {
282  return;
283  }
284  // NOOP
285  }
286 
287 
303  virtual QString name() const = 0;
304 
305 
318  virtual QString description() const = 0;
319 
320 
331  virtual QString fileVectorFilters() const
332  {
333  return QLatin1String( "" );
334  }
335 
336 
347  virtual QString fileRasterFilters() const
348  {
349  return QLatin1String( "" );
350  }
351 
356  virtual void reloadData() {}
357 
359  virtual QDateTime timestamp() const { return mTimestamp; }
360 
362  virtual QDateTime dataTimestamp() const { return QDateTime(); }
363 
369  virtual QgsError error() const { return mError; }
370 
375  virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ); }
376 
399  virtual bool enterUpdateMode() { return true; }
400 
418  virtual bool leaveUpdateMode() { return true; }
419 
426  void setProviderProperty( ProviderProperty property, const QVariant &value );
427 
434  void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
435 
442  QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
443 
450  QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
451 
462  virtual void setListening( bool isListening );
463 
464 #ifndef SIP_RUN
465 
472  {
474  double lastRenderingTimeMs = -1;
475 
477  double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
478  };
479 #endif
480 
493  virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
494 
495  signals:
496 
502  void fullExtentCalculated();
503 
511  void dataChanged();
512 
520  void notify( const QString &msg );
521 
522 
523  protected:
524 
528  QDateTime mTimestamp;
529 
532 
534  void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
535 
537  void setError( const QgsError &error ) { mError = error;}
538 
539  private:
540 
545  QString mDataSourceURI;
546 
547  QMap< int, QVariant > mProviderProperties;
548 };
549 
550 
551 #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:39
virtual QString subsetString() const
Returns the subset definition string (typically sql) currently in use by the layer and used by the pr...
static QString SUBLAYER_SEPARATOR
String sequence used for separating components of sublayers strings.
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:32
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:39
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:83
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.
Stores settings related to the context in which a preview job runs.
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.