KPlotting 5.109.0
Public Types | Public Member Functions | List of all members
KPlotObject

Encapsulates a data set to be plotted in a KPlotWidget. More...

#include <kplotobject.h>

Public Types

enum  PlotType { UnknownType = 0 , Points = 1 , Lines = 2 , Bars = 4 }
 The type classification of the KPlotObject. More...
 
typedef QFlags< PlotTypePlotTypes
 
enum  PointStyle {
  NoPoints = 0 , Circle = 1 , Letter = 2 , Triangle = 3 ,
  Square = 4 , Pentagon = 5 , Hexagon = 6 , Asterisk = 7 ,
  Star = 8 , UnknownPoint
}
 The available shape styles for plotted points. More...
 

Public Member Functions

 KPlotObject (const QColor &color=Qt::white, PlotType otype=Points, double size=2.0, PointStyle ps=Circle)
 Constructor.
 
 ~KPlotObject ()
 Destructor.
 
void addPoint (const QPointF &p, const QString &label=QString(), double barWidth=0.0)
 Add a point to the object's list of points, using input data to construct a KPlotPoint.
 
void addPoint (double x, double y, const QString &label=QString(), double barWidth=0.0)
 Add a point to the object's list of points, using input data to construct a KPlotPoint.
 
void addPoint (KPlotPoint *p)
 Add a given KPlotPoint to the object's list of points.
 
const QBrush barBrush () const
 
const QPen & barPen () const
 
const QBrush brush () const
 
void clearPoints ()
 Remove and destroy the points of this object.
 
void draw (QPainter *p, KPlotWidget *pw)
 Draw this KPlotObject on the given QPainter.
 
const QPen & labelPen () const
 
const QPen & linePen () const
 
const QPen & pen () const
 
PlotTypes plotTypes () const
 
QList< KPlotPoint * > points () const
 
PointStyle pointStyle () const
 
void removePoint (int index)
 Remove the QPointF at position index from the list of points.
 
void setBarBrush (const QBrush &b)
 Set the brush to use for drawing bars for this object The brush to use.
 
void setBarPen (const QPen &p)
 Set the pen to use for drawing bars for this object The pen to use.
 
void setBrush (const QBrush &b)
 Set the default brush to use for this object The brush to use.
 
void setLabelPen (const QPen &p)
 Set the pen to use for labels for this object The pen to use.
 
void setLinePen (const QPen &p)
 Set the pen to use for drawing lines for this object The pen to use.
 
void setPen (const QPen &p)
 Set the default pen for this object The pen to use.
 
void setPointStyle (PointStyle p)
 Set a new style for drawing the points in this object.
 
void setShowBars (bool b)
 Set whether bars will be drawn for this object.
 
void setShowLines (bool b)
 Set whether lines will be drawn for this object.
 
void setShowPoints (bool b)
 Set whether points will be drawn for this object.
 
void setSize (double s)
 Set the size for plotted points in this object, in pixels.
 
double size () const
 

Detailed Description

Encapsulates a data set to be plotted in a KPlotWidget.

Think of a KPlotObject as a set of data displayed as a group in the plot. Each KPlotObject consists of a list of KPlotPoints, a "type" controlling how the data points are displayed (some combination of Points, Lines, or Bars), a color, and a size. There is also a parameter which controls the shape of the points used to display the KPlotObject.

Note
KPlotObject will take care of the points added to it, so when clearing the points list (eg with clearPoints()) any previous reference to a KPlotPoint already added to a KPlotObject will be invalid.
Author
Jason Harris
Version
1.1

Member Enumeration Documentation

◆ PlotType

The type classification of the KPlotObject.

These are bitmask values that can be OR'd together, so that a set of points can be represented in the plot in multiple ways.

Note
points should be added in order of increasing x-coordinate when using Bars.
Enumerator
Points 

each KPlotPoint is represented with a drawn point

Lines 

each KPlotPoint is connected with a line

Bars 

each KPlotPoint is shown as a vertical bar

◆ PointStyle

The available shape styles for plotted points.

Constructor & Destructor Documentation

◆ KPlotObject()

KPlotObject::KPlotObject ( const QColor &  color = Qt::white,
PlotType  otype = Points,
double  size = 2.0,
PointStyle  ps = Circle 
)
explicit

Constructor.

Parameters
colorThe color for plotting this object. By default this sets the color for Points, Lines and Bars, but there are functions to override any of these.
otypethe PlotType for this object (Points, Lines or Bars)
sizethe size to use for plotted points, in pixels
psThe PointStyle describing the shape for plotted points

◆ ~KPlotObject()

KPlotObject::~KPlotObject ( )

Destructor.

Member Function Documentation

