Skip to content

Commit a04ebf9

Browse files
committedJun 5, 2014
Reintroduce datum transforms (were disabled during transition to MTR)
1 parent 9019805 commit a04ebf9

15 files changed

+344
-38
lines changed
 

‎python/core/core.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
%Include qgsdataitem.sip
2626
%Include qgsdataprovider.sip
2727
%Include qgsdatasourceuri.sip
28+
%Include qgsdatumtransformstore.sip
2829
%Include qgsdbfilterproxymodel.sip
2930
%Include qgsdistancearea.sip
3031
%Include qgseditorwidgetconfig.sip
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @brief The QgsDatumTransformStore class keeps track of datum transformations
3+
* as chosen by the user.
4+
*
5+
* @note added in 2.4
6+
*/
7+
class QgsDatumTransformStore
8+
{
9+
%TypeHeaderCode
10+
#include <qgsdatumtransformstore.h>
11+
%End
12+
13+
public:
14+
explicit QgsDatumTransformStore( const QgsCoordinateReferenceSystem& destCrs );
15+
16+
void clear();
17+
18+
void setDestinationCrs( const QgsCoordinateReferenceSystem& destCrs );
19+
20+
void addEntry( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform, int destDatumTransform );
21+
22+
bool hasEntryForLayer( QgsMapLayer* layer ) const;
23+
24+
/** will return transform from layer's CRS to current destination CRS.
25+
* Will emit datumTransformInfoRequested signal if the layer has no entry.
26+
* Returns an instance from QgsCoordinateTransformCache
27+
*/
28+
const QgsCoordinateTransform* transformation( QgsMapLayer* layer ) const;
29+
30+
void readXML( const QDomNode& parentNode );
31+
32+
void writeXML( QDomNode& parentNode, QDomDocument& theDoc ) const;
33+
34+
};

‎python/core/qgsmapsettings.sip

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class QgsMapSettings
8080

8181
// -- utility functions --
8282

83+
//const QgsDatumTransformStore& datumTransformStore() const;
84+
QgsDatumTransformStore& datumTransformStore();
85+
8386
const QgsMapToPixel& mapToPixel() const;
8487

8588
/**
@@ -122,6 +125,12 @@ class QgsMapSettings
122125
*/
123126
QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
124127

128+
/**
129+
* @brief Return coordinate transform from layer's CRS to destination CRS
130+
* @param layer
131+
* @return transform - may be null if the transform is not needed
132+
*/
133+
const QgsCoordinateTransform* layerTransfrom( QgsMapLayer *layer ) const;
125134

126135
//! returns current extent of layer set
127136
QgsRectangle fullExtent() const;

