#include "param_page.h" #include "ui_param_page.h" #include "IMEKeyBoard/keyboard_num.h" #include #include Param_Page::Param_Page(QWidget *parent, Work_Thread *wt) : custom_dialog(parent), ui(new Ui::Param_Page) { ui->setupUi(this); comboBoxSet(); workThread = wt; set_btn_beep(ui->comboBox_testtype,SIGNAL(activated(int))); set_btn_beep(ui->comboBox_constvol,SIGNAL(activated(int))); set_btn_beep(ui->ledit_celldiffvol,SIGNAL(custom_click())); set_btn_beep(ui->ledit_temphigh,SIGNAL(custom_click())); set_btn_beep(ui->ledit_stopcurr,SIGNAL(custom_click())); set_btn_beep(ui->ledit_discurr,SIGNAL(custom_click())); set_btn_beep(ui->ledit_distime,SIGNAL(custom_click())); set_btn_beep(ui->ledit_disvollow,SIGNAL(custom_click())); set_btn_beep(ui->ledit_discap,SIGNAL(custom_click())); set_btn_beep(ui->ledit_cellvollow,SIGNAL(custom_click())); set_btn_beep(ui->ledit_dissoc,SIGNAL(custom_click())); set_btn_beep(ui->ledit_chgcurr,SIGNAL(custom_click())); set_btn_beep(ui->ledit_chgtime,SIGNAL(custom_click())); set_btn_beep(ui->ledit_chgvolhigh,SIGNAL(custom_click())); set_btn_beep(ui->ledit_chgcap,SIGNAL(custom_click())); set_btn_beep(ui->ledit_cellvolhigh,SIGNAL(custom_click())); set_btn_beep(ui->ledit_chgsoc,SIGNAL(custom_click())); set_btn_beep(ui->pushButton_cancel,SIGNAL(pressed())); set_btn_beep(ui->pushButton_save,SIGNAL(pressed())); set_btn_beep(ui->pushButton_Exit,SIGNAL(pressed())); connect(ui->comboBox_testtype,SIGNAL(currentIndexChanged(int)),this,SLOT(ComboBoxTestTypeAct(int))); connect(ui->comboBox_constvol,SIGNAL(currentIndexChanged(int)),this,SLOT(ComboBoxConVolAct(int))); connect(ui->ledit_celldiffvol,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->ledit_temphigh,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->ledit_stopcurr,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->ledit_discurr,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->ledit_distime,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->ledit_disvollow,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->ledit_discap,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->ledit_cellvollow,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->ledit_dissoc,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->ledit_chgcurr,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->ledit_chgtime,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->ledit_chgvolhigh,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->ledit_chgcap,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->ledit_cellvolhigh,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->ledit_chgsoc,SIGNAL(custom_click()),this,SLOT(leditClickAction())); connect(ui->pushButton_cancel,SIGNAL(released()),this,SLOT(buttonReleasedAction())); connect(ui->pushButton_save,SIGNAL(released()),this,SLOT(buttonReleasedAction())); connect(ui->pushButton_Exit,SIGNAL(released()),this,SLOT(buttonReleasedAction())); timer_500ms = new QTimer(this); connect(timer_500ms,SIGNAL(timeout()),this,SLOT(SystemTime())); } Param_Page::~Param_Page() { delete ui; delete timer_500ms; //qDebug("~Param_Page"); } void Param_Page::showParamPage() { workThread->setPageIndex(1); initParamPage(); paramValueShow(); paramEdited = false; buttonStateShow(); timer_500ms->start(500); this->exec(); } void Param_Page::closeParamPage() { timer_500ms->stop(); this->close(); } void Param_Page::buttonStateShow() { if(paramEdited){ ui->pushButton_save->setEnabled(true); ui->pushButton_cancel->setEnabled(true); } else{ ui->pushButton_save->setEnabled(false); ui->pushButton_cancel->setEnabled(false); ui->ledit_celldiffvol->setStyleSheet("color:black"); ui->ledit_temphigh->setStyleSheet("color:black"); ui->ledit_stopcurr->setStyleSheet("color:black"); ui->ledit_discurr->setStyleSheet("color:black"); ui->ledit_distime->setStyleSheet("color:black"); ui->ledit_disvollow->setStyleSheet("color:black"); ui->ledit_discap->setStyleSheet("color:black"); ui->ledit_cellvollow->setStyleSheet("color:black"); ui->ledit_dissoc->setStyleSheet("color:black"); ui->ledit_chgcurr->setStyleSheet("color:black"); ui->ledit_chgtime->setStyleSheet("color:black"); ui->ledit_chgvolhigh->setStyleSheet("color:black"); ui->ledit_chgcap->setStyleSheet("color:black"); ui->ledit_cellvolhigh->setStyleSheet("color:black"); ui->ledit_chgsoc->setStyleSheet("color:black"); } } void Param_Page::comboBoxSet() { QStringList modeStrList; modeStrList<comboBox_testtype->setIconSize(QSize(1, 50)); for(int i=0;icomboBox_testtype->addItem(icon,modeStrList.at(i)); } QStringList cvStrList; cvStrList<comboBox_constvol->setIconSize(QSize(1, 50)); for(int i=0;icomboBox_constvol->addItem(icon,cvStrList.at(i)); } } void Param_Page::initParamPage() { testParam = workThread->testParam; QString title = tr("参数设置--"); if(workThread->packParam.pack_type == PACK_TYPE_Halo){ title += tr("哈啰"); } else{ title += tr("其它"); } ui->label_Title->setText(title); paramEdited = false; if(workThread->testStateData.workState != WORK_STATE_STOPPED) { ui->comboBox_testtype->setEnabled(false); } else { ui->comboBox_testtype->setEnabled(true); } if(testParam.test_type == TestTypeDischarge) { ui->tabWidget->setCurrentIndex(0); } else{ ui->tabWidget->setCurrentIndex(1); } } void Param_Page::paramValueShow(void) { if(testParam.test_type == TestTypeDischarge) { ui->comboBox_testtype->setCurrentIndex(0); } else{ ui->comboBox_testtype->setCurrentIndex(1); } if(testParam.constvol_EN == 0){ ui->comboBox_constvol->setCurrentIndex(0); } else{ ui->comboBox_constvol->setCurrentIndex(1); } ui->ledit_celldiffvol->setText(QString::number(testParam.cell_vol_diff)); ui->ledit_temphigh->setText(QString::number((float)testParam.temp_high/10,'f',1)); ui->ledit_stopcurr->setText(QString::number((float)testParam.curr_end/100,'f',2)); ui->ledit_discurr->setText(QString::number((float)testParam.disParam.dis_curr/100,'f',2)); QString pretime = QString("%1:%2").arg(testParam.disParam.dis_time/60,2,10,QChar('0')).arg(testParam.disParam.dis_time%60,2,10,QChar('0')); ui->ledit_distime->setText(pretime); ui->ledit_disvollow->setText(QString::number((float)testParam.disParam.sum_vol_low/100,'f',2)); ui->ledit_discap->setText(QString::number((float)testParam.disParam.dis_cap/100,'f',2)); ui->ledit_cellvollow->setText(QString::number((float)testParam.disParam.cell_vol_low/1000,'f',3)); ui->ledit_dissoc->setText(QString::number((float)testParam.disParam.dis_soc/10,'f',1)); ui->ledit_chgcurr->setText(QString::number((float)testParam.chgParam.chg_curr/100,'f',2)); pretime = QString("%1:%2").arg(testParam.chgParam.chg_time/60,2,10,QChar('0')).arg(testParam.chgParam.chg_time%60,2,10,QChar('0')); ui->ledit_chgtime->setText(pretime); ui->ledit_chgvolhigh->setText(QString::number((float)testParam.chgParam.sum_vol_high/100,'f',2)); ui->ledit_chgcap->setText(QString::number((float)testParam.chgParam.chg_cap/100,'f',2)); ui->ledit_cellvolhigh->setText(QString::number((float)testParam.chgParam.cell_vol_high/1000,'f',3)); ui->ledit_chgsoc->setText(QString::number((float)testParam.chgParam.chg_soc/10,'f',1)); } void Param_Page::getTestParamValue() { if(ui->comboBox_testtype->currentIndex() == 0){ testParam.test_type = TestTypeDischarge; } else{ testParam.test_type = TestTypeCharge; } if(ui->comboBox_constvol->currentIndex() == 0){ testParam.constvol_EN = 0; } else{ testParam.constvol_EN = 1; } testParam.cell_vol_diff = ui->ledit_celldiffvol->text().toInt(); testParam.temp_high = ui->ledit_temphigh->text().toDouble()*10; testParam.curr_end = ui->ledit_stopcurr->text().toDouble()*100; testParam.disParam.dis_curr = ui->ledit_discurr->text().toDouble()*100; int hh = ui->ledit_distime->text().section(":",0,0).toInt(); int mm = ui->ledit_distime->text().section(":",1,1).toInt(); testParam.disParam.dis_time = hh*60+mm; testParam.disParam.sum_vol_low = ui->ledit_disvollow->text().toDouble()*100; testParam.disParam.dis_cap = ui->ledit_discap->text().toDouble()*100; testParam.disParam.cell_vol_low = ui->ledit_cellvollow->text().toDouble()*1000; testParam.disParam.dis_soc = ui->ledit_dissoc->text().toDouble()*10; testParam.chgParam.chg_curr = ui->ledit_chgcurr->text().toDouble()*100; hh = ui->ledit_chgtime->text().section(":",0,0).toInt(); mm = ui->ledit_chgtime->text().section(":",1,1).toInt(); testParam.chgParam.chg_time = hh*60+mm; testParam.chgParam.sum_vol_high = ui->ledit_chgvolhigh->text().toDouble()*100; testParam.chgParam.chg_cap = ui->ledit_chgcap->text().toDouble()*100; testParam.chgParam.cell_vol_high = ui->ledit_cellvolhigh->text().toDouble()*1000; testParam.chgParam.chg_soc = ui->ledit_chgsoc->text().toDouble()*10; } void Param_Page::SystemTime(void) { checkIcon(); QDateTime time = QDateTime::currentDateTime();//获取系统现在的时间 QString str = time.toString("yyyy-MM-dd hh:mm:ss"); //设置显示格式 ui->label_Time->setText(str); if(1 == workThread->remoteState.to_workpage){ closeParamPage(); } } void Param_Page::checkIcon() { if(workThread->iconState.usbState) ui->label_USB->setPixmap(QPixmap(":new/prefix1/usb.png")); else ui->label_USB->setPixmap(QPixmap("")); } void Param_Page::buttonReleasedAction() { QPushButton *pb = dynamic_cast(sender()); if(ui->pushButton_Exit == pb) { closeParamPage(); } else if(ui->pushButton_cancel == pb){ testParam = workThread->testParam; paramEdited = false; paramValueShow(); buttonStateShow(); } else if(ui->pushButton_save == pb){ getTestParamValue(); workThread->saveTestParam(testParam); //workThread->setWorkThreadCMD(workThread->CMD_SetTestParam); paramEdited = false; paramValueShow(); buttonStateShow(); } } void Param_Page::ComboBoxTestTypeAct(int idex) { if( (0==idex && testParam.test_type==TestTypeCharge) ||(1==idex && testParam.test_type==TestTypeDischarge) ){ paramEdited = true; buttonStateShow(); } ui->tabWidget->setCurrentIndex(idex); } void Param_Page::ComboBoxConVolAct(int idex) { if( (0==idex && testParam.constvol_EN==1) ||(1==idex && testParam.constvol_EN==0) ){ paramEdited = true; buttonStateShow(); } } void Param_Page::leditClickAction() { Custom_LineEdit *le = dynamic_cast(sender()); if(ui->ledit_celldiffvol == le){ setEditInput(le,ui->label_celldiffvol,0,3000,0); } else if(ui->ledit_temphigh == le){ setEditInput(le,ui->label_temphigh,0,100,1); } else if(ui->ledit_stopcurr == le) { setEditInput(le,ui->label_stopcurr,0,(CURRENT_MAX+0.2),2); } else if(ui->ledit_discurr == le) { setEditInput(le,ui->label_discurr,0,(CURRENT_MAX+0.2),2); } else if(ui->ledit_distime == le) { setTimeInput(le,ui->label_disctime); } else if(ui->ledit_disvollow == le) { setEditInput(le,ui->label_disvollow,0,(VOLTAGE_MAX+0.2),2); } else if(ui->ledit_discap == le) { setEditInput(le,ui->label_discap,0,50,2); } else if(ui->ledit_cellvollow == le) { setEditInput(le,ui->label_discellvollow,0,5,3); } else if(ui->ledit_dissoc == le) { setEditInput(le,ui->label_dissoc,0,100,1); } else if(ui->ledit_chgcurr == le) { setEditInput(le,ui->label_chgcurr,0,(CURRENT_MAX+0.2),2); } else if(ui->ledit_chgtime == le) { setTimeInput(le,ui->label_chgctime); } else if(ui->ledit_chgvolhigh == le) { setEditInput(le,ui->label_chgvolhigh,0,(VOLTAGE_MAX+0.2),2); } else if(ui->ledit_chgcap == le) { setEditInput(le,ui->label_chgcap,0,50,2); } else if(ui->ledit_cellvolhigh == le) { setEditInput(le,ui->label_cellvolhigh,0,5,3); } else if(ui->ledit_chgsoc == le) { setEditInput(le,ui->label_chgsoc,0,100,1); } buttonStateShow(); } void Param_Page::setEditInput(Custom_LineEdit *edit, QLabel *lable, float min, float max, int floatNum) { QString origcolor = edit->styleSheet(); edit->setStyleSheet("color:red"); // KeyBoard_Num *keyboard = new KeyBoard_Num(this, INPUT_DATA, lable->text()); // keyboard->execKeyboard(); KeyBoard_Num keyboard(this, INPUT_DATA, lable->text()); keyboard.execKeyboard(); DATA_KB_RTN kbdata = keyboard.get_kb_data(); if(kbdata.If_OK) { float input = kbdata.set_text.toFloat(); if(input>=min && input<=max) { edit->setText(QString::number(input,'f',floatNum)); paramEdited = true; } else edit->setStyleSheet(origcolor); } else edit->setStyleSheet(origcolor); } void Param_Page::setTimeInput(Custom_LineEdit *edit, QLabel *lable) { QString origcolor = edit->styleSheet(); edit->setStyleSheet("color:red"); // KeyBoard_Num *keyboard = new KeyBoard_Num(this, INPUT_TIME, lable->text()); // keyboard->execKeyboard(); KeyBoard_Num keyboard(this, INPUT_TIME, lable->text()); keyboard.execKeyboard(); DATA_KB_RTN kbdata = keyboard.get_kb_data(); if(kbdata.If_OK) { QString data = kbdata.set_text; if(checkTimeText(data)) { edit->setText(QString("%1:%2") .arg(data.section(":",0,0).trimmed(). toInt(),2,10,QChar('0')) .arg(data.section(":",1,1).trimmed(). toInt(),2,10,QChar('0'))); paramEdited = true; } else edit->setStyleSheet(origcolor); } else edit->setStyleSheet(origcolor); } bool Param_Page::checkTimeText(QString &time) { if(time.length()<3) return false; if(time.contains(QRegExp("[.-]"))) return false; QString hour = time.section(":",0,0).trimmed(); QString minute = time.section(":",1,1).trimmed(); int ih = hour.toInt(); int im = minute.toInt(); if(ih<0 || ih>99) return false; if(im<0 || im>59) return false; int minsum = ih*60+im; if(minsum > 14400) return false; return true; }