QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
39  // For true retro fans: this is approximately how the graphics looked like in 1990
40  if ( mMapCanvas->property( "retro" ).toBool() )
41  mImage = mImage.scaled( mImage.width() / 3, mImage.height() / 3 )
42  .convertToFormat( QImage::Format_Indexed8, Qt::OrderedDither | Qt::OrderedAlphaDither );
43 
44  setRect( rect );
45 }
46 
47 void QgsMapCanvasMap::paint( QPainter* painter )
48 {
49  int w = qRound( boundingRect().width() ) - 2, h = qRound( boundingRect().height() ) - 2; // setRect() makes the size +2 :-(
50  if ( mImage.size() != QSize( w, h ) )
51  {
52  QgsDebugMsg( QString( "map paint DIFFERENT SIZE: img %1,%2 item %3,%4" ).arg( mImage.width() ).arg( mImage.height() ).arg( w ).arg( h ) );
53  }
54  painter->drawImage( QRect( 0, 0, w, h ), mImage );
55 }
56 
58 {
59  return mImage;
60 }
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:33
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)
QgsMapCanvas * mMapCanvas
pointer to map canvas
void setRect(const QgsRectangle &r)
sets canvas item rectangle
QgsMapCanvasMap(QgsMapCanvas *canvas)
constructor