From c45aef0efdcb88d41becdef99f71d4e8704c0406 Mon Sep 17 00:00:00 2001 From: Emil Sawicki Date: Sun, 13 Mar 2022 22:49:39 +0100 Subject: [PATCH] Add type for axis data for corner cases --- limereport/items/charts/lrlineschart.cpp | 2 +- limereport/items/lrchartitem.cpp | 9 ++++----- limereport/lraxisdata.cpp | 10 ++++++++-- limereport/lraxisdata.h | 10 +++++++++- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/limereport/items/charts/lrlineschart.cpp b/limereport/items/charts/lrlineschart.cpp index 01da6b0..18c8692 100644 --- a/limereport/items/charts/lrlineschart.cpp +++ b/limereport/items/charts/lrlineschart.cpp @@ -70,7 +70,7 @@ void LinesChart::drawDesignMode(QPainter* painter, qreal hStep, qreal vStep, qre qreal LinesChart::calculatePos(const AxisData &data, qreal value, qreal rectSize) const { - if (data.reverseDirection() && data.rangeMin() >= 0) { + if (data.type() == AxisData::XAxis || (data.reverseDirection() && data.rangeMin() >= 0)) { // Not flipping for minimum less than 0 because lower number is at the bottom. return (1 - (data.rangeMax() - value) / data.delta()) * rectSize; } else { diff --git a/limereport/items/lrchartitem.cpp b/limereport/items/lrchartitem.cpp index 90a7c14..049942d 100644 --- a/limereport/items/lrchartitem.cpp +++ b/limereport/items/lrchartitem.cpp @@ -148,9 +148,9 @@ ChartItem::ChartItem(QObject *owner, QGraphicsItem *parent) m_horizontalAxisOnTop(false), m_gridChartLines(AllLines), m_legendStyle(LegendPoints) { - m_xAxisData = new AxisData(this); + m_xAxisData = new AxisData(AxisData::XAxis, this); m_xAxisData->setReverseDirection(true); - m_yAxisData = new AxisData(this); + m_yAxisData = new AxisData(AxisData::YAxis, this); m_labels<<"First"<<"Second"<<"Thrid"; m_chart = new PieChart(this); m_chart->setTitleFont(font()); @@ -1033,7 +1033,7 @@ void AbstractSeriesChart::paintGrid(QPainter *painter, QRectF gridRect) painter->save(); const AxisData &yAxisData = this->yAxisData(); - const AxisData &xAxisData = this->xAxisData(); + AxisData &xAxisData = this->xAxisData(); painter->setRenderHint(QPainter::Antialiasing,false); @@ -1091,7 +1091,6 @@ void AbstractSeriesChart::paintGrid(QPainter *painter, QRectF gridRect) text); } } - painter->restore(); } @@ -1178,7 +1177,7 @@ QString AbstractSeriesChart::axisLabel(int i, const AxisData &axisData) const qreal min = axisData.rangeMin(); const qreal step = axisData.step(); qreal value = 0; - if (axisData.reverseDirection() && min >= 0) { + if (axisData.type() == AxisData::YAxis && axisData.reverseDirection() && min >= 0) { value = min + (axisData.segmentCount() - i) * step; } else { value = min + i * step; diff --git a/limereport/lraxisdata.cpp b/limereport/lraxisdata.cpp index e429583..80a6cf3 100644 --- a/limereport/lraxisdata.cpp +++ b/limereport/lraxisdata.cpp @@ -4,13 +4,14 @@ #include namespace LimeReport { -AxisData::AxisData(QObject *parent) +AxisData::AxisData(AxisType type, QObject *parent) : QObject(parent), m_rangeMin(0), m_rangeMax(0), m_minValue(0), m_maxValue(0), m_step(0), m_delta(0), m_segmentCount(4), m_calculateAxisScale(false), m_reverseDirection(false), m_manualMaximum(0), m_manualMinimum(0), m_manualStep(0), m_isMaximumAutomatic(true), - m_isMinimumAutomatic(true), m_isStepAutomatic(true) + m_isMinimumAutomatic(true), m_isStepAutomatic(true), + m_type(type) { } @@ -333,4 +334,9 @@ void AxisData::setIsStepAutomatic(bool newIsStepAutomatic) m_isStepAutomatic = newIsStepAutomatic; } +AxisData::AxisType AxisData::type() const +{ + return m_type; +} + } diff --git a/limereport/lraxisdata.h b/limereport/lraxisdata.h index 66c63a1..d7342a4 100644 --- a/limereport/lraxisdata.h +++ b/limereport/lraxisdata.h @@ -16,7 +16,12 @@ class AxisData : public QObject Q_PROPERTY(qreal manualMinimum READ manualMinimum WRITE setManualMinimum) Q_PROPERTY(qreal manualMaximum READ manualMaximum WRITE setManualMaximum) public: - AxisData(QObject *parent = nullptr); + enum AxisType { + YAxis = 0, + XAxis = 1 + }; + + AxisData(AxisType type, QObject *parent = nullptr); QString toString() const; void copy(AxisData *other); @@ -58,6 +63,8 @@ public: bool isStepAutomatic() const; void setIsStepAutomatic(bool newIsStepAutomatic); + AxisType type() const; + private: void calculateRoundedAxisScale(); void calculateSimpleAxisScale(); @@ -79,6 +86,7 @@ private: bool m_isMaximumAutomatic; bool m_isMinimumAutomatic; bool m_isStepAutomatic; + const AxisType m_type; }; };