##// END OF EJS Templates
Work-around for a bug in Clang compiler
Tero Ahola -
r946:fd78c1dee939
parent child
Show More
@@ -1,134 +1,140
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "splinechartitem_p.h"
21 #include "splinechartitem_p.h"
22 #include "qsplineseries_p.h"
22 #include "qsplineseries_p.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
24 #include "chartanimator_p.h"
25 #include <QPainter>
25 #include <QPainter>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 SplineChartItem::SplineChartItem(QSplineSeries *series, ChartPresenter *presenter) :
29 SplineChartItem::SplineChartItem(QSplineSeries *series, ChartPresenter *presenter) :
30 XYChartItem(series, presenter),
30 XYChartItem(series, presenter),
31 m_series(series),
31 m_series(series),
32 m_pointsVisible(false)
32 m_pointsVisible(false)
33 {
33 {
34 setZValue(ChartPresenter::LineChartZValue);
34 setZValue(ChartPresenter::LineChartZValue);
35 QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated()));
35 QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated()));
36 handleUpdated();
36 handleUpdated();
37 }
37 }
38
38
39 QRectF SplineChartItem::boundingRect() const
39 QRectF SplineChartItem::boundingRect() const
40 {
40 {
41 return m_rect;
41 return m_rect;
42 }
42 }
43
43
44 QPainterPath SplineChartItem::shape() const
44 QPainterPath SplineChartItem::shape() const
45 {
45 {
46 return m_path;
46 return m_path;
47 }
47 }
48
48
49 void SplineChartItem::updateLayout(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index)
49 void SplineChartItem::updateLayout(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index)
50 {
50 {
51 QVector<QPointF> controlPoints;
51 QVector<QPointF> controlPoints;
52
52
53 controlPoints.resize(newPoints.count()*2-2);
53 controlPoints.resize(newPoints.count()*2-2);
54
54
55 for (int i = 0; i < newPoints.size() - 1; i++) {
55 for (int i = 0; i < newPoints.size() - 1; i++) {
56 controlPoints[2*i] = calculateGeometryControlPoint(2 * i);
56 controlPoints[2*i] = calculateGeometryControlPoint(2 * i);
57 controlPoints[2 * i + 1] = calculateGeometryControlPoint(2 * i + 1);
57 controlPoints[2 * i + 1] = calculateGeometryControlPoint(2 * i + 1);
58 }
58 }
59
59
60 if (controlPoints.count()<2) {
60 if (controlPoints.count()<2) {
61 setLayout(newPoints,controlPoints);
61 setLayout(newPoints,controlPoints);
62 return;
62 return;
63 }
63 }
64
64
65 if (animator()) {
65 if (animator()) {
66 animator()->updateLayout(this,oldPoints,newPoints,m_controlPoints,controlPoints,index);
66 animator()->updateLayout(this,oldPoints,newPoints,m_controlPoints,controlPoints,index);
67 } else {
67 } else {
68 setLayout(newPoints,controlPoints);
68 setLayout(newPoints,controlPoints);
69 }
69 }
70 }
70 }
71
71
72 QPointF SplineChartItem::calculateGeometryControlPoint(int index) const
72 QPointF SplineChartItem::calculateGeometryControlPoint(int index) const
73 {
73 {
74 return XYChartItem::calculateGeometryPoint(m_series->controlPoint(index));
74 return XYChartItem::calculateGeometryPoint(m_series->controlPoint(index));
75 }
75 }
76
76
77 void SplineChartItem::setLayout(QVector<QPointF> &points)
78 {
79 // Dummy implementation because of a bug in Clang compiler
80 XYChartItem::setLayout(points);
81 }
82
77 void SplineChartItem::setLayout(QVector<QPointF> &points, QVector<QPointF> &controlPoints)
83 void SplineChartItem::setLayout(QVector<QPointF> &points, QVector<QPointF> &controlPoints)
78 {
84 {
79 if ((points.size()<2) || (controlPoints.size()<2)) {
85 if ((points.size()<2) || (controlPoints.size()<2)) {
80 XYChartItem::setLayout(points);
86 XYChartItem::setLayout(points);
81 m_controlPoints=controlPoints;
87 m_controlPoints=controlPoints;
82 return;
88 return;
83 }
89 }
84
90
85 Q_ASSERT(points.count()*2-2 == controlPoints.count());
91 Q_ASSERT(points.count()*2-2 == controlPoints.count());
86
92
87 QPainterPath splinePath(points.at(0));
93 QPainterPath splinePath(points.at(0));
88
94
89 for (int i = 0; i < points.size() - 1; i++) {
95 for (int i = 0; i < points.size() - 1; i++) {
90 const QPointF& point = points.at(i + 1);
96 const QPointF& point = points.at(i + 1);
91 splinePath.cubicTo(controlPoints[2*i],controlPoints[2 * i + 1],point);
97 splinePath.cubicTo(controlPoints[2*i],controlPoints[2 * i + 1],point);
92 }
98 }
93
99
94 prepareGeometryChange();
100 prepareGeometryChange();
95 m_path = splinePath;
101 m_path = splinePath;
96 m_rect = splinePath.boundingRect();
102 m_rect = splinePath.boundingRect();
97 XYChartItem::setLayout(points);
103 XYChartItem::setLayout(points);
98 m_controlPoints=controlPoints;
104 m_controlPoints=controlPoints;
99 }
105 }
100
106
101 //handlers
107 //handlers
102
108
103 void SplineChartItem::handleUpdated()
109 void SplineChartItem::handleUpdated()
104 {
110 {
105 m_pointsVisible = m_series->pointsVisible();
111 m_pointsVisible = m_series->pointsVisible();
106 m_linePen = m_series->pen();
112 m_linePen = m_series->pen();
107 m_pointPen = m_series->pen();
113 m_pointPen = m_series->pen();
108 m_pointPen.setWidthF(2*m_pointPen.width());
114 m_pointPen.setWidthF(2*m_pointPen.width());
109 update();
115 update();
110 }
116 }
111
117
112 //painter
118 //painter
113
119
114 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
120 void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
115 {
121 {
116 Q_UNUSED(widget)
122 Q_UNUSED(widget)
117 Q_UNUSED(option)
123 Q_UNUSED(option)
118
124
119 painter->save();
125 painter->save();
120 painter->setClipRect(clipRect());
126 painter->setClipRect(clipRect());
121 painter->setPen(m_linePen);
127 painter->setPen(m_linePen);
122 painter->drawPath(m_path);
128 painter->drawPath(m_path);
123 if (m_pointsVisible) {
129 if (m_pointsVisible) {
124 painter->setPen(m_pointPen);
130 painter->setPen(m_pointPen);
125 painter->drawPoints(points());
131 painter->drawPoints(points());
126 }
132 }
127 painter->restore();
133 painter->restore();
128 }
134 }
129
135
130
136
131
137
132 #include "moc_splinechartitem_p.cpp"
138 #include "moc_splinechartitem_p.cpp"
133
139
134 QTCOMMERCIALCHART_END_NAMESPACE
140 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,64 +1,65
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef SPLINECHARTITEM_P_H
21 #ifndef SPLINECHARTITEM_P_H
22 #define SPLINECHARTITEM_P_H
22 #define SPLINECHARTITEM_P_H
23
23
24 #include "qsplineseries.h"
24 #include "qsplineseries.h"
25 #include "xychartitem_p.h"
25 #include "xychartitem_p.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class SplineChartItem : public XYChartItem
29 class SplineChartItem : public XYChartItem
30 {
30 {
31 Q_OBJECT
31 Q_OBJECT
32 public:
32 public:
33 SplineChartItem(QSplineSeries *series, ChartPresenter *presenter);
33 SplineChartItem(QSplineSeries *series, ChartPresenter *presenter);
34
34
35 //from QGraphicsItem
35 //from QGraphicsItem
36 QRectF boundingRect() const;
36 QRectF boundingRect() const;
37 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
37 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
38 QPainterPath shape() const;
38 QPainterPath shape() const;
39
39
40 public Q_SLOTS:
40 public Q_SLOTS:
41 void handleUpdated();
41 void handleUpdated();
42
42
43 protected:
43 protected:
44 void setLayout(QVector<QPointF> &points);
44 void setLayout(QVector<QPointF> &points,QVector<QPointF> &controlPoints);
45 void setLayout(QVector<QPointF> &points,QVector<QPointF> &controlPoints);
45 void updateLayout(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index);
46 void updateLayout(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index);
46
47
47 private:
48 private:
48 QPointF calculateGeometryControlPoint(int index) const;
49 QPointF calculateGeometryControlPoint(int index) const;
49
50
50 private:
51 private:
51 QSplineSeries* m_series;
52 QSplineSeries* m_series;
52 QPainterPath m_path;
53 QPainterPath m_path;
53 QRectF m_rect;
54 QRectF m_rect;
54 QPen m_linePen;
55 QPen m_linePen;
55 QPen m_pointPen;
56 QPen m_pointPen;
56 bool m_pointsVisible;
57 bool m_pointsVisible;
57 QVector<QPointF> m_controlPoints;
58 QVector<QPointF> m_controlPoints;
58
59
59 friend class SplineAnimation;
60 friend class SplineAnimation;
60 };
61 };
61
62
62 QTCOMMERCIALCHART_END_NAMESPACE
63 QTCOMMERCIALCHART_END_NAMESPACE
63
64
64 #endif // SPLINECHARTITEM_P_H
65 #endif // SPLINECHARTITEM_P_H
General Comments 0
You need to be logged in to leave comments. Login now