Skip to content

Commit 1a46c40

Browse files
committed
Port a bunch of CRS selectors across to QgsProjectionSelectionWidget
1 parent 7933847 commit 1a46c40

20 files changed

+400
-433
lines changed

python/gui/qgsnewmemorylayerdialog.sip

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ class QgsNewMemoryLayerDialog : QDialog
1818
/**Returns the selected geometry type*/
1919
QGis::WkbType selectedType() const;
2020

21-
/**Returns the selected crs id*/
22-
QString selectedCrsId() const;
21+
/**Returns the selected crs*/
22+
QgsCoordinateReferenceSystem crs() const;
2323

2424
/**Returns the layer name*/
2525
QString layerName() const;
2626

27-
protected slots:
28-
29-
void on_mChangeSrsButton_clicked();
3027
};

python/gui/qgsnewvectorlayerdialog.sip

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class QgsNewVectorLayerDialog : QDialog
2727
void on_mAddAttributeButton_clicked();
2828
void on_mRemoveAttributeButton_clicked();
2929
void on_mTypeBox_currentIndexChanged( int index );
30-
void on_pbnChangeSpatialRefSys_clicked();
3130
void on_buttonBox_helpRequested();
3231
void nameChanged( QString );
3332
void selectionChanged();

python/gui/qgsprojectionselectionwidget.sip

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ class QgsProjectionSelectionWidget : QWidget
1414

1515
explicit QgsProjectionSelectionWidget( QWidget *parent /TransferThis/ = 0 );
1616

17+
/* Returns a pointer to the projection selector dialog used by the widget. Can be used
18+
* to modify how the projection selector dialog behaves.
19+
* @returns projection selector dialog
20+
*/
21+
QgsGenericProjectionSelector* dialog();
22+
23+
/* Returns a pointer to the line edit used by the widget
24+
* @returns CRS line edit
25+
*/
26+
QLineEdit* lineEdit();
27+
1728
/* Returns the currently selected CRS for the widget
1829
* @returns current CRS
1930
*/

src/app/ogr/qgsvectorlayersaveasdialog.cpp

+8-20
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ void QgsVectorLayerSaveAsDialog::setup()
8181
mCRSSelection->addItems( QStringList() << tr( "Layer CRS" ) << tr( "Project CRS" ) << tr( "Selected CRS" ) );
8282

8383
QgsCoordinateReferenceSystem srs( mCRS, QgsCoordinateReferenceSystem::InternalCrsId );
84-
leCRS->setText( srs.description() );
84+
mCrsSelector->setCrs( srs );
85+
mCrsSelector->dialog()->setMessage( tr( "Select the coordinate reference system for the vector file. "
86+
"The data points will be transformed from the layer coordinate reference system." ) );
8587

8688
mEncodingComboBox->setCurrentIndex( idx );
8789
on_mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() );
@@ -186,7 +188,7 @@ void QgsVectorLayerSaveAsDialog::accept()
186188

187189
void QgsVectorLayerSaveAsDialog::on_mCRSSelection_currentIndexChanged( int idx )
188190
{
189-
leCRS->setEnabled( idx == 2 );
191+
mCrsSelector->lineEdit()->setEnabled( idx == 2 );
190192

191193
QgsCoordinateReferenceSystem crs;
192194
if ( mCRSSelection->currentIndex() == 0 )
@@ -302,25 +304,11 @@ void QgsVectorLayerSaveAsDialog::on_browseFilename_clicked()
302304
}
303305
}
304306

305-
void QgsVectorLayerSaveAsDialog::on_browseCRS_clicked()
307+
void QgsVectorLayerSaveAsDialog::on_mCrsSelector_crsChanged( QgsCoordinateReferenceSystem crs )
306308
{
307-
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector();
308-
if ( mCRS >= 0 )
309-
mySelector->setSelectedCrsId( mCRS );
310-
mySelector->setMessage( tr( "Select the coordinate reference system for the vector file. "
311-
"The data points will be transformed from the layer coordinate reference system." ) );
312-
313-
if ( mySelector->exec() )
314-
{
315-
QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
316-
mCRS = srs.srsid();
317-
leCRS->setText( srs.description() );
318-
mCRSSelection->setCurrentIndex( 2 );
319-
320-
mExtentGroupBox->setOutputCrs( srs );
321-
}
322-
323-
delete mySelector;
309+
mCRS = crs.srsid();
310+
mCRSSelection->setCurrentIndex( 2 );
311+
mExtentGroupBox->setOutputCrs( crs );
324312
}
325313

