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