Back to index

fet  5.18.0
addconstraintteacherhomeroomsform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintteacherhomeroomsform.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 "addconstraintteacherhomeroomsform.h"
00025 
00026 #include <QListWidget>
00027 #include <QAbstractItemView>
00028 
00029 AddConstraintTeacherHomeRoomsForm::AddConstraintTeacherHomeRoomsForm(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 tmp1=teachersComboBox->minimumSizeHint();
00048        Q_UNUSED(tmp1);
00049        
00050        updateRoomsListWidget();
00051 
00052        teachersComboBox->clear();
00053        foreach(Teacher* tch, gt.rules.teachersList)
00054               teachersComboBox->addItem(tch->name);
00055 }
00056 
00057 AddConstraintTeacherHomeRoomsForm::~AddConstraintTeacherHomeRoomsForm()
00058 {
00059        saveFETDialogGeometry(this);
00060 }
00061 
00062 void AddConstraintTeacherHomeRoomsForm::updateRoomsListWidget()
00063 {
00064        roomsListWidget->clear();
00065        selectedRoomsListWidget->clear();
00066 
00067        for(int i=0; i<gt.rules.roomsList.size(); i++){
00068               Room* rm=gt.rules.roomsList[i];
00069               roomsListWidget->addItem(rm->name);
00070        }
00071 }
00072 
00073 void AddConstraintTeacherHomeRoomsForm::addConstraint()
00074 {
00075        SpaceConstraint *ctr=NULL;
00076 
00077        double weight;
00078        QString tmp=weightLineEdit->text();
00079        weight_sscanf(tmp, "%lf", &weight);
00080        if(weight<0.0 || weight>100){
00081               QMessageBox::warning(this, tr("FET information"),
00082                      tr("Invalid weight"));
00083               return;
00084        }
00085 
00086        if(selectedRoomsListWidget->count()==0){
00087               QMessageBox::warning(this, tr("FET information"),
00088                      tr("Empty list of selected rooms"));
00089               return;
00090        }
00091        if(selectedRoomsListWidget->count()==1){
00092               QMessageBox::warning(this, tr("FET information"),
00093                      tr("Only one selected room - please use constraint teacher home room if you want a single room"));
00094               return;
00095        }
00096 
00097        QString teacher=teachersComboBox->currentText();
00098        assert(gt.rules.searchTeacher(teacher)>=0);
00099 
00100        QStringList roomsList;
00101        for(int i=0; i<selectedRoomsListWidget->count(); i++)
00102               roomsList.append(selectedRoomsListWidget->item(i)->text());
00103        
00104        ctr=new ConstraintTeacherHomeRooms(weight, teacher, roomsList);
00105        bool tmp2=gt.rules.addSpaceConstraint(ctr);
00106        
00107        if(tmp2){
00108               QString s=tr("Constraint added:");
00109               s+="\n\n";
00110               s+=ctr->getDetailedDescription(gt.rules);
00111               LongTextMessageBox::information(this, tr("FET information"), s);
00112        }
00113        else{
00114               QMessageBox::warning(this, tr("FET information"),
00115                      tr("Constraint NOT added - please report error"));
00116               delete ctr;
00117        }
00118 }
00119 
00120 void AddConstraintTeacherHomeRoomsForm::addRoom()
00121 {
00122        if(roomsListWidget->currentRow()<0)
00123               return;
00124        QString rmName=roomsListWidget->currentItem()->text();
00125        assert(rmName!="");
00126        int i;
00127        //duplicate?
00128        for(i=0; i<selectedRoomsListWidget->count(); i++)
00129               if(rmName==selectedRoomsListWidget->item(i)->text())
00130                      break;
00131        if(i<selectedRoomsListWidget->count())
00132               return;
00133        selectedRoomsListWidget->addItem(rmName);
00134        selectedRoomsListWidget->setCurrentRow(selectedRoomsListWidget->count()-1);
00135 }
00136 
00137 void AddConstraintTeacherHomeRoomsForm::removeRoom()
00138 {
00139        if(selectedRoomsListWidget->currentRow()<0 || selectedRoomsListWidget->count()<=0)
00140               return;
00141        int tmp=selectedRoomsListWidget->currentRow();
00142 
00143        selectedRoomsListWidget->setCurrentRow(-1);
00144        QListWidgetItem* item=selectedRoomsListWidget->takeItem(tmp);
00145        delete item;
00146        if(tmp<selectedRoomsListWidget->count())
00147               selectedRoomsListWidget->setCurrentRow(tmp);
00148        else
00149               selectedRoomsListWidget->setCurrentRow(selectedRoomsListWidget->count()-1);
00150 }
00151 
00152 void AddConstraintTeacherHomeRoomsForm::clear()
00153 {
00154        selectedRoomsListWidget->clear();
00155 }