Skip to content

Commit 03ec2d8

Browse files
authoredNov 24, 2017
Merge pull request #5702 from nyalldawson/dxf_improve
[dxf] Add option to export labels as text elements, instead of mtext
2 parents 2b5aca5 + f8d8395 commit 03ec2d8

File tree

13 files changed

+725
-280
lines changed

13 files changed

+725
-280
lines changed
 

‎python/core/dxf/qgsdxfexport.sip

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ class QgsDxfExport
2727
SymbolLayerSymbology
2828
};
2929

30+
enum Flag
31+
{
32+
FlagNoMText,
33+
};
34+
typedef QFlags<QgsDxfExport::Flag> Flags;
35+
36+
3037
QgsDxfExport();
3138
%Docstring
3239
Constructor for QgsDxfExport.
@@ -38,6 +45,21 @@ class QgsDxfExport
3845
\param settings map settings to apply
3946
%End
4047

48+
void setFlags( QgsDxfExport::Flags flags );
49+
%Docstring
50+
Sets the export flags.
51+
.. versionadded:: 3.0
52+
.. seealso:: flags()
53+
%End
54+
55+
QgsDxfExport::Flags flags() const;
56+
%Docstring
57+
Returns the export flags.
58+
.. versionadded:: 3.0
59+
.. seealso:: setFlags()
60+
:rtype: QgsDxfExport.Flags
61+
%End
62+
4163
void addLayers( const QList< QPair<QgsVectorLayer *, int > > &layers );
4264
%Docstring
4365
Add layers to export
@@ -342,6 +364,9 @@ return list of available DXF encodings
342364

343365
};
344366

