JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
jkqtmathtextinstructionnode.h
1/*
2 Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>)
3 with contributions from: Razi Alavizadeh
4
5
6
7 This software is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License (LGPL) as published by
9 the Free Software Foundation, either version 2.1 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License (LGPL) for more details.
16
17 You should have received a copy of the GNU Lesser General Public License (LGPL)
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21
22
23
24#ifndef JKQTMATHTEXTINSTRUCTIONNODE_H
25#define JKQTMATHTEXTINSTRUCTIONNODE_H
26#include "jkqtmathtext/jkqtmathtext_imexport.h"
27#include "jkqtmathtext/jkqtmathtexttools.h"
28#include "jkqtmathtext/nodes/jkqtmathtextnode.h"
29#include <QPainter>
30#include <functional>
31
32class JKQTMathText; // forward
33// JKQTMATHTEXT_LIB_EXPORT
34
35/** \brief subclass representing an instruction node with exactly one argument and possibly additional parameters in the syntax tree
36 * This is a base-class without concrete implementations ... Implementations can be found in derived classes!
37 * \ingroup jkqtmathtext_items
38 *
39 * The parameters are sinple strings (e.g. directly for instructions like \c \\textcolor{color}{coloredLatexText},
40 * but they might also be translated into numbers or other properties.
41 *
42 * Typically derived nodes will provide static methods to determine the number of instructions
43 * and whether an instruction name is supported.
44 */
46 public:
47 explicit JKQTMathTextInstruction1Node(JKQTMathText* parent, const QString& name, JKQTMathTextNode* child, const QStringList& parameters=QStringList());
49 /** \copydoc instructionName */
50 const QString& getInstructionName() const;
51 /** \copydoc parameters */
52 const QStringList& getParameters() const;
53 protected:
54 /** \brief instruction name */
56 /** \brief additional string-parameters */
57 QStringList parameters;
58};
59
60
61
62/** \brief subclass representing a simple instruction node which only accepts string arguments, not LaTeX arguments
63 * i.e. it represents instructions like \c \\unicode{...}, ...
64 * \ingroup jkqtmathtext_items
65 */
67 public:
68 explicit JKQTMathTextSimpleInstructionNode(JKQTMathText* parent, const QString& name, const QStringList& parameters=QStringList());
70 /** \copydoc JKQTMathTextNode::getTypeName() */
71 virtual QString getTypeName() const override;
72 /** \copydoc JKQTMathTextNode::draw() */
73 virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
74 /** \copydoc JKQTMathTextNode::toHtml() */
75 virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
76 /** \copydoc instructionName */
77 const QString& getInstructionName() const;
78 /** \copydoc parameters */
79 const QStringList& getParameters() const;
80
81 /** \brief returns true, if the given \a instructionName can be represented by this node
82 * \see instructions
83 */
84 static bool supportsInstructionName(const QString& instructionName);
85 /** \brief returns the number of additional string parameters, required for the given \a instructionName
86 * \see instructions
87 */
88 static size_t countParametersOfInstruction(const QString& instructionName);
89
90 protected:
91 /** \copydoc JKQTMathTextNode::getSizeInternal() */
92 virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
93 /** \brief defines the implementation of an instruction represented by JKQTMathTextModifiedTextPropsInstructionNode */
95 /** \brief this functor implements the instruction */
96 typedef std::function<QString(const QStringList& parameters)> EvaluateInstructionFunctor;
97 /** \brief default constructor, creates a NOP-instruction that does nothing */
99 /** \brief constructor which gets a functor \a _modifier and a number of required parameters \a _NParams */
100 InstructionProperties(const EvaluateInstructionFunctor& _evaluator, size_t _NParams=0);
101 /** \brief number of parameters for this node */
102 size_t NParams;
103 /** \brief output of the instruction */
105 };
106 /** \brief defines all implemented instructions in this node
107 *
108 * \note this is the customization point for new instructions!
109 */
110 static const QHash<QString, InstructionProperties>& instructions();
111 /** \brief executes the instruction on \a ev */
112 QString executeInstruction() const;
113 /** \brief instruction name */
115 /** \brief additional string-parameters */
116 QStringList parameters;
117};
118
119
120
121#endif // JKQTMATHTEXTINSTRUCTIONNODE_H
122
123
124
125
126
127
128
129
130
this class parses a mathematical markup string and can then draw the contained text/equation onto a Q...
Definition jkqtmathtext.h:192
subclass representing an instruction node with exactly one argument and possibly additional parameter...
Definition jkqtmathtextinstructionnode.h:45
virtual ~JKQTMathTextInstruction1Node() override
QString instructionName
instruction name
Definition jkqtmathtextinstructionnode.h:55
JKQTMathTextInstruction1Node(JKQTMathText *parent, const QString &name, JKQTMathTextNode *child, const QStringList &parameters=QStringList())
const QStringList & getParameters() const
additional string-parameters
QStringList parameters
additional string-parameters
Definition jkqtmathtextinstructionnode.h:57
const QString & getInstructionName() const
instruction name
subclass representing one node in the syntax tree
Definition jkqtmathtextnode.h:37
subclass representing a simple instruction node which only accepts string arguments,...
Definition jkqtmathtextinstructionnode.h:66
virtual JKQTMathTextNodeSize getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const override
determine the size of the node, overwrite this function in derived classes
QString instructionName
instruction name
Definition jkqtmathtextinstructionnode.h:114
virtual bool toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override
convert node to HTML and returns true on success
static bool supportsInstructionName(const QString &instructionName)
returns true, if the given instructionName can be represented by this node
virtual double draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const override
draw the contents at the designated position
QString executeInstruction() const
executes the instruction on ev
JKQTMathTextSimpleInstructionNode(JKQTMathText *parent, const QString &name, const QStringList &parameters=QStringList())
QStringList parameters
additional string-parameters
Definition jkqtmathtextinstructionnode.h:116
virtual ~JKQTMathTextSimpleInstructionNode() override
static size_t countParametersOfInstruction(const QString &instructionName)
returns the number of additional string parameters, required for the given instructionName
static const QHash< QString, InstructionProperties > & instructions()
defines all implemented instructions in this node
virtual QString getTypeName() const override
return the name of this class as a string
const QStringList & getParameters() const
additional string-parameters
const QString & getInstructionName() const
instruction name
subclass representing a node in the syntax tree, that has one child
Definition jkqtmathtextnode.h:174
#define JKQTMATHTEXT_LIB_EXPORT
Definition jkqtmathtext_imexport.h:108
describes the current drawing environment (base fontname ...)
Definition jkqtmathtexttools.h:304
beschreibt die Größe(n) eines Knotens
Definition jkqtmathtexttools.h:393
defines the implementation of an instruction represented by JKQTMathTextModifiedTextPropsInstructionN...
Definition jkqtmathtextinstructionnode.h:94
std::function< QString(const QStringList &parameters)> EvaluateInstructionFunctor
this functor implements the instruction
Definition jkqtmathtextinstructionnode.h:96
EvaluateInstructionFunctor evaluator
output of the instruction
Definition jkqtmathtextinstructionnode.h:104
InstructionProperties()
default constructor, creates a NOP-instruction that does nothing
size_t NParams
number of parameters for this node
Definition jkqtmathtextinstructionnode.h:102
InstructionProperties(const EvaluateInstructionFunctor &_evaluator, size_t _NParams=0)
constructor which gets a functor _modifier and a number of required parameters _NParams