QGIS API Documentation  2.99.0-Master (a18066b)
qgslayertreemapcanvasbridge.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayertreemapcanvasbridge.h
3  --------------------------------------
4  Date : May 2014
5  Copyright : (C) 2014 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSLAYERTREEMAPCANVASBRIDGE_H
17 #define QGSLAYERTREEMAPCANVASBRIDGE_H
18 
19 #include <QObject>
20 #include <QStringList>
21 
23 #include "qgis_gui.h"
24 
25 class QgsMapCanvas;
26 class QgsMapLayer;
28 class QgsLayerTreeGroup;
29 class QgsLayerTreeNode;
30 
47 class GUI_EXPORT QgsLayerTreeMapCanvasBridge : public QObject
48 {
49  Q_OBJECT
50  public:
52  QgsLayerTreeMapCanvasBridge( QgsLayerTreeGroup* root, QgsMapCanvas* canvas, QObject* parent = nullptr );
53 
54  void clear();
55 
56  QgsLayerTreeGroup* rootGroup() const { return mRoot; }
57  QgsMapCanvas* mapCanvas() const { return mCanvas; }
58 
61  void setOvervewCanvas( QgsMapOverviewCanvas* overviewCanvas ) { mOverviewCanvas = overviewCanvas; }
64  QgsMapOverviewCanvas* overviewCanvas() const { return mOverviewCanvas; }
65 
66  bool hasCustomLayerOrder() const { return mHasCustomLayerOrder; }
67  QStringList customLayerOrder() const { return mCustomLayerOrder; }
68 
69  QStringList defaultLayerOrder() const;
70 
73  void setAutoSetupOnFirstLayer( bool enabled ) { mAutoSetupOnFirstLayer = enabled; }
74  bool autoSetupOnFirstLayer() const { return mAutoSetupOnFirstLayer; }
75 
78  void setAutoEnableCrsTransform( bool enabled ) { mAutoEnableCrsTransform = enabled; }
79  bool autoEnableCrsTransform() const { return mAutoEnableCrsTransform; }
80 
81  public slots:
82  void setHasCustomLayerOrder( bool state );
83  void setCustomLayerOrder( const QStringList& order );
84 
86  void setCanvasLayers();
87 
88  void readProject( const QDomDocument& doc );
89  void writeProject( QDomDocument& doc );
90 
91  signals:
92  void hasCustomLayerOrderChanged( bool );
93  void customLayerOrderChanged( const QStringList& order );
94 
100  void canvasLayersChanged( const QList< QgsMapLayer* >& layers );
101 
102  protected:
103 
104  void defaultLayerOrder( QgsLayerTreeNode* node, QStringList& order ) const;
105 
107  void setCanvasLayers( QgsLayerTreeNode* node, QList<QgsMapLayer*> &canvasLayers, QList<QgsMapLayer*>& overviewLayers );
108 
109  void deferredSetCanvasLayers();
110 
111  protected slots:
112  void nodeAddedChildren( QgsLayerTreeNode* node, int indexFrom, int indexTo );
113  void nodeRemovedChildren();
114  void nodeVisibilityChanged();
115  void nodeCustomPropertyChanged( QgsLayerTreeNode* node, const QString& key );
116 
117  protected:
118  QgsLayerTreeGroup* mRoot = nullptr;
119  QgsMapCanvas* mCanvas = nullptr;
120  QgsMapOverviewCanvas* mOverviewCanvas = nullptr;
121 
123 
125  QStringList mCustomLayerOrder;
126 
129 
133 };
134 
135 #endif // QGSLAYERTREEMAPCANVASBRIDGE_H
Layer tree group node serves as a container for layers and further groups.
Base class for all map layer types.
Definition: qgsmaplayer.h:52
A widget that displays an overview map.
The QgsLayerTreeMapCanvasBridge class takes care of updates of layer set for QgsMapCanvas from a laye...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:72
void setAutoEnableCrsTransform(bool enabled)
if enabled, will automatically turn on on-the-fly reprojection of layers if a layer with different so...
This class is a base class for nodes in a layer tree.
void setAutoSetupOnFirstLayer(bool enabled)
if enabled, will automatically set full canvas extent and destination CRS + map units when first laye...
QgsLayerTreeGroup * rootGroup() const
This class represents a coordinate reference system (CRS).
void setOvervewCanvas(QgsMapOverviewCanvas *overviewCanvas)
Associates overview canvas with the bridge, so the overview will be updated whenever main canvas is u...
QgsCoordinateReferenceSystem mFirstCRS
QgsMapOverviewCanvas * overviewCanvas() const
Returns associated overview canvas (may be null)