QWT 7.0.1
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
QwtPlotLayoutEngine Class Reference

The QwtPlotLayoutEngine class. More...

#include <qwt_plot_layout_engine.h>

Classes

struct  Dimensions
 
class  LayoutData
 

Public Member Functions

 QwtPlotLayoutEngine ()
 Default constructor for QwtPlotLayoutEngine / QwtPlotLayoutEngine的默认构造函数
 
QRectF layoutLegend (int plotLayoutOptions, const LayoutData::LegendData &legendData, const QRectF &rect, const QSize &legendHint) const
 Calculate legend rectangle within available space / 在可用空间内计算图例矩形
 
QRectF alignLegend (const QSize &legendHint, const QRectF &canvasRect, const QRectF &legendRect) const
 Align legend rectangle relative to canvas / 相对于画布对齐图例矩形
 
void alignScales (int plotLayoutOptions, const LayoutData &layoutData, QRectF &canvasRect, QRectF scaleRect[QwtAxis::AxisPositions]) const
 Align scale rectangles with canvas / 将刻度矩形与画布对齐
 
void alignScalesToCanvas (int plotLayoutOptions, const LayoutData &layoutData, const QRectF &canvasRect, QRectF scaleRect[QwtAxis::AxisPositions]) const
 
Dimensions layoutDimensions (int plotLayoutOptions, const LayoutData &layoutData, const QRectF &rect) const
 Iteratively calculate the layout dimensions for a QwtPlot / 迭代计算QwtPlot的布局尺寸
 
void setSpacing (unsigned int spacing)
 Set spacing value / 设置间距值
 
unsigned int spacing () const
 Get spacing value / 获取间距值
 
void setAlignCanvas (int axisPos, bool on)
 Set canvas alignment to scale for a specific axis / 设置画布对齐到特定轴的刻度
 
bool alignCanvas (int axisPos) const
 Check if canvas is aligned to scale for a specific axis / 检查画布是否对齐到特定轴的刻度
 
void setCanvasMargin (int axisPos, int margin)
 Set canvas margin for a specific axis / 设置特定轴的画布边距
 
int canvasMargin (int axisPos) const
 Get canvas margin for a specific axis / 获取特定轴的画布边距
 
void setLegendPos (QwtPlot::LegendPosition pos)
 Set the legend position / 设置图例位置
 
QwtPlot::LegendPosition legendPos () const
 Get the legend position / 获取图例位置
 
void setLegendRatio (double ratio)
 Set the legend ratio / 设置图例比例
 
double legendRatio () const
 Get the legend ratio / 获取图例比例
 

Detailed Description

The QwtPlotLayoutEngine class.

原来的QwtPlotLayout里的私有类,原来此类写在qwt_plot_layout.cpp中,class LayoutEngine,由于其它布局会用到,把它提取为公共类

Constructor & Destructor Documentation

◆ QwtPlotLayoutEngine()

QwtPlotLayoutEngine::QwtPlotLayoutEngine ( )

Default constructor for QwtPlotLayoutEngine / QwtPlotLayoutEngine的默认构造函数

Initializes the layout engine with default values:

  • Legend position: Bottom
  • Legend ratio: 1.0
  • Spacing: 5 pixels

使用默认值初始化布局引擎:

  • 图例位置:底部
  • 图例比例:1.0
  • 间距:5像素

Member Function Documentation

◆ alignCanvas()

bool QwtPlotLayoutEngine::alignCanvas ( int  axisPos) const

Check if canvas is aligned to scale for a specific axis / 检查画布是否对齐到特定轴的刻度

Parameters
axisPosAxis position (0-3) / 轴位置(0-3)
Returns
True if canvas is aligned to scale / 如果画布对齐到刻度,则返回true

◆ alignLegend()

QRectF QwtPlotLayoutEngine::alignLegend ( const QSize &  legendHint,
const QRectF &  canvasRect,
const QRectF &  legendRect 
) const

Align legend rectangle relative to canvas / 相对于画布对齐图例矩形

Adjusts the legend rectangle to be properly aligned with the canvas, ensuring it doesn't extend beyond the canvas boundaries when possible.

