Back to index

fet  5.18.0
addconstraintteachermaxhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintteachermaxhoursdailyform.cpp  -  description
00003                              -------------------
00004     begin                : July 19, 2007
00005     copyright            : (C) 2007 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 "addconstraintteachermaxhoursdailyform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintTeacherMaxHoursDailyForm::AddConstraintTeacherMaxHoursDailyForm(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        
00040        updateMaxHoursSpinBox();
00041 
00042        teachersComboBox->clear();
00043        for(int i=0; i<gt.rules.teachersList.size(); i++){
00044               Teacher* tch=gt.rules.teachersList[i];
00045               teachersComboBox->addItem(tch->name);
00046        }
00047 
00048        constraintChanged();
00049 }
00050 
00051 AddConstraintTeacherMaxHoursDailyForm::~AddConstraintTeacherMaxHoursDailyForm()
00052 {
00053        saveFETDialogGeometry(this);
00054 }
00055 
00056 void AddConstraintTeacherMaxHoursDailyForm::updateMaxHoursSpinBox(){
00057        maxHoursSpinBox->setMinimum(1);
00058        maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
00059        maxHoursSpinBox->setValue(gt.rules.nHoursPerDay);
00060 }
00061 
00062 void AddConstraintTeacherMaxHoursDailyForm::constraintChanged()
00063 {
00064 }
00065 
00066 void AddConstraintTeacherMaxHoursDailyForm::addCurrentConstraint()
00067 {
00068        TimeConstraint *ctr=NULL;
00069 
00070        double weight;
00071        QString tmp=weightLineEdit->text();
00072        weight_sscanf(tmp, "%lf", &weight);
00073        if(weight<0.0 || weight>100.0){
00074               QMessageBox::warning(this, tr("FET information"),
00075                      tr("Invalid weight (percentage)"));
00076               return;
00077        }
00078 
00079        QString teacher_name=teachersComboBox->currentText();
00080        int teacher_ID=gt.rules.searchTeacher(teacher_name);
00081        if(teacher_ID<0){
00082               QMessageBox::warning(this, tr("FET information"),
00083                      tr("Invalid teacher"));
00084               return;
00085        }
00086 
00087        int max_hours=maxHoursSpinBox->value();
00088 
00089        ctr=new ConstraintTeacherMaxHoursDaily(weight, max_hours, teacher_name);
00090 
00091        bool tmp2=gt.rules.addTimeConstraint(ctr);
00092        if(tmp2)
00093               LongTextMessageBox::information(this, tr("FET information"),
00094                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00095        else{
00096               QMessageBox::warning(this, tr("FET information"),
00097                      tr("Constraint NOT added - please report error"));
00098               delete ctr;
00099        }
00100 }