Back to index

fet  5.18.0
modifyconstraintteachermindaysperweekform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintteachermindaysperweekform.cpp  -  description
00003                              -------------------
00004     begin                : 2009
00005     copyright            : (C) 2009 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 "modifyconstraintteachermindaysperweekform.h"
00021 #include "timeconstraint.h"
00022 
00023 ModifyConstraintTeacherMinDaysPerWeekForm::ModifyConstraintTeacherMinDaysPerWeekForm(QWidget* parent, ConstraintTeacherMinDaysPerWeek* 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        updateMinDaysSpinBox();
00043        updateTeachersComboBox();
00044        
00045        minDaysSpinBox->setValue(ctr->minDaysPerWeek);
00046 }
00047 
00048 ModifyConstraintTeacherMinDaysPerWeekForm::~ModifyConstraintTeacherMinDaysPerWeekForm()
00049 {
00050        saveFETDialogGeometry(this);
00051 }
00052 
00053 void ModifyConstraintTeacherMinDaysPerWeekForm::updateTeachersComboBox(){
00054        teachersComboBox->clear();
00055        int i=0, j=-1;
00056        for(int k=0; k<gt.rules.teachersList.size(); k++, i++){
00057               Teacher* tch=gt.rules.teachersList[k];
00058               teachersComboBox->addItem(tch->name);
00059               if(tch->name==this->_ctr->teacherName)
00060                      j=i;
00061        }
00062        assert(j>=0);
00063        teachersComboBox->setCurrentIndex(j);
00064 }
00065 
00066 void ModifyConstraintTeacherMinDaysPerWeekForm::updateMinDaysSpinBox(){
00067        minDaysSpinBox->setMinimum(1);
00068        minDaysSpinBox->setMaximum(gt.rules.nDaysPerWeek);      
00069 }
00070 
00071 void ModifyConstraintTeacherMinDaysPerWeekForm::ok()
00072 {
00073        double weight;
00074        QString tmp=weightLineEdit->text();
00075        weight_sscanf(tmp, "%lf", &weight);
00076        if(weight<0.0 || weight>100.0){
00077               QMessageBox::warning(this, tr("FET information"),
00078                      tr("Invalid weight (percentage)"));
00079               return;
00080        }
00081        if(weight!=100.0){
00082               QMessageBox::warning(this, tr("FET information"),
00083                      tr("Invalid weight (percentage) - it has to be 100%"));
00084               return;
00085        }
00086 
00087        int min_days=minDaysSpinBox->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->minDaysPerWeek=min_days;
00099        this->_ctr->teacherName=teacher_name;
00100 
00101        gt.rules.internalStructureComputed=false;
00102        setRulesModifiedAndOtherThings(&gt.rules);
00103        
00104        this->close();
00105 }
00106 
00107 void ModifyConstraintTeacherMinDaysPerWeekForm::cancel()
00108 {
00109        this->close();
00110 }