22 #include <QDomElement>
84 int currentMaxIndex = 0;
86 QList< QgsVectorJoinInfo>::const_iterator joinIt =
mVectorJoins.constBegin();
96 QgsFieldMap::const_iterator fieldIt = joinFields.constBegin();
97 for ( ; fieldIt != joinFields.constEnd(); ++fieldIt )
99 fields.insert( maxIndex + 1 + fieldIt.key(), fieldIt.value() );
104 maxIndex += ( currentMaxIndex + 1 );
111 QList< QgsVectorJoinInfo >::iterator joinIt =
mVectorJoins.begin();
122 sourceJoinFields.clear();
124 QgsAttributeList::const_iterator attIt = fetchAttributes.constBegin();
125 for ( ; attIt != fetchAttributes.constEnd(); ++attIt )
135 mFetchJoinInfos[ joinLayer].attributes.push_back( *attIt - indexOffset );
138 if ( !fetchAttributes.contains( joinInfo->
targetField ) )
151 int index = maxProviderIndex + 1;
154 QList< QgsVectorJoinInfo >::const_iterator joinIt =
mVectorJoins.constBegin();
163 QString joinFieldName = joinLayer->
pendingFields().value( joinIt->joinField ).name();
164 if ( joinFieldName.isEmpty() )
169 QVariant targetFieldValue = f.
attributeMap().value( joinIt->targetField );
170 if ( !targetFieldValue.isValid() )
178 index += ( currentMaxIndex + 1 );
183 QMap<QgsVectorLayer*, QgsFetchJoinInfo>::const_iterator joinIt =
mFetchJoinInfos.constBegin();
192 QString joinFieldName = joinLayer->
pendingFields().value( joinIt.value().joinInfo->joinField ).name();
193 if ( joinFieldName.isEmpty() )
198 QVariant targetFieldValue = f.
attributeMap().value( joinIt->joinInfo->targetField );
199 if ( !targetFieldValue.isValid() )
204 addJoinedFeatureAttributes( f, *( joinIt.value().joinInfo ), joinFieldName, targetFieldValue, joinIt.value().attributes, joinIt.value().indexOffset );
210 const QVariant& joinValue,
const QgsAttributeList& attributes,
int attributeIndexOffset )
212 const QHash< QString, QgsAttributeMap>& memoryCache = joinInfo.
cachedAttributes;
213 if ( !memoryCache.isEmpty() )
215 QgsAttributeMap featureAttributes = memoryCache.value( joinValue.toString() );
216 bool found = !featureAttributes.isEmpty();
217 QgsAttributeList::const_iterator attIt = attributes.constBegin();
218 for ( ; attIt != attributes.constEnd(); ++attIt )
222 f.
addAttribute( *attIt + attributeIndexOffset, featureAttributes.value( *attIt ) );
226 f.
addAttribute( *attIt + attributeIndexOffset, QVariant() );
240 QString bkSubsetString = subsetString;
241 if ( !subsetString.isEmpty() )
243 subsetString.append(
" AND " );
246 subsetString.append(
"\"" + joinFieldName +
"\"" +
" = " +
"\"" + joinValue.toString() +
"\"" );
257 QgsAttributeMap::const_iterator attIt = attMap.constBegin();
258 for ( ; attIt != attMap.constEnd(); ++attIt )
260 f.
addAttribute( attIt.key() + attributeIndexOffset, attIt.value() );
265 QgsAttributeList::const_iterator attIt = attributes.constBegin();
266 for ( ; attIt != attributes.constEnd(); ++attIt )
268 f.
addAttribute( *attIt + attributeIndexOffset, QVariant() );
278 QDomElement vectorJoinsElem = document.createElement(
"vectorjoins" );
279 layer_node.appendChild( vectorJoinsElem );
280 QList< QgsVectorJoinInfo >::const_iterator joinIt =
mVectorJoins.constBegin();
283 QDomElement joinElem = document.createElement(
"join" );
284 joinElem.setAttribute(
"targetField", joinIt->targetField );
285 joinElem.setAttribute(
"joinLayerId", joinIt->joinLayerId );
286 joinElem.setAttribute(
"joinField", joinIt->joinField );
287 joinElem.setAttribute(
"memoryCache", !joinIt->cachedAttributes.isEmpty() );
288 vectorJoinsElem.appendChild( joinElem );
295 QDomElement vectorJoinsElem = layer_node.firstChildElement(
"vectorjoins" );
296 if ( !vectorJoinsElem.isNull() )
298 QDomNodeList joinList = vectorJoinsElem.elementsByTagName(
"join" );
299 for (
int i = 0; i < joinList.size(); ++i )
301 QDomElement infoElem = joinList.at( i ).toElement();
303 info.
joinField = infoElem.attribute(
"joinField" ).toInt();
304 info.
joinLayerId = infoElem.attribute(
"joinLayerId" );
305 info.
targetField = infoElem.attribute(
"targetField" ).toInt();
306 info.
memoryCache = infoElem.attribute(
"memoryCache" ).toInt();
314 int currentMaxIndex = 0;
315 int totIndex = maxProviderIndex + 1;
318 QList< QgsVectorJoinInfo>::const_iterator joinIt =
mVectorJoins.constBegin();
327 if ( joinLayer->
pendingFields().contains( index - totIndex ) )
329 indexOffset = totIndex;
334 totIndex += ( currentMaxIndex + 1 );
343 if ( fMap.size() < 1 )
347 QgsFieldMap::const_iterator endIt = fMap.constEnd();