Skip to content
Permalink
Browse files
Fetch attributes for symbology export
  • Loading branch information
mhugent committed Dec 23, 2012
1 parent 7fef39e commit 5327da987cad68e4ee3357763c1085aa48aff912
Showing with 23 additions and 1 deletion.
  1. +21 −1 src/core/qgsvectorfilewriter.cpp
  2. +2 −0 src/core/qgsvectorfilewriter.h
@@ -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();
@@ -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();
@@ -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 ) ) );
}
}
}
}
@@ -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 );

};

0 comments on commit 5327da9

Please sign in to comment.