33 void 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 );
47 void QgsMapCanvasMap::addPreviewImage(
const QImage &image,
const QgsRectangle &rect )
49 mPreviewImages.append( qMakePair( image, rect ) );
53 QRectF QgsMapCanvasMap::boundingRect()
const 58 return QRectF( -width, -height, 3 * width, 3 * height );
61 void QgsMapCanvasMap::paint( QPainter *painter )
64 int w = std::round(
mItemSize.width() ) - 2;
65 int h = std::round(
mItemSize.height() ) - 2;
68 #if QT_VERSION >= 0x050600 69 if ( mImage.size() != QSize( w, h ) * mImage.devicePixelRatioF() )
71 if ( mImage.size() != QSize( w, h ) * mImage.devicePixelRatio() )
74 #if QT_VERSION >= 0x050600 75 QgsDebugMsg( QStringLiteral(
"map paint DIFFERENT SIZE: img %1,%2 item %3,%4" )
76 .arg( mImage.width() / mImage.devicePixelRatioF() )
77 .arg( mImage.height() / mImage.devicePixelRatioF() )
80 QgsDebugMsg( QStringLiteral(
"map paint DIFFERENT SIZE: img %1,%2 item %3,%4" )
81 .arg( mImage.width() / mImage.devicePixelRatio() )
82 .arg( mImage.height() / mImage.devicePixelRatio() )
97 QList< QPair< QImage, QgsRectangle > >::const_iterator imIt = mPreviewImages.constBegin();
98 for ( ; imIt != mPreviewImages.constEnd(); ++imIt )
102 painter->drawImage( QRectF( ul.x(), ul.y(), lr.x() - ul.x(), lr.y() - ul.y() ), imIt->first, QRect( 0, 0, imIt->first.width(), imIt->first.height() ) );
106 painter->drawImage( QRect( 0, 0, w, h ), mImage );
108 painter->drawImage( 0, 0, mImage );
113 QPointF
c = br.center();
114 double rad = std::max( br.width(), br.height() ) / 10;
115 painter->drawRoundedRect( br, rad, rad );
116 painter->drawLine( QLineF( 0, 0, br.width(), br.height() ) );
117 painter->drawLine( QLineF( br.width(), 0, 0, br.height() ) );
119 double nw = br.width() * 0.5;
120 double nh = br.height() * 0.5;
121 br = QRectF( c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
122 painter->drawRoundedRect( br, rad, rad );
124 nw = br.width() * 0.5;
125 nh = br.height() * 0.5;
126 br = QRectF( c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
127 painter->drawRoundedRect( br, rad, rad );
A rectangle specified with double values.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
A class to represent a 2D point.
An abstract class for items that can be placed on the map canvas.
QgsRectangle rect() const
returns canvas item rectangle in map units
Map canvas is a class for displaying all GIS data types on a canvas.
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
QSizeF mItemSize
cached size of the item (to return in boundingRect())
QRectF boundingRect() const override
void setRect(const QgsRectangle &r, bool resetRotation=true)
sets canvas item rectangle in map units
QgsRectangle mRect
cached canvas item rectangle in map coordinates encodes position (xmin,ymax) and size (width/height) ...
Point geometry type, with support for z-dimension and m-values.
QgsPointXY toMapCoordinates(QPoint point) const
transformation from screen coordinates to map coordinates
QgsMapCanvas * mMapCanvas
pointer to map canvas
QPointF toCanvasCoordinates(const QgsPointXY &point) const
transformation from map coordinates to screen coordinates
double xMinimum() const
Returns the x minimum value (left side of rectangle).