##// END OF EJS Templates
Adds plotArea()...
Michal Klocek -
r1648:8b084e770b03
parent child
Show More
@@ -21,12 +21,15
21 21 #include "chart.h"
22 22 #include <QAbstractAxis>
23 23 #include <QSplineSeries>
24 #include <QValuesAxis>
24 25 #include <QTime>
26 #include <QDebug>
25 27
26 28 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
27 29 :QChart(parent, wFlags),
28 m_step(1),
29 m_x(0),
30 m_step(0),
31 m_axis(new QValuesAxis),
32 m_x(5),
30 33 m_y(1)
31 34 {
32 35 qsrand((uint) QTime::currentTime().msec());
@@ -42,10 +45,10 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
42 45
43 46 addSeries(m_series);
44 47 createDefaultAxes();
45
46 axisY()->setRange(-5, 5);
47 axisX()->setRange(-9, 1);
48 //TODO:axisX()->setTicksCount(11);
48 setAxisX(m_axis,m_series);
49 m_axis->setTicksCount(5);
50 axisX()->setRange(0, 10);
51 axisY()->setRange(-5, 10);
49 52
50 53 m_timer.start();
51 54 }
@@ -57,9 +60,11 Chart::~Chart()
57 60
58 61 void Chart::handleTimeout()
59 62 {
60 m_x += m_step;
63 qreal x = plotArea().width()/m_axis->ticksCount();
64 qreal y =(m_axis->max() - m_axis->min())/m_axis->ticksCount();
65 m_x += y;
61 66 m_y = qrand() % 5 - 2.5;
62 67 m_series->append(m_x, m_y);
63 scroll(10,0);
68 scroll(x,0);
64 69 if(m_x==100) m_timer.stop();
65 70 }
@@ -26,6 +26,7
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28 class QSplineSeries;
29 class QValuesAxis;
29 30 QTCOMMERCIALCHART_END_NAMESPACE
30 31
31 32 QTCOMMERCIALCHART_USE_NAMESPACE
@@ -45,6 +46,7 private:
45 46 QTimer m_timer;
46 47 QSplineSeries* m_series;
47 48 QStringList m_titles;
49 QValuesAxis* m_axis;
48 50 qreal m_step;
49 51 qreal m_x;
50 52 qreal m_y;
@@ -451,7 +451,7 void ChartPresenter::setMarginsMinimum(const QRectF& margins)
451 451
452 452 QRectF ChartPresenter::margins() const
453 453 {
454 return QRectF();//m_layout->margins();
454 return m_layout->margins();
455 455 }
456 456
457 457 QLegend* ChartPresenter::legend()
@@ -379,6 +379,11 QRectF QChart::margins() const
379 379 return d_ptr->m_presenter->margins();
380 380 }
381 381
382 QRectF QChart::plotArea() const
383 {
384 return d_ptr->m_presenter->geometry();
385 }
386
382 387 /*!
383 388 Sets animation \a options for the chart
384 389 */
@@ -117,6 +117,7 public:
117 117
118 118 void setMarginsMinimum(const QRectF& margins);
119 119 QRectF margins() const;
120 QRectF plotArea() const;
120 121
121 122 Q_SIGNALS:
122 123 void marginsChanged(QRectF newMargins);
General Comments 0
You need to be logged in to leave comments. Login now