Back to index

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