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() )
207 if ( f.
type() == QVariant::Int )
209 else if ( f.
type() == QVariant::Double )
211 else if ( f.
type() == QVariant::String )
237 if ( l.
name() == name )
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QString cap(int nth) const
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.
const T & at(int i) const
Container of fields for a vector layer.
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...
void addEncodedQueryItem(const QByteArray &key, const QByteArray &value)
QString source() const
The source url used by the provider to build the layer.
void addSource(const QString &name, const QString &ref)
Add a live layer source layer.
void setFilePath(const QString &filePath)
Set the file path.
int indexIn(const QString &str, int offset, CaretMode caretMode) const
void append(const T &value)
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.
QString name() const
Gets the name of the field.
QList< QPair< QByteArray, QByteArray > > encodedQueryItems() const
void setGeometryWkbType(QgsWKBTypes::Type t)
Set the type of the geometry.
const SourceLayers & sourceLayers() const
Get access to the source layers.
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) ...
bool hasDefinedGeometry() const
Convenient method to test if the geometry is defined (not NoGeometry and not Unknown) ...
int count() const
Return number of items.
QString toString() const
Convert into a QString that can be read by the virtual layer provider.
Encapsulate a field in an attribute table or data source.
QString fromPercentEncoding(const QByteArray &input)
QString provider() const
Provider key.
QString toLocalFile() const
QString name() const
Name of the layer.
QUrl toUrl() const
Convert the definition into a QUrl.
long toLong(bool *ok, int base) const
bool hasSourceLayer(const QString &name) const
Convenience method to test if a given source layer is part of the definition.
QString mid(int position, int n) const
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
void addQueryItem(const QString &key, const QString &value)
bool isReferenced() const
Is it a live layer or not ?
static Type parseType(const QString &wktStr)
Attempts to extract the WKB type from a WKT string.
long geometrySrid() const
Get the SRID of the geometry.
QgsVirtualLayerDefinition(const QString &filePath="")
Constructor with an optional file path.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
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.
QUrl fromLocalFile(const QString &localFile)
bool hasReferencedLayers() const
Convenience method to test whether the definition has referenced (live) layers.
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
QByteArray toUtf8() const