Back to index

fet  5.18.0
addconstraintactivitypreferredroomsform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintactivitypreferredroomsform.cpp  -  description
00003                              -------------------
00004     begin                : March 28, 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 
00021 
00022 #include "longtextmessagebox.h"
00023 
00024 #include "addconstraintactivitypreferredroomsform.h"
00025 #include "spaceconstraint.h"
00026 
00027 #include <QListWidget>
00028 #include <QAbstractItemView>
00029 
00030 AddConstraintActivityPreferredRoomsForm::AddConstraintActivityPreferredRoomsForm(QWidget* parent): QDialog(parent)
00031 {
00032        setupUi(this);
00033 
00034        addConstraintPushButton->setDefault(true);
00035        
00036        roomsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00037        selectedRoomsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00038 
00039        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00040        connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addConstraint()));
00041        connect(roomsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(addRoom()));
00042        connect(selectedRoomsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(removeRoom()));
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        connect(clearPushButton, SIGNAL(clicked()), this, SLOT(clear()));
00048 
00049        centerWidgetOnScreen(this);
00050        restoreFETDialogGeometry(this);
00051        
00052        QSize tmp1=teachersComboBox->minimumSizeHint();
00053        Q_UNUSED(tmp1);
00054        QSize tmp2=studentsComboBox->minimumSizeHint();
00055        Q_UNUSED(tmp2);
00056        QSize tmp3=subjectsComboBox->minimumSizeHint();
00057        Q_UNUSED(tmp3);
00058        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00059        Q_UNUSED(tmp4);
00060        
00061        QSize tmp5=activitiesComboBox->minimumSizeHint();
00062        Q_UNUSED(tmp5);
00063 
00064        activitiesComboBox->setMaximumWidth(maxRecommendedWidth(this));
00065        
00066        teachersComboBox->addItem("");
00067        for(int i=0; i<gt.rules.teachersList.size(); i++){
00068               Teacher* tch=gt.rules.teachersList[i];
00069               teachersComboBox->addItem(tch->name);
00070        }
00071        teachersComboBox->setCurrentIndex(0);
00072 
00073        subjectsComboBox->addItem("");
00074        for(int i=0; i<gt.rules.subjectsList.size(); i++){
00075               Subject* sb=gt.rules.subjectsList[i];
00076               subjectsComboBox->addItem(sb->name);
00077        }
00078        subjectsComboBox->setCurrentIndex(0);
00079 
00080        activityTagsComboBox->addItem("");
00081        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
00082               ActivityTag* st=gt.rules.activityTagsList[i];
00083               activityTagsComboBox->addItem(st->name);
00084        }
00085        activityTagsComboBox->setCurrentIndex(0);
00086 
00087        studentsComboBox->addItem("");
00088        for(int i=0; i<gt.rules.yearsList.size(); i++){
00089               StudentsYear* sty=gt.rules.yearsList[i];
00090               studentsComboBox->addItem(sty->name);
00091               for(int j=0; j<sty->groupsList.size(); j++){
00092                      StudentsGroup* stg=sty->groupsList[j];
00093                      studentsComboBox->addItem(stg->name);
00094                      for(int k=0; k<stg->subgroupsList.size(); k++){
00095                             StudentsSubgroup* sts=stg->subgroupsList[k];
00096                             studentsComboBox->addItem(sts->name);
00097                      }
00098               }
00099        }
00100        studentsComboBox->setCurrentIndex(0);
00101        
00102        updateActivitiesComboBox();
00103 
00104        updateRoomsListWidget();
00105 }
00106 
00107 AddConstraintActivityPreferredRoomsForm::~AddConstraintActivityPreferredRoomsForm()
00108 {
00109        saveFETDialogGeometry(this);
00110 }
00111 
00112 bool AddConstraintActivityPreferredRoomsForm::filterOk(Activity* act)
00113 {
00114        QString tn=teachersComboBox->currentText();
00115        QString stn=studentsComboBox->currentText();
00116        QString sbn=subjectsComboBox->currentText();
00117        QString sbtn=activityTagsComboBox->currentText();
00118        int ok=true;
00119 
00120        //teacher
00121        if(tn!=""){
00122               bool ok2=false;
00123               for(QStringList::Iterator it=act->teachersNames.begin(); it!=act->teachersNames.end(); it++)
00124                      if(*it == tn){
00125                             ok2=true;
00126                             break;
00127                      }
00128               if(!ok2)
00129                      ok=false;
00130        }
00131 
00132        //subject
00133        if(sbn!="" && sbn!=act->subjectName)
00134               ok=false;
00135               
00136        //activity tag
00137        if(sbtn!="" && !act->activityTagsNames.contains(sbtn))
00138               ok=false;
00139               
00140        //students
00141        if(stn!=""){
00142               bool ok2=false;
00143               for(QStringList::Iterator it=act->studentsNames.begin(); it!=act->studentsNames.end(); it++)
00144                      if(*it == stn){
00145                             ok2=true;
00146                             break;
00147                      }
00148               if(!ok2)
00149                      ok=false;
00150        }
00151        
00152        return ok;
00153 }
00154 
00155 void AddConstraintActivityPreferredRoomsForm::updateActivitiesComboBox(){
00156        activitiesComboBox->clear();
00157        activitiesList.clear();
00158        
00159        for(int i=0; i<gt.rules.activitiesList.size(); i++){
00160               Activity* act=gt.rules.activitiesList[i];
00161               
00162               if(filterOk(act)){
00163                      activitiesComboBox->addItem(act->getDescription(gt.rules));
00164                      this->activitiesList.append(act->id);
00165               }
00166        }
00167 }
00168 
00169 void AddConstraintActivityPreferredRoomsForm::filterChanged()
00170 {
00171        this->updateActivitiesComboBox();
00172 }
00173 
00174 void AddConstraintActivityPreferredRoomsForm::updateRoomsListWidget()
00175 {
00176        roomsListWidget->clear();
00177        selectedRoomsListWidget->clear();
00178 
00179        for(int i=0; i<gt.rules.roomsList.size(); i++){
00180               Room* rm= gt.rules.roomsList[i];
00181               roomsListWidget->addItem(rm->name);
00182        }
00183 }
00184 
00185 void AddConstraintActivityPreferredRoomsForm::addConstraint()
00186 {
00187        SpaceConstraint *ctr=NULL;
00188 
00189        double weight;
00190        QString tmp=weightLineEdit->text();
00191        weight_sscanf(tmp, "%lf", &weight);
00192        if(weight<0.0 || weight>100){
00193               QMessageBox::warning(this, tr("FET information"),
00194                      tr("Invalid weight (percentage)"));
00195               return;
00196        }
00197 
00198        if(selectedRoomsListWidget->count()==0){
00199               QMessageBox::warning(this, tr("FET information"),
00200                      tr("Empty list of selected rooms"));
00201               return;
00202        }
00203        if(selectedRoomsListWidget->count()==1){
00204               QMessageBox::warning(this, tr("FET information"),
00205                      tr("Only one selected room - please use constraint activity preferred room if you want a single room"));
00206               return;
00207        }
00208 
00209        int id;
00210        int tmp2=activitiesComboBox->currentIndex();
00211        if(tmp2<0 || tmp2>=gt.rules.activitiesList.size() || tmp2>=activitiesList.size()){
00212               QMessageBox::warning(this, tr("FET information"),
00213                      tr("Invalid activity"));
00214               return;
00215        }
00216        else
00217               id=activitiesList.at(tmp2);
00218        
00219        QStringList roomsList;
00220        for(int i=0; i<selectedRoomsListWidget->count(); i++)
00221               roomsList.append(selectedRoomsListWidget->item(i)->text());
00222        
00223        ctr=new ConstraintActivityPreferredRooms(weight, id, roomsList);
00224        bool tmp3=gt.rules.addSpaceConstraint(ctr);
00225        
00226        if(tmp3){
00227               QString s=tr("Constraint added:");
00228               s+="\n\n";
00229               s+=ctr->getDetailedDescription(gt.rules);
00230               LongTextMessageBox::information(this, tr("FET information"), s);
00231        }
00232        else{
00233               QMessageBox::warning(this, tr("FET information"),
00234                      tr("Constraint NOT added - please report error"));
00235               delete ctr;
00236        }
00237 }
00238 
00239 void AddConstraintActivityPreferredRoomsForm::addRoom()
00240 {
00241        if(roomsListWidget->currentRow()<0)
00242               return;
00243        QString rmName=roomsListWidget->currentItem()->text();
00244        assert(rmName!="");
00245        int i;
00246        //duplicate?
00247        for(i=0; i<selectedRoomsListWidget->count(); i++)
00248               if(rmName==selectedRoomsListWidget->item(i)->text())
00249                      break;
00250        if(i<selectedRoomsListWidget->count())
00251               return;
00252        selectedRoomsListWidget->addItem(rmName);
00253        selectedRoomsListWidget->setCurrentRow(selectedRoomsListWidget->count()-1);
00254 }
00255 
00256 void AddConstraintActivityPreferredRoomsForm::removeRoom()
00257 {
00258        if(selectedRoomsListWidget->currentRow()<0 || selectedRoomsListWidget->count()<=0)
00259               return;
00260        int tmp=selectedRoomsListWidget->currentRow();
00261        
00262        selectedRoomsListWidget->setCurrentRow(-1);
00263        QListWidgetItem* item=selectedRoomsListWidget->takeItem(tmp);
00264        delete item;
00265        if(tmp<selectedRoomsListWidget->count())
00266               selectedRoomsListWidget->setCurrentRow(tmp);
00267        else
00268               selectedRoomsListWidget->setCurrentRow(selectedRoomsListWidget->count()-1);
00269 }
00270 
00271 void AddConstraintActivityPreferredRoomsForm::clear()
00272 {
00273        selectedRoomsListWidget->clear();
00274 }