Back to index

fet  5.18.0
addconstraintstudentssetearlymaxbeginningsatsecondhourform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintstudentssetearlymaxbeginningsatsecondhourform.cpp  -  description
00003                              -------------------
00004     begin                : July 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 #include "longtextmessagebox.h"
00021 
00022 #include "addconstraintstudentssetearlymaxbeginningsatsecondhourform.h"
00023 #include "timeconstraint.h"
00024 
00025 AddConstraintStudentsSetEarlyMaxBeginningsAtSecondHourForm::AddConstraintStudentsSetEarlyMaxBeginningsAtSecondHourForm(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 tmp2=studentsComboBox->minimumSizeHint();
00038        Q_UNUSED(tmp2);
00039        
00040        studentsComboBox->clear();  
00041        for(int i=0; i<gt.rules.yearsList.size(); i++){
00042               StudentsYear* sty=gt.rules.yearsList[i];
00043               studentsComboBox->addItem(sty->name);
00044               for(int j=0; j<sty->groupsList.size(); j++){
00045                      StudentsGroup* stg=sty->groupsList[j];
00046                      studentsComboBox->addItem(stg->name);
00047                      for(int k=0; k<stg->subgroupsList.size(); k++){
00048                             StudentsSubgroup* sts=stg->subgroupsList[k];
00049                             studentsComboBox->addItem(sts->name);
00050                      }
00051               }
00052        }
00053 
00054        maxBeginningsSpinBox->setMinimum(0);
00055        maxBeginningsSpinBox->setMaximum(gt.rules.nDaysPerWeek);
00056        maxBeginningsSpinBox->setValue(0);
00057        
00058        constraintChanged();
00059 }
00060 
00061 AddConstraintStudentsSetEarlyMaxBeginningsAtSecondHourForm::~AddConstraintStudentsSetEarlyMaxBeginningsAtSecondHourForm()
00062 {
00063        saveFETDialogGeometry(this);
00064 }
00065 
00066 void AddConstraintStudentsSetEarlyMaxBeginningsAtSecondHourForm::constraintChanged()
00067 {
00068 }
00069 
00070 void AddConstraintStudentsSetEarlyMaxBeginningsAtSecondHourForm::addCurrentConstraint()
00071 {
00072        TimeConstraint *ctr=NULL;
00073 
00074        double weight;
00075        QString tmp=weightLineEdit->text();
00076        weight_sscanf(tmp, "%lf", &weight);
00077        if(weight<0.0 || weight>100.0){
00078               QMessageBox::warning(this, tr("FET information"),
00079                      tr("Invalid weight (percentage)"));
00080               return;
00081        }
00082        if(weight!=100.0){
00083               QMessageBox::warning(this, tr("FET information"),
00084                      tr("Invalid weight (percentage) - it must be 100%"));
00085               return;
00086        }
00087 
00088        QString students_name=studentsComboBox->currentText();
00089        StudentsSet* s=gt.rules.searchStudentsSet(students_name);
00090        if(s==NULL){
00091               QMessageBox::warning(this, tr("FET information"),
00092                      tr("Invalid students set"));
00093               return;
00094        }
00095 
00096        ctr=new ConstraintStudentsSetEarlyMaxBeginningsAtSecondHour(weight, maxBeginningsSpinBox->value(), students_name);
00097 
00098        bool tmp2=gt.rules.addTimeConstraint(ctr);
00099        if(tmp2)
00100               LongTextMessageBox::information(this, tr("FET information"),
00101                      tr("Constraint added:")+"\n\n"+ctr->getDetailedDescription(gt.rules));
00102        else{
00103               QMessageBox::warning(this, tr("FET information"),
00104                      tr("Constraint NOT added - please report error"));
00105               delete ctr;
00106        }
00107 }