| 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/polarchartlogvalueaxisangular_p.h> |
| 35 | |
| 36 | QT_CHARTS_BEGIN_NAMESPACE |
| 37 | |
| 38 | PolarChartLogValueAxisAngular::PolarChartLogValueAxisAngular(QLogValueAxis *axis, |
| 39 | QGraphicsItem *item) |
| 40 | : PolarChartAxisAngular(axis, item) |
| 41 | { |
| 42 | QObject::connect(sender: axis, SIGNAL(baseChanged(qreal)), receiver: this, SLOT(handleBaseChanged(qreal))); |
| 43 | QObject::connect(sender: axis, SIGNAL(labelFormatChanged(QString)), |
| 44 | receiver: this, SLOT(handleLabelFormatChanged(QString))); |
| 45 | } |
| 46 | |
| 47 | PolarChartLogValueAxisAngular::~PolarChartLogValueAxisAngular() |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | QVector<qreal> PolarChartLogValueAxisAngular::calculateLayout() const |
| 52 | { |
| 53 | QLogValueAxis *logValueAxis = qobject_cast<QLogValueAxis *>(object: axis()); |
| 54 | |
| 55 | QVector<qreal> points; |
| 56 | points.resize(size: logValueAxis->tickCount()); |
| 57 | |
| 58 | const qreal logMax = std::log10(x: logValueAxis->max()) / std::log10(x: logValueAxis->base()); |
| 59 | const qreal logMin = std::log10(x: logValueAxis->min()) / std::log10(x: logValueAxis->base()); |
| 60 | const qreal startEdge = qMin(a: logMin, b: logMax); |
| 61 | const qreal delta = 360.0 / qAbs(t: logMax - logMin); |
| 62 | const qreal initialSpan = (qCeil(v: startEdge) - startEdge) * delta; |
| 63 | |
| 64 | for (int i = 0; i < logValueAxis->tickCount(); ++i) |
| 65 | points[i] = initialSpan + (delta * qreal(i)); |
| 66 | |
| 67 | return points; |
| 68 | } |
| 69 | |
| 70 | void PolarChartLogValueAxisAngular::createAxisLabels(const QVector<qreal> &layout) |
| 71 | { |
| 72 | QLogValueAxis *logValueAxis = static_cast<QLogValueAxis *>(axis()); |
| 73 | setLabels(createLogValueLabels(min: logValueAxis->min(), |
| 74 | max: logValueAxis->max(), |
| 75 | base: logValueAxis->base(), |
| 76 | ticks: layout.size(), |
| 77 | format: logValueAxis->labelFormat())); |
| 78 | } |
| 79 | |
| 80 | void PolarChartLogValueAxisAngular::handleBaseChanged(qreal base) |
| 81 | { |
| 82 | Q_UNUSED(base); |
| 83 | QGraphicsLayoutItem::updateGeometry(); |
| 84 | if (presenter()) |
| 85 | presenter()->layout()->invalidate(); |
| 86 | } |
| 87 | |
| 88 | void PolarChartLogValueAxisAngular::handleLabelFormatChanged(const QString &format) |
| 89 | { |
| 90 | Q_UNUSED(format); |
| 91 | QGraphicsLayoutItem::updateGeometry(); |
| 92 | if (presenter()) |
| 93 | presenter()->layout()->invalidate(); |
| 94 | } |
| 95 | |
| 96 | QT_CHARTS_END_NAMESPACE |
| 97 | |
| 98 | #include "moc_polarchartlogvalueaxisangular_p.cpp" |
| 99 | |