Back to index

fet  5.18.0
addconstraintstudentssetactivitytagmaxhourscontinuouslyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintstudentssetactivitytagmaxhourscontinuouslyform.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 "addconstraintstudentssetactivitytagmaxhourscontinuouslyform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintStudentsSetActivityTagMaxHoursContinuouslyForm::AddConstraintStudentsSetActivityTagMaxHoursContinuouslyForm(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 AddConstraintStudentsSetActivityTagMaxHoursContinuouslyForm::~AddConstraintStudentsSetActivityTagMaxHoursContinuouslyForm()
00052 {
00053        saveFETDialogGeometry(this);
00054 }
00055 
00056 void AddConstraintStudentsSetActivityTagMaxHoursContinuouslyForm::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 AddConstraintStudentsSetActivityTagMaxHoursContinuouslyForm::updateActivityTagsComboBox()
00076 {
00077        foreach(ActivityTag* at, gt.rules.activityTagsList)
00078               activityTagsComboBox->addItem(at->name);
00079 
00080        constraintChanged();
00081 }
00082 
00083 void AddConstraintStudentsSetActivityTagMaxHoursContinuouslyForm::constraintChanged()
00084 {
00085 }
00086 
00087 void AddConstraintStudentsSetActivityTagMaxHoursContinuouslyForm::addCurrentConstraint()
00088 {
00089        TimeConstraint *ctr=NULL;
00090 
00091        double weight;
00092        QString tmp=weightLineEdit->text();
00093        weight_sscanf(tmp, "%lf", &weight);
00094        if(weight<0.0 || weight>100.0){
00095               QMessageBox::warning(this, tr("FET information"),
00096                      tr("Invalid weight"));
00097               return;
00098        }
00099 
00100        int maxHours=maxHoursSpinBox->value();
00101 
00102        QString students_name=studentsComboBox->currentText();
00103        StudentsSet* s=gt.rules.searchStudentsSet(students_name);
00104        if(s==NULL){
00105               QMessageBox::warning(this, tr("FET warning"),
00106                      tr("Invalid students set"));
00107               return;
00108        }
00109        
00110        QString activityTagName=activityTagsComboBox->currentText();
00111        int acttagindex=gt.rules.searchActivityTag(activityTagName);
00112        if(acttagindex<0){
00113               QMessageBox::warning(this, tr("FET warning"), tr("Invalid activity tag"));
00114               return;
00115        }
00116 
00117        ctr=new ConstraintStudentsSetActivityTagMaxHoursContinuously(weight, maxHours, students_name, activityTagName);
00118 
00119        bool tmp2=gt.rules.addTimeConstraint(ctr);
00120        if(tmp2)
00121               LongTextMessageBox::information(this, tr("FET information"),
00122                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00123        else{
00124               QMessageBox::warning(this, tr("FET information"),
00125                      tr("Constraint NOT added - please report error"));
00126               delete ctr;
00127        }
00128 }