Skip to content

Commit 5682341

Browse files
author
jef
committed
deprecate QgsMapCanvas::pixmap() following QgsMapCanvasMap::pixmap()
git-svn-id: http://svn.osgeo.org/qgis/trunk@15208 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 9eac944 commit 5682341

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

python/gui/qgsmapcanvas.sip

+5-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ class QgsMapCanvas : QGraphicsView
6565
QgsMapRenderer* mapRenderer();
6666

6767
//! Accessor for the canvas pixmap
68-
QPixmap& canvasPixmap();
68+
// @deprecated use canvasPaintDevice()
69+
QPixmap& canvasPixmap() /Deprecated/;
70+
71+
//! Accessor for the canvas paint device
72+
QPaintDevice &canvasPaintDevice();
6973

7074
//! Get the last reported scale of the canvas
7175
double scale();

python/gui/qgsmapcanvasmap.sip

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class QgsMapCanvasMap : QGraphicsRectItem
4242

4343
void setPanningOffset(const QPoint& point);
4444

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

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

src/gui/qgsmapcanvas.cpp

+30-3
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,11 @@ void QgsMapCanvas::saveAsImage( QString theFileName, QPixmap * theQPixmap, QStri
422422
}
423423
else //use the map view
424424
{
425-
mMap->pixmap().save( theFileName, theFormat.toLocal8Bit().data() );
425+
QPixmap *pixmap = dynamic_cast<QPixmap *>( &mMap->paintDevice() );
426+
if( !pixmap )
427+
return;
428+
429+
pixmap->save( theFileName, theFormat.toLocal8Bit().data() );
426430
}
427431
//create a world file to go with the image...
428432
QgsRectangle myRect = mMapRenderer->extent();
@@ -1232,10 +1236,33 @@ bool QgsMapCanvas::isFrozen()
12321236

12331237
QPixmap& QgsMapCanvas::canvasPixmap()
12341238
{
1235-
return mMap->pixmap();
1236-
} // canvasPixmap
1239+
QPixmap *pixmap = dynamic_cast<QPixmap *>( &canvasPaintDevice() );
1240+
if( pixmap )
1241+
{
1242+
return *pixmap;
1243+
}
1244+
1245+
qWarning( "QgsMapCanvas::canvasPixmap() deprecated - returning static pixmap instance - use QgsMapCanvas::paintDevice()" );
1246+
1247+
static QPixmap staticPixmap;
1248+
1249+
QImage *image = dynamic_cast<QImage *>( &mMap->paintDevice() );
1250+
if( image )
1251+
{
1252+
staticPixmap = QPixmap::fromImage( *image );
1253+
}
1254+
else
1255+
{
1256+
staticPixmap = QPixmap( canvasPaintDevice().width(), canvasPaintDevice().height() );
1257+
}
12371258

1259+
return staticPixmap;
1260+
} // canvasPixmap
12381261

1262+
QPaintDevice &QgsMapCanvas::canvasPaintDevice()
1263+
{
1264+
return mMap->paintDevice();
1265+
}
12391266

12401267
double QgsMapCanvas::mapUnitsPerPixel() const
12411268
{

src/gui/qgsmapcanvas.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
119119
QgsMapRenderer* mapRenderer();
120120

121121
//! Accessor for the canvas pixmap
122-
QPixmap& canvasPixmap();
122+
//! @deprecated use canvasPaintDevice()
123+
QGISDEPRECATED QPixmap& canvasPixmap();
124+
125+
//! Accessor for the canvas paint device
126+
QPaintDevice &canvasPaintDevice();
123127

124128
//! Get the last reported scale of the canvas
125129
double scale();

0 commit comments

Comments
 (0)