@@ -1,465 +1,482 | |||||
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 "chartdataset_p.h" |
|
21 | #include "chartdataset_p.h" | |
22 | #include "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 | #include "qchart_p.h" |
|
24 | #include "qchart_p.h" | |
25 | #include "qvalueaxis.h" |
|
25 | #include "qvalueaxis.h" | |
26 | #include "qbarcategoryaxis.h" |
|
26 | #include "qbarcategoryaxis.h" | |
27 | #include "qvalueaxis_p.h" |
|
27 | #include "qvalueaxis_p.h" | |
28 | #include "qcategoryaxis.h" |
|
28 | #include "qcategoryaxis.h" | |
29 | #include "qabstractseries_p.h" |
|
29 | #include "qabstractseries_p.h" | |
30 | #include "qabstractbarseries.h" |
|
30 | #include "qabstractbarseries.h" | |
31 | #include "qstackedbarseries.h" |
|
31 | #include "qstackedbarseries.h" | |
32 | #include "qpercentbarseries.h" |
|
32 | #include "qpercentbarseries.h" | |
33 | #include "qpieseries.h" |
|
33 | #include "qpieseries.h" | |
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "xydomain_p.h" |
|
35 | #include "xydomain_p.h" | |
36 | #include "xlogydomain_p.h" |
|
36 | #include "xlogydomain_p.h" | |
37 | #include "logxydomain_p.h" |
|
37 | #include "logxydomain_p.h" | |
38 | #include "logxlogydomain_p.h" |
|
38 | #include "logxlogydomain_p.h" | |
39 |
|
39 | |||
40 | #ifndef QT_ON_ARM |
|
40 | #ifndef QT_ON_ARM | |
41 | #include "qdatetimeaxis.h" |
|
41 | #include "qdatetimeaxis.h" | |
42 | #endif |
|
42 | #endif | |
43 |
|
43 | |||
44 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
44 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
45 |
|
45 | |||
46 | ChartDataSet::ChartDataSet(QChart *chart) |
|
46 | ChartDataSet::ChartDataSet(QChart *chart) | |
47 | : QObject(chart), |
|
47 | : QObject(chart), | |
48 | m_chart(chart) |
|
48 | m_chart(chart) | |
49 | { |
|
49 | { | |
50 |
|
50 | |||
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | ChartDataSet::~ChartDataSet() |
|
53 | ChartDataSet::~ChartDataSet() | |
54 | { |
|
54 | { | |
55 | deleteAllSeries(); |
|
55 | deleteAllSeries(); | |
56 | deleteAllAxes(); |
|
56 | deleteAllAxes(); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | /* |
|
59 | /* | |
60 | * This method adds series to chartdataset, series ownership is taken from caller. |
|
60 | * This method adds series to chartdataset, series ownership is taken from caller. | |
61 | */ |
|
61 | */ | |
62 | void ChartDataSet::addSeries(QAbstractSeries *series) |
|
62 | void ChartDataSet::addSeries(QAbstractSeries *series) | |
63 | { |
|
63 | { | |
64 | if (m_seriesList.contains(series)) { |
|
64 | if (m_seriesList.contains(series)) { | |
65 | qWarning() << QObject::tr("Can not add series. Series already on the chart."); |
|
65 | qWarning() << QObject::tr("Can not add series. Series already on the chart."); | |
66 | return; |
|
66 | return; | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | series->d_ptr->initializeDomain(); |
|
69 | series->d_ptr->initializeDomain(); | |
70 | m_seriesList.append(series); |
|
70 | m_seriesList.append(series); | |
71 |
|
71 | |||
72 | series->setParent(this); // take ownership |
|
72 | series->setParent(this); // take ownership | |
73 | series->d_ptr->m_chart = m_chart; |
|
73 | series->d_ptr->m_chart = m_chart; | |
74 |
|
74 | |||
75 | emit seriesAdded(series); |
|
75 | emit seriesAdded(series); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | /* |
|
78 | /* | |
79 | * This method adds axis to chartdataset, axis ownership is taken from caller. |
|
79 | * This method adds axis to chartdataset, axis ownership is taken from caller. | |
80 | */ |
|
80 | */ | |
81 | void ChartDataSet::addAxis(QAbstractAxis *axis,Qt::Alignment aligment) |
|
81 | void ChartDataSet::addAxis(QAbstractAxis *axis,Qt::Alignment aligment) | |
82 | { |
|
82 | { | |
83 | if (m_axisList.contains(axis)) { |
|
83 | if (m_axisList.contains(axis)) { | |
84 | qWarning() << QObject::tr("Can not add axis. Axis already on the chart."); |
|
84 | qWarning() << QObject::tr("Can not add axis. Axis already on the chart."); | |
85 | return; |
|
85 | return; | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | axis->d_ptr->setAlignment(aligment); |
|
88 | axis->d_ptr->setAlignment(aligment); | |
89 |
|
89 | |||
90 | if(!axis->alignment()) { |
|
90 | if(!axis->alignment()) { | |
91 | qWarning()<< QObject::tr("No alignment specified !"); |
|
91 | qWarning()<< QObject::tr("No alignment specified !"); | |
92 | return; |
|
92 | return; | |
93 | }; |
|
93 | }; | |
94 |
|
94 | |||
95 | QSharedPointer<AbstractDomain> domain(new XYDomain()); |
|
95 | QSharedPointer<AbstractDomain> domain(new XYDomain()); | |
96 | axis->d_ptr->initializeDomain(domain.data()); |
|
96 | axis->d_ptr->initializeDomain(domain.data()); | |
97 |
|
97 | |||
98 | axis->setParent(this); |
|
98 | axis->setParent(this); | |
99 | axis->d_ptr->m_chart = m_chart; |
|
99 | axis->d_ptr->m_chart = m_chart; | |
100 | m_axisList.append(axis); |
|
100 | m_axisList.append(axis); | |
101 |
|
101 | |||
102 | emit axisAdded(axis); |
|
102 | emit axisAdded(axis); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | /* |
|
105 | /* | |
106 | * This method removes series form chartdataset, series ownership is passed back to caller. |
|
106 | * This method removes series form chartdataset, series ownership is passed back to caller. | |
107 | */ |
|
107 | */ | |
108 | void ChartDataSet::removeSeries(QAbstractSeries *series) |
|
108 | void ChartDataSet::removeSeries(QAbstractSeries *series) | |
109 | { |
|
109 | { | |
110 |
|
110 | |||
111 | if (! m_seriesList.contains(series)) { |
|
111 | if (! m_seriesList.contains(series)) { | |
112 | qWarning() << QObject::tr("Can not remove series. Series not found on the chart."); |
|
112 | qWarning() << QObject::tr("Can not remove series. Series not found on the chart."); | |
113 | return; |
|
113 | return; | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | emit seriesRemoved(series); |
|
116 | emit seriesRemoved(series); | |
117 | m_seriesList.removeAll(series); |
|
117 | m_seriesList.removeAll(series); | |
118 |
|
118 | |||
119 | series->setParent(0); |
|
119 | series->setParent(0); | |
120 | series->d_ptr->m_chart = 0; |
|
120 | series->d_ptr->m_chart = 0; | |
121 | series->d_ptr->m_domain.reset(0); |
|
121 | series->d_ptr->m_domain.reset(0); | |
122 |
|
122 | |||
123 | QList<QAbstractAxis*> axes = series->d_ptr->m_axes; |
|
123 | QList<QAbstractAxis*> axes = series->d_ptr->m_axes; | |
124 |
|
124 | |||
125 | foreach(QAbstractAxis* axis, axes) { |
|
125 | foreach(QAbstractAxis* axis, axes) { | |
126 | axis->d_ptr->m_series.removeAll(series); |
|
126 | axis->d_ptr->m_series.removeAll(series); | |
127 | series->d_ptr->m_axes.removeAll(axis); |
|
127 | series->d_ptr->m_axes.removeAll(axis); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | /* |
|
132 | /* | |
133 | * This method removes axis form chartdataset, series ownership is passed back to caller. |
|
133 | * This method removes axis form chartdataset, series ownership is passed back to caller. | |
134 | */ |
|
134 | */ | |
135 | void ChartDataSet::removeAxis(QAbstractAxis *axis) |
|
135 | void ChartDataSet::removeAxis(QAbstractAxis *axis) | |
136 | { |
|
136 | { | |
137 | if (! m_axisList.contains(axis)) { |
|
137 | if (! m_axisList.contains(axis)) { | |
138 | qWarning() << QObject::tr("Can not remove axis. Axis not found on the chart."); |
|
138 | qWarning() << QObject::tr("Can not remove axis. Axis not found on the chart."); | |
139 | return; |
|
139 | return; | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | emit axisRemoved(axis); |
|
142 | emit axisRemoved(axis); | |
143 | m_axisList.removeAll(axis); |
|
143 | m_axisList.removeAll(axis); | |
144 |
|
144 | |||
145 | axis->setParent(0); |
|
145 | axis->setParent(0); | |
146 | axis->d_ptr->m_chart = 0; |
|
146 | axis->d_ptr->m_chart = 0; | |
147 |
|
147 | |||
148 | QList<QAbstractSeries*> series = axis->d_ptr->m_series; |
|
148 | QList<QAbstractSeries*> series = axis->d_ptr->m_series; | |
149 |
|
149 | |||
150 | foreach(QAbstractSeries* s, series) { |
|
150 | foreach(QAbstractSeries* s, series) { | |
151 | s->d_ptr->m_axes.removeAll(axis); |
|
151 | s->d_ptr->m_axes.removeAll(axis); | |
152 | axis->d_ptr->m_series.removeAll(s); |
|
152 | axis->d_ptr->m_series.removeAll(s); | |
153 | } |
|
153 | } | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | /* |
|
156 | /* | |
157 | * This method attaches axis to series, return true if success. |
|
157 | * This method attaches axis to series, return true if success. | |
158 | */ |
|
158 | */ | |
159 | bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis) |
|
159 | bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis) | |
160 | { |
|
160 | { | |
161 | Q_ASSERT(series); |
|
161 | Q_ASSERT(series); | |
162 | Q_ASSERT(axis); |
|
162 | Q_ASSERT(axis); | |
163 |
|
163 | |||
164 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; |
|
164 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; | |
165 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; |
|
165 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; | |
166 |
|
166 | |||
167 | if (!m_seriesList.contains(series)) { |
|
167 | if (!m_seriesList.contains(series)) { | |
168 | qWarning() << QObject::tr("Can not find series on the chart."); |
|
168 | qWarning() << QObject::tr("Can not find series on the chart."); | |
169 | return false; |
|
169 | return false; | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | if (axis && !m_axisList.contains(axis)) { |
|
172 | if (axis && !m_axisList.contains(axis)) { | |
173 | qWarning() << QObject::tr("Can not find axis on the chart."); |
|
173 | qWarning() << QObject::tr("Can not find axis on the chart."); | |
174 | return false; |
|
174 | return false; | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | if (attachedAxisList.contains(axis)) { |
|
177 | if (attachedAxisList.contains(axis)) { | |
178 | qWarning() << QObject::tr("Axis already attached to series."); |
|
178 | qWarning() << QObject::tr("Axis already attached to series."); | |
179 | return false; |
|
179 | return false; | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | if (attachedSeriesList.contains(series)) { |
|
182 | if (attachedSeriesList.contains(series)) { | |
183 | qWarning() << QObject::tr("Axis already attached to series."); |
|
183 | qWarning() << QObject::tr("Axis already attached to series."); | |
184 | return false; |
|
184 | return false; | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | AbstractDomain* domain = series->d_ptr->domain(); |
|
187 | AbstractDomain* domain = series->d_ptr->domain(); | |
188 | AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis); |
|
188 | AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis); | |
189 |
|
189 | |||
190 | if(type == AbstractDomain::UndefinedDomain) return false; |
|
190 | if(type == AbstractDomain::UndefinedDomain) return false; | |
191 |
|
191 | |||
192 |
|
||||
193 | if(domain->type()!=type){ |
|
192 | if(domain->type()!=type){ | |
194 | domain = createDomain(type); |
|
193 | domain = createDomain(type); | |
195 | } |
|
194 | } | |
196 |
|
195 | |||
197 | if(!domain) return false; |
|
196 | if(!domain) return false; | |
198 |
|
197 | |||
199 | if(!domain->attachAxis(axis)) return false; |
|
198 | if(!domain->attachAxis(axis)) return false; | |
200 |
|
199 | |||
201 | series->d_ptr->m_axes<<axis; |
|
200 | series->d_ptr->m_axes<<axis; | |
202 | axis->d_ptr->m_series<<series; |
|
201 | axis->d_ptr->m_series<<series; | |
203 |
|
202 | |||
|
203 | if(domain!=series->d_ptr->domain()){ | |||
204 | series->d_ptr->setDomain(domain); |
|
204 | series->d_ptr->setDomain(domain); | |
205 | series->d_ptr->initializeDomain(); |
|
205 | series->d_ptr->initializeDomain(); | |
|
206 | } | |||
206 | series->d_ptr->initializeAxes(); |
|
207 | series->d_ptr->initializeAxes(); | |
207 | axis->d_ptr->initializeDomain(domain); |
|
208 | axis->d_ptr->initializeDomain(domain); | |
208 |
|
209 | |||
209 | return true; |
|
210 | return true; | |
210 | } |
|
211 | } | |
211 |
|
212 | |||
212 | /* |
|
213 | /* | |
213 | * This method detaches axis to series, return true if success. |
|
214 | * This method detaches axis to series, return true if success. | |
214 | */ |
|
215 | */ | |
215 | bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis) |
|
216 | bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis) | |
216 | { |
|
217 | { | |
217 | Q_ASSERT(series); |
|
218 | Q_ASSERT(series); | |
218 | Q_ASSERT(axis); |
|
219 | Q_ASSERT(axis); | |
219 |
|
220 | |||
220 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; |
|
221 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; | |
221 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; |
|
222 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; | |
222 | AbstractDomain* domain = series->d_ptr->domain(); |
|
223 | AbstractDomain* domain = series->d_ptr->domain(); | |
223 |
|
224 | |||
224 | if (!m_seriesList.contains(series)) { |
|
225 | if (!m_seriesList.contains(series)) { | |
225 | qWarning() << QObject::tr("Can not find series on the chart."); |
|
226 | qWarning() << QObject::tr("Can not find series on the chart."); | |
226 | return false; |
|
227 | return false; | |
227 | } |
|
228 | } | |
228 |
|
229 | |||
229 | if (axis && !m_axisList.contains(axis)) { |
|
230 | if (axis && !m_axisList.contains(axis)) { | |
230 | qWarning() << QObject::tr("Can not find axis on the chart."); |
|
231 | qWarning() << QObject::tr("Can not find axis on the chart."); | |
231 | return false; |
|
232 | return false; | |
232 | } |
|
233 | } | |
233 |
|
234 | |||
234 | if (!attachedAxisList.contains(axis)) { |
|
235 | if (!attachedAxisList.contains(axis)) { | |
235 | qWarning() << QObject::tr("Axis not attached to series."); |
|
236 | qWarning() << QObject::tr("Axis not attached to series."); | |
236 | return false; |
|
237 | return false; | |
237 | } |
|
238 | } | |
238 |
|
239 | |||
239 | Q_ASSERT(axis->d_ptr->m_series.contains(series)); |
|
240 | Q_ASSERT(axis->d_ptr->m_series.contains(series)); | |
240 |
|
241 | |||
241 | domain->detachAxis(axis); |
|
242 | domain->detachAxis(axis); | |
242 | series->d_ptr->m_axes.removeAll(axis); |
|
243 | series->d_ptr->m_axes.removeAll(axis); | |
243 | axis->d_ptr->m_series.removeAll(series); |
|
244 | axis->d_ptr->m_series.removeAll(series); | |
244 |
|
245 | |||
245 | return true; |
|
246 | return true; | |
246 | } |
|
247 | } | |
247 |
|
248 | |||
248 | void ChartDataSet::createDefaultAxes() |
|
249 | void ChartDataSet::createDefaultAxes() | |
249 | { |
|
250 | { | |
250 | if (m_seriesList.isEmpty()) |
|
251 | if (m_seriesList.isEmpty()) | |
251 | return; |
|
252 | return; | |
252 |
|
253 | |||
253 | QAbstractAxis::AxisTypes typeX(0); |
|
254 | QAbstractAxis::AxisTypes typeX(0); | |
254 | QAbstractAxis::AxisTypes typeY(0); |
|
255 | QAbstractAxis::AxisTypes typeY(0); | |
255 |
|
256 | |||
256 | // Remove possibly existing axes |
|
257 | // Remove possibly existing axes | |
257 | deleteAllAxes(); |
|
258 | deleteAllAxes(); | |
258 |
|
259 | |||
259 | Q_ASSERT(m_axisList.isEmpty()); |
|
260 | Q_ASSERT(m_axisList.isEmpty()); | |
260 |
|
261 | |||
261 | // Select the required axis x and axis y types based on the types of the current series |
|
262 | // Select the required axis x and axis y types based on the types of the current series | |
262 | foreach(QAbstractSeries* s, m_seriesList) { |
|
263 | foreach(QAbstractSeries* s, m_seriesList) { | |
263 | typeX |= s->d_ptr->defaultAxisType(Qt::Horizontal); |
|
264 | typeX |= s->d_ptr->defaultAxisType(Qt::Horizontal); | |
264 | typeY |= s->d_ptr->defaultAxisType(Qt::Vertical); |
|
265 | typeY |= s->d_ptr->defaultAxisType(Qt::Vertical); | |
265 | } |
|
266 | } | |
266 |
|
267 | |||
267 | // Create the axes of the types selected |
|
268 | // Create the axes of the types selected | |
268 | createAxes(typeX, Qt::Horizontal); |
|
269 | createAxes(typeX, Qt::Horizontal); | |
269 | createAxes(typeY, Qt::Vertical); |
|
270 | createAxes(typeY, Qt::Vertical); | |
270 |
|
271 | |||
271 | } |
|
272 | } | |
272 |
|
273 | |||
273 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation) |
|
274 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation) | |
274 | { |
|
275 | { | |
275 | QAbstractAxis *axis = 0; |
|
276 | QAbstractAxis *axis = 0; | |
276 | //decide what axis should be created |
|
277 | //decide what axis should be created | |
277 |
|
278 | |||
278 | switch (type) { |
|
279 | switch (type) { | |
279 | case QAbstractAxis::AxisTypeValue: |
|
280 | case QAbstractAxis::AxisTypeValue: | |
280 | axis = new QValueAxis(this); |
|
281 | axis = new QValueAxis(this); | |
281 | break; |
|
282 | break; | |
282 | case QAbstractAxis::AxisTypeBarCategory: |
|
283 | case QAbstractAxis::AxisTypeBarCategory: | |
283 | axis = new QBarCategoryAxis(this); |
|
284 | axis = new QBarCategoryAxis(this); | |
284 | break; |
|
285 | break; | |
285 | case QAbstractAxis::AxisTypeCategory: |
|
286 | case QAbstractAxis::AxisTypeCategory: | |
286 | axis = new QCategoryAxis(this); |
|
287 | axis = new QCategoryAxis(this); | |
287 | break; |
|
288 | break; | |
288 | #ifndef Q_WS_QWS |
|
289 | #ifndef Q_WS_QWS | |
289 | case QAbstractAxis::AxisTypeDateTime: |
|
290 | case QAbstractAxis::AxisTypeDateTime: | |
290 | axis = new QDateTimeAxis(this); |
|
291 | axis = new QDateTimeAxis(this); | |
291 | break; |
|
292 | break; | |
292 | #endif |
|
293 | #endif | |
293 | default: |
|
294 | default: | |
294 | axis = 0; |
|
295 | axis = 0; | |
295 | break; |
|
296 | break; | |
296 | } |
|
297 | } | |
297 |
|
298 | |||
298 | if (axis) { |
|
299 | if (axis) { | |
299 | //create one axis for all |
|
300 | //create one axis for all | |
300 |
|
301 | |||
301 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); |
|
302 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); | |
302 |
|
303 | |||
303 | foreach(QAbstractSeries *s, m_seriesList) { |
|
304 | foreach(QAbstractSeries *s, m_seriesList) { | |
304 | attachAxis(s,axis); |
|
305 | attachAxis(s,axis); | |
305 | } |
|
306 | } | |
306 |
|
307 | |||
307 | } |
|
308 | } | |
308 | else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { |
|
309 | else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { | |
309 | //create separate axis |
|
310 | //create separate axis | |
310 | foreach(QAbstractSeries *s, m_seriesList) { |
|
311 | foreach(QAbstractSeries *s, m_seriesList) { | |
311 | QAbstractAxis *axis = s->d_ptr->createDefaultAxis(orientation); |
|
312 | QAbstractAxis *axis = s->d_ptr->createDefaultAxis(orientation); | |
312 | if(axis) { |
|
313 | if(axis) { | |
313 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); |
|
314 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); | |
314 | attachAxis(s,axis); |
|
315 | attachAxis(s,axis); | |
315 | } |
|
316 | } | |
316 | } |
|
317 | } | |
317 | } |
|
318 | } | |
318 | } |
|
319 | } | |
319 |
|
320 | |||
320 | void ChartDataSet::deleteAllSeries() |
|
321 | void ChartDataSet::deleteAllSeries() | |
321 | { |
|
322 | { | |
322 | foreach (QAbstractSeries *s , m_seriesList){ |
|
323 | foreach (QAbstractSeries *s , m_seriesList){ | |
323 | removeSeries(s); |
|
324 | removeSeries(s); | |
324 | delete s; |
|
325 | delete s; | |
325 | } |
|
326 | } | |
326 | Q_ASSERT(m_seriesList.count() == 0); |
|
327 | Q_ASSERT(m_seriesList.count() == 0); | |
327 | } |
|
328 | } | |
328 |
|
329 | |||
329 | void ChartDataSet::deleteAllAxes() |
|
330 | void ChartDataSet::deleteAllAxes() | |
330 | { |
|
331 | { | |
331 | foreach (QAbstractAxis *a , m_axisList){ |
|
332 | foreach (QAbstractAxis *a , m_axisList){ | |
332 | removeAxis(a); |
|
333 | removeAxis(a); | |
333 | delete a; |
|
334 | delete a; | |
334 | } |
|
335 | } | |
335 | Q_ASSERT(m_axisList.count() == 0); |
|
336 | Q_ASSERT(m_axisList.count() == 0); | |
336 | } |
|
337 | } | |
337 |
|
338 | |||
338 | void ChartDataSet::zoomInDomain(const QRectF &rect) |
|
339 | void ChartDataSet::zoomInDomain(const QRectF &rect) | |
339 | { |
|
340 | { | |
340 | QList<AbstractDomain*> domains; |
|
341 | QList<AbstractDomain*> domains; | |
341 | foreach(QAbstractSeries *s, m_seriesList) { |
|
342 | foreach(QAbstractSeries *s, m_seriesList) { | |
342 | AbstractDomain* domain = s->d_ptr->domain(); |
|
343 | AbstractDomain* domain = s->d_ptr->domain(); | |
343 | s->d_ptr->m_domain->blockAxisSignals(true); |
|
344 | s->d_ptr->m_domain->blockAxisSignals(true); | |
344 | domains<<domain; |
|
345 | domains<<domain; | |
345 | } |
|
346 | } | |
346 |
|
347 | |||
347 | foreach(AbstractDomain *domain, domains) |
|
348 | foreach(AbstractDomain *domain, domains) | |
348 | domain->zoomIn(rect); |
|
349 | domain->zoomIn(rect); | |
349 |
|
350 | |||
350 | foreach(AbstractDomain *domain, domains) |
|
351 | foreach(AbstractDomain *domain, domains) | |
351 | domain->blockAxisSignals(false); |
|
352 | domain->blockAxisSignals(false); | |
352 | } |
|
353 | } | |
353 |
|
354 | |||
354 | void ChartDataSet::zoomOutDomain(const QRectF &rect) |
|
355 | void ChartDataSet::zoomOutDomain(const QRectF &rect) | |
355 | { |
|
356 | { | |
356 | QList<AbstractDomain*> domains; |
|
357 | QList<AbstractDomain*> domains; | |
357 | foreach(QAbstractSeries *s, m_seriesList) { |
|
358 | foreach(QAbstractSeries *s, m_seriesList) { | |
358 | AbstractDomain* domain = s->d_ptr->domain(); |
|
359 | AbstractDomain* domain = s->d_ptr->domain(); | |
359 | s->d_ptr->m_domain->blockAxisSignals(true); |
|
360 | s->d_ptr->m_domain->blockAxisSignals(true); | |
360 | domains<<domain; |
|
361 | domains<<domain; | |
361 | } |
|
362 | } | |
362 |
|
363 | |||
363 | foreach(AbstractDomain *domain, domains) |
|
364 | foreach(AbstractDomain *domain, domains) | |
364 | domain->zoomOut(rect); |
|
365 | domain->zoomOut(rect); | |
365 |
|
366 | |||
366 | foreach(AbstractDomain *domain, domains) |
|
367 | foreach(AbstractDomain *domain, domains) | |
367 | domain->blockAxisSignals(false); |
|
368 | domain->blockAxisSignals(false); | |
368 | } |
|
369 | } | |
369 |
|
370 | |||
370 | void ChartDataSet::scrollDomain(qreal dx, qreal dy) |
|
371 | void ChartDataSet::scrollDomain(qreal dx, qreal dy) | |
371 | { |
|
372 | { | |
372 | QList<AbstractDomain*> domains; |
|
373 | QList<AbstractDomain*> domains; | |
373 | foreach(QAbstractSeries *s, m_seriesList) { |
|
374 | foreach(QAbstractSeries *s, m_seriesList) { | |
374 | AbstractDomain* domain = s->d_ptr->m_domain.data(); |
|
375 | AbstractDomain* domain = s->d_ptr->m_domain.data(); | |
375 | if(domains.contains(domain)) continue; |
|
376 | if(domains.contains(domain)) continue; | |
376 | s->d_ptr->m_domain->blockAxisSignals(true); |
|
377 | s->d_ptr->m_domain->blockAxisSignals(true); | |
377 | domains<<domain; |
|
378 | domains<<domain; | |
378 | } |
|
379 | } | |
379 |
|
380 | |||
380 | foreach(AbstractDomain *domain, domains) |
|
381 | foreach(AbstractDomain *domain, domains) | |
381 | domain->move(dx, dy); |
|
382 | domain->move(dx, dy); | |
382 |
|
383 | |||
383 | foreach(AbstractDomain *domain, domains) |
|
384 | foreach(AbstractDomain *domain, domains) | |
384 | domain->blockAxisSignals(false); |
|
385 | domain->blockAxisSignals(false); | |
385 | } |
|
386 | } | |
386 |
|
387 | |||
387 | QList<QAbstractAxis*> ChartDataSet::axes() const |
|
388 | QList<QAbstractAxis*> ChartDataSet::axes() const | |
388 | { |
|
389 | { | |
389 | return m_axisList; |
|
390 | return m_axisList; | |
390 | } |
|
391 | } | |
391 |
|
392 | |||
392 | QList<QAbstractSeries *> ChartDataSet::series() const |
|
393 | QList<QAbstractSeries *> ChartDataSet::series() const | |
393 | { |
|
394 | { | |
394 | return m_seriesList; |
|
395 | return m_seriesList; | |
395 | } |
|
396 | } | |
396 |
|
397 | |||
397 | AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis*> axes) |
|
398 | AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis*> axes) | |
398 | { |
|
399 | { | |
399 | enum Type { |
|
400 | enum Type { | |
|
401 | Undefined = 0, | |||
400 | LogType = 0x1, |
|
402 | LogType = 0x1, | |
401 | ValueType = 0x2 |
|
403 | ValueType = 0x2 | |
402 | }; |
|
404 | }; | |
403 |
|
405 | |||
404 |
int horizontal( |
|
406 | int horizontal(Undefined); | |
405 |
int vertical( |
|
407 | int vertical(Undefined); | |
406 |
|
408 | |||
407 | foreach(QAbstractAxis* axis, axes) |
|
409 | foreach(QAbstractAxis* axis, axes) | |
408 | { |
|
410 | { | |
409 | switch(axis->type()) { |
|
411 | switch(axis->type()) { | |
410 | case QAbstractAxis::AxisTypeLogValue: |
|
412 | case QAbstractAxis::AxisTypeLogValue: | |
411 | axis->orientation()==Qt::Horizontal?horizontal:vertical|=LogType; |
|
413 | ||
|
414 | if(axis->orientation()==Qt::Horizontal) { | |||
|
415 | horizontal|=LogType; | |||
|
416 | } | |||
|
417 | if(axis->orientation()==Qt::Vertical) { | |||
|
418 | vertical|=LogType; | |||
|
419 | } | |||
|
420 | ||||
412 | break; |
|
421 | break; | |
413 | case QAbstractAxis::AxisTypeValue: |
|
422 | case QAbstractAxis::AxisTypeValue: | |
414 | case QAbstractAxis::AxisTypeBarCategory: |
|
423 | case QAbstractAxis::AxisTypeBarCategory: | |
415 | case QAbstractAxis::AxisTypeCategory: |
|
424 | case QAbstractAxis::AxisTypeCategory: | |
416 | case QAbstractAxis::AxisTypeDateTime: |
|
425 | case QAbstractAxis::AxisTypeDateTime: | |
417 |
|
|
426 | if(axis->orientation()==Qt::Horizontal) { | |
|
427 | horizontal|=ValueType; | |||
|
428 | } | |||
|
429 | if(axis->orientation()==Qt::Vertical) { | |||
|
430 | vertical|=ValueType; | |||
|
431 | } | |||
418 | break; |
|
432 | break; | |
419 | default: |
|
433 | default: | |
420 | qWarning()<<"Undefined type"; |
|
434 | qWarning()<<"Undefined type"; | |
421 | break; |
|
435 | break; | |
422 | } |
|
436 | } | |
423 | } |
|
437 | } | |
424 |
|
438 | |||
|
439 | if(vertical==Undefined) vertical=ValueType; | |||
|
440 | if(horizontal==Undefined) horizontal=ValueType; | |||
|
441 | ||||
425 | if(vertical==ValueType && horizontal== ValueType) { |
|
442 | if(vertical==ValueType && horizontal== ValueType) { | |
426 | return AbstractDomain::XYDomain; |
|
443 | return AbstractDomain::XYDomain; | |
427 | } |
|
444 | } | |
428 |
|
445 | |||
429 | if(vertical==LogType && horizontal== ValueType) { |
|
446 | if(vertical==LogType && horizontal== ValueType) { | |
430 | return AbstractDomain::XLogYDomain; |
|
447 | return AbstractDomain::XLogYDomain; | |
431 | } |
|
448 | } | |
432 |
|
449 | |||
433 | if(vertical==ValueType && horizontal== LogType) { |
|
450 | if(vertical==ValueType && horizontal== LogType) { | |
434 | return AbstractDomain::LogXYDomain; |
|
451 | return AbstractDomain::LogXYDomain; | |
435 | } |
|
452 | } | |
436 |
|
453 | |||
437 | if(vertical==LogType && horizontal== LogType) { |
|
454 | if(vertical==LogType && horizontal== LogType) { | |
438 | return AbstractDomain::LogXLogYDomain; |
|
455 | return AbstractDomain::LogXLogYDomain; | |
439 | } |
|
456 | } | |
440 |
|
457 | |||
441 | return AbstractDomain::UndefinedDomain; |
|
458 | return AbstractDomain::UndefinedDomain; | |
442 | } |
|
459 | } | |
443 |
|
460 | |||
444 |
|
461 | |||
445 | //refactor create factory |
|
462 | //refactor create factory | |
446 | AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type) |
|
463 | AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type) | |
447 | { |
|
464 | { | |
448 | switch(type) |
|
465 | switch(type) | |
449 | { |
|
466 | { | |
450 | case AbstractDomain::LogXLogYDomain: |
|
467 | case AbstractDomain::LogXLogYDomain: | |
451 | return new LogXLogYDomain(); |
|
468 | return new LogXLogYDomain(); | |
452 | case AbstractDomain::XYDomain: |
|
469 | case AbstractDomain::XYDomain: | |
453 | return new XYDomain(); |
|
470 | return new XYDomain(); | |
454 | case AbstractDomain::XLogYDomain: |
|
471 | case AbstractDomain::XLogYDomain: | |
455 | return new XLogYDomain(); |
|
472 | return new XLogYDomain(); | |
456 | case AbstractDomain::LogXYDomain: |
|
473 | case AbstractDomain::LogXYDomain: | |
457 | return new LogXYDomain(); |
|
474 | return new LogXYDomain(); | |
458 | default: |
|
475 | default: | |
459 | return 0; |
|
476 | return 0; | |
460 | } |
|
477 | } | |
461 | } |
|
478 | } | |
462 |
|
479 | |||
463 | #include "moc_chartdataset_p.cpp" |
|
480 | #include "moc_chartdataset_p.cpp" | |
464 |
|
481 | |||
465 | QTCOMMERCIALCHART_END_NAMESPACE |
|
482 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,319 +1,315 | |||||
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 "chartitem_p.h" |
|
22 | #include "chartitem_p.h" | |
23 | #include "qchart_p.h" |
|
23 | #include "qchart_p.h" | |
24 | #include "qabstractaxis.h" |
|
24 | #include "qabstractaxis.h" | |
25 | #include "qabstractaxis_p.h" |
|
25 | #include "qabstractaxis_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "chartanimation_p.h" |
|
27 | #include "chartanimation_p.h" | |
28 | #include "qabstractseries_p.h" |
|
28 | #include "qabstractseries_p.h" | |
29 | #include "qareaseries.h" |
|
29 | #include "qareaseries.h" | |
30 | #include "chartaxis_p.h" |
|
30 | #include "chartaxis_p.h" | |
31 | #include "chartbackground_p.h" |
|
31 | #include "chartbackground_p.h" | |
32 | #include "chartlayout_p.h" |
|
32 | #include "chartlayout_p.h" | |
33 | #include "charttitle_p.h" |
|
33 | #include "charttitle_p.h" | |
34 | #include <QTimer> |
|
34 | #include <QTimer> | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 | ChartPresenter::ChartPresenter(QChart *chart) |
|
38 | ChartPresenter::ChartPresenter(QChart *chart) | |
39 | : QObject(chart), |
|
39 | : QObject(chart), | |
40 | m_chart(chart), |
|
40 | m_chart(chart), | |
41 | m_options(QChart::NoAnimation), |
|
41 | m_options(QChart::NoAnimation), | |
42 | m_state(ShowState), |
|
42 | m_state(ShowState), | |
43 | m_layout(new ChartLayout(this)), |
|
43 | m_layout(new ChartLayout(this)), | |
44 | m_background(0), |
|
44 | m_background(0), | |
45 | m_title(0) |
|
45 | m_title(0) | |
46 | { |
|
46 | { | |
47 |
|
47 | |||
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | ChartPresenter::~ChartPresenter() |
|
50 | ChartPresenter::~ChartPresenter() | |
51 | { |
|
51 | { | |
52 |
|
52 | |||
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | void ChartPresenter::setGeometry(const QRectF rect) |
|
55 | void ChartPresenter::setGeometry(const QRectF rect) | |
56 | { |
|
56 | { | |
57 | if(m_rect != rect) { |
|
57 | if(m_rect != rect) { | |
58 | m_rect=rect; |
|
58 | m_rect=rect; | |
59 | foreach (ChartItem *chart, m_chartItems){ |
|
59 | foreach (ChartItem *chart, m_chartItems){ | |
60 | chart->domain()->setSize(rect.size()); |
|
60 | chart->domain()->setSize(rect.size()); | |
61 | chart->setPos(rect.topLeft()); |
|
61 | chart->setPos(rect.topLeft()); | |
62 | } |
|
62 | } | |
63 | } |
|
63 | } | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QRectF ChartPresenter::geometry() const |
|
66 | QRectF ChartPresenter::geometry() const | |
67 | { |
|
67 | { | |
68 | return m_rect; |
|
68 | return m_rect; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void ChartPresenter::handleAxisAdded(QAbstractAxis *axis) |
|
71 | void ChartPresenter::handleAxisAdded(QAbstractAxis *axis) | |
72 | { |
|
72 | { | |
73 | qDebug()<<__FUNCTION__; |
|
|||
74 | axis->d_ptr->initializeGraphics(rootItem()); |
|
73 | axis->d_ptr->initializeGraphics(rootItem()); | |
75 | axis->d_ptr->initializeAnimations(m_options); |
|
74 | axis->d_ptr->initializeAnimations(m_options); | |
76 | ChartAxis *item = axis->d_ptr->axisItem(); |
|
75 | ChartAxis *item = axis->d_ptr->axisItem(); | |
77 | item->setPresenter(this); |
|
76 | item->setPresenter(this); | |
78 | item->setThemeManager(m_chart->d_ptr->m_themeManager); |
|
77 | item->setThemeManager(m_chart->d_ptr->m_themeManager); | |
79 | m_axisItems<<item; |
|
78 | m_axisItems<<item; | |
80 | m_axes<<axis; |
|
79 | m_axes<<axis; | |
81 | m_layout->invalidate(); |
|
80 | m_layout->invalidate(); | |
82 | } |
|
81 | } | |
83 |
|
82 | |||
84 | void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) |
|
83 | void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis) | |
85 | { |
|
84 | { | |
86 | qDebug()<<__FUNCTION__; |
|
|||
87 | ChartAxis *item = axis->d_ptr->m_item.take(); |
|
85 | ChartAxis *item = axis->d_ptr->m_item.take(); | |
88 | item->hide(); |
|
86 | item->hide(); | |
89 | item->disconnect(); |
|
87 | item->disconnect(); | |
90 | item->deleteLater(); |
|
88 | item->deleteLater(); | |
91 | m_axisItems.removeAll(item); |
|
89 | m_axisItems.removeAll(item); | |
92 | m_axes.removeAll(axis); |
|
90 | m_axes.removeAll(axis); | |
93 | m_layout->invalidate(); |
|
91 | m_layout->invalidate(); | |
94 | } |
|
92 | } | |
95 |
|
93 | |||
96 |
|
94 | |||
97 | void ChartPresenter::handleSeriesAdded(QAbstractSeries *series) |
|
95 | void ChartPresenter::handleSeriesAdded(QAbstractSeries *series) | |
98 | { |
|
96 | { | |
99 | qDebug()<<__FUNCTION__; |
|
|||
100 | series->d_ptr->initializeGraphics(rootItem()); |
|
97 | series->d_ptr->initializeGraphics(rootItem()); | |
101 | series->d_ptr->initializeAnimations(m_options); |
|
98 | series->d_ptr->initializeAnimations(m_options); | |
102 | ChartItem *chart = series->d_ptr->chartItem(); |
|
99 | ChartItem *chart = series->d_ptr->chartItem(); | |
103 | chart->setPresenter(this); |
|
100 | chart->setPresenter(this); | |
104 | chart->setThemeManager(m_chart->d_ptr->m_themeManager); |
|
101 | chart->setThemeManager(m_chart->d_ptr->m_themeManager); | |
105 | chart->domain()->setSize(m_rect.size()); |
|
102 | chart->domain()->setSize(m_rect.size()); | |
106 | chart->setPos(m_rect.topLeft()); |
|
103 | chart->setPos(m_rect.topLeft()); | |
107 | chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored |
|
104 | chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored | |
108 | m_chartItems<<chart; |
|
105 | m_chartItems<<chart; | |
109 | m_series<<series; |
|
106 | m_series<<series; | |
110 | m_layout->invalidate(); |
|
107 | m_layout->invalidate(); | |
111 | } |
|
108 | } | |
112 |
|
109 | |||
113 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) |
|
110 | void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series) | |
114 | { |
|
111 | { | |
115 | qDebug()<<__FUNCTION__; |
|
|||
116 | ChartItem *chart = series->d_ptr->m_item.take(); |
|
112 | ChartItem *chart = series->d_ptr->m_item.take(); | |
117 | chart->hide(); |
|
113 | chart->hide(); | |
118 | chart->disconnect(); |
|
114 | chart->disconnect(); | |
119 | chart->deleteLater(); |
|
115 | chart->deleteLater(); | |
120 | m_chartItems.removeAll(chart); |
|
116 | m_chartItems.removeAll(chart); | |
121 | m_series.removeAll(series); |
|
117 | m_series.removeAll(series); | |
122 | m_layout->invalidate(); |
|
118 | m_layout->invalidate(); | |
123 | } |
|
119 | } | |
124 |
|
120 | |||
125 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
121 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
126 | { |
|
122 | { | |
127 | if (m_options != options) { |
|
123 | if (m_options != options) { | |
128 | m_options = options; |
|
124 | m_options = options; | |
129 |
|
125 | |||
130 | foreach(QAbstractSeries* series, m_series){ |
|
126 | foreach(QAbstractSeries* series, m_series){ | |
131 | series->d_ptr->initializeAnimations(m_options); |
|
127 | series->d_ptr->initializeAnimations(m_options); | |
132 | } |
|
128 | } | |
133 | foreach(QAbstractAxis* axis, m_axes){ |
|
129 | foreach(QAbstractAxis* axis, m_axes){ | |
134 | axis->d_ptr->initializeAnimations(m_options); |
|
130 | axis->d_ptr->initializeAnimations(m_options); | |
135 | } |
|
131 | } | |
136 | } |
|
132 | } | |
137 | } |
|
133 | } | |
138 |
|
134 | |||
139 | void ChartPresenter::setState(State state,QPointF point) |
|
135 | void ChartPresenter::setState(State state,QPointF point) | |
140 | { |
|
136 | { | |
141 | m_state=state; |
|
137 | m_state=state; | |
142 | m_statePoint=point; |
|
138 | m_statePoint=point; | |
143 | } |
|
139 | } | |
144 |
|
140 | |||
145 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
141 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
146 | { |
|
142 | { | |
147 | return m_options; |
|
143 | return m_options; | |
148 | } |
|
144 | } | |
149 |
|
145 | |||
150 | void ChartPresenter::createBackgroundItem() |
|
146 | void ChartPresenter::createBackgroundItem() | |
151 | { |
|
147 | { | |
152 | if (!m_background) { |
|
148 | if (!m_background) { | |
153 | m_background = new ChartBackground(rootItem()); |
|
149 | m_background = new ChartBackground(rootItem()); | |
154 | m_background->setPen(Qt::NoPen); |
|
150 | m_background->setPen(Qt::NoPen); | |
155 | m_background->setZValue(ChartPresenter::BackgroundZValue); |
|
151 | m_background->setZValue(ChartPresenter::BackgroundZValue); | |
156 | } |
|
152 | } | |
157 | } |
|
153 | } | |
158 |
|
154 | |||
159 | void ChartPresenter::createTitleItem() |
|
155 | void ChartPresenter::createTitleItem() | |
160 | { |
|
156 | { | |
161 | if (!m_title) { |
|
157 | if (!m_title) { | |
162 | m_title = new ChartTitle(rootItem()); |
|
158 | m_title = new ChartTitle(rootItem()); | |
163 | m_title->setZValue(ChartPresenter::BackgroundZValue); |
|
159 | m_title->setZValue(ChartPresenter::BackgroundZValue); | |
164 | } |
|
160 | } | |
165 | } |
|
161 | } | |
166 |
|
162 | |||
167 |
|
163 | |||
168 | void ChartPresenter::handleAnimationFinished() |
|
164 | void ChartPresenter::handleAnimationFinished() | |
169 | { |
|
165 | { | |
170 | m_animations.removeAll(qobject_cast<ChartAnimation *>(sender())); |
|
166 | m_animations.removeAll(qobject_cast<ChartAnimation *>(sender())); | |
171 | if (m_animations.empty()) |
|
167 | if (m_animations.empty()) | |
172 | emit animationsFinished(); |
|
168 | emit animationsFinished(); | |
173 | } |
|
169 | } | |
174 |
|
170 | |||
175 | void ChartPresenter::startAnimation(ChartAnimation *animation) |
|
171 | void ChartPresenter::startAnimation(ChartAnimation *animation) | |
176 | { |
|
172 | { | |
177 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); |
|
173 | if (animation->state() != QAbstractAnimation::Stopped) animation->stop(); | |
178 | QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection); |
|
174 | QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection); | |
179 | if (!m_animations.isEmpty()) |
|
175 | if (!m_animations.isEmpty()) | |
180 | m_animations.append(animation); |
|
176 | m_animations.append(animation); | |
181 | QTimer::singleShot(0, animation, SLOT(start())); |
|
177 | QTimer::singleShot(0, animation, SLOT(start())); | |
182 | } |
|
178 | } | |
183 |
|
179 | |||
184 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) |
|
180 | void ChartPresenter::setBackgroundBrush(const QBrush &brush) | |
185 | { |
|
181 | { | |
186 | createBackgroundItem(); |
|
182 | createBackgroundItem(); | |
187 | m_background->setBrush(brush); |
|
183 | m_background->setBrush(brush); | |
188 | m_layout->invalidate(); |
|
184 | m_layout->invalidate(); | |
189 | } |
|
185 | } | |
190 |
|
186 | |||
191 | QBrush ChartPresenter::backgroundBrush() const |
|
187 | QBrush ChartPresenter::backgroundBrush() const | |
192 | { |
|
188 | { | |
193 | if (!m_background) |
|
189 | if (!m_background) | |
194 | return QBrush(); |
|
190 | return QBrush(); | |
195 | return m_background->brush(); |
|
191 | return m_background->brush(); | |
196 | } |
|
192 | } | |
197 |
|
193 | |||
198 | void ChartPresenter::setBackgroundPen(const QPen &pen) |
|
194 | void ChartPresenter::setBackgroundPen(const QPen &pen) | |
199 | { |
|
195 | { | |
200 | createBackgroundItem(); |
|
196 | createBackgroundItem(); | |
201 | m_background->setPen(pen); |
|
197 | m_background->setPen(pen); | |
202 | m_layout->invalidate(); |
|
198 | m_layout->invalidate(); | |
203 | } |
|
199 | } | |
204 |
|
200 | |||
205 | QPen ChartPresenter::backgroundPen() const |
|
201 | QPen ChartPresenter::backgroundPen() const | |
206 | { |
|
202 | { | |
207 | if (!m_background) |
|
203 | if (!m_background) | |
208 | return QPen(); |
|
204 | return QPen(); | |
209 | return m_background->pen(); |
|
205 | return m_background->pen(); | |
210 | } |
|
206 | } | |
211 |
|
207 | |||
212 | void ChartPresenter::setTitle(const QString &title) |
|
208 | void ChartPresenter::setTitle(const QString &title) | |
213 | { |
|
209 | { | |
214 | createTitleItem(); |
|
210 | createTitleItem(); | |
215 | m_title->setText(title); |
|
211 | m_title->setText(title); | |
216 | m_layout->invalidate(); |
|
212 | m_layout->invalidate(); | |
217 | } |
|
213 | } | |
218 |
|
214 | |||
219 | QString ChartPresenter::title() const |
|
215 | QString ChartPresenter::title() const | |
220 | { |
|
216 | { | |
221 | if (!m_title) |
|
217 | if (!m_title) | |
222 | return QString(); |
|
218 | return QString(); | |
223 | return m_title->text(); |
|
219 | return m_title->text(); | |
224 | } |
|
220 | } | |
225 |
|
221 | |||
226 | void ChartPresenter::setTitleFont(const QFont &font) |
|
222 | void ChartPresenter::setTitleFont(const QFont &font) | |
227 | { |
|
223 | { | |
228 | createTitleItem(); |
|
224 | createTitleItem(); | |
229 | m_title->setFont(font); |
|
225 | m_title->setFont(font); | |
230 | m_layout->invalidate(); |
|
226 | m_layout->invalidate(); | |
231 | } |
|
227 | } | |
232 |
|
228 | |||
233 | QFont ChartPresenter::titleFont() const |
|
229 | QFont ChartPresenter::titleFont() const | |
234 | { |
|
230 | { | |
235 | if (!m_title) |
|
231 | if (!m_title) | |
236 | return QFont(); |
|
232 | return QFont(); | |
237 | return m_title->font(); |
|
233 | return m_title->font(); | |
238 | } |
|
234 | } | |
239 |
|
235 | |||
240 | void ChartPresenter::setTitleBrush(const QBrush &brush) |
|
236 | void ChartPresenter::setTitleBrush(const QBrush &brush) | |
241 | { |
|
237 | { | |
242 | createTitleItem(); |
|
238 | createTitleItem(); | |
243 | m_title->setBrush(brush); |
|
239 | m_title->setBrush(brush); | |
244 | m_layout->invalidate(); |
|
240 | m_layout->invalidate(); | |
245 | } |
|
241 | } | |
246 |
|
242 | |||
247 | QBrush ChartPresenter::titleBrush() const |
|
243 | QBrush ChartPresenter::titleBrush() const | |
248 | { |
|
244 | { | |
249 | if (!m_title) |
|
245 | if (!m_title) | |
250 | return QBrush(); |
|
246 | return QBrush(); | |
251 | return m_title->brush(); |
|
247 | return m_title->brush(); | |
252 | } |
|
248 | } | |
253 |
|
249 | |||
254 | void ChartPresenter::setBackgroundVisible(bool visible) |
|
250 | void ChartPresenter::setBackgroundVisible(bool visible) | |
255 | { |
|
251 | { | |
256 | createBackgroundItem(); |
|
252 | createBackgroundItem(); | |
257 | m_background->setVisible(visible); |
|
253 | m_background->setVisible(visible); | |
258 | } |
|
254 | } | |
259 |
|
255 | |||
260 |
|
256 | |||
261 | bool ChartPresenter::isBackgroundVisible() const |
|
257 | bool ChartPresenter::isBackgroundVisible() const | |
262 | { |
|
258 | { | |
263 | if (!m_background) |
|
259 | if (!m_background) | |
264 | return false; |
|
260 | return false; | |
265 | return m_background->isVisible(); |
|
261 | return m_background->isVisible(); | |
266 | } |
|
262 | } | |
267 |
|
263 | |||
268 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) |
|
264 | void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled) | |
269 | { |
|
265 | { | |
270 | createBackgroundItem(); |
|
266 | createBackgroundItem(); | |
271 | m_background->setDropShadowEnabled(enabled); |
|
267 | m_background->setDropShadowEnabled(enabled); | |
272 | } |
|
268 | } | |
273 |
|
269 | |||
274 | bool ChartPresenter::isBackgroundDropShadowEnabled() const |
|
270 | bool ChartPresenter::isBackgroundDropShadowEnabled() const | |
275 | { |
|
271 | { | |
276 | if (!m_background) |
|
272 | if (!m_background) | |
277 | return false; |
|
273 | return false; | |
278 | return m_background->isDropShadowEnabled(); |
|
274 | return m_background->isDropShadowEnabled(); | |
279 | } |
|
275 | } | |
280 |
|
276 | |||
281 |
|
277 | |||
282 | ChartLayout *ChartPresenter::layout() |
|
278 | ChartLayout *ChartPresenter::layout() | |
283 | { |
|
279 | { | |
284 | return m_layout; |
|
280 | return m_layout; | |
285 | } |
|
281 | } | |
286 |
|
282 | |||
287 | QLegend *ChartPresenter::legend() |
|
283 | QLegend *ChartPresenter::legend() | |
288 | { |
|
284 | { | |
289 | return m_chart->legend(); |
|
285 | return m_chart->legend(); | |
290 | } |
|
286 | } | |
291 |
|
287 | |||
292 | void ChartPresenter::setVisible(bool visible) |
|
288 | void ChartPresenter::setVisible(bool visible) | |
293 | { |
|
289 | { | |
294 | m_chart->setVisible(visible); |
|
290 | m_chart->setVisible(visible); | |
295 | } |
|
291 | } | |
296 |
|
292 | |||
297 | ChartBackground *ChartPresenter::backgroundElement() |
|
293 | ChartBackground *ChartPresenter::backgroundElement() | |
298 | { |
|
294 | { | |
299 | return m_background; |
|
295 | return m_background; | |
300 | } |
|
296 | } | |
301 |
|
297 | |||
302 | QList<ChartAxis *> ChartPresenter::axisItems() const |
|
298 | QList<ChartAxis *> ChartPresenter::axisItems() const | |
303 | { |
|
299 | { | |
304 | return m_axisItems; |
|
300 | return m_axisItems; | |
305 | } |
|
301 | } | |
306 |
|
302 | |||
307 | QList<ChartItem *> ChartPresenter::chartItems() const |
|
303 | QList<ChartItem *> ChartPresenter::chartItems() const | |
308 | { |
|
304 | { | |
309 | return m_chartItems; |
|
305 | return m_chartItems; | |
310 | } |
|
306 | } | |
311 |
|
307 | |||
312 | ChartTitle *ChartPresenter::titleElement() |
|
308 | ChartTitle *ChartPresenter::titleElement() | |
313 | { |
|
309 | { | |
314 | return m_title; |
|
310 | return m_title; | |
315 | } |
|
311 | } | |
316 |
|
312 | |||
317 | #include "moc_chartpresenter_p.cpp" |
|
313 | #include "moc_chartpresenter_p.cpp" | |
318 |
|
314 | |||
319 | QTCOMMERCIALCHART_END_NAMESPACE |
|
315 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,180 +1,182 | |||||
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 "logxlogydomain_p.h" |
|
21 | #include "logxlogydomain_p.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
23 | #include <qmath.h> |
|
23 | #include <qmath.h> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | LogXLogYDomain::LogXLogYDomain(QObject *parent) |
|
27 | LogXLogYDomain::LogXLogYDomain(QObject *parent) | |
28 | : AbstractDomain(parent), |
|
28 | : AbstractDomain(parent), | |
29 | m_logMinX(0), |
|
29 | m_logMinX(0), | |
30 | m_logMaxX(1), |
|
30 | m_logMaxX(1), | |
31 | m_logBaseX(10), |
|
31 | m_logBaseX(10), | |
32 | m_logMinY(0), |
|
32 | m_logMinY(0), | |
33 | m_logMaxY(1), |
|
33 | m_logMaxY(1), | |
34 | m_logBaseY(10) |
|
34 | m_logBaseY(10) | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | LogXLogYDomain::~LogXLogYDomain() |
|
38 | LogXLogYDomain::~LogXLogYDomain() | |
39 | { |
|
39 | { | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | void LogXLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
42 | void LogXLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
43 | { |
|
43 | { | |
44 | bool axisXChanged = false; |
|
44 | bool axisXChanged = false; | |
45 | bool axisYChanged = false; |
|
45 | bool axisYChanged = false; | |
46 |
|
46 | |||
47 | if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) { |
|
47 | if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) { | |
48 | m_minX = minX; |
|
48 | m_minX = minX; | |
49 | m_maxX = maxX; |
|
49 | m_maxX = maxX; | |
50 | axisXChanged = true; |
|
50 | axisXChanged = true; | |
51 | m_logMinX = log10(m_minX) / log10(m_logBaseX); |
|
51 | m_logMinX = log10(m_minX) / log10(m_logBaseX); | |
52 | m_logMaxX = log10(m_maxX) / log10(m_logBaseX); |
|
52 | m_logMaxX = log10(m_maxX) / log10(m_logBaseX); | |
|
53 | if(!m_signalsBlocked) | |||
53 | emit rangeHorizontalChanged(m_minX, m_maxX); |
|
54 | emit rangeHorizontalChanged(m_minX, m_maxX); | |
54 | } |
|
55 | } | |
55 |
|
56 | |||
56 | if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { |
|
57 | if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { | |
57 | m_minY = minY; |
|
58 | m_minY = minY; | |
58 | m_maxY = maxY; |
|
59 | m_maxY = maxY; | |
59 | axisYChanged = true; |
|
60 | axisYChanged = true; | |
60 | m_logMinY = log10(m_minY) / log10(m_logBaseY); |
|
61 | m_logMinY = log10(m_minY) / log10(m_logBaseY); | |
61 | m_logMaxY = log10(m_maxY) / log10(m_logBaseY); |
|
62 | m_logMaxY = log10(m_maxY) / log10(m_logBaseY); | |
|
63 | if(!m_signalsBlocked) | |||
62 | emit rangeVerticalChanged(m_minY, m_maxY); |
|
64 | emit rangeVerticalChanged(m_minY, m_maxY); | |
63 | } |
|
65 | } | |
64 |
|
66 | |||
65 | if (axisXChanged || axisYChanged) |
|
67 | if (axisXChanged || axisYChanged) | |
66 | emit updated(); |
|
68 | emit updated(); | |
67 | } |
|
69 | } | |
68 |
|
70 | |||
69 | void LogXLogYDomain::zoomIn(const QRectF &rect) |
|
71 | void LogXLogYDomain::zoomIn(const QRectF &rect) | |
70 | { |
|
72 | { | |
71 | qreal newLogMinX = rect.left() * (m_logMaxX - m_logMinX) / m_size.width() + m_logMinX; |
|
73 | qreal newLogMinX = rect.left() * (m_logMaxX - m_logMinX) / m_size.width() + m_logMinX; | |
72 | qreal newLogMaxX = rect.right() * (m_logMaxX - m_logMinX) / m_size.width() + m_logMinX; |
|
74 | qreal newLogMaxX = rect.right() * (m_logMaxX - m_logMinX) / m_size.width() + m_logMinX; | |
73 | qreal minX = qPow(m_logBaseX, newLogMinX); |
|
75 | qreal minX = qPow(m_logBaseX, newLogMinX); | |
74 | qreal maxX = qPow(m_logBaseX, newLogMaxX); |
|
76 | qreal maxX = qPow(m_logBaseX, newLogMaxX); | |
75 |
|
77 | |||
76 | qreal newLogMinY = m_logMaxY - rect.bottom() * (m_logMaxY - m_logMinY) / m_size.height(); |
|
78 | qreal newLogMinY = m_logMaxY - rect.bottom() * (m_logMaxY - m_logMinY) / m_size.height(); | |
77 | qreal newLogMaxY = m_logMaxY - rect.top() * (m_logMaxY - m_logMinY) / m_size.height(); |
|
79 | qreal newLogMaxY = m_logMaxY - rect.top() * (m_logMaxY - m_logMinY) / m_size.height(); | |
78 | qreal minY = qPow(m_logBaseY, newLogMinY); |
|
80 | qreal minY = qPow(m_logBaseY, newLogMinY); | |
79 | qreal maxY = qPow(m_logBaseY, newLogMaxY); |
|
81 | qreal maxY = qPow(m_logBaseY, newLogMaxY); | |
80 |
|
82 | |||
81 | setRange(minX, maxX, minY, maxY); |
|
83 | setRange(minX, maxX, minY, maxY); | |
82 | } |
|
84 | } | |
83 |
|
85 | |||
84 | void LogXLogYDomain::zoomOut(const QRectF &rect) |
|
86 | void LogXLogYDomain::zoomOut(const QRectF &rect) | |
85 | { |
|
87 | { | |
86 | qreal ratioX = m_size.width()/rect.width(); |
|
88 | qreal ratioX = m_size.width()/rect.width(); | |
87 | qreal newLogMinX = m_logMinX - (m_logMaxX - m_logMinX) / ratioX; |
|
89 | qreal newLogMinX = m_logMinX - (m_logMaxX - m_logMinX) / ratioX; | |
88 | qreal newLogMaxX = m_logMaxX + (m_logMaxX - m_logMinX) / ratioX; |
|
90 | qreal newLogMaxX = m_logMaxX + (m_logMaxX - m_logMinX) / ratioX; | |
89 | qreal minX = qPow(m_logBaseX, newLogMinX); |
|
91 | qreal minX = qPow(m_logBaseX, newLogMinX); | |
90 | qreal maxX = qPow(m_logBaseX, newLogMaxX); |
|
92 | qreal maxX = qPow(m_logBaseX, newLogMaxX); | |
91 |
|
93 | |||
92 | qreal ratioY = m_size.height()/rect.height(); |
|
94 | qreal ratioY = m_size.height()/rect.height(); | |
93 | qreal newLogMinY = m_logMaxY - (m_logMaxY - m_logMinY) / ratioY; |
|
95 | qreal newLogMinY = m_logMaxY - (m_logMaxY - m_logMinY) / ratioY; | |
94 | qreal newLogMaxY = m_logMaxY + (m_logMaxY - m_logMinY) / ratioY; |
|
96 | qreal newLogMaxY = m_logMaxY + (m_logMaxY - m_logMinY) / ratioY; | |
95 | qreal minY = qPow(m_logBaseY, newLogMinY); |
|
97 | qreal minY = qPow(m_logBaseY, newLogMinY); | |
96 | qreal maxY = qPow(m_logBaseY, newLogMaxY); |
|
98 | qreal maxY = qPow(m_logBaseY, newLogMaxY); | |
97 |
|
99 | |||
98 | setRange(minX, maxX, minY, maxY); |
|
100 | setRange(minX, maxX, minY, maxY); | |
99 | } |
|
101 | } | |
100 |
|
102 | |||
101 | void LogXLogYDomain::move(qreal dx, qreal dy) |
|
103 | void LogXLogYDomain::move(qreal dx, qreal dy) | |
102 | { |
|
104 | { | |
103 | qreal stepX = dx * qAbs(m_logMaxX - m_logMinX) / m_size.width(); |
|
105 | qreal stepX = dx * qAbs(m_logMaxX - m_logMinX) / m_size.width(); | |
104 | qreal minX = qPow(m_logBaseX, m_logMinX + stepX); |
|
106 | qreal minX = qPow(m_logBaseX, m_logMinX + stepX); | |
105 | qreal maxX = qPow(m_logBaseX, m_logMaxX + stepX); |
|
107 | qreal maxX = qPow(m_logBaseX, m_logMaxX + stepX); | |
106 |
|
108 | |||
107 | qreal stepY = dy * qAbs(m_logMaxY - m_logMinY) / m_size.height(); |
|
109 | qreal stepY = dy * qAbs(m_logMaxY - m_logMinY) / m_size.height(); | |
108 | qreal minY = qPow(m_logBaseY, m_logMinY + stepY); |
|
110 | qreal minY = qPow(m_logBaseY, m_logMinY + stepY); | |
109 | qreal maxY = qPow(m_logBaseY, m_logMaxY + stepY); |
|
111 | qreal maxY = qPow(m_logBaseY, m_logMaxY + stepY); | |
110 |
|
112 | |||
111 | setRange(minX, maxX, minY, maxY); |
|
113 | setRange(minX, maxX, minY, maxY); | |
112 | } |
|
114 | } | |
113 |
|
115 | |||
114 | QPointF LogXLogYDomain::calculateGeometryPoint(const QPointF &point) const |
|
116 | QPointF LogXLogYDomain::calculateGeometryPoint(const QPointF &point) const | |
115 | { |
|
117 | { | |
116 | const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; |
|
118 | const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; | |
117 | const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; |
|
119 | const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; | |
118 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); |
|
120 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); | |
119 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); |
|
121 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); | |
120 | qreal x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - leftEdgeX * deltaX; |
|
122 | qreal x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - leftEdgeX * deltaX; | |
121 | qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - leftEdgeY * -deltaY + m_size.height(); |
|
123 | qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - leftEdgeY * -deltaY + m_size.height(); | |
122 | return QPointF(x, y); |
|
124 | return QPointF(x, y); | |
123 | } |
|
125 | } | |
124 |
|
126 | |||
125 | QVector<QPointF> LogXLogYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const |
|
127 | QVector<QPointF> LogXLogYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const | |
126 | { |
|
128 | { | |
127 | const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; |
|
129 | const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; | |
128 | const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; |
|
130 | const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; | |
129 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); |
|
131 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); | |
130 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); |
|
132 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); | |
131 |
|
133 | |||
132 | QVector<QPointF> result; |
|
134 | QVector<QPointF> result; | |
133 | result.resize(vector.count()); |
|
135 | result.resize(vector.count()); | |
134 |
|
136 | |||
135 | for (int i = 0; i < vector.count(); ++i) { |
|
137 | for (int i = 0; i < vector.count(); ++i) { | |
136 | qreal x = (log10(vector[i].x()) / log10(m_logBaseX)) * deltaX - leftEdgeX * deltaX; |
|
138 | qreal x = (log10(vector[i].x()) / log10(m_logBaseX)) * deltaX - leftEdgeX * deltaX; | |
137 | qreal y = (log10(vector[i].y()) / log10(m_logBaseY)) * -deltaY - leftEdgeY * -deltaY + m_size.height(); |
|
139 | qreal y = (log10(vector[i].y()) / log10(m_logBaseY)) * -deltaY - leftEdgeY * -deltaY + m_size.height(); | |
138 | result[i].setX(x); |
|
140 | result[i].setX(x); | |
139 | result[i].setY(y); |
|
141 | result[i].setY(y); | |
140 | } |
|
142 | } | |
141 | return result; |
|
143 | return result; | |
142 | } |
|
144 | } | |
143 |
|
145 | |||
144 | QPointF LogXLogYDomain::calculateDomainPoint(const QPointF &point) const |
|
146 | QPointF LogXLogYDomain::calculateDomainPoint(const QPointF &point) const | |
145 | { |
|
147 | { | |
146 | const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; |
|
148 | const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; | |
147 | const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; |
|
149 | const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; | |
148 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); |
|
150 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); | |
149 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); |
|
151 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); | |
150 | qreal x = qPow(m_logBaseX, leftEdgeX + point.x() / deltaX); |
|
152 | qreal x = qPow(m_logBaseX, leftEdgeX + point.x() / deltaX); | |
151 | qreal y = qPow(m_logBaseY, leftEdgeY + (m_size.height() - point.y()) / deltaY); |
|
153 | qreal y = qPow(m_logBaseY, leftEdgeY + (m_size.height() - point.y()) / deltaY); | |
152 | return QPointF(x, y); |
|
154 | return QPointF(x, y); | |
153 | } |
|
155 | } | |
154 |
|
156 | |||
155 | // operators |
|
157 | // operators | |
156 |
|
158 | |||
157 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2) |
|
159 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2) | |
158 | { |
|
160 | { | |
159 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) && |
|
161 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) && | |
160 | qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) && |
|
162 | qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) && | |
161 | qFuzzyIsNull(domain1.m_minX - domain2.m_minX) && |
|
163 | qFuzzyIsNull(domain1.m_minX - domain2.m_minX) && | |
162 | qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); |
|
164 | qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); | |
163 | } |
|
165 | } | |
164 |
|
166 | |||
165 |
|
167 | |||
166 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2) |
|
168 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2) | |
167 | { |
|
169 | { | |
168 | return !(domain1 == domain2); |
|
170 | return !(domain1 == domain2); | |
169 | } |
|
171 | } | |
170 |
|
172 | |||
171 |
|
173 | |||
172 | QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXLogYDomain &domain) |
|
174 | QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXLogYDomain &domain) | |
173 | { |
|
175 | { | |
174 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; |
|
176 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; | |
175 | return dbg.maybeSpace(); |
|
177 | return dbg.maybeSpace(); | |
176 | } |
|
178 | } | |
177 |
|
179 | |||
178 | #include "moc_logxlogydomain_p.cpp" |
|
180 | #include "moc_logxlogydomain_p.cpp" | |
179 |
|
181 | |||
180 | QTCOMMERCIALCHART_END_NAMESPACE |
|
182 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,181 +1,182 | |||||
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 "logxydomain_p.h" |
|
21 | #include "logxydomain_p.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
23 | #include <qmath.h> |
|
23 | #include <qmath.h> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | LogXYDomain::LogXYDomain(QObject *parent) |
|
27 | LogXYDomain::LogXYDomain(QObject *parent) | |
28 | : AbstractDomain(parent), |
|
28 | : AbstractDomain(parent), | |
29 | m_logMinX(0), |
|
29 | m_logMinX(0), | |
30 | m_logMaxX(1), |
|
30 | m_logMaxX(1), | |
31 | m_logBaseX(10) |
|
31 | m_logBaseX(10) | |
32 | { |
|
32 | { | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | LogXYDomain::~LogXYDomain() |
|
35 | LogXYDomain::~LogXYDomain() | |
36 | { |
|
36 | { | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | void LogXYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
39 | void LogXYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
40 | { |
|
40 | { | |
41 | bool axisXChanged = false; |
|
41 | bool axisXChanged = false; | |
42 | bool axisYChanged = false; |
|
42 | bool axisYChanged = false; | |
43 |
|
43 | |||
44 | if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) { |
|
44 | if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) { | |
45 | m_minX = minX; |
|
45 | m_minX = minX; | |
46 | m_maxX = maxX; |
|
46 | m_maxX = maxX; | |
47 | axisXChanged = true; |
|
47 | axisXChanged = true; | |
48 | m_logMinX = log10(m_minX) / log10(m_logBaseX); |
|
48 | m_logMinX = log10(m_minX) / log10(m_logBaseX); | |
49 | m_logMaxX = log10(m_maxX) / log10(m_logBaseX); |
|
49 | m_logMaxX = log10(m_maxX) / log10(m_logBaseX); | |
50 |
|
50 | if(!m_signalsBlocked) | ||
51 | emit rangeHorizontalChanged(m_minX, m_maxX); |
|
51 | emit rangeHorizontalChanged(m_minX, m_maxX); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { |
|
54 | if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { | |
55 | m_minY = minY; |
|
55 | m_minY = minY; | |
56 | m_maxY = maxY; |
|
56 | m_maxY = maxY; | |
57 | axisYChanged = true; |
|
57 | axisYChanged = true; | |
|
58 | if(!m_signalsBlocked) | |||
58 | emit rangeVerticalChanged(m_minY, m_maxY); |
|
59 | emit rangeVerticalChanged(m_minY, m_maxY); | |
59 | } |
|
60 | } | |
60 |
|
61 | |||
61 | if (axisXChanged || axisYChanged) |
|
62 | if (axisXChanged || axisYChanged) | |
62 | emit updated(); |
|
63 | emit updated(); | |
63 | } |
|
64 | } | |
64 |
|
65 | |||
65 | void LogXYDomain::zoomIn(const QRectF &rect) |
|
66 | void LogXYDomain::zoomIn(const QRectF &rect) | |
66 | { |
|
67 | { | |
67 | qreal newLogMinX = rect.left() * (m_logMaxX - m_logMinX) / m_size.width() + m_logMinX; |
|
68 | qreal newLogMinX = rect.left() * (m_logMaxX - m_logMinX) / m_size.width() + m_logMinX; | |
68 | qreal newLogMaxX = rect.right() * (m_logMaxX - m_logMinX) / m_size.width() + m_logMinX; |
|
69 | qreal newLogMaxX = rect.right() * (m_logMaxX - m_logMinX) / m_size.width() + m_logMinX; | |
69 | qreal minX = qPow(m_logBaseX, newLogMinX); |
|
70 | qreal minX = qPow(m_logBaseX, newLogMinX); | |
70 | qreal maxX = qPow(m_logBaseX, newLogMaxX); |
|
71 | qreal maxX = qPow(m_logBaseX, newLogMaxX); | |
71 |
|
72 | |||
72 | qreal dy = spanY() / m_size.height(); |
|
73 | qreal dy = spanY() / m_size.height(); | |
73 | qreal minY = m_minY; |
|
74 | qreal minY = m_minY; | |
74 | qreal maxY = m_maxY; |
|
75 | qreal maxY = m_maxY; | |
75 |
|
76 | |||
76 | minY = maxY - dy * rect.bottom(); |
|
77 | minY = maxY - dy * rect.bottom(); | |
77 | maxY = maxY - dy * rect.top(); |
|
78 | maxY = maxY - dy * rect.top(); | |
78 |
|
79 | |||
79 | setRange(minX, maxX, minY, maxY); |
|
80 | setRange(minX, maxX, minY, maxY); | |
80 | } |
|
81 | } | |
81 |
|
82 | |||
82 | void LogXYDomain::zoomOut(const QRectF &rect) |
|
83 | void LogXYDomain::zoomOut(const QRectF &rect) | |
83 | { |
|
84 | { | |
84 | qreal ratioX = m_size.width()/rect.width(); |
|
85 | qreal ratioX = m_size.width()/rect.width(); | |
85 | qreal newLogMinX = m_logMinX - (m_logMaxX - m_logMinX) / ratioX; |
|
86 | qreal newLogMinX = m_logMinX - (m_logMaxX - m_logMinX) / ratioX; | |
86 | qreal newLogMaxX = m_logMaxX + (m_logMaxX - m_logMinX) / ratioX; |
|
87 | qreal newLogMaxX = m_logMaxX + (m_logMaxX - m_logMinX) / ratioX; | |
87 | qreal minX = qPow(m_logBaseX, newLogMinX); |
|
88 | qreal minX = qPow(m_logBaseX, newLogMinX); | |
88 | qreal maxX = qPow(m_logBaseX, newLogMaxX); |
|
89 | qreal maxX = qPow(m_logBaseX, newLogMaxX); | |
89 |
|
90 | |||
90 | qreal dy = spanY() / rect.height(); |
|
91 | qreal dy = spanY() / rect.height(); | |
91 | qreal minY = m_minY; |
|
92 | qreal minY = m_minY; | |
92 | qreal maxY = m_maxY; |
|
93 | qreal maxY = m_maxY; | |
93 |
|
94 | |||
94 | maxY = minY + dy * rect.bottom(); |
|
95 | maxY = minY + dy * rect.bottom(); | |
95 | minY = maxY - dy * m_size.height(); |
|
96 | minY = maxY - dy * m_size.height(); | |
96 |
|
97 | |||
97 | setRange(minX, maxX, minY, maxY); |
|
98 | setRange(minX, maxX, minY, maxY); | |
98 | } |
|
99 | } | |
99 |
|
100 | |||
100 | void LogXYDomain::move(qreal dx, qreal dy) |
|
101 | void LogXYDomain::move(qreal dx, qreal dy) | |
101 | { |
|
102 | { | |
102 | qreal stepX = dx * qAbs(m_logMaxX - m_logMinX) / m_size.width(); |
|
103 | qreal stepX = dx * qAbs(m_logMaxX - m_logMinX) / m_size.width(); | |
103 | qreal minX = qPow(m_logBaseX, m_logMinX + stepX); |
|
104 | qreal minX = qPow(m_logBaseX, m_logMinX + stepX); | |
104 | qreal maxX = qPow(m_logBaseX, m_logMaxX + stepX); |
|
105 | qreal maxX = qPow(m_logBaseX, m_logMaxX + stepX); | |
105 |
|
106 | |||
106 | qreal y = spanY() / m_size.height(); |
|
107 | qreal y = spanY() / m_size.height(); | |
107 | qreal minY = m_minY; |
|
108 | qreal minY = m_minY; | |
108 | qreal maxY = m_maxY; |
|
109 | qreal maxY = m_maxY; | |
109 |
|
110 | |||
110 | if (dy != 0) { |
|
111 | if (dy != 0) { | |
111 | minY = minY + y * dy; |
|
112 | minY = minY + y * dy; | |
112 | maxY = maxY + y * dy; |
|
113 | maxY = maxY + y * dy; | |
113 | } |
|
114 | } | |
114 | setRange(minX, maxX, minY, maxY); |
|
115 | setRange(minX, maxX, minY, maxY); | |
115 | } |
|
116 | } | |
116 |
|
117 | |||
117 | QPointF LogXYDomain::calculateGeometryPoint(const QPointF &point) const |
|
118 | QPointF LogXYDomain::calculateGeometryPoint(const QPointF &point) const | |
118 | { |
|
119 | { | |
119 | const qreal leftEdge = m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; |
|
120 | const qreal leftEdge = m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; | |
120 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); |
|
121 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); | |
121 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
122 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); | |
122 |
|
123 | |||
123 | qreal x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - leftEdge * deltaX; |
|
124 | qreal x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - leftEdge * deltaX; | |
124 | qreal y = (point.y() - m_minY) * -deltaY + m_size.height(); |
|
125 | qreal y = (point.y() - m_minY) * -deltaY + m_size.height(); | |
125 | return QPointF(x, y); |
|
126 | return QPointF(x, y); | |
126 | } |
|
127 | } | |
127 |
|
128 | |||
128 | QVector<QPointF> LogXYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const |
|
129 | QVector<QPointF> LogXYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const | |
129 | { |
|
130 | { | |
130 | const qreal leftEdge = m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; |
|
131 | const qreal leftEdge = m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; | |
131 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); |
|
132 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); | |
132 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
133 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); | |
133 |
|
134 | |||
134 | QVector<QPointF> result; |
|
135 | QVector<QPointF> result; | |
135 | result.resize(vector.count()); |
|
136 | result.resize(vector.count()); | |
136 |
|
137 | |||
137 | for (int i = 0; i < vector.count(); ++i) { |
|
138 | for (int i = 0; i < vector.count(); ++i) { | |
138 | qreal x = (log10(vector[i].x()) / log10(m_logBaseX)) * deltaX - leftEdge * deltaX; |
|
139 | qreal x = (log10(vector[i].x()) / log10(m_logBaseX)) * deltaX - leftEdge * deltaX; | |
139 | qreal y = (vector[i].y() - m_minY) * -deltaY + m_size.height(); |
|
140 | qreal y = (vector[i].y() - m_minY) * -deltaY + m_size.height(); | |
140 | result[i].setX(x); |
|
141 | result[i].setX(x); | |
141 | result[i].setY(y); |
|
142 | result[i].setY(y); | |
142 | } |
|
143 | } | |
143 | return result; |
|
144 | return result; | |
144 | } |
|
145 | } | |
145 |
|
146 | |||
146 | QPointF LogXYDomain::calculateDomainPoint(const QPointF &point) const |
|
147 | QPointF LogXYDomain::calculateDomainPoint(const QPointF &point) const | |
147 | { |
|
148 | { | |
148 | const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; |
|
149 | const qreal leftEdgeX= m_logMinX < m_logMaxX ? m_logMinX : m_logMaxX; | |
149 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); |
|
150 | const qreal deltaX = m_size.width() / qAbs(m_logMaxX - m_logMinX); | |
150 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); |
|
151 | const qreal deltaY = m_size.height() / (m_maxY - m_minY); | |
151 | qreal x = qPow(m_logBaseX, leftEdgeX + point.x() / deltaX); |
|
152 | qreal x = qPow(m_logBaseX, leftEdgeX + point.x() / deltaX); | |
152 | qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY; |
|
153 | qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY; | |
153 | return QPointF(x, y); |
|
154 | return QPointF(x, y); | |
154 | } |
|
155 | } | |
155 |
|
156 | |||
156 | // operators |
|
157 | // operators | |
157 |
|
158 | |||
158 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXYDomain &domain1, const LogXYDomain &domain2) |
|
159 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXYDomain &domain1, const LogXYDomain &domain2) | |
159 | { |
|
160 | { | |
160 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) && |
|
161 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) && | |
161 | qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) && |
|
162 | qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) && | |
162 | qFuzzyIsNull(domain1.m_minX - domain2.m_minX) && |
|
163 | qFuzzyIsNull(domain1.m_minX - domain2.m_minX) && | |
163 | qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); |
|
164 | qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); | |
164 | } |
|
165 | } | |
165 |
|
166 | |||
166 |
|
167 | |||
167 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const LogXYDomain &domain1, const LogXYDomain &domain2) |
|
168 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const LogXYDomain &domain1, const LogXYDomain &domain2) | |
168 | { |
|
169 | { | |
169 | return !(domain1 == domain2); |
|
170 | return !(domain1 == domain2); | |
170 | } |
|
171 | } | |
171 |
|
172 | |||
172 |
|
173 | |||
173 | QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXYDomain &domain) |
|
174 | QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXYDomain &domain) | |
174 | { |
|
175 | { | |
175 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; |
|
176 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; | |
176 | return dbg.maybeSpace(); |
|
177 | return dbg.maybeSpace(); | |
177 | } |
|
178 | } | |
178 |
|
179 | |||
179 | #include "moc_logxydomain_p.cpp" |
|
180 | #include "moc_logxydomain_p.cpp" | |
180 |
|
181 | |||
181 | QTCOMMERCIALCHART_END_NAMESPACE |
|
182 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,181 +1,183 | |||||
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 "xlogydomain_p.h" |
|
21 | #include "xlogydomain_p.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
23 | #include <qmath.h> |
|
23 | #include <qmath.h> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | XLogYDomain::XLogYDomain(QObject *parent) |
|
27 | XLogYDomain::XLogYDomain(QObject *parent) | |
28 | : AbstractDomain(parent), |
|
28 | : AbstractDomain(parent), | |
29 | m_logMinY(0), |
|
29 | m_logMinY(0), | |
30 | m_logMaxY(1), |
|
30 | m_logMaxY(1), | |
31 | m_logBaseY(10) |
|
31 | m_logBaseY(10) | |
32 | { |
|
32 | { | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | XLogYDomain::~XLogYDomain() |
|
35 | XLogYDomain::~XLogYDomain() | |
36 | { |
|
36 | { | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | void XLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
39 | void XLogYDomain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
40 | { |
|
40 | { | |
41 | bool axisXChanged = false; |
|
41 | bool axisXChanged = false; | |
42 | bool axisYChanged = false; |
|
42 | bool axisYChanged = false; | |
43 |
|
43 | |||
44 | if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) { |
|
44 | if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) { | |
45 | m_minX = minX; |
|
45 | m_minX = minX; | |
46 | m_maxX = maxX; |
|
46 | m_maxX = maxX; | |
47 | axisXChanged = true; |
|
47 | axisXChanged = true; | |
|
48 | if(!m_signalsBlocked) | |||
48 | emit rangeHorizontalChanged(m_minX, m_maxX); |
|
49 | emit rangeHorizontalChanged(m_minX, m_maxX); | |
49 | } |
|
50 | } | |
50 |
|
51 | |||
51 | if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { |
|
52 | if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) { | |
52 | m_minY = minY; |
|
53 | m_minY = minY; | |
53 | m_maxY = maxY; |
|
54 | m_maxY = maxY; | |
54 | axisYChanged = true; |
|
55 | axisYChanged = true; | |
55 | m_logMinY = log10(m_minY) / log10(m_logBaseY); |
|
56 | m_logMinY = log10(m_minY) / log10(m_logBaseY); | |
56 | m_logMaxY = log10(m_maxY) / log10(m_logBaseY); |
|
57 | m_logMaxY = log10(m_maxY) / log10(m_logBaseY); | |
|
58 | if(!m_signalsBlocked) | |||
57 | emit rangeVerticalChanged(m_minY, m_maxY); |
|
59 | emit rangeVerticalChanged(m_minY, m_maxY); | |
58 | } |
|
60 | } | |
59 |
|
61 | |||
60 | if (axisXChanged || axisYChanged) |
|
62 | if (axisXChanged || axisYChanged) | |
61 | emit updated(); |
|
63 | emit updated(); | |
62 | } |
|
64 | } | |
63 |
|
65 | |||
64 | void XLogYDomain::zoomIn(const QRectF &rect) |
|
66 | void XLogYDomain::zoomIn(const QRectF &rect) | |
65 | { |
|
67 | { | |
66 | qreal dx = spanX() / m_size.width(); |
|
68 | qreal dx = spanX() / m_size.width(); | |
67 | qreal maxX = m_maxX; |
|
69 | qreal maxX = m_maxX; | |
68 | qreal minX = m_minX; |
|
70 | qreal minX = m_minX; | |
69 |
|
71 | |||
70 | maxX = minX + dx * rect.right(); |
|
72 | maxX = minX + dx * rect.right(); | |
71 | minX = minX + dx * rect.left(); |
|
73 | minX = minX + dx * rect.left(); | |
72 |
|
74 | |||
73 | qreal newLogMinY = m_logMaxY - rect.bottom() * (m_logMaxY - m_logMinY) / m_size.height(); |
|
75 | qreal newLogMinY = m_logMaxY - rect.bottom() * (m_logMaxY - m_logMinY) / m_size.height(); | |
74 | qreal newLogMaxY = m_logMaxY - rect.top() * (m_logMaxY - m_logMinY) / m_size.height(); |
|
76 | qreal newLogMaxY = m_logMaxY - rect.top() * (m_logMaxY - m_logMinY) / m_size.height(); | |
75 | qreal minY = qPow(m_logBaseY, newLogMinY); |
|
77 | qreal minY = qPow(m_logBaseY, newLogMinY); | |
76 | qreal maxY = qPow(m_logBaseY, newLogMaxY); |
|
78 | qreal maxY = qPow(m_logBaseY, newLogMaxY); | |
77 |
|
79 | |||
78 | setRange(minX, maxX, minY, maxY); |
|
80 | setRange(minX, maxX, minY, maxY); | |
79 | } |
|
81 | } | |
80 |
|
82 | |||
81 | void XLogYDomain::zoomOut(const QRectF &rect) |
|
83 | void XLogYDomain::zoomOut(const QRectF &rect) | |
82 | { |
|
84 | { | |
83 | qreal dx = spanX() / rect.width(); |
|
85 | qreal dx = spanX() / rect.width(); | |
84 | qreal maxX = m_maxX; |
|
86 | qreal maxX = m_maxX; | |
85 | qreal minX = m_minX; |
|
87 | qreal minX = m_minX; | |
86 |
|
88 | |||
87 | minX = maxX - dx * rect.right(); |
|
89 | minX = maxX - dx * rect.right(); | |
88 | maxX = minX + dx * m_size.width(); |
|
90 | maxX = minX + dx * m_size.width(); | |
89 |
|
91 | |||
90 | qreal ratioY = m_size.height()/rect.height(); |
|
92 | qreal ratioY = m_size.height()/rect.height(); | |
91 | qreal newLogMinY = m_logMaxY - (m_logMaxY - m_logMinY) / ratioY; |
|
93 | qreal newLogMinY = m_logMaxY - (m_logMaxY - m_logMinY) / ratioY; | |
92 | qreal newLogMaxY = m_logMaxY + (m_logMaxY - m_logMinY) / ratioY; |
|
94 | qreal newLogMaxY = m_logMaxY + (m_logMaxY - m_logMinY) / ratioY; | |
93 | qreal minY = qPow(m_logBaseY, newLogMinY); |
|
95 | qreal minY = qPow(m_logBaseY, newLogMinY); | |
94 | qreal maxY = qPow(m_logBaseY, newLogMaxY); |
|
96 | qreal maxY = qPow(m_logBaseY, newLogMaxY); | |
95 |
|
97 | |||
96 | setRange(minX, maxX, minY, maxY); |
|
98 | setRange(minX, maxX, minY, maxY); | |
97 | } |
|
99 | } | |
98 |
|
100 | |||
99 | void XLogYDomain::move(qreal dx, qreal dy) |
|
101 | void XLogYDomain::move(qreal dx, qreal dy) | |
100 | { |
|
102 | { | |
101 | qreal x = spanX() / m_size.width(); |
|
103 | qreal x = spanX() / m_size.width(); | |
102 | qreal maxX = m_maxX; |
|
104 | qreal maxX = m_maxX; | |
103 | qreal minX = m_minX; |
|
105 | qreal minX = m_minX; | |
104 |
|
106 | |||
105 | if (dx != 0) { |
|
107 | if (dx != 0) { | |
106 | minX = minX + x * dx; |
|
108 | minX = minX + x * dx; | |
107 | maxX = maxX + x * dx; |
|
109 | maxX = maxX + x * dx; | |
108 | } |
|
110 | } | |
109 |
|
111 | |||
110 | qreal stepY = dy * qAbs(m_logMaxY - m_logMinY) / m_size.height(); |
|
112 | qreal stepY = dy * qAbs(m_logMaxY - m_logMinY) / m_size.height(); | |
111 | qreal minY = qPow(m_logBaseY, m_logMinY + stepY); |
|
113 | qreal minY = qPow(m_logBaseY, m_logMinY + stepY); | |
112 | qreal maxY = qPow(m_logBaseY, m_logMaxY + stepY); |
|
114 | qreal maxY = qPow(m_logBaseY, m_logMaxY + stepY); | |
113 |
|
115 | |||
114 | setRange(minX, maxX, minY, maxY); |
|
116 | setRange(minX, maxX, minY, maxY); | |
115 | } |
|
117 | } | |
116 |
|
118 | |||
117 | QPointF XLogYDomain::calculateGeometryPoint(const QPointF &point) const |
|
119 | QPointF XLogYDomain::calculateGeometryPoint(const QPointF &point) const | |
118 | { |
|
120 | { | |
119 | const qreal leftEdge = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; |
|
121 | const qreal leftEdge = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; | |
120 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
122 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); | |
121 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); |
|
123 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); | |
122 |
|
124 | |||
123 | qreal x = (point.x() - m_minX) * deltaX; |
|
125 | qreal x = (point.x() - m_minX) * deltaX; | |
124 | qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - leftEdge * -deltaY + m_size.height(); |
|
126 | qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - leftEdge * -deltaY + m_size.height(); | |
125 | return QPointF(x, y); |
|
127 | return QPointF(x, y); | |
126 | } |
|
128 | } | |
127 |
|
129 | |||
128 | QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const |
|
130 | QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QList<QPointF>& vector) const | |
129 | { |
|
131 | { | |
130 | const qreal leftEdge = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; |
|
132 | const qreal leftEdge = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; | |
131 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
133 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); | |
132 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); |
|
134 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); | |
133 |
|
135 | |||
134 | QVector<QPointF> result; |
|
136 | QVector<QPointF> result; | |
135 | result.resize(vector.count()); |
|
137 | result.resize(vector.count()); | |
136 |
|
138 | |||
137 | for (int i = 0; i < vector.count(); ++i) { |
|
139 | for (int i = 0; i < vector.count(); ++i) { | |
138 | qreal x = (vector[i].x() - m_minX) * deltaX; |
|
140 | qreal x = (vector[i].x() - m_minX) * deltaX; | |
139 | qreal y = (log10(vector[i].y()) / log10(m_logBaseY)) * -deltaY - leftEdge * -deltaY + m_size.height(); |
|
141 | qreal y = (log10(vector[i].y()) / log10(m_logBaseY)) * -deltaY - leftEdge * -deltaY + m_size.height(); | |
140 | result[i].setX(x); |
|
142 | result[i].setX(x); | |
141 | result[i].setY(y); |
|
143 | result[i].setY(y); | |
142 | } |
|
144 | } | |
143 | return result; |
|
145 | return result; | |
144 | } |
|
146 | } | |
145 |
|
147 | |||
146 | QPointF XLogYDomain::calculateDomainPoint(const QPointF &point) const |
|
148 | QPointF XLogYDomain::calculateDomainPoint(const QPointF &point) const | |
147 | { |
|
149 | { | |
148 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); |
|
150 | const qreal deltaX = m_size.width() / (m_maxX - m_minX); | |
149 | const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; |
|
151 | const qreal leftEdgeY = m_logMinY < m_logMaxY ? m_logMinY : m_logMaxY; | |
150 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); |
|
152 | const qreal deltaY = m_size.height() / qAbs(m_logMaxY - m_logMinY); | |
151 | qreal x = point.x() / deltaX + m_minX; |
|
153 | qreal x = point.x() / deltaX + m_minX; | |
152 | qreal y = qPow(m_logBaseY, leftEdgeY + (m_size.height() - point.y()) / deltaY); |
|
154 | qreal y = qPow(m_logBaseY, leftEdgeY + (m_size.height() - point.y()) / deltaY); | |
153 | return QPointF(x, y); |
|
155 | return QPointF(x, y); | |
154 | } |
|
156 | } | |
155 |
|
157 | |||
156 | // operators |
|
158 | // operators | |
157 |
|
159 | |||
158 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XLogYDomain &domain1, const XLogYDomain &domain2) |
|
160 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XLogYDomain &domain1, const XLogYDomain &domain2) | |
159 | { |
|
161 | { | |
160 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) && |
|
162 | return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) && | |
161 | qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) && |
|
163 | qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) && | |
162 | qFuzzyIsNull(domain1.m_minX - domain2.m_minX) && |
|
164 | qFuzzyIsNull(domain1.m_minX - domain2.m_minX) && | |
163 | qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); |
|
165 | qFuzzyIsNull(domain1.m_minY - domain2.m_minY)); | |
164 | } |
|
166 | } | |
165 |
|
167 | |||
166 |
|
168 | |||
167 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const XLogYDomain &domain1, const XLogYDomain &domain2) |
|
169 | bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const XLogYDomain &domain1, const XLogYDomain &domain2) | |
168 | { |
|
170 | { | |
169 | return !(domain1 == domain2); |
|
171 | return !(domain1 == domain2); | |
170 | } |
|
172 | } | |
171 |
|
173 | |||
172 |
|
174 | |||
173 | QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const XLogYDomain &domain) |
|
175 | QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const XLogYDomain &domain) | |
174 | { |
|
176 | { | |
175 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; |
|
177 | dbg.nospace() << "AbstractDomain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')' << domain.m_size; | |
176 | return dbg.maybeSpace(); |
|
178 | return dbg.maybeSpace(); | |
177 | } |
|
179 | } | |
178 |
|
180 | |||
179 | #include "moc_xlogydomain_p.cpp" |
|
181 | #include "moc_xlogydomain_p.cpp" | |
180 |
|
182 | |||
181 | QTCOMMERCIALCHART_END_NAMESPACE |
|
183 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now