1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2010-09-27
7  * Description : Interface for info stored about a face tag in the database
8  *
9  * Copyright (C) 2010      by Aditya Bhatt <adityabhatt1991 at gmail dot com>
10  * Copyright (C) 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
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_FACE_TAGS_IFACE_H
26 #define DIGIKAM_FACE_TAGS_IFACE_H
27 
28 // Qt includes
29 
30 #include <QFlags>
31 #include <QVariant>
32 
33 // Local includes
34 
35 #include "tagregion.h"
36 #include "digikam_export.h"
37 
38 class QDebug;
39 
40 namespace Digikam
41 {
42 
43 class DIGIKAM_DATABASE_EXPORT FaceTagsIface
44 {
45 public:
46 
47     enum Type
48     {
49         InvalidFace      = 0,
50         UnknownName      = 1 << 0,
51         UnconfirmedName  = 1 << 1,
52         IgnoredName      = 1 << 2,
53         ConfirmedName    = 1 << 3,
54         FaceForTraining  = 1 << 4,
55 
56         UnconfirmedTypes = UnknownName | UnconfirmedName,
57         NormalFaces      = UnknownName | UnconfirmedName | IgnoredName | ConfirmedName,
58         AllTypes         = UnknownName | UnconfirmedName | IgnoredName | ConfirmedName | FaceForTraining,
59         TypeFirst        = UnknownName,
60         TypeLast         = FaceForTraining
61     };
62     Q_DECLARE_FLAGS(TypeFlags, Type)
63 
64 public:
65 
66     FaceTagsIface();
67     FaceTagsIface(Type type, qlonglong imageId, int tagId, const TagRegion& region);
68     FaceTagsIface(const QString& attribute, qlonglong imageId, int tagId, const TagRegion& region);
69 
70     bool      isNull()                          const;
71 
72     Type      type()                            const;
73     qlonglong imageId()                         const;
74     int       tagId()                           const;
75     TagRegion region()                          const;
76 
isInvalidFace()77     bool      isInvalidFace()                   const
78     {
79         return (type() == InvalidFace);
80     }
81 
isUnknownName()82     bool      isUnknownName()                   const
83     {
84         return (type() == UnknownName);
85     }
86 
isUnconfirmedName()87     bool      isUnconfirmedName()               const
88     {
89         return (type() == UnconfirmedName);
90     }
91 
isUnconfirmedType()92     bool      isUnconfirmedType()               const
93     {
94         return (type() & UnconfirmedTypes);
95     }
96 
isIgnoredName()97     bool      isIgnoredName()                   const
98     {
99         return (type() == IgnoredName);
100     }
101 
isConfirmedName()102     bool      isConfirmedName()                 const
103     {
104         return (type() == ConfirmedName);
105     }
106 
isForTraining()107     bool      isForTraining()                   const
108     {
109         return (type() == FaceForTraining);
110     }
111 
112     void setType(Type type);
113     void setTagId(int tagId);
114     void setRegion(const TagRegion& region);
115 
116     bool operator==(const FaceTagsIface& other) const;
117 
118     /**
119      * Returns a list of all image tag properties for which flags are set
120      */
121     static QStringList attributesForFlags(TypeFlags flags);
122 
123     /**
124      * Return the corresponding image tag property for the given type
125      */
126     static QString attributeForType(Type type);
127 
128     /**
129      * Returns the Face Type corresponding to
130      * the given TagId.
131      */
132     static Type typeForId(int tagId);
133 
134     /**
135      * Return the Type for the given attribute. To distinguish between UnknownName
136      * and UnconfirmedName, the tagId must be given.
137      */
138     static Type typeForAttribute(const QString& attribute, int tagId = 0);
139 
140     /**
141      * Returns the string tagId + ',' + unconfirmedFace + ',' + regionXml
142      */
143     QString getAutodetectedPersonString()       const;
144 
145     /**
146      * Writes the contents of this face - in a compact way - in the QVariant.
147      * Only native QVariant types are used, that is, the QVariant will not have a custom type,
148      * thus it can be compared by value by operator==.
149      */
150     static FaceTagsIface fromVariant(const QVariant& var);
151     QVariant toVariant()                        const;
152 
153     /**
154      * Create a FaceTagsIface from the extraValues returned from ItemLister.
155      */
156     static FaceTagsIface fromListing(qlonglong imageid, const QList<QVariant>& values);
157 
158 protected:
159 
160     Type      m_type;
161     qlonglong m_imageId;
162     int       m_tagId;
163     TagRegion m_region;
164 };
165 
166 DIGIKAM_DATABASE_EXPORT QDebug operator<<(QDebug dbg, const FaceTagsIface& f);
167 
168 } // namespace Digikam
169 
170 Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::FaceTagsIface::TypeFlags)
171 
172 #endif // DIGIKAM_FACE_TAGS_IFACE_H
173