LeechCraft 0.6.70-19424-g027e980fd1
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
itagsmanager.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#ifndef INTERFACES_CORE_ITAGSMANAGER_H
10#define INTERFACES_CORE_ITAGSMANAGER_H
11#include <optional>
12#include <QDataStream>
13#include <QHash>
14#include <QMetaType>
15#include <QObject>
16#include <QStringList>
18
19class QAbstractItemModel;
20
21namespace LC
22{
29 struct TagId
30 {
31 QString Id_;
32
33 bool operator== (const TagId&) const = default;
34
39 static QList<TagId> FromStrings (const QStringList& ids)
40 {
41 QList<TagId> result;
42 result.reserve (ids.size ());
43 for (const auto& id : ids)
44 result << TagId { id };
45 return result;
46 }
47
52 static QStringList ToStrings (const QList<TagId>& ids)
53 {
54 QStringList result;
55 result.reserve (ids.size ());
56 for (const auto& id : ids)
57 result << id.Id_;
58 return result;
59 }
60 };
61
62 inline size_t qHash (const TagId& id, size_t seed = 0) noexcept
63 {
64 return qHash (id.Id_, seed);
65 }
66
67 inline QDataStream& operator<< (QDataStream& out, const TagId& id)
68 {
69 return out << id.Id_;
70 }
71
72 inline QDataStream& operator>> (QDataStream& in, TagId& id)
73 {
74 return in >> id.Id_;
75 }
76}
77
79
80
90class Q_DECL_EXPORT ITagsManager
91{
92protected:
94public:
95 virtual ~ITagsManager () {}
96
100
115 virtual std::optional<LC::TagId> GetID (const QString& tag) = 0;
116
128 QList<LC::TagId> GetIDs (const QStringList& tags)
129 {
130 QList<LC::TagId> result;
131 for (const auto& tag : tags)
132 if (const auto& id = GetID (tag))
133 result << *id;
134 return result;
135 }
136
150 virtual QStringList GetTags (const LC::TagId& id) const = 0;
151
163 QStringList GetTags (const QList<LC::TagId>& ids) const
164 {
165 QStringList result;
166 result.reserve (ids.size ());
167 for (const auto& id : ids)
168 result += GetTags (id);
169 result.removeDuplicates ();
170 return result;
171 }
172
177 virtual QStringList GetAllTags () const = 0;
178
184 virtual QStringList Split (const QString& string) const = 0;
185
195 virtual QList<LC::TagId> SplitToIDs (const QString& string) = 0;
196
203 virtual QString Join (const QStringList& tags) const = 0;
204
215 virtual QString JoinIDs (const QList<LC::TagId>& tagIDs) const = 0;
216
225 virtual QAbstractItemModel* GetModel () = 0;
226};
227
228Q_DECLARE_INTERFACE (ITagsManager, "org.Deviant.LeechCraft.ITagsManager/1.0")
229
230#endif
Tags manager's interface.
virtual QString JoinIDs(const QList< LC::TagId > &tagIDs) const =0
Joins the given tag IDs into one human-readable string.
virtual ~ITagsManager()
virtual QStringList GetTags(const LC::TagId &id) const =0
Returns the tags denoted by the given id.
virtual QStringList GetAllTags() const =0
Returns all tags existing in LeechCraft now.
QList< LC::TagId > GetIDs(const QStringList &tags)
Returns the IDs of the given tags.
virtual QList< LC::TagId > SplitToIDs(const QString &string)=0
Splits the given string with tags and returns tags IDs.
const LC::Util::Emitters::TagsManager & GetEmitter() const
Returns the emitter of this manager's signals.
QStringList GetTags(const QList< LC::TagId > &ids) const
Returns the tags denoted by the given ids.
virtual QAbstractItemModel * GetModel()=0
Returns the model listing the tag names.
virtual QString Join(const QStringList &tags) const =0
Joins the given tags into one string that's suitable to display to the user.
virtual QStringList Split(const QString &string) const =0
Splits the given string with tags to the list of the tags.
virtual std::optional< LC::TagId > GetID(const QString &tag)=0
Returns the ID of the given tag.
LC::Util::Emitters::TagsManager Emitter_
The signals of an ITagsManager.
Definition tagsmanager.h:22
Definition constants.h:15
QDataStream & operator>>(QDataStream &in, TagId &id)
size_t qHash(const TagId &id, size_t seed=0) noexcept
QDataStream & operator<<(QDataStream &out, const TagId &id)
An identifier of a tag in ITagsManager.
static QList< TagId > FromStrings(const QStringList &ids)
Wraps the persisted forms ids into identifiers.
bool operator==(const TagId &) const =default
static QStringList ToStrings(const QList< TagId > &ids)
Returns the persisted forms of ids.
QString Id_
Q_DECLARE_METATYPE(QVariantList *)