File indexing completed on 2023-10-03 04:00:38
0001 /* 0002 * Copyright 2014 Sebastian Gottfried <sebastiangottfried@web.de> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) version 3, or any 0008 * later version accepted by the membership of KDE e.V. (or its 0009 * successor approved by the membership of KDE e.V.), which shall 0010 * act as a proxy defined in Section 6 of version 3 of the license. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 */ 0019 0020 #ifndef CHARTCORE_H 0021 #define CHARTCORE_H 0022 0023 #include <QQuickPaintedItem> 0024 0025 #include "dimension.h" 0026 0027 class QAbstractTableModel; 0028 0029 class ChartCore : public QQuickPaintedItem 0030 { 0031 Q_OBJECT 0032 Q_PROPERTY(QAbstractTableModel* model READ model WRITE setModel NOTIFY modelChanged) 0033 Q_PROPERTY(QQmlListProperty<Dimension> dimensions READ dimensions CONSTANT) 0034 Q_PROPERTY(qreal pitch READ pitch WRITE setPitch NOTIFY pitchChanged) 0035 Q_PROPERTY(int textRole READ textRole WRITE setTextRole NOTIFY textRoleChanged) 0036 public: 0037 explicit ChartCore(QQuickItem *parent = nullptr); 0038 QAbstractTableModel* model() const; 0039 void setModel(QAbstractTableModel* model); 0040 QQmlListProperty<Dimension> dimensions(); 0041 QList<Dimension*> dimensionsList() const; 0042 qreal pitch() const; 0043 void setPitch(qreal pitch); 0044 int textRole() const; 0045 void setTextRole(int textRole); 0046 Q_SIGNALS: 0047 void modelChanged(); 0048 void chartStyleChanged(); 0049 void pitchChanged(); 0050 void textRoleChanged(); 0051 void updated(); 0052 protected Q_SLOTS: 0053 void triggerUpdate(); 0054 protected: 0055 void paint(QPainter* painter) override; 0056 void paintAxisAndLines(QPainter* painter, qreal offset); 0057 private: 0058 static void appendDimension(QQmlListProperty<Dimension>* list, Dimension* dimension); 0059 static int countDimensions(QQmlListProperty<Dimension>* list); 0060 static Dimension* dimensionAt(QQmlListProperty<Dimension>* list, int index); 0061 static void clearDimensions(QQmlListProperty<Dimension>* list); 0062 QAbstractTableModel* m_model; 0063 QList<Dimension*> m_dimensions; 0064 qreal m_pitch; 0065 int m_textRole; 0066 }; 0067 0068 #endif // CHARTCORE_H