Skip to content

Commit 446b6d6

Browse files
committed
Add dxf export gui and menu entry in qgisapp
1 parent d131b7a commit 446b6d6

File tree

7 files changed

+339
-19
lines changed

7 files changed

+339
-19
lines changed

src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ SET(QGIS_APP_SRCS
2727
qgsdecorationscalebardialog.cpp
2828
qgsdecorationgrid.cpp
2929
qgsdecorationgriddialog.cpp
30+
qgsdxfexportdialog.cpp
3031
qgsformannotationdialog.cpp
3132
qgshtmlannotationdialog.cpp
3233
qgsdelattrdialog.cpp
@@ -187,6 +188,7 @@ SET (QGIS_APP_MOC_HDRS
187188
qgsdelattrdialog.h
188189
qgsdiagramproperties.h
189190
qgsdisplayangle.h
191+
qgsdxfexportdialog.h
190192
qgsfeatureaction.h
191193
qgsfieldcalculator.h
192194
qgsfieldsproperties.h

src/app/qgisapp.cpp

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@
118118
#include "qgscustomization.h"
119119
#include "qgscustomprojectiondialog.h"
120120
#include "qgsdatasourceuri.h"
121+
#include "qgsdxfexport.h"
122+
#include "qgsdxfexportdialog.h"
121123
#include "qgsdecorationcopyright.h"
122124
#include "qgsdecorationnortharrow.h"
123125
#include "qgsdecorationscalebar.h"
@@ -947,6 +949,7 @@ void QgisApp::createActions()
947949
connect( mActionNewPrintComposer, SIGNAL( triggered() ), this, SLOT( newPrintComposer() ) );
948950
connect( mActionShowComposerManager, SIGNAL( triggered() ), this, SLOT( showComposerManager() ) );
949951
connect( mActionExit, SIGNAL( triggered() ), this, SLOT( fileExit() ) );
952+
connect( mActionDxfExport, SIGNAL( triggered() ), this, SLOT( dxfExport() ) );
950953

951954
// Edit Menu Items
952955

@@ -1778,7 +1781,7 @@ void QgisApp::setTheme( QString theThemeName )
17781781
mActionRotateFeature->setIcon( QgsApplication::getThemeIcon( "/mActionRotateFeature.png" ) );
17791782
mActionReshapeFeatures->setIcon( QgsApplication::getThemeIcon( "/mActionReshape.png" ) );
17801783
mActionSplitFeatures->setIcon( QgsApplication::getThemeIcon( "/mActionSplitFeatures.svg" ) );
1781-
mActionSplitParts->setIcon( QgsApplication::getThemeIcon( "/mActionSplitParts.svg" ) );
1784+
mActionSplitParts->setIcon( QgsApplication::getThemeIcon( "/mActionSplitParts.svg" ) );
17821785
mActionDeleteSelected->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteSelected.svg" ) );
17831786
mActionNodeTool->setIcon( QgsApplication::getThemeIcon( "/mActionNodeTool.png" ) );
17841787
mActionSimplifyFeature->setIcon( QgsApplication::getThemeIcon( "/mActionSimplify.png" ) );
@@ -3797,6 +3800,33 @@ void QgisApp::fileSaveAs()
37973800
}
37983801
} // QgisApp::fileSaveAs
37993802

