Skip to content

Commit

Permalink
Fetch attributes for symbology export
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Dec 23, 2012
1 parent 7fef39e commit 5327da9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/core/qgsvectorfilewriter.cpp
Expand Up @@ -735,6 +735,8 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
QgsAttributeList allAttr = skipAttributeCreation ? QgsAttributeList() : layer->pendingAllAttributesList();
QgsFeature fet;

//add possible attributes needed by renderer
writer->addRendererAttributes( layer, allAttr );
layer->select( allAttr, QgsRectangle(), layer->wkbType() != QGis::WKBNoGeometry );

const QgsFeatureIds& ids = layer->selectedFeaturesIds();
Expand Down Expand Up @@ -810,10 +812,11 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
return ErrProjection;
}
}
if ( skipAttributeCreation )
if ( allAttr.size() < 1 && skipAttributeCreation )
{
fet.clearAttributeMap();
}

if ( !writer->addFeature( fet, layer->rendererV2(), mapUnits ) )
{
WriterError err = writer->hasError();
Expand Down Expand Up @@ -1423,3 +1426,20 @@ QgsFeatureRendererV2* QgsVectorFileWriter::symbologyRenderer( QgsVectorLayer* vl

return vl->rendererV2();
}

void QgsVectorFileWriter::addRendererAttributes( QgsVectorLayer* vl, QgsAttributeList& attList )
{
QgsFeatureRendererV2* renderer = symbologyRenderer( vl );
if ( renderer )
{
QList<QString> rendererAttributes = renderer->usedAttributes();
for ( int i = 0; i < rendererAttributes.size(); ++i )
{
int index = vl->fieldNameIndex( rendererAttributes.at( i ) );
if ( index != -1 )
{
attList.push_back( vl->fieldNameIndex( rendererAttributes.at( i ) ) );
}
}
}
}
2 changes: 2 additions & 0 deletions src/core/qgsvectorfilewriter.h
Expand Up @@ -208,6 +208,8 @@ class CORE_EXPORT QgsVectorFileWriter
void startRender( QgsVectorLayer* vl ) const;
void stopRender( QgsVectorLayer* vl ) const;
QgsFeatureRendererV2* symbologyRenderer( QgsVectorLayer* vl ) const;
/**Adds attributes needed for classification*/
void addRendererAttributes( QgsVectorLayer* vl, QgsAttributeList& attList );

};

Expand Down

0 comments on commit 5327da9

Please sign in to comment.