aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/namevalueitem.h
blob: c518b17e66780a4ece23db4c8fa876c8be53acc9 (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
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include "utils_global.h"

#include "environmentfwd.h"
#include "utils_global.h"

#include <QStringList>
#include <QVariantList>

namespace Utils {

class QTCREATOR_UTILS_EXPORT EnvironmentItem
{
public:
    enum Operation : char { SetEnabled, Unset, Prepend, Append, SetDisabled, Comment };
    EnvironmentItem() = default;
    EnvironmentItem(const QString &key, const QString &value, Operation operation = SetEnabled)
        : name(key)
        , value(value)
        , operation(operation)
    {}

    void apply(NameValueDictionary *dictionary) const { apply(dictionary, operation); }

    static void sort(EnvironmentItems *list);
    static EnvironmentItems fromStringList(const QStringList &list);
    static QStringList toStringList(const EnvironmentItems &list);
    static EnvironmentItems itemsFromVariantList(const QVariantList &list);
    static QVariantList toVariantList(const EnvironmentItems &list);
    static EnvironmentItem itemFromVariantList(const QVariantList &list);
    static QVariantList toVariantList(const EnvironmentItem &item);

    friend bool operator==(const EnvironmentItem &first, const EnvironmentItem &second)
    {
        return first.operation == second.operation && first.name == second.name
               && first.value == second.value;
    }
    friend bool operator!=(const EnvironmentItem &first, const EnvironmentItem &second)
    {
        return !(first == second);
    }

    friend QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug debug, const EnvironmentItem &i);

public:
    QString name;
    QString value;
    Operation operation = Unset;

private:
    void apply(NameValueDictionary *dictionary, Operation op) const;
};

} // namespace Utils