-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewCourses.cpp
More file actions
83 lines (79 loc) · 2.16 KB
/
ViewCourses.cpp
File metadata and controls
83 lines (79 loc) · 2.16 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
#include "ViewCourses.h"
#include "Course.h"
#include"database.h"
#include"qmessagebox.h"
ViewCourses::ViewCourses(Student* S,QWidget* parent)
: QWidget(parent)
{
stud = S;
c=nullptr;
ui.setupUi(this);
ui.rgstrbtn->hide();
RadioButton_Clicked();
ui.lbl_Code->hide();
ui.lbl_Hours->hide();
ui.lbl_MaxNum->hide();
ui.lbl_Name->hide();
}
ViewCourses::~ViewCourses()
{
}
void ViewCourses::RadioButton_Clicked()
{
ui.rgstrbtn->hide();
ui.treeWidget->clear();
bool Fulltree = true;
vector<Course*> ToDisplay;
if(ui.rad_All->isChecked())
ToDisplay = Database::Courses;
else if (ui.rad_Finished->isChecked())
ToDisplay = stud->GetFinishedCourses();
else if (ui.rad_Progrss->isChecked())
{
ToDisplay = stud->GetCoursesInProgress();
Fulltree = false;
}
else if (ui.radAllowed->isChecked())
{
ui.rgstrbtn->show();
for (int i = 0; i < Database::Courses.size(); i++)
{
if (stud->CanTakeCourse(Database::Courses[i]))
ToDisplay.push_back(Database::Courses[i]);
}
}
auto itms = Course::CreateTree(ToDisplay,Fulltree);
for (int i = 0; i < itms.size(); i++)
ui.treeWidget->addTopLevelItem(itms[i]);
}
void ViewCourses::Widget_Item_Clicked(QTreeWidgetItem* item, int index)
{
if (ui.lbl_Code->isHidden())
{
ui.lbl_Code->show();
ui.lbl_Hours->show();
ui.lbl_MaxNum->show();
ui.lbl_Name->show();
}
c= Database::GetCourse(item->data(0,Qt::UserRole).toString().toStdString());
if (c == nullptr)
return;
ui.lbl_Name->setText("Course Name: \n"+QString::fromStdString(c->Name));
ui.lbl_Code->setText("Course Id: \n" + QString::fromStdString(c->Code));
ui.lbl_Hours->setText("Course MaxHourse: \n" + QString::number(c->Hours));
ui.lbl_MaxNum->setText("Course MaxNumOfStuds: \n" + QString::number(c->MaxNumOfStudents));
}
void ViewCourses::on_rgstrbtn_clicked()
{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Register Course", "Are you sure you wawnt to register for the selected course?", QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes)
{
if (c == nullptr)
return;
if (stud->CanTakeCourse(c))
stud->CoursesInProgress.push_back(c->Code);
ViewCourses::RadioButton_Clicked();
Database::Save();
}
}