Back to index

fet  5.18.0
addconstraintteachersactivitytagmaxhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintteachersactivitytagmaxhoursdailyform.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 "longtextmessagebox.h"
00021 
00022 #include "addconstraintteachersactivitytagmaxhoursdailyform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintTeachersActivityTagMaxHoursDailyForm::AddConstraintTeachersActivityTagMaxHoursDailyForm(QWidget* parent): QDialog(parent)
00026 {
00027        setupUi(this);
00028 
00029        addConstraintPushButton->setDefault(true);
00030 
00031        connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addCurrentConstraint()));
00032        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00033 
00034        centerWidgetOnScreen(this);
00035        restoreFETDialogGeometry(this);
00036 
00037        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp4);
00039        
00040        updateMaxHoursSpinBox();
00041 
00042        activityTagsComboBox->clear();
00043        foreach(ActivityTag* at, gt.rules.activityTagsList)
00044               activityTagsComboBox->addItem(at->name);
00045 
00046        constraintChanged();
00047 }
00048 
00049 AddConstraintTeachersActivityTagMaxHoursDailyForm::~AddConstraintTeachersActivityTagMaxHoursDailyForm()
00050 {
00051        saveFETDialogGeometry(this);
00052 }
00053 
00054 void AddConstraintTeachersActivityTagMaxHoursDailyForm::updateMaxHoursSpinBox(){
00055        maxHoursSpinBox->setMinimum(1);
00056        maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
00057        maxHoursSpinBox->setValue(gt.rules.nHoursPerDay);
00058 }
00059 
00060 void AddConstraintTeachersActivityTagMaxHoursDailyForm::constraintChanged()
00061 {
00062        //nothing
00063 }
00064 
00065 void AddConstraintTeachersActivityTagMaxHoursDailyForm::addCurrentConstraint()
00066 {
00067        TimeConstraint *ctr=NULL;
00068 
00069        double weight;
00070        QString tmp=weightLineEdit->text();
00071        weight_sscanf(tmp, "%lf", &weight);
00072        if(weight<0.0 || weight>100.0){
00073               QMessageBox::warning(this, tr("FET warning"),
00074                      tr("Invalid weight (percentage)"));
00075               return;
00076        }
00077 
00078        QString activityTagName=activityTagsComboBox->currentText();
00079        int activityTagIndex=gt.rules.searchActivityTag(activityTagName);
00080        if(activityTagIndex<0){
00081               QMessageBox::warning(this, tr("FET warning"),
00082                      tr("Invalid activity tag"));
00083               return;
00084        }
00085 
00086        int max_hours=maxHoursSpinBox->value();
00087 
00088        ctr=new ConstraintTeachersActivityTagMaxHoursDaily(weight, max_hours, activityTagName);
00089 
00090        bool tmp2=gt.rules.addTimeConstraint(ctr);
00091        if(tmp2)
00092               LongTextMessageBox::information(this, tr("FET information"),
00093                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00094        else{
00095               QMessageBox::warning(this, tr("FET information"),
00096                      tr("Constraint NOT added - please report error"));
00097               delete ctr;
00098        }
00099 }