QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
28 QStringList leftJoins;
33 columns <<
"t.geometry";
46 QString uid = QStringLiteral(
"uid" );
48 uid += QLatin1String(
"_" );
51 columns <<
"t.rowid AS " + uid;
56 for (
const auto &f : providerFields )
58 columns <<
"t.\"" + f.name() +
"\"";
65 QString joinName = QStringLiteral(
"j%1" ).arg( ++joinIdx );
69 QString prefix = join.prefix().isEmpty() ? joinedLayer->
name() +
"_" : join.prefix();
71 leftJoins << QStringLiteral(
"LEFT JOIN \"%1\" AS %2 ON t.\"%5\"=%2.\"%3\"" ).arg( joinedLayer->
id(), joinName, join.joinFieldName(), join.targetFieldName() );
72 if ( join.joinFieldNamesSubset() )
74 const QStringList joinFieldNamesSubset { *join.joinFieldNamesSubset() };
75 for (
const QString &f : joinFieldNamesSubset )
77 columns << joinName +
".\"" + f +
"\" AS \"" + prefix + f +
"\"";
83 for (
const QgsField &f : joinFields )
85 if ( f.name() == join.joinFieldName() )
87 columns << joinName +
".\"" + f.name() +
"\" AS \"" + prefix + f.name() +
"\"";
92 QString query =
"SELECT " + columns.join( QStringLiteral(
", " ) ) +
" FROM \"" + layer->
id() +
"\" AS t " + leftJoins.join( QStringLiteral(
" " ) );
void setQuery(const QString &query)
Sets the SQL query.
virtual QgsAttributeList pkAttributeIndexes() const
Returns list of indexes of fields that make up the primary key.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
void setUid(const QString &uid)
Sets the name of the field with unique identifiers.
QgsFields fields() const override=0
Returns the fields associated with this data provider.
bool isSpatial() const FINAL
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
QList< int > QgsAttributeList
QgsFields fields() const FINAL
Returns the list of fields of this layer.
const QList< QgsVectorLayerJoinInfo > vectorJoins() const
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
QgsField field(int fieldIdx) const
Gets field at particular index (must be in range 0..N-1)
static QgsVirtualLayerDefinition fromJoinedLayer(QgsVectorLayer *joinedLayer)
Gets a virtual layer definition from a vector layer where vector joins are replaced by SQL LEFT JOINs...
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.