Back to index

fet  5.18.0
modifyconstraintteachersactivitytagmaxhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintteachersactivitytagmaxhoursdailyform.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 "modifyconstraintteachersactivitytagmaxhoursdailyform.h"
00021 #include "timeconstraint.h"
00022 
00023 ModifyConstraintTeachersActivityTagMaxHoursDailyForm::ModifyConstraintTeachersActivityTagMaxHoursDailyForm(QWidget* parent, ConstraintTeachersActivityTagMaxHoursDaily* 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 tmp4=activityTagsComboBox->minimumSizeHint();
00036        Q_UNUSED(tmp4);
00037        
00038        this->_ctr=ctr;
00039        
00040        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00041        
00042        updateMaxHoursSpinBox();
00043        
00044        maxHoursSpinBox->setValue(ctr->maxHoursDaily);
00045 
00046        activityTagsComboBox->clear();
00047        int j=-1;
00048        for(int k=0; k<gt.rules.activityTagsList.count(); k++){
00049               ActivityTag* at=gt.rules.activityTagsList.at(k);
00050               activityTagsComboBox->addItem(at->name);
00051               if(at->name==this->_ctr->activityTagName)
00052                      j=k;
00053        }
00054        assert(j>=0);
00055        activityTagsComboBox->setCurrentIndex(j);
00056 
00057        constraintChanged();
00058 }
00059 
00060 ModifyConstraintTeachersActivityTagMaxHoursDailyForm::~ModifyConstraintTeachersActivityTagMaxHoursDailyForm()
00061 {
00062        saveFETDialogGeometry(this);
00063 }
00064 
00065 void ModifyConstraintTeachersActivityTagMaxHoursDailyForm::updateMaxHoursSpinBox(){
00066        maxHoursSpinBox->setMinimum(1);
00067        maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);     
00068 }
00069 
00070 void ModifyConstraintTeachersActivityTagMaxHoursDailyForm::constraintChanged()
00071 {
00072        //nothing
00073 }
00074 
00075 void ModifyConstraintTeachersActivityTagMaxHoursDailyForm::ok()
00076 {
00077        double weight;
00078        QString tmp=weightLineEdit->text();
00079        weight_sscanf(tmp, "%lf", &weight);
00080        if(weight<0.0 || weight>100.0){
00081               QMessageBox::warning(this, tr("FET information"),
00082                      tr("Invalid weight (percentage)"));
00083               return;
00084        }
00085 
00086        int max_hours=maxHoursSpinBox->value();
00087 
00088        QString activityTagName=activityTagsComboBox->currentText();
00089        int ati=gt.rules.searchActivityTag(activityTagName);
00090        if(ati<0){
00091               QMessageBox::warning(this, tr("FET warning"), tr("Invalid activity tag"));
00092               return;
00093        }
00094 
00095        this->_ctr->weightPercentage=weight;
00096        this->_ctr->maxHoursDaily=max_hours;
00097        this->_ctr->activityTagName=activityTagName;
00098 
00099        gt.rules.internalStructureComputed=false;
00100        setRulesModifiedAndOtherThings(&gt.rules);
00101        
00102        this->close();
00103 }
00104 
00105 void ModifyConstraintTeachersActivityTagMaxHoursDailyForm::cancel()
00106 {
00107        this->close();
00108 }