Esempio n. 1
0
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(&current_db_sessions)));
    delete d;
    setDatabaseModified();
}
Esempio n. 2
0
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(&current_db_sessions, &current_db_archivedsessions)));
}