29 #include <QPushButton>
36 if ( sourceCrs == destinationCrs )
45 QgsDatumTransformDialog dlg( sourceCrs, destinationCrs,
false,
true,
false, qMakePair( -1, -1 ), parent, Qt::WindowFlags(), QString(), mapCanvas );
46 if ( !windowTitle.isEmpty() )
47 dlg.setWindowTitle( windowTitle );
49 if ( dlg.shouldAskUserForSelection() )
69 dlg.applyDefaultTransform();
76 QPair<int, int> selectedDatumTransforms,
78 Qt::WindowFlags f,
const QString &selectedProj,
QgsMapCanvas *mapCanvas,
bool allowFallback )
79 : QDialog( parent, f )
89 if ( !showMakeDefault )
90 mCoordinateOperationsWidget->setShowMakeDefault(
false );
94 mButtonBox->removeButton( mButtonBox->button( QDialogButtonBox::Cancel ) );
95 setWindowFlags( windowFlags() | Qt::CustomizeWindowHint );
96 setWindowFlags( windowFlags() & ~Qt::WindowCloseButtonHint );
103 if ( !destinationCrs.
isValid() )
105 if ( !destinationCrs.
isValid() )
111 mSourceProjectionSelectionWidget->setCrs( sourceCrs );
112 mDestinationProjectionSelectionWidget->setCrs( destinationCrs );
113 if ( !allowCrsChanges )
115 mCrsStackedWidget->setCurrentIndex( 1 );
116 mSourceProjectionSelectionWidget->setEnabled(
false );
117 mDestinationProjectionSelectionWidget->setEnabled(
false );
122 mCoordinateOperationsWidget->setMapCanvas( mapCanvas );
127 mCoordinateOperationsWidget->setSourceCrs( sourceCrs );
128 mCoordinateOperationsWidget->setDestinationCrs( destinationCrs );
130 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, [ = ]
132 QgsHelp::openHelp( QStringLiteral(
"working_with_projections/working_with_projections.html" ) );
137 deets.
proj = selectedProj;
141 mCoordinateOperationsWidget->setSelectedOperation( deets );
145 if ( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid()
146 && mCoordinateOperationsWidget->selectedOperation().isAvailable )
151 void QgsDatumTransformDialog::setOKButtonEnabled()
153 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid()
154 && mCoordinateOperationsWidget->selectedOperation().isAvailable );
159 if ( mCoordinateOperationsWidget->makeDefaultSelected() && mCoordinateOperationsWidget->hasSelection() )
162 settings.
beginGroup( QStringLiteral(
"/Projections" ) );
169 QString sourceDatumProj;
171 if ( sourceDatumTransform >= 0 )
174 QString destinationDatumProj;
175 if ( destinationDatumTransform >= 0 )
178 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_srcTransform" ), sourceDatumProj );
179 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_destTransform" ), destinationDatumProj );
180 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_coordinateOp" ), dt.
proj );
181 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_allowFallback" ), dt.
allowFallback );
188 if ( !mButtonBox->button( QDialogButtonBox::Cancel ) )
194 bool QgsDatumTransformDialog::shouldAskUserForSelection()
const
196 if ( mCoordinateOperationsWidget->availableOperations().count() > 1 )
206 TransformInfo preferred;
207 preferred.
sourceCrs = mCoordinateOperationsWidget->sourceCrs();
208 preferred.destinationCrs = mCoordinateOperationsWidget->destinationCrs();
212 preferred.proj = defaultOp.
proj;
216 void QgsDatumTransformDialog::applyDefaultTransform()
218 if ( mCoordinateOperationsWidget->availableOperations().count() > 0 )
221 const TransformInfo dt = defaultDatumTransform();
236 sdt.
sourceCrs = mCoordinateOperationsWidget->sourceCrs();
237 sdt.
destinationCrs = mCoordinateOperationsWidget->destinationCrs();
245 bool QgsDatumTransformDialog::gridShiftTransformation(
const QString &itemText )
const
247 return !itemText.isEmpty() && !itemText.contains( QLatin1String(
"towgs84" ), Qt::CaseInsensitive );
250 void QgsDatumTransformDialog::operationChanged()
252 setOKButtonEnabled();
257 mCoordinateOperationsWidget->setSourceCrs( sourceCrs );
258 setOKButtonEnabled();
263 mCoordinateOperationsWidget->setDestinationCrs( destinationCrs );
264 setOKButtonEnabled();