Back to index

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