Back to index

fet  5.18.0
modifyconstraintactivitypreferredstartingtimeform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintactivitypreferredstartingtimeform.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 #include "modifyconstraintactivitypreferredstartingtimeform.h"
00021 #include "timeconstraint.h"
00022 
00023 #include "lockunlock.h"
00024 
00025 ModifyConstraintActivityPreferredStartingTimeForm::ModifyConstraintActivityPreferredStartingTimeForm(QWidget* parent, ConstraintActivityPreferredStartingTime* ctr): QDialog(parent)
00026 {
00027        setupUi(this);
00028 
00029        okPushButton->setDefault(true);
00030 
00031        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00032        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
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=activitiesComboBox->minimumSizeHint();
00051        Q_UNUSED(tmp5);
00052        QSize tmp6=dayComboBox->minimumSizeHint();
00053        Q_UNUSED(tmp6);
00054        QSize tmp7=startHourComboBox->minimumSizeHint();
00055        Q_UNUSED(tmp7);
00056        
00057        activitiesComboBox->setMaximumWidth(maxRecommendedWidth(this));
00058        
00059        this->_ctr=ctr;
00060        
00061        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00062 
00063        teachersComboBox->addItem("");
00064        for(int i=0; i<gt.rules.teachersList.size(); i++){
00065               Teacher* tch=gt.rules.teachersList[i];
00066               teachersComboBox->addItem(tch->name);
00067        }
00068        teachersComboBox->setCurrentIndex(0);
00069 
00070        subjectsComboBox->addItem("");
00071        for(int i=0; i<gt.rules.subjectsList.size(); i++){
00072               Subject* sb=gt.rules.subjectsList[i];
00073               subjectsComboBox->addItem(sb->name);
00074        }
00075        subjectsComboBox->setCurrentIndex(0);
00076 
00077        activityTagsComboBox->addItem("");
00078        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
00079               ActivityTag* st=gt.rules.activityTagsList[i];
00080               activityTagsComboBox->addItem(st->name);
00081        }
00082        activityTagsComboBox->setCurrentIndex(0);
00083 
00084        studentsComboBox->addItem("");
00085        for(int i=0; i<gt.rules.yearsList.size(); i++){
00086               StudentsYear* sty=gt.rules.yearsList[i];
00087               studentsComboBox->addItem(sty->name);
00088               for(int j=0; j<sty->groupsList.size(); j++){
00089                      StudentsGroup* stg=sty->groupsList[j];
00090                      studentsComboBox->addItem(stg->name);
00091                      for(int k=0; k<stg->subgroupsList.size(); k++){
00092                             StudentsSubgroup* sts=stg->subgroupsList[k];
00093                             studentsComboBox->addItem(sts->name);
00094                      }
00095               }
00096        }
00097        studentsComboBox->setCurrentIndex(0);
00098        
00099        updatePeriodGroupBox();
00100        updateActivitiesComboBox();
00101 
00102        if(ctr->day>=0 && ctr->day<gt.rules.nDaysPerWeek)
00103               dayComboBox->setCurrentIndex(ctr->day);
00104        else
00105               dayComboBox->setCurrentIndex(-1);
00106               
00107        if(ctr->hour>=0 && ctr->hour<gt.rules.nHoursPerDay)
00108               startHourComboBox->setCurrentIndex(ctr->hour);
00109        else
00110               startHourComboBox->setCurrentIndex(-1);
00111        
00112        permLockedCheckBox->setChecked(this->_ctr->permanentlyLocked);
00113        
00114        constraintChanged();
00115 }
00116 
00117 ModifyConstraintActivityPreferredStartingTimeForm::~ModifyConstraintActivityPreferredStartingTimeForm()
00118 {
00119        saveFETDialogGeometry(this);
00120 }
00121 
00122 bool ModifyConstraintActivityPreferredStartingTimeForm::filterOk(Activity* act)
00123 {
00124        QString tn=teachersComboBox->currentText();
00125        QString stn=studentsComboBox->currentText();
00126        QString sbn=subjectsComboBox->currentText();
00127        QString sbtn=activityTagsComboBox->currentText();
00128        int ok=true;
00129 
00130        //teacher
00131        if(tn!=""){
00132               bool ok2=false;
00133               for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)
00134                      if(*it == tn){
00135                             ok2=true;
00136                             break;
00137                      }
00138               if(!ok2)
00139                      ok=false;
00140        }
00141 
00142        //subject
00143        if(sbn!="" && sbn!=act->subjectName)
00144               ok=false;
00145               
00146        //activity tag
00147        if(sbtn!="" && !act->activityTagsNames.contains(sbtn))
00148               ok=false;
00149               
00150        //students
00151        if(stn!=""){
00152               bool ok2=false;
00153               for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)
00154                      if(*it == stn){
00155                             ok2=true;
00156                             break;
00157                      }
00158               if(!ok2)
00159                      ok=false;
00160        }
00161        
00162        return ok;
00163 }
00164 
00165 void ModifyConstraintActivityPreferredStartingTimeForm::filterChanged()
00166 {
00167        this->updateActivitiesComboBox();
00168 }
00169 
00170 void ModifyConstraintActivityPreferredStartingTimeForm::updateActivitiesComboBox(){
00171        activitiesComboBox->clear();
00172        activitiesList.clear();
00173        int i=0, j=-1;
00174        for(int k=0; k<gt.rules.activitiesList.size(); k++){
00175               Activity* act=gt.rules.activitiesList[k];
00176               if(filterOk(act)){
00177                      activitiesComboBox->addItem(act->getDescription(gt.rules));
00178                      this->activitiesList.append(act->id);
00179                      if(act->id==this->_ctr->activityId)
00180                             j=i;
00181                             
00182                      i++;
00183               }
00184        }
00185        //assert(j>=0); only first time
00186        activitiesComboBox->setCurrentIndex(j);
00187 
00188        constraintChanged();
00189 }
00190 
00191 void ModifyConstraintActivityPreferredStartingTimeForm::updatePeriodGroupBox(){
00192        startHourComboBox->clear();
00193        for(int i=0; i<gt.rules.nHoursPerDay; i++)
00194               startHourComboBox->addItem(gt.rules.hoursOfTheDay[i]);
00195 
00196        dayComboBox->clear();
00197        for(int i=0; i<gt.rules.nDaysPerWeek; i++)
00198               dayComboBox->addItem(gt.rules.daysOfTheWeek[i]);
00199 }
00200 
00201 void ModifyConstraintActivityPreferredStartingTimeForm::constraintChanged()
00202 {
00203 }
00204 
00205 void ModifyConstraintActivityPreferredStartingTimeForm::ok()
00206 {
00207        double weight;
00208        QString tmp=weightLineEdit->text();
00209        weight_sscanf(tmp, "%lf", &weight);
00210        if(weight<0.0 || weight>100.0){
00211               QMessageBox::warning(this, tr("FET information"),
00212                      tr("Invalid weight (percentage)"));
00213               return;
00214        }
00215 
00216        int day=dayComboBox->currentIndex();
00217        if(day<0 || day>=gt.rules.nDaysPerWeek){
00218               QMessageBox::warning(this, tr("FET information"),
00219                      tr("Invalid day"));
00220               return;
00221        }
00222        int startHour=startHourComboBox->currentIndex();
00223        if(startHour<0 || startHour>=gt.rules.nHoursPerDay){
00224               QMessageBox::warning(this, tr("FET information"),
00225                      tr("Invalid start hour"));
00226               return;
00227        }
00228 
00229        int tmp2=activitiesComboBox->currentIndex();
00230        assert(tmp2<gt.rules.activitiesList.size());
00231        assert(tmp2<activitiesList.size());
00232        if(tmp2<0){
00233               QMessageBox::warning(this, tr("FET information"),
00234                      tr("Invalid activity"));
00235               return;
00236        }
00237        int id=activitiesList.at(tmp2);
00238        
00239        this->_ctr->weightPercentage=weight;
00240        this->_ctr->day=day;
00241        this->_ctr->hour=startHour;
00242        this->_ctr->activityId=id;
00243        
00244        this->_ctr->permanentlyLocked=permLockedCheckBox->isChecked();
00245        
00246        gt.rules.internalStructureComputed=false;
00247        setRulesModifiedAndOtherThings(&gt.rules);
00248        
00249        LockUnlock::computeLockedUnlockedActivitiesOnlyTime();
00250        LockUnlock::increaseCommunicationSpinBox();
00251 
00252        this->close();
00253 }
00254 
00255 void ModifyConstraintActivityPreferredStartingTimeForm::cancel()
00256 {
00257        this->close();
00258 }