File: surveytargetexpression.cpp

package info (click to toggle)
gammaray 3.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,612 kB
  • sloc: cpp: 94,643; ansic: 2,227; sh: 336; python: 164; yacc: 90; lex: 82; xml: 61; makefile: 26
file content (118 lines) | stat: -rw-r--r-- 3,500 bytes parent folder | download | duplicates (2)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
    SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org>

    SPDX-License-Identifier: MIT
*/

#include "surveytargetexpression.h"

using namespace KUserFeedback;

SurveyTargetExpression::SurveyTargetExpression(const QVariant &value)
    : m_type(Value)
    , m_value(value)
{
}

SurveyTargetExpression::SurveyTargetExpression(const QString& source, const QVariant &index, const QString& elem)
    : m_value(index)
    , m_source(source)
    , m_sourceElement(elem)
{
    if (index.typeId() == QMetaType::Int)
        m_type = ListElement;
    else if (index.typeId() == QMetaType::QString)
        m_type = MapElement;
    else
        m_type = ScalarElement;
}

SurveyTargetExpression::SurveyTargetExpression(Type type, SurveyTargetExpression* left, SurveyTargetExpression* right)
    : m_type(type)
    , m_left(left)
    , m_right(right)
{
}

SurveyTargetExpression::~SurveyTargetExpression()
{
}

SurveyTargetExpression::Type SurveyTargetExpression::type() const
{
    return m_type;
}

QVariant SurveyTargetExpression::value() const
{
    return m_value;
}

QString SurveyTargetExpression::source() const
{
    return m_source;
}

QString SurveyTargetExpression::sourceElement() const
{
    return m_sourceElement;
}

SurveyTargetExpression* SurveyTargetExpression::left() const
{
    return m_left.get();
}

SurveyTargetExpression* SurveyTargetExpression::right() const
{
    return m_right.get();
}

QDebug operator<<(QDebug debug, SurveyTargetExpression* expr)
{
    if (!expr) {
        debug << "(null)";
        return debug;
    }

    switch (expr->type()) {
        case SurveyTargetExpression::Value:
            debug << expr->value().toString(); //toString() is needed for Qt4 support
            break;
        case SurveyTargetExpression::ScalarElement:
            debug.nospace() << expr->source() << "." << expr->sourceElement();
            break;
        case SurveyTargetExpression::ListElement:
            debug.nospace() << expr->source() << "[" << expr->value().toInt() << "]." << expr->sourceElement();
            break;
        case SurveyTargetExpression::MapElement:
            debug.nospace() << expr->source() << "[" << expr->value().toString() << "]." << expr->sourceElement();
            break;
        case SurveyTargetExpression::OpLogicAnd:
            debug.nospace() << "(" << expr->left() << " && " << expr->right() << ")";
            break;
        case SurveyTargetExpression::OpLogicOr:
            debug.nospace() << "(" << expr->left() << " || " << expr->right() << ")";
            break;
        case SurveyTargetExpression::OpEqual:
            debug.nospace() << "[" << expr->left() << " == " << expr->right() << "]";
            break;
        case SurveyTargetExpression::OpNotEqual:
            debug.nospace() << "[" << expr->left() << " != " << expr->right() << "]";
            break;
        case SurveyTargetExpression::OpGreater:
            debug.nospace() << "[" << expr->left() << " > " << expr->right() << "]";
            break;
        case SurveyTargetExpression::OpGreaterEqual:
            debug.nospace() << "[" << expr->left() << " >= " << expr->right() << "]";
            break;
        case SurveyTargetExpression::OpLess:
            debug.nospace() << "[" << expr->left() << " < " << expr->right() << "]";
            break;
        case SurveyTargetExpression::OpLessEqual:
            debug.nospace() << "[" << expr->left() << " <= " << expr->right() << "]";
            break;
    }

    return debug;
}