/
qgsmapcanvas.h
1049 lines (828 loc) · 32.5 KB
/
qgsmapcanvas.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
qgsmapcanvas.h - description
-------------------
begin : Sun Jun 30 2002
copyright : (C) 2002 by Gary E.Sherman
email : sherman at mrcc.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSMAPCANVAS_H
#define QGSMAPCANVAS_H
#include "qgsconfig.h"
#include "qgis_sip.h"
#include "qgsexpressioncontext.h"
#include "qgsfeature.h"
#include "qgsmessagebar.h"
#include "qgsrectangle.h"
#include "qgis.h"
#include <QDomDocument>
#include <QGraphicsView>
#include <QtCore>
#include "qgsmapsettings.h" // TEMPORARY
#include "qgsprevieweffect.h" //for QgsPreviewEffect::PreviewMode
#include <QGestureEvent>
#include "qgis_gui.h"
class QWheelEvent;
class QPixmap;
class QPaintEvent;
class QKeyEvent;
class ResizeEvent;
class QColor;
class QDomDocument;
class QPaintDevice;
class QMouseEvent;
class QRubberBand;
class QGraphicsScene;
class QgsMapToPixel;
class QgsMapLayer;
class QgsHighlight;
class QgsVectorLayer;
class QgsLabelingResults;
class QgsMapRendererCache;
class QgsMapRendererQImageJob;
class QgsMapSettings;
class QgsMapCanvasMap;
class QgsMapOverviewCanvas;
class QgsMapTool;
class QgsSnappingUtils;
class QgsRubberBand;
class QgsMapCanvasAnnotationItem;
/**
* \ingroup gui
* Map canvas is a class for displaying all GIS data types on a canvas.
*/
class GUI_EXPORT QgsMapCanvas : public QGraphicsView
{
#ifdef SIP_RUN
SIP_CONVERT_TO_SUBCLASS_CODE
if ( dynamic_cast<QgsMapCanvas *>( sipCpp ) != NULL )
sipType = sipType_QgsMapCanvas;
else
sipType = NULL;
SIP_END
#endif
Q_OBJECT
Q_PROPERTY( QString theme READ theme WRITE setTheme NOTIFY themeChanged )
Q_PROPERTY( bool previewJobsEnabled READ previewJobsEnabled WRITE setPreviewJobsEnabled )
public:
//! Constructor
QgsMapCanvas( QWidget *parent SIP_TRANSFERTHIS = nullptr );
~QgsMapCanvas() override;
/**
* Returns the magnification factor
* \since QGIS 2.16
*/
double magnificationFactor() const;
/**
* Sets the list of \a layers that should be shown in the canvas.
*
* If the map canvas has been associated with a map theme via a call
* to setTheme(), then any calls to setLayers() are ignored. It is necessary
* to first clear the theme association by calling setTheme() with an
* empty string before setLayers() calls can be made.
*
* \since QGIS 3.0
* \see layers()
*/
void setLayers( const QList<QgsMapLayer *> &layers );
void setCurrentLayer( QgsMapLayer *layer );
/**
* Get access to properties used for map rendering
* \since QGIS 2.4
*/
const QgsMapSettings &mapSettings() const SIP_KEEPREFERENCE;
/**
* sets destination coordinate reference system
* \since QGIS 2.4
*/
void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
/**
* Resets the \a flags for the canvas' map settings.
* \since QGIS 3.0
*/
void setMapSettingsFlags( QgsMapSettings::Flags flags );
/**
* Get access to the labeling results (may be null)
* \since QGIS 2.4
*/
const QgsLabelingResults *labelingResults() const;
/**
* Set whether to cache images of rendered layers
* \since QGIS 2.4
*/
void setCachingEnabled( bool enabled );
/**
* Check whether images of rendered layers are curerently being cached
* \since QGIS 2.4
*/
bool isCachingEnabled() const;
/**
* Make sure to remove any rendered images from cache (does nothing if cache is not enabled)
* \since QGIS 2.4
*/
void clearCache();
/**
* Blocks until the rendering job has finished.
*
* In almost all cases you do NOT want to call this, as it will hang the UI
* until the rendering job is complete. It's included in API solely for
* unit testing and standalone Python scripts.
*
* \since QGIS 3.0
*/
void waitWhileRendering();
/**
* Set whether the layers are rendered in parallel or sequentially
* \since QGIS 2.4
*/
void setParallelRenderingEnabled( bool enabled );
/**
* Check whether the layers are rendered in parallel or sequentially
* \since QGIS 2.4
*/
bool isParallelRenderingEnabled() const;
/**
* Set how often map preview should be updated while it is being rendered (in milliseconds)
* \since QGIS 2.4
*/
void setMapUpdateInterval( int timeMilliseconds );
/**
* Find out how often map preview should be updated while it is being rendered (in milliseconds)
* \since QGIS 2.4
*/
int mapUpdateInterval() const;
/**
* Returns the last reported scale of the canvas.
* The \a scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
*/
double scale() const;
//! Returns the mapUnitsPerPixel (map units per pixel) for the canvas
double mapUnitsPerPixel() const;
//! Returns the current zoom extent of the map canvas
QgsRectangle extent() const;
//! Returns the combined extent for all layers on the map canvas
QgsRectangle fullExtent() const;
//! Set the extent of the map canvas
void setExtent( const QgsRectangle &r, bool magnified = false );
/**
* Get the current map canvas rotation in clockwise degrees
* \since QGIS 2.8
*/
double rotation() const;
/**
* Set the rotation of the map canvas in clockwise degrees
* \since QGIS 2.8
*/
void setRotation( double degrees );
/**
* Set the center of the map canvas, in geographical coordinates
* \since QGIS 2.8
*/
void setCenter( const QgsPointXY ¢er );
/**
* Get map center, in geographical coordinates
* \since QGIS 2.8
*/
QgsPointXY center() const;
//! Zoom to the full extent of all layers
void zoomToFullExtent();
//! Zoom to the previous extent (view)
void zoomToPreviousExtent();
//! Zoom to the next extent (view)
void zoomToNextExtent();
// ! Clears the list of extents and sets current extent as first item
void clearExtentHistory();
/**
* Set canvas extent to the bounding box of a set of features
\param layer the vector layer
\param ids the feature ids*/
void zoomToFeatureIds( QgsVectorLayer *layer, const QgsFeatureIds &ids );
/**
* Centers canvas extent to feature ids
\param layer the vector layer
\param ids the feature ids*/
void panToFeatureIds( QgsVectorLayer *layer, const QgsFeatureIds &ids );
//! Pan to the selected features of current (vector) layer keeping same extent.
void panToSelected( QgsVectorLayer *layer = nullptr );
/**
* Causes a set of features with matching \a ids from a vector \a layer to flash
* within the canvas.
*
* The \a startColor and \a endColor can be specified, along with the number of
* \a flashes and \a duration of each flash (in milliseconds).
*
* \note If the features or geometries are already available, flashGeometries() is much more efficient.
*
* \since QGIS 3.0
* \see flashGeometries()
*/
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 \a geometries to flash within the canvas.
*
* If \a crs is a valid coordinate reference system, the geometries will be automatically
* transformed from this CRS to the canvas CRS.
*
* The \a startColor and \a endColor can be specified, along with the number of
* \a flashes and \a duration of each flash (in milliseconds).
*
* \since QGIS 3.0
* \see flashFeatureIds()
*/
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 );
//! \brief Sets the map tool currently being used on the canvas
void setMapTool( QgsMapTool *mapTool, bool clean = false );
/**
* \brief Unset the current map tool or last non zoom tool
*
* This is called from destructor of map tools to make sure
* that this map tool won't be used any more.
* You don't have to call it manually, QgsMapTool takes care of it.
*/
void unsetMapTool( QgsMapTool *mapTool );
//! Returns the currently active tool
QgsMapTool *mapTool();
//! Write property of QColor bgColor.
void setCanvasColor( const QColor &_newVal );
//! Read property of QColor bgColor.
QColor canvasColor() const;
/**
* Set color of selected vector features
* \since QGIS 2.4
*/
void setSelectionColor( const QColor &color );
/**
* Returns color for selected features
* \since QGIS 3.0
*/
QColor selectionColor() const;
//! Emits signal scaleChanged to update scale in main window
void updateScale();
//! return the map layer at position index in the layer stack
QgsMapLayer *layer( int index );
//! return number of layers on the map
int layerCount() const;
/**
* Return the list of layers shown within the map canvas.
* \see setLayers()
*/
QList<QgsMapLayer *> layers() const;
/**
* Freeze/thaw the map canvas. This is used to prevent the canvas from
* responding to events while layers are being added/removed etc.
* \param frozen Boolean specifying if the canvas should be frozen (true) or
* thawed (false). Default is true.
* \see isFrozen()
* \see setRenderFlag(). freeze() should be used to programmatically halt map updates,
* while setRenderFlag() should only be used when users disable rendering via GUI.
*/
void freeze( bool frozen = true );
/**
* Returns true if canvas is frozen.
* \see renderFlag(). isFrozen() should be used to determine whether map updates
* have been halted programmatically, while renderFlag() should be used to
* determine whether a user has disabled rendering via GUI.
* \see freeze()
*/
bool isFrozen() const;
/**
* Returns true if canvas render is disabled as a result of user disabling
* renders via the GUI.
* \see setRenderFlag()
* \see isFrozen(). isFrozen() should be used to determine whether map updates
* have been halted programmatically, while renderFlag() should be used to
* determine whether a user has disabled rendering via GUI.
*/
bool renderFlag() const { return mRenderFlag; }
/**
* Convenience function for returning the current canvas map units. The map units
* are dictated by the canvas' destinationCrs() map units.
*/
QgsUnitTypes::DistanceUnit mapUnits() const;
/**
* Returns the stored overrides of styles for layers.
* \since QGIS 2.12
* \see setLayerStyleOverrides().
*/
QMap<QString, QString> layerStyleOverrides() const;
/**
* Sets the stored overrides of styles for rendering layers.
*
* If the map canvas has been associated with a map theme via a call
* to setTheme(), then any calls to setLayerStyleOverrides() are ignored. It is necessary
* to first clear the theme association by calling setTheme() with an
* empty string before setLayerStyleOverrides() calls can be made.
*
* \since QGIS 2.12
* \see layerStyleOverrides()
*/
void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
/**
* Sets a map \a theme to show in the canvas. The theme name must match
* a theme present in the associated project's QgsMapThemeCollection.
*
* When the canvas is associated to a map theme, it will automatically follow
* the layer selection and layer styles from that theme. Calls to setLayers()
* or setLayerStyleOverrides() will have no effect, and canvases associated
* with a QgsLayerTreeMapCanvasBridge will no longer synchronize their
* state with the layer tree. In these cases it is necessary to call
* setTheme() with an empty string to clear the theme association and
* allow map updates with setLayers(), setLayerStyleOverrides(), or via
* QgsLayerTreeMapCanvasBridge.
*
* If an empty string is passed then the current theme association will be
* cleared.
* \since QGIS 3.0
* \see theme()
*/
void setTheme( const QString &theme );
/**
* Returns the map's theme shown in the canvas, if set.
* \since QGIS 3.0
* \see setTheme()
*/
QString theme() const { return mTheme; }
//! Get the current coordinate transform
const QgsMapToPixel *getCoordinateTransform();
//! Find out whether rendering is in progress
bool isDrawing();
//! returns current layer (set by legend widget)
QgsMapLayer *currentLayer();
//! set wheel zoom factor (should be greater than 1)
void setWheelFactor( double factor );
/**
* Zooms the canvas to a specific \a scale.
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
*/
void zoomScale( double scale );
/**
* Zoom with the factor supplied. Factor > 1 zooms out, interval (0,1) zooms in
* If point is given, re-center on it
*/
void zoomByFactor( double scaleFactor, const QgsPointXY *center = nullptr );
//! Zooms in/out with a given center
void zoomWithCenter( int x, int y, bool zoomIn );
/**
* Zooms to feature extent. Adds a small margin around the extent
* and does a pan if rect is empty (point extent)
*/
void zoomToFeatureExtent( QgsRectangle &rect );
/**
* Returns whether the scale is locked, so zooming can be performed using magnication.
* \since QGIS 2.16
* \see setScaleLocked()
*/
bool scaleLocked() const { return mScaleLocked;}
//! used to determine if anti-aliasing is enabled or not
void enableAntiAliasing( bool flag );
//! true if antialising is enabled
bool antiAliasingEnabled() const { return mSettings.testFlag( QgsMapSettings::Antialiasing ); }
//! sets map tile rendering flag
void enableMapTileRendering( bool flag );
// following 2 methods should be moved elsewhere or changed to private
// currently used by pan map tool
//! Ends pan action and redraws the canvas.
void panActionEnd( QPoint releasePoint );
//! Called when mouse is moving and pan is activated
void panAction( QMouseEvent *event );
//! returns last position of mouse cursor
QPoint mouseLastXY();
/**
* Enables a preview mode for the map canvas
* \param previewEnabled set to true to enable a preview mode
* \see setPreviewMode
* \since QGIS 2.3 */
void setPreviewModeEnabled( bool previewEnabled );
/**
* Returns whether a preview mode is enabled for the map canvas
* \returns true if a preview mode is currently enabled
* \see setPreviewModeEnabled
* \see previewMode
* \since QGIS 2.3 */
bool previewModeEnabled() const;
/**
* Sets a preview mode for the map canvas. This setting only has an effect if
* previewModeEnabled is true.
* \param mode preview mode for the canvas
* \see previewMode
* \see setPreviewModeEnabled
* \see previewModeEnabled
* \since QGIS 2.3 */
void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
/**
* Returns the current preview mode for the map canvas. This setting only has an effect if
* previewModeEnabled is true.
* \returns preview mode for map canvas
* \see setPreviewMode
* \see previewModeEnabled
* \since QGIS 2.3 */
QgsPreviewEffect::PreviewMode previewMode() const;
/**
* Return snapping utility class that is associated with map canvas.
* If no snapping utils instance has been associated previously, an internal will be created for convenience
* (so map tools do not need to test for existence of the instance).
*
* Main canvas in QGIS returns an instance which is always up-to-date with the project's snapping configuration.
* \since QGIS 2.8
*/
QgsSnappingUtils *snappingUtils() const;
/**
* Assign an instance of snapping utils to the map canvas.
* The instance is not owned by the canvas, so it is possible to use one instance in multiple canvases.
*
* For main canvas in QGIS, do not associate a different instance from the existing one (it is updated from
* the project's snapping configuration).
* \since QGIS 2.8
*/
void setSnappingUtils( QgsSnappingUtils *utils );
/**
* Sets an expression context scope for the map canvas. This scope is injected into the expression
* context used for rendering the map, and can be used to apply specific variable overrides for
* expression evaluation for the map canvas render. This method will overwrite the existing expression
* context scope for the canvas.
* \param scope new expression context scope
* \since QGIS 2.12
* \see expressionContextScope()
*/
void setExpressionContextScope( const QgsExpressionContextScope &scope ) { mExpressionContextScope = scope; }
/**
* Returns a reference to the expression context scope for the map canvas. This scope is injected
* into the expression context used for rendering the map, and can be used to apply specific variable
* overrides for expression evaluation for the map canvas render.
* \since QGIS 2.12
* \see setExpressionContextScope()
*/
QgsExpressionContextScope &expressionContextScope() { return mExpressionContextScope; }
/**
* Returns a const reference to the expression context scope for the map canvas.
* \since QGIS 2.12
* \see setExpressionContextScope()
* \note not available in Python bindings
*/
const QgsExpressionContextScope &expressionContextScope() const { return mExpressionContextScope; } SIP_SKIP
/**
* Sets the segmentation tolerance applied when rendering curved geometries
\param tolerance the segmentation tolerance*/
void setSegmentationTolerance( double tolerance );
/**
* Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)
\param type the segmentation tolerance typename*/
void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type );
/**
* Returns a list of all annotation items in the canvas.
* \since QGIS 3.0
*/
QList< QgsMapCanvasAnnotationItem *> annotationItems() const;
/**
* Returns true if annotations are visible within the map canvas.
* \since QGIS 3.0
* \see setAnnotationsVisible()
*/
bool annotationsVisible() const { return mAnnotationsVisible; }
/**
* Sets whether annotations are \a visible in the canvas.
* \since QGIS 3.0
* \see annotationsVisible()
*/
void setAnnotationsVisible( bool visible );
/**
* Sets global labeling engine settings in the internal map settings
* \since QGIS 3.0
*/
void setLabelingEngineSettings( const QgsLabelingEngineSettings &settings );
/**
* Returns global labeling engine settings from the internal map settings
* \since QGIS 3.0
*/
const QgsLabelingEngineSettings &labelingEngineSettings() const;
/**
* Returns true if canvas map preview jobs (low priority render jobs which render portions
* of the view just outside of the canvas extent, to allow preview of these
* out-of-canvas areas when panning or zooming out the map) are enabled
* for the canvas.
* \see setPreviewJobsEnabled()
* \since QGIS 3.0
*/
bool previewJobsEnabled() const;
/**
* Sets whether canvas map preview jobs (low priority render jobs which render portions
* of the view just outside of the canvas extent, to allow preview of these
* out-of-canvas areas when panning or zooming out the map) are \a enabled
* for the canvas.
* \see previewJobsEnabled()
* \since QGIS 3.0
*/
void setPreviewJobsEnabled( bool enabled );
public slots:
//! Repaints the canvas map
void refresh();
/**
* Reload all layers, clear the cache and refresh the canvas
* \since QGIS 2.9
*/
void refreshAllLayers();
//! Receives signal about selection change, and pass it on with layer info
void selectionChangedSlot();
//! Save the convtents of the map canvas to disk as an image
void saveAsImage( const QString &fileName, QPixmap *QPixmap = nullptr, const QString & = "PNG" );
//! This slot is connected to the visibility change of one or more layers
void layerStateChange();
/**
* Sets whether a user has disabled canvas renders via the GUI.
* \param flag set to false to indicate that user has disabled renders
* \see renderFlag()
* \see freeze(). freeze() should be used to programmatically halt map updates,
* while setRenderFlag() should only be used when users disable rendering via GUI.
*/
void setRenderFlag( bool flag );
/**
* stop rendering (if there is any right now)
* \since QGIS 2.4
*/
void stopRendering();
//! called to read map canvas settings from project
void readProject( const QDomDocument & );
//! called to write map canvas settings to project
void writeProject( QDomDocument & );
#if 0
//! ask user about datum transformation
void getDatumTransformInfo( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination );
#endif
/**
* Sets the factor of magnification to apply to the map canvas. Indeed, we
* increase/decrease the DPI of the map settings according to this factor
* in order to render marker point, labels, ... bigger.
* \since QGIS 2.16
*/
void setMagnificationFactor( double factor );
/**
* Lock the scale, so zooming can be performed using magnication
* \since QGIS 2.16
* \see scaleLocked()
*/
void setScaleLocked( bool isLocked );
//! Zoom in with fixed factor
void zoomIn();
//! Zoom out with fixed factor
void zoomOut();
/**
* Zoom to the extent of the selected features of provided (vector) layer.
* \param layer optionally specify different than current layer
*/
void zoomToSelected( QgsVectorLayer *layer = nullptr );
private slots:
//! called when current maptool is destroyed
void mapToolDestroyed();
//! called when a renderer job has finished successfully or when it was canceled
void rendererJobFinished();
//! called when a preview job has been finished
void previewJobFinished();
void mapUpdateTimeout();
void refreshMap();
void mapThemeChanged( const QString &theme );
signals:
/**
* Emits current mouse position
\note changed in 1.3 */
void xyCoordinates( const QgsPointXY &p );
//! Emitted when the scale of the map changes
void scaleChanged( double );
//! Emitted when the extents of the map change
void extentsChanged();
/**
* Emitted when the rotation of the map changes
* \since QGIS 2.8
*/
void rotationChanged( double );
/**
* Emitted when the scale of the map changes
* \since QGIS 2.16
*/
void magnificationChanged( double );
/**
* Emitted when canvas background color changes
* \since QGIS 3.0
*/
void canvasColorChanged();
/**
* Emitted when the canvas has rendered.
* Passes a pointer to the painter on which the map was drawn. This is
* useful for plugins that wish to draw on the map after it has been
* rendered. Passing the painter allows plugins to work when the map is
* being rendered onto a pixmap other than the mapCanvas own pixmap member.
*
*/
/**
* TODO: deprecate when decorations are reimplemented as map canvas items
* - anything related to rendering progress is not visible outside of map canvas
* - additional drawing shall be done directly within the renderer job or independently as a map canvas item
*/
void renderComplete( QPainter * );
// ### QGIS 3: renamte to mapRefreshFinished()
//! Emitted when canvas finished a refresh request.
void mapCanvasRefreshed();
// ### QGIS 3: rename to mapRefreshStarted()
//! Emitted when the canvas is about to be rendered.
void renderStarting();
//! Emitted when a new set of layers has been received
void layersChanged();
//! Emit key press event
void keyPressed( QKeyEvent *e );
//! Emit key release event
void keyReleased( QKeyEvent *e );
/**
* Emit map tool changed with the old tool
* \since QGIS 2.3
*/
void mapToolSet( QgsMapTool *newTool, QgsMapTool *oldTool );
//! Emitted when selection in any layer gets changed
void selectionChanged( QgsVectorLayer *layer );
//! Emitted when zoom last status changed
void zoomLastStatusChanged( bool );
//! Emitted when zoom next status changed
void zoomNextStatusChanged( bool );
/**
* Emitted when map CRS has changed
* \since QGIS 2.4
*/
void destinationCrsChanged();
/**
* Emitted when the canvas transform context is changed.
* \since QGIS 3.0
*/
void transformContextChanged();
/**
* Emitted when the current layer is changed
* \since QGIS 2.8
*/
void currentLayerChanged( QgsMapLayer *layer );
/**
* Emitted when the configuration of overridden layer styles changes
* \since QGIS 2.12
*/
void layerStyleOverridesChanged();
/**
* Emitted when the canvas has been assigned a different map theme.
* \see setTheme()
* \since QGIS 3.0
*/
void themeChanged( const QString &theme );
//! emit a message (usually to be displayed in a message bar)
void messageEmitted( const QString &title, const QString &message, Qgis::MessageLevel = Qgis::Info );
protected:
//! Overridden standard event to be gestures aware
bool event( QEvent *e ) override;
//! Overridden key press event
void keyPressEvent( QKeyEvent *e ) override;
//! Overridden key release event
void keyReleaseEvent( QKeyEvent *e ) override;
//! Overridden mouse double-click event
void mouseDoubleClickEvent( QMouseEvent *e ) override;
//! Overridden mouse move event
void mouseMoveEvent( QMouseEvent *e ) override;
//! Overridden mouse press event
void mousePressEvent( QMouseEvent *e ) override;
//! Overridden mouse release event
void mouseReleaseEvent( QMouseEvent *e ) override;
//! Overridden mouse wheel event
void wheelEvent( QWheelEvent *e ) override;
//! Overridden resize event
void resizeEvent( QResizeEvent *e ) override;
//! Overridden paint event
void paintEvent( QPaintEvent *e ) override;
//! Overridden drag enter event
void dragEnterEvent( QDragEnterEvent *e ) override;
//! called when panning is in action, reset indicates end of panning
void moveCanvasContents( bool reset = false );
/// implementation struct
class CanvasProperties;
/// Handle pattern for implementation object
std::unique_ptr<CanvasProperties> mCanvasProperties;
#if 0
/**
* Debugging member
* invoked when a connect() is made to this object
*/
void connectNotify( const char *signal ) override;
#endif
protected slots:
//! called on resize or changed extent to notify canvas items to change their rectangle
void updateCanvasItemPositions();
private slots:
void layerRepaintRequested( bool deferred );
void autoRefreshTriggered();
void updateAutoRefreshTimer();
void projectThemesChanged();
void startPreviewJob( int number );
private:
/// this class is non-copyable
/**
\note
Otherwise QScopedPointer would pass the object responsibility on to the
copy like a hot potato leaving the copyer in a weird state.
*/
QgsMapCanvas( QgsMapCanvas const & );
//! encompases all map settings necessary for map rendering
QgsMapSettings mSettings;
//! owns pixmap with rendered map and controls rendering
QgsMapCanvasMap *mMap = nullptr;
//! Flag indicating if the map canvas is frozen.
bool mFrozen = false;
//! Flag that allows squashing multiple refresh() calls into just one delayed rendering job
bool mRefreshScheduled = false;
//! determines whether user has requested to suppress rendering
bool mRenderFlag = true;
//! current layer in legend
QgsMapLayer *mCurrentLayer = nullptr;
//! graphics scene manages canvas items
QGraphicsScene *mScene = nullptr;
//! pointer to current map tool
QgsMapTool *mMapTool = nullptr;
//! previous tool if current is for zooming/panning
QgsMapTool *mLastNonZoomMapTool = nullptr;
//! recently used extent
QList <QgsRectangle> mLastExtent;
int mLastExtentIndex = -1;
//! Scale factor multiple for default zoom in/out
double mWheelZoomFactor = 2.0;
//! Timer that periodically fires while map rendering is in progress to update the visible map
QTimer mMapUpdateTimer;
//! Job that takes care of map rendering in background
QgsMapRendererQImageJob *mJob = nullptr;
//! Flag determining whether the active job has been canceled
bool mJobCanceled = false;
//! Labeling results from the recently rendered map
QgsLabelingResults *mLabelingResults = nullptr;
//! Whether layers are rendered sequentially or in parallel
bool mUseParallelRendering = false;
//! Whether to add rendering stats to the rendered image
bool mDrawRenderingStats = false;
//! Optionally use cache with rendered map layers for the current map settings
QgsMapRendererCache *mCache = nullptr;
QTimer *mResizeTimer = nullptr;
QTimer *mRefreshTimer = nullptr;
QgsPreviewEffect *mPreviewEffect = nullptr;
QgsRectangle imageRect( const QImage &img, const QgsMapSettings &mapSettings );
QgsSnappingUtils *mSnappingUtils = nullptr;
QList< QgsMapRendererQImageJob * > mPreviewJobs;
//! lock the scale, so zooming can be performed using magnication
bool mScaleLocked = false;
QgsExpressionContextScope mExpressionContextScope;
//! Stores zoom rect
QRect mZoomRect;
//! Flag to indicate a zoom by rectangle operation is taking place
bool mZoomDragging = false;
//! Zoom by rectangle rubber band
std::unique_ptr< QgsRubberBand > mZoomRubberBand;
QCursor mZoomCursor;
QTimer mAutoRefreshTimer;
QTimer mPreviewTimer;
QMetaObject::Connection mPreviewTimerConnection;
QString mTheme;