今天原本计划完成三个功能的,其中有一个是难点问题,但结果却大出所望。分析如下:
一、之前对功能设计不是很完善,在解决较为麻烦的问题之后,发现后续还要做密码验证,颜色标记等问题,所以没有预估好工作量
二、自己在大的表单一列的不同对象间,交替使用QDoubleSpinBox与QSpinBox,且都是new的其对象,下一个表单使用时要把前一个QDoubleSpinBox或QSpinBox对象干掉,但是思路不严紧,对于其初始化的位置及最后一个干掉的位置没有多想,导致出了很多状况,严重的拉慢了进度。
三、以后还是不能抱侥幸心理,增强逻辑性与严紧性,这样提高效率与正确率,做到善始自终。
PS:虽然局部代码看不出个什么,但还是拿出来,
void XXX::spinboxint(int fv) { QString strfv = QString::number(fv, 16); //判断map中是否已经有,如果有修改其值,如果没有插入 if (fvmapcell.contains(fvcurrentrow)) { fvmapcell[fvcurrentrow] = strfv; } else { fvmapcell.insert(fvcurrentrow,strfv); } } void XXX::spinboxdouble(double fvd) { QString strfv = QString::number(fvd,‘f‘, 4); //判断map中是否已经有,如果有修改其值,如果没有插入 if (fvmapcell.contains(fvcurrentrow)) { fvmapcell[fvcurrentrow] = strfv; } else { fvmapcell.insert(fvcurrentrow,strfv); } }
//如果spinbox_fv已经有过定义 就把之前的干掉 if (spinbox_fv != NULL) { spinbox_fv->disconnect(); delete spinbox_fv; spinbox_fv = NULL; //表单上显示修改结果 QTableWidgetItem *itemfvi = new QTableWidgetItem(fvmapcell[lastfvtablerow]); itemfvi->setTextAlignment(Qt::AlignCenter);//字体居中显示 itemfvi->setTextColor(QColor(255,0,0)); uitablefixvalue.tableWidget->setItem(lastfvtablerow,lastfvtablecloum,itemfvi); } else if (spinbox_fvd !=NULL) { spinbox_fvd->disconnect(); delete spinbox_fvd; spinbox_fvd = NULL; //表单上显示修改结果 QTableWidgetItem *itemfvd = new QTableWidgetItem(fvmapcell[lastfvtablerow]); itemfvd->setTextAlignment(Qt::AlignCenter);//字体居中显示 itemfvd->setTextColor(QColor(255,0,0)); uitablefixvalue.tableWidget->setItem(lastfvtablerow,lastfvtablecloum,itemfvd); } //判断当前行是整数行还是浮点行 if (typeItem.contains(chineseToString("整数"))) { spinbox_fv = new QSpinBox(this); spinbox_fv->setRange(minItem.toInt(&ok,10),maxItem.toInt(&ok,10)); spinbox_fv->setSingleStep(stepItem.toInt(&ok,10)); uitablefixvalue.tableWidget->setCellWidget(fvrow,fvclounm,spinbox_fv); connect(spinbox_fv,SIGNAL(valueChanged(int)),this,SLOT(spinboxint(int))); } else if(typeItem.contains(chineseToString("浮点"))) { spinbox_fvd = new QDoubleSpinBox(this); spinbox_fvd->setDecimals(4); spinbox_fvd->setRange(minItem.toDouble(&ok),maxItem.toDouble(&ok)); spinbox_fvd->setSingleStep(stepItem.toDouble(&ok)); uitablefixvalue.tableWidget->setCellWidget(fvrow,fvclounm,spinbox_fvd); connect(spinbox_fvd,SIGNAL(valueChanged(double)),this,SLOT(spinboxdouble(double))); } lastfvtablerow = fvrow; lastfvtablecloum = fvclounm;
void XXX::changeconstvalue() { //最后 退出有一个错误是不是这个原因 ? if (spinbox_fv != NULL) { spinbox_fv->disconnect(); delete spinbox_fv; spinbox_fv = NULL; //表单上显示修改结果 QTableWidgetItem *itemfvi = new QTableWidgetItem(fvmapcell[lastfvtablerow]); itemfvi->setTextAlignment(Qt::AlignCenter);//字体居中显示 itemfvi->setTextColor(QColor(255,0,0)); uitablefixvalue.tableWidget->setItem(lastfvtablerow,lastfvtablecloum,itemfvi); } else if (spinbox_fvd !=NULL) { spinbox_fvd->disconnect(); delete spinbox_fvd; spinbox_fvd = NULL; //表单上显示修改结果 QTableWidgetItem *itemfvd = new QTableWidgetItem(fvmapcell[lastfvtablerow]); itemfvd->setTextAlignment(Qt::AlignCenter);//字体居中显示 itemfvd->setTextColor(QColor(255,0,0)); uitablefixvalue.tableWidget->setItem(lastfvtablerow,lastfvtablecloum,itemfvd); } //加一个密码认证 fvconfirmWidget->show(); } void XXX::fvconfirmyes() { if(uifvconfirm.lineEdit->text().trimmed()== tr("admin") && uifvconfirm.lineEdit_2->text().trimmed()==tr("admin")) { QMessageBox:: StandardButton rb = QMessageBox:: question(NULL, QStringLiteral("提示"), QStringLiteral("确定修改定值?"), QMessageBox:: Yes | QMessageBox:: No, QMessageBox:: Yes) ; if(rb == QMessageBox:: Yes) { fvconfirmWidget->close(); //下发修改定值命令 QMap<int ,QString>::const_iterator i; for(i = fvmapcell.constBegin(); i != fvmapcell.constEnd();i++) { //使用时先判断test1不为空且与当前定值值不同才会下发 QString test1=i.value(); int test2 = i.key(); } //下发完清空map数据 QMap<int ,QString>::iterator ic; ic = fvmapcell.begin(); int num = fvmapcell.size()-1; while (num>0) { fvmapcell.erase(ic+num); num--; } fvmapcell[0]=""; //刷新界面 showconstvalue(); } uifvconfirm.lineEdit->clear(); uifvconfirm.lineEdit_2->clear(); } else { QMessageBox::warning(this,QStringLiteral("警告"),QStringLiteral("用户名或密码错误!"),QMessageBox::Yes); uifvconfirm.lineEdit->clear(); uifvconfirm.lineEdit_2->clear(); uifvconfirm.lineEdit->setFocus(); } } void monizhuzhan::fvconfirmcancel() { fvconfirmWidget->close(); }
时间: 2024-10-12 21:22:38