‎src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ SET(QGIS_CORE_SRCS
7474
qgsdatadefined.cpp
7575
qgsdatasourceuri.cpp
7676
qgsdataitem.cpp
77+
qgsdatumtransformstore.cpp
7778
qgsdbfilterproxymodel.cpp
7879
qgsdiagramrendererv2.cpp
7980
qgsdistancearea.cpp
@@ -431,6 +432,7 @@ SET(QGIS_CORE_HDRS
431432
qgsdatadefined.h
432433
qgsdatasourceuri.h
433434
qgsdataitem.h
435+
qgsdatumtransformstore.h
434436
qgsdistancearea.h
435437
qgscsexception.h
436438
qgseditorwidgetconfig.h

‎src/core/qgsdatumtransformstore.cpp

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/***************************************************************************
2+
qgsdatumtransformstore.cpp
3+
---------------------
4+
begin : June 2014
5+
copyright : (C) 2014 by Martin Dobias
6+
email : wonder dot sk at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgsdatumtransformstore.h"
17+
18+
#include "qgscrscache.h"
19+
#include "qgslogger.h"
20+
#include "qgsmaplayer.h"
21+
22+
QgsDatumTransformStore::QgsDatumTransformStore( const QgsCoordinateReferenceSystem& destCrs )
23+
: mDestCRS( destCrs )
24+
{
25+
26+
}
27+
28+
void QgsDatumTransformStore::clear()
29+
{
30+
mEntries.clear();
31+
}
32+
33+
void QgsDatumTransformStore::setDestinationCrs( const QgsCoordinateReferenceSystem& destCrs )
34+
{
35+
mDestCRS = destCrs;
36+
clear();
37+
}
38+
39+
void QgsDatumTransformStore::addEntry( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform, int destDatumTransform )
40+
{
41+
Entry lt;
42+
lt.srcAuthId = srcAuthId;
43+
lt.destAuthId = destAuthId;
44+
lt.srcDatumTransform = srcDatumTransform;
45+
lt.destDatumTransform = destDatumTransform;
46+
mEntries.insert( layerId, lt );
47+
}
48+
49+
bool QgsDatumTransformStore::hasEntryForLayer( QgsMapLayer* layer ) const
50+
{
51+
return mEntries.contains( layer->id() );
52+
}
53+
54+
const QgsCoordinateTransform* QgsDatumTransformStore::transformation( QgsMapLayer* layer ) const
55+
{
56+
QString srcAuthId = layer->crs().authid();
57+
QString dstAuthId = mDestCRS.authid();
58+
59+
if ( !layer || srcAuthId == dstAuthId )
60+
{
61+
return 0;
62+
}
63+
64+
QHash< QString, Entry >::const_iterator ctIt = mEntries.find( layer->id() );
65+
if ( ctIt != mEntries.constEnd() && ctIt->srcAuthId == srcAuthId && ctIt->destAuthId == dstAuthId )
66+
{
67+
return QgsCoordinateTransformCache::instance()->transform( ctIt->srcAuthId, ctIt->destAuthId, ctIt->srcDatumTransform, ctIt->destDatumTransform );
68+
}
69+
else
70+
{
71+
return QgsCoordinateTransformCache::instance()->transform( srcAuthId, dstAuthId, -1, -1 );
72+
}
73+
}
74+
75+
void QgsDatumTransformStore::readXML( const QDomNode& parentNode )
76+
{
77+
clear();
78+
79+
QDomElement layerCoordTransformInfoElem = parentNode.firstChildElement( "layer_coordinate_transform_info" );
80+
if ( !layerCoordTransformInfoElem.isNull() )
81+
{
82+
QDomNodeList layerCoordinateTransformList = layerCoordTransformInfoElem.elementsByTagName( "layer_coordinate_transform" );
83+
QDomElement layerCoordTransformElem;
84+
for ( int i = 0; i < layerCoordinateTransformList.size(); ++i )
85+
{
86+
layerCoordTransformElem = layerCoordinateTransformList.at( i ).toElement();
87+
QString layerId = layerCoordTransformElem.attribute( "layerid" );
88+
if ( layerId.isEmpty() )
89+
{
90+
continue;
91+
}
92+
93+
Entry lct;
94+
lct.srcAuthId = layerCoordTransformElem.attribute( "srcAuthId" );
95+
lct.destAuthId = layerCoordTransformElem.attribute( "destAuthId" );
96+
lct.srcDatumTransform = layerCoordTransformElem.attribute( "srcDatumTransform", "-1" ).toInt();
97+
lct.destDatumTransform = layerCoordTransformElem.attribute( "destDatumTransform", "-1" ).toInt();
98+
mEntries.insert( layerId, lct );
99+
}
100+
}
101+
}
102+
103+
void QgsDatumTransformStore::writeXML( QDomNode& parentNode, QDomDocument& theDoc ) const
104+
{
105+
// layer coordinate transform infos
106+
QDomElement layerCoordTransformInfo = theDoc.createElement( "layer_coordinate_transform_info" );
107+
108+
for ( QHash< QString, Entry >::const_iterator coordIt = mEntries.constBegin(); coordIt != mEntries.constEnd(); ++coordIt )
109+
{
110+
QDomElement layerCoordTransformElem = theDoc.createElement( "layer_coordinate_transform" );
111+
layerCoordTransformElem.setAttribute( "layerid", coordIt.key() );
112+
layerCoordTransformElem.setAttribute( "srcAuthId", coordIt->srcAuthId );
113+
layerCoordTransformElem.setAttribute( "destAuthId", coordIt->destAuthId );
114+
layerCoordTransformElem.setAttribute( "srcDatumTransform", QString::number( coordIt->srcDatumTransform ) );
115+
layerCoordTransformElem.setAttribute( "destDatumTransform", QString::number( coordIt->destDatumTransform ) );
116+
layerCoordTransformInfo.appendChild( layerCoordTransformElem );
117+
}
118+
parentNode.appendChild( layerCoordTransformInfo );
119+
}

‎src/core/qgsdatumtransformstore.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/***************************************************************************
2+
qgsdatumtransformstore.h
3+
---------------------
4+
begin : June 2014
5+
copyright : (C) 2014 by Martin Dobias
6+
email : wonder dot sk at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
#ifndef QGSDATUMTRANSFORMSTORE_H
16+
#define QGSDATUMTRANSFORMSTORE_H
17+
18+
#include "qgscoordinatereferencesystem.h"
19+
20+
class QgsCoordinateTransform;
21+
class QgsMapLayer;
22+
23+
class QDomElement;
24+
25+
26+
/**
27+
* @brief The QgsDatumTransformStore class keeps track of datum transformations
28+
* as chosen by the user.
29+
*
30+
* @note added in 2.4
31+
*/
32+
class CORE_EXPORT QgsDatumTransformStore
33+
{
34+
public:
35+
explicit QgsDatumTransformStore( const QgsCoordinateReferenceSystem& destCrs );
36+
37+
void clear();
38+
39+
void setDestinationCrs( const QgsCoordinateReferenceSystem& destCrs );
40+
41+
void addEntry( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform, int destDatumTransform );
42+
43+
bool hasEntryForLayer( QgsMapLayer* layer ) const;
44+
45+
/** will return transform from layer's CRS to current destination CRS.
46+
* Will emit datumTransformInfoRequested signal if the layer has no entry.
47+
* Returns an instance from QgsCoordinateTransformCache
48+
*/
49+
const QgsCoordinateTransform* transformation( QgsMapLayer* layer ) const;
50+
51+
void readXML( const QDomNode& parentNode );
52+
53+
void writeXML( QDomNode& parentNode, QDomDocument& theDoc ) const;
54+
55+
struct Entry
56+
{
57+
QString srcAuthId;
58+
QString destAuthId;
59+
int srcDatumTransform; //-1 if unknown or not specified
60+
int destDatumTransform;
61+
};
62+
63+
protected:
64+
QgsCoordinateReferenceSystem mDestCRS;
65+
66+
//! key = layer ID
67+
QHash< QString, Entry > mEntries;
68+
};
69+
70+
#endif // QGSDATUMTRANSFORMSTORE_H

‎src/core/qgsmaprendererjob.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ void QgsMapRendererJob::drawOldLabeling( const QgsMapSettings& settings, QgsRend
408408

409409
if ( settings.hasCrsTransformEnabled() )
410410
{
411-
ct = QgsCoordinateTransformCache::instance()->transform( ml->crs().authid(), settings.destinationCrs().authid() );
411+
ct = settings.layerTransfrom( ml );
412412
reprojectToLayerExtent( ct, ml->crs().geographicFlag(), r1, r2 );
413413
}
414414

@@ -571,7 +571,7 @@ LayerRenderJobs QgsMapRendererJob::prepareJobs( QPainter* painter, QgsPalLabelin
571571

572572
if ( mSettings.hasCrsTransformEnabled() )
573573
{
574-
ct = QgsCoordinateTransformCache::instance()->transform( ml->crs().authid(), mSettings.destinationCrs().authid() );
574+
ct = mSettings.layerTransfrom( ml );
575575
reprojectToLayerExtent( ct, ml->crs().geographicFlag(), r1, r2 );
576576
QgsDebugMsg( "extent: " + r1.toString() );
577577
if ( !r1.isFinite() || !r2.isFinite() )

‎src/core/qgsmapsettings.cpp

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ QgsMapSettings::QgsMapSettings()
2222
, mExtent()
2323
, mProjectionsEnabled( false )
2424
, mDestCRS( GEOCRS_ID, QgsCoordinateReferenceSystem::InternalCrsId ) // WGS 84
25+
, mDatumTransformStore( mDestCRS )
2526
, mBackgroundColor( Qt::white )
2627
, mSelectionColor( Qt::yellow )
2728
, mShowSelection( true )
@@ -189,6 +190,7 @@ bool QgsMapSettings::hasCrsTransformEnabled() const
189190
void QgsMapSettings::setDestinationCrs( const QgsCoordinateReferenceSystem& crs )
190191
{
191192
mDestCRS = crs;
193+
mDatumTransformStore.setDestinationCrs( crs );
192194
}
193195

194196
const QgsCoordinateReferenceSystem& QgsMapSettings::destinationCrs() const
@@ -258,27 +260,26 @@ double QgsMapSettings::scale() const
258260

259261

260262

261-
const QgsCoordinateTransform* QgsMapSettings::coordTransform( QgsMapLayer *layer ) const
263+
const QgsCoordinateTransform* QgsMapSettings::layerTransfrom( QgsMapLayer *layer ) const
262264
{
263-
if ( !layer )
264-
{
265-
return 0;
266-
}
267-
return QgsCoordinateTransformCache::instance()->transform( layer->crs().authid(), mDestCRS.authid() );
265+
return mDatumTransformStore.transformation( layer );
268266
}
269267

270268

271269

272270
QgsRectangle QgsMapSettings::layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const
273271
{
274-
QgsDebugMsg( QString( "sourceCrs = " + coordTransform( theLayer )->sourceCrs().authid() ) );
275-
QgsDebugMsg( QString( "destCRS = " + coordTransform( theLayer )->destCRS().authid() ) );
276-
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
277272
if ( hasCrsTransformEnabled() )
278273
{
279274
try
280275
{
281-
extent = coordTransform( theLayer )->transformBoundingBox( extent );
276+
if ( const QgsCoordinateTransform* ct = layerTransfrom( theLayer ) )
277+
{
278+
QgsDebugMsg( QString( "sourceCrs = " + ct->sourceCrs().authid() ) );
279+
QgsDebugMsg( QString( "destCRS = " + ct->destCRS().authid() ) );
280+
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
281+
extent = ct->transformBoundingBox( extent );
282+
}
282283
}
283284
catch ( QgsCsException &cse )
284285
{
@@ -294,14 +295,17 @@ QgsRectangle QgsMapSettings::layerExtentToOutputExtent( QgsMapLayer* theLayer, Q
294295

295296
QgsRectangle QgsMapSettings::outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const
296297
{
297-
QgsDebugMsg( QString( "layer sourceCrs = " + coordTransform( theLayer )->sourceCrs().authid() ) );
298-
QgsDebugMsg( QString( "layer destCRS = " + coordTransform( theLayer )->destCRS().authid() ) );
299-
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
300298
if ( hasCrsTransformEnabled() )
301299
{
302300
try
303301
{
304-
extent = coordTransform( theLayer )->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
302+
if ( const QgsCoordinateTransform* ct = layerTransfrom( theLayer ) )
303+
{
304+
QgsDebugMsg( QString( "sourceCrs = " + ct->sourceCrs().authid() ) );
305+
QgsDebugMsg( QString( "destCRS = " + ct->destCRS().authid() ) );
306+
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
307+
extent = ct->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
308+
}
305309
}
306310
catch ( QgsCsException &cse )
307311
{
@@ -321,7 +325,8 @@ QgsPoint QgsMapSettings::layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint
321325
{
322326
try
323327
{
324-
point = coordTransform( theLayer )->transform( point, QgsCoordinateTransform::ForwardTransform );
328+
if ( const QgsCoordinateTransform* ct = layerTransfrom( theLayer ) )
329+
point = ct->transform( point, QgsCoordinateTransform::ForwardTransform );
325330
}
326331
catch ( QgsCsException &cse )
327332
{
@@ -342,7 +347,8 @@ QgsRectangle QgsMapSettings::layerToMapCoordinates( QgsMapLayer* theLayer, QgsRe
342347
{
343348
try
344349
{
345-
rect = coordTransform( theLayer )->transform( rect, QgsCoordinateTransform::ForwardTransform );
350+
if ( const QgsCoordinateTransform* ct = layerTransfrom( theLayer ) )
351+
rect = ct->transform( rect, QgsCoordinateTransform::ForwardTransform );
346352
}
347353
catch ( QgsCsException &cse )
348354
{
@@ -363,7 +369,8 @@ QgsPoint QgsMapSettings::mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint
363369
{
364370
try
365371
{
366-
point = coordTransform( theLayer )->transform( point, QgsCoordinateTransform::ReverseTransform );
372+
if ( const QgsCoordinateTransform* ct = layerTransfrom( theLayer ) )
373+
point = ct->transform( point, QgsCoordinateTransform::ReverseTransform );
367374
}
368375
catch ( QgsCsException &cse )
369376
{
@@ -384,7 +391,8 @@ QgsRectangle QgsMapSettings::mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRe
384391
{
385392
try
386393
{
387-
rect = coordTransform( theLayer )->transform( rect, QgsCoordinateTransform::ReverseTransform );
394+
if ( const QgsCoordinateTransform* ct = layerTransfrom( theLayer ) )
395+
rect = ct->transform( rect, QgsCoordinateTransform::ReverseTransform );
388396
}
389397
catch ( QgsCsException &cse )
390398
{
@@ -489,6 +497,8 @@ void QgsMapSettings::readXML( QDomNode& theNode )
489497
QDomNode extentNode = theNode.namedItem( "extent" );
490498
QgsRectangle aoi = QgsXmlUtils::readRectangle( extentNode.toElement() );
491499
setExtent( aoi );
500+
501+
mDatumTransformStore.readXML( theNode );
492502
}
493503

494504

@@ -510,4 +520,6 @@ void QgsMapSettings::writeXML( QDomNode& theNode, QDomDocument& theDoc )
510520
QDomElement srsNode = theDoc.createElement( "destinationsrs" );
511521
theNode.appendChild( srsNode );
512522
destinationCrs().writeXML( srsNode, theDoc );
523+
524+
mDatumTransformStore.writeXML( theNode, theDoc );
513525
}

‎src/core/qgsmapsettings.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <QStringList>
77

88
#include "qgscoordinatereferencesystem.h"
9+
#include "qgsdatumtransformstore.h"
910
#include "qgsmaptopixel.h"
1011
#include "qgsrectangle.h"
1112
#include "qgsscalecalculator.h"
@@ -95,6 +96,9 @@ class CORE_EXPORT QgsMapSettings
9596

9697
// -- utility functions --
9798

99+
const QgsDatumTransformStore& datumTransformStore() const { return mDatumTransformStore; }
100+
QgsDatumTransformStore& datumTransformStore() { return mDatumTransformStore; }
101+
98102
const QgsMapToPixel& mapToPixel() const { return mMapToPixel; }
99103

100104
/**
@@ -137,6 +141,12 @@ class CORE_EXPORT QgsMapSettings
137141
*/
138142
QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
139143

144+
/**
145+
* @brief Return coordinate transform from layer's CRS to destination CRS
146+
* @param layer
147+
* @return transform - may be null if the transform is not needed
148+
*/
149+
const QgsCoordinateTransform* layerTransfrom( QgsMapLayer *layer ) const;
140150

141151
//! returns current extent of layer set
142152
QgsRectangle fullExtent() const;
@@ -159,6 +169,7 @@ class CORE_EXPORT QgsMapSettings
159169

160170
bool mProjectionsEnabled;
161171
QgsCoordinateReferenceSystem mDestCRS;
172+
QgsDatumTransformStore mDatumTransformStore;
162173

163174
QColor mBackgroundColor;
164175
QColor mSelectionColor;
@@ -178,10 +189,7 @@ class CORE_EXPORT QgsMapSettings
178189
QgsScaleCalculator mScaleCalculator;
179190
QgsMapToPixel mMapToPixel;
180191

181-
182192
void updateDerived();
183-
184-
const QgsCoordinateTransform* coordTransform( QgsMapLayer *layer ) const;
185193
};
186194

187195
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapSettings::Flags )

‎src/gui/layertree/qgslayertreemapcanvasbridge.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,12 @@ void QgsLayerTreeMapCanvasBridge::setCanvasLayers()
112112
else
113113
setCanvasLayers( mRoot, layers );
114114

115-
mCanvas->setLayerSet( layers );
116-
117115
QList<QgsLayerTreeLayer*> layerNodes = mRoot->findLayers();
118-
119116
int currentLayerCount = layerNodes.count();
120-
if ( mAutoSetupOnFirstLayer && mLastLayerCount == 0 && currentLayerCount != 0 )
121-
{
122-
// if we are moving from zero to non-zero layers, let's zoom to those data
123-
mCanvas->zoomToFullExtent();
117+
bool firstLayers = mAutoSetupOnFirstLayer && mLastLayerCount == 0 && currentLayerCount != 0;
124118

119+
if ( firstLayers )
120+
{
125121
// also setup destination CRS and map units if the OTF projections are not yet enabled
126122
if ( !mCanvas->mapSettings().hasCrsTransformEnabled() )
127123
{
@@ -131,11 +127,20 @@ void QgsLayerTreeMapCanvasBridge::setCanvasLayers()
131127
{
132128
mCanvas->setDestinationCrs( layerNode->layer()->crs() );
133129
mCanvas->setMapUnits( layerNode->layer()->crs().mapUnits() );
130+
break;
134131
}
135132
}
136133
}
137134
}
138135

136+
mCanvas->setLayerSet( layers );
137+
138+
if ( firstLayers )
139+
{
140+
// if we are moving from zero to non-zero layers, let's zoom to those data
141+
mCanvas->zoomToFullExtent();
142+
}
143+
139144
if ( !mFirstCRS.isValid() )
140145
{
141146
// find out what is the first used CRS in case we may need to turn on OTF projections later

‎src/gui/qgsdatumtransformdialog.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
QgsDatumTransformDialog::QgsDatumTransformDialog( const QString& layerName, const QList< QList< int > > &dt, QWidget *parent, Qt::WindowFlags f )
2626
: QDialog( parent, f )
2727
, mDt( dt )
28+
, mLayerName( layerName )
2829
{
2930
setupUi( this );
3031

3132
QApplication::setOverrideCursor( Qt::ArrowCursor );
3233

33-
setWindowTitle( tr( "Select datum transformations for layer" ) + " " + layerName );
34+
updateTitle();
3435

3536
QSettings settings;
3637
restoreGeometry( settings.value( "/Windows/DatumTransformDialog/geometry" ).toByteArray() );
@@ -134,6 +135,13 @@ QgsDatumTransformDialog::~QgsDatumTransformDialog()
134135
QApplication::restoreOverrideCursor();
135136
}
136137

138+
void QgsDatumTransformDialog::setDatumTransformInfo( const QString& srcCRSauthId, const QString& destCRSauthId )
139+
{
140+
mSrcCRSauthId = srcCRSauthId;
141+
mDestCRSauthId = destCRSauthId;
142+
updateTitle();
143+
}
144+
137145
QList< int > QgsDatumTransformDialog::selectedDatumTransform()
138146
{
139147
QList<int> list;
@@ -216,3 +224,11 @@ void QgsDatumTransformDialog::on_mHideDeprecatedCheckBox_stateChanged( int )
216224
{
217225
load();
218226
}
227+
228+
void QgsDatumTransformDialog::updateTitle()
229+
{
230+
QString title = tr( "Select datum transformations for layer" ) + " " + mLayerName;
231+
if ( !mSrcCRSauthId.isEmpty() && !mDestCRSauthId.isEmpty() )
232+
title += QString( " (%1 -> %2)" ).arg( mSrcCRSauthId ).arg( mDestCRSauthId );
233+
setWindowTitle( title );
234+
}

‎src/gui/qgsdatumtransformdialog.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class GUI_EXPORT QgsDatumTransformDialog: public QDialog, private Ui::QgsDatumTr
2727
QgsDatumTransformDialog( const QString& layerName, const QList< QList< int > >& dt, QWidget * parent = 0, Qt::WindowFlags f = 0 );
2828
~QgsDatumTransformDialog();
2929

30+
//! @note added in 2.4
31+
void setDatumTransformInfo( const QString& srcCRSauthId, const QString& destCRSauthId );
32+
3033
QList< int > selectedDatumTransform();
3134

3235
bool rememberSelection() const;
@@ -36,12 +39,15 @@ class GUI_EXPORT QgsDatumTransformDialog: public QDialog, private Ui::QgsDatumTr
3639

3740
private:
3841
QgsDatumTransformDialog();
42+
void updateTitle();
3943
bool gridShiftTransformation( const QString& itemText ) const;
4044
/**Returns false if the location of the grid shift files is known (PROJ_LIB) and the shift file is not there*/
4145
bool testGridShiftFileAvailability( QTreeWidgetItem* item, int col ) const;
4246
void load();
4347

4448
const QList< QList< int > > &mDt;
49+
QString mLayerName;
50+
QString mSrcCRSauthId, mDestCRSauthId;
4551
};
4652

4753
#endif // QGSDATUMTRANSFORMDIALOG_H

‎src/gui/qgshighlight.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ void QgsHighlight::init()
8888
{
8989
if ( mMapCanvas->mapSettings().hasCrsTransformEnabled() )
9090
{
91-
// TODO[MD]: after merge - should not use mapRenderer()
92-
const QgsCoordinateTransform* ct = mMapCanvas->mapRenderer()->transformation( mLayer );
91+
const QgsCoordinateTransform* ct = mMapCanvas->mapSettings().layerTransfrom( mLayer );
9392
if ( ct )
9493
{
9594
if ( mGeometry )

‎src/gui/qgsmapcanvas.cpp

100755100644
Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@ QgsMapCanvas::QgsMapCanvas( QWidget * parent, const char *name )
201201
setFocusPolicy( Qt::StrongFocus );
202202

203203
mMapRenderer = new QgsMapRenderer;
204-
connect( mMapRenderer, SIGNAL( datumTransformInfoRequested( const QgsMapLayer*, const QString&, const QString& ) ),
205-
this, SLOT( getDatumTransformInfo( const QgsMapLayer*, const QString& , const QString& ) ) );
206204

207205
mResizeTimer = new QTimer( this );
208206
mResizeTimer->setSingleShot( true );
@@ -423,6 +421,8 @@ void QgsMapCanvas::setLayerSet( QList<QgsMapCanvasLayer> &layers )
423421
}
424422
}
425423

424+
updateDatumTransformEntries();
425+
426426
QgsDebugMsg( "Layers have changed, refreshing" );
427427
emit layersChanged();
428428

@@ -510,6 +510,8 @@ void QgsMapCanvas::setDestinationCrs( const QgsCoordinateReferenceSystem &crs )
510510

511511
mSettings.setDestinationCrs( crs );
512512

513+
updateDatumTransformEntries();
514+
513515
emit destinationCrsChanged();
514516
}
515517

@@ -1551,6 +1553,22 @@ void QgsMapCanvas::connectNotify( const char * signal )
15511553
} //connectNotify
15521554

15531555

1556+
void QgsMapCanvas::updateDatumTransformEntries()
1557+
{
1558+
QString destAuthId = mSettings.destinationCrs().authid();
1559+
foreach ( QString layerID, mSettings.layers() )
1560+
{
1561+
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerID );
1562+
if ( !layer )
1563+
continue;
1564+
1565+
// if there are more options, ask the user which datum transform to use
1566+
if ( !mSettings.datumTransformStore().hasEntryForLayer( layer ) )
1567+
getDatumTransformInfo( layer, layer->crs().authid(), destAuthId );
1568+
}
1569+
}
1570+
1571+
15541572

15551573
QgsMapTool* QgsMapCanvas::mapTool()
15561574
{
@@ -1683,7 +1701,7 @@ void QgsMapCanvas::readProject( const QDomDocument & doc )
16831701
setCrsTransformEnabled( tmpSettings.hasCrsTransformEnabled() );
16841702
setDestinationCrs( tmpSettings.destinationCrs() );
16851703
setExtent( tmpSettings.extent() );
1686-
// TODO: read only units, extent, projections, dest CRS
1704+
mSettings.datumTransformStore() = tmpSettings.datumTransformStore();
16871705

16881706
clearExtentHistory(); // clear the extent history on project load
16891707
}
@@ -1727,6 +1745,7 @@ void QgsMapCanvas::getDatumTransformInfo( const QgsMapLayer* ml, const QString&
17271745
QVariant defaultDestTransform = s.value( settingsString + "_destTransform" );
17281746
if ( defaultSrcTransform.isValid() && defaultDestTransform.isValid() )
17291747
{
1748+
mSettings.datumTransformStore().addEntry( ml->id(), srcAuthId, destAuthId, defaultSrcTransform.toInt(), defaultDestTransform.toInt() );
17301749
mMapRenderer->addLayerCoordinateTransform( ml->id(), srcAuthId, destAuthId, defaultSrcTransform.toInt(), defaultDestTransform.toInt() );
17311750
return;
17321751
}
@@ -1737,6 +1756,7 @@ void QgsMapCanvas::getDatumTransformInfo( const QgsMapLayer* ml, const QString&
17371756
if ( !s.value( "/Projections/showDatumTransformDialog", false ).toBool() )
17381757
{
17391758
// just use the default transform
1759+
mSettings.datumTransformStore().addEntry( ml->id(), srcAuthId, destAuthId, -1, -1 );
17401760
mMapRenderer->addLayerCoordinateTransform( ml->id(), srcAuthId, destAuthId, -1, -1 );
17411761
return;
17421762
}
@@ -1750,7 +1770,8 @@ void QgsMapCanvas::getDatumTransformInfo( const QgsMapLayer* ml, const QString&
17501770

17511771
//if several possibilities: present dialog
17521772
QgsDatumTransformDialog d( ml->name(), dt );
1753-
if ( mMapRenderer && ( d.exec() == QDialog::Accepted ) )
1773+
d.setDatumTransformInfo( srcCRS.authid(), destCRS.authid() );
1774+
if ( d.exec() == QDialog::Accepted )
17541775
{
17551776
int srcTransform = -1;
17561777
int destTransform = -1;
@@ -1763,6 +1784,7 @@ void QgsMapCanvas::getDatumTransformInfo( const QgsMapLayer* ml, const QString&
17631784
{
17641785
destTransform = t.at( 1 );
17651786
}
1787+
mSettings.datumTransformStore().addEntry( ml->id(), srcAuthId, destAuthId, srcTransform, destTransform );
17661788
mMapRenderer->addLayerCoordinateTransform( ml->id(), srcAuthId, destAuthId, srcTransform, destTransform );
17671789
if ( d.rememberSelection() )
17681790
{
@@ -1772,6 +1794,7 @@ void QgsMapCanvas::getDatumTransformInfo( const QgsMapLayer* ml, const QString&
17721794
}
17731795
else
17741796
{
1797+
mSettings.datumTransformStore().addEntry( ml->id(), srcAuthId, destAuthId, -1, -1 );
17751798
mMapRenderer->addLayerCoordinateTransform( ml->id(), srcAuthId, destAuthId, -1, -1 );
17761799
}
17771800
}

‎src/gui/qgsmapcanvas.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
547547
*/
548548
void connectNotify( const char * signal );
549549

550+
//! Make sure the datum transform store is properly populated
551+
void updateDatumTransformEntries();
552+
550553
private:
551554
/// this class is non-copyable
552555
/**
@@ -621,7 +624,6 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
621624
//! Optionally use cache with rendered map layers for the current map settings
622625
QgsMapRendererCache* mCache;
623626

624-
625627
QTimer *mResizeTimer;
626628

627629
QgsPreviewEffect* mPreviewEffect;

0 commit comments

Comments
 (0)
Please sign in to comment.