1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include <private/polarchartaxis_p.h>
5#include <private/qabstractaxis_p.h>
6#include <private/chartpresenter_p.h>
7#include <QtCharts/QValueAxis>
8
9QT_BEGIN_NAMESPACE
10
11PolarChartAxis::PolarChartAxis(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
12 : ChartAxisElement(axis, item, intervalAxis)
13{
14}
15
16PolarChartAxis::~PolarChartAxis()
17{
18
19}
20
21void PolarChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
22{
23 Q_UNUSED(grid);
24 setAxisGeometry(axis);
25
26 if (emptyAxis()) {
27 prepareGeometryChange();
28 return;
29 }
30
31 const QList<qreal> layout = calculateLayout();
32 updateLayout(layout);
33}
34
35QRectF PolarChartAxis::gridGeometry() const
36{
37 return QRectF();
38}
39
40void PolarChartAxis::updateLayout(const QList<qreal> &layout)
41{
42 int diff = ChartAxisElement::layout().size() - layout.size();
43
44 if (animation()) {
45 switch (presenter()->state()) {
46 case ChartPresenter::ZoomInState:
47 case ChartPresenter::ZoomOutState:
48 case ChartPresenter::ScrollUpState:
49 case ChartPresenter::ScrollLeftState:
50 case ChartPresenter::ScrollDownState:
51 case ChartPresenter::ScrollRightState:
52 case ChartPresenter::ShowState:
53 animation()->setAnimationType(AxisAnimation::DefaultAnimation);
54 break;
55 }
56 // Update to "old" geometry before starting animation to avoid incorrectly sized
57 // axes lingering in wrong position compared to series plot before animation can kick in.
58 // Note that the position mismatch still exists even with this update, but it will be
59 // far less ugly.
60 if (ChartAxisElement::layout().size() != 0)
61 updateGeometry();
62 }
63
64 if (diff > 0)
65 deleteItems(count: diff);
66 else if (diff <= 0)
67 createItems(count: -diff);
68
69 updateMinorTickItems();
70
71 if (animation()) {
72 animation()->setValues(oldLayout&: ChartAxisElement::layout(), newLayout: layout);
73 presenter()->startAnimation(animation: animation());
74 } else {
75 setLayout(layout);
76 updateGeometry();
77 }
78}
79
80bool PolarChartAxis::emptyAxis() const
81{
82 return !axisGeometry().isValid() || qFuzzyIsNull(d: min() - max());
83}
84
85void PolarChartAxis::deleteItems(int count)
86{
87 QList<QGraphicsItem *> gridLines = gridItems();
88 QList<QGraphicsItem *> labels = labelItems();
89 QList<QGraphicsItem *> shades = shadeItems();
90 QList<QGraphicsItem *> axis = arrowItems();
91
92 for (int i = 0; i < count; ++i) {
93 if (gridItems().size() == 1 || (((gridLines.size() + 1) % 2) && gridLines.size() > 0))
94 delete(shades.takeLast());
95 delete(gridLines.takeLast());
96 delete(labels.takeLast());
97 delete(axis.takeLast());
98 }
99}
100
101void PolarChartAxis::handleShadesBrushChanged(const QBrush &brush)
102{
103 foreach (QGraphicsItem *item, shadeItems())
104 static_cast<QGraphicsPathItem *>(item)->setBrush(brush);
105}
106
107void PolarChartAxis::handleShadesPenChanged(const QPen &pen)
108{
109 foreach (QGraphicsItem *item, shadeItems())
110 static_cast<QGraphicsPathItem *>(item)->setPen(pen);
111}
112
113QT_END_NAMESPACE
114
115#include "moc_polarchartaxis_p.cpp"
116

source code of qtcharts/src/charts/axis/polarchartaxis.cpp