Back to index

fet  5.18.0
addconstraintteachersactivitytagmaxhourscontinuouslyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintteachersactivitytagmaxhourscontinuouslyform.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 "addconstraintteachersactivitytagmaxhourscontinuouslyform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintTeachersActivityTagMaxHoursContinuouslyForm::AddConstraintTeachersActivityTagMaxHoursContinuouslyForm(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 AddConstraintTeachersActivityTagMaxHoursContinuouslyForm::~AddConstraintTeachersActivityTagMaxHoursContinuouslyForm()
00050 {
00051        saveFETDialogGeometry(this);
00052 }
00053 
00054 void AddConstraintTeachersActivityTagMaxHoursContinuouslyForm::updateMaxHoursSpinBox(){
00055        maxHoursSpinBox->setMinimum(1);
00056        maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
00057        maxHoursSpinBox->setValue(gt.rules.nHoursPerDay);
00058 }
00059 
00060 void AddConstraintTeachersActivityTagMaxHoursContinuouslyForm::constraintChanged()
00061 {
00062 }
00063 
00064 void AddConstraintTeachersActivityTagMaxHoursContinuouslyForm::addCurrentConstraint()
00065 {
00066        TimeConstraint *ctr=NULL;
00067 
00068        double weight;
00069        QString tmp=weightLineEdit->text();
00070        weight_sscanf(tmp, "%lf", &weight);
00071        if(weight<0.0 || weight>100.0){
00072               QMessageBox::warning(this, tr("FET warning"),
00073                      tr("Invalid weight (percentage)"));
00074               return;
00075        }
00076 
00077        QString activityTagName=activityTagsComboBox->currentText();
00078        int activityTagIndex=gt.rules.searchActivityTag(activityTagName);
00079        if(activityTagIndex<0){
00080               QMessageBox::warning(this, tr("FET warning"),
00081                      tr("Invalid activity tag"));
00082               return;
00083        }
00084 
00085        int max_hours=maxHoursSpinBox->value();
00086 
00087        ctr=new ConstraintTeachersActivityTagMaxHoursContinuously(weight, max_hours, activityTagName);
00088 
00089        bool tmp2=gt.rules.addTimeConstraint(ctr);
00090        if(tmp2)
00091               LongTextMessageBox::information(this, tr("FET information"),
00092                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00093        else{
00094               QMessageBox::warning(this, tr("FET information"),
00095                      tr("Constraint NOT added - please report error"));
00096               delete ctr;
00097        }
00098 }