##// 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();
326
327 if(axis==axisX()) {
328
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 }
336 344
337 345 }
346 else {
347
348 QList<Domain> domains = m_domainMap.values(axis);
349 m_domainMap.remove(axis);
338 350
339 void ChartDataSet::handleMaxChanged(qreal max)
351 for(int i=0;i<domains.size();i++)
340 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 */
@@ -280,7 +290,7 void QChartAxis::setMin(qreal min)
280 290 {
281 291 if(m_min!=min){
282 292 m_min=min;
283 emit minChanged(m_min);
293 emit rangeChanged(this);
284 294 }
285 295 }
286 296
@@ -291,7 +301,7 void QChartAxis::setMax(qreal max)
291 301 {
292 302 if(m_max!=max){
293 303 m_max=max;
294 emit maxChanged(m_max);
304 emit rangeChanged(this);
295 305 }
296 306 }
297 307
@@ -304,6 +314,20 void QChartAxis::setRange(qreal min, qreal max)
304 314 setMax(max);
305 315 }
306 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;
329 }
330
307 331 /*!
308 332 Sets \a count for ticks on the axis.
309 333 */
@@ -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