QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
qgsfields.h
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
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:52
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
QgsVirtualLayerDefinition::SourceLayers
QList< QgsVirtualLayerDefinition::SourceLayer > SourceLayers
List of source layers.
Definition: qgsvirtuallayerdefinition.h:127
QgsWkbTypes::Unknown
@ Unknown
Definition: qgswkbtypes.h:71
QgsWkbTypes::NoGeometry
@ NoGeometry
Definition: qgswkbtypes.h:85
QgsVirtualLayerDefinition
Class to manipulate the definition of a virtual layer.
Definition: qgsvirtuallayerdefinition.h:31
qgswkbtypes.h