7#include "surveytargetexpressionevaluator.h"
8#include "surveytargetexpression.h"
12SurveyTargetExpressionDataProvider::SurveyTargetExpressionDataProvider()
16SurveyTargetExpressionDataProvider::~SurveyTargetExpressionDataProvider()
20SurveyTargetExpressionEvaluator::SurveyTargetExpressionEvaluator()
25SurveyTargetExpressionEvaluator::~SurveyTargetExpressionEvaluator()
29void SurveyTargetExpressionEvaluator::setDataProvider(
const SurveyTargetExpressionDataProvider* provider)
31 m_provider = provider;
36#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
45#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
47 return order == QPartialOrdering::Less || order == QPartialOrdering::Equivalent;
53bool SurveyTargetExpressionEvaluator::evaluate(SurveyTargetExpression* expression)
56 switch (expression->type()) {
57 case SurveyTargetExpression::OpLogicAnd:
58 return evaluate(expression->left()) && evaluate(expression->right());
59 case SurveyTargetExpression::OpLogicOr:
60 return evaluate(expression->left()) || evaluate(expression->right());
66 const auto lhs = value(expression->left());
67 const auto rhs = value(expression->right());
74 switch (expression->type()) {
75 case SurveyTargetExpression::OpEqual:
77 case SurveyTargetExpression::OpNotEqual:
79 case SurveyTargetExpression::OpGreater:
80 return variantLess(rhs, lhs);
81 case SurveyTargetExpression::OpGreaterEqual:
82 return variantLessOrEqual(rhs, lhs);
83 case SurveyTargetExpression::OpLess:
84 return variantLess(lhs, rhs);
85 case SurveyTargetExpression::OpLessEqual:
86 return variantLessOrEqual(lhs, rhs);
94QVariant SurveyTargetExpressionEvaluator::value(SurveyTargetExpression* expression)
96 switch (expression->type()) {
97 case SurveyTargetExpression::Value:
98 return expression->value();
99 case SurveyTargetExpression::ScalarElement:
101 const auto v = value(expression->source());
102 if (v.canConvert<QVariantList>() && expression->sourceElement() ==
QLatin1String(
"size"))
103 return v.value<QVariantList>().size();
104 const auto m = v.toMap();
105 const auto it = m.find(expression->sourceElement());
106 if (it != m.end() && !it.value().canConvert<QVariantMap>())
112 case SurveyTargetExpression::ListElement:
114 const auto v = value(expression->source()).
value<QVariantList>().value(expression->value().
toInt());
115 return v.toMap().value(expression->sourceElement());
117 case SurveyTargetExpression::MapElement:
119 const auto v = value(expression->source()).
toMap().value(expression->value().
toString());
120 qDebug() << v << value(expression->source()).
toMap() << expression->value().
toString();
121 return v.toMap().value(expression->sourceElement());
133 Q_ASSERT(m_provider);
134 const auto it = m_dataCache.
constFind(source);
138 const auto v = m_provider->sourceData(source);
139 m_dataCache.
insert(source, v);
Classes for integrating telemetry collection, survey targeting, and contribution encouragenemt and co...
const_iterator constEnd() const const
const_iterator constFind(const Key &key) const const
iterator insert(const Key &key, const T &value)
QPartialOrdering compare(const QVariant &lhs, const QVariant &rhs)
int toInt(bool *ok) const const
QMap< QString, QVariant > toMap() const const
QString toString() const const