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 <private/polarchartaxis_p.h> |
31 | #include <private/qabstractaxis_p.h> |
32 | #include <private/chartpresenter_p.h> |
33 | #include <QtCharts/QValueAxis> |
34 | |
35 | QT_CHARTS_BEGIN_NAMESPACE |
36 | |
37 | PolarChartAxis::PolarChartAxis(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis) |
38 | : ChartAxisElement(axis, item, intervalAxis) |
39 | { |
40 | } |
41 | |
42 | PolarChartAxis::~PolarChartAxis() |
43 | { |
44 | |
45 | } |
46 | |
47 | void PolarChartAxis::setGeometry(const QRectF &axis, const QRectF &grid) |
48 | { |
49 | Q_UNUSED(grid); |
50 | setAxisGeometry(axis); |
51 | |
52 | if (isEmpty()) { |
53 | prepareGeometryChange(); |
54 | return; |
55 | } |
56 | |
57 | QVector<qreal> layout = calculateLayout(); |
58 | updateLayout(layout); |
59 | } |
60 | |
61 | QRectF PolarChartAxis::gridGeometry() const |
62 | { |
63 | return QRectF(); |
64 | } |
65 | |
66 | void PolarChartAxis::updateLayout(QVector<qreal> &layout) |
67 | { |
68 | int diff = ChartAxisElement::layout().size() - layout.size(); |
69 | |
70 | if (animation()) { |
71 | switch (presenter()->state()) { |
72 | case ChartPresenter::ZoomInState: |
73 | case ChartPresenter::ZoomOutState: |
74 | case ChartPresenter::ScrollUpState: |
75 | case ChartPresenter::ScrollLeftState: |
76 | case ChartPresenter::ScrollDownState: |
77 | case ChartPresenter::ScrollRightState: |
78 | case ChartPresenter::ShowState: |
79 | animation()->setAnimationType(AxisAnimation::DefaultAnimation); |
80 | break; |
81 | } |
82 | // Update to "old" geometry before starting animation to avoid incorrectly sized |
83 | // axes lingering in wrong position compared to series plot before animation can kick in. |
84 | // Note that the position mismatch still exists even with this update, but it will be |
85 | // far less ugly. |
86 | if (ChartAxisElement::layout().size() != 0) |
87 | updateGeometry(); |
88 | } |
89 | |
90 | if (diff > 0) |
91 | deleteItems(count: diff); |
92 | else if (diff <= 0) |
93 | createItems(count: -diff); |
94 | |
95 | updateMinorTickItems(); |
96 | |
97 | if (animation()) { |
98 | animation()->setValues(oldLayout&: ChartAxisElement::layout(), newLayout&: layout); |
99 | presenter()->startAnimation(animation: animation()); |
100 | } else { |
101 | setLayout(layout); |
102 | updateGeometry(); |
103 | } |
104 | } |
105 | |
106 | bool PolarChartAxis::isEmpty() |
107 | { |
108 | return !axisGeometry().isValid() || qFuzzyIsNull(d: min() - max()); |
109 | } |
110 | |
111 | void PolarChartAxis::deleteItems(int count) |
112 | { |
113 | QList<QGraphicsItem *> gridLines = gridItems(); |
114 | QList<QGraphicsItem *> labels = labelItems(); |
115 | QList<QGraphicsItem *> shades = shadeItems(); |
116 | QList<QGraphicsItem *> axis = arrowItems(); |
117 | |
118 | for (int i = 0; i < count; ++i) { |
119 | if (gridItems().size() == 1 || (((gridLines.size() + 1) % 2) && gridLines.size() > 0)) |
120 | delete(shades.takeLast()); |
121 | delete(gridLines.takeLast()); |
122 | delete(labels.takeLast()); |
123 | delete(axis.takeLast()); |
124 | } |
125 | } |
126 | |
127 | void PolarChartAxis::handleShadesBrushChanged(const QBrush &brush) |
128 | { |
129 | foreach (QGraphicsItem *item, shadeItems()) |
130 | static_cast<QGraphicsPathItem *>(item)->setBrush(brush); |
131 | } |
132 | |
133 | void PolarChartAxis::handleShadesPenChanged(const QPen &pen) |
134 | { |
135 | foreach (QGraphicsItem *item, shadeItems()) |
136 | static_cast<QGraphicsPathItem *>(item)->setPen(pen); |
137 | } |
138 | |
139 | QT_CHARTS_END_NAMESPACE |
140 | |
141 | #include "moc_polarchartaxis_p.cpp" |
142 | |