Skip to content
Permalink
Browse files
Use start / stopRender for renderer in vector symbology export
  • Loading branch information
mhugent committed Dec 23, 2012
1 parent fa5cb77 commit d9c79911976d146764bfcbf4fad9d30e9abf7433
Showing with 58 additions and 1 deletion.
  1. +52 −0 src/core/qgsvectorfilewriter.cpp
  2. +5 −0 src/core/qgsvectorfilewriter.h
  3. +1 −1 src/core/symbology-ng/qgslinesymbollayerv2.cpp
@@ -779,6 +779,8 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
mapUnits = ct->destCRS().mapUnits();
}

writer->startRender( layer );

// write all features
while ( layer->nextFeature( fet ) )
{
@@ -839,6 +841,7 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
n++;
}

writer->stopRender( layer );
delete writer;

if ( shallTransform )
@@ -1241,6 +1244,8 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::exportFeaturesSymbolLevels
mapUnits = ct->destCRS().mapUnits();
}

startRender( layer );

//fetch features
QgsFeature fet;
QgsSymbolV2* featureSymbol = 0;
@@ -1346,6 +1351,8 @@ QgsVectorFileWriter::WriterError QgsVectorFileWriter::exportFeaturesSymbolLevels
}
}

stopRender( layer );

if ( nErrors > 0 && errorMessage )
{
*errorMessage += QObject::tr( "\nOnly %1 of %2 features written." ).arg( nTotalFeatures - nErrors ).arg( nTotalFeatures );
@@ -1371,3 +1378,48 @@ double QgsVectorFileWriter::widthScaleFactor( double scaleDenominator, QgsSymbol
}
return 1.0; //todo: map units
}

QgsRenderContext QgsVectorFileWriter::renderContext() const
{
QgsRenderContext context;
context.setRendererScale( mSymbologyScaleDenominator );
return context;
}

void QgsVectorFileWriter::startRender( QgsVectorLayer* vl ) const
{
QgsFeatureRendererV2* renderer = symbologyRenderer( vl );
if ( !renderer )
{
return;
}

QgsRenderContext ctx = renderContext();
renderer->startRender( ctx, vl );
}

void QgsVectorFileWriter::stopRender( QgsVectorLayer* vl ) const
{
QgsFeatureRendererV2* renderer = symbologyRenderer( vl );
if ( !renderer )
{
return;
}

QgsRenderContext ctx = renderContext();
renderer->stopRender( ctx );
}

QgsFeatureRendererV2* QgsVectorFileWriter::symbologyRenderer( QgsVectorLayer* vl ) const
{
if ( mSymbologyExport == NoSymbology )
{
return 0;
}
if ( !vl || !vl->isUsingRendererV2() )
{
return 0;
}

return vl->rendererV2();
}
@@ -204,6 +204,11 @@ class CORE_EXPORT QgsVectorFileWriter
/**Writes features considering symbol level order*/
WriterError exportFeaturesSymbolLevels( QgsVectorLayer* layer, const QgsCoordinateTransform* ct, QString* errorMessage = 0 );
double widthScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
QgsRenderContext renderContext() const;
void startRender( QgsVectorLayer* vl ) const;
void stopRender( QgsVectorLayer* vl ) const;
QgsFeatureRendererV2* symbologyRenderer( QgsVectorLayer* vl ) const;

};

#endif
@@ -209,7 +209,7 @@ QString QgsSimpleLineSymbolLayerV2::ogrFeatureStyle( double widthScaleFactor ) c
symbolStyle.append( "mm" );

//dash dot vector
if ( mCustomDashVector.size() > 0 )
if ( mUseCustomDashPattern && mCustomDashVector.size() > 0 )
{
symbolStyle.append( ",p:\"" );
QVector<qreal>::const_iterator pIt = mCustomDashVector.constBegin();

0 comments on commit d9c7991

Please sign in to comment.