-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcourseeditor.cpp
More file actions
159 lines (137 loc) · 4.76 KB
/
Copy pathcourseeditor.cpp
File metadata and controls
159 lines (137 loc) · 4.76 KB
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
154
155
156
157
158
159
#include "courseeditor.h"
#include "ui_courseeditor.h"
#include <QMessageBox>
#include "sessionactivation.h"
#include "sessionhandler.h"
#include "searchteacher.h"
CourseEditor::CourseEditor(QWidget *parent, School* schoolptr , Course* courseptr)
: QDialog(parent)
, ui(new Ui::CourseEditor)
,school(schoolptr)
,course(courseptr)
{
school->loadTeacherAttendance(course);
school->loadStudentAttendance(course);
ui->setupUi(this);
ui->CourseNameEdit->setText(course->getCourseName());
ui->CourseIDedit->setText(QString::number(course->getID()));
ui->Semesteredit->setText(QString::number(course->getsemester()));
ui->Coefedit->setText(QString::number(course->getCoef()));
for ( auto teacher : course->getCourseTeacher())
{
QListWidgetItem* item = new QListWidgetItem(teacher->getName() + " ("+QString::number(teacher->getID()) +")");
item->setSizeHint(QSize(10, 20));
ui->TeacherListWidget->addItem(item);
}
}
CourseEditor::~CourseEditor()
{
school->EmptyCourseTeachersAttendance(course);
delete ui;
}
void CourseEditor::on_DeleteCourseButton_clicked()
{
QMessageBox::StandardButton confirm = QMessageBox::question(
this, "Confirm Deletion",
QString("Are you sure you want to delete the following Course : '%1'?").arg(course->getCourseName()),
QMessageBox::Yes | QMessageBox::No
);
if (confirm == QMessageBox::Yes) {
qDebug()<<" You are Here !! 1";
school->deleteCourseDefinitively(course); // Implement this function to delete the group from the data structure or database
emit this->courseDeleted();
}
this->deleteLater();
}
void CourseEditor::on_LectureButton_clicked()
{
if( !course->hasLecture())
{
QMessageBox::information(this,"NO Lecture !! ","this Course Has No Lectures");
}
else
{
SessionHandler* session = new SessionHandler(this,school,course,SessionType::Lecture);
session->show();
}
}
void CourseEditor::on_TutorialButton_clicked()
{
if( !course->hasTutorial())
{
QMessageBox::information(this,"NO Tutorial !! ","this Course Has No Tutorials");
}
else
{
SessionHandler* session = new SessionHandler(this,school,course,SessionType::Tutorial);
session->show();
}
}
void CourseEditor::on_LabButton_clicked()
{
if( !course->hasLab())
{
QMessageBox::information(this,"NO Lab !! ","this Course Has No Labs");
}
else
{
SessionHandler* session = new SessionHandler(this,school,course,SessionType::Lab);
session->show();
}
}
void CourseEditor::on_SessionActivation_clicked()
{
SessionActivation* activate = new SessionActivation(this,school,course);
activate->show();
}
void CourseEditor::on_AddTeacherToCourseButton_clicked()
{
SearchTeacher * AddTeacher = new SearchTeacher(this,school,course);
AddTeacher->show();
connect(AddTeacher,&SearchTeacher::AddedTeacherToCourse, this, [this](Teacher * teacher)
{
ui->TeacherListWidget->addItem(teacher->getName() + " (" + QString::number(teacher->getID()) +")" );
});
}
void CourseEditor::on_RemoveTeacherFromCourse_clicked()
{
QMessageBox::StandardButton message = QMessageBox::question(this,"remove Teacher ?"," Would you like to remove the Selected Teachers from the Course Teachers ? ",QMessageBox::Yes | QMessageBox::No);
if ( message == QMessageBox::Yes)
{
QList<QListWidgetItem*> Items = ui->TeacherListWidget->selectedItems();
if( !Items.isEmpty())
{
Teacher* teacher;
for (auto item : Items)
{
teacher = school->findTeacherByName(item->text());
course->removeteacherFromCourse(teacher);
// this will empty the teacher Attendance before removing him from the Teachers of the Course
teacher->removeLabAttendance();
teacher->removeLectureAttendance();
teacher->removeTutorialAttendance();
course->removeCourseTeacherFromDatabase(teacher);
delete item;
}
}
}
}
void CourseEditor::on_SaveButton_clicked()
{
QString name = ui->CourseNameEdit->text();
bool semesterok (true);
bool coefok(true);
int semester = ui->Semesteredit->text().toInt(&semesterok);
int coef = ui->Coefedit->text().toInt(&coefok);
course->setCourseName(name);
emit this->CourseNameHasBeenChanged(name);
if ( semesterok)
{
course->setSemester(semester);
}
if( coefok )
{
course->setCoef(coef);
}
course->UpdateCourseinDatabase();
}