33 , mMinimalPreviewInterval( 250 )
38 void QgsRasterLayerRendererFeedback::onNewData()
40 if ( !renderPartialOutput() )
45 if ( mLastPreview.isValid() && mLastPreview.msecsTo( QTime::currentTime() ) < mMinimalPreviewInterval )
50 QgsDebugMsg( QStringLiteral(
"new raster preview! %1" ).arg( mLastPreview.msecsTo( QTime::currentTime() ) ) );
58 drawer.draw( mR->mPainter, mR->mRasterViewPort, mR->mMapToPixel, &feedback );
59 QgsDebugMsg( QStringLiteral(
"total raster preview time: %1 ms" ).arg( t.elapsed() ) );
60 mLastPreview = QTime::currentTime();
67 , mContext( rendererContext )
68 , mFeedback( new QgsRasterLayerRendererFeedback( this ) )
70 mPainter = rendererContext.
painter();
72 mMapToPixel = &qgsMapToPixel;
82 static_cast<int>( mapToPixel.
mapWidth() / 2.0 ),
83 static_cast<int>( mapToPixel.
mapHeight() / 2.0 )
93 QgsDebugMsgLevel( QStringLiteral(
"coordinateTransform set -> project extents." ), 4 );
94 if ( rendererContext.
extent().
xMinimum() == std::numeric_limits<double>::lowest() &&
95 rendererContext.
extent().
yMinimum() == std::numeric_limits<double>::lowest() &&
96 rendererContext.
extent().
xMaximum() == std::numeric_limits<double>::max() &&
97 rendererContext.
extent().
yMaximum() == std::numeric_limits<double>::max() )
104 myProjectedViewExtent = rendererContext.
extent();
132 myProjectedViewExtent = rendererContext.
extent();
133 myProjectedLayerExtent = layer->
extent();
138 if ( myRasterExtent.
isEmpty() )
140 QgsDebugMsg( QStringLiteral(
"draw request outside view extent." ) );
159 mRasterViewPort->mDrawnExtent = myRasterExtent;
162 mRasterViewPort->mSrcCRS = layer->
crs();
171 mRasterViewPort->mSrcDatumTransform = -1;
172 mRasterViewPort->mDestDatumTransform = -1;
185 mRasterViewPort->mTopLeftPoint.
setX( std::floor( mRasterViewPort->mTopLeftPoint.x() ) );
186 mRasterViewPort->mTopLeftPoint.setY( std::floor( mRasterViewPort->mTopLeftPoint.y() ) );
187 mRasterViewPort->mBottomRightPoint.setX( std::ceil( mRasterViewPort->mBottomRightPoint.x() ) );
188 mRasterViewPort->mBottomRightPoint.setY( std::ceil( mRasterViewPort->mBottomRightPoint.y() ) );
192 mRasterViewPort->mBottomRightPoint.y() ),
194 mRasterViewPort->mTopLeftPoint.y() )
198 mRasterViewPort->mWidth =
static_cast<int>( mRasterViewPort->mBottomRightPoint.x() - mRasterViewPort->mTopLeftPoint.x() );
199 mRasterViewPort->mHeight =
static_cast<int>( mRasterViewPort->mBottomRightPoint.y() - mRasterViewPort->mTopLeftPoint.y() );
213 QgsDebugMsgLevel( QStringLiteral(
"mTopLeftPoint.x() = %1" ).arg( mRasterViewPort->mTopLeftPoint.x() ), 3 );
214 QgsDebugMsgLevel( QStringLiteral(
"mBottomRightPoint.x() = %1" ).arg( mRasterViewPort->mBottomRightPoint.x() ), 3 );
215 QgsDebugMsgLevel( QStringLiteral(
"mTopLeftPoint.y() = %1" ).arg( mRasterViewPort->mTopLeftPoint.y() ), 3 );
216 QgsDebugMsgLevel( QStringLiteral(
"mBottomRightPoint.y() = %1" ).arg( mRasterViewPort->mBottomRightPoint.y() ), 3 );
218 QgsDebugMsgLevel( QStringLiteral(
"mWidth = %1" ).arg( mRasterViewPort->mWidth ), 3 );
219 QgsDebugMsgLevel( QStringLiteral(
"mHeight = %1" ).arg( mRasterViewPort->mHeight ), 3 );
240 delete mRasterViewPort;
246 if ( !mRasterViewPort )
272 drawer.draw( mPainter, mRasterViewPort, mMapToPixel, mFeedback );
274 QgsDebugMsgLevel( QStringLiteral(
"total raster draw time (ms): %1" ).arg( time.elapsed(), 5 ), 4 );
int width() const
Returns the width of the (unclipped) raster.
~QgsRasterLayerRenderer() override
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be null)
A rectangle specified with double values.
void setMapRotation(double degrees, double cx, double cy)
Set map rotation in degrees (clockwise)
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
Base class for processing modules.
Iterator for sequentially processing raster cells.
QgsRasterRenderer * renderer() const
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QgsRasterPipe * pipe()
Returns the raster pipe.
A class to represent a 2D point.
QgsRasterProjector * projector() const
QgsRasterInterface * last() const
void setRenderPartialOutput(bool enable)
Set whether our painter is drawing to a temporary image used just by this layer.
Flags flags() const
Returns combination of flags used for rendering.
int height() const
Returns the height of the (unclipped) raster.
Implementation of threaded rendering for raster layers.
bool render() override
Do the rendering (based on data stored in the class)
virtual QgsRectangle extent() const
Returns the extent of the layer.
double mapRotation() const
Returns current map rotation in degrees.
QgsCoordinateReferenceSystem mDestCRS
Target coordinate system.
void setCrs(const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS, int srcDatumTransform=-1, int destDatumTransform=-1)
Sets the source and destination CRS.
Base class for feedback objects to be used for cancelation of something running in a worker thread...
Perform transforms between map coordinates and device coordinates.
The drawing pipe for raster layers.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
QgsRasterDataProvider * dataProvider() override
Returns the layer's data provider, it may be null.
int mapWidth() const
Returns current map width in pixels The information is only known if setRotation was used...
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
int mapHeight() const
Returns current map height in pixels.
void setPreviewOnly(bool preview)
set flag whether the block request is for preview purposes only
#define QgsDebugMsgLevel(str, level)
bool isEmpty() const
Returns true if the rectangle is empty.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
QgsRasterLayerRenderer(QgsRasterLayer *layer, QgsRenderContext &rendererContext)
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
double mapUnitsPerPixel() const
Returns current map units per pixel.
void setX(double x)
Sets the x value of the point.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
QgsCoordinateReferenceSystem mSrcCRS
Source coordinate system.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
Render is a 'canvas preview' render, and shortcuts should be taken to ensure fast rendering...
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
This class represents a coordinate reference system (CRS).
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Base class for utility classes that encapsulate information necessary for rendering of map layers...
double yMaximum() const
Returns the y maximum value (top side of rectangle).
void refreshRendererIfNeeded(QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent)
Refresh renderer with new extent, if needed.
Custom exception class for Coordinate Reference System related exceptions.
This class provides details of the viewable area that a raster will be rendered into.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Feedback object tailored for raster block reading.
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
Raster renderer pipe that applies colors to a raster.
void setDpi(int dpi)
Sets the output device resolution.
void set(const QgsPointXY &p1, const QgsPointXY &p2)
Sets the rectangle from two QgsPoints.
QgsCoordinateReferenceSystem crs