Back to index

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