Back to index

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