#include "StateGroup.h" StateGroup::StateGroup(int index,QWidget *parent) : QWidget(parent) { id = index; toplayout = new QGridLayout(this); this->setLayout(toplayout); toplayout->setMargin(0); box = new QGroupBox(this); toplayout->addWidget(box); layout = new QGridLayout(box); layout->setMargin(3); layout->setVerticalSpacing(6); box->setLayout(layout); m_lenght += layout->margin() * 2; } StateGroup::~StateGroup() { foreach (StateWidget * w, ItemList) { delete w; } } void StateGroup::addItem(StateWidget * w) { if(ItemList.size() >= 1) { //为什么减2? m_lenght += w->height() + layout->verticalSpacing() - 2; //qDebug() << this->height() << w->height() << layout->verticalSpacing(); } else { m_lenght += w->height(); } ItemList.insert(ItemList.size(),w);//逐渐往上加 if(layout) { if(w->ID() >= 0) { layout->addWidget(w,w->ID(),0,1,1); } } //检查界面,添加到界面 updateUI(); } void StateGroup::addItems(QMap list) { foreach (StateWidget *w, list) { addItem(w); } } void StateGroup::removeItem(int index) { if(ItemList.contains(index)) { StateWidget *w = ItemList.value(index); m_lenght -= w->height() + layout->verticalSpacing(); delete w; } } void StateGroup::removeItem(StateWidget * w) { if(ItemList.values().contains(w)) { m_lenght -= w->height() + layout->verticalSpacing(); delete w; } } void StateGroup::setValue(int index,QString value) { if(ItemList.contains(index)) { ItemList.value(index)->setValue(value); } } void StateGroup::setColor(int index,StateWidget::state s) { if(ItemList.contains(index)) { ItemList.value(index)->setColor(s); } } void StateGroup::updateUI(void) { }