Skip to content

Commit a58e710

Browse files
committedJun 26, 2016
dxf export: add support for expression contexts and rotated symbols (fixes #14495)
(cherry picked from commit c30f71a)
1 parent 5ce8a45 commit a58e710

14 files changed

+109
-106
lines changed
 

‎python/core/symbology-ng/qgsellipsesymbollayerv2.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class QgsEllipseSymbolLayerV2 : QgsMarkerSymbolLayerV2
2121
void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;
2222
void writeSldMarker( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;
2323

24-
bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext* context, const QgsFeature* f, QPointF shift = QPointF( 0.0, 0.0 ) ) const;
24+
bool writeDxf( QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolV2RenderContext &context, QPointF shift = QPointF( 0.0, 0.0 ) ) const;
2525

2626
void setSymbolName( const QString& name );
2727
QString symbolName() const;

‎python/core/symbology-ng/qgsmarkersymbollayerv2.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class QgsSimpleMarkerSymbolLayerV2 : QgsMarkerSymbolLayerV2
6767
void setOutlineWidthMapUnitScale( const QgsMapUnitScale& scale);
6868
const QgsMapUnitScale& outlineWidthMapUnitScale() const;
6969

70-
bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext* context, const QgsFeature* f, QPointF shift = QPointF( 0.0, 0.0 ) ) const;
70+
bool writeDxf( QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolV2RenderContext &context, QPointF shift = QPointF( 0.0, 0.0 ) ) const;
7171

7272
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
7373
QgsSymbolV2::OutputUnit outputUnit() const;
@@ -146,7 +146,7 @@ class QgsSvgMarkerSymbolLayerV2 : QgsMarkerSymbolLayerV2
146146
void setMapUnitScale( const QgsMapUnitScale& scale );
147147
QgsMapUnitScale mapUnitScale() const;
148148

149-
bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext* context, const QgsFeature* f, QPointF shift = QPointF( 0.0, 0.0 ) ) const;
149+
bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext &context, QPointF shift = QPointF( 0.0, 0.0 ) ) const;
150150

151151
QRectF bounds( QPointF point, QgsSymbolV2RenderContext& context );
152152
};

‎python/core/symbology-ng/qgssymbollayerv2.sip

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,13 @@ class QgsSymbolLayerV2
252252
*/
253253
virtual QVariant evaluateDataDefinedProperty( const QString& property, const QgsSymbolV2RenderContext& context, const QVariant& defaultVal = QVariant(), bool *ok = 0 ) const;
254254

255-
virtual bool writeDxf( QgsDxfExport& e,
256-
double mmMapUnitScaleFactor,
257-
const QString& layerName,
258-
QgsSymbolV2RenderContext* context,
259-
const QgsFeature* f,
260-
QPointF shift = QPointF( 0.0, 0.0 ) ) const;
255+
virtual bool writeDxf( QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolV2RenderContext &context, QPointF shift = QPointF( 0.0, 0.0 ) ) const;
261256

262257
virtual double dxfWidth( const QgsDxfExport& e, QgsSymbolV2RenderContext& context ) const;
263258
virtual double dxfOffset( const QgsDxfExport& e, QgsSymbolV2RenderContext& context ) const;
264259

265260
virtual QColor dxfColor( QgsSymbolV2RenderContext& context ) const;
261+
virtual double dxfAngle( QgsSymbolV2RenderContext& context ) const;
266262

267263
virtual QVector<qreal> dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const;
268264
virtual Qt::PenStyle dxfPenStyle() const;

‎src/core/dxf/qgsdxfexport.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ void QgsDxfExport::writeBlocks()
870870
writeGroup( 1, "" );
871871

872872
// maplayer 0 -> block receives layer from INSERT statement
873-
ml->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, ml->sizeUnit(), mMapUnits ), "0", &ctx, nullptr );
873+
ml->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, ml->sizeUnit(), mMapUnits ), "0", ctx );
874874

875875
writeGroup( 0, "ENDBLK" );
876876
writeHandle();
@@ -984,7 +984,7 @@ void QgsDxfExport::writeEntities()
984984
continue;
985985
}
986986

