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

« back to all changes in this revision

Viewing changes to src/interface/modifyconstraintstudentssetearlymaxbeginningsatsecondhourform.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
                          modifyconstraintstudentssetearlymaxbeginningsatsecondhourform.cpp  -  description
 
3
                             -------------------
 
4
    begin                : July 18, 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 "modifyconstraintstudentssetearlymaxbeginningsatsecondhourform.h"
 
19
#include "timeconstraint.h"
 
20
 
 
21
#include <qradiobutton.h>
 
22
#include <qlabel.h>
 
23
#include <qlineedit.h>
 
24
 
 
25
#include <QDesktopWidget>
 
26
 
 
27
//#define yesNo(x)      ((x)==0?tr("no"):tr("yes"))
 
28
 
 
29
ModifyConstraintStudentsSetEarlyMaxBeginningsAtSecondHourForm::ModifyConstraintStudentsSetEarlyMaxBeginningsAtSecondHourForm(ConstraintStudentsSetEarlyMaxBeginningsAtSecondHour* ctr)
 
30
{
 
31
        //setWindowFlags(Qt::Window);
 
32
        setWindowFlags(windowFlags() | Qt::WindowMinMaxButtonsHint);
 
33
        QDesktopWidget* desktop=QApplication::desktop();
 
34
        int xx=desktop->width()/2 - frameGeometry().width()/2;
 
35
        int yy=desktop->height()/2 - frameGeometry().height()/2;
 
36
        move(xx, yy);
 
37
 
 
38
        this->_ctr=ctr;
 
39
        
 
40
        //compulsoryCheckBox->setChecked(ctr->compulsory);
 
41
        weightLineEdit->setText(QString::number(ctr->weightPercentage));
 
42
 
 
43
        studentsComboBox->clear();
 
44
        int i=0, j=-1;
 
45
        for(int m=0; m<gt.rules.yearsList.size(); m++){
 
46
                StudentsYear* sty=gt.rules.yearsList[m];
 
47
                studentsComboBox->insertItem(sty->name);
 
48
                if(sty->name==this->_ctr->students)
 
49
                        j=i;
 
50
                i++;
 
51
                for(int n=0; n<sty->groupsList.size(); n++){
 
52
                        StudentsGroup* stg=sty->groupsList[n];
 
53
                        studentsComboBox->insertItem(stg->name);
 
54
                        if(stg->name==this->_ctr->students)
 
55
                                j=i;
 
56
                        i++;
 
57
                        for(int p=0; p<stg->subgroupsList.size(); p++){
 
58
                                StudentsSubgroup* sts=stg->subgroupsList[p];
 
59
                                studentsComboBox->insertItem(sts->name);
 
60
                                if(sts->name==this->_ctr->students)
 
61
                                        j=i;
 
62
                                i++;
 
63
                        }
 
64
                }
 
65
        }
 
66
        assert(j>=0);
 
67
        studentsComboBox->setCurrentItem(j);                                                                                                                            
 
68
        constraintChanged();
 
69
        
 
70
        maxBeginningsSpinBox->setMinValue(0);
 
71
        maxBeginningsSpinBox->setMaxValue(gt.rules.nDaysPerWeek);
 
72
        maxBeginningsSpinBox->setValue(ctr->maxBeginningsAtSecondHour);
 
73
}
 
74
 
 
75
ModifyConstraintStudentsSetEarlyMaxBeginningsAtSecondHourForm::~ModifyConstraintStudentsSetEarlyMaxBeginningsAtSecondHourForm()
 
76
{
 
77
}
 
78
 
 
79
void ModifyConstraintStudentsSetEarlyMaxBeginningsAtSecondHourForm::constraintChanged()
 
80
{
 
81
        QString s;
 
82
        s+=tr("Current constraint:");
 
83
        s+="\n";
 
84
 
 
85
        s+=tr("Students set=%1").arg(studentsComboBox->currentText());
 
86
        s+="\n";
 
87
 
 
88
        double weight;
 
89
        QString tmp=weightLineEdit->text();
 
90
        sscanf(tmp, "%lf", &weight);
 
91
        s+=tr("Weight (percentage)=%1").arg(weight);
 
92
        s+="\n";
 
93
 
 
94
        /*bool compulsory=false;
 
95
        if(compulsoryCheckBox->isChecked())
 
96
                compulsory=true;
 
97
        s+=tr("Compulsory=%1").arg(yesNo(compulsory));
 
98
        s+="\n";*/
 
99
 
 
100
        //s+=tr("Students set must begin activities as early as possible (permitted by not available and break)");
 
101
        //s+="\n";
 
102
        s+=tr("Students set must begin activities early, with maximum %1 beginnings at the second available hour, per week (not available and break not counted)")
 
103
         .arg(maxBeginningsSpinBox->value());
 
104
        s+="\n";
 
105
                        
 
106
        currentConstraintTextEdit->setText(s);
 
107
}
 
108
 
 
109
void ModifyConstraintStudentsSetEarlyMaxBeginningsAtSecondHourForm::ok()
 
110
{
 
111
        double weight;
 
112
        QString tmp=weightLineEdit->text();
 
113
        sscanf(tmp, "%lf", &weight);
 
114
        if(weight<0.0 || weight>100.0){
 
115
                QMessageBox::warning(this, tr("FET information"),
 
116
                        tr("Invalid weight (percentage)"));
 
117
                return;
 
118
        }
 
119
        if(weight!=100.0){
 
120
                QMessageBox::warning(this, tr("FET information"),
 
121
                        tr("Invalid weight (percentage) - it must be 100%"));
 
122
                return;
 
123
        }
 
124
 
 
125
        QString students_name=studentsComboBox->currentText();
 
126
        StudentsSet* s=gt.rules.searchStudentsSet(students_name);
 
127
        if(s==NULL){
 
128
                QMessageBox::warning(this, tr("FET information"),
 
129
                        tr("Invalid students set"));
 
130
                return;
 
131
        }
 
132
 
 
133
        /*bool compulsory=false;
 
134
        if(compulsoryCheckBox->isChecked())
 
135
                compulsory=true;*/
 
136
 
 
137
        this->_ctr->students=students_name;
 
138
        this->_ctr->weightPercentage=weight;
 
139
        //this->_ctr->compulsory=compulsory;
 
140
        
 
141
        this->_ctr->maxBeginningsAtSecondHour=maxBeginningsSpinBox->value();
 
142
        
 
143
        gt.rules.internalStructureComputed=false;
 
144
        
 
145
        this->close();
 
146
}
 
147
 
 
148
void ModifyConstraintStudentsSetEarlyMaxBeginningsAtSecondHourForm::cancel()
 
149
{
 
150
        this->close();
 
151
}