367+
QFlags<QgsDxfExport::Flag> operator|(QgsDxfExport::Flag f1, QFlags<QgsDxfExport::Flag> f2);
368+
369+
345370
/************************************************************************
346371
* This file has been generated automatically from *
347372
* *

‎src/app/qgisapp.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5700,6 +5700,12 @@ void QgisApp::dxfExport()
57005700
dxfExport.setLayerTitleAsName( d.layerTitleAsName() );
57015701
dxfExport.setDestinationCrs( d.crs() );
57025702
dxfExport.setForce2d( d.force2d() );
5703+
5704+
QgsDxfExport::Flags flags = 0;
5705+
if ( !d.useMText() )
5706+
flags = flags | QgsDxfExport::FlagNoMText;
5707+
dxfExport.setFlags( flags );
5708+
57035709
if ( mapCanvas() )
57045710
{
57055711
//extent

‎src/app/qgscrashhandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class APP_EXPORT QgsCrashHandler
3131
{
3232

3333
public:
34+
3435
/**
3536
* This class doesn't need to be created by anyone as is only used to handle
3637
* crashes in the application.

‎src/app/qgsdxfexportdialog.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ QgsDxfExportDialog::QgsDxfExportDialog( QWidget *parent, Qt::WindowFlags f )
458458
mScaleWidget->setScale( 1.0 / oldScale );
459459
mLayerTitleAsName->setChecked( QgsProject::instance()->readEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfLayerTitleAsName" ), s.value( QStringLiteral( "qgis/lastDxfLayerTitleAsName" ), "false" ).toString() ) != QLatin1String( "false" ) );
460460
mMapExtentCheckBox->setChecked( QgsProject::instance()->readEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfMapRectangle" ), s.value( QStringLiteral( "qgis/lastDxfMapRectangle" ), "false" ).toString() ) != QLatin1String( "false" ) );
461+
mMTextCheckBox->setChecked( QgsProject::instance()->readEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfUseMText" ), s.value( QStringLiteral( "qgis/lastDxfUseMText" ), "true" ).toString() ) != QLatin1String( "false" ) );
461462

462463
QStringList ids = QgsProject::instance()->mapThemeCollection()->mapThemes();
463464
ids.prepend( QLatin1String( "" ) );
@@ -611,6 +612,11 @@ bool QgsDxfExportDialog::force2d() const
611612
return mForce2d->isChecked();
612613
}
613614

615+
bool QgsDxfExportDialog::useMText() const
616+
{
617+
return mMTextCheckBox->isChecked();
618+
}
619+
614620
void QgsDxfExportDialog::saveSettings()
615621
{
616622
QgsSettings s;
@@ -622,6 +628,7 @@ void QgsDxfExportDialog::saveSettings()
622628
s.setValue( QStringLiteral( "qgis/lastDxfLayerTitleAsName" ), mLayerTitleAsName->isChecked() );
623629
s.setValue( QStringLiteral( "qgis/lastDxfEncoding" ), mEncoding->currentText() );
624630
s.setValue( QStringLiteral( "qgis/lastDxfCrs" ), QString::number( mCRS.srsid() ) );
631+
s.setValue( QStringLiteral( "qgis/lastDxfUseMText" ), mMTextCheckBox->isChecked() );
625632

626633
QgsProject::instance()->writeEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfSymbologyMode" ), mSymbologyModeComboBox->currentIndex() );
627634
QgsProject::instance()->writeEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastSymbologyExportScale" ), mScaleWidget->scale() != 0 ? 1.0 / mScaleWidget->scale() : 0 );
@@ -630,6 +637,7 @@ void QgsDxfExportDialog::saveSettings()
630637
QgsProject::instance()->writeEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfEncoding" ), mEncoding->currentText() );
631638
QgsProject::instance()->writeEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastVisibilityPreset" ), mVisibilityPresets->currentText() );
632639
QgsProject::instance()->writeEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfCrs" ), QString::number( mCRS.srsid() ) );
640+
QgsProject::instance()->writeEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfUseMText" ), mMTextCheckBox->isChecked() );
633641
}
634642

635643

‎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
bool exportMapExtent() const;
8989
bool layerTitleAsName() const;
9090
bool force2d() const;
91+
bool useMText() const;
9192
QString mapTheme() const;
9293
QString encoding() const;
9394
QgsCoordinateReferenceSystem crs() const;

‎src/core/dxf/qgsdxfexport.cpp

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,16 @@ void QgsDxfExport::setMapSettings( const QgsMapSettings &settings )
389389
mMapSettings = settings;
390390
}
391391

392+
void QgsDxfExport::setFlags( QgsDxfExport::Flags flags )
393+
{
394+
mFlags = flags;
395+
}
396+
397+
QgsDxfExport::Flags QgsDxfExport::flags() const
398+
{
399+
return mFlags;
400+
}
401+
392402
void QgsDxfExport::addLayers( const QList< QPair< QgsVectorLayer *, int > > &layers )
393403
{
394404
QList<QgsMapLayer *> layerList;
@@ -491,7 +501,7 @@ int QgsDxfExport::writeToFile( QIODevice *d, const QString &encoding )
491501
return 1;
492502
}
493503

494-
if ( !d->isOpen() && !d->open( QIODevice::WriteOnly ) )
504+
if ( !d->isOpen() && !d->open( QIODevice::WriteOnly | QIODevice::Truncate ) )
495505
{
496506
return 2;
497507
}
@@ -3633,6 +3643,7 @@ void QgsDxfExport::writeText( const QString &layer, const QString &text, const Q
36333643
writeGroup( 1, text );
36343644
writeGroup( 50, angle );
36353645
writeGroup( 7, QStringLiteral( "STANDARD" ) ); // so far only support for standard font
3646+
writeGroup( 100, QStringLiteral( "AcDbText" ) );
36363647
}
36373648

36383649
void QgsDxfExport::writeMText( const QString &layer, const QString &text, const QgsPoint &pt, double width, double angle, const QColor &color )
@@ -4400,30 +4411,36 @@ void QgsDxfExport::drawLabel( const QString &layerId, QgsRenderContext &context,
44004411
}
44014412
}
44024413

4403-
txt = txt.replace( wrapchr, QLatin1String( "\\P" ) );
4404-
4405-
if ( tmpLyr.format().font().underline() )
4414+
if ( mFlags & FlagNoMText )
44064415
{
4407-
txt.prepend( "\\L" ).append( "\\l" );
4416+
writeText( dxfLayer, txt, QgsPoint( label->getX(), label->getY() ), label->getHeight(), label->getAlpha() * 180.0 / M_PI, tmpLyr.format().color() );
44084417
}
4409-
4410-
if ( tmpLyr.format().font().overline() )
4418+
else
44114419
{
4412-
txt.prepend( "\\O" ).append( "\\o" );
4413-
}
4420+
txt = txt.replace( wrapchr, QLatin1String( "\\P" ) );
44144421

4415-
if ( tmpLyr.format().font().strikeOut() )
4416-
{
4417-
txt.prepend( "\\K" ).append( "\\k" );
4418-
}
4422+
if ( tmpLyr.format().font().underline() )
4423+
{
4424+
txt.prepend( "\\L" ).append( "\\l" );
4425+
}
4426+
4427+
if ( tmpLyr.format().font().overline() )
4428+
{
4429+
txt.prepend( "\\O" ).append( "\\o" );
4430+
}
44194431

4420-
txt.prepend( QStringLiteral( "\\f%1|i%2|b%3;\\H%4;" )
4421-
.arg( tmpLyr.format().font().family() )
4422-
.arg( tmpLyr.format().font().italic() ? 1 : 0 )
4423-
.arg( tmpLyr.format().font().bold() ? 1 : 0 )
4424-
.arg( label->getHeight() / ( 1 + txt.count( QStringLiteral( "\\P" ) ) ) * 0.75 ) );
4432+
if ( tmpLyr.format().font().strikeOut() )
4433+
{
4434+
txt.prepend( "\\K" ).append( "\\k" );
4435+
}
44254436

4426-
writeMText( dxfLayer, txt, QgsPoint( label->getX(), label->getY() ), label->getWidth(), label->getAlpha() * 180.0 / M_PI, tmpLyr.format().color() );
4437+
txt.prepend( QStringLiteral( "\\f%1|i%2|b%3;\\H%4;" )
4438+
.arg( tmpLyr.format().font().family() )
4439+
.arg( tmpLyr.format().font().italic() ? 1 : 0 )
4440+
.arg( tmpLyr.format().font().bold() ? 1 : 0 )
4441+
.arg( label->getHeight() / ( 1 + txt.count( QStringLiteral( "\\P" ) ) ) * 0.75 ) );
4442+
writeMText( dxfLayer, txt, QgsPoint( label->getX(), label->getY() ), label->getWidth(), label->getAlpha() * 180.0 / M_PI, tmpLyr.format().color() );
4443+
}
44274444
}
44284445

44294446

‎src/core/dxf/qgsdxfexport.h

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,18 @@ class CORE_EXPORT QgsDxfExport
5353
public:
5454
enum SymbologyExport
5555
{
56-
NoSymbology = 0, //export only data
57-
FeatureSymbology, //Keeps the number of features and export symbology per feature (using the first symbol level)
58-
SymbolLayerSymbology //Exports one feature per symbol layer (considering symbol levels)
56+
NoSymbology = 0, //!< Export only data
57+
FeatureSymbology, //!< Keeps the number of features and export symbology per feature (using the first symbol level)
58+
SymbolLayerSymbology //!< Exports one feature per symbol layer (considering symbol levels)
5959
};
6060

61+
//! Export flags
62+
enum Flag
63+
{
64+
FlagNoMText = 1 << 1, //!< Export text as TEXT elements. If not set, text will be exported as MTEXT elements.
65+
};
66+
Q_DECLARE_FLAGS( Flags, Flag )
67+
6168
/**
6269
* Constructor for QgsDxfExport.
6370
*/
@@ -71,6 +78,20 @@ class CORE_EXPORT QgsDxfExport
7178
*/
7279
void setMapSettings( const QgsMapSettings &settings );
7380

