Skip to content

Commit

Permalink
[FEATURE] dxf export: add option to use title instead of name as dxf …
Browse files Browse the repository at this point in the history
…layer name in application and server
  • Loading branch information
jef-n committed Dec 11, 2015
1 parent a1a19d2 commit 555b7a4
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgsdxfexportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -580,6 +581,10 @@ bool QgsDxfExportDialog::exportMapExtent() const
return mMapExtentCheckBox->isChecked();
}

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

void QgsDxfExportDialog::saveSettings()
{
Expand All @@ -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() );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsdxfexportdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
23 changes: 16 additions & 7 deletions src/core/dxf/qgsdxfexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ QgsDxfExport::QgsDxfExport()
: mSymbologyScaleDenominator( 1.0 )
, mSymbologyExport( NoSymbology )
, mMapUnits( QGis::Meters )
, mLayerTitleAsName( false )
, mSymbolLayerCounter( 0 )
, mNextHandleId( DXF_HANDSEED )
, mBlockCounter( 0 )
Expand Down Expand Up @@ -716,7 +717,7 @@ void QgsDxfExport::writeTables()
{
if ( layerIt->second < 0 )
{
layerNames << dxfLayerName( layerIt->first->name() );
layerNames << dxfLayerName( layerName( layerIt->first ) );
}
else
{
Expand Down Expand Up @@ -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
{
Expand All @@ -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 );
}
}
}
Expand All @@ -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 );
}
}
}
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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();
}
5 changes: 5 additions & 0 deletions src/core/dxf/qgsdxfexport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -128,6 +132,7 @@ class CORE_EXPORT QgsDxfExport
double mSymbologyScaleDenominator;
SymbologyExport mSymbologyExport;
QGis::UnitType mMapUnits;
bool mLayerTitleAsName;

QTextStream mTextStream;

Expand Down
4 changes: 3 additions & 1 deletion src/server/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );

Expand Down
42 changes: 25 additions & 17 deletions src/ui/qgsdxfexportdialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -172,6 +179,7 @@
<tabstop>mTreeView</tabstop>
<tabstop>mSelectAllButton</tabstop>
<tabstop>mUnSelectAllButton</tabstop>
<tabstop>mLayerTitleAsName</tabstop>
<tabstop>mMapExtentCheckBox</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
Expand Down

0 comments on commit 555b7a4

Please sign in to comment.