##// END OF EJS Templates
Adds axis setRange implementation
Michal Klocek -
r400:911bb45e5e52
parent child
Show More
@@ -51,6 +51,8 int main(int argc, char *argv[])
51 51 axisX->addAxisTickLabel(0,"low");
52 52 axisX->addAxisTickLabel(50,"medium");
53 53 axisX->addAxisTickLabel(100,"High");
54 axisX->setMin(-10);
55 axisX->setMax(200);
54 56
55 57 QChartAxis* axisY = chartView->axisY();
56 58 axisY->setLabelsAngle(45);
@@ -58,6 +60,8 int main(int argc, char *argv[])
58 60 axisY->addAxisTickLabel(0,"low");
59 61 axisY->addAxisTickLabel(50,"medium");
60 62 axisY->addAxisTickLabel(100,"High");
63 axisY->setMin(-10);
64 axisY->setMax(200);
61 65
62 66 window.setCentralWidget(chartView);
63 67 window.resize(400, 300);
@@ -134,28 +134,22 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
134 134 if(!m_domainMap.contains(axisY))
135 135 {
136 136 emit axisAdded(axisY);
137 QObject::connect(axisY,SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal)));
138 QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal)));
137 QObject::connect(axisY,SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*)));
139 138 QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*)));
140 139 }
141 m_domainMap.replace(axisY,domain);
142 m_seriesMap.insert(axisY,series);
143 140
144 141 if(!m_axisXInitialized)
145 142 {
146 143 emit axisAdded(axisX());
147 QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal)));
148 QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal)));
144 QObject::connect(axisX(),SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*)));
149 145 QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*)));
150 146 m_axisXInitialized=true;
151 147 }
152 148
153 QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY);
154 QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
155 emit axisRangeChanged(axisY,ylabels);
156 emit axisRangeChanged(axisX(),xlabels);
149 m_domainMap.replace(axisY,domain);
150 m_seriesMap.insert(axisY,series);
157 151 emit seriesAdded(series);
158 emit seriesDomainChanged(series,domain);
152 setDomain(m_domainIndex);
159 153
160 154 }
161 155
@@ -240,10 +234,13 void ChartDataSet::setDomain(int index)
240 234 foreach(QSeries* series, seriesList) {
241 235 emit seriesDomainChanged(series,domain);
242 236 }
237 axis->setRange(domain.m_minY,domain.m_maxY);
243 238 emit axisRangeChanged(axis,labels);
239
244 240 }
245 241
246 242 QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
243 axisX()->setRange(domain.m_minX,domain.m_maxY);
247 244 emit axisRangeChanged(axisX(),labels);
248 245 }
249 246
@@ -281,19 +278,10 void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport)
281 278
282 279 foreach (QChartAxis* axis , domainList){
283 280 domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height());
284 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
285 QList<QSeries*> seriesList = m_seriesMap.values(axis);
286 foreach(QSeries* series, seriesList){
287 emit seriesDomainChanged(series,domain);
288 }
289 emit axisRangeChanged(axis,labels);
290 281 m_domainMap.insert(axis,domain);
291 282 }
292 283
293 QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
294 emit axisRangeChanged(axisX(),labels);
295
296 m_domainIndex++;
284 setDomain(++m_domainIndex);
297 285 }
298 286
299 287 QChartAxis* ChartDataSet::axisY(QSeries* series) const
@@ -331,23 +319,56 QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max)
331 319 }
332 320
333 321
334 void ChartDataSet::handleMinChanged(qreal min)
322 void ChartDataSet::handleRangeChanged(QChartAxis* axis)
335 323 {
324 qreal min = axis->min();
325 qreal max = axis->max();
336 326
337 }
327 if(axis==axisX()) {
338 328
339 void ChartDataSet::handleMaxChanged(qreal max)
340 {
329 m_domainIndex=0;
330
331 clearDomains(m_domainIndex);
332
333 QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
334
335 foreach (QChartAxis* axis , domainList) {
336
337 Q_ASSERT(m_domainMap.values(axis).size()==1);
338
339 Domain domain = m_domainMap.value(axis);
340 domain.m_minX=min;
341 domain.m_maxX=max;
342 m_domainMap.replace(axis,domain);
343 }
344
345 }
346 else {
347
348 QList<Domain> domains = m_domainMap.values(axis);
349 m_domainMap.remove(axis);
350
351 for(int i=0;i<domains.size();i++)
352 {
353 domains[i].m_minY=min;
354 domains[i].m_maxY=max;
355 }
356
357 for(int j=domains.size()-1; j>=0;j--)
358 m_domainMap.insert(axis,domains.at(j));
359 }
341 360
361 setDomain(m_domainIndex);
342 362 }
343 363
344 364 void ChartDataSet::handleTickChanged(QChartAxis* axis)
345 365 {
346 Domain domain = m_domainMap.value(axisY());
347 366 if(axis==axisX()){
367 Domain domain = m_domainMap.value(axisY());
348 368 QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX);
349 369 emit axisRangeChanged(axis,labels);
350 370 }else{
371 Domain domain = m_domainMap.value(axis);
351 372 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
352 373 emit axisRangeChanged(axis,labels);
353 374 }
@@ -39,8 +39,7 signals:
39 39 void seriesDomainChanged(QSeries* series,const Domain& domain);
40 40
41 41 private slots:
42 void handleMinChanged(qreal min);
43 void handleMaxChanged(qreal max);
42 void handleRangeChanged(QChartAxis*);
44 43 void handleTickChanged(QChartAxis*);
45 44
46 45 private:
@@ -58,7 +58,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
58 58 */
59 59
60 60 /*!
61 \fn void QLineSeries::updated(int index)
61 \fn void QLineSeries::updated()
62 62 \brief \internal
63 63 */
64 64
@@ -130,6 +130,16 QTCOMMERCIALCHART_BEGIN_NAMESPACE
130 130 */
131 131
132 132 /*!
133 \fn void QChartAxis::rangeChanged(QChartAxis*)
134 \brief \internal
135 */
136
137 /*!
138 \fn void QChartAxis::updateRange(qreal min, qreal max)
139 \brief \internal \a min \a max
140 */
141
142 /*!
133 143 Constructs new axis object which is a child of \a parent. Ownership is taken by
134 144 QChatView or QChart when axis added.
135 145 */
@@ -274,25 +284,25 void QChartAxis::setShadesOpacity(qreal opacity)
274 284 }
275 285
276 286 /*!
277 Sets \a min value on the axis.
287 Sets \a min value on the axis.
278 288 */
279 289 void QChartAxis::setMin(qreal min)
280 290 {
281 if(m_min!=min){
282 m_min=min;
283 emit minChanged(m_min);
284 }
291 if(m_min!=min) {
292 m_min=min;
293 emit rangeChanged(this);
294 }
285 295 }
286 296
287 297 /*!
288 Sets \a max value on the axis.
298 Sets \a max value on the axis.
289 299 */
290 300 void QChartAxis::setMax(qreal max)
291 301 {
292 if(m_max!=max){
293 m_max=max;
294 emit maxChanged(m_max);
295 }
302 if(m_max!=max) {
303 m_max=max;
304 emit rangeChanged(this);
305 }
296 306 }
297 307
298 308 /*!
@@ -300,8 +310,22 void QChartAxis::setMax(qreal max)
300 310 */
301 311 void QChartAxis::setRange(qreal min, qreal max)
302 312 {
303 setMin(min);
304 setMax(max);
313 setMin(min);
314 setMax(max);
315 }
316
317 void QChartAxis::updateRange(qreal min, qreal max)
318 {
319 if(m_max!=max){
320 emit maxChanged(max);
321 }
322
323 if(m_min!=min){
324 emit minChanged(min);
325 }
326
327 m_max=max;
328 m_min=min;
305 329 }
306 330
307 331 /*!
@@ -64,11 +64,15 public:
64 64 QString axisTickLabel(qreal value) const ;
65 65 void clearAxisTickLabels();
66 66
67 //internal
68 void updateRange(qreal min, qreal max);
69
67 70 signals:
68 71 void minChanged(qreal min);
69 72 void maxChanged(qreal max);
70 73 //private signal
71 74 void update(QChartAxis*);
75 void rangeChanged(QChartAxis*);
72 76 void ticksChanged(QChartAxis*);
73 77
74 78 private:
General Comments 0
You need to be logged in to leave comments. Login now