Back to index

fet  5.18.0
modifyconstraintteacherhomeroomform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintteacherhomeroomform.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 "modifyconstraintteacherhomeroomform.h"
00021 #include "spaceconstraint.h"
00022 
00023 ModifyConstraintTeacherHomeRoomForm::ModifyConstraintTeacherHomeRoomForm(QWidget* parent, ConstraintTeacherHomeRoom* ctr): QDialog(parent)
00024 {
00025        setupUi(this);
00026 
00027        okPushButton->setDefault(true);
00028 
00029        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
00030        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00031 
00032        centerWidgetOnScreen(this);
00033        restoreFETDialogGeometry(this);
00034 
00035        QSize tmp1=teachersComboBox->minimumSizeHint();
00036        Q_UNUSED(tmp1);
00037        
00038        QSize tmp5=roomsComboBox->minimumSizeHint();
00039        Q_UNUSED(tmp5);
00040        
00041        this->_ctr=ctr;
00042        
00043        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00044 
00045        updateTeachersComboBox();
00046        updateRoomsComboBox();
00047 }
00048 
00049 ModifyConstraintTeacherHomeRoomForm::~ModifyConstraintTeacherHomeRoomForm()
00050 {
00051        saveFETDialogGeometry(this);
00052 }
00053 
00054 void ModifyConstraintTeacherHomeRoomForm::updateTeachersComboBox(){
00055        teachersComboBox->clear();
00056        int i=0, j=-1;
00057        for(int k=0; k<gt.rules.teachersList.size(); k++, i++){
00058               Teacher* tch=gt.rules.teachersList[k];
00059               teachersComboBox->addItem(tch->name);
00060               if(tch->name==this->_ctr->teacherName)
00061                      j=i;
00062        }
00063        assert(j>=0);
00064        teachersComboBox->setCurrentIndex(j);
00065 }
00066 
00067 void ModifyConstraintTeacherHomeRoomForm::updateRoomsComboBox()
00068 {
00069        int i=0, j=-1;
00070        roomsComboBox->clear();
00071        for(int k=0; k<gt.rules.roomsList.size(); k++){
00072               Room* rm=gt.rules.roomsList[k];
00073               roomsComboBox->addItem(rm->name);
00074               if(rm->name==this->_ctr->roomName)
00075                      j=i;
00076               i++;
00077        }
00078        assert(j>=0);
00079        roomsComboBox->setCurrentIndex(j);
00080 }
00081 
00082 void ModifyConstraintTeacherHomeRoomForm::cancel()
00083 {
00084        this->close();
00085 }
00086 
00087 void ModifyConstraintTeacherHomeRoomForm::ok()
00088 {
00089        double weight;
00090        QString tmp=weightLineEdit->text();
00091        weight_sscanf(tmp, "%lf", &weight);
00092        if(weight<0.0 || weight>100){
00093               QMessageBox::warning(this, tr("FET information"),
00094                      tr("Invalid weight"));
00095               return;
00096        }
00097 
00098        QString teacher=teachersComboBox->currentText();
00099        assert(gt.rules.searchTeacher(teacher)>=0);
00100 
00101        int i=roomsComboBox->currentIndex();
00102        if(i<0 || roomsComboBox->count()<=0){
00103               QMessageBox::warning(this, tr("FET information"),
00104                      tr("Invalid room"));
00105               return;
00106        }
00107        QString room=roomsComboBox->currentText();
00108 
00109        this->_ctr->weightPercentage=weight;
00110        this->_ctr->roomName=room;
00111        this->_ctr->teacherName=teacher;
00112 
00113        gt.rules.internalStructureComputed=false;
00114        setRulesModifiedAndOtherThings(&gt.rules);
00115        
00116        this->close();
00117 }