21 #include "widthratio.h" 23 #include "../lib/exception.h" 26 WidthRatioNodeFactory::WidthRatioNodeFactory() {}
32 if (expr.size() != 4) {
34 TagSyntaxError, QStringLiteral(
"widthratio takes three arguments"));
51 m_maxWidth = maxWidth;
54 int WidthRatioNode::round(qreal number)
56 auto intPart = (int)number;
57 if (number < (intPart + 0.5))
64 auto thisVal = m_valExpr.
resolve(c);
65 auto maxVal = m_maxExpr.
resolve(c);
66 if (!thisVal.isValid() || !maxVal.isValid())
69 auto tv = thisVal.
value<
double>();
70 auto mv = maxVal.value<
double>();
77 auto result = (tv / mv) * maxWidth;
79 result = round(result);
void render(OutputStream *stream, Context *c) const override
The Context class holds the context to render a Template with.
QString number(int n, int base)
Base class for all nodes.
Node * getNode(const QString &tagContent, Parser *p) const override
The OutputStream class is used to render templates to a QTextStream.
QVariant resolve(OutputStream *stream, Context *c) const
The Parser class processes a string template into a tree of nodes.
A FilterExpression object represents a filter expression in a template.
Q_INVOKABLE QStringList smartSplit(const QString &str) const
An exception for use when implementing template tags.