Skip to content

Commit a58e710

Browse files
committed
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

0 commit comments

Comments
 (0)