Back to index

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