Skip to content

Commit 3f50017

Browse files
committed
vector layer save as: replace 'original crs' with 'layer crs' and 'project crs' - OTFR doesn't matter anymore (fixes #4109)
1 parent 16d0d2f commit 3f50017

File tree

4 files changed

+61
-35
lines changed

4 files changed

+61
-35
lines changed

src/app/ogr/qgsvectorlayersaveasdialog.cpp

+27-5
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
#include "qgsgenericprojectionselector.h"
2020
#include "qgsvectordataprovider.h"
2121
#include "qgsvectorfilewriter.h"
22+
#include "qgscoordinatereferencesystem.h"
2223

2324
#include <QSettings>
2425
#include <QFileDialog>
2526
#include <QTextCodec>
2627

27-
QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QWidget* parent, Qt::WFlags fl )
28+
QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( long srsid, QWidget* parent, Qt::WFlags fl )
2829
: QDialog( parent, fl )
29-
, mCRS( -1 )
30+
, mCRS( srsid )
3031
{
3132
setupUi( this );
3233

@@ -57,9 +58,13 @@ QgsVectorLayerSaveAsDialog::QgsVectorLayerSaveAsDialog( QWidget* parent, Qt::WFl
5758
idx = 0;
5859
}
5960

60-
mEncodingComboBox->setCurrentIndex( idx );
61+
mCRSSelection->clear();
62+
mCRSSelection->addItems( QStringList() << tr( "Layer CRS" ) << tr( "Project CRS" ) << tr( "Selected CRS" ) );
63+
64+
QgsCoordinateReferenceSystem srs( srsid, QgsCoordinateReferenceSystem::InternalCrsId );
65+
leCRS->setText( srs.description() );
6166

62-
leCRS->setText( tr( "Original CRS" ) );
67+
mEncodingComboBox->setCurrentIndex( idx );
6368
on_mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() );
6469
}
6570

@@ -78,6 +83,11 @@ void QgsVectorLayerSaveAsDialog::accept()
7883
QDialog::accept();
7984
}
8085

86+
void QgsVectorLayerSaveAsDialog::on_mCRSSelection_currentIndexChanged( int idx )
87+
{
88+
leCRS->setEnabled( idx == 2 );
89+
}
90+
8191
void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx )
8292
{
8393
Q_UNUSED( idx );
@@ -128,6 +138,7 @@ void QgsVectorLayerSaveAsDialog::on_browseCRS_clicked()
128138
QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
129139
mCRS = srs.srsid();
130140
leCRS->setText( srs.description() );
141+
mCRSSelection->setCurrentIndex( 2 );
131142
}
132143

133144
delete mySelector;
@@ -150,7 +161,18 @@ QString QgsVectorLayerSaveAsDialog::format() const
150161

151162
long QgsVectorLayerSaveAsDialog::crs() const
152163
{
153-
return mCRS;
164+
if ( mCRSSelection->currentIndex() == 0 )
165+
{
166+
return -1; // Layer CRS
167+
}
168+
else if ( mCRSSelection->currentIndex() == 1 )
169+
{
170+
return -2; // Project CRS
171+
}
172+
else
173+
{
174+
return mCRS;
175+
}
154176
}
155177

156178
QStringList QgsVectorLayerSaveAsDialog::datasourceOptions() const

src/app/ogr/qgsvectorlayersaveasdialog.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVectorLayerSav
3030
Q_OBJECT
3131

3232
public:
33-
QgsVectorLayerSaveAsDialog( QWidget* parent = 0, Qt::WFlags fl = 0 );
33+
QgsVectorLayerSaveAsDialog( long srsid, QWidget* parent = 0, Qt::WFlags fl = 0 );
3434
~QgsVectorLayerSaveAsDialog();
3535

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

4545
private slots:
4646
void on_mFormatComboBox_currentIndexChanged( int idx );
47+
void on_mCRSSelection_currentIndexChanged( int idx );
4748
void on_browseFilename_clicked();
4849
void on_browseCRS_clicked();
4950
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }

src/app/qgisapp.cpp

+10-13
Original file line numberDiff line numberDiff line change
@@ -3422,7 +3422,7 @@ void QgisApp::saveAsVectorFileGeneral( bool saveOnlySelection )
34223422

