Krita Source Code Documentation
Loading...
Searching...
No Matches
EnhancedPathFormula.h
Go to the documentation of this file.
1
/* This file is part of the KDE project
2
* SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net>
3
*
4
* SPDX-License-Identifier: LGPL-2.0-or-later
5
*/
6
7
#ifndef KOENHANCEDPATHFORMULA_H
8
#define KOENHANCEDPATHFORMULA_H
9
10
#include <QString>
11
#include <QVariant>
12
13
class
EnhancedPathShape
;
14
15
class
FormulaToken
16
{
17
public
:
19
enum
Type
{
20
TypeUnknown
= 0,
21
TypeNumber
,
22
TypeOperator
,
23
TypeReference
,
24
TypeFunction
25
};
26
28
enum
Operator
{
29
OperatorInvalid
,
30
OperatorAdd
,
31
OperatorSub
,
32
OperatorMul
,
33
OperatorDiv
,
34
OperatorLeftPar
,
35
OperatorRightPar
,
36
OperatorComma
37
};
38
40
explicit
FormulaToken
(
Type
type
=
TypeUnknown
,
const
QString &
text
= QString(),
int
position
= -1);
41
43
FormulaToken
(
const
FormulaToken
&token);
44
46
FormulaToken
&
operator=
(
const
FormulaToken
&token);
47
49
Type
type
()
const
50
{
51
return
m_type
;
52
}
54
QString
text
()
const
55
{
56
return
m_text
;
57
}
59
int
position
()
const
60
{
61
return
m_position
;
62
}
63
65
bool
isNumber
()
const
66
{
67
return
m_type
==
TypeNumber
;
68
}
70
bool
isOperator
()
const
71
{
72
return
m_type
==
TypeOperator
;
73
}
75
bool
isFunction
()
const
76
{
77
return
m_type
==
TypeFunction
;
78
}
80
bool
isReference
()
const
81
{
82
return
m_type
==
TypeReference
;
83
}
84
86
qreal
asNumber
()
const
;
88
Operator
asOperator
()
const
;
89
private
:
90
Type
m_type
{
TypeUnknown
};
91
QString
m_text
;
92
int
m_position
{-1};
93
};
94
95
typedef
QList<FormulaToken>
TokenList
;
96
97
class
Opcode
;
98
99
class
EnhancedPathFormula
100
{
101
public
:
103
enum
Function
{
104
FunctionUnknown
,
105
// unary functions
106
FunctionAbs
,
107
FunctionSqrt
,
108
FunctionSin
,
109
FunctionCos
,
110
FunctionTan
,
111
FunctionAtan
,
112
// binary functions
113
FunctionAtan2
,
114
FunctionMin
,
115
FunctionMax
,
116
// ternary functions
117
FunctionIf
118
};
119
121
enum
Error
{
122
ErrorNone
,
123
ErrorValue
,
124
ErrorParse
,
125
ErrorCompile
,
126
ErrorName
127
};
128
130
EnhancedPathFormula
(
const
QString &text,
EnhancedPathShape
*parent);
131
133
~EnhancedPathFormula
();
134
141
qreal
evaluate
();
142
144
Error
error
()
const
145
{
146
return
m_error
;
147
}
148
150
QString
toString
()
const
;
151
private
:
153
TokenList
scan
(
const
QString &formula)
const
;
154
156
bool
compile
(
const
TokenList
&tokens);
157
164
qreal
evaluateFunction
(
Function
function,
const
QList<qreal>
&arguments)
const
;
165
167
void
debugTokens
(
const
TokenList
&tokens);
169
void
debugOpcodes
();
170
171
bool
m_valid
;
172
bool
m_compiled
;
173
Error
m_error
;
174
QString
m_text
;
175
QList<QVariant>
m_constants
;
176
QList<Opcode>
m_codes
;
177
EnhancedPathShape
*
m_parent
;
178
};
179
180
#endif
// KOENHANCEDPATHFORMULA_H
TokenList
QList< FormulaToken > TokenList
Definition
EnhancedPathFormula.h:95
EnhancedPathFormula
Definition
EnhancedPathFormula.h:100
EnhancedPathFormula::m_parent
EnhancedPathShape * m_parent
Definition
EnhancedPathFormula.h:177
EnhancedPathFormula::m_text
QString m_text
the formula text representation
Definition
EnhancedPathFormula.h:174
EnhancedPathFormula::toString
QString toString() const
returns string representation of the formula
Definition
EnhancedPathFormula.cpp:649
EnhancedPathFormula::~EnhancedPathFormula
~EnhancedPathFormula()
Destroys the formula.
Definition
EnhancedPathFormula.cpp:109
EnhancedPathFormula::m_constants
QList< QVariant > m_constants
constant values
Definition
EnhancedPathFormula.h:175
EnhancedPathFormula::evaluateFunction
qreal evaluateFunction(Function function, const QList< qreal > &arguments) const
Definition
EnhancedPathFormula.cpp:247
EnhancedPathFormula::m_compiled
bool m_compiled
flag that shows if function was compiled
Definition
EnhancedPathFormula.h:172
EnhancedPathFormula::m_valid
bool m_valid
flag that shows if function is valid, i.e the function was compiled successfully
Definition
EnhancedPathFormula.h:171
EnhancedPathFormula::m_codes
QList< Opcode > m_codes
the compiled byte code
Definition
EnhancedPathFormula.h:176
EnhancedPathFormula::debugTokens
void debugTokens(const TokenList &tokens)
Prints token list.
Definition
EnhancedPathFormula.cpp:817
EnhancedPathFormula::m_error
Error m_error
the last occurred error
Definition
EnhancedPathFormula.h:173
EnhancedPathFormula::scan
TokenList scan(const QString &formula) const
Separates the given formula text into tokens.
Definition
EnhancedPathFormula.cpp:292
EnhancedPathFormula::EnhancedPathFormula
EnhancedPathFormula(const QString &text, EnhancedPathShape *parent)
Constructs a new formula from the specified string representation.
Definition
EnhancedPathFormula.cpp:99
EnhancedPathFormula::Error
Error
The possible error code returned by error()
Definition
EnhancedPathFormula.h:121
EnhancedPathFormula::ErrorParse
@ ErrorParse
parsing error
Definition
EnhancedPathFormula.h:124
EnhancedPathFormula::ErrorValue
@ ErrorValue
error when converting value
Definition
EnhancedPathFormula.h:123
EnhancedPathFormula::ErrorCompile
@ ErrorCompile
compiling error
Definition
EnhancedPathFormula.h:125
EnhancedPathFormula::ErrorName
@ ErrorName
invalid function name value
Definition
EnhancedPathFormula.h:126
EnhancedPathFormula::ErrorNone
@ ErrorNone
no error
Definition
EnhancedPathFormula.h:122
EnhancedPathFormula::error
Error error() const
Returns the last occurred error.
Definition
EnhancedPathFormula.h:144
EnhancedPathFormula::Function
Function
predefined functions
Definition
EnhancedPathFormula.h:103
EnhancedPathFormula::FunctionAtan
@ FunctionAtan
Definition
EnhancedPathFormula.h:111
EnhancedPathFormula::FunctionSqrt
@ FunctionSqrt
Definition
EnhancedPathFormula.h:107
EnhancedPathFormula::FunctionSin
@ FunctionSin
Definition
EnhancedPathFormula.h:108
EnhancedPathFormula::FunctionAbs
@ FunctionAbs
Definition
EnhancedPathFormula.h:106
EnhancedPathFormula::FunctionTan
@ FunctionTan
Definition
EnhancedPathFormula.h:110
EnhancedPathFormula::FunctionUnknown
@ FunctionUnknown
Definition
EnhancedPathFormula.h:104
EnhancedPathFormula::FunctionCos
@ FunctionCos
Definition
EnhancedPathFormula.h:109
EnhancedPathFormula::FunctionIf
@ FunctionIf
Definition
EnhancedPathFormula.h:117
EnhancedPathFormula::FunctionAtan2
@ FunctionAtan2
Definition
EnhancedPathFormula.h:113
EnhancedPathFormula::FunctionMin
@ FunctionMin
Definition
EnhancedPathFormula.h:114
EnhancedPathFormula::FunctionMax
@ FunctionMax
Definition
EnhancedPathFormula.h:115
EnhancedPathFormula::debugOpcodes
void debugOpcodes()
Prints byte code.
Definition
EnhancedPathFormula.cpp:828
EnhancedPathFormula::compile
bool compile(const TokenList &tokens)
Compiles the formula tokens into byte code.
Definition
EnhancedPathFormula.cpp:426
EnhancedPathFormula::evaluate
qreal evaluate()
Definition
EnhancedPathFormula.cpp:113
EnhancedPathShape
Definition
EnhancedPathShape.h:38
FormulaToken
Definition
EnhancedPathFormula.h:16
FormulaToken::type
Type type() const
Returns the type of the token.
Definition
EnhancedPathFormula.h:49
FormulaToken::operator=
FormulaToken & operator=(const FormulaToken &token)
assignment operator
Definition
EnhancedPathFormula.cpp:666
FormulaToken::text
QString text() const
Returns the text representation of the token.
Definition
EnhancedPathFormula.h:54
FormulaToken::isFunction
bool isFunction() const
Returns if token is a function.
Definition
EnhancedPathFormula.h:75
FormulaToken::FormulaToken
FormulaToken(Type type=TypeUnknown, const QString &text=QString(), int position=-1)
Constructs token with given type, text and position.
Definition
EnhancedPathFormula.cpp:654
FormulaToken::Operator
Operator
operator types
Definition
EnhancedPathFormula.h:28
FormulaToken::OperatorComma
@ OperatorComma
, comma
Definition
EnhancedPathFormula.h:36
FormulaToken::OperatorLeftPar
@ OperatorLeftPar
(left parentheses
Definition
EnhancedPathFormula.h:34
FormulaToken::OperatorAdd
@ OperatorAdd
Definition
EnhancedPathFormula.h:30
FormulaToken::OperatorInvalid
@ OperatorInvalid
invalid operator
Definition
EnhancedPathFormula.h:29
FormulaToken::OperatorRightPar
@ OperatorRightPar
) right parentheses
Definition
EnhancedPathFormula.h:35
FormulaToken::OperatorSub
@ OperatorSub
Definition
EnhancedPathFormula.h:31
FormulaToken::OperatorMul
@ OperatorMul
Definition
EnhancedPathFormula.h:32
FormulaToken::OperatorDiv
@ OperatorDiv
/ division
Definition
EnhancedPathFormula.h:33
FormulaToken::isOperator
bool isOperator() const
Returns if the token is a operator, OperatorInvalid if token is no operator.
Definition
EnhancedPathFormula.h:70
FormulaToken::asOperator
Operator asOperator() const
Returns the token as operator.
Definition
EnhancedPathFormula.cpp:688
FormulaToken::asNumber
qreal asNumber() const
Returns the token converted to qreal.
Definition
EnhancedPathFormula.cpp:679
FormulaToken::m_text
QString m_text
the token text representation
Definition
EnhancedPathFormula.h:91
FormulaToken::isReference
bool isReference() const
Returns if token is a reference.
Definition
EnhancedPathFormula.h:80
FormulaToken::m_type
Type m_type
the token type
Definition
EnhancedPathFormula.h:90
FormulaToken::Type
Type
token types
Definition
EnhancedPathFormula.h:19
FormulaToken::TypeReference
@ TypeReference
function reference, modifier reference or named variable
Definition
EnhancedPathFormula.h:23
FormulaToken::TypeOperator
@ TypeOperator
+, *, /, -
Definition
EnhancedPathFormula.h:22
FormulaToken::TypeNumber
@ TypeNumber
14, 3, 1977, 3.141592, 1e10, 5.9e-7
Definition
EnhancedPathFormula.h:21
FormulaToken::TypeUnknown
@ TypeUnknown
unknown type
Definition
EnhancedPathFormula.h:20
FormulaToken::TypeFunction
@ TypeFunction
function name
Definition
EnhancedPathFormula.h:24
FormulaToken::isNumber
bool isNumber() const
Returns if the token is a number.
Definition
EnhancedPathFormula.h:65
FormulaToken::position
int position() const
Returns the position of the token.
Definition
EnhancedPathFormula.h:59
FormulaToken::m_position
int m_position
the tokens position
Definition
EnhancedPathFormula.h:92
Opcode
Definition
EnhancedPathFormula.cpp:86
QList
Definition
KisQStringListFwd.h:16
plugins
flake
pathshapes
enhancedpath
EnhancedPathFormula.h
Generated at
2025-11-04 02:30:02+01:00
from
Krita
branch
master
, commit
c9dde2e79561a8aea4a7e8d9ac99c98a7bac9e52