Back to index

fet  5.18.0
addconstraintsubjectactivitytagpreferredroomform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintsubjectactivitytagpreferredroomform.cpp  -  description
00003                              -------------------
00004     begin                : 18 Aug 2007
00005     copyright            : (C) 2007 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 "addconstraintsubjectactivitytagpreferredroomform.h"
00023 #include "spaceconstraint.h"
00024 
00025 AddConstraintSubjectActivityTagPreferredRoomForm::AddConstraintSubjectActivityTagPreferredRoomForm(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 tmp3=subjectsComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp3);
00039        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00040        Q_UNUSED(tmp4);
00041        
00042        QSize tmp5=roomsComboBox->minimumSizeHint();
00043        Q_UNUSED(tmp5);
00044        
00045        updateSubjectsComboBox();
00046        updateActivityTagsComboBox();
00047        updateRoomsComboBox();
00048 }
00049 
00050 AddConstraintSubjectActivityTagPreferredRoomForm::~AddConstraintSubjectActivityTagPreferredRoomForm()
00051 {
00052        saveFETDialogGeometry(this);
00053 }
00054 
00055 void AddConstraintSubjectActivityTagPreferredRoomForm::updateSubjectsComboBox()
00056 {
00057        subjectsComboBox->clear();
00058        for(int i=0; i<gt.rules.subjectsList.size(); i++){
00059               Subject* sb=gt.rules.subjectsList[i];
00060               subjectsComboBox->addItem(sb->name);
00061        }
00062 }
00063 
00064 void AddConstraintSubjectActivityTagPreferredRoomForm::updateActivityTagsComboBox()
00065 {
00066        activityTagsComboBox->clear();
00067        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
00068               ActivityTag* sb=gt.rules.activityTagsList[i];
00069               activityTagsComboBox->addItem(sb->name);
00070        }
00071 }
00072 
00073 void AddConstraintSubjectActivityTagPreferredRoomForm::updateRoomsComboBox()
00074 {
00075        roomsComboBox->clear();
00076        for(int i=0; i<gt.rules.roomsList.size(); i++){
00077               Room* rm=gt.rules.roomsList[i];
00078               roomsComboBox->addItem(rm->name);
00079        }
00080 }
00081 
00082 void AddConstraintSubjectActivityTagPreferredRoomForm::addConstraint()
00083 {
00084        SpaceConstraint *ctr=NULL;
00085 
00086        double weight;
00087        QString tmp=weightLineEdit->text();
00088        weight_sscanf(tmp, "%lf", &weight);
00089        if(weight<0.0 || weight>100){
00090               QMessageBox::warning(this, tr("FET information"),
00091                      tr("Invalid weight"));
00092               return;
00093        }
00094 
00095        int i=subjectsComboBox->currentIndex();
00096        if(i<0 || subjectsComboBox->count()<=0){
00097               QMessageBox::warning(this, tr("FET information"),
00098                      tr("Invalid subject"));
00099               return;
00100        }
00101        QString subject=subjectsComboBox->currentText();
00102 
00103        i=activityTagsComboBox->currentIndex();
00104        if(i<0 || activityTagsComboBox->count()<=0){
00105               QMessageBox::warning(this, tr("FET information"),
00106                      tr("Invalid activity tag"));
00107               return;
00108        }
00109        QString activityTag=activityTagsComboBox->currentText();
00110 
00111        i=roomsComboBox->currentIndex();
00112        if(i<0 || roomsComboBox->count()<=0){
00113               QMessageBox::warning(this, tr("FET information"),
00114                      tr("Invalid room"));
00115               return;
00116        }
00117        QString room=roomsComboBox->currentText();
00118 
00119        ctr=new ConstraintSubjectActivityTagPreferredRoom(weight, subject, activityTag, room);
00120 
00121        bool tmp2=gt.rules.addSpaceConstraint(ctr);
00122        if(tmp2){
00123               QString s=tr("Constraint added:");
00124               s+="\n\n";
00125               s+=ctr->getDetailedDescription(gt.rules);
00126               LongTextMessageBox::information(this, tr("FET information"), s);
00127        }
00128        else{
00129               QMessageBox::warning(this, tr("FET information"),
00130                      tr("Constraint NOT added - error ?"));
00131               delete ctr;
00132        }
00133 }