Skip to content

Commit 86b6c5b

Browse files
committedNov 11, 2013
don't crash when transforming between the same CRSes and update map renderer sip bindings
1 parent 7c98970 commit 86b6c5b

File tree

2 files changed

+53
-14
lines changed

2 files changed

+53
-14
lines changed
 

‎python/core/qgsmaprenderer.sip

+23-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ class QgsLabelingEngineInterface
7272
virtual QgsLabelingEngineInterface* clone() = 0 /Factory/;
7373
};
7474

75-
75+
struct QgsLayerCoordinateTransform
76+
{
77+
QString srcAuthId;
78+
QString destAuthId;
79+
int srcDatumTransform; //-1 if unknown or not specified
80+
int destDatumTransform;
81+
};
7682

7783
/** \ingroup core
7884
* A non GUI class for rendering a map layer set onto a QPainter.
@@ -132,6 +138,7 @@ class QgsMapRenderer : QObject
132138

133139
const QgsMapToPixel* coordinateTransform();
134140

141+
//! Scale denominator
135142
double scale() const;
136143
/**Sets scale for scale based visibility. Normally, the scale is calculated automatically. This
137144
function is only used to force a preview scale (e.g. for print composer)*/
@@ -159,7 +166,7 @@ class QgsMapRenderer : QObject
159166
QSize outputSize();
160167
QSizeF outputSizeF();
161168

162-
/**
169+
/**
163170
* @brief transform bounding box from layer's CRS to output CRS
164171
* @see layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) if you want to transform a rectangle
165172
* @return a bounding box (aligned rectangle) containing the transformed extent
@@ -206,7 +213,7 @@ class QgsMapRenderer : QObject
206213
bool hasCrsTransformEnabled() const;
207214

208215
//! sets destination coordinate reference system
209-
void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
216+
void setDestinationCrs( const QgsCoordinateReferenceSystem& crs, bool refreshCoordinateTransformInfo = true );
210217

211218
//! returns CRS of destination coordinate reference system
212219
const QgsCoordinateReferenceSystem& destinationCrs() const;
@@ -245,6 +252,16 @@ class QgsMapRenderer : QObject
245252
//! Added in QGIS v1.4
246253
void setLabelingEngine( QgsLabelingEngineInterface* iface /Transfer/ );
247254

255+
//! Returns a QPainter::CompositionMode corresponding to a BlendMode
256+
//! Added in 1.9
257+
static QPainter::CompositionMode getCompositionMode( const QgsMapRenderer::BlendMode blendMode );
258+
//! Returns a BlendMode corresponding to a QPainter::CompositionMode
259+
//! Added in 1.9
260+
static QgsMapRenderer::BlendMode getBlendModeEnum( const QPainter::CompositionMode blendMode );
261+
262+
void addLayerCoordinateTransform( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform = -1, int destDatumTransform = -1 );
263+
void clearLayerCoordinateTransforms();
264+
248265
const QgsCoordinateTransform* transformation( const QgsMapLayer *layer ) const;
249266

250267
signals:
@@ -262,6 +279,9 @@ class QgsMapRenderer : QObject
262279
//! emitted when layer's draw() returned false
263280
void drawError( QgsMapLayer* );
264281

282+
//! Notifies higher level components to show the datum transform dialog and add a QgsLayerCoordinateTransformInfo for that layer
283+
void datumTransformInfoRequested( const QgsMapLayer* ml, const QString& srcAuthId, const QString& destAuthId ) const;
284+
265285
public slots:
266286

267287
//! called by signal from layer current being drawn

‎src/core/qgsmaprenderer.cpp

+30-11
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
261261

262262
mDrawing = true;
263263

264-
const QgsCoordinateTransform* ct;
264+
const QgsCoordinateTransform *ct;
265265

266266
#ifdef QGISDEBUG
267267
QgsDebugMsg( "Starting to render layer stack." );
@@ -794,7 +794,7 @@ bool QgsMapRenderer::splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent
794794
// extent separately.
795795
static const double splitCoord = 180.0;
796796

797-
const QgsCoordinateTransform* transform = transformation( layer );
797+
const QgsCoordinateTransform *transform = transformation( layer );
798798
if ( layer->crs().geographicFlag() )
799799
{
800800
// Note: ll = lower left point
@@ -848,7 +848,7 @@ QgsRectangle QgsMapRenderer::layerExtentToOutputExtent( QgsMapLayer* theLayer, Q
848848
{
849849
try
850850
{
851-
const QgsCoordinateTransform* transform = transformation( theLayer );
851+
const QgsCoordinateTransform *transform = transformation( theLayer );
852852
if ( transform )
853853
{
854854
extent = transform->transformBoundingBox( extent );
@@ -867,14 +867,21 @@ QgsRectangle QgsMapRenderer::layerExtentToOutputExtent( QgsMapLayer* theLayer, Q
867867

868868
QgsRectangle QgsMapRenderer::outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent )
869869
{
870-
QgsDebugMsg( QString( "layer sourceCrs = " + transformation( theLayer )->sourceCrs().authid() ) );
871-
QgsDebugMsg( QString( "layer destCRS = " + transformation( theLayer )->destCRS().authid() ) );
870+
#if QGISDEBUG
871+
const QgsCoordinateTransform *transform = transformation( theLayer );
872+
QgsDebugMsg( QString( "layer sourceCrs = " + ( transform ? transform->sourceCrs().authid() : "none" ) ) );
873+
QgsDebugMsg( QString( "layer destCRS = " + ( transform ? transform->destCRS().authid() : "none" ) ) );
872874
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
875+
#endif
873876
if ( hasCrsTransformEnabled() )
874877
{
875878
try
876879
{
877-
extent = transformation( theLayer )->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
880+
const QgsCoordinateTransform *transform = transformation( theLayer );
881+
if ( transform )
882+
{
883+
extent = transform->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
884+
}
878885
}
879886
catch ( QgsCsException &cse )
880887
{
@@ -893,7 +900,11 @@ QgsPoint QgsMapRenderer::layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint
893900
{
894901
try
895902
{
896-
point = transformation( theLayer )->transform( point, QgsCoordinateTransform::ForwardTransform );
903+
const QgsCoordinateTransform *transform = transformation( theLayer );
904+
if ( transform )
905+
{
906+
point = transform->transform( point, QgsCoordinateTransform::ForwardTransform );
907+
}
897908
}
898909
catch ( QgsCsException &cse )
899910
{
@@ -913,7 +924,11 @@ QgsRectangle QgsMapRenderer::layerToMapCoordinates( QgsMapLayer* theLayer, QgsRe
913924
{
914925
try
915926
{
916-
rect = transformation( theLayer )->transform( rect, QgsCoordinateTransform::ForwardTransform );
927+
const QgsCoordinateTransform *transform = transformation( theLayer );
928+
if ( transform )
929+
{
930+
rect = transform->transform( rect, QgsCoordinateTransform::ForwardTransform );
931+
}
917932
}
918933
catch ( QgsCsException &cse )
919934
{
@@ -933,7 +948,9 @@ QgsPoint QgsMapRenderer::mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint
933948
{
934949
try
935950
{
936-
point = transformation( theLayer )->transform( point, QgsCoordinateTransform::ReverseTransform );
951+
const QgsCoordinateTransform *transform = transformation( theLayer );
952+
if ( transform )
953+
point = transform->transform( point, QgsCoordinateTransform::ReverseTransform );
937954
}
938955
catch ( QgsCsException &cse )
939956
{
@@ -953,7 +970,9 @@ QgsRectangle QgsMapRenderer::mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRe
953970
{
954971
try
955972
{
956-
rect = transformation( theLayer )->transform( rect, QgsCoordinateTransform::ReverseTransform );
973+
const QgsCoordinateTransform *transform = transformation( theLayer );
974+
if ( transform )
975+
rect = transform->transform( rect, QgsCoordinateTransform::ReverseTransform );
957976
}
958977
catch ( QgsCsException &cse )
959978
{
@@ -1245,7 +1264,7 @@ void QgsMapRenderer::setLabelingEngine( QgsLabelingEngineInterface* iface )
12451264
mLabelingEngine = iface;
12461265
}
12471266

1248-
const QgsCoordinateTransform* QgsMapRenderer::transformation( const QgsMapLayer *layer ) const
1267+
const QgsCoordinateTransform *QgsMapRenderer::transformation( const QgsMapLayer *layer ) const
12491268
{
12501269
if ( !layer || !mDestCRS )
12511270
{

0 commit comments

Comments
 (0)
Please sign in to comment.