Back to index

fet  5.18.0
addconstraintactivitytagpreferredroomform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintactivitytagpreferredroomform.cpp  -  description
00003                              -------------------
00004     begin                : 2009
00005     copyright            : (C) 2009 by Liviu Lalescu
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 #include "longtextmessagebox.h"
00021 
00022 #include "addconstraintactivitytagpreferredroomform.h"
00023 #include "spaceconstraint.h"
00024 
00025 AddConstraintActivityTagPreferredRoomForm::AddConstraintActivityTagPreferredRoomForm(QWidget* parent): QDialog(parent)
00026 {
00027        setupUi(this);
00028 
00029        addConstraintPushButton->setDefault(true);
00030 
00031        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00032        connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addConstraint()));
00033 
00034        centerWidgetOnScreen(this);
00035        restoreFETDialogGeometry(this);
00036        
00037        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp4);
00039        
00040        QSize tmp5=roomsComboBox->minimumSizeHint();
00041        Q_UNUSED(tmp5);
00042 
00043        updateActivityTagsComboBox();
00044        updateRoomsComboBox();
00045 }
00046 
00047 AddConstraintActivityTagPreferredRoomForm::~AddConstraintActivityTagPreferredRoomForm()
00048 {
00049        saveFETDialogGeometry(this);
00050 }
00051 
00052 void AddConstraintActivityTagPreferredRoomForm::updateActivityTagsComboBox()
00053 {
00054        activityTagsComboBox->clear();
00055        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
00056               ActivityTag* sb=gt.rules.activityTagsList[i];
00057               activityTagsComboBox->addItem(sb->name);
00058        }
00059 }
00060 
00061 void AddConstraintActivityTagPreferredRoomForm::updateRoomsComboBox()
00062 {
00063        roomsComboBox->clear();
00064        for(int i=0; i<gt.rules.roomsList.size(); i++){
00065               Room* rm=gt.rules.roomsList[i];
00066               roomsComboBox->addItem(rm->name);
00067        }
00068 }
00069 
00070 void AddConstraintActivityTagPreferredRoomForm::addConstraint()
00071 {
00072        SpaceConstraint *ctr=NULL;
00073 
00074        double weight;
00075        QString tmp=weightLineEdit->text();
00076        weight_sscanf(tmp, "%lf", &weight);
00077        if(weight<0.0 || weight>100){
00078               QMessageBox::warning(this, tr("FET information"),
00079                      tr("Invalid weight"));
00080               return;
00081        }
00082 
00083 /*     int i=subjectsComboBox->currentIndex();
00084        if(i<0 || subjectsComboBox->count()<=0){
00085               QMessageBox::warning(this, tr("FET information"),
00086                      tr("Invalid subject"));
00087               return;
00088        }
00089        QString subject=subjectsComboBox->currentText();*/
00090 
00091        int i=activityTagsComboBox->currentIndex();
00092        if(i<0 || activityTagsComboBox->count()<=0){
00093               QMessageBox::warning(this, tr("FET information"),
00094                      tr("Invalid activity tag"));
00095               return;
00096        }
00097        QString activityTag=activityTagsComboBox->currentText();
00098 
00099        i=roomsComboBox->currentIndex();
00100        if(i<0 || roomsComboBox->count()<=0){
00101               QMessageBox::warning(this, tr("FET information"),
00102                      tr("Invalid room"));
00103               return;
00104        }
00105        QString room=roomsComboBox->currentText();
00106 
00107        ctr=new ConstraintActivityTagPreferredRoom(weight/*, subject*/, activityTag, room);
00108 
00109        bool tmp2=gt.rules.addSpaceConstraint(ctr);
00110        if(tmp2){
00111               QString s=tr("Constraint added:");
00112               s+="\n\n";
00113               s+=ctr->getDetailedDescription(gt.rules);
00114               LongTextMessageBox::information(this, tr("FET information"), s);
00115        }
00116        else{
00117               QMessageBox::warning(this, tr("FET information"),
00118                      tr("Constraint NOT added - error ?"));
00119               delete ctr;
00120        }
00121 }