Back to index

fet  5.18.0
addconstraintstudentssetmaxgapsperdayform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintstudentssetmaxgapsperdayform.cpp  -  description
00003                              -------------------
00004     begin                : 2009
00005     copyright            : (C) 2009 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 <QMessageBox>
00019 
00020 #include "longtextmessagebox.h"
00021 
00022 #include "addconstraintstudentssetmaxgapsperdayform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintStudentsSetMaxGapsPerDayForm::AddConstraintStudentsSetMaxGapsPerDayForm(QWidget* parent): QDialog(parent)
00026 {
00027        setupUi(this);
00028 
00029        addConstraintPushButton->setDefault(true);
00030 
00031        connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addCurrentConstraint()));
00032        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00033 
00034        centerWidgetOnScreen(this);
00035        restoreFETDialogGeometry(this);
00036 
00037        QSize tmp2=studentsComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp2);
00039               
00040        maxGapsSpinBox->setMinimum(0);
00041        maxGapsSpinBox->setMaximum(gt.rules.nHoursPerDay);
00042        maxGapsSpinBox->setValue(1);
00043 
00044        updateStudentsSetComboBox();
00045        
00046        constraintChanged();
00047 }
00048 
00049 AddConstraintStudentsSetMaxGapsPerDayForm::~AddConstraintStudentsSetMaxGapsPerDayForm()
00050 {
00051        saveFETDialogGeometry(this);
00052 }
00053 
00054 void AddConstraintStudentsSetMaxGapsPerDayForm::updateStudentsSetComboBox()
00055 {
00056        studentsComboBox->clear();  
00057        for(int i=0; i<gt.rules.yearsList.size(); i++){
00058               StudentsYear* sty=gt.rules.yearsList[i];
00059               studentsComboBox->addItem(sty->name);
00060               for(int j=0; j<sty->groupsList.size(); j++){
00061                      StudentsGroup* stg=sty->groupsList[j];
00062                      studentsComboBox->addItem(stg->name);
00063                      for(int k=0; k<stg->subgroupsList.size(); k++){
00064                             StudentsSubgroup* sts=stg->subgroupsList[k];
00065                             studentsComboBox->addItem(sts->name);
00066                      }
00067               }
00068        }
00069 
00070        constraintChanged();
00071 }
00072 
00073 void AddConstraintStudentsSetMaxGapsPerDayForm::constraintChanged()
00074 {
00075 }
00076 
00077 void AddConstraintStudentsSetMaxGapsPerDayForm::addCurrentConstraint()
00078 {
00079        TimeConstraint *ctr=NULL;
00080 
00081        double weight;
00082        QString tmp=weightLineEdit->text();
00083        weight_sscanf(tmp, "%lf", &weight);
00084        if(weight<0.0 || weight>100.0){
00085               QMessageBox::warning(this, tr("FET information"),
00086                      tr("Invalid weight (percentage)"));
00087               return;
00088        }
00089        if(weight!=100.0){
00090               QMessageBox::warning(this, tr("FET information"),
00091                      tr("Invalid weight (percentage) - it must be 100%"));
00092               return;
00093        }
00094 
00095        QString students_name=studentsComboBox->currentText();
00096        StudentsSet* s=gt.rules.searchStudentsSet(students_name);
00097        if(s==NULL){
00098               QMessageBox::warning(this, tr("FET information"),
00099                      tr("Invalid students set"));
00100               return;
00101        }
00102 
00103        ctr=new ConstraintStudentsSetMaxGapsPerDay(weight, maxGapsSpinBox->value(), students_name);
00104 
00105        bool tmp2=gt.rules.addTimeConstraint(ctr);
00106        if(tmp2)
00107               LongTextMessageBox::information(this, tr("FET information"),
00108                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00109        else{
00110               QMessageBox::warning(this, tr("FET information"),
00111                      tr("Constraint NOT added - please report error"));
00112               delete ctr;
00113        }
00114 }