Back to index

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