Back to index

fet  5.18.0
modifyconstraintstudentssetminhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintstudentssetminhoursdailyform.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 "modifyconstraintstudentssetminhoursdailyform.h"
00021 #include "timeconstraint.h"
00022 
00023 ModifyConstraintStudentsSetMinHoursDailyForm::ModifyConstraintStudentsSetMinHoursDailyForm(QWidget* parent, ConstraintStudentsSetMinHoursDaily* ctr): QDialog(parent)
00024 {
00025        setupUi(this);
00026 
00027        okPushButton->setDefault(true);
00028 
00029        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00030        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
00031 
00032        centerWidgetOnScreen(this);
00033        restoreFETDialogGeometry(this);
00034 
00035        QSize tmp2=studentsComboBox->minimumSizeHint();
00036        Q_UNUSED(tmp2);
00037        
00038        this->_ctr=ctr;
00039        
00040        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00041        
00042        allowEmptyDaysCheckBox->setChecked(ctr->allowEmptyDays);
00043        
00044        connect(allowEmptyDaysCheckBox, SIGNAL(toggled(bool)), this, SLOT(allowEmptyDaysCheckBoxToggled())); //after set checked!
00045        
00046        if(ENABLE_STUDENTS_MIN_HOURS_DAILY_WITH_ALLOW_EMPTY_DAYS)
00047               allowLabel->setText(tr("Advanced usage: enabled"));
00048        else
00049               allowLabel->setText(tr("Advanced usage: not enabled"));
00050        
00051        updateStudentsComboBox();
00052 
00053        minHoursSpinBox->setMinimum(1);
00054        minHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
00055        minHoursSpinBox->setValue(ctr->minHoursDaily);
00056 
00057        constraintChanged();
00058 }
00059 
00060 ModifyConstraintStudentsSetMinHoursDailyForm::~ModifyConstraintStudentsSetMinHoursDailyForm()
00061 {
00062        saveFETDialogGeometry(this);
00063 }
00064 
00065 void ModifyConstraintStudentsSetMinHoursDailyForm::updateStudentsComboBox(){
00066        studentsComboBox->clear();
00067        int i=0, j=-1;
00068        for(int m=0; m<gt.rules.yearsList.size(); m++){
00069               StudentsYear* sty=gt.rules.yearsList[m];
00070               studentsComboBox->addItem(sty->name);
00071               if(sty->name==this->_ctr->students)
00072                      j=i;
00073               i++;
00074               for(int n=0; n<sty->groupsList.size(); n++){
00075                      StudentsGroup* stg=sty->groupsList[n];
00076                      studentsComboBox->addItem(stg->name);
00077                      if(stg->name==this->_ctr->students)
00078                             j=i;
00079                      i++;
00080                      for(int p=0; p<stg->subgroupsList.size(); p++){
00081                             StudentsSubgroup* sts=stg->subgroupsList[p];
00082                             studentsComboBox->addItem(sts->name);
00083                             if(sts->name==this->_ctr->students)
00084                                    j=i;
00085                             i++;
00086                      }
00087               }
00088        }
00089        assert(j>=0);
00090        studentsComboBox->setCurrentIndex(j);                                                                                                              
00091 
00092        constraintChanged();
00093 }
00094 
00095 void ModifyConstraintStudentsSetMinHoursDailyForm::constraintChanged()
00096 {
00097 }
00098 
00099 void ModifyConstraintStudentsSetMinHoursDailyForm::ok()
00100 {
00101        double weight;
00102        QString tmp=weightLineEdit->text();
00103        weight_sscanf(tmp, "%lf", &weight);
00104        if(weight<0.0 || weight>100.0){
00105               QMessageBox::warning(this, tr("FET information"),
00106                      tr("Invalid weight (percentage)"));
00107               return;
00108        }
00109        if(weight!=100.0){
00110               QMessageBox::warning(this, tr("FET information"),
00111                      tr("Invalid weight (percentage) - it has to be 100%"));
00112               return;
00113        }
00114 
00115        if(!ENABLE_STUDENTS_MIN_HOURS_DAILY_WITH_ALLOW_EMPTY_DAYS && allowEmptyDaysCheckBox->isChecked()){
00116               QMessageBox::warning(this, tr("FET warning"), tr("Empty days for students min hours daily constraints are not enabled. You must enable them from the Settings->Advanced menu."));
00117               return;
00118        }
00119 
00120        if(allowEmptyDaysCheckBox->isChecked() && minHoursSpinBox->value()<2){
00121               QMessageBox::warning(this, tr("FET warning"), tr("If you allow empty days, the min hours must be at least 2 (to make it a non-trivial constraint)"));
00122               return;
00123        }
00124 
00125        QString students_name=studentsComboBox->currentText();
00126        StudentsSet* s=gt.rules.searchStudentsSet(students_name);
00127        if(s==NULL){
00128               QMessageBox::warning(this, tr("FET information"),
00129                      tr("Invalid students set"));
00130               return;
00131        }
00132 
00133        this->_ctr->weightPercentage=weight;
00134        this->_ctr->students=students_name;
00135        this->_ctr->minHoursDaily=minHoursSpinBox->value();
00136 
00137        this->_ctr->allowEmptyDays=allowEmptyDaysCheckBox->isChecked();
00138 
00139        gt.rules.internalStructureComputed=false;
00140        setRulesModifiedAndOtherThings(&gt.rules);
00141        
00142        this->close();
00143 }
00144 
00145 void ModifyConstraintStudentsSetMinHoursDailyForm::cancel()
00146 {
00147        this->close();
00148 }
00149 
00150 void ModifyConstraintStudentsSetMinHoursDailyForm::allowEmptyDaysCheckBoxToggled()
00151 {
00152        bool k=allowEmptyDaysCheckBox->isChecked();
00153               
00154        if(k && !ENABLE_STUDENTS_MIN_HOURS_DAILY_WITH_ALLOW_EMPTY_DAYS){
00155               allowEmptyDaysCheckBox->setChecked(false);
00156               QString s=tr("Advanced usage is not enabled. To be able to select 'Allow empty days' for the constraints of type min hours daily for students, you must enable the option from the Settings->Advanced menu.",
00157                      "'Allow empty days' is an option which the user can enable and then he can select it.");
00158               s+="\n\n";
00159               s+=tr("Explanation: only select this option if your institution allows empty days for students and a timetable is possible with empty days for students."
00160                      " Otherwise, it is IMPERATIVE (for performance reasons) to not select this option (or FET may not be able to find a timetable).");
00161               s+="\n\n";
00162               s+=tr("Use with caution.");
00163               QMessageBox::information(this, tr("FET information"), s);
00164        }
00165 }