This repository has been archived by the owner on Aug 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifieruv_fen.cpp
112 lines (103 loc) · 3.28 KB
/
modifieruv_fen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "modifieruv_fen.h"
#include "ui_modifieruv_fen.h"
Modifieruv_fen::Modifieruv_fen(UV& uv, QWidget *parent) :
QDialog(parent),
ui(new Ui::Modifieruv_fen),
uv(&uv)
{
ui->setupUi(this);
b=1;
ui->code->setText(QString(uv.getCode().c_str()));
ui->code->setDisabled(1);
ui->nom->setText(QString(uv.getTitre().c_str()));
ui->automne->setChecked(uv.ouvertureAutomne());
ui->printemps->setChecked(uv.ouverturePrintemps());
TemplateManager<Categorie>& tCat=TemplateManager<Categorie>::getInstance();
for(unsigned int i=0; i<tCat.size(); i++)
{
ui->type_cat->addItem(tCat.getIterator()[i].getCode());
}
QObject::connect(ui->Ok, SIGNAL(clicked()), this, SLOT(ok()) );
QObject::connect(ui->Cancel, SIGNAL(clicked()), this, SLOT(cancel()) );
QObject::connect(ui->appliquer, SIGNAL(clicked()), this, SLOT(updateCredits()) );
QObject::connect(ui->type_cat, SIGNAL(currentIndexChanged(QString)), this, SLOT(afficheCredits(QString)) );
}
Modifieruv_fen::Modifieruv_fen(QWidget *parent) :
QDialog(parent),
ui(new Ui::Modifieruv_fen)
{
uv=NULL;
b=0;
ui->setupUi(this);
TemplateManager<Categorie>& tCat=TemplateManager<Categorie>::getInstance();
for(unsigned int i=0; i<tCat.size(); i++)
{
ui->type_cat->addItem(tCat.getIterator()[i].getCode());
}
QObject::connect(ui->Ok, SIGNAL(clicked()), this, SLOT(ok()) );
QObject::connect(ui->Cancel, SIGNAL(clicked()), this, SLOT(cancel()) );
QObject::connect(ui->appliquer, SIGNAL(clicked()), this, SLOT(updateCredits()) );
QObject::connect(ui->type_cat, SIGNAL(currentIndexChanged(QString)), this, SLOT(afficheCredits(QString)) );
}
Modifieruv_fen::~Modifieruv_fen()
{
delete ui;
}
void Modifieruv_fen::ok()
{
try
{
if(!b)
{
uv = new UV(ui->code->text().toStdString(), ui->nom->text().toStdString(), cat, ui->automne->isChecked(), ui->printemps->isChecked());
delete uv;
}
else
{
uv->setTitre(ui->nom->text().toStdString());
uv->setAutomne(ui->automne->isChecked());
uv->setPrintemps(ui->printemps->isChecked());
}
this->close();
}
catch(std::exception& e)
{
QMessageBox::warning(this, "Erreur", e.what());
}
}
void Modifieruv_fen::cancel()
{
this->close();
}
void Modifieruv_fen::updateCredits()
{
TemplateManager<Categorie>& tCat=TemplateManager<Categorie>::getInstance();
if(b)
{
uv->setCredits(tCat.getElement(ui->type_cat->currentText()), ui->nb_credit->text().toUInt());
}
else
{
cat[tCat.getElement(ui->type_cat->currentText())]=ui->nb_credit->text().toUInt();
}
}
void Modifieruv_fen::afficheCredits(QString q)
{
TemplateManager<Categorie>& tCat=TemplateManager<Categorie>::getInstance();
if(b)
{
const map<Categorie, unsigned int> cre=uv->getCredits();
if(cre.find(tCat.getElement(q.toStdString()))!=cre.end())
{
ui->nb_credit->setText(QString::number(uv->getCredits().find(tCat.getElement(q.toStdString()))->second));
}
else
{
ui->nb_credit->setText("0");
}
}
else
{
ui->nb_credit->setText(QString::number(cat[tCat.getElement(q.toStdString())]));
}
}