##// END OF EJS Templates
fix: wrong delete order in legendmarkeritem and legendmarker private
sauimone -
r2381:9531960162cc
parent child
Show More
@@ -1,273 +1,274
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 "qlegendmarker.h"
21 #include "qlegendmarker.h"
22 #include "qlegendmarker_p.h"
22 #include "qlegendmarker_p.h"
23 #include "legendmarkeritem_p.h"
23 #include "legendmarkeritem_p.h"
24 #include "qlegend.h"
24 #include "qlegend.h"
25 #include "qlegend_p.h"
25 #include "qlegend_p.h"
26 #include "legendlayout_p.h"
26 #include "legendlayout_p.h"
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <QGraphicsSceneEvent>
28 #include <QGraphicsSceneEvent>
29 #include <QAbstractSeries>
29 #include <QAbstractSeries>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \class QLegendMarker
34 \class QLegendMarker
35 \brief LegendMarker object
35 \brief LegendMarker object
36 \mainclass
36 \mainclass
37
37
38 QLegendMarker is abstract object that can be used to access markers inside QLegend. Legend marker consists of two
38 QLegendMarker is abstract object that can be used to access markers inside QLegend. Legend marker consists of two
39 items: The colored box, which reflects the color of series and label, which is the name of series (or label of slice/barset
39 items: The colored box, which reflects the color of series and label, which is the name of series (or label of slice/barset
40 in case of pie or bar series)
40 in case of pie or bar series)
41 The QLegendMarker is always related to one series.
41 The QLegendMarker is always related to one series.
42
42
43 \image examples_percentbarchart_legend.png
43 \image examples_percentbarchart_legend.png
44
44
45 \sa QLegend
45 \sa QLegend
46 */
46 */
47 /*!
47 /*!
48 \enum QLegendMarker::LegendMarkerType
48 \enum QLegendMarker::LegendMarkerType
49
49
50 The type of the legendmarker object.
50 The type of the legendmarker object.
51
51
52 \value LegendMarkerTypeArea
52 \value LegendMarkerTypeArea
53 \value LegendMarkerTypeBar
53 \value LegendMarkerTypeBar
54 \value LegendMarkerTypePie
54 \value LegendMarkerTypePie
55 \value LegendMarkerTypeXY
55 \value LegendMarkerTypeXY
56 */
56 */
57
57
58 /*!
58 /*!
59 \fn virtual LegendMarkerType QLegendMarker::type() = 0;
59 \fn virtual LegendMarkerType QLegendMarker::type() = 0;
60 Returns the type of legendmarker. Type depends of the related series. LegendMarkerTypeXY is used for all QXYSeries derived
60 Returns the type of legendmarker. Type depends of the related series. LegendMarkerTypeXY is used for all QXYSeries derived
61 classes.
61 classes.
62 */
62 */
63
63
64 /*!
64 /*!
65 \fn virtual QAbstractSeries* QLegendMarker::series() = 0;
65 \fn virtual QAbstractSeries* QLegendMarker::series() = 0;
66 Returns pointer to series, which is related to this marker. Marker is always related to some series.
66 Returns pointer to series, which is related to this marker. Marker is always related to some series.
67 */
67 */
68
68
69 /*!
69 /*!
70 \fn void QLegendMarker::clicked();
70 \fn void QLegendMarker::clicked();
71 This signal is emitted, when marker is clicked with mouse.
71 This signal is emitted, when marker is clicked with mouse.
72 */
72 */
73
73
74 /*!
74 /*!
75 \fn void QLegendMarker::hovered(bool status);
75 \fn void QLegendMarker::hovered(bool status);
76 This signal is emitted, when mouse is hovered over marker. \a status is true, when mouse enters the marker
76 This signal is emitted, when mouse is hovered over marker. \a status is true, when mouse enters the marker
77 and false when it leaves the marker.
77 and false when it leaves the marker.
78 */
78 */
79
79
80 /*!
80 /*!
81 \fn void QLegendMarker::labelChanged()
81 \fn void QLegendMarker::labelChanged()
82 This signal is emitted when the label of the legend marker has changed.
82 This signal is emitted when the label of the legend marker has changed.
83 */
83 */
84
84
85 /*!
85 /*!
86 \fn void QLegendMarker::labelBrushChanged()
86 \fn void QLegendMarker::labelBrushChanged()
87 This signal is emitted when the label brush of the legend marker has changed.
87 This signal is emitted when the label brush of the legend marker has changed.
88 */
88 */
89
89
90 /*!
90 /*!
91 \fn void QLegendMarker::fontChanged()
91 \fn void QLegendMarker::fontChanged()
92 This signal is emitted when the (label) font of the legend marker has changed.
92 This signal is emitted when the (label) font of the legend marker has changed.
93 */
93 */
94
94
95 /*!
95 /*!
96 \fn void QLegendMarker::penChanged()
96 \fn void QLegendMarker::penChanged()
97 This signal is emitted when the pen of the legend marker has changed.
97 This signal is emitted when the pen of the legend marker has changed.
98 */
98 */
99
99
100 /*!
100 /*!
101 \fn void QLegendMarker::brushChanged()
101 \fn void QLegendMarker::brushChanged()
102 This signal is emitted when the brush of the legend marker has changed.
102 This signal is emitted when the brush of the legend marker has changed.
103 */
103 */
104
104
105 /*!
105 /*!
106 \fn void QLegendMarker::visibleChanged()
106 \fn void QLegendMarker::visibleChanged()
107 This signal is emitted when the visibility of the legend marker has changed.
107 This signal is emitted when the visibility of the legend marker has changed.
108 */
108 */
109
109
110 /*!
110 /*!
111 \property QLegendMarker::label
111 \property QLegendMarker::label
112 Label of the marker. This is the text that is shown in legend.
112 Label of the marker. This is the text that is shown in legend.
113 */
113 */
114
114
115 /*!
115 /*!
116 \property QLegendMarker::labelBrush
116 \property QLegendMarker::labelBrush
117 Brush of the label
117 Brush of the label
118 */
118 */
119
119
120 /*!
120 /*!
121 \property QLegendMarker::font
121 \property QLegendMarker::font
122 Font of the label
122 Font of the label
123 */
123 */
124
124
125 /*!
125 /*!
126 \property QLegendMarker::pen
126 \property QLegendMarker::pen
127 Pen of the marker. This is the outline of the colored square.
127 Pen of the marker. This is the outline of the colored square.
128 */
128 */
129
129
130 /*!
130 /*!
131 \property QLegendMarker::brush
131 \property QLegendMarker::brush
132 Brush of the marker. This is the inside of the colored square.
132 Brush of the marker. This is the inside of the colored square.
133 */
133 */
134
134
135 /*!
135 /*!
136 \property QLegendMarker::visible
136 \property QLegendMarker::visible
137 Visibility of the legend marker. Affects label and the colored square.
137 Visibility of the legend marker. Affects label and the colored square.
138 */
138 */
139
139
140
140
141 /*!
141 /*!
142 \internal
142 \internal
143 */
143 */
144 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
144 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
145 QObject(parent),
145 QObject(parent),
146 d_ptr(&d)
146 d_ptr(&d)
147 {
147 {
148 d_ptr->m_item->setVisible(d_ptr->series()->isVisible());
148 d_ptr->m_item->setVisible(d_ptr->series()->isVisible());
149 }
149 }
150
150
151 /*!
151 /*!
152 Destructor of marker
152 Destructor of marker
153 */
153 */
154 QLegendMarker::~QLegendMarker()
154 QLegendMarker::~QLegendMarker()
155 {
155 {
156 }
156 }
157
157
158 /*!
158 /*!
159 Returns the label of the marker.
159 Returns the label of the marker.
160 */
160 */
161 QString QLegendMarker::label() const
161 QString QLegendMarker::label() const
162 {
162 {
163 return d_ptr->m_item->label();
163 return d_ptr->m_item->label();
164 }
164 }
165
165
166 /*!
166 /*!
167 Sets the \a label of marker. Note that changing name of series will also change label of its marker.
167 Sets the \a label of marker. Note that changing name of series will also change label of its marker.
168 */
168 */
169 void QLegendMarker::setLabel(const QString &label)
169 void QLegendMarker::setLabel(const QString &label)
170 {
170 {
171 d_ptr->m_item->setLabel(label);
171 d_ptr->m_item->setLabel(label);
172 }
172 }
173 /*!
173 /*!
174 Returns the brush which is used to draw label.
174 Returns the brush which is used to draw label.
175 */
175 */
176 QBrush QLegendMarker::labelBrush() const
176 QBrush QLegendMarker::labelBrush() const
177 {
177 {
178 return d_ptr->m_item->labelBrush();
178 return d_ptr->m_item->labelBrush();
179 }
179 }
180
180
181 /*!
181 /*!
182 Sets the \a brush of label
182 Sets the \a brush of label
183 */
183 */
184 void QLegendMarker::setLabelBrush(const QBrush &brush)
184 void QLegendMarker::setLabelBrush(const QBrush &brush)
185 {
185 {
186 d_ptr->m_item->setLabelBrush(brush);
186 d_ptr->m_item->setLabelBrush(brush);
187 }
187 }
188
188
189 /*!
189 /*!
190 Retuns the font of label
190 Retuns the font of label
191 */
191 */
192 QFont QLegendMarker::font() const
192 QFont QLegendMarker::font() const
193 {
193 {
194 return d_ptr->m_item->font();
194 return d_ptr->m_item->font();
195 }
195 }
196
196
197 /*!
197 /*!
198 Sets the \a font of label
198 Sets the \a font of label
199 */
199 */
200 void QLegendMarker::setFont(const QFont &font)
200 void QLegendMarker::setFont(const QFont &font)
201 {
201 {
202 d_ptr->m_item->setFont(font);
202 d_ptr->m_item->setFont(font);
203 }
203 }
204
204
205 /*!
205 /*!
206 Returns the pen of marker item
206 Returns the pen of marker item
207 */
207 */
208 QPen QLegendMarker::pen() const
208 QPen QLegendMarker::pen() const
209 {
209 {
210 return d_ptr->m_item->pen();
210 return d_ptr->m_item->pen();
211 }
211 }
212
212
213 /*!
213 /*!
214 Sets the \a pen of marker item
214 Sets the \a pen of marker item
215 */
215 */
216 void QLegendMarker::setPen(const QPen &pen)
216 void QLegendMarker::setPen(const QPen &pen)
217 {
217 {
218 d_ptr->m_item->setPen(pen);
218 d_ptr->m_item->setPen(pen);
219 }
219 }
220
220
221 /*!
221 /*!
222 Returns the brush of marker item
222 Returns the brush of marker item
223 */
223 */
224 QBrush QLegendMarker::brush() const
224 QBrush QLegendMarker::brush() const
225 {
225 {
226 return d_ptr->m_item->brush();
226 return d_ptr->m_item->brush();
227 }
227 }
228
228
229 /*!
229 /*!
230 Sets the \a brush of marker item. Note that changing color of the series also changes this.
230 Sets the \a brush of marker item. Note that changing color of the series also changes this.
231 */
231 */
232 void QLegendMarker::setBrush(const QBrush &brush)
232 void QLegendMarker::setBrush(const QBrush &brush)
233 {
233 {
234 d_ptr->m_item->setBrush(brush);
234 d_ptr->m_item->setBrush(brush);
235 }
235 }
236
236
237 /*!
237 /*!
238 Returns visibility of the marker
238 Returns visibility of the marker
239 */
239 */
240 bool QLegendMarker::isVisible() const
240 bool QLegendMarker::isVisible() const
241 {
241 {
242 return d_ptr->m_item->isVisible();
242 return d_ptr->m_item->isVisible();
243 }
243 }
244
244
245 /*!
245 /*!
246 Sets markers visibility to \a visible
246 Sets markers visibility to \a visible
247 */
247 */
248 void QLegendMarker::setVisible(bool visible)
248 void QLegendMarker::setVisible(bool visible)
249 {
249 {
250 d_ptr->m_item->setVisible(visible);
250 d_ptr->m_item->setVisible(visible);
251 }
251 }
252
252
253 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
253 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
254 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) :
254 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) :
255 m_legend(legend),
255 m_legend(legend),
256 q_ptr(q)
256 q_ptr(q)
257 {
257 {
258 m_item = new LegendMarkerItem(this);
258 m_item = new LegendMarkerItem(this);
259 }
259 }
260
260
261 QLegendMarkerPrivate::~QLegendMarkerPrivate()
261 QLegendMarkerPrivate::~QLegendMarkerPrivate()
262 {
262 {
263 delete m_item;
263 }
264 }
264
265
265 void QLegendMarkerPrivate::invalidateLegend()
266 void QLegendMarkerPrivate::invalidateLegend()
266 {
267 {
267 m_legend->d_ptr->m_layout->invalidate();
268 m_legend->d_ptr->m_layout->invalidate();
268 }
269 }
269
270
270 #include "moc_qlegendmarker.cpp"
271 #include "moc_qlegendmarker.cpp"
271 #include "moc_qlegendmarker_p.cpp"
272 #include "moc_qlegendmarker_p.cpp"
272
273
273 QTCOMMERCIALCHART_END_NAMESPACE
274 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now