Back to index

fet  5.18.0
addconstraintteachermindaysperweekform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintteachermindaysperweekform.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 "addconstraintteachermindaysperweekform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintTeacherMinDaysPerWeekForm::AddConstraintTeacherMinDaysPerWeekForm(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        updateMinDaysSpinBox();
00041        updateTeachersComboBox();
00042 }
00043 
00044 AddConstraintTeacherMinDaysPerWeekForm::~AddConstraintTeacherMinDaysPerWeekForm()
00045 {
00046        saveFETDialogGeometry(this);
00047 }
00048 
00049 void AddConstraintTeacherMinDaysPerWeekForm::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 
00057 void AddConstraintTeacherMinDaysPerWeekForm::updateMinDaysSpinBox(){
00058        minDaysSpinBox->setMinimum(1);
00059        minDaysSpinBox->setMaximum(gt.rules.nDaysPerWeek);
00060        minDaysSpinBox->setValue(1);
00061 }
00062 
00063 void AddConstraintTeacherMinDaysPerWeekForm::addCurrentConstraint()
00064 {
00065        TimeConstraint *ctr=NULL;
00066 
00067        double weight;
00068        QString tmp=weightLineEdit->text();
00069        weight_sscanf(tmp, "%lf", &weight);
00070        if(weight<0.0 || weight>100.0){
00071               QMessageBox::warning(this, tr("FET information"),
00072                      tr("Invalid weight (percentage)"));
00073               return;
00074        }
00075        if(weight!=100.0){
00076               QMessageBox::warning(this, tr("FET information"),
00077                      tr("Invalid weight (percentage) - it has to be 100%"));
00078               return;
00079        }
00080 
00081        int min_days=minDaysSpinBox->value();
00082 
00083        QString teacher_name=teachersComboBox->currentText();
00084        int teacher_ID=gt.rules.searchTeacher(teacher_name);
00085        if(teacher_ID<0){
00086               QMessageBox::warning(this, tr("FET information"),
00087                      tr("Invalid teacher"));
00088               return;
00089        }
00090 
00091        ctr=new ConstraintTeacherMinDaysPerWeek(weight, min_days, teacher_name);
00092 
00093        bool tmp2=gt.rules.addTimeConstraint(ctr);
00094        if(tmp2)
00095               LongTextMessageBox::information(this, tr("FET information"),
00096                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00097        else{
00098               QMessageBox::warning(this, tr("FET information"),
00099                      tr("Constraint NOT added - please report error"));
00100               delete ctr;
00101        }
00102 }