Skip to content

Commit 2bb049e

Browse files
committedApr 5, 2019
Code modenization
1 parent 8703378 commit 2bb049e

File tree

3 files changed

+24
-34
lines changed

3 files changed

+24
-34
lines changed
 

‎python/gui/auto_generated/qgsmapcanvas.sip.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ Map canvas is a class for displaying all GIS data types on a canvas.
2828
#include "qgsmapcanvas.h"
2929
%End
3030
%ConvertToSubClassCode
31-
if ( dynamic_cast<QgsMapCanvas *>( sipCpp ) != NULL )
31+
if ( qobject_cast<QgsMapCanvas *>( sipCpp ) != nullptr )
3232
sipType = sipType_QgsMapCanvas;
3333
else
34-
sipType = NULL;
34+
sipType = nullptr;
3535
%End
3636
public:
3737

‎src/gui/qgsmapcanvas.cpp

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,7 @@ QgsMapCanvas::~QgsMapCanvas()
243243
// delete canvas items prior to deleting the canvas
244244
// because they might try to update canvas when it's
245245
// already being destructed, ends with segfault
246-
QList<QGraphicsItem *> list = mScene->items();
247-
QList<QGraphicsItem *>::iterator it = list.begin();
248-
while ( it != list.end() )
249-
{
250-
QGraphicsItem *item = *it;
251-
delete item;
252-
++it;
253-
}
246+
qDeleteAll( mScene->items() );
254247

255248
mScene->deleteLater(); // crashes in python tests on windows
256249

@@ -1567,18 +1560,15 @@ void QgsMapCanvas::paintEvent( QPaintEvent *e )
15671560

15681561
void QgsMapCanvas::updateCanvasItemPositions()
15691562
{
1570-
QList<QGraphicsItem *> list = mScene->items();
1571-
QList<QGraphicsItem *>::iterator it = list.begin();
1572-
while ( it != list.end() )
1563+
const QList<QGraphicsItem *> items = mScene->items();
1564+
for ( QGraphicsItem *gi : items )
15731565
{
1574-
QgsMapCanvasItem *item = dynamic_cast<QgsMapCanvasItem *>( *it );
1566+
QgsMapCanvasItem *item = dynamic_cast<QgsMapCanvasItem *>( gi );
15751567

15761568
if ( item )
15771569
{
15781570
item->updatePosition();
15791571
}
1580-
1581-
++it;
15821572
}
15831573
}
15841574

@@ -1912,7 +1902,8 @@ void QgsMapCanvas::updateAutoRefreshTimer()
19121902
// min auto refresh interval stores the smallest interval between layer auto refreshes. We automatically
19131903
// trigger a map refresh on this minimum interval
19141904
int minAutoRefreshInterval = -1;
1915-
Q_FOREACH ( QgsMapLayer *layer, mSettings.layers() )
1905+
const auto layers = mSettings.layers();
1906+
for ( QgsMapLayer *layer : layers )
19161907
{
19171908
if ( layer->hasAutoRefreshEnabled() && layer->autoRefreshInterval() > 0 )
19181909
minAutoRefreshInterval = minAutoRefreshInterval > 0 ? std::min( layer->autoRefreshInterval(), minAutoRefreshInterval ) : layer->autoRefreshInterval();
@@ -2194,11 +2185,10 @@ bool QgsMapCanvas::event( QEvent *e )
21942185
void QgsMapCanvas::refreshAllLayers()
21952186
{
21962187
// reload all layers in canvas
2197-
for ( int i = 0; i < layerCount(); i++ )
2188+
const QList<QgsMapLayer *> layers = mapSettings().layers();
2189+
for ( QgsMapLayer *layer : layers )
21982190
{
2199-
QgsMapLayer *l = layer( i );
2200-
if ( l )
2201-
l->reload();
2191+
layer->reload();
22022192
}
22032193

22042194
// clear the cache
@@ -2229,11 +2219,10 @@ void QgsMapCanvas::setSegmentationToleranceType( QgsAbstractGeometry::Segmentati
22292219
QList<QgsMapCanvasAnnotationItem *> QgsMapCanvas::annotationItems() const
22302220
{
22312221
QList<QgsMapCanvasAnnotationItem *> annotationItemList;
2232-
QList<QGraphicsItem *> itemList = mScene->items();
2233-
QList<QGraphicsItem *>::iterator it = itemList.begin();
2234-
for ( ; it != itemList.end(); ++it )
2222+
const QList<QGraphicsItem *> items = mScene->items();
2223+
for ( QGraphicsItem *gi : items )
22352224
{
2236-
QgsMapCanvasAnnotationItem *aItem = dynamic_cast< QgsMapCanvasAnnotationItem *>( *it );
2225+
QgsMapCanvasAnnotationItem *aItem = dynamic_cast< QgsMapCanvasAnnotationItem *>( gi );
22372226
if ( aItem )
22382227
{
22392228
annotationItemList.push_back( aItem );
@@ -2246,7 +2235,8 @@ QList<QgsMapCanvasAnnotationItem *> QgsMapCanvas::annotationItems() const
22462235
void QgsMapCanvas::setAnnotationsVisible( bool show )
22472236
{
22482237
mAnnotationsVisible = show;
2249-
Q_FOREACH ( QgsMapCanvasAnnotationItem *item, annotationItems() )
2238+
const QList<QgsMapCanvasAnnotationItem *> items = annotationItems();
2239+
for ( QgsMapCanvasAnnotationItem *item : items )
22502240
{
22512241
item->setVisible( show );
22522242
}
@@ -2322,14 +2312,14 @@ void QgsMapCanvas::startPreviewJob( int number )
23222312
void QgsMapCanvas::stopPreviewJobs()
23232313
{
23242314
mPreviewTimer.stop();
2325-
QList< QgsMapRendererQImageJob * >::const_iterator it = mPreviewJobs.constBegin();
2326-
for ( ; it != mPreviewJobs.constEnd(); ++it )
2315+
const auto previewJobs = mPreviewJobs;
2316+
for ( auto previewJob : previewJobs )
23272317
{
2328-
if ( *it )
2318+
if ( previewJob )
23292319
{
2330-
disconnect( *it, &QgsMapRendererJob::finished, this, &QgsMapCanvas::previewJobFinished );
2331-
connect( *it, &QgsMapRendererQImageJob::finished, *it, &QgsMapRendererQImageJob::deleteLater );
2332-
( *it )->cancelWithoutBlocking();
2320+
disconnect( previewJob, &QgsMapRendererJob::finished, this, &QgsMapCanvas::previewJobFinished );
2321+
connect( previewJob, &QgsMapRendererQImageJob::finished, previewJob, &QgsMapRendererQImageJob::deleteLater );
2322+
previewJob->cancelWithoutBlocking();
23332323
}
23342324
}
23352325
mPreviewJobs.clear();

‎src/gui/qgsmapcanvas.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
7575

7676
#ifdef SIP_RUN
7777
SIP_CONVERT_TO_SUBCLASS_CODE
78-
if ( dynamic_cast<QgsMapCanvas *>( sipCpp ) != NULL )
78+
if ( qobject_cast<QgsMapCanvas *>( sipCpp ) != nullptr )
7979
sipType = sipType_QgsMapCanvas;
8080
else
81-
sipType = NULL;
81+
sipType = nullptr;
8282
SIP_END
8383
#endif
8484

0 commit comments

Comments
 (0)
Please sign in to comment.