Back to index

fet  5.18.0
addconstraintteachermaxbuildingchangesperweekform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintteachermaxbuildingchangesperweekform.cpp  -  description
00003                              -------------------
00004     begin                : Feb 10, 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 "addconstraintteachermaxbuildingchangesperweekform.h"
00023 #include "spaceconstraint.h"
00024 
00025 AddConstraintTeacherMaxBuildingChangesPerWeekForm::AddConstraintTeacherMaxBuildingChangesPerWeekForm(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        QSize tmp1=teachersComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp1);
00039               
00040        maxChangesSpinBox->setMinimum(0);
00041        maxChangesSpinBox->setMaximum(gt.rules.nHoursPerDay*gt.rules.nDaysPerWeek);
00042        maxChangesSpinBox->setValue(3);
00043 
00044        updateTeachersComboBox();
00045 }
00046 
00047 AddConstraintTeacherMaxBuildingChangesPerWeekForm::~AddConstraintTeacherMaxBuildingChangesPerWeekForm()
00048 {
00049        saveFETDialogGeometry(this);
00050 }
00051 
00052 void AddConstraintTeacherMaxBuildingChangesPerWeekForm::updateTeachersComboBox()
00053 {
00054        teachersComboBox->clear();
00055        foreach(Teacher* tch, gt.rules.teachersList)
00056               teachersComboBox->addItem(tch->name);
00057 
00058        constraintChanged();
00059 }
00060 
00061 void AddConstraintTeacherMaxBuildingChangesPerWeekForm::constraintChanged()
00062 {
00063 }
00064 
00065 void AddConstraintTeacherMaxBuildingChangesPerWeekForm::addCurrentConstraint()
00066 {
00067        SpaceConstraint *ctr=NULL;
00068 
00069        double weight;
00070        QString tmp=weightLineEdit->text();
00071        weight_sscanf(tmp, "%lf", &weight);
00072        if(weight<100.0 || 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        QString teacher_name=teachersComboBox->currentText();
00079        int t=gt.rules.searchTeacher(teacher_name);
00080        if(t==-1){
00081               QMessageBox::warning(this, tr("FET information"),
00082                      tr("Invalid teacher"));
00083               return;
00084        }
00085 
00086        ctr=new ConstraintTeacherMaxBuildingChangesPerWeek(weight, teacher_name, maxChangesSpinBox->value());
00087 
00088        bool tmp2=gt.rules.addSpaceConstraint(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 }