QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
39 class CORE_EXPORT SourceLayer
40 {
41 public:
43 SourceLayer( const QString &name, const QString &ref )
44 : mName( name )
45 , mRef( ref )
46 {}
47
48 SourceLayer( const QString &name, const QString &source, const QString &provider, const QString &encoding )
49 : mName( name )
50 , mSource( source )
51 , mProvider( provider )
52 , mEncoding( encoding )
53 {}
54
56 bool isReferenced() const { return !mRef.isEmpty(); }
57
59 QString reference() const { return mRef; }
60
62 QString name() const { return mName; }
63
65 QString provider() const { return mProvider; }
66
68 QString source() const { return mSource; }
69
71 QString encoding() const { return mEncoding; }
72
73 private:
74 QString mName;
75 QString mSource;
76 QString mProvider;
77 QString mRef;
78 QString mEncoding;
79 };
80
82 QgsVirtualLayerDefinition( const QString &filePath = "" );
83
99 static QgsVirtualLayerDefinition fromUrl( const QUrl &url );
100
102 QUrl toUrl() const;
103
105 QString toString() const;
106
108 void addSource( const QString &name, const QString &ref );
109
111 void addSource( const QString &name, const QString &source, const QString &provider, const QString &encoding = "" );
112
114 typedef QList<QgsVirtualLayerDefinition::SourceLayer> SourceLayers;
115
117 const QgsVirtualLayerDefinition::SourceLayers &sourceLayers() const { return mSourceLayers; }
118
120 QString query() const { return mQuery; }
122 void setQuery( const QString &query ) { mQuery = query; }
123
125 QString filePath() const { return mFilePath; }
127 void setFilePath( const QString &filePath ) { mFilePath = filePath; }
128
130 QString uid() const { return mUid; }
132 void setUid( const QString &uid ) { mUid = uid; }
133
142 void setLazy( bool lazy ) { mLazy = lazy; }
143
150 bool isLazy() const { return mLazy; }
151
153 QString geometryField() const { return mGeometryField; }
155 void setGeometryField( const QString &geometryField ) { mGeometryField = geometryField; }
156
162 Qgis::WkbType geometryWkbType() const { return mGeometryWkbType; }
164 void setGeometryWkbType( Qgis::WkbType t ) { mGeometryWkbType = t; }
165
167 long geometrySrid() const { return mGeometrySrid; }
169 void setGeometrySrid( long srid ) { mGeometrySrid = srid; }
170
172 QgsFields fields() const { return mFields; }
174 void setFields( const QgsFields &fields ) { mFields = fields; }
175
177 bool hasSourceLayer( const QString &name ) const;
178
180 bool hasReferencedLayers() const;
181
184
189 QString subsetString() const;
190
195 void setSubsetString( const QString &subsetString );
196
197 private:
198 SourceLayers mSourceLayers;
199 QString mQuery;
200 QString mUid;
201 QString mGeometryField;
202 QString mFilePath;
203 QgsFields mFields;
204 bool mLazy = false;
205 Qgis::WkbType mGeometryWkbType = Qgis::WkbType::Unknown;
206 long mGeometrySrid = 0;
207 QString mSubsetString;
208};
209
210// clazy:excludeall=qstring-allocations
211
212#endif
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:294
@ NoGeometry
No geometry.
Definition qgis.h:312
@ Unknown
Unknown.
Definition qgis.h:295
Container of fields for a vector layer.
Definition qgsfields.h:46
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.
Manipulates 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.
QgsVirtualLayerDefinition(const QString &filePath="")
Constructor with an optional file path.
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.