libkpl  6.0
A Library for Graphical Presentation of Data Sets and Functions
scaleditem.h
1//
2// C++ Interface: scaleditem
3//
4// Description:
5//
6//
7// Author: Werner Stille <kpl@werner-stille.de>, (C) 2024
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#ifndef SCALEDITEM_H
13#define SCALEDITEM_H
14
15#include <QGraphicsItem>
16#include <QPainterPath>
17#include <QRectF>
18#include "kplitem.h"
19
24class Q_DECL_EXPORT ScaledItem : public KplItem, public QGraphicsItem
25{
26public:
41 ScaledItem(const KConfigGroup* plo, Symbol symbol, unsigned color,
42 QGraphicsItem* parent);
55 ScaledItem(FillStyle fillStyle, Symbol symbol, unsigned color, double fx,
56 double fy, double xOffset, double yOffset, double relSize,
57 QGraphicsItem* parent);
59 virtual ~ScaledItem();
61 inline unsigned color() const { return m_color; };
68 static void exponent(double a, int& iExp, double& f);
70 inline FillStyle fillStyle() const { return m_fillStyle; };
77 inline bool isNormalized(double fx, double fy) const
78 { return (m_normX == fx) && (m_normY == fy); };
87 static bool limits(double& xMin, double& xMax, const double* values, int n);
93 inline void normalize(double fx, double fy) { m_normX = fx; m_normY = fy; };
95 inline double normX() const { return m_normX; };
97 inline double normY() const { return m_normY; };
99 QPixmap pixmap() const;
106 void readPlo(const KConfigGroup* plo, Symbol symbol, unsigned color);
111 inline void setColor(unsigned color) { m_color = color; };
116 inline void setFillStyle(FillStyle style) { m_fillStyle = style; };
121 inline void setNormX(double fx) { m_normX = fx; };
126 inline void setNormY(double fy) { m_normY = fy; };
131 void setProperties(const QTransform& m);
133 void setSize();
138 inline void setSymbol(Symbol symbol) { m_symbol = symbol; };
143 inline void setXOffset(double xOffset) { m_xOffset = xOffset; };
148 inline void setYOffset(double yOffset) { m_yOffset = yOffset; };
150 inline Symbol symbol() const { return m_symbol; };
152 void update();
160 void writePlo(KConfigGroup* plo, bool visible) const;
162 inline double xOffset() const { return m_xOffset; };
164 inline double yOffset() const { return m_yOffset; };
165
166protected:
174 double length(const double* x, const double* y, int n) const;
183 void plotArray(QPainter* painter, const double* x, const double* y,
184 int n) const;
187 FillStyle m_fillStyle;
188 Symbol m_symbol;
189 unsigned m_color;
190 double m_normX, m_normY, m_xOffset, m_yOffset, dydx, myDashOffset;
191 mutable QPen m_pen;
192 mutable QPainterPath bPath;
193 mutable QRectF bRect;
194 QRectF symbRect;
195 QTransform m_matrix;
196};
197
198#endif
Kpl item class.
Definition kplitem.h:42
FillStyle
Fill styles.
Definition kplitem.h:45
Symbol
Symbol types.
Definition kplitem.h:83
Scaled item class.
Definition scaleditem.h:25
void setColor(unsigned color)
Sets color.
Definition scaleditem.h:111
ScaledItem(FillStyle fillStyle, Symbol symbol, unsigned color, double fx, double fy, double xOffset, double yOffset, double relSize, QGraphicsItem *parent)
Constructor.
void setFillStyle(FillStyle style)
Sets fill style.
Definition scaleditem.h:116
void update()
Applies changes and forces redrawing.
static bool limits(double &xMin, double &xMax, const double *values, int n)
Calculates minimum and maximum values of an array.
void normalize(double fx, double fy)
Sets normalization factors.
Definition scaleditem.h:93
void setNormY(double fy)
Sets normalization factor for y values.
Definition scaleditem.h:126
QPixmap pixmap() const
Returns decoration pixmap for item list.
static void exponent(double a, int &iExp, double &f)
Calculates normalization factor.
void setProperties(const QTransform &m)
Sets properties according to transformation matrix.
void setNormX(double fx)
Sets normalization factor for x values.
Definition scaleditem.h:121
Symbol symbol() const
Returns symbol type.
Definition scaleditem.h:150
void setSize()
Sets size according to transformation matrix.
ScaledItem(const ScaledItem &a)
Copy constructor.
virtual ~ScaledItem()
Destructor.
void plotArray(QPainter *painter, const double *x, const double *y, int n) const
Plots array.
bool isNormalized(double fx, double fy) const
Checks if both normalization factors are equal to given values.
Definition scaleditem.h:77
void readPlo(const KConfigGroup *plo, Symbol symbol, unsigned color)
Initializes corresponding to plot file.
double xOffset() const
Returns offset for x values.
Definition scaleditem.h:162
FillStyle fillStyle() const
Returns fill style.
Definition scaleditem.h:70
void updateGeometry()
Updates geometry.
double yOffset() const
Returns offset for y values.
Definition scaleditem.h:164
double normX() const
Returns normalization factor for x values.
Definition scaleditem.h:95
ScaledItem()
Constructor.
void setYOffset(double yOffset)
Sets offset for y values.
Definition scaleditem.h:148
void setXOffset(double xOffset)
Sets offset for x values.
Definition scaleditem.h:143
void setSymbol(Symbol symbol)
Sets symbol type.
Definition scaleditem.h:138
double normY() const
Returns normalization factor for y values.
Definition scaleditem.h:97
unsigned color() const
Returns color.
Definition scaleditem.h:61
void setProperties()
Sets properties according to transformation matrix.
double length(const double *x, const double *y, int n) const
Calculates line length.
ScaledItem(const KConfigGroup *plo, Symbol symbol, unsigned color, QGraphicsItem *parent)
Constructor.
void writePlo(KConfigGroup *plo, bool visible) const
Writes into plot file.