Skip to content
Permalink
Browse files

added method in QgisApp to ask for datum

  • Loading branch information
3nids authored and nyalldawson committed Dec 15, 2017
1 parent e303f74 commit 5cc3a1f07912e191b7a86677f327cef34ee84bc8
@@ -1209,6 +1209,15 @@ Unregister a previously registered action. (e.g. when plugin is going to be unlo
.. versionadded:: 3.0
%End

virtual bool askForDatumTransform( QgsCoordinateReferenceSystem sourceCrs, QgsCoordinateReferenceSystem destinationCrs ) = 0;
%Docstring
Checks available datum transforms and ask user if several are available and none
is chosen. Dialog is shown only if global option is set accordingly.
:return: true if a datum transform has been specifically chosen by user or only one is available.
.. versionadded:: 3.0
:rtype: bool
%End

signals:

void currentLayerChanged( QgsMapLayer *layer );
@@ -727,10 +727,6 @@ called to read map canvas settings from project
called to write map canvas settings to project
%End

void getDatumTransformInfo( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination );
%Docstring
ask user about datum transformation
%End

void setMagnificationFactor( double factor );
%Docstring
@@ -12525,6 +12525,49 @@ void QgisApp::writeDockWidgetSettings( QDockWidget *dockWidget, QDomElement &ele
elem.setAttribute( QStringLiteral( "area" ), dockWidgetArea( dockWidget ) );
}

bool QgisApp::askForDatumTransform( QgsCoordinateReferenceSystem sourceCrs, QgsCoordinateReferenceSystem destinationCrs )
{
bool ok = false;

QgsCoordinateTransformContext context = QgsProject::instance()->transformContext();
QPair<int, int> dt = context.calculateDatumTransforms( sourceCrs, destinationCrs );
if ( dt != qMakePair( -1, -1 ) )
{
// already defined by user
ok = true;
}
else
{
//if several possibilities: present dialog
QgsDatumTransformDialog dlg( sourceCrs, destinationCrs );
if ( dlg.availableTransformationCount() > 1 )
{
bool ask = QgsSettings().value( QStringLiteral( "/Projections/showDatumTransformDialog" ), false ).toBool();
if ( !ask )
{
ok = false;
}
if ( dlg.exec() )
{
QPair< QPair<QgsCoordinateReferenceSystem, int>, QPair<QgsCoordinateReferenceSystem, int > > dt = dlg.selectedDatumTransforms();
QgsCoordinateTransformContext context = QgsProject::instance()->transformContext();
context.addSourceDestinationDatumTransform( dt.first.first, dt.second.first, dt.first.second, dt.second.second );
QgsProject::instance()->setTransformContext( context );
ok = true;
}
else
{
ok = false;
}
}
else
{
ok = true;
}
}
return ok;
}

void QgisApp::readDockWidgetSettings( QDockWidget *dockWidget, const QDomElement &elem )
{
int x = elem.attribute( QStringLiteral( "x" ), QStringLiteral( "0" ) ).toInt();
@@ -691,6 +691,14 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
QSize iconSize( bool dockedToolbar = false ) const;

/**
* Checks available datum transforms and ask user if several are available and none
* is chosen. Dialog is shown only if global option is set accordingly.
* \returns true if a datum transform has been specifically chosen by user or only one is available.
* \since 3.0
*/
bool askForDatumTransform( QgsCoordinateReferenceSystem sourceCrs, QgsCoordinateReferenceSystem destinationCrs );

public slots:
//! save current vector layer
void saveAsFile( QgsMapLayer *layer = nullptr );
@@ -31,6 +31,7 @@
#include "qgsapplayertreeviewmenuprovider.h"
#include "qgscomposer.h"
#include "qgscomposerview.h"
#include "qgsdatumtransformdialog.h"
#include "qgsgui.h"
#include "qgsmaplayer.h"
#include "qgsmaptooladvanceddigitizing.h"
@@ -823,3 +824,8 @@ void QgisAppInterface::deregisterLocatorFilter( QgsLocatorFilter *filter )
{
qgis->mLocatorWidget->locator()->deregisterFilter( filter );
}

bool QgisAppInterface::askForDatumTransform( QgsCoordinateReferenceSystem sourceCrs, QgsCoordinateReferenceSystem destinationCrs )
{
return qgis->askForDatumTransform( sourceCrs, destinationCrs );
}
@@ -544,6 +544,9 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
void registerLocatorFilter( QgsLocatorFilter *filter ) override;
void deregisterLocatorFilter( QgsLocatorFilter *filter ) override;

bool askForDatumTransform( QgsCoordinateReferenceSystem sourceCrs, QgsCoordinateReferenceSystem destinationCrs ) override;


private slots:

void cacheloadForm( const QString &uifile );
@@ -270,11 +270,7 @@ QgsFeatureList QgsClipboard::transformedCopyOf( const QgsCoordinateReferenceSyst
{
QgsFeatureList featureList = copyOf( fields );

if ( mSrcLayer )
{
QgisApp::instance()->mapCanvas()->getDatumTransformInfo( crs(), destCRS );
}

QgisApp::instance()->askForDatumTransform( crs(), destCRS );
QgsCoordinateTransform ct = QgsCoordinateTransform( crs(), destCRS, QgsProject::instance() );

QgsDebugMsg( "transforming clipboard." );
@@ -771,6 +771,14 @@ class GUI_EXPORT QgisInterface : public QObject
*/
virtual void deregisterLocatorFilter( QgsLocatorFilter *filter ) = 0;

/**
* Checks available datum transforms and ask user if several are available and none
* is chosen. Dialog is shown only if global option is set accordingly.
* \returns true if a datum transform has been specifically chosen by user or only one is available.
* \since 3.0
*/
virtual bool askForDatumTransform( QgsCoordinateReferenceSystem sourceCrs, QgsCoordinateReferenceSystem destinationCrs ) = 0;

signals:

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

void QgsMapCanvas::freeze( bool frozen )
@@ -1826,8 +1827,9 @@ void QgsMapCanvas::updateDatumTransformEntries()
#if 0 //old logic - TODO - what is the new logic for when we show this dialog?
if ( !mSettings.datumTransformStore().hasEntryForLayer( layer ) )
#endif
getDatumTransformInfo( layer->crs(), mSettings.destinationCrs() );
}
// TODO datum we should trigger a message to say one could choose datum transform
// getDatumTransformInfo( layer->crs(), mSettings.destinationCrs() );
}
}

void QgsMapCanvas::layerRepaintRequested( bool deferred )
@@ -2060,6 +2062,7 @@ void QgsMapCanvas::writeProject( QDomDocument &doc )
// TODO: store only units, extent, projections, dest CRS
}

#if 0
void QgsMapCanvas::getDatumTransformInfo( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination )
{
if ( !source.isValid() || !destination.isValid() )
@@ -2091,6 +2094,7 @@ void QgsMapCanvas::getDatumTransformInfo( const QgsCoordinateReferenceSystem &so
if ( d.availableTransformationCount() > 1 )
d.exec();
}
#endif

void QgsMapCanvas::zoomByFactor( double scaleFactor, const QgsPointXY *center )
{
@@ -676,8 +676,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! called to write map canvas settings to project
void writeProject( QDomDocument & );

#if 0
//! ask user about datum transformation
void getDatumTransformInfo( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination );
#endif

/**
* Sets the factor of magnification to apply to the map canvas. Indeed, we

0 comments on commit 5cc3a1f

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