@@ -0,0 +1,72 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | // W A R N I N G | |||
|
22 | // ------------- | |||
|
23 | // | |||
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |||
|
25 | // implementation detail. This header file may change from version to | |||
|
26 | // version without notice, or even be removed. | |||
|
27 | // | |||
|
28 | // We mean it. | |||
|
29 | ||||
|
30 | ||||
|
31 | #ifndef LEGENDSCROLLER_P_H_ | |||
|
32 | #define LEGENDSCROLLER_P_H_ | |||
|
33 | ||||
|
34 | #include "qlegend.h" | |||
|
35 | #include "scroller_p.h" | |||
|
36 | ||||
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
38 | ||||
|
39 | class LegendScroller: public QLegend, public Scroller | |||
|
40 | { | |||
|
41 | ||||
|
42 | public: | |||
|
43 | LegendScroller(QChart *chart):QLegend(chart) | |||
|
44 | { | |||
|
45 | } | |||
|
46 | ||||
|
47 | void setOffset(const QPointF& point) | |||
|
48 | { | |||
|
49 | QLegend::setOffset(point); | |||
|
50 | } | |||
|
51 | QPointF offset() const | |||
|
52 | { | |||
|
53 | return QLegend::offset(); | |||
|
54 | } | |||
|
55 | ||||
|
56 | void mousePressEvent(QGraphicsSceneMouseEvent* event){ | |||
|
57 | Scroller::mousePressEvent(event); | |||
|
58 | //QLegend::mousePressEvent(event); | |||
|
59 | } | |||
|
60 | void mouseMoveEvent(QGraphicsSceneMouseEvent* event){ | |||
|
61 | Scroller::mouseMoveEvent(event); | |||
|
62 | //QLegend::mouseMoveEvent(event); | |||
|
63 | } | |||
|
64 | void mouseReleaseEvent(QGraphicsSceneMouseEvent* event){ | |||
|
65 | Scroller::mouseReleaseEvent(event); | |||
|
66 | //QLegend::mouseReleaseEvent(event); | |||
|
67 | } | |||
|
68 | }; | |||
|
69 | ||||
|
70 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
71 | ||||
|
72 | #endif |
@@ -0,0 +1,76 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | // W A R N I N G | |||
|
22 | // ------------- | |||
|
23 | // | |||
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |||
|
25 | // implementation detail. This header file may change from version to | |||
|
26 | // version without notice, or even be removed. | |||
|
27 | // | |||
|
28 | // We mean it. | |||
|
29 | ||||
|
30 | #ifndef QLEGEND_P_H_ | |||
|
31 | #define QLEGEND_P_H_ | |||
|
32 | ||||
|
33 | #include "qlegend.h" | |||
|
34 | ||||
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
36 | ||||
|
37 | class ChartPresenter; | |||
|
38 | ||||
|
39 | class QLegendPrivate : public QObject | |||
|
40 | { | |||
|
41 | Q_OBJECT | |||
|
42 | public: | |||
|
43 | QLegendPrivate(ChartPresenter *chart,QLegend *q); | |||
|
44 | ~QLegendPrivate(); | |||
|
45 | ||||
|
46 | void setOffset(qreal x, qreal y); | |||
|
47 | void updateLayout(); | |||
|
48 | ||||
|
49 | public Q_SLOTS: | |||
|
50 | void handleSeriesAdded(QSeries *series, Domain *domain); | |||
|
51 | void handleSeriesRemoved(QSeries *series); | |||
|
52 | ||||
|
53 | private: | |||
|
54 | QLegend *q_ptr; | |||
|
55 | ChartPresenter *m_presenter; | |||
|
56 | QGraphicsItemGroup* m_markers; | |||
|
57 | QLegend::Alignments m_alignment; | |||
|
58 | QBrush m_brush; | |||
|
59 | QPen m_pen; | |||
|
60 | QRectF m_rect; | |||
|
61 | qreal m_offsetX; | |||
|
62 | qreal m_offsetY; | |||
|
63 | qreal m_minWidth; | |||
|
64 | qreal m_minHeight; | |||
|
65 | qreal m_width; | |||
|
66 | qreal m_height; | |||
|
67 | bool m_attachedToChart; | |||
|
68 | bool m_backgroundVisible; | |||
|
69 | ||||
|
70 | friend class QLegend; | |||
|
71 | ||||
|
72 | }; | |||
|
73 | ||||
|
74 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
75 | ||||
|
76 | #endif |
@@ -1,267 +1,275 | |||||
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 "qareaseries.h" |
|
21 | #include "qareaseries.h" | |
22 | #include "qareaseries_p.h" |
|
22 | #include "qareaseries_p.h" | |
23 | #include "qlineseries.h" |
|
23 | #include "qlineseries.h" | |
24 | #include "areachartitem_p.h" |
|
24 | #include "areachartitem_p.h" | |
|
25 | #include "legendmarker_p.h" | |||
25 | #include "domain_p.h" |
|
26 | #include "domain_p.h" | |
26 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
27 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
28 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
29 |
|
30 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
32 | |||
32 | /*! |
|
33 | /*! | |
33 | \class QAreaSeries |
|
34 | \class QAreaSeries | |
34 | \brief The QAreaSeries class is used for making area charts. |
|
35 | \brief The QAreaSeries class is used for making area charts. | |
35 |
|
36 | |||
36 | \mainclass |
|
37 | \mainclass | |
37 |
|
38 | |||
38 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line |
|
39 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line | |
39 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, |
|
40 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, | |
40 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. |
|
41 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. | |
41 | In that case QAreaSeries should be initiated with two QLineSerie instances. Please note terms "upper" and "lower" boundary can be misleading in cases |
|
42 | In that case QAreaSeries should be initiated with two QLineSerie instances. Please note terms "upper" and "lower" boundary can be misleading in cases | |
42 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. |
|
43 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. | |
43 |
|
44 | |||
44 | \image areachart.png |
|
45 | \image areachart.png | |
45 |
|
46 | |||
46 | Creating basic area chart is simple: |
|
47 | Creating basic area chart is simple: | |
47 | \code |
|
48 | \code | |
48 | QLineSeries* lineSeries = new QLineSeries(); |
|
49 | QLineSeries* lineSeries = new QLineSeries(); | |
49 | series->append(0, 6); |
|
50 | series->append(0, 6); | |
50 | series->append(2, 4); |
|
51 | series->append(2, 4); | |
51 | QAreaSeries* areaSeries = new QAreaSeries(lineSeries); |
|
52 | QAreaSeries* areaSeries = new QAreaSeries(lineSeries); | |
52 | ... |
|
53 | ... | |
53 | chartView->addSeries(areaSeries); |
|
54 | chartView->addSeries(areaSeries); | |
54 | \endcode |
|
55 | \endcode | |
55 | */ |
|
56 | */ | |
56 |
|
57 | |||
57 | /*! |
|
58 | /*! | |
58 | \fn virtual QSeriesType QAreaSeries::type() const |
|
59 | \fn virtual QSeriesType QAreaSeries::type() const | |
59 | \brief Returns type of series. |
|
60 | \brief Returns type of series. | |
60 | \sa QSeries, QSeriesType |
|
61 | \sa QSeries, QSeriesType | |
61 | */ |
|
62 | */ | |
62 |
|
63 | |||
63 | /*! |
|
64 | /*! | |
64 | \fn QLineSeries* QAreaSeries::upperSeries() const |
|
65 | \fn QLineSeries* QAreaSeries::upperSeries() const | |
65 | \brief Returns upperSeries used to define one of area boundaries. |
|
66 | \brief Returns upperSeries used to define one of area boundaries. | |
66 | */ |
|
67 | */ | |
67 |
|
68 | |||
68 | /*! |
|
69 | /*! | |
69 | \fn QLineSeries* QAreaSeries::lowerSeries() const |
|
70 | \fn QLineSeries* QAreaSeries::lowerSeries() const | |
70 | \brief Returns lowerSeries used to define one of area boundaries. Note if QAreaSeries where counstucted wihtout a\ lowerSeries |
|
71 | \brief Returns lowerSeries used to define one of area boundaries. Note if QAreaSeries where counstucted wihtout a\ lowerSeries | |
71 | this function return Null pointer. |
|
72 | this function return Null pointer. | |
72 | */ |
|
73 | */ | |
73 |
|
74 | |||
74 | /*! |
|
75 | /*! | |
75 | \fn QPen QAreaSeries::pen() const |
|
76 | \fn QPen QAreaSeries::pen() const | |
76 | \brief Returns the pen used to draw line for this series. |
|
77 | \brief Returns the pen used to draw line for this series. | |
77 | \sa setPen() |
|
78 | \sa setPen() | |
78 | */ |
|
79 | */ | |
79 |
|
80 | |||
80 | /*! |
|
81 | /*! | |
81 | \fn QPen QAreaSeries::brush() const |
|
82 | \fn QPen QAreaSeries::brush() const | |
82 | \brief Returns the brush used to draw line for this series. |
|
83 | \brief Returns the brush used to draw line for this series. | |
83 | \sa setBrush() |
|
84 | \sa setBrush() | |
84 | */ |
|
85 | */ | |
85 |
|
86 | |||
86 | /*! |
|
87 | /*! | |
87 | \fn bool QAreaSeries::pointsVisible() const |
|
88 | \fn bool QAreaSeries::pointsVisible() const | |
88 | \brief Returns if the points are drawn for this series. |
|
89 | \brief Returns if the points are drawn for this series. | |
89 | \sa setPointsVisible() |
|
90 | \sa setPointsVisible() | |
90 | */ |
|
91 | */ | |
91 |
|
92 | |||
92 | /*! |
|
93 | /*! | |
93 | \fn void QAreaSeries::clicked(const QPointF& point) |
|
94 | \fn void QAreaSeries::clicked(const QPointF& point) | |
94 | \brief Signal is emitted when user clicks the \a point on area chart. |
|
95 | \brief Signal is emitted when user clicks the \a point on area chart. | |
95 | */ |
|
96 | */ | |
96 |
|
97 | |||
97 | /*! |
|
98 | /*! | |
98 | \fn void QAreaSeriesPrivate::updated() |
|
99 | \fn void QAreaSeriesPrivate::updated() | |
99 | \brief \internal |
|
100 | \brief \internal | |
100 | */ |
|
101 | */ | |
101 |
|
102 | |||
102 | /*! |
|
103 | /*! | |
103 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a |
|
104 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a | |
104 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. |
|
105 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. | |
105 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
106 | When series object is added to QChartView or QChart instance ownerships is transfered. | |
106 | */ |
|
107 | */ | |
107 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
|
108 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) | |
108 | : QSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries) |
|
109 | : QSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries) | |
109 | { |
|
110 | { | |
110 | } |
|
111 | } | |
111 |
|
112 | |||
112 | /*! |
|
113 | /*! | |
113 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
114 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
114 | and are deleted when mentioned object are destroyed. |
|
115 | and are deleted when mentioned object are destroyed. | |
115 | */ |
|
116 | */ | |
116 | QAreaSeries::~QAreaSeries() |
|
117 | QAreaSeries::~QAreaSeries() | |
117 | { |
|
118 | { | |
118 | } |
|
119 | } | |
119 |
|
120 | |||
120 |
|
121 | |||
121 | QSeries::QSeriesType QAreaSeries::type() const |
|
122 | QSeries::QSeriesType QAreaSeries::type() const | |
122 | { |
|
123 | { | |
123 | return QSeries::SeriesTypeArea; |
|
124 | return QSeries::SeriesTypeArea; | |
124 | } |
|
125 | } | |
125 |
|
126 | |||
126 | QLineSeries* QAreaSeries::upperSeries() const |
|
127 | QLineSeries* QAreaSeries::upperSeries() const | |
127 | { |
|
128 | { | |
128 | Q_D(const QAreaSeries); |
|
129 | Q_D(const QAreaSeries); | |
129 | return d->m_upperSeries; |
|
130 | return d->m_upperSeries; | |
130 | } |
|
131 | } | |
131 |
|
132 | |||
132 | QLineSeries* QAreaSeries::lowerSeries() const |
|
133 | QLineSeries* QAreaSeries::lowerSeries() const | |
133 | { |
|
134 | { | |
134 | Q_D(const QAreaSeries); |
|
135 | Q_D(const QAreaSeries); | |
135 | return d->m_lowerSeries; |
|
136 | return d->m_lowerSeries; | |
136 | } |
|
137 | } | |
137 |
|
138 | |||
138 | /*! |
|
139 | /*! | |
139 | Sets \a pen used for drawing area outline. |
|
140 | Sets \a pen used for drawing area outline. | |
140 | */ |
|
141 | */ | |
141 | void QAreaSeries::setPen(const QPen &pen) |
|
142 | void QAreaSeries::setPen(const QPen &pen) | |
142 | { |
|
143 | { | |
143 | Q_D(QAreaSeries); |
|
144 | Q_D(QAreaSeries); | |
144 | if (d->m_pen != pen) { |
|
145 | if (d->m_pen != pen) { | |
145 | d->m_pen = pen; |
|
146 | d->m_pen = pen; | |
146 | emit d->updated(); |
|
147 | emit d->updated(); | |
147 | } |
|
148 | } | |
148 | } |
|
149 | } | |
149 |
|
150 | |||
150 | QPen QAreaSeries::pen() const |
|
151 | QPen QAreaSeries::pen() const | |
151 | { |
|
152 | { | |
152 | Q_D(const QAreaSeries); |
|
153 | Q_D(const QAreaSeries); | |
153 | return d->m_pen; |
|
154 | return d->m_pen; | |
154 | } |
|
155 | } | |
155 |
|
156 | |||
156 | /*! |
|
157 | /*! | |
157 | Sets \a brush used for filling the area. |
|
158 | Sets \a brush used for filling the area. | |
158 | */ |
|
159 | */ | |
159 | void QAreaSeries::setBrush(const QBrush &brush) |
|
160 | void QAreaSeries::setBrush(const QBrush &brush) | |
160 | { |
|
161 | { | |
161 | Q_D(QAreaSeries); |
|
162 | Q_D(QAreaSeries); | |
162 | if (d->m_brush != brush) { |
|
163 | if (d->m_brush != brush) { | |
163 | d->m_brush = brush; |
|
164 | d->m_brush = brush; | |
164 | emit d->updated(); |
|
165 | emit d->updated(); | |
165 | } |
|
166 | } | |
166 | } |
|
167 | } | |
167 |
|
168 | |||
168 | QBrush QAreaSeries::brush() const |
|
169 | QBrush QAreaSeries::brush() const | |
169 | { |
|
170 | { | |
170 | Q_D(const QAreaSeries); |
|
171 | Q_D(const QAreaSeries); | |
171 | return d->m_brush; |
|
172 | return d->m_brush; | |
172 | } |
|
173 | } | |
173 | /*! |
|
174 | /*! | |
174 | Sets if data points are \a visible and should be drawn on line. |
|
175 | Sets if data points are \a visible and should be drawn on line. | |
175 | */ |
|
176 | */ | |
176 | void QAreaSeries::setPointsVisible(bool visible) |
|
177 | void QAreaSeries::setPointsVisible(bool visible) | |
177 | { |
|
178 | { | |
178 | Q_D(QAreaSeries); |
|
179 | Q_D(QAreaSeries); | |
179 | if (d->m_pointsVisible != visible) { |
|
180 | if (d->m_pointsVisible != visible) { | |
180 | d->m_pointsVisible = visible; |
|
181 | d->m_pointsVisible = visible; | |
181 | emit d->updated(); |
|
182 | emit d->updated(); | |
182 | } |
|
183 | } | |
183 | } |
|
184 | } | |
184 |
|
185 | |||
185 | bool QAreaSeries::pointsVisible() const |
|
186 | bool QAreaSeries::pointsVisible() const | |
186 | { |
|
187 | { | |
187 | Q_D(const QAreaSeries); |
|
188 | Q_D(const QAreaSeries); | |
188 | return d->m_pointsVisible; |
|
189 | return d->m_pointsVisible; | |
189 | } |
|
190 | } | |
190 |
|
191 | |||
191 | bool QAreaSeries::setModel(QAbstractItemModel* model) |
|
192 | bool QAreaSeries::setModel(QAbstractItemModel* model) | |
192 | { |
|
193 | { | |
193 | Q_UNUSED(model); |
|
194 | Q_UNUSED(model); | |
194 | qWarning()<<"Not implemented"; |
|
195 | qWarning()<<"Not implemented"; | |
195 | return false; |
|
196 | return false; | |
196 | } |
|
197 | } | |
197 |
|
198 | |||
198 | QAbstractItemModel* QAreaSeries::model() const |
|
199 | QAbstractItemModel* QAreaSeries::model() const | |
199 | { |
|
200 | { | |
200 | return 0; |
|
201 | return 0; | |
201 | } |
|
202 | } | |
202 |
|
203 | |||
203 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
204 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
204 |
|
205 | |||
205 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q):QSeriesPrivate(q), |
|
206 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q):QSeriesPrivate(q), | |
206 | m_upperSeries(upperSeries), |
|
207 | m_upperSeries(upperSeries), | |
207 | m_lowerSeries(lowerSeries), |
|
208 | m_lowerSeries(lowerSeries), | |
208 | m_pointsVisible(false) |
|
209 | m_pointsVisible(false) | |
209 | { |
|
210 | { | |
210 |
|
211 | |||
211 | }; |
|
212 | }; | |
212 |
|
213 | |||
213 | void QAreaSeriesPrivate::scaleDomain(Domain& domain) |
|
214 | void QAreaSeriesPrivate::scaleDomain(Domain& domain) | |
214 | { |
|
215 | { | |
215 | Q_Q(QAreaSeries); |
|
216 | Q_Q(QAreaSeries); | |
216 |
|
217 | |||
217 | qreal minX(domain.minX()); |
|
218 | qreal minX(domain.minX()); | |
218 | qreal minY(domain.minY()); |
|
219 | qreal minY(domain.minY()); | |
219 | qreal maxX(domain.maxX()); |
|
220 | qreal maxX(domain.maxX()); | |
220 | qreal maxY(domain.maxY()); |
|
221 | qreal maxY(domain.maxY()); | |
221 | int tickXCount(domain.tickXCount()); |
|
222 | int tickXCount(domain.tickXCount()); | |
222 | int tickYCount(domain.tickYCount()); |
|
223 | int tickYCount(domain.tickYCount()); | |
223 |
|
224 | |||
224 | QLineSeries* upperSeries = q->upperSeries(); |
|
225 | QLineSeries* upperSeries = q->upperSeries(); | |
225 | QLineSeries* lowerSeries = q->lowerSeries(); |
|
226 | QLineSeries* lowerSeries = q->lowerSeries(); | |
226 |
|
227 | |||
227 | for (int i = 0; i < upperSeries->count(); i++) |
|
228 | for (int i = 0; i < upperSeries->count(); i++) | |
228 | { |
|
229 | { | |
229 | qreal x = upperSeries->x(i); |
|
230 | qreal x = upperSeries->x(i); | |
230 | qreal y = upperSeries->y(i); |
|
231 | qreal y = upperSeries->y(i); | |
231 | minX = qMin(minX, x); |
|
232 | minX = qMin(minX, x); | |
232 | minY = qMin(minY, y); |
|
233 | minY = qMin(minY, y); | |
233 | maxX = qMax(maxX, x); |
|
234 | maxX = qMax(maxX, x); | |
234 | maxY = qMax(maxY, y); |
|
235 | maxY = qMax(maxY, y); | |
235 | } |
|
236 | } | |
236 | if(lowerSeries) { |
|
237 | if(lowerSeries) { | |
237 | for (int i = 0; i < lowerSeries->count(); i++) |
|
238 | for (int i = 0; i < lowerSeries->count(); i++) | |
238 | { |
|
239 | { | |
239 | qreal x = lowerSeries->x(i); |
|
240 | qreal x = lowerSeries->x(i); | |
240 | qreal y = lowerSeries->y(i); |
|
241 | qreal y = lowerSeries->y(i); | |
241 | minX = qMin(minX, x); |
|
242 | minX = qMin(minX, x); | |
242 | minY = qMin(minY, y); |
|
243 | minY = qMin(minY, y); | |
243 | maxX = qMax(maxX, x); |
|
244 | maxX = qMax(maxX, x); | |
244 | maxY = qMax(maxY, y); |
|
245 | maxY = qMax(maxY, y); | |
245 | }} |
|
246 | }} | |
246 |
|
247 | |||
247 | domain.setRangeX(minX,maxX,tickXCount); |
|
248 | domain.setRangeX(minX,maxX,tickXCount); | |
248 | domain.setRangeY(minY,maxY,tickYCount); |
|
249 | domain.setRangeY(minY,maxY,tickYCount); | |
249 | } |
|
250 | } | |
250 |
|
251 | |||
251 | Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
252 | Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
252 | { |
|
253 | { | |
253 | Q_Q(QAreaSeries); |
|
254 | Q_Q(QAreaSeries); | |
254 |
|
255 | |||
255 | AreaChartItem* area = new AreaChartItem(q,presenter); |
|
256 | AreaChartItem* area = new AreaChartItem(q,presenter); | |
256 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
257 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
257 | presenter->animator()->addAnimation(area->upperLineItem()); |
|
258 | presenter->animator()->addAnimation(area->upperLineItem()); | |
258 | if(q->lowerSeries()) presenter->animator()->addAnimation(area->lowerLineItem()); |
|
259 | if(q->lowerSeries()) presenter->animator()->addAnimation(area->lowerLineItem()); | |
259 | } |
|
260 | } | |
260 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
261 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
261 | return area; |
|
262 | return area; | |
262 | } |
|
263 | } | |
263 |
|
264 | |||
|
265 | QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend) | |||
|
266 | { | |||
|
267 | Q_Q(QAreaSeries); | |||
|
268 | QList<LegendMarker*> list; | |||
|
269 | return list << new AreaLegendMarker(q,legend); | |||
|
270 | } | |||
|
271 | ||||
264 | #include "moc_qareaseries.cpp" |
|
272 | #include "moc_qareaseries.cpp" | |
265 | #include "moc_qareaseries_p.cpp" |
|
273 | #include "moc_qareaseries_p.cpp" | |
266 |
|
274 | |||
267 | QTCOMMERCIALCHART_END_NAMESPACE |
|
275 | 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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QAREASERIES_P_H_ |
|
30 | #ifndef QAREASERIES_P_H_ | |
31 | #define QAREASERIES_P_H_ |
|
31 | #define QAREASERIES_P_H_ | |
32 |
|
32 | |||
33 | #include "qseries_p.h" |
|
33 | #include "qseries_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAreaSeries; |
|
37 | class QAreaSeries; | |
38 |
|
38 | |||
39 | class QAreaSeriesPrivate: public QSeriesPrivate |
|
39 | class QAreaSeriesPrivate: public QSeriesPrivate | |
40 | { |
|
40 | { | |
41 | Q_OBJECT |
|
41 | Q_OBJECT | |
42 |
|
42 | |||
43 | public: |
|
43 | public: | |
44 | QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q); |
|
44 | QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q); | |
45 |
|
45 | |||
46 | void scaleDomain(Domain& domain); |
|
46 | void scaleDomain(Domain& domain); | |
47 | Chart* createGraphics(ChartPresenter* presenter); |
|
47 | Chart* createGraphics(ChartPresenter* presenter); | |
|
48 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |||
48 |
|
49 | |||
49 | Q_SIGNALS: |
|
50 | Q_SIGNALS: | |
50 | void updated(); |
|
51 | void updated(); | |
51 |
|
52 | |||
52 | protected: |
|
53 | protected: | |
53 | QBrush m_brush; |
|
54 | QBrush m_brush; | |
54 | QPen m_pen; |
|
55 | QPen m_pen; | |
55 | QLineSeries* m_upperSeries; |
|
56 | QLineSeries* m_upperSeries; | |
56 | QLineSeries* m_lowerSeries; |
|
57 | QLineSeries* m_lowerSeries; | |
57 | bool m_pointsVisible; |
|
58 | bool m_pointsVisible; | |
58 | private: |
|
59 | private: | |
59 | Q_DECLARE_PUBLIC(QAreaSeries); |
|
60 | Q_DECLARE_PUBLIC(QAreaSeries); | |
60 | }; |
|
61 | }; | |
61 |
|
62 | |||
62 | QTCOMMERCIALCHART_END_NAMESPACE |
|
63 | QTCOMMERCIALCHART_END_NAMESPACE | |
63 |
|
64 | |||
64 | #endif |
|
65 | #endif |
@@ -1,811 +1,824 | |||||
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 "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "barchartmodel_p.h" |
|
25 | #include "barchartmodel_p.h" | |
26 | #include "domain_p.h" |
|
26 | #include "domain_p.h" | |
|
27 | #include "legendmarker_p.h" | |||
27 | #include "chartdataset_p.h" |
|
28 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
29 | #include "charttheme_p.h" | |
29 | #include "chartanimator_p.h" |
|
30 | #include "chartanimator_p.h" | |
30 |
|
31 | |||
31 | #include <QAbstractItemModel> |
|
32 | #include <QAbstractItemModel> | |
32 | #include <QModelIndex> |
|
33 | #include <QModelIndex> | |
33 |
|
34 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
36 | |||
36 | /*! |
|
37 | /*! | |
37 | \class QBarSeries |
|
38 | \class QBarSeries | |
38 | \brief part of QtCommercial chart API. |
|
39 | \brief part of QtCommercial chart API. | |
39 |
|
40 | |||
40 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible |
|
41 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible | |
41 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
42 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
42 | by QStringList. |
|
43 | by QStringList. | |
43 |
|
44 | |||
44 | \mainclass |
|
45 | \mainclass | |
45 |
|
46 | |||
46 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
47 | */ |
|
48 | */ | |
48 |
|
49 | |||
49 | /*! |
|
50 | /*! | |
50 | \fn virtual QSeriesType QBarSeries::type() const |
|
51 | \fn virtual QSeriesType QBarSeries::type() const | |
51 | \brief Returns type of series. |
|
52 | \brief Returns type of series. | |
52 | \sa QSeries, QSeriesType |
|
53 | \sa QSeries, QSeriesType | |
53 | */ |
|
54 | */ | |
54 |
|
55 | |||
55 | /*! |
|
56 | /*! | |
56 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) |
|
57 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | |
57 | \brief \internal \a pos \a tip |
|
58 | \brief \internal \a pos \a tip | |
58 | */ |
|
59 | */ | |
59 |
|
60 | |||
60 | /*! |
|
61 | /*! | |
61 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
62 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
62 | QBarSeries is QObject which is a child of a \a parent. |
|
63 | QBarSeries is QObject which is a child of a \a parent. | |
63 | */ |
|
64 | */ | |
64 |
|
65 | |||
65 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(*new QBarSeriesPrivate(categories, this),parent) |
|
66 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(*new QBarSeriesPrivate(categories, this),parent) | |
66 | { |
|
67 | { | |
67 |
|
68 | |||
68 | } |
|
69 | } | |
69 |
|
70 | |||
70 | QBarSeries::QBarSeries(QBarSeriesPrivate &d,QObject *parent) : QSeries(d,parent) |
|
71 | QBarSeries::QBarSeries(QBarSeriesPrivate &d,QObject *parent) : QSeries(d,parent) | |
71 | { |
|
72 | { | |
72 |
|
73 | |||
73 | } |
|
74 | } | |
74 |
|
75 | |||
75 | QSeries::QSeriesType QBarSeries::type() const |
|
76 | QSeries::QSeriesType QBarSeries::type() const | |
76 | { |
|
77 | { | |
77 | return QSeries::SeriesTypeBar; |
|
78 | return QSeries::SeriesTypeBar; | |
78 | } |
|
79 | } | |
79 |
|
80 | |||
80 | /*! |
|
81 | /*! | |
81 | Adds a set of bars to series. Takes ownership of \a set. |
|
82 | Adds a set of bars to series. Takes ownership of \a set. | |
82 | Connects the clicked(QString, Qt::MouseButtons) signal |
|
83 | Connects the clicked(QString, Qt::MouseButtons) signal | |
83 | of \a set to this series |
|
84 | of \a set to this series | |
84 | */ |
|
85 | */ | |
85 | void QBarSeries::appendBarSet(QBarSet *set) |
|
86 | void QBarSeries::appendBarSet(QBarSet *set) | |
86 | { |
|
87 | { | |
87 | Q_D(QBarSeries); |
|
88 | Q_D(QBarSeries); | |
88 | d->m_internalModel->appendBarSet(set); |
|
89 | d->m_internalModel->appendBarSet(set); | |
89 | QObject::connect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
90 | QObject::connect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
90 | QObject::connect(set->d_ptr.data(), SIGNAL(valueChanged()), d, SLOT(barsetChanged())); |
|
91 | QObject::connect(set->d_ptr.data(), SIGNAL(valueChanged()), d, SLOT(barsetChanged())); | |
91 | emit d->restructuredBars(); |
|
92 | emit d->restructuredBars(); | |
92 | } |
|
93 | } | |
93 |
|
94 | |||
94 | /*! |
|
95 | /*! | |
95 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
96 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | |
96 | Disconnects the clicked(QString, Qt::MouseButtons) signal |
|
97 | Disconnects the clicked(QString, Qt::MouseButtons) signal | |
97 | of \a set from this series |
|
98 | of \a set from this series | |
98 | */ |
|
99 | */ | |
99 | void QBarSeries::removeBarSet(QBarSet *set) |
|
100 | void QBarSeries::removeBarSet(QBarSet *set) | |
100 | { |
|
101 | { | |
101 | Q_D(QBarSeries); |
|
102 | Q_D(QBarSeries); | |
102 | QObject::disconnect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
103 | QObject::disconnect(set->d_ptr.data(), SIGNAL(clicked(QString,Qt::MouseButtons)), d, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
103 | d->m_internalModel->removeBarSet(set); |
|
104 | d->m_internalModel->removeBarSet(set); | |
104 | emit d->restructuredBars(); |
|
105 | emit d->restructuredBars(); | |
105 | } |
|
106 | } | |
106 |
|
107 | |||
107 | /*! |
|
108 | /*! | |
108 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
109 | Adds a list of barsets to series. Takes ownership of \a sets. | |
109 | Connects the clicked(QString, Qt::MouseButtons) signals |
|
110 | Connects the clicked(QString, Qt::MouseButtons) signals | |
110 | of \a sets to this series |
|
111 | of \a sets to this series | |
111 | */ |
|
112 | */ | |
112 | void QBarSeries::appendBarSets(QList<QBarSet* > sets) |
|
113 | void QBarSeries::appendBarSets(QList<QBarSet* > sets) | |
113 | { |
|
114 | { | |
114 | Q_D(QBarSeries); |
|
115 | Q_D(QBarSeries); | |
115 | foreach (QBarSet* barset, sets) { |
|
116 | foreach (QBarSet* barset, sets) { | |
116 | d->m_internalModel->appendBarSet(barset); |
|
117 | d->m_internalModel->appendBarSet(barset); | |
117 | QObject::connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
118 | QObject::connect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
118 | QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
119 | QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
119 | } |
|
120 | } | |
120 | emit d->restructuredBars(); |
|
121 | emit d->restructuredBars(); | |
121 |
|
122 | |||
122 | } |
|
123 | } | |
123 |
|
124 | |||
124 | /*! |
|
125 | /*! | |
125 | Removes a list of barsets from series. Releases ownership of \a sets. Doesnt delete \a sets. |
|
126 | Removes a list of barsets from series. Releases ownership of \a sets. Doesnt delete \a sets. | |
126 | Disconnects the clicked(QString, Qt::MouseButtons) signal |
|
127 | Disconnects the clicked(QString, Qt::MouseButtons) signal | |
127 | of \a sets from this series |
|
128 | of \a sets from this series | |
128 | */ |
|
129 | */ | |
129 | void QBarSeries::removeBarSets(QList<QBarSet* > sets) |
|
130 | void QBarSeries::removeBarSets(QList<QBarSet* > sets) | |
130 | { |
|
131 | { | |
131 | Q_D(QBarSeries); |
|
132 | Q_D(QBarSeries); | |
132 |
|
133 | |||
133 | foreach (QBarSet* barset, sets) { |
|
134 | foreach (QBarSet* barset, sets) { | |
134 | QObject::disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
135 | QObject::disconnect(barset, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
135 | d->m_internalModel->removeBarSet(barset); |
|
136 | d->m_internalModel->removeBarSet(barset); | |
136 | } |
|
137 | } | |
137 | emit d->restructuredBars(); |
|
138 | emit d->restructuredBars(); | |
138 | } |
|
139 | } | |
139 |
|
140 | |||
140 | /*! |
|
141 | /*! | |
141 | Inserts new \a set on the \a i position. |
|
142 | Inserts new \a set on the \a i position. | |
142 | The barset that is currently at this postion is moved to postion i + 1 |
|
143 | The barset that is currently at this postion is moved to postion i + 1 | |
143 | */ |
|
144 | */ | |
144 | void QBarSeries::insertBarSet(int i, QBarSet *set) |
|
145 | void QBarSeries::insertBarSet(int i, QBarSet *set) | |
145 | { |
|
146 | { | |
146 | Q_D(QBarSeries); |
|
147 | Q_D(QBarSeries); | |
147 | d->m_internalModel->insertBarSet(i, set); |
|
148 | d->m_internalModel->insertBarSet(i, set); | |
148 | emit d->barsetChanged(); |
|
149 | emit d->barsetChanged(); | |
149 | } |
|
150 | } | |
150 |
|
151 | |||
151 | /*! |
|
152 | /*! | |
152 | Inserts new \a category on the \a i position. |
|
153 | Inserts new \a category on the \a i position. | |
153 | The category that is currently at this postion is moved to postion i + 1 |
|
154 | The category that is currently at this postion is moved to postion i + 1 | |
154 | \sa removeCategory() |
|
155 | \sa removeCategory() | |
155 | */ |
|
156 | */ | |
156 | void QBarSeries::insertCategory(int i, QString category) |
|
157 | void QBarSeries::insertCategory(int i, QString category) | |
157 | { |
|
158 | { | |
158 | Q_D(QBarSeries); |
|
159 | Q_D(QBarSeries); | |
159 | d->m_internalModel->insertCategory(i, category); |
|
160 | d->m_internalModel->insertCategory(i, category); | |
160 | } |
|
161 | } | |
161 |
|
162 | |||
162 | /*! |
|
163 | /*! | |
163 | Removes the category specified by \a i |
|
164 | Removes the category specified by \a i | |
164 | \sa insertCategory() |
|
165 | \sa insertCategory() | |
165 | */ |
|
166 | */ | |
166 | void QBarSeries::removeCategory(int i) |
|
167 | void QBarSeries::removeCategory(int i) | |
167 | { |
|
168 | { | |
168 | Q_D(QBarSeries); |
|
169 | Q_D(QBarSeries); | |
169 | d->m_internalModel->removeCategory(i); |
|
170 | d->m_internalModel->removeCategory(i); | |
170 | } |
|
171 | } | |
171 |
|
172 | |||
172 | /*! |
|
173 | /*! | |
173 | Returns number of sets in series. |
|
174 | Returns number of sets in series. | |
174 | */ |
|
175 | */ | |
175 | int QBarSeries::barsetCount() const |
|
176 | int QBarSeries::barsetCount() const | |
176 | { |
|
177 | { | |
177 | Q_D(const QBarSeries); |
|
178 | Q_D(const QBarSeries); | |
178 | /* |
|
179 | /* | |
179 | // if(m_model) |
|
180 | // if(m_model) | |
180 | // return m_mapBarTop - m_mapBarBottom; |
|
181 | // return m_mapBarTop - m_mapBarBottom; | |
181 | // else |
|
182 | // else | |
182 |
|
183 | |||
183 | */ |
|
184 | */ | |
184 | return d->m_internalModel->barsetCount(); |
|
185 | return d->m_internalModel->barsetCount(); | |
185 | } |
|
186 | } | |
186 |
|
187 | |||
187 | /*! |
|
188 | /*! | |
188 | Returns number of categories in series |
|
189 | Returns number of categories in series | |
189 | */ |
|
190 | */ | |
190 | int QBarSeries::categoryCount() const |
|
191 | int QBarSeries::categoryCount() const | |
191 | { |
|
192 | { | |
192 | Q_D(const QBarSeries); |
|
193 | Q_D(const QBarSeries); | |
193 | return d->m_internalModel->categoryCount(); |
|
194 | return d->m_internalModel->categoryCount(); | |
194 | } |
|
195 | } | |
195 |
|
196 | |||
196 | /*! |
|
197 | /*! | |
197 | Returns a list of sets in series. Keeps ownership of sets. |
|
198 | Returns a list of sets in series. Keeps ownership of sets. | |
198 | */ |
|
199 | */ | |
199 | QList<QBarSet*> QBarSeries::barSets() const |
|
200 | QList<QBarSet*> QBarSeries::barSets() const | |
200 | { |
|
201 | { | |
201 | Q_D(const QBarSeries); |
|
202 | Q_D(const QBarSeries); | |
202 | return d->m_internalModel->barSets(); |
|
203 | return d->m_internalModel->barSets(); | |
203 | } |
|
204 | } | |
204 |
|
205 | |||
205 | /*! |
|
206 | /*! | |
206 | \internal \a index |
|
207 | \internal \a index | |
207 | */ |
|
208 | */ | |
208 | QBarSet* QBarSeries::barsetAt(int index) |
|
209 | QBarSet* QBarSeries::barsetAt(int index) | |
209 | { |
|
210 | { | |
210 | Q_D(QBarSeries); |
|
211 | Q_D(QBarSeries); | |
211 | return d->barsetAt(index); |
|
212 | return d->barsetAt(index); | |
212 | // return m_internalModel->barsetAt(index); |
|
213 | // return m_internalModel->barsetAt(index); | |
213 | } |
|
214 | } | |
214 |
|
215 | |||
215 | /*! |
|
216 | /*! | |
216 | \internal \a category |
|
217 | \internal \a category | |
217 | */ |
|
218 | */ | |
218 | QString QBarSeries::categoryName(int category) |
|
219 | QString QBarSeries::categoryName(int category) | |
219 | { |
|
220 | { | |
220 | Q_D(QBarSeries); |
|
221 | Q_D(QBarSeries); | |
221 | return d->categoryName(category); |
|
222 | return d->categoryName(category); | |
222 | // return m_internalModel->categoryName(category); |
|
223 | // return m_internalModel->categoryName(category); | |
223 | } |
|
224 | } | |
224 |
|
225 | |||
225 | /*! |
|
226 | /*! | |
226 | Enables or disables tooltip depending on parameter \a enabled. |
|
227 | Enables or disables tooltip depending on parameter \a enabled. | |
227 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
228 | Tooltip shows the name of set, when mouse is hovering on top of bar. | |
228 | Calling without parameter \a enabled, enables the tooltip |
|
229 | Calling without parameter \a enabled, enables the tooltip | |
229 | */ |
|
230 | */ | |
230 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
231 | void QBarSeries::setToolTipEnabled(bool enabled) | |
231 | { |
|
232 | { | |
232 | Q_D(QBarSeries); |
|
233 | Q_D(QBarSeries); | |
233 | d->setToolTipEnabled(enabled); |
|
234 | d->setToolTipEnabled(enabled); | |
234 | /* |
|
235 | /* | |
235 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
236 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
236 | if (enabled) { |
|
237 | if (enabled) { | |
237 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
238 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
238 | QBarSet *set = m_internalModel->barsetAt(i); |
|
239 | QBarSet *set = m_internalModel->barsetAt(i); | |
239 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
240 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
240 | } |
|
241 | } | |
241 | } else { |
|
242 | } else { | |
242 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
243 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
243 | QBarSet *set = m_internalModel->barsetAt(i); |
|
244 | QBarSet *set = m_internalModel->barsetAt(i); | |
244 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
245 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
245 | } |
|
246 | } | |
246 | } |
|
247 | } | |
247 | */ |
|
248 | */ | |
248 | } |
|
249 | } | |
249 |
|
250 | |||
250 |
|
251 | |||
251 | /*! |
|
252 | /*! | |
252 | \internal \a category |
|
253 | \internal \a category | |
253 | */ |
|
254 | */ | |
254 | void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button) |
|
255 | void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button) | |
255 | { |
|
256 | { | |
256 | Q_D(QBarSeries); |
|
257 | Q_D(QBarSeries); | |
257 | d->barsetClicked(category,button); |
|
258 | d->barsetClicked(category,button); | |
258 | // emit clicked(qobject_cast<QBarSet*>(sender()), category, button); |
|
259 | // emit clicked(qobject_cast<QBarSet*>(sender()), category, button); | |
259 | } |
|
260 | } | |
260 |
|
261 | |||
261 | /*! |
|
262 | /*! | |
262 | \internal |
|
263 | \internal | |
263 | */ |
|
264 | */ | |
264 | qreal QBarSeries::min() |
|
265 | qreal QBarSeries::min() | |
265 | { |
|
266 | { | |
266 | Q_D(QBarSeries); |
|
267 | Q_D(QBarSeries); | |
267 | return d->min(); |
|
268 | return d->min(); | |
268 | //return m_internalModel->min(); |
|
269 | //return m_internalModel->min(); | |
269 | } |
|
270 | } | |
270 |
|
271 | |||
271 | /*! |
|
272 | /*! | |
272 | \internal |
|
273 | \internal | |
273 | */ |
|
274 | */ | |
274 | qreal QBarSeries::max() |
|
275 | qreal QBarSeries::max() | |
275 | { |
|
276 | { | |
276 | Q_D(QBarSeries); |
|
277 | Q_D(QBarSeries); | |
277 | return d->max(); |
|
278 | return d->max(); | |
278 | // return m_internalModel->max(); |
|
279 | // return m_internalModel->max(); | |
279 | } |
|
280 | } | |
280 |
|
281 | |||
281 | /*! |
|
282 | /*! | |
282 | \internal \a set \a category |
|
283 | \internal \a set \a category | |
283 | */ |
|
284 | */ | |
284 | qreal QBarSeries::valueAt(int set, int category) |
|
285 | qreal QBarSeries::valueAt(int set, int category) | |
285 | { |
|
286 | { | |
286 | Q_D(QBarSeries); |
|
287 | Q_D(QBarSeries); | |
287 | return d->valueAt(set,category); |
|
288 | return d->valueAt(set,category); | |
288 | // return m_internalModel->valueAt(set, category); |
|
289 | // return m_internalModel->valueAt(set, category); | |
289 | } |
|
290 | } | |
290 |
|
291 | |||
291 | /*! |
|
292 | /*! | |
292 | \internal \a set \a category |
|
293 | \internal \a set \a category | |
293 | */ |
|
294 | */ | |
294 | qreal QBarSeries::percentageAt(int set, int category) |
|
295 | qreal QBarSeries::percentageAt(int set, int category) | |
295 | { |
|
296 | { | |
296 | Q_D(QBarSeries); |
|
297 | Q_D(QBarSeries); | |
297 | return d->percentageAt(set,category); |
|
298 | return d->percentageAt(set,category); | |
298 | // return m_internalModel->percentageAt(set, category); |
|
299 | // return m_internalModel->percentageAt(set, category); | |
299 | } |
|
300 | } | |
300 |
|
301 | |||
301 | /*! |
|
302 | /*! | |
302 | \internal \a category |
|
303 | \internal \a category | |
303 | */ |
|
304 | */ | |
304 | qreal QBarSeries::categorySum(int category) |
|
305 | qreal QBarSeries::categorySum(int category) | |
305 | { |
|
306 | { | |
306 | Q_D(QBarSeries); |
|
307 | Q_D(QBarSeries); | |
307 | return d->categorySum(category); |
|
308 | return d->categorySum(category); | |
308 | // return m_internalModel->categorySum(category); |
|
309 | // return m_internalModel->categorySum(category); | |
309 | } |
|
310 | } | |
310 |
|
311 | |||
311 | /*! |
|
312 | /*! | |
312 | \internal \a category |
|
313 | \internal \a category | |
313 | */ |
|
314 | */ | |
314 | qreal QBarSeries::absoluteCategorySum(int category) |
|
315 | qreal QBarSeries::absoluteCategorySum(int category) | |
315 | { |
|
316 | { | |
316 | Q_D(QBarSeries); |
|
317 | Q_D(QBarSeries); | |
317 | return d->absoluteCategorySum(category); |
|
318 | return d->absoluteCategorySum(category); | |
318 | // return m_internalModel->absoluteCategorySum(category); |
|
319 | // return m_internalModel->absoluteCategorySum(category); | |
319 | } |
|
320 | } | |
320 |
|
321 | |||
321 | /*! |
|
322 | /*! | |
322 | \internal |
|
323 | \internal | |
323 | */ |
|
324 | */ | |
324 | qreal QBarSeries::maxCategorySum() |
|
325 | qreal QBarSeries::maxCategorySum() | |
325 | { |
|
326 | { | |
326 | Q_D(QBarSeries); |
|
327 | Q_D(QBarSeries); | |
327 | return d->maxCategorySum(); |
|
328 | return d->maxCategorySum(); | |
328 | // return m_internalModel->maxCategorySum(); |
|
329 | // return m_internalModel->maxCategorySum(); | |
329 | } |
|
330 | } | |
330 |
|
331 | |||
331 | /*! |
|
332 | /*! | |
332 | \internal |
|
333 | \internal | |
333 | */ |
|
334 | */ | |
334 | BarChartModel& QBarSeries::modelInternal() |
|
335 | BarChartModel& QBarSeries::modelInternal() | |
335 | { |
|
336 | { | |
336 | Q_D(QBarSeries); |
|
337 | Q_D(QBarSeries); | |
337 | return d->modelInternal(); |
|
338 | return d->modelInternal(); | |
338 | // return *m_internalModel; |
|
339 | // return *m_internalModel; | |
339 | } |
|
340 | } | |
340 |
|
341 | |||
341 | /*! |
|
342 | /*! | |
342 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) |
|
343 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) | |
343 | Sets the \a model to be used as a data source |
|
344 | Sets the \a model to be used as a data source | |
344 | */ |
|
345 | */ | |
345 | bool QBarSeries::setModel(QAbstractItemModel *model) |
|
346 | bool QBarSeries::setModel(QAbstractItemModel *model) | |
346 | { |
|
347 | { | |
347 | Q_D(QBarSeries); |
|
348 | Q_D(QBarSeries); | |
348 | return d->setModel(model); |
|
349 | return d->setModel(model); | |
349 | /* |
|
350 | /* | |
350 | // disconnect signals from old model |
|
351 | // disconnect signals from old model | |
351 | if(m_model) |
|
352 | if(m_model) | |
352 | { |
|
353 | { | |
353 | disconnect(m_model, 0, this, 0); |
|
354 | disconnect(m_model, 0, this, 0); | |
354 | m_mapCategories = -1; |
|
355 | m_mapCategories = -1; | |
355 | m_mapBarBottom = -1; |
|
356 | m_mapBarBottom = -1; | |
356 | m_mapBarTop = -1; |
|
357 | m_mapBarTop = -1; | |
357 | m_mapFirst = 0; |
|
358 | m_mapFirst = 0; | |
358 | m_mapCount = 0; |
|
359 | m_mapCount = 0; | |
359 | m_mapOrientation = Qt::Vertical; |
|
360 | m_mapOrientation = Qt::Vertical; | |
360 | } |
|
361 | } | |
361 |
|
362 | |||
362 | // set new model |
|
363 | // set new model | |
363 | if(model) |
|
364 | if(model) | |
364 | { |
|
365 | { | |
365 | m_model = model; |
|
366 | m_model = model; | |
366 | return true; |
|
367 | return true; | |
367 | } |
|
368 | } | |
368 | else |
|
369 | else | |
369 | { |
|
370 | { | |
370 | m_model = 0; |
|
371 | m_model = 0; | |
371 | return false; |
|
372 | return false; | |
372 | } |
|
373 | } | |
373 | */ |
|
374 | */ | |
374 | } |
|
375 | } | |
375 |
|
376 | |||
376 | /*! |
|
377 | /*! | |
377 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
378 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
378 | Sets column/row specified by \a categories to be used as a list of bar series categories. |
|
379 | Sets column/row specified by \a categories to be used as a list of bar series categories. | |
379 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. |
|
380 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. | |
380 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. |
|
381 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. | |
381 | All the columns/rows inbetween those two values are also used as data for bar sets. |
|
382 | All the columns/rows inbetween those two values are also used as data for bar sets. | |
382 | The \a orientation paramater specifies whether the data is in columns or in rows. |
|
383 | The \a orientation paramater specifies whether the data is in columns or in rows. | |
383 | */ |
|
384 | */ | |
384 | void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation) |
|
385 | void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation) | |
385 | { |
|
386 | { | |
386 | Q_D(QBarSeries); |
|
387 | Q_D(QBarSeries); | |
387 | d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); |
|
388 | d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); | |
388 | /* |
|
389 | /* | |
389 | if (!m_model) |
|
390 | if (!m_model) | |
390 | return; |
|
391 | return; | |
391 |
|
392 | |||
392 | m_mapCategories = categories; |
|
393 | m_mapCategories = categories; | |
393 | m_mapBarBottom = bottomBoundry; |
|
394 | m_mapBarBottom = bottomBoundry; | |
394 | m_mapBarTop = topBoundry; |
|
395 | m_mapBarTop = topBoundry; | |
395 | // m_mapFirst = 1; |
|
396 | // m_mapFirst = 1; | |
396 | m_mapOrientation = orientation; |
|
397 | m_mapOrientation = orientation; | |
397 |
|
398 | |||
398 | // connect the signals |
|
399 | // connect the signals | |
399 | if (m_mapOrientation == Qt::Vertical) { |
|
400 | if (m_mapOrientation == Qt::Vertical) { | |
400 | m_mapCount = m_model->rowCount() - m_mapFirst; |
|
401 | m_mapCount = m_model->rowCount() - m_mapFirst; | |
401 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
402 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
402 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
403 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
403 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), |
|
404 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), | |
404 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
405 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
405 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), |
|
406 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), | |
406 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
407 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
407 | } else { |
|
408 | } else { | |
408 | m_mapCount = m_model->columnCount() - m_mapFirst; |
|
409 | m_mapCount = m_model->columnCount() - m_mapFirst; | |
409 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
410 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
410 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
411 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
411 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), |
|
412 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), | |
412 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
413 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
413 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), |
|
414 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), | |
414 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
415 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
415 | } |
|
416 | } | |
416 |
|
417 | |||
417 | // create the initial bars |
|
418 | // create the initial bars | |
418 | delete m_internalModel; |
|
419 | delete m_internalModel; | |
419 | if (m_mapOrientation == Qt::Vertical) { |
|
420 | if (m_mapOrientation == Qt::Vertical) { | |
420 | QStringList categories; |
|
421 | QStringList categories; | |
421 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
422 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
422 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
423 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
423 | m_internalModel = new BarChartModel(categories, this); |
|
424 | m_internalModel = new BarChartModel(categories, this); | |
424 |
|
425 | |||
425 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
426 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
426 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
427 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
427 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
428 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
428 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
429 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
429 | appendBarSet(barSet); |
|
430 | appendBarSet(barSet); | |
430 | } |
|
431 | } | |
431 | } else { |
|
432 | } else { | |
432 | QStringList categories; |
|
433 | QStringList categories; | |
433 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
434 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
434 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
435 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
435 | m_internalModel = new BarChartModel(categories, this); |
|
436 | m_internalModel = new BarChartModel(categories, this); | |
436 |
|
437 | |||
437 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
438 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
438 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
439 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
439 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
440 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
440 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
441 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
441 | appendBarSet(barSet); |
|
442 | appendBarSet(barSet); | |
442 | } |
|
443 | } | |
443 | } |
|
444 | } | |
444 | */ |
|
445 | */ | |
445 | } |
|
446 | } | |
446 |
|
447 | |||
447 | /*! |
|
448 | /*! | |
448 | \internal |
|
449 | \internal | |
449 | */ |
|
450 | */ | |
450 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
451 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
451 | { |
|
452 | { | |
452 | Q_D(QBarSeries); |
|
453 | Q_D(QBarSeries); | |
453 | d->modelUpdated(topLeft,bottomRight); |
|
454 | d->modelUpdated(topLeft,bottomRight); | |
454 | /* |
|
455 | /* | |
455 | Q_UNUSED(bottomRight) |
|
456 | Q_UNUSED(bottomRight) | |
456 |
|
457 | |||
457 | if (m_mapOrientation == Qt::Vertical) |
|
458 | if (m_mapOrientation == Qt::Vertical) | |
458 | { |
|
459 | { | |
459 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
460 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
460 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) |
|
461 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) | |
461 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
462 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
462 | } |
|
463 | } | |
463 | else |
|
464 | else | |
464 | { |
|
465 | { | |
465 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
466 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
466 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) |
|
467 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) | |
467 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
468 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
468 | } |
|
469 | } | |
469 | */ |
|
470 | */ | |
470 | } |
|
471 | } | |
471 |
|
472 | |||
472 | /*! |
|
473 | /*! | |
473 | \internal |
|
474 | \internal | |
474 | */ |
|
475 | */ | |
475 | void QBarSeries::modelDataAdded(QModelIndex parent, int start, int end) |
|
476 | void QBarSeries::modelDataAdded(QModelIndex parent, int start, int end) | |
476 | { |
|
477 | { | |
477 | Q_D(QBarSeries); |
|
478 | Q_D(QBarSeries); | |
478 | d->modelDataAdded(parent,start,end); |
|
479 | d->modelDataAdded(parent,start,end); | |
479 | /* |
|
480 | /* | |
480 | if (m_mapOrientation == Qt::Vertical) { |
|
481 | if (m_mapOrientation == Qt::Vertical) { | |
481 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); |
|
482 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
482 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
483 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
483 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); |
|
484 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
484 | } |
|
485 | } | |
485 | } else { |
|
486 | } else { | |
486 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); |
|
487 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
487 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
488 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
488 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); |
|
489 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
489 | } |
|
490 | } | |
490 | } |
|
491 | } | |
491 | emit restructuredBars(); |
|
492 | emit restructuredBars(); | |
492 | */ |
|
493 | */ | |
493 | } |
|
494 | } | |
494 |
|
495 | |||
495 | /*! |
|
496 | /*! | |
496 | \internal |
|
497 | \internal | |
497 | */ |
|
498 | */ | |
498 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) |
|
499 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
499 | { |
|
500 | { | |
500 | Q_D(QBarSeries); |
|
501 | Q_D(QBarSeries); | |
501 | d->modelDataRemoved(parent,start,end); |
|
502 | d->modelDataRemoved(parent,start,end); | |
502 | /* |
|
503 | /* | |
503 | Q_UNUSED(parent) |
|
504 | Q_UNUSED(parent) | |
504 | Q_UNUSED(end) |
|
505 | Q_UNUSED(end) | |
505 |
|
506 | |||
506 | removeCategory(start - m_mapFirst); |
|
507 | removeCategory(start - m_mapFirst); | |
507 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
508 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
508 | { |
|
509 | { | |
509 | barsetAt(i)->removeValue(start - m_mapFirst); |
|
510 | barsetAt(i)->removeValue(start - m_mapFirst); | |
510 | } |
|
511 | } | |
511 | emit restructuredBars(); |
|
512 | emit restructuredBars(); | |
512 | */ |
|
513 | */ | |
513 | } |
|
514 | } | |
514 |
|
515 | |||
515 | void QBarSeries::barsetChanged() |
|
516 | void QBarSeries::barsetChanged() | |
516 | { |
|
517 | { | |
517 | Q_D(QBarSeries); |
|
518 | Q_D(QBarSeries); | |
518 | d->barsetChanged(); |
|
519 | d->barsetChanged(); | |
519 | // emit updatedBars(); |
|
520 | // emit updatedBars(); | |
520 | } |
|
521 | } | |
521 |
|
522 | |||
522 | QBarCategories QBarSeries::categories() const |
|
523 | QBarCategories QBarSeries::categories() const | |
523 | { |
|
524 | { | |
524 | Q_D(const QBarSeries); |
|
525 | Q_D(const QBarSeries); | |
525 |
|
526 | |||
526 | QBarCategories categories; |
|
527 | QBarCategories categories; | |
527 | int count = d->m_internalModel->categoryCount(); |
|
528 | int count = d->m_internalModel->categoryCount(); | |
528 | for (int i=1; i <= count; i++) { |
|
529 | for (int i=1; i <= count; i++) { | |
529 | categories.insert(i, d->m_internalModel->categoryName(i - 1)); |
|
530 | categories.insert(i, d->m_internalModel->categoryName(i - 1)); | |
530 | } |
|
531 | } | |
531 | return categories; |
|
532 | return categories; | |
532 |
|
533 | |||
533 | } |
|
534 | } | |
534 |
|
535 | |||
535 | /*! |
|
536 | /*! | |
536 | Sets the visibility of labels in series to \a visible |
|
537 | Sets the visibility of labels in series to \a visible | |
537 | */ |
|
538 | */ | |
538 | void QBarSeries::setLabelsVisible(bool visible) |
|
539 | void QBarSeries::setLabelsVisible(bool visible) | |
539 | { |
|
540 | { | |
540 | foreach (QBarSet* s, barSets()) { |
|
541 | foreach (QBarSet* s, barSets()) { | |
541 | s->setLabelsVisible(visible); |
|
542 | s->setLabelsVisible(visible); | |
542 | } |
|
543 | } | |
543 | } |
|
544 | } | |
544 |
|
545 | |||
545 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
546 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
546 |
|
547 | |||
547 | QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : QSeriesPrivate(q), |
|
548 | QBarSeriesPrivate::QBarSeriesPrivate(QBarCategories categories, QBarSeries *q) : QSeriesPrivate(q), | |
548 | m_internalModel(new BarChartModel(categories,this)), |
|
549 | m_internalModel(new BarChartModel(categories,this)), | |
549 | m_model(0), |
|
550 | m_model(0), | |
550 | m_mapCategories(-1), |
|
551 | m_mapCategories(-1), | |
551 | m_mapBarBottom(-1), |
|
552 | m_mapBarBottom(-1), | |
552 | m_mapBarTop(-1), |
|
553 | m_mapBarTop(-1), | |
553 | m_mapFirst(0), |
|
554 | m_mapFirst(0), | |
554 | m_mapCount(0), |
|
555 | m_mapCount(0), | |
555 | m_mapOrientation(Qt::Vertical) |
|
556 | m_mapOrientation(Qt::Vertical) | |
556 | { |
|
557 | { | |
557 | } |
|
558 | } | |
558 |
|
559 | |||
559 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
560 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
560 | { |
|
561 | { | |
561 | return m_internalModel->barsetAt(index); |
|
562 | return m_internalModel->barsetAt(index); | |
562 | } |
|
563 | } | |
563 |
|
564 | |||
564 | QString QBarSeriesPrivate::categoryName(int category) |
|
565 | QString QBarSeriesPrivate::categoryName(int category) | |
565 | { |
|
566 | { | |
566 | return m_internalModel->categoryName(category); |
|
567 | return m_internalModel->categoryName(category); | |
567 | } |
|
568 | } | |
568 |
|
569 | |||
569 | void QBarSeriesPrivate::setToolTipEnabled(bool enabled) |
|
570 | void QBarSeriesPrivate::setToolTipEnabled(bool enabled) | |
570 | { |
|
571 | { | |
571 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
572 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
572 | if (enabled) { |
|
573 | if (enabled) { | |
573 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
574 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
574 | QBarSet *set = m_internalModel->barsetAt(i); |
|
575 | QBarSet *set = m_internalModel->barsetAt(i); | |
575 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
576 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
576 | } |
|
577 | } | |
577 | } else { |
|
578 | } else { | |
578 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
579 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
579 | QBarSet *set = m_internalModel->barsetAt(i); |
|
580 | QBarSet *set = m_internalModel->barsetAt(i); | |
580 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
581 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
581 | } |
|
582 | } | |
582 | } |
|
583 | } | |
583 | } |
|
584 | } | |
584 |
|
585 | |||
585 | void QBarSeriesPrivate::barsetClicked(QString category, Qt::MouseButtons button) |
|
586 | void QBarSeriesPrivate::barsetClicked(QString category, Qt::MouseButtons button) | |
586 | { |
|
587 | { | |
587 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); |
|
588 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); | |
588 | } |
|
589 | } | |
589 |
|
590 | |||
590 | qreal QBarSeriesPrivate::min() |
|
591 | qreal QBarSeriesPrivate::min() | |
591 | { |
|
592 | { | |
592 | return m_internalModel->min(); |
|
593 | return m_internalModel->min(); | |
593 | } |
|
594 | } | |
594 |
|
595 | |||
595 | qreal QBarSeriesPrivate::max() |
|
596 | qreal QBarSeriesPrivate::max() | |
596 | { |
|
597 | { | |
597 | return m_internalModel->max(); |
|
598 | return m_internalModel->max(); | |
598 | } |
|
599 | } | |
599 |
|
600 | |||
600 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
601 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
601 | { |
|
602 | { | |
602 | return m_internalModel->valueAt(set, category); |
|
603 | return m_internalModel->valueAt(set, category); | |
603 | } |
|
604 | } | |
604 |
|
605 | |||
605 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
606 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
606 | { |
|
607 | { | |
607 | return m_internalModel->percentageAt(set, category); |
|
608 | return m_internalModel->percentageAt(set, category); | |
608 | } |
|
609 | } | |
609 |
|
610 | |||
610 | qreal QBarSeriesPrivate::categorySum(int category) |
|
611 | qreal QBarSeriesPrivate::categorySum(int category) | |
611 | { |
|
612 | { | |
612 | return m_internalModel->categorySum(category); |
|
613 | return m_internalModel->categorySum(category); | |
613 | } |
|
614 | } | |
614 |
|
615 | |||
615 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
616 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
616 | { |
|
617 | { | |
617 | return m_internalModel->absoluteCategorySum(category); |
|
618 | return m_internalModel->absoluteCategorySum(category); | |
618 | } |
|
619 | } | |
619 |
|
620 | |||
620 | qreal QBarSeriesPrivate::maxCategorySum() |
|
621 | qreal QBarSeriesPrivate::maxCategorySum() | |
621 | { |
|
622 | { | |
622 | return m_internalModel->maxCategorySum(); |
|
623 | return m_internalModel->maxCategorySum(); | |
623 | } |
|
624 | } | |
624 |
|
625 | |||
625 | BarChartModel& QBarSeriesPrivate::modelInternal() |
|
626 | BarChartModel& QBarSeriesPrivate::modelInternal() | |
626 | { |
|
627 | { | |
627 | return *m_internalModel; |
|
628 | return *m_internalModel; | |
628 | } |
|
629 | } | |
629 |
|
630 | |||
630 | bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) |
|
631 | bool QBarSeriesPrivate::setModel(QAbstractItemModel *model) | |
631 | { |
|
632 | { | |
632 | // disconnect signals from old model |
|
633 | // disconnect signals from old model | |
633 | if(m_model) |
|
634 | if(m_model) | |
634 | { |
|
635 | { | |
635 | disconnect(m_model, 0, this, 0); |
|
636 | disconnect(m_model, 0, this, 0); | |
636 | m_mapCategories = -1; |
|
637 | m_mapCategories = -1; | |
637 | m_mapBarBottom = -1; |
|
638 | m_mapBarBottom = -1; | |
638 | m_mapBarTop = -1; |
|
639 | m_mapBarTop = -1; | |
639 | m_mapFirst = 0; |
|
640 | m_mapFirst = 0; | |
640 | m_mapCount = 0; |
|
641 | m_mapCount = 0; | |
641 | m_mapOrientation = Qt::Vertical; |
|
642 | m_mapOrientation = Qt::Vertical; | |
642 | } |
|
643 | } | |
643 |
|
644 | |||
644 | // set new model |
|
645 | // set new model | |
645 | if(model) |
|
646 | if(model) | |
646 | { |
|
647 | { | |
647 | m_model = model; |
|
648 | m_model = model; | |
648 | return true; |
|
649 | return true; | |
649 | } |
|
650 | } | |
650 | else |
|
651 | else | |
651 | { |
|
652 | { | |
652 | m_model = 0; |
|
653 | m_model = 0; | |
653 | return false; |
|
654 | return false; | |
654 | } |
|
655 | } | |
655 | } |
|
656 | } | |
656 |
|
657 | |||
657 | void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
658 | void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
658 | { |
|
659 | { | |
659 | Q_Q(QBarSeries); |
|
660 | Q_Q(QBarSeries); | |
660 |
|
661 | |||
661 | if (m_model == 0) |
|
662 | if (m_model == 0) | |
662 | return; |
|
663 | return; | |
663 |
|
664 | |||
664 | m_mapCategories = categories; |
|
665 | m_mapCategories = categories; | |
665 | m_mapBarBottom = bottomBoundry; |
|
666 | m_mapBarBottom = bottomBoundry; | |
666 | m_mapBarTop = topBoundry; |
|
667 | m_mapBarTop = topBoundry; | |
667 | // m_mapFirst = 1; |
|
668 | // m_mapFirst = 1; | |
668 | m_mapOrientation = orientation; |
|
669 | m_mapOrientation = orientation; | |
669 |
|
670 | |||
670 | // connect the signals |
|
671 | // connect the signals | |
671 | if (m_mapOrientation == Qt::Vertical) { |
|
672 | if (m_mapOrientation == Qt::Vertical) { | |
672 | m_mapCount = m_model->rowCount() - m_mapFirst; |
|
673 | m_mapCount = m_model->rowCount() - m_mapFirst; | |
673 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
674 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
674 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
675 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
675 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), |
|
676 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), | |
676 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
677 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
677 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), |
|
678 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), | |
678 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
679 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
679 | } else { |
|
680 | } else { | |
680 | m_mapCount = m_model->columnCount() - m_mapFirst; |
|
681 | m_mapCount = m_model->columnCount() - m_mapFirst; | |
681 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
682 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
682 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
683 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
683 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), |
|
684 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), | |
684 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
685 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
685 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), |
|
686 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), | |
686 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
687 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
687 | } |
|
688 | } | |
688 |
|
689 | |||
689 | // create the initial bars |
|
690 | // create the initial bars | |
690 | delete m_internalModel; |
|
691 | delete m_internalModel; | |
691 | if (m_mapOrientation == Qt::Vertical) { |
|
692 | if (m_mapOrientation == Qt::Vertical) { | |
692 | QStringList categories; |
|
693 | QStringList categories; | |
693 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
694 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
694 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
695 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
695 | m_internalModel = new BarChartModel(categories, this); |
|
696 | m_internalModel = new BarChartModel(categories, this); | |
696 |
|
697 | |||
697 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
698 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
698 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
699 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
699 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
700 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
700 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
701 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
701 | q->appendBarSet(barSet); |
|
702 | q->appendBarSet(barSet); | |
702 | } |
|
703 | } | |
703 | } else { |
|
704 | } else { | |
704 | QStringList categories; |
|
705 | QStringList categories; | |
705 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
706 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
706 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
707 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
707 | m_internalModel = new BarChartModel(categories, this); |
|
708 | m_internalModel = new BarChartModel(categories, this); | |
708 |
|
709 | |||
709 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
710 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
710 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
711 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
711 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
712 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
712 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
713 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
713 | q->appendBarSet(barSet); |
|
714 | q->appendBarSet(barSet); | |
714 | } |
|
715 | } | |
715 | } |
|
716 | } | |
716 | } |
|
717 | } | |
717 |
|
718 | |||
718 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
719 | void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
719 | { |
|
720 | { | |
720 | Q_UNUSED(bottomRight) |
|
721 | Q_UNUSED(bottomRight) | |
721 |
|
722 | |||
722 | if (m_mapOrientation == Qt::Vertical) |
|
723 | if (m_mapOrientation == Qt::Vertical) | |
723 | { |
|
724 | { | |
724 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
725 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
725 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) |
|
726 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) | |
726 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
727 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
727 | } |
|
728 | } | |
728 | else |
|
729 | else | |
729 | { |
|
730 | { | |
730 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
731 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
731 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) |
|
732 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) | |
732 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
733 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
733 | } |
|
734 | } | |
734 | } |
|
735 | } | |
735 |
|
736 | |||
736 | void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) |
|
737 | void QBarSeriesPrivate::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
737 | { |
|
738 | { | |
738 | Q_Q(QBarSeries); |
|
739 | Q_Q(QBarSeries); | |
739 |
|
740 | |||
740 | if (m_mapOrientation == Qt::Vertical) { |
|
741 | if (m_mapOrientation == Qt::Vertical) { | |
741 | q->insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); |
|
742 | q->insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
742 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
743 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
743 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); |
|
744 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
744 | } |
|
745 | } | |
745 | } else { |
|
746 | } else { | |
746 | q->insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); |
|
747 | q->insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
747 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
748 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
748 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); |
|
749 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
749 | } |
|
750 | } | |
750 | } |
|
751 | } | |
751 | emit restructuredBars(); |
|
752 | emit restructuredBars(); | |
752 | } |
|
753 | } | |
753 |
|
754 | |||
754 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) |
|
755 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
755 | { |
|
756 | { | |
756 | Q_Q(QBarSeries); |
|
757 | Q_Q(QBarSeries); | |
757 | Q_UNUSED(parent) |
|
758 | Q_UNUSED(parent) | |
758 | Q_UNUSED(end) |
|
759 | Q_UNUSED(end) | |
759 |
|
760 | |||
760 | q->removeCategory(start - m_mapFirst); |
|
761 | q->removeCategory(start - m_mapFirst); | |
761 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
762 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
762 | { |
|
763 | { | |
763 | barsetAt(i)->removeValue(start - m_mapFirst); |
|
764 | barsetAt(i)->removeValue(start - m_mapFirst); | |
764 | } |
|
765 | } | |
765 | emit restructuredBars(); |
|
766 | emit restructuredBars(); | |
766 | } |
|
767 | } | |
767 |
|
768 | |||
768 | void QBarSeriesPrivate::barsetChanged() |
|
769 | void QBarSeriesPrivate::barsetChanged() | |
769 | { |
|
770 | { | |
770 | emit updatedBars(); |
|
771 | emit updatedBars(); | |
771 | } |
|
772 | } | |
772 |
|
773 | |||
773 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
774 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
774 | { |
|
775 | { | |
775 | Q_Q(QBarSeries); |
|
776 | Q_Q(QBarSeries); | |
776 | qreal minX(domain.minX()); |
|
777 | qreal minX(domain.minX()); | |
777 | qreal minY(domain.minY()); |
|
778 | qreal minY(domain.minY()); | |
778 | qreal maxX(domain.maxX()); |
|
779 | qreal maxX(domain.maxX()); | |
779 | qreal maxY(domain.maxY()); |
|
780 | qreal maxY(domain.maxY()); | |
780 | int tickXCount(domain.tickXCount()); |
|
781 | int tickXCount(domain.tickXCount()); | |
781 | int tickYCount(domain.tickYCount()); |
|
782 | int tickYCount(domain.tickYCount()); | |
782 |
|
783 | |||
783 | qreal x = q->categoryCount(); |
|
784 | qreal x = q->categoryCount(); | |
784 | qreal y = q->max(); |
|
785 | qreal y = q->max(); | |
785 | minX = qMin(minX, x); |
|
786 | minX = qMin(minX, x); | |
786 | minY = qMin(minY, y); |
|
787 | minY = qMin(minY, y); | |
787 | maxX = qMax(maxX, x); |
|
788 | maxX = qMax(maxX, x); | |
788 | maxY = qMax(maxY, y); |
|
789 | maxY = qMax(maxY, y); | |
789 | tickXCount = x+1; |
|
790 | tickXCount = x+1; | |
790 |
|
791 | |||
791 | domain.setRangeX(minX,maxX,tickXCount); |
|
792 | domain.setRangeX(minX,maxX,tickXCount); | |
792 | domain.setRangeY(minY,maxY,tickYCount); |
|
793 | domain.setRangeY(minY,maxY,tickYCount); | |
793 | } |
|
794 | } | |
794 |
|
795 | |||
795 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
796 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
796 | { |
|
797 | { | |
797 | Q_Q(QBarSeries); |
|
798 | Q_Q(QBarSeries); | |
798 |
|
799 | |||
799 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
800 | BarChartItem* bar = new BarChartItem(q,presenter); | |
800 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
801 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
801 | presenter->animator()->addAnimation(bar); |
|
802 | presenter->animator()->addAnimation(bar); | |
802 | } |
|
803 | } | |
803 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
804 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
804 | return bar; |
|
805 | return bar; | |
805 |
|
806 | |||
806 | } |
|
807 | } | |
807 |
|
808 | |||
|
809 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |||
|
810 | { | |||
|
811 | Q_Q(QBarSeries); | |||
|
812 | QList<LegendMarker*> markers; | |||
|
813 | foreach(QBarSet* set, q->barSets()) { | |||
|
814 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |||
|
815 | markers << marker; | |||
|
816 | } | |||
|
817 | ||||
|
818 | return markers; | |||
|
819 | } | |||
|
820 | ||||
808 | #include "moc_qbarseries.cpp" |
|
821 | #include "moc_qbarseries.cpp" | |
809 | #include "moc_qbarseries_p.cpp" |
|
822 | #include "moc_qbarseries_p.cpp" | |
810 |
|
823 | |||
811 | QTCOMMERCIALCHART_END_NAMESPACE |
|
824 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,70 +1,71 | |||||
1 | #ifndef QBARSERIES_P_H |
|
1 | #ifndef QBARSERIES_P_H | |
2 | #define QBARSERIES_P_H |
|
2 | #define QBARSERIES_P_H | |
3 |
|
3 | |||
4 | #include "qbarseries.h" |
|
4 | #include "qbarseries.h" | |
5 | #include "qseries_p.h" |
|
5 | #include "qseries_p.h" | |
6 | #include <QStringList> |
|
6 | #include <QStringList> | |
7 | #include <QSeries> |
|
7 | #include <QSeries> | |
8 |
|
8 | |||
9 | class QModelIndex; |
|
9 | class QModelIndex; | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | // Container for series |
|
13 | // Container for series | |
14 | class QBarSeriesPrivate : public QSeriesPrivate |
|
14 | class QBarSeriesPrivate : public QSeriesPrivate | |
15 | { |
|
15 | { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 | public: |
|
17 | public: | |
18 | QBarSeriesPrivate(QBarCategories categories, QBarSeries *parent); |
|
18 | QBarSeriesPrivate(QBarCategories categories, QBarSeries *parent); | |
19 |
|
19 | |||
20 | void scaleDomain(Domain& domain); |
|
20 | void scaleDomain(Domain& domain); | |
21 | Chart* createGraphics(ChartPresenter* presenter); |
|
21 | Chart* createGraphics(ChartPresenter* presenter); | |
|
22 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |||
22 |
|
23 | |||
23 | bool setModel(QAbstractItemModel *model); |
|
24 | bool setModel(QAbstractItemModel *model); | |
24 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
25 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
25 |
|
26 | |||
26 | QBarSet* barsetAt(int index); |
|
27 | QBarSet* barsetAt(int index); | |
27 | QString categoryName(int category); |
|
28 | QString categoryName(int category); | |
28 | qreal min(); |
|
29 | qreal min(); | |
29 | qreal max(); |
|
30 | qreal max(); | |
30 | qreal valueAt(int set, int category); |
|
31 | qreal valueAt(int set, int category); | |
31 | qreal percentageAt(int set, int category); |
|
32 | qreal percentageAt(int set, int category); | |
32 | qreal categorySum(int category); |
|
33 | qreal categorySum(int category); | |
33 | qreal absoluteCategorySum(int category); |
|
34 | qreal absoluteCategorySum(int category); | |
34 | qreal maxCategorySum(); |
|
35 | qreal maxCategorySum(); | |
35 | BarChartModel& modelInternal(); |
|
36 | BarChartModel& modelInternal(); | |
36 |
|
37 | |||
37 | Q_SIGNALS: |
|
38 | Q_SIGNALS: | |
38 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals |
|
39 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals | |
39 | void selected(); |
|
40 | void selected(); | |
40 | void updatedBars(); |
|
41 | void updatedBars(); | |
41 | void restructuredBars(); |
|
42 | void restructuredBars(); | |
42 | void showToolTip(QPoint pos, QString tip); |
|
43 | void showToolTip(QPoint pos, QString tip); | |
43 |
|
44 | |||
44 | public Q_SLOTS: |
|
45 | public Q_SLOTS: | |
45 | void setToolTipEnabled(bool enabled = true); // enables tooltips |
|
46 | void setToolTipEnabled(bool enabled = true); // enables tooltips | |
46 | void barsetClicked(QString category, Qt::MouseButtons button); |
|
47 | void barsetClicked(QString category, Qt::MouseButtons button); | |
47 |
|
48 | |||
48 | private Q_SLOTS: |
|
49 | private Q_SLOTS: | |
49 | // slots for updating bars when data in model changes |
|
50 | // slots for updating bars when data in model changes | |
50 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
51 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
51 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
52 | void modelDataAdded(QModelIndex parent, int start, int end); | |
52 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
53 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
53 | void barsetChanged(); |
|
54 | void barsetChanged(); | |
54 |
|
55 | |||
55 | protected: |
|
56 | protected: | |
56 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. |
|
57 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. | |
57 | QAbstractItemModel* m_model; |
|
58 | QAbstractItemModel* m_model; | |
58 | int m_mapCategories; |
|
59 | int m_mapCategories; | |
59 | int m_mapBarBottom; |
|
60 | int m_mapBarBottom; | |
60 | int m_mapBarTop; |
|
61 | int m_mapBarTop; | |
61 | int m_mapFirst; |
|
62 | int m_mapFirst; | |
62 | int m_mapCount; |
|
63 | int m_mapCount; | |
63 | Qt::Orientation m_mapOrientation; |
|
64 | Qt::Orientation m_mapOrientation; | |
64 | private: |
|
65 | private: | |
65 | Q_DECLARE_PUBLIC(QBarSeries) |
|
66 | Q_DECLARE_PUBLIC(QBarSeries) | |
66 | }; |
|
67 | }; | |
67 |
|
68 | |||
68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | QTCOMMERCIALCHART_END_NAMESPACE | |
69 |
|
70 | |||
70 | #endif // QBARSERIESPRIVATE_P_H |
|
71 | #endif // QBARSERIESPRIVATE_P_H |
@@ -1,722 +1,734 | |||||
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 "qpieseries.h" |
|
21 | #include "qpieseries.h" | |
22 | #include "qpieseries_p.h" |
|
22 | #include "qpieseries_p.h" | |
23 | #include "qpieslice.h" |
|
23 | #include "qpieslice.h" | |
24 | #include "pieslicedata_p.h" |
|
24 | #include "pieslicedata_p.h" | |
25 | #include "chartdataset_p.h" |
|
25 | #include "chartdataset_p.h" | |
26 | #include "charttheme_p.h" |
|
26 | #include "charttheme_p.h" | |
27 | #include "chartanimator_p.h" |
|
27 | #include "chartanimator_p.h" | |
|
28 | #include "legendmarker_p.h" | |||
28 | #include <QAbstractItemModel> |
|
29 | #include <QAbstractItemModel> | |
29 | #include <QDebug> |
|
30 | #include <QDebug> | |
30 |
|
31 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
33 | |||
33 | /*! |
|
34 | /*! | |
34 | \class QPieSeries |
|
35 | \class QPieSeries | |
35 | \brief Pie series API for QtCommercial Charts |
|
36 | \brief Pie series API for QtCommercial Charts | |
36 |
|
37 | |||
37 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. |
|
38 | The pie series defines a pie chart which consists of pie slices which are QPieSlice objects. | |
38 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
39 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
39 | The actual slice size is determined by that relative value. |
|
40 | The actual slice size is determined by that relative value. | |
40 |
|
41 | |||
41 | By default the pie is defined as a full pie but it can be a partial pie. |
|
42 | By default the pie is defined as a full pie but it can be a partial pie. | |
42 | This can be done by setting a starting angle and angle span to the series. |
|
43 | This can be done by setting a starting angle and angle span to the series. | |
43 | */ |
|
44 | */ | |
44 |
|
45 | |||
45 | /*! |
|
46 | /*! | |
46 | \property QPieSeries::horizontalPosition |
|
47 | \property QPieSeries::horizontalPosition | |
47 | \brief Defines the horizontal position of the pie. |
|
48 | \brief Defines the horizontal position of the pie. | |
48 |
|
49 | |||
49 | The value is a relative value to the chart rectangle where: |
|
50 | The value is a relative value to the chart rectangle where: | |
50 |
|
51 | |||
51 | \list |
|
52 | \list | |
52 | \o 0.0 is the absolute left. |
|
53 | \o 0.0 is the absolute left. | |
53 | \o 1.0 is the absolute right. |
|
54 | \o 1.0 is the absolute right. | |
54 | \endlist |
|
55 | \endlist | |
55 |
|
56 | |||
56 | Default value is 0.5 (center). |
|
57 | Default value is 0.5 (center). | |
57 | */ |
|
58 | */ | |
58 |
|
59 | |||
59 | /*! |
|
60 | /*! | |
60 | \property QPieSeries::verticalPosition |
|
61 | \property QPieSeries::verticalPosition | |
61 | \brief Defines the vertical position of the pie. |
|
62 | \brief Defines the vertical position of the pie. | |
62 |
|
63 | |||
63 | The value is a relative value to the chart rectangle where: |
|
64 | The value is a relative value to the chart rectangle where: | |
64 |
|
65 | |||
65 | \list |
|
66 | \list | |
66 | \o 0.0 is the absolute top. |
|
67 | \o 0.0 is the absolute top. | |
67 | \o 1.0 is the absolute bottom. |
|
68 | \o 1.0 is the absolute bottom. | |
68 | \endlist |
|
69 | \endlist | |
69 |
|
70 | |||
70 | Default value is 0.5 (center). |
|
71 | Default value is 0.5 (center). | |
71 | */ |
|
72 | */ | |
72 |
|
73 | |||
73 | /*! |
|
74 | /*! | |
74 | \property QPieSeries::size |
|
75 | \property QPieSeries::size | |
75 | \brief Defines the pie size. |
|
76 | \brief Defines the pie size. | |
76 |
|
77 | |||
77 | The value is a relative value to the chart rectangle where: |
|
78 | The value is a relative value to the chart rectangle where: | |
78 |
|
79 | |||
79 | \list |
|
80 | \list | |
80 | \o 0.0 is the minumum size (pie not drawn). |
|
81 | \o 0.0 is the minumum size (pie not drawn). | |
81 | \o 1.0 is the maximum size that can fit the chart. |
|
82 | \o 1.0 is the maximum size that can fit the chart. | |
82 | \endlist |
|
83 | \endlist | |
83 |
|
84 | |||
84 | Default value is 0.7. |
|
85 | Default value is 0.7. | |
85 | */ |
|
86 | */ | |
86 |
|
87 | |||
87 | /*! |
|
88 | /*! | |
88 | \property QPieSeries::startAngle |
|
89 | \property QPieSeries::startAngle | |
89 | \brief Defines the starting angle of the pie. |
|
90 | \brief Defines the starting angle of the pie. | |
90 |
|
91 | |||
91 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
92 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
92 |
|
93 | |||
93 | Default is value is 0. |
|
94 | Default is value is 0. | |
94 | */ |
|
95 | */ | |
95 |
|
96 | |||
96 | /*! |
|
97 | /*! | |
97 | \property QPieSeries::endAngle |
|
98 | \property QPieSeries::endAngle | |
98 | \brief Defines the ending angle of the pie. |
|
99 | \brief Defines the ending angle of the pie. | |
99 |
|
100 | |||
100 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
101 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
101 |
|
102 | |||
102 | Default is value is 360. |
|
103 | Default is value is 360. | |
103 | */ |
|
104 | */ | |
104 |
|
105 | |||
105 |
|
106 | |||
106 | /*! |
|
107 | /*! | |
107 | Constructs a series object which is a child of \a parent. |
|
108 | Constructs a series object which is a child of \a parent. | |
108 | */ |
|
109 | */ | |
109 | QPieSeries::QPieSeries(QObject *parent) : |
|
110 | QPieSeries::QPieSeries(QObject *parent) : | |
110 | QSeries(*new QPieSeriesPrivate(this),parent) |
|
111 | QSeries(*new QPieSeriesPrivate(this),parent) | |
111 | { |
|
112 | { | |
112 |
|
113 | |||
113 | } |
|
114 | } | |
114 |
|
115 | |||
115 | /*! |
|
116 | /*! | |
116 | Destroys the series and its slices. |
|
117 | Destroys the series and its slices. | |
117 | */ |
|
118 | */ | |
118 | QPieSeries::~QPieSeries() |
|
119 | QPieSeries::~QPieSeries() | |
119 | { |
|
120 | { | |
120 | // NOTE: d_prt destroyed by QObject |
|
121 | // NOTE: d_prt destroyed by QObject | |
121 | } |
|
122 | } | |
122 |
|
123 | |||
123 | /*! |
|
124 | /*! | |
124 | Returns QChartSeries::SeriesTypePie. |
|
125 | Returns QChartSeries::SeriesTypePie. | |
125 | */ |
|
126 | */ | |
126 | QSeries::QSeriesType QPieSeries::type() const |
|
127 | QSeries::QSeriesType QPieSeries::type() const | |
127 | { |
|
128 | { | |
128 | return QSeries::SeriesTypePie; |
|
129 | return QSeries::SeriesTypePie; | |
129 | } |
|
130 | } | |
130 |
|
131 | |||
131 | /*! |
|
132 | /*! | |
132 | Sets an array of \a slices to the series replacing the existing slices. |
|
133 | Sets an array of \a slices to the series replacing the existing slices. | |
133 | Slice ownership is passed to the series. |
|
134 | Slice ownership is passed to the series. | |
134 | */ |
|
135 | */ | |
135 | void QPieSeries::replace(QList<QPieSlice*> slices) |
|
136 | void QPieSeries::replace(QList<QPieSlice*> slices) | |
136 | { |
|
137 | { | |
137 | clear(); |
|
138 | clear(); | |
138 | append(slices); |
|
139 | append(slices); | |
139 | } |
|
140 | } | |
140 |
|
141 | |||
141 | /*! |
|
142 | /*! | |
142 | Appends an array of \a slices to the series. |
|
143 | Appends an array of \a slices to the series. | |
143 | Slice ownership is passed to the series. |
|
144 | Slice ownership is passed to the series. | |
144 | */ |
|
145 | */ | |
145 | void QPieSeries::append(QList<QPieSlice*> slices) |
|
146 | void QPieSeries::append(QList<QPieSlice*> slices) | |
146 | { |
|
147 | { | |
147 | Q_D(QPieSeries); |
|
148 | Q_D(QPieSeries); | |
148 |
|
149 | |||
149 | foreach (QPieSlice* s, slices) { |
|
150 | foreach (QPieSlice* s, slices) { | |
150 | s->setParent(this); |
|
151 | s->setParent(this); | |
151 | d->m_slices << s; |
|
152 | d->m_slices << s; | |
152 | } |
|
153 | } | |
153 |
|
154 | |||
154 | d->updateDerivativeData(); |
|
155 | d->updateDerivativeData(); | |
155 |
|
156 | |||
156 | foreach (QPieSlice* s, slices) { |
|
157 | foreach (QPieSlice* s, slices) { | |
157 | connect(s, SIGNAL(changed()), d, SLOT(sliceChanged())); |
|
158 | connect(s, SIGNAL(changed()), d, SLOT(sliceChanged())); | |
158 | connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); |
|
159 | connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); | |
159 | connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); |
|
160 | connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); | |
160 | connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); |
|
161 | connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); | |
161 | } |
|
162 | } | |
162 |
|
163 | |||
163 | emit added(slices); |
|
164 | emit added(slices); | |
164 | } |
|
165 | } | |
165 |
|
166 | |||
166 | /*! |
|
167 | /*! | |
167 | Appends a single \a slice to the series. |
|
168 | Appends a single \a slice to the series. | |
168 | Slice ownership is passed to the series. |
|
169 | Slice ownership is passed to the series. | |
169 | */ |
|
170 | */ | |
170 | void QPieSeries::append(QPieSlice* slice) |
|
171 | void QPieSeries::append(QPieSlice* slice) | |
171 | { |
|
172 | { | |
172 | append(QList<QPieSlice*>() << slice); |
|
173 | append(QList<QPieSlice*>() << slice); | |
173 | } |
|
174 | } | |
174 |
|
175 | |||
175 | /*! |
|
176 | /*! | |
176 | Appends a single \a slice to the series and returns a reference to the series. |
|
177 | Appends a single \a slice to the series and returns a reference to the series. | |
177 | Slice ownership is passed to the series. |
|
178 | Slice ownership is passed to the series. | |
178 | */ |
|
179 | */ | |
179 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) |
|
180 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) | |
180 | { |
|
181 | { | |
181 | append(slice); |
|
182 | append(slice); | |
182 | return *this; |
|
183 | return *this; | |
183 | } |
|
184 | } | |
184 |
|
185 | |||
185 |
|
186 | |||
186 | /*! |
|
187 | /*! | |
187 | Appends a single slice to the series with give \a value and \a name. |
|
188 | Appends a single slice to the series with give \a value and \a name. | |
188 | Slice ownership is passed to the series. |
|
189 | Slice ownership is passed to the series. | |
189 | */ |
|
190 | */ | |
190 | QPieSlice* QPieSeries::append(qreal value, QString name) |
|
191 | QPieSlice* QPieSeries::append(qreal value, QString name) | |
191 | { |
|
192 | { | |
192 | QPieSlice* slice = new QPieSlice(value, name); |
|
193 | QPieSlice* slice = new QPieSlice(value, name); | |
193 | append(slice); |
|
194 | append(slice); | |
194 | return slice; |
|
195 | return slice; | |
195 | } |
|
196 | } | |
196 |
|
197 | |||
197 | /*! |
|
198 | /*! | |
198 | Inserts a single \a slice to the series before the slice at \a index position. |
|
199 | Inserts a single \a slice to the series before the slice at \a index position. | |
199 | Slice ownership is passed to the series. |
|
200 | Slice ownership is passed to the series. | |
200 | */ |
|
201 | */ | |
201 | void QPieSeries::insert(int index, QPieSlice* slice) |
|
202 | void QPieSeries::insert(int index, QPieSlice* slice) | |
202 | { |
|
203 | { | |
203 | Q_D(QPieSeries); |
|
204 | Q_D(QPieSeries); | |
204 | Q_ASSERT(index <= d->m_slices.count()); |
|
205 | Q_ASSERT(index <= d->m_slices.count()); | |
205 | slice->setParent(this); |
|
206 | slice->setParent(this); | |
206 | d->m_slices.insert(index, slice); |
|
207 | d->m_slices.insert(index, slice); | |
207 |
|
208 | |||
208 | d->updateDerivativeData(); |
|
209 | d->updateDerivativeData(); | |
209 |
|
210 | |||
210 | connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged())); |
|
211 | connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged())); | |
211 | connect(slice, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); |
|
212 | connect(slice, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons))); | |
212 | connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); |
|
213 | connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter())); | |
213 | connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); |
|
214 | connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave())); | |
214 |
|
215 | |||
215 | emit added(QList<QPieSlice*>() << slice); |
|
216 | emit added(QList<QPieSlice*>() << slice); | |
216 | } |
|
217 | } | |
217 |
|
218 | |||
218 | /*! |
|
219 | /*! | |
219 | Removes a single \a slice from the series and deletes the slice. |
|
220 | Removes a single \a slice from the series and deletes the slice. | |
220 |
|
221 | |||
221 | Do not reference this pointer after this call. |
|
222 | Do not reference this pointer after this call. | |
222 | */ |
|
223 | */ | |
223 | void QPieSeries::remove(QPieSlice* slice) |
|
224 | void QPieSeries::remove(QPieSlice* slice) | |
224 | { |
|
225 | { | |
225 | Q_D(QPieSeries); |
|
226 | Q_D(QPieSeries); | |
226 | if (!d->m_slices.removeOne(slice)) { |
|
227 | if (!d->m_slices.removeOne(slice)) { | |
227 | Q_ASSERT(0); // TODO: how should this be reported? |
|
228 | Q_ASSERT(0); // TODO: how should this be reported? | |
228 | return; |
|
229 | return; | |
229 | } |
|
230 | } | |
230 |
|
231 | |||
231 | d->updateDerivativeData(); |
|
232 | d->updateDerivativeData(); | |
232 |
|
233 | |||
233 | emit removed(QList<QPieSlice*>() << slice); |
|
234 | emit removed(QList<QPieSlice*>() << slice); | |
234 |
|
235 | |||
235 | delete slice; |
|
236 | delete slice; | |
236 | slice = 0; |
|
237 | slice = 0; | |
237 | } |
|
238 | } | |
238 |
|
239 | |||
239 | /*! |
|
240 | /*! | |
240 | Clears all slices from the series. |
|
241 | Clears all slices from the series. | |
241 | */ |
|
242 | */ | |
242 | void QPieSeries::clear() |
|
243 | void QPieSeries::clear() | |
243 | { |
|
244 | { | |
244 | Q_D(QPieSeries); |
|
245 | Q_D(QPieSeries); | |
245 | if (d->m_slices.count() == 0) |
|
246 | if (d->m_slices.count() == 0) | |
246 | return; |
|
247 | return; | |
247 |
|
248 | |||
248 | QList<QPieSlice*> slices = d->m_slices; |
|
249 | QList<QPieSlice*> slices = d->m_slices; | |
249 | foreach (QPieSlice* s, d->m_slices) { |
|
250 | foreach (QPieSlice* s, d->m_slices) { | |
250 | d->m_slices.removeOne(s); |
|
251 | d->m_slices.removeOne(s); | |
251 | delete s; |
|
252 | delete s; | |
252 | } |
|
253 | } | |
253 |
|
254 | |||
254 | d->updateDerivativeData(); |
|
255 | d->updateDerivativeData(); | |
255 |
|
256 | |||
256 | emit removed(slices); |
|
257 | emit removed(slices); | |
257 | } |
|
258 | } | |
258 |
|
259 | |||
259 | /*! |
|
260 | /*! | |
260 | returns the number of the slices in this series. |
|
261 | returns the number of the slices in this series. | |
261 | */ |
|
262 | */ | |
262 | int QPieSeries::count() const |
|
263 | int QPieSeries::count() const | |
263 | { |
|
264 | { | |
264 | Q_D(const QPieSeries); |
|
265 | Q_D(const QPieSeries); | |
265 | return d->m_slices.count(); |
|
266 | return d->m_slices.count(); | |
266 | } |
|
267 | } | |
267 |
|
268 | |||
268 | /*! |
|
269 | /*! | |
269 | Returns true is the series is empty. |
|
270 | Returns true is the series is empty. | |
270 | */ |
|
271 | */ | |
271 | bool QPieSeries::isEmpty() const |
|
272 | bool QPieSeries::isEmpty() const | |
272 | { |
|
273 | { | |
273 | Q_D(const QPieSeries); |
|
274 | Q_D(const QPieSeries); | |
274 | return d->m_slices.isEmpty(); |
|
275 | return d->m_slices.isEmpty(); | |
275 | } |
|
276 | } | |
276 |
|
277 | |||
277 | /*! |
|
278 | /*! | |
278 | Returns a list of slices that belong to this series. |
|
279 | Returns a list of slices that belong to this series. | |
279 | */ |
|
280 | */ | |
280 | QList<QPieSlice*> QPieSeries::slices() const |
|
281 | QList<QPieSlice*> QPieSeries::slices() const | |
281 | { |
|
282 | { | |
282 | Q_D(const QPieSeries); |
|
283 | Q_D(const QPieSeries); | |
283 | return d->m_slices; |
|
284 | return d->m_slices; | |
284 | } |
|
285 | } | |
285 |
|
286 | |||
286 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
287 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
287 | { |
|
288 | { | |
288 | Q_D(QPieSeries); |
|
289 | Q_D(QPieSeries); | |
289 | if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0)) |
|
290 | if (d->setRealValue(d->m_pieRelativeHorPos, relativePosition, 1.0)) | |
290 | emit piePositionChanged(); |
|
291 | emit piePositionChanged(); | |
291 | } |
|
292 | } | |
292 |
|
293 | |||
293 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
294 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
294 | { |
|
295 | { | |
295 | Q_D(QPieSeries); |
|
296 | Q_D(QPieSeries); | |
296 | if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0)) |
|
297 | if (d->setRealValue(d->m_pieRelativeVerPos, relativePosition, 1.0)) | |
297 | emit piePositionChanged(); |
|
298 | emit piePositionChanged(); | |
298 | } |
|
299 | } | |
299 |
|
300 | |||
300 | qreal QPieSeries::horizontalPosition() const |
|
301 | qreal QPieSeries::horizontalPosition() const | |
301 | { |
|
302 | { | |
302 | Q_D(const QPieSeries); |
|
303 | Q_D(const QPieSeries); | |
303 | return d->m_pieRelativeHorPos; |
|
304 | return d->m_pieRelativeHorPos; | |
304 | } |
|
305 | } | |
305 |
|
306 | |||
306 | qreal QPieSeries::verticalPosition() const |
|
307 | qreal QPieSeries::verticalPosition() const | |
307 | { |
|
308 | { | |
308 | Q_D(const QPieSeries); |
|
309 | Q_D(const QPieSeries); | |
309 | return d->m_pieRelativeVerPos; |
|
310 | return d->m_pieRelativeVerPos; | |
310 | } |
|
311 | } | |
311 |
|
312 | |||
312 | void QPieSeries::setPieSize(qreal relativeSize) |
|
313 | void QPieSeries::setPieSize(qreal relativeSize) | |
313 | { |
|
314 | { | |
314 | Q_D(QPieSeries); |
|
315 | Q_D(QPieSeries); | |
315 | if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0)) |
|
316 | if (d->setRealValue(d->m_pieRelativeSize, relativeSize, 1.0)) | |
316 | emit pieSizeChanged(); |
|
317 | emit pieSizeChanged(); | |
317 | } |
|
318 | } | |
318 |
|
319 | |||
319 | qreal QPieSeries::pieSize() const |
|
320 | qreal QPieSeries::pieSize() const | |
320 | { |
|
321 | { | |
321 | Q_D(const QPieSeries); |
|
322 | Q_D(const QPieSeries); | |
322 | return d->m_pieRelativeSize; |
|
323 | return d->m_pieRelativeSize; | |
323 | } |
|
324 | } | |
324 |
|
325 | |||
325 |
|
326 | |||
326 | void QPieSeries::setPieStartAngle(qreal angle) |
|
327 | void QPieSeries::setPieStartAngle(qreal angle) | |
327 | { |
|
328 | { | |
328 | Q_D(QPieSeries); |
|
329 | Q_D(QPieSeries); | |
329 | if (d->setRealValue(d->m_pieStartAngle, angle, d->m_pieEndAngle)) |
|
330 | if (d->setRealValue(d->m_pieStartAngle, angle, d->m_pieEndAngle)) | |
330 | d->updateDerivativeData(); |
|
331 | d->updateDerivativeData(); | |
331 | } |
|
332 | } | |
332 |
|
333 | |||
333 | qreal QPieSeries::pieStartAngle() const |
|
334 | qreal QPieSeries::pieStartAngle() const | |
334 | { |
|
335 | { | |
335 | Q_D(const QPieSeries); |
|
336 | Q_D(const QPieSeries); | |
336 | return d->m_pieStartAngle; |
|
337 | return d->m_pieStartAngle; | |
337 | } |
|
338 | } | |
338 |
|
339 | |||
339 | /*! |
|
340 | /*! | |
340 | Sets the end angle of the pie. |
|
341 | Sets the end angle of the pie. | |
341 |
|
342 | |||
342 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
343 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
343 |
|
344 | |||
344 | \a angle must be greater than start angle. |
|
345 | \a angle must be greater than start angle. | |
345 |
|
346 | |||
346 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
347 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
347 | */ |
|
348 | */ | |
348 | void QPieSeries::setPieEndAngle(qreal angle) |
|
349 | void QPieSeries::setPieEndAngle(qreal angle) | |
349 | { |
|
350 | { | |
350 | Q_D(QPieSeries); |
|
351 | Q_D(QPieSeries); | |
351 |
|
352 | |||
352 | if (d->setRealValue(d->m_pieEndAngle, angle, 360.0, d->m_pieStartAngle)) |
|
353 | if (d->setRealValue(d->m_pieEndAngle, angle, 360.0, d->m_pieStartAngle)) | |
353 | d->updateDerivativeData(); |
|
354 | d->updateDerivativeData(); | |
354 | } |
|
355 | } | |
355 |
|
356 | |||
356 | /*! |
|
357 | /*! | |
357 | Returns the end angle of the pie. |
|
358 | Returns the end angle of the pie. | |
358 |
|
359 | |||
359 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
360 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
360 |
|
361 | |||
361 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
362 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
362 | */ |
|
363 | */ | |
363 | qreal QPieSeries::pieEndAngle() const |
|
364 | qreal QPieSeries::pieEndAngle() const | |
364 | { |
|
365 | { | |
365 | Q_D(const QPieSeries); |
|
366 | Q_D(const QPieSeries); | |
366 | return d->m_pieEndAngle; |
|
367 | return d->m_pieEndAngle; | |
367 | } |
|
368 | } | |
368 |
|
369 | |||
369 | /*! |
|
370 | /*! | |
370 | Sets the all the slice labels \a visible or invisible. |
|
371 | Sets the all the slice labels \a visible or invisible. | |
371 |
|
372 | |||
372 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
373 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
373 | */ |
|
374 | */ | |
374 | void QPieSeries::setLabelsVisible(bool visible) |
|
375 | void QPieSeries::setLabelsVisible(bool visible) | |
375 | { |
|
376 | { | |
376 | Q_D(QPieSeries); |
|
377 | Q_D(QPieSeries); | |
377 | foreach (QPieSlice* s, d->m_slices) |
|
378 | foreach (QPieSlice* s, d->m_slices) | |
378 | s->setLabelVisible(visible); |
|
379 | s->setLabelVisible(visible); | |
379 | } |
|
380 | } | |
380 |
|
381 | |||
381 | /*! |
|
382 | /*! | |
382 | Returns the sum of all slice values in this series. |
|
383 | Returns the sum of all slice values in this series. | |
383 |
|
384 | |||
384 | \sa QPieSlice::value(), QPieSlice::setValue() |
|
385 | \sa QPieSlice::value(), QPieSlice::setValue() | |
385 | */ |
|
386 | */ | |
386 | qreal QPieSeries::sum() const |
|
387 | qreal QPieSeries::sum() const | |
387 | { |
|
388 | { | |
388 | Q_D(const QPieSeries); |
|
389 | Q_D(const QPieSeries); | |
389 | return d->m_sum; |
|
390 | return d->m_sum; | |
390 | } |
|
391 | } | |
391 |
|
392 | |||
392 | /*! |
|
393 | /*! | |
393 | \fn void QPieSeries::clicked(QPieSlice* slice, Qt::MouseButtons buttons) |
|
394 | \fn void QPieSeries::clicked(QPieSlice* slice, Qt::MouseButtons buttons) | |
394 |
|
395 | |||
395 | This signal is emitted when a \a slice has been clicked with mouse \a buttons. |
|
396 | This signal is emitted when a \a slice has been clicked with mouse \a buttons. | |
396 |
|
397 | |||
397 | \sa QPieSlice::clicked() |
|
398 | \sa QPieSlice::clicked() | |
398 | */ |
|
399 | */ | |
399 |
|
400 | |||
400 | /*! |
|
401 | /*! | |
401 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) |
|
402 | \fn void QPieSeries::hoverEnter(QPieSlice* slice) | |
402 |
|
403 | |||
403 | This signal is emitted when user has hovered over a \a slice. |
|
404 | This signal is emitted when user has hovered over a \a slice. | |
404 |
|
405 | |||
405 | \sa QPieSlice::hoverEnter() |
|
406 | \sa QPieSlice::hoverEnter() | |
406 | */ |
|
407 | */ | |
407 |
|
408 | |||
408 | /*! |
|
409 | /*! | |
409 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) |
|
410 | \fn void QPieSeries::hoverLeave(QPieSlice* slice) | |
410 |
|
411 | |||
411 | This signal is emitted when user has hovered away from a \a slice. |
|
412 | This signal is emitted when user has hovered away from a \a slice. | |
412 |
|
413 | |||
413 | \sa QPieSlice::hoverLeave() |
|
414 | \sa QPieSlice::hoverLeave() | |
414 | */ |
|
415 | */ | |
415 |
|
416 | |||
416 | /*! |
|
417 | /*! | |
417 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
418 | \fn void QPieSeries::added(QList<QPieSlice*> slices) | |
418 |
|
419 | |||
419 | This signal is emitted when \a slices has been added to the series. |
|
420 | This signal is emitted when \a slices has been added to the series. | |
420 |
|
421 | |||
421 | \sa append(), insert() |
|
422 | \sa append(), insert() | |
422 | */ |
|
423 | */ | |
423 |
|
424 | |||
424 | /*! |
|
425 | /*! | |
425 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
426 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) | |
426 |
|
427 | |||
427 | This signal is emitted when \a slices has been removed from the series. |
|
428 | This signal is emitted when \a slices has been removed from the series. | |
428 |
|
429 | |||
429 | \sa remove(), clear() |
|
430 | \sa remove(), clear() | |
430 | */ |
|
431 | */ | |
431 |
|
432 | |||
432 | /*! |
|
433 | /*! | |
433 | \fn void QPieSeries::piePositionChanged() |
|
434 | \fn void QPieSeries::piePositionChanged() | |
434 |
|
435 | |||
435 | This signal is emitted when pie position has changed. |
|
436 | This signal is emitted when pie position has changed. | |
436 |
|
437 | |||
437 | \sa verticalPosition(), setVerticalPosition(), horizontalPosition(), setHorizontalPosition() |
|
438 | \sa verticalPosition(), setVerticalPosition(), horizontalPosition(), setHorizontalPosition() | |
438 | */ |
|
439 | */ | |
439 |
|
440 | |||
440 | /*! |
|
441 | /*! | |
441 | \fn void QPieSeries::pieSizeChanged() |
|
442 | \fn void QPieSeries::pieSizeChanged() | |
442 |
|
443 | |||
443 | This signal is emitted when pie size has changed. |
|
444 | This signal is emitted when pie size has changed. | |
444 |
|
445 | |||
445 | \sa pieSize(), setPieSize() |
|
446 | \sa pieSize(), setPieSize() | |
446 | */ |
|
447 | */ | |
447 |
|
448 | |||
448 | /*! |
|
449 | /*! | |
449 | \fn bool QPieSeries::setModel(QAbstractItemModel *model) |
|
450 | \fn bool QPieSeries::setModel(QAbstractItemModel *model) | |
450 | Sets the \a model to be used as a data source |
|
451 | Sets the \a model to be used as a data source | |
451 | */ |
|
452 | */ | |
452 | bool QPieSeries::setModel(QAbstractItemModel* model) |
|
453 | bool QPieSeries::setModel(QAbstractItemModel* model) | |
453 | { |
|
454 | { | |
454 | Q_D(QPieSeries); |
|
455 | Q_D(QPieSeries); | |
455 | // disconnect signals from old model |
|
456 | // disconnect signals from old model | |
456 | if(d->m_model) |
|
457 | if(d->m_model) | |
457 | { |
|
458 | { | |
458 | disconnect(d->m_model, 0, this, 0); |
|
459 | disconnect(d->m_model, 0, this, 0); | |
459 | d->m_mapValues = -1; |
|
460 | d->m_mapValues = -1; | |
460 | d->m_mapLabels = -1; |
|
461 | d->m_mapLabels = -1; | |
461 | d->m_mapOrientation = Qt::Vertical; |
|
462 | d->m_mapOrientation = Qt::Vertical; | |
462 | } |
|
463 | } | |
463 |
|
464 | |||
464 | // set new model |
|
465 | // set new model | |
465 | if(model) |
|
466 | if(model) | |
466 | { |
|
467 | { | |
467 | d->m_model = model; |
|
468 | d->m_model = model; | |
468 | return true; |
|
469 | return true; | |
469 | } |
|
470 | } | |
470 | else |
|
471 | else | |
471 | { |
|
472 | { | |
472 | d->m_model = 0; |
|
473 | d->m_model = 0; | |
473 | return false; |
|
474 | return false; | |
474 | } |
|
475 | } | |
475 | } |
|
476 | } | |
476 |
|
477 | |||
477 | /*! |
|
478 | /*! | |
478 | \fn bool QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) |
|
479 | \fn bool QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) | |
479 | Sets column/row specified by \a modelValuesLine to be used as a list of pie slice values for the pie. |
|
480 | Sets column/row specified by \a modelValuesLine to be used as a list of pie slice values for the pie. | |
480 | Parameter \a modelValuesLine indicates the column/row where the values for the pie slices are located in the model. |
|
481 | Parameter \a modelValuesLine indicates the column/row where the values for the pie slices are located in the model. | |
481 | Parameter \a modelLabelsLine indicates the column/row where the labels for the pie slices are located in the model. |
|
482 | Parameter \a modelLabelsLine indicates the column/row where the labels for the pie slices are located in the model. | |
482 | The \a orientation paramater specifies whether the data is in columns or in rows. |
|
483 | The \a orientation paramater specifies whether the data is in columns or in rows. | |
483 | */ |
|
484 | */ | |
484 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) |
|
485 | void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation) | |
485 | { |
|
486 | { | |
486 | Q_D(QPieSeries); |
|
487 | Q_D(QPieSeries); | |
487 |
|
488 | |||
488 | if (d->m_model == 0) |
|
489 | if (d->m_model == 0) | |
489 | return; |
|
490 | return; | |
490 |
|
491 | |||
491 | d->m_mapValues = modelValuesLine; |
|
492 | d->m_mapValues = modelValuesLine; | |
492 | d->m_mapLabels = modelLabelsLine; |
|
493 | d->m_mapLabels = modelLabelsLine; | |
493 | d->m_mapOrientation = orientation; |
|
494 | d->m_mapOrientation = orientation; | |
494 |
|
495 | |||
495 | // connect the signals |
|
496 | // connect the signals | |
496 | if (d->m_mapOrientation == Qt::Vertical) { |
|
497 | if (d->m_mapOrientation == Qt::Vertical) { | |
497 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
498 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
498 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
499 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
499 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
500 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
500 | } else { |
|
501 | } else { | |
501 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
502 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
502 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
503 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int))); | |
503 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
504 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
504 | } |
|
505 | } | |
505 |
|
506 | |||
506 | // create the initial slices set |
|
507 | // create the initial slices set | |
507 | if (d->m_mapOrientation == Qt::Vertical) { |
|
508 | if (d->m_mapOrientation == Qt::Vertical) { | |
508 | for (int i = 0; i < d->m_model->rowCount(); i++) |
|
509 | for (int i = 0; i < d->m_model->rowCount(); i++) | |
509 | append(d->m_model->data(d->m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), d->m_model->data(d->m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); |
|
510 | append(d->m_model->data(d->m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), d->m_model->data(d->m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString()); | |
510 | } else { |
|
511 | } else { | |
511 | for (int i = 0; i < d->m_model->columnCount(); i++) |
|
512 | for (int i = 0; i < d->m_model->columnCount(); i++) | |
512 | append(d->m_model->data(d->m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), d->m_model->data(d->m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); |
|
513 | append(d->m_model->data(d->m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), d->m_model->data(d->m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString()); | |
513 | } |
|
514 | } | |
514 | } |
|
515 | } | |
515 |
|
516 | |||
516 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
517 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
517 |
|
518 | |||
518 |
|
519 | |||
519 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) |
|
520 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) | |
520 | :QSeriesPrivate(parent), |
|
521 | :QSeriesPrivate(parent), | |
521 | m_pieRelativeHorPos(0.5), |
|
522 | m_pieRelativeHorPos(0.5), | |
522 | m_pieRelativeVerPos(0.5), |
|
523 | m_pieRelativeVerPos(0.5), | |
523 | m_pieRelativeSize(0.7), |
|
524 | m_pieRelativeSize(0.7), | |
524 | m_pieStartAngle(0), |
|
525 | m_pieStartAngle(0), | |
525 | m_pieEndAngle(360), |
|
526 | m_pieEndAngle(360), | |
526 | m_sum(0), |
|
527 | m_sum(0), | |
527 | m_mapValues(0), |
|
528 | m_mapValues(0), | |
528 | m_mapLabels(0), |
|
529 | m_mapLabels(0), | |
529 | m_mapOrientation(Qt::Horizontal) |
|
530 | m_mapOrientation(Qt::Horizontal) | |
530 | { |
|
531 | { | |
531 |
|
532 | |||
532 | } |
|
533 | } | |
533 |
|
534 | |||
534 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
535 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
535 | { |
|
536 | { | |
536 |
|
537 | |||
537 | } |
|
538 | } | |
538 |
|
539 | |||
539 | void QPieSeriesPrivate::updateDerivativeData() |
|
540 | void QPieSeriesPrivate::updateDerivativeData() | |
540 | { |
|
541 | { | |
541 | m_sum = 0; |
|
542 | m_sum = 0; | |
542 |
|
543 | |||
543 | // nothing to do? |
|
544 | // nothing to do? | |
544 | if (m_slices.count() == 0) |
|
545 | if (m_slices.count() == 0) | |
545 | return; |
|
546 | return; | |
546 |
|
547 | |||
547 | // calculate sum of all slices |
|
548 | // calculate sum of all slices | |
548 | foreach (QPieSlice* s, m_slices) |
|
549 | foreach (QPieSlice* s, m_slices) | |
549 | m_sum += s->value(); |
|
550 | m_sum += s->value(); | |
550 |
|
551 | |||
551 | // nothing to show.. |
|
552 | // nothing to show.. | |
552 | if (qFuzzyIsNull(m_sum)) |
|
553 | if (qFuzzyIsNull(m_sum)) | |
553 | return; |
|
554 | return; | |
554 |
|
555 | |||
555 | // update slice attributes |
|
556 | // update slice attributes | |
556 | qreal sliceAngle = m_pieStartAngle; |
|
557 | qreal sliceAngle = m_pieStartAngle; | |
557 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
558 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
558 | QVector<QPieSlice*> changed; |
|
559 | QVector<QPieSlice*> changed; | |
559 | foreach (QPieSlice* s, m_slices) { |
|
560 | foreach (QPieSlice* s, m_slices) { | |
560 |
|
561 | |||
561 | PieSliceData data = PieSliceData::data(s); |
|
562 | PieSliceData data = PieSliceData::data(s); | |
562 | data.m_percentage = s->value() / m_sum; |
|
563 | data.m_percentage = s->value() / m_sum; | |
563 | data.m_angleSpan = pieSpan * data.m_percentage; |
|
564 | data.m_angleSpan = pieSpan * data.m_percentage; | |
564 | data.m_startAngle = sliceAngle; |
|
565 | data.m_startAngle = sliceAngle; | |
565 | sliceAngle += data.m_angleSpan; |
|
566 | sliceAngle += data.m_angleSpan; | |
566 |
|
567 | |||
567 | if (PieSliceData::data(s) != data) { |
|
568 | if (PieSliceData::data(s) != data) { | |
568 | PieSliceData::data(s) = data; |
|
569 | PieSliceData::data(s) = data; | |
569 | changed << s; |
|
570 | changed << s; | |
570 | } |
|
571 | } | |
571 | } |
|
572 | } | |
572 |
|
573 | |||
573 | // emit signals |
|
574 | // emit signals | |
574 | foreach (QPieSlice* s, changed) |
|
575 | foreach (QPieSlice* s, changed) | |
575 | PieSliceData::data(s).emitChangedSignal(s); |
|
576 | PieSliceData::data(s).emitChangedSignal(s); | |
576 | } |
|
577 | } | |
577 |
|
578 | |||
578 | void QPieSeriesPrivate::sliceChanged() |
|
579 | void QPieSeriesPrivate::sliceChanged() | |
579 | { |
|
580 | { | |
580 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
581 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
581 | updateDerivativeData(); |
|
582 | updateDerivativeData(); | |
582 | } |
|
583 | } | |
583 |
|
584 | |||
584 | void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons) |
|
585 | void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons) | |
585 | { |
|
586 | { | |
586 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
587 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
587 | Q_ASSERT(m_slices.contains(slice)); |
|
588 | Q_ASSERT(m_slices.contains(slice)); | |
588 | Q_Q(QPieSeries); |
|
589 | Q_Q(QPieSeries); | |
589 | emit q->clicked(slice, buttons); |
|
590 | emit q->clicked(slice, buttons); | |
590 | } |
|
591 | } | |
591 |
|
592 | |||
592 | void QPieSeriesPrivate::sliceHoverEnter() |
|
593 | void QPieSeriesPrivate::sliceHoverEnter() | |
593 | { |
|
594 | { | |
594 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
595 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
595 | Q_ASSERT(m_slices.contains(slice)); |
|
596 | Q_ASSERT(m_slices.contains(slice)); | |
596 | Q_Q(QPieSeries); |
|
597 | Q_Q(QPieSeries); | |
597 | emit q->hoverEnter(slice); |
|
598 | emit q->hoverEnter(slice); | |
598 | } |
|
599 | } | |
599 |
|
600 | |||
600 | void QPieSeriesPrivate::sliceHoverLeave() |
|
601 | void QPieSeriesPrivate::sliceHoverLeave() | |
601 | { |
|
602 | { | |
602 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
603 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
603 | Q_ASSERT(m_slices.contains(slice)); |
|
604 | Q_ASSERT(m_slices.contains(slice)); | |
604 | Q_Q(QPieSeries); |
|
605 | Q_Q(QPieSeries); | |
605 | emit q->hoverLeave(slice); |
|
606 | emit q->hoverLeave(slice); | |
606 | } |
|
607 | } | |
607 |
|
608 | |||
608 | void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
609 | void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
609 | { |
|
610 | { | |
610 | Q_UNUSED(bottomRight) |
|
611 | Q_UNUSED(bottomRight) | |
611 |
|
612 | |||
612 | if (m_mapOrientation == Qt::Vertical) |
|
613 | if (m_mapOrientation == Qt::Vertical) | |
613 | { |
|
614 | { | |
614 | if (topLeft.column() == m_mapValues) |
|
615 | if (topLeft.column() == m_mapValues) | |
615 | if (m_mapValues == m_mapLabels) |
|
616 | if (m_mapValues == m_mapLabels) | |
616 | { |
|
617 | { | |
617 | m_slices.at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
618 | m_slices.at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
618 | m_slices.at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
619 | m_slices.at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
619 | } |
|
620 | } | |
620 | else |
|
621 | else | |
621 | { |
|
622 | { | |
622 | m_slices.at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
623 | m_slices.at(topLeft.row())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
623 | } |
|
624 | } | |
624 | else if (topLeft.column() == m_mapLabels) |
|
625 | else if (topLeft.column() == m_mapLabels) | |
625 | m_slices.at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
626 | m_slices.at(topLeft.row())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
626 | } |
|
627 | } | |
627 | else |
|
628 | else | |
628 | { |
|
629 | { | |
629 | if (topLeft.row() == m_mapValues) |
|
630 | if (topLeft.row() == m_mapValues) | |
630 | if (m_mapValues == m_mapLabels) |
|
631 | if (m_mapValues == m_mapLabels) | |
631 | { |
|
632 | { | |
632 | m_slices.at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
633 | m_slices.at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
633 | m_slices.at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
634 | m_slices.at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
634 | } |
|
635 | } | |
635 | else |
|
636 | else | |
636 | { |
|
637 | { | |
637 | m_slices.at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
638 | m_slices.at(topLeft.column())->setValue(m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
638 | } |
|
639 | } | |
639 | else if (topLeft.row() == m_mapLabels) |
|
640 | else if (topLeft.row() == m_mapLabels) | |
640 | m_slices.at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); |
|
641 | m_slices.at(topLeft.column())->setLabel(m_model->data(topLeft, Qt::DisplayRole).toString()); | |
641 | } |
|
642 | } | |
642 | } |
|
643 | } | |
643 |
|
644 | |||
644 | void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) |
|
645 | void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) | |
645 | { |
|
646 | { | |
646 | Q_UNUSED(parent) |
|
647 | Q_UNUSED(parent) | |
647 | Q_UNUSED(end) |
|
648 | Q_UNUSED(end) | |
648 | Q_Q(QPieSeries); |
|
649 | Q_Q(QPieSeries); | |
649 |
|
650 | |||
650 | QPieSlice* newSlice = new QPieSlice; |
|
651 | QPieSlice* newSlice = new QPieSlice; | |
651 | newSlice->setLabelVisible(true); |
|
652 | newSlice->setLabelVisible(true); | |
652 | if (m_mapOrientation == Qt::Vertical) |
|
653 | if (m_mapOrientation == Qt::Vertical) | |
653 | { |
|
654 | { | |
654 | newSlice->setValue(m_model->data(m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); |
|
655 | newSlice->setValue(m_model->data(m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble()); | |
655 | newSlice->setLabel(m_model->data(m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); |
|
656 | newSlice->setLabel(m_model->data(m_model->index(start, m_mapLabels), Qt::DisplayRole).toString()); | |
656 | } |
|
657 | } | |
657 | else |
|
658 | else | |
658 | { |
|
659 | { | |
659 | newSlice->setValue(m_model->data(m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); |
|
660 | newSlice->setValue(m_model->data(m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble()); | |
660 | newSlice->setLabel(m_model->data(m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); |
|
661 | newSlice->setLabel(m_model->data(m_model->index(m_mapLabels, start), Qt::DisplayRole).toString()); | |
661 | } |
|
662 | } | |
662 |
|
663 | |||
663 | q->insert(start, newSlice); |
|
664 | q->insert(start, newSlice); | |
664 | } |
|
665 | } | |
665 |
|
666 | |||
666 | void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) |
|
667 | void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) | |
667 | { |
|
668 | { | |
668 | Q_UNUSED(parent) |
|
669 | Q_UNUSED(parent) | |
669 | Q_UNUSED(end) |
|
670 | Q_UNUSED(end) | |
670 | Q_Q(QPieSeries); |
|
671 | Q_Q(QPieSeries); | |
671 | q->remove(m_slices.at(start)); |
|
672 | q->remove(m_slices.at(start)); | |
672 | } |
|
673 | } | |
673 |
|
674 | |||
674 | bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min) |
|
675 | bool QPieSeriesPrivate::setRealValue(qreal &value, qreal newValue, qreal max, qreal min) | |
675 | { |
|
676 | { | |
676 | // Remove rounding errors |
|
677 | // Remove rounding errors | |
677 | qreal roundedValue = newValue; |
|
678 | qreal roundedValue = newValue; | |
678 | if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue)) |
|
679 | if (qFuzzyIsNull(min) && qFuzzyIsNull(newValue)) | |
679 | roundedValue = 0.0; |
|
680 | roundedValue = 0.0; | |
680 | else if (qFuzzyCompare(newValue, max)) |
|
681 | else if (qFuzzyCompare(newValue, max)) | |
681 | roundedValue = max; |
|
682 | roundedValue = max; | |
682 | else if (qFuzzyCompare(newValue, min)) |
|
683 | else if (qFuzzyCompare(newValue, min)) | |
683 | roundedValue = min; |
|
684 | roundedValue = min; | |
684 |
|
685 | |||
685 | // Check if the position is valid after removing the rounding errors |
|
686 | // Check if the position is valid after removing the rounding errors | |
686 | if (roundedValue < min || roundedValue > max) { |
|
687 | if (roundedValue < min || roundedValue > max) { | |
687 | qWarning("QPieSeries: Illegal value"); |
|
688 | qWarning("QPieSeries: Illegal value"); | |
688 | return false; |
|
689 | return false; | |
689 | } |
|
690 | } | |
690 |
|
691 | |||
691 | if (!qFuzzyIsNull(value - roundedValue)) { |
|
692 | if (!qFuzzyIsNull(value - roundedValue)) { | |
692 | value = roundedValue; |
|
693 | value = roundedValue; | |
693 | return true; |
|
694 | return true; | |
694 | } |
|
695 | } | |
695 |
|
696 | |||
696 | // The change was so small it is considered a rounding error |
|
697 | // The change was so small it is considered a rounding error | |
697 | return false; |
|
698 | return false; | |
698 | } |
|
699 | } | |
699 |
|
700 | |||
700 | void QPieSeriesPrivate::scaleDomain(Domain& domain) |
|
701 | void QPieSeriesPrivate::scaleDomain(Domain& domain) | |
701 | { |
|
702 | { | |
702 | Q_UNUSED(domain); |
|
703 | Q_UNUSED(domain); | |
703 | #ifndef QT_NO_DEBUG |
|
704 | #ifndef QT_NO_DEBUG | |
704 | qWarning() << __FILE__<<__FUNCTION__<<"not implemented"; |
|
705 | qWarning() << __FILE__<<__FUNCTION__<<"not implemented"; | |
705 | #endif |
|
706 | #endif | |
706 | } |
|
707 | } | |
707 |
|
708 | |||
708 | Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
709 | Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
709 | { |
|
710 | { | |
710 | Q_Q(QPieSeries); |
|
711 | Q_Q(QPieSeries); | |
711 | PieChartItem* pie = new PieChartItem(q,presenter); |
|
712 | PieChartItem* pie = new PieChartItem(q,presenter); | |
712 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
713 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
713 | presenter->animator()->addAnimation(pie); |
|
714 | presenter->animator()->addAnimation(pie); | |
714 | } |
|
715 | } | |
715 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
716 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
716 | return pie; |
|
717 | return pie; | |
717 | } |
|
718 | } | |
718 |
|
719 | |||
|
720 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) | |||
|
721 | { | |||
|
722 | Q_Q(QPieSeries); | |||
|
723 | QList<LegendMarker*> markers; | |||
|
724 | foreach(QPieSlice* slice, q->slices()) { | |||
|
725 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); | |||
|
726 | markers << marker; | |||
|
727 | } | |||
|
728 | return markers; | |||
|
729 | } | |||
|
730 | ||||
719 | #include "moc_qpieseries.cpp" |
|
731 | #include "moc_qpieseries.cpp" | |
720 | #include "moc_qpieseries_p.cpp" |
|
732 | #include "moc_qpieseries_p.cpp" | |
721 |
|
733 | |||
722 | QTCOMMERCIALCHART_END_NAMESPACE |
|
734 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,73 +1,74 | |||||
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 QPIESERIES_P_H |
|
21 | #ifndef QPIESERIES_P_H | |
22 | #define QPIESERIES_P_H |
|
22 | #define QPIESERIES_P_H | |
23 |
|
23 | |||
24 | #include "qpieseries.h" |
|
24 | #include "qpieseries.h" | |
25 | #include "qseries_p.h" |
|
25 | #include "qseries_p.h" | |
26 |
|
26 | |||
27 | class QModelIndex; |
|
27 | class QModelIndex; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QPieSeriesPrivate : public QSeriesPrivate |
|
31 | class QPieSeriesPrivate : public QSeriesPrivate | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
|
34 | |||
35 | public: |
|
35 | public: | |
36 | QPieSeriesPrivate(QPieSeries *parent); |
|
36 | QPieSeriesPrivate(QPieSeries *parent); | |
37 | ~QPieSeriesPrivate(); |
|
37 | ~QPieSeriesPrivate(); | |
38 |
|
38 | |||
39 | void scaleDomain(Domain& domain); |
|
39 | void scaleDomain(Domain& domain); | |
40 | Chart* createGraphics(ChartPresenter* presenter); |
|
40 | Chart* createGraphics(ChartPresenter* presenter); | |
|
41 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |||
41 |
|
42 | |||
42 | void updateDerivativeData(); |
|
43 | void updateDerivativeData(); | |
43 |
|
44 | |||
44 | public Q_SLOTS: |
|
45 | public Q_SLOTS: | |
45 | void sliceChanged(); |
|
46 | void sliceChanged(); | |
46 | void sliceClicked(Qt::MouseButtons buttons); |
|
47 | void sliceClicked(Qt::MouseButtons buttons); | |
47 | void sliceHoverEnter(); |
|
48 | void sliceHoverEnter(); | |
48 | void sliceHoverLeave(); |
|
49 | void sliceHoverLeave(); | |
49 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
50 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
50 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
51 | void modelDataAdded(QModelIndex parent, int start, int end); | |
51 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
52 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
52 | bool setRealValue(qreal &value, qreal newValue, qreal max, qreal min = 0.0); |
|
53 | bool setRealValue(qreal &value, qreal newValue, qreal max, qreal min = 0.0); | |
53 |
|
54 | |||
54 | public: |
|
55 | public: | |
55 | QList<QPieSlice*> m_slices; |
|
56 | QList<QPieSlice*> m_slices; | |
56 | qreal m_pieRelativeHorPos; |
|
57 | qreal m_pieRelativeHorPos; | |
57 | qreal m_pieRelativeVerPos; |
|
58 | qreal m_pieRelativeVerPos; | |
58 | qreal m_pieRelativeSize; |
|
59 | qreal m_pieRelativeSize; | |
59 | qreal m_pieStartAngle; |
|
60 | qreal m_pieStartAngle; | |
60 | qreal m_pieEndAngle; |
|
61 | qreal m_pieEndAngle; | |
61 | qreal m_sum; |
|
62 | qreal m_sum; | |
62 |
|
63 | |||
63 | // model map |
|
64 | // model map | |
64 | int m_mapValues; |
|
65 | int m_mapValues; | |
65 | int m_mapLabels; |
|
66 | int m_mapLabels; | |
66 | Qt::Orientation m_mapOrientation; |
|
67 | Qt::Orientation m_mapOrientation; | |
67 | private: |
|
68 | private: | |
68 | Q_DECLARE_PUBLIC(QPieSeries) |
|
69 | Q_DECLARE_PUBLIC(QPieSeries) | |
69 | }; |
|
70 | }; | |
70 |
|
71 | |||
71 | QTCOMMERCIALCHART_END_NAMESPACE |
|
72 | QTCOMMERCIALCHART_END_NAMESPACE | |
72 |
|
73 | |||
73 | #endif // QPIESERIES_P_H |
|
74 | #endif // QPIESERIES_P_H |
@@ -1,413 +1,415 | |||||
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 "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
|
23 | #include "legendscroller_p.h" | |||
|
24 | #include "qlegend_p.h" | |||
23 | #include <QGraphicsScene> |
|
25 | #include <QGraphicsScene> | |
24 | #include <QGraphicsSceneResizeEvent> |
|
26 | #include <QGraphicsSceneResizeEvent> | |
25 |
|
27 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
29 | |||
28 | /*! |
|
30 | /*! | |
29 | \enum QChart::ChartTheme |
|
31 | \enum QChart::ChartTheme | |
30 |
|
32 | |||
31 | This enum describes the theme used by the chart. |
|
33 | This enum describes the theme used by the chart. | |
32 |
|
34 | |||
33 | \value ChartThemeLight The default theme |
|
35 | \value ChartThemeLight The default theme | |
34 | \value ChartThemeBlueCerulean |
|
36 | \value ChartThemeBlueCerulean | |
35 | \value ChartThemeDark |
|
37 | \value ChartThemeDark | |
36 | \value ChartThemeBrownSand |
|
38 | \value ChartThemeBrownSand | |
37 | \value ChartThemeBlueNcs |
|
39 | \value ChartThemeBlueNcs | |
38 | \value ChartThemeHighContrast |
|
40 | \value ChartThemeHighContrast | |
39 | \value ChartThemeBlueIcy |
|
41 | \value ChartThemeBlueIcy | |
40 | */ |
|
42 | */ | |
41 |
|
43 | |||
42 | /*! |
|
44 | /*! | |
43 | \enum QChart::AnimationOption |
|
45 | \enum QChart::AnimationOption | |
44 |
|
46 | |||
45 | For enabling/disabling animations. Defaults to NoAnimation. |
|
47 | For enabling/disabling animations. Defaults to NoAnimation. | |
46 |
|
48 | |||
47 | \value NoAnimation |
|
49 | \value NoAnimation | |
48 | \value GridAxisAnimations |
|
50 | \value GridAxisAnimations | |
49 | \value SeriesAnimations |
|
51 | \value SeriesAnimations | |
50 | \value AllAnimations |
|
52 | \value AllAnimations | |
51 | */ |
|
53 | */ | |
52 |
|
54 | |||
53 | /*! |
|
55 | /*! | |
54 | \class QChart |
|
56 | \class QChart | |
55 | \brief QtCommercial chart API. |
|
57 | \brief QtCommercial chart API. | |
56 |
|
58 | |||
57 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
59 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
58 | representation of different types of QChartSeries and other chart related objects like |
|
60 | representation of different types of QChartSeries and other chart related objects like | |
59 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
61 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
60 | convenience class QChartView instead of QChart. |
|
62 | convenience class QChartView instead of QChart. | |
61 | \sa QChartView |
|
63 | \sa QChartView | |
62 | */ |
|
64 | */ | |
63 |
|
65 | |||
64 | /*! |
|
66 | /*! | |
65 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
67 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
66 | */ |
|
68 | */ | |
67 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
69 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
68 | d_ptr(new QChartPrivate()) |
|
70 | d_ptr(new QChartPrivate()) | |
69 | { |
|
71 | { | |
70 | d_ptr->m_legend = new ScrolledQLegend(this); |
|
|||
71 | d_ptr->m_legend->setVisible(false); |
|
|||
72 | d_ptr->m_dataset = new ChartDataSet(this); |
|
72 | d_ptr->m_dataset = new ChartDataSet(this); | |
73 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
73 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); | |
74 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
|||
75 | d_ptr->createConnections(); |
|
74 | d_ptr->createConnections(); | |
|
75 | d_ptr->m_legend = new LegendScroller(this); | |||
|
76 | // d_ptr->m_legend->setVisible(false); | |||
|
77 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); | |||
|
78 | ||||
76 | //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); |
|
79 | //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); | |
77 | } |
|
80 | } | |
78 |
|
81 | |||
79 | /*! |
|
82 | /*! | |
80 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
83 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
81 | */ |
|
84 | */ | |
82 | QChart::~QChart() |
|
85 | QChart::~QChart() | |
83 | { |
|
86 | { | |
84 | //delete first presenter , since this is a root of all the graphical items |
|
87 | //delete first presenter , since this is a root of all the graphical items | |
85 | delete d_ptr->m_presenter; |
|
88 | delete d_ptr->m_presenter; | |
86 | d_ptr->m_presenter=0; |
|
89 | d_ptr->m_presenter=0; | |
87 | } |
|
90 | } | |
88 |
|
91 | |||
89 | /*! |
|
92 | /*! | |
90 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
93 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
91 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
94 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
92 | the y axis). |
|
95 | the y axis). | |
93 | */ |
|
96 | */ | |
94 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) |
|
97 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) | |
95 | { |
|
98 | { | |
96 | Q_ASSERT(series); |
|
99 | Q_ASSERT(series); | |
97 | d_ptr->m_dataset->addSeries(series, axisY); |
|
100 | d_ptr->m_dataset->addSeries(series, axisY); | |
98 | } |
|
101 | } | |
99 |
|
102 | |||
100 | /*! |
|
103 | /*! | |
101 | Removes the \a series specified in a perameter from the QChartView. |
|
104 | Removes the \a series specified in a perameter from the QChartView. | |
102 | It releses its ownership of the specified QChartSeries object. |
|
105 | It releses its ownership of the specified QChartSeries object. | |
103 | It does not delete the pointed QChartSeries data object |
|
106 | It does not delete the pointed QChartSeries data object | |
104 | \sa addSeries(), removeAllSeries() |
|
107 | \sa addSeries(), removeAllSeries() | |
105 | */ |
|
108 | */ | |
106 | void QChart::removeSeries(QSeries* series) |
|
109 | void QChart::removeSeries(QSeries* series) | |
107 | { |
|
110 | { | |
108 | Q_ASSERT(series); |
|
111 | Q_ASSERT(series); | |
109 | d_ptr->m_dataset->removeSeries(series); |
|
112 | d_ptr->m_dataset->removeSeries(series); | |
110 | } |
|
113 | } | |
111 |
|
114 | |||
112 | /*! |
|
115 | /*! | |
113 | Removes all the QChartSeries that have been added to the QChartView |
|
116 | Removes all the QChartSeries that have been added to the QChartView | |
114 | It also deletes the pointed QChartSeries data objects |
|
117 | It also deletes the pointed QChartSeries data objects | |
115 | \sa addSeries(), removeSeries() |
|
118 | \sa addSeries(), removeSeries() | |
116 | */ |
|
119 | */ | |
117 | void QChart::removeAllSeries() |
|
120 | void QChart::removeAllSeries() | |
118 | { |
|
121 | { | |
119 | d_ptr->m_dataset->removeAllSeries(); |
|
122 | d_ptr->m_dataset->removeAllSeries(); | |
120 | } |
|
123 | } | |
121 |
|
124 | |||
122 | /*! |
|
125 | /*! | |
123 | Sets the \a brush that is used for painting the background of the chart area. |
|
126 | Sets the \a brush that is used for painting the background of the chart area. | |
124 | */ |
|
127 | */ | |
125 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
128 | void QChart::setBackgroundBrush(const QBrush& brush) | |
126 | { |
|
129 | { | |
127 | //TODO: refactor me |
|
130 | //TODO: refactor me | |
128 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
131 | d_ptr->m_presenter->createChartBackgroundItem(); | |
129 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); |
|
132 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); | |
130 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
133 | d_ptr->m_presenter->m_backgroundItem->update(); | |
131 | } |
|
134 | } | |
132 |
|
135 | |||
133 | /*! |
|
136 | /*! | |
134 | Gets the brush that is used for painting the background of the chart area. |
|
137 | Gets the brush that is used for painting the background of the chart area. | |
135 | */ |
|
138 | */ | |
136 | QBrush QChart::backgroundBrush() const |
|
139 | QBrush QChart::backgroundBrush() const | |
137 | { |
|
140 | { | |
138 | //TODO: refactor me |
|
141 | //TODO: refactor me | |
139 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); |
|
142 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); | |
140 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); |
|
143 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); | |
141 | } |
|
144 | } | |
142 |
|
145 | |||
143 | /*! |
|
146 | /*! | |
144 | Sets the \a pen that is used for painting the background of the chart area. |
|
147 | Sets the \a pen that is used for painting the background of the chart area. | |
145 | */ |
|
148 | */ | |
146 | void QChart::setBackgroundPen(const QPen& pen) |
|
149 | void QChart::setBackgroundPen(const QPen& pen) | |
147 | { |
|
150 | { | |
148 | //TODO: refactor me |
|
151 | //TODO: refactor me | |
149 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
152 | d_ptr->m_presenter->createChartBackgroundItem(); | |
150 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); |
|
153 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); | |
151 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
154 | d_ptr->m_presenter->m_backgroundItem->update(); | |
152 | } |
|
155 | } | |
153 |
|
156 | |||
154 | /*! |
|
157 | /*! | |
155 | Gets the pen that is used for painting the background of the chart area. |
|
158 | Gets the pen that is used for painting the background of the chart area. | |
156 | */ |
|
159 | */ | |
157 | QPen QChart::backgroundPen() const |
|
160 | QPen QChart::backgroundPen() const | |
158 | { |
|
161 | { | |
159 | //TODO: refactor me |
|
162 | //TODO: refactor me | |
160 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); |
|
163 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); | |
161 | return d_ptr->m_presenter->m_backgroundItem->pen(); |
|
164 | return d_ptr->m_presenter->m_backgroundItem->pen(); | |
162 | } |
|
165 | } | |
163 |
|
166 | |||
164 | /*! |
|
167 | /*! | |
165 | Sets the chart \a title. The description text that is drawn above the chart. |
|
168 | Sets the chart \a title. The description text that is drawn above the chart. | |
166 | */ |
|
169 | */ | |
167 | void QChart::setTitle(const QString& title) |
|
170 | void QChart::setTitle(const QString& title) | |
168 | { |
|
171 | { | |
169 | //TODO: refactor me |
|
172 | //TODO: refactor me | |
170 | d_ptr->m_presenter->createChartTitleItem(); |
|
173 | d_ptr->m_presenter->createChartTitleItem(); | |
171 | d_ptr->m_presenter->m_titleItem->setText(title); |
|
174 | d_ptr->m_presenter->m_titleItem->setText(title); | |
172 | d_ptr->m_presenter->updateLayout(); |
|
175 | d_ptr->m_presenter->updateLayout(); | |
173 | } |
|
176 | } | |
174 |
|
177 | |||
175 | /*! |
|
178 | /*! | |
176 | Returns the chart title. The description text that is drawn above the chart. |
|
179 | Returns the chart title. The description text that is drawn above the chart. | |
177 | */ |
|
180 | */ | |
178 | QString QChart::title() const |
|
181 | QString QChart::title() const | |
179 | { |
|
182 | { | |
180 | //TODO: refactor me |
|
183 | //TODO: refactor me | |
181 | if (d_ptr->m_presenter->m_titleItem) |
|
184 | if (d_ptr->m_presenter->m_titleItem) | |
182 | return d_ptr->m_presenter->m_titleItem->text(); |
|
185 | return d_ptr->m_presenter->m_titleItem->text(); | |
183 | else |
|
186 | else | |
184 | return QString(); |
|
187 | return QString(); | |
185 | } |
|
188 | } | |
186 |
|
189 | |||
187 | /*! |
|
190 | /*! | |
188 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
191 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. | |
189 | */ |
|
192 | */ | |
190 | void QChart::setTitleFont(const QFont& font) |
|
193 | void QChart::setTitleFont(const QFont& font) | |
191 | { |
|
194 | { | |
192 | //TODO: refactor me |
|
195 | //TODO: refactor me | |
193 | d_ptr->m_presenter->createChartTitleItem(); |
|
196 | d_ptr->m_presenter->createChartTitleItem(); | |
194 | d_ptr->m_presenter->m_titleItem->setFont(font); |
|
197 | d_ptr->m_presenter->m_titleItem->setFont(font); | |
195 | d_ptr->m_presenter->updateLayout(); |
|
198 | d_ptr->m_presenter->updateLayout(); | |
196 | } |
|
199 | } | |
197 |
|
200 | |||
198 | /*! |
|
201 | /*! | |
199 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
202 | Gets the font that is used for drawing the chart description text that is rendered above the chart. | |
200 | */ |
|
203 | */ | |
201 | QFont QChart::titleFont() const |
|
204 | QFont QChart::titleFont() const | |
202 | { |
|
205 | { | |
203 | if (d_ptr->m_presenter->m_titleItem) |
|
206 | if (d_ptr->m_presenter->m_titleItem) | |
204 | return d_ptr->m_presenter->m_titleItem->font(); |
|
207 | return d_ptr->m_presenter->m_titleItem->font(); | |
205 | else |
|
208 | else | |
206 | return QFont(); |
|
209 | return QFont(); | |
207 | } |
|
210 | } | |
208 |
|
211 | |||
209 | /*! |
|
212 | /*! | |
210 | Sets the \a brush used for rendering the title text. |
|
213 | Sets the \a brush used for rendering the title text. | |
211 | */ |
|
214 | */ | |
212 | void QChart::setTitleBrush(const QBrush &brush) |
|
215 | void QChart::setTitleBrush(const QBrush &brush) | |
213 | { |
|
216 | { | |
214 | //TODO: refactor me |
|
217 | //TODO: refactor me | |
215 | d_ptr->m_presenter->createChartTitleItem(); |
|
218 | d_ptr->m_presenter->createChartTitleItem(); | |
216 | d_ptr->m_presenter->m_titleItem->setBrush(brush); |
|
219 | d_ptr->m_presenter->m_titleItem->setBrush(brush); | |
217 | d_ptr->m_presenter->updateLayout(); |
|
220 | d_ptr->m_presenter->updateLayout(); | |
218 | } |
|
221 | } | |
219 |
|
222 | |||
220 | /*! |
|
223 | /*! | |
221 | Returns the brush used for rendering the title text. |
|
224 | Returns the brush used for rendering the title text. | |
222 | */ |
|
225 | */ | |
223 | QBrush QChart::titleBrush() const |
|
226 | QBrush QChart::titleBrush() const | |
224 | { |
|
227 | { | |
225 | //TODO: refactor me |
|
228 | //TODO: refactor me | |
226 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); |
|
229 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); | |
227 | return d_ptr->m_presenter->m_titleItem->brush(); |
|
230 | return d_ptr->m_presenter->m_titleItem->brush(); | |
228 | } |
|
231 | } | |
229 |
|
232 | |||
230 | /*! |
|
233 | /*! | |
231 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
234 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
232 | \sa theme() |
|
235 | \sa theme() | |
233 | */ |
|
236 | */ | |
234 | void QChart::setTheme(QChart::ChartTheme theme) |
|
237 | void QChart::setTheme(QChart::ChartTheme theme) | |
235 | { |
|
238 | { | |
236 | d_ptr->m_presenter->setTheme(theme); |
|
239 | d_ptr->m_presenter->setTheme(theme); | |
237 | } |
|
240 | } | |
238 |
|
241 | |||
239 | /*! |
|
242 | /*! | |
240 | Returns the theme enum used by the chart. |
|
243 | Returns the theme enum used by the chart. | |
241 | \sa ChartTheme, setTheme() |
|
244 | \sa ChartTheme, setTheme() | |
242 | */ |
|
245 | */ | |
243 | QChart::ChartTheme QChart::theme() const |
|
246 | QChart::ChartTheme QChart::theme() const | |
244 | { |
|
247 | { | |
245 | return d_ptr->m_presenter->theme(); |
|
248 | return d_ptr->m_presenter->theme(); | |
246 | } |
|
249 | } | |
247 |
|
250 | |||
248 | /*! |
|
251 | /*! | |
249 | Zooms in the view by a factor of 2 |
|
252 | Zooms in the view by a factor of 2 | |
250 | */ |
|
253 | */ | |
251 | void QChart::zoomIn() |
|
254 | void QChart::zoomIn() | |
252 | { |
|
255 | { | |
253 | d_ptr->m_presenter->zoomIn(); |
|
256 | d_ptr->m_presenter->zoomIn(); | |
254 | } |
|
257 | } | |
255 |
|
258 | |||
256 | /*! |
|
259 | /*! | |
257 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
260 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
258 | */ |
|
261 | */ | |
259 | void QChart::zoomIn(const QRectF& rect) |
|
262 | void QChart::zoomIn(const QRectF& rect) | |
260 | { |
|
263 | { | |
261 | if (!rect.isValid()) return; |
|
264 | if (!rect.isValid()) return; | |
262 | d_ptr->m_presenter->zoomIn(rect); |
|
265 | d_ptr->m_presenter->zoomIn(rect); | |
263 | } |
|
266 | } | |
264 |
|
267 | |||
265 | /*! |
|
268 | /*! | |
266 | Restores the view zoom level to the previous one. |
|
269 | Restores the view zoom level to the previous one. | |
267 | */ |
|
270 | */ | |
268 | void QChart::zoomOut() |
|
271 | void QChart::zoomOut() | |
269 | { |
|
272 | { | |
270 | d_ptr->m_presenter->zoomOut(); |
|
273 | d_ptr->m_presenter->zoomOut(); | |
271 | } |
|
274 | } | |
272 |
|
275 | |||
273 | /*! |
|
276 | /*! | |
274 | Returns the pointer to the x axis object of the chart |
|
277 | Returns the pointer to the x axis object of the chart | |
275 | */ |
|
278 | */ | |
276 | QChartAxis* QChart::axisX() const |
|
279 | QChartAxis* QChart::axisX() const | |
277 | { |
|
280 | { | |
278 | return d_ptr->m_dataset->axisX(); |
|
281 | return d_ptr->m_dataset->axisX(); | |
279 | } |
|
282 | } | |
280 |
|
283 | |||
281 | /*! |
|
284 | /*! | |
282 | Returns the pointer to the y axis object of the \a series |
|
285 | Returns the pointer to the y axis object of the \a series | |
283 | If no \a series is provided then default Y axis of the chart is returned. |
|
286 | If no \a series is provided then default Y axis of the chart is returned. | |
284 | */ |
|
287 | */ | |
285 | QChartAxis* QChart::axisY(QSeries* series) const |
|
288 | QChartAxis* QChart::axisY(QSeries* series) const | |
286 | { |
|
289 | { | |
287 | return d_ptr->m_dataset->axisY(series); |
|
290 | return d_ptr->m_dataset->axisY(series); | |
288 | } |
|
291 | } | |
289 |
|
292 | |||
290 | /*! |
|
293 | /*! | |
291 | Returns the legend object of the chart. Ownership stays in chart. |
|
294 | Returns the legend object of the chart. Ownership stays in chart. | |
292 | */ |
|
295 | */ | |
293 | QLegend* QChart::legend() const |
|
296 | QLegend* QChart::legend() const | |
294 | { |
|
297 | { | |
295 | return d_ptr->m_legend; |
|
298 | return d_ptr->m_legend; | |
296 | } |
|
299 | } | |
297 |
|
300 | |||
298 | /*! |
|
301 | /*! | |
299 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
302 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
300 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
303 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
301 | */ |
|
304 | */ | |
302 | QRectF QChart::margins() const |
|
305 | QRectF QChart::margins() const | |
303 | { |
|
306 | { | |
304 | return d_ptr->m_presenter->margins(); |
|
307 | return d_ptr->m_presenter->margins(); | |
305 | } |
|
308 | } | |
306 |
|
309 | |||
307 |
|
310 | |||
308 | /*! |
|
311 | /*! | |
309 | Resizes and updates the chart area using the \a event data |
|
312 | Resizes and updates the chart area using the \a event data | |
310 | */ |
|
313 | */ | |
311 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
314 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
312 | { |
|
315 | { | |
313 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
316 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); | |
314 | QGraphicsWidget::resizeEvent(event); |
|
317 | QGraphicsWidget::resizeEvent(event); | |
315 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); |
|
318 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); | |
316 | } |
|
319 | } | |
317 |
|
320 | |||
318 | /*! |
|
321 | /*! | |
319 | Sets animation \a options for the chart |
|
322 | Sets animation \a options for the chart | |
320 | */ |
|
323 | */ | |
321 | void QChart::setAnimationOptions(AnimationOptions options) |
|
324 | void QChart::setAnimationOptions(AnimationOptions options) | |
322 | { |
|
325 | { | |
323 | d_ptr->m_presenter->setAnimationOptions(options); |
|
326 | d_ptr->m_presenter->setAnimationOptions(options); | |
324 | } |
|
327 | } | |
325 |
|
328 | |||
326 | /*! |
|
329 | /*! | |
327 | Returns animation options for the chart |
|
330 | Returns animation options for the chart | |
328 | */ |
|
331 | */ | |
329 | QChart::AnimationOptions QChart::animationOptions() const |
|
332 | QChart::AnimationOptions QChart::animationOptions() const | |
330 | { |
|
333 | { | |
331 | return d_ptr->m_presenter->animationOptions(); |
|
334 | return d_ptr->m_presenter->animationOptions(); | |
332 | } |
|
335 | } | |
333 |
|
336 | |||
334 | /*! |
|
337 | /*! | |
335 | Scrolls the visible area of the chart to the left by the distance between two x axis ticks |
|
338 | Scrolls the visible area of the chart to the left by the distance between two x axis ticks | |
336 | */ |
|
339 | */ | |
337 | void QChart::scrollLeft() |
|
340 | void QChart::scrollLeft() | |
338 | { |
|
341 | { | |
339 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
342 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
340 | } |
|
343 | } | |
341 |
|
344 | |||
342 | /*! |
|
345 | /*! | |
343 | Scrolls the visible area of the chart to the right by the distance between two x axis ticks |
|
346 | Scrolls the visible area of the chart to the right by the distance between two x axis ticks | |
344 | */ |
|
347 | */ | |
345 | void QChart::scrollRight() |
|
348 | void QChart::scrollRight() | |
346 | { |
|
349 | { | |
347 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
350 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
348 | } |
|
351 | } | |
349 |
|
352 | |||
350 | /*! |
|
353 | /*! | |
351 | Scrolls the visible area of the chart up by the distance between two y axis ticks |
|
354 | Scrolls the visible area of the chart up by the distance between two y axis ticks | |
352 | */ |
|
355 | */ | |
353 | void QChart::scrollUp() |
|
356 | void QChart::scrollUp() | |
354 | { |
|
357 | { | |
355 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
358 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
356 | } |
|
359 | } | |
357 |
|
360 | |||
358 | /*! |
|
361 | /*! | |
359 | Scrolls the visible area of the chart down by the distance between two y axis ticks |
|
362 | Scrolls the visible area of the chart down by the distance between two y axis ticks | |
360 | */ |
|
363 | */ | |
361 | void QChart::scrollDown() |
|
364 | void QChart::scrollDown() | |
362 | { |
|
365 | { | |
363 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
366 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
364 | } |
|
367 | } | |
365 |
|
368 | |||
366 | /*! |
|
369 | /*! | |
367 | Sets the chart background visibility state to \a visible |
|
370 | Sets the chart background visibility state to \a visible | |
368 | */ |
|
371 | */ | |
369 | void QChart::setBackgroundVisible(bool visible) |
|
372 | void QChart::setBackgroundVisible(bool visible) | |
370 | { |
|
373 | { | |
371 | //TODO: refactor me |
|
374 | //TODO: refactor me | |
372 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
375 | d_ptr->m_presenter->createChartBackgroundItem(); | |
373 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); |
|
376 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); | |
374 | } |
|
377 | } | |
375 |
|
378 | |||
376 | /*! |
|
379 | /*! | |
377 | Returns the chart's background visibility state |
|
380 | Returns the chart's background visibility state | |
378 | */ |
|
381 | */ | |
379 | bool QChart::isBackgroundVisible() const |
|
382 | bool QChart::isBackgroundVisible() const | |
380 | { |
|
383 | { | |
381 | //TODO: refactor me |
|
384 | //TODO: refactor me | |
382 | if (!d_ptr->m_presenter->m_backgroundItem) return false; |
|
385 | if (!d_ptr->m_presenter->m_backgroundItem) return false; | |
383 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); |
|
386 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); | |
384 | } |
|
387 | } | |
385 |
|
388 | |||
386 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
389 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
387 |
|
390 | |||
388 | QChartPrivate::QChartPrivate(): |
|
391 | QChartPrivate::QChartPrivate(): | |
389 | m_legend(0), |
|
392 | m_legend(0), | |
390 | m_dataset(0), |
|
393 | m_dataset(0), | |
391 | m_presenter(0) |
|
394 | m_presenter(0) | |
392 | { |
|
395 | { | |
393 |
|
396 | |||
394 | } |
|
397 | } | |
395 |
|
398 | |||
396 | QChartPrivate::~QChartPrivate() |
|
399 | QChartPrivate::~QChartPrivate() | |
397 | { |
|
400 | { | |
398 |
|
401 | |||
399 | } |
|
402 | } | |
400 |
|
403 | |||
401 | void QChartPrivate::createConnections() |
|
404 | void QChartPrivate::createConnections() | |
402 | { |
|
405 | { | |
403 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
406 | ||
404 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
|||
405 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
407 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
406 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_presenter,SLOT(handleSeriesRemoved(QSeries*))); |
|
408 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_presenter,SLOT(handleSeriesRemoved(QSeries*))); | |
407 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QChartAxis*,Domain*))); |
|
409 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QChartAxis*,Domain*))); | |
408 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),m_presenter,SLOT(handleAxisRemoved(QChartAxis*))); |
|
410 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),m_presenter,SLOT(handleAxisRemoved(QChartAxis*))); | |
409 | } |
|
411 | } | |
410 |
|
412 | |||
411 | #include "moc_qchart.cpp" |
|
413 | #include "moc_qchart.cpp" | |
412 |
|
414 | |||
413 | QTCOMMERCIALCHART_END_NAMESPACE |
|
415 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,533 +1,428 | |||||
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 "qlegend.h" |
|
21 | #include "qlegend.h" | |
22 |
#include "q |
|
22 | #include "qlegend_p.h" | |
23 | #include "qseries.h" |
|
23 | #include "qseries.h" | |
|
24 | #include "qseries_p.h" | |||
|
25 | #include "qchart_p.h" | |||
|
26 | ||||
24 | #include "legendmarker_p.h" |
|
27 | #include "legendmarker_p.h" | |
25 | #include "qxyseries.h" |
|
28 | #include "qxyseries.h" | |
26 | #include "qlineseries.h" |
|
29 | #include "qlineseries.h" | |
27 | #include "qareaseries.h" |
|
30 | #include "qareaseries.h" | |
28 | #include "qscatterseries.h" |
|
31 | #include "qscatterseries.h" | |
29 | #include "qsplineseries.h" |
|
32 | #include "qsplineseries.h" | |
30 | #include "qbarseries.h" |
|
33 | #include "qbarseries.h" | |
31 | #include "qstackedbarseries.h" |
|
34 | #include "qstackedbarseries.h" | |
32 | #include "qpercentbarseries.h" |
|
35 | #include "qpercentbarseries.h" | |
33 | #include "qbarset.h" |
|
36 | #include "qbarset.h" | |
34 | #include "qpieseries.h" |
|
37 | #include "qpieseries.h" | |
35 | #include "qpieslice.h" |
|
38 | #include "qpieslice.h" | |
36 | #include "chartpresenter_p.h" |
|
39 | #include "chartpresenter_p.h" | |
37 | #include <QPainter> |
|
40 | #include <QPainter> | |
38 | #include <QPen> |
|
41 | #include <QPen> | |
39 | #include <QTimer> |
|
42 | #include <QTimer> | |
40 |
|
43 | |||
41 | #include <QGraphicsSceneEvent> |
|
44 | #include <QGraphicsSceneEvent> | |
42 |
|
45 | |||
43 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
46 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
44 |
|
47 | |||
45 | /*! |
|
48 | /*! | |
46 |
|
|
49 | \class QLegend | |
47 |
|
|
50 | \brief part of QtCommercial chart API. | |
48 |
|
51 | |||
49 |
|
|
52 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when | |
50 |
|
|
53 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
51 |
|
|
54 | handle the drawing manually. | |
52 |
|
|
55 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
53 |
|
56 | |||
54 |
|
|
57 | \mainclass | |
55 |
|
58 | |||
56 |
|
|
59 | \sa QChart, QSeries | |
57 | */ |
|
60 | */ | |
58 |
|
61 | |||
59 | /*! |
|
62 | /*! | |
60 |
|
|
63 | \enum QLegend::Alignment | |
61 |
|
64 | |||
62 |
|
|
65 | This enum describes the possible position for legend inside chart. | |
63 |
|
66 | |||
64 |
|
|
67 | \value AlignmentTop | |
65 |
|
|
68 | \value AlignmentBottom | |
66 |
|
|
69 | \value AlignmentLeft | |
67 |
|
|
70 | \value AlignmentRight | |
68 | */ |
|
71 | */ | |
69 |
|
72 | |||
70 | /*! |
|
73 | /*! | |
71 |
|
|
74 | \fn qreal QLegend::minWidth() const | |
72 |
|
|
75 | Returns minimum width of the legend | |
73 | */ |
|
76 | */ | |
74 |
|
77 | |||
75 | /*! |
|
78 | /*! | |
76 |
|
|
79 | \fn qreal QLegend::minHeight() const | |
77 |
|
|
80 | Returns minimum height of the legend | |
78 | */ |
|
81 | */ | |
79 |
|
82 | |||
80 | /*! |
|
83 | /*! | |
81 |
|
|
84 | Constructs the legend object and sets the parent to \a parent | |
82 | */ |
|
85 | */ | |
83 |
|
86 | |||
84 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), |
|
87 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), | |
85 | m_margin(5), |
|
88 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,this)) | |
86 | m_offsetX(0), |
|
|||
87 | m_offsetY(0), |
|
|||
88 | m_brush(Qt::darkGray), // TODO: default should come from theme |
|
|||
89 | m_alignment(QLegend::AlignmentTop), |
|
|||
90 | m_markers(new QGraphicsItemGroup(this)), |
|
|||
91 | m_attachedToChart(true), |
|
|||
92 | m_chart(chart), |
|
|||
93 | m_minWidth(0), |
|
|||
94 | m_minHeight(0), |
|
|||
95 | m_width(0), |
|
|||
96 | m_height(0), |
|
|||
97 | m_backgroundVisible(false) |
|
|||
98 | { |
|
89 | { | |
99 | setZValue(ChartPresenter::LegendZValue); |
|
90 | setZValue(ChartPresenter::LegendZValue); | |
100 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
91 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
101 |
set |
|
92 | setEnabled(false); // By default legend is disabled | |
|
93 | ||||
|
94 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QSeries*,Domain*))); | |||
|
95 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QSeries*))); | |||
|
96 | } | |||
|
97 | ||||
|
98 | QLegend::~QLegend() | |||
|
99 | { | |||
|
100 | ||||
102 | } |
|
101 | } | |
103 |
|
102 | |||
104 | /*! |
|
103 | /*! | |
105 |
|
|
104 | Paints the legend to given \a painter. Paremeters \a option and \a widget arent used. | |
106 | */ |
|
105 | */ | |
107 |
|
106 | |||
108 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
107 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
109 | { |
|
108 | { | |
110 |
|
|
109 | Q_UNUSED(option) | |
111 |
|
|
110 | Q_UNUSED(widget) | |
112 | if(!m_backgroundVisible) return; |
|
111 | if(!d_ptr->m_backgroundVisible) return; | |
113 |
|
112 | |||
114 | painter->setOpacity(opacity()); |
|
113 | painter->setOpacity(opacity()); | |
115 | painter->setPen(m_pen); |
|
114 | painter->setPen(d_ptr->m_pen); | |
116 | painter->setBrush(m_brush); |
|
115 | painter->setBrush(d_ptr->m_brush); | |
117 | painter->drawRect(boundingRect()); |
|
116 | painter->drawRect(boundingRect()); | |
118 | } |
|
117 | } | |
119 |
|
118 | |||
120 | /*! |
|
119 | /*! | |
121 |
|
|
120 | Bounding rect of legend. | |
122 | */ |
|
121 | */ | |
123 |
|
122 | |||
124 | QRectF QLegend::boundingRect() const |
|
123 | QRectF QLegend::boundingRect() const | |
125 | { |
|
124 | { | |
126 | return m_rect; |
|
125 | return d_ptr->m_rect; | |
127 | } |
|
126 | } | |
128 |
|
127 | |||
129 | /*! |
|
128 | /*! | |
130 |
|
|
129 | Sets the \a brush of legend. Brush affects the background of legend. | |
131 | */ |
|
130 | */ | |
132 | void QLegend::setBrush(const QBrush &brush) |
|
131 | void QLegend::setBrush(const QBrush &brush) | |
133 | { |
|
132 | { | |
134 | if (m_brush != brush) { |
|
133 | if (d_ptr->m_brush != brush) { | |
135 | m_brush = brush; |
|
134 | d_ptr->m_brush = brush; | |
136 | update(); |
|
135 | update(); | |
137 | } |
|
136 | } | |
138 | } |
|
137 | } | |
139 |
|
138 | |||
140 | /*! |
|
139 | /*! | |
141 |
|
|
140 | Returns the brush used by legend. | |
142 | */ |
|
141 | */ | |
143 | QBrush QLegend::brush() const |
|
142 | QBrush QLegend::brush() const | |
144 | { |
|
143 | { | |
145 | return m_brush; |
|
144 | return d_ptr->m_brush; | |
146 | } |
|
145 | } | |
147 |
|
146 | |||
148 | /*! |
|
147 | /*! | |
149 |
|
|
148 | Sets the \a pen of legend. Pen affects the legend borders. | |
150 | */ |
|
149 | */ | |
151 | void QLegend::setPen(const QPen &pen) |
|
150 | void QLegend::setPen(const QPen &pen) | |
152 | { |
|
151 | { | |
153 | if (m_pen != pen) { |
|
152 | if (d_ptr->m_pen != pen) { | |
154 | m_pen = pen; |
|
153 | d_ptr->m_pen = pen; | |
155 | update(); |
|
154 | update(); | |
156 | } |
|
155 | } | |
157 | } |
|
156 | } | |
158 |
|
157 | |||
159 | /*! |
|
158 | /*! | |
160 |
|
|
159 | Returns the pen used by legend | |
161 | */ |
|
160 | */ | |
162 |
|
161 | |||
163 | QPen QLegend::pen() const |
|
162 | QPen QLegend::pen() const | |
164 | { |
|
163 | { | |
165 | return m_pen; |
|
164 | return d_ptr->m_pen; | |
166 | } |
|
165 | } | |
167 |
|
166 | |||
168 | /*! |
|
167 | /*! | |
169 |
|
|
168 | Sets the \a alignment for legend. Legend tries to paint itself on the defined position in chart. | |
170 |
|
|
169 | \sa QLegend::Alignment | |
171 | */ |
|
170 | */ | |
172 | void QLegend::setAlignment(QLegend::Alignments alignment) |
|
171 | void QLegend::setAlignment(QLegend::Alignments alignment) | |
173 | { |
|
172 | { | |
174 | if(m_alignment!=alignment && m_attachedToChart) { |
|
173 | if(d_ptr->m_alignment!=alignment && d_ptr->m_attachedToChart) { | |
175 | m_alignment = alignment; |
|
174 | d_ptr->m_alignment = alignment; | |
176 | updateLayout(); |
|
175 | d_ptr->updateLayout(); | |
177 | } |
|
176 | } | |
178 | } |
|
177 | } | |
179 |
|
178 | |||
180 | /*! |
|
179 | /*! | |
181 |
|
|
180 | Returns the preferred layout for legend | |
182 | */ |
|
181 | */ | |
183 | QLegend::Alignments QLegend::alignment() const |
|
182 | QLegend::Alignments QLegend::alignment() const | |
184 | { |
|
183 | { | |
185 | return m_alignment; |
|
184 | return d_ptr->m_alignment; | |
186 | } |
|
185 | } | |
187 |
|
186 | |||
188 | /*! |
|
187 | /*! | |
189 | \internal \a series \a domain Should be called when series is added to chart. |
|
188 | Detaches the legend from chart. Chart won't change layout of the legend. | |
190 | */ |
|
189 | */ | |
191 | void QLegend::handleSeriesAdded(QSeries *series, Domain *domain) |
|
190 | void QLegend::detachFromChart() | |
192 | { |
|
|||
193 | Q_UNUSED(domain) |
|
|||
194 |
|
||||
195 | switch (series->type()) |
|
|||
196 | { |
|
191 | { | |
197 | case QSeries::SeriesTypeLine: { |
|
192 | d_ptr->m_attachedToChart = false; | |
198 | QLineSeries *lineSeries = static_cast<QLineSeries *>(series); |
|
|||
199 | appendMarkers(lineSeries); |
|
|||
200 | break; |
|
|||
201 | } |
|
|||
202 | case QSeries::SeriesTypeArea: { |
|
|||
203 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); |
|
|||
204 | appendMarkers(areaSeries); |
|
|||
205 | break; |
|
|||
206 | } |
|
|||
207 | case QSeries::SeriesTypeBar: { |
|
|||
208 | QBarSeries *barSeries = static_cast<QBarSeries *>(series); |
|
|||
209 | appendMarkers(barSeries); |
|
|||
210 | break; |
|
|||
211 | } |
|
|||
212 | case QSeries::SeriesTypeStackedBar: { |
|
|||
213 | QStackedBarSeries *stackedBarSeries = static_cast<QStackedBarSeries *>(series); |
|
|||
214 | appendMarkers(stackedBarSeries); |
|
|||
215 | break; |
|
|||
216 | } |
|
|||
217 | case QSeries::SeriesTypePercentBar: { |
|
|||
218 | QPercentBarSeries *percentBarSeries = static_cast<QPercentBarSeries *>(series); |
|
|||
219 | appendMarkers(percentBarSeries); |
|
|||
220 | break; |
|
|||
221 | } |
|
|||
222 | case QSeries::SeriesTypeScatter: { |
|
|||
223 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); |
|
|||
224 | appendMarkers(scatterSeries); |
|
|||
225 | break; |
|
|||
226 | } |
|
|||
227 | case QSeries::SeriesTypePie: { |
|
|||
228 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
|||
229 | appendMarkers(pieSeries); |
|
|||
230 | connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>))); |
|
|||
231 | break; |
|
|||
232 | } |
|
|||
233 | case QSeries::SeriesTypeSpline: { |
|
|||
234 | QSplineSeries *splineSeries = static_cast<QSplineSeries *>(series); |
|
|||
235 | appendMarkers(splineSeries); |
|
|||
236 | break; |
|
|||
237 | } |
|
|||
238 | default: { |
|
|||
239 | qWarning()<< "QLegend::handleSeriesAdded" << series->type() << "unknown series type."; |
|
|||
240 | break; |
|
|||
241 | } |
|
|||
242 | } |
|
|||
243 |
|
||||
244 | updateLayout(); |
|
|||
245 | } |
|
193 | } | |
246 |
|
194 | |||
247 | /*! |
|
195 | /*! | |
248 | \internal \a series Should be called when series is removed from chart. |
|
196 | Attaches the legend to chart. Chart may change layout of the legend. | |
249 | */ |
|
197 | */ | |
250 | void QLegend::handleSeriesRemoved(QSeries *series) |
|
198 | void QLegend::attachToChart() | |
251 | { |
|
|||
252 | switch (series->type()) |
|
|||
253 | { |
|
199 | { | |
254 | case QSeries::SeriesTypeArea: { |
|
200 | d_ptr->m_attachedToChart = true; | |
255 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); |
|
|||
256 | deleteMarkers(areaSeries); |
|
|||
257 | break; |
|
|||
258 | } |
|
|||
259 | case QSeries::SeriesTypePie: { |
|
|||
260 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
|||
261 | disconnect(pieSeries, SIGNAL(added(QList<QPieSlice *>)), this, SLOT(handleAdded(QList<QPieSlice *>))); |
|
|||
262 | deleteMarkers(series); |
|
|||
263 | break; |
|
|||
264 | } |
|
|||
265 | default: { |
|
|||
266 | // All other types |
|
|||
267 | deleteMarkers(series); |
|
|||
268 | break; |
|
|||
269 | } |
|
|||
270 | } |
|
|||
271 |
|
||||
272 | updateLayout(); |
|
|||
273 | } |
|
201 | } | |
274 |
|
202 | |||
275 | /*! |
|
203 | /*! | |
276 | \internal \a slices Should be called when slices are added to pie chart. |
|
204 | Returns true, if legend is attached to chart. | |
277 | */ |
|
205 | */ | |
278 | void QLegend::handleAdded(QList<QPieSlice *> slices) |
|
206 | bool QLegend::isAttachedToChart() | |
279 | { |
|
207 | { | |
280 | QPieSeries* series = static_cast<QPieSeries *> (sender()); |
|
208 | return d_ptr->m_attachedToChart; | |
281 | foreach(QPieSlice* slice, slices) { |
|
|||
282 | PieLegendMarker* marker = new PieLegendMarker(series,slice, this); |
|
|||
283 | m_markers->addToGroup(marker); |
|
|||
284 | } |
|
|||
285 | updateLayout(); |
|
|||
286 | } |
|
209 | } | |
287 |
|
210 | |||
288 | /*! |
|
211 | void QLegend::setOffset(const QPointF& point) | |
289 | \internal \a slices Should be called when slices are removed from pie chart. Currently unused, |
|
|||
290 | because removed slices are also deleted and we listen destroyed signal |
|
|||
291 | */ |
|
|||
292 | void QLegend::handleRemoved(QList<QPieSlice *> slices) |
|
|||
293 | { |
|
212 | { | |
294 | Q_UNUSED(slices) |
|
213 | d_ptr->setOffset(point.x(),point.y()); | |
295 | } |
|
214 | } | |
296 |
|
215 | |||
297 | /*! |
|
216 | QPointF QLegend::offset() const | |
298 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
|||
299 | */ |
|
|||
300 | void QLegend::detachFromChart() |
|
|||
301 | { |
|
217 | { | |
302 | m_attachedToChart = false; |
|
218 | return QPointF(d_ptr->m_offsetX,d_ptr->m_offsetY); | |
303 | } |
|
219 | } | |
304 |
|
220 | |||
305 | /*! |
|
221 | /*! | |
306 | Attaches the legend to chart. Chart may change layout of the legend. |
|
222 | Sets the visibility of legend background to \a visible | |
307 | */ |
|
223 | */ | |
308 | void QLegend::attachToChart() |
|
224 | void QLegend::setBackgroundVisible(bool visible) | |
|
225 | { | |||
|
226 | if(d_ptr->m_backgroundVisible!=visible) | |||
309 | { |
|
227 | { | |
310 | m_attachedToChart = true; |
|
228 | d_ptr->m_backgroundVisible=visible; | |
|
229 | update(); | |||
|
230 | } | |||
311 | } |
|
231 | } | |
312 |
|
232 | |||
313 | /*! |
|
233 | /*! | |
314 | Returns true, if legend is attached to chart. |
|
234 | Returns the visibility of legend background | |
315 | */ |
|
235 | */ | |
316 | bool QLegend::isAttachedToChart() |
|
236 | bool QLegend::isBackgroundVisible() const | |
317 | { |
|
237 | { | |
318 | return m_attachedToChart; |
|
238 | return d_ptr->m_backgroundVisible; | |
319 | } |
|
239 | } | |
320 |
|
240 | |||
321 | /*! |
|
241 | /*! | |
322 | \internal Helper function. Appends markers from \a series to legend. |
|
242 | \internal \a event see QGraphicsWidget for details | |
323 | */ |
|
243 | */ | |
324 | void QLegend::appendMarkers(QAreaSeries* series) |
|
244 | void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event) | |
325 | { |
|
245 | { | |
326 | AreaLegendMarker* marker = new AreaLegendMarker(series,this); |
|
246 | const QRectF& rect = QRectF(QPoint(0,0),event->newSize()); | |
327 | m_markers->addToGroup(marker); |
|
247 | QGraphicsWidget::resizeEvent(event); | |
|
248 | if(d_ptr->m_rect != rect) { | |||
|
249 | d_ptr->m_rect = rect; | |||
|
250 | d_ptr->updateLayout(); | |||
|
251 | } | |||
328 | } |
|
252 | } | |
329 |
|
253 | |||
330 | /*! |
|
254 | /*! | |
331 | \internal Helper function. Appends markers from \a series to legend. |
|
255 | \internal \a event see QGraphicsWidget for details | |
332 | */ |
|
256 | */ | |
333 | void QLegend::appendMarkers(QXYSeries* series) |
|
257 | void QLegend::hideEvent(QHideEvent *event) | |
334 | { |
|
258 | { | |
335 | XYLegendMarker* marker = new XYLegendMarker(series,this); |
|
259 | QGraphicsWidget::hideEvent(event); | |
336 | m_markers->addToGroup(marker); |
|
260 | setEnabled(false); | |
|
261 | d_ptr->updateLayout(); | |||
337 | } |
|
262 | } | |
338 |
|
263 | |||
339 | /*! |
|
264 | /*! | |
340 | \internal Helper function. Appends markers from \a series to legend. |
|
265 | \internal \a event see QGraphicsWidget for details | |
341 | */ |
|
266 | */ | |
342 | void QLegend::appendMarkers(QBarSeries *series) |
|
267 | void QLegend::showEvent(QShowEvent *event) | |
343 | { |
|
268 | { | |
344 | foreach(QBarSet* set, series->barSets()) { |
|
269 | QGraphicsWidget::showEvent(event); | |
345 | BarLegendMarker* marker = new BarLegendMarker(series,set, this); |
|
270 | setEnabled(true); | |
346 | m_markers->addToGroup(marker); |
|
271 | d_ptr->updateLayout(); | |
347 | } |
|
|||
348 | } |
|
272 | } | |
349 |
|
273 | |||
350 | /*! |
|
274 | qreal QLegend::minWidth() const | |
351 | \internal Helper function. Appends markers from \a series to legend. |
|
|||
352 | */ |
|
|||
353 | void QLegend::appendMarkers(QPieSeries *series) |
|
|||
354 | { |
|
275 | { | |
355 | foreach(QPieSlice* slice, series->slices()) { |
|
276 | return d_ptr->m_minWidth; | |
356 | PieLegendMarker* marker = new PieLegendMarker(series,slice, this); |
|
|||
357 | m_markers->addToGroup(marker); |
|
|||
358 | } |
|
|||
359 | } |
|
277 | } | |
360 |
|
278 | |||
361 | /*! |
|
279 | qreal QLegend::minHeight() const | |
362 | \internal Deletes all markers that are created from \a series |
|
|||
363 | */ |
|
|||
364 | void QLegend::deleteMarkers(QSeries *series) |
|
|||
365 | { |
|
280 | { | |
366 | // Search all markers that belong to given series and delete them. |
|
281 | return d_ptr->m_minHeight; | |
|
282 | } | |||
367 |
|
283 | |||
368 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
284 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
285 | ||||
|
286 | QLegendPrivate::QLegendPrivate(ChartPresenter* presenter,QLegend *q): | |||
|
287 | q_ptr(q), | |||
|
288 | m_presenter(presenter), | |||
|
289 | m_markers(new QGraphicsItemGroup(q)), | |||
|
290 | m_alignment(QLegend::AlignmentTop), | |||
|
291 | m_offsetX(0), | |||
|
292 | m_offsetY(0), | |||
|
293 | m_minWidth(0), | |||
|
294 | m_minHeight(0), | |||
|
295 | m_width(0), | |||
|
296 | m_height(0), | |||
|
297 | m_attachedToChart(true), | |||
|
298 | m_backgroundVisible(false) | |||
|
299 | { | |||
369 |
|
300 | |||
370 | foreach (QGraphicsItem *markers, items) { |
|
|||
371 | LegendMarker *marker = static_cast<LegendMarker*>(markers); |
|
|||
372 | if (marker->series() == series) { |
|
|||
373 | delete marker; |
|
|||
374 | } |
|
|||
375 | } |
|
|||
376 | } |
|
301 | } | |
377 |
|
302 | |||
378 | /*! |
|
303 | QLegendPrivate::~QLegendPrivate() | |
379 | \internal Updates layout of legend. Tries to fit as many markers as possible up to the maximum size of legend. |
|
304 | { | |
380 | If items don't fit, sets the visibility of scroll buttons accordingly. |
|
|||
381 | Causes legend to be resized. |
|
|||
382 | */ |
|
|||
383 |
|
305 | |||
384 | void QLegend::setOffset(const QPointF& point) |
|
306 | } | |
|
307 | ||||
|
308 | void QLegendPrivate::setOffset(qreal x, qreal y) | |||
385 | { |
|
309 | { | |
386 |
|
310 | |||
387 | switch(m_alignment) { |
|
311 | switch(m_alignment) { | |
388 |
|
312 | |||
389 | case AlignmentTop: |
|
313 | case QLegend::AlignmentTop: | |
390 | case AlignmentBottom: { |
|
314 | case QLegend::AlignmentBottom: { | |
391 | if(m_width<=m_rect.width()) return; |
|
315 | if(m_width<=m_rect.width()) return; | |
392 |
|
316 | |||
393 |
if ( |
|
317 | if (x != m_offsetX) { | |
394 |
m_offsetX = qBound(0.0, |
|
318 | m_offsetX = qBound(0.0, x, m_width - m_rect.width()); | |
395 | m_markers->setPos(-m_offsetX,m_rect.top()); |
|
319 | m_markers->setPos(-m_offsetX,m_rect.top()); | |
396 | } |
|
320 | } | |
397 | break; |
|
321 | break; | |
398 | } |
|
322 | } | |
399 | case AlignmentLeft: |
|
323 | case QLegend::AlignmentLeft: | |
400 | case AlignmentRight: { |
|
324 | case QLegend::AlignmentRight: { | |
401 |
|
325 | |||
402 | if(m_height<=m_rect.height()) return; |
|
326 | if(m_height<=m_rect.height()) return; | |
403 |
|
327 | |||
404 |
if ( |
|
328 | if (y != m_offsetY) { | |
405 |
m_offsetY = qBound(0.0, |
|
329 | m_offsetY = qBound(0.0, y, m_height - m_rect.height()); | |
406 | m_markers->setPos(m_rect.left(),-m_offsetY); |
|
330 | m_markers->setPos(m_rect.left(),-m_offsetY); | |
407 | } |
|
331 | } | |
408 | break; |
|
332 | break; | |
409 | } |
|
333 | } | |
410 | } |
|
334 | } | |
411 | } |
|
335 | } | |
412 |
|
336 | |||
413 | QPointF QLegend::offset() const |
|
|||
414 | { |
|
|||
415 | return QPointF(m_offsetX,m_offsetY); |
|
|||
416 | } |
|
|||
417 |
|
337 | |||
418 | // this function runs first to set min max values |
|
338 | void QLegendPrivate::updateLayout() | |
419 | void QLegend::updateLayout() |
|
|||
420 | { |
|
339 | { | |
421 |
|
|
340 | m_offsetX=0; | |
422 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
341 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
423 |
|
342 | |||
424 | if(items.isEmpty()) return; |
|
343 | if(items.isEmpty()) return; | |
425 |
|
344 | |||
426 | m_minWidth=0; |
|
345 | m_minWidth=0; | |
427 | m_minHeight=0; |
|
346 | m_minHeight=0; | |
428 |
|
347 | |||
429 | switch(m_alignment) { |
|
348 | switch(m_alignment) { | |
430 |
|
349 | |||
431 | case AlignmentTop: |
|
350 | case QLegend::AlignmentTop: | |
432 | case AlignmentBottom: { |
|
351 | case QLegend::AlignmentBottom: { | |
433 | QPointF point = m_rect.topLeft(); |
|
352 | QPointF point = m_rect.topLeft(); | |
434 | m_width = 0; |
|
353 | m_width = 0; | |
435 | foreach (QGraphicsItem *item, items) { |
|
354 | foreach (QGraphicsItem *item, items) { | |
436 | item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2); |
|
355 | item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2); | |
437 | const QRectF& rect = item->boundingRect(); |
|
356 | const QRectF& rect = item->boundingRect(); | |
438 | qreal w = rect.width(); |
|
357 | qreal w = rect.width(); | |
439 | m_minWidth=qMax(m_minWidth,w); |
|
358 | m_minWidth=qMax(m_minWidth,w); | |
440 | m_minHeight=qMax(m_minHeight,rect.height()); |
|
359 | m_minHeight=qMax(m_minHeight,rect.height()); | |
441 | m_width+=w; |
|
360 | m_width+=w; | |
442 | point.setX(point.x() + w); |
|
361 | point.setX(point.x() + w); | |
443 | } |
|
362 | } | |
444 | if(m_width<m_rect.width()){ |
|
363 | if(m_width<m_rect.width()) { | |
445 | m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top()); |
|
364 | m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top()); | |
446 |
} |
|
365 | } | |
|
366 | else { | |||
447 | m_markers->setPos(m_rect.topLeft()); |
|
367 | m_markers->setPos(m_rect.topLeft()); | |
448 | } |
|
368 | } | |
449 | m_height=m_minHeight; |
|
369 | m_height=m_minHeight; | |
450 | } |
|
370 | } | |
451 | break; |
|
371 | break; | |
452 | case AlignmentLeft: |
|
372 | case QLegend::AlignmentLeft: | |
453 | case AlignmentRight:{ |
|
373 | case QLegend::AlignmentRight: { | |
454 | QPointF point = m_rect.topLeft(); |
|
374 | QPointF point = m_rect.topLeft(); | |
455 | m_height = 0; |
|
375 | m_height = 0; | |
456 | foreach (QGraphicsItem *item, items) { |
|
376 | foreach (QGraphicsItem *item, items) { | |
457 | item->setPos(point); |
|
377 | item->setPos(point); | |
458 | const QRectF& rect = item->boundingRect(); |
|
378 | const QRectF& rect = item->boundingRect(); | |
459 | qreal h = rect.height(); |
|
379 | qreal h = rect.height(); | |
460 | m_minWidth=qMax(m_minWidth,rect.width()); |
|
380 | m_minWidth=qMax(m_minWidth,rect.width()); | |
461 | m_minHeight=qMax(m_minHeight,h); |
|
381 | m_minHeight=qMax(m_minHeight,h); | |
462 | m_height+=h; |
|
382 | m_height+=h; | |
463 | point.setY(point.y() + h); |
|
383 | point.setY(point.y() + h); | |
464 | } |
|
384 | } | |
465 | if(m_height<m_rect.height()){ |
|
385 | if(m_height<m_rect.height()) { | |
466 | m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2); |
|
386 | m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2); | |
467 |
} |
|
387 | } | |
|
388 | else { | |||
468 | m_markers->setPos(m_rect.topLeft()); |
|
389 | m_markers->setPos(m_rect.topLeft()); | |
469 | } |
|
390 | } | |
470 | m_width=m_minWidth; |
|
391 | m_width=m_minWidth; | |
471 | } |
|
392 | } | |
472 | break; |
|
393 | break; | |
473 | } |
|
394 | } | |
474 |
|
395 | |||
475 |
|
|
396 | m_presenter->updateLayout(); | |
476 | } |
|
397 | } | |
477 |
|
398 | |||
478 | /*! |
|
399 | void QLegendPrivate::handleSeriesAdded(QSeries *series, Domain *domain) | |
479 | Sets the visibility of legend background to \a visible |
|
|||
480 | */ |
|
|||
481 | void QLegend::setBackgroundVisible(bool visible) |
|
|||
482 | { |
|
|||
483 | if(m_backgroundVisible!=visible) |
|
|||
484 | { |
|
400 | { | |
485 | m_backgroundVisible=visible; |
|
401 | Q_UNUSED(domain) | |
486 | update(); |
|
|||
487 | } |
|
|||
488 | } |
|
|||
489 |
|
402 | |||
490 | /*! |
|
403 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); | |
491 | Returns the visibility of legend background |
|
404 | foreach(LegendMarker* marker , markers) | |
492 | */ |
|
405 | m_markers->addToGroup(marker); | |
493 | bool QLegend::isBackgroundVisible() const |
|
|||
494 | { |
|
|||
495 | return m_backgroundVisible; |
|
|||
496 | } |
|
|||
497 |
|
406 | |||
498 | /*! |
|
|||
499 | \internal \a event see QGraphicsWidget for details |
|
|||
500 | */ |
|
|||
501 | void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
|||
502 | { |
|
|||
503 | const QRectF& rect = QRectF(QPoint(0,0),event->newSize()); |
|
|||
504 | QGraphicsWidget::resizeEvent(event); |
|
|||
505 | if(m_rect != rect){ |
|
|||
506 | m_rect = rect; |
|
|||
507 |
|
|
407 | updateLayout(); | |
508 | } |
|
408 | } | |
509 | } |
|
|||
510 |
|
409 | |||
511 | /*! |
|
410 | void QLegendPrivate::handleSeriesRemoved(QSeries *series) | |
512 | \internal \a event see QGraphicsWidget for details |
|
|||
513 | */ |
|
|||
514 | void QLegend::hideEvent(QHideEvent *event) |
|
|||
515 | { |
|
411 | { | |
516 | QGraphicsWidget::hideEvent(event); |
|
412 | ||
517 | setEnabled(false); |
|
413 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
518 | updateLayout(); |
|
414 | ||
|
415 | foreach (QGraphicsItem *markers, items) { | |||
|
416 | LegendMarker *marker = static_cast<LegendMarker*>(markers); | |||
|
417 | if (marker->series() == series) { | |||
|
418 | delete marker; | |||
|
419 | } | |||
519 | } |
|
420 | } | |
520 |
|
421 | |||
521 | /*! |
|
|||
522 | \internal \a event see QGraphicsWidget for details |
|
|||
523 | */ |
|
|||
524 | void QLegend::showEvent(QShowEvent *event) |
|
|||
525 | { |
|
|||
526 | QGraphicsWidget::showEvent(event); |
|
|||
527 | setEnabled(true); |
|
|||
528 | updateLayout(); |
|
422 | updateLayout(); | |
529 | } |
|
423 | } | |
530 |
|
424 | |||
531 | #include "moc_qlegend.cpp" |
|
425 | #include "moc_qlegend.cpp" | |
|
426 | #include "moc_qlegend_p.cpp" | |||
532 |
|
427 | |||
533 | QTCOMMERCIALCHART_END_NAMESPACE |
|
428 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,170 +1,104 | |||||
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 QLEGEND_H |
|
21 | #ifndef QLEGEND_H | |
22 | #define QLEGEND_H |
|
22 | #define QLEGEND_H | |
23 |
|
23 | |||
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QGraphicsWidget> |
|
25 | #include <QGraphicsWidget> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 | #include "private/scroller_p.h" //TODO fixme |
|
|||
29 |
|
28 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
30 | |||
32 | class Domain; |
|
31 | class Domain; | |
33 | class LegendMarker; |
|
32 | class LegendMarker; | |
34 | class QPieSlice; |
|
33 | class QPieSlice; | |
35 | class QXYSeries; |
|
34 | class QXYSeries; | |
36 | class QBarSet; |
|
35 | class QBarSet; | |
37 | class QBarSeries; |
|
36 | class QBarSeries; | |
38 | class QPieSeries; |
|
37 | class QPieSeries; | |
39 | class QAreaSeries; |
|
38 | class QAreaSeries; | |
40 | class LegendScrollButton; |
|
39 | class LegendScrollButton; | |
41 | class QSeries; |
|
40 | class QSeries; | |
|
41 | ||||
42 | class QChart; |
|
42 | class QChart; | |
|
43 | class QLegendPrivate; | |||
43 |
|
44 | |||
44 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget |
|
45 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget | |
45 | { |
|
46 | { | |
46 | Q_OBJECT |
|
47 | Q_OBJECT | |
47 | public: |
|
48 | public: | |
48 |
|
49 | |||
49 | // We only support these alignments (for now) |
|
50 | // We only support these alignments (for now) | |
50 | enum Alignment { |
|
51 | enum Alignment { | |
51 | AlignmentTop = Qt::AlignTop, |
|
52 | AlignmentTop = Qt::AlignTop, | |
52 | AlignmentBottom = Qt::AlignBottom, |
|
53 | AlignmentBottom = Qt::AlignBottom, | |
53 | AlignmentLeft = Qt::AlignLeft, |
|
54 | AlignmentLeft = Qt::AlignLeft, | |
54 | AlignmentRight = Qt::AlignRight |
|
55 | AlignmentRight = Qt::AlignRight | |
55 | }; |
|
56 | }; | |
56 |
|
57 | |||
57 | Q_DECLARE_FLAGS(Alignments, Alignment) |
|
58 | Q_DECLARE_FLAGS(Alignments, Alignment) | |
58 |
|
59 | |||
59 | private: |
|
60 | private: | |
60 | explicit QLegend(QChart *chart); |
|
61 | explicit QLegend(QChart *chart); | |
61 |
|
62 | |||
62 | public: |
|
63 | public: | |
|
64 | ~QLegend(); | |||
|
65 | ||||
63 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
66 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
64 | QRectF boundingRect() const; |
|
67 | QRectF boundingRect() const; | |
65 |
|
68 | |||
66 | void setBrush(const QBrush &brush); |
|
69 | void setBrush(const QBrush &brush); | |
67 | QBrush brush() const; |
|
70 | QBrush brush() const; | |
68 |
|
71 | |||
69 | void setPen(const QPen &pen); |
|
72 | void setPen(const QPen &pen); | |
70 | QPen pen() const; |
|
73 | QPen pen() const; | |
71 |
|
74 | |||
72 | void setAlignment(QLegend::Alignments alignment); |
|
75 | void setAlignment(QLegend::Alignments alignment); | |
73 | QLegend::Alignments alignment() const; |
|
76 | QLegend::Alignments alignment() const; | |
74 |
|
77 | |||
75 | void detachFromChart(); |
|
78 | void detachFromChart(); | |
76 | void attachToChart(); |
|
79 | void attachToChart(); | |
77 | bool isAttachedToChart(); |
|
80 | bool isAttachedToChart(); | |
78 |
|
81 | |||
79 |
qreal minWidth() const |
|
82 | qreal minWidth() const; | |
80 |
qreal minHeight() const |
|
83 | qreal minHeight() const; | |
81 |
|
84 | |||
82 | void setBackgroundVisible(bool visible = true); |
|
85 | void setBackgroundVisible(bool visible = true); | |
83 | bool isBackgroundVisible() const; |
|
86 | bool isBackgroundVisible() const; | |
84 |
|
87 | |||
85 | void setOffset(const QPointF& point); |
|
88 | void setOffset(const QPointF& point); | |
86 | QPointF offset() const; |
|
89 | QPointF offset() const; | |
87 |
|
90 | |||
88 | protected: |
|
91 | protected: | |
89 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
92 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
90 | void hideEvent(QHideEvent *event); |
|
93 | void hideEvent(QHideEvent *event); | |
91 | void showEvent(QShowEvent *event); |
|
94 | void showEvent(QShowEvent *event); | |
92 |
|
95 | |||
93 | public Q_SLOTS: |
|
|||
94 | // PIMPL ---> |
|
|||
95 | void handleSeriesAdded(QSeries *series, Domain *domain); |
|
|||
96 | void handleSeriesRemoved(QSeries *series); |
|
|||
97 | void handleAdded(QList<QPieSlice *> slices); |
|
|||
98 | void handleRemoved(QList<QPieSlice *> slices); |
|
|||
99 | // PIMPL <--- |
|
|||
100 |
|
||||
101 | private: |
|
|||
102 | // PIMPL ---> |
|
|||
103 | void appendMarkers(QAreaSeries *series); |
|
|||
104 | void appendMarkers(QXYSeries *series); |
|
|||
105 | void appendMarkers(QBarSeries *series); |
|
|||
106 | void appendMarkers(QPieSeries *series); |
|
|||
107 | void deleteMarkers(QSeries *series); |
|
|||
108 | void updateLayout(); |
|
|||
109 |
|
||||
110 | private: |
|
96 | private: | |
111 | qreal m_margin; |
|
97 | QScopedPointer<QLegendPrivate> d_ptr; | |
112 |
|
98 | Q_DISABLE_COPY(QLegend); | ||
113 | QRectF m_rect; |
|
99 | friend class LegendScroller; | |
114 | qreal m_offsetX; |
|
|||
115 | qreal m_offsetY; |
|
|||
116 |
|
||||
117 | //QList<LegendMarker *> m_markers; |
|
|||
118 |
|
||||
119 | QBrush m_brush; |
|
|||
120 | QPen m_pen; |
|
|||
121 | QLegend::Alignments m_alignment; |
|
|||
122 | QGraphicsItemGroup* m_markers; |
|
|||
123 |
|
||||
124 |
|
||||
125 | bool m_attachedToChart; |
|
|||
126 |
|
||||
127 | QChart *m_chart; |
|
|||
128 | qreal m_minWidth; |
|
|||
129 | qreal m_minHeight; |
|
|||
130 | qreal m_width; |
|
|||
131 | qreal m_height; |
|
|||
132 | bool m_backgroundVisible; |
|
|||
133 | friend class ScrolledQLegend; |
|
|||
134 | // <--- PIMPL |
|
|||
135 | }; |
|
|||
136 |
|
||||
137 | class ScrolledQLegend: public QLegend, public Scroller |
|
|||
138 | { |
|
|||
139 |
|
||||
140 | public: |
|
|||
141 | ScrolledQLegend(QChart *chart):QLegend(chart) |
|
|||
142 | { |
|
|||
143 | } |
|
|||
144 |
|
||||
145 | void setOffset(const QPointF& point) |
|
|||
146 | { |
|
|||
147 | QLegend::setOffset(point); |
|
|||
148 | } |
|
|||
149 | QPointF offset() const |
|
|||
150 | { |
|
|||
151 | return QLegend::offset(); |
|
|||
152 | } |
|
|||
153 |
|
||||
154 | void mousePressEvent(QGraphicsSceneMouseEvent* event){ |
|
|||
155 | Scroller::mousePressEvent(event); |
|
|||
156 | //QLegend::mousePressEvent(event); |
|
|||
157 | } |
|
|||
158 | void mouseMoveEvent(QGraphicsSceneMouseEvent* event){ |
|
|||
159 | Scroller::mouseMoveEvent(event); |
|
|||
160 | //QLegend::mouseMoveEvent(event); |
|
|||
161 | } |
|
|||
162 | void mouseReleaseEvent(QGraphicsSceneMouseEvent* event){ |
|
|||
163 | Scroller::mouseReleaseEvent(event); |
|
|||
164 | //QLegend::mouseReleaseEvent(event); |
|
|||
165 | } |
|
|||
166 | }; |
|
100 | }; | |
167 |
|
101 | |||
168 | QTCOMMERCIALCHART_END_NAMESPACE |
|
102 | QTCOMMERCIALCHART_END_NAMESPACE | |
169 |
|
103 | |||
170 | #endif // QLEGEND_H |
|
104 | #endif // QLEGEND_H |
@@ -1,72 +1,73 | |||||
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 QSERIES_H |
|
21 | #ifndef QSERIES_H | |
22 | #define QSERIES_H |
|
22 | #define QSERIES_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QObject> |
|
25 | #include <QObject> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 |
|
27 | |||
28 | class QAbstractItemModel; |
|
28 | class QAbstractItemModel; | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | class QSeriesPrivate; |
|
32 | class QSeriesPrivate; | |
33 |
|
33 | |||
34 | class QTCOMMERCIALCHART_EXPORT QSeries : public QObject |
|
34 | class QTCOMMERCIALCHART_EXPORT QSeries : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 | Q_PROPERTY(QString name READ name WRITE setName) |
|
37 | Q_PROPERTY(QString name READ name WRITE setName) | |
38 | Q_ENUMS(QSeriesType) |
|
38 | Q_ENUMS(QSeriesType) | |
39 |
|
39 | |||
40 | public: |
|
40 | public: | |
41 | enum QSeriesType { |
|
41 | enum QSeriesType { | |
42 | SeriesTypeLine, |
|
42 | SeriesTypeLine, | |
43 | SeriesTypeArea, |
|
43 | SeriesTypeArea, | |
44 | SeriesTypeBar, |
|
44 | SeriesTypeBar, | |
45 | SeriesTypeStackedBar, |
|
45 | SeriesTypeStackedBar, | |
46 | SeriesTypePercentBar, |
|
46 | SeriesTypePercentBar, | |
47 | SeriesTypePie, |
|
47 | SeriesTypePie, | |
48 | SeriesTypeScatter, |
|
48 | SeriesTypeScatter, | |
49 | SeriesTypeSpline |
|
49 | SeriesTypeSpline | |
50 | }; |
|
50 | }; | |
51 |
|
51 | |||
52 | protected: |
|
52 | protected: | |
53 | QSeries(QSeriesPrivate &d,QObject *parent = 0); |
|
53 | QSeries(QSeriesPrivate &d,QObject *parent = 0); | |
54 |
|
54 | |||
55 | public: |
|
55 | public: | |
56 | ~QSeries(); |
|
56 | ~QSeries(); | |
57 | virtual QSeriesType type() const = 0; |
|
57 | virtual QSeriesType type() const = 0; | |
58 | // TODO |
|
58 | // TODO | |
59 | virtual bool setModel(QAbstractItemModel* model) = 0; |
|
59 | virtual bool setModel(QAbstractItemModel* model) = 0; | |
60 | QAbstractItemModel* model() const; |
|
60 | QAbstractItemModel* model() const; | |
61 | void setName(const QString& name); |
|
61 | void setName(const QString& name); | |
62 | QString name() const; |
|
62 | QString name() const; | |
63 |
|
63 | |||
64 | protected: |
|
64 | protected: | |
65 | QScopedPointer<QSeriesPrivate> d_ptr; |
|
65 | QScopedPointer<QSeriesPrivate> d_ptr; | |
66 | friend class ChartDataSet; |
|
66 | friend class ChartDataSet; | |
67 | friend class ChartPresenter; |
|
67 | friend class ChartPresenter; | |
|
68 | friend class QLegendPrivate; | |||
68 | }; |
|
69 | }; | |
69 |
|
70 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
71 | QTCOMMERCIALCHART_END_NAMESPACE | |
71 |
|
72 | |||
72 | #endif |
|
73 | #endif |
@@ -1,62 +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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QSERIES_P_H_ |
|
30 | #ifndef QSERIES_P_H_ | |
31 | #define QSERIES_P_H_ |
|
31 | #define QSERIES_P_H_ | |
32 |
|
32 | |||
33 | #include "qseries.h" |
|
33 | #include "qseries.h" | |
34 |
|
34 | |||
35 | class QAbstractItemModel; |
|
35 | class QAbstractItemModel; | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | class Domain; |
|
39 | class Domain; | |
40 | class ChartPresenter; |
|
40 | class ChartPresenter; | |
41 | class Chart; |
|
41 | class Chart; | |
|
42 | class LegendMarker; | |||
|
43 | class QLegend; | |||
42 |
|
44 | |||
43 | class QSeriesPrivate : public QObject |
|
45 | class QSeriesPrivate : public QObject | |
44 | { |
|
46 | { | |
45 | public: |
|
47 | public: | |
46 | QSeriesPrivate(QSeries *q); |
|
48 | QSeriesPrivate(QSeries *q); | |
47 | ~QSeriesPrivate(); |
|
49 | ~QSeriesPrivate(); | |
48 |
|
50 | |||
49 | virtual void scaleDomain(Domain& domain) = 0; |
|
51 | virtual void scaleDomain(Domain& domain) = 0; | |
50 | virtual Chart* createGraphics(ChartPresenter* presenter) = 0; |
|
52 | virtual Chart* createGraphics(ChartPresenter* presenter) = 0; | |
|
53 | virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0; | |||
51 |
|
54 | |||
52 | protected: |
|
55 | protected: | |
53 | QSeries *q_ptr; |
|
56 | QSeries *q_ptr; | |
54 | QAbstractItemModel *m_model; |
|
57 | QAbstractItemModel *m_model; | |
55 | QString m_name; |
|
58 | QString m_name; | |
56 |
|
59 | |||
57 | friend class QSeries; |
|
60 | friend class QSeries; | |
58 | }; |
|
61 | }; | |
59 |
|
62 | |||
60 | QTCOMMERCIALCHART_END_NAMESPACE |
|
63 | QTCOMMERCIALCHART_END_NAMESPACE | |
61 |
|
64 | |||
62 | #endif |
|
65 | #endif |
@@ -1,171 +1,173 | |||||
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) |
|
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) | |
2 | TARGET = QtCommercialChart |
|
2 | TARGET = QtCommercialChart | |
3 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
3 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
4 | TEMPLATE = lib |
|
4 | TEMPLATE = lib | |
5 | QT += core \ |
|
5 | QT += core \ | |
6 | gui |
|
6 | gui | |
7 | win32-msvc*: LIBS += User32.lib |
|
7 | win32-msvc*: LIBS += User32.lib | |
8 | CONFIG += debug_and_release |
|
8 | CONFIG += debug_and_release | |
9 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
9 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
10 | SOURCES += \ |
|
10 | SOURCES += \ | |
11 | $$PWD/chartdataset.cpp \ |
|
11 | $$PWD/chartdataset.cpp \ | |
12 | $$PWD/chartpresenter.cpp \ |
|
12 | $$PWD/chartpresenter.cpp \ | |
13 | $$PWD/charttheme.cpp \ |
|
13 | $$PWD/charttheme.cpp \ | |
14 | $$PWD/domain.cpp \ |
|
14 | $$PWD/domain.cpp \ | |
15 | $$PWD/qchart.cpp \ |
|
15 | $$PWD/qchart.cpp \ | |
16 | $$PWD/qchartview.cpp \ |
|
16 | $$PWD/qchartview.cpp \ | |
17 | $$PWD/qseries.cpp \ |
|
17 | $$PWD/qseries.cpp \ | |
18 | $$PWD/qlegend.cpp \ |
|
18 | $$PWD/qlegend.cpp \ | |
19 | $$PWD/legendmarker.cpp \ |
|
19 | $$PWD/legendmarker.cpp \ | |
20 | $$PWD/chartbackground.cpp \ |
|
20 | $$PWD/chartbackground.cpp \ | |
21 | $$PWD/chart.cpp \ |
|
21 | $$PWD/chart.cpp \ | |
22 | $$PWD/scroller.cpp |
|
22 | $$PWD/scroller.cpp | |
23 | PRIVATE_HEADERS += \ |
|
23 | PRIVATE_HEADERS += \ | |
24 | $$PWD/chartdataset_p.h \ |
|
24 | $$PWD/chartdataset_p.h \ | |
25 | $$PWD/chartitem_p.h \ |
|
25 | $$PWD/chartitem_p.h \ | |
26 | $$PWD/chartpresenter_p.h \ |
|
26 | $$PWD/chartpresenter_p.h \ | |
27 | $$PWD/charttheme_p.h \ |
|
27 | $$PWD/charttheme_p.h \ | |
28 | $$PWD/domain_p.h \ |
|
28 | $$PWD/domain_p.h \ | |
29 | $$PWD/legendmarker_p.h \ |
|
29 | $$PWD/legendmarker_p.h \ | |
30 | $$PWD/chartbackground_p.h \ |
|
30 | $$PWD/chartbackground_p.h \ | |
31 | $$PWD/chart_p.h \ |
|
31 | $$PWD/chart_p.h \ | |
32 | $$PWD/chartconfig_p.h \ |
|
32 | $$PWD/chartconfig_p.h \ | |
33 | $$PWD/qchart_p.h \ |
|
33 | $$PWD/qchart_p.h \ | |
34 | $$PWD/qchartview_p.h \ |
|
34 | $$PWD/qchartview_p.h \ | |
35 | $$PWD/scroller_p.h \ |
|
35 | $$PWD/scroller_p.h \ | |
36 | $$PWD/qseries_p.h |
|
36 | $$PWD/qseries_p.h \ | |
|
37 | $$PWD/qlegend_p.h \ | |||
|
38 | $$PWD/legendscroller_p.h | |||
37 | PUBLIC_HEADERS += \ |
|
39 | PUBLIC_HEADERS += \ | |
38 | $$PWD/qchart.h \ |
|
40 | $$PWD/qchart.h \ | |
39 | $$PWD/qchartglobal.h \ |
|
41 | $$PWD/qchartglobal.h \ | |
40 | $$PWD/qseries.h \ |
|
42 | $$PWD/qseries.h \ | |
41 | $$PWD/qchartview.h \ |
|
43 | $$PWD/qchartview.h \ | |
42 | $$PWD/qlegend.h |
|
44 | $$PWD/qlegend.h | |
43 |
|
45 | |||
44 | include(animations/animations.pri) |
|
46 | include(animations/animations.pri) | |
45 | include(axis/axis.pri) |
|
47 | include(axis/axis.pri) | |
46 | include(xychart/xychart.pri) |
|
48 | include(xychart/xychart.pri) | |
47 | include(linechart/linechart.pri) |
|
49 | include(linechart/linechart.pri) | |
48 | include(areachart/areachart.pri) |
|
50 | include(areachart/areachart.pri) | |
49 | include(barchart/barchart.pri) |
|
51 | include(barchart/barchart.pri) | |
50 | include(piechart/piechart.pri) |
|
52 | include(piechart/piechart.pri) | |
51 | include(scatterseries/scatter.pri) |
|
53 | include(scatterseries/scatter.pri) | |
52 | include(splinechart/splinechart.pri) |
|
54 | include(splinechart/splinechart.pri) | |
53 | include(themes/themes.pri) |
|
55 | include(themes/themes.pri) | |
54 |
|
56 | |||
55 |
|
57 | |||
56 | HEADERS += $$PUBLIC_HEADERS |
|
58 | HEADERS += $$PUBLIC_HEADERS | |
57 | HEADERS += $$PRIVATE_HEADERS |
|
59 | HEADERS += $$PRIVATE_HEADERS | |
58 | HEADERS += $$THEMES |
|
60 | HEADERS += $$THEMES | |
59 | INCLUDEPATH += ../include . |
|
61 | INCLUDEPATH += ../include . | |
60 |
|
62 | |||
61 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
63 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
62 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
64 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
63 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
65 | UI_DIR = $$CHART_BUILD_DIR/lib | |
64 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
66 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
65 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
67 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
66 |
|
68 | |||
67 | #qt public headers |
|
69 | #qt public headers | |
68 | #this is very primitive and lame parser , TODO: make perl script insted |
|
70 | #this is very primitive and lame parser , TODO: make perl script insted | |
69 | !exists($$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal) |
|
71 | !exists($$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal) | |
70 | { |
|
72 | { | |
71 | system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR) |
|
73 | system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR) | |
72 | win32:{ |
|
74 | win32:{ | |
73 | command = "echo $${LITERAL_HASH}include \"qchartglobal.h\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal" |
|
75 | command = "echo $${LITERAL_HASH}include \"qchartglobal.h\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal" | |
74 | }else{ |
|
76 | }else{ | |
75 | command = "echo \"$${LITERAL_HASH}include \\\"qchartglobal.h\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal" |
|
77 | command = "echo \"$${LITERAL_HASH}include \\\"qchartglobal.h\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal" | |
76 | } |
|
78 | } | |
77 | system($$command) |
|
79 | system($$command) | |
78 | } |
|
80 | } | |
79 |
|
81 | |||
80 | for(file, PUBLIC_HEADERS) { |
|
82 | for(file, PUBLIC_HEADERS) { | |
81 | name = $$split(file,'/') |
|
83 | name = $$split(file,'/') | |
82 | name = $$last(name) |
|
84 | name = $$last(name) | |
83 | class = "$$cat($$file)" |
|
85 | class = "$$cat($$file)" | |
84 | class = $$find(class,class) |
|
86 | class = $$find(class,class) | |
85 | !isEmpty(class){ |
|
87 | !isEmpty(class){ | |
86 | class = $$split(class,QTCOMMERCIALCHART_EXPORT) |
|
88 | class = $$split(class,QTCOMMERCIALCHART_EXPORT) | |
87 | class = $$member(class,1) |
|
89 | class = $$member(class,1) | |
88 | class = $$split(class,' ') |
|
90 | class = $$split(class,' ') | |
89 | class = $$replace(class,' ','') |
|
91 | class = $$replace(class,' ','') | |
90 | class = $$member(class,0) |
|
92 | class = $$member(class,0) | |
91 | win32:{ |
|
93 | win32:{ | |
92 | command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" |
|
94 | command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" | |
93 | }else{ |
|
95 | }else{ | |
94 | command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" |
|
96 | command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" | |
95 | } |
|
97 | } | |
96 | PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class |
|
98 | PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class | |
97 | system($$command) |
|
99 | system($$command) | |
98 | } |
|
100 | } | |
99 | } |
|
101 | } | |
100 |
|
102 | |||
101 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
103 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
102 | public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS |
|
104 | public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS | |
103 |
|
105 | |||
104 | target.path = $$[QT_INSTALL_LIBS] |
|
106 | target.path = $$[QT_INSTALL_LIBS] | |
105 | INSTALLS += target public_headers |
|
107 | INSTALLS += target public_headers | |
106 |
|
108 | |||
107 | install_build_public_headers.name = build_public_headers |
|
109 | install_build_public_headers.name = build_public_headers | |
108 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
110 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
109 | install_build_public_headers.input = PUBLIC_HEADERS |
|
111 | install_build_public_headers.input = PUBLIC_HEADERS | |
110 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
112 | install_build_public_headers.commands = $$QMAKE_COPY \ | |
111 | ${QMAKE_FILE_NAME} \ |
|
113 | ${QMAKE_FILE_NAME} \ | |
112 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
114 | $$CHART_BUILD_PUBLIC_HEADER_DIR | |
113 | install_build_public_headers.CONFIG += target_predeps \ |
|
115 | install_build_public_headers.CONFIG += target_predeps \ | |
114 | no_link |
|
116 | no_link | |
115 |
|
117 | |||
116 | install_build_private_headers.name = buld_private_headers |
|
118 | install_build_private_headers.name = buld_private_headers | |
117 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
119 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
118 | install_build_private_headers.input = PRIVATE_HEADERS |
|
120 | install_build_private_headers.input = PRIVATE_HEADERS | |
119 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
121 | install_build_private_headers.commands = $$QMAKE_COPY \ | |
120 | ${QMAKE_FILE_NAME} \ |
|
122 | ${QMAKE_FILE_NAME} \ | |
121 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
123 | $$CHART_BUILD_PRIVATE_HEADER_DIR | |
122 | install_build_private_headers.CONFIG += target_predeps \ |
|
124 | install_build_private_headers.CONFIG += target_predeps \ | |
123 | no_link |
|
125 | no_link | |
124 |
|
126 | |||
125 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ |
|
127 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ | |
126 | install_build_private_headers \ |
|
128 | install_build_private_headers \ | |
127 |
|
129 | |||
128 |
|
130 | |||
129 | !win32-msvc*: { |
|
131 | !win32-msvc*: { | |
130 |
|
132 | |||
131 | # There is a problem with jom.exe currently. It does not seem to understand QMAKE_EXTRA_TARGETS properly. |
|
133 | # There is a problem with jom.exe currently. It does not seem to understand QMAKE_EXTRA_TARGETS properly. | |
132 | # This is the case at least with shadow builds. |
|
134 | # This is the case at least with shadow builds. | |
133 | # http://qt-project.org/wiki/jom |
|
135 | # http://qt-project.org/wiki/jom | |
134 |
|
136 | |||
135 | chartversion.target = $$PWD/qchartversion_p.h |
|
137 | chartversion.target = $$PWD/qchartversion_p.h | |
136 |
|
138 | |||
137 | unix:{ |
|
139 | unix:{ | |
138 | chartversion.commands = @echo \ |
|
140 | chartversion.commands = @echo \ | |
139 | "const char *buildTime = \\\"`date +'%y%m%d%H%M'`\\\" \\; \ |
|
141 | "const char *buildTime = \\\"`date +'%y%m%d%H%M'`\\\" \\; \ | |
140 | const char *gitHead = \\\"`git rev-parse HEAD`\\\" \\; " \ |
|
142 | const char *gitHead = \\\"`git rev-parse HEAD`\\\" \\; " \ | |
141 | > \ |
|
143 | > \ | |
142 | $$chartversion.target; |
|
144 | $$chartversion.target; | |
143 | }else{ |
|
145 | }else{ | |
144 | chartversion.commands = @echo \ |
|
146 | chartversion.commands = @echo \ | |
145 | "const char *buildTime = \"%date%_%time%\" ; \ |
|
147 | "const char *buildTime = \"%date%_%time%\" ; \ | |
146 | const char *gitHead = \"unknown\" ; " \ |
|
148 | const char *gitHead = \"unknown\" ; " \ | |
147 | > \ |
|
149 | > \ | |
148 | $$chartversion.target |
|
150 | $$chartversion.target | |
149 | } |
|
151 | } | |
150 |
|
152 | |||
151 | chartversion.depends = $$HEADERS \ |
|
153 | chartversion.depends = $$HEADERS \ | |
152 | $$SOURCES |
|
154 | $$SOURCES | |
153 |
|
155 | |||
154 | PRE_TARGETDEPS += $$PWD/qchartversion_p.h |
|
156 | PRE_TARGETDEPS += $$PWD/qchartversion_p.h | |
155 | QMAKE_CLEAN += $$PWD/qchartversion_p.h |
|
157 | QMAKE_CLEAN += $$PWD/qchartversion_p.h | |
156 | QMAKE_EXTRA_TARGETS += chartversion |
|
158 | QMAKE_EXTRA_TARGETS += chartversion | |
157 | } |
|
159 | } | |
158 |
|
160 | |||
159 | unix:QMAKE_DISTCLEAN += -r \ |
|
161 | unix:QMAKE_DISTCLEAN += -r \ | |
160 | $$CHART_BUILD_HEADER_DIR \ |
|
162 | $$CHART_BUILD_HEADER_DIR \ | |
161 | $$CHART_BUILD_LIB_DIR |
|
163 | $$CHART_BUILD_LIB_DIR | |
162 | win32:QMAKE_DISTCLEAN += /Q \ |
|
164 | win32:QMAKE_DISTCLEAN += /Q \ | |
163 | $$CHART_BUILD_HEADER_DIR \ |
|
165 | $$CHART_BUILD_HEADER_DIR \ | |
164 | $$CHART_BUILD_LIB_DIR |
|
166 | $$CHART_BUILD_LIB_DIR | |
165 |
|
167 | |||
166 | # treat warnings as errors |
|
168 | # treat warnings as errors | |
167 | win32-msvc*: { |
|
169 | win32-msvc*: { | |
168 | QMAKE_CXXFLAGS += /WX |
|
170 | QMAKE_CXXFLAGS += /WX | |
169 | } else { |
|
171 | } else { | |
170 | QMAKE_CXXFLAGS += -Werror |
|
172 | QMAKE_CXXFLAGS += -Werror | |
171 | } |
|
173 | } |
@@ -1,652 +1,660 | |||||
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 "qxyseries.h" |
|
21 | #include "qxyseries.h" | |
22 | #include "qxyseries_p.h" |
|
22 | #include "qxyseries_p.h" | |
23 | #include "domain_p.h" |
|
23 | #include "domain_p.h" | |
|
24 | #include "legendmarker_p.h" | |||
24 | #include <QAbstractItemModel> |
|
25 | #include <QAbstractItemModel> | |
25 |
|
26 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
28 | |||
28 | /*! |
|
29 | /*! | |
29 | \class QXYSeries |
|
30 | \class QXYSeries | |
30 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
31 | \brief The QXYSeries class is a base class for line, spline and scatter series. | |
31 | */ |
|
32 | */ | |
32 |
|
33 | |||
33 | /*! |
|
34 | /*! | |
34 | \fn QPen QXYSeries::pen() const |
|
35 | \fn QPen QXYSeries::pen() const | |
35 | \brief Returns pen used to draw points for series. |
|
36 | \brief Returns pen used to draw points for series. | |
36 | \sa setPen() |
|
37 | \sa setPen() | |
37 | */ |
|
38 | */ | |
38 |
|
39 | |||
39 | /*! |
|
40 | /*! | |
40 | \fn QBrush QXYSeries::brush() const |
|
41 | \fn QBrush QXYSeries::brush() const | |
41 | \brief Returns brush used to draw points for series. |
|
42 | \brief Returns brush used to draw points for series. | |
42 | \sa setBrush() |
|
43 | \sa setBrush() | |
43 | */ |
|
44 | */ | |
44 |
|
45 | |||
45 | /*! |
|
46 | /*! | |
46 | \fn void QXYSeries::clicked(const QPointF& point) |
|
47 | \fn void QXYSeries::clicked(const QPointF& point) | |
47 | \brief Signal is emitted when user clicks the \a point on chart. |
|
48 | \brief Signal is emitted when user clicks the \a point on chart. | |
48 | */ |
|
49 | */ | |
49 |
|
50 | |||
50 | /*! |
|
51 | /*! | |
51 | \fn void QXYSeriesPrivate::pointReplaced(int index) |
|
52 | \fn void QXYSeriesPrivate::pointReplaced(int index) | |
52 | \brief \internal \a index |
|
53 | \brief \internal \a index | |
53 | */ |
|
54 | */ | |
54 |
|
55 | |||
55 | /*! |
|
56 | /*! | |
56 | \fn void QXYSeriesPrivate::pointAdded(int index) |
|
57 | \fn void QXYSeriesPrivate::pointAdded(int index) | |
57 | \brief \internal \a index |
|
58 | \brief \internal \a index | |
58 | */ |
|
59 | */ | |
59 |
|
60 | |||
60 | /*! |
|
61 | /*! | |
61 | \fn void QXYSeriesPrivate::pointRemoved(int index) |
|
62 | \fn void QXYSeriesPrivate::pointRemoved(int index) | |
62 | \brief \internal \a index |
|
63 | \brief \internal \a index | |
63 | */ |
|
64 | */ | |
64 |
|
65 | |||
65 | /*! |
|
66 | /*! | |
66 | \fn void QXYSeriesPrivate::updated() |
|
67 | \fn void QXYSeriesPrivate::updated() | |
67 | \brief \internal |
|
68 | \brief \internal | |
68 | */ |
|
69 | */ | |
69 |
|
70 | |||
70 | /*! |
|
71 | /*! | |
71 | \fn int QXYSeries::mapFirst() const |
|
72 | \fn int QXYSeries::mapFirst() const | |
72 | Returns the index of the model's item that is used as a first one for the series. |
|
73 | Returns the index of the model's item that is used as a first one for the series. | |
73 | \sa mapCount() |
|
74 | \sa mapCount() | |
74 | */ |
|
75 | */ | |
75 |
|
76 | |||
76 | /*! |
|
77 | /*! | |
77 | \fn int QXYSeries::mapCount() const |
|
78 | \fn int QXYSeries::mapCount() const | |
78 | Returns the number of the items that are taken from the model. |
|
79 | Returns the number of the items that are taken from the model. | |
79 | If -1 it means all the items of the model following the first one are used. |
|
80 | If -1 it means all the items of the model following the first one are used. | |
80 | \sa mapFirst() |
|
81 | \sa mapFirst() | |
81 | */ |
|
82 | */ | |
82 |
|
83 | |||
83 | /*! |
|
84 | /*! | |
84 | Constructs empty series object which is a child of \a parent. |
|
85 | Constructs empty series object which is a child of \a parent. | |
85 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
86 | When series object is added to QChartView or QChart instance ownerships is transfered. | |
86 | */ |
|
87 | */ | |
87 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent):QSeries(d,parent) |
|
88 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent):QSeries(d,parent) | |
88 | { |
|
89 | { | |
89 |
|
90 | |||
90 | } |
|
91 | } | |
91 | /*! |
|
92 | /*! | |
92 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
93 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
93 | and are deleted when mentioned object are destroyed. |
|
94 | and are deleted when mentioned object are destroyed. | |
94 | */ |
|
95 | */ | |
95 | QXYSeries::~QXYSeries() |
|
96 | QXYSeries::~QXYSeries() | |
96 | { |
|
97 | { | |
97 | } |
|
98 | } | |
98 |
|
99 | |||
99 | /*! |
|
100 | /*! | |
100 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
101 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. | |
101 | */ |
|
102 | */ | |
102 | void QXYSeries::append(qreal x,qreal y) |
|
103 | void QXYSeries::append(qreal x,qreal y) | |
103 | { |
|
104 | { | |
104 | Q_D(QXYSeries); |
|
105 | Q_D(QXYSeries); | |
105 | Q_ASSERT(d->m_x.size() == d->m_y.size()); |
|
106 | Q_ASSERT(d->m_x.size() == d->m_y.size()); | |
106 | d->m_x<<x; |
|
107 | d->m_x<<x; | |
107 | d->m_y<<y; |
|
108 | d->m_y<<y; | |
108 | emit d->pointAdded(d->m_x.size()-1); |
|
109 | emit d->pointAdded(d->m_x.size()-1); | |
109 | } |
|
110 | } | |
110 |
|
111 | |||
111 | /*! |
|
112 | /*! | |
112 | This is an overloaded function. |
|
113 | This is an overloaded function. | |
113 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
114 | Adds data \a point to the series. Points are connected with lines on the chart. | |
114 | */ |
|
115 | */ | |
115 | void QXYSeries::append(const QPointF &point) |
|
116 | void QXYSeries::append(const QPointF &point) | |
116 | { |
|
117 | { | |
117 | append(point.x(),point.y()); |
|
118 | append(point.x(),point.y()); | |
118 | } |
|
119 | } | |
119 |
|
120 | |||
120 | /*! |
|
121 | /*! | |
121 | This is an overloaded function. |
|
122 | This is an overloaded function. | |
122 | Adds list of data \a points to the series. Points are connected with lines on the chart. |
|
123 | Adds list of data \a points to the series. Points are connected with lines on the chart. | |
123 | */ |
|
124 | */ | |
124 | void QXYSeries::append(const QList<QPointF> points) |
|
125 | void QXYSeries::append(const QList<QPointF> points) | |
125 | { |
|
126 | { | |
126 | foreach(const QPointF& point , points) { |
|
127 | foreach(const QPointF& point , points) { | |
127 | append(point.x(),point.y()); |
|
128 | append(point.x(),point.y()); | |
128 | } |
|
129 | } | |
129 | } |
|
130 | } | |
130 |
|
131 | |||
131 | /*! |
|
132 | /*! | |
132 | Modifies \a y value for given \a x a value. |
|
133 | Modifies \a y value for given \a x a value. | |
133 | */ |
|
134 | */ | |
134 | void QXYSeries::replace(qreal x,qreal y) |
|
135 | void QXYSeries::replace(qreal x,qreal y) | |
135 | { |
|
136 | { | |
136 | Q_D(QXYSeries); |
|
137 | Q_D(QXYSeries); | |
137 | int index = d->m_x.indexOf(x); |
|
138 | int index = d->m_x.indexOf(x); | |
138 | d->m_x[index] = x; |
|
139 | d->m_x[index] = x; | |
139 | d->m_y[index] = y; |
|
140 | d->m_y[index] = y; | |
140 | emit d->pointReplaced(index); |
|
141 | emit d->pointReplaced(index); | |
141 | } |
|
142 | } | |
142 |
|
143 | |||
143 | /*! |
|
144 | /*! | |
144 | This is an overloaded function. |
|
145 | This is an overloaded function. | |
145 | Replaces current y value of for given \a point x value with \a point y value. |
|
146 | Replaces current y value of for given \a point x value with \a point y value. | |
146 | */ |
|
147 | */ | |
147 | void QXYSeries::replace(const QPointF &point) |
|
148 | void QXYSeries::replace(const QPointF &point) | |
148 | { |
|
149 | { | |
149 | replace(point.x(),point.y()); |
|
150 | replace(point.x(),point.y()); | |
150 | } |
|
151 | } | |
151 |
|
152 | |||
152 | /*! |
|
153 | /*! | |
153 | Removes first \a x value and related y value. |
|
154 | Removes first \a x value and related y value. | |
154 | */ |
|
155 | */ | |
155 | void QXYSeries::remove(qreal x) |
|
156 | void QXYSeries::remove(qreal x) | |
156 | { |
|
157 | { | |
157 | Q_D(QXYSeries); |
|
158 | Q_D(QXYSeries); | |
158 | int index = d->m_x.indexOf(x); |
|
159 | int index = d->m_x.indexOf(x); | |
159 |
|
160 | |||
160 | if (index == -1) return; |
|
161 | if (index == -1) return; | |
161 |
|
162 | |||
162 | d->m_x.remove(index); |
|
163 | d->m_x.remove(index); | |
163 | d->m_y.remove(index); |
|
164 | d->m_y.remove(index); | |
164 |
|
165 | |||
165 | emit d->pointRemoved(index); |
|
166 | emit d->pointRemoved(index); | |
166 | } |
|
167 | } | |
167 |
|
168 | |||
168 | /*! |
|
169 | /*! | |
169 | Removes current \a x and \a y value. |
|
170 | Removes current \a x and \a y value. | |
170 | */ |
|
171 | */ | |
171 | void QXYSeries::remove(qreal x,qreal y) |
|
172 | void QXYSeries::remove(qreal x,qreal y) | |
172 | { |
|
173 | { | |
173 | Q_D(QXYSeries); |
|
174 | Q_D(QXYSeries); | |
174 | int index =-1; |
|
175 | int index =-1; | |
175 | do { |
|
176 | do { | |
176 | index = d->m_x.indexOf(x,index+1); |
|
177 | index = d->m_x.indexOf(x,index+1); | |
177 | } while (index !=-1 && d->m_y.at(index)!=y); |
|
178 | } while (index !=-1 && d->m_y.at(index)!=y); | |
178 |
|
179 | |||
179 | if (index==-1) return; |
|
180 | if (index==-1) return; | |
180 |
|
181 | |||
181 | d->m_x.remove(index); |
|
182 | d->m_x.remove(index); | |
182 | d->m_y.remove(index); |
|
183 | d->m_y.remove(index); | |
183 | emit d->pointRemoved(index); |
|
184 | emit d->pointRemoved(index); | |
184 | } |
|
185 | } | |
185 |
|
186 | |||
186 | /*! |
|
187 | /*! | |
187 | Removes current \a point x value. Note \a point y value is ignored. |
|
188 | Removes current \a point x value. Note \a point y value is ignored. | |
188 | */ |
|
189 | */ | |
189 | void QXYSeries::remove(const QPointF &point) |
|
190 | void QXYSeries::remove(const QPointF &point) | |
190 | { |
|
191 | { | |
191 | remove(point.x(),point.y()); |
|
192 | remove(point.x(),point.y()); | |
192 | } |
|
193 | } | |
193 |
|
194 | |||
194 | /*! |
|
195 | /*! | |
195 | Removes all data points from the series. |
|
196 | Removes all data points from the series. | |
196 | */ |
|
197 | */ | |
197 | void QXYSeries::removeAll() |
|
198 | void QXYSeries::removeAll() | |
198 | { |
|
199 | { | |
199 | Q_D(QXYSeries); |
|
200 | Q_D(QXYSeries); | |
200 | d->m_x.clear(); |
|
201 | d->m_x.clear(); | |
201 | d->m_y.clear(); |
|
202 | d->m_y.clear(); | |
202 | } |
|
203 | } | |
203 |
|
204 | |||
204 | /*! |
|
205 | /*! | |
205 | \internal \a pos |
|
206 | \internal \a pos | |
206 | */ |
|
207 | */ | |
207 | qreal QXYSeries::x(int pos) const |
|
208 | qreal QXYSeries::x(int pos) const | |
208 | { |
|
209 | { | |
209 | Q_D(const QXYSeries); |
|
210 | Q_D(const QXYSeries); | |
210 | if (d->m_model) { |
|
211 | if (d->m_model) { | |
211 | if (d->m_mapOrientation == Qt::Vertical) |
|
212 | if (d->m_mapOrientation == Qt::Vertical) | |
212 | // consecutive data is read from model's column |
|
213 | // consecutive data is read from model's column | |
213 | return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapX), Qt::DisplayRole).toDouble(); |
|
214 | return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapX), Qt::DisplayRole).toDouble(); | |
214 | else |
|
215 | else | |
215 | // consecutive data is read from model's row |
|
216 | // consecutive data is read from model's row | |
216 | return d->m_model->data(d->m_model->index(d->m_mapX, pos + d->m_mapFirst), Qt::DisplayRole).toDouble(); |
|
217 | return d->m_model->data(d->m_model->index(d->m_mapX, pos + d->m_mapFirst), Qt::DisplayRole).toDouble(); | |
217 | } else { |
|
218 | } else { | |
218 | // model is not specified, return the data from series' internal data store |
|
219 | // model is not specified, return the data from series' internal data store | |
219 | return d->m_x.at(pos); |
|
220 | return d->m_x.at(pos); | |
220 | } |
|
221 | } | |
221 | } |
|
222 | } | |
222 |
|
223 | |||
223 | /*! |
|
224 | /*! | |
224 | \internal \a pos |
|
225 | \internal \a pos | |
225 | */ |
|
226 | */ | |
226 | qreal QXYSeries::y(int pos) const |
|
227 | qreal QXYSeries::y(int pos) const | |
227 | { |
|
228 | { | |
228 | Q_D(const QXYSeries); |
|
229 | Q_D(const QXYSeries); | |
229 | if (d->m_model) { |
|
230 | if (d->m_model) { | |
230 | if (d->m_mapOrientation == Qt::Vertical) |
|
231 | if (d->m_mapOrientation == Qt::Vertical) | |
231 | // consecutive data is read from model's column |
|
232 | // consecutive data is read from model's column | |
232 | return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapY), Qt::DisplayRole).toDouble(); |
|
233 | return d->m_model->data(d->m_model->index(pos + d->m_mapFirst, d->m_mapY), Qt::DisplayRole).toDouble(); | |
233 | else |
|
234 | else | |
234 | // consecutive data is read from model's row |
|
235 | // consecutive data is read from model's row | |
235 | return d->m_model->data(d->m_model->index(d->m_mapY, pos + d->m_mapFirst), Qt::DisplayRole).toDouble(); |
|
236 | return d->m_model->data(d->m_model->index(d->m_mapY, pos + d->m_mapFirst), Qt::DisplayRole).toDouble(); | |
236 | } else { |
|
237 | } else { | |
237 | // model is not specified, return the data from series' internal data store |
|
238 | // model is not specified, return the data from series' internal data store | |
238 | return d->m_y.at(pos); |
|
239 | return d->m_y.at(pos); | |
239 | } |
|
240 | } | |
240 | } |
|
241 | } | |
241 |
|
242 | |||
242 | /*! |
|
243 | /*! | |
243 | Returns number of data points within series. |
|
244 | Returns number of data points within series. | |
244 | */ |
|
245 | */ | |
245 | int QXYSeries::count() const |
|
246 | int QXYSeries::count() const | |
246 | { |
|
247 | { | |
247 | Q_D(const QXYSeries); |
|
248 | Q_D(const QXYSeries); | |
248 |
|
249 | |||
249 | Q_ASSERT(d->m_x.size() == d->m_y.size()); |
|
250 | Q_ASSERT(d->m_x.size() == d->m_y.size()); | |
250 |
|
251 | |||
251 | if (d->m_model) { |
|
252 | if (d->m_model) { | |
252 | if (d->m_mapOrientation == Qt::Vertical) { |
|
253 | if (d->m_mapOrientation == Qt::Vertical) { | |
253 | // data is in a column. Return the number of mapped items if the model's column have enough items |
|
254 | // data is in a column. Return the number of mapped items if the model's column have enough items | |
254 | // or the number of items that can be mapped |
|
255 | // or the number of items that can be mapped | |
255 | if (d->m_mapLimited) |
|
256 | if (d->m_mapLimited) | |
256 | return qMin(d->m_mapCount, qMax(d->m_model->rowCount() - d->m_mapFirst, 0)); |
|
257 | return qMin(d->m_mapCount, qMax(d->m_model->rowCount() - d->m_mapFirst, 0)); | |
257 | else |
|
258 | else | |
258 | return qMax(d->m_model->rowCount() - d->m_mapFirst, 0); |
|
259 | return qMax(d->m_model->rowCount() - d->m_mapFirst, 0); | |
259 | } else { |
|
260 | } else { | |
260 | // data is in a row. Return the number of mapped items if the model's row have enough items |
|
261 | // data is in a row. Return the number of mapped items if the model's row have enough items | |
261 | // or the number of items that can be mapped |
|
262 | // or the number of items that can be mapped | |
262 | if (d->m_mapLimited) |
|
263 | if (d->m_mapLimited) | |
263 | return qMin(d->m_mapCount, qMax(d->m_model->columnCount() - d->m_mapFirst, 0)); |
|
264 | return qMin(d->m_mapCount, qMax(d->m_model->columnCount() - d->m_mapFirst, 0)); | |
264 | else |
|
265 | else | |
265 | return qMax(d->m_model->columnCount() - d->m_mapFirst, 0); |
|
266 | return qMax(d->m_model->columnCount() - d->m_mapFirst, 0); | |
266 | } |
|
267 | } | |
267 | } |
|
268 | } | |
268 |
|
269 | |||
269 | // model is not specified, return the number of points in the series internal data store |
|
270 | // model is not specified, return the number of points in the series internal data store | |
270 | return d->m_x.size(); |
|
271 | return d->m_x.size(); | |
271 | } |
|
272 | } | |
272 |
|
273 | |||
273 | /*! |
|
274 | /*! | |
274 | Returns the data points of the series. |
|
275 | Returns the data points of the series. | |
275 | */ |
|
276 | */ | |
276 | QList<QPointF> QXYSeries::data() |
|
277 | QList<QPointF> QXYSeries::data() | |
277 | { |
|
278 | { | |
278 | Q_D(QXYSeries); |
|
279 | Q_D(QXYSeries); | |
279 | QList<QPointF> data; |
|
280 | QList<QPointF> data; | |
280 | for (int i(0); i < d->m_x.count() && i < d->m_y.count(); i++) |
|
281 | for (int i(0); i < d->m_x.count() && i < d->m_y.count(); i++) | |
281 | data.append(QPointF(d->m_x.at(i), d->m_y.at(i))); |
|
282 | data.append(QPointF(d->m_x.at(i), d->m_y.at(i))); | |
282 | return data; |
|
283 | return data; | |
283 | } |
|
284 | } | |
284 |
|
285 | |||
285 |
|
286 | |||
286 | /*! |
|
287 | /*! | |
287 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
288 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the | |
288 | pen from chart theme is used. |
|
289 | pen from chart theme is used. | |
289 | \sa QChart::setTheme() |
|
290 | \sa QChart::setTheme() | |
290 | */ |
|
291 | */ | |
291 | void QXYSeries::setPen(const QPen &pen) |
|
292 | void QXYSeries::setPen(const QPen &pen) | |
292 | { |
|
293 | { | |
293 | Q_D(QXYSeries); |
|
294 | Q_D(QXYSeries); | |
294 | if (d->m_pen!=pen) { |
|
295 | if (d->m_pen!=pen) { | |
295 | d->m_pen = pen; |
|
296 | d->m_pen = pen; | |
296 | emit d->updated(); |
|
297 | emit d->updated(); | |
297 | } |
|
298 | } | |
298 | } |
|
299 | } | |
299 |
|
300 | |||
300 | QPen QXYSeries::pen() const |
|
301 | QPen QXYSeries::pen() const | |
301 | { |
|
302 | { | |
302 | Q_D(const QXYSeries); |
|
303 | Q_D(const QXYSeries); | |
303 | return d->m_pen; |
|
304 | return d->m_pen; | |
304 | } |
|
305 | } | |
305 |
|
306 | |||
306 | /*! |
|
307 | /*! | |
307 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
308 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush | |
308 | from chart theme setting is used. |
|
309 | from chart theme setting is used. | |
309 | \sa QChart::setTheme() |
|
310 | \sa QChart::setTheme() | |
310 | */ |
|
311 | */ | |
311 | void QXYSeries::setBrush(const QBrush &brush) |
|
312 | void QXYSeries::setBrush(const QBrush &brush) | |
312 | { |
|
313 | { | |
313 | Q_D(QXYSeries); |
|
314 | Q_D(QXYSeries); | |
314 | if (d->m_brush!=brush) { |
|
315 | if (d->m_brush!=brush) { | |
315 | d->m_brush = brush; |
|
316 | d->m_brush = brush; | |
316 | emit d->updated(); |
|
317 | emit d->updated(); | |
317 | } |
|
318 | } | |
318 | } |
|
319 | } | |
319 |
|
320 | |||
320 | QBrush QXYSeries::brush() const |
|
321 | QBrush QXYSeries::brush() const | |
321 | { |
|
322 | { | |
322 | Q_D(const QXYSeries); |
|
323 | Q_D(const QXYSeries); | |
323 | return d->m_brush; |
|
324 | return d->m_brush; | |
324 | } |
|
325 | } | |
325 |
|
326 | |||
326 |
|
327 | |||
327 | /*! |
|
328 | /*! | |
328 | Sets if data points are \a visible and should be drawn on line. |
|
329 | Sets if data points are \a visible and should be drawn on line. | |
329 | */ |
|
330 | */ | |
330 | void QXYSeries::setPointsVisible(bool visible) |
|
331 | void QXYSeries::setPointsVisible(bool visible) | |
331 | { |
|
332 | { | |
332 | Q_D(QXYSeries); |
|
333 | Q_D(QXYSeries); | |
333 | if (d->m_pointsVisible != visible){ |
|
334 | if (d->m_pointsVisible != visible){ | |
334 | d->m_pointsVisible = visible; |
|
335 | d->m_pointsVisible = visible; | |
335 | emit d->updated(); |
|
336 | emit d->updated(); | |
336 | } |
|
337 | } | |
337 | } |
|
338 | } | |
338 |
|
339 | |||
339 |
|
340 | |||
340 | bool QXYSeries::pointsVisible() const |
|
341 | bool QXYSeries::pointsVisible() const | |
341 | { |
|
342 | { | |
342 | Q_D(const QXYSeries); |
|
343 | Q_D(const QXYSeries); | |
343 | return d->m_pointsVisible; |
|
344 | return d->m_pointsVisible; | |
344 | } |
|
345 | } | |
345 |
|
346 | |||
346 |
|
347 | |||
347 | /*! |
|
348 | /*! | |
348 | Stream operator for adding a data \a point to the series. |
|
349 | Stream operator for adding a data \a point to the series. | |
349 | \sa append() |
|
350 | \sa append() | |
350 | */ |
|
351 | */ | |
351 | QXYSeries& QXYSeries::operator<< (const QPointF &point) |
|
352 | QXYSeries& QXYSeries::operator<< (const QPointF &point) | |
352 | { |
|
353 | { | |
353 | append(point); |
|
354 | append(point); | |
354 | return *this; |
|
355 | return *this; | |
355 | } |
|
356 | } | |
356 |
|
357 | |||
357 |
|
358 | |||
358 | /*! |
|
359 | /*! | |
359 | Stream operator for adding a list of \a points to the series. |
|
360 | Stream operator for adding a list of \a points to the series. | |
360 | \sa append() |
|
361 | \sa append() | |
361 | */ |
|
362 | */ | |
362 |
|
363 | |||
363 | QXYSeries& QXYSeries::operator<< (const QList<QPointF> points) |
|
364 | QXYSeries& QXYSeries::operator<< (const QList<QPointF> points) | |
364 | { |
|
365 | { | |
365 | append(points); |
|
366 | append(points); | |
366 | return *this; |
|
367 | return *this; | |
367 | } |
|
368 | } | |
368 |
|
369 | |||
369 | /*! |
|
370 | /*! | |
370 | \internal |
|
371 | \internal | |
371 | */ |
|
372 | */ | |
372 | void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
373 | void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
373 | { |
|
374 | { | |
374 | Q_UNUSED(bottomRight) |
|
375 | Q_UNUSED(bottomRight) | |
375 | Q_D(QXYSeries); |
|
376 | Q_D(QXYSeries); | |
376 | if (d->m_mapOrientation == Qt::Vertical) { |
|
377 | if (d->m_mapOrientation == Qt::Vertical) { | |
377 | if (topLeft.row() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.row() < d->m_mapFirst + d->m_mapCount)) |
|
378 | if (topLeft.row() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.row() < d->m_mapFirst + d->m_mapCount)) | |
378 | emit d->pointReplaced(topLeft.row() - d->m_mapFirst); |
|
379 | emit d->pointReplaced(topLeft.row() - d->m_mapFirst); | |
379 | } else { |
|
380 | } else { | |
380 | if (topLeft.column() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.column() < d->m_mapFirst + d->m_mapCount)) |
|
381 | if (topLeft.column() >= d->m_mapFirst && (!d->m_mapLimited || topLeft.column() < d->m_mapFirst + d->m_mapCount)) | |
381 | emit d->pointReplaced(topLeft.column() - d->m_mapFirst); |
|
382 | emit d->pointReplaced(topLeft.column() - d->m_mapFirst); | |
382 | } |
|
383 | } | |
383 | } |
|
384 | } | |
384 |
|
385 | |||
385 | /*! |
|
386 | /*! | |
386 | \internal |
|
387 | \internal | |
387 | */ |
|
388 | */ | |
388 | void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end) |
|
389 | void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end) | |
389 | { |
|
390 | { | |
390 | Q_UNUSED(parent) |
|
391 | Q_UNUSED(parent) | |
391 | // Q_UNUSED(end) |
|
392 | // Q_UNUSED(end) | |
392 | Q_D(QXYSeries); |
|
393 | Q_D(QXYSeries); | |
393 | if (d->m_mapLimited) { |
|
394 | if (d->m_mapLimited) { | |
394 | if (start >= d->m_mapFirst + d->m_mapCount) { |
|
395 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
395 | // the added data is below mapped area |
|
396 | // the added data is below mapped area | |
396 | // therefore it has no relevance |
|
397 | // therefore it has no relevance | |
397 | return; |
|
398 | return; | |
398 | } else { |
|
399 | } else { | |
399 | // the added data is in the mapped area or before it and update is needed |
|
400 | // the added data is in the mapped area or before it and update is needed | |
400 |
|
401 | |||
401 | // check how many mapped items there is currently (before new items are added) |
|
402 | // check how many mapped items there is currently (before new items are added) | |
402 | // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem |
|
403 | // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem | |
403 | // internal storage before new ones can be added |
|
404 | // internal storage before new ones can be added | |
404 |
|
405 | |||
405 | int itemsToRemove = qMin(count() - qMax(start - d->m_mapFirst, 0), end - start + 1); |
|
406 | int itemsToRemove = qMin(count() - qMax(start - d->m_mapFirst, 0), end - start + 1); | |
406 | if (d->m_mapCount == count()) { |
|
407 | if (d->m_mapCount == count()) { | |
407 | for (int i = 0; i < itemsToRemove; i++) |
|
408 | for (int i = 0; i < itemsToRemove; i++) | |
408 | emit d->pointRemoved(qMin(end, count()) - i); |
|
409 | emit d->pointRemoved(qMin(end, count()) - i); | |
409 | } |
|
410 | } | |
410 | } |
|
411 | } | |
411 | } else { |
|
412 | } else { | |
412 | // map is not limited (it includes all the items starting from m_mapFirst till the end of model) |
|
413 | // map is not limited (it includes all the items starting from m_mapFirst till the end of model) | |
413 | // nothing to do |
|
414 | // nothing to do | |
414 | // emit pointAdded(qMax(start - m_mapFirst, 0)); |
|
415 | // emit pointAdded(qMax(start - m_mapFirst, 0)); | |
415 | } |
|
416 | } | |
416 | } |
|
417 | } | |
417 |
|
418 | |||
418 | /*! |
|
419 | /*! | |
419 | \internal |
|
420 | \internal | |
420 | */ |
|
421 | */ | |
421 | void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) |
|
422 | void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end) | |
422 | { |
|
423 | { | |
423 | Q_UNUSED(parent) |
|
424 | Q_UNUSED(parent) | |
424 | // Q_UNUSED(end) |
|
425 | // Q_UNUSED(end) | |
425 | Q_D(QXYSeries); |
|
426 | Q_D(QXYSeries); | |
426 | if (d->m_mapLimited) { |
|
427 | if (d->m_mapLimited) { | |
427 | if (start >= d->m_mapFirst + d->m_mapCount) { |
|
428 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
428 | // the added data is below mapped area |
|
429 | // the added data is below mapped area | |
429 | // therefore it has no relevance |
|
430 | // therefore it has no relevance | |
430 | return; |
|
431 | return; | |
431 | } else { |
|
432 | } else { | |
432 | // the added data is in the mapped area or before it |
|
433 | // the added data is in the mapped area or before it | |
433 | // update needed |
|
434 | // update needed | |
434 | if (count() > 0) { |
|
435 | if (count() > 0) { | |
435 | int toBeAdded = qMin(d->m_mapCount - (start - d->m_mapFirst), end - start + 1); |
|
436 | int toBeAdded = qMin(d->m_mapCount - (start - d->m_mapFirst), end - start + 1); | |
436 | for (int i = 0; i < toBeAdded; i++) |
|
437 | for (int i = 0; i < toBeAdded; i++) | |
437 | if (start + i >= d->m_mapFirst) |
|
438 | if (start + i >= d->m_mapFirst) | |
438 | emit d->pointAdded(start + i); |
|
439 | emit d->pointAdded(start + i); | |
439 | } |
|
440 | } | |
440 | } |
|
441 | } | |
441 | } else { |
|
442 | } else { | |
442 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) |
|
443 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) | |
443 | for (int i = 0; i < end - start + 1; i++) |
|
444 | for (int i = 0; i < end - start + 1; i++) | |
444 | emit d->pointAdded(start + i); |
|
445 | emit d->pointAdded(start + i); | |
445 | } |
|
446 | } | |
446 | } |
|
447 | } | |
447 |
|
448 | |||
448 | /*! |
|
449 | /*! | |
449 | \internal |
|
450 | \internal | |
450 | */ |
|
451 | */ | |
451 | void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end) |
|
452 | void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end) | |
452 | { |
|
453 | { | |
453 | Q_UNUSED(parent) |
|
454 | Q_UNUSED(parent) | |
454 | // Q_UNUSED(end) |
|
455 | // Q_UNUSED(end) | |
455 | Q_D(QXYSeries); |
|
456 | Q_D(QXYSeries); | |
456 | if (d->m_mapLimited) { |
|
457 | if (d->m_mapLimited) { | |
457 | if (start >= d->m_mapFirst + d->m_mapCount) { |
|
458 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
458 | // the removed data is below mapped area |
|
459 | // the removed data is below mapped area | |
459 | // therefore it has no relevance |
|
460 | // therefore it has no relevance | |
460 | return; |
|
461 | return; | |
461 | } else { |
|
462 | } else { | |
462 | // the removed data is in the mapped area or before it |
|
463 | // the removed data is in the mapped area or before it | |
463 | // update needed |
|
464 | // update needed | |
464 |
|
465 | |||
465 | // check how many items need to be removed from the xychartitem storage |
|
466 | // check how many items need to be removed from the xychartitem storage | |
466 | // the number equals the number of items that are removed and that lay before |
|
467 | // the number equals the number of items that are removed and that lay before | |
467 | // or in the mapped area. Items that lay beyond the map do not count |
|
468 | // or in the mapped area. Items that lay beyond the map do not count | |
468 | // the max is the current number of items in storage (count()) |
|
469 | // the max is the current number of items in storage (count()) | |
469 | int itemsToRemove = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1); |
|
470 | int itemsToRemove = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1); | |
470 | for (int i = 0; i < itemsToRemove; i++) |
|
471 | for (int i = 0; i < itemsToRemove; i++) | |
471 | emit d->pointRemoved(start); |
|
472 | emit d->pointRemoved(start); | |
472 | } |
|
473 | } | |
473 | } else { |
|
474 | } else { | |
474 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) |
|
475 | // map is not limited (it included all the items starting from m_mapFirst till the end of model) | |
475 | for (int i = 0; i < end - start + 1; i++) |
|
476 | for (int i = 0; i < end - start + 1; i++) | |
476 | emit d->pointRemoved(start); |
|
477 | emit d->pointRemoved(start); | |
477 | } |
|
478 | } | |
478 | } |
|
479 | } | |
479 |
|
480 | |||
480 | /*! |
|
481 | /*! | |
481 | \internal |
|
482 | \internal | |
482 | */ |
|
483 | */ | |
483 | void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) |
|
484 | void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
484 | { |
|
485 | { | |
485 |
|
486 | |||
486 | Q_UNUSED(parent) |
|
487 | Q_UNUSED(parent) | |
487 | Q_UNUSED(end) |
|
488 | Q_UNUSED(end) | |
488 | Q_D(QXYSeries); |
|
489 | Q_D(QXYSeries); | |
489 | // how many items there were before data was removed |
|
490 | // how many items there were before data was removed | |
490 | // int oldCount = count() - 1; |
|
491 | // int oldCount = count() - 1; | |
491 |
|
492 | |||
492 | if (d->m_mapLimited) { |
|
493 | if (d->m_mapLimited) { | |
493 | if (start >= d->m_mapFirst + d->m_mapCount) { |
|
494 | if (start >= d->m_mapFirst + d->m_mapCount) { | |
494 | // the removed data is below mapped area |
|
495 | // the removed data is below mapped area | |
495 | // therefore it has no relevance |
|
496 | // therefore it has no relevance | |
496 | return; |
|
497 | return; | |
497 | } else { |
|
498 | } else { | |
498 | // if the current items count in the whole model is bigger than the index of the last item |
|
499 | // if the current items count in the whole model is bigger than the index of the last item | |
499 | // that was removed than it means there are some extra items available |
|
500 | // that was removed than it means there are some extra items available | |
500 |
|
501 | |||
501 | int removedItemsCount = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1); |
|
502 | int removedItemsCount = qMin(count(), qMin(end, d->m_mapFirst + d->m_mapCount - 1) - start + 1); | |
502 | int extraItemsAvailable = 0; |
|
503 | int extraItemsAvailable = 0; | |
503 | if (d->m_mapOrientation == Qt::Vertical) { |
|
504 | if (d->m_mapOrientation == Qt::Vertical) { | |
504 | extraItemsAvailable = qMax(d->m_model->rowCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0); |
|
505 | extraItemsAvailable = qMax(d->m_model->rowCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0); | |
505 | } else { |
|
506 | } else { | |
506 | extraItemsAvailable = qMax(d->m_model->columnCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0); |
|
507 | extraItemsAvailable = qMax(d->m_model->columnCount() + (end - start + 1) - qMax(end + 1, d->m_mapFirst + d->m_mapCount), 0); | |
507 | } |
|
508 | } | |
508 |
|
509 | |||
509 | // if there are excess items available (below the mapped area) use them to repopulate mapped area |
|
510 | // if there are excess items available (below the mapped area) use them to repopulate mapped area | |
510 | int toBeAdded = qMin(extraItemsAvailable, removedItemsCount); |
|
511 | int toBeAdded = qMin(extraItemsAvailable, removedItemsCount); | |
511 | for (int k = 0; k < toBeAdded; k++) |
|
512 | for (int k = 0; k < toBeAdded; k++) | |
512 | emit d->pointAdded(d->m_mapFirst + d->m_mapCount - removedItemsCount + k); |
|
513 | emit d->pointAdded(d->m_mapFirst + d->m_mapCount - removedItemsCount + k); | |
513 | } |
|
514 | } | |
514 | } else { |
|
515 | } else { | |
515 | // data was removed from XYSeries interal storage. Nothing more to do |
|
516 | // data was removed from XYSeries interal storage. Nothing more to do | |
516 | } |
|
517 | } | |
517 | } |
|
518 | } | |
518 |
|
519 | |||
519 | /*! |
|
520 | /*! | |
520 | \fn bool QXYSeries::setModel(QAbstractItemModel *model) |
|
521 | \fn bool QXYSeries::setModel(QAbstractItemModel *model) | |
521 | Sets the \a model to be used as a data source |
|
522 | Sets the \a model to be used as a data source | |
522 | \sa setModelMapping(), setModelMappingRange() |
|
523 | \sa setModelMapping(), setModelMappingRange() | |
523 | */ |
|
524 | */ | |
524 | bool QXYSeries::setModel(QAbstractItemModel *model) |
|
525 | bool QXYSeries::setModel(QAbstractItemModel *model) | |
525 | { |
|
526 | { | |
526 | Q_D(QXYSeries); |
|
527 | Q_D(QXYSeries); | |
527 | // disconnect signals from old model |
|
528 | // disconnect signals from old model | |
528 | if (d->m_model) { |
|
529 | if (d->m_model) { | |
529 | QObject::disconnect(d->m_model, 0, this, 0); |
|
530 | QObject::disconnect(d->m_model, 0, this, 0); | |
530 | d->m_mapX = -1; |
|
531 | d->m_mapX = -1; | |
531 | d->m_mapY = -1; |
|
532 | d->m_mapY = -1; | |
532 | d->m_mapFirst = 0; |
|
533 | d->m_mapFirst = 0; | |
533 | d->m_mapCount = 0; |
|
534 | d->m_mapCount = 0; | |
534 | d->m_mapLimited = false; |
|
535 | d->m_mapLimited = false; | |
535 | d->m_mapOrientation = Qt::Vertical; |
|
536 | d->m_mapOrientation = Qt::Vertical; | |
536 | } |
|
537 | } | |
537 |
|
538 | |||
538 | // set new model |
|
539 | // set new model | |
539 | if (model) { |
|
540 | if (model) { | |
540 | d->m_model = model; |
|
541 | d->m_model = model; | |
541 | return true; |
|
542 | return true; | |
542 | } else { |
|
543 | } else { | |
543 | d->m_model = 0; |
|
544 | d->m_model = 0; | |
544 | return false; |
|
545 | return false; | |
545 | } |
|
546 | } | |
546 | } |
|
547 | } | |
547 |
|
548 | |||
548 | /*! |
|
549 | /*! | |
549 | \fn bool QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) |
|
550 | \fn bool QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) | |
550 | Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used |
|
551 | Sets the \a modelX to be used as a data source for x coordinate and \a modelY to be used | |
551 | as a data source for y coordinate. The \a orientation paramater specifies whether the data |
|
552 | as a data source for y coordinate. The \a orientation paramater specifies whether the data | |
552 | is in columns or in rows. |
|
553 | is in columns or in rows. | |
553 | \sa setModel(), setModelMappingRange() |
|
554 | \sa setModel(), setModelMappingRange() | |
554 | */ |
|
555 | */ | |
555 | void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) |
|
556 | void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation) | |
556 | { |
|
557 | { | |
557 | Q_D(QXYSeries); |
|
558 | Q_D(QXYSeries); | |
558 | if (d->m_model == 0) |
|
559 | if (d->m_model == 0) | |
559 | return; |
|
560 | return; | |
560 | d->m_mapX = modelX; |
|
561 | d->m_mapX = modelX; | |
561 | d->m_mapY = modelY; |
|
562 | d->m_mapY = modelY; | |
562 | d->m_mapFirst = 0; |
|
563 | d->m_mapFirst = 0; | |
563 | d->m_mapOrientation = orientation; |
|
564 | d->m_mapOrientation = orientation; | |
564 | if (d->m_mapOrientation == Qt::Vertical) { |
|
565 | if (d->m_mapOrientation == Qt::Vertical) { | |
565 | connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
566 | connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
566 | connect(d->m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); |
|
567 | connect(d->m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); | |
567 | connect(d->m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
568 | connect(d->m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
568 | connect(d->m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); |
|
569 | connect(d->m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); | |
569 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
570 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
570 | } else { |
|
571 | } else { | |
571 | connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
572 | connect(d->m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
572 | connect(d->m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); |
|
573 | connect(d->m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int))); | |
573 | connect(d->m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
574 | connect(d->m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
574 | connect(d->m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); |
|
575 | connect(d->m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int))); | |
575 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
576 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
576 | } |
|
577 | } | |
577 | } |
|
578 | } | |
578 |
|
579 | |||
579 | /*! |
|
580 | /*! | |
580 | \fn bool QXYSeries::setModelMappingRange(int first, int count) |
|
581 | \fn bool QXYSeries::setModelMappingRange(int first, int count) | |
581 | Allows limiting the model mapping. |
|
582 | Allows limiting the model mapping. | |
582 | Parameter \a first specifies which element of the model should be used as a first one of the series. |
|
583 | Parameter \a first specifies which element of the model should be used as a first one of the series. | |
583 | Parameter \a count specifies how many elements should be mapped. If count is not specified (defaults to -1) |
|
584 | Parameter \a count specifies how many elements should be mapped. If count is not specified (defaults to -1) | |
584 | then all the items following \a first item in a model are used. |
|
585 | then all the items following \a first item in a model are used. | |
585 | \sa setModel(), setModelMapping() |
|
586 | \sa setModel(), setModelMapping() | |
586 | */ |
|
587 | */ | |
587 | void QXYSeries::setModelMappingRange(int first, int count) |
|
588 | void QXYSeries::setModelMappingRange(int first, int count) | |
588 | { |
|
589 | { | |
589 | Q_D(QXYSeries); |
|
590 | Q_D(QXYSeries); | |
590 | d->m_mapFirst = first; |
|
591 | d->m_mapFirst = first; | |
591 | if (count == 0) { |
|
592 | if (count == 0) { | |
592 | d->m_mapLimited = false; |
|
593 | d->m_mapLimited = false; | |
593 | } else { |
|
594 | } else { | |
594 | d->m_mapCount = count; |
|
595 | d->m_mapCount = count; | |
595 | d->m_mapLimited = true; |
|
596 | d->m_mapLimited = true; | |
596 | } |
|
597 | } | |
597 | } |
|
598 | } | |
598 |
|
599 | |||
599 | int QXYSeries::mapFirst() const |
|
600 | int QXYSeries::mapFirst() const | |
600 | { |
|
601 | { | |
601 | Q_D(const QXYSeries); |
|
602 | Q_D(const QXYSeries); | |
602 | return d->m_mapFirst; |
|
603 | return d->m_mapFirst; | |
603 | } |
|
604 | } | |
604 |
|
605 | |||
605 | int QXYSeries::mapCount() const |
|
606 | int QXYSeries::mapCount() const | |
606 | { |
|
607 | { | |
607 | Q_D(const QXYSeries); |
|
608 | Q_D(const QXYSeries); | |
608 | return d->m_mapCount; |
|
609 | return d->m_mapCount; | |
609 | } |
|
610 | } | |
610 |
|
611 | |||
611 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
612 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
612 |
|
613 | |||
613 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q): QSeriesPrivate(q), |
|
614 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q): QSeriesPrivate(q), | |
614 | m_mapX(-1), |
|
615 | m_mapX(-1), | |
615 | m_mapY(-1), |
|
616 | m_mapY(-1), | |
616 | m_mapFirst(0), |
|
617 | m_mapFirst(0), | |
617 | m_mapCount(0), |
|
618 | m_mapCount(0), | |
618 | m_mapLimited(false), |
|
619 | m_mapLimited(false), | |
619 | m_mapOrientation( Qt::Vertical), |
|
620 | m_mapOrientation( Qt::Vertical), | |
620 | m_pointsVisible(false) |
|
621 | m_pointsVisible(false) | |
621 | { |
|
622 | { | |
622 |
|
623 | |||
623 | } |
|
624 | } | |
624 |
|
625 | |||
625 | void QXYSeriesPrivate::scaleDomain(Domain& domain) |
|
626 | void QXYSeriesPrivate::scaleDomain(Domain& domain) | |
626 | { |
|
627 | { | |
627 | qreal minX(domain.minX()); |
|
628 | qreal minX(domain.minX()); | |
628 | qreal minY(domain.minY()); |
|
629 | qreal minY(domain.minY()); | |
629 | qreal maxX(domain.maxX()); |
|
630 | qreal maxX(domain.maxX()); | |
630 | qreal maxY(domain.maxY()); |
|
631 | qreal maxY(domain.maxY()); | |
631 | int tickXCount(domain.tickXCount()); |
|
632 | int tickXCount(domain.tickXCount()); | |
632 | int tickYCount(domain.tickYCount()); |
|
633 | int tickYCount(domain.tickYCount()); | |
633 |
|
634 | |||
634 | Q_Q(QXYSeries); |
|
635 | Q_Q(QXYSeries); | |
635 | for (int i = 0; i < q->count(); i++) |
|
636 | for (int i = 0; i < q->count(); i++) | |
636 | { |
|
637 | { | |
637 | qreal x = q->x(i); |
|
638 | qreal x = q->x(i); | |
638 | qreal y = q->y(i); |
|
639 | qreal y = q->y(i); | |
639 | minX = qMin(minX, x); |
|
640 | minX = qMin(minX, x); | |
640 | minY = qMin(minY, y); |
|
641 | minY = qMin(minY, y); | |
641 | maxX = qMax(maxX, x); |
|
642 | maxX = qMax(maxX, x); | |
642 | maxY = qMax(maxY, y); |
|
643 | maxY = qMax(maxY, y); | |
643 | } |
|
644 | } | |
644 |
|
645 | |||
645 | domain.setRangeX(minX,maxX,tickXCount); |
|
646 | domain.setRangeX(minX,maxX,tickXCount); | |
646 | domain.setRangeY(minY,maxY,tickYCount); |
|
647 | domain.setRangeY(minY,maxY,tickYCount); | |
647 | } |
|
648 | } | |
648 |
|
649 | |||
|
650 | QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) | |||
|
651 | { | |||
|
652 | Q_Q(QXYSeries); | |||
|
653 | QList<LegendMarker*> list; | |||
|
654 | return list << new XYLegendMarker(q,legend); | |||
|
655 | } | |||
|
656 | ||||
649 | #include "moc_qxyseries.cpp" |
|
657 | #include "moc_qxyseries.cpp" | |
650 | #include "moc_qxyseries_p.cpp" |
|
658 | #include "moc_qxyseries_p.cpp" | |
651 |
|
659 | |||
652 | QTCOMMERCIALCHART_END_NAMESPACE |
|
660 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,78 +1,79 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QXYSERIES_P_H_ |
|
30 | #ifndef QXYSERIES_P_H_ | |
31 | #define QXYSERIES_P_H_ |
|
31 | #define QXYSERIES_P_H_ | |
32 |
|
32 | |||
33 | #include "qseries_p.h" |
|
33 | #include "qseries_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QXYSeries; |
|
37 | class QXYSeries; | |
38 |
|
38 | |||
39 | class QXYSeriesPrivate: public QSeriesPrivate |
|
39 | class QXYSeriesPrivate: public QSeriesPrivate | |
40 | { |
|
40 | { | |
41 | Q_OBJECT |
|
41 | Q_OBJECT | |
42 |
|
42 | |||
43 | public: |
|
43 | public: | |
44 | QXYSeriesPrivate(QXYSeries* q); |
|
44 | QXYSeriesPrivate(QXYSeries* q); | |
45 |
|
45 | |||
46 | void scaleDomain(Domain& domain); |
|
46 | void scaleDomain(Domain& domain); | |
|
47 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |||
47 |
|
48 | |||
48 | Q_SIGNALS: |
|
49 | Q_SIGNALS: | |
49 | void updated(); |
|
50 | void updated(); | |
50 | void pointReplaced(int index); |
|
51 | void pointReplaced(int index); | |
51 | void pointRemoved(int index); |
|
52 | void pointRemoved(int index); | |
52 | void pointAdded(int index); |
|
53 | void pointAdded(int index); | |
53 |
|
54 | |||
54 | protected: |
|
55 | protected: | |
55 | QVector<qreal> m_x; |
|
56 | QVector<qreal> m_x; | |
56 | QVector<qreal> m_y; |
|
57 | QVector<qreal> m_y; | |
57 |
|
58 | |||
58 | QPen m_pen; |
|
59 | QPen m_pen; | |
59 | QBrush m_brush; |
|
60 | QBrush m_brush; | |
60 |
|
61 | |||
61 | int m_mapX; |
|
62 | int m_mapX; | |
62 | int m_mapY; |
|
63 | int m_mapY; | |
63 | int m_mapFirst; |
|
64 | int m_mapFirst; | |
64 | int m_mapCount; |
|
65 | int m_mapCount; | |
65 | bool m_mapLimited; |
|
66 | bool m_mapLimited; | |
66 | Qt::Orientation m_mapOrientation; |
|
67 | Qt::Orientation m_mapOrientation; | |
67 | int tempItemsRemoved; |
|
68 | int tempItemsRemoved; | |
68 | bool m_pointsVisible; |
|
69 | bool m_pointsVisible; | |
69 |
|
70 | |||
70 | private: |
|
71 | private: | |
71 | Q_DECLARE_PUBLIC(QXYSeries); |
|
72 | Q_DECLARE_PUBLIC(QXYSeries); | |
72 | friend class QScatterSeries; |
|
73 | friend class QScatterSeries; | |
73 |
|
74 | |||
74 | }; |
|
75 | }; | |
75 |
|
76 | |||
76 | QTCOMMERCIALCHART_END_NAMESPACE |
|
77 | QTCOMMERCIALCHART_END_NAMESPACE | |
77 |
|
78 | |||
78 | #endif |
|
79 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now