@@ -1,463 +1,463 | |||||
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 |
|
26 | |||
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 "qbarseries.h" |
|
33 | #include "qbarseries.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 |
|
44 | |||
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 part of QtCommercial chart API. |
|
51 | \brief part of QtCommercial chart API. | |
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 | /*! |
|
64 | /*! | |
65 | \enum QLegend::Alignment |
|
65 | \enum QLegend::Alignment | |
66 |
|
66 | |||
67 | This enum describes the possible position for legend inside chart. |
|
67 | This enum describes the possible position for legend inside chart. | |
68 |
|
68 | |||
69 | \value AlignmentTop |
|
69 | \value AlignmentTop | |
70 | \value AlignmentBottom |
|
70 | \value AlignmentBottom | |
71 | \value AlignmentLeft |
|
71 | \value AlignmentLeft | |
72 | \value AlignmentRight |
|
72 | \value AlignmentRight | |
73 | */ |
|
73 | */ | |
74 |
|
74 | |||
75 | /*! |
|
75 | /*! | |
76 | \fn qreal QLegend::minWidth() const |
|
76 | \fn qreal QLegend::minWidth() const | |
77 | Returns minimum width of the legend |
|
77 | Returns minimum width of the legend | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \fn qreal QLegend::minHeight() const |
|
81 | \fn qreal QLegend::minHeight() const | |
82 | Returns minimum height of the legend |
|
82 | Returns minimum height of the legend | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | Constructs the legend object and sets the parent to \a parent |
|
86 | Constructs the legend object and sets the parent to \a parent | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), |
|
89 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), | |
90 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,this)) |
|
90 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,this)) | |
91 | { |
|
91 | { | |
92 | setZValue(ChartPresenter::LegendZValue); |
|
92 | setZValue(ChartPresenter::LegendZValue); | |
93 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
93 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
94 | setEnabled(false); // By default legend is disabled |
|
94 | setEnabled(false); // By default legend is disabled | |
95 | setVisible(false); |
|
95 | setVisible(false); | |
96 |
QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries |
|
96 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); | |
97 |
QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries |
|
97 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
101 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. | |
102 | */ |
|
102 | */ | |
103 | QLegend::~QLegend() |
|
103 | QLegend::~QLegend() | |
104 | { |
|
104 | { | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | Paints the legend to given \a painter. Paremeters \a option and \a widget arent used. |
|
108 | Paints the legend to given \a painter. Paremeters \a option and \a widget arent used. | |
109 | */ |
|
109 | */ | |
110 |
|
110 | |||
111 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
111 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
112 | { |
|
112 | { | |
113 | Q_UNUSED(option) |
|
113 | Q_UNUSED(option) | |
114 | Q_UNUSED(widget) |
|
114 | Q_UNUSED(widget) | |
115 | if(!d_ptr->m_backgroundVisible) return; |
|
115 | if(!d_ptr->m_backgroundVisible) return; | |
116 |
|
116 | |||
117 | painter->setOpacity(opacity()); |
|
117 | painter->setOpacity(opacity()); | |
118 | painter->setPen(d_ptr->m_pen); |
|
118 | painter->setPen(d_ptr->m_pen); | |
119 | painter->setBrush(d_ptr->m_brush); |
|
119 | painter->setBrush(d_ptr->m_brush); | |
120 | painter->drawRect(boundingRect()); |
|
120 | painter->drawRect(boundingRect()); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | Bounding rect of legend. |
|
124 | Bounding rect of legend. | |
125 | */ |
|
125 | */ | |
126 |
|
126 | |||
127 | QRectF QLegend::boundingRect() const |
|
127 | QRectF QLegend::boundingRect() const | |
128 | { |
|
128 | { | |
129 | return d_ptr->m_rect; |
|
129 | return d_ptr->m_rect; | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | Sets the \a brush of legend. Brush affects the background of legend. |
|
133 | Sets the \a brush of legend. Brush affects the background of legend. | |
134 | */ |
|
134 | */ | |
135 | void QLegend::setBrush(const QBrush &brush) |
|
135 | void QLegend::setBrush(const QBrush &brush) | |
136 | { |
|
136 | { | |
137 | if (d_ptr->m_brush != brush) { |
|
137 | if (d_ptr->m_brush != brush) { | |
138 | d_ptr->m_brush = brush; |
|
138 | d_ptr->m_brush = brush; | |
139 | update(); |
|
139 | update(); | |
140 | } |
|
140 | } | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | Returns the brush used by legend. |
|
144 | Returns the brush used by legend. | |
145 | */ |
|
145 | */ | |
146 | QBrush QLegend::brush() const |
|
146 | QBrush QLegend::brush() const | |
147 | { |
|
147 | { | |
148 | return d_ptr->m_brush; |
|
148 | return d_ptr->m_brush; | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | /*! |
|
151 | /*! | |
152 | Sets the \a pen of legend. Pen affects the legend borders. |
|
152 | Sets the \a pen of legend. Pen affects the legend borders. | |
153 | */ |
|
153 | */ | |
154 | void QLegend::setPen(const QPen &pen) |
|
154 | void QLegend::setPen(const QPen &pen) | |
155 | { |
|
155 | { | |
156 | if (d_ptr->m_pen != pen) { |
|
156 | if (d_ptr->m_pen != pen) { | |
157 | d_ptr->m_pen = pen; |
|
157 | d_ptr->m_pen = pen; | |
158 | update(); |
|
158 | update(); | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | /*! |
|
162 | /*! | |
163 | Returns the pen used by legend |
|
163 | Returns the pen used by legend | |
164 | */ |
|
164 | */ | |
165 |
|
165 | |||
166 | QPen QLegend::pen() const |
|
166 | QPen QLegend::pen() const | |
167 | { |
|
167 | { | |
168 | return d_ptr->m_pen; |
|
168 | return d_ptr->m_pen; | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | Sets the \a alignment for legend. Legend tries to paint itself on the defined position in chart. |
|
172 | Sets the \a alignment for legend. Legend tries to paint itself on the defined position in chart. | |
173 | \sa QLegend::Alignment |
|
173 | \sa QLegend::Alignment | |
174 | */ |
|
174 | */ | |
175 | void QLegend::setAlignment(QLegend::Alignments alignment) |
|
175 | void QLegend::setAlignment(QLegend::Alignments alignment) | |
176 | { |
|
176 | { | |
177 | if(d_ptr->m_alignment!=alignment && d_ptr->m_attachedToChart) { |
|
177 | if(d_ptr->m_alignment!=alignment && d_ptr->m_attachedToChart) { | |
178 | d_ptr->m_alignment = alignment; |
|
178 | d_ptr->m_alignment = alignment; | |
179 | d_ptr->updateLayout(); |
|
179 | d_ptr->updateLayout(); | |
180 | } |
|
180 | } | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | /*! |
|
183 | /*! | |
184 | Returns the preferred layout for legend |
|
184 | Returns the preferred layout for legend | |
185 | */ |
|
185 | */ | |
186 | QLegend::Alignments QLegend::alignment() const |
|
186 | QLegend::Alignments QLegend::alignment() const | |
187 | { |
|
187 | { | |
188 | return d_ptr->m_alignment; |
|
188 | return d_ptr->m_alignment; | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
192 | Detaches the legend from chart. Chart won't change layout of the legend. | |
193 | */ |
|
193 | */ | |
194 | void QLegend::detachFromChart() |
|
194 | void QLegend::detachFromChart() | |
195 | { |
|
195 | { | |
196 | d_ptr->m_attachedToChart = false; |
|
196 | d_ptr->m_attachedToChart = false; | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | /*! |
|
199 | /*! | |
200 | Attaches the legend to chart. Chart may change layout of the legend. |
|
200 | Attaches the legend to chart. Chart may change layout of the legend. | |
201 | */ |
|
201 | */ | |
202 | void QLegend::attachToChart() |
|
202 | void QLegend::attachToChart() | |
203 | { |
|
203 | { | |
204 | d_ptr->m_attachedToChart = true; |
|
204 | d_ptr->m_attachedToChart = true; | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | /*! |
|
207 | /*! | |
208 | Returns true, if legend is attached to chart. |
|
208 | Returns true, if legend is attached to chart. | |
209 | */ |
|
209 | */ | |
210 | bool QLegend::isAttachedToChart() |
|
210 | bool QLegend::isAttachedToChart() | |
211 | { |
|
211 | { | |
212 | return d_ptr->m_attachedToChart; |
|
212 | return d_ptr->m_attachedToChart; | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | /*! |
|
215 | /*! | |
216 | Sets the legend's scrolling offset to value defined by \a point. |
|
216 | Sets the legend's scrolling offset to value defined by \a point. | |
217 | */ |
|
217 | */ | |
218 | void QLegend::setOffset(const QPointF& point) |
|
218 | void QLegend::setOffset(const QPointF& point) | |
219 | { |
|
219 | { | |
220 | d_ptr->setOffset(point.x(),point.y()); |
|
220 | d_ptr->setOffset(point.x(),point.y()); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | /*! |
|
223 | /*! | |
224 | Returns the legend's scrolling offset. |
|
224 | Returns the legend's scrolling offset. | |
225 | */ |
|
225 | */ | |
226 | QPointF QLegend::offset() const |
|
226 | QPointF QLegend::offset() const | |
227 | { |
|
227 | { | |
228 | return QPointF(d_ptr->m_offsetX,d_ptr->m_offsetY); |
|
228 | return QPointF(d_ptr->m_offsetX,d_ptr->m_offsetY); | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | /*! |
|
231 | /*! | |
232 | Sets the visibility of legend background to \a visible |
|
232 | Sets the visibility of legend background to \a visible | |
233 | */ |
|
233 | */ | |
234 | void QLegend::setBackgroundVisible(bool visible) |
|
234 | void QLegend::setBackgroundVisible(bool visible) | |
235 | { |
|
235 | { | |
236 | if(d_ptr->m_backgroundVisible!=visible) |
|
236 | if(d_ptr->m_backgroundVisible!=visible) | |
237 | { |
|
237 | { | |
238 | d_ptr->m_backgroundVisible=visible; |
|
238 | d_ptr->m_backgroundVisible=visible; | |
239 | update(); |
|
239 | update(); | |
240 | } |
|
240 | } | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | Returns the visibility of legend background |
|
244 | Returns the visibility of legend background | |
245 | */ |
|
245 | */ | |
246 | bool QLegend::isBackgroundVisible() const |
|
246 | bool QLegend::isBackgroundVisible() const | |
247 | { |
|
247 | { | |
248 | return d_ptr->m_backgroundVisible; |
|
248 | return d_ptr->m_backgroundVisible; | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | /*! |
|
251 | /*! | |
252 | \internal \a event see QGraphicsWidget for details |
|
252 | \internal \a event see QGraphicsWidget for details | |
253 | */ |
|
253 | */ | |
254 | void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
254 | void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event) | |
255 | { |
|
255 | { | |
256 | const QRectF& rect = QRectF(QPoint(0,0),event->newSize()); |
|
256 | const QRectF& rect = QRectF(QPoint(0,0),event->newSize()); | |
257 | QGraphicsWidget::resizeEvent(event); |
|
257 | QGraphicsWidget::resizeEvent(event); | |
258 | if(d_ptr->m_rect != rect) { |
|
258 | if(d_ptr->m_rect != rect) { | |
259 | d_ptr->m_rect = rect; |
|
259 | d_ptr->m_rect = rect; | |
260 | d_ptr->updateLayout(); |
|
260 | d_ptr->updateLayout(); | |
261 | } |
|
261 | } | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | /*! |
|
264 | /*! | |
265 | \internal \a event see QGraphicsWidget for details |
|
265 | \internal \a event see QGraphicsWidget for details | |
266 | */ |
|
266 | */ | |
267 | void QLegend::hideEvent(QHideEvent *event) |
|
267 | void QLegend::hideEvent(QHideEvent *event) | |
268 | { |
|
268 | { | |
269 | QGraphicsWidget::hideEvent(event); |
|
269 | QGraphicsWidget::hideEvent(event); | |
270 | setEnabled(false); |
|
270 | setEnabled(false); | |
271 | d_ptr->updateLayout(); |
|
271 | d_ptr->updateLayout(); | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | /*! |
|
274 | /*! | |
275 | \internal \a event see QGraphicsWidget for details |
|
275 | \internal \a event see QGraphicsWidget for details | |
276 | */ |
|
276 | */ | |
277 | void QLegend::showEvent(QShowEvent *event) |
|
277 | void QLegend::showEvent(QShowEvent *event) | |
278 | { |
|
278 | { | |
279 | QGraphicsWidget::showEvent(event); |
|
279 | QGraphicsWidget::showEvent(event); | |
280 | setEnabled(true); |
|
280 | setEnabled(true); | |
281 | d_ptr->updateLayout(); |
|
281 | d_ptr->updateLayout(); | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | qreal QLegend::minWidth() const |
|
284 | qreal QLegend::minWidth() const | |
285 | { |
|
285 | { | |
286 | return d_ptr->m_minWidth; |
|
286 | return d_ptr->m_minWidth; | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | qreal QLegend::minHeight() const |
|
289 | qreal QLegend::minHeight() const | |
290 | { |
|
290 | { | |
291 | return d_ptr->m_minHeight; |
|
291 | return d_ptr->m_minHeight; | |
292 | } |
|
292 | } | |
293 |
|
293 | |||
294 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
294 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
295 |
|
295 | |||
296 | QLegendPrivate::QLegendPrivate(ChartPresenter* presenter,QLegend *q): |
|
296 | QLegendPrivate::QLegendPrivate(ChartPresenter* presenter,QLegend *q): | |
297 | q_ptr(q), |
|
297 | q_ptr(q), | |
298 | m_presenter(presenter), |
|
298 | m_presenter(presenter), | |
299 | m_markers(new QGraphicsItemGroup(q)), |
|
299 | m_markers(new QGraphicsItemGroup(q)), | |
300 | m_alignment(QLegend::AlignmentTop), |
|
300 | m_alignment(QLegend::AlignmentTop), | |
301 | m_offsetX(0), |
|
301 | m_offsetX(0), | |
302 | m_offsetY(0), |
|
302 | m_offsetY(0), | |
303 | m_minWidth(0), |
|
303 | m_minWidth(0), | |
304 | m_minHeight(0), |
|
304 | m_minHeight(0), | |
305 | m_width(0), |
|
305 | m_width(0), | |
306 | m_height(0), |
|
306 | m_height(0), | |
307 | m_attachedToChart(true), |
|
307 | m_attachedToChart(true), | |
308 | m_backgroundVisible(false) |
|
308 | m_backgroundVisible(false) | |
309 | { |
|
309 | { | |
310 |
|
310 | |||
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 | QLegendPrivate::~QLegendPrivate() |
|
313 | QLegendPrivate::~QLegendPrivate() | |
314 | { |
|
314 | { | |
315 |
|
315 | |||
316 | } |
|
316 | } | |
317 |
|
317 | |||
318 | void QLegendPrivate::setOffset(qreal x, qreal y) |
|
318 | void QLegendPrivate::setOffset(qreal x, qreal y) | |
319 | { |
|
319 | { | |
320 |
|
320 | |||
321 | switch(m_alignment) { |
|
321 | switch(m_alignment) { | |
322 |
|
322 | |||
323 | case QLegend::AlignmentTop: |
|
323 | case QLegend::AlignmentTop: | |
324 | case QLegend::AlignmentBottom: { |
|
324 | case QLegend::AlignmentBottom: { | |
325 | if(m_width<=m_rect.width()) return; |
|
325 | if(m_width<=m_rect.width()) return; | |
326 |
|
326 | |||
327 | if (x != m_offsetX) { |
|
327 | if (x != m_offsetX) { | |
328 | m_offsetX = qBound(qreal(0), x, m_width - m_rect.width()); |
|
328 | m_offsetX = qBound(qreal(0), x, m_width - m_rect.width()); | |
329 | m_markers->setPos(-m_offsetX,m_rect.top()); |
|
329 | m_markers->setPos(-m_offsetX,m_rect.top()); | |
330 | } |
|
330 | } | |
331 | break; |
|
331 | break; | |
332 | } |
|
332 | } | |
333 | case QLegend::AlignmentLeft: |
|
333 | case QLegend::AlignmentLeft: | |
334 | case QLegend::AlignmentRight: { |
|
334 | case QLegend::AlignmentRight: { | |
335 |
|
335 | |||
336 | if(m_height<=m_rect.height()) return; |
|
336 | if(m_height<=m_rect.height()) return; | |
337 |
|
337 | |||
338 | if (y != m_offsetY) { |
|
338 | if (y != m_offsetY) { | |
339 | m_offsetY = qBound(qreal(0), y, m_height - m_rect.height()); |
|
339 | m_offsetY = qBound(qreal(0), y, m_height - m_rect.height()); | |
340 | m_markers->setPos(m_rect.left(),-m_offsetY); |
|
340 | m_markers->setPos(m_rect.left(),-m_offsetY); | |
341 | } |
|
341 | } | |
342 | break; |
|
342 | break; | |
343 | } |
|
343 | } | |
344 | } |
|
344 | } | |
345 | } |
|
345 | } | |
346 |
|
346 | |||
347 |
|
347 | |||
348 | void QLegendPrivate::updateLayout() |
|
348 | void QLegendPrivate::updateLayout() | |
349 | { |
|
349 | { | |
350 | m_offsetX=0; |
|
350 | m_offsetX=0; | |
351 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
351 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
352 |
|
352 | |||
353 | if(items.isEmpty()) return; |
|
353 | if(items.isEmpty()) return; | |
354 |
|
354 | |||
355 | m_minWidth=0; |
|
355 | m_minWidth=0; | |
356 | m_minHeight=0; |
|
356 | m_minHeight=0; | |
357 |
|
357 | |||
358 | switch(m_alignment) { |
|
358 | switch(m_alignment) { | |
359 |
|
359 | |||
360 | case QLegend::AlignmentTop: |
|
360 | case QLegend::AlignmentTop: | |
361 | case QLegend::AlignmentBottom: { |
|
361 | case QLegend::AlignmentBottom: { | |
362 | QPointF point = m_rect.topLeft(); |
|
362 | QPointF point = m_rect.topLeft(); | |
363 | m_width = 0; |
|
363 | m_width = 0; | |
364 | foreach (QGraphicsItem *item, items) { |
|
364 | foreach (QGraphicsItem *item, items) { | |
365 | item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2); |
|
365 | item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2); | |
366 | const QRectF& rect = item->boundingRect(); |
|
366 | const QRectF& rect = item->boundingRect(); | |
367 | qreal w = rect.width(); |
|
367 | qreal w = rect.width(); | |
368 | m_minWidth=qMax(m_minWidth,w); |
|
368 | m_minWidth=qMax(m_minWidth,w); | |
369 | m_minHeight=qMax(m_minHeight,rect.height()); |
|
369 | m_minHeight=qMax(m_minHeight,rect.height()); | |
370 | m_width+=w; |
|
370 | m_width+=w; | |
371 | point.setX(point.x() + w); |
|
371 | point.setX(point.x() + w); | |
372 | } |
|
372 | } | |
373 | if(m_width<m_rect.width()) { |
|
373 | if(m_width<m_rect.width()) { | |
374 | m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top()); |
|
374 | m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top()); | |
375 | } |
|
375 | } | |
376 | else { |
|
376 | else { | |
377 | m_markers->setPos(m_rect.topLeft()); |
|
377 | m_markers->setPos(m_rect.topLeft()); | |
378 | } |
|
378 | } | |
379 | m_height=m_minHeight; |
|
379 | m_height=m_minHeight; | |
380 | } |
|
380 | } | |
381 | break; |
|
381 | break; | |
382 | case QLegend::AlignmentLeft: |
|
382 | case QLegend::AlignmentLeft: | |
383 | case QLegend::AlignmentRight: { |
|
383 | case QLegend::AlignmentRight: { | |
384 | QPointF point = m_rect.topLeft(); |
|
384 | QPointF point = m_rect.topLeft(); | |
385 | m_height = 0; |
|
385 | m_height = 0; | |
386 | foreach (QGraphicsItem *item, items) { |
|
386 | foreach (QGraphicsItem *item, items) { | |
387 | item->setPos(point); |
|
387 | item->setPos(point); | |
388 | const QRectF& rect = item->boundingRect(); |
|
388 | const QRectF& rect = item->boundingRect(); | |
389 | qreal h = rect.height(); |
|
389 | qreal h = rect.height(); | |
390 | m_minWidth=qMax(m_minWidth,rect.width()); |
|
390 | m_minWidth=qMax(m_minWidth,rect.width()); | |
391 | m_minHeight=qMax(m_minHeight,h); |
|
391 | m_minHeight=qMax(m_minHeight,h); | |
392 | m_height+=h; |
|
392 | m_height+=h; | |
393 | point.setY(point.y() + h); |
|
393 | point.setY(point.y() + h); | |
394 | } |
|
394 | } | |
395 | if(m_height<m_rect.height()) { |
|
395 | if(m_height<m_rect.height()) { | |
396 | m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2); |
|
396 | m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2); | |
397 | } |
|
397 | } | |
398 | else { |
|
398 | else { | |
399 | m_markers->setPos(m_rect.topLeft()); |
|
399 | m_markers->setPos(m_rect.topLeft()); | |
400 | } |
|
400 | } | |
401 | m_width=m_minWidth; |
|
401 | m_width=m_minWidth; | |
402 | } |
|
402 | } | |
403 | break; |
|
403 | break; | |
404 | } |
|
404 | } | |
405 |
|
405 | |||
406 | m_presenter->updateLayout(); |
|
406 | m_presenter->updateLayout(); | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
409 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) |
|
409 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) | |
410 | { |
|
410 | { | |
411 | Q_UNUSED(domain) |
|
411 | Q_UNUSED(domain) | |
412 |
|
412 | |||
413 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); |
|
413 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); | |
414 | foreach(LegendMarker* marker , markers) |
|
414 | foreach(LegendMarker* marker , markers) | |
415 | m_markers->addToGroup(marker); |
|
415 | m_markers->addToGroup(marker); | |
416 |
|
416 | |||
417 | if(series->type() == QAbstractSeries::SeriesTypePie) |
|
417 | if(series->type() == QAbstractSeries::SeriesTypePie) | |
418 | { |
|
418 | { | |
419 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
419 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
420 | QPieSeriesPrivate *d = QPieSeriesPrivate::seriesData(*pieSeries); |
|
420 | QPieSeriesPrivate *d = QPieSeriesPrivate::seriesData(*pieSeries); | |
421 | QObject::connect(d, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
421 | QObject::connect(d, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
422 | QObject::connect(d, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
422 | QObject::connect(d, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | updateLayout(); |
|
425 | updateLayout(); | |
426 | } |
|
426 | } | |
427 |
|
427 | |||
428 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
428 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | |
429 | { |
|
429 | { | |
430 |
|
430 | |||
431 | QList<QGraphicsItem *> items = m_markers->childItems(); |
|
431 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
432 |
|
432 | |||
433 | foreach (QGraphicsItem *markers, items) { |
|
433 | foreach (QGraphicsItem *markers, items) { | |
434 | LegendMarker *marker = static_cast<LegendMarker*>(markers); |
|
434 | LegendMarker *marker = static_cast<LegendMarker*>(markers); | |
435 | if (marker->series() == series) { |
|
435 | if (marker->series() == series) { | |
436 | delete marker; |
|
436 | delete marker; | |
437 | } |
|
437 | } | |
438 | } |
|
438 | } | |
439 |
|
439 | |||
440 | if(series->type() == QAbstractSeries::SeriesTypePie) |
|
440 | if(series->type() == QAbstractSeries::SeriesTypePie) | |
441 | { |
|
441 | { | |
442 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
442 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
443 | QPieSeriesPrivate *d = QPieSeriesPrivate::seriesData(*pieSeries); |
|
443 | QPieSeriesPrivate *d = QPieSeriesPrivate::seriesData(*pieSeries); | |
444 | QObject::disconnect(d, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
444 | QObject::disconnect(d, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
445 | QObject::disconnect(d, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
445 | QObject::disconnect(d, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 | updateLayout(); |
|
448 | updateLayout(); | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | void QLegendPrivate::handleUpdatePieSeries() |
|
451 | void QLegendPrivate::handleUpdatePieSeries() | |
452 | { |
|
452 | { | |
453 | //TODO: reimplement to be optimal |
|
453 | //TODO: reimplement to be optimal | |
454 | QPieSeriesPrivate* d = qobject_cast<QPieSeriesPrivate *> (sender()); |
|
454 | QPieSeriesPrivate* d = qobject_cast<QPieSeriesPrivate *> (sender()); | |
455 | Q_ASSERT(d->q_func()); |
|
455 | Q_ASSERT(d->q_func()); | |
456 | handleSeriesRemoved(d->q_func()); |
|
456 | handleSeriesRemoved(d->q_func()); | |
457 | handleSeriesAdded(d->q_func(), 0); |
|
457 | handleSeriesAdded(d->q_func(), 0); | |
458 | } |
|
458 | } | |
459 |
|
459 | |||
460 | #include "moc_qlegend.cpp" |
|
460 | #include "moc_qlegend.cpp" | |
461 | #include "moc_qlegend_p.cpp" |
|
461 | #include "moc_qlegend_p.cpp" | |
462 |
|
462 | |||
463 | QTCOMMERCIALCHART_END_NAMESPACE |
|
463 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,436 +1,435 | |||||
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 "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "legendscroller_p.h" |
|
23 | #include "legendscroller_p.h" | |
24 | #include "qlegend_p.h" |
|
24 | #include "qlegend_p.h" | |
25 | #include "chartbackground_p.h" |
|
25 | #include "chartbackground_p.h" | |
26 | #include "qaxis.h" |
|
26 | #include "qaxis.h" | |
27 | #include <QGraphicsScene> |
|
27 | #include <QGraphicsScene> | |
28 | #include <QGraphicsSceneResizeEvent> |
|
28 | #include <QGraphicsSceneResizeEvent> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \enum QChart::ChartTheme |
|
33 | \enum QChart::ChartTheme | |
34 |
|
34 | |||
35 | This enum describes the theme used by the chart. |
|
35 | This enum describes the theme used by the chart. | |
36 |
|
36 | |||
37 | \value ChartThemeLight The default theme |
|
37 | \value ChartThemeLight The default theme | |
38 | \value ChartThemeBlueCerulean |
|
38 | \value ChartThemeBlueCerulean | |
39 | \value ChartThemeDark |
|
39 | \value ChartThemeDark | |
40 | \value ChartThemeBrownSand |
|
40 | \value ChartThemeBrownSand | |
41 | \value ChartThemeBlueNcs |
|
41 | \value ChartThemeBlueNcs | |
42 | \value ChartThemeHighContrast |
|
42 | \value ChartThemeHighContrast | |
43 | \value ChartThemeBlueIcy |
|
43 | \value ChartThemeBlueIcy | |
44 | */ |
|
44 | */ | |
45 |
|
45 | |||
46 | /*! |
|
46 | /*! | |
47 | \enum QChart::AnimationOption |
|
47 | \enum QChart::AnimationOption | |
48 |
|
48 | |||
49 | For enabling/disabling animations. Defaults to NoAnimation. |
|
49 | For enabling/disabling animations. Defaults to NoAnimation. | |
50 |
|
50 | |||
51 | \value NoAnimation |
|
51 | \value NoAnimation | |
52 | \value GridAxisAnimations |
|
52 | \value GridAxisAnimations | |
53 | \value SeriesAnimations |
|
53 | \value SeriesAnimations | |
54 | \value AllAnimations |
|
54 | \value AllAnimations | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \class QChart |
|
58 | \class QChart | |
59 | \brief QtCommercial chart API. |
|
59 | \brief QtCommercial chart API. | |
60 |
|
60 | |||
61 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
61 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
62 | representation of different types of series and other chart related objects like |
|
62 | representation of different types of series and other chart related objects like | |
63 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the |
|
63 | QAxis and QLegend. If you simply want to show a chart in a layout, you can use the | |
64 | convenience class QChartView instead of QChart. |
|
64 | convenience class QChartView instead of QChart. | |
65 | \sa QChartView |
|
65 | \sa QChartView | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
69 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
70 | */ |
|
70 | */ | |
71 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
71 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
72 | d_ptr(new QChartPrivate()) |
|
72 | d_ptr(new QChartPrivate()) | |
73 | { |
|
73 | { | |
74 | d_ptr->m_dataset = new ChartDataSet(this); |
|
74 | d_ptr->m_dataset = new ChartDataSet(this); | |
75 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
75 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); | |
76 | d_ptr->createConnections(); |
|
76 | d_ptr->createConnections(); | |
77 | d_ptr->m_legend = new LegendScroller(this); |
|
77 | d_ptr->m_legend = new LegendScroller(this); | |
78 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
78 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | Destroys the object and it's children, like series and axis objects added to it. |
|
82 | Destroys the object and it's children, like series and axis objects added to it. | |
83 | */ |
|
83 | */ | |
84 | QChart::~QChart() |
|
84 | QChart::~QChart() | |
85 | { |
|
85 | { | |
86 | //delete first presenter , since this is a root of all the graphical items |
|
86 | //delete first presenter , since this is a root of all the graphical items | |
87 | delete d_ptr->m_presenter; |
|
87 | delete d_ptr->m_presenter; | |
88 | d_ptr->m_presenter=0; |
|
88 | d_ptr->m_presenter=0; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
92 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
93 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
93 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
94 | the y axis). |
|
94 | the y axis). | |
95 | */ |
|
95 | */ | |
96 | void QChart::addSeries(QAbstractSeries *series, QAxis *axisY) |
|
96 | void QChart::addSeries(QAbstractSeries *series, QAxis *axisY) | |
97 | { |
|
97 | { | |
98 | Q_ASSERT(series); |
|
98 | Q_ASSERT(series); | |
99 | d_ptr->m_dataset->addSeries(series, axisY); |
|
99 | d_ptr->m_dataset->addSeries(series, axisY); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | /*! |
|
102 | /*! | |
103 | Removes the \a series specified in a perameter from the QChartView. |
|
103 | Removes the \a series specified in a perameter from the QChartView. | |
104 | It releses its ownership of the specified QChartSeries object. |
|
104 | It releses its ownership of the specified QChartSeries object. | |
105 | It does not delete the pointed QChartSeries data object |
|
105 | It does not delete the pointed QChartSeries data object | |
106 | \sa addSeries(), removeAllSeries() |
|
106 | \sa addSeries(), removeAllSeries() | |
107 | */ |
|
107 | */ | |
108 | void QChart::removeSeries(QAbstractSeries *series) |
|
108 | void QChart::removeSeries(QAbstractSeries *series) | |
109 | { |
|
109 | { | |
110 | Q_ASSERT(series); |
|
110 | Q_ASSERT(series); | |
111 | d_ptr->m_dataset->removeSeries(series); |
|
111 | d_ptr->m_dataset->removeSeries(series); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | Removes all the QChartSeries that have been added to the QChartView |
|
115 | Removes all the QChartSeries that have been added to the QChartView | |
116 | It also deletes the pointed QChartSeries data objects |
|
116 | It also deletes the pointed QChartSeries data objects | |
117 | \sa addSeries(), removeSeries() |
|
117 | \sa addSeries(), removeSeries() | |
118 | */ |
|
118 | */ | |
119 | void QChart::removeAllSeries() |
|
119 | void QChart::removeAllSeries() | |
120 | { |
|
120 | { | |
121 | d_ptr->m_dataset->removeAllSeries(); |
|
121 | d_ptr->m_dataset->removeAllSeries(); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | Sets the \a brush that is used for painting the background of the chart area. |
|
125 | Sets the \a brush that is used for painting the background of the chart area. | |
126 | */ |
|
126 | */ | |
127 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
127 | void QChart::setBackgroundBrush(const QBrush& brush) | |
128 | { |
|
128 | { | |
129 | //TODO: refactor me |
|
129 | //TODO: refactor me | |
130 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
130 | d_ptr->m_presenter->createChartBackgroundItem(); | |
131 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); |
|
131 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); | |
132 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
132 | d_ptr->m_presenter->m_backgroundItem->update(); | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | /*! |
|
135 | /*! | |
136 | Gets the brush that is used for painting the background of the chart area. |
|
136 | Gets the brush that is used for painting the background of the chart area. | |
137 | */ |
|
137 | */ | |
138 | QBrush QChart::backgroundBrush() const |
|
138 | QBrush QChart::backgroundBrush() const | |
139 | { |
|
139 | { | |
140 | //TODO: refactor me |
|
140 | //TODO: refactor me | |
141 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); |
|
141 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); | |
142 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); |
|
142 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | Sets the \a pen that is used for painting the background of the chart area. |
|
146 | Sets the \a pen that is used for painting the background of the chart area. | |
147 | */ |
|
147 | */ | |
148 | void QChart::setBackgroundPen(const QPen& pen) |
|
148 | void QChart::setBackgroundPen(const QPen& pen) | |
149 | { |
|
149 | { | |
150 | //TODO: refactor me |
|
150 | //TODO: refactor me | |
151 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
151 | d_ptr->m_presenter->createChartBackgroundItem(); | |
152 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); |
|
152 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); | |
153 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
153 | d_ptr->m_presenter->m_backgroundItem->update(); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | /*! |
|
156 | /*! | |
157 | Gets the pen that is used for painting the background of the chart area. |
|
157 | Gets the pen that is used for painting the background of the chart area. | |
158 | */ |
|
158 | */ | |
159 | QPen QChart::backgroundPen() const |
|
159 | QPen QChart::backgroundPen() const | |
160 | { |
|
160 | { | |
161 | //TODO: refactor me |
|
161 | //TODO: refactor me | |
162 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); |
|
162 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); | |
163 | return d_ptr->m_presenter->m_backgroundItem->pen(); |
|
163 | return d_ptr->m_presenter->m_backgroundItem->pen(); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | /*! |
|
166 | /*! | |
167 | Sets the chart \a title. The description text that is drawn above the chart. |
|
167 | Sets the chart \a title. The description text that is drawn above the chart. | |
168 | */ |
|
168 | */ | |
169 | void QChart::setTitle(const QString& title) |
|
169 | void QChart::setTitle(const QString& title) | |
170 | { |
|
170 | { | |
171 | //TODO: refactor me |
|
171 | //TODO: refactor me | |
172 | d_ptr->m_presenter->createChartTitleItem(); |
|
172 | d_ptr->m_presenter->createChartTitleItem(); | |
173 | d_ptr->m_presenter->m_titleItem->setText(title); |
|
173 | d_ptr->m_presenter->m_titleItem->setText(title); | |
174 | d_ptr->m_presenter->updateLayout(); |
|
174 | d_ptr->m_presenter->updateLayout(); | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | /*! |
|
177 | /*! | |
178 | Returns the chart title. The description text that is drawn above the chart. |
|
178 | Returns the chart title. The description text that is drawn above the chart. | |
179 | */ |
|
179 | */ | |
180 | QString QChart::title() const |
|
180 | QString QChart::title() const | |
181 | { |
|
181 | { | |
182 | //TODO: refactor me |
|
182 | //TODO: refactor me | |
183 | if (d_ptr->m_presenter->m_titleItem) |
|
183 | if (d_ptr->m_presenter->m_titleItem) | |
184 | return d_ptr->m_presenter->m_titleItem->text(); |
|
184 | return d_ptr->m_presenter->m_titleItem->text(); | |
185 | else |
|
185 | else | |
186 | return QString(); |
|
186 | return QString(); | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | /*! |
|
189 | /*! | |
190 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. |
|
190 | Sets the \a font that is used for drawing the chart description text that is rendered above the chart. | |
191 | */ |
|
191 | */ | |
192 | void QChart::setTitleFont(const QFont& font) |
|
192 | void QChart::setTitleFont(const QFont& font) | |
193 | { |
|
193 | { | |
194 | //TODO: refactor me |
|
194 | //TODO: refactor me | |
195 | d_ptr->m_presenter->createChartTitleItem(); |
|
195 | d_ptr->m_presenter->createChartTitleItem(); | |
196 | d_ptr->m_presenter->m_titleItem->setFont(font); |
|
196 | d_ptr->m_presenter->m_titleItem->setFont(font); | |
197 | d_ptr->m_presenter->updateLayout(); |
|
197 | d_ptr->m_presenter->updateLayout(); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Gets the font that is used for drawing the chart description text that is rendered above the chart. |
|
201 | Gets the font that is used for drawing the chart description text that is rendered above the chart. | |
202 | */ |
|
202 | */ | |
203 | QFont QChart::titleFont() const |
|
203 | QFont QChart::titleFont() const | |
204 | { |
|
204 | { | |
205 | if (d_ptr->m_presenter->m_titleItem) |
|
205 | if (d_ptr->m_presenter->m_titleItem) | |
206 | return d_ptr->m_presenter->m_titleItem->font(); |
|
206 | return d_ptr->m_presenter->m_titleItem->font(); | |
207 | else |
|
207 | else | |
208 | return QFont(); |
|
208 | return QFont(); | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | /*! |
|
211 | /*! | |
212 | Sets the \a brush used for rendering the title text. |
|
212 | Sets the \a brush used for rendering the title text. | |
213 | */ |
|
213 | */ | |
214 | void QChart::setTitleBrush(const QBrush &brush) |
|
214 | void QChart::setTitleBrush(const QBrush &brush) | |
215 | { |
|
215 | { | |
216 | //TODO: refactor me |
|
216 | //TODO: refactor me | |
217 | d_ptr->m_presenter->createChartTitleItem(); |
|
217 | d_ptr->m_presenter->createChartTitleItem(); | |
218 | d_ptr->m_presenter->m_titleItem->setBrush(brush); |
|
218 | d_ptr->m_presenter->m_titleItem->setBrush(brush); | |
219 | d_ptr->m_presenter->updateLayout(); |
|
219 | d_ptr->m_presenter->updateLayout(); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | Returns the brush used for rendering the title text. |
|
223 | Returns the brush used for rendering the title text. | |
224 | */ |
|
224 | */ | |
225 | QBrush QChart::titleBrush() const |
|
225 | QBrush QChart::titleBrush() const | |
226 | { |
|
226 | { | |
227 | //TODO: refactor me |
|
227 | //TODO: refactor me | |
228 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); |
|
228 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); | |
229 | return d_ptr->m_presenter->m_titleItem->brush(); |
|
229 | return d_ptr->m_presenter->m_titleItem->brush(); | |
230 | } |
|
230 | } | |
231 |
|
231 | |||
232 | /*! |
|
232 | /*! | |
233 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
233 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
234 | \sa theme() |
|
234 | \sa theme() | |
235 | */ |
|
235 | */ | |
236 | void QChart::setTheme(QChart::ChartTheme theme) |
|
236 | void QChart::setTheme(QChart::ChartTheme theme) | |
237 | { |
|
237 | { | |
238 | d_ptr->m_presenter->setTheme(theme); |
|
238 | d_ptr->m_presenter->setTheme(theme); | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | /*! |
|
241 | /*! | |
242 | Returns the theme enum used by the chart. |
|
242 | Returns the theme enum used by the chart. | |
243 | \sa ChartTheme, setTheme() |
|
243 | \sa ChartTheme, setTheme() | |
244 | */ |
|
244 | */ | |
245 | QChart::ChartTheme QChart::theme() const |
|
245 | QChart::ChartTheme QChart::theme() const | |
246 | { |
|
246 | { | |
247 | return d_ptr->m_presenter->theme(); |
|
247 | return d_ptr->m_presenter->theme(); | |
248 | } |
|
248 | } | |
249 |
|
249 | |||
250 | /*! |
|
250 | /*! | |
251 | Zooms in the view by a factor of 2 |
|
251 | Zooms in the view by a factor of 2 | |
252 | */ |
|
252 | */ | |
253 | void QChart::zoomIn() |
|
253 | void QChart::zoomIn() | |
254 | { |
|
254 | { | |
255 | d_ptr->m_presenter->zoomIn(); |
|
255 | d_ptr->m_presenter->zoomIn(); | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | /*! |
|
258 | /*! | |
259 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
259 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
260 | */ |
|
260 | */ | |
261 | void QChart::zoomIn(const QRectF& rect) |
|
261 | void QChart::zoomIn(const QRectF& rect) | |
262 | { |
|
262 | { | |
263 | if (!rect.isValid()) return; |
|
263 | if (!rect.isValid()) return; | |
264 | d_ptr->m_presenter->zoomIn(rect); |
|
264 | d_ptr->m_presenter->zoomIn(rect); | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | /*! |
|
267 | /*! | |
268 | Restores the view zoom level to the previous one. |
|
268 | Restores the view zoom level to the previous one. | |
269 | */ |
|
269 | */ | |
270 | void QChart::zoomOut() |
|
270 | void QChart::zoomOut() | |
271 | { |
|
271 | { | |
272 | d_ptr->m_presenter->zoomOut(); |
|
272 | d_ptr->m_presenter->zoomOut(); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Returns the pointer to the x axis object of the chart |
|
276 | Returns the pointer to the x axis object of the chart | |
277 | */ |
|
277 | */ | |
278 | QAxis* QChart::axisX() const |
|
278 | QAxis* QChart::axisX() const | |
279 | { |
|
279 | { | |
280 | return d_ptr->m_dataset->axisX(); |
|
280 | return d_ptr->m_dataset->axisX(); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | /*! |
|
283 | /*! | |
284 | Returns the pointer to the y axis object of the \a series |
|
284 | Returns the pointer to the y axis object of the \a series | |
285 | If no \a series is provided then default Y axis of the chart is returned. |
|
285 | If no \a series is provided then default Y axis of the chart is returned. | |
286 | */ |
|
286 | */ | |
287 | QAxis* QChart::axisY(QAbstractSeries *series) const |
|
287 | QAxis* QChart::axisY(QAbstractSeries *series) const | |
288 | { |
|
288 | { | |
289 | return d_ptr->m_dataset->axisY(series); |
|
289 | return d_ptr->m_dataset->axisY(series); | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | /*! |
|
292 | /*! | |
293 | Returns the legend object of the chart. Ownership stays in chart. |
|
293 | Returns the legend object of the chart. Ownership stays in chart. | |
294 | */ |
|
294 | */ | |
295 | QLegend* QChart::legend() const |
|
295 | QLegend* QChart::legend() const | |
296 | { |
|
296 | { | |
297 | return d_ptr->m_legend; |
|
297 | return d_ptr->m_legend; | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | /*! |
|
300 | /*! | |
301 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
301 | Returns the rect that contains information about margins (distance between chart widget edge and axes). | |
302 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
302 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. | |
303 | */ |
|
303 | */ | |
304 | QRectF QChart::margins() const |
|
304 | QRectF QChart::margins() const | |
305 | { |
|
305 | { | |
306 | return d_ptr->m_presenter->margins(); |
|
306 | return d_ptr->m_presenter->margins(); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 |
|
309 | |||
310 | /*! |
|
310 | /*! | |
311 | Resizes and updates the chart area using the \a event data |
|
311 | Resizes and updates the chart area using the \a event data | |
312 | */ |
|
312 | */ | |
313 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
313 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
314 | { |
|
314 | { | |
315 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
315 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); | |
316 | QGraphicsWidget::resizeEvent(event); |
|
316 | QGraphicsWidget::resizeEvent(event); | |
317 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); |
|
317 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | /*! |
|
320 | /*! | |
321 | Sets animation \a options for the chart |
|
321 | Sets animation \a options for the chart | |
322 | */ |
|
322 | */ | |
323 | void QChart::setAnimationOptions(AnimationOptions options) |
|
323 | void QChart::setAnimationOptions(AnimationOptions options) | |
324 | { |
|
324 | { | |
325 | d_ptr->m_presenter->setAnimationOptions(options); |
|
325 | d_ptr->m_presenter->setAnimationOptions(options); | |
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | /*! |
|
328 | /*! | |
329 | Returns animation options for the chart |
|
329 | Returns animation options for the chart | |
330 | */ |
|
330 | */ | |
331 | QChart::AnimationOptions QChart::animationOptions() const |
|
331 | QChart::AnimationOptions QChart::animationOptions() const | |
332 | { |
|
332 | { | |
333 | return d_ptr->m_presenter->animationOptions(); |
|
333 | return d_ptr->m_presenter->animationOptions(); | |
334 | } |
|
334 | } | |
335 |
|
335 | |||
336 | /*! |
|
336 | /*! | |
337 | Scrolls the visible area of the chart to the left by the distance between two x axis ticks |
|
337 | Scrolls the visible area of the chart to the left by the distance between two x axis ticks | |
338 | */ |
|
338 | */ | |
339 | void QChart::scrollLeft() |
|
339 | void QChart::scrollLeft() | |
340 | { |
|
340 | { | |
341 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
341 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 | /*! |
|
344 | /*! | |
345 | Scrolls the visible area of the chart to the right by the distance between two x axis ticks |
|
345 | Scrolls the visible area of the chart to the right by the distance between two x axis ticks | |
346 | */ |
|
346 | */ | |
347 | void QChart::scrollRight() |
|
347 | void QChart::scrollRight() | |
348 | { |
|
348 | { | |
349 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
349 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | /*! |
|
352 | /*! | |
353 | Scrolls the visible area of the chart up by the distance between two y axis ticks |
|
353 | Scrolls the visible area of the chart up by the distance between two y axis ticks | |
354 | */ |
|
354 | */ | |
355 | void QChart::scrollUp() |
|
355 | void QChart::scrollUp() | |
356 | { |
|
356 | { | |
357 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
357 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
358 | } |
|
358 | } | |
359 |
|
359 | |||
360 | /*! |
|
360 | /*! | |
361 | Scrolls the visible area of the chart down by the distance between two y axis ticks |
|
361 | Scrolls the visible area of the chart down by the distance between two y axis ticks | |
362 | */ |
|
362 | */ | |
363 | void QChart::scrollDown() |
|
363 | void QChart::scrollDown() | |
364 | { |
|
364 | { | |
365 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
365 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
366 | } |
|
366 | } | |
367 |
|
367 | |||
368 | /*! |
|
368 | /*! | |
369 | Sets the chart background visibility state to \a visible |
|
369 | Sets the chart background visibility state to \a visible | |
370 | */ |
|
370 | */ | |
371 | void QChart::setBackgroundVisible(bool visible) |
|
371 | void QChart::setBackgroundVisible(bool visible) | |
372 | { |
|
372 | { | |
373 | //TODO: refactor me |
|
373 | //TODO: refactor me | |
374 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
374 | d_ptr->m_presenter->createChartBackgroundItem(); | |
375 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); |
|
375 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | /*! |
|
378 | /*! | |
379 | Returns the chart's background visibility state |
|
379 | Returns the chart's background visibility state | |
380 | */ |
|
380 | */ | |
381 | bool QChart::isBackgroundVisible() const |
|
381 | bool QChart::isBackgroundVisible() const | |
382 | { |
|
382 | { | |
383 | //TODO: refactor me |
|
383 | //TODO: refactor me | |
384 | if (!d_ptr->m_presenter->m_backgroundItem) |
|
384 | if (!d_ptr->m_presenter->m_backgroundItem) | |
385 | return false; |
|
385 | return false; | |
386 |
|
386 | |||
387 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); |
|
387 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); | |
388 | } |
|
388 | } | |
389 |
|
389 | |||
390 | /*! |
|
390 | /*! | |
391 | Sets the background drop shadow effect state to \a enabled. |
|
391 | Sets the background drop shadow effect state to \a enabled. | |
392 | */ |
|
392 | */ | |
393 | void QChart::setBackgroundDropShadowEnabled(bool enabled) |
|
393 | void QChart::setBackgroundDropShadowEnabled(bool enabled) | |
394 | { |
|
394 | { | |
395 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
395 | d_ptr->m_presenter->createChartBackgroundItem(); | |
396 | d_ptr->m_presenter->m_backgroundItem->setDropShadowEnabled(enabled); |
|
396 | d_ptr->m_presenter->m_backgroundItem->setDropShadowEnabled(enabled); | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | /*! |
|
399 | /*! | |
400 | Returns true if the drop shadow effect is enabled for the chart background. |
|
400 | Returns true if the drop shadow effect is enabled for the chart background. | |
401 | */ |
|
401 | */ | |
402 | bool QChart::isBackgroundDropShadowEnabled() const |
|
402 | bool QChart::isBackgroundDropShadowEnabled() const | |
403 | { |
|
403 | { | |
404 | if (!d_ptr->m_presenter->m_backgroundItem) |
|
404 | if (!d_ptr->m_presenter->m_backgroundItem) | |
405 | return false; |
|
405 | return false; | |
406 |
|
406 | |||
407 | return d_ptr->m_presenter->m_backgroundItem->isDropShadowEnabled(); |
|
407 | return d_ptr->m_presenter->m_backgroundItem->isDropShadowEnabled(); | |
408 | } |
|
408 | } | |
409 |
|
409 | |||
410 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
410 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
411 |
|
411 | |||
412 | QChartPrivate::QChartPrivate(): |
|
412 | QChartPrivate::QChartPrivate(): | |
413 | m_legend(0), |
|
413 | m_legend(0), | |
414 | m_dataset(0), |
|
414 | m_dataset(0), | |
415 | m_presenter(0) |
|
415 | m_presenter(0) | |
416 | { |
|
416 | { | |
417 |
|
417 | |||
418 | } |
|
418 | } | |
419 |
|
419 | |||
420 | QChartPrivate::~QChartPrivate() |
|
420 | QChartPrivate::~QChartPrivate() | |
421 | { |
|
421 | { | |
422 |
|
422 | |||
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | void QChartPrivate::createConnections() |
|
425 | void QChartPrivate::createConnections() | |
426 | { |
|
426 | { | |
427 |
|
427 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); | ||
428 |
QObject::connect(m_dataset,SIGNAL(series |
|
428 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
429 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries *)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries *))); |
|
|||
430 | QObject::connect(m_dataset,SIGNAL(axisAdded(QAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAxis*,Domain*))); |
|
429 | QObject::connect(m_dataset,SIGNAL(axisAdded(QAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAxis*,Domain*))); | |
431 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QAxis*)),m_presenter,SLOT(handleAxisRemoved(QAxis*))); |
|
430 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QAxis*)),m_presenter,SLOT(handleAxisRemoved(QAxis*))); | |
432 | } |
|
431 | } | |
433 |
|
432 | |||
434 | #include "moc_qchart.cpp" |
|
433 | #include "moc_qchart.cpp" | |
435 |
|
434 | |||
436 | QTCOMMERCIALCHART_END_NAMESPACE |
|
435 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now