QGIS API Documentation  2.14.0-Essen
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 <qgsfield.h>
21 #include <qgis.h>
22 
29 class CORE_EXPORT QgsVirtualLayerDefinition
30 {
31  public:
36  class CORE_EXPORT SourceLayer
37  {
38  public:
40  SourceLayer( const QString& name, const QString& ref ) : mName( name ), mRef( ref ) {}
42  SourceLayer( const QString& name, const QString& source, const QString& provider, const QString& encoding )
43  : mName( name ), mSource( source ), mProvider( provider ), mEncoding( encoding ) {}
44 
46  bool isReferenced() const { return !mRef.isEmpty(); }
47 
49  QString reference() const { return mRef; }
50 
52  QString name() const { return mName; }
53 
55  QString provider() const { return mProvider; }
56 
58  QString source() const { return mSource; }
59 
61  QString encoding() const { return mEncoding; }
62 
63  private:
64  QString mName;
65  QString mSource;
66  QString mProvider;
67  QString mRef;
68  QString mEncoding;
69  };
70 
72  QgsVirtualLayerDefinition( const QString& filePath = "" );
73 
86  static QgsVirtualLayerDefinition fromUrl( const QUrl& url );
87 
89  QUrl toUrl() const;
90 
92  QString toString() const;
93 
95  void addSource( const QString& name, const QString& ref );
96 
98  void addSource( const QString& name, const QString& source, const QString& provider, const QString& encoding = "" );
99 
102 
104  const SourceLayers& sourceLayers() const { return mSourceLayers; }
105 
107  QString query() const { return mQuery; }
109  void setQuery( const QString& query ) { mQuery = query; }
110 
112  QString filePath() const { return mFilePath; }
114  void setFilePath( const QString& filePath ) { mFilePath = filePath; }
115 
117  QString uid() const { return mUid; }
119  void setUid( const QString& uid ) { mUid = uid; }
120 
122  QString geometryField() const { return mGeometryField; }
124  void setGeometryField( const QString& geometryField ) { mGeometryField = geometryField; }
125 
129  QgsWKBTypes::Type geometryWkbType() const { return mGeometryWkbType; }
131  void setGeometryWkbType( QgsWKBTypes::Type t ) { mGeometryWkbType = t; }
132 
134  long geometrySrid() const { return mGeometrySrid; }
136  void setGeometrySrid( long srid ) { mGeometrySrid = srid; }
137 
139  const QgsFields& fields() const { return mFields; }
141  void setFields( const QgsFields& fields ) { mFields = fields; }
142 
144  bool hasSourceLayer( const QString& name ) const;
145 
147  bool hasReferencedLayers() const;
148 
150  bool hasDefinedGeometry() const
151  {
152  return geometryWkbType() != QgsWKBTypes::NoGeometry && geometryWkbType() != QgsWKBTypes::Unknown;
153  }
154 
155  private:
156  SourceLayers mSourceLayers;
157  QString mQuery;
158  QString mUid;
159  QString mGeometryField;
160  QString mFilePath;
161  QgsFields mFields;
162  QgsWKBTypes::Type mGeometryWkbType;
163  long mGeometrySrid;
164 };
165 
166 #endif
QString geometryField() const
Get the name of the geometry field. Empty if no geometry field.
void setFields(const QgsFields &fields)
Set field definitions.
QString query() const
Get the SQL query.
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.
Container of fields for a vector layer.
Definition: qgsfield.h:187
QString source() const
The source url used by the provider to build the layer.
void setFilePath(const QString &filePath)
Set the file path.
const QgsFields & fields() const
Get field definitions.
QString uid() const
Get the name of the field with unique identifiers.
void setQuery(const QString &query)
Set the SQL query.
void setGeometryField(const QString &geometryField)
Set the name of the geometry field.
void setGeometryWkbType(QgsWKBTypes::Type t)
Set the type of the geometry.
const SourceLayers & sourceLayers() const
Get access to the source layers.
bool hasDefinedGeometry() const
Convenient method to test if the geometry is defined (not NoGeometry and not Unknown) ...
QString name() const
Name of the layer.
SourceLayer(const QString &name, const QString &ref)
Constructor variant to build a live layer reference.
void setUid(const QString &uid)
Set the name of the field with unique identifiers.
QgsWKBTypes::Type geometryWkbType() const
Get the type of the geometry QgsWKBTypes::NoGeometry to hide any geometry QgsWKBTypes::Unknown for un...
void setGeometrySrid(long srid)
Set the SRID of the geometry.
QList< SourceLayer > SourceLayers
List of source layers.
bool isReferenced() const
Is it a live layer or not ?
long geometrySrid() const
Get the SRID of the geometry.
QString reference() const
The reference (id) of the live layer.
QString filePath() const
Get the file path. May be empty.
QString encoding() const
Optional encoding for the provider.
A SourceLayer is either a reference to a live layer in the registry or all the parameters needed to l...
Class to manipulate the definition of a virtual layer.