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 ).convertToFormat( QImage::Format_Indexed8, Qt::OrderedDither | Qt::OrderedAlphaDither );
50void QgsMapCanvasMap::addPreviewImage(
const QImage &image,
const QPolygonF &visiblePolygon )
52 mPreviewImages.append( qMakePair( image, visiblePolygon ) );
56QRectF QgsMapCanvasMap::boundingRect()
const
58 const double width = mItemSize.width();
59 const double height = mItemSize.height();
61 return QRectF( -width, -height, 3 * width, 3 * height );
64void QgsMapCanvasMap::paint( QPainter *painter )
67 const int w = std::round( mItemSize.width() ) - 2;
68 const int h = std::round( mItemSize.height() ) - 2;
71 if ( mImage.size() != QSize( w, h ) * mImage.devicePixelRatioF() )
73 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 );
81 const QgsPointXY pt = toMapCoordinates( QPoint( 0, 0 ) );
82 const double offsetX = pt.
x() - mRect.xMinimum();
83 const double offsetY = pt.
y() - mRect.yMaximum();
86 QList<QPair<QImage, QPolygonF>>::const_iterator imIt = mPreviewImages.constBegin();
87 for ( ; imIt != mPreviewImages.constEnd(); ++imIt )
89 const QPointF mapTopLeft = imIt->second.at( 0 );
90 const QPointF mapBottomRight = imIt->second.at( 2 );
91 const QPointF canvasTopLeft = toCanvasCoordinates(
QgsPoint( mapTopLeft.x() + offsetX, mapTopLeft.y() + offsetY ) );
92 const QPointF canvasBottomRight = toCanvasCoordinates(
QgsPoint( mapBottomRight.x() + offsetX, mapBottomRight.y() + offsetY ) );
93 painter->drawImage( QRectF( canvasTopLeft, canvasBottomRight ), imIt->first, QRect( 0, 0, imIt->first.width(), imIt->first.height() ) );
97 painter->drawImage( QRect( 0, 0, w, h ), mImage );
99 painter->drawImage( 0, 0, mImage );
103 QRectF br = boundingRect();
104 QPointF
c = br.center();
105 double rad = std::max( br.width(), br.height() ) / 10;
106 painter->drawRoundedRect( br, rad, rad );
107 painter->drawLine( QLineF( 0, 0, br.width(), br.height() ) );
108 painter->drawLine( QLineF( br.width(), 0, 0, br.height() ) );
110 double nw = br.width() * 0.5;
111 double nh = br.height() * 0.5;
112 br = QRectF(
c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
113 painter->drawRoundedRect( br, rad, rad );
115 nw = br.width() * 0.5;
116 nh = br.height() * 0.5;
117 br = QRectF(
c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
118 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)