Back to index

fet  5.18.0
addconstraintteacherhomeroomform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintteacherhomeroomform.cpp  -  description
00003                              -------------------
00004     begin                : 8 Apr 2005
00005     copyright            : (C) 2005 by Liviu Lalescu
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 "addconstraintteacherhomeroomform.h"
00023 #include "spaceconstraint.h"
00024 
00025 AddConstraintTeacherHomeRoomForm::AddConstraintTeacherHomeRoomForm(QWidget* parent): QDialog(parent)
00026 {
00027        setupUi(this);
00028 
00029        addConstraintPushButton->setDefault(true);
00030 
00031        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00032        connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addConstraint()));
00033 
00034        centerWidgetOnScreen(this);
00035        restoreFETDialogGeometry(this);
00036 
00037        QSize tmp1=teachersComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp1);
00039        
00040        QSize tmp5=roomsComboBox->minimumSizeHint();
00041        Q_UNUSED(tmp5);
00042        
00043        updateTeachersComboBox();
00044        updateRoomsComboBox();
00045 }
00046 
00047 AddConstraintTeacherHomeRoomForm::~AddConstraintTeacherHomeRoomForm()
00048 {
00049        saveFETDialogGeometry(this);
00050 }
00051 
00052 void AddConstraintTeacherHomeRoomForm::updateTeachersComboBox(){
00053        teachersComboBox->clear();
00054        foreach(Teacher* tch, gt.rules.teachersList)
00055               teachersComboBox->addItem(tch->name);
00056 }
00057 
00058 void AddConstraintTeacherHomeRoomForm::updateRoomsComboBox()
00059 {
00060        roomsComboBox->clear();
00061        for(int i=0; i<gt.rules.roomsList.size(); i++){
00062               Room* rm=gt.rules.roomsList[i];
00063               roomsComboBox->addItem(rm->name);
00064        }
00065 }
00066 
00067 void AddConstraintTeacherHomeRoomForm::addConstraint()
00068 {
00069        SpaceConstraint *ctr=NULL;
00070 
00071        double weight;
00072        QString tmp=weightLineEdit->text();
00073        weight_sscanf(tmp, "%lf", &weight);
00074        if(weight<0.0 || weight>100){
00075               QMessageBox::warning(this, tr("FET information"),
00076                      tr("Invalid weight"));
00077               return;
00078        }
00079 
00080        QString teacher=teachersComboBox->currentText();
00081        assert(gt.rules.searchTeacher(teacher)>=0);
00082 
00083        int i=roomsComboBox->currentIndex();
00084        if(i<0 || roomsComboBox->count()<=0){
00085               QMessageBox::warning(this, tr("FET information"),
00086                      tr("Invalid room"));
00087               return;
00088        }
00089        QString room=roomsComboBox->currentText();
00090 
00091        ctr=new ConstraintTeacherHomeRoom(weight, teacher, room);
00092 
00093        bool tmp2=gt.rules.addSpaceConstraint(ctr);
00094        if(tmp2){
00095               QString s=tr("Constraint added:");
00096               s+="\n\n";
00097               s+=ctr->getDetailedDescription(gt.rules);
00098               LongTextMessageBox::information(this, tr("FET information"), s);
00099        }
00100        else{
00101               QMessageBox::warning(this, tr("FET information"),
00102                      tr("Constraint NOT added - error ?"));
00103               delete ctr;
00104        }
00105 }