987-
QgsFeatureRequest freq = QgsFeatureRequest().setSubsetOfAttributes( attributes, vl->fields() );
987+
QgsFeatureRequest freq = QgsFeatureRequest().setSubsetOfAttributes( attributes, vl->fields() ).setExpressionContext( ctx.expressionContext() );
988988
if ( !mExtent.isEmpty() )
989989
{
990990
freq.setFilterRect( mExtent );
@@ -3329,7 +3329,7 @@ void QgsDxfExport::endSection()
33293329
writeGroup( 0, "ENDSEC" );
33303330
}
33313331

3332-
void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const QColor& color, const QgsFeature* f, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol )
3332+
void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const QColor& color, QgsSymbolV2RenderContext &ctx, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol, double angle )
33333333
{
33343334
#if 0
33353335
// debug: draw rectangle for debugging
@@ -3356,9 +3356,7 @@ void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const Q
33563356
const QgsMarkerSymbolLayerV2* msl = dynamic_cast< const QgsMarkerSymbolLayerV2* >( symbolLayer );
33573357
if ( msl && symbol )
33583358
{
3359-
QgsRenderContext ct;
3360-
QgsSymbolV2RenderContext ctx( ct, QgsSymbolV2::MapUnit, symbol->alpha(), false, symbol->renderHints(), f );
3361-
if ( symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, msl->sizeUnit(), mMapUnits ), layer, &ctx, f, QPointF( pt.x(), pt.y() ) ) )
3359+
if ( symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, msl->sizeUnit(), mMapUnits ), layer, ctx, QPointF( pt.x(), pt.y() ) ) )
33623360
{
33633361
return;
33643362
}
@@ -3374,6 +3372,7 @@ void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const Q
33743372
writeGroup( 100, "AcDbBlockReference" );
33753373
writeGroup( 8, layer );
33763374
writeGroup( 2, blockIt.value() ); // Block name
3375+
writeGroup( 50, angle ); // angle
33773376
writeGroup( 0, pt ); // Insertion point (in OCS)
33783377
}
33793378
}
@@ -3659,10 +3658,12 @@ void QgsDxfExport::addFeature( QgsSymbolV2RenderContext& ctx, const QString& lay
36593658
Qt::BrushStyle brushStyle( Qt::NoBrush );
36603659
double width = -1;
36613660
double offset = 0.0;
3661+
double angle = 0.0;
36623662
if ( mSymbologyExport != NoSymbology && symbolLayer )
36633663
{
36643664
width = symbolLayer->dxfWidth( *this, ctx );
36653665
offset = symbolLayer->dxfOffset( *this, ctx );
3666+
angle = symbolLayer->dxfAngle( ctx );
36663667
penStyle = symbolLayer->dxfPenStyle();
36673668
brushStyle = symbolLayer->dxfBrushStyle();
36683669

@@ -3679,7 +3680,7 @@ void QgsDxfExport::addFeature( QgsSymbolV2RenderContext& ctx, const QString& lay
36793680
// single point
36803681
if ( geometryType == QGis::WKBPoint || geometryType == QGis::WKBPoint25D )
36813682
{
3682-
writePoint( geom->asPoint(), layer, penColor, fet, symbolLayer, symbol );
3683+
writePoint( geom->asPoint(), layer, penColor, ctx, symbolLayer, symbol, angle );
36833684
return;
36843685
}
36853686

@@ -3690,7 +3691,7 @@ void QgsDxfExport::addFeature( QgsSymbolV2RenderContext& ctx, const QString& lay
36903691
QgsMultiPoint::const_iterator it = multiPoint.constBegin();
36913692
for ( ; it != multiPoint.constEnd(); ++it )
36923693
{
3693-
writePoint( *it, layer, penColor, fet, symbolLayer, symbol );
3694+
writePoint( *it, layer, penColor, ctx, symbolLayer, symbol, angle );
36943695
}
36953696

36963697
return;

‎src/core/dxf/qgsdxfexport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class CORE_EXPORT QgsDxfExport
327327
void startSection();
328328
void endSection();
329329

330-
void writePoint( const QgsPoint &pt, const QString &layer, const QColor& color, const QgsFeature *f, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol );
330+
void writePoint( const QgsPoint &pt, const QString &layer, const QColor& color, QgsSymbolV2RenderContext &ctx, const QgsSymbolLayerV2 *symbolLayer, const QgsSymbolV2 *symbol, double angle );
331331
void writeVertex( const QgsPoint &pt, const QString &layer );
332332
void writeDefaultLinetypes();
333333
void writeSymbolLayerLinetype( const QgsSymbolLayerV2 *symbolLayer );

‎src/core/symbology-ng/qgsellipsesymbollayerv2.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -686,17 +686,17 @@ QRectF QgsEllipseSymbolLayerV2::bounds( QPointF point, QgsSymbolV2RenderContext&
686686
return symbolBounds;
687687
}
688688

689-
bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext *context, const QgsFeature*, QPointF shift ) const
689+
bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext &context, QPointF shift ) const
690690
{
691691
//width
692692
double symbolWidth = mSymbolWidth;
693693

694694
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH ) ) //1. priority: data defined setting on symbol layer le
695695
{
696-
context->setOriginalValueVariable( mSymbolWidth );
697-
symbolWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, *context, mSymbolWidth ).toDouble();
696+
context.setOriginalValueVariable( mSymbolWidth );
697+
symbolWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mSymbolWidth ).toDouble();
698698
}
699-
else if ( context->renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
699+
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
700700
{
701701
symbolWidth = mSize;
702702
}
@@ -709,10 +709,10 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
709709
double symbolHeight = mSymbolHeight;
710710
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT ) ) //1. priority: data defined setting on symbol layer level
711711
{
712-
context->setOriginalValueVariable( mSymbolHeight );
713-
symbolHeight = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT, *context, mSymbolHeight ).toDouble();
712+
context.setOriginalValueVariable( mSymbolHeight );
713+
symbolHeight = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT, context, mSymbolHeight ).toDouble();
714714
}
715-
else if ( context->renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
715+
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
716716
{
717717
symbolHeight = mSize;
718718
}
@@ -726,8 +726,8 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
726726

727727
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH ) )
728728
{
729-
context->setOriginalValueVariable( mOutlineWidth );
730-
outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, *context, mOutlineWidth ).toDouble();
729+
context.setOriginalValueVariable( mOutlineWidth );
730+
outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, context, mOutlineWidth ).toDouble();
731731
}
732732
if ( mOutlineWidthUnit == QgsSymbolV2::MM )
733733
{
@@ -739,8 +739,8 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
739739
QColor fc = mColor;
740740
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL_COLOR ) )
741741
{
742-
context->setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mColor ) );
743-
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL_COLOR, *context, QVariant(), &ok ).toString();
742+
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mColor ) );
743+
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL_COLOR, context, QVariant(), &ok ).toString();
744744
if ( ok )
745745
fc = QgsSymbolLayerV2Utils::decodeColor( colorString );
746746
}
@@ -749,8 +749,8 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
749749
QColor oc = mOutlineColor;
750750
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_COLOR ) )
751751
{
752-
context->setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mOutlineColor ) );
753-
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_COLOR, *context, QVariant(), &ok ).toString();
752+
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mOutlineColor ) );
753+
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_COLOR, context, QVariant(), &ok ).toString();
754754
if ( ok )
755755
oc = QgsSymbolLayerV2Utils::decodeColor( colorString );
756756
}
@@ -759,22 +759,22 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
759759
QString symbolName = mSymbolName;
760760
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_SYMBOL_NAME ) )
761761
{
762-
context->setOriginalValueVariable( mSymbolName );
763-
symbolName = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_SYMBOL_NAME, *context, mSymbolName ).toString();
762+
context.setOriginalValueVariable( mSymbolName );
763+
symbolName = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_SYMBOL_NAME, context, mSymbolName ).toString();
764764
}
765765

