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();
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString authid() const
Returns the authority identifier for the CRS.
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