#include "checkmethodmanage.h" #include "ui_checkmethodmanage.h" #include "newcheckmethod.h" #include <QMessageBox> CheckMethodManage::CheckMethodManage(QWidget *parent) : QWidget(parent), ui(new Ui::CheckMethodManage) { ui->setupUi(this); ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 for(int i=1;i<5;i++) ui->tableWidget_2->horizontalHeader()->setSectionResizeMode(i,QHeaderView::Stretch); ui->tableWidget_2->setColumnWidth(0, 60); ui->tableWidget_2->setColumnWidth(5, 200); getCheckMethod(); } CheckMethodManage::~CheckMethodManage() { programList.clear(); delete ui; } void CheckMethodManage::showNewMethod() { NewCheckMethod* checkWindow = new NewCheckMethod; checkWindow->setWindowState(Qt::WindowMaximized); checkWindow->setWindowModality(Qt::ApplicationModal); checkWindow->show(); } void CheckMethodManage::on_editButton_clicked() { QPushButton *pushButton_ = dynamic_cast<QPushButton*>(this->sender()); if(NULL == pushButton_) { return; } // 获取按钮的x坐标和y坐标 int x = pushButton_->parentWidget()->frameGeometry().x(); int y = pushButton_->parentWidget()->frameGeometry().y(); // 根据按钮的x和y坐标来定位对应的单元格 QModelIndex index = ui->tableWidget_2->indexAt(QPoint(x, y)); // 获取该按钮所在表格的行号和列号 int row = index.row(); //int column = index.column(); QString sId = programList[row].id; NewCheckMethod* checkWindow = new NewCheckMethod(nullptr,sId); checkWindow->setWindowState(Qt::WindowMaximized); checkWindow->setWindowModality(Qt::ApplicationModal); checkWindow->show(); checkWindow->getMethodInfo(); } void CheckMethodManage::on_deleteButton_clicked() { QPushButton *pushButton_ = dynamic_cast<QPushButton*>(this->sender()); if(NULL == pushButton_) { return; } // 获取按钮的x坐标和y坐标 int x = pushButton_->parentWidget()->frameGeometry().x(); int y = pushButton_->parentWidget()->frameGeometry().y(); // 根据按钮的x和y坐标来定位对应的单元格 QModelIndex index = ui->tableWidget_2->indexAt(QPoint(x, y)); // 获取该按钮所在表格的行号和列号 int row = index.row(); //int column = index.column(); if(QMessageBox::question(this, "确认", "确认删除吗?", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes)==QMessageBox::Yes) { if(BaseCommonApi::DeleteVerificationProgramInfo(programList[row].id)) { programList.removeAt(row); ui->tableWidget_2->removeRow(row); } } } void CheckMethodManage::getCheckMethod() { programList = BaseCommonApi::getVerificationProgramInfoMain(); int rowCount = 0; int row=0; for (const VerificationProgramInfo& program : programList) { rowCount = ui->tableWidget_2->rowCount(); ui->tableWidget_2->insertRow(rowCount); ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); //ui->tableWidget->setItem(row, 0, new QTableWidgetItem(dept.id)); ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(program.program_name)); //设置数据 ui->tableWidget_2->setItem(row, 2, new QTableWidgetItem(program.create_name)); //设置数据 ui->tableWidget_2->setItem(row, 3, new QTableWidgetItem(program.create_time.toString())); //设置数据 ui->tableWidget_2->setItem(row, 4, new QTableWidgetItem(program.remark)); //设置数据 QPushButton *btn_1 = new QPushButton(); btn_1->setText(tr("编辑")); btn_1->setStyleSheet("QPushButton{" "background-color:rgba(255,255,255,0);" "color:rgba(92,170,54,100);" "text-decoration:underline;" "}"); btn_1->setCursor(Qt::PointingHandCursor); connect(btn_1,SIGNAL(clicked()),this,SLOT(on_editButton_clicked())); btn_1->setIconSize(QSize(16,16)); btn_1->setIcon(QIcon(":/image/Index/u2324.svg")); QPushButton *btn_2 = new QPushButton(); btn_2->setText(tr("删除")); btn_2->setStyleSheet("QPushButton{" "background-color:rgba(255,255,255,0);" "color:rgba(170,17,17,100);" "text-decoration:underline;" "}"); btn_2->setCursor(Qt::PointingHandCursor); connect(btn_2,SIGNAL(clicked()),this,SLOT(on_deleteButton_clicked())); btn_2->setIconSize(QSize(16,16)); btn_2->setIcon(QIcon(":/image/Index/u2325.svg")); QWidget *tmp_widget = new QWidget(); QHBoxLayout *tmp_layout = new QHBoxLayout(tmp_widget); tmp_layout->addWidget(btn_1); tmp_layout->addWidget(btn_2); tmp_layout->setMargin(0); ui->tableWidget_2->setCellWidget(row,5,tmp_widget); row++; } }