Skip to content

Commit

Permalink
Fix #17510 - Better scoping of QgsProjectionSelectionDialog inside Qg…
Browse files Browse the repository at this point in the history
…sProjectionSelectionWidget
  • Loading branch information
NathanW2 committed Nov 27, 2017
1 parent 0717835 commit b2c396f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 25 deletions.
16 changes: 8 additions & 8 deletions python/gui/qgsprojectionselectionwidget.sip
Expand Up @@ -35,14 +35,6 @@ class QgsProjectionSelectionWidget : QWidget


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


QgsProjectionSelectionDialog *dialog();
%Docstring
Returns a pointer to the projection selector dialog used by the widget.
Can be used to modify how the projection selector dialog behaves.
:return: projection selector dialog
:rtype: QgsProjectionSelectionDialog
%End

QgsCoordinateReferenceSystem crs() const; QgsCoordinateReferenceSystem crs() const;
%Docstring %Docstring
Returns the currently selected CRS for the widget Returns the currently selected CRS for the widget
Expand Down Expand Up @@ -71,6 +63,14 @@ class QgsProjectionSelectionWidget : QWidget
Sets the text to show for the not set option. Note that this option is not shown Sets the text to show for the not set option. Note that this option is not shown
by default and must be set visible by calling setOptionVisible(). by default and must be set visible by calling setOptionVisible().
.. versionadded:: 3.0 .. versionadded:: 3.0
%End

void setMessage( const QString &text );
%Docstring
Sets a ``message`` to show in the dialog. If an empty string is
passed, the message will be a generic
'define the CRS for this layer'.
.. versionadded:: 3.0
%End %End


signals: signals:
Expand Down
4 changes: 2 additions & 2 deletions src/app/dwg/qgsdwgimportdialog.cpp
Expand Up @@ -90,8 +90,8 @@ QgsDwgImportDialog::QgsDwgImportDialog( QWidget *parent, Qt::WindowFlags f )
QgsCoordinateReferenceSystem crs( crsid, QgsCoordinateReferenceSystem::InternalCrsId ); QgsCoordinateReferenceSystem crs( crsid, QgsCoordinateReferenceSystem::InternalCrsId );
mCrsSelector->setCrs( crs ); mCrsSelector->setCrs( crs );
mCrsSelector->setLayerCrs( crs ); mCrsSelector->setLayerCrs( crs );
mCrsSelector->dialog()->setMessage( tr( "Select the coordinate reference system for the dxf file. " mCrsSelector->setMessage( tr( "Select the coordinate reference system for the dxf file. "
"The data points will be transformed from the layer coordinate reference system." ) ); "The data points will be transformed from the layer coordinate reference system." ) );


pbLoadDatabase_clicked(); pbLoadDatabase_clicked();
updateUI(); updateUI();
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsdxfexportdialog.cpp
Expand Up @@ -474,8 +474,8 @@ QgsDxfExportDialog::QgsDxfExportDialog( QWidget *parent, Qt::WindowFlags f )
mCRS = QgsCoordinateReferenceSystem::fromSrsId( crsid ); mCRS = QgsCoordinateReferenceSystem::fromSrsId( crsid );
mCrsSelector->setCrs( mCRS ); mCrsSelector->setCrs( mCRS );
mCrsSelector->setLayerCrs( mCRS ); mCrsSelector->setLayerCrs( mCRS );
mCrsSelector->dialog()->setMessage( tr( "Select the coordinate reference system for the dxf file. " mCrsSelector->setMessage( tr( "Select the coordinate reference system for the dxf file. "
"The data points will be transformed from the layer coordinate reference system." ) ); "The data points will be transformed from the layer coordinate reference system." ) );


