33void QgsMapCanvasMap::setContent(
const QImage &image,
const QgsRectangle &rect )
35 mPreviewImages.clear();
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 );
47void QgsMapCanvasMap::addPreviewImage(
const QImage &image,
const QPolygonF &visiblePolygon )
49 mPreviewImages.append( qMakePair( image, visiblePolygon ) );
53QRectF QgsMapCanvasMap::boundingRect()
const
55 const double width = mItemSize.width();
56 const double height = mItemSize.height();
58 return QRectF( -width, -height, 3 * width, 3 * height );
61void QgsMapCanvasMap::paint( QPainter *painter )
64 const int w = std::round( mItemSize.width() ) - 2;
65 const int h = std::round( mItemSize.height() ) - 2;
68 if ( mImage.size() != QSize( w, h ) * mImage.devicePixelRatioF() )
70 QgsDebugMsgLevel( QStringLiteral(
"map paint DIFFERENT SIZE: img %1,%2 item %3,%4" ).arg( mImage.width() / mImage.devicePixelRatioF() ).arg( mImage.height() / mImage.devicePixelRatioF() ).arg( w ).arg( h ), 2 );
78 const QgsPointXY pt = toMapCoordinates( QPoint( 0, 0 ) );
79 const double offsetX = pt.
x() - mRect.xMinimum();
80 const double offsetY = pt.
y() - mRect.yMaximum();
83 QList<QPair<QImage, QPolygonF>>::const_iterator imIt = mPreviewImages.constBegin();
84 for ( ; imIt != mPreviewImages.constEnd(); ++imIt )
86 const QPointF mapTopLeft = imIt->second.at( 0 );
87 const QPointF mapBottomRight = imIt->second.at( 2 );
88 const QPointF canvasTopLeft = toCanvasCoordinates(
QgsPoint( mapTopLeft.x() + offsetX, mapTopLeft.y() + offsetY ) );
89 const QPointF canvasBottomRight = toCanvasCoordinates(
QgsPoint( mapBottomRight.x() + offsetX, mapBottomRight.y() + offsetY ) );
90 painter->drawImage( QRectF( canvasTopLeft, canvasBottomRight ), imIt->first, QRect( 0, 0, imIt->first.width(), imIt->first.height() ) );
94 painter->drawImage( QRect( 0, 0, w, h ), mImage );
96 painter->drawImage( 0, 0, mImage );
100 QRectF br = boundingRect();
101 QPointF
c = br.center();
102 double rad = std::max( br.width(), br.height() ) / 10;
103 painter->drawRoundedRect( br, rad, rad );
104 painter->drawLine( QLineF( 0, 0, br.width(), br.height() ) );
105 painter->drawLine( QLineF( br.width(), 0, 0, br.height() ) );
107 double nw = br.width() * 0.5;
108 double nh = br.height() * 0.5;
109 br = QRectF(
c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
110 painter->drawRoundedRect( br, rad, rad );
112 nw = br.width() * 0.5;
113 nh = br.height() * 0.5;
114 br = QRectF(
c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
115 painter->drawRoundedRect( br, rad, rad );
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.
A class to represent a 2D point.
Point geometry type, with support for z-dimension and m-values.
A rectangle specified with double values.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
#define QgsDebugMsgLevel(str, level)