Back to index

fet  5.18.0
modifyconstraintactivitytagpreferredroomsform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           modifyconstraintactivitytagpreferredroomsform.cpp  -  description
00003                              -------------------
00004     begin                : 2009
00005     copyright            : (C) 2009 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 "modifyconstraintactivitytagpreferredroomsform.h"
00023 #include "spaceconstraint.h"
00024 
00025 #include <QListWidget>
00026 #include <QAbstractItemView>
00027 
00028 ModifyConstraintActivityTagPreferredRoomsForm::ModifyConstraintActivityTagPreferredRoomsForm(QWidget* parent, ConstraintActivityTagPreferredRooms* ctr): QDialog(parent)
00029 {
00030        setupUi(this);
00031 
00032        okPushButton->setDefault(true);
00033        
00034        roomsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00035        selectedRoomsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
00036 
00037        connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancel()));
00038        connect(okPushButton, SIGNAL(clicked()), this, SLOT(ok()));
00039        connect(roomsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(addRoom()));
00040        connect(selectedRoomsListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(removeRoom()));
00041        connect(clearPushButton, SIGNAL(clicked()), this, SLOT(clear()));
00042 
00043        centerWidgetOnScreen(this);
00044        restoreFETDialogGeometry(this);
00045 
00046        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00047        Q_UNUSED(tmp4);
00048        
00049        updateRoomsListWidget();
00050        
00051        int i=0;
00052        int j=-1;
00053        for(int k=0; k<gt.rules.activityTagsList.size(); k++){
00054               ActivityTag* sb=gt.rules.activityTagsList[k];
00055               activityTagsComboBox->addItem(sb->name);
00056               if(ctr->activityTagName==sb->name){
00057                      assert(j==-1);
00058                      j=i;
00059               }
00060               i++;
00061        }
00062        assert(j>=0);
00063        activityTagsComboBox->setCurrentIndex(j);
00065        
00066        this->_ctr=ctr;
00067        
00068        weightLineEdit->setText(CustomFETString::number(ctr->weightPercentage));
00069        
00070        for(QStringList::Iterator it=ctr->roomsNames.begin(); it!=ctr->roomsNames.end(); it++)
00071               selectedRoomsListWidget->addItem(*it);
00072 }
00073 
00074 ModifyConstraintActivityTagPreferredRoomsForm::~ModifyConstraintActivityTagPreferredRoomsForm()
00075 {
00076        saveFETDialogGeometry(this);
00077 }
00078 
00079 void ModifyConstraintActivityTagPreferredRoomsForm::updateRoomsListWidget()
00080 {
00081        roomsListWidget->clear();
00082        selectedRoomsListWidget->clear();
00083 
00084        for(int i=0; i<gt.rules.roomsList.size(); i++){
00085               Room* rm=gt.rules.roomsList[i];
00086               roomsListWidget->addItem(rm->name);
00087        }
00088 }
00089 
00090 void ModifyConstraintActivityTagPreferredRoomsForm::ok()
00091 {
00092        double weight;
00093        QString tmp=weightLineEdit->text();
00094        weight_sscanf(tmp, "%lf", &weight);
00095        if(weight<0.0 || weight>100){
00096               QMessageBox::warning(this, tr("FET information"),
00097                      tr("Invalid weight"));
00098               return;
00099        }
00100 
00101        if(selectedRoomsListWidget->count()==0){
00102               QMessageBox::warning(this, tr("FET information"),
00103                      tr("Empty list of selected rooms"));
00104               return;
00105        }
00106        if(selectedRoomsListWidget->count()==1){
00107               QMessageBox::warning(this, tr("FET information"),
00108                      tr("Only one selected room - please use constraint activity tag preferred room if you want a single room"));
00109               return;
00110        }
00111        
00112        if(activityTagsComboBox->currentIndex()<0){
00113               QMessageBox::warning(this, tr("FET information"),
00114                      tr("Invalid selected activity tag"));
00115               return;
00116        }
00117        QString activityTag=activityTagsComboBox->currentText();
00118        
00119        QStringList roomsList;
00120        for(int i=0; i<selectedRoomsListWidget->count(); i++)
00121               roomsList.append(selectedRoomsListWidget->item(i)->text());
00122        
00123        this->_ctr->weightPercentage=weight;
00124        this->_ctr->activityTagName=activityTag;
00125        this->_ctr->roomsNames=roomsList;
00126        
00127        gt.rules.internalStructureComputed=false;
00128        setRulesModifiedAndOtherThings(&gt.rules);
00129        
00130        this->close();
00131 }
00132 
00133 void ModifyConstraintActivityTagPreferredRoomsForm::cancel()
00134 {
00135        this->close();
00136 }
00137 
00138 void ModifyConstraintActivityTagPreferredRoomsForm::addRoom()
00139 {
00140        if(roomsListWidget->currentRow()<0)
00141               return;
00142        QString rmName=roomsListWidget->currentItem()->text();
00143        assert(rmName!="");
00144        int i;
00145        //duplicate?
00146        for(i=0; i<selectedRoomsListWidget->count(); i++)
00147               if(rmName==selectedRoomsListWidget->item(i)->text())
00148                      break;
00149        if(i<selectedRoomsListWidget->count())
00150               return;
00151        selectedRoomsListWidget->addItem(rmName);
00152        selectedRoomsListWidget->setCurrentRow(selectedRoomsListWidget->count()-1);
00153 }
00154 
00155 void ModifyConstraintActivityTagPreferredRoomsForm::removeRoom()
00156 {
00157        if(selectedRoomsListWidget->currentRow()<0 || selectedRoomsListWidget->count()<=0)
00158               return;
00159        
00160        int tmp=selectedRoomsListWidget->currentRow();
00161        
00162        selectedRoomsListWidget->setCurrentRow(-1);
00163        QListWidgetItem* item=selectedRoomsListWidget->takeItem(tmp);
00164        delete item;
00165        if(tmp<selectedRoomsListWidget->count())
00166               selectedRoomsListWidget->setCurrentRow(tmp);
00167        else
00168               selectedRoomsListWidget->setCurrentRow(selectedRoomsListWidget->count()-1);
00169 }
00170 
00171 void ModifyConstraintActivityTagPreferredRoomsForm::clear()
00172 {
00173        selectedRoomsListWidget->clear();
00174 }