Skip to content
Permalink
Browse files

[FEATURE]: merge dxf_export branch

  • Loading branch information
mhugent committed Dec 6, 2013
2 parents ba76c99 + 0239b4d commit 561f01c0c222ca6d4d7c2904606d66d00f963c66
@@ -38,6 +38,7 @@ INCLUDE_DIRECTORIES(
../src/core/pal
../src/core/composer
../src/core/diagram
../src/core/dxf
../src/core/gps
../src/core/raster
../src/core/symbology-ng
@@ -27,6 +27,7 @@
%Include qgsdatasourceuri.sip
%Include qgsdbfilterproxymodel.sip
%Include qgsdistancearea.sip
%Include qgsdxfexport.sip
%Include qgseditorwidgetconfig.sip
%Include qgserror.sip
%Include qgsexpression.sip
@@ -0,0 +1,29 @@
/***************************************************************************
qgsdxfexport.sip
----------------
begin : September 2013
copyright : (C) 2013 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

class QgsDxfExport
{
%TypeHeaderCode
#include <qgsdxfexport.h>
%End
public:
QgsDxfExport();
~QgsDxfExport();

void addLayers( QList< QgsMapLayer* >& layers );
int writeToFile( QIODevice* d );
};
@@ -157,7 +157,7 @@ class QgsMarkerSymbolLayerV2 : QgsSymbolLayerV2

protected:
QgsMarkerSymbolLayerV2( bool locked = false );
void markerOffset( QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY );
void markerOffset( const QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY ) const;
static QPointF _rotatedOffset( const QPointF& offset, double angle );
};

@@ -27,6 +27,7 @@ SET(QGIS_APP_SRCS
qgsdecorationscalebardialog.cpp
qgsdecorationgrid.cpp
qgsdecorationgriddialog.cpp
qgsdxfexportdialog.cpp
qgsformannotationdialog.cpp
qgshtmlannotationdialog.cpp
qgsdelattrdialog.cpp
@@ -190,6 +191,7 @@ SET (QGIS_APP_MOC_HDRS
qgsdelattrdialog.h
qgsdiagramproperties.h
qgsdisplayangle.h
qgsdxfexportdialog.h
qgsfeatureaction.h
qgsfieldcalculator.h
qgsfieldsproperties.h
@@ -423,7 +425,7 @@ INCLUDE_DIRECTORIES(
../analysis/raster ../analysis/openstreetmap
../core
../core/gps
../core/composer ../core/raster ../core/symbology-ng
../core/composer ../core/dxf ../core/raster ../core/symbology-ng
../gui ../gui/symbology-ng ../gui/attributetable ../gui/raster ../gui/editorwidgets ../gui/editorwidgets/core
../plugins
../python
@@ -116,6 +116,8 @@
#include "qgscustomprojectiondialog.h"
#include "qgsdatasourceuri.h"
#include "qgsdatumtransformdialog.h"
#include "qgsdxfexport.h"
#include "qgsdxfexportdialog.h"
#include "qgsdecorationcopyright.h"
#include "qgsdecorationnortharrow.h"
#include "qgsdecorationscalebar.h"
@@ -958,6 +960,7 @@ void QgisApp::createActions()
connect( mActionNewPrintComposer, SIGNAL( triggered() ), this, SLOT( newPrintComposer() ) );
connect( mActionShowComposerManager, SIGNAL( triggered() ), this, SLOT( showComposerManager() ) );
connect( mActionExit, SIGNAL( triggered() ), this, SLOT( fileExit() ) );
connect( mActionDxfExport, SIGNAL( triggered() ), this, SLOT( dxfExport() ) );

// Edit Menu Items

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

void QgisApp::dxfExport()
{
QgsLegend* mapLegend = legend();
if ( !mapLegend )
{
return;
}

QgsDxfExportDialog d( mapLegend->layers() );
if ( d.exec() == QDialog::Accepted )
{
QgsDxfExport dxfExport;

QList<QgsMapLayer*> layerList;
QList<QString> layerIdList = d.layers();
QList<QString>::const_iterator layerIt = layerIdList.constBegin();
for ( ; layerIt != layerIdList.constEnd(); ++layerIt )
{
QgsMapLayer* l = QgsMapLayerRegistry::instance()->mapLayer( *layerIt );
if ( l )
{
layerList.append( l );
}
}

dxfExport.addLayers( layerList );
dxfExport.setSymbologyScaleDenominator( d.symbologyScale() );
dxfExport.setSymbologyExport( d.symbologyMode() );
if ( mapCanvas() )
{
QgsMapRenderer* r = mapCanvas()->mapRenderer();
if ( r )
{
dxfExport.setMapUnits( r->mapUnits() );
}
}
QFile dxfFile( d.saveFile() );
if ( dxfExport.writeToFile( &dxfFile ) == 0 )
{
messageBar()->pushMessage( tr( "DXF export completed" ), QgsMessageBar::INFO, 4 );
}
else
{
messageBar()->pushMessage( tr( "DXF export failed" ), QgsMessageBar::CRITICAL, 4 );
}
}
}

// Open the project file corresponding to the
// path at the given index in mRecentProjectPaths
void QgisApp::openProject( QAction *action )
@@ -7430,7 +7481,7 @@ QMenu* QgisApp::getPluginMenu( QString menuName )
}
// It doesn't exist, so create
QMenu *menu = new QMenu( menuName, this );
menu->setObjectName( menuName.normalized(QString::NormalizationForm_KD).remove(QRegExp("[^a-zA-Z]")) );
menu->setObjectName( menuName.normalized( QString::NormalizationForm_KD ).remove( QRegExp( "[^a-zA-Z]" ) ) );
// Where to put it? - we worked that out above...
mPluginMenu->insertMenu( before, menu );

@@ -838,6 +838,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
bool fileSave();
//! Save project as
void fileSaveAs();
//! Export project in dxf format
void dxfExport();
//! Open the project file corresponding to the
//! text)= of the given action.
void openProject( QAction *action );
@@ -0,0 +1,119 @@
#include "qgsdxfexportdialog.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgis.h"
#include <QFileDialog>
#include <QPushButton>
#include <QSettings>

QgsDxfExportDialog::QgsDxfExportDialog( const QList<QgsMapLayer*>& layerKeys, QWidget* parent, Qt::WindowFlags f ): QDialog( parent, f )
{
setupUi( this );
connect( mFileLineEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( setOkEnabled() ) );
connect( this, SIGNAL( accepted() ), this, SLOT( saveSettings() ) );

QList<QgsMapLayer*>::const_iterator layerIt = layerKeys.constBegin();
for ( ; layerIt != layerKeys.constEnd(); ++layerIt )
{
QgsMapLayer* layer = *layerIt;
if ( layer )
{
if ( layer->type() == QgsMapLayer::VectorLayer )
{
QListWidgetItem* layerItem = new QListWidgetItem( layer->name() );
layerItem->setData( Qt::UserRole, layer->id() );
layerItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
layerItem->setCheckState( Qt::Checked );
mLayersListWidget->addItem( layerItem );
}
}
}

//last dxf symbology mode
QSettings s;
mSymbologyModeComboBox->setCurrentIndex( s.value( "qgis/lastDxfSymbologyMode", "2" ).toInt() );
//last symbol scale
mSymbologyScaleLineEdit->setText( s.value( "qgis/lastSymbologyExportScale", "50000" ).toString() );

buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
}

QgsDxfExportDialog::~QgsDxfExportDialog()
{

}

QList<QString> QgsDxfExportDialog::layers() const
{
QList<QString> layerKeyList;
int nItems = mLayersListWidget->count();
for ( int i = 0; i < nItems; ++i )
{
QListWidgetItem* currentItem = mLayersListWidget->item( i );
if ( currentItem->checkState() == Qt::Checked )
{
layerKeyList.prepend( currentItem->data( Qt::UserRole ).toString() );
}
}
return layerKeyList;
}

double QgsDxfExportDialog::symbologyScale() const
{
double scale = mSymbologyScaleLineEdit->text().toDouble();
if ( qgsDoubleNear( scale, 0.0 ) )
{
return 1.0;
}
return scale;
}

QString QgsDxfExportDialog::saveFile() const
{
return mFileLineEdit->text();
}

QgsDxfExport::SymbologyExport QgsDxfExportDialog::symbologyMode() const
{
return ( QgsDxfExport::SymbologyExport )mSymbologyModeComboBox->currentIndex();
}

void QgsDxfExportDialog::on_mFileSelectionButton_clicked()
{
//get last dxf save directory
QSettings s;
QString lastSavePath = s.value( "qgis/lastDxfDir" ).toString();

QString filePath = QFileDialog::getSaveFileName( 0, tr( "Export as DXF" ), lastSavePath, tr( "DXF files *.dxf *.DXF" ) );
if ( !filePath.isEmpty() )
{
mFileLineEdit->setText( filePath );
}
}

void QgsDxfExportDialog::setOkEnabled()
{
QPushButton* btn = buttonBox->button( QDialogButtonBox::Ok );

QString filePath = mFileLineEdit->text();
if ( filePath.isEmpty() )
{
btn->setEnabled( false );
}

QFileInfo fi( filePath );
btn->setEnabled( fi.absoluteDir().exists() );
}

void QgsDxfExportDialog::saveSettings()
{
QSettings s;

//last dxf dir
QFileInfo dxfFileInfo( mFileLineEdit->text() );
s.setValue( "qgis/lastDxfDir", dxfFileInfo.absolutePath() );

//last dxf symbology mode
s.setValue( "qgis/lastDxfSymbologyMode", mSymbologyModeComboBox->currentIndex() );
s.setValue( "qgis/lastSymbologyExportScale", mSymbologyScaleLineEdit->text() );
}
@@ -0,0 +1,25 @@
#ifndef QGSDXFEXPORTDIALOG_H
#define QGSDXFEXPORTDIALOG_H

#include "ui_qgsdxfexportdialogbase.h"
#include "qgsdxfexport.h"

class QgsDxfExportDialog: public QDialog, private Ui::QgsDxfExportDialogBase
{
Q_OBJECT
public:
QgsDxfExportDialog( const QList<QgsMapLayer*>& layerKeys, QWidget * parent = 0, Qt::WindowFlags f = 0 );
~QgsDxfExportDialog();

QList<QString> layers() const;
double symbologyScale() const;
QgsDxfExport::SymbologyExport symbologyMode() const;
QString saveFile() const;

private slots:
void on_mFileSelectionButton_clicked();
void setOkEnabled();
void saveSettings();
};

#endif // QGSDXFEXPORTDIALOG_H
@@ -162,6 +162,10 @@ SET(QGIS_CORE_SRCS
composer/qgscomposerhtml.cpp
composer/qgscomposermultiframe.cpp
composer/qgscomposition.cpp

dxf/qgsdxfexport.cpp
dxf/qgsdxfpaintdevice.cpp
dxf/qgsdxfpaintengine.cpp

pal/costcalculator.cpp
pal/feature.cpp
@@ -556,6 +560,7 @@ ENDIF (QT_MOBILITY_LOCATION_FOUND)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
composer
dxf
pal
raster
renderer

0 comments on commit 561f01c

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