Back to index

fet  5.18.0
addconstraintstudentssetactivitytagmaxhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintstudentssetactivitytagmaxhoursdailyform.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 "longtextmessagebox.h"
00021 
00022 #include "addconstraintstudentssetactivitytagmaxhoursdailyform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintStudentsSetActivityTagMaxHoursDailyForm::AddConstraintStudentsSetActivityTagMaxHoursDailyForm(QWidget* parent): QDialog(parent)
00026 {
00027        setupUi(this);
00028 
00029        addConstraintPushButton->setDefault(true);
00030 
00031        connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addCurrentConstraint()));
00032        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
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        maxHoursSpinBox->setMinimum(1);
00043        maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
00044        maxHoursSpinBox->setValue(gt.rules.nHoursPerDay);
00045 
00046        updateStudentsSetComboBox();
00047        
00048        updateActivityTagsComboBox();
00049 }
00050 
00051 AddConstraintStudentsSetActivityTagMaxHoursDailyForm::~AddConstraintStudentsSetActivityTagMaxHoursDailyForm()
00052 {
00053        saveFETDialogGeometry(this);
00054 }
00055 
00056 void AddConstraintStudentsSetActivityTagMaxHoursDailyForm::updateStudentsSetComboBox()
00057 {
00058        studentsComboBox->clear();  
00059        for(int i=0; i<gt.rules.yearsList.size(); i++){
00060               StudentsYear* sty=gt.rules.yearsList[i];
00061               studentsComboBox->addItem(sty->name);
00062               for(int j=0; j<sty->groupsList.size(); j++){
00063                      StudentsGroup* stg=sty->groupsList[j];
00064                      studentsComboBox->addItem(stg->name);
00065                      for(int k=0; k<stg->subgroupsList.size(); k++){
00066                             StudentsSubgroup* sts=stg->subgroupsList[k];
00067                             studentsComboBox->addItem(sts->name);
00068                      }
00069               }
00070        }
00071 
00072        constraintChanged();
00073 }
00074 
00075 void AddConstraintStudentsSetActivityTagMaxHoursDailyForm::updateActivityTagsComboBox()
00076 {
00077        foreach(ActivityTag* at, gt.rules.activityTagsList)
00078               activityTagsComboBox->addItem(at->name);
00079 
00080        constraintChanged();
00081 }
00082 
00083 void AddConstraintStudentsSetActivityTagMaxHoursDailyForm::constraintChanged()
00084 {
00085        //nothing
00086 }
00087 
00088 void AddConstraintStudentsSetActivityTagMaxHoursDailyForm::addCurrentConstraint()
00089 {
00090        TimeConstraint *ctr=NULL;
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"));
00098               return;
00099        }
00100 
00101        int maxHours=maxHoursSpinBox->value();
00102 
00103        QString students_name=studentsComboBox->currentText();
00104        StudentsSet* s=gt.rules.searchStudentsSet(students_name);
00105        if(s==NULL){
00106               QMessageBox::warning(this, tr("FET warning"),
00107                      tr("Invalid students set"));
00108               return;
00109        }
00110        
00111        QString activityTagName=activityTagsComboBox->currentText();
00112        int acttagindex=gt.rules.searchActivityTag(activityTagName);
00113        if(acttagindex<0){
00114               QMessageBox::warning(this, tr("FET warning"), tr("Invalid activity tag"));
00115               return;
00116        }
00117 
00118        ctr=new ConstraintStudentsSetActivityTagMaxHoursDaily(weight, maxHours, students_name, activityTagName);
00119 
00120        bool tmp2=gt.rules.addTimeConstraint(ctr);
00121        if(tmp2)
00122               LongTextMessageBox::information(this, tr("FET information"),
00123                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00124        else{
00125               QMessageBox::warning(this, tr("FET information"),
00126                      tr("Constraint NOT added - please report error"));
00127               delete ctr;
00128        }
00129 }