##// END OF EJS Templates
optional series parameter to markers function. code style fixes
sauimone -
r2193:7e0a20ef8117
parent child
Show More
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
@@ -1,610 +1,612
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qlegend.h"
21 #include "qlegend.h"
22 #include "qlegend_p.h"
22 #include "qlegend_p.h"
23 #include "qabstractseries.h"
23 #include "qabstractseries.h"
24 #include "qabstractseries_p.h"
24 #include "qabstractseries_p.h"
25 #include "qchart_p.h"
25 #include "qchart_p.h"
26 #include "legendlayout_p.h"
26 #include "legendlayout_p.h"
27 #include "qxyseries.h"
28 #include "qlineseries.h"
29 #include "qareaseries.h"
30 #include "qscatterseries.h"
31 #include "qsplineseries.h"
32 #include "qabstractbarseries.h"
33 #include "qstackedbarseries.h"
34 #include "qpercentbarseries.h"
35 #include "qbarset.h"
36 #include "qpieseries.h"
37 #include "qpieseries_p.h"
38 #include "qpieslice.h"
39 #include "chartpresenter_p.h"
27 #include "chartpresenter_p.h"
40 #include "chartlayout_p.h"
28 #include "chartlayout_p.h"
41 #include <QPainter>
42 #include <QPen>
43 #include <QTimer>
44 #include <QGraphicsSceneEvent>
45 #include <QGraphicsItemGroup>
46
47 #include "qlegendmarker.h"
29 #include "qlegendmarker.h"
48 #include "qlegendmarker_p.h"
30 #include "qlegendmarker_p.h"
49 #include "legendmarkeritem_p.h"
31 #include "legendmarkeritem_p.h"
32 #include <QPainter>
33 #include <QPen>
34 #include <QGraphicsItemGroup>
50
35
51 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
52
37
53 /*!
38 /*!
54 \class QLegend
39 \class QLegend
55 \brief Legend object
40 \brief Legend object
56 \mainclass
41 \mainclass
57
42
58 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
43 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
59 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
44 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
60 handle the drawing manually.
45 handle the drawing manually.
61 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
46 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
62
47
63 \image examples_percentbarchart_legend.png
48 \image examples_percentbarchart_legend.png
64
49
65 \sa QChart
50 \sa QChart
66 */
51 */
67 /*!
52 /*!
68 \qmlclass Legend QLegend
53 \qmlclass Legend QLegend
69 \brief Legend is part of QtCommercial Chart QML API.
54 \brief Legend is part of QtCommercial Chart QML API.
70
55
71 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
56 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
72 series have been changed. Legend is used via ChartView class. For example:
57 series have been changed. Legend is used via ChartView class. For example:
73 \code
58 \code
74 ChartView {
59 ChartView {
75 legend.visible: true
60 legend.visible: true
76 legend.alignment: Qt.AlignBottom
61 legend.alignment: Qt.AlignBottom
77 // Add a few series...
62 // Add a few series...
78 }
63 }
79 \endcode
64 \endcode
80
65
81 \image examples_percentbarchart_legend.png
66 \image examples_percentbarchart_legend.png
82 */
67 */
83
68
84 /*!
69 /*!
85 \property QLegend::alignment
70 \property QLegend::alignment
86 \brief The alignment of the legend.
71 \brief The alignment of the legend.
87
72
88 Legend paints on the defined position in the chart. The following alignments are supported:
73 Legend paints on the defined position in the chart. The following alignments are supported:
89 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
74 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
90 */
75 */
91 /*!
76 /*!
92 \qmlproperty Qt.Alignment Legend::alignment
77 \qmlproperty Qt.Alignment Legend::alignment
93 \brief The alignment of the legend.
78 \brief The alignment of the legend.
94
79
95 Legend paints on the defined position in the chart. The following alignments are supported:
80 Legend paints on the defined position in the chart. The following alignments are supported:
96 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
81 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
97 */
82 */
98
83
99 /*!
84 /*!
100 \property QLegend::backgroundVisible
85 \property QLegend::backgroundVisible
101 Whether the legend background is visible or not.
86 Whether the legend background is visible or not.
102 */
87 */
103 /*!
88 /*!
104 \qmlproperty bool Legend::backgroundVisible
89 \qmlproperty bool Legend::backgroundVisible
105 Whether the legend background is visible or not.
90 Whether the legend background is visible or not.
106 */
91 */
107
92
108 /*!
93 /*!
109 \property QLegend::color
94 \property QLegend::color
110 The color of the legend, i.e. the background (brush) color. Note that if you change the color
95 The color of the legend, i.e. the background (brush) color. Note that if you change the color
111 of the legend, the style of the legend brush is set to Qt::SolidPattern.
96 of the legend, the style of the legend brush is set to Qt::SolidPattern.
112 */
97 */
113 /*!
98 /*!
114 \qmlproperty color Legend::color
99 \qmlproperty color Legend::color
115 The color of the legend, i.e. the background (brush) color.
100 The color of the legend, i.e. the background (brush) color.
116 */
101 */
117
102
118 /*!
103 /*!
119 \property QLegend::borderColor
104 \property QLegend::borderColor
120 The border color of the legend, i.e. the line color.
105 The border color of the legend, i.e. the line color.
121 */
106 */
122 /*!
107 /*!
123 \qmlproperty color Legend::borderColor
108 \qmlproperty color Legend::borderColor
124 The border color of the legend, i.e. the line color.
109 The border color of the legend, i.e. the line color.
125 */
110 */
126
111
127 /*!
112 /*!
128 \property QLegend::font
113 \property QLegend::font
129 The font of markers used by legend
114 The font of markers used by legend
130 */
115 */
131 /*!
116 /*!
132 \qmlproperty Font Legend::font
117 \qmlproperty Font Legend::font
133 The font of markers used by legend
118 The font of markers used by legend
134 */
119 */
135
120
136 /*!
121 /*!
137 \property QLegend::labelColor
122 \property QLegend::labelColor
138 The color of brush used to draw labels.
123 The color of brush used to draw labels.
139 */
124 */
140 /*!
125 /*!
141 \qmlproperty color QLegend::labelColor
126 \qmlproperty color QLegend::labelColor
142 The color of brush used to draw labels.
127 The color of brush used to draw labels.
143 */
128 */
144
129
145 /*!
130 /*!
146 \fn void QLegend::backgroundVisibleChanged(bool)
131 \fn void QLegend::backgroundVisibleChanged(bool)
147 The visibility of the legend background changed to \a visible.
132 The visibility of the legend background changed to \a visible.
148 */
133 */
149
134
150 /*!
135 /*!
151 \fn void QLegend::colorChanged(QColor)
136 \fn void QLegend::colorChanged(QColor)
152 The color of the legend background changed to \a color.
137 The color of the legend background changed to \a color.
153 */
138 */
154
139
155 /*!
140 /*!
156 \fn void QLegend::borderColorChanged(QColor)
141 \fn void QLegend::borderColorChanged(QColor)
157 The border color of the legend background changed to \a color.
142 The border color of the legend background changed to \a color.
158 */
143 */
159
144
160 /*!
145 /*!
161 \fn void QLegend::fontChanged(QFont)
146 \fn void QLegend::fontChanged(QFont)
162 The font of markers of the legend changed to \a font.
147 The font of markers of the legend changed to \a font.
163 */
148 */
164
149
165 /*!
150 /*!
166 \fn void QLegend::labelColorChanged(QColor color)
151 \fn void QLegend::labelColorChanged(QColor color)
167 This signal is emitted when the color of brush used to draw labels has changed to \a color.
152 This signal is emitted when the color of brush used to draw labels has changed to \a color.
168 */
153 */
169
154
170 /*!
155 /*!
171 Constructs the legend object and sets the parent to \a parent
156 Constructs the legend object and sets the parent to \a parent
172 */
157 */
173
158
174 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart),
159 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart),
175 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this))
160 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this))
176 {
161 {
177 setZValue(ChartPresenter::LegendZValue);
162 setZValue(ChartPresenter::LegendZValue);
178 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
163 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
179 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*)));
164 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*)));
180 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
165 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
181 setLayout(d_ptr->m_layout);
166 setLayout(d_ptr->m_layout);
182 }
167 }
183
168
184 /*!
169 /*!
185 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
170 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
186 */
171 */
187 QLegend::~QLegend()
172 QLegend::~QLegend()
188 {
173 {
189 }
174 }
190
175
191 /*!
176 /*!
192 \internal
177 \internal
193 */
178 */
194 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
179 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
195 {
180 {
196 Q_UNUSED(option)
181 Q_UNUSED(option)
197 Q_UNUSED(widget)
182 Q_UNUSED(widget)
198
183
199 if (!d_ptr->m_backgroundVisible)
184 if (!d_ptr->m_backgroundVisible)
200 return;
185 return;
201
186
202 painter->setOpacity(opacity());
187 painter->setOpacity(opacity());
203 painter->setPen(d_ptr->m_pen);
188 painter->setPen(d_ptr->m_pen);
204 painter->setBrush(d_ptr->m_brush);
189 painter->setBrush(d_ptr->m_brush);
205 painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()));
190 painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()));
206 }
191 }
207
192
208
193
209 /*!
194 /*!
210 Sets the \a brush of legend. Brush affects the background of legend.
195 Sets the \a brush of legend. Brush affects the background of legend.
211 */
196 */
212 void QLegend::setBrush(const QBrush &brush)
197 void QLegend::setBrush(const QBrush &brush)
213 {
198 {
214 if (d_ptr->m_brush != brush) {
199 if (d_ptr->m_brush != brush) {
215 d_ptr->m_brush = brush;
200 d_ptr->m_brush = brush;
216 update();
201 update();
217 emit colorChanged(brush.color());
202 emit colorChanged(brush.color());
218 }
203 }
219 }
204 }
220
205
221 /*!
206 /*!
222 Returns the brush used by legend.
207 Returns the brush used by legend.
223 */
208 */
224 QBrush QLegend::brush() const
209 QBrush QLegend::brush() const
225 {
210 {
226 return d_ptr->m_brush;
211 return d_ptr->m_brush;
227 }
212 }
228
213
229 void QLegend::setColor(QColor color)
214 void QLegend::setColor(QColor color)
230 {
215 {
231 QBrush b = d_ptr->m_brush;
216 QBrush b = d_ptr->m_brush;
232 if (b.style() != Qt::SolidPattern || b.color() != color) {
217 if (b.style() != Qt::SolidPattern || b.color() != color) {
233 b.setStyle(Qt::SolidPattern);
218 b.setStyle(Qt::SolidPattern);
234 b.setColor(color);
219 b.setColor(color);
235 setBrush(b);
220 setBrush(b);
236 }
221 }
237 }
222 }
238
223
239 QColor QLegend::color()
224 QColor QLegend::color()
240 {
225 {
241 return d_ptr->m_brush.color();
226 return d_ptr->m_brush.color();
242 }
227 }
243
228
244 /*!
229 /*!
245 Sets the \a pen of legend. Pen affects the legend borders.
230 Sets the \a pen of legend. Pen affects the legend borders.
246 */
231 */
247 void QLegend::setPen(const QPen &pen)
232 void QLegend::setPen(const QPen &pen)
248 {
233 {
249 if (d_ptr->m_pen != pen) {
234 if (d_ptr->m_pen != pen) {
250 d_ptr->m_pen = pen;
235 d_ptr->m_pen = pen;
251 update();
236 update();
252 emit borderColorChanged(pen.color());
237 emit borderColorChanged(pen.color());
253 }
238 }
254 }
239 }
255
240
256 /*!
241 /*!
257 Returns the pen used by legend
242 Returns the pen used by legend
258 */
243 */
259
244
260 QPen QLegend::pen() const
245 QPen QLegend::pen() const
261 {
246 {
262 return d_ptr->m_pen;
247 return d_ptr->m_pen;
263 }
248 }
264
249
265 void QLegend::setFont(const QFont &font)
250 void QLegend::setFont(const QFont &font)
266 {
251 {
267 if (d_ptr->m_font != font)
252 if (d_ptr->m_font != font)
268 d_ptr->m_font = font;
253 d_ptr->m_font = font;
269
254
270 foreach (QLegendMarker *marker, d_ptr->markers()) {
255 foreach (QLegendMarker *marker, d_ptr->markers()) {
271 marker->setFont(d_ptr->m_font);
256 marker->setFont(d_ptr->m_font);
272 }
257 }
273 layout()->invalidate();
258 layout()->invalidate();
274 emit fontChanged(font);
259 emit fontChanged(font);
275 }
260 }
276
261
277 QFont QLegend::font() const
262 QFont QLegend::font() const
278 {
263 {
279 return d_ptr->m_font;
264 return d_ptr->m_font;
280 }
265 }
281
266
282 void QLegend::setBorderColor(QColor color)
267 void QLegend::setBorderColor(QColor color)
283 {
268 {
284 QPen p = d_ptr->m_pen;
269 QPen p = d_ptr->m_pen;
285 if (p.color() != color) {
270 if (p.color() != color) {
286 p.setColor(color);
271 p.setColor(color);
287 setPen(p);
272 setPen(p);
288 }
273 }
289 }
274 }
290
275
291 QColor QLegend::borderColor()
276 QColor QLegend::borderColor()
292 {
277 {
293 return d_ptr->m_pen.color();
278 return d_ptr->m_pen.color();
294 }
279 }
295
280
296 /*!
281 /*!
297 Set brush used to draw labels to \a brush.
282 Set brush used to draw labels to \a brush.
298 */
283 */
299 void QLegend::setLabelBrush(const QBrush &brush)
284 void QLegend::setLabelBrush(const QBrush &brush)
300 {
285 {
301 if (d_ptr->m_labelBrush != brush) {
286 if (d_ptr->m_labelBrush != brush) {
302 d_ptr->m_labelBrush = brush;
287 d_ptr->m_labelBrush = brush;
303 foreach (QLegendMarker *marker, d_ptr->markers()) {
288 foreach (QLegendMarker *marker, d_ptr->markers()) {
304 marker->setLabelBrush(d_ptr->m_labelBrush);
289 marker->setLabelBrush(d_ptr->m_labelBrush);
305 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
290 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
306 // instead of mapping it from label brush color
291 // instead of mapping it from label brush color
307 marker->setPen(brush.color());
292 marker->setPen(brush.color());
308 }
293 }
309 emit labelColorChanged(brush.color());
294 emit labelColorChanged(brush.color());
310 }
295 }
311 }
296 }
312
297
313 /*!
298 /*!
314 Brush used to draw labels.
299 Brush used to draw labels.
315 */
300 */
316 QBrush QLegend::labelBrush() const
301 QBrush QLegend::labelBrush() const
317 {
302 {
318 return d_ptr->m_labelBrush;
303 return d_ptr->m_labelBrush;
319 }
304 }
320
305
321 void QLegend::setLabelColor(QColor color)
306 void QLegend::setLabelColor(QColor color)
322 {
307 {
323 QBrush b = d_ptr->m_labelBrush;
308 QBrush b = d_ptr->m_labelBrush;
324 if (b.style() != Qt::SolidPattern || b.color() != color) {
309 if (b.style() != Qt::SolidPattern || b.color() != color) {
325 b.setStyle(Qt::SolidPattern);
310 b.setStyle(Qt::SolidPattern);
326 b.setColor(color);
311 b.setColor(color);
327 setLabelBrush(b);
312 setLabelBrush(b);
328 }
313 }
329 }
314 }
330
315
331 QColor QLegend::labelColor() const
316 QColor QLegend::labelColor() const
332 {
317 {
333 return d_ptr->m_labelBrush.color();
318 return d_ptr->m_labelBrush.color();
334 }
319 }
335
320
336
321
337 void QLegend::setAlignment(Qt::Alignment alignment)
322 void QLegend::setAlignment(Qt::Alignment alignment)
338 {
323 {
339 if (d_ptr->m_alignment != alignment) {
324 if (d_ptr->m_alignment != alignment) {
340 d_ptr->m_alignment = alignment;
325 d_ptr->m_alignment = alignment;
341 layout()->invalidate();
326 layout()->invalidate();
342 }
327 }
343 }
328 }
344
329
345 Qt::Alignment QLegend::alignment() const
330 Qt::Alignment QLegend::alignment() const
346 {
331 {
347 return d_ptr->m_alignment;
332 return d_ptr->m_alignment;
348 }
333 }
349
334
350 /*!
335 /*!
351 Detaches the legend from chart. Chart won't change layout of the legend.
336 Detaches the legend from chart. Chart won't change layout of the legend.
352 */
337 */
353 void QLegend::detachFromChart()
338 void QLegend::detachFromChart()
354 {
339 {
355 d_ptr->m_attachedToChart = false;
340 d_ptr->m_attachedToChart = false;
356 layout()->invalidate();
341 layout()->invalidate();
357 setParent(0);
342 setParent(0);
358
343
359 }
344 }
360
345
361 /*!
346 /*!
362 Attaches the legend to chart. Chart may change layout of the legend.
347 Attaches the legend to chart. Chart may change layout of the legend.
363 */
348 */
364 void QLegend::attachToChart()
349 void QLegend::attachToChart()
365 {
350 {
366 d_ptr->m_attachedToChart = true;
351 d_ptr->m_attachedToChart = true;
367 layout()->invalidate();
352 layout()->invalidate();
368 setParent(d_ptr->m_chart);
353 setParent(d_ptr->m_chart);
369 }
354 }
370
355
371 /*!
356 /*!
372 Returns true, if legend is attached to chart.
357 Returns true, if legend is attached to chart.
373 */
358 */
374 bool QLegend::isAttachedToChart()
359 bool QLegend::isAttachedToChart()
375 {
360 {
376 return d_ptr->m_attachedToChart;
361 return d_ptr->m_attachedToChart;
377 }
362 }
378
363
379 /*!
364 /*!
380 Sets the visibility of legend background to \a visible
365 Sets the visibility of legend background to \a visible
381 */
366 */
382 void QLegend::setBackgroundVisible(bool visible)
367 void QLegend::setBackgroundVisible(bool visible)
383 {
368 {
384 if (d_ptr->m_backgroundVisible != visible) {
369 if (d_ptr->m_backgroundVisible != visible) {
385 d_ptr->m_backgroundVisible = visible;
370 d_ptr->m_backgroundVisible = visible;
386 update();
371 update();
387 emit backgroundVisibleChanged(visible);
372 emit backgroundVisibleChanged(visible);
388 }
373 }
389 }
374 }
390
375
391 /*!
376 /*!
392 Returns the visibility of legend background
377 Returns the visibility of legend background
393 */
378 */
394 bool QLegend::isBackgroundVisible() const
379 bool QLegend::isBackgroundVisible() const
395 {
380 {
396 return d_ptr->m_backgroundVisible;
381 return d_ptr->m_backgroundVisible;
397 }
382 }
398
383
399 QList<QLegendMarker*> QLegend::markers() const
384 QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const
400 {
385 {
401 return d_ptr->markers();
386 return d_ptr->markers(series);
402 }
387 }
403
388
404 void QLegend::addSeries(QAbstractSeries* series)
389 void QLegend::addSeries(QAbstractSeries *series)
405 {
390 {
406 d_ptr->addSeries(series);
391 d_ptr->addSeries(series);
407 }
392 }
408
393
409 void QLegend::removeSeries(QAbstractSeries* series)
394 void QLegend::removeSeries(QAbstractSeries *series)
410 {
395 {
411 d_ptr->removeSeries(series);
396 d_ptr->removeSeries(series);
412 }
397 }
413
398
414 /*!
399 /*!
415 \internal \a event see QGraphicsWidget for details
400 \internal \a event see QGraphicsWidget for details
416 */
401 */
417 void QLegend::hideEvent(QHideEvent *event)
402 void QLegend::hideEvent(QHideEvent *event)
418 {
403 {
419 if (isAttachedToChart())
404 if (isAttachedToChart())
420 d_ptr->m_presenter->layout()->invalidate();
405 d_ptr->m_presenter->layout()->invalidate();
421 QGraphicsWidget::hideEvent(event);
406 QGraphicsWidget::hideEvent(event);
422 }
407 }
423 /*!
408 /*!
424 \internal \a event see QGraphicsWidget for details
409 \internal \a event see QGraphicsWidget for details
425 */
410 */
426 void QLegend::showEvent(QShowEvent *event)
411 void QLegend::showEvent(QShowEvent *event)
427 {
412 {
428 if (isAttachedToChart()) {
413 if (isAttachedToChart()) {
429 d_ptr->items()->setVisible(false);
414 d_ptr->items()->setVisible(false);
430 layout()->invalidate();
415 layout()->invalidate();
431 }
416 }
432 QGraphicsWidget::showEvent(event);
417 QGraphicsWidget::showEvent(event);
433 //layout activation will show the items
418 //layout activation will show the items
434 }
419 }
435
420
436 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
421 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
437
422
438 QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q)
423 QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q)
439 : q_ptr(q),
424 : q_ptr(q),
440 m_presenter(presenter),
425 m_presenter(presenter),
441 m_layout(new LegendLayout(q)),
426 m_layout(new LegendLayout(q)),
442 m_chart(chart),
427 m_chart(chart),
443 m_items(new QGraphicsItemGroup(q)),
428 m_items(new QGraphicsItemGroup(q)),
444 m_alignment(Qt::AlignTop),
429 m_alignment(Qt::AlignTop),
445 m_brush(QBrush()),
430 m_brush(QBrush()),
446 m_pen(QPen()),
431 m_pen(QPen()),
447 m_labelBrush(QBrush()),
432 m_labelBrush(QBrush()),
448 m_diameter(5),
433 m_diameter(5),
449 m_attachedToChart(true),
434 m_attachedToChart(true),
450 m_backgroundVisible(false)
435 m_backgroundVisible(false)
451 {
436 {
452 m_items->setHandlesChildEvents(false);
437 m_items->setHandlesChildEvents(false);
453 }
438 }
454
439
455 QLegendPrivate::~QLegendPrivate()
440 QLegendPrivate::~QLegendPrivate()
456 {
441 {
457
442
458 }
443 }
459
444
460 void QLegendPrivate::setOffset(const QPointF &offset)
445 void QLegendPrivate::setOffset(const QPointF &offset)
461 {
446 {
462 m_layout->setOffset(offset.x(), offset.y());
447 m_layout->setOffset(offset.x(), offset.y());
463 }
448 }
464
449
465 QPointF QLegendPrivate::offset() const
450 QPointF QLegendPrivate::offset() const
466 {
451 {
467 return m_layout->offset();
452 return m_layout->offset();
468 }
453 }
469
454
470 int QLegendPrivate::roundness(qreal size)
455 int QLegendPrivate::roundness(qreal size)
471 {
456 {
472 return 100 * m_diameter / int(size);
457 return 100 * m_diameter / int(size);
473 }
458 }
474
459
460 QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series)
461 {
462 // Return all markers
463 if (!series) {
464 return m_markers;
465 }
466
467 // Create filtered list
468 QList<QLegendMarker *> markers;
469 foreach (QLegendMarker *marker, m_markers) {
470 if (marker->series() == series) {
471 markers.append(marker);
472 }
473 }
474 return markers;
475 }
476
475 void QLegendPrivate::addSeries(QAbstractSeries* series)
477 void QLegendPrivate::addSeries(QAbstractSeries *series)
476 {
478 {
477 // Only allow one instance of series
479 // Only allow one instance of series
478 if (m_series.contains(series)) {
480 if (m_series.contains(series)) {
479 return;
481 return;
480 }
482 }
481
483
482 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
484 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
483 decorateMarkers(newMarkers);
485 decorateMarkers(newMarkers);
484 addMarkers(newMarkers);
486 addMarkers(newMarkers);
485
487
486 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
488 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
487 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
489 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
488
490
489 m_series.append(series);
491 m_series.append(series);
490 m_items->setVisible(false);
492 m_items->setVisible(false);
491 m_layout->invalidate();
493 m_layout->invalidate();
492 }
494 }
493
495
494 void QLegendPrivate::removeSeries(QAbstractSeries* series)
496 void QLegendPrivate::removeSeries(QAbstractSeries *series)
495 {
497 {
496 if (m_series.contains(series)) {
498 if (m_series.contains(series)) {
497 m_series.removeOne(series);
499 m_series.removeOne(series);
498 }
500 }
499
501
500 // Find out, which markers to remove
502 // Find out, which markers to remove
501 QList<QLegendMarker *> removed;
503 QList<QLegendMarker *> removed;
502 foreach (QLegendMarker *m, m_markers) {
504 foreach (QLegendMarker *m, m_markers) {
503 if (m->series() == series) {
505 if (m->series() == series) {
504 removed << m;
506 removed << m;
505 }
507 }
506 }
508 }
507 removeMarkers(removed);
509 removeMarkers(removed);
508
510
509 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
511 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
510 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
512 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
511
513
512 m_layout->invalidate();
514 m_layout->invalidate();
513 }
515 }
514
516
515 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series)
517 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series)
516 {
518 {
517 // Moved to appendSeries
519 // Moved to appendSeries
518 // This slot is just to make old code work for now.
520 // This slot is just to make old code work for now.
519 addSeries(series);
521 addSeries(series);
520 }
522 }
521
523
522 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
524 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
523 {
525 {
524 // Moved to removeSeries
526 // Moved to removeSeries
525 // This slot is just to make old code work for now.
527 // This slot is just to make old code work for now.
526 removeSeries(series);
528 removeSeries(series);
527 }
529 }
528
530
529 void QLegendPrivate::handleSeriesVisibleChanged()
531 void QLegendPrivate::handleSeriesVisibleChanged()
530 {
532 {
531 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
533 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
532 Q_ASSERT(series);
534 Q_ASSERT(series);
533
535
534 foreach (QLegendMarker* marker, m_markers) {
536 foreach (QLegendMarker *marker, m_markers) {
535 if (marker->series() == series) {
537 if (marker->series() == series) {
536 marker->setVisible(series->isVisible());
538 marker->setVisible(series->isVisible());
537 }
539 }
538 }
540 }
539 m_layout->invalidate();
541 m_layout->invalidate();
540 }
542 }
541
543
542 void QLegendPrivate::handleCountChanged()
544 void QLegendPrivate::handleCountChanged()
543 {
545 {
544 // Here we handle the changes in marker count.
546 // Here we handle the changes in marker count.
545 // Can happen for example when pieslice(s) have been added to or removed from pieseries.
547 // Can happen for example when pieslice(s) have been added to or removed from pieseries.
546
548
547 QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender());
549 QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender());
548 QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr);
550 QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr);
549
551
550 // Find out removed markers and created markers
552 // Find out removed markers and created markers
551 QList<QLegendMarker *> removedMarkers;
553 QList<QLegendMarker *> removedMarkers;
552 foreach (QLegendMarker *oldMarker, m_markers) {
554 foreach (QLegendMarker *oldMarker, m_markers) {
553 // we have marker, which is related to sender.
555 // we have marker, which is related to sender.
554 if (oldMarker->series() == series->q_ptr) {
556 if (oldMarker->series() == series->q_ptr) {
555 bool found = false;
557 bool found = false;
556 foreach(QLegendMarker *newMarker, createdMarkers) {
558 foreach(QLegendMarker *newMarker, createdMarkers) {
557 // New marker considered existing if:
559 // New marker considered existing if:
558 // - d_ptr->relatedObject() is same for both markers.
560 // - d_ptr->relatedObject() is same for both markers.
559 if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) {
561 if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) {
560 // Delete the new marker, since we already have existing marker, that might be connected on user side.
562 // Delete the new marker, since we already have existing marker, that might be connected on user side.
561 found = true;
563 found = true;
562 createdMarkers.removeOne(newMarker);
564 createdMarkers.removeOne(newMarker);
563 delete newMarker;
565 delete newMarker;
564 }
566 }
565 }
567 }
566 if (!found) {
568 if (!found) {
567 // No related object found for marker, add to removedMarkers list
569 // No related object found for marker, add to removedMarkers list
568 removedMarkers << oldMarker;
570 removedMarkers << oldMarker;
569 }
571 }
570 }
572 }
571 }
573 }
572
574
573 removeMarkers(removedMarkers);
575 removeMarkers(removedMarkers);
574 decorateMarkers(createdMarkers);
576 decorateMarkers(createdMarkers);
575 addMarkers(createdMarkers);
577 addMarkers(createdMarkers);
576
578
577 q_ptr->layout()->invalidate();
579 q_ptr->layout()->invalidate();
578 }
580 }
579
581
580 void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers)
582 void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers)
581 {
583 {
582 foreach (QLegendMarker* marker, markers) {
584 foreach (QLegendMarker *marker, markers) {
583 m_items->addToGroup(marker->d_ptr.data()->item());
585 m_items->addToGroup(marker->d_ptr.data()->item());
584 m_markers << marker;
586 m_markers << marker;
585 }
587 }
586 }
588 }
587
589
588 void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers)
590 void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers)
589 {
591 {
590 foreach (QLegendMarker *marker, markers) {
592 foreach (QLegendMarker *marker, markers) {
591 marker->d_ptr->item()->setVisible(false);
593 marker->d_ptr->item()->setVisible(false);
592 m_items->removeFromGroup(marker->d_ptr->item());
594 m_items->removeFromGroup(marker->d_ptr->item());
593 delete marker;
595 delete marker;
594 m_markers.removeOne(marker);
596 m_markers.removeOne(marker);
595 }
597 }
596 }
598 }
597
599
598 void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers)
600 void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers)
599 {
601 {
600 foreach (QLegendMarker* marker, markers) {
602 foreach (QLegendMarker *marker, markers) {
601 marker->setFont(m_font);
603 marker->setFont(m_font);
602 marker->setLabelBrush(m_labelBrush);
604 marker->setLabelBrush(m_labelBrush);
603 }
605 }
604 }
606 }
605
607
606
608
607 #include "moc_qlegend.cpp"
609 #include "moc_qlegend.cpp"
608 #include "moc_qlegend_p.cpp"
610 #include "moc_qlegend_p.cpp"
609
611
610 QTCOMMERCIALCHART_END_NAMESPACE
612 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,109 +1,109
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QLEGEND_H
21 #ifndef QLEGEND_H
22 #define QLEGEND_H
22 #define QLEGEND_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QGraphicsWidget>
25 #include <QGraphicsWidget>
26 #include <QPen>
26 #include <QPen>
27 #include <QBrush>
27 #include <QBrush>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QChart;
31 class QChart;
32 class QLegendPrivate;
32 class QLegendPrivate;
33 class QLegendMarker;
33 class QLegendMarker;
34 class QAbstractSeries;
34 class QAbstractSeries;
35
35
36 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
36 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
37 {
37 {
38 Q_OBJECT
38 Q_OBJECT
39 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
39 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
40 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged)
40 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged)
41 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
41 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
42 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
42 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
43 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
43 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
44 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
44 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
45
45
46 private:
46 private:
47 explicit QLegend(QChart *chart);
47 explicit QLegend(QChart *chart);
48
48
49 public:
49 public:
50 ~QLegend();
50 ~QLegend();
51
51
52 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
52 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
53
53
54 void setBrush(const QBrush &brush);
54 void setBrush(const QBrush &brush);
55 QBrush brush() const;
55 QBrush brush() const;
56 void setColor(QColor color);
56 void setColor(QColor color);
57 QColor color();
57 QColor color();
58
58
59 void setPen(const QPen &pen);
59 void setPen(const QPen &pen);
60 QPen pen() const;
60 QPen pen() const;
61 void setBorderColor(QColor color);
61 void setBorderColor(QColor color);
62 QColor borderColor();
62 QColor borderColor();
63
63
64 void setFont(const QFont &font);
64 void setFont(const QFont &font);
65 QFont font() const;
65 QFont font() const;
66 void setLabelBrush(const QBrush &brush);
66 void setLabelBrush(const QBrush &brush);
67 QBrush labelBrush() const;
67 QBrush labelBrush() const;
68
68
69 void setLabelColor(QColor color);
69 void setLabelColor(QColor color);
70 QColor labelColor() const;
70 QColor labelColor() const;
71
71
72 void setAlignment(Qt::Alignment alignment);
72 void setAlignment(Qt::Alignment alignment);
73 Qt::Alignment alignment() const;
73 Qt::Alignment alignment() const;
74
74
75 void detachFromChart();
75 void detachFromChart();
76 void attachToChart();
76 void attachToChart();
77 bool isAttachedToChart();
77 bool isAttachedToChart();
78
78
79 void setBackgroundVisible(bool visible = true);
79 void setBackgroundVisible(bool visible = true);
80 bool isBackgroundVisible() const;
80 bool isBackgroundVisible() const;
81
81
82 // New stuff:
82 // New stuff:
83 QList <QLegendMarker*> markers() const;
83 QList <QLegendMarker*> markers(QAbstractSeries *series = 0) const;
84 void addSeries(QAbstractSeries* series);
84 void addSeries(QAbstractSeries *series);
85 void removeSeries(QAbstractSeries* series);
85 void removeSeries(QAbstractSeries *series);
86
86
87 protected:
87 protected:
88 void hideEvent(QHideEvent *event);
88 void hideEvent(QHideEvent *event);
89 void showEvent(QShowEvent *event);
89 void showEvent(QShowEvent *event);
90
90
91 Q_SIGNALS:
91 Q_SIGNALS:
92 void backgroundVisibleChanged(bool visible);
92 void backgroundVisibleChanged(bool visible);
93 void colorChanged(QColor color);
93 void colorChanged(QColor color);
94 void borderColorChanged(QColor color);
94 void borderColorChanged(QColor color);
95 void fontChanged(QFont font);
95 void fontChanged(QFont font);
96 void labelColorChanged(QColor color);
96 void labelColorChanged(QColor color);
97
97
98 private:
98 private:
99 QScopedPointer<QLegendPrivate> d_ptr;
99 QScopedPointer<QLegendPrivate> d_ptr;
100 Q_DISABLE_COPY(QLegend)
100 Q_DISABLE_COPY(QLegend)
101 friend class LegendScroller;
101 friend class LegendScroller;
102 friend class LegendLayout;
102 friend class LegendLayout;
103 friend class ChartLayout;
103 friend class ChartLayout;
104 friend class LegendMarkerItem;
104 friend class LegendMarkerItem;
105 };
105 };
106
106
107 QTCOMMERCIALCHART_END_NAMESPACE
107 QTCOMMERCIALCHART_END_NAMESPACE
108
108
109 #endif // QLEGEND_H
109 #endif // QLEGEND_H
@@ -1,102 +1,100
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QLEGEND_P_H
30 #ifndef QLEGEND_P_H
31 #define QLEGEND_P_H
31 #define QLEGEND_P_H
32
32
33 #include "qlegend.h"
33 #include "qlegend.h"
34 #include "scroller_p.h"
34 #include "scroller_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QChart;
38 class QChart;
39 class ChartPresenter;
39 class ChartPresenter;
40 class QAbstractSeries;
40 class QAbstractSeries;
41 class LegendLayout;
41 class LegendLayout;
42 class Domain;
42 class Domain;
43 class QLegendMarker;
43 class QLegendMarker;
44
44
45 class QLegendPrivate : public QObject, public Scroller
45 class QLegendPrivate : public QObject, public Scroller
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48 public:
48 public:
49 QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q);
49 QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q);
50 ~QLegendPrivate();
50 ~QLegendPrivate();
51
51
52 void setOffset(const QPointF &offset);
52 void setOffset(const QPointF &offset);
53 QPointF offset() const;
53 QPointF offset() const;
54 int roundness(qreal size);
54 int roundness(qreal size);
55
55
56 QGraphicsItemGroup* items() { return m_items; }
56 QGraphicsItemGroup* items() { return m_items; }
57
57
58 // New stuff:
58 QList<QLegendMarker*> markers(QAbstractSeries *series = 0);
59 QList<QLegendMarker*> markers() { return m_markers; }
60 void addSeries(QAbstractSeries* series);
59 void addSeries(QAbstractSeries *series);
61 void removeSeries(QAbstractSeries* series);
60 void removeSeries(QAbstractSeries *series);
62
61
63 public Q_SLOTS:
62 public Q_SLOTS:
64 void handleSeriesAdded(QAbstractSeries *series);
63 void handleSeriesAdded(QAbstractSeries *series);
65 void handleSeriesRemoved(QAbstractSeries *series);
64 void handleSeriesRemoved(QAbstractSeries *series);
66 void handleSeriesVisibleChanged();
65 void handleSeriesVisibleChanged();
67 void handleCountChanged();
66 void handleCountChanged();
68
67
69 private:
68 private:
70 // Internal helpers
69 // Internal helpers
71 void addMarkers(QList<QLegendMarker *> markers);
70 void addMarkers(QList<QLegendMarker *> markers);
72 void removeMarkers(QList<QLegendMarker *> markers);
71 void removeMarkers(QList<QLegendMarker *> markers);
73 void decorateMarkers(QList<QLegendMarker *> markers);
72 void decorateMarkers(QList<QLegendMarker *> markers);
74
73
75 private:
74 private:
76 QLegend *q_ptr;
75 QLegend *q_ptr;
77 ChartPresenter *m_presenter;
76 ChartPresenter *m_presenter;
78 LegendLayout *m_layout;
77 LegendLayout *m_layout;
79 QChart* m_chart;
78 QChart *m_chart;
80 QGraphicsItemGroup* m_items;
79 QGraphicsItemGroup *m_items;
81 Qt::Alignment m_alignment;
80 Qt::Alignment m_alignment;
82 QBrush m_brush;
81 QBrush m_brush;
83 QPen m_pen;
82 QPen m_pen;
84 QFont m_font;
83 QFont m_font;
85 QBrush m_labelBrush;
84 QBrush m_labelBrush;
86
85
87 qreal m_diameter;
86 qreal m_diameter;
88 bool m_attachedToChart;
87 bool m_attachedToChart;
89 bool m_backgroundVisible;
88 bool m_backgroundVisible;
90
89
91 friend class QLegend;
92 friend class LegendLayout;
93 QList<QLegendMarker*> m_markers;
90 QList<QLegendMarker *> m_markers;
94 QList<QAbstractSeries*> m_series;
91 QList<QAbstractSeries *> m_series;
95
92
96 friend class QLegend;
93 friend class QLegend;
97 friend class LegendMarkerItem;
94 friend class LegendMarkerItem;
95 friend class LegendLayout;
98 };
96 };
99
97
100 QTCOMMERCIALCHART_END_NAMESPACE
98 QTCOMMERCIALCHART_END_NAMESPACE
101
99
102 #endif
100 #endif
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
1 NO CONTENT: modified file
NO CONTENT: modified file
General Comments 0
You need to be logged in to leave comments. Login now