mEncoding->addItems( QgsDxfExport::encodings() ); mEncoding->addItems( QgsDxfExport::encodings() );
mEncoding->setCurrentIndex( mEncoding->findText( QgsProject::instance()->readEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfEncoding" ), s.value( QStringLiteral( "qgis/lastDxfEncoding" ), "CP1252" ).toString() ) ) ); mEncoding->setCurrentIndex( mEncoding->findText( QgsProject::instance()->readEntry( QStringLiteral( "dxf" ), QStringLiteral( "/lastDxfEncoding" ), s.value( QStringLiteral( "qgis/lastDxfEncoding" ), "CP1252" ).toString() ) ) );
Expand Down
4 changes: 2 additions & 2 deletions src/gui/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -120,8 +120,8 @@ void QgsVectorLayerSaveAsDialog::setup()
QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromSrsId( mCRS ); QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromSrsId( mCRS );
mCrsSelector->setCrs( srs ); mCrsSelector->setCrs( srs );
mCrsSelector->setLayerCrs( srs ); mCrsSelector->setLayerCrs( srs );
mCrsSelector->dialog()->setMessage( tr( "Select the coordinate reference system for the vector file. " mCrsSelector->setMessage( tr( "Select the coordinate reference system for the vector file. "
"The data points will be transformed from the layer coordinate reference system." ) ); "The data points will be transformed from the layer coordinate reference system." ) );


mEncodingComboBox->setCurrentIndex( idx ); mEncodingComboBox->setCurrentIndex( idx );
mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() ); mFormatComboBox_currentIndexChanged( mFormatComboBox->currentIndex() );
Expand Down
14 changes: 10 additions & 4 deletions src/gui/qgsprojectionselectionwidget.cpp
Expand Up @@ -24,7 +24,6 @@
QgsProjectionSelectionWidget::QgsProjectionSelectionWidget( QWidget *parent ) QgsProjectionSelectionWidget::QgsProjectionSelectionWidget( QWidget *parent )
: QWidget( parent ) : QWidget( parent )
{ {
mDialog = new QgsProjectionSelectionDialog( this );




QHBoxLayout *layout = new QHBoxLayout(); QHBoxLayout *layout = new QHBoxLayout();
Expand Down Expand Up @@ -157,6 +156,11 @@ void QgsProjectionSelectionWidget::setNotSetText( const QString &text )
} }
} }


void QgsProjectionSelectionWidget::setMessage( const QString &text )
{
mMessage = text;
}

bool QgsProjectionSelectionWidget::optionVisible( QgsProjectionSelectionWidget::CrsOption option ) const bool QgsProjectionSelectionWidget::optionVisible( QgsProjectionSelectionWidget::CrsOption option ) const
{ {
int optionIndex = mCrsComboBox->findData( option ); int optionIndex = mCrsComboBox->findData( option );
Expand All @@ -166,17 +170,19 @@ bool QgsProjectionSelectionWidget::optionVisible( QgsProjectionSelectionWidget::
void QgsProjectionSelectionWidget::selectCrs() void QgsProjectionSelectionWidget::selectCrs()
{ {
//find out crs id of current proj4 string //find out crs id of current proj4 string
QgsProjectionSelectionDialog dlg( this );
dlg.setMessage( mMessage );
if ( mCrs.isValid() ) if ( mCrs.isValid() )
{ {
mDialog->setCrs( mCrs ); dlg.setCrs( mCrs );
} }


if ( mDialog->exec() ) if ( dlg.exec() )
{ {
mCrsComboBox->blockSignals( true ); mCrsComboBox->blockSignals( true );
mCrsComboBox->setCurrentIndex( mCrsComboBox->findData( QgsProjectionSelectionWidget::CurrentCrs ) ); mCrsComboBox->setCurrentIndex( mCrsComboBox->findData( QgsProjectionSelectionWidget::CurrentCrs ) );
mCrsComboBox->blockSignals( false ); mCrsComboBox->blockSignals( false );
QgsCoordinateReferenceSystem crs = mDialog->crs(); QgsCoordinateReferenceSystem crs = dlg.crs();
setCrs( crs ); setCrs( crs );
emit crsChanged( crs ); emit crsChanged( crs );
} }
Expand Down
16 changes: 9 additions & 7 deletions src/gui/qgsprojectionselectionwidget.h
Expand Up @@ -54,13 +54,6 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget


explicit QgsProjectionSelectionWidget( QWidget *parent SIP_TRANSFERTHIS = 0 ); explicit QgsProjectionSelectionWidget( QWidget *parent SIP_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
*/
QgsProjectionSelectionDialog *dialog() { return mDialog; }

/** /**
* Returns the currently selected CRS for the widget * Returns the currently selected CRS for the widget
* \returns current CRS * \returns current CRS
Expand Down Expand Up @@ -89,6 +82,14 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
*/ */
void setNotSetText( const QString &text ); void setNotSetText( const QString &text );


/**
* Sets a \a message to show in the dialog. If an empty string is
* passed, the message will be a generic
* 'define the CRS for this layer'.
* \since QGIS 3.0
*/
void setMessage( const QString &text );

signals: signals:


/** /**
Expand Down Expand Up @@ -132,6 +133,7 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
QToolButton *mButton = nullptr; QToolButton *mButton = nullptr;
QgsProjectionSelectionDialog *mDialog = nullptr; QgsProjectionSelectionDialog *mDialog = nullptr;
QString mNotSetText; QString mNotSetText;
QString mMessage;


void addNotSetOption(); void addNotSetOption();
void addProjectCrsOption(); void addProjectCrsOption();
Expand Down

0 comments on commit b2c396f

Please sign in to comment.