Back to index

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