Back to index

fet  5.18.0
modifyconstraintsubjectpreferredroomsform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintsubjectpreferredroomsform.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 "modifyconstraintsubjectpreferredroomsform.h"
00023 
00024 #include <QListWidget>
00025 #include <QAbstractItemView>
00026 
00027 ModifyConstraintSubjectPreferredRoomsForm::ModifyConstraintSubjectPreferredRoomsForm(QWidget* parent, ConstraintSubjectPreferredRooms* 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 tmp3=subjectsComboBox->minimumSizeHint();
00046        Q_UNUSED(tmp3);
00047        
00048        updateRoomsListWidget();
00049        
00050        int i=0, j=-1;
00051        for(int k=0; k<gt.rules.subjectsList.size(); k++){
00052               Subject* sb=gt.rules.subjectsList[k];
00053               subjectsComboBox->addItem(sb->name);
00054               if(ctr->subjectName==sb->name){
00055                      assert(j==-1);
00056                      j=i;
00057               }
00058               i++;
00059        }
00060        assert(j>=0);
00061        subjectsComboBox->setCurrentIndex(j);
00062        
00063        this->_ctr=ctr;
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 ModifyConstraintSubjectPreferredRoomsForm::~ModifyConstraintSubjectPreferredRoomsForm()
00072 {
00073        saveFETDialogGeometry(this);
00074 }
00075 
00076 void ModifyConstraintSubjectPreferredRoomsForm::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 ModifyConstraintSubjectPreferredRoomsForm::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 subject preferred room if you want a single room"));
00106               return;
00107        }
00108        
00109        if(subjectsComboBox->currentIndex()<0){
00110               QMessageBox::warning(this, tr("FET information"),
00111                      tr("Invalid selected subject"));
00112               return;
00113        }
00114        QString subject=subjectsComboBox->currentText();
00115        
00116        QStringList roomsList;
00117        for(int i=0; i<selectedRoomsListWidget->count(); i++)
00118               roomsList.append(selectedRoomsListWidget->item(i)->text());
00119        
00120        this->_ctr->weightPercentage=weight;
00121        this->_ctr->subjectName=subject;
00122        this->_ctr->roomsNames=roomsList;
00123        
00124        gt.rules.internalStructureComputed=false;
00125        setRulesModifiedAndOtherThings(&gt.rules);
00126        
00127        this->close();
00128 }
00129 
00130 void ModifyConstraintSubjectPreferredRoomsForm::cancel()
00131 {
00132        this->close();
00133 }
00134 
00135 void ModifyConstraintSubjectPreferredRoomsForm::addRoom()
00136 {
00137        if(roomsListWidget->currentRow()<0)
00138               return;
00139        QString rmName=roomsListWidget->currentItem()->text();
00140        assert(rmName!="");
00141        int i;
00142        //duplicate?
00143        for(i=0; i<selectedRoomsListWidget->count(); i++)
00144               if(rmName==selectedRoomsListWidget->item(i)->text())
00145                      break;
00146        if(i<selectedRoomsListWidget->count())
00147               return;
00148        selectedRoomsListWidget->addItem(rmName);
00149        selectedRoomsListWidget->setCurrentRow(selectedRoomsListWidget->count()-1);
00150 }
00151 
00152 void ModifyConstraintSubjectPreferredRoomsForm::removeRoom()
00153 {
00154        if(selectedRoomsListWidget->currentRow()<0 || selectedRoomsListWidget->count()<=0)
00155               return;
00156        int tmp=selectedRoomsListWidget->currentRow();
00157 
00158        selectedRoomsListWidget->setCurrentRow(-1);
00159        QListWidgetItem* item=selectedRoomsListWidget->takeItem(tmp);
00160        delete item;
00161        if(tmp<selectedRoomsListWidget->count())
00162               selectedRoomsListWidget->setCurrentRow(tmp);
00163        else
00164               selectedRoomsListWidget->setCurrentRow(selectedRoomsListWidget->count()-1);
00165 }
00166 
00167 void ModifyConstraintSubjectPreferredRoomsForm::clear()
00168 {
00169        selectedRoomsListWidget->clear();
00170 }