QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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"
30
31class 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
72 // TODO QGIS 4: (re)move DataCapability as this enum is really meant for data items rather than data providers
73
78 {
79 NoDataCapabilities = 0,
80 File = 1,
81 Dir = 1 << 1,
82 Database = 1 << 2,
83 Net = 1 << 3 // Internet source
84 };
85 Q_DECLARE_FLAGS( DataCapabilities, DataCapability )
86
87
95 {
97 CustomData = 3000
98 };
99
100
117
123 {
124 FlagTrustDataSource = 1 << 0,
125 SkipFeatureCount = 1 << 1,
126 FlagLoadDefaultStyle = 1 << 2,
127 SkipGetExtent = 1 << 3,
128 SkipFullScan = 1 << 4,
129 ForceReadOnly = 1 << 5,
130 SkipCredentialsRequest = 1 << 6,
131 ParallelThreadLoading = 1 << 7,
132 };
133 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
134
135
140 QgsDataProvider( const QString &uri = QString(),
142 QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() );
143
150
156 virtual void setDataSourceUri( const QString &uri )
157 {
158 mDataSourceURI = uri;
159 }
160
170 virtual QString dataSourceUri( bool expandAuthConfig = false ) const
171 {
172 if ( expandAuthConfig && mDataSourceURI.contains( QLatin1String( "authcfg" ) ) )
173 {
174 const QgsDataSourceUri uri( mDataSourceURI );
175 return uri.uri( expandAuthConfig );
176 }
177 else
178 {
179 return mDataSourceURI;
180 }
181 }
182
190 virtual QString dataComment() const { return QString(); };
191
192
198 void setUri( const QgsDataSourceUri &uri )
199 {
200 mDataSourceURI = uri.uri( true );
201 }
202
209 {
210 return QgsDataSourceUri( mDataSourceURI );
211 }
212
218 virtual Qgis::DataProviderFlags flags() const;
219
227 virtual QgsDataProviderTemporalCapabilities *temporalCapabilities();
228
236 virtual const QgsDataProviderTemporalCapabilities *temporalCapabilities() const SIP_SKIP;
237
245 virtual QgsDataProviderElevationProperties *elevationProperties();
246
254 virtual const QgsDataProviderElevationProperties *elevationProperties() const SIP_SKIP;
255
260 virtual QgsRectangle extent() const = 0;
261
262
267 virtual bool isValid() const = 0;
268
272 virtual void updateExtents()
273 {
274 // NOP by default
275 }
276
277
284 virtual bool setSubsetString( const QString &subset, bool updateFeatureCount = true )
285 {
286 // NOP by default
287 Q_UNUSED( subset )
288 Q_UNUSED( updateFeatureCount )
289 return false;
290 }
291
292
296 virtual bool supportsSubsetString() const { return false; }
297
304 virtual QString subsetString() const
305 {
306 return QString();
307 }
308
309
318 virtual QStringList subLayers() const
319 {
320 return QStringList(); // Empty
321 }
322
330 virtual QStringList subLayerStyles() const
331 {
332 return QStringList(); // Empty
333 }
334
335
339 virtual uint subLayerCount() const
340 {
341 return 0;
342 }
343
344
350 virtual void setLayerOrder( const QStringList &layers )
351 {
352 //prevent unused var warnings
353 if ( layers.count() < 1 )
354 {
355 return;
356 }
357 // NOOP
358 }
359
360
364 virtual void setSubLayerVisibility( const QString &name, bool vis )
365 {
366 //prevent unused var warnings
367 if ( name.isEmpty() || !vis )
368 {
369 return;
370 }
371 // NOOP
372 }
373
374
390 virtual QString name() const = 0;
391
392
405 virtual QString description() const = 0;
406
407
418 virtual QString fileVectorFilters() const
419 {
420 return QString();
421 }
422
423
434 virtual QString fileRasterFilters() const
435 {
436 return QString();
437 }
438
439 // TODO QGIS 4 -> Make `reloadData()` non virtual. This should be implemented in `reloadProviderData()`.
440
448 virtual void reloadData();
449
451 virtual QDateTime timestamp() const { return mTimestamp; }
452
454 virtual QDateTime dataTimestamp() const { return QDateTime(); }
455
461 virtual QgsError error() const { return mError; }
462
467 virtual void invalidateConnections( const QString &connection ) { Q_UNUSED( connection ) }
468
491 virtual bool enterUpdateMode() { return true; }
492
510 virtual bool leaveUpdateMode() { return true; }
511
518 void setProviderProperty( ProviderProperty property, const QVariant &value );
519
526 void setProviderProperty( int property, const QVariant &value ); // SIP_SKIP
527
534 QVariant providerProperty( ProviderProperty property, const QVariant &defaultValue = QVariant() ) const;
535
542 QVariant providerProperty( int property, const QVariant &defaultValue ) const; // SIP_SKIP
543
554 virtual void setListening( bool isListening );
555
556#ifndef SIP_RUN
557
564 {
566 double lastRenderingTimeMs = -1;
567
569 double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
570 };
571#endif
572
585 virtual bool renderInPreview( const QgsDataProvider::PreviewContext &context ); // SIP_SKIP
586
595 virtual QgsLayerMetadata layerMetadata() const { return QgsLayerMetadata(); }
596
605 virtual bool writeLayerMetadata( const QgsLayerMetadata &metadata ) { Q_UNUSED( metadata ) return false; }
606
614 QgsCoordinateTransformContext transformContext() const SIP_SKIP;
615
626 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) SIP_SKIP;
627
634 static QString sublayerSeparator();
635
641 virtual Qgis::ProviderStyleStorageCapabilities styleStorageCapabilities() const;
642
643 signals:
644
651 void fullExtentCalculated();
652
665 void dataChanged();
666
674 void notify( const QString &msg );
675
676
677 protected:
678
682 QDateTime mTimestamp;
683
685 QgsError mError;
686
688 void appendError( const QgsErrorMessage &message ) { mError.append( message ); }
689
691 void setError( const QgsError &error ) { mError = error;}
692
694 QgsDataProvider::ReadFlags mReadFlags = QgsDataProvider::ReadFlags();
695
696 private:
697
702 QString mDataSourceURI;
703
705
706 QMap< int, QVariant > mProviderProperties;
707
711 mutable QMutex mOptionsMutex;
712
717 virtual void reloadProviderData() {}
718
719 friend class TestQgsProject;
720};
721
722Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataProvider::ReadFlags )
723
724#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
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)
ReadFlag
Flags which control dataprovider construction.
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....
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 QString subsetString() const
Returns the subset definition string (typically sql) currently in use by the layer and used by the pr...
virtual QgsLayerMetadata layerMetadata() const
Returns layer metadata collected from the provider's source.
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.
DataCapability
Used in browser model to understand which items for which providers should be populated.
virtual QDateTime dataTimestamp() const
Current time stamp of data source.
virtual bool supportsSubsetString() const
Returns true if the provider supports setting of subset strings.
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.
virtual bool setSubsetString(const QString &subset, bool updateFeatureCount=true)
Set the subset string used to create a subset of features in 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
QgsError is container for error messages (report).
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:186
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_END
Definition qgis_sip.h:203
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
Stores settings related to the context in which a preview job runs.
Setting options for creating vector data providers.
QgsCoordinateTransformContext transformContext
Coordinate transform context.