Back to index

fet  5.18.0
addconstraintteachersminhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintteachersminhoursdailyform.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 "addconstraintteachersminhoursdailyform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintTeachersMinHoursDailyForm::AddConstraintTeachersMinHoursDailyForm(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        updateMinHoursSpinBox();
00038        
00039        constraintChanged();
00040 }
00041 
00042 AddConstraintTeachersMinHoursDailyForm::~AddConstraintTeachersMinHoursDailyForm()
00043 {
00044        saveFETDialogGeometry(this);
00045 }
00046 
00047 void AddConstraintTeachersMinHoursDailyForm::updateMinHoursSpinBox(){
00048        minHoursSpinBox->setMinimum(2);
00049        minHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
00050        minHoursSpinBox->setValue(2);
00051 }
00052 
00053 void AddConstraintTeachersMinHoursDailyForm::constraintChanged()
00054 {
00055 }
00056 
00057 void AddConstraintTeachersMinHoursDailyForm::addCurrentConstraint()
00058 {
00059        TimeConstraint *ctr=NULL;
00060 
00061        double weight;
00062        QString tmp=weightLineEdit->text();
00063        weight_sscanf(tmp, "%lf", &weight);
00064        if(weight<0.0 || weight>100.0){
00065               QMessageBox::warning(this, tr("FET information"),
00066                      tr("Invalid weight (percentage)"));
00067               return;
00068        }
00069        if(weight!=100.0){
00070               QMessageBox::warning(this, tr("FET information"),
00071                      tr("Invalid weight (percentage) - must be 100%"));
00072               return;
00073        }
00074 
00075        if(!allowEmptyDaysCheckBox->isChecked()){
00076               QMessageBox::warning(this, tr("FET information"), tr("Allow empty days check box must be checked. If you need to not allow empty days for the teachers, "
00077                      "please use the constraint teachers min days per week"));
00078               return;
00079        }
00080 
00081        int min_hours=minHoursSpinBox->value();
00082 
00083        ctr=new ConstraintTeachersMinHoursDaily(weight, min_hours, allowEmptyDaysCheckBox->isChecked());
00084 
00085        bool tmp2=gt.rules.addTimeConstraint(ctr);
00086        if(tmp2)
00087               LongTextMessageBox::information(this, tr("FET information"),
00088                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00089        else{
00090               QMessageBox::warning(this, tr("FET information"),
00091                      tr("Constraint NOT added - please report error"));
00092               delete ctr;
00093        }
00094 }
00095 
00096 void AddConstraintTeachersMinHoursDailyForm::on_allowEmptyDaysCheckBox_toggled()
00097 {
00098        bool k=allowEmptyDaysCheckBox->isChecked();
00099 
00100        if(!k){
00101               allowEmptyDaysCheckBox->setChecked(true);
00102               QMessageBox::information(this, tr("FET information"), tr("This check box must remain checked. If you really need to not allow empty days for the teachers,"
00103                      " please use constraint teachers min days per week"));
00104        }
00105 }