mirror of
https://github.com/fralx/LimeReport.git
synced 2025-11-25 00:18:06 +03:00
Define code style and format all source file using clang-format-14
except those placed in 3rdparty directories.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "lrgridlineschart.h"
|
||||
|
||||
namespace LimeReport {
|
||||
void GridLinesChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||
void GridLinesChart::paintChart(QPainter* painter, QRectF chartRect)
|
||||
{
|
||||
updateMinAndMaxValues();
|
||||
|
||||
@@ -10,22 +10,18 @@ void GridLinesChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||
|
||||
const qreal valuesVMargin = this->valuesVMargin(painter);
|
||||
|
||||
QRectF gridRect = chartRect.adjusted(
|
||||
hPadding,
|
||||
vPadding + valuesVMargin * 2,
|
||||
-hPadding * 3,
|
||||
-vPadding * 3
|
||||
);
|
||||
QRectF gridRect
|
||||
= chartRect.adjusted(hPadding, vPadding + valuesVMargin * 2, -hPadding * 3, -vPadding * 3);
|
||||
|
||||
if (!m_chartItem->horizontalAxisOnTop()) {
|
||||
// If horizontal axis is on the bottom, move grid a little up
|
||||
gridRect.adjust(0, -valuesVMargin, 0 , -valuesVMargin);
|
||||
gridRect.adjust(0, -valuesVMargin, 0, -valuesVMargin);
|
||||
}
|
||||
|
||||
// Adapt font for horizontal axis
|
||||
painter->setFont(adaptFont((gridRect.width() - this->valuesHMargin(painter)) / xAxisData().segmentCount() * 0.8,
|
||||
painter->font(),
|
||||
xAxisData()));
|
||||
painter->setFont(adaptFont((gridRect.width() - this->valuesHMargin(painter))
|
||||
/ xAxisData().segmentCount() * 0.8,
|
||||
painter->font(), xAxisData()));
|
||||
|
||||
const qreal valuesHMargin = this->valuesHMargin(painter);
|
||||
|
||||
@@ -34,23 +30,21 @@ void GridLinesChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||
|
||||
paintGrid(painter, gridRect);
|
||||
|
||||
paintSerialLines(
|
||||
painter,
|
||||
gridRect.adjusted(hPadding + valuesHMargin, 0, 0, 0)
|
||||
);
|
||||
paintSerialLines(painter, gridRect.adjusted(hPadding + valuesHMargin, 0, 0, 0));
|
||||
}
|
||||
|
||||
void GridLinesChart::paintSerialLines(QPainter* painter, QRectF barsRect)
|
||||
{
|
||||
if (valuesCount() == 0) return;
|
||||
if (valuesCount() == 0)
|
||||
return;
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing,true);
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
|
||||
const AxisData &yAxisData = this->yAxisData();
|
||||
const AxisData& yAxisData = this->yAxisData();
|
||||
const qreal delta = yAxisData.delta();
|
||||
|
||||
if (m_chartItem->itemMode() == DesignMode){
|
||||
if (m_chartItem->itemMode() == DesignMode) {
|
||||
const qreal hStep = barsRect.width() / valuesCount();
|
||||
const qreal vStep = barsRect.height() / delta;
|
||||
const qreal topShift = (delta - (maxValue() - minValue())) * vStep + barsRect.top();
|
||||
@@ -59,7 +53,7 @@ void GridLinesChart::paintSerialLines(QPainter* painter, QRectF barsRect)
|
||||
return;
|
||||
}
|
||||
|
||||
const AxisData &xAxisData = this->xAxisData();
|
||||
const AxisData& xAxisData = this->xAxisData();
|
||||
const qreal hStep = barsRect.width() / (xAxisData.rangeMax() - xAxisData.rangeMin());
|
||||
|
||||
qreal leftMargin = 0;
|
||||
@@ -70,8 +64,8 @@ void GridLinesChart::paintSerialLines(QPainter* painter, QRectF barsRect)
|
||||
pen.setWidth(m_chartItem->seriesLineWidth());
|
||||
painter->setPen(pen);
|
||||
|
||||
const QList<qreal> &xAxisValues = series->data()->xAxisValues();
|
||||
const QList<qreal> &values = series->data()->values();
|
||||
const QList<qreal>& xAxisValues = series->data()->xAxisValues();
|
||||
const QList<qreal>& values = series->data()->values();
|
||||
const int xAxisValuesSize = xAxisValues.size();
|
||||
qreal lastXPos = 0;
|
||||
qreal lastYPos = 0;
|
||||
@@ -85,16 +79,16 @@ void GridLinesChart::paintSerialLines(QPainter* painter, QRectF barsRect)
|
||||
leftMargin = barsRect.left();
|
||||
lastXPos = calculatePos(xAxisData, xAxisValues.first(), barsRect.width());
|
||||
}
|
||||
for (int i = 0; i < values.count() - 1; ++i ) {
|
||||
for (int i = 0; i < values.count() - 1; ++i) {
|
||||
const qreal startY = lastYPos;
|
||||
const qreal endY = calculatePos(yAxisData, values.at(i+1), barsRect.height());
|
||||
const qreal endY = calculatePos(yAxisData, values.at(i + 1), barsRect.height());
|
||||
// Record last used Y position to only calculate new one
|
||||
lastYPos = endY;
|
||||
|
||||
qreal startX = lastXPos;
|
||||
qreal endX = 0;
|
||||
if (i + 1 < xAxisValuesSize) {
|
||||
endX = calculatePos(xAxisData, xAxisValues.at(i+1), barsRect.width());
|
||||
endX = calculatePos(xAxisData, xAxisValues.at(i + 1), barsRect.width());
|
||||
} else {
|
||||
endX = startX + hStep;
|
||||
}
|
||||
@@ -109,4 +103,4 @@ void GridLinesChart::paintSerialLines(QPainter* painter, QRectF barsRect)
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
}
|
||||
} // namespace LimeReport
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
#include "lrlineschart.h"
|
||||
|
||||
namespace LimeReport {
|
||||
class GridLinesChart : public LinesChart{
|
||||
class GridLinesChart: public LinesChart {
|
||||
public:
|
||||
GridLinesChart(ChartItem* chartItem):LinesChart(chartItem){}
|
||||
void paintChart(QPainter *painter, QRectF chartRect);
|
||||
GridLinesChart(ChartItem* chartItem): LinesChart(chartItem) { }
|
||||
void paintChart(QPainter* painter, QRectF chartRect);
|
||||
|
||||
private:
|
||||
void paintSerialLines(QPainter *painter, QRectF barsRect);
|
||||
void paintSerialLines(QPainter* painter, QRectF barsRect);
|
||||
};
|
||||
}
|
||||
} // namespace LimeReport
|
||||
|
||||
#endif // GRIDLINESCHART_H
|
||||
|
||||
@@ -1,52 +1,49 @@
|
||||
#include "lrhorizontalbarchart.h"
|
||||
|
||||
namespace LimeReport{
|
||||
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(
|
||||
hPadding(chartRect),
|
||||
vPadding(chartRect) * 2,
|
||||
-(chartRect.width() * 0.9),
|
||||
-(vPadding(chartRect) * 2 + valuesVMargin)
|
||||
));
|
||||
QRectF calcRect = verticalLabelsRect(
|
||||
painter,
|
||||
chartRect.adjusted(hPadding(chartRect), vPadding(chartRect) * 2, -(chartRect.width() * 0.9),
|
||||
-(vPadding(chartRect) * 2 + valuesVMargin)));
|
||||
|
||||
qreal barsShift = calcRect.width();
|
||||
|
||||
paintHorizontalGrid(painter, chartRect.adjusted(
|
||||
hPadding(chartRect) + barsShift,
|
||||
vPadding(chartRect),
|
||||
-(hPadding(chartRect)),
|
||||
-vPadding(chartRect)));
|
||||
paintHorizontalGrid(painter,
|
||||
chartRect.adjusted(hPadding(chartRect) + barsShift, vPadding(chartRect),
|
||||
-(hPadding(chartRect)), -vPadding(chartRect)));
|
||||
|
||||
paintHorizontalBars(painter, chartRect.adjusted(
|
||||
hPadding(chartRect) + barsShift,
|
||||
vPadding(chartRect) * 2,
|
||||
-(hPadding(chartRect)),
|
||||
-(vPadding(chartRect) * 2) ));
|
||||
paintHorizontalBars(painter,
|
||||
chartRect.adjusted(hPadding(chartRect) + barsShift, vPadding(chartRect) * 2,
|
||||
-(hPadding(chartRect)), -(vPadding(chartRect) * 2)));
|
||||
|
||||
paintVerticalLabels(painter, calcRect);
|
||||
}
|
||||
|
||||
void HorizontalBarChart::paintHorizontalBars(QPainter *painter, QRectF barsRect)
|
||||
void HorizontalBarChart::paintHorizontalBars(QPainter* painter, QRectF barsRect)
|
||||
{
|
||||
if (seriesCount() == 0) return;
|
||||
if (seriesCount() == 0)
|
||||
return;
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing,false);
|
||||
painter->setRenderHint(QPainter::Antialiasing, false);
|
||||
|
||||
const AxisData &yAxisData = this->yAxisData();
|
||||
const AxisData& yAxisData = this->yAxisData();
|
||||
const qreal delta = yAxisData.delta();
|
||||
|
||||
const qreal verticalOffset = painter->fontMetrics().height();
|
||||
qreal vStep = (barsRect.height() - verticalOffset) / valuesCount() / seriesCount();
|
||||
qreal hStep = (barsRect.width()-painter->fontMetrics().boundingRect(QString::number(maxValue())).width()) / delta;
|
||||
qreal hStep = (barsRect.width()
|
||||
- painter->fontMetrics().boundingRect(QString::number(maxValue())).width())
|
||||
/ delta;
|
||||
|
||||
if (!m_chartItem->series().isEmpty() && (m_chartItem->itemMode() != DesignMode)){
|
||||
if (!m_chartItem->series().isEmpty() && (m_chartItem->itemMode() != DesignMode)) {
|
||||
qreal curVOffset = barsRect.top();
|
||||
if (m_chartItem->horizontalAxisOnTop()) {
|
||||
curVOffset += verticalOffset;
|
||||
@@ -55,8 +52,9 @@ void HorizontalBarChart::paintHorizontalBars(QPainter *painter, QRectF barsRect)
|
||||
painter->setBrush(series->color());
|
||||
qreal y = curVOffset;
|
||||
foreach (qreal value, series->data()->values()) {
|
||||
painter->drawRect(QRectF((-minValue()*hStep)+barsRect.left(), y, value*hStep, vStep));
|
||||
y+=vStep*seriesCount();
|
||||
painter->drawRect(
|
||||
QRectF((-minValue() * hStep) + barsRect.left(), y, value * hStep, vStep));
|
||||
y += vStep * seriesCount();
|
||||
}
|
||||
curVOffset += vStep;
|
||||
}
|
||||
@@ -66,15 +64,17 @@ void HorizontalBarChart::paintHorizontalBars(QPainter *painter, QRectF barsRect)
|
||||
curVOffset += verticalOffset;
|
||||
}
|
||||
int curColor = 0;
|
||||
for (int i=0; i<9; ++i){
|
||||
if (curColor==3) curColor=0;
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
if (curColor == 3)
|
||||
curColor = 0;
|
||||
painter->setBrush(color_map[curColor]);
|
||||
painter->drawRect(QRectF(barsRect.left(), curVOffset, designValues()[i]*hStep, vStep));
|
||||
curVOffset+=vStep;
|
||||
painter->drawRect(
|
||||
QRectF(barsRect.left(), curVOffset, designValues()[i] * hStep, vStep));
|
||||
curVOffset += vStep;
|
||||
curColor++;
|
||||
}
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LimeReport
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
#include "lrchartitem.h"
|
||||
|
||||
namespace LimeReport{
|
||||
namespace LimeReport {
|
||||
|
||||
class HorizontalBarChart: public AbstractBarChart{
|
||||
class HorizontalBarChart: public AbstractBarChart {
|
||||
public:
|
||||
HorizontalBarChart(ChartItem* chartItem):AbstractBarChart(chartItem){}
|
||||
void paintChart(QPainter *painter, QRectF chartRect);
|
||||
void paintHorizontalBars(QPainter *painter, QRectF barsRect);
|
||||
HorizontalBarChart(ChartItem* chartItem): AbstractBarChart(chartItem) { }
|
||||
void paintChart(QPainter* painter, QRectF chartRect);
|
||||
void paintHorizontalBars(QPainter* painter, QRectF barsRect);
|
||||
};
|
||||
|
||||
} // namespace LimeReport
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace LimeReport {
|
||||
|
||||
void LinesChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||
void LinesChart::paintChart(QPainter* painter, QRectF chartRect)
|
||||
{
|
||||
updateMinAndMaxValues();
|
||||
|
||||
@@ -11,64 +11,47 @@ void LinesChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||
|
||||
QRectF calcRect = horizontalLabelsRect(
|
||||
painter,
|
||||
chartRect.adjusted(
|
||||
hPadding(chartRect) * 2 + valuesHMargin,
|
||||
chartRect.height() - (painter->fontMetrics().height() + vPadding(chartRect)*2),
|
||||
-(hPadding(chartRect) * 2),
|
||||
-vPadding(chartRect)
|
||||
)
|
||||
);
|
||||
chartRect.adjusted(hPadding(chartRect) * 2 + valuesHMargin,
|
||||
chartRect.height()
|
||||
- (painter->fontMetrics().height() + vPadding(chartRect) * 2),
|
||||
-(hPadding(chartRect) * 2), -vPadding(chartRect)));
|
||||
qreal barsShift = calcRect.height();
|
||||
paintVerticalGrid(
|
||||
painter,
|
||||
chartRect.adjusted(
|
||||
hPadding(chartRect),
|
||||
vPadding(chartRect) + valuesVMargin,
|
||||
-hPadding(chartRect),
|
||||
-(vPadding(chartRect) + barsShift)
|
||||
)
|
||||
);
|
||||
paintSerialLines(
|
||||
painter,
|
||||
chartRect.adjusted(
|
||||
hPadding(chartRect) * 2 + valuesHMargin,
|
||||
vPadding(chartRect) + valuesVMargin,
|
||||
-(hPadding(chartRect) * 2),
|
||||
-(vPadding(chartRect)+barsShift)
|
||||
)
|
||||
);
|
||||
paintVerticalGrid(painter,
|
||||
chartRect.adjusted(hPadding(chartRect), vPadding(chartRect) + valuesVMargin,
|
||||
-hPadding(chartRect), -(vPadding(chartRect) + barsShift)));
|
||||
paintSerialLines(painter,
|
||||
chartRect.adjusted(hPadding(chartRect) * 2 + valuesHMargin,
|
||||
vPadding(chartRect) + valuesVMargin,
|
||||
-(hPadding(chartRect) * 2),
|
||||
-(vPadding(chartRect) + barsShift)));
|
||||
paintHorizontalLabels(painter, calcRect);
|
||||
}
|
||||
|
||||
void LinesChart::drawDesignMode(QPainter* painter, qreal hStep, qreal vStep, qreal topShift, QRectF barsRect){
|
||||
for (int i = 0; i < valuesCount()-1; ++i){
|
||||
QPoint startPoint = QPoint((i+1) * hStep + barsRect.left() - hStep/2,
|
||||
(maxValue() * vStep+topShift) - designValues()[i] * vStep
|
||||
);
|
||||
QPoint endPoint = QPoint((i+2) * hStep + barsRect.left() - hStep/2,
|
||||
(maxValue() * vStep+topShift) - designValues()[i+1] * vStep
|
||||
);
|
||||
void LinesChart::drawDesignMode(QPainter* painter, qreal hStep, qreal vStep, qreal topShift,
|
||||
QRectF barsRect)
|
||||
{
|
||||
for (int i = 0; i < valuesCount() - 1; ++i) {
|
||||
QPoint startPoint = QPoint((i + 1) * hStep + barsRect.left() - hStep / 2,
|
||||
(maxValue() * vStep + topShift) - designValues()[i] * vStep);
|
||||
QPoint endPoint = QPoint((i + 2) * hStep + barsRect.left() - hStep / 2,
|
||||
(maxValue() * vStep + topShift) - designValues()[i + 1] * vStep);
|
||||
drawSegment(painter, startPoint, endPoint, color_map[0]);
|
||||
|
||||
startPoint = QPoint((i+1) * hStep + barsRect.left() - hStep/2,
|
||||
(maxValue() * vStep+topShift) - designValues()[i+3] * vStep
|
||||
);
|
||||
endPoint = QPoint((i+2) * hStep + barsRect.left() - hStep/2,
|
||||
(maxValue() * vStep+topShift) - designValues()[i+3+1] * vStep
|
||||
);
|
||||
startPoint = QPoint((i + 1) * hStep + barsRect.left() - hStep / 2,
|
||||
(maxValue() * vStep + topShift) - designValues()[i + 3] * vStep);
|
||||
endPoint = QPoint((i + 2) * hStep + barsRect.left() - hStep / 2,
|
||||
(maxValue() * vStep + topShift) - designValues()[i + 3 + 1] * vStep);
|
||||
drawSegment(painter, startPoint, endPoint, color_map[1]);
|
||||
|
||||
startPoint = QPoint((i+1) * hStep + barsRect.left() - hStep/2,
|
||||
(maxValue() * vStep+topShift) - designValues()[i+6] * vStep
|
||||
);
|
||||
endPoint = QPoint((i+2) * hStep + barsRect.left() - hStep/2,
|
||||
(maxValue() * vStep+topShift) - designValues()[i+6+1] * vStep
|
||||
);
|
||||
startPoint = QPoint((i + 1) * hStep + barsRect.left() - hStep / 2,
|
||||
(maxValue() * vStep + topShift) - designValues()[i + 6] * vStep);
|
||||
endPoint = QPoint((i + 2) * hStep + barsRect.left() - hStep / 2,
|
||||
(maxValue() * vStep + topShift) - designValues()[i + 6 + 1] * vStep);
|
||||
drawSegment(painter, startPoint, endPoint, color_map[2]);
|
||||
}
|
||||
}
|
||||
|
||||
qreal LinesChart::calculatePos(const AxisData &data, qreal value, qreal rectSize) const
|
||||
qreal LinesChart::calculatePos(const AxisData& data, qreal value, qreal rectSize) const
|
||||
{
|
||||
if (data.type() == AxisData::XAxis || (data.reverseDirection() && data.rangeMin() >= 0)) {
|
||||
// Not flipping for minimum less than 0 because lower number is at the bottom.
|
||||
@@ -78,10 +61,10 @@ qreal LinesChart::calculatePos(const AxisData &data, qreal value, qreal rectSize
|
||||
}
|
||||
}
|
||||
|
||||
void LinesChart::paintSeries(QPainter *painter, SeriesItem *series, QRectF barsRect)
|
||||
void LinesChart::paintSeries(QPainter* painter, SeriesItem* series, QRectF barsRect)
|
||||
{
|
||||
const AxisData &yAxisData = this->yAxisData();
|
||||
const AxisData &xAxisData = this->xAxisData();
|
||||
const AxisData& yAxisData = this->yAxisData();
|
||||
const AxisData& xAxisData = this->xAxisData();
|
||||
|
||||
const qreal xAxisDiff = std::max(1.0, xAxisData.maxValue() - xAxisData.minValue());
|
||||
const qreal hStep = barsRect.width() / xAxisDiff;
|
||||
@@ -91,17 +74,17 @@ void LinesChart::paintSeries(QPainter *painter, SeriesItem *series, QRectF barsR
|
||||
pen.setWidth(4);
|
||||
painter->setPen(pen);
|
||||
|
||||
const QList<qreal> &values = series->data()->values();
|
||||
const QList<qreal>& values = series->data()->values();
|
||||
|
||||
qreal lastYValue = 0;
|
||||
qreal lastXValue = barsRect.left() + hStep/2;
|
||||
qreal lastXValue = barsRect.left() + hStep / 2;
|
||||
if (!values.isEmpty()) {
|
||||
// Calculate first point position on plot before loop
|
||||
lastYValue = calculatePos(yAxisData, values.first(), barsRect.height());
|
||||
}
|
||||
for (int i = 0; i < values.count()-1; ++i ){
|
||||
for (int i = 0; i < values.count() - 1; ++i) {
|
||||
const qreal startY = lastYValue;
|
||||
const qreal endY = calculatePos(yAxisData, values.at(i+1), barsRect.height());
|
||||
const qreal endY = calculatePos(yAxisData, values.at(i + 1), barsRect.height());
|
||||
// Record last used Y position to only calculate new one
|
||||
lastYValue = endY;
|
||||
|
||||
@@ -118,13 +101,14 @@ void LinesChart::paintSeries(QPainter *painter, SeriesItem *series, QRectF barsR
|
||||
|
||||
void LinesChart::paintSerialLines(QPainter* painter, QRectF barsRect)
|
||||
{
|
||||
if (valuesCount() == 0) return;
|
||||
if (valuesCount() == 0)
|
||||
return;
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing,true);
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
|
||||
if (m_chartItem->itemMode() == DesignMode){
|
||||
const AxisData &yAxisData = this->yAxisData();
|
||||
if (m_chartItem->itemMode() == DesignMode) {
|
||||
const AxisData& yAxisData = this->yAxisData();
|
||||
const qreal delta = yAxisData.delta();
|
||||
const qreal hStep = barsRect.width() / valuesCount();
|
||||
const qreal vStep = barsRect.height() / delta;
|
||||
@@ -134,12 +118,11 @@ void LinesChart::paintSerialLines(QPainter* painter, QRectF barsRect)
|
||||
return;
|
||||
}
|
||||
|
||||
for (SeriesItem *series : m_chartItem->series()) {
|
||||
for (SeriesItem* series : m_chartItem->series()) {
|
||||
paintSeries(painter, series, barsRect);
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
} //namespace LimeReport
|
||||
|
||||
} // namespace LimeReport
|
||||
|
||||
@@ -4,18 +4,20 @@
|
||||
#include "lrchartitem.h"
|
||||
|
||||
namespace LimeReport {
|
||||
class LinesChart: public AbstractBarChart{
|
||||
class LinesChart: public AbstractBarChart {
|
||||
public:
|
||||
LinesChart(ChartItem* chartItem):AbstractBarChart(chartItem){}
|
||||
void paintChart(QPainter *painter, QRectF chartRect);
|
||||
LinesChart(ChartItem* chartItem): AbstractBarChart(chartItem) { }
|
||||
void paintChart(QPainter* painter, QRectF chartRect);
|
||||
|
||||
protected:
|
||||
void drawDesignMode(QPainter *painter, qreal hStep, qreal vStep, qreal topShift, QRectF barsRect);
|
||||
qreal calculatePos(const AxisData &data, qreal value, qreal rectSize) const;
|
||||
void paintSeries(QPainter *painter, SeriesItem *series, QRectF barsRect);
|
||||
void drawDesignMode(QPainter* painter, qreal hStep, qreal vStep, qreal topShift,
|
||||
QRectF barsRect);
|
||||
qreal calculatePos(const AxisData& data, qreal value, qreal rectSize) const;
|
||||
void paintSeries(QPainter* painter, SeriesItem* series, QRectF barsRect);
|
||||
|
||||
private:
|
||||
void paintSerialLines(QPainter *painter, QRectF barsRect);
|
||||
void paintSerialLines(QPainter* painter, QRectF barsRect);
|
||||
};
|
||||
}
|
||||
} // namespace LimeReport
|
||||
|
||||
#endif // LINESCHART_H
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
#include "lrpiechart.h"
|
||||
|
||||
namespace LimeReport{
|
||||
namespace LimeReport {
|
||||
|
||||
void PieChart::drawPercent(QPainter *painter, QRectF chartRect, qreal startAngle, qreal angle)
|
||||
void PieChart::drawPercent(QPainter* painter, QRectF chartRect, qreal startAngle, qreal angle)
|
||||
{
|
||||
painter->save();
|
||||
|
||||
QPointF center(chartRect.left()+chartRect.width()/2,chartRect.top()+chartRect.height()/2);
|
||||
qreal percent = angle/3.6;
|
||||
QPointF center(chartRect.left() + chartRect.width() / 2,
|
||||
chartRect.top() + chartRect.height() / 2);
|
||||
qreal percent = angle / 3.6;
|
||||
#if QT_VERSION < 0x050000
|
||||
qreal radAngle = (angle/2+startAngle)*(M_PI/180);
|
||||
qreal radAngle = (angle / 2 + startAngle) * (M_PI / 180);
|
||||
#else
|
||||
qreal radAngle = qDegreesToRadians(angle/2+startAngle);
|
||||
qreal radAngle = qDegreesToRadians(angle / 2 + startAngle);
|
||||
#endif
|
||||
qreal radius = painter->fontMetrics().boundingRect("99,9%").width();
|
||||
qreal border = chartRect.height()*0.02;
|
||||
qreal length = (chartRect.height())/2-(radius/2+border);
|
||||
qreal x,y;
|
||||
x = length*qCos(radAngle);
|
||||
y = length*qSin(radAngle);
|
||||
QPointF endPoint(center.x()+x,center.y()-y);
|
||||
qreal border = chartRect.height() * 0.02;
|
||||
qreal length = (chartRect.height()) / 2 - (radius / 2 + border);
|
||||
qreal x, y;
|
||||
x = length * qCos(radAngle);
|
||||
y = length * qSin(radAngle);
|
||||
QPointF endPoint(center.x() + x, center.y() - y);
|
||||
painter->setPen(Qt::white);
|
||||
QRectF textRect(endPoint.x()-(radius/2),endPoint.y()-(radius/2),radius,radius);
|
||||
QRectF textRect(endPoint.x() - (radius / 2), endPoint.y() - (radius / 2), radius, radius);
|
||||
|
||||
qreal arcLength = 3.14 * length * angle / 180;
|
||||
if (arcLength >= radius)
|
||||
painter->drawText(textRect,Qt::AlignCenter,QString::number(percent,'f',1)+"%");
|
||||
painter->drawText(textRect, Qt::AlignCenter, QString::number(percent, 'f', 1) + "%");
|
||||
painter->restore();
|
||||
|
||||
}
|
||||
|
||||
void PieChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||
void PieChart::paintChart(QPainter* painter, QRectF chartRect)
|
||||
{
|
||||
painter->save();
|
||||
QPen pen(Qt::white);
|
||||
@@ -42,10 +42,10 @@ void PieChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||
painter->setBackground(QBrush(Qt::NoBrush));
|
||||
|
||||
QRectF tmpRect = chartRect;
|
||||
if (chartRect.height()>chartRect.width()){
|
||||
if (chartRect.height() > chartRect.width()) {
|
||||
tmpRect.setHeight(chartRect.width());
|
||||
tmpRect.adjust(0,(chartRect.bottom()-tmpRect.bottom())/2,
|
||||
0,(chartRect.bottom()-tmpRect.bottom())/2);
|
||||
tmpRect.adjust(0, (chartRect.bottom() - tmpRect.bottom()) / 2, 0,
|
||||
(chartRect.bottom() - tmpRect.bottom()) / 2);
|
||||
} else {
|
||||
tmpRect.setWidth(chartRect.height());
|
||||
}
|
||||
@@ -53,31 +53,32 @@ void PieChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||
chartRect = tmpRect;
|
||||
painter->drawRect(chartRect);
|
||||
|
||||
if (!m_chartItem->series().isEmpty()&&!m_chartItem->series().at(0)->data()->values().isEmpty()){
|
||||
if (!m_chartItem->series().isEmpty()
|
||||
&& !m_chartItem->series().at(0)->data()->values().isEmpty()) {
|
||||
SeriesItem* si = m_chartItem->series().at(0);
|
||||
qreal sum = 0;
|
||||
foreach(qreal value, si->data()->values()){
|
||||
sum+=value;
|
||||
foreach (qreal value, si->data()->values()) {
|
||||
sum += value;
|
||||
}
|
||||
qreal onePercent = sum / 100;
|
||||
qreal currentDegree = 0;
|
||||
for(int i=0; i<si->data()->values().count(); ++i){
|
||||
for (int i = 0; i < si->data()->values().count(); ++i) {
|
||||
qreal value = si->data()->values().at(i);
|
||||
qreal sectorDegree = (value/onePercent)*3.6;
|
||||
qreal sectorDegree = (value / onePercent) * 3.6;
|
||||
painter->setBrush(si->data()->colors().at(i));
|
||||
painter->drawPie(chartRect,currentDegree*16,sectorDegree*16);
|
||||
painter->drawPie(chartRect, currentDegree * 16, sectorDegree * 16);
|
||||
drawPercent(painter, chartRect, currentDegree, sectorDegree);
|
||||
currentDegree += sectorDegree;
|
||||
}
|
||||
} else if (m_chartItem->itemMode() == DesignMode){
|
||||
} else if (m_chartItem->itemMode() == DesignMode) {
|
||||
painter->setBrush(color_map[0]);
|
||||
painter->drawPie(chartRect,0,260*16);
|
||||
painter->drawPie(chartRect, 0, 260 * 16);
|
||||
drawPercent(painter, chartRect, 0, 260);
|
||||
painter->setBrush(color_map[1]);
|
||||
painter->drawPie(chartRect,260*16,40*16);
|
||||
painter->drawPie(chartRect, 260 * 16, 40 * 16);
|
||||
drawPercent(painter, chartRect, 260, 40);
|
||||
painter->setBrush(color_map[2]);
|
||||
painter->drawPie(chartRect,300*16,60*16);
|
||||
painter->drawPie(chartRect, 300 * 16, 60 * 16);
|
||||
drawPercent(painter, chartRect, 300, 60);
|
||||
}
|
||||
|
||||
@@ -89,83 +90,77 @@ void PieChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void PieChart::paintChartLegend(QPainter *painter, QRectF legendRect)
|
||||
void PieChart::paintChartLegend(QPainter* painter, QRectF legendRect)
|
||||
{
|
||||
prepareLegendToPaint(legendRect, painter);
|
||||
|
||||
int indicatorSize = painter->fontMetrics().height()/2;
|
||||
painter->setRenderHint(QPainter::Antialiasing,false);
|
||||
int indicatorSize = painter->fontMetrics().height() / 2;
|
||||
painter->setRenderHint(QPainter::Antialiasing, false);
|
||||
|
||||
if (m_chartItem->drawLegendBorder())
|
||||
painter->drawRect(legendRect);
|
||||
|
||||
painter->setRenderHint(QPainter::Antialiasing,true);
|
||||
QRectF indicatorsRect = legendRect.adjusted(painter->fontMetrics().height()/2,painter->fontMetrics().height()/2,0,0);
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
QRectF indicatorsRect = legendRect.adjusted(painter->fontMetrics().height() / 2,
|
||||
painter->fontMetrics().height() / 2, 0, 0);
|
||||
|
||||
if (!m_chartItem->series().isEmpty() && !m_chartItem->series().at(0)->data()->labels().isEmpty()){
|
||||
if (!m_chartItem->series().isEmpty()
|
||||
&& !m_chartItem->series().at(0)->data()->labels().isEmpty()) {
|
||||
qreal cw = 0;
|
||||
SeriesItem* si = m_chartItem->series().at(0);
|
||||
for (int i=0;i<si->data()->labels().count();++i){
|
||||
for (int i = 0; i < si->data()->labels().count(); ++i) {
|
||||
QString label = si->data()->labels().at(i);
|
||||
painter->setPen(Qt::black);
|
||||
painter->drawText(indicatorsRect.adjusted(indicatorSize+indicatorSize/2,cw,0,0),label);
|
||||
painter->drawText(indicatorsRect.adjusted(indicatorSize + indicatorSize / 2, cw, 0, 0),
|
||||
label);
|
||||
painter->setPen(si->data()->colors().at(i));
|
||||
painter->setBrush(si->data()->colors().at(i));
|
||||
painter->drawEllipse(
|
||||
indicatorsRect.adjusted(
|
||||
0,
|
||||
cw+indicatorSize/2,
|
||||
-(indicatorsRect.width()-indicatorSize),
|
||||
-(indicatorsRect.height()-(cw+indicatorSize+indicatorSize/2))
|
||||
)
|
||||
);
|
||||
painter->drawEllipse(indicatorsRect.adjusted(
|
||||
0, cw + indicatorSize / 2, -(indicatorsRect.width() - indicatorSize),
|
||||
-(indicatorsRect.height() - (cw + indicatorSize + indicatorSize / 2))));
|
||||
cw += painter->fontMetrics().height();
|
||||
}
|
||||
} else if (m_chartItem->itemMode() == DesignMode){
|
||||
} else if (m_chartItem->itemMode() == DesignMode) {
|
||||
qreal cw = 0;
|
||||
for (int i=0;i<m_designLabels.size();++i){
|
||||
for (int i = 0; i < m_designLabels.size(); ++i) {
|
||||
QString label = m_designLabels.at(i);
|
||||
painter->setPen(Qt::black);
|
||||
painter->drawText(indicatorsRect.adjusted(indicatorSize+indicatorSize/2,cw,0,0),label);
|
||||
painter->drawText(indicatorsRect.adjusted(indicatorSize + indicatorSize / 2, cw, 0, 0),
|
||||
label);
|
||||
painter->setBrush(color_map[i]);
|
||||
painter->setPen(color_map[i]);
|
||||
painter->drawEllipse(
|
||||
indicatorsRect.adjusted(
|
||||
0,
|
||||
cw+indicatorSize/2,
|
||||
-(indicatorsRect.width()-indicatorSize),
|
||||
-(indicatorsRect.height()-(cw+indicatorSize+indicatorSize/2))
|
||||
)
|
||||
);
|
||||
painter->drawEllipse(indicatorsRect.adjusted(
|
||||
0, cw + indicatorSize / 2, -(indicatorsRect.width() - indicatorSize),
|
||||
-(indicatorsRect.height() - (cw + indicatorSize + indicatorSize / 2))));
|
||||
cw += painter->fontMetrics().height();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
QSizeF PieChart::calcChartLegendSize(const QFont &font, qreal)
|
||||
QSizeF PieChart::calcChartLegendSize(const QFont& font, qreal)
|
||||
{
|
||||
QFontMetrics fm(font);
|
||||
|
||||
qreal cw = 0;
|
||||
qreal maxWidth = 0;
|
||||
|
||||
if (!m_chartItem->series().isEmpty() && !m_chartItem->series().at(0)->data()->labels().isEmpty()){
|
||||
if (!m_chartItem->series().isEmpty()
|
||||
&& !m_chartItem->series().at(0)->data()->labels().isEmpty()) {
|
||||
SeriesItem* si = m_chartItem->series().at(0);
|
||||
foreach(QString label, si->data()->labels()){
|
||||
foreach (QString label, si->data()->labels()) {
|
||||
cw += fm.height();
|
||||
if (maxWidth<fm.boundingRect(label).width())
|
||||
maxWidth = fm.boundingRect(label).width()+10;
|
||||
if (maxWidth < fm.boundingRect(label).width())
|
||||
maxWidth = fm.boundingRect(label).width() + 10;
|
||||
}
|
||||
} else {
|
||||
foreach(QString label, m_designLabels){
|
||||
foreach (QString label, m_designLabels) {
|
||||
cw += fm.height();
|
||||
if (maxWidth<fm.boundingRect(label).width())
|
||||
maxWidth = fm.boundingRect(label).width()+10;
|
||||
if (maxWidth < fm.boundingRect(label).width())
|
||||
maxWidth = fm.boundingRect(label).width() + 10;
|
||||
}
|
||||
}
|
||||
cw += fm.height();
|
||||
return QSizeF(maxWidth+fm.height()*2,cw);
|
||||
return QSizeF(maxWidth + fm.height() * 2, cw);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace LimeReport
|
||||
|
||||
@@ -3,16 +3,17 @@
|
||||
|
||||
#include "lrchartitem.h"
|
||||
|
||||
namespace LimeReport{
|
||||
namespace LimeReport {
|
||||
|
||||
class PieChart : public AbstractChart{
|
||||
class PieChart: public AbstractChart {
|
||||
public:
|
||||
PieChart(ChartItem* chartItem):AbstractChart(chartItem){}
|
||||
QSizeF calcChartLegendSize(const QFont &font, qreal maxWidth = 0);
|
||||
void paintChart(QPainter *painter, QRectF chartRect);
|
||||
void paintChartLegend(QPainter *painter, QRectF legendRect);
|
||||
PieChart(ChartItem* chartItem): AbstractChart(chartItem) { }
|
||||
QSizeF calcChartLegendSize(const QFont& font, qreal maxWidth = 0);
|
||||
void paintChart(QPainter* painter, QRectF chartRect);
|
||||
void paintChartLegend(QPainter* painter, QRectF legendRect);
|
||||
|
||||
protected:
|
||||
void drawPercent(QPainter *painter, QRectF chartRect, qreal startAngle, qreal angle);
|
||||
void drawPercent(QPainter* painter, QRectF chartRect, qreal startAngle, qreal angle);
|
||||
};
|
||||
|
||||
} // namespace LimeReport
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "lrverticalbarchart.h"
|
||||
|
||||
namespace LimeReport{
|
||||
namespace LimeReport {
|
||||
|
||||
void VerticalBarChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||
void VerticalBarChart::paintChart(QPainter* painter, QRectF chartRect)
|
||||
{
|
||||
updateMinAndMaxValues();
|
||||
|
||||
@@ -11,74 +11,61 @@ void VerticalBarChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||
|
||||
QRectF calcRect = horizontalLabelsRect(
|
||||
painter,
|
||||
chartRect.adjusted(
|
||||
hPadding(chartRect) * 2 + valuesHMargin,
|
||||
chartRect.height() - (painter->fontMetrics().height() + vPadding(chartRect) * 2),
|
||||
-(hPadding(chartRect) * 2),
|
||||
-vPadding(chartRect)
|
||||
)
|
||||
);
|
||||
chartRect.adjusted(hPadding(chartRect) * 2 + valuesHMargin,
|
||||
chartRect.height()
|
||||
- (painter->fontMetrics().height() + vPadding(chartRect) * 2),
|
||||
-(hPadding(chartRect) * 2), -vPadding(chartRect)));
|
||||
qreal barsShift = calcRect.height();
|
||||
paintVerticalGrid(
|
||||
painter,
|
||||
chartRect.adjusted(
|
||||
hPadding(chartRect),
|
||||
vPadding(chartRect) + valuesVMargin,
|
||||
-hPadding(chartRect),
|
||||
-(vPadding(chartRect) + barsShift)
|
||||
)
|
||||
);
|
||||
paintVerticalBars(
|
||||
painter,
|
||||
chartRect.adjusted(
|
||||
hPadding(chartRect) * 2 + valuesHMargin,
|
||||
vPadding(chartRect) + valuesVMargin,
|
||||
-hPadding(chartRect) * 2,
|
||||
-(vPadding(chartRect) + barsShift)
|
||||
)
|
||||
);
|
||||
paintSerialLines(
|
||||
painter,
|
||||
chartRect.adjusted(
|
||||
hPadding(chartRect) * 2 + valuesHMargin,
|
||||
vPadding(chartRect) + valuesVMargin,
|
||||
-hPadding(chartRect) * 2,
|
||||
-(vPadding(chartRect) + barsShift)
|
||||
)
|
||||
);
|
||||
paintVerticalGrid(painter,
|
||||
chartRect.adjusted(hPadding(chartRect), vPadding(chartRect) + valuesVMargin,
|
||||
-hPadding(chartRect), -(vPadding(chartRect) + barsShift)));
|
||||
paintVerticalBars(painter,
|
||||
chartRect.adjusted(hPadding(chartRect) * 2 + valuesHMargin,
|
||||
vPadding(chartRect) + valuesVMargin,
|
||||
-hPadding(chartRect) * 2,
|
||||
-(vPadding(chartRect) + barsShift)));
|
||||
paintSerialLines(painter,
|
||||
chartRect.adjusted(hPadding(chartRect) * 2 + valuesHMargin,
|
||||
vPadding(chartRect) + valuesVMargin,
|
||||
-hPadding(chartRect) * 2,
|
||||
-(vPadding(chartRect) + barsShift)));
|
||||
paintHorizontalLabels(painter, calcRect);
|
||||
}
|
||||
|
||||
void VerticalBarChart::paintVerticalBars(QPainter *painter, QRectF barsRect)
|
||||
void VerticalBarChart::paintVerticalBars(QPainter* painter, QRectF barsRect)
|
||||
{
|
||||
|
||||
if (valuesCount() == 0) return;
|
||||
if (valuesCount() == 0)
|
||||
return;
|
||||
|
||||
const AxisData &yAxisData = this->yAxisData();
|
||||
const AxisData& yAxisData = this->yAxisData();
|
||||
const qreal delta = yAxisData.delta();
|
||||
|
||||
int barSeriesCount = 0;
|
||||
foreach(SeriesItem* series, m_chartItem->series()){
|
||||
if (series->preferredType() == SeriesItem::Bar) barSeriesCount++;
|
||||
foreach (SeriesItem* series, m_chartItem->series()) {
|
||||
if (series->preferredType() == SeriesItem::Bar)
|
||||
barSeriesCount++;
|
||||
}
|
||||
|
||||
barSeriesCount = (m_chartItem->itemMode() == DesignMode) ? seriesCount() : barSeriesCount;
|
||||
if (barSeriesCount < 1) return;
|
||||
if (barSeriesCount < 1)
|
||||
return;
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing,false);
|
||||
painter->setRenderHint(QPainter::Antialiasing, false);
|
||||
|
||||
qreal vStep = barsRect.height() / delta;
|
||||
qreal hStep = (barsRect.width() / valuesCount()) / (barSeriesCount == 0 ? 1 : barSeriesCount);
|
||||
qreal topShift = (delta - (maxValue() - minValue())) * vStep + barsRect.top();
|
||||
|
||||
if (!m_chartItem->series().isEmpty() && (m_chartItem->itemMode() != DesignMode)){
|
||||
if (!m_chartItem->series().isEmpty() && (m_chartItem->itemMode() != DesignMode)) {
|
||||
int curSeries = 0;
|
||||
foreach (SeriesItem* series, m_chartItem->series()) {
|
||||
if (series->preferredType() == SeriesItem::Bar){
|
||||
if (series->preferredType() == SeriesItem::Bar) {
|
||||
qreal curHOffset = curSeries * hStep + barsRect.left();
|
||||
painter->setBrush(series->color());
|
||||
foreach (qreal value, series->data()->values()) {
|
||||
painter->drawRect(QRectF(curHOffset, maxValue() * vStep + topShift, hStep, -value * vStep));
|
||||
painter->drawRect(
|
||||
QRectF(curHOffset, maxValue() * vStep + topShift, hStep, -value * vStep));
|
||||
curHOffset += hStep * barSeriesCount;
|
||||
}
|
||||
curSeries++;
|
||||
@@ -87,10 +74,12 @@ void VerticalBarChart::paintVerticalBars(QPainter *painter, QRectF barsRect)
|
||||
} else {
|
||||
qreal curHOffset = barsRect.left();
|
||||
int curColor = 0;
|
||||
for (int i = 0; i < 9; ++i){
|
||||
if (curColor == 3) curColor = 0;
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
if (curColor == 3)
|
||||
curColor = 0;
|
||||
painter->setBrush(color_map[curColor]);
|
||||
painter->drawRect(QRectF(curHOffset, maxValue() * vStep + barsRect.top(), hStep, -designValues()[i] * vStep));
|
||||
painter->drawRect(QRectF(curHOffset, maxValue() * vStep + barsRect.top(), hStep,
|
||||
-designValues()[i] * vStep));
|
||||
curHOffset += hStep;
|
||||
curColor++;
|
||||
}
|
||||
@@ -100,13 +89,14 @@ void VerticalBarChart::paintVerticalBars(QPainter *painter, QRectF barsRect)
|
||||
|
||||
void VerticalBarChart::paintSerialLines(QPainter* painter, QRectF barsRect)
|
||||
{
|
||||
if (valuesCount() == 0 || m_chartItem->series().isEmpty() ) return;
|
||||
if (valuesCount() == 0 || m_chartItem->series().isEmpty())
|
||||
return;
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing,true);
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
|
||||
for (SeriesItem *series : m_chartItem->series()) {
|
||||
if (series->preferredType() == SeriesItem::Line){
|
||||
for (SeriesItem* series : m_chartItem->series()) {
|
||||
if (series->preferredType() == SeriesItem::Line) {
|
||||
paintSeries(painter, series, barsRect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,17 @@
|
||||
|
||||
#include "lrlineschart.h"
|
||||
|
||||
namespace LimeReport{
|
||||
namespace LimeReport {
|
||||
|
||||
class VerticalBarChart: public LinesChart{
|
||||
class VerticalBarChart: public LinesChart {
|
||||
public:
|
||||
VerticalBarChart(ChartItem* chartItem):LinesChart(chartItem){}
|
||||
void paintChart(QPainter *painter, QRectF chartRect);
|
||||
// void paintVerticalGrid(QPainter *painter, QRectF gridRect);
|
||||
void paintVerticalBars(QPainter *painter, QRectF barsRect);
|
||||
void paintSerialLines(QPainter *painter, QRectF barsRect);
|
||||
VerticalBarChart(ChartItem* chartItem): LinesChart(chartItem) { }
|
||||
void paintChart(QPainter* painter, QRectF chartRect);
|
||||
// void paintVerticalGrid(QPainter *painter, QRectF gridRect);
|
||||
void paintVerticalBars(QPainter* painter, QRectF barsRect);
|
||||
void paintSerialLines(QPainter* painter, QRectF barsRect);
|
||||
};
|
||||
|
||||
} //namespace LimeReport
|
||||
} // namespace LimeReport
|
||||
|
||||
#endif // VERTICALBARCHART_H
|
||||
|
||||
Reference in New Issue
Block a user