1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include <private/polarchartvalueaxisradial_p.h> |
5 | #include <private/chartpresenter_p.h> |
6 | #include <private/abstractchartlayout_p.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | PolarChartValueAxisRadial::PolarChartValueAxisRadial(QValueAxis *axis, QGraphicsItem *item) |
11 | : PolarChartAxisRadial(axis, item) |
12 | { |
13 | QObject::connect(sender: axis, SIGNAL(tickCountChanged(int)), receiver: this, SLOT(handleTickCountChanged(int))); |
14 | QObject::connect(sender: axis, SIGNAL(minorTickCountChanged(int)), |
15 | receiver: this, SLOT(handleMinorTickCountChanged(int))); |
16 | QObject::connect(sender: axis, SIGNAL(labelFormatChanged(QString)), receiver: this, SLOT(handleLabelFormatChanged(QString))); |
17 | } |
18 | |
19 | PolarChartValueAxisRadial::~PolarChartValueAxisRadial() |
20 | { |
21 | } |
22 | |
23 | QList<qreal> PolarChartValueAxisRadial::calculateLayout() const |
24 | { |
25 | int tickCount = static_cast<QValueAxis *>(axis())->tickCount(); |
26 | Q_ASSERT(tickCount >= 2); |
27 | |
28 | QList<qreal> points; |
29 | points.resize(size: tickCount); |
30 | |
31 | const qreal d = (axisGeometry().width() / 2) / qreal(tickCount - 1); |
32 | |
33 | for (int i = 0; i < tickCount; ++i) { |
34 | qreal radialCoordinate = qreal(i) * d; |
35 | points[i] = radialCoordinate; |
36 | } |
37 | |
38 | return points; |
39 | } |
40 | |
41 | void PolarChartValueAxisRadial::createAxisLabels(const QList<qreal> &layout) |
42 | { |
43 | setLabels(createValueLabels(max: min(), min: max(), ticks: layout.size(), tickInterval: 0.0, tickAnchor: 0.0, |
44 | tickType: QValueAxis::TicksFixed, |
45 | format: static_cast<QValueAxis *>(axis())->labelFormat())); |
46 | } |
47 | |
48 | void PolarChartValueAxisRadial::handleTickCountChanged(int tick) |
49 | { |
50 | Q_UNUSED(tick); |
51 | QGraphicsLayoutItem::updateGeometry(); |
52 | if (presenter()) |
53 | presenter()->layout()->invalidate(); |
54 | } |
55 | |
56 | void PolarChartValueAxisRadial::handleMinorTickCountChanged(int tick) |
57 | { |
58 | Q_UNUSED(tick); |
59 | QGraphicsLayoutItem::updateGeometry(); |
60 | if (presenter()) |
61 | presenter()->layout()->invalidate(); |
62 | } |
63 | |
64 | void PolarChartValueAxisRadial::handleLabelFormatChanged(const QString &format) |
65 | { |
66 | Q_UNUSED(format); |
67 | QGraphicsLayoutItem::updateGeometry(); |
68 | if (presenter()) |
69 | presenter()->layout()->invalidate(); |
70 | } |
71 | |
72 | QT_END_NAMESPACE |
73 | |
74 | #include "moc_polarchartvalueaxisradial_p.cpp" |
75 | |