Back to index

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