Back to index

fet  5.18.0
addconstraintstudentssetintervalmaxdaysperweekform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintstudentssetintervalmaxdaysperweekform.cpp  -  description
00003                              -------------------
00004     begin                : 2008
00005     copyright            : (C) 2008 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 "addconstraintstudentssetintervalmaxdaysperweekform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintStudentsSetIntervalMaxDaysPerWeekForm::AddConstraintStudentsSetIntervalMaxDaysPerWeekForm(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        QSize tmp5=startHourComboBox->minimumSizeHint();
00041        Q_UNUSED(tmp5);
00042        QSize tmp6=endHourComboBox->minimumSizeHint();
00043        Q_UNUSED(tmp6);
00044 
00045        updateMaxDaysSpinBox();
00046        updateStudentsComboBox();
00047        updateStartHoursComboBox();
00048        updateEndHoursComboBox();
00049 }
00050 
00051 AddConstraintStudentsSetIntervalMaxDaysPerWeekForm::~AddConstraintStudentsSetIntervalMaxDaysPerWeekForm()
00052 {
00053        saveFETDialogGeometry(this);
00054 }
00055 
00056 void AddConstraintStudentsSetIntervalMaxDaysPerWeekForm::updateStudentsComboBox()
00057 {
00058        studentsComboBox->clear();  
00059        for(int i=0; i<gt.rules.yearsList.size(); i++){
00060               StudentsYear* sty=gt.rules.yearsList[i];
00061               studentsComboBox->addItem(sty->name);
00062               for(int j=0; j<sty->groupsList.size(); j++){
00063                      StudentsGroup* stg=sty->groupsList[j];
00064                      studentsComboBox->addItem(stg->name);
00065                      for(int k=0; k<stg->subgroupsList.size(); k++){
00066                             StudentsSubgroup* sts=stg->subgroupsList[k];
00067                             studentsComboBox->addItem(sts->name);
00068                      }
00069               }
00070        }
00071 
00072        constraintChanged();
00073 }
00074 
00075 void AddConstraintStudentsSetIntervalMaxDaysPerWeekForm::updateMaxDaysSpinBox(){
00076        maxDaysSpinBox->setMinimum(0);
00077        maxDaysSpinBox->setMaximum(gt.rules.nDaysPerWeek);
00078        maxDaysSpinBox->setValue(gt.rules.nDaysPerWeek);
00079 }
00080 
00081 void AddConstraintStudentsSetIntervalMaxDaysPerWeekForm::updateStartHoursComboBox()
00082 {
00083        startHourComboBox->clear();
00084        for(int i=0; i<gt.rules.nHoursPerDay; i++)
00085               startHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
00086        startHourComboBox->setCurrentIndex(gt.rules.nHoursPerDay-1);
00087        
00088        constraintChanged();
00089 }
00090 
00091 void AddConstraintStudentsSetIntervalMaxDaysPerWeekForm::updateEndHoursComboBox()
00092 {
00093        endHourComboBox->clear();
00094        for(int i=0; i<gt.rules.nHoursPerDay; i++)
00095               endHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
00096        endHourComboBox->addItem(tr("End of day"));
00097        endHourComboBox->setCurrentIndex(gt.rules.nHoursPerDay);
00098        
00099        constraintChanged();
00100 }
00101 
00102 void AddConstraintStudentsSetIntervalMaxDaysPerWeekForm::constraintChanged()
00103 {
00104 }
00105 
00106 void AddConstraintStudentsSetIntervalMaxDaysPerWeekForm::addCurrentConstraint()
00107 {
00108        TimeConstraint *ctr=NULL;
00109 
00110        double weight;
00111        QString tmp=weightLineEdit->text();
00112        weight_sscanf(tmp, "%lf", &weight);
00113        if(weight<0.0 || weight>100.0){
00114               QMessageBox::warning(this, tr("FET information"),
00115                      tr("Invalid weight (percentage)"));
00116               return;
00117        }
00118        if(weight!=100.0){
00119               QMessageBox::warning(this, tr("FET information"),
00120                      tr("Invalid weight (percentage) - it has to be 100%"));
00121               return;
00122        }
00123 
00124        int max_days=maxDaysSpinBox->value();
00125 
00126        QString students_name=studentsComboBox->currentText();
00127        StudentsSet* s=gt.rules.searchStudentsSet(students_name);
00128        if(s==NULL){
00129               QMessageBox::warning(this, tr("FET information"),
00130                      tr("Invalid students set"));
00131               return;
00132        }
00133        
00134        int startHour=startHourComboBox->currentIndex();
00135        int endHour=endHourComboBox->currentIndex();
00136        if(startHour<0 || startHour>=gt.rules.nHoursPerDay){
00137               QMessageBox::warning(this, tr("FET information"),
00138                      tr("Start hour invalid"));
00139               return;
00140        }
00141        if(endHour<0 || endHour>gt.rules.nHoursPerDay){
00142               QMessageBox::warning(this, tr("FET information"),
00143                      tr("End hour invalid"));
00144               return;
00145        }
00146        if(endHour<=startHour){
00147               QMessageBox::warning(this, tr("FET information"),
00148                      tr("Start hour cannot be greater or equal than end hour"));
00149               return;
00150        }
00151 
00152        ctr=new ConstraintStudentsSetIntervalMaxDaysPerWeek(weight, max_days, students_name, startHour, endHour);
00153 
00154        bool tmp2=gt.rules.addTimeConstraint(ctr);
00155        if(tmp2)
00156               LongTextMessageBox::information(this, tr("FET information"),
00157                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00158        else{
00159               QMessageBox::warning(this, tr("FET information"),
00160                      tr("Constraint NOT added - please report error"));
00161               delete ctr;
00162        }
00163 }