Back to index

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