QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsvirtuallayerdefinition.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsvirtuallayerdefinition.h
3begin : Feb, 2015
4copyright : (C) 2015 Hugo Mercier, Oslandia
5email : hugo dot mercier at oslandia dot com
6 ***************************************************************************/
7
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#ifndef QGSVIRTUALLAYERDEFINITION_H
18#define QGSVIRTUALLAYERDEFINITION_H
19
20#include "qgis_core.h"
21#include "qgsfields.h"
22#include "qgswkbtypes.h"
23
32{
33 public:
34
40 class CORE_EXPORT SourceLayer
41 {
42 public:
44 SourceLayer( const QString &name, const QString &ref )
45 : mName( name )
46 , mRef( ref )
47 {}
49 SourceLayer( const QString &name, const QString &source, const QString &provider, const QString &encoding )
50 : mName( name )
51 , mSource( source )
52 , mProvider( provider )
53 , mEncoding( encoding )
54 {}
55
57 bool isReferenced() const { return !mRef.isEmpty(); }
58
60 QString reference() const { return mRef; }
61
63 QString name() const { return mName; }
64
66 QString provider() const { return mProvider; }
67
69 QString source() const { return mSource; }
70
72 QString encoding() const { return mEncoding; }
73
74 private:
75 QString mName;
76 QString mSource;
77 QString mProvider;
78 QString mRef;
79 QString mEncoding;
80 };
81
83 QgsVirtualLayerDefinition( const QString &filePath = "" );
84
100 static QgsVirtualLayerDefinition fromUrl( const QUrl &url );
101
103 QUrl toUrl() const;
104
106 QString toString() const;
107
109 void addSource( const QString &name, const QString &ref );
110
112 void addSource( const QString &name, const QString &source, const QString &provider, const QString &encoding = "" );
113
115 typedef QList<QgsVirtualLayerDefinition::SourceLayer> SourceLayers;
116
118 const QgsVirtualLayerDefinition::SourceLayers &sourceLayers() const { return mSourceLayers; }
119
121 QString query() const { return mQuery; }
123 void setQuery( const QString &query ) { mQuery = query; }
124
126 QString filePath() const { return mFilePath; }
128 void setFilePath( const QString &filePath ) { mFilePath = filePath; }
129
131 QString uid() const { return mUid; }
133 void setUid( const QString &uid ) { mUid = uid; }
134
143 void setLazy( bool lazy ) { mLazy = lazy; }
144
151 bool isLazy() const { return mLazy; }
152
154 QString geometryField() const { return mGeometryField; }
156 void setGeometryField( const QString &geometryField ) { mGeometryField = geometryField; }
157
163 Qgis::WkbType geometryWkbType() const { return mGeometryWkbType; }
165 void setGeometryWkbType( Qgis::WkbType t ) { mGeometryWkbType = t; }
166
168 long geometrySrid() const { return mGeometrySrid; }
170 void setGeometrySrid( long srid ) { mGeometrySrid = srid; }
171
173 QgsFields fields() const { return mFields; }
175 void setFields( const QgsFields &fields ) { mFields = fields; }
176
178 bool hasSourceLayer( const QString &name ) const;
179
181 bool hasReferencedLayers() const;
182
185 {
186 return geometryWkbType() != Qgis::WkbType::NoGeometry && geometryWkbType() != Qgis::WkbType::Unknown;
187 }
188
193 QString subsetString() const;
194
199 void setSubsetString( const QString &subsetString );
200
201 private:
202 SourceLayers mSourceLayers;
203 QString mQuery;
204 QString mUid;
205 QString mGeometryField;
206 QString mFilePath;
207 QgsFields mFields;
208 bool mLazy = false;
209 Qgis::WkbType mGeometryWkbType = Qgis::WkbType::Unknown;
210 long mGeometrySrid = 0;
211 QString mSubsetString;
212};
213
214// clazy:excludeall=qstring-allocations
215
216#endif
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:182
@ NoGeometry
No geometry.
@ Unknown
Unknown.
Container of fields for a vector layer.
Definition qgsfields.h:45
A SourceLayer is either a reference to a live layer in the registry or all the parameters needed to l...
QString source() const
The source url used by the provider to build the layer.
SourceLayer(const QString &name, const QString &ref)
Constructor variant to build a live layer reference.
QString encoding() const
Optional encoding for the provider.
bool isReferenced() const
Is it a live layer or not ?
SourceLayer(const QString &name, const QString &source, const QString &provider, const QString &encoding)
Constructor variant to build a layer with a provider and a source.
QString reference() const
The reference (id) of the live layer.
Class to manipulate the definition of a virtual layer.
QString geometryField() const
Gets the name of the geometry field. Empty if no geometry field.
QString query() const
Gets the SQL query.
Qgis::WkbType geometryWkbType() const
Gets the type of the geometry QgsWkbTypes::NoGeometry to hide any geometry QgsWkbTypes::Unknown for u...
QgsFields fields() const
Gets field definitions.
long geometrySrid() const
Gets the SRID of the geometry.
void setUid(const QString &uid)
Sets the name of the field with unique identifiers.
bool hasDefinedGeometry() const
Convenient method to test if the geometry is defined (not NoGeometry and not Unknown)
void setLazy(bool lazy)
Sets the lazy mode.
QList< QgsVirtualLayerDefinition::SourceLayer > SourceLayers
List of source layers.
void setFilePath(const QString &filePath)
Sets the file path.
void setGeometrySrid(long srid)
Sets the SRID of the geometry.
void setGeometryField(const QString &geometryField)
Sets the name of the geometry field.
const QgsVirtualLayerDefinition::SourceLayers & sourceLayers() const
Gets access to the source layers.
QString uid() const
Gets the name of the field with unique identifiers.
QString filePath() const
Gets the file path. May be empty.
void setFields(const QgsFields &fields)
Sets field definitions.
void setGeometryWkbType(Qgis::WkbType t)
Sets the type of the geometry.
void setQuery(const QString &query)
Sets the SQL query.
bool isLazy() const
Returns the lazy mode.