Back to index

fet  5.18.0
addconstrainttwoactivitiesconsecutiveform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstrainttwoactivitiesconsecutiveform.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 "longtextmessagebox.h"
00021 
00022 #include "addconstrainttwoactivitiesconsecutiveform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintTwoActivitiesConsecutiveForm::AddConstraintTwoActivitiesConsecutiveForm(QWidget* parent): QDialog(parent)
00026 {
00027        setupUi(this);
00028 
00029        addConstraintPushButton->setDefault(true);
00030 
00031        connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addCurrentConstraint()));
00032        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00033        connect(teachersComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00034        connect(studentsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00035        connect(subjectsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00036        connect(activityTagsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00037 
00038        centerWidgetOnScreen(this);
00039        restoreFETDialogGeometry(this);
00040        
00041        QSize tmp1=teachersComboBox->minimumSizeHint();
00042        Q_UNUSED(tmp1);
00043        QSize tmp2=studentsComboBox->minimumSizeHint();
00044        Q_UNUSED(tmp2);
00045        QSize tmp3=subjectsComboBox->minimumSizeHint();
00046        Q_UNUSED(tmp3);
00047        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00048        Q_UNUSED(tmp4);
00049        
00050        QSize tmp5=firstActivitiesComboBox->minimumSizeHint();
00051        Q_UNUSED(tmp5);
00052        QSize tmp6=secondActivitiesComboBox->minimumSizeHint();
00053        Q_UNUSED(tmp6);
00054 
00055        firstActivitiesComboBox->setMaximumWidth(maxRecommendedWidth(this));
00056        secondActivitiesComboBox->setMaximumWidth(maxRecommendedWidth(this));
00057        
00058        teachersComboBox->addItem("");
00059        for(int i=0; i<gt.rules.teachersList.size(); i++){
00060               Teacher* tch=gt.rules.teachersList[i];
00061               teachersComboBox->addItem(tch->name);
00062        }
00063        teachersComboBox->setCurrentIndex(0);
00064 
00065        subjectsComboBox->addItem("");
00066        for(int i=0; i<gt.rules.subjectsList.size(); i++){
00067               Subject* sb=gt.rules.subjectsList[i];
00068               subjectsComboBox->addItem(sb->name);
00069        }
00070        subjectsComboBox->setCurrentIndex(0);
00071 
00072        activityTagsComboBox->addItem("");
00073        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
00074               ActivityTag* st=gt.rules.activityTagsList[i];
00075               activityTagsComboBox->addItem(st->name);
00076        }
00077        activityTagsComboBox->setCurrentIndex(0);
00078 
00079        studentsComboBox->addItem("");
00080        for(int i=0; i<gt.rules.yearsList.size(); i++){
00081               StudentsYear* sty=gt.rules.yearsList[i];
00082               studentsComboBox->addItem(sty->name);
00083               for(int j=0; j<sty->groupsList.size(); j++){
00084                      StudentsGroup* stg=sty->groupsList[j];
00085                      studentsComboBox->addItem(stg->name);
00086                      for(int k=0; k<stg->subgroupsList.size(); k++){
00087                             StudentsSubgroup* sts=stg->subgroupsList[k];
00088                             studentsComboBox->addItem(sts->name);
00089                      }
00090               }
00091        }
00092        studentsComboBox->setCurrentIndex(0);
00093 
00094        updateActivitiesComboBox();
00095 }
00096 
00097 AddConstraintTwoActivitiesConsecutiveForm::~AddConstraintTwoActivitiesConsecutiveForm()
00098 {
00099        saveFETDialogGeometry(this);
00100 }
00101 
00102 bool AddConstraintTwoActivitiesConsecutiveForm::filterOk(Activity* act)
00103 {
00104        QString tn=teachersComboBox->currentText();
00105        QString stn=studentsComboBox->currentText();
00106        QString sbn=subjectsComboBox->currentText();
00107        QString sbtn=activityTagsComboBox->currentText();
00108        int ok=true;
00109 
00110        //teacher
00111        if(tn!=""){
00112               bool ok2=false;
00113               for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)
00114                      if(*it == tn){
00115                             ok2=true;
00116                             break;
00117                      }
00118               if(!ok2)
00119                      ok=false;
00120        }
00121 
00122        //subject
00123        if(sbn!="" && sbn!=act->subjectName)
00124               ok=false;
00125               
00126        //activity tag
00127        if(sbtn!="" && !act->activityTagsNames.contains(sbtn))
00128               ok=false;
00129               
00130        //students
00131        if(stn!=""){
00132               bool ok2=false;
00133               for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)
00134                      if(*it == stn){
00135                             ok2=true;
00136                             break;
00137                      }
00138               if(!ok2)
00139                      ok=false;
00140        }
00141        
00142        return ok;
00143 }
00144 
00145 void AddConstraintTwoActivitiesConsecutiveForm::updateActivitiesComboBox(){
00146        firstActivitiesComboBox->clear();
00147        firstActivitiesList.clear();
00148 
00149        secondActivitiesComboBox->clear();
00150        secondActivitiesList.clear();
00151        
00152        for(int i=0; i<gt.rules.activitiesList.size(); i++){
00153               Activity* act=gt.rules.activitiesList[i];
00154               
00155               if(filterOk(act)){
00156                      firstActivitiesComboBox->addItem(act->getDescription(gt.rules));
00157                      this->firstActivitiesList.append(act->id);
00158 
00159                      secondActivitiesComboBox->addItem(act->getDescription(gt.rules));
00160                      this->secondActivitiesList.append(act->id);
00161               }
00162        }
00163 
00164        constraintChanged();
00165 }
00166 
00167 void AddConstraintTwoActivitiesConsecutiveForm::filterChanged()
00168 {
00169        this->updateActivitiesComboBox();
00170 }
00171 
00172 void AddConstraintTwoActivitiesConsecutiveForm::constraintChanged()
00173 {
00174 }
00175 
00176 void AddConstraintTwoActivitiesConsecutiveForm::addCurrentConstraint()
00177 {
00178        TimeConstraint *ctr=NULL;
00179 
00180        double weight;
00181        QString tmp=weightLineEdit->text();
00182        weight_sscanf(tmp, "%lf", &weight);
00183        if(weight<0.0 || weight>100.0){
00184               QMessageBox::warning(this, tr("FET information"),
00185                      tr("Invalid weight (percentage)"));
00186               return;
00187        }
00188 
00189        int fid;
00190        int tmp2=firstActivitiesComboBox->currentIndex();
00191        assert(tmp2<gt.rules.activitiesList.size());
00192        assert(tmp2<firstActivitiesList.size());
00193        if(tmp2<0){
00194               QMessageBox::warning(this, tr("FET information"),
00195                      tr("Invalid activity"));
00196               return;
00197        }
00198        else
00199               fid=firstActivitiesList.at(tmp2);
00200        
00201        int sid;
00202        int tmp3=secondActivitiesComboBox->currentIndex();
00203        assert(tmp3<gt.rules.activitiesList.size());
00204        assert(tmp3<secondActivitiesList.size());
00205        if(tmp3<0){
00206               QMessageBox::warning(this, tr("FET information"),
00207                      tr("Invalid activity"));
00208               return;
00209        }
00210        else
00211               sid=secondActivitiesList.at(tmp3);
00212               
00213        if(sid==fid){
00214               QMessageBox::warning(this, tr("FET information"),
00215                      tr("Same activities - impossible"));
00216               return;
00217        }
00218        
00219        ctr=new ConstraintTwoActivitiesConsecutive(weight, fid, sid);
00220 
00221        bool tmp4=gt.rules.addTimeConstraint(ctr);
00222        if(tmp4)
00223               LongTextMessageBox::information(this, tr("FET information"),
00224                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00225        else{
00226               QMessageBox::warning(this, tr("FET information"),
00227                      tr("Constraint NOT added - error?"));
00228               delete ctr;
00229        }
00230 }