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