766766
//offset
767767
double offsetX = 0;
768768
double offsetY = 0;
769-
markerOffset( *context, offsetX, offsetY );
769+
markerOffset( context, offsetX, offsetY );
770770
QPointF off( offsetX, offsetY );
771771

772772
//priority for rotation: 1. data defined symbol level, 2. symbol layer rotation (mAngle)
773773
double rotation = 0.0;
774774
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION ) )
775775
{
776-
context->setOriginalValueVariable( mAngle );
777-
rotation = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION, *context, mAngle ).toDouble() + mLineAngle;
776+
context.setOriginalValueVariable( mAngle );
777+
rotation = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION, context, mAngle ).toDouble() + mLineAngle;
778778
}
779779
else if ( !qgsDoubleNear( mAngle + mLineAngle, 0.0 ) )
780780
{

‎src/core/symbology-ng/qgsellipsesymbollayerv2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CORE_EXPORT QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
4040
void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const override;
4141
void writeSldMarker( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const override;
4242

43-
bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext* context, const QgsFeature* f, QPointF shift = QPointF( 0.0, 0.0 ) ) const override;
43+
bool writeDxf( QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolV2RenderContext &context, QPointF shift = QPointF( 0.0, 0.0 ) ) const override;
4444

4545
void setSymbolName( const QString& name ) { mSymbolName = name; }
4646
QString symbolName() const { return mSymbolName; }

‎src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,17 @@ QColor QgsSimpleFillSymbolLayerV2::dxfColor( QgsSymbolV2RenderContext &context )
422422
return mBorderColor;
423423
}
424424

