File indexing completed on 2025-03-02 03:46:52
0001 /* 0002 SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #include "surveytargetexpression.h" 0008 0009 using namespace KUserFeedback; 0010 0011 SurveyTargetExpression::SurveyTargetExpression(const QVariant &value) 0012 : m_type(Value) 0013 , m_value(value) 0014 { 0015 } 0016 0017 SurveyTargetExpression::SurveyTargetExpression(const QString& source, const QVariant &index, const QString& elem) 0018 : m_value(index) 0019 , m_source(source) 0020 , m_sourceElement(elem) 0021 { 0022 if (index.type() == QVariant::Int) 0023 m_type = ListElement; 0024 else if (index.type() == QVariant::String) 0025 m_type = MapElement; 0026 else 0027 m_type = ScalarElement; 0028 } 0029 0030 SurveyTargetExpression::SurveyTargetExpression(Type type, SurveyTargetExpression* left, SurveyTargetExpression* right) 0031 : m_type(type) 0032 , m_left(left) 0033 , m_right(right) 0034 { 0035 } 0036 0037 SurveyTargetExpression::~SurveyTargetExpression() 0038 { 0039 } 0040 0041 SurveyTargetExpression::Type SurveyTargetExpression::type() const 0042 { 0043 return m_type; 0044 } 0045 0046 QVariant SurveyTargetExpression::value() const 0047 { 0048 return m_value; 0049 } 0050 0051 QString SurveyTargetExpression::source() const 0052 { 0053 return m_source; 0054 } 0055 0056 QString SurveyTargetExpression::sourceElement() const 0057 { 0058 return m_sourceElement; 0059 } 0060 0061 SurveyTargetExpression* SurveyTargetExpression::left() const 0062 { 0063 return m_left.get(); 0064 } 0065 0066 SurveyTargetExpression* SurveyTargetExpression::right() const 0067 { 0068 return m_right.get(); 0069 } 0070 0071 QDebug operator<<(QDebug debug, SurveyTargetExpression* expr) 0072 { 0073 if (!expr) { 0074 debug << "(null)"; 0075 return debug; 0076 } 0077 0078 switch (expr->type()) { 0079 case SurveyTargetExpression::Value: 0080 debug << expr->value().toString(); //toString() is needed for Qt4 support 0081 break; 0082 case SurveyTargetExpression::ScalarElement: 0083 debug.nospace() << expr->source() << "." << expr->sourceElement(); 0084 break; 0085 case SurveyTargetExpression::ListElement: 0086 debug.nospace() << expr->source() << "[" << expr->value().toInt() << "]." << expr->sourceElement(); 0087 break; 0088 case SurveyTargetExpression::MapElement: 0089 debug.nospace() << expr->source() << "[" << expr->value().toString() << "]." << expr->sourceElement(); 0090 break; 0091 case SurveyTargetExpression::OpLogicAnd: 0092 debug.nospace() << "(" << expr->left() << " && " << expr->right() << ")"; 0093 break; 0094 case SurveyTargetExpression::OpLogicOr: 0095 debug.nospace() << "(" << expr->left() << " || " << expr->right() << ")"; 0096 break; 0097 case SurveyTargetExpression::OpEqual: 0098 debug.nospace() << "[" << expr->left() << " == " << expr->right() << "]"; 0099 break; 0100 case SurveyTargetExpression::OpNotEqual: 0101 debug.nospace() << "[" << expr->left() << " != " << expr->right() << "]"; 0102 break; 0103 case SurveyTargetExpression::OpGreater: 0104 debug.nospace() << "[" << expr->left() << " > " << expr->right() << "]"; 0105 break; 0106 case SurveyTargetExpression::OpGreaterEqual: 0107 debug.nospace() << "[" << expr->left() << " >= " << expr->right() << "]"; 0108 break; 0109 case SurveyTargetExpression::OpLess: 0110 debug.nospace() << "[" << expr->left() << " < " << expr->right() << "]"; 0111 break; 0112 case SurveyTargetExpression::OpLessEqual: 0113 debug.nospace() << "[" << expr->left() << " <= " << expr->right() << "]"; 0114 break; 0115 } 0116 0117 return debug; 0118 }