QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
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  QgsWkbTypes::Type geometryWkbType() const { return mGeometryWkbType; }
164  void setGeometryWkbType( QgsWkbTypes::Type 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 
183  bool hasDefinedGeometry() const
184  {
185  return geometryWkbType() != QgsWkbTypes::NoGeometry && geometryWkbType() != QgsWkbTypes::Unknown;
186  }
187 
188  private:
189  SourceLayers mSourceLayers;
190  QString mQuery;
191  QString mUid;
192  QString mGeometryField;
193  QString mFilePath;
194  QgsFields mFields;
195  bool mLazy = false;
196  QgsWkbTypes::Type mGeometryWkbType = QgsWkbTypes::Unknown;
197  long mGeometrySrid = 0;
198 };
199 
200 // clazy:excludeall=qstring-allocations
201 
202 #endif
qgsfields.h
QgsFields
Definition: qgsfields.h:44
QgsVirtualLayerDefinition::SourceLayer
Definition: qgsvirtuallayerdefinition.h:52
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
QgsVirtualLayerDefinition::SourceLayers
QList< QgsVirtualLayerDefinition::SourceLayer > SourceLayers
List of source layers.
Definition: qgsvirtuallayerdefinition.h:126
QgsWkbTypes::Unknown
@ Unknown
Definition: qgswkbtypes.h:70
QgsWkbTypes::NoGeometry
@ NoGeometry
Definition: qgswkbtypes.h:84
QgsVirtualLayerDefinition
Definition: qgsvirtuallayerdefinition.h:31
qgswkbtypes.h