1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include <private/polarchartcategoryaxisangular_p.h> |
5 | #include <private/chartpresenter_p.h> |
6 | #include <private/abstractchartlayout_p.h> |
7 | #include <QtCharts/QCategoryAxis> |
8 | #include <QtCore/QDebug> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | PolarChartCategoryAxisAngular::PolarChartCategoryAxisAngular(QCategoryAxis *axis, QGraphicsItem *item) |
13 | : PolarChartAxisAngular(axis, item, true) |
14 | { |
15 | QObject::connect(sender: axis, SIGNAL(categoriesChanged()), receiver: this, SLOT(handleCategoriesChanged())); |
16 | } |
17 | |
18 | PolarChartCategoryAxisAngular::~PolarChartCategoryAxisAngular() |
19 | { |
20 | } |
21 | |
22 | QList<qreal> PolarChartCategoryAxisAngular::calculateLayout() const |
23 | { |
24 | QCategoryAxis *catAxis = static_cast<QCategoryAxis *>(axis()); |
25 | int tickCount = catAxis->categoriesLabels().size() + 1; |
26 | QList<qreal> points; |
27 | |
28 | if (tickCount < 2) |
29 | return points; |
30 | |
31 | qreal range = max() - min(); |
32 | if (range > 0) { |
33 | points.resize(size: tickCount); |
34 | qreal scale = 360.0 / range; |
35 | qreal angle; |
36 | for (int i = 0; i < tickCount; ++i) { |
37 | if (i < tickCount - 1) |
38 | angle = (catAxis->startValue(categoryLabel: catAxis->categoriesLabels().at(i)) - min()) * scale; |
39 | else |
40 | angle = (catAxis->endValue(categoryLabel: catAxis->categoriesLabels().at(i: i - 1)) - min()) * scale; |
41 | points[i] = angle; |
42 | } |
43 | } |
44 | |
45 | return points; |
46 | } |
47 | |
48 | void PolarChartCategoryAxisAngular::createAxisLabels(const QList<qreal> &layout) |
49 | { |
50 | Q_UNUSED(layout); |
51 | setLabels(static_cast<QCategoryAxis *>(axis())->categoriesLabels() << QString()); |
52 | } |
53 | |
54 | void PolarChartCategoryAxisAngular::handleCategoriesChanged() |
55 | { |
56 | QGraphicsLayoutItem::updateGeometry(); |
57 | presenter()->layout()->invalidate(); |
58 | } |
59 | |
60 | QT_END_NAMESPACE |
61 | |
62 | #include "moc_polarchartcategoryaxisangular_p.cpp" |
63 |