QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
16 #include <QQuickWindow>
18 #include <QSGSimpleTextureNode>
19 #include <QtConcurrent>
34 : QQuickItem( parent )
37 connect(
this, &QQuickItem::windowChanged,
this, &QgsQuickMapCanvasMap::onWindowChanged );
38 connect( &mRefreshTimer, &QTimer::timeout,
this, &QgsQuickMapCanvasMap::refreshMap );
39 connect( &mMapUpdateTimer, &QTimer::timeout,
this, &QgsQuickMapCanvasMap::renderJobUpdated );
47 mMapUpdateTimer.setSingleShot(
false );
48 mMapUpdateTimer.setInterval( 250 );
49 mRefreshTimer.setSingleShot(
true );
50 setTransformOrigin( QQuickItem::TopLeft );
51 setFlags( QQuickItem::ItemHasContents );
56 return mMapSettings.get();
63 QgsPoint mousePos( mMapSettings->screenToCoordinate( center ) );
64 QgsPointXY newCenter( mousePos.
x() + ( ( oldCenter.
x() - mousePos.
x() ) * scale ),
65 mousePos.
y() + ( ( oldCenter.
y() - mousePos.
y() ) * scale ) );
68 extent.
scale( scale, &newCenter );
69 mMapSettings->setExtent( extent );
75 QgsPoint start = mMapSettings->screenToCoordinate( oldPos.toPoint() );
76 QgsPoint end = mMapSettings->screenToCoordinate( newPos.toPoint() );
78 double dx = end.
x() - start.
x();
79 double dy = end.
y() - start.
y();
89 mMapSettings->setExtent( extent );
93 void QgsQuickMapCanvasMap::refreshMap()
104 QgsProject *project = mMapSettings->project();
112 mapSettings.setExpressionContext( expressionContext );
123 if ( mIncrementalRendering )
124 mMapUpdateTimer.start();
135 void QgsQuickMapCanvasMap::renderJobUpdated()
150 void QgsQuickMapCanvasMap::renderJobFinished()
160 delete mLabelingResults;
171 mMapUpdateTimer.stop();
183 void QgsQuickMapCanvasMap::onWindowChanged( QQuickWindow *window )
187 disconnect( window, &QQuickWindow::screenChanged,
this, &QgsQuickMapCanvasMap::onScreenChanged );
190 connect( window, &QQuickWindow::screenChanged,
this, &QgsQuickMapCanvasMap::onScreenChanged );
191 onScreenChanged( window->screen() );
195 void QgsQuickMapCanvasMap::onScreenChanged( QScreen *screen )
198 mMapSettings->setOutputDpi( screen->physicalDotsPerInch() );
201 void QgsQuickMapCanvasMap::onExtentChanged()
209 void QgsQuickMapCanvasMap::updateTransform()
217 setScale( imageExtent.
width() / newExtent.
width() );
225 return mMapUpdateTimer.interval();
240 return mIncrementalRendering;
264 if ( !mFreeze && mNeedsRefresh )
270 mNeedsRefresh =
false;
289 QSGSimpleTextureNode *node =
static_cast<QSGSimpleTextureNode *
>( oldNode );
292 node =
new QSGSimpleTextureNode();
293 QSGTexture *texture = window()->createTextureFromImage( mImage );
294 node->setTexture( texture );
295 node->setOwnsTexture(
true );
298 QRectF rect( boundingRect() );
301 if ( !rect.isEmpty() &&
302 !mImage.size().isEmpty() &&
303 !
qgsDoubleNear( rect.width() / rect.height(), mImage.width() / mImage.height() ) )
307 rect.setHeight( rect.width() / mImage.width() * mImage.height() );
311 rect.setWidth( rect.height() / mImage.height() * mImage.width() );
315 node->setRect( rect );
322 Q_UNUSED( oldGeometry )
329 mMapSettings->setOutputSize( newGeometry.size().toSize() );
333 void QgsQuickMapCanvasMap::onLayersChanged()
335 if ( mMapSettings->extent().isEmpty() )
338 for (
const QMetaObject::Connection &conn : qgis::as_const( mLayerConnections ) )
342 mLayerConnections.clear();
344 const QList<QgsMapLayer *> layers = mMapSettings->layers();
371 void QgsQuickMapCanvasMap::zoomToFullExtent()
374 const QList<QgsMapLayer *> layers = mMapSettings->layers();
377 if ( mMapSettings->destinationCrs() != layer->crs() )
379 QgsCoordinateTransform transform( layer->crs(), mMapSettings->destinationCrs(), mMapSettings->transformContext() );
387 mMapSettings->setExtent( extent );
394 if ( mMapSettings->outputSize().isNull() )
398 mRefreshTimer.start( 1 );
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool freeze
When freeze property is set to true, the map canvas does not refresh.
void isRenderingChanged()
The isRendering property is set to true while a rendering job is pending for this map canvas map.
const QgsMapSettings & mapSettings() const
Returns map settings with which this job was started.
void extentChanged()
Geographical coordinates of the rectangle that should be rendered.
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Point geometry type, with support for z-dimension and m-values.
void renderingLayersFinished()
Emitted when the layers are rendered.
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
void zoom(QPointF center, qreal scale)
Set map setting's extent (zoom the map) on the center by given scale.
int mapUpdateInterval
Interval in milliseconds after which the map canvas will be updated while a rendering job is ongoing.
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
void mapUpdateIntervalChanged()
Interval in milliseconds after which the map canvas will be updated while a rendering job is ongoing.
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
@ RenderPartialOutput
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override
void mapCanvasRefreshed()
Emitted when the canvas is refreshed.
void layersChanged()
Set list of layers for map rendering.
A rectangle specified with double values.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns project's global labeling engine settings.
The QgsQuickMapSettings class encapsulates QgsMapSettings class to offer settings of configuration of...
Errors errors() const
List of errors that happened during the rendering job - available when the rendering has been finishe...
void setIncrementalRendering(bool incrementalRendering)
When the incrementalRendering property is set to true, the automatic refresh of map canvas during ren...
Job implementation that renders all layers in parallel.
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
void start() override
Start the rendering job and immediately return.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
void setCache(QgsMapRendererCache *cache)
Assign a cache to be used for reading and storing rendered images of individual layers.
void renderStarting()
Emitted when a rendering is starting.
void pan(QPointF oldPos, QPointF newPos)
Set map setting's extent (pan the map) based on the difference of positions.
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
void incrementalRenderingChanged()
When the incrementalRendering property is set to true, the automatic refresh of map canvas during ren...
bool incrementalRendering
When the incrementalRendering property is set to true, the automatic refresh of map canvas during ren...
QgsQuickMapCanvasMap(QQuickItem *parent=nullptr)
Create map canvas map.
void stopRendering()
Stop map rendering.
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
void setMapUpdateInterval(int mapUpdateInterval)
Interval in milliseconds after which the map canvas will be updated while a rendering job is ongoing.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
QgsLabelingResults * takeLabelingResults() override
Gets pointer to internal labeling engine (in order to get access to the results).
A class to represent a 2D point.
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y value.
@ UseRenderingOptimization
Enable vector simplification and other rendering optimizations.
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
Perform transforms between map coordinates and device coordinates.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Base class for all map layer types.
void freezeChanged()
When freeze property is set to true, the map canvas does not refresh.
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).
Abstract base class for map rendering implementations.
void setFreeze(bool freeze)
When freeze property is set to true, the map canvas does not refresh.
QSGNode * updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *) override
QList< QgsMapRendererJob::Error > Errors
virtual void cancel()=0
Stop the rendering job - does not return until the job has terminated.
bool isRendering
The isRendering property is set to true while a rendering job is pending for this map canvas map.
The QgsMapSettings class contains configuration for rendering of the map.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
QgsQuickMapSettings * mapSettings
The mapSettings property contains configuration for rendering of the map.
QImage renderedImage() override
Gets a preview/resulting image.
void cancelWithoutBlocking() override
Triggers cancellation of the rendering job without blocking.
const QgsMapToPixel & mapToPixel() const
void finished()
emitted when asynchronous rendering is finished (or canceled).
void refresh()
Refresh the map canvas.