23 #include <QDomElement>
89 QList< QgsVectorJoinInfo>::const_iterator joinIt =
mVectorJoins.constBegin();
90 for (
int joinIdx = 0 ; joinIt !=
mVectorJoins.constEnd(); ++joinIt, ++joinIdx )
99 QString joinFieldName;
100 if ( joinIt->joinFieldName.isEmpty() && joinIt->joinFieldIndex >= 0 && joinIt->joinFieldIndex < joinFields.
count() )
101 joinFieldName = joinFields.
field( joinIt->joinFieldIndex ).
name();
103 joinFieldName = joinIt->joinFieldName;
105 for (
int idx = 0; idx < joinFields.
count(); ++idx )
108 if ( joinFields[idx].name() != joinFieldName )
120 QList< QgsVectorJoinInfo >::iterator joinIt =
mVectorJoins.begin();
130 QDomElement vectorJoinsElem = document.createElement(
"vectorjoins" );
131 layer_node.appendChild( vectorJoinsElem );
132 QList< QgsVectorJoinInfo >::const_iterator joinIt =
mVectorJoins.constBegin();
135 QDomElement joinElem = document.createElement(
"join" );
137 if ( joinIt->targetFieldName.isEmpty() )
138 joinElem.setAttribute(
"targetField", joinIt->targetFieldIndex );
140 joinElem.setAttribute(
"targetFieldName", joinIt->targetFieldName );
142 joinElem.setAttribute(
"joinLayerId", joinIt->joinLayerId );
143 if ( joinIt->joinFieldName.isEmpty() )
144 joinElem.setAttribute(
"joinField", joinIt->joinFieldIndex );
146 joinElem.setAttribute(
"joinFieldName", joinIt->joinFieldName );
148 joinElem.setAttribute(
"memoryCache", !joinIt->cachedAttributes.isEmpty() );
149 vectorJoinsElem.appendChild( joinElem );
156 QDomElement vectorJoinsElem = layer_node.firstChildElement(
"vectorjoins" );
157 if ( !vectorJoinsElem.isNull() )
159 QDomNodeList joinList = vectorJoinsElem.elementsByTagName(
"join" );
160 for (
int i = 0; i < joinList.size(); ++i )
162 QDomElement infoElem = joinList.at( i ).toElement();
165 info.
joinLayerId = infoElem.attribute(
"joinLayerId" );
167 info.
memoryCache = infoElem.attribute(
"memoryCache" ).toInt();
183 int sourceJoinIndex = originIndex / 1000;
184 sourceFieldIndex = originIndex % 1000;
186 if ( sourceJoinIndex < 0 || sourceJoinIndex >=
mVectorJoins.count() )
const QString & name() const
Gets the name of the field.
Wrapper for iterator of features from vector data provider or vector layer.
QString joinFieldName
Join field in the source layer.
QString targetFieldName
Join field in the target layer.
void createJoinCaches()
Calls cacheJoinLayer() for all vector joins.
const QgsField & field(int fieldIdx) const
Get field at particular index (must be in range 0..N-1)
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
int joinFieldIndex
Join field index in the source layer.
void readXml(const QDomNode &layer_node)
Reads joins from project file.
Container of fields for a vector layer.
bool memoryCache
True if the join is cached in virtual memory.
int targetFieldIndex
Join field index in the target layer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
const QgsVectorJoinInfo * joinForFieldIndex(int index, const QgsFields &fields, int &sourceFieldIndex) const
Finds the vector join for a layer field index.
const QString & name() const
Get the display name of the layer.
int fieldOriginIndex(int fieldIdx) const
Get field's origin index (its meaning is specific to each type of origin)
This class wraps a request for features to a vector layer (or directly its vector data provider)...
const QgsAttributes & attributes() const
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) ...
int count() const
Return number of items.
Encapsulate a field in an attribute table or data source.
void removeJoin(const QString &joinLayerId)
Removes a vector layer join.
int indexFromName(const QString &name) const
Look up field's index from name. Returns -1 on error.
~QgsVectorLayerJoinBuffer()
void setName(const QString &nam)
Set the field name.
QList< QgsVectorJoinInfo > mVectorJoins
Joined vector layers.
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
QHash< QString, QgsAttributes > cachedAttributes
Cache for joined attributes to provide fast lookup (size is 0 if no memory caching) ...
QgsVectorLayerJoinBuffer()
QVector< QVariant > QgsAttributes
void writeXml(QDomNode &layer_node, QDomDocument &document) const
Saves mVectorJoins to xml under the layer node.
FieldOrigin fieldOrigin(int fieldIdx) const
Get field's origin (value from an enumeration)
void cacheJoinLayer(QgsVectorJoinInfo &joinInfo)
Caches attributes of join layer in memory if QgsVectorJoinInfo.memoryCache is true (and the cache is ...
void updateFields(QgsFields &fields)
Updates field map with joined attributes.
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
bool nextFeature(QgsFeature &f)
Geometry is not required. It may still be returned if e.g. required for a filter condition.
Represents a vector layer which manages a vector based data sets.
QString joinLayerId
Source layer.
void addJoin(const QgsVectorJoinInfo &joinInfo)
Joins another vector layer to this layer.