Back to index

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