425+
double QgsSimpleFillSymbolLayerV2::dxfAngle( QgsSymbolV2RenderContext &context ) const
426+
{
427+
double angle = mAngle;
428+
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_ANGLE ) )
429+
{
430+
context.setOriginalValueVariable( mAngle );
431+
angle = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_ANGLE, context, mAngle ).toDouble();
432+
}
433+
return angle;
434+
}
435+
425436
Qt::PenStyle QgsSimpleFillSymbolLayerV2::dxfPenStyle() const
426437
{
427438
return mBorderStyle;

‎src/core/symbology-ng/qgsfillsymbollayerv2.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
118118

119119
double dxfWidth( const QgsDxfExport& e, QgsSymbolV2RenderContext& context ) const override;
120120
QColor dxfColor( QgsSymbolV2RenderContext& context ) const override;
121+
double dxfAngle( QgsSymbolV2RenderContext& context ) const override;
122+
121123
Qt::PenStyle dxfPenStyle() const override;
122124
QColor dxfBrushColor( QgsSymbolV2RenderContext &context ) const override;
123125
Qt::BrushStyle dxfBrushStyle() const override;
@@ -562,14 +564,15 @@ class CORE_EXPORT QgsImageFillSymbolLayer: public QgsFillSymbolLayerV2
562564
void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
563565
QgsSymbolV2::OutputUnit outputUnit() const override;
564566

565-
void setMapUnitScale( const QgsMapUnitScale& scale ) override;
567+
void setMapUnitScale( const QgsMapUnitScale &scale ) override;
566568
QgsMapUnitScale mapUnitScale() const override;
567569

568570
virtual double estimateMaxBleed() const override;
569571

570-
virtual double dxfWidth( const QgsDxfExport& e, QgsSymbolV2RenderContext& context ) const override;
571-
virtual QColor dxfColor( QgsSymbolV2RenderContext& context ) const override;
572-
virtual Qt::PenStyle dxfPenStyle() const override;
572+
double dxfWidth( const QgsDxfExport& e, QgsSymbolV2RenderContext& context ) const override;
573+
QColor dxfColor( QgsSymbolV2RenderContext& context ) const override;
574+
575+
Qt::PenStyle dxfPenStyle() const override;
573576

574577
QSet<QString> usedAttributes() const override;
575578

‎src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -830,25 +830,21 @@ void QgsSimpleMarkerSymbolLayerV2::drawMarker( QPainter* p, QgsSymbolV2RenderCon
830830
}
831831
}
832832

833-
bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext *context, const QgsFeature*, QPointF shift ) const
833+
bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext &context, QPointF shift ) const
834834
{
835835
//data defined size?
836836
double size = mSize;
837837

838-
bool hasDataDefinedSize = false;
839-
if ( context )
840-
{
841-
hasDataDefinedSize = context->renderHints() & QgsSymbolV2::DataDefinedSizeScale || hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_SIZE );
842-
}
838+
bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale || hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_SIZE );
843839

844840
//data defined size
845841
bool ok = true;
846842
if ( hasDataDefinedSize )
847843
{
848844
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_SIZE ) )
849845
{
850-
context->setOriginalValueVariable( mSize );
851-
size = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_SIZE, *context, mSize, &ok ).toDouble();
846+
context.setOriginalValueVariable( mSize );
847+
size = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_SIZE, context, mSize, &ok ).toDouble();
852848
}
853849

