summaryrefslogtreecommitdiff
path: root/src/mbgl/style/layers/symbol_layer_impl.hpp
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-03-28 00:44:32 +0200
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-04-01 20:29:19 +0300
commit2325271c80023e680c71db065d4639d6e3da5f5a (patch)
tree0a3746cf0f478c5aa82ab561d661c2079d5004fc /src/mbgl/style/layers/symbol_layer_impl.hpp
parent4260644ef1d1689e4f4a5afe1f31685096d72efc (diff)
downloadqtlocation-mapboxgl-2325271c80023e680c71db065d4639d6e3da5f5a.tar.gz
[core] Traverse expression tree when checking for property overrides
Before this change, symbol layer was only checking whether top level 'text-field' layout property expression is FormatExpression and if it has paint property overrides. This change takes into account that 'text-field' might have nested expressions, thus, requires traversal over child expressions. Fixes: #14254
Diffstat (limited to 'src/mbgl/style/layers/symbol_layer_impl.hpp')
-rw-r--r--src/mbgl/style/layers/symbol_layer_impl.hpp62
1 files changed, 48 insertions, 14 deletions
diff --git a/src/mbgl/style/layers/symbol_layer_impl.hpp b/src/mbgl/style/layers/symbol_layer_impl.hpp
index f937fccaa8..9b63e0e8d6 100644
--- a/src/mbgl/style/layers/symbol_layer_impl.hpp
+++ b/src/mbgl/style/layers/symbol_layer_impl.hpp
@@ -3,9 +3,11 @@
#include <mbgl/style/layer_impl.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/layers/symbol_layer_properties.hpp>
+#include <mbgl/style/expression/literal.hpp>
#include <mbgl/style/expression/format_expression.hpp>
#include <mbgl/style/expression/formatted.hpp>
#include <mbgl/style/expression/format_section_override.hpp>
+#include <mbgl/style/expression/value.hpp>
namespace mbgl {
namespace style {
@@ -56,25 +58,57 @@ struct FormatSectionOverrides<TypeList<PaintProperty...>> {
template<typename Property, typename FormattedProperty>
static bool hasOverride(const FormattedProperty& formatted) {
+
+ const auto checkLiteral = [] (const TextField::Type& literal) {
+ for (const auto& section : literal.sections) {
+ if (Property::hasOverride(section)) {
+ return true;
+ }
+ }
+ return false;
+ };
+
return formatted.match(
- [] (const TextField::Type& t) {
- for (const auto& section : t.sections) {
- if (Property::hasOverride(section)) {
- return true;
- }
- }
- return false;
+ [&checkLiteral] (const TextField::Type& literal) {
+ return checkLiteral(literal);
},
- [] (const PropertyExpression<TextField::Type>& t) {
- if (t.getExpression().getKind() == expression::Kind::FormatExpression) {
- const auto* e = static_cast<const expression::FormatExpression*>(&t.getExpression());
- for (const auto& section : e->getSections()) {
- if (Property::hasOverride(section)) {
- return true;
+ [&checkLiteral] (const PropertyExpression<TextField::Type>& property) {
+ bool expressionHasOverrides = false;
+ const auto checkExpression = [&](const expression::Expression& e) {
+ if (expressionHasOverrides) {
+ return;
+ }
+
+ if (e.getKind() == expression::Kind::Literal &&
+ e.getType() == expression::type::Formatted) {
+ const auto* literalExpr = static_cast<const expression::Literal*>(&e);
+ const auto formattedValue = expression::fromExpressionValue<expression::Formatted>(literalExpr->getValue());
+ if (formattedValue && checkLiteral(*formattedValue)) {
+ expressionHasOverrides = true;
+ }
+ return;
+ }
+
+ if (e.getKind() == expression::Kind::FormatExpression) {
+ const auto* formatExpr = static_cast<const expression::FormatExpression*>(&e);
+ for (const auto& section : formatExpr->getSections()) {
+ if (Property::hasOverride(section)) {
+ expressionHasOverrides = true;
+ break;
+ }
}
}
+ };
+
+ // Check root property expression and return early.
+ checkExpression(property.getExpression());
+ if (expressionHasOverrides) {
+ return true;
}
- return false;
+
+ // Traverse thru children and check whether any of them have overrides.
+ property.getExpression().eachChild(checkExpression);
+ return expressionHasOverrides;
},
[] (const auto&) {
return false;