-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchoosegradeswindow.cpp
58 lines (49 loc) · 1.92 KB
/
choosegradeswindow.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
#include "choosegradeswindow.h"
#include "ui_choosegradeswindow.h"
chooseGradesWindow::chooseGradesWindow(QWidget *parent) : QDialog(parent), ui(new Ui::chooseGradesWindow), gradeCategoriesModel(new QStringListModel)
{
ui->setupUi(this);
this->setWindowTitle("Enter Categories");
ui->gradesList->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->gradesList->setModel(gradeCategoriesModel);
gradeCategoriesModel->setStringList(gradesStringList);
}
chooseGradesWindow::~chooseGradesWindow()
{
delete ui;
delete gradeCategoriesModel;
}
void chooseGradesWindow::on_addButton_clicked()
{
QString userInputText = ui->inputText->text();
if (userInputText != "") {
if(gradesStringList.contains(userInputText)) {
QMessageBox::critical(this, "Error", "Cannot enter duplicate categories. \n\"" + userInputText + "\"" + " is already a category.");
} else if(gradesStringList.size() >= 20) {
QMessageBox::critical(this, "Error", "Cannot enter 20 or more categories.\nDelete categories to make space.");
} else {
gradesStringList.append(ui->inputText->text());
gradeCategoriesModel->setStringList(gradesStringList);
}
ui->inputText->clear();
}
}
void chooseGradesWindow::on_deleteButton_clicked()
{
QModelIndex currentSelection;
currentSelection = ui->gradesList->currentIndex();
if (currentSelection.row() >= 0 && currentSelection.row() < gradesStringList.size()) {
gradesStringList.removeAt(currentSelection.row());
gradeCategoriesModel->setStringList(gradesStringList);
}
}
void chooseGradesWindow::on_doneButton_clicked()
{
if (gradesStringList.size() <= 1) {
QMessageBox::information(this, "Error", "Must insert at least two grade categories");
} else {
close();
chooseWeightsWindow = new ChooseWeights(gradesStringList);
chooseWeightsWindow->show();
}
}