// Build the Histogram
void frmStats::setupGrafico()
{
// qDebug() << "frmStats setupGrafico";
if (maxCifraAnno == 0)
{
singolaUnitaIsto = 0;
}
else
{
singolaUnitaIsto = - 1 * (double(maxAltezzaIsto) / double(maxCifraAnno));
}
scene->clear();
// X line
endY - margineY), 0, scene);
ascissa
->setPen
(QPen(Qt
::black,
3, Qt
::SolidLine));
// Y line
scene);
ordinata
->setPen
(QPen(Qt
::black,
3, Qt
::SolidLine));
for (int i = 1; i < 4; i++)
{
// 25%, 50% and 75% lines
int factorY = ((endY - margineY) / 4) * i;
(margineX, factorY, endX - 10, factorY), 0, scene);
livelliY
->setPen
(QPen(Qt
::black,
1, Qt
::DashLine));
int h = int(testoPercentuale->boundingRect().height() / 2);
int w = int(testoPercentuale->boundingRect().width());
testoPercentuale->setPos(margineX - w, factorY - h);
}
font.setPointSize(14);
for (int i = 0; i < 12; i++)
{
/*
Draw the histogram's values per month
*/
60, int(totMese[i] * singolaUnitaIsto)), 0, scene);
isto
->setPen
(QPen(Qt
::black,
1, Qt
::SolidLine));
isto->setBrush(Qt::green);
isto->setOpacity(0.7);
/*
histogram' s text
*/
inEuro
= QString("%L1").
arg(totMese
[i
] ,
12,
'f',
2,
' ');
testoIsto->setFont(font);
testoIsto->setDefaultTextColor(Qt::black);
testoIsto->setHtml(inEuro);
int xSize = int(testoIsto->boundingRect().height());
testoIsto->setPos(margineX + 2 + 30 - int(xSize / 2) + 60 * i,
(endY - margineY - 2));
testoIsto->rotate(-90);
testoIsto->translate(20, 0);
/*
Porto in fronte - di livello - il testo con setZValue.
*/
testoIsto->setZValue(0.1);
/*
Month's text
*/
int h = int(testoMese->boundingRect().height() / 2);
int w = int(testoMese->boundingRect().width() / 2);
testoMese->setPos
(margineX + 30 - w + 60 * i, (endY - (margineY / 2 + h)));
}
}
// Build the Histogram
void frmStats::setupGrafico()
{
// qDebug() << "frmStats setupGrafico";
if (maxCifraAnno == 0)
{
singolaUnitaIsto = 0;
}
else
{
singolaUnitaIsto = - 1 * (double(maxAltezzaIsto) / double(maxCifraAnno));
}
scene->clear();
// X line
QGraphicsLineItem *ascissa =
new QGraphicsLineItem(QLine(margineX, endY - margineY, endX - 10,
endY - margineY), 0, scene);
ascissa->setPen(QPen(Qt::black, 3, Qt::SolidLine));
// Y line
QGraphicsLineItem *ordinata =
new QGraphicsLineItem(QLine(margineX, 10, margineX, endY - margineY), 0,
scene);
ordinata->setPen(QPen(Qt::black, 3, Qt::SolidLine));
for (int i = 1; i < 4; i++)
{
// 25%, 50% and 75% lines
int factorY = ((endY - margineY) / 4) * i;
QGraphicsLineItem *livelliY =
new QGraphicsLineItem(QLine
(margineX, factorY, endX - 10, factorY), 0, scene);
livelliY->setPen(QPen(Qt::black, 1, Qt::DashLine));
QGraphicsTextItem *testoPercentuale =
new QGraphicsTextItem(QString::number(100 - (25 * i)) + "%", 0, scene);
int h = int(testoPercentuale->boundingRect().height() / 2);
int w = int(testoPercentuale->boundingRect().width());
testoPercentuale->setPos(margineX - w, factorY - h);
}
QString inEuro;
QFont font;
font.setPointSize(14);
for (int i = 0; i < 12; i++)
{
/*
Draw the histogram's values per month
*/
QGraphicsRectItem *isto =
new QGraphicsRectItem(QRect(margineX + 1 + 60 * i, endY - margineY - 1,
60, int(totMese[i] * singolaUnitaIsto)), 0, scene);
isto->setPen(QPen(Qt::black, 1, Qt::SolidLine));
isto->setBrush(Qt::green);
isto->setOpacity(0.7);
/*
histogram' s text
*/
inEuro = QString("%L1").arg(totMese[i] ,12,'f',2,' ');
QGraphicsTextItem *testoIsto =
new QGraphicsTextItem("", 0, scene);
testoIsto->setFont(font);
testoIsto->setDefaultTextColor(Qt::black);
testoIsto->setHtml(inEuro);
int xSize = int(testoIsto->boundingRect().height());
testoIsto->setPos(margineX + 2 + 30 - int(xSize / 2) + 60 * i,
(endY - margineY - 2));
testoIsto->rotate(-90);
testoIsto->translate(20, 0);
/*
Porto in fronte - di livello - il testo con setZValue.
*/
testoIsto->setZValue(0.1);
/*
Month's text
*/
QGraphicsTextItem *testoMese =
new QGraphicsTextItem(mesiAnno.at(i), 0, scene);
int h = int(testoMese->boundingRect().height() / 2);
int w = int(testoMese->boundingRect().width() / 2);
testoMese->setPos
(margineX + 30 - w + 60 * i, (endY - (margineY / 2 + h)));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks