Back to index

fet  5.18.0
modifyconstraintsubjectactivitytagpreferredroomform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintsubjectactivitytagpreferredroomform.cpp  -  description
00003                              -------------------
00004     begin                : 18 Aug 2007
00005     copyright            : (C) 2007 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 "modifyconstraintsubjectactivitytagpreferredroomform.h"
00021 #include "spaceconstraint.h"
00022 
00023 ModifyConstraintSubjectActivityTagPreferredRoomForm::ModifyConstraintSubjectActivityTagPreferredRoomForm(QWidget* parent, ConstraintSubjectActivityTagPreferredRoom* 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        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp4);
00039 
00040        QSize tmp5=roomsComboBox->minimumSizeHint();
00041        Q_UNUSED(tmp5);
00042        
00043        this->_ctr=ctr;
00044        
00045        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00046 
00047        updateSubjectsComboBox();
00048        updateActivityTagsComboBox();
00049        updateRoomsComboBox();
00050 }
00051 
00052 ModifyConstraintSubjectActivityTagPreferredRoomForm::~ModifyConstraintSubjectActivityTagPreferredRoomForm()
00053 {
00054        saveFETDialogGeometry(this);
00055 }
00056 
00057 void ModifyConstraintSubjectActivityTagPreferredRoomForm::updateSubjectsComboBox()
00058 {
00059        int i=0, j=-1;
00060        subjectsComboBox->clear();
00061        for(int k=0; k<gt.rules.subjectsList.size(); k++){
00062               Subject* sb=gt.rules.subjectsList[k];
00063               subjectsComboBox->addItem(sb->name);
00064               if(sb->name==this->_ctr->subjectName)
00065                      j=i;
00066               i++;
00067        }
00068        assert(j>=0);
00069        subjectsComboBox->setCurrentIndex(j);
00070 }
00071 
00072 void ModifyConstraintSubjectActivityTagPreferredRoomForm::updateActivityTagsComboBox()
00073 {
00074        int i=0, j=-1;
00075        activityTagsComboBox->clear();
00076        for(int k=0; k<gt.rules.activityTagsList.size(); k++){
00077               ActivityTag* sb=gt.rules.activityTagsList[k];
00078               activityTagsComboBox->addItem(sb->name);
00079               if(sb->name==this->_ctr->activityTagName)
00080                      j=i;
00081               i++;
00082        }
00083        assert(j>=0);
00084        activityTagsComboBox->setCurrentIndex(j);
00085 }
00086 
00087 void ModifyConstraintSubjectActivityTagPreferredRoomForm::updateRoomsComboBox()
00088 {
00089        int i=0, j=-1;
00090        roomsComboBox->clear();
00091        for(int k=0; k<gt.rules.roomsList.size(); k++){
00092               Room* rm=gt.rules.roomsList[k];
00093               roomsComboBox->addItem(rm->name);
00094               if(rm->name==this->_ctr->roomName)
00095                      j=i;
00096               i++;
00097        }
00098        assert(j>=0);
00099        roomsComboBox->setCurrentIndex(j);
00100 }
00101 
00102 void ModifyConstraintSubjectActivityTagPreferredRoomForm::cancel()
00103 {
00104        this->close();
00105 }
00106 
00107 void ModifyConstraintSubjectActivityTagPreferredRoomForm::ok()
00108 {
00109        double weight;
00110        QString tmp=weightLineEdit->text();
00111        weight_sscanf(tmp, "%lf", &weight);
00112        if(weight<0.0 || weight>100){
00113               QMessageBox::warning(this, tr("FET information"),
00114                      tr("Invalid weight"));
00115               return;
00116        }
00117 
00118        int i=subjectsComboBox->currentIndex();
00119        if(i<0 || subjectsComboBox->count()<=0){
00120               QMessageBox::warning(this, tr("FET information"),
00121                      tr("Invalid subject"));
00122               return;
00123        }
00124        QString subject=subjectsComboBox->currentText();
00125 
00126        i=activityTagsComboBox->currentIndex();
00127        if(i<0 || activityTagsComboBox->count()<=0){
00128               QMessageBox::warning(this, tr("FET information"),
00129                      tr("Invalid activity tag"));
00130               return;
00131        }
00132        QString activityTag=activityTagsComboBox->currentText();
00133 
00134        i=roomsComboBox->currentIndex();
00135        if(i<0 || roomsComboBox->count()<=0){
00136               QMessageBox::warning(this, tr("FET information"),
00137                      tr("Invalid room"));
00138               return;
00139        }
00140        QString room=roomsComboBox->currentText();
00141 
00142        this->_ctr->weightPercentage=weight;
00143        this->_ctr->roomName=room;
00144        this->_ctr->subjectName=subject;
00145        this->_ctr->activityTagName=activityTag;
00146 
00147        gt.rules.internalStructureComputed=false;
00148        setRulesModifiedAndOtherThings(&gt.rules);
00149        
00150        this->close();
00151 }