Skip to content
Permalink
Browse files

Fix geometry generator symbol layers in dxf export

  • Loading branch information
mhugent committed Apr 19, 2018
1 parent cdee3b5 commit 543f501cd52218fc106619715b987d60430199be
Showing with 73 additions and 2 deletions.
  1. +66 −2 src/core/dxf/qgsdxfexport.cpp
  2. +7 −0 src/core/dxf/qgsdxfexport.h
@@ -28,6 +28,7 @@

#include "qgsdxfexport.h"
#include "qgsdxfpallabeling.h"
#include "qgsgeometrygeneratorsymbollayerv2.h"
#include "qgsvectordataprovider.h"
#include "qgspoint.h"
#include "qgsrendererv2.h"
@@ -1085,7 +1086,22 @@ void QgsDxfExport::writeEntities()
int nSymbolLayers = ( *symbolIt )->symbolLayerCount();
for ( int i = 0; i < nSymbolLayers; ++i )
{
addFeature( sctx, ct, lName, ( *symbolIt )->symbolLayer( i ), *symbolIt );
QgsSymbolLayerV2* sl = ( *symbolIt )->symbolLayer( i );
if ( !sl )
{
continue;
}

bool isGeometryGenerator = ( sl->layerType() == "GeometryGenerator" );

if ( isGeometryGenerator )
{
addGeometryGeneratorSymbolLayer( sctx, ct, lName, sl, true );
}
else
{
addFeature( sctx, ct, lName, sl, *symbolIt );
}
}
}
}
@@ -1097,7 +1113,15 @@ void QgsDxfExport::writeEntities()
{
continue;
}
addFeature( sctx, ct, lName, s->symbolLayer( 0 ), s );

if ( s->symbolLayer( 0 )->layerType() == "GeometryGenerator" )
{
addGeometryGeneratorSymbolLayer( sctx, ct, lName, s->symbolLayer( 0 ), false );
}
else
{
addFeature( sctx, ct, lName, s->symbolLayer( 0 ), s );
}
}

if ( lp )
@@ -3959,6 +3983,46 @@ void QgsDxfExport::addFeature( QgsSymbolV2RenderContext& ctx, const QgsCoordinat
}
}

void QgsDxfExport::addGeometryGeneratorSymbolLayer( QgsSymbolV2RenderContext &ctx, const QgsCoordinateTransform *ct, const QString &layer, QgsSymbolLayerV2 *symbolLayer, bool allSymbolLayers )
{
QgsGeometryGeneratorSymbolLayerV2* gg = dynamic_cast<QgsGeometryGeneratorSymbolLayerV2*>( symbolLayer );
if ( !gg )
{
return;
}

const QgsFeature* fet = ctx.feature();
if ( !fet )
{
return;
}

QgsFeature f = *fet;

QgsExpressionContext& expressionContext = ctx.renderContext().expressionContext();
QgsExpression geomExpr( gg->geometryExpression() );
geomExpr.prepare( &expressionContext );
QgsGeometry geom = geomExpr.evaluate( &expressionContext ).value<QgsGeometry>();
f.setGeometry( geom );

QgsSymbolV2* symbol = gg->subSymbol();
if ( symbol && symbol->symbolLayerCount() > 0 )
{
QgsExpressionContextScope* symbolExpressionContextScope = symbol->symbolRenderContext()->expressionContextScope();
symbolExpressionContextScope->setFeature( f );

ctx.setFeature( &f );

int nSymbolLayers = allSymbolLayers ? symbol->symbolLayerCount() : 1;
for ( int i = 0; i < nSymbolLayers; ++i )
{
addFeature( ctx, ct, layer, symbol->symbolLayer( i ), symbol );
}

ctx.setFeature( fet );
}
}

QColor QgsDxfExport::colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer, QgsSymbolV2RenderContext &ctx )
{
if ( !symbolLayer )
@@ -477,6 +477,13 @@ class CORE_EXPORT QgsDxfExport
void writeLinetype( const QString &styleName, const QVector<qreal> &pattern, QgsSymbolV2::OutputUnit u );

void addFeature( QgsSymbolV2RenderContext &ctx, const QgsCoordinateTransform *ct, const QString &layer, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol );
/** Writes geometry generator symbol layer
@param ctx the symbol render context
@param ct the coordinate transform
@param layer the layer name
@param symbolLayer the symbollayer to write to the dxf file
@param allSymbolLayers if true, all symbol layers of the subsymbol are writeen. If false, only the first one is written*/
void addGeometryGeneratorSymbolLayer( QgsSymbolV2RenderContext &ctx, const QgsCoordinateTransform *ct, const QString &layer, QgsSymbolLayerV2 *symbolLayer, bool allSymbolLayers );

//returns dxf palette index from symbol layer color
static QColor colorFromSymbolLayer( const QgsSymbolLayerV2 *symbolLayer, QgsSymbolV2RenderContext &ctx );

0 comments on commit 543f501

Please sign in to comment.
You can’t perform that action at this time.