File indexing completed on 2024-05-12 16:28:09

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