@@ -1,379 +1,404 | |||||
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,axisY); | |
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->updateRange(domain.m_minY,domain.m_maxY); |
|
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()->updateRange(domain.m_minX,domain.m_maxY); |
|
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::setDomain(int index,QChartAxis* axis) | |||
|
248 | { | |||
|
249 | int i = m_domainMap.count(axis) - index -1; | |||
|
250 | Q_ASSERT(i>=0); | |||
|
251 | Domain domain = m_domainMap.values(axis).at(i); | |||
|
252 | { | |||
|
253 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |||
|
254 | QList<QSeries*> seriesList = m_seriesMap.values(axis); | |||
|
255 | foreach(QSeries* series, seriesList) { | |||
|
256 | emit seriesDomainChanged(series,domain); | |||
|
257 | } | |||
|
258 | axis->updateRange(domain.m_minY,domain.m_maxY); | |||
|
259 | emit axisRangeChanged(axis,labels); | |||
|
260 | } | |||
|
261 | ||||
|
262 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); | |||
|
263 | axisX()->updateRange(domain.m_minX,domain.m_maxY); | |||
|
264 | emit axisRangeChanged(axisX(),labels); | |||
|
265 | } | |||
|
266 | ||||
|
267 | ||||
247 | void ChartDataSet::clearDomains(int toIndex) |
|
268 | void ChartDataSet::clearDomains(int toIndex) | |
248 | { |
|
269 | { | |
249 | Q_ASSERT(toIndex>=0); |
|
270 | Q_ASSERT(toIndex>=0); | |
250 |
|
271 | |||
251 | m_domainIndex = toIndex; |
|
272 | m_domainIndex = toIndex; | |
252 |
|
273 | |||
253 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); |
|
274 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); | |
254 |
|
275 | |||
255 | foreach (QChartAxis* key , keys) |
|
276 | foreach (QChartAxis* key , keys) | |
256 | { |
|
277 | { | |
257 | QList<Domain> domains = m_domainMap.values(key); |
|
278 | QList<Domain> domains = m_domainMap.values(key); | |
258 | m_domainMap.remove(key); |
|
279 | m_domainMap.remove(key); | |
259 | int i = domains.size() - toIndex - 1; |
|
280 | int i = domains.size() - toIndex - 1; | |
260 | while(i--){ |
|
281 | while(i--){ | |
261 | domains.removeFirst(); |
|
282 | domains.removeFirst(); | |
262 | } |
|
283 | } | |
263 | for(int j=domains.size()-1; j>=0 ;j--) |
|
284 | for(int j=domains.size()-1; j>=0 ;j--) | |
264 | m_domainMap.insert(key,domains.at(j)); |
|
285 | m_domainMap.insert(key,domains.at(j)); | |
265 | } |
|
286 | } | |
266 | } |
|
287 | } | |
267 |
|
288 | |||
268 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) |
|
289 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) | |
269 | { |
|
290 | { | |
270 | Q_ASSERT(rect.isValid()); |
|
291 | Q_ASSERT(rect.isValid()); | |
271 | Q_ASSERT(viewport.isValid()); |
|
292 | Q_ASSERT(viewport.isValid()); | |
272 |
|
293 | |||
273 | clearDomains(m_domainIndex); |
|
294 | clearDomains(m_domainIndex); | |
274 |
|
295 | |||
275 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
296 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
276 |
|
297 | |||
277 | Domain domain; |
|
298 | Domain domain; | |
278 |
|
299 | |||
279 | foreach (QChartAxis* axis , domainList){ |
|
300 | foreach (QChartAxis* axis , domainList){ | |
280 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); |
|
301 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); | |
281 | m_domainMap.insert(axis,domain); |
|
302 | m_domainMap.insert(axis,domain); | |
282 | } |
|
303 | } | |
283 |
|
304 | |||
284 | setDomain(++m_domainIndex); |
|
305 | setDomain(++m_domainIndex); | |
285 | } |
|
306 | } | |
286 |
|
307 | |||
287 | QChartAxis* ChartDataSet::axisY(QSeries* series) const |
|
308 | QChartAxis* ChartDataSet::axisY(QSeries* series) const | |
288 | { |
|
309 | { | |
289 | if(series == 0) return m_axisY; |
|
310 | if(series == 0) return m_axisY; | |
290 |
|
311 | |||
291 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
312 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); | |
292 |
|
313 | |||
293 | foreach(QChartAxis* axis , keys) { |
|
314 | foreach(QChartAxis* axis , keys) { | |
294 | if(m_seriesMap.contains(axis,series)){ |
|
315 | if(m_seriesMap.contains(axis,series)){ | |
295 | return axis; |
|
316 | return axis; | |
296 | } |
|
317 | } | |
297 | } |
|
318 | } | |
298 | return 0; |
|
319 | return 0; | |
299 | } |
|
320 | } | |
300 |
|
321 | |||
301 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) |
|
322 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) | |
302 | { |
|
323 | { | |
303 | Q_ASSERT(max>=min); |
|
324 | Q_ASSERT(max>=min); | |
304 |
|
325 | |||
305 | QStringList labels; |
|
326 | QStringList labels; | |
306 |
|
327 | |||
307 | int ticks = axis->ticksCount()-1; |
|
328 | int ticks = axis->ticksCount()-1; | |
308 |
|
329 | |||
309 | for(int i=0; i<= ticks; i++){ |
|
330 | for(int i=0; i<= ticks; i++){ | |
310 | qreal value = min + (i * (max - min)/ ticks); |
|
331 | qreal value = min + (i * (max - min)/ ticks); | |
311 | QString label = axis->axisTickLabel(value); |
|
332 | QString label = axis->axisTickLabel(value); | |
312 | if(label.isEmpty()){ |
|
333 | if(label.isEmpty()){ | |
313 | labels << QString::number(value); |
|
334 | labels << QString::number(value); | |
314 | }else{ |
|
335 | }else{ | |
315 | labels << label; |
|
336 | labels << label; | |
316 | } |
|
337 | } | |
317 | } |
|
338 | } | |
318 | return labels; |
|
339 | return labels; | |
319 | } |
|
340 | } | |
320 |
|
341 | |||
321 |
|
342 | |||
322 | void ChartDataSet::handleRangeChanged(QChartAxis* axis) |
|
343 | void ChartDataSet::handleRangeChanged(QChartAxis* axis) | |
323 | { |
|
344 | { | |
324 | qreal min = axis->min(); |
|
345 | qreal min = axis->min(); | |
325 | qreal max = axis->max(); |
|
346 | qreal max = axis->max(); | |
326 |
|
347 | |||
327 | if(axis==axisX()) { |
|
348 | if(axis==axisX()) { | |
328 |
|
349 | |||
329 | m_domainIndex=0; |
|
350 | m_domainIndex=0; | |
330 |
|
351 | |||
331 | clearDomains(m_domainIndex); |
|
352 | clearDomains(m_domainIndex); | |
332 |
|
353 | |||
333 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
354 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); | |
334 |
|
355 | |||
335 | foreach (QChartAxis* axis , domainList) { |
|
356 | foreach (QChartAxis* axis , domainList) { | |
336 |
|
357 | |||
337 | Q_ASSERT(m_domainMap.values(axis).size()==1); |
|
358 | Q_ASSERT(m_domainMap.values(axis).size()==1); | |
338 |
|
359 | |||
339 | Domain domain = m_domainMap.value(axis); |
|
360 | Domain domain = m_domainMap.value(axis); | |
340 | domain.m_minX=min; |
|
361 | domain.m_minX=min; | |
341 | domain.m_maxX=max; |
|
362 | domain.m_maxX=max; | |
342 | m_domainMap.replace(axis,domain); |
|
363 | m_domainMap.replace(axis,domain); | |
343 | } |
|
364 | } | |
344 |
|
365 | |||
|
366 | setDomain(m_domainIndex); | |||
|
367 | ||||
345 | } |
|
368 | } | |
346 | else { |
|
369 | else { | |
347 |
|
370 | |||
348 | QList<Domain> domains = m_domainMap.values(axis); |
|
371 | QList<Domain> domains = m_domainMap.values(axis); | |
349 | m_domainMap.remove(axis); |
|
372 | m_domainMap.remove(axis); | |
350 |
|
373 | |||
351 | for(int i=0;i<domains.size();i++) |
|
374 | for(int i=0;i<domains.size();i++) | |
352 | { |
|
375 | { | |
353 | domains[i].m_minY=min; |
|
376 | domains[i].m_minY=min; | |
354 | domains[i].m_maxY=max; |
|
377 | domains[i].m_maxY=max; | |
355 | } |
|
378 | } | |
356 |
|
379 | |||
357 | for(int j=domains.size()-1; j>=0;j--) |
|
380 | for(int j=domains.size()-1; j>=0;j--) | |
358 | m_domainMap.insert(axis,domains.at(j)); |
|
381 | m_domainMap.insert(axis,domains.at(j)); | |
|
382 | ||||
|
383 | setDomain(m_domainIndex,axis); | |||
359 | } |
|
384 | } | |
360 |
|
385 | |||
361 | setDomain(m_domainIndex); |
|
386 | ||
362 | } |
|
387 | } | |
363 |
|
388 | |||
364 | void ChartDataSet::handleTickChanged(QChartAxis* axis) |
|
389 | void ChartDataSet::handleTickChanged(QChartAxis* axis) | |
365 | { |
|
390 | { | |
366 | if(axis==axisX()){ |
|
391 | if(axis==axisX()){ | |
367 | Domain domain = m_domainMap.value(axisY()); |
|
392 | Domain domain = m_domainMap.value(axisY()); | |
368 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); |
|
393 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); | |
369 | emit axisRangeChanged(axis,labels); |
|
394 | emit axisRangeChanged(axis,labels); | |
370 | }else{ |
|
395 | }else{ | |
371 | Domain domain = m_domainMap.value(axis); |
|
396 | Domain domain = m_domainMap.value(axis); | |
372 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
397 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); | |
373 | emit axisRangeChanged(axis,labels); |
|
398 | emit axisRangeChanged(axis,labels); | |
374 | } |
|
399 | } | |
375 | } |
|
400 | } | |
376 |
|
401 | |||
377 | #include "moc_chartdataset_p.cpp" |
|
402 | #include "moc_chartdataset_p.cpp" | |
378 |
|
403 | |||
379 | QTCOMMERCIALCHART_END_NAMESPACE |
|
404 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,59 +1,60 | |||||
1 | #ifndef CHARTDATASET_P_H_ |
|
1 | #ifndef CHARTDATASET_P_H_ | |
2 | #define CHARTDATASET_P_H_ |
|
2 | #define CHARTDATASET_P_H_ | |
3 |
|
3 | |||
4 | #include "qseries.h" |
|
4 | #include "qseries.h" | |
5 | #include "domain_p.h" |
|
5 | #include "domain_p.h" | |
6 | #include <QVector> |
|
6 | #include <QVector> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QChartAxis; |
|
10 | class QChartAxis; | |
11 |
|
11 | |||
12 | class ChartDataSet : public QObject |
|
12 | class ChartDataSet : public QObject | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | public: |
|
15 | public: | |
16 | ChartDataSet(QObject* parent=0); |
|
16 | ChartDataSet(QObject* parent=0); | |
17 | virtual ~ChartDataSet(); |
|
17 | virtual ~ChartDataSet(); | |
18 |
|
18 | |||
19 | void addSeries(QSeries* series,QChartAxis *axisY = 0); |
|
19 | void addSeries(QSeries* series,QChartAxis *axisY = 0); | |
20 | void removeSeries(QSeries* series); |
|
20 | void removeSeries(QSeries* series); | |
21 | void removeAllSeries(); |
|
21 | void removeAllSeries(); | |
22 | void addDomain(const QRectF& rect, const QRectF& viewport); |
|
22 | void addDomain(const QRectF& rect, const QRectF& viewport); | |
23 | bool nextDomain(); |
|
23 | bool nextDomain(); | |
24 | bool previousDomain(); |
|
24 | bool previousDomain(); | |
25 | void clearDomains(int toIndex =0); |
|
25 | void clearDomains(int toIndex =0); | |
26 | const Domain domain(QChartAxis *axisY) const; |
|
26 | const Domain domain(QChartAxis *axisY) const; | |
27 | int domainIndex() const {return m_domainIndex;} |
|
27 | int domainIndex() const {return m_domainIndex;} | |
28 | void setDomain(int index); |
|
28 | void setDomain(int index); | |
|
29 | void setDomain(int index,QChartAxis* axis); | |||
29 |
|
30 | |||
30 | QChartAxis* axisX() const { return m_axisX;}; |
|
31 | QChartAxis* axisX() const { return m_axisX;}; | |
31 | QChartAxis* axisY(QSeries* series = 0) const; |
|
32 | QChartAxis* axisY(QSeries* series = 0) const; | |
32 |
|
33 | |||
33 | signals: |
|
34 | signals: | |
34 | void seriesAdded(QSeries* series); |
|
35 | void seriesAdded(QSeries* series); | |
35 | void seriesRemoved(QSeries* series); |
|
36 | void seriesRemoved(QSeries* series); | |
36 | void axisAdded(QChartAxis* axis); |
|
37 | void axisAdded(QChartAxis* axis); | |
37 | void axisRemoved(QChartAxis* axis); |
|
38 | void axisRemoved(QChartAxis* axis); | |
38 | void axisRangeChanged(QChartAxis* axis, const QStringList& labels); |
|
39 | void axisRangeChanged(QChartAxis* axis, const QStringList& labels); | |
39 | void seriesDomainChanged(QSeries* series,const Domain& domain); |
|
40 | void seriesDomainChanged(QSeries* series,const Domain& domain); | |
40 |
|
41 | |||
41 | private slots: |
|
42 | private slots: | |
42 | void handleRangeChanged(QChartAxis*); |
|
43 | void handleRangeChanged(QChartAxis*); | |
43 | void handleTickChanged(QChartAxis*); |
|
44 | void handleTickChanged(QChartAxis*); | |
44 |
|
45 | |||
45 | private: |
|
46 | private: | |
46 | QStringList createLabels(QChartAxis* axis,qreal min, qreal max); |
|
47 | QStringList createLabels(QChartAxis* axis,qreal min, qreal max); | |
47 |
|
48 | |||
48 | private: |
|
49 | private: | |
49 | QMultiMap<QChartAxis*, Domain> m_domainMap; |
|
50 | QMultiMap<QChartAxis*, Domain> m_domainMap; | |
50 | QMultiMap<QChartAxis*, QSeries*> m_seriesMap; |
|
51 | QMultiMap<QChartAxis*, QSeries*> m_seriesMap; | |
51 | QChartAxis* m_axisX; |
|
52 | QChartAxis* m_axisX; | |
52 | QChartAxis* m_axisY; |
|
53 | QChartAxis* m_axisY; | |
53 | int m_domainIndex; |
|
54 | int m_domainIndex; | |
54 | bool m_axisXInitialized; |
|
55 | bool m_axisXInitialized; | |
55 | }; |
|
56 | }; | |
56 |
|
57 | |||
57 | QTCOMMERCIALCHART_END_NAMESPACE |
|
58 | QTCOMMERCIALCHART_END_NAMESPACE | |
58 |
|
59 | |||
59 | #endif /* CHARTENGINE_P_H_ */ |
|
60 | #endif /* CHARTENGINE_P_H_ */ |
@@ -1,598 +1,614 | |||||
1 | #include <QtTest/QtTest> |
|
1 | #include <QtTest/QtTest> | |
2 | #include <qchartaxis.h> |
|
2 | #include <qchartaxis.h> | |
3 | #include <qlineseries.h> |
|
3 | #include <qlineseries.h> | |
4 | #include <private/chartdataset_p.h> |
|
4 | #include <private/chartdataset_p.h> | |
5 | #include <private/domain_p.h> |
|
5 | #include <private/domain_p.h> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
7 | QTCOMMERCIALCHART_USE_NAMESPACE | |
8 |
|
8 | |||
9 | Q_DECLARE_METATYPE(Domain) |
|
9 | Q_DECLARE_METATYPE(Domain) | |
10 | Q_DECLARE_METATYPE(QChartAxis*) |
|
10 | Q_DECLARE_METATYPE(QChartAxis*) | |
11 | Q_DECLARE_METATYPE(QSeries*) |
|
11 | Q_DECLARE_METATYPE(QSeries*) | |
12 | Q_DECLARE_METATYPE(QLineSeries*) |
|
12 | Q_DECLARE_METATYPE(QLineSeries*) | |
13 |
|
13 | |||
14 | class tst_ChartDataSet: public QObject { |
|
14 | class tst_ChartDataSet: public QObject { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 |
|
16 | |||
17 | public slots: |
|
17 | public slots: | |
18 | void initTestCase(); |
|
18 | void initTestCase(); | |
19 | void cleanupTestCase(); |
|
19 | void cleanupTestCase(); | |
20 | void init(); |
|
20 | void init(); | |
21 | void cleanup(); |
|
21 | void cleanup(); | |
22 |
|
22 | |||
23 | private slots: |
|
23 | private slots: | |
24 | void chartdataset_data(); |
|
24 | void chartdataset_data(); | |
25 | void chartdataset(); |
|
25 | void chartdataset(); | |
26 |
|
26 | |||
27 | void addDomain_data(); |
|
27 | void addDomain_data(); | |
28 | void addDomain(); |
|
28 | void addDomain(); | |
29 | void addSeries_data(); |
|
29 | void addSeries_data(); | |
30 | void addSeries(); |
|
30 | void addSeries(); | |
31 | void axisY_data(); |
|
31 | void axisY_data(); | |
32 | void axisY(); |
|
32 | void axisY(); | |
33 | void clearDomains_data(); |
|
33 | void clearDomains_data(); | |
34 | void clearDomains(); |
|
34 | void clearDomains(); | |
35 | void domain_data(); |
|
35 | void domain_data(); | |
36 | void domain(); |
|
36 | void domain(); | |
37 | void nextpreviousDomain_data(); |
|
37 | void nextpreviousDomain_data(); | |
38 | void nextpreviousDomain(); |
|
38 | void nextpreviousDomain(); | |
39 | void removeSeries_data(); |
|
39 | void removeSeries_data(); | |
40 | void removeSeries(); |
|
40 | void removeSeries(); | |
41 | void removeAllSeries_data(); |
|
41 | void removeAllSeries_data(); | |
42 | void removeAllSeries(); |
|
42 | void removeAllSeries(); | |
43 | }; |
|
43 | }; | |
44 |
|
44 | |||
45 | void tst_ChartDataSet::initTestCase() |
|
45 | void tst_ChartDataSet::initTestCase() | |
46 | { |
|
46 | { | |
47 | qRegisterMetaType<Domain>("Domain"); |
|
47 | qRegisterMetaType<Domain>("Domain"); | |
48 | qRegisterMetaType<QChartAxis*>(); |
|
48 | qRegisterMetaType<QChartAxis*>(); | |
49 | qRegisterMetaType<QSeries*>(); |
|
49 | qRegisterMetaType<QSeries*>(); | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | void tst_ChartDataSet::cleanupTestCase() |
|
52 | void tst_ChartDataSet::cleanupTestCase() | |
53 | { |
|
53 | { | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | void tst_ChartDataSet::init() |
|
56 | void tst_ChartDataSet::init() | |
57 | { |
|
57 | { | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void tst_ChartDataSet::cleanup() |
|
60 | void tst_ChartDataSet::cleanup() | |
61 | { |
|
61 | { | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void tst_ChartDataSet::chartdataset_data() |
|
64 | void tst_ChartDataSet::chartdataset_data() | |
65 | { |
|
65 | { | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void tst_ChartDataSet::chartdataset() |
|
68 | void tst_ChartDataSet::chartdataset() | |
69 | { |
|
69 | { | |
70 | ChartDataSet dataSet; |
|
70 | ChartDataSet dataSet; | |
71 | QVERIFY2(dataSet.axisX(), "Missing axisX."); |
|
71 | QVERIFY2(dataSet.axisX(), "Missing axisX."); | |
72 | QVERIFY2(dataSet.axisY(), "Missing axisY."); |
|
72 | QVERIFY2(dataSet.axisY(), "Missing axisY."); | |
73 | //check if not dangling pointer |
|
73 | //check if not dangling pointer | |
74 | dataSet.axisX()->objectName(); |
|
74 | dataSet.axisX()->objectName(); | |
75 | dataSet.axisY()->objectName(); |
|
75 | dataSet.axisY()->objectName(); | |
76 | QVERIFY(dataSet.domain(dataSet.axisX())==Domain()); |
|
76 | QVERIFY(dataSet.domain(dataSet.axisX())==Domain()); | |
77 | QVERIFY(dataSet.domain(dataSet.axisY())==Domain()); |
|
77 | QVERIFY(dataSet.domain(dataSet.axisY())==Domain()); | |
78 | QCOMPARE(dataSet.domainIndex(), 0); |
|
78 | QCOMPARE(dataSet.domainIndex(), 0); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | void tst_ChartDataSet::addDomain_data() |
|
81 | void tst_ChartDataSet::addDomain_data() | |
82 | { |
|
82 | { | |
83 | QTest::addColumn<QRectF>("rect"); |
|
83 | QTest::addColumn<QRectF>("rect"); | |
84 | QTest::addColumn<QRectF>("viewport"); |
|
84 | QTest::addColumn<QRectF>("viewport"); | |
85 | QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600) |
|
85 | QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600) | |
86 | << QRectF(0, 0, 1000, 1000); |
|
86 | << QRectF(0, 0, 1000, 1000); | |
87 | QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700) |
|
87 | QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700) | |
88 | << QRectF(0, 0, 1000, 1000); |
|
88 | << QRectF(0, 0, 1000, 1000); | |
89 | QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600) |
|
89 | QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600) | |
90 | << QRectF(0, 0, 1000, 1000); |
|
90 | << QRectF(0, 0, 1000, 1000); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | void tst_ChartDataSet::addDomain() |
|
93 | void tst_ChartDataSet::addDomain() | |
94 | { |
|
94 | { | |
95 | QFETCH(QRectF, rect); |
|
95 | QFETCH(QRectF, rect); | |
96 | QFETCH(QRectF, viewport); |
|
96 | QFETCH(QRectF, viewport); | |
97 |
|
97 | |||
98 | ChartDataSet dataSet; |
|
98 | ChartDataSet dataSet; | |
99 |
|
99 | |||
100 | Domain domain1(0, 1000, 0, 1000); |
|
100 | Domain domain1(0, 1000, 0, 1000); | |
101 | QLineSeries series; |
|
101 | QLineSeries series; | |
102 | series.add(0, 0); |
|
102 | series.add(0, 0); | |
103 | series.add(1000, 1000); |
|
103 | series.add(1000, 1000); | |
104 |
|
104 | |||
105 | dataSet.addSeries(&series); |
|
105 | dataSet.addSeries(&series); | |
106 |
|
106 | |||
107 | QCOMPARE(dataSet.domainIndex(), 0); |
|
107 | QCOMPARE(dataSet.domainIndex(), 0); | |
108 |
|
108 | |||
109 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
109 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |
110 | QSignalSpy spy1(&dataSet, |
|
110 | QSignalSpy spy1(&dataSet, | |
111 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); |
|
111 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); | |
112 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
112 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
113 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); |
|
113 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
114 | QSignalSpy spy4(&dataSet, |
|
114 | QSignalSpy spy4(&dataSet, | |
115 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
115 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
116 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
116 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
117 |
|
117 | |||
118 | Domain domain2 = dataSet.domain(dataSet.axisY()); |
|
118 | Domain domain2 = dataSet.domain(dataSet.axisY()); | |
119 | QVERIFY(domain1 == domain2); |
|
119 | QVERIFY(domain1 == domain2); | |
120 |
|
120 | |||
121 | dataSet.addDomain(rect, viewport); |
|
121 | dataSet.addDomain(rect, viewport); | |
122 | QCOMPARE(dataSet.domainIndex(), 1); |
|
122 | QCOMPARE(dataSet.domainIndex(), 1); | |
123 | Domain domain3 = dataSet.domain(dataSet.axisY()); |
|
123 | Domain domain3 = dataSet.domain(dataSet.axisY()); | |
124 | Domain domain4 = domain1.subDomain(rect, viewport.width(), |
|
124 | Domain domain4 = domain1.subDomain(rect, viewport.width(), | |
125 | viewport.height()); |
|
125 | viewport.height()); | |
126 | QVERIFY(domain3 == domain4); |
|
126 | QVERIFY(domain3 == domain4); | |
127 |
|
127 | |||
128 | QCOMPARE(spy0.count(), 0); |
|
128 | QCOMPARE(spy0.count(), 0); | |
129 | QCOMPARE(spy1.count(), 2); |
|
129 | QCOMPARE(spy1.count(), 2); | |
130 | QCOMPARE(spy2.count(), 0); |
|
130 | QCOMPARE(spy2.count(), 0); | |
131 | QCOMPARE(spy3.count(), 0); |
|
131 | QCOMPARE(spy3.count(), 0); | |
132 | QCOMPARE(spy4.count(), 1); |
|
132 | QCOMPARE(spy4.count(), 1); | |
133 | QCOMPARE(spy5.count(), 0); |
|
133 | QCOMPARE(spy5.count(), 0); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | void tst_ChartDataSet::addSeries_data() |
|
136 | void tst_ChartDataSet::addSeries_data() | |
137 | { |
|
137 | { | |
138 |
QTest::addColumn<int>(" |
|
138 | QTest::addColumn<int>("defaultAxisCount"); | |
139 |
|
|
139 | QTest::addColumn<int>("firstAxisCount"); | |
140 | QTest::newRow("2 series, default axis") << 2 << 0; |
|
140 | QTest::addColumn<int>("secoundAxisCount"); | |
141 |
QTest::newRow("2 |
|
141 | QTest::newRow("2 ,1 ,0") << 2 << 1 << 0; | |
142 |
QTest::newRow("2 series, |
|
142 | QTest::newRow("2 series, 2 new axis") << 2 << 0 << 2; | |
143 |
QTest::newRow(" |
|
143 | QTest::newRow("2 series, 1 new axis") << 2 << 0 << 2; | |
144 |
QTest::newRow("3 series, |
|
144 | QTest::newRow("3 series, 3 new axis") << 3 << 0 << 3; | |
145 |
QTest::newRow("3 series, |
|
145 | QTest::newRow("3 series, 2 new axis") << 3 << 0 << 2; | |
|
146 | QTest::newRow("3 series, 1 new axis") << 3 << 0 << 1; | |||
|
147 | QTest::newRow("3 series, default + 1 new axis") << 3 << 0 << 1; | |||
146 | } |
|
148 | } | |
147 |
|
149 | |||
148 | void tst_ChartDataSet::addSeries() |
|
150 | void tst_ChartDataSet::addSeries() | |
149 | { |
|
151 | { | |
150 |
|
|
152 | QFETCH(int, defaultAxisCount); | |
151 |
|
|
153 | QFETCH(int, firstAxisCount); | |
|
154 | QFETCH(int, secoundAxisCount); | |||
152 |
|
155 | |||
153 |
|
|
156 | ChartDataSet dataSet; | |
154 |
|
157 | |||
155 |
|
|
158 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |
156 | QSignalSpy spy1(&dataSet, |
|
159 | QSignalSpy spy1(&dataSet, SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); | |
157 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); |
|
160 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
158 |
|
|
161 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
159 |
|
|
162 | QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
160 | QSignalSpy spy4(&dataSet, |
|
163 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
161 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
|||
162 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
|||
163 |
|
164 | |||
164 | QList<QChartAxis*> axisList; |
|
165 | for (int i = 0; i < defaultAxisCount; i++) { | |
|
166 | QLineSeries* series = new QLineSeries(); | |||
|
167 | dataSet.addSeries(series); | |||
|
168 | } | |||
165 |
|
169 | |||
166 | for (int i = 0; i < axisYCount; i++) { |
|
170 | QChartAxis* firstAxis = new QChartAxis(); | |
167 | QChartAxis* axis = new QChartAxis(); |
|
|||
168 | axisList << axis; |
|
|||
169 | } |
|
|||
170 |
|
171 | |||
171 | QList<QChartAxis*>::iterator iterator = axisList.begin(); |
|
172 | for (int i = 0; i < firstAxisCount; i++) { | |
|
173 | QLineSeries* series = new QLineSeries(); | |||
|
174 | dataSet.addSeries(series, firstAxis); | |||
|
175 | } | |||
172 |
|
176 | |||
173 | for (int i = 0; i < seriesCount; i++) { |
|
177 | QChartAxis* secoundAxis = new QChartAxis(); | |
174 | QChartAxis* axisY = 0; |
|
178 | ||
175 | QLineSeries* series = new QLineSeries(); |
|
179 | for (int i = 0; i < secoundAxisCount; i++) { | |
176 | if (iterator != axisList.end()) { |
|
180 | QLineSeries* series = new QLineSeries(); | |
177 | axisY = *iterator; |
|
181 | dataSet.addSeries(series, secoundAxis); | |
178 | iterator++; |
|
182 | } | |
179 | } else if (axisList.count() > 0) { |
|
|||
180 | iterator--; |
|
|||
181 | axisY = *iterator; |
|
|||
182 | iterator++; |
|
|||
183 | } |
|
|||
184 | dataSet.addSeries(series, axisY); |
|
|||
185 | } |
|
|||
186 |
|
183 | |||
187 | //default axis |
|
184 | int axisCount = 1; | |
188 | if (axisYCount == 0) |
|
|||
189 | axisYCount+=2; |
|
|||
190 | else |
|
|||
191 | axisYCount++; |
|
|||
192 |
|
185 | |||
193 | QCOMPARE(spy0.count(), axisYCount); |
|
186 | if (defaultAxisCount > 0) | |
194 | QCOMPARE(spy1.count(), seriesCount*2); |
|
187 | axisCount++; | |
195 | QCOMPARE(spy2.count(), 0); |
|
188 | if (firstAxisCount > 0) | |
196 | QCOMPARE(spy3.count(), seriesCount); |
|
189 | axisCount++; | |
197 | QCOMPARE(spy4.count(), seriesCount); |
|
190 | if (secoundAxisCount > 0) | |
198 | QCOMPARE(spy5.count(), 0); |
|
191 | axisCount++; | |
199 |
|
192 | |||
200 | QCOMPARE(dataSet.domainIndex(), 0); |
|
193 | QCOMPARE(spy0.count(), axisCount); | |
|
194 | QCOMPARE(spy1.count(), (defaultAxisCount + firstAxisCount + secoundAxisCount)*2); | |||
|
195 | QCOMPARE(spy2.count(), 0); | |||
|
196 | QCOMPARE(spy3.count(), defaultAxisCount + firstAxisCount + secoundAxisCount); | |||
|
197 | ||||
|
198 | int i = 0; | |||
|
199 | while (defaultAxisCount) { | |||
|
200 | i+=defaultAxisCount; | |||
|
201 | defaultAxisCount--; | |||
|
202 | } | |||
|
203 | int j = 0; | |||
|
204 | while (firstAxisCount>0) { | |||
|
205 | j += firstAxisCount; | |||
|
206 | firstAxisCount--; | |||
|
207 | } | |||
|
208 | int k = 0; | |||
|
209 | while (secoundAxisCount>0) { | |||
|
210 | k += secoundAxisCount; | |||
|
211 | secoundAxisCount--; | |||
|
212 | } | |||
|
213 | QCOMPARE(spy4.count(),i + j + k); | |||
|
214 | QCOMPARE(spy5.count(), 0); | |||
|
215 | ||||
|
216 | QCOMPARE(dataSet.domainIndex(), 0); | |||
201 | } |
|
217 | } | |
202 |
|
218 | |||
203 | void tst_ChartDataSet::axisY_data() |
|
219 | void tst_ChartDataSet::axisY_data() | |
204 | { |
|
220 | { | |
205 | QTest::addColumn<QChartAxis*>("axisY"); |
|
221 | QTest::addColumn<QChartAxis*>("axisY"); | |
206 | QTest::newRow("axisY1") << new QChartAxis(); |
|
222 | QTest::newRow("axisY1") << new QChartAxis(); | |
207 | QTest::newRow("axisY2") << new QChartAxis(); |
|
223 | QTest::newRow("axisY2") << new QChartAxis(); | |
208 | } |
|
224 | } | |
209 |
|
225 | |||
210 | void tst_ChartDataSet::axisY() |
|
226 | void tst_ChartDataSet::axisY() | |
211 | { |
|
227 | { | |
212 | QFETCH(QChartAxis*, axisY); |
|
228 | QFETCH(QChartAxis*, axisY); | |
213 |
|
229 | |||
214 | ChartDataSet dataSet; |
|
230 | ChartDataSet dataSet; | |
215 |
|
231 | |||
216 | QChartAxis* defaultAxisY = dataSet.axisY(); |
|
232 | QChartAxis* defaultAxisY = dataSet.axisY(); | |
217 |
|
233 | |||
218 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
234 | QVERIFY2(defaultAxisY, "Missing axisY."); | |
219 |
|
235 | |||
220 | QLineSeries* series1 = new QLineSeries(); |
|
236 | QLineSeries* series1 = new QLineSeries(); | |
221 | dataSet.addSeries(series1); |
|
237 | dataSet.addSeries(series1); | |
222 |
|
238 | |||
223 | QLineSeries* series2 = new QLineSeries(); |
|
239 | QLineSeries* series2 = new QLineSeries(); | |
224 | dataSet.addSeries(series2, axisY); |
|
240 | dataSet.addSeries(series2, axisY); | |
225 |
|
241 | |||
226 | QVERIFY(dataSet.axisY(series1) == defaultAxisY); |
|
242 | QVERIFY(dataSet.axisY(series1) == defaultAxisY); | |
227 | QVERIFY(dataSet.axisY(series2) == axisY); |
|
243 | QVERIFY(dataSet.axisY(series2) == axisY); | |
228 |
|
244 | |||
229 |
|
245 | |||
230 | } |
|
246 | } | |
231 |
|
247 | |||
232 | void tst_ChartDataSet::clearDomains_data() |
|
248 | void tst_ChartDataSet::clearDomains_data() | |
233 | { |
|
249 | { | |
234 | QTest::addColumn<int>("indexCount"); |
|
250 | QTest::addColumn<int>("indexCount"); | |
235 | QTest::newRow("0") << 0; |
|
251 | QTest::newRow("0") << 0; | |
236 | QTest::newRow("1") << 1; |
|
252 | QTest::newRow("1") << 1; | |
237 | QTest::newRow("5") << 2; |
|
253 | QTest::newRow("5") << 2; | |
238 | QTest::newRow("8") << 3; |
|
254 | QTest::newRow("8") << 3; | |
239 | } |
|
255 | } | |
240 |
|
256 | |||
241 | void tst_ChartDataSet::clearDomains() |
|
257 | void tst_ChartDataSet::clearDomains() | |
242 | { |
|
258 | { | |
243 | QFETCH(int, indexCount); |
|
259 | QFETCH(int, indexCount); | |
244 |
|
260 | |||
245 | Domain domain1(0, 100, 0, 100); |
|
261 | Domain domain1(0, 100, 0, 100); | |
246 | QLineSeries* series = new QLineSeries(); |
|
262 | QLineSeries* series = new QLineSeries(); | |
247 | series->add(0, 0); |
|
263 | series->add(0, 0); | |
248 | series->add(100, 100); |
|
264 | series->add(100, 100); | |
249 |
|
265 | |||
250 | ChartDataSet dataSet; |
|
266 | ChartDataSet dataSet; | |
251 |
|
267 | |||
252 | QCOMPARE(dataSet.domainIndex(), 0); |
|
268 | QCOMPARE(dataSet.domainIndex(), 0); | |
253 |
|
269 | |||
254 | dataSet.addSeries(series); |
|
270 | dataSet.addSeries(series); | |
255 |
|
271 | |||
256 | Domain domain2 = dataSet.domain(dataSet.axisY()); |
|
272 | Domain domain2 = dataSet.domain(dataSet.axisY()); | |
257 |
|
273 | |||
258 | QVERIFY(domain2 == domain1); |
|
274 | QVERIFY(domain2 == domain1); | |
259 |
|
275 | |||
260 | QList<Domain> domains; |
|
276 | QList<Domain> domains; | |
261 |
|
277 | |||
262 | domains << domain1; |
|
278 | domains << domain1; | |
263 |
|
279 | |||
264 | for (int i = 0; i < indexCount; i++) { |
|
280 | for (int i = 0; i < indexCount; i++) { | |
265 | dataSet.addDomain(QRect(0, 0, 10, 10), QRect(0, 0, 100, 100)); |
|
281 | dataSet.addDomain(QRect(0, 0, 10, 10), QRect(0, 0, 100, 100)); | |
266 | domains << dataSet.domain(dataSet.axisY()); |
|
282 | domains << dataSet.domain(dataSet.axisY()); | |
267 | } |
|
283 | } | |
268 |
|
284 | |||
269 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
285 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |
270 | QSignalSpy spy1(&dataSet, |
|
286 | QSignalSpy spy1(&dataSet, | |
271 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); |
|
287 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); | |
272 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
288 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
273 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); |
|
289 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
274 | QSignalSpy spy4(&dataSet, |
|
290 | QSignalSpy spy4(&dataSet, | |
275 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
291 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
276 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
292 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
277 |
|
293 | |||
278 | dataSet.clearDomains(indexCount); |
|
294 | dataSet.clearDomains(indexCount); | |
279 |
|
295 | |||
280 | QCOMPARE(dataSet.domainIndex(), indexCount); |
|
296 | QCOMPARE(dataSet.domainIndex(), indexCount); | |
281 |
|
297 | |||
282 | domain2 = dataSet.domain(dataSet.axisY()); |
|
298 | domain2 = dataSet.domain(dataSet.axisY()); | |
283 |
|
299 | |||
284 | QVERIFY(domain2 == domains.at(indexCount)); |
|
300 | QVERIFY(domain2 == domains.at(indexCount)); | |
285 |
|
301 | |||
286 | QCOMPARE(spy0.count(), 0); |
|
302 | QCOMPARE(spy0.count(), 0); | |
287 | QCOMPARE(spy1.count(), 0); |
|
303 | QCOMPARE(spy1.count(), 0); | |
288 | QCOMPARE(spy2.count(), 0); |
|
304 | QCOMPARE(spy2.count(), 0); | |
289 | QCOMPARE(spy3.count(), 0); |
|
305 | QCOMPARE(spy3.count(), 0); | |
290 | QCOMPARE(spy4.count(), 0); |
|
306 | QCOMPARE(spy4.count(), 0); | |
291 | QCOMPARE(spy5.count(), 0); |
|
307 | QCOMPARE(spy5.count(), 0); | |
292 | } |
|
308 | } | |
293 |
|
309 | |||
294 | void tst_ChartDataSet::domain_data() |
|
310 | void tst_ChartDataSet::domain_data() | |
295 | { |
|
311 | { | |
296 | QTest::addColumn<Domain>("domain1"); |
|
312 | QTest::addColumn<Domain>("domain1"); | |
297 | QTest::addColumn<Domain>("domain2"); |
|
313 | QTest::addColumn<Domain>("domain2"); | |
298 | QTest::addColumn<Domain>("domain3"); |
|
314 | QTest::addColumn<Domain>("domain3"); | |
299 | QTest::addColumn<Domain>("domain"); |
|
315 | QTest::addColumn<Domain>("domain"); | |
300 | QTest::newRow("Domain(0,10,0,10)") << Domain(0, 10, 0, 10) |
|
316 | QTest::newRow("Domain(0,10,0,10)") << Domain(0, 10, 0, 10) | |
301 | << Domain(0, 5, 0, 5) << Domain(0, 3, 0, 3) << Domain(0, 10, 0, 10); |
|
317 | << Domain(0, 5, 0, 5) << Domain(0, 3, 0, 3) << Domain(0, 10, 0, 10); | |
302 | QTest::newRow("Domain(-1,11,0,11)") << Domain(-1, 10, 0, 10) |
|
318 | QTest::newRow("Domain(-1,11,0,11)") << Domain(-1, 10, 0, 10) | |
303 | << Domain(0, 11, 0, 11) << Domain(0, 3, 0, 3) |
|
319 | << Domain(0, 11, 0, 11) << Domain(0, 3, 0, 3) | |
304 | << Domain(-1, 11, 0, 11); |
|
320 | << Domain(-1, 11, 0, 11); | |
305 | QTest::newRow("Domain(-5,5,1,8)") << Domain(-5, 0, 1, 1) |
|
321 | QTest::newRow("Domain(-5,5,1,8)") << Domain(-5, 0, 1, 1) | |
306 | << Domain(0, 5, 0, 8) << Domain(1, 2, 1, 2) << Domain(-5, 5, 0, 8); |
|
322 | << Domain(0, 5, 0, 8) << Domain(1, 2, 1, 2) << Domain(-5, 5, 0, 8); | |
307 | } |
|
323 | } | |
308 |
|
324 | |||
309 | void tst_ChartDataSet::domain() |
|
325 | void tst_ChartDataSet::domain() | |
310 | { |
|
326 | { | |
311 | QFETCH(Domain, domain1); |
|
327 | QFETCH(Domain, domain1); | |
312 | QFETCH(Domain, domain2); |
|
328 | QFETCH(Domain, domain2); | |
313 | QFETCH(Domain, domain3); |
|
329 | QFETCH(Domain, domain3); | |
314 | QFETCH(Domain, domain); |
|
330 | QFETCH(Domain, domain); | |
315 |
|
331 | |||
316 | ChartDataSet dataSet; |
|
332 | ChartDataSet dataSet; | |
317 | QLineSeries* series1 = new QLineSeries(); |
|
333 | QLineSeries* series1 = new QLineSeries(); | |
318 | series1->add(domain1.m_minX, domain1.m_minY); |
|
334 | series1->add(domain1.m_minX, domain1.m_minY); | |
319 | series1->add(domain1.m_maxX, domain1.m_maxY); |
|
335 | series1->add(domain1.m_maxX, domain1.m_maxY); | |
320 | QLineSeries* series2 = new QLineSeries(); |
|
336 | QLineSeries* series2 = new QLineSeries(); | |
321 | series2->add(domain2.m_minX, domain2.m_minY); |
|
337 | series2->add(domain2.m_minX, domain2.m_minY); | |
322 | series2->add(domain2.m_maxX, domain2.m_maxY); |
|
338 | series2->add(domain2.m_maxX, domain2.m_maxY); | |
323 | QLineSeries* series3 = new QLineSeries(); |
|
339 | QLineSeries* series3 = new QLineSeries(); | |
324 | series3->add(domain3.m_minX, domain3.m_minY); |
|
340 | series3->add(domain3.m_minX, domain3.m_minY); | |
325 | series3->add(domain3.m_maxX, domain3.m_maxY); |
|
341 | series3->add(domain3.m_maxX, domain3.m_maxY); | |
326 |
|
342 | |||
327 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
343 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |
328 | QSignalSpy spy1(&dataSet, |
|
344 | QSignalSpy spy1(&dataSet, | |
329 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); |
|
345 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); | |
330 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
346 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
331 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); |
|
347 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
332 | QSignalSpy spy4(&dataSet, |
|
348 | QSignalSpy spy4(&dataSet, | |
333 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
349 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
334 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
350 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
335 |
|
351 | |||
336 | dataSet.addSeries(series1); |
|
352 | dataSet.addSeries(series1); | |
337 | dataSet.addSeries(series2); |
|
353 | dataSet.addSeries(series2); | |
338 | dataSet.addSeries(series3); |
|
354 | dataSet.addSeries(series3); | |
339 |
|
355 | |||
340 | QCOMPARE(dataSet.domainIndex(), 0); |
|
356 | QCOMPARE(dataSet.domainIndex(), 0); | |
341 | QVERIFY2(dataSet.domain(dataSet.axisY()) == domain, "Domain not equal"); |
|
357 | QVERIFY2(dataSet.domain(dataSet.axisY()) == domain, "Domain not equal"); | |
342 |
|
358 | |||
343 | QCOMPARE(spy0.count(), 2); |
|
359 | QCOMPARE(spy0.count(), 2); | |
344 | QCOMPARE(spy1.count(), 6); |
|
360 | QCOMPARE(spy1.count(), 6); | |
345 | QCOMPARE(spy2.count(), 0); |
|
361 | QCOMPARE(spy2.count(), 0); | |
346 | QCOMPARE(spy3.count(), 3); |
|
362 | QCOMPARE(spy3.count(), 3); | |
347 |
QCOMPARE(spy4.count(), |
|
363 | QCOMPARE(spy4.count(), 6); | |
348 | QCOMPARE(spy5.count(), 0); |
|
364 | QCOMPARE(spy5.count(), 0); | |
349 | } |
|
365 | } | |
350 |
|
366 | |||
351 | void tst_ChartDataSet::nextpreviousDomain_data() |
|
367 | void tst_ChartDataSet::nextpreviousDomain_data() | |
352 | { |
|
368 | { | |
353 | QTest::addColumn<QRectF>("rect"); |
|
369 | QTest::addColumn<QRectF>("rect"); | |
354 | QTest::addColumn<QRectF>("viewport"); |
|
370 | QTest::addColumn<QRectF>("viewport"); | |
355 | QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600) |
|
371 | QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600) | |
356 | << QRectF(0, 0, 1000, 1000); |
|
372 | << QRectF(0, 0, 1000, 1000); | |
357 | QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700) |
|
373 | QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700) | |
358 | << QRectF(0, 0, 1000, 1000); |
|
374 | << QRectF(0, 0, 1000, 1000); | |
359 | QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600) |
|
375 | QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600) | |
360 | << QRectF(0, 0, 1000, 1000); |
|
376 | << QRectF(0, 0, 1000, 1000); | |
361 | } |
|
377 | } | |
362 |
|
378 | |||
363 | void tst_ChartDataSet::nextpreviousDomain() |
|
379 | void tst_ChartDataSet::nextpreviousDomain() | |
364 | { |
|
380 | { | |
365 |
|
381 | |||
366 | QFETCH(QRectF, rect); |
|
382 | QFETCH(QRectF, rect); | |
367 | QFETCH(QRectF, viewport); |
|
383 | QFETCH(QRectF, viewport); | |
368 |
|
384 | |||
369 | ChartDataSet dataSet; |
|
385 | ChartDataSet dataSet; | |
370 |
|
386 | |||
371 | Domain domain1(0, 1000, 0, 1000); |
|
387 | Domain domain1(0, 1000, 0, 1000); | |
372 | QLineSeries* series = new QLineSeries(); |
|
388 | QLineSeries* series = new QLineSeries(); | |
373 | series->add(0, 0); |
|
389 | series->add(0, 0); | |
374 | series->add(1000, 1000); |
|
390 | series->add(1000, 1000); | |
375 |
|
391 | |||
376 | dataSet.addSeries(series); |
|
392 | dataSet.addSeries(series); | |
377 |
|
393 | |||
378 | QCOMPARE(dataSet.domainIndex(), 0); |
|
394 | QCOMPARE(dataSet.domainIndex(), 0); | |
379 |
|
395 | |||
380 | Domain domain2 = dataSet.domain(dataSet.axisY()); |
|
396 | Domain domain2 = dataSet.domain(dataSet.axisY()); | |
381 | QVERIFY(domain1 == domain2); |
|
397 | QVERIFY(domain1 == domain2); | |
382 |
|
398 | |||
383 | dataSet.addDomain(rect, viewport); |
|
399 | dataSet.addDomain(rect, viewport); | |
384 | QCOMPARE(dataSet.domainIndex(), 1); |
|
400 | QCOMPARE(dataSet.domainIndex(), 1); | |
385 | Domain domain3 = dataSet.domain(dataSet.axisY()); |
|
401 | Domain domain3 = dataSet.domain(dataSet.axisY()); | |
386 | Domain domain4 = domain1.subDomain(rect, viewport.width(), |
|
402 | Domain domain4 = domain1.subDomain(rect, viewport.width(), | |
387 | viewport.height()); |
|
403 | viewport.height()); | |
388 | QVERIFY(domain3 == domain4); |
|
404 | QVERIFY(domain3 == domain4); | |
389 |
|
405 | |||
390 | dataSet.addDomain(rect, viewport); |
|
406 | dataSet.addDomain(rect, viewport); | |
391 | QCOMPARE(dataSet.domainIndex(), 2); |
|
407 | QCOMPARE(dataSet.domainIndex(), 2); | |
392 | Domain domain5 = dataSet.domain(dataSet.axisY()); |
|
408 | Domain domain5 = dataSet.domain(dataSet.axisY()); | |
393 | Domain domain6 = domain3.subDomain(rect, viewport.width(), |
|
409 | Domain domain6 = domain3.subDomain(rect, viewport.width(), | |
394 | viewport.height()); |
|
410 | viewport.height()); | |
395 | QVERIFY(domain5 == domain6); |
|
411 | QVERIFY(domain5 == domain6); | |
396 |
|
412 | |||
397 | dataSet.addDomain(rect, viewport); |
|
413 | dataSet.addDomain(rect, viewport); | |
398 | QCOMPARE(dataSet.domainIndex(), 3); |
|
414 | QCOMPARE(dataSet.domainIndex(), 3); | |
399 | Domain domain7 = dataSet.domain(dataSet.axisY()); |
|
415 | Domain domain7 = dataSet.domain(dataSet.axisY()); | |
400 | Domain domain8 = domain5.subDomain(rect, viewport.width(), |
|
416 | Domain domain8 = domain5.subDomain(rect, viewport.width(), | |
401 | viewport.height()); |
|
417 | viewport.height()); | |
402 | QVERIFY(domain7 == domain8); |
|
418 | QVERIFY(domain7 == domain8); | |
403 |
|
419 | |||
404 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
420 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |
405 | QSignalSpy spy1(&dataSet, |
|
421 | QSignalSpy spy1(&dataSet, | |
406 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); |
|
422 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); | |
407 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
423 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
408 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); |
|
424 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
409 | QSignalSpy spy4(&dataSet, |
|
425 | QSignalSpy spy4(&dataSet, | |
410 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
426 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
411 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
427 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
412 |
|
428 | |||
413 | Domain domain; |
|
429 | Domain domain; | |
414 |
|
430 | |||
415 | bool previous = dataSet.previousDomain(); |
|
431 | bool previous = dataSet.previousDomain(); | |
416 | QCOMPARE(previous, true); |
|
432 | QCOMPARE(previous, true); | |
417 | QCOMPARE(dataSet.domainIndex(), 2); |
|
433 | QCOMPARE(dataSet.domainIndex(), 2); | |
418 | domain = dataSet.domain(dataSet.axisY()); |
|
434 | domain = dataSet.domain(dataSet.axisY()); | |
419 | QVERIFY(domain == domain5); |
|
435 | QVERIFY(domain == domain5); | |
420 | previous = dataSet.previousDomain(); |
|
436 | previous = dataSet.previousDomain(); | |
421 | QCOMPARE(previous, true); |
|
437 | QCOMPARE(previous, true); | |
422 | QCOMPARE(dataSet.domainIndex(), 1); |
|
438 | QCOMPARE(dataSet.domainIndex(), 1); | |
423 | domain = dataSet.domain(dataSet.axisY()); |
|
439 | domain = dataSet.domain(dataSet.axisY()); | |
424 | QVERIFY(domain == domain3); |
|
440 | QVERIFY(domain == domain3); | |
425 | previous = dataSet.previousDomain(); |
|
441 | previous = dataSet.previousDomain(); | |
426 | QCOMPARE(previous, true); |
|
442 | QCOMPARE(previous, true); | |
427 | QCOMPARE(dataSet.domainIndex(), 0); |
|
443 | QCOMPARE(dataSet.domainIndex(), 0); | |
428 | domain = dataSet.domain(dataSet.axisY()); |
|
444 | domain = dataSet.domain(dataSet.axisY()); | |
429 | QVERIFY(domain == domain1); |
|
445 | QVERIFY(domain == domain1); | |
430 | previous = dataSet.previousDomain(); |
|
446 | previous = dataSet.previousDomain(); | |
431 | QCOMPARE(previous, false); |
|
447 | QCOMPARE(previous, false); | |
432 | QCOMPARE(dataSet.domainIndex(), 0); |
|
448 | QCOMPARE(dataSet.domainIndex(), 0); | |
433 | domain = dataSet.domain(dataSet.axisY()); |
|
449 | domain = dataSet.domain(dataSet.axisY()); | |
434 | QVERIFY(domain == domain1); |
|
450 | QVERIFY(domain == domain1); | |
435 |
|
451 | |||
436 | bool next = dataSet.nextDomain(); |
|
452 | bool next = dataSet.nextDomain(); | |
437 | QCOMPARE(next, true); |
|
453 | QCOMPARE(next, true); | |
438 | QCOMPARE(dataSet.domainIndex(),1); |
|
454 | QCOMPARE(dataSet.domainIndex(),1); | |
439 | next = dataSet.nextDomain(); |
|
455 | next = dataSet.nextDomain(); | |
440 | QCOMPARE(next, true); |
|
456 | QCOMPARE(next, true); | |
441 | QCOMPARE(dataSet.domainIndex(),2); |
|
457 | QCOMPARE(dataSet.domainIndex(),2); | |
442 | next = dataSet.nextDomain(); |
|
458 | next = dataSet.nextDomain(); | |
443 | QCOMPARE(next, true); |
|
459 | QCOMPARE(next, true); | |
444 | QCOMPARE(dataSet.domainIndex(),3); |
|
460 | QCOMPARE(dataSet.domainIndex(),3); | |
445 | next = dataSet.nextDomain(); |
|
461 | next = dataSet.nextDomain(); | |
446 | QCOMPARE(next, false); |
|
462 | QCOMPARE(next, false); | |
447 | QCOMPARE(dataSet.domainIndex(),3); |
|
463 | QCOMPARE(dataSet.domainIndex(),3); | |
448 |
|
464 | |||
449 |
|
465 | |||
450 | QCOMPARE(spy0.count(), 0); |
|
466 | QCOMPARE(spy0.count(), 0); | |
451 | QCOMPARE(spy1.count(), 12); |
|
467 | QCOMPARE(spy1.count(), 12); | |
452 | QCOMPARE(spy2.count(), 0); |
|
468 | QCOMPARE(spy2.count(), 0); | |
453 | QCOMPARE(spy3.count(), 0); |
|
469 | QCOMPARE(spy3.count(), 0); | |
454 | QCOMPARE(spy4.count(), 6); |
|
470 | QCOMPARE(spy4.count(), 6); | |
455 | QCOMPARE(spy5.count(), 0); |
|
471 | QCOMPARE(spy5.count(), 0); | |
456 | } |
|
472 | } | |
457 |
|
473 | |||
458 | void tst_ChartDataSet::removeSeries_data() |
|
474 | void tst_ChartDataSet::removeSeries_data() | |
459 | { |
|
475 | { | |
460 | QTest::addColumn<int>("seriesCount"); |
|
476 | QTest::addColumn<int>("seriesCount"); | |
461 | QTest::addColumn<int>("axisYCount"); |
|
477 | QTest::addColumn<int>("axisYCount"); | |
462 | QTest::newRow("2 series, default axis") << 2 << 0; |
|
478 | QTest::newRow("2 series, default axis") << 2 << 0; | |
463 | QTest::newRow("2 series, 2 new axis") << 2 << 2; |
|
479 | QTest::newRow("2 series, 2 new axis") << 2 << 2; | |
464 | QTest::newRow("2 series, 1 new axis") << 2 << 2; |
|
480 | QTest::newRow("2 series, 1 new axis") << 2 << 2; | |
465 | QTest::newRow("3 series, 3 new axis") << 3 << 3; |
|
481 | QTest::newRow("3 series, 3 new axis") << 3 << 3; | |
466 | QTest::newRow("3 series, 2 new axis") << 3 << 2; |
|
482 | QTest::newRow("3 series, 2 new axis") << 3 << 2; | |
467 | QTest::newRow("3 series, 1 new axis") << 3 << 1; |
|
483 | QTest::newRow("3 series, 1 new axis") << 3 << 1; | |
468 | } |
|
484 | } | |
469 |
|
485 | |||
470 | void tst_ChartDataSet::removeSeries() |
|
486 | void tst_ChartDataSet::removeSeries() | |
471 | { |
|
487 | { | |
472 | QFETCH(int, seriesCount); |
|
488 | QFETCH(int, seriesCount); | |
473 | QFETCH(int, axisYCount); |
|
489 | QFETCH(int, axisYCount); | |
474 |
|
490 | |||
475 | ChartDataSet dataSet; |
|
491 | ChartDataSet dataSet; | |
476 |
|
492 | |||
477 | QList<QChartAxis*> axisList; |
|
493 | QList<QChartAxis*> axisList; | |
478 | QList<QSeries*> seriesList; |
|
494 | QList<QSeries*> seriesList; | |
479 |
|
495 | |||
480 | for (int i = 0; i < axisYCount; i++) { |
|
496 | for (int i = 0; i < axisYCount; i++) { | |
481 | QChartAxis* axis = new QChartAxis(); |
|
497 | QChartAxis* axis = new QChartAxis(); | |
482 | axisList << axis; |
|
498 | axisList << axis; | |
483 | } |
|
499 | } | |
484 |
|
500 | |||
485 | QList<QChartAxis*>::iterator iterator = axisList.begin(); |
|
501 | QList<QChartAxis*>::iterator iterator = axisList.begin(); | |
486 |
|
502 | |||
487 | for (int i = 0; i < seriesCount; i++) { |
|
503 | for (int i = 0; i < seriesCount; i++) { | |
488 | QChartAxis* axisY = 0; |
|
504 | QChartAxis* axisY = 0; | |
489 | QLineSeries* series = new QLineSeries(); |
|
505 | QLineSeries* series = new QLineSeries(); | |
490 | if (iterator != axisList.end()) { |
|
506 | if (iterator != axisList.end()) { | |
491 | axisY = *iterator; |
|
507 | axisY = *iterator; | |
492 | iterator++; |
|
508 | iterator++; | |
493 | } else if (axisList.count() > 0) { |
|
509 | } else if (axisList.count() > 0) { | |
494 | iterator--; |
|
510 | iterator--; | |
495 | axisY = *iterator; |
|
511 | axisY = *iterator; | |
496 | iterator++; |
|
512 | iterator++; | |
497 | } |
|
513 | } | |
498 | dataSet.addSeries(series, axisY); |
|
514 | dataSet.addSeries(series, axisY); | |
499 | seriesList << series; |
|
515 | seriesList << series; | |
500 | } |
|
516 | } | |
501 |
|
517 | |||
502 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
518 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |
503 | QSignalSpy spy1(&dataSet, |
|
519 | QSignalSpy spy1(&dataSet, | |
504 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); |
|
520 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); | |
505 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
521 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
506 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); |
|
522 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
507 | QSignalSpy spy4(&dataSet, |
|
523 | QSignalSpy spy4(&dataSet, | |
508 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
524 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
509 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
525 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
510 |
|
526 | |||
511 | for (int i = 0; i < seriesCount; i++) { |
|
527 | for (int i = 0; i < seriesCount; i++) { | |
512 | dataSet.removeSeries(seriesList.at(i)); |
|
528 | dataSet.removeSeries(seriesList.at(i)); | |
513 | } |
|
529 | } | |
514 |
|
530 | |||
515 | //default axis |
|
531 | //default axis | |
516 | if (axisYCount == 0) |
|
532 | if (axisYCount == 0) | |
517 | axisYCount++; |
|
533 | axisYCount++; | |
518 |
|
534 | |||
519 | QCOMPARE(spy0.count(), 0); |
|
535 | QCOMPARE(spy0.count(), 0); | |
520 | QCOMPARE(spy1.count(), 0); |
|
536 | QCOMPARE(spy1.count(), 0); | |
521 | QCOMPARE(spy2.count(), axisYCount); |
|
537 | QCOMPARE(spy2.count(), axisYCount); | |
522 | QCOMPARE(spy3.count(), 0); |
|
538 | QCOMPARE(spy3.count(), 0); | |
523 | QCOMPARE(spy4.count(), 0); |
|
539 | QCOMPARE(spy4.count(), 0); | |
524 | QCOMPARE(spy5.count(), seriesCount); |
|
540 | QCOMPARE(spy5.count(), seriesCount); | |
525 |
|
541 | |||
526 | QCOMPARE(dataSet.domainIndex(), 0); |
|
542 | QCOMPARE(dataSet.domainIndex(), 0); | |
527 |
|
543 | |||
528 | qDeleteAll(seriesList); |
|
544 | qDeleteAll(seriesList); | |
529 | } |
|
545 | } | |
530 |
|
546 | |||
531 | void tst_ChartDataSet::removeAllSeries_data() |
|
547 | void tst_ChartDataSet::removeAllSeries_data() | |
532 | { |
|
548 | { | |
533 | QTest::addColumn<int>("seriesCount"); |
|
549 | QTest::addColumn<int>("seriesCount"); | |
534 | QTest::addColumn<int>("axisYCount"); |
|
550 | QTest::addColumn<int>("axisYCount"); | |
535 | QTest::newRow("2 series, default axis") << 2 << 0; |
|
551 | QTest::newRow("2 series, default axis") << 2 << 0; | |
536 | QTest::newRow("2 series, 2 new axis") << 2 << 2; |
|
552 | QTest::newRow("2 series, 2 new axis") << 2 << 2; | |
537 | QTest::newRow("2 series, 1 new axis") << 2 << 2; |
|
553 | QTest::newRow("2 series, 1 new axis") << 2 << 2; | |
538 | QTest::newRow("3 series, 3 new axis") << 3 << 3; |
|
554 | QTest::newRow("3 series, 3 new axis") << 3 << 3; | |
539 | QTest::newRow("3 series, 2 new axis") << 3 << 2; |
|
555 | QTest::newRow("3 series, 2 new axis") << 3 << 2; | |
540 | QTest::newRow("3 series, 1 new axis") << 3 << 1; |
|
556 | QTest::newRow("3 series, 1 new axis") << 3 << 1; | |
541 | } |
|
557 | } | |
542 |
|
558 | |||
543 | void tst_ChartDataSet::removeAllSeries() |
|
559 | void tst_ChartDataSet::removeAllSeries() | |
544 | { |
|
560 | { | |
545 | QFETCH(int, seriesCount); |
|
561 | QFETCH(int, seriesCount); | |
546 | QFETCH(int, axisYCount); |
|
562 | QFETCH(int, axisYCount); | |
547 |
|
563 | |||
548 | ChartDataSet dataSet; |
|
564 | ChartDataSet dataSet; | |
549 |
|
565 | |||
550 | QList<QChartAxis*> axisList; |
|
566 | QList<QChartAxis*> axisList; | |
551 |
|
567 | |||
552 | for (int i = 0; i < axisYCount; i++) { |
|
568 | for (int i = 0; i < axisYCount; i++) { | |
553 | QChartAxis* axis = new QChartAxis(); |
|
569 | QChartAxis* axis = new QChartAxis(); | |
554 | axisList << axis; |
|
570 | axisList << axis; | |
555 | } |
|
571 | } | |
556 |
|
572 | |||
557 | QList<QChartAxis*>::iterator iterator = axisList.begin(); |
|
573 | QList<QChartAxis*>::iterator iterator = axisList.begin(); | |
558 |
|
574 | |||
559 | for (int i = 0; i < seriesCount; i++) { |
|
575 | for (int i = 0; i < seriesCount; i++) { | |
560 | QChartAxis* axisY = 0; |
|
576 | QChartAxis* axisY = 0; | |
561 | QLineSeries* series = new QLineSeries(); |
|
577 | QLineSeries* series = new QLineSeries(); | |
562 | if (iterator != axisList.end()) { |
|
578 | if (iterator != axisList.end()) { | |
563 | axisY = *iterator; |
|
579 | axisY = *iterator; | |
564 | iterator++; |
|
580 | iterator++; | |
565 | } else if (axisList.count() > 0) { |
|
581 | } else if (axisList.count() > 0) { | |
566 | iterator--; |
|
582 | iterator--; | |
567 | axisY = *iterator; |
|
583 | axisY = *iterator; | |
568 | iterator++; |
|
584 | iterator++; | |
569 | } |
|
585 | } | |
570 | dataSet.addSeries(series, axisY); |
|
586 | dataSet.addSeries(series, axisY); | |
571 | } |
|
587 | } | |
572 |
|
588 | |||
573 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
589 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); | |
574 | QSignalSpy spy1(&dataSet, SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); |
|
590 | QSignalSpy spy1(&dataSet, SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); | |
575 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
591 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
576 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); |
|
592 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
577 | QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
593 | QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
578 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
594 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
579 |
|
595 | |||
580 | dataSet.removeAllSeries(); |
|
596 | dataSet.removeAllSeries(); | |
581 | //default axis |
|
597 | //default axis | |
582 | if (axisYCount == 0) |
|
598 | if (axisYCount == 0) | |
583 | axisYCount++; |
|
599 | axisYCount++; | |
584 |
|
600 | |||
585 | QCOMPARE(spy0.count(), 0); |
|
601 | QCOMPARE(spy0.count(), 0); | |
586 | QCOMPARE(spy1.count(), 0); |
|
602 | QCOMPARE(spy1.count(), 0); | |
587 | QCOMPARE(spy2.count(), axisYCount); |
|
603 | QCOMPARE(spy2.count(), axisYCount); | |
588 | QCOMPARE(spy3.count(), 0); |
|
604 | QCOMPARE(spy3.count(), 0); | |
589 | QCOMPARE(spy4.count(), 0); |
|
605 | QCOMPARE(spy4.count(), 0); | |
590 | QCOMPARE(spy5.count(), seriesCount); |
|
606 | QCOMPARE(spy5.count(), seriesCount); | |
591 |
|
607 | |||
592 | QCOMPARE(dataSet.domainIndex(), 0); |
|
608 | QCOMPARE(dataSet.domainIndex(), 0); | |
593 | } |
|
609 | } | |
594 |
|
610 | |||
595 |
|
611 | |||
596 | QTEST_MAIN(tst_ChartDataSet) |
|
612 | QTEST_MAIN(tst_ChartDataSet) | |
597 | #include "tst_chartdataset.moc" |
|
613 | #include "tst_chartdataset.moc" | |
598 |
|
614 |
General Comments 0
You need to be logged in to leave comments.
Login now