Skip to content

Commit 5c02c8a

Browse files
authored
Merge pull request #4238 from nyalldawson/canvas_theme
Allow setting map canvases to auto follow a map theme
2 parents cd7b19c + 9842fcb commit 5c02c8a

File tree

8 files changed

+334
-274
lines changed

8 files changed

+334
-274
lines changed

python/gui/qgsmapcanvas.sip

Lines changed: 32 additions & 255 deletions
Original file line numberDiff line numberDiff line change
@@ -18,303 +18,83 @@ class QgsMapCanvas : QGraphicsView
1818
public:
1919

2020
//! Constructor
21-
QgsMapCanvas( QWidget * parent /TransferThis/ = 0 );
22-
21+
QgsMapCanvas( QWidget *parent /TransferThis/ = 0 );
2322
~QgsMapCanvas();
24-
25-
//! Returns the magnification factor
26-
//! @note added in 2.16
2723
double magnificationFactor() const;
28-
29-
//! Set list of layers that should be shown in the canvas
30-
//! @note added in 3.0
31-
void setLayers( const QList<QgsMapLayer*>& layers );
32-
33-
void setCurrentLayer( QgsMapLayer* layer );
34-
35-
//! Get access to properties used for map rendering
36-
//! @note added in 2.4
37-
const QgsMapSettings& mapSettings() const /KeepReference/;
38-
39-
//! sets destination coordinate reference system
40-
//! @note added in 2.4
41-
void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
42-
43-
//! Get access to the labeling results (may be null)
44-
//! @note added in 2.4
45-
const QgsLabelingResults* labelingResults() const;
46-
47-
//! Set whether to cache images of rendered layers
48-
//! @note added in 2.4
24+
void setLayers( const QList<QgsMapLayer *> &layers );
25+
void setCurrentLayer( QgsMapLayer *layer );
26+
const QgsMapSettings &mapSettings() const /KeepReference/;
27+
void setDestinationCrs( const QgsCoordinateReferenceSystem &crs );
28+
const QgsLabelingResults *labelingResults() const;
4929
void setCachingEnabled( bool enabled );
50-
51-
//! Check whether images of rendered layers are curerently being cached
52-
//! @note added in 2.4
5330
bool isCachingEnabled() const;
54-
55-
//! Make sure to remove any rendered images from cache (does nothing if cache is not enabled)
56-
//! @note added in 2.4
5731
void clearCache();
58-
59-
//! Reload all layers, clear the cache and refresh the canvas
60-
//! @note added in 2.9
6132
void refreshAllLayers();
62-
63-
//! Set whether the layers are rendered in parallel or sequentially
64-
//! @note added in 2.4
33+
void waitWhileRendering();
6534
void setParallelRenderingEnabled( bool enabled );
66-
67-
//! Check whether the layers are rendered in parallel or sequentially
68-
//! @note added in 2.4
6935
bool isParallelRenderingEnabled() const;
70-
71-
//! Set how often map preview should be updated while it is being rendered (in milliseconds)
72-
//! @note added in 2.4
7336
void setMapUpdateInterval( int timeMilliseconds );
74-
75-
//! Find out how often map preview should be updated while it is being rendered (in milliseconds)
76-
//! @note added in 2.4
7737
int mapUpdateInterval() const;
78-
79-
//! Get the last reported scale of the canvas
8038
double scale();
81-
82-
//! Returns the mapUnitsPerPixel (map units per pixel) for the canvas
8339
double mapUnitsPerPixel() const;
84-
85-
//! Returns the current zoom extent of the map canvas
8640
QgsRectangle extent() const;
87-
//! Returns the combined extent for all layers on the map canvas
8841
QgsRectangle fullExtent() const;
89-
90-
//! Set the extent of the map canvas
9142
void setExtent( const QgsRectangle &r, bool magnified = false );
92-
93-
//! Get the current map canvas rotation in clockwise degrees
94-
//! @note added in 2.8
9543
double rotation() const;
96-
97-
//! Set the rotation of the map canvas in clockwise degrees
98-
//! @note added in 2.8
9944
void setRotation( double degrees );
100-
101-
//! Set the center of the map canvas, in geographical coordinates
102-
//! @note added in 2.8
103-
void setCenter( const QgsPoint& center );
104-
105-
//! Get map center, in geographical coordinates
106-
//! @note added in 2.8
45+
void setCenter( const QgsPoint &center );
10746
QgsPoint center() const;
108-
109-
//! Zoom to the full extent of all layers
11047
void zoomToFullExtent();
111-
112-
//! Zoom to the previous extent (view)
11348
void zoomToPreviousExtent();
114-
115-
//! Zoom to the next extent (view)
11649
void zoomToNextExtent();
117-
118-
// ! Clears the list of extents and sets current extent as first item
11950
void clearExtentHistory();
120-
121-
/** Zoom to the extent of the selected features of current (vector) layer.
122-
* @param layer optionally specify different than current layer
123-
*/
124-
void zoomToSelected( QgsVectorLayer* layer = 0 );
125-
126-
/** Set canvas extent to the bounding box of a set of features
127-
@param layer the vector layer
128-
@param ids the feature ids*/
129-
void zoomToFeatureIds( QgsVectorLayer* layer, const QgsFeatureIds& ids );
130-
131-
/** Centers canvas extent to feature ids
132-
@param layer the vector layer
133-
@param ids the feature ids*/
134-
void panToFeatureIds( QgsVectorLayer* layer, const QgsFeatureIds& ids );
135-
136-
//! Pan to the selected features of current (vector) layer keeping same extent.
137-
void panToSelected( QgsVectorLayer* layer = 0 );
138-
139-
//! \brief Sets the map tool currently being used on the canvas
140-
void setMapTool( QgsMapTool* mapTool );
141-
142-
/** \brief Unset the current map tool or last non zoom tool
143-
*
144-
* This is called from destructor of map tools to make sure
145-
* that this map tool won't be used any more.
146-
* You don't have to call it manualy, QgsMapTool takes care of it.
147-
*/
148-
void unsetMapTool( QgsMapTool* mapTool );
149-
150-
//! Returns the currently active tool
151-
QgsMapTool* mapTool();
152-
153-
//! Write property of QColor bgColor.
154-
void setCanvasColor( const QColor & _newVal );
155-
//! Read property of QColor bgColor.
51+
void zoomToSelected( QgsVectorLayer *layer = 0 );
52+
void zoomToFeatureIds( QgsVectorLayer *layer, const QgsFeatureIds &ids );
53+
void panToFeatureIds( QgsVectorLayer *layer, const QgsFeatureIds &ids );
54+
void panToSelected( QgsVectorLayer *layer = 0 );
55+
void setMapTool( QgsMapTool *mapTool );
56+
void unsetMapTool( QgsMapTool *mapTool );
57+
QgsMapTool *mapTool();
58+
void setCanvasColor( const QColor &_newVal );
15659
QColor canvasColor() const;
157-
158-
//! Set color of selected vector features
159-
//! @note added in 2.4
160-
void setSelectionColor( const QColor& color );
161-
162-
//! Emits signal scaleChanged to update scale in main window
60+
void setSelectionColor( const QColor &color );
16361
void updateScale();
164-
165-
//! return the map layer at position index in the layer stack
16662
QgsMapLayer *layer( int index );
167-
168-
//! return number of layers on the map
16963
int layerCount() const;
170-
171-
//! return list of layers within map canvas.
172-
QList<QgsMapLayer*> layers() const;
64+
QList<QgsMapLayer *> layers() const;
17365
void freeze( bool frozen = true );
17466
bool isFrozen() const;
17567
bool renderFlag() const;
176-
177-
//! Get the current canvas map units
17868
QgsUnitTypes::DistanceUnit mapUnits() const;
179-
180-
//! Getter for stored overrides of styles for layers.
181-
//! @note added in 2.12
18269
QMap<QString, QString> layerStyleOverrides() const;
183-
184-
//! Setter for stored overrides of styles for layers.
185-
//! @note added in 2.12
186-
void setLayerStyleOverrides( const QMap<QString, QString>& overrides );
187-
188-
//! Get the current coordinate transform
189-
const QgsMapToPixel* getCoordinateTransform();
190-
191-
//! Find out whether rendering is in progress
70+
void setLayerStyleOverrides( const QMap<QString, QString> &overrides );
71+
void setTheme( const QString &theme );
72+
QString theme() const;
73+
const QgsMapToPixel *getCoordinateTransform();
19274
bool isDrawing();
193-
194-
//! returns current layer (set by legend widget)
195-
QgsMapLayer* currentLayer();
196-
197-
//! set wheel zoom factor (should be greater than 1)
75+
QgsMapLayer *currentLayer();
19876
void setWheelFactor( double factor );
199-
200-
//! Zoom to a specific scale
20177
void zoomScale( double scale );
202-
203-
//! Zoom with the factor supplied. Factor > 1 zooms out, interval (0,1) zooms in
204-
//! If point is given, re-center on it
20578
void zoomByFactor( double scaleFactor, const QgsPoint *center = 0 );
206-
207-
//! Zooms in/out with a given center
20879
void zoomWithCenter( int x, int y, bool zoomIn );
209-
210-
//! Zooms to feature extent. Adds a small margin around the extent
211-
//! and does a pan if rect is empty (point extent)
212-
void zoomToFeatureExtent( QgsRectangle& rect );
213-
214-
//! Returns whether the scale is locked, so zooming can be performed using magnication.
215-
//! @note added in 2.16
216-
//! @see setScaleLocked()
80+
void zoomToFeatureExtent( QgsRectangle &rect );
21781
bool scaleLocked() const;
218-
219-
//! used to determine if anti-aliasing is enabled or not
22082
void enableAntiAliasing( bool flag );
221-
222-
//! true if antialising is enabled
22383
bool antiAliasingEnabled() const;
224-
225-
//! sets map tile rendering flag
22684
void enableMapTileRendering( bool flag );
227-
228-
// following 2 methods should be moved elsewhere or changed to private
229-
// currently used by pan map tool
230-
//! Ends pan action and redraws the canvas.
23185
void panActionEnd( QPoint releasePoint );
232-
233-
//! Called when mouse is moving and pan is activated
234-
void panAction( QMouseEvent * event );
235-
236-
//! returns last position of mouse cursor
86+
void panAction( QMouseEvent *event );
23787
QPoint mouseLastXY();
238-
239-
/** Enables a preview mode for the map canvas
240-
* @param previewEnabled set to true to enable a preview mode
241-
* @see setPreviewMode
242-
* @note added in 2.3 */
24388
void setPreviewModeEnabled( bool previewEnabled );
244-
245-
/** Returns whether a preview mode is enabled for the map canvas
246-
* @returns true if a preview mode is currently enabled
247-
* @see setPreviewModeEnabled
248-
* @see previewMode
249-
* @note added in 2.3 */
25089
bool previewModeEnabled() const;
251-
252-
/** Sets a preview mode for the map canvas. This setting only has an effect if
253-
* previewModeEnabled is true.
254-
* @param mode preview mode for the canvas
255-
* @see previewMode
256-
* @see setPreviewModeEnabled
257-
* @see previewModeEnabled
258-
* @note added in 2.3 */
25990
void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
260-
261-
/** Returns the current preview mode for the map canvas. This setting only has an effect if
262-
* previewModeEnabled is true.
263-
* @returns preview mode for map canvas
264-
* @see setPreviewMode
265-
* @see previewModeEnabled
266-
* @note added in 2.3 */
26791
QgsPreviewEffect::PreviewMode previewMode() const;
268-
269-
/** Return snapping utility class that is associated with map canvas.
270-
* If no snapping utils instance has been associated previously, an internal will be created for convenience
271-
* (so map tools do not need to test for existence of the instance).
272-
*
273-
* Main canvas in QGIS returns an instance which is always up-to-date with the project's snapping configuration.
274-
* @note added in 2.8
275-
*/
276-
QgsSnappingUtils* snappingUtils() const;
277-
278-
/** Assign an instance of snapping utils to the map canvas.
279-
* The instance is not owned by the canvas, so it is possible to use one instance in multiple canvases.
280-
*
281-
* For main canvas in QGIS, do not associate a different instance from the existing one (it is updated from
282-
* the project's snapping configuration).
283-
* @note added in 2.8
284-
*/
285-
void setSnappingUtils( QgsSnappingUtils* utils );
286-
287-
/** Sets an expression context scope for the map canvas. This scope is injected into the expression
288-
* context used for rendering the map, and can be used to apply specific variable overrides for
289-
* expression evaluation for the map canvas render. This method will overwrite the existing expression
290-
* context scope for the canvas.
291-
* @param scope new expression context scope
292-
* @note added in QGIS 2.12
293-
* @see expressionContextScope()
294-
*/
295-
void setExpressionContextScope( const QgsExpressionContextScope& scope );
296-
297-
/** Returns a reference to the expression context scope for the map canvas. This scope is injected
298-
* into the expression context used for rendering the map, and can be used to apply specific variable
299-
* overrides for expression evaluation for the map canvas render.
300-
* @note added in QGIS 2.12
301-
* @see setExpressionContextScope()
302-
*/
303-
QgsExpressionContextScope& expressionContextScope();
304-
305-
/** Returns a const reference to the expression context scope for the map canvas.
306-
* @note added in QGIS 2.12
307-
* @see setExpressionContextScope()
308-
* @note not available in python bindings
309-
*/
310-
// const QgsExpressionContextScope& expressionContextScope() const;
311-
312-
/** Sets the segmentation tolerance applied when rendering curved geometries
313-
@param tolerance the segmentation tolerance*/
92+
QgsSnappingUtils *snappingUtils() const;
93+
void setSnappingUtils( QgsSnappingUtils *utils );
94+
void setExpressionContextScope( const QgsExpressionContextScope &scope );
95+
QgsExpressionContextScope &expressionContextScope();
96+
// const QgsExpressionContextScope &expressionContextScope() const;
31497
void setSegmentationTolerance( double tolerance );
315-
316-
/** Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)
317-
@param type the segmentation tolerance typename*/
31898
void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type );
31999

320100
public slots:
@@ -434,12 +214,9 @@ class QgsMapCanvas : QGraphicsView
434214
//! @note added in 2.8
435215
void currentLayerChanged( QgsMapLayer* layer );
436216

437-
//! Emitted when the configuration of overridden layer styles changes
438-
//! @note added in 2.12
439217
void layerStyleOverridesChanged();
440-
441-
//! emit a message (usually to be displayed in a message bar)
442-
void messageEmitted( const QString& title, const QString& message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );
218+
void themeChanged( const QString &theme );
219+
void messageEmitted( const QString &title, const QString &message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );
443220

444221
protected:
445222

0 commit comments

Comments
 (0)