34233423
QgsCoordinateReferenceSystem destCRS;
34243424

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

34273427
if ( dialog->exec() == QDialog::Accepted )
34283428
{
@@ -3438,21 +3438,18 @@ void QgisApp::saveAsVectorFileGeneral( bool saveOnlySelection )
34383438
format = "SQLite";
34393439
}
34403440

3441-
if ( dialog->crs() < 0 )
3441+
switch ( dialog->crs() )
34423442
{
3443-
// Find out if we have projections enabled or not
3444-
if ( mMapCanvas->mapRenderer()->hasCrsTransformEnabled() )
3445-
{
3443+
case -2: // Project CRS
34463444
destCRS = mMapCanvas->mapRenderer()->destinationCrs();
3447-
}
3448-
else
3449-
{
3445+
break;
3446+
case -1: // Layer CRS
34503447
destCRS = vlayer->crs();
3451-
}
3452-
}
3453-
else
3454-
{
3455-
destCRS = QgsCoordinateReferenceSystem( dialog->crs(), QgsCoordinateReferenceSystem::InternalCrsId );
3448+
break;
3449+
3450+
default: // Selected CRS
3451+
destCRS = QgsCoordinateReferenceSystem( dialog->crs(), QgsCoordinateReferenceSystem::InternalCrsId );
3452+
break;
34563453
}
34573454

34583455
// ok if the file existed it should be deleted now so we can continue...

src/ui/qgsvectorlayersaveasdialogbase.ui

+22-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>383</width>
10-
<height>427</height>
10+
<height>496</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -21,24 +21,17 @@
2121
</property>
2222
</widget>
2323
</item>
24-
<item row="5" column="0">
25-
<widget class="QLabel" name="label_3">
26-
<property name="text">
27-
<string>CRS</string>
28-
</property>
29-
<property name="buddy">
30-
<cstring>leCRS</cstring>
31-
</property>
32-
</widget>
33-
</item>
34-
<item row="5" column="1">
24+
<item row="6" column="1">
3525
<widget class="QLineEdit" name="leCRS">
26+
<property name="enabled">
27+
<bool>false</bool>
28+
</property>
3629
<property name="readOnly">
3730
<bool>true</bool>
3831
</property>
3932
</widget>
4033
</item>
41-
<item row="7" column="0" colspan="3">
34+
<item row="8" column="0" colspan="3">
4235
<widget class="QDialogButtonBox" name="buttonBox">
4336
<property name="orientation">
4437
<enum>Qt::Horizontal</enum>
@@ -68,7 +61,7 @@
6861
</property>
6962
</widget>
7063
</item>
71-
<item row="5" column="2">
64+
<item row="6" column="2">
7265
<widget class="QPushButton" name="browseCRS">
7366
<property name="text">
7467
<string>Browse</string>
@@ -101,7 +94,7 @@
10194
<item row="0" column="1" colspan="2">
10295
<widget class="QComboBox" name="mFormatComboBox"/>
10396
</item>
104-
<item row="6" column="0" colspan="3">
97+
<item row="7" column="0" colspan="3">
10598
<widget class="QGroupBox" name="groupBox">
10699
<property name="title">
107100
<string>OGR creation options</string>
@@ -146,13 +139,26 @@
146139
<item row="3" column="0" colspan="2">
147140
<widget class="QCheckBox" name="mAddToCanvas">
148141
<property name="text">
149-
<string>Add save file to map</string>
142+
<string>Add saved file to map</string>
150143
</property>
151144
</widget>
152145
</item>
153146
</layout>
154147
</widget>
155148
</item>
149+
<item row="5" column="1" colspan="2">
150+
<widget class="QComboBox" name="mCRSSelection"/>
151+
</item>
152+
<item row="5" column="0" rowspan="2">
153+
<widget class="QLabel" name="label_3">
154+
<property name="text">
155+
<string>CRS</string>
156+
</property>
157+
<property name="buddy">
158+
<cstring>leCRS</cstring>
159+
</property>
160+
</widget>
161+
</item>
156162
</layout>
157163
</widget>
158164
<tabstops>

0 commit comments

Comments
 (0)