libkpl  6.0
A Library for Graphical Presentation of Data Sets and Functions
ArrayItem Class Reference

Array item class. More...

#include <arrayitem.h>

Inheritance diagram for ArrayItem:

Public Types

enum  DecimalCharacter { Point , Comma , Settings }
 Decimal character. More...
 
enum  { Type = UserType + Array }
 Specific QGraphicsItem type number for function type() More...
 
- Public Types inherited from KplItem
enum  FillStyle {
  NoBrush , SolidPattern , HorPattern , VerPattern ,
  CrossPattern , BDiagPattern , FDiagPattern , DiagCrossPattern
}
 Fill styles. More...
 
enum  ItemType {
  Frame = 1 , Array , Function , ParFunction ,
  Spline , Array3D , Function3D , Legend ,
  Text , Line , Arrow , Arc ,
  Rectangle , Ellipse , Image , ScaleBar
}
 Item types. More...
 
enum  PenType { FramePen , GridPen , DataPen }
 Pen types. More...
 
enum  Symbol {
  Invisible = -17 , FilledOctagon , FilledHourglass , FilledTriangle ,
  FilledSquare , FilledDiamond , FilledCircle , Umbrella ,
  Ypsilon , Plus , Cross , OpenOctagon ,
  OpenHourglass , OpenTriangle , OpenSquare , OpenDiamond ,
  Dot , OpenCircle , SolidLine , DashLine1 ,
  DashLine2 , DotLine1 , DashLine3 , DashDotLine ,
  DashLine4 , DashLine5 , DotLine2
}
 Symbol types. More...
 

Public Member Functions

 ArrayItem ()
 Constructor.
 
 ArrayItem (unsigned color, int colX=0, int colY=0, int colErr=0, bool errorBars=false, Symbol symbol=OpenCircle, DecimalCharacter decimalChar=Point, const QUrl &url=QUrl(), double fx=1, double fy=1, QGraphicsItem *parent=nullptr, int n=0, int rowStart=0, FillStyle fillStyle=NoBrush, double xOffset=0, double yOffset=0, bool visible=true, bool internal=false, double relSize=1)
 Constructor.
 
 ArrayItem (const ArrayItem &a)
 Copy constructor.
 
 ArrayItem (const KConfigGroup *plo, const QUrl &urlPlo, unsigned color=0, int colX=0, int colY=0, int colErr=0, bool errorBars=false, Symbol symbol=OpenCircle, QGraphicsItem *parent=nullptr)
 Constructor.
 
virtual ~ArrayItem ()
 Destructor.
 
void adjustCols (int colX, int colY, int colErr)
 Sets and limits the column indices.
 
void adjustCols ()
 Limits the column indices.
 
virtual QRectF boundingRect () const override
 Calculates bounding rectangle.
 
int colErr () const
 Returns y error column index.
 
int colX () const
 Returns x column index.
 
int colY () const
 Returns y column index.
 
int count () const
 Returns number of data points to be plotted.
 
double ** data () const
 Returns pointer to internal array.
 
DecimalCharacter decimalCharacter () const
 Returns decimal symbol of floating point numbers.
 
bool errorBars () const
 Returns true for plotting error bars.
 
void exponent (int &expX, int &expY, double &fx, double &fy) const
 Calculates normalization factors.
 
bool internal () const
 Returns true for internal stored array data.
 
void limits (double &xMin, double &xMax, double &yMin, double &yMax) const
 Calculates minimum and maximum values.
 
int numCols () const
 Returns number of columns.
 
int numRows () const
 Returns number of rows.
 
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr) override
 Paints item.
 
virtual int readFile ()
 Reads double values from the URL.
 
int readFile (QString *text)
 Reads double values from a string.
 
int rowStart () const
 Returns start row index.
 
void setColErr (int colErr)
 Sets error column index.
 
void setColX (int colX)
 Sets x column index.
 
void setColY (int colY)
 Sets y column index.
 
void setCount (int n)
 Sets number of data points.
 
void setDashOffset ()
 Sets offset for dashed lines.
 
void setData (double **data)
 Sets array pointer.
 
