@@ -1,333 +1,334 | |||||
1 | #include "chartdataset_p.h" |
|
1 | #include "chartdataset_p.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | //series |
|
3 | //series | |
4 | #include "qlinechartseries.h" |
|
4 | #include "qlinechartseries.h" | |
5 | #include "qbarchartseries.h" |
|
5 | #include "qbarchartseries.h" | |
6 | #include "qstackedbarchartseries.h" |
|
6 | #include "qstackedbarchartseries.h" | |
7 | #include "qpercentbarchartseries.h" |
|
7 | #include "qpercentbarchartseries.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(QChartSeries* series, QChartAxis *axisY) |
|
36 | void ChartDataSet::addSeries(QChartSeries* 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 | series->setParent(this); // take ownership |
|
39 | series->setParent(this); // take ownership | |
40 |
|
40 | |||
|
41 | series->setParent(this); // take ownership | |||
41 | clearDomains(); |
|
42 | clearDomains(); | |
42 |
|
43 | |||
43 | if(axisY==0) axisY = m_axisY; |
|
44 | if(axisY==0) axisY = m_axisY; | |
44 |
|
45 | |||
45 | QList<QChartSeries*> seriesList = m_seriesMap.values(axisY); |
|
46 | QList<QChartSeries*> seriesList = m_seriesMap.values(axisY); | |
46 |
|
47 | |||
47 | QList<Domain> domainList = m_domainMap.values(axisY); |
|
48 | QList<Domain> domainList = m_domainMap.values(axisY); | |
48 |
|
49 | |||
49 | Q_ASSERT(domainList.size()<=1); |
|
50 | Q_ASSERT(domainList.size()<=1); | |
50 |
|
51 | |||
51 | Domain domain; |
|
52 | Domain domain; | |
52 |
|
53 | |||
53 | if(domainList.size()>0) domain = domainList.at(0); |
|
54 | if(domainList.size()>0) domain = domainList.at(0); | |
54 |
|
55 | |||
55 | switch(series->type()) |
|
56 | switch(series->type()) | |
56 | { |
|
57 | { | |
57 | case QChartSeries::SeriesTypeLine: { |
|
58 | case QChartSeries::SeriesTypeLine: { | |
58 |
|
59 | |||
59 | QLineChartSeries* xyseries = static_cast<QLineChartSeries*>(series); |
|
60 | QLineChartSeries* xyseries = static_cast<QLineChartSeries*>(series); | |
60 |
|
61 | |||
61 | for (int i = 0; i < xyseries->count(); i++) |
|
62 | for (int i = 0; i < xyseries->count(); i++) | |
62 | { |
|
63 | { | |
63 | qreal x = xyseries->x(i); |
|
64 | qreal x = xyseries->x(i); | |
64 | qreal y = xyseries->y(i); |
|
65 | qreal y = xyseries->y(i); | |
65 | domain.m_minX = qMin(domain.m_minX,x); |
|
66 | domain.m_minX = qMin(domain.m_minX,x); | |
66 | domain.m_minY = qMin(domain.m_minY,y); |
|
67 | domain.m_minY = qMin(domain.m_minY,y); | |
67 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
68 | domain.m_maxX = qMax(domain.m_maxX,x); | |
68 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
69 | domain.m_maxY = qMax(domain.m_maxY,y); | |
69 | } |
|
70 | } | |
70 | break; |
|
71 | break; | |
71 | } |
|
72 | } | |
72 | case QChartSeries::SeriesTypeBar: { |
|
73 | case QChartSeries::SeriesTypeBar: { | |
73 | qDebug() << "QChartSeries::SeriesTypeBar"; |
|
74 | qDebug() << "QChartSeries::SeriesTypeBar"; | |
74 | QBarChartSeries* barSeries = static_cast<QBarChartSeries*>(series); |
|
75 | QBarChartSeries* barSeries = static_cast<QBarChartSeries*>(series); | |
75 | qreal x = barSeries->countCategories(); |
|
76 | qreal x = barSeries->countCategories(); | |
76 | qreal y = barSeries->max(); |
|
77 | qreal y = barSeries->max(); | |
77 | domain.m_minX = qMin(domain.m_minX,x); |
|
78 | domain.m_minX = qMin(domain.m_minX,x); | |
78 | domain.m_minY = qMin(domain.m_minY,y); |
|
79 | domain.m_minY = qMin(domain.m_minY,y); | |
79 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
80 | domain.m_maxX = qMax(domain.m_maxX,x); | |
80 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
81 | domain.m_maxY = qMax(domain.m_maxY,y); | |
81 | break; |
|
82 | break; | |
82 | } |
|
83 | } | |
83 | case QChartSeries::SeriesTypeStackedBar: { |
|
84 | case QChartSeries::SeriesTypeStackedBar: { | |
84 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; |
|
85 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; | |
85 |
|
86 | |||
86 | QStackedBarChartSeries* stackedBarSeries = static_cast<QStackedBarChartSeries*>(series); |
|
87 | QStackedBarChartSeries* stackedBarSeries = static_cast<QStackedBarChartSeries*>(series); | |
87 | qreal x = stackedBarSeries->countCategories(); |
|
88 | qreal x = stackedBarSeries->countCategories(); | |
88 | qreal y = stackedBarSeries->maxCategorySum(); |
|
89 | qreal y = stackedBarSeries->maxCategorySum(); | |
89 | domain.m_minX = qMin(domain.m_minX,x); |
|
90 | domain.m_minX = qMin(domain.m_minX,x); | |
90 | domain.m_minY = qMin(domain.m_minY,y); |
|
91 | domain.m_minY = qMin(domain.m_minY,y); | |
91 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
92 | domain.m_maxX = qMax(domain.m_maxX,x); | |
92 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
93 | domain.m_maxY = qMax(domain.m_maxY,y); | |
93 | break; |
|
94 | break; | |
94 | } |
|
95 | } | |
95 | case QChartSeries::SeriesTypePercentBar: { |
|
96 | case QChartSeries::SeriesTypePercentBar: { | |
96 | qDebug() << "QChartSeries::SeriesTypePercentBar"; |
|
97 | qDebug() << "QChartSeries::SeriesTypePercentBar"; | |
97 |
|
98 | |||
98 | QPercentBarChartSeries* percentBarSeries = static_cast<QPercentBarChartSeries*>(series); |
|
99 | QPercentBarChartSeries* percentBarSeries = static_cast<QPercentBarChartSeries*>(series); | |
99 | qreal x = percentBarSeries->countCategories(); |
|
100 | qreal x = percentBarSeries->countCategories(); | |
100 | domain.m_minX = qMin(domain.m_minX,x); |
|
101 | domain.m_minX = qMin(domain.m_minX,x); | |
101 | domain.m_minY = 0; |
|
102 | domain.m_minY = 0; | |
102 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
103 | domain.m_maxX = qMax(domain.m_maxX,x); | |
103 | domain.m_maxY = 100; |
|
104 | domain.m_maxY = 100; | |
104 | break; |
|
105 | break; | |
105 | } |
|
106 | } | |
106 |
|
107 | |||
107 | case QChartSeries::SeriesTypePie: { |
|
108 | case QChartSeries::SeriesTypePie: { | |
108 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
109 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
109 | // TODO: domain stuff |
|
110 | // TODO: domain stuff | |
110 | break; |
|
111 | break; | |
111 | } |
|
112 | } | |
112 |
|
113 | |||
113 | case QChartSeries::SeriesTypeScatter: { |
|
114 | case QChartSeries::SeriesTypeScatter: { | |
114 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
115 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
115 | Q_ASSERT(scatterSeries); |
|
116 | Q_ASSERT(scatterSeries); | |
116 | foreach (QPointF point, scatterSeries->data()) { |
|
117 | foreach (QPointF point, scatterSeries->data()) { | |
117 | domain.m_minX = qMin(domain.m_minX, point.x()); |
|
118 | domain.m_minX = qMin(domain.m_minX, point.x()); | |
118 | domain.m_maxX = qMax(domain.m_maxX, point.x()); |
|
119 | domain.m_maxX = qMax(domain.m_maxX, point.x()); | |
119 | domain.m_minY = qMin(domain.m_minY, point.y()); |
|
120 | domain.m_minY = qMin(domain.m_minY, point.y()); | |
120 | domain.m_maxY = qMax(domain.m_maxY, point.y()); |
|
121 | domain.m_maxY = qMax(domain.m_maxY, point.y()); | |
121 | } |
|
122 | } | |
122 | break; |
|
123 | break; | |
123 | } |
|
124 | } | |
124 |
|
125 | |||
125 | default: { |
|
126 | default: { | |
126 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
127 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; | |
127 | return; |
|
128 | return; | |
128 | break; |
|
129 | break; | |
129 | } |
|
130 | } | |
130 |
|
131 | |||
131 | } |
|
132 | } | |
132 |
|
133 | |||
133 | if(!m_domainMap.contains(axisY)) |
|
134 | if(!m_domainMap.contains(axisY)) | |
134 | { |
|
135 | { | |
135 | emit axisAdded(axisY); |
|
136 | emit axisAdded(axisY); | |
136 | QObject::connect(axisY,SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); |
|
137 | QObject::connect(axisY,SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); | |
137 | QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); |
|
138 | QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); | |
138 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
139 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
139 | } |
|
140 | } | |
140 | m_domainMap.replace(axisY,domain); |
|
141 | m_domainMap.replace(axisY,domain); | |
141 | m_seriesMap.insert(axisY,series); |
|
142 | m_seriesMap.insert(axisY,series); | |
142 |
|
143 | |||
143 | if(!m_axisXInitialized) |
|
144 | if(!m_axisXInitialized) | |
144 | { |
|
145 | { | |
145 | emit axisAdded(axisX()); |
|
146 | emit axisAdded(axisX()); | |
146 | QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); |
|
147 | QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal))); | |
147 | QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); |
|
148 | QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal))); | |
148 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
149 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); | |
149 | m_axisXInitialized=true; |
|
150 | m_axisXInitialized=true; | |
150 | } |
|
151 | } | |
151 |
|
152 | |||
152 |
|
153 | |||
153 | emit seriesAdded(series); |
|
154 | emit seriesAdded(series); | |
154 | QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY); |
|
155 | QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY); | |
155 | QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
156 | QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
156 | emit axisLabelsChanged(axisY,ylabels); |
|
157 | emit axisLabelsChanged(axisY,ylabels); | |
157 | emit axisLabelsChanged(axisX(),xlabels); |
|
158 | emit axisLabelsChanged(axisX(),xlabels); | |
158 | emit seriesDomainChanged(series,domain); |
|
159 | emit seriesDomainChanged(series,domain); | |
159 |
|
160 | |||
160 | } |
|
161 | } | |
161 |
|
162 | |||
162 | void ChartDataSet::removeSeries(QChartSeries* series) |
|
163 | void ChartDataSet::removeSeries(QChartSeries* series) | |
163 | { |
|
164 | { | |
164 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
165 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
165 | foreach(QChartAxis* axis , keys) { |
|
166 | foreach(QChartAxis* axis , keys) { | |
166 | if(m_seriesMap.contains(axis,series)){ |
|
167 | if(m_seriesMap.contains(axis,series)){ | |
167 | emit seriesRemoved(series); |
|
168 | emit seriesRemoved(series); | |
168 | m_seriesMap.remove(axis,series); |
|
169 | m_seriesMap.remove(axis,series); | |
169 | //remove axis if no longer there |
|
170 | //remove axis if no longer there | |
170 | if(!m_seriesMap.contains(axis) && axis != m_axisY){ |
|
171 | if(!m_seriesMap.contains(axis) && axis != m_axisY){ | |
171 | emit axisRemoved(axis); |
|
172 | emit axisRemoved(axis); | |
172 | m_domainMap.remove(axis); |
|
173 | m_domainMap.remove(axis); | |
173 | delete axis; |
|
174 | delete axis; | |
174 | } |
|
175 | } | |
175 | break; |
|
176 | break; | |
176 | } |
|
177 | } | |
177 | } |
|
178 | } | |
178 | } |
|
179 | } | |
179 |
|
180 | |||
180 | bool ChartDataSet::nextDomain() |
|
181 | bool ChartDataSet::nextDomain() | |
181 | { |
|
182 | { | |
182 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; |
|
183 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; | |
183 |
|
184 | |||
184 | if (m_domainIndex < limit) { |
|
185 | if (m_domainIndex < limit) { | |
185 | m_domainIndex++; |
|
186 | m_domainIndex++; | |
186 | setDomain(m_domainIndex); |
|
187 | setDomain(m_domainIndex); | |
187 | return true; |
|
188 | return true; | |
188 | } |
|
189 | } | |
189 | else { |
|
190 | else { | |
190 | return false; |
|
191 | return false; | |
191 | } |
|
192 | } | |
192 | } |
|
193 | } | |
193 |
|
194 | |||
194 | bool ChartDataSet::previousDomain() |
|
195 | bool ChartDataSet::previousDomain() | |
195 | { |
|
196 | { | |
196 | if (m_domainIndex > 0) { |
|
197 | if (m_domainIndex > 0) { | |
197 | m_domainIndex--; |
|
198 | m_domainIndex--; | |
198 | setDomain(m_domainIndex); |
|
199 | setDomain(m_domainIndex); | |
199 | return true; |
|
200 | return true; | |
200 | } |
|
201 | } | |
201 | else { |
|
202 | else { | |
202 | return false; |
|
203 | return false; | |
203 | } |
|
204 | } | |
204 | } |
|
205 | } | |
205 |
|
206 | |||
206 | void ChartDataSet::setDomain(int index) |
|
207 | void ChartDataSet::setDomain(int index) | |
207 | { |
|
208 | { | |
208 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
209 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
209 | foreach (QChartAxis* axis , domainList) { |
|
210 | foreach (QChartAxis* axis , domainList) { | |
210 | int i = m_domainMap.count(axis) - index -1; |
|
211 | int i = m_domainMap.count(axis) - index -1; | |
211 | Q_ASSERT(i>=0); |
|
212 | Q_ASSERT(i>=0); | |
212 | Domain domain = m_domainMap.values(axis).at(i); |
|
213 | Domain domain = m_domainMap.values(axis).at(i); | |
213 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
214 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
214 | QList<QChartSeries*> seriesList = m_seriesMap.values(axis); |
|
215 | QList<QChartSeries*> seriesList = m_seriesMap.values(axis); | |
215 | foreach(QChartSeries* series, seriesList) { |
|
216 | foreach(QChartSeries* series, seriesList) { | |
216 | emit seriesDomainChanged(series,domain); |
|
217 | emit seriesDomainChanged(series,domain); | |
217 | } |
|
218 | } | |
218 | emit axisLabelsChanged(axis,labels); |
|
219 | emit axisLabelsChanged(axis,labels); | |
219 | } |
|
220 | } | |
220 |
|
221 | |||
221 | Domain domain = m_domainMap.value(axisY()); |
|
222 | Domain domain = m_domainMap.value(axisY()); | |
222 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
223 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
223 | emit axisLabelsChanged(axisX(),labels); |
|
224 | emit axisLabelsChanged(axisX(),labels); | |
224 | } |
|
225 | } | |
225 |
|
226 | |||
226 | void ChartDataSet::clearDomains(int toIndex) |
|
227 | void ChartDataSet::clearDomains(int toIndex) | |
227 | { |
|
228 | { | |
228 | Q_ASSERT(toIndex>=0); |
|
229 | Q_ASSERT(toIndex>=0); | |
229 |
|
230 | |||
230 | m_domainIndex = toIndex; |
|
231 | m_domainIndex = toIndex; | |
231 |
|
232 | |||
232 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); |
|
233 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); | |
233 |
|
234 | |||
234 | foreach (QChartAxis* key , keys) |
|
235 | foreach (QChartAxis* key , keys) | |
235 | { |
|
236 | { | |
236 | QList<Domain> domains = m_domainMap.values(key); |
|
237 | QList<Domain> domains = m_domainMap.values(key); | |
237 | m_domainMap.remove(key); |
|
238 | m_domainMap.remove(key); | |
238 | int i = domains.size() - toIndex - 1; |
|
239 | int i = domains.size() - toIndex - 1; | |
239 | while(i--){ |
|
240 | while(i--){ | |
240 | domains.removeFirst(); |
|
241 | domains.removeFirst(); | |
241 | } |
|
242 | } | |
242 | for(int j=domains.size()-1; j>=0 ;j--) |
|
243 | for(int j=domains.size()-1; j>=0 ;j--) | |
243 | m_domainMap.insert(key,domains.at(j)); |
|
244 | m_domainMap.insert(key,domains.at(j)); | |
244 | } |
|
245 | } | |
245 | } |
|
246 | } | |
246 |
|
247 | |||
247 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) |
|
248 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) | |
248 | { |
|
249 | { | |
249 | Q_ASSERT(rect.isValid()); |
|
250 | Q_ASSERT(rect.isValid()); | |
250 | Q_ASSERT(viewport.isValid()); |
|
251 | Q_ASSERT(viewport.isValid()); | |
251 |
|
252 | |||
252 | clearDomains(m_domainIndex); |
|
253 | clearDomains(m_domainIndex); | |
253 |
|
254 | |||
254 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
255 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
255 |
|
256 | |||
256 | foreach (QChartAxis* axis , domainList){ |
|
257 | foreach (QChartAxis* axis , domainList){ | |
257 | Domain domain(m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height())); |
|
258 | Domain domain(m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height())); | |
258 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
259 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
259 | QList<QChartSeries*> seriesList = m_seriesMap.values(axis); |
|
260 | QList<QChartSeries*> seriesList = m_seriesMap.values(axis); | |
260 | foreach(QChartSeries* series, seriesList){ |
|
261 | foreach(QChartSeries* series, seriesList){ | |
261 | emit seriesDomainChanged(series,domain); |
|
262 | emit seriesDomainChanged(series,domain); | |
262 | } |
|
263 | } | |
263 | emit axisLabelsChanged(axis,labels); |
|
264 | emit axisLabelsChanged(axis,labels); | |
264 | m_domainMap.insert(axis,domain); |
|
265 | m_domainMap.insert(axis,domain); | |
265 | } |
|
266 | } | |
266 |
|
267 | |||
267 | Domain domain = m_domainMap.value(axisY()); |
|
268 | Domain domain = m_domainMap.value(axisY()); | |
268 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
269 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |
269 | emit axisLabelsChanged(axisX(),labels); |
|
270 | emit axisLabelsChanged(axisX(),labels); | |
270 |
|
271 | |||
271 | m_domainIndex++; |
|
272 | m_domainIndex++; | |
272 | } |
|
273 | } | |
273 |
|
274 | |||
274 | QChartAxis* ChartDataSet::axisY(QChartSeries* series) const |
|
275 | QChartAxis* ChartDataSet::axisY(QChartSeries* series) const | |
275 | { |
|
276 | { | |
276 | if(series == 0) return m_axisY; |
|
277 | if(series == 0) return m_axisY; | |
277 |
|
278 | |||
278 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
279 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
279 |
|
280 | |||
280 | foreach(QChartAxis* axis , keys) { |
|
281 | foreach(QChartAxis* axis , keys) { | |
281 | if(m_seriesMap.contains(axis,series)){ |
|
282 | if(m_seriesMap.contains(axis,series)){ | |
282 | return axis; |
|
283 | return axis; | |
283 | } |
|
284 | } | |
284 | } |
|
285 | } | |
285 | return 0; |
|
286 | return 0; | |
286 | } |
|
287 | } | |
287 |
|
288 | |||
288 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) |
|
289 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) | |
289 | { |
|
290 | { | |
290 | Q_ASSERT(max>=min); |
|
291 | Q_ASSERT(max>=min); | |
291 |
|
292 | |||
292 | QStringList labels; |
|
293 | QStringList labels; | |
293 |
|
294 | |||
294 | int ticks = axis->ticksCount(); |
|
295 | int ticks = axis->ticksCount(); | |
295 |
|
296 | |||
296 | for(int i=0; i<= ticks; i++){ |
|
297 | for(int i=0; i<= ticks; i++){ | |
297 | qreal value = min + (i * (max - min)/ ticks); |
|
298 | qreal value = min + (i * (max - min)/ ticks); | |
298 | QString label = axis->axisTickLabel(value); |
|
299 | QString label = axis->axisTickLabel(value); | |
299 | if(label.isEmpty()){ |
|
300 | if(label.isEmpty()){ | |
300 | labels << QString::number(value); |
|
301 | labels << QString::number(value); | |
301 | }else{ |
|
302 | }else{ | |
302 | labels << label; |
|
303 | labels << label; | |
303 | } |
|
304 | } | |
304 | } |
|
305 | } | |
305 | return labels; |
|
306 | return labels; | |
306 | } |
|
307 | } | |
307 |
|
308 | |||
308 |
|
309 | |||
309 | void ChartDataSet::handleMinChanged(qreal min) |
|
310 | void ChartDataSet::handleMinChanged(qreal min) | |
310 | { |
|
311 | { | |
311 |
|
312 | |||
312 | } |
|
313 | } | |
313 |
|
314 | |||
314 | void ChartDataSet::handleMaxChanged(qreal max) |
|
315 | void ChartDataSet::handleMaxChanged(qreal max) | |
315 | { |
|
316 | { | |
316 |
|
317 | |||
317 | } |
|
318 | } | |
318 |
|
319 | |||
319 | void ChartDataSet::handleTickChanged(QChartAxis* axis) |
|
320 | void ChartDataSet::handleTickChanged(QChartAxis* axis) | |
320 | { |
|
321 | { | |
321 | Domain domain = m_domainMap.value(axisY()); |
|
322 | Domain domain = m_domainMap.value(axisY()); | |
322 | if(axis==axisX()){ |
|
323 | if(axis==axisX()){ | |
323 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); |
|
324 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); | |
324 | emit axisLabelsChanged(axis,labels); |
|
325 | emit axisLabelsChanged(axis,labels); | |
325 | }else{ |
|
326 | }else{ | |
326 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
327 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
327 | emit axisLabelsChanged(axis,labels); |
|
328 | emit axisLabelsChanged(axis,labels); | |
328 | } |
|
329 | } | |
329 | } |
|
330 | } | |
330 |
|
331 | |||
331 | #include "moc_chartdataset_p.cpp" |
|
332 | #include "moc_chartdataset_p.cpp" | |
332 |
|
333 | |||
333 | QTCOMMERCIALCHART_END_NAMESPACE |
|
334 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,71 +1,70 | |||||
1 | #ifndef QCHARTWIDGET_H |
|
1 | #ifndef QCHARTWIDGET_H | |
2 | #define QCHARTWIDGET_H |
|
2 | #define QCHARTWIDGET_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchartseries.h" |
|
5 | #include "qchartseries.h" | |
6 | #include "qchart.h" |
|
6 | #include "qchart.h" | |
7 | #include <QGraphicsView> |
|
7 | #include <QGraphicsView> | |
8 |
|
8 | |||
9 | class QGraphicsScene; |
|
9 | class QGraphicsScene; | |
10 | class QRubberBand; |
|
10 | class QRubberBand; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class QChart; |
|
14 | class QChart; | |
15 |
|
15 | |||
16 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView |
|
16 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView | |
17 | { |
|
17 | { | |
18 | public: |
|
18 | public: | |
19 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; |
|
19 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; | |
20 |
|
20 | |||
21 | explicit QChartView(QWidget *parent = 0); |
|
21 | explicit QChartView(QWidget *parent = 0); | |
22 | ~QChartView(); |
|
22 | ~QChartView(); | |
23 |
|
23 | |||
24 | //implement from QWidget |
|
24 | //implement from QWidget | |
25 | void resizeEvent(QResizeEvent *event); |
|
25 | void resizeEvent(QResizeEvent *event); | |
26 |
|
26 | |||
27 |
void addSeries(QChartSeries* series,QChartAxis* axisY=0) |
|
27 | void addSeries(QChartSeries* series,QChartAxis* axisY=0);// takes ownership | |
28 | void removeSeries(QChartSeries* series); |
|
28 | void removeSeries(QChartSeries* series); | |
29 |
|
||||
30 | int margin() const; |
|
29 | int margin() const; | |
31 |
|
30 | |||
32 | void setChartTitle(const QString& title); |
|
31 | void setChartTitle(const QString& title); | |
33 | void setChartTitleFont(const QFont& font); |
|
32 | void setChartTitleFont(const QFont& font); | |
34 | void setChartBackgroundBrush(const QBrush& brush); |
|
33 | void setChartBackgroundBrush(const QBrush& brush); | |
35 | void setChartBackgroundPen(const QPen& pen); |
|
34 | void setChartBackgroundPen(const QPen& pen); | |
36 |
|
35 | |||
37 | void zoomIn(); |
|
36 | void zoomIn(); | |
38 | void zoomIn(const QRect& rect); |
|
37 | void zoomIn(const QRect& rect); | |
39 | void zoomOut(); |
|
38 | void zoomOut(); | |
40 |
|
39 | |||
41 | void setRubberBandPolicy(const RubberBandPolicy ); |
|
40 | void setRubberBandPolicy(const RubberBandPolicy ); | |
42 | RubberBandPolicy rubberBandPolicy() const; |
|
41 | RubberBandPolicy rubberBandPolicy() const; | |
43 |
|
42 | |||
44 | void setChartTheme(QChart::ChartTheme theme); |
|
43 | void setChartTheme(QChart::ChartTheme theme); | |
45 | QChart::ChartTheme chartTheme() const; |
|
44 | QChart::ChartTheme chartTheme() const; | |
46 |
|
45 | |||
47 | QChartAxis* axisX() const; |
|
46 | QChartAxis* axisX() const; | |
48 | QChartAxis* axisY() const; |
|
47 | QChartAxis* axisY() const; | |
49 |
|
48 | |||
50 | protected: |
|
49 | protected: | |
51 | void mousePressEvent(QMouseEvent *event); |
|
50 | void mousePressEvent(QMouseEvent *event); | |
52 | void mouseMoveEvent(QMouseEvent *event); |
|
51 | void mouseMoveEvent(QMouseEvent *event); | |
53 | void mouseReleaseEvent(QMouseEvent *event); |
|
52 | void mouseReleaseEvent(QMouseEvent *event); | |
54 | void keyPressEvent(QKeyEvent *event); |
|
53 | void keyPressEvent(QKeyEvent *event); | |
55 |
|
54 | |||
56 |
|
55 | |||
57 | private: |
|
56 | private: | |
58 | QGraphicsScene *m_scene; |
|
57 | QGraphicsScene *m_scene; | |
59 | QChart* m_chart; |
|
58 | QChart* m_chart; | |
60 | QPoint m_rubberBandOrigin; |
|
59 | QPoint m_rubberBandOrigin; | |
61 | QRubberBand* m_rubberBand; |
|
60 | QRubberBand* m_rubberBand; | |
62 | bool m_verticalRubberBand; |
|
61 | bool m_verticalRubberBand; | |
63 | bool m_horizonalRubberBand; |
|
62 | bool m_horizonalRubberBand; | |
64 | Q_DISABLE_COPY(QChartView) |
|
63 | Q_DISABLE_COPY(QChartView) | |
65 |
|
64 | |||
66 |
|
65 | |||
67 | }; |
|
66 | }; | |
68 |
|
67 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
68 | QTCOMMERCIALCHART_END_NAMESPACE | |
70 |
|
69 | |||
71 | #endif // QCHARTWIDGET_H |
|
70 | #endif // QCHARTWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now