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
jkqtpparsedfunction.h
1/*
2 Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>)
3
4
5
6 This software is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License (LGPL) as published by
8 the Free Software Foundation, either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License (LGPL) for more details.
15
16 You should have received a copy of the GNU Lesser General Public License (LGPL)
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20
21#ifndef jkqtpgraphsparsedfunction_H
22#define jkqtpgraphsparsedfunction_H
23
24#include <QString>
25#include <QPainter>
26#include <QPair>
27#include "jkqtplotter/jkqtptools.h"
28#include "jkqtmath/jkqtpmathparser.h"
29#include "jkqtplotter/jkqtplotter_imexport.h"
30#include "jkqtplotter/graphs/jkqtpevaluatedfunction.h"
31
32// forward declarations
33class JKQTBasePlotter;
34class JKQTPlotter;
35
36
37/** \brief extends JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase with the capabilities to define functions from strings
38 * that are parsed by JKQTPMathParser
39 * \ingroup jkqtplotter_functiongraphs
40 *
41 * \see JKQTPXParsedFunctionLineGraph and JKQTPYParsedFunctionLineGraph for a concrete implementation, see also JKQTPMathParser
42 */
44 Q_OBJECT
45public:
46
47
48 /** \brief class constructor */
49 JKQTPParsedFunctionLineGraphBase(const QString& dependentVariableName, JKQTBasePlotter* parent=nullptr);
50 /** \brief class constructor */
51 JKQTPParsedFunctionLineGraphBase(const QString& dependentVariableName, JKQTPlotter* parent);
52
53 /** \brief class constructor */
54 JKQTPParsedFunctionLineGraphBase(const QString& dependentVariableName, const QString& function, JKQTBasePlotter* parent=nullptr);
55 /** \brief class constructor */
56 JKQTPParsedFunctionLineGraphBase(const QString& dependentVariableName, const QString& function, JKQTPlotter* parent);
57
58
59 /** \brief class destructor */
61
62 /** \copydoc function */
63 QString getFunction() const;
64
65 /** \copydoc errorFunction */
66 QString getErrorFunction() const;
67 /** \copydoc dependentVariableName */
68 QString getDependentVariableName() const;
69
70public Q_SLOTS:
71 /** \copydoc errorFunction */
72 void setErrorFunction(const QString & __value);
73 /** \copydoc function */
74 void setFunction(const QString & __value);
75
76protected:
77
78 /** \brief INTERNAL data structure combining a JKQTPMathParser and a JKQTPMathParser::jkmpNode
79 */
81 inline ParsedFunctionLineGraphFunctionData(): varcount(0) {};
82 std::shared_ptr<JKQTPMathParser> parser;
83 std::shared_ptr<JKQTPMathParser::jkmpNode> node;
86 };
87
88 /** \brief nache of the dependent variable (e.g. x for a function f(x) ) */
90
91 /** \brief the function to be evaluated for the plot. Use \c x as the free variable, e.g. \c "x^2+2" */
92 QString function;
93 /** \brief parser data structure for function */
95
96 /** \brief the function to be evaluated to add error indicators to the graph. This function is evaluated to an error for every x. Use \c x as the free variable, e.g. \c "x^2+2". */
98 /** \brief parser data structure for errorFunction */
100
101 /** \brief implements the actual plot function */
103};
104
105
106
107/*! \brief This implements line plots where the data is taken from a user supplied function \f$ y=f(x) \f$ The function is defined as a string and parsed by JKMathParser
108 \ingroup jkqtplotter_functiongraphs
109
110 Additional function parameters may be given in the vector parameters. They are accessible in the function as \c p1 , \c p2 , \c p3 , ...
111 Parameters may also be given from a data column. Then first the params from the column and the the parameters from the vector are numbered.
112
113 Use the variable \c x in an equation to refer to the free parameter of the curve.
114
115 \see \ref JKQTPlotterParsedFunctionPlot, JKQTPMathParser
116 */
118 Q_OBJECT
119 public:
120
121
122 /** \brief class constructor */
124 /** \brief class constructor */
126
127 /** \brief class constructor */
128 JKQTPXParsedFunctionLineGraph(const QString& function, JKQTBasePlotter* parent=nullptr);
129 /** \brief class constructor */
130 JKQTPXParsedFunctionLineGraph(const QString& function, JKQTPlotter* parent);
131
132
133 /** \brief class destructor */
135
136 /** \brief plots the graph to the plotter object specified as parent */
137 virtual void draw(JKQTPEnhancedPainter& painter) override;
138
139 protected:
140
141
142 /** \copydoc JKQTPEvaluatedFunctionGraphBase::buildPlotFunctorSpec() */
144
145 /** \copydoc JKQTPEvaluatedFunctionWithErrorsGraphBase::buildPlotFunctorSpec() */
146 virtual std::function<QPointF(double)> buildErrorFunctorSpec() override;
147};
148
149
150
151
152/*! \brief This implements line plots where the data is taken from a user supplied function \f$ x=f(y) \f$ The function is defined as a string and parsed by JKMathParser
153 \ingroup jkqtplotter_functiongraphs
154
155 Additional function parameters may be given in the vector parameters. They are accessible in the function as \c p1 , \c p2 , \c p3 , ...
156 Parameters may also be given from a data column. Then first the params from the column and the the parameters from the vector are numbered.
157
158 Use the variable \c y in an equation to refer to the free parameter of the curve (\c is also understood for convenience).
159
160 \see \ref JKQTPlotterParsedFunctionPlot, JKQTPMathParser
161
162 */
164 Q_OBJECT
165 public:
166
167
168 /** \brief class constructor */
170 /** \brief class constructor */
172
173 /** \brief class constructor */
174 JKQTPYParsedFunctionLineGraph(const QString& function, JKQTBasePlotter* parent=nullptr);
175 /** \brief class constructor */
176 JKQTPYParsedFunctionLineGraph(const QString& function, JKQTPlotter* parent);
177
178
179 /** \brief class destructor */
181
182 /** \brief plots the graph to the plotter object specified as parent */
183 virtual void draw(JKQTPEnhancedPainter& painter) override;
184
185
186 protected:
187
188 /** \copydoc JKQTPEvaluatedFunctionGraphBase::buildPlotFunctorSpec() */
190
191 /** \copydoc JKQTPEvaluatedFunctionWithErrorsGraphBase::buildPlotFunctorSpec() */
192 virtual std::function<QPointF(double)> buildErrorFunctorSpec() override;
193};
194#endif // jkqtpgraphsparsedfunction_H
base class for 2D plotter classes (used by the plotter widget JKQTPlotter)
Definition jkqtpbaseplotter.h:394
this class extends the QPainter
Definition jkqtpenhancedpainter.h:33
This class extends JKQTPEvaluatedFunctionWithErrorsGraphBase with functions to draw the graphs and se...
Definition jkqtpevaluatedfunction.h:47
extends JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase with the capabilities to define functions fr...
Definition jkqtpparsedfunction.h:43
ParsedFunctionLineGraphFunctionData efdata
parser data structure for errorFunction
Definition jkqtpparsedfunction.h:99
static double evaluateParsedFunction(double x, ParsedFunctionLineGraphFunctionData *fdata)
implements the actual plot function
QString getDependentVariableName() const
nache of the dependent variable (e.g. x for a function f(x) )
JKQTPParsedFunctionLineGraphBase(const QString &dependentVariableName, const QString &function, JKQTPlotter *parent)
class constructor
JKQTPParsedFunctionLineGraphBase(const QString &dependentVariableName, JKQTBasePlotter *parent=nullptr)
class constructor
virtual ~JKQTPParsedFunctionLineGraphBase() override
class destructor
QString getErrorFunction() const
the function to be evaluated to add error indicators to the graph. This function is evaluated to an e...
ParsedFunctionLineGraphFunctionData fdata
parser data structure for function
Definition jkqtpparsedfunction.h:94
JKQTPParsedFunctionLineGraphBase(const QString &dependentVariableName, const QString &function, JKQTBasePlotter *parent=nullptr)
class constructor
QString function
the function to be evaluated for the plot. Use x as the free variable, e.g. "x^2+2"
Definition jkqtpparsedfunction.h:92
QString dependentVariableName
nache of the dependent variable (e.g. x for a function f(x) )
Definition jkqtpparsedfunction.h:89
JKQTPParsedFunctionLineGraphBase(const QString &dependentVariableName, JKQTPlotter *parent)
class constructor
QString errorFunction
the function to be evaluated to add error indicators to the graph. This function is evaluated to an e...
Definition jkqtpparsedfunction.h:97
QString getFunction() const
the function to be evaluated for the plot. Use x as the free variable, e.g. "x^2+2"
void setErrorFunction(const QString &__value)
the function to be evaluated to add error indicators to the graph. This function is evaluated to an e...
void setFunction(const QString &__value)
the function to be evaluated for the plot. Use x as the free variable, e.g. "x^2+2"
This implements line plots where the data is taken from a user supplied function The function is def...
Definition jkqtpparsedfunction.h:117
virtual std::function< QPointF(double)> buildErrorFunctorSpec() override
this function returns a functor that is used to generate the plot data in coordinate space,...
virtual void draw(JKQTPEnhancedPainter &painter) override
plots the graph to the plotter object specified as parent
JKQTPXParsedFunctionLineGraph(JKQTPlotter *parent)
class constructor
JKQTPXParsedFunctionLineGraph(const QString &function, JKQTBasePlotter *parent=nullptr)
class constructor
virtual PlotFunctorSpec buildPlotFunctorSpec() override
this function returns a functor that is used to generate the plot data in coordinate space,...
virtual ~JKQTPXParsedFunctionLineGraph() override
class destructor
JKQTPXParsedFunctionLineGraph(JKQTBasePlotter *parent=nullptr)
class constructor
JKQTPXParsedFunctionLineGraph(const QString &function, JKQTPlotter *parent)
class constructor
This implements line plots where the data is taken from a user supplied function The function is def...
Definition jkqtpparsedfunction.h:163
JKQTPYParsedFunctionLineGraph(const QString &function, JKQTPlotter *parent)
class constructor
JKQTPYParsedFunctionLineGraph(JKQTBasePlotter *parent=nullptr)
class constructor
JKQTPYParsedFunctionLineGraph(const QString &function, JKQTBasePlotter *parent=nullptr)
class constructor
virtual PlotFunctorSpec buildPlotFunctorSpec() override
this function returns a functor that is used to generate the plot data in coordinate space,...
virtual std::function< QPointF(double)> buildErrorFunctorSpec() override
this function returns a functor that is used to generate the plot data in coordinate space,...
virtual ~JKQTPYParsedFunctionLineGraph() override
class destructor
virtual void draw(JKQTPEnhancedPainter &painter) override
plots the graph to the plotter object specified as parent
JKQTPYParsedFunctionLineGraph(JKQTPlotter *parent)
class constructor
plotter widget for scientific plots (uses JKQTBasePlotter to do the actual drawing)
Definition jkqtplotter.h:364
#define JKQTPLOTTER_LIB_EXPORT
Definition jkqtplotter_imexport.h:89
specifies an internal plot functor
Definition jkqtpevaluatedfunctionbase.h:152
INTERNAL data structure combining a JKQTPMathParser and a JKQTPMathParser::jkmpNode.
Definition jkqtpparsedfunction.h:80
std::shared_ptr< JKQTPMathParser::jkmpNode > node
Definition jkqtpparsedfunction.h:83
QString dependentVariableName
Definition jkqtpparsedfunction.h:85
ParsedFunctionLineGraphFunctionData()
Definition jkqtpparsedfunction.h:81
std::shared_ptr< JKQTPMathParser > parser
Definition jkqtpparsedfunction.h:82