void MainWindow::setCurrentClass(QListWidgetItem * item) { if (item == NULL) { return; } MTListWidget::highlightItem(item); clearCLSC(); setCLSCEnabled(true); Class * cl = current_db_classes.value(item, NULL); if (cl == NULL) { return; } current_db_class = cl; CLSCGroupBox->setEnabled(true); CLSCNameLineEdit->setText(cl->name()); CLSCFirstYearSpinBox->setValue(cl->firstYear()); CLSCLastYearSpinBox->setValue(cl->lastYear()); CLSCNumStudentsLabel->setText(QString::number(cl->numMembers())); CLSCAverageLabel->setText(QString("%1%").arg(cl->average(¤t_db_sessions, ¤t_db_archivedsessions))); CLLSListWidget->clear(); for (int i = 0; i < cl->numMembers(); ++i) { CLLSListWidget->addItem(cl->member(i)->name()); } for (int i = 0; i < cl->numSessions(); ++i) { Session * session = current_db_sessions.value(cl->session(i), current_db_archivedsessions.value(cl->session(i), new ArchivedSession(this))); QListWidgetItem * item = new QListWidgetItem(QString("%1 - %2").arg(cl->sessionToString(i)).arg(session->name())); item->setData(Qt::UserRole, cl->session(i)); CLLSSListWidget->addItem(item); } togglePrintEnabled(); }
void MainWindow::enableTools() { togglePrintEnabled(); int i = mainStackedWidget->currentIndex(); setEQToolsEnabled(i == EQ); menuQuestion->setEnabled(i == EQ); menuClass->setEnabled(i == CL); enableSMTools(); enableSVTools(); }
void MainWindow::setCurrentStudent() { if (SVLCListWidget->currentIndex().isValid()) { selectedStudentTab->setEnabled(true); clearSVSC(); togglePrintEnabled(); SVStudentTabWidget->setCurrentIndex(0); Student * student = current_db_students.value(SVLCListWidget->currentItem()); SVStudentNameLabel->setText(student->name()); if (student->isReady()) { if (current_db_session != NULL) { SVStudentScoreLabel->setText(tr("%1 out of %2 (%3)").arg(student->score()).arg(student->maximumScore()).arg(student->passed() ? tr("PASSED") : tr("FAILED"))); } else { SVStudentScoreLabel->setText(tr("%1 out of %2").arg(student->score()).arg(student->maximumScore())); } loadStudentResults(student->results()); } } else { selectedStudentTab->setEnabled(false); clearSVSC(); togglePrintEnabled(); } }
void MainWindow::deleteStudent() { if (current_db_class == NULL) { return; } if (CLLSListWidget->highlightedRow() < 0) { return; } switch (QMessageBox::information(this, tr("Delete student"), tr("Are you sure you want to delete student \"%1\"?").arg(CLLSListWidget->highlightedItem()->text()), tr("&Delete"), tr("Cancel"), 0, 1)) { case 0: // Delete break; case 1: // Cancel return; break; } current_db_class->removeMember(CLLSListWidget->highlightedRow()); delete CLLSListWidget->takeItem(CLLSListWidget->highlightedRow()); CLSCNumStudentsLabel->setText(QString::number(current_db_class->numMembers())); CLSCAverageLabel->setText(QString("%1%").arg(current_db_class->average(¤t_db_sessions, ¤t_db_archivedsessions))); clearCLSS(); togglePrintEnabled(); setDatabaseModified(); }
void MainWindow::deleteClass() { if (!current_db_class) { return; } QList<QListWidgetItem *> cl_items = current_db_classes.keys(current_db_class); if (cl_items.count() <= 0) { return; } switch (QMessageBox::information(this, tr("Delete class"), tr("Are you sure you want to delete class \"%1\"?").arg(cl_items.at(0)->text()), tr("&Delete"), tr("Cancel"), 0, 1)) { case 0: // Delete break; case 1: // Cancel return; break; } delete current_db_class; for (int i = 0; i < cl_items.count(); ++i) { current_db_classes.remove(cl_items.at(i)); delete cl_items.at(i); } clearCLSC(); togglePrintEnabled(); setDatabaseModified(); }
void MainWindow::setCurrentClassMember(QListWidgetItem * item) { if (item == NULL) { return; } if (!current_db_class) { return; } MTListWidget::highlightItem(item); clearCLSS(); setCLSSEnabled(true); ClassMember * mem = current_db_class->member(CLLSListWidget->row(item)); CLSSNameLineEdit->setText(mem->name()); CLSSAverageLabel->setText(QString("%1%").arg(mem->average(¤t_db_sessions, ¤t_db_archivedsessions))); CLSSResultsTableWidget->setRowCount(mem->numSessionEntries()); CLSSResultsTableWidget->setSortingEnabled(false); for (int i = 0; i < mem->numSessionEntries(); ++i) { Session * session = current_db_sessions.value(mem->sessionEntry(i).session, current_db_archivedsessions.value(mem->sessionEntry(i).session, NULL)); if (session != NULL) { CLSSResultsTableWidget->setItem(i, 0, new QTableWidgetItem(QString("%1 - %2").arg(session->dateTimeToString()).arg(session->name()))); CLSSResultsTableWidget->item(i, 0)->setData(Qt::UserRole, session->dateTime()); CLSSResultsTableWidget->setItem(i, 1, new QTableWidgetItem(session->student(mem->sessionEntry(i).member_num)->name())); CLSSResultsTableWidget->item(i, 1)->setData(Qt::UserRole, mem->sessionEntry(i).member_num); CLSSResultsTableWidget->item(i, 1)->setBackground(QBrush(session->student(mem->sessionEntry(i).member_num)->passed() ? QColor(197, 255, 120) : QColor(204, 163, 0))); MTProgressBar * bar = new MTProgressBar(this); CLSSResultsTableWidget->setCellWidget(i, 2, bar); bar->setMaximum((int)(session->student(mem->sessionEntry(i).member_num)->maximumScore() * 100.0)); bar->setValue((int)(session->student(mem->sessionEntry(i).member_num)->score() * 100.0)); bar->setTextVisible(true); } else { CLSSResultsTableWidget->setItem(i, 0, new QTableWidgetItem(mem->sessionToString(i))); CLSSResultsTableWidget->item(i, 0)->setData(Qt::UserRole, mem->sessionEntry(i).session); CLSSResultsTableWidget->setItem(i, 1, new QTableWidgetItem); CLSSResultsTableWidget->item(i, 1)->setData(Qt::UserRole, mem->sessionEntry(i).member_num); CLSSResultsTableWidget->setItem(i, 2, new QTableWidgetItem); } } CLSSResultsTableWidget->setSortingEnabled(true); CLSSResultsTableWidget->resizeRowsToContents(); toggleAddSessionToMemberEnabled(); tbtnRemoveSession->setEnabled(CLSSResultsTableWidget->currentIndex().isValid()); togglePrintEnabled(); }
void MainWindow::setCurrentSession(QListWidgetItem * item) { if (item == NULL) { return; } selectSessionItem(item); Session * session; if (item->listWidget() == SVLSListWidget) { session = current_db_sessions.value(item->data(Qt::UserRole).toDateTime()); } else if (item->listWidget() == SVLASListWidget) { session = current_db_archivedsessions.value(item->data(Qt::UserRole).toDateTime()); } else { return; } current_db_session = session; SVSelectedSessionWidget->setEnabled(true); SVNameLabel->setText(session->name()); SVDateTimeLabel->setText(session->dateTimeToString()); SVPassMarkLabel->setText(QString::number(session->passMark().passMark())); SVOverallResultsProgressBar->setMaximum((int)session->maximumScore()); SVOverallResultsProgressBar->setValue(session->score() > 0 ? (int)session->score() : 0); SVOverallResultsLabel->setText(QString("%1%").arg(session->average())); current_db_students.clear(); SVLCListWidget->clear(); SVLogListWidget->clear(); for (int i = 0; i < session->numLogEntries(); ++i) { QListWidgetItem * log_entry = new QListWidgetItem (session->logEntry(i).entryText(), SVLogListWidget); log_entry->setBackground(QBrush(session->logEntry(i).entryBackgroundColour())); log_entry->setForeground(QBrush(session->logEntry(i).entryForegroundColour())); } SVLogGroupBox->setVisible(session->numLogEntries() > 0); for (int i = 0; i < session->numStudents(); ++i) { QListWidgetItem * item = new QListWidgetItem(session->student(i)->name(), SVLCListWidget); current_db_students.insert(item, session->student(i)); if (session->student(i)->passed()) { item->setBackground(QBrush(QColor(197, 255, 120))); } else { item->setBackground(QBrush(QColor(204, 163, 0))); } item->setForeground(QBrush(QColor(0, 0, 0))); } SVPassMarkTableWidget->clearContents(); SVPassMarkTableWidget->verticalHeader()->hide(); if (session->passMark().count() > 0) { passMarkDetailsTab->setEnabled(true); QTableWidgetItem * item; SVPassMarkTableWidget->setRowCount(session->passMark().count()); for (int i = 0; i < session->passMark().count(); ++i) { if (session->passMark().condition(i) < 0 || session->passMark().condition(i) >= current_db_f.size()) { continue; } item = new QTableWidgetItem(QString("%1 - %2").arg(session->passMark().condition(i) + 1).arg(current_db_f[session->passMark().condition(i)])); item->setBackground(QBrush(backgroundColourForFlag(session->passMark().condition(i)))); item->setForeground(QBrush(foregroundColourForFlag(session->passMark().condition(i)))); SVPassMarkTableWidget->setItem(i, 0, item); item = new QTableWidgetItem(QString::number(session->passMark().value(i))); SVPassMarkTableWidget->setItem(i, 1, item); SVPassMarkTableWidget->setRowHeight(i, 16); } SVPassMarkTableWidget->filterItems(SVSearchDetailsLineEdit, SVSearchDetailsLineEdit->text()); SVStudentTabWidget->setCurrentIndex(1); } else { passMarkDetailsTab->setEnabled(false); SVStudentTabWidget->setCurrentIndex(0); } selectedStudentTab->setEnabled(false); scoringSystemTab->setEnabled(true); SVScoringSystemTableWidget->item(0, 1)->setText(session->scoringSystem().allowIncompleteAnswers ? tr("allowed") : tr("disallowed")); for (int i = 0, n = 0; i < 3; ++i, n += 3) { SVScoringSystemTableWidget->item(n + 1, 1)->setText(QString::number(session->scoringSystem().correctAnswer[i])); SVScoringSystemTableWidget->item(n + 2, 1)->setText(QString::number(session->scoringSystem().incorrectAnswer[i])); SVScoringSystemTableWidget->item(n + 3, 1)->setText(QString::number(session->scoringSystem().missingAnswer[i])); } SVLCGroupBox->setEnabled(true); SVLogGroupBox->setEnabled(true); togglePrintEnabled(); enableSVTools(); }