Skip to content
Permalink
Browse files

FORCE users to make a choice in the transformation selection dialog

We don't want users to fallback to a "don't know what this means,
I'll click 'Cancel'" behaviour here. Doing so results in the
worst possible inaccurate transformations used. Literally, picking
ANYTHING in the dialog is a better selection then allowing
them to click cancel.

Sponsored by ICSM
  • Loading branch information
nyalldawson committed Mar 12, 2019
1 parent 785c033 commit 8b1d247fc18433b7f6b9aec19b7a658c54eec84c
@@ -197,7 +197,7 @@ QgsDatumTransformTableWidget::QgsDatumTransformTableWidget( QWidget *parent )

void QgsDatumTransformTableWidget::addDatumTransform()
{
QgsDatumTransformDialog dlg( QgsCoordinateReferenceSystem(), QgsCoordinateReferenceSystem(), true, false );
QgsDatumTransformDialog dlg( QgsCoordinateReferenceSystem(), QgsCoordinateReferenceSystem(), true, false, false );
if ( dlg.exec() )
{
QPair< QPair<QgsCoordinateReferenceSystem, int>, QPair<QgsCoordinateReferenceSystem, int > > dt = dlg.selectedDatumTransforms();
@@ -250,7 +250,7 @@ void QgsDatumTransformTableWidget::editDatumTransform()
if ( sourceCrs.isValid() && destinationCrs.isValid() &&
( sourceTransform != -1 || destinationTransform != -1 ) )
{
QgsDatumTransformDialog dlg( sourceCrs, destinationCrs, true, false, qMakePair( sourceTransform, destinationTransform ) );
QgsDatumTransformDialog dlg( sourceCrs, destinationCrs, true, false, false, qMakePair( sourceTransform, destinationTransform ) );
if ( dlg.exec() )
{
QPair< QPair<QgsCoordinateReferenceSystem, int>, QPair<QgsCoordinateReferenceSystem, int > > dt = dlg.selectedDatumTransforms();
@@ -38,7 +38,7 @@ bool QgsDatumTransformDialog::run( const QgsCoordinateReferenceSystem &sourceCrs
return true;
}

QgsDatumTransformDialog dlg( sourceCrs, destinationCrs, false, true, qMakePair( -1, -1 ), parent );
QgsDatumTransformDialog dlg( sourceCrs, destinationCrs, false, true, true, qMakePair( -1, -1 ), parent );
if ( dlg.shouldAskUserForSelection() )
{
if ( dlg.exec() )
@@ -62,7 +62,7 @@ bool QgsDatumTransformDialog::run( const QgsCoordinateReferenceSystem &sourceCrs
}

QgsDatumTransformDialog::QgsDatumTransformDialog( const QgsCoordinateReferenceSystem &sourceCrs,
const QgsCoordinateReferenceSystem &destinationCrs, const bool allowCrsChanges, const bool showMakeDefault,
const QgsCoordinateReferenceSystem &destinationCrs, const bool allowCrsChanges, const bool showMakeDefault, const bool forceChoice,
QPair<int, int> selectedDatumTransforms,
QWidget *parent,
Qt::WindowFlags f )
@@ -76,6 +76,13 @@ QgsDatumTransformDialog::QgsDatumTransformDialog( const QgsCoordinateReferenceSy
if ( !showMakeDefault )
mMakeDefaultCheckBox->setVisible( false );

if ( forceChoice )
{
mButtonBox->removeButton( mButtonBox->button( QDialogButtonBox::Cancel ) );
setWindowFlags( windowFlags() | Qt::CustomizeWindowHint );
setWindowFlags( windowFlags() & ~Qt::WindowCloseButtonHint );
}

mDatumTransformTableWidget->setColumnCount( 2 );
QStringList headers;
headers << tr( "Source Transform" ) << tr( "Destination Transform" ) ;
@@ -253,6 +260,14 @@ void QgsDatumTransformDialog::accept()
QDialog::accept();
}

void QgsDatumTransformDialog::reject()
{
if ( !mButtonBox->button( QDialogButtonBox::Cancel ) )
return; // users HAVE to make a choice, no click on the dialog "x" to avoid this!

QDialog::reject();
}

bool QgsDatumTransformDialog::shouldAskUserForSelection()
{
if ( mDatumTransforms.count() > 1 )
@@ -59,12 +59,14 @@ class GUI_EXPORT QgsDatumTransformDialog : public QDialog, private Ui::QgsDatumT
const QgsCoordinateReferenceSystem &destinationCrs = QgsCoordinateReferenceSystem(),
bool allowCrsChanges = false,
bool showMakeDefault = true,
bool forceChoice = true,
QPair<int, int> selectedDatumTransforms = qMakePair( -1, -1 ),
QWidget *parent = nullptr,
Qt::WindowFlags f = nullptr );
~QgsDatumTransformDialog() override;

void accept() override;
void reject() override;

/**
* Returns the source and destination transforms, each being a pair of QgsCoordinateReferenceSystems and datum transform code

0 comments on commit 8b1d247

Please sign in to comment.
You can’t perform that action at this time.