##// END OF EJS Templates
refactoring
sauimone -
r2167:39840e10ebaa
parent child
Show More
@@ -19,26 +19,19
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "legendmarkeritem_p.h"
21 #include "legendmarkeritem_p.h"
22 #include "qxyseries.h"
23 #include "qxyseries_p.h"
24 #include "qlegend.h"
25 #include "qabstractbarseries.h"
26 #include "qpieseries.h"
27 #include "qpieslice.h"
28 #include "qbarset.h"
29 #include "qbarset_p.h"
30 #include "qareaseries.h"
31 #include "qareaseries_p.h"
32 #include <QPainter>
22 #include <QPainter>
33 #include <QGraphicsSceneEvent>
23 #include <QGraphicsSceneEvent>
34 #include <QGraphicsSimpleTextItem>
24 #include <QGraphicsSimpleTextItem>
35 #include <QDebug>
25 #include <QDebug>
36
26
27 #include "qlegendmarker_p.h"
28
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
30
39 LegendMarkerItem::LegendMarkerItem(QAbstractSeries *series, QGraphicsObject *parent) :
31 //LegendMarkerItem::LegendMarkerItem(QAbstractSeries *series, QGraphicsObject *parent) :
32 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) :
40 QGraphicsObject(parent),
33 QGraphicsObject(parent),
41 m_series(series),
34 m_marker(marker),
42 m_markerRect(0,0,10.0,10.0),
35 m_markerRect(0,0,10.0,10.0),
43 m_boundingRect(0,0,0,0),
36 m_boundingRect(0,0,0,0),
44 m_textItem(new QGraphicsSimpleTextItem(this)),
37 m_textItem(new QGraphicsSimpleTextItem(this)),
@@ -46,7 +39,8 LegendMarkerItem::LegendMarkerItem(QAbstractSeries *series, QGraphicsObject *par
46 m_margin(4),
39 m_margin(4),
47 m_space(4)
40 m_space(4)
48 {
41 {
49 //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
42 qDebug() << "LegendMarkerItem created for marker:" << m_marker;
43 setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
50 m_rectItem->setRect(m_markerRect);
44 m_rectItem->setRect(m_markerRect);
51 }
45 }
52
46
@@ -170,82 +164,10 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint)
170 void LegendMarkerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
164 void LegendMarkerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
171 {
165 {
172 qDebug() << "LegendMarkerItem::mousePressEvent";
166 qDebug() << "LegendMarkerItem::mousePressEvent";
173 QGraphicsObject::mousePressEvent(event);
167 // QGraphicsObject::mousePressEvent(event);
174 //TODO: selected signal removed for now
168 //TODO: selected signal removed for now
175 }
169 emit m_marker->handleMousePressEvent(event);
176
170 QGraphicsItem::mousePressEvent(event);
177 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
178
179 AreaLegendMarkerItem::AreaLegendMarkerItem(QAreaSeries *series,QLegend *legend) : LegendMarkerItem(series,legend),
180 m_series(series)
181 {
182 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
183 // QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
184 // QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated()));
185 updated();
186 }
187
188 void AreaLegendMarkerItem::updated()
189 {
190 setBrush(m_series->brush());
191 setLabel(m_series->name());
192 }
193
194 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
195
196 BarLegendMarkerItem::BarLegendMarkerItem(QAbstractBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarkerItem(barseries,legend),
197 m_barset(barset)
198 {
199 //QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected()));
200 // QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated()));
201 updated();
202 }
203
204 void BarLegendMarkerItem::updated()
205 {
206 setBrush(m_barset->brush());
207 setLabel(m_barset->label());
208 }
209
210 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
211
212 PieLegendMarkerItem::PieLegendMarkerItem(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarkerItem(series,legend),
213 m_pieslice(pieslice)
214 {
215 // QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated()));
216 // QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated()));
217 updated();
218 }
219
220 void PieLegendMarkerItem::updated()
221 {
222 setBrush(m_pieslice->brush());
223 setLabel(m_pieslice->label());
224 }
225
226 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
227
228 XYLegendMarkerItem::XYLegendMarkerItem(QXYSeries *series, QLegend *legend) : LegendMarkerItem(series,legend),
229 m_series(series)
230 {
231 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
232 // QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
233 // QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated()));
234 updated();
235 }
236
237 void XYLegendMarkerItem::updated()
238 {
239 setLabel(m_series->name());
240
241 if(m_series->type()== QAbstractSeries::SeriesTypeScatter)
242 {
243 setBrush(m_series->brush());
244
245 }
246 else {
247 setBrush(QBrush(m_series->pen().color()));
248 }
249 }
171 }
250
172
251 #include "moc_legendmarkeritem_p.cpp"
173 #include "moc_legendmarkeritem_p.cpp"
@@ -39,21 +39,15
39
39
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41
41
42 class QAbstractSeries;
42 class QLegendMarkerPrivate;
43 class QAreaSeries;
44 class QXYSeries;
45 class QBarSet;
46 class QAbstractBarSeries;
47 class QPieSlice;
48 class QLegend;
49 class QPieSeries;
50
43
51 class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem
44 class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem
52 {
45 {
53 Q_OBJECT
46 Q_OBJECT
54 Q_INTERFACES(QGraphicsLayoutItem)
47 Q_INTERFACES(QGraphicsLayoutItem)
55 public:
48 public:
56 explicit LegendMarkerItem(QAbstractSeries *m_series, QGraphicsObject *parent = 0);
49 // explicit LegendMarkerItem(QAbstractSeries *m_series, QGraphicsObject *parent = 0);
50 explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = 0);
57
51
58 void setPen(const QPen &pen);
52 void setPen(const QPen &pen);
59 QPen pen() const;
53 QPen pen() const;
@@ -70,8 +64,6 public:
70 void setLabelBrush(const QBrush &brush);
64 void setLabelBrush(const QBrush &brush);
71 QBrush labelBrush() const;
65 QBrush labelBrush() const;
72
66
73 QAbstractSeries *series() const { return m_series;}
74
75 void setGeometry(const QRectF& rect);
67 void setGeometry(const QRectF& rect);
76
68
77 QRectF boundingRect() const;
69 QRectF boundingRect() const;
@@ -84,14 +76,10 protected:
84 // From QGraphicsObject
76 // From QGraphicsObject
85 void mousePressEvent(QGraphicsSceneMouseEvent *event);
77 void mousePressEvent(QGraphicsSceneMouseEvent *event);
86
78
87 //public Q_SLOTS:
88 //virtual void updated() = 0;
89
90 protected:
79 protected:
91 QAbstractSeries *m_series;
80 QLegendMarkerPrivate *m_marker;
92 QRectF m_markerRect;
81 QRectF m_markerRect;
93 QRectF m_boundingRect;
82 QRectF m_boundingRect;
94 // QLegend* m_legend;
95 QGraphicsSimpleTextItem *m_textItem;
83 QGraphicsSimpleTextItem *m_textItem;
96 QGraphicsRectItem *m_rectItem;
84 QGraphicsRectItem *m_rectItem;
97 qreal m_margin;
85 qreal m_margin;
@@ -100,47 +88,6 protected:
100
88
101 };
89 };
102
90
103 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
104 class XYLegendMarkerItem : public LegendMarkerItem
105 {
106 public:
107 XYLegendMarkerItem(QXYSeries *series, QLegend *legend);
108 protected:
109 void updated();
110 private:
111 QXYSeries *m_series;
112 };
113 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
114 class AreaLegendMarkerItem : public LegendMarkerItem
115 {
116 public:
117 AreaLegendMarkerItem(QAreaSeries *series, QLegend *legend);
118 protected:
119 void updated();
120 private:
121 QAreaSeries *m_series;
122 };
123 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
124 class BarLegendMarkerItem : public LegendMarkerItem
125 {
126 public:
127 BarLegendMarkerItem(QAbstractBarSeries *barseries, QBarSet *barset,QLegend *legend);
128 protected:
129 void updated();
130 private:
131 QBarSet *m_barset;
132 };
133 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
134 class PieLegendMarkerItem : public LegendMarkerItem
135 {
136 public:
137 PieLegendMarkerItem(QPieSeries *pieSeries, QPieSlice *pieslice, QLegend *legend);
138 protected:
139 void updated();
140 private:
141 QPieSlice *m_pieslice;
142 };
143
144 QTCOMMERCIALCHART_END_NAMESPACE
91 QTCOMMERCIALCHART_END_NAMESPACE
145
92
146 #endif // LEGENDMARKERITEM_P_H
93 #endif // LEGENDMARKERITEM_P_H
@@ -24,7 +24,7
24 #include "qabstractseries_p.h"
24 #include "qabstractseries_p.h"
25 #include "qchart_p.h"
25 #include "qchart_p.h"
26 #include "legendlayout_p.h"
26 #include "legendlayout_p.h"
27 #include "legendmarker_p.h"
27 #include "legendmarker_p.h" // TODO: deprecated
28 #include "qxyseries.h"
28 #include "qxyseries.h"
29 #include "qlineseries.h"
29 #include "qlineseries.h"
30 #include "qareaseries.h"
30 #include "qareaseries.h"
@@ -45,6 +45,8
45 #include <QGraphicsSceneEvent>
45 #include <QGraphicsSceneEvent>
46
46
47 #include <QLegendMarker>
47 #include <QLegendMarker>
48 #include "qlegendmarker_p.h"
49 #include "legendmarkeritem_p.h"
48
50
49 QTCOMMERCIALCHART_BEGIN_NAMESPACE
51 QTCOMMERCIALCHART_BEGIN_NAMESPACE
50
52
@@ -401,6 +403,15 QList<QLegendMarker*> QLegend::markers() const
401 return d_ptr->legendMarkers();
403 return d_ptr->legendMarkers();
402 }
404 }
403
405
406 void QLegend::appendSeries(QAbstractSeries* series)
407 {
408 d_ptr->appendSeries(series);
409 }
410
411 void QLegend::removeSeries(QAbstractSeries* series)
412 {
413 d_ptr->removeSeries(series);
414 }
404
415
405 /*!
416 /*!
406 \internal \a event see QGraphicsWidget for details
417 \internal \a event see QGraphicsWidget for details
@@ -463,6 +474,30 int QLegendPrivate::roundness(qreal size)
463 return 100 * m_diameter / int(size);
474 return 100 * m_diameter / int(size);
464 }
475 }
465
476
477 void QLegendPrivate::appendSeries(QAbstractSeries* series)
478 {
479 Q_UNUSED(series);
480 // TODO:
481 /*
482 if (!m_series.contains(series)) {
483 m_series.append(series);
484 handleSeriesAdded(series,0); // Dummy domain
485 }
486 */
487 }
488
489 void QLegendPrivate::removeSeries(QAbstractSeries* series)
490 {
491 Q_UNUSED(series);
492 // TODO:
493 /*
494 if (m_series.contains(series)) {
495 m_series.removeOne(series);
496 handleSeriesRemoved(series);
497 }
498 */
499 }
500
466 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
501 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
467 {
502 {
468 Q_UNUSED(domain)
503 Q_UNUSED(domain)
@@ -475,9 +510,9 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
475 marker->setFont(m_font);
510 marker->setFont(m_font);
476 marker->setLabelBrush(m_labelBrush);
511 marker->setLabelBrush(m_labelBrush);
477 marker->setVisible(series->isVisible());
512 marker->setVisible(series->isVisible());
478 // TODO: QLegendMarker has QGraphicsItem vs QLegendMarker is QGraphicsItem
479 // TODO: possible hazard. What if marker is deleted and group still has pointer?
513 // TODO: possible hazard. What if marker is deleted and group still has pointer?
480 // m_items->addToGroup(marker->d_ptr.data());
514 m_items->addToGroup(marker->d_ptr.data()->item());
515 // qDebug() << "item:" << marker->d_ptr.data()->item();
481 m_legendMarkers << marker;
516 m_legendMarkers << marker;
482 }
517 }
483
518
@@ -28,15 +28,10
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QPieSlice;
32 class QXYSeries;
33 class QBarSet;
34 class QAbstractBarSeries;
35 class QPieSeries;
36 class QAreaSeries;
37 class QChart;
31 class QChart;
38 class QLegendPrivate;
32 class QLegendPrivate;
39 class QLegendMarker;
33 class QLegendMarker;
34 class QAbstractSeries;
40
35
41 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
36 class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget
42 {
37 {
@@ -86,6 +81,8 public:
86
81
87 // New stuff:
82 // New stuff:
88 QList <QLegendMarker*> markers() const;
83 QList <QLegendMarker*> markers() const;
84 void appendSeries(QAbstractSeries* series);
85 void removeSeries(QAbstractSeries* series);
89
86
90 protected:
87 protected:
91 void hideEvent(QHideEvent *event);
88 void hideEvent(QHideEvent *event);
@@ -58,6 +58,8 public:
58
58
59 // New stuff:
59 // New stuff:
60 QList<QLegendMarker*> legendMarkers() { return m_legendMarkers; } // TODO: function name will change
60 QList<QLegendMarker*> legendMarkers() { return m_legendMarkers; } // TODO: function name will change
61 void appendSeries(QAbstractSeries* series);
62 void removeSeries(QAbstractSeries* series);
61
63
62 public Q_SLOTS:
64 public Q_SLOTS:
63 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
65 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
@@ -85,6 +87,7 private:
85 friend class QLegend;
87 friend class QLegend;
86 friend class LegendLayout;
88 friend class LegendLayout;
87 QList<QLegendMarker*> m_legendMarkers; // TODO: rename to m_markers eventually.
89 QList<QLegendMarker*> m_legendMarkers; // TODO: rename to m_markers eventually.
90 QList<QAbstractSeries*> m_series;
88
91
89 };
92 };
90
93
@@ -25,12 +25,18
25 #include <QFontMetrics>
25 #include <QFontMetrics>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28 /*
29 QLegendMarker::QLegendMarker(QAbstractSeries* series, QObject *parent) :
29 QLegendMarker::QLegendMarker(QAbstractSeries* series, QObject *parent) :
30 QObject(parent),
30 QObject(parent),
31 d_ptr(new QLegendMarkerPrivate(series, this))
31 d_ptr(new QLegendMarkerPrivate(series, this))
32 {
32 {
33 }
33 }
34 */
35 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
36 QObject(parent),
37 d_ptr(&d)
38 {
39 }
34
40
35 QLegendMarker::~QLegendMarker()
41 QLegendMarker::~QLegendMarker()
36 {
42 {
@@ -96,24 +102,34 void QLegendMarker::setVisible(bool visible)
96 d_ptr->m_visible = visible;
102 d_ptr->m_visible = visible;
97 }
103 }
98
104
99 QAbstractSeries* QLegendMarker::series()
100 {
101 return d_ptr->m_series;
102 }
103
104 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
105 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
105
106 /*
106 QLegendMarkerPrivate::QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q) :
107 QLegendMarkerPrivate::QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q) :
107 q_ptr(q),
108 q_ptr(q),
108 m_series(series)
109 m_series(series)
109 {
110 {
110 m_item = new LegendMarkerItem(m_series);
111 m_item = new LegendMarkerItem(m_series);
111 }
112 }
113 */
114 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q) :
115 q_ptr(q)
116 {
117 qDebug() << "QLegendMarkerPrivate created";
118 m_item = new LegendMarkerItem(this);
119 }
112
120
113 QLegendMarkerPrivate::~QLegendMarkerPrivate()
121 QLegendMarkerPrivate::~QLegendMarkerPrivate()
114 {
122 {
115 }
123 }
116
124
125 void QLegendMarkerPrivate::handleMousePressEvent(QGraphicsSceneEvent *event)
126 {
127 // Just emit clicked signal for now
128 Q_UNUSED(event);
129 Q_Q(QLegendMarker);
130 emit q->clicked();
131 }
132
117
133
118 #include "moc_qlegendmarker.cpp"
134 #include "moc_qlegendmarker.cpp"
119 #include "moc_qlegendmarker_p.cpp"
135 #include "moc_qlegendmarker_p.cpp"
@@ -43,7 +43,7 class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject
43 // Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged);
43 // Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged);
44
44
45 public:
45 public:
46 explicit QLegendMarker(QAbstractSeries* series, QObject *parent = 0);
46 // explicit QLegendMarker(QAbstractSeries* series, QObject *parent = 0);
47 virtual ~QLegendMarker();
47 virtual ~QLegendMarker();
48
48
49 QString label() const;
49 QString label() const;
@@ -64,10 +64,13 public:
64 bool isVisible() const;
64 bool isVisible() const;
65 void setVisible(bool visible);
65 void setVisible(bool visible);
66
66
67 // virtual QAbstractSeries::SeriesType type() = 0;
67 // virtual QAbstractSeries::SeriesType type() = 0; // TODO?
68 virtual QAbstractSeries* series();
68 virtual QAbstractSeries* series() = 0;
69 virtual QObject* peerObject() = 0;
69 virtual QObject* peerObject() = 0;
70
70
71 protected:
72 explicit QLegendMarker(QLegendMarkerPrivate &d, QObject *parent = 0);
73
71 Q_SIGNALS:
74 Q_SIGNALS:
72 void clicked();
75 void clicked();
73 void hovered(bool status);
76 void hovered(bool status);
@@ -75,10 +78,11 Q_SIGNALS:
75 public Q_SLOTS:
78 public Q_SLOTS:
76 virtual void updated() = 0; // TODO: private. Idea is that series signals, when some property has changed
79 virtual void updated() = 0; // TODO: private. Idea is that series signals, when some property has changed
77
80
78 public:
81 protected:
79 QScopedPointer<QLegendMarkerPrivate> d_ptr;
82 QScopedPointer<QLegendMarkerPrivate> d_ptr;
80 Q_DISABLE_COPY(QLegendMarker)
83 Q_DISABLE_COPY(QLegendMarker)
81
84 friend class QLegendPrivate;
85 friend class QLegendMarkerPrivate;
82 };
86 };
83
87
84 QTCOMMERCIALCHART_END_NAMESPACE
88 QTCOMMERCIALCHART_END_NAMESPACE
@@ -36,6 +36,7
36 #include <QPen>
36 #include <QPen>
37 #include <QGraphicsSimpleTextItem>
37 #include <QGraphicsSimpleTextItem>
38 #include <QGraphicsLayoutItem>
38 #include <QGraphicsLayoutItem>
39 #include <QDebug>
39
40
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41
42
@@ -56,7 +57,8 class QLegendMarkerPrivate : public QObject
56 {
57 {
57 Q_OBJECT
58 Q_OBJECT
58 public:
59 public:
59 explicit QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q);
60 // explicit QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q);
61 explicit QLegendMarkerPrivate(QLegendMarker *q);
60 virtual ~QLegendMarkerPrivate();
62 virtual ~QLegendMarkerPrivate();
61 /*
63 /*
62 void setPen(const QPen &pen);
64 void setPen(const QPen &pen);
@@ -74,21 +76,25 public:
74 void setLabelBrush(const QBrush &brush);
76 void setLabelBrush(const QBrush &brush);
75 QBrush labelBrush() const;
77 QBrush labelBrush() const;
76 */
78 */
79 // Helper for now.
80 LegendMarkerItem* item() const { return m_item; }
81
82 // Item gets the event, logic for event is here
83 void handleMousePressEvent(QGraphicsSceneEvent *event);
77
84
78 public Q_SLOTS:
85 public Q_SLOTS:
79 virtual void updated() {};
86 virtual void updated() {};
80
87
81 private:
88 protected:
82 QLegendMarker *q_ptr;
83
84 LegendMarkerItem *m_item;
89 LegendMarkerItem *m_item;
85
90
91 private:
92 QLegendMarker *q_ptr;
86 /*
93 /*
87 QLegend* m_legend;
94 QLegend* m_legend;
88 */
95 */
89
96
90 // New legend marker properties
97 // New legend marker properties
91 QAbstractSeries* m_series;
92 QString m_label;
98 QString m_label;
93 QBrush m_labelBrush;
99 QBrush m_labelBrush;
94 QFont m_font;
100 QFont m_font;
@@ -96,14 +102,6 private:
96 QBrush m_brush;
102 QBrush m_brush;
97 bool m_visible;
103 bool m_visible;
98
104
99 // Implementation details of new marker
100 QRectF m_markerRect;
101 QRectF m_boundingRect;
102 QGraphicsSimpleTextItem *m_textItem;
103 QGraphicsRectItem *m_rectItem;
104 qreal m_margin;
105 qreal m_space;
106
107 friend class QLegendPrivate; // TODO: Is this needed?
105 friend class QLegendPrivate; // TODO: Is this needed?
108 Q_DECLARE_PUBLIC(QLegendMarker)
106 Q_DECLARE_PUBLIC(QLegendMarker)
109 };
107 };
@@ -21,41 +21,70
21 #include "qpielegendmarker.h"
21 #include "qpielegendmarker.h"
22 #include "qpielegendmarker_p.h"
22 #include "qpielegendmarker_p.h"
23 #include <QPieSeries>
23 #include <QPieSeries>
24 #include <QDebug>
24
25
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
27 /*
27 QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject *parent) :
28 QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject *parent) :
28 QLegendMarker(series, parent),
29 QLegendMarker(series, parent),
29 m_slice(slice)
30 d_ptr(new QPieLegendMarkerPrivate(series,slice,this))
30 {
31 {
31 QObject::connect(slice, SIGNAL(labelChanged()), this, SLOT(updated()));
32 QObject::connect(slice, SIGNAL(labelChanged()), this, SLOT(updated()));
32 QObject::connect(slice, SIGNAL(brushChanged()), this, SLOT(updated()));
33 QObject::connect(slice, SIGNAL(brushChanged()), this, SLOT(updated()));
33 updated();
34 updated();
34 }
35 }
35
36
36 QPieSlice* QPieLegendMarker::peerObject()
37 */
38 QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject *parent) :
39 QLegendMarker(*new QPieLegendMarkerPrivate(series,slice,this), parent)
40 {
41 QObject::connect(slice, SIGNAL(labelChanged()), this, SLOT(updated()));
42 QObject::connect(slice, SIGNAL(brushChanged()), this, SLOT(updated()));
43 // updated();
44 }
45
46 /*!
47 \internal
48 */
49 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
50 QLegendMarker(d, parent)
37 {
51 {
38 return m_slice;
39 }
52 }
40
53
41 void QPieLegendMarker::updated()
54 QAbstractSeries* QPieLegendMarker::series()
42 {
55 {
43 // TODO: to PIMPL.
56 Q_D(QPieLegendMarker);
44 setBrush(m_slice->brush());
57 return d->m_series;
45 setLabel(m_slice->label());
58 }
59
60 QPieSlice* QPieLegendMarker::peerObject()
61 {
62 Q_D(QPieLegendMarker);
63 return d->m_slice;
46 }
64 }
47
65
48 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49
67
50 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QAbstractSeries *series, QPieLegendMarker *q) :
68 //QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QAbstractSeries *series, QPieLegendMarker *q) :
51 QLegendMarkerPrivate(series, q)
69 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieSeries *series, QPieSlice *slice, QPieLegendMarker *q) :
70 QLegendMarkerPrivate(q),
71 m_series(series),
72 m_slice(slice)
52 {
73 {
74 qDebug() << "QPieLegendMarkerPrivate created";
75 updated();
53 }
76 }
54
77
55 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
78 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
56 {
79 {
57 }
80 }
58
81
82 void QPieLegendMarkerPrivate::updated()
83 {
84 m_item->setBrush(m_slice->brush());
85 m_item->setLabel(m_slice->label());
86 }
87
59 #include "moc_qpielegendmarker.cpp"
88 #include "moc_qpielegendmarker.cpp"
60 #include "moc_qpielegendmarker_p.cpp"
89 #include "moc_qpielegendmarker_p.cpp"
61
90
@@ -35,22 +35,20 class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker
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
37
38 virtual QAbstractSeries* series();
38 virtual QPieSlice* peerObject();
39 virtual QPieSlice* peerObject();
39
40
40 // TODO: to pimpl.
41 protected:
41 void updated();
42 QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent = 0);
42
43
43 //Q_SIGNALS:
44 //Q_SIGNALS:
44
45
45 //public Q_SLOTS:
46 //public Q_SLOTS:
46
47
47 private:
48 private:
48 QScopedPointer<QPieLegendMarkerPrivate> d_ptr;
49 Q_DECLARE_PRIVATE(QPieLegendMarker)
49 Q_DISABLE_COPY(QPieLegendMarker)
50 Q_DISABLE_COPY(QPieLegendMarker)
50
51
51 // TODO: PIMPL
52 QPieSlice* m_slice;
53
54 };
52 };
55
53
56 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
@@ -33,6 +33,10
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qlegendmarker_p.h"
34 #include "qlegendmarker_p.h"
35 #include "legendmarkeritem_p.h"
35 #include "legendmarkeritem_p.h"
36 #include <QPieSeries>
37 #include <QPieSlice>
38
39 #include <QDebug>
36
40
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
42
@@ -42,15 +46,18 class QPieLegendMarkerPrivate : public QLegendMarkerPrivate
42 {
46 {
43 Q_OBJECT
47 Q_OBJECT
44 public:
48 public:
45 explicit QPieLegendMarkerPrivate(QAbstractSeries *series, QPieLegendMarker *q);
49 // explicit QPieLegendMarkerPrivate(QAbstractSeries *series, QPieLegendMarker *q);
50 explicit QPieLegendMarkerPrivate(QPieSeries *series, QPieSlice *slice, QPieLegendMarker *q);
46 virtual ~QPieLegendMarkerPrivate();
51 virtual ~QPieLegendMarkerPrivate();
47
52
48 public Q_SLOTS:
53 public Q_SLOTS:
49 virtual void updated() {};
54 virtual void updated();
50
55
51 private:
56 private:
52 QPieLegendMarker *q_ptr;
57 QPieLegendMarker *q_ptr;
53 PieLegendMarkerItem *m_item;
58
59 QPieSeries* m_series;
60 QPieSlice* m_slice;
54
61
55 friend class QLegendPrivate; // TODO: Is this needed?
62 friend class QLegendPrivate; // TODO: Is this needed?
56 Q_DECLARE_PUBLIC(QPieLegendMarker)
63 Q_DECLARE_PUBLIC(QPieLegendMarker)
@@ -865,11 +865,11 QList<LegendMarker *> QPieSeriesPrivate::createLegendMarker(QLegend *legend)
865
865
866 QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend)
866 QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend)
867 {
867 {
868 Q_UNUSED(legend);
868 // Q_UNUSED(legend);
869 Q_Q(QPieSeries);
869 Q_Q(QPieSeries);
870 QList<QLegendMarker*> markers;
870 QList<QLegendMarker*> markers;
871 foreach(QPieSlice* slice, q->slices()) {
871 foreach(QPieSlice* slice, q->slices()) {
872 QPieLegendMarker* marker = new QPieLegendMarker(q,slice);
872 QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend);
873 markers << marker;
873 markers << marker;
874 }
874 }
875 return markers;
875 return markers;
General Comments 0
You need to be logged in to leave comments. Login now