33 : mIterator( iterator )
34 , mDpiTarget( dpiTarget )
41 if ( !p || !mIterator || !viewPort || !qgsMapToPixel )
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 QRgb transparentBlack = qRgba( 0, 0, 0, 0 );
83 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 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();
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 );
bool isCanceled() const SIP_HOLDGIL
Tells whether the operation has been canceled already.
Perform transforms between map coordinates and device coordinates.
int mapHeight() const
Returns current map height in pixels.
int mapWidth() const
Returns current map width in pixels The information is only known if setRotation was used.
double mapRotation() const
Returns current map rotation in degrees (clockwise)
Feedback object tailored for raster block reading.
bool renderPartialOutput() const
Whether our painter is drawing to a temporary image used just by this layer.
void drawImage(QPainter *p, QgsRasterViewPort *viewPort, const QImage &img, int topLeftCol, int topLeftRow, const QgsMapToPixel *mapToPixel=nullptr) const
Draws raster part.
QgsRasterDrawer(QgsRasterIterator *iterator, double dpiTarget=-1.0)
The QgsRasterDrawer constructor.
void draw(QPainter *p, QgsRasterViewPort *viewPort, const QgsMapToPixel *qgsMapToPixel, QgsRasterBlockFeedback *feedback=nullptr)
Draws raster data.
Iterator for sequentially processing raster cells.
bool readNextRasterPart(int bandNumber, int &nCols, int &nRows, QgsRasterBlock **block, int &topLeftCol, int &topLeftRow)
Fetches next part of raster data, caller takes ownership of the block and caller should delete the bl...
void startRasterRead(int bandNumber, qgssize nCols, qgssize nRows, const QgsRectangle &extent, QgsRasterBlockFeedback *feedback=nullptr)
Start reading of raster band.
Scoped object for saving and restoring a QPainter object's state.
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)
This class provides details of the viewable area that a raster will be rendered into.
qgssize mHeight
Height, number of rows to be rendered.
QgsPointXY mTopLeftPoint
Coordinate (in output device coordinate system) of top left corner of the part of the raster that is ...
QgsRectangle mDrawnExtent
Intersection of current map extent and layer extent.
qgssize mWidth
Width, number of columns to be rendered.