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
55 double width = mItemSize.width();
56 double height = mItemSize.height();
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 ( mImage.size() != QSize( w, h ) * mImage.devicePixelRatioF() )
70 QgsDebugMsgLevel( QStringLiteral(
"map paint DIFFERENT SIZE: img %1,%2 item %3,%4" )
71 .arg( mImage.width() / mImage.devicePixelRatioF() )
72 .arg( mImage.height() / mImage.devicePixelRatioF() )
73 .arg( w ).arg( h ), 2 );
81 QgsPointXY pt = toMapCoordinates( QPoint( 0, 0 ) );
82 double offsetX = pt.
x() - mRect.xMinimum();
83 double offsetY = pt.
y() - mRect.yMaximum();
86 QList< QPair< QImage, QgsRectangle > >::const_iterator imIt = mPreviewImages.constBegin();
87 for ( ; imIt != mPreviewImages.constEnd(); ++imIt )
89 QPointF ul = toCanvasCoordinates(
QgsPoint( imIt->second.xMinimum() + offsetX, imIt->second.yMaximum() + offsetY ) );
90 QPointF lr = toCanvasCoordinates(
QgsPoint( imIt->second.xMaximum() + offsetX, imIt->second.yMinimum() + offsetY ) );
91 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() ) );
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 );