Skip to content
Permalink
Browse files

Store relation between layer and coordinate transform in maprenderer …

…class
  • Loading branch information
mhugent committed Oct 18, 2013
1 parent 39fd5b8 commit 7612e12702ba03c0c1a030a7b18803911bca6b8a
Showing with 105 additions and 3 deletions.
  1. +91 −2 src/core/qgsmaprenderer.cpp
  2. +14 −1 src/core/qgsmaprenderer.h
@@ -412,7 +412,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
{
r1 = mExtent;
split = splitLayersExtent( ml, r1, r2 );
ct = QgsCoordinateTransformCache::instance()->transform( ml->crs().authid(), mDestCRS->authid() );
ct = tr( ml );
mRenderContext.setExtent( r1 );
QgsDebugMsg( " extent 1: " + r1.toString() );
QgsDebugMsg( " extent 2: " + r2.toString() );
@@ -742,6 +742,8 @@ void QgsMapRenderer::setDestinationCrs( const QgsCoordinateReferenceSystem& crs
QgsDebugMsg( "* DestCRS.srsid() = " + QString::number( crs.srsid() ) );
if ( *mDestCRS != crs )
{
mLayerCoordinateTransformInfo.clear();

QgsRectangle rect;
if ( !mExtent.isEmpty() )
{
@@ -1026,6 +1028,27 @@ void QgsMapRenderer::setLayerSet( const QStringList& layers )
{
QgsDebugMsg( QString( "Entering: %1" ).arg( layers.join( ", " ) ) );
mLayerSet = layers;

//remove all entries in mLayerCoordinateTransformInfo which are not part of the layer set
if ( mLayerCoordinateTransformInfo.size() > 0 )
{
QSet<QString> layerSet = layers.toSet();
QStringList removeEntries;
QHash< QString, QgsLayerCoordinateTransform >::const_iterator lctIt = mLayerCoordinateTransformInfo.constBegin();
for ( ; lctIt != mLayerCoordinateTransformInfo.constEnd(); ++lctIt )
{
if ( !layerSet.contains( lctIt.key() ) )
{
removeEntries.push_back( lctIt.key() );
}
}

QStringList::const_iterator rIt = removeEntries.constBegin();
for ( ; rIt != removeEntries.constEnd(); ++rIt )
{
mLayerCoordinateTransformInfo.remove( *rIt );
}
}
updateFullExtent();
}

@@ -1101,6 +1124,31 @@ bool QgsMapRenderer::readXML( QDomNode & theNode )
aoi.setYMaximum( ymax );

setExtent( aoi );

mLayerCoordinateTransformInfo.clear();
QDomElement layerCoordTransformInfoElem = theNode.firstChildElement( "layer_coordinate_transform_info" );
if ( !layerCoordTransformInfoElem.isNull() )
{
QDomNodeList layerCoordinateTransformList = layerCoordTransformInfoElem.elementsByTagName( "layer_coordinate_transform" );
QDomElement layerCoordTransformElem;
for ( int i = 0; i < layerCoordinateTransformList.size(); ++i )
{
layerCoordTransformElem = layerCoordinateTransformList.at( i ).toElement();
QString layerId = layerCoordTransformElem.attribute( "layerid" );
if ( layerId.isEmpty() )
{
continue;
}

QgsLayerCoordinateTransform lct;
lct.srcAuthId = layerCoordTransformElem.attribute( "srcAuthId" );
lct.destAuthId = layerCoordTransformElem.attribute( "destAuthId" );
lct.srcDatumTransform = layerCoordTransformElem.attribute( "srcDatumTransform", "-1" ).toInt();
lct.destDatumTransform = layerCoordTransformElem.attribute( "destDatumTransform", "-1" ).toInt();
mLayerCoordinateTransformInfo.insert( layerId, lct );
}
}

return true;
}

@@ -1170,6 +1218,20 @@ bool QgsMapRenderer::writeXML( QDomNode & theNode, QDomDocument & theDoc )
theNode.appendChild( srsNode );
destinationCrs().writeXML( srsNode, theDoc );

// layer coordinate transform infos
QDomElement layerCoordTransformInfo = theDoc.createElement( "layer_coordinate_transform_info" );
QHash< QString, QgsLayerCoordinateTransform >::const_iterator coordIt = mLayerCoordinateTransformInfo.constBegin();
for ( ; coordIt != mLayerCoordinateTransformInfo.constEnd(); ++coordIt )
{
QDomElement layerCoordTransformElem = theDoc.createElement( "layer_coordinate_transform" );
layerCoordTransformElem.setAttribute( "layerid", coordIt.key() );
layerCoordTransformElem.setAttribute( "srcAuthId", coordIt->srcAuthId );
layerCoordTransformElem.setAttribute( "destAuthId", coordIt->destAuthId );
layerCoordTransformElem.setAttribute( "srcDatumTransform", QString::number( coordIt->srcDatumTransform ) );
layerCoordTransformElem.setAttribute( "destDatumTransform", QString::number( coordIt->destDatumTransform ) );
layerCoordTransformInfo.appendChild( layerCoordTransformElem );
}
theNode.appendChild( layerCoordTransformInfo );
return true;
}

@@ -1187,7 +1249,24 @@ const QgsCoordinateTransform* QgsMapRenderer::tr( QgsMapLayer *layer )
{
return 0;
}
return QgsCoordinateTransformCache::instance()->transform( layer->crs().authid(), mDestCRS->authid() );

QHash< QString, QgsLayerCoordinateTransform >::const_iterator ctIt = mLayerCoordinateTransformInfo.find( layer->id() );
if ( ctIt != mLayerCoordinateTransformInfo.constEnd() )
{
return QgsCoordinateTransformCache::instance()->transform( ctIt->srcAuthId, ctIt->destAuthId, ctIt->srcDatumTransform, ctIt->destDatumTransform );
}
else
{
emit datumTransformInfoRequested( layer, layer->crs().authid(), mDestCRS->authid() );
}

//still not present? get coordinate transformation with -1/-1 datum transform as default
ctIt = mLayerCoordinateTransformInfo.find( layer->id() );
if ( ctIt == mLayerCoordinateTransformInfo.constEnd() )
{
return QgsCoordinateTransformCache::instance()->transform( layer->crs().authid(), mDestCRS->authid(), -1, -1 );
}
return QgsCoordinateTransformCache::instance()->transform( ctIt->srcAuthId, ctIt->destAuthId, ctIt->srcDatumTransform, ctIt->destDatumTransform );
}

/** Returns a QPainter::CompositionMode corresponding to a QgsMapRenderer::BlendMode
@@ -1264,4 +1343,14 @@ QgsMapRenderer::BlendMode QgsMapRenderer::getBlendModeEnum( const QPainter::Comp
}
}

void QgsMapRenderer::addLayerCoordinateTransform( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform, int destDatumTransform )
{
QgsLayerCoordinateTransform lt;
lt.srcAuthId = srcAuthId;
lt.destAuthId = destAuthId;
lt.srcDatumTransform = srcDatumTransform;
lt.destDatumTransform = destDatumTransform;
mLayerCoordinateTransformInfo.insert( layerId, lt );
}

bool QgsMapRenderer::mDrawing = false;
@@ -110,7 +110,13 @@ class CORE_EXPORT QgsLabelingEngineInterface
virtual QgsLabelingEngineInterface* clone() = 0;
};


struct CORE_EXPORT QgsLayerCoordinateTransform
{
QString srcAuthId;
QString destAuthId;
int srcDatumTransform; //-1 if unknown or not specified
int destDatumTransform;
};

/** \ingroup core
* A non GUI class for rendering a map layer set onto a QPainter.
@@ -289,6 +295,8 @@ class CORE_EXPORT QgsMapRenderer : public QObject
//! Added in 1.9
static QgsMapRenderer::BlendMode getBlendModeEnum( const QPainter::CompositionMode blendMode );

void addLayerCoordinateTransform( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform = -1, int destDatumTransform = -1 );

signals:

void drawingProgress( int current, int total );
@@ -304,6 +312,9 @@ class CORE_EXPORT QgsMapRenderer : public QObject
//! emitted when layer's draw() returned false
void drawError( QgsMapLayer* );

//! Notifies higher level components to show the datum transform dialog and add a QgsLayerCoordinateTransformInfo for that layer
void datumTransformInfoRequested( QgsMapLayer* ml, const QString& srcAuthId, const QString& destAuthId );

public slots:

//! called by signal from layer current being drawn
@@ -376,6 +387,8 @@ class CORE_EXPORT QgsMapRenderer : public QObject
//! Locks rendering loop for concurrent draws
QMutex mRenderMutex;

QHash< QString, QgsLayerCoordinateTransform > mLayerCoordinateTransformInfo;

private:
const QgsCoordinateTransform* tr( QgsMapLayer *layer );
};

0 comments on commit 7612e12

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