Back to index

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