Back to index

fet  5.18.0
addconstraintteachermaxgapsperdayform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintteachersmaxgapsperdayform.cpp  -  description
00003                              -------------------
00004     begin                : Jan 21, 2008
00005     copyright            : (C) 2008 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 "addconstraintteachermaxgapsperdayform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintTeacherMaxGapsPerDayForm::AddConstraintTeacherMaxGapsPerDayForm(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        maxGapsSpinBox->setMinimum(0);
00041        maxGapsSpinBox->setMaximum(gt.rules.nHoursPerDay);
00042        maxGapsSpinBox->setValue(1);
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        constraintChanged();
00051 }
00052 
00053 AddConstraintTeacherMaxGapsPerDayForm::~AddConstraintTeacherMaxGapsPerDayForm()
00054 {
00055        saveFETDialogGeometry(this);
00056 }
00057 
00058 void AddConstraintTeacherMaxGapsPerDayForm::constraintChanged()
00059 {
00060 }
00061 
00062 void AddConstraintTeacherMaxGapsPerDayForm::addCurrentConstraint()
00063 {
00064        TimeConstraint *ctr=NULL;
00065 
00066        double weight;
00067        QString tmp=weightLineEdit->text();
00068        weight_sscanf(tmp, "%lf", &weight);
00069        if(weight<0.0 || weight>100.0){
00070               QMessageBox::warning(this, tr("FET information"),
00071                      tr("Invalid weight (percentage)"));
00072               return;
00073        }
00074        if(weight!=100.0){
00075               QMessageBox::warning(this, tr("FET information"),
00076                      tr("Invalid weight (percentage) - it must be 100%"));
00077               return;
00078        }
00079 
00080        QString teacher_name=teachersComboBox->currentText();
00081        int teacher_ID=gt.rules.searchTeacher(teacher_name);
00082        if(teacher_ID<0){
00083               QMessageBox::warning(this, tr("FET information"),
00084                      tr("Invalid teacher"));
00085               return;
00086        }
00087 
00088        ctr=new ConstraintTeacherMaxGapsPerDay(weight, teacher_name, maxGapsSpinBox->value());
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 }