Krita Source Code Documentation
Loading...
Searching...
No Matches
KisNumericParser Namespace Reference

the namespace contains functions to transform math expression written as QString in numbers. More...

Functions

int parseIntegerMathExpr (QString const &expr, bool *noProblem=0)
 parse an expression to an int.
 
double parseSimpleMathExpr (QString const &expr, bool *noProblem=0)
 parse an expression to a double.
 

Detailed Description

the namespace contains functions to transform math expression written as QString in numbers.

Computation is done in a recursive way, maybe not the most efficient way compared to infix to postfix conversion before parsing. (TODO: look if it need to be changed).

Function Documentation

◆ parseIntegerMathExpr()

KRITAWIDGETUTILS_EXPORT int KisNumericParser::parseIntegerMathExpr ( QString const & expr,
bool * noProblem )

parse an expression to an int.

Parameters
exprthe expression to parse
noProblemif provided, the value pointed to will be se to true is no problem appeared, false otherwise.
Returns
the numerical value the expression eval to (or 0 in case of error).

Definition at line 69 of file kis_num_parser.cpp.

70{
71
72 bool ok = true; //intermediate variable to pass by reference to the sublevel parser (if no pointer is provided).
73
74 if (noProblem != nullptr) {
75 return qRound(treatLevel1Int(expr, *noProblem));
76 }
77
78 return qRound(treatLevel1Int(expr, ok));
79
80}
double treatLevel1Int(QString const &expr, bool &noProblem)
treatLevel1 treat an expression at the first level of recursion.

References treatLevel1Int().

◆ parseSimpleMathExpr()

KRITAWIDGETUTILS_EXPORT double KisNumericParser::parseSimpleMathExpr ( const QString & expr,
bool * noProblem )

parse an expression to a double.

Parameters
exprthe expression to parse
noProblemif provided, the value pointed to will be se to true is no problem appeared, false otherwise.
Returns
the numerical value the expression eval to (or 0 in case of error).

Definition at line 50 of file kis_num_parser.cpp.

51{
52
53 bool ok = true; //intermediate variable to pass by reference to the sublevel parser (if no pointer is provided).
54
55 //then go down each 3 levels of operation priority.
56 if (noProblem != nullptr) {
57 return treatLevel1(expr, *noProblem);
58 }
59
60 return treatLevel1(expr, ok);
61
62}
double treatLevel1(QString const &expr, bool &noProblem)
treatLevel1 treat an expression at the first level of recursion.

References treatLevel1().