Back to index

fet  5.18.0
addconstraintstudentsactivitytagmaxhourscontinuouslyform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintstudentsactivitytagmaxhourscontinuouslyform.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 #include "longtextmessagebox.h"
00021 
00022 #include "addconstraintstudentsactivitytagmaxhourscontinuouslyform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintStudentsActivityTagMaxHoursContinuouslyForm::AddConstraintStudentsActivityTagMaxHoursContinuouslyForm(QWidget* parent): QDialog(parent)
00026 {
00027        setupUi(this);
00028 
00029        addConstraintPushButton->setDefault(true);
00030 
00031        connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addCurrentConstraint()));
00032        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00033 
00034        centerWidgetOnScreen(this);
00035        restoreFETDialogGeometry(this);
00036        
00037        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp4);
00039        
00040        maxHoursSpinBox->setMinimum(1);
00041        maxHoursSpinBox->setMaximum(gt.rules.nHoursPerDay);
00042        maxHoursSpinBox->setValue(gt.rules.nHoursPerDay);
00043 
00044        updateActivityTagsComboBox();
00045 }
00046 
00047 AddConstraintStudentsActivityTagMaxHoursContinuouslyForm::~AddConstraintStudentsActivityTagMaxHoursContinuouslyForm()
00048 {
00049        saveFETDialogGeometry(this);
00050 }
00051 
00052 void AddConstraintStudentsActivityTagMaxHoursContinuouslyForm::updateActivityTagsComboBox()
00053 {
00054        foreach(ActivityTag* at, gt.rules.activityTagsList)
00055               activityTagsComboBox->addItem(at->name);
00056 
00057        constraintChanged();
00058 }
00059 
00060 void AddConstraintStudentsActivityTagMaxHoursContinuouslyForm::constraintChanged()
00061 {
00062 }
00063 
00064 void AddConstraintStudentsActivityTagMaxHoursContinuouslyForm::addCurrentConstraint()
00065 {
00066        TimeConstraint *ctr=NULL;
00067 
00068        double weight;
00069        QString tmp=weightLineEdit->text();
00070        weight_sscanf(tmp, "%lf", &weight);
00071        if(weight<0.0 || weight>100.0){
00072               QMessageBox::warning(this, tr("FET information"),
00073                      tr("Invalid weight"));
00074               return;
00075        }
00076 
00077        int maxHours=maxHoursSpinBox->value();
00078 
00079        QString activityTagName=activityTagsComboBox->currentText();
00080        int acttagindex=gt.rules.searchActivityTag(activityTagName);
00081        if(acttagindex<0){
00082               QMessageBox::warning(this, tr("FET warning"), tr("Invalid activity tag"));
00083               return;
00084        }
00085 
00086        ctr=new ConstraintStudentsActivityTagMaxHoursContinuously(weight, maxHours, activityTagName);
00087 
00088        bool tmp2=gt.rules.addTimeConstraint(ctr);
00089        if(tmp2)
00090               LongTextMessageBox::information(this, tr("FET information"),
00091                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00092        else{
00093               QMessageBox::warning(this, tr("FET information"),
00094                      tr("Constraint NOT added - please report error"));
00095               delete ctr;
00096        }
00097 }