libkpl  5.0
A Library for Graphical Presentation of Data Sets and Functions
funitem.h
1 /***************************************************************************
2  funitem.h - description
3  -------------------
4 
5  This file is a part of kpl - a program for graphical presentation of
6  data sets and functions.
7 
8  begin : Sun Aug 29 1999
9  copyright : (C) 2017 by Werner Stille
10  email : kpl@werner-stille.de
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 
22 #ifndef FUNITEM_H
23 #define FUNITEM_H
24 
25 #include <QVector>
26 #include <QUrl>
27 #include "scaleditem.h"
28 
29 class QLibrary;
30 class QTextStream;
31 class ArrayItem;
32 class LMFit;
33 
39 class Q_DECL_EXPORT FunItem : public ScaledItem
40 {
41 public:
43  static const int NumParMax = 20;
45  enum {
46  Type = UserType + Function
48  };
52  struct DataErrorStruct {
58  ColX,
59  ColY
60  };
62  DataErrorStruct() : errModArg(ColY) {};
67  bool fitErrCol;
71  double parErrMod[NumParMax];
76  };
78  FunItem();
83  FunItem(const FunItem& a);
92  FunItem(const KConfigGroup* plo, const QUrl& urlPlo, unsigned color = 0,
93  Symbol symbol = SolidLine, QGraphicsItem* parent = 0);
112  FunItem(const QUrl& url, const QString& name, unsigned color = 0,
113  Symbol symbol = SolidLine, double fx = 1, double fy = 1,
114  QGraphicsItem* parent = 0, double xMin = 0, double xMax = 0,
115  double deltaX = 0, bool visible = true,
116  FillStyle fillStyle = NoBrush, double xOffset = 0,
117  double yOffset = 0, double relSize = 1);
119  virtual ~FunItem();
121  virtual QRectF boundingRect() const;
130  static void calcTable(const double* x, double* values,
131  double (*func)(double, const double*),
132  const double* par, int n);
137  int calcTable() const;
143  int calcTable(bool logX) const;
145  inline double deltaT() const { return m_deltaT; };
152  static bool errorStructChanged(const DataErrorStruct& e1,
153  const DataErrorStruct& e2);
162  void exponent(int& expX, int& expY, double& fx, double& fy, bool logX) const;
170  void exportTable(QTextStream& stream, char separator, char format,
171  int precision) const;
192  static int fit(const QList<const ArrayItem*>* aList, QList<FunItem*>* fList,
193  const bool* bFit, double* par,
194  QVector<double>* resVector = 0, QVector<double>* sigma = 0,
195  FunItem::DataErrorStruct* err = 0, bool nonLin = true,
196  double tol = 1e-14, int itMax = 100, LMFit* lm = 0,
197  double* chiSquare = 0, double* corr = 0, double* parErr = 0,
198  double* avgErr = 0, QObject* parent = 0);
200  double (*funcY)(double, const double*);
202  inline const QLibrary* libY() const { return m_libY; };
211  void limits(double& xMin, double& xMax, double& yMin, double& yMax,
212  bool logX) const;
214  inline QString nameY() const { return m_nameY; };
216  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
217  QWidget* widget = 0);
224  static bool parChanged(const double* p1, const double* p2);
232  static QString parToString(const double* par, char format, int precision);
234  inline double* parY() { return m_parY; };
236  void setDashOffset();
241  inline void setDeltaT(double deltaT) { m_deltaT = deltaT; };
248  bool setFuncY(const QUrl& url, const QString& name);
255  virtual void setPar(int i, double value, bool yFunc = true);
260  inline void setTMax(double xMax) { m_tMax = xMax; };
265  inline void setTMin(double xMin) { m_tMin = xMin; };
267  virtual QPainterPath shape() const;
273  static void stringToPar(const QString& s, double* par);
275  inline double tMax() const { return m_tMax; };
277  inline double tMin() const { return m_tMin; };
279  const double* tValues() const;
281  virtual int type() const { return Type; };
283  inline const QUrl& urlY() const { return m_urlY; };
292  void writePlo(KConfigGroup* plo, const QUrl& urlPlo, bool absolute,
293  char format, int precision) const;
295  double* yValues() const;
296 
297 protected:
299  void init();
304  void paintCond(QPainter* painter) const;
306  void unload();
307  mutable bool logXo;
308  double m_tMin, m_tMax, m_deltaT;
309  mutable double tMino, tMaxo, deltaTo;
310  mutable double (*funcYo)(double, const double*);
311  double m_parY[NumParMax];
312  mutable double parYo[NumParMax];
313  mutable QVector<double> m_tValues, m_yValues;
314  QString m_nameY;
315  QUrl m_urlY;
316  QLibrary* m_libY;
317 };
318 
319 #endif
Parameter fit class.
Definition: lmfit.h:41
FillStyle
Fill styles.
Definition: kplitem.h:45
bool fitErrCol
True for using error column of array item instead of error model function.
Definition: funitem.h:62
Symbol
Symbol types.
Definition: kplitem.h:83
const QUrl & urlY() const
Returns URL of y function library.
Definition: funitem.h:283
const QLibrary * libY() const
Returns pointer to library for y function.
Definition: funitem.h:202
double deltaT() const
Returns argument step size.
Definition: funitem.h:145
void setTMax(double xMax)
Sets maximum argument value.
Definition: funitem.h:260
void setTMin(double xMin)
Sets minimum argument value.
Definition: funitem.h:265
virtual int type() const
Returns specific QGraphicsItem type number.
Definition: funitem.h:281
Function item class.
Definition: funitem.h:39
x column.
Definition: funitem.h:58
QString errModPath
Path of library containing error model function.
Definition: funitem.h:75
Data error structure.
Definition: funitem.h:52
QString errModName
Name of error model function.
Definition: funitem.h:73
ErrorModelArgument
Error model function argument.
Definition: funitem.h:57
ErrorModelArgument errModArg
Error model function argument.
Definition: funitem.h:69
Scaled item class.
Definition: scaleditem.h:24
double tMax() const
Returns maximum argument value.
Definition: funitem.h:275
QString nameY() const
Returns y function name.
Definition: funitem.h:214
double * parY()
Returns y function parameter array pointer.
Definition: funitem.h:234
void setDeltaT(double deltaT)
Sets argument step size.
Definition: funitem.h:241
Array item class.
Definition: arrayitem.h:36
double tMin() const
Returns minimum argument value.
Definition: funitem.h:277