-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdlgrelaylinkcontrol.cpp
117 lines (101 loc) · 3.08 KB
/
dlgrelaylinkcontrol.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*********************************************************************
* Copyright EoF Software Labs. All Rights Reserved.
* Copyright EoF Software Labs Authors.
* Written by B. Eschrich ([email protected])
* SPDX-License-Identifier: GPL v3
**********************************************************************/
#include "ui_dlgrelaylinkcontrol.h"
#include <dlgrelaylinkcontrol.h>
DlgRelayLinkControl::DlgRelayLinkControl(WSRelayDigInMbRtu* rtu, QWidget* parent)
: QDialog(parent)
, ui(new Ui::DlgRelayLinkControl)
, m_rtu(rtu)
, m_channel(0)
, m_control()
, m_btnSave(nullptr)
{
ui->setupUi(this);
ui->cbChannel->clear();
for (quint8 i = 0; i < m_rtu->maxInputs(); i++) {
QString name = tr("Channel %1").arg(i + 1);
ui->cbChannel->addItem(name, QVariant());
m_control[i] = rtu->controlMode(i);
}
m_btnSave = ui->buttonBox->button(QDialogButtonBox::Save);
m_btnSave->setEnabled(false);
/* initial selection */
ui->cbChannel->setCurrentIndex(0);
/* initial active radio button */
on_cbChannel_activated(0);
}
uint DlgRelayLinkControl::controlMode(quint8 channel)
{
return m_control[channel];
}
void DlgRelayLinkControl::setControlModes(const QMap<quint8, WSRelayDigInMbRtu::TControlMode>& modes)
{
m_control = modes;
}
const QMap<quint8, WSRelayDigInMbRtu::TControlMode>& DlgRelayLinkControl::controlModes() const
{
return m_control;
}
inline void DlgRelayLinkControl::setModeOption(quint8 channel, WSRelayDigInMbRtu::TControlMode mode)
{
m_control[channel] = mode;
m_channel = channel;
switch (mode) {
case WSRelayDigInMbRtu::NormalMode: {
ui->rbMode0->setChecked(true);
ui->rbMode1->setChecked(false);
ui->rbMode2->setChecked(false);
break;
}
case WSRelayDigInMbRtu::LinkageMode: {
ui->rbMode0->setChecked(false);
ui->rbMode1->setChecked(true);
ui->rbMode2->setChecked(false);
break;
}
case WSRelayDigInMbRtu::ToggleMode: {
ui->rbMode0->setChecked(false);
ui->rbMode1->setChecked(false);
ui->rbMode2->setChecked(true);
break;
}
}
}
DlgRelayLinkControl::~DlgRelayLinkControl()
{
delete ui;
}
void DlgRelayLinkControl::on_cbChannel_activated(int index)
{
quint8 channel = static_cast<quint8>(index);
setModeOption(channel, m_control[channel]);
}
void DlgRelayLinkControl::on_rbMode0_clicked(bool checked)
{
if (checked) {
m_control[m_channel] = WSRelayDigInMbRtu::NormalMode;
m_btnSave->setEnabled(true);
}
}
void DlgRelayLinkControl::on_rbMode1_clicked(bool checked)
{
if (checked) {
m_control[m_channel] = WSRelayDigInMbRtu::LinkageMode;
m_btnSave->setEnabled(true);
}
}
void DlgRelayLinkControl::on_rbMode2_clicked(bool checked)
{
if (checked) {
m_control[m_channel] = WSRelayDigInMbRtu::ToggleMode;
m_btnSave->setEnabled(true);
}
}
void DlgRelayLinkControl::on_buttonBox_accepted()
{
m_rtu->setControlModes(m_control, true);
}