Skip to content

Commit

Permalink
Don't show crs accuracy warnings when saving a vector/raster layer
Browse files Browse the repository at this point in the history
from an ensemble based crs to another crs with the same ensemble datum
  • Loading branch information
nyalldawson committed May 11, 2021
1 parent a2e369f commit b81ece4
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 3 deletions.
24 changes: 24 additions & 0 deletions python/gui/auto_generated/qgsprojectionselectionwidget.sip.in
Expand Up @@ -100,6 +100,30 @@ low accuracy.

.. seealso:: :py:func:`showAccuracyWarnings`

.. versionadded:: 3.20
%End

void setSourceEnsemble( const QString &ensemble );
%Docstring
Sets the original source ``ensemble`` datum name.

If set, CRS accuracy warnings will not be shown when the selected CRS in the widget has a matching
ensemble datum, regardless of the ensemble's accuracy.

.. seealso:: :py:func:`sourceEnsemble`

.. versionadded:: 3.20
%End

QString sourceEnsemble() const;
%Docstring
Returns the original source ensemble datum name.

If set, CRS accuracy warnings will not be shown when the selected CRS in the widget has a matching
ensemble datum, regardless of the ensemble's accuracy.

.. seealso:: :py:func:`setSourceEnsemble`

.. versionadded:: 3.20
%End

Expand Down
15 changes: 14 additions & 1 deletion src/gui/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -34,6 +34,7 @@
#include <QSpinBox>
#include <QRegularExpression>
#include "gdal.h"
#include "qgsdatums.h"

static const int COLUMN_IDX_NAME = 0;
static const int COLUMN_IDX_TYPE = 1;
Expand Down Expand Up @@ -201,7 +202,19 @@ void QgsVectorLayerSaveAsDialog::setup()
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( !filePath.isEmpty() );
} );

mCrsSelector->showAccuracyWarnings( true );
try
{
const QgsDatumEnsemble ensemble = mSelectedCrs.datumEnsemble();
if ( ensemble.isValid() )
{
mCrsSelector->setSourceEnsemble( ensemble.name() );
}
}
catch ( QgsNotSupportedException & )
{
}

mCrsSelector->setShowAccuracyWarnings( true );
}

QList<QPair<QLabel *, QWidget *> > QgsVectorLayerSaveAsDialog::createControls( const QMap<QString, QgsVectorFileWriter::Option *> &options )
Expand Down
16 changes: 15 additions & 1 deletion src/gui/qgsprojectionselectionwidget.cpp
Expand Up @@ -289,6 +289,20 @@ void QgsProjectionSelectionWidget::dropEvent( QDropEvent *event )
update();
}

QString QgsProjectionSelectionWidget::sourceEnsemble() const
{
return mSourceEnsemble;
}

void QgsProjectionSelectionWidget::setSourceEnsemble( const QString &ensemble )
{
if ( mSourceEnsemble == ensemble )
return;

mSourceEnsemble = ensemble;
updateWarning();
}

bool QgsProjectionSelectionWidget::showAccuracyWarnings() const
{
return mShowAccuracyWarnings;
Expand Down Expand Up @@ -353,7 +367,7 @@ void QgsProjectionSelectionWidget::updateWarning()
try
{
const QgsDatumEnsemble ensemble = crs().datumEnsemble();
if ( !ensemble.isValid() )
if ( !ensemble.isValid() || ensemble.name() == mSourceEnsemble )
{
mWarningLabelContainer->hide();
}
Expand Down
24 changes: 24 additions & 0 deletions src/gui/qgsprojectionselectionwidget.h
Expand Up @@ -119,6 +119,28 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
*/
void setShowAccuracyWarnings( bool show );

/**
* Sets the original source \a ensemble datum name.
*
* If set, CRS accuracy warnings will not be shown when the selected CRS in the widget has a matching
* ensemble datum, regardless of the ensemble's accuracy.
*
* \see sourceEnsemble()
* \since QGIS 3.20
*/
void setSourceEnsemble( const QString &ensemble );

/**
* Returns the original source ensemble datum name.
*
* If set, CRS accuracy warnings will not be shown when the selected CRS in the widget has a matching
* ensemble datum, regardless of the ensemble's accuracy.
*
* \see setSourceEnsemble()
* \since QGIS 3.20
*/
QString sourceEnsemble() const;

signals:

/**
Expand Down Expand Up @@ -171,6 +193,8 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
QString mMessage;

bool mShowAccuracyWarnings = false;
QString mSourceEnsemble;

QWidget *mWarningLabelContainer = nullptr;
QLabel *mWarningLabel = nullptr;

Expand Down
14 changes: 13 additions & 1 deletion src/gui/qgsrasterlayersaveasdialog.cpp
Expand Up @@ -32,6 +32,7 @@
#include "qgsmessagelog.h"
#include "qgsgui.h"
#include "qgsdoublevalidator.h"
#include "qgsdatums.h"

#include <QFileDialog>
#include <QMessageBox>
Expand Down Expand Up @@ -140,7 +141,18 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterLayer *rasterLa
// don't restore nodata, it needs user input
// pyramids are not necessarily built every time

mCrsSelector->showAccuracyWarnings( true );
try
{
const QgsDatumEnsemble ensemble = mLayerCrs.datumEnsemble();
if ( ensemble.isValid() )
{
mCrsSelector->setSourceEnsemble( ensemble.name() );
}
}
catch ( QgsNotSupportedException & )
{
}
mCrsSelector->setShowAccuracyWarnings( true );

mCrsSelector->setLayerCrs( mLayerCrs );
//default to layer CRS - see https://github.com/qgis/QGIS/issues/22211 for discussion
Expand Down

0 comments on commit b81ece4

Please sign in to comment.