207 lines
7.3 KiB
C++
207 lines
7.3 KiB
C++
#include "CustomFilter.h"
|
|
#include "ui_CustomFilter.h"
|
|
#include <QNetworkRequest>
|
|
#include "QMyTableViewBtnDelegate.h"
|
|
#include "NetMgr.h"
|
|
#include <QListView>
|
|
|
|
CustomFilter::CustomFilter(QWidget *parent) :
|
|
QWidget(parent),
|
|
ui(new Ui::CustomFilter)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
headerStr = QObject::tr("频率(Hz),衰减位移量(um)");
|
|
|
|
model = new QStandardItemModel(ui->tableView);
|
|
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); //选中行
|
|
QStringList headerList = headerStr.split(",");
|
|
model->setHorizontalHeaderLabels(headerList);
|
|
model->setColumnCount(headerList.size());
|
|
ui->tableView->setModel(model);
|
|
ui->tableView->setAlternatingRowColors(true);
|
|
ui->tableView->setColumnWidth(1, 150);
|
|
|
|
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
|
|
|
|
|
|
|
|
ui->comboBox_open->setView(new QListView());
|
|
ui->comboBox_open->addItem("否");
|
|
ui->comboBox_open->addItem("是");
|
|
connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&)));
|
|
connect(ui->comboBox_open,SIGNAL(currentIndexChanged(const QString &)),this,SLOT(comboBox_open_currentTextChanged(const QString&)));
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
}
|
|
|
|
CustomFilter::~CustomFilter()
|
|
{
|
|
qDebug() << "~CustomFilter()" << endl;
|
|
disconnect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&)));
|
|
delete ui;
|
|
}
|
|
|
|
void CustomFilter::on_pushButton_Add_clicked()
|
|
{
|
|
int rowCount = model->rowCount();
|
|
model->setRowCount(rowCount+1);
|
|
model->setData(model->index(rowCount,0,QModelIndex()),"");
|
|
model->setData(model->index(rowCount,1,QModelIndex()),"");
|
|
}
|
|
|
|
|
|
void CustomFilter::on_pushButton_Del_clicked()
|
|
{
|
|
int rowCount = model->rowCount();
|
|
int row = ui->tableView->currentIndex().row();//获得当前行索引
|
|
if(rowCount < 1 || row == -1){
|
|
QMessageBox::warning(this, QStringLiteral("提示"), QStringLiteral("请先选择一条记录!"));
|
|
return;
|
|
}
|
|
model->removeRow(row);
|
|
}
|
|
|
|
|
|
void CustomFilter::on_pushButton_Submit_clicked()
|
|
{
|
|
int rowCount = model->rowCount();
|
|
QJsonObject sendData;
|
|
sendData["cmd"] = "99";
|
|
sendData["chan_id"] = channel_ID;
|
|
sendData["num"] = rowCount;
|
|
QJsonArray range;
|
|
for(int i = 0; i < rowCount;i++){
|
|
QModelIndex index = model->index(i,0);
|
|
QString strData = model->data(index).toString();
|
|
range.append(strData.toFloat());
|
|
index = model->index(i,1);
|
|
strData = model->data(index).toString();
|
|
range.append(strData.toFloat());
|
|
}
|
|
sendData["range"] = range;
|
|
QNetworkRequest req;
|
|
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
|
|
req.setUrl(sUrl);
|
|
g_NetMgr->PostJson(req,sendData);
|
|
|
|
bool type ;
|
|
if(ui->comboBox_open->currentText() == "是"){
|
|
type = true;
|
|
}
|
|
if(ui->comboBox_open->currentText() == "否"){
|
|
type = false;
|
|
}
|
|
|
|
if(ui->doubleSpinBox_start->text().toDouble() >= ui->doubleSpinBox_stop->text().toDouble()){
|
|
QMessageBox::warning(this, QStringLiteral("提示"), QStringLiteral("频率下限设置错误!"));
|
|
return;
|
|
}
|
|
QJsonObject sendData2;
|
|
sendData2["cmd"] = "95";
|
|
sendData2["chan_id"] = channel_ID;
|
|
sendData2["open"] = type;
|
|
sendData2["start"] = ui->doubleSpinBox_start->text().toDouble();
|
|
sendData2["stop"] = ui->doubleSpinBox_stop->text().toDouble();
|
|
req.setUrl(sUrl);
|
|
g_NetMgr->PostJson(req,sendData2);
|
|
this->close();
|
|
}
|
|
|
|
void CustomFilter::slotNetMgr(QString sAddr, const QVariant &msg)
|
|
{
|
|
QJsonObject objec = msg.value<QJsonObject>();
|
|
if(objec.contains("cmd"))
|
|
{
|
|
QJsonValue arrays_value = objec.take("cmd");
|
|
qDebug() << "arrays_value" << arrays_value << endl;
|
|
bool Status = objec.take("success").toBool();
|
|
QString strMessage = objec.take("message").toString();
|
|
if(!Status){
|
|
QMessageBox::information(NULL, QStringLiteral("提示"), strMessage);
|
|
return;
|
|
}
|
|
if(arrays_value.toString() == "94"){
|
|
|
|
int Statusfilter = objec.take("status").toInt();
|
|
ui->doubleSpinBox_start->setValue(objec.take("start").toDouble());
|
|
ui->doubleSpinBox_stop->setValue(objec.take("stop").toDouble());
|
|
|
|
if(Statusfilter){
|
|
ui->comboBox_open->setCurrentText("是");
|
|
}else if(!Statusfilter){
|
|
ui->comboBox_open->setCurrentText("否");
|
|
ui->doubleSpinBox_start->setEnabled(false);
|
|
ui->doubleSpinBox_stop->setEnabled(false);
|
|
}
|
|
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("获取成功!"));
|
|
}else if(arrays_value.toString() == "98"){
|
|
int num = objec["num"].toInt();
|
|
int j = 0;
|
|
model->setRowCount(num);
|
|
QJsonArray range = objec["range"].toArray();
|
|
for (int i = 0; i < num; i++) {
|
|
model->setData(model->index(i,0,QModelIndex()),range[j].toInt());
|
|
j++;
|
|
model->setData(model->index(i,1,QModelIndex()),range[j].toInt());
|
|
j++;
|
|
}
|
|
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("获取成功!"));
|
|
}else if(arrays_value.toString() == "112"){
|
|
int Statusfilter = objec.take("status").toInt();
|
|
ui->doubleSpinBox_start->setValue(objec.take("start").toDouble());
|
|
ui->doubleSpinBox_stop->setValue(objec.take("stop").toDouble());
|
|
|
|
if(Statusfilter){
|
|
ui->comboBox_open->setCurrentText("是");
|
|
}else if(!Statusfilter){
|
|
ui->comboBox_open->setCurrentText("否");
|
|
ui->doubleSpinBox_start->setEnabled(false);
|
|
ui->doubleSpinBox_stop->setEnabled(false);
|
|
}
|
|
int num = objec["num"].toInt();
|
|
int j = 0;
|
|
model->setRowCount(num);
|
|
QJsonArray range = objec["range"].toArray();
|
|
for (int i = 0; i < num; i++) {
|
|
model->setData(model->index(i,0,QModelIndex()),range[j].toDouble());
|
|
j++;
|
|
model->setData(model->index(i,1,QModelIndex()),range[j].toInt());
|
|
j++;
|
|
}
|
|
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("获取成功!"));
|
|
}else if(arrays_value.toString() == "95" || arrays_value.toString() == "99"){
|
|
QMessageBox::information(this, QStringLiteral("提示"), QStringLiteral("设置成功!"));
|
|
}
|
|
}
|
|
if(!vibrate_channel){
|
|
ui->comboBox_open->setEnabled(false);
|
|
ui->doubleSpinBox_start->setEnabled(false);
|
|
ui->doubleSpinBox_stop->setEnabled(false);
|
|
}
|
|
|
|
}
|
|
|
|
void CustomFilter::getfilterInfo()
|
|
{
|
|
|
|
QJsonObject sendData;
|
|
sendData["cmd"] = "112";
|
|
sendData["chan_id"] = channel_ID;
|
|
QNetworkRequest req;
|
|
QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP);
|
|
req.setUrl(sUrl);
|
|
g_NetMgr->PostJson(req,sendData);
|
|
|
|
}
|
|
|
|
void CustomFilter::comboBox_open_currentTextChanged(const QString &str)
|
|
{
|
|
if(str == "否"){
|
|
ui->doubleSpinBox_start->setEnabled(false);
|
|
ui->doubleSpinBox_stop->setEnabled(false);
|
|
}else if(str == "是"){
|
|
ui->doubleSpinBox_start->setEnabled(true);
|
|
ui->doubleSpinBox_stop->setEnabled(true);
|
|
}
|
|
}
|