forked from Betcheg/gestionnairedaffectations
/
tableauderemplissage.cpp
123 lines (106 loc) · 5.8 KB
/
tableauderemplissage.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
113
114
115
116
117
118
119
120
121
122
123
#include "tableauderemplissage.h"
#include <QSqlQuery>
#include <QSqlRecord>
#include <QTextCursor>
#include <QLocale>
#include <QDate>
#include <QDebug>
#include <QSqlError>
TableauDeRemplissage::TableauDeRemplissage(int idEvenement, QObject *parent)
: Etat(tr("Tableau de remplissage"), idEvenement, parent)
{
QSqlQuery query;
if (query.prepare("select *"
" from tableau_de_remplissage"
" where id_evenement=:id_evenement")) {
query.bindValue(":id_evenement", idEvenement);
if (query.exec()) {
// FIXME : ce rapport devrait être une feuille de calcul
QString symboleAcceptee = "●";
QString symboleProposee = "◍";
QString symbolePossible = "○";
QString symboleManquante = "◌";
QTextCursor c(this);
QTextBlockFormat formatDuTitreDeLaLegende;
formatDuTitreDeLaLegende.setBottomMargin(10);
QTextCharFormat formatDesCaracteresDuTitreDeLaLegende;
formatDesCaracteresDuTitreDeLaLegende.setUnderlineStyle(QTextCharFormat::SingleUnderline);
QTextBlockFormat formatDesBlocsDeLaLegende;
QTextCharFormat formatDesCaracteresDeLaLegende;
QTextListFormat formatDeLaListeDeLaLegende;
QTextBlockFormat formatDuBlocJour;
formatDuBlocJour.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore);
formatDuBlocJour.setAlignment(Qt::AlignCenter);
formatDuBlocJour.setBottomMargin(20);
QTextCharFormat formatDesCaracteresDuJour;
formatDesCaracteresDuJour.setFontCapitalization(QFont::Capitalize);
formatDesCaracteresDuJour.setFontPointSize(14);
formatDesCaracteresDuJour.setFontWeight(QFont::Bold);
QTextBlockFormat formatDuBlocTour;
formatDuBlocTour.setTopMargin(20);
QTextCharFormat formatDesCaracteresDuTour;
formatDesCaracteresDuTour.setFontWeight(QFont::Bold);
QTextBlockFormat formatDuBlocDesResponsables;
QTextCharFormat formatDesCaracteresDesResponsables;
QTextBlockFormat formatDuBlocDuRemplissage;
QTextCharFormat formatDesCaracteresDuRemplissage;
if (query.first()) {
c.movePosition(QTextCursor::End);
c.insertBlock(formatDuTitreDeLaLegende, formatDesCaracteresDuTitreDeLaLegende);
c.insertText(tr("Légende"));
c.insertBlock(formatDesBlocsDeLaLegende, formatDesCaracteresDeLaLegende);
c.insertList(formatDeLaListeDeLaLegende);
c.insertText(tr("%1 affectation acceptée ou validée").arg(symboleAcceptee));
c.insertText("\n");
c.insertText(tr("%1 affectation proposée, en attente d'acceptation").arg(symboleProposee));
c.insertText("\n");
c.insertText(tr("%1 affectation possible, à proposer ou valider").arg(symbolePossible));
c.insertText("\n");
c.insertText(tr("%1 affectation manquante, reste à créer").arg(symboleManquante));
QSqlRecord r = query.record();
do {
QDate jour = r.value("debut_tour").toDate();
c.insertBlock(formatDuBlocJour, formatDesCaracteresDuJour);
c.insertText(QLocale().toString(jour));
do {
int
min = r.value("min").toInt(),
max = r.value("max").toInt(),
possibles = r.value("nombre_affectations_possibles").toInt(),
proposees = r.value("nombre_affectations_proposees").toInt(),
acceptees = r.value("nombre_affectations_validees_ou_acceptees").toInt(),
trouvees = acceptees + proposees + possibles,
manquantes = trouvees < min ? min - trouvees : 0,
enTrop = max < trouvees ? trouvees - max : 0;
QString responsables = r.value("liste_responsables").toString();
c.insertBlock(formatDuBlocTour, formatDesCaracteresDuTour);
c.insertText(tr("De %1 à %2 / %3")
.arg(r.value("debut_tour").toTime().toString("H:mm"))
.arg(r.value("fin_tour").toTime().toString("H:mm"))
.arg(r.value("nom_poste").toString())
);
if (!responsables.isEmpty()) {
c.insertBlock(formatDuBlocDesResponsables, formatDesCaracteresDesResponsables);
c.insertText(tr("Responsable(s) : %1").arg(responsables));
}
c.insertBlock(formatDuBlocDuRemplissage, formatDesCaracteresDuRemplissage);
c.insertText(symboleAcceptee.repeated(acceptees));
c.insertText(symboleProposee.repeated(proposees));
c.insertText(symbolePossible.repeated(possibles));
c.insertText(symboleManquante.repeated(manquantes));
if (enTrop) c.insertText(tr(" (%n affectation(s) en trop)", "", enTrop));
query.next();
r = query.record();
} while (query.isValid()
&& r.value("debut_tour").toDate() == jour);
} while (query.isValid());
} else {
qWarning() << tr("Aucune affectation trouvée");
}
} else {
qCritical() << query.lastError();
}
} else {
qCritical() << query.lastError();
}
}