Skip to content
Permalink
Browse files

[FEATURE] dxf export: add option to use title instead of name as dxf …

…layer name in application and server
  • Loading branch information
jef-n committed Dec 11, 2015
1 parent a1a19d2 commit 555b7a431906de48e6014976e5102c0b859a72aa
@@ -4512,6 +4512,7 @@ void QgisApp::dxfExport()
dxfExport.addLayers( d.layers() );
dxfExport.setSymbologyScaleDenominator( d.symbologyScale() );
dxfExport.setSymbologyExport( d.symbologyMode() );
dxfExport.setLayerTitleAsName( d.layerTitleAsName() );
if ( mapCanvas() )
{
dxfExport.setMapUnits( mapCanvas()->mapUnits() );
@@ -445,6 +445,7 @@ QgsDxfExportDialog::QgsDxfExportDialog( QWidget *parent, Qt::WindowFlags f )
//last symbol scale
mScaleWidget->setMapCanvas( QgisApp::instance()->mapCanvas() );
mScaleWidget->setScale( QgsProject::instance()->readEntry( "dxf", "/lastSymbologyExportScale", s.value( "qgis/lastSymbologyExportScale", "1/50000" ).toString() ).toDouble() );
mLayerTitleAsName->setChecked( QgsProject::instance()->readEntry( "dxf", "/lastDxfLayerTitleAsName", s.value( "qgis/lastDxfLayerTitleAsName", "false" ).toString() ) != "false" );
mMapExtentCheckBox->setChecked( QgsProject::instance()->readEntry( "dxf", "/lastDxfMapRectangle", s.value( "qgis/lastDxfMapRectangle", "false" ).toString() ) != "false" );

QStringList ids = QgsProject::instance()->visibilityPresetCollection()->presets();
@@ -580,6 +581,10 @@ bool QgsDxfExportDialog::exportMapExtent() const
return mMapExtentCheckBox->isChecked();
}

bool QgsDxfExportDialog::layerTitleAsName() const
{
return mLayerTitleAsName->isChecked();
}

void QgsDxfExportDialog::saveSettings()
{
@@ -589,10 +594,12 @@ void QgsDxfExportDialog::saveSettings()
s.setValue( "qgis/lastDxfSymbologyMode", mSymbologyModeComboBox->currentIndex() );
s.setValue( "qgis/lastSymbologyExportScale", mScaleWidget->scale() );
s.setValue( "qgis/lastDxfMapRectangle", mMapExtentCheckBox->isChecked() );
s.setValue( "qgis/lastDxfLayerTitleAsName", mLayerTitleAsName->isChecked() );
s.setValue( "qgis/lastDxfEncoding", mEncoding->currentText() );

QgsProject::instance()->writeEntry( "dxf", "/lastDxfSymbologyMode", mSymbologyModeComboBox->currentIndex() );
QgsProject::instance()->writeEntry( "dxf", "/lastSymbologyExportScale", mScaleWidget->scale() );
QgsProject::instance()->writeEntry( "dxf", "/lastDxfLayerTitleAsName", mLayerTitleAsName->isChecked() );
QgsProject::instance()->writeEntry( "dxf", "/lastDxfMapRectangle", mMapExtentCheckBox->isChecked() );
QgsProject::instance()->writeEntry( "dxf", "/lastDxfEncoding", mEncoding->currentText() );
QgsProject::instance()->writeEntry( "dxf", "/lastVisibilityPreset", mVisibilityPresets->currentText() );
@@ -86,6 +86,7 @@ class QgsDxfExportDialog : public QDialog, private Ui::QgsDxfExportDialogBase
QgsDxfExport::SymbologyExport symbologyMode() const;
QString saveFile() const;
bool exportMapExtent() const;
bool layerTitleAsName() const;
QString encoding() const;

public slots:
@@ -356,6 +356,7 @@ QgsDxfExport::QgsDxfExport()
: mSymbologyScaleDenominator( 1.0 )
, mSymbologyExport( NoSymbology )
, mMapUnits( QGis::Meters )
, mLayerTitleAsName( false )
, mSymbolLayerCounter( 0 )
, mNextHandleId( DXF_HANDSEED )
, mBlockCounter( 0 )
@@ -716,7 +717,7 @@ void QgsDxfExport::writeTables()
{
if ( layerIt->second < 0 )
{
layerNames << dxfLayerName( layerIt->first->name() );
layerNames << dxfLayerName( layerName( layerIt->first ) );
}
else
{
@@ -967,12 +968,12 @@ void QgsDxfExport::writeEntities()
while ( featureIt.nextFeature( fet ) )
{
ctx.expressionContext().setFeature( fet );
QString layerName( dxfLayerName( layerIt->second == -1 ? vl->name() : fet.attribute( layerIt->second ).toString() ) );
QString lName( dxfLayerName( layerIt->second == -1 ? layerName( vl ) : fet.attribute( layerIt->second ).toString() ) );

sctx.setFeature( &fet );
if ( mSymbologyExport == NoSymbology )
{
addFeature( sctx, layerName, 0, 0 ); // no symbology at all
addFeature( sctx, lName, 0, 0 ); // no symbology at all
}
else
{
@@ -990,7 +991,7 @@ void QgsDxfExport::writeEntities()
int nSymbolLayers = ( *symbolIt )->symbolLayerCount();
for ( int i = 0; i < nSymbolLayers; ++i )
{
addFeature( sctx, layerName, ( *symbolIt )->symbolLayer( i ), *symbolIt );
addFeature( sctx, lName, ( *symbolIt )->symbolLayer( i ), *symbolIt );
}
}
}
@@ -1002,12 +1003,12 @@ void QgsDxfExport::writeEntities()
{
continue;
}
addFeature( sctx, layerName, s->symbolLayer( 0 ), s );
addFeature( sctx, lName, s->symbolLayer( 0 ), s );
}

if ( lp )
{
lp->registerDxfFeature( fet, ctx, layerName );
lp->registerDxfFeature( fet, ctx, lName );
}
}
}
@@ -4119,7 +4120,9 @@ QString QgsDxfExport::layerName( const QString &id, const QgsFeature &f ) const
for ( ; layerIt != mLayers.constEnd(); ++layerIt )
{
if ( layerIt->first && layerIt->first->id() == id )
return dxfLayerName( layerIt->second < 0 ? layerIt->first->name() : f.attribute( layerIt->second ).toString() );
{
return dxfLayerName( layerIt->second < 0 ? layerName( layerIt->first ) : f.attribute( layerIt->second ).toString() );
}
}

return "0";
@@ -4159,3 +4162,9 @@ QStringList QgsDxfExport::encodings()
}
return encodings;
}

QString QgsDxfExport::layerName( QgsVectorLayer *vl ) const
{
Q_ASSERT( vl );
return mLayerTitleAsName && !vl->title().isEmpty() ? vl->title() : vl->name();
}
@@ -59,10 +59,14 @@ class CORE_EXPORT QgsDxfExport
void setExtent( const QgsRectangle &r ) { mExtent = r; }
QgsRectangle extent() const { return mExtent; }

bool layerTitleAsName() { return mLayerTitleAsName; }
void setLayerTitleAsName( bool layerTitleAsName ) { mLayerTitleAsName = layerTitleAsName; };

//get closest entry in dxf palette
static int closestColorMatch( QRgb pixel );

QString layerName( const QString &id, const QgsFeature &f ) const;
QString layerName( QgsVectorLayer *vl ) const;

//! @note available in python bindings as writeGroupInt
void writeGroup( int code, int i );
@@ -128,6 +132,7 @@ class CORE_EXPORT QgsDxfExport
double mSymbologyScaleDenominator;
SymbologyExport mSymbologyExport;
QGis::UnitType mMapUnits;
bool mLayerTitleAsName;

QTextStream mTextStream;

@@ -1439,14 +1439,16 @@ void QgsWMSServer::getMapAsDxf()
}
dxf.setExtent( extent );

//get format options (for MODE,SCALE, LAYERATTRIBUTES )
//get format options (for MODE, USE_TITLE_AS_LAYERNAME, SCALE, LAYERATTRIBUTES)
QMap<QString, QString > formatOptionsMap;
readFormatOptions( formatOptionsMap );

QList< QPair<QgsVectorLayer *, int > > layers;
readDxfLayerSettings( layers, formatOptionsMap );
dxf.addLayers( layers );

dxf.setLayerTitleAsName( formatOptionsMap.contains( "USE_TITLE_AS_LAYERNAME" ) );

//MODE
QMap<QString, QString>::const_iterator modeIt = formatOptionsMap.find( "MODE" );

@@ -14,6 +14,16 @@
<string>DXF export</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="1" colspan="2">
<widget class="QgsScaleWidget" name="mScaleWidget">
<property name="showCurrentScaleButton">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QComboBox" name="mEncoding"/>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="mFileSelectionButton">
<property name="text">
@@ -105,14 +115,14 @@
<item row="0" column="1">
<widget class="QLineEdit" name="mFileLineEdit"/>
</item>
<item row="8" column="0" colspan="3">
<item row="9" column="0" colspan="3">
<widget class="QCheckBox" name="mMapExtentCheckBox">
<property name="text">
<string>Export features intersecting the current map extent</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="3">
<item row="10" column="0" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -132,36 +142,33 @@
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QgsScaleWidget" name="mScaleWidget" native="true">
<property name="showCurrentScaleButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QComboBox" name="mEncoding"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Encoding</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="3">
<widget class="QCheckBox" name="mLayerTitleAsName">
<property name="text">
<string>Use layer title as name if set</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsLayerTreeView</class>
<extends>QTreeView</extends>
<header>qgslayertreeview.h</header>
</customwidget>
<customwidget>
<class>QgsScaleWidget</class>
<extends>QWidget</extends>
<header>qgsscalewidget.h</header>
</customwidget>
<customwidget>
<class>QgsLayerTreeView</class>
<extends>QTreeView</extends>
<header>qgslayertreeview.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mFileLineEdit</tabstop>
@@ -172,6 +179,7 @@
<tabstop>mTreeView</tabstop>
<tabstop>mSelectAllButton</tabstop>
<tabstop>mUnSelectAllButton</tabstop>
<tabstop>mLayerTitleAsName</tabstop>
<tabstop>mMapExtentCheckBox</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>

0 comments on commit 555b7a4

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