Skip to content

Commit

Permalink
Port a bunch of CRS selectors across to QgsProjectionSelectionWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 6, 2015
1 parent 7933847 commit 1a46c40
Show file tree
Hide file tree
Showing 20 changed files with 400 additions and 433 deletions.
7 changes: 2 additions & 5 deletions python/gui/qgsnewmemorylayerdialog.sip
Expand Up @@ -18,13 +18,10 @@ class QgsNewMemoryLayerDialog : QDialog
/**Returns the selected geometry type*/
QGis::WkbType selectedType() const;

/**Returns the selected crs id*/
QString selectedCrsId() const;
/**Returns the selected crs*/
QgsCoordinateReferenceSystem crs() const;

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

protected slots:

void on_mChangeSrsButton_clicked();
};
1 change: 0 additions & 1 deletion python/gui/qgsnewvectorlayerdialog.sip
Expand Up @@ -27,7 +27,6 @@ class QgsNewVectorLayerDialog : QDialog
void on_mAddAttributeButton_clicked();
void on_mRemoveAttributeButton_clicked();
void on_mTypeBox_currentIndexChanged( int index );
void on_pbnChangeSpatialRefSys_clicked();
void on_buttonBox_helpRequested();
void nameChanged( QString );
void selectionChanged();
Expand Down
11 changes: 11 additions & 0 deletions python/gui/qgsprojectionselectionwidget.sip
Expand Up @@ -14,6 +14,17 @@ class QgsProjectionSelectionWidget : QWidget

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

/* Returns a pointer to the projection selector dialog used by the widget. Can be used
* to modify how the projection selector dialog behaves.
* @returns projection selector dialog
*/
QgsGenericProjectionSelector* dialog();

/* Returns a pointer to the line edit used by the widget
* @returns CRS line edit
*/
QLineEdit* lineEdit();

/* Returns the currently selected CRS for the widget
* @returns current CRS
*/
Expand Down
28 changes: 8 additions & 20 deletions src/app/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -81,7 +81,9 @@ void QgsVectorLayerSaveAsDialog::setup()
mCRSSelection->addItems( QStringList() << tr( "Layer CRS" ) << tr( "Project CRS" ) << tr( "Selected CRS" ) );

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

mEncodingComboBox->setCurrentIndex( idx );
on_mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() );
Expand Down Expand Up @@ -186,7 +188,7 @@ void QgsVectorLayerSaveAsDialog::accept()

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

QgsCoordinateReferenceSystem crs;
if ( mCRSSelection->currentIndex() == 0 )
Expand Down Expand Up @@ -302,25 +304,11 @@ void QgsVectorLayerSaveAsDialog::on_browseFilename_clicked()
}
}

void QgsVectorLayerSaveAsDialog::on_browseCRS_clicked()
void QgsVectorLayerSaveAsDialog::on_mCrsSelector_crsChanged( QgsCoordinateReferenceSystem crs )
{
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector();
if ( mCRS >= 0 )
mySelector->setSelectedCrsId( mCRS );
mySelector->setMessage( tr( "Select the coordinate reference system for the vector file. "
"The data points will be transformed from the layer coordinate reference system." ) );

if ( mySelector->exec() )
{
QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
mCRS = srs.srsid();
leCRS->setText( srs.description() );
mCRSSelection->setCurrentIndex( 2 );

mExtentGroupBox->setOutputCrs( srs );
}

delete mySelector;
mCRS = crs.srsid();
mCRSSelection->setCurrentIndex( 2 );
mExtentGroupBox->setOutputCrs( crs );
}

QString QgsVectorLayerSaveAsDialog::filename() const
Expand Down
2 changes: 1 addition & 1 deletion src/app/ogr/qgsvectorlayersaveasdialog.h
Expand Up @@ -70,7 +70,7 @@ class QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVectorLayerSav
void on_leFilename_textChanged( const QString& text );
void on_mCRSSelection_currentIndexChanged( int idx );
void on_browseFilename_clicked();
void on_browseCRS_clicked();
void on_mCrsSelector_crsChanged( QgsCoordinateReferenceSystem crs );
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
void on_mSymbologyExportComboBox_currentIndexChanged( const QString& text );
void accept();
Expand Down
22 changes: 3 additions & 19 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -198,8 +198,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv

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

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

