19#include "moc_qgsdatumtransformdialog.cpp"
37 if ( sourceCrs == destinationCrs )
46 QgsDatumTransformDialog dlg( sourceCrs, destinationCrs,
false,
true,
false, qMakePair( -1, -1 ), parent, Qt::WindowFlags(), QString(), mapCanvas );
47 if ( !windowTitle.isEmpty() )
48 dlg.setWindowTitle( windowTitle );
50 if ( dlg.shouldAskUserForSelection() )
70 dlg.applyDefaultTransform();
77 QPair<int, int> selectedDatumTransforms,
79 Qt::WindowFlags f,
const QString &selectedProj,
QgsMapCanvas *mapCanvas,
bool allowFallback )
80 : QDialog( parent, f )
90 if ( !showMakeDefault )
91 mCoordinateOperationsWidget->setShowMakeDefault(
false );
95 mButtonBox->removeButton( mButtonBox->button( QDialogButtonBox::Cancel ) );
96 setWindowFlags( windowFlags() | Qt::CustomizeWindowHint );
97 setWindowFlags( windowFlags() & ~Qt::WindowCloseButtonHint );
104 if ( !destinationCrs.
isValid() )
106 if ( !destinationCrs.
isValid() )
112 mSourceProjectionSelectionWidget->setCrs( sourceCrs );
113 mDestinationProjectionSelectionWidget->setCrs( destinationCrs );
114 if ( !allowCrsChanges )
116 mCrsStackedWidget->setCurrentIndex( 1 );
117 mSourceProjectionSelectionWidget->setEnabled(
false );
118 mDestinationProjectionSelectionWidget->setEnabled(
false );
123 mCoordinateOperationsWidget->setMapCanvas( mapCanvas );
128 mCoordinateOperationsWidget->setSourceCrs( sourceCrs );
129 mCoordinateOperationsWidget->setDestinationCrs( destinationCrs );
131 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, [ = ]
133 QgsHelp::openHelp( QStringLiteral(
"working_with_projections/working_with_projections.html" ) );
138 deets.
proj = selectedProj;
142 mCoordinateOperationsWidget->setSelectedOperation( deets );
146 if ( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid()
147 && mCoordinateOperationsWidget->selectedOperation().isAvailable )
152void QgsDatumTransformDialog::setOKButtonEnabled()
154 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid()
155 && mCoordinateOperationsWidget->selectedOperation().isAvailable );
160 if ( mCoordinateOperationsWidget->makeDefaultSelected() && mCoordinateOperationsWidget->hasSelection() )
163 settings.
beginGroup( QStringLiteral(
"/Projections" ) );
170 QString sourceDatumProj;
172 if ( sourceDatumTransform >= 0 )
175 QString destinationDatumProj;
176 if ( destinationDatumTransform >= 0 )
179 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_srcTransform" ), sourceDatumProj );
180 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_destTransform" ), destinationDatumProj );
181 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_coordinateOp" ), dt.
proj );
182 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_allowFallback" ), dt.
allowFallback );
189 if ( !mButtonBox->button( QDialogButtonBox::Cancel ) )
195bool QgsDatumTransformDialog::shouldAskUserForSelection()
const
197 if ( mCoordinateOperationsWidget->availableOperations().count() > 1 )
207 TransformInfo preferred;
208 preferred.
sourceCrs = mCoordinateOperationsWidget->sourceCrs();
209 preferred.destinationCrs = mCoordinateOperationsWidget->destinationCrs();
213 preferred.proj = defaultOp.
proj;
217void QgsDatumTransformDialog::applyDefaultTransform()
219 if ( mCoordinateOperationsWidget->availableOperations().count() > 0 )
222 const TransformInfo dt = defaultDatumTransform();
237 sdt.
sourceCrs = mCoordinateOperationsWidget->sourceCrs();
238 sdt.
destinationCrs = mCoordinateOperationsWidget->destinationCrs();
246bool QgsDatumTransformDialog::gridShiftTransformation(
const QString &itemText )
const
248 return !itemText.isEmpty() && !itemText.contains( QLatin1String(
"towgs84" ), Qt::CaseInsensitive );
251void QgsDatumTransformDialog::operationChanged()
253 setOKButtonEnabled();
258 mCoordinateOperationsWidget->setSourceCrs( sourceCrs );
259 setOKButtonEnabled();
264 mCoordinateOperationsWidget->setDestinationCrs( destinationCrs );
265 setOKButtonEnabled();
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Contains information about the context in which a coordinate transform is executed.
Q_DECL_DEPRECATED bool addSourceDestinationDatumTransform(const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs, int sourceTransformId, int destinationTransformId)
Adds a new sourceTransform and destinationTransform to use when projecting coordinates from the speci...
bool addCoordinateOperation(const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs, const QString &coordinateOperationProjString, bool allowFallback=true)
Adds a new coordinateOperationProjString to use when projecting coordinates from the specified source...
void removeCoordinateOperation(const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs)
Removes the coordinate operation for the specified sourceCrs and destinationCrs.
bool hasTransform(const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination) const
Returns true if the context has a valid coordinate operation to use when transforming from the specif...
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Map canvas is a class for displaying all GIS data types on a canvas.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsCoordinateTransformContext transformContext
QgsCoordinateReferenceSystem crs
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the project's coordinate transform context, which stores various information regarding which dat...
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Temporarily removes all cursor overrides for the QApplication for the lifetime of the object.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH