| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2017 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/QPolarChart> |
| 31 | #include <QtCharts/QAbstractAxis> |
| 32 | |
| 33 | QT_CHARTS_BEGIN_NAMESPACE |
| 34 | |
| 35 | /*! |
| 36 | \enum QPolarChart::PolarOrientation |
| 37 | |
| 38 | This enum type specifies the polar orientation of an axis. |
| 39 | |
| 40 | \value PolarOrientationRadial |
| 41 | A radial axis, where the values are placed along the radius of the |
| 42 | chart, starting at the pole. |
| 43 | \value PolarOrientationAngular |
| 44 | An angular axis, where the values are placed around the chart. |
| 45 | */ |
| 46 | |
| 47 | /*! |
| 48 | \class QPolarChart |
| 49 | \inmodule QtCharts |
| 50 | \brief The QPolarChart presents data in polar charts. |
| 51 | |
| 52 | Polar charts present data in a circular graph, where the placement of data |
| 53 | is based on the angle and distance from the center of the graph, the \e pole. |
| 54 | |
| 55 | \image examples_polarchart.png |
| 56 | |
| 57 | A polar chart is a specialization of QChart that supports line, spline, area, |
| 58 | and scatter series, and all axis types supported by them. Each axis can be used |
| 59 | either as a radial or an angular axis. |
| 60 | |
| 61 | The first and last tick mark on an angular QValueAxis are co-located at a 0/360 degree angle. |
| 62 | |
| 63 | If the angular distance between two consecutive points in a series is more than 180 degrees, |
| 64 | any direct line connecting the two points becomes meaningless, and will not be drawn. Instead, |
| 65 | a line will be drawn to and from the center of the chart. Therefore, the axis ranges must be |
| 66 | chosen accordingly when displaying line, spline, or area series. |
| 67 | |
| 68 | Polar charts draw all axes of the same orientation in the same position, so using multiple |
| 69 | axes of the same orientation can be confusing, unless the extra axes are only used to customize the |
| 70 | grid. For example, you can display a highlighted range with a secondary shaded QCategoryAxis |
| 71 | or provide unlabeled subticks with a secondary QValueAxis thas has hidden labels. |
| 72 | |
| 73 | \sa QChart |
| 74 | */ |
| 75 | |
| 76 | /*! |
| 77 | Constructs a polar chart as a child of \a parent. |
| 78 | The properties specified by \a wFlags are passed to the QChart constructor. |
| 79 | */ |
| 80 | QPolarChart::QPolarChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
| 81 | : QChart(QChart::ChartTypePolar, parent, wFlags) |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | /*! |
| 86 | Deletes the polar chart object and its children, such as the series and axis objects added to it. |
| 87 | */ |
| 88 | QPolarChart::~QPolarChart() |
| 89 | { |
| 90 | } |
| 91 | |
| 92 | /*! |
| 93 | Returns the axes added for the series \a series with the polar orientation |
| 94 | \a polarOrientation. If no series is provided, any axis with the |
| 95 | specified polar orientation is returned. |
| 96 | |
| 97 | \sa addAxis() |
| 98 | */ |
| 99 | QList<QAbstractAxis *> QPolarChart::axes(PolarOrientations polarOrientation, QAbstractSeries *series) const |
| 100 | { |
| 101 | Qt::Orientations orientation; |
| 102 | if (polarOrientation.testFlag(flag: PolarOrientationAngular)) |
| 103 | orientation |= Qt::Horizontal; |
| 104 | if (polarOrientation.testFlag(flag: PolarOrientationRadial)) |
| 105 | orientation |= Qt::Vertical; |
| 106 | |
| 107 | return QChart::axes(orientation, series); |
| 108 | } |
| 109 | |
| 110 | /*! |
| 111 | This convenience method adds the axis \a axis to the polar chart with the polar |
| 112 | orientation \a polarOrientation. |
| 113 | The chart takes the ownership of the axis. |
| 114 | |
| 115 | \note Axes can be added to a polar chart also with QChart::addAxis(). |
| 116 | The specified alignment determines the polar orientation: horizontal alignments indicate |
| 117 | an angular axis and vertical alignments indicate a radial axis. |
| 118 | |
| 119 | \sa QChart::removeAxis(), QChart::createDefaultAxes(), QAbstractSeries::attachAxis(), QChart::addAxis() |
| 120 | */ |
| 121 | void QPolarChart::addAxis(QAbstractAxis *axis, PolarOrientation polarOrientation) |
| 122 | { |
| 123 | if (!axis || axis->type() == QAbstractAxis::AxisTypeBarCategory) { |
| 124 | qWarning(msg: "QAbstractAxis::AxisTypeBarCategory is not a supported axis type for polar charts." ); |
| 125 | } else { |
| 126 | Qt::Alignment alignment = Qt::AlignLeft; |
| 127 | if (polarOrientation == PolarOrientationAngular) |
| 128 | alignment = Qt::AlignBottom; |
| 129 | QChart::addAxis(axis, alignment); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /*! |
| 134 | The angular axes of a polar chart report horizontal orientation and the radial axes report |
| 135 | vertical orientation. |
| 136 | This function is a convenience function for converting the orientation of the axis \a axis to |
| 137 | the corresponding polar orientation. If the \a axis is null or not added to a polar chart, |
| 138 | the return value is meaningless. |
| 139 | */ |
| 140 | QPolarChart::PolarOrientation QPolarChart::axisPolarOrientation(QAbstractAxis *axis) |
| 141 | { |
| 142 | if (axis && axis->orientation() == Qt::Horizontal) |
| 143 | return PolarOrientationAngular; |
| 144 | else |
| 145 | return PolarOrientationRadial; |
| 146 | } |
| 147 | |
| 148 | QT_CHARTS_END_NAMESPACE |
| 149 | |
| 150 | #include "moc_qpolarchart.cpp" |
| 151 | |