-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConfigForm.cpp
194 lines (166 loc) · 6.48 KB
/
ConfigForm.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include "ConfigForm.h"
#include "ui_ConfigForm.h"
ConfigForm::ConfigForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::ConfigForm)
{
ui->setupUi(this);
init();
}
ConfigForm::~ConfigForm()
{
delete ui;
}
void ConfigForm::init()
{
ui->groupBox->setTitle(QString::fromLocal8Bit("数据库服务器参数配置"));
ui->groupBox_2->setTitle(QString::fromLocal8Bit("网络服务器参数配置"));
ui->groupBox_3->setTitle(QString::fromLocal8Bit("WMS服务器参数配置"));
ui->groupBox_4->setTitle(QString::fromLocal8Bit("串口参数配置"));
// 更新串口号
updatePort();
// 波特率
ui->comboBoxBaud->addItem("9600");
ui->comboBoxBaud->addItem("19200");
ui->comboBoxBaud->addItem("38400");
ui->comboBoxBaud->addItem("57600");
ui->comboBoxBaud->addItem("115200");
QRegExp rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b");
ui->lineEditNetSerIP->setValidator(new QRegExpValidator(rx, this));
ui->lineEditNetSerPort->setValidator(new QRegExpValidator(QRegExp("[0-9]+$")));
// 读取服务器配置参数
Config config("./res/set/config.ini");
QString serverName = config.get("DataBase", "ServerName").toString();
QString databaseName = config.get("DataBase", "DataBaseName").toString();
QString loginName = config.get("DataBase", "LoginName").toString();
QString passwd = config.get("DataBase", "Passwd").toString();
QString netip = config.get("Net", "IP").toString();
QString netport = config.get("Net", "Port").toString();
QString com = config.get("SerialPort", "Com").toString();
QString num = config.get("SerialPort", "Num").toString();
QString baud = config.get("SerialPort", "Baud").toString();
QString details = config.get("SerialPort", "Details").toString();
// 填充相应文本框
ui->lineEditSerName->setText(serverName);
ui->lineEditDbName->setText(databaseName);
ui->lineEditLoginName->setText(loginName);
ui->lineEditPasswd->setText(passwd);
ui->lineEditNetSerIP->setText(netip);
ui->lineEditNetSerPort->setText(netport);
ui->comboBoxComName->setCurrentText(com);
ui->lineEditComNumber->setText(num);
ui->comboBoxBaud->setCurrentText(baud);
ui->labelComDetails->setText(details);
}
void ConfigForm::on_pushButtonSetDb_clicked()
{
QString serverName = ui->lineEditSerName->text();
QString databaseName = ui->lineEditDbName->text();
QString loginName = ui->lineEditLoginName->text();
QString passwd = ui->lineEditPasswd->text();
if(serverName.isEmpty() || databaseName.isEmpty() || loginName.isEmpty() || passwd.isEmpty())
{
MsgBoxEx *msgBox = new MsgBoxEx();
msgBox->setMsgBoxMode(QString::fromLocal8Bit("所有数据库服务器参数都不可为空!"));
delete msgBox;
return;
}
// 设置服务器参数
Config config("./res/set/config.ini");
config.set("DataBase", "ServerName", QString("%1").arg(serverName));
config.set("DataBase", "DataBaseName", QString("%1").arg(databaseName));
config.set("DataBase", "LoginName", QString("%1").arg(loginName));
config.set("DataBase", "Passwd", QString("%1").arg(passwd));
MsgBoxEx *msgBox = new MsgBoxEx();
msgBox->setMsgBoxMode(QString::fromLocal8Bit("数据库服务器参数设置成功,若要应用此设置请重启程序!"), 3000);
delete msgBox;
}
void ConfigForm::on_pushButtonSetNet_clicked()
{
QString ip = ui->lineEditNetSerIP->text();
QString port = ui->lineEditNetSerPort->text();
if(ip.isEmpty() || port.isEmpty())
{
MsgBoxEx *msgBox = new MsgBoxEx();
msgBox->setMsgBoxMode(QString::fromLocal8Bit("网络服务器参数不可为空!"));
delete msgBox;
return;
}
Config config("./res/set/config.ini");
config.set("Net", "IP", QString("%1").arg(ip));
config.set("Net", "Port", QString("%1").arg(port));
MsgBoxEx *msgBox = new MsgBoxEx();
msgBox->setMsgBoxMode(QString::fromLocal8Bit("网络服务器参数设置成功,若要应用此设置请重启程序!"), 3000);
delete msgBox;
}
void ConfigForm::onNetServerStateChange(QString strLinkDesc)
{
ui->labelNetState->setText(strLinkDesc);
}
void ConfigForm::onSerialPortStateChange(QString strOpenDesc)
{
ui->labelComState->setText(strOpenDesc);
}
void ConfigForm::on_pushButtonSetCom_clicked()
{
QString com = ui->comboBoxComName->currentText();
QString num = ui->lineEditComNumber->text();
QString baud = ui->comboBoxBaud->currentText();
QString details = ui->labelComDetails->text();
if(com.isEmpty() || baud.isEmpty())
{
MsgBoxEx *msgBox = new MsgBoxEx();
msgBox->setMsgBoxMode(QString::fromLocal8Bit("串口参数不可为空!"));
delete msgBox;
return;
}
Config config("./res/set/config.ini");
config.set("SerialPort", "Com", QString("%1").arg(com));
config.set("SerialPort", "Num", QString("%1").arg(num));
config.set("SerialPort", "Baud", QString("%1").arg(baud));
config.set("SerialPort", "Details", QString("%1").arg(details));
MsgBoxEx *msgBox = new MsgBoxEx();
msgBox->setMsgBoxMode(QString::fromLocal8Bit("串口参数设置成功,若要应用此设置请重启程序!"), 3000);
delete msgBox;
}
void ConfigForm::on_comboBoxComName_currentTextChanged(const QString &arg1)
{
QString strValue = m_mapSerialPort[arg1];
QStringList listValue = strValue.split(";");
if(listValue.count()!=2)
return;
ui->lineEditComNumber->setText(listValue[0]);
ui->labelComDetails->setText(listValue[1]);
}
void ConfigForm::on_pushButtonRefresh_clicked()
{
updatePort();
}
void ConfigForm::updatePort()
{
m_mapSerialPort.clear();
ui->comboBoxComName->clear();
ui->lineEditComNumber->setText("");
ui->comboBoxBaud->setCurrentIndex(-1);
ui->labelComDetails->setText("");
QSerialPort serial;
QStringList listPort;
const auto infos = QSerialPortInfo::availablePorts();
for (const QSerialPortInfo &info : infos)
{
serial.setPort(info);
if(serial.open(QIODevice::ReadWrite))
{
m_mapSerialPort[info.portName()] = info.serialNumber()+";"+info.description();
serial.close();
}
}
for (QMap<QString, QString>::iterator it = m_mapSerialPort.begin(); it != m_mapSerialPort.end(); it++)
{
if(!it.key().isEmpty())
{
ui->comboBoxComName->addItem(it.key());
}
}
ui->comboBoxComName->setCurrentIndex(-1);
}