34void QgsMapCanvasMap::setContent(
const QImage &image,
const QgsRectangle &rect )
36 mPreviewImages.clear();
41 if ( mMapCanvas->property(
"retro" ).toBool() )
42 mImage = mImage.scaled( mImage.width() / 3, mImage.height() / 3 )
43 .convertToFormat( QImage::Format_Indexed8, Qt::OrderedDither | Qt::OrderedAlphaDither );
48void QgsMapCanvasMap::addPreviewImage(
const QImage &image,
const QPolygonF &visiblePolygon )
50 mPreviewImages.append( qMakePair( image, visiblePolygon ) );
54QRectF QgsMapCanvasMap::boundingRect()
const
56 const double width = mItemSize.width();
57 const double height = mItemSize.height();
59 return QRectF( -width, -height, 3 * width, 3 * height );
62void QgsMapCanvasMap::paint( QPainter *painter )
65 const int w = std::round( mItemSize.width() ) - 2;
66 const int h = std::round( mItemSize.height() ) - 2;
69 if ( mImage.size() != QSize( w, h ) * mImage.devicePixelRatioF() )
71 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 );
79 const QgsPointXY pt = toMapCoordinates( QPoint( 0, 0 ) );
80 const double offsetX = pt.
x() - mRect.xMinimum();
81 const double offsetY = pt.
y() - mRect.yMaximum();
84 QList<QPair<QImage, QPolygonF>>::const_iterator imIt = mPreviewImages.constBegin();
85 for ( ; imIt != mPreviewImages.constEnd(); ++imIt )
87 const QPointF mapTopLeft = imIt->second.at( 0 );
88 const QPointF mapBottomRight = imIt->second.at( 2 );
89 const QPointF canvasTopLeft = toCanvasCoordinates(
QgsPoint( mapTopLeft.x() + offsetX, mapTopLeft.y() + offsetY ) );
90 const QPointF canvasBottomRight = toCanvasCoordinates(
QgsPoint( mapBottomRight.x() + offsetX, mapBottomRight.y() + offsetY ) );
91 painter->drawImage( QRectF( canvasTopLeft, canvasBottomRight ), imIt->first, QRect( 0, 0, imIt->first.width(), imIt->first.height() ) );
95 painter->drawImage( QRect( 0, 0, w, h ), mImage );
97 painter->drawImage( 0, 0, mImage );
101 QRectF br = boundingRect();
102 QPointF
c = br.center();
103 double rad = std::max( br.width(), br.height() ) / 10;
104 painter->drawRoundedRect( br, rad, rad );
105 painter->drawLine( QLineF( 0, 0, br.width(), br.height() ) );
106 painter->drawLine( QLineF( br.width(), 0, 0, br.height() ) );
108 double nw = br.width() * 0.5;
109 double nh = br.height() * 0.5;
110 br = QRectF(
c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
111 painter->drawRoundedRect( br, rad, rad );
113 nw = br.width() * 0.5;
114 nh = br.height() * 0.5;
115 br = QRectF(
c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
116 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.
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)