QgsVirtualLayerDefinition class
Class to manipulate the definition of a virtual layer.
Contents
It is used to extract parameters from an initial virtual layer definition as well as to store the complete, expanded definition once types have been detected.
Public types
- class SourceLayer
- A SourceLayer is either a reference to a live layer in the registry or all the parameters needed to load it (provider key, source, etc.)
-
using SourceLayers = QList<QgsVirtualLayerDefinition::
SourceLayer> - List of source layers.
Public static functions
- static auto fromUrl(const QUrl& url) -> QgsVirtualLayerDefinition
- Constructor to build a definition from a QUrl The path part of the URL is extracted as well as the following optional keys: layer_ref=layer_id[:name] represents a live layer referenced by its ID.
Constructors, destructors, conversion operators
- QgsVirtualLayerDefinition(const QString& filePath = "")
- Constructor with an optional file path.
Public functions
- void addSource(const QString& name, const QString& ref)
- Add a live layer source layer.
- void addSource(const QString& name, const QString& source, const QString& provider, const QString& encoding = "")
- Add a layer with a source, a provider and an encoding.
- auto fields() const -> QgsFields
- Gets field definitions.
- auto filePath() const -> QString
- Gets the file path. May be empty.
- auto geometryField() const -> QString
- Gets the name of the geometry field. Empty if no geometry field.
- auto geometrySrid() const -> long
- Gets the SRID of the geometry.
-
auto geometryWkbType() const -> QgsWkbTypes::
Type - Gets the type of the geometry QgsWkbTypes::
NoGeometry to hide any geometry QgsWkbTypes:: Unknown for unknown types. - auto hasDefinedGeometry() const -> bool
- Convenient method to test if the geometry is defined (not NoGeometry and not Unknown)
- auto hasReferencedLayers() const -> bool
- Convenience method to test whether the definition has referenced (live) layers.
- auto hasSourceLayer(const QString& name) const -> bool
- Convenience method to test if a given source layer is part of the definition.
- auto isLazy() const -> bool
- Returns the lazy mode.
- auto query() const -> QString
- Gets the SQL query.
- void setFields(const QgsFields& fields)
- Sets field definitions.
- void setFilePath(const QString& filePath)
- Sets the file path.
- void setGeometryField(const QString& geometryField)
- Sets the name of the geometry field.
- void setGeometrySrid(long srid)
- Sets the SRID of the geometry.
-
void setGeometryWkbType(QgsWkbTypes::
Type t) - Sets the type of the geometry.
- void setLazy(bool lazy)
- Sets the lazy mode.
- void setQuery(const QString& query)
- Sets the SQL query.
- void setUid(const QString& uid)
- Sets the name of the field with unique identifiers.
-
auto sourceLayers() const -> const QgsVirtualLayerDefinition::
SourceLayers& - Gets access to the source layers.
- auto toString() const -> QString
- Convert into a QString that can be read by the virtual layer provider.
- auto toUrl() const -> QUrl
- Convert the definition into a QUrl.
- auto uid() const -> QString
- Gets the name of the field with unique identifiers.
Function documentation
static QgsVirtualLayerDefinition QgsVirtualLayerDefinition:: fromUrl(const QUrl& url)
Constructor to build a definition from a QUrl The path part of the URL is extracted as well as the following optional keys: layer_ref=layer_id[:name] represents a live layer referenced by its ID.
An optional name can be given layer=provider:source[:name[:encoding]] represents a layer given by its provider key, its source url (URL-encoded). An optional name and encoding can be given geometry=column_name[:type:srid] gives the definition of the geometry column. Type can be either a WKB type code or a string (point, linestring, etc.) srid is an integer uid=column_name is the name of a column with unique integer values. nogeometry is a flag to force the layer to be a non-geometry layer query=sql represents the SQL query. Must be URL-encoded field=column_name:[int|real|text] represents a field with its name and its type
bool QgsVirtualLayerDefinition:: isLazy() const
Returns the lazy mode.
| Returns | True if the loading is delayed, false otherwise. |
|---|
void QgsVirtualLayerDefinition:: setLazy(bool lazy)
Sets the lazy mode.
| Parameters | |
|---|---|
| lazy | True to delay the loading, false otherwise |
If lazy is true, then the loading is delayed until an explicit reloading of the layer.