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>();
75 auto maxWidth = m_maxWidth.
resolve(c).value<
int>();
77 auto result = (tv / mv) * maxWidth;
79 result = round(result);
82 (*stream) << QString::number(result);
Q_INVOKABLE QStringList smartSplit(const QString &str) const
The Context class holds the context to render a Template with.
An exception for use when implementing template tags.
A FilterExpression object represents a filter expression in a template.
QVariant resolve(OutputStream *stream, Context *c) const
Base class for all nodes.
The OutputStream class is used to render templates to a QTextStream.
The Parser class processes a string template into a tree of nodes.
Node * getNode(const QString &tagContent, Parser *p) const override
void render(OutputStream *stream, Context *c) const override