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 "rs_layerlist.h"
23 * Default Constructor. You must call init manually before using
26 QG_LayerBox::QG_LayerBox(QWidget * parent, const char */*name*/): QComboBox(parent)
29 showUnchanged = false;
38 QG_LayerBox::~QG_LayerBox()
42 RS_Layer * QG_LayerBox::getLayer()
48 * Initialisation (called manually only once).
50 * @param layerList Layer list which provides the layer names that are
52 * @param showByBlock true: Show attribute ByBlock.
54 void QG_LayerBox::init(RS_LayerList & layerList, bool showByBlock, bool showUnchanged)
56 this->showByBlock = showByBlock;
57 this->showUnchanged = showUnchanged;
58 this->layerList = &layerList;
61 // insertItem(tr("- Unchanged -"));
62 addItem(tr("- Unchanged -"));
64 for(uint i=0; i<layerList.count(); ++i)
66 RS_Layer * lay = layerList.at(i);
68 if (lay != NULL && (lay->getName() != "ByBlock" || showByBlock))
69 // insertItem(lay->getName());
70 addItem(lay->getName());
73 connect(this, SIGNAL(activated(int)), this, SLOT(slotLayerChanged(int)));
75 slotLayerChanged(currentIndex());
79 * Sets the layer shown in the combobox to the given layer.
81 void QG_LayerBox::setLayer(RS_Layer & layer)
83 currentLayer = &layer;
85 //if (layer.getName()=="ByBlock" && showByBlock) {
89 // setCurrentText(layer.getName());
90 setItemText(currentIndex(), layer.getName());
93 //if (currentItem()!=7+(int)showByBlock*2) {
94 slotLayerChanged(currentIndex());
99 * Sets the layer shown in the combobox to the given layer.
101 void QG_LayerBox::setLayer(QString & layer)
103 //if (layer.getName()=="ByBlock" && showByBlock) {
104 // setCurrentItem(0);
106 // setCurrentText(layer);
107 setItemText(currentIndex(), layer);
110 //if (currentItem()!=7+(int)showByBlock*2) {
111 slotLayerChanged(currentIndex());
115 bool QG_LayerBox::isUnchanged()
121 * Called when the color has changed. This method
122 * sets the current color to the value chosen or even
123 * offers a dialog to the user that allows him/ her to
124 * choose an individual color.
126 void QG_LayerBox::slotLayerChanged(int index)
128 //currentLayer.resetFlags();
130 if (index == 0 && showUnchanged)
135 // currentLayer = layerList->find(text(index));
136 currentLayer = layerList->find(itemText(index));
138 //printf("Current color is (%d): %s\n",
139 // index, currentLayer.name().latin1());
141 emit layerChanged(currentLayer);