-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeleteRecordPage.cpp
153 lines (144 loc) · 4.91 KB
/
deleteRecordPage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "deleteRecordPage.h"
deleteRecordPage::deleteRecordPage(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
emit loadDatabase();
}
deleteRecordPage::~deleteRecordPage()
{}
void deleteRecordPage::loadDatabase() {
DatabaseAPI* dbAPI = new DatabaseAPI();
dbAPI->read_translation_data();
dbMemory *translationQuery = dbMemory::getInstance();
queryCopy = translationQuery->queryResult;
int rowNum = queryCopy.size();
for (int row = 0; row < rowNum;row++) {
ui.tableWidget->insertRow(ui.tableWidget->rowCount());
QString recognitionText = QString::fromStdString(queryCopy.at(row).at(4));
QString translationText = QString::fromStdString(queryCopy.at(row).at(5));
QTableWidgetItem *recognitionTableItem = new QTableWidgetItem(recognitionText);
QTableWidgetItem *translationTableItem = new QTableWidgetItem(translationText);
ui.tableWidget->setCellWidget(row, 0, generateCheckBox(1));
ui.tableWidget->setItem(row, 1, recognitionTableItem);
ui.tableWidget->setItem(row, 2, translationTableItem);
}
ui.tableWidget->horizontalHeader()->setStretchLastSection(true);
QHeaderView* headerView = ui.tableWidget->horizontalHeader();
headerView->setSectionResizeMode(0, QHeaderView::ResizeToContents);
dbAPI->read_recognition_data();
dbMemory* recognitionQuery = dbMemory::getInstance();
queryCopy = recognitionQuery->queryResult;
rowNum = queryCopy.size();
for (int row = 0; row < rowNum; row++) {
ui.tableWidget_2->insertRow(ui.tableWidget_2->rowCount());
QString recognitionText = QString::fromStdString(queryCopy.at(row).at(3));
QTableWidgetItem* recognitionTableItem = new QTableWidgetItem(recognitionText);
ui.tableWidget_2->setCellWidget(row, 0, generateCheckBox(0));
ui.tableWidget_2->setItem(row, 1, recognitionTableItem);
}
ui.tableWidget_2->horizontalHeader()->setStretchLastSection(true);
headerView = ui.tableWidget->horizontalHeader();
headerView->setSectionResizeMode(0, QHeaderView::ResizeToContents);
}
void deleteRecordPage::on_deleteButton_clicked()
{
if (ui.tabWidget->currentIndex() == 0) {
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Delete selected record", "Are you sure you want to delete the data?",
QMessageBox::Yes | QMessageBox::Cancel);
if (reply == QMessageBox::Yes) {
std::vector<int> IDs;
for (int x = 0; x < recognitionCheckBoxList.size(); x++) {
if (recognitionCheckBoxList.at(x)->isChecked()) {
IDs.push_back(x + 1);
}
}
DatabaseAPI* db = new DatabaseAPI();
db->delete_recognition_data(IDs);
this->close();
}
}
if (ui.tabWidget->currentIndex() == 1) {
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Delete selected record", "Are you sure you want to delete the data?",
QMessageBox::Yes | QMessageBox::Cancel);
if (reply == QMessageBox::Yes) {
std::vector<int> IDs;
for (int x = 0; x < translationCheckBoxList.size(); x++) {
if (translationCheckBoxList.at(x)->isChecked()) {
IDs.push_back(x + 1);
}
}
DatabaseAPI* db = new DatabaseAPI();
db->delete_translation_data(IDs);
this->close();
}
}
}
void deleteRecordPage::on_deleteAllButton_clicked()
{
if (ui.tabWidget->currentIndex() == 0) {
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Delete all record", "Are you sure you want to delete all data?",
QMessageBox::Yes | QMessageBox::Cancel);
if (reply == QMessageBox::Yes) {
std::vector<int> IDs;
for (int x = 0; x < recognitionCheckBoxList.size(); x++) {
IDs.push_back(x + 1);
}
DatabaseAPI* db = new DatabaseAPI();
db->delete_recognition_data(IDs);
this->close();
}
}
if (ui.tabWidget->currentIndex() == 1) {
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Delete all record", "Are you sure you want to delete all data?",
QMessageBox::Yes | QMessageBox::Cancel);
if (reply == QMessageBox::Yes) {
std::vector<int> IDs;
for (int x = 0; x < translationCheckBoxList.size(); x++) {
IDs.push_back(x + 1);
}
DatabaseAPI* db = new DatabaseAPI();
db->delete_translation_data(IDs);
this->close();
}
}
}
void deleteRecordPage::checkBoxClicked()
{
bool flag = false;
for (int x = 0; x < recognitionCheckBoxList.size(); x++) {
if (recognitionCheckBoxList.at(x)->isChecked()) {
flag = true;
}
}
for (int x = 0; x < translationCheckBoxList.size(); x++) {
if (translationCheckBoxList.at(x)->isChecked()) {
flag = true;
}
}
if (flag) {
ui.deleteButton->setEnabled(true);
}
else {
ui.deleteButton->setEnabled(false);
}
}
QCheckBox* deleteRecordPage::generateCheckBox(int mode)
{
if (mode == 0) {
QCheckBox* checkBox = new QCheckBox();
connect(checkBox, SIGNAL(clicked()), this, SLOT(checkBoxClicked()));
recognitionCheckBoxList.push_back(checkBox);
return checkBox;
}
else {
QCheckBox* checkBox = new QCheckBox();
connect(checkBox, SIGNAL(clicked()), this, SLOT(checkBoxClicked()));
translationCheckBoxList.push_back(checkBox);
return checkBox;
}
}