mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 00:33:02 +03:00
Add type for axis data for corner cases
This commit is contained in:
parent
e7a301c8b6
commit
c45aef0efd
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -4,13 +4,14 @@
|
||||
#include <QDebug>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user