Back to index

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