Skip to content

Commit e721e7f

Browse files
committedJan 15, 2014
Bugfixes for dxf export
1 parent 0ca7316 commit e721e7f

File tree

8 files changed

+101
-72
lines changed

8 files changed

+101
-72
lines changed
 

‎src/core/dxf/qgsdxfexport.cpp

Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,9 @@ void QgsDxfExport::writeEntities()
547547
continue;
548548
}
549549

550-
QgsRenderContext ctx;
550+
QgsRenderContext ctx = renderContext();
551551
ctx.setRendererScale( mSymbologyScaleDenominator );
552+
QgsSymbolV2RenderContext sctx( ctx, QgsSymbolV2::MM , 1.0, false, 0, 0 );
552553
QgsFeatureRendererV2* renderer = vl->rendererV2();
553554
renderer->startRender( ctx, vl );
554555

@@ -569,9 +570,10 @@ void QgsDxfExport::writeEntities()
569570
QgsFeature fet;
570571
while ( featureIt.nextFeature( fet ) )
571572
{
573+
sctx.setFeature( &fet );
572574
if ( mSymbologyExport == NoSymbology )
573575
{
574-
addFeature( fet, dxfLayerName( vl->name() ), 0, 0 ); //no symbology at all
576+
addFeature( sctx, dxfLayerName( vl->name() ), 0, 0 ); //no symbology at all
575577
}
576578
else
577579
{
@@ -593,7 +595,7 @@ void QgsDxfExport::writeEntities()
593595
int nSymbolLayers = ( *symbolIt )->symbolLayerCount();
594596
for ( int i = 0; i < nSymbolLayers; ++i )
595597
{
596-
addFeature( fet, dxfLayerName( vl->name() ), ( *symbolIt )->symbolLayer( i ), *symbolIt );
598+
addFeature( sctx, dxfLayerName( vl->name() ), ( *symbolIt )->symbolLayer( i ), *symbolIt );
597599
}
598600
}
599601
}
@@ -605,7 +607,7 @@ void QgsDxfExport::writeEntities()
605607
{
606608
continue;
607609
}
608-
addFeature( fet, dxfLayerName( vl->name() ), s->symbolLayer( 0 ), s );
610+
addFeature( sctx, dxfLayerName( vl->name() ), s->symbolLayer( 0 ), s );
609611
}
610612
}
611613
}
@@ -629,7 +631,9 @@ void QgsDxfExport::writeEntitiesSymbolLevels( QgsVectorLayer* layer )
629631
}
630632
QHash< QgsSymbolV2*, QList<QgsFeature> > features;
631633

632-
startRender( layer );
634+
QgsRenderContext ctx = renderContext();
635+
QgsSymbolV2RenderContext sctx( ctx, QgsSymbolV2::MM , 1.0, false, 0, 0 );
636+
renderer->startRender( ctx, layer );
633637

634638
//get iterator
635639
QgsFeatureRequest req;
@@ -695,11 +699,11 @@ void QgsDxfExport::writeEntitiesSymbolLevels( QgsVectorLayer* layer )
695699
QList<QgsFeature>::iterator featureIt = featureList.begin();
696700
for ( ; featureIt != featureList.end(); ++featureIt )
697701
{
698-
addFeature( *featureIt, layer->name(), levelIt.key()->symbolLayer( llayer ), levelIt.key() );
702+
addFeature( sctx, layer->name(), levelIt.key()->symbolLayer( llayer ), levelIt.key() );
699703
}
700704
}
701705
}
702-
stopRender( layer );
706+
renderer->stopRender( ctx );
703707
}
704708

705709
void QgsDxfExport::writeEndFile()
@@ -874,17 +878,23 @@ QgsRectangle QgsDxfExport::dxfExtent() const
874878
return extent;
875879
}
876880

