Back to index

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