QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsmapcanvasmap.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmapcanvasmap.cpp - draws the map in map canvas
3  ----------------------
4  begin : February 2006
5  copyright : (C) 2006 by Martin Dobias
6  email : wonder.sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgslogger.h"
17 #include "qgsmapcanvas.h"
18 #include "qgsmapcanvasmap.h"
19 #include "qgsmaprenderer.h"
20 #include "qgsmapsettings.h"
21 #include "qgsmaplayer.h"
22 
23 #include <QPainter>
24 
26  : QgsMapCanvasItem( canvas )
27 {
28  setZValue( -10 );
29 }
30 
32 {
33 }
34 
35 void QgsMapCanvasMap::setContent( const QImage& image, const QgsRectangle& rect )
36 {
37  mImage = image;
38  setRect( rect );
39 }
40 
41 void QgsMapCanvasMap::paint( QPainter* painter )
42 {
43  int w = qRound( boundingRect().width() ) - 2, h = qRound( boundingRect().height() ) - 2; // setRect() makes the size +2 :-(
44  if ( mImage.size() != QSize( w, h ) )
45  {
46  QgsDebugMsg( QString( "map paint DIFFERENT SIZE: img %1,%2 item %3,%4" ).arg( mImage.width() ).arg( mImage.height() ).arg( w ).arg( h ) );
47  }
48  painter->drawImage( QRect( 0, 0, w, h ), mImage );
49 }
50 
52 {
53  return mImage;
54 }
A rectangle specified with double values.
Definition: qgsrectangle.h:35
virtual QRectF boundingRect() const
default implementation for canvas items
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
An abstract class for items that can be placed on the map canvas.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:104
Q_DECL_DEPRECATED QPaintDevice & paintDevice()
virtual void paint(QPainter *painter)
function to be implemented by derived classes
void setContent(const QImage &image, const QgsRectangle &rect)
void setRect(const QgsRectangle &r)
sets canvas item rectangle
QgsMapCanvasMap(QgsMapCanvas *canvas)
constructor