Back to index

fet  5.18.0
modifyconstraintactivitiessamestartinghourform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintactivitiessamestartinghourform.cpp  -  description
00003                              -------------------
00004     begin                : Feb 15, 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 "modifyconstraintactivitiessamestartinghourform.h"
00021 
00022 #include <QList>
00023 
00024 #include <QListWidget>
00025 #include <QAbstractItemView>
00026 #include <QScrollBar>
00027 
00028 ModifyConstraintActivitiesSameStartingHourForm::ModifyConstraintActivitiesSameStartingHourForm(QWidget* parent, ConstraintActivitiesSameStartingHour* ctr): QDialog(parent)
00029 {
00030        setupUi(this);
00031 
00032        okPushButton->setDefault(true);
00033        
00034        activitiesListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00035        selectedActivitiesListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00036 
00037        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
00038        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00039        connect(activitiesListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(addActivity()));
00040        connect(addAllActivitiesPushButton, SIGNAL(clicked()), this, SLOT(addAllActivities()));
00041        connect(selectedActivitiesListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(removeActivity()));
00042        connect(teachersComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00043        connect(studentsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00044        connect(subjectsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00045        connect(activityTagsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00046        connect(clearPushButton, SIGNAL(clicked()), this, SLOT(clear()));
00047 
00048        centerWidgetOnScreen(this);
00049        restoreFETDialogGeometry(this);
00050        
00051        this->_ctr=ctr;
00052 
00053        QSize tmp1=teachersComboBox->minimumSizeHint();
00054        Q_UNUSED(tmp1);
00055        QSize tmp2=studentsComboBox->minimumSizeHint();
00056        Q_UNUSED(tmp2);
00057        QSize tmp3=subjectsComboBox->minimumSizeHint();
00058        Q_UNUSED(tmp3);
00059        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00060        Q_UNUSED(tmp4);
00061        
00062 
00063        teachersComboBox->addItem("");
00064        for(int i=0; i<gt.rules.teachersList.size(); i++){
00065               Teacher* tch=gt.rules.teachersList[i];
00066               teachersComboBox->addItem(tch->name);
00067        }
00068        teachersComboBox->setCurrentIndex(0);
00069 
00070        subjectsComboBox->addItem("");
00071        for(int i=0; i<gt.rules.subjectsList.size(); i++){
00072               Subject* sb=gt.rules.subjectsList[i];
00073               subjectsComboBox->addItem(sb->name);
00074        }
00075        subjectsComboBox->setCurrentIndex(0);
00076 
00077        activityTagsComboBox->addItem("");
00078        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
00079               ActivityTag* st=gt.rules.activityTagsList[i];
00080               activityTagsComboBox->addItem(st->name);
00081        }
00082        activityTagsComboBox->setCurrentIndex(0);
00083 
00084        studentsComboBox->addItem("");
00085        for(int i=0; i<gt.rules.yearsList.size(); i++){
00086               StudentsYear* sty=gt.rules.yearsList[i];
00087               studentsComboBox->addItem(sty->name);
00088               for(int j=0; j<sty->groupsList.size(); j++){
00089                      StudentsGroup* stg=sty->groupsList[j];
00090                      studentsComboBox->addItem(stg->name);
00091                      for(int k=0; k<stg->subgroupsList.size(); k++){
00092                             StudentsSubgroup* sts=stg->subgroupsList[k];
00093                             studentsComboBox->addItem(sts->name);
00094                      }
00095               }
00096        }
00097        studentsComboBox->setCurrentIndex(0);
00098 
00099        updateActivitiesListWidget();
00100 
00101        selectedActivitiesListWidget->clear();
00102        this->selectedActivitiesList.clear();
00103        
00104        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00105        
00106        for(int i=0; i<ctr->n_activities; i++){
00107               int actId=ctr->activitiesId[i];
00108               this->selectedActivitiesList.append(actId);
00109               Activity* act=NULL;
00110               for(int k=0; k<gt.rules.activitiesList.size(); k++){
00111                      act=gt.rules.activitiesList[k];
00112                      if(act->id==actId)
00113                             break;
00114               }
00115               assert(act);
00116               this->selectedActivitiesListWidget->addItem(act->getDescription(gt.rules));
00117        }
00118 }
00119 
00120 ModifyConstraintActivitiesSameStartingHourForm::~ModifyConstraintActivitiesSameStartingHourForm()
00121 {
00122        saveFETDialogGeometry(this);
00123 }
00124 
00125 bool ModifyConstraintActivitiesSameStartingHourForm::filterOk(Activity* act)
00126 {
00127        QString tn=teachersComboBox->currentText();
00128        QString stn=studentsComboBox->currentText();
00129        QString sbn=subjectsComboBox->currentText();
00130        QString sbtn=activityTagsComboBox->currentText();
00131        int ok=true;
00132 
00133        //teacher
00134        if(tn!=""){
00135               bool ok2=false;
00136               for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)
00137                      if(*it == tn){
00138                             ok2=true;
00139                             break;
00140                      }
00141               if(!ok2)
00142                      ok=false;
00143        }
00144 
00145        //subject
00146        if(sbn!="" && sbn!=act->subjectName)
00147               ok=false;
00148               
00149        //activity tag
00150        if(sbtn!="" && !act->activityTagsNames.contains(sbtn))
00151               ok=false;
00152               
00153        //students
00154        if(stn!=""){
00155               bool ok2=false;
00156               for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)
00157                      if(*it == stn){
00158                             ok2=true;
00159                             break;
00160                      }
00161               if(!ok2)
00162                      ok=false;
00163        }
00164        
00165        return ok;
00166 }
00167 
00168 void ModifyConstraintActivitiesSameStartingHourForm::filterChanged()
00169 {
00170        this->updateActivitiesListWidget();
00171 }
00172 
00173 void ModifyConstraintActivitiesSameStartingHourForm::updateActivitiesListWidget()
00174 {
00175        activitiesListWidget->clear();
00176        this->activitiesList.clear();
00177 
00178        for(int i=0; i<gt.rules.activitiesList.size(); i++){
00179               Activity* ac=gt.rules.activitiesList[i];
00180                if(filterOk(ac)){
00181                      activitiesListWidget->addItem(ac->getDescription(gt.rules));
00182                      this->activitiesList.append(ac->id);
00183               }
00184        }
00185        
00186        int q=activitiesListWidget->verticalScrollBar()->minimum();
00187        activitiesListWidget->verticalScrollBar()->setValue(q);
00188 }
00189 
00190 void ModifyConstraintActivitiesSameStartingHourForm::ok()
00191 {
00192        double weight;
00193        QString tmp=weightLineEdit->text();
00194        weight_sscanf(tmp, "%lf", &weight);
00195        if(weight<0.0 || weight>100.0){
00196               QMessageBox::warning(this, tr("FET information"),
00197                      tr("Invalid weight (percentage)"));
00198               return;
00199        }
00200 
00201        if(this->selectedActivitiesList.size()==0){
00202               QMessageBox::warning(this, tr("FET information"),
00203                      tr("Empty list of selected activities"));
00204               return;
00205        }
00206        if(this->selectedActivitiesList.size()==1){
00207               QMessageBox::warning(this, tr("FET information"),
00208                      tr("Only one selected activity"));
00209               return;
00210        }
00211        
00212        int i;
00213        QList<int>::iterator it;
00214        this->_ctr->activitiesId.clear();
00215        for(i=0, it=this->selectedActivitiesList.begin(); it!=this->selectedActivitiesList.end(); it++, i++){
00216               this->_ctr->activitiesId.append(*it);
00217        }
00218        this->_ctr->n_activities=i;
00219               
00220        this->_ctr->weightPercentage=weight;
00221        
00222        gt.rules.internalStructureComputed=false;
00223        setRulesModifiedAndOtherThings(&gt.rules);
00224        
00225        this->close();
00226 }
00227 
00228 void ModifyConstraintActivitiesSameStartingHourForm::cancel()
00229 {
00230        this->close();
00231 }
00232 
00233 void ModifyConstraintActivitiesSameStartingHourForm::addActivity()
00234 {
00235        if(activitiesListWidget->currentRow()<0)
00236               return;
00237        int tmp=activitiesListWidget->currentRow();
00238        int _id=this->activitiesList.at(tmp);
00239        
00240        QString actName=activitiesListWidget->currentItem()->text();
00241        assert(actName!="");
00242        int i;
00243        //duplicate?
00244        for(i=0; i<selectedActivitiesListWidget->count(); i++)
00245               if(actName==selectedActivitiesListWidget->item(i)->text())
00246                      break;
00247        if(i<selectedActivitiesListWidget->count())
00248               return;
00249        selectedActivitiesListWidget->addItem(actName);
00250        selectedActivitiesListWidget->setCurrentRow(selectedActivitiesListWidget->count()-1);
00251        
00252        this->selectedActivitiesList.append(_id);
00253 }
00254 
00255 void ModifyConstraintActivitiesSameStartingHourForm::addAllActivities()
00256 {
00257        for(int tmp=0; tmp<activitiesListWidget->count(); tmp++){
00258               int _id=this->activitiesList.at(tmp);
00259        
00260               QString actName=activitiesListWidget->item(tmp)->text();
00261               assert(actName!="");
00262               int i;
00263               //duplicate?
00264               for(i=0; i<selectedActivitiesList.count(); i++)
00265                      if(selectedActivitiesList.at(i)==_id)
00266                             break;
00267               if(i<selectedActivitiesList.count())
00268                      continue;
00269                      
00270               selectedActivitiesListWidget->addItem(actName);
00271               this->selectedActivitiesList.append(_id);
00272        }
00273        
00274        selectedActivitiesListWidget->setCurrentRow(selectedActivitiesListWidget->count()-1);
00275 }
00276 
00277 void ModifyConstraintActivitiesSameStartingHourForm::removeActivity()
00278 {
00279        if(selectedActivitiesListWidget->currentRow()<0 || selectedActivitiesListWidget->count()<=0)
00280               return;
00281        int tmp=selectedActivitiesListWidget->currentRow();
00282        
00283        selectedActivitiesList.removeAt(tmp);
00284        
00285        selectedActivitiesListWidget->setCurrentRow(-1);
00286        QListWidgetItem* item=selectedActivitiesListWidget->takeItem(tmp);
00287        delete item;
00288        if(tmp<selectedActivitiesListWidget->count())
00289               selectedActivitiesListWidget->setCurrentRow(tmp);
00290        else
00291               selectedActivitiesListWidget->setCurrentRow(selectedActivitiesListWidget->count()-1);
00292 }
00293 
00294 void ModifyConstraintActivitiesSameStartingHourForm::clear()
00295 {
00296        selectedActivitiesListWidget->clear();
00297        selectedActivitiesList.clear();
00298 }