Skip to content

Commit abf2fc6

Browse files
committed
Fix opacity in svg marker dxf export
1 parent a20ae46 commit abf2fc6

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/core/dxf/qgsdxfpaintengine.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ QgsDxfPaintEngine::QgsDxfPaintEngine( const QgsDxfPaintDevice* dxfDevice, QgsDxf
2424
: QPaintEngine( QPaintEngine::AllFeatures /*QPaintEngine::PainterPaths | QPaintEngine::PaintOutsidePaintEvent*/ )
2525
, mPaintDevice( dxfDevice )
2626
, mDxf( dxf )
27+
, mOpacity( 1.0 )
2728
{
2829
}
2930

@@ -64,6 +65,11 @@ void QgsDxfPaintEngine::updateState( const QPaintEngineState& state )
6465

6566
if ( state.state() & QPaintEngine::DirtyBrush )
6667
mBrush = state.brush();
68+
69+
if ( state.state() & QPaintEngine::DirtyOpacity )
70+
{
71+
mOpacity = state.opacity();
72+
}
6773
}
6874

6975
void QgsDxfPaintEngine::setRing( QgsPointSequenceV2 &polyline, const QPointF *points, int pointCount )
@@ -86,12 +92,12 @@ void QgsDxfPaintEngine::drawPolygon( const QPointF *points, int pointCount, Poly
8692
if ( mode == QPaintEngine::PolylineMode )
8793
{
8894
if ( mPen.style() != Qt::NoPen && mPen.brush().style() != Qt::NoBrush )
89-
mDxf->writePolyline( polygon.at( 0 ), mLayer, "CONTINUOUS", mPen.color(), currentWidth() );
95+
mDxf->writePolyline( polygon.at( 0 ), mLayer, "CONTINUOUS", penColor(), currentWidth() );
9096
}
9197
else
9298
{
9399
if ( mBrush.style() != Qt::NoBrush )
94-
mDxf->writePolygon( polygon, mLayer, "SOLID", mBrush.color() );
100+
mDxf->writePolygon( polygon, mLayer, "SOLID", brushColor() );
95101
}
96102
}
97103

@@ -122,7 +128,7 @@ void QgsDxfPaintEngine::drawPath( const QPainterPath& path )
122128
endPolygon();
123129

124130
if ( !mPolygon.isEmpty() && mBrush.style() != Qt::NoBrush )
125-
mDxf->writePolygon( mPolygon, mLayer, "SOLID", mBrush.color() );
131+
mDxf->writePolygon( mPolygon, mLayer, "SOLID", brushColor() );
126132

127133
mPolygon.clear();
128134
}
@@ -198,7 +204,7 @@ void QgsDxfPaintEngine::drawLines( const QLineF* lines, int lineCount )
198204
{
199205
mDxf->writeLine( toDxfCoordinates( lines[i].p1() ),
200206
toDxfCoordinates( lines[i].p2() ),
201-
mLayer, "CONTINUOUS", mPen.color(), currentWidth() );
207+
mLayer, "CONTINUOUS", penColor(), currentWidth() );
202208
}
203209
}
204210

@@ -291,3 +297,25 @@ int QgsDxfPaintEngine::faculty( int n )
291297

292298
return result;
293299
}
300+
301+
QColor QgsDxfPaintEngine::penColor() const
302+
{
303+
if ( qgsDoubleNear( mOpacity, 1.0 ) )
304+
{
305+
return mPen.color();
306+
}
307+
QColor c = mPen.color();
308+
c.setAlphaF( c.alphaF() * mOpacity );
309+
return c;
310+
}
311+
312+
QColor QgsDxfPaintEngine::brushColor() const
313+
{
314+
if ( qgsDoubleNear( mOpacity, 1.0 ) )
315+
{
316+
return mBrush.color();
317+
}
318+
QColor c = mBrush.color();
319+
c.setAlphaF( c.alphaF() * mOpacity );
320+
return c;
321+
}

src/core/dxf/qgsdxfpaintengine.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class CORE_EXPORT QgsDxfPaintEngine: public QPaintEngine
6161
QTransform mTransform;
6262
QPen mPen;
6363
QBrush mBrush;
64+
double mOpacity;
6465
QString mLayer;
6566
QPointF mShift;
6667
QgsRingSequenceV2 mPolygon;
@@ -84,6 +85,9 @@ class CORE_EXPORT QgsDxfPaintEngine: public QPaintEngine
8485
static int lower( int n, int i );
8586
static double power( double a, int b );
8687
static int faculty( int n );
88+
89+
QColor penColor() const;
90+
QColor brushColor() const;
8791
};
8892

8993
#endif // QGSDXFPAINTENGINE_H

0 commit comments

Comments
 (0)