1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2015 A. Stebich (librecad@mail.lordofbikes.de)
6 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
7 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
8 **
9 **
10 ** This file may be distributed and/or modified under the terms of the
11 ** GNU General Public License version 2 as published by the Free Software
12 ** Foundation and appearing in the file gpl-2.0.txt included in the
13 ** packaging of this file.
14 **
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ** GNU General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program; if not, write to the Free Software
22 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 **
24 ** This copyright notice MUST APPEAR in all copies of the script!
25 **
26 **********************************************************************/
27 
28 
29 #ifndef RS_LAYERLIST_H
30 #define RS_LAYERLIST_H
31 
32 #include <QList>
33 #include "rs_layer.h"
34 
35 class RS_LayerListListener;
36 class QG_LayerWidget;
37 
38 /**
39  * A list of layers.
40  *
41  * @author Andrew Mustun
42  */
43 class RS_LayerList {
44 public:
45     RS_LayerList();
46 	virtual ~RS_LayerList() = default;
47 
48     void clear();
49 
50     /**
51      * @return Number of layers in the list.
52      */
count()53     unsigned int count() const {
54         return layers.count();
55     }
56 
57     /**
58      * @return Layer at given position or NULL if i is out of range.
59      */
at(unsigned int i)60     RS_Layer* at(unsigned int i) {
61         return layers.at(i);
62     }
63     QList<RS_Layer*>::iterator begin();
64     QList<RS_Layer*>::iterator end();
65     QList<RS_Layer*>::const_iterator begin()const;
66     QList<RS_Layer*>::const_iterator end()const;
67 
68     void activate(const QString& name, bool notify = false);
69     void activate(RS_Layer* layer, bool notify = false);
70     //! @return The active layer of NULL if no layer is activated.
getActive()71     RS_Layer* getActive() {
72         return activeLayer;
73     }
74     virtual void add(RS_Layer* layer);
75     virtual void remove(RS_Layer* layer);
76     virtual void edit(RS_Layer* layer, const RS_Layer& source);
77     RS_Layer* find(const QString& name);
78     int getIndex(const QString& name);
79     int getIndex(RS_Layer* layer);
80     void toggle(const QString& name);
81     void toggle(RS_Layer* layer);
82     void toggleLock(RS_Layer* layer);
83     void togglePrint(RS_Layer* layer);
84     void toggleConstruction(RS_Layer* layer);
85     void freezeAll(bool freeze);
86     void lockAll(bool lock);
87 
88     //! sets the layerWidget pointer in RS_LayerListClass
setLayerWitget(QG_LayerWidget * lw)89     void setLayerWitget(QG_LayerWidget * lw) {
90         layerWidget=lw;
91     }
92     //! @return the layerWidget pointer inside the RS_LayerListClass
getLayerWitget()93     QG_LayerWidget* getLayerWitget() {
94         return layerWidget;
95     }
96     //! @return First layer of the list.
97     //RS_Layer* firstLayer() {
98     //    return layers.first();
99     //}
100     /** @return Next layer from the list after
101      * calling firstLayer() or nextLayer().
102      */
103     //RS_Layer* nextLayer() {
104     //    return layers.next();
105     //}
106 
107     void addListener(RS_LayerListListener* listener);
108     void removeListener(RS_LayerListListener* listener);
109 
110     /**
111      * Sets the layer lists modified status to 'm'.
112      */
113     void setModified(bool m);
114 
115     /**
116      * @retval true The layer list has been modified.
117      * @retval false The layer list has not been modified.
118      */
isModified()119     virtual bool isModified() const {
120         return modified;
121     }
122     /**
123      * @brief sort by layer names
124      */
125     void sort();
126 
127     friend std::ostream& operator << (std::ostream& os, RS_LayerList& l);
128 
129 private:
130     //! layers in the graphic
131     QList<RS_Layer*> layers;
132     //! List of registered LayerListListeners
133     QList<RS_LayerListListener*> layerListListeners;
134     QG_LayerWidget* layerWidget;
135     //! Currently active layer
136     RS_Layer* activeLayer;
137     /** Flag set if the layer list was modified and not yet saved. */
138     bool modified;
139 };
140 
141 #endif
142