3803+
void QgisApp::dxfExport()
3804+
{
3805+
QgsDxfExportDialog d( QgsMapLayerRegistry::instance()->mapLayers().keys() );
3806+
if ( d.exec() == QDialog::Accepted )
3807+
{
3808+
QgsDxfExport dxfExport;
3809+
3810+
QList<QgsMapLayer*> layerList;
3811+
QList<QString> layerIdList = d.layers();
3812+
QList<QString>::const_iterator layerIt = layerIdList.constBegin();
3813+
for ( ; layerIt != layerIdList.constEnd(); ++layerIt )
3814+
{
3815+
QgsMapLayer* l = QgsMapLayerRegistry::instance()->mapLayer( *layerIt );
3816+
if ( l )
3817+
{
3818+
layerList.append( l );
3819+
}
3820+
}
3821+
3822+
dxfExport.addLayers( layerList );
3823+
dxfExport.setSymbologyScaleDenominator( d.symbologyScale() );
3824+
dxfExport.setSymbologyExport( d.symbologyMode() );
3825+
QFile dxfFile( d.saveFile() );
3826+
dxfExport.writeToFile( &dxfFile );
3827+
}
3828+
}
3829+
38003830
// Open the project file corresponding to the
38013831
// path at the given index in mRecentProjectPaths
38023832
void QgisApp::openProject( QAction *action )
@@ -8873,27 +8903,27 @@ bool QgisApp::addRasterLayers( QStringList const &theFileNameQStringList, bool g
88738903
///////////////////////////////////////////////////////////////////
88748904

88758905
#ifdef ANDROID
8876-
void QgisApp::keyReleaseEvent(QKeyEvent *event)
8906+
void QgisApp::keyReleaseEvent( QKeyEvent *event )
88778907
{
8878-
static bool accepted=true;
8879-
if (event->key()==Qt::Key_Close)
8908+
static bool accepted = true;
8909+
if ( event->key() == Qt::Key_Close )
8910+
{
8911+
// do something useful here
8912+
int ret = QMessageBox::question( this, tr( "Exit QGIS" ),
8913+
tr( "Do you really want to quit QGIS?" ),
8914+
QMessageBox::Yes | QMessageBox::No );
8915+
switch ( ret )
88808916
{
8881-
// do something useful here
8882-
int ret = QMessageBox::question(this, tr("Exit QGIS"),
8883-
tr("Do you really want to quit QGIS?"),
8884-
QMessageBox::Yes | QMessageBox::No);
8885-
switch(ret)
8886-
{
8887-
case QMessageBox::Yes:
8888-
this->close();
8889-
break;
8917+
case QMessageBox::Yes:
8918+
this->close();
8919+
break;
88908920

8891-
case QMessageBox::No:
8892-
break;
8893-
}
8894-
event->setAccepted(accepted); // dont't close my Top Level Widget !
8895-
accepted=false;// close the app next time when the user press back button
8921+
case QMessageBox::No:
8922+
break;
88968923
}
8924+
event->setAccepted( accepted ); // dont't close my Top Level Widget !
8925+
accepted = false;// close the app next time when the user press back button
8926+
}
88978927
}
88988928
#endif
88998929

src/app/qgisapp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
827827
bool fileSave();
828828
//! Save project as
829829
void fileSaveAs();
830+
//! Export project in dxf format
831+
void dxfExport();
830832
//! Open the project file corresponding to the
831833
//! text)= of the given action.
832834
void openProject( QAction *action );

src/app/qgsdxfexportdialog.cpp

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#include "qgsdxfexportdialog.h"
2+
#include "qgsmaplayer.h"
3+
#include "qgsmaplayerregistry.h"
4+
#include "qgis.h"
5+
#include <QFileDialog>
6+
#include <QPushButton>
7+
#include <QSettings>
8+
9+
QgsDxfExportDialog::QgsDxfExportDialog( const QList<QString>& layerKeys, QWidget* parent, Qt::WindowFlags f ): QDialog( parent, f )
10+
{
11+
setupUi( this );
12+
connect( mFileLineEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( setOkEnabled() ) );
13+
connect( this, SIGNAL( accepted() ), this, SLOT( saveSettings() ) );
14+
15+
QList<QString>::const_iterator layerIt = layerKeys.constBegin();
16+
for ( ; layerIt != layerKeys.constEnd(); ++layerIt )
17+
{
18+
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( *layerIt );
19+
if ( layer )
20+
{
21+
if ( layer->type() == QgsMapLayer::VectorLayer )
22+
{
23+
QListWidgetItem* layerItem = new QListWidgetItem( layer->name() );
24+
layerItem->setData( Qt::UserRole, *layerIt );
25+
layerItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
26+
layerItem->setCheckState( Qt::Checked );
27+
mLayersListWidget->addItem( layerItem );
28+
}
29+
}
30+
}
31+
32+
//last dxf symbology mode
33+
QSettings s;
34+
mSymbologyModeComboBox->setCurrentIndex( s.value( "qgis/lastDxfSymbologyMode", "2" ).toInt() );
35+
//last symbol scale
36+
mSymbologyScaleLineEdit->setText( s.value( "qgis/lastSymbologyExportScale", "50000" ).toString() );
37+
38+
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
39+
}
40+
41+
QgsDxfExportDialog::~QgsDxfExportDialog()
42+
{
43+
44+
}
45+
46+
QList<QString> QgsDxfExportDialog::layers() const
47+
{
48+
QList<QString> layerKeyList;
49+
int nItems = mLayersListWidget->count();
50+
for ( int i = 0; i < nItems; ++i )
51+
{
52+
QListWidgetItem* currentItem = mLayersListWidget->item( i );
53+
if ( currentItem->checkState() == Qt::Checked )
54+
{
55+
layerKeyList.append( currentItem->data( Qt::UserRole ).toString() );
56+
}
57+
}
58+
return layerKeyList;
59+
}
60+
61+
double QgsDxfExportDialog::symbologyScale() const
62+
{
63+
double scale = mSymbologyScaleLineEdit->text().toDouble();
64+
if ( qgsDoubleNear( scale, 0.0 ) )
65+
{
66+
return 1.0;
67+
}
68+
return scale;
69+
}
70+
71+
QString QgsDxfExportDialog::saveFile() const
72+
{
73+
return mFileLineEdit->text();
74+
}
75+
76+
QgsDxfExport::SymbologyExport QgsDxfExportDialog::symbologyMode() const
77+
{
78+
return ( QgsDxfExport::SymbologyExport )mSymbologyModeComboBox->currentIndex();
79+
}
80+
81+
void QgsDxfExportDialog::on_mFileSelectionButton_clicked()
82+
{
83+
//get last dxf save directory
84+
QSettings s;
85+
QString lastSavePath = s.value( "qgis/lastDxfDir" ).toString();
86+
87+
QString filePath = QFileDialog::getSaveFileName( 0, tr( "Export as DXF" ), lastSavePath, tr( "DXF files *.dxf *.DXF" ) );
88+
if ( !filePath.isEmpty() )
89+
{
90+
mFileLineEdit->setText( filePath );
91+
}
92+
}
93+
94+
void QgsDxfExportDialog::setOkEnabled()
95+
{
96+
QPushButton* btn = buttonBox->button( QDialogButtonBox::Ok );
97+
98+
QString filePath = mFileLineEdit->text();
99+
if ( filePath.isEmpty() )
100+
{
101+
btn->setEnabled( false );
102+
}
103+
104+
QFileInfo fi( filePath );
105+
btn->setEnabled( fi.absoluteDir().exists() );
106+
}
107+
108+
void QgsDxfExportDialog::saveSettings()
109+
{
110+
QSettings s;
111+
112+
//last dxf dir
113+
QFileInfo dxfFileInfo( mFileLineEdit->text() );
114+
s.setValue( "qgis/lastDxfDir", dxfFileInfo.absolutePath() );
115+
116+
//last dxf symbology mode
117+
s.setValue( "qgis/lastDxfSymbologyMode", mSymbologyModeComboBox->currentIndex() );
118+
s.setValue( "qgis/lastSymbologyExportScale", mSymbologyScaleLineEdit->text() );
119+
}

src/app/qgsdxfexportdialog.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef QGSDXFEXPORTDIALOG_H
2+
#define QGSDXFEXPORTDIALOG_H
3+
4+
#include "ui_qgsdxfexportdialogbase.h"
5+
#include "qgsdxfexport.h"
6+
7+
class QgsDxfExportDialog: public QDialog, private Ui::QgsDxfExportDialogBase
8+
{
9+
Q_OBJECT
10+
public:
11+
QgsDxfExportDialog( const QList<QString>& layerKeys, QWidget * parent = 0, Qt::WindowFlags f = 0 );
12+
~QgsDxfExportDialog();
13+
14+
QList<QString> layers() const;
15+
double symbologyScale() const;
16+
QgsDxfExport::SymbologyExport symbologyMode() const;
17+
QString saveFile() const;
18+
19+
private slots:
20+
void on_mFileSelectionButton_clicked();
21+
void setOkEnabled();
22+
void saveSettings();
23+
};
24+
25+
#endif // QGSDXFEXPORTDIALOG_H

src/ui/qgisapp.ui

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<x>0</x>
1818
<y>0</y>
1919
<width>1050</width>
20-
<height>31</height>
20+
<height>20</height>
2121
</rect>
2222
</property>
2323
<widget class="QMenu" name="mProjectMenu">
@@ -47,6 +47,7 @@
4747
<addaction name="mActionSaveProject"/>
4848
<addaction name="mActionSaveProjectAs"/>
4949
<addaction name="mActionSaveMapAsImage"/>
50+
<addaction name="mActionDxfExport"/>
5051
<addaction name="separator"/>
5152
<addaction name="mActionNewPrintComposer"/>
5253
<addaction name="mActionShowComposerManager"/>
@@ -2136,6 +2137,11 @@ Acts on currently active editable layer</string>
21362137
<string>Paste features in clipboard into a new memory vector layer.</string>
21372138
</property>
21382139
</action>
2140+
<action name="mActionDxfExport">
2141+
<property name="text">
2142+
<string>DXF Export...</string>
2143+
</property>
2144+
</action>
21392145
</widget>
21402146
<resources>
21412147
<include location="../../images/images.qrc"/>

0 commit comments

Comments
 (0)