QGIS API Documentation  3.13.0-Master (788156190c)
qgsmapcanvas.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 qgsmapcanvas.cpp - description
3 ------------------ -
4 begin : Sun Jun 30 2002
5 copyright : (C) 2002 by Gary E.Sherman
6 email : sherman at mrcc.com
7 ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include <cmath>
19 
20 #include <QtGlobal>
21 #include <QApplication>
22 #include <QCursor>
23 #include <QDir>
24 #include <QFile>
25 #include <QGraphicsItem>
26 #include <QGraphicsScene>
27 #include <QGraphicsView>
28 #include <QKeyEvent>
29 #include <QPainter>
30 #include <QPaintEvent>
31 #include <QPixmap>
32 #include <QRect>
33 #include <QTextStream>
34 #include <QResizeEvent>
35 #include <QScreen>
36 #include <QString>
37 #include <QStringList>
38 #include <QWheelEvent>
39 #include <QWindow>
40 
41 #include "qgis.h"
42 #include "qgssettings.h"
44 #include "qgsapplication.h"
45 #include "qgsexception.h"
47 #include "qgsfeatureiterator.h"
48 #include "qgslogger.h"
49 #include "qgsmapcanvas.h"
50 #include "qgsmapcanvasmap.h"
52 #include "qgsmaplayer.h"
53 #include "qgsmapmouseevent.h"
54 #include "qgsmaptoolpan.h"
55 #include "qgsmaptoolzoom.h"
56 #include "qgsmaptopixel.h"
57 #include "qgsmapoverviewcanvas.h"
58 #include "qgsmaprenderercache.h"
62 #include "qgsmapsettingsutils.h"
63 #include "qgsmessagelog.h"
64 #include "qgsmessageviewer.h"
65 #include "qgspallabeling.h"
66 #include "qgsproject.h"
67 #include "qgsrubberband.h"
68 #include "qgsvectorlayer.h"
69 #include "qgsmapthemecollection.h"
71 #include "qgssvgcache.h"
72 #include "qgsimagecache.h"
74 #include "qgsmimedatautils.h"
75 #include "qgscustomdrophandler.h"
76 #include "qgsreferencedgeometry.h"
77 #include "qgsprojectviewsettings.h"
79 #include "qgstemporalcontroller.h"
80 
86 //TODO QGIS 4.0 - remove
88 {
89  public:
90 
94  CanvasProperties() = default;
95 
97  bool mouseButtonDown{ false };
98 
100  QPoint mouseLastXY;
101 
103  QPoint rubberStartPoint;
104 
106  bool panSelectorDown{ false };
107 };
108 
109 
110 
111 QgsMapCanvas::QgsMapCanvas( QWidget *parent )
112  : QGraphicsView( parent )
113  , mCanvasProperties( new CanvasProperties )
114  , mExpressionContextScope( tr( "Map Canvas" ) )
115 {
116  mScene = new QGraphicsScene();
117  setScene( mScene );
118  setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
119  setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
120  setMouseTracking( true );
121  setFocusPolicy( Qt::StrongFocus );
122 
123  mResizeTimer = new QTimer( this );
124  mResizeTimer->setSingleShot( true );
125  connect( mResizeTimer, &QTimer::timeout, this, &QgsMapCanvas::refresh );
126 
127  mRefreshTimer = new QTimer( this );
128  mRefreshTimer->setSingleShot( true );
129  connect( mRefreshTimer, &QTimer::timeout, this, &QgsMapCanvas::refreshMap );
130 
131  // create map canvas item which will show the map
132  mMap = new QgsMapCanvasMap( this );
133 
134  // project handling
136  this, &QgsMapCanvas::readProject );
139 
140  connect( QgsProject::instance()->mapThemeCollection(), &QgsMapThemeCollection::mapThemeChanged, this, &QgsMapCanvas::mapThemeChanged );
141  connect( QgsProject::instance()->mapThemeCollection(), &QgsMapThemeCollection::mapThemesChanged, this, &QgsMapCanvas::projectThemesChanged );
142 
143  mSettings.setFlag( QgsMapSettings::DrawEditingInfo );
144  mSettings.setFlag( QgsMapSettings::UseRenderingOptimization );
145  mSettings.setFlag( QgsMapSettings::RenderPartialOutput );
146  mSettings.setEllipsoid( QgsProject::instance()->ellipsoid() );
148  this, [ = ]
149  {
150  mSettings.setEllipsoid( QgsProject::instance()->ellipsoid() );
151  refresh();
152  } );
153  mSettings.setTransformContext( QgsProject::instance()->transformContext() );
155  this, [ = ]
156  {
157  mSettings.setTransformContext( QgsProject::instance()->transformContext() );
158  emit transformContextChanged();
159  refresh();
160  } );
161 
162  // refresh canvas when a remote svg/image has finished downloading
165  // refresh canvas when project color scheme is changed -- if layers use project colors, they need to be redrawn
167 
168  //segmentation parameters
169  QgsSettings settings;
170  double segmentationTolerance = settings.value( QStringLiteral( "qgis/segmentationTolerance" ), "0.01745" ).toDouble();
171  QgsAbstractGeometry::SegmentationToleranceType toleranceType = settings.enumValue( QStringLiteral( "qgis/segmentationToleranceType" ), QgsAbstractGeometry::MaximumAngle );
172  mSettings.setSegmentationTolerance( segmentationTolerance );
173  mSettings.setSegmentationToleranceType( toleranceType );
174 
175  mWheelZoomFactor = settings.value( QStringLiteral( "qgis/zoom_factor" ), 2 ).toDouble();
176 
177  QSize s = viewport()->size();
178  mSettings.setOutputSize( s );
179  mSettings.setDevicePixelRatio( devicePixelRatio() );
180  setSceneRect( 0, 0, s.width(), s.height() );
181  mScene->setSceneRect( QRectF( 0, 0, s.width(), s.height() ) );
182 
183  moveCanvasContents( true );
184 
185  // keep device pixel ratio up to date on screen or resolution change
186  if ( window()->windowHandle() )
187  {
188  connect( window()->windowHandle(), &QWindow::screenChanged, this, [ = ]( QScreen * ) {mSettings.setDevicePixelRatio( devicePixelRatio() );} );
189  connect( window()->windowHandle()->screen(), &QScreen::physicalDotsPerInchChanged, this, [ = ]( qreal ) {mSettings.setDevicePixelRatio( devicePixelRatio() );} );
190  }
191 
192  connect( &mMapUpdateTimer, &QTimer::timeout, this, &QgsMapCanvas::mapUpdateTimeout );
193  mMapUpdateTimer.setInterval( 250 );
194 
195 #ifdef Q_OS_WIN
196  // Enable touch event on Windows.
197  // Qt on Windows needs to be told it can take touch events or else it ignores them.
198  grabGesture( Qt::PinchGesture );
199  grabGesture( Qt::TapAndHoldGesture );
200  viewport()->setAttribute( Qt::WA_AcceptTouchEvents );
201 #endif
202 
203  mPreviewEffect = new QgsPreviewEffect( this );
204  viewport()->setGraphicsEffect( mPreviewEffect );
205 
206  mZoomCursor = QgsApplication::getThemeCursor( QgsApplication::Cursor::ZoomIn );
207 
208  connect( &mAutoRefreshTimer, &QTimer::timeout, this, &QgsMapCanvas::autoRefreshTriggered );
209 
211 
212  setInteractive( false );
213 
214  // make sure we have the same default in QgsMapSettings and the scene's background brush
215  // (by default map settings has white bg color, scene background brush is black)
216  setCanvasColor( mSettings.backgroundColor() );
217 
218  setTemporalRange( mSettings.temporalRange() );
219 
220  refresh();
221 
222 } // QgsMapCanvas ctor
223 
224 
226 {
227  if ( mMapTool )
228  {
229  mMapTool->deactivate();
230  mMapTool = nullptr;
231  }
232  mLastNonZoomMapTool = nullptr;
233 
234  // rendering job may still end up writing into canvas map item
235  // so kill it before deleting canvas items
236  if ( mJob )
237  {
238  whileBlocking( mJob )->cancel();
239  delete mJob;
240  }
241 
242  QList< QgsMapRendererQImageJob * >::const_iterator previewJob = mPreviewJobs.constBegin();
243  for ( ; previewJob != mPreviewJobs.constEnd(); ++previewJob )
244  {
245  if ( *previewJob )
246  {
247  whileBlocking( *previewJob )->cancel();
248  delete *previewJob;
249  }
250  }
251 
252  // delete canvas items prior to deleting the canvas
253  // because they might try to update canvas when it's
254  // already being destructed, ends with segfault
255  qDeleteAll( mScene->items() );
256 
257  mScene->deleteLater(); // crashes in python tests on windows
258 
259  delete mCache;
260  delete mLabelingResults;
261 }
262 
264 {
265  // do not go higher or lower than min max magnification ratio
266  double magnifierMin = QgsGuiUtils::CANVAS_MAGNIFICATION_MIN;
267  double magnifierMax = QgsGuiUtils::CANVAS_MAGNIFICATION_MAX;
268  factor = qBound( magnifierMin, factor, magnifierMax );
269 
270  // the magnifier widget is in integer percent
271  if ( !qgsDoubleNear( factor, mSettings.magnificationFactor(), 0.01 ) )
272  {
273  mSettings.setMagnificationFactor( factor );
274  refresh();
275  emit magnificationChanged( factor );
276  }
277 }
278 
280 {
281  return mSettings.magnificationFactor();
282 }
283 
285 {
286  mSettings.setFlag( QgsMapSettings::Antialiasing, flag );
287 } // anti aliasing
288 
290 {
291  mSettings.setFlag( QgsMapSettings::RenderMapTile, flag );
292 }
293 
295 {
296  QList<QgsMapLayer *> layers = mapSettings().layers();
297  if ( index >= 0 && index < layers.size() )
298  return layers[index];
299  else
300  return nullptr;
301 }
302 
304 {
305  if ( mCurrentLayer == layer )
306  return;
307 
308  mCurrentLayer = layer;
309  emit currentLayerChanged( layer );
310 }
311 
312 double QgsMapCanvas::scale() const
313 {
314  return mapSettings().scale();
315 }
316 
318 {
319  return nullptr != mJob;
320 } // isDrawing
321 
322 // return the current coordinate transform based on the extents and
323 // device size
325 {
326  return &mapSettings().mapToPixel();
327 }
328 
329 void QgsMapCanvas::setLayers( const QList<QgsMapLayer *> &layers )
330 {
331  // following a theme => request denied!
332  if ( !mTheme.isEmpty() )
333  return;
334 
335  setLayersPrivate( layers );
336 }
337 
338 void QgsMapCanvas::setLayersPrivate( const QList<QgsMapLayer *> &layers )
339 {
340  QList<QgsMapLayer *> oldLayers = mSettings.layers();
341 
342  // update only if needed
343  if ( layers == oldLayers )
344  return;
345 
346  const auto constOldLayers = oldLayers;
347  for ( QgsMapLayer *layer : constOldLayers )
348  {
349  disconnect( layer, &QgsMapLayer::repaintRequested, this, &QgsMapCanvas::layerRepaintRequested );
350  disconnect( layer, &QgsMapLayer::autoRefreshIntervalChanged, this, &QgsMapCanvas::updateAutoRefreshTimer );
351  if ( QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer ) )
352  {
354  }
355  }
356 
357  mSettings.setLayers( layers );
358 
359  const auto constLayers = layers;
360  for ( QgsMapLayer *layer : constLayers )
361  {
362  if ( !layer )
363  continue;
364  connect( layer, &QgsMapLayer::repaintRequested, this, &QgsMapCanvas::layerRepaintRequested );
365  connect( layer, &QgsMapLayer::autoRefreshIntervalChanged, this, &QgsMapCanvas::updateAutoRefreshTimer );
366  if ( QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer ) )
367  {
369  }
370  }
371 
372  QgsDebugMsgLevel( QStringLiteral( "Layers have changed, refreshing" ), 2 );
373  emit layersChanged();
374 
375  updateAutoRefreshTimer();
376  refresh();
377 }
378 
379 
381 {
382  return mSettings;
383 }
384 
386 {
387  if ( mSettings.destinationCrs() == crs )
388  return;
389 
390  // try to reproject current extent to the new one
391  QgsRectangle rect;
392  if ( !mSettings.visibleExtent().isEmpty() )
393  {
394  QgsCoordinateTransform transform( mSettings.destinationCrs(), crs, QgsProject::instance() );
395  try
396  {
397  rect = transform.transformBoundingBox( mSettings.visibleExtent() );
398  }
399  catch ( QgsCsException &e )
400  {
401  Q_UNUSED( e )
402  QgsDebugMsg( QStringLiteral( "Transform error caught: %1" ).arg( e.what() ) );
403  }
404  }
405 
406  if ( !rect.isEmpty() )
407  {
408  setExtent( rect );
409  }
410 
411  mSettings.setDestinationCrs( crs );
412  updateScale();
413 
414  QgsDebugMsgLevel( QStringLiteral( "refreshing after destination CRS changed" ), 2 );
415  refresh();
416 
417  emit destinationCrsChanged();
418 }
419 
421 {
422  if ( mController )
424 
425  mController = controller;
427 }
428 
429 void QgsMapCanvas::setMapSettingsFlags( QgsMapSettings::Flags flags )
430 {
431  mSettings.setFlags( flags );
432  clearCache();
433  refresh();
434 }
435 
437 {
438  return mLabelingResults;
439 }
440 
442 {
443  if ( enabled == isCachingEnabled() )
444  return;
445 
446  if ( mJob && mJob->isActive() )
447  {
448  // wait for the current rendering to finish, before touching the cache
449  mJob->waitForFinished();
450  }
451 
452  if ( enabled )
453  {
454  mCache = new QgsMapRendererCache;
455  }
456  else
457  {
458  delete mCache;
459  mCache = nullptr;
460  }
461 }
462 
464 {
465  return nullptr != mCache;
466 }
467 
469 {
470  if ( mCache )
471  mCache->clear();
472 }
473 
475 {
476  mUseParallelRendering = enabled;
477 }
478 
480 {
481  return mUseParallelRendering;
482 }
483 
484 void QgsMapCanvas::setMapUpdateInterval( int timeMilliseconds )
485 {
486  mMapUpdateTimer.setInterval( timeMilliseconds );
487 }
488 
490 {
491  return mMapUpdateTimer.interval();
492 }
493 
494 
496 {
497  return mCurrentLayer;
498 }
499 
501 {
502  QgsExpressionContextScope *s = new QgsExpressionContextScope( QObject::tr( "Map Canvas" ) );
503  s->setVariable( QStringLiteral( "canvas_cursor_point" ), QgsGeometry::fromPointXY( cursorPoint() ), true );
504 
505  return s;
506 }
507 
509 {
510  if ( !mSettings.hasValidSettings() )
511  {
512  QgsDebugMsgLevel( QStringLiteral( "CANVAS refresh - invalid settings -> nothing to do" ), 2 );
513  return;
514  }
515 
516  if ( !mRenderFlag || mFrozen )
517  {
518  QgsDebugMsgLevel( QStringLiteral( "CANVAS render flag off" ), 2 );
519  return;
520  }
521 
522  if ( mRefreshScheduled )
523  {
524  QgsDebugMsgLevel( QStringLiteral( "CANVAS refresh already scheduled" ), 2 );
525  return;
526  }
527 
528  mRefreshScheduled = true;
529 
530  QgsDebugMsgLevel( QStringLiteral( "CANVAS refresh scheduling" ), 2 );
531 
532  // schedule a refresh
533  mRefreshTimer->start( 1 );
534 }
535 
536 void QgsMapCanvas::refreshMap()
537 {
538  Q_ASSERT( mRefreshScheduled );
539 
540  QgsDebugMsgLevel( QStringLiteral( "CANVAS refresh!" ), 3 );
541 
542  stopRendering(); // if any...
543  stopPreviewJobs();
544 
545  //build the expression context
546  QgsExpressionContext expressionContext;
547  expressionContext << QgsExpressionContextUtils::globalScope()
552  << new QgsExpressionContextScope( mExpressionContextScope );
553 
554  mSettings.setExpressionContext( expressionContext );
555  mSettings.setPathResolver( QgsProject::instance()->pathResolver() );
556 
557  if ( !mTheme.isEmpty() )
558  {
559  // IMPORTANT: we MUST set the layer style overrides here! (At the time of writing this
560  // comment) retrieving layer styles from the theme collection gives an XML snapshot of the
561  // current state of the style. If we had stored the style overrides earlier (such as in
562  // mapThemeChanged slot) then this xml could be out of date...
563  // TODO: if in future QgsMapThemeCollection::mapThemeStyleOverrides is changed to
564  // just return the style name, we can instead set the overrides in mapThemeChanged and not here
565  mSettings.setLayerStyleOverrides( QgsProject::instance()->mapThemeCollection()->mapThemeStyleOverrides( mTheme ) );
566  }
567 
568  // create the renderer job
569  Q_ASSERT( !mJob );
570  mJobCanceled = false;
571  if ( mUseParallelRendering )
572  mJob = new QgsMapRendererParallelJob( mSettings );
573  else
574  mJob = new QgsMapRendererSequentialJob( mSettings );
575  connect( mJob, &QgsMapRendererJob::finished, this, &QgsMapCanvas::rendererJobFinished );
576  mJob->setCache( mCache );
577 
578  mJob->start();
579 
580  // from now on we can accept refresh requests again
581  // this must be reset only after the job has been started, because
582  // some providers (yes, it's you WCS and AMS!) during preparation
583  // do network requests and start an internal event loop, which may
584  // end up calling refresh() and would schedule another refresh,
585  // deleting the one we have just started.
586  mRefreshScheduled = false;
587 
588  mMapUpdateTimer.start();
589 
590  emit renderStarting();
591 }
592 
593 void QgsMapCanvas::mapThemeChanged( const QString &theme )
594 {
595  if ( theme == mTheme )
596  {
597  // set the canvas layers to match the new layers contained in the map theme
598  // NOTE: we do this when the theme layers change and not when we are refreshing the map
599  // as setLayers() sets up necessary connections to handle changes to the layers
600  setLayersPrivate( QgsProject::instance()->mapThemeCollection()->mapThemeVisibleLayers( mTheme ) );
601  // IMPORTANT: we don't set the layer style overrides here! (At the time of writing this
602  // comment) retrieving layer styles from the theme collection gives an XML snapshot of the
603  // current state of the style. If changes were made to the style then this xml
604  // snapshot goes out of sync...
605  // TODO: if in future QgsMapThemeCollection::mapThemeStyleOverrides is changed to
606  // just return the style name, we can instead set the overrides here and not in refreshMap()
607 
608  clearCache();
609  refresh();
610  }
611 }
612 
613 void QgsMapCanvas::rendererJobFinished()
614 {
615  QgsDebugMsgLevel( QStringLiteral( "CANVAS finish! %1" ).arg( !mJobCanceled ), 2 );
616 
617  mMapUpdateTimer.stop();
618 
619  // TODO: would be better to show the errors in message bar
620  const auto constErrors = mJob->errors();
621  for ( const QgsMapRendererJob::Error &error : constErrors )
622  {
623  QgsMapLayer *layer = QgsProject::instance()->mapLayer( error.layerID );
624  emit renderErrorOccurred( error.message, layer );
625  QgsMessageLog::logMessage( error.layerID + " :: " + error.message, tr( "Rendering" ) );
626  }
627 
628  if ( !mJobCanceled )
629  {
630  // take labeling results before emitting renderComplete, so labeling map tools
631  // connected to signal work with correct results
632  if ( !mJob->usedCachedLabels() )
633  {
634  delete mLabelingResults;
635  mLabelingResults = mJob->takeLabelingResults();
636  }
637 
638  QImage img = mJob->renderedImage();
639 
640  // emit renderComplete to get our decorations drawn
641  QPainter p( &img );
642  emit renderComplete( &p );
643 
644  QgsSettings settings;
645  if ( settings.value( QStringLiteral( "Map/logCanvasRefreshEvent" ), false ).toBool() )
646  {
647  QString logMsg = tr( "Canvas refresh: %1 ms" ).arg( mJob->renderingTime() );
648  QgsMessageLog::logMessage( logMsg, tr( "Rendering" ) );
649  }
650 
651  if ( mDrawRenderingStats )
652  {
653  int w = img.width(), h = img.height();
654  QFont fnt = p.font();
655  fnt.setBold( true );
656  p.setFont( fnt );
657  int lh = p.fontMetrics().height() * 2;
658  QRect r( 0, h - lh, w, lh );
659  p.setPen( Qt::NoPen );
660  p.setBrush( QColor( 0, 0, 0, 110 ) );
661  p.drawRect( r );
662  p.setPen( Qt::white );
663  QString msg = QStringLiteral( "%1 :: %2 ms" ).arg( mUseParallelRendering ? QStringLiteral( "PARALLEL" ) : QStringLiteral( "SEQUENTIAL" ) ).arg( mJob->renderingTime() );
664  p.drawText( r, msg, QTextOption( Qt::AlignCenter ) );
665  }
666 
667  p.end();
668 
669  mMap->setContent( img, imageRect( img, mSettings ) );
670 
671  mLastLayerRenderTime.clear();
672  const auto times = mJob->perLayerRenderingTime();
673  for ( auto it = times.constBegin(); it != times.constEnd(); ++it )
674  {
675  mLastLayerRenderTime.insert( it.key()->id(), it.value() );
676  }
677  if ( mUsePreviewJobs )
678  startPreviewJobs();
679  }
680 
681  // now we are in a slot called from mJob - do not delete it immediately
682  // so the class is still valid when the execution returns to the class
683  mJob->deleteLater();
684  mJob = nullptr;
685 
686  emit mapCanvasRefreshed();
687 }
688 
689 void QgsMapCanvas::previewJobFinished()
690 {
691  QgsMapRendererQImageJob *job = qobject_cast<QgsMapRendererQImageJob *>( sender() );
692  Q_ASSERT( job );
693 
694  if ( mMap )
695  {
696  mMap->addPreviewImage( job->renderedImage(), job->mapSettings().extent() );
697  mPreviewJobs.removeAll( job );
698 
699  int number = job->property( "number" ).toInt();
700  if ( number < 8 )
701  {
702  startPreviewJob( number + 1 );
703  }
704 
705  delete job;
706  }
707 }
708 
709 QgsRectangle QgsMapCanvas::imageRect( const QImage &img, const QgsMapSettings &mapSettings )
710 {
711  // This is a hack to pass QgsMapCanvasItem::setRect what it
712  // expects (encoding of position and size of the item)
713  const QgsMapToPixel &m2p = mapSettings.mapToPixel();
714  QgsPointXY topLeft = m2p.toMapCoordinates( 0, 0 );
715 #ifdef QGISDEBUG
716  // do not assert this, since it might lead to crashes when changing screen while rendering
717  if ( img.devicePixelRatio() != mapSettings.devicePixelRatio() )
718  {
719  QgsLogger::warning( QStringLiteral( "The renderer map has a wrong device pixel ratio" ) );
720  }
721 #endif
722  double res = m2p.mapUnitsPerPixel() / img.devicePixelRatioF();
723  QgsRectangle rect( topLeft.x(), topLeft.y(), topLeft.x() + img.width()*res, topLeft.y() - img.height()*res );
724  return rect;
725 }
726 
728 {
729  return mUsePreviewJobs;
730 }
731 
733 {
734  mUsePreviewJobs = enabled;
735 }
736 
737 void QgsMapCanvas::setCustomDropHandlers( const QVector<QPointer<QgsCustomDropHandler> > &handlers )
738 {
739  mDropHandlers = handlers;
740 }
741 
742 void QgsMapCanvas::setTemporalRange( const QgsDateTimeRange &dateTimeRange )
743 {
744  if ( temporalRange() == dateTimeRange )
745  return;
746 
747  mSettings.setTemporalRange( dateTimeRange );
748 
749  if ( mCache )
750  {
751  // we need to discard any previously cached images which have temporal properties enabled, so that these will be updated when
752  // the canvas is redrawn
753  const QList<QgsMapLayer *> layerList = mapSettings().layers();
754  for ( QgsMapLayer *layer : layerList )
755  {
757  mCache->invalidateCacheForLayer( layer );
758  }
759  }
760 
761  emit temporalRangeChanged();
762 
763  autoRefreshTriggered();
764 }
765 
766 const QgsDateTimeRange &QgsMapCanvas::temporalRange() const
767 {
768  return mSettings.temporalRange();
769 }
770 
771 void QgsMapCanvas::mapUpdateTimeout()
772 {
773  if ( mJob )
774  {
775  const QImage &img = mJob->renderedImage();
776  mMap->setContent( img, imageRect( img, mSettings ) );
777  }
778 }
779 
781 {
782  if ( mJob )
783  {
784  QgsDebugMsgLevel( QStringLiteral( "CANVAS stop rendering!" ), 2 );
785  mJobCanceled = true;
786  disconnect( mJob, &QgsMapRendererJob::finished, this, &QgsMapCanvas::rendererJobFinished );
787  connect( mJob, &QgsMapRendererQImageJob::finished, mJob, &QgsMapRendererQImageJob::deleteLater );
788  mJob->cancelWithoutBlocking();
789  mJob = nullptr;
790  }
791  stopPreviewJobs();
792 }
793 
794 //the format defaults to "PNG" if not specified
795 void QgsMapCanvas::saveAsImage( const QString &fileName, QPixmap *theQPixmap, const QString &format )
796 {
797  QPainter painter;
798  QImage image;
799 
800  //
801  //check if the optional QPaintDevice was supplied
802  //
803  if ( theQPixmap )
804  {
805  image = theQPixmap->toImage();
806  painter.begin( &image );
807 
808  // render
809  QgsMapRendererCustomPainterJob job( mSettings, &painter );
810  job.start();
811  job.waitForFinished();
812  emit renderComplete( &painter );
813  }
814  else //use the map view
815  {
816  image = mMap->contentImage().copy();
817  painter.begin( &image );
818  }
819 
820  // draw annotations
821  QStyleOptionGraphicsItem option;
822  option.initFrom( this );
823  QGraphicsItem *item = nullptr;
824  QListIterator<QGraphicsItem *> i( items() );
825  i.toBack();
826  while ( i.hasPrevious() )
827  {
828  item = i.previous();
829 
830  if ( !( item && dynamic_cast< QgsMapCanvasAnnotationItem * >( item ) ) )
831  {
832  continue;
833  }
834 
835  painter.save();
836 
837  QPointF itemScenePos = item->scenePos();
838  painter.translate( itemScenePos.x(), itemScenePos.y() );
839 
840  item->paint( &painter, &option );
841 
842  painter.restore();
843  }
844 
845  painter.end();
846  image.save( fileName, format.toLocal8Bit().data() );
847 
848  QFileInfo myInfo = QFileInfo( fileName );
849 
850  // build the world file name
851  QString outputSuffix = myInfo.suffix();
852  QString myWorldFileName = myInfo.absolutePath() + '/' + myInfo.baseName() + '.'
853  + outputSuffix.at( 0 ) + outputSuffix.at( myInfo.suffix().size() - 1 ) + 'w';
854  QFile myWorldFile( myWorldFileName );
855  if ( !myWorldFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) ) //don't use QIODevice::Text
856  {
857  return;
858  }
859  QTextStream myStream( &myWorldFile );
861 } // saveAsImage
862 
863 
864 
866 {
867  return mapSettings().visibleExtent();
868 } // extent
869 
871 {
872  return mapSettings().fullExtent();
873 } // extent
874 
875 
876 void QgsMapCanvas::setExtent( const QgsRectangle &r, bool magnified )
877 {
878  QgsRectangle current = extent();
879 
880  if ( ( r == current ) && magnified )
881  return;
882 
883  if ( r.isEmpty() )
884  {
885  if ( !mSettings.hasValidSettings() )
886  {
887  // we can't even just move the map center
888  QgsDebugMsgLevel( QStringLiteral( "Empty extent - ignoring" ), 2 );
889  return;
890  }
891 
892  // ### QGIS 3: do not allow empty extent - require users to call setCenter() explicitly
893  QgsDebugMsgLevel( QStringLiteral( "Empty extent - keeping old scale with new center!" ), 2 );
894  setCenter( r.center() );
895  }
896  else
897  {
898  mSettings.setExtent( r, magnified );
899  }
900  emit extentsChanged();
901  updateScale();
902  if ( mLastExtent.size() > 20 )
903  mLastExtent.removeAt( 0 );
904 
905  //clear all extent items after current index
906  for ( int i = mLastExtent.size() - 1; i > mLastExtentIndex; i-- )
907  {
908  mLastExtent.removeAt( i );
909  }
910 
911  mLastExtent.append( extent() );
912 
913  // adjust history to no more than 20
914  if ( mLastExtent.size() > 20 )
915  {
916  mLastExtent.removeAt( 0 );
917  }
918 
919  // the last item is the current extent
920  mLastExtentIndex = mLastExtent.size() - 1;
921 
922  // update controls' enabled state
923  emit zoomLastStatusChanged( mLastExtentIndex > 0 );
924  emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 );
925 }
926 
928 {
929  QgsRectangle canvasExtent = extent;
930  if ( extent.crs() != mapSettings().destinationCrs() )
931  {
932  QgsCoordinateTransform ct( extent.crs(), mapSettings().destinationCrs(), QgsProject::instance() );
933  canvasExtent = ct.transform( extent );
934 
935  if ( canvasExtent.isEmpty() )
936  {
937  return false;
938  }
939  }
940 
941  setExtent( canvasExtent, true );
942  return true;
943 }
944 
945 void QgsMapCanvas::setCenter( const QgsPointXY &center )
946 {
947  const QgsRectangle r = mapSettings().extent();
948  const double x = center.x();
949  const double y = center.y();
950  const QgsRectangle rect(
951  x - r.width() / 2.0, y - r.height() / 2.0,
952  x + r.width() / 2.0, y + r.height() / 2.0
953  );
954  if ( ! rect.isEmpty() )
955  {
956  setExtent(
957  rect,
958  true
959  );
960  }
961 } // setCenter
962 
964 {
966  return r.center();
967 }
968 
969 QgsPointXY QgsMapCanvas::cursorPoint() const
970 {
971  return mCursorPoint;
972 }
973 
975 {
976  return mapSettings().rotation();
977 } // rotation
978 
979 void QgsMapCanvas::setRotation( double degrees )
980 {
981  double current = rotation();
982 
983  if ( qgsDoubleNear( degrees, current ) )
984  return;
985 
986  mSettings.setRotation( degrees );
987  emit rotationChanged( degrees );
988  emit extentsChanged(); // visible extent changes with rotation
989 } // setRotation
990 
991 
993 {
994  emit scaleChanged( mapSettings().scale() );
995 }
996 
997 
999 {
1001  // If the full extent is an empty set, don't do the zoom
1002  if ( !extent.isEmpty() )
1003  {
1004  // Add a 5% margin around the full extent
1005  extent.scale( 1.05 );
1006  setExtent( extent );
1007  }
1008  refresh();
1009 
1010 } // zoomToFullExtent
1011 
1012 
1014 {
1015  if ( mLastExtentIndex > 0 )
1016  {
1017  mLastExtentIndex--;
1018  mSettings.setExtent( mLastExtent[mLastExtentIndex] );
1019  emit extentsChanged();
1020  updateScale();
1021  refresh();
1022  // update controls' enabled state
1023  emit zoomLastStatusChanged( mLastExtentIndex > 0 );
1024  emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 );
1025  }
1026 
1027 } // zoomToPreviousExtent
1028 
1030 {
1031  if ( mLastExtentIndex < mLastExtent.size() - 1 )
1032  {
1033  mLastExtentIndex++;
1034  mSettings.setExtent( mLastExtent[mLastExtentIndex] );
1035  emit extentsChanged();
1036  updateScale();
1037  refresh();
1038  // update controls' enabled state
1039  emit zoomLastStatusChanged( mLastExtentIndex > 0 );
1040  emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 );
1041  }
1042 }// zoomToNextExtent
1043 
1045 {
1046  mLastExtent.clear(); // clear the zoom history list
1047  mLastExtent.append( extent() ) ; // set the current extent in the list
1048  mLastExtentIndex = mLastExtent.size() - 1;
1049  // update controls' enabled state
1050  emit zoomLastStatusChanged( mLastExtentIndex > 0 );
1051  emit zoomNextStatusChanged( mLastExtentIndex < mLastExtent.size() - 1 );
1052 }// clearExtentHistory
1053 
1055 {
1056  if ( !layer )
1057  {
1058  // use current layer by default
1059  layer = qobject_cast<QgsVectorLayer *>( mCurrentLayer );
1060  }
1061 
1062  if ( !layer || !layer->isSpatial() || layer->selectedFeatureCount() == 0 )
1063  return;
1064 
1065  QgsRectangle rect = layer->boundingBoxOfSelected();
1066  if ( rect.isNull() )
1067  {
1068  emit messageEmitted( tr( "Cannot zoom to selected feature(s)" ), tr( "No extent could be determined." ), Qgis::Warning );
1069  return;
1070  }
1071 
1072  rect = mapSettings().layerExtentToOutputExtent( layer, rect );
1073 
1074  // zoom in if point cannot be distinguished from others
1075  // also check that rect is empty, as it might not in case of multi points
1076  if ( layer->geometryType() == QgsWkbTypes::PointGeometry && rect.isEmpty() )
1077  {
1078  int scaleFactor = 5;
1079  QgsPointXY centerMapCoordinates = rect.center();
1080  QgsPointXY centerLayerCoordinates = mSettings.mapToLayerCoordinates( layer, centerMapCoordinates );
1081  QgsRectangle extentRect = mSettings.mapToLayerCoordinates( layer, extent() ).scaled( 1.0 / scaleFactor, &centerLayerCoordinates );
1083  QgsFeatureIterator fit = layer->getFeatures( req );
1084  QgsFeature f;
1085  QgsPointXY closestPoint;
1086  double closestSquaredDistance = pow( extentRect.width(), 2.0 ) + pow( extentRect.height(), 2.0 );
1087  bool pointFound = false;
1088  while ( fit.nextFeature( f ) )
1089  {
1090  QgsPointXY point = f.geometry().asPoint();
1091  double sqrDist = point.sqrDist( centerLayerCoordinates );
1092  if ( sqrDist > closestSquaredDistance || sqrDist < 4 * std::numeric_limits<double>::epsilon() )
1093  continue;
1094  pointFound = true;
1095  closestPoint = point;
1096  closestSquaredDistance = sqrDist;
1097  }
1098  if ( pointFound )
1099  {
1100  // combine selected point with closest point and scale this rect
1101  rect.combineExtentWith( mSettings.layerToMapCoordinates( layer, closestPoint ) );
1102  rect.scale( scaleFactor, &centerMapCoordinates );
1103  }
1104  }
1105 
1106  zoomToFeatureExtent( rect );
1107 }
1108 
1110 {
1111  // no selected features, only one selected point feature
1112  //or two point features with the same x- or y-coordinates
1113  if ( rect.isEmpty() )
1114  {
1115  // zoom in
1116  QgsPointXY c = rect.center();
1117  rect = extent();
1118  rect.scale( 1.0, &c );
1119  }
1120  //zoom to an area
1121  else
1122  {
1123  // Expand rect to give a bit of space around the selected
1124  // objects so as to keep them clear of the map boundaries
1125  // The same 5% should apply to all margins.
1126  rect.scale( 1.05 );
1127  }
1128 
1129  setExtent( rect );
1130  refresh();
1131 }
1132 
1134 {
1135  if ( !layer )
1136  {
1137  return;
1138  }
1139 
1140  QgsRectangle bbox;
1141  QString errorMsg;
1142  if ( boundingBoxOfFeatureIds( ids, layer, bbox, errorMsg ) )
1143  {
1144  zoomToFeatureExtent( bbox );
1145  }
1146  else
1147  {
1148  emit messageEmitted( tr( "Zoom to feature id failed" ), errorMsg, Qgis::Warning );
1149  }
1150 
1151 }
1152 
1153 void QgsMapCanvas::panToFeatureIds( QgsVectorLayer *layer, const QgsFeatureIds &ids, bool alwaysRecenter )
1154 {
1155  if ( !layer )
1156  {
1157  return;
1158  }
1159 
1160  QgsRectangle bbox;
1161  QString errorMsg;
1162  if ( boundingBoxOfFeatureIds( ids, layer, bbox, errorMsg ) )
1163  {
1164  if ( alwaysRecenter || !mapSettings().extent().contains( bbox ) )
1165  setCenter( bbox.center() );
1166  refresh();
1167  }
1168  else
1169  {
1170  emit messageEmitted( tr( "Pan to feature id failed" ), errorMsg, Qgis::Warning );
1171  }
1172 }
1173 
1174 bool QgsMapCanvas::boundingBoxOfFeatureIds( const QgsFeatureIds &ids, QgsVectorLayer *layer, QgsRectangle &bbox, QString &errorMsg ) const
1175 {
1176  QgsFeatureIterator it = layer->getFeatures( QgsFeatureRequest().setFilterFids( ids ).setNoAttributes() );
1177  bbox.setMinimal();
1178  QgsFeature fet;
1179  int featureCount = 0;
1180  errorMsg.clear();
1181 
1182  while ( it.nextFeature( fet ) )
1183  {
1184  QgsGeometry geom = fet.geometry();
1185  if ( geom.isNull() )
1186  {
1187  errorMsg = tr( "Feature does not have a geometry" );
1188  }
1189  else if ( geom.constGet()->isEmpty() )
1190  {
1191  errorMsg = tr( "Feature geometry is empty" );
1192  }
1193  if ( !errorMsg.isEmpty() )
1194  {
1195  return false;
1196  }
1198  bbox.combineExtentWith( r );
1199  featureCount++;
1200  }
1201 
1202  if ( featureCount != ids.count() )
1203  {
1204  errorMsg = tr( "Feature not found" );
1205  return false;
1206  }
1207 
1208  return true;
1209 }
1210 
1212 {
1213  if ( !layer )
1214  {
1215  // use current layer by default
1216  layer = qobject_cast<QgsVectorLayer *>( mCurrentLayer );
1217  }
1218 
1219  if ( !layer || !layer->isSpatial() || layer->selectedFeatureCount() == 0 )
1220  return;
1221 
1222  QgsRectangle rect = layer->boundingBoxOfSelected();
1223  if ( rect.isNull() )
1224  {
1225  emit messageEmitted( tr( "Cannot pan to selected feature(s)" ), tr( "No extent could be determined." ), Qgis::Warning );
1226  return;
1227  }
1228 
1229  rect = mapSettings().layerExtentToOutputExtent( layer, rect );
1230  setCenter( rect.center() );
1231  refresh();
1232 }
1233 
1235  const QColor &color1, const QColor &color2,
1236  int flashes, int duration )
1237 {
1238  if ( !layer )
1239  {
1240  return;
1241  }
1242 
1243  QList< QgsGeometry > geoms;
1244 
1245  QgsFeatureIterator it = layer->getFeatures( QgsFeatureRequest().setFilterFids( ids ).setNoAttributes() );
1246  QgsFeature fet;
1247  while ( it.nextFeature( fet ) )
1248  {
1249  if ( !fet.hasGeometry() )
1250  continue;
1251  geoms << fet.geometry();
1252  }
1253 
1254  flashGeometries( geoms, layer->crs(), color1, color2, flashes, duration );
1255 }
1256 
1257 void QgsMapCanvas::flashGeometries( const QList<QgsGeometry> &geometries, const QgsCoordinateReferenceSystem &crs, const QColor &color1, const QColor &color2, int flashes, int duration )
1258 {
1259  if ( geometries.isEmpty() )
1260  return;
1261 
1262  QgsWkbTypes::GeometryType geomType = QgsWkbTypes::geometryType( geometries.at( 0 ).wkbType() );
1263  QgsRubberBand *rb = new QgsRubberBand( this, geomType );
1264  for ( const QgsGeometry &geom : geometries )
1265  rb->addGeometry( geom, crs );
1266 
1267  if ( geomType == QgsWkbTypes::LineGeometry || geomType == QgsWkbTypes::PointGeometry )
1268  {
1269  rb->setWidth( 2 );
1270  rb->setSecondaryStrokeColor( QColor( 255, 255, 255 ) );
1271  }
1272  if ( geomType == QgsWkbTypes::PointGeometry )
1274 
1275  QColor startColor = color1;
1276  if ( !startColor.isValid() )
1277  {
1278  if ( geomType == QgsWkbTypes::PolygonGeometry )
1279  {
1280  startColor = rb->fillColor();
1281  }
1282  else
1283  {
1284  startColor = rb->strokeColor();
1285  }
1286  startColor.setAlpha( 255 );
1287  }
1288  QColor endColor = color2;
1289  if ( !endColor.isValid() )
1290  {
1291  endColor = startColor;
1292  endColor.setAlpha( 0 );
1293  }
1294 
1295 
1296  QVariantAnimation *animation = new QVariantAnimation( this );
1297  connect( animation, &QVariantAnimation::finished, this, [animation, rb]
1298  {
1299  animation->deleteLater();
1300  delete rb;
1301  } );
1302  connect( animation, &QPropertyAnimation::valueChanged, this, [rb, geomType]( const QVariant & value )
1303  {
1304  QColor c = value.value<QColor>();
1305  if ( geomType == QgsWkbTypes::PolygonGeometry )
1306  {
1307  rb->setFillColor( c );
1308  }
1309  else
1310  {
1311  rb->setStrokeColor( c );
1312  QColor c = rb->secondaryStrokeColor();
1313  c.setAlpha( c.alpha() );
1314  rb->setSecondaryStrokeColor( c );
1315  }
1316  rb->update();
1317  } );
1318 
1319  animation->setDuration( duration * flashes );
1320  animation->setStartValue( endColor );
1321  double midStep = 0.2 / flashes;
1322  for ( int i = 0; i < flashes; ++i )
1323  {
1324  double start = static_cast< double >( i ) / flashes;
1325  animation->setKeyValueAt( start + midStep, startColor );
1326  double end = static_cast< double >( i + 1 ) / flashes;
1327  if ( !qgsDoubleNear( end, 1.0 ) )
1328  animation->setKeyValueAt( end, endColor );
1329  }
1330  animation->setEndValue( endColor );
1331  animation->start();
1332 }
1333 
1334 void QgsMapCanvas::keyPressEvent( QKeyEvent *e )
1335 {
1336  if ( mCanvasProperties->mouseButtonDown || mCanvasProperties->panSelectorDown )
1337  {
1338  emit keyPressed( e );
1339  return;
1340  }
1341 
1342  if ( ! mCanvasProperties->mouseButtonDown )
1343  {
1344  // Don't want to interfer with mouse events
1345 
1346  QgsRectangle currentExtent = mapSettings().visibleExtent();
1347  double dx = std::fabs( currentExtent.width() / 4 );
1348  double dy = std::fabs( currentExtent.height() / 4 );
1349 
1350  switch ( e->key() )
1351  {
1352  case Qt::Key_Left:
1353  QgsDebugMsgLevel( QStringLiteral( "Pan left" ), 2 );
1354  setCenter( center() - QgsVector( dx, 0 ).rotateBy( rotation() * M_PI / 180.0 ) );
1355  refresh();
1356  break;
1357 
1358  case Qt::Key_Right:
1359  QgsDebugMsgLevel( QStringLiteral( "Pan right" ), 2 );
1360  setCenter( center() + QgsVector( dx, 0 ).rotateBy( rotation() * M_PI / 180.0 ) );
1361  refresh();
1362  break;
1363 
1364  case Qt::Key_Up:
1365  QgsDebugMsgLevel( QStringLiteral( "Pan up" ), 2 );
1366  setCenter( center() + QgsVector( 0, dy ).rotateBy( rotation() * M_PI / 180.0 ) );
1367  refresh();
1368  break;
1369 
1370  case Qt::Key_Down:
1371  QgsDebugMsgLevel( QStringLiteral( "Pan down" ), 2 );
1372  setCenter( center() - QgsVector( 0, dy ).rotateBy( rotation() * M_PI / 180.0 ) );
1373  refresh();
1374  break;
1375 
1376 
1377 
1378  case Qt::Key_Space:
1379  QgsDebugMsgLevel( QStringLiteral( "Pressing pan selector" ), 2 );
1380 
1381  //mCanvasProperties->dragging = true;
1382  if ( ! e->isAutoRepeat() )
1383  {
1384  QApplication::setOverrideCursor( Qt::ClosedHandCursor );
1385  mCanvasProperties->panSelectorDown = true;
1386  panActionStart( mCanvasProperties->mouseLastXY );
1387  }
1388  break;
1389 
1390  case Qt::Key_PageUp:
1391  QgsDebugMsgLevel( QStringLiteral( "Zoom in" ), 2 );
1392  zoomIn();
1393  break;
1394 
1395  case Qt::Key_PageDown:
1396  QgsDebugMsgLevel( QStringLiteral( "Zoom out" ), 2 );
1397  zoomOut();
1398  break;
1399 
1400 #if 0
1401  case Qt::Key_P:
1402  mUseParallelRendering = !mUseParallelRendering;
1403  refresh();
1404  break;
1405 
1406  case Qt::Key_S:
1407  mDrawRenderingStats = !mDrawRenderingStats;
1408  refresh();
1409  break;
1410 #endif
1411 
1412  default:
1413  // Pass it on
1414  if ( mMapTool )
1415  {
1416  mMapTool->keyPressEvent( e );
1417  }
1418  else e->ignore();
1419 
1420  QgsDebugMsgLevel( "Ignoring key: " + QString::number( e->key() ), 2 );
1421  }
1422  }
1423 
1424  emit keyPressed( e );
1425 
1426 } //keyPressEvent()
1427 
1428 void QgsMapCanvas::keyReleaseEvent( QKeyEvent *e )
1429 {
1430  QgsDebugMsgLevel( QStringLiteral( "keyRelease event" ), 2 );
1431 
1432  switch ( e->key() )
1433  {
1434  case Qt::Key_Space:
1435  if ( !e->isAutoRepeat() && mCanvasProperties->panSelectorDown )
1436  {
1437  QgsDebugMsgLevel( QStringLiteral( "Releasing pan selector" ), 2 );
1438  QApplication::restoreOverrideCursor();
1439  mCanvasProperties->panSelectorDown = false;
1440  panActionEnd( mCanvasProperties->mouseLastXY );
1441  }
1442  break;
1443 
1444  default:
1445  // Pass it on
1446  if ( mMapTool )
1447  {
1448  mMapTool->keyReleaseEvent( e );
1449  }
1450  else e->ignore();
1451 
1452  QgsDebugMsgLevel( "Ignoring key release: " + QString::number( e->key() ), 2 );
1453  }
1454 
1455  emit keyReleased( e );
1456 
1457 } //keyReleaseEvent()
1458 
1459 
1461 {
1462  // call handler of current map tool
1463  if ( mMapTool )
1464  {
1465  std::unique_ptr<QgsMapMouseEvent> me( new QgsMapMouseEvent( this, e ) );
1466  mMapTool->canvasDoubleClickEvent( me.get() );
1467  }
1468 }// mouseDoubleClickEvent
1469 
1470 
1471 void QgsMapCanvas::beginZoomRect( QPoint pos )
1472 {
1473  mZoomRect.setRect( 0, 0, 0, 0 );
1474  QApplication::setOverrideCursor( mZoomCursor );
1475  mZoomDragging = true;
1476  mZoomRubberBand.reset( new QgsRubberBand( this, QgsWkbTypes::PolygonGeometry ) );
1477  QColor color( Qt::blue );
1478  color.setAlpha( 63 );
1479  mZoomRubberBand->setColor( color );
1480  mZoomRect.setTopLeft( pos );
1481 }
1482 
1483 void QgsMapCanvas::endZoomRect( QPoint pos )
1484 {
1485  mZoomDragging = false;
1486  mZoomRubberBand.reset( nullptr );
1487  QApplication::restoreOverrideCursor();
1488 
1489  // store the rectangle
1490  mZoomRect.setRight( pos.x() );
1491  mZoomRect.setBottom( pos.y() );
1492 
1493  if ( mZoomRect.width() < 5 && mZoomRect.height() < 5 )
1494  {
1495  //probably a mistake - would result in huge zoom!
1496  return;
1497  }
1498 
1499  //account for bottom right -> top left dragging
1500  mZoomRect = mZoomRect.normalized();
1501 
1502  // set center and zoom
1503  const QSize &zoomRectSize = mZoomRect.size();
1504  const QSize &canvasSize = mSettings.outputSize();
1505  double sfx = static_cast< double >( zoomRectSize.width() ) / canvasSize.width();
1506  double sfy = static_cast< double >( zoomRectSize.height() ) / canvasSize.height();
1507  double sf = std::max( sfx, sfy );
1508 
1509  QgsPointXY c = mSettings.mapToPixel().toMapCoordinates( mZoomRect.center() );
1510 
1511  zoomByFactor( sf, &c );
1512  refresh();
1513 }
1514 
1515 void QgsMapCanvas::mousePressEvent( QMouseEvent *e )
1516 {
1517  //use middle mouse button for panning, map tools won't receive any events in that case
1518  if ( e->button() == Qt::MidButton )
1519  {
1520  mCanvasProperties->panSelectorDown = true;
1521  panActionStart( mCanvasProperties->mouseLastXY );
1522  }
1523  else
1524  {
1525  // call handler of current map tool
1526  if ( mMapTool )
1527  {
1528  if ( mMapTool->flags() & QgsMapTool::AllowZoomRect && e->button() == Qt::LeftButton
1529  && e->modifiers() & Qt::ShiftModifier )
1530  {
1531  beginZoomRect( e->pos() );
1532  return;
1533  }
1534  else
1535  {
1536  std::unique_ptr<QgsMapMouseEvent> me( new QgsMapMouseEvent( this, e ) );
1537  mMapTool->canvasPressEvent( me.get() );
1538  }
1539  }
1540  }
1541 
1542  if ( mCanvasProperties->panSelectorDown )
1543  {
1544  return;
1545  }
1546 
1547  mCanvasProperties->mouseButtonDown = true;
1548  mCanvasProperties->rubberStartPoint = e->pos();
1549 
1550 } // mousePressEvent
1551 
1552 
1553 void QgsMapCanvas::mouseReleaseEvent( QMouseEvent *e )
1554 {
1555  //use middle mouse button for panning, map tools won't receive any events in that case
1556  if ( e->button() == Qt::MidButton )
1557  {
1558  mCanvasProperties->panSelectorDown = false;
1559  panActionEnd( mCanvasProperties->mouseLastXY );
1560  }
1561  else if ( e->button() == Qt::BackButton )
1562  {
1564  return;
1565  }
1566  else if ( e->button() == Qt::ForwardButton )
1567  {
1568  zoomToNextExtent();
1569  return;
1570  }
1571  else
1572  {
1573  if ( mZoomDragging && e->button() == Qt::LeftButton )
1574  {
1575  endZoomRect( e->pos() );
1576  return;
1577  }
1578 
1579  // call handler of current map tool
1580  if ( mMapTool )
1581  {
1582  // right button was pressed in zoom tool? return to previous non zoom tool
1583  if ( e->button() == Qt::RightButton && mMapTool->flags() & QgsMapTool::Transient )
1584  {
1585  QgsDebugMsgLevel( QStringLiteral( "Right click in map tool zoom or pan, last tool is %1." ).arg(
1586  mLastNonZoomMapTool ? QStringLiteral( "not null" ) : QStringLiteral( "null" ) ), 2 );
1587 
1588  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCurrentLayer );
1589 
1590  // change to older non-zoom tool
1591  if ( mLastNonZoomMapTool
1592  && ( !( mLastNonZoomMapTool->flags() & QgsMapTool::EditTool )
1593  || ( vlayer && vlayer->isEditable() ) ) )
1594  {
1595  QgsMapTool *t = mLastNonZoomMapTool;
1596  mLastNonZoomMapTool = nullptr;
1597  setMapTool( t );
1598  }
1599  return;
1600  }
1601  std::unique_ptr<QgsMapMouseEvent> me( new QgsMapMouseEvent( this, e ) );
1602  mMapTool->canvasReleaseEvent( me.get() );
1603  }
1604  }
1605 
1606 
1607  mCanvasProperties->mouseButtonDown = false;
1608 
1609  if ( mCanvasProperties->panSelectorDown )
1610  return;
1611 
1612 } // mouseReleaseEvent
1613 
1614 void QgsMapCanvas::resizeEvent( QResizeEvent *e )
1615 {
1616  QGraphicsView::resizeEvent( e );
1617  mResizeTimer->start( 500 ); // in charge of refreshing canvas
1618 
1619  double oldScale = mSettings.scale();
1620  QSize lastSize = viewport()->size();
1621  mSettings.setOutputSize( lastSize );
1622 
1623  mScene->setSceneRect( QRectF( 0, 0, lastSize.width(), lastSize.height() ) );
1624 
1625  moveCanvasContents( true );
1626 
1627  if ( mScaleLocked )
1628  {
1629  double scaleFactor = oldScale / mSettings.scale();
1630  QgsRectangle r = mSettings.extent();
1631  QgsPointXY center = r.center();
1632  r.scale( scaleFactor, &center );
1633  mSettings.setExtent( r );
1634  }
1635  else
1636  {
1637  updateScale();
1638  }
1639 
1640  emit extentsChanged();
1641 }
1642 
1643 void QgsMapCanvas::paintEvent( QPaintEvent *e )
1644 {
1645  // no custom event handling anymore
1646 
1647  QGraphicsView::paintEvent( e );
1648 } // paintEvent
1649 
1651 {
1652  const QList<QGraphicsItem *> items = mScene->items();
1653  for ( QGraphicsItem *gi : items )
1654  {
1655  QgsMapCanvasItem *item = dynamic_cast<QgsMapCanvasItem *>( gi );
1656 
1657  if ( item )
1658  {
1659  item->updatePosition();
1660  }
1661  }
1662 }
1663 
1664 
1665 void QgsMapCanvas::wheelEvent( QWheelEvent *e )
1666 {
1667  // Zoom the map canvas in response to a mouse wheel event. Moving the
1668  // wheel forward (away) from the user zooms in
1669 
1670  QgsDebugMsgLevel( "Wheel event delta " + QString::number( e->delta() ), 2 );
1671 
1672  if ( mMapTool )
1673  {
1674  mMapTool->wheelEvent( e );
1675  if ( e->isAccepted() )
1676  return;
1677  }
1678 
1679  if ( e->delta() == 0 )
1680  {
1681  e->accept();
1682  return;
1683  }
1684 
1685  double zoomFactor = e->angleDelta().y() > 0 ? 1. / zoomInFactor() : zoomOutFactor();
1686 
1687  // "Normal" mouse have an angle delta of 120, precision mouses provide data faster, in smaller steps
1688  zoomFactor = 1.0 + ( zoomFactor - 1.0 ) / 120.0 * std::fabs( e->angleDelta().y() );
1689 
1690  if ( e->modifiers() & Qt::ControlModifier )
1691  {
1692  //holding ctrl while wheel zooming results in a finer zoom
1693  zoomFactor = 1.0 + ( zoomFactor - 1.0 ) / 20.0;
1694  }
1695 
1696  double signedWheelFactor = e->angleDelta().y() > 0 ? 1 / zoomFactor : zoomFactor;
1697 
1698  // zoom map to mouse cursor by scaling
1699  QgsPointXY oldCenter = center();
1700  QgsPointXY mousePos( getCoordinateTransform()->toMapCoordinates( e->x(), e->y() ) );
1701  QgsPointXY newCenter( mousePos.x() + ( ( oldCenter.x() - mousePos.x() ) * signedWheelFactor ),
1702  mousePos.y() + ( ( oldCenter.y() - mousePos.y() ) * signedWheelFactor ) );
1703 
1704  zoomByFactor( signedWheelFactor, &newCenter );
1705  e->accept();
1706 }
1707 
1708 void QgsMapCanvas::setWheelFactor( double factor )
1709 {
1710  mWheelZoomFactor = factor;
1711 }
1712 
1714 {
1715  // magnification is alreday handled in zoomByFactor
1716  zoomByFactor( zoomInFactor() );
1717 }
1718 
1720 {
1721  // magnification is alreday handled in zoomByFactor
1722  zoomByFactor( zoomOutFactor() );
1723 }
1724 
1725 void QgsMapCanvas::zoomScale( double newScale, bool ignoreScaleLock )
1726 {
1727  zoomByFactor( newScale / scale(), nullptr, ignoreScaleLock );
1728 }
1729 
1730 void QgsMapCanvas::zoomWithCenter( int x, int y, bool zoomIn )
1731 {
1732  double scaleFactor = ( zoomIn ? zoomInFactor() : zoomOutFactor() );
1733 
1734  if ( mScaleLocked )
1735  {
1737  }
1738  else
1739  {
1740  // transform the mouse pos to map coordinates
1743  r.scale( scaleFactor, &center );
1744  setExtent( r, true );
1745  refresh();
1746  }
1747 }
1748 
1749 void QgsMapCanvas::setScaleLocked( bool isLocked )
1750 {
1751  mScaleLocked = isLocked;
1752 }
1753 
1754 void QgsMapCanvas::mouseMoveEvent( QMouseEvent *e )
1755 {
1756  mCanvasProperties->mouseLastXY = e->pos();
1757 
1758  if ( mCanvasProperties->panSelectorDown )
1759  {
1760  panAction( e );
1761  }
1762  else if ( mZoomDragging )
1763  {
1764  mZoomRect.setBottomRight( e->pos() );
1765  mZoomRubberBand->setToCanvasRectangle( mZoomRect );
1766  mZoomRubberBand->show();
1767  }
1768  else
1769  {
1770  // call handler of current map tool
1771  if ( mMapTool )
1772  {
1773  std::unique_ptr<QgsMapMouseEvent> me( new QgsMapMouseEvent( this, e ) );
1774  mMapTool->canvasMoveEvent( me.get() );
1775  }
1776  }
1777 
1778  // show x y on status bar (if we are mid pan operation, then the cursor point hasn't changed!)
1779  if ( !panOperationInProgress() )
1780  {
1781  mCursorPoint = getCoordinateTransform()->toMapCoordinates( mCanvasProperties->mouseLastXY );
1782  emit xyCoordinates( mCursorPoint );
1783  }
1784 }
1785 
1786 void QgsMapCanvas::setMapTool( QgsMapTool *tool, bool clean )
1787 {
1788  if ( !tool )
1789  return;
1790 
1791  if ( mMapTool )
1792  {
1793  if ( clean )
1794  mMapTool->clean();
1795 
1796  disconnect( mMapTool, &QObject::destroyed, this, &QgsMapCanvas::mapToolDestroyed );
1797  mMapTool->deactivate();
1798  }
1799 
1800  if ( ( tool->flags() & QgsMapTool::Transient )
1801  && mMapTool && !( mMapTool->flags() & QgsMapTool::Transient ) )
1802  {
1803  // if zoom or pan tool will be active, save old tool
1804  // to bring it back on right click
1805  // (but only if it wasn't also zoom or pan tool)
1806  mLastNonZoomMapTool = mMapTool;
1807  }
1808  else
1809  {
1810  mLastNonZoomMapTool = nullptr;
1811  }
1812 
1813  QgsMapTool *oldTool = mMapTool;
1814 
1815  // set new map tool and activate it
1816  mMapTool = tool;
1817  emit mapToolSet( mMapTool, oldTool );
1818  if ( mMapTool )
1819  {
1820  connect( mMapTool, &QObject::destroyed, this, &QgsMapCanvas::mapToolDestroyed );
1821  mMapTool->activate();
1822  }
1823 
1824 } // setMapTool
1825 
1827 {
1828  if ( mMapTool && mMapTool == tool )
1829  {
1830  disconnect( mMapTool, &QObject::destroyed, this, &QgsMapCanvas::mapToolDestroyed );
1831  QgsMapTool *oldTool = mMapTool;
1832  mMapTool = nullptr;
1833  oldTool->deactivate();
1834  emit mapToolSet( nullptr, oldTool );
1835  setCursor( Qt::ArrowCursor );
1836  }
1837 
1838  if ( mLastNonZoomMapTool && mLastNonZoomMapTool == tool )
1839  {
1840  mLastNonZoomMapTool = nullptr;
1841  }
1842 }
1843 
1844 void QgsMapCanvas::setCanvasColor( const QColor &color )
1845 {
1846  if ( canvasColor() == color )
1847  return;
1848 
1849  // background of map's pixmap
1850  mSettings.setBackgroundColor( color );
1851 
1852  // background of the QGraphicsView
1853  QBrush bgBrush( color );
1854  setBackgroundBrush( bgBrush );
1855 #if 0
1856  QPalette palette;
1857  palette.setColor( backgroundRole(), color );
1858  setPalette( palette );
1859 #endif
1860 
1861  // background of QGraphicsScene
1862  mScene->setBackgroundBrush( bgBrush );
1863 
1864  refresh();
1865 
1866  emit canvasColorChanged();
1867 }
1868 
1870 {
1871  return mScene->backgroundBrush().color();
1872 }
1873 
1874 void QgsMapCanvas::setSelectionColor( const QColor &color )
1875 {
1876  if ( mSettings.selectionColor() == color )
1877  return;
1878 
1879  mSettings.setSelectionColor( color );
1880 
1881  if ( mCache )
1882  {
1883  bool hasSelectedFeatures = false;
1884  const auto layers = mSettings.layers();
1885  for ( QgsMapLayer *layer : layers )
1886  {
1887  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
1888  if ( vlayer && vlayer->selectedFeatureCount() )
1889  {
1890  hasSelectedFeatures = true;
1891  break;
1892  }
1893  }
1894 
1895  if ( hasSelectedFeatures )
1896  {
1897  mCache->clear();
1898  refresh();
1899  }
1900  }
1901 }
1902 
1904 {
1905  return mSettings.selectionColor();
1906 }
1907 
1909 {
1910  return mapSettings().layers().size();
1911 } // layerCount
1912 
1913 
1914 QList<QgsMapLayer *> QgsMapCanvas::layers() const
1915 {
1916  return mapSettings().layers();
1917 }
1918 
1920 {
1921  // called when a layer has changed visibility setting
1922  refresh();
1923 }
1924 
1925 void QgsMapCanvas::freeze( bool frozen )
1926 {
1927  mFrozen = frozen;
1928 }
1929 
1931 {
1932  return mFrozen;
1933 }
1934 
1936 {
1937  return mapSettings().mapUnitsPerPixel();
1938 }
1939 
1941 {
1942  return mapSettings().mapUnits();
1943 }
1944 
1945 QMap<QString, QString> QgsMapCanvas::layerStyleOverrides() const
1946 {
1947  return mSettings.layerStyleOverrides();
1948 }
1949 
1950 void QgsMapCanvas::setLayerStyleOverrides( const QMap<QString, QString> &overrides )
1951 {
1952  if ( overrides == mSettings.layerStyleOverrides() )
1953  return;
1954 
1955  mSettings.setLayerStyleOverrides( overrides );
1956  clearCache();
1958 }
1959 
1960 void QgsMapCanvas::setTheme( const QString &theme )
1961 {
1962  if ( mTheme == theme )
1963  return;
1964 
1965  clearCache();
1966  if ( theme.isEmpty() || !QgsProject::instance()->mapThemeCollection()->hasMapTheme( theme ) )
1967  {
1968  mTheme.clear();
1969  mSettings.setLayerStyleOverrides( QMap< QString, QString>() );
1970  setLayers( QgsProject::instance()->mapThemeCollection()->masterVisibleLayers() );
1971  emit themeChanged( QString() );
1972  }
1973  else
1974  {
1975  mTheme = theme;
1976  setLayersPrivate( QgsProject::instance()->mapThemeCollection()->mapThemeVisibleLayers( mTheme ) );
1977  emit themeChanged( theme );
1978  }
1979 }
1980 
1982 {
1983  mRenderFlag = flag;
1984 
1985  if ( mRenderFlag )
1986  {
1987  refresh();
1988  }
1989  else
1990  stopRendering();
1991 }
1992 
1993 #if 0
1994 void QgsMapCanvas::connectNotify( const char *signal )
1995 {
1996  Q_UNUSED( signal )
1997  QgsDebugMsg( "QgsMapCanvas connected to " + QString( signal ) );
1998 } //connectNotify
1999 #endif
2000 
2001 void QgsMapCanvas::layerRepaintRequested( bool deferred )
2002 {
2003  if ( !deferred )
2004  refresh();
2005 }
2006 
2007 void QgsMapCanvas::autoRefreshTriggered()
2008 {
2009  if ( mJob )
2010  {
2011  // canvas is currently being redrawn, so we skip this auto refresh
2012  // otherwise we could get stuck in the situation where an auto refresh is triggered
2013  // too often to allow the canvas to ever finish rendering
2014  return;
2015  }
2016 
2017  refresh();
2018 }
2019 
2020 void QgsMapCanvas::updateAutoRefreshTimer()
2021 {
2022  // min auto refresh interval stores the smallest interval between layer auto refreshes. We automatically
2023  // trigger a map refresh on this minimum interval
2024  int minAutoRefreshInterval = -1;
2025  const auto layers = mSettings.layers();
2026  for ( QgsMapLayer *layer : layers )
2027  {
2029  minAutoRefreshInterval = minAutoRefreshInterval > 0 ? std::min( layer->autoRefreshInterval(), minAutoRefreshInterval ) : layer->autoRefreshInterval();
2030  }
2031 
2032  if ( minAutoRefreshInterval > 0 )
2033  {
2034  mAutoRefreshTimer.setInterval( minAutoRefreshInterval );
2035  mAutoRefreshTimer.start();
2036  }
2037  else
2038  {
2039  mAutoRefreshTimer.stop();
2040  }
2041 }
2042 
2043 void QgsMapCanvas::projectThemesChanged()
2044 {
2045  if ( mTheme.isEmpty() )
2046  return;
2047 
2048  if ( !QgsProject::instance()->mapThemeCollection()->hasMapTheme( mTheme ) )
2049  {
2050  // theme has been removed - stop following
2051  setTheme( QString() );
2052  }
2053 
2054 }
2055 
2057 {
2058  return mMapTool;
2059 }
2060 
2061 void QgsMapCanvas::panActionEnd( QPoint releasePoint )
2062 {
2063  // move map image and other items to standard position
2064  moveCanvasContents( true ); // true means reset
2065 
2066  // use start and end box points to calculate the extent
2067  QgsPointXY start = getCoordinateTransform()->toMapCoordinates( mCanvasProperties->rubberStartPoint );
2068  QgsPointXY end = getCoordinateTransform()->toMapCoordinates( releasePoint );
2069 
2070  // modify the center
2071  double dx = end.x() - start.x();
2072  double dy = end.y() - start.y();
2073  QgsPointXY c = center();
2074  c.set( c.x() - dx, c.y() - dy );
2075  setCenter( c );
2076 
2077  refresh();
2078 }
2079 
2080 void QgsMapCanvas::panActionStart( QPoint releasePoint )
2081 {
2082  mCanvasProperties->rubberStartPoint = releasePoint;
2083 
2084  mDa = QgsDistanceArea();
2085  mDa.setEllipsoid( QgsProject::instance()->ellipsoid() );
2086  mDa.setSourceCrs( mapSettings().destinationCrs(), QgsProject::instance()->transformContext() );
2087 }
2088 
2089 void QgsMapCanvas::panAction( QMouseEvent *e )
2090 {
2091  Q_UNUSED( e )
2092 
2093  QgsPointXY currentMapPoint = getCoordinateTransform()->toMapCoordinates( e->pos() );
2094  QgsPointXY startMapPoint = getCoordinateTransform()->toMapCoordinates( mCanvasProperties->rubberStartPoint );
2095  emit panDistanceBearingChanged( mDa.measureLine( currentMapPoint, startMapPoint ), mDa.lengthUnits(), mDa.bearing( currentMapPoint, startMapPoint ) * 180 / M_PI );
2096 
2097  // move all map canvas items
2099 }
2100 
2102 {
2103  QPoint pnt( 0, 0 );
2104  if ( !reset )
2105  pnt += mCanvasProperties->mouseLastXY - mCanvasProperties->rubberStartPoint;
2106 
2107  setSceneRect( -pnt.x(), -pnt.y(), viewport()->size().width(), viewport()->size().height() );
2108 }
2109 
2110 void QgsMapCanvas::dropEvent( QDropEvent *event )
2111 {
2112  if ( QgsMimeDataUtils::isUriList( event->mimeData() ) )
2113  {
2115  bool allHandled = true;
2116  for ( const QgsMimeDataUtils::Uri &uri : lst )
2117  {
2118  bool handled = false;
2119  for ( QgsCustomDropHandler *handler : qgis::as_const( mDropHandlers ) )
2120  {
2121  if ( handler && handler->customUriProviderKey() == uri.providerKey )
2122  {
2123  if ( handler->handleCustomUriCanvasDrop( uri, this ) )
2124  {
2125  handled = true;
2126  break;
2127  }
2128  }
2129  }
2130  if ( !handled )
2131  allHandled = false;
2132  }
2133  if ( allHandled )
2134  event->accept();
2135  else
2136  event->ignore();
2137  }
2138  else
2139  {
2140  event->ignore();
2141  }
2142 }
2143 
2145 {
2146  return mCanvasProperties->mouseLastXY;
2147 }
2148 
2149 void QgsMapCanvas::setPreviewModeEnabled( bool previewEnabled )
2150 {
2151  if ( !mPreviewEffect )
2152  {
2153  return;
2154  }
2155 
2156  mPreviewEffect->setEnabled( previewEnabled );
2157 }
2158 
2160 {
2161  if ( !mPreviewEffect )
2162  {
2163  return false;
2164  }
2165 
2166  return mPreviewEffect->isEnabled();
2167 }
2168 
2170 {
2171  if ( !mPreviewEffect )
2172  {
2173  return;
2174  }
2175 
2176  mPreviewEffect->setMode( mode );
2177 }
2178 
2180 {
2181  if ( !mPreviewEffect )
2182  {
2184  }
2185 
2186  return mPreviewEffect->mode();
2187 }
2188 
2190 {
2191  if ( !mSnappingUtils )
2192  {
2193  // associate a dummy instance, but better than null pointer
2194  QgsMapCanvas *c = const_cast<QgsMapCanvas *>( this );
2195  c->mSnappingUtils = new QgsMapCanvasSnappingUtils( c, c );
2196  }
2197  return mSnappingUtils;
2198 }
2199 
2201 {
2202  mSnappingUtils = utils;
2203 }
2204 
2205 void QgsMapCanvas::readProject( const QDomDocument &doc )
2206 {
2207  QgsProject *project = qobject_cast< QgsProject * >( sender() );
2208 
2209  QDomNodeList nodes = doc.elementsByTagName( QStringLiteral( "mapcanvas" ) );
2210  if ( nodes.count() )
2211  {
2212  QDomNode node = nodes.item( 0 );
2213 
2214  // Search the specific MapCanvas node using the name
2215  if ( nodes.count() > 1 )
2216  {
2217  for ( int i = 0; i < nodes.size(); ++i )
2218  {
2219  QDomElement elementNode = nodes.at( i ).toElement();
2220 
2221  if ( elementNode.hasAttribute( QStringLiteral( "name" ) ) && elementNode.attribute( QStringLiteral( "name" ) ) == objectName() )
2222  {
2223  node = nodes.at( i );
2224  break;
2225  }
2226  }
2227  }
2228 
2229  QgsMapSettings tmpSettings;
2230  tmpSettings.readXml( node );
2231  if ( objectName() != QStringLiteral( "theMapCanvas" ) )
2232  {
2233  // never manually set the crs for the main canvas - this is instead connected to the project CRS
2234  setDestinationCrs( tmpSettings.destinationCrs() );
2235  }
2236  setExtent( tmpSettings.extent() );
2237  setRotation( tmpSettings.rotation() );
2239 
2240  clearExtentHistory(); // clear the extent history on project load
2241 
2242  QDomElement elem = node.toElement();
2243  if ( elem.hasAttribute( QStringLiteral( "theme" ) ) )
2244  {
2245  if ( QgsProject::instance()->mapThemeCollection()->hasMapTheme( elem.attribute( QStringLiteral( "theme" ) ) ) )
2246  {
2247  setTheme( elem.attribute( QStringLiteral( "theme" ) ) );
2248  }
2249  }
2250  setAnnotationsVisible( elem.attribute( QStringLiteral( "annotationsVisible" ), QStringLiteral( "1" ) ).toInt() );
2251 
2252  // restore canvas expression context
2253  const QDomNodeList scopeElements = elem.elementsByTagName( QStringLiteral( "expressionContextScope" ) );
2254  if ( scopeElements.size() > 0 )
2255  {
2256  const QDomElement scopeElement = scopeElements.at( 0 ).toElement();
2257  mExpressionContextScope.readXml( scopeElement, QgsReadWriteContext() );
2258  }
2259  }
2260  else
2261  {
2262  QgsDebugMsg( QStringLiteral( "Couldn't read mapcanvas information from project" ) );
2263  if ( !project->viewSettings()->defaultViewExtent().isNull() )
2264  {
2266  clearExtentHistory(); // clear the extent history on project load
2267  }
2268  }
2269 }
2270 
2271 void QgsMapCanvas::writeProject( QDomDocument &doc )
2272 {
2273  // create node "mapcanvas" and call mMapRenderer->writeXml()
2274 
2275  QDomNodeList nl = doc.elementsByTagName( QStringLiteral( "qgis" ) );
2276  if ( !nl.count() )
2277  {
2278  QgsDebugMsg( QStringLiteral( "Unable to find qgis element in project file" ) );
2279  return;
2280  }
2281  QDomNode qgisNode = nl.item( 0 ); // there should only be one, so zeroth element OK
2282 
2283  QDomElement mapcanvasNode = doc.createElement( QStringLiteral( "mapcanvas" ) );
2284  mapcanvasNode.setAttribute( QStringLiteral( "name" ), objectName() );
2285  if ( !mTheme.isEmpty() )
2286  mapcanvasNode.setAttribute( QStringLiteral( "theme" ), mTheme );
2287  mapcanvasNode.setAttribute( QStringLiteral( "annotationsVisible" ), mAnnotationsVisible );
2288  qgisNode.appendChild( mapcanvasNode );
2289 
2290  mSettings.writeXml( mapcanvasNode, doc );
2291 
2292  // store canvas expression context
2293  QDomElement scopeElement = doc.createElement( QStringLiteral( "expressionContextScope" ) );
2294  QgsExpressionContextScope tmpScope( mExpressionContextScope );
2295  tmpScope.removeVariable( QStringLiteral( "atlas_featurenumber" ) );
2296  tmpScope.removeVariable( QStringLiteral( "atlas_pagename" ) );
2297  tmpScope.removeVariable( QStringLiteral( "atlas_feature" ) );
2298  tmpScope.removeVariable( QStringLiteral( "atlas_featureid" ) );
2299  tmpScope.removeVariable( QStringLiteral( "atlas_geometry" ) );
2300  tmpScope.writeXml( scopeElement, doc, QgsReadWriteContext() );
2301  mapcanvasNode.appendChild( scopeElement );
2302 
2303  // TODO: store only units, extent, projections, dest CRS
2304 }
2305 
2306 void QgsMapCanvas::zoomByFactor( double scaleFactor, const QgsPointXY *center, bool ignoreScaleLock )
2307 {
2308  if ( mScaleLocked && !ignoreScaleLock )
2309  {
2310  // zoom map to mouse cursor by magnifying
2312  }
2313  else
2314  {
2316  r.scale( scaleFactor, center );
2317  setExtent( r, true );
2318  refresh();
2319  }
2320 }
2321 
2323 {
2324  // Find out which layer it was that sent the signal.
2325  QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( sender() );
2326  if ( layer )
2327  {
2328  emit selectionChanged( layer );
2329  refresh();
2330  }
2331 }
2332 
2333 void QgsMapCanvas::dragEnterEvent( QDragEnterEvent *event )
2334 {
2335  // By default graphics view delegates the drag events to graphics items.
2336  // But we do not want that and by ignoring the drag enter we let the
2337  // parent (e.g. QgisApp) to handle drops of map layers etc.
2338 
2339  // so we ONLY accept the event if we know in advance that a custom drop handler
2340  // wants it
2341 
2342  if ( QgsMimeDataUtils::isUriList( event->mimeData() ) )
2343  {
2345  bool allHandled = true;
2346  for ( const QgsMimeDataUtils::Uri &uri : lst )
2347  {
2348  bool handled = false;
2349  for ( QgsCustomDropHandler *handler : qgis::as_const( mDropHandlers ) )
2350  {
2351  if ( handler->canHandleCustomUriCanvasDrop( uri, this ) )
2352  {
2353  handled = true;
2354  break;
2355  }
2356  }
2357  if ( !handled )
2358  allHandled = false;
2359  }
2360  if ( allHandled )
2361  event->accept();
2362  else
2363  event->ignore();
2364  }
2365  else
2366  {
2367  event->ignore();
2368  }
2369 }
2370 
2371 void QgsMapCanvas::mapToolDestroyed()
2372 {
2373  QgsDebugMsgLevel( QStringLiteral( "maptool destroyed" ), 2 );
2374  mMapTool = nullptr;
2375 }
2376 
2377 bool QgsMapCanvas::event( QEvent *e )
2378 {
2379  if ( !QTouchDevice::devices().empty() )
2380  {
2381  if ( e->type() == QEvent::Gesture )
2382  {
2383  if ( QTapAndHoldGesture *tapAndHoldGesture = qobject_cast< QTapAndHoldGesture * >( static_cast<QGestureEvent *>( e )->gesture( Qt::TapAndHoldGesture ) ) )
2384  {
2385  QPointF pos = tapAndHoldGesture->position();
2386  pos = mapFromGlobal( QPoint( pos.x(), pos.y() ) );
2387  QgsPointXY mapPoint = getCoordinateTransform()->toMapCoordinates( pos.x(), pos.y() );
2388  emit tapAndHoldGestureOccurred( mapPoint, tapAndHoldGesture );
2389  }
2390 
2391  // call handler of current map tool
2392  if ( mMapTool )
2393  {
2394  return mMapTool->gestureEvent( static_cast<QGestureEvent *>( e ) );
2395  }
2396  }
2397  }
2398 
2399  // pass other events to base class
2400  return QGraphicsView::event( e );
2401 }
2402 
2404 {
2405  // reload all layers in canvas
2406  const QList<QgsMapLayer *> layers = mapSettings().layers();
2407  for ( QgsMapLayer *layer : layers )
2408  {
2409  layer->reload();
2410  }
2411 
2412  redrawAllLayers();
2413 }
2414 
2416 {
2417  // clear the cache
2418  clearCache();
2419 
2420  // and then refresh
2421  refresh();
2422 }
2423 
2425 {
2426  while ( mRefreshScheduled || mJob )
2427  {
2428  QgsApplication::processEvents();
2429  }
2430 }
2431 
2433 {
2434  mSettings.setSegmentationTolerance( tolerance );
2435 }
2436 
2438 {
2439  mSettings.setSegmentationToleranceType( type );
2440 }
2441 
2442 QList<QgsMapCanvasAnnotationItem *> QgsMapCanvas::annotationItems() const
2443 {
2444  QList<QgsMapCanvasAnnotationItem *> annotationItemList;
2445  const QList<QGraphicsItem *> items = mScene->items();
2446  for ( QGraphicsItem *gi : items )
2447  {
2448  QgsMapCanvasAnnotationItem *aItem = dynamic_cast< QgsMapCanvasAnnotationItem *>( gi );
2449  if ( aItem )
2450  {
2451  annotationItemList.push_back( aItem );
2452  }
2453  }
2454 
2455  return annotationItemList;
2456 }
2457 
2459 {
2460  mAnnotationsVisible = show;
2461  const QList<QgsMapCanvasAnnotationItem *> items = annotationItems();
2462  for ( QgsMapCanvasAnnotationItem *item : items )
2463  {
2464  item->setVisible( show );
2465  }
2466 }
2467 
2469 {
2470  mSettings.setLabelingEngineSettings( settings );
2471 }
2472 
2474 {
2475  return mSettings.labelingEngineSettings();
2476 }
2477 
2478 void QgsMapCanvas::startPreviewJobs()
2479 {
2480  stopPreviewJobs(); //just in case still running
2481 
2482  //canvas preview jobs aren't compatible with rotation
2483  // TODO fix this
2484  if ( !qgsDoubleNear( mSettings.rotation(), 0.0 ) )
2485  return;
2486 
2487  schedulePreviewJob( 0 );
2488 }
2489 
2490 void QgsMapCanvas::startPreviewJob( int number )
2491 {
2492  QgsRectangle mapRect = mSettings.visibleExtent();
2493 
2494  if ( number == 4 )
2495  number += 1;
2496 
2497  int j = number / 3;
2498  int i = number % 3;
2499 
2500  //copy settings, only update extent
2501  QgsMapSettings jobSettings = mSettings;
2502 
2503  double dx = ( i - 1 ) * mapRect.width();
2504  double dy = ( 1 - j ) * mapRect.height();
2505  QgsRectangle jobExtent = mapRect;
2506 
2507  jobExtent.setXMaximum( jobExtent.xMaximum() + dx );
2508  jobExtent.setXMinimum( jobExtent.xMinimum() + dx );
2509  jobExtent.setYMaximum( jobExtent.yMaximum() + dy );
2510  jobExtent.setYMinimum( jobExtent.yMinimum() + dy );
2511 
2512  jobSettings.setExtent( jobExtent );
2513  jobSettings.setFlag( QgsMapSettings::DrawLabeling, false );
2514  jobSettings.setFlag( QgsMapSettings::RenderPreviewJob, true );
2515 
2516  // truncate preview layers to fast layers
2517  const QList<QgsMapLayer *> layers = jobSettings.layers();
2518  QList< QgsMapLayer * > previewLayers;
2520  context.maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
2521  for ( QgsMapLayer *layer : layers )
2522  {
2523  context.lastRenderingTimeMs = mLastLayerRenderTime.value( layer->id(), 0 );
2524  QgsDataProvider *provider = layer->dataProvider();
2525  if ( provider && !provider->renderInPreview( context ) )
2526  {
2527  QgsDebugMsgLevel( QStringLiteral( "Layer %1 not rendered because it does not match the renderInPreview criterion %2" ).arg( layer->id() ).arg( mLastLayerRenderTime.value( layer->id() ) ), 3 );
2528  continue;
2529  }
2530 
2531  previewLayers << layer;
2532  }
2533  jobSettings.setLayers( previewLayers );
2534 
2535  QgsMapRendererQImageJob *job = new QgsMapRendererSequentialJob( jobSettings );
2536  job->setProperty( "number", number );
2537  mPreviewJobs.append( job );
2538  connect( job, &QgsMapRendererJob::finished, this, &QgsMapCanvas::previewJobFinished );
2539  job->start();
2540 }
2541 
2542 void QgsMapCanvas::stopPreviewJobs()
2543 {
2544  mPreviewTimer.stop();
2545  const auto previewJobs = mPreviewJobs;
2546  for ( auto previewJob : previewJobs )
2547  {
2548  if ( previewJob )
2549  {
2550  disconnect( previewJob, &QgsMapRendererJob::finished, this, &QgsMapCanvas::previewJobFinished );
2551  connect( previewJob, &QgsMapRendererQImageJob::finished, previewJob, &QgsMapRendererQImageJob::deleteLater );
2552  previewJob->cancelWithoutBlocking();
2553  }
2554  }
2555  mPreviewJobs.clear();
2556 }
2557 
2558 void QgsMapCanvas::schedulePreviewJob( int number )
2559 {
2560  mPreviewTimer.setSingleShot( true );
2561  mPreviewTimer.setInterval( PREVIEW_JOB_DELAY_MS );
2562  disconnect( mPreviewTimerConnection );
2563  mPreviewTimerConnection = connect( &mPreviewTimer, &QTimer::timeout, this, [ = ]()
2564  {
2565  startPreviewJob( number );
2566  } );
2567  mPreviewTimer.start();
2568 }
2569 
2570 bool QgsMapCanvas::panOperationInProgress()
2571 {
2572  if ( mCanvasProperties->panSelectorDown )
2573  return true;
2574 
2575  if ( QgsMapToolPan *panTool = qobject_cast< QgsMapToolPan *>( mMapTool ) )
2576  {
2577  if ( panTool->isDragging() )
2578  return true;
2579  }
2580 
2581  return false;
2582 }
2583 
2584 int QgsMapCanvas::nextZoomLevel( const QList<double> &resolutions, bool zoomIn ) const
2585 {
2586  int resolutionLevel = -1;
2587  double currentResolution = mapUnitsPerPixel();
2588 
2589  for ( int i = 0, n = resolutions.size(); i < n; ++i )
2590  {
2591  if ( qgsDoubleNear( resolutions[i], currentResolution, 0.0001 ) )
2592  {
2593  resolutionLevel = zoomIn ? ( i - 1 ) : ( i + 1 );
2594  break;
2595  }
2596  else if ( currentResolution <= resolutions[i] )
2597  {
2598  resolutionLevel = zoomIn ? ( i - 1 ) : i;
2599  break;
2600  }
2601  }
2602  return ( resolutionLevel < 0 || resolutionLevel >= resolutions.size() ) ? -1 : resolutionLevel;
2603 }
2604 
2605 double QgsMapCanvas::zoomInFactor() const
2606 {
2607  if ( !mZoomResolutions.isEmpty() )
2608  {
2609  int zoomLevel = nextZoomLevel( mZoomResolutions, true );
2610  if ( zoomLevel != -1 )
2611  {
2612  return mZoomResolutions.at( zoomLevel ) / mapUnitsPerPixel();
2613  }
2614  }
2615  return 1 / mWheelZoomFactor;
2616 }
2617 
2618 double QgsMapCanvas::zoomOutFactor() const
2619 {
2620  if ( !mZoomResolutions.isEmpty() )
2621  {
2622  int zoomLevel = nextZoomLevel( mZoomResolutions, false );
2623  if ( zoomLevel != -1 )
2624  {
2625  return mZoomResolutions.at( zoomLevel ) / mapUnitsPerPixel();
2626  }
2627  }
2628  return mWheelZoomFactor;
2629 }
QgsMapCanvas::CanvasProperties::rubberStartPoint
QPoint rubberStartPoint
Beginning point of a rubber band.
Definition: qgsmapcanvas.cpp:116
QgsGeometry::fromPointXY
static QgsGeometry fromPointXY(const QgsPointXY &point)
Creates a new geometry from a QgsPointXY object.
Definition: qgsgeometry.cpp:161
QgsMapCanvas::renderStarting
void renderStarting()
Emitted when the canvas is about to be rendered.
QgsMapCanvas::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *e) override
Definition: qgsmapcanvas.cpp:1460
QgsAbstractGeometry::MaximumAngle
@ MaximumAngle
Maximum angle between generating radii (lines from arc center to output vertices)
Definition: qgsabstractgeometry.h:118
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:371
QgsMapLayer::crs
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:87
QgsMapTool::flags
virtual Flags flags() const
Returns the flags for the map tool.
Definition: qgsmaptool.h:102
QgsMapSettings::labelingEngineSettings
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns the global configuration of the labeling engine.
Definition: qgsmapsettings.h:534
QgsMapCanvas::renderErrorOccurred
void renderErrorOccurred(const QString &error, QgsMapLayer *layer)
Emitted whenever an error is encountered during a map render operation.
QgsMapCanvas::panToSelected
void panToSelected(QgsVectorLayer *layer=nullptr)
Pan to the selected features of current (vector) layer keeping same extent.
Definition: qgsmapcanvas.cpp:1211
QgsMapCanvas::currentLayerChanged
void currentLayerChanged(QgsMapLayer *layer)
Emitted when the current layer is changed.
QgsMapTool::keyReleaseEvent
virtual void keyReleaseEvent(QKeyEvent *e)
Key event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:187
QgsMapSettings::setDestinationCrs
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
Definition: qgsmapsettings.cpp:309
QgsMapCanvas::dropEvent
void dropEvent(QDropEvent *event) override
Definition: qgsmapcanvas.cpp:2110
qgsexpressioncontextutils.h
QgsMapCanvas::waitWhileRendering
void waitWhileRendering()
Blocks until the rendering job has finished.
Definition: qgsmapcanvas.cpp:2424
QgsMapCanvas::zoomToPreviousExtent
void zoomToPreviousExtent()
Zoom to the previous extent (view)
Definition: qgsmapcanvas.cpp:1013
qgssvgcache.h
QgsMapLayer::hasAutoRefreshEnabled
bool hasAutoRefreshEnabled() const
Returns true if auto refresh is enabled for the layer.
Definition: qgsmaplayer.cpp:675
QgsMapCanvasAnnotationItem
Definition: qgsmapcanvasannotationitem.h:39
QgsMapRendererJob::usedCachedLabels
virtual bool usedCachedLabels() const =0
Returns true if the render job was able to use a cached labeling solution.
QgsPointXY::y
double y
Definition: qgspointxy.h:48
QgsMapRendererJob::Error
Definition: qgsmaprendererjob.h:250
qgspallabeling.h
QgsMapCanvas::extent
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
Definition: qgsmapcanvas.cpp:865
QgsMapCanvas::CanvasProperties::mouseLastXY
QPoint mouseLastXY
Last seen point of the mouse.
Definition: qgsmapcanvas.cpp:113
QgsMapCanvas::moveCanvasContents
void moveCanvasContents(bool reset=false)
called when panning is in action, reset indicates end of panning
Definition: qgsmapcanvas.cpp:2101
QgsMapSettings::mapToLayerCoordinates
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
Definition: qgsmapsettings.cpp:515
QgsMapCanvas::setTheme
void setTheme(const QString &theme)
Sets a map theme to show in the canvas.
Definition: qgsmapcanvas.cpp:1960
QgsProject::viewSettings
const QgsProjectViewSettings * viewSettings() const
Returns the project's view settings, which contains settings and properties relating to how a QgsProj...
Definition: qgsproject.cpp:2910
QgsMapCanvas::mapToolSet
void mapToolSet(QgsMapTool *newTool, QgsMapTool *oldTool)
Emit map tool changed with the old tool.
QgsMapRendererJob::mapSettings
const QgsMapSettings & mapSettings() const
Returns map settings with which this job was started.
QgsMapCanvas::refresh
void refresh()
Repaints the canvas map.
Definition: qgsmapcanvas.cpp:508
QgsMapSettings::setFlag
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
Definition: qgsmapsettings.cpp:341
QgsMapLayer::autoRefreshInterval
int autoRefreshInterval
Definition: qgsmaplayer.h:85
QgsExpressionContextScope::setVariable
void setVariable(const QString &name, const QVariant &value, bool isStatic=false)
Convenience method for setting a variable in the context scope by name name and value.
Definition: qgsexpressioncontext.cpp:78
QgsMapTool::canvasDoubleClickEvent
virtual void canvasDoubleClickEvent(QgsMapMouseEvent *e)
Mouse double-click event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:162
QgsMapCanvas::setWheelFactor
void setWheelFactor(double factor)
Sets wheel zoom factor (should be greater than 1)
Definition: qgsmapcanvas.cpp:1708
QgsMapCanvas::isDrawing
bool isDrawing()
Find out whether rendering is in progress.
Definition: qgsmapcanvas.cpp:317
QgsMapToPixel::mapUnitsPerPixel
double mapUnitsPerPixel() const
Returns current map units per pixel.
Definition: qgsmaptopixel.cpp:128
QgsMapSettings::readXml
void readXml(QDomNode &node)
Definition: qgsmapsettings.cpp:609
QgsRubberBand::ICON_CIRCLE
@ ICON_CIRCLE
A circle is used to highlight points (○)
Definition: qgsrubberband.h:100
QgsRectangle::combineExtentWith
void combineExtentWith(const QgsRectangle &rect)
Expands the rectangle so that it covers both the original rectangle and the given rectangle.
Definition: qgsrectangle.h:359
QgsSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Definition: qgssettings.cpp:174
QgsMapRendererCustomPainterJob::waitForFinished
void waitForFinished() override
Block until the job has finished.
Definition: qgsmaprenderercustompainterjob.cpp:169
QgsExpressionContextUtils::globalScope
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
Definition: qgsexpressioncontextutils.cpp:33
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsMapCanvas::destinationCrsChanged
void destinationCrsChanged()
Emitted when map CRS has changed.
QgsDataProvider
Definition: qgsdataprovider.h:41
QgsMapSettings::outputSize
QSize outputSize() const
Returns the size of the resulting map image.
Definition: qgsmapsettings.cpp:234
QgsMapCanvas::zoomScale
void zoomScale(double scale, bool ignoreScaleLock=false)
Zooms the canvas to a specific scale.
Definition: qgsmapcanvas.cpp:1725
qgsmapcanvas.h
QgsMapCanvas::xyCoordinates
void xyCoordinates(const QgsPointXY &p)
Emits current mouse position.
QgsMapSettings::setRotation
void setRotation(double rotation)
Sets the rotation of the resulting map image, in degrees clockwise.
Definition: qgsmapsettings.cpp:106
QgsMapCanvas::mapTool
QgsMapTool * mapTool()
Returns the currently active tool.
Definition: qgsmapcanvas.cpp:2056
qgsmapthemecollection.h
QgsMapCanvas::zoomByFactor
void zoomByFactor(double scaleFactor, const QgsPointXY *center=nullptr, bool ignoreScaleLock=false)
Zoom with the factor supplied.
Definition: qgsmapcanvas.cpp:2306
QgsMapRendererJob::isActive
virtual bool isActive() const =0
Tell whether the rendering job is currently running in background.
QgsMapCanvas::zoomOut
void zoomOut()
Zoom out with fixed factor.
Definition: qgsmapcanvas.cpp:1719
QgsMapCanvas::zoomLastStatusChanged
void zoomLastStatusChanged(bool)
Emitted when zoom last status changed.
QgsMapCanvas::mouseLastXY
QPoint mouseLastXY()
returns last position of mouse cursor
Definition: qgsmapcanvas.cpp:2144
QgsReferencedRectangle
Definition: qgsreferencedgeometry.h:72
QgsRectangle::setXMinimum
void setXMinimum(double x)
Set the minimum x value.
Definition: qgsrectangle.h:130
QgsMapCanvas::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *e) override
Definition: qgsmapcanvas.cpp:1754
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
QgsGuiUtils::CANVAS_MAGNIFICATION_MIN
constexpr double CANVAS_MAGNIFICATION_MIN
Minimum magnification level allowed in map canvases.
Definition: qgsguiutils.h:61
qgsmaptopixel.h
QgsMapCanvas::mapSettings
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
Definition: qgsmapcanvas.cpp:380
QgsMapCanvas::redrawAllLayers
void redrawAllLayers()
Clears all cached images and redraws all layers.
Definition: qgsmapcanvas.cpp:2415
QgsRubberBand
Definition: qgsrubberband.h:49
QgsPointXY::sqrDist
double sqrDist(double x, double y) const
Returns the squared distance between this point a specified x, y coordinate.
Definition: qgspointxy.h:175
QgsMapSettings::devicePixelRatio
float devicePixelRatio() const
Returns device pixel ratio Common values are 1 for normal-dpi displays and 2 for high-dpi "retina" di...
Definition: qgsmapsettings.cpp:246
QgsExpressionContextScope::readXml
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads scope variables from an XML element.
Definition: qgsexpressioncontext.cpp:205
QgsMapRendererQImageJob::renderedImage
virtual QImage renderedImage()=0
Gets a preview/resulting image.
qgscoordinatetransformcontext.h
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsMapCanvas::CanvasProperties::mouseButtonDown
bool mouseButtonDown
Flag to indicate status of mouse button.
Definition: qgsmapcanvas.cpp:110
QgsApplication::getThemeCursor
static QCursor getThemeCursor(Cursor cursor)
Helper to get a theme cursor.
Definition: qgsapplication.cpp:619
QgsMapCanvas::flashGeometries
void flashGeometries(const QList< QgsGeometry > &geometries, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem(), const QColor &startColor=QColor(255, 0, 0, 255), const QColor &endColor=QColor(255, 0, 0, 0), int flashes=3, int duration=500)
Causes a set of geometries to flash within the canvas.
Definition: qgsmapcanvas.cpp:1257
QgsRectangle::xMaximum
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:162
Qgis::Warning
@ Warning
Definition: qgis.h:104
QgsRubberBand::strokeColor
QColor strokeColor
Definition: qgsrubberband.h:68
QgsMapCanvas::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *e) override
Definition: qgsmapcanvas.cpp:1553
QgsMapThemeCollection::mapThemeChanged
void mapThemeChanged(const QString &theme)
Emitted when a map theme changes definition.
QgsMapCanvas::temporalRangeChanged
void temporalRangeChanged()
Emitted when the map canvas temporal range changes.
qgsfeatureiterator.h
QgsMapRendererCache::clear
void clear()
Invalidates the cache contents, clearing all cached images.
Definition: qgsmaprenderercache.cpp:26
QgsMapSettings::hasValidSettings
bool hasValidSettings() const
Check whether the map settings are valid and can be used for rendering.
Definition: qgsmapsettings.cpp:365
QgsMapCanvas
Definition: qgsmapcanvas.h:78
QgsMapCanvas::panActionEnd
void panActionEnd(QPoint releasePoint)
Ends pan action and redraws the canvas.
Definition: qgsmapcanvas.cpp:2061
QgsMapSettings::fullExtent
QgsRectangle fullExtent() const
returns current extent of layer set
Definition: qgsmapsettings.cpp:550
QgsMapTool::deactivate
virtual void deactivate()
called when map tool is being deactivated
Definition: qgsmaptool.cpp:99
QgsMapSettings::setSegmentationToleranceType
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Definition: qgsmapsettings.h:507
QgsMapSettings::writeXml
void writeXml(QDomNode &node, QDomDocument &doc)
Definition: qgsmapsettings.cpp:644
QgsMapCanvas::center
QgsPointXY center() const
Gets map center, in geographical coordinates.
Definition: qgsmapcanvas.cpp:963
QgsLabelingResults
Definition: qgspallabeling.h:1190
QgsExpressionContextScope::writeXml
bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Writes scope variables to an XML element.
Definition: qgsexpressioncontext.cpp:217
qgsmapcanvasannotationitem.h
QgsFeature::geometry
QgsGeometry geometry
Definition: qgsfeature.h:71
QgsProject::transformContext
QgsCoordinateTransformContext transformContext
Definition: qgsproject.h:99
QgsTemporalRangeObject::temporalRange
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
Definition: qgstemporalrangeobject.cpp:43
QgsMapCanvas::fullExtent
QgsRectangle fullExtent() const
Returns the combined extent for all layers on the map canvas.
Definition: qgsmapcanvas.cpp:870
QgsMapSettings::mapUnitsPerPixel
double mapUnitsPerPixel() const
Returns the distance in geographical coordinates that equals to one pixel in the map.
Definition: qgsmapsettings.cpp:390
QgsMapCanvas::~QgsMapCanvas
~QgsMapCanvas() override
Definition: qgsmapcanvas.cpp:225
QgsMapCanvas::setRotation
void setRotation(double degrees)
Set the rotation of the map canvas in clockwise degrees.
Definition: qgsmapcanvas.cpp:979
qgis.h
QgsExpressionContextUtils::mapSettingsScope
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
Definition: qgsexpressioncontextutils.cpp:346
qgsmaprenderercustompainterjob.h
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:457
QgsMapSettings::layerExtentToOutputExtent
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer's CRS to output CRS
Definition: qgsmapsettings.cpp:432
QgsRubberBand::setStrokeColor
void setStrokeColor(const QColor &color)
Sets the stroke color for the rubberband.
Definition: qgsrubberband.cpp:60
QgsMapCanvas::scale
double scale() const
Returns the last reported scale of the canvas.
Definition: qgsmapcanvas.cpp:312
QgsMapTool::Transient
@ Transient
Definition: qgsmaptool.h:90
QgsMapCanvas::rotationChanged
void rotationChanged(double)
Emitted when the rotation of the map changes.
QgsProject::readProject
void readProject(const QDomDocument &)
Emitted when a project is being read.
QgsMapCanvas::zoomWithCenter
void zoomWithCenter(int x, int y, bool zoomIn)
Zooms in/out with a given center.
Definition: qgsmapcanvas.cpp:1730
QgsMapSettings::magnificationFactor
double magnificationFactor() const
Returns the magnification factor.
Definition: qgsmapsettings.cpp:69
QgsRubberBand::setFillColor
void setFillColor(const QColor &color)
Sets the fill color for the rubberband.
Definition: qgsrubberband.cpp:52
QgsMapSettings::layerStyleOverrides
QMap< QString, QString > layerStyleOverrides() const
Gets map of map layer style overrides (key: layer ID, value: style name) where a different style shou...
Definition: qgsmapsettings.cpp:299
QgsSettings
Definition: qgssettings.h:61
QgsMapCanvas::writeProject
void writeProject(QDomDocument &)
called to write map canvas settings to project
Definition: qgsmapcanvas.cpp:2271
QgsMapCanvas::selectionChangedSlot
void selectionChangedSlot()
Receives signal about selection change, and pass it on with layer info.
Definition: qgsmapcanvas.cpp:2322
QgsMapCanvas::panAction
void panAction(QMouseEvent *event)
Called when mouse is moving and pan is activated.
Definition: qgsmapcanvas.cpp:2089
QgsMapLayer::reload
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:466
QgsMapCanvas::clearCache
void clearCache()
Make sure to remove any rendered images from cache (does nothing if cache is not enabled)
Definition: qgsmapcanvas.cpp:468
QgsMapSettings::RenderPartialOutput
@ RenderPartialOutput
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
Definition: qgsmapsettings.h:310
QgsRubberBand::fillColor
QColor fillColor
Definition: qgsrubberband.h:67
QgsMapCanvas::CanvasProperties::panSelectorDown
bool panSelectorDown
Flag to indicate the pan selector key is held down by user.
Definition: qgsmapcanvas.cpp:119
QgsMapCanvas::mapUnits
QgsUnitTypes::DistanceUnit mapUnits() const
Convenience function for returning the current canvas map units.
Definition: qgsmapcanvas.cpp:1940
QgsAbstractGeometry::SegmentationToleranceType
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle.
Definition: qgsabstractgeometry.h:112
qgsmimedatautils.h
QgsMimeDataUtils::UriList
QList< QgsMimeDataUtils::Uri > UriList
Definition: qgsmimedatautils.h:155
QgsMapCanvas::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *e) override
Definition: qgsmapcanvas.cpp:2333
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
qgsmaprenderercache.h
QgsUnitTypes::DistanceUnit
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:67
QgsMapCanvas::paintEvent
void paintEvent(QPaintEvent *e) override
Definition: qgsmapcanvas.cpp:1643
QgsProject::mapLayer
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
Definition: qgsproject.cpp:3048
QgsMapToPixel::toMapCoordinates
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
Definition: qgsmaptopixel.cpp:108
QgsRubberBand::secondaryStrokeColor
QColor secondaryStrokeColor
Definition: qgsrubberband.h:70
QgsCoordinateTransform::transform
QgsPointXY transform(const QgsPointXY &point, TransformDirection direction=ForwardTransform) const SIP_THROW(QgsCsException)
Transform the point from the source CRS to the destination CRS.
Definition: qgscoordinatetransform.cpp:237
QgsMapCanvas::freeze
void freeze(bool frozen=true)
Freeze/thaw the map canvas.
Definition: qgsmapcanvas.cpp:1925
QgsMapTool::clean
virtual void clean()
convenient method to clean members
Definition: qgsmaptool.cpp:109
QgsMapTool::keyPressEvent
virtual void keyPressEvent(QKeyEvent *e)
Key event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:182
QgsMapCanvas::layers
QList< QgsMapLayer * > layers() const
Returns the list of layers shown within the map canvas.
Definition: qgsmapcanvas.cpp:1914
QgsMapCanvas::wheelEvent
void wheelEvent(QWheelEvent *e) override
Definition: qgsmapcanvas.cpp:1665
QgsMapCanvas::QgsMapCanvas
QgsMapCanvas(QWidget *parent=nullptr)
Constructor.
Definition: qgsmapcanvas.cpp:111
QgsMapSettings::setSegmentationTolerance
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
Definition: qgsmapsettings.h:500
QgsRectangle
Definition: qgsrectangle.h:41
QgsMapCanvas::setSegmentationToleranceType
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
Definition: qgsmapcanvas.cpp:2437
QgsMapRendererCache
Definition: qgsmaprenderercache.h:42
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:143
QgsMapRendererCustomPainterJob::start
void start() override
Start the rendering job and immediately return.
Definition: qgsmaprenderercustompainterjob.cpp:75
QgsMapCanvas::setMapSettingsFlags
void setMapSettingsFlags(QgsMapSettings::Flags flags)
Resets the flags for the canvas' map settings.
Definition: qgsmapcanvas.cpp:429
QgsCoordinateTransform::transformBoundingBox
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, TransformDirection direction=ForwardTransform, bool handle180Crossover=false) const SIP_THROW(QgsCsException)
Transforms a rectangle from the source CRS to the destination CRS.
Definition: qgscoordinatetransform.cpp:509
QgsVectorLayer::isEditable
bool isEditable() const FINAL
Returns true if the provider is in editing mode.
Definition: qgsvectorlayer.cpp:3509
QgsProject
Definition: qgsproject.h:92
QgsPreviewEffect::PreviewGrayscale
@ PreviewGrayscale
Definition: qgsprevieweffect.h:64
QgsGuiUtils::CANVAS_MAGNIFICATION_MAX
constexpr double CANVAS_MAGNIFICATION_MAX
Maximum magnification level allowed in map canvases.
Definition: qgsguiutils.h:69
QgsMapCanvas::snappingUtils
QgsSnappingUtils * snappingUtils() const
Returns snapping utility class that is associated with map canvas.
Definition: qgsmapcanvas.cpp:2189
QgsMapCanvas::setPreviewJobsEnabled
void setPreviewJobsEnabled(bool enabled)
Sets whether canvas map preview jobs (low priority render jobs which render portions of the view just...
Definition: qgsmapcanvas.cpp:732
qgsrubberband.h
QgsMapCanvas::scaleChanged
void scaleChanged(double)
Emitted when the scale of the map changes.
QgsMapSettings::extent
QgsRectangle extent() const
Returns geographical coordinates of the rectangle that should be rendered.
Definition: qgsmapsettings.cpp:74
QgsProject::writeProject
void writeProject(QDomDocument &)
Emitted when the project is being written.
QgsMapSettings::DrawLabeling
@ DrawLabeling
Enable drawing of labels on top of the map.
Definition: qgsmapsettings.h:305
QgsMapCanvas::isParallelRenderingEnabled
bool isParallelRenderingEnabled() const
Check whether the layers are rendered in parallel or sequentially.
Definition: qgsmapcanvas.cpp:479
QgsMapRendererJob::renderingTime
int renderingTime() const
Returns the total time it took to finish the job (in milliseconds).
Definition: qgsmaprendererjob.h:277
QgsMapCanvas::labelingResults
const QgsLabelingResults * labelingResults() const
Gets access to the labeling results (may be nullptr)
Definition: qgsmapcanvas.cpp:436
qgsapplication.h
QgsMapTool
Definition: qgsmaptool.h:62
QgsFeatureRequest::setFilterRect
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
Definition: qgsfeaturerequest.cpp:94
QgsMapCanvasSnappingUtils
Definition: qgsmapcanvassnappingutils.h:33
QgsMapCanvas::setCurrentLayer
void setCurrentLayer(QgsMapLayer *layer)
Definition: qgsmapcanvas.cpp:303
qgsmaptoolzoom.h
QgsMapRendererJob::errors
Errors errors() const
List of errors that happened during the rendering job - available when the rendering has been finishe...
QgsMapRendererParallelJob
Definition: qgsmaprendererparalleljob.h:32
QgsMapCanvasItem::updatePosition
virtual void updatePosition()
called on changed extent or resize event to update position of the item
Definition: qgsmapcanvasitem.cpp:135
QgsMapCanvas::rotation
double rotation() const
Gets the current map canvas rotation in clockwise degrees.
Definition: qgsmapcanvas.cpp:974
QgsRectangle::scale
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
Definition: qgsrectangle.h:235
qgstemporalcontroller.h
QgsDistanceArea::setEllipsoid
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
Definition: qgsdistancearea.cpp:66
QgsMapCanvas::zoomIn
void zoomIn()
Zoom in with fixed factor.
Definition: qgsmapcanvas.cpp:1713
QgsMapCanvas::readProject
void readProject(const QDomDocument &)
called to read map canvas settings from project
Definition: qgsmapcanvas.cpp:2205
QgsFeatureRequest
Definition: qgsfeaturerequest.h:72
qgsmaplayertemporalproperties.h
QgsExpressionContextUtils::projectScope
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
Definition: qgsexpressioncontextutils.cpp:211
qgsmaptoolpan.h
QgsPreviewEffect::PreviewMode
PreviewMode
Definition: qgsprevieweffect.h:49
QgsMapCanvas::enableAntiAliasing
void enableAntiAliasing(bool flag)
used to determine if anti-aliasing is enabled or not
Definition: qgsmapcanvas.cpp:284
QgsCsException
Definition: qgsexception.h:65
QgsMapSettings::setBackgroundColor
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
Definition: qgsmapsettings.h:289
QgsMapCanvas::setTemporalController
void setTemporalController(QgsTemporalController *controller)
Sets the temporal controller, this controller will be used to update the canvas temporal range.
Definition: qgsmapcanvas.cpp:420
QgsMapCanvasItem
Definition: qgsmapcanvasitem.h:33
QgsProjectViewSettings::defaultViewExtent
QgsReferencedRectangle defaultViewExtent() const
Returns the default view extent, which should be used as the initial map extent when this project is ...
Definition: qgsprojectviewsettings.cpp:37
QgsMapCanvas::setPreviewMode
void setPreviewMode(QgsPreviewEffect::PreviewMode mode)
Sets a preview mode for the map canvas.
Definition: qgsmapcanvas.cpp:2169
QgsMapRendererJob::perLayerRenderingTime
QHash< QgsMapLayer *, int > perLayerRenderingTime() const
Returns the render time (in ms) per layer.
QgsMapSettings::setMagnificationFactor
void setMagnificationFactor(double factor)
Set the magnification factor.
Definition: qgsmapsettings.cpp:48
QgsMapLayer::dataProvider
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
Definition: qgsmaplayer.cpp:168
QgsMapCanvas::layerCount
int layerCount() const
Returns number of layers on the map.
Definition: qgsmapcanvas.cpp:1908
QgsMapSettings::rotation
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
Definition: qgsmapsettings.cpp:101
QgsMapRendererJob::waitForFinished
virtual void waitForFinished()=0
Block until the job has finished.
qgsmapsettingsutils.h
QgsMapCanvas::layerStyleOverrides
QMap< QString, QString > layerStyleOverrides() const
Returns the stored overrides of styles for layers.
Definition: qgsmapcanvas.cpp:1945
QgsTemporalProperty::isActive
bool isActive() const
Returns true if the temporal property is active.
Definition: qgstemporalproperty.cpp:36
QgsDistanceArea::bearing
double bearing(const QgsPointXY &p1, const QgsPointXY &p2) const
Computes the bearing (in radians) between two points.
Definition: qgsdistancearea.cpp:842
whileBlocking
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition: qgis.h:262
QgsMapCanvas::canvasColor
QColor canvasColor() const
Read property of QColor bgColor.
Definition: qgsmapcanvas.cpp:1869
QgsLabelingEngineSettings
Definition: qgslabelingenginesettings.h:30
QgsVectorLayer::selectionChanged
void selectionChanged(const QgsFeatureIds &selected, const QgsFeatureIds &deselected, bool clearAndSelect)
Emitted when selection was changed.
QgsMapCanvas::zoomToSelected
void zoomToSelected(QgsVectorLayer *layer=nullptr)
Zoom to the extent of the selected features of provided (vector) layer.
Definition: qgsmapcanvas.cpp:1054
QgsMapCanvas::setMagnificationFactor
void setMagnificationFactor(double factor)
Sets the factor of magnification to apply to the map canvas.
Definition: qgsmapcanvas.cpp:263
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:315
QgsMapCanvas::layersChanged
void layersChanged()
Emitted when a new set of layers has been received.
QgsMapLayer::repaintRequested
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
QgsMapCanvas::layer
QgsMapLayer * layer(int index)
Returns the map layer at position index in the layer stack.
Definition: qgsmapcanvas.cpp:294
QgsMapRendererJob::setCache
void setCache(QgsMapRendererCache *cache)
Assign a cache to be used for reading and storing rendered images of individual layers.
QgsMapTool::gestureEvent
virtual bool gestureEvent(QGestureEvent *e)
gesture event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:192
QgsMapSettings::mapUnits
QgsUnitTypes::DistanceUnit mapUnits() const
Gets units of map's geographical coordinates - used for scale calculation.
Definition: qgsmapsettings.cpp:359
QgsMapCanvas::keyReleaseEvent
void keyReleaseEvent(QKeyEvent *e) override
Definition: qgsmapcanvas.cpp:1428
QgsException::what
QString what() const
Definition: qgsexception.h:48
qgsmaplayer.h
qgsmessageviewer.h
QgsDistanceArea::measureLine
double measureLine(const QVector< QgsPointXY > &points) const
Measures the length of a line with multiple segments.
Definition: qgsdistancearea.cpp:273
QgsProject::projectColorsChanged
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
QgsMapCanvas::extentsChanged
void extentsChanged()
Emitted when the extents of the map change.
QgsMapCanvas::setSegmentationTolerance
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
Definition: qgsmapcanvas.cpp:2432
QgsMapThemeCollection::mapThemesChanged
void mapThemesChanged()
Emitted when map themes within the collection are changed.
QgsMapCanvas::updateCanvasItemPositions
void updateCanvasItemPositions()
called on resize or changed extent to notify canvas items to change their rectangle
Definition: qgsmapcanvas.cpp:1650
QgsMapSettings::Antialiasing
@ Antialiasing
Enable anti-aliasing for map rendering.
Definition: qgsmapsettings.h:301
QgsTemporalController
Definition: qgstemporalcontroller.h:35
QgsDistanceArea::lengthUnits
QgsUnitTypes::DistanceUnit lengthUnits() const
Returns the units of distance for length calculations made by this object.
Definition: qgsdistancearea.cpp:789
QgsApplication::imageCache
static QgsImageCache * imageCache()
Returns the application's image cache, used for caching resampled versions of raster images.
Definition: qgsapplication.cpp:2118
QgsMapLayer::temporalProperties
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
Definition: qgsmaplayer.h:1189
QgsMapRendererSequentialJob
Definition: qgsmaprenderersequentialjob.h:33
QgsDataProvider::PreviewContext
Stores settings related to the context in which a preview job runs.
Definition: qgsdataprovider.h:489
QgsMapCanvas::setTemporalRange
void setTemporalRange(const QgsDateTimeRange &range)
Set datetime range for the map canvas.
Definition: qgsmapcanvas.cpp:742
QgsMapCanvas::mCanvasProperties
std::unique_ptr< CanvasProperties > mCanvasProperties
Handle pattern for implementation object.
Definition: qgsmapcanvas.h:1000
QgsMapSettings::setSelectionColor
void setSelectionColor(const QColor &color)
Sets color that is used for drawing of selected vector features.
Definition: qgsmapsettings.h:294
QgsWkbTypes::geometryType
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Definition: qgswkbtypes.h:812
QgsMapCanvas::updateScale
void updateScale()
Emits signal scaleChanged to update scale in main window.
Definition: qgsmapcanvas.cpp:992
QgsMapCanvas::theme
QString theme
Definition: qgsmapcanvas.h:91
QgsRectangle::setXMaximum
void setXMaximum(double x)
Set the maximum x value.
Definition: qgsrectangle.h:135
QgsLogger::warning
static void warning(const QString &msg)
Goes to qWarning.
Definition: qgslogger.cpp:122
QgsMapCanvas::setDestinationCrs
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
Definition: qgsmapcanvas.cpp:385
QgsMapCanvas::setCanvasColor
void setCanvasColor(const QColor &_newVal)
Write property of QColor bgColor.
Definition: qgsmapcanvas.cpp:1844
QgsMapCanvas::setCenter
void setCenter(const QgsPointXY &center)
Set the center of the map canvas, in geographical coordinates.
Definition: qgsmapcanvas.cpp:945
QgsMapSettings::setFlags
void setFlags(QgsMapSettings::Flags flags)
Sets combination of flags that will be used for rendering.
Definition: qgsmapsettings.cpp:336
QgsMapCanvas::resizeEvent
void resizeEvent(QResizeEvent *e) override
Definition: qgsmapcanvas.cpp:1614
QgsMapLayer::id
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
Definition: qgsmaplayer.cpp:147
QgsMapCanvas::labelingEngineSettings
const QgsLabelingEngineSettings & labelingEngineSettings() const
Returns global labeling engine settings from the internal map settings.
Definition: qgsmapcanvas.cpp:2473
QgsMapCanvas::enableMapTileRendering
void enableMapTileRendering(bool flag)
sets map tile rendering flag
Definition: qgsmapcanvas.cpp:289
QgsMapCanvas::zoomToFullExtent
void zoomToFullExtent()
Zoom to the full extent of all layers.
Definition: qgsmapcanvas.cpp:998
QgsMapCanvas::selectionColor
QColor selectionColor() const
Returns color for selected features.
Definition: qgsmapcanvas.cpp:1903
QgsMapToolPan
Definition: qgsmaptoolpan.h:32
QgsGeometry::isNull
bool isNull
Definition: qgsgeometry.h:125
QgsMapSettings::scale
double scale() const
Returns the calculated map scale.
Definition: qgsmapsettings.cpp:395
QgsMapCanvas::layerStyleOverridesChanged
void layerStyleOverridesChanged()
Emitted when the configuration of overridden layer styles changes.
QgsProject::mapThemeCollection
QgsMapThemeCollection mapThemeCollection
Definition: qgsproject.h:101
QgsGeometry::constGet
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Definition: qgsgeometry.cpp:125
QgsDataProvider::PreviewContext::maxRenderingTimeMs
double maxRenderingTimeMs
Default maximum allowable render time, in ms.
Definition: qgsdataprovider.h:495
QgsMapCanvas::zoomToNextExtent
void zoomToNextExtent()
Zoom to the next extent (view)
Definition: qgsmapcanvas.cpp:1029
QgsMapCanvas::setReferencedExtent
bool setReferencedExtent(const QgsReferencedRectangle &extent) SIP_THROW(QgsCsException)
Sets the canvas to the specified extent.
Definition: qgsmapcanvas.cpp:927
QgsMapRendererJob::start
virtual void start()=0
Start the rendering job and immediately return.
QgsMapCanvas::refreshAllLayers
void refreshAllLayers()
Reload all layers (including refreshing layer properties from their data sources),...
Definition: qgsmapcanvas.cpp:2403
QgsDistanceArea::setSourceCrs
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
Definition: qgsdistancearea.cpp:60
QgsMapCanvas::setExtent
void setExtent(const QgsRectangle &r, bool magnified=false)
Sets the extent of the map canvas to the specified rectangle.
Definition: qgsmapcanvas.cpp:876
QgsMapSettings::RenderMapTile
@ RenderMapTile
Draw map such that there are no problems between adjacent tiles.
Definition: qgsmapsettings.h:309
QgsProject::transformContextChanged
void transformContextChanged()
Emitted when the project transformContext() is changed.
QgsMapCanvas::setMapTool
void setMapTool(QgsMapTool *mapTool, bool clean=false)
Sets the map tool currently being used on the canvas.
Definition: qgsmapcanvas.cpp:1786
QgsMapCanvas::previewMode
QgsPreviewEffect::PreviewMode previewMode() const
Returns the current preview mode for the map canvas.
Definition: qgsmapcanvas.cpp:2179
QgsMapCanvas::getCoordinateTransform
const QgsMapToPixel * getCoordinateTransform()
Gets the current coordinate transform.
Definition: qgsmapcanvas.cpp:324
QgsMimeDataUtils::Uri
Definition: qgsmimedatautils.h:40
QgsFeatureRequest::setNoAttributes
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
Definition: qgsfeaturerequest.cpp:194
QgsMapCanvas::setParallelRenderingEnabled
void setParallelRenderingEnabled(bool enabled)
Set whether the layers are rendered in parallel or sequentially.
Definition: qgsmapcanvas.cpp:474
QgsMapCanvas::panToFeatureIds
void panToFeatureIds(QgsVectorLayer *layer, const QgsFeatureIds &ids, bool alwaysRecenter=true)
Centers canvas extent to feature ids.
Definition: qgsmapcanvas.cpp:1153
QgsAbstractGeometry::isEmpty
virtual bool isEmpty() const
Returns true if the geometry is empty.
Definition: qgsabstractgeometry.cpp:298
QgsFeatureIds
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
QgsMapTool::activate
virtual void activate()
called when set as currently active map tool
Definition: qgsmaptool.cpp:83
QgsMapCanvas::keyPressEvent
void keyPressEvent(QKeyEvent *e) override
Definition: qgsmapcanvas.cpp:1334
QgsMapCanvas::zoomToFeatureExtent
void zoomToFeatureExtent(QgsRectangle &rect)
Zooms to feature extent.
Definition: qgsmapcanvas.cpp:1109
QgsMapCanvas::saveAsImage
void saveAsImage(const QString &fileName, QPixmap *QPixmap=nullptr, const QString &="PNG")
Save the contents of the map canvas to disk as an image.
Definition: qgsmapcanvas.cpp:795
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:209
QgsDataProvider::renderInPreview
virtual bool renderInPreview(const QgsDataProvider::PreviewContext &context)
Returns whether the layer must be rendered in preview jobs.
Definition: qgsdataprovider.cpp:64
QgsSnappingUtils
Definition: qgssnappingutils.h:47
QgsMapSettings::selectionColor
QColor selectionColor() const
Gets color that is used for drawing of selected vector features.
Definition: qgsmapsettings.h:296
QgsMapSettingsUtils::worldFileContent
static QString worldFileContent(const QgsMapSettings &mapSettings)
Creates the content of a world file.
Definition: qgsmapsettingsutils.cpp:114
QgsMapCanvas::setRenderFlag
void setRenderFlag(bool flag)
Sets whether a user has disabled canvas renders via the GUI.
Definition: qgsmapcanvas.cpp:1981
QgsMapCanvas::mapUpdateInterval
int mapUpdateInterval() const
Find out how often map preview should be updated while it is being rendered (in milliseconds)
Definition: qgsmapcanvas.cpp:489
QgsRectangle::yMaximum
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:172
QgsMapSettings::RenderPreviewJob
@ RenderPreviewJob
Render is a 'canvas preview' render, and shortcuts should be taken to ensure fast rendering.
Definition: qgsmapsettings.h:311
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:111
QgsApplication::svgCache
static QgsSvgCache * svgCache()
Returns the application's SVG cache, used for caching SVG images and handling parameter replacement w...
Definition: qgsapplication.cpp:2113
QgsMapSettings::setLabelingEngineSettings
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets the global configuration of the labeling engine.
Definition: qgsmapsettings.h:521
QgsMapSettings::setLayers
void setLayers(const QList< QgsMapLayer * > &layers)
Set list of layers for map rendering.
Definition: qgsmapsettings.cpp:286
QgsMapCanvas::setScaleLocked
void setScaleLocked(bool isLocked)
Lock the scale, so zooming can be performed using magnication.
Definition: qgsmapcanvas.cpp:1749
QgsMapCanvas::flashFeatureIds
void flashFeatureIds(QgsVectorLayer *layer, const QgsFeatureIds &ids, const QColor &startColor=QColor(255, 0, 0, 255), const QColor &endColor=QColor(255, 0, 0, 0), int flashes=3, int duration=500)
Causes a set of features with matching ids from a vector layer to flash within the canvas.
Definition: qgsmapcanvas.cpp:1234
qgsvectorlayer.h
QgsPointXY
Definition: qgspointxy.h:43
QgsMapSettings::destinationCrs
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
Definition: qgsmapsettings.cpp:317
qgsmaprenderersequentialjob.h
QgsMapRendererCustomPainterJob
Definition: qgsmaprenderercustompainterjob.h:63
qgsmapcanvassnappingutils.h
QgsGeometry::asPoint
QgsPointXY asPoint() const
Returns the contents of the geometry as a 2-dimensional point.
Definition: qgsgeometry.cpp:1422
QgsMapTool::canvasPressEvent
virtual void canvasPressEvent(QgsMapMouseEvent *e)
Mouse press event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:167
QgsMapCanvas::setMapUpdateInterval
void setMapUpdateInterval(int timeMilliseconds)
Set how often map preview should be updated while it is being rendered (in milliseconds)
Definition: qgsmapcanvas.cpp:484
QgsMapSettings::setExpressionContext
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Definition: qgsmapsettings.h:384
qgsreferencedgeometry.h
QgsMapCanvas::keyReleased
void keyReleased(QKeyEvent *e)
Emit key release event.
qgsprojectviewsettings.h
QgsMapCanvas::temporalRange
const QgsDateTimeRange & temporalRange() const
Returns map canvas datetime range.
Definition: qgsmapcanvas.cpp:766
QgsMapMouseEvent
Definition: qgsmapmouseevent.h:35
QgsMapCanvas::clearExtentHistory
void clearExtentHistory()
Definition: qgsmapcanvas.cpp:1044
QgsMapTool::canvasMoveEvent
virtual void canvasMoveEvent(QgsMapMouseEvent *e)
Mouse move event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:157
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:142
QgsMapSettings::UseRenderingOptimization
@ UseRenderingOptimization
Enable vector simplification and other rendering optimizations.
Definition: qgsmapsettings.h:306
QgsMapRendererQImageJob
Definition: qgsmaprendererjob.h:435
QgsWkbTypes::PointGeometry
@ PointGeometry
Definition: qgswkbtypes.h:141
QgsTemporalController::updateTemporalRange
void updateTemporalRange(const QgsDateTimeRange &range)
Signals that a temporal range has changed and needs to be updated in all connected objects.
QgsMapCanvas::event
bool event(QEvent *e) override
Definition: qgsmapcanvas.cpp:2377
QgsRubberBand::setWidth
void setWidth(int width)
Sets the width of the line.
Definition: qgsrubberband.cpp:70
QgsMapCanvas::setAnnotationsVisible
void setAnnotationsVisible(bool visible)
Sets whether annotations are visible in the canvas.
Definition: qgsmapcanvas.cpp:2458
QgsRectangle::center
QgsPointXY center() const
Returns the center point of the rectangle.
Definition: qgsrectangle.h:230
QgsMapCanvas::canvasColorChanged
void canvasColorChanged()
Emitted when canvas background color changes.
QgsMimeDataUtils::decodeUriList
static UriList decodeUriList(const QMimeData *data)
Definition: qgsmimedatautils.cpp:204
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:139
QgsMapSettings::testFlag
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
Definition: qgsmapsettings.cpp:354
QgsMapCanvas::tapAndHoldGestureOccurred
void tapAndHoldGestureOccurred(const QgsPointXY &mapPoint, QTapAndHoldGesture *gesture)
Emitted whenever a tap and hold gesture occurs at the specified map point.
QgsMapCanvas::setCustomDropHandlers
void setCustomDropHandlers(const QVector< QPointer< QgsCustomDropHandler >> &handlers)
Sets a list of custom drop handlers to use when drop events occur on the canvas.
Definition: qgsmapcanvas.cpp:737
QgsFeatureIterator::nextFeature
bool nextFeature(QgsFeature &f)
Definition: qgsfeatureiterator.h:373
QgsMapCanvas::themeChanged
void themeChanged(const QString &theme)
Emitted when the canvas has been assigned a different map theme.
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsGeometry
Definition: qgsgeometry.h:122
QgsMapCanvas::previewJobsEnabled
bool previewJobsEnabled
Definition: qgsmapcanvas.h:92
QgsMapToPixel
Definition: qgsmaptopixel.h:37
QgsMapSettings::setLayerStyleOverrides
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Set map of map layer style overrides (key: layer ID, value: style name) where a different style shoul...
Definition: qgsmapsettings.cpp:304
QgsVectorLayer
Definition: qgsvectorlayer.h:386
QgsFeature::hasGeometry
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:197
qgsimagecache.h
QgsMapCanvas::isCachingEnabled
bool isCachingEnabled() const
Check whether images of rendered layers are curerently being cached.
Definition: qgsmapcanvas.cpp:463
QgsMapCanvas::selectionChanged
void selectionChanged(QgsVectorLayer *layer)
Emitted when selection in any layer gets changed.
QgsMapSettings::DrawEditingInfo
@ DrawEditingInfo
Enable drawing of vertex markers for layers in editing mode.
Definition: qgsmapsettings.h:302
QgsFeatureRequest::setLimit
QgsFeatureRequest & setLimit(long limit)
Set the maximum number of features to request.
Definition: qgsfeaturerequest.cpp:175
QgsMapTool::canvasReleaseEvent
virtual void canvasReleaseEvent(QgsMapMouseEvent *e)
Mouse release event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:172
QgsMapLayer
Definition: qgsmaplayer.h:80
QgsMapCanvas::isFrozen
bool isFrozen() const
Returns true if canvas is frozen.
Definition: qgsmapcanvas.cpp:1930
QgsVector
Definition: qgsvector.h:29
QgsRubberBand::addGeometry
void addGeometry(const QgsGeometry &geometry, QgsVectorLayer *layer)
Adds the geometry of an existing feature to a rubberband This is useful for multi feature highlightin...
Definition: qgsrubberband.cpp:258
QgsMapCanvas::magnificationChanged
void magnificationChanged(double)
Emitted when the scale of the map changes.
QgsPointXY::x
double x
Definition: qgspointxy.h:47
QgsCustomDropHandler
Definition: qgscustomdrophandler.h:49
qgsmapoverviewcanvas.h
qgssettings.h
QgsRectangle::height
double height() const
Returns the height of the rectangle.
Definition: qgsrectangle.h:209
QgsMessageLog::logMessage
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Definition: qgsmessagelog.cpp:27
QgsProject::ellipsoidChanged
void ellipsoidChanged(const QString &ellipsoid)
Emitted when the project ellipsoid is changed.
QgsMapRendererJob::cancelWithoutBlocking
virtual void cancelWithoutBlocking()=0
Triggers cancellation of the rendering job without blocking.
QgsMapCanvas::previewModeEnabled
bool previewModeEnabled() const
Returns whether a preview mode is enabled for the map canvas.
Definition: qgsmapcanvas.cpp:2159
QgsMapCanvas::setPreviewModeEnabled
void setPreviewModeEnabled(bool previewEnabled)
Enables a preview mode for the map canvas.
Definition: qgsmapcanvas.cpp:2149
QgsMapCanvas::panDistanceBearingChanged
void panDistanceBearingChanged(double distance, QgsUnitTypes::DistanceUnit unit, double bearing)
Emitted whenever the distance or bearing of an in-progress panning operation is changed.
QgsMapCanvas::defaultExpressionContextScope
QgsExpressionContextScope * defaultExpressionContextScope()
Creates a new scope which contains default variables and functions relating to the map canvas.
Definition: qgsmapcanvas.cpp:500
QgsRectangle::yMinimum
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
QgsRubberBand::setIcon
void setIcon(IconType icon)
Sets the icon type to highlight point geometries.
Definition: qgsrubberband.cpp:75
QgsMapCanvas::keyPressed
void keyPressed(QKeyEvent *e)
Emit key press event.
QgsMapCanvas::unsetMapTool
void unsetMapTool(QgsMapTool *mapTool)
Unset the current map tool or last non zoom tool.
Definition: qgsmapcanvas.cpp:1826
qgsdatumtransformdialog.h
QgsMapCanvas::mousePressEvent
void mousePressEvent(QMouseEvent *e) override
Definition: qgsmapcanvas.cpp:1515
QgsExpressionContextUtils::atlasScope
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
Definition: qgsexpressioncontextutils.cpp:560
QgsMapCanvas::renderComplete
void renderComplete(QPainter *)
Emitted when the canvas has rendered.
QgsMapCanvas::CanvasProperties
Definition: qgsmapcanvas.cpp:87
qgscustomdrophandler.h
QgsMapSettings::layers
QList< QgsMapLayer * > layers() const
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
Definition: qgsmapsettings.cpp:281
QgsTemporalRangeObject::setTemporalRange
void setTemporalRange(const QgsDateTimeRange &range)
Sets the temporal range for the object.
Definition: qgstemporalrangeobject.cpp:35
QgsGeometry::boundingBox
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Definition: qgsgeometry.cpp:948
QgsDistanceArea
Definition: qgsdistancearea.h:49
QgsMapTool::wheelEvent
virtual void wheelEvent(QWheelEvent *e)
Mouse wheel event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:177
QgsPreviewEffect::setMode
void setMode(PreviewMode mode)
Sets the mode for the preview effect, which controls how the effect modifies a widgets appearance.
Definition: qgsprevieweffect.cpp:30
qgsexception.h
QgsMapCanvas::messageEmitted
void messageEmitted(const QString &title, const QString &message, Qgis::MessageLevel=Qgis::Info)
emit a message (usually to be displayed in a message bar)
QgsFeature
Definition: qgsfeature.h:55
QgsMapCanvas::magnificationFactor
double magnificationFactor() const
Returns the magnification factor.
Definition: qgsmapcanvas.cpp:279
QgsPreviewEffect
Definition: qgsprevieweffect.h:31
QgsMapRendererJob::takeLabelingResults
virtual QgsLabelingResults * takeLabelingResults()=0
Gets pointer to internal labeling engine (in order to get access to the results).
QgsMapCanvas::currentLayer
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
Definition: qgsmapcanvas.cpp:495
QgsMapCanvas::setSnappingUtils
void setSnappingUtils(QgsSnappingUtils *utils)
Assign an instance of snapping utils to the map canvas.
Definition: qgsmapcanvas.cpp:2200
QgsMapThemeCollection::hasMapTheme
bool hasMapTheme(const QString &name) const
Returns whether a map theme with a matching name exists.
Definition: qgsmapthemecollection.cpp:258
QgsDataProvider::PreviewContext::lastRenderingTimeMs
double lastRenderingTimeMs
Previous rendering time for the layer, in ms.
Definition: qgsdataprovider.h:492
QgsMapCanvas::zoomToFeatureIds
void zoomToFeatureIds(QgsVectorLayer *layer, const QgsFeatureIds &ids)
Set canvas extent to the bounding box of a set of features.
Definition: qgsmapcanvas.cpp:1133
QgsImageCache::remoteImageFetched
void remoteImageFetched(const QString &url)
Emitted when the cache has finished retrieving an image file from a remote url.
QgsMapTool::AllowZoomRect
@ AllowZoomRect
Allow zooming by rectangle (by holding shift and dragging) while the tool is active.
Definition: qgsmaptool.h:94
QgsMapCanvas::zoomNextStatusChanged
void zoomNextStatusChanged(bool)
Emitted when zoom next status changed.
QgsVectorLayer::selectedFeatureCount
int selectedFeatureCount() const
Returns the number of features that are selected in this layer.
Definition: qgsvectorlayer.cpp:3351
qgsmaprendererparalleljob.h
QgsRectangle::setMinimal
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
Definition: qgsrectangle.h:151
QgsSettings::enumValue
T enumValue(const QString &key, const T &defaultValue, const Section section=NoSection)
Returns the setting value for a setting based on an enum.
Definition: qgssettings.h:252
QgsMapLayer::isSpatial
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
Definition: qgsmaplayer.cpp:1729
QgsMapCanvas::setLayers
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of layers that should be shown in the canvas.
Definition: qgsmapcanvas.cpp:329
QgsMapSettings::setOutputSize
void setOutputSize(QSize size)
Sets the size of the resulting map image.
Definition: qgsmapsettings.cpp:239
qgslogger.h
QgsMapCanvas::panActionStart
void panActionStart(QPoint releasePoint)
Starts a pan action.
Definition: qgsmapcanvas.cpp:2080
qgsmapcanvasmap.h
QgsMapCanvas::mapUnitsPerPixel
double mapUnitsPerPixel() const
Returns the mapUnitsPerPixel (map units per pixel) for the canvas.
Definition: qgsmapcanvas.cpp:1935
QgsMapSettings::setPathResolver
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
Definition: qgsmapsettings.h:430
QgsMapSettings
Definition: qgsmapsettings.h:86
QgsMapSettings::visibleExtent
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
Definition: qgsmapsettings.cpp:370
QgsMapRendererCache::invalidateCacheForLayer
void invalidateCacheForLayer(QgsMapLayer *layer)
Invalidates cached images which relate to the specified map layer.
Definition: qgsmaprenderercache.cpp:155
QgsCoordinateTransform
Definition: qgscoordinatetransform.h:52
qgsmapmouseevent.h
QgsMapCanvas::CanvasProperties::CanvasProperties
CanvasProperties()=default
Constructor for CanvasProperties.
QgsMapCanvas::annotationItems
QList< QgsMapCanvasAnnotationItem * > annotationItems() const
Returns a list of all annotation items in the canvas.
Definition: qgsmapcanvas.cpp:2442
QgsFeatureIterator
Definition: qgsfeatureiterator.h:263
QgsMapSettings::layerToMapCoordinates
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS
Definition: qgsmapsettings.cpp:481
QgsMapSettings::setExtent
void setExtent(const QgsRectangle &rect, bool magnified=true)
Set coordinates of the rectangle which should be rendered.
Definition: qgsmapsettings.cpp:79
QgsRubberBand::setSecondaryStrokeColor
void setSecondaryStrokeColor(const QColor &color)
Sets a secondary stroke color for the rubberband which will be drawn under the main stroke color.
Definition: qgsrubberband.cpp:65
QgsRectangle::isEmpty
bool isEmpty() const
Returns true if the rectangle is empty.
Definition: qgsrectangle.h:437
QgsMapTool::EditTool
@ EditTool
Map tool is an edit tool, which can only be used when layer is editable.
Definition: qgsmaptool.h:93
QgsMapSettings::mapToPixel
const QgsMapToPixel & mapToPixel() const
Definition: qgsmapsettings.h:432
QgsRectangle::isNull
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Definition: qgsrectangle.h:447
qgsproject.h
QgsRectangle::width
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
QgsRectangle::setYMinimum
void setYMinimum(double y)
Set the minimum y value.
Definition: qgsrectangle.h:140
QgsMapCanvas::setLayerStyleOverrides
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Sets the stored overrides of styles for rendering layers.
Definition: qgsmapcanvas.cpp:1950
QgsMapLayer::autoRefreshIntervalChanged
void autoRefreshIntervalChanged(int interval)
Emitted when the auto refresh interval changes.
QgsRectangle::setYMaximum
void setYMaximum(double y)
Set the maximum y value.
Definition: qgsrectangle.h:145
QgsRectangle::xMinimum
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
QgsMimeDataUtils::isUriList
static bool isUriList(const QMimeData *data)
Definition: qgsmimedatautils.cpp:190
QgsPreviewEffect::mode
PreviewMode mode() const
Returns the mode used for the preview effect.
Definition: qgsprevieweffect.h:73
QgsMapCanvas::setCachingEnabled
void setCachingEnabled(bool enabled)
Set whether to cache images of rendered layers.
Definition: qgsmapcanvas.cpp:441
QgsMapCanvas::setLabelingEngineSettings
void setLabelingEngineSettings(const QgsLabelingEngineSettings &settings)
Sets global labeling engine settings in the internal map settings.
Definition: qgsmapcanvas.cpp:2468
qgsmessagelog.h
QgsMapRendererJob::finished
void finished()
emitted when asynchronous rendering is finished (or canceled).
QgsMapCanvas::mapCanvasRefreshed
void mapCanvasRefreshed()
Emitted when canvas finished a refresh request.
QgsMapCanvas::setSelectionColor
void setSelectionColor(const QColor &color)
Set color of selected vector features.
Definition: qgsmapcanvas.cpp:1874
QgsMapCanvas::layerStateChange
void layerStateChange()
This slot is connected to the visibility change of one or more layers.
Definition: qgsmapcanvas.cpp:1919
QgsMapCanvas::stopRendering
void stopRendering()
stop rendering (if there is any right now)
Definition: qgsmapcanvas.cpp:780
QgsSvgCache::remoteSvgFetched
void remoteSvgFetched(const QString &url)
Emitted when the cache has finished retrieving an SVG file from a remote url.
QgsExpressionContextScope::removeVariable
bool removeVariable(const QString &name)
Removes a variable from the context scope, if found.
Definition: qgsexpressioncontext.cpp:98