326314
QString QgsVectorLayerSaveAsDialog::filename() const

src/app/ogr/qgsvectorlayersaveasdialog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVectorLayerSav
7070
void on_leFilename_textChanged( const QString& text );
7171
void on_mCRSSelection_currentIndexChanged( int idx );
7272
void on_browseFilename_clicked();
73-
void on_browseCRS_clicked();
73+
void on_mCrsSelector_crsChanged( QgsCoordinateReferenceSystem crs );
7474
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
7575
void on_mSymbologyExportComboBox_currentIndexChanged( const QString& text );
7676
void accept();

src/app/qgsrasterlayerproperties.cpp

+3-19
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
198198

199199
QgsDebugMsg( "Setting crs to " + mRasterLayer->crs().toWkt() );
200200
QgsDebugMsg( "Setting crs to " + mRasterLayer->crs().authid() + " - " + mRasterLayer->crs().description() );
201-
leSpatialRefSys->setText( mRasterLayer->crs().authid() + " - " + mRasterLayer->crs().description() );
202-
leSpatialRefSys->setCursorPosition( 0 );
201+
mCrsSelector->setCrs( mRasterLayer->crs() );
203202

204203
// Set text for pyramid info box
205204
QString pyramidFormat( "<h2>%1</h2><p>%2 %3 %4</p><b><font color='red'><p>%5</p><p>%6</p>" );
@@ -1086,24 +1085,9 @@ void QgsRasterLayerProperties::on_pbnAddValuesManually_clicked()
10861085
tableTransparency->resizeRowsToContents();
10871086
}
10881087

1089-
void QgsRasterLayerProperties::on_pbnChangeSpatialRefSys_clicked()
1088+
void QgsRasterLayerProperties::on_mCrsSelector_crsChanged( QgsCoordinateReferenceSystem crs )
10901089
{
1091-
1092-
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this );
1093-
mySelector->setSelectedCrsId( mRasterLayer->crs().srsid() );
1094-
if ( mySelector->exec() )
1095-
{
1096-
QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
1097-
mRasterLayer->setCrs( srs );
1098-
}
1099-
else
1100-
{
1101-
QApplication::restoreOverrideCursor();
1102-
}
1103-
delete mySelector;
1104-
1105-
leSpatialRefSys->setText( mRasterLayer->crs().authid() + " - " + mRasterLayer->crs().description() );
1106-
leSpatialRefSys->setCursorPosition( 0 );
1090+
mRasterLayer->setCrs( crs );
11071091
}
11081092

11091093
void QgsRasterLayerProperties::on_pbnDefaultValues_clicked()

src/app/qgsrasterlayerproperties.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
6565
void on_pbnAddValuesFromDisplay_clicked();
6666
/** \brief slot executed when user presses "Add Values Manually" button on the transparency page */
6767
void on_pbnAddValuesManually_clicked();
68-
/** Override the CRS specified when the layer was loaded */
69-
void on_pbnChangeSpatialRefSys_clicked();
68+
/** \brief slot executed when user changes the layer's CRS */
69+
void on_mCrsSelector_crsChanged( QgsCoordinateReferenceSystem crs );
7070
/** \brief slot executed when user wishes to reset noNoDataValue and transparencyTable to default value */
7171
void on_pbnDefaultValues_clicked();
7272
/** \brief slot executed when user wishes to export transparency values */

src/app/qgsvectorlayerproperties.cpp

+3-19
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
205205
}
206206
}
207207

208-
leSpatialRefSys->setText( layer->crs().authid() + " - " + layer->crs().description() );
209-
leSpatialRefSys->setCursorPosition( 0 );
208+
mCrsSelector->setCrs( layer->crs() );
210209

211210
//insert existing join info
212211
const QList< QgsVectorJoinInfo >& joins = layer->vectorJoins();
@@ -652,24 +651,9 @@ void QgsVectorLayerProperties::on_mLayerOrigNameLineEdit_textEdited( const QStri
652651
txtDisplayName->setText( layer->capitaliseLayerName( text ) );
653652
}
654653

