Back to index

fet  5.18.0
addconstraintstudentssetminhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintstudentssetminhoursdailyform.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 "addconstraintstudentssetminhoursdailyform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintStudentsSetMinHoursDailyForm::AddConstraintStudentsSetMinHoursDailyForm(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        if(ENABLE_STUDENTS_MIN_HOURS_DAILY_WITH_ALLOW_EMPTY_DAYS)
00038               allowLabel->setText(tr("Advanced usage: enabled"));
00039        else
00040               allowLabel->setText(tr("Advanced usage: not enabled"));
00041        
00042        QSize tmp2=studentsComboBox->minimumSizeHint();
00043        Q_UNUSED(tmp2);
00044 
00045        minHoursSpinBox->setMinimum(1);
00046        minHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
00047        minHoursSpinBox->setValue(1);
00048 
00049        updateStudentsSetComboBox();
00050 }
00051 
00052 AddConstraintStudentsSetMinHoursDailyForm::~AddConstraintStudentsSetMinHoursDailyForm()
00053 {
00054        saveFETDialogGeometry(this);
00055 }
00056 
00057 void AddConstraintStudentsSetMinHoursDailyForm::updateStudentsSetComboBox()
00058 {
00059        studentsComboBox->clear();
00060        for(int i=0; i<gt.rules.yearsList.size(); i++){
00061               StudentsYear* sty=gt.rules.yearsList[i];
00062               studentsComboBox->addItem(sty->name);
00063               for(int j=0; j<sty->groupsList.size(); j++){
00064                      StudentsGroup* stg=sty->groupsList[j];
00065                      studentsComboBox->addItem(stg->name);
00066                      for(int k=0; k<stg->subgroupsList.size(); k++){
00067                             StudentsSubgroup* sts=stg->subgroupsList[k];
00068                             studentsComboBox->addItem(sts->name);
00069                      }
00070               }
00071        }
00072 
00073        constraintChanged();
00074 }
00075 
00076 void AddConstraintStudentsSetMinHoursDailyForm::constraintChanged()
00077 {
00078 }
00079 
00080 void AddConstraintStudentsSetMinHoursDailyForm::addCurrentConstraint()
00081 {
00082        TimeConstraint *ctr=NULL;
00083 
00084        double weight;
00085        QString tmp=weightLineEdit->text();
00086        weight_sscanf(tmp, "%lf", &weight);
00087        if(weight<0.0 || weight>100.0){
00088               QMessageBox::warning(this, tr("FET information"),
00089                      tr("Invalid weight"));
00090               return;
00091        }
00092        if(weight!=100.0){
00093               QMessageBox::warning(this, tr("FET information"),
00094                      tr("Invalid weight - it has to be 100%"));
00095               return;
00096        }
00097 
00098        if(!ENABLE_STUDENTS_MIN_HOURS_DAILY_WITH_ALLOW_EMPTY_DAYS && allowEmptyDaysCheckBox->isChecked()){
00099               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."));
00100               return;
00101        }
00102 
00103        if(allowEmptyDaysCheckBox->isChecked() && minHoursSpinBox->value()<2){
00104               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)"));
00105               return;
00106        }
00107 
00108        int minHours=minHoursSpinBox->value();
00109 
00110        QString students_name=studentsComboBox->currentText();
00111        StudentsSet* s=gt.rules.searchStudentsSet(students_name);
00112        if(s==NULL){
00113               QMessageBox::warning(this, tr("FET information"),
00114                      tr("Invalid students set"));
00115               return;
00116        }
00117 
00118        ctr=new ConstraintStudentsSetMinHoursDaily(weight, minHours, students_name, allowEmptyDaysCheckBox->isChecked());
00119 
00120        bool tmp2=gt.rules.addTimeConstraint(ctr);
00121        if(tmp2)
00122               LongTextMessageBox::information(this, tr("FET information"),
00123                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00124        else{
00125               QMessageBox::warning(this, tr("FET information"),
00126                      tr("Constraint NOT added - please report error"));
00127               delete ctr;
00128        }
00129 }
00130 
00131 void AddConstraintStudentsSetMinHoursDailyForm::on_allowEmptyDaysCheckBox_toggled()
00132 {
00133        bool k=allowEmptyDaysCheckBox->isChecked();
00134               
00135        if(k && !ENABLE_STUDENTS_MIN_HOURS_DAILY_WITH_ALLOW_EMPTY_DAYS){
00136               allowEmptyDaysCheckBox->setChecked(false);
00137               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.",
00138                      "'Allow empty days' is an option which the user can enable and then he can select it.");
00139               s+="\n\n";
00140               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."
00141                      " Otherwise, it is IMPERATIVE (for performance reasons) to not select this option (or FET may not be able to find a timetable).");
00142               s+="\n\n";
00143               s+=tr("Use with caution.");
00144               QMessageBox::information(this, tr("FET information"), s);
00145        }
00146 }