1 /*
2  *  Copyright 2014  Sebastian Gottfried <sebastiangottfried@web.de>
3  *
4  *  This library is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public
6  *  License as published by the Free Software Foundation; either
7  *  version 2.1 of the License, or (at your option) version 3, or any
8  *  later version accepted by the membership of KDE e.V. (or its
9  *  successor approved by the membership of KDE e.V.), which shall
10  *  act as a proxy defined in Section 6 of version 3 of the license.
11  *
12  *  This library is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *  Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public
18  */
19 
20 #ifndef CHARTCORE_H
21 #define CHARTCORE_H
22 
23 #include <QQuickPaintedItem>
24 
25 #include "dimension.h"
26 
27 class QAbstractTableModel;
28 
29 class ChartCore : public QQuickPaintedItem
30 {
31     Q_OBJECT
32     Q_PROPERTY(QAbstractTableModel* model READ model WRITE setModel NOTIFY modelChanged)
33     Q_PROPERTY(QQmlListProperty<Dimension> dimensions READ dimensions CONSTANT)
34     Q_PROPERTY(qreal pitch READ pitch WRITE setPitch NOTIFY pitchChanged)
35     Q_PROPERTY(int textRole READ textRole WRITE setTextRole NOTIFY textRoleChanged)
36 public:
37     explicit ChartCore(QQuickItem *parent = nullptr);
38     QAbstractTableModel* model() const;
39     void setModel(QAbstractTableModel* model);
40     QQmlListProperty<Dimension> dimensions();
41     QList<Dimension*> dimensionsList() const;
42     qreal pitch() const;
43     void setPitch(qreal pitch);
44     int textRole() const;
45     void setTextRole(int textRole);
46 Q_SIGNALS:
47     void modelChanged();
48     void chartStyleChanged();
49     void pitchChanged();
50     void textRoleChanged();
51     void updated();
52 protected Q_SLOTS:
53     void triggerUpdate();
54 protected:
55     void paint(QPainter* painter) override;
56     void paintAxisAndLines(QPainter* painter, qreal offset);
57 private:
58     static void appendDimension(QQmlListProperty<Dimension>* list, Dimension* dimension);
59     static int countDimensions(QQmlListProperty<Dimension>* list);
60     static Dimension* dimensionAt(QQmlListProperty<Dimension>* list, int index);
61     static void clearDimensions(QQmlListProperty<Dimension>* list);
62     QAbstractTableModel* m_model;
63     QList<Dimension*> m_dimensions;
64     qreal m_pitch;
65     int m_textRole;
66 };
67 
68 #endif // CHARTCORE_H
69