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();
75QgsDatumTransformDialog::QgsDatumTransformDialog(
const QgsCoordinateReferenceSystem &sCrs,
const QgsCoordinateReferenceSystem &dCrs,
const bool allowCrsChanges,
const bool showMakeDefault,
const bool forceChoice, QPair<int, int> selectedDatumTransforms, QWidget *parent, Qt::WindowFlags f,
const QString &selectedProj,
QgsMapCanvas *mapCanvas,
bool allowFallback )
76 : QDialog( parent, f )
86 if ( !showMakeDefault )
87 mCoordinateOperationsWidget->setShowMakeDefault(
false );
91 mButtonBox->removeButton( mButtonBox->button( QDialogButtonBox::Cancel ) );
92 setWindowFlags( windowFlags() | Qt::CustomizeWindowHint );
93 setWindowFlags( windowFlags() & ~Qt::WindowCloseButtonHint );
100 if ( !destinationCrs.
isValid() )
102 if ( !destinationCrs.
isValid() )
108 mSourceProjectionSelectionWidget->setCrs( sourceCrs );
109 mDestinationProjectionSelectionWidget->setCrs( destinationCrs );
110 if ( !allowCrsChanges )
112 mCrsStackedWidget->setCurrentIndex( 1 );
113 mSourceProjectionSelectionWidget->setEnabled(
false );
114 mDestinationProjectionSelectionWidget->setEnabled(
false );
119 mCoordinateOperationsWidget->setMapCanvas( mapCanvas );
124 mCoordinateOperationsWidget->setSourceCrs( sourceCrs );
125 mCoordinateOperationsWidget->setDestinationCrs( destinationCrs );
127 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, [=] {
128 QgsHelp::openHelp( QStringLiteral(
"working_with_projections/working_with_projections.html" ) );
133 deets.
proj = selectedProj;
137 mCoordinateOperationsWidget->setSelectedOperation( deets );
140 if ( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid()
141 && mCoordinateOperationsWidget->selectedOperation().isAvailable )
146void QgsDatumTransformDialog::setOKButtonEnabled()
148 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( mCoordinateOperationsWidget->sourceCrs().isValid() && mCoordinateOperationsWidget->destinationCrs().isValid() && mCoordinateOperationsWidget->selectedOperation().isAvailable );
153 if ( mCoordinateOperationsWidget->makeDefaultSelected() && mCoordinateOperationsWidget->hasSelection() )
156 settings.
beginGroup( QStringLiteral(
"/Projections" ) );
163 QString sourceDatumProj;
165 if ( sourceDatumTransform >= 0 )
168 QString destinationDatumProj;
169 if ( destinationDatumTransform >= 0 )
172 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_srcTransform" ), sourceDatumProj );
173 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_destTransform" ), destinationDatumProj );
174 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_coordinateOp" ), dt.
proj );
175 settings.
setValue( srcAuthId + QStringLiteral(
"//" ) + destAuthId + QStringLiteral(
"_allowFallback" ), dt.
allowFallback );
182 if ( !mButtonBox->button( QDialogButtonBox::Cancel ) )
188bool QgsDatumTransformDialog::shouldAskUserForSelection()
const
190 if ( mCoordinateOperationsWidget->availableOperations().count() > 1 )
200 TransformInfo preferred;
201 preferred.
sourceCrs = mCoordinateOperationsWidget->sourceCrs();
202 preferred.destinationCrs = mCoordinateOperationsWidget->destinationCrs();
206 preferred.proj = defaultOp.
proj;
210void QgsDatumTransformDialog::applyDefaultTransform()
212 if ( mCoordinateOperationsWidget->availableOperations().count() > 0 )
215 const TransformInfo dt = defaultDatumTransform();
230 sdt.
sourceCrs = mCoordinateOperationsWidget->sourceCrs();
231 sdt.
destinationCrs = mCoordinateOperationsWidget->destinationCrs();
239bool QgsDatumTransformDialog::gridShiftTransformation(
const QString &itemText )
const
241 return !itemText.isEmpty() && !itemText.contains( QLatin1String(
"towgs84" ), Qt::CaseInsensitive );
244void QgsDatumTransformDialog::operationChanged()
246 setOKButtonEnabled();
251 mCoordinateOperationsWidget->setSourceCrs( sourceCrs );
252 setOKButtonEnabled();
257 mCoordinateOperationsWidget->setDestinationCrs( destinationCrs );
258 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