Skip to content
Permalink
Browse files

Added utility functions to QgsMapSettings

  • Loading branch information
wonder-sk committed Oct 31, 2013
1 parent 159f135 commit f2004962bcea8ab011b55a62583ce83baacf7e01
@@ -6,7 +6,7 @@
#include <QTimer>
#include <QMouseEvent>

#include "qgsmaprendererv2.h"
#include "qgsmapsettings.h"
#include "qgsmaplayer.h"

#include "qgsmaprendererjob.h"
@@ -94,10 +94,10 @@ void QgsMapToolLabel::createRubberBands( )
{
if ( mCanvas )
{
QgsMapRenderer* r = mCanvas->mapRenderer();
if ( r && r->hasCrsTransformEnabled() )
const QgsMapSettings& s = mCanvas->mapSettings();
if ( s.hasCrsTransformEnabled() )
{
fixPoint = r->mapToLayerCoordinates( vlayer, fixPoint );
fixPoint = s.mapToLayerCoordinates( vlayer, fixPoint );
}
}

@@ -3,7 +3,7 @@

SET(QGIS_CORE_SRCS

qgsmaprendererv2.cpp
qgsmapsettings.cpp
qgsmaprendererjob.cpp

gps/qgsgpsconnection.cpp
@@ -297,7 +297,7 @@ ADD_BISON_FILES(QGIS_CORE_SRCS qgsexpressionparser.yy)

SET(QGIS_CORE_MOC_HDRS

qgsmaprendererv2.h
qgsmapsettings.h
qgsmaprendererjob.h

qgsapplication.h
@@ -6,7 +6,7 @@

#include "qgsrendercontext.h"

#include "qgsmaprendererv2.h"
#include "qgsmapsettings.h"

/** abstract base class renderer jobs that asynchronously start map rendering */
class QgsMapRendererJob : public QObject
@@ -109,7 +109,6 @@ class QgsMapRendererCustomPainterJob : public QgsMapRendererJob

virtual void start();
virtual void cancel();
//virtual QImage renderedImage();

protected slots:
void futureFinished();

This file was deleted.

@@ -1,11 +1,15 @@

#include "qgsmaprendererv2.h"
#include "qgsmapsettings.h"

#include "qgsscalecalculator.h"
#include "qgsmaprendererjob.h"
#include "qgsmaptopixel.h"
#include "qgslogger.h"

#include "qgscrscache.h"
#include "qgsmessagelog.h"
#include "qgsmaplayer.h"

/*
usage in QgsMapCanvas - upon pan / zoom - in QgsMapCanvasMap:
@@ -155,6 +159,16 @@ void QgsMapSettings::setLayers(const QStringList& layers)
mLayers = layers;
}

void QgsMapSettings::setProjectionsEnabled( bool enabled )
{
mProjectionsEnabled = enabled;
}

bool QgsMapSettings::hasCrsTransformEnabled() const
{
return mProjectionsEnabled;
}


bool QgsMapSettings::hasValidSettings() const
{
@@ -175,3 +189,143 @@ double QgsMapSettings::scale() const
{
return mScale;
}





const QgsCoordinateTransform* QgsMapSettings::coordTransform( QgsMapLayer *layer )
{
if ( !layer )
{
return 0;
}
return QgsCoordinateTransformCache::instance()->transform( layer->crs().authid(), mDestCRS.authid() );
}



QgsRectangle QgsMapSettings::layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent )
{
QgsDebugMsg( QString( "sourceCrs = " + coordTransform( theLayer )->sourceCrs().authid() ) );
QgsDebugMsg( QString( "destCRS = " + coordTransform( theLayer )->destCRS().authid() ) );
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
if ( hasCrsTransformEnabled() )
{
try
{
extent = coordTransform( theLayer )->transformBoundingBox( extent );
}
catch ( QgsCsException &cse )
{
QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
}
}

QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );

return extent;
}


QgsRectangle QgsMapSettings::outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent )
{
QgsDebugMsg( QString( "layer sourceCrs = " + coordTransform( theLayer )->sourceCrs().authid() ) );
QgsDebugMsg( QString( "layer destCRS = " + coordTransform( theLayer )->destCRS().authid() ) );
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
if ( hasCrsTransformEnabled() )
{
try
{
extent = coordTransform( theLayer )->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
}
catch ( QgsCsException &cse )
{
QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
}
}

QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );

return extent;
}


QgsPoint QgsMapSettings::layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point )
{
if ( hasCrsTransformEnabled() )
{
try
{
point = coordTransform( theLayer )->transform( point, QgsCoordinateTransform::ForwardTransform );
}
catch ( QgsCsException &cse )
{
QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
}
}
else
{
// leave point without transformation
}
return point;
}


QgsRectangle QgsMapSettings::layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect )
{
if ( hasCrsTransformEnabled() )
{
try
{
rect = coordTransform( theLayer )->transform( rect, QgsCoordinateTransform::ForwardTransform );
}
catch ( QgsCsException &cse )
{
QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
}
}
else
{
// leave point without transformation
}
return rect;
}


QgsPoint QgsMapSettings::mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point )
{
if ( hasCrsTransformEnabled() )
{
try
{
point = coordTransform( theLayer )->transform( point, QgsCoordinateTransform::ReverseTransform );
}
catch ( QgsCsException &cse )
{
QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
}
}
else
{
// leave point without transformation
}
return point;
}


QgsRectangle QgsMapSettings::mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect )
{
if ( hasCrsTransformEnabled() )
{
try
{
rect = coordTransform( theLayer )->transform( rect, QgsCoordinateTransform::ReverseTransform );
}
catch ( QgsCsException &cse )
{
QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ), "CRS" );
}
}
return rect;
}

0 comments on commit f200496

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