2015-07-11 18:56:02 +08:00
/*
2024-02-06 21:50:49 +08:00
Copyright ( c ) 2008 - 2024 Jan W . Krieger ( < jan @ jkrieger . de > )
2015-07-11 18:56:02 +08:00
2015-07-12 22:34:27 +08:00
2015-07-11 18:56:02 +08:00
This software is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License ( LGPL ) as published by
2019-02-08 00:24:46 +08:00
the Free Software Foundation , either version 2.1 of the License , or
2015-07-11 18:56:02 +08:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License ( LGPL ) for more details .
You should have received a copy of the GNU Lesser General Public License ( LGPL )
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2018-12-19 00:13:18 +08:00
# ifndef jkqtpgraphsparsedfunction_H
# define jkqtpgraphsparsedfunction_H
2015-07-11 18:56:02 +08:00
# include <QString>
# include <QPainter>
# include <QPair>
2019-05-30 04:40:02 +08:00
# include "jkqtplotter/jkqtptools.h"
2023-03-15 21:37:25 +08:00
# include "jkqtmath/jkqtpmathparser.h"
2019-06-22 20:21:32 +08:00
# include "jkqtplotter/jkqtplotter_imexport.h"
2019-06-20 22:06:31 +08:00
# include "jkqtplotter/graphs/jkqtpevaluatedfunction.h"
2015-07-11 18:56:02 +08:00
// forward declarations
2019-01-20 17:49:29 +08:00
class JKQTBasePlotter ;
2019-01-20 23:15:10 +08:00
class JKQTPlotter ;
2015-07-11 18:56:02 +08:00
2020-09-08 02:57:25 +08:00
/** \brief extends JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase with the capabilities to define functions from strings
* that are parsed by JKQTPMathParser
* \ ingroup jkqtplotter_functiongraphs
*
* \ see JKQTPXParsedFunctionLineGraph and JKQTPYParsedFunctionLineGraph for a concrete implementation , see also JKQTPMathParser
*/
class JKQTPLOTTER_LIB_EXPORT JKQTPParsedFunctionLineGraphBase : public JKQTPEvaluatedFunctionWithErrorsGraphDrawingBase {
Q_OBJECT
public :
/** \brief class constructor */
JKQTPParsedFunctionLineGraphBase ( const QString & dependentVariableName , JKQTBasePlotter * parent = nullptr ) ;
/** \brief class constructor */
JKQTPParsedFunctionLineGraphBase ( const QString & dependentVariableName , JKQTPlotter * parent ) ;
/** \brief class constructor */
JKQTPParsedFunctionLineGraphBase ( const QString & dependentVariableName , const QString & function , JKQTBasePlotter * parent = nullptr ) ;
/** \brief class constructor */
JKQTPParsedFunctionLineGraphBase ( const QString & dependentVariableName , const QString & function , JKQTPlotter * parent ) ;
/** \brief class destructor */
virtual ~ JKQTPParsedFunctionLineGraphBase ( ) override ;
/** \copydoc function */
QString getFunction ( ) const ;
/** \copydoc errorFunction */
QString getErrorFunction ( ) const ;
/** \copydoc dependentVariableName */
QString getDependentVariableName ( ) const ;
2023-07-22 20:26:02 +08:00
public Q_SLOTS :
2020-09-08 02:57:25 +08:00
/** \copydoc errorFunction */
void setErrorFunction ( const QString & __value ) ;
/** \copydoc function */
void setFunction ( const QString & __value ) ;
protected :
/** \brief INTERNAL data structure combining a JKQTPMathParser and a JKQTPMathParser::jkmpNode
*/
struct ParsedFunctionLineGraphFunctionData {
2024-01-10 17:35:43 +08:00
inline ParsedFunctionLineGraphFunctionData ( ) : varcount ( 0 ) { } ;
2020-09-08 02:57:25 +08:00
std : : shared_ptr < JKQTPMathParser > parser ;
std : : shared_ptr < JKQTPMathParser : : jkmpNode > node ;
int varcount ;
QString dependentVariableName ;
} ;
/** \brief nache of the dependent variable (e.g. x for a function f(x) ) */
QString dependentVariableName ;
/** \brief the function to be evaluated for the plot. Use \c x as the free variable, e.g. \c "x^2+2" */
QString function ;
/** \brief parser data structure for function */
ParsedFunctionLineGraphFunctionData fdata ;
/** \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". */
QString errorFunction ;
/** \brief parser data structure for errorFunction */
ParsedFunctionLineGraphFunctionData efdata ;
/** \brief implements the actual plot function */
static double evaluateParsedFunction ( double x , ParsedFunctionLineGraphFunctionData * fdata ) ;
} ;
2015-07-11 18:56:02 +08:00
/*! \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
2022-10-23 03:07:14 +08:00
\ ingroup jkqtplotter_functiongraphs
2015-07-11 18:56:02 +08:00
Additional function parameters may be given in the vector parameters . They are accessible in the function as \ c p1 , \ c p2 , \ c p3 , . . .
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 .
2018-12-24 22:07:14 +08:00
Use the variable \ c x in an equation to refer to the free parameter of the curve .
2019-06-13 16:27:06 +08:00
\ see \ ref JKQTPlotterParsedFunctionPlot , JKQTPMathParser
2015-07-11 18:56:02 +08:00
*/
2020-09-08 02:57:25 +08:00
class JKQTPLOTTER_LIB_EXPORT JKQTPXParsedFunctionLineGraph : public JKQTPParsedFunctionLineGraphBase {
2018-12-24 22:07:14 +08:00
Q_OBJECT
2015-07-11 18:56:02 +08:00
public :
/** \brief class constructor */
2019-01-20 17:49:29 +08:00
JKQTPXParsedFunctionLineGraph ( JKQTBasePlotter * parent = nullptr ) ;
2015-08-02 19:36:54 +08:00
/** \brief class constructor */
2019-01-20 23:15:10 +08:00
JKQTPXParsedFunctionLineGraph ( JKQTPlotter * parent ) ;
2015-08-02 19:36:54 +08:00
2020-09-08 02:57:25 +08:00
/** \brief class constructor */
JKQTPXParsedFunctionLineGraph ( const QString & function , JKQTBasePlotter * parent = nullptr ) ;
/** \brief class constructor */
JKQTPXParsedFunctionLineGraph ( const QString & function , JKQTPlotter * parent ) ;
2015-07-11 18:56:02 +08:00
/** \brief class destructor */
2019-01-20 17:49:29 +08:00
virtual ~ JKQTPXParsedFunctionLineGraph ( ) override ;
2015-07-11 18:56:02 +08:00
2020-09-08 02:57:25 +08:00
/** \brief plots the graph to the plotter object specified as parent */
virtual void draw ( JKQTPEnhancedPainter & painter ) override ;
2015-07-11 18:56:02 +08:00
2018-12-24 03:27:24 +08:00
protected :
2015-07-11 18:56:02 +08:00
2020-09-08 02:57:25 +08:00
/** \copydoc JKQTPEvaluatedFunctionGraphBase::buildPlotFunctorSpec() */
virtual PlotFunctorSpec buildPlotFunctorSpec ( ) override ;
2018-12-24 22:07:14 +08:00
2020-09-08 02:57:25 +08:00
/** \copydoc JKQTPEvaluatedFunctionWithErrorsGraphBase::buildPlotFunctorSpec() */
virtual std : : function < QPointF ( double ) > buildErrorFunctorSpec ( ) override ;
2018-12-24 22:07:14 +08:00
} ;
/*! \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
2022-10-23 03:07:14 +08:00
\ ingroup jkqtplotter_functiongraphs
2018-12-24 22:07:14 +08:00
Additional function parameters may be given in the vector parameters . They are accessible in the function as \ c p1 , \ c p2 , \ c p3 , . . .
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 .
Use the variable \ c y in an equation to refer to the free parameter of the curve ( \ c is also understood for convenience ) .
2019-06-13 16:27:06 +08:00
\ see \ ref JKQTPlotterParsedFunctionPlot , JKQTPMathParser
2018-12-24 22:07:14 +08:00
*/
2020-09-08 02:57:25 +08:00
class JKQTPLOTTER_LIB_EXPORT JKQTPYParsedFunctionLineGraph : public JKQTPParsedFunctionLineGraphBase {
2018-12-24 22:07:14 +08:00
Q_OBJECT
public :
/** \brief class constructor */
2019-01-20 17:49:29 +08:00
JKQTPYParsedFunctionLineGraph ( JKQTBasePlotter * parent = nullptr ) ;
2018-12-24 22:07:14 +08:00
/** \brief class constructor */
2019-01-20 23:15:10 +08:00
JKQTPYParsedFunctionLineGraph ( JKQTPlotter * parent ) ;
2018-12-24 22:07:14 +08:00
2020-09-08 02:57:25 +08:00
/** \brief class constructor */
JKQTPYParsedFunctionLineGraph ( const QString & function , JKQTBasePlotter * parent = nullptr ) ;
/** \brief class constructor */
JKQTPYParsedFunctionLineGraph ( const QString & function , JKQTPlotter * parent ) ;
2018-12-24 22:07:14 +08:00
/** \brief class destructor */
2019-01-20 17:49:29 +08:00
virtual ~ JKQTPYParsedFunctionLineGraph ( ) override ;
2018-12-24 22:07:14 +08:00
2020-09-08 02:57:25 +08:00
/** \brief plots the graph to the plotter object specified as parent */
virtual void draw ( JKQTPEnhancedPainter & painter ) override ;
2018-12-24 22:07:14 +08:00
protected :
2020-09-08 02:57:25 +08:00
/** \copydoc JKQTPEvaluatedFunctionGraphBase::buildPlotFunctorSpec() */
virtual PlotFunctorSpec buildPlotFunctorSpec ( ) override ;
/** \copydoc JKQTPEvaluatedFunctionWithErrorsGraphBase::buildPlotFunctorSpec() */
virtual std : : function < QPointF ( double ) > buildErrorFunctorSpec ( ) override ;
2015-07-11 18:56:02 +08:00
} ;
2018-12-19 00:13:18 +08:00
# endif // jkqtpgraphsparsedfunction_H