summaryrefslogtreecommitdiff
path: root/seriesmodel.h
blob: 5aca1f4bafefc0745332f3ac76459acb3023c778 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once

// qt
#include <QAbstractTableModel>
#include <QMutex>
#include <QVector2D>

// goodies
#include "g_property.h"

class SeriesModel : public QAbstractTableModel
{
    Q_OBJECT

    G_PROPERTY(float, minX);
    G_PROPERTY(float, maxX);
    G_PROPERTY(float, minY);
    G_PROPERTY(float, maxY);

public:
    Q_INVOKABLE SeriesModel(QObject* parent = nullptr);
    Q_INVOKABLE SeriesModel(const SeriesModel& other);
    Q_INVOKABLE ~SeriesModel() Q_DECL_OVERRIDE = default;

public:
    Q_INVOKABLE int rowCount(
        const QModelIndex& parent = QModelIndex()
    ) const Q_DECL_OVERRIDE;
    Q_INVOKABLE int columnCount(
        const QModelIndex& parent = QModelIndex()
    ) const Q_DECL_OVERRIDE;
    Q_INVOKABLE QVariant data(
        const QModelIndex& modelIndex,
        int role = Qt::DisplayRole
    ) const Q_DECL_OVERRIDE;

public slots:
    void append(const QVector<QVector2D> points);
    void replace(const QVector<QVector2D> points);
    void clear();
    void recalcLimits();

protected:
    QVector<QVector2D> m_points;
    QMutex m_mtx;
};

Q_DECLARE_METATYPE(SeriesModel);