Back to index

fet  5.18.0
modifyconstraintactivitiessamestartingdayform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintactivitiessamestartingdayform.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 "modifyconstraintactivitiessamestartingdayform.h"
00021 #include "spaceconstraint.h"
00022 
00023 #include <QList>
00024 
00025 #include <QListWidget>
00026 #include <QAbstractItemView>
00027 #include <QScrollBar>
00028 
00029 ModifyConstraintActivitiesSameStartingDayForm::ModifyConstraintActivitiesSameStartingDayForm(QWidget* parent, ConstraintActivitiesSameStartingDay* ctr): QDialog(parent)
00030 {
00031        setupUi(this);
00032 
00033        okPushButton->setDefault(true);
00034 
00035        activitiesListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00036        selectedActivitiesListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00037 
00038        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
00039        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00040        connect(activitiesListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(addActivity()));
00041        connect(addAllActivitiesPushButton, SIGNAL(clicked()), this, SLOT(addAllActivities()));
00042        connect(selectedActivitiesListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(removeActivity()));
00043        connect(teachersComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00044        connect(studentsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00045        connect(subjectsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00046        connect(activityTagsComboBox, SIGNAL(activated(QString)), this, SLOT(filterChanged()));
00047 
00048        connect(clearPushButton, SIGNAL(clicked()), this, SLOT(clear()));
00049 
00050        centerWidgetOnScreen(this);
00051        restoreFETDialogGeometry(this);
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        this->_ctr=ctr;
00063 
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);
00099        
00100        updateActivitiesListWidget();
00101        
00102        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00103        
00104        selectedActivitiesListWidget->clear();
00105        this->selectedActivitiesList.clear();
00106 
00107        for(int i=0; i<ctr->n_activities; i++){
00108               int actId=ctr->activitiesId[i];
00109               this->selectedActivitiesList.append(actId);
00110               Activity* act=NULL;
00111               for(int k=0; k<gt.rules.activitiesList.size(); k++){
00112                      act=gt.rules.activitiesList[k];
00113                      if(act->id==actId)
00114                             break;
00115               }
00116               assert(act);
00117               selectedActivitiesListWidget->addItem(act->getDescription(gt.rules));
00118        }
00119 }
00120 
00121 ModifyConstraintActivitiesSameStartingDayForm::~ModifyConstraintActivitiesSameStartingDayForm()
00122 {
00123        saveFETDialogGeometry(this);
00124 }
00125 
00126 bool ModifyConstraintActivitiesSameStartingDayForm::filterOk(Activity* act)
00127 {
00128        QString tn=teachersComboBox->currentText();
00129        QString stn=studentsComboBox->currentText();
00130        QString sbn=subjectsComboBox->currentText();
00131        QString sbtn=activityTagsComboBox->currentText();
00132        int ok=true;
00133 
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                      ok=false;
00144        }
00145 
00146        //subject
00147        if(sbn!="" && sbn!=act->subjectName)
00148               ok=false;
00149               
00150        //activity tag
00151        if(sbtn!="" && !act->activityTagsNames.contains(sbtn))
00152               ok=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                      ok=false;
00164        }
00165        
00166        return ok;
00167 }
00168 
00169 void ModifyConstraintActivitiesSameStartingDayForm::filterChanged()
00170 {
00171        updateActivitiesListWidget();
00172 }
00173 
00174 void ModifyConstraintActivitiesSameStartingDayForm::updateActivitiesListWidget()
00175 {
00176        activitiesListWidget->clear();
00177        this->activitiesList.clear();
00178 
00179        for(int i=0; i<gt.rules.activitiesList.size(); i++){
00180               Activity* ac=gt.rules.activitiesList[i];
00181               if(filterOk(ac)){
00182                      activitiesListWidget->addItem(ac->getDescription(gt.rules));
00183                      this->activitiesList.append(ac->id);
00184               }
00185        }
00186        
00187        int q=activitiesListWidget->verticalScrollBar()->minimum();
00188        activitiesListWidget->verticalScrollBar()->setValue(q);
00189 }
00190 
00191 void ModifyConstraintActivitiesSameStartingDayForm::ok()
00192 {
00193        double weight;
00194        QString tmp=weightLineEdit->text();
00195        weight_sscanf(tmp, "%lf", &weight);
00196        if(weight<0.0 || weight>100.0){
00197               QMessageBox::warning(this, tr("FET information"),
00198                      tr("Invalid weight (percentage)"));
00199               return;
00200        }
00201 
00202        if(this->selectedActivitiesList.size()==0){
00203               QMessageBox::warning(this, tr("FET information"),
00204                      tr("Empty list of selected activities"));
00205               return;
00206        }
00207        if(this->selectedActivitiesList.size()==1){
00208               QMessageBox::warning(this, tr("FET information"),
00209                      tr("Only one selected activity"));
00210               return;
00211        }
00212        
00213        int i;
00214        QList<int>::iterator it;
00215        this->_ctr->activitiesId.clear();
00216        for(i=0, it=this->selectedActivitiesList.begin(); it!=this->selectedActivitiesList.end(); it++, i++){
00217               this->_ctr->activitiesId.append(*it);
00218        }
00219        this->_ctr->n_activities=i;
00220               
00221        this->_ctr->weightPercentage=weight;
00222        
00223        gt.rules.internalStructureComputed=false;
00224        setRulesModifiedAndOtherThings(&gt.rules);
00225        
00226        this->close();
00227 }
00228 
00229 void ModifyConstraintActivitiesSameStartingDayForm::cancel()
00230 {
00231        this->close();
00232 }
00233 
00234 void ModifyConstraintActivitiesSameStartingDayForm::addActivity()
00235 {
00236        if(activitiesListWidget->currentRow()<0)
00237               return;
00238        int tmp=activitiesListWidget->currentRow();
00239        int _id=this->activitiesList.at(tmp);
00240        
00241        QString actName=activitiesListWidget->currentItem()->text();
00242        assert(actName!="");
00243        int i;
00244        //duplicate?
00245        for(i=0; i<selectedActivitiesListWidget->count(); i++)
00246               if(actName==selectedActivitiesListWidget->item(i)->text())
00247                      break;
00248        if(i<selectedActivitiesListWidget->count())
00249               return;
00250        selectedActivitiesListWidget->addItem(actName);
00251        selectedActivitiesListWidget->setCurrentRow(selectedActivitiesListWidget->count()-1);
00252        
00253        this->selectedActivitiesList.append(_id);
00254 }
00255 
00256 void ModifyConstraintActivitiesSameStartingDayForm::addAllActivities()
00257 {
00258        for(int tmp=0; tmp<activitiesListWidget->count(); tmp++){
00259               int _id=this->activitiesList.at(tmp);
00260        
00261               QString actName=activitiesListWidget->item(tmp)->text();
00262               assert(actName!="");
00263               int i;
00264               //duplicate?
00265               for(i=0; i<selectedActivitiesList.count(); i++)
00266                      if(selectedActivitiesList.at(i)==_id)
00267                             break;
00268               if(i<selectedActivitiesList.count())
00269                      continue;
00270                      
00271               selectedActivitiesListWidget->addItem(actName);
00272               this->selectedActivitiesList.append(_id);
00273        }
00274        
00275        selectedActivitiesListWidget->setCurrentRow(selectedActivitiesListWidget->count()-1);
00276 }
00277 
00278 void ModifyConstraintActivitiesSameStartingDayForm::removeActivity()
00279 {
00280        if(selectedActivitiesListWidget->currentRow()<0 || selectedActivitiesListWidget->count()<=0)
00281               return;
00282        int tmp=selectedActivitiesListWidget->currentRow();
00283        
00284        selectedActivitiesList.removeAt(tmp);
00285 
00286        selectedActivitiesListWidget->setCurrentRow(-1);
00287        QListWidgetItem* item=selectedActivitiesListWidget->takeItem(tmp);
00288        delete item;
00289        if(tmp<selectedActivitiesListWidget->count())
00290               selectedActivitiesListWidget->setCurrentRow(tmp);
00291        else
00292               selectedActivitiesListWidget->setCurrentRow(selectedActivitiesListWidget->count()-1);
00293 }
00294 
00295 void ModifyConstraintActivitiesSameStartingDayForm::clear()
00296 {
00297        selectedActivitiesListWidget->clear();
00298        selectedActivitiesList.clear();
00299 }