877-
void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol )
881+
void QgsDxfExport::addFeature( const QgsSymbolV2RenderContext& ctx, const QString& layer, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol )
878882
{
879-
QgsGeometry* geom = fet.geometry();
883+
const QgsFeature* fet = ctx.feature();
884+
if ( !fet )
885+
{
886+
return;
887+
}
888+
889+
QgsGeometry* geom = fet->geometry();
880890
if ( geom )
881891
{
882892
int c = 0;
883893
if ( mSymbologyExport != NoSymbology )
884894
{
885-
c = colorFromSymbolLayer( symbolLayer );
895+
c = colorFromSymbolLayer( symbolLayer, ctx );
886896
}
887-
double width = symbolLayer->dxfWidth( *this );;
897+
double width = symbolLayer->dxfWidth( *this, ctx );
888898
QString lineStyleName = "CONTINUOUS";
889899
if ( mSymbologyExport != NoSymbology )
890900
{
@@ -895,7 +905,7 @@ void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, cons
895905
//single point
896906
if ( geometryType == QGis::WKBPoint || geometryType == QGis::WKBPoint25D )
897907
{
898-
writePoint( geom->asPoint(), layer, c, &fet, symbolLayer, symbol );
908+
writePoint( geom->asPoint(), layer, c, fet, symbolLayer, symbol );
899909
}
900910

901911
//multipoint
@@ -905,7 +915,7 @@ void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, cons
905915
QgsMultiPoint::const_iterator it = multiPoint.constBegin();
906916
for ( ; it != multiPoint.constEnd(); ++it )
907917
{
908-
writePoint( *it, layer, c, &fet, symbolLayer, symbol );
918+
writePoint( *it, layer, c, fet, symbolLayer, symbol );
909919
}
910920
}
911921

@@ -974,14 +984,14 @@ double QgsDxfExport::scaleToMapUnits( double value, QgsSymbolV2::OutputUnit symb
974984
return value;
975985
}
976986

977-
int QgsDxfExport::colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer )
987+
int QgsDxfExport::colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2RenderContext& ctx )
978988
{
979989
if ( !symbolLayer )
980990
{
981991
return 0;
982992
}
983993

984-
QColor c = symbolLayer->dxfColor();
994+
QColor c = symbolLayer->dxfColor( ctx );
985995
return closestColorMatch( c.rgba() );
986996
}
987997

@@ -1046,40 +1056,6 @@ QgsRenderContext QgsDxfExport::renderContext() const
10461056
return context;
10471057
}
10481058

1049-
void QgsDxfExport::startRender( QgsVectorLayer* vl ) const
1050-
{
1051-
if ( !vl )
1052-
{
1053-
return;
1054-
}
1055-
1056-
QgsFeatureRendererV2* renderer = vl->rendererV2();
1057-
if ( !renderer )
1058-
{
1059-
return;
1060-
}
1061-
1062-
QgsRenderContext ctx = renderContext();
1063-
renderer->startRender( ctx, vl );
1064-
}
1065-
1066-
void QgsDxfExport::stopRender( QgsVectorLayer* vl ) const
1067-
{
1068-
if ( !vl )
1069-
{
1070-
return;
1071-
}
1072-
1073-
QgsFeatureRendererV2* renderer = vl->rendererV2();
1074-
if ( !renderer )
1075-
{
1076-
return;
1077-
}
1078-
1079-
QgsRenderContext ctx = renderContext();
1080-
renderer->stopRender( ctx );
1081-
}
1082-
10831059
double QgsDxfExport::mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits )
10841060
{
10851061
if ( symbolUnits == QgsSymbolV2::MapUnit )
@@ -1188,9 +1164,9 @@ void QgsDxfExport::writeSymbolLayerLinestyle( const QgsSymbolLayerV2* symbolLaye
11881164

11891165
QgsSymbolV2::OutputUnit unit;
11901166
QVector<qreal> customLinestyle = symbolLayer->dxfCustomDashPattern( unit );
1191-
if ( customLinestyle.size() < 0 )
1167+
if ( customLinestyle.size() > 0 )
11921168
{
1193-
QString name = QString( "symbolLayer%1" ).arg( mSymbolLayerCounter );
1169+
QString name = QString( "symbolLayer%1" ).arg( mSymbolLayerCounter++ );
11941170
writeLinestyle( name, customLinestyle, unit );
11951171
mLineStyles.insert( symbolLayer, name );
11961172
}
@@ -1220,7 +1196,7 @@ void QgsDxfExport::writeLinestyle( const QString& styleName, const QVector<qreal
12201196
QVector<qreal>::const_iterator dashIt = pattern.constBegin();
12211197
for ( ; dashIt != pattern.constEnd(); ++dashIt )
12221198
{
1223-
length += *dashIt;
1199+
length += ( *dashIt * mapUnitScaleFactor( mSymbologyScaleDenominator, u, mMapUnits ) );
12241200
}
12251201

12261202
writeGroup( 0, "LTYPE" );

‎src/core/dxf/qgsdxfexport.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ class CORE_EXPORT QgsDxfExport
137137

138138
QgsRectangle dxfExtent() const;
139139

140-
void addFeature( const QgsFeature& fet, const QString& layer, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol );
140+
void addFeature( const QgsSymbolV2RenderContext& ctx, const QString& layer, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol );
141141
double scaleToMapUnits( double value, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits ) const;
142142

143143
//returns dxf palette index from symbol layer color
144-
static int colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer );
144+
static int colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2RenderContext& ctx );
145145
QString lineStyleFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer );
146146

