27using namespace Qt::StringLiterals;
37void QgsMapCanvasMap::setContent(
const QImage &image,
const QgsRectangle &rect )
39 mPreviewImages.clear();
44 if ( mMapCanvas->property(
"retro" ).toBool() )
45 mImage = mImage.scaled( mImage.width() / 3, mImage.height() / 3 )
46 .convertToFormat( QImage::Format_Indexed8, Qt::OrderedDither | Qt::OrderedAlphaDither );
51void QgsMapCanvasMap::addPreviewImage(
const QImage &image,
const QPolygonF &visiblePolygon )
53 mPreviewImages.append( qMakePair( image, visiblePolygon ) );
57QRectF QgsMapCanvasMap::boundingRect()
const
59 const double width = mItemSize.width();
60 const double height = mItemSize.height();
62 return QRectF( -width, -height, 3 * width, 3 * height );
65void QgsMapCanvasMap::paint( QPainter *painter )
68 const int w = std::round( mItemSize.width() ) - 2;
69 const int h = std::round( mItemSize.height() ) - 2;
72 if ( mImage.size() != QSize( w, h ) * mImage.devicePixelRatioF() )
74 QgsDebugMsgLevel( u
"map paint DIFFERENT SIZE: img %1,%2 item %3,%4"_s.arg( mImage.width() / mImage.devicePixelRatioF() ).arg( mImage.height() / mImage.devicePixelRatioF() ).arg( w ).arg( h ), 2 );
82 const QgsPointXY pt = toMapCoordinates( QPoint( 0, 0 ) );
83 const double offsetX = pt.
x() - mRect.xMinimum();
84 const double offsetY = pt.
y() - mRect.yMaximum();
87 QList<QPair<QImage, QPolygonF>>::const_iterator imIt = mPreviewImages.constBegin();
88 for ( ; imIt != mPreviewImages.constEnd(); ++imIt )
90 const QPointF mapTopLeft = imIt->second.at( 0 );
91 const QPointF mapBottomRight = imIt->second.at( 2 );
92 const QPointF canvasTopLeft = toCanvasCoordinates(
QgsPoint( mapTopLeft.x() + offsetX, mapTopLeft.y() + offsetY ) );
93 const QPointF canvasBottomRight = toCanvasCoordinates(
QgsPoint( mapBottomRight.x() + offsetX, mapBottomRight.y() + offsetY ) );
94 painter->drawImage( QRectF( canvasTopLeft, canvasBottomRight ), imIt->first, QRect( 0, 0, imIt->first.width(), imIt->first.height() ) );
98 painter->drawImage( QRect( 0, 0, w, h ), mImage );
100 painter->drawImage( 0, 0, mImage );
104 QRectF br = boundingRect();
105 QPointF
c = br.center();
106 double rad = std::max( br.width(), br.height() ) / 10;
107 painter->drawRoundedRect( br, rad, rad );
108 painter->drawLine( QLineF( 0, 0, br.width(), br.height() ) );
109 painter->drawLine( QLineF( br.width(), 0, 0, br.height() ) );
111 double nw = br.width() * 0.5;
112 double nh = br.height() * 0.5;
113 br = QRectF(
c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
114 painter->drawRoundedRect( br, rad, rad );
116 nw = br.width() * 0.5;
117 nh = br.height() * 0.5;
118 br = QRectF(
c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
119 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)