Back to index

fet  5.18.0
modifyconstraintstudentssetintervalmaxdaysperweekform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintstudentssetintervalmaxdaysperweekform.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 
00021 
00022 #include "modifyconstraintstudentssetintervalmaxdaysperweekform.h"
00023 #include "timeconstraint.h"
00024 
00025 ModifyConstraintStudentsSetIntervalMaxDaysPerWeekForm::ModifyConstraintStudentsSetIntervalMaxDaysPerWeekForm(QWidget* parent, ConstraintStudentsSetIntervalMaxDaysPerWeek* ctr): QDialog(parent)
00026 {
00027        setupUi(this);
00028 
00029        okPushButton->setDefault(true);
00030 
00031        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00032        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
00033 
00034        centerWidgetOnScreen(this);
00035        restoreFETDialogGeometry(this);
00036 
00037        QSize tmp2=studentsComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp2);
00039        
00040        QSize tmp5=startHourComboBox->minimumSizeHint();
00041        Q_UNUSED(tmp5);
00042        QSize tmp6=endHourComboBox->minimumSizeHint();
00043        Q_UNUSED(tmp6);
00044        
00045        this->_ctr=ctr;
00046        
00047        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00048        
00049        updateMaxDaysSpinBox();
00050        updateStudentsComboBox();
00051        
00052        maxDaysSpinBox->setValue(ctr->maxDaysPerWeek);
00053        
00054        for(int i=0; i<gt.rules.nHoursPerDay; i++){
00055               startHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
00056        }
00057        startHourComboBox->setCurrentIndex(ctr->startHour);
00058 
00059        for(int i=0; i<gt.rules.nHoursPerDay; i++){
00060               endHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
00061        }
00062        endHourComboBox->addItem(tr("End of day"));
00063        endHourComboBox->setCurrentIndex(ctr->endHour);
00064 
00065        constraintChanged();
00066 }
00067 
00068 ModifyConstraintStudentsSetIntervalMaxDaysPerWeekForm::~ModifyConstraintStudentsSetIntervalMaxDaysPerWeekForm()
00069 {
00070        saveFETDialogGeometry(this);
00071 }
00072 
00073 void ModifyConstraintStudentsSetIntervalMaxDaysPerWeekForm::updateStudentsComboBox(){
00074        studentsComboBox->clear();
00075        int i=0, j=-1;
00076        for(int m=0; m<gt.rules.yearsList.size(); m++){
00077               StudentsYear* sty=gt.rules.yearsList[m];
00078               studentsComboBox->addItem(sty->name);
00079               if(sty->name==this->_ctr->students)
00080                      j=i;
00081               i++;
00082               for(int n=0; n<sty->groupsList.size(); n++){
00083                      StudentsGroup* stg=sty->groupsList[n];
00084                      studentsComboBox->addItem(stg->name);
00085                      if(stg->name==this->_ctr->students)
00086                             j=i;
00087                      i++;
00088                      for(int p=0; p<stg->subgroupsList.size(); p++){
00089                             StudentsSubgroup* sts=stg->subgroupsList[p];
00090                             studentsComboBox->addItem(sts->name);
00091                             if(sts->name==this->_ctr->students)
00092                                    j=i;
00093                             i++;
00094                      }
00095               }
00096        }
00097        assert(j>=0);
00098        studentsComboBox->setCurrentIndex(j);                                                                                                              
00099 
00100        constraintChanged();
00101 }
00102 
00103 void ModifyConstraintStudentsSetIntervalMaxDaysPerWeekForm::updateMaxDaysSpinBox(){
00104        maxDaysSpinBox->setMinimum(0);
00105        maxDaysSpinBox->setMaximum(gt.rules.nDaysPerWeek);      
00106 }
00107 
00108 void ModifyConstraintStudentsSetIntervalMaxDaysPerWeekForm::constraintChanged()
00109 {
00110 }
00111 
00112 void ModifyConstraintStudentsSetIntervalMaxDaysPerWeekForm::ok()
00113 {
00114        double weight;
00115        QString tmp=weightLineEdit->text();
00116        weight_sscanf(tmp, "%lf", &weight);
00117        if(weight<0.0 || weight>100.0){
00118               QMessageBox::warning(this, tr("FET information"),
00119                      tr("Invalid weight (percentage)"));
00120               return;
00121        }
00122        if(weight!=100.0){
00123               QMessageBox::warning(this, tr("FET information"),
00124                      tr("Invalid weight (percentage) - it has to be 100%"));
00125               return;
00126        }
00127 
00128        int max_days=maxDaysSpinBox->value();
00129 
00130        QString students_name=studentsComboBox->currentText();
00131        StudentsSet* s=gt.rules.searchStudentsSet(students_name);
00132        if(s==NULL){
00133               QMessageBox::warning(this, tr("FET information"),
00134                      tr("Invalid students set"));
00135               return;
00136        }
00137        
00138        int startHour=startHourComboBox->currentIndex();
00139        int endHour=endHourComboBox->currentIndex();
00140        if(startHour<0 || startHour>=gt.rules.nHoursPerDay){
00141               QMessageBox::warning(this, tr("FET information"),
00142                tr("Start hour invalid"));
00143               return;
00144        }
00145        if(endHour<0 || endHour>gt.rules.nHoursPerDay){
00146               QMessageBox::warning(this, tr("FET information"),
00147                tr("End hour invalid"));
00148               return;
00149        }
00150        if(endHour<=startHour){
00151               QMessageBox::warning(this, tr("FET information"),
00152                tr("Start hour cannot be greater or equal than end hour"));
00153               return;
00154        }
00155 
00156        this->_ctr->weightPercentage=weight;
00157        this->_ctr->maxDaysPerWeek=max_days;
00158        this->_ctr->students=students_name;
00159 
00160        this->_ctr->startHour=startHour;
00161        this->_ctr->endHour=endHour;
00162 
00163        gt.rules.internalStructureComputed=false;
00164        setRulesModifiedAndOtherThings(&gt.rules);
00165        
00166        this->close();
00167 }
00168 
00169 void ModifyConstraintStudentsSetIntervalMaxDaysPerWeekForm::cancel()
00170 {
00171        this->close();
00172 }