Back to index

fet  5.18.0
modifyconstraintteacherminhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintteacherminhoursdailyform.cpp  -  description
00003                              -------------------
00004     begin                : Sept 21, 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 "modifyconstraintteacherminhoursdailyform.h"
00021 #include "timeconstraint.h"
00022 
00023 ModifyConstraintTeacherMinHoursDailyForm::ModifyConstraintTeacherMinHoursDailyForm(QWidget* parent, ConstraintTeacherMinHoursDaily* 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        allowEmptyDaysCheckBox->setChecked(ctr->allowEmptyDays);
00043        
00044        connect(allowEmptyDaysCheckBox, SIGNAL(toggled(bool)), this, SLOT(allowEmptyDaysCheckBoxToggled())); //after setChecked(...)
00045        
00046        updateMinHoursSpinBox();
00047        
00048        minHoursSpinBox->setValue(ctr->minHoursDaily);
00049 
00050        teachersComboBox->clear();
00051        int i=0, j=-1;
00052        for(int k=0; k<gt.rules.teachersList.size(); k++, i++){
00053               Teacher* tch=gt.rules.teachersList[k];
00054               teachersComboBox->addItem(tch->name);
00055               if(tch->name==this->_ctr->teacherName)
00056                      j=i;
00057        }
00058        assert(j>=0);
00059        teachersComboBox->setCurrentIndex(j);
00060 
00061        constraintChanged();
00062 }
00063 
00064 ModifyConstraintTeacherMinHoursDailyForm::~ModifyConstraintTeacherMinHoursDailyForm()
00065 {
00066        saveFETDialogGeometry(this);
00067 }
00068 
00069 void ModifyConstraintTeacherMinHoursDailyForm::updateMinHoursSpinBox(){
00070        minHoursSpinBox->setMinimum(2);
00071        minHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);     
00072 }
00073 
00074 void ModifyConstraintTeacherMinHoursDailyForm::constraintChanged()
00075 {
00076 }
00077 
00078 void ModifyConstraintTeacherMinHoursDailyForm::ok()
00079 {
00080        double weight;
00081        QString tmp=weightLineEdit->text();
00082        weight_sscanf(tmp, "%lf", &weight);
00083        if(weight<0.0 || weight>100.0){
00084               QMessageBox::warning(this, tr("FET information"),
00085                      tr("Invalid weight (percentage)"));
00086               return;
00087        }
00088        if(weight!=100.0){
00089               QMessageBox::warning(this, tr("FET information"),
00090                      tr("Invalid weight (percentage) - must be 100%"));
00091               return;
00092        }
00093 
00094        if(!allowEmptyDaysCheckBox->isChecked()){
00095               QMessageBox::warning(this, tr("FET information"), tr("Allow empty days check box must be checked. If you need to not allow empty days for a teacher, "
00096                      "please use the constraint teacher min days per week"));
00097               return;
00098        }
00099 
00100        int min_hours=minHoursSpinBox->value();
00101 
00102        QString teacher_name=teachersComboBox->currentText();
00103        int teacher_ID=gt.rules.searchTeacher(teacher_name);
00104        if(teacher_ID<0){
00105               QMessageBox::warning(this, tr("FET information"),
00106                      tr("Invalid teacher"));
00107               return;
00108        }
00109 
00110        this->_ctr->weightPercentage=weight;
00111        this->_ctr->minHoursDaily=min_hours;
00112        this->_ctr->teacherName=teacher_name;
00113        
00114        this->_ctr->allowEmptyDays=allowEmptyDaysCheckBox->isChecked();
00115 
00116        gt.rules.internalStructureComputed=false;
00117        setRulesModifiedAndOtherThings(&gt.rules);
00118        
00119        this->close();
00120 }
00121 
00122 void ModifyConstraintTeacherMinHoursDailyForm::cancel()
00123 {
00124        this->close();
00125 }
00126 
00127 void ModifyConstraintTeacherMinHoursDailyForm::allowEmptyDaysCheckBoxToggled()
00128 {
00129        bool k=allowEmptyDaysCheckBox->isChecked();
00130 
00131        if(!k){
00132               allowEmptyDaysCheckBox->setChecked(true);
00133               QMessageBox::information(this, tr("FET information"), tr("This check box must remain checked. If you really need to not allow empty days for this teacher,"
00134                      " please use constraint teacher min days per week"));
00135        }
00136 }