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