Back to index

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