##// END OF EJS Templates
optional series parameter to markers function. code style fixes
sauimone -
r2193:7e0a20ef8117
parent child
Show More
@@ -1,399 +1,399
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 "legendlayout_p.h"
21 #include "legendlayout_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "qlegend_p.h"
23 #include "qlegend_p.h"
24 #include "chartlayout_p.h"
24 #include "chartlayout_p.h"
25
25
26 #include "qlegendmarker_p.h"
26 #include "qlegendmarker_p.h"
27 #include "legendmarkeritem_p.h"
27 #include "legendmarkeritem_p.h"
28 #include "qlegendmarker.h"
28 #include "qlegendmarker.h"
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 LegendLayout::LegendLayout(QLegend *legend)
32 LegendLayout::LegendLayout(QLegend *legend)
33 : m_legend(legend)
33 : m_legend(legend)
34 {
34 {
35
35
36 }
36 }
37
37
38 LegendLayout::~LegendLayout()
38 LegendLayout::~LegendLayout()
39 {
39 {
40
40
41 }
41 }
42
42
43 void LegendLayout::setOffset(qreal x, qreal y)
43 void LegendLayout::setOffset(qreal x, qreal y)
44 {
44 {
45 bool scrollHorizontal = true;
45 bool scrollHorizontal = true;
46 switch (m_legend->alignment()) {
46 switch (m_legend->alignment()) {
47 case Qt::AlignTop:
47 case Qt::AlignTop:
48 case Qt::AlignBottom:
48 case Qt::AlignBottom:
49 scrollHorizontal = true;
49 scrollHorizontal = true;
50 break;
50 break;
51 case Qt::AlignLeft:
51 case Qt::AlignLeft:
52 case Qt::AlignRight:
52 case Qt::AlignRight:
53 scrollHorizontal = false;
53 scrollHorizontal = false;
54 break;
54 break;
55 }
55 }
56
56
57 // If detached, the scrolling direction is vertical instead of horizontal and vice versa.
57 // If detached, the scrolling direction is vertical instead of horizontal and vice versa.
58 if (!m_legend->isAttachedToChart())
58 if (!m_legend->isAttachedToChart())
59 scrollHorizontal = !scrollHorizontal;
59 scrollHorizontal = !scrollHorizontal;
60
60
61 QRectF boundingRect = geometry();
61 QRectF boundingRect = geometry();
62 qreal left, top, right, bottom;
62 qreal left, top, right, bottom;
63 getContentsMargins(&left, &top, &right, &bottom);
63 getContentsMargins(&left, &top, &right, &bottom);
64 boundingRect.adjust(left, top, -right, -bottom);
64 boundingRect.adjust(left, top, -right, -bottom);
65
65
66 // Limit offset between m_minOffset and m_maxOffset
66 // Limit offset between m_minOffset and m_maxOffset
67 if (scrollHorizontal) {
67 if (scrollHorizontal) {
68 if (m_width <= boundingRect.width())
68 if (m_width <= boundingRect.width())
69 return;
69 return;
70
70
71 if (x != m_offsetX) {
71 if (x != m_offsetX) {
72 m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
72 m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
73 m_legend->d_ptr->items()->setPos(-m_offsetX, boundingRect.top());
73 m_legend->d_ptr->items()->setPos(-m_offsetX, boundingRect.top());
74 }
74 }
75 } else {
75 } else {
76 if (m_height <= boundingRect.height())
76 if (m_height <= boundingRect.height())
77 return;
77 return;
78
78
79 if (y != m_offsetY) {
79 if (y != m_offsetY) {
80 m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
80 m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
81 m_legend->d_ptr->items()->setPos(boundingRect.left(), -m_offsetY);
81 m_legend->d_ptr->items()->setPos(boundingRect.left(), -m_offsetY);
82 }
82 }
83 }
83 }
84 }
84 }
85
85
86 QPointF LegendLayout::offset() const
86 QPointF LegendLayout::offset() const
87 {
87 {
88 return QPointF(m_offsetX, m_offsetY);
88 return QPointF(m_offsetX, m_offsetY);
89 }
89 }
90
90
91 void LegendLayout::invalidate()
91 void LegendLayout::invalidate()
92 {
92 {
93 QGraphicsLayout::invalidate();
93 QGraphicsLayout::invalidate();
94 if (m_legend->isAttachedToChart())
94 if (m_legend->isAttachedToChart())
95 m_legend->d_ptr->m_presenter->layout()->invalidate();
95 m_legend->d_ptr->m_presenter->layout()->invalidate();
96 }
96 }
97
97
98 void LegendLayout::setGeometry(const QRectF &rect)
98 void LegendLayout::setGeometry(const QRectF &rect)
99 {
99 {
100 m_legend->d_ptr->items()->setVisible(m_legend->isVisible());
100 m_legend->d_ptr->items()->setVisible(m_legend->isVisible());
101
101
102 QGraphicsLayout::setGeometry(rect);
102 QGraphicsLayout::setGeometry(rect);
103
103
104 if (m_legend->isAttachedToChart())
104 if (m_legend->isAttachedToChart())
105 setAttachedGeometry(rect);
105 setAttachedGeometry(rect);
106 else
106 else
107 setDettachedGeometry(rect);
107 setDettachedGeometry(rect);
108 }
108 }
109
109
110 void LegendLayout::setAttachedGeometry(const QRectF &rect)
110 void LegendLayout::setAttachedGeometry(const QRectF &rect)
111 {
111 {
112 if (!rect.isValid())
112 if (!rect.isValid())
113 return;
113 return;
114
114
115 m_offsetX = 0;
115 m_offsetX = 0;
116 m_offsetY = 0;
116 m_offsetY = 0;
117
117
118 QSizeF size(0, 0);
118 QSizeF size(0, 0);
119
119
120 if (m_legend->d_ptr->markers().isEmpty()) {
120 if (m_legend->d_ptr->markers().isEmpty()) {
121 return;
121 return;
122 }
122 }
123
123
124 m_width = 0;
124 m_width = 0;
125 m_height = 0;
125 m_height = 0;
126
126
127 qreal left, top, right, bottom;
127 qreal left, top, right, bottom;
128 getContentsMargins(&left, &top, &right, &bottom);
128 getContentsMargins(&left, &top, &right, &bottom);
129
129
130 QRectF geometry = rect.adjusted(left, top, -right, -bottom);
130 QRectF geometry = rect.adjusted(left, top, -right, -bottom);
131
131
132 switch(m_legend->alignment()) {
132 switch(m_legend->alignment()) {
133 case Qt::AlignTop:
133 case Qt::AlignTop:
134 case Qt::AlignBottom: {
134 case Qt::AlignBottom: {
135 QPointF point(0,0);
135 QPointF point(0,0);
136 foreach (QLegendMarker* marker, m_legend->d_ptr->markers()) {
136 foreach (QLegendMarker *marker, m_legend->d_ptr->markers()) {
137 LegendMarkerItem* item = marker->d_ptr->item();
137 LegendMarkerItem *item = marker->d_ptr->item();
138 if (item->isVisible()) {
138 if (item->isVisible()) {
139 item->setGeometry(geometry);
139 item->setGeometry(geometry);
140 item->setPos(point.x(),geometry.height()/2 - item->boundingRect().height()/2);
140 item->setPos(point.x(),geometry.height()/2 - item->boundingRect().height()/2);
141 const QRectF& rect = item->boundingRect();
141 const QRectF &rect = item->boundingRect();
142 size = size.expandedTo(rect.size());
142 size = size.expandedTo(rect.size());
143 qreal w = rect.width();
143 qreal w = rect.width();
144 m_width+=w;
144 m_width+=w;
145 point.setX(point.x() + w);
145 point.setX(point.x() + w);
146 }
146 }
147 }
147 }
148 if (m_width < geometry.width())
148 if (m_width < geometry.width())
149 m_legend->d_ptr->items()->setPos(geometry.width() / 2 - m_width / 2, geometry.top());
149 m_legend->d_ptr->items()->setPos(geometry.width() / 2 - m_width / 2, geometry.top());
150 else
150 else
151 m_legend->d_ptr->items()->setPos(geometry.topLeft());
151 m_legend->d_ptr->items()->setPos(geometry.topLeft());
152 m_height = size.height();
152 m_height = size.height();
153 }
153 }
154 break;
154 break;
155 case Qt::AlignLeft:
155 case Qt::AlignLeft:
156 case Qt::AlignRight: {
156 case Qt::AlignRight: {
157 QPointF point(0,0);
157 QPointF point(0,0);
158 foreach (QLegendMarker* marker, m_legend->d_ptr->markers()) {
158 foreach (QLegendMarker *marker, m_legend->d_ptr->markers()) {
159 LegendMarkerItem* item = marker->d_ptr->item();
159 LegendMarkerItem *item = marker->d_ptr->item();
160 if (item->isVisible()) {
160 if (item->isVisible()) {
161 item->setGeometry(geometry);
161 item->setGeometry(geometry);
162 item->setPos(point);
162 item->setPos(point);
163 const QRectF& rect = item->boundingRect();
163 const QRectF &rect = item->boundingRect();
164 qreal h = rect.height();
164 qreal h = rect.height();
165 size = size.expandedTo(rect.size());
165 size = size.expandedTo(rect.size());
166 m_height+=h;
166 m_height+=h;
167 point.setY(point.y() + h);
167 point.setY(point.y() + h);
168 }
168 }
169 }
169 }
170
170
171 if (m_height < geometry.height())
171 if (m_height < geometry.height())
172 m_legend->d_ptr->items()->setPos(geometry.left(), geometry.height() / 2 - m_height / 2);
172 m_legend->d_ptr->items()->setPos(geometry.left(), geometry.height() / 2 - m_height / 2);
173 else
173 else
174 m_legend->d_ptr->items()->setPos(geometry.topLeft());
174 m_legend->d_ptr->items()->setPos(geometry.topLeft());
175 m_width = size.width();
175 m_width = size.width();
176 break;
176 break;
177 }
177 }
178 }
178 }
179
179
180 m_minOffsetX = -left;
180 m_minOffsetX = -left;
181 m_minOffsetY = - top;
181 m_minOffsetY = - top;
182 m_maxOffsetX = m_width - geometry.width() - right;
182 m_maxOffsetX = m_width - geometry.width() - right;
183 m_maxOffsetY = m_height - geometry.height() - bottom;
183 m_maxOffsetY = m_height - geometry.height() - bottom;
184 }
184 }
185
185
186 void LegendLayout::setDettachedGeometry(const QRectF &rect)
186 void LegendLayout::setDettachedGeometry(const QRectF &rect)
187 {
187 {
188 if (!rect.isValid())
188 if (!rect.isValid())
189 return;
189 return;
190
190
191 // Detached layout is different.
191 // Detached layout is different.
192 // In detached mode legend may have multiple rows and columns, so layout calculations
192 // In detached mode legend may have multiple rows and columns, so layout calculations
193 // differ a log from attached mode.
193 // differ a log from attached mode.
194 // Also the scrolling logic is bit different.
194 // Also the scrolling logic is bit different.
195
195
196 m_offsetX = 0;
196 m_offsetX = 0;
197 m_offsetY = 0;
197 m_offsetY = 0;
198
198
199 qreal left, top, right, bottom;
199 qreal left, top, right, bottom;
200 getContentsMargins(&left, &top, &right, &bottom);
200 getContentsMargins(&left, &top, &right, &bottom);
201 QRectF geometry = rect.adjusted(left, top, -right, -bottom);
201 QRectF geometry = rect.adjusted(left, top, -right, -bottom);
202
202
203 QSizeF size(0, 0);
203 QSizeF size(0, 0);
204
204
205 QList<QLegendMarker *> markers = m_legend->d_ptr->markers();
205 QList<QLegendMarker *> markers = m_legend->d_ptr->markers();
206
206
207 if (markers.isEmpty())
207 if (markers.isEmpty())
208 return;
208 return;
209
209
210 switch (m_legend->alignment()) {
210 switch (m_legend->alignment()) {
211 case Qt::AlignTop: {
211 case Qt::AlignTop: {
212 QPointF point(0, 0);
212 QPointF point(0, 0);
213 m_width = 0;
213 m_width = 0;
214 m_height = 0;
214 m_height = 0;
215 for (int i = 0; i < markers.count(); i++) {
215 for (int i = 0; i < markers.count(); i++) {
216 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
216 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
217 if (item->isVisible()) {
217 if (item->isVisible()) {
218 item->setGeometry(geometry);
218 item->setGeometry(geometry);
219 item->setPos(point.x(),point.y());
219 item->setPos(point.x(),point.y());
220 const QRectF& boundingRect = item->boundingRect();
220 const QRectF &boundingRect = item->boundingRect();
221 qreal w = boundingRect.width();
221 qreal w = boundingRect.width();
222 qreal h = boundingRect.height();
222 qreal h = boundingRect.height();
223 m_width = qMax(m_width,w);
223 m_width = qMax(m_width,w);
224 m_height = qMax(m_height,h);
224 m_height = qMax(m_height,h);
225 point.setX(point.x() + w);
225 point.setX(point.x() + w);
226 if (point.x() + w > geometry.left() + geometry.width() - right) {
226 if (point.x() + w > geometry.left() + geometry.width() - right) {
227 // Next item would go off rect.
227 // Next item would go off rect.
228 point.setX(0);
228 point.setX(0);
229 point.setY(point.y() + h);
229 point.setY(point.y() + h);
230 if (i+1 < markers.count()) {
230 if (i+1 < markers.count()) {
231 m_height += h;
231 m_height += h;
232 }
232 }
233 }
233 }
234 }
234 }
235 }
235 }
236 m_legend->d_ptr->items()->setPos(geometry.topLeft());
236 m_legend->d_ptr->items()->setPos(geometry.topLeft());
237
237
238 m_minOffsetX = -left;
238 m_minOffsetX = -left;
239 m_minOffsetY = -top;
239 m_minOffsetY = -top;
240 m_maxOffsetX = m_width - geometry.width() - right;
240 m_maxOffsetX = m_width - geometry.width() - right;
241 m_maxOffsetY = m_height - geometry.height() - bottom;
241 m_maxOffsetY = m_height - geometry.height() - bottom;
242 }
242 }
243 break;
243 break;
244 case Qt::AlignBottom: {
244 case Qt::AlignBottom: {
245 QPointF point(0, geometry.height());
245 QPointF point(0, geometry.height());
246 m_width = 0;
246 m_width = 0;
247 m_height = 0;
247 m_height = 0;
248 for (int i = 0; i < markers.count(); i++) {
248 for (int i = 0; i < markers.count(); i++) {
249 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
249 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
250 if (item->isVisible()) {
250 if (item->isVisible()) {
251 item->setGeometry(geometry);
251 item->setGeometry(geometry);
252 const QRectF& boundingRect = item->boundingRect();
252 const QRectF &boundingRect = item->boundingRect();
253 qreal w = boundingRect.width();
253 qreal w = boundingRect.width();
254 qreal h = boundingRect.height();
254 qreal h = boundingRect.height();
255 m_width = qMax(m_width,w);
255 m_width = qMax(m_width,w);
256 m_height = qMax(m_height,h);
256 m_height = qMax(m_height,h);
257 item->setPos(point.x(),point.y() - h);
257 item->setPos(point.x(),point.y() - h);
258 point.setX(point.x() + w);
258 point.setX(point.x() + w);
259 if (point.x() + w > geometry.left() + geometry.width() - right) {
259 if (point.x() + w > geometry.left() + geometry.width() - right) {
260 // Next item would go off rect.
260 // Next item would go off rect.
261 point.setX(0);
261 point.setX(0);
262 point.setY(point.y() - h);
262 point.setY(point.y() - h);
263 if (i+1 < markers.count()) {
263 if (i+1 < markers.count()) {
264 m_height += h;
264 m_height += h;
265 }
265 }
266 }
266 }
267 }
267 }
268 }
268 }
269 m_legend->d_ptr->items()->setPos(geometry.topLeft());
269 m_legend->d_ptr->items()->setPos(geometry.topLeft());
270
270
271 m_minOffsetX = -left;
271 m_minOffsetX = -left;
272 m_minOffsetY = -m_height + geometry.height() - top;
272 m_minOffsetY = -m_height + geometry.height() - top;
273 m_maxOffsetX = m_width - geometry.width() - right;
273 m_maxOffsetX = m_width - geometry.width() - right;
274 m_maxOffsetY = -bottom;
274 m_maxOffsetY = -bottom;
275 }
275 }
276 break;
276 break;
277 case Qt::AlignLeft: {
277 case Qt::AlignLeft: {
278 QPointF point(0, 0);
278 QPointF point(0, 0);
279 m_width = 0;
279 m_width = 0;
280 m_height = 0;
280 m_height = 0;
281 qreal maxWidth = 0;
281 qreal maxWidth = 0;
282 for (int i = 0; i < markers.count(); i++) {
282 for (int i = 0; i < markers.count(); i++) {
283 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
283 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
284 if (item->isVisible()) {
284 if (item->isVisible()) {
285 item->setGeometry(geometry);
285 item->setGeometry(geometry);
286 const QRectF& boundingRect = item->boundingRect();
286 const QRectF &boundingRect = item->boundingRect();
287 qreal w = boundingRect.width();
287 qreal w = boundingRect.width();
288 qreal h = boundingRect.height();
288 qreal h = boundingRect.height();
289 m_height = qMax(m_height,h);
289 m_height = qMax(m_height,h);
290 maxWidth = qMax(maxWidth,w);
290 maxWidth = qMax(maxWidth,w);
291 item->setPos(point.x(),point.y());
291 item->setPos(point.x(),point.y());
292 point.setY(point.y() + h);
292 point.setY(point.y() + h);
293 if (point.y() + h > geometry.bottom() - bottom) {
293 if (point.y() + h > geometry.bottom() - bottom) {
294 // Next item would go off rect.
294 // Next item would go off rect.
295 point.setX(point.x() + maxWidth);
295 point.setX(point.x() + maxWidth);
296 point.setY(0);
296 point.setY(0);
297 if (i+1 < markers.count()) {
297 if (i+1 < markers.count()) {
298 m_width += maxWidth;
298 m_width += maxWidth;
299 maxWidth = 0;
299 maxWidth = 0;
300 }
300 }
301 }
301 }
302 }
302 }
303 }
303 }
304 m_width += maxWidth;
304 m_width += maxWidth;
305 m_legend->d_ptr->items()->setPos(geometry.topLeft());
305 m_legend->d_ptr->items()->setPos(geometry.topLeft());
306
306
307 m_minOffsetX = -left;
307 m_minOffsetX = -left;
308 m_minOffsetY = -top;
308 m_minOffsetY = -top;
309 m_maxOffsetX = m_width - geometry.width() - right;
309 m_maxOffsetX = m_width - geometry.width() - right;
310 m_maxOffsetY = m_height - geometry.height() - bottom;
310 m_maxOffsetY = m_height - geometry.height() - bottom;
311 }
311 }
312 break;
312 break;
313 case Qt::AlignRight: {
313 case Qt::AlignRight: {
314 QPointF point(geometry.width(), 0);
314 QPointF point(geometry.width(), 0);
315 m_width = 0;
315 m_width = 0;
316 m_height = 0;
316 m_height = 0;
317 qreal maxWidth = 0;
317 qreal maxWidth = 0;
318 for (int i = 0; i < markers.count(); i++) {
318 for (int i = 0; i < markers.count(); i++) {
319 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
319 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
320 if (item->isVisible()) {
320 if (item->isVisible()) {
321 item->setGeometry(geometry);
321 item->setGeometry(geometry);
322 const QRectF& boundingRect = item->boundingRect();
322 const QRectF &boundingRect = item->boundingRect();
323 qreal w = boundingRect.width();
323 qreal w = boundingRect.width();
324 qreal h = boundingRect.height();
324 qreal h = boundingRect.height();
325 m_height = qMax(m_height,h);
325 m_height = qMax(m_height,h);
326 maxWidth = qMax(maxWidth,w);
326 maxWidth = qMax(maxWidth,w);
327 item->setPos(point.x() - w,point.y());
327 item->setPos(point.x() - w,point.y());
328 point.setY(point.y() + h);
328 point.setY(point.y() + h);
329 if (point.y() + h > geometry.bottom()-bottom) {
329 if (point.y() + h > geometry.bottom()-bottom) {
330 // Next item would go off rect.
330 // Next item would go off rect.
331 point.setX(point.x() - maxWidth);
331 point.setX(point.x() - maxWidth);
332 point.setY(0);
332 point.setY(0);
333 if (i+1 < markers.count()) {
333 if (i+1 < markers.count()) {
334 m_width += maxWidth;
334 m_width += maxWidth;
335 maxWidth = 0;
335 maxWidth = 0;
336 }
336 }
337 }
337 }
338 }
338 }
339 }
339 }
340 m_width += maxWidth;
340 m_width += maxWidth;
341 m_legend->d_ptr->items()->setPos(geometry.topLeft());
341 m_legend->d_ptr->items()->setPos(geometry.topLeft());
342
342
343 m_minOffsetX = - m_width + geometry.width() - left;
343 m_minOffsetX = - m_width + geometry.width() - left;
344 m_minOffsetY = -top;
344 m_minOffsetY = -top;
345 m_maxOffsetX = - right;
345 m_maxOffsetX = - right;
346 m_maxOffsetY = m_height - geometry.height() - bottom;
346 m_maxOffsetY = m_height - geometry.height() - bottom;
347 }
347 }
348 break;
348 break;
349 default:
349 default:
350 break;
350 break;
351 }
351 }
352
352
353 }
353 }
354
354
355 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
355 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
356 {
356 {
357 QSizeF size(0, 0);
357 QSizeF size(0, 0);
358 qreal left, top, right, bottom;
358 qreal left, top, right, bottom;
359 getContentsMargins(&left, &top, &right, &bottom);
359 getContentsMargins(&left, &top, &right, &bottom);
360
360
361 if(constraint.isValid()) {
361 if(constraint.isValid()) {
362 foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) {
362 foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) {
363 LegendMarkerItem *item = marker->d_ptr->item();
363 LegendMarkerItem *item = marker->d_ptr->item();
364 size = size.expandedTo(item->effectiveSizeHint(which));
364 size = size.expandedTo(item->effectiveSizeHint(which));
365 }
365 }
366 size = size.boundedTo(constraint);
366 size = size.boundedTo(constraint);
367 }
367 }
368 else if (constraint.width() >= 0) {
368 else if (constraint.width() >= 0) {
369 qreal width = 0;
369 qreal width = 0;
370 qreal height = 0;
370 qreal height = 0;
371 foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) {
371 foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) {
372 LegendMarkerItem *item = marker->d_ptr->item();
372 LegendMarkerItem *item = marker->d_ptr->item();
373 width+=item->effectiveSizeHint(which).width();
373 width+=item->effectiveSizeHint(which).width();
374 height=qMax(height,item->effectiveSizeHint(which).height());
374 height=qMax(height,item->effectiveSizeHint(which).height());
375 }
375 }
376
376
377 size = QSizeF(qMin(constraint.width(),width), height);
377 size = QSizeF(qMin(constraint.width(),width), height);
378 }
378 }
379 else if (constraint.height() >= 0) {
379 else if (constraint.height() >= 0) {
380 qreal width = 0;
380 qreal width = 0;
381 qreal height = 0;
381 qreal height = 0;
382 foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) {
382 foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) {
383 LegendMarkerItem *item = marker->d_ptr->item();
383 LegendMarkerItem *item = marker->d_ptr->item();
384 width=qMax(width,item->effectiveSizeHint(which).width());
384 width=qMax(width,item->effectiveSizeHint(which).width());
385 height+=height,item->effectiveSizeHint(which).height();
385 height+=height,item->effectiveSizeHint(which).height();
386 }
386 }
387 size = QSizeF(width,qMin(constraint.height(),height));
387 size = QSizeF(width,qMin(constraint.height(),height));
388 }
388 }
389 else {
389 else {
390 foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) {
390 foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) {
391 LegendMarkerItem *item = marker->d_ptr->item();
391 LegendMarkerItem *item = marker->d_ptr->item();
392 size = size.expandedTo(item->effectiveSizeHint(which));
392 size = size.expandedTo(item->effectiveSizeHint(which));
393 }
393 }
394 }
394 }
395 size += QSize(left + right, top + bottom);
395 size += QSize(left + right, top + bottom);
396 return size;
396 return size;
397 }
397 }
398
398
399 QTCOMMERCIALCHART_END_NAMESPACE
399 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,196 +1,196
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 <QPainter>
21 #include <QPainter>
22 #include <QGraphicsSceneEvent>
22 #include <QGraphicsSceneEvent>
23 #include <QGraphicsSimpleTextItem>
23 #include <QGraphicsSimpleTextItem>
24
24
25 #include "qlegend.h"
25 #include "qlegend.h"
26 #include "qlegend_p.h"
26 #include "qlegend_p.h"
27 #include "qlegendmarker.h"
27 #include "qlegendmarker.h"
28 #include "qlegendmarker_p.h"
28 #include "qlegendmarker_p.h"
29 #include "legendmarkeritem_p.h"
29 #include "legendmarkeritem_p.h"
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) :
33 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) :
34 QGraphicsObject(parent),
34 QGraphicsObject(parent),
35 m_marker(marker),
35 m_marker(marker),
36 m_markerRect(0,0,10.0,10.0),
36 m_markerRect(0,0,10.0,10.0),
37 m_boundingRect(0,0,0,0),
37 m_boundingRect(0,0,0,0),
38 m_textItem(new QGraphicsSimpleTextItem(this)),
38 m_textItem(new QGraphicsSimpleTextItem(this)),
39 m_rectItem(new QGraphicsRectItem(this)),
39 m_rectItem(new QGraphicsRectItem(this)),
40 m_margin(4),
40 m_margin(4),
41 m_space(4),
41 m_space(4),
42 m_pressPos(0, 0)
42 m_pressPos(0, 0)
43 {
43 {
44 m_rectItem->setRect(m_markerRect);
44 m_rectItem->setRect(m_markerRect);
45 }
45 }
46
46
47 void LegendMarkerItem::setPen(const QPen &pen)
47 void LegendMarkerItem::setPen(const QPen &pen)
48 {
48 {
49 m_rectItem->setPen(pen);
49 m_rectItem->setPen(pen);
50 }
50 }
51
51
52 QPen LegendMarkerItem::pen() const
52 QPen LegendMarkerItem::pen() const
53 {
53 {
54 return m_rectItem->pen();
54 return m_rectItem->pen();
55 }
55 }
56
56
57 void LegendMarkerItem::setBrush(const QBrush &brush)
57 void LegendMarkerItem::setBrush(const QBrush &brush)
58 {
58 {
59 m_rectItem->setBrush(brush);
59 m_rectItem->setBrush(brush);
60 }
60 }
61
61
62 QBrush LegendMarkerItem::brush() const
62 QBrush LegendMarkerItem::brush() const
63 {
63 {
64 return m_rectItem->brush();
64 return m_rectItem->brush();
65 }
65 }
66
66
67 void LegendMarkerItem::setFont(const QFont &font)
67 void LegendMarkerItem::setFont(const QFont &font)
68 {
68 {
69 m_textItem->setFont(font);
69 m_textItem->setFont(font);
70 QFontMetrics fn(font);
70 QFontMetrics fn(font);
71 m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
71 m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
72 updateGeometry();
72 updateGeometry();
73 }
73 }
74
74
75 QFont LegendMarkerItem::font() const
75 QFont LegendMarkerItem::font() const
76 {
76 {
77 return m_textItem->font();
77 return m_textItem->font();
78 }
78 }
79
79
80 void LegendMarkerItem::setLabel(const QString label)
80 void LegendMarkerItem::setLabel(const QString label)
81 {
81 {
82 m_label = label;
82 m_label = label;
83 updateGeometry();
83 updateGeometry();
84 }
84 }
85
85
86 QString LegendMarkerItem::label() const
86 QString LegendMarkerItem::label() const
87 {
87 {
88 return m_label;
88 return m_label;
89 }
89 }
90
90
91 void LegendMarkerItem::setLabelBrush(const QBrush &brush)
91 void LegendMarkerItem::setLabelBrush(const QBrush &brush)
92 {
92 {
93 m_textItem->setBrush(brush);
93 m_textItem->setBrush(brush);
94 }
94 }
95
95
96 QBrush LegendMarkerItem::labelBrush() const
96 QBrush LegendMarkerItem::labelBrush() const
97 {
97 {
98 return m_textItem->brush();
98 return m_textItem->brush();
99 }
99 }
100
100
101 void LegendMarkerItem::setGeometry(const QRectF& rect)
101 void LegendMarkerItem::setGeometry(const QRectF &rect)
102 {
102 {
103 QFontMetrics fn (m_font);
103 QFontMetrics fn (m_font);
104
104
105 int width = rect.width();
105 int width = rect.width();
106 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
106 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
107 qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin);
107 qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin);
108
108
109 if (fn.boundingRect(m_label).width() + x > width)
109 if (fn.boundingRect(m_label).width() + x > width)
110 {
110 {
111 QString string = m_label + "...";
111 QString string = m_label + "...";
112 while(fn.boundingRect(string).width() + x > width && string.length() > 3)
112 while(fn.boundingRect(string).width() + x > width && string.length() > 3)
113 string.remove(string.length() - 4, 1);
113 string.remove(string.length() - 4, 1);
114 m_textItem->setText(string);
114 m_textItem->setText(string);
115 }
115 }
116 else
116 else
117 m_textItem->setText(m_label);
117 m_textItem->setText(m_label);
118
118
119 const QRectF& textRect = m_textItem->boundingRect();
119 const QRectF &textRect = m_textItem->boundingRect();
120
120
121
121
122 m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2);
122 m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2);
123 m_rectItem->setRect(m_markerRect);
123 m_rectItem->setRect(m_markerRect);
124 m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2);
124 m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2);
125
125
126 prepareGeometryChange();
126 prepareGeometryChange();
127 m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y);
127 m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y);
128 }
128 }
129
129
130 QRectF LegendMarkerItem::boundingRect() const
130 QRectF LegendMarkerItem::boundingRect() const
131 {
131 {
132 return m_boundingRect;
132 return m_boundingRect;
133 }
133 }
134
134
135 void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
135 void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
136 {
136 {
137 Q_UNUSED(option)
137 Q_UNUSED(option)
138 Q_UNUSED(widget)
138 Q_UNUSED(widget)
139 Q_UNUSED(painter)
139 Q_UNUSED(painter)
140 }
140 }
141
141
142 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
142 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
143 {
143 {
144 Q_UNUSED(constraint)
144 Q_UNUSED(constraint)
145
145
146 QFontMetrics fn(m_textItem->font());
146 QFontMetrics fn(m_textItem->font());
147 QSizeF sh;
147 QSizeF sh;
148
148
149 switch (which) {
149 switch (which) {
150 case Qt::MinimumSize:
150 case Qt::MinimumSize:
151 sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
151 sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
152 break;
152 break;
153 case Qt::PreferredSize:
153 case Qt::PreferredSize:
154 sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
154 sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
155 break;
155 break;
156 default:
156 default:
157 break;
157 break;
158 }
158 }
159
159
160 return sh;
160 return sh;
161 }
161 }
162
162
163 void LegendMarkerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
163 void LegendMarkerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
164 {
164 {
165 MouseEventHandler::handleMousePressEvent(event);
165 MouseEventHandler::handleMousePressEvent(event);
166 m_pressPos = event->screenPos();
166 m_pressPos = event->screenPos();
167 }
167 }
168
168
169 void LegendMarkerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
169 void LegendMarkerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
170 {
170 {
171 MouseEventHandler::handleMouseMoveEvent(event);
171 MouseEventHandler::handleMouseMoveEvent(event);
172 }
172 }
173
173
174 void LegendMarkerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
174 void LegendMarkerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
175 {
175 {
176 MouseEventHandler::handleMouseReleaseEvent(event);
176 MouseEventHandler::handleMouseReleaseEvent(event);
177 }
177 }
178
178
179 void LegendMarkerItem::mouseClicked()
179 void LegendMarkerItem::mouseClicked()
180 {
180 {
181 emit m_marker->q_func()->clicked();
181 emit m_marker->q_func()->clicked();
182 }
182 }
183
183
184 void LegendMarkerItem::mouseMoved(const QPointF &delta)
184 void LegendMarkerItem::mouseMoved(const QPointF &delta)
185 {
185 {
186 m_marker->m_legend->d_ptr->move(delta);
186 m_marker->m_legend->d_ptr->move(delta);
187 }
187 }
188
188
189 void LegendMarkerItem::mouseReleased(const QPointF &pos)
189 void LegendMarkerItem::mouseReleased(const QPointF &pos)
190 {
190 {
191 m_marker->m_legend->d_ptr->release(pos - m_pressPos);
191 m_marker->m_legend->d_ptr->release(pos - m_pressPos);
192 }
192 }
193
193
194 #include "moc_legendmarkeritem_p.cpp"
194 #include "moc_legendmarkeritem_p.cpp"
195
195
196 QTCOMMERCIALCHART_END_NAMESPACE
196 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,112 +1,112
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 LEGENDMARKERITEM_P_H
30 #ifndef LEGENDMARKERITEM_P_H
31 #define LEGENDMARKERITEM_P_H
31 #define LEGENDMARKERITEM_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QGraphicsObject>
34 #include <QGraphicsObject>
35 #include <QFont>
35 #include <QFont>
36 #include <QBrush>
36 #include <QBrush>
37 #include <QPen>
37 #include <QPen>
38 #include <QGraphicsSimpleTextItem>
38 #include <QGraphicsSimpleTextItem>
39 #include <QGraphicsLayoutItem>
39 #include <QGraphicsLayoutItem>
40 #include "mouseeventhandler_p.h"
40 #include "mouseeventhandler_p.h"
41
41
42 QTCOMMERCIALCHART_BEGIN_NAMESPACE
42 QTCOMMERCIALCHART_BEGIN_NAMESPACE
43
43
44 class QLegendMarkerPrivate;
44 class QLegendMarkerPrivate;
45
45
46 class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem, public MouseEventHandler
46 class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem, public MouseEventHandler
47 {
47 {
48 Q_OBJECT
48 Q_OBJECT
49 Q_INTERFACES(QGraphicsLayoutItem)
49 Q_INTERFACES(QGraphicsLayoutItem)
50 public:
50 public:
51 explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = 0);
51 explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = 0);
52
52
53 void setPen(const QPen &pen);
53 void setPen(const QPen &pen);
54 QPen pen() const;
54 QPen pen() const;
55
55
56 void setBrush(const QBrush &brush);
56 void setBrush(const QBrush &brush);
57 QBrush brush() const;
57 QBrush brush() const;
58
58
59 void setFont(const QFont &font);
59 void setFont(const QFont &font);
60 QFont font() const;
60 QFont font() const;
61
61
62 void setLabel(const QString label);
62 void setLabel(const QString label);
63 QString label() const;
63 QString label() const;
64
64
65 void setLabelBrush(const QBrush &brush);
65 void setLabelBrush(const QBrush &brush);
66 QBrush labelBrush() const;
66 QBrush labelBrush() const;
67
67
68 void setGeometry(const QRectF& rect);
68 void setGeometry(const QRectF &rect);
69
69
70 QRectF boundingRect() const;
70 QRectF boundingRect() const;
71
71
72 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
72 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
73
73
74 QSizeF sizeHint (Qt::SizeHint which, const QSizeF& constraint) const;
74 QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint) const;
75
75
76 // Event handlers, logic delegated to MouseEventHandler
76 // Event handlers, logic delegated to MouseEventHandler
77 void mousePressEvent(QGraphicsSceneMouseEvent *event);
77 void mousePressEvent(QGraphicsSceneMouseEvent *event);
78 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
78 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
79 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
79 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
80
80
81 // Filtered callbacks from MouseEventHandler
81 // Filtered callbacks from MouseEventHandler
82 void mouseClicked();
82 void mouseClicked();
83 void mouseMoved(const QPointF &delta);
83 void mouseMoved(const QPointF &delta);
84 void mouseReleased(const QPointF &pos);
84 void mouseReleased(const QPointF &pos);
85
85
86 protected:
86 protected:
87 QLegendMarkerPrivate *m_marker; // Knows
87 QLegendMarkerPrivate *m_marker; // Knows
88 QRectF m_markerRect;
88 QRectF m_markerRect;
89 QRectF m_boundingRect;
89 QRectF m_boundingRect;
90 QGraphicsSimpleTextItem *m_textItem;
90 QGraphicsSimpleTextItem *m_textItem;
91 QGraphicsRectItem *m_rectItem;
91 QGraphicsRectItem *m_rectItem;
92 qreal m_margin;
92 qreal m_margin;
93 qreal m_space;
93 qreal m_space;
94 QString m_label;
94 QString m_label;
95
95
96 QBrush m_labelBrush;
96 QBrush m_labelBrush;
97 QFont m_font;
97 QFont m_font;
98 QPen m_pen;
98 QPen m_pen;
99 QBrush m_brush;
99 QBrush m_brush;
100 bool m_visible;
100 bool m_visible;
101
101
102 QPointF m_pressPos;
102 QPointF m_pressPos;
103
103
104 friend class QLegendMarker;
104 friend class QLegendMarker;
105 friend class QLegendMarkerPrivate;
105 friend class QLegendMarkerPrivate;
106 friend class LegendMarkerItem;
106 friend class LegendMarkerItem;
107 friend class LegendLayout;
107 friend class LegendLayout;
108 };
108 };
109
109
110 QTCOMMERCIALCHART_END_NAMESPACE
110 QTCOMMERCIALCHART_END_NAMESPACE
111
111
112 #endif // LEGENDMARKERITEM_P_H
112 #endif // LEGENDMARKERITEM_P_H
@@ -1,106 +1,106
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 "mouseeventhandler_p.h"
21 #include "mouseeventhandler_p.h"
22 #include <QGraphicsSceneMouseEvent>
22 #include <QGraphicsSceneMouseEvent>
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 MouseEventHandler::MouseEventHandler() :
26 MouseEventHandler::MouseEventHandler() :
27 m_lastPos(0, 0),
27 m_lastPos(0, 0),
28 m_state(Idle),
28 m_state(Idle),
29 m_treshold(10)
29 m_treshold(10)
30 {
30 {
31 }
31 }
32
32
33 MouseEventHandler::~MouseEventHandler()
33 MouseEventHandler::~MouseEventHandler()
34 {
34 {
35 }
35 }
36
36
37 void MouseEventHandler::setMoveTreshold(qreal treshold)
37 void MouseEventHandler::setMoveTreshold(qreal treshold)
38 {
38 {
39 m_treshold = treshold;
39 m_treshold = treshold;
40 }
40 }
41
41
42 void MouseEventHandler::handleMousePressEvent(QGraphicsSceneMouseEvent* event)
42 void MouseEventHandler::handleMousePressEvent(QGraphicsSceneMouseEvent *event)
43 {
43 {
44 m_lastPos = event->screenPos();
44 m_lastPos = event->screenPos();
45 m_state = Pressed;
45 m_state = Pressed;
46 event->accept();
46 event->accept();
47 }
47 }
48
48
49 void MouseEventHandler::handleMouseMoveEvent(QGraphicsSceneMouseEvent* event)
49 void MouseEventHandler::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event)
50 {
50 {
51 QPointF delta = event->screenPos() - m_lastPos;
51 QPointF delta = event->screenPos() - m_lastPos;
52
52
53 switch (m_state) {
53 switch (m_state) {
54 case Pressed: {
54 case Pressed: {
55 // calculate treshold. If enough, change to move state and send out move deltas.
55 // calculate treshold. If enough, change to move state and send out move deltas.
56 if (qAbs(delta.x()) > m_treshold || qAbs(delta.y()) > m_treshold) {
56 if (qAbs(delta.x()) > m_treshold || qAbs(delta.y()) > m_treshold) {
57 m_state = Moved;
57 m_state = Moved;
58 m_lastPos = event->screenPos();
58 m_lastPos = event->screenPos();
59 mouseMoved(delta);
59 mouseMoved(delta);
60 }
60 }
61 event->accept();
61 event->accept();
62 break;
62 break;
63 }
63 }
64 case Moved: {
64 case Moved: {
65 m_lastPos = event->screenPos();
65 m_lastPos = event->screenPos();
66 mouseMoved(delta);
66 mouseMoved(delta);
67 event->accept();
67 event->accept();
68 break;
68 break;
69 }
69 }
70 case Idle:
70 case Idle:
71 default: {
71 default: {
72 event->ignore();
72 event->ignore();
73 break;
73 break;
74 }
74 }
75 }
75 }
76 }
76 }
77
77
78 void MouseEventHandler::handleMouseReleaseEvent(QGraphicsSceneMouseEvent* event)
78 void MouseEventHandler::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
79 {
79 {
80 m_lastPos = event->screenPos();
80 m_lastPos = event->screenPos();
81
81
82 switch (m_state) {
82 switch (m_state) {
83 case Pressed:
83 case Pressed:
84 {
84 {
85 m_state = Idle;
85 m_state = Idle;
86 mouseClicked();
86 mouseClicked();
87 event->accept();
87 event->accept();
88 break;
88 break;
89 }
89 }
90 case Moved:
90 case Moved:
91 {
91 {
92 m_state = Idle;
92 m_state = Idle;
93 mouseReleased(m_lastPos);
93 mouseReleased(m_lastPos);
94 event->accept();
94 event->accept();
95 break;
95 break;
96 }
96 }
97 default:
97 default:
98 {
98 {
99 m_state = Idle;
99 m_state = Idle;
100 event->ignore();
100 event->ignore();
101 break;
101 break;
102 }
102 }
103 }
103 }
104 }
104 }
105
105
106 QTCOMMERCIALCHART_END_NAMESPACE
106 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,89 +1,89
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 /*
30 /*
31 Purpose of this class is to resolve what happens during MousePress - MouseMove - MouseRelease event chain.
31 Purpose of this class is to resolve what happens during MousePress - MouseMove - MouseRelease event chain.
32 Threre can be many MouseMove events and if they all are below our treshold, the result is clicked call.
32 Threre can be many MouseMove events and if they all are below our treshold, the result is clicked call.
33 If any move event goes over treshold, result will be many moved(QPointF delta) calls,
33 If any move event goes over treshold, result will be many moved(QPointF delta) calls,
34 where delta is calculated from original position.
34 where delta is calculated from original position.
35
35
36 Reason for this is, that legend marker don't know when it should emit clicked and when it should
36 Reason for this is, that legend marker don't know when it should emit clicked and when it should
37 allow legend to scroll. We only get this information when some move goes beyond treshold, but
37 allow legend to scroll. We only get this information when some move goes beyond treshold, but
38 then it will be too late to let the scroller handle events, because marker is already handling.
38 then it will be too late to let the scroller handle events, because marker is already handling.
39
39
40 By handling clicked calls in markers and moved calls in scroller, the problem is solved.
40 By handling clicked calls in markers and moved calls in scroller, the problem is solved.
41 Derived class descides, should the virtual method be implemented as signal or not.
41 Derived class descides, should the virtual method be implemented as signal or not.
42
42
43 This could be implemented in LegendMarkerItem, but this way the code is reusable and in one place only.
43 This could be implemented in LegendMarkerItem, but this way the code is reusable and in one place only.
44 */
44 */
45
45
46 #ifndef MOUSEEVENTHANDLER_H
46 #ifndef MOUSEEVENTHANDLER_H
47 #define MOUSEEVENTHANDLER_H
47 #define MOUSEEVENTHANDLER_H
48
48
49 #include "qchartglobal.h"
49 #include "qchartglobal.h"
50 #include <QBasicTimer>
50 #include <QBasicTimer>
51 #include <QTime>
51 #include <QTime>
52 #include <QPointF>
52 #include <QPointF>
53
53
54 class QGraphicsSceneMouseEvent;
54 class QGraphicsSceneMouseEvent;
55
55
56 QTCOMMERCIALCHART_BEGIN_NAMESPACE
56 QTCOMMERCIALCHART_BEGIN_NAMESPACE
57
57
58 class MouseEventHandler
58 class MouseEventHandler
59 {
59 {
60 public:
60 public:
61 enum State {
61 enum State {
62 Idle,
62 Idle,
63 Pressed,
63 Pressed,
64 Moved,
64 Moved,
65 Released
65 Released
66 };
66 };
67
67
68 MouseEventHandler();
68 MouseEventHandler();
69 virtual ~MouseEventHandler();
69 virtual ~MouseEventHandler();
70
70
71 void setMoveTreshold(qreal treshold);
71 void setMoveTreshold(qreal treshold);
72
72
73 virtual void mouseClicked() = 0;
73 virtual void mouseClicked() = 0;
74 virtual void mouseMoved(const QPointF &delta) = 0;
74 virtual void mouseMoved(const QPointF &delta) = 0;
75 virtual void mouseReleased(const QPointF &pos) = 0;
75 virtual void mouseReleased(const QPointF &pos) = 0;
76
76
77 void handleMousePressEvent(QGraphicsSceneMouseEvent* event);
77 void handleMousePressEvent(QGraphicsSceneMouseEvent *event);
78 void handleMouseMoveEvent(QGraphicsSceneMouseEvent* event);
78 void handleMouseMoveEvent(QGraphicsSceneMouseEvent *event);
79 void handleMouseReleaseEvent(QGraphicsSceneMouseEvent* event);
79 void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event);
80
80
81 private:
81 private:
82 QPointF m_lastPos;
82 QPointF m_lastPos;
83 State m_state;
83 State m_state;
84 qreal m_treshold;
84 qreal m_treshold;
85 };
85 };
86
86
87 QTCOMMERCIALCHART_END_NAMESPACE
87 QTCOMMERCIALCHART_END_NAMESPACE
88
88
89 #endif // MOUSEEVENTHANDLER_H
89 #endif // MOUSEEVENTHANDLER_H
@@ -1,85 +1,85
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 "qarealegendmarker.h"
21 #include "qarealegendmarker.h"
22 #include "qarealegendmarker_p.h"
22 #include "qarealegendmarker_p.h"
23 #include "qareaseries_p.h"
23 #include "qareaseries_p.h"
24 #include <QAreaSeries>
24 #include <QAreaSeries>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 QAreaLegendMarker::QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent) :
28 QAreaLegendMarker::QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent) :
29 QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent)
29 QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent)
30 {
30 {
31 }
31 }
32
32
33 QAreaLegendMarker::~QAreaLegendMarker()
33 QAreaLegendMarker::~QAreaLegendMarker()
34 {
34 {
35 }
35 }
36
36
37 /*!
37 /*!
38 \internal
38 \internal
39 */
39 */
40 QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) :
40 QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) :
41 QLegendMarker(d, parent)
41 QLegendMarker(d, parent)
42 {
42 {
43 }
43 }
44
44
45 QAreaSeries* QAreaLegendMarker::series()
45 QAreaSeries* QAreaLegendMarker::series()
46 {
46 {
47 Q_D(QAreaLegendMarker);
47 Q_D(QAreaLegendMarker);
48 return d->m_series;
48 return d->m_series;
49 }
49 }
50
50
51 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
51 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52
52
53 QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) :
53 QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) :
54 QLegendMarkerPrivate(q,legend),
54 QLegendMarkerPrivate(q,legend),
55 m_series(series)
55 m_series(series)
56 {
56 {
57 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
57 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
58 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
58 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
59 updated();
59 updated();
60 }
60 }
61
61
62 QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate()
62 QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate()
63 {
63 {
64 }
64 }
65
65
66 QAreaSeries* QAreaLegendMarkerPrivate::series()
66 QAreaSeries* QAreaLegendMarkerPrivate::series()
67 {
67 {
68 return m_series;
68 return m_series;
69 }
69 }
70
70
71 QObject* QAreaLegendMarkerPrivate::relatedObject()
71 QObject* QAreaLegendMarkerPrivate::relatedObject()
72 {
72 {
73 return m_series;
73 return m_series;
74 }
74 }
75
75
76 void QAreaLegendMarkerPrivate::updated()
76 void QAreaLegendMarkerPrivate::updated()
77 {
77 {
78 m_item->setBrush(m_series->brush());
78 m_item->setBrush(m_series->brush());
79 m_item->setLabel(m_series->name());
79 m_item->setLabel(m_series->name());
80 }
80 }
81
81
82 #include "moc_qarealegendmarker.cpp"
82 #include "moc_qarealegendmarker.cpp"
83 #include "moc_qarealegendmarker_p.cpp"
83 #include "moc_qarealegendmarker_p.cpp"
84
84
85 QTCOMMERCIALCHART_END_NAMESPACE
85 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,56 +1,56
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 QAREALEGENDMARKER_H
21 #ifndef QAREALEGENDMARKER_H
22 #define QAREALEGENDMARKER_H
22 #define QAREALEGENDMARKER_H
23
23
24 #include <QChartGlobal>
24 #include <QChartGlobal>
25 #include <QLegendMarker>
25 #include <QLegendMarker>
26 #include <QAreaSeries>
26 #include <QAreaSeries>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 class QAreaLegendMarkerPrivate;
30 class QAreaLegendMarkerPrivate;
31
31
32 class QTCOMMERCIALCHART_EXPORT QAreaLegendMarker : public QLegendMarker
32 class QTCOMMERCIALCHART_EXPORT QAreaLegendMarker : public QLegendMarker
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35
35
36 public:
36 public:
37 explicit QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent = 0);
37 explicit QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent = 0);
38 virtual ~QAreaLegendMarker();
38 virtual ~QAreaLegendMarker();
39
39
40 virtual LegendMarkerType type() { return LegendMarkerTypeArea; }
40 virtual LegendMarkerType type() { return LegendMarkerTypeArea; }
41
41
42 // Related series
42 // Related series
43 virtual QAreaSeries* series();
43 virtual QAreaSeries* series();
44
44
45 protected:
45 protected:
46 QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent = 0);
46 QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent = 0);
47
47
48 private:
48 private:
49 Q_DECLARE_PRIVATE(QAreaLegendMarker)
49 Q_DECLARE_PRIVATE(QAreaLegendMarker)
50 Q_DISABLE_COPY(QAreaLegendMarker)
50 Q_DISABLE_COPY(QAreaLegendMarker)
51
51
52 };
52 };
53
53
54 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
55
55
56 #endif // QAREALEGENDMARKER_H
56 #endif // QAREALEGENDMARKER_H
@@ -1,64 +1,64
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 QAREALEGENDMARKER_P_H
30 #ifndef QAREALEGENDMARKER_P_H
31 #define QAREALEGENDMARKER_P_H
31 #define QAREALEGENDMARKER_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qlegendmarker_p.h"
34 #include "qlegendmarker_p.h"
35 #include "legendmarkeritem_p.h"
35 #include "legendmarkeritem_p.h"
36 #include <QAreaSeries>
36 #include <QAreaSeries>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class QAreaLegendMarker;
40 class QAreaLegendMarker;
41
41
42 class QAreaLegendMarkerPrivate : public QLegendMarkerPrivate
42 class QAreaLegendMarkerPrivate : public QLegendMarkerPrivate
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45 public:
45 public:
46 explicit QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend);
46 explicit QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend);
47 virtual ~QAreaLegendMarkerPrivate();
47 virtual ~QAreaLegendMarkerPrivate();
48
48
49 virtual QAreaSeries* series();
49 virtual QAreaSeries* series();
50 virtual QObject* relatedObject();
50 virtual QObject* relatedObject();
51
51
52 public Q_SLOTS:
52 public Q_SLOTS:
53 virtual void updated();
53 virtual void updated();
54
54
55 private:
55 private:
56 QAreaLegendMarker *q_ptr;
56 QAreaLegendMarker *q_ptr;
57 QAreaSeries* m_series;
57 QAreaSeries *m_series;
58
58
59 Q_DECLARE_PUBLIC(QAreaLegendMarker)
59 Q_DECLARE_PUBLIC(QAreaLegendMarker)
60 };
60 };
61
61
62 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
63
63
64 #endif // QAREALEGENDMARKER_P_H
64 #endif // QAREALEGENDMARKER_P_H
@@ -1,95 +1,95
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 "qbarlegendmarker.h"
21 #include "qbarlegendmarker.h"
22 #include "qbarlegendmarker_p.h"
22 #include "qbarlegendmarker_p.h"
23 #include <QAbstractBarSeries>
23 #include <QAbstractBarSeries>
24 #include <QBarSet>
24 #include <QBarSet>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent) :
28 QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent) :
29 QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent)
29 QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent)
30 {
30 {
31 }
31 }
32
32
33 QBarLegendMarker::~QBarLegendMarker()
33 QBarLegendMarker::~QBarLegendMarker()
34 {
34 {
35 }
35 }
36
36
37 /*!
37 /*!
38 \internal
38 \internal
39 */
39 */
40 QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) :
40 QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) :
41 QLegendMarker(d, parent)
41 QLegendMarker(d, parent)
42 {
42 {
43 }
43 }
44
44
45 QAbstractBarSeries *QBarLegendMarker::series()
45 QAbstractBarSeries *QBarLegendMarker::series()
46 {
46 {
47 Q_D(QBarLegendMarker);
47 Q_D(QBarLegendMarker);
48 return d->m_series;
48 return d->m_series;
49 }
49 }
50
50
51 QBarSet* QBarLegendMarker::barset()
51 QBarSet* QBarLegendMarker::barset()
52 {
52 {
53 Q_D(QBarLegendMarker);
53 Q_D(QBarLegendMarker);
54 return d->m_barset;
54 return d->m_barset;
55 }
55 }
56
56
57 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
57 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58
58
59 QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) :
59 QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) :
60 QLegendMarkerPrivate(q,legend),
60 QLegendMarkerPrivate(q,legend),
61 m_series(series),
61 m_series(series),
62 m_barset(barset)
62 m_barset(barset)
63 {
63 {
64 QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated()));
64 QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated()));
65 QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated()));
65 QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated()));
66 QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated()));
66 QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated()));
67 updated();
67 updated();
68 }
68 }
69
69
70 QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate()
70 QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate()
71 {
71 {
72 }
72 }
73
73
74 QAbstractBarSeries* QBarLegendMarkerPrivate::series()
74 QAbstractBarSeries* QBarLegendMarkerPrivate::series()
75 {
75 {
76 return m_series;
76 return m_series;
77 }
77 }
78
78
79 QObject* QBarLegendMarkerPrivate::relatedObject()
79 QObject* QBarLegendMarkerPrivate::relatedObject()
80 {
80 {
81 return m_barset;
81 return m_barset;
82 }
82 }
83
83
84 void QBarLegendMarkerPrivate::updated()
84 void QBarLegendMarkerPrivate::updated()
85 {
85 {
86 m_item->setPen(m_barset->pen());
86 m_item->setPen(m_barset->pen());
87 m_item->setBrush(m_barset->brush());
87 m_item->setBrush(m_barset->brush());
88 m_item->setLabel(m_barset->label());
88 m_item->setLabel(m_barset->label());
89 }
89 }
90
90
91 #include "moc_qbarlegendmarker.cpp"
91 #include "moc_qbarlegendmarker.cpp"
92 #include "moc_qbarlegendmarker_p.cpp"
92 #include "moc_qbarlegendmarker_p.cpp"
93
93
94 QTCOMMERCIALCHART_END_NAMESPACE
94 QTCOMMERCIALCHART_END_NAMESPACE
95
95
@@ -1,57 +1,57
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 #ifndef QBARLEGENDMARKER_H
20 #ifndef QBARLEGENDMARKER_H
21 #define QBARLEGENDMARKER_H
21 #define QBARLEGENDMARKER_H
22
22
23 #include <QChartGlobal>
23 #include <QChartGlobal>
24 #include <QLegendMarker>
24 #include <QLegendMarker>
25 #include <QAbstractBarSeries>
25 #include <QAbstractBarSeries>
26 #include <QBarSet>
26 #include <QBarSet>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 class QLegend;
30 class QLegend;
31 class QBarLegendMarkerPrivate;
31 class QBarLegendMarkerPrivate;
32
32
33 class QTCOMMERCIALCHART_EXPORT QBarLegendMarker : public QLegendMarker
33 class QTCOMMERCIALCHART_EXPORT QBarLegendMarker : public QLegendMarker
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 public:
36 public:
37 explicit QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent = 0);
37 explicit QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent = 0);
38 virtual ~QBarLegendMarker();
38 virtual ~QBarLegendMarker();
39
39
40 virtual LegendMarkerType type() { return LegendMarkerTypeBar; }
40 virtual LegendMarkerType type() { return LegendMarkerTypeBar; }
41
41
42 // Related series and barset
42 // Related series and barset
43 virtual QAbstractBarSeries* series();
43 virtual QAbstractBarSeries* series();
44 QBarSet* barset();
44 QBarSet* barset();
45
45
46 protected:
46 protected:
47 QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent = 0);
47 QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent = 0);
48
48
49 private:
49 private:
50 Q_DECLARE_PRIVATE(QBarLegendMarker)
50 Q_DECLARE_PRIVATE(QBarLegendMarker)
51 Q_DISABLE_COPY(QBarLegendMarker)
51 Q_DISABLE_COPY(QBarLegendMarker)
52
52
53 };
53 };
54
54
55 QTCOMMERCIALCHART_END_NAMESPACE
55 QTCOMMERCIALCHART_END_NAMESPACE
56
56
57 #endif // QBARLEGENDMARKER_H
57 #endif // QBARLEGENDMARKER_H
@@ -1,66 +1,66
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 QBARLEGENDMARKER_P_H
30 #ifndef QBARLEGENDMARKER_P_H
31 #define QBARLEGENDMARKER_P_H
31 #define QBARLEGENDMARKER_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qlegendmarker_p.h"
34 #include "qlegendmarker_p.h"
35 #include "legendmarkeritem_p.h"
35 #include "legendmarkeritem_p.h"
36 #include <QAbstractBarSeries>
36 #include <QAbstractBarSeries>
37 #include <QBarSet>
37 #include <QBarSet>
38
38
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40
40
41 class QBarLegendMarker;
41 class QBarLegendMarker;
42
42
43 class QBarLegendMarkerPrivate : public QLegendMarkerPrivate
43 class QBarLegendMarkerPrivate : public QLegendMarkerPrivate
44 {
44 {
45 Q_OBJECT
45 Q_OBJECT
46 public:
46 public:
47 explicit QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend);
47 explicit QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend);
48 virtual ~QBarLegendMarkerPrivate();
48 virtual ~QBarLegendMarkerPrivate();
49
49
50 virtual QAbstractBarSeries* series();
50 virtual QAbstractBarSeries* series();
51 virtual QObject* relatedObject();
51 virtual QObject* relatedObject();
52
52
53 public Q_SLOTS:
53 public Q_SLOTS:
54 virtual void updated();
54 virtual void updated();
55
55
56 private:
56 private:
57 QBarLegendMarker *q_ptr;
57 QBarLegendMarker *q_ptr;
58 QAbstractBarSeries* m_series;
58 QAbstractBarSeries *m_series;
59 QBarSet* m_barset;
59 QBarSet *m_barset;
60
60
61 Q_DECLARE_PUBLIC(QBarLegendMarker)
61 Q_DECLARE_PUBLIC(QBarLegendMarker)
62 };
62 };
63
63
64 QTCOMMERCIALCHART_END_NAMESPACE
64 QTCOMMERCIALCHART_END_NAMESPACE
65
65
66 #endif // QBARLEGENDMARKER_P_H
66 #endif // QBARLEGENDMARKER_P_H
@@ -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
475 void QLegendPrivate::addSeries(QAbstractSeries* series)
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
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; }
59 void addSeries(QAbstractSeries *series);
60 void addSeries(QAbstractSeries* series);
60 void removeSeries(QAbstractSeries *series);
61 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;
90 QList<QLegendMarker *> m_markers;
92 friend class LegendLayout;
91 QList<QAbstractSeries *> m_series;
93 QList<QLegendMarker*> m_markers;
94 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,85 +1,85
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 QLEGENDMARKERPRIVATE_H
30 #ifndef QLEGENDMARKERPRIVATE_H
31 #define QLEGENDMARKERPRIVATE_H
31 #define QLEGENDMARKERPRIVATE_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QGraphicsObject>
34 #include <QGraphicsObject>
35 #include <QBrush>
35 #include <QBrush>
36 #include <QPen>
36 #include <QPen>
37 #include <QGraphicsSimpleTextItem>
37 #include <QGraphicsSimpleTextItem>
38 #include <QGraphicsLayoutItem>
38 #include <QGraphicsLayoutItem>
39
39
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41
41
42 // TODO: check these
42 // TODO: check these
43 class QAbstractSeries;
43 class QAbstractSeries;
44 class QAreaSeries;
44 class QAreaSeries;
45 class QXYSeries;
45 class QXYSeries;
46 class QBarSet;
46 class QBarSet;
47 class QAbstractBarSeries;
47 class QAbstractBarSeries;
48 class QPieSlice;
48 class QPieSlice;
49 class QLegend;
49 class QLegend;
50 class QPieSeries;
50 class QPieSeries;
51
51
52 class QLegendMarker;
52 class QLegendMarker;
53 class LegendMarkerItem;
53 class LegendMarkerItem;
54
54
55 class QLegendMarkerPrivate : public QObject
55 class QLegendMarkerPrivate : public QObject
56 {
56 {
57 Q_OBJECT
57 Q_OBJECT
58 public:
58 public:
59 explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend);
59 explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend);
60 virtual ~QLegendMarkerPrivate();
60 virtual ~QLegendMarkerPrivate();
61
61
62 // Helper for now. (or declare LegendLayout as friend)
62 // Helper for now. (or declare LegendLayout as friend)
63 LegendMarkerItem* item() const { return m_item; }
63 LegendMarkerItem* item() const { return m_item; }
64
64
65 virtual QAbstractSeries* series() = 0;
65 virtual QAbstractSeries* series() = 0;
66 virtual QObject* relatedObject() = 0;
66 virtual QObject* relatedObject() = 0;
67
67
68 public Q_SLOTS:
68 public Q_SLOTS:
69 virtual void updated() {};
69 virtual void updated() {};
70
70
71 protected:
71 protected:
72 LegendMarkerItem *m_item;
72 LegendMarkerItem *m_item;
73 QLegend* m_legend;
73 QLegend *m_legend;
74
74
75 private:
75 private:
76 QLegendMarker *q_ptr;
76 QLegendMarker *q_ptr;
77
77
78 friend class QLegendPrivate;
78 friend class QLegendPrivate;
79 friend class LegendMarkerItem;
79 friend class LegendMarkerItem;
80 Q_DECLARE_PUBLIC(QLegendMarker)
80 Q_DECLARE_PUBLIC(QLegendMarker)
81 };
81 };
82
82
83 QTCOMMERCIALCHART_END_NAMESPACE
83 QTCOMMERCIALCHART_END_NAMESPACE
84
84
85 #endif // QLEGENDMARKERPRIVATE_H
85 #endif // QLEGENDMARKERPRIVATE_H
@@ -1,94 +1,94
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 "qpielegendmarker.h"
21 #include "qpielegendmarker.h"
22 #include "qpielegendmarker_p.h"
22 #include "qpielegendmarker_p.h"
23 #include <QPieSeries>
23 #include <QPieSeries>
24 #include <QPieSlice>
24 #include <QPieSlice>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent) :
28 QPieLegendMarker::QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent) :
29 QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent)
29 QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent)
30 {
30 {
31 }
31 }
32
32
33 QPieLegendMarker::~QPieLegendMarker()
33 QPieLegendMarker::~QPieLegendMarker()
34 {
34 {
35 }
35 }
36
36
37 /*!
37 /*!
38 \internal
38 \internal
39 */
39 */
40 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
40 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
41 QLegendMarker(d, parent)
41 QLegendMarker(d, parent)
42 {
42 {
43 }
43 }
44
44
45 QPieSeries* QPieLegendMarker::series()
45 QPieSeries* QPieLegendMarker::series()
46 {
46 {
47 Q_D(QPieLegendMarker);
47 Q_D(QPieLegendMarker);
48 return d->m_series;
48 return d->m_series;
49 }
49 }
50
50
51 QPieSlice* QPieLegendMarker::slice()
51 QPieSlice* QPieLegendMarker::slice()
52 {
52 {
53 Q_D(QPieLegendMarker);
53 Q_D(QPieLegendMarker);
54 return d->m_slice;
54 return d->m_slice;
55 }
55 }
56
56
57 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
57 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58
58
59 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) :
59 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) :
60 QLegendMarkerPrivate(q,legend),
60 QLegendMarkerPrivate(q,legend),
61 m_series(series),
61 m_series(series),
62 m_slice(slice)
62 m_slice(slice)
63 {
63 {
64 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
64 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
65 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
65 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
66 QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated()));
66 QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated()));
67 updated();
67 updated();
68 }
68 }
69
69
70 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
70 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
71 {
71 {
72 }
72 }
73
73
74 QPieSeries* QPieLegendMarkerPrivate::series()
74 QPieSeries* QPieLegendMarkerPrivate::series()
75 {
75 {
76 return m_series;
76 return m_series;
77 }
77 }
78
78
79 QObject* QPieLegendMarkerPrivate::relatedObject()
79 QObject* QPieLegendMarkerPrivate::relatedObject()
80 {
80 {
81 return m_slice;
81 return m_slice;
82 }
82 }
83
83
84 void QPieLegendMarkerPrivate::updated()
84 void QPieLegendMarkerPrivate::updated()
85 {
85 {
86 m_item->setPen(m_slice->pen());
86 m_item->setPen(m_slice->pen());
87 m_item->setBrush(m_slice->brush());
87 m_item->setBrush(m_slice->brush());
88 m_item->setLabel(m_slice->label());
88 m_item->setLabel(m_slice->label());
89 }
89 }
90
90
91 #include "moc_qpielegendmarker.cpp"
91 #include "moc_qpielegendmarker.cpp"
92 #include "moc_qpielegendmarker_p.cpp"
92 #include "moc_qpielegendmarker_p.cpp"
93
93
94 QTCOMMERCIALCHART_END_NAMESPACE
94 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,57 +1,57
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 QPIELEGENDMARKER_H
21 #ifndef QPIELEGENDMARKER_H
22 #define QPIELEGENDMARKER_H
22 #define QPIELEGENDMARKER_H
23
23
24 #include <QChartGlobal>
24 #include <QChartGlobal>
25 #include <QLegendMarker>
25 #include <QLegendMarker>
26 #include <QPieSeries>
26 #include <QPieSeries>
27 #include <QPieSlice>
27 #include <QPieSlice>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QPieLegendMarkerPrivate;
31 class QPieLegendMarkerPrivate;
32
32
33 class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker
33 class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36
36
37 public:
37 public:
38 explicit QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent = 0);
38 explicit QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent = 0);
39 virtual ~QPieLegendMarker();
39 virtual ~QPieLegendMarker();
40
40
41 virtual LegendMarkerType type() { return LegendMarkerTypePie; }
41 virtual LegendMarkerType type() { return LegendMarkerTypePie; }
42
42
43 // Related series and slice
43 // Related series and slice
44 virtual QPieSeries* series();
44 virtual QPieSeries* series();
45 QPieSlice* slice();
45 QPieSlice* slice();
46
46
47 protected:
47 protected:
48 QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent = 0);
48 QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent = 0);
49
49
50 private:
50 private:
51 Q_DECLARE_PRIVATE(QPieLegendMarker)
51 Q_DECLARE_PRIVATE(QPieLegendMarker)
52 Q_DISABLE_COPY(QPieLegendMarker)
52 Q_DISABLE_COPY(QPieLegendMarker)
53
53
54 };
54 };
55
55
56 QTCOMMERCIALCHART_END_NAMESPACE
56 QTCOMMERCIALCHART_END_NAMESPACE
57 #endif // QPIELEGENDMARKER_H
57 #endif // QPIELEGENDMARKER_H
@@ -1,68 +1,68
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 QPIELEGENDMARKER_P_H
30 #ifndef QPIELEGENDMARKER_P_H
31 #define QPIELEGENDMARKER_P_H
31 #define QPIELEGENDMARKER_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qlegendmarker_p.h"
34 #include "qlegendmarker_p.h"
35 #include "legendmarkeritem_p.h"
35 #include "legendmarkeritem_p.h"
36 #include <QPieSeries>
36 #include <QPieSeries>
37 #include <QPieSlice>
37 #include <QPieSlice>
38
38
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40
40
41 class QPieLegendMarker;
41 class QPieLegendMarker;
42
42
43 class QPieLegendMarkerPrivate : public QLegendMarkerPrivate
43 class QPieLegendMarkerPrivate : public QLegendMarkerPrivate
44 {
44 {
45 Q_OBJECT
45 Q_OBJECT
46 public:
46 public:
47 explicit QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend);
47 explicit QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend);
48 virtual ~QPieLegendMarkerPrivate();
48 virtual ~QPieLegendMarkerPrivate();
49
49
50 // internal
50 // internal
51 virtual QPieSeries* series();
51 virtual QPieSeries* series();
52 virtual QObject* relatedObject();
52 virtual QObject* relatedObject();
53
53
54 public Q_SLOTS:
54 public Q_SLOTS:
55 virtual void updated();
55 virtual void updated();
56
56
57 private:
57 private:
58 QPieLegendMarker *q_ptr;
58 QPieLegendMarker *q_ptr;
59
59
60 QPieSeries* m_series;
60 QPieSeries *m_series;
61 QPieSlice* m_slice;
61 QPieSlice *m_slice;
62
62
63 Q_DECLARE_PUBLIC(QPieLegendMarker)
63 Q_DECLARE_PUBLIC(QPieLegendMarker)
64 };
64 };
65
65
66 QTCOMMERCIALCHART_END_NAMESPACE
66 QTCOMMERCIALCHART_END_NAMESPACE
67
67
68 #endif // QPIELEGENDMARKER_P_H
68 #endif // QPIELEGENDMARKER_P_H
@@ -1,91 +1,91
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 "qxylegendmarker.h"
21 #include "qxylegendmarker.h"
22 #include "qxylegendmarker_p.h"
22 #include "qxylegendmarker_p.h"
23 #include "qxyseries_p.h"
23 #include "qxyseries_p.h"
24 #include <QXYSeries>
24 #include <QXYSeries>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 QXYLegendMarker::QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent) :
28 QXYLegendMarker::QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent) :
29 QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent)
29 QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent)
30 {
30 {
31 }
31 }
32
32
33 QXYLegendMarker::~QXYLegendMarker()
33 QXYLegendMarker::~QXYLegendMarker()
34 {
34 {
35 }
35 }
36
36
37 /*!
37 /*!
38 \internal
38 \internal
39 */
39 */
40 QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) :
40 QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) :
41 QLegendMarker(d, parent)
41 QLegendMarker(d, parent)
42 {
42 {
43 }
43 }
44
44
45 QXYSeries* QXYLegendMarker::series()
45 QXYSeries* QXYLegendMarker::series()
46 {
46 {
47 Q_D(QXYLegendMarker);
47 Q_D(QXYLegendMarker);
48 return d->m_series;
48 return d->m_series;
49 }
49 }
50
50
51 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
51 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52
52
53 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
53 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
54 QLegendMarkerPrivate(q,legend),
54 QLegendMarkerPrivate(q,legend),
55 m_series(series)
55 m_series(series)
56 {
56 {
57 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
57 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
58 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
58 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
59 updated();
59 updated();
60 }
60 }
61
61
62 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
62 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
63 {
63 {
64 }
64 }
65
65
66 QAbstractSeries* QXYLegendMarkerPrivate::series()
66 QAbstractSeries* QXYLegendMarkerPrivate::series()
67 {
67 {
68 return m_series;
68 return m_series;
69 }
69 }
70
70
71 QObject* QXYLegendMarkerPrivate::relatedObject()
71 QObject* QXYLegendMarkerPrivate::relatedObject()
72 {
72 {
73 return m_series;
73 return m_series;
74 }
74 }
75
75
76 void QXYLegendMarkerPrivate::updated()
76 void QXYLegendMarkerPrivate::updated()
77 {
77 {
78 m_item->setLabel(m_series->name());
78 m_item->setLabel(m_series->name());
79
79
80 if (m_series->type()== QAbstractSeries::SeriesTypeScatter) {
80 if (m_series->type()== QAbstractSeries::SeriesTypeScatter) {
81 m_item->setBrush(m_series->brush());
81 m_item->setBrush(m_series->brush());
82 } else {
82 } else {
83 m_item->setBrush(QBrush(m_series->pen().color()));
83 m_item->setBrush(QBrush(m_series->pen().color()));
84 }
84 }
85 }
85 }
86
86
87 #include "moc_qxylegendmarker.cpp"
87 #include "moc_qxylegendmarker.cpp"
88 #include "moc_qxylegendmarker_p.cpp"
88 #include "moc_qxylegendmarker_p.cpp"
89
89
90 QTCOMMERCIALCHART_END_NAMESPACE
90 QTCOMMERCIALCHART_END_NAMESPACE
91
91
@@ -1,55 +1,55
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 QXYLEGENDMARKER_H
21 #ifndef QXYLEGENDMARKER_H
22 #define QXYLEGENDMARKER_H
22 #define QXYLEGENDMARKER_H
23
23
24 #include <QChartGlobal>
24 #include <QChartGlobal>
25 #include <QLegendMarker>
25 #include <QLegendMarker>
26 #include <QXYSeries>
26 #include <QXYSeries>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 class QXYLegendMarkerPrivate;
30 class QXYLegendMarkerPrivate;
31
31
32 class QTCOMMERCIALCHART_EXPORT QXYLegendMarker : public QLegendMarker
32 class QTCOMMERCIALCHART_EXPORT QXYLegendMarker : public QLegendMarker
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35 public:
35 public:
36 explicit QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent = 0);
36 explicit QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent = 0);
37 virtual ~QXYLegendMarker();
37 virtual ~QXYLegendMarker();
38
38
39 virtual LegendMarkerType type() { return LegendMarkerTypeXY; }
39 virtual LegendMarkerType type() { return LegendMarkerTypeXY; }
40
40
41 // Related series
41 // Related series
42 virtual QXYSeries* series();
42 virtual QXYSeries* series();
43
43
44 protected:
44 protected:
45 QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent = 0);
45 QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent = 0);
46
46
47 private:
47 private:
48 Q_DECLARE_PRIVATE(QXYLegendMarker)
48 Q_DECLARE_PRIVATE(QXYLegendMarker)
49 Q_DISABLE_COPY(QXYLegendMarker)
49 Q_DISABLE_COPY(QXYLegendMarker)
50
50
51 };
51 };
52
52
53 QTCOMMERCIALCHART_END_NAMESPACE
53 QTCOMMERCIALCHART_END_NAMESPACE
54
54
55 #endif // QXYLEGENDMARKER_H
55 #endif // QXYLEGENDMARKER_H
@@ -1,64 +1,64
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 QXYLEGENDMARKER_P_H
30 #ifndef QXYLEGENDMARKER_P_H
31 #define QXYLEGENDMARKER_P_H
31 #define QXYLEGENDMARKER_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qlegendmarker_p.h"
34 #include "qlegendmarker_p.h"
35 #include "legendmarkeritem_p.h"
35 #include "legendmarkeritem_p.h"
36 #include <QXYSeries>
36 #include <QXYSeries>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class QXYLegendMarker;
40 class QXYLegendMarker;
41
41
42 class QXYLegendMarkerPrivate : public QLegendMarkerPrivate
42 class QXYLegendMarkerPrivate : public QLegendMarkerPrivate
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45 public:
45 public:
46 explicit QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend);
46 explicit QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend);
47 virtual ~QXYLegendMarkerPrivate();
47 virtual ~QXYLegendMarkerPrivate();
48
48
49 virtual QAbstractSeries* series();
49 virtual QAbstractSeries* series();
50 virtual QObject* relatedObject();
50 virtual QObject* relatedObject();
51
51
52 public Q_SLOTS:
52 public Q_SLOTS:
53 virtual void updated();
53 virtual void updated();
54
54
55 private:
55 private:
56 QXYLegendMarker *q_ptr;
56 QXYLegendMarker *q_ptr;
57 QXYSeries* m_series;
57 QXYSeries *m_series;
58
58
59 Q_DECLARE_PUBLIC(QXYLegendMarker)
59 Q_DECLARE_PUBLIC(QXYLegendMarker)
60 };
60 };
61
61
62 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
63
63
64 #endif // QXYLEGENDMARKER_P_H
64 #endif // QXYLEGENDMARKER_P_H
General Comments 0
You need to be logged in to leave comments. Login now