Skip to content

Commit 68aef9a

Browse files
3nidsnyalldawson
authored andcommitted
ask for datum transform update on layer or project crs change
in the case of project crs change, if several transforms are available, pop up a message rather than showing multiple dialogs
1 parent adf0722 commit 68aef9a

File tree

8 files changed

+48
-55
lines changed

8 files changed

+48
-55
lines changed

doc/api_break.dox

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,7 @@ QgsMapCanvas {#qgis_api_break_3_0_QgsMapCanvas}
16471647
- setCrsTransformEnabled(), hasCrsTransformEnabled(), hasCrsTransformEnabledChanged() were removed. CRS transformation is now always enabled.
16481648
- setMapUnits() was removed. The map units are dictated by the units for the destination CRS.
16491649
- The mapUnitsChanged() signal was removed. Listen for the destinationCrsChanged() signal instead, as the destination CRS dictates the map units.
1650+
- layerCrsChange() slot was removed. Datum transforms are now handled in QgisApp.
16501651

16511652
QgsMapCanvasItem {#qgis_api_break_3_0_QgsMapCanvasItem}
16521653
----------------

python/gui/qgsmapcanvas.sip

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,6 @@ Save the convtents of the map canvas to disk as an image
695695
void layerStateChange();
696696
%Docstring
697697
This slot is connected to the visibility change of one or more layers
698-
%End
699-
700-
void layerCrsChange();
701-
%Docstring
702-
This slot is connected to the layer's CRS change
703698
%End
704699

705700
void setRenderFlag( bool flag );
@@ -952,11 +947,6 @@ called when panning is in action, reset indicates end of panning
952947

953948

954949

955-
void updateDatumTransformEntries();
956-
%Docstring
957-
Make sure the datum transform store is properly populated
958-
%End
959-
960950
protected slots:
961951
void updateCanvasItemPositions();
962952
%Docstring

src/app/qgisapp.cpp

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,14 +3184,7 @@ void QgisApp::setupConnections()
31843184
this, &QgisApp::mapCanvas_keyPressed );
31853185

31863186
// project crs connections
3187-
connect( QgsProject::instance(), &QgsProject::crsChanged,
3188-
this, &QgisApp::updateCrsStatusBar );
3189-
connect( QgsProject::instance(), &QgsProject::crsChanged,
3190-
this, [ = ]
3191-
{
3192-
QgsDebugMsgLevel( QString( "QgisApp::setupConnections -1- : QgsProject::instance()->crs().description[%1]ellipsoid[%2]" ).arg( QgsProject::instance()->crs().description() ).arg( QgsProject::instance()->crs().ellipsoidAcronym() ), 3 );
3193-
mMapCanvas->setDestinationCrs( QgsProject::instance()->crs() );
3194-
} );
3187+
connect( QgsProject::instance(), &QgsProject::crsChanged, this, &QgisApp::onProjectCrsChanged );
31953188

31963189
connect( QgsProject::instance(), &QgsProject::labelingEngineSettingsChanged,
31973190
this, [ = ]
@@ -9126,6 +9119,45 @@ void QgisApp::onFocusChanged( QWidget *oldWidget, QWidget *newWidget )
91269119
}
91279120
}
91289121

