File indexing completed on 2025-02-02 05:18:05

0001 /*
0002     SPDX-FileCopyrightText: 2018 Friedrich W. H. Kossebau <kossebau@kde.org>
0003     SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef CONFIGSTORAGE_H
0009 #define CONFIGSTORAGE_H
0010 
0011 #include <QAbstractListModel>
0012 
0013 #include <KConfigGroup>
0014 
0015 #include "../../calendarsystem.h"
0016 
0017 class CalendarSystemModel : public QAbstractListModel
0018 {
0019     Q_OBJECT
0020 
0021 public:
0022     enum Role {
0023         IdRole = Qt::UserRole,
0024     };
0025 
0026     explicit CalendarSystemModel(QObject *parent = nullptr);
0027 
0028     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0029     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0030     QHash<int, QByteArray> roleNames() const override;
0031 
0032     int indexOf(const QString &id) const;
0033 
0034 private:
0035     std::vector<CalendarSystemItem> m_items;
0036 };
0037 
0038 class ConfigStorage : public QObject
0039 {
0040     Q_OBJECT
0041 
0042     /**
0043      * The current choosen calendar system
0044      */
0045     Q_PROPERTY(QString calendarSystem MEMBER m_calendarSystem NOTIFY calendarSystemChanged)
0046 
0047     /**
0048      * The available calendar system list
0049      */
0050     Q_PROPERTY(QAbstractListModel *calendarSystemModel READ calendarSystemModel CONSTANT)
0051 
0052     /**
0053      * The index of current choosen calendar system
0054      */
0055     Q_PROPERTY(int currentIndex READ currentIndex CONSTANT)
0056 
0057     /**
0058      * The date offset in days
0059      */
0060     Q_PROPERTY(int dateOffset MEMBER m_dateOffset NOTIFY dateOffsetChanged)
0061 
0062 public:
0063     explicit ConfigStorage(QObject *parent = nullptr);
0064 
0065     QAbstractListModel *calendarSystemModel() const;
0066 
0067     int currentIndex() const;
0068 
0069     /**
0070      * Saves the modifed configuration.
0071      *
0072      * @see calendarSystem
0073      * @see dateOffset
0074      */
0075     Q_INVOKABLE void save();
0076 
0077 Q_SIGNALS:
0078     void calendarSystemChanged();
0079     void dateOffsetChanged();
0080 
0081 private:
0082     KConfigGroup m_generalConfigGroup;
0083 
0084     QString m_calendarSystem;
0085     CalendarSystemModel *const m_calendarSystemModel;
0086 
0087     int m_dateOffset; // For the (tabular) Islamic Civil calendar
0088 };
0089 
0090 #endif