Back to index

fet  5.18.0
addconstraintstudentsminhoursdailyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintstudentsminhoursdailyform.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 "addconstraintstudentsminhoursdailyform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintStudentsMinHoursDailyForm::AddConstraintStudentsMinHoursDailyForm(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("Avdanced usage: not enabled"));
00041        
00042        minHoursSpinBox->setMinimum(1);
00043        minHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
00044        minHoursSpinBox->setValue(1);
00045 }
00046 
00047 AddConstraintStudentsMinHoursDailyForm::~AddConstraintStudentsMinHoursDailyForm()
00048 {
00049        saveFETDialogGeometry(this);
00050 }
00051 
00052 void AddConstraintStudentsMinHoursDailyForm::constraintChanged()
00053 {
00054 }
00055 
00056 void AddConstraintStudentsMinHoursDailyForm::addCurrentConstraint()
00057 {
00058        TimeConstraint *ctr=NULL;
00059 
00060        double weight;
00061        QString tmp=weightLineEdit->text();
00062        weight_sscanf(tmp, "%lf", &weight);
00063        if(weight<0.0 || weight>100.0){
00064               QMessageBox::warning(this, tr("FET information"),
00065                      tr("Invalid weight (percentage)"));
00066               return;
00067        }
00068        if(weight!=100.0){
00069               QMessageBox::warning(this, tr("FET information"),
00070                      tr("Invalid weight (percentage) - it has to be 100%"));
00071               return;
00072        }
00073        
00074        if(!ENABLE_STUDENTS_MIN_HOURS_DAILY_WITH_ALLOW_EMPTY_DAYS && allowEmptyDaysCheckBox->isChecked()){
00075               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."));
00076               return;
00077        }
00078        
00079        if(allowEmptyDaysCheckBox->isChecked() && minHoursSpinBox->value()<2){
00080               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)"));
00081               return;
00082        }
00083        
00084        int minHours=minHoursSpinBox->value();
00085 
00086        ctr=new ConstraintStudentsMinHoursDaily(weight, minHours, allowEmptyDaysCheckBox->isChecked());
00087 
00088        bool tmp2=gt.rules.addTimeConstraint(ctr);
00089        if(tmp2)
00090               LongTextMessageBox::information(this, tr("FET information"),
00091                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00092        else{
00093               QMessageBox::warning(this, tr("FET information"),
00094                      tr("Constraint NOT added - please report error"));
00095               delete ctr;
00096        }
00097 }
00098 
00099 void AddConstraintStudentsMinHoursDailyForm::on_allowEmptyDaysCheckBox_toggled()
00100 {
00101        bool k=allowEmptyDaysCheckBox->isChecked();
00102        
00103        if(k && !ENABLE_STUDENTS_MIN_HOURS_DAILY_WITH_ALLOW_EMPTY_DAYS){
00104               allowEmptyDaysCheckBox->setChecked(false);
00105               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.",
00106                      "'Allow empty days' is an option which the user can enable and then he can select it.");
00107               s+="\n\n";
00108               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."
00109                      " Otherwise, it is IMPERATIVE (for performance reasons) to not select this option (or FET may not be able to find a timetable).");
00110               s+="\n\n";
00111               s+=tr("Use with caution.");
00112               QMessageBox::information(this, tr("FET information"), s);
00113        }
00114 }