Back to index

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