19 #include <QStringList> 26 : mFilePath( filePath )
39 const QString columnNameRx(
"[a-zA-Z_\x80-\xFF][a-zA-Z0-9_\x80-\xFF]*" );
45 for (
int i = 0; i < items.
size(); i++ )
49 if ( key ==
"layer_ref" )
58 vlayerName =
QString(
"vtab%1" ).
arg( layerIdx );
62 layerId = value.
left( pos );
68 else if ( key ==
"layer" )
75 QString providerKey, source, vlayerName, encoding =
"UTF-8";
77 providerKey = value.
left( pos );
78 int pos2 = value.
indexOf(
':', pos + 1 );
79 if ( pos2 - pos == 2 )
80 pos2 = value.
indexOf(
':', pos + 3 );
84 int pos3 = value.
indexOf(
':', pos2 + 1 );
88 encoding = value.
mid( pos3 + 1 );
98 vlayerName =
QString(
"vtab%1" ).
arg( layerIdx );
101 def.
addSource( vlayerName, source, providerKey, encoding );
104 else if ( key ==
"geometry" )
108 QRegExp reGeom(
"(" + columnNameRx +
")(?::([a-zA-Z0-9]+):(\\d+))?" );
109 int pos = reGeom.
indexIn( value );
126 else if ( key ==
"nogeometry" )
130 else if ( key ==
"uid" )
134 else if ( key ==
"query" )
139 else if ( key ==
"field" )
142 QRegExp reField(
"(" + columnNameRx +
"):(int|real|text)" );
143 int pos = reField.
indexIn( value );
148 if ( fieldType ==
"int" )
152 else if ( fieldType ==
"real" )
154 fields.
append(
QgsField( fieldName, QVariant::Double, fieldType ) );
156 if ( fieldType ==
"text" )
158 fields.
append(
QgsField( fieldName, QVariant::String, fieldType ) );
191 if ( !
uid().isEmpty() )
206 if ( f.
type() == QVariant::Int )
208 else if ( f.
type() == QVariant::Double )
210 else if ( f.
type() == QVariant::String )
236 if ( l.
name() == name )
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QString cap(int nth) const
bool isReferenced() const
Is it a live layer or not ?
const SourceLayers & sourceLayers() const
Get access to the source layers.
bool hasReferencedLayers() const
Convenience method to test whether the definition has referenced (live) layers.
void setFields(const QgsFields &fields)
Set field definitions.
QString name() const
Name of the layer.
QString uid() const
Get the name of the field with unique identifiers.
const T & at(int i) const
QString encoding() const
Optional encoding for the provider.
Container of fields for a vector layer.
QString toString() const
Convert into a QString that can be read by the virtual layer provider.
static QgsVirtualLayerDefinition fromUrl(const QUrl &url)
Constructor to build a definition from a QUrl The path part of the URL is extracted as well as the fo...
QString source() const
The source url used by the provider to build the layer.
void addEncodedQueryItem(const QByteArray &key, const QByteArray &value)
void addSource(const QString &name, const QString &ref)
Add a live layer source layer.
void setFilePath(const QString &filePath)
Set the file path.
QUrl toUrl() const
Convert the definition into a QUrl.
QString filePath() const
Get the file path. May be empty.
int indexIn(const QString &str, int offset, CaretMode caretMode) const
QString reference() const
The reference (id) of the live layer.
void append(const T &value)
void setQuery(const QString &query)
Set the SQL query.
void setGeometryField(const QString &geometryField)
Set the name of the geometry field.
QList< QPair< QByteArray, QByteArray > > encodedQueryItems() const
const QgsFields & fields() const
Get field definitions.
QString geometryField() const
Get the name of the geometry field. Empty if no geometry field.
void setGeometryWkbType(QgsWKBTypes::Type t)
Set the type of the geometry.
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Append a field. The field must have unique name, otherwise it is rejected (returns false) ...
Encapsulate a field in an attribute table or data source.
QString fromPercentEncoding(const QByteArray &input)
bool hasSourceLayer(const QString &name) const
Convenience method to test if a given source layer is part of the definition.
QString toLocalFile() const
long toLong(bool *ok, int base) const
QString mid(int position, int n) const
bool hasDefinedGeometry() const
Convenient method to test if the geometry is defined (not NoGeometry and not Unknown) ...
Handles storage of information regarding WKB types and their properties.
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...
QByteArray toPercentEncoding(const QString &input, const QByteArray &exclude, const QByteArray &include)
void setGeometrySrid(long srid)
Set the SRID of the geometry.
QString left(int n) const
QString provider() const
Provider key.
void addQueryItem(const QString &key, const QString &value)
static Type parseType(const QString &wktStr)
Attempts to extract the WKB type from a WKT string.
QString query() const
Get the SQL query.
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
QgsVirtualLayerDefinition(const QString &filePath="")
Constructor with an optional file path.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
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.
long geometrySrid() const
Get the SRID of the geometry.
QUrl fromLocalFile(const QString &localFile)
QByteArray toUtf8() const