File indexing completed on 2023-12-03 08:31:22
0001 // SPDX-FileCopyrightText: 2023 Shubham Arora <shubhamarora@protonmail.com> 0002 // SPDX-License-Identifier: GPL-3.0-only 0003 0004 /** 0005 * @file tagsmodel.h 0006 * @brief The TagsModel class header file. 0007 * */ 0008 #pragma once 0009 0010 #include "abstractlistmodel.h" 0011 #include "tag.h" 0012 0013 /** 0014 * @class TagsModel 0015 * @brief The TagsModel class provides a model for displaying a list of tags. 0016 * The TagsModel class is a subclass of AbstractListModel and provides 0017 * functionality for displaying a list of tags. It inherits the basic model 0018 * functionality from AbstractListModel and extends it to handle tags. 0019 */ 0020 class TagsModel : public AbstractListModel 0021 { 0022 Q_OBJECT 0023 0024 public: 0025 enum CustomRoles { NameRole = Qt::UserRole + 1, UrlRole, HistoryRole }; 0026 0027 /** 0028 * @brief Constructs a TagsModel object. 0029 * @param parent The parent object (optional). 0030 */ 0031 explicit TagsModel(QObject *parent = nullptr); 0032 0033 /** 0034 * @brief Returns the number of rows in the model. 0035 * @param parent The parent index (unused). 0036 * @return The number of rows in the model. 0037 */ 0038 int rowCount(const QModelIndex &parent) const override; 0039 0040 /** 0041 * @brief Returns the data for the given role and index. 0042 * @param index The index of the item. 0043 * @param role The role for which to return data. 0044 * @return The data for the given role and index. 0045 */ 0046 QVariant data(const QModelIndex &index, int role) const override; 0047 0048 /** 0049 * @brief Returns the role names used by the model. 0050 * @return The role names used by the model. 0051 */ 0052 QHash<int, QByteArray> roleNames() const override; 0053 0054 /** 0055 * @brief Fills the timeline with tags starting from the specified ID. 0056 * @param fromId The ID from which to start filling the timeline (optional). 0057 */ 0058 void fillTimeline(const QString &fromId = {}); 0059 0060 /** 0061 * @brief Fetches more data for the specified parent index. 0062 * @param parent The parent index. 0063 */ 0064 void fetchMore(const QModelIndex &parent) override; 0065 0066 /** 0067 * @brief Checks if more data can be fetched for the specified parent index. 0068 * @param parent The parent index. 0069 * @return True if more data can be fetched, false otherwise. 0070 */ 0071 bool canFetchMore(const QModelIndex &parent) const override; 0072 /** 0073 * @brief Returns the display name of the model. 0074 * @return The display name of the model. 0075 */ 0076 QString displayName() const override; 0077 0078 public Q_SLOTS: 0079 /** 0080 * @brief Slot called when the name is changed. 0081 */ 0082 void onNameChanged(); 0083 0084 private: 0085 /** 0086 * @brief The next URL for fetching more data. 0087 */ 0088 QUrl m_next; 0089 /** 0090 * @brief The list of tags in the model. 0091 */ 0092 QList<Tag> m_tags; 0093 };