◆ addPoint() [1/3]

void KPlotObject::addPoint ( const QPointF &  p,
const QString &  label = QString(),
double  barWidth = 0.0 
)

Add a point to the object's list of points, using input data to construct a KPlotPoint.

Parameters
pthe QPointF to add.
labelthe optional text label for this point
barWidththe width of the bar, if this object is to be drawn with bars
Note
if
Parameters
barWidthis left at its default value of 0.0, then the width will be automatically set to the distance between this point and the one to its right.

◆ addPoint() [2/3]

void KPlotObject::addPoint ( double  x,
double  y,
const QString &  label = QString(),
double  barWidth = 0.0 
)

Add a point to the object's list of points, using input data to construct a KPlotPoint.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
xthe X-coordinate of the point to add.
ythe Y-coordinate of the point to add.
labelthe optional text label
barWidththe width of the bar, if this object is to be drawn with bars
Note
if
Parameters
barWidthis left at its default value of 0.0, then the width will be automatically set to the distance between this point and the one to its right.

◆ addPoint() [3/3]

void KPlotObject::addPoint ( KPlotPoint p)

Add a given KPlotPoint to the object's list of points.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
ppointer to the KPlotPoint to add.

◆ barBrush()

const QBrush KPlotObject::barBrush ( ) const
Returns
the brush to use for filling bars for this Object.

◆ barPen()

const QPen & KPlotObject::barPen ( ) const
Returns
the pen to use for drawing bars for this Object.

◆ brush()

const QBrush KPlotObject::brush ( ) const
Returns
the default Brush to use for this Object.

◆ clearPoints()

void KPlotObject::clearPoints ( )

Remove and destroy the points of this object.

◆ draw()

void KPlotObject::draw ( QPainter *  p,
KPlotWidget pw 
)

Draw this KPlotObject on the given QPainter.

Parameters
pThe QPainter to draw on
pwthe KPlotWidget to draw on (this is needed for the KPlotWidget::mapToWidget() function)

◆ labelPen()

const QPen & KPlotObject::labelPen ( ) const
Returns
the pen to use for drawing labels for this Object.

◆ linePen()

const QPen & KPlotObject::linePen ( ) const
Returns
the pen to use for drawing lines for this Object.

◆ pen()

const QPen & KPlotObject::pen ( ) const
Returns
the default pen for this Object. If no other pens are set, this pen will be used for points, lines, bars and labels (this pen is always used for points).

◆ plotTypes()

PlotTypes KPlotObject::plotTypes ( ) const
Returns
the plot flags of the object

◆ points()

QList< KPlotPoint * > KPlotObject::points ( ) const
Returns
the list of KPlotPoints that make up this object

◆ pointStyle()

PointStyle KPlotObject::pointStyle ( ) const
Returns
the style used for drawing the points in this object

◆ removePoint()

void KPlotObject::removePoint ( int  index)

Remove the QPointF at position index from the list of points.

Parameters
indexthe index of the point to be removed.

◆ setBarBrush()

void KPlotObject::setBarBrush ( const QBrush &  b)

Set the brush to use for drawing bars for this object The brush to use.

◆ setBarPen()

void KPlotObject::setBarPen ( const QPen &  p)

Set the pen to use for drawing bars for this object The pen to use.

◆ setBrush()

void KPlotObject::setBrush ( const QBrush &  b)

Set the default brush to use for this object The brush to use.

◆ setLabelPen()

void KPlotObject::setLabelPen ( const QPen &  p)

Set the pen to use for labels for this object The pen to use.

◆ setLinePen()

void KPlotObject::setLinePen ( const QPen &  p)

Set the pen to use for drawing lines for this object The pen to use.

◆ setPen()

void KPlotObject::setPen ( const QPen &  p)

Set the default pen for this object The pen to use.

◆ setPointStyle()

void KPlotObject::setPointStyle ( PointStyle  p)

Set a new style for drawing the points in this object.

Parameters
pthe new style

◆ setShowBars()

void KPlotObject::setShowBars ( bool  b)

Set whether bars will be drawn for this object.

Parameters
bif true, bars will be drawn

◆ setShowLines()

void KPlotObject::setShowLines ( bool  b)

Set whether lines will be drawn for this object.

Parameters
bif true, lines will be drawn

◆ setShowPoints()

void KPlotObject::setShowPoints ( bool  b)

Set whether points will be drawn for this object.

Parameters
bif true, points will be drawn

◆ setSize()

void KPlotObject::setSize ( double  s)

Set the size for plotted points in this object, in pixels.

Parameters
sthe new size

◆ size()

double KPlotObject::size ( ) const
Returns
the size of the plotted points in this object, in pixels