~ubuntu-branches/ubuntu/quantal/fet/quantal

« back to all changes in this revision

Viewing changes to src/interface/addconstraintteachermaxhourscontinuouslyform.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2008-05-05 22:28:46 UTC
  • mfrom: (1.1.6 upstream) (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080505222846-l34al11t2vivuh3h
Tags: 5.5.5-1ubuntu1
* Merge from debian unstable (LP: #227080), remaining changes:
  - Include .desktop file and logo

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          addconstraintteachermaxhourscontinuouslyform.cpp  -  description
 
3
                             -------------------
 
4
    begin                : July 19, 2007
 
5
    copyright            : (C) 2007 by Lalescu Liviu
 
6
    email                : Please see http://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#include "addconstraintteachermaxhourscontinuouslyform.h"
 
19
#include "timeconstraint.h"
 
20
 
 
21
#include <qradiobutton.h>
 
22
#include <qlabel.h>
 
23
#include <qlineedit.h>
 
24
 
 
25
#include <QDesktopWidget>
 
26
 
 
27
AddConstraintTeacherMaxHoursContinuouslyForm::AddConstraintTeacherMaxHoursContinuouslyForm()
 
28
{
 
29
        //setWindowFlags(Qt::Window);
 
30
        setWindowFlags(windowFlags() | Qt::WindowMinMaxButtonsHint);
 
31
        QDesktopWidget* desktop=QApplication::desktop();
 
32
        int xx=desktop->width()/2 - frameGeometry().width()/2;
 
33
        int yy=desktop->height()/2 - frameGeometry().height()/2;
 
34
        move(xx, yy);
 
35
 
 
36
        updateMaxHoursSpinBox();
 
37
 
 
38
        teachersComboBox->clear();
 
39
        for(int i=0; i<gt.rules.teachersList.size(); i++){
 
40
                Teacher* tch=gt.rules.teachersList[i];
 
41
                teachersComboBox->insertItem(tch->name);
 
42
        }
 
43
 
 
44
        constraintChanged();
 
45
}
 
46
 
 
47
AddConstraintTeacherMaxHoursContinuouslyForm::~AddConstraintTeacherMaxHoursContinuouslyForm()
 
48
{
 
49
}
 
50
 
 
51
void AddConstraintTeacherMaxHoursContinuouslyForm::updateMaxHoursSpinBox(){
 
52
        maxHoursSpinBox->setMinValue(1);
 
53
        maxHoursSpinBox->setMaxValue(gt.rules.nHoursPerDay);
 
54
        maxHoursSpinBox->setValue(gt.rules.nHoursPerDay);
 
55
}
 
56
 
 
57
void AddConstraintTeacherMaxHoursContinuouslyForm::constraintChanged()
 
58
{
 
59
        QString s;
 
60
        s+=QObject::tr("Current constraint:");
 
61
        s+="\n";
 
62
 
 
63
        double weight;
 
64
        QString tmp=weightLineEdit->text();
 
65
        sscanf(tmp, "%lf", &weight);
 
66
        s+=QObject::tr("Weight (percentage)=%1").arg(weight);
 
67
        s+="\n";
 
68
 
 
69
        /*bool compulsory=false;
 
70
        if(compulsoryCheckBox->isChecked())
 
71
                compulsory=true;
 
72
        s+=QObject::tr("Compulsory=%1").arg(yesNo(compulsory));
 
73
        s+="\n";*/
 
74
 
 
75
        s+=QObject::tr("Teacher max hours continuously");
 
76
        s+="\n";
 
77
 
 
78
        s+=QObject::tr("Teacher=%1").arg(teachersComboBox->currentText());
 
79
        s+="\n";
 
80
 
 
81
        s+=QObject::tr("Max hours continuously=%1").arg(maxHoursSpinBox->value());
 
82
        s+="\n";
 
83
 
 
84
        currentConstraintTextEdit->setText(s);
 
85
}
 
86
 
 
87
void AddConstraintTeacherMaxHoursContinuouslyForm::addCurrentConstraint()
 
88
{
 
89
        TimeConstraint *ctr=NULL;
 
90
 
 
91
        double weight;
 
92
        QString tmp=weightLineEdit->text();
 
93
        sscanf(tmp, "%lf", &weight);
 
94
        if(weight<0.0 || weight>100.0){
 
95
                QMessageBox::warning(this, QObject::tr("FET information"),
 
96
                        QObject::tr("Invalid weight (percentage)"));
 
97
                return;
 
98
        }
 
99
        /*if(weight!=100.0){
 
100
                QMessageBox::warning(this, QObject::tr("FET information"),
 
101
                        QObject::tr("Invalid weight (percentage) - must be 100%"));
 
102
                return;
 
103
        }*/
 
104
 
 
105
        QString teacher_name=teachersComboBox->currentText();
 
106
        int teacher_ID=gt.rules.searchTeacher(teacher_name);
 
107
        if(teacher_ID<0){
 
108
                QMessageBox::warning(this, QObject::tr("FET information"),
 
109
                        QObject::tr("Invalid teacher"));
 
110
                return;
 
111
        }
 
112
 
 
113
        /*bool compulsory=false;
 
114
        if(compulsoryCheckBox->isChecked())
 
115
                compulsory=true;*/
 
116
 
 
117
        int max_hours=maxHoursSpinBox->value();
 
118
 
 
119
        ctr=new ConstraintTeacherMaxHoursContinuously(weight, /*compulsory,*/ max_hours, teacher_name);
 
120
 
 
121
        bool tmp2=gt.rules.addTimeConstraint(ctr);
 
122
        if(tmp2)
 
123
                QMessageBox::information(this, QObject::tr("FET information"),
 
124
                        QObject::tr("Constraint added"));
 
125
        else{
 
126
                QMessageBox::warning(this, QObject::tr("FET information"),
 
127
                        QObject::tr("Constraint NOT added - please report error"));
 
128
                delete ctr;
 
129
        }
 
130
}