Back to index

fet  5.18.0
modifyconstraintteacherintervalmaxdaysperweekform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintteacherintervalmaxdaysperweekform.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 "modifyconstraintteacherintervalmaxdaysperweekform.h"
00021 #include "timeconstraint.h"
00022 
00023 ModifyConstraintTeacherIntervalMaxDaysPerWeekForm::ModifyConstraintTeacherIntervalMaxDaysPerWeekForm(QWidget* parent, ConstraintTeacherIntervalMaxDaysPerWeek* ctr): QDialog(parent)
00024 {
00025        setupUi(this);
00026 
00027        okPushButton->setDefault(true);
00028 
00029        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00030        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
00031 
00032        centerWidgetOnScreen(this);
00033        restoreFETDialogGeometry(this);
00034 
00035        QSize tmp1=teachersComboBox->minimumSizeHint();
00036        Q_UNUSED(tmp1);
00037        
00038        QSize tmp5=startHourComboBox->minimumSizeHint();
00039        Q_UNUSED(tmp5);
00040        QSize tmp6=endHourComboBox->minimumSizeHint();
00041        Q_UNUSED(tmp6);
00042        
00043        this->_ctr=ctr;
00044        
00045        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00046        
00047        updateMaxDaysSpinBox();
00048        updateTeachersComboBox();
00049        
00050        maxDaysSpinBox->setValue(ctr->maxDaysPerWeek);
00051        
00052        for(int i=0; i<gt.rules.nHoursPerDay; i++){
00053               startHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
00054        }
00055        startHourComboBox->setCurrentIndex(ctr->startHour);
00056 
00057        for(int i=0; i<gt.rules.nHoursPerDay; i++){
00058               endHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
00059        }
00060        endHourComboBox->addItem(tr("End of day"));
00061        endHourComboBox->setCurrentIndex(ctr->endHour);
00062 
00063        constraintChanged();
00064 }
00065 
00066 ModifyConstraintTeacherIntervalMaxDaysPerWeekForm::~ModifyConstraintTeacherIntervalMaxDaysPerWeekForm()
00067 {
00068        saveFETDialogGeometry(this);
00069 }
00070 
00071 void ModifyConstraintTeacherIntervalMaxDaysPerWeekForm::updateTeachersComboBox(){
00072        teachersComboBox->clear();
00073        int i=0, j=-1;
00074        for(int k=0; k<gt.rules.teachersList.size(); k++, i++){
00075               Teacher* tch=gt.rules.teachersList[k];
00076               teachersComboBox->addItem(tch->name);
00077               if(tch->name==this->_ctr->teacherName)
00078                      j=i;
00079        }
00080        assert(j>=0);
00081        teachersComboBox->setCurrentIndex(j);
00082 
00083        constraintChanged();
00084 }
00085 
00086 void ModifyConstraintTeacherIntervalMaxDaysPerWeekForm::updateMaxDaysSpinBox(){
00087        maxDaysSpinBox->setMinimum(0);
00088        maxDaysSpinBox->setMaximum(gt.rules.nDaysPerWeek);      
00089 }
00090 
00091 void ModifyConstraintTeacherIntervalMaxDaysPerWeekForm::constraintChanged()
00092 {
00093 }
00094 
00095 void ModifyConstraintTeacherIntervalMaxDaysPerWeekForm::ok()
00096 {
00097        double weight;
00098        QString tmp=weightLineEdit->text();
00099        weight_sscanf(tmp, "%lf", &weight);
00100        if(weight<0.0 || weight>100.0){
00101               QMessageBox::warning(this, tr("FET information"),
00102                      tr("Invalid weight (percentage)"));
00103               return;
00104        }
00105        if(weight!=100.0){
00106               QMessageBox::warning(this, tr("FET information"),
00107                      tr("Invalid weight (percentage) - it has to be 100%"));
00108               return;
00109        }
00110 
00111        int max_days=maxDaysSpinBox->value();
00112 
00113        QString teacher_name=teachersComboBox->currentText();
00114        int teacher_ID=gt.rules.searchTeacher(teacher_name);
00115        if(teacher_ID<0){
00116               QMessageBox::warning(this, tr("FET information"),
00117                      tr("Invalid teacher"));
00118               return;
00119        }
00120        
00121        int startHour=startHourComboBox->currentIndex();
00122        int endHour=endHourComboBox->currentIndex();
00123        if(startHour<0 || startHour>=gt.rules.nHoursPerDay){
00124               QMessageBox::warning(this, tr("FET information"),
00125                tr("Start hour invalid"));
00126               return;
00127        }
00128        if(endHour<0 || endHour>gt.rules.nHoursPerDay){
00129               QMessageBox::warning(this, tr("FET information"),
00130                tr("End hour invalid"));
00131               return;
00132        }
00133        if(endHour<=startHour){
00134               QMessageBox::warning(this, tr("FET information"),
00135                tr("Start hour cannot be greater or equal than end hour"));
00136               return;
00137        }
00138 
00139        this->_ctr->weightPercentage=weight;
00140        this->_ctr->maxDaysPerWeek=max_days;
00141        this->_ctr->teacherName=teacher_name;
00142 
00143        this->_ctr->startHour=startHour;
00144        this->_ctr->endHour=endHour;
00145 
00146        gt.rules.internalStructureComputed=false;
00147        setRulesModifiedAndOtherThings(&gt.rules);
00148        
00149        this->close();
00150 }
00151 
00152 void ModifyConstraintTeacherIntervalMaxDaysPerWeekForm::cancel()
00153 {
00154        this->close();
00155 }