| 1 | // Copyright (C) 2021 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QtCharts/qlogvalueaxis.h> |
| 5 | #include <QtCore/qmath.h> |
| 6 | #include <private/abstractchartlayout_p.h> |
| 7 | #include <private/chartpresenter_p.h> |
| 8 | #include <private/polarchartlogvalueaxisangular_p.h> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | PolarChartLogValueAxisAngular::PolarChartLogValueAxisAngular(QLogValueAxis *axis, |
| 13 | QGraphicsItem *item) |
| 14 | : PolarChartAxisAngular(axis, item) |
| 15 | { |
| 16 | QObject::connect(sender: axis, SIGNAL(baseChanged(qreal)), receiver: this, SLOT(handleBaseChanged(qreal))); |
| 17 | QObject::connect(sender: axis, SIGNAL(labelFormatChanged(QString)), |
| 18 | receiver: this, SLOT(handleLabelFormatChanged(QString))); |
| 19 | } |
| 20 | |
| 21 | PolarChartLogValueAxisAngular::~PolarChartLogValueAxisAngular() |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | QList<qreal> PolarChartLogValueAxisAngular::calculateLayout() const |
| 26 | { |
| 27 | QLogValueAxis *logValueAxis = qobject_cast<QLogValueAxis *>(object: axis()); |
| 28 | |
| 29 | QList<qreal> points; |
| 30 | points.resize(size: logValueAxis->tickCount()); |
| 31 | |
| 32 | const qreal logMax = qLn(v: logValueAxis->max()) / qLn(v: logValueAxis->base()); |
| 33 | const qreal logMin = qLn(v: logValueAxis->min()) / qLn(v: logValueAxis->base()); |
| 34 | const qreal startEdge = qMin(a: logMin, b: logMax); |
| 35 | const qreal delta = 360.0 / qAbs(t: logMax - logMin); |
| 36 | const qreal initialSpan = (std::ceil(x: startEdge) - startEdge) * delta; |
| 37 | |
| 38 | for (int i = 0; i < logValueAxis->tickCount(); ++i) |
| 39 | points[i] = initialSpan + (delta * qreal(i)); |
| 40 | |
| 41 | return points; |
| 42 | } |
| 43 | |
| 44 | void PolarChartLogValueAxisAngular::createAxisLabels(const QList<qreal> &layout) |
| 45 | { |
| 46 | QLogValueAxis *logValueAxis = static_cast<QLogValueAxis *>(axis()); |
| 47 | setLabels(createLogValueLabels(min: logValueAxis->min(), |
| 48 | max: logValueAxis->max(), |
| 49 | base: logValueAxis->base(), |
| 50 | ticks: layout.size(), |
| 51 | format: logValueAxis->labelFormat())); |
| 52 | } |
| 53 | |
| 54 | void PolarChartLogValueAxisAngular::handleBaseChanged(qreal base) |
| 55 | { |
| 56 | Q_UNUSED(base); |
| 57 | QGraphicsLayoutItem::updateGeometry(); |
| 58 | if (presenter()) |
| 59 | presenter()->layout()->invalidate(); |
| 60 | } |
| 61 | |
| 62 | void PolarChartLogValueAxisAngular::handleLabelFormatChanged(const QString &format) |
| 63 | { |
| 64 | Q_UNUSED(format); |
| 65 | QGraphicsLayoutItem::updateGeometry(); |
| 66 | if (presenter()) |
| 67 | presenter()->layout()->invalidate(); |
| 68 | } |
| 69 | |
| 70 | QT_END_NAMESPACE |
| 71 | |
| 72 | #include "moc_polarchartlogvalueaxisangular_p.cpp" |
| 73 | |