Skip to content
Permalink
Browse files

[needs-docs] Add a "Make Default" checkbox in the datum transform sel…

…ection dialog

If checked, the selected transformation will be set as a default
for all newly created projects (this can later be changed
in the usual place in Options - CRS)

Sponsored by ICSM
  • Loading branch information
nyalldawson committed Mar 22, 2019
1 parent cd01a5b commit 3505eb9ceb2a7cfbb5548e1c930324382f2a25e4
@@ -197,7 +197,7 @@ QgsDatumTransformTableWidget::QgsDatumTransformTableWidget( QWidget *parent )

void QgsDatumTransformTableWidget::addDatumTransform()
{
QgsDatumTransformDialog dlg( QgsCoordinateReferenceSystem(), QgsCoordinateReferenceSystem(), true );
QgsDatumTransformDialog dlg( QgsCoordinateReferenceSystem(), QgsCoordinateReferenceSystem(), true, 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, qMakePair( sourceTransform, destinationTransform ) );
QgsDatumTransformDialog dlg( sourceCrs, destinationCrs, true, 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, qMakePair( -1, -1 ), parent );
QgsDatumTransformDialog dlg( sourceCrs, destinationCrs, false, 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 QgsCoordinateReferenceSystem &destinationCrs, const bool allowCrsChanges, const bool showMakeDefault,
QPair<int, int> selectedDatumTransforms,
QWidget *parent,
Qt::WindowFlags f )
@@ -73,6 +73,9 @@ QgsDatumTransformDialog::QgsDatumTransformDialog( const QgsCoordinateReferenceSy

QgsGui::enableAutoGeometryRestore( this );

if ( !showMakeDefault )
mMakeDefaultCheckBox->setVisible( false );

mDatumTransformTableWidget->setColumnCount( 2 );
QStringList headers;
headers << tr( "Source Transform" ) << tr( "Destination Transform" ) ;
@@ -224,6 +227,32 @@ QgsDatumTransformDialog::~QgsDatumTransformDialog()
}
}

void QgsDatumTransformDialog::accept()
{
if ( mMakeDefaultCheckBox->isChecked() && !mDatumTransformTableWidget->selectedItems().isEmpty() )
{
QgsSettings settings;
settings.beginGroup( QStringLiteral( "/Projections" ) );

QPair< QPair<QgsCoordinateReferenceSystem, int>, QPair<QgsCoordinateReferenceSystem, int > > dt = selectedDatumTransforms();

QString srcAuthId = dt.first.first.authid();
QString destAuthId = dt.second.first.authid();
int sourceDatumTransform = dt.first.second;
QString sourceDatumProj;
if ( sourceDatumTransform >= 0 )
sourceDatumProj = QgsDatumTransform::datumTransformToProj( sourceDatumTransform );
int destinationDatumTransform = dt.second.second;
QString destinationDatumProj;
if ( destinationDatumTransform >= 0 )
destinationDatumProj = QgsDatumTransform::datumTransformToProj( destinationDatumTransform );

settings.setValue( srcAuthId + "//" + destAuthId + "_srcTransform", sourceDatumProj );
settings.setValue( srcAuthId + "//" + destAuthId + "_destTransform", destinationDatumProj );
}
QDialog::accept();
}

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

void accept() override;

/**
* Returns the source and destination transforms, each being a pair of QgsCoordinateReferenceSystems and datum transform code
* \since 3.0
@@ -134,6 +134,16 @@
</item>
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="mMakeDefaultCheckBox">
<property name="toolTip">
<string>If checked, the selected transformation will become the default choice in all new projects</string>
</property>
<property name="text">
<string>Make default</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@@ -191,8 +201,8 @@
</customwidgets>
<tabstops>
<tabstop>mDatumTransformTableWidget</tabstop>
<tabstop>mMakeDefaultCheckBox</tabstop>
<tabstop>mHideDeprecatedCheckBox</tabstop>
<tabstop>mButtonBox</tabstop>
</tabstops>
<resources/>
<connections>

0 comments on commit 3505eb9

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