29 #include <QPushButton>
31 #if PROJ_VERSION_MAJOR>=6
38 if ( sourceCrs == destinationCrs )
47 QgsDatumTransformDialog dlg( sourceCrs, destinationCrs,
false,
true,
false, qMakePair( -1, -1 ), parent,
nullptr, QString(), mapCanvas );
48 if ( !windowTitle.isEmpty() )
49 dlg.setWindowTitle( windowTitle );
51 if ( dlg.shouldAskUserForSelection() )
71 dlg.applyDefaultTransform();
78 QPair<int, int> selectedDatumTransforms,
80 Qt::WindowFlags f,
const QString &selectedProj,
QgsMapCanvas *mapCanvas,
bool allowFallback )
81 : QDialog( parent, f )
91 if ( !showMakeDefault )
92 mCoordinateOperationsWidget->setShowMakeDefault(
false );
96 mButtonBox->removeButton( mButtonBox->button( QDialogButtonBox::Cancel ) );
97 setWindowFlags( windowFlags() | Qt::CustomizeWindowHint );
98 setWindowFlags( windowFlags() & ~Qt::WindowCloseButtonHint );
101 #if PROJ_VERSION_MAJOR>=6
106 if ( !destinationCrs.
isValid() )
108 if ( !destinationCrs.
isValid() )
115 mSourceProjectionSelectionWidget->setCrs( sourceCrs );
116 mDestinationProjectionSelectionWidget->setCrs( destinationCrs );
117 if ( !allowCrsChanges )
119 mCrsStackedWidget->setCurrentIndex( 1 );
120 mSourceProjectionSelectionWidget->setEnabled(
false );
121 mDestinationProjectionSelectionWidget->setEnabled(
false );
126 mCoordinateOperationsWidget->setMapCanvas( mapCanvas );
131 mCoordinateOperationsWidget->setSourceCrs( sourceCrs );
132 mCoordinateOperationsWidget->setDestinationCrs( destinationCrs );
134 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, [ = ]
136 QgsHelp::openHelp( QStringLiteral(
"working_with_projections/working_with_projections.html" ) );
141 deets.
proj = selectedProj;
145 mCoordinateOperationsWidget->setSelectedOperation( deets );
150 #if PROJ_VERSION_MAJOR>=6
151 if ( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid()
152 && mCoordinateOperationsWidget->selectedOperation().isAvailable )
155 if ( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid() && mCoordinateOperationsWidget->hasSelection() )
161 void QgsDatumTransformDialog::setOKButtonEnabled()
163 #if PROJ_VERSION_MAJOR>=6
164 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid()
165 && mCoordinateOperationsWidget->selectedOperation().isAvailable );
167 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid() && mCoordinateOperationsWidget->hasSelection() );
173 if ( mCoordinateOperationsWidget->makeDefaultSelected() && mCoordinateOperationsWidget->hasSelection() )
176 settings.
beginGroup( QStringLiteral(
"/Projections" ) );
183 QString sourceDatumProj;
185 if ( sourceDatumTransform >= 0 )
188 QString destinationDatumProj;
189 if ( destinationDatumTransform >= 0 )
192 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_srcTransform" ), sourceDatumProj );
193 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_destTransform" ), destinationDatumProj );
194 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_coordinateOp" ), dt.
proj );
195 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_allowFallback" ), dt.
allowFallback );
202 if ( !mButtonBox->button( QDialogButtonBox::Cancel ) )
208 bool QgsDatumTransformDialog::shouldAskUserForSelection()
const
210 if ( mCoordinateOperationsWidget->availableOperations().count() > 1 )
220 TransformInfo preferred;
221 preferred.
sourceCrs = mCoordinateOperationsWidget->sourceCrs();
222 preferred.destinationCrs = mCoordinateOperationsWidget->destinationCrs();
226 preferred.proj = defaultOp.
proj;
230 void QgsDatumTransformDialog::applyDefaultTransform()
232 if ( mCoordinateOperationsWidget->availableOperations().count() > 0 )
235 const TransformInfo dt = defaultDatumTransform();
240 #if PROJ_VERSION_MAJOR>=6
254 sdt.
sourceCrs = mCoordinateOperationsWidget->sourceCrs();
255 sdt.
destinationCrs = mCoordinateOperationsWidget->destinationCrs();
263 bool QgsDatumTransformDialog::gridShiftTransformation(
const QString &itemText )
const
265 return !itemText.isEmpty() && !itemText.contains( QLatin1String(
"towgs84" ), Qt::CaseInsensitive );
268 void QgsDatumTransformDialog::operationChanged()
270 setOKButtonEnabled();
275 mCoordinateOperationsWidget->setSourceCrs( sourceCrs );
276 setOKButtonEnabled();
281 mCoordinateOperationsWidget->setDestinationCrs( destinationCrs );
282 setOKButtonEnabled();