9122+
void QgisApp::onProjectCrsChanged()
9123+
{
9124+
updateCrsStatusBar();
9125+
QgsDebugMsgLevel( QString( "QgisApp::setupConnections -1- : QgsProject::instance()->crs().description[%1]ellipsoid[%2]" ).arg( QgsProject::instance()->crs().description() ).arg( QgsProject::instance()->crs().ellipsoidAcronym() ), 3 );
9126+
mMapCanvas->setDestinationCrs( QgsProject::instance()->crs() );
9127+
9128+
// handle datum transforms
9129+
QList<QgsCoordinateReferenceSystem> transformsToAskFor = QList<QgsCoordinateReferenceSystem>();
9130+
QMap<QString, QgsMapLayer *> layers = QgsProject::instance()->mapLayers();
9131+
for ( QMap<QString, QgsMapLayer *>::iterator it = layers.begin(); it != layers.end(); ++it )
9132+
{
9133+
if ( !transformsToAskFor.contains( it.value()->crs() ) &&
9134+
it.value()->crs() != QgsProject::instance()->crs() &&
9135+
!QgsProject::instance()->transformContext().hasTransform( it.value()->crs(), QgsProject::instance()->crs() ) &&
9136+
QgsCoordinateTransform::datumTransformations( it.value()->crs(), QgsProject::instance()->crs() ).count() > 1 )
9137+
{
9138+
transformsToAskFor.append( it.value()->crs() );
9139+
}
9140+
}
9141+
if ( transformsToAskFor.count() == 1 )
9142+
{
9143+
askForDatumTransform( transformsToAskFor.at( 0 ),
9144+
QgsProject::instance()->crs() );
9145+
}
9146+
else if ( transformsToAskFor.count() > 1 )
9147+
{
9148+
bool ask = QgsSettings().value( QStringLiteral( "/Projections/showDatumTransformDialog" ), false ).toBool();
9149+
if ( ask )
9150+
{
9151+
messageBar()->pushMessage( tr( "Datum transforms" ),
9152+
tr( "Project CRS changed and datum transforms might need to be adapted." ),
9153+
QgsMessageBar::WARNING,
9154+
5 );
9155+
}
9156+
}
9157+
9158+
9159+
}
9160+
91299161
// toggle overview status
91309162
void QgisApp::isInOverview()
91319163
{
@@ -9425,6 +9457,7 @@ void QgisApp::setLayerCrs()
94259457
{
94269458
if ( child->layer() )
94279459
{
9460+
askForDatumTransform( crs, QgsProject::instance()->crs() );
94289461
child->layer()->setCrs( crs );
94299462
child->layer()->triggerRepaint();
94309463
}
@@ -9435,6 +9468,7 @@ void QgisApp::setLayerCrs()
94359468
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
94369469
if ( nodeLayer->layer() )
94379470
{
9471+
askForDatumTransform( crs, QgsProject::instance()->crs() );
94389472
nodeLayer->layer()->setCrs( crs );
94399473
nodeLayer->layer()->triggerRepaint();
94409474
}

src/app/qgisapp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
16151615

16161616
void onFocusChanged( QWidget *oldWidget, QWidget *newWidget );
16171617

1618+
//! handles project crs changes
1619+
void onProjectCrsChanged();
1620+
16181621
signals:
16191622

16201623
/**

src/app/qgsrasterlayerproperties.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,7 @@ void QgsRasterLayerProperties::pbnAddValuesManually_clicked()
12211221

12221222
void QgsRasterLayerProperties::mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs )
12231223
{
1224+
QgisApp::instance()->askForDatumTransform( crs, QgsProject::instance()->crs() );
12241225
mRasterLayer->setCrs( crs );
12251226
}
12261227

src/app/qgsvectorlayerproperties.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ void QgsVectorLayerProperties::mLayerOrigNameLineEdit_textEdited( const QString
831831

832832
void QgsVectorLayerProperties::mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs )
833833
{
834+
QgisApp::instance()->askForDatumTransform( crs, QgsProject::instance()->crs() );
834835
mLayer->setCrs( crs );
835836
mMetadataFilled = false;
836837
}

src/gui/qgsmapcanvas.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ void QgsMapCanvas::setLayersPrivate( const QList<QgsMapLayer *> &layers )
317317
Q_FOREACH ( QgsMapLayer *layer, oldLayers )
318318
{
319319
disconnect( layer, &QgsMapLayer::repaintRequested, this, &QgsMapCanvas::layerRepaintRequested );
320-
disconnect( layer, &QgsMapLayer::crsChanged, this, &QgsMapCanvas::layerCrsChange );
321320
disconnect( layer, &QgsMapLayer::autoRefreshIntervalChanged, this, &QgsMapCanvas::updateAutoRefreshTimer );
322321
if ( QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer ) )
323322
{
@@ -332,14 +331,12 @@ void QgsMapCanvas::setLayersPrivate( const QList<QgsMapLayer *> &layers )
332331
if ( !layer )
333332
continue;
334333
connect( layer, &QgsMapLayer::repaintRequested, this, &QgsMapCanvas::layerRepaintRequested );
335-
connect( layer, &QgsMapLayer::crsChanged, this, &QgsMapCanvas::layerCrsChange );
336334
connect( layer, &QgsMapLayer::autoRefreshIntervalChanged, this, &QgsMapCanvas::updateAutoRefreshTimer );
337335
if ( QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer ) )
338336
{
339337
connect( vlayer, &QgsVectorLayer::selectionChanged, this, &QgsMapCanvas::selectionChangedSlot );
340338
}
341339
}
342-
updateDatumTransformEntries();
343340

344341
QgsDebugMsg( "Layers have changed, refreshing" );
345342
emit layersChanged();
@@ -386,8 +383,6 @@ void QgsMapCanvas::setDestinationCrs( const QgsCoordinateReferenceSystem &crs )
386383
QgsDebugMsg( "refreshing after destination CRS changed" );
387384
refresh();
388385

389-
updateDatumTransformEntries();
390-
391386
emit destinationCrsChanged();
392387
}
393388

@@ -1732,14 +1727,6 @@ void QgsMapCanvas::layerStateChange()
17321727
refresh();
17331728
}
17341729

1735-
void QgsMapCanvas::layerCrsChange()
1736-
{
1737-
// called when a layer's CRS has been changed
1738-
QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sender() );
1739-
// TODO datum we should trigger a message to say one could choose datum transform
1740-
//getDatumTransformInfo( layer->crs(), mSettings.destinationCrs() );
1741-
}
1742-
17431730
void QgsMapCanvas::freeze( bool frozen )
17441731
{
17451732
mFrozen = frozen;
@@ -1816,24 +1803,6 @@ void QgsMapCanvas::connectNotify( const char *signal )
18161803
} //connectNotify
18171804
#endif
18181805

1819-
void QgsMapCanvas::updateDatumTransformEntries()
1820-
{
1821-
const QList< QgsMapLayer * > layers = mSettings.layers();
1822-
for ( QgsMapLayer *layer : layers )
1823-
{
1824-
if ( !layer->isSpatial() )
1825-
continue;
1826-
1827-
// if there are more options, ask the user which datum transform to use
1828-
1829-
#if 0 //old logic - TODO - what is the new logic for when we show this dialog?
1830-
if ( !mSettings.datumTransformStore().hasEntryForLayer( layer ) )
1831-
#endif
1832-
// TODO datum we should trigger a message to say one could choose datum transform
1833-
// getDatumTransformInfo( layer->crs(), mSettings.destinationCrs() );
1834-
}
1835-
}
1836-
18371806
void QgsMapCanvas::layerRepaintRequested( bool deferred )
18381807
{
18391808
if ( !deferred )

src/gui/qgsmapcanvas.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,6 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
652652
//! This slot is connected to the visibility change of one or more layers
653653
void layerStateChange();
654654

655-
//! This slot is connected to the layer's CRS change
656-
void layerCrsChange();
657-
658655
/**
659656
* Sets whether a user has disabled canvas renders via the GUI.
660657
* \param flag set to false to indicate that user has disabled renders
@@ -879,9 +876,6 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
879876
void connectNotify( const char *signal ) override;
880877
#endif
881878

882-
//! Make sure the datum transform store is properly populated
883-
void updateDatumTransformEntries();
884-
885879
protected slots:
886880
//! called on resize or changed extent to notify canvas items to change their rectangle
887881
void updateCanvasItemPositions();

0 commit comments

Comments
 (0)