1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#include <QtCharts/qlogvalueaxis.h>
31#include <QtCore/qmath.h>
32#include <private/abstractchartlayout_p.h>
33#include <private/chartpresenter_p.h>
34#include <private/polarchartlogvalueaxisradial_p.h>
35
36QT_CHARTS_BEGIN_NAMESPACE
37
38PolarChartLogValueAxisRadial::PolarChartLogValueAxisRadial(QLogValueAxis *axis, QGraphicsItem *item)
39 : PolarChartAxisRadial(axis, item)
40{
41 QObject::connect(sender: axis, SIGNAL(baseChanged(qreal)), receiver: this, SLOT(handleBaseChanged(qreal)));
42 QObject::connect(sender: axis, SIGNAL(labelFormatChanged(QString)),
43 receiver: this, SLOT(handleLabelFormatChanged(QString)));
44}
45
46PolarChartLogValueAxisRadial::~PolarChartLogValueAxisRadial()
47{
48}
49
50QVector<qreal> PolarChartLogValueAxisRadial::calculateLayout() const
51{
52 QLogValueAxis *logValueAxis = qobject_cast<QLogValueAxis *>(object: axis());
53
54 QVector<qreal> points;
55 points.resize(size: logValueAxis->tickCount());
56
57 const qreal logMax = std::log10(x: logValueAxis->max()) / std::log10(x: logValueAxis->base());
58 const qreal logMin = std::log10(x: logValueAxis->min()) / std::log10(x: logValueAxis->base());
59 const qreal innerEdge = logMin < logMax ? logMin : logMax;
60 const qreal delta = (axisGeometry().width() / 2.0) / qAbs(t: logMax - logMin);
61 const qreal initialSpan = (qCeil(v: innerEdge) - innerEdge) * delta;
62
63 for (int i = 0; i < logValueAxis->tickCount(); ++i)
64 points[i] = initialSpan + (delta * qreal(i));
65
66 return points;
67}
68
69void PolarChartLogValueAxisRadial::createAxisLabels(const QVector<qreal> &layout)
70{
71 QLogValueAxis *logValueAxis = static_cast<QLogValueAxis *>(axis());
72 setLabels(createLogValueLabels(min: logValueAxis->min(),
73 max: logValueAxis->max(),
74 base: logValueAxis->base(),
75 ticks: layout.size(),
76 format: logValueAxis->labelFormat()));
77}
78
79void PolarChartLogValueAxisRadial::handleBaseChanged(qreal base)
80{
81 Q_UNUSED(base);
82 QGraphicsLayoutItem::updateGeometry();
83 if (presenter())
84 presenter()->layout()->invalidate();
85}
86
87void PolarChartLogValueAxisRadial::handleLabelFormatChanged(const QString &format)
88{
89 Q_UNUSED(format);
90 QGraphicsLayoutItem::updateGeometry();
91 if (presenter())
92 presenter()->layout()->invalidate();
93}
94
95QT_CHARTS_END_NAMESPACE
96
97#include "moc_polarchartlogvalueaxisradial_p.cpp"
98

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