调整图例矩形以与画布正确对齐,确保在可能的情况下不超出画布边界。

Parameters
legendHintPreferred size hint for the legend / 图例的首选尺寸提示
canvasRectCanvas rectangle / 画布矩形
legendRectInitial legend rectangle / 初始图例矩形
Returns
Aligned legend rectangle / 对齐后的图例矩形

◆ alignScales()

void QwtPlotLayoutEngine::alignScales ( int  plotLayoutOptions,
const LayoutData layoutData,
QRectF &  canvasRect,
QRectF  scaleRect[QwtAxis::AxisPositions] 
) const

Align scale rectangles with canvas / 将刻度矩形与画布对齐

Adjusts the positions of scale rectangles to ensure proper alignment with the canvas, taking into account border distances and tick offsets.

调整刻度矩形的位置以确保与画布正确对齐,考虑边框距离和刻度偏移量。

这个函数的主要职责是调整坐标轴刻度矩形的位置,确保它们与画布正确对齐。 这是一个复杂的布局计算过程,涉及到多个坐标轴和画布之间的空间协调。 具体计算过程可见代码里的注释

Parameters
plotLayoutOptionsLayout options bitmask / 布局选项位掩码
layoutDataPrecalculated layout data / 预计算的布局数据
canvasRectCanvas rectangle (may be modified) / 画布矩形(可能被修改)
scaleRectArray of scale rectangles (will be modified) / 刻度矩形数组(将被修改)
  1. 初始化骨干偏移量 (Backbone Offset) 首先计算每个轴的骨干偏移量,这个偏移量由以下几部分组成:
    • 如果不对齐画布到刻度,则加上画布边距
    • 如果不忽略框架,则加上画布内容边距
  1. 处理X轴和Y轴的相互影响 函数遍历所有轴位置,处理X轴和Y轴之间的相互空间影响:

对于X轴(水平轴): 检查左侧Y轴和右侧Y轴的影响 计算左右偏移量,考虑轴起始/结束距离和骨干偏移 调整X轴矩形位置,必要时调整画布矩形

对于Y轴(垂直轴): 检查底部X轴和顶部X轴的影响 计算上下偏移量,考虑轴起始/结束距离和骨干偏移 调整Y轴矩形位置,必要时调整画布矩形

当轴需要比可用空间更多的空间时,函数会调整画布矩形

在所有轴相互调整后,函数进行最终的对齐调整,确保轴与画布边缘正确对齐

◆ alignScalesToCanvas()

void QwtPlotLayoutEngine::alignScalesToCanvas ( int  plotLayoutOptions,
const LayoutData layoutData,
const QRectF &  canvasRect,
QRectF  scaleRect[QwtAxis::AxisPositions] 
) const
  1. 初始化骨干偏移量 (Backbone Offset) 首先计算每个轴的骨干偏移量,这个偏移量由以下几部分组成:
    • 如果不对齐画布到刻度,则加上画布边距
    • 如果不忽略框架,则加上画布内容边距
  1. 处理X轴和Y轴的相互影响 函数遍历所有轴位置,处理X轴和Y轴之间的相互空间影响:

对于X轴(水平轴): 检查左侧Y轴和右侧Y轴的影响 计算左右偏移量,考虑轴起始/结束距离和骨干偏移 调整X轴矩形位置,必要时调整画布矩形

对于Y轴(垂直轴): 检查底部X轴和顶部X轴的影响 计算上下偏移量,考虑轴起始/结束距离和骨干偏移 调整Y轴矩形位置,必要时调整画布矩形

在所有轴相互调整后,函数进行最终的对齐调整,确保轴与画布边缘正确对齐

◆ canvasMargin()

int QwtPlotLayoutEngine::canvasMargin ( int  axisPos) const

Get canvas margin for a specific axis / 获取特定轴的画布边距

Parameters
axisPosAxis position (0-3) / 轴位置(0-3)
Returns
Canvas margin value / 画布边距值

◆ layoutDimensions()

