forked from shamsuzzamansadi/libraryBird
/
newbook.cpp
152 lines (131 loc) · 2.48 KB
/
newbook.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
#include "newbook.h"
#include "ui_newbook.h"
NewBook::NewBook(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewBook)
{
ui->setupUi(this);
}
NewBook::~NewBook()
{
delete ui;
}
void NewBook::setName(const QString n)
{
ui->nameEdit->setText(n);
}
QString NewBook::name() const
{
return ui->nameEdit->text();
}
void NewBook::resetName()
{
setName("");
};
void NewBook::setAuthor(const QString a)
{
ui->authorEdit->setText(a);
}
QString NewBook::author() const
{
return ui->authorEdit->text();
}
void NewBook::resetAuthor()
{
setAuthor(tr(""));
}
void NewBook::setIsbn(const QString i)
{
ui->isbnEdit->setText(i);
}
QString NewBook::isbn() const
{
return ui->isbnEdit->text();
}
void NewBook::resetIsbn()
{
setIsbn(tr(""));
}
void NewBook::setQuantity(const QString q)
{
ui->quantityEdit->setText(q);
}
QString NewBook::quantity() const
{
return ui->quantityEdit->text();
}
void NewBook::resetQuantity()
{
setQuantity(tr(""));
}
void NewBook::setAvailable(const QString a)
{
ui->availableEdit->setText(a);
}
QString NewBook::available() const
{
return ui->availableEdit->text();
}
void NewBook::resetAvailable()
{
setAvailable(tr(""));
}
void NewBook::setStudentid(const QString s)
{
ui->studentidEdit->setText(s);
}
QString NewBook::studentid() const
{
return ui->studentidEdit->text();
}
void NewBook::resetStudentid()
{
setStudentid(tr(""));
}
void NewBook::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void NewBook::done(int r)
{
if(QDialog::Accepted == r) // ok was pressed
{
if(ui->quantityEdit->text().toInt() > 0) // validate the data somehow
{
QDialog::done(r);
return;
}
else
{
QMessageBox msgBox;
msgBox.setText("Invalid Quantity, must be a positive integer");
msgBox.exec();
return;
}
}
else // cancel, close or exc was pressed
{
QDialog::done(r);
return;
}
}
void NewBook::on_buttonBox_accepted()
{
setName(ui->nameEdit->text());
setAuthor(ui->authorEdit->text());
setIsbn(ui->isbnEdit->text());
setQuantity(ui->quantityEdit->text());
setAvailable(ui->availableEdit->text());
setStudentid(ui->studentidEdit->text());
}
void NewBook::on_buttonBox_rejected()
{
close;
}