File indexing completed on 2024-05-12 05:04:10
0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com> 0002 // SPDX-License-Identifier: GPL-3.0-or-later 0003 0004 #pragma once 0005 0006 #include "account/abstractaccount.h" 0007 0008 /// Fetches server rules 0009 class RulesModel : public QAbstractListModel 0010 { 0011 Q_OBJECT 0012 QML_ELEMENT 0013 0014 Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged) 0015 Q_PROPERTY(AbstractAccount *account READ account WRITE setAccount NOTIFY accountChanged) 0016 0017 public: 0018 /// Custom roles for this model 0019 enum CustomRoles { 0020 IdRole = Qt::UserRole, ///< ID of the rule 0021 TextRole, ///< Text content of the rule 0022 }; 0023 0024 explicit RulesModel(QObject *parent = nullptr); 0025 0026 bool loading() const; 0027 void setLoading(bool loading); 0028 0029 AbstractAccount *account() const; 0030 void setAccount(AbstractAccount *account); 0031 0032 QVariant data(const QModelIndex &index, int role) const override; 0033 int rowCount(const QModelIndex &parent) const override; 0034 QHash<int, QByteArray> roleNames() const override; 0035 0036 Q_SIGNALS: 0037 void loadingChanged(); 0038 void accountChanged(); 0039 0040 private: 0041 void fill(); 0042 0043 struct Rule { 0044 QString id, text; 0045 }; 0046 0047 QList<Rule> m_rules; 0048 bool m_loading = false; 0049 AbstractAccount *m_account = nullptr; 0050 Rule fromSourceData(const QJsonObject &object) const; 0051 };