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 );