mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
[dxf][feature] Add option to export labels as text elements, instead of mtext
Sponsored by SMEC
This commit is contained in:
parent
d2369425c6
commit
1535ff84ff
@ -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
Normal file → Executable file
1
src/app/qgsdxfexportdialog.h
Normal file → Executable file
@ -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;
|
||||
|
57
src/core/dxf/qgsdxfexport.cpp
Normal file → Executable file
57
src/core/dxf/qgsdxfexport.cpp
Normal file → Executable file
@ -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().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() );
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
166
src/ui/qgsdxfexportdialogbase.ui
Normal file → Executable file
166
src/ui/qgsdxfexportdialogbase.ui
Normal file → Executable file
@ -14,17 +14,10 @@
|
||||
<string>DXF Export</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="mSymbologyScaleLabel">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="mSymbologyModeLabel">
|
||||
<property name="text">
|
||||
<string>Symbology scale</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QToolButton" name="mFileSelectionButton">
|
||||
<property name="text">
|
||||
<string>…</string>
|
||||
<string>Symbology mode</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -35,6 +28,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QToolButton" name="mFileSelectionButton">
|
||||
<property name="text">
|
||||
<string>…</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="mSymbologyModeComboBox">
|
||||
<item>
|
||||
@ -54,13 +54,16 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="mSymbologyModeLabel">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="mSymbologyScaleLabel">
|
||||
<property name="text">
|
||||
<string>Symbology mode</string>
|
||||
<string>Symbology scale</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="mEncoding"/>
|
||||
</item>
|
||||
<item row="7" column="0" colspan="3">
|
||||
<widget class="QgsLayerTreeView" name="mTreeView">
|
||||
<property name="selectionMode">
|
||||
@ -81,8 +84,35 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="mEncoding"/>
|
||||
<item row="5" column="1" colspan="2">
|
||||
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector" native="true">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="mVisibilityPresets"/>
|
||||
</item>
|
||||
<item row="15" column="0" colspan="3">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="mFileLineEdit"/>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>CRS</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0" colspan="3">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
@ -115,29 +145,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="mFileLineEdit"/>
|
||||
</item>
|
||||
<item row="11" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="mMapExtentCheckBox">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Export features intersecting the current map extent</string>
|
||||
<string>Encoding</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="13" column="0" colspan="3">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="mVisibilityPresets"/>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="mSymbologyScaleLabel_2">
|
||||
<property name="text">
|
||||
@ -145,40 +159,53 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Encoding</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="mLayerTitleAsName">
|
||||
<property name="text">
|
||||
<string>Use layer title as name if set</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>CRS</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1" colspan="2">
|
||||
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector" native="true">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="12" column="0" colspan="3">
|
||||
<widget class="QCheckBox" name="mForce2d">
|
||||
<property name="text">
|
||||
<string>Force 2d output (eg. to support polyline width)</string>
|
||||
</property>
|
||||
</widget>
|
||||
<item row="11" column="0" colspan="3">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="mMapExtentCheckBox">
|
||||
<property name="text">
|
||||
<string>Export features intersecting the current map extent</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="mLayerTitleAsName">
|
||||
<property name="text">
|
||||
<string>Use layer title as name if set</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="mForce2d">
|
||||
<property name="text">
|
||||
<string>Force 2d output (eg. to support polyline width)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="mMTextCheckBox">
|
||||
<property name="text">
|
||||
<string>Export labels as MTEXT elements</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@ -211,9 +238,6 @@
|
||||
<tabstop>mTreeView</tabstop>
|
||||
<tabstop>mSelectAllButton</tabstop>
|
||||
<tabstop>mDeselectAllButton</tabstop>
|
||||
<tabstop>mLayerTitleAsName</tabstop>
|
||||
<tabstop>mMapExtentCheckBox</tabstop>
|
||||
<tabstop>mForce2d</tabstop>
|
||||
<tabstop>buttonBox</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user