QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsvirtuallayerdefinition.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvirtuallayerdefinition.h
3 begin : Feb, 2015
4 copyright : (C) 2015 Hugo Mercier, Oslandia
5 email : 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 
31 class CORE_EXPORT QgsVirtualLayerDefinition
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  QgsWkbTypes::Type geometryWkbType() const { return mGeometryWkbType; }
165  void setGeometryWkbType( QgsWkbTypes::Type 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 
184  bool hasDefinedGeometry() const
185  {
186  return geometryWkbType() != QgsWkbTypes::NoGeometry && geometryWkbType() != QgsWkbTypes::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  QgsWkbTypes::Type mGeometryWkbType = QgsWkbTypes::Unknown;
210  long mGeometrySrid = 0;
211  QString mSubsetString;
212 };
213 
214 // clazy:excludeall=qstring-allocations
215 
216 #endif
QgsVirtualLayerDefinition::setGeometryWkbType
void setGeometryWkbType(QgsWkbTypes::Type t)
Sets the type of the geometry.
Definition: qgsvirtuallayerdefinition.h:165
qgsfields.h
QgsVirtualLayerDefinition::SourceLayer::source
QString source() const
The source url used by the provider to build the layer.
Definition: qgsvirtuallayerdefinition.h:69
QgsVirtualLayerDefinition::setGeometrySrid
void setGeometrySrid(long srid)
Sets the SRID of the geometry.
Definition: qgsvirtuallayerdefinition.h:170
QgsVirtualLayerDefinition::setQuery
void setQuery(const QString &query)
Sets the SQL query.
Definition: qgsvirtuallayerdefinition.h:123
QgsVirtualLayerDefinition::geometryField
QString geometryField() const
Gets the name of the geometry field. Empty if no geometry field.
Definition: qgsvirtuallayerdefinition.h:154
QgsVirtualLayerDefinition::setLazy
void setLazy(bool lazy)
Sets the lazy mode.
Definition: qgsvirtuallayerdefinition.h:143
QgsVirtualLayerDefinition::SourceLayer::SourceLayer
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.
Definition: qgsvirtuallayerdefinition.h:49
QgsVirtualLayerDefinition::setUid
void setUid(const QString &uid)
Sets the name of the field with unique identifiers.
Definition: qgsvirtuallayerdefinition.h:133
QgsVirtualLayerDefinition::SourceLayer::reference
QString reference() const
The reference (id) of the live layer.
Definition: qgsvirtuallayerdefinition.h:60
QgsVirtualLayerDefinition::SourceLayer::isReferenced
bool isReferenced() const
Is it a live layer or not ?
Definition: qgsvirtuallayerdefinition.h:57
QgsVirtualLayerDefinition::SourceLayer::encoding
QString encoding() const
Optional encoding for the provider.
Definition: qgsvirtuallayerdefinition.h:72
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:45
QgsVirtualLayerDefinition::sourceLayers
const QgsVirtualLayerDefinition::SourceLayers & sourceLayers() const
Gets access to the source layers.
Definition: qgsvirtuallayerdefinition.h:118
QgsVirtualLayerDefinition::SourceLayer
A SourceLayer is either a reference to a live layer in the registry or all the parameters needed to l...
Definition: qgsvirtuallayerdefinition.h:41
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
QgsVirtualLayerDefinition::geometrySrid
long geometrySrid() const
Gets the SRID of the geometry.
Definition: qgsvirtuallayerdefinition.h:168
QgsVirtualLayerDefinition::SourceLayers
QList< QgsVirtualLayerDefinition::SourceLayer > SourceLayers
List of source layers.
Definition: qgsvirtuallayerdefinition.h:115
QgsVirtualLayerDefinition::setFields
void setFields(const QgsFields &fields)
Sets field definitions.
Definition: qgsvirtuallayerdefinition.h:175
QgsWkbTypes::Unknown
@ Unknown
Definition: qgswkbtypes.h:71
QgsVirtualLayerDefinition::setGeometryField
void setGeometryField(const QString &geometryField)
Sets the name of the geometry field.
Definition: qgsvirtuallayerdefinition.h:156
QgsVirtualLayerDefinition::uid
QString uid() const
Gets the name of the field with unique identifiers.
Definition: qgsvirtuallayerdefinition.h:131
QgsVirtualLayerDefinition::isLazy
bool isLazy() const
Returns the lazy mode.
Definition: qgsvirtuallayerdefinition.h:151
QgsVirtualLayerDefinition::query
QString query() const
Gets the SQL query.
Definition: qgsvirtuallayerdefinition.h:121
QgsVirtualLayerDefinition::setFilePath
void setFilePath(const QString &filePath)
Sets the file path.
Definition: qgsvirtuallayerdefinition.h:128
QgsWkbTypes::NoGeometry
@ NoGeometry
Definition: qgswkbtypes.h:85
QgsVirtualLayerDefinition
Class to manipulate the definition of a virtual layer.
Definition: qgsvirtuallayerdefinition.h:32
QgsVirtualLayerDefinition::hasDefinedGeometry
bool hasDefinedGeometry() const
Convenient method to test if the geometry is defined (not NoGeometry and not Unknown)
Definition: qgsvirtuallayerdefinition.h:184
QgsVirtualLayerDefinition::SourceLayer::SourceLayer
SourceLayer(const QString &name, const QString &ref)
Constructor variant to build a live layer reference.
Definition: qgsvirtuallayerdefinition.h:44
QgsVirtualLayerDefinition::SourceLayer::provider
QString provider() const
Provider key.
Definition: qgsvirtuallayerdefinition.h:66
QgsVirtualLayerDefinition::geometryWkbType
QgsWkbTypes::Type geometryWkbType() const
Gets the type of the geometry QgsWkbTypes::NoGeometry to hide any geometry QgsWkbTypes::Unknown for u...
Definition: qgsvirtuallayerdefinition.h:163
QgsVirtualLayerDefinition::fields
QgsFields fields() const
Gets field definitions.
Definition: qgsvirtuallayerdefinition.h:173
QgsVirtualLayerDefinition::SourceLayer::name
QString name() const
Name of the layer.
Definition: qgsvirtuallayerdefinition.h:63
qgswkbtypes.h
QgsVirtualLayerDefinition::filePath
QString filePath() const
Gets the file path. May be empty.
Definition: qgsvirtuallayerdefinition.h:126