mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 00:33:02 +03:00
Refactor min and max values
This commit is contained in:
parent
e415611fa0
commit
e3bd7e05d5
@ -4,11 +4,15 @@ namespace LimeReport{
|
|||||||
|
|
||||||
void HorizontalBarChart::paintChart(QPainter *painter, QRectF chartRect)
|
void HorizontalBarChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||||
{
|
{
|
||||||
|
updateMinAndMaxValues();
|
||||||
|
|
||||||
|
const qreal valuesVMargin = this->valuesVMargin(painter);
|
||||||
|
|
||||||
QRectF calcRect = verticalLabelsRect(painter, chartRect.adjusted(
|
QRectF calcRect = verticalLabelsRect(painter, chartRect.adjusted(
|
||||||
hPadding(chartRect),
|
hPadding(chartRect),
|
||||||
vPadding(chartRect) * 2,
|
vPadding(chartRect) * 2,
|
||||||
-(chartRect.width() * 0.9),
|
-(chartRect.width() * 0.9),
|
||||||
-(vPadding(chartRect) * 2 + valuesVMargin(painter))
|
-(vPadding(chartRect) * 2 + valuesVMargin)
|
||||||
));
|
));
|
||||||
|
|
||||||
qreal barsShift = calcRect.width();
|
qreal barsShift = calcRect.width();
|
||||||
|
@ -4,10 +4,15 @@ namespace LimeReport {
|
|||||||
|
|
||||||
void LinesChart::paintChart(QPainter *painter, QRectF chartRect)
|
void LinesChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||||
{
|
{
|
||||||
|
updateMinAndMaxValues();
|
||||||
|
|
||||||
|
const qreal valuesHMargin = this->valuesHMargin(painter);
|
||||||
|
const qreal valuesVMargin = this->valuesVMargin(painter);
|
||||||
|
|
||||||
QRectF calcRect = horizontalLabelsRect(
|
QRectF calcRect = horizontalLabelsRect(
|
||||||
painter,
|
painter,
|
||||||
chartRect.adjusted(
|
chartRect.adjusted(
|
||||||
hPadding(chartRect) * 2 + valuesHMargin(painter),
|
hPadding(chartRect) * 2 + valuesHMargin,
|
||||||
chartRect.height() - (painter->fontMetrics().height() + vPadding(chartRect)*2),
|
chartRect.height() - (painter->fontMetrics().height() + vPadding(chartRect)*2),
|
||||||
-(hPadding(chartRect) * 2),
|
-(hPadding(chartRect) * 2),
|
||||||
-vPadding(chartRect)
|
-vPadding(chartRect)
|
||||||
@ -18,7 +23,7 @@ void LinesChart::paintChart(QPainter *painter, QRectF chartRect)
|
|||||||
painter,
|
painter,
|
||||||
chartRect.adjusted(
|
chartRect.adjusted(
|
||||||
hPadding(chartRect),
|
hPadding(chartRect),
|
||||||
vPadding(chartRect) + valuesVMargin(painter),
|
vPadding(chartRect) + valuesVMargin,
|
||||||
-hPadding(chartRect),
|
-hPadding(chartRect),
|
||||||
-(vPadding(chartRect) + barsShift)
|
-(vPadding(chartRect) + barsShift)
|
||||||
)
|
)
|
||||||
@ -26,8 +31,8 @@ void LinesChart::paintChart(QPainter *painter, QRectF chartRect)
|
|||||||
paintSerialLines(
|
paintSerialLines(
|
||||||
painter,
|
painter,
|
||||||
chartRect.adjusted(
|
chartRect.adjusted(
|
||||||
hPadding(chartRect) * 2 + valuesHMargin(painter),
|
hPadding(chartRect) * 2 + valuesHMargin,
|
||||||
vPadding(chartRect) + valuesVMargin(painter),
|
vPadding(chartRect) + valuesVMargin,
|
||||||
-(hPadding(chartRect) * 2),
|
-(hPadding(chartRect) * 2),
|
||||||
-(vPadding(chartRect)+barsShift)
|
-(vPadding(chartRect)+barsShift)
|
||||||
)
|
)
|
||||||
|
@ -4,10 +4,15 @@ namespace LimeReport{
|
|||||||
|
|
||||||
void VerticalBarChart::paintChart(QPainter *painter, QRectF chartRect)
|
void VerticalBarChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||||
{
|
{
|
||||||
|
updateMinAndMaxValues();
|
||||||
|
|
||||||
|
const qreal valuesHMargin = this->valuesHMargin(painter);
|
||||||
|
const qreal valuesVMargin = this->valuesVMargin(painter);
|
||||||
|
|
||||||
QRectF calcRect = horizontalLabelsRect(
|
QRectF calcRect = horizontalLabelsRect(
|
||||||
painter,
|
painter,
|
||||||
chartRect.adjusted(
|
chartRect.adjusted(
|
||||||
hPadding(chartRect) * 2 + valuesHMargin(painter),
|
hPadding(chartRect) * 2 + valuesHMargin,
|
||||||
chartRect.height() - (painter->fontMetrics().height() + vPadding(chartRect) * 2),
|
chartRect.height() - (painter->fontMetrics().height() + vPadding(chartRect) * 2),
|
||||||
-(hPadding(chartRect) * 2),
|
-(hPadding(chartRect) * 2),
|
||||||
-vPadding(chartRect)
|
-vPadding(chartRect)
|
||||||
@ -18,7 +23,7 @@ void VerticalBarChart::paintChart(QPainter *painter, QRectF chartRect)
|
|||||||
painter,
|
painter,
|
||||||
chartRect.adjusted(
|
chartRect.adjusted(
|
||||||
hPadding(chartRect),
|
hPadding(chartRect),
|
||||||
vPadding(chartRect) + valuesVMargin(painter),
|
vPadding(chartRect) + valuesVMargin,
|
||||||
-hPadding(chartRect),
|
-hPadding(chartRect),
|
||||||
-(vPadding(chartRect) + barsShift)
|
-(vPadding(chartRect) + barsShift)
|
||||||
)
|
)
|
||||||
@ -26,8 +31,8 @@ void VerticalBarChart::paintChart(QPainter *painter, QRectF chartRect)
|
|||||||
paintVerticalBars(
|
paintVerticalBars(
|
||||||
painter,
|
painter,
|
||||||
chartRect.adjusted(
|
chartRect.adjusted(
|
||||||
hPadding(chartRect) * 2 + valuesHMargin(painter),
|
hPadding(chartRect) * 2 + valuesHMargin,
|
||||||
vPadding(chartRect) + valuesVMargin(painter),
|
vPadding(chartRect) + valuesVMargin,
|
||||||
-hPadding(chartRect) * 2,
|
-hPadding(chartRect) * 2,
|
||||||
-(vPadding(chartRect) + barsShift)
|
-(vPadding(chartRect) + barsShift)
|
||||||
)
|
)
|
||||||
@ -35,8 +40,8 @@ void VerticalBarChart::paintChart(QPainter *painter, QRectF chartRect)
|
|||||||
paintSerialLines(
|
paintSerialLines(
|
||||||
painter,
|
painter,
|
||||||
chartRect.adjusted(
|
chartRect.adjusted(
|
||||||
hPadding(chartRect) * 2 + valuesHMargin(painter),
|
hPadding(chartRect) * 2 + valuesHMargin,
|
||||||
vPadding(chartRect) + valuesVMargin(painter),
|
vPadding(chartRect) + valuesVMargin,
|
||||||
-hPadding(chartRect) * 2,
|
-hPadding(chartRect) * 2,
|
||||||
-(vPadding(chartRect) + barsShift)
|
-(vPadding(chartRect) + barsShift)
|
||||||
)
|
)
|
||||||
|
@ -516,26 +516,29 @@ AbstractSeriesChart::AbstractSeriesChart(ChartItem *chartItem)
|
|||||||
|
|
||||||
qreal AbstractSeriesChart::maxValue()
|
qreal AbstractSeriesChart::maxValue()
|
||||||
{
|
{
|
||||||
if (m_chartItem->itemMode() == DesignMode) return 40;
|
return m_maxValue;
|
||||||
qreal maxValue = 0;
|
|
||||||
foreach(SeriesItem* series, m_chartItem->series()){
|
|
||||||
foreach(qreal value, series->data()->values()){
|
|
||||||
if (value>maxValue) maxValue=value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return maxValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal AbstractSeriesChart::minValue()
|
qreal AbstractSeriesChart::minValue()
|
||||||
{
|
{
|
||||||
if (m_chartItem->itemMode() == DesignMode) return 0;
|
return m_minValue;
|
||||||
qreal minValue = 0;
|
}
|
||||||
|
|
||||||
|
void AbstractSeriesChart::updateMinAndMaxValues()
|
||||||
|
{
|
||||||
|
if (m_chartItem->itemMode() == DesignMode) {
|
||||||
|
m_maxValue = 40;
|
||||||
|
m_minValue = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_minValue = 0;
|
||||||
|
m_maxValue = 0;
|
||||||
foreach(SeriesItem* series, m_chartItem->series()){
|
foreach(SeriesItem* series, m_chartItem->series()){
|
||||||
foreach(qreal value, series->data()->values()){
|
foreach(qreal value, series->data()->values()){
|
||||||
if (value<minValue) minValue=value;
|
if (value<m_minValue) m_minValue=value;
|
||||||
|
if (value>m_maxValue) m_maxValue=value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return minValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal AbstractSeriesChart::hPadding(QRectF chartRect)
|
qreal AbstractSeriesChart::hPadding(QRectF chartRect)
|
||||||
@ -679,11 +682,13 @@ void AbstractSeriesChart::paintVerticalGrid(QPainter *painter, QRectF gridRect)
|
|||||||
painter->setRenderHint(QPainter::Antialiasing,false);
|
painter->setRenderHint(QPainter::Antialiasing,false);
|
||||||
qreal vStep = gridRect.height() / 4;
|
qreal vStep = gridRect.height() / 4;
|
||||||
|
|
||||||
|
const qreal valuesHMargin = this->valuesHMargin(painter);
|
||||||
|
|
||||||
for (int i=0;i<5;i++){
|
for (int i=0;i<5;i++){
|
||||||
painter->drawText(QRectF(gridRect.bottomLeft()-QPointF(0,vStep*i+painter->fontMetrics().height()),
|
painter->drawText(QRectF(gridRect.bottomLeft()-QPointF(0,vStep*i+painter->fontMetrics().height()),
|
||||||
QSizeF(valuesHMargin(painter),painter->fontMetrics().height())),
|
QSizeF(valuesHMargin,painter->fontMetrics().height())),
|
||||||
QString::number(minValue()+i*delta/4));
|
QString::number(minValue()+i*delta/4));
|
||||||
painter->drawLine(gridRect.bottomLeft()-QPointF(-valuesHMargin(painter),vStep*i),
|
painter->drawLine(gridRect.bottomLeft()-QPointF(-valuesHMargin,vStep*i),
|
||||||
gridRect.bottomRight()-QPointF(0,vStep*i));
|
gridRect.bottomRight()-QPointF(0,vStep*i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
qreal maxValue();
|
qreal maxValue();
|
||||||
qreal minValue();
|
qreal minValue();
|
||||||
|
void updateMinAndMaxValues();
|
||||||
int valuesCount();
|
int valuesCount();
|
||||||
int seriesCount();
|
int seriesCount();
|
||||||
bool verticalLabels(QPainter* painter, QRectF labelsRect);
|
bool verticalLabels(QPainter* painter, QRectF labelsRect);
|
||||||
@ -103,6 +104,7 @@ protected:
|
|||||||
virtual QFont adaptValuesFont(qreal width, QFont font);
|
virtual QFont adaptValuesFont(qreal width, QFont font);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
qreal m_minValue = 0, m_maxValue = 0;
|
||||||
qreal m_designValues [9];
|
qreal m_designValues [9];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user