854850
if ( ok )
@@ -863,7 +859,7 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
863859
}
864860
}
865861

866-
size = QgsSymbolLayerV2Utils::convertToPainterUnits( context->renderContext(), size, mSizeUnit, mSizeMapUnitScale );
862+
size = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), size, mSizeUnit, mSizeMapUnitScale );
867863
}
868864
if ( mSizeUnit == QgsSymbolV2::MM )
869865
{
@@ -874,10 +870,10 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
874870
//outlineWidth
875871
double outlineWidth = mOutlineWidth;
876872

877-
if ( context && hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH ) )
873+
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH ) )
878874
{
879-
context->setOriginalValueVariable( mOutlineWidth );
880-
outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, *context, mOutlineWidth ).toDouble();
875+
context.setOriginalValueVariable( mOutlineWidth );
876+
outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, context, mOutlineWidth ).toDouble();
881877
}
882878
if ( mSizeUnit == QgsSymbolV2::MM )
883879
{
@@ -887,43 +883,41 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
887883
//color
888884
QColor pc = mPen.color();
889885
QColor bc = mBrush.color();
890-
if ( context && hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR ) )
886+
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR ) )
891887
{
892-
context->setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mColor ) );
893-
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR, *context, QVariant(), &ok ).toString();
888+
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mColor ) );
889+
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR, context, QVariant(), &ok ).toString();
894890
if ( ok )
895891
bc = QgsSymbolLayerV2Utils::decodeColor( colorString );
896892
}
897-
if ( context && hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR_BORDER ) )
893+
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR_BORDER ) )
898894
{
899-
context->setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mBorderColor ) );
900-
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR_BORDER, *context, QVariant(), &ok ).toString();
895+
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mBorderColor ) );
896+
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR_BORDER, context, QVariant(), &ok ).toString();
901897
if ( ok )
902898
pc = QgsSymbolLayerV2Utils::decodeColor( colorString );
903899
}
904900

905901
//offset
906902
double offsetX = 0;
907903
double offsetY = 0;
908-
if ( context )
909-
{
910-
markerOffset( *context, offsetX, offsetY );
911-
}
904+
markerOffset( context, offsetX, offsetY );
905+
912906
QPointF off( offsetX, offsetY );
913907

914908
//angle
915909
double angle = mAngle + mLineAngle;
916-
if ( context && hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_ANGLE ) )
910+
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_ANGLE ) )
917911
{
918-
context->setOriginalValueVariable( mAngle );
919-
angle = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_ANGLE, *context, mAngle ).toDouble() + mLineAngle;
912+
context.setOriginalValueVariable( mAngle );
913+
angle = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_ANGLE, context, mAngle ).toDouble() + mLineAngle;
920914
}
921915

922916
QString name( mName );
923-
if ( context && hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_NAME ) )
917+
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_NAME ) )
924918
{
925-
context->setOriginalValueVariable( mName );
926-
name = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_NAME, *context, QVariant(), &ok ).toString();
919+
context.setOriginalValueVariable( mName );
920+
name = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_NAME, context, QVariant(), &ok ).toString();
927921
}
928922

929923
angle = -angle; //rotation in Qt is counterclockwise
@@ -1654,22 +1648,21 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::createFromSld( QDomElement &element
16541648
return m;
16551649
}
16561650

1657-
bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext *context, const QgsFeature*,
1658-
QPointF shift ) const
1651+
bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext &context, QPointF shift ) const
16591652
{
16601653
Q_UNUSED( layerName );
16611654
Q_UNUSED( shift ); //todo...
16621655

16631656
//size
16641657
double size = mSize;
16651658

1666-
bool hasDataDefinedSize = context->renderHints() & QgsSymbolV2::DataDefinedSizeScale || hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_SIZE );
1659+
bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale || hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_SIZE );
16671660

16681661
bool ok = true;
16691662
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_SIZE ) )
16701663
{
1671-
context->setOriginalValueVariable( mSize );
1672-
size = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_SIZE, *context, mSize, &ok ).toDouble();
1664+
context.setOriginalValueVariable( mSize );
1665+
size = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_SIZE, context, mSize, &ok ).toDouble();
16731666
}
16741667

16751668
if ( hasDataDefinedSize && ok )
@@ -1696,8 +1689,8 @@ bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
16961689

