"Fossies" - the Fresh Open Source Software Archive

Member "fet-5.48.0/src/interface/modifyconstrainttwoactivitiesconsecutiveform.cpp" (12 Feb 2020, 5116 Bytes) of package /linux/privat/fet-5.48.0.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "modifyconstrainttwoactivitiesconsecutiveform.cpp" see the Fossies "Dox" file reference documentation.

    1 /***************************************************************************
    2                           modifyconstrainttwoactivitiesconsecutiveform.cpp  -  description
    3                              -------------------
    4     begin                : Aug 21, 2007
    5     copyright            : (C) 2007 by Lalescu Liviu
    6     email                : Please see https://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
    7  ***************************************************************************/
    8 
    9 /***************************************************************************
   10  *                                                                         *
   11  *   This program is free software: you can redistribute it and/or modify  *
   12  *   it under the terms of the GNU Affero General Public License as        *
   13  *   published by the Free Software Foundation, either version 3 of the    *
   14  *   License, or (at your option) any later version.                       *
   15  *                                                                         *
   16  ***************************************************************************/
   17 
   18 #include <QMessageBox>
   19 
   20 #include "modifyconstrainttwoactivitiesconsecutiveform.h"
   21 #include "timeconstraint.h"
   22 
   23 ModifyConstraintTwoActivitiesConsecutiveForm::ModifyConstraintTwoActivitiesConsecutiveForm(QWidget* parent, ConstraintTwoActivitiesConsecutive* ctr): QDialog(parent)
   24 {
   25     setupUi(this);
   26 
   27     okPushButton->setDefault(true);
   28 
   29     connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
   30     connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
   31 
   32     connect(swapPushButton, SIGNAL(clicked()), this, SLOT(swap()));
   33 
   34     centerWidgetOnScreen(this);
   35     restoreFETDialogGeometry(this);
   36     
   37     QSize tmp5=firstActivitiesComboBox->minimumSizeHint();
   38     Q_UNUSED(tmp5);
   39     QSize tmp6=secondActivitiesComboBox->minimumSizeHint();
   40     Q_UNUSED(tmp6);
   41     
   42     firstActivitiesComboBox->setMaximumWidth(maxRecommendedWidth(this));
   43     secondActivitiesComboBox->setMaximumWidth(maxRecommendedWidth(this));
   44     
   45     this->_ctr=ctr;
   46     
   47     weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
   48 
   49     updateActivitiesComboBox();
   50 }
   51 
   52 ModifyConstraintTwoActivitiesConsecutiveForm::~ModifyConstraintTwoActivitiesConsecutiveForm()
   53 {
   54     saveFETDialogGeometry(this);
   55 }
   56 
   57 bool ModifyConstraintTwoActivitiesConsecutiveForm::filterOk(Activity* act)
   58 {
   59     Q_UNUSED(act);
   60 
   61     int ok=true;
   62     
   63     return ok;
   64 }
   65 
   66 void ModifyConstraintTwoActivitiesConsecutiveForm::filterChanged()
   67 {
   68     this->updateActivitiesComboBox();
   69 }
   70 
   71 void ModifyConstraintTwoActivitiesConsecutiveForm::updateActivitiesComboBox(){
   72     firstActivitiesComboBox->clear();
   73     firstActivitiesList.clear();
   74 
   75     secondActivitiesComboBox->clear();
   76     secondActivitiesList.clear();
   77     
   78     int i=0, j=-1;
   79     for(int k=0; k<gt.rules.activitiesList.size(); k++){
   80         Activity* act=gt.rules.activitiesList[k];
   81         if(filterOk(act)){
   82             firstActivitiesComboBox->addItem(act->getDescription(gt.rules));
   83             this->firstActivitiesList.append(act->id);
   84 
   85             if(act->id==this->_ctr->firstActivityId)
   86                 j=i;
   87                 
   88             i++;
   89         }
   90     }
   91     //assert(j>=0); only the first time
   92     firstActivitiesComboBox->setCurrentIndex(j);
   93 
   94     i=0, j=-1;
   95     for(int k=0; k<gt.rules.activitiesList.size(); k++){
   96         Activity* act=gt.rules.activitiesList[k];
   97         if(filterOk(act)){
   98             secondActivitiesComboBox->addItem(act->getDescription(gt.rules));
   99             this->secondActivitiesList.append(act->id);
  100 
  101             if(act->id==this->_ctr->secondActivityId)
  102                 j=i;
  103                 
  104             i++;
  105         }
  106     }
  107     //assert(j>=0); only the first time
  108     secondActivitiesComboBox->setCurrentIndex(j);
  109 }
  110 
  111 void ModifyConstraintTwoActivitiesConsecutiveForm::ok()
  112 {
  113     double weight;
  114     QString tmp=weightLineEdit->text();
  115     weight_sscanf(tmp, "%lf", &weight);
  116     if(weight<0.0 || weight>100.0){
  117         QMessageBox::warning(this, tr("FET information"),
  118             tr("Invalid weight (percentage)"));
  119         return;
  120     }
  121 
  122     int tmp2=firstActivitiesComboBox->currentIndex();
  123     assert(tmp2<gt.rules.activitiesList.size());
  124     assert(tmp2<firstActivitiesList.size());
  125     if(tmp2<0){
  126         QMessageBox::warning(this, tr("FET information"),
  127             tr("Invalid first activity"));
  128         return;
  129     }
  130     int fid=firstActivitiesList.at(tmp2);
  131     
  132     int tmp3=secondActivitiesComboBox->currentIndex();
  133     assert(tmp3<gt.rules.activitiesList.size());
  134     assert(tmp3<secondActivitiesList.size());
  135     if(tmp3<0){
  136         QMessageBox::warning(this, tr("FET information"),
  137             tr("Invalid second activity"));
  138         return;
  139     }
  140     int sid=secondActivitiesList.at(tmp3);
  141 
  142     if(sid==fid){
  143         QMessageBox::warning(this, tr("FET information"),
  144             tr("Same activities - impossible"));
  145         return;
  146     }
  147     
  148     this->_ctr->weightPercentage=weight;
  149     this->_ctr->firstActivityId=fid;
  150     this->_ctr->secondActivityId=sid;
  151     
  152     gt.rules.internalStructureComputed=false;
  153     setRulesModifiedAndOtherThings(&gt.rules);
  154 
  155     this->close();
  156 }
  157 
  158 void ModifyConstraintTwoActivitiesConsecutiveForm::cancel()
  159 {
  160     this->close();
  161 }
  162 
  163 void ModifyConstraintTwoActivitiesConsecutiveForm::swap()
  164 {
  165     int t1=firstActivitiesComboBox->currentIndex();
  166     int t2=secondActivitiesComboBox->currentIndex();
  167     firstActivitiesComboBox->setCurrentIndex(t2);
  168     secondActivitiesComboBox->setCurrentIndex(t1);
  169 }