void setDecimalCharacter (DecimalCharacter decimalChar)
 Sets decimal character.
 
void setErrorBars (bool errorBars)
 Sets error bars plotting.
 
void setInternal (bool internal)
 Sets storage mode.
 
void setNumCols (int nCols)
 Sets number of columns.
 
void setNumRows (int nRows)
 Sets number of rows.
 
void setRange (int rowStart, int n)
 Sets and limits the start row index and the number of points to be plotted.
 
void setRowStart (int rowStart)
 Sets start row index.
 
void setUrl (const QUrl &url)
 Sets URL.
 
virtual QPainterPath shape () const override
 Returns the shape of the plot item.
 
virtual int type () const override
 Returns specific QGraphicsItem type number.
 
const QUrl & url () const
 Returns URL of data file.
 
void writePlo (KConfigGroup *plo, const QUrl &urlPlo, bool absolute) const
 Writes into plot file.
 
- Public Member Functions inherited from ScaledItem
 ScaledItem ()
 Constructor.
 
 ScaledItem (const ScaledItem &a)
 Copy constructor.
 
 ScaledItem (const KConfigGroup *plo, Symbol symbol, unsigned color, QGraphicsItem *parent)
 Constructor.
 
 ScaledItem (FillStyle fillStyle, Symbol symbol, unsigned color, double fx, double fy, double xOffset, double yOffset, double relSize, QGraphicsItem *parent)
 Constructor.
 
virtual ~ScaledItem ()
 Destructor.
 
unsigned color () const
 Returns color.
 
FillStyle fillStyle () const
 Returns fill style.
 
bool isNormalized (double fx, double fy) const
 Checks if both normalization factors are equal to given values.
 
void normalize (double fx, double fy)
 Sets normalization factors.
 
double normX () const
 Returns normalization factor for x values.
 
double normY () const
 Returns normalization factor for y values.
 
QPixmap pixmap () const
 Returns decoration pixmap for item list.
 
void readPlo (const KConfigGroup *plo, Symbol symbol, unsigned color)
 Initializes corresponding to plot file.
 
void setColor (unsigned color)
 Sets color.
 
void setFillStyle (FillStyle style)
 Sets fill style.
 
void setNormX (double fx)
 Sets normalization factor for x values.
 
void setNormY (double fy)
 Sets normalization factor for y values.
 
void setProperties (const QTransform &m)
 Sets properties according to transformation matrix.
 
void setSize ()
 Sets size according to transformation matrix.
 
void setSymbol (Symbol symbol)
 Sets symbol type.
 
void setXOffset (double xOffset)
 Sets offset for x values.
 
void setYOffset (double yOffset)
 Sets offset for y values.
 
Symbol symbol () const
 Returns symbol type.
 
void update ()
 Applies changes and forces redrawing.
 
void updateGeometry ()
 Updates geometry.
 
void writePlo (KConfigGroup *plo, bool visible) const
 Writes into plot file.
 
double xOffset () const
 Returns offset for x values.
 
double yOffset () const
 Returns offset for y values.
 
- Public Member Functions inherited from KplItem
 KplItem (double relSize=1)
 Constructor.
 
 KplItem (const KplItem &a)
 Copy constructor.
 
 KplItem (const KConfigGroup *plo)
 Constructor.
 
virtual ~KplItem ()
 Destructor.
 
void readPlo (const KConfigGroup *plo)
 Initializes corresponding to plot file.
 
double relSize () const
 Returns relative size of item.
 
void setRelSize (double relSize)
 Sets relative size of item.
 
void writePlo (KConfigGroup *plo, bool visible=true) const
 Writes into plot file.
 

Static Public Member Functions

static double ** copyArray (double **data, int nCols, int nRows)
 Copies array storage.
 
static void freeArray (double ***data)
 Deallocates array storage.
 
static int readFile (const QUrl &url, int &nCols, double ***data, DecimalCharacter decimalChar=Point)
 Reads double values from a file into an array.
 
static int readFile (QIODevice *device, int &nCols, double ***data, DecimalCharacter decimalChar=Point)
 Reads double values from an I/O device into an array.
 
