Back to index

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