Back to index

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