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
| #include <QtGui>
#include "DomComptes.h"
#include "InfoOperation.h"
#include "VueOperations.h"
CVueOperations::CVueOperations (CDomComptes *pComptes)
{
if (pComptes != 0) {
m_pComptes = pComptes;
setRootIsDecorated(false);
setAlternatingRowColors(true);
setSortingEnabled(true);
}
}
void CVueOperations::updateVueOperations(CInfoCompte infoCompte)
{
int i;
qDebug() << "## updateVueOperations ## 0 :" << columnWidth(0);
qDebug() << "## updateVueOperations ## 1 :" << columnWidth(1);
qDebug() << "## updateVueOperations ## 2 :" << columnWidth(2);
qDebug() << "## updateVueOperations ## 3 :" << columnWidth(3);
for (i=0; i < m_ListeVueOperations.size(); i++) {
qDebug() << "## updateVueOperations ## : Parcours de la liste";
if (m_ListeVueOperations.at(i).m_Nom == infoCompte.nomCompte()) {
qDebug() << "## updateVueOperations ## : Compte trouvé";
setModel(m_ListeVueOperations.at(i).m_pModel);
setColumnWidth(0, 75);
setColumnWidth(1, 265);
setColumnWidth(2, 75);
setColumnWidth(3, 75);
return;
}
}
createModel(infoCompte);
}
void CVueOperations::createModel(CInfoCompte infoCompte)
{
int i, j, k;
int myAlignment;
QString Element;
QStandardItemModel *pModel;
CModelVue modelVue;
CInfoOperation infoOperation;
qDebug() << "## createModel ## : Création du modèle";
pModel = new QStandardItemModel(0, 4, this);
pModel->setHeaderData(0, Qt::Horizontal, tr("Date"));
pModel->setHeaderData(1, Qt::Horizontal, tr("Catégorie/Sous-catégorie"));
pModel->setHeaderData(2, Qt::Horizontal, tr("Débit"));
pModel->setHeaderData(3, Qt::Horizontal, tr("Crédit"));
i = 0;
m_pComptes->firstOperation(infoCompte, infoOperation);
while (!infoOperation.isEmpty()) {
qDebug() << "## createModel ## : Parcourt les opérations :" << i;
pModel->insertRow(i);
for(j=0; j<2; j++) {
switch (j) {
case 0 : Element = QString("%1").arg(infoOperation.Date().toString("dd.MM.yyyy"));
qDebug() << "## createModel ## : la date =" << infoOperation.Date();
break;
case 1 : Element = QString("%1\n %2").arg(infoOperation.nomCategorie()).arg(infoOperation.nomSousCategorie());
qDebug() << "## createModel ## : la catégorie =" << Element;
break;
}
pModel->setData(pModel->index(i, j), Element, Qt::DisplayRole);
pModel->setData(pModel->index(i, j), Qt::AlignVCenter, Qt::TextAlignmentRole);
}
myAlignment = Qt::AlignRight | Qt::AlignVCenter;
if (infoOperation.Valeur() <= 0)
k = 2;
else
k = 3;
pModel->setData(pModel->index(i, k), QString("%1").arg(infoOperation.Valeur(), 0, 'f', 2), Qt::DisplayRole);
pModel->setData(pModel->index(i, k), myAlignment, Qt::TextAlignmentRole);
i++;
m_pComptes->nextOperation(infoCompte, infoOperation);
}
modelVue.m_Nom = infoCompte.nomCompte();
modelVue.m_pModel = pModel;
m_ListeVueOperations.append(modelVue);
setModel(pModel);
setColumnWidth(0, 75);
setColumnWidth(1, 265);
setColumnWidth(2, 75);
setColumnWidth(3, 75);
} |
Partager