Back to index

fet  5.18.0
modifyconstraintstudentssetmaxgapsperdayform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintstudentssetmaxgapsperdayform.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 "modifyconstraintstudentssetmaxgapsperdayform.h"
00021 #include "timeconstraint.h"
00022 
00023 ModifyConstraintStudentsSetMaxGapsPerDayForm::ModifyConstraintStudentsSetMaxGapsPerDayForm(QWidget* parent, ConstraintStudentsSetMaxGapsPerDay* 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 tmp2=studentsComboBox->minimumSizeHint();
00036        Q_UNUSED(tmp2);
00037 
00038        
00039        this->_ctr=ctr;
00040        
00041        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00042 
00043        maxGapsSpinBox->setMinimum(0);
00044        maxGapsSpinBox->setMaximum(gt.rules.nHoursPerDay);
00045        maxGapsSpinBox->setValue(ctr->maxGaps);
00046        
00047        updateStudentsComboBox();
00048 
00049        constraintChanged();
00050 }
00051 
00052 ModifyConstraintStudentsSetMaxGapsPerDayForm::~ModifyConstraintStudentsSetMaxGapsPerDayForm()
00053 {
00054        saveFETDialogGeometry(this);
00055 }
00056 
00057 void ModifyConstraintStudentsSetMaxGapsPerDayForm::updateStudentsComboBox(){
00058        studentsComboBox->clear();
00059        int i=0, j=-1;
00060        for(int m=0; m<gt.rules.yearsList.size(); m++){
00061               StudentsYear* sty=gt.rules.yearsList[m];
00062               studentsComboBox->addItem(sty->name);
00063               if(sty->name==this->_ctr->students)
00064                      j=i;
00065               i++;
00066               for(int n=0; n<sty->groupsList.size(); n++){
00067                      StudentsGroup* stg=sty->groupsList[n];
00068                      studentsComboBox->addItem(stg->name);
00069                      if(stg->name==this->_ctr->students)
00070                             j=i;
00071                      i++;
00072                      for(int p=0; p<stg->subgroupsList.size(); p++){
00073                             StudentsSubgroup* sts=stg->subgroupsList[p];
00074                             studentsComboBox->addItem(sts->name);
00075                             if(sts->name==this->_ctr->students)
00076                                    j=i;
00077                             i++;
00078                      }
00079               }
00080        }
00081        assert(j>=0);
00082        studentsComboBox->setCurrentIndex(j);                                                                                                              
00083 
00084        constraintChanged();
00085 }
00086 
00087 void ModifyConstraintStudentsSetMaxGapsPerDayForm::constraintChanged()
00088 {
00089 }
00090 
00091 void ModifyConstraintStudentsSetMaxGapsPerDayForm::ok()
00092 {
00093        double weight;
00094        QString tmp=weightLineEdit->text();
00095        weight_sscanf(tmp, "%lf", &weight);
00096        if(weight<0.0 || weight>100.0){
00097               QMessageBox::warning(this, tr("FET information"),
00098                      tr("Invalid weight (percentage)"));
00099               return;
00100        }
00101        if(weight!=100.0){
00102               QMessageBox::warning(this, tr("FET information"),
00103                      tr("Invalid weight (percentage) - it must be 100%"));
00104               return;
00105        }
00106 
00107        QString students_name=studentsComboBox->currentText();
00108        StudentsSet* s=gt.rules.searchStudentsSet(students_name);
00109        if(s==NULL){
00110               QMessageBox::warning(this, tr("FET information"),
00111                      tr("Invalid students set"));
00112               return;
00113        }
00114 
00115        this->_ctr->weightPercentage=weight;
00116        this->_ctr->maxGaps=maxGapsSpinBox->value();
00117        this->_ctr->students=students_name;
00118 
00119        gt.rules.internalStructureComputed=false;
00120        setRulesModifiedAndOtherThings(&gt.rules);
00121        
00122        this->close();
00123 }
00124 
00125 void ModifyConstraintStudentsSetMaxGapsPerDayForm::cancel()
00126 {
00127        this->close();
00128 }