Skip to content

Commit b2188d4

Browse files
committed
use smart pointer for QgsQuickMapSettings in map canvas
1 parent dc621ad commit b2188d4

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

src/quickgui/qgsquickmapcanvasmap.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ QgsQuickMapCanvasMap::QgsQuickMapCanvasMap( QQuickItem *parent )
3737
connect( &mRefreshTimer, &QTimer::timeout, this, &QgsQuickMapCanvasMap::refreshMap );
3838
connect( &mMapUpdateTimer, &QTimer::timeout, this, &QgsQuickMapCanvasMap::renderJobUpdated );
3939

40-
connect( mMapSettings, &QgsQuickMapSettings::extentChanged, this, &QgsQuickMapCanvasMap::onExtentChanged );
41-
connect( mMapSettings, &QgsQuickMapSettings::layersChanged, this, &QgsQuickMapCanvasMap::onLayersChanged );
40+
connect( mMapSettings.get(), &QgsQuickMapSettings::extentChanged, this, &QgsQuickMapCanvasMap::onExtentChanged );
41+
connect( mMapSettings.get(), &QgsQuickMapSettings::layersChanged, this, &QgsQuickMapCanvasMap::onLayersChanged );
4242

4343
connect( this, &QgsQuickMapCanvasMap::renderStarting, this, &QgsQuickMapCanvasMap::isRenderingChanged );
4444
connect( this, &QgsQuickMapCanvasMap::mapCanvasRefreshed, this, &QgsQuickMapCanvasMap::isRenderingChanged );
@@ -50,22 +50,13 @@ QgsQuickMapCanvasMap::QgsQuickMapCanvasMap( QQuickItem *parent )
5050
setFlags( QQuickItem::ItemHasContents );
5151
}
5252

53-
QgsQuickMapCanvasMap::~QgsQuickMapCanvasMap()
54-
{
55-
Q_ASSERT( mMapSettings );
56-
delete mMapSettings;
57-
mMapSettings = nullptr;
58-
}
59-
6053
QgsQuickMapSettings *QgsQuickMapCanvasMap::mapSettings() const
6154
{
62-
Q_ASSERT( mMapSettings );
63-
return mMapSettings;
55+
return mMapSettings.get();
6456
}
6557

6658
void QgsQuickMapCanvasMap::zoom( QPointF center, qreal scale )
6759
{
68-
Q_ASSERT( mMapSettings );
6960
QgsRectangle extent = mMapSettings->extent();
7061
QgsPoint oldCenter( extent.center() );
7162
QgsPoint mousePos( mMapSettings->screenToCoordinate( center ) );
@@ -79,7 +70,6 @@ void QgsQuickMapCanvasMap::zoom( QPointF center, qreal scale )
7970

8071
void QgsQuickMapCanvasMap::pan( QPointF oldPos, QPointF newPos )
8172
{
82-
Q_ASSERT( mMapSettings );
8373
QgsPoint start = mMapSettings->screenToCoordinate( oldPos.toPoint() );
8474
QgsPoint end = mMapSettings->screenToCoordinate( newPos.toPoint() );
8575

@@ -99,8 +89,6 @@ void QgsQuickMapCanvasMap::pan( QPointF oldPos, QPointF newPos )
9989

10090
void QgsQuickMapCanvasMap::refreshMap()
10191
{
102-
Q_ASSERT( mMapSettings );
103-
10492
stopRendering(); // if any...
10593

10694
QgsMapSettings mapSettings = mMapSettings->mapSettings();
@@ -194,7 +182,6 @@ void QgsQuickMapCanvasMap::onWindowChanged( QQuickWindow *window )
194182

195183
void QgsQuickMapCanvasMap::onScreenChanged( QScreen *screen )
196184
{
197-
Q_ASSERT( mMapSettings );
198185
if ( screen )
199186
mMapSettings->setOutputDpi( screen->physicalDotsPerInch() );
200187
}
@@ -209,7 +196,6 @@ void QgsQuickMapCanvasMap::onExtentChanged()
209196

210197
void QgsQuickMapCanvasMap::updateTransform()
211198
{
212-
Q_ASSERT( mMapSettings );
213199
QgsMapSettings currentMapSettings = mMapSettings->mapSettings();
214200
QgsMapToPixel mtp = currentMapSettings.mapToPixel();
215201

@@ -317,7 +303,6 @@ QSGNode *QgsQuickMapCanvasMap::updatePaintNode( QSGNode *oldNode, QQuickItem::Up
317303
void QgsQuickMapCanvasMap::geometryChanged( const QRectF &newGeometry, const QRectF &oldGeometry )
318304
{
319305
Q_UNUSED( oldGeometry )
320-
Q_ASSERT( mMapSettings );
321306
// The Qt documentation advices to call the base method here.
322307
// However, this introduces instabilities and heavy performance impacts on Android.
323308
// It seems on desktop disabling it prevents us from downsizing the window...
@@ -330,7 +315,6 @@ void QgsQuickMapCanvasMap::geometryChanged( const QRectF &newGeometry, const QRe
330315

331316
void QgsQuickMapCanvasMap::onLayersChanged()
332317
{
333-
Q_ASSERT( mMapSettings );
334318
if ( mMapSettings->extent().isEmpty() )
335319
zoomToFullExtent();
336320

@@ -369,7 +353,6 @@ void QgsQuickMapCanvasMap::stopRendering()
369353

370354
void QgsQuickMapCanvasMap::zoomToFullExtent()
371355
{
372-
Q_ASSERT( mMapSettings );
373356
QgsRectangle extent;
374357
const QList<QgsMapLayer *> layers = mMapSettings->layers();
375358
for ( QgsMapLayer *layer : layers )
@@ -391,7 +374,6 @@ void QgsQuickMapCanvasMap::zoomToFullExtent()
391374

392375
void QgsQuickMapCanvasMap::refresh()
393376
{
394-
Q_ASSERT( mMapSettings );
395377
if ( mMapSettings->outputSize().isNull() )
396378
return; // the map image size has not been set yet
397379

src/quickgui/qgsquickmapcanvasmap.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef QGSQUICKMAPCANVASMAP_H
1717
#define QGSQUICKMAPCANVASMAP_H
1818

19+
#include <memory>
20+
1921
#include <QtQuick/QQuickItem>
2022
#include <QFutureSynchronizer>
2123
#include <QTimer>
@@ -89,7 +91,7 @@ class QUICK_EXPORT QgsQuickMapCanvasMap : public QQuickItem
8991
public:
9092
//! Create map canvas map
9193
QgsQuickMapCanvasMap( QQuickItem *parent = nullptr );
92-
~QgsQuickMapCanvasMap();
94+
~QgsQuickMapCanvasMap() = default;
9395

9496
virtual QSGNode *updatePaintNode( QSGNode *oldNode, QQuickItem::UpdatePaintNodeData * ) override;
9597

@@ -183,7 +185,7 @@ class QUICK_EXPORT QgsQuickMapCanvasMap : public QQuickItem
183185
void updateTransform();
184186
void zoomToFullExtent();
185187

186-
QgsQuickMapSettings *mMapSettings;
188+
std::unique_ptr<QgsQuickMapSettings> mMapSettings;
187189
bool mPinching = false;
188190
QPoint mPinchStartPoint;
189191
QgsMapRendererParallelJob *mJob = nullptr;

0 commit comments

Comments
 (0)