655-
void QgsVectorLayerProperties::on_pbnChangeSpatialRefSys_clicked()
654+
void QgsVectorLayerProperties::on_mCrsSelector_crsChanged( QgsCoordinateReferenceSystem crs )
656655
{
657-
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this );
658-
mySelector->setMessage();
659-
mySelector->setSelectedCrsId( layer->crs().srsid() );
660-
if ( mySelector->exec() )
661-
{
662-
QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
663-
layer->setCrs( srs );
664-
}
665-
else
666-
{
667-
QApplication::restoreOverrideCursor();
668-
}
669-
delete mySelector;
670-
671-
leSpatialRefSys->setText( layer->crs().authid() + " - " + layer->crs().description() );
672-
leSpatialRefSys->setCursorPosition( 0 );
656+
layer->setCrs( crs );
673657
}
674658

675659
void QgsVectorLayerProperties::on_pbnLoadDefaultStyle_clicked()

src/app/qgsvectorlayerproperties.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
103103

104104
void on_pbnQueryBuilder_clicked();
105105
void on_pbnIndex_clicked();
106-
void on_pbnChangeSpatialRefSys_clicked();
106+
void on_mCrsSelector_crsChanged( QgsCoordinateReferenceSystem crs );
107107
void on_pbnLoadDefaultStyle_clicked();
108108
void on_pbnSaveDefaultStyle_clicked();
109109
void on_pbnLoadStyle_clicked();

src/gui/qgsnewmemorylayerdialog.cpp

+9-28
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "qgsapplication.h"
2020
#include "qgis.h"
2121
#include "qgscoordinatereferencesystem.h"
22-
#include "qgsgenericprojectionselector.h"
2322
#include "qgsproviderregistry.h"
2423
#include "qgsvectordataprovider.h"
2524

@@ -38,7 +37,7 @@ QgsVectorLayer *QgsNewMemoryLayerDialog::runAndCreateLayer( QWidget *parent )
3837
}
3938

4039
QGis::WkbType geometrytype = dialog.selectedType();
41-
QString crsId = dialog.selectedCrsId();
40+
QString crsId = dialog.crs().authid();
4241

4342
QString geomType;
4443
switch ( geometrytype )
@@ -81,11 +80,10 @@ QgsNewMemoryLayerDialog::QgsNewMemoryLayerDialog( QWidget *parent, Qt::WindowFla
8180

8281
mPointRadioButton->setChecked( true );
8382

84-
QgsCoordinateReferenceSystem srs;
85-
srs.createFromOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() );
86-
srs.validate();
87-
mCrsId = srs.authid();
88-
mSpatialRefSysEdit->setText( srs.authid() + " - " + srs.description() );
83+
QgsCoordinateReferenceSystem defaultCrs;
84+
defaultCrs.createFromOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() );
85+
defaultCrs.validate();
86+
mCrsSelector->setCrs( defaultCrs );
8987

9088
mNameLineEdit->setText( tr( "New scratch layer" ) );
9189
}
@@ -125,29 +123,12 @@ QGis::WkbType QgsNewMemoryLayerDialog::selectedType() const
125123
return QGis::WKBUnknown;
126124
}
127125

128-
QString QgsNewMemoryLayerDialog::layerName() const
129-
{
130-
return mNameLineEdit->text();
131-
}
132-
133-
QString QgsNewMemoryLayerDialog::selectedCrsId() const
126+
QgsCoordinateReferenceSystem QgsNewMemoryLayerDialog::crs() const
134127
{
135-
return mCrsId;
128+
return mCrsSelector->crs();
136129
}
137130

138-
void QgsNewMemoryLayerDialog::on_mChangeSrsButton_clicked()
131+
QString QgsNewMemoryLayerDialog::layerName() const
139132
{
140-
QgsGenericProjectionSelector *selector = new QgsGenericProjectionSelector( this );
141-
selector->setMessage();
142-
selector->setSelectedAuthId( mCrsId );
143-
if ( selector->exec() )
144-
{
145-
mCrsId = selector->selectedAuthId();
146-
mSpatialRefSysEdit->setText( mCrsId );
147-
}
148-
else
149-
{
150-
QApplication::restoreOverrideCursor();
151-
}
152-
delete selector;
133+
return mNameLineEdit->text();
153134
}

src/gui/qgsnewmemorylayerdialog.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgisgui.h"
2222
#include "qgis.h"
2323
#include "qgsvectorlayer.h"
24+
#include "qgscoordinatereferencesystem.h"
2425

