1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2010-06-12
 * Description : Action when adding a tag
 *
 * SPDX-FileCopyrightText: 2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * ============================================================ */

#pragma once

// Qt includes

#include <QString>
#include <QMetaType>

namespace Digikam
{

class TaggingAction
{
public:

    /**
     * Describes two possible actions:
     * Assigning an existing tag, known by tag id,
     * or creation of a new tag, with a given tag name and a parent tag.
     */
    enum Type
    {
        NoAction,
        AssignTag,
        CreateNewTag
    };

public:

    /**
     * Create a NoAction
     */
    TaggingAction() = default;

    /**
     * Assign the existing tag with given id
     */
    explicit TaggingAction(int tagId);

    /**
     * Create a new tag with the given name.
     * The parent shall be the tag with the given id,
     * or 0 for a toplevel tag.
     */
    TaggingAction(const QString& name, int parentTagId);

    bool operator==(const TaggingAction& other) const;

    Type type()                                 const;
    bool isValid()                              const;
    bool shallAssignTag()                       const;
    bool shallCreateNewTag()                    const;

    /// If shallAssignTag(), returns the tag id
    int tagId()                                 const;

    /// If shallCreateNewTag(), returns the tag name and the parent tag id, 0 for toplevel tag
    QString newTagName()                        const;<--- Function 'newTagName()' should return member 'm_tagName' by const reference.
    int     parentTagId()                       const;

protected:

    Type    m_type      = NoAction;
    int     m_tagId     = -1;
    QString m_tagName;
};

} // namespace Digikam

Q_DECLARE_METATYPE(Digikam::TaggingAction)