@@ -1,379 +1,379 | |||||
1 | #include "chartdataset_p.h" |
|
1 | #include "chartdataset_p.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | //series |
|
3 | //series | |
4 | #include "qlineseries.h" |
|
4 | #include "qlineseries.h" | |
5 | #include "qbarseries.h" |
|
5 | #include "qbarseries.h" | |
6 | #include "qstackedbarseries.h" |
|
6 | #include "qstackedbarseries.h" | |
7 | #include "qpercentbarseries.h" |
|
7 | #include "qpercentbarseries.h" | |
8 | #include "qpieseries.h" |
|
8 | #include "qpieseries.h" | |
9 | #include "qscatterseries.h" |
|
9 | #include "qscatterseries.h" | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
12 |
|
12 | |||
13 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), |
|
13 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), | |
14 | m_axisX(new QChartAxis(this)), |
|
14 | m_axisX(new QChartAxis(this)), | |
15 | m_axisY(new QChartAxis(this)), |
|
15 | m_axisY(new QChartAxis(this)), | |
16 | m_domainIndex(0), |
|
16 | m_domainIndex(0), | |
17 | m_axisXInitialized(false) |
|
17 | m_axisXInitialized(false) | |
18 | { |
|
18 | { | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | ChartDataSet::~ChartDataSet() |
|
21 | ChartDataSet::~ChartDataSet() | |
22 | { |
|
22 | { | |
23 | // TODO Auto-generated destructor stub |
|
23 | // TODO Auto-generated destructor stub | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | const Domain ChartDataSet::domain(QChartAxis *axisY) const |
|
26 | const Domain ChartDataSet::domain(QChartAxis *axisY) const | |
27 | { |
|
27 | { | |
28 | int i = m_domainMap.count(axisY); |
|
28 | int i = m_domainMap.count(axisY); | |
29 | if(i == 0){ |
|
29 | if(i == 0){ | |
30 | return Domain(); |
|
30 | return Domain(); | |
31 | } |
|
31 | } | |
32 | i = i - m_domainIndex -1; |
|
32 | i = i - m_domainIndex -1; | |
33 | return m_domainMap.values(axisY).at(i); |
|
33 | return m_domainMap.values(axisY).at(i); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) |
|
36 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |
37 | { |
|
37 | { | |
38 | // TODO: we should check the series not already added |
|
38 | // TODO: we should check the series not already added | |
39 |
|
39 | |||
40 | series->setParent(this); // take ownership |
|
40 | series->setParent(this); // take ownership | |
41 | clearDomains(); |
|
41 | clearDomains(); | |
42 |
|
42 | |||
43 | if(axisY==0) axisY = m_axisY; |
|
43 | if(axisY==0) axisY = m_axisY; | |
44 | axisY->setParent(this); // take ownership |
|
44 | axisY->setParent(this); // take ownership | |
45 |
|
45 | |||
46 | QList<QSeries*> seriesList = m_seriesMap.values(axisY); |
|
46 | QList<QSeries*> seriesList = m_seriesMap.values(axisY); | |
47 |
|
47 | |||
48 | QList<Domain> domainList = m_domainMap.values(axisY); |
|
48 | QList<Domain> domainList = m_domainMap.values(axisY); | |
49 |
|
49 | |||
50 | Q_ASSERT(domainList.size()<=1); |
|
50 | Q_ASSERT(domainList.size()<=1); | |
51 |
|
51 | |||
52 | Domain domain; |
|
52 | Domain domain; | |
53 |
|
53 | |||
54 | if(domainList.size()>0) domain = domainList.at(0); |
|
54 | if(domainList.size()>0) domain = domainList.at(0); | |
55 |
|
55 | |||
56 | switch(series->type()) |
|
56 | switch(series->type()) | |
57 | { |
|
57 | { | |
58 | case QSeries::SeriesTypeLine: { |
|
58 | case QSeries::SeriesTypeLine: { | |
59 |
|
59 | |||
60 | QLineSeries* xyseries = static_cast<QLineSeries*>(series); |
|
60 | QLineSeries* xyseries = static_cast<QLineSeries*>(series); | |
61 |
|
61 | |||
62 | for (int i = 0; i < xyseries->count(); i++) |
|
62 | for (int i = 0; i < xyseries->count(); i++) | |
63 | { |
|
63 | { | |
64 | qreal x = xyseries->x(i); |
|
64 | qreal x = xyseries->x(i); | |
65 | qreal y = xyseries->y(i); |
|
65 | qreal y = xyseries->y(i); | |
66 | domain.m_minX = qMin(domain.m_minX,x); |
|
66 | domain.m_minX = qMin(domain.m_minX,x); | |
67 | domain.m_minY = qMin(domain.m_minY,y); |
|
67 | domain.m_minY = qMin(domain.m_minY,y); | |
68 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
68 | domain.m_maxX = qMax(domain.m_maxX,x); | |
69 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
69 | domain.m_maxY = qMax(domain.m_maxY,y); | |
70 | } |
|
70 | } | |
71 | break; |
|
71 | break; | |
72 | } |
|
72 | } | |
73 | case QSeries::SeriesTypeBar: { |
|
73 | case QSeries::SeriesTypeBar: { | |
74 | qDebug() << "QChartSeries::SeriesTypeBar"; |
|
74 | qDebug() << "QChartSeries::SeriesTypeBar"; | |
75 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
75 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
76 | qreal x = barSeries->categoryCount(); |
|
76 | qreal x = barSeries->categoryCount(); | |
77 | qreal y = barSeries->max(); |
|
77 | qreal y = barSeries->max(); | |
78 | domain.m_minX = qMin(domain.m_minX,x); |
|
78 | domain.m_minX = qMin(domain.m_minX,x); | |
79 | domain.m_minY = qMin(domain.m_minY,y); |
|
79 | domain.m_minY = qMin(domain.m_minY,y); | |
80 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
80 | domain.m_maxX = qMax(domain.m_maxX,x); | |
81 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
81 | domain.m_maxY = qMax(domain.m_maxY,y); | |
82 | break; |
|
82 | break; | |
83 | } |
|
83 | } | |
84 | case QSeries::SeriesTypeStackedBar: { |
|
84 | case QSeries::SeriesTypeStackedBar: { | |
85 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; |
|
85 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; | |
86 |
|
86 | |||
87 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
87 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
88 | qreal x = stackedBarSeries->categoryCount(); |
|
88 | qreal x = stackedBarSeries->categoryCount(); | |
89 | qreal y = stackedBarSeries->maxCategorySum(); |
|
89 | qreal y = stackedBarSeries->maxCategorySum(); | |
90 | domain.m_minX = qMin(domain.m_minX,x); |
|
90 | domain.m_minX = qMin(domain.m_minX,x); | |
91 | domain.m_minY = qMin(domain.m_minY,y); |
|
91 | domain.m_minY = qMin(domain.m_minY,y); | |
92 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
92 | domain.m_maxX = qMax(domain.m_maxX,x); | |
93 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
93 | domain.m_maxY = qMax(domain.m_maxY,y); | |
94 | break; |
|
94 | break; | |
95 | } |
|
95 | } | |
96 | case QSeries::SeriesTypePercentBar: { |
|
96 | case QSeries::SeriesTypePercentBar: { | |
97 | qDebug() << "QChartSeries::SeriesTypePercentBar"; |
|
97 | qDebug() << "QChartSeries::SeriesTypePercentBar"; | |
98 |
|
98 | |||
99 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
99 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
100 | qreal x = percentBarSeries->categoryCount(); |
|
100 | qreal x = percentBarSeries->categoryCount(); | |
101 | domain.m_minX = qMin(domain.m_minX,x); |
|
101 | domain.m_minX = qMin(domain.m_minX,x); | |
102 | domain.m_minY = 0; |
|
102 | domain.m_minY = 0; | |
103 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
103 | domain.m_maxX = qMax(domain.m_maxX,x); | |
104 | domain.m_maxY = 100; |
|
104 | domain.m_maxY = 100; | |
105 | break; |
|
105 | break; | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | case QSeries::SeriesTypePie: { |
|
108 | case QSeries::SeriesTypePie: { | |
109 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
109 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
110 | // TODO: domain stuff |
|
110 | // TODO: domain stuff | |
111 | break; |
|
111 | break; | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | case QSeries::SeriesTypeScatter: { |
|
114 | case QSeries::SeriesTypeScatter: { | |
115 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
115 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
116 | Q_ASSERT(scatterSeries); |
|
116 | Q_ASSERT(scatterSeries); | |
117 | foreach (QPointF point, scatterSeries->data()) { |
|
117 | foreach (QPointF point, scatterSeries->data()) { | |
118 | domain.m_minX = qMin(domain.m_minX, point.x()); |
|
118 | domain.m_minX = qMin(domain.m_minX, point.x()); | |
119 | domain.m_maxX = qMax(domain.m_maxX, point.x()); |
|
119 | domain.m_maxX = qMax(domain.m_maxX, point.x()); | |
120 | domain.m_minY = qMin(domain.m_minY, point.y()); |
|
120 | domain.m_minY = qMin(domain.m_minY, point.y()); | |
121 | domain.m_maxY = qMax(domain.m_maxY, point.y()); |
|
121 | domain.m_maxY = qMax(domain.m_maxY, point.y()); | |
122 | } |
|
122 | } | |
123 | break; |
|
123 | break; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | default: { |
|
126 | default: { | |
127 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
127 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; | |
128 | return; |
|
128 | return; | |
129 | break; |
|
129 | break; | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | if(!m_domainMap.contains(axisY)) |
|
134 | if(!m_domainMap.contains(axisY)) | |
135 | { |
|
135 | { | |
136 | emit axisAdded(axisY); |
|
136 | emit axisAdded(axisY); | |
137 | QObject::connect(axisY,SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*))); |
|
137 | QObject::connect(axisY,SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*))); | |
138 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
138 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | if(!m_axisXInitialized) |
|
141 | if(!m_axisXInitialized) | |
142 | { |
|
142 | { | |
143 | emit axisAdded(axisX()); |
|
143 | emit axisAdded(axisX()); | |
144 | QObject::connect(axisX(),SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*))); |
|
144 | QObject::connect(axisX(),SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*))); | |
145 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
145 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
146 | m_axisXInitialized=true; |
|
146 | m_axisXInitialized=true; | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | m_domainMap.replace(axisY,domain); |
|
149 | m_domainMap.replace(axisY,domain); | |
150 | m_seriesMap.insert(axisY,series); |
|
150 | m_seriesMap.insert(axisY,series); | |
151 | emit seriesAdded(series); |
|
151 | emit seriesAdded(series); | |
152 | setDomain(m_domainIndex); |
|
152 | setDomain(m_domainIndex); | |
153 |
|
153 | |||
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void ChartDataSet::removeSeries(QSeries* series) |
|
156 | void ChartDataSet::removeSeries(QSeries* series) | |
157 | { |
|
157 | { | |
158 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
158 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
159 | foreach(QChartAxis* axis , keys) { |
|
159 | foreach(QChartAxis* axis , keys) { | |
160 | if(m_seriesMap.contains(axis,series)){ |
|
160 | if(m_seriesMap.contains(axis,series)){ | |
161 | emit seriesRemoved(series); |
|
161 | emit seriesRemoved(series); | |
162 | m_seriesMap.remove(axis,series); |
|
162 | m_seriesMap.remove(axis,series); | |
163 | //remove axis if no longer there |
|
163 | //remove axis if no longer there | |
164 | if(!m_seriesMap.contains(axis)){ |
|
164 | if(!m_seriesMap.contains(axis)){ | |
165 | emit axisRemoved(axis); |
|
165 | emit axisRemoved(axis); | |
166 | m_domainMap.remove(axis); |
|
166 | m_domainMap.remove(axis); | |
167 | if(axis != m_axisY) |
|
167 | if(axis != m_axisY) | |
168 | delete axis; |
|
168 | delete axis; | |
169 | } |
|
169 | } | |
170 | series->setParent(0); |
|
170 | series->setParent(0); | |
171 | break; |
|
171 | break; | |
172 | } |
|
172 | } | |
173 | } |
|
173 | } | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void ChartDataSet::removeAllSeries() |
|
176 | void ChartDataSet::removeAllSeries() | |
177 | { |
|
177 | { | |
178 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
178 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
179 | foreach(QChartAxis* axis , keys) { |
|
179 | foreach(QChartAxis* axis , keys) { | |
180 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
180 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
181 | for(int i =0 ; i < seriesList.size();i++ ) |
|
181 | for(int i =0 ; i < seriesList.size();i++ ) | |
182 | { |
|
182 | { | |
183 | emit seriesRemoved(seriesList.at(i)); |
|
183 | emit seriesRemoved(seriesList.at(i)); | |
184 | delete(seriesList.at(i)); |
|
184 | delete(seriesList.at(i)); | |
185 | } |
|
185 | } | |
186 | m_seriesMap.remove(axis); |
|
186 | m_seriesMap.remove(axis); | |
187 | m_domainMap.remove(axis); |
|
187 | m_domainMap.remove(axis); | |
188 | emit axisRemoved(axis); |
|
188 | emit axisRemoved(axis); | |
189 | if(axis != m_axisY) delete axis; |
|
189 | if(axis != m_axisY) delete axis; | |
190 | } |
|
190 | } | |
191 | m_domainIndex=0; |
|
191 | m_domainIndex=0; | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | bool ChartDataSet::nextDomain() |
|
194 | bool ChartDataSet::nextDomain() | |
195 | { |
|
195 | { | |
196 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; |
|
196 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; | |
197 |
|
197 | |||
198 | if (m_domainIndex < limit) { |
|
198 | if (m_domainIndex < limit) { | |
199 | m_domainIndex++; |
|
199 | m_domainIndex++; | |
200 | setDomain(m_domainIndex); |
|
200 | setDomain(m_domainIndex); | |
201 | return true; |
|
201 | return true; | |
202 | } |
|
202 | } | |
203 | else { |
|
203 | else { | |
204 | return false; |
|
204 | return false; | |
205 | } |
|
205 | } | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | bool ChartDataSet::previousDomain() |
|
208 | bool ChartDataSet::previousDomain() | |
209 | { |
|
209 | { | |
210 | if (m_domainIndex > 0) { |
|
210 | if (m_domainIndex > 0) { | |
211 | m_domainIndex--; |
|
211 | m_domainIndex--; | |
212 | setDomain(m_domainIndex); |
|
212 | setDomain(m_domainIndex); | |
213 | return true; |
|
213 | return true; | |
214 | } |
|
214 | } | |
215 | else { |
|
215 | else { | |
216 | return false; |
|
216 | return false; | |
217 | } |
|
217 | } | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | void ChartDataSet::setDomain(int index) |
|
220 | void ChartDataSet::setDomain(int index) | |
221 | { |
|
221 | { | |
222 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
222 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
223 |
|
223 | |||
224 | if(domainList.count()==0) return; |
|
224 | if(domainList.count()==0) return; | |
225 |
|
225 | |||
226 | Domain domain; |
|
226 | Domain domain; | |
227 |
|
227 | |||
228 | foreach (QChartAxis* axis , domainList) { |
|
228 | foreach (QChartAxis* axis , domainList) { | |
229 | int i = m_domainMap.count(axis) - index -1; |
|
229 | int i = m_domainMap.count(axis) - index -1; | |
230 | Q_ASSERT(i>=0); |
|
230 | Q_ASSERT(i>=0); | |
231 | domain = m_domainMap.values(axis).at(i); |
|
231 | domain = m_domainMap.values(axis).at(i); | |
232 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
232 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
233 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
233 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
234 | foreach(QSeries* series, seriesList) { |
|
234 | foreach(QSeries* series, seriesList) { | |
235 | emit seriesDomainChanged(series,domain); |
|
235 | emit seriesDomainChanged(series,domain); | |
236 | } |
|
236 | } | |
237 |
axis-> |
|
237 | axis->updateRange(domain.m_minY,domain.m_maxY); | |
238 | emit axisRangeChanged(axis,labels); |
|
238 | emit axisRangeChanged(axis,labels); | |
239 |
|
239 | |||
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
242 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
243 |
axisX()-> |
|
243 | axisX()->updateRange(domain.m_minX,domain.m_maxY); | |
244 | emit axisRangeChanged(axisX(),labels); |
|
244 | emit axisRangeChanged(axisX(),labels); | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | void ChartDataSet::clearDomains(int toIndex) |
|
247 | void ChartDataSet::clearDomains(int toIndex) | |
248 | { |
|
248 | { | |
249 | Q_ASSERT(toIndex>=0); |
|
249 | Q_ASSERT(toIndex>=0); | |
250 |
|
250 | |||
251 | m_domainIndex = toIndex; |
|
251 | m_domainIndex = toIndex; | |
252 |
|
252 | |||
253 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); |
|
253 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); | |
254 |
|
254 | |||
255 | foreach (QChartAxis* key , keys) |
|
255 | foreach (QChartAxis* key , keys) | |
256 | { |
|
256 | { | |
257 | QList<Domain> domains = m_domainMap.values(key); |
|
257 | QList<Domain> domains = m_domainMap.values(key); | |
258 | m_domainMap.remove(key); |
|
258 | m_domainMap.remove(key); | |
259 | int i = domains.size() - toIndex - 1; |
|
259 | int i = domains.size() - toIndex - 1; | |
260 | while(i--){ |
|
260 | while(i--){ | |
261 | domains.removeFirst(); |
|
261 | domains.removeFirst(); | |
262 | } |
|
262 | } | |
263 | for(int j=domains.size()-1; j>=0 ;j--) |
|
263 | for(int j=domains.size()-1; j>=0 ;j--) | |
264 | m_domainMap.insert(key,domains.at(j)); |
|
264 | m_domainMap.insert(key,domains.at(j)); | |
265 | } |
|
265 | } | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) |
|
268 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) | |
269 | { |
|
269 | { | |
270 | Q_ASSERT(rect.isValid()); |
|
270 | Q_ASSERT(rect.isValid()); | |
271 | Q_ASSERT(viewport.isValid()); |
|
271 | Q_ASSERT(viewport.isValid()); | |
272 |
|
272 | |||
273 | clearDomains(m_domainIndex); |
|
273 | clearDomains(m_domainIndex); | |
274 |
|
274 | |||
275 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
275 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
276 |
|
276 | |||
277 | Domain domain; |
|
277 | Domain domain; | |
278 |
|
278 | |||
279 | foreach (QChartAxis* axis , domainList){ |
|
279 | foreach (QChartAxis* axis , domainList){ | |
280 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); |
|
280 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); | |
281 | m_domainMap.insert(axis,domain); |
|
281 | m_domainMap.insert(axis,domain); | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | setDomain(++m_domainIndex); |
|
284 | setDomain(++m_domainIndex); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | QChartAxis* ChartDataSet::axisY(QSeries* series) const |
|
287 | QChartAxis* ChartDataSet::axisY(QSeries* series) const | |
288 | { |
|
288 | { | |
289 | if(series == 0) return m_axisY; |
|
289 | if(series == 0) return m_axisY; | |
290 |
|
290 | |||
291 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
291 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
292 |
|
292 | |||
293 | foreach(QChartAxis* axis , keys) { |
|
293 | foreach(QChartAxis* axis , keys) { | |
294 | if(m_seriesMap.contains(axis,series)){ |
|
294 | if(m_seriesMap.contains(axis,series)){ | |
295 | return axis; |
|
295 | return axis; | |
296 | } |
|
296 | } | |
297 | } |
|
297 | } | |
298 | return 0; |
|
298 | return 0; | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) |
|
301 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) | |
302 | { |
|
302 | { | |
303 | Q_ASSERT(max>=min); |
|
303 | Q_ASSERT(max>=min); | |
304 |
|
304 | |||
305 | QStringList labels; |
|
305 | QStringList labels; | |
306 |
|
306 | |||
307 | int ticks = axis->ticksCount()-1; |
|
307 | int ticks = axis->ticksCount()-1; | |
308 |
|
308 | |||
309 | for(int i=0; i<= ticks; i++){ |
|
309 | for(int i=0; i<= ticks; i++){ | |
310 | qreal value = min + (i * (max - min)/ ticks); |
|
310 | qreal value = min + (i * (max - min)/ ticks); | |
311 | QString label = axis->axisTickLabel(value); |
|
311 | QString label = axis->axisTickLabel(value); | |
312 | if(label.isEmpty()){ |
|
312 | if(label.isEmpty()){ | |
313 | labels << QString::number(value); |
|
313 | labels << QString::number(value); | |
314 | }else{ |
|
314 | }else{ | |
315 | labels << label; |
|
315 | labels << label; | |
316 | } |
|
316 | } | |
317 | } |
|
317 | } | |
318 | return labels; |
|
318 | return labels; | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 |
|
321 | |||
322 | void ChartDataSet::handleRangeChanged(QChartAxis* axis) |
|
322 | void ChartDataSet::handleRangeChanged(QChartAxis* axis) | |
323 | { |
|
323 | { | |
324 | qreal min = axis->min(); |
|
324 | qreal min = axis->min(); | |
325 | qreal max = axis->max(); |
|
325 | qreal max = axis->max(); | |
326 |
|
326 | |||
327 | if(axis==axisX()) { |
|
327 | if(axis==axisX()) { | |
328 |
|
328 | |||
329 | m_domainIndex=0; |
|
329 | m_domainIndex=0; | |
330 |
|
330 | |||
331 | clearDomains(m_domainIndex); |
|
331 | clearDomains(m_domainIndex); | |
332 |
|
332 | |||
333 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
333 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
334 |
|
334 | |||
335 | foreach (QChartAxis* axis , domainList) { |
|
335 | foreach (QChartAxis* axis , domainList) { | |
336 |
|
336 | |||
337 | Q_ASSERT(m_domainMap.values(axis).size()==1); |
|
337 | Q_ASSERT(m_domainMap.values(axis).size()==1); | |
338 |
|
338 | |||
339 | Domain domain = m_domainMap.value(axis); |
|
339 | Domain domain = m_domainMap.value(axis); | |
340 | domain.m_minX=min; |
|
340 | domain.m_minX=min; | |
341 | domain.m_maxX=max; |
|
341 | domain.m_maxX=max; | |
342 | m_domainMap.replace(axis,domain); |
|
342 | m_domainMap.replace(axis,domain); | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | } |
|
345 | } | |
346 | else { |
|
346 | else { | |
347 |
|
347 | |||
348 | QList<Domain> domains = m_domainMap.values(axis); |
|
348 | QList<Domain> domains = m_domainMap.values(axis); | |
349 | m_domainMap.remove(axis); |
|
349 | m_domainMap.remove(axis); | |
350 |
|
350 | |||
351 | for(int i=0;i<domains.size();i++) |
|
351 | for(int i=0;i<domains.size();i++) | |
352 | { |
|
352 | { | |
353 | domains[i].m_minY=min; |
|
353 | domains[i].m_minY=min; | |
354 | domains[i].m_maxY=max; |
|
354 | domains[i].m_maxY=max; | |
355 | } |
|
355 | } | |
356 |
|
356 | |||
357 | for(int j=domains.size()-1; j>=0;j--) |
|
357 | for(int j=domains.size()-1; j>=0;j--) | |
358 | m_domainMap.insert(axis,domains.at(j)); |
|
358 | m_domainMap.insert(axis,domains.at(j)); | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | setDomain(m_domainIndex); |
|
361 | setDomain(m_domainIndex); | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | void ChartDataSet::handleTickChanged(QChartAxis* axis) |
|
364 | void ChartDataSet::handleTickChanged(QChartAxis* axis) | |
365 | { |
|
365 | { | |
366 | if(axis==axisX()){ |
|
366 | if(axis==axisX()){ | |
367 | Domain domain = m_domainMap.value(axisY()); |
|
367 | Domain domain = m_domainMap.value(axisY()); | |
368 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); |
|
368 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); | |
369 | emit axisRangeChanged(axis,labels); |
|
369 | emit axisRangeChanged(axis,labels); | |
370 | }else{ |
|
370 | }else{ | |
371 | Domain domain = m_domainMap.value(axis); |
|
371 | Domain domain = m_domainMap.value(axis); | |
372 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
372 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
373 | emit axisRangeChanged(axis,labels); |
|
373 | emit axisRangeChanged(axis,labels); | |
374 | } |
|
374 | } | |
375 | } |
|
375 | } | |
376 |
|
376 | |||
377 | #include "moc_chartdataset_p.cpp" |
|
377 | #include "moc_chartdataset_p.cpp" | |
378 |
|
378 | |||
379 | QTCOMMERCIALCHART_END_NAMESPACE |
|
379 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now