open_iA 2025.6
Loading...
Searching...
No Matches
iAChartWidget Class Reference

A chart widget which can show an arbitrary number of plots. More...

#include <iAChartWidget.h>

Inheritance diagram for iAChartWidget:
[legend]
Collaboration diagram for iAChartWidget:
[legend]

Public Types

enum  AxisMappingType { Linear , Logarithmic }
 
enum  Mode { NO_MODE , MOVE_VIEW_MODE , X_ZOOM_MODE , Y_ZOOM_MODE }
 
enum  SelectionMode { SelectionDisabled , SelectPlot }
 

Public Slots

void resetView ()
 Reset view (zoom and shift in x and y direction) such that all plots are fully visible.
 
void setDrawXAxisAtZero (bool enable)
 Determines whether the x axis is drawn at location of zero in the data, or at the bottom of the chart region.
 

Signals

void axisChanged ()
 Fires whenever the displayed x/y axis has changed (i.e. if it has been shifted, zoomed, or reset).
 
void clicked (double x, Qt::KeyboardModifiers modifiers)
 Fires whenever the user clicks on the chart.
 
void dblClicked ()
 Fires whenever the user double-clicks on the chart.
 
void legendPlotClicked (size_t plotID)
 Emitted when a plot is clicked in the legend.
 
void plotsSelected (std::vector< size_t > const &plotIDs)
 Fires whenever one or more plots are selected.
 

Public Member Functions

 iAChartWidget (QWidget *parent, QString const &xLabel, QString const &yLabel)
 
 ~iAChartWidget ()
 
void addImageOverlay (std::shared_ptr< QImage > imgOverlay, bool stretch=true)
 Add an image overlay to the chart.
 
void addPlot (std::shared_ptr< iAPlot > plot)
 Add a plot to the chart.
 
virtual int bottomMargin () const
 Retrieve bottom margin (in pixels).
 
bool categoricalAxis () const
 Whether the axis of this chart is categorical type (as determined by the first plot).
 
virtual int chartHeight () const
 Retrieve height (in pixels) of the actual chart, i.e. the region where plots are drawn, without space for the margins / axes.
 
virtual int chartWidth () const
 Retrieve width (in pixels) of the actual chart, i.e. the region where plots are drawn, without space for margins / axes.
 
void clearImageOverlays ()
 Clear all image overlays:
 
void clearMarkers ()
 Remove all markers.
 
void clearPlots ()
 Remove all plots from the chart.
 
QPoint contextMenuPos () const
 Get the position where the context menu was last shown.
 
int dataBin2ScreenX (long x) const
 Convert a bin number to a screen coordinate.
 
QImage drawOffscreen ()
 Draws the chart off screen and returns an image of the result.
 
double fullChartWidth () const
 width in pixels that the chart would have if it were fully shown (considering current zoom level)k
 
bool isTooltipShown () const
 Check whether currently tooltips are enabled.
 
virtual int leftMargin () const
 Retrieve left margin (in pixels).
 
double maxXZoom () const
 Get the maximum zoom factor in x direction that can be in use.
 
std::vector< std::shared_ptr< iAPlot > > const & plots ()
 Retrieve all plots currently in the chart.
 
void removeImageOverlay (QImage *imgOverlay)
 Remove an image overlay from the chart.
 
void removePlot (std::shared_ptr< iAPlot > plot)
 Remove a plot from the chart.
 
void removeXMarker (double xPos)
 Remove the marker at the given x position (in data space, see screenX2DataBin for details).
 
void resetYBounds ()
 Reset y bounds to the range specified by the current plots.
 
long screenX2DataBin (int x) const
 Convert an x screen coordinate to a bin space index; Note that there are (at least) four different coordinate spaces to consider:
 
void setCaptionPosition (Qt::Alignment captionAlignment)
 Set position of x axis caption (Center/Left, Bottom/Top, via Qt::Align... flags).
 
void setEmptyText (QString const &text)
 Set text shown when no plot available.
 
void setSelectionMode (SelectionMode mode)
 Determine how a selection works; see SelectionMode: either disable selection, or allow selection of single plots.
 
void setXBounds (double minVal, double maxVal)
 Set custom x bounds (the interval the x axis covers).
 
void setXCaption (QString const &caption)
 Set the caption shown along the x axis.
 
void setXMarker (double xPos, QColor const &color, Qt::PenStyle penStyle=Qt::SolidLine)
 Add or update a marker at a specific x position (in data space, see screenX2DataBin for details) in the given color.
 
