File indexing completed on 2022-09-20 16:26:44

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 Library 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 DATA_H
0021 #define DATA_H
0022 
0023 #include <QObject>
0024 #include <QHash>
0025 #include <QStandardItemModel>
0026 #include <QVector>
0027 
0028 #include <ksharedconfig.h>
0029 
0030 class QTimer;
0031 class AvailableGradesModel;
0032 
0033 class Data : public QObject {
0034     Q_OBJECT
0035     Q_PROPERTY(AvailableGradesModel *availableLeadModel READ availableLeadModel CONSTANT)
0036     Q_PROPERTY(AvailableGradesModel *availableBoulderModel READ availableBoulderModel CONSTANT)
0037     Q_PROPERTY(int currentTab READ currentTab WRITE setCurrentTab NOTIFY currentTabChanged)
0038     Q_PROPERTY(bool leadAndBoulderLinked READ isLeadAndBoulderLinked WRITE setLeadAndBoulderLinked NOTIFY leadAndBoulderLinkedChanged)
0039 
0040 public:
0041     Data(QObject *parent = 0);
0042     ~Data();
0043 
0044     AvailableGradesModel *availableLeadModel();
0045     AvailableGradesModel *availableBoulderModel();
0046 
0047     KSharedConfigPtr config();
0048 
0049     int currentTab() const;
0050     void setCurrentTab(int tab);
0051  
0052     int isLeadAndBoulderLinked() const;
0053     void setLeadAndBoulderLinked(bool linked);
0054 
0055     void configNeedsSaving();
0056 
0057     Q_INVOKABLE QString gradeName(const QString &scale, int decimalGrade) const;
0058 
0059 Q_SIGNALS:
0060     void currentTabChanged();
0061     void leadAndBoulderLinkedChanged();
0062 
0063 private:
0064     QStringList m_scales;
0065     QHash<QString, QVector<QString> > m_data;
0066     AvailableGradesModel *m_availableLeadModel;
0067     AvailableGradesModel *m_availableBoulderModel;
0068     QTimer *m_configSyncTimer;
0069     KSharedConfigPtr m_config;
0070     int m_currentTab;
0071     bool m_leadAndBoulderLinked : 1;
0072 };
0073 
0074 #endif