Back to index

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