2015-07-11 18:56:02 +08:00
/*
2018-11-25 21:53:26 +08:00
Copyright ( c ) 2008 - 2018 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
the Free Software Foundation , either version 2 of the License , or
( 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
class JKQtBasePlotter ;
2015-08-02 19:36:54 +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
\ ingroup jkqtplotter_plots
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
*/
class 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 */
2018-11-18 18:59:30 +08:00
JKQTPxParsedFunctionLineGraph ( JKQtBasePlotter * parent = nullptr ) ;
2015-08-02 19:36:54 +08:00
/** \brief class constructor */
JKQTPxParsedFunctionLineGraph ( JKQtPlotter * parent ) ;
2015-07-11 18:56:02 +08:00
/** \brief class destructor */
2018-12-28 05:52:00 +08:00
virtual ~ JKQTPxParsedFunctionLineGraph ( ) override ;
2015-07-11 18:56:02 +08:00
2019-01-10 04:23:24 +08:00
/*! \brief sets the property function to the specified \a __value.
\ details Description of the parameter function is : < CENTER > \ copybrief function . < / CENTER >
\ see function for more information */
inline virtual void set_function ( const QString & __value )
{
this - > function = __value ;
}
/*! \brief returns the property function.
\ details Description of the parameter function is : < CENTER > \ copybrief function . < / CENTER >
\ see function for more information */
inline virtual QString get_function ( ) const
{
return this - > function ;
}
/*! \brief sets the property errorFunction to the specified \a __value.
\ details Description of the parameter errorFunction is : < CENTER > \ copybrief errorFunction . < / CENTER >
\ see errorFunction for more information */
inline virtual void set_errorFunction ( const QString & __value )
{
this - > errorFunction = __value ;
}
/*! \brief returns the property errorFunction.
\ details Description of the parameter errorFunction is : < CENTER > \ copybrief errorFunction . < / CENTER >
\ see errorFunction for more information */
inline virtual QString get_errorFunction ( ) const
{
return this - > errorFunction ;
}
2015-07-11 18:56:02 +08:00
2018-12-24 03:27:24 +08:00
/** \brief INTERNAL data structure
* \ internal
*/
struct JKQTPxParsedFunctionLineGraphFunctionData {
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 ;
JKQTPxParsedFunctionLineGraphFunctionData fdata ;
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 ;
JKQTPxParsedFunctionLineGraphFunctionData efdata ;
2018-12-24 22:07:14 +08:00
// hide functions that should not be used in this class!
using JKQTPxFunctionLineGraph : : set_plotFunction ;
using JKQTPxFunctionLineGraph : : set_params ;
using JKQTPxFunctionLineGraph : : set_errorPlotFunction ;
using JKQTPxFunctionLineGraph : : set_errorParams ;
/** \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 */
2018-12-28 05:52:00 +08:00
static double JKQTPxParsedFunctionLineGraphFunction ( double x , void * data ) ;
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
\ ingroup jkqtplotter_plots
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 ) .
*/
class LIB_EXPORT JKQTPyParsedFunctionLineGraph : public JKQTPyFunctionLineGraph {
Q_OBJECT
public :
/** \brief class constructor */
JKQTPyParsedFunctionLineGraph ( JKQtBasePlotter * parent = nullptr ) ;
/** \brief class constructor */
JKQTPyParsedFunctionLineGraph ( JKQtPlotter * parent ) ;
/** \brief class destructor */
2018-12-28 05:52:00 +08:00
virtual ~ JKQTPyParsedFunctionLineGraph ( ) override ;
2018-12-24 22:07:14 +08:00
2019-01-10 04:23:24 +08:00
/*! \brief sets the property function to the specified \a __value.
\ details Description of the parameter function is : < CENTER > \ copybrief function . < / CENTER >
\ see function for more information */
inline virtual void set_function ( const QString & __value )
{
this - > function = __value ;
}
/*! \brief returns the property function.
\ details Description of the parameter function is : < CENTER > \ copybrief function . < / CENTER >
\ see function for more information */
inline virtual QString get_function ( ) const
{
return this - > function ;
}
/*! \brief sets the property errorFunction to the specified \a __value.
\ details Description of the parameter errorFunction is : < CENTER > \ copybrief errorFunction . < / CENTER >
\ see errorFunction for more information */
inline virtual void set_errorFunction ( const QString & __value )
{
this - > errorFunction = __value ;
}
/*! \brief returns the property errorFunction.
\ details Description of the parameter errorFunction is : < CENTER > \ copybrief errorFunction . < / CENTER >
\ see errorFunction for more information */
inline virtual QString get_errorFunction ( ) const
{
return this - > errorFunction ;
}
2018-12-24 22:07:14 +08:00
/** \brief INTERNAL data structure
* \ internal
*/
struct JKQTPyParsedFunctionLineGraphFunctionData {
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 ;
JKQTPyParsedFunctionLineGraphFunctionData 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 ;
JKQTPyParsedFunctionLineGraphFunctionData efdata ;
// hide functions that should not be used in this class!
using JKQTPxFunctionLineGraph : : set_plotFunction ;
using JKQTPxFunctionLineGraph : : set_params ;
using JKQTPxFunctionLineGraph : : set_errorPlotFunction ;
using JKQTPxFunctionLineGraph : : set_errorParams ;
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 */
static double JKQTPyParsedFunctionLineGraphFunction ( double x , void * data ) ;
2015-07-11 18:56:02 +08:00
} ;
2018-12-19 00:13:18 +08:00
# endif // jkqtpgraphsparsedfunction_H