Back to index

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