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/polarchartlogvalueaxisradial_p.h>
9
10QT_BEGIN_NAMESPACE
11
12PolarChartLogValueAxisRadial::PolarChartLogValueAxisRadial(QLogValueAxis *axis, QGraphicsItem *item)
13 : PolarChartAxisRadial(axis, item)
14{
15 QObject::connect(sender: axis, SIGNAL(baseChanged(qreal)), receiver: this, SLOT(handleBaseChanged(qreal)));
16 QObject::connect(sender: axis, SIGNAL(labelFormatChanged(QString)),
17 receiver: this, SLOT(handleLabelFormatChanged(QString)));
18}
19
20PolarChartLogValueAxisRadial::~PolarChartLogValueAxisRadial()
21{
22}
23
24QList<qreal> PolarChartLogValueAxisRadial::calculateLayout() const
25{
26 QLogValueAxis *logValueAxis = qobject_cast<QLogValueAxis *>(object: axis());
27
28 QList<qreal> points;
29 points.resize(size: logValueAxis->tickCount());
30
31 const qreal logMax = qLn(v: logValueAxis->max()) / qLn(v: logValueAxis->base());
32 const qreal logMin = qLn(v: logValueAxis->min()) / qLn(v: logValueAxis->base());
33 const qreal innerEdge = logMin < logMax ? logMin : logMax;
34 const qreal delta = (axisGeometry().width() / 2.0) / qAbs(t: logMax - logMin);
35 const qreal initialSpan = (std::ceil(x: innerEdge) - innerEdge) * delta;
36
37 for (int i = 0; i < logValueAxis->tickCount(); ++i)
38 points[i] = initialSpan + (delta * qreal(i));
39
40 return points;
41}
42
43void PolarChartLogValueAxisRadial::createAxisLabels(const QList<qreal> &layout)
44{
45 QLogValueAxis *logValueAxis = static_cast<QLogValueAxis *>(axis());
46 setLabels(createLogValueLabels(min: logValueAxis->min(),
47 max: logValueAxis->max(),
48 base: logValueAxis->base(),
49 ticks: layout.size(),
50 format: logValueAxis->labelFormat()));
51}
52
53void PolarChartLogValueAxisRadial::handleBaseChanged(qreal base)
54{
55 Q_UNUSED(base);
56 QGraphicsLayoutItem::updateGeometry();
57 if (presenter())
58 presenter()->layout()->invalidate();
59}
60
61void PolarChartLogValueAxisRadial::handleLabelFormatChanged(const QString &format)
62{
63 Q_UNUSED(format);
64 QGraphicsLayoutItem::updateGeometry();
65 if (presenter())
66 presenter()->layout()->invalidate();
67}
68
69QT_END_NAMESPACE
70
71#include "moc_polarchartlogvalueaxisradial_p.cpp"
72

source code of qtcharts/src/charts/axis/logvalueaxis/polarchartlogvalueaxisradial.cpp