OfficeAssistant_Win10/OfficeAssistant_msvc/addcategory.cpp

74 lines
2.2 KiB
C++
Raw Normal View History

2023-08-13 12:16:22 +08:00
#include "addcategory.h"
#include <QString>
AddCategory::AddCategory(QWidget* parent)
: QDialog(parent)
{
ui.setupUi(this);
setWindowFlags(Qt::WindowCloseButtonHint);
setFixedSize(900, 600);
//connect(ui.submit, &QPushButton::click, this, &AddCategory::submit);
QStringList title;
ui.tableWidget->setColumnCount(3);
title << QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") << QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ") << QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
ui.tableWidget->setHorizontalHeaderLabels(title);
2023-08-15 11:17:09 +08:00
sqlite_helper.get_category(categrories,false);
2023-08-13 12:16:22 +08:00
ui.tableWidget->setRowCount(categrories.count());
int i = 0;
for(auto category : categrories)
{
ui.tableWidget->setItem(i, 0, new QTableWidgetItem(category.name));
if(category.id==1&&category.id==8)
{
ui.tableWidget->item(i, 0)->setFlags(ui.tableWidget->item(i, 0)->flags() & (~Qt::ItemIsEditable));
}
QComboBox* combo_box = new QComboBox;
combo_box->addItem(QString::fromLocal8Bit("<EFBFBD><EFBFBD>ʾ"), true);
combo_box->addItem(QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ"), false);
if(category.display==true)
{
combo_box->setCurrentIndex(0);
}else
{
combo_box->setCurrentIndex(1);
}
ui.tableWidget->setCellWidget(i, 1, combo_box);
ui.tableWidget->setItem(i, 2, new QTableWidgetItem(QString::number(category.sort)));
combo_boxes << combo_box;
i++;
}
//submit_btn = new QPushButton(QString::fromLocal8Bit("<22>ύ"));
connect(ui.submit, &QPushButton::clicked, this, &AddCategory::submit);
}
AddCategory::~AddCategory()
{
for(auto combo_box : combo_boxes)
{
delete combo_box;
}
}
void AddCategory::submit()
{
int num = categrories.count();
QList<Categrory> categrories_new;
int i=0;
for(Categrory categrory:categrories)
{
categrory.name = ui.tableWidget->item(i, 0)->text();
QComboBox * combox =(QComboBox *)ui.tableWidget->cellWidget(i, 1);
categrory.display = combox->currentData().toBool();
bool ok;
categrory.sort = ui.tableWidget->item(i, 2)->text().toInt(&ok, 10);
if(!ok)
{
QMessageBox::critical(this, QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"), QString::fromLocal8Bit("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>в<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
return;
}
categrories_new << categrory;
i++;
}
categrories.clear();
categrories = categrories_new;
changed = true;
close();
}