1 /***************************************************************************
2   qgslayertreeviewdefaultactions.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 QGSLAYERTREEVIEWDEFAULTACTIONS_H
17 #define QGSLAYERTREEVIEWDEFAULTACTIONS_H
18 
19 #include <QObject>
20 #include "qgis.h"
21 #include "qgis_gui.h"
22 
23 class QAction;
24 
25 class QgsLayerTreeGroup;
26 class QgsLayerTreeView;
27 class QgsMapCanvas;
28 class QgsMapLayer;
29 
30 
31 /**
32  * \ingroup gui
33  * \brief The QgsLayerTreeViewDefaultActions class serves as a factory of actions
34  * that can be used together with a layer tree view.
35  *
36  * \see QgsLayerTreeView
37  * \since QGIS 2.4
38  */
39 class GUI_EXPORT QgsLayerTreeViewDefaultActions : public QObject
40 {
41     Q_OBJECT
42   public:
43     QgsLayerTreeViewDefaultActions( QgsLayerTreeView *view );
44 
45     QAction *actionAddGroup( QObject *parent = nullptr ) SIP_FACTORY;
46     QAction *actionRemoveGroupOrLayer( QObject *parent = nullptr ) SIP_FACTORY;
47     QAction *actionShowInOverview( QObject *parent = nullptr ) SIP_FACTORY;
48     QAction *actionRenameGroupOrLayer( QObject *parent = nullptr ) SIP_FACTORY;
49     QAction *actionShowFeatureCount( QObject *parent = nullptr ) SIP_FACTORY;
50 
51     //! Action to check a group and all its children
52     QAction *actionCheckAndAllChildren( QObject *parent = nullptr );
53 
54     //! Action to uncheck a group and all its children
55     QAction *actionUncheckAndAllChildren( QObject *parent = nullptr );
56 
57     //! Action to check a group and all its parents
58     QAction *actionCheckAndAllParents( QObject *parent = nullptr );
59 
60     /**
61      * Action to zoom to the active layer from the layer tree.
62      * \deprecated since QGIS 3.18, use actionZoomToLayers()
63      */
64     Q_DECL_DEPRECATED QAction *actionZoomToLayer( QgsMapCanvas *canvas, QObject *parent = nullptr ) SIP_FACTORY SIP_DEPRECATED;
65 
66     /**
67      * Action to zoom to all the selected layer(s) in the layer tree
68      * \since QGIS 3.18
69      */
70     QAction *actionZoomToLayers( QgsMapCanvas *canvas, QObject *parent = nullptr ) SIP_FACTORY;
71 
72     /**
73      * Action to zoom to selected features of a vector layer
74      * \since QGIS 3.2
75      */
76     QAction *actionZoomToSelection( QgsMapCanvas *canvas, QObject *parent = nullptr ) SIP_FACTORY;
77     QAction *actionZoomToGroup( QgsMapCanvas *canvas, QObject *parent = nullptr ) SIP_FACTORY;
78 
79     /**
80      * \deprecated since QGIS 3.2, use actionMoveOutOfGroup()
81      */
82     Q_DECL_DEPRECATED QAction *actionMakeTopLevel( QObject *parent = nullptr ) SIP_FACTORY;
83 
84     /**
85      * \see moveOutOfGroup()
86      * \since QGIS 3.2
87      */
88     QAction *actionMoveOutOfGroup( QObject *parent = nullptr ) SIP_FACTORY;
89 
90     /**
91      * \see moveToTop()
92      * \since QGIS 3.2
93      */
94     QAction *actionMoveToTop( QObject *parent = nullptr ) SIP_FACTORY;
95 
96     /**
97      * \see moveToBottom()
98      * \since QGIS 3.14
99      */
100     QAction *actionMoveToBottom( QObject *parent = nullptr ) SIP_FACTORY;
101     QAction *actionGroupSelected( QObject *parent = nullptr ) SIP_FACTORY;
102 
103     /**
104      * Action to enable/disable mutually exclusive flag of a group (only one child node may be checked)
105      * \since QGIS 2.12
106      */
107     QAction *actionMutuallyExclusiveGroup( QObject *parent = nullptr ) SIP_FACTORY;
108 
109     /**
110     * Zooms a map \a canvas to the extent of the active layer in the layer tree.
111     * \deprecated since QGIS 3.18, use zoomToLayers()
112     */
113     Q_DECL_DEPRECATED void zoomToLayer( QgsMapCanvas *canvas ) SIP_DEPRECATED;
114 
115     /**
116      * Zooms a map \a canvas to all the selected layer(s) in the layer tree
117      * \see zoomToLayers()
118      * \since QGIS 3.18
119      */
120     void zoomToLayers( QgsMapCanvas *canvas );
121 
122     /**
123      * \see zoomToSelection()
124      * \since QGIS 3.2
125      */
126     void zoomToSelection( QgsMapCanvas *canvas );
127     void zoomToGroup( QgsMapCanvas *canvas );
128 
129   public slots:
130     void showInOverview();
131     void addGroup();
132 
133   protected slots:
134     void removeGroupOrLayer();
135     void renameGroupOrLayer();
136     void showFeatureCount();
137 
138     /**
139      * Zooms to the extent of the active layer in the layer tree.
140      * \deprecated since QGIS 3.18, use zoomToLayers()
141      */
142     Q_DECL_DEPRECATED void zoomToLayer() SIP_DEPRECATED;
143 
144     /**
145      * Zooms to the combined extent of all the selected layer(s) in the layer tree.
146      * \since QGIS 3.18
147      */
148     void zoomToLayers();
149 
150     /**
151      * Zooms to the bounding box of all selected features of a vector layer.
152      * \since QGIS 3.2
153      */
154     void zoomToSelection();
155     void zoomToGroup();
156 
157     /**
158      * \deprecated since QGIS 3.2, use moveOutOfGroup()
159      */
160     Q_DECL_DEPRECATED void makeTopLevel() SIP_DEPRECATED;
161 
162     /**
163      * Moves selected layer(s) out of the group(s) and places this/these above the group(s)
164      * \since QGIS 3.2
165      */
166     void moveOutOfGroup();
167 
168     /**
169      * Moves selected layer(s) and/or group(s) to the top of the layer panel
170      * or the top of the group if the layer/group is placed within a group.
171      * \since QGIS 3.2
172      */
173     void moveToTop();
174 
175     /**
176      * Moves selected layer(s) and/or group(s) to the bottom of the layer panel
177      * or the bottom of the group if the layer/group is placed within a group.
178      * \since QGIS 3.14
179      */
180     void moveToBottom();
181     void groupSelected();
182 
183     /**
184      * Slot to enable/disable mutually exclusive group flag
185      * \since QGIS 2.12
186      */
187     void mutuallyExclusiveGroup();
188 
189   private slots:
190     void checkAndAllChildren();
191     void uncheckAndAllChildren();
192     void checkAndAllParents();
193 
194   protected:
195     void zoomToLayers( QgsMapCanvas *canvas, const QList<QgsMapLayer *> &layers );
196 
197     QString uniqueGroupName( QgsLayerTreeGroup *parentGroup );
198 
199   protected:
200     QgsLayerTreeView *mView = nullptr;
201 };
202 
203 
204 #endif // QGSLAYERTREEVIEWDEFAULTACTIONS_H
205