Back to index

fet  5.18.0
modifyconstraintteacheractivitytagmaxhourscontinuouslyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintteacheractivitytagmaxhourscontinuouslyform.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 "modifyconstraintteacheractivitytagmaxhourscontinuouslyform.h"
00021 #include "timeconstraint.h"
00022 
00023 ModifyConstraintTeacherActivityTagMaxHoursContinuouslyForm::ModifyConstraintTeacherActivityTagMaxHoursContinuouslyForm(QWidget* parent, ConstraintTeacherActivityTagMaxHoursContinuously* 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        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp4);
00039        
00040        this->_ctr=ctr;
00041        
00042        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00043        
00044        updateMaxHoursSpinBox();
00045        
00046        maxHoursSpinBox->setValue(ctr->maxHoursContinuously);
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        j=-1;
00060        activityTagsComboBox->clear();
00061        for(int k=0; k<gt.rules.activityTagsList.count(); k++){
00062               ActivityTag* at=gt.rules.activityTagsList.at(k);
00063               activityTagsComboBox->addItem(at->name);
00064               if(at->name==this->_ctr->activityTagName)
00065                      j=k;
00066        }
00067        assert(j>=0);
00068        activityTagsComboBox->setCurrentIndex(j);
00069 
00070        constraintChanged();
00071 }
00072 
00073 ModifyConstraintTeacherActivityTagMaxHoursContinuouslyForm::~ModifyConstraintTeacherActivityTagMaxHoursContinuouslyForm()
00074 {
00075        saveFETDialogGeometry(this);
00076 }
00077 
00078 void ModifyConstraintTeacherActivityTagMaxHoursContinuouslyForm::updateMaxHoursSpinBox(){
00079        maxHoursSpinBox->setMinimum(1);
00080        maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);     
00081 }
00082 
00083 void ModifyConstraintTeacherActivityTagMaxHoursContinuouslyForm::constraintChanged()
00084 {
00085 }
00086 
00087 void ModifyConstraintTeacherActivityTagMaxHoursContinuouslyForm::ok()
00088 {
00089        double weight;
00090        QString tmp=weightLineEdit->text();
00091        weight_sscanf(tmp, "%lf", &weight);
00092        if(weight<0.0 || weight>100.0){
00093               QMessageBox::warning(this, tr("FET information"),
00094                      tr("Invalid weight (percentage)"));
00095               return;
00096        }
00097 
00098        int max_hours=maxHoursSpinBox->value();
00099 
00100        QString teacher_name=teachersComboBox->currentText();
00101        int teacher_ID=gt.rules.searchTeacher(teacher_name);
00102        if(teacher_ID<0){
00103               QMessageBox::warning(this, tr("FET warning"),
00104                      tr("Invalid teacher"));
00105               return;
00106        }
00107        
00108        QString activityTagName=activityTagsComboBox->currentText();
00109        int ati=gt.rules.searchActivityTag(activityTagName);
00110        if(ati<0){
00111               QMessageBox::warning(this, tr("FET warning"), tr("Invalid activity tag"));
00112               return;
00113        }
00114 
00115        this->_ctr->weightPercentage=weight;
00116        this->_ctr->maxHoursContinuously=max_hours;
00117        this->_ctr->teacherName=teacher_name;
00118        this->_ctr->activityTagName=activityTagName;
00119 
00120        gt.rules.internalStructureComputed=false;
00121        setRulesModifiedAndOtherThings(&gt.rules);
00122        
00123        this->close();
00124 }
00125 
00126 void ModifyConstraintTeacherActivityTagMaxHoursContinuouslyForm::cancel()
00127 {
00128        this->close();
00129 }