void setYBounds (iAPlotData::DataType minVal, iAPlotData::DataType maxVal)
 Set custom y bounds (the interval the y axis covers).
 
void setYCaption (QString const &caption)
 Set the caption shown along the y axis.
 
void setYMappingMode (AxisMappingType drawMode)
 Set either linear or logarithmic mapping mode.
 
void showLegend (bool show)
 Set whether legend should be shown or not.
 
void showXAxisLabel (bool show)
 Set whether x axis caption should be shown or not.
 
void updateBounds (size_t startPlot=0)
 Update all bounds such that all current plots are in the visible area of the chart.
 
void updateXBounds (size_t startPlot=0)
 Update x bounds of the chart such that the x bounds of all current plots are in the visible area of the chart.
 
void updateYBounds (size_t startPlot=0)
 Update y bounds of the chart such that the y bounds of all current plots are in the visible area of the chart.
 
double xRange () const
 Get the range in x direction (i.e. maximum - minimum of x bounds)
 
double xZoom () const
 Get x/y zoom and shift.
 
double yZoom () const
 
double xShift () const
 
int yShift () const
 
void setXShift (double xShift)
 set the x zoom/shift:
 
void setXZoom (double xZoom)
 
void setYZoom (double yZoom)
 
iAPlotData::DataType minYDataValue (size_t startPlot=0) const
 Retrieve minimum/maximum y data value.
 
iAPlotData::DataType maxYDataValue (size_t startPlot=0) const
 
iAMapper const & xMapper () const
 Get mapper for x/y coordinates.
 
iAMapper const & yMapper () const
 
