#include "sysconfig.h" #include "ui_sysconfig.h" #include "includes.h" #include "maindlg.h" sysconfig::sysconfig(QWidget *parent) : QWidget(parent) , ui(new Ui::sysconfig) { ui->setupUi(this); m_pMainDlg = static_cast(parent);//保存上级窗口指针 memset(&m_stSysConfig, 0, sizeof(SYS_CONFIG_T));//初始化 configSignalSlot(); initUi(); } sysconfig::~sysconfig() { delete ui; } //配置界面按钮信号与槽 void sysconfig::configSignalSlot(){ connect(ui->pushButtonAllSel, &QPushButton::clicked, this, &this->selectAllItem);//全选 connect(ui->pushButtonAllNoSel, &QPushButton::clicked, this, &this->selectAllNoItem);//全不选 connect(ui->pushButtonClear, &QPushButton::clicked, this, &this->clearAllItem);//清空 connect(ui->pushButtonQuery, &QPushButton::clicked, this, &sysconfig::queryParam);//查询参数 connect(ui->pushButtonConfig, &QPushButton::clicked, this, &sysconfig::configParam);//设置参数 } void sysconfig::initUi(){ selectAllItem(); queryParam(); } //全选 void sysconfig::selectAllItem(){ ui->checkBoxHostUrl->setChecked(true); ui->checkBoxHostPort->setChecked(true); } //全不选 void sysconfig::selectAllNoItem(){ ui->checkBoxHostUrl->setChecked(false); ui->checkBoxHostPort->setChecked(false); } //清空参数 void sysconfig::clearAllItem(){ QString strText = ""; ui->lineEditHostUrl->setText(strText); ui->spinBoxHostPort->setValue(1); } //获得系统参数 void sysconfig::getSysConfigParam(QString *pstrHostUrl, QString *pstrHostPort){ QString strText = ""; QString folderPath = "mx_ips8000"; QString filePath = ""; //判断文件夹是否存在 QDir dir(folderPath); if (!dir.exists()) { dir.mkpath("."); // 创建文件夹,如果它不存在 } filePath = folderPath + "/IPS8000GUI.ini"; //创建读指针 QSettings *configIniRead = new QSettings(filePath, QSettings::IniFormat); strText = configIniRead->value("/host/url").toString(); *pstrHostUrl = strText.trimmed();//去掉首尾空格 strText = configIniRead->value("/host/port").toString(); *pstrHostPort = strText.trimmed();//去掉首尾空格 return; } //查询参数 void sysconfig::queryParam(){ QString strText = ""; QString folderPath = "mx_ips8000"; QString filePath = ""; //判断文件夹是否存在 QDir dir(folderPath); if (!dir.exists()) { dir.mkpath("."); // 创建文件夹,如果它不存在 } filePath = folderPath + "/IPS8000GUI.ini"; //创建读指针 QSettings *configIniRead = new QSettings(filePath, QSettings::IniFormat); //读取主机地址 if(ui->checkBoxHostUrl->isChecked()){ strText = configIniRead->value("/host/url").toString(); strText = strText.trimmed();//去掉首尾空格 ui->lineEditHostUrl->setText(strText); m_stSysConfig.hostUrl = strText; } //读取主机端口 if(ui->checkBoxHostPort->isChecked()){ strText = configIniRead->value("/host/port").toString(); strText = strText.trimmed();//去掉首尾空格 ui->spinBoxHostPort->setValue(strText.toInt()); m_stSysConfig.hostPort = strText.toInt(); } //读入入完成后删除指针 delete configIniRead; } //配置参数,将参数保存到本地ini文件中 void sysconfig::configParam(){ QString strText = ""; QByteArray baData; quint8 byCharLen = 0; quint32 dwPort = 0; QString folderPath = "mx_ips8000"; QString filePath = ""; QMessageBox::StandardButton dlg; dlg = QMessageBox::question(this, "提示", "确定要设置系统参数吗?", QMessageBox::Yes|QMessageBox::No); if (dlg == QMessageBox::No) { return; } //判断文件夹是否存在 QDir dir(folderPath); if (!dir.exists()) { dir.mkpath("."); // 创建文件夹,如果它不存在 } filePath = folderPath + "/IPS8000GUI.ini"; //创建写指针 QSettings *configIniWrite = new QSettings(filePath, QSettings::IniFormat); //管理中心URL if(ui->checkBoxHostUrl->isChecked()){ strText = ui->lineEditHostUrl->text(); strText = strText.trimmed(); baData = strText.toUtf8(); byCharLen = baData.size(); if(byCharLen < 6){ QMessageBox::information(this, "提示", "请输入正确的主机地址"); return; } //向ini文件中写入内容,setValue函数的两个参数是键值对 //向ini文件的host节写入内容 configIniWrite->setValue("/host/url", strText); m_stSysConfig.hostUrl = strText; } //管理中心端口 if(ui->checkBoxHostPort->isChecked()){ dwPort = ui->spinBoxHostPort->value(); if(dwPort <= 0){ QMessageBox::information(this, "提示", "请输入正确的网络端口"); return; } //向ini文件的Project节写入内容 configIniWrite->setValue("/host/port", dwPort); m_stSysConfig.hostPort = dwPort; } //写入完成后删除指针 delete configIniWrite; //重新配置http模块 m_pMainDlg->configHttpReq(); QMessageBox::information(this, "提示", "保存系统参数成功"); }