Skip to content

Commit

Permalink
Standardise API for deciding whether the datum transform dialog shoul…
Browse files Browse the repository at this point in the history
…d be shown
  • Loading branch information
nyalldawson committed Mar 22, 2019
1 parent fc4d9b8 commit 0b6fdd9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7855,8 +7855,7 @@ QString QgisApp::saveAsVectorFileGeneral( QgsVectorLayer *vlayer, bool symbology
//ask user about datum transformation
QgsSettings settings;
QgsDatumTransformDialog dlg( vlayer->crs(), destCRS );
if ( dlg.availableTransformationCount() > 1 &&
settings.value( QStringLiteral( "Projections/showDatumTransformDialog" ), false ).toBool() )
if ( dlg.shouldAskUserForSelection() )
{
dlg.exec();
}
Expand Down Expand Up @@ -9912,6 +9911,7 @@ void QgisApp::projectCrsChanged()
}
else if ( transformsToAskFor.count() > 1 )
{
// TODO - this should actually loop through and ask for each in turn
bool ask = QgsSettings().value( QStringLiteral( "/Projections/showDatumTransformDialog" ), false ).toBool();
if ( ask )
{
Expand All @@ -9921,8 +9921,6 @@ void QgisApp::projectCrsChanged()
5 );
}
}


}

// toggle overview status
Expand Down Expand Up @@ -13736,14 +13734,9 @@ bool QgisApp::askUserForDatumTransform( const QgsCoordinateReferenceSystem &sour
{
//if several possibilities: present dialog
QgsDatumTransformDialog dlg( sourceCrs, destinationCrs );
if ( dlg.availableTransformationCount() > 1 )
if ( dlg.shouldAskUserForSelection() )
{
bool ask = QgsSettings().value( QStringLiteral( "/Projections/showDatumTransformDialog" ), false ).toBool();
if ( !ask )
{
ok = false;
}
else if ( dlg.exec() )
if ( dlg.exec() )
{
QPair< QPair<QgsCoordinateReferenceSystem, int>, QPair<QgsCoordinateReferenceSystem, int > > dt = dlg.selectedDatumTransforms();
QgsCoordinateTransformContext context = QgsProject::instance()->transformContext();
Expand Down
10 changes: 10 additions & 0 deletions src/gui/qgsdatumtransformdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ int QgsDatumTransformDialog::availableTransformationCount()
return mDatumTransforms.count();
}

bool QgsDatumTransformDialog::shouldAskUserForSelection()
{
if ( availableTransformationCount() > 1 )
{
return QgsSettings().value( QStringLiteral( "/Projections/showDatumTransformDialog" ), false ).toBool();
}
// TODO: show if transform grids are required, but missing
return false;
}

QPair<QPair<QgsCoordinateReferenceSystem, int>, QPair<QgsCoordinateReferenceSystem, int> > QgsDatumTransformDialog::selectedDatumTransforms()
{
int row = mDatumTransformTableWidget->currentRow();
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsdatumtransformdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class GUI_EXPORT QgsDatumTransformDialog : public QDialog, private Ui::QgsDatumT
*/
int availableTransformationCount();

/**
* Returns true if the dialog should be shown and the user prompted to make the transformation selection.
*
* \since QGIS 3.8
*/
bool shouldAskUserForSelection();

/**
* Returns the source and destination transforms, each being a pair of QgsCoordinateReferenceSystems and datum transform code
* \since 3.0
Expand Down

0 comments on commit 0b6fdd9

Please sign in to comment.