MauiKit File Browsing

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

KDE's Doxygen guidelines are available online.