##// END OF EJS Templates
layout work started
sauimone -
r2168:778c4543bf0c
parent child
Show More
@@ -24,6 +24,10
24 #include "qlegend_p.h"
24 #include "qlegend_p.h"
25 #include "chartlayout_p.h"
25 #include "chartlayout_p.h"
26
26
27 #include "qlegendmarker_p.h"
28 #include "legendmarkeritem_p.h"
29 #include "qlegendmarker.h"
30
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
32
29 LegendLayout::LegendLayout(QLegend *legend)
33 LegendLayout::LegendLayout(QLegend *legend)
@@ -125,52 +129,84 void LegendLayout::setAttachedGeometry(const QRectF &rect)
125
129
126 QRectF geometry = rect.adjusted(left, top, -right, -bottom);
130 QRectF geometry = rect.adjusted(left, top, -right, -bottom);
127
131
128 switch (m_legend->alignment()) {
132 switch(m_legend->alignment()) {
129 case Qt::AlignTop:
133 case Qt::AlignTop:
130 case Qt::AlignBottom: {
134 case Qt::AlignBottom: {
131 QPointF point(0, 0);
135 QPointF point(0,0);
132 foreach (LegendMarker *marker, m_legend->d_ptr->markers()) {
136 /*
133 if (marker->isVisible()) {
137 foreach (LegendMarker* marker, m_legend->d_ptr->markers()) {
134 marker->setGeometry(geometry);
138 if (marker->isVisible()) {
135 marker->setPos(point.x(), geometry.height() / 2 - marker->boundingRect().height() / 2);
139 marker->setGeometry(geometry);
136 const QRectF &rect = marker->boundingRect();
140 marker->setPos(point.x(),geometry.height()/2 - marker->boundingRect().height()/2);
137 size = size.expandedTo(rect.size());
141 const QRectF& rect = marker->boundingRect();
138 qreal w = rect.width();
142 size = size.expandedTo(rect.size());
139 m_width += w;
143 qreal w = rect.width();
140 point.setX(point.x() + w);
144 m_width+=w;
145 point.setX(point.x() + w);
146 }
147 }
148 */
149 // New markers -->>
150 foreach (QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
151 if (marker->isVisible()) {
152 LegendMarkerItem* item = marker->d_ptr.data()->item();
153 item->setGeometry(geometry);
154 item->setPos(point.x(),geometry.height()/2 - item->boundingRect().height()/2);
155 const QRectF& rect = item->boundingRect();
156 size = size.expandedTo(rect.size());
157 qreal w = rect.width();
158 m_width+=w;
159 point.setX(point.x() + w);
160 }
141 }
161 }
162 // <<-- New markers
163 if (m_width < geometry.width())
164 m_legend->d_ptr->items()->setPos(geometry.width() / 2 - m_width / 2, geometry.top());
165 else
166 m_legend->d_ptr->items()->setPos(geometry.topLeft());
167 m_height = size.height();
142 }
168 }
143 if (m_width < geometry.width())
169 break;
144 m_legend->d_ptr->items()->setPos(geometry.width() / 2 - m_width / 2, geometry.top());
145 else
146 m_legend->d_ptr->items()->setPos(geometry.topLeft());
147 m_height = size.height();
148 }
149 break;
150 case Qt::AlignLeft:
170 case Qt::AlignLeft:
151 case Qt::AlignRight: {
171 case Qt::AlignRight: {
152 QPointF point(0, 0);
172 QPointF point(0,0);
153 foreach (LegendMarker *marker, m_legend->d_ptr->markers()) {
173 /*
154 if (marker->isVisible()) {
174 foreach (LegendMarker* marker, m_legend->d_ptr->markers()) {
155 marker->setGeometry(geometry);
175 if (marker->isVisible()) {
156 marker->setPos(point);
176 marker->setGeometry(geometry);
157 const QRectF &rect = marker->boundingRect();
177 marker->setPos(point);
158 qreal h = rect.height();
178 const QRectF& rect = marker->boundingRect();
159 size = size.expandedTo(rect.size());
179 qreal h = rect.height();
160 m_height += h;
180 size = size.expandedTo(rect.size());
161 point.setY(point.y() + h);
181 m_height+=h;
182 point.setY(point.y() + h);
183 }
184 }
185 */
186 // New markers -->>
187 foreach (QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
188 if (marker->isVisible()) {
189 LegendMarkerItem* item = marker->d_ptr.data()->item();
190 item->setGeometry(geometry);
191 item->setPos(point);
192 const QRectF& rect = item->boundingRect();
193 qreal h = rect.height();
194 size = size.expandedTo(rect.size());
195 m_height+=h;
196 point.setY(point.y() + h);
197 }
198 }
199 // <<--- New markers
200
201 if (m_height < geometry.height())
202 m_legend->d_ptr->items()->setPos(geometry.left(), geometry.height() / 2 - m_height / 2);
203 else
204 m_legend->d_ptr->items()->setPos(geometry.topLeft());
205 m_width = size.width();
206 break;
162 }
207 }
163 }
208 }
164
209
165 if (m_height < geometry.height())
166 m_legend->d_ptr->items()->setPos(geometry.left(), geometry.height() / 2 - m_height / 2);
167 else
168 m_legend->d_ptr->items()->setPos(geometry.topLeft());
169 m_width = size.width();
170 break;
171 }
172 }
173
174 m_minOffsetX = -left;
210 m_minOffsetX = -left;
175 m_minOffsetY = - top;
211 m_minOffsetY = - top;
176 m_maxOffsetX = m_width - geometry.width() - right;
212 m_maxOffsetX = m_width - geometry.width() - right;
@@ -348,6 +384,7 void LegendLayout::setDettachedGeometry(const QRectF &rect)
348
384
349 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
385 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
350 {
386 {
387 /*
351 QSizeF size(0, 0);
388 QSizeF size(0, 0);
352 qreal left, top, right, bottom;
389 qreal left, top, right, bottom;
353 getContentsMargins(&left, &top, &right, &bottom);
390 getContentsMargins(&left, &top, &right, &bottom);
@@ -379,6 +416,49 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
379 }
416 }
380 size += QSize(left + right, top + bottom);
417 size += QSize(left + right, top + bottom);
381 return size;
418 return size;
419 */
420 // New markers -->>
421 QSizeF size(0, 0);
422 qreal left, top, right, bottom;
423 getContentsMargins(&left, &top, &right, &bottom);
424
425 if(constraint.isValid()) {
426 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
427 LegendMarkerItem *item = marker->d_ptr.data()->item();
428 size = size.expandedTo(item->effectiveSizeHint(which));
429 }
430 size = size.boundedTo(constraint);
431 }
432 else if (constraint.width() >= 0) {
433 qreal width = 0;
434 qreal height = 0;
435 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
436 LegendMarkerItem *item = marker->d_ptr.data()->item();
437 width+=item->effectiveSizeHint(which).width();
438 height=qMax(height,item->effectiveSizeHint(which).height());
439 }
440
441 size = QSizeF(qMin(constraint.width(),width), height);
442 }
443 else if (constraint.height() >= 0) {
444 qreal width = 0;
445 qreal height = 0;
446 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
447 LegendMarkerItem *item = marker->d_ptr.data()->item();
448 width=qMax(width,item->effectiveSizeHint(which).width());
449 height+=height,item->effectiveSizeHint(which).height();
450 }
451 size = QSizeF(width,qMin(constraint.height(),height));
452 }
453 else {
454 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
455 LegendMarkerItem *item = marker->d_ptr.data()->item();
456 size = size.expandedTo(item->effectiveSizeHint(which));
457 }
458 }
459 size += QSize(left + right, top + bottom);
460 return size;
461 // <<-- New markers
382 }
462 }
383
463
384 QTCOMMERCIALCHART_END_NAMESPACE
464 QTCOMMERCIALCHART_END_NAMESPACE
@@ -33,15 +33,17 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject
33 QGraphicsObject(parent),
33 QGraphicsObject(parent),
34 m_marker(marker),
34 m_marker(marker),
35 m_markerRect(0,0,10.0,10.0),
35 m_markerRect(0,0,10.0,10.0),
36 m_boundingRect(0,0,0,0),
36 m_boundingRect(0,0,10,10),
37 m_textItem(new QGraphicsSimpleTextItem(this)),
37 m_textItem(new QGraphicsSimpleTextItem(this)),
38 m_rectItem(new QGraphicsRectItem(this)),
38 m_rectItem(new QGraphicsRectItem(this)),
39 m_margin(4),
39 m_margin(4),
40 m_space(4)
40 m_space(4)
41 {
41 {
42 qDebug() << "LegendMarkerItem created for marker:" << m_marker;
42 // qDebug() << "LegendMarkerItem created for marker:" << m_marker;
43 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
43 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
44 m_rectItem->setRect(m_markerRect);
44 m_rectItem->setRect(m_markerRect);
45 // setZValue(zValue() + 20);
46 // qDebug() << "z:" << this->zValue();
45 }
47 }
46
48
47 void LegendMarkerItem::setPen(const QPen &pen)
49 void LegendMarkerItem::setPen(const QPen &pen)
@@ -79,6 +81,7 QFont LegendMarkerItem::font() const
79
81
80 void LegendMarkerItem::setLabel(const QString label)
82 void LegendMarkerItem::setLabel(const QString label)
81 {
83 {
84 qDebug() << "LegendMarkerItem::setlabel" << label;
82 m_text = label;
85 m_text = label;
83 updateGeometry();
86 updateGeometry();
84 }
87 }
@@ -88,11 +91,6 QString LegendMarkerItem::label() const
88 return m_text;
91 return m_text;
89 }
92 }
90
93
91 QRectF LegendMarkerItem::boundingRect() const
92 {
93 return m_boundingRect;
94 }
95
96 void LegendMarkerItem::setLabelBrush(const QBrush &brush)
94 void LegendMarkerItem::setLabelBrush(const QBrush &brush)
97 {
95 {
98 m_textItem->setBrush(brush);
96 m_textItem->setBrush(brush);
@@ -103,10 +101,9 QBrush LegendMarkerItem::labelBrush() const
103 return m_textItem->brush();
101 return m_textItem->brush();
104 }
102 }
105
103
106
107 void LegendMarkerItem::setGeometry(const QRectF& rect)
104 void LegendMarkerItem::setGeometry(const QRectF& rect)
108 {
105 {
109 QFontMetrics fn (font());
106 QFontMetrics fn (m_font);
110
107
111 int width = rect.width();
108 int width = rect.width();
112 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
109 qreal x = m_margin + m_markerRect.width() + m_space + m_margin;
@@ -133,6 +130,11 void LegendMarkerItem::setGeometry(const QRectF& rect)
133 m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y);
130 m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y);
134 }
131 }
135
132
133 QRectF LegendMarkerItem::boundingRect() const
134 {
135 return m_boundingRect;
136 }
137
136 void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
138 void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
137 {
139 {
138 Q_UNUSED(option)
140 Q_UNUSED(option)
@@ -32,6 +32,7
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QGraphicsObject>
34 #include <QGraphicsObject>
35 #include <QFont>
35 #include <QBrush>
36 #include <QBrush>
36 #include <QPen>
37 #include <QPen>
37 #include <QGraphicsSimpleTextItem>
38 #include <QGraphicsSimpleTextItem>
@@ -46,7 +47,6 class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem
46 Q_OBJECT
47 Q_OBJECT
47 Q_INTERFACES(QGraphicsLayoutItem)
48 Q_INTERFACES(QGraphicsLayoutItem)
48 public:
49 public:
49 // explicit LegendMarkerItem(QAbstractSeries *m_series, QGraphicsObject *parent = 0);
50 explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = 0);
50 explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = 0);
51
51
52 void setPen(const QPen &pen);
52 void setPen(const QPen &pen);
@@ -77,7 +77,7 protected:
77 void mousePressEvent(QGraphicsSceneMouseEvent *event);
77 void mousePressEvent(QGraphicsSceneMouseEvent *event);
78
78
79 protected:
79 protected:
80 QLegendMarkerPrivate *m_marker;
80 QLegendMarkerPrivate *m_marker; // Knows
81 QRectF m_markerRect;
81 QRectF m_markerRect;
82 QRectF m_boundingRect;
82 QRectF m_boundingRect;
83 QGraphicsSimpleTextItem *m_textItem;
83 QGraphicsSimpleTextItem *m_textItem;
@@ -86,6 +86,15 protected:
86 qreal m_space;
86 qreal m_space;
87 QString m_text;
87 QString m_text;
88
88
89 QString m_label;
90 QBrush m_labelBrush;
91 QFont m_font;
92 QPen m_pen;
93 QBrush m_brush;
94 bool m_visible;
95
96 friend class QLegendMarkerPrivate;
97 friend class LegendLayout;
89 };
98 };
90
99
91 QTCOMMERCIALCHART_END_NAMESPACE
100 QTCOMMERCIALCHART_END_NAMESPACE
@@ -510,9 +510,7 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
510 marker->setFont(m_font);
510 marker->setFont(m_font);
511 marker->setLabelBrush(m_labelBrush);
511 marker->setLabelBrush(m_labelBrush);
512 marker->setVisible(series->isVisible());
512 marker->setVisible(series->isVisible());
513 // TODO: possible hazard. What if marker is deleted and group still has pointer?
514 m_items->addToGroup(marker->d_ptr.data()->item());
513 m_items->addToGroup(marker->d_ptr.data()->item());
515 // qDebug() << "item:" << marker->d_ptr.data()->item();
516 m_legendMarkers << marker;
514 m_legendMarkers << marker;
517 }
515 }
518
516
@@ -44,77 +44,69 QLegendMarker::~QLegendMarker()
44
44
45 QString QLegendMarker::label() const
45 QString QLegendMarker::label() const
46 {
46 {
47 return d_ptr->m_label;
47 return d_ptr->label();
48 }
48 }
49
49
50 void QLegendMarker::setLabel(const QString &label)
50 void QLegendMarker::setLabel(const QString &label)
51 {
51 {
52 d_ptr->m_label = label;
52 d_ptr->setLabel(label);
53 }
53 }
54
54
55 QBrush QLegendMarker::labelBrush() const
55 QBrush QLegendMarker::labelBrush() const
56 {
56 {
57 return d_ptr->m_labelBrush;
57 return d_ptr->labelBrush();
58 }
58 }
59
59
60 void QLegendMarker::setLabelBrush(const QBrush &brush)
60 void QLegendMarker::setLabelBrush(const QBrush &brush)
61 {
61 {
62 d_ptr->m_labelBrush = brush;
62 d_ptr->setLabelBrush(brush);
63 }
63 }
64
64
65 QFont QLegendMarker::font() const
65 QFont QLegendMarker::font() const
66 {
66 {
67 return d_ptr->m_font;
67 return d_ptr->font();
68 }
68 }
69
69
70 void QLegendMarker::setFont(const QFont &font)
70 void QLegendMarker::setFont(const QFont &font)
71 {
71 {
72 d_ptr->m_font = font;
72 d_ptr->setFont(font);
73 }
73 }
74
74
75 QPen QLegendMarker::pen() const
75 QPen QLegendMarker::pen() const
76 {
76 {
77 return d_ptr->m_pen;
77 return d_ptr->pen();
78 }
78 }
79
79
80 void QLegendMarker::setPen(const QPen &pen)
80 void QLegendMarker::setPen(const QPen &pen)
81 {
81 {
82 d_ptr->m_pen = pen;
82 d_ptr->setPen(pen);
83 }
83 }
84
84
85 QBrush QLegendMarker::brush() const
85 QBrush QLegendMarker::brush() const
86 {
86 {
87 return d_ptr->m_brush;
87 return d_ptr->brush();
88 }
88 }
89
89
90 void QLegendMarker::setBrush(const QBrush &brush)
90 void QLegendMarker::setBrush(const QBrush &brush)
91 {
91 {
92 d_ptr->m_brush = brush;
92 d_ptr->setBrush(brush);
93 }
93 }
94
94
95 bool QLegendMarker::isVisible() const
95 bool QLegendMarker::isVisible() const
96 {
96 {
97 return d_ptr->m_visible;
97 return d_ptr->isVisible();
98 }
98 }
99
99
100 void QLegendMarker::setVisible(bool visible)
100 void QLegendMarker::setVisible(bool visible)
101 {
101 {
102 d_ptr->m_visible = visible;
102 d_ptr->setVisible(visible);
103 }
103 }
104
104
105 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
105 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
106 /*
107 QLegendMarkerPrivate::QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q) :
108 q_ptr(q),
109 m_series(series)
110 {
111 m_item = new LegendMarkerItem(m_series);
112 }
113 */
114 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q) :
106 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q) :
115 q_ptr(q)
107 q_ptr(q)
116 {
108 {
117 qDebug() << "QLegendMarkerPrivate created";
109 // qDebug() << "QLegendMarkerPrivate created";
118 m_item = new LegendMarkerItem(this);
110 m_item = new LegendMarkerItem(this);
119 }
111 }
120
112
@@ -130,6 +122,66 void QLegendMarkerPrivate::handleMousePressEvent(QGraphicsSceneEvent *event)
130 emit q->clicked();
122 emit q->clicked();
131 }
123 }
132
124
125 void QLegendMarkerPrivate::setPen(const QPen &pen)
126 {
127 m_item->setPen(pen);
128 }
129
130 QPen QLegendMarkerPrivate::pen() const
131 {
132 return m_item->pen();
133 }
134
135 void QLegendMarkerPrivate::setBrush(const QBrush &brush)
136 {
137 m_item->setBrush(brush);
138 }
139
140 QBrush QLegendMarkerPrivate::brush() const
141 {
142 return m_item->brush();
143 }
144
145 void QLegendMarkerPrivate::setFont(const QFont &font)
146 {
147 m_item->setFont(font);
148 }
149
150 QFont QLegendMarkerPrivate::font() const
151 {
152 return m_item->font();
153 }
154
155 void QLegendMarkerPrivate::setLabel(const QString label)
156 {
157 m_item->setLabel(label);
158 }
159
160 QString QLegendMarkerPrivate::label() const
161 {
162 return m_item->label();
163 }
164
165 void QLegendMarkerPrivate::setLabelBrush(const QBrush &brush)
166 {
167 m_item->setLabelBrush(brush);
168 }
169
170 QBrush QLegendMarkerPrivate::labelBrush() const
171 {
172 return m_item->labelBrush();
173 }
174
175 bool QLegendMarkerPrivate::isVisible() const
176 {
177 return m_item->isVisible();
178 }
179
180 void QLegendMarkerPrivate::setVisible(bool visible)
181 {
182 m_item->setVisible(visible);
183 }
184
133
185
134 #include "moc_qlegendmarker.cpp"
186 #include "moc_qlegendmarker.cpp"
135 #include "moc_qlegendmarker_p.cpp"
187 #include "moc_qlegendmarker_p.cpp"
@@ -75,14 +75,12 Q_SIGNALS:
75 void clicked();
75 void clicked();
76 void hovered(bool status);
76 void hovered(bool status);
77
77
78 public Q_SLOTS:
79 virtual void updated() = 0; // TODO: private. Idea is that series signals, when some property has changed
80
81 protected:
78 protected:
82 QScopedPointer<QLegendMarkerPrivate> d_ptr;
79 QScopedPointer<QLegendMarkerPrivate> d_ptr;
83 Q_DISABLE_COPY(QLegendMarker)
80 Q_DISABLE_COPY(QLegendMarker)
84 friend class QLegendPrivate;
81 friend class QLegendPrivate;
85 friend class QLegendMarkerPrivate;
82 friend class QLegendMarkerPrivate;
83 friend class LegendLayout;
86 };
84 };
87
85
88 QTCOMMERCIALCHART_END_NAMESPACE
86 QTCOMMERCIALCHART_END_NAMESPACE
@@ -60,7 +60,7 public:
60 // explicit QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q);
60 // explicit QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q);
61 explicit QLegendMarkerPrivate(QLegendMarker *q);
61 explicit QLegendMarkerPrivate(QLegendMarker *q);
62 virtual ~QLegendMarkerPrivate();
62 virtual ~QLegendMarkerPrivate();
63 /*
63
64 void setPen(const QPen &pen);
64 void setPen(const QPen &pen);
65 QPen pen() const;
65 QPen pen() const;
66
66
@@ -75,7 +75,10 public:
75
75
76 void setLabelBrush(const QBrush &brush);
76 void setLabelBrush(const QBrush &brush);
77 QBrush labelBrush() const;
77 QBrush labelBrush() const;
78 */
78
79 bool isVisible() const;
80 void setVisible(bool visible);
81
79 // Helper for now.
82 // Helper for now.
80 LegendMarkerItem* item() const { return m_item; }
83 LegendMarkerItem* item() const { return m_item; }
81
84
@@ -95,13 +98,14 private:
95 */
98 */
96
99
97 // New legend marker properties
100 // New legend marker properties
101 /*
98 QString m_label;
102 QString m_label;
99 QBrush m_labelBrush;
103 QBrush m_labelBrush;
100 QFont m_font;
104 QFont m_font;
101 QPen m_pen;
105 QPen m_pen;
102 QBrush m_brush;
106 QBrush m_brush;
103 bool m_visible;
107 bool m_visible;
104
108 */
105 friend class QLegendPrivate; // TODO: Is this needed?
109 friend class QLegendPrivate; // TODO: Is this needed?
106 Q_DECLARE_PUBLIC(QLegendMarker)
110 Q_DECLARE_PUBLIC(QLegendMarker)
107 };
111 };
@@ -24,23 +24,14
24 #include <QDebug>
24 #include <QDebug>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 /*
27
28 QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject *parent) :
28 QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject *parent) :
29 QLegendMarker(series, parent),
29 QLegendMarker(*new QPieLegendMarkerPrivate(series,slice,this), parent)
30 d_ptr(new QPieLegendMarkerPrivate(series,slice,this))
31 {
30 {
32 QObject::connect(slice, SIGNAL(labelChanged()), this, SLOT(updated()));
33 QObject::connect(slice, SIGNAL(brushChanged()), this, SLOT(updated()));
34 updated();
35 }
31 }
36
32
37 */
33 QPieLegendMarker::~QPieLegendMarker()
38 QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject *parent) :
39 QLegendMarker(*new QPieLegendMarkerPrivate(series,slice,this), parent)
40 {
34 {
41 QObject::connect(slice, SIGNAL(labelChanged()), this, SLOT(updated()));
42 QObject::connect(slice, SIGNAL(brushChanged()), this, SLOT(updated()));
43 // updated();
44 }
35 }
45
36
46 /*!
37 /*!
@@ -65,24 +56,30 QPieSlice* QPieLegendMarker::peerObject()
65
56
66 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
57 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67
58
68 //QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QAbstractSeries *series, QPieLegendMarker *q) :
69 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieSeries *series, QPieSlice *slice, QPieLegendMarker *q) :
59 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieSeries *series, QPieSlice *slice, QPieLegendMarker *q) :
70 QLegendMarkerPrivate(q),
60 QLegendMarkerPrivate(q),
71 m_series(series),
61 m_series(series),
72 m_slice(slice)
62 m_slice(slice)
73 {
63 {
74 qDebug() << "QPieLegendMarkerPrivate created";
64 qDebug() << "QPieLegendMarkerPrivate created";
65 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
66 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
75 updated();
67 updated();
76 }
68 }
77
69
78 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
70 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
79 {
71 {
72 QObject::disconnect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
73 QObject::disconnect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
80 }
74 }
81
75
82 void QPieLegendMarkerPrivate::updated()
76 void QPieLegendMarkerPrivate::updated()
83 {
77 {
78 qDebug() << "QPieLegendMarkerPrivate::updated";
84 m_item->setBrush(m_slice->brush());
79 m_item->setBrush(m_slice->brush());
85 m_item->setLabel(m_slice->label());
80 m_item->setLabel(m_slice->label());
81 m_item->setPen(m_slice->pen());
82 m_item->setBrush(m_slice->brush());
86 }
83 }
87
84
88 #include "moc_qpielegendmarker.cpp"
85 #include "moc_qpielegendmarker.cpp"
@@ -34,6 +34,7 class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker
34
34
35 public:
35 public:
36 explicit QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject *parent = 0);
36 explicit QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject *parent = 0);
37 virtual ~QPieLegendMarker();
37
38
38 virtual QAbstractSeries* series();
39 virtual QAbstractSeries* series();
39 virtual QPieSlice* peerObject();
40 virtual QPieSlice* peerObject();
General Comments 0
You need to be logged in to leave comments. Login now