Back to index

fet  5.18.0
addconstraintteacheractivitytagmaxhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintteacheractivitytagmaxhoursdailyform.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 "addconstraintteacheractivitytagmaxhoursdailyform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintTeacherActivityTagMaxHoursDailyForm::AddConstraintTeacherActivityTagMaxHoursDailyForm(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 tmp1=teachersComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp1);
00039        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00040        Q_UNUSED(tmp4);
00041        
00042        updateMaxHoursSpinBox();
00043 
00044        teachersComboBox->clear();
00045        for(int i=0; i<gt.rules.teachersList.size(); i++){
00046               Teacher* tch=gt.rules.teachersList[i];
00047               teachersComboBox->addItem(tch->name);
00048        }
00049        
00050        activityTagsComboBox->clear();
00051        foreach(ActivityTag* at, gt.rules.activityTagsList)
00052               activityTagsComboBox->addItem(at->name);
00053 
00054        constraintChanged();
00055 }
00056 
00057 AddConstraintTeacherActivityTagMaxHoursDailyForm::~AddConstraintTeacherActivityTagMaxHoursDailyForm()
00058 {
00059        saveFETDialogGeometry(this);
00060 }
00061 
00062 void AddConstraintTeacherActivityTagMaxHoursDailyForm::updateMaxHoursSpinBox(){
00063        maxHoursSpinBox->setMinimum(1);
00064        maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
00065        maxHoursSpinBox->setValue(gt.rules.nHoursPerDay);
00066 }
00067 
00068 void AddConstraintTeacherActivityTagMaxHoursDailyForm::constraintChanged()
00069 {
00070        //nothing
00071 }
00072 
00073 void AddConstraintTeacherActivityTagMaxHoursDailyForm::addCurrentConstraint()
00074 {
00075        TimeConstraint *ctr=NULL;
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 warning"),
00082                      tr("Invalid weight (percentage)"));
00083               return;
00084        }
00085 
00086        QString teacher_name=teachersComboBox->currentText();
00087        int teacher_ID=gt.rules.searchTeacher(teacher_name);
00088        if(teacher_ID<0){
00089               QMessageBox::warning(this, tr("FET warning"),
00090                      tr("Invalid teacher"));
00091               return;
00092        }
00093 
00094        QString activityTagName=activityTagsComboBox->currentText();
00095        int activityTagIndex=gt.rules.searchActivityTag(activityTagName);
00096        if(activityTagIndex<0){
00097               QMessageBox::warning(this, tr("FET warning"),
00098                      tr("Invalid activity tag"));
00099               return;
00100        }
00101 
00102        int max_hours=maxHoursSpinBox->value();
00103 
00104        ctr=new ConstraintTeacherActivityTagMaxHoursDaily(weight, max_hours, teacher_name, activityTagName);
00105 
00106        bool tmp2=gt.rules.addTimeConstraint(ctr);
00107        if(tmp2)
00108               LongTextMessageBox::information(this, tr("FET information"),
00109                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00110        else{
00111               QMessageBox::warning(this, tr("FET information"),
00112                      tr("Constraint NOT added - please report error"));
00113               delete ctr;
00114        }
00115 }