7#include "mapcsscondition_p.h"
8#include "mapcssresult.h"
9#include "mapcssstate_p.h"
16MapCSSCondition::MapCSSCondition() =
default;
17MapCSSCondition::MapCSSCondition(MapCSSCondition &&) =
default;
18MapCSSCondition::~MapCSSCondition() =
default;
27void MapCSSCondition::compile(
const OSM::DataSet &dataSet)
29 if (m_key ==
"mx:closed") {
30 m_tagKey = dataSet.
tagKey(
"opening_hours");
31 m_op = (m_op == KeyNotSet ? IsNotClosed : IsClosed);
33 m_tagKey = dataSet.
tagKey(m_key.constData());
42 if (m_value.isEmpty() && std::isnan(m_numericValue)) {
43 qWarning() <<
"Empty comparison, use key (not) set operation instead!";
50 if (std::isnan(m_numericValue)) {
51 qWarning() <<
"Numeric comparison without numeric value set!";
60bool MapCSSCondition::matches(
const MapCSSState &state,
const MapCSSResultLayer &result)
const
62 if (m_tagKey.isNull()) {
64 return m_op == KeyNotSet || m_op == NotEqual;
70 const auto tagIsSet =
tagValue.has_value();
77 if (std::isnan(m_numericValue)) {
78 return !tagIsSet ? false : *
tagValue == m_value;
80 return !tagIsSet ? false : toNumber(*tagValue) == m_numericValue;
82 if (std::isnan(m_numericValue)) {
83 return !tagIsSet ? true : *
tagValue != m_value;
85 return !tagIsSet ? true : toNumber(*tagValue) != m_numericValue;
86 case LessThan:
return !tagIsSet ? false : toNumber(*tagValue) < m_numericValue;
87 case GreaterThan:
return !tagIsSet ? false : toNumber(*tagValue) > m_numericValue;
88 case LessOrEqual:
return !tagIsSet ? false : toNumber(*tagValue) <= m_numericValue;
89 case GreaterOrEqual:
return !tagIsSet ? false : toNumber(*tagValue) >= m_numericValue;
93 if (!tagIsSet || (*tagValue).isEmpty() || !state.openingHours) {
94 return m_op == IsNotClosed;
96 const auto closed = state.openingHours->isEntirelyClosedInRange(state.element, *tagValue);
97 return m_op == IsClosed ? closed : !closed;
103bool MapCSSCondition::matchesCanvas(
const MapCSSState &state)
const
105 if (m_key !=
"level") {
115 case Equal:
return (state.floorLevel/10) == m_numericValue;
116 case NotEqual:
return (state.floorLevel/10) != m_numericValue;
117 case LessThan:
return (state.floorLevel/10) < m_numericValue;
118 case GreaterThan:
return (state.floorLevel/10) > m_numericValue;
119 case LessOrEqual:
return (state.floorLevel/10) <= m_numericValue;
120 case GreaterOrEqual:
return (state.floorLevel/10) >= m_numericValue;
126void MapCSSCondition::setKey(
const char *key,
int len)
131void MapCSSCondition::setOperation(MapCSSCondition::Operator op)
136void MapCSSCondition::setValue(
const char *value,
int len)
141void MapCSSCondition::setValue(
double val)
143 m_numericValue = val;
146void MapCSSCondition::write(
QIODevice *out)
const
149 if (m_op == KeyNotSet) { out->
write(
"!"); }
157 out->
write(
"]");
return;
158 case Equal: out->
write(
"=");
break;
159 case NotEqual: out->
write(
"!=");
break;
160 case LessThan: out->
write(
"<");
break;
161 case GreaterThan: out->
write(
">");
break;
162 case LessOrEqual: out->
write(
"<=");
break;
163 case GreaterOrEqual: out->
write(
">=");
break;
166 if (m_numericValue != NAN && m_value.isEmpty()) {
177void MapCSSConditionHolder::addCondition(MapCSSCondition *condition)
179 conditions.push_back(std::unique_ptr<MapCSSCondition>(condition));
Result of MapCSS stylesheet evaluation for a single layer selector.
std::optional< QByteArray > resolvedTagValue(OSM::TagKey key, const MapCSSState &state) const
Returns the tag value set by preceding declarations, via MapCSS expressions or in the source data.
A set of nodes, ways and relations.
TagKey tagKey(const char *keyName) const
Look up a tag key for the given tag name, if it exists.
OSM-based multi-floor indoor maps for buildings.
QByteArray tagValue(const Elem &elem, TagKey key)
Returns the tag value for key of elem.
QByteArray number(double n, char format, int precision)
double toDouble(bool *ok) const const
qint64 write(const QByteArray &data)