int data2MouseX (double dataX)
 Convert mouse X coordinates (in chart already, i.e.
 
double mouse2DataX (int mouseX)
 
virtual iAPlotData::DataType const * yBounds () const
 Get x/y bounds as array of size 2 (minimum, maximum)
 
virtual double const * xBounds () const
 

Static Public Attributes

static const size_t MaxPossiblePlot = std::numeric_limits<size_t>::max()
 

Protected Member Functions

virtual void changeMode (int newMode, QMouseEvent *event)
 
virtual void drawAxes (QPainter &painter)
 
virtual void drawLegend (QPainter &painter)
 
virtual void drawPlots (QPainter &painter)
 
virtual void showDataTooltip (QHelpEvent *event)
 
virtual QString xAxisTickMarkLabel (double value, double stepWidth)
 
void zoomAlongX (double value, int x, bool deltaMode)
 
void zoomAlongY (double value, bool deltaMode)
 
void mouseMoveEvent (QMouseEvent *event) override
 Overriden Qt events.
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void mouseDoubleClickEvent (QMouseEvent *event) override
 
void wheelEvent (QWheelEvent *event) override
 
void leaveEvent (QEvent *event) override
 
void paintEvent (QPaintEvent *event) override
 
void contextMenuEvent (QContextMenuEvent *event) override
 
bool event (QEvent *event) override
 

Protected Attributes

int m_dragStartPosX
 
int m_dragStartPosY
 
int m_mode
 
int m_translationStartY
 
int m_translationY
 
QString m_xCaption
 
std::shared_ptr< iAMapperm_xMapper
 Main mappers from diagram coordinates to pixel coordinates, for each axis:
 
double m_xShift
 
double m_xShiftStart
 
double m_xZoom
 
double m_xZoomStart
 
QString m_yCaption
 
std::shared_ptr< iAMapperm_yMapper
 
AxisMappingType m_yMappingMode
 
double m_yZoom
 
double m_yZoomStart
 
int m_zoomXPos
 
int m_zoomYPos
 

Detailed Description

A chart widget which can show an arbitrary number of plots.

Member Enumeration Documentation

◆ AxisMappingType

Enumerator
Linear 
Logarithmic 

◆ Mode

Enumerator
NO_MODE 
MOVE_VIEW_MODE 
X_ZOOM_MODE 
Y_ZOOM_MODE 

◆ SelectionMode

Enumerator
SelectionDisabled 
SelectPlot 

Constructor & Destructor Documentation

◆ iAChartWidget()

iAChartWidget::iAChartWidget ( QWidget * parent,
QString const & xLabel,
QString const & yLabel )

◆ ~iAChartWidget()

iAChartWidget::~iAChartWidget ( )

Member Function Documentation

◆ addImageOverlay()

void iAChartWidget::addImageOverlay ( std::shared_ptr< QImage > imgOverlay,
bool stretch = true )

Add an image overlay to the chart.

◆ addPlot()

void iAChartWidget::addPlot ( std::shared_ptr< iAPlot > plot)

Add a plot to the chart.

◆ axisChanged

void iAChartWidget::axisChanged ( )
signal

Fires whenever the displayed x/y axis has changed (i.e. if it has been shifted, zoomed, or reset).

◆ bottomMargin()

int iAChartWidget::bottomMargin ( ) const
virtual

Retrieve bottom margin (in pixels).

◆ categoricalAxis()

bool iAChartWidget::categoricalAxis ( ) const

Whether the axis of this chart is categorical type (as determined by the first plot).

◆ changeMode()

void iAChartWidget::changeMode ( int newMode,
QMouseEvent * event )
protectedvirtual

Reimplemented in iAChartWithFunctionsWidget.

◆ chartHeight()

int iAChartWidget::chartHeight ( ) const
virtual

Retrieve height (in pixels) of the actual chart, i.e. the region where plots are drawn, without space for the margins / axes.

◆ chartWidth()

int iAChartWidget::chartWidth ( ) const
virtual

Retrieve width (in pixels) of the actual chart, i.e. the region where plots are drawn, without space for margins / axes.

◆ clearImageOverlays()

void iAChartWidget::clearImageOverlays ( )

Clear all image overlays:

◆ clearMarkers()

void iAChartWidget::clearMarkers ( )

Remove all markers.

◆ clearPlots()

void iAChartWidget::clearPlots ( )

Remove all plots from the chart.

◆ clicked

void iAChartWidget::clicked ( double x,
Qt::KeyboardModifiers modifiers )
signal

Fires whenever the user clicks on the chart.

Parameters
xcoordinate x of the click position, in chart coordinates
modifiersmodifier keys that were pressed at time of click

◆ contextMenuEvent()

void iAChartWidget::contextMenuEvent ( QContextMenuEvent * event)
overrideprotected

◆ contextMenuPos()

QPoint iAChartWidget::contextMenuPos ( ) const

Get the position where the context menu was last shown.

◆ data2MouseX()

int iAChartWidget::data2MouseX ( double dataX)

Convert mouse X coordinates (in chart already, i.e.

without left/bottom margin) to chart x coordinates and vice versa

◆ dataBin2ScreenX()

int iAChartWidget::dataBin2ScreenX ( long x) const

Convert a bin number to a screen coordinate.

Parameters
xthe bin space index; see screenX2DataBin for details
Returns
the screen space coordinate for the given bin space index

◆ dblClicked

void iAChartWidget::dblClicked ( )
signal

Fires whenever the user double-clicks on the chart.

◆ drawAxes()

void iAChartWidget::drawAxes ( QPainter & painter)
protectedvirtual

◆ drawLegend()

void iAChartWidget::drawLegend ( QPainter & painter)
protectedvirtual

◆ drawOffscreen()

QImage iAChartWidget::drawOffscreen ( )

Draws the chart off screen and returns an image of the result.

◆ drawPlots()

void iAChartWidget::drawPlots ( QPainter & painter)
protectedvirtual

◆ event()

bool iAChartWidget::event ( QEvent * event)
overrideprotected

◆ fullChartWidth()

double iAChartWidget::fullChartWidth ( ) const

width in pixels that the chart would have if it were fully shown (considering current zoom level)k

◆ isTooltipShown()

bool iAChartWidget::isTooltipShown ( ) const

Check whether currently tooltips are enabled.

◆ leaveEvent()

void iAChartWidget::leaveEvent ( QEvent * event)
overrideprotected

◆ leftMargin()

int iAChartWidget::leftMargin ( ) const
virtual

Retrieve left margin (in pixels).

◆ legendPlotClicked

void iAChartWidget::legendPlotClicked ( size_t plotID)
signal

Emitted when a plot is clicked in the legend.

Parameters
plotIDthe index of the plot that was clicked (in the vector accessible via plots())

◆ maxXZoom()

double iAChartWidget::maxXZoom ( ) const

Get the maximum zoom factor in x direction that can be in use.

◆ maxYDataValue()

iAPlotData::DataType iAChartWidget::maxYDataValue ( size_t startPlot = 0) const

◆ minYDataValue()

iAPlotData::DataType iAChartWidget::minYDataValue ( size_t startPlot = 0) const

Retrieve minimum/maximum y data value.

◆ mouse2DataX()

double iAChartWidget::mouse2DataX ( int mouseX)

◆ mouseDoubleClickEvent()

void iAChartWidget::mouseDoubleClickEvent ( QMouseEvent * event)
overrideprotected

◆ mouseMoveEvent()

void iAChartWidget::mouseMoveEvent ( QMouseEvent * event)
overrideprotected

Overriden Qt events.

◆ mousePressEvent()

void iAChartWidget::mousePressEvent ( QMouseEvent * event)
overrideprotected

◆ mouseReleaseEvent()

void iAChartWidget::mouseReleaseEvent ( QMouseEvent * event)
overrideprotected

◆ paintEvent()

void iAChartWidget::paintEvent ( QPaintEvent * event)
overrideprotected

◆ plots()

std::vector< std::shared_ptr< iAPlot > > const & iAChartWidget::plots ( )

Retrieve all plots currently in the chart.

◆ plotsSelected

void iAChartWidget::plotsSelected ( std::vector< size_t > const & plotIDs)
signal

Fires whenever one or more plots are selected.

Parameters
plotIDsthe IDs of the selected plots

◆ removeImageOverlay()

void iAChartWidget::removeImageOverlay ( QImage * imgOverlay)

Remove an image overlay from the chart.

◆ removePlot()

void iAChartWidget::removePlot ( std::shared_ptr< iAPlot > plot)

Remove a plot from the chart.

◆ removeXMarker()

void iAChartWidget::removeXMarker ( double xPos)

Remove the marker at the given x position (in data space, see screenX2DataBin for details).

◆ resetView

void iAChartWidget::resetView ( )
slot

Reset view (zoom and shift in x and y direction) such that all plots are fully visible.

◆ resetYBounds()

void iAChartWidget::resetYBounds ( )

Reset y bounds to the range specified by the current plots.

◆ screenX2DataBin()

long iAChartWidget::screenX2DataBin ( int x) const

Convert an x screen coordinate to a bin space index; Note that there are (at least) four different coordinate spaces to consider:

  1. the data space (i.e., a coordinate between the minimum/maximum specified by the x bounds),
  2. the bin space (i.e., an index in the data bin array)
  3. the screen space (i.e., a pixel coordinate on the screen)
  4. the mouse space (i.e., a pixel coordinate on the currently visible part of the chart)
Parameters
xthe x screen coordinate to convert
Returns
the bin index for the given x coordinate.
See also
xMapper, yMapper, data2MouseX, mouse2DataX

◆ setCaptionPosition()

void iAChartWidget::setCaptionPosition ( Qt::Alignment captionAlignment)

Set position of x axis caption (Center/Left, Bottom/Top, via Qt::Align... flags).

◆ setDrawXAxisAtZero

void iAChartWidget::setDrawXAxisAtZero ( bool enable)
slot

Determines whether the x axis is drawn at location of zero in the data, or at the bottom of the chart region.

Parameters
enableif true, the x axis is drawn where the value 0 is on the y axis; if false, it is drawn at the bottom of the chart region.

◆ setEmptyText()

void iAChartWidget::setEmptyText ( QString const & text)

Set text shown when no plot available.

◆ setSelectionMode()

void iAChartWidget::setSelectionMode ( SelectionMode mode)

Determine how a selection works; see SelectionMode: either disable selection, or allow selection of single plots.

◆ setXBounds()

void iAChartWidget::setXBounds ( double minVal,
double maxVal )

Set custom x bounds (the interval the x axis covers).

◆ setXCaption()

void iAChartWidget::setXCaption ( QString const & caption)

Set the caption shown along the x axis.

◆ setXMarker()

void iAChartWidget::setXMarker ( double xPos,
QColor const & color,
Qt::PenStyle penStyle = Qt::SolidLine )

Add or update a marker at a specific x position (in data space, see screenX2DataBin for details) in the given color.

◆ setXShift()

void iAChartWidget::setXShift ( double xShift)

set the x zoom/shift:

◆ setXZoom()

void iAChartWidget::setXZoom ( double xZoom)

◆ setYBounds()

void iAChartWidget::setYBounds ( iAPlotData::DataType minVal,
iAPlotData::DataType maxVal )

Set custom y bounds (the interval the y axis covers).

◆ setYCaption()

void iAChartWidget::setYCaption ( QString const & caption)

Set the caption shown along the y axis.

◆ setYMappingMode()

void iAChartWidget::setYMappingMode ( AxisMappingType drawMode)

Set either linear or logarithmic mapping mode.

◆ setYZoom()

void iAChartWidget::setYZoom ( double yZoom)

◆ showDataTooltip()

void iAChartWidget::showDataTooltip ( QHelpEvent * event)
protectedvirtual

◆ showLegend()

void iAChartWidget::showLegend ( bool show)

Set whether legend should be shown or not.

◆ showXAxisLabel()

void iAChartWidget::showXAxisLabel ( bool show)

Set whether x axis caption should be shown or not.

◆ updateBounds()

void iAChartWidget::updateBounds ( size_t startPlot = 0)

Update all bounds such that all current plots are in the visible area of the chart.

◆ updateXBounds()

void iAChartWidget::updateXBounds ( size_t startPlot = 0)

Update x bounds of the chart such that the x bounds of all current plots are in the visible area of the chart.

◆ updateYBounds()

void iAChartWidget::updateYBounds ( size_t startPlot = 0)

Update y bounds of the chart such that the y bounds of all current plots are in the visible area of the chart.

◆ wheelEvent()

void iAChartWidget::wheelEvent ( QWheelEvent * event)
overrideprotected

◆ xAxisTickMarkLabel()

QString iAChartWidget::xAxisTickMarkLabel ( double value,
double stepWidth )
protectedvirtual

◆ xBounds()

double const * iAChartWidget::xBounds ( ) const
virtual

◆ xMapper()

iAMapper const & iAChartWidget::xMapper ( ) const

Get mapper for x/y coordinates.

◆ xRange()

double iAChartWidget::xRange ( ) const

Get the range in x direction (i.e. maximum - minimum of x bounds)

◆ xShift()

double iAChartWidget::xShift ( ) const
inline

◆ xZoom()

double iAChartWidget::xZoom ( ) const
inline

Get x/y zoom and shift.

◆ yBounds()

iAPlotData::DataType const * iAChartWidget::yBounds ( ) const
virtual

Get x/y bounds as array of size 2 (minimum, maximum)

◆ yMapper()

iAMapper const & iAChartWidget::yMapper ( ) const

◆ yShift()

int iAChartWidget::yShift ( ) const
inline

◆ yZoom()

double iAChartWidget::yZoom ( ) const
inline

◆ zoomAlongX()

void iAChartWidget::zoomAlongX ( double value,
int x,
bool deltaMode )
protected

◆ zoomAlongY()

void iAChartWidget::zoomAlongY ( double value,
bool deltaMode )
protected

Member Data Documentation

◆ m_dragStartPosX

int iAChartWidget::m_dragStartPosX
protected

◆ m_dragStartPosY

int iAChartWidget::m_dragStartPosY
protected

◆ m_mode

int iAChartWidget::m_mode
protected

◆ m_translationStartY

int iAChartWidget::m_translationStartY
protected

◆ m_translationY

int iAChartWidget::m_translationY
protected

◆ m_xCaption

QString iAChartWidget::m_xCaption
protected

◆ m_xMapper

std::shared_ptr<iAMapper> iAChartWidget::m_xMapper
mutableprotected

Main mappers from diagram coordinates to pixel coordinates, for each axis:

◆ m_xShift

double iAChartWidget::m_xShift
protected

◆ m_xShiftStart

double iAChartWidget::m_xShiftStart
protected

◆ m_xZoom

double iAChartWidget::m_xZoom
protected

◆ m_xZoomStart

double iAChartWidget::m_xZoomStart
protected

◆ m_yCaption

QString iAChartWidget::m_yCaption
protected

◆ m_yMapper

std::shared_ptr<iAMapper> iAChartWidget::m_yMapper
protected

◆ m_yMappingMode

AxisMappingType iAChartWidget::m_yMappingMode
protected

◆ m_yZoom

double iAChartWidget::m_yZoom
protected

◆ m_yZoomStart

double iAChartWidget::m_yZoomStart
protected

◆ m_zoomXPos

int iAChartWidget::m_zoomXPos
protected

◆ m_zoomYPos

int iAChartWidget::m_zoomYPos
protected

◆ MaxPossiblePlot

const size_t iAChartWidget::MaxPossiblePlot = std::numeric_limits<size_t>::max()
static

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