Back to index

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