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
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/11/2010 Added this text. :-)
20 #include "layerlist.h"
23 * Default Constructor. You must call init manually before using this class.
25 LayerBox::LayerBox(QWidget * parent, const char */*name*/): QComboBox(parent)
28 showUnchanged = false;
41 Layer * LayerBox::getLayer()
47 * Initialization (called manually only once).
49 * @param layerList Layer list which provides the layer names that are available.
50 * @param showByBlock true: Show attribute ByBlock.
52 void LayerBox::init(LayerList & layerList, bool showByBlock, bool showUnchanged)
54 this->showByBlock = showByBlock;
55 this->showUnchanged = showUnchanged;
56 this->layerList = &layerList;
59 addItem(tr("- Unchanged -"));
61 for(uint i=0; i<layerList.count(); ++i)
63 Layer * currentLayer = layerList.at(i);
65 if (currentLayer != NULL && (currentLayer->getName() != "ByBlock" || showByBlock))
66 addItem(currentLayer->getName());
69 connect(this, SIGNAL(activated(int)), this, SLOT(slotLayerChanged(int)));
71 slotLayerChanged(currentIndex());
75 * Sets the layer shown in the combobox to the given layer.
77 void LayerBox::setLayer(Layer & layer)
79 currentLayer = &layer;
81 //if (layer.getName()=="ByBlock" && showByBlock) {
85 // setCurrentText(layer.getName());
86 setItemText(currentIndex(), layer.getName());
89 //if (currentItem()!=7+(int)showByBlock*2) {
90 slotLayerChanged(currentIndex());
95 * Sets the layer shown in the combobox to the given layer.
97 void LayerBox::setLayer(QString & layer)
99 //if (layer.getName()=="ByBlock" && showByBlock) {
100 // setCurrentItem(0);
102 // setCurrentText(layer);
103 setItemText(currentIndex(), layer);
106 //if (currentItem()!=7+(int)showByBlock*2) {
107 slotLayerChanged(currentIndex());
111 bool LayerBox::isUnchanged()
117 * Called when the color has changed. This method sets the current color to
118 * the value chosen or even offers a dialog to the user that allows him/her to
119 * choose an individual color.
121 void LayerBox::slotLayerChanged(int index)
123 //currentLayer.resetFlags();
125 if (index == 0 && showUnchanged)
130 // currentLayer = layerList->find(text(index));
131 currentLayer = layerList->find(itemText(index));
133 //printf("Current color is (%d): %s\n",
134 // index, currentLayer.name().latin1());
136 emit layerChanged(currentLayer);