Warning, file /libraries/kqtquickcharts/src/chartmodel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 CHARTMODEL_H
0021 #define CHARTMODEL_H
0022 
0023 #include <QAbstractTableModel>
0024 
0025 #include <QQmlListProperty>
0026 
0027 class Record;
0028 
0029 class ChartModel : public QAbstractTableModel
0030 {
0031     Q_OBJECT
0032     Q_PROPERTY(QQmlListProperty<Record> records READ records CONSTANT)
0033     Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
0034     Q_PROPERTY(int rows READ rows NOTIFY rowsChanged)
0035     Q_CLASSINFO("DefaultProperty", "records")
0036 public:
0037     QQmlListProperty<Record> records();
0038     int columns() const;
0039     void setColumns(int columns);
0040     int rows() const;
0041     Q_INVOKABLE void appendRecord();
0042     Q_INVOKABLE void insertRecord(int row);
0043     Q_INVOKABLE void removeRecord(int row);
0044     Q_INVOKABLE qreal value(int row, int column) const;
0045     Q_INVOKABLE void setValue(int row, int column, qreal value);
0046     explicit ChartModel(QObject* parent = nullptr);
0047     int rowCount(const QModelIndex& parent) const override;
0048     int columnCount(const QModelIndex& parent) const override;
0049     QVariant data(const QModelIndex& index, int role) const override;
0050 Q_SIGNALS:
0051     void columnsChanged();
0052     void rowsChanged();
0053     void recordChanged(int row);
0054 private Q_SLOTS:
0055     void onRecordChanged(Record* record);
0056 private:
0057     void insertRecord(int row, Record* record);
0058     static void appendRecord(QQmlListProperty<Record>* list, Record* record);
0059     static int countRecords(QQmlListProperty<Record>* list);
0060     static Record* recordAt(QQmlListProperty<Record>* list, int index);
0061     static void clearRecords(QQmlListProperty<Record>* list);
0062     QList<Record*> m_records;
0063     int m_columns;
0064 };
0065 
0066 #endif // CHARTMODEL_H