Back to index

fet  5.18.0
modifyconstraintteachersintervalmaxdaysperweekform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintteachersintervalmaxdaysperweekform.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 
00021 
00022 #include "modifyconstraintteachersintervalmaxdaysperweekform.h"
00023 #include "timeconstraint.h"
00024 
00025 ModifyConstraintTeachersIntervalMaxDaysPerWeekForm::ModifyConstraintTeachersIntervalMaxDaysPerWeekForm(QWidget* parent, ConstraintTeachersIntervalMaxDaysPerWeek* ctr): QDialog(parent)
00026 {
00027        setupUi(this);
00028 
00029        okPushButton->setDefault(true);
00030 
00031        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00032        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
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        this->_ctr=ctr;
00043        
00044        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00045        
00046        updateMaxDaysSpinBox();
00047        maxDaysSpinBox->setValue(ctr->maxDaysPerWeek);
00048        
00049        for(int i=0; i<gt.rules.nHoursPerDay; i++){
00050               startHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
00051        }
00052        startHourComboBox->setCurrentIndex(ctr->startHour);
00053 
00054        for(int i=0; i<gt.rules.nHoursPerDay; i++){
00055               endHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
00056        }
00057        endHourComboBox->addItem(tr("End of day"));
00058        endHourComboBox->setCurrentIndex(ctr->endHour);
00059 
00060        constraintChanged();
00061 }
00062 
00063 ModifyConstraintTeachersIntervalMaxDaysPerWeekForm::~ModifyConstraintTeachersIntervalMaxDaysPerWeekForm()
00064 {
00065        saveFETDialogGeometry(this);
00066 }
00067 
00068 void ModifyConstraintTeachersIntervalMaxDaysPerWeekForm::updateMaxDaysSpinBox(){
00069        maxDaysSpinBox->setMinimum(0);
00070        maxDaysSpinBox->setMaximum(gt.rules.nDaysPerWeek);      
00071 }
00072 
00073 void ModifyConstraintTeachersIntervalMaxDaysPerWeekForm::constraintChanged()
00074 {
00075 }
00076 
00077 void ModifyConstraintTeachersIntervalMaxDaysPerWeekForm::ok()
00078 {
00079        double weight;
00080        QString tmp=weightLineEdit->text();
00081        weight_sscanf(tmp, "%lf", &weight);
00082        if(weight<0.0 || weight>100.0){
00083               QMessageBox::warning(this, tr("FET information"),
00084                      tr("Invalid weight (percentage)"));
00085               return;
00086        }
00087        if(weight!=100.0){
00088               QMessageBox::warning(this, tr("FET information"),
00089                      tr("Invalid weight (percentage) - it has to be 100%"));
00090               return;
00091        }
00092 
00093        int max_days=maxDaysSpinBox->value();
00094 
00095        int startHour=startHourComboBox->currentIndex();
00096        int endHour=endHourComboBox->currentIndex();
00097        if(startHour<0 || startHour>=gt.rules.nHoursPerDay){
00098               QMessageBox::warning(this, tr("FET information"),
00099                tr("Start hour invalid"));
00100               return;
00101        }
00102        if(endHour<0 || endHour>gt.rules.nHoursPerDay){
00103               QMessageBox::warning(this, tr("FET information"),
00104                tr("End hour invalid"));
00105               return;
00106        }
00107        if(endHour<=startHour){
00108               QMessageBox::warning(this, tr("FET information"),
00109                tr("Start hour cannot be greater or equal than end hour"));
00110               return;
00111        }
00112 
00113        this->_ctr->weightPercentage=weight;
00114        this->_ctr->maxDaysPerWeek=max_days;
00115 
00116        this->_ctr->startHour=startHour;
00117        this->_ctr->endHour=endHour;
00118 
00119        gt.rules.internalStructureComputed=false;
00120        setRulesModifiedAndOtherThings(&gt.rules);
00121        
00122        this->close();
00123 }
00124 
00125 void ModifyConstraintTeachersIntervalMaxDaysPerWeekForm::cancel()
00126 {
00127        this->close();
00128 }