Back to index

fet  5.18.0
modifyconstraintteacheractivitytagmaxhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintteacheractivitytagmaxhoursdailyform.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 "modifyconstraintteacheractivitytagmaxhoursdailyform.h"
00021 #include "timeconstraint.h"
00022 
00023 ModifyConstraintTeacherActivityTagMaxHoursDailyForm::ModifyConstraintTeacherActivityTagMaxHoursDailyForm(QWidget* parent, ConstraintTeacherActivityTagMaxHoursDaily* 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->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        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 ModifyConstraintTeacherActivityTagMaxHoursDailyForm::~ModifyConstraintTeacherActivityTagMaxHoursDailyForm()
00074 {
00075        saveFETDialogGeometry(this);
00076 }
00077 
00078 void ModifyConstraintTeacherActivityTagMaxHoursDailyForm::updateMaxHoursSpinBox(){
00079        maxHoursSpinBox->setMinimum(1);
00080        maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);     
00081 }
00082 
00083 void ModifyConstraintTeacherActivityTagMaxHoursDailyForm::constraintChanged()
00084 {
00085        //nothing
00086 }
00087 
00088 void ModifyConstraintTeacherActivityTagMaxHoursDailyForm::ok()
00089 {
00090        double weight;
00091        QString tmp=weightLineEdit->text();
00092        weight_sscanf(tmp, "%lf", &weight);
00093        if(weight<0.0 || weight>100.0){
00094               QMessageBox::warning(this, tr("FET information"),
00095                      tr("Invalid weight (percentage)"));
00096               return;
00097        }
00098 
00099        int max_hours=maxHoursSpinBox->value();
00100 
00101        QString teacher_name=teachersComboBox->currentText();
00102        int teacher_ID=gt.rules.searchTeacher(teacher_name);
00103        if(teacher_ID<0){
00104               QMessageBox::warning(this, tr("FET warning"),
00105                      tr("Invalid teacher"));
00106               return;
00107        }
00108        
00109        QString activityTagName=activityTagsComboBox->currentText();
00110        int ati=gt.rules.searchActivityTag(activityTagName);
00111        if(ati<0){
00112               QMessageBox::warning(this, tr("FET warning"), tr("Invalid activity tag"));
00113               return;
00114        }
00115 
00116        this->_ctr->weightPercentage=weight;
00117        this->_ctr->maxHoursDaily=max_hours;
00118        this->_ctr->teacherName=teacher_name;
00119        this->_ctr->activityTagName=activityTagName;
00120 
00121        gt.rules.internalStructureComputed=false;
00122        setRulesModifiedAndOtherThings(&gt.rules);
00123        
00124        this->close();
00125 }
00126 
00127 void ModifyConstraintTeacherActivityTagMaxHoursDailyForm::cancel()
00128 {
00129        this->close();
00130 }