147147
//functions for dxf palette
@@ -150,8 +150,6 @@ class CORE_EXPORT QgsDxfExport
150150

151151
//helper functions for symbology export
152152
QgsRenderContext renderContext() const;
153-
void startRender( QgsVectorLayer* vl ) const;
154-
void stopRender( QgsVectorLayer* vl ) const;
155153

156154
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > symbolLayers();
157155
static int nLineTypes( const QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> >& symbolLayers );

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,19 +289,35 @@ double QgsSimpleFillSymbolLayerV2::estimateMaxBleed() const
289289
return penBleed + offsetBleed;
290290
}
291291

292-
double QgsSimpleFillSymbolLayerV2::dxfWidth( const QgsDxfExport& e ) const
292+
double QgsSimpleFillSymbolLayerV2::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
293293
{
294-
return mBorderWidth * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mBorderWidthUnit, e.mapUnits() );
294+
double width = mBorderWidth;
295+
QgsExpression* widthBorderExpression = expression( "width_border" );
296+
if ( widthBorderExpression )
297+
{
298+
width = widthBorderExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
299+
}
300+
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mBorderWidthUnit, e.mapUnits() );
295301
}
296302

297-
QColor QgsSimpleFillSymbolLayerV2::dxfColor() const
303+
QColor QgsSimpleFillSymbolLayerV2::dxfColor( const QgsSymbolV2RenderContext& context ) const
298304
{
299305
if ( mBrushStyle == Qt::NoBrush )
300306
{
307+
QgsExpression* colorBorderExpression = expression( "color_border" );
308+
if ( colorBorderExpression )
309+
{
310+
return QgsSymbolLayerV2Utils::decodeColor( colorBorderExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() );
311+
}
301312
return mBorderColor;
302313
}
303314
else
304315
{
316+
QgsExpression* colorExpression = expression( "color" );
317+
if ( colorExpression )
318+
{
319+
return QgsSymbolLayerV2Utils::decodeColor( colorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() );
320+
}
305321
return mColor;
306322
}
307323
}
@@ -858,12 +874,18 @@ double QgsImageFillSymbolLayer::estimateMaxBleed() const
858874
return subLayerBleed;
859875
}
860876

861-
double QgsImageFillSymbolLayer::dxfWidth( const QgsDxfExport& e ) const
877+
double QgsImageFillSymbolLayer::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
862878
{
863-
return mOutlineWidth * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOutlineWidthUnit, e.mapUnits() );
879+
double width = mOutlineWidth;
880+
QgsExpression* widthExpression = expression( "width" );
881+
if ( widthExpression )
882+
{
883+
width = widthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
884+
}
885+
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), mOutlineWidthUnit, e.mapUnits() );
864886
}
865887

