Back to index

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