33 : mIterator( iterator )
34 , mDpiTarget( dpiTarget )
39 : mIterator( iterator )
51 mDpiScaleFactor = 1.0;
60 if ( !p || !mIterator || !viewPort || !qgsMapToPixel )
65 if ( mDpiTarget >= 0 )
67 mDpiScaleFactor = mDpiTarget / p->device()->logicalDpiX();
71 const int bandNumber = 1;
83 std::unique_ptr< QgsRasterBlock > block;
87 block, topLeftCol, topLeftRow ) )
95 QImage img = block->image();
100 QPrinter *printer =
dynamic_cast<QPrinter *
>( p->device() );
101 if ( printer && printer->outputFormat() == QPrinter::PdfFormat )
105 img = img.convertToFormat( QImage::Format_ARGB32 );
106 const QRgb transparentBlack = qRgba( 0, 0, 0, 0 );
107 const QRgb transparentWhite = qRgba( 255, 255, 255, 0 );
108 for (
int x = 0; x < img.width(); x++ )
110 for (
int y = 0; y < img.height(); y++ )
112 if ( img.pixel( x, y ) == transparentBlack )
114 img.setPixel( x, y, transparentWhite );
126 p->setCompositionMode( QPainter::CompositionMode_Source );
129 drawImage( p, viewPort, img, topLeftCol, topLeftRow, qgsMapToPixel );
134 p->setCompositionMode( QPainter::CompositionMode_SourceOver );
146 if ( !p || !viewPort )
151 const double devicePixelRatio = p->device()->devicePixelRatio();
154 const QPoint tlPoint = QPoint( std::floor( viewPort->
mTopLeftPoint.
x() + topLeftCol / mDpiScaleFactor / devicePixelRatio ),
155 std::floor( viewPort->
mTopLeftPoint.
y() + topLeftRow / mDpiScaleFactor / devicePixelRatio ) );
157 p->setRenderHint( QPainter::Antialiasing,
false );
162 p->setBrush( QBrush( QColor( Qt::white ), Qt::NoBrush ) );
165 const int w = qgsMapToPixel->
mapWidth();
166 const int h = qgsMapToPixel->
mapHeight();
167 const double rotation = qgsMapToPixel->
mapRotation();
171 const double cx = w / 2.0;
172 const double cy = h / 2.0;
173 p->translate( cx, cy );
174 p->rotate( rotation );
175 p->translate( -cx, -cy );
179 p->drawImage( QRect( tlPoint.x(), tlPoint.y(),
180 std::ceil( img.width() / mDpiScaleFactor / devicePixelRatio ),
181 std::ceil( img.height() / mDpiScaleFactor / devicePixelRatio ) ),
186 QRectF br = QRectF( tlPoint, img.size() / mDpiScaleFactor / devicePixelRatio );
187 QPointF
c = br.center();
188 double rad = std::max( br.width(), br.height() ) / 10;
189 p->drawRoundedRect( br, rad, rad );
190 p->drawLine( QLineF( br.x(), br.y(), br.x() + br.width(), br.y() + br.height() ) );
191 p->drawLine( QLineF( br.x() + br.width(), br.y(), br.x(), br.y() + br.height() ) );
193 double nw = br.width() * 0.5;
194 double nh = br.height() * 0.5;
195 br = QRectF(
c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
196 p->drawRoundedRect( br, rad, rad );
198 nw = br.width() * 0.5;
199 nh = br.height() * 0.5;
200 br = QRectF(
c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
201 p->drawRoundedRect( br, rad, rad );
bool isCanceled() const
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 the current map width in pixels.
double mapRotation() const
Returns the 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.
Q_DECL_DEPRECATED QgsRasterDrawer(QgsRasterIterator *iterator, double dpiTarget)
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.
Contains information about the context of a rendering operation.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
QPainter * painter()
Returns the destination QPainter for the render operation.
double dpiTarget() const
Returns the targeted DPI for rendering.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
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)
#define QgsDebugError(str)
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.