static int readFile (QString *text, int &nCols, double ***data, DecimalCharacter decimalChar=Point)
 Reads double values from a string into an array.
 
static int readLines (QTextStream &t, int nCols, double ***data, DecimalCharacter decimalChar=Point)
 Reads double values from a text stream into an array.
 
static void translate (QString &line, DecimalCharacter decimalChar)
 Translates exponent and decimal symbols.
 
- Static Public Member Functions inherited from ScaledItem
static void exponent (double a, int &iExp, double &f)
 Calculates normalization factor.
 
static bool limits (double &xMin, double &xMax, const double *values, int n)
 Calculates minimum and maximum values of an array.
 
- Static Public Member Functions inherited from KplItem
static QUrl absoluteUrl (const QString &path, const QUrl &urlPlo)
 Constructs absolute file URL.
 
static QBrush createBrush (unsigned color, FillStyle fillStyle=NoBrush)
 Creates brush.
 
static QPen createPen (double width, unsigned color, PenType penType, Symbol symbol)
 Creates pen.
 
static void paintSymbol (QPainter *painter, const QRectF &rect, Symbol symbol=OpenCircle)
 Paints symbol.
 
static QPixmap pixmap (Symbol symbol)
 Returns black decoration pixmap of plot symbol for use in dialog GUI.
 
static QPixmap pixmap (QPen pen, Symbol symbol=SolidLine)
 Returns decoration pixmap of plot symbol for use in item lists.
 
static QString path (const QUrl &urlPlo, const QUrl &url, bool absolute=false)
 Constructs absolute or (if possible) relative file path.
 
static void resetDashOffset ()
 Resets offset for dashed lines.
 
static unsigned rgb (const QString &color)
 Converts rgb string to QRgb.
 
static unsigned rgbQt1 (unsigned rgb)
 Converts QRgb to Qt1 QRgb.
 

Protected Member Functions

void paintCond (QPainter *painter) const
 Paints or calculates bounding area.
 
- Protected Member Functions inherited from ScaledItem
double length (const double *x, const double *y, int n) const
 Calculates line length.
 
void plotArray (QPainter *painter, const double *x, const double *y, int n) const
 Plots array.
 
void setProperties ()
 Sets properties according to transformation matrix.
 
- Protected Member Functions inherited from KplItem
QPen & changePenWidth (QPen &pen, double width) const
 Changes pen width.
 
QPen createPen (QGraphicsItem *item, unsigned color=0, PenType penType=DataPen, Symbol symbol=SolidLine) const
 Creates pen for plot item.
 
double penWidth (const QGraphicsItem *item, PenType penType=DataPen) const
 Calculates pen width for plot item.
 

Protected Attributes

bool m_internal
 
bool m_errorBars
 
int m_colX
 
int m_colY
 
int m_colErr
 
int m_rowStart
 
int m_count
 
int m_numRows
 
int m_numCols
 
DecimalCharacter m_decimalCharacter
 
double ** m_data
 
QUrl m_url
 
- Protected Attributes inherited from ScaledItem
FillStyle m_fillStyle
 
Symbol m_symbol
 
unsigned m_color
 
double m_normX
 
double m_normY
 
double m_xOffset
 
double m_yOffset
 
double dydx
 
double myDashOffset
 
QPen m_pen
 
QPainterPath bPath
 
QRectF bRect
 
QRectF symbRect
 
QTransform m_matrix
 
- Protected Attributes inherited from KplItem
double m_relSize
 

Additional Inherited Members

- Static Protected Member Functions inherited from KplItem
static double parentWidth (const QGraphicsItem *item)
 Returns width of item's parent frame or width of scene if the item has no parent item.
 
static double penWidthFactor (PenType penType)
 Returns factor to calculate pen width from frame width.
 
- Static Protected Attributes inherited from KplItem
static double m_dashOffset
 

Detailed Description

Array item class.

Class for array items showing data arrays by lines or markers.

Author
Werner Stille

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Specific QGraphicsItem type number for function type()

Enumerator
Type 

Specific QGraphicsItem type number of ArrayItem for function type().

◆ DecimalCharacter

Decimal character.

Determines decimal character for reading of floating point numbers.

