##// 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 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "legendlayout_p.h"
22 22 #include "chartpresenter_p.h"
23 23 #include "qlegend_p.h"
24 24 #include "chartlayout_p.h"
25 25
26 26 #include "qlegendmarker_p.h"
27 27 #include "legendmarkeritem_p.h"
28 28 #include "qlegendmarker.h"
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 LegendLayout::LegendLayout(QLegend *legend)
33 33 : m_legend(legend)
34 34 {
35 35
36 36 }
37 37
38 38 LegendLayout::~LegendLayout()
39 39 {
40 40
41 41 }
42 42
43 43 void LegendLayout::setOffset(qreal x, qreal y)
44 44 {
45 45 bool scrollHorizontal = true;
46 46 switch (m_legend->alignment()) {
47 47 case Qt::AlignTop:
48 48 case Qt::AlignBottom:
49 49 scrollHorizontal = true;
50 50 break;
51 51 case Qt::AlignLeft:
52 52 case Qt::AlignRight:
53 53 scrollHorizontal = false;
54 54 break;
55 55 }
56 56
57 57 // If detached, the scrolling direction is vertical instead of horizontal and vice versa.
58 58 if (!m_legend->isAttachedToChart())
59 59 scrollHorizontal = !scrollHorizontal;
60 60
61 61 QRectF boundingRect = geometry();
62 62 qreal left, top, right, bottom;
63 63 getContentsMargins(&left, &top, &right, &bottom);
64 64 boundingRect.adjust(left, top, -right, -bottom);
65 65
66 66 // Limit offset between m_minOffset and m_maxOffset
67 67 if (scrollHorizontal) {
68 68 if (m_width <= boundingRect.width())
69 69 return;
70 70
71 71 if (x != m_offsetX) {
72 72 m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
73 73 m_legend->d_ptr->items()->setPos(-m_offsetX, boundingRect.top());
74 74 }
75 75 } else {
76 76 if (m_height <= boundingRect.height())
77 77 return;
78 78
79 79 if (y != m_offsetY) {
80 80 m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
81 81 m_legend->d_ptr->items()->setPos(boundingRect.left(), -m_offsetY);
82 82 }
83 83 }
84 84 }
85 85
86 86 QPointF LegendLayout::offset() const
87 87 {
88 88 return QPointF(m_offsetX, m_offsetY);
89 89 }
90 90
91 91 void LegendLayout::invalidate()
92 92 {
93 93 QGraphicsLayout::invalidate();
94 94 if (m_legend->isAttachedToChart())
95 95 m_legend->d_ptr->m_presenter->layout()->invalidate();
96 96 }
97 97
98 98 void LegendLayout::setGeometry(const QRectF &rect)
99 99 {
100 100 m_legend->d_ptr->items()->setVisible(m_legend->isVisible());
101 101
102 102 QGraphicsLayout::setGeometry(rect);
103 103
104 104 if (m_legend->isAttachedToChart())
105 105 setAttachedGeometry(rect);
106 106 else
107 107 setDettachedGeometry(rect);
108 108 }
109 109
110 110 void LegendLayout::setAttachedGeometry(const QRectF &rect)
111 111 {
112 112 if (!rect.isValid())
113 113 return;
114 114
115 115 m_offsetX = 0;
116 116 m_offsetY = 0;
117 117
118 118 QSizeF size(0, 0);
119 119
120 120 if (m_legend->d_ptr->markers().isEmpty()) {
121 121 return;
122 122 }
123 123
124 124 m_width = 0;
125 125 m_height = 0;
126 126
127 127 qreal left, top, right, bottom;
128 128 getContentsMargins(&left, &top, &right, &bottom);
129 129
130 130 QRectF geometry = rect.adjusted(left, top, -right, -bottom);
131 131
132 132 switch(m_legend->alignment()) {
133 133 case Qt::AlignTop:
134 134 case Qt::AlignBottom: {
135 135 QPointF point(0,0);
136 foreach (QLegendMarker* marker, m_legend->d_ptr->markers()) {
137 LegendMarkerItem* item = marker->d_ptr->item();
136 foreach (QLegendMarker *marker, m_legend->d_ptr->markers()) {
137 LegendMarkerItem *item = marker->d_ptr->item();
138 138 if (item->isVisible()) {
139 139 item->setGeometry(geometry);
140 140 item->setPos(point.x(),geometry.height()/2 - item->boundingRect().height()/2);
141 const QRectF& rect = item->boundingRect();
141 const QRectF &rect = item->boundingRect();
142 142 size = size.expandedTo(rect.size());
143 143 qreal w = rect.width();
144 144 m_width+=w;
145 145 point.setX(point.x() + w);
146 146 }
147 147 }
148 148 if (m_width < geometry.width())
149 149 m_legend->d_ptr->items()->setPos(geometry.width() / 2 - m_width / 2, geometry.top());
150 150 else
151 151 m_legend->d_ptr->items()->setPos(geometry.topLeft());
152 152 m_height = size.height();
153 153 }
154 154 break;
155 155 case Qt::AlignLeft:
156 156 case Qt::AlignRight: {
157 157 QPointF point(0,0);
158 foreach (QLegendMarker* marker, m_legend->d_ptr->markers()) {
159 LegendMarkerItem* item = marker->d_ptr->item();
158 foreach (QLegendMarker *marker, m_legend->d_ptr->markers()) {
159 LegendMarkerItem *item = marker->d_ptr->item();
160 160 if (item->isVisible()) {
161 161 item->setGeometry(geometry);
162 162 item->setPos(point);
163 const QRectF& rect = item->boundingRect();
163 const QRectF &rect = item->boundingRect();
164 164 qreal h = rect.height();
165 165 size = size.expandedTo(rect.size());
166 166 m_height+=h;
167 167 point.setY(point.y() + h);
168 168 }
169 169 }
170 170
171 171 if (m_height < geometry.height())
172 172 m_legend->d_ptr->items()->setPos(geometry.left(), geometry.height() / 2 - m_height / 2);
173 173 else
174 174 m_legend->d_ptr->items()->setPos(geometry.topLeft());
175 175 m_width = size.width();
176 176 break;
177 177 }
178 178 }
179 179
180 180 m_minOffsetX = -left;
181 181 m_minOffsetY = - top;
182 182 m_maxOffsetX = m_width - geometry.width() - right;
183 183 m_maxOffsetY = m_height - geometry.height() - bottom;
184 184 }
185 185
186 186 void LegendLayout::setDettachedGeometry(const QRectF &rect)
187 187 {
188 188 if (!rect.isValid())
189 189 return;
190 190
191 191 // Detached layout is different.
192 192 // In detached mode legend may have multiple rows and columns, so layout calculations
193 193 // differ a log from attached mode.
194 194 // Also the scrolling logic is bit different.
195 195
196 196 m_offsetX = 0;
197 197 m_offsetY = 0;
198 198
199 199 qreal left, top, right, bottom;
200 200 getContentsMargins(&left, &top, &right, &bottom);
201 201 QRectF geometry = rect.adjusted(left, top, -right, -bottom);
202 202
203 203 QSizeF size(0, 0);
204 204
205 205 QList<QLegendMarker *> markers = m_legend->d_ptr->markers();
206 206
207 207 if (markers.isEmpty())
208 208 return;
209 209
210 210 switch (m_legend->alignment()) {
211 211 case Qt::AlignTop: {
212 212 QPointF point(0, 0);
213 213 m_width = 0;
214 214 m_height = 0;
215 215 for (int i = 0; i < markers.count(); i++) {
216 216 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
217 217 if (item->isVisible()) {
218 218 item->setGeometry(geometry);
219 219 item->setPos(point.x(),point.y());
220 const QRectF& boundingRect = item->boundingRect();
220 const QRectF &boundingRect = item->boundingRect();
221 221 qreal w = boundingRect.width();
222 222 qreal h = boundingRect.height();
223 223 m_width = qMax(m_width,w);
224 224 m_height = qMax(m_height,h);
225 225 point.setX(point.x() + w);
226 226 if (point.x() + w > geometry.left() + geometry.width() - right) {
227 227 // Next item would go off rect.
228 228 point.setX(0);
229 229 point.setY(point.y() + h);
230 230 if (i+1 < markers.count()) {
231 231 m_height += h;
232 232 }
233 233 }
234 234 }
235 235 }
236 236 m_legend->d_ptr->items()->setPos(geometry.topLeft());
237 237
238 238 m_minOffsetX = -left;
239 239 m_minOffsetY = -top;
240 240 m_maxOffsetX = m_width - geometry.width() - right;
241 241 m_maxOffsetY = m_height - geometry.height() - bottom;
242 242 }
243 243 break;
244 244 case Qt::AlignBottom: {
245 245 QPointF point(0, geometry.height());
246 246 m_width = 0;
247 247 m_height = 0;
248 248 for (int i = 0; i < markers.count(); i++) {
249 249 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
250 250 if (item->isVisible()) {
251 251 item->setGeometry(geometry);
252 const QRectF& boundingRect = item->boundingRect();
252 const QRectF &boundingRect = item->boundingRect();
253 253 qreal w = boundingRect.width();
254 254 qreal h = boundingRect.height();
255 255 m_width = qMax(m_width,w);
256 256 m_height = qMax(m_height,h);
257 257 item->setPos(point.x(),point.y() - h);
258 258 point.setX(point.x() + w);
259 259 if (point.x() + w > geometry.left() + geometry.width() - right) {
260 260 // Next item would go off rect.
261 261 point.setX(0);
262 262 point.setY(point.y() - h);
263 263 if (i+1 < markers.count()) {
264 264 m_height += h;
265 265 }
266 266 }
267 267 }
268 268 }
269 269 m_legend->d_ptr->items()->setPos(geometry.topLeft());
270 270
271 271 m_minOffsetX = -left;
272 272 m_minOffsetY = -m_height + geometry.height() - top;
273 273 m_maxOffsetX = m_width - geometry.width() - right;
274 274 m_maxOffsetY = -bottom;
275 275 }
276 276 break;
277 277 case Qt::AlignLeft: {
278 278 QPointF point(0, 0);
279 279 m_width = 0;
280 280 m_height = 0;
281 281 qreal maxWidth = 0;
282 282 for (int i = 0; i < markers.count(); i++) {
283 283 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
284 284 if (item->isVisible()) {
285 285 item->setGeometry(geometry);
286 const QRectF& boundingRect = item->boundingRect();
286 const QRectF &boundingRect = item->boundingRect();
287 287 qreal w = boundingRect.width();
288 288 qreal h = boundingRect.height();
289 289 m_height = qMax(m_height,h);
290 290 maxWidth = qMax(maxWidth,w);
291 291 item->setPos(point.x(),point.y());
292 292 point.setY(point.y() + h);
293 293 if (point.y() + h > geometry.bottom() - bottom) {
294 294 // Next item would go off rect.
295 295 point.setX(point.x() + maxWidth);
296 296 point.setY(0);
297 297 if (i+1 < markers.count()) {
298 298 m_width += maxWidth;
299 299 maxWidth = 0;
300 300 }
301 301 }
302 302 }
303 303 }
304 304 m_width += maxWidth;
305 305 m_legend->d_ptr->items()->setPos(geometry.topLeft());
306 306
307 307 m_minOffsetX = -left;
308 308 m_minOffsetY = -top;
309 309 m_maxOffsetX = m_width - geometry.width() - right;
310 310 m_maxOffsetY = m_height - geometry.height() - bottom;
311 311 }
312 312 break;
313 313 case Qt::AlignRight: {
314 314 QPointF point(geometry.width(), 0);
315 315 m_width = 0;
316 316 m_height = 0;
317 317 qreal maxWidth = 0;
318 318 for (int i = 0; i < markers.count(); i++) {
319 319 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
320 320 if (item->isVisible()) {
321 321 item->setGeometry(geometry);
322 const QRectF& boundingRect = item->boundingRect();
322 const QRectF &boundingRect = item->boundingRect();
323 323 qreal w = boundingRect.width();
324 324 qreal h = boundingRect.height();
325 325 m_height = qMax(m_height,h);
326 326 maxWidth = qMax(maxWidth,w);
327 327 item->setPos(point.x() - w,point.y());
328 328 point.setY(point.y() + h);
329 329 if (point.y() + h > geometry.bottom()-bottom) {
330 330 // Next item would go off rect.
331 331 point.setX(point.x() - maxWidth);
332 332 point.setY(0);
333 333 if (i+1 < markers.count()) {
334 334 m_width += maxWidth;
335 335 maxWidth = 0;
336 336 }
337 337 }
338 338 }
339 339 }
340 340 m_width += maxWidth;
341 341 m_legend->d_ptr->items()->setPos(geometry.topLeft());
342 342
343 343 m_minOffsetX = - m_width + geometry.width() - left;
344 344 m_minOffsetY = -top;
345 345 m_maxOffsetX = - right;
346 346 m_maxOffsetY = m_height - geometry.height() - bottom;
347 347 }
348 348 break;
349 349 default:
350 350 break;
351 351 }
352 352
353 353 }
354 354
355 355 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
356 356 {
357 357 QSizeF size(0, 0);
358 358 qreal left, top, right, bottom;
359 359 getContentsMargins(&left, &top, &right, &bottom);
360 360
361 361 if(constraint.isValid()) {
362 foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) {
362 foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) {
363 363 LegendMarkerItem *item = marker->d_ptr->item();
364 364 size = size.expandedTo(item->effectiveSizeHint(which));
365 365 }
366 366 size = size.boundedTo(constraint);
367 367 }
368 368 else if (constraint.width() >= 0) {
369 369 qreal width = 0;
370 370 qreal height = 0;
371 foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) {
371 foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) {
372 372 LegendMarkerItem *item = marker->d_ptr->item();
373 373 width+=item->effectiveSizeHint(which).width();
374 374 height=qMax(height,item->effectiveSizeHint(which).height());
375 375 }
376 376
377 377 size = QSizeF(qMin(constraint.width(),width), height);
378 378 }
379 379 else if (constraint.height() >= 0) {
380 380 qreal width = 0;
381 381 qreal height = 0;
382 foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) {
382 foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) {
383 383 LegendMarkerItem *item = marker->d_ptr->item();
384 384 width=qMax(width,item->effectiveSizeHint(which).width());
385 385 height+=height,item->effectiveSizeHint(which).height();
386 386 }
387 387 size = QSizeF(width,qMin(constraint.height(),height));
388 388 }
389 389 else {
390 foreach(QLegendMarker* marker, m_legend->d_ptr->markers()) {
390 foreach(QLegendMarker *marker, m_legend->d_ptr->markers()) {
391 391 LegendMarkerItem *item = marker->d_ptr->item();
392 392 size = size.expandedTo(item->effectiveSizeHint(which));
393 393 }
394 394 }
395 395 size += QSize(left + right, top + bottom);
396 396 return size;
397 397 }
398 398
399 399 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,196 +1,196
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QPainter>
22 22 #include <QGraphicsSceneEvent>
23 23 #include <QGraphicsSimpleTextItem>
24 24
25 25 #include "qlegend.h"
26 26 #include "qlegend_p.h"
27 27 #include "qlegendmarker.h"
28 28 #include "qlegendmarker_p.h"
29 29 #include "legendmarkeritem_p.h"
30 30
31 31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 32
33 33 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) :
34 34 QGraphicsObject(parent),
35 35 m_marker(marker),
36 36 m_markerRect(0,0,10.0,10.0),
37 37 m_boundingRect(0,0,0,0),
38 38 m_textItem(new QGraphicsSimpleTextItem(this)),
39 39 m_rectItem(new QGraphicsRectItem(this)),
40 40 m_margin(4),
41 41 m_space(4),
42 42 m_pressPos(0, 0)
43 43 {
44 44 m_rectItem->setRect(m_markerRect);
45 45 }
46 46
47 47 void LegendMarkerItem::setPen(const QPen &pen)
48 48 {
49 49 m_rectItem->setPen(pen);
50 50 }
51 51
52 52 QPen LegendMarkerItem::pen() const
53 53 {
54 54 return m_rectItem->pen();
55 55 }
56 56
57 57 void LegendMarkerItem::setBrush(const QBrush &brush)
58 58 {
59 59 m_rectItem->setBrush(brush);
60 60 }
61 61
62 62 QBrush LegendMarkerItem::brush() const
63 63 {
64 64 return m_rectItem->brush();
65 65 }
66 66
67 67 void LegendMarkerItem::setFont(const QFont &font)
68 68 {
69 69 m_textItem->setFont(font);
70 70 QFontMetrics fn(font);
71 71 m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
72 72 updateGeometry();
73 73 }
74 74
75 75 QFont LegendMarkerItem::font() const
76 76 {
77 77 return m_textItem->font();
78 78 }
79 79
80 80 void LegendMarkerItem::setLabel(const QString label)
81 81 {
82 82 m_label = label;
83 83 updateGeometry();
84 84 }
85 85
86 86 QString LegendMarkerItem::label() const
87 87 {
88 88 return m_label;
89 89 }
90 90
91 91 void LegendMarkerItem::setLabelBrush(const QBrush &brush)
92 92 {
93 93 m_textItem->setBrush(brush);
94 94 }
95 95
96 96 QBrush LegendMarkerItem::labelBrush() const
97 97 {
98 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 103 QFontMetrics fn (m_font);
104 104
105 105 int width = rect.width();
106 106 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
107 107 qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin);
108 108
109 109 if (fn.boundingRect(m_label).width() + x > width)
110 110 {
111 111 QString string = m_label + "...";
112 112 while(fn.boundingRect(string).width() + x > width && string.length() > 3)
113 113 string.remove(string.length() - 4, 1);
114 114 m_textItem->setText(string);
115 115 }
116 116 else
117 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 122 m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2);
123 123 m_rectItem->setRect(m_markerRect);
124 124 m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2);
125 125
126 126 prepareGeometryChange();
127 127 m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y);
128 128 }
129 129
130 130 QRectF LegendMarkerItem::boundingRect() const
131 131 {
132 132 return m_boundingRect;
133 133 }
134 134
135 135 void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
136 136 {
137 137 Q_UNUSED(option)
138 138 Q_UNUSED(widget)
139 139 Q_UNUSED(painter)
140 140 }
141 141
142 142 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
143 143 {
144 144 Q_UNUSED(constraint)
145 145
146 146 QFontMetrics fn(m_textItem->font());
147 147 QSizeF sh;
148 148
149 149 switch (which) {
150 150 case Qt::MinimumSize:
151 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 152 break;
153 153 case Qt::PreferredSize:
154 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 155 break;
156 156 default:
157 157 break;
158 158 }
159 159
160 160 return sh;
161 161 }
162 162
163 163 void LegendMarkerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
164 164 {
165 165 MouseEventHandler::handleMousePressEvent(event);
166 166 m_pressPos = event->screenPos();
167 167 }
168 168
169 169 void LegendMarkerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
170 170 {
171 171 MouseEventHandler::handleMouseMoveEvent(event);
172 172 }
173 173
174 174 void LegendMarkerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
175 175 {
176 176 MouseEventHandler::handleMouseReleaseEvent(event);
177 177 }
178 178
179 179 void LegendMarkerItem::mouseClicked()
180 180 {
181 181 emit m_marker->q_func()->clicked();
182 182 }
183 183
184 184 void LegendMarkerItem::mouseMoved(const QPointF &delta)
185 185 {
186 186 m_marker->m_legend->d_ptr->move(delta);
187 187 }
188 188
189 189 void LegendMarkerItem::mouseReleased(const QPointF &pos)
190 190 {
191 191 m_marker->m_legend->d_ptr->release(pos - m_pressPos);
192 192 }
193 193
194 194 #include "moc_legendmarkeritem_p.cpp"
195 195
196 196 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,112 +1,112
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef LEGENDMARKERITEM_P_H
31 31 #define LEGENDMARKERITEM_P_H
32 32
33 33 #include "qchartglobal.h"
34 34 #include <QGraphicsObject>
35 35 #include <QFont>
36 36 #include <QBrush>
37 37 #include <QPen>
38 38 #include <QGraphicsSimpleTextItem>
39 39 #include <QGraphicsLayoutItem>
40 40 #include "mouseeventhandler_p.h"
41 41
42 42 QTCOMMERCIALCHART_BEGIN_NAMESPACE
43 43
44 44 class QLegendMarkerPrivate;
45 45
46 46 class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem, public MouseEventHandler
47 47 {
48 48 Q_OBJECT
49 49 Q_INTERFACES(QGraphicsLayoutItem)
50 50 public:
51 51 explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = 0);
52 52
53 53 void setPen(const QPen &pen);
54 54 QPen pen() const;
55 55
56 56 void setBrush(const QBrush &brush);
57 57 QBrush brush() const;
58 58
59 59 void setFont(const QFont &font);
60 60 QFont font() const;
61 61
62 62 void setLabel(const QString label);
63 63 QString label() const;
64 64
65 65 void setLabelBrush(const QBrush &brush);
66 66 QBrush labelBrush() const;
67 67
68 void setGeometry(const QRectF& rect);
68 void setGeometry(const QRectF &rect);
69 69
70 70 QRectF boundingRect() const;
71 71
72 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 76 // Event handlers, logic delegated to MouseEventHandler
77 77 void mousePressEvent(QGraphicsSceneMouseEvent *event);
78 78 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
79 79 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
80 80
81 81 // Filtered callbacks from MouseEventHandler
82 82 void mouseClicked();
83 83 void mouseMoved(const QPointF &delta);
84 84 void mouseReleased(const QPointF &pos);
85 85
86 86 protected:
87 87 QLegendMarkerPrivate *m_marker; // Knows
88 88 QRectF m_markerRect;
89 89 QRectF m_boundingRect;
90 90 QGraphicsSimpleTextItem *m_textItem;
91 91 QGraphicsRectItem *m_rectItem;
92 92 qreal m_margin;
93 93 qreal m_space;
94 94 QString m_label;
95 95
96 96 QBrush m_labelBrush;
97 97 QFont m_font;
98 98 QPen m_pen;
99 99 QBrush m_brush;
100 100 bool m_visible;
101 101
102 102 QPointF m_pressPos;
103 103
104 104 friend class QLegendMarker;
105 105 friend class QLegendMarkerPrivate;
106 106 friend class LegendMarkerItem;
107 107 friend class LegendLayout;
108 108 };
109 109
110 110 QTCOMMERCIALCHART_END_NAMESPACE
111 111
112 112 #endif // LEGENDMARKERITEM_P_H
@@ -1,106 +1,106
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "mouseeventhandler_p.h"
22 22 #include <QGraphicsSceneMouseEvent>
23 23
24 24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 25
26 26 MouseEventHandler::MouseEventHandler() :
27 27 m_lastPos(0, 0),
28 28 m_state(Idle),
29 29 m_treshold(10)
30 30 {
31 31 }
32 32
33 33 MouseEventHandler::~MouseEventHandler()
34 34 {
35 35 }
36 36
37 37 void MouseEventHandler::setMoveTreshold(qreal treshold)
38 38 {
39 39 m_treshold = treshold;
40 40 }
41 41
42 void MouseEventHandler::handleMousePressEvent(QGraphicsSceneMouseEvent* event)
42 void MouseEventHandler::handleMousePressEvent(QGraphicsSceneMouseEvent *event)
43 43 {
44 44 m_lastPos = event->screenPos();
45 45 m_state = Pressed;
46 46 event->accept();
47 47 }
48 48
49 void MouseEventHandler::handleMouseMoveEvent(QGraphicsSceneMouseEvent* event)
49 void MouseEventHandler::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event)
50 50 {
51 51 QPointF delta = event->screenPos() - m_lastPos;
52 52
53 53 switch (m_state) {
54 54 case Pressed: {
55 55 // calculate treshold. If enough, change to move state and send out move deltas.
56 56 if (qAbs(delta.x()) > m_treshold || qAbs(delta.y()) > m_treshold) {
57 57 m_state = Moved;
58 58 m_lastPos = event->screenPos();
59 59 mouseMoved(delta);
60 60 }
61 61 event->accept();
62 62 break;
63 63 }
64 64 case Moved: {
65 65 m_lastPos = event->screenPos();
66 66 mouseMoved(delta);
67 67 event->accept();
68 68 break;
69 69 }
70 70 case Idle:
71 71 default: {
72 72 event->ignore();
73 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 80 m_lastPos = event->screenPos();
81 81
82 82 switch (m_state) {
83 83 case Pressed:
84 84 {
85 85 m_state = Idle;
86 86 mouseClicked();
87 87 event->accept();
88 88 break;
89 89 }
90 90 case Moved:
91 91 {
92 92 m_state = Idle;
93 93 mouseReleased(m_lastPos);
94 94 event->accept();
95 95 break;
96 96 }
97 97 default:
98 98 {
99 99 m_state = Idle;
100 100 event->ignore();
101 101 break;
102 102 }
103 103 }
104 104 }
105 105
106 106 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,89 +1,89
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 /*
31 31 Purpose of this class is to resolve what happens during MousePress - MouseMove - MouseRelease event chain.
32 32 Threre can be many MouseMove events and if they all are below our treshold, the result is clicked call.
33 33 If any move event goes over treshold, result will be many moved(QPointF delta) calls,
34 34 where delta is calculated from original position.
35 35
36 36 Reason for this is, that legend marker don't know when it should emit clicked and when it should
37 37 allow legend to scroll. We only get this information when some move goes beyond treshold, but
38 38 then it will be too late to let the scroller handle events, because marker is already handling.
39 39
40 40 By handling clicked calls in markers and moved calls in scroller, the problem is solved.
41 41 Derived class descides, should the virtual method be implemented as signal or not.
42 42
43 43 This could be implemented in LegendMarkerItem, but this way the code is reusable and in one place only.
44 44 */
45 45
46 46 #ifndef MOUSEEVENTHANDLER_H
47 47 #define MOUSEEVENTHANDLER_H
48 48
49 49 #include "qchartglobal.h"
50 50 #include <QBasicTimer>
51 51 #include <QTime>
52 52 #include <QPointF>
53 53
54 54 class QGraphicsSceneMouseEvent;
55 55
56 56 QTCOMMERCIALCHART_BEGIN_NAMESPACE
57 57
58 58 class MouseEventHandler
59 59 {
60 60 public:
61 61 enum State {
62 62 Idle,
63 63 Pressed,
64 64 Moved,
65 65 Released
66 66 };
67 67
68 68 MouseEventHandler();
69 69 virtual ~MouseEventHandler();
70 70
71 71 void setMoveTreshold(qreal treshold);
72 72
73 73 virtual void mouseClicked() = 0;
74 74 virtual void mouseMoved(const QPointF &delta) = 0;
75 75 virtual void mouseReleased(const QPointF &pos) = 0;
76 76
77 void handleMousePressEvent(QGraphicsSceneMouseEvent* event);
78 void handleMouseMoveEvent(QGraphicsSceneMouseEvent* event);
79 void handleMouseReleaseEvent(QGraphicsSceneMouseEvent* event);
77 void handleMousePressEvent(QGraphicsSceneMouseEvent *event);
78 void handleMouseMoveEvent(QGraphicsSceneMouseEvent *event);
79 void handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event);
80 80
81 81 private:
82 82 QPointF m_lastPos;
83 83 State m_state;
84 84 qreal m_treshold;
85 85 };
86 86
87 87 QTCOMMERCIALCHART_END_NAMESPACE
88 88
89 89 #endif // MOUSEEVENTHANDLER_H
@@ -1,85 +1,85
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qarealegendmarker.h"
22 22 #include "qarealegendmarker_p.h"
23 23 #include "qareaseries_p.h"
24 24 #include <QAreaSeries>
25 25
26 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 29 QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent)
30 30 {
31 31 }
32 32
33 33 QAreaLegendMarker::~QAreaLegendMarker()
34 34 {
35 35 }
36 36
37 37 /*!
38 38 \internal
39 39 */
40 40 QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) :
41 41 QLegendMarker(d, parent)
42 42 {
43 43 }
44 44
45 45 QAreaSeries* QAreaLegendMarker::series()
46 46 {
47 47 Q_D(QAreaLegendMarker);
48 48 return d->m_series;
49 49 }
50 50
51 51 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52 52
53 53 QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) :
54 54 QLegendMarkerPrivate(q,legend),
55 55 m_series(series)
56 56 {
57 57 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
58 58 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
59 59 updated();
60 60 }
61 61
62 62 QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate()
63 63 {
64 64 }
65 65
66 66 QAreaSeries* QAreaLegendMarkerPrivate::series()
67 67 {
68 68 return m_series;
69 69 }
70 70
71 71 QObject* QAreaLegendMarkerPrivate::relatedObject()
72 72 {
73 73 return m_series;
74 74 }
75 75
76 76 void QAreaLegendMarkerPrivate::updated()
77 77 {
78 78 m_item->setBrush(m_series->brush());
79 79 m_item->setLabel(m_series->name());
80 80 }
81 81
82 82 #include "moc_qarealegendmarker.cpp"
83 83 #include "moc_qarealegendmarker_p.cpp"
84 84
85 85 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,56 +1,56
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QAREALEGENDMARKER_H
22 22 #define QAREALEGENDMARKER_H
23 23
24 24 #include <QChartGlobal>
25 25 #include <QLegendMarker>
26 26 #include <QAreaSeries>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 class QAreaLegendMarkerPrivate;
31 31
32 32 class QTCOMMERCIALCHART_EXPORT QAreaLegendMarker : public QLegendMarker
33 33 {
34 34 Q_OBJECT
35 35
36 36 public:
37 explicit QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent = 0);
37 explicit QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent = 0);
38 38 virtual ~QAreaLegendMarker();
39 39
40 40 virtual LegendMarkerType type() { return LegendMarkerTypeArea; }
41 41
42 42 // Related series
43 43 virtual QAreaSeries* series();
44 44
45 45 protected:
46 46 QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent = 0);
47 47
48 48 private:
49 49 Q_DECLARE_PRIVATE(QAreaLegendMarker)
50 50 Q_DISABLE_COPY(QAreaLegendMarker)
51 51
52 52 };
53 53
54 54 QTCOMMERCIALCHART_END_NAMESPACE
55 55
56 56 #endif // QAREALEGENDMARKER_H
@@ -1,64 +1,64
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QAREALEGENDMARKER_P_H
31 31 #define QAREALEGENDMARKER_P_H
32 32
33 33 #include "qchartglobal.h"
34 34 #include "qlegendmarker_p.h"
35 35 #include "legendmarkeritem_p.h"
36 36 #include <QAreaSeries>
37 37
38 38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 39
40 40 class QAreaLegendMarker;
41 41
42 42 class QAreaLegendMarkerPrivate : public QLegendMarkerPrivate
43 43 {
44 44 Q_OBJECT
45 45 public:
46 46 explicit QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend);
47 47 virtual ~QAreaLegendMarkerPrivate();
48 48
49 49 virtual QAreaSeries* series();
50 50 virtual QObject* relatedObject();
51 51
52 52 public Q_SLOTS:
53 53 virtual void updated();
54 54
55 55 private:
56 56 QAreaLegendMarker *q_ptr;
57 QAreaSeries* m_series;
57 QAreaSeries *m_series;
58 58
59 59 Q_DECLARE_PUBLIC(QAreaLegendMarker)
60 60 };
61 61
62 62 QTCOMMERCIALCHART_END_NAMESPACE
63 63
64 64 #endif // QAREALEGENDMARKER_P_H
@@ -1,95 +1,95
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qbarlegendmarker.h"
22 22 #include "qbarlegendmarker_p.h"
23 23 #include <QAbstractBarSeries>
24 24 #include <QBarSet>
25 25
26 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 29 QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent)
30 30 {
31 31 }
32 32
33 33 QBarLegendMarker::~QBarLegendMarker()
34 34 {
35 35 }
36 36
37 37 /*!
38 38 \internal
39 39 */
40 40 QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) :
41 41 QLegendMarker(d, parent)
42 42 {
43 43 }
44 44
45 45 QAbstractBarSeries *QBarLegendMarker::series()
46 46 {
47 47 Q_D(QBarLegendMarker);
48 48 return d->m_series;
49 49 }
50 50
51 51 QBarSet* QBarLegendMarker::barset()
52 52 {
53 53 Q_D(QBarLegendMarker);
54 54 return d->m_barset;
55 55 }
56 56
57 57 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58 58
59 59 QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) :
60 60 QLegendMarkerPrivate(q,legend),
61 61 m_series(series),
62 62 m_barset(barset)
63 63 {
64 64 QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated()));
65 65 QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated()));
66 66 QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated()));
67 67 updated();
68 68 }
69 69
70 70 QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate()
71 71 {
72 72 }
73 73
74 74 QAbstractBarSeries* QBarLegendMarkerPrivate::series()
75 75 {
76 76 return m_series;
77 77 }
78 78
79 79 QObject* QBarLegendMarkerPrivate::relatedObject()
80 80 {
81 81 return m_barset;
82 82 }
83 83
84 84 void QBarLegendMarkerPrivate::updated()
85 85 {
86 86 m_item->setPen(m_barset->pen());
87 87 m_item->setBrush(m_barset->brush());
88 88 m_item->setLabel(m_barset->label());
89 89 }
90 90
91 91 #include "moc_qbarlegendmarker.cpp"
92 92 #include "moc_qbarlegendmarker_p.cpp"
93 93
94 94 QTCOMMERCIALCHART_END_NAMESPACE
95 95
@@ -1,57 +1,57
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20 #ifndef QBARLEGENDMARKER_H
21 21 #define QBARLEGENDMARKER_H
22 22
23 23 #include <QChartGlobal>
24 24 #include <QLegendMarker>
25 25 #include <QAbstractBarSeries>
26 26 #include <QBarSet>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 class QLegend;
31 31 class QBarLegendMarkerPrivate;
32 32
33 33 class QTCOMMERCIALCHART_EXPORT QBarLegendMarker : public QLegendMarker
34 34 {
35 35 Q_OBJECT
36 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 38 virtual ~QBarLegendMarker();
39 39
40 40 virtual LegendMarkerType type() { return LegendMarkerTypeBar; }
41 41
42 42 // Related series and barset
43 43 virtual QAbstractBarSeries* series();
44 44 QBarSet* barset();
45 45
46 46 protected:
47 47 QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent = 0);
48 48
49 49 private:
50 50 Q_DECLARE_PRIVATE(QBarLegendMarker)
51 51 Q_DISABLE_COPY(QBarLegendMarker)
52 52
53 53 };
54 54
55 55 QTCOMMERCIALCHART_END_NAMESPACE
56 56
57 57 #endif // QBARLEGENDMARKER_H
@@ -1,66 +1,66
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QBARLEGENDMARKER_P_H
31 31 #define QBARLEGENDMARKER_P_H
32 32
33 33 #include "qchartglobal.h"
34 34 #include "qlegendmarker_p.h"
35 35 #include "legendmarkeritem_p.h"
36 36 #include <QAbstractBarSeries>
37 37 #include <QBarSet>
38 38
39 39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 40
41 41 class QBarLegendMarker;
42 42
43 43 class QBarLegendMarkerPrivate : public QLegendMarkerPrivate
44 44 {
45 45 Q_OBJECT
46 46 public:
47 47 explicit QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend);
48 48 virtual ~QBarLegendMarkerPrivate();
49 49
50 50 virtual QAbstractBarSeries* series();
51 51 virtual QObject* relatedObject();
52 52
53 53 public Q_SLOTS:
54 54 virtual void updated();
55 55
56 56 private:
57 57 QBarLegendMarker *q_ptr;
58 QAbstractBarSeries* m_series;
59 QBarSet* m_barset;
58 QAbstractBarSeries *m_series;
59 QBarSet *m_barset;
60 60
61 61 Q_DECLARE_PUBLIC(QBarLegendMarker)
62 62 };
63 63
64 64 QTCOMMERCIALCHART_END_NAMESPACE
65 65
66 66 #endif // QBARLEGENDMARKER_P_H
@@ -1,610 +1,612
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qlegend.h"
22 22 #include "qlegend_p.h"
23 23 #include "qabstractseries.h"
24 24 #include "qabstractseries_p.h"
25 25 #include "qchart_p.h"
26 26 #include "legendlayout_p.h"
27 #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 27 #include "chartpresenter_p.h"
40 28 #include "chartlayout_p.h"
41 #include <QPainter>
42 #include <QPen>
43 #include <QTimer>
44 #include <QGraphicsSceneEvent>
45 #include <QGraphicsItemGroup>
46
47 29 #include "qlegendmarker.h"
48 30 #include "qlegendmarker_p.h"
49 31 #include "legendmarkeritem_p.h"
32 #include <QPainter>
33 #include <QPen>
34 #include <QGraphicsItemGroup>
50 35
51 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
52 37
53 38 /*!
54 39 \class QLegend
55 40 \brief Legend object
56 41 \mainclass
57 42
58 43 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
59 44 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
60 45 handle the drawing manually.
61 46 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
62 47
63 48 \image examples_percentbarchart_legend.png
64 49
65 50 \sa QChart
66 51 */
67 52 /*!
68 53 \qmlclass Legend QLegend
69 54 \brief Legend is part of QtCommercial Chart QML API.
70 55
71 56 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
72 57 series have been changed. Legend is used via ChartView class. For example:
73 58 \code
74 59 ChartView {
75 60 legend.visible: true
76 61 legend.alignment: Qt.AlignBottom
77 62 // Add a few series...
78 63 }
79 64 \endcode
80 65
81 66 \image examples_percentbarchart_legend.png
82 67 */
83 68
84 69 /*!
85 70 \property QLegend::alignment
86 71 \brief The alignment of the legend.
87 72
88 73 Legend paints on the defined position in the chart. The following alignments are supported:
89 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 77 \qmlproperty Qt.Alignment Legend::alignment
93 78 \brief The alignment of the legend.
94 79
95 80 Legend paints on the defined position in the chart. The following alignments are supported:
96 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 85 \property QLegend::backgroundVisible
101 86 Whether the legend background is visible or not.
102 87 */
103 88 /*!
104 89 \qmlproperty bool Legend::backgroundVisible
105 90 Whether the legend background is visible or not.
106 91 */
107 92
108 93 /*!
109 94 \property QLegend::color
110 95 The color of the legend, i.e. the background (brush) color. Note that if you change the color
111 96 of the legend, the style of the legend brush is set to Qt::SolidPattern.
112 97 */
113 98 /*!
114 99 \qmlproperty color Legend::color
115 100 The color of the legend, i.e. the background (brush) color.
116 101 */
117 102
118 103 /*!
119 104 \property QLegend::borderColor
120 105 The border color of the legend, i.e. the line color.
121 106 */
122 107 /*!
123 108 \qmlproperty color Legend::borderColor
124 109 The border color of the legend, i.e. the line color.
125 110 */
126 111
127 112 /*!
128 113 \property QLegend::font
129 114 The font of markers used by legend
130 115 */
131 116 /*!
132 117 \qmlproperty Font Legend::font
133 118 The font of markers used by legend
134 119 */
135 120
136 121 /*!
137 122 \property QLegend::labelColor
138 123 The color of brush used to draw labels.
139 124 */
140 125 /*!
141 126 \qmlproperty color QLegend::labelColor
142 127 The color of brush used to draw labels.
143 128 */
144 129
145 130 /*!
146 131 \fn void QLegend::backgroundVisibleChanged(bool)
147 132 The visibility of the legend background changed to \a visible.
148 133 */
149 134
150 135 /*!
151 136 \fn void QLegend::colorChanged(QColor)
152 137 The color of the legend background changed to \a color.
153 138 */
154 139
155 140 /*!
156 141 \fn void QLegend::borderColorChanged(QColor)
157 142 The border color of the legend background changed to \a color.
158 143 */
159 144
160 145 /*!
161 146 \fn void QLegend::fontChanged(QFont)
162 147 The font of markers of the legend changed to \a font.
163 148 */
164 149
165 150 /*!
166 151 \fn void QLegend::labelColorChanged(QColor color)
167 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 156 Constructs the legend object and sets the parent to \a parent
172 157 */
173 158
174 159 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart),
175 160 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this))
176 161 {
177 162 setZValue(ChartPresenter::LegendZValue);
178 163 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
179 164 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*)));
180 165 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
181 166 setLayout(d_ptr->m_layout);
182 167 }
183 168
184 169 /*!
185 170 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
186 171 */
187 172 QLegend::~QLegend()
188 173 {
189 174 }
190 175
191 176 /*!
192 177 \internal
193 178 */
194 179 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
195 180 {
196 181 Q_UNUSED(option)
197 182 Q_UNUSED(widget)
198 183
199 184 if (!d_ptr->m_backgroundVisible)
200 185 return;
201 186
202 187 painter->setOpacity(opacity());
203 188 painter->setPen(d_ptr->m_pen);
204 189 painter->setBrush(d_ptr->m_brush);
205 190 painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()));
206 191 }
207 192
208 193
209 194 /*!
210 195 Sets the \a brush of legend. Brush affects the background of legend.
211 196 */
212 197 void QLegend::setBrush(const QBrush &brush)
213 198 {
214 199 if (d_ptr->m_brush != brush) {
215 200 d_ptr->m_brush = brush;
216 201 update();
217 202 emit colorChanged(brush.color());
218 203 }
219 204 }
220 205
221 206 /*!
222 207 Returns the brush used by legend.
223 208 */
224 209 QBrush QLegend::brush() const
225 210 {
226 211 return d_ptr->m_brush;
227 212 }
228 213
229 214 void QLegend::setColor(QColor color)
230 215 {
231 216 QBrush b = d_ptr->m_brush;
232 217 if (b.style() != Qt::SolidPattern || b.color() != color) {
233 218 b.setStyle(Qt::SolidPattern);
234 219 b.setColor(color);
235 220 setBrush(b);
236 221 }
237 222 }
238 223
239 224 QColor QLegend::color()
240 225 {
241 226 return d_ptr->m_brush.color();
242 227 }
243 228
244 229 /*!
245 230 Sets the \a pen of legend. Pen affects the legend borders.
246 231 */
247 232 void QLegend::setPen(const QPen &pen)
248 233 {
249 234 if (d_ptr->m_pen != pen) {
250 235 d_ptr->m_pen = pen;
251 236 update();
252 237 emit borderColorChanged(pen.color());
253 238 }
254 239 }
255 240
256 241 /*!
257 242 Returns the pen used by legend
258 243 */
259 244
260 245 QPen QLegend::pen() const
261 246 {
262 247 return d_ptr->m_pen;
263 248 }
264 249
265 250 void QLegend::setFont(const QFont &font)
266 251 {
267 252 if (d_ptr->m_font != font)
268 253 d_ptr->m_font = font;
269 254
270 255 foreach (QLegendMarker *marker, d_ptr->markers()) {
271 256 marker->setFont(d_ptr->m_font);
272 257 }
273 258 layout()->invalidate();
274 259 emit fontChanged(font);
275 260 }
276 261
277 262 QFont QLegend::font() const
278 263 {
279 264 return d_ptr->m_font;
280 265 }
281 266
282 267 void QLegend::setBorderColor(QColor color)
283 268 {
284 269 QPen p = d_ptr->m_pen;
285 270 if (p.color() != color) {
286 271 p.setColor(color);
287 272 setPen(p);
288 273 }
289 274 }
290 275
291 276 QColor QLegend::borderColor()
292 277 {
293 278 return d_ptr->m_pen.color();
294 279 }
295 280
296 281 /*!
297 282 Set brush used to draw labels to \a brush.
298 283 */
299 284 void QLegend::setLabelBrush(const QBrush &brush)
300 285 {
301 286 if (d_ptr->m_labelBrush != brush) {
302 287 d_ptr->m_labelBrush = brush;
303 288 foreach (QLegendMarker *marker, d_ptr->markers()) {
304 289 marker->setLabelBrush(d_ptr->m_labelBrush);
305 290 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
306 291 // instead of mapping it from label brush color
307 292 marker->setPen(brush.color());
308 293 }
309 294 emit labelColorChanged(brush.color());
310 295 }
311 296 }
312 297
313 298 /*!
314 299 Brush used to draw labels.
315 300 */
316 301 QBrush QLegend::labelBrush() const
317 302 {
318 303 return d_ptr->m_labelBrush;
319 304 }
320 305
321 306 void QLegend::setLabelColor(QColor color)
322 307 {
323 308 QBrush b = d_ptr->m_labelBrush;
324 309 if (b.style() != Qt::SolidPattern || b.color() != color) {
325 310 b.setStyle(Qt::SolidPattern);
326 311 b.setColor(color);
327 312 setLabelBrush(b);
328 313 }
329 314 }
330 315
331 316 QColor QLegend::labelColor() const
332 317 {
333 318 return d_ptr->m_labelBrush.color();
334 319 }
335 320
336 321
337 322 void QLegend::setAlignment(Qt::Alignment alignment)
338 323 {
339 324 if (d_ptr->m_alignment != alignment) {
340 325 d_ptr->m_alignment = alignment;
341 326 layout()->invalidate();
342 327 }
343 328 }
344 329
345 330 Qt::Alignment QLegend::alignment() const
346 331 {
347 332 return d_ptr->m_alignment;
348 333 }
349 334
350 335 /*!
351 336 Detaches the legend from chart. Chart won't change layout of the legend.
352 337 */
353 338 void QLegend::detachFromChart()
354 339 {
355 340 d_ptr->m_attachedToChart = false;
356 341 layout()->invalidate();
357 342 setParent(0);
358 343
359 344 }
360 345
361 346 /*!
362 347 Attaches the legend to chart. Chart may change layout of the legend.
363 348 */
364 349 void QLegend::attachToChart()
365 350 {
366 351 d_ptr->m_attachedToChart = true;
367 352 layout()->invalidate();
368 353 setParent(d_ptr->m_chart);
369 354 }
370 355
371 356 /*!
372 357 Returns true, if legend is attached to chart.
373 358 */
374 359 bool QLegend::isAttachedToChart()
375 360 {
376 361 return d_ptr->m_attachedToChart;
377 362 }
378 363
379 364 /*!
380 365 Sets the visibility of legend background to \a visible
381 366 */
382 367 void QLegend::setBackgroundVisible(bool visible)
383 368 {
384 369 if (d_ptr->m_backgroundVisible != visible) {
385 370 d_ptr->m_backgroundVisible = visible;
386 371 update();
387 372 emit backgroundVisibleChanged(visible);
388 373 }
389 374 }
390 375
391 376 /*!
392 377 Returns the visibility of legend background
393 378 */
394 379 bool QLegend::isBackgroundVisible() const
395 380 {
396 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 391 d_ptr->addSeries(series);
407 392 }
408 393
409 void QLegend::removeSeries(QAbstractSeries* series)
394 void QLegend::removeSeries(QAbstractSeries *series)
410 395 {
411 396 d_ptr->removeSeries(series);
412 397 }
413 398
414 399 /*!
415 400 \internal \a event see QGraphicsWidget for details
416 401 */
417 402 void QLegend::hideEvent(QHideEvent *event)
418 403 {
419 404 if (isAttachedToChart())
420 405 d_ptr->m_presenter->layout()->invalidate();
421 406 QGraphicsWidget::hideEvent(event);
422 407 }
423 408 /*!
424 409 \internal \a event see QGraphicsWidget for details
425 410 */
426 411 void QLegend::showEvent(QShowEvent *event)
427 412 {
428 413 if (isAttachedToChart()) {
429 414 d_ptr->items()->setVisible(false);
430 415 layout()->invalidate();
431 416 }
432 417 QGraphicsWidget::showEvent(event);
433 418 //layout activation will show the items
434 419 }
435 420
436 421 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
437 422
438 423 QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q)
439 424 : q_ptr(q),
440 425 m_presenter(presenter),
441 426 m_layout(new LegendLayout(q)),
442 427 m_chart(chart),
443 428 m_items(new QGraphicsItemGroup(q)),
444 429 m_alignment(Qt::AlignTop),
445 430 m_brush(QBrush()),
446 431 m_pen(QPen()),
447 432 m_labelBrush(QBrush()),
448 433 m_diameter(5),
449 434 m_attachedToChart(true),
450 435 m_backgroundVisible(false)
451 436 {
452 437 m_items->setHandlesChildEvents(false);
453 438 }
454 439
455 440 QLegendPrivate::~QLegendPrivate()
456 441 {
457 442
458 443 }
459 444
460 445 void QLegendPrivate::setOffset(const QPointF &offset)
461 446 {
462 447 m_layout->setOffset(offset.x(), offset.y());
463 448 }
464 449
465 450 QPointF QLegendPrivate::offset() const
466 451 {
467 452 return m_layout->offset();
468 453 }
469 454
470 455 int QLegendPrivate::roundness(qreal size)
471 456 {
472 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 479 // Only allow one instance of series
478 480 if (m_series.contains(series)) {
479 481 return;
480 482 }
481 483
482 484 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
483 485 decorateMarkers(newMarkers);
484 486 addMarkers(newMarkers);
485 487
486 488 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
487 489 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
488 490
489 491 m_series.append(series);
490 492 m_items->setVisible(false);
491 493 m_layout->invalidate();
492 494 }
493 495
494 void QLegendPrivate::removeSeries(QAbstractSeries* series)
496 void QLegendPrivate::removeSeries(QAbstractSeries *series)
495 497 {
496 498 if (m_series.contains(series)) {
497 499 m_series.removeOne(series);
498 500 }
499 501
500 502 // Find out, which markers to remove
501 503 QList<QLegendMarker *> removed;
502 504 foreach (QLegendMarker *m, m_markers) {
503 505 if (m->series() == series) {
504 506 removed << m;
505 507 }
506 508 }
507 509 removeMarkers(removed);
508 510
509 511 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
510 512 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
511 513
512 514 m_layout->invalidate();
513 515 }
514 516
515 517 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series)
516 518 {
517 519 // Moved to appendSeries
518 520 // This slot is just to make old code work for now.
519 521 addSeries(series);
520 522 }
521 523
522 524 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
523 525 {
524 526 // Moved to removeSeries
525 527 // This slot is just to make old code work for now.
526 528 removeSeries(series);
527 529 }
528 530
529 531 void QLegendPrivate::handleSeriesVisibleChanged()
530 532 {
531 533 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
532 534 Q_ASSERT(series);
533 535
534 foreach (QLegendMarker* marker, m_markers) {
536 foreach (QLegendMarker *marker, m_markers) {
535 537 if (marker->series() == series) {
536 538 marker->setVisible(series->isVisible());
537 539 }
538 540 }
539 541 m_layout->invalidate();
540 542 }
541 543
542 544 void QLegendPrivate::handleCountChanged()
543 545 {
544 546 // Here we handle the changes in marker count.
545 547 // Can happen for example when pieslice(s) have been added to or removed from pieseries.
546 548
547 549 QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender());
548 550 QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr);
549 551
550 552 // Find out removed markers and created markers
551 553 QList<QLegendMarker *> removedMarkers;
552 554 foreach (QLegendMarker *oldMarker, m_markers) {
553 555 // we have marker, which is related to sender.
554 556 if (oldMarker->series() == series->q_ptr) {
555 557 bool found = false;
556 558 foreach(QLegendMarker *newMarker, createdMarkers) {
557 559 // New marker considered existing if:
558 560 // - d_ptr->relatedObject() is same for both markers.
559 561 if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) {
560 562 // Delete the new marker, since we already have existing marker, that might be connected on user side.
561 563 found = true;
562 564 createdMarkers.removeOne(newMarker);
563 565 delete newMarker;
564 566 }
565 567 }
566 568 if (!found) {
567 569 // No related object found for marker, add to removedMarkers list
568 570 removedMarkers << oldMarker;
569 571 }
570 572 }
571 573 }
572 574
573 575 removeMarkers(removedMarkers);
574 576 decorateMarkers(createdMarkers);
575 577 addMarkers(createdMarkers);
576 578
577 579 q_ptr->layout()->invalidate();
578 580 }
579 581
580 582 void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers)
581 583 {
582 foreach (QLegendMarker* marker, markers) {
584 foreach (QLegendMarker *marker, markers) {
583 585 m_items->addToGroup(marker->d_ptr.data()->item());
584 586 m_markers << marker;
585 587 }
586 588 }
587 589
588 590 void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers)
589 591 {
590 592 foreach (QLegendMarker *marker, markers) {
591 593 marker->d_ptr->item()->setVisible(false);
592 594 m_items->removeFromGroup(marker->d_ptr->item());
593 595 delete marker;
594 596 m_markers.removeOne(marker);
595 597 }
596 598 }
597 599
598 600 void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers)
599 601 {
600 foreach (QLegendMarker* marker, markers) {
602 foreach (QLegendMarker *marker, markers) {
601 603 marker->setFont(m_font);
602 604 marker->setLabelBrush(m_labelBrush);
603 605 }
604 606 }
605 607
606 608
607 609 #include "moc_qlegend.cpp"
608 610 #include "moc_qlegend_p.cpp"
609 611
610 612 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,109 +1,109
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QLEGEND_H
22 22 #define QLEGEND_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <QGraphicsWidget>
26 26 #include <QPen>
27 27 #include <QBrush>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class QChart;
32 32 class QLegendPrivate;
33 33 class QLegendMarker;
34 34 class QAbstractSeries;
35 35
36 36 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
37 37 {
38 38 Q_OBJECT
39 39 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
40 40 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged)
41 41 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
42 42 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
43 43 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
44 44 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
45 45
46 46 private:
47 47 explicit QLegend(QChart *chart);
48 48
49 49 public:
50 50 ~QLegend();
51 51
52 52 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
53 53
54 54 void setBrush(const QBrush &brush);
55 55 QBrush brush() const;
56 56 void setColor(QColor color);
57 57 QColor color();
58 58
59 59 void setPen(const QPen &pen);
60 60 QPen pen() const;
61 61 void setBorderColor(QColor color);
62 62 QColor borderColor();
63 63
64 64 void setFont(const QFont &font);
65 65 QFont font() const;
66 66 void setLabelBrush(const QBrush &brush);
67 67 QBrush labelBrush() const;
68 68
69 69 void setLabelColor(QColor color);
70 70 QColor labelColor() const;
71 71
72 72 void setAlignment(Qt::Alignment alignment);
73 73 Qt::Alignment alignment() const;
74 74
75 75 void detachFromChart();
76 76 void attachToChart();
77 77 bool isAttachedToChart();
78 78
79 79 void setBackgroundVisible(bool visible = true);
80 80 bool isBackgroundVisible() const;
81 81
82 82 // New stuff:
83 QList <QLegendMarker*> markers() const;
84 void addSeries(QAbstractSeries* series);
85 void removeSeries(QAbstractSeries* series);
83 QList <QLegendMarker*> markers(QAbstractSeries *series = 0) const;
84 void addSeries(QAbstractSeries *series);
85 void removeSeries(QAbstractSeries *series);
86 86
87 87 protected:
88 88 void hideEvent(QHideEvent *event);
89 89 void showEvent(QShowEvent *event);
90 90
91 91 Q_SIGNALS:
92 92 void backgroundVisibleChanged(bool visible);
93 93 void colorChanged(QColor color);
94 94 void borderColorChanged(QColor color);
95 95 void fontChanged(QFont font);
96 96 void labelColorChanged(QColor color);
97 97
98 98 private:
99 99 QScopedPointer<QLegendPrivate> d_ptr;
100 100 Q_DISABLE_COPY(QLegend)
101 101 friend class LegendScroller;
102 102 friend class LegendLayout;
103 103 friend class ChartLayout;
104 104 friend class LegendMarkerItem;
105 105 };
106 106
107 107 QTCOMMERCIALCHART_END_NAMESPACE
108 108
109 109 #endif // QLEGEND_H
@@ -1,102 +1,100
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QLEGEND_P_H
31 31 #define QLEGEND_P_H
32 32
33 33 #include "qlegend.h"
34 34 #include "scroller_p.h"
35 35
36 36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 37
38 38 class QChart;
39 39 class ChartPresenter;
40 40 class QAbstractSeries;
41 41 class LegendLayout;
42 42 class Domain;
43 43 class QLegendMarker;
44 44
45 45 class QLegendPrivate : public QObject, public Scroller
46 46 {
47 47 Q_OBJECT
48 48 public:
49 49 QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q);
50 50 ~QLegendPrivate();
51 51
52 52 void setOffset(const QPointF &offset);
53 53 QPointF offset() const;
54 54 int roundness(qreal size);
55 55
56 56 QGraphicsItemGroup* items() { return m_items; }
57 57
58 // New stuff:
59 QList<QLegendMarker*> markers() { return m_markers; }
60 void addSeries(QAbstractSeries* series);
61 void removeSeries(QAbstractSeries* series);
58 QList<QLegendMarker*> markers(QAbstractSeries *series = 0);
59 void addSeries(QAbstractSeries *series);
60 void removeSeries(QAbstractSeries *series);
62 61
63 62 public Q_SLOTS:
64 63 void handleSeriesAdded(QAbstractSeries *series);
65 64 void handleSeriesRemoved(QAbstractSeries *series);
66 65 void handleSeriesVisibleChanged();
67 66 void handleCountChanged();
68 67
69 68 private:
70 69 // Internal helpers
71 70 void addMarkers(QList<QLegendMarker *> markers);
72 71 void removeMarkers(QList<QLegendMarker *> markers);
73 72 void decorateMarkers(QList<QLegendMarker *> markers);
74 73
75 74 private:
76 75 QLegend *q_ptr;
77 76 ChartPresenter *m_presenter;
78 77 LegendLayout *m_layout;
79 QChart* m_chart;
80 QGraphicsItemGroup* m_items;
78 QChart *m_chart;
79 QGraphicsItemGroup *m_items;
81 80 Qt::Alignment m_alignment;
82 81 QBrush m_brush;
83 82 QPen m_pen;
84 83 QFont m_font;
85 84 QBrush m_labelBrush;
86 85
87 86 qreal m_diameter;
88 87 bool m_attachedToChart;
89 88 bool m_backgroundVisible;
90 89
91 friend class QLegend;
92 friend class LegendLayout;
93 QList<QLegendMarker*> m_markers;
94 QList<QAbstractSeries*> m_series;
90 QList<QLegendMarker *> m_markers;
91 QList<QAbstractSeries *> m_series;
95 92
96 93 friend class QLegend;
97 94 friend class LegendMarkerItem;
95 friend class LegendLayout;
98 96 };
99 97
100 98 QTCOMMERCIALCHART_END_NAMESPACE
101 99
102 100 #endif
@@ -1,85 +1,85
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QLEGENDMARKERPRIVATE_H
31 31 #define QLEGENDMARKERPRIVATE_H
32 32
33 33 #include "qchartglobal.h"
34 34 #include <QGraphicsObject>
35 35 #include <QBrush>
36 36 #include <QPen>
37 37 #include <QGraphicsSimpleTextItem>
38 38 #include <QGraphicsLayoutItem>
39 39
40 40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 41
42 42 // TODO: check these
43 43 class QAbstractSeries;
44 44 class QAreaSeries;
45 45 class QXYSeries;
46 46 class QBarSet;
47 47 class QAbstractBarSeries;
48 48 class QPieSlice;
49 49 class QLegend;
50 50 class QPieSeries;
51 51
52 52 class QLegendMarker;
53 53 class LegendMarkerItem;
54 54
55 55 class QLegendMarkerPrivate : public QObject
56 56 {
57 57 Q_OBJECT
58 58 public:
59 59 explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend);
60 60 virtual ~QLegendMarkerPrivate();
61 61
62 62 // Helper for now. (or declare LegendLayout as friend)
63 63 LegendMarkerItem* item() const { return m_item; }
64 64
65 65 virtual QAbstractSeries* series() = 0;
66 66 virtual QObject* relatedObject() = 0;
67 67
68 68 public Q_SLOTS:
69 69 virtual void updated() {};
70 70
71 71 protected:
72 72 LegendMarkerItem *m_item;
73 QLegend* m_legend;
73 QLegend *m_legend;
74 74
75 75 private:
76 76 QLegendMarker *q_ptr;
77 77
78 78 friend class QLegendPrivate;
79 79 friend class LegendMarkerItem;
80 80 Q_DECLARE_PUBLIC(QLegendMarker)
81 81 };
82 82
83 83 QTCOMMERCIALCHART_END_NAMESPACE
84 84
85 85 #endif // QLEGENDMARKERPRIVATE_H
@@ -1,94 +1,94
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qpielegendmarker.h"
22 22 #include "qpielegendmarker_p.h"
23 23 #include <QPieSeries>
24 24 #include <QPieSlice>
25 25
26 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 29 QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent)
30 30 {
31 31 }
32 32
33 33 QPieLegendMarker::~QPieLegendMarker()
34 34 {
35 35 }
36 36
37 37 /*!
38 38 \internal
39 39 */
40 40 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
41 41 QLegendMarker(d, parent)
42 42 {
43 43 }
44 44
45 45 QPieSeries* QPieLegendMarker::series()
46 46 {
47 47 Q_D(QPieLegendMarker);
48 48 return d->m_series;
49 49 }
50 50
51 51 QPieSlice* QPieLegendMarker::slice()
52 52 {
53 53 Q_D(QPieLegendMarker);
54 54 return d->m_slice;
55 55 }
56 56
57 57 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58 58
59 59 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) :
60 60 QLegendMarkerPrivate(q,legend),
61 61 m_series(series),
62 62 m_slice(slice)
63 63 {
64 64 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
65 65 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
66 66 QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated()));
67 67 updated();
68 68 }
69 69
70 70 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
71 71 {
72 72 }
73 73
74 74 QPieSeries* QPieLegendMarkerPrivate::series()
75 75 {
76 76 return m_series;
77 77 }
78 78
79 79 QObject* QPieLegendMarkerPrivate::relatedObject()
80 80 {
81 81 return m_slice;
82 82 }
83 83
84 84 void QPieLegendMarkerPrivate::updated()
85 85 {
86 86 m_item->setPen(m_slice->pen());
87 87 m_item->setBrush(m_slice->brush());
88 88 m_item->setLabel(m_slice->label());
89 89 }
90 90
91 91 #include "moc_qpielegendmarker.cpp"
92 92 #include "moc_qpielegendmarker_p.cpp"
93 93
94 94 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,57 +1,57
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QPIELEGENDMARKER_H
22 22 #define QPIELEGENDMARKER_H
23 23
24 24 #include <QChartGlobal>
25 25 #include <QLegendMarker>
26 26 #include <QPieSeries>
27 27 #include <QPieSlice>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class QPieLegendMarkerPrivate;
32 32
33 33 class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker
34 34 {
35 35 Q_OBJECT
36 36
37 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 39 virtual ~QPieLegendMarker();
40 40
41 41 virtual LegendMarkerType type() { return LegendMarkerTypePie; }
42 42
43 43 // Related series and slice
44 44 virtual QPieSeries* series();
45 45 QPieSlice* slice();
46 46
47 47 protected:
48 48 QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent = 0);
49 49
50 50 private:
51 51 Q_DECLARE_PRIVATE(QPieLegendMarker)
52 52 Q_DISABLE_COPY(QPieLegendMarker)
53 53
54 54 };
55 55
56 56 QTCOMMERCIALCHART_END_NAMESPACE
57 57 #endif // QPIELEGENDMARKER_H
@@ -1,68 +1,68
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QPIELEGENDMARKER_P_H
31 31 #define QPIELEGENDMARKER_P_H
32 32
33 33 #include "qchartglobal.h"
34 34 #include "qlegendmarker_p.h"
35 35 #include "legendmarkeritem_p.h"
36 36 #include <QPieSeries>
37 37 #include <QPieSlice>
38 38
39 39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 40
41 41 class QPieLegendMarker;
42 42
43 43 class QPieLegendMarkerPrivate : public QLegendMarkerPrivate
44 44 {
45 45 Q_OBJECT
46 46 public:
47 47 explicit QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend);
48 48 virtual ~QPieLegendMarkerPrivate();
49 49
50 50 // internal
51 51 virtual QPieSeries* series();
52 52 virtual QObject* relatedObject();
53 53
54 54 public Q_SLOTS:
55 55 virtual void updated();
56 56
57 57 private:
58 58 QPieLegendMarker *q_ptr;
59 59
60 QPieSeries* m_series;
61 QPieSlice* m_slice;
60 QPieSeries *m_series;
61 QPieSlice *m_slice;
62 62
63 63 Q_DECLARE_PUBLIC(QPieLegendMarker)
64 64 };
65 65
66 66 QTCOMMERCIALCHART_END_NAMESPACE
67 67
68 68 #endif // QPIELEGENDMARKER_P_H
@@ -1,91 +1,91
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qxylegendmarker.h"
22 22 #include "qxylegendmarker_p.h"
23 23 #include "qxyseries_p.h"
24 24 #include <QXYSeries>
25 25
26 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 29 QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent)
30 30 {
31 31 }
32 32
33 33 QXYLegendMarker::~QXYLegendMarker()
34 34 {
35 35 }
36 36
37 37 /*!
38 38 \internal
39 39 */
40 40 QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) :
41 41 QLegendMarker(d, parent)
42 42 {
43 43 }
44 44
45 45 QXYSeries* QXYLegendMarker::series()
46 46 {
47 47 Q_D(QXYLegendMarker);
48 48 return d->m_series;
49 49 }
50 50
51 51 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52 52
53 53 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
54 54 QLegendMarkerPrivate(q,legend),
55 55 m_series(series)
56 56 {
57 57 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
58 58 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
59 59 updated();
60 60 }
61 61
62 62 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
63 63 {
64 64 }
65 65
66 66 QAbstractSeries* QXYLegendMarkerPrivate::series()
67 67 {
68 68 return m_series;
69 69 }
70 70
71 71 QObject* QXYLegendMarkerPrivate::relatedObject()
72 72 {
73 73 return m_series;
74 74 }
75 75
76 76 void QXYLegendMarkerPrivate::updated()
77 77 {
78 78 m_item->setLabel(m_series->name());
79 79
80 80 if (m_series->type()== QAbstractSeries::SeriesTypeScatter) {
81 81 m_item->setBrush(m_series->brush());
82 82 } else {
83 83 m_item->setBrush(QBrush(m_series->pen().color()));
84 84 }
85 85 }
86 86
87 87 #include "moc_qxylegendmarker.cpp"
88 88 #include "moc_qxylegendmarker_p.cpp"
89 89
90 90 QTCOMMERCIALCHART_END_NAMESPACE
91 91
@@ -1,55 +1,55
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QXYLEGENDMARKER_H
22 22 #define QXYLEGENDMARKER_H
23 23
24 24 #include <QChartGlobal>
25 25 #include <QLegendMarker>
26 26 #include <QXYSeries>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29
30 30 class QXYLegendMarkerPrivate;
31 31
32 32 class QTCOMMERCIALCHART_EXPORT QXYLegendMarker : public QLegendMarker
33 33 {
34 34 Q_OBJECT
35 35 public:
36 explicit QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent = 0);
36 explicit QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent = 0);
37 37 virtual ~QXYLegendMarker();
38 38
39 39 virtual LegendMarkerType type() { return LegendMarkerTypeXY; }
40 40
41 41 // Related series
42 42 virtual QXYSeries* series();
43 43
44 44 protected:
45 45 QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent = 0);
46 46
47 47 private:
48 48 Q_DECLARE_PRIVATE(QXYLegendMarker)
49 49 Q_DISABLE_COPY(QXYLegendMarker)
50 50
51 51 };
52 52
53 53 QTCOMMERCIALCHART_END_NAMESPACE
54 54
55 55 #endif // QXYLEGENDMARKER_H
@@ -1,64 +1,64
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QXYLEGENDMARKER_P_H
31 31 #define QXYLEGENDMARKER_P_H
32 32
33 33 #include "qchartglobal.h"
34 34 #include "qlegendmarker_p.h"
35 35 #include "legendmarkeritem_p.h"
36 36 #include <QXYSeries>
37 37
38 38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 39
40 40 class QXYLegendMarker;
41 41
42 42 class QXYLegendMarkerPrivate : public QLegendMarkerPrivate
43 43 {
44 44 Q_OBJECT
45 45 public:
46 46 explicit QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend);
47 47 virtual ~QXYLegendMarkerPrivate();
48 48
49 49 virtual QAbstractSeries* series();
50 50 virtual QObject* relatedObject();
51 51
52 52 public Q_SLOTS:
53 53 virtual void updated();
54 54
55 55 private:
56 56 QXYLegendMarker *q_ptr;
57 QXYSeries* m_series;
57 QXYSeries *m_series;
58 58
59 59 Q_DECLARE_PUBLIC(QXYLegendMarker)
60 60 };
61 61
62 62 QTCOMMERCIALCHART_END_NAMESPACE
63 63
64 64 #endif // QXYLEGENDMARKER_P_H
General Comments 0
You need to be logged in to leave comments. Login now