Skip to content

Commit 12e69d0

Browse files
committedAug 29, 2017
dxf export:
* empty field name resets to layer name (fixes #17060) * allow forcing to 2d to support polyline width (fixes #17049)
1 parent b978c4d commit 12e69d0

File tree

7 files changed

+82
-35
lines changed

7 files changed

+82
-35
lines changed
 

‎python/core/dxf/qgsdxfexport.sip

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ class QgsDxfExport
126126
:rtype: bool
127127
%End
128128

129+
void setForce2d( bool force2d );
130+
%Docstring
131+
Force 2d output (eg. to support linewidth in polylines)
132+
\param force2d flag
133+
.. seealso:: force2d
134+
%End
135+
136+
bool force2d();
137+
%Docstring
138+
Retrieve whether the output should be forced to 2d
139+
:return: flag
140+
.. seealso:: setForce2d
141+
:rtype: bool
142+
%End
143+
129144
static int closestColorMatch( QRgb color );
130145
%Docstring
131146
Get DXF palette index of nearest entry for given color

‎src/app/qgisapp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5528,6 +5528,7 @@ void QgisApp::dxfExport()
55285528
dxfExport.setSymbologyExport( d.symbologyMode() );
55295529
dxfExport.setLayerTitleAsName( d.layerTitleAsName() );
55305530
dxfExport.setDestinationCrs( d.crs() );
5531+
dxfExport.setForce2d( d.force2d() );
55315532
if ( mapCanvas() )
55325533
{
55335534
//extent

‎src/app/qgsdxfexportdialog.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ QWidget *FieldSelectorDelegate::createEditor( QWidget *parent, const QStyleOptio
5252
if ( !vl )
5353
return nullptr;
5454

55-
5655
QgsFieldComboBox *w = new QgsFieldComboBox( parent );
5756
w->setLayer( vl );
57+
w->setAllowEmptyFieldName( true );
5858
return w;
5959
}
6060

@@ -607,6 +607,11 @@ bool QgsDxfExportDialog::layerTitleAsName() const
607607
return mLayerTitleAsName->isChecked();
608608
}
609609

610+
bool QgsDxfExportDialog::force2d() const
611+
{
612+
return mForce2d->isChecked();
613+
}
614+
610615
void QgsDxfExportDialog::saveSettings()
611616
{
612617
QgsSettings s;

‎src/app/qgsdxfexportdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class QgsDxfExportDialog : public QDialog, private Ui::QgsDxfExportDialogBase
8888
QString saveFile() const;
8989
bool exportMapExtent() const;
9090
bool layerTitleAsName() const;
91+
bool force2d() const;
9192
QString mapTheme() const;
9293
QString encoding() const;
9394
QgsCoordinateReferenceSystem crs() const;

‎src/core/dxf/qgsdxfexport.cpp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ QgsDxfExport::QgsDxfExport()
375375
, mNextHandleId( DXF_HANDSEED )
376376
, mBlockCounter( 0 )
377377
, mFactor( 1 )
378+
, mForce2d( false )
378379
{
379380
}
380381

@@ -443,7 +444,7 @@ void QgsDxfExport::writeGroup( int code, const QgsPoint &p )
443444
{
444445
writeGroup( code + 10, p.x() );
445446
writeGroup( code + 20, p.y() );
446-
if ( p.is3D() && std::isfinite( p.z() ) )
447+
if ( !mForce2d && p.is3D() && std::isfinite( p.z() ) )
447448
writeGroup( code + 30, p.z() );
448449
}
449450

@@ -735,28 +736,28 @@ void QgsDxfExport::writeTables()
735736
writeGroup( 5, QgsPoint( 1.0, 1.0 ) ); // grid spacing
736737
writeGroup( 6, QgsPoint( QgsWkbTypes::PointZ, 0.0, 0.0, 1.0 ) ); // view direction from target point
737738
writeGroup( 7, QgsPoint( mExtent.center() ) ); // view target point
738-
writeGroup( 40, mExtent.height() ); // view height
739-
writeGroup( 41, mExtent.width() / mExtent.height() ); // view aspect ratio
740-
writeGroup( 42, 50.0 ); // lens length
741-
writeGroup( 43, 0.0 ); // front clipping plane
742-
writeGroup( 44, 0.0 ); // back clipping plane
743-
writeGroup( 50, 0.0 ); // snap rotation
744-
writeGroup( 51, 0.0 ); // view twist angle
745-
writeGroup( 71, 0 ); // view mode (0 = deactivates)
746-
writeGroup( 72, 100 ); // circle zoom percent
747-
writeGroup( 73, 1 ); // fast zoom setting
748-
writeGroup( 74, 1 ); // UCSICON setting
749-
writeGroup( 75, 0 ); // snapping off
750-
writeGroup( 76, 0 ); // grid off
751-
writeGroup( 77, 0 ); // snap style
752-
writeGroup( 78, 0 ); // snap isopair
753-
writeGroup( 281, 0 ); // render mode (0 = 2D optimized)
754-
writeGroup( 65, 1 ); // value of UCSVP for this viewport
739+
writeGroup( 40, mExtent.height() ); // view height
740+
writeGroup( 41, mExtent.width() / mExtent.height() ); // view aspect ratio
741+
writeGroup( 42, 50.0 ); // lens length
742+
writeGroup( 43, 0.0 ); // front clipping plane
743+
writeGroup( 44, 0.0 ); // back clipping plane
744+
writeGroup( 50, 0.0 ); // snap rotation
745+
writeGroup( 51, 0.0 ); // view twist angle
746+
writeGroup( 71, 0 ); // view mode (0 = deactivates)
747+
writeGroup( 72, 100 ); // circle zoom percent
748+
writeGroup( 73, 1 ); // fast zoom setting
749+
writeGroup( 74, 1 ); // UCSICON setting
750+
writeGroup( 75, 0 ); // snapping off
751+
writeGroup( 76, 0 ); // grid off
752+
writeGroup( 77, 0 ); // snap style
753+
writeGroup( 78, 0 ); // snap isopair
754+
writeGroup( 281, 0 ); // render mode (0 = 2D optimized)
755+
writeGroup( 65, 1 ); // value of UCSVP for this viewport
755756
writeGroup( 100, QgsPoint( QgsWkbTypes::PointZ ) ); // UCS origin
756757
writeGroup( 101, QgsPoint( QgsWkbTypes::PointZ, 1.0 ) ); // UCS x axis
757758
writeGroup( 102, QgsPoint( QgsWkbTypes::PointZ, 0.0, 1.0 ) ); // UCS y axis
758-
writeGroup( 79, 0 ); // Orthographic type of UCS (0 = UCS is not orthographic)
759-
writeGroup( 146, 0.0 ); // Elevation
759+
writeGroup( 79, 0 ); // Orthographic type of UCS (0 = UCS is not orthographic)
760+
writeGroup( 146, 0.0 ); // Elevation
760761

761762
writeGroup( 70, 0 );
762763
writeGroup( 0, QStringLiteral( "ENDTAB" ) );
@@ -3457,7 +3458,7 @@ void QgsDxfExport::writePolyline( const QgsPointSequence &line, const QString &l
34573458
return;
34583459
}
34593460

3460-
if ( !line.at( 0 ).is3D() )
3461+
if ( mForce2d || !line.at( 0 ).is3D() )
34613462
{
34623463
writeGroup( 0, QStringLiteral( "LWPOLYLINE" ) );
34633464
writeHandle();
@@ -3760,7 +3761,7 @@ void QgsDxfExport::addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateT
37603761
QgsGeos geos( tempGeom );
37613762
if ( tempGeom != geom.get() )
37623763
delete tempGeom;
3763-
tempGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok //#spellok
3764+
tempGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok
37643765
if ( !tempGeom )
37653766
tempGeom = geom.get();
37663767
}
@@ -3781,7 +3782,7 @@ void QgsDxfExport::addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateT
37813782
QgsGeos geos( tempGeom );
37823783
if ( tempGeom != geom.get() )
37833784
delete tempGeom;
3784-
tempGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok //#spellok
3785+
tempGeom = geos.offsetCurve( offset, 0, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok
37853786
if ( !tempGeom )
37863787
tempGeom = geom.get();
37873788
}
@@ -3807,7 +3808,7 @@ void QgsDxfExport::addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateT
38073808
QgsGeos geos( tempGeom );
38083809
if ( tempGeom != geom.get() )
38093810
delete tempGeom;
3810-
tempGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok //#spellok
3811+
tempGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok
38113812
if ( !tempGeom )
38123813
tempGeom = geom.get();
38133814
}
@@ -3828,7 +3829,7 @@ void QgsDxfExport::addFeature( QgsSymbolRenderContext &ctx, const QgsCoordinateT
38283829
QgsGeos geos( tempGeom );
38293830
if ( tempGeom != geom.get() )
38303831
delete tempGeom;
3831-
tempGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok //#spellok
3832+
tempGeom = geos.buffer( offset, 0, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, 2.0 ); //#spellok
38323833
if ( !tempGeom )
38333834
tempGeom = geom.get();
38343835
}

‎src/core/dxf/qgsdxfexport.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,20 @@ class CORE_EXPORT QgsDxfExport
155155
*/
156156
bool layerTitleAsName() { return mLayerTitleAsName; }
157157

158+
/**
159+
* Force 2d output (eg. to support linewidth in polylines)
160+
* \param force2d flag
161+
* \see force2d
162+
*/
163+
void setForce2d( bool force2d ) { mForce2d = force2d; }
164+
165+
/**
166+
* Retrieve whether the output should be forced to 2d
167+
* \returns flag
168+
* \see setForce2d
169+
*/
170+
bool force2d() { return mForce2d; }
171+
158172
/**
159173
* Get DXF palette index of nearest entry for given color
160174
* \param color
@@ -403,6 +417,7 @@ class CORE_EXPORT QgsDxfExport
403417
QgsMapSettings mMapSettings;
404418
QHash<QString, int> mLayerNameAttribute;
405419
double mFactor;
420+
bool mForce2d;
406421
};
407422

408423
#endif // QGSDXFEXPORT_H

‎src/ui/qgsdxfexportdialogbase.ui

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
<string>DXF Export</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout_2">
17+
<item row="2" column="0">
18+
<widget class="QLabel" name="mSymbologyScaleLabel">
19+
<property name="text">
20+
<string>Symbology scale</string>
21+
</property>
22+
</widget>
23+
</item>
1724
<item row="0" column="2">
1825
<widget class="QToolButton" name="mFileSelectionButton">
1926
<property name="text">
@@ -54,13 +61,6 @@
5461
</property>
5562
</widget>
5663
</item>
57-
<item row="2" column="0">
58-
<widget class="QLabel" name="mSymbologyScaleLabel">
59-
<property name="text">
60-
<string>Symbology scale</string>
61-
</property>
62-
</widget>
63-
</item>
6464
<item row="7" column="0" colspan="3">
6565
<widget class="QgsLayerTreeView" name="mTreeView">
6666
<property name="selectionMode">
@@ -125,7 +125,7 @@
125125
</property>
126126
</widget>
127127
</item>
128-
<item row="12" column="0" colspan="3">
128+
<item row="13" column="0" colspan="3">
129129
<widget class="QDialogButtonBox" name="buttonBox">
130130
<property name="orientation">
131131
<enum>Qt::Horizontal</enum>
@@ -173,6 +173,13 @@
173173
</property>
174174
</widget>
175175
</item>
176+
<item row="12" column="0" colspan="3">
177+
<widget class="QCheckBox" name="mForce2d">
178+
<property name="text">
179+
<string>Force 2d output (eg. to support polyline width)</string>
180+
</property>
181+
</widget>
182+
</item>
176183
</layout>
177184
</widget>
178185
<customwidgets>
@@ -197,15 +204,17 @@
197204
<tabstop>mFileLineEdit</tabstop>
198205
<tabstop>mFileSelectionButton</tabstop>
199206
<tabstop>mSymbologyModeComboBox</tabstop>
200-
<tabstop>mScaleWidget</tabstop>
201207
<tabstop>mEncoding</tabstop>
208+
<tabstop>mScaleWidget</tabstop>
202209
<tabstop>mVisibilityPresets</tabstop>
203210
<tabstop>mCrsSelector</tabstop>
204211
<tabstop>mTreeView</tabstop>
205212
<tabstop>mSelectAllButton</tabstop>
206213
<tabstop>mDeselectAllButton</tabstop>
207214
<tabstop>mLayerTitleAsName</tabstop>
208215
<tabstop>mMapExtentCheckBox</tabstop>
216+
<tabstop>mForce2d</tabstop>
217+
<tabstop>buttonBox</tabstop>
209218
</tabstops>
210219
<resources/>
211220
<connections>

1 commit comments

Comments
 (1)

3nids commented on Sep 1, 2017

@3nids
Member

@jef-n thanks a lot for the fix.
Do you consider this as a feature? or is there another reason not to backport?

Please sign in to comment.