Back to index

fet  5.18.0
modifyconstrainttwoactivitiesgroupedform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstrainttwoactivitiesgroupedform.cpp  -  description
00003                              -------------------
00004     begin                : Aug 21, 2007
00005     copyright            : (C) 2007 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 "modifyconstrainttwoactivitiesgroupedform.h"
00021 #include "timeconstraint.h"
00022 
00023 ModifyConstraintTwoActivitiesGroupedForm::ModifyConstraintTwoActivitiesGroupedForm(QWidget* parent, ConstraintTwoActivitiesGrouped* 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        
00040        firstActivitiesComboBox->setMaximumWidth(maxRecommendedWidth(this));
00041        secondActivitiesComboBox->setMaximumWidth(maxRecommendedWidth(this));
00042        
00043        this->_ctr=ctr;
00044        
00045        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00046 
00047        updateActivitiesComboBox();
00048 
00049        constraintChanged();
00050 }
00051 
00052 ModifyConstraintTwoActivitiesGroupedForm::~ModifyConstraintTwoActivitiesGroupedForm()
00053 {
00054        saveFETDialogGeometry(this);
00055 }
00056 
00057 bool ModifyConstraintTwoActivitiesGroupedForm::filterOk(Activity* act)
00058 {
00059        Q_UNUSED(act);
00060 
00061        int ok=true;
00062        
00063        return ok;
00064 }
00065 
00066 void ModifyConstraintTwoActivitiesGroupedForm::filterChanged()
00067 {
00068        this->updateActivitiesComboBox();
00069 }
00070 
00071 void ModifyConstraintTwoActivitiesGroupedForm::updateActivitiesComboBox(){
00072        firstActivitiesComboBox->clear();
00073        firstActivitiesList.clear();
00074 
00075        secondActivitiesComboBox->clear();
00076        secondActivitiesList.clear();
00077        
00078        int i=0, j=-1;
00079        for(int k=0; k<gt.rules.activitiesList.size(); k++){
00080               Activity* act=gt.rules.activitiesList[k];
00081               if(filterOk(act)){
00082                      firstActivitiesComboBox->addItem(act->getDescription(gt.rules));
00083                      this->firstActivitiesList.append(act->id);
00084 
00085                      if(act->id==this->_ctr->firstActivityId)
00086                             j=i;
00087                             
00088                      i++;
00089               }
00090        }
00091        //assert(j>=0); only first time
00092        firstActivitiesComboBox->setCurrentIndex(j);
00093 
00094        i=0, j=-1;
00095        for(int k=0; k<gt.rules.activitiesList.size(); k++){
00096               Activity* act=gt.rules.activitiesList[k];
00097               if(filterOk(act)){
00098                      secondActivitiesComboBox->addItem(act->getDescription(gt.rules));
00099                      this->secondActivitiesList.append(act->id);
00100 
00101                      if(act->id==this->_ctr->secondActivityId)
00102                             j=i;
00103                             
00104                      i++;
00105               }
00106        }
00107        //assert(j>=0); only first time
00108        secondActivitiesComboBox->setCurrentIndex(j);
00109 
00110        constraintChanged();
00111 }
00112 
00113 void ModifyConstraintTwoActivitiesGroupedForm::constraintChanged()
00114 {
00115 }
00116 
00117 void ModifyConstraintTwoActivitiesGroupedForm::ok()
00118 {
00119        double weight;
00120        QString tmp=weightLineEdit->text();
00121        weight_sscanf(tmp, "%lf", &weight);
00122        if(weight<0.0 || weight>100.0){
00123               QMessageBox::warning(this, tr("FET information"),
00124                      tr("Invalid weight (percentage)"));
00125               return;
00126        }
00127 
00128        int tmp2=firstActivitiesComboBox->currentIndex();
00129        assert(tmp2<gt.rules.activitiesList.size());
00130        assert(tmp2<firstActivitiesList.size());
00131        if(tmp2<0){
00132               QMessageBox::warning(this, tr("FET information"),
00133                      tr("Invalid first activity"));
00134               return;
00135        }
00136        int fid=firstActivitiesList.at(tmp2);
00137        
00138        int tmp3=secondActivitiesComboBox->currentIndex();
00139        assert(tmp3<gt.rules.activitiesList.size());
00140        assert(tmp3<secondActivitiesList.size());
00141        if(tmp3<0){
00142               QMessageBox::warning(this, tr("FET information"),
00143                      tr("Invalid second activity"));
00144               return;
00145        }
00146        int sid=secondActivitiesList.at(tmp3);
00147 
00148        if(sid==fid){
00149               QMessageBox::warning(this, tr("FET information"),
00150                      tr("Same activities - impossible"));
00151               return;
00152        }
00153        
00154        this->_ctr->weightPercentage=weight;
00155        this->_ctr->firstActivityId=fid;
00156        this->_ctr->secondActivityId=sid;
00157        
00158        gt.rules.internalStructureComputed=false;
00159        setRulesModifiedAndOtherThings(&gt.rules);
00160 
00161        this->close();
00162 }
00163 
00164 void ModifyConstraintTwoActivitiesGroupedForm::cancel()
00165 {
00166        this->close();
00167 }