##// END OF EJS Templates
optional series parameter to markers function. code style fixes
sauimone -
r2193:7e0a20ef8117
parent child
Show More
@@ -133,12 +133,12 void LegendLayout::setAttachedGeometry(const QRectF &rect)
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;
@@ -155,12 +155,12 void LegendLayout::setAttachedGeometry(const QRectF &rect)
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;
@@ -217,7 +217,7 void LegendLayout::setDettachedGeometry(const QRectF &rect)
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);
@@ -249,7 +249,7 void LegendLayout::setDettachedGeometry(const QRectF &rect)
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);
@@ -283,7 +283,7 void LegendLayout::setDettachedGeometry(const QRectF &rect)
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);
@@ -319,7 +319,7 void LegendLayout::setDettachedGeometry(const QRectF &rect)
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);
@@ -359,7 +359,7 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
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 }
@@ -368,7 +368,7 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
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());
@@ -379,7 +379,7 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
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();
@@ -387,7 +387,7 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
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 }
@@ -98,7 +98,7 QBrush LegendMarkerItem::labelBrush() const
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
@@ -116,7 +116,7 void LegendMarkerItem::setGeometry(const QRectF& rect)
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);
@@ -65,13 +65,13 public:
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);
@@ -39,14 +39,14 void MouseEventHandler::setMoveTreshold(qreal treshold)
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
@@ -75,7 +75,7 void MouseEventHandler::handleMouseMoveEvent(QGraphicsSceneMouseEvent* event)
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
@@ -74,9 +74,9 public:
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;
@@ -25,7 +25,7
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 }
@@ -34,7 +34,7 class QTCOMMERCIALCHART_EXPORT QAreaLegendMarker : public QLegendMarker
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; }
@@ -54,7 +54,7 public Q_SLOTS:
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 };
@@ -25,7 +25,7
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 }
@@ -34,7 +34,7 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; }
@@ -55,8 +55,8 public Q_SLOTS:
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 };
@@ -24,29 +24,14
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
@@ -396,17 +381,17 bool QLegend::isBackgroundVisible() const
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 }
@@ -472,7 +457,24 int QLegendPrivate::roundness(qreal size)
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)) {
@@ -491,7 +493,7 void QLegendPrivate::addSeries(QAbstractSeries* series)
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);
@@ -531,7 +533,7 void QLegendPrivate::handleSeriesVisibleChanged()
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 }
@@ -579,7 +581,7 void QLegendPrivate::handleCountChanged()
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 }
@@ -597,7 +599,7 void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers)
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 }
@@ -80,9 +80,9 public:
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);
@@ -55,10 +55,9 public:
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);
@@ -76,8 +75,8 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;
@@ -88,13 +87,12 private:
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
@@ -70,7 +70,7 public Q_SLOTS:
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;
@@ -25,7 +25,7
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 }
@@ -35,7 +35,7 class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker
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; }
@@ -57,8 +57,8 public Q_SLOTS:
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 };
@@ -25,7 +25,7
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 }
@@ -33,7 +33,7 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; }
@@ -54,7 +54,7 public Q_SLOTS:
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 };
General Comments 0
You need to be logged in to leave comments. Login now