forked from loaded02/ICF_Report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_showperson.cpp
152 lines (140 loc) · 4.87 KB
/
gui_showperson.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 "gui_showperson.h"
#include "ui_gui_showperson.h"
#include "gui_newperson.h"
#include <QMessageBox>
void GUI_ShowPerson::fillListView()
{
ui->listWidget->clear();
if (art == 'p') {
for (int i=0; i<icfcontroller->sizeOfPatients(); i++) {
Patient* actPerson = icfcontroller->getPatient(i);
new QListWidgetItem(QString::number(actPerson->getId()) + " " + actPerson->getName() + " " + actPerson->getSurname(),ui->listWidget);
}
} else if (art == 't') {
for (int i=0; i<icfcontroller->sizeOfTherapists(); i++) {
Therapist* actPerson = icfcontroller->getTherapist(i);
new QListWidgetItem(QString::number(actPerson->getId()) + " " + actPerson->getName() + " " + actPerson->getSurname(),ui->listWidget);
}
} else {
std::cerr << "Art ist weder p noch t" << std::endl;
}
}
GUI_ShowPerson::GUI_ShowPerson(ICFController *controller, char art, QWidget *parent) :
QDialog(parent),
ui(new Ui::GUI_ShowPerson),icfcontroller(controller),art(art){
ui->setupUi(this);
this->fillListView();
if (art == 'p') {
connect(ui->newButton,SIGNAL(clicked()),this,SLOT(onActionNew_Patient_clicked()));
} else if (art == 't') {
connect(ui->newButton,SIGNAL(clicked()),this,SLOT(onActionNew_Therapist_clicked()));
} else {
std::cerr << "Art ist weder p noch t" << std::endl;
}
}
GUI_ShowPerson::~GUI_ShowPerson()
{
delete ui;
}
void GUI_ShowPerson::onActionNew_Therapist_clicked()
{
GUI_NewPerson* therapist = new GUI_NewPerson(this);
therapist->therapistAppearance();
therapist->setWindowTitle("Add new Therapist");
if (therapist->exec())
this->addTherapist(therapist->getSurname(),therapist->getName(), therapist->getDiagnosis());
delete therapist;
}
void GUI_ShowPerson::onActionNew_Patient_clicked()
{
GUI_NewPerson* patient = new GUI_NewPerson(this);
if (patient->exec())
this->addPatient(patient->getSurname(),patient->getName(),patient->getDob(),patient->getDiagnosis());
delete patient;
}
void GUI_ShowPerson::on_listWidget_itemDoubleClicked(QListWidgetItem *item)
{
QStringList stringList = item->text().split(" ");
GUI_NewPerson* form = new GUI_NewPerson(this);
if (art == 't') {
if (Therapist* ther = icfcontroller->findTherapist(stringList[0].toInt())) {
form->therapistAppearance();
form->setWindowTitle("Edit Therapist");
form->setSurname(ther->getSurname());
form->setName(ther->getName());
form->setDiagnosis(ther->getCompany());
if (form->exec()) {
ther->setSurname(form->getSurname());
ther->setName(form->getName());
ther->setCompany(form->getDiagnosis());
}
}
}
else if (art == 'p') {
if (Patient* pat = icfcontroller->findPatient(stringList[0].toInt())) {
form->setSurname(pat->getSurname());
form->setName(pat->getName());
form->setDob(pat->getDob());
form->setDiagnosis(pat->getDiagnosis());
form->setWindowTitle("Edit Patient");
if (form->exec()) {
pat->setSurname(form->getSurname());
pat->setName(form->getName());
pat->setDob(form->getDob());
pat->setDiagnosis(form->getDiagnosis());
}
}
} else {
std::cerr << "Art ist weder p noch t" << std::endl;
}
this->fillListView();
}
void GUI_ShowPerson::on_closeButton_clicked()
{
this->close();
}
void GUI_ShowPerson::on_editButton_clicked()
{
QListWidgetItem* item = ui->listWidget->currentItem();
if (item)
this->on_listWidget_itemDoubleClicked(item);
}
void GUI_ShowPerson::on_removeButton_clicked()
{
QListWidgetItem* item = ui->listWidget->currentItem();
if (item) {
QStringList stringList = item->text().split(" ");
switch (art) {
case 't':
icfcontroller->removeTherapist(stringList[0].toInt());
break;
case 'p':
icfcontroller->removePatient(stringList[0].toInt());
break;
default:std::cerr << "Art ist weder Pat noch Ther" << std::endl;
break;
}
this->fillListView();
}
}
void GUI_ShowPerson::on_refreshButton_clicked()
{
this->fillListView();
}
void GUI_ShowPerson::addPatient(QString surname, QString name, QDate dob, QString diagnosis)
{
Patient* pat = new Patient(surname);
pat->setName(name);
pat->setDob(dob);
pat->setDiagnosis(diagnosis);
icfcontroller->addPatient(pat);
emit on_refreshButton_clicked();
}
void GUI_ShowPerson::addTherapist(QString surname, QString name, QString company)
{
Therapist* ther = new Therapist(surname);
ther->setName(name);
ther->setCompany(company);
icfcontroller->addTherapist(ther);
emit on_refreshButton_clicked();
}