| 1 | // Copyright (C) 2016 The Qt Company Ltd. | 
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only | 
| 3 |  | 
| 4 | #include <private/polarchartvalueaxisangular_p.h> | 
| 5 | #include <private/chartpresenter_p.h> | 
| 6 | #include <private/abstractchartlayout_p.h> | 
| 7 |  | 
| 8 | QT_BEGIN_NAMESPACE | 
| 9 |  | 
| 10 | PolarChartValueAxisAngular::PolarChartValueAxisAngular(QValueAxis *axis, QGraphicsItem *item) | 
| 11 |     : PolarChartAxisAngular(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 | PolarChartValueAxisAngular::~PolarChartValueAxisAngular() | 
| 20 | { | 
| 21 | } | 
| 22 |  | 
| 23 | QList<qreal> PolarChartValueAxisAngular::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 = 360.0 / qreal(tickCount - 1); | 
| 32 |  | 
| 33 |     for (int i = 0; i < tickCount; ++i) { | 
| 34 |         qreal angularCoordinate = qreal(i) * d; | 
| 35 |         points[i] = angularCoordinate; | 
| 36 |     } | 
| 37 |  | 
| 38 |     return points; | 
| 39 | } | 
| 40 |  | 
| 41 | void PolarChartValueAxisAngular::createAxisLabels(const QList<qreal> &layout) | 
| 42 | { | 
| 43 |     QStringList labelList = 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 |     setLabels(labelList); | 
| 47 | } | 
| 48 |  | 
| 49 | void PolarChartValueAxisAngular::handleTickCountChanged(int tick) | 
| 50 | { | 
| 51 |     Q_UNUSED(tick); | 
| 52 |     QGraphicsLayoutItem::updateGeometry(); | 
| 53 |     if (presenter()) | 
| 54 |         presenter()->layout()->invalidate(); | 
| 55 | } | 
| 56 |  | 
| 57 | void PolarChartValueAxisAngular::handleMinorTickCountChanged(int tick) | 
| 58 | { | 
| 59 |     Q_UNUSED(tick); | 
| 60 |     QGraphicsLayoutItem::updateGeometry(); | 
| 61 |     if (presenter()) | 
| 62 |         presenter()->layout()->invalidate(); | 
| 63 | } | 
| 64 |  | 
| 65 | void PolarChartValueAxisAngular::handleLabelFormatChanged(const QString &format) | 
| 66 | { | 
| 67 |     Q_UNUSED(format); | 
| 68 |     QGraphicsLayoutItem::updateGeometry(); | 
| 69 |     if (presenter()) | 
| 70 |         presenter()->layout()->invalidate(); | 
| 71 | } | 
| 72 |  | 
| 73 | QT_END_NAMESPACE | 
| 74 |  | 
| 75 | #include "moc_polarchartvalueaxisangular_p.cpp" | 
| 76 |  |