void QgsRasterLayerProperties::on_pbnChangeSpatialRefSys_clicked()
void QgsRasterLayerProperties::on_mCrsSelector_crsChanged( QgsCoordinateReferenceSystem crs )
{

QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this );
mySelector->setSelectedCrsId( mRasterLayer->crs().srsid() );
if ( mySelector->exec() )
{
QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
mRasterLayer->setCrs( srs );
}
else
{
QApplication::restoreOverrideCursor();
}
delete mySelector;

leSpatialRefSys->setText( mRasterLayer->crs().authid() + " - " + mRasterLayer->crs().description() );
leSpatialRefSys->setCursorPosition( 0 );
mRasterLayer->setCrs( crs );
}

void QgsRasterLayerProperties::on_pbnDefaultValues_clicked()
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsrasterlayerproperties.h
Expand Up @@ -65,8 +65,8 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
void on_pbnAddValuesFromDisplay_clicked();
/** \brief slot executed when user presses "Add Values Manually" button on the transparency page */
void on_pbnAddValuesManually_clicked();
/** Override the CRS specified when the layer was loaded */
void on_pbnChangeSpatialRefSys_clicked();
/** \brief slot executed when user changes the layer's CRS */
void on_mCrsSelector_crsChanged( QgsCoordinateReferenceSystem crs );
/** \brief slot executed when user wishes to reset noNoDataValue and transparencyTable to default value */
void on_pbnDefaultValues_clicked();
/** \brief slot executed when user wishes to export transparency values */
Expand Down
22 changes: 3 additions & 19 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -205,8 +205,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
}
}

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

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

void QgsVectorLayerProperties::on_pbnChangeSpatialRefSys_clicked()
void QgsVectorLayerProperties::on_mCrsSelector_crsChanged( QgsCoordinateReferenceSystem crs )
{
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this );
mySelector->setMessage();
mySelector->setSelectedCrsId( layer->crs().srsid() );
if ( mySelector->exec() )
{
QgsCoordinateReferenceSystem srs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
layer->setCrs( srs );
}
else
{
QApplication::restoreOverrideCursor();
}
delete mySelector;

leSpatialRefSys->setText( layer->crs().authid() + " - " + layer->crs().description() );
leSpatialRefSys->setCursorPosition( 0 );
layer->setCrs( crs );
}

void QgsVectorLayerProperties::on_pbnLoadDefaultStyle_clicked()
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsvectorlayerproperties.h
Expand Up @@ -103,7 +103,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private

void on_pbnQueryBuilder_clicked();
void on_pbnIndex_clicked();
void on_pbnChangeSpatialRefSys_clicked();
void on_mCrsSelector_crsChanged( QgsCoordinateReferenceSystem crs );
void on_pbnLoadDefaultStyle_clicked();
void on_pbnSaveDefaultStyle_clicked();
void on_pbnLoadStyle_clicked();
Expand Down
37 changes: 9 additions & 28 deletions src/gui/qgsnewmemorylayerdialog.cpp
Expand Up @@ -19,7 +19,6 @@
#include "qgsapplication.h"
#include "qgis.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsgenericprojectionselector.h"
#include "qgsproviderregistry.h"
#include "qgsvectordataprovider.h"

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

QGis::WkbType geometrytype = dialog.selectedType();
QString crsId = dialog.selectedCrsId();
QString crsId = dialog.crs().authid();

QString geomType;
switch ( geometrytype )
Expand Down Expand Up @@ -81,11 +80,10 @@ QgsNewMemoryLayerDialog::QgsNewMemoryLayerDialog( QWidget *parent, Qt::WindowFla

mPointRadioButton->setChecked( true );

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

mNameLineEdit->setText( tr( "New scratch layer" ) );
}
Expand Down Expand Up @@ -125,29 +123,12 @@ QGis::WkbType QgsNewMemoryLayerDialog::selectedType() const
return QGis::WKBUnknown;
}

QString QgsNewMemoryLayerDialog::layerName() const
{
return mNameLineEdit->text();
}

