Back to index

fet  5.18.0
addconstraintactivitiesendstudentsdayform.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                           addconstraintactivitiesendstudentsdayform.cpp  -  description
00003                              -------------------
00004     begin                : 2008
00005     copyright            : (C) 2008 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 "addconstraintactivitiesendstudentsdayform.h"
00025 
00026 AddConstraintActivitiesEndStudentsDayForm::AddConstraintActivitiesEndStudentsDayForm(QWidget* parent): QDialog(parent)
00027 {
00028        setupUi(this);
00029 
00030        addConstraintPushButton->setDefault(true);
00031 
00032        connect(addConstraintPushButton, SIGNAL(clicked()), this, SLOT(addConstraint()));
00033        connect(closePushButton, SIGNAL(clicked()), this, SLOT(close()));
00034 
00035        centerWidgetOnScreen(this);
00036        restoreFETDialogGeometry(this);
00037 
00038        QSize tmp1=teachersComboBox->minimumSizeHint();
00039        Q_UNUSED(tmp1);
00040        QSize tmp2=studentsComboBox->minimumSizeHint();
00041        Q_UNUSED(tmp2);
00042        QSize tmp3=subjectsComboBox->minimumSizeHint();
00043        Q_UNUSED(tmp3);
00044        QSize tmp4=activityTagsComboBox->minimumSizeHint();
00045        Q_UNUSED(tmp4);
00046        
00047        updateTeachersComboBox();
00048        updateStudentsComboBox();
00049        updateSubjectsComboBox();
00050        updateActivityTagsComboBox();
00051 }
00052 
00053 AddConstraintActivitiesEndStudentsDayForm::~AddConstraintActivitiesEndStudentsDayForm()
00054 {
00055        saveFETDialogGeometry(this);
00056 }
00057 
00058 void AddConstraintActivitiesEndStudentsDayForm::updateTeachersComboBox(){
00059        teachersComboBox->clear();
00060        teachersComboBox->addItem("");
00061        for(int i=0; i<gt.rules.teachersList.size(); i++){
00062               Teacher* t=gt.rules.teachersList[i];
00063               teachersComboBox->addItem(t->name);
00064        }
00065 }
00066 
00067 void AddConstraintActivitiesEndStudentsDayForm::updateStudentsComboBox(){
00068        studentsComboBox->clear();
00069        studentsComboBox->addItem("");
00070        for(int i=0; i<gt.rules.yearsList.size(); i++){
00071               StudentsYear* sty=gt.rules.yearsList[i];
00072               studentsComboBox->addItem(sty->name);
00073               for(int j=0; j<sty->groupsList.size(); j++){
00074                      StudentsGroup* stg=sty->groupsList[j];
00075                      studentsComboBox->addItem(stg->name);
00076                      for(int k=0; k<stg->subgroupsList.size(); k++){
00077                             StudentsSubgroup* sts=stg->subgroupsList[k];
00078                             studentsComboBox->addItem(sts->name);
00079                      }
00080               }
00081        }
00082 }
00083 
00084 void AddConstraintActivitiesEndStudentsDayForm::updateSubjectsComboBox(){
00085        subjectsComboBox->clear();
00086        subjectsComboBox->addItem("");
00087        for(int i=0; i<gt.rules.subjectsList.size(); i++){
00088               Subject* s=gt.rules.subjectsList[i];
00089               subjectsComboBox->addItem(s->name);
00090        }
00091 }
00092 
00093 void AddConstraintActivitiesEndStudentsDayForm::updateActivityTagsComboBox(){
00094        activityTagsComboBox->clear();
00095        activityTagsComboBox->addItem("");
00096        for(int i=0; i<gt.rules.activityTagsList.size(); i++){
00097               ActivityTag* s=gt.rules.activityTagsList[i];
00098               activityTagsComboBox->addItem(s->name);
00099        }
00100 }
00101 
00102 void AddConstraintActivitiesEndStudentsDayForm::addConstraint()
00103 {
00104        TimeConstraint *ctr=NULL;
00105 
00106        double weight;
00107        QString tmp=weightLineEdit->text();
00108        weight_sscanf(tmp, "%lf", &weight);
00109        if(weight<0.0 || weight>100.0){
00110               QMessageBox::warning(this, tr("FET information"),
00111                      tr("Invalid weight (percentage)"));
00112               return;
00113        }
00114        if(weight!=100.0){
00115               QMessageBox::warning(this, tr("FET information"),
00116                      tr("Invalid weight (percentage) - must be 100%"));
00117               return;
00118        }
00119 
00120        QString teacher=teachersComboBox->currentText();
00121        if(teacher!="")
00122               assert(gt.rules.searchTeacher(teacher)>=0);
00123 
00124        QString students=studentsComboBox->currentText();
00125        if(students!="")
00126               assert(gt.rules.searchStudentsSet(students)!=NULL);
00127 
00128        QString subject=subjectsComboBox->currentText();
00129        if(subject!="")
00130               assert(gt.rules.searchSubject(subject)>=0);
00131               
00132        QString activityTag=activityTagsComboBox->currentText();
00133        if(activityTag!="")
00134               assert(gt.rules.searchActivityTag(activityTag)>=0);
00135               
00136        ctr=new ConstraintActivitiesEndStudentsDay(weight, teacher, students, subject, activityTag);
00137 
00138        bool tmp2=gt.rules.addTimeConstraint(ctr);
00139        if(tmp2){
00140               QString s=tr("Constraint added:");
00141               s+="\n\n";
00142               s+=ctr->getDetailedDescription(gt.rules);
00143               LongTextMessageBox::information(this, tr("FET information"), s);
00144        }
00145        else{
00146               QMessageBox::warning(this, tr("FET information"),
00147                      tr("Constraint NOT added - please report error"));
00148               delete ctr;
00149        }
00150 }