Back to index

fet  5.18.0
modifyconstraintteacherhomeroomsform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintteacherhomeroomform.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 "modifyconstraintteacherhomeroomsform.h"
00023 
00024 #include <QListWidget>
00025 #include <QAbstractItemView>
00026 
00027 ModifyConstraintTeacherHomeRoomsForm::ModifyConstraintTeacherHomeRoomsForm(QWidget* parent, ConstraintTeacherHomeRooms* 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 tmp1=teachersComboBox->minimumSizeHint();
00046        Q_UNUSED(tmp1);
00047        
00048        updateRoomsListWidget();
00049        
00050        this->_ctr=ctr;
00051        
00053        teachersComboBox->clear();
00054        int i=0, j=-1;
00055        for(int k=0; k<gt.rules.teachersList.size(); k++, i++){
00056               Teacher* tch=gt.rules.teachersList[k];
00057                      teachersComboBox->addItem(tch->name);
00058                             if(tch->name==this->_ctr->teacherName)
00059                                    j=i;
00060        }
00061        assert(j>=0);
00062        teachersComboBox->setCurrentIndex(j);
00064        
00065        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00066        
00067        for(QStringList::Iterator it=ctr->roomsNames.begin(); it!=ctr->roomsNames.end(); it++)
00068               selectedRoomsListWidget->addItem(*it);
00069 }
00070 
00071 ModifyConstraintTeacherHomeRoomsForm::~ModifyConstraintTeacherHomeRoomsForm()
00072 {
00073        saveFETDialogGeometry(this);
00074 }
00075 
00076 void ModifyConstraintTeacherHomeRoomsForm::updateRoomsListWidget()
00077 {
00078        roomsListWidget->clear();
00079        selectedRoomsListWidget->clear();
00080 
00081        for(int i=0; i<gt.rules.roomsList.size(); i++){
00082               Room* rm=gt.rules.roomsList[i];
00083               roomsListWidget->addItem(rm->name);
00084        }
00085 }
00086 
00087 void ModifyConstraintTeacherHomeRoomsForm::ok()
00088 {
00089        double weight;
00090        QString tmp=weightLineEdit->text();
00091        weight_sscanf(tmp, "%lf", &weight);
00092        if(weight<0.0 || weight>100){
00093               QMessageBox::warning(this, tr("FET information"),
00094                      tr("Invalid weight"));
00095               return;
00096        }
00097 
00098        if(selectedRoomsListWidget->count()==0){
00099               QMessageBox::warning(this, tr("FET information"),
00100                      tr("Empty list of selected rooms"));
00101               return;
00102        }
00103        if(selectedRoomsListWidget->count()==1){
00104               QMessageBox::warning(this, tr("FET information"),
00105                      tr("Only one selected room - please use constraint teacher home room if you want a single room"));
00106               return;
00107        }
00108 
00109        QString teacher=teachersComboBox->currentText();
00110        assert(gt.rules.searchTeacher(teacher)>=0);
00111 
00112        QStringList roomsList;
00113        for(int i=0; i<selectedRoomsListWidget->count(); i++)
00114               roomsList.append(selectedRoomsListWidget->item(i)->text());
00115        
00116        this->_ctr->weightPercentage=weight;
00117 
00118        this->_ctr->teacherName=teacher;
00119 
00120        this->_ctr->roomsNames=roomsList;
00121        
00122        gt.rules.internalStructureComputed=false;
00123        setRulesModifiedAndOtherThings(&gt.rules);
00124        
00125        this->close();
00126 }
00127 
00128 void ModifyConstraintTeacherHomeRoomsForm::cancel()
00129 {
00130        this->close();
00131 }
00132 
00133 void ModifyConstraintTeacherHomeRoomsForm::addRoom()
00134 {
00135        if(roomsListWidget->currentRow()<0)
00136               return;
00137        QString rmName=roomsListWidget->currentItem()->text();
00138        assert(rmName!="");
00139        int i;
00140        //duplicate?
00141        for(i=0; i<selectedRoomsListWidget->count(); i++)
00142               if(rmName==selectedRoomsListWidget->item(i)->text())
00143                      break;
00144        if(i<selectedRoomsListWidget->count())
00145               return;
00146        selectedRoomsListWidget->addItem(rmName);
00147        selectedRoomsListWidget->setCurrentRow(selectedRoomsListWidget->count()-1);
00148 }
00149 
00150 void ModifyConstraintTeacherHomeRoomsForm::removeRoom()
00151 {
00152        if(selectedRoomsListWidget->currentRow()<0 || selectedRoomsListWidget->count()<=0)
00153               return;
00154        int tmp=selectedRoomsListWidget->currentRow();
00155 
00156        selectedRoomsListWidget->setCurrentRow(-1);
00157        QListWidgetItem* item=selectedRoomsListWidget->takeItem(tmp);
00158        delete item;
00159        if(tmp<selectedRoomsListWidget->count())
00160               selectedRoomsListWidget->setCurrentRow(tmp);
00161        else
00162               selectedRoomsListWidget->setCurrentRow(selectedRoomsListWidget->count()-1);
00163 }
00164 
00165 void ModifyConstraintTeacherHomeRoomsForm::clear()
00166 {
00167        selectedRoomsListWidget->clear();
00168 }