Back to index

fet  5.18.0
modifyconstraintactivitypreferredroomform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintactivitypreferredroomform.cpp  -  description
00003                              -------------------
00004     begin                : 13 Feb 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 "modifyconstraintactivitypreferredroomform.h"
00021 #include "spaceconstraint.h"
00022 
00023 #include "lockunlock.h"
00024 
00025 ModifyConstraintActivityPreferredRoomForm::ModifyConstraintActivityPreferredRoomForm(QWidget* parent, ConstraintActivityPreferredRoom* ctr): QDialog(parent)
00026 {
00027        setupUi(this);
00028 
00029        okPushButton->setDefault(true);
00030 
00031        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
00032        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00033 
00034        centerWidgetOnScreen(this);
00035        restoreFETDialogGeometry(this);
00036 
00037        QSize tmp5=roomsComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp5);
00039        QSize tmp6=activitiesComboBox->minimumSizeHint();
00040        Q_UNUSED(tmp6);
00041        
00042        activitiesComboBox->setMaximumWidth(maxRecommendedWidth(this));
00043        
00044        this->_ctr=ctr;
00045        
00046        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00047        
00048        permLockedCheckBox->setChecked(this->_ctr->permanentlyLocked);
00049 
00050        updateActivitiesComboBox();
00051        updateRoomsComboBox();
00052 }
00053 
00054 ModifyConstraintActivityPreferredRoomForm::~ModifyConstraintActivityPreferredRoomForm()
00055 {
00056        saveFETDialogGeometry(this);
00057 }
00058 
00059 void ModifyConstraintActivityPreferredRoomForm::updateActivitiesComboBox()
00060 {
00061        int i=0, j=-1;
00062        activitiesComboBox->clear();
00063        for(int k=0; k<gt.rules.activitiesList.size(); k++){
00064               Activity* act=gt.rules.activitiesList[k];
00065               activitiesComboBox->addItem(act->getDescription(gt.rules));
00066               if(act->id==this->_ctr->activityId)
00067                      j=i;
00068               i++;
00069        }
00070        assert(j>=0);
00071        activitiesComboBox->setCurrentIndex(j);
00072 }
00073 
00074 void ModifyConstraintActivityPreferredRoomForm::updateRoomsComboBox()
00075 {
00076        int i=0, j=-1;
00077        roomsComboBox->clear();
00078        for(int k=0; k<gt.rules.roomsList.size(); k++){
00079               Room* rm=gt.rules.roomsList[k];
00080               roomsComboBox->addItem(rm->name);
00081               if(rm->name==this->_ctr->roomName)
00082                      j=i;
00083               i++;
00084        }
00085        assert(j>=0);
00086        roomsComboBox->setCurrentIndex(j);
00087 }
00088 
00089 void ModifyConstraintActivityPreferredRoomForm::cancel()
00090 {
00091        this->close();
00092 }
00093 
00094 void ModifyConstraintActivityPreferredRoomForm::ok()
00095 {
00096        double weight;
00097        QString tmp=weightLineEdit->text();
00098        weight_sscanf(tmp, "%lf", &weight);
00099        if(weight<0.0 || weight>100){
00100               QMessageBox::warning(this, tr("FET information"),
00101                      tr("Invalid weight"));
00102               return;
00103        }
00104 
00105        int i=activitiesComboBox->currentIndex();
00106        if(i<0 || activitiesComboBox->count()<=0){
00107               QMessageBox::warning(this, tr("FET information"),
00108                      tr("Invalid activity"));
00109               return;
00110        }
00111        Activity* act=gt.rules.activitiesList.at(i);
00112 
00113        i=roomsComboBox->currentIndex();
00114        if(i<0 || roomsComboBox->count()<=0){
00115               QMessageBox::warning(this, tr("FET information"),
00116                      tr("Invalid room"));
00117               return;
00118        }
00119        QString room=roomsComboBox->currentText();
00120 
00121        this->_ctr->weightPercentage=weight;
00122        this->_ctr->roomName=room;
00123        this->_ctr->activityId=act->id;
00124        
00125        this->_ctr->permanentlyLocked=permLockedCheckBox->isChecked();
00126 
00127        gt.rules.internalStructureComputed=false;
00128        setRulesModifiedAndOtherThings(&gt.rules);
00129        
00130        LockUnlock::computeLockedUnlockedActivitiesOnlySpace();
00131        LockUnlock::increaseCommunicationSpinBox();
00132        
00133        this->close();
00134 }