30 #include <QElapsedTimer>
37 , mMinimalPreviewInterval( 250 )
42 void QgsRasterLayerRendererFeedback::onNewData()
44 if ( !renderPartialOutput() )
49 if ( mLastPreview.isValid() && mLastPreview.msecsTo( QTime::currentTime() ) < mMinimalPreviewInterval )
54 QgsDebugMsgLevel( QStringLiteral(
"new raster preview! %1" ).arg( mLastPreview.msecsTo( QTime::currentTime() ) ), 3 );
62 drawer.draw( mR->renderContext()->painter(), mR->mRasterViewPort, &mR->renderContext()->mapToPixel(), &feedback );
63 mR->mReadyToCompose =
true;
64 QgsDebugMsgLevel( QStringLiteral(
"total raster preview time: %1 ms" ).arg( t.elapsed() ), 3 );
65 mLastPreview = QTime::currentTime();
72 , mProviderCapabilities( static_cast<
QgsRasterDataProvider::Capability>( layer->dataProvider()->capabilities() ) )
73 , mFeedback( new QgsRasterLayerRendererFeedback( this ) )
84 static_cast<int>( mapToPixel.
mapWidth() / 2.0 ),
85 static_cast<int>( mapToPixel.
mapHeight() / 2.0 )
95 QgsDebugMsgLevel( QStringLiteral(
"coordinateTransform set -> project extents." ), 4 );
96 if ( rendererContext.
extent().
xMinimum() == std::numeric_limits<double>::lowest() &&
97 rendererContext.
extent().
yMinimum() == std::numeric_limits<double>::lowest() &&
98 rendererContext.
extent().
xMaximum() == std::numeric_limits<double>::max() &&
99 rendererContext.
extent().
yMaximum() == std::numeric_limits<double>::max() )
106 myProjectedViewExtent = rendererContext.
extent();
138 myProjectedViewExtent = rendererContext.
extent();
139 myProjectedLayerExtent = layer->
extent();
144 if ( myRasterExtent.
isEmpty() )
146 QgsDebugMsgLevel( QStringLiteral(
"draw request outside view extent." ), 2 );
208 const double dpiScaleFactor = rendererContext.
dpiTarget() / rendererContext.
painter()->device()->logicalDpiX();
209 mRasterViewPort->
mWidth *= dpiScaleFactor;
210 mRasterViewPort->
mHeight *= dpiScaleFactor;
259 switch ( temporalProperties->
mode() )
287 delete mRasterViewPort;
294 if ( !mRasterViewPort || (
renderContext()->testFlag( QgsRenderContext::Flag::RenderPreviewJob ) &&
295 !( mProviderCapabilities &
296 QgsRasterInterface::Capability::Prefetch ) ) )
309 if ( !mClippingRegions.empty() )
311 bool needsPainterClipPath =
false;
313 if ( needsPainterClipPath )
318 bool restoreOldResamplingStage =
false;
330 restoreOldResamplingStage =
true;
341 if ( restoreOldResamplingStage )
346 const QStringList
errors = mFeedback->errors();
347 for (
const QString &error :
errors )
352 QgsDebugMsgLevel( QStringLiteral(
"total raster draw time (ms): %1" ).arg( time.elapsed(), 5 ), 4 );
355 return !mFeedback->isCanceled();
This class represents a coordinate reference system (CRS).
Custom exception class for Coordinate Reference System related exceptions.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
static QList< QgsMapClippingRegion > collectClippingRegionsForLayer(const QgsRenderContext &context, const QgsMapLayer *layer)
Collects the list of map clipping regions from a context which apply to a map layer.
static QPainterPath calculatePainterClipRegion(const QList< QgsMapClippingRegion > ®ions, const QgsRenderContext &context, QgsMapLayerType layerType, bool &shouldClip)
Returns a QPainterPath representing the intersection of clipping regions from context which should be...
Base class for utility classes that encapsulate information necessary for rendering of map layers.
bool mReadyToCompose
The flag must be set to false in renderer's constructor if wants to use the smarter map redraws funct...
QStringList errors() const
Returns list of errors (problems) that happened during the rendering.
QgsRenderContext * renderContext()
Returns the render context associated with the renderer.
virtual QgsRectangle extent() const
Returns the extent of the layer.
QgsCoordinateReferenceSystem crs
void statusChanged(const QString &status)
Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar)
Perform transforms between map coordinates and device coordinates.
int mapHeight() const
Returns current map height in pixels.
void setMapRotation(double degrees, double cx, double cy)
Set map rotation in degrees (clockwise)
double mapUnitsPerPixel() const
Returns current map units per pixel.
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
int mapWidth() const
Returns current map width in pixels The information is only known if setRotation was used.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point p from map (world) coordinates to device coordinates.
double mapRotation() const
Returns current map rotation in degrees (clockwise)
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
A class to represent a 2D point.
void setX(double x) SIP_HOLDGIL
Sets the x value of the point.
void setY(double y) SIP_HOLDGIL
Sets the y value of the point.
Feedback object tailored for raster block reading.
void setPreviewOnly(bool preview)
set flag whether the block request is for preview purposes only
void setRenderPartialOutput(bool enable)
Set whether our painter is drawing to a temporary image used just by this layer.
void setRequestedTemporalRange(const QgsDateTimeRange &range)
Sets the requested temporal range to retrieve when returning data from the associated data provider.
void setIntervalHandlingMethod(IntervalHandlingMethod method)
Sets the desired method to use when resolving a temporal interval to matching layers or bands in the ...
Base class for raster data providers.
virtual QgsRasterDataProvider::ProviderCapabilities providerCapabilities() const
Returns flags containing the supported capabilities of the data provider.
void setDpi(int dpi)
Sets the output device resolution.
@ ProviderHintCanPerformProviderResampling
Provider can perform resampling (to be opposed to post rendering resampling) (since QGIS 3....
void statusChanged(const QString &) const
Emit a message to be displayed on status bar, usually used by network providers (WMS,...
QgsRasterDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
The drawing pipe for raster layers.
void draw(QPainter *p, QgsRasterViewPort *viewPort, const QgsMapToPixel *qgsMapToPixel, QgsRasterBlockFeedback *feedback=nullptr)
Draws raster data.
Iterator for sequentially processing raster cells.
Implementation of threaded rendering for raster layers.
bool render() override
Do the rendering (based on data stored in the class).
QgsRasterLayerRenderer(QgsRasterLayer *layer, QgsRenderContext &rendererContext)
bool forceRasterRender() const override
Returns true if the renderer must be rendered to a raster paint device (e.g.
~QgsRasterLayerRenderer() override
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be nullptr)
Implementation of map layer temporal properties for raster layers.
@ ModeFixedTemporalRange
Mode when temporal properties have fixed start and end datetimes.
@ ModeTemporalRangeFromDataProvider
Mode when raster layer delegates temporal range handling to the dataprovider.
TemporalMode mode() const
Returns the temporal properties mode.
QgsRasterDataProviderTemporalCapabilities::IntervalHandlingMethod intervalHandlingMethod() const
Returns the desired method to use when resolving a temporal interval to matching layers or bands in t...
Represents a raster layer.
int height() const
Returns the height of the (unclipped) raster.
QgsRasterPipe * pipe()
Returns the raster pipe.
void refreshRendererIfNeeded(QgsRasterRenderer *rasterRenderer, const QgsRectangle &extent)
Refresh renderer with new extent, if needed.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
bool ignoreExtents() const
If the ignoreExtent flag is set, the layer will also render outside the bounding box reported by the ...
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
int width() const
Returns the width of the (unclipped) raster.
Base class for processing modules.
ResamplingStage
Stage at which resampling occurs.
@ Provider
Resampling occurs in Provider.
QgsRasterDataProvider * provider() const
QgsRasterProjector * projector() const
QgsRasterInterface * last() const
QgsRasterRenderer * renderer() const
ResamplingStage resamplingStage() const
Returns which stage of the pipe should apply resampling.
void setResamplingStage(ResamplingStage stage)
Select which stage of the pipe should apply resampling.
QgsRasterProjector implements approximate projection support for it calculates grid of points in sour...
Q_DECL_DEPRECATED void setCrs(const QgsCoordinateReferenceSystem &srcCRS, const QgsCoordinateReferenceSystem &destCRS, int srcDatumTransform=-1, int destDatumTransform=-1)
Sets the source and destination CRS.
Raster renderer pipe that applies colors to a raster.
A rectangle specified with double values.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
void set(const QgsPointXY &p1, const QgsPointXY &p2, bool normalize=true)
Sets the rectangle from two QgsPoints.
void setMinimal() SIP_HOLDGIL
Set a rectangle so that min corner is at max and max corner is at min.
bool isEmpty() const
Returns true if the rectangle is empty.
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.
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.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QgsCoordinateTransformContext transformContext() const
Returns the context's coordinate transform context, which stores various information regarding which ...
void setDpiTarget(double dpi)
Sets the targeted dpi for rendering.
double dpiTarget() const
Returns the targeted DPI for rendering.
@ RenderPreviewJob
Render is a 'canvas preview' render, and shortcuts should be taken to ensure fast rendering.
@ RenderPartialOutput
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
@ Render3DMap
Render is for a 3D map.
Flags flags() const
Returns combination of flags used for rendering.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
Scoped object for saving and restoring a QPainter object's state.
bool isActive() const
Returns true if the temporal property is active.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
unsigned long long qgssize
Qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...
#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.
QgsCoordinateReferenceSystem mDestCRS
Target coordinate system.
QgsPointXY mBottomRightPoint
Coordinate (in output device coordinate system) of bottom right corner of the part of the raster that...
QgsPointXY mTopLeftPoint
Coordinate (in output device coordinate system) of top left corner of the part of the raster that is ...
QgsCoordinateReferenceSystem mSrcCRS
Source coordinate system.
QgsRectangle mDrawnExtent
Intersection of current map extent and layer extent.
QgsCoordinateTransformContext mTransformContext
Coordinate transform context.
qgssize mWidth
Width, number of columns to be rendered.