QString QgsNewMemoryLayerDialog::selectedCrsId() const
QgsCoordinateReferenceSystem QgsNewMemoryLayerDialog::crs() const
{
return mCrsId;
return mCrsSelector->crs();
}

void QgsNewMemoryLayerDialog::on_mChangeSrsButton_clicked()
QString QgsNewMemoryLayerDialog::layerName() const
{
QgsGenericProjectionSelector *selector = new QgsGenericProjectionSelector( this );
selector->setMessage();
selector->setSelectedAuthId( mCrsId );
if ( selector->exec() )
{
mCrsId = selector->selectedAuthId();
mSpatialRefSysEdit->setText( mCrsId );
}
else
{
QApplication::restoreOverrideCursor();
}
delete selector;
return mNameLineEdit->text();
}
10 changes: 4 additions & 6 deletions src/gui/qgsnewmemorylayerdialog.h
Expand Up @@ -21,6 +21,7 @@
#include "qgisgui.h"
#include "qgis.h"
#include "qgsvectorlayer.h"
#include "qgscoordinatereferencesystem.h"

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

/**Returns the selected crs id*/
QString selectedCrsId() const;
/**Returns the selected crs*/
QgsCoordinateReferenceSystem crs() const;

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

protected slots:

void on_mChangeSrsButton_clicked();

private:

QString mCrsId;
};

Expand Down
33 changes: 5 additions & 28 deletions src/gui/qgsnewvectorlayerdialog.cpp
Expand Up @@ -20,7 +20,6 @@
#include "qgis.h"
#include "qgslogger.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsgenericprojectionselector.h"
#include "qgsproviderregistry.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorfilewriter.h"
Expand Down Expand Up @@ -85,13 +84,10 @@ QgsNewVectorLayerDialog::QgsNewVectorLayerDialog( QWidget *parent, Qt::WindowFla

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

QgsCoordinateReferenceSystem srs;

srs.createFromOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() );
srs.validate();

mCrsId = srs.srsid();
leSpatialRefSys->setText( srs.authid() + " - " + srs.description() );
QgsCoordinateReferenceSystem defaultCrs;
defaultCrs.createFromOgcWmsCrs( settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() );
defaultCrs.validate();
mCrsSelector->setCrs( defaultCrs );

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

int QgsNewVectorLayerDialog::selectedCrsId() const
{
return mCrsId;
return mCrsSelector->crs().srsid();
}

void QgsNewVectorLayerDialog::on_mAddAttributeButton_clicked()
Expand All @@ -193,25 +189,6 @@ void QgsNewVectorLayerDialog::on_mRemoveAttributeButton_clicked()
}
}

void QgsNewVectorLayerDialog::on_pbnChangeSpatialRefSys_clicked()
{
QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector( this );
mySelector->setMessage();
mySelector->setSelectedCrsId( mCrsId );
if ( mySelector->exec() )
{
QgsCoordinateReferenceSystem srs;
srs.createFromOgcWmsCrs( mySelector->selectedAuthId() );
mCrsId = srs.srsid();
leSpatialRefSys->setText( srs.authid() + " - " + srs.description() );
}
else
{
QApplication::restoreOverrideCursor();
}
delete mySelector;
}

void QgsNewVectorLayerDialog::attributes( QList< QPair<QString, QString> >& at ) const
{
QTreeWidgetItemIterator it( mAttributeView );
Expand Down
2 changes: 0 additions & 2 deletions src/gui/qgsnewvectorlayerdialog.h
Expand Up @@ -51,14 +51,12 @@ class GUI_EXPORT QgsNewVectorLayerDialog: public QDialog, private Ui::QgsNewVect
void on_mRemoveAttributeButton_clicked();
void on_mFileFormatComboBox_currentIndexChanged( int index );
void on_mTypeBox_currentIndexChanged( int index );
void on_pbnChangeSpatialRefSys_clicked();
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
void nameChanged( QString );
void selectionChanged();

private:
QPushButton *mOkButton;
int mCrsId;
};

#endif //qgsnewvectorlayerdialog_H

0 comments on commit 1a46c40

Please sign in to comment.