Commit | Line | Data |
---|---|---|
b647ee2a S |
1 | #include "device.h" |
2 | #include "ui_device.h" | |
3 | ||
4 | Device::Device(qint16 index, QWidget *parent, QString name, QString serial, quint16 channelCount, QVector<bool> status) : | |
5 | QWidget(parent), | |
6 | ui(new Ui::device), | |
7 | _index(index) | |
8 | { | |
9 | ui->setupUi(this); | |
10 | ||
11 | ui->device_channel_count_value->setText(QString::number(channelCount)); | |
12 | ui->device_name_value->setText(name); | |
13 | ui->device_serial_value->setText(serial); | |
14 | ||
15 | connect(ui->device_close_all,&QPushButton::clicked,[this](){ | |
16 | changeChannelStatus(false); | |
17 | emit closeAllSignal(this->_index); | |
18 | }); | |
19 | ||
20 | connect(ui->device_open_all,&QPushButton::clicked,[this](){ | |
21 | changeChannelStatus(true); | |
22 | emit openAllSignal(this->_index); | |
23 | }); | |
24 | ||
25 | ||
26 | QVBoxLayout *vbox = new QVBoxLayout; | |
27 | for(auto i=1;i<channelCount+1;i++){ | |
28 | QCheckBox *checkBox = new QCheckBox(QString("Channel %1").arg(i),this); | |
29 | connect(checkBox, &QCheckBox::clicked,[this,i](bool state){ | |
30 | emit changeChannelState(this->_index, state,i); | |
31 | }); | |
32 | checkBox->setChecked(status[i-1]); | |
33 | vbox->addWidget(checkBox); | |
34 | } | |
35 | ||
36 | ui->channels_windget->setLayout(vbox); | |
37 | } | |
38 | ||
39 | Device::~Device() | |
40 | { | |
41 | delete ui; | |
42 | } | |
43 | ||
44 | void Device::changeChannelStatus(bool status) | |
45 | { | |
46 | QList<QCheckBox *> allCButtons = this->ui->channels_windget->findChildren<QCheckBox *>(); | |
47 | for(const auto& i:allCButtons){ | |
48 | i->setChecked(status); | |
49 | } | |
50 | } |