-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdatedialog.cpp
149 lines (125 loc) · 4.6 KB
/
updatedialog.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
#include "updatedialog.h"
#include "ui_updatedialog.h"
#include "Validation.h"
#include <QMessageBox>
UpdateDialog::UpdateDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::UpdateDialog)
{
ui->setupUi(this);
}
UpdateDialog::~UpdateDialog()
{
delete ui;
}
void UpdateDialog::setUpdateCtrl(Controller& c){
this->ctrl = c;
}
void UpdateDialog::on_cancelBtn_clicked()
{
this->close();
}
void UpdateDialog::on_comboBox_currentIndexChanged(const QString &arg1)
{
if (ui->comboBox->currentText() == "New Title" || ui->comboBox->currentText() == "New Genre" || ui->comboBox->currentText() == "New Year") {
ui->customLabel->setText(ui->comboBox->currentText());
ui->customLabel->setVisible(true);
ui->customEdit->setVisible(true);
}
else {
ui->customLabel->setVisible(false);
ui->customEdit->setVisible(false);
}
}
void UpdateDialog::on_titleEdit_textChanged(const QString &arg1)
{
ui->label_4->setStyleSheet("color: green;");
ui->label_7->setStyleSheet("color: red;");
if(ui->titleEdit->text().isEmpty()) {
ui->label_7->setVisible(true);
ui->label_4->setVisible(false);
}
else {
ui->label_4->setVisible(true);
ui->label_7->setVisible(false);
}
}
void UpdateDialog::on_yearEdit_textChanged(const QString &arg1)
{
ui->label_6->setStyleSheet("color: green;");
ui->label_9->setStyleSheet("color: red;");
if(ui->yearEdit->text().isEmpty() || Validation::validateYear(ui->yearEdit->text().toStdString()) == -1 || Validation::validateYear(ui->yearEdit->text().toStdString()) == -2) {
ui->label_9->setVisible(true);
ui->label_6->setVisible(false);
}
else {
ui->label_6->setVisible(true);
ui->label_9->setVisible(false);
}
}
void UpdateDialog::on_customEdit_textChanged(const QString &arg1)
{
if (ui->comboBox->currentText() == "New Title") {
ui->label_5->setStyleSheet("color: green;");
ui->label_8->setStyleSheet("color: red;");
if(ui->customEdit->text().isEmpty()) {
ui->label_8->setVisible(true);
ui->label_5->setVisible(false);
}
else {
ui->label_5->setVisible(true);
ui->label_8->setVisible(false);
}
}
else if (ui->comboBox->currentText() == "New Genre") {
ui->label_5->setStyleSheet("color: green;");
ui->label_8->setStyleSheet("color: red;");
if(ui->customEdit->text().isEmpty()) {
ui->label_8->setVisible(true);
ui->label_5->setVisible(false);
}
else {
ui->label_5->setVisible(true);
ui->label_8->setVisible(false);
}
}
else if (ui->comboBox->currentText() == "New Year") {
ui->label_5->setStyleSheet("color: green;");
ui->label_8->setStyleSheet("color: red;");
if(ui->customEdit->text().isEmpty() || Validation::validateYear(ui->customEdit->text().toStdString()) == -1 || Validation::validateYear(ui->customEdit->text().toStdString()) == -2) {
ui->label_8->setVisible(true);
ui->label_5->setVisible(false);
}
else {
ui->label_5->setVisible(true);
ui->label_8->setVisible(false);
}
}
}
void UpdateDialog::on_addBtn_clicked()
{
QString title = ui->titleEdit->text();
QString year = ui->yearEdit->text();
if (ui->titleEdit->text().isEmpty() || ui->customEdit->text().isEmpty() || ui->yearEdit->text().isEmpty() || Validation::validateYear(year.toStdString()) == -1 || Validation::validateYear(year.toStdString()) == -2)
QMessageBox::warning(this, "UPDATE", "Can't update any film!");
else {
int exists = ctrl.getRepo().findFilm(ctrl.getRepo().findByID(title.toStdString(), Validation::validateYear(year.toStdString())));
if (exists == -1)
QMessageBox::warning(this, "UPDATE", "The film wasn't found!");
else {
if (ui->comboBox->currentText() == "New Title") {
QString newTitle = ui->customEdit->text();
ctrl.updateFilmFromRepo(exists, newTitle.toStdString());
}
else if (ui->comboBox->currentText() == "New Genre") {
QString newGenre = ui->customEdit->text();
ctrl.updateFilmFromRepo(exists, "", newGenre.toStdString());
}
else if (ui->comboBox->currentText() == "New Year") {
QString newYear = ui->customEdit->text();
ctrl.updateFilmFromRepo(exists, "", "", Validation::validateYear(newYear.toStdString()));
}
}
}
this->close();
}