Skip to content
Permalink
Browse files

Merge pull request #9719 from m-kuhn/code_modernization

Code modernization in map canvas
  • Loading branch information
m-kuhn committed Apr 5, 2019
2 parents 8703378 + 2bb049e commit 41a9e6fac18d46cc8438d8f001bf649540059239
Showing with 24 additions and 34 deletions.
  1. +2 −2 python/gui/auto_generated/qgsmapcanvas.sip.in
  2. +20 −30 src/gui/qgsmapcanvas.cpp
  3. +2 −2 src/gui/qgsmapcanvas.h
@@ -28,10 +28,10 @@ Map canvas is a class for displaying all GIS data types on a canvas.
#include "qgsmapcanvas.h"
%End
%ConvertToSubClassCode
if ( dynamic_cast<QgsMapCanvas *>( sipCpp ) != NULL )
if ( qobject_cast<QgsMapCanvas *>( sipCpp ) != nullptr )
sipType = sipType_QgsMapCanvas;
else
sipType = NULL;
sipType = nullptr;
%End
public:

@@ -243,14 +243,7 @@ QgsMapCanvas::~QgsMapCanvas()
// delete canvas items prior to deleting the canvas
// because they might try to update canvas when it's
// already being destructed, ends with segfault
QList<QGraphicsItem *> list = mScene->items();
QList<QGraphicsItem *>::iterator it = list.begin();
while ( it != list.end() )
{
QGraphicsItem *item = *it;
delete item;
++it;
}
qDeleteAll( mScene->items() );

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

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

void QgsMapCanvas::updateCanvasItemPositions()
{
QList<QGraphicsItem *> list = mScene->items();
QList<QGraphicsItem *>::iterator it = list.begin();
while ( it != list.end() )
const QList<QGraphicsItem *> items = mScene->items();
for ( QGraphicsItem *gi : items )
{
QgsMapCanvasItem *item = dynamic_cast<QgsMapCanvasItem *>( *it );
QgsMapCanvasItem *item = dynamic_cast<QgsMapCanvasItem *>( gi );

if ( item )
{
item->updatePosition();
}

++it;
}
}

@@ -1912,7 +1902,8 @@ void QgsMapCanvas::updateAutoRefreshTimer()
// min auto refresh interval stores the smallest interval between layer auto refreshes. We automatically
// trigger a map refresh on this minimum interval
int minAutoRefreshInterval = -1;
Q_FOREACH ( QgsMapLayer *layer, mSettings.layers() )
const auto layers = mSettings.layers();
for ( QgsMapLayer *layer : layers )
{
if ( layer->hasAutoRefreshEnabled() && layer->autoRefreshInterval() > 0 )
minAutoRefreshInterval = minAutoRefreshInterval > 0 ? std::min( layer->autoRefreshInterval(), minAutoRefreshInterval ) : layer->autoRefreshInterval();
@@ -2194,11 +2185,10 @@ bool QgsMapCanvas::event( QEvent *e )
void QgsMapCanvas::refreshAllLayers()
{
// reload all layers in canvas
for ( int i = 0; i < layerCount(); i++ )
const QList<QgsMapLayer *> layers = mapSettings().layers();
for ( QgsMapLayer *layer : layers )
{
QgsMapLayer *l = layer( i );
if ( l )
l->reload();
layer->reload();
}

// clear the cache
@@ -2229,11 +2219,10 @@ void QgsMapCanvas::setSegmentationToleranceType( QgsAbstractGeometry::Segmentati
QList<QgsMapCanvasAnnotationItem *> QgsMapCanvas::annotationItems() const
{
QList<QgsMapCanvasAnnotationItem *> annotationItemList;
QList<QGraphicsItem *> itemList = mScene->items();
QList<QGraphicsItem *>::iterator it = itemList.begin();
for ( ; it != itemList.end(); ++it )
const QList<QGraphicsItem *> items = mScene->items();
for ( QGraphicsItem *gi : items )
{
QgsMapCanvasAnnotationItem *aItem = dynamic_cast< QgsMapCanvasAnnotationItem *>( *it );
QgsMapCanvasAnnotationItem *aItem = dynamic_cast< QgsMapCanvasAnnotationItem *>( gi );
if ( aItem )
{
annotationItemList.push_back( aItem );
@@ -2246,7 +2235,8 @@ QList<QgsMapCanvasAnnotationItem *> QgsMapCanvas::annotationItems() const
void QgsMapCanvas::setAnnotationsVisible( bool show )
{
mAnnotationsVisible = show;
Q_FOREACH ( QgsMapCanvasAnnotationItem *item, annotationItems() )
const QList<QgsMapCanvasAnnotationItem *> items = annotationItems();
for ( QgsMapCanvasAnnotationItem *item : items )
{
item->setVisible( show );
}
@@ -2322,14 +2312,14 @@ void QgsMapCanvas::startPreviewJob( int number )
void QgsMapCanvas::stopPreviewJobs()
{
mPreviewTimer.stop();
QList< QgsMapRendererQImageJob * >::const_iterator it = mPreviewJobs.constBegin();
for ( ; it != mPreviewJobs.constEnd(); ++it )
const auto previewJobs = mPreviewJobs;
for ( auto previewJob : previewJobs )
{
if ( *it )
if ( previewJob )
{
disconnect( *it, &QgsMapRendererJob::finished, this, &QgsMapCanvas::previewJobFinished );
connect( *it, &QgsMapRendererQImageJob::finished, *it, &QgsMapRendererQImageJob::deleteLater );
( *it )->cancelWithoutBlocking();
disconnect( previewJob, &QgsMapRendererJob::finished, this, &QgsMapCanvas::previewJobFinished );
connect( previewJob, &QgsMapRendererQImageJob::finished, previewJob, &QgsMapRendererQImageJob::deleteLater );
previewJob->cancelWithoutBlocking();
}
}
mPreviewJobs.clear();
@@ -75,10 +75,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView

#ifdef SIP_RUN
SIP_CONVERT_TO_SUBCLASS_CODE
if ( dynamic_cast<QgsMapCanvas *>( sipCpp ) != NULL )
if ( qobject_cast<QgsMapCanvas *>( sipCpp ) != nullptr )
sipType = sipType_QgsMapCanvas;
else
sipType = NULL;
sipType = nullptr;
SIP_END
#endif

0 comments on commit 41a9e6f

Please sign in to comment.
You can’t perform that action at this time.