diff options
author | Jani Honkonen <jani.honkonen@digia.com> | 2012-04-11 13:14:59 +0300 |
---|---|---|
committer | Jani Honkonen <jani.honkonen@digia.com> | 2012-04-11 13:31:41 +0300 |
commit | 7e0bb451a8c03b6df459ba5a6af8fd854d094e86 (patch) | |
tree | 499c42db4c37b58b7b35c377030c71b45a2f4d68 /demos | |
parent | dc6e36e81b8a5650c2a11dd7a847e030f426a46d (diff) |
Move dynamicspline under demos
Diffstat (limited to 'demos')
-rw-r--r-- | demos/demos.pro | 3 | ||||
-rw-r--r-- | demos/dynamicspline/chart.cpp | 65 | ||||
-rw-r--r-- | demos/dynamicspline/chart.h | 54 | ||||
-rw-r--r-- | demos/dynamicspline/dynamicspline.pro | 4 | ||||
-rw-r--r-- | demos/dynamicspline/main.cpp | 41 |
5 files changed, 166 insertions, 1 deletions
diff --git a/demos/demos.pro b/demos/demos.pro index 4f7390fc..1897190e 100644 --- a/demos/demos.pro +++ b/demos/demos.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs SUBDIRS += chartthemes \ piechartcustomization \ - qmlchart + qmlchart \ + dynamicspline diff --git a/demos/dynamicspline/chart.cpp b/demos/dynamicspline/chart.cpp new file mode 100644 index 00000000..5d8cc28f --- /dev/null +++ b/demos/dynamicspline/chart.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "chart.h" +#include <QChartAxis> +#include <QSplineSeries> +#include <QTime> + +Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) + :QChart(parent, wFlags), + m_step(1), + m_x(0), + m_y(1) +{ + qsrand((uint) QTime::currentTime().msec()); + + QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout())); + m_timer.setInterval(1000); + + m_series = new QSplineSeries(this); + QPen green(Qt::red); + green.setWidth(3); + m_series->setPen(green); + m_series->append(m_x, m_y); + + addSeries(m_series); + + axisY()->setRange(-5, 5); + axisX()->setRange(-9, 1); + axisX()->setTicksCount(11); + + m_timer.start(); +} + +Chart::~Chart() +{ + +} + +void Chart::handleTimeout() +{ + m_x += m_step; + m_y = qrand() % 5 - 2.5; + m_series->append(m_x, m_y); + if (m_x >= 10) + m_series->remove(m_x - 10); + scrollRight(); +} diff --git a/demos/dynamicspline/chart.h b/demos/dynamicspline/chart.h new file mode 100644 index 00000000..7611dfab --- /dev/null +++ b/demos/dynamicspline/chart.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CHART_H_ +#define CHART_H_ + +#include <QChart> +#include <QTimer> + +QTCOMMERCIALCHART_BEGIN_NAMESPACE +class QSplineSeries; +QTCOMMERCIALCHART_END_NAMESPACE + +QTCOMMERCIALCHART_USE_NAMESPACE + +//![1] +class Chart: public QChart +{ + Q_OBJECT +public: + Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); + virtual ~Chart(); + +public slots: + void handleTimeout(); + +private: + QTimer m_timer; + QSplineSeries* m_series; + QStringList m_titles; + qreal m_step; + qreal m_x; + qreal m_y; +}; +//![1] + +#endif /* CHART_H_ */ diff --git a/demos/dynamicspline/dynamicspline.pro b/demos/dynamicspline/dynamicspline.pro new file mode 100644 index 00000000..697a864e --- /dev/null +++ b/demos/dynamicspline/dynamicspline.pro @@ -0,0 +1,4 @@ +!include( ../demos.pri ):error( "Couldn't find the demos.pri file!" ) +TARGET = dynamicspline +HEADERS += chart.h +SOURCES += main.cpp chart.cpp diff --git a/demos/dynamicspline/main.cpp b/demos/dynamicspline/main.cpp new file mode 100644 index 00000000..bea00b3a --- /dev/null +++ b/demos/dynamicspline/main.cpp @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "chart.h" +#include <QChartView> +#include <QApplication> +#include <QMainWindow> + +QTCOMMERCIALCHART_USE_NAMESPACE + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + QMainWindow window; + Chart *chart = new Chart; + chart->setTitle("Dynamic spline chart"); + chart->setAnimationOptions(QChart::AllAnimations); + QChartView chartView(chart); + chartView.setRenderHint(QPainter::Antialiasing); + window.setCentralWidget(&chartView); + window.resize(400, 300); + window.show(); + return a.exec(); +} |