digiKam
tagscache.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2010-04-02
7  * Description : Cache for Tag information
8  *
9  * Copyright (C) 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2011-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_TAGS_CACHE_H
26 #define DIGIKAM_TAGS_CACHE_H
27 
28 // Qt includes
29 
30 #include <QObject>
31 
32 // Local includes
33 
34 #include "coredbchangesets.h"
35 #include "digikam_export.h"
36 
37 namespace Digikam
38 {
39 
40 class DIGIKAM_DATABASE_EXPORT TagsCache : public QObject
41 {
42  Q_OBJECT
43 
44 public:
45 
47  {
49  IncludeLeadingSlash
50  };
51 
53  {
55  IncludeHiddenTags
56  };
57 
58 public:
59 
65  QString tagName(int id) const;
66  QStringList tagNames(const QList<int>& ids, HiddenTagsPolicy hiddenTagsPolicy = IncludeHiddenTags) const;
67 
73  QString tagPath(int id, LeadingSlashPolicy slashPolicy = IncludeLeadingSlash) const;
74  QStringList tagPaths(const QList<int>& ids,
75  LeadingSlashPolicy slashPolicy = IncludeLeadingSlash,
76  HiddenTagsPolicy hiddenTagsPolicy = IncludeHiddenTags) const;
77 
81  bool hasTag(int id) const;
82 
86  int parentTag(int id) const;
87 
93  QList<int> parentTags(int id) const;
94 
100  QList<int> tagsForName(const QString& tagName, HiddenTagsPolicy hiddenTagsPolicy = NoHiddenTags) const;
101 
107  int tagForName(const QString& tagName, int parentId = 0) const;
108 
116  int tagForPath(const QString& path) const;
117  QList<int> tagsForPaths(const QStringList& tagPaths) const;
118 
126  int createTag(const QString& tagPathToCreate);
127  QList<int> createTags(const QStringList& tagPaths);
128 
134  int getOrCreateTag(const QString& tagPath);
135  QList<int> getOrCreateTags(const QStringList& tagPaths);
136 
142  int getOrCreateTagWithProperty(const QString& tagPath,
143  const QString& property,
144  const QString& value = QString());
145 
151  bool hasProperty(int tagId, const QString& property, const QString& value = QString()) const;
152 
159  QString propertyValue(int tagId, const QString& property) const;
160  QStringList propertyValues(int tagId, const QString& property) const;
161 
166  QMap<QString, QString> properties(int tagId) const;
167 
174  QList<int> tagsWithProperty(const QString& property, const QString& value = QString()) const;
175 
182  QList<int> tagsWithPropertyCached(const QString& property) const;
183 
188  bool isInternalTag(int tagId) const;
189 
194  QList<int> publicTags(const QList<int>& tagIds) const;
195 
200  bool containsPublicTags(const QList<int>& tagIds) const;
201 
206  bool canBeWrittenToMetadata(int tagId) const;
207 
213  int getOrCreateInternalTag(const QString& tagName);
214 
219  int tagForColorLabel(int label);
220 
224  QVector<int> colorLabelTags();
225 
230  int colorLabelForTag(int tagId);
231 
237  int colorLabelFromTags(QList<int> tagIds);
238 
243  int tagForPickLabel(int label);
244 
248  QVector<int> pickLabelTags();
249 
254  int pickLabelForTag(int tagId);
255 
261  int pickLabelFromTags(QList<int> tagIds);
262 
266  QList<int> tagsContaining(const QString& fragment,
267  Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive,
268  HiddenTagsPolicy hiddenTagsPolicy = NoHiddenTags);
269  QList<int> tagsStartingWith(const QString& begin,
270  Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive,
271  HiddenTagsPolicy hiddenTagsPolicy = NoHiddenTags);
272 
281  QStringList shortenedTagPaths(const QList<int>& ids,
282  LeadingSlashPolicy slashPolicy = IncludeLeadingSlash,
283  HiddenTagsPolicy hiddenTagsPolicy = IncludeHiddenTags) const;
284 
285  QStringList shortenedTagPaths(const QList<int>& ids, QList<int>* sortedIds,
286  LeadingSlashPolicy slashPolicy = IncludeLeadingSlash,
287  HiddenTagsPolicy hiddenTagsPolicy = IncludeHiddenTags) const;
288 
289 public:
290 
291  static TagsCache* instance();
292 
293  static QLatin1String tagPathOfDigikamInternalTags(LeadingSlashPolicy slashPolicy = IncludeLeadingSlash);
294  static QLatin1String propertyNameDigikamInternalTag();
295  static QLatin1String propertyNameExcludedFromWriting();
296 
297 Q_SIGNALS:
298 
304  void tagAdded(int tagId);
305  void tagDeleted(int tagId);
306  void tagAboutToBeDeleted(QString name);
307 
308 private Q_SLOTS:
309 
310  void slotTagChanged(const TagChangeset& changeset);
311 
312 private:
313 
314  // Disable
315  TagsCache();
316  explicit TagsCache(QObject*) = delete;
317  ~TagsCache() override;
318 
319  void initialize();
320  void invalidate();
321 
322 private:
323 
324  friend class CoreDbAccess;
325  friend class TagsCacheCreator;
326  friend class ChangingDB;
327 
328 private:
329 
330  class Private;
331  Private* const d;
332 };
333 
334 } // namespace Digikam
335 
336 #endif // DIGIKAM_TAGS_CACHE_H
Definition: albummanager_p.h:215
Definition: coredbaccess.h:56
Definition: coredbchangesets.h:298
Definition: tagscache.h:41
LeadingSlashPolicy
Definition: tagscache.h:47
@ NoLeadingSlash
Ex: "Places/Cities/Paris".
Definition: tagscache.h:48
void tagAdded(int tagId)
void tagAboutToBeDeleted(QString name)
void tagDeleted(int tagId)
HiddenTagsPolicy
Definition: tagscache.h:53
@ NoHiddenTags
Definition: tagscache.h:54
qulonglong value
Definition: itemviewutilities.cpp:592
Definition: datefolderview.cpp:43