##// END OF EJS Templates
Fix issue with ghost axes being drawn when last axis removed...
Miikka Heikkinen -
r2836:7a48aa2a436d
parent child
Show More
@@ -1,262 +1,264
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd
3 ** Copyright (C) 2015 The Qt Company Ltd
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
6 **
6 **
7 ** This file is part of the Qt Charts module.
7 ** This file is part of the Qt Charts module.
8 **
8 **
9 ** Licensees holding valid commercial license for Qt may use this file in
9 ** Licensees holding valid commercial license for Qt may use this file in
10 ** accordance with the Qt License Agreement provided with the Software
10 ** accordance with the Qt License Agreement provided with the Software
11 ** or, alternatively, in accordance with the terms contained in a written
11 ** or, alternatively, in accordance with the terms contained in a written
12 ** agreement between you and The Qt Company.
12 ** agreement between you and The Qt Company.
13 **
13 **
14 ** If you have questions regarding the use of this file, please use
14 ** If you have questions regarding the use of this file, please use
15 ** contact form at http://qt.io
15 ** contact form at http://qt.io
16 **
16 **
17 ****************************************************************************/
17 ****************************************************************************/
18
18
19 #include <private/cartesianchartaxis_p.h>
19 #include <private/cartesianchartaxis_p.h>
20 #include <QtCharts/QAbstractAxis>
20 #include <QtCharts/QAbstractAxis>
21 #include <private/qabstractaxis_p.h>
21 #include <private/qabstractaxis_p.h>
22 #include <private/chartpresenter_p.h>
22 #include <private/chartpresenter_p.h>
23 #include <private/abstractchartlayout_p.h>
23 #include <private/abstractchartlayout_p.h>
24 #include <private/abstractdomain_p.h>
24 #include <private/abstractdomain_p.h>
25 #include <private/linearrowitem_p.h>
25 #include <private/linearrowitem_p.h>
26 #include <QtCharts/QValueAxis>
26 #include <QtCharts/QValueAxis>
27 #include <QtCharts/QLogValueAxis>
27 #include <QtCharts/QLogValueAxis>
28 #include <QtWidgets/QGraphicsLayout>
28 #include <QtWidgets/QGraphicsLayout>
29 #include <QtGui/QTextDocument>
29 #include <QtGui/QTextDocument>
30
30
31 QT_CHARTS_BEGIN_NAMESPACE
31 QT_CHARTS_BEGIN_NAMESPACE
32
32
33 CartesianChartAxis::CartesianChartAxis(QAbstractAxis *axis, QGraphicsItem *item , bool intervalAxis)
33 CartesianChartAxis::CartesianChartAxis(QAbstractAxis *axis, QGraphicsItem *item , bool intervalAxis)
34 : ChartAxisElement(axis, item, intervalAxis)
34 : ChartAxisElement(axis, item, intervalAxis)
35 {
35 {
36 Q_ASSERT(item);
36 Q_ASSERT(item);
37 }
37 }
38
38
39
39
40 CartesianChartAxis::~CartesianChartAxis()
40 CartesianChartAxis::~CartesianChartAxis()
41 {
41 {
42 }
42 }
43
43
44 void CartesianChartAxis::createItems(int count)
44 void CartesianChartAxis::createItems(int count)
45 {
45 {
46 if (arrowItems().size() == 0) {
46 if (arrowItems().size() == 0) {
47 QGraphicsLineItem *arrow = new LineArrowItem(this, this);
47 QGraphicsLineItem *arrow = new LineArrowItem(this, this);
48 arrow->setPen(axis()->linePen());
48 arrow->setPen(axis()->linePen());
49 arrowGroup()->addToGroup(arrow);
49 arrowGroup()->addToGroup(arrow);
50 }
50 }
51
51
52 if (intervalAxis() && gridItems().size() == 0) {
52 if (intervalAxis() && gridItems().size() == 0) {
53 for (int i = 0 ; i < 2 ; i ++){
53 for (int i = 0 ; i < 2 ; i ++){
54 QGraphicsLineItem *item = new QGraphicsLineItem(this);
54 QGraphicsLineItem *item = new QGraphicsLineItem(this);
55 item->setPen(axis()->gridLinePen());
55 item->setPen(axis()->gridLinePen());
56 gridGroup()->addToGroup(item);
56 gridGroup()->addToGroup(item);
57 QGraphicsRectItem *shades = new QGraphicsRectItem(this);
57 QGraphicsRectItem *shades = new QGraphicsRectItem(this);
58 shades->setPen(axis()->shadesPen());
58 shades->setPen(axis()->shadesPen());
59 shades->setBrush(axis()->shadesBrush());
59 shades->setBrush(axis()->shadesBrush());
60 shadeGroup()->addToGroup(shades);
60 shadeGroup()->addToGroup(shades);
61 }
61 }
62 }
62 }
63
63
64 QGraphicsTextItem *title = titleItem();
64 QGraphicsTextItem *title = titleItem();
65 title->setFont(axis()->titleFont());
65 title->setFont(axis()->titleFont());
66 title->setDefaultTextColor(axis()->titleBrush().color());
66 title->setDefaultTextColor(axis()->titleBrush().color());
67 title->setHtml(axis()->titleText());
67 title->setHtml(axis()->titleText());
68
68
69 for (int i = 0; i < count; ++i) {
69 for (int i = 0; i < count; ++i) {
70 QGraphicsLineItem *arrow = new QGraphicsLineItem(this);
70 QGraphicsLineItem *arrow = new QGraphicsLineItem(this);
71 QGraphicsLineItem *grid = new QGraphicsLineItem(this);
71 QGraphicsLineItem *grid = new QGraphicsLineItem(this);
72 QGraphicsTextItem *label = new QGraphicsTextItem(this);
72 QGraphicsTextItem *label = new QGraphicsTextItem(this);
73 label->document()->setDocumentMargin(ChartPresenter::textMargin());
73 label->document()->setDocumentMargin(ChartPresenter::textMargin());
74 arrow->setPen(axis()->linePen());
74 arrow->setPen(axis()->linePen());
75 grid->setPen(axis()->gridLinePen());
75 grid->setPen(axis()->gridLinePen());
76 label->setFont(axis()->labelsFont());
76 label->setFont(axis()->labelsFont());
77 label->setDefaultTextColor(axis()->labelsBrush().color());
77 label->setDefaultTextColor(axis()->labelsBrush().color());
78 label->setRotation(axis()->labelsAngle());
78 label->setRotation(axis()->labelsAngle());
79 arrowGroup()->addToGroup(arrow);
79 arrowGroup()->addToGroup(arrow);
80 gridGroup()->addToGroup(grid);
80 gridGroup()->addToGroup(grid);
81 labelGroup()->addToGroup(label);
81 labelGroup()->addToGroup(label);
82
82
83 if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) {
83 if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) {
84 QGraphicsRectItem *shades = new QGraphicsRectItem(this);
84 QGraphicsRectItem *shades = new QGraphicsRectItem(this);
85 shades->setPen(axis()->shadesPen());
85 shades->setPen(axis()->shadesPen());
86 shades->setBrush(axis()->shadesBrush());
86 shades->setBrush(axis()->shadesBrush());
87 shadeGroup()->addToGroup(shades);
87 shadeGroup()->addToGroup(shades);
88 }
88 }
89 }
89 }
90 }
90 }
91
91
92 void CartesianChartAxis::updateMinorTickItems()
92 void CartesianChartAxis::updateMinorTickItems()
93 {
93 {
94 QValueAxis *valueAxis = qobject_cast<QValueAxis *>(this->axis());
94 QValueAxis *valueAxis = qobject_cast<QValueAxis *>(this->axis());
95 if (valueAxis) {
95 if (valueAxis) {
96 int currentCount = minorArrowItems().size();
96 int currentCount = minorArrowItems().size();
97 int expectedCount = valueAxis->minorTickCount() * (valueAxis->tickCount() - 1);
97 int expectedCount = valueAxis->minorTickCount() * (valueAxis->tickCount() - 1);
98 int diff = expectedCount - currentCount;
98 int diff = expectedCount - currentCount;
99 if (diff > 0) {
99 if (diff > 0) {
100 for (int i = 0; i < diff; i++) {
100 for (int i = 0; i < diff; i++) {
101 QGraphicsLineItem *minorArrow = new QGraphicsLineItem(this);
101 QGraphicsLineItem *minorArrow = new QGraphicsLineItem(this);
102 QGraphicsLineItem *minorGrid = new QGraphicsLineItem(this);
102 QGraphicsLineItem *minorGrid = new QGraphicsLineItem(this);
103 minorArrow->setPen(valueAxis->linePen());
103 minorArrow->setPen(valueAxis->linePen());
104 minorGrid->setPen(valueAxis->minorGridLinePen());
104 minorGrid->setPen(valueAxis->minorGridLinePen());
105 minorArrowGroup()->addToGroup(minorArrow);
105 minorArrowGroup()->addToGroup(minorArrow);
106 minorGridGroup()->addToGroup(minorGrid);
106 minorGridGroup()->addToGroup(minorGrid);
107 }
107 }
108 } else {
108 } else {
109 QList<QGraphicsItem *> minorGridLines = minorGridItems();
109 QList<QGraphicsItem *> minorGridLines = minorGridItems();
110 QList<QGraphicsItem *> minorArrows = minorArrowItems();
110 QList<QGraphicsItem *> minorArrows = minorArrowItems();
111 for (int i = 0; i > diff; i--) {
111 for (int i = 0; i > diff; i--) {
112 if (!minorGridLines.isEmpty())
112 if (!minorGridLines.isEmpty())
113 delete(minorGridLines.takeLast());
113 delete(minorGridLines.takeLast());
114 if (!minorArrows.isEmpty())
114 if (!minorArrows.isEmpty())
115 delete(minorArrows.takeLast());
115 delete(minorArrows.takeLast());
116 }
116 }
117 }
117 }
118 }
118 }
119 }
119 }
120
120
121 void CartesianChartAxis::deleteItems(int count)
121 void CartesianChartAxis::deleteItems(int count)
122 {
122 {
123 QList<QGraphicsItem *> lines = gridItems();
123 QList<QGraphicsItem *> lines = gridItems();
124 QList<QGraphicsItem *> labels = labelItems();
124 QList<QGraphicsItem *> labels = labelItems();
125 QList<QGraphicsItem *> shades = shadeItems();
125 QList<QGraphicsItem *> shades = shadeItems();
126 QList<QGraphicsItem *> axis = arrowItems();
126 QList<QGraphicsItem *> axis = arrowItems();
127
127
128 for (int i = 0; i < count; ++i) {
128 for (int i = 0; i < count; ++i) {
129 if (lines.size() == 1 || (((lines.size() + 1) % 2) && lines.size() > 0))
129 if (lines.size() == 1 || (((lines.size() + 1) % 2) && lines.size() > 0))
130 delete(shades.takeLast());
130 delete(shades.takeLast());
131 delete(lines.takeLast());
131 delete(lines.takeLast());
132 delete(labels.takeLast());
132 delete(labels.takeLast());
133 delete(axis.takeLast());
133 delete(axis.takeLast());
134 }
134 }
135 }
135 }
136
136
137 void CartesianChartAxis::updateLayout(QVector<qreal> &layout)
137 void CartesianChartAxis::updateLayout(QVector<qreal> &layout)
138 {
138 {
139 int diff = ChartAxisElement::layout().size() - layout.size();
139 int diff = ChartAxisElement::layout().size() - layout.size();
140
140
141 if (diff > 0)
141 if (diff > 0)
142 deleteItems(diff);
142 deleteItems(diff);
143 else if (diff < 0)
143 else if (diff < 0)
144 createItems(-diff);
144 createItems(-diff);
145
145
146 updateMinorTickItems();
146 updateMinorTickItems();
147
147
148 if (animation()) {
148 if (animation()) {
149 switch (presenter()->state()) {
149 switch (presenter()->state()) {
150 case ChartPresenter::ZoomInState:
150 case ChartPresenter::ZoomInState:
151 animation()->setAnimationType(AxisAnimation::ZoomInAnimation);
151 animation()->setAnimationType(AxisAnimation::ZoomInAnimation);
152 animation()->setAnimationPoint(presenter()->statePoint());
152 animation()->setAnimationPoint(presenter()->statePoint());
153 break;
153 break;
154 case ChartPresenter::ZoomOutState:
154 case ChartPresenter::ZoomOutState:
155 animation()->setAnimationType(AxisAnimation::ZoomOutAnimation);
155 animation()->setAnimationType(AxisAnimation::ZoomOutAnimation);
156 animation()->setAnimationPoint(presenter()->statePoint());
156 animation()->setAnimationPoint(presenter()->statePoint());
157 break;
157 break;
158 case ChartPresenter::ScrollUpState:
158 case ChartPresenter::ScrollUpState:
159 case ChartPresenter::ScrollLeftState:
159 case ChartPresenter::ScrollLeftState:
160 animation()->setAnimationType(AxisAnimation::MoveBackwordAnimation);
160 animation()->setAnimationType(AxisAnimation::MoveBackwordAnimation);
161 break;
161 break;
162 case ChartPresenter::ScrollDownState:
162 case ChartPresenter::ScrollDownState:
163 case ChartPresenter::ScrollRightState:
163 case ChartPresenter::ScrollRightState:
164 animation()->setAnimationType(AxisAnimation::MoveForwardAnimation);
164 animation()->setAnimationType(AxisAnimation::MoveForwardAnimation);
165 break;
165 break;
166 case ChartPresenter::ShowState:
166 case ChartPresenter::ShowState:
167 animation()->setAnimationType(AxisAnimation::DefaultAnimation);
167 animation()->setAnimationType(AxisAnimation::DefaultAnimation);
168 break;
168 break;
169 }
169 }
170 animation()->setValues(ChartAxisElement::layout(), layout);
170 animation()->setValues(ChartAxisElement::layout(), layout);
171 presenter()->startAnimation(animation());
171 presenter()->startAnimation(animation());
172 } else {
172 } else {
173 setLayout(layout);
173 setLayout(layout);
174 updateGeometry();
174 updateGeometry();
175 }
175 }
176 }
176 }
177
177
178 bool CartesianChartAxis::isEmpty()
178 bool CartesianChartAxis::isEmpty()
179 {
179 {
180 return axisGeometry().isEmpty()
180 return axisGeometry().isEmpty()
181 || gridGeometry().isEmpty()
181 || gridGeometry().isEmpty()
182 || qFuzzyCompare(min(), max());
182 || qFuzzyCompare(min(), max());
183 }
183 }
184
184
185 void CartesianChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
185 void CartesianChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
186 {
186 {
187 m_gridRect = grid;
187 m_gridRect = grid;
188 setAxisGeometry(axis);
188 setAxisGeometry(axis);
189
189
190 if (isEmpty())
190 if (isEmpty()) {
191 prepareGeometryChange();
191 return;
192 return;
193 }
192
194
193 QVector<qreal> layout = calculateLayout();
195 QVector<qreal> layout = calculateLayout();
194 updateLayout(layout);
196 updateLayout(layout);
195 }
197 }
196
198
197 QSizeF CartesianChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
199 QSizeF CartesianChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
198 {
200 {
199 Q_UNUSED(which);
201 Q_UNUSED(which);
200 Q_UNUSED(constraint);
202 Q_UNUSED(constraint);
201 return QSizeF();
203 return QSizeF();
202 }
204 }
203
205
204 void CartesianChartAxis::handleArrowPenChanged(const QPen &pen)
206 void CartesianChartAxis::handleArrowPenChanged(const QPen &pen)
205 {
207 {
206 foreach (QGraphicsItem *item, arrowItems())
208 foreach (QGraphicsItem *item, arrowItems())
207 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
209 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
208 }
210 }
209
211
210 void CartesianChartAxis::handleGridPenChanged(const QPen &pen)
212 void CartesianChartAxis::handleGridPenChanged(const QPen &pen)
211 {
213 {
212 foreach (QGraphicsItem *item, gridItems())
214 foreach (QGraphicsItem *item, gridItems())
213 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
215 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
214 }
216 }
215
217
216 void CartesianChartAxis::handleMinorArrowPenChanged(const QPen &pen)
218 void CartesianChartAxis::handleMinorArrowPenChanged(const QPen &pen)
217 {
219 {
218 foreach (QGraphicsItem *item, minorArrowItems())
220 foreach (QGraphicsItem *item, minorArrowItems())
219 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
221 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
220 }
222 }
221
223
222 void CartesianChartAxis::handleMinorGridPenChanged(const QPen &pen)
224 void CartesianChartAxis::handleMinorGridPenChanged(const QPen &pen)
223 {
225 {
224 foreach (QGraphicsItem *item, minorGridItems())
226 foreach (QGraphicsItem *item, minorGridItems())
225 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
227 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
226 }
228 }
227
229
228 void CartesianChartAxis::handleGridLineColorChanged(const QColor &color)
230 void CartesianChartAxis::handleGridLineColorChanged(const QColor &color)
229 {
231 {
230 foreach (QGraphicsItem *item, gridItems()) {
232 foreach (QGraphicsItem *item, gridItems()) {
231 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem *>(item);
233 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem *>(item);
232 QPen pen = lineItem->pen();
234 QPen pen = lineItem->pen();
233 pen.setColor(color);
235 pen.setColor(color);
234 lineItem->setPen(pen);
236 lineItem->setPen(pen);
235 }
237 }
236 }
238 }
237
239
238 void CartesianChartAxis::handleMinorGridLineColorChanged(const QColor &color)
240 void CartesianChartAxis::handleMinorGridLineColorChanged(const QColor &color)
239 {
241 {
240 foreach (QGraphicsItem *item, minorGridItems()) {
242 foreach (QGraphicsItem *item, minorGridItems()) {
241 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem *>(item);
243 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem *>(item);
242 QPen pen = lineItem->pen();
244 QPen pen = lineItem->pen();
243 pen.setColor(color);
245 pen.setColor(color);
244 lineItem->setPen(pen);
246 lineItem->setPen(pen);
245 }
247 }
246 }
248 }
247
249
248 void CartesianChartAxis::handleShadesBrushChanged(const QBrush &brush)
250 void CartesianChartAxis::handleShadesBrushChanged(const QBrush &brush)
249 {
251 {
250 foreach (QGraphicsItem *item, shadeItems())
252 foreach (QGraphicsItem *item, shadeItems())
251 static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
253 static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
252 }
254 }
253
255
254 void CartesianChartAxis::handleShadesPenChanged(const QPen &pen)
256 void CartesianChartAxis::handleShadesPenChanged(const QPen &pen)
255 {
257 {
256 foreach (QGraphicsItem *item, shadeItems())
258 foreach (QGraphicsItem *item, shadeItems())
257 static_cast<QGraphicsRectItem *>(item)->setPen(pen);
259 static_cast<QGraphicsRectItem *>(item)->setPen(pen);
258 }
260 }
259
261
260 #include "moc_cartesianchartaxis_p.cpp"
262 #include "moc_cartesianchartaxis_p.cpp"
261
263
262 QT_CHARTS_END_NAMESPACE
264 QT_CHARTS_END_NAMESPACE
@@ -1,127 +1,129
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd
3 ** Copyright (C) 2015 The Qt Company Ltd
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
5 ** For any questions to The Qt Company, please use contact form at http://qt.io
6 **
6 **
7 ** This file is part of the Qt Charts module.
7 ** This file is part of the Qt Charts module.
8 **
8 **
9 ** Licensees holding valid commercial license for Qt may use this file in
9 ** Licensees holding valid commercial license for Qt may use this file in
10 ** accordance with the Qt License Agreement provided with the Software
10 ** accordance with the Qt License Agreement provided with the Software
11 ** or, alternatively, in accordance with the terms contained in a written
11 ** or, alternatively, in accordance with the terms contained in a written
12 ** agreement between you and The Qt Company.
12 ** agreement between you and The Qt Company.
13 **
13 **
14 ** If you have questions regarding the use of this file, please use
14 ** If you have questions regarding the use of this file, please use
15 ** contact form at http://qt.io
15 ** contact form at http://qt.io
16 **
16 **
17 ****************************************************************************/
17 ****************************************************************************/
18
18
19 #include <private/polarchartaxis_p.h>
19 #include <private/polarchartaxis_p.h>
20 #include <private/qabstractaxis_p.h>
20 #include <private/qabstractaxis_p.h>
21 #include <private/chartpresenter_p.h>
21 #include <private/chartpresenter_p.h>
22 #include <QtCharts/QValueAxis>
22 #include <QtCharts/QValueAxis>
23
23
24 QT_CHARTS_BEGIN_NAMESPACE
24 QT_CHARTS_BEGIN_NAMESPACE
25
25
26 PolarChartAxis::PolarChartAxis(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
26 PolarChartAxis::PolarChartAxis(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
27 : ChartAxisElement(axis, item, intervalAxis)
27 : ChartAxisElement(axis, item, intervalAxis)
28 {
28 {
29 }
29 }
30
30
31 PolarChartAxis::~PolarChartAxis()
31 PolarChartAxis::~PolarChartAxis()
32 {
32 {
33
33
34 }
34 }
35
35
36 void PolarChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
36 void PolarChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
37 {
37 {
38 Q_UNUSED(grid);
38 Q_UNUSED(grid);
39 setAxisGeometry(axis);
39 setAxisGeometry(axis);
40
40
41 if (isEmpty())
41 if (isEmpty()) {
42 prepareGeometryChange();
42 return;
43 return;
44 }
43
45
44 QVector<qreal> layout = calculateLayout();
46 QVector<qreal> layout = calculateLayout();
45 updateLayout(layout);
47 updateLayout(layout);
46 }
48 }
47
49
48 QRectF PolarChartAxis::gridGeometry() const
50 QRectF PolarChartAxis::gridGeometry() const
49 {
51 {
50 return QRectF();
52 return QRectF();
51 }
53 }
52
54
53 void PolarChartAxis::updateLayout(QVector<qreal> &layout)
55 void PolarChartAxis::updateLayout(QVector<qreal> &layout)
54 {
56 {
55 int diff = ChartAxisElement::layout().size() - layout.size();
57 int diff = ChartAxisElement::layout().size() - layout.size();
56
58
57 if (animation()) {
59 if (animation()) {
58 switch (presenter()->state()) {
60 switch (presenter()->state()) {
59 case ChartPresenter::ZoomInState:
61 case ChartPresenter::ZoomInState:
60 case ChartPresenter::ZoomOutState:
62 case ChartPresenter::ZoomOutState:
61 case ChartPresenter::ScrollUpState:
63 case ChartPresenter::ScrollUpState:
62 case ChartPresenter::ScrollLeftState:
64 case ChartPresenter::ScrollLeftState:
63 case ChartPresenter::ScrollDownState:
65 case ChartPresenter::ScrollDownState:
64 case ChartPresenter::ScrollRightState:
66 case ChartPresenter::ScrollRightState:
65 case ChartPresenter::ShowState:
67 case ChartPresenter::ShowState:
66 animation()->setAnimationType(AxisAnimation::DefaultAnimation);
68 animation()->setAnimationType(AxisAnimation::DefaultAnimation);
67 break;
69 break;
68 }
70 }
69 // Update to "old" geometry before starting animation to avoid incorrectly sized
71 // Update to "old" geometry before starting animation to avoid incorrectly sized
70 // axes lingering in wrong position compared to series plot before animation can kick in.
72 // axes lingering in wrong position compared to series plot before animation can kick in.
71 // Note that the position mismatch still exists even with this update, but it will be
73 // Note that the position mismatch still exists even with this update, but it will be
72 // far less ugly.
74 // far less ugly.
73 updateGeometry();
75 updateGeometry();
74 }
76 }
75
77
76 if (diff > 0)
78 if (diff > 0)
77 deleteItems(diff);
79 deleteItems(diff);
78 else if (diff < 0)
80 else if (diff < 0)
79 createItems(-diff);
81 createItems(-diff);
80
82
81 updateMinorTickItems();
83 updateMinorTickItems();
82
84
83 if (animation()) {
85 if (animation()) {
84 animation()->setValues(ChartAxisElement::layout(), layout);
86 animation()->setValues(ChartAxisElement::layout(), layout);
85 presenter()->startAnimation(animation());
87 presenter()->startAnimation(animation());
86 } else {
88 } else {
87 setLayout(layout);
89 setLayout(layout);
88 updateGeometry();
90 updateGeometry();
89 }
91 }
90 }
92 }
91
93
92 bool PolarChartAxis::isEmpty()
94 bool PolarChartAxis::isEmpty()
93 {
95 {
94 return !axisGeometry().isValid() || qFuzzyIsNull(min() - max());
96 return !axisGeometry().isValid() || qFuzzyIsNull(min() - max());
95 }
97 }
96
98
97 void PolarChartAxis::deleteItems(int count)
99 void PolarChartAxis::deleteItems(int count)
98 {
100 {
99 QList<QGraphicsItem *> gridLines = gridItems();
101 QList<QGraphicsItem *> gridLines = gridItems();
100 QList<QGraphicsItem *> labels = labelItems();
102 QList<QGraphicsItem *> labels = labelItems();
101 QList<QGraphicsItem *> shades = shadeItems();
103 QList<QGraphicsItem *> shades = shadeItems();
102 QList<QGraphicsItem *> axis = arrowItems();
104 QList<QGraphicsItem *> axis = arrowItems();
103
105
104 for (int i = 0; i < count; ++i) {
106 for (int i = 0; i < count; ++i) {
105 if (gridItems().size() == 1 || (((gridLines.size() + 1) % 2) && gridLines.size() > 0))
107 if (gridItems().size() == 1 || (((gridLines.size() + 1) % 2) && gridLines.size() > 0))
106 delete(shades.takeLast());
108 delete(shades.takeLast());
107 delete(gridLines.takeLast());
109 delete(gridLines.takeLast());
108 delete(labels.takeLast());
110 delete(labels.takeLast());
109 delete(axis.takeLast());
111 delete(axis.takeLast());
110 }
112 }
111 }
113 }
112
114
113 void PolarChartAxis::handleShadesBrushChanged(const QBrush &brush)
115 void PolarChartAxis::handleShadesBrushChanged(const QBrush &brush)
114 {
116 {
115 foreach (QGraphicsItem *item, shadeItems())
117 foreach (QGraphicsItem *item, shadeItems())
116 static_cast<QGraphicsPathItem *>(item)->setBrush(brush);
118 static_cast<QGraphicsPathItem *>(item)->setBrush(brush);
117 }
119 }
118
120
119 void PolarChartAxis::handleShadesPenChanged(const QPen &pen)
121 void PolarChartAxis::handleShadesPenChanged(const QPen &pen)
120 {
122 {
121 foreach (QGraphicsItem *item, shadeItems())
123 foreach (QGraphicsItem *item, shadeItems())
122 static_cast<QGraphicsPathItem *>(item)->setPen(pen);
124 static_cast<QGraphicsPathItem *>(item)->setPen(pen);
123 }
125 }
124
126
125 #include "moc_polarchartaxis_p.cpp"
127 #include "moc_polarchartaxis_p.cpp"
126
128
127 QT_CHARTS_END_NAMESPACE
129 QT_CHARTS_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now