summaryrefslogtreecommitdiff
path: root/include/svx/ClassificationField.hxx
blob: e2b5a71ab7756679f5748e62523e4d3276a61e4c (plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 */

#ifndef INCLUDED_SVX_CLASSIFICATIONFIELD_HXX
#define INCLUDED_SVX_CLASSIFICATIONFIELD_HXX

#include <sal/config.h>
#include <svx/svxdllapi.h>
#include <editeng/flditem.hxx>
#include <utility>

namespace svx {

enum class ClassificationType
{
    CATEGORY,
    MARKING,
    TEXT,
    INTELLECTUAL_PROPERTY_PART,
    PARAGRAPH,
};

class SVX_DLLPUBLIC ClassificationResult
{
public:
    ClassificationType meType;
    OUString msName;            //< Display text or 'Name' field (from example.xml).
    OUString msAbbreviatedName; //< Abbreviated name, displayed instead of Name.
    OUString msIdentifier;      //< The identifier of this entry (from example.xml).

    ClassificationResult(ClassificationType eType, OUString sName,
                         OUString sAbbreviatedName, OUString sIdentifier = "")
        : meType(eType)
        , msName(std::move(sName))
        , msAbbreviatedName(std::move(sAbbreviatedName))
        , msIdentifier(std::move(sIdentifier))
    {
    }

    /// Returns the text to display, which is the Abbreviated Name, if provided, otherwise Name.
    OUString const & getDisplayText() const
    {
        return !msAbbreviatedName.isEmpty() ? msAbbreviatedName : msName;
    }

    bool operator==(const ClassificationResult& rOther) const
    {
        return (meType == rOther.meType &&
                msName == rOther.msName &&
                msAbbreviatedName == rOther.msAbbreviatedName &&
                msIdentifier == rOther.msIdentifier);
    }
};

class SVX_DLLPUBLIC ClassificationField final : public SvxFieldData
{
public:
    ClassificationType meType;
    OUString msDescription;
    OUString msFullClassName;
    OUString msIdentifier;

    ClassificationField(ClassificationType eType, OUString sDescription, OUString sFullClassName, OUString sIdentifier)
        : meType(eType)
        , msDescription(std::move(sDescription))
        , msFullClassName(std::move(sFullClassName))
        , msIdentifier(std::move(sIdentifier))
    {}

    std::unique_ptr<SvxFieldData> Clone() const override
    {
        return std::make_unique<ClassificationField>(meType, msDescription, msFullClassName, msIdentifier);
    }

    bool operator==(const SvxFieldData& rOther) const override
    {
        if (typeid(rOther) != typeid(*this))
            return false;

        const ClassificationField& rOtherField = static_cast<const ClassificationField&>(rOther);
        return (meType == rOtherField.meType &&
                msDescription == rOtherField.msDescription &&
                msFullClassName == rOtherField.msFullClassName &&
                msIdentifier == rOtherField.msIdentifier);
    }
};

} // end svx namespace

#endif // INCLUDED_SVX_CLASSIFICATIONFIELD_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */