Back to index

fet  5.18.0
modifyconstraintstudentsintervalmaxdaysperweekform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintstudentsintervalmaxdaysperweekform.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 "modifyconstraintstudentsintervalmaxdaysperweekform.h"
00021 #include "timeconstraint.h"
00022 
00023 ModifyConstraintStudentsIntervalMaxDaysPerWeekForm::ModifyConstraintStudentsIntervalMaxDaysPerWeekForm(QWidget* parent, ConstraintStudentsIntervalMaxDaysPerWeek* ctr): QDialog(parent)
00024 {
00025        setupUi(this);
00026 
00027        okPushButton->setDefault(true);
00028 
00029        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00030        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
00031 
00032        centerWidgetOnScreen(this);
00033        restoreFETDialogGeometry(this);
00034 
00035        QSize tmp5=startHourComboBox->minimumSizeHint();
00036        Q_UNUSED(tmp5);
00037        QSize tmp6=endHourComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp6);
00039        
00040        this->_ctr=ctr;
00041        
00042        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00043        
00044        updateMaxDaysSpinBox();
00045 
00046        maxDaysSpinBox->setValue(ctr->maxDaysPerWeek);
00047        
00048        for(int i=0; i<gt.rules.nHoursPerDay; i++){
00049               startHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
00050        }
00051        startHourComboBox->setCurrentIndex(ctr->startHour);
00052 
00053        for(int i=0; i<gt.rules.nHoursPerDay; i++){
00054               endHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
00055        }
00056        endHourComboBox->addItem(tr("End of day"));
00057        endHourComboBox->setCurrentIndex(ctr->endHour);
00058 
00059        constraintChanged();
00060 }
00061 
00062 ModifyConstraintStudentsIntervalMaxDaysPerWeekForm::~ModifyConstraintStudentsIntervalMaxDaysPerWeekForm()
00063 {
00064        saveFETDialogGeometry(this);
00065 }
00066 
00067 void ModifyConstraintStudentsIntervalMaxDaysPerWeekForm::updateMaxDaysSpinBox(){
00068        maxDaysSpinBox->setMinimum(0);
00069        maxDaysSpinBox->setMaximum(gt.rules.nDaysPerWeek);      
00070 }
00071 
00072 void ModifyConstraintStudentsIntervalMaxDaysPerWeekForm::constraintChanged()
00073 {
00074 }
00075 
00076 void ModifyConstraintStudentsIntervalMaxDaysPerWeekForm::ok()
00077 {
00078        double weight;
00079        QString tmp=weightLineEdit->text();
00080        weight_sscanf(tmp, "%lf", &weight);
00081        if(weight<0.0 || weight>100.0){
00082               QMessageBox::warning(this, tr("FET information"),
00083                      tr("Invalid weight (percentage)"));
00084               return;
00085        }
00086        if(weight!=100.0){
00087               QMessageBox::warning(this, tr("FET information"),
00088                      tr("Invalid weight (percentage) - it has to be 100%"));
00089               return;
00090        }
00091 
00092        int max_days=maxDaysSpinBox->value();
00093 
00094        int startHour=startHourComboBox->currentIndex();
00095        int endHour=endHourComboBox->currentIndex();
00096        if(startHour<0 || startHour>=gt.rules.nHoursPerDay){
00097               QMessageBox::warning(this, tr("FET information"),
00098                tr("Start hour invalid"));
00099               return;
00100        }
00101        if(endHour<0 || endHour>gt.rules.nHoursPerDay){
00102               QMessageBox::warning(this, tr("FET information"),
00103                tr("End hour invalid"));
00104               return;
00105        }
00106        if(endHour<=startHour){
00107               QMessageBox::warning(this, tr("FET information"),
00108                tr("Start hour cannot be greater or equal than end hour"));
00109               return;
00110        }
00111 
00112        this->_ctr->weightPercentage=weight;
00113        this->_ctr->maxDaysPerWeek=max_days;
00114 
00115        this->_ctr->startHour=startHour;
00116        this->_ctr->endHour=endHour;
00117 
00118        gt.rules.internalStructureComputed=false;
00119        setRulesModifiedAndOtherThings(&gt.rules);
00120        
00121        this->close();
00122 }
00123 
00124 void ModifyConstraintStudentsIntervalMaxDaysPerWeekForm::cancel()
00125 {
00126        this->close();
00127 }