Back to index

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