2015-07-11 18:56:02 +08:00
/*
2019-01-12 23:01:55 +08:00
Copyright ( c ) 2008 - 2019 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>
2018-11-26 03:25:44 +08:00
# include "jkqtplottertools/jkqtptools.h"
# include "jkqtplottertools/jkqtpmathparser.h"
# include "jkqtplottertools/jkqtp_imexport.h"
2018-12-24 03:27:24 +08:00
# include "jkqtplotter/jkqtpgraphsevaluatedfunction.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
/*! \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
2019-01-13 01:53:16 +08:00
\ ingroup jkqtplotter_parsedFgraphs
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 .
2015-07-11 18:56:02 +08:00
*/
2019-02-03 21:04:48 +08:00
class JKQTP_LIB_EXPORT JKQTPXParsedFunctionLineGraph : public JKQTPXFunctionLineGraph {
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
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
2019-04-22 19:27:50 +08:00
/*! \copydoc function
2019-02-08 00:24:46 +08:00
\ see see function for details */
2019-04-22 19:27:50 +08:00
void setFunction ( const QString & __value ) ;
/*! \copydoc function
2019-02-08 00:24:46 +08:00
\ see see function for details */
2019-04-22 19:27:50 +08:00
QString getFunction ( ) const ;
2019-01-10 04:23:24 +08:00
2019-04-22 19:27:50 +08:00
/*! \copydoc errorFunction
2019-02-08 00:24:46 +08:00
\ see see errorFunction for details */
2019-04-22 19:27:50 +08:00
void setErrorFunction ( const QString & __value ) ;
/*! \copydoc errorFunction
2019-02-08 00:24:46 +08:00
\ see see errorFunction for details */
2019-04-22 19:27:50 +08:00
QString getErrorFunction ( ) const ;
2015-07-11 18:56:02 +08:00
2018-12-24 03:27:24 +08:00
/** \brief INTERNAL data structure
* \ internal
*/
2019-01-20 17:49:29 +08:00
struct JKQTPXParsedFunctionLineGraphFunctionData {
2018-12-24 03:27:24 +08:00
JKQTPMathParser * parser ;
JKQTPMathParser : : jkmpNode * node ;
int varcount ;
} ;
2015-07-11 18:56:02 +08:00
2018-12-24 03:27:24 +08:00
protected :
/** \brief the function to be evaluated for the plot. Use \c x as the free variable, e.g. \c "x^2+2" */
2015-07-11 18:56:02 +08:00
QString function ;
2019-01-20 17:49:29 +08:00
JKQTPXParsedFunctionLineGraphFunctionData fdata ;
2015-07-11 18:56:02 +08:00
2018-12-24 03:27:24 +08:00
/** \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". */
2015-07-11 18:56:02 +08:00
QString errorFunction ;
2019-01-20 17:49:29 +08:00
JKQTPXParsedFunctionLineGraphFunctionData efdata ;
2015-07-11 18:56:02 +08:00
2018-12-24 22:07:14 +08:00
// hide functions that should not be used in this class!
2019-04-22 19:27:50 +08:00
using JKQTPXFunctionLineGraph : : setPlotFunctionFunctor ;
2019-01-26 20:00:40 +08:00
using JKQTPXFunctionLineGraph : : setParams ;
using JKQTPXFunctionLineGraph : : setErrorPlotFunction ;
using JKQTPXFunctionLineGraph : : setErrorParams ;
2018-12-24 22:07:14 +08:00
/** \brief fill the data array with data from the function plotFunction */
2018-12-28 05:52:00 +08:00
virtual void createPlotData ( bool collectParams = true ) override ;
2018-12-24 22:07:14 +08:00
/** \brief implements the actual plot function */
2019-04-22 19:27:50 +08:00
static double JKQTPXParsedFunctionLineGraphFunction ( double x , void * data , JKQTPXParsedFunctionLineGraphFunctionData * fdata ) ;
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
2019-01-13 01:53:16 +08:00
\ ingroup jkqtplotter_parsedFgraphs
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-02-03 21:04:48 +08:00
class JKQTP_LIB_EXPORT JKQTPYParsedFunctionLineGraph : public JKQTPYFunctionLineGraph {
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
/** \brief class destructor */
2019-01-20 17:49:29 +08:00
virtual ~ JKQTPYParsedFunctionLineGraph ( ) override ;
2018-12-24 22:07:14 +08:00
2019-04-22 19:27:50 +08:00
/*! \copydoc function
2019-02-08 00:24:46 +08:00
\ see see function for details */
2019-04-22 19:27:50 +08:00
void setFunction ( const QString & __value ) ;
/*! \copydoc function
2019-02-08 00:24:46 +08:00
\ see see function for details */
2019-04-22 19:27:50 +08:00
QString getFunction ( ) const ;
2019-01-10 04:23:24 +08:00
2019-04-22 19:27:50 +08:00
/*! \copydoc errorFunction
2019-02-08 00:24:46 +08:00
\ see see errorFunction for details */
2019-04-22 19:27:50 +08:00
void setErrorFunction ( const QString & __value ) ;
/*! \copydoc errorFunction
2019-02-08 00:24:46 +08:00
\ see see errorFunction for details */
2019-04-22 19:27:50 +08:00
QString getErrorFunction ( ) const ;
2018-12-24 22:07:14 +08:00
/** \brief INTERNAL data structure
* \ internal
*/
2019-01-20 17:49:29 +08:00
struct JKQTPYParsedFunctionLineGraphFunctionData {
2018-12-24 22:07:14 +08:00
JKQTPMathParser * parser ;
JKQTPMathParser : : jkmpNode * node ;
int varcount ;
} ;
protected :
/** \brief the function to be evaluated for the plot. Use \c x as the free variable, e.g. \c "x^2+2" */
QString function ;
2019-01-20 17:49:29 +08:00
JKQTPYParsedFunctionLineGraphFunctionData fdata ;
2018-12-24 22:07:14 +08:00
/** \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 ;
2019-01-20 17:49:29 +08:00
JKQTPYParsedFunctionLineGraphFunctionData efdata ;
2018-12-24 22:07:14 +08:00
// hide functions that should not be used in this class!
2019-04-22 19:27:50 +08:00
using JKQTPXFunctionLineGraph : : setPlotFunctionFunctor ;
2019-01-26 20:00:40 +08:00
using JKQTPXFunctionLineGraph : : setParams ;
using JKQTPXFunctionLineGraph : : setErrorPlotFunction ;
using JKQTPXFunctionLineGraph : : setErrorParams ;
2015-07-11 18:56:02 +08:00
/** \brief fill the data array with data from the function plotFunction */
2018-12-28 05:52:00 +08:00
virtual void createPlotData ( bool collectParams = true ) override ;
2018-12-24 22:07:14 +08:00
/** \brief implements the actual plot function */
2019-04-22 19:27:50 +08:00
static double JKQTPYParsedFunctionLineGraphFunction ( double x , void * data , JKQTPYParsedFunctionLineGraphFunctionData * fdata ) ;
2015-07-11 18:56:02 +08:00
} ;
2018-12-19 00:13:18 +08:00
# endif // jkqtpgraphsparsedfunction_H