Back to index

fet  5.18.0
addconstraintstudentsintervalmaxdaysperweekform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintstudentsintervalmaxdaysperweekform.cpp  -  description
00003                              -------------------
00004     begin                : 2008
00005     copyright            : (C) 2008 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 "addconstraintstudentsintervalmaxdaysperweekform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintStudentsIntervalMaxDaysPerWeekForm::AddConstraintStudentsIntervalMaxDaysPerWeekForm(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=startHourComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp1);
00039        QSize tmp2=endHourComboBox->minimumSizeHint();
00040        Q_UNUSED(tmp2);
00041 
00042        updateMaxDaysSpinBox();
00043        //updateStudentsComboBox();
00044        updateStartHoursComboBox();
00045        updateEndHoursComboBox();
00046 }
00047 
00048 AddConstraintStudentsIntervalMaxDaysPerWeekForm::~AddConstraintStudentsIntervalMaxDaysPerWeekForm()
00049 {
00050        saveFETDialogGeometry(this);
00051 }
00052 
00053 void AddConstraintStudentsIntervalMaxDaysPerWeekForm::updateMaxDaysSpinBox(){
00054        maxDaysSpinBox->setMinimum(0);
00055        maxDaysSpinBox->setMaximum(gt.rules.nDaysPerWeek);
00056        maxDaysSpinBox->setValue(gt.rules.nDaysPerWeek);
00057 }
00058 
00059 void AddConstraintStudentsIntervalMaxDaysPerWeekForm::updateStartHoursComboBox()
00060 {
00061        startHourComboBox->clear();
00062        for(int i=0; i<gt.rules.nHoursPerDay; i++)
00063               startHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
00064        startHourComboBox->setCurrentIndex(gt.rules.nHoursPerDay-1);
00065        
00066        constraintChanged();
00067 }
00068 
00069 void AddConstraintStudentsIntervalMaxDaysPerWeekForm::updateEndHoursComboBox()
00070 {
00071        endHourComboBox->clear();
00072        for(int i=0; i<gt.rules.nHoursPerDay; i++)
00073               endHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
00074        endHourComboBox->addItem(tr("End of day"));
00075        endHourComboBox->setCurrentIndex(gt.rules.nHoursPerDay);
00076        
00077        constraintChanged();
00078 }
00079 
00080 void AddConstraintStudentsIntervalMaxDaysPerWeekForm::constraintChanged()
00081 {
00082 }
00083 
00084 void AddConstraintStudentsIntervalMaxDaysPerWeekForm::addCurrentConstraint()
00085 {
00086        TimeConstraint *ctr=NULL;
00087 
00088        double weight;
00089        QString tmp=weightLineEdit->text();
00090        weight_sscanf(tmp, "%lf", &weight);
00091        if(weight<0.0 || weight>100.0){
00092               QMessageBox::warning(this, tr("FET information"),
00093                      tr("Invalid weight (percentage)"));
00094               return;
00095        }
00096        if(weight!=100.0){
00097               QMessageBox::warning(this, tr("FET information"),
00098                      tr("Invalid weight (percentage) - it has to be 100%"));
00099               return;
00100        }
00101 
00102        int max_days=maxDaysSpinBox->value();
00103        
00104        int startHour=startHourComboBox->currentIndex();
00105        int endHour=endHourComboBox->currentIndex();
00106        if(startHour<0 || startHour>=gt.rules.nHoursPerDay){
00107               QMessageBox::warning(this, tr("FET information"),
00108                      tr("Start hour invalid"));
00109               return;
00110        }
00111        if(endHour<0 || endHour>gt.rules.nHoursPerDay){
00112               QMessageBox::warning(this, tr("FET information"),
00113                      tr("End hour invalid"));
00114               return;
00115        }
00116        if(endHour<=startHour){
00117               QMessageBox::warning(this, tr("FET information"),
00118                      tr("Start hour cannot be greater or equal than end hour"));
00119               return;
00120        }
00121 
00122        ctr=new ConstraintStudentsIntervalMaxDaysPerWeek(weight, /*compulsory,*/ max_days, /*students_name,*/ startHour, endHour);
00123 
00124        bool tmp2=gt.rules.addTimeConstraint(ctr);
00125        if(tmp2)
00126               LongTextMessageBox::information(this, tr("FET information"),
00127                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00128        else{
00129               QMessageBox::warning(this, tr("FET information"),
00130                      tr("Constraint NOT added - please report error"));
00131               delete ctr;
00132        }
00133 }