Enumerator
Point 

Decimal point.

Comma 

Decimal comma.

Settings 

Use Kpl Settings (only for internal use in Kpl application).

Constructor & Destructor Documentation

◆ ArrayItem() [1/3]

ArrayItem::ArrayItem ( unsigned color,
int colX = 0,
int colY = 0,
int colErr = 0,
bool errorBars = false,
Symbol symbol = OpenCircle,
DecimalCharacter decimalChar = Point,
const QUrl & url = QUrl(),
double fx = 1,
double fy = 1,
QGraphicsItem * parent = nullptr,
int n = 0,
int rowStart = 0,
FillStyle fillStyle = NoBrush,
double xOffset = 0,
double yOffset = 0,
bool visible = true,
bool internal = false,
double relSize = 1 )

Constructor.

Initializes corresponding to arguments.

Parameters
colorcolor for data plot.
colXx column index.
colYy column index.
colErry error column index.
errorBarstrue to plot error bars.
symbolsymbol type.
decimalChardecimal symbol of floating point numbers used in file.
urlURL of data file.
fxnormalization factor for x values.
fynormalization factor for y values.
parentpointer to parent item.
nnumber of data points to be plotted.
rowStartstart row index.
fillStylefill style.
xOffsetoffset for x values.
yOffsetoffset for x values.
visibletrue for visible item.
internaltrue for internal stored array data.
relSizerelative size of lines or symbols.

◆ ArrayItem() [2/3]

ArrayItem::ArrayItem ( const ArrayItem & a)

Copy constructor.

Parameters
asource item.

◆ ArrayItem() [3/3]

ArrayItem::ArrayItem ( const KConfigGroup * plo,
const QUrl & urlPlo,
unsigned color = 0,
int colX = 0,
int colY = 0,
int colErr = 0,
bool errorBars = false,
Symbol symbol = OpenCircle,
QGraphicsItem * parent = nullptr )

Constructor.

Initializes corresponding to plot file.

Parameters
plopointer to KSimpleConfig object containing item data.
urlPloURL of plot file.
colordefault color for data plot.
colXdefault x column index.
colYdefault y column index.
colErrdefault y error column index.
errorBarsdefault, true to plot error bars.
symboldefault symbol type.
parentpointer to parent item.

Member Function Documentation

◆ adjustCols()

void ArrayItem::adjustCols ( int colX,
int colY,
int colErr )

Sets and limits the column indices.

Parameters
colXx column.
colYy column.
colErrerror column.

◆ copyArray()

static double ** ArrayItem::copyArray ( double ** data,
int nCols,
int nRows )
static

Copies array storage.

Parameters
datatwo-dimensional source array.
nColsnumber of columns.
nRowsnumber of rows.
Returns
pointer to copy of array.

◆ data()

double ** ArrayItem::data ( ) const
inline

Returns pointer to internal array.

Returns
pointer to two-dimensional array.

◆ exponent()

void ArrayItem::exponent ( int & expX,
int & expY,
double & fx,
double & fy ) const

Calculates normalization factors.

Parameters
expXreference to logarithm of x normalization factor.
expYreference to logarithm of x normalization factor.
fxreference to x normalization factor.
fyreference to y normalization factor.

◆ freeArray()

static void ArrayItem::freeArray ( double *** data)
static

Deallocates array storage.

Parameters
datapointer to two-dimensional array.

◆ limits()

void ArrayItem::limits ( double & xMin,
double & xMax,
double & yMin,
double & yMax ) const

Calculates minimum and maximum values.

Parameters
xMinreference to minimum of x values.
xMaxreference to maximum of x values.
yMinreference to minimum of y values.
yMaxreference to maximum of y values.

◆ paintCond()

void ArrayItem::paintCond ( QPainter * painter) const
protected

Paints or calculates bounding area.

Parameters
painterPointer to QPainter object, 0 for calculating bounding area.

◆ readFile() [1/5]

virtual int ArrayItem::readFile ( )
virtual

Reads double values from the URL.

Returns
number of rows, 0 for error.

◆ readFile() [2/5]

static int ArrayItem::readFile ( const QUrl & url,
int & nCols,
double *** data,
DecimalCharacter decimalChar = Point )
static

