Back to index

fet  5.18.0
addconstraintteachersmindaysperweekform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintteachersmindaysperweekform.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 "addconstraintteachersmindaysperweekform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintTeachersMinDaysPerWeekForm::AddConstraintTeachersMinDaysPerWeekForm(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        updateMinDaysSpinBox();
00038 }
00039 
00040 AddConstraintTeachersMinDaysPerWeekForm::~AddConstraintTeachersMinDaysPerWeekForm()
00041 {
00042        saveFETDialogGeometry(this);
00043 }
00044 
00045 void AddConstraintTeachersMinDaysPerWeekForm::updateMinDaysSpinBox(){
00046        minDaysSpinBox->setMinimum(1);
00047        minDaysSpinBox->setMaximum(gt.rules.nDaysPerWeek);
00048        minDaysSpinBox->setValue(1);
00049 }
00050 
00051 void AddConstraintTeachersMinDaysPerWeekForm::addCurrentConstraint()
00052 {
00053        TimeConstraint *ctr=NULL;
00054 
00055        double weight;
00056        QString tmp=weightLineEdit->text();
00057        weight_sscanf(tmp, "%lf", &weight);
00058        if(weight<0.0 || weight>100.0){
00059               QMessageBox::warning(this, tr("FET information"),
00060                      tr("Invalid weight (percentage)"));
00061               return;
00062        }
00063        if(weight!=100.0){
00064               QMessageBox::warning(this, tr("FET information"),
00065                      tr("Invalid weight (percentage) - it has to be 100%"));
00066               return;
00067        }
00068 
00069        int min_days=minDaysSpinBox->value();
00070 
00071        ctr=new ConstraintTeachersMinDaysPerWeek(weight, min_days);
00072 
00073        bool tmp2=gt.rules.addTimeConstraint(ctr);
00074        if(tmp2)
00075               LongTextMessageBox::information(this, tr("FET information"),
00076                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00077        else{
00078               QMessageBox::warning(this, tr("FET information"),
00079                      tr("Constraint NOT added - please report error"));
00080               delete ctr;
00081        }
00082 }