@@ -1,357 +1,359 | |||||
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(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); |
|
137 | QObject::connect(axisY,SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); | |
138 | QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); |
|
138 | QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); | |
139 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
139 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
140 | } |
|
140 | } | |
141 | m_domainMap.replace(axisY,domain); |
|
141 | m_domainMap.replace(axisY,domain); | |
142 | m_seriesMap.insert(axisY,series); |
|
142 | m_seriesMap.insert(axisY,series); | |
143 |
|
143 | |||
144 | if(!m_axisXInitialized) |
|
144 | if(!m_axisXInitialized) | |
145 | { |
|
145 | { | |
146 | emit axisAdded(axisX()); |
|
146 | emit axisAdded(axisX()); | |
147 | QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); |
|
147 | QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); | |
148 | QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); |
|
148 | QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); | |
149 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
149 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
150 | m_axisXInitialized=true; |
|
150 | m_axisXInitialized=true; | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 |
|
153 | |||
154 | emit seriesAdded(series); |
|
154 | emit seriesAdded(series); | |
155 | QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY); |
|
155 | QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY); | |
156 | QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
156 | QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
157 | emit axisLabelsChanged(axisY,ylabels); |
|
157 | emit axisLabelsChanged(axisY,ylabels); | |
158 | emit axisLabelsChanged(axisX(),xlabels); |
|
158 | emit axisLabelsChanged(axisX(),xlabels); | |
159 | emit seriesDomainChanged(series,domain); |
|
159 | emit seriesDomainChanged(series,domain); | |
160 |
|
160 | |||
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | void ChartDataSet::removeSeries(QSeries* series) |
|
163 | void ChartDataSet::removeSeries(QSeries* series) | |
164 | { |
|
164 | { | |
165 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
165 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
166 | foreach(QChartAxis* axis , keys) { |
|
166 | foreach(QChartAxis* axis , keys) { | |
167 | if(m_seriesMap.contains(axis,series)){ |
|
167 | if(m_seriesMap.contains(axis,series)){ | |
168 | emit seriesRemoved(series); |
|
168 | emit seriesRemoved(series); | |
169 | m_seriesMap.remove(axis,series); |
|
169 | m_seriesMap.remove(axis,series); | |
170 | //remove axis if no longer there |
|
170 | //remove axis if no longer there | |
171 | if(!m_seriesMap.contains(axis)){ |
|
171 | if(!m_seriesMap.contains(axis)){ | |
172 | emit axisRemoved(axis); |
|
172 | emit axisRemoved(axis); | |
173 | m_domainMap.remove(axis); |
|
173 | m_domainMap.remove(axis); | |
174 | if(axis != m_axisY) |
|
174 | if(axis != m_axisY) | |
175 | delete axis; |
|
175 | delete axis; | |
176 | } |
|
176 | } | |
177 | series->setParent(0); |
|
177 | series->setParent(0); | |
178 | break; |
|
178 | break; | |
179 | } |
|
179 | } | |
180 | } |
|
180 | } | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | void ChartDataSet::removeAllSeries() |
|
183 | void ChartDataSet::removeAllSeries() | |
184 | { |
|
184 | { | |
185 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
185 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
186 | foreach(QChartAxis* axis , keys) { |
|
186 | foreach(QChartAxis* axis , keys) { | |
187 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
187 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
188 | for(int i =0 ; i < seriesList.size();i++ ) |
|
188 | for(int i =0 ; i < seriesList.size();i++ ) | |
189 | { |
|
189 | { | |
190 | emit seriesRemoved(seriesList.at(i)); |
|
190 | emit seriesRemoved(seriesList.at(i)); | |
191 | delete(seriesList.at(i)); |
|
191 | delete(seriesList.at(i)); | |
192 | } |
|
192 | } | |
193 | m_seriesMap.remove(axis); |
|
193 | m_seriesMap.remove(axis); | |
194 | m_domainMap.remove(axis); |
|
194 | m_domainMap.remove(axis); | |
195 | emit axisRemoved(axis); |
|
195 | emit axisRemoved(axis); | |
196 | if(axis != m_axisY) delete axis; |
|
196 | if(axis != m_axisY) delete axis; | |
197 | } |
|
197 | } | |
198 | m_domainIndex=0; |
|
198 | m_domainIndex=0; | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | bool ChartDataSet::nextDomain() |
|
201 | bool ChartDataSet::nextDomain() | |
202 | { |
|
202 | { | |
203 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; |
|
203 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; | |
204 |
|
204 | |||
205 | if (m_domainIndex < limit) { |
|
205 | if (m_domainIndex < limit) { | |
206 | m_domainIndex++; |
|
206 | m_domainIndex++; | |
207 | setDomain(m_domainIndex); |
|
207 | setDomain(m_domainIndex); | |
208 | return true; |
|
208 | return true; | |
209 | } |
|
209 | } | |
210 | else { |
|
210 | else { | |
211 | return false; |
|
211 | return false; | |
212 | } |
|
212 | } | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | bool ChartDataSet::previousDomain() |
|
215 | bool ChartDataSet::previousDomain() | |
216 | { |
|
216 | { | |
217 | if (m_domainIndex > 0) { |
|
217 | if (m_domainIndex > 0) { | |
218 | m_domainIndex--; |
|
218 | m_domainIndex--; | |
219 | setDomain(m_domainIndex); |
|
219 | setDomain(m_domainIndex); | |
220 | return true; |
|
220 | return true; | |
221 | } |
|
221 | } | |
222 | else { |
|
222 | else { | |
223 | return false; |
|
223 | return false; | |
224 | } |
|
224 | } | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | void ChartDataSet::setDomain(int index) |
|
227 | void ChartDataSet::setDomain(int index) | |
228 | { |
|
228 | { | |
229 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
229 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
230 |
|
230 | |||
|
231 | if(domainList.count()==0) return; | |||
|
232 | ||||
231 | Domain domain; |
|
233 | Domain domain; | |
232 |
|
234 | |||
233 | foreach (QChartAxis* axis , domainList) { |
|
235 | foreach (QChartAxis* axis , domainList) { | |
234 | int i = m_domainMap.count(axis) - index -1; |
|
236 | int i = m_domainMap.count(axis) - index -1; | |
235 | Q_ASSERT(i>=0); |
|
237 | Q_ASSERT(i>=0); | |
236 | domain = m_domainMap.values(axis).at(i); |
|
238 | domain = m_domainMap.values(axis).at(i); | |
237 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
239 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
238 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
240 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
239 | foreach(QSeries* series, seriesList) { |
|
241 | foreach(QSeries* series, seriesList) { | |
240 | emit seriesDomainChanged(series,domain); |
|
242 | emit seriesDomainChanged(series,domain); | |
241 | } |
|
243 | } | |
242 | emit axisLabelsChanged(axis,labels); |
|
244 | emit axisLabelsChanged(axis,labels); | |
243 | } |
|
245 | } | |
244 |
|
246 | |||
245 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
247 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
246 | emit axisLabelsChanged(axisX(),labels); |
|
248 | emit axisLabelsChanged(axisX(),labels); | |
247 | } |
|
249 | } | |
248 |
|
250 | |||
249 | void ChartDataSet::clearDomains(int toIndex) |
|
251 | void ChartDataSet::clearDomains(int toIndex) | |
250 | { |
|
252 | { | |
251 | Q_ASSERT(toIndex>=0); |
|
253 | Q_ASSERT(toIndex>=0); | |
252 |
|
254 | |||
253 | m_domainIndex = toIndex; |
|
255 | m_domainIndex = toIndex; | |
254 |
|
256 | |||
255 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); |
|
257 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); | |
256 |
|
258 | |||
257 | foreach (QChartAxis* key , keys) |
|
259 | foreach (QChartAxis* key , keys) | |
258 | { |
|
260 | { | |
259 | QList<Domain> domains = m_domainMap.values(key); |
|
261 | QList<Domain> domains = m_domainMap.values(key); | |
260 | m_domainMap.remove(key); |
|
262 | m_domainMap.remove(key); | |
261 | int i = domains.size() - toIndex - 1; |
|
263 | int i = domains.size() - toIndex - 1; | |
262 | while(i--){ |
|
264 | while(i--){ | |
263 | domains.removeFirst(); |
|
265 | domains.removeFirst(); | |
264 | } |
|
266 | } | |
265 | for(int j=domains.size()-1; j>=0 ;j--) |
|
267 | for(int j=domains.size()-1; j>=0 ;j--) | |
266 | m_domainMap.insert(key,domains.at(j)); |
|
268 | m_domainMap.insert(key,domains.at(j)); | |
267 | } |
|
269 | } | |
268 | } |
|
270 | } | |
269 |
|
271 | |||
270 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) |
|
272 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) | |
271 | { |
|
273 | { | |
272 | Q_ASSERT(rect.isValid()); |
|
274 | Q_ASSERT(rect.isValid()); | |
273 | Q_ASSERT(viewport.isValid()); |
|
275 | Q_ASSERT(viewport.isValid()); | |
274 |
|
276 | |||
275 | clearDomains(m_domainIndex); |
|
277 | clearDomains(m_domainIndex); | |
276 |
|
278 | |||
277 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
279 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
278 |
|
280 | |||
279 | Domain domain; |
|
281 | Domain domain; | |
280 |
|
282 | |||
281 | foreach (QChartAxis* axis , domainList){ |
|
283 | foreach (QChartAxis* axis , domainList){ | |
282 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); |
|
284 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); | |
283 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
285 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
284 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
286 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |
285 | foreach(QSeries* series, seriesList){ |
|
287 | foreach(QSeries* series, seriesList){ | |
286 | emit seriesDomainChanged(series,domain); |
|
288 | emit seriesDomainChanged(series,domain); | |
287 | } |
|
289 | } | |
288 | emit axisLabelsChanged(axis,labels); |
|
290 | emit axisLabelsChanged(axis,labels); | |
289 | m_domainMap.insert(axis,domain); |
|
291 | m_domainMap.insert(axis,domain); | |
290 | } |
|
292 | } | |
291 |
|
293 | |||
292 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
294 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
293 | emit axisLabelsChanged(axisX(),labels); |
|
295 | emit axisLabelsChanged(axisX(),labels); | |
294 |
|
296 | |||
295 | m_domainIndex++; |
|
297 | m_domainIndex++; | |
296 | } |
|
298 | } | |
297 |
|
299 | |||
298 | QChartAxis* ChartDataSet::axisY(QSeries* series) const |
|
300 | QChartAxis* ChartDataSet::axisY(QSeries* series) const | |
299 | { |
|
301 | { | |
300 | if(series == 0) return m_axisY; |
|
302 | if(series == 0) return m_axisY; | |
301 |
|
303 | |||
302 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
304 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
303 |
|
305 | |||
304 | foreach(QChartAxis* axis , keys) { |
|
306 | foreach(QChartAxis* axis , keys) { | |
305 | if(m_seriesMap.contains(axis,series)){ |
|
307 | if(m_seriesMap.contains(axis,series)){ | |
306 | return axis; |
|
308 | return axis; | |
307 | } |
|
309 | } | |
308 | } |
|
310 | } | |
309 | return 0; |
|
311 | return 0; | |
310 | } |
|
312 | } | |
311 |
|
313 | |||
312 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) |
|
314 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) | |
313 | { |
|
315 | { | |
314 | Q_ASSERT(max>=min); |
|
316 | Q_ASSERT(max>=min); | |
315 |
|
317 | |||
316 | QStringList labels; |
|
318 | QStringList labels; | |
317 |
|
319 | |||
318 | int ticks = axis->ticksCount()-1; |
|
320 | int ticks = axis->ticksCount()-1; | |
319 |
|
321 | |||
320 | for(int i=0; i<= ticks; i++){ |
|
322 | for(int i=0; i<= ticks; i++){ | |
321 | qreal value = min + (i * (max - min)/ ticks); |
|
323 | qreal value = min + (i * (max - min)/ ticks); | |
322 | QString label = axis->axisTickLabel(value); |
|
324 | QString label = axis->axisTickLabel(value); | |
323 | if(label.isEmpty()){ |
|
325 | if(label.isEmpty()){ | |
324 | labels << QString::number(value); |
|
326 | labels << QString::number(value); | |
325 | }else{ |
|
327 | }else{ | |
326 | labels << label; |
|
328 | labels << label; | |
327 | } |
|
329 | } | |
328 | } |
|
330 | } | |
329 | return labels; |
|
331 | return labels; | |
330 | } |
|
332 | } | |
331 |
|
333 | |||
332 |
|
334 | |||
333 | void ChartDataSet::handleMinChanged(qreal min) |
|
335 | void ChartDataSet::handleMinChanged(qreal min) | |
334 | { |
|
336 | { | |
335 |
|
337 | |||
336 | } |
|
338 | } | |
337 |
|
339 | |||
338 | void ChartDataSet::handleMaxChanged(qreal max) |
|
340 | void ChartDataSet::handleMaxChanged(qreal max) | |
339 | { |
|
341 | { | |
340 |
|
342 | |||
341 | } |
|
343 | } | |
342 |
|
344 | |||
343 | void ChartDataSet::handleTickChanged(QChartAxis* axis) |
|
345 | void ChartDataSet::handleTickChanged(QChartAxis* axis) | |
344 | { |
|
346 | { | |
345 | Domain domain = m_domainMap.value(axisY()); |
|
347 | Domain domain = m_domainMap.value(axisY()); | |
346 | if(axis==axisX()){ |
|
348 | if(axis==axisX()){ | |
347 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); |
|
349 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); | |
348 | emit axisLabelsChanged(axis,labels); |
|
350 | emit axisLabelsChanged(axis,labels); | |
349 | }else{ |
|
351 | }else{ | |
350 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
352 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
351 | emit axisLabelsChanged(axis,labels); |
|
353 | emit axisLabelsChanged(axis,labels); | |
352 | } |
|
354 | } | |
353 | } |
|
355 | } | |
354 |
|
356 | |||
355 | #include "moc_chartdataset_p.cpp" |
|
357 | #include "moc_chartdataset_p.cpp" | |
356 |
|
358 | |||
357 | QTCOMMERCIALCHART_END_NAMESPACE |
|
359 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now