Back to index

fet  5.18.0
addconstraintstudentssetmaxhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintstudentssetmaxhoursdailyform.cpp  -  description
00003                              -------------------
00004     begin                : July 19, 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 "longtextmessagebox.h"
00021 
00022 #include "addconstraintstudentssetmaxhoursdailyform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintStudentsSetMaxHoursDailyForm::AddConstraintStudentsSetMaxHoursDailyForm(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 
00040        maxHoursSpinBox->setMinimum(1);
00041        maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
00042        maxHoursSpinBox->setValue(gt.rules.nHoursPerDay);
00043 
00044        updateStudentsSetComboBox();
00045 }
00046 
00047 AddConstraintStudentsSetMaxHoursDailyForm::~AddConstraintStudentsSetMaxHoursDailyForm()
00048 {
00049        saveFETDialogGeometry(this);
00050 }
00051 
00052 void AddConstraintStudentsSetMaxHoursDailyForm::updateStudentsSetComboBox()
00053 {
00054        studentsComboBox->clear();  
00055        for(int i=0; i<gt.rules.yearsList.size(); i++){
00056               StudentsYear* sty=gt.rules.yearsList[i];
00057               studentsComboBox->addItem(sty->name);
00058               for(int j=0; j<sty->groupsList.size(); j++){
00059                      StudentsGroup* stg=sty->groupsList[j];
00060                      studentsComboBox->addItem(stg->name);
00061                      for(int k=0; k<stg->subgroupsList.size(); k++){
00062                             StudentsSubgroup* sts=stg->subgroupsList[k];
00063                             studentsComboBox->addItem(sts->name);
00064                      }
00065               }
00066        }
00067 
00068        constraintChanged();
00069 }
00070 
00071 void AddConstraintStudentsSetMaxHoursDailyForm::constraintChanged()
00072 {
00073 }
00074 
00075 void AddConstraintStudentsSetMaxHoursDailyForm::addCurrentConstraint()
00076 {
00077        TimeConstraint *ctr=NULL;
00078 
00079        double weight;
00080        QString tmp=weightLineEdit->text();
00081        weight_sscanf(tmp, "%lf", &weight);
00082        if(weight<0.0 || weight>100.0){
00083               QMessageBox::warning(this, tr("FET information"),
00084                      tr("Invalid weight"));
00085               return;
00086        }
00087 
00088        int maxHours=maxHoursSpinBox->value();
00089 
00090        QString students_name=studentsComboBox->currentText();
00091        StudentsSet* s=gt.rules.searchStudentsSet(students_name);
00092        if(s==NULL){
00093               QMessageBox::warning(this, tr("FET information"),
00094                      tr("Invalid students set"));
00095               return;
00096        }
00097 
00098        ctr=new ConstraintStudentsSetMaxHoursDaily(weight, maxHours, students_name);
00099 
00100        bool tmp2=gt.rules.addTimeConstraint(ctr);
00101        if(tmp2)
00102               LongTextMessageBox::information(this, tr("FET information"),
00103                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00104        else{
00105               QMessageBox::warning(this, tr("FET information"),
00106                      tr("Constraint NOT added - please report error"));
00107               delete ctr;
00108        }
00109 }