Skip to content
Permalink
Browse files

Map canvas has its QgsMapSettings, moving away from QgsMapRenderer

  • Loading branch information
wonder-sk committed Nov 1, 2013
1 parent f200496 commit ccd40bf0bf52afbb333ae44c027235398dae6698
@@ -2736,11 +2736,7 @@ void QgsLegend::legendLayerZoom()
//transform extent if otf-projection is on
if ( mMapCanvas->hasCrsTransformEnabled() )
{
QgsMapRenderer* renderer = mMapCanvas->mapRenderer();
if ( renderer )
{
extent = renderer->layerExtentToOutputExtent( theLayer, extent );
}
extent = mMapCanvas->mapSettings().layerExtentToOutputExtent( theLayer, extent );
}
}
else if ( li->type() == QgsLegendItem::LEGEND_GROUP )
@@ -2766,11 +2762,7 @@ void QgsLegend::legendLayerZoom()
//transform extent if otf-projection is on
if ( mMapCanvas->hasCrsTransformEnabled() )
{
QgsMapRenderer* renderer = mMapCanvas->mapRenderer();
if ( renderer )
{
layerExtent = renderer->layerExtentToOutputExtent( theLayer, layerExtent );
}
layerExtent = mMapCanvas->mapSettings().layerExtentToOutputExtent( theLayer, layerExtent );
}

if ( i == 0 )
@@ -2847,7 +2839,7 @@ void QgsLegend::legendLayerStretchUsingCurrentExtent()
QgsContrastEnhancement::ContrastEnhancementAlgorithm contrastEnhancementAlgorithm = QgsContrastEnhancement::StretchToMinimumMaximum;

QgsRectangle myRectangle;
myRectangle = mMapCanvas->mapRenderer()->outputExtentToLayerExtent( layer, mMapCanvas->extent() );
myRectangle = mMapCanvas->mapSettings().outputExtentToLayerExtent( layer, mMapCanvas->extent() );
layer->setContrastEnhancement( contrastEnhancementAlgorithm, QgsRaster::ContrastEnhancementMinMax, myRectangle );

layer->setCacheImage( NULL );
@@ -30,7 +30,6 @@ class TestWidget : public QLabel
ms.setExtent(layer->extent());
ms.setOutputSize(i.size());
ms.setOutputDpi(120);
ms.updateDerived();

