KUserFeedback

surveytargetexpression.cpp
1/*
2 SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#include "surveytargetexpression.h"
8
9using namespace KUserFeedback;
10
11SurveyTargetExpression::SurveyTargetExpression(const QVariant &value)
12 : m_type(Value)
13 , m_value(value)
14{
15}
16
17SurveyTargetExpression::SurveyTargetExpression(const QString& source, const QVariant &index, const QString& elem)
18 : m_value(index)
19 , m_source(source)
20 , m_sourceElement(elem)
21{
22 if (index.type() == QVariant::Int)
23 m_type = ListElement;
24 else if (index.type() == QVariant::String)
25 m_type = MapElement;
26 else
27 m_type = ScalarElement;
28}
29
30SurveyTargetExpression::SurveyTargetExpression(Type type, SurveyTargetExpression* left, SurveyTargetExpression* right)
31 : m_type(type)
32 , m_left(left)
33 , m_right(right)
34{
35}
36
37SurveyTargetExpression::~SurveyTargetExpression()
38{
39}
40
41SurveyTargetExpression::Type SurveyTargetExpression::type() const
42{
43 return m_type;
44}
45
46QVariant SurveyTargetExpression::value() const
47{
48 return m_value;
49}
50
51QString SurveyTargetExpression::source() const
52{
53 return m_source;
54}
55
56QString SurveyTargetExpression::sourceElement() const
57{
58 return m_sourceElement;
59}
60
61SurveyTargetExpression* SurveyTargetExpression::left() const
62{
63 return m_left.get();
64}
65
66SurveyTargetExpression* SurveyTargetExpression::right() const
67{
68 return m_right.get();
69}
70
71QDebug operator<<(QDebug debug, SurveyTargetExpression* expr)
72{
73 if (!expr) {
74 debug << "(null)";
75 return debug;
76 }
77
78 switch (expr->type()) {
79 case SurveyTargetExpression::Value:
80 debug << expr->value().toString(); //toString() is needed for Qt4 support
81 break;
82 case SurveyTargetExpression::ScalarElement:
83 debug.nospace() << expr->source() << "." << expr->sourceElement();
84 break;
85 case SurveyTargetExpression::ListElement:
86 debug.nospace() << expr->source() << "[" << expr->value().toInt() << "]." << expr->sourceElement();
87 break;
88 case SurveyTargetExpression::MapElement:
89 debug.nospace() << expr->source() << "[" << expr->value().toString() << "]." << expr->sourceElement();
90 break;
91 case SurveyTargetExpression::OpLogicAnd:
92 debug.nospace() << "(" << expr->left() << " && " << expr->right() << ")";
93 break;
94 case SurveyTargetExpression::OpLogicOr:
95 debug.nospace() << "(" << expr->left() << " || " << expr->right() << ")";
96 break;
97 case SurveyTargetExpression::OpEqual:
98 debug.nospace() << "[" << expr->left() << " == " << expr->right() << "]";
99 break;
100 case SurveyTargetExpression::OpNotEqual:
101 debug.nospace() << "[" << expr->left() << " != " << expr->right() << "]";
102 break;
103 case SurveyTargetExpression::OpGreater:
104 debug.nospace() << "[" << expr->left() << " > " << expr->right() << "]";
105 break;
106 case SurveyTargetExpression::OpGreaterEqual:
107 debug.nospace() << "[" << expr->left() << " >= " << expr->right() << "]";
108 break;
109 case SurveyTargetExpression::OpLess:
110 debug.nospace() << "[" << expr->left() << " < " << expr->right() << "]";
111 break;
112 case SurveyTargetExpression::OpLessEqual:
113 debug.nospace() << "[" << expr->left() << " <= " << expr->right() << "]";
114 break;
115 }
116
117 return debug;
118}
Type type(const QSqlDatabase &db)
Classes for integrating telemetry collection, survey targeting, and contribution encouragenemt and co...
QDebug operator<<(QDebug dbg, const PerceptualColor::MultiSpinBoxSection &value)
QDebug & nospace()
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)
Type type() const const
int toInt(bool *ok) const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.