@@ -1,37 +1,35 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "mainwidget.h" |
|
22 | 22 | |
|
23 | 23 | #include <QApplication> |
|
24 | 24 | #include <QMainWindow> |
|
25 | 25 | |
|
26 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
27 | ||
|
28 | 26 | int main(int argc, char *argv[]) |
|
29 | 27 | { |
|
30 | 28 | QApplication a(argc, argv); |
|
31 | 29 | |
|
32 | 30 | MainWidget w; |
|
33 | 31 | w.resize(720, 480); |
|
34 | 32 | w.show(); |
|
35 | 33 | |
|
36 | 34 | return a.exec(); |
|
37 | 35 | } |
@@ -1,88 +1,84 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef MAINWIDGET_H |
|
22 | 22 | #define MAINWIDGET_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "qchart.h" |
|
26 | 26 | #include "qchartview.h" |
|
27 | 27 | #include <QWidget> |
|
28 | 28 | #include <QGraphicsWidget> |
|
29 | 29 | #include <QGridLayout> |
|
30 | 30 | #include <QGraphicsGridLayout> |
|
31 | 31 | #include <QDoubleSpinBox> |
|
32 | 32 | #include <QGroupBox> |
|
33 | 33 | #include <QPieSlice> |
|
34 | 34 | #include <QPieSeries> |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | class MainWidget : public QWidget |
|
39 | 39 | { |
|
40 | 40 | Q_OBJECT |
|
41 | 41 | public: |
|
42 | 42 | explicit MainWidget(QWidget *parent = 0); |
|
43 | 43 | void createSeries(); |
|
44 | 44 | void showLegendSpinbox(); |
|
45 | 45 | void hideLegendSpinbox(); |
|
46 | 46 | |
|
47 | signals: | |
|
48 | ||
|
49 | 47 | public slots: |
|
50 | 48 | void toggleAttached(); |
|
51 | 49 | void addSlice(); |
|
52 | 50 | void removeSlice(); |
|
53 | 51 | void connectMarkers(); |
|
54 | 52 | void disconnectMarkers(); |
|
55 | 53 | |
|
56 | 54 | void setLegendAlignment(); |
|
57 | 55 | |
|
58 | 56 | void toggleBold(); |
|
59 | 57 | void toggleItalic(); |
|
60 | 58 | void showDebugInfo(); |
|
61 | 59 | void fontSizeChanged(); |
|
62 | 60 | |
|
63 | 61 | void updateLegendLayout(); |
|
64 | ||
|
65 | 62 | void handleMarkerClicked(); |
|
66 | 63 | |
|
67 | ||
|
68 | 64 | private: |
|
69 | 65 | |
|
70 | 66 | QChart *m_chart; |
|
71 | 67 | QPieSeries *m_series; |
|
72 | 68 | |
|
73 | 69 | QChartView *m_chartView; |
|
74 | 70 | QGridLayout *m_mainLayout; |
|
75 | 71 | QGridLayout *m_buttonLayout; |
|
76 | 72 | QGridLayout *m_fontLayout; |
|
77 | 73 | |
|
78 | 74 | QDoubleSpinBox *m_fontSize; |
|
79 | 75 | |
|
80 | 76 | // For detached layout |
|
81 | 77 | QGroupBox* m_legendSettings; |
|
82 | 78 | QDoubleSpinBox *m_legendPosX; |
|
83 | 79 | QDoubleSpinBox *m_legendPosY; |
|
84 | 80 | QDoubleSpinBox *m_legendWidth; |
|
85 | 81 | QDoubleSpinBox *m_legendHeight; |
|
86 | 82 | }; |
|
87 | 83 | |
|
88 | 84 | #endif // MAINWIDGET_H |
@@ -1,400 +1,399 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qareaseries.h" |
|
22 | 22 | #include "qareaseries_p.h" |
|
23 | 23 | #include "qlineseries.h" |
|
24 | 24 | #include "areachartitem_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include "charttheme_p.h" |
|
28 | 28 | #include "qvalueaxis.h" |
|
29 | ||
|
30 | 29 | #include "qarealegendmarker.h" |
|
31 | 30 | |
|
32 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 32 | |
|
34 | 33 | /*! |
|
35 | 34 | \class QAreaSeries |
|
36 | 35 | \brief The QAreaSeries class is used for making area charts. |
|
37 | 36 | |
|
38 | 37 | \mainclass |
|
39 | 38 | |
|
40 | 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 |
|
41 | 40 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, |
|
42 | 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. |
|
43 | 42 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases |
|
44 | 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. |
|
45 | 44 | |
|
46 | 45 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. |
|
47 | 46 | \image examples_areachart.png |
|
48 | 47 | */ |
|
49 | 48 | /*! |
|
50 | 49 | \qmlclass AreaSeries QAreaSeries |
|
51 | 50 | |
|
52 | 51 | The following QML shows how to create a simple area chart: |
|
53 | 52 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 |
|
54 | 53 | \beginfloatleft |
|
55 | 54 | \image demos_qmlchart4.png |
|
56 | 55 | \endfloat |
|
57 | 56 | \clearfloat |
|
58 | 57 | */ |
|
59 | 58 | |
|
60 | 59 | /*! |
|
61 | 60 | \property QAreaSeries::upperSeries |
|
62 | 61 | \brief The upper one of the two line series used to define area series boundaries. |
|
63 | 62 | */ |
|
64 | 63 | /*! |
|
65 | 64 | \qmlproperty LineSeries AreaSeries::upperSeries |
|
66 | 65 | The upper one of the two line series used to define area series boundaries. |
|
67 | 66 | */ |
|
68 | 67 | |
|
69 | 68 | /*! |
|
70 | 69 | \property QAreaSeries::lowerSeries |
|
71 | 70 | The lower one of the two line series used to define are series boundaries. Note if |
|
72 | 71 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
73 | 72 | */ |
|
74 | 73 | /*! |
|
75 | 74 | \qmlproperty LineSeries AreaSeries::lowerSeries |
|
76 | 75 | The lower one of the two line series used to define are series boundaries. Note if |
|
77 | 76 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
78 | 77 | */ |
|
79 | 78 | |
|
80 | 79 | /*! |
|
81 | 80 | \property QAreaSeries::color |
|
82 | 81 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
83 | 82 | \sa QAreaSeries::brush() |
|
84 | 83 | */ |
|
85 | 84 | /*! |
|
86 | 85 | \qmlproperty color AreaSeries::color |
|
87 | 86 | Fill (brush) color of the series. |
|
88 | 87 | */ |
|
89 | 88 | |
|
90 | 89 | /*! |
|
91 | 90 | \property QAreaSeries::borderColor |
|
92 | 91 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
93 | 92 | \sa QAreaSeries::pen() |
|
94 | 93 | */ |
|
95 | 94 | /*! |
|
96 | 95 | \qmlproperty color AreaSeries::borderColor |
|
97 | 96 | Line (pen) color of the series. |
|
98 | 97 | */ |
|
99 | 98 | |
|
100 | 99 | /*! |
|
101 | 100 | \qmlproperty real AreaSeries::borderWidth |
|
102 | 101 | The width of the border line. By default the width is 2.0. |
|
103 | 102 | */ |
|
104 | 103 | |
|
105 | 104 | /*! |
|
106 | 105 | \fn QPen QAreaSeries::pen() const |
|
107 | 106 | \brief Returns the pen used to draw line for this series. |
|
108 | 107 | \sa setPen() |
|
109 | 108 | */ |
|
110 | 109 | |
|
111 | 110 | /*! |
|
112 | 111 | \fn QPen QAreaSeries::brush() const |
|
113 | 112 | \brief Returns the brush used to draw line for this series. |
|
114 | 113 | \sa setBrush() |
|
115 | 114 | */ |
|
116 | 115 | |
|
117 | 116 | /*! |
|
118 | 117 | \fn void QAreaSeries::colorChanged(QColor color) |
|
119 | 118 | \brief Signal is emitted when the fill (brush) color has changed to \a color. |
|
120 | 119 | */ |
|
121 | 120 | /*! |
|
122 | 121 | \qmlsignal AreaSeries::onColorChanged(color color) |
|
123 | 122 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
124 | 123 | */ |
|
125 | 124 | |
|
126 | 125 | /*! |
|
127 | 126 | \fn void QAreaSeries::borderColorChanged(QColor color) |
|
128 | 127 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
129 | 128 | */ |
|
130 | 129 | /*! |
|
131 | 130 | \qmlsignal AreaSeries::onBorderColorChanged(color color) |
|
132 | 131 | Signal is emitted when the line (pen) color has changed to \a color. |
|
133 | 132 | */ |
|
134 | 133 | |
|
135 | 134 | /*! |
|
136 | 135 | \fn void QAreaSeries::clicked(const QPointF& point) |
|
137 | 136 | \brief Signal is emitted when user clicks the \a point on area chart. |
|
138 | 137 | */ |
|
139 | 138 | /*! |
|
140 | 139 | \qmlsignal AreaSeries::onClicked(QPointF point) |
|
141 | 140 | Signal is emitted when user clicks the \a point on area chart. |
|
142 | 141 | */ |
|
143 | 142 | |
|
144 | 143 | /*! |
|
145 | 144 | \fn void QAreaSeries::selected() |
|
146 | 145 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
147 | 146 | implemented by the user of QAreaSeries API. |
|
148 | 147 | */ |
|
149 | 148 | /*! |
|
150 | 149 | \qmlsignal AreaSeries::onSelected() |
|
151 | 150 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
152 | 151 | implemented by the user of AreaSeries API. |
|
153 | 152 | */ |
|
154 | 153 | |
|
155 | 154 | /*! |
|
156 | 155 | \fn void QAreaSeriesPrivate::updated() |
|
157 | 156 | \brief \internal |
|
158 | 157 | */ |
|
159 | 158 | |
|
160 | 159 | /*! |
|
161 | 160 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a |
|
162 | 161 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. |
|
163 | 162 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
164 | 163 | */ |
|
165 | 164 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
|
166 | 165 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries) |
|
167 | 166 | { |
|
168 | 167 | } |
|
169 | 168 | |
|
170 | 169 | /*! |
|
171 | 170 | Constructs area series object without upper or lower series with \a parent object. |
|
172 | 171 | */ |
|
173 | 172 | QAreaSeries::QAreaSeries(QObject *parent) |
|
174 | 173 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) |
|
175 | 174 | { |
|
176 | 175 | } |
|
177 | 176 | |
|
178 | 177 | /*! |
|
179 | 178 | Destroys the object. |
|
180 | 179 | */ |
|
181 | 180 | QAreaSeries::~QAreaSeries() |
|
182 | 181 | { |
|
183 | 182 | Q_D(QAreaSeries); |
|
184 | 183 | if (d->m_dataset) |
|
185 | 184 | d->m_dataset->removeSeries(this); |
|
186 | 185 | } |
|
187 | 186 | |
|
188 | 187 | /*! |
|
189 | 188 | Returns QChartSeries::SeriesTypeArea. |
|
190 | 189 | */ |
|
191 | 190 | QAbstractSeries::SeriesType QAreaSeries::type() const |
|
192 | 191 | { |
|
193 | 192 | return QAbstractSeries::SeriesTypeArea; |
|
194 | 193 | } |
|
195 | 194 | |
|
196 | 195 | /*! |
|
197 | 196 | Sets the \a series that is to be used as the area chart upper series. |
|
198 | 197 | */ |
|
199 | 198 | void QAreaSeries::setUpperSeries(QLineSeries *series) |
|
200 | 199 | { |
|
201 | 200 | Q_D(QAreaSeries); |
|
202 | 201 | d->m_upperSeries = series; |
|
203 | 202 | } |
|
204 | 203 | |
|
205 | 204 | QLineSeries *QAreaSeries::upperSeries() const |
|
206 | 205 | { |
|
207 | 206 | Q_D(const QAreaSeries); |
|
208 | 207 | return d->m_upperSeries; |
|
209 | 208 | } |
|
210 | 209 | |
|
211 | 210 | /*! |
|
212 | 211 | Sets the \a series that is to be used as the area chart lower series. |
|
213 | 212 | */ |
|
214 | 213 | void QAreaSeries::setLowerSeries(QLineSeries *series) |
|
215 | 214 | { |
|
216 | 215 | Q_D(QAreaSeries); |
|
217 | 216 | d->m_lowerSeries = series; |
|
218 | 217 | } |
|
219 | 218 | |
|
220 | 219 | QLineSeries *QAreaSeries::lowerSeries() const |
|
221 | 220 | { |
|
222 | 221 | Q_D(const QAreaSeries); |
|
223 | 222 | return d->m_lowerSeries; |
|
224 | 223 | } |
|
225 | 224 | |
|
226 | 225 | /*! |
|
227 | 226 | Sets \a pen used for drawing area outline. |
|
228 | 227 | */ |
|
229 | 228 | void QAreaSeries::setPen(const QPen &pen) |
|
230 | 229 | { |
|
231 | 230 | Q_D(QAreaSeries); |
|
232 | 231 | if (d->m_pen != pen) { |
|
233 | 232 | d->m_pen = pen; |
|
234 | 233 | emit d->updated(); |
|
235 | 234 | } |
|
236 | 235 | } |
|
237 | 236 | |
|
238 | 237 | QPen QAreaSeries::pen() const |
|
239 | 238 | { |
|
240 | 239 | Q_D(const QAreaSeries); |
|
241 | 240 | return d->m_pen; |
|
242 | 241 | } |
|
243 | 242 | |
|
244 | 243 | /*! |
|
245 | 244 | Sets \a brush used for filling the area. |
|
246 | 245 | */ |
|
247 | 246 | void QAreaSeries::setBrush(const QBrush &brush) |
|
248 | 247 | { |
|
249 | 248 | Q_D(QAreaSeries); |
|
250 | 249 | if (d->m_brush != brush) { |
|
251 | 250 | bool emitColorChanged = brush.color() != d->m_brush.color(); |
|
252 | 251 | d->m_brush = brush; |
|
253 | 252 | emit d->updated(); |
|
254 | 253 | if (emitColorChanged) |
|
255 | 254 | emit colorChanged(brush.color()); |
|
256 | 255 | } |
|
257 | 256 | } |
|
258 | 257 | |
|
259 | 258 | QBrush QAreaSeries::brush() const |
|
260 | 259 | { |
|
261 | 260 | Q_D(const QAreaSeries); |
|
262 | 261 | return d->m_brush; |
|
263 | 262 | } |
|
264 | 263 | |
|
265 | 264 | void QAreaSeries::setColor(const QColor &color) |
|
266 | 265 | { |
|
267 | 266 | QBrush b = brush(); |
|
268 | 267 | if (b == QBrush()) |
|
269 | 268 | b.setStyle(Qt::SolidPattern); |
|
270 | 269 | b.setColor(color); |
|
271 | 270 | setBrush(b); |
|
272 | 271 | } |
|
273 | 272 | |
|
274 | 273 | QColor QAreaSeries::color() const |
|
275 | 274 | { |
|
276 | 275 | return brush().color(); |
|
277 | 276 | } |
|
278 | 277 | |
|
279 | 278 | void QAreaSeries::setBorderColor(const QColor &color) |
|
280 | 279 | { |
|
281 | 280 | QPen p = pen(); |
|
282 | 281 | if (p.color() != color) { |
|
283 | 282 | p.setColor(color); |
|
284 | 283 | setPen(p); |
|
285 | 284 | emit borderColorChanged(color); |
|
286 | 285 | } |
|
287 | 286 | } |
|
288 | 287 | |
|
289 | 288 | QColor QAreaSeries::borderColor() const |
|
290 | 289 | { |
|
291 | 290 | return pen().color(); |
|
292 | 291 | } |
|
293 | 292 | |
|
294 | 293 | /*! |
|
295 | 294 | Sets if data points are \a visible and should be drawn on line. |
|
296 | 295 | */ |
|
297 | 296 | void QAreaSeries::setPointsVisible(bool visible) |
|
298 | 297 | { |
|
299 | 298 | Q_D(QAreaSeries); |
|
300 | 299 | if (d->m_pointsVisible != visible) { |
|
301 | 300 | d->m_pointsVisible = visible; |
|
302 | 301 | emit d->updated(); |
|
303 | 302 | } |
|
304 | 303 | } |
|
305 | 304 | |
|
306 | 305 | /*! |
|
307 | 306 | Returns if the points are drawn for this series. |
|
308 | 307 | \sa setPointsVisible() |
|
309 | 308 | */ |
|
310 | 309 | bool QAreaSeries::pointsVisible() const |
|
311 | 310 | { |
|
312 | 311 | Q_D(const QAreaSeries); |
|
313 | 312 | return d->m_pointsVisible; |
|
314 | 313 | } |
|
315 | 314 | |
|
316 | 315 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
317 | 316 | |
|
318 | 317 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q) |
|
319 | 318 | : QAbstractSeriesPrivate(q), |
|
320 | 319 | m_upperSeries(upperSeries), |
|
321 | 320 | m_lowerSeries(lowerSeries), |
|
322 | 321 | m_pointsVisible(false) |
|
323 | 322 | { |
|
324 | 323 | } |
|
325 | 324 | |
|
326 | 325 | void QAreaSeriesPrivate::scaleDomain(Domain &domain) |
|
327 | 326 | { |
|
328 | 327 | Q_Q(QAreaSeries); |
|
329 | 328 | |
|
330 | 329 | qreal minX(domain.minX()); |
|
331 | 330 | qreal minY(domain.minY()); |
|
332 | 331 | qreal maxX(domain.maxX()); |
|
333 | 332 | qreal maxY(domain.maxY()); |
|
334 | 333 | |
|
335 | 334 | QLineSeries *upperSeries = q->upperSeries(); |
|
336 | 335 | QLineSeries *lowerSeries = q->lowerSeries(); |
|
337 | 336 | |
|
338 | 337 | const QList<QPointF>& points = upperSeries->points(); |
|
339 | 338 | |
|
340 | 339 | for (int i = 0; i < points.count(); i++) { |
|
341 | 340 | qreal x = points[i].x(); |
|
342 | 341 | qreal y = points[i].y(); |
|
343 | 342 | minX = qMin(minX, x); |
|
344 | 343 | minY = qMin(minY, y); |
|
345 | 344 | maxX = qMax(maxX, x); |
|
346 | 345 | maxY = qMax(maxY, y); |
|
347 | 346 | } |
|
348 | 347 | if (lowerSeries) { |
|
349 | 348 | |
|
350 | 349 | const QList<QPointF>& points = lowerSeries->points(); |
|
351 | 350 | |
|
352 | 351 | for (int i = 0; i < points.count(); i++) { |
|
353 | 352 | qreal x = points[i].x(); |
|
354 | 353 | qreal y = points[i].y(); |
|
355 | 354 | minX = qMin(minX, x); |
|
356 | 355 | minY = qMin(minY, y); |
|
357 | 356 | maxX = qMax(maxX, x); |
|
358 | 357 | maxY = qMax(maxY, y); |
|
359 | 358 | } |
|
360 | 359 | } |
|
361 | 360 | |
|
362 | 361 | domain.setRange(minX, maxX, minY, maxY); |
|
363 | 362 | } |
|
364 | 363 | |
|
365 | 364 | ChartElement *QAreaSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
366 | 365 | { |
|
367 | 366 | Q_Q(QAreaSeries); |
|
368 | 367 | |
|
369 | 368 | AreaChartItem *area = new AreaChartItem(q, presenter); |
|
370 | 369 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
371 | 370 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
372 | 371 | if (q->lowerSeries()) |
|
373 | 372 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); |
|
374 | 373 | } |
|
375 | 374 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
376 | 375 | return area; |
|
377 | 376 | } |
|
378 | 377 | |
|
379 | 378 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
380 | 379 | { |
|
381 | 380 | Q_Q(QAreaSeries); |
|
382 | 381 | QList<QLegendMarker*> list; |
|
383 | 382 | return list << new QAreaLegendMarker(q,legend); |
|
384 | 383 | } |
|
385 | 384 | |
|
386 | 385 | void QAreaSeriesPrivate::initializeAxis(QAbstractAxis *axis) |
|
387 | 386 | { |
|
388 | 387 | Q_UNUSED(axis); |
|
389 | 388 | } |
|
390 | 389 | |
|
391 | 390 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
392 | 391 | { |
|
393 | 392 | Q_UNUSED(orientation); |
|
394 | 393 | return QAbstractAxis::AxisTypeValue; |
|
395 | 394 | } |
|
396 | 395 | |
|
397 | 396 | #include "moc_qareaseries.cpp" |
|
398 | 397 | #include "moc_qareaseries_p.cpp" |
|
399 | 398 | |
|
400 | 399 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,813 +1,812 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qabstractbarseries.h" |
|
22 | 22 | #include "qabstractbarseries_p.h" |
|
23 | 23 | #include "qbarset.h" |
|
24 | 24 | #include "qbarset_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include "charttheme_p.h" |
|
28 | 28 | #include "qvalueaxis.h" |
|
29 | 29 | #include "qbarcategoryaxis.h" |
|
30 | ||
|
31 | 30 | #include "qbarlegendmarker.h" |
|
32 | 31 | |
|
33 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 33 | |
|
35 | 34 | /*! |
|
36 | 35 | \class QAbstractBarSeries |
|
37 | 36 | \brief Series for creating a bar chart |
|
38 | 37 | \mainclass |
|
39 | 38 | |
|
40 | 39 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
41 | 40 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
42 | 41 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
43 | 42 | shows the x-values. |
|
44 | 43 | |
|
45 | 44 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
46 | 45 | \image examples_barchart.png |
|
47 | 46 | |
|
48 | 47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
49 | 48 | */ |
|
50 | 49 | /*! |
|
51 | 50 | \qmlclass AbstractBarSeries QAbstractBarSeries |
|
52 | 51 | \inherits QAbstractSeries |
|
53 | 52 | |
|
54 | 53 | The following QML shows how to create a simple bar chart: |
|
55 | 54 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
56 | 55 | |
|
57 | 56 | \beginfloatleft |
|
58 | 57 | \image demos_qmlchart6.png |
|
59 | 58 | \endfloat |
|
60 | 59 | \clearfloat |
|
61 | 60 | */ |
|
62 | 61 | |
|
63 | 62 | /*! |
|
64 | 63 | \property QAbstractBarSeries::barWidth |
|
65 | 64 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
66 | 65 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
67 | 66 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
68 | 67 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
69 | 68 | \sa QBarSeries |
|
70 | 69 | */ |
|
71 | 70 | /*! |
|
72 | 71 | \qmlproperty real AbstractBarSeries::barWidth |
|
73 | 72 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
74 | 73 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
75 | 74 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
76 | 75 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
77 | 76 | */ |
|
78 | 77 | |
|
79 | 78 | /*! |
|
80 | 79 | \property QAbstractBarSeries::count |
|
81 | 80 | Holds the number of sets in series. |
|
82 | 81 | */ |
|
83 | 82 | /*! |
|
84 | 83 | \qmlproperty int AbstractBarSeries::count |
|
85 | 84 | Holds the number of sets in series. |
|
86 | 85 | */ |
|
87 | 86 | |
|
88 | 87 | /*! |
|
89 | 88 | \property QAbstractBarSeries::labelsVisible |
|
90 | 89 | Defines the visibility of the labels in series |
|
91 | 90 | */ |
|
92 | 91 | /*! |
|
93 | 92 | \qmlproperty bool AbstractBarSeries::labelsVisible |
|
94 | 93 | Defines the visibility of the labels in series |
|
95 | 94 | */ |
|
96 | 95 | |
|
97 | 96 | /*! |
|
98 | 97 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
99 | 98 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
100 | 99 | Clicked bar inside set is indexed by \a index |
|
101 | 100 | */ |
|
102 | 101 | /*! |
|
103 | 102 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) |
|
104 | 103 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
105 | 104 | Clicked bar inside set is indexed by \a index |
|
106 | 105 | */ |
|
107 | 106 | |
|
108 | 107 | /*! |
|
109 | 108 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
110 | 109 | |
|
111 | 110 | The signal is emitted if mouse is hovered on top of series. |
|
112 | 111 | Parameter \a barset is the pointer of barset, where hover happened. |
|
113 | 112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
114 | 113 | */ |
|
115 | 114 | /*! |
|
116 | 115 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) |
|
117 | 116 | |
|
118 | 117 | The signal is emitted if mouse is hovered on top of series. |
|
119 | 118 | Parameter \a barset is the pointer of barset, where hover happened. |
|
120 | 119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
121 | 120 | */ |
|
122 | 121 | |
|
123 | 122 | /*! |
|
124 | 123 | \fn void QAbstractBarSeries::countChanged() |
|
125 | 124 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
126 | 125 | */ |
|
127 | 126 | /*! |
|
128 | 127 | \qmlsignal AbstractBarSeries::onCountChanged() |
|
129 | 128 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
130 | 129 | */ |
|
131 | 130 | |
|
132 | 131 | /*! |
|
133 | 132 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
134 | 133 | This signal is emitted when labels visibility have changed. |
|
135 | 134 | \sa isLabelsVisible(), setLabelsVisible() |
|
136 | 135 | */ |
|
137 | 136 | |
|
138 | 137 | /*! |
|
139 | 138 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
140 | 139 | This signal is emitted when \a sets have been added to the series. |
|
141 | 140 | \sa append(), insert() |
|
142 | 141 | */ |
|
143 | 142 | /*! |
|
144 | 143 | \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset) |
|
145 | 144 | Emitted when \a barset has been added to the series. |
|
146 | 145 | */ |
|
147 | 146 | |
|
148 | 147 | /*! |
|
149 | 148 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
150 | 149 | This signal is emitted when \a sets have been removed from the series. |
|
151 | 150 | \sa remove() |
|
152 | 151 | */ |
|
153 | 152 | /*! |
|
154 | 153 | \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset) |
|
155 | 154 | Emitted when \a barset has been removed from the series. |
|
156 | 155 | */ |
|
157 | 156 | |
|
158 | 157 | /*! |
|
159 | 158 | \qmlmethod BarSet AbstractBarSeries::at(int index) |
|
160 | 159 | Returns bar set at \a index. Returns null if the index is not valid. |
|
161 | 160 | */ |
|
162 | 161 | |
|
163 | 162 | /*! |
|
164 | 163 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) |
|
165 | 164 | Adds a new bar set with \a label and \a values to \a index. Values is a list of reals. |
|
166 | 165 | For example: |
|
167 | 166 | \code |
|
168 | 167 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
169 | 168 | \endcode |
|
170 | 169 | */ |
|
171 | 170 | |
|
172 | 171 | /*! |
|
173 | 172 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) |
|
174 | 173 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
175 | 174 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
176 | 175 | appended. |
|
177 | 176 | \sa AbstractBarSeries::append() |
|
178 | 177 | */ |
|
179 | 178 | |
|
180 | 179 | /*! |
|
181 | 180 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) |
|
182 | 181 | Removes the barset from the series. Returns true if successful, false otherwise. |
|
183 | 182 | */ |
|
184 | 183 | |
|
185 | 184 | /*! |
|
186 | 185 | \qmlmethod AbstractBarSeries::clear() |
|
187 | 186 | Removes all barsets from the series. |
|
188 | 187 | */ |
|
189 | 188 | |
|
190 | 189 | /*! |
|
191 | 190 | Destructs abstractbarseries and owned barsets. |
|
192 | 191 | */ |
|
193 | 192 | QAbstractBarSeries::~QAbstractBarSeries() |
|
194 | 193 | { |
|
195 | 194 | |
|
196 | 195 | } |
|
197 | 196 | |
|
198 | 197 | /*! |
|
199 | 198 | \internal |
|
200 | 199 | */ |
|
201 | 200 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent) |
|
202 | 201 | : QAbstractSeries(o, parent) |
|
203 | 202 | { |
|
204 | 203 | Q_D(QAbstractSeries); |
|
205 | 204 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); |
|
206 | 205 | } |
|
207 | 206 | |
|
208 | 207 | /*! |
|
209 | 208 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
210 | 209 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
211 | 210 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
212 | 211 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
213 | 212 | */ |
|
214 | 213 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
215 | 214 | { |
|
216 | 215 | Q_D(QAbstractBarSeries); |
|
217 | 216 | d->setBarWidth(width); |
|
218 | 217 | } |
|
219 | 218 | |
|
220 | 219 | /*! |
|
221 | 220 | Returns the width of the bars of the series. |
|
222 | 221 | \sa setBarWidth() |
|
223 | 222 | */ |
|
224 | 223 | qreal QAbstractBarSeries::barWidth() const |
|
225 | 224 | { |
|
226 | 225 | Q_D(const QAbstractBarSeries); |
|
227 | 226 | return d->barWidth(); |
|
228 | 227 | } |
|
229 | 228 | |
|
230 | 229 | /*! |
|
231 | 230 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
232 | 231 | Returns true, if appending succeeded. |
|
233 | 232 | */ |
|
234 | 233 | bool QAbstractBarSeries::append(QBarSet *set) |
|
235 | 234 | { |
|
236 | 235 | Q_D(QAbstractBarSeries); |
|
237 | 236 | bool success = d->append(set); |
|
238 | 237 | if (success) { |
|
239 | 238 | QList<QBarSet *> sets; |
|
240 | 239 | sets.append(set); |
|
241 | 240 | set->setParent(this); |
|
242 | 241 | emit barsetsAdded(sets); |
|
243 | 242 | emit countChanged(); |
|
244 | 243 | } |
|
245 | 244 | return success; |
|
246 | 245 | } |
|
247 | 246 | |
|
248 | 247 | /*! |
|
249 | 248 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove |
|
250 | 249 | was successful. |
|
251 | 250 | Returns true, if set was removed. |
|
252 | 251 | */ |
|
253 | 252 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
254 | 253 | { |
|
255 | 254 | Q_D(QAbstractBarSeries); |
|
256 | 255 | bool success = d->remove(set); |
|
257 | 256 | if (success) { |
|
258 | 257 | QList<QBarSet *> sets; |
|
259 | 258 | sets.append(set); |
|
260 | 259 | set->setParent(0); |
|
261 | 260 | emit barsetsRemoved(sets); |
|
262 | 261 | emit countChanged(); |
|
263 | 262 | delete set; |
|
264 | 263 | set = 0; |
|
265 | 264 | } |
|
266 | 265 | return success; |
|
267 | 266 | } |
|
268 | 267 | |
|
269 | 268 | /*! |
|
270 | 269 | Takes a single \a set from the series. Does not delete the barset object. |
|
271 | 270 | |
|
272 | 271 | NOTE: The series remains as the barset's parent object. You must set the |
|
273 | 272 | parent object to take full ownership. |
|
274 | 273 | |
|
275 | 274 | Returns true if take was successful. |
|
276 | 275 | */ |
|
277 | 276 | bool QAbstractBarSeries::take(QBarSet *set) |
|
278 | 277 | { |
|
279 | 278 | Q_D(QAbstractBarSeries); |
|
280 | 279 | bool success = d->remove(set); |
|
281 | 280 | if (success) { |
|
282 | 281 | QList<QBarSet *> sets; |
|
283 | 282 | sets.append(set); |
|
284 | 283 | emit barsetsRemoved(sets); |
|
285 | 284 | emit countChanged(); |
|
286 | 285 | } |
|
287 | 286 | return success; |
|
288 | 287 | } |
|
289 | 288 | |
|
290 | 289 | /*! |
|
291 | 290 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
292 | 291 | Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, |
|
293 | 292 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
294 | 293 | and function returns false. |
|
295 | 294 | */ |
|
296 | 295 | bool QAbstractBarSeries::append(QList<QBarSet *> sets) |
|
297 | 296 | { |
|
298 | 297 | Q_D(QAbstractBarSeries); |
|
299 | 298 | bool success = d->append(sets); |
|
300 | 299 | if (success) { |
|
301 | 300 | emit barsetsAdded(sets); |
|
302 | 301 | emit countChanged(); |
|
303 | 302 | } |
|
304 | 303 | return success; |
|
305 | 304 | } |
|
306 | 305 | |
|
307 | 306 | /*! |
|
308 | 307 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
309 | 308 | Returns true, if inserting succeeded. |
|
310 | 309 | |
|
311 | 310 | */ |
|
312 | 311 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
313 | 312 | { |
|
314 | 313 | Q_D(QAbstractBarSeries); |
|
315 | 314 | bool success = d->insert(index, set); |
|
316 | 315 | if (success) { |
|
317 | 316 | QList<QBarSet *> sets; |
|
318 | 317 | sets.append(set); |
|
319 | 318 | emit barsetsAdded(sets); |
|
320 | 319 | emit countChanged(); |
|
321 | 320 | } |
|
322 | 321 | return success; |
|
323 | 322 | } |
|
324 | 323 | |
|
325 | 324 | /*! |
|
326 | 325 | Removes all barsets from the series. Deletes removed sets. |
|
327 | 326 | */ |
|
328 | 327 | void QAbstractBarSeries::clear() |
|
329 | 328 | { |
|
330 | 329 | Q_D(QAbstractBarSeries); |
|
331 | 330 | QList<QBarSet *> sets = barSets(); |
|
332 | 331 | bool success = d->remove(sets); |
|
333 | 332 | if (success) { |
|
334 | 333 | emit barsetsRemoved(sets); |
|
335 | 334 | emit countChanged(); |
|
336 | 335 | foreach (QBarSet *set, sets) |
|
337 | 336 | delete set; |
|
338 | 337 | } |
|
339 | 338 | } |
|
340 | 339 | |
|
341 | 340 | /*! |
|
342 | 341 | Returns number of sets in series. |
|
343 | 342 | */ |
|
344 | 343 | int QAbstractBarSeries::count() const |
|
345 | 344 | { |
|
346 | 345 | Q_D(const QAbstractBarSeries); |
|
347 | 346 | return d->m_barSets.count(); |
|
348 | 347 | } |
|
349 | 348 | |
|
350 | 349 | /*! |
|
351 | 350 | Returns a list of sets in series. Keeps ownership of sets. |
|
352 | 351 | */ |
|
353 | 352 | QList<QBarSet *> QAbstractBarSeries::barSets() const |
|
354 | 353 | { |
|
355 | 354 | Q_D(const QAbstractBarSeries); |
|
356 | 355 | return d->m_barSets; |
|
357 | 356 | } |
|
358 | 357 | |
|
359 | 358 | /*! |
|
360 | 359 | Sets the visibility of labels in series to \a visible |
|
361 | 360 | */ |
|
362 | 361 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
363 | 362 | { |
|
364 | 363 | Q_D(QAbstractBarSeries); |
|
365 | 364 | if (d->m_labelsVisible != visible) { |
|
366 | 365 | d->setLabelsVisible(visible); |
|
367 | 366 | emit labelsVisibleChanged(); |
|
368 | 367 | } |
|
369 | 368 | } |
|
370 | 369 | |
|
371 | 370 | /*! |
|
372 | 371 | Returns the visibility of labels |
|
373 | 372 | */ |
|
374 | 373 | bool QAbstractBarSeries::isLabelsVisible() const |
|
375 | 374 | { |
|
376 | 375 | Q_D(const QAbstractBarSeries); |
|
377 | 376 | return d->m_labelsVisible; |
|
378 | 377 | } |
|
379 | 378 | |
|
380 | 379 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
381 | 380 | |
|
382 | 381 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
383 | 382 | QAbstractSeriesPrivate(q), |
|
384 | 383 | m_barWidth(0.5), // Default value is 50% of category width |
|
385 | 384 | m_labelsVisible(false), |
|
386 | 385 | m_visible(true) |
|
387 | 386 | { |
|
388 | 387 | } |
|
389 | 388 | |
|
390 | 389 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
391 | 390 | { |
|
392 | 391 | // No categories defined. return count of longest set. |
|
393 | 392 | int count = 0; |
|
394 | 393 | for (int i = 0; i < m_barSets.count(); i++) { |
|
395 | 394 | if (m_barSets.at(i)->count() > count) |
|
396 | 395 | count = m_barSets.at(i)->count(); |
|
397 | 396 | } |
|
398 | 397 | |
|
399 | 398 | return count; |
|
400 | 399 | } |
|
401 | 400 | |
|
402 | 401 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
403 | 402 | { |
|
404 | 403 | if (width < 0.0) |
|
405 | 404 | width = 0.0; |
|
406 | 405 | m_barWidth = width; |
|
407 | 406 | emit updatedLayout(); |
|
408 | 407 | } |
|
409 | 408 | |
|
410 | 409 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
411 | 410 | { |
|
412 | 411 | return m_barWidth; |
|
413 | 412 | } |
|
414 | 413 | |
|
415 | 414 | QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index) |
|
416 | 415 | { |
|
417 | 416 | return m_barSets.at(index); |
|
418 | 417 | } |
|
419 | 418 | |
|
420 | 419 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
421 | 420 | { |
|
422 | 421 | m_visible = visible; |
|
423 | 422 | emit visibleChanged(); |
|
424 | 423 | } |
|
425 | 424 | |
|
426 | 425 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
427 | 426 | { |
|
428 | 427 | m_labelsVisible = visible; |
|
429 | 428 | emit labelsVisibleChanged(visible); |
|
430 | 429 | } |
|
431 | 430 | |
|
432 | 431 | qreal QAbstractBarSeriesPrivate::min() |
|
433 | 432 | { |
|
434 | 433 | if (m_barSets.count() <= 0) |
|
435 | 434 | return 0; |
|
436 | 435 | |
|
437 | 436 | qreal min = INT_MAX; |
|
438 | 437 | |
|
439 | 438 | for (int i = 0; i < m_barSets.count(); i++) { |
|
440 | 439 | int categoryCount = m_barSets.at(i)->count(); |
|
441 | 440 | for (int j = 0; j < categoryCount; j++) { |
|
442 | 441 | qreal temp = m_barSets.at(i)->at(j); |
|
443 | 442 | if (temp < min) |
|
444 | 443 | min = temp; |
|
445 | 444 | } |
|
446 | 445 | } |
|
447 | 446 | return min; |
|
448 | 447 | } |
|
449 | 448 | |
|
450 | 449 | qreal QAbstractBarSeriesPrivate::max() |
|
451 | 450 | { |
|
452 | 451 | if (m_barSets.count() <= 0) |
|
453 | 452 | return 0; |
|
454 | 453 | |
|
455 | 454 | qreal max = INT_MIN; |
|
456 | 455 | |
|
457 | 456 | for (int i = 0; i < m_barSets.count(); i++) { |
|
458 | 457 | int categoryCount = m_barSets.at(i)->count(); |
|
459 | 458 | for (int j = 0; j < categoryCount; j++) { |
|
460 | 459 | qreal temp = m_barSets.at(i)->at(j); |
|
461 | 460 | if (temp > max) |
|
462 | 461 | max = temp; |
|
463 | 462 | } |
|
464 | 463 | } |
|
465 | 464 | |
|
466 | 465 | return max; |
|
467 | 466 | } |
|
468 | 467 | |
|
469 | 468 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
470 | 469 | { |
|
471 | 470 | if ((set < 0) || (set >= m_barSets.count())) |
|
472 | 471 | return 0; // No set, no value. |
|
473 | 472 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) |
|
474 | 473 | return 0; // No category, no value. |
|
475 | 474 | |
|
476 | 475 | return m_barSets.at(set)->at(category); |
|
477 | 476 | } |
|
478 | 477 | |
|
479 | 478 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
480 | 479 | { |
|
481 | 480 | if ((set < 0) || (set >= m_barSets.count())) |
|
482 | 481 | return 0; // No set, no value. |
|
483 | 482 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) |
|
484 | 483 | return 0; // No category, no value. |
|
485 | 484 | |
|
486 | 485 | qreal value = m_barSets.at(set)->at(category); |
|
487 | 486 | qreal sum = categorySum(category); |
|
488 | 487 | if (qFuzzyIsNull(sum)) |
|
489 | 488 | return 0; |
|
490 | 489 | |
|
491 | 490 | return value / sum; |
|
492 | 491 | } |
|
493 | 492 | |
|
494 | 493 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
495 | 494 | { |
|
496 | 495 | qreal sum(0); |
|
497 | 496 | int count = m_barSets.count(); // Count sets |
|
498 | 497 | for (int set = 0; set < count; set++) { |
|
499 | 498 | if (category < m_barSets.at(set)->count()) |
|
500 | 499 | sum += m_barSets.at(set)->at(category); |
|
501 | 500 | } |
|
502 | 501 | return sum; |
|
503 | 502 | } |
|
504 | 503 | |
|
505 | 504 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
506 | 505 | { |
|
507 | 506 | qreal sum(0); |
|
508 | 507 | int count = m_barSets.count(); // Count sets |
|
509 | 508 | for (int set = 0; set < count; set++) { |
|
510 | 509 | if (category < m_barSets.at(set)->count()) |
|
511 | 510 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
512 | 511 | } |
|
513 | 512 | return sum; |
|
514 | 513 | } |
|
515 | 514 | |
|
516 | 515 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
517 | 516 | { |
|
518 | 517 | qreal max = INT_MIN; |
|
519 | 518 | int count = categoryCount(); |
|
520 | 519 | for (int i = 0; i < count; i++) { |
|
521 | 520 | qreal sum = categorySum(i); |
|
522 | 521 | if (sum > max) |
|
523 | 522 | max = sum; |
|
524 | 523 | } |
|
525 | 524 | return max; |
|
526 | 525 | } |
|
527 | 526 | |
|
528 | 527 | qreal QAbstractBarSeriesPrivate::minX() |
|
529 | 528 | { |
|
530 | 529 | if (m_barSets.count() <= 0) |
|
531 | 530 | return 0; |
|
532 | 531 | |
|
533 | 532 | qreal min = INT_MAX; |
|
534 | 533 | |
|
535 | 534 | for (int i = 0; i < m_barSets.count(); i++) { |
|
536 | 535 | int categoryCount = m_barSets.at(i)->count(); |
|
537 | 536 | for (int j = 0; j < categoryCount; j++) { |
|
538 | 537 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
539 | 538 | if (temp < min) |
|
540 | 539 | min = temp; |
|
541 | 540 | } |
|
542 | 541 | } |
|
543 | 542 | return min; |
|
544 | 543 | } |
|
545 | 544 | |
|
546 | 545 | qreal QAbstractBarSeriesPrivate::maxX() |
|
547 | 546 | { |
|
548 | 547 | if (m_barSets.count() <= 0) |
|
549 | 548 | return 0; |
|
550 | 549 | |
|
551 | 550 | qreal max = INT_MIN; |
|
552 | 551 | |
|
553 | 552 | for (int i = 0; i < m_barSets.count(); i++) { |
|
554 | 553 | int categoryCount = m_barSets.at(i)->count(); |
|
555 | 554 | for (int j = 0; j < categoryCount; j++) { |
|
556 | 555 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
557 | 556 | if (temp > max) |
|
558 | 557 | max = temp; |
|
559 | 558 | } |
|
560 | 559 | } |
|
561 | 560 | |
|
562 | 561 | return max; |
|
563 | 562 | } |
|
564 | 563 | |
|
565 | 564 | qreal QAbstractBarSeriesPrivate::categoryTop(int category) |
|
566 | 565 | { |
|
567 | 566 | // Returns top (sum of all positive values) of category. |
|
568 | 567 | // Returns 0, if all values are negative |
|
569 | 568 | qreal top(0); |
|
570 | 569 | int count = m_barSets.count(); |
|
571 | 570 | for (int set = 0; set < count; set++) { |
|
572 | 571 | if (category < m_barSets.at(set)->count()) { |
|
573 | 572 | qreal temp = m_barSets.at(set)->at(category); |
|
574 | 573 | if (temp > 0) { |
|
575 | 574 | top += temp; |
|
576 | 575 | } |
|
577 | 576 | } |
|
578 | 577 | } |
|
579 | 578 | return top; |
|
580 | 579 | } |
|
581 | 580 | |
|
582 | 581 | qreal QAbstractBarSeriesPrivate::categoryBottom(int category) |
|
583 | 582 | { |
|
584 | 583 | // Returns bottom (sum of all negative values) of category |
|
585 | 584 | // Returns 0, if all values are positive |
|
586 | 585 | qreal bottom(0); |
|
587 | 586 | int count = m_barSets.count(); |
|
588 | 587 | for (int set = 0; set < count; set++) { |
|
589 | 588 | if (category < m_barSets.at(set)->count()) { |
|
590 | 589 | qreal temp = m_barSets.at(set)->at(category); |
|
591 | 590 | if (temp < 0) { |
|
592 | 591 | bottom += temp; |
|
593 | 592 | } |
|
594 | 593 | } |
|
595 | 594 | } |
|
596 | 595 | return bottom; |
|
597 | 596 | } |
|
598 | 597 | |
|
599 | 598 | qreal QAbstractBarSeriesPrivate::top() |
|
600 | 599 | { |
|
601 | 600 | // Returns top of all categories |
|
602 | 601 | qreal top(0); |
|
603 | 602 | int count = categoryCount(); |
|
604 | 603 | for (int i = 0; i < count; i++) { |
|
605 | 604 | qreal temp = categoryTop(i); |
|
606 | 605 | if (temp > top) |
|
607 | 606 | top = temp; |
|
608 | 607 | } |
|
609 | 608 | return top; |
|
610 | 609 | } |
|
611 | 610 | |
|
612 | 611 | qreal QAbstractBarSeriesPrivate::bottom() |
|
613 | 612 | { |
|
614 | 613 | // Returns bottom of all categories |
|
615 | 614 | qreal bottom(0); |
|
616 | 615 | int count = categoryCount(); |
|
617 | 616 | for (int i = 0; i < count; i++) { |
|
618 | 617 | qreal temp = categoryBottom(i); |
|
619 | 618 | if (temp < bottom) |
|
620 | 619 | bottom = temp; |
|
621 | 620 | } |
|
622 | 621 | return bottom; |
|
623 | 622 | } |
|
624 | 623 | |
|
625 | 624 | |
|
626 | 625 | void QAbstractBarSeriesPrivate::scaleDomain(Domain &domain) |
|
627 | 626 | { |
|
628 | 627 | qreal minX(domain.minX()); |
|
629 | 628 | qreal minY(domain.minY()); |
|
630 | 629 | qreal maxX(domain.maxX()); |
|
631 | 630 | qreal maxY(domain.maxY()); |
|
632 | 631 | |
|
633 | 632 | qreal seriesMinX = this->minX(); |
|
634 | 633 | qreal seriesMaxX = this->maxX(); |
|
635 | 634 | qreal y = max(); |
|
636 | 635 | minX = qMin(minX, seriesMinX - (qreal)0.5); |
|
637 | 636 | minY = qMin(minY, y); |
|
638 | 637 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); |
|
639 | 638 | maxY = qMax(maxY, y); |
|
640 | 639 | |
|
641 | 640 | domain.setRange(minX, maxX, minY, maxY); |
|
642 | 641 | } |
|
643 | 642 | |
|
644 | 643 | ChartElement *QAbstractBarSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
645 | 644 | { |
|
646 | 645 | Q_UNUSED(presenter); |
|
647 | 646 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; |
|
648 | 647 | return 0; |
|
649 | 648 | } |
|
650 | 649 | |
|
651 | 650 | QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
652 | 651 | { |
|
653 | 652 | Q_Q(QAbstractBarSeries); |
|
654 | 653 | QList<QLegendMarker*> markers; |
|
655 | 654 | |
|
656 | 655 | foreach(QBarSet* set, q->barSets()) { |
|
657 | 656 | QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend); |
|
658 | 657 | markers << marker; |
|
659 | 658 | } |
|
660 | 659 | return markers; |
|
661 | 660 | } |
|
662 | 661 | |
|
663 | 662 | |
|
664 | 663 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
665 | 664 | { |
|
666 | 665 | if ((m_barSets.contains(set)) || (set == 0)) |
|
667 | 666 | return false; // Fail if set is already in list or set is null. |
|
668 | 667 | |
|
669 | 668 | m_barSets.append(set); |
|
670 | 669 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
671 | 670 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
672 | 671 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
673 | 672 | |
|
674 | 673 | emit restructuredBars(); // this notifies barchartitem |
|
675 | 674 | return true; |
|
676 | 675 | } |
|
677 | 676 | |
|
678 | 677 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
679 | 678 | { |
|
680 | 679 | if (!m_barSets.contains(set)) |
|
681 | 680 | return false; // Fail if set is not in list |
|
682 | 681 | |
|
683 | 682 | m_barSets.removeOne(set); |
|
684 | 683 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
685 | 684 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
686 | 685 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
687 | 686 | |
|
688 | 687 | emit restructuredBars(); // this notifies barchartitem |
|
689 | 688 | return true; |
|
690 | 689 | } |
|
691 | 690 | |
|
692 | 691 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets) |
|
693 | 692 | { |
|
694 | 693 | foreach (QBarSet *set, sets) { |
|
695 | 694 | if ((set == 0) || (m_barSets.contains(set))) |
|
696 | 695 | return false; // Fail if any of the sets is null or is already appended. |
|
697 | 696 | if (sets.count(set) != 1) |
|
698 | 697 | return false; // Also fail if same set is more than once in given list. |
|
699 | 698 | } |
|
700 | 699 | |
|
701 | 700 | foreach (QBarSet *set, sets) { |
|
702 | 701 | m_barSets.append(set); |
|
703 | 702 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
704 | 703 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
705 | 704 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
706 | 705 | } |
|
707 | 706 | |
|
708 | 707 | emit restructuredBars(); // this notifies barchartitem |
|
709 | 708 | return true; |
|
710 | 709 | } |
|
711 | 710 | |
|
712 | 711 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets) |
|
713 | 712 | { |
|
714 | 713 | if (sets.count() == 0) |
|
715 | 714 | return false; |
|
716 | 715 | |
|
717 | 716 | foreach (QBarSet *set, sets) { |
|
718 | 717 | if ((set == 0) || (!m_barSets.contains(set))) |
|
719 | 718 | return false; // Fail if any of the sets is null or is not in series |
|
720 | 719 | if (sets.count(set) != 1) |
|
721 | 720 | return false; // Also fail if same set is more than once in given list. |
|
722 | 721 | } |
|
723 | 722 | |
|
724 | 723 | foreach (QBarSet *set, sets) { |
|
725 | 724 | m_barSets.removeOne(set); |
|
726 | 725 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
727 | 726 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
728 | 727 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
729 | 728 | } |
|
730 | 729 | |
|
731 | 730 | emit restructuredBars(); // this notifies barchartitem |
|
732 | 731 | |
|
733 | 732 | return true; |
|
734 | 733 | } |
|
735 | 734 | |
|
736 | 735 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
737 | 736 | { |
|
738 | 737 | if ((m_barSets.contains(set)) || (set == 0)) |
|
739 | 738 | return false; // Fail if set is already in list or set is null. |
|
740 | 739 | |
|
741 | 740 | m_barSets.insert(index, set); |
|
742 | 741 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
743 | 742 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
744 | 743 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
745 | 744 | |
|
746 | 745 | emit restructuredBars(); // this notifies barchartitem |
|
747 | 746 | return true; |
|
748 | 747 | } |
|
749 | 748 | |
|
750 | 749 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis *axis) |
|
751 | 750 | { |
|
752 | 751 | Q_Q(QAbstractBarSeries); |
|
753 | 752 | |
|
754 | 753 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { |
|
755 | 754 | switch (q->type()) { |
|
756 | 755 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
757 | 756 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
758 | 757 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
759 | 758 | if (axis->orientation() == Qt::Vertical) |
|
760 | 759 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); |
|
761 | 760 | break; |
|
762 | 761 | case QAbstractSeries::SeriesTypeBar: |
|
763 | 762 | case QAbstractSeries::SeriesTypePercentBar: |
|
764 | 763 | case QAbstractSeries::SeriesTypeStackedBar: |
|
765 | 764 | if (axis->orientation() == Qt::Horizontal) |
|
766 | 765 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); |
|
767 | 766 | break; |
|
768 | 767 | default: |
|
769 | 768 | qWarning() << "Unexpected series type"; |
|
770 | 769 | break; |
|
771 | 770 | } |
|
772 | 771 | } |
|
773 | 772 | } |
|
774 | 773 | |
|
775 | 774 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
776 | 775 | { |
|
777 | 776 | Q_Q(const QAbstractBarSeries); |
|
778 | 777 | |
|
779 | 778 | switch (q->type()) { |
|
780 | 779 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
781 | 780 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
782 | 781 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
783 | 782 | if (orientation == Qt::Vertical) |
|
784 | 783 | return QAbstractAxis::AxisTypeBarCategory; |
|
785 | 784 | break; |
|
786 | 785 | case QAbstractSeries::SeriesTypeBar: |
|
787 | 786 | case QAbstractSeries::SeriesTypePercentBar: |
|
788 | 787 | case QAbstractSeries::SeriesTypeStackedBar: |
|
789 | 788 | if (orientation == Qt::Horizontal) |
|
790 | 789 | return QAbstractAxis::AxisTypeBarCategory; |
|
791 | 790 | break; |
|
792 | 791 | default: |
|
793 | 792 | qWarning() << "Unexpected series type"; |
|
794 | 793 | break; |
|
795 | 794 | } |
|
796 | 795 | return QAbstractAxis::AxisTypeValue; |
|
797 | 796 | |
|
798 | 797 | } |
|
799 | 798 | |
|
800 | 799 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis) |
|
801 | 800 | { |
|
802 | 801 | QStringList categories; |
|
803 | 802 | if (axis->categories().isEmpty()) { |
|
804 | 803 | for (int i(1); i < categoryCount() + 1; i++) |
|
805 | 804 | categories << QString::number(i); |
|
806 | 805 | axis->append(categories); |
|
807 | 806 | } |
|
808 | 807 | } |
|
809 | 808 | |
|
810 | 809 | #include "moc_qabstractbarseries.cpp" |
|
811 | 810 | #include "moc_qabstractbarseries_p.cpp" |
|
812 | 811 | |
|
813 | 812 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,399 +1,399 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "legendlayout_p.h" |
|
22 | 22 | #include "chartpresenter_p.h" |
|
23 | 23 | #include "qlegend_p.h" |
|
24 | 24 | #include "chartlayout_p.h" |
|
25 | 25 | |
|
26 | 26 | #include "qlegendmarker_p.h" |
|
27 | 27 | #include "legendmarkeritem_p.h" |
|
28 | 28 | #include "qlegendmarker.h" |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | LegendLayout::LegendLayout(QLegend *legend) |
|
33 | 33 | : m_legend(legend) |
|
34 | 34 | { |
|
35 | 35 | |
|
36 | 36 | } |
|
37 | 37 | |
|
38 | 38 | LegendLayout::~LegendLayout() |
|
39 | 39 | { |
|
40 | 40 | |
|
41 | 41 | } |
|
42 | 42 | |
|
43 | 43 | void LegendLayout::setOffset(qreal x, qreal y) |
|
44 | 44 | { |
|
45 | 45 | bool scrollHorizontal = true; |
|
46 | 46 | switch (m_legend->alignment()) { |
|
47 | 47 | case Qt::AlignTop: |
|
48 | 48 | case Qt::AlignBottom: |
|
49 | 49 | scrollHorizontal = true; |
|
50 | 50 | break; |
|
51 | 51 | case Qt::AlignLeft: |
|
52 | 52 | case Qt::AlignRight: |
|
53 | 53 | scrollHorizontal = false; |
|
54 | 54 | break; |
|
55 | 55 | } |
|
56 | 56 | |
|
57 | 57 | // If detached, the scrolling direction is vertical instead of horizontal and vice versa. |
|
58 | 58 | if (!m_legend->isAttachedToChart()) |
|
59 | 59 | scrollHorizontal = !scrollHorizontal; |
|
60 | 60 | |
|
61 | 61 | QRectF boundingRect = geometry(); |
|
62 | 62 | qreal left, top, right, bottom; |
|
63 | 63 | getContentsMargins(&left, &top, &right, &bottom); |
|
64 | 64 | boundingRect.adjust(left, top, -right, -bottom); |
|
65 | 65 | |
|
66 | 66 | // Limit offset between m_minOffset and m_maxOffset |
|
67 | 67 | if (scrollHorizontal) { |
|
68 | 68 | if (m_width <= boundingRect.width()) |
|
69 | 69 | return; |
|
70 | 70 | |
|
71 | 71 | if (x != m_offsetX) { |
|
72 | 72 | m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX); |
|
73 | 73 | m_legend->d_ptr->items()->setPos(-m_offsetX, boundingRect.top()); |
|
74 | 74 | } |
|
75 | 75 | } else { |
|
76 | 76 | if (m_height <= boundingRect.height()) |
|
77 | 77 | return; |
|
78 | 78 | |
|
79 | 79 | if (y != m_offsetY) { |
|
80 | 80 | m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY); |
|
81 | 81 | m_legend->d_ptr->items()->setPos(boundingRect.left(), -m_offsetY); |
|
82 | 82 | } |
|
83 | 83 | } |
|
84 | 84 | } |
|
85 | 85 | |
|
86 | 86 | QPointF LegendLayout::offset() const |
|
87 | 87 | { |
|
88 | 88 | return QPointF(m_offsetX, m_offsetY); |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | void LegendLayout::invalidate() |
|
92 | 92 | { |
|
93 | 93 | QGraphicsLayout::invalidate(); |
|
94 | 94 | if (m_legend->isAttachedToChart()) |
|
95 | 95 | m_legend->d_ptr->m_presenter->layout()->invalidate(); |
|
96 | 96 | } |
|
97 | 97 | |
|
98 | 98 | void LegendLayout::setGeometry(const QRectF &rect) |
|
99 | 99 | { |
|
100 | 100 | m_legend->d_ptr->items()->setVisible(m_legend->isVisible()); |
|
101 | 101 | |
|
102 | 102 | QGraphicsLayout::setGeometry(rect); |
|
103 | 103 | |
|
104 | 104 | if (m_legend->isAttachedToChart()) |
|
105 | 105 | setAttachedGeometry(rect); |
|
106 | 106 | else |
|
107 | 107 | setDettachedGeometry(rect); |
|
108 | 108 | } |
|
109 | 109 | |
|
110 | 110 | void LegendLayout::setAttachedGeometry(const QRectF &rect) |
|
111 | 111 | { |
|
112 | 112 | if (!rect.isValid()) |
|
113 | 113 | return; |
|
114 | 114 | |
|
115 | 115 | m_offsetX = 0; |
|
116 | 116 | m_offsetY = 0; |
|
117 | 117 | |
|
118 | 118 | QSizeF size(0, 0); |
|
119 | 119 | |
|
120 |
if (m_legend->d_ptr-> |
|
|
120 | if (m_legend->d_ptr->markers().isEmpty()) { | |
|
121 | 121 | return; |
|
122 | 122 | } |
|
123 | 123 | |
|
124 | 124 | m_width = 0; |
|
125 | 125 | m_height = 0; |
|
126 | 126 | |
|
127 | 127 | qreal left, top, right, bottom; |
|
128 | 128 | getContentsMargins(&left, &top, &right, &bottom); |
|
129 | 129 | |
|
130 | 130 | QRectF geometry = rect.adjusted(left, top, -right, -bottom); |
|
131 | 131 | |
|
132 | 132 | switch(m_legend->alignment()) { |
|
133 | 133 | case Qt::AlignTop: |
|
134 | 134 | case Qt::AlignBottom: { |
|
135 | 135 | QPointF point(0,0); |
|
136 |
foreach (QLegendMarker* marker, m_legend->d_ptr-> |
|
|
136 | foreach (QLegendMarker* marker, m_legend->d_ptr->markers()) { | |
|
137 | 137 | LegendMarkerItem* item = marker->d_ptr->item(); |
|
138 | 138 | if (item->isVisible()) { |
|
139 | 139 | item->setGeometry(geometry); |
|
140 | 140 | item->setPos(point.x(),geometry.height()/2 - item->boundingRect().height()/2); |
|
141 | 141 | const QRectF& rect = item->boundingRect(); |
|
142 | 142 | size = size.expandedTo(rect.size()); |
|
143 | 143 | qreal w = rect.width(); |
|
144 | 144 | m_width+=w; |
|
145 | 145 | point.setX(point.x() + w); |
|
146 | 146 | } |
|
147 | 147 | } |
|
148 | 148 | if (m_width < geometry.width()) |
|
149 | 149 | m_legend->d_ptr->items()->setPos(geometry.width() / 2 - m_width / 2, geometry.top()); |
|
150 | 150 | else |
|
151 | 151 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
152 | 152 | m_height = size.height(); |
|
153 | 153 | } |
|
154 | 154 | break; |
|
155 | 155 | case Qt::AlignLeft: |
|
156 | 156 | case Qt::AlignRight: { |
|
157 | 157 | QPointF point(0,0); |
|
158 |
foreach (QLegendMarker* marker, m_legend->d_ptr-> |
|
|
158 | foreach (QLegendMarker* marker, m_legend->d_ptr->markers()) { | |
|
159 | 159 | LegendMarkerItem* item = marker->d_ptr->item(); |
|
160 | 160 | if (item->isVisible()) { |
|
161 | 161 | item->setGeometry(geometry); |
|
162 | 162 | item->setPos(point); |
|
163 | 163 | const QRectF& rect = item->boundingRect(); |
|
164 | 164 | qreal h = rect.height(); |
|
165 | 165 | size = size.expandedTo(rect.size()); |
|
166 | 166 | m_height+=h; |
|
167 | 167 | point.setY(point.y() + h); |
|
168 | 168 | } |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | if (m_height < geometry.height()) |
|
172 | 172 | m_legend->d_ptr->items()->setPos(geometry.left(), geometry.height() / 2 - m_height / 2); |
|
173 | 173 | else |
|
174 | 174 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
175 | 175 | m_width = size.width(); |
|
176 | 176 | break; |
|
177 | 177 | } |
|
178 | 178 | } |
|
179 | 179 | |
|
180 | 180 | m_minOffsetX = -left; |
|
181 | 181 | m_minOffsetY = - top; |
|
182 | 182 | m_maxOffsetX = m_width - geometry.width() - right; |
|
183 | 183 | m_maxOffsetY = m_height - geometry.height() - bottom; |
|
184 | 184 | } |
|
185 | 185 | |
|
186 | 186 | void LegendLayout::setDettachedGeometry(const QRectF &rect) |
|
187 | 187 | { |
|
188 | 188 | if (!rect.isValid()) |
|
189 | 189 | return; |
|
190 | 190 | |
|
191 | 191 | // Detached layout is different. |
|
192 | 192 | // In detached mode legend may have multiple rows and columns, so layout calculations |
|
193 | 193 | // differ a log from attached mode. |
|
194 | 194 | // Also the scrolling logic is bit different. |
|
195 | 195 | |
|
196 | 196 | m_offsetX = 0; |
|
197 | 197 | m_offsetY = 0; |
|
198 | 198 | |
|
199 | 199 | qreal left, top, right, bottom; |
|
200 | 200 | getContentsMargins(&left, &top, &right, &bottom); |
|
201 | 201 | QRectF geometry = rect.adjusted(left, top, -right, -bottom); |
|
202 | 202 | |
|
203 | 203 | QSizeF size(0, 0); |
|
204 | 204 | |
|
205 |
QList<QLegendMarker *> markers = m_legend->d_ptr-> |
|
|
205 | QList<QLegendMarker *> markers = m_legend->d_ptr->markers(); | |
|
206 | 206 | |
|
207 | 207 | if (markers.isEmpty()) |
|
208 | 208 | return; |
|
209 | 209 | |
|
210 | 210 | switch (m_legend->alignment()) { |
|
211 | 211 | case Qt::AlignTop: { |
|
212 | 212 | QPointF point(0, 0); |
|
213 | 213 | m_width = 0; |
|
214 | 214 | m_height = 0; |
|
215 | 215 | for (int i = 0; i < markers.count(); i++) { |
|
216 | 216 | LegendMarkerItem *item = markers.at(i)->d_ptr->item(); |
|
217 | 217 | if (item->isVisible()) { |
|
218 | 218 | item->setGeometry(geometry); |
|
219 | 219 | item->setPos(point.x(),point.y()); |
|
220 | 220 | const QRectF& boundingRect = item->boundingRect(); |
|
221 | 221 | qreal w = boundingRect.width(); |
|
222 | 222 | qreal h = boundingRect.height(); |
|
223 | 223 | m_width = qMax(m_width,w); |
|
224 | 224 | m_height = qMax(m_height,h); |
|
225 | 225 | point.setX(point.x() + w); |
|
226 | 226 | if (point.x() + w > geometry.left() + geometry.width() - right) { |
|
227 | 227 | // Next item would go off rect. |
|
228 | 228 | point.setX(0); |
|
229 | 229 | point.setY(point.y() + h); |
|
230 | 230 | if (i+1 < markers.count()) { |
|
231 | 231 | m_height += h; |
|
232 | 232 | } |
|
233 | 233 | } |
|
234 | 234 | } |
|
235 | 235 | } |
|
236 | 236 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
237 | 237 | |
|
238 | 238 | m_minOffsetX = -left; |
|
239 | 239 | m_minOffsetY = -top; |
|
240 | 240 | m_maxOffsetX = m_width - geometry.width() - right; |
|
241 | 241 | m_maxOffsetY = m_height - geometry.height() - bottom; |
|
242 | 242 | } |
|
243 | 243 | break; |
|
244 | 244 | case Qt::AlignBottom: { |
|
245 | 245 | QPointF point(0, geometry.height()); |
|
246 | 246 | m_width = 0; |
|
247 | 247 | m_height = 0; |
|
248 | 248 | for (int i = 0; i < markers.count(); i++) { |
|
249 | 249 | LegendMarkerItem *item = markers.at(i)->d_ptr->item(); |
|
250 | 250 | if (item->isVisible()) { |
|
251 | 251 | item->setGeometry(geometry); |
|
252 | 252 | const QRectF& boundingRect = item->boundingRect(); |
|
253 | 253 | qreal w = boundingRect.width(); |
|
254 | 254 | qreal h = boundingRect.height(); |
|
255 | 255 | m_width = qMax(m_width,w); |
|
256 | 256 | m_height = qMax(m_height,h); |
|
257 | 257 | item->setPos(point.x(),point.y() - h); |
|
258 | 258 | point.setX(point.x() + w); |
|
259 | 259 | if (point.x() + w > geometry.left() + geometry.width() - right) { |
|
260 | 260 | // Next item would go off rect. |
|
261 | 261 | point.setX(0); |
|
262 | 262 | point.setY(point.y() - h); |
|
263 | 263 | if (i+1 < markers.count()) { |
|
264 | 264 | m_height += h; |
|
265 | 265 | } |
|
266 | 266 | } |
|
267 | 267 | } |
|
268 | 268 | } |
|
269 | 269 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
270 | 270 | |
|
271 | 271 | m_minOffsetX = -left; |
|
272 | 272 | m_minOffsetY = -m_height + geometry.height() - top; |
|
273 | 273 | m_maxOffsetX = m_width - geometry.width() - right; |
|
274 | 274 | m_maxOffsetY = -bottom; |
|
275 | 275 | } |
|
276 | 276 | break; |
|
277 | 277 | case Qt::AlignLeft: { |
|
278 | 278 | QPointF point(0, 0); |
|
279 | 279 | m_width = 0; |
|
280 | 280 | m_height = 0; |
|
281 | 281 | qreal maxWidth = 0; |
|
282 | 282 | for (int i = 0; i < markers.count(); i++) { |
|
283 | 283 | LegendMarkerItem *item = markers.at(i)->d_ptr->item(); |
|
284 | 284 | if (item->isVisible()) { |
|
285 | 285 | item->setGeometry(geometry); |
|
286 | 286 | const QRectF& boundingRect = item->boundingRect(); |
|
287 | 287 | qreal w = boundingRect.width(); |
|
288 | 288 | qreal h = boundingRect.height(); |
|
289 | 289 | m_height = qMax(m_height,h); |
|
290 | 290 | maxWidth = qMax(maxWidth,w); |
|
291 | 291 | item->setPos(point.x(),point.y()); |
|
292 | 292 | point.setY(point.y() + h); |
|
293 | 293 | if (point.y() + h > geometry.bottom() - bottom) { |
|
294 | 294 | // Next item would go off rect. |
|
295 | 295 | point.setX(point.x() + maxWidth); |
|
296 | 296 | point.setY(0); |
|
297 | 297 | if (i+1 < markers.count()) { |
|
298 | 298 | m_width += maxWidth; |
|
299 | 299 | maxWidth = 0; |
|
300 | 300 | } |
|
301 | 301 | } |
|
302 | 302 | } |
|
303 | 303 | } |
|
304 | 304 | m_width += maxWidth; |
|
305 | 305 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
306 | 306 | |
|
307 | 307 | m_minOffsetX = -left; |
|
308 | 308 | m_minOffsetY = -top; |
|
309 | 309 | m_maxOffsetX = m_width - geometry.width() - right; |
|
310 | 310 | m_maxOffsetY = m_height - geometry.height() - bottom; |
|
311 | 311 | } |
|
312 | 312 | break; |
|
313 | 313 | case Qt::AlignRight: { |
|
314 | 314 | QPointF point(geometry.width(), 0); |
|
315 | 315 | m_width = 0; |
|
316 | 316 | m_height = 0; |
|
317 | 317 | qreal maxWidth = 0; |
|
318 | 318 | for (int i = 0; i < markers.count(); i++) { |
|
319 | 319 | LegendMarkerItem *item = markers.at(i)->d_ptr->item(); |
|
320 | 320 | if (item->isVisible()) { |
|
321 | 321 | item->setGeometry(geometry); |
|
322 | 322 | const QRectF& boundingRect = item->boundingRect(); |
|
323 | 323 | qreal w = boundingRect.width(); |
|
324 | 324 | qreal h = boundingRect.height(); |
|
325 | 325 | m_height = qMax(m_height,h); |
|
326 | 326 | maxWidth = qMax(maxWidth,w); |
|
327 | 327 | item->setPos(point.x() - w,point.y()); |
|
328 | 328 | point.setY(point.y() + h); |
|
329 | 329 | if (point.y() + h > geometry.bottom()-bottom) { |
|
330 | 330 | // Next item would go off rect. |
|
331 | 331 | point.setX(point.x() - maxWidth); |
|
332 | 332 | point.setY(0); |
|
333 | 333 | if (i+1 < markers.count()) { |
|
334 | 334 | m_width += maxWidth; |
|
335 | 335 | maxWidth = 0; |
|
336 | 336 | } |
|
337 | 337 | } |
|
338 | 338 | } |
|
339 | 339 | } |
|
340 | 340 | m_width += maxWidth; |
|
341 | 341 | m_legend->d_ptr->items()->setPos(geometry.topLeft()); |
|
342 | 342 | |
|
343 | 343 | m_minOffsetX = - m_width + geometry.width() - left; |
|
344 | 344 | m_minOffsetY = -top; |
|
345 | 345 | m_maxOffsetX = - right; |
|
346 | 346 | m_maxOffsetY = m_height - geometry.height() - bottom; |
|
347 | 347 | } |
|
348 | 348 | break; |
|
349 | 349 | default: |
|
350 | 350 | break; |
|
351 | 351 | } |
|
352 | 352 | |
|
353 | 353 | } |
|
354 | 354 | |
|
355 | 355 | QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const |
|
356 | 356 | { |
|
357 | 357 | QSizeF size(0, 0); |
|
358 | 358 | qreal left, top, right, bottom; |
|
359 | 359 | getContentsMargins(&left, &top, &right, &bottom); |
|
360 | 360 | |
|
361 | 361 | if(constraint.isValid()) { |
|
362 |
foreach(QLegendMarker* marker, m_legend->d_ptr-> |
|
|
362 | foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) { | |
|
363 | 363 | LegendMarkerItem *item = marker->d_ptr->item(); |
|
364 | 364 | size = size.expandedTo(item->effectiveSizeHint(which)); |
|
365 | 365 | } |
|
366 | 366 | size = size.boundedTo(constraint); |
|
367 | 367 | } |
|
368 | 368 | else if (constraint.width() >= 0) { |
|
369 | 369 | qreal width = 0; |
|
370 | 370 | qreal height = 0; |
|
371 |
foreach(QLegendMarker* marker, m_legend->d_ptr-> |
|
|
371 | foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) { | |
|
372 | 372 | LegendMarkerItem *item = marker->d_ptr->item(); |
|
373 | 373 | width+=item->effectiveSizeHint(which).width(); |
|
374 | 374 | height=qMax(height,item->effectiveSizeHint(which).height()); |
|
375 | 375 | } |
|
376 | 376 | |
|
377 | 377 | size = QSizeF(qMin(constraint.width(),width), height); |
|
378 | 378 | } |
|
379 | 379 | else if (constraint.height() >= 0) { |
|
380 | 380 | qreal width = 0; |
|
381 | 381 | qreal height = 0; |
|
382 |
foreach(QLegendMarker* marker, m_legend->d_ptr-> |
|
|
382 | foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) { | |
|
383 | 383 | LegendMarkerItem *item = marker->d_ptr->item(); |
|
384 | 384 | width=qMax(width,item->effectiveSizeHint(which).width()); |
|
385 | 385 | height+=height,item->effectiveSizeHint(which).height(); |
|
386 | 386 | } |
|
387 | 387 | size = QSizeF(width,qMin(constraint.height(),height)); |
|
388 | 388 | } |
|
389 | 389 | else { |
|
390 |
foreach(QLegendMarker* marker, m_legend->d_ptr-> |
|
|
390 | foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) { | |
|
391 | 391 | LegendMarkerItem *item = marker->d_ptr->item(); |
|
392 | 392 | size = size.expandedTo(item->effectiveSizeHint(which)); |
|
393 | 393 | } |
|
394 | 394 | } |
|
395 | 395 | size += QSize(left + right, top + bottom); |
|
396 | 396 | return size; |
|
397 | 397 | } |
|
398 | 398 | |
|
399 | 399 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,89 +1,87 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qarealegendmarker.h" |
|
22 | 22 | #include "qarealegendmarker_p.h" |
|
23 | 23 | #include "qareaseries_p.h" |
|
24 | 24 | #include <QAreaSeries> |
|
25 | 25 | #include <QDebug> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | QAreaLegendMarker::QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent) : |
|
30 | 30 | QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent) |
|
31 | 31 | { |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | 34 | QAreaLegendMarker::~QAreaLegendMarker() |
|
35 | 35 | { |
|
36 | 36 | // qDebug() << "deleting Area marker" << this; |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | /*! |
|
40 | 40 | \internal |
|
41 | 41 | */ |
|
42 | 42 | QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) : |
|
43 | 43 | QLegendMarker(d, parent) |
|
44 | 44 | { |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | 47 | QAreaSeries* QAreaLegendMarker::series() |
|
48 | 48 | { |
|
49 | 49 | Q_D(QAreaLegendMarker); |
|
50 | 50 | return d->m_series; |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 | 54 | |
|
55 | 55 | QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) : |
|
56 | 56 | QLegendMarkerPrivate(q,legend), |
|
57 | 57 | m_series(series) |
|
58 | 58 | { |
|
59 | 59 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
60 | 60 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
61 | 61 | updated(); |
|
62 | 62 | } |
|
63 | 63 | |
|
64 | 64 | QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate() |
|
65 | 65 | { |
|
66 | QObject::disconnect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
|
67 | QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
|
68 | 66 | } |
|
69 | 67 | |
|
70 | 68 | QAreaSeries* QAreaLegendMarkerPrivate::series() |
|
71 | 69 | { |
|
72 | 70 | return m_series; |
|
73 | 71 | } |
|
74 | 72 | |
|
75 | 73 | QObject* QAreaLegendMarkerPrivate::relatedObject() |
|
76 | 74 | { |
|
77 | 75 | return m_series; |
|
78 | 76 | } |
|
79 | 77 | |
|
80 | 78 | void QAreaLegendMarkerPrivate::updated() |
|
81 | 79 | { |
|
82 | 80 | m_item->setBrush(m_series->brush()); |
|
83 | 81 | m_item->setLabel(m_series->name()); |
|
84 | 82 | } |
|
85 | 83 | |
|
86 | 84 | #include "moc_qarealegendmarker.cpp" |
|
87 | 85 | #include "moc_qarealegendmarker_p.cpp" |
|
88 | 86 | |
|
89 | 87 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,100 +1,97 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarlegendmarker.h" |
|
22 | 22 | #include "qbarlegendmarker_p.h" |
|
23 | 23 | #include <QAbstractBarSeries> |
|
24 | 24 | #include <QBarSet> |
|
25 | 25 | #include <QDebug> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent) : |
|
30 | 30 | QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent) |
|
31 | 31 | { |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | 34 | QBarLegendMarker::~QBarLegendMarker() |
|
35 | 35 | { |
|
36 | 36 | // qDebug() << "deleting bar marker" << this; |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | /*! |
|
40 | 40 | \internal |
|
41 | 41 | */ |
|
42 | 42 | QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) : |
|
43 | 43 | QLegendMarker(d, parent) |
|
44 | 44 | { |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | 47 | QAbstractBarSeries *QBarLegendMarker::series() |
|
48 | 48 | { |
|
49 | 49 | Q_D(QBarLegendMarker); |
|
50 | 50 | return d->m_series; |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | QBarSet* QBarLegendMarker::barset() |
|
54 | 54 | { |
|
55 | 55 | Q_D(QBarLegendMarker); |
|
56 | 56 | return d->m_barset; |
|
57 | 57 | } |
|
58 | 58 | |
|
59 | 59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 | 60 | |
|
61 | 61 | QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) : |
|
62 | 62 | QLegendMarkerPrivate(q,legend), |
|
63 | 63 | m_series(series), |
|
64 | 64 | m_barset(barset) |
|
65 | 65 | { |
|
66 | 66 | QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); |
|
67 | 67 | QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
68 | 68 | QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
69 | 69 | updated(); |
|
70 | 70 | } |
|
71 | 71 | |
|
72 | 72 | QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate() |
|
73 | 73 | { |
|
74 | QObject::disconnect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); | |
|
75 | QObject::disconnect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); | |
|
76 | QObject::disconnect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); | |
|
77 | 74 | } |
|
78 | 75 | |
|
79 | 76 | QAbstractBarSeries* QBarLegendMarkerPrivate::series() |
|
80 | 77 | { |
|
81 | 78 | return m_series; |
|
82 | 79 | } |
|
83 | 80 | |
|
84 | 81 | QObject* QBarLegendMarkerPrivate::relatedObject() |
|
85 | 82 | { |
|
86 | 83 | return m_barset; |
|
87 | 84 | } |
|
88 | 85 | |
|
89 | 86 | void QBarLegendMarkerPrivate::updated() |
|
90 | 87 | { |
|
91 | 88 | m_item->setPen(m_barset->pen()); |
|
92 | 89 | m_item->setBrush(m_barset->brush()); |
|
93 | 90 | m_item->setLabel(m_barset->label()); |
|
94 | 91 | } |
|
95 | 92 | |
|
96 | 93 | #include "moc_qbarlegendmarker.cpp" |
|
97 | 94 | #include "moc_qbarlegendmarker_p.cpp" |
|
98 | 95 | |
|
99 | 96 | QTCOMMERCIALCHART_END_NAMESPACE |
|
100 | 97 |
@@ -1,70 +1,70 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef QBARLEGENDMARKER_P_H |
|
31 | 31 | #define QBARLEGENDMARKER_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qchartglobal.h" |
|
34 | 34 | #include "qlegendmarker_p.h" |
|
35 | 35 | #include "legendmarkeritem_p.h" |
|
36 | 36 | #include <QAbstractBarSeries> |
|
37 | 37 | #include <QBarSet> |
|
38 | 38 | |
|
39 | 39 | #include <QDebug> |
|
40 | 40 | |
|
41 | 41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
42 | 42 | |
|
43 | 43 | class QBarLegendMarker; |
|
44 | 44 | |
|
45 | 45 | class QBarLegendMarkerPrivate : public QLegendMarkerPrivate |
|
46 | 46 | { |
|
47 | 47 | Q_OBJECT |
|
48 | 48 | public: |
|
49 | 49 | explicit QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend); |
|
50 | 50 | virtual ~QBarLegendMarkerPrivate(); |
|
51 | 51 | |
|
52 | 52 | virtual QAbstractBarSeries* series(); |
|
53 | 53 | virtual QObject* relatedObject(); |
|
54 | 54 | |
|
55 | 55 | public Q_SLOTS: |
|
56 | 56 | virtual void updated(); |
|
57 | 57 | |
|
58 | 58 | private: |
|
59 | 59 | QBarLegendMarker *q_ptr; |
|
60 | 60 | |
|
61 | 61 | QAbstractBarSeries* m_series; |
|
62 | 62 | QBarSet* m_barset; |
|
63 | 63 | |
|
64 |
friend class QLegendPrivate; |
|
|
64 | friend class QLegendPrivate; | |
|
65 | 65 | Q_DECLARE_PUBLIC(QBarLegendMarker) |
|
66 | 66 | }; |
|
67 | 67 | |
|
68 | 68 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | 69 | |
|
70 | 70 | #endif // QBARLEGENDMARKER_P_H |
@@ -1,671 +1,669 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qlegend.h" |
|
22 | 22 | #include "qlegend_p.h" |
|
23 | 23 | #include "qabstractseries.h" |
|
24 | 24 | #include "qabstractseries_p.h" |
|
25 | 25 | #include "qchart_p.h" |
|
26 | 26 | #include "legendlayout_p.h" |
|
27 | 27 | #include "qxyseries.h" |
|
28 | 28 | #include "qlineseries.h" |
|
29 | 29 | #include "qareaseries.h" |
|
30 | 30 | #include "qscatterseries.h" |
|
31 | 31 | #include "qsplineseries.h" |
|
32 | 32 | #include "qabstractbarseries.h" |
|
33 | 33 | #include "qstackedbarseries.h" |
|
34 | 34 | #include "qpercentbarseries.h" |
|
35 | 35 | #include "qbarset.h" |
|
36 | 36 | #include "qpieseries.h" |
|
37 | 37 | #include "qpieseries_p.h" |
|
38 | 38 | #include "qpieslice.h" |
|
39 | 39 | #include "chartpresenter_p.h" |
|
40 | 40 | #include "chartlayout_p.h" |
|
41 | 41 | #include <QPainter> |
|
42 | 42 | #include <QPen> |
|
43 | 43 | #include <QTimer> |
|
44 | 44 | #include <QGraphicsSceneEvent> |
|
45 | 45 | #include <QGraphicsItemGroup> |
|
46 | 46 | |
|
47 | 47 | #include "qlegendmarker.h" |
|
48 | 48 | #include "qlegendmarker_p.h" |
|
49 | 49 | #include "legendmarkeritem_p.h" |
|
50 | 50 | |
|
51 | 51 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
52 | 52 | |
|
53 | 53 | /*! |
|
54 | 54 | \class QLegend |
|
55 | 55 | \brief Legend object |
|
56 | 56 | \mainclass |
|
57 | 57 | |
|
58 | 58 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
59 | 59 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
60 | 60 | handle the drawing manually. |
|
61 | 61 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
62 | 62 | |
|
63 | 63 | \image examples_percentbarchart_legend.png |
|
64 | 64 | |
|
65 | 65 | \sa QChart |
|
66 | 66 | */ |
|
67 | 67 | /*! |
|
68 | 68 | \qmlclass Legend QLegend |
|
69 | 69 | \brief Legend is part of QtCommercial Chart QML API. |
|
70 | 70 | |
|
71 | 71 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when |
|
72 | 72 | series have been changed. Legend is used via ChartView class. For example: |
|
73 | 73 | \code |
|
74 | 74 | ChartView { |
|
75 | 75 | legend.visible: true |
|
76 | 76 | legend.alignment: Qt.AlignBottom |
|
77 | 77 | // Add a few series... |
|
78 | 78 | } |
|
79 | 79 | \endcode |
|
80 | 80 | |
|
81 | 81 | \image examples_percentbarchart_legend.png |
|
82 | 82 | */ |
|
83 | 83 | |
|
84 | 84 | /*! |
|
85 | 85 | \property QLegend::alignment |
|
86 | 86 | \brief The alignment of the legend. |
|
87 | 87 | |
|
88 | 88 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
89 | 89 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
90 | 90 | */ |
|
91 | 91 | /*! |
|
92 | 92 | \qmlproperty Qt.Alignment Legend::alignment |
|
93 | 93 | \brief The alignment of the legend. |
|
94 | 94 | |
|
95 | 95 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
96 | 96 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
97 | 97 | */ |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | \property QLegend::backgroundVisible |
|
101 | 101 | Whether the legend background is visible or not. |
|
102 | 102 | */ |
|
103 | 103 | /*! |
|
104 | 104 | \qmlproperty bool Legend::backgroundVisible |
|
105 | 105 | Whether the legend background is visible or not. |
|
106 | 106 | */ |
|
107 | 107 | |
|
108 | 108 | /*! |
|
109 | 109 | \property QLegend::color |
|
110 | 110 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
111 | 111 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
112 | 112 | */ |
|
113 | 113 | /*! |
|
114 | 114 | \qmlproperty color Legend::color |
|
115 | 115 | The color of the legend, i.e. the background (brush) color. |
|
116 | 116 | */ |
|
117 | 117 | |
|
118 | 118 | /*! |
|
119 | 119 | \property QLegend::borderColor |
|
120 | 120 | The border color of the legend, i.e. the line color. |
|
121 | 121 | */ |
|
122 | 122 | /*! |
|
123 | 123 | \qmlproperty color Legend::borderColor |
|
124 | 124 | The border color of the legend, i.e. the line color. |
|
125 | 125 | */ |
|
126 | 126 | |
|
127 | 127 | /*! |
|
128 | 128 | \property QLegend::font |
|
129 | 129 | The font of markers used by legend |
|
130 | 130 | */ |
|
131 | 131 | /*! |
|
132 | 132 | \qmlproperty Font Legend::font |
|
133 | 133 | The font of markers used by legend |
|
134 | 134 | */ |
|
135 | 135 | |
|
136 | 136 | /*! |
|
137 | 137 | \property QLegend::labelColor |
|
138 | 138 | The color of brush used to draw labels. |
|
139 | 139 | */ |
|
140 | 140 | /*! |
|
141 | 141 | \qmlproperty color QLegend::labelColor |
|
142 | 142 | The color of brush used to draw labels. |
|
143 | 143 | */ |
|
144 | 144 | |
|
145 | 145 | /*! |
|
146 | 146 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
147 | 147 | The visibility of the legend background changed to \a visible. |
|
148 | 148 | */ |
|
149 | 149 | |
|
150 | 150 | /*! |
|
151 | 151 | \fn void QLegend::colorChanged(QColor) |
|
152 | 152 | The color of the legend background changed to \a color. |
|
153 | 153 | */ |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | \fn void QLegend::borderColorChanged(QColor) |
|
157 | 157 | The border color of the legend background changed to \a color. |
|
158 | 158 | */ |
|
159 | 159 | |
|
160 | 160 | /*! |
|
161 | 161 | \fn void QLegend::fontChanged(QFont) |
|
162 | 162 | The font of markers of the legend changed to \a font. |
|
163 | 163 | */ |
|
164 | 164 | |
|
165 | 165 | /*! |
|
166 | 166 | \fn void QLegend::labelColorChanged(QColor color) |
|
167 | 167 | This signal is emitted when the color of brush used to draw labels has changed to \a color. |
|
168 | 168 | */ |
|
169 | 169 | |
|
170 | 170 | /*! |
|
171 | 171 | Constructs the legend object and sets the parent to \a parent |
|
172 | 172 | */ |
|
173 | 173 | |
|
174 | 174 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), |
|
175 | 175 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) |
|
176 | 176 | { |
|
177 | 177 | setZValue(ChartPresenter::LegendZValue); |
|
178 | 178 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
179 | 179 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
180 | 180 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
181 | 181 | // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); |
|
182 | 182 | setLayout(d_ptr->m_layout); |
|
183 | 183 | } |
|
184 | 184 | |
|
185 | 185 | /*! |
|
186 | 186 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
187 | 187 | */ |
|
188 | 188 | QLegend::~QLegend() |
|
189 | 189 | { |
|
190 | 190 | } |
|
191 | 191 | |
|
192 | 192 | /*! |
|
193 | 193 | \internal |
|
194 | 194 | */ |
|
195 | 195 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
196 | 196 | { |
|
197 | 197 | Q_UNUSED(option) |
|
198 | 198 | Q_UNUSED(widget) |
|
199 | 199 | |
|
200 | 200 | if (!d_ptr->m_backgroundVisible) |
|
201 | 201 | return; |
|
202 | 202 | |
|
203 | 203 | painter->setOpacity(opacity()); |
|
204 | 204 | painter->setPen(d_ptr->m_pen); |
|
205 | 205 | painter->setBrush(d_ptr->m_brush); |
|
206 | 206 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); |
|
207 | 207 | } |
|
208 | 208 | |
|
209 | 209 | |
|
210 | 210 | /*! |
|
211 | 211 | Sets the \a brush of legend. Brush affects the background of legend. |
|
212 | 212 | */ |
|
213 | 213 | void QLegend::setBrush(const QBrush &brush) |
|
214 | 214 | { |
|
215 | 215 | if (d_ptr->m_brush != brush) { |
|
216 | 216 | d_ptr->m_brush = brush; |
|
217 | 217 | update(); |
|
218 | 218 | emit colorChanged(brush.color()); |
|
219 | 219 | } |
|
220 | 220 | } |
|
221 | 221 | |
|
222 | 222 | /*! |
|
223 | 223 | Returns the brush used by legend. |
|
224 | 224 | */ |
|
225 | 225 | QBrush QLegend::brush() const |
|
226 | 226 | { |
|
227 | 227 | return d_ptr->m_brush; |
|
228 | 228 | } |
|
229 | 229 | |
|
230 | 230 | void QLegend::setColor(QColor color) |
|
231 | 231 | { |
|
232 | 232 | QBrush b = d_ptr->m_brush; |
|
233 | 233 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
234 | 234 | b.setStyle(Qt::SolidPattern); |
|
235 | 235 | b.setColor(color); |
|
236 | 236 | setBrush(b); |
|
237 | 237 | } |
|
238 | 238 | } |
|
239 | 239 | |
|
240 | 240 | QColor QLegend::color() |
|
241 | 241 | { |
|
242 | 242 | return d_ptr->m_brush.color(); |
|
243 | 243 | } |
|
244 | 244 | |
|
245 | 245 | /*! |
|
246 | 246 | Sets the \a pen of legend. Pen affects the legend borders. |
|
247 | 247 | */ |
|
248 | 248 | void QLegend::setPen(const QPen &pen) |
|
249 | 249 | { |
|
250 | 250 | if (d_ptr->m_pen != pen) { |
|
251 | 251 | d_ptr->m_pen = pen; |
|
252 | 252 | update(); |
|
253 | 253 | emit borderColorChanged(pen.color()); |
|
254 | 254 | } |
|
255 | 255 | } |
|
256 | 256 | |
|
257 | 257 | /*! |
|
258 | 258 | Returns the pen used by legend |
|
259 | 259 | */ |
|
260 | 260 | |
|
261 | 261 | QPen QLegend::pen() const |
|
262 | 262 | { |
|
263 | 263 | return d_ptr->m_pen; |
|
264 | 264 | } |
|
265 | 265 | |
|
266 | 266 | void QLegend::setFont(const QFont &font) |
|
267 | 267 | { |
|
268 | 268 | if (d_ptr->m_font != font) |
|
269 | 269 | d_ptr->m_font = font; |
|
270 | 270 | |
|
271 |
foreach (QLegendMarker *marker, d_ptr-> |
|
|
271 | foreach (QLegendMarker *marker, d_ptr->markers()) { | |
|
272 | 272 | marker->setFont(d_ptr->m_font); |
|
273 | layout()->invalidate(); | |
|
274 | emit fontChanged(font); | |
|
275 | 273 | } |
|
274 | layout()->invalidate(); | |
|
275 | emit fontChanged(font); | |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | QFont QLegend::font() const |
|
279 | 279 | { |
|
280 | 280 | return d_ptr->m_font; |
|
281 | 281 | } |
|
282 | 282 | |
|
283 | 283 | void QLegend::setBorderColor(QColor color) |
|
284 | 284 | { |
|
285 | 285 | QPen p = d_ptr->m_pen; |
|
286 | 286 | if (p.color() != color) { |
|
287 | 287 | p.setColor(color); |
|
288 | 288 | setPen(p); |
|
289 | 289 | } |
|
290 | 290 | } |
|
291 | 291 | |
|
292 | 292 | QColor QLegend::borderColor() |
|
293 | 293 | { |
|
294 | 294 | return d_ptr->m_pen.color(); |
|
295 | 295 | } |
|
296 | 296 | |
|
297 | 297 | /*! |
|
298 | 298 | Set brush used to draw labels to \a brush. |
|
299 | 299 | */ |
|
300 | 300 | void QLegend::setLabelBrush(const QBrush &brush) |
|
301 | 301 | { |
|
302 | 302 | if (d_ptr->m_labelBrush != brush) { |
|
303 | 303 | d_ptr->m_labelBrush = brush; |
|
304 |
foreach (QLegendMarker *marker, d_ptr-> |
|
|
304 | foreach (QLegendMarker *marker, d_ptr->markers()) { | |
|
305 | 305 | marker->setLabelBrush(d_ptr->m_labelBrush); |
|
306 | 306 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API |
|
307 | 307 | // instead of mapping it from label brush color |
|
308 | 308 | marker->setPen(brush.color()); |
|
309 | 309 | } |
|
310 | 310 | emit labelColorChanged(brush.color()); |
|
311 | 311 | } |
|
312 | 312 | } |
|
313 | 313 | |
|
314 | 314 | /*! |
|
315 | 315 | Brush used to draw labels. |
|
316 | 316 | */ |
|
317 | 317 | QBrush QLegend::labelBrush() const |
|
318 | 318 | { |
|
319 | 319 | return d_ptr->m_labelBrush; |
|
320 | 320 | } |
|
321 | 321 | |
|
322 | 322 | void QLegend::setLabelColor(QColor color) |
|
323 | 323 | { |
|
324 | 324 | QBrush b = d_ptr->m_labelBrush; |
|
325 | 325 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
326 | 326 | b.setStyle(Qt::SolidPattern); |
|
327 | 327 | b.setColor(color); |
|
328 | 328 | setLabelBrush(b); |
|
329 | 329 | } |
|
330 | 330 | } |
|
331 | 331 | |
|
332 | 332 | QColor QLegend::labelColor() const |
|
333 | 333 | { |
|
334 | 334 | return d_ptr->m_labelBrush.color(); |
|
335 | 335 | } |
|
336 | 336 | |
|
337 | 337 | |
|
338 | 338 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
339 | 339 | { |
|
340 | 340 | if (d_ptr->m_alignment != alignment) { |
|
341 | 341 | d_ptr->m_alignment = alignment; |
|
342 | 342 | layout()->invalidate(); |
|
343 | 343 | } |
|
344 | 344 | } |
|
345 | 345 | |
|
346 | 346 | Qt::Alignment QLegend::alignment() const |
|
347 | 347 | { |
|
348 | 348 | return d_ptr->m_alignment; |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | /*! |
|
352 | 352 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
353 | 353 | */ |
|
354 | 354 | void QLegend::detachFromChart() |
|
355 | 355 | { |
|
356 | 356 | d_ptr->m_attachedToChart = false; |
|
357 | 357 | layout()->invalidate(); |
|
358 | 358 | setParent(0); |
|
359 | 359 | |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 362 | /*! |
|
363 | 363 | Attaches the legend to chart. Chart may change layout of the legend. |
|
364 | 364 | */ |
|
365 | 365 | void QLegend::attachToChart() |
|
366 | 366 | { |
|
367 | 367 | d_ptr->m_attachedToChart = true; |
|
368 | 368 | layout()->invalidate(); |
|
369 | 369 | setParent(d_ptr->m_chart); |
|
370 | 370 | } |
|
371 | 371 | |
|
372 | 372 | /*! |
|
373 | 373 | Returns true, if legend is attached to chart. |
|
374 | 374 | */ |
|
375 | 375 | bool QLegend::isAttachedToChart() |
|
376 | 376 | { |
|
377 | 377 | return d_ptr->m_attachedToChart; |
|
378 | 378 | } |
|
379 | 379 | |
|
380 | 380 | /*! |
|
381 | 381 | Sets the visibility of legend background to \a visible |
|
382 | 382 | */ |
|
383 | 383 | void QLegend::setBackgroundVisible(bool visible) |
|
384 | 384 | { |
|
385 | 385 | if (d_ptr->m_backgroundVisible != visible) { |
|
386 | 386 | d_ptr->m_backgroundVisible = visible; |
|
387 | 387 | update(); |
|
388 | 388 | emit backgroundVisibleChanged(visible); |
|
389 | 389 | } |
|
390 | 390 | } |
|
391 | 391 | |
|
392 | 392 | /*! |
|
393 | 393 | Returns the visibility of legend background |
|
394 | 394 | */ |
|
395 | 395 | bool QLegend::isBackgroundVisible() const |
|
396 | 396 | { |
|
397 | 397 | return d_ptr->m_backgroundVisible; |
|
398 | 398 | } |
|
399 | 399 | |
|
400 | ||
|
401 | 400 | QList<QLegendMarker*> QLegend::markers() const |
|
402 | 401 | { |
|
403 | // TODO: name of PIMPL method will change. | |
|
404 | return d_ptr->legendMarkers(); | |
|
402 | return d_ptr->markers(); | |
|
405 | 403 | } |
|
406 | 404 | |
|
407 |
void QLegend::a |
|
|
405 | void QLegend::addSeries(QAbstractSeries* series) | |
|
408 | 406 | { |
|
409 |
d_ptr->a |
|
|
407 | d_ptr->addSeries(series); | |
|
410 | 408 | } |
|
411 | 409 | |
|
412 | 410 | void QLegend::removeSeries(QAbstractSeries* series) |
|
413 | 411 | { |
|
414 | 412 | d_ptr->removeSeries(series); |
|
415 | 413 | } |
|
416 | 414 | |
|
417 | 415 | /*! |
|
418 | 416 | \internal \a event see QGraphicsWidget for details |
|
419 | 417 | */ |
|
420 | 418 | void QLegend::hideEvent(QHideEvent *event) |
|
421 | 419 | { |
|
422 | 420 | if (isAttachedToChart()) |
|
423 | 421 | d_ptr->m_presenter->layout()->invalidate(); |
|
424 | 422 | QGraphicsWidget::hideEvent(event); |
|
425 | 423 | } |
|
426 | 424 | /*! |
|
427 | 425 | \internal \a event see QGraphicsWidget for details |
|
428 | 426 | */ |
|
429 | 427 | void QLegend::showEvent(QShowEvent *event) |
|
430 | 428 | { |
|
431 | 429 | if (isAttachedToChart()) { |
|
432 | 430 | d_ptr->items()->setVisible(false); |
|
433 | 431 | layout()->invalidate(); |
|
434 | 432 | } |
|
435 | 433 | QGraphicsWidget::showEvent(event); |
|
436 | 434 | //layout activation will show the items |
|
437 | 435 | } |
|
438 | 436 | |
|
439 | 437 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
440 | 438 | |
|
441 | 439 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) |
|
442 | 440 | : q_ptr(q), |
|
443 | 441 | m_presenter(presenter), |
|
444 | 442 | m_layout(new LegendLayout(q)), |
|
445 | 443 | m_chart(chart), |
|
446 | 444 | m_items(new QGraphicsItemGroup(q)), |
|
447 | 445 | m_alignment(Qt::AlignTop), |
|
448 | 446 | m_brush(QBrush()), |
|
449 | 447 | m_pen(QPen()), |
|
450 | 448 | m_labelBrush(QBrush()), |
|
451 | 449 | m_diameter(5), |
|
452 | 450 | m_attachedToChart(true), |
|
453 | 451 | m_backgroundVisible(false) |
|
454 | 452 | { |
|
455 | 453 | m_items->setHandlesChildEvents(false); |
|
456 | 454 | } |
|
457 | 455 | |
|
458 | 456 | QLegendPrivate::~QLegendPrivate() |
|
459 | 457 | { |
|
460 | 458 | |
|
461 | 459 | } |
|
462 | 460 | |
|
463 | 461 | void QLegendPrivate::setOffset(qreal x, qreal y) |
|
464 | 462 | { |
|
465 | 463 | m_layout->setOffset(x, y); |
|
466 | 464 | } |
|
467 | 465 | |
|
468 | 466 | QPointF QLegendPrivate::offset() const |
|
469 | 467 | { |
|
470 | 468 | return m_layout->offset(); |
|
471 | 469 | } |
|
472 | 470 | |
|
473 | 471 | int QLegendPrivate::roundness(qreal size) |
|
474 | 472 | { |
|
475 | 473 | return 100 * m_diameter / int(size); |
|
476 | 474 | } |
|
477 | 475 | |
|
478 |
void QLegendPrivate::a |
|
|
476 | void QLegendPrivate::addSeries(QAbstractSeries* series) | |
|
479 | 477 | { |
|
480 | 478 | // Only allow one instance of series |
|
481 | 479 | if (m_series.contains(series)) { |
|
482 | 480 | qDebug() << "series already added" << series; |
|
483 | 481 | return; |
|
484 | 482 | } |
|
485 | 483 | |
|
486 | 484 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); |
|
487 | 485 | decorateMarkers(newMarkers); |
|
488 | 486 | addMarkers(newMarkers); |
|
489 | 487 | |
|
490 | 488 | // TODO: This is the part I don't like. There should be better solution. |
|
491 | 489 | // On the other hand. It is only one switch case for appending and another for removing series |
|
492 | 490 | // If countChanged signal were on QAbstractSeries, there would be no need for switch at all. |
|
493 | 491 | switch (series->type()) |
|
494 | 492 | { |
|
495 | 493 | case QAbstractSeries::SeriesTypePie: { |
|
496 | 494 | QPieSeries *s = qobject_cast<QPieSeries *> (series); |
|
497 | 495 | QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
498 | 496 | break; |
|
499 | 497 | } |
|
500 | 498 | case QAbstractSeries::SeriesTypeBar: |
|
501 | 499 | case QAbstractSeries::SeriesTypeStackedBar: |
|
502 | 500 | case QAbstractSeries::SeriesTypePercentBar: |
|
503 | 501 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
504 | 502 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
505 | 503 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: { |
|
506 | 504 | QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series); |
|
507 | 505 | QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
508 | 506 | break; |
|
509 | 507 | } |
|
510 | 508 | case QAbstractSeries::SeriesTypeLine: |
|
511 | 509 | case QAbstractSeries::SeriesTypeArea: |
|
512 | 510 | case QAbstractSeries::SeriesTypeScatter: |
|
513 | 511 | case QAbstractSeries::SeriesTypeSpline: |
|
514 | 512 | default: { |
|
515 | 513 | // No need to connect any series related signals. We have no series level |
|
516 | 514 | // changes, that would generate or delete markers |
|
517 | 515 | } |
|
518 | 516 | } |
|
519 | 517 | |
|
520 | 518 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
521 | 519 | |
|
522 | 520 | m_series.append(series); |
|
523 | 521 | m_items->setVisible(false); |
|
524 | 522 | m_layout->invalidate(); |
|
525 | 523 | } |
|
526 | 524 | |
|
527 | 525 | void QLegendPrivate::removeSeries(QAbstractSeries* series) |
|
528 | 526 | { |
|
529 | 527 | if (m_series.contains(series)) { |
|
530 | 528 | m_series.removeOne(series); |
|
531 | 529 | } |
|
532 | 530 | |
|
533 | 531 | // Find out, which markers to remove |
|
534 | 532 | QList<QLegendMarker *> removed; |
|
535 |
foreach (QLegendMarker *m, m_ |
|
|
533 | foreach (QLegendMarker *m, m_markers) { | |
|
536 | 534 | if (m->series() == series) { |
|
537 | 535 | removed << m; |
|
538 | 536 | } |
|
539 | 537 | } |
|
540 | 538 | removeMarkers(removed); |
|
541 | 539 | |
|
542 | 540 | switch (series->type()) |
|
543 | 541 | { |
|
544 | 542 | case QAbstractSeries::SeriesTypePie: { |
|
545 | 543 | QPieSeries *s = qobject_cast<QPieSeries *> (series); |
|
546 | 544 | QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
547 | 545 | break; |
|
548 | 546 | } |
|
549 | 547 | case QAbstractSeries::SeriesTypeBar: |
|
550 | 548 | case QAbstractSeries::SeriesTypeStackedBar: |
|
551 | 549 | case QAbstractSeries::SeriesTypePercentBar: |
|
552 | 550 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
553 | 551 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
554 | 552 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: { |
|
555 | 553 | QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series); |
|
556 | 554 | QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
557 | 555 | break; |
|
558 | 556 | } |
|
559 | 557 | // TODO: |
|
560 | 558 | case QAbstractSeries::SeriesTypeLine: |
|
561 | 559 | case QAbstractSeries::SeriesTypeArea: |
|
562 | 560 | case QAbstractSeries::SeriesTypeScatter: |
|
563 | 561 | case QAbstractSeries::SeriesTypeSpline: |
|
564 | 562 | default: { |
|
565 | 563 | // No need to disconnect any series related signals |
|
566 | 564 | break; |
|
567 | 565 | } |
|
568 | 566 | } |
|
569 | 567 | |
|
570 | 568 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
571 | 569 | |
|
572 | 570 | m_layout->invalidate(); |
|
573 | 571 | // q_ptr->layout()->activate(); |
|
574 | 572 | } |
|
575 | 573 | |
|
576 | 574 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) |
|
577 | 575 | { |
|
578 | 576 | // Moved to appendSeries |
|
579 | 577 | // This slot is just to make old code work for now. |
|
580 |
a |
|
|
578 | addSeries(series); | |
|
581 | 579 | } |
|
582 | 580 | |
|
583 | 581 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
584 | 582 | { |
|
585 | 583 | // Moved to removeSeries |
|
586 | 584 | // This slot is just to make old code work for now. |
|
587 | 585 | removeSeries(series); |
|
588 | 586 | } |
|
589 | 587 | |
|
590 | 588 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
591 | 589 | { |
|
592 | 590 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
593 | 591 | Q_ASSERT(series); |
|
594 | 592 | |
|
595 |
foreach (QLegendMarker* marker, m_ |
|
|
593 | foreach (QLegendMarker* marker, m_markers) { | |
|
596 | 594 | if (marker->series() == series) { |
|
597 | 595 | marker->setVisible(series->isVisible()); |
|
598 | 596 | } |
|
599 | 597 | } |
|
600 | 598 | m_layout->invalidate(); |
|
601 | 599 | } |
|
602 | 600 | |
|
603 | 601 | void QLegendPrivate::handleCountChanged() |
|
604 | 602 | { |
|
605 | 603 | // Here we handle the changes in marker count. |
|
606 | 604 | // Can happen for example when pieslice(s) have been added to or removed from pieseries. |
|
607 | 605 | |
|
608 | 606 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
609 | 607 | QList<QLegendMarker *> createdMarkers = series->d_ptr->createLegendMarkers(q_ptr); |
|
610 | 608 | |
|
611 | 609 | // Find out removed markers and created markers |
|
612 | 610 | QList<QLegendMarker *> removedMarkers; |
|
613 |
foreach (QLegendMarker *oldMarker, m_ |
|
|
611 | foreach (QLegendMarker *oldMarker, m_markers) { | |
|
614 | 612 | // we have marker, which is related to sender. |
|
615 | 613 | if (oldMarker->series() == series) { |
|
616 | 614 | bool found = false; |
|
617 | 615 | foreach(QLegendMarker *newMarker, createdMarkers) { |
|
618 | 616 | // New marker considered existing if: |
|
619 | 617 | // - d_ptr->relatedObject() is same for both markers. |
|
620 | 618 | if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) { |
|
621 | 619 | // Delete the new marker, since we already have existing marker, that might be connected on user side. |
|
622 | 620 | found = true; |
|
623 | 621 | createdMarkers.removeOne(newMarker); |
|
624 | 622 | delete newMarker; |
|
625 | 623 | } |
|
626 | 624 | } |
|
627 | 625 | if (!found) { |
|
628 | 626 | // No related object found for marker, add to removedMarkers list |
|
629 | 627 | removedMarkers << oldMarker; |
|
630 | 628 | } |
|
631 | 629 | } |
|
632 | 630 | } |
|
633 | 631 | |
|
634 | 632 | removeMarkers(removedMarkers); |
|
635 | 633 | decorateMarkers(createdMarkers); |
|
636 | 634 | addMarkers(createdMarkers); |
|
637 | 635 | |
|
638 | 636 | q_ptr->layout()->invalidate(); |
|
639 | 637 | } |
|
640 | 638 | |
|
641 | 639 | void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers) |
|
642 | 640 | { |
|
643 | 641 | foreach (QLegendMarker* marker, markers) { |
|
644 | 642 | m_items->addToGroup(marker->d_ptr.data()->item()); |
|
645 |
m_ |
|
|
643 | m_markers << marker; | |
|
646 | 644 | } |
|
647 | 645 | } |
|
648 | 646 | |
|
649 | 647 | void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers) |
|
650 | 648 | { |
|
651 | 649 | foreach (QLegendMarker *marker, markers) { |
|
652 | 650 | marker->d_ptr->item()->setVisible(false); |
|
653 | 651 | m_items->removeFromGroup(marker->d_ptr->item()); |
|
654 | 652 | delete marker; |
|
655 |
m_ |
|
|
653 | m_markers.removeOne(marker); | |
|
656 | 654 | } |
|
657 | 655 | } |
|
658 | 656 | |
|
659 | 657 | void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers) |
|
660 | 658 | { |
|
661 | 659 | foreach (QLegendMarker* marker, markers) { |
|
662 | 660 | marker->setFont(m_font); |
|
663 | 661 | marker->setLabelBrush(m_labelBrush); |
|
664 | 662 | } |
|
665 | 663 | } |
|
666 | 664 | |
|
667 | 665 | |
|
668 | 666 | #include "moc_qlegend.cpp" |
|
669 | 667 | #include "moc_qlegend_p.cpp" |
|
670 | 668 | |
|
671 | 669 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,109 +1,109 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef QLEGEND_H |
|
22 | 22 | #define QLEGEND_H |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <QGraphicsWidget> |
|
26 | 26 | #include <QPen> |
|
27 | 27 | #include <QBrush> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class QChart; |
|
32 | 32 | class QLegendPrivate; |
|
33 | 33 | class QLegendMarker; |
|
34 | 34 | class QAbstractSeries; |
|
35 | 35 | |
|
36 | 36 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget |
|
37 | 37 | { |
|
38 | 38 | Q_OBJECT |
|
39 | 39 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) |
|
40 | 40 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) |
|
41 | 41 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
42 | 42 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
43 | 43 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) |
|
44 | 44 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) |
|
45 | 45 | |
|
46 | 46 | private: |
|
47 | 47 | explicit QLegend(QChart *chart); |
|
48 | 48 | |
|
49 | 49 | public: |
|
50 | 50 | ~QLegend(); |
|
51 | 51 | |
|
52 | 52 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
53 | 53 | |
|
54 | 54 | void setBrush(const QBrush &brush); |
|
55 | 55 | QBrush brush() const; |
|
56 | 56 | void setColor(QColor color); |
|
57 | 57 | QColor color(); |
|
58 | 58 | |
|
59 | 59 | void setPen(const QPen &pen); |
|
60 | 60 | QPen pen() const; |
|
61 | 61 | void setBorderColor(QColor color); |
|
62 | 62 | QColor borderColor(); |
|
63 | 63 | |
|
64 | 64 | void setFont(const QFont &font); |
|
65 | 65 | QFont font() const; |
|
66 | 66 | void setLabelBrush(const QBrush &brush); |
|
67 | 67 | QBrush labelBrush() const; |
|
68 | 68 | |
|
69 | 69 | void setLabelColor(QColor color); |
|
70 | 70 | QColor labelColor() const; |
|
71 | 71 | |
|
72 | 72 | void setAlignment(Qt::Alignment alignment); |
|
73 | 73 | Qt::Alignment alignment() const; |
|
74 | 74 | |
|
75 | 75 | void detachFromChart(); |
|
76 | 76 | void attachToChart(); |
|
77 | 77 | bool isAttachedToChart(); |
|
78 | 78 | |
|
79 | 79 | void setBackgroundVisible(bool visible = true); |
|
80 | 80 | bool isBackgroundVisible() const; |
|
81 | 81 | |
|
82 | 82 | // New stuff: |
|
83 | 83 | QList <QLegendMarker*> markers() const; |
|
84 |
void a |
|
|
84 | void addSeries(QAbstractSeries* series); | |
|
85 | 85 | void removeSeries(QAbstractSeries* series); |
|
86 | 86 | |
|
87 | 87 | protected: |
|
88 | 88 | void hideEvent(QHideEvent *event); |
|
89 | 89 | void showEvent(QShowEvent *event); |
|
90 | 90 | |
|
91 | 91 | Q_SIGNALS: |
|
92 | 92 | void backgroundVisibleChanged(bool visible); |
|
93 | 93 | void colorChanged(QColor color); |
|
94 | 94 | void borderColorChanged(QColor color); |
|
95 | 95 | void fontChanged(QFont font); |
|
96 | 96 | void labelColorChanged(QColor color); |
|
97 | 97 | |
|
98 | 98 | private: |
|
99 | 99 | QScopedPointer<QLegendPrivate> d_ptr; |
|
100 | 100 | Q_DISABLE_COPY(QLegend) |
|
101 | 101 | friend class LegendScroller; |
|
102 | 102 | friend class LegendLayout; |
|
103 | 103 | friend class ChartLayout; |
|
104 | 104 | friend class LegendMarkerItem; |
|
105 | 105 | }; |
|
106 | 106 | |
|
107 | 107 | QTCOMMERCIALCHART_END_NAMESPACE |
|
108 | 108 | |
|
109 | 109 | #endif // QLEGEND_H |
@@ -1,101 +1,101 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef QLEGEND_P_H |
|
31 | 31 | #define QLEGEND_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qlegend.h" |
|
34 | 34 | |
|
35 | 35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | 36 | |
|
37 | 37 | class QChart; |
|
38 | 38 | class ChartPresenter; |
|
39 | 39 | class QAbstractSeries; |
|
40 | 40 | class LegendLayout; |
|
41 | 41 | class Domain; |
|
42 | 42 | class QLegendMarker; |
|
43 | 43 | |
|
44 | 44 | class QLegendPrivate : public QObject |
|
45 | 45 | { |
|
46 | 46 | Q_OBJECT |
|
47 | 47 | public: |
|
48 | 48 | QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q); |
|
49 | 49 | ~QLegendPrivate(); |
|
50 | 50 | |
|
51 | 51 | void setOffset(qreal x, qreal y); |
|
52 | 52 | QPointF offset() const; |
|
53 | 53 | int roundness(qreal size); |
|
54 | 54 | |
|
55 | 55 | QGraphicsItemGroup* items() { return m_items; } |
|
56 | 56 | |
|
57 | 57 | // New stuff: |
|
58 |
QList<QLegendMarker*> |
|
|
59 |
void a |
|
|
58 | QList<QLegendMarker*> markers() { return m_markers; } | |
|
59 | void addSeries(QAbstractSeries* series); | |
|
60 | 60 | void removeSeries(QAbstractSeries* series); |
|
61 | 61 | |
|
62 | 62 | public Q_SLOTS: |
|
63 | 63 | void handleSeriesAdded(QAbstractSeries *series); |
|
64 | 64 | void handleSeriesRemoved(QAbstractSeries *series); |
|
65 | 65 | void handleSeriesVisibleChanged(); |
|
66 | 66 | void handleCountChanged(); |
|
67 | 67 | |
|
68 | 68 | private: |
|
69 | 69 | // Internal helpers |
|
70 | 70 | void addMarkers(QList<QLegendMarker *> markers); |
|
71 | 71 | void removeMarkers(QList<QLegendMarker *> markers); |
|
72 | 72 | void decorateMarkers(QList<QLegendMarker *> markers); |
|
73 | 73 | |
|
74 | 74 | private: |
|
75 | 75 | QLegend *q_ptr; |
|
76 | 76 | ChartPresenter *m_presenter; |
|
77 | 77 | LegendLayout *m_layout; |
|
78 | 78 | QChart* m_chart; |
|
79 | 79 | QGraphicsItemGroup* m_items; |
|
80 | 80 | Qt::Alignment m_alignment; |
|
81 | 81 | QBrush m_brush; |
|
82 | 82 | QPen m_pen; |
|
83 | 83 | QFont m_font; |
|
84 | 84 | QBrush m_labelBrush; |
|
85 | 85 | |
|
86 | 86 | qreal m_diameter; |
|
87 | 87 | bool m_attachedToChart; |
|
88 | 88 | bool m_backgroundVisible; |
|
89 | 89 | |
|
90 | 90 | friend class QLegend; |
|
91 | 91 | friend class LegendLayout; |
|
92 | QList<QLegendMarker*> m_legendMarkers; // TODO: rename to m_markers eventually. | |
|
92 | QList<QLegendMarker*> m_markers; | |
|
93 | 93 | QList<QAbstractSeries*> m_series; |
|
94 | 94 | |
|
95 | 95 | friend class QLegend; |
|
96 | 96 | friend class LegendMarkerItem; |
|
97 | 97 | }; |
|
98 | 98 | |
|
99 | 99 | QTCOMMERCIALCHART_END_NAMESPACE |
|
100 | 100 | |
|
101 | 101 | #endif |
@@ -1,99 +1,96 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qpielegendmarker.h" |
|
22 | 22 | #include "qpielegendmarker_p.h" |
|
23 | 23 | #include <QPieSeries> |
|
24 | 24 | #include <QPieSlice> |
|
25 | 25 | #include <QDebug> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent) : |
|
30 | 30 | QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent) |
|
31 | 31 | { |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | 34 | QPieLegendMarker::~QPieLegendMarker() |
|
35 | 35 | { |
|
36 | 36 | // qDebug() << "deleting pie marker" << this; |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | /*! |
|
40 | 40 | \internal |
|
41 | 41 | */ |
|
42 | 42 | QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) : |
|
43 | 43 | QLegendMarker(d, parent) |
|
44 | 44 | { |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | 47 | QPieSeries* QPieLegendMarker::series() |
|
48 | 48 | { |
|
49 | 49 | Q_D(QPieLegendMarker); |
|
50 | 50 | return d->m_series; |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | QPieSlice* QPieLegendMarker::slice() |
|
54 | 54 | { |
|
55 | 55 | Q_D(QPieLegendMarker); |
|
56 | 56 | return d->m_slice; |
|
57 | 57 | } |
|
58 | 58 | |
|
59 | 59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 | 60 | |
|
61 | 61 | QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) : |
|
62 | 62 | QLegendMarkerPrivate(q,legend), |
|
63 | 63 | m_series(series), |
|
64 | 64 | m_slice(slice) |
|
65 | 65 | { |
|
66 | 66 | QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
67 | 67 | QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
68 | 68 | QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); |
|
69 | 69 | updated(); |
|
70 | 70 | } |
|
71 | 71 | |
|
72 | 72 | QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate() |
|
73 | 73 | { |
|
74 | QObject::disconnect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); | |
|
75 | QObject::disconnect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); | |
|
76 | QObject::disconnect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); | |
|
77 | 74 | } |
|
78 | 75 | |
|
79 | 76 | QPieSeries* QPieLegendMarkerPrivate::series() |
|
80 | 77 | { |
|
81 | 78 | return m_series; |
|
82 | 79 | } |
|
83 | 80 | |
|
84 | 81 | QObject* QPieLegendMarkerPrivate::relatedObject() |
|
85 | 82 | { |
|
86 | 83 | return m_slice; |
|
87 | 84 | } |
|
88 | 85 | |
|
89 | 86 | void QPieLegendMarkerPrivate::updated() |
|
90 | 87 | { |
|
91 | 88 | m_item->setPen(m_slice->pen()); |
|
92 | 89 | m_item->setBrush(m_slice->brush()); |
|
93 | 90 | m_item->setLabel(m_slice->label()); |
|
94 | 91 | } |
|
95 | 92 | |
|
96 | 93 | #include "moc_qpielegendmarker.cpp" |
|
97 | 94 | #include "moc_qpielegendmarker_p.cpp" |
|
98 | 95 | |
|
99 | 96 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,95 +1,93 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qxylegendmarker.h" |
|
22 | 22 | #include "qxylegendmarker_p.h" |
|
23 | 23 | #include "qxyseries_p.h" |
|
24 | 24 | #include <QXYSeries> |
|
25 | 25 | #include <QDebug> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | QXYLegendMarker::QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent) : |
|
30 | 30 | QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent) |
|
31 | 31 | { |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | 34 | QXYLegendMarker::~QXYLegendMarker() |
|
35 | 35 | { |
|
36 | 36 | // qDebug() << "deleting xy marker" << this; |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | /*! |
|
40 | 40 | \internal |
|
41 | 41 | */ |
|
42 | 42 | QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) : |
|
43 | 43 | QLegendMarker(d, parent) |
|
44 | 44 | { |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | 47 | QXYSeries* QXYLegendMarker::series() |
|
48 | 48 | { |
|
49 | 49 | Q_D(QXYLegendMarker); |
|
50 | 50 | return d->m_series; |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 | 54 | |
|
55 | 55 | QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) : |
|
56 | 56 | QLegendMarkerPrivate(q,legend), |
|
57 | 57 | m_series(series) |
|
58 | 58 | { |
|
59 | 59 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
60 | 60 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); |
|
61 | 61 | updated(); |
|
62 | 62 | } |
|
63 | 63 | |
|
64 | 64 | QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate() |
|
65 | 65 | { |
|
66 | QObject::disconnect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); | |
|
67 | QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
|
68 | 66 | } |
|
69 | 67 | |
|
70 | 68 | QAbstractSeries* QXYLegendMarkerPrivate::series() |
|
71 | 69 | { |
|
72 | 70 | return m_series; |
|
73 | 71 | } |
|
74 | 72 | |
|
75 | 73 | QObject* QXYLegendMarkerPrivate::relatedObject() |
|
76 | 74 | { |
|
77 | 75 | return m_series; |
|
78 | 76 | } |
|
79 | 77 | |
|
80 | 78 | void QXYLegendMarkerPrivate::updated() |
|
81 | 79 | { |
|
82 | 80 | m_item->setLabel(m_series->name()); |
|
83 | 81 | |
|
84 | 82 | if (m_series->type()== QAbstractSeries::SeriesTypeScatter) { |
|
85 | 83 | m_item->setBrush(m_series->brush()); |
|
86 | 84 | } else { |
|
87 | 85 | m_item->setBrush(QBrush(m_series->pen().color())); |
|
88 | 86 | } |
|
89 | 87 | } |
|
90 | 88 | |
|
91 | 89 | #include "moc_qxylegendmarker.cpp" |
|
92 | 90 | #include "moc_qxylegendmarker_p.cpp" |
|
93 | 91 | |
|
94 | 92 | QTCOMMERCIALCHART_END_NAMESPACE |
|
95 | 93 |
General Comments 0
You need to be logged in to leave comments.
Login now