-
Notifications
You must be signed in to change notification settings - Fork 0
/
problemspecsdialog.cpp
executable file
·152 lines (130 loc) · 5.88 KB
/
problemspecsdialog.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
/*
* This file is part of community judge client project developed by Shervin Kh.
* Copyright (C) 2014 Shervin Kh.
* License: GPLv3 Or Later
* Full license could be found in License file shipped with program or at http://www.gnu.org/licenses/
*/
#include "problemspecsdialog.h"
#include <limits>
#include <QtGui>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#endif
ProblemSpecsDialog::ProblemSpecsDialog(const Problem &prob, const QList<QString> &scps,
const QList<QString> &cons, QWidget *parent) :
QDialog(parent), cur(prob)
{
nameLabel = new QLabel("Name: ");
nameEdit = new QLineEdit;
nameLabel->setBuddy(nameEdit);
nameEdit->setText(prob.name());
connect(nameEdit, SIGNAL(textChanged(QString)), this, SLOT(validateForm()));
folderLabel = new QLabel("Folder: ");
folderEdit = new QLineEdit;
folderLabel->setBuddy(folderEdit);
folderEdit->setText(prob.folder());
connect(folderEdit, SIGNAL(textChanged(QString)), this, SLOT(validateForm()));
descLabel = new QLabel("Description: ");
descEdit = new QLineEdit;
descLabel->setBuddy(descEdit);
descEdit->setText(prob.description());
descFileLabel = new QLabel("Description File: ");
descFileEdit = new QLineEdit;
descFileLabel->setBuddy(descFileEdit);
descFileEdit->setText(prob.descriptionFile());
ntLabel = new QLabel("Num. Tests: ");
ntEdit = new QLineEdit;
ntLabel->setBuddy(ntEdit);
ntEdit->setText(QString::number(prob.numTests()));
ntEdit->setValidator(new QIntValidator(0, std::numeric_limits<int>::max()));
connect(ntEdit, SIGNAL(textChanged(QString)), this, SLOT(validateForm()));
tlLabel = new QLabel("Time Limit (ms): ");
tlEdit = new QLineEdit;
tlLabel->setBuddy(tlEdit);
tlEdit->setText(QString::number(prob.timeLimit()));
tlEdit->setValidator(new QIntValidator(0, std::numeric_limits<int>::max()));
connect(tlEdit, SIGNAL(textChanged(QString)), this, SLOT(validateForm()));
mlLabel = new QLabel("Memory Limit (KB): ");
mlEdit = new QLineEdit;
mlLabel->setBuddy(mlEdit);
mlEdit->setText(QString::number(prob.memoryLimit()));
mlEdit->setValidator(new QIntValidator(0, std::numeric_limits<int>::max()));
connect(mlEdit, SIGNAL(textChanged(QString)), this, SLOT(validateForm()));
scpLabel = new QLabel("Score Plan: ");
scpComboBox = new QComboBox;
scpLabel->setBuddy(scpComboBox);
scpComboBox->addItem("Select Score Plan...");
foreach (QString str, scps)
scpComboBox->addItem(str);
scpComboBox->setCurrentIndex(scps.indexOf(prob.scorePlan()) + 1);
connect(scpComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(validateForm()));
contestLabel = new QLabel("Contest: ");
contestComboBox = new QComboBox;
contestLabel->setBuddy(contestComboBox);
foreach (QString str, cons)
contestComboBox->addItem(str);
int idx = cons.indexOf(prob.contest());
contestComboBox->setCurrentIndex(idx == -1 ? 0 : idx);
pubsubLabel = new QLabel("View Public Submissions' Code: ");
pubsub = new QComboBox;
pubsub->addItem(viewCodePermissions[0]);
pubsub->addItem(viewCodePermissions[1]);
pubsub->addItem(viewCodePermissions[2]);
pubsub->setCurrentIndex(prob.publicSubmissions());
othsubLabel = new QLabel("View Other's Submissions' Code: ");
othsub = new QComboBox;
othsub->addItem(viewCodePermissions[0]);
othsub->addItem(viewCodePermissions[1]);
othsub->addItem(viewCodePermissions[2]);
othsub->setCurrentIndex(prob.othersSubmissions());
glayout = new QGridLayout;
glayout->addWidget(nameLabel, 0, 0);
glayout->addWidget(nameEdit, 0, 1);
glayout->addWidget(folderLabel, 1, 0);
glayout->addWidget(folderEdit, 1, 1);
glayout->addWidget(descLabel, 2, 0);
glayout->addWidget(descEdit, 2, 1);
glayout->addWidget(descFileLabel, 3, 0);
glayout->addWidget(descFileEdit, 3, 1);
glayout->addWidget(ntLabel, 4, 0);
glayout->addWidget(ntEdit, 4, 1);
glayout->addWidget(tlLabel, 5, 0);
glayout->addWidget(tlEdit, 5, 1);
glayout->addWidget(mlLabel, 6, 0);
glayout->addWidget(mlEdit, 6, 1);
glayout->addWidget(scpLabel, 7, 0);
glayout->addWidget(scpComboBox, 7, 1);
glayout->addWidget(contestLabel, 8, 0);
glayout->addWidget(contestComboBox, 8, 1);
glayout->addWidget(pubsubLabel, 9, 0);
glayout->addWidget(pubsub, 9, 1);
glayout->addWidget(othsubLabel, 10, 0);
glayout->addWidget(othsub, 10, 1);
completed = new QCheckBox("Complete Judge");
completed->setChecked(prob.isComplete());
enabled = new QCheckBox("Enabled");
enabled->setChecked(prob.isEnabled());
buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
totalLayout = new QVBoxLayout;
totalLayout->addLayout(glayout);
totalLayout->addWidget(completed);
totalLayout->addWidget(enabled);
totalLayout->addWidget(buttons);
setLayout(totalLayout);
validateForm();
}
Problem ProblemSpecsDialog::resultProblem() const
{
return Problem(cur.ID(), nameEdit->text(), descEdit->text(), ntEdit->text().toInt(), tlEdit->text().toLongLong(),
mlEdit->text().toLongLong(), completed->isChecked(), enabled->isChecked(),
scpComboBox->currentText(), contestComboBox->currentText(), descFileEdit->text(), folderEdit->text(),
pubsub->currentIndex(), othsub->currentIndex());
}
void ProblemSpecsDialog::validateForm()
{
buttons->button(QDialogButtonBox::Ok)->setEnabled(!nameEdit->text().isEmpty() && !ntEdit->text().isEmpty()
&& !tlEdit->text().isEmpty() && !mlEdit->text().isEmpty()
&& scpComboBox->currentIndex() > 0 && !folderEdit->text().isEmpty());
}