]> Shamusworld >> Repos - architektonas/blob - src/widgets/layerbox.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / widgets / layerbox.cpp
1 // layerbox.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  05/11/2010  Added this text. :-)
15 //
16
17 #include "layerbox.h"
18
19 #include "layer.h"
20 #include "layerlist.h"
21
22 /**
23  * Default Constructor. You must call init manually before using
24  * this class.
25  */
26 LayerBox::LayerBox(QWidget * parent, const char */*name*/): QComboBox(parent)
27 {
28         showByBlock = false;
29         showUnchanged = false;
30         unchanged = false;
31         layerList = NULL;
32         currentLayer = NULL;
33 }
34
35 /**
36  * Destructor
37  */
38 LayerBox::~LayerBox()
39 {
40 }
41
42 Layer * LayerBox::getLayer()
43 {
44         return currentLayer;
45 }
46
47 /**
48  * Initialisation (called manually only once).
49  *
50  * @param layerList Layer list which provides the layer names that are
51  *                  available.
52  * @param showByBlock true: Show attribute ByBlock.
53  */
54 void LayerBox::init(LayerList & layerList, bool showByBlock, bool showUnchanged)
55 {
56         this->showByBlock = showByBlock;
57         this->showUnchanged = showUnchanged;
58         this->layerList = &layerList;
59
60         if (showUnchanged)
61 //              insertItem(tr("- Unchanged -"));
62                 addItem(tr("- Unchanged -"));
63
64         for(uint i=0; i<layerList.count(); ++i)
65         {
66                 Layer * lay = layerList.at(i);
67
68                 if (lay != NULL && (lay->getName() != "ByBlock" || showByBlock))
69 //                      insertItem(lay->getName());
70                         addItem(lay->getName());
71         }
72
73         connect(this, SIGNAL(activated(int)), this, SLOT(slotLayerChanged(int)));
74         setCurrentIndex(0);
75         slotLayerChanged(currentIndex());
76 }
77
78 /**
79  * Sets the layer shown in the combobox to the given layer.
80  */
81 void LayerBox::setLayer(Layer & layer)
82 {
83         currentLayer = &layer;
84
85         //if (layer.getName()=="ByBlock" && showByBlock) {
86         //    setCurrentItem(0);
87         //} else {
88
89 //      setCurrentText(layer.getName());
90         setItemText(currentIndex(), layer.getName());
91         //}
92
93         //if (currentItem()!=7+(int)showByBlock*2) {
94         slotLayerChanged(currentIndex());
95         //}
96 }
97
98 /**
99  * Sets the layer shown in the combobox to the given layer.
100  */
101 void LayerBox::setLayer(QString & layer)
102 {
103     //if (layer.getName()=="ByBlock" && showByBlock) {
104     //    setCurrentItem(0);
105     //} else {
106 //    setCurrentText(layer);
107     setItemText(currentIndex(), layer);
108     //}
109
110     //if (currentItem()!=7+(int)showByBlock*2) {
111     slotLayerChanged(currentIndex());
112     //}
113 }
114
115 bool LayerBox::isUnchanged()
116 {
117         return unchanged;
118 }
119
120 /**
121  * Called when the color has changed. This method sets the current color to
122  * the value chosen or even offers a dialog to the user that allows him/her to
123  * choose an individual color.
124  */
125 void LayerBox::slotLayerChanged(int index)
126 {
127         //currentLayer.resetFlags();
128
129         if (index == 0 && showUnchanged)
130                 unchanged = true;
131         else
132                 unchanged = false;
133
134 //      currentLayer = layerList->find(text(index));
135         currentLayer = layerList->find(itemText(index));
136
137         //printf("Current color is (%d): %s\n",
138         //       index, currentLayer.name().latin1());
139
140         emit layerChanged(currentLayer);
141 }