Back to index

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