File indexing completed on 2024-05-12 05:04:14
0001 // SPDX-FileCopyrightText: 2023 Shubham Arora <shubhamarora@protonmail.com> 0002 // SPDX-License-Identifier: GPL-3.0-only 0003 0004 #pragma once 0005 0006 #include "abstractaccount.h" 0007 #include "accountmanager.h" 0008 0009 class AbstractAccount; 0010 0011 /** 0012 * @class AbstractListModel 0013 * @brief The AbstractListModel class extends QAbstractListModel to provide a base class for custom list models. 0014 * This class defines properties and methods that can be used by derived list models to implement custom functionality. 0015 */ 0016 class AbstractListModel : public QAbstractListModel 0017 { 0018 Q_OBJECT 0019 0020 Q_PROPERTY(QString displayName READ displayName CONSTANT) 0021 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 0022 Q_PROPERTY(bool loading READ loading WRITE setLoading NOTIFY loadingChanged) 0023 Q_PROPERTY(bool shouldLoadMore READ shouldLoadMore WRITE setShouldLoadMore NOTIFY shouldLoadMoreChanged) 0024 0025 public: 0026 /** 0027 * @brief Constructs an AbstractListModel object. 0028 * @param parent The parent QObject. 0029 */ 0030 explicit AbstractListModel(QObject *parent = nullptr); 0031 0032 /** 0033 * @brief Returns the display name of the list model. 0034 * @return The display name as a QString. 0035 * 0036 * This method should be overridden by derived classes to provide the specific display name. 0037 */ 0038 virtual QString displayName() const = 0; 0039 0040 /** 0041 * @brief Returns the name of the list model. 0042 * @return The name as a QString. 0043 */ 0044 QString name() const; 0045 0046 /** 0047 * @brief Sets the name of the list model. 0048 * @param name The name to set. 0049 */ 0050 void setName(const QString &name); 0051 0052 /** 0053 * @brief Returns the loading state of the list model. 0054 * @return True if the list model is currently loading, false otherwise. 0055 */ 0056 bool loading() const; 0057 /** 0058 * @brief Sets the loading state of the list model. 0059 * @param loading The loading state to set. 0060 */ 0061 void setLoading(bool loading); 0062 /** 0063 * @brief Returns the account associated with the list model. 0064 * @return A pointer to the AbstractAccount object. 0065 */ 0066 0067 AbstractAccount *account() const; 0068 0069 /** 0070 * @brief Returns whether the list model should load more items. 0071 * @return True if the list model should load more items, false otherwise. 0072 */ 0073 bool shouldLoadMore() const; 0074 0075 /** 0076 * @brief Sets whether the list model should load more items. 0077 * @param shouldLoadMore The value to set. 0078 */ 0079 void setShouldLoadMore(bool shouldLoadMore); 0080 0081 Q_SIGNALS: 0082 /** 0083 * @brief This signal is emitted when the name of the list model changes. 0084 */ 0085 void nameChanged(); 0086 /** 0087 * @brief This signal is emitted when the loading state of the list model changes. 0088 */ 0089 void loadingChanged(); 0090 /** 0091 * @brief This signal is emitted when the shouldLoadMore property changes. 0092 */ 0093 void shouldLoadMoreChanged(); 0094 0095 private: 0096 /** 0097 * @brief The name of the list model. 0098 */ 0099 QString m_listName; 0100 /** 0101 * @brief The loading state of the list model. 0102 */ 0103 bool m_loading = false; 0104 /** 0105 * @brief A pointer to the AbstractAccount object. 0106 */ 0107 AbstractAccount *m_account = nullptr; 0108 /* 0109 * @brief A pointer to the AccountManager object. 0110 */ 0111 AccountManager *m_manager = nullptr; 0112 /** 0113 * @brief Whether the list model should load more items. 0114 */ 0115 bool m_shouldLoadMore = true; 0116 };