2526
class GUI_EXPORT QgsNewMemoryLayerDialog: public QDialog, private Ui::QgsNewMemoryLayerDialogBase
2627
{
@@ -40,17 +41,14 @@ class GUI_EXPORT QgsNewMemoryLayerDialog: public QDialog, private Ui::QgsNewMemo
4041
/**Returns the selected geometry type*/
4142
QGis::WkbType selectedType() const;
4243

43-
/**Returns the selected crs id*/
44-
QString selectedCrsId() const;
44+
/**Returns the selected crs*/
45+
QgsCoordinateReferenceSystem crs() const;
4546

4647
/**Returns the layer name*/
4748
QString layerName() const;
4849

49-
protected slots:
50-
51-
void on_mChangeSrsButton_clicked();
52-
5350
private:
51+
5452
QString mCrsId;
5553
};
5654

src/gui/qgsnewvectorlayerdialog.cpp

+5-28
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "qgis.h"
2121
#include "qgslogger.h"
2222
#include "qgscoordinatereferencesystem.h"
23-
#include "qgsgenericprojectionselector.h"
2423
#include "qgsproviderregistry.h"
2524
#include "qgsvectordataprovider.h"
2625
#include "qgsvectorfilewriter.h"
@@ -85,13 +84,10 @@ QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WindowFla
8584

8685
mAttributeView->addTopLevelItem( new QTreeWidgetItem( QStringList() << "id" << "Integer" << "10" << "" ) );
8786

88-
QgsCoordinateReferenceSystem srs;
89-
90-
srs.createFromOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() );
91-
srs.validate();
92-
93-
mCrsId = srs.srsid();
94-
leSpatialRefSys->setText( srs.authid() + " - " + srs.description() );
87+
QgsCoordinateReferenceSystem defaultCrs;
88+
defaultCrs.createFromOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() );
89+
defaultCrs.validate();
90+
mCrsSelector->setCrs( defaultCrs );
9591

9692
connect( mNameEdit, SIGNAL( textChanged( QString ) ), this, SLOT( nameChanged( QString ) ) );
9793
connect( mAttributeView, SIGNAL( itemSelectionChanged() ), this, SLOT( selectionChanged() ) );
@@ -166,7 +162,7 @@ QGis::WkbType QgsNewVectorLayerDialog::selectedType() const
166162

167163
int QgsNewVectorLayerDialog::selectedCrsId() const
168164
{
169-
return mCrsId;
165+
return mCrsSelector->crs().srsid();
170166
}
171167

172168
void QgsNewVectorLayerDialog::on_mAddAttributeButton_clicked()
@@ -193,25 +189,6 @@ void QgsNewVectorLayerDialog::on_mRemoveAttributeButton_clicked()
193189
}
194190
}
195191

196-
void QgsNewVectorLayerDialog::on_pbnChangeSpatialRefSys_clicked()
197-
{
198-
QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector( this );
199-
mySelector->setMessage();
200-
mySelector->setSelectedCrsId( mCrsId );
201-
if ( mySelector->exec() )
202-
{
203-
QgsCoordinateReferenceSystem srs;
204-
srs.createFromOgcWmsCrs( mySelector->selectedAuthId() );
205-
mCrsId = srs.srsid();
206-
leSpatialRefSys->setText( srs.authid() + " - " + srs.description() );
207-
}
208-
else
209-
{
210-
QApplication::restoreOverrideCursor();
211-
}
212-
delete mySelector;
213-
}
214-
215192
void QgsNewVectorLayerDialog::attributes( QList< QPair<QString, QString> >& at ) const
216193
{
217194
QTreeWidgetItemIterator it( mAttributeView );

src/gui/qgsnewvectorlayerdialog.h

-2
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ class GUI_EXPORT QgsNewVectorLayerDialog: public QDialog, private Ui::QgsNewVect
5151
void on_mRemoveAttributeButton_clicked();
5252
void on_mFileFormatComboBox_currentIndexChanged( int index );
5353
void on_mTypeBox_currentIndexChanged( int index );
54-
void on_pbnChangeSpatialRefSys_clicked();
5554
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
5655
void nameChanged( QString );
5756
void selectionChanged();
5857

5958
private:
6059
QPushButton *mOkButton;
61-
int mCrsId;
6260
};
6361

6462
#endif //qgsnewvectorlayerdialog_H

0 commit comments

Comments
 (0)