-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.cpp
More file actions
99 lines (75 loc) · 3.21 KB
/
window.cpp
File metadata and controls
99 lines (75 loc) · 3.21 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
//
// Created by User on 7/12/2023.
//
#include "window.h"
#include <QMessageBox>
Window::Window(Session &session, Department department, QWidget *parent) : session{session}, department(department), QWidget(parent) {
this->session.registerObserver(this);
this->setWindowTitle(QString::fromStdString(department.getName()));
auto *layout = new QVBoxLayout;
this->description = new QLabel(QString::fromStdString("Description: " + department.getDescription()));
layout->addWidget(this->description);
auto *layoutLists = new QHBoxLayout();
this->volunteersList = new QListWidget();
layoutLists->addWidget(this->volunteersList);
this->unassignedVolunteers = new QListWidget();
layoutLists->addWidget(this->unassignedVolunteers);
auto *layoutVolunteer = new QHBoxLayout();
this->volunteerNameLabel = new QLabel("Name");
layoutVolunteer->addWidget(this->volunteerNameLabel);
this->volunteerName = new QLineEdit();
layoutVolunteer->addWidget(this->volunteerName);
this->volunteerEmailLabel = new QLabel("Email");
layoutVolunteer->addWidget(this->volunteerEmailLabel);
this->volunteerEmail = new QLineEdit();
layoutVolunteer->addWidget(this->volunteerEmail);
this->volunteerInterestsLabel = new QLabel("Interests");
layoutVolunteer->addWidget(this->volunteerInterestsLabel);
this->volunteerInterests = new QLineEdit();
layoutVolunteer->addWidget(this->volunteerInterests);
this->addVolunteer = new QPushButton("Add");
layoutVolunteer->addWidget(this->addVolunteer);
layout->addLayout(layoutLists);
layout->addLayout(layoutVolunteer);
this->assignVolunteer = new QPushButton("Assign");
layout->addWidget(this->assignVolunteer);
this->setLayout(layout);
this->update();
QObject::connect(this->addVolunteer, &QPushButton::clicked, this, &Window::addVol);
QObject::connect(this->assignVolunteer, &QPushButton::clicked, this, &Window::assignVol);
}
void Window::update() {
this->volunteersList->clear();
for (auto vol : this->session.getVolunteersFromDepartment(this->department.getName()))
this->volunteersList->addItem(QString::fromStdString(vol));
this->unassignedVolunteers->clear();
for (auto vol : this->session.getUnassigned())
this->unassignedVolunteers->addItem(QString::fromStdString(vol));
}
void Window::addVol() {
auto name = this->volunteerName->text().toStdString();
auto email = this->volunteerEmail->text().toStdString();
auto interests = this->volunteerInterests->text().toStdString();
try {
this->session.addVolunteer(name, email, interests, "Unassigned");
this->volunteerName->clear();
this->volunteerEmail->clear();
this->volunteerInterests->clear();
}
catch (const std::exception& e)
{
QMessageBox::critical(this, "Error", e.what());
}
}
void Window::assignVol() {
if (this->unassignedVolunteers->selectedItems().empty())
return;
string key = this->unassignedVolunteers->currentItem()->text().toStdString();
try {
this->session.assignVolunteer(key, this->department.getName());
}
catch (const std::exception& e)
{
QMessageBox::critical(this, "Error", e.what());
}
}