Back to index

fet  5.18.0
addconstraintteacherminhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintteacherminhoursdailyform.cpp  -  description
00003                              -------------------
00004     begin                : Sept. 21, 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 "addconstraintteacherminhoursdailyform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintTeacherMinHoursDailyForm::AddConstraintTeacherMinHoursDailyForm(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        updateMinHoursSpinBox();
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 AddConstraintTeacherMinHoursDailyForm::~AddConstraintTeacherMinHoursDailyForm()
00052 {
00053        saveFETDialogGeometry(this);
00054 }
00055 
00056 void AddConstraintTeacherMinHoursDailyForm::updateMinHoursSpinBox(){
00057        minHoursSpinBox->setMinimum(2);
00058        minHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
00059        minHoursSpinBox->setValue(2);
00060 }
00061 
00062 void AddConstraintTeacherMinHoursDailyForm::constraintChanged()
00063 {
00064 }
00065 
00066 void AddConstraintTeacherMinHoursDailyForm::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        if(weight!=100.0){
00079               QMessageBox::warning(this, tr("FET information"),
00080                      tr("Invalid weight (percentage) - must be 100%"));
00081               return;
00082        }
00083 
00084        QString teacher_name=teachersComboBox->currentText();
00085        int teacher_ID=gt.rules.searchTeacher(teacher_name);
00086        if(teacher_ID<0){
00087               QMessageBox::warning(this, tr("FET information"),
00088                      tr("Invalid teacher"));
00089               return;
00090        }
00091        
00092        if(!allowEmptyDaysCheckBox->isChecked()){
00093               QMessageBox::warning(this, tr("FET information"), tr("Allow empty days check box must be checked. If you need to not allow empty days for a teacher, "
00094                      "please use the constraint teacher min days per week"));
00095               return;
00096        }
00097 
00098        int min_hours=minHoursSpinBox->value();
00099 
00100        ctr=new ConstraintTeacherMinHoursDaily(weight, min_hours, teacher_name, allowEmptyDaysCheckBox->isChecked());
00101 
00102        bool tmp2=gt.rules.addTimeConstraint(ctr);
00103        if(tmp2)
00104               LongTextMessageBox::information(this, tr("FET information"),
00105                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00106        else{
00107               QMessageBox::warning(this, tr("FET information"),
00108                      tr("Constraint NOT added - please report error"));
00109               delete ctr;
00110        }
00111 }
00112 
00113 void AddConstraintTeacherMinHoursDailyForm::on_allowEmptyDaysCheckBox_toggled()
00114 {
00115        bool k=allowEmptyDaysCheckBox->isChecked();
00116 
00117        if(!k){
00118               allowEmptyDaysCheckBox->setChecked(true);
00119               QMessageBox::information(this, tr("FET information"), tr("This check box must remain checked. If you really need to not allow empty days for this teacher,"
00120                      " please use constraint teacher min days per week"));
00121        }
00122 }