Back to index

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