void MainWindow::addSessionToMember() { if (!CLLSSListWidget->currentIndex().isValid()) { return; } if (current_db_class == NULL) { return; } if (CLLSListWidget->highlightedRow() < 0) { return; } QDateTime datetime = CLLSSListWidget->currentItem()->data(Qt::UserRole).toDateTime(); Session * session = current_db_sessions.value(datetime); if (!session) return; if (session->numStudents() < 1) { return; } MTListWidget * lw = new MTListWidget; QDialog * d = createAddSessionDialogue(tr("Add selected session"), lw); for (int i = 0; i < session->numStudents(); ++i) { lw->addItem(session->student(i)->name()); } lw->setCurrentRow(0); if (!d->exec()) { delete d; return; } if (lw->currentItem() == NULL) { delete d; return; } current_db_class->member(CLLSListWidget->highlightedRow())->addSession(datetime, lw->currentRow()); setCurrentClassMember(CLLSListWidget->highlightedItem()); CLSCAverageLabel->setText(QString("%1%").arg(current_db_class->average(¤t_db_sessions))); delete d; setDatabaseModified(); }
void MainWindow::removeSessionFromMember() { if (CLSSResultsTableWidget->currentRow() < 0) { return; } if (current_db_class == NULL) { return; } if (CLLSListWidget->highlightedRow() < 0) { return; } switch (QMessageBox::information(this, tr("Remove session"), tr("Are you sure you want to remove session \"%1\" from the table of results of the selected student? The session will not be deleted from the database.").arg(CLSSResultsTableWidget->item(CLSSResultsTableWidget->currentRow(), 0)->text()), tr("&Remove"), tr("Cancel"), 0, 1)) { case 0: // Remove break; case 1: // Cancel return; break; } current_db_class->member(CLLSListWidget->highlightedRow())->removeSession(CLSSResultsTableWidget->item(CLSSResultsTableWidget->currentRow(), 0)->data(Qt::UserRole).toDateTime()); setCurrentClassMember(CLLSListWidget->highlightedItem()); CLSCAverageLabel->setText(QString("%1%").arg(current_db_class->average(¤t_db_sessions, ¤t_db_archivedsessions))); setDatabaseModified(); }
void MainWindow::addSession() { if (!current_db_class) { return; } MTListWidget * lw = new MTListWidget; QDialog * d = createAddSessionDialogue(tr("Add session"), lw); QList<QDateTime> sessions_list; for (int i = 0; i < CLLSSListWidget->count(); ++i) { sessions_list << CLLSSListWidget->item(i)->data(Qt::UserRole).toDateTime(); } QFont font; font.setBold(true); for (int i = 0; i < SVLSListWidget->count(); ++i) { if (sessions_list.contains(SVLSListWidget->item(i)->data(Qt::UserRole).toDateTime())) { continue; } QListWidgetItem * item = new QListWidgetItem(*(SVLSListWidget->item(i))); item->setFont(font); item->setBackground(QBrush(QColor(255, 255, 255))); item->setForeground(QBrush(QColor(0, 0, 0))); lw->addItem(item); } for (int i = 0; i < SVLASListWidget->count(); ++i) { if (sessions_list.contains(SVLASListWidget->item(i)->data(Qt::UserRole).toDateTime())) { continue; } QListWidgetItem * item = new QListWidgetItem(*(SVLASListWidget->item(i))); item->setBackground(QBrush(QColor(255, 255, 255))); item->setForeground(QBrush(QColor(0, 0, 0))); lw->addItem(item); } lw->setCurrentRow(0); if (!d->exec()) { delete d; return; } if (lw->currentItem() == NULL) { delete d; return; } QDateTime datetime = lw->currentItem()->data(Qt::UserRole).toDateTime(); current_db_class->addSession(datetime); QListWidgetItem * item = new QListWidgetItem(*(lw->currentItem())); item->setFont(QFont()); CLLSSListWidget->addItem(item); delete d; setDatabaseModified(); Session * session = current_db_sessions.value(datetime, current_db_archivedsessions.value(datetime, new ArchivedSession(this))); SessionWizard wizard(session, current_db_class, this); wizard.setWindowModality(Qt::WindowModal); wizard.exec(); for (int i = 0; i < wizard.numMatchedPairs(); ++i) { current_db_class->member(wizard.studentNumberInClass(i))->addSession(datetime, wizard.studentNumberInSession(i)); } setCurrentClassMember(CLLSListWidget->highlightedItem()); CLSCAverageLabel->setText(QString("%1%").arg(current_db_class->average(¤t_db_sessions, ¤t_db_archivedsessions))); }
void MainWindow::deleteSession() { if (current_db_class == NULL) { return; } if (!CLLSSListWidget->currentIndex().isValid()) { return; } switch (QMessageBox::information(this, tr("Delete session"), tr("Are you sure you want to delete session \"%1\" from this class? The session will not be deleted from the database.").arg(CLLSSListWidget->currentItem()->text()), tr("&Delete"), tr("Cancel"), 0, 1)) { case 0: // Delete break; case 1: // Cancel return; break; } QDateTime datetime = CLLSSListWidget->currentItem()->data(Qt::UserRole).toDateTime(); current_db_class->removeSession(datetime); delete CLLSSListWidget->takeItem(CLLSSListWidget->currentRow()); for (int i = 0; i < current_db_class->numMembers(); ++i) { current_db_class->member(i)->removeSession(datetime); } if (CLLSListWidget->highlightedRow() >= 0) { setCurrentClassMember(CLLSListWidget->highlightedItem()); } CLSCAverageLabel->setText(QString("%1%").arg(current_db_class->average(¤t_db_sessions, ¤t_db_archivedsessions))); setDatabaseModified(); }