Back to index

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