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
jkqtmathtextmodifyenvironmentnode.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 JKQTMATHTEXTMODIFYTEXTPROPSINSTRUCTIONNODE_H
25#define JKQTMATHTEXTMODIFYTEXTPROPSINSTRUCTIONNODE_H
26#include "jkqtmathtext/jkqtmathtext_imexport.h"
27#include "jkqtmathtext/jkqtmathtexttools.h"
28#include "jkqtmathtext/nodes/jkqtmathtextnode.h"
29#include "jkqtmathtext/nodes/jkqtmathtextinstructionnode.h"
30#include <QPainter>
31#include <functional>
32
33class JKQTMathText; // forward
34// JKQTMATHTEXT_LIB_EXPORT
35
36/** \brief subclass representing an instruction node which modifies the current
37 * font (as defined in JKQTMathTextEnvironment), for it's child node,
38 * i.e. it represents instructions like \c \\textbf{...}, \c \\ul{underlinedText}, ...
39 * \ingroup jkqtmathtext_items
40 *
41 * \note Instructions that modify the text for any further nodes WITHIN the
42 * current block are represented by JKQTMathTextModifiedEnvironmentInstructionNode
43 */
45 public:
46 explicit JKQTMathTextModifiedTextPropsInstructionNode(JKQTMathText* parent, const QString& name, JKQTMathTextNode* child, const QStringList& parameters=QStringList());
48 /** \copydoc JKQTMathTextNode::getTypeName() */
49 virtual QString getTypeName() const override;
50 /** \copydoc JKQTMathTextNode::draw() */
51 virtual double draw(QPainter& painter, double x, double y, JKQTMathTextEnvironment currentEv) const override;
52 /** \copydoc JKQTMathTextNode::toHtml() */
53 virtual bool toHtml(QString& html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override;
54
55 /** \brief returns true, if the given \a instructionName can be represented by this node
56 * \see instructions()
57 */
58 static bool supportsInstructionName(const QString& instructionName);
59 /** \brief returns the number of additional string parameters, required for the given \a instructionName
60 * \see instructions()
61 */
62 static size_t countParametersOfInstruction(const QString& instructionName);
63 /** \brief sets \a insideMath to \c true if inside the node is to be parsed in math mode and \c false else
64 * \see instructions()
65 */
66 static void modifyInMathEnvironment(const QString& instructionName, bool& insideMath, bool &insideMathTextStyle, const QStringList &params=QStringList());
67
68 protected:
69 /** \copydoc JKQTMathTextNode::getSizeInternal() */
70 virtual JKQTMathTextNodeSize getSizeInternal(QPainter& painter, JKQTMathTextEnvironment currentEv) const override;
71 /** \brief defines the implementation of an instruction represented by JKQTMathTextModifiedTextPropsInstructionNode */
73 /** \brief this functor implements the instruction */
74 typedef std::function<void(JKQTMathTextEnvironment& ev, const QStringList& parameters)> ModifyEnvironmentFunctor;
75 /** \brief default constructor, creates a NOP-instruction that does nothing */
77 /** \brief constructor which gets a functor \a _modifier and a number of required parameters \a _NParams */
78 InstructionProperties(const ModifyEnvironmentFunctor& _modifier, size_t _NParams=0);
79 /** \brief number of parameters for this node */
80 size_t NParams;
81 /** \brief functor that modifies a JKQTMathTextEnvironment */
83 };
84
85 /** \brief defines all implemented instructions in this node
86 *
87 * \note this is the customization point for new instructions!
88 */
89 static const QHash<QString, InstructionProperties>& instructions();
90 /** \brief executes the instruction on \a ev */
92};
93
94
95
96/** \brief subclass representing an instruction node which modify the
97 * current JKQTMathTextEnvironment, in the current block. This
98 * implements functions like \c \\bf or \c \\color{COL}
99 * \ingroup jkqtmathtext_items
100 *
101 * \see JKQTMathTextModifyEnvironmentNodeMixIn
102 */
104 public:
105 explicit JKQTMathTextModifiedEnvironmentInstructionNode(JKQTMathText* parent_, const QString& instructionName_, const QStringList& parameters_=QStringList());
107 /** \copydoc JKQTMathTextNode::getTypeName() */
108 virtual QString getTypeName() const override;
109 /** \copydoc instructionName */
110 const QString& getInstructionName() const;
111 /** \copydoc parameters */
112 const QStringList& getParameters() const;
113 /** \copydoc JKQTMathTextModifyEnvironmentNodeMixIn::modifyEnvironment() */
114 virtual void modifyEnvironment(JKQTMathTextEnvironment& currentEv) const override;
115
116 /** \brief returns true, if the given \a instructionName can be represented by this node
117 * \see instructions()
118 */
119 static bool supportsInstructionName(const QString& instructionName);
120 /** \brief returns the number of additional string parameters, required for the given \a instructionName
121 * \see instructions()
122 */
123 static size_t countParametersOfInstruction(const QString& instructionName);
124 /** \brief sets \a insideMathTextStyle to \c true if textstyle is set inside math
125 * \see instructions()
126 */
127 static void modifyInMathTextStyleEnvironment(const QString& instructionName, bool &insideMathTextStyle, JKQTMathText *parentMathText, const QStringList &params=QStringList());
128 protected:
129 /** \brief instruction name */
131 /** \brief additional string-parameters */
132 QStringList parameters;
133 /** \brief defines the implementation of an instruction represented by JKQTMathTextModifiedTextPropsInstructionNode */
135 /** \brief this functor implements the instruction */
136 typedef std::function<void(JKQTMathTextEnvironment& ev, const QStringList& parameters, JKQTMathText* parentMathText)> ModifyEnvironmentFunctor;
137 /** \brief default constructor, creates a NOP-instruction that does nothing */
139 /** \brief constructor which gets a functor \a _modifier and a number of required parameters \a _NParams */
140 InstructionProperties(const ModifyEnvironmentFunctor& _modifier, size_t _NParams=0);
141 /** \brief number of parameters for this node */
142 size_t NParams;
143 /** \brief functor that modifies a JKQTMathTextEnvironment */
145 };
146
147 /** \brief defines all implemented instructions in this node
148 *
149 * \note this is the customization point for new instructions!
150 */
151 static const QHash<QString, InstructionProperties>& instructions();
152};
153
154
155
156
157#endif // JKQTMATHTEXTMODIFYTEXTPROPSINSTRUCTIONNODE_H
158
159
160
161
162
163
164
165
166
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
subclass representing an instruction node which modify the current JKQTMathTextEnvironment,...
Definition jkqtmathtextmodifyenvironmentnode.h:103
static const QHash< QString, InstructionProperties > & instructions()
defines all implemented instructions in this node
static bool supportsInstructionName(const QString &instructionName)
returns true, if the given instructionName can be represented by this node
JKQTMathTextModifiedEnvironmentInstructionNode(JKQTMathText *parent_, const QString &instructionName_, const QStringList &parameters_=QStringList())
const QStringList & getParameters() const
additional string-parameters
virtual ~JKQTMathTextModifiedEnvironmentInstructionNode() override
virtual void modifyEnvironment(JKQTMathTextEnvironment &currentEv) const override
modifies the fiven JKQTMathTextEnvironment currrentEv
QStringList parameters
additional string-parameters
Definition jkqtmathtextmodifyenvironmentnode.h:132
QString instructionName
instruction name
Definition jkqtmathtextmodifyenvironmentnode.h:130
const QString & getInstructionName() const
instruction name
virtual QString getTypeName() const override
return the name of this class as a string
static void modifyInMathTextStyleEnvironment(const QString &instructionName, bool &insideMathTextStyle, JKQTMathText *parentMathText, const QStringList &params=QStringList())
sets insideMathTextStyle to true if textstyle is set inside math
static size_t countParametersOfInstruction(const QString &instructionName)
returns the number of additional string parameters, required for the given instructionName
subclass representing an instruction node which modifies the current font (as defined in JKQTMathText...
Definition jkqtmathtextmodifyenvironmentnode.h:44
virtual bool toHtml(QString &html, JKQTMathTextEnvironment currentEv, JKQTMathTextEnvironment defaultEv) const override
convert node to HTML and returns true on success
virtual JKQTMathTextNodeSize getSizeInternal(QPainter &painter, JKQTMathTextEnvironment currentEv) const override
determine the size of the node, overwrite this function in derived classes
virtual ~JKQTMathTextModifiedTextPropsInstructionNode() override
static const QHash< QString, InstructionProperties > & instructions()
defines all implemented instructions in this node
JKQTMathTextModifiedTextPropsInstructionNode(JKQTMathText *parent, const QString &name, JKQTMathTextNode *child, const QStringList &parameters=QStringList())
static size_t countParametersOfInstruction(const QString &instructionName)
returns the number of additional string parameters, required for the given instructionName
static void modifyInMathEnvironment(const QString &instructionName, bool &insideMath, bool &insideMathTextStyle, const QStringList &params=QStringList())
sets insideMath to true if inside the node is to be parsed in math mode and false else
void executeInstruction(JKQTMathTextEnvironment &ev) const
executes the instruction on ev
static bool supportsInstructionName(const QString &instructionName)
returns true, if the given instructionName can be represented by this node
virtual QString getTypeName() const override
return the name of this class as a string
virtual double draw(QPainter &painter, double x, double y, JKQTMathTextEnvironment currentEv) const override
draw the contents at the designated position
mixin extending a node that does not produce any output, but provides a function modifyEnvironment() ...
Definition jkqtmathtextnode.h:322
subclass representing one node in the syntax tree
Definition jkqtmathtextnode.h:37
base class for all derived classes that do not draw anything
Definition jkqtmathtextnode.h:296
#define JKQTMATHTEXT_LIB_EXPORT
Definition jkqtmathtext_imexport.h:108
describes the current drawing environment (base fontname ...)
Definition jkqtmathtexttools.h:304
defines the implementation of an instruction represented by JKQTMathTextModifiedTextPropsInstructionN...
Definition jkqtmathtextmodifyenvironmentnode.h:134
InstructionProperties(const ModifyEnvironmentFunctor &_modifier, size_t _NParams=0)
constructor which gets a functor _modifier and a number of required parameters _NParams
InstructionProperties()
default constructor, creates a NOP-instruction that does nothing
std::function< void(JKQTMathTextEnvironment &ev, const QStringList &parameters, JKQTMathText *parentMathText)> ModifyEnvironmentFunctor
this functor implements the instruction
Definition jkqtmathtextmodifyenvironmentnode.h:136
size_t NParams
number of parameters for this node
Definition jkqtmathtextmodifyenvironmentnode.h:142
ModifyEnvironmentFunctor modifier
functor that modifies a JKQTMathTextEnvironment
Definition jkqtmathtextmodifyenvironmentnode.h:144
defines the implementation of an instruction represented by JKQTMathTextModifiedTextPropsInstructionN...
Definition jkqtmathtextmodifyenvironmentnode.h:72
ModifyEnvironmentFunctor modifier
functor that modifies a JKQTMathTextEnvironment
Definition jkqtmathtextmodifyenvironmentnode.h:82
InstructionProperties(const ModifyEnvironmentFunctor &_modifier, size_t _NParams=0)
constructor which gets a functor _modifier and a number of required parameters _NParams
std::function< void(JKQTMathTextEnvironment &ev, const QStringList &parameters)> ModifyEnvironmentFunctor
this functor implements the instruction
Definition jkqtmathtextmodifyenvironmentnode.h:74
size_t NParams
number of parameters for this node
Definition jkqtmathtextmodifyenvironmentnode.h:80
InstructionProperties()
default constructor, creates a NOP-instruction that does nothing
beschreibt die Größe(n) eines Knotens
Definition jkqtmathtexttools.h:393