1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
7 **
8 **
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License version 2 as published by the Free Software
11 ** Foundation and appearing in the file gpl-2.0.txt included in the
12 ** packaging of this file.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 **
23 ** This copyright notice MUST APPEAR in all copies of the script!
24 **
25 ** *************************************************************************
26 ** ChangeLog
27 ** *************************************************************************
28 ** This file was changed in 2016 by ravas. See ChangeLogs/r-a-v-a-s.txt
29 ****************************************************************************/
30 
31 #include "rs_actionlayerstoggleview.h"
32 
33 #include <QAction>
34 #include "rs_graphic.h"
35 #include "rs_debug.h"
36 #include "rs_layer.h"
37 
38 
RS_ActionLayersToggleView(RS_EntityContainer & container,RS_GraphicView & graphicView,RS_Layer * layer)39 RS_ActionLayersToggleView::RS_ActionLayersToggleView(
40                                 RS_EntityContainer& container,
41                                 RS_GraphicView& graphicView,
42                                 RS_Layer* layer)
43     : RS_ActionInterface("Toggle Layer Visibility", container, graphicView)
44     , a_layer(layer) {}
45 
trigger()46 void RS_ActionLayersToggleView::trigger() {
47     RS_DEBUG->print("toggle layer");
48     if (graphic) {
49         RS_LayerList* ll = graphic->getLayerList();
50         unsigned cnt = 0;
51         // toggle selected layers
52         for (auto layer: *ll) {
53             if (!layer) continue;
54             if (!layer->isVisibleInLayerList()) continue;
55             if (!layer->isSelectedInLayerList()) continue;
56             graphic->toggleLayer(layer);
57             cnt++;
58         }
59         // if there wasn't selected layers, toggle active layer
60         if (!cnt) {
61             graphic->toggleLayer(a_layer);
62         }
63         graphic->updateInserts();
64         container->calculateBorders();
65     }
66     finish(false);
67 }
68 
init(int status)69 void RS_ActionLayersToggleView::init(int status) {
70     RS_ActionInterface::init(status);
71     trigger();
72 }
73 
74 // EOF
75