File indexing completed on 2024-03-24 05:53:46
0001 /* 0002 * Copyright 2016 Marco Martin <mart@kde.org> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU Library General Public License as 0006 * published by the Free Software Foundation; either version 2, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details 0013 * 0014 * You should have received a copy of the GNU Library General Public 0015 * License along with this program; if not, write to the 0016 * Free Software Foundation, Inc., 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef AVAILABLEGRADESMODEL_H 0021 #define AVAILABLEGRADESMODEL_H 0022 0023 #include <QAbstractListModel> 0024 #include <QJsonArray> 0025 #include <QJsonObject> 0026 #include <QJsonDocument> 0027 0028 class Data; 0029 0030 class AvailableGradesModel : public QAbstractListModel 0031 { 0032 Q_OBJECT 0033 Q_PROPERTY(int currentGrade READ currentGrade WRITE setCurrentGrade NOTIFY currentGradeChanged) 0034 Q_PROPERTY(int personalRecord READ personalRecord WRITE setPersonalRecord NOTIFY personalRecordChanged) 0035 0036 public: 0037 enum Roles { 0038 NameRole = Qt::UserRole, 0039 EnabledRole, 0040 DescriptionRole, 0041 UrlRole 0042 }; 0043 0044 explicit AvailableGradesModel(Data *parent = 0); 0045 ~AvailableGradesModel(); 0046 0047 int personalRecord() const; 0048 void setPersonalRecord(int record); 0049 0050 int currentGrade() const; 0051 void setCurrentGrade(int tab); 0052 0053 Q_INVOKABLE void setScaleEnabled(int row, bool enabled); 0054 virtual QHash<int, QByteArray> roleNames() const; 0055 virtual int rowCount(const QModelIndex &parent) const; 0056 virtual QVariant data(const QModelIndex &index, int role) const; 0057 0058 void load(const QString &dataName); 0059 0060 Q_SIGNALS: 0061 void personalRecordChanged(); 0062 void currentGradeChanged(); 0063 0064 private: 0065 QHash<int, QByteArray> m_roleNames; 0066 0067 Data *m_data; 0068 QJsonDocument m_jsonDoc; 0069 QString m_dataName; 0070 int m_personalRecord; 0071 int m_currentGrade; 0072 }; 0073 0074 #endif // AVAILABLEGRADESMODEL_H