Reads double values from a file into an array.

Parameters
urlURL of data file.
nColsreference to number of columns.
datapointer to two-dimensional array.
decimalChardecimal symbol of floating point numbers used in file.
Returns
number of rows, 0 for error.

◆ readFile() [3/5]

static int ArrayItem::readFile ( QIODevice * device,
int & nCols,
double *** data,
DecimalCharacter decimalChar = Point )
static

Reads double values from an I/O device into an array.

Parameters
deviceI/O device to read from.
nColsreference to number of columns.
datapointer to two-dimensional array.
decimalChardecimal character: Point or Comma.
Returns
number of rows, 0 for error.

◆ readFile() [4/5]

int ArrayItem::readFile ( QString * text)

Reads double values from a string.

Returns
number of rows, 0 for error.

◆ readFile() [5/5]

static int ArrayItem::readFile ( QString * text,
int & nCols,
double *** data,
DecimalCharacter decimalChar = Point )
static

Reads double values from a string into an array.

Parameters
textstring to read from.
nColsreference to number of columns.
datapointer to two-dimensional array.
decimalChardecimal character: Point or Comma.
Returns
number of rows, 0 for error.

◆ readLines()

static int ArrayItem::readLines ( QTextStream & t,
int nCols,
double *** data,
DecimalCharacter decimalChar = Point )
static

Reads double values from a text stream into an array.

Parameters
ttext stream to read from.
nColsnumber of columns.
datapointer to array.
decimalChardecimal character: Point or Comma.
Returns
number of lines, 0 for error.

◆ setColErr()

void ArrayItem::setColErr ( int colErr)
inline

Sets error column index.

Parameters
colErry error column index.

◆ setColX()

void ArrayItem::setColX ( int colX)
inline

Sets x column index.

Parameters
colXy error column index.

◆ setColY()

void ArrayItem::setColY ( int colY)
inline

Sets y column index.

Parameters
colYy column index.

◆ setCount()

void ArrayItem::setCount ( int n)
inline

Sets number of data points.

Parameters
nnumber of data points.

◆ setData()

void ArrayItem::setData ( double ** data)

Sets array pointer.

Parameters
datatwo-dimensional array.

◆ setDecimalCharacter()

void ArrayItem::setDecimalCharacter ( DecimalCharacter decimalChar)
inline

Sets decimal character.

Parameters
decimalChardecimal symbol of floating point numbers used in file.

◆ setErrorBars()

void ArrayItem::setErrorBars ( bool errorBars)
inline

Sets error bars plotting.

Parameters
errorBarstrue to plot error bars.

◆ setInternal()

void ArrayItem::setInternal ( bool internal)
inline

Sets storage mode.

Parameters
internaltrue for internal stored array data.

◆ setNumCols()

void ArrayItem::setNumCols ( int nCols)
inline

Sets number of columns.

Parameters
nColsnumber of columns.

◆ setNumRows()

void ArrayItem::setNumRows ( int nRows)
inline

Sets number of rows.

Parameters
nRowsnumber of Rows.

◆ setRange()

void ArrayItem::setRange ( int rowStart,
int n )

Sets and limits the start row index and the number of points to be plotted.

Parameters
rowStartstart row index.
nnumber of data points.

◆ setRowStart()

void ArrayItem::setRowStart ( int rowStart)
inline

Sets start row index.

Parameters
rowStartstart row index.

◆ setUrl()

void ArrayItem::setUrl ( const QUrl & url)
inline

Sets URL.

Parameters
urlURL of data file.

◆ translate()

static void ArrayItem::translate ( QString & line,
DecimalCharacter decimalChar )
static

Translates exponent and decimal symbols.

Parameters
lineline from data or parameter file.
decimalChardecimal symbol of floating point numbers used in file.

◆ writePlo()

void ArrayItem::writePlo ( KConfigGroup * plo,
const QUrl & urlPlo,
bool absolute ) const

Writes into plot file.

Parameters
ploKConfigGroup object.
urlPloURL of plot file.
absolutetrue to save absolute paths.

The documentation for this class was generated from the following file: