QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
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#include <QMutex>
25
26#include "qgsdatasourceuri.h"
28#include "qgslayermetadata.h"
29#include "qgserror.h"
31
32class QgsRectangle;
35
36
41class CORE_EXPORT QgsDataProvider : public QObject
42{
43
44#ifdef SIP_RUN
46 if ( qobject_cast<QgsVectorDataProvider *>( sipCpp ) )
47 {
48 sipType = sipType_QgsVectorDataProvider;
49 }
50 else if ( qobject_cast<QgsRasterDataProvider *>( sipCpp ) )
51 {
52 sipType = sipType_QgsRasterDataProvider;
53 }
54 else if ( qobject_cast<QgsMeshDataProvider *>( sipCpp ) )
55 {
56 sipType = sipType_QgsMeshDataProvider;
57 }
58 else if ( qobject_cast<QgsPointCloudDataProvider *>( sipCpp ) )
59 {
60 sipType = sipType_QgsPointCloudDataProvider;
61 }
62 else
63 {
64 sipType = 0;
65 }
67#endif
68 Q_OBJECT
69
70 public:
71
80 {
82 CustomData = 3000
83 };
84
101
107 QgsDataProvider( const QString &uri = QString(),
110
117
123 virtual void setDataSourceUri( const QString &uri )
124 {
125 mDataSourceURI = uri;
126 }
127
137 virtual QString dataSourceUri( bool expandAuthConfig = false ) const
138 {
139 if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
140 {
141 const QgsDataSourceUri uri( mDataSourceURI );
142 return uri.uri( expandAuthConfig );
143 }
144 else
145 {
146 return mDataSourceURI;
147 }
148 }
149
157 virtual QString dataComment() const { return QString(); };
158
164 virtual QString htmlMetadata() const;
165
170 void setUri( const QgsDataSourceUri &uri )
171 {
172 mDataSourceURI = uri.uri( true );
173 }
174
180 void setUri( const QString &uri )
181 {
182 mDataSourceURI = uri;
183 }
184
190 {
191 return QgsDataSourceUri( mDataSourceURI );
192 }
193
199 virtual Qgis::DataProviderFlags flags() const;
200
208 virtual QgsDataProviderTemporalCapabilities *temporalCapabilities();
209
217 virtual const QgsDataProviderTemporalCapabilities *temporalCapabilities() const SIP_SKIP;
218
226 virtual QgsDataProviderElevationProperties *elevationProperties();
227
235 virtual const QgsDataProviderElevationProperties *elevationProperties() const SIP_SKIP;
236
245 virtual QgsRectangle extent() const = 0;
246
257 virtual QgsBox3D extent3D() const
258 {
259 return extent().toBox3d( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN() );
260 }
261
266 virtual bool isValid() const = 0;
267
271 virtual void updateExtents()
272 {
273 // NOP by default
274 }
275
287 virtual QString subsetStringDialect() const;
288
300 virtual QString subsetStringHelpUrl() const;
301
317 virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true );
318
325 virtual bool supportsSubsetString() const;
326
343 virtual QString subsetString() const;
344
353 virtual QStringList subLayers() const
354 {
355 return QStringList(); // Empty
356 }
357
365 virtual QStringList subLayerStyles() const
366 {
367 return QStringList(); // Empty
368 }
369
370
374 virtual uint subLayerCount() const
375 {
376 return 0;
377 }
378
379
385 virtual void setLayerOrder( const QStringList &layers )
386 {
387 //prevent unused var warnings
388 if ( layers.count() < 1 )
389 {
390 return;
391 }
392 // NOOP
393 }
394
395
399 virtual void setSubLayerVisibility( const QString &name, bool vis )
400 {
401 //prevent unused var warnings
402 if ( name.isEmpty() || !vis )
403 {
404 return;
405 }
406 // NOOP
407 }
408
409
410 // TODO? Instead of being pure virtual, might be better to generalize this
411 // behavior and presume that none of the sub-classes are going to do
412 // anything strange with regards to their name or description?
413
422 virtual QString name() const = 0;
423
424
430 virtual QString description() const = 0;
431
432
441 virtual QString fileVectorFilters() const
442 {
443 return QString();
444 }
445
446
455 virtual QString fileRasterFilters() const
456 {
457 return QString();
458 }
459
460 // TODO QGIS 4 -> Make `reloadData()` non virtual. This should be implemented in `reloadProviderData()`.
461
469 virtual void reloadData();
470
472 virtual QDateTime timestamp() const { return mTimestamp; }
473
475 virtual QDateTime dataTimestamp() const { return QDateTime(); }
476
482 virtual QgsError error() const { return mError; }
483
487 virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ) }
488
510 virtual bool enterUpdateMode() { return true; }
511
528 virtual bool leaveUpdateMode() { return true; }
529
535 void setProviderProperty( ProviderProperty property, const QVariant &value );
536
542 void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
543
549 QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
550
556 QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
557
567 virtual void setListening( bool isListening );
568
569#ifndef SIP_RUN
570
576 {
578 double lastRenderingTimeMs = -1;
579
581 double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
582 };
583#endif
584
596 virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
597
605 virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
606
614 virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ) return false; }
615
623 QgsCoordinateTransformContext transformContext() const SIP_SKIP;
624
635 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) SIP_SKIP;
636
643 static QString sublayerSeparator();
644
650 virtual Qgis::ProviderStyleStorageCapabilities styleStorageCapabilities() const;
651
652 signals:
653
660 void fullExtentCalculated();
661
674 void dataChanged();
675
682 void notify( const QString &msg );
683
684
685 protected:
686
690 QDateTime mTimestamp;
691
693 QgsError mError;
694
696 void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
697
699 void setError( const QgsError &error ) { mError = error;}
700
703
704 private:
705
710 QString mDataSourceURI;
711
713
714 QMap< int, QVariant > mProviderProperties;
715
719 mutable QMutex mOptionsMutex;
720
725 virtual void reloadProviderData() {}
726
727 friend class TestQgsProject;
728};
729
730#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
QFlags< DataProviderFlag > DataProviderFlags
Data provider flags.
Definition qgis.h:2147
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:450
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:43
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Base class for handling elevation related properties for a data provider.
Base class for handling properties relating to a data provider's temporal capabilities.
Abstract base class for spatial data provider implementations.
virtual void invalidateConnections(const QString &connection)
Invalidate connections corresponding to specified name.
virtual bool leaveUpdateMode()
Leave update mode.
void setUri(const QgsDataSourceUri &uri)
Set 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)
virtual QString name() const =0
Returns a provider name.
void setError(const QgsError &error)
Sets error message.
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
virtual QString dataComment() const
Returns a short comment for the data that this provider is providing access to (e....
void setUri(const QString &uri)
Set the data source specification.
ProviderProperty
Properties are used to pass custom configuration options into data providers.
@ EvaluateDefaultValues
Evaluate default values on provider side when calling QgsVectorDataProvider::defaultValue( int index ...
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider's source.
virtual bool isValid() const =0
Returns true if this is a valid layer.
virtual void setDataSourceUri(const QString &uri)
Set the data source specification.
virtual QString fileRasterFilters() const
Returns raster file filter string.
virtual QgsError error() const
Gets current status error.
virtual QDateTime dataTimestamp() const
Current time stamp of data source.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Gets the data source specification.
virtual QString description() const =0
Returns description.
QgsDataSourceUri uri() const
Gets the data source specification.
virtual QString fileVectorFilters() const
Returns vector file filter string.
virtual QStringList subLayerStyles() const
Sub-layer styles for each sub-layer handled by this provider, in order from bottom to top.
Qgis::DataProviderReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when needed.
virtual void updateExtents()
Update the extents of the layer.
virtual uint subLayerCount() const
Returns the number of layers for the current data source.
virtual QStringList subLayers() const
Sub-layers handled by this provider, in order from bottom to top.
virtual bool writeLayerMetadata(const QgsLayerMetadata &metadata)
Writes layer metadata to the underlying provider source.
virtual bool enterUpdateMode()
Enter update mode.
virtual void setSubLayerVisibility(const QString &name, bool vis)
Set the visibility of the given sublayer name.
Class for storing the component parts of a RDBMS data source URI (e.g.
QString uri(bool expandAuthConfig=true) const
Returns the complete URI as a string.
QgsErrorMessage represents single error message.
Definition qgserror.h:33
A container for error messages.
Definition qgserror.h:81
void append(const QString &message, const QString &tag)
Append new error message.
Definition qgserror.cpp:39
A structured metadata store for a map layer.
A rectangle specified with double values.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_END
Definition qgis_sip.h:208
Stores settings related to the context in which a preview job runs.
Setting options for creating vector data providers.
QgsCoordinateTransformContext transformContext
Coordinate transform context.