Skip to content

Commit

Permalink
vector layer save as: replace 'original crs' with 'layer crs' and 'pr…
Browse files Browse the repository at this point in the history
…oject crs' - OTFR doesn't matter anymore (fixes #4109)
  • Loading branch information
jef-n authored and alexbruy committed Feb 11, 2012
1 parent 4ba2c39 commit b3807b7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 34 deletions.
32 changes: 27 additions & 5 deletions src/app/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -20,14 +20,15 @@
#include "qgsgenericprojectionselector.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorfilewriter.h"
#include "qgscoordinatereferencesystem.h"

#include <QSettings>
#include <QFileDialog>
#include <QTextCodec>

QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QWidget* parent, Qt::WFlags fl )
QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( long srsid, QWidget* parent, Qt::WFlags fl )
: QDialog( parent, fl )
, mCRS( -1 )
, mCRS( srsid )
{
setupUi( this );

Expand All @@ -53,9 +54,13 @@ QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QWidget* parent, Qt::WFl
idx = 0;
}

mEncodingComboBox->setCurrentIndex( idx );
mCRSSelection->clear();
mCRSSelection->addItems( QStringList() << tr( "Layer CRS" ) << tr( "Project CRS" ) << tr( "Selected CRS" ) );

QgsCoordinateReferenceSystem srs( srsid, QgsCoordinateReferenceSystem::InternalCrsId );
leCRS->setText( srs.description() );

leCRS->setText( tr( "Original CRS" ) );
mEncodingComboBox->setCurrentIndex( idx );
on_mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() );
}

Expand All @@ -72,6 +77,11 @@ void QgsVectorLayerSaveAsDialog::accept()
QDialog::accept();
}

void QgsVectorLayerSaveAsDialog::on_mCRSSelection_currentIndexChanged( int idx )
{
leCRS->setEnabled( idx == 2 );
}

void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx )
{
browseFilename->setEnabled( true );
Expand Down Expand Up @@ -120,6 +130,7 @@ void QgsVectorLayerSaveAsDialog::on_browseCRS_clicked()
QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
mCRS = srs.srsid();
leCRS->setText( srs.description() );
mCRSSelection->setCurrentIndex( 2 );
}

delete mySelector;
Expand All @@ -142,7 +153,18 @@ QString QgsVectorLayerSaveAsDialog::format() const

long QgsVectorLayerSaveAsDialog::crs() const
{
return mCRS;
if ( mCRSSelection->currentIndex() == 0 )
{
return -1; // Layer CRS
}
else if ( mCRSSelection->currentIndex() == 1 )
{
return -2; // Project CRS
}
else
{
return mCRS;
}
}

QStringList QgsVectorLayerSaveAsDialog::datasourceOptions() const
Expand Down
3 changes: 2 additions & 1 deletion src/app/ogr/qgsvectorlayersaveasdialog.h
Expand Up @@ -31,7 +31,7 @@ class QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVectorLayerSav
Q_OBJECT

public:
QgsVectorLayerSaveAsDialog( QWidget* parent = 0, Qt::WFlags fl = 0 );
QgsVectorLayerSaveAsDialog( long srsid, QWidget* parent = 0, Qt::WFlags fl = 0 );
~QgsVectorLayerSaveAsDialog();

QString format() const;
Expand All @@ -44,6 +44,7 @@ class QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVectorLayerSav

private slots:
void on_mFormatComboBox_currentIndexChanged( int idx );
void on_mCRSSelection_currentIndexChanged( int idx );
void on_browseFilename_clicked();
void on_browseCRS_clicked();
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
Expand Down
23 changes: 10 additions & 13 deletions src/app/qgisapp.cpp
Expand Up @@ -3284,29 +3284,26 @@ void QgisApp::saveAsVectorFileGeneral( bool saveOnlySelection )

QgsCoordinateReferenceSystem destCRS;

QgsVectorLayerSaveAsDialog *dialog = new QgsVectorLayerSaveAsDialog( this );
QgsVectorLayerSaveAsDialog *dialog = new QgsVectorLayerSaveAsDialog( vlayer->crs().srsid(), this );

if ( dialog->exec() == QDialog::Accepted )
{
QString encoding = dialog->encoding();
QString vectorFilename = dialog->filename();
QString format = dialog->format();

if ( dialog->crs() < 0 )
switch ( dialog->crs() )
{
// Find out if we have projections enabled or not
if ( mMapCanvas->mapRenderer()->hasCrsTransformEnabled() )
{
case -2: // Project CRS
destCRS = mMapCanvas->mapRenderer()->destinationCrs();
}
else
{
break;
case -1: // Layer CRS
destCRS = vlayer->crs();
}
}
else
{
destCRS = QgsCoordinateReferenceSystem( dialog->crs(), QgsCoordinateReferenceSystem::InternalCrsId );
break;

default: // Selected CRS
destCRS = QgsCoordinateReferenceSystem( dialog->crs(), QgsCoordinateReferenceSystem::InternalCrsId );
break;
}

// ok if the file existed it should be deleted now so we can continue...
Expand Down
36 changes: 21 additions & 15 deletions src/ui/qgsvectorlayersaveasdialogbase.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>383</width>
<height>427</height>
<height>496</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -21,24 +21,17 @@
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>CRS</string>
</property>
<property name="buddy">
<cstring>leCRS</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QLineEdit" name="leCRS">
<property name="enabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="0" colspan="3">
<item row="8" column="0" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand Down Expand Up @@ -68,7 +61,7 @@
</property>
</widget>
</item>
<item row="5" column="2">
<item row="6" column="2">
<widget class="QPushButton" name="browseCRS">
<property name="text">
<string>Browse</string>
Expand Down Expand Up @@ -101,7 +94,7 @@
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="mFormatComboBox"/>
</item>
<item row="6" column="0" colspan="3">
<item row="7" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>OGR creation options</string>
Expand Down Expand Up @@ -146,6 +139,19 @@
</layout>
</widget>
</item>
<item row="5" column="1" colspan="2">
<widget class="QComboBox" name="mCRSSelection"/>
</item>
<item row="5" column="0" rowspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>CRS</string>
</property>
<property name="buddy">
<cstring>leCRS</cstring>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
Expand Down

0 comments on commit b3807b7

Please sign in to comment.