@@ -1,237 +1,236 | |||||
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 "qabstractbarseries.h" |
|
25 | #include "qabstractbarseries.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 | #include <QDebug> |
|
35 | #include <QDebug> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) : |
|
39 | LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) : | |
40 | QGraphicsObject(legend), |
|
40 | QGraphicsObject(legend), | |
41 | m_series(series), |
|
41 | m_series(series), | |
42 | m_markerRect(0,0,10.0,10.0), |
|
42 | m_markerRect(0,0,10.0,10.0), | |
43 | m_boundingRect(0,0,0,0), |
|
43 | m_boundingRect(0,0,0,0), | |
44 | m_legend(legend), |
|
44 | m_legend(legend), | |
45 | m_textItem(new QGraphicsSimpleTextItem(this)), |
|
45 | m_textItem(new QGraphicsSimpleTextItem(this)), | |
46 | m_rectItem(new QGraphicsRectItem(this)), |
|
46 | m_rectItem(new QGraphicsRectItem(this)), | |
47 | m_margin(2), |
|
47 | m_margin(2), | |
48 | m_space(4) |
|
48 | m_space(4) | |
49 | { |
|
49 | { | |
50 | //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
50 | //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | |
51 | m_rectItem->setRect(m_markerRect); |
|
51 | m_rectItem->setRect(m_markerRect); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void LegendMarker::setPen(const QPen &pen) |
|
54 | void LegendMarker::setPen(const QPen &pen) | |
55 | { |
|
55 | { | |
56 | m_rectItem->setPen(pen); |
|
56 | m_rectItem->setPen(pen); | |
57 | m_textItem->setPen(pen); |
|
|||
58 | } |
|
57 | } | |
59 |
|
58 | |||
60 | QPen LegendMarker::pen() const |
|
59 | QPen LegendMarker::pen() const | |
61 | { |
|
60 | { | |
62 | return m_rectItem->pen(); |
|
61 | return m_rectItem->pen(); | |
63 | } |
|
62 | } | |
64 |
|
63 | |||
65 | void LegendMarker::setBrush(const QBrush &brush) |
|
64 | void LegendMarker::setBrush(const QBrush &brush) | |
66 | { |
|
65 | { | |
67 | m_rectItem->setBrush(brush); |
|
66 | m_rectItem->setBrush(brush); | |
68 | } |
|
67 | } | |
69 |
|
68 | |||
70 | QBrush LegendMarker::brush() const |
|
69 | QBrush LegendMarker::brush() const | |
71 | { |
|
70 | { | |
72 | return m_rectItem->brush(); |
|
71 | return m_rectItem->brush(); | |
73 | } |
|
72 | } | |
74 |
|
73 | |||
75 | void LegendMarker::setFont(const QFont &font) |
|
74 | void LegendMarker::setFont(const QFont &font) | |
76 | { |
|
75 | { | |
77 | m_textItem->setFont(font); |
|
76 | m_textItem->setFont(font); | |
78 | QFontMetrics fn(font); |
|
77 | QFontMetrics fn(font); | |
79 | m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2); |
|
78 | m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2); | |
80 | updateGeometry(); |
|
79 | updateGeometry(); | |
81 | } |
|
80 | } | |
82 |
|
81 | |||
83 | QFont LegendMarker::font() const |
|
82 | QFont LegendMarker::font() const | |
84 | { |
|
83 | { | |
85 | return m_textItem->font(); |
|
84 | return m_textItem->font(); | |
86 | } |
|
85 | } | |
87 |
|
86 | |||
88 | void LegendMarker::setLabel(const QString label) |
|
87 | void LegendMarker::setLabel(const QString label) | |
89 | { |
|
88 | { | |
90 | m_textItem->setText(label); |
|
89 | m_textItem->setText(label); | |
91 | } |
|
90 | } | |
92 |
|
91 | |||
93 | QString LegendMarker::label() const |
|
92 | QString LegendMarker::label() const | |
94 | { |
|
93 | { | |
95 | return m_textItem->text(); |
|
94 | return m_textItem->text(); | |
96 | } |
|
95 | } | |
97 |
|
96 | |||
98 | QRectF LegendMarker::boundingRect() const |
|
97 | QRectF LegendMarker::boundingRect() const | |
99 | { |
|
98 | { | |
100 | return m_boundingRect; |
|
99 | return m_boundingRect; | |
101 | } |
|
100 | } | |
102 |
|
101 | |||
103 | void LegendMarker::setLabelBrush(const QBrush &brush) |
|
102 | void LegendMarker::setLabelBrush(const QBrush &brush) | |
104 | { |
|
103 | { | |
105 | m_textItem->setBrush(brush); |
|
104 | m_textItem->setBrush(brush); | |
106 | } |
|
105 | } | |
107 |
|
106 | |||
108 | QBrush LegendMarker::labelBrush() const |
|
107 | QBrush LegendMarker::labelBrush() const | |
109 | { |
|
108 | { | |
110 | return m_textItem->brush(); |
|
109 | return m_textItem->brush(); | |
111 | } |
|
110 | } | |
112 |
|
111 | |||
113 |
|
112 | |||
114 | void LegendMarker::setGeometry(const QRectF& rect) |
|
113 | void LegendMarker::setGeometry(const QRectF& rect) | |
115 | { |
|
114 | { | |
116 | const QRectF& textRect = m_textItem->boundingRect(); |
|
115 | const QRectF& textRect = m_textItem->boundingRect(); | |
117 |
|
116 | |||
118 | m_textItem->setPos(m_markerRect.width() + m_space + m_margin,rect.height()/2 - textRect.height()/2); |
|
117 | m_textItem->setPos(m_markerRect.width() + m_space + m_margin,rect.height()/2 - textRect.height()/2); | |
119 | m_rectItem->setRect(m_markerRect); |
|
118 | m_rectItem->setRect(m_markerRect); | |
120 | m_rectItem->setPos(m_margin,rect.height()/2 - m_markerRect.height()/2); |
|
119 | m_rectItem->setPos(m_margin,rect.height()/2 - m_markerRect.height()/2); | |
121 |
|
120 | |||
122 | prepareGeometryChange(); |
|
121 | prepareGeometryChange(); | |
123 | m_boundingRect = rect; |
|
122 | m_boundingRect = rect; | |
124 | } |
|
123 | } | |
125 |
|
124 | |||
126 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
125 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
127 | { |
|
126 | { | |
128 | Q_UNUSED(option) |
|
127 | Q_UNUSED(option) | |
129 | Q_UNUSED(widget) |
|
128 | Q_UNUSED(widget) | |
130 | Q_UNUSED(painter) |
|
129 | Q_UNUSED(painter) | |
131 | } |
|
130 | } | |
132 |
|
131 | |||
133 |
|
132 | |||
134 | QSizeF LegendMarker::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const |
|
133 | QSizeF LegendMarker::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |
135 | { |
|
134 | { | |
136 | Q_UNUSED(constraint) |
|
135 | Q_UNUSED(constraint) | |
137 |
|
136 | |||
138 | QFontMetrics fn(m_textItem->font()); |
|
137 | QFontMetrics fn(m_textItem->font()); | |
139 | QSizeF sh; |
|
138 | QSizeF sh; | |
140 |
|
139 | |||
141 | switch (which) { |
|
140 | switch (which) { | |
142 | case Qt::MinimumSize: |
|
141 | case Qt::MinimumSize: | |
143 | sh = QSizeF(fn.boundingRect("...").width(),fn.height()); |
|
142 | sh = QSizeF(fn.boundingRect("...").width(),fn.height()); | |
144 | break; |
|
143 | break; | |
145 | case Qt::PreferredSize: |
|
144 | case Qt::PreferredSize: | |
146 | sh = QSizeF(fn.boundingRect(m_textItem->text()).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); |
|
145 | sh = QSizeF(fn.boundingRect(m_textItem->text()).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); | |
147 | break; |
|
146 | break; | |
148 | default: |
|
147 | default: | |
149 | break; |
|
148 | break; | |
150 | } |
|
149 | } | |
151 |
|
150 | |||
152 | return sh; |
|
151 | return sh; | |
153 | } |
|
152 | } | |
154 |
|
153 | |||
155 | void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
154 | void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
156 | { |
|
155 | { | |
157 | QGraphicsObject::mousePressEvent(event); |
|
156 | QGraphicsObject::mousePressEvent(event); | |
158 | qDebug()<<"Not implemented"; //TODO: selected signal removed for now |
|
157 | qDebug()<<"Not implemented"; //TODO: selected signal removed for now | |
159 | } |
|
158 | } | |
160 |
|
159 | |||
161 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
160 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
162 |
|
161 | |||
163 | AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend), |
|
162 | AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend), | |
164 | m_series(series) |
|
163 | m_series(series) | |
165 | { |
|
164 | { | |
166 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); |
|
165 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); | |
167 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
166 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
168 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
167 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
169 | updated(); |
|
168 | updated(); | |
170 | } |
|
169 | } | |
171 |
|
170 | |||
172 | void AreaLegendMarker::updated() |
|
171 | void AreaLegendMarker::updated() | |
173 | { |
|
172 | { | |
174 | setBrush(m_series->brush()); |
|
173 | setBrush(m_series->brush()); | |
175 | setLabel(m_series->name()); |
|
174 | setLabel(m_series->name()); | |
176 | } |
|
175 | } | |
177 |
|
176 | |||
178 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
177 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
179 |
|
178 | |||
180 | BarLegendMarker::BarLegendMarker(QAbstractBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend), |
|
179 | BarLegendMarker::BarLegendMarker(QAbstractBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend), | |
181 | m_barset(barset) |
|
180 | m_barset(barset) | |
182 | { |
|
181 | { | |
183 | //QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected())); |
|
182 | //QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected())); | |
184 | QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated())); |
|
183 | QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated())); | |
185 | updated(); |
|
184 | updated(); | |
186 | } |
|
185 | } | |
187 |
|
186 | |||
188 | void BarLegendMarker::updated() |
|
187 | void BarLegendMarker::updated() | |
189 | { |
|
188 | { | |
190 | setBrush(m_barset->brush()); |
|
189 | setBrush(m_barset->brush()); | |
191 | setLabel(m_barset->label()); |
|
190 | setLabel(m_barset->label()); | |
192 | } |
|
191 | } | |
193 |
|
192 | |||
194 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
193 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
195 |
|
194 | |||
196 | PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend), |
|
195 | PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend), | |
197 | m_pieslice(pieslice) |
|
196 | m_pieslice(pieslice) | |
198 | { |
|
197 | { | |
199 | QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
198 | QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated())); | |
200 | QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
199 | QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated())); | |
201 | updated(); |
|
200 | updated(); | |
202 | } |
|
201 | } | |
203 |
|
202 | |||
204 | void PieLegendMarker::updated() |
|
203 | void PieLegendMarker::updated() | |
205 | { |
|
204 | { | |
206 | setBrush(m_pieslice->brush()); |
|
205 | setBrush(m_pieslice->brush()); | |
207 | setLabel(m_pieslice->label()); |
|
206 | setLabel(m_pieslice->label()); | |
208 | } |
|
207 | } | |
209 |
|
208 | |||
210 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
209 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
211 |
|
210 | |||
212 | XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend), |
|
211 | XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend), | |
213 | m_series(series) |
|
212 | m_series(series) | |
214 | { |
|
213 | { | |
215 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); |
|
214 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); | |
216 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
215 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
217 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
216 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
218 | updated(); |
|
217 | updated(); | |
219 | } |
|
218 | } | |
220 |
|
219 | |||
221 | void XYLegendMarker::updated() |
|
220 | void XYLegendMarker::updated() | |
222 | { |
|
221 | { | |
223 | setLabel(m_series->name()); |
|
222 | setLabel(m_series->name()); | |
224 |
|
223 | |||
225 | if(m_series->type()== QAbstractSeries::SeriesTypeScatter) |
|
224 | if(m_series->type()== QAbstractSeries::SeriesTypeScatter) | |
226 | { |
|
225 | { | |
227 | setBrush(m_series->brush()); |
|
226 | setBrush(m_series->brush()); | |
228 |
|
227 | |||
229 | } |
|
228 | } | |
230 | else { |
|
229 | else { | |
231 | setBrush(QBrush(m_series->pen().color())); |
|
230 | setBrush(QBrush(m_series->pen().color())); | |
232 | } |
|
231 | } | |
233 | } |
|
232 | } | |
234 |
|
233 | |||
235 | #include "moc_legendmarker_p.cpp" |
|
234 | #include "moc_legendmarker_p.cpp" | |
236 |
|
235 | |||
237 | QTCOMMERCIALCHART_END_NAMESPACE |
|
236 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,534 +1,537 | |||||
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 "qlegend.h" |
|
21 | #include "qlegend.h" | |
22 | #include "qlegend_p.h" |
|
22 | #include "qlegend_p.h" | |
23 | #include "qabstractseries.h" |
|
23 | #include "qabstractseries.h" | |
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" | |
28 | #include "qxyseries.h" |
|
28 | #include "qxyseries.h" | |
29 | #include "qlineseries.h" |
|
29 | #include "qlineseries.h" | |
30 | #include "qareaseries.h" |
|
30 | #include "qareaseries.h" | |
31 | #include "qscatterseries.h" |
|
31 | #include "qscatterseries.h" | |
32 | #include "qsplineseries.h" |
|
32 | #include "qsplineseries.h" | |
33 | #include "qabstractbarseries.h" |
|
33 | #include "qabstractbarseries.h" | |
34 | #include "qstackedbarseries.h" |
|
34 | #include "qstackedbarseries.h" | |
35 | #include "qpercentbarseries.h" |
|
35 | #include "qpercentbarseries.h" | |
36 | #include "qbarset.h" |
|
36 | #include "qbarset.h" | |
37 | #include "qpieseries.h" |
|
37 | #include "qpieseries.h" | |
38 | #include "qpieseries_p.h" |
|
38 | #include "qpieseries_p.h" | |
39 | #include "qpieslice.h" |
|
39 | #include "qpieslice.h" | |
40 | #include "chartpresenter_p.h" |
|
40 | #include "chartpresenter_p.h" | |
41 | #include <QPainter> |
|
41 | #include <QPainter> | |
42 | #include <QPen> |
|
42 | #include <QPen> | |
43 | #include <QTimer> |
|
43 | #include <QTimer> | |
44 | #include <QGraphicsLayout> |
|
44 | #include <QGraphicsLayout> | |
45 | #include <QGraphicsSceneEvent> |
|
45 | #include <QGraphicsSceneEvent> | |
46 |
|
46 | |||
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \class QLegend |
|
50 | \class QLegend | |
51 | \brief Legend object |
|
51 | \brief Legend object | |
52 | \mainclass |
|
52 | \mainclass | |
53 |
|
53 | |||
54 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
54 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when | |
55 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
55 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
56 | handle the drawing manually. |
|
56 | handle the drawing manually. | |
57 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
57 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
58 |
|
58 | |||
59 | \image examples_percentbarchart_legend.png |
|
59 | \image examples_percentbarchart_legend.png | |
60 |
|
60 | |||
61 | \sa QChart |
|
61 | \sa QChart | |
62 | */ |
|
62 | */ | |
63 | /*! |
|
63 | /*! | |
64 | \qmlclass Legend QLegend |
|
64 | \qmlclass Legend QLegend | |
65 | \brief Legend is part of QtCommercial Chart QML API. |
|
65 | \brief Legend is part of QtCommercial Chart QML API. | |
66 |
|
66 | |||
67 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when |
|
67 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when | |
68 | series have been changed. Legend is used via ChartView class. For example: |
|
68 | series have been changed. Legend is used via ChartView class. For example: | |
69 | \code |
|
69 | \code | |
70 | ChartView { |
|
70 | ChartView { | |
71 | legend.visible: true |
|
71 | legend.visible: true | |
72 | legend.alignment: Qt.AlignBottom |
|
72 | legend.alignment: Qt.AlignBottom | |
73 | // Add a few series... |
|
73 | // Add a few series... | |
74 | } |
|
74 | } | |
75 | \endcode |
|
75 | \endcode | |
76 |
|
76 | |||
77 | \image examples_percentbarchart_legend.png |
|
77 | \image examples_percentbarchart_legend.png | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \property QLegend::alignment |
|
81 | \property QLegend::alignment | |
82 | \brief The alignment of the legend. |
|
82 | \brief The alignment of the legend. | |
83 |
|
83 | |||
84 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
84 | Legend paints on the defined position in the chart. The following alignments are supported: | |
85 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
85 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. | |
86 | */ |
|
86 | */ | |
87 | /*! |
|
87 | /*! | |
88 | \qmlproperty Qt.Alignment Legend::alignment |
|
88 | \qmlproperty Qt.Alignment Legend::alignment | |
89 | \brief The alignment of the legend. |
|
89 | \brief The alignment of the legend. | |
90 |
|
90 | |||
91 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
91 | Legend paints on the defined position in the chart. The following alignments are supported: | |
92 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
92 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \property QLegend::backgroundVisible |
|
96 | \property QLegend::backgroundVisible | |
97 | Whether the legend background is visible or not. |
|
97 | Whether the legend background is visible or not. | |
98 | */ |
|
98 | */ | |
99 | /*! |
|
99 | /*! | |
100 | \qmlproperty bool Legend::backgroundVisible |
|
100 | \qmlproperty bool Legend::backgroundVisible | |
101 | Whether the legend background is visible or not. |
|
101 | Whether the legend background is visible or not. | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \property QLegend::color |
|
105 | \property QLegend::color | |
106 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
106 | The color of the legend, i.e. the background (brush) color. Note that if you change the color | |
107 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
107 | of the legend, the style of the legend brush is set to Qt::SolidPattern. | |
108 | */ |
|
108 | */ | |
109 | /*! |
|
109 | /*! | |
110 | \qmlproperty color Legend::color |
|
110 | \qmlproperty color Legend::color | |
111 | The color of the legend, i.e. the background (brush) color. |
|
111 | The color of the legend, i.e. the background (brush) color. | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | \property QLegend::borderColor |
|
115 | \property QLegend::borderColor | |
116 | The border color of the legend, i.e. the line color. |
|
116 | The border color of the legend, i.e. the line color. | |
117 | */ |
|
117 | */ | |
118 | /*! |
|
118 | /*! | |
119 | \qmlproperty color Legend::borderColor |
|
119 | \qmlproperty color Legend::borderColor | |
120 | The border color of the legend, i.e. the line color. |
|
120 | The border color of the legend, i.e. the line color. | |
121 | */ |
|
121 | */ | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | \property QLegend::font |
|
124 | \property QLegend::font | |
125 | The font of markers used by legend |
|
125 | The font of markers used by legend | |
126 | */ |
|
126 | */ | |
127 | /*! |
|
127 | /*! | |
128 | \qmlproperty color Legend::font |
|
128 | \qmlproperty color Legend::font | |
129 | The font of markers used by legend |
|
129 | The font of markers used by legend | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \property QLegend::labelColor |
|
133 | \property QLegend::labelColor | |
134 | The color of brush used to draw labels. |
|
134 | The color of brush used to draw labels. | |
135 | */ |
|
135 | */ | |
136 | /*! |
|
136 | /*! | |
137 | \qmlproperty color QLegend::labelColor |
|
137 | \qmlproperty color QLegend::labelColor | |
138 | The color of brush used to draw labels. |
|
138 | The color of brush used to draw labels. | |
139 | */ |
|
139 | */ | |
140 |
|
140 | |||
141 | /*! |
|
141 | /*! | |
142 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
142 | \fn void QLegend::backgroundVisibleChanged(bool) | |
143 | The visibility of the legend background changed to \a visible. |
|
143 | The visibility of the legend background changed to \a visible. | |
144 | */ |
|
144 | */ | |
145 |
|
145 | |||
146 | /*! |
|
146 | /*! | |
147 | \fn void QLegend::colorChanged(QColor) |
|
147 | \fn void QLegend::colorChanged(QColor) | |
148 | The color of the legend background changed to \a color. |
|
148 | The color of the legend background changed to \a color. | |
149 | */ |
|
149 | */ | |
150 |
|
150 | |||
151 | /*! |
|
151 | /*! | |
152 | \fn void QLegend::borderColorChanged(QColor) |
|
152 | \fn void QLegend::borderColorChanged(QColor) | |
153 | The border color of the legend background changed to \a color. |
|
153 | The border color of the legend background changed to \a color. | |
154 | */ |
|
154 | */ | |
155 |
|
155 | |||
156 | /*! |
|
156 | /*! | |
157 | \fn void QLegend::fontChanged(QFont) |
|
157 | \fn void QLegend::fontChanged(QFont) | |
158 | The font of markers of the legend changed to \a font. |
|
158 | The font of markers of the legend changed to \a font. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \fn void QLegend::labelColorChanged(QColor color) |
|
162 | \fn void QLegend::labelColorChanged(QColor color) | |
163 | This signal is emitted when the color of brush used to draw labels has changed to \a color. |
|
163 | This signal is emitted when the color of brush used to draw labels has changed to \a color. | |
164 | */ |
|
164 | */ | |
165 |
|
165 | |||
166 | /*! |
|
166 | /*! | |
167 | Constructs the legend object and sets the parent to \a parent |
|
167 | Constructs the legend object and sets the parent to \a parent | |
168 | */ |
|
168 | */ | |
169 |
|
169 | |||
170 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), |
|
170 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), | |
171 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this)) |
|
171 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this)) | |
172 | { |
|
172 | { | |
173 | setZValue(ChartPresenter::LegendZValue); |
|
173 | setZValue(ChartPresenter::LegendZValue); | |
174 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
174 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
175 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
175 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); | |
176 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
176 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
177 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); |
|
177 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); | |
178 | setLayout(d_ptr->m_layout); |
|
178 | setLayout(d_ptr->m_layout); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
182 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. | |
183 | */ |
|
183 | */ | |
184 | QLegend::~QLegend() |
|
184 | QLegend::~QLegend() | |
185 | { |
|
185 | { | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | \internal |
|
189 | \internal | |
190 | */ |
|
190 | */ | |
191 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
191 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
192 | { |
|
192 | { | |
193 | Q_UNUSED(option) |
|
193 | Q_UNUSED(option) | |
194 | Q_UNUSED(widget) |
|
194 | Q_UNUSED(widget) | |
195 | if(!d_ptr->m_backgroundVisible) return; |
|
195 | if(!d_ptr->m_backgroundVisible) return; | |
196 |
|
196 | |||
197 | painter->setOpacity(opacity()); |
|
197 | painter->setOpacity(opacity()); | |
198 | painter->setPen(d_ptr->m_pen); |
|
198 | painter->setPen(d_ptr->m_pen); | |
199 | painter->setBrush(d_ptr->m_brush); |
|
199 | painter->setBrush(d_ptr->m_brush); | |
200 | painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height())); |
|
200 | painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height())); | |
201 |
|
201 | |||
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 |
|
204 | |||
205 | /*! |
|
205 | /*! | |
206 | Sets the \a brush of legend. Brush affects the background of legend. |
|
206 | Sets the \a brush of legend. Brush affects the background of legend. | |
207 | */ |
|
207 | */ | |
208 | void QLegend::setBrush(const QBrush &brush) |
|
208 | void QLegend::setBrush(const QBrush &brush) | |
209 | { |
|
209 | { | |
210 | if (d_ptr->m_brush != brush) { |
|
210 | if (d_ptr->m_brush != brush) { | |
211 | d_ptr->m_brush = brush; |
|
211 | d_ptr->m_brush = brush; | |
212 | update(); |
|
212 | update(); | |
213 | emit colorChanged(brush.color()); |
|
213 | emit colorChanged(brush.color()); | |
214 | } |
|
214 | } | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | /*! |
|
217 | /*! | |
218 | Returns the brush used by legend. |
|
218 | Returns the brush used by legend. | |
219 | */ |
|
219 | */ | |
220 | QBrush QLegend::brush() const |
|
220 | QBrush QLegend::brush() const | |
221 | { |
|
221 | { | |
222 | return d_ptr->m_brush; |
|
222 | return d_ptr->m_brush; | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | void QLegend::setColor(QColor color) |
|
225 | void QLegend::setColor(QColor color) | |
226 | { |
|
226 | { | |
227 | QBrush b = d_ptr->m_brush; |
|
227 | QBrush b = d_ptr->m_brush; | |
228 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
228 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
229 | b.setStyle(Qt::SolidPattern); |
|
229 | b.setStyle(Qt::SolidPattern); | |
230 | b.setColor(color); |
|
230 | b.setColor(color); | |
231 | setBrush(b); |
|
231 | setBrush(b); | |
232 | } |
|
232 | } | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | QColor QLegend::color() |
|
235 | QColor QLegend::color() | |
236 | { |
|
236 | { | |
237 | return d_ptr->m_brush.color(); |
|
237 | return d_ptr->m_brush.color(); | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | /*! |
|
240 | /*! | |
241 | Sets the \a pen of legend. Pen affects the legend borders. |
|
241 | Sets the \a pen of legend. Pen affects the legend borders. | |
242 | */ |
|
242 | */ | |
243 | void QLegend::setPen(const QPen &pen) |
|
243 | void QLegend::setPen(const QPen &pen) | |
244 | { |
|
244 | { | |
245 | if (d_ptr->m_pen != pen) { |
|
245 | if (d_ptr->m_pen != pen) { | |
246 | d_ptr->m_pen = pen; |
|
246 | d_ptr->m_pen = pen; | |
247 | update(); |
|
247 | update(); | |
248 | emit borderColorChanged(pen.color()); |
|
248 | emit borderColorChanged(pen.color()); | |
249 | } |
|
249 | } | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | /*! |
|
252 | /*! | |
253 | Returns the pen used by legend |
|
253 | Returns the pen used by legend | |
254 | */ |
|
254 | */ | |
255 |
|
255 | |||
256 | QPen QLegend::pen() const |
|
256 | QPen QLegend::pen() const | |
257 | { |
|
257 | { | |
258 | return d_ptr->m_pen; |
|
258 | return d_ptr->m_pen; | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | void QLegend::setFont(const QFont &font) |
|
261 | void QLegend::setFont(const QFont &font) | |
262 | { |
|
262 | { | |
263 | if (d_ptr->m_font != font) { |
|
263 | if (d_ptr->m_font != font) { | |
264 | d_ptr->m_font = font; |
|
264 | d_ptr->m_font = font; | |
265 |
|
265 | |||
266 | foreach (LegendMarker *marker, d_ptr->markers()) { |
|
266 | foreach (LegendMarker *marker, d_ptr->markers()) { | |
267 | marker->setFont(d_ptr->m_font); |
|
267 | marker->setFont(d_ptr->m_font); | |
268 | } |
|
268 | } | |
269 | layout()->invalidate(); |
|
269 | layout()->invalidate(); | |
270 | emit fontChanged(font); |
|
270 | emit fontChanged(font); | |
271 | } |
|
271 | } | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | QFont QLegend::font() const |
|
274 | QFont QLegend::font() const | |
275 | { |
|
275 | { | |
276 | return d_ptr->m_font; |
|
276 | return d_ptr->m_font; | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | void QLegend::setBorderColor(QColor color) |
|
279 | void QLegend::setBorderColor(QColor color) | |
280 | { |
|
280 | { | |
281 | QPen p = d_ptr->m_pen; |
|
281 | QPen p = d_ptr->m_pen; | |
282 | if (p.color() != color) { |
|
282 | if (p.color() != color) { | |
283 | p.setColor(color); |
|
283 | p.setColor(color); | |
284 | setPen(p); |
|
284 | setPen(p); | |
285 | } |
|
285 | } | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | QColor QLegend::borderColor() |
|
288 | QColor QLegend::borderColor() | |
289 | { |
|
289 | { | |
290 | return d_ptr->m_pen.color(); |
|
290 | return d_ptr->m_pen.color(); | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | /*! |
|
293 | /*! | |
294 | Set brush used to draw labels to \a brush. |
|
294 | Set brush used to draw labels to \a brush. | |
295 | */ |
|
295 | */ | |
296 | void QLegend::setLabelBrush(const QBrush &brush) |
|
296 | void QLegend::setLabelBrush(const QBrush &brush) | |
297 | { |
|
297 | { | |
298 | if (d_ptr->m_labelBrush != brush) { |
|
298 | if (d_ptr->m_labelBrush != brush) { | |
299 | d_ptr->m_labelBrush = brush; |
|
299 | d_ptr->m_labelBrush = brush; | |
300 | foreach (LegendMarker *marker, d_ptr->markers()) { |
|
300 | foreach (LegendMarker *marker, d_ptr->markers()) { | |
301 | marker->setLabelBrush(d_ptr->m_labelBrush); |
|
301 | marker->setLabelBrush(d_ptr->m_labelBrush); | |
|
302 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API | |||
|
303 | // instead of mapping it from label brush color | |||
|
304 | marker->setPen(brush.color()); | |||
302 | } |
|
305 | } | |
303 | emit labelColorChanged(brush.color()); |
|
306 | emit labelColorChanged(brush.color()); | |
304 | } |
|
307 | } | |
305 | } |
|
308 | } | |
306 |
|
309 | |||
307 | /*! |
|
310 | /*! | |
308 | Brush used to draw labels. |
|
311 | Brush used to draw labels. | |
309 | */ |
|
312 | */ | |
310 | QBrush QLegend::labelBrush() const |
|
313 | QBrush QLegend::labelBrush() const | |
311 | { |
|
314 | { | |
312 | return d_ptr->m_labelBrush; |
|
315 | return d_ptr->m_labelBrush; | |
313 | } |
|
316 | } | |
314 |
|
317 | |||
315 | void QLegend::setLabelColor(QColor color) |
|
318 | void QLegend::setLabelColor(QColor color) | |
316 | { |
|
319 | { | |
317 | QBrush b = d_ptr->m_labelBrush; |
|
320 | QBrush b = d_ptr->m_labelBrush; | |
318 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
321 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
319 | b.setStyle(Qt::SolidPattern); |
|
322 | b.setStyle(Qt::SolidPattern); | |
320 | b.setColor(color); |
|
323 | b.setColor(color); | |
321 | setLabelBrush(b); |
|
324 | setLabelBrush(b); | |
322 | } |
|
325 | } | |
323 | } |
|
326 | } | |
324 |
|
327 | |||
325 | QColor QLegend::labelColor() const |
|
328 | QColor QLegend::labelColor() const | |
326 | { |
|
329 | { | |
327 | return d_ptr->m_labelBrush.color(); |
|
330 | return d_ptr->m_labelBrush.color(); | |
328 | } |
|
331 | } | |
329 |
|
332 | |||
330 |
|
333 | |||
331 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
334 | void QLegend::setAlignment(Qt::Alignment alignment) | |
332 | { |
|
335 | { | |
333 | if(d_ptr->m_alignment!=alignment) { |
|
336 | if(d_ptr->m_alignment!=alignment) { | |
334 | d_ptr->m_alignment = alignment; |
|
337 | d_ptr->m_alignment = alignment; | |
335 | updateGeometry(); |
|
338 | updateGeometry(); | |
336 | if(isAttachedToChart()){ |
|
339 | if(isAttachedToChart()){ | |
337 | d_ptr->m_presenter->layout()->invalidate(); |
|
340 | d_ptr->m_presenter->layout()->invalidate(); | |
338 | }else{ |
|
341 | }else{ | |
339 | layout()->invalidate(); |
|
342 | layout()->invalidate(); | |
340 | } |
|
343 | } | |
341 | } |
|
344 | } | |
342 | } |
|
345 | } | |
343 |
|
346 | |||
344 | Qt::Alignment QLegend::alignment() const |
|
347 | Qt::Alignment QLegend::alignment() const | |
345 | { |
|
348 | { | |
346 | return d_ptr->m_alignment; |
|
349 | return d_ptr->m_alignment; | |
347 | } |
|
350 | } | |
348 |
|
351 | |||
349 | /*! |
|
352 | /*! | |
350 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
353 | Detaches the legend from chart. Chart won't change layout of the legend. | |
351 | */ |
|
354 | */ | |
352 | void QLegend::detachFromChart() |
|
355 | void QLegend::detachFromChart() | |
353 | { |
|
356 | { | |
354 | d_ptr->m_attachedToChart = false; |
|
357 | d_ptr->m_attachedToChart = false; | |
355 | d_ptr->m_layout->invalidate(); |
|
358 | d_ptr->m_layout->invalidate(); | |
356 | setParent(0); |
|
359 | setParent(0); | |
357 |
|
360 | |||
358 | } |
|
361 | } | |
359 |
|
362 | |||
360 | /*! |
|
363 | /*! | |
361 | Attaches the legend to chart. Chart may change layout of the legend. |
|
364 | Attaches the legend to chart. Chart may change layout of the legend. | |
362 | */ |
|
365 | */ | |
363 | void QLegend::attachToChart() |
|
366 | void QLegend::attachToChart() | |
364 | { |
|
367 | { | |
365 | d_ptr->m_attachedToChart = true; |
|
368 | d_ptr->m_attachedToChart = true; | |
366 | d_ptr->m_layout->invalidate(); |
|
369 | d_ptr->m_layout->invalidate(); | |
367 | setParent(d_ptr->m_chart); |
|
370 | setParent(d_ptr->m_chart); | |
368 | } |
|
371 | } | |
369 |
|
372 | |||
370 | /*! |
|
373 | /*! | |
371 | Returns true, if legend is attached to chart. |
|
374 | Returns true, if legend is attached to chart. | |
372 | */ |
|
375 | */ | |
373 | bool QLegend::isAttachedToChart() |
|
376 | bool QLegend::isAttachedToChart() | |
374 | { |
|
377 | { | |
375 | return d_ptr->m_attachedToChart; |
|
378 | return d_ptr->m_attachedToChart; | |
376 | } |
|
379 | } | |
377 |
|
380 | |||
378 | /*! |
|
381 | /*! | |
379 | Sets the visibility of legend background to \a visible |
|
382 | Sets the visibility of legend background to \a visible | |
380 | */ |
|
383 | */ | |
381 | void QLegend::setBackgroundVisible(bool visible) |
|
384 | void QLegend::setBackgroundVisible(bool visible) | |
382 | { |
|
385 | { | |
383 | if(d_ptr->m_backgroundVisible != visible) { |
|
386 | if(d_ptr->m_backgroundVisible != visible) { | |
384 | d_ptr->m_backgroundVisible = visible; |
|
387 | d_ptr->m_backgroundVisible = visible; | |
385 | update(); |
|
388 | update(); | |
386 | emit backgroundVisibleChanged(visible); |
|
389 | emit backgroundVisibleChanged(visible); | |
387 | } |
|
390 | } | |
388 | } |
|
391 | } | |
389 |
|
392 | |||
390 | /*! |
|
393 | /*! | |
391 | Returns the visibility of legend background |
|
394 | Returns the visibility of legend background | |
392 | */ |
|
395 | */ | |
393 | bool QLegend::isBackgroundVisible() const |
|
396 | bool QLegend::isBackgroundVisible() const | |
394 | { |
|
397 | { | |
395 | return d_ptr->m_backgroundVisible; |
|
398 | return d_ptr->m_backgroundVisible; | |
396 | } |
|
399 | } | |
397 |
|
400 | |||
398 | /*! |
|
401 | /*! | |
399 | \internal \a event see QGraphicsWidget for details |
|
402 | \internal \a event see QGraphicsWidget for details | |
400 | */ |
|
403 | */ | |
401 | void QLegend::hideEvent(QHideEvent *event) |
|
404 | void QLegend::hideEvent(QHideEvent *event) | |
402 | { |
|
405 | { | |
403 | QGraphicsWidget::hideEvent(event); |
|
406 | QGraphicsWidget::hideEvent(event); | |
404 | d_ptr->m_presenter->layout()->invalidate(); |
|
407 | d_ptr->m_presenter->layout()->invalidate(); | |
405 | } |
|
408 | } | |
406 |
|
409 | |||
407 | /*! |
|
410 | /*! | |
408 | \internal \a event see QGraphicsWidget for details |
|
411 | \internal \a event see QGraphicsWidget for details | |
409 | */ |
|
412 | */ | |
410 | void QLegend::showEvent(QShowEvent *event) |
|
413 | void QLegend::showEvent(QShowEvent *event) | |
411 | { |
|
414 | { | |
412 | QGraphicsWidget::showEvent(event); |
|
415 | QGraphicsWidget::showEvent(event); | |
413 | d_ptr->m_presenter->layout()->invalidate(); |
|
416 | d_ptr->m_presenter->layout()->invalidate(); | |
414 | } |
|
417 | } | |
415 |
|
418 | |||
416 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
419 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
417 |
|
420 | |||
418 | QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q): |
|
421 | QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q): | |
419 | q_ptr(q), |
|
422 | q_ptr(q), | |
420 | m_presenter(presenter), |
|
423 | m_presenter(presenter), | |
421 | m_layout(new LegendLayout(q)), |
|
424 | m_layout(new LegendLayout(q)), | |
422 | m_chart(chart), |
|
425 | m_chart(chart), | |
423 | m_items(new QGraphicsItemGroup(q)), |
|
426 | m_items(new QGraphicsItemGroup(q)), | |
424 | m_alignment(Qt::AlignTop), |
|
427 | m_alignment(Qt::AlignTop), | |
425 | m_brush(QBrush()), |
|
428 | m_brush(QBrush()), | |
426 | m_pen(QPen()), |
|
429 | m_pen(QPen()), | |
427 | m_labelBrush(QBrush()), |
|
430 | m_labelBrush(QBrush()), | |
428 | m_diameter(5), |
|
431 | m_diameter(5), | |
429 | m_attachedToChart(true), |
|
432 | m_attachedToChart(true), | |
430 | m_backgroundVisible(false) |
|
433 | m_backgroundVisible(false) | |
431 | { |
|
434 | { | |
432 |
|
435 | |||
433 | } |
|
436 | } | |
434 |
|
437 | |||
435 | QLegendPrivate::~QLegendPrivate() |
|
438 | QLegendPrivate::~QLegendPrivate() | |
436 | { |
|
439 | { | |
437 |
|
440 | |||
438 | } |
|
441 | } | |
439 |
|
442 | |||
440 | void QLegendPrivate::setOffset(qreal x, qreal y) |
|
443 | void QLegendPrivate::setOffset(qreal x, qreal y) | |
441 | { |
|
444 | { | |
442 | m_layout->setOffset(x,y); |
|
445 | m_layout->setOffset(x,y); | |
443 | } |
|
446 | } | |
444 |
|
447 | |||
445 | QPointF QLegendPrivate::offset() const |
|
448 | QPointF QLegendPrivate::offset() const | |
446 | { |
|
449 | { | |
447 | return m_layout->offset(); |
|
450 | return m_layout->offset(); | |
448 | } |
|
451 | } | |
449 |
|
452 | |||
450 | int QLegendPrivate::roundness(qreal size) |
|
453 | int QLegendPrivate::roundness(qreal size) | |
451 | { |
|
454 | { | |
452 | return 100*m_diameter/int(size); |
|
455 | return 100*m_diameter/int(size); | |
453 | } |
|
456 | } | |
454 |
|
457 | |||
455 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) |
|
458 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) | |
456 | { |
|
459 | { | |
457 | Q_UNUSED(domain) |
|
460 | Q_UNUSED(domain) | |
458 |
|
461 | |||
459 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); |
|
462 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); | |
460 |
|
463 | |||
461 | foreach(LegendMarker* marker, markers) { |
|
464 | foreach(LegendMarker* marker, markers) { | |
462 | marker->setFont(m_font); |
|
465 | marker->setFont(m_font); | |
463 | marker->setLabelBrush(m_labelBrush); |
|
466 | marker->setLabelBrush(m_labelBrush); | |
464 | marker->setVisible(series->isVisible()); |
|
467 | marker->setVisible(series->isVisible()); | |
465 | m_items->addToGroup(marker); |
|
468 | m_items->addToGroup(marker); | |
466 | m_markers<<marker; |
|
469 | m_markers<<marker; | |
467 | } |
|
470 | } | |
468 |
|
471 | |||
469 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
472 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
470 |
|
473 | |||
471 | if(series->type() == QAbstractSeries::SeriesTypePie) { |
|
474 | if(series->type() == QAbstractSeries::SeriesTypePie) { | |
472 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
475 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
473 | QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
476 | QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
474 | QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
477 | QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
475 | } |
|
478 | } | |
476 |
|
479 | |||
477 | q_ptr->layout()->invalidate(); |
|
480 | q_ptr->layout()->invalidate(); | |
478 | q_ptr->layout()->activate(); |
|
481 | q_ptr->layout()->activate(); | |
479 | } |
|
482 | } | |
480 |
|
483 | |||
481 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
484 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | |
482 | { |
|
485 | { | |
483 | foreach (LegendMarker *marker, m_markers) { |
|
486 | foreach (LegendMarker *marker, m_markers) { | |
484 | if (marker->series() == series) { |
|
487 | if (marker->series() == series) { | |
485 | delete marker; |
|
488 | delete marker; | |
486 | m_markers.removeAll(marker); |
|
489 | m_markers.removeAll(marker); | |
487 | } |
|
490 | } | |
488 | } |
|
491 | } | |
489 |
|
492 | |||
490 | if(series->type() == QAbstractSeries::SeriesTypePie) |
|
493 | if(series->type() == QAbstractSeries::SeriesTypePie) | |
491 | { |
|
494 | { | |
492 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
495 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
493 | QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
496 | QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
494 | QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
497 | QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
495 | } |
|
498 | } | |
496 |
|
499 | |||
497 | q_ptr->layout()->invalidate(); |
|
500 | q_ptr->layout()->invalidate(); | |
498 | } |
|
501 | } | |
499 |
|
502 | |||
500 | void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series) |
|
503 | void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series) | |
501 | { |
|
504 | { | |
502 | // TODO: find out which markers are are added or removed. Update them |
|
505 | // TODO: find out which markers are are added or removed. Update them | |
503 | // TODO: better implementation |
|
506 | // TODO: better implementation | |
504 | handleSeriesRemoved(series); |
|
507 | handleSeriesRemoved(series); | |
505 | Domain domain; |
|
508 | Domain domain; | |
506 | handleSeriesAdded(series, &domain); |
|
509 | handleSeriesAdded(series, &domain); | |
507 | } |
|
510 | } | |
508 |
|
511 | |||
509 | void QLegendPrivate::handleUpdatePieSeries() |
|
512 | void QLegendPrivate::handleUpdatePieSeries() | |
510 | { |
|
513 | { | |
511 | //TODO: reimplement to be optimal |
|
514 | //TODO: reimplement to be optimal | |
512 | QPieSeries* series = qobject_cast<QPieSeries *> (sender()); |
|
515 | QPieSeries* series = qobject_cast<QPieSeries *> (sender()); | |
513 | Q_ASSERT(series); |
|
516 | Q_ASSERT(series); | |
514 | handleSeriesRemoved(series); |
|
517 | handleSeriesRemoved(series); | |
515 | handleSeriesAdded(series, 0); |
|
518 | handleSeriesAdded(series, 0); | |
516 | } |
|
519 | } | |
517 |
|
520 | |||
518 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
521 | void QLegendPrivate::handleSeriesVisibleChanged() | |
519 | { |
|
522 | { | |
520 | QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender()); |
|
523 | QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender()); | |
521 |
|
524 | |||
522 | foreach (LegendMarker* marker, m_markers) { |
|
525 | foreach (LegendMarker* marker, m_markers) { | |
523 | if (marker->series() == series) { |
|
526 | if (marker->series() == series) { | |
524 | marker->setVisible(series->isVisible()); |
|
527 | marker->setVisible(series->isVisible()); | |
525 | } |
|
528 | } | |
526 | } |
|
529 | } | |
527 |
|
530 | |||
528 | q_ptr->layout()->invalidate(); |
|
531 | q_ptr->layout()->invalidate(); | |
529 | } |
|
532 | } | |
530 |
|
533 | |||
531 | #include "moc_qlegend.cpp" |
|
534 | #include "moc_qlegend.cpp" | |
532 | #include "moc_qlegend_p.cpp" |
|
535 | #include "moc_qlegend_p.cpp" | |
533 |
|
536 | |||
534 | QTCOMMERCIALCHART_END_NAMESPACE |
|
537 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now