@@ -1,58 +1,58 | |||||
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 "bar_p.h" |
|
21 | #include "bar_p.h" | |
22 | #include <QPainter> |
|
22 | #include <QPainter> | |
23 | #include <QGraphicsSceneEvent> |
|
23 | #include <QGraphicsSceneEvent> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | Bar::Bar(QBarSet *barset, int index, QGraphicsItem *parent) : QGraphicsRectItem(parent), |
|
27 | Bar::Bar(QBarSet *barset, int index, QGraphicsItem *parent) : QGraphicsRectItem(parent), | |
28 | m_index(index), |
|
28 | m_index(index), | |
29 | m_barset(barset) |
|
29 | m_barset(barset) | |
30 | { |
|
30 | { | |
31 | setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); |
|
31 | setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); | |
32 | setAcceptHoverEvents(true); |
|
32 | setAcceptHoverEvents(true); | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
35 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
36 | { |
|
36 | { | |
37 | Q_UNUSED(event) |
|
37 | Q_UNUSED(event) | |
38 | emit clicked(m_barset, m_index); |
|
38 | emit clicked(m_barset, m_index); | |
39 |
|
|
39 | emit clicked(m_index); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
42 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
43 | { |
|
43 | { | |
44 | Q_UNUSED(event) |
|
44 | Q_UNUSED(event) | |
45 | emit hovered(m_barset, true); |
|
45 | emit hovered(m_barset, true); | |
46 |
|
|
46 | emit hovered(true); | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
49 | void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
50 | { |
|
50 | { | |
51 | Q_UNUSED(event) |
|
51 | Q_UNUSED(event) | |
52 | emit hovered(m_barset, false); |
|
52 | emit hovered(m_barset, false); | |
53 |
|
|
53 | emit hovered(false); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | #include "moc_bar_p.cpp" |
|
56 | #include "moc_bar_p.cpp" | |
57 |
|
57 | |||
58 | QTCOMMERCIALCHART_END_NAMESPACE |
|
58 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,420 +1,420 | |||||
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 | #include "chartpresenter_p.h" |
|
20 | #include "chartpresenter_p.h" | |
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "qabstractaxis.h" |
|
23 | #include "qabstractaxis.h" | |
24 | #include "qabstractaxis_p.h" |
|
24 | #include "qabstractaxis_p.h" | |
25 | #include "chartdataset_p.h" |
|
25 | #include "chartdataset_p.h" | |
26 | #include "charttheme_p.h" |
|
26 | #include "charttheme_p.h" | |
27 | #include "chartanimator_p.h" |
|
27 | #include "chartanimator_p.h" | |
28 | #include "chartanimation_p.h" |
|
28 | #include "chartanimation_p.h" | |
29 | #include "qabstractseries_p.h" |
|
29 | #include "qabstractseries_p.h" | |
30 | #include "qareaseries.h" |
|
30 | #include "qareaseries.h" | |
31 | #include "chartaxis_p.h" |
|
31 | #include "chartaxis_p.h" | |
32 | //#include "chartaxisx_p.h" |
|
32 | //#include "chartaxisx_p.h" | |
33 | //#include "chartaxisy_p.h" |
|
33 | //#include "chartaxisy_p.h" | |
34 | #include "areachartitem_p.h" |
|
34 | #include "areachartitem_p.h" | |
35 | #include "chartbackground_p.h" |
|
35 | #include "chartbackground_p.h" | |
36 | #include "chartlayout_p.h" |
|
36 | #include "chartlayout_p.h" | |
37 | #include <QTimer> |
|
37 | #include <QTimer> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
41 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
42 | m_chart(chart), |
|
42 | m_chart(chart), | |
43 | m_animator(0), |
|
43 | m_animator(0), | |
44 | m_dataset(dataset), |
|
44 | m_dataset(dataset), | |
45 | m_chartTheme(0), |
|
45 | m_chartTheme(0), | |
46 | m_options(QChart::NoAnimation), |
|
46 | m_options(QChart::NoAnimation), | |
47 | m_state(ShowState), |
|
47 | m_state(ShowState), | |
48 | m_layout(new ChartLayout(this)), |
|
48 | m_layout(new ChartLayout(this)), | |
49 | m_backgroundItem(0), |
|
49 | m_backgroundItem(0), | |
50 | m_titleItem(0) |
|
50 | m_titleItem(0) | |
51 | { |
|
51 | { | |
52 |
|
52 | |||
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | ChartPresenter::~ChartPresenter() |
|
55 | ChartPresenter::~ChartPresenter() | |
56 | { |
|
56 | { | |
57 | delete m_chartTheme; |
|
57 | delete m_chartTheme; | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void ChartPresenter::setGeometry(const QRectF& rect) |
|
60 | void ChartPresenter::setGeometry(const QRectF& rect) | |
61 | { |
|
61 | { | |
62 |
|
62 | |||
63 | Q_ASSERT(rect.isValid()); |
|
63 | Q_ASSERT(rect.isValid()); | |
64 |
|
64 | |||
65 | if(m_rect!=rect) { |
|
65 | if(m_rect!=rect) { | |
66 | m_rect=rect; |
|
66 | m_rect=rect; | |
67 | emit geometryChanged(m_rect); |
|
67 | emit geometryChanged(m_rect); | |
68 | } |
|
68 | } | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) |
|
71 | void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain) | |
72 | { |
|
72 | { | |
73 | ChartAxis* item = axis->d_ptr->createGraphics(this); |
|
73 | ChartAxis* item = axis->d_ptr->createGraphics(this); | |
74 | item->setDomain(domain); |
|
74 | item->setDomain(domain); | |
75 |
|
75 | |||
76 | if(m_options.testFlag(QChart::GridAxisAnimations)){ |
|
76 | if(m_options.testFlag(QChart::GridAxisAnimations)){ | |
77 | item->setAnimator(m_animator); |
|
77 | item->setAnimator(m_animator); | |
78 | item->setAnimation(new AxisAnimation(item)); |
|
78 | item->setAnimation(new AxisAnimation(item)); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | if(item->axisType()==ChartAxis::X_AXIS){ |
|
81 | if(item->axisType()==ChartAxis::X_AXIS){ | |
82 | m_chartTheme->decorate(axis,true); |
|
82 | m_chartTheme->decorate(axis,true); | |
83 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
83 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
84 | //initialize |
|
84 | //initialize | |
85 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); |
|
85 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); | |
86 |
|
86 | |||
87 | } |
|
87 | } | |
88 | else{ |
|
88 | else{ | |
89 | m_chartTheme->decorate(axis,false); |
|
89 | m_chartTheme->decorate(axis,false); | |
90 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
90 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
91 | //initialize |
|
91 | //initialize | |
92 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); |
|
92 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); |
|
95 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); | |
96 | //initialize |
|
96 | //initialize | |
97 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
97 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
98 | m_axisItems.insert(axis, item); |
|
98 | m_axisItems.insert(axis, item); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis) |
|
101 | void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis) | |
102 | { |
|
102 | { | |
103 | ChartAxis* item = m_axisItems.take(axis); |
|
103 | ChartAxis* item = m_axisItems.take(axis); | |
104 | Q_ASSERT(item); |
|
104 | Q_ASSERT(item); | |
105 | if(m_animator) m_animator->removeAnimation(item); |
|
105 | if(m_animator) m_animator->removeAnimation(item); | |
106 |
|
|
106 | item->deleteLater(); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 |
|
109 | |||
110 | void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain) |
|
110 | void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain) | |
111 | { |
|
111 | { | |
112 | Chart *item = series->d_ptr->createGraphics(this); |
|
112 | Chart *item = series->d_ptr->createGraphics(this); | |
113 | Q_ASSERT(item); |
|
113 | Q_ASSERT(item); | |
114 | item->setDomain(domain); |
|
114 | item->setDomain(domain); | |
115 |
|
115 | |||
116 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); |
|
116 | QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF))); | |
117 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
117 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
118 | //initialize |
|
118 | //initialize | |
119 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
119 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
120 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
120 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
121 | m_chartItems.insert(series,item); |
|
121 | m_chartItems.insert(series,item); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series) |
|
124 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series) | |
125 | { |
|
125 | { | |
126 | Chart* item = m_chartItems.take(series); |
|
126 | Chart* item = m_chartItems.take(series); | |
127 | Q_ASSERT(item); |
|
127 | Q_ASSERT(item); | |
128 | if(m_animator) { |
|
128 | if(m_animator) { | |
129 | //small hack to handle area animations |
|
129 | //small hack to handle area animations | |
130 | if(series->type() == QAbstractSeries::SeriesTypeArea){ |
|
130 | if(series->type() == QAbstractSeries::SeriesTypeArea){ | |
131 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
131 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
132 | AreaChartItem* area = static_cast<AreaChartItem*>(item); |
|
132 | AreaChartItem* area = static_cast<AreaChartItem*>(item); | |
133 | m_animator->removeAnimation(area->upperLineItem()); |
|
133 | m_animator->removeAnimation(area->upperLineItem()); | |
134 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); |
|
134 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); | |
135 | }else |
|
135 | }else | |
136 | m_animator->removeAnimation(item); |
|
136 | m_animator->removeAnimation(item); | |
137 | } |
|
137 | } | |
138 |
|
|
138 | item->deleteLater(); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) |
|
141 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) | |
142 | { |
|
142 | { | |
143 | if(m_chartTheme && m_chartTheme->id() == theme) return; |
|
143 | if(m_chartTheme && m_chartTheme->id() == theme) return; | |
144 | delete m_chartTheme; |
|
144 | delete m_chartTheme; | |
145 | m_chartTheme = ChartTheme::createTheme(theme); |
|
145 | m_chartTheme = ChartTheme::createTheme(theme); | |
146 | m_chartTheme->setForced(force); |
|
146 | m_chartTheme->setForced(force); | |
147 | m_chartTheme->decorate(m_chart); |
|
147 | m_chartTheme->decorate(m_chart); | |
148 | m_chartTheme->decorate(m_chart->legend()); |
|
148 | m_chartTheme->decorate(m_chart->legend()); | |
149 | resetAllElements(); |
|
149 | resetAllElements(); | |
150 |
|
150 | |||
151 | // We do not want "force" to stay on. |
|
151 | // We do not want "force" to stay on. | |
152 | // Bar/pie are calling decorate when adding/removing slices/bars which means |
|
152 | // Bar/pie are calling decorate when adding/removing slices/bars which means | |
153 | // that to preserve users colors "force" must not be on. |
|
153 | // that to preserve users colors "force" must not be on. | |
154 | m_chartTheme->setForced(false); |
|
154 | m_chartTheme->setForced(false); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | QChart::ChartTheme ChartPresenter::theme() |
|
157 | QChart::ChartTheme ChartPresenter::theme() | |
158 | { |
|
158 | { | |
159 | return m_chartTheme->id(); |
|
159 | return m_chartTheme->id(); | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
162 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
163 | { |
|
163 | { | |
164 | if(m_options!=options) { |
|
164 | if(m_options!=options) { | |
165 |
|
165 | |||
166 | m_options=options; |
|
166 | m_options=options; | |
167 |
|
167 | |||
168 | if(m_options!=QChart::NoAnimation && !m_animator) { |
|
168 | if(m_options!=QChart::NoAnimation && !m_animator) { | |
169 | m_animator= new ChartAnimator(this); |
|
169 | m_animator= new ChartAnimator(this); | |
170 | } |
|
170 | } | |
171 | resetAllElements(); |
|
171 | resetAllElements(); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void ChartPresenter::resetAllElements() |
|
176 | void ChartPresenter::resetAllElements() | |
177 | { |
|
177 | { | |
178 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); |
|
178 | QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems); | |
179 | while (i.hasNext()) { |
|
179 | while (i.hasNext()) { | |
180 | i.next(); |
|
180 | i.next(); | |
181 | Domain* domain = i.value()->domain(); |
|
181 | Domain* domain = i.value()->domain(); | |
182 | QAbstractAxis* axis = i.key(); |
|
182 | QAbstractAxis* axis = i.key(); | |
183 | handleAxisRemoved(axis); |
|
183 | handleAxisRemoved(axis); | |
184 | handleAxisAdded(axis,domain); |
|
184 | handleAxisAdded(axis,domain); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | QMapIterator<QAbstractSeries*, Chart*> j(m_chartItems); |
|
187 | QMapIterator<QAbstractSeries*, Chart*> j(m_chartItems); | |
188 | while (j.hasNext()) { |
|
188 | while (j.hasNext()) { | |
189 | j.next(); |
|
189 | j.next(); | |
190 | Domain* domain = j.value()->domain(); |
|
190 | Domain* domain = j.value()->domain(); | |
191 | QAbstractSeries* series = j.key(); |
|
191 | QAbstractSeries* series = j.key(); | |
192 | handleSeriesRemoved(series); |
|
192 | handleSeriesRemoved(series); | |
193 | handleSeriesAdded(series,domain); |
|
193 | handleSeriesAdded(series,domain); | |
194 | } |
|
194 | } | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | void ChartPresenter::zoomIn(qreal factor) |
|
197 | void ChartPresenter::zoomIn(qreal factor) | |
198 | { |
|
198 | { | |
199 | QRectF rect = geometry(); |
|
199 | QRectF rect = geometry(); | |
200 | rect.setWidth(rect.width()/factor); |
|
200 | rect.setWidth(rect.width()/factor); | |
201 | rect.setHeight(rect.height()/factor); |
|
201 | rect.setHeight(rect.height()/factor); | |
202 | rect.moveCenter(geometry().center()); |
|
202 | rect.moveCenter(geometry().center()); | |
203 | zoomIn(rect); |
|
203 | zoomIn(rect); | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
206 | void ChartPresenter::zoomIn(const QRectF& rect) | |
207 | { |
|
207 | { | |
208 | QRectF r = rect.normalized(); |
|
208 | QRectF r = rect.normalized(); | |
209 | r.translate(-geometry().topLeft()); |
|
209 | r.translate(-geometry().topLeft()); | |
210 | if (!r.isValid()) |
|
210 | if (!r.isValid()) | |
211 | return; |
|
211 | return; | |
212 |
|
212 | |||
213 | m_state = ZoomInState; |
|
213 | m_state = ZoomInState; | |
214 | m_statePoint = QPointF(r.center().x()/geometry().width(),r.center().y()/geometry().height()); |
|
214 | m_statePoint = QPointF(r.center().x()/geometry().width(),r.center().y()/geometry().height()); | |
215 | m_dataset->zoomInDomain(r,geometry().size()); |
|
215 | m_dataset->zoomInDomain(r,geometry().size()); | |
216 | m_state = ShowState; |
|
216 | m_state = ShowState; | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | void ChartPresenter::zoomOut(qreal factor) |
|
219 | void ChartPresenter::zoomOut(qreal factor) | |
220 | { |
|
220 | { | |
221 | m_state = ZoomOutState; |
|
221 | m_state = ZoomOutState; | |
222 |
|
222 | |||
223 | QRectF chartRect; |
|
223 | QRectF chartRect; | |
224 | chartRect.setSize(geometry().size()); |
|
224 | chartRect.setSize(geometry().size()); | |
225 |
|
225 | |||
226 | QRectF rect; |
|
226 | QRectF rect; | |
227 | rect.setSize(chartRect.size()/factor); |
|
227 | rect.setSize(chartRect.size()/factor); | |
228 | rect.moveCenter(chartRect.center()); |
|
228 | rect.moveCenter(chartRect.center()); | |
229 | if (!rect.isValid()) |
|
229 | if (!rect.isValid()) | |
230 | return; |
|
230 | return; | |
231 | m_statePoint = QPointF(rect.center().x()/geometry().width(),rect.center().y()/geometry().height()); |
|
231 | m_statePoint = QPointF(rect.center().x()/geometry().width(),rect.center().y()/geometry().height()); | |
232 | m_dataset->zoomOutDomain(rect, chartRect.size()); |
|
232 | m_dataset->zoomOutDomain(rect, chartRect.size()); | |
233 | m_state = ShowState; |
|
233 | m_state = ShowState; | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | void ChartPresenter::scroll(qreal dx,qreal dy) |
|
236 | void ChartPresenter::scroll(qreal dx,qreal dy) | |
237 | { |
|
237 | { | |
238 | if(dx<0) m_state=ScrollLeftState; |
|
238 | if(dx<0) m_state=ScrollLeftState; | |
239 | if(dx>0) m_state=ScrollRightState; |
|
239 | if(dx>0) m_state=ScrollRightState; | |
240 | if(dy<0) m_state=ScrollUpState; |
|
240 | if(dy<0) m_state=ScrollUpState; | |
241 | if(dy>0) m_state=ScrollDownState; |
|
241 | if(dy>0) m_state=ScrollDownState; | |
242 |
|
242 | |||
243 | m_dataset->scrollDomain(dx,dy,geometry().size()); |
|
243 | m_dataset->scrollDomain(dx,dy,geometry().size()); | |
244 | m_state = ShowState; |
|
244 | m_state = ShowState; | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
247 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
248 | { |
|
248 | { | |
249 | return m_options; |
|
249 | return m_options; | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | void ChartPresenter::createBackgroundItem() |
|
252 | void ChartPresenter::createBackgroundItem() | |
253 | { |
|
253 | { | |
254 | if (!m_backgroundItem) { |
|
254 | if (!m_backgroundItem) { | |
255 | m_backgroundItem = new ChartBackground(rootItem()); |
|
255 | m_backgroundItem = new ChartBackground(rootItem()); | |
256 | m_backgroundItem->setPen(Qt::NoPen); |
|
256 | m_backgroundItem->setPen(Qt::NoPen); | |
257 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
257 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
258 | } |
|
258 | } | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | void ChartPresenter::createTitleItem() |
|
261 | void ChartPresenter::createTitleItem() | |
262 | { |
|
262 | { | |
263 | if (!m_titleItem) { |
|
263 | if (!m_titleItem) { | |
264 | m_titleItem = new QGraphicsSimpleTextItem(rootItem()); |
|
264 | m_titleItem = new QGraphicsSimpleTextItem(rootItem()); | |
265 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
265 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
266 | } |
|
266 | } | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 |
|
269 | |||
270 | void ChartPresenter::handleAnimationFinished() |
|
270 | void ChartPresenter::handleAnimationFinished() | |
271 | { |
|
271 | { | |
272 | m_animations.removeAll(qobject_cast<ChartAnimation*>(sender())); |
|
272 | m_animations.removeAll(qobject_cast<ChartAnimation*>(sender())); | |
273 | if(m_animations.empty()) emit animationsFinished(); |
|
273 | if(m_animations.empty()) emit animationsFinished(); | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | void ChartPresenter::startAnimation(ChartAnimation* animation) |
|
276 | void ChartPresenter::startAnimation(ChartAnimation* animation) | |
277 | { |
|
277 | { | |
278 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); |
|
278 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); | |
279 | QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection); |
|
279 | QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection); | |
280 | if(!m_animations.isEmpty()){ |
|
280 | if(!m_animations.isEmpty()){ | |
281 | m_animations.append(animation); |
|
281 | m_animations.append(animation); | |
282 | } |
|
282 | } | |
283 | QTimer::singleShot(0, animation, SLOT(start())); |
|
283 | QTimer::singleShot(0, animation, SLOT(start())); | |
284 | } |
|
284 | } | |
285 |
|
285 | |||
286 | QGraphicsRectItem* ChartPresenter::backgroundItem() |
|
286 | QGraphicsRectItem* ChartPresenter::backgroundItem() | |
287 | { |
|
287 | { | |
288 | return m_backgroundItem; |
|
288 | return m_backgroundItem; | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | void ChartPresenter::setBackgroundBrush(const QBrush& brush) |
|
291 | void ChartPresenter::setBackgroundBrush(const QBrush& brush) | |
292 | { |
|
292 | { | |
293 | createBackgroundItem(); |
|
293 | createBackgroundItem(); | |
294 | m_backgroundItem->setBrush(brush); |
|
294 | m_backgroundItem->setBrush(brush); | |
295 | m_layout->invalidate(); |
|
295 | m_layout->invalidate(); | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
298 | QBrush ChartPresenter::backgroundBrush() const |
|
298 | QBrush ChartPresenter::backgroundBrush() const | |
299 | { |
|
299 | { | |
300 | if (!m_backgroundItem) return QBrush(); |
|
300 | if (!m_backgroundItem) return QBrush(); | |
301 | return m_backgroundItem->brush(); |
|
301 | return m_backgroundItem->brush(); | |
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | void ChartPresenter::setBackgroundPen(const QPen& pen) |
|
304 | void ChartPresenter::setBackgroundPen(const QPen& pen) | |
305 | { |
|
305 | { | |
306 | createBackgroundItem(); |
|
306 | createBackgroundItem(); | |
307 | m_backgroundItem->setPen(pen); |
|
307 | m_backgroundItem->setPen(pen); | |
308 | m_layout->invalidate(); |
|
308 | m_layout->invalidate(); | |
309 | } |
|
309 | } | |
310 |
|
310 | |||
311 | QPen ChartPresenter::backgroundPen() const |
|
311 | QPen ChartPresenter::backgroundPen() const | |
312 | { |
|
312 | { | |
313 | if (!m_backgroundItem) return QPen(); |
|
313 | if (!m_backgroundItem) return QPen(); | |
314 | return m_backgroundItem->pen(); |
|
314 | return m_backgroundItem->pen(); | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | QGraphicsItem* ChartPresenter::titleItem() |
|
317 | QGraphicsItem* ChartPresenter::titleItem() | |
318 | { |
|
318 | { | |
319 | return m_titleItem; |
|
319 | return m_titleItem; | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | void ChartPresenter::setTitle(const QString& title) |
|
322 | void ChartPresenter::setTitle(const QString& title) | |
323 | { |
|
323 | { | |
324 | createTitleItem(); |
|
324 | createTitleItem(); | |
325 | m_titleItem->setText(title); |
|
325 | m_titleItem->setText(title); | |
326 | m_layout->invalidate(); |
|
326 | m_layout->invalidate(); | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | QString ChartPresenter::title() const |
|
329 | QString ChartPresenter::title() const | |
330 | { |
|
330 | { | |
331 | if (!m_titleItem) return QString(); |
|
331 | if (!m_titleItem) return QString(); | |
332 | return m_titleItem->text(); |
|
332 | return m_titleItem->text(); | |
333 | } |
|
333 | } | |
334 |
|
334 | |||
335 | void ChartPresenter::setTitleFont(const QFont& font) |
|
335 | void ChartPresenter::setTitleFont(const QFont& font) | |
336 | { |
|
336 | { | |
337 | createTitleItem(); |
|
337 | createTitleItem(); | |
338 | m_titleItem->setFont(font); |
|
338 | m_titleItem->setFont(font); | |
339 | m_layout->invalidate(); |
|
339 | m_layout->invalidate(); | |
340 | } |
|
340 | } | |
341 |
|
341 | |||
342 | QFont ChartPresenter::titleFont() const |
|
342 | QFont ChartPresenter::titleFont() const | |
343 | { |
|
343 | { | |
344 | if (!m_titleItem) return QFont(); |
|
344 | if (!m_titleItem) return QFont(); | |
345 | return m_titleItem->font(); |
|
345 | return m_titleItem->font(); | |
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | void ChartPresenter::setTitleBrush(const QBrush &brush) |
|
348 | void ChartPresenter::setTitleBrush(const QBrush &brush) | |
349 | { |
|
349 | { | |
350 | createTitleItem(); |
|
350 | createTitleItem(); | |
351 | m_titleItem->setBrush(brush); |
|
351 | m_titleItem->setBrush(brush); | |
352 | m_layout->invalidate(); |
|
352 | m_layout->invalidate(); | |
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | QBrush ChartPresenter::titleBrush() const |
|
355 | QBrush ChartPresenter::titleBrush() const | |
356 | { |
|
356 | { | |
357 | if (!m_titleItem) return QBrush(); |
|
357 | if (!m_titleItem) return QBrush(); | |
358 | return m_titleItem->brush(); |
|
358 | return m_titleItem->brush(); | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | void ChartPresenter::setBackgroundVisible(bool visible) |
|
361 | void ChartPresenter::setBackgroundVisible(bool visible) | |
362 | { |
|
362 | { | |
363 | createBackgroundItem(); |
|
363 | createBackgroundItem(); | |
364 | m_backgroundItem->setVisible(visible); |
|
364 | m_backgroundItem->setVisible(visible); | |
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 |
|
367 | |||
368 | bool ChartPresenter::isBackgroundVisible() const |
|
368 | bool ChartPresenter::isBackgroundVisible() const | |
369 | { |
|
369 | { | |
370 | if (!m_backgroundItem) return false; |
|
370 | if (!m_backgroundItem) return false; | |
371 | return m_backgroundItem->isVisible(); |
|
371 | return m_backgroundItem->isVisible(); | |
372 | } |
|
372 | } | |
373 |
|
373 | |||
374 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) |
|
374 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) | |
375 | { |
|
375 | { | |
376 | createBackgroundItem(); |
|
376 | createBackgroundItem(); | |
377 | m_backgroundItem->setDropShadowEnabled(enabled); |
|
377 | m_backgroundItem->setDropShadowEnabled(enabled); | |
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | bool ChartPresenter::isBackgroundDropShadowEnabled() const |
|
380 | bool ChartPresenter::isBackgroundDropShadowEnabled() const | |
381 | { |
|
381 | { | |
382 | if (!m_backgroundItem) return false; |
|
382 | if (!m_backgroundItem) return false; | |
383 | return m_backgroundItem->isDropShadowEnabled(); |
|
383 | return m_backgroundItem->isDropShadowEnabled(); | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 |
|
386 | |||
387 | QGraphicsLayout* ChartPresenter::layout() |
|
387 | QGraphicsLayout* ChartPresenter::layout() | |
388 | { |
|
388 | { | |
389 | return m_layout; |
|
389 | return m_layout; | |
390 | } |
|
390 | } | |
391 |
|
391 | |||
392 | void ChartPresenter::setMarginsMinimum(const QRectF& margins) |
|
392 | void ChartPresenter::setMarginsMinimum(const QRectF& margins) | |
393 | { |
|
393 | { | |
394 | Q_UNUSED(margins); |
|
394 | Q_UNUSED(margins); | |
395 | // m_layout->setMarginsMinimum(margins); |
|
395 | // m_layout->setMarginsMinimum(margins); | |
396 | } |
|
396 | } | |
397 |
|
397 | |||
398 | QRectF ChartPresenter::margins() const |
|
398 | QRectF ChartPresenter::margins() const | |
399 | { |
|
399 | { | |
400 | return QRectF();//m_layout->margins(); |
|
400 | return QRectF();//m_layout->margins(); | |
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | QLegend* ChartPresenter::legend() |
|
403 | QLegend* ChartPresenter::legend() | |
404 | { |
|
404 | { | |
405 | return m_chart->legend(); |
|
405 | return m_chart->legend(); | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | QList<ChartAxis*> ChartPresenter::axisItems() const |
|
408 | QList<ChartAxis*> ChartPresenter::axisItems() const | |
409 | { |
|
409 | { | |
410 | return m_axisItems.values(); |
|
410 | return m_axisItems.values(); | |
411 | } |
|
411 | } | |
412 |
|
412 | |||
413 | void ChartPresenter::setVisible(bool visible) |
|
413 | void ChartPresenter::setVisible(bool visible) | |
414 | { |
|
414 | { | |
415 | m_chart->setVisible(visible); |
|
415 | m_chart->setVisible(visible); | |
416 | } |
|
416 | } | |
417 |
|
417 | |||
418 | #include "moc_chartpresenter_p.cpp" |
|
418 | #include "moc_chartpresenter_p.cpp" | |
419 |
|
419 | |||
420 | QTCOMMERCIALCHART_END_NAMESPACE |
|
420 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now