Navigation Menu

Skip to content

Commit

Permalink
deprecate QgsMapCanvas::pixmap() following QgsMapCanvasMap::pixmap()
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@15208 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Feb 19, 2011
1 parent 9eac944 commit 5682341
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
6 changes: 5 additions & 1 deletion python/gui/qgsmapcanvas.sip
Expand Up @@ -65,7 +65,11 @@ class QgsMapCanvas : QGraphicsView
QgsMapRenderer* mapRenderer();

//! Accessor for the canvas pixmap
QPixmap& canvasPixmap();
// @deprecated use canvasPaintDevice()
QPixmap& canvasPixmap() /Deprecated/;

//! Accessor for the canvas paint device
QPaintDevice &canvasPaintDevice();

//! Get the last reported scale of the canvas
double scale();
Expand Down
3 changes: 2 additions & 1 deletion python/gui/qgsmapcanvasmap.sip
Expand Up @@ -42,7 +42,8 @@ class QgsMapCanvasMap : QGraphicsRectItem

void setPanningOffset(const QPoint& point);

QPixmap& pixmap();
//! @deprecated Please use paintDevice() function which is also save in case QImage is used
QPixmap& pixmap() /Deprecated/;

void paint(QPainter* p, const QStyleOptionGraphicsItem*, QWidget*);

Expand Down
33 changes: 30 additions & 3 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -422,7 +422,11 @@ void QgsMapCanvas::saveAsImage( QString theFileName, QPixmap * theQPixmap, QStri
}
else //use the map view
{
mMap->pixmap().save( theFileName, theFormat.toLocal8Bit().data() );
QPixmap *pixmap = dynamic_cast<QPixmap *>( &mMap->paintDevice() );
if( !pixmap )
return;

pixmap->save( theFileName, theFormat.toLocal8Bit().data() );
}
//create a world file to go with the image...
QgsRectangle myRect = mMapRenderer->extent();
Expand Down Expand Up @@ -1232,10 +1236,33 @@ bool QgsMapCanvas::isFrozen()

QPixmap& QgsMapCanvas::canvasPixmap()
{
return mMap->pixmap();
} // canvasPixmap
QPixmap *pixmap = dynamic_cast<QPixmap *>( &canvasPaintDevice() );
if( pixmap )
{
return *pixmap;
}

qWarning( "QgsMapCanvas::canvasPixmap() deprecated - returning static pixmap instance - use QgsMapCanvas::paintDevice()" );

static QPixmap staticPixmap;

QImage *image = dynamic_cast<QImage *>( &mMap->paintDevice() );
if( image )
{
staticPixmap = QPixmap::fromImage( *image );
}
else
{
staticPixmap = QPixmap( canvasPaintDevice().width(), canvasPaintDevice().height() );
}

return staticPixmap;
} // canvasPixmap

QPaintDevice &QgsMapCanvas::canvasPaintDevice()
{
return mMap->paintDevice();
}

double QgsMapCanvas::mapUnitsPerPixel() const
{
Expand Down
6 changes: 5 additions & 1 deletion src/gui/qgsmapcanvas.h
Expand Up @@ -119,7 +119,11 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
QgsMapRenderer* mapRenderer();

//! Accessor for the canvas pixmap
QPixmap& canvasPixmap();
//! @deprecated use canvasPaintDevice()
QGISDEPRECATED QPixmap& canvasPixmap();

//! Accessor for the canvas paint device
QPaintDevice &canvasPaintDevice();

//! Get the last reported scale of the canvas
double scale();
Expand Down

0 comments on commit 5682341

Please sign in to comment.