Back to index

fet  5.18.0
modifyconstraintstudentssethomeroomsform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintstudentsethomeroomform.cpp  -  description
00003                              -------------------
00004     begin                : April 8, 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 "modifyconstraintstudentssethomeroomsform.h"
00023 
00024 #include <QListWidget>
00025 #include <QAbstractItemView>
00026 
00027 ModifyConstraintStudentsSetHomeRoomsForm::ModifyConstraintStudentsSetHomeRoomsForm(QWidget* parent, ConstraintStudentsSetHomeRooms* ctr): QDialog(parent)
00028 {
00029        setupUi(this);
00030 
00031        okPushButton->setDefault(true);
00032        
00033        roomsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00034        selectedRoomsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00035 
00036        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
00037        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00038        connect(roomsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(addRoom()));
00039        connect(selectedRoomsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(removeRoom()));
00040        connect(clearPushButton, SIGNAL(clicked()), this, SLOT(clear()));
00041 
00042        centerWidgetOnScreen(this);
00043        restoreFETDialogGeometry(this);
00044 
00045        QSize tmp2=studentsComboBox->minimumSizeHint();
00046        Q_UNUSED(tmp2);
00047        
00048        updateRoomsListWidget();
00049        
00050        this->_ctr=ctr;
00051        
00053        //students
00054        int i=0, j=-1;
00055        studentsComboBox->clear();
00056        for(int m=0; m<gt.rules.yearsList.size(); m++){
00057               StudentsYear* sty=gt.rules.yearsList[m];
00058               studentsComboBox->addItem(sty->name);
00059               if(sty->name==this->_ctr->studentsName)
00060                      j=i;
00061               i++;
00062               for(int n=0; n<sty->groupsList.size(); n++){
00063                      StudentsGroup* stg=sty->groupsList[n];
00064                      studentsComboBox->addItem(stg->name);
00065                      if(stg->name==this->_ctr->studentsName)
00066                             j=i;
00067                      i++;
00068                      for(int p=0; p<stg->subgroupsList.size(); p++){
00069                             StudentsSubgroup* sts=stg->subgroupsList[p];
00070                             studentsComboBox->addItem(sts->name);
00071                             if(sts->name==this->_ctr->studentsName)
00072                                    j=i;
00073                             i++;
00074                      }
00075               }
00076        }
00077        assert(j>=0);
00078        studentsComboBox->setCurrentIndex(j);
00080        
00081        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00082        
00083        for(QStringList::Iterator it=ctr->roomsNames.begin(); it!=ctr->roomsNames.end(); it++)
00084               selectedRoomsListWidget->addItem(*it);
00085 }
00086 
00087 ModifyConstraintStudentsSetHomeRoomsForm::~ModifyConstraintStudentsSetHomeRoomsForm()
00088 {
00089        saveFETDialogGeometry(this);
00090 }
00091 
00092 void ModifyConstraintStudentsSetHomeRoomsForm::updateRoomsListWidget()
00093 {
00094        roomsListWidget->clear();
00095        selectedRoomsListWidget->clear();
00096 
00097        for(int i=0; i<gt.rules.roomsList.size(); i++){
00098               Room* rm=gt.rules.roomsList[i];
00099               roomsListWidget->addItem(rm->name);
00100        }
00101 }
00102 
00103 void ModifyConstraintStudentsSetHomeRoomsForm::ok()
00104 {
00105        double weight;
00106        QString tmp=weightLineEdit->text();
00107        weight_sscanf(tmp, "%lf", &weight);
00108        if(weight<0.0 || weight>100){
00109               QMessageBox::warning(this, tr("FET information"),
00110                      tr("Invalid weight"));
00111               return;
00112        }
00113 
00114        if(selectedRoomsListWidget->count()==0){
00115               QMessageBox::warning(this, tr("FET information"),
00116                      tr("Empty list of selected rooms"));
00117               return;
00118        }
00119        if(selectedRoomsListWidget->count()==1){
00120               QMessageBox::warning(this, tr("FET information"),
00121                      tr("Only one selected room - please use constraint students set home room if you want a single room"));
00122               return;
00123        }
00124 
00125        QString students=studentsComboBox->currentText();
00126        assert(gt.rules.searchStudentsSet(students)!=NULL);
00127 
00128        QStringList roomsList;
00129        for(int i=0; i<selectedRoomsListWidget->count(); i++)
00130               roomsList.append(selectedRoomsListWidget->item(i)->text());
00131        
00132        this->_ctr->weightPercentage=weight;
00133 
00134        this->_ctr->studentsName=students;
00135 
00136        this->_ctr->roomsNames=roomsList;
00137        
00138        gt.rules.internalStructureComputed=false;
00139        setRulesModifiedAndOtherThings(&gt.rules);
00140        
00141        this->close();
00142 }
00143 
00144 void ModifyConstraintStudentsSetHomeRoomsForm::cancel()
00145 {
00146        this->close();
00147 }
00148 
00149 void ModifyConstraintStudentsSetHomeRoomsForm::addRoom()
00150 {
00151        if(roomsListWidget->currentRow()<0)
00152               return;
00153        QString rmName=roomsListWidget->currentItem()->text();
00154        assert(rmName!="");
00155        int i;
00156        //duplicate?
00157        for(i=0; i<selectedRoomsListWidget->count(); i++)
00158               if(rmName==selectedRoomsListWidget->item(i)->text())
00159                      break;
00160        if(i<selectedRoomsListWidget->count())
00161               return;
00162        selectedRoomsListWidget->addItem(rmName);
00163        selectedRoomsListWidget->setCurrentRow(selectedRoomsListWidget->count()-1);
00164 }
00165 
00166 void ModifyConstraintStudentsSetHomeRoomsForm::removeRoom()
00167 {
00168        if(selectedRoomsListWidget->currentRow()<0 || selectedRoomsListWidget->count()<=0)
00169               return;
00170        int tmp=selectedRoomsListWidget->currentRow();
00171 
00172        selectedRoomsListWidget->setCurrentRow(-1);
00173        QListWidgetItem* item=selectedRoomsListWidget->takeItem(tmp);
00174        delete item;
00175        if(tmp<selectedRoomsListWidget->count())
00176               selectedRoomsListWidget->setCurrentRow(tmp);
00177        else
00178               selectedRoomsListWidget->setCurrentRow(selectedRoomsListWidget->count()-1);
00179 }
00180 
00181 void ModifyConstraintStudentsSetHomeRoomsForm::clear()
00182 {
00183        selectedRoomsListWidget->clear();
00184 }