Back to index

fet  5.18.0
addstudentssubgroupform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addstudentssubgroupform.cpp  -  description
00003                              -------------------
00004     begin                : Sat Jan 24 2004
00005     copyright            : (C) 2004 by Lalescu Liviu
00006     email                : Please see http://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "addstudentssubgroupform.h"
00019 
00020 #include <QMessageBox>
00021 
00022 AddStudentsSubgroupForm::AddStudentsSubgroupForm(QWidget* parent, const QString& yearName, const QString& groupName): QDialog(parent)
00023 {
00024        setupUi(this);
00025 
00026        addStudentsSubgroupPushButton->setDefault(true);
00027 
00028        connect(addStudentsSubgroupPushButton, SIGNAL(clicked()), this, SLOT(addStudentsSubgroup()));
00029        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00030 
00031        centerWidgetOnScreen(this);
00032        restoreFETDialogGeometry(this);
00033        
00034        yearNameLineEdit->setText(yearName);
00035        groupNameLineEdit->setText(groupName);
00036 
00037        nameLineEdit->selectAll();
00038        nameLineEdit->setFocus();
00039 
00040        numberSpinBox->setMaximum(MAX_ROOM_CAPACITY);
00041        numberSpinBox->setMinimum(0);
00042        numberSpinBox->setValue(0);
00043 }
00044 
00045 AddStudentsSubgroupForm::~AddStudentsSubgroupForm()
00046 {
00047        saveFETDialogGeometry(this);
00048 }
00049 
00050 void AddStudentsSubgroupForm::addStudentsSubgroup()
00051 {
00052        if(nameLineEdit->text().isEmpty()){
00053               QMessageBox::information(this, tr("FET information"), tr("Incorrect name"));
00054               return;
00055        }
00056        QString subgroupName=nameLineEdit->text();
00057        QString yearName=yearNameLineEdit->text();
00058        QString groupName=groupNameLineEdit->text();
00059 
00060        if(gt.rules.searchSubgroup(yearName, groupName, subgroupName)>=0){
00061               QMessageBox::information( this, tr("Subgroup insertion dialog"),
00062                      tr("Could not insert item. Must be a duplicate"));
00063               return;
00064        }
00065        StudentsSet* ss=gt.rules.searchStudentsSet(subgroupName);
00066        StudentsSubgroup* sts;
00067        if(ss!=NULL && ss->type==STUDENTS_YEAR){
00068               QMessageBox::information( this, tr("Subgroup insertion dialog"),
00069                      tr("This name is taken for a year - please consider another name"));
00070               return;
00071        }
00072        if(ss!=NULL && ss->type==STUDENTS_GROUP){
00073               QMessageBox::information( this, tr("Subgroup insertion dialog"),
00074                      tr("This name is taken for a group - please consider another name"));
00075               return;
00076        }
00077        if(ss!=NULL){ //already existing subgroup, but in other group. Several groups share the same subgroup.
00078               assert(ss->type==STUDENTS_SUBGROUP);
00079               if(QMessageBox::warning( this, tr("FET"),
00080                      tr("This subgroup already exists, but in another group. "
00081                      "If you insert current subgroup to current group, that "
00082                      "means that some groups share the same subgroup (overlap). "
00083                      "If you want to make a new subgroup, independent, "
00084                      "please abort now and give it another name.")+"\n\n"+tr("Note: the number of students for the added subgroup will be the number of students of the already existing subgroup "
00085                      "(you can modify the number of students in the modify subgroup dialog)."),
00086                      tr("Add"), tr("Abort"), 0, 0, 1 ) == 1)
00087                      return;
00088 
00089               numberSpinBox->setValue(ss->numberOfStudents);
00090               sts=(StudentsSubgroup*)ss;
00091        }
00092        else{
00093               sts=new StudentsSubgroup();
00094               sts->name=subgroupName;
00095               sts->numberOfStudents=numberSpinBox->value();
00096        }
00097        gt.rules.addSubgroup(yearName, groupName, sts);
00098        QMessageBox::information(this, tr("Subgroup insertion dialog"),
00099               tr("Subgroup added"));
00100 
00101        nameLineEdit->selectAll();
00102        nameLineEdit->setFocus();
00103 }