Skip to content
Permalink
Browse files

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
  • Loading branch information
3nids authored and nyalldawson committed Dec 1, 2017
1 parent adf0722 commit 68aef9a42621ae41ba15699528dc35771cae8241
@@ -1647,6 +1647,7 @@ QgsMapCanvas {#qgis_api_break_3_0_QgsMapCanvas}
- setCrsTransformEnabled(), hasCrsTransformEnabled(), hasCrsTransformEnabledChanged() were removed. CRS transformation is now always enabled.
- setMapUnits() was removed. The map units are dictated by the units for the destination CRS.
- The mapUnitsChanged() signal was removed. Listen for the destinationCrsChanged() signal instead, as the destination CRS dictates the map units.
- layerCrsChange() slot was removed. Datum transforms are now handled in QgisApp.

QgsMapCanvasItem {#qgis_api_break_3_0_QgsMapCanvasItem}
----------------
@@ -695,11 +695,6 @@ Save the convtents of the map canvas to disk as an image
void layerStateChange();
%Docstring
This slot is connected to the visibility change of one or more layers
%End

void layerCrsChange();
%Docstring
This slot is connected to the layer's CRS change
%End

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



void updateDatumTransformEntries();
%Docstring
Make sure the datum transform store is properly populated
%End

protected slots:
void updateCanvasItemPositions();
%Docstring
@@ -3184,14 +3184,7 @@ void QgisApp::setupConnections()
this, &QgisApp::mapCanvas_keyPressed );

// project crs connections
connect( QgsProject::instance(), &QgsProject::crsChanged,
this, &QgisApp::updateCrsStatusBar );
connect( QgsProject::instance(), &QgsProject::crsChanged,
this, [ = ]
{
QgsDebugMsgLevel( QString( "QgisApp::setupConnections -1- : QgsProject::instance()->crs().description[%1]ellipsoid[%2]" ).arg( QgsProject::instance()->crs().description() ).arg( QgsProject::instance()->crs().ellipsoidAcronym() ), 3 );
mMapCanvas->setDestinationCrs( QgsProject::instance()->crs() );
} );
connect( QgsProject::instance(), &QgsProject::crsChanged, this, &QgisApp::onProjectCrsChanged );

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

void QgisApp::onProjectCrsChanged()
{
updateCrsStatusBar();
QgsDebugMsgLevel( QString( "QgisApp::setupConnections -1- : QgsProject::instance()->crs().description[%1]ellipsoid[%2]" ).arg( QgsProject::instance()->crs().description() ).arg( QgsProject::instance()->crs().ellipsoidAcronym() ), 3 );
mMapCanvas->setDestinationCrs( QgsProject::instance()->crs() );

// handle datum transforms
QList<QgsCoordinateReferenceSystem> transformsToAskFor = QList<QgsCoordinateReferenceSystem>();
QMap<QString, QgsMapLayer *> layers = QgsProject::instance()->mapLayers();
for ( QMap<QString, QgsMapLayer *>::iterator it = layers.begin(); it != layers.end(); ++it )
{
if ( !transformsToAskFor.contains( it.value()->crs() ) &&
it.value()->crs() != QgsProject::instance()->crs() &&
!QgsProject::instance()->transformContext().hasTransform( it.value()->crs(), QgsProject::instance()->crs() ) &&
QgsCoordinateTransform::datumTransformations( it.value()->crs(), QgsProject::instance()->crs() ).count() > 1 )
{
transformsToAskFor.append( it.value()->crs() );
}
}
if ( transformsToAskFor.count() == 1 )
{
askForDatumTransform( transformsToAskFor.at( 0 ),
QgsProject::instance()->crs() );
}
else if ( transformsToAskFor.count() > 1 )
{
bool ask = QgsSettings().value( QStringLiteral( "/Projections/showDatumTransformDialog" ), false ).toBool();
if ( ask )
{
messageBar()->pushMessage( tr( "Datum transforms" ),
tr( "Project CRS changed and datum transforms might need to be adapted." ),
QgsMessageBar::WARNING,
5 );
}
}


}

// toggle overview status
void QgisApp::isInOverview()
{
@@ -9425,6 +9457,7 @@ void QgisApp::setLayerCrs()
{
if ( child->layer() )
{
askForDatumTransform( crs, QgsProject::instance()->crs() );
child->layer()->setCrs( crs );
child->layer()->triggerRepaint();
}
@@ -9435,6 +9468,7 @@ void QgisApp::setLayerCrs()
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
if ( nodeLayer->layer() )
{
askForDatumTransform( crs, QgsProject::instance()->crs() );
nodeLayer->layer()->setCrs( crs );
nodeLayer->layer()->triggerRepaint();
}
@@ -1615,6 +1615,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

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

//! handles project crs changes
void onProjectCrsChanged();

signals:

/**
@@ -1221,6 +1221,7 @@ void QgsRasterLayerProperties::pbnAddValuesManually_clicked()

void QgsRasterLayerProperties::mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs )
{
QgisApp::instance()->askForDatumTransform( crs, QgsProject::instance()->crs() );
mRasterLayer->setCrs( crs );
}

@@ -831,6 +831,7 @@ void QgsVectorLayerProperties::mLayerOrigNameLineEdit_textEdited( const QString

void QgsVectorLayerProperties::mCrsSelector_crsChanged( const QgsCoordinateReferenceSystem &crs )
{
QgisApp::instance()->askForDatumTransform( crs, QgsProject::instance()->crs() );
mLayer->setCrs( crs );
mMetadataFilled = false;
}
@@ -317,7 +317,6 @@ void QgsMapCanvas::setLayersPrivate( const QList<QgsMapLayer *> &layers )
Q_FOREACH ( QgsMapLayer *layer, oldLayers )
{
disconnect( layer, &QgsMapLayer::repaintRequested, this, &QgsMapCanvas::layerRepaintRequested );
disconnect( layer, &QgsMapLayer::crsChanged, this, &QgsMapCanvas::layerCrsChange );
disconnect( layer, &QgsMapLayer::autoRefreshIntervalChanged, this, &QgsMapCanvas::updateAutoRefreshTimer );
if ( QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer ) )
{
@@ -332,14 +331,12 @@ void QgsMapCanvas::setLayersPrivate( const QList<QgsMapLayer *> &layers )
if ( !layer )
continue;
connect( layer, &QgsMapLayer::repaintRequested, this, &QgsMapCanvas::layerRepaintRequested );
connect( layer, &QgsMapLayer::crsChanged, this, &QgsMapCanvas::layerCrsChange );
connect( layer, &QgsMapLayer::autoRefreshIntervalChanged, this, &QgsMapCanvas::updateAutoRefreshTimer );
if ( QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer ) )
{
connect( vlayer, &QgsVectorLayer::selectionChanged, this, &QgsMapCanvas::selectionChangedSlot );
}
}
updateDatumTransformEntries();

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

updateDatumTransformEntries();

emit destinationCrsChanged();
}

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

void QgsMapCanvas::layerCrsChange()
{
// called when a layer's CRS has been changed
QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sender() );
// TODO datum we should trigger a message to say one could choose datum transform
//getDatumTransformInfo( layer->crs(), mSettings.destinationCrs() );
}

void QgsMapCanvas::freeze( bool frozen )
{
mFrozen = frozen;
@@ -1816,24 +1803,6 @@ void QgsMapCanvas::connectNotify( const char *signal )
} //connectNotify
#endif

void QgsMapCanvas::updateDatumTransformEntries()
{
const QList< QgsMapLayer * > layers = mSettings.layers();
for ( QgsMapLayer *layer : layers )
{
if ( !layer->isSpatial() )
continue;

// if there are more options, ask the user which datum transform to use

#if 0 //old logic - TODO - what is the new logic for when we show this dialog?
if ( !mSettings.datumTransformStore().hasEntryForLayer( layer ) )
#endif
// TODO datum we should trigger a message to say one could choose datum transform
// getDatumTransformInfo( layer->crs(), mSettings.destinationCrs() );
}
}

void QgsMapCanvas::layerRepaintRequested( bool deferred )
{
if ( !deferred )
@@ -652,9 +652,6 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! This slot is connected to the visibility change of one or more layers
void layerStateChange();

//! This slot is connected to the layer's CRS change
void layerCrsChange();

/**
* Sets whether a user has disabled canvas renders via the GUI.
* \param flag set to false to indicate that user has disabled renders
@@ -879,9 +876,6 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
void connectNotify( const char *signal ) override;
#endif

//! Make sure the datum transform store is properly populated
void updateDatumTransformEntries();

protected slots:
//! called on resize or changed extent to notify canvas items to change their rectangle
void updateCanvasItemPositions();

0 comments on commit 68aef9a

Please sign in to comment.
You can’t perform that action at this time.