From 1535ff84ffb2a16678e96cbf1cfc98e7a00477ff Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 16 Nov 2017 14:44:17 +1000 Subject: [PATCH] [dxf][feature] Add option to export labels as text elements, instead of mtext Sponsored by SMEC --- python/core/dxf/qgsdxfexport.sip | 25 +++++ src/app/qgisapp.cpp | 6 ++ src/app/qgsdxfexportdialog.cpp | 10 +- src/app/qgsdxfexportdialog.h | 1 + src/core/dxf/qgsdxfexport.cpp | 57 +++++++---- src/core/dxf/qgsdxfexport.h | 32 +++++- src/ui/qgsdxfexportdialogbase.ui | 166 ++++++++++++++++++------------- 7 files changed, 202 insertions(+), 95 deletions(-) mode change 100644 => 100755 src/app/qgsdxfexportdialog.h mode change 100644 => 100755 src/core/dxf/qgsdxfexport.cpp mode change 100644 => 100755 src/ui/qgsdxfexportdialogbase.ui diff --git a/python/core/dxf/qgsdxfexport.sip b/python/core/dxf/qgsdxfexport.sip index 1aaf32aa792..e0a120c7560 100644 --- a/python/core/dxf/qgsdxfexport.sip +++ b/python/core/dxf/qgsdxfexport.sip @@ -27,6 +27,13 @@ class QgsDxfExport SymbolLayerSymbology }; + enum Flag + { + FlagNoMText, + }; + typedef QFlags Flags; + + QgsDxfExport(); %Docstring Constructor for QgsDxfExport. @@ -38,6 +45,21 @@ class QgsDxfExport \param settings map settings to apply %End + void setFlags( QgsDxfExport::Flags flags ); +%Docstring + Sets the export flags. +.. versionadded:: 3.0 +.. seealso:: flags() +%End + + QgsDxfExport::Flags flags() const; +%Docstring + Returns the export flags. +.. versionadded:: 3.0 +.. seealso:: setFlags() + :rtype: QgsDxfExport.Flags +%End + void addLayers( const QList< QPair > &layers ); %Docstring Add layers to export @@ -342,6 +364,9 @@ return list of available DXF encodings }; +QFlags operator|(QgsDxfExport::Flag f1, QFlags f2); + + /************************************************************************ * This file has been generated automatically from * * * diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index f0d08cdd3a2..ca94804c47c 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -5700,6 +5700,12 @@ void QgisApp::dxfExport() dxfExport.setLayerTitleAsName( d.layerTitleAsName() ); dxfExport.setDestinationCrs( d.crs() ); dxfExport.setForce2d( d.force2d() ); + + QgsDxfExport::Flags flags = 0; + if ( !d.useMText() ) + flags = flags | QgsDxfExport::FlagNoMText; + dxfExport.setFlags( flags ); + if ( mapCanvas() ) { //extent diff --git a/src/app/qgsdxfexportdialog.cpp b/src/app/qgsdxfexportdialog.cpp index c815bb90de4..83bb294bd90 100644 --- a/src/app/qgsdxfexportdialog.cpp +++ b/src/app/qgsdxfexportdialog.cpp @@ -458,6 +458,7 @@ QgsDxfExportDialog::QgsDxfExportDialog( QWidget *parent, Qt::WindowFlags f ) mScaleWidget->setScale( 1.0 / oldScale ); mLayerTitleAsName->setChecked( QgsProject::instance()->readEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfLayerTitleAsName" ), s.value( QStringLiteral( "qgis/lastDxfLayerTitleAsName" ), "false" ).toString() ) != QLatin1String( "false" ) ); mMapExtentCheckBox->setChecked( QgsProject::instance()->readEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfMapRectangle" ), s.value( QStringLiteral( "qgis/lastDxfMapRectangle" ), "false" ).toString() ) != QLatin1String( "false" ) ); + mMTextCheckBox->setChecked( QgsProject::instance()->readEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfUseMText" ), s.value( QStringLiteral( "qgis/lastDxfUseMText" ), "true" ).toString() ) != QLatin1String( "false" ) ); QStringList ids = QgsProject::instance()->mapThemeCollection()->mapThemes(); ids.prepend( QLatin1String( "" ) ); @@ -608,7 +609,12 @@ bool QgsDxfExportDialog::layerTitleAsName() const bool QgsDxfExportDialog::force2d() const { - return mForce2d->isChecked(); + return mForce2d->isChecked(); +} + +bool QgsDxfExportDialog::useMText() const +{ + return mMTextCheckBox->isChecked(); } void QgsDxfExportDialog::saveSettings() @@ -622,6 +628,7 @@ void QgsDxfExportDialog::saveSettings() s.setValue( QStringLiteral( "qgis/lastDxfLayerTitleAsName" ), mLayerTitleAsName->isChecked() ); s.setValue( QStringLiteral( "qgis/lastDxfEncoding" ), mEncoding->currentText() ); s.setValue( QStringLiteral( "qgis/lastDxfCrs" ), QString::number( mCRS.srsid() ) ); + s.setValue( QStringLiteral( "qgis/lastDxfUseMText" ), mMTextCheckBox->isChecked() ); QgsProject::instance()->writeEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfSymbologyMode" ), mSymbologyModeComboBox->currentIndex() ); QgsProject::instance()->writeEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastSymbologyExportScale" ), mScaleWidget->scale() != 0 ? 1.0 / mScaleWidget->scale() : 0 ); @@ -630,6 +637,7 @@ void QgsDxfExportDialog::saveSettings() QgsProject::instance()->writeEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfEncoding" ), mEncoding->currentText() ); QgsProject::instance()->writeEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastVisibilityPreset" ), mVisibilityPresets->currentText() ); QgsProject::instance()->writeEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfCrs" ), QString::number( mCRS.srsid() ) ); + QgsProject::instance()->writeEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfUseMText" ), mMTextCheckBox->isChecked() ); } diff --git a/src/app/qgsdxfexportdialog.h b/src/app/qgsdxfexportdialog.h old mode 100644 new mode 100755 index 2841f5c6e5a..0b03fa9b051 --- a/src/app/qgsdxfexportdialog.h +++ b/src/app/qgsdxfexportdialog.h @@ -88,6 +88,7 @@ class QgsDxfExportDialog : public QDialog, private Ui::QgsDxfExportDialogBase bool exportMapExtent() const; bool layerTitleAsName() const; bool force2d() const; + bool useMText() const; QString mapTheme() const; QString encoding() const; QgsCoordinateReferenceSystem crs() const; diff --git a/src/core/dxf/qgsdxfexport.cpp b/src/core/dxf/qgsdxfexport.cpp old mode 100644 new mode 100755 index 6237283ea09..1a4425b8ec3 --- a/src/core/dxf/qgsdxfexport.cpp +++ b/src/core/dxf/qgsdxfexport.cpp @@ -389,6 +389,16 @@ void QgsDxfExport::setMapSettings( const QgsMapSettings &settings ) mMapSettings = settings; } +void QgsDxfExport::setFlags( QgsDxfExport::Flags flags ) +{ + mFlags = flags; +} + +QgsDxfExport::Flags QgsDxfExport::flags() const +{ + return mFlags; +} + void QgsDxfExport::addLayers( const QList< QPair< QgsVectorLayer *, int > > &layers ) { QList layerList; @@ -3633,6 +3643,7 @@ void QgsDxfExport::writeText( const QString &layer, const QString &text, const Q writeGroup( 1, text ); writeGroup( 50, angle ); writeGroup( 7, QStringLiteral( "STANDARD" ) ); // so far only support for standard font + writeGroup( 100, QStringLiteral( "AcDbText" ) ); } 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, } } - txt = txt.replace( wrapchr, QLatin1String( "\\P" ) ); - - if ( tmpLyr.format().font().underline() ) + if ( mFlags & FlagNoMText ) { - txt.prepend( "\\L" ).append( "\\l" ); + writeText( dxfLayer, txt, QgsPoint( label->getX(), label->getY() ), label->getHeight(), label->getAlpha() * 180.0 / M_PI, tmpLyr.format().color() ); } - - if ( tmpLyr.format().font().overline() ) + else { - txt.prepend( "\\O" ).append( "\\o" ); + txt = txt.replace( wrapchr, QLatin1String( "\\P" ) ); + + if ( tmpLyr.format().font().underline() ) + { + txt.prepend( "\\L" ).append( "\\l" ); + } + + if ( tmpLyr.format().font().overline() ) + { + txt.prepend( "\\O" ).append( "\\o" ); + } + + if ( tmpLyr.format().font().strikeOut() ) + { + txt.prepend( "\\K" ).append( "\\k" ); + } + + txt.prepend( QStringLiteral( "\\f%1|i%2|b%3;\\H%4;" ) + .arg( tmpLyr.format().font().family() ) + .arg( tmpLyr.format().font().italic() ? 1 : 0 ) + .arg( tmpLyr.format().font().bold() ? 1 : 0 ) + .arg( label->getHeight() / ( 1 + txt.count( QStringLiteral( "\\P" ) ) ) * 0.75 ) ); + writeMText( dxfLayer, txt, QgsPoint( label->getX(), label->getY() ), label->getWidth(), label->getAlpha() * 180.0 / M_PI, tmpLyr.format().color() ); } - - if ( tmpLyr.format().font().strikeOut() ) - { - txt.prepend( "\\K" ).append( "\\k" ); - } - - txt.prepend( QStringLiteral( "\\f%1|i%2|b%3;\\H%4;" ) - .arg( tmpLyr.format().font().family() ) - .arg( tmpLyr.format().font().italic() ? 1 : 0 ) - .arg( tmpLyr.format().font().bold() ? 1 : 0 ) - .arg( label->getHeight() / ( 1 + txt.count( QStringLiteral( "\\P" ) ) ) * 0.75 ) ); - - writeMText( dxfLayer, txt, QgsPoint( label->getX(), label->getY() ), label->getWidth(), label->getAlpha() * 180.0 / M_PI, tmpLyr.format().color() ); } diff --git a/src/core/dxf/qgsdxfexport.h b/src/core/dxf/qgsdxfexport.h index ee47ca4ecce..08daafe2f31 100644 --- a/src/core/dxf/qgsdxfexport.h +++ b/src/core/dxf/qgsdxfexport.h @@ -53,11 +53,18 @@ class CORE_EXPORT QgsDxfExport public: enum SymbologyExport { - NoSymbology = 0, //export only data - FeatureSymbology, //Keeps the number of features and export symbology per feature (using the first symbol level) - SymbolLayerSymbology //Exports one feature per symbol layer (considering symbol levels) + NoSymbology = 0, //!< Export only data + FeatureSymbology, //!< Keeps the number of features and export symbology per feature (using the first symbol level) + SymbolLayerSymbology //!< Exports one feature per symbol layer (considering symbol levels) }; + //! Export flags + enum Flag + { + FlagNoMText = 1 << 1, //!< Export text as TEXT elements. If not set, text will be exported as MTEXT elements. + }; + Q_DECLARE_FLAGS( Flags, Flag ) + /** * Constructor for QgsDxfExport. */ @@ -71,6 +78,20 @@ class CORE_EXPORT QgsDxfExport */ void setMapSettings( const QgsMapSettings &settings ); + /** + * Sets the export flags. + * \since QGIS 3.0 + * \see flags() + */ + void setFlags( QgsDxfExport::Flags flags ); + + /** + * Returns the export flags. + * \since QGIS 3.0 + * \see setFlags() + */ + QgsDxfExport::Flags flags() const; + /** * Add layers to export * \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 QHash mLayerNameAttribute; double mFactor = 1.0; bool mForce2d = false; + + QgsDxfExport::Flags mFlags = 0; + }; +Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDxfExport::Flags ) + #endif // QGSDXFEXPORT_H diff --git a/src/ui/qgsdxfexportdialogbase.ui b/src/ui/qgsdxfexportdialogbase.ui old mode 100644 new mode 100755 index 4e533d89a78..cf1b4347527 --- a/src/ui/qgsdxfexportdialogbase.ui +++ b/src/ui/qgsdxfexportdialogbase.ui @@ -14,17 +14,10 @@ DXF Export - - + + - Symbology scale - - - - - - - + Symbology mode @@ -35,6 +28,13 @@ + + + + + + + @@ -54,13 +54,16 @@ - - + + - Symbology mode + Symbology scale + + + @@ -81,8 +84,35 @@ - - + + + + Qt::StrongFocus + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok + + + + + + + + + + CRS + + @@ -115,29 +145,13 @@ - - - - - + + - Export features intersecting the current map extent + Encoding - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok - - - - - - @@ -145,40 +159,53 @@ - - - - Encoding - - - - - - - Use layer title as name if set - - - - - - - CRS - - - - - - - Qt::StrongFocus - - - - - - - Force 2d output (eg. to support polyline width) - - + + + + + + Export features intersecting the current map extent + + + + + + + Use layer title as name if set + + + + + + + Force 2d output (eg. to support polyline width) + + + + + + + Export labels as MTEXT elements + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + @@ -211,9 +238,6 @@ mTreeView mSelectAllButton mDeselectAllButton - mLayerTitleAsName - mMapExtentCheckBox - mForce2d buttonBox