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 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/11/2010 Added this text. :-)
15 #include "qg_layerbox.h"
18 #include "rs_layerlist.h"
21 * Default Constructor. You must call init manually before using
24 QG_LayerBox::QG_LayerBox(QWidget * parent, const char */*name*/): QComboBox(parent)
27 showUnchanged = false;
36 QG_LayerBox::~QG_LayerBox()
40 RS_Layer * QG_LayerBox::getLayer()
46 * Initialisation (called manually only once).
48 * @param layerList Layer list which provides the layer names that are
50 * @param showByBlock true: Show attribute ByBlock.
52 void QG_LayerBox::init(RS_LayerList & layerList, bool showByBlock, bool showUnchanged)
54 this->showByBlock = showByBlock;
55 this->showUnchanged = showUnchanged;
56 this->layerList = &layerList;
59 // insertItem(tr("- Unchanged -"));
60 addItem(tr("- Unchanged -"));
62 for(uint i=0; i<layerList.count(); ++i)
64 RS_Layer * lay = layerList.at(i);
66 if (lay != NULL && (lay->getName() != "ByBlock" || showByBlock))
67 // insertItem(lay->getName());
68 addItem(lay->getName());
71 connect(this, SIGNAL(activated(int)), this, SLOT(slotLayerChanged(int)));
73 slotLayerChanged(currentIndex());
77 * Sets the layer shown in the combobox to the given layer.
79 void QG_LayerBox::setLayer(RS_Layer & layer)
81 currentLayer = &layer;
83 //if (layer.getName()=="ByBlock" && showByBlock) {
87 // setCurrentText(layer.getName());
88 setItemText(currentIndex(), layer.getName());
91 //if (currentItem()!=7+(int)showByBlock*2) {
92 slotLayerChanged(currentIndex());
97 * Sets the layer shown in the combobox to the given layer.
99 void QG_LayerBox::setLayer(QString & layer)
101 //if (layer.getName()=="ByBlock" && showByBlock) {
102 // setCurrentItem(0);
104 // setCurrentText(layer);
105 setItemText(currentIndex(), layer);
108 //if (currentItem()!=7+(int)showByBlock*2) {
109 slotLayerChanged(currentIndex());
113 bool QG_LayerBox::isUnchanged()
119 * Called when the color has changed. This method
120 * sets the current color to the value chosen or even
121 * offers a dialog to the user that allows him/ her to
122 * choose an individual color.
124 void QG_LayerBox::slotLayerChanged(int index)
126 //currentLayer.resetFlags();
128 if (index == 0 && showUnchanged)
133 // currentLayer = layerList->find(text(index));
134 currentLayer = layerList->find(itemText(index));
136 //printf("Current color is (%d): %s\n",
137 // index, currentLayer.name().latin1());
139 emit layerChanged(currentLayer);