Back to index

fet  5.18.0
addstudentsgroupform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addstudentsgroupform.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 "addstudentsgroupform.h"
00019 
00020 #include <QMessageBox>
00021 
00022 AddStudentsGroupForm::AddStudentsGroupForm(QWidget* parent, const QString& yearName): QDialog(parent)
00023 {
00024        setupUi(this);
00025        
00026        addStudentsGroupPushButton->setDefault(true);
00027 
00028        connect(addStudentsGroupPushButton, SIGNAL(clicked()), this, SLOT(addStudentsGroup()));
00029        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00030 
00031        centerWidgetOnScreen(this);
00032        restoreFETDialogGeometry(this);
00033               
00034        yearNameLineEdit->setText(yearName);
00035 
00036        nameLineEdit->selectAll();
00037        nameLineEdit->setFocus();
00038        
00039        numberSpinBox->setMaximum(MAX_ROOM_CAPACITY);
00040        numberSpinBox->setMinimum(0);
00041        numberSpinBox->setValue(0);
00042 }
00043 
00044 AddStudentsGroupForm::~AddStudentsGroupForm()
00045 {
00046        saveFETDialogGeometry(this);
00047 }
00048 
00049 void AddStudentsGroupForm::addStudentsGroup()
00050 {
00051        StudentsGroup* sg;
00052 
00053        if(nameLineEdit->text().isEmpty()){
00054               QMessageBox::information(this, tr("FET information"), tr("Incorrect name"));
00055               return;
00056        }
00057        QString yearName=yearNameLineEdit->text();
00058        QString groupName=nameLineEdit->text();
00059 
00060        if(gt.rules.searchGroup(yearName, groupName)>=0){
00061               QMessageBox::information( this, tr("Group insertion dialog"),
00062                      tr("Could not insert item. Duplicate"));
00063               return;
00064        }
00065        StudentsSet* ss=gt.rules.searchStudentsSet(groupName);
00066        if(ss!=NULL && ss->type==STUDENTS_YEAR){
00067               QMessageBox::information( this, tr("Group insertion dialog"),
00068                      tr("This name is taken for a year - please consider another name"));
00069               return;
00070        }
00071        if(ss!=NULL && ss->type==STUDENTS_SUBGROUP){
00072               QMessageBox::information( this, tr("Group insertion dialog"),
00073                      tr("This name is taken for a subgroup - please consider another name"));
00074               return;
00075        }
00076        if(ss!=NULL){ //already existing group, but in other year. It is the same group.
00077               assert(ss->type==STUDENTS_GROUP);
00078               if(QMessageBox::warning( this, tr("FET"),
00079                      tr("This group already exists, but in another year. "
00080                      "If you insert current group to current year, that "
00081                      "means that some years share the same group (overlap). "
00082                      "If you want to make a new group, independent, "
00083                      "please abort now and give it another name.")+"\n\n"+tr("Note: the number of students for the added group will be the number of students of the already existing group"
00084                      " (you can modify the number of students in the modify group dialog)."),
00085                      tr("Add"),tr("Abort"), 0, 0, 1 ) == 1)
00086                      return;
00087 
00088               numberSpinBox->setValue(ss->numberOfStudents);
00089               sg=(StudentsGroup*)ss;
00090        }
00091        else{
00092               sg=new StudentsGroup();
00093               sg->name=groupName;
00094               sg->numberOfStudents=numberSpinBox->value();
00095        }
00096 
00097        gt.rules.addGroup(yearName, sg);
00098        QMessageBox::information(this, tr("Group insertion dialog"),
00099               tr("Group added"));
00100 
00101        nameLineEdit->selectAll();
00102        nameLineEdit->setFocus();
00103 }