Back to index

fet  5.18.0
modifyconstraintteachermaxhourscontinuouslyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintteachermaxhourscontinuouslyform.cpp  -  description
00003                              -------------------
00004     begin                : July 19, 2007
00005     copyright            : (C) 2007 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 "modifyconstraintteachermaxhourscontinuouslyform.h"
00021 #include "timeconstraint.h"
00022 
00023 ModifyConstraintTeacherMaxHoursContinuouslyForm::ModifyConstraintTeacherMaxHoursContinuouslyForm(QWidget* parent, ConstraintTeacherMaxHoursContinuously* 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        this->_ctr=ctr;
00039        
00040        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00041        
00042        updateMaxHoursSpinBox();
00043        
00044        maxHoursSpinBox->setValue(ctr->maxHoursContinuously);
00045 
00046        teachersComboBox->clear();
00047        int i=0, j=-1;
00048        for(int k=0; k<gt.rules.teachersList.size(); k++, i++){
00049               Teacher* tch=gt.rules.teachersList[k];
00050               teachersComboBox->addItem(tch->name);
00051               if(tch->name==this->_ctr->teacherName)
00052                      j=i;
00053        }
00054        assert(j>=0);
00055        teachersComboBox->setCurrentIndex(j);
00056 
00057        constraintChanged();
00058 }
00059 
00060 ModifyConstraintTeacherMaxHoursContinuouslyForm::~ModifyConstraintTeacherMaxHoursContinuouslyForm()
00061 {
00062        saveFETDialogGeometry(this);
00063 }
00064 
00065 void ModifyConstraintTeacherMaxHoursContinuouslyForm::updateMaxHoursSpinBox(){
00066        maxHoursSpinBox->setMinimum(1);
00067        maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);     
00068 }
00069 
00070 void ModifyConstraintTeacherMaxHoursContinuouslyForm::constraintChanged()
00071 {
00072 }
00073 
00074 void ModifyConstraintTeacherMaxHoursContinuouslyForm::ok()
00075 {
00076        double weight;
00077        QString tmp=weightLineEdit->text();
00078        weight_sscanf(tmp, "%lf", &weight);
00079        if(weight<0.0 || weight>100.0){
00080               QMessageBox::warning(this, tr("FET information"),
00081                      tr("Invalid weight (percentage)"));
00082               return;
00083        }
00084 
00085        int max_hours=maxHoursSpinBox->value();
00086 
00087        QString teacher_name=teachersComboBox->currentText();
00088        int teacher_ID=gt.rules.searchTeacher(teacher_name);
00089        if(teacher_ID<0){
00090               QMessageBox::warning(this, tr("FET information"),
00091                      tr("Invalid teacher"));
00092               return;
00093        }
00094 
00095        this->_ctr->weightPercentage=weight;
00096        this->_ctr->maxHoursContinuously=max_hours;
00097        this->_ctr->teacherName=teacher_name;
00098 
00099        gt.rules.internalStructureComputed=false;
00100        setRulesModifiedAndOtherThings(&gt.rules);
00101        
00102        this->close();
00103 }
00104 
00105 void ModifyConstraintTeacherMaxHoursContinuouslyForm::cancel()
00106 {
00107        this->close();
00108 }