16971690
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OFFSET ) )
16981691
{
1699-
context->setOriginalValueVariable( QgsSymbolLayerV2Utils::encodePoint( mOffset ) );
1700-
QString offsetString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OFFSET, *context, QVariant(), &ok ).toString();
1692+
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodePoint( mOffset ) );
1693+
QString offsetString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OFFSET, context, QVariant(), &ok ).toString();
17011694
if ( ok )
17021695
offset = QgsSymbolLayerV2Utils::decodePoint( offsetString );
17031696
}
@@ -1714,8 +1707,8 @@ bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
17141707
double angle = mAngle + mLineAngle;
17151708
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_ANGLE ) )
17161709
{
1717-
context->setOriginalValueVariable( mAngle );
1718-
angle = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_ANGLE, *context, mAngle ).toDouble() + mLineAngle;
1710+
context.setOriginalValueVariable( mAngle );
1711+
angle = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_ANGLE, context, mAngle ).toDouble() + mLineAngle;
17191712
}
17201713
//angle = -angle; //rotation in Qt is counterclockwise
17211714
if ( angle )
@@ -1724,39 +1717,39 @@ bool QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScale
17241717
QString path = mPath;
17251718
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_NAME ) )
17261719
{
1727-
context->setOriginalValueVariable( mPath );
1728-
path = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_NAME, *context, mPath ).toString();
1720+
context.setOriginalValueVariable( mPath );
1721+
path = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_NAME, context, mPath ).toString();
17291722
}
17301723

17311724
double outlineWidth = mOutlineWidth;
17321725
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH ) )
17331726
{
1734-
context->setOriginalValueVariable( mOutlineWidth );
1735-
outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, *context, mOutlineWidth ).toDouble();
1727+
context.setOriginalValueVariable( mOutlineWidth );
1728+
outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, context, mOutlineWidth ).toDouble();
17361729
}
1737-
outlineWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context->renderContext(), outlineWidth, mOutlineWidthUnit, mOutlineWidthMapUnitScale );
1730+
outlineWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), outlineWidth, mOutlineWidthUnit, mOutlineWidthMapUnitScale );
17381731

17391732
QColor fillColor = mColor;
17401733
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL ) )
17411734
{
1742-
context->setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mColor ) );
1743-
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL, *context, QVariant(), &ok ).toString();
1735+
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mColor ) );
1736+
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL, context, QVariant(), &ok ).toString();
17441737
if ( ok )
17451738
fillColor = QgsSymbolLayerV2Utils::decodeColor( colorString );
17461739
}
17471740

17481741
QColor outlineColor = mOutlineColor;
17491742
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE ) )
17501743
{
1751-
context->setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mOutlineColor ) );
1752-
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE, *context, QVariant(), &ok ).toString();
1744+
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mOutlineColor ) );
1745+
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE, context, QVariant(), &ok ).toString();
17531746
if ( ok )
17541747
outlineColor = QgsSymbolLayerV2Utils::decodeColor( colorString );
17551748
}
17561749

17571750
const QByteArray &svgContent = QgsSvgCache::instance()->svgContent( path, size, fillColor, outlineColor, outlineWidth,
1758-
context->renderContext().scaleFactor(),
1759-
context->renderContext().rasterScaleFactor() );
1751+
context.renderContext().scaleFactor(),
1752+
context.renderContext().rasterScaleFactor() );
17601753

17611754
//if current entry image is 0: cache image for entry
17621755
// checks to see if image will fit into cache

‎src/core/symbology-ng/qgsmarkersymbollayerv2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
9696
void setOutlineWidthMapUnitScale( const QgsMapUnitScale& scale ) { mOutlineWidthMapUnitScale = scale; }
9797
const QgsMapUnitScale& outlineWidthMapUnitScale() const { return mOutlineWidthMapUnitScale; }
9898

99-
bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext* context, const QgsFeature* f, QPointF shift = QPointF( 0.0, 0.0 ) ) const override;
99+
bool writeDxf( QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolV2RenderContext &context, QPointF shift = QPointF( 0.0, 0.0 ) ) const override;
100100

