Skip to content
Permalink
Browse files

Add dxf export gui and menu entry in qgisapp

  • Loading branch information
mhugent committed Nov 5, 2013
1 parent d131b7a commit 446b6d632f1be00fcd2882048beb73a21e0e0c86
@@ -27,6 +27,7 @@ SET(QGIS_APP_SRCS
qgsdecorationscalebardialog.cpp
qgsdecorationgrid.cpp
qgsdecorationgriddialog.cpp
qgsdxfexportdialog.cpp
qgsformannotationdialog.cpp
qgshtmlannotationdialog.cpp
qgsdelattrdialog.cpp
@@ -187,6 +188,7 @@ SET (QGIS_APP_MOC_HDRS
qgsdelattrdialog.h
qgsdiagramproperties.h
qgsdisplayangle.h
qgsdxfexportdialog.h
qgsfeatureaction.h
qgsfieldcalculator.h
qgsfieldsproperties.h
@@ -118,6 +118,8 @@
#include "qgscustomization.h"
#include "qgscustomprojectiondialog.h"
#include "qgsdatasourceuri.h"
#include "qgsdxfexport.h"
#include "qgsdxfexportdialog.h"
#include "qgsdecorationcopyright.h"
#include "qgsdecorationnortharrow.h"
#include "qgsdecorationscalebar.h"
@@ -947,6 +949,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

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

void QgisApp::dxfExport()
{
QgsDxfExportDialog d( QgsMapLayerRegistry::instance()->mapLayers().keys() );
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() );
QFile dxfFile( d.saveFile() );
dxfExport.writeToFile( &dxfFile );
}
}

// Open the project file corresponding to the
// path at the given index in mRecentProjectPaths
void QgisApp::openProject( QAction *action )
@@ -8873,27 +8903,27 @@ bool QgisApp::addRasterLayers( QStringList const &theFileNameQStringList, bool g
///////////////////////////////////////////////////////////////////

#ifdef ANDROID
void QgisApp::keyReleaseEvent(QKeyEvent *event)
void QgisApp::keyReleaseEvent( QKeyEvent *event )
{
static bool accepted=true;
if (event->key()==Qt::Key_Close)
static bool accepted = true;
if ( event->key() == Qt::Key_Close )
{
// do something useful here
int ret = QMessageBox::question( this, tr( "Exit QGIS" ),
tr( "Do you really want to quit QGIS?" ),
QMessageBox::Yes | QMessageBox::No );
switch ( ret )
{
// do something useful here
int ret = QMessageBox::question(this, tr("Exit QGIS"),
tr("Do you really want to quit QGIS?"),
QMessageBox::Yes | QMessageBox::No);
switch(ret)
{
case QMessageBox::Yes:
this->close();
break;
case QMessageBox::Yes:
this->close();
break;

case QMessageBox::No:
break;
}
event->setAccepted(accepted); // dont't close my Top Level Widget !
accepted=false;// close the app next time when the user press back button
case QMessageBox::No:
break;
}
event->setAccepted( accepted ); // dont't close my Top Level Widget !
accepted = false;// close the app next time when the user press back button
}
}
#endif

@@ -827,6 +827,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<QString>& 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<QString>::const_iterator layerIt = layerKeys.constBegin();
for ( ; layerIt != layerKeys.constEnd(); ++layerIt )
{
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( *layerIt );
if ( layer )
{
if ( layer->type() == QgsMapLayer::VectorLayer )
{
QListWidgetItem* layerItem = new QListWidgetItem( layer->name() );
layerItem->setData( Qt::UserRole, *layerIt );
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.append( 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<QString>& 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
@@ -17,7 +17,7 @@
<x>0</x>
<y>0</y>
<width>1050</width>
<height>31</height>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="mProjectMenu">
@@ -47,6 +47,7 @@
<addaction name="mActionSaveProject"/>
<addaction name="mActionSaveProjectAs"/>
<addaction name="mActionSaveMapAsImage"/>
<addaction name="mActionDxfExport"/>
<addaction name="separator"/>
<addaction name="mActionNewPrintComposer"/>
<addaction name="mActionShowComposerManager"/>
@@ -2136,6 +2137,11 @@ Acts on currently active editable layer</string>
<string>Paste features in clipboard into a new memory vector layer.</string>
</property>
</action>
<action name="mActionDxfExport">
<property name="text">
<string>DXF Export...</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>

0 comments on commit 446b6d6

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