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/qgis@15208 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Feb 19, 2011
1 parent 65c3543 commit 4d0aaf0
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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ class QgsMapCanvas : QGraphicsView
QgsMapRenderer* mapRenderer(); QgsMapRenderer* mapRenderer();


//! Accessor for the canvas pixmap //! 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 //! Get the last reported scale of the canvas
double scale(); double scale();
Expand Down
3 changes: 2 additions & 1 deletion python/gui/qgsmapcanvasmap.sip
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class QgsMapCanvasMap : QGraphicsRectItem


void setPanningOffset(const QPoint& point); 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*); void paint(QPainter* p, const QStyleOptionGraphicsItem*, QWidget*);


Expand Down
33 changes: 30 additions & 3 deletions src/gui/qgsmapcanvas.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -422,7 +422,11 @@ void QgsMapCanvas::saveAsImage( QString theFileName, QPixmap * theQPixmap, QStri
} }
else //use the map view 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... //create a world file to go with the image...
QgsRectangle myRect = mMapRenderer->extent(); QgsRectangle myRect = mMapRenderer->extent();
Expand Down Expand Up @@ -1232,10 +1236,33 @@ bool QgsMapCanvas::isFrozen()


QPixmap& QgsMapCanvas::canvasPixmap() QPixmap& QgsMapCanvas::canvasPixmap()
{ {
return mMap->pixmap(); QPixmap *pixmap = dynamic_cast<QPixmap *>( &canvasPaintDevice() );
} // canvasPixmap 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 double QgsMapCanvas::mapUnitsPerPixel() const
{ {
Expand Down
6 changes: 5 additions & 1 deletion src/gui/qgsmapcanvas.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
QgsMapRenderer* mapRenderer(); QgsMapRenderer* mapRenderer();


//! Accessor for the canvas pixmap //! 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 //! Get the last reported scale of the canvas
double scale(); double scale();
Expand Down

0 comments on commit 4d0aaf0

Please sign in to comment.