Skip to content

Commit 561f01c

Browse files
committed
[FEATURE]: merge dxf_export branch
2 parents ba76c99 + 0239b4d commit 561f01c

24 files changed

+3013
-14
lines changed

python/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ INCLUDE_DIRECTORIES(
3838
../src/core/pal
3939
../src/core/composer
4040
../src/core/diagram
41+
../src/core/dxf
4142
../src/core/gps
4243
../src/core/raster
4344
../src/core/symbology-ng

python/core/core.sip

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
%Include qgsdatasourceuri.sip
2828
%Include qgsdbfilterproxymodel.sip
2929
%Include qgsdistancearea.sip
30+
%Include qgsdxfexport.sip
3031
%Include qgseditorwidgetconfig.sip
3132
%Include qgserror.sip
3233
%Include qgsexpression.sip

python/core/qgsdxfexport.sip

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/***************************************************************************
2+
qgsdxfexport.sip
3+
----------------
4+
begin : September 2013
5+
copyright : (C) 2013 by Marco Hugentobler
6+
email : marco at sourcepole dot ch
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
class QgsDxfExport
19+
{
20+
%TypeHeaderCode
21+
#include <qgsdxfexport.h>
22+
%End
23+
public:
24+
QgsDxfExport();
25+
~QgsDxfExport();
26+
27+
void addLayers( QList< QgsMapLayer* >& layers );
28+
int writeToFile( QIODevice* d );
29+
};

python/core/symbology-ng/qgssymbollayerv2.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class QgsMarkerSymbolLayerV2 : QgsSymbolLayerV2
157157

158158
protected:
159159
QgsMarkerSymbolLayerV2( bool locked = false );
160-
void markerOffset( QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY );
160+
void markerOffset( const QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY ) const;
161161
static QPointF _rotatedOffset( const QPointF& offset, double angle );
162162
};
163163

src/app/CMakeLists.txt

+3-1
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
@@ -190,6 +191,7 @@ SET (QGIS_APP_MOC_HDRS
190191
qgsdelattrdialog.h
191192
qgsdiagramproperties.h
192193
qgsdisplayangle.h
194+
qgsdxfexportdialog.h
193195
qgsfeatureaction.h
194196
qgsfieldcalculator.h
195197
qgsfieldsproperties.h
@@ -423,7 +425,7 @@ INCLUDE_DIRECTORIES(
423425
../analysis/raster ../analysis/openstreetmap
424426
../core
425427
../core/gps
426-
../core/composer ../core/raster ../core/symbology-ng
428+
../core/composer ../core/dxf ../core/raster ../core/symbology-ng
427429
../gui ../gui/symbology-ng ../gui/attributetable ../gui/raster ../gui/editorwidgets ../gui/editorwidgets/core
428430
../plugins
429431
../python

src/app/qgisapp.cpp

+52-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@
116116
#include "qgscustomprojectiondialog.h"
117117
#include "qgsdatasourceuri.h"
118118
#include "qgsdatumtransformdialog.h"
119+
#include "qgsdxfexport.h"
120+
#include "qgsdxfexportdialog.h"
119121
#include "qgsdecorationcopyright.h"
120122
#include "qgsdecorationnortharrow.h"
121123
#include "qgsdecorationscalebar.h"
@@ -958,6 +960,7 @@ void QgisApp::createActions()
958960
connect( mActionNewPrintComposer, SIGNAL( triggered() ), this, SLOT( newPrintComposer() ) );
959961
connect( mActionShowComposerManager, SIGNAL( triggered() ), this, SLOT( showComposerManager() ) );
960962
connect( mActionExit, SIGNAL( triggered() ), this, SLOT( fileExit() ) );
963+
connect( mActionDxfExport, SIGNAL( triggered() ), this, SLOT( dxfExport() ) );
961964

962965
// Edit Menu Items
963966

@@ -3808,6 +3811,54 @@ void QgisApp::fileSaveAs()
38083811
}
38093812
} // QgisApp::fileSaveAs
38103813

3814+
void QgisApp::dxfExport()
3815+
{
3816+
QgsLegend* mapLegend = legend();
3817+
if ( !mapLegend )
3818+
{
3819+
return;
3820+
}
3821+
3822+
QgsDxfExportDialog d( mapLegend->layers() );
3823+
if ( d.exec() == QDialog::Accepted )
3824+
{
3825+
QgsDxfExport dxfExport;
3826+
3827+
QList<QgsMapLayer*> layerList;
3828+
QList<QString> layerIdList = d.layers();
3829+
QList<QString>::const_iterator layerIt = layerIdList.constBegin();
3830+
for ( ; layerIt != layerIdList.constEnd(); ++layerIt )
3831+
{
3832+
QgsMapLayer* l = QgsMapLayerRegistry::instance()->mapLayer( *layerIt );
3833+
if ( l )
3834+
{
3835+
layerList.append( l );
3836+
}
3837+
}
3838+
3839+
dxfExport.addLayers( layerList );
3840+
dxfExport.setSymbologyScaleDenominator( d.symbologyScale() );
3841+
dxfExport.setSymbologyExport( d.symbologyMode() );
3842+
if ( mapCanvas() )
3843+
{
3844+
QgsMapRenderer* r = mapCanvas()->mapRenderer();
3845+
if ( r )
3846+
{
3847+
dxfExport.setMapUnits( r->mapUnits() );
3848+
}
3849+
}
3850+
QFile dxfFile( d.saveFile() );
3851+
if ( dxfExport.writeToFile( &dxfFile ) == 0 )
3852+
{
3853+
messageBar()->pushMessage( tr( "DXF export completed" ), QgsMessageBar::INFO, 4 );
3854+
}
3855+
else
3856+
{
3857+
messageBar()->pushMessage( tr( "DXF export failed" ), QgsMessageBar::CRITICAL, 4 );
3858+
}
3859+
}
3860+
}
3861+
38113862
// Open the project file corresponding to the
38123863
// path at the given index in mRecentProjectPaths
38133864
void QgisApp::openProject( QAction *action )
@@ -7430,7 +7481,7 @@ QMenu* QgisApp::getPluginMenu( QString menuName )
74307481
}
74317482
// It doesn't exist, so create
74327483
QMenu *menu = new QMenu( menuName, this );
7433-
menu->setObjectName( menuName.normalized(QString::NormalizationForm_KD).remove(QRegExp("[^a-zA-Z]")) );
7484+
menu->setObjectName( menuName.normalized( QString::NormalizationForm_KD ).remove( QRegExp( "[^a-zA-Z]" ) ) );
74347485
// Where to put it? - we worked that out above...
74357486
mPluginMenu->insertMenu( before, menu );
74367487

src/app/qgisapp.h

+2
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
838838
bool fileSave();
839839
//! Save project as
840840
void fileSaveAs();
841+
//! Export project in dxf format
842+
void dxfExport();
841843
//! Open the project file corresponding to the
842844
//! text)= of the given action.
843845
void openProject( QAction *action );

src/app/qgsdxfexportdialog.cpp

+119
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<QgsMapLayer*>& 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<QgsMapLayer*>::const_iterator layerIt = layerKeys.constBegin();
16+
for ( ; layerIt != layerKeys.constEnd(); ++layerIt )
17+
{
18+
QgsMapLayer* layer = *layerIt;
19+
if ( layer )
20+
{
21+
if ( layer->type() == QgsMapLayer::VectorLayer )
22+
{
23+
QListWidgetItem* layerItem = new QListWidgetItem( layer->name() );
24+
layerItem->setData( Qt::UserRole, layer->id() );
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.prepend( 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

+25
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<QgsMapLayer*>& 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/core/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ SET(QGIS_CORE_SRCS
162162
composer/qgscomposerhtml.cpp
163163
composer/qgscomposermultiframe.cpp
164164
composer/qgscomposition.cpp
165+
166+
dxf/qgsdxfexport.cpp
167+
dxf/qgsdxfpaintdevice.cpp
168+
dxf/qgsdxfpaintengine.cpp
165169

166170
pal/costcalculator.cpp
167171
pal/feature.cpp
@@ -556,6 +560,7 @@ ENDIF (QT_MOBILITY_LOCATION_FOUND)
556560
INCLUDE_DIRECTORIES(
557561
${CMAKE_CURRENT_SOURCE_DIR}
558562
composer
563+
dxf
559564
pal
560565
raster
561566
renderer

0 commit comments

Comments
 (0)