Back to index

fet  5.18.0
constraintactivitypreferredroomform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           constraintactivitypreferredroomform.cpp  -  description
00003                              -------------------
00004     begin                : Feb 13, 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 "longtextmessagebox.h"
00021 
00022 #include "constraintactivitypreferredroomform.h"
00023 #include "addconstraintactivitypreferredroomform.h"
00024 #include "modifyconstraintactivitypreferredroomform.h"
00025 
00026 #include "lockunlock.h"
00027 
00028 #include <QListWidget>
00029 #include <QScrollBar>
00030 #include <QAbstractItemView>
00031 
00032 ConstraintActivityPreferredRoomForm::ConstraintActivityPreferredRoomForm(QWidget* parent): QDialog(parent)
00033 {
00034        setupUi(this);
00035 
00036        currentConstraintTextEdit->setReadOnly(true);
00037        
00038        modifyConstraintPushButton->setDefault(true);
00039        
00040        constraintsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00041 
00042        connect(constraintsListWidget, SIGNAL(currentRowChanged(int)), this, SLOT(constraintChanged(int)));
00043        connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addConstraint()));
00044        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00045        connect(removeConstraintPushButton, SIGNAL(clicked()), this, SLOT(removeConstraint()));
00046        connect(modifyConstraintPushButton, SIGNAL(clicked()), this, SLOT(modifyConstraint()));
00047        connect(roomsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00048        connect(constraintsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(modifyConstraint()));
00049        connect(teachersComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00050        connect(studentsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00051        connect(subjectsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00052        connect(activityTagsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00053 
00054        centerWidgetOnScreen(this);
00055        restoreFETDialogGeometry(this);
00056        
00057        QSize tmp1=teachersComboBox->minimumSizeHint();
00058        Q_UNUSED(tmp1);
00059        QSize tmp2=studentsComboBox->minimumSizeHint();
00060        Q_UNUSED(tmp2);
00061        QSize tmp3=subjectsComboBox->minimumSizeHint();
00062        Q_UNUSED(tmp3);
00063        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00064        Q_UNUSED(tmp4);
00065        
00066        QSize tmp5=roomsComboBox->minimumSizeHint();
00067        Q_UNUSED(tmp5);
00068 
00069        roomsComboBox->addItem("");
00070        for(int i=0; i<gt.rules.roomsList.size(); i++){
00071               Room* rm=gt.rules.roomsList[i];
00072               roomsComboBox->addItem(rm->name);
00073        }
00074 
00076        teachersComboBox->addItem("");
00077        for(int i=0; i<gt.rules.teachersList.size(); i++){
00078               Teacher* tch=gt.rules.teachersList[i];
00079               teachersComboBox->addItem(tch->name);
00080        }
00081        teachersComboBox->setCurrentIndex(0);
00082 
00083        subjectsComboBox->addItem("");
00084        for(int i=0; i<gt.rules.subjectsList.size(); i++){
00085               Subject* sb=gt.rules.subjectsList[i];
00086               subjectsComboBox->addItem(sb->name);
00087        }
00088        subjectsComboBox->setCurrentIndex(0);
00089 
00090        activityTagsComboBox->addItem("");
00091        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
00092               ActivityTag* st=gt.rules.activityTagsList[i];
00093               activityTagsComboBox->addItem(st->name);
00094        }
00095        activityTagsComboBox->setCurrentIndex(0);
00096 
00097        studentsComboBox->addItem("");
00098        for(int i=0; i<gt.rules.yearsList.size(); i++){
00099               StudentsYear* sty=gt.rules.yearsList[i];
00100               studentsComboBox->addItem(sty->name);
00101               for(int j=0; j<sty->groupsList.size(); j++){
00102                      StudentsGroup* stg=sty->groupsList[j];
00103                      studentsComboBox->addItem(stg->name);
00104                      for(int k=0; k<stg->subgroupsList.size(); k++){
00105                             StudentsSubgroup* sts=stg->subgroupsList[k];
00106                             studentsComboBox->addItem(sts->name);
00107                      }
00108               }
00109        }
00110        studentsComboBox->setCurrentIndex(0);
00112 
00113        this->filterChanged();
00114 }
00115 
00116 ConstraintActivityPreferredRoomForm::~ConstraintActivityPreferredRoomForm()
00117 {
00118        saveFETDialogGeometry(this);
00119 }
00120 
00121 bool ConstraintActivityPreferredRoomForm::filterOk(SpaceConstraint* ctr)
00122 {
00123        if(ctr->type!=CONSTRAINT_ACTIVITY_PREFERRED_ROOM)
00124               return false;
00125               
00126        ConstraintActivityPreferredRoom* c=(ConstraintActivityPreferredRoom*) ctr;
00127        
00128        QString tn=teachersComboBox->currentText();
00129        QString sbn=subjectsComboBox->currentText();
00130        QString sbtn=activityTagsComboBox->currentText();
00131        QString stn=studentsComboBox->currentText();
00132               
00133        bool found=true;
00134        
00135        int id=c->activityId;
00136        Activity* act=NULL;
00137        foreach(Activity* a, gt.rules.activitiesList)
00138               if(a->id==id)
00139                      act=a;
00140 
00141        found=true;
00142               
00143        if(act!=NULL){
00144               //teacher
00145               if(tn!=""){
00146                      bool ok2=false;
00147                      for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)
00148                             if(*it == tn){
00149                                    ok2=true;
00150                                    break;
00151                             }
00152                      if(!ok2)
00153                             found=false;
00154               }
00155 
00156               //subject
00157               if(sbn!="" && sbn!=act->subjectName)
00158                      found=false;
00159        
00160               //activity tag
00161               if(sbtn!="" && !act->activityTagsNames.contains(sbtn))
00162                      found=false;
00163        
00164               //students
00165               if(stn!=""){
00166                      bool ok2=false;
00167                      for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)
00168                             if(*it == stn){
00169                                    ok2=true;
00170                                    break;
00171                      }
00172                      if(!ok2)
00173                             found=false;
00174               }
00175        }
00176        
00177        if(!found)
00178               return false;
00179        
00180        return c->roomName==roomsComboBox->currentText() || roomsComboBox->currentText()=="";
00181 }
00182 
00183 void ConstraintActivityPreferredRoomForm::filterChanged()
00184 {
00185        this->visibleConstraintsList.clear();
00186        constraintsListWidget->clear();
00187        for(int i=0; i<gt.rules.spaceConstraintsList.size(); i++){
00188               SpaceConstraint* ctr=gt.rules.spaceConstraintsList[i];
00189               if(filterOk(ctr)){
00190                      visibleConstraintsList.append(ctr);
00191                      constraintsListWidget->addItem(ctr->getDescription(gt.rules));
00192               }
00193        }
00194        
00195        if(constraintsListWidget->count()>0)
00196               constraintsListWidget->setCurrentRow(0);
00197        else
00198               constraintChanged(-1);
00199 }
00200 
00201 void ConstraintActivityPreferredRoomForm::constraintChanged(int index)
00202 {
00203        if(index<0){
00204               currentConstraintTextEdit->setPlainText("");
00205               return;
00206        }
00207        assert(index<this->visibleConstraintsList.size());
00208        SpaceConstraint* ctr=this->visibleConstraintsList.at(index);
00209        assert(ctr!=NULL);
00210        currentConstraintTextEdit->setPlainText(ctr->getDetailedDescription(gt.rules));
00211 }
00212 
00213 void ConstraintActivityPreferredRoomForm::addConstraint()
00214 {
00215        AddConstraintActivityPreferredRoomForm form(this);
00216        setParentAndOtherThings(&form, this);
00217        form.exec();
00218 
00219        filterChanged();
00220        
00221        constraintsListWidget->setCurrentRow(constraintsListWidget->count()-1);
00222 }
00223 
00224 void ConstraintActivityPreferredRoomForm::modifyConstraint()
00225 {
00226        int valv=constraintsListWidget->verticalScrollBar()->value();
00227        int valh=constraintsListWidget->horizontalScrollBar()->value();
00228 
00229        int i=constraintsListWidget->currentRow();
00230        if(i<0){
00231               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00232               return;
00233        }
00234        SpaceConstraint* ctr=this->visibleConstraintsList.at(i);
00235 
00236        ModifyConstraintActivityPreferredRoomForm form(this, (ConstraintActivityPreferredRoom*)ctr);
00237        setParentAndOtherThings(&form, this);
00238        form.exec();
00239 
00240        filterChanged();
00241 
00242        constraintsListWidget->verticalScrollBar()->setValue(valv);
00243        constraintsListWidget->horizontalScrollBar()->setValue(valh);
00244        
00245        if(i>=constraintsListWidget->count())
00246               i=constraintsListWidget->count()-1;
00247        
00248        if(i>=0)
00249               constraintsListWidget->setCurrentRow(i);
00250        else
00251               this->constraintChanged(-1);
00252 }
00253 
00254 void ConstraintActivityPreferredRoomForm::removeConstraint()
00255 {
00256        int i=constraintsListWidget->currentRow();
00257        if(i<0){
00258               QMessageBox::information(this, tr("FET information"), tr("Invalid selected constraint"));
00259               return;
00260        }
00261        SpaceConstraint* ctr=this->visibleConstraintsList.at(i);
00262        QString s;
00263        s=tr("Remove constraint?");
00264        s+="\n\n";
00265        s+=ctr->getDetailedDescription(gt.rules);
00266        
00267        QListWidgetItem* item;
00268 
00269        switch( LongTextMessageBox::confirmation( this, tr("FET confirmation"),
00270               s, tr("Yes"), tr("No"), 0, 0, 1 ) ){
00271        case 0: // The user clicked the OK button or pressed Enter
00272               gt.rules.removeSpaceConstraint(ctr);
00273               
00274               visibleConstraintsList.removeAt(i);
00275               constraintsListWidget->setCurrentRow(-1);
00276               item=constraintsListWidget->takeItem(i);
00277               delete item;
00278               
00279               LockUnlock::computeLockedUnlockedActivitiesOnlySpace();
00280               LockUnlock::increaseCommunicationSpinBox();
00281               
00282               break;
00283        case 1: // The user clicked the Cancel button or pressed Escape
00284               break;
00285        }
00286        
00287        if(i>=constraintsListWidget->count())
00288               i=constraintsListWidget->count()-1;
00289        if(i>=0)
00290               constraintsListWidget->setCurrentRow(i);
00291        else
00292               this->constraintChanged(-1);
00293 }