Back to index

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