Back to index

fet  5.18.0
modifyconstraintthreeactivitiesgroupedform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintthreeactivitiesgroupedform.cpp  -  description
00003                              -------------------
00004     begin                : Aug 14, 2009
00005     copyright            : (C) 2009 by Lalescu Liviu
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 "modifyconstraintthreeactivitiesgroupedform.h"
00021 #include "timeconstraint.h"
00022 
00023 ModifyConstraintThreeActivitiesGroupedForm::ModifyConstraintThreeActivitiesGroupedForm(QWidget* parent, ConstraintThreeActivitiesGrouped* ctr): QDialog(parent)
00024 {
00025        setupUi(this);
00026 
00027        okPushButton->setDefault(true);
00028 
00029        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00030        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
00031 
00032        centerWidgetOnScreen(this);
00033        restoreFETDialogGeometry(this);
00034 
00035        QSize tmp5=firstActivitiesComboBox->minimumSizeHint();
00036        Q_UNUSED(tmp5);
00037        QSize tmp6=secondActivitiesComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp6);
00039        QSize tmp7=thirdActivitiesComboBox->minimumSizeHint();
00040        Q_UNUSED(tmp7);
00041        
00042        firstActivitiesComboBox->setMaximumWidth(maxRecommendedWidth(this));
00043        secondActivitiesComboBox->setMaximumWidth(maxRecommendedWidth(this));
00044        thirdActivitiesComboBox->setMaximumWidth(maxRecommendedWidth(this));
00045        
00046        this->_ctr=ctr;
00047        
00048        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00049 
00050        updateActivitiesComboBox();
00051 }
00052 
00053 ModifyConstraintThreeActivitiesGroupedForm::~ModifyConstraintThreeActivitiesGroupedForm()
00054 {
00055        saveFETDialogGeometry(this);
00056 }
00057 
00058 bool ModifyConstraintThreeActivitiesGroupedForm::filterOk(Activity* act)
00059 {
00060        Q_UNUSED(act);
00061 
00062        int ok=true;
00063        
00064        return ok;
00065 }
00066 
00067 void ModifyConstraintThreeActivitiesGroupedForm::filterChanged()
00068 {
00069        this->updateActivitiesComboBox();
00070 }
00071 
00072 void ModifyConstraintThreeActivitiesGroupedForm::updateActivitiesComboBox(){
00073        firstActivitiesComboBox->clear();
00074        firstActivitiesList.clear();
00075 
00076        secondActivitiesComboBox->clear();
00077        secondActivitiesList.clear();
00078 
00079        thirdActivitiesComboBox->clear();
00080        thirdActivitiesList.clear();
00081        
00082        int i=0, j=-1;
00083        for(int k=0; k<gt.rules.activitiesList.size(); k++){
00084               Activity* act=gt.rules.activitiesList[k];
00085               if(filterOk(act)){
00086                      firstActivitiesComboBox->addItem(act->getDescription(gt.rules));
00087                      this->firstActivitiesList.append(act->id);
00088 
00089                      if(act->id==this->_ctr->firstActivityId)
00090                             j=i;
00091                             
00092                      i++;
00093               }
00094        }
00095        //assert(j>=0); only first time
00096        firstActivitiesComboBox->setCurrentIndex(j);
00097 
00098        i=0, j=-1;
00099        for(int k=0; k<gt.rules.activitiesList.size(); k++){
00100               Activity* act=gt.rules.activitiesList[k];
00101               if(filterOk(act)){
00102                      secondActivitiesComboBox->addItem(act->getDescription(gt.rules));
00103                      this->secondActivitiesList.append(act->id);
00104 
00105                      if(act->id==this->_ctr->secondActivityId)
00106                             j=i;
00107                             
00108                      i++;
00109               }
00110        }
00111        //assert(j>=0); only first time
00112        secondActivitiesComboBox->setCurrentIndex(j);
00113 
00114        i=0, j=-1;
00115        for(int k=0; k<gt.rules.activitiesList.size(); k++){
00116               Activity* act=gt.rules.activitiesList[k];
00117               if(filterOk(act)){
00118                      thirdActivitiesComboBox->addItem(act->getDescription(gt.rules));
00119                      this->thirdActivitiesList.append(act->id);
00120 
00121                      if(act->id==this->_ctr->thirdActivityId)
00122                             j=i;
00123                             
00124                      i++;
00125               }
00126        }
00127        //assert(j>=0); only first time
00128        thirdActivitiesComboBox->setCurrentIndex(j);
00129 }
00130 
00131 void ModifyConstraintThreeActivitiesGroupedForm::ok()
00132 {
00133        double weight;
00134        QString tmp=weightLineEdit->text();
00135        weight_sscanf(tmp, "%lf", &weight);
00136        if(weight<0.0 || weight>100.0){
00137               QMessageBox::warning(this, tr("FET information"),
00138                      tr("Invalid weight (percentage)"));
00139               return;
00140        }
00141 
00142        int tmp2=firstActivitiesComboBox->currentIndex();
00143        assert(tmp2<gt.rules.activitiesList.size());
00144        assert(tmp2<firstActivitiesList.size());
00145        if(tmp2<0){
00146               QMessageBox::warning(this, tr("FET information"),
00147                      tr("Invalid first activity"));
00148               return;
00149        }
00150        int fid=firstActivitiesList.at(tmp2);
00151        
00152        int tmp3=secondActivitiesComboBox->currentIndex();
00153        assert(tmp3<gt.rules.activitiesList.size());
00154        assert(tmp3<secondActivitiesList.size());
00155        if(tmp3<0){
00156               QMessageBox::warning(this, tr("FET information"),
00157                      tr("Invalid second activity"));
00158               return;
00159        }
00160        int sid=secondActivitiesList.at(tmp3);
00161 
00162        int tmp4=thirdActivitiesComboBox->currentIndex();
00163        assert(tmp4<gt.rules.activitiesList.size());
00164        assert(tmp4<thirdActivitiesList.size());
00165        if(tmp4<0){
00166               QMessageBox::warning(this, tr("FET information"),
00167                      tr("Invalid third activity"));
00168               return;
00169        }
00170        int tid=thirdActivitiesList.at(tmp4);
00171 
00172        if(sid==fid || sid==tid || fid==tid){
00173               QMessageBox::warning(this, tr("FET information"),
00174                      tr("Same activities - impossible"));
00175               return;
00176        }
00177        
00178        this->_ctr->weightPercentage=weight;
00179        this->_ctr->firstActivityId=fid;
00180        this->_ctr->secondActivityId=sid;
00181        this->_ctr->thirdActivityId=tid;
00182        
00183        gt.rules.internalStructureComputed=false;
00184        setRulesModifiedAndOtherThings(&gt.rules);
00185 
00186        this->close();
00187 }
00188 
00189 void ModifyConstraintThreeActivitiesGroupedForm::cancel()
00190 {
00191        this->close();
00192 }