QwtPlotLayoutEngine::Dimensions QwtPlotLayoutEngine::layoutDimensions ( int  plotLayoutOptions,
const LayoutData layoutData,
const QRectF &  rect 
) const

Iteratively calculate the layout dimensions for a QwtPlot / 迭代计算QwtPlot的布局尺寸

This routine determines the exact space (in pixels) that every visual component of a QwtPlot—title, footer, and the four axes (X-top, X-bottom, Y-left, Y-right)—needs inside a given rectangle. Because the required size of one component affects the available space for all others (e.g. a taller horizontal axis shrinks the vertical axes, which may then wrap their labels and expand horizontally, and so on), the algorithm loops until the dimensions stabilize.

本函数在给定矩形区域内,精确地计算QwtPlot中每一个可视部件 (标题、页脚以及四个坐标轴:上、下、左、右)所占用的像素尺寸。 由于各部件相互影响(例如水平轴变高会压缩垂直轴,垂直轴标签换行 又可能使水平轴再次换行),因此采用迭代方式,直到所有尺寸不再变化。

Parameters
plotLayoutOptionsLayout options bitmask / 布局选项位掩码
layoutDataPrecalculated layout data / 预计算的布局数据
rectAvailable rectangle for layout / 布局的可用矩形区域
Returns
Dimensions structure with calculated sizes / 包含计算尺寸的Dimensions结构体

◆ layoutLegend()

QRectF QwtPlotLayoutEngine::layoutLegend ( int  plotLayoutOptions,
const LayoutData::LegendData legendData,
const QRectF &  rect,
const QSize &  legendHint 
) const

Calculate legend rectangle within available space / 在可用空间内计算图例矩形

Determines the optimal position and size for the legend based on the specified legend position and ratio constraints.

根据指定的图例位置和比例约束,确定图例的最佳位置和大小。

Parameters
plotLayoutOptionsLayout options bitmask / 布局选项位掩码
legendDataPrecalculated legend data / 预计算的图例数据
rectAvailable rectangle for layout / 布局的可用矩形区域
legendHintPreferred size hint for the legend / 图例的首选尺寸提示
Returns
Calculated legend rectangle / 计算出的图例矩形

◆ legendPos()

QwtPlot::LegendPosition QwtPlotLayoutEngine::legendPos ( ) const

Get the legend position / 获取图例位置

Returns
Current legend position / 当前图例位置

◆ legendRatio()

double QwtPlotLayoutEngine::legendRatio ( ) const

Get the legend ratio / 获取图例比例

Returns
Current legend ratio value / 当前图例比例值

◆ setAlignCanvas()

void QwtPlotLayoutEngine::setAlignCanvas ( int  axisPos,
bool  on 
)

Set canvas alignment to scale for a specific axis / 设置画布对齐到特定轴的刻度

Parameters
axisPosAxis position (0-3) / 轴位置(0-3)
onTrue to align canvas to scale / 为true时对齐画布到刻度

◆ setCanvasMargin()

void QwtPlotLayoutEngine::setCanvasMargin ( int  axisPos,
int  margin 
)

Set canvas margin for a specific axis / 设置特定轴的画布边距

Parameters
axisPosAxis position (0-3) / 轴位置(0-3)
marginNew canvas margin value / 新的画布边距值

◆ setLegendPos()

void QwtPlotLayoutEngine::setLegendPos ( QwtPlot::LegendPosition  pos)

Set the legend position / 设置图例位置

Parameters
posNew legend position / 新的图例位置

◆ setLegendRatio()

void QwtPlotLayoutEngine::setLegendRatio ( double  ratio)

Set the legend ratio / 设置图例比例

Parameters
ratioNew legend ratio value / 新的图例比例值

◆ setSpacing()

void QwtPlotLayoutEngine::setSpacing ( unsigned int  spacing)

Set spacing value / 设置间距值

Parameters
spacingNew spacing value in pixels / 新的间距值(像素)

◆ spacing()

unsigned int QwtPlotLayoutEngine::spacing ( ) const

Get spacing value / 获取间距值

Returns
Current spacing value in pixels / 当前的间距值(像素)

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