Back to index

fet  5.18.0
modifyconstraintactivityendsstudentsdayform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintactivityendsstudentsdayform.cpp  -  description
00003                              -------------------
00004     begin                : Sept 14, 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 
00021 
00022 #include "modifyconstraintactivityendsstudentsdayform.h"
00023 #include "timeconstraint.h"
00024 
00025 ModifyConstraintActivityEndsStudentsDayForm::ModifyConstraintActivityEndsStudentsDayForm(QWidget* parent, ConstraintActivityEndsStudentsDay* 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        
00053        activitiesComboBox->setMaximumWidth(maxRecommendedWidth(this));
00054        
00055        this->_ctr=ctr;
00056        
00057        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00058 
00059        teachersComboBox->addItem("");
00060        for(int i=0; i<gt.rules.teachersList.size(); i++){
00061               Teacher* tch=gt.rules.teachersList[i];
00062               teachersComboBox->addItem(tch->name);
00063        }
00064        teachersComboBox->setCurrentIndex(0);
00065 
00066        subjectsComboBox->addItem("");
00067        for(int i=0; i<gt.rules.subjectsList.size(); i++){
00068               Subject* sb=gt.rules.subjectsList[i];
00069               subjectsComboBox->addItem(sb->name);
00070        }
00071        subjectsComboBox->setCurrentIndex(0);
00072 
00073        activityTagsComboBox->addItem("");
00074        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
00075               ActivityTag* st=gt.rules.activityTagsList[i];
00076               activityTagsComboBox->addItem(st->name);
00077        }
00078        activityTagsComboBox->setCurrentIndex(0);
00079 
00080        studentsComboBox->addItem("");
00081        for(int i=0; i<gt.rules.yearsList.size(); i++){
00082               StudentsYear* sty=gt.rules.yearsList[i];
00083               studentsComboBox->addItem(sty->name);
00084               for(int j=0; j<sty->groupsList.size(); j++){
00085                      StudentsGroup* stg=sty->groupsList[j];
00086                      studentsComboBox->addItem(stg->name);
00087                      for(int k=0; k<stg->subgroupsList.size(); k++){
00088                             StudentsSubgroup* sts=stg->subgroupsList[k];
00089                             studentsComboBox->addItem(sts->name);
00090                      }
00091               }
00092        }
00093        studentsComboBox->setCurrentIndex(0);
00094        
00095        updateActivitiesComboBox();
00096 
00097        constraintChanged();
00098 }
00099 
00100 ModifyConstraintActivityEndsStudentsDayForm::~ModifyConstraintActivityEndsStudentsDayForm()
00101 {
00102        saveFETDialogGeometry(this);
00103 }
00104 
00105 bool ModifyConstraintActivityEndsStudentsDayForm::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 ModifyConstraintActivityEndsStudentsDayForm::filterChanged()
00149 {
00150        this->updateActivitiesComboBox();
00151 }
00152 
00153 void ModifyConstraintActivityEndsStudentsDayForm::updateActivitiesComboBox(){
00154        activitiesComboBox->clear();
00155        activitiesList.clear();
00156        int i=0, j=-1;
00157        for(int k=0; k<gt.rules.activitiesList.size(); k++){
00158               Activity* act=gt.rules.activitiesList[k];
00159               if(filterOk(act)){
00160                      activitiesComboBox->addItem(act->getDescription(gt.rules));
00161                      this->activitiesList.append(act->id);
00162                      if(act->id==this->_ctr->activityId)
00163                             j=i;
00164                             
00165                      i++;
00166               }
00167        }
00168        //assert(j>=0); only first time
00169        activitiesComboBox->setCurrentIndex(j);
00170 
00171        constraintChanged();
00172 }
00173 
00174 void ModifyConstraintActivityEndsStudentsDayForm::constraintChanged()
00175 {
00176 }
00177 
00178 void ModifyConstraintActivityEndsStudentsDayForm::ok()
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        if(weight!=100.0){
00189               QMessageBox::warning(this, tr("FET information"),
00190                      tr("Invalid weight (percentage) - it must be 100%"));
00191               return;
00192        }
00193 
00194        int tmp2=activitiesComboBox->currentIndex();
00195        assert(tmp2<gt.rules.activitiesList.size());
00196        assert(tmp2<activitiesList.size());
00197        if(tmp2<0){
00198               QMessageBox::warning(this, tr("FET information"),
00199                      tr("Invalid activity"));
00200               return;
00201        }
00202        int id=activitiesList.at(tmp2);
00203        
00204        this->_ctr->weightPercentage=weight;
00205        this->_ctr->activityId=id;
00206        
00207        gt.rules.internalStructureComputed=false;
00208        setRulesModifiedAndOtherThings(&gt.rules);
00209 
00210        this->close();
00211 }
00212 
00213 void ModifyConstraintActivityEndsStudentsDayForm::cancel()
00214 {
00215        this->close();
00216 }