Back to index

fet  5.18.0
modifyconstraintstudentssethomeroomform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintstudentssethomeroomform.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 "modifyconstraintstudentssethomeroomform.h"
00021 #include "spaceconstraint.h"
00022 
00023 ModifyConstraintStudentsSetHomeRoomForm::ModifyConstraintStudentsSetHomeRoomForm(QWidget* parent, ConstraintStudentsSetHomeRoom* 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 tmp2=studentsComboBox->minimumSizeHint();
00036        Q_UNUSED(tmp2);
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        updateStudentsComboBox();
00046        updateRoomsComboBox();
00047 }
00048 
00049 ModifyConstraintStudentsSetHomeRoomForm::~ModifyConstraintStudentsSetHomeRoomForm()
00050 {
00051        saveFETDialogGeometry(this);
00052 }
00053 
00054 void ModifyConstraintStudentsSetHomeRoomForm::updateStudentsComboBox(){
00055        int i=0, j=-1;
00056        studentsComboBox->clear();
00057        for(int m=0; m<gt.rules.yearsList.size(); m++){
00058               StudentsYear* sty=gt.rules.yearsList[m];
00059               studentsComboBox->addItem(sty->name);
00060               if(sty->name==this->_ctr->studentsName)
00061                      j=i;
00062               i++;
00063               for(int n=0; n<sty->groupsList.size(); n++){
00064                      StudentsGroup* stg=sty->groupsList[n];
00065                      studentsComboBox->addItem(stg->name);
00066                      if(stg->name==this->_ctr->studentsName)
00067                             j=i;
00068                      i++;
00069                      for(int p=0; p<stg->subgroupsList.size(); p++){
00070                             StudentsSubgroup* sts=stg->subgroupsList[p];
00071                             studentsComboBox->addItem(sts->name);
00072                             if(sts->name==this->_ctr->studentsName)
00073                                    j=i;
00074                             i++;
00075                      }
00076               }
00077        }
00078        assert(j>=0);
00079        studentsComboBox->setCurrentIndex(j);
00080 }
00081 
00082 void ModifyConstraintStudentsSetHomeRoomForm::updateRoomsComboBox()
00083 {
00084        int i=0, j=-1;
00085        roomsComboBox->clear();
00086        for(int k=0; k<gt.rules.roomsList.size(); k++){
00087               Room* rm=gt.rules.roomsList[k];
00088               roomsComboBox->addItem(rm->name);
00089               if(rm->name==this->_ctr->roomName)
00090                      j=i;
00091               i++;
00092        }
00093        assert(j>=0);
00094        roomsComboBox->setCurrentIndex(j);
00095 }
00096 
00097 void ModifyConstraintStudentsSetHomeRoomForm::cancel()
00098 {
00099        this->close();
00100 }
00101 
00102 void ModifyConstraintStudentsSetHomeRoomForm::ok()
00103 {
00104        double weight;
00105        QString tmp=weightLineEdit->text();
00106        weight_sscanf(tmp, "%lf", &weight);
00107        if(weight<0.0 || weight>100){
00108               QMessageBox::warning(this, tr("FET information"),
00109                      tr("Invalid weight"));
00110               return;
00111        }
00112 
00113        QString students=studentsComboBox->currentText();
00114        assert(gt.rules.searchStudentsSet(students)!=NULL);
00115 
00116        int i=roomsComboBox->currentIndex();
00117        if(i<0 || roomsComboBox->count()<=0){
00118               QMessageBox::warning(this, tr("FET information"),
00119                      tr("Invalid room"));
00120               return;
00121        }
00122        QString room=roomsComboBox->currentText();
00123 
00124        this->_ctr->weightPercentage=weight;
00125        this->_ctr->roomName=room;
00126        this->_ctr->studentsName=students;
00127 
00128        gt.rules.internalStructureComputed=false;
00129        setRulesModifiedAndOtherThings(&gt.rules);
00130        
00131        this->close();
00132 }