Back to index

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