QTradingView 1.0.0
A high-performance charting library built with C++ and Qt.
Loading...
Searching...
No Matches
QTradingView::ViewPort Class Reference

Manages the visible range and pixel mapping for chart bars. More...

#include <ViewPort.h>

Public Member Functions

 ViewPort ()
 Constructs an empty ViewPort.
 
 ViewPort (int startIndex, int endIndex, const QRectF &pixelRect, double barWidth=8.0)
 Constructs a ViewPort with specified range, pixel rectangle, and bar width.
 
void setVisibleRange (int start, int end)
 Sets the visible range of bar indices.
 
int startIndex () const
 Returns the index of the first visible bar.
 
int endIndex () const
 Returns the index of the last visible bar.
 
int visibleCount () const
 Returns the number of visible bars in the viewport.
 
void setPixelRect (const QRectF &rect)
 Sets the pixel rectangle for the viewport area.
 
QRectF pixelRect () const
 Returns the pixel rectangle of the viewport.
 
double indexToPixel (int index) const
 Converts a bar index to its pixel position within the viewport.
 
int pixelToIndex (double pixel) const
 Converts a pixel position to the corresponding bar index.
 
void setBarWidth (double width)
 Sets the width of each bar in pixels.
 
double barWidth () const
 Returns the width of each bar in pixels.
 

Detailed Description

Manages the visible range and pixel mapping for chart bars.

ViewPort controls which data indices are visible, their pixel positions, and the bar width for rendering. It provides conversion between data indices and pixel coordinates, and supports dynamic resizing and zooming.

Constructor & Destructor Documentation

◆ ViewPort()

QTradingView::ViewPort::ViewPort ( int  startIndex,
int  endIndex,
const QRectF &  pixelRect,
double  barWidth = 8.0 
)

Constructs a ViewPort with specified range, pixel rectangle, and bar width.

Parameters
startIndexIndex of the first visible bar.
endIndexIndex of the last visible bar.
pixelRectRectangle area in pixels for the viewport.
barWidthWidth of each bar in pixels (default 8.0).

Member Function Documentation

◆ indexToPixel()

double QTradingView::ViewPort::indexToPixel ( int  index) const

Converts a bar index to its pixel position within the viewport.

Parameters
indexBar index to convert.
Returns
Pixel position corresponding to the index.

◆ pixelToIndex()

int QTradingView::ViewPort::pixelToIndex ( double  pixel) const

Converts a pixel position to the corresponding bar index.

Parameters
pixelPixel position to convert.
Returns
Bar index corresponding to the pixel position.

◆ setBarWidth()

void QTradingView::ViewPort::setBarWidth ( double  width)

Sets the width of each bar in pixels.

Parameters
widthBar width in pixels.

◆ setPixelRect()

void QTradingView::ViewPort::setPixelRect ( const QRectF &  rect)

Sets the pixel rectangle for the viewport area.

Parameters
rectRectangle area in pixels.

◆ setVisibleRange()

void QTradingView::ViewPort::setVisibleRange ( int  start,
int  end 
)

Sets the visible range of bar indices.

Parameters
startIndex of the first visible bar.
endIndex of the last visible bar.

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