Code modenization

This commit is contained in:
Matthias Kuhn 2019-04-05 11:22:56 +02:00
parent 870337871a
commit 2bb049ecd1
No known key found for this signature in database
GPG Key ID: 7A7F1A1C90C3E6A7
3 changed files with 24 additions and 34 deletions

View File

@ -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:

View File

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

View File

@ -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