81+
/**
82+
* Sets the export flags.
83+
* \since QGIS 3.0
84+
* \see flags()
85+
*/
86+
void setFlags( QgsDxfExport::Flags flags );
87+
88+
/**
89+
* Returns the export flags.
90+
* \since QGIS 3.0
91+
* \see setFlags()
92+
*/
93+
QgsDxfExport::Flags flags() const;
94+
7495
/**
7596
* Add layers to export
7697
* \param layers list of layers and corresponding attribute indexes that determine the layer name (-1 for original layer name or title)
@@ -440,6 +461,11 @@ class CORE_EXPORT QgsDxfExport
440461
QHash<QString, int> mLayerNameAttribute;
441462
double mFactor = 1.0;
442463
bool mForce2d = false;
464+
465+
QgsDxfExport::Flags mFlags = 0;
466+
443467
};
444468

469+
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDxfExport::Flags )
470+
445471
#endif // QGSDXFEXPORT_H

‎src/crashhandler/CMakeLists.txt

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
INCLUDE_DIRECTORIES(SYSTEM
2-
${CMAKE_CURRENT_BINARY_DIR}
3-
)
4-
5-
QT5_WRAP_UI(CRASH_UIS_H qgscrashdialog.ui)
6-
QT5_WRAP_CPP(CRASH_HDR_MOC qgscrashdialog.h)
7-
8-
SET(IMAGE_RCCS ../../images/images.qrc)
9-
QT5_ADD_RESOURCES(IMAGE_RCC_SRCS ${IMAGE_RCCS})
10-
11-
# -wd4091 Avoid 'typedef' ignored on left of '' when no variable is declared warning in DbgHelp.h
12-
SET_SOURCE_FILES_PROPERTIES(qgsstacktrace.cpp PROPERTIES COMPILE_FLAGS -wd4091)
13-
14-
ADD_EXECUTABLE(qgiscrashhandler WIN32
15-
main.cpp
16-
${CRASH_UIS_H}
17-
${CRASH_HDR_MOC}
18-
${IMAGE_RCC_SRCS}
19-
qgscrashdialog.cpp
20-
qgsstacktrace.cpp
21-
qgscrashreport.cpp
22-
${CMAKE_CURRENT_SOURCE_DIR}/../app/qgis_win32.rc
23-
)
24-
25-
TARGET_LINK_LIBRARIES(qgiscrashhandler
26-
${QT_QTCORE_LIBRARY}
27-
${QT_QTGUI_LIBRARY}
28-
DbgHelp
29-
)
30-
31-
INSTALL(CODE "MESSAGE(\"Installing crashhandler ...\")")
32-
INSTALL(TARGETS qgiscrashhandler RUNTIME DESTINATION ${QGIS_LIBEXEC_DIR})
1+
INCLUDE_DIRECTORIES(SYSTEM
2+
${CMAKE_CURRENT_BINARY_DIR}
3+
)
4+
5+
QT5_WRAP_UI(CRASH_UIS_H qgscrashdialog.ui)
6+
QT5_WRAP_CPP(CRASH_HDR_MOC qgscrashdialog.h)
7+
8+
SET(IMAGE_RCCS ../../images/images.qrc)
9+
QT5_ADD_RESOURCES(IMAGE_RCC_SRCS ${IMAGE_RCCS})
10+
11+
# -wd4091 Avoid 'typedef' ignored on left of '' when no variable is declared warning in DbgHelp.h
12+
SET_SOURCE_FILES_PROPERTIES(qgsstacktrace.cpp PROPERTIES COMPILE_FLAGS -wd4091)
13+
14+
ADD_EXECUTABLE(qgiscrashhandler WIN32
15+
main.cpp
16+
${CRASH_UIS_H}
17+
${CRASH_HDR_MOC}
18+
${IMAGE_RCC_SRCS}
19+
qgscrashdialog.cpp
20+
qgsstacktrace.cpp
21+
qgscrashreport.cpp
22+
${CMAKE_CURRENT_SOURCE_DIR}/../app/qgis_win32.rc
23+
)
24+
25+
TARGET_LINK_LIBRARIES(qgiscrashhandler
26+
${QT_QTCORE_LIBRARY}
27+
${QT_QTGUI_LIBRARY}
28+
DbgHelp
29+
)
30+
31+
INSTALL(CODE "MESSAGE(\"Installing crashhandler ...\")")
32+
INSTALL(TARGETS qgiscrashhandler RUNTIME DESTINATION ${QGIS_LIBEXEC_DIR})

0 commit comments

Comments
 (0)