Back to index

fet  5.18.0
modifyconstraintstudentsminhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintstudentsminhoursdailyform.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 "modifyconstraintstudentsminhoursdailyform.h"
00021 #include "timeconstraint.h"
00022 
00023 ModifyConstraintStudentsMinHoursDailyForm::ModifyConstraintStudentsMinHoursDailyForm(QWidget* parent, ConstraintStudentsMinHoursDaily* 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        this->_ctr=ctr;
00036        
00037        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00038        
00039        allowEmptyDaysCheckBox->setChecked(ctr->allowEmptyDays);
00040        
00041        connect(allowEmptyDaysCheckBox, SIGNAL(toggled(bool)), this, SLOT(allowEmptyDaysCheckBoxToggled())); //after set checked!
00042 
00043        if(ENABLE_STUDENTS_MIN_HOURS_DAILY_WITH_ALLOW_EMPTY_DAYS)
00044               allowLabel->setText(tr("Advanced usage: enabled"));
00045        else
00046               allowLabel->setText(tr("Advanced usage: not enabled"));
00047        
00048        minHoursSpinBox->setMinimum(1);
00049        minHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
00050        minHoursSpinBox->setValue(ctr->minHoursDaily);
00051 }
00052 
00053 ModifyConstraintStudentsMinHoursDailyForm::~ModifyConstraintStudentsMinHoursDailyForm()
00054 {
00055        saveFETDialogGeometry(this);
00056 }
00057 
00058 void ModifyConstraintStudentsMinHoursDailyForm::constraintChanged()
00059 {
00060 }
00061 
00062 void ModifyConstraintStudentsMinHoursDailyForm::ok()
00063 {
00064        double weight;
00065        QString tmp=weightLineEdit->text();
00066        weight_sscanf(tmp, "%lf", &weight);
00067        if(weight<0.0 || weight>100.0){
00068               QMessageBox::warning(this, tr("FET information"),
00069                      tr("Invalid weight (percentage)"));
00070               return;
00071        }
00072        if(weight!=100.0){
00073               QMessageBox::warning(this, tr("FET information"),
00074                      tr("Invalid weight (percentage) - it has to be 100%"));
00075               return;
00076        }
00077 
00078        if(!ENABLE_STUDENTS_MIN_HOURS_DAILY_WITH_ALLOW_EMPTY_DAYS && allowEmptyDaysCheckBox->isChecked()){
00079               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."));
00080               return;
00081        }
00082 
00083        if(allowEmptyDaysCheckBox->isChecked() && minHoursSpinBox->value()<2){
00084               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)"));
00085               return;
00086        }
00087 
00088        this->_ctr->weightPercentage=weight;
00089        this->_ctr->minHoursDaily=minHoursSpinBox->value();
00090        
00091        this->_ctr->allowEmptyDays=allowEmptyDaysCheckBox->isChecked();
00092 
00093        gt.rules.internalStructureComputed=false;
00094        setRulesModifiedAndOtherThings(&gt.rules);
00095        
00096        this->close();
00097 }
00098 
00099 void ModifyConstraintStudentsMinHoursDailyForm::cancel()
00100 {
00101        this->close();
00102 }
00103 
00104 void ModifyConstraintStudentsMinHoursDailyForm::allowEmptyDaysCheckBoxToggled()
00105 {
00106        bool k=allowEmptyDaysCheckBox->isChecked();
00107        
00108        if(k && !ENABLE_STUDENTS_MIN_HOURS_DAILY_WITH_ALLOW_EMPTY_DAYS){
00109               allowEmptyDaysCheckBox->setChecked(false);
00110               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.",
00111                      "'Allow empty days' is an option which the user can enable and then he can select it.");
00112               s+="\n\n";
00113               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."
00114                      " Otherwise, it is IMPERATIVE (for performance reasons) to not select this option (or FET may not be able to find a timetable).");
00115               s+="\n\n";
00116               s+=tr("Use with caution.");
00117               QMessageBox::information(this, tr("FET information"), s);
00118        }
00119 }