mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-17 00:09:36 -04:00
Change projection selection widget to use a combo box
With options for layer CRS, project CRS and default CRS.
This commit is contained in:
parent
36f363b9b8
commit
f68b099bc1
@ -12,6 +12,16 @@ class QgsProjectionSelectionWidget : QWidget
|
||||
|
||||
public:
|
||||
|
||||
/** Predefined CRS options shown in widget
|
||||
*/
|
||||
enum CrsOption
|
||||
{
|
||||
LayerCrs, /*< optional layer CRS */
|
||||
ProjectCrs, /*< current project CRS (if OTF reprojection enabled) */
|
||||
CurrentCrs, /*< current user selected CRS */
|
||||
DefaultCrs /*< global default QGIS CRS */
|
||||
};
|
||||
|
||||
explicit QgsProjectionSelectionWidget( QWidget *parent /TransferThis/ = 0 );
|
||||
|
||||
/* Returns a pointer to the projection selector dialog used by the widget. Can be used
|
||||
@ -25,6 +35,12 @@ class QgsProjectionSelectionWidget : QWidget
|
||||
*/
|
||||
QgsCoordinateReferenceSystem crs() const;
|
||||
|
||||
/* Sets whether a predefined CRS option should be shown in the widget.
|
||||
* @param option CRS option to show/hide
|
||||
* @param visible whether the option should be shown
|
||||
*/
|
||||
void setOptionVisible( const CrsOption option, const bool visible );
|
||||
|
||||
signals:
|
||||
|
||||
/* Emitted when the selected CRS is changed
|
||||
@ -36,9 +52,16 @@ class QgsProjectionSelectionWidget : QWidget
|
||||
/* Sets the current CRS for the widget
|
||||
* @param crs new CRS
|
||||
*/
|
||||
void setCrs( QgsCoordinateReferenceSystem crs );
|
||||
void setCrs( const QgsCoordinateReferenceSystem& crs );
|
||||
|
||||
/* Sets the layer CRS for the widget. If set, this will be added as an option
|
||||
* to the preset CRSes shown in the widget.
|
||||
* @param crs layer CRS
|
||||
*/
|
||||
void setLayerCrs( const QgsCoordinateReferenceSystem& crs );
|
||||
|
||||
/* Opens the dialog for selecting a new CRS
|
||||
*/
|
||||
void selectCrs();
|
||||
|
||||
};
|
||||
|
@ -77,11 +77,9 @@ void QgsVectorLayerSaveAsDialog::setup()
|
||||
idx = 0;
|
||||
}
|
||||
|
||||
mCRSSelection->clear();
|
||||
mCRSSelection->addItems( QStringList() << tr( "Layer CRS" ) << tr( "Project CRS" ) << tr( "Selected CRS" ) );
|
||||
|
||||
QgsCoordinateReferenceSystem srs( mCRS, QgsCoordinateReferenceSystem::InternalCrsId );
|
||||
mCrsSelector->setCrs( srs );
|
||||
mCrsSelector->setLayerCrs( 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." ) );
|
||||
|
||||
@ -186,26 +184,6 @@ void QgsVectorLayerSaveAsDialog::accept()
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void QgsVectorLayerSaveAsDialog::on_mCRSSelection_currentIndexChanged( int idx )
|
||||
{
|
||||
mCrsSelector->setEnabled( idx == 2 );
|
||||
|
||||
QgsCoordinateReferenceSystem crs;
|
||||
if ( mCRSSelection->currentIndex() == 0 )
|
||||
{
|
||||
crs = mLayerCrs;
|
||||
}
|
||||
else if ( mCRSSelection->currentIndex() == 1 )
|
||||
{
|
||||
crs = mExtentGroupBox->currentCrs();
|
||||
}
|
||||
else // custom CRS
|
||||
{
|
||||
crs.createFromId( mCRS, QgsCoordinateReferenceSystem::InternalCrsId );
|
||||
}
|
||||
mExtentGroupBox->setOutputCrs( crs );
|
||||
}
|
||||
|
||||
void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx )
|
||||
{
|
||||
Q_UNUSED( idx );
|
||||
@ -307,7 +285,6 @@ void QgsVectorLayerSaveAsDialog::on_browseFilename_clicked()
|
||||
void QgsVectorLayerSaveAsDialog::on_mCrsSelector_crsChanged( QgsCoordinateReferenceSystem crs )
|
||||
{
|
||||
mCRS = crs.srsid();
|
||||
mCRSSelection->setCurrentIndex( 2 );
|
||||
mExtentGroupBox->setOutputCrs( crs );
|
||||
}
|
||||
|
||||
@ -328,18 +305,7 @@ QString QgsVectorLayerSaveAsDialog::format() const
|
||||
|
||||
long QgsVectorLayerSaveAsDialog::crs() const
|
||||
{
|
||||
if ( mCRSSelection->currentIndex() == 0 )
|
||||
{
|
||||
return -1; // Layer CRS
|
||||
}
|
||||
else if ( mCRSSelection->currentIndex() == 1 )
|
||||
{
|
||||
return -2; // Project CRS
|
||||
}
|
||||
else
|
||||
{
|
||||
return mCRS;
|
||||
}
|
||||
return mCRS;
|
||||
}
|
||||
|
||||
QStringList QgsVectorLayerSaveAsDialog::datasourceOptions() const
|
||||
|
@ -68,7 +68,6 @@ class QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVectorLayerSav
|
||||
private slots:
|
||||
void on_mFormatComboBox_currentIndexChanged( int idx );
|
||||
void on_leFilename_textChanged( const QString& text );
|
||||
void on_mCRSSelection_currentIndexChanged( int idx );
|
||||
void on_browseFilename_clicked();
|
||||
void on_mCrsSelector_crsChanged( QgsCoordinateReferenceSystem crs );
|
||||
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
|
||||
|
@ -5088,21 +5088,7 @@ void QgisApp::saveAsVectorFileGeneral( QgsVectorLayer* vlayer, bool symbologyOpt
|
||||
QStringList datasourceOptions = dialog->datasourceOptions();
|
||||
|
||||
QgsCoordinateTransform* ct = 0;
|
||||
|
||||
switch ( dialog->crs() )
|
||||
{
|
||||
case -2: // Project CRS
|
||||
destCRS = mMapCanvas->mapSettings().destinationCrs();
|
||||
|
||||
break;
|
||||
case -1: // Layer CRS
|
||||
destCRS = vlayer->crs();
|
||||
break;
|
||||
|
||||
default: // Selected CRS
|
||||
destCRS = QgsCoordinateReferenceSystem( dialog->crs(), QgsCoordinateReferenceSystem::InternalCrsId );
|
||||
break;
|
||||
}
|
||||
destCRS = QgsCoordinateReferenceSystem( dialog->crs(), QgsCoordinateReferenceSystem::InternalCrsId );
|
||||
|
||||
if ( destCRS.isValid() && destCRS != vlayer->crs() )
|
||||
{
|
||||
|
@ -383,6 +383,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
|
||||
QString myDefaultCrs = settings.value( "/Projections/projectDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
|
||||
mDefaultCrs.createFromOgcWmsCrs( myDefaultCrs );
|
||||
leProjectGlobalCrs->setCrs( mDefaultCrs );
|
||||
leProjectGlobalCrs->setOptionVisible( QgsProjectionSelectionWidget::DefaultCrs, false );
|
||||
|
||||
//default datum transformations
|
||||
settings.beginGroup( "/Projections" );
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include "qgsprojectionselectionwidget.h"
|
||||
#include "qgsapplication.h"
|
||||
#include "qgsgenericprojectionselector.h"
|
||||
#include "qgsproject.h"
|
||||
#include <QSettings>
|
||||
|
||||
QgsProjectionSelectionWidget::QgsProjectionSelectionWidget( QWidget *parent ) :
|
||||
QWidget( parent )
|
||||
@ -30,9 +32,29 @@ QgsProjectionSelectionWidget::QgsProjectionSelectionWidget( QWidget *parent ) :
|
||||
layout->setSpacing( 0 );
|
||||
setLayout( layout );
|
||||
|
||||
mCrsLineEdit = new QLineEdit( tr( "invalid projection" ), this );
|
||||
mCrsLineEdit->setReadOnly( true );
|
||||
layout->addWidget( mCrsLineEdit );
|
||||
mCrsComboBox = new QComboBox( this );
|
||||
mCrsComboBox->addItem( tr( "invalid projection" ), QgsProjectionSelectionWidget::CurrentCrs );
|
||||
|
||||
if ( QgsProject::instance()->readNumEntry( "SpatialRefSys", "/ProjectionsEnabled", 0 ) )
|
||||
{
|
||||
//only show project CRS if OTF reprojection is enabled - otherwise the
|
||||
//CRS stored in the project can be misleading
|
||||
QString projectCrsString = QgsProject::instance()->readEntry( "SpatialRefSys", "/ProjectCrs" );
|
||||
mProjectCrs.createFromOgcWmsCrs( projectCrsString );
|
||||
addProjectCrsOption();
|
||||
}
|
||||
|
||||
QSettings settings;
|
||||
QString defCrsString = settings.value( "/Projections/projectDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
|
||||
mDefaultCrs.createFromOgcWmsCrs( defCrsString );
|
||||
if ( mDefaultCrs.authid() != mProjectCrs.authid() )
|
||||
{
|
||||
//only show default CRS option if it's different to the project CRS, avoids
|
||||
//needlessly cluttering the widget
|
||||
addDefaultCrsOption();
|
||||
}
|
||||
|
||||
layout->addWidget( mCrsComboBox );
|
||||
|
||||
mButton = new QToolButton( this );
|
||||
mButton->setIcon( QgsApplication::getThemeIcon( "mActionSetProjection.svg" ) );
|
||||
@ -43,6 +65,56 @@ QgsProjectionSelectionWidget::QgsProjectionSelectionWidget( QWidget *parent ) :
|
||||
setFocusProxy( mButton );
|
||||
|
||||
connect( mButton, SIGNAL( clicked() ), this, SLOT( selectCrs() ) );
|
||||
connect( mCrsComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( comboIndexChanged( int ) ) );
|
||||
}
|
||||
|
||||
QgsCoordinateReferenceSystem QgsProjectionSelectionWidget::crs() const
|
||||
{
|
||||
switch (( CrsOption )mCrsComboBox->itemData( mCrsComboBox->currentIndex() ).toInt() )
|
||||
{
|
||||
case QgsProjectionSelectionWidget::LayerCrs:
|
||||
return mLayerCrs;
|
||||
case QgsProjectionSelectionWidget::ProjectCrs:
|
||||
return mProjectCrs ;
|
||||
case QgsProjectionSelectionWidget::DefaultCrs:
|
||||
return mDefaultCrs ;
|
||||
case QgsProjectionSelectionWidget::CurrentCrs:
|
||||
return mCrs;
|
||||
}
|
||||
return mCrs;
|
||||
}
|
||||
|
||||
void QgsProjectionSelectionWidget::setOptionVisible( const QgsProjectionSelectionWidget::CrsOption option, const bool visible )
|
||||
{
|
||||
int optionIndex = mCrsComboBox->findData( option );
|
||||
|
||||
if ( visible && optionIndex < 0 )
|
||||
{
|
||||
//add missing CRS option
|
||||
switch ( option )
|
||||
{
|
||||
case QgsProjectionSelectionWidget::LayerCrs:
|
||||
{
|
||||
setLayerCrs( mLayerCrs );
|
||||
return;
|
||||
}
|
||||
case QgsProjectionSelectionWidget::ProjectCrs:
|
||||
{
|
||||
addProjectCrsOption();
|
||||
return;
|
||||
}
|
||||
case QgsProjectionSelectionWidget::DefaultCrs:
|
||||
{
|
||||
addDefaultCrsOption();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( !visible && optionIndex >= 0 )
|
||||
{
|
||||
//remove CRS option
|
||||
mCrsComboBox->removeItem( optionIndex );
|
||||
}
|
||||
}
|
||||
|
||||
void QgsProjectionSelectionWidget::selectCrs()
|
||||
@ -55,6 +127,9 @@ void QgsProjectionSelectionWidget::selectCrs()
|
||||
|
||||
if ( mDialog->exec() )
|
||||
{
|
||||
mCrsComboBox->blockSignals( true );
|
||||
mCrsComboBox->setCurrentIndex( mCrsComboBox->findData( QgsProjectionSelectionWidget::CurrentCrs ) );
|
||||
mCrsComboBox->blockSignals( false );
|
||||
QgsCoordinateReferenceSystem crs;
|
||||
crs.createFromOgcWmsCrs( mDialog->selectedAuthId() );
|
||||
setCrs( crs );
|
||||
@ -66,16 +141,76 @@ void QgsProjectionSelectionWidget::selectCrs()
|
||||
}
|
||||
}
|
||||
|
||||
void QgsProjectionSelectionWidget::comboIndexChanged( int idx )
|
||||
{
|
||||
switch (( CrsOption )mCrsComboBox->itemData( idx ).toInt() )
|
||||
{
|
||||
case QgsProjectionSelectionWidget::LayerCrs:
|
||||
emit crsChanged( mLayerCrs );
|
||||
break;
|
||||
case QgsProjectionSelectionWidget::ProjectCrs:
|
||||
emit crsChanged( mProjectCrs );
|
||||
break;
|
||||
case QgsProjectionSelectionWidget::CurrentCrs:
|
||||
emit crsChanged( mCrs );
|
||||
break;
|
||||
case QgsProjectionSelectionWidget::DefaultCrs:
|
||||
emit crsChanged( mDefaultCrs );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void QgsProjectionSelectionWidget::setCrs( const QgsCoordinateReferenceSystem& crs )
|
||||
{
|
||||
if ( crs.isValid() )
|
||||
{
|
||||
mCrsLineEdit->setText( crs.authid() + " - " + crs.description() );
|
||||
mCrsComboBox->setItemText( mCrsComboBox->findData( QgsProjectionSelectionWidget::CurrentCrs ),
|
||||
tr( "Selected CRS (%1, %2)" ).arg( crs.authid() ).arg( crs.description() ) );
|
||||
mCrsComboBox->blockSignals( true );
|
||||
mCrsComboBox->setCurrentIndex( mCrsComboBox->findData( QgsProjectionSelectionWidget::CurrentCrs ) );
|
||||
mCrsComboBox->blockSignals( false );
|
||||
}
|
||||
else
|
||||
{
|
||||
mCrsLineEdit->setText( tr( "invalid projection" ) );
|
||||
mCrsComboBox->setItemText( mCrsComboBox->findData( QgsProjectionSelectionWidget::CurrentCrs ),
|
||||
tr( "invalid projection" ) );
|
||||
}
|
||||
mCrs = crs;
|
||||
}
|
||||
|
||||
void QgsProjectionSelectionWidget::setLayerCrs( const QgsCoordinateReferenceSystem &crs )
|
||||
{
|
||||
int layerItemIndex = mCrsComboBox->findData( QgsProjectionSelectionWidget::LayerCrs );
|
||||
if ( crs.isValid() )
|
||||
{
|
||||
if ( layerItemIndex > -1 )
|
||||
{
|
||||
mCrsComboBox->setItemText( layerItemIndex, tr( "Layer CRS (%1, %2)" ).arg( crs.authid() ).arg( crs.description() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
mCrsComboBox->addItem( tr( "Layer CRS (%1, %2)" ).arg( crs.authid() ).arg( crs.description() ), QgsProjectionSelectionWidget::LayerCrs );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( layerItemIndex > -1 )
|
||||
{
|
||||
mCrsComboBox->removeItem( layerItemIndex );
|
||||
}
|
||||
}
|
||||
mLayerCrs = crs;
|
||||
}
|
||||
|
||||
void QgsProjectionSelectionWidget::addProjectCrsOption()
|
||||
{
|
||||
if ( mProjectCrs.isValid() )
|
||||
{
|
||||
mCrsComboBox->addItem( tr( "Project CRS (%1 - %2)" ).arg( mProjectCrs.authid() ).arg( mProjectCrs.description() ), QgsProjectionSelectionWidget::ProjectCrs );
|
||||
}
|
||||
}
|
||||
|
||||
void QgsProjectionSelectionWidget::addDefaultCrsOption()
|
||||
{
|
||||
mCrsComboBox->addItem( tr( "Default CRS (%1 - %2)" ).arg( mDefaultCrs.authid() ).arg( mDefaultCrs.description() ), QgsProjectionSelectionWidget::DefaultCrs );
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <QWidget>
|
||||
#include <QLineEdit>
|
||||
#include <QToolButton>
|
||||
#include <QComboBox>
|
||||
|
||||
#include "qgscoordinatereferencesystem.h"
|
||||
|
||||
@ -35,6 +36,17 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
/** Predefined CRS options shown in widget
|
||||
*/
|
||||
enum CrsOption
|
||||
{
|
||||
LayerCrs, /*< optional layer CRS */
|
||||
ProjectCrs, /*< current project CRS (if OTF reprojection enabled) */
|
||||
CurrentCrs, /*< current user selected CRS */
|
||||
DefaultCrs /*< global default QGIS CRS */
|
||||
};
|
||||
|
||||
explicit QgsProjectionSelectionWidget( QWidget *parent = 0 );
|
||||
|
||||
/* Returns a pointer to the projection selector dialog used by the widget
|
||||
@ -45,7 +57,13 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
|
||||
/* Returns the currently selected CRS for the widget
|
||||
* @returns current CRS
|
||||
*/
|
||||
QgsCoordinateReferenceSystem crs() const { return mCrs; }
|
||||
QgsCoordinateReferenceSystem crs() const;
|
||||
|
||||
/* Sets whether a predefined CRS option should be shown in the widget.
|
||||
* @param option CRS option to show/hide
|
||||
* @param visible whether the option should be shown
|
||||
*/
|
||||
void setOptionVisible( const CrsOption option, const bool visible );
|
||||
|
||||
signals:
|
||||
|
||||
@ -60,15 +78,33 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
|
||||
*/
|
||||
void setCrs( const QgsCoordinateReferenceSystem& crs );
|
||||
|
||||
/* Sets the layer CRS for the widget. If set, this will be added as an option
|
||||
* to the preset CRSes shown in the widget.
|
||||
* @param crs layer CRS
|
||||
*/
|
||||
void setLayerCrs( const QgsCoordinateReferenceSystem& crs );
|
||||
|
||||
/* Opens the dialog for selecting a new CRS
|
||||
*/
|
||||
void selectCrs();
|
||||
|
||||
private:
|
||||
|
||||
QgsCoordinateReferenceSystem mCrs;
|
||||
QLineEdit* mCrsLineEdit;
|
||||
QgsCoordinateReferenceSystem mLayerCrs;
|
||||
QgsCoordinateReferenceSystem mProjectCrs;
|
||||
QgsCoordinateReferenceSystem mDefaultCrs;
|
||||
QComboBox* mCrsComboBox;
|
||||
QToolButton* mButton;
|
||||
QgsGenericProjectionSelector* mDialog;
|
||||
|
||||
void addProjectCrsOption();
|
||||
void addDefaultCrsOption();
|
||||
|
||||
private slots:
|
||||
|
||||
void comboIndexChanged( int idx );
|
||||
|
||||
};
|
||||
|
||||
#endif // QGSPROJECTIONSELECTIONWIDGET_H
|
||||
|
@ -23,6 +23,13 @@
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>CRS</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="leFilename">
|
||||
<property name="enabled">
|
||||
@ -50,26 +57,9 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>CRS</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="mFormatComboBox"/>
|
||||
</item>
|
||||
<item row="3" column="1" colspan="2">
|
||||
<widget class="QComboBox" name="mCRSSelection"/>
|
||||
</item>
|
||||
<item row="4" column="1" colspan="2">
|
||||
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector" native="true">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
@ -80,6 +70,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="2">
|
||||
<widget class="QgsProjectionSelectionWidget" name="mCrsSelector" native="true">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@ -345,7 +342,6 @@
|
||||
<tabstop>mFormatComboBox</tabstop>
|
||||
<tabstop>leFilename</tabstop>
|
||||
<tabstop>browseFilename</tabstop>
|
||||
<tabstop>mCRSSelection</tabstop>
|
||||
<tabstop>mCrsSelector</tabstop>
|
||||
<tabstop>scrollArea</tabstop>
|
||||
<tabstop>mEncodingComboBox</tabstop>
|
||||
|
Loading…
x
Reference in New Issue
Block a user