##// END OF EJS Templates
barset: selected is now private signal
sauimone -
r1017:d84649cce525
parent child
Show More
@@ -1,304 +1,303
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarset.h"
21 #include "qbarset.h"
22 #include "qbarset_p.h"
22 #include "qbarset_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QBarSet
27 \class QBarSet
28 \brief part of QtCommercial chart API.
28 \brief part of QtCommercial chart API.
29
29
30 QBarSet represents one set of bars. Set of bars contains one data value for each category.
30 QBarSet represents one set of bars. Set of bars contains one data value for each category.
31 First value of set is assumed to belong to first category, second to second category and so on.
31 First value of set is assumed to belong to first category, second to second category and so on.
32 If set has fewer values than there are categories, then the missing values are assumed to be
32 If set has fewer values than there are categories, then the missing values are assumed to be
33 at the end of set. For missing values in middle of a set, numerical value of zero is used.
33 at the end of set. For missing values in middle of a set, numerical value of zero is used.
34
34
35 \mainclass
35 \mainclass
36
36
37 \sa QBarSeries, QStackedBarSeries, QPercentBarSeries
37 \sa QBarSeries, QStackedBarSeries, QPercentBarSeries
38 */
38 */
39
39
40 /*!
40 /*!
41 \fn void QBarSet::clicked(QString category)
41 \fn void QBarSet::clicked(QString category)
42 \brief signals that set has been clicked
42 \brief signals that set has been clicked
43 Parameter \a category describes on which category was clicked
43 Parameter \a category describes on which category was clicked
44 */
44 */
45
45
46 /*!
46 /*!
47 \fn void QBarSet::hovered(bool status)
47 \fn void QBarSet::hovered(bool status)
48 \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left.
48 \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left.
49
49
50 The signal is emitted if mouse is hovered on top of set
50 The signal is emitted if mouse is hovered on top of set
51 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
51 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
52 */
52 */
53
53
54 /*!
54 /*!
55 Constructs QBarSet with a name of \a name and with parent of \a parent
55 Constructs QBarSet with a name of \a name and with parent of \a parent
56 */
56 */
57 QBarSet::QBarSet(const QString name, QObject *parent)
57 QBarSet::QBarSet(const QString name, QObject *parent)
58 : QObject(parent)
58 : QObject(parent)
59 ,d_ptr(new QBarSetPrivate(name,this))
59 ,d_ptr(new QBarSetPrivate(name,this))
60 {
60 {
61 }
61 }
62
62
63 /*!
63 /*!
64 Destroys the barset
64 Destroys the barset
65 */
65 */
66 QBarSet::~QBarSet()
66 QBarSet::~QBarSet()
67 {
67 {
68 // NOTE: d_ptr destroyed by QObject
68 // NOTE: d_ptr destroyed by QObject
69 }
69 }
70
70
71 /*!
71 /*!
72 Sets new \a name for set.
72 Sets new \a name for set.
73 */
73 */
74 void QBarSet::setName(const QString name)
74 void QBarSet::setName(const QString name)
75 {
75 {
76 d_ptr->m_name = name;
76 d_ptr->m_name = name;
77 }
77 }
78
78
79 /*!
79 /*!
80 Returns name of the set.
80 Returns name of the set.
81 */
81 */
82 QString QBarSet::name() const
82 QString QBarSet::name() const
83 {
83 {
84 return d_ptr->m_name;
84 return d_ptr->m_name;
85 }
85 }
86
86
87 /*!
87 /*!
88 Appends new value \a value to the end of set.
88 Appends new value \a value to the end of set.
89 */
89 */
90 void QBarSet::append(const qreal value)
90 void QBarSet::append(const qreal value)
91 {
91 {
92 d_ptr->m_values.append(value);
92 d_ptr->m_values.append(value);
93 emit d_ptr->restructuredBars();
93 emit d_ptr->restructuredBars();
94 }
94 }
95
95
96 /*!
96 /*!
97 Appends new value \a value to the end of set.
97 Appends new value \a value to the end of set.
98 */
98 */
99 QBarSet& QBarSet::operator << (const qreal &value)
99 QBarSet& QBarSet::operator << (const qreal &value)
100 {
100 {
101 append(value);
101 append(value);
102 return *this;
102 return *this;
103 }
103 }
104
104
105 /*!
105 /*!
106 Inserts new \a value on the \a index position.
106 Inserts new \a value on the \a index position.
107 The value that is currently at this postion is moved to postion index + 1
107 The value that is currently at this postion is moved to postion index + 1
108 \sa remove()
108 \sa remove()
109 */
109 */
110 void QBarSet::insert(const int index, const qreal value)
110 void QBarSet::insert(const int index, const qreal value)
111 {
111 {
112 d_ptr->m_values.insert(index, value);
112 d_ptr->m_values.insert(index, value);
113 emit d_ptr->updatedBars();
113 emit d_ptr->updatedBars();
114 }
114 }
115
115
116 /*!
116 /*!
117 Removes the value specified by \a index
117 Removes the value specified by \a index
118 \sa insert()
118 \sa insert()
119 */
119 */
120 void QBarSet::remove(const int index)
120 void QBarSet::remove(const int index)
121 {
121 {
122 d_ptr->m_values.removeAt(index);
122 d_ptr->m_values.removeAt(index);
123 emit d_ptr->updatedBars();
123 emit d_ptr->updatedBars();
124 }
124 }
125
125
126 /*!
126 /*!
127 Sets a new value \a value to set, indexed by \a index
127 Sets a new value \a value to set, indexed by \a index
128 */
128 */
129 void QBarSet::replace(const int index, const qreal value)
129 void QBarSet::replace(const int index, const qreal value)
130 {
130 {
131 d_ptr->m_values.replace(index,value);
131 d_ptr->m_values.replace(index,value);
132 emit d_ptr->updatedBars();
132 emit d_ptr->updatedBars();
133 }
133 }
134
134
135 /*!
135 /*!
136 Returns value of set indexed by \a index
136 Returns value of set indexed by \a index
137 */
137 */
138 qreal QBarSet::at(const int index) const
138 qreal QBarSet::at(const int index) const
139 {
139 {
140 return d_ptr->m_values.at(index);
140 return d_ptr->m_values.at(index);
141 }
141 }
142
142
143 /*!
143 /*!
144 Returns value of set indexed by \a index
144 Returns value of set indexed by \a index
145 */
145 */
146 qreal QBarSet::operator [] (int index) const
146 qreal QBarSet::operator [] (int index) const
147 {
147 {
148 return d_ptr->m_values.at(index);
148 return d_ptr->m_values.at(index);
149 }
149 }
150
150
151 /*!
151 /*!
152 Returns count of values in set.
152 Returns count of values in set.
153 */
153 */
154 int QBarSet::count() const
154 int QBarSet::count() const
155 {
155 {
156 return d_ptr->m_values.count();
156 return d_ptr->m_values.count();
157 }
157 }
158
158
159 /*!
159 /*!
160 Returns sum of all values in barset.
160 Returns sum of all values in barset.
161 */
161 */
162 qreal QBarSet::sum() const
162 qreal QBarSet::sum() const
163 {
163 {
164 qreal total(0);
164 qreal total(0);
165 for (int i=0; i < d_ptr->m_values.count(); i++) {
165 for (int i=0; i < d_ptr->m_values.count(); i++) {
166 total += d_ptr->m_values.at(i);
166 total += d_ptr->m_values.at(i);
167 }
167 }
168 return total;
168 return total;
169 }
169 }
170
170
171 /*!
171 /*!
172 Sets pen for set. Bars of this set are drawn using \a pen
172 Sets pen for set. Bars of this set are drawn using \a pen
173 */
173 */
174 void QBarSet::setPen(const QPen &pen)
174 void QBarSet::setPen(const QPen &pen)
175 {
175 {
176 if(d_ptr->m_pen!=pen){
176 if(d_ptr->m_pen!=pen){
177 d_ptr->m_pen = pen;
177 d_ptr->m_pen = pen;
178 emit d_ptr->updatedBars();
178 emit d_ptr->updatedBars();
179 }
179 }
180 }
180 }
181
181
182 /*!
182 /*!
183 Returns pen of the set.
183 Returns pen of the set.
184 */
184 */
185 QPen QBarSet::pen() const
185 QPen QBarSet::pen() const
186 {
186 {
187 return d_ptr->m_pen;
187 return d_ptr->m_pen;
188 }
188 }
189
189
190 /*!
190 /*!
191 Sets brush for the set. Bars of this set are drawn using \a brush
191 Sets brush for the set. Bars of this set are drawn using \a brush
192 */
192 */
193 void QBarSet::setBrush(const QBrush &brush)
193 void QBarSet::setBrush(const QBrush &brush)
194 {
194 {
195 if(d_ptr->m_brush!=brush){
195 if(d_ptr->m_brush!=brush){
196 d_ptr->m_brush = brush;
196 d_ptr->m_brush = brush;
197 emit d_ptr->updatedBars();
197 emit d_ptr->updatedBars();
198 }
198 }
199 }
199 }
200
200
201 /*!
201 /*!
202 Returns brush of the set.
202 Returns brush of the set.
203 */
203 */
204 QBrush QBarSet::brush() const
204 QBrush QBarSet::brush() const
205 {
205 {
206 return d_ptr->m_brush;
206 return d_ptr->m_brush;
207 }
207 }
208
208
209 /*!
209 /*!
210 Sets \a pen of the values that are drawn on top of this barset
210 Sets \a pen of the values that are drawn on top of this barset
211 */
211 */
212 void QBarSet::setLabelPen(const QPen &pen)
212 void QBarSet::setLabelPen(const QPen &pen)
213 {
213 {
214 if(d_ptr->m_labelPen!=pen){
214 if(d_ptr->m_labelPen!=pen){
215 d_ptr->m_labelPen = pen;
215 d_ptr->m_labelPen = pen;
216 emit d_ptr->updatedBars();
216 emit d_ptr->updatedBars();
217 }
217 }
218 }
218 }
219
219
220 /*!
220 /*!
221 Returns pen of the values that are drawn on top of this barset
221 Returns pen of the values that are drawn on top of this barset
222 */
222 */
223 QPen QBarSet::labelPen() const
223 QPen QBarSet::labelPen() const
224 {
224 {
225 return d_ptr->m_labelPen;
225 return d_ptr->m_labelPen;
226 }
226 }
227
227
228 /*!
228 /*!
229 Sets \a brush of the values that are drawn on top of this barset
229 Sets \a brush of the values that are drawn on top of this barset
230 */
230 */
231 void QBarSet::setLabelBrush(const QBrush &brush)
231 void QBarSet::setLabelBrush(const QBrush &brush)
232 {
232 {
233 if(d_ptr->m_labelBrush!=brush){
233 if(d_ptr->m_labelBrush!=brush){
234 d_ptr->m_labelBrush = brush;
234 d_ptr->m_labelBrush = brush;
235 emit d_ptr->updatedBars();
235 emit d_ptr->updatedBars();
236 }
236 }
237 }
237 }
238
238
239 /*!
239 /*!
240 Returns brush of the values that are drawn on top of this barset
240 Returns brush of the values that are drawn on top of this barset
241 */
241 */
242 QBrush QBarSet::labelBrush() const
242 QBrush QBarSet::labelBrush() const
243 {
243 {
244 return d_ptr->m_labelBrush;
244 return d_ptr->m_labelBrush;
245 }
245 }
246
246
247 /*!
247 /*!
248 Sets the \a font for values that are drawn on top of this barset
248 Sets the \a font for values that are drawn on top of this barset
249 */
249 */
250 void QBarSet::setLabelFont(const QFont &font)
250 void QBarSet::setLabelFont(const QFont &font)
251 {
251 {
252 if(d_ptr->m_labelFont!=font) {
252 if(d_ptr->m_labelFont!=font) {
253 d_ptr->m_labelFont = font;
253 d_ptr->m_labelFont = font;
254 emit d_ptr->updatedBars();
254 emit d_ptr->updatedBars();
255 }
255 }
256
256
257 }
257 }
258
258
259 /*!
259 /*!
260 Returns the pen for values that are drawn on top of this set
260 Returns the pen for values that are drawn on top of this set
261 */
261 */
262 QFont QBarSet::labelFont() const
262 QFont QBarSet::labelFont() const
263 {
263 {
264 return d_ptr->m_labelFont;
264 return d_ptr->m_labelFont;
265 }
265 }
266
266
267 /*!
267 /*!
268 Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets.
268 Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets.
269 */
269 */
270
270
271 void QBarSet::setLabelsVisible(bool visible)
271 void QBarSet::setLabelsVisible(bool visible)
272 {
272 {
273 if(d_ptr->m_labelsVisible!=visible) {
273 if(d_ptr->m_labelsVisible!=visible) {
274 d_ptr->m_labelsVisible = visible;
274 d_ptr->m_labelsVisible = visible;
275 emit d_ptr->labelsVisibleChanged(visible);
275 emit d_ptr->labelsVisibleChanged(visible);
276 }
276 }
277 }
277 }
278
278
279 /*!
279 /*!
280 Returns the visibility of values
280 Returns the visibility of values
281 */
281 */
282 bool QBarSet::labelsVisible() const
282 bool QBarSet::labelsVisible() const
283 {
283 {
284 return d_ptr->m_labelsVisible;
284 return d_ptr->m_labelsVisible;
285 }
285 }
286
286
287 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
287 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
288
288
289 QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent),
289 QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent),
290 q_ptr(parent),
290 q_ptr(parent),
291 m_name(name),
291 m_name(name),
292 m_labelsVisible(false)
292 m_labelsVisible(false)
293 {
293 {
294
295 }
294 }
296
295
297 QBarSetPrivate::~QBarSetPrivate()
296 QBarSetPrivate::~QBarSetPrivate()
298 {
297 {
299
300 }
298 }
299
301 #include "moc_qbarset.cpp"
300 #include "moc_qbarset.cpp"
302 #include "moc_qbarset_p.cpp"
301 #include "moc_qbarset_p.cpp"
303
302
304 QTCOMMERCIALCHART_END_NAMESPACE
303 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,40 +1,41
1 #ifndef QBARSET_P_H
1 #ifndef QBARSET_P_H
2 #define QBARSET_P_H
2 #define QBARSET_P_H
3
3
4 #include "qbarset.h"
4 #include "qbarset.h"
5 #include <QMap>
5 #include <QMap>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 class QBarSetPrivate : public QObject
9 class QBarSetPrivate : public QObject
10 {
10 {
11 Q_OBJECT
11 Q_OBJECT
12
12
13 public:
13 public:
14 QBarSetPrivate(const QString name, QBarSet *parent);
14 QBarSetPrivate(const QString name, QBarSet *parent);
15 ~QBarSetPrivate();
15 ~QBarSetPrivate();
16
16
17 Q_SIGNALS:
17 Q_SIGNALS:
18 void clicked(QString category);
18 void clicked(QString category);
19 void selected();
19 void restructuredBars();
20 void restructuredBars();
20 void updatedBars();
21 void updatedBars();
21 void labelsVisibleChanged(bool visible);
22 void labelsVisibleChanged(bool visible);
22
23
23 public:
24 public:
24 QBarSet * const q_ptr;
25 QBarSet * const q_ptr;
25 QString m_name;
26 QString m_name;
26 QList<qreal> m_values; // TODO: replace with map (category, value)
27 QList<qreal> m_values; // TODO: replace with map (category, value)
27 QMap<QString, qreal> m_mappedValues;
28 QMap<QString, qreal> m_mappedValues;
28 QPen m_pen;
29 QPen m_pen;
29 QBrush m_brush;
30 QBrush m_brush;
30 QPen m_labelPen;
31 QPen m_labelPen;
31 QBrush m_labelBrush;
32 QBrush m_labelBrush;
32 QFont m_labelFont;
33 QFont m_labelFont;
33 bool m_labelsVisible;
34 bool m_labelsVisible;
34
35
35 friend class QBarSet;
36 friend class QBarSet;
36 };
37 };
37
38
38 QTCOMMERCIALCHART_END_NAMESPACE
39 QTCOMMERCIALCHART_END_NAMESPACE
39
40
40 #endif // QBARSETPRIVATE_P_H
41 #endif // QBARSETPRIVATE_P_H
@@ -1,194 +1,194
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "legendmarker_p.h"
21 #include "legendmarker_p.h"
22 #include "qxyseries.h"
22 #include "qxyseries.h"
23 #include "qxyseries_p.h"
23 #include "qxyseries_p.h"
24 #include "qlegend.h"
24 #include "qlegend.h"
25 #include "qbarseries.h"
25 #include "qbarseries.h"
26 #include "qpieseries.h"
26 #include "qpieseries.h"
27 #include "qpieslice.h"
27 #include "qpieslice.h"
28 #include "qbarset.h"
28 #include "qbarset.h"
29 #include "qbarset_p.h"
29 #include "qbarset_p.h"
30 #include "qareaseries.h"
30 #include "qareaseries.h"
31 #include "qareaseries_p.h"
31 #include "qareaseries_p.h"
32 #include <QPainter>
32 #include <QPainter>
33 #include <QGraphicsSceneEvent>
33 #include <QGraphicsSceneEvent>
34 #include <QGraphicsSimpleTextItem>
34 #include <QGraphicsSimpleTextItem>
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) : QGraphicsObject(legend),
38 LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) : QGraphicsObject(legend),
39 m_series(series),
39 m_series(series),
40 m_markerRect(0,0,10.0,10.0),
40 m_markerRect(0,0,10.0,10.0),
41 m_boundingRect(0,0,0,0),
41 m_boundingRect(0,0,0,0),
42 m_legend(legend),
42 m_legend(legend),
43 m_textItem(new QGraphicsSimpleTextItem(this)),
43 m_textItem(new QGraphicsSimpleTextItem(this)),
44 m_rectItem(new QGraphicsRectItem(this))
44 m_rectItem(new QGraphicsRectItem(this))
45 {
45 {
46 //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
46 //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
47 m_rectItem->setRect(m_markerRect);
47 m_rectItem->setRect(m_markerRect);
48 updateLayout();
48 updateLayout();
49 }
49 }
50
50
51 void LegendMarker::setPen(const QPen &pen)
51 void LegendMarker::setPen(const QPen &pen)
52 {
52 {
53 m_textItem->setPen(pen);
53 m_textItem->setPen(pen);
54 updateLayout();
54 updateLayout();
55 }
55 }
56
56
57 QPen LegendMarker::pen() const
57 QPen LegendMarker::pen() const
58 {
58 {
59 return m_textItem->pen();
59 return m_textItem->pen();
60 }
60 }
61
61
62 void LegendMarker::setBrush(const QBrush &brush)
62 void LegendMarker::setBrush(const QBrush &brush)
63 {
63 {
64 m_rectItem->setBrush(brush);
64 m_rectItem->setBrush(brush);
65 }
65 }
66
66
67 QBrush LegendMarker::brush() const
67 QBrush LegendMarker::brush() const
68 {
68 {
69 return m_rectItem->brush();
69 return m_rectItem->brush();
70 }
70 }
71
71
72 void LegendMarker::setLabel(const QString name)
72 void LegendMarker::setLabel(const QString name)
73 {
73 {
74 m_textItem->setText(name);
74 m_textItem->setText(name);
75 updateLayout();
75 updateLayout();
76 }
76 }
77
77
78 void LegendMarker::setSize(const QSize& size)
78 void LegendMarker::setSize(const QSize& size)
79 {
79 {
80 m_markerRect = QRectF(0,0,size.width(),size.height());
80 m_markerRect = QRectF(0,0,size.width(),size.height());
81 }
81 }
82
82
83 QString LegendMarker::label() const
83 QString LegendMarker::label() const
84 {
84 {
85 return m_textItem->text();
85 return m_textItem->text();
86 }
86 }
87
87
88 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
88 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
89 {
89 {
90 Q_UNUSED(option)
90 Q_UNUSED(option)
91 Q_UNUSED(widget)
91 Q_UNUSED(widget)
92 Q_UNUSED(painter)
92 Q_UNUSED(painter)
93 }
93 }
94
94
95 QRectF LegendMarker::boundingRect() const
95 QRectF LegendMarker::boundingRect() const
96 {
96 {
97 return m_boundingRect;
97 return m_boundingRect;
98 }
98 }
99
99
100 void LegendMarker::updateLayout()
100 void LegendMarker::updateLayout()
101 {
101 {
102
102
103 static const qreal margin = 2;
103 static const qreal margin = 2;
104 static const qreal space = 4;
104 static const qreal space = 4;
105
105
106 const QRectF& textRect = m_textItem->boundingRect();
106 const QRectF& textRect = m_textItem->boundingRect();
107 prepareGeometryChange();
107 prepareGeometryChange();
108 m_boundingRect = QRectF(0,0,m_markerRect.width() + 2*margin + space + textRect.width(),qMax(m_markerRect.height()+2*margin,textRect.height()+2*margin));
108 m_boundingRect = QRectF(0,0,m_markerRect.width() + 2*margin + space + textRect.width(),qMax(m_markerRect.height()+2*margin,textRect.height()+2*margin));
109 m_textItem->setPos(m_markerRect.width() + space + margin,m_boundingRect.height()/2 - textRect.height()/2);
109 m_textItem->setPos(m_markerRect.width() + space + margin,m_boundingRect.height()/2 - textRect.height()/2);
110 m_rectItem->setPos(margin,m_boundingRect.height()/2 - m_markerRect.height()/2);
110 m_rectItem->setPos(margin,m_boundingRect.height()/2 - m_markerRect.height()/2);
111
111
112 }
112 }
113
113
114 void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
114 void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
115 {
115 {
116 QGraphicsObject::mousePressEvent(event);
116 QGraphicsObject::mousePressEvent(event);
117 emit selected();
117 emit selected();
118 }
118 }
119
119
120 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
120 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
121
121
122 AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend),
122 AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend),
123 m_series(series)
123 m_series(series)
124 {
124 {
125 QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
125 QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
126 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
126 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
127 updated();
127 updated();
128 }
128 }
129
129
130 void AreaLegendMarker::updated()
130 void AreaLegendMarker::updated()
131 {
131 {
132 setBrush(m_series->brush());
132 setBrush(m_series->brush());
133 setLabel(m_series->name());
133 setLabel(m_series->name());
134 }
134 }
135
135
136 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
136 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
137
137
138 BarLegendMarker::BarLegendMarker(QBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend),
138 BarLegendMarker::BarLegendMarker(QBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend),
139 m_barset(barset)
139 m_barset(barset)
140 {
140 {
141 QObject::connect(this, SIGNAL(selected()),barseries, SIGNAL(selected()));
141 QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected()));
142 QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated()));
142 QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated()));
143 updated();
143 updated();
144 }
144 }
145
145
146 void BarLegendMarker::updated()
146 void BarLegendMarker::updated()
147 {
147 {
148 setBrush(m_barset->brush());
148 setBrush(m_barset->brush());
149 setLabel(m_barset->name());
149 setLabel(m_barset->name());
150 }
150 }
151
151
152 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
152 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
153
153
154 PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend),
154 PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend),
155 m_pieslice(pieslice)
155 m_pieslice(pieslice)
156 {
156 {
157 QObject::connect(this, SIGNAL(selected()),pieslice, SIGNAL(clicked()));
157 QObject::connect(this, SIGNAL(selected()),pieslice, SIGNAL(clicked()));
158 QObject::connect(pieslice, SIGNAL(changed()), this, SLOT(updated()));
158 QObject::connect(pieslice, SIGNAL(changed()), this, SLOT(updated()));
159 updated();
159 updated();
160 }
160 }
161
161
162 void PieLegendMarker::updated()
162 void PieLegendMarker::updated()
163 {
163 {
164 setBrush(m_pieslice->brush());
164 setBrush(m_pieslice->brush());
165 setLabel(m_pieslice->label());
165 setLabel(m_pieslice->label());
166 }
166 }
167
167
168 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
168 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
169
169
170 XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend),
170 XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend),
171 m_series(series)
171 m_series(series)
172 {
172 {
173 QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
173 QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
174 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
174 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
175 updated();
175 updated();
176 }
176 }
177
177
178 void XYLegendMarker::updated()
178 void XYLegendMarker::updated()
179 {
179 {
180 setLabel(m_series->name());
180 setLabel(m_series->name());
181
181
182 if(m_series->type()== QAbstractSeries::SeriesTypeScatter)
182 if(m_series->type()== QAbstractSeries::SeriesTypeScatter)
183 {
183 {
184 setBrush(m_series->brush());
184 setBrush(m_series->brush());
185
185
186 }
186 }
187 else {
187 else {
188 setBrush(QBrush(m_series->pen().color()));
188 setBrush(QBrush(m_series->pen().color()));
189 }
189 }
190 }
190 }
191
191
192 #include "moc_legendmarker_p.cpp"
192 #include "moc_legendmarker_p.cpp"
193
193
194 QTCOMMERCIALCHART_END_NAMESPACE
194 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now