# class KPlotWidget

###

Module | kdeui
Namespace |
Class | KPlotWidget
Inherits | QFrame

KPlotWidget

Generic data plotting widget.

Widget for drawing plots. The basic idea behind KPlotWidget is that you don't have to worry about any transformation from your data's natural units to screen pixel coordinates; this is handled internally by the widget.

Data to be plotted are represented by one or more instances of KPlotObject. KPlotObject contains a list of QPointFs to be plotted (again, in the data's natural units), as well as information about how the data are to be rendered in the plot (i.e., as separate points or connected by lines? With what color and point style? etc). See KPlotObject for more information.

KPlotWidget automatically adds axis labels with tickmarks and tick labels. These are encapsulated in the KPlotAxis class. All you have to do is set the limits of the plotting area in data units, and KPlotWidget wil figure out the optimal positions and labels for the tickmarks on the axes.

Example of usage:

    KPlotWidget *kpw = new KPlotWidget( parent );
    // setting our limits for the plot
    kpw->setLimits( 1.0, 5.0, 1.0, 25.0 );

    // creating a plot object whose points are connected by red lines ...
    KPlotObject *kpo = new KPlotObject( Qt.red, KPlotObject.Lines );
    // ... adding some points to it ...
    for ( float x = 1.0; x <= 5.0; x += 0.1 )
    kpo->addPoint( x, x*x );

    // ... and adding the object to the plot widget
    kpw->addPlotObject( kpo );

KPlotWidget will take care of the objects added to it, so when clearing the objects list (eg with removeAllPlotObjects()) any previous reference to a KPlotObject already added to a KPlotWidget will be invalid.

Author Jason Harris Version: 1.1

### enums

- Axis { LeftAxis, BottomAxis, RightAxis, TopAxis }

enum details

### methods

- KPlotWidget (parent)

  returns ctor
  KDE 4.1.0 and later only

  Argument | Type | Default
  --- | --- | ---
  parent | QWidget | 0

  Constructor.

  parent - the parent widget

- KPlotWidget (a0)

  returns ctor
  Not implemented

  Argument | Type | Default
  --- | --- | ---
  a0 | KPlotWidget |

- KPlotWidget (a0)

  returns ctor
  before KDE 4.1.0 only

  Argument | Type | Default
  --- | --- | ---
  a0 | QWidget | 0

- addPlotObject (object)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  object | KPlotObject |

  Add an item to the list of KPlotObjects to be plotted. do not use this multiple time if many objects have to be added, addPlotObjects() is strongly suggested in this case

  object - the KPlotObject to be added

- addPlotObjects (objects)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  objects | QList<KPlotObject |

  Add more than one KPlotObject at one time.

  objects - the list of KPlotObjects to be added

- antialiasing ( )

  returns bool

  Returns whether the antialiasing is active Antialiasing is not active by default.

- axis (type)

  returns KPlotAxis

  Argument | Type | Default
  --- | --- | ---
  type | KPlotWidget.Axis |

  Returns the axis of the specified type, or 0 if no axis has been set.

  See also Axis

- axis (type)

  returns KPlotAxis
  Not implemented

  Argument | Type | Default
  --- | --- | ---
  type | KPlotWidget.Axis |

  Returns the axis of the specified type, or 0 if no axis has been set.

  See also Axis

- backgroundColor ( )

  returns QColor

  Returns the background color of the plot.

  The default color is black.

- bottomPadding ( )

  returns int

  Returns the number of pixels below the plot area. Padding values are set to -1 by default; if unchanged, this function will try to guess a good value, based on whether ticklabels and/or axis labels are to be drawn.

- clearSecondaryLimits ( )

  returns Nothing

  Unset the secondary limits, so the top and right axes show the same tickmarks as the bottom and left axes (no tickmark labels will be drawn for the top and right axes in this case)

- dataRect ( )

  returns QRectF

  Returns the rectangle representing the boundaries of the current plot, in natural data units.

  See also setLimits()

- drawAxes (p)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  p | QPainter |

  Draws the plot axes and axis labels. Internal Internal use only; one should simply call update() to draw the widget with axes and all objects.

  p - pointer to the painter on which we are drawing

- event (a0)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  a0 | QEvent |

  Generic event handler.

- foregroundColor ( )

  returns QColor

  Returns the foreground color, used for axes, tickmarks and associated labels.

  The default color is white.

- gridColor ( )

  returns QColor

  Returns the grid color.

  The default color is gray.

- isGridShown ( )

  returns bool

  Returns whether the grid lines are shown Grid lines are not shown by default.

- isObjectToolTipShown ( )

  returns bool

  Returns whether the tooltip for the point objects is shown. Tooltips are enabled by default.

- leftPadding ( )

  returns int

  Returns the number of pixels to the left of the plot area.

  Padding values are set to -1 by default; if unchanged, this function will try to guess a good value, based on whether ticklabels and/or axis labels need to be drawn.

- mapToWidget (p)

  returns QPointF

  Argument | Type | Default
  --- | --- | ---
  p | QPointF |

  Map a coordinate p - from the data rect to the physical pixel rect. Used mainly when drawing.

  p - the point to be converted, in natural data units Returns the coordinate in the pixel coordinate system

- maskAlongLine (p1, p2, value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  p1 | QPointF |
  p2 | QPointF |
  value | float | 1.0

  Indicate that object labels should try to avoid the line joining the two given points (in pixel coordinates).

  You should not normally call this function directly. It is called by KPlotObject when lines are drawn in the plot.

  p1 - the starting point for the line

  p2 - the ending point for the line

  value - Allows you to determine how strongly the line should be avoided. Larger values are avoided more strongly.

- maskRect (r, value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  r | QRectF |
  value | float | 1.0

  Indicate that object labels should try to avoid the given rectangle in the plot. The rectangle is in pixel coordinates.

  You should not normally call this function directly. It is called by KPlotObject when points, bars and labels are drawn.

  r - the rectangle defining the region in the plot that text labels should avoid (in pixel coordinates)

  value - Allows you to determine how strongly the rectangle should be avoided. Larger values are avoided more strongly.

- minimumSizeHint ( )

  returns QSize

  Returns suggested minimum size for the plot widget

- paintEvent (a0)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  a0 | QPaintEvent |

  The paint event handler, executed when update() or repaint() is called.

- pixRect ( )

  returns QRect

  Returns the rectangle representing the boundaries of the current plot, in screen pixel units.

- placeLabel (painter, pp)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  painter | QPainter |
  pp | KPlotPoint |

  Place an object label optimally in the plot. This function will attempt to place the label as close as it can to the point to which the label belongs, while avoiding overlap with regions of the plot that have been masked.

  You should not normally call this function directly. It is called internally in KPlotObject.draw().

  painter - Pointer to the painter on which to draw the label

  pp - pointer to the KPlotPoint whose label is to be drawn.

- plotObjects ( )

  returns QList<KPlotObject

  Returns the current list of plot objects

- pointsUnderPoint (p)

  returns QList<KPlotPoint

  Argument | Type | Default
  --- | --- | ---
  p | QPoint |

  Returns a list of points in the plot which are within 4 pixels of the screen position given as an argument.

  p - The screen position from which to check for plot points.

- removeAllPlotObjects ( )

  returns Nothing

  Remove and delete all items from the list of KPlotObjects

- replacePlotObject (i, o)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  i | int |
  o | KPlotObject |

  Replace an item in the KPlotObject list.

  i - the index of the item to be replaced

  o - pointer to the replacement KPlotObject

- resetPlot ( )

  returns Nothing

  Clear the object list, reset the data limits, and remove axis labels

- resetPlotMask ( )

  returns Nothing

  Reset the mask used for non-overlapping labels so that all regions of the plot area are considered empty.

- resizeEvent (a0)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  a0 | QResizeEvent |

  The resize event handler, called when the widget is resized.

- rightPadding ( )

  returns int

  Returns the number of pixels to the right of the plot area. Padding values are set to -1 by default; if unchanged, this function will try to guess a good value, based on whether ticklabels and/or axis labels are to be drawn.

- secondaryDataRect ( )

  returns QRectF

  Returns the rectangle representing the boundaries of the secondary data limits, if they have been set. Otherwise, this function behaves the same as dataRect().

  See also setSecondaryLimits()

- setAntialiasing (b)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  b | bool |

  Toggle antialiased drawing.

  b - if true, the plot graphics will be antialiased.

- setBackgroundColor (bg)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  bg | QColor |

  Set the background color

  bg - the new background color

- setBottomPadding (padding)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  padding | int |

  Set the number of pixels below the plot area. Set this to -1 to revert to automatic determination of padding values.

- setDefaultPaddings ( )

  returns Nothing

  Revert all four padding values to -1, so that they will be automatically determined.

- setForegroundColor (fg)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  fg | QColor |

  Set the foreground color

  fg - the new foreground color

- setGridColor (gc)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  gc | QColor |

  Set the grid color

  gc - the new grid color

- setLeftPadding (padding)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  padding | int |

  Set the number of pixels to the left of the plot area. Set this to -1 to revert to automatic determination of padding values.

- setLimits (x1, x2, y1, y2)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  x1 | double |
  x2 | double |
  y1 | double |
  y2 | double |

  Set new data limits for the plot.

  x1 - the minimum X value in data units

  x2 - the maximum X value in data units

  y1 - the minimum Y value in data units

  y2 - the maximum Y value in data units

- setObjectToolTipShown (show)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  show | bool |

  Toggle the display of a tooltip for point objects.

  show - whether show the tooltip.

  See also isObjectToolTipShown()

- setPixRect ( )

  returns Nothing

  Synchronize the PixRect with the current widget size and padding settings.

- setRightPadding (padding)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  padding | int |

  Set the number of pixels to the right of the plot area. Set this to -1 to revert to automatic determination of padding values.

- setSecondaryLimits (x1, x2, y1, y2)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  x1 | double |
  x2 | double |
  y1 | double |
  y2 | double |

  Reset the secondary data limits, which control the values displayed along the top and right axes.

  All data points are *plotted* using the coordinates defined by setLimits(), so this function is only useful for showing alternate tickmark labels along the top and right edges. For example, if you were plotting temperature on the X-axis, you could use Centigrade units for the primary (bottom) axis, using setLimits( 0.0, 100.0, 0.0, 1.0 ). If you also wanted to show Farenheit units along the secondary (top) axis, you would additionally use setSecondaryLimits( 32.0, 212.0, 0.0, 1.0 ). The data added to the plot would have x-coordinates in Centigrade degrees.

  x1 - the minimum X value in secondary data units

  x2 - the maximum X value in secondary data units

  y1 - the minimum Y value in secondary data units

  y2 - the maximum Y value in secondary data units

  See also setLimits()

- setShowGrid (show)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  show | bool |

  Toggle whether grid lines are drawn at major tickmarks.

  show - if true, grid lines will be drawn.

  See also isGridShown()

- setTopPadding (padding)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  padding | int |

  Set the number of pixels above the plot area. Set this to -1 to revert to automatic determination of padding values.

- sizeHint ( )

  returns QSize

  Returns suggested size for the plot widget

- topPadding ( )

  returns int

  Returns the number of pixels above the plot area. Padding values are set to -1 by default; if unchanged, this function will try to guess a good value, based on whether ticklabels and/or axis labels are to be drawn.

### enums - detail

- Axis { LeftAxis, BottomAxis, RightAxis, TopAxis }

  The four types of plot axes.

  | LeftAxis | - 0 | - |
  | BottomAxis | - | - |
  | RightAxis | - | - |
  | TopAxis | - | - |