866-
QColor QgsImageFillSymbolLayer::dxfColor() const
888+
QColor QgsImageFillSymbolLayer::dxfColor( const QgsSymbolV2RenderContext& context ) const
867889
{
868890
if ( !mOutline )
869891
{

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
9999

100100
double estimateMaxBleed() const;
101101

102-
double dxfWidth( const QgsDxfExport& e ) const;
103-
QColor dxfColor() const;
102+
double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
103+
QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
104104
Qt::PenStyle dxfPenStyle() const;
105105

106106
protected:
@@ -287,8 +287,8 @@ class CORE_EXPORT QgsImageFillSymbolLayer: public QgsFillSymbolLayerV2
287287

288288
double estimateMaxBleed() const;
289289

290-
virtual double dxfWidth( const QgsDxfExport& e ) const;
291-
virtual QColor dxfColor() const;
290+
virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
291+
virtual QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
292292
virtual Qt::PenStyle dxfPenStyle() const;
293293

294294
protected:

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
***************************************************************************/
1515

1616
#include "qgslinesymbollayerv2.h"
17+
#include "qgsdxfexport.h"
1718
#include "qgssymbollayerv2utils.h"
1819
#include "qgsexpression.h"
1920
#include "qgsrendercontext.h"
@@ -395,6 +396,32 @@ QVector<qreal> QgsSimpleLineSymbolLayerV2::dxfCustomDashPattern( QgsSymbolV2::Ou
395396
return mUseCustomDashPattern ? mCustomDashVector : QVector<qreal>() ;
396397
}
397398

399+
double QgsSimpleLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
400+
{
401+
double width = mWidth;
402+
QgsExpression* strokeWidthExpression = expression( "width" );
403+
if ( strokeWidthExpression )
404+
{
405+
width = strokeWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() );
406+
}
407+
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale )
408+
{
409+
width = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit );
410+
}
411+
412+
return width * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() );
413+
}
414+
415+
QColor QgsSimpleLineSymbolLayerV2::dxfColor( const QgsSymbolV2RenderContext& context ) const
416+
{
417+
QgsExpression* strokeColorExpression = expression( "color" );
418+
if ( strokeColorExpression )
419+
{
420+
return ( QgsSymbolLayerV2Utils::decodeColor( strokeColorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
421+
}
422+
return mColor;
423+
}
424+
398425
/////////
399426

400427

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class CORE_EXPORT QgsSimpleLineSymbolLayerV2 : public QgsLineSymbolLayerV2
9393

9494
QVector<qreal> dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const;
9595

96+
double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
97+
QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
98+
9699
protected:
97100
Qt::PenStyle mPenStyle;
98101
Qt::PenJoinStyle mPenJoinStyle;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,16 @@ bool QgsSymbolLayerV2::writeDxf( QgsDxfExport& e,
9494
return false;
9595
}
9696

97-
double QgsSymbolLayerV2::dxfWidth( const QgsDxfExport& e ) const
97+
double QgsSymbolLayerV2::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
9898
{
9999
Q_UNUSED( e );
100+
Q_UNUSED( context );
100101
return 1.0;
101102
}
102103

103-
QColor QgsSymbolLayerV2::dxfColor() const
104+
QColor QgsSymbolLayerV2::dxfColor( const QgsSymbolV2RenderContext& context ) const
104105
{
106+
Q_UNUSED( context );
105107
return color();
106108
}
107109

@@ -363,8 +365,9 @@ void QgsLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<
363365
}
364366
}
365367

366-
double QgsLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e ) const
368+
double QgsLineSymbolLayerV2::dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const
367369
{
370+
Q_UNUSED( context );
368371
return ( width() * e.mapUnitScaleFactor( e.symbologyScaleDenominator(), widthUnit(), e.mapUnits() ) );
369372
}
370373

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ class CORE_EXPORT QgsSymbolLayerV2
119119
const QgsFeature* f,
120120
const QPointF& shift = QPointF( 0.0, 0.0 ) ) const;
121121

122-
virtual double dxfWidth( const QgsDxfExport& e ) const;
122+
virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
123123

124-
virtual QColor dxfColor() const;
124+
virtual QColor dxfColor( const QgsSymbolV2RenderContext& context ) const;
125125

126126
virtual QVector<qreal> dxfCustomDashPattern( QgsSymbolV2::OutputUnit& unit ) const;
127127
virtual Qt::PenStyle dxfPenStyle() const;
@@ -254,7 +254,7 @@ class CORE_EXPORT QgsLineSymbolLayerV2 : public QgsSymbolLayerV2
254254

255255
void drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size );
256256

257-
virtual double dxfWidth( const QgsDxfExport& e ) const;
257+
virtual double dxfWidth( const QgsDxfExport& e, const QgsSymbolV2RenderContext& context ) const;
258258

259259
protected:
260260
QgsLineSymbolLayerV2( bool locked = false );

0 commit comments

Comments
 (0)
Please sign in to comment.