QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 "qgslayermetadata.h"
28 #include "qgserror.h"
29 
30 typedef int dataCapabilities_t(); // SIP_SKIP
31 
32 class QgsRectangle;
34 
35 
49 class CORE_EXPORT QgsDataProvider : public QObject
50 {
51 
52 #ifdef SIP_RUN
54  if ( qobject_cast<QgsVectorDataProvider *>( sipCpp ) )
55  {
56  sipType = sipType_QgsVectorDataProvider;
57  }
58  else if ( qobject_cast<QgsRasterDataProvider *>( sipCpp ) )
59  {
60  sipType = sipType_QgsRasterDataProvider;
61  }
62  else if ( qobject_cast<QgsMeshDataProvider *>( sipCpp ) )
63  {
64  sipType = sipType_QgsMeshDataProvider;
65  }
66  else
67  {
68  sipType = 0;
69  }
70  SIP_END
71 #endif
72  Q_OBJECT
73 
74  public:
75 
77  {
78  NoDataCapabilities = 0,
79  File = 1,
80  Dir = 1 << 1,
81  Database = 1 << 2,
82  Net = 1 << 3 // Internet source
83  };
84  Q_ENUM( DataCapability )
85 
86 
94  {
96  CustomData = 3000
97  };
98 
99 
105  {
106  int unused;
107  };
108 
114  QgsDataProvider( const QString &uri = QString(), const QgsDataProvider::ProviderOptions &options = QgsDataProvider::ProviderOptions() )
115  : mDataSourceURI( uri )
116  {
117  Q_UNUSED( options );
118  }
119 
125  virtual QgsCoordinateReferenceSystem crs() const = 0;
126 
127 
133  virtual void setDataSourceUri( const QString &uri )
134  {
135  mDataSourceURI = uri;
136  }
137 
147  virtual QString dataSourceUri( bool expandAuthConfig = false ) const
148  {
149  if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
150  {
151  QgsDataSourceUri uri( mDataSourceURI );
152  return uri.uri( expandAuthConfig );
153  }
154  else
155  {
156  return mDataSourceURI;
157  }
158  }
159 
165  void setUri( const QgsDataSourceUri &uri )
166  {
167  mDataSourceURI = uri.uri( true );
168  }
169 
176  {
177  return QgsDataSourceUri( mDataSourceURI );
178  }
179 
184  virtual QgsRectangle extent() const = 0;
185 
186 
191  virtual bool isValid() const = 0;
192 
193 
197  virtual void updateExtents()
198  {
199  // NOP by default
200  }
201 
202 
209  virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
210  {
211  // NOP by default
212  Q_UNUSED( subset );
213  Q_UNUSED( updateFeatureCount );
214  return false;
215  }
216 
217 
221  virtual bool supportsSubsetString() const { return false; }
222 
229  virtual QString subsetString() const
230  {
231  return QString();
232  }
233 
234 
243  virtual QStringList subLayers() const
244  {
245  return QStringList(); // Empty
246  }
247 
253  static QString SUBLAYER_SEPARATOR;
254 
262  virtual QStringList subLayerStyles() const
263  {
264  return QStringList(); // Empty
265  }
266 
267 
271  virtual uint subLayerCount() const
272  {
273  return 0;
274  }
275 
276 
282  virtual void setLayerOrder( const QStringList &layers )
283  {
284  //prevent unused var warnings
285  if ( layers.count() < 1 )
286  {
287  return;
288  }
289  // NOOP
290  }
291 
292 
296  virtual void setSubLayerVisibility( const QString &name, bool vis )
297  {
298  //prevent unused var warnings
299  if ( name.isEmpty() || !vis )
300  {
301  return;
302  }
303  // NOOP
304  }
305 
306 
322  virtual QString name() const = 0;
323 
324 
337  virtual QString description() const = 0;
338 
339 
350  virtual QString fileVectorFilters() const
351  {
352  return QString();
353  }
354 
355 
366  virtual QString fileRasterFilters() const
367  {
368  return QString();
369  }
370 
375  virtual void reloadData() {}
376 
378  virtual QDateTime timestamp() const { return mTimestamp; }
379 
381  virtual QDateTime dataTimestamp() const { return QDateTime(); }
382 
388  virtual QgsError error() const { return mError; }
389 
394  virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ); }
395 
418  virtual bool enterUpdateMode() { return true; }
419 
437  virtual bool leaveUpdateMode() { return true; }
438 
445  void setProviderProperty( ProviderProperty property, const QVariant &value );
446 
453  void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
454 
461  QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
462 
469  QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
470 
481  virtual void setListening( bool isListening );
482 
483 #ifndef SIP_RUN
484 
491  {
493  double lastRenderingTimeMs = -1;
494 
496  double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
497  };
498 #endif
499 
512  virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
513 
522  virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
523 
532  virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ); return false; }
533 
534  signals:
535 
541  void fullExtentCalculated();
542 
550  void dataChanged();
551 
559  void notify( const QString &msg );
560 
561 
562  protected:
563 
567  QDateTime mTimestamp;
568 
571 
573  void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
574 
576  void setError( const QgsError &error ) { mError = error;}
577 
578  private:
579 
584  QString mDataSourceURI;
585 
586  QMap< int, QVariant > mProviderProperties;
587 };
588 
589 
590 #endif
virtual uint subLayerCount() const
Returns 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 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:40
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider&#39;s source.
static QString SUBLAYER_SEPARATOR
String sequence used for separating components of sublayers strings.
virtual void updateExtents()
Update the extents of the layer.
virtual QString fileRasterFilters() const
Returns raster file filter string.
QgsDataProvider(const QString &uri=QString(), const QgsDataProvider::ProviderOptions &options=QgsDataProvider::ProviderOptions())
Create a new dataprovider with the specified in the uri.
QDateTime mTimestamp
Timestamp of data in the moment when the data were loaded by provider.
QgsDataSourceUri uri() const
Gets the data source specification.
Abstract base class for spatial data provider implementations.
const QgsCoordinateReferenceSystem & crs
virtual QString fileVectorFilters() const
Returns 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.
QString uri(bool expandAuthConfig=true) const
Returns complete uri.
void setUri(const QgsDataSourceUri &uri)
Set the data source specification.
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
#define SIP_END
Definition: qgis_sip.h:182
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) ...
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
virtual bool supportsSubsetString() const
Returns true if the provider supports setting of subset strings.
virtual QStringList subLayerStyles() const
Sub-layer styles for each sub-layer handled by this provider, in order from bottom to top...
A structured metadata store for a map layer.
Setting options for creating vector data providers.
QgsError is container for error messages (report).
Definition: qgserror.h:80
void setError(const QgsError &error)
Sets 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 QString subsetString() const
Returns the subset definition string (typically sql) currently in use by the layer and used by the pr...
virtual bool writeLayerMetadata(const QgsLayerMetadata &metadata)
Writes layer metadata to the underlying provider source.
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.
virtual void invalidateConnections(const QString &connection)
Invalidate connections corresponding to specified name.
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 QgsError error() const
Gets current status error.
virtual bool leaveUpdateMode()
Leave update mode.