101101
void setOutputUnit( QgsSymbolV2::OutputUnit unit ) override;
102102
QgsSymbolV2::OutputUnit outputUnit() const override;
@@ -201,7 +201,7 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
201201
void setMapUnitScale( const QgsMapUnitScale& scale ) override;
202202
QgsMapUnitScale mapUnitScale() const override;
203203

204-
bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext* context, const QgsFeature* f, QPointF shift = QPointF( 0.0, 0.0 ) ) const override;
204+
bool writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext &context, QPointF shift = QPointF( 0.0, 0.0 ) ) const override;
205205

206206
QRectF bounds( QPointF point, QgsSymbolV2RenderContext& context ) override;
207207

‎src/core/symbology-ng/qgssymbollayerv2.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,12 @@ QVariant QgsSymbolLayerV2::evaluateDataDefinedProperty( const QString& property,
256256
return defaultVal;
257257
}
258258

259-
bool QgsSymbolLayerV2::writeDxf( QgsDxfExport& e,
260-
double mmMapUnitScaleFactor,
261-
const QString& layerName,
262-
QgsSymbolV2RenderContext *context,
263-
const QgsFeature* f,
264-
QPointF shift ) const
259+
bool QgsSymbolLayerV2::writeDxf( QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolV2RenderContext &context, QPointF shift ) const
265260
{
266261
Q_UNUSED( e );
267262
Q_UNUSED( mmMapUnitScaleFactor );
268263
Q_UNUSED( layerName );
269264
Q_UNUSED( context );
270-
Q_UNUSED( f );
271265
Q_UNUSED( shift );
272266
return false;
273267
}
@@ -292,6 +286,12 @@ QColor QgsSymbolLayerV2::dxfColor( QgsSymbolV2RenderContext &context ) const
292286
return color();
293287
}
294288

289+
double QgsSymbolLayerV2::dxfAngle( QgsSymbolV2RenderContext &context ) const
290+
{
291+
Q_UNUSED( context );
292+
return 0.0;
293+
}
294+
295295
QVector<qreal> QgsSymbolLayerV2::dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const
296296
{
297297
Q_UNUSED( unit );

‎src/core/symbology-ng/qgssymbollayerv2.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,13 @@ class CORE_EXPORT QgsSymbolLayerV2
235235
*/
236236
virtual QVariant evaluateDataDefinedProperty( const QString& property, const QgsSymbolV2RenderContext& context, const QVariant& defaultVal = QVariant(), bool *ok = nullptr ) const;
237237

238-
virtual bool writeDxf( QgsDxfExport& e,
239-
double mmMapUnitScaleFactor,
240-
const QString& layerName,
241-
QgsSymbolV2RenderContext* context,
242-
const QgsFeature* f,
243-
QPointF shift = QPointF( 0.0, 0.0 ) ) const;
238+
virtual bool writeDxf( QgsDxfExport &e, double mmMapUnitScaleFactor, const QString &layerName, QgsSymbolV2RenderContext &context, QPointF shift = QPointF( 0.0, 0.0 ) ) const;
244239

245240
virtual double dxfWidth( const QgsDxfExport& e, QgsSymbolV2RenderContext& context ) const;
246241
virtual double dxfOffset( const QgsDxfExport& e, QgsSymbolV2RenderContext& context ) const;
247242

248243
virtual QColor dxfColor( QgsSymbolV2RenderContext& context ) const;
244+
virtual double dxfAngle( QgsSymbolV2RenderContext& context ) const;
249245

250246
virtual QVector<qreal> dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const;
251247
virtual Qt::PenStyle dxfPenStyle() const;

‎src/core/symbology-ng/qgssymbolv2.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,11 @@ void QgsSymbolV2::startRender( QgsRenderContext& context, const QgsFields* field
469469
void QgsSymbolV2::stopRender( QgsRenderContext& context )
470470
{
471471
Q_UNUSED( context )
472-
Q_FOREACH ( QgsSymbolLayerV2* layer, mLayers )
473-
layer->stopRender( *mSymbolRenderContext );
472+
if ( mSymbolRenderContext )
473+
{
474+
Q_FOREACH ( QgsSymbolLayerV2* layer, mLayers )
475+
layer->stopRender( *mSymbolRenderContext );
476+
}
474477

475478
delete mSymbolRenderContext;
476479
mSymbolRenderContext = nullptr;

0 commit comments

Comments
 (0)
Please sign in to comment.