00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "qgslogger.h"
00018 #include "qgsmapcanvas.h"
00019 #include "qgsmapcanvasmap.h"
00020 #include "qgsmaprenderer.h"
00021
00022 #include <QPainter>
00023
00024 QgsMapCanvasMap::QgsMapCanvasMap( QgsMapCanvas* canvas )
00025 : mCanvas( canvas )
00026 {
00027 setZValue( -10 );
00028 setPos( 0, 0 );
00029 resize( QSize( 1, 1 ) );
00030 mUseQImageToRender = false;
00031 }
00032
00033 void QgsMapCanvasMap::paint( QPainter* p, const QStyleOptionGraphicsItem*, QWidget* )
00034 {
00035
00036 p->drawPixmap( 0, 0, mPixmap );
00037 }
00038
00039 QRectF QgsMapCanvasMap::boundingRect() const
00040 {
00041 return QRectF( 0, 0, mPixmap.width(), mPixmap.height() );
00042 }
00043
00044
00045 void QgsMapCanvasMap::resize( QSize size )
00046 {
00047 prepareGeometryChange();
00048
00049 mPixmap = QPixmap( size );
00050 mPixmap.fill( mBgColor.rgb() );
00051 mImage = QImage( size, QImage::Format_RGB32 );
00052 mCanvas->mapRenderer()->setOutputSize( size, mPixmap.logicalDpiX() );
00053 }
00054
00055 void QgsMapCanvasMap::setPanningOffset( const QPoint& point )
00056 {
00057 mOffset = point;
00058 setPos( mOffset );
00059 }
00060
00061 void QgsMapCanvasMap::render()
00062 {
00063
00064
00065
00066
00067
00068 if ( mUseQImageToRender )
00069 {
00070
00071 mImage.fill( mBgColor.rgb() );
00072
00073
00074
00075 mPixmap = QPixmap( mImage.size() );
00076 mPixmap.fill( mBgColor.rgb() );
00077
00078 QPainter paint;
00079 paint.begin( &mImage );
00080
00081 paint.setClipRect( mImage.rect() );
00082
00083
00084 if ( mAntiAliasing )
00085 paint.setRenderHint( QPainter::Antialiasing );
00086
00087 mCanvas->mapRenderer()->render( &paint );
00088
00089 paint.end();
00090
00091
00092 mPixmap = QPixmap::fromImage( mImage );
00093 }
00094 else
00095 {
00096 mPixmap.fill( mBgColor.rgb() );
00097 QPainter paint;
00098 paint.begin( &mPixmap );
00099
00100 paint.setClipRect( mPixmap.rect() );
00101 mCanvas->mapRenderer()->render( &paint );
00102 paint.end();
00103 }
00104 update();
00105 }
00106
00107 QPaintDevice& QgsMapCanvasMap::paintDevice()
00108 {
00109 return mPixmap;
00110 }
00111
00112 void QgsMapCanvasMap::updateContents()
00113 {
00114
00115 if ( mUseQImageToRender )
00116 mPixmap = QPixmap::fromImage( mImage );
00117
00118
00119 update();
00120 }