Back to index

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