Back to index

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