Back to index

fet  5.18.0
addconstraintstudentssethomeroomform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintstudentssethomeroomform.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 "addconstraintstudentssethomeroomform.h"
00023 #include "spaceconstraint.h"
00024 
00025 AddConstraintStudentsSetHomeRoomForm::AddConstraintStudentsSetHomeRoomForm(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 tmp2=studentsComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp2);
00039        
00040        QSize tmp5=roomsComboBox->minimumSizeHint();
00041        Q_UNUSED(tmp5);
00042 
00043        updateStudentsComboBox();
00044        updateRoomsComboBox();
00045 }
00046 
00047 AddConstraintStudentsSetHomeRoomForm::~AddConstraintStudentsSetHomeRoomForm()
00048 {
00049        saveFETDialogGeometry(this);
00050 }
00051 
00052 void AddConstraintStudentsSetHomeRoomForm::updateStudentsComboBox(){
00053        studentsComboBox->clear();
00054        for(int i=0; i<gt.rules.yearsList.size(); i++){
00055               StudentsYear* sty=gt.rules.yearsList[i];
00056               studentsComboBox->addItem(sty->name);
00057               for(int j=0; j<sty->groupsList.size(); j++){
00058                      StudentsGroup* stg=sty->groupsList[j];
00059                      studentsComboBox->addItem(stg->name);
00060                      for(int k=0; k<stg->subgroupsList.size(); k++){
00061                             StudentsSubgroup* sts=stg->subgroupsList[k];
00062                             studentsComboBox->addItem(sts->name);
00063                      }
00064               }
00065        }
00066 }
00067 
00068 void AddConstraintStudentsSetHomeRoomForm::updateRoomsComboBox()
00069 {
00070        roomsComboBox->clear();
00071        for(int i=0; i<gt.rules.roomsList.size(); i++){
00072               Room* rm=gt.rules.roomsList[i];
00073               roomsComboBox->addItem(rm->name);
00074        }
00075 }
00076 
00077 void AddConstraintStudentsSetHomeRoomForm::addConstraint()
00078 {
00079        SpaceConstraint *ctr=NULL;
00080 
00081        double weight;
00082        QString tmp=weightLineEdit->text();
00083        weight_sscanf(tmp, "%lf", &weight);
00084        if(weight<0.0 || weight>100){
00085               QMessageBox::warning(this, tr("FET information"),
00086                      tr("Invalid weight"));
00087               return;
00088        }
00089 
00090        QString students=studentsComboBox->currentText();
00091        assert(gt.rules.searchStudentsSet(students)!=NULL);
00092 
00093        int i=roomsComboBox->currentIndex();
00094        if(i<0 || roomsComboBox->count()<=0){
00095               QMessageBox::warning(this, tr("FET information"),
00096                      tr("Invalid room"));
00097               return;
00098        }
00099        QString room=roomsComboBox->currentText();
00100 
00101        ctr=new ConstraintStudentsSetHomeRoom(weight, students, room);
00102 
00103        bool tmp2=gt.rules.addSpaceConstraint(ctr);
00104        if(tmp2){
00105               QString s=tr("Constraint added:");
00106               s+="\n\n";
00107               s+=ctr->getDetailedDescription(gt.rules);
00108               LongTextMessageBox::information(this, tr("FET information"), s);
00109        }
00110        else{
00111               QMessageBox::warning(this, tr("FET information"),
00112                      tr("Constraint NOT added - error ?"));
00113               delete ctr;
00114        }
00115 }