34using namespace Qt::StringLiterals;
37 : mIterator( iterator )
38 , mDpiTarget( dpiTarget )
42 : mIterator( iterator )
56 if ( !p || !mIterator || !viewPort || !qgsMapToPixel )
61 if ( mDpiTarget >= 0 )
63 mDpiScaleFactor = mDpiTarget / p->device()->logicalDpiX();
67 const int bandNumber = 1;
69 ->startRasterRead( bandNumber, std::floor(
static_cast<double>( viewPort->
mWidth ) * mDevicePixelRatio ), std::floor(
static_cast<double>( viewPort->
mHeight ) * mDevicePixelRatio ), viewPort->
mDrawnExtent, feedback );
80 std::unique_ptr< QgsRasterBlock > block;
83 while ( mIterator->readNextRasterPart( bandNumber, nCols, nRows, block, topLeftCol, topLeftRow ) )
91 QImage img = block->image();
95 QPdfWriter *pdfWriter =
dynamic_cast<QPdfWriter *
>( p->device() );
100 img = img.convertToFormat( QImage::Format_ARGB32 );
101 const QRgb transparentBlack = qRgba( 0, 0, 0, 0 );
102 const QRgb transparentWhite = qRgba( 255, 255, 255, 0 );
103 for (
int x = 0; x < img.width(); x++ )
105 for (
int y = 0; y < img.height(); y++ )
107 if ( img.pixel( x, y ) == transparentBlack )
109 img.setPixel( x, y, transparentWhite );
120 p->setCompositionMode( QPainter::CompositionMode_Source );
123 drawImage( p, viewPort, img, topLeftCol, topLeftRow, qgsMapToPixel );
128 p->setCompositionMode( QPainter::CompositionMode_SourceOver );
140 if ( !p || !viewPort )
147 = QPoint( std::floor( viewPort->
mTopLeftPoint.
x() + topLeftCol / mDpiScaleFactor / mDevicePixelRatio ), std::floor( viewPort->
mTopLeftPoint.
y() + topLeftRow / mDpiScaleFactor / mDevicePixelRatio ) );
153 p->setRenderHint( QPainter::SmoothPixmapTransform,
true );
159 p->setBrush( QBrush( QColor( Qt::white ), Qt::NoBrush ) );
162 const int w = qgsMapToPixel->
mapWidth();
163 const int h = qgsMapToPixel->
mapHeight();
164 const double rotation = qgsMapToPixel->
mapRotation();
168 const double cx = w / 2.0;
169 const double cy = h / 2.0;
170 p->translate( cx, cy );
171 p->rotate( rotation );
172 p->translate( -cx, -cy );
176 p->drawImage( QRect( tlPoint.x(), tlPoint.y(), std::ceil( img.width() / mDpiScaleFactor / mDevicePixelRatio ), std::ceil( img.height() / mDpiScaleFactor / mDevicePixelRatio ) ), img );
180 QRectF br = QRectF( tlPoint, img.size() / mDpiScaleFactor / devicePixelRatio );
181 QPointF
c = br.center();
182 double rad = std::max( br.width(), br.height() ) / 10;
183 p->drawRoundedRect( br, rad, rad );
184 p->drawLine( QLineF( br.x(), br.y(), br.x() + br.width(), br.y() + br.height() ) );
185 p->drawLine( QLineF( br.x() + br.width(), br.y(), br.x(), br.y() + br.height() ) );
187 double nw = br.width() * 0.5;
188 double nh = br.height() * 0.5;
189 br = QRectF(
c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
190 p->drawRoundedRect( br, rad, rad );
192 nw = br.width() * 0.5;
193 nh = br.height() * 0.5;
194 br = QRectF(
c - QPointF( nw / 2, nh / 2 ), QSize( nw, nh ) );
195 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.
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.
float devicePixelRatio() const
Returns the device pixel ratio.
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
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
#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, in map (destination) CRS.
qgssize mWidth
Width, number of columns to be rendered.