33 : mIterator( iterator )
34 , mDpiTarget( dpiTarget )
41 if ( !p || !mIterator || !viewPort || !qgsMapToPixel )
47 const int bandNumber = 1;
59 std::unique_ptr< QgsRasterBlock > block;
63 block, topLeftCol, topLeftRow ) )
67 QgsDebugMsg( QStringLiteral(
"Cannot get block" ) );
71 QImage img = block->image();
76 QPrinter *printer =
dynamic_cast<QPrinter *
>( p->device() );
77 if ( printer && printer->outputFormat() == QPrinter::PdfFormat )
81 img = img.convertToFormat( QImage::Format_ARGB32 );
82 const QRgb transparentBlack = qRgba( 0, 0, 0, 0 );
83 const QRgb transparentWhite = qRgba( 255, 255, 255, 0 );
84 for (
int x = 0; x < img.width(); x++ )
86 for (
int y = 0; y < img.height(); y++ )
88 if ( img.pixel( x, y ) == transparentBlack )
90 img.setPixel( x, y, transparentWhite );
102 p->setCompositionMode( QPainter::CompositionMode_Source );
105 drawImage( p, viewPort, img, topLeftCol, topLeftRow, qgsMapToPixel );
110 p->setCompositionMode( QPainter::CompositionMode_SourceOver );
122 if ( !p || !viewPort )
127 const double dpiScaleFactor = mDpiTarget >= 0.0 ? mDpiTarget / p->device()->logicalDpiX() : 1.0;
129 const QPoint tlPoint = QPoint( viewPort->
mTopLeftPoint.
x() + std::floor( topLeftCol / dpiScaleFactor ), viewPort->
mTopLeftPoint.
y() + std::floor( topLeftRow / dpiScaleFactor ) );
132 p->setRenderHint( QPainter::Antialiasing,
false );
137 p->setBrush( QBrush( QColor( Qt::white ), Qt::NoBrush ) );
140 const int w = qgsMapToPixel->
mapWidth();
141 const int h = qgsMapToPixel->
mapHeight();
142 const double rotation = qgsMapToPixel->
mapRotation();
146 const double cx = w / 2.0;
147 const double cy = h / 2.0;
148 p->translate( cx, cy );
149 p->rotate( rotation );
150 p->translate( -cx, -cy );
154 p->drawImage( tlPoint, dpiScaleFactor != 1.0 ? img.scaledToHeight( std::ceil( img.height() / dpiScaleFactor ) ) : img );
158 QRectF br = QRectF( tlPoint, img.size() );
159 QPointF
c = br.center();
160 double rad = std::max( br.width(), br.height() ) / 10;
161 p->drawRoundedRect( br, rad, rad );
162 p->drawLine( QLineF( br.x(), br.y(), br.x() + br.width(), br.y() + br.height() ) );
163 p->drawLine( QLineF( br.x() + br.width(), br.y(), br.x(), br.y() + br.height() ) );
165 double nw = br.width() * 0.5;
166 double nh = br.height() * 0.5;
167 br = QRectF(
c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
168 p->drawRoundedRect( br, rad, rad );
170 nw = br.width() * 0.5;
171 nh = br.height() * 0.5;
172 br = QRectF(
c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
173 p->drawRoundedRect( br, rad, rad );