File indexing completed on 2024-06-16 04:09:02

0001 /**
0002  * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #ifndef MODEL_H
0010 #define MODEL_H
0011 
0012 #include <QAbstractItemModel>
0013 #include <QTimer>
0014 #include <QVector>
0015 
0016 class Model : public QAbstractItemModel
0017 {
0018     Q_OBJECT
0019 public:
0020     enum Function {
0021         SineFunction = 0,
0022         TriangleFunction,
0023         SquareFunction,
0024         NoiseFunction,
0025         OneDivSineFunction,
0026         SineOneDivFunction
0027     };
0028     Model();
0029 
0030     int columnCount( const QModelIndex& parent ) const override;
0031     int rowCount( const QModelIndex& parent ) const override;
0032 
0033     QModelIndex index( int row, int column, const QModelIndex& parent ) const override;
0034     QModelIndex parent( const QModelIndex& index ) const override;
0035 
0036     QVariant data( const QModelIndex& index, int role ) const override;
0037 
0038     void setFunction( Function f );
0039 
0040     void appendPoints( int numPoints );
0041 
0042 public Q_SLOTS:
0043     void setRunning( bool );
0044 
0045 private Q_SLOTS:
0046     void appendPoint();
0047 
0048 private:
0049     qreal nextFunctionValue();
0050 
0051     qreal m_x;
0052     Function m_function;
0053     QVector< qreal > m_data;
0054     QTimer m_appendTimer;
0055 };
0056 
0057 #endif