if (ms.hasValidSettings())
qDebug("map renderer settings valid");
@@ -218,7 +218,7 @@ void QgsSelectedFeature::addError( QgsGeometry::Error e )
if ( e.hasWhere() )
{
QgsVertexMarker *marker = new QgsVertexMarker( mCanvas );
marker->setCenter( mCanvas->mapRenderer()->layerToMapCoordinates( mVlayer, e.where() ) );
marker->setCenter( mCanvas->mapSettings().layerToMapCoordinates( mVlayer, e.where() ) );
marker->setIconType( QgsVertexMarker::ICON_X );
marker->setColor( Qt::green );
marker->setZValue( marker->zValue() + 1 );
@@ -43,7 +43,7 @@ QgsVertexEntry::~QgsVertexEntry()
void QgsVertexEntry::setCenter( QgsPoint p )
{
mPoint = p;
p = mCanvas->mapRenderer()->layerToMapCoordinates( mLayer, p );
p = mCanvas->mapSettings().layerToMapCoordinates( mLayer, p );

if ( mCanvas->extent().contains( p ) )
{
@@ -6893,7 +6893,7 @@ void QgisApp::histogramStretch( bool visibleAreaOnly, QgsRaster::ContrastEnhance

QgsRectangle myRectangle;
if ( visibleAreaOnly )
myRectangle = mMapCanvas->mapRenderer()->outputExtentToLayerExtent( myRasterLayer, mMapCanvas->extent() );
myRectangle = mMapCanvas->mapSettings().outputExtentToLayerExtent( myRasterLayer, mMapCanvas->extent() );

myRasterLayer->setContrastEnhancement( QgsContrastEnhancement::StretchToMinimumMaximum, theLimits, myRectangle );

@@ -1207,7 +1207,7 @@ void QgsIdentifyResultsDialog::zoomToFeature()
}

// TODO: verify CRS for raster WMS features
QgsRectangle rect = mCanvas->mapRenderer()->layerExtentToOutputExtent( layer, feat.geometry()->boundingBox() );
QgsRectangle rect = mapSettings().layerExtentToOutputExtent( layer, feat.geometry()->boundingBox() );

if ( rect.isEmpty() )
{
@@ -387,7 +387,7 @@ void QgsMapToolCapture::addError( QgsGeometry::Error e )
if ( e.hasWhere() )
{
QgsVertexMarker *vm = new QgsVertexMarker( mCanvas );
vm->setCenter( mCanvas->mapRenderer()->layerToMapCoordinates( vlayer, e.where() ) );
vm->setCenter( mCanvas->mapSettings().layerToMapCoordinates( vlayer, e.where() ) );
vm->setIconType( QgsVertexMarker::ICON_X );
vm->setPenWidth( 2 );
vm->setToolTip( e.what() );
@@ -126,10 +126,10 @@ void QgsMapToolMoveLabel::canvasReleaseEvent( QMouseEvent * e )
else
{
//transform to map crs first, because xdiff,ydiff are in map coordinates
QgsMapRenderer* r = mCanvas->mapRenderer();
if ( r && r->hasCrsTransformEnabled() )
const QgsMapSettings& ms = mCanvas->mapSettings();
if ( ms->hasCrsTransformEnabled() )
{
QgsPoint transformedPoint = r->layerToMapCoordinates( vlayer, QgsPoint( xPosOrig, yPosOrig ) );
QgsPoint transformedPoint = ms.layerToMapCoordinates( vlayer, QgsPoint( xPosOrig, yPosOrig ) );
xPosOrig = transformedPoint.x();
yPosOrig = transformedPoint.y();
}
@@ -140,10 +140,10 @@ void QgsMapToolMoveLabel::canvasReleaseEvent( QMouseEvent * e )
//transform back to layer crs
if ( mCanvas )
{
QgsMapRenderer* r = mCanvas->mapRenderer();
if ( r && r->hasCrsTransformEnabled() )
const QgsMapSettings& s = mCanvas->mapSettings();
if ( s.hasCrsTransformEnabled() )
{
QgsPoint transformedPoint = r->mapToLayerCoordinates( vlayer, QgsPoint( xPosNew, yPosNew ) );
QgsPoint transformedPoint = s.mapToLayerCoordinates( vlayer, QgsPoint( xPosNew, yPosNew ) );
xPosNew = transformedPoint.x();
yPosNew = transformedPoint.y();
}
@@ -32,7 +32,6 @@

QgsMapToolPinLabels::QgsMapToolPinLabels( QgsMapCanvas* canvas ): QgsMapToolLabel( canvas )
{
mRender = 0;
mRubberBand = 0;
mShowPinned = false;

@@ -145,13 +144,14 @@ void QgsMapToolPinLabels::highlightLabel( QgsVectorLayer* vlayer,
{
QgsRectangle rect = labelpos.labelRect;

if ( vlayer->crs().isValid() && mRender->destinationCrs().isValid() )
const QgsMapSettings& ms = mCanvas->mapSettings();
if ( vlayer->crs().isValid() && ms.destinationCrs().isValid() )
{
// if label's layer is on-fly transformed, reverse-transform label rect
// QgsHighlight will convert it, yet again, to the correct map coords
if ( vlayer->crs() != mRender->destinationCrs() )
if ( vlayer->crs() != ms.destinationCrs() )
{
rect = mRender->mapToLayerCoordinates( vlayer, rect );
rect = ms.mapToLayerCoordinates( vlayer, rect );
QgsDebugMsg( QString( "Reverse transform needed for highlight rectangle" ) );
}
}
@@ -178,20 +178,10 @@ void QgsMapToolPinLabels::highlightPinnedLabels()
return;
}

if ( mCanvas )
{
mRender = mCanvas->mapRenderer();
if ( !mRender )
{
QgsDebugMsg( QString( "Failed to acquire map renderer" ) );
return;
}
}

QgsDebugMsg( QString( "Highlighting pinned labels" ) );

// get list of all drawn labels from all layers within given extent
QgsPalLabeling* labelEngine = dynamic_cast<QgsPalLabeling*>( mRender->labelingEngine() );
QgsPalLabeling* labelEngine = dynamic_cast<QgsPalLabeling*>( mCanvas->mapRenderer()->labelingEngine() );
if ( !labelEngine )
{
QgsDebugMsg( QString( "No labeling engine" ) );
@@ -262,17 +252,7 @@ void QgsMapToolPinLabels::pinUnpinLabels( const QgsRectangle& ext, QMouseEvent *
// get list of all drawn labels from all layers within, or touching, chosen extent
bool labelChanged = false;

if ( mCanvas )
{
mRender = mCanvas->mapRenderer();
if ( !mRender )
{
QgsDebugMsg( QString( "Failed to acquire map renderer" ) );
return;
}
}

QgsPalLabeling* labelEngine = dynamic_cast<QgsPalLabeling*>( mRender->labelingEngine() );
QgsPalLabeling* labelEngine = dynamic_cast<QgsPalLabeling*>( mCanvas->mapRenderer()->labelingEngine() );
if ( !labelEngine )
{
QgsDebugMsg( QString( "No labeling engine" ) );
@@ -410,9 +390,9 @@ bool QgsMapToolPinLabels::pinUnpinLabel( QgsVectorLayer* vlayer,
double labelR = labelpos.rotation * 180 / M_PI;

// transform back to layer crs, if on-fly on
if ( mRender->hasCrsTransformEnabled() )
if ( mCanvas->mapSettings().hasCrsTransformEnabled() )
{
QgsPoint transformedPoint = mRender->mapToLayerCoordinates( vlayer, referencePoint );
QgsPoint transformedPoint = mCanvas->mapSettings().mapToLayerCoordinates( vlayer, referencePoint );
labelX = transformedPoint.x();
labelY = transformedPoint.y();
}
@@ -79,9 +79,6 @@ class APP_EXPORT QgsMapToolPinLabels: public QgsMapToolLabel

private:

//! Pointer to map renderer
QgsMapRenderer* mRender;

//! Highlights a given label relative to whether its pinned and editable
void highlightLabel( QgsVectorLayer* vlayer,
const QgsLabelPosition& labelpos,
@@ -520,7 +520,7 @@ void QgsRasterLayerProperties::setRendererWidget( const QString& rendererName )
{
QgsDebugMsg( "renderer has widgetCreateFunction" );
// Current canvas extent (used to calc min/max) in layer CRS
QgsRectangle myExtent = mMapCanvas->mapRenderer()->outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
QgsRectangle myExtent = mMapCanvas->mapSettings().outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
mRendererWidget = ( *rendererEntry.widgetCreateFunction )( mRasterLayer, myExtent );
mRendererStackedWidget->addWidget( mRendererWidget );
if ( oldWidget )
@@ -1461,9 +1461,10 @@ void QgsRasterLayerProperties::pixelSelected( const QgsPoint& canvasPoint )
{
mMapCanvas->unsetMapTool( mPixelSelectorTool );

QgsPoint myPoint = mMapCanvas->mapRenderer()->mapToLayerCoordinates( mRasterLayer, canvasPoint );
const QgsMapSettings& ms = mMapCanvas->mapSettings();
QgsPoint myPoint = ms.mapToLayerCoordinates( mRasterLayer, canvasPoint );

QgsRectangle myExtent = mMapCanvas->mapRenderer()->mapToLayerCoordinates( mRasterLayer, mMapCanvas->extent() );
QgsRectangle myExtent = ms.mapToLayerCoordinates( mRasterLayer, mMapCanvas->extent() );
double mapUnitsPerPixel = mMapCanvas->mapUnitsPerPixel();
int myWidth = mMapCanvas->extent().width() / mapUnitsPerPixel;
int myHeight = mMapCanvas->extent().height() / mapUnitsPerPixel;
@@ -219,7 +219,7 @@ void QgsMapRendererCustomPainterJob::startRender()
// cache painter
QPainter * mypContextPainter = mRenderContext.painter();
// Flattened image for drawing when a blending mode is set
QImage * mypFlattenedImage = 0;
//QImage * mypFlattenedImage = 0;

QString layerId = li.previous();

0 comments on commit ccd40bf

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