MauiKit File Browsing

tagslist.h
1#pragma once
2#include <QObject>
3#include <QStringList>
4#include <QQmlEngine>
5
6#include <MauiKit4/Core/mauilist.h>
7
8class QTimer;
9/**
10 * @brief The TagsList class
11 * A model of the system tags, ready to be consumed by QML. This model has basic support for browsing, associating, adding and removing tags.
12 *
13 * This is a basic model for most actions supported by the MauiKit File Browsing Tagging system. For more details on supported actions and complete API documentation refer to the Tagging page.
14 * @see Tagging
15 *
16 * @note This class is exposed as a QML type with the alias name of `TagsListModel`.
17 */
18class TagsList : public MauiList
19{
21 QML_ELEMENT
22 QML_NAMED_ELEMENT(TagsListModel)
23 Q_DISABLE_COPY(TagsList)
24
25 /**
26 * Whether the retrieved tags should be only associated to the current application or to any other app.
27 * By default this is set to `true`, so the lookup will be only matching tags associated to the given URLs that were created by the current application.
28 */
29 Q_PROPERTY(bool strict READ getStrict WRITE setStrict NOTIFY strictChanged)
30
31 /**
32 * The list of file URLs to look for their tags.
33 */
34 Q_PROPERTY(QStringList urls READ getUrls WRITE setUrls NOTIFY urlsChanged)
35
36 /**
37 * The resulting list of tag names that were found.
38 */
39 Q_PROPERTY(QStringList tags READ getTags NOTIFY tagsChanged)
40
41public:
42 explicit TagsList(QObject *parent = nullptr);
43
44 const FMH::MODEL_LIST &items() const override;
45
46 bool getStrict() const;
47 void setStrict(const bool &value);
48
49 QStringList getUrls() const;
50 void setUrls(const QStringList &value);
51
52 QStringList getTags() const;
53
54 void componentComplete() override final;
55
56private:
57 FMH::MODEL_LIST list;
58 void setList();
59
60 bool strict = true;
61 QStringList m_urls;
62
63 void append(const FMH::MODEL &tag);
64
65 QTimer *m_refreshTimer;
66
68 void strictChanged();
69 void urlsChanged();
70 void tagsChanged();
71
72public Q_SLOTS:
73
74 /**
75 * @brief Adds a given tag to the model, if the tag already exists in the model then nothing happens.
76 * @note This operation does not inserts the tag to the tagging data base. To insert a new tag see the insert function.
77 * @see insert
78 * @param tag the tag to be added to the model
79 */
80 void append(const QString &tag);
81
82 /**
83 * @brief Adds a given tag map to the model, if the tag map already exists in the model then nothing happens.
84 * @note This operation does not inserts the tag to the tagging data base.
85 * @param tag the tag map to be added to the model. The supported key values are: `tag`, `color`, `date`
86 */
87 void appendItem(const QVariantMap &tag);
88
89 /**
90 * @brief Adds a given list of tags to the model. Tags that already exists in the model are ignored.
91 * @param tags list of tags to be added to the model.
92 * @see append
93 */
94 void append(const QStringList &tags);
95
96 /**
97 * @brief Inserts a tag to the tagging data base.
98 * @param tag to be inserted
99 * @return if the tag already exists in the data base then it return false, if the operation is successful returns true otherwise false
100 */
101 bool insert(const QString &tag);
102
103 /**
104 * @brief Associates a given tag to the current file URLs set to the URLs property
105 * @param tag a tag to be associated, if the tag doesn't exists then it gets created
106 */
107 void insertToUrls(const QString &tag);
108
109 /**
110 * @brief Updates a list of tags associated to the current file URLs. All the previous tags associated to each file URL are removed and replaced by the new ones
111 * @param tags tags to be updated
112 */
113 void updateToUrls(const QStringList &tags);
114
115 /**
116 * @brief Removes a tag from the model at a given index. The tag is removed from the model but not from the tagging data base
117 * @param index index position of the tag in the model. If the model has been filtered or ordered using the MauiKit BaseModel then it should use the mapped index.
118 * @return
119 */
120 bool remove(const int &index);
121
122 /**
123 * @brief Removes a tag at the given index in the model from the given file URL. This removes the associated file URL from the tagging data base and the tag from the model
124 * @param index index of the tag in the model
125 * @param url file URL
126 */
127 void removeFrom(const int &index, const QString &url);
128
129 /**
130 * @brief Removes a tag at a given index in the model from the all the file URLs currently set
131 * @param index index of the tag in the model.
132 */
133 void removeFromUrls(const int &index);
134
135 /**
136 * @brief Removes a given tag name from the current list of file URLs set
137 * @param tag the tag name
138 */
139 void removeFromUrls(const QString &tag);
140
141 /**
142 * @brief Removes a tag from the tagging data base. This operation will remove the association of the tag to the current application making the request, meaning that if the tag is also associated to another application then the tag will be conserved.
143 * @param index
144 */
145 void erase(const int &index);
146
147 /**
148 * @brief Reloads the model, checking the tags from the given list of file URLs
149 */
150 void refresh();
151
152 /**
153 * @brief Checks whether a given tag name is already in the model list
154 * @param tag tag name to look up
155 * @return whether the tag exists
156 */
157 bool contains(const QString &tag);
158};
159
MauiList(QObject *parent=nullptr)
QStringList tags
The resulting list of tag names that were found.
Definition tagslist.h:39
QML_ELEMENTbool strict
Whether the retrieved tags should be only associated to the current application or to any other app.
Definition tagslist.h:29
void updateToUrls(const QStringList &tags)
Updates a list of tags associated to the current file URLs.
Definition tagslist.cpp:59
bool insert(const QString &tag)
Inserts a tag to the tagging data base.
Definition tagslist.cpp:42
bool remove(const int &index)
Removes a tag from the model at a given index.
Definition tagslist.cpp:103
void appendItem(const QVariantMap &tag)
Adds a given tag map to the model, if the tag map already exists in the model then nothing happens.
Definition tagslist.cpp:173
void erase(const int &index)
Removes a tag from the tagging data base.
Definition tagslist.cpp:125
void removeFromUrls(const int &index)
Removes a tag at a given index in the model from the all the file URLs currently set.
Definition tagslist.cpp:79
bool contains(const QString &tag)
Checks whether a given tag name is already in the model list.
Definition tagslist.cpp:197
QStringList urls
The list of file URLs to look for their tags.
Definition tagslist.h:34
void removeFrom(const int &index, const QString &url)
Removes a tag at the given index in the model from the given file URL.
Definition tagslist.cpp:116
void insertToUrls(const QString &tag)
Associates a given tag to the current file URLs set to the URLs property.
Definition tagslist.cpp:50
void refresh()
Reloads the model, checking the tags from the given list of file URLs.
Definition tagslist.cpp:37
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Thu Jan 23 2025 18:53:41 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.