Skip to content
Permalink
Browse files

[dxf][feature] Add option to export labels as text elements, instead …

…of mtext

Sponsored by SMEC
  • Loading branch information
nyalldawson committed Nov 16, 2017
1 parent d236942 commit 1535ff84ffb2a16678e96cbf1cfc98e7a00477ff
@@ -27,6 +27,13 @@ class QgsDxfExport
SymbolLayerSymbology
};

enum Flag
{
FlagNoMText,
};
typedef QFlags<QgsDxfExport::Flag> 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<QgsVectorLayer *, int > > &layers );
%Docstring
Add layers to export
@@ -342,6 +364,9 @@ return list of available DXF encodings

};

QFlags<QgsDxfExport::Flag> operator|(QgsDxfExport::Flag f1, QFlags<QgsDxfExport::Flag> f2);


/************************************************************************
* This file has been generated automatically from *
* *
@@ -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
@@ -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() );
}


1 src/app/qgsdxfexportdialog.h 100644 → 100755
@@ -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;
53 src/core/dxf/qgsdxfexport.cpp 100644 → 100755
@@ -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<QgsMapLayer *> 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().strikeOut() )
{
txt.prepend( "\\K" ).append( "\\k" );
}
if ( tmpLyr.format().font().underline() )
{
txt.prepend( "\\L" ).append( "\\l" );
}

if ( tmpLyr.format().font().overline() )
{
txt.prepend( "\\O" ).append( "\\o" );
}

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 ) );
if ( tmpLyr.format().font().strikeOut() )
{
txt.prepend( "\\K" ).append( "\\k" );
}

writeMText( dxfLayer, txt, QgsPoint( label->getX(), label->getY() ), label->getWidth(), label->getAlpha() * 180.0 / M_PI, tmpLyr.format().color() );
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() );
}
}


@@ -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<QString, int> mLayerNameAttribute;
double mFactor = 1.0;
bool mForce2d = false;

QgsDxfExport::Flags mFlags = 0;

};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDxfExport::Flags )

#endif // QGSDXFEXPORT_H

0 comments on commit 1535ff8

Please sign in to comment.
You can’t perform that action at this time.