Back to index

fet  5.18.0
modifyconstraintstudentsactivitytagmaxhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintstudentsactivitytagmaxhoursdailyform.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 "modifyconstraintstudentsactivitytagmaxhoursdailyform.h"
00021 #include "timeconstraint.h"
00022 
00023 ModifyConstraintStudentsActivityTagMaxHoursDailyForm::ModifyConstraintStudentsActivityTagMaxHoursDailyForm(QWidget* parent, ConstraintStudentsActivityTagMaxHoursDaily* 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        updateActivityTagsComboBox();
00043 
00044        maxHoursSpinBox->setMinimum(1);
00045        maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
00046        maxHoursSpinBox->setValue(ctr->maxHoursDaily);
00047 
00048        constraintChanged();
00049 }
00050 
00051 ModifyConstraintStudentsActivityTagMaxHoursDailyForm::~ModifyConstraintStudentsActivityTagMaxHoursDailyForm()
00052 {
00053        saveFETDialogGeometry(this);
00054 }
00055 
00056 void ModifyConstraintStudentsActivityTagMaxHoursDailyForm::updateActivityTagsComboBox()
00057 {
00058        activityTagsComboBox->clear();
00059        int j=-1;
00060        for(int i=0; i<gt.rules.activityTagsList.count(); i++){
00061               ActivityTag* at=gt.rules.activityTagsList.at(i);
00062               activityTagsComboBox->addItem(at->name);
00063               if(at->name==this->_ctr->activityTagName)
00064                      j=i;
00065        }
00066        assert(j>=0);
00067        activityTagsComboBox->setCurrentIndex(j);
00068        
00069        constraintChanged();
00070 }
00071 
00072 void ModifyConstraintStudentsActivityTagMaxHoursDailyForm::constraintChanged()
00073 {
00074        //nothing
00075 }
00076 
00077 void ModifyConstraintStudentsActivityTagMaxHoursDailyForm::ok()
00078 {
00079        double weight;
00080        QString tmp=weightLineEdit->text();
00081        weight_sscanf(tmp, "%lf", &weight);
00082        if(weight<0.0 || weight>100.0){
00083               QMessageBox::warning(this, tr("FET warning"),
00084                      tr("Invalid weight (percentage)"));
00085               return;
00086        }
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->activityTagName=activityTagName;
00097        this->_ctr->maxHoursDaily=maxHoursSpinBox->value();
00098 
00099        gt.rules.internalStructureComputed=false;
00100        setRulesModifiedAndOtherThings(&gt.rules);
00101        
00102        this->close();
00103 }
00104 
00105 void ModifyConstraintStudentsActivityTagMaxHoursDailyForm::cancel()
00106 {
00107        this->close();
00108 }