class QWT_EXPORT QwtPlot: public QFrame, public QwtPlotDict
{
Q_OBJECT
Q_PROPERTY( QBrush canvasBackground
READ canvasBackground WRITE setCanvasBackground )
Q_PROPERTY( bool autoReplot READ autoReplot WRITE setAutoReplot )
public:
//坐标轴位置
enum Axis
{
//! Y axis left of the canvas
yLeft,
//! Y axis right of the canvas
yRight,
//! X axis below the canvas
xBottom,
//! X axis above the canvas
xTop,
//! Number of axes
axisCnt
};
//图例位置
enum LegendPosition
{
//! The legend will be left from the QwtPlot::yLeft axis.
LeftLegend,
//! The legend will be right from the QwtPlot::yRight axis.
RightLegend,
//! The legend will be below the footer
BottomLegend,
//! The legend will be above the title
TopLegend
};
//构造函数和析构函数
explicit QwtPlot( QWidget * = NULL );
explicit QwtPlot( const QwtText &title, QWidget * = NULL );
virtual ~QwtPlot();
//(目前不清楚)
void applyProperties( const QString & );
QString grabProperties() const;
/*如果设置了autoReplot选项,则将通过操纵成员函数来隐式更新图。 由于这可能很耗时,因此建议关闭此选项,并在必要时显式调用replot()*/
void setAutoReplot( bool = true ); //设置自动更新状态为自动更新
bool autoReplot() const; //返回当前自动更新状态
// Layout
void setPlotLayout( QwtPlotLayout * ); //为QwtPlot分配一个新的布局
QwtPlotLayout *plotLayout(); //返回QwtPlot当前的布局
const QwtPlotLayout *plotLayout() const;
// Title
void setTitle( const QString & ); //设置QwtPlot标题
void setTitle( const QwtText &t );
QwtText title() const; //返回当前的QwtPlot标题
QwtTextLabel *titleLabel(); //返回当前显示QwtPlot标题的标签
const QwtTextLabel *titleLabel() const; //返回当前显示QwtPlot标题的标签
// Footer
void setFooter( const QString & ); //设置QwtPlot底部标题
void setFooter( const QwtText &t );
QwtText footer() const; //返回当前QwtPlot底部标题
QwtTextLabel *footerLabel(); //返回当前显示QwtPlot底部标题的标签
const QwtTextLabel *footerLabel() const; //返回当前显示QwtPlot底部标题的标签
// Canvas
void setCanvas( QWidget * ); //给QwtPlot设置画布
QWidget *canvas(); //返回当前QwtPlot的画布
const QWidget *canvas() const;
void setCanvasBackground( const QBrush & ); //设置画布的背景颜色
QBrush canvasBackground() const; //返回画布的背景颜色
//返回画布上指定轴的map,使用此map,像素坐标可以转换为绘图坐标,反之亦然
virtual QwtScaleMap canvasMap( int axisId ) const;
//将绘图区域内的一个点的x坐标或y坐标转换为一个值,这个点是x还是y取决于指定的坐标轴
//简而言之:就是将画布内的x或y坐标值映射为屏幕像素的x或y坐标值
double invTransform( int axisId, int pos ) const;
//将一个值转换为绘图区域内的一个点的x坐标或y坐标,这个点是x还是y取决于指定的坐标轴
//简而言之:就是将屏幕像素的x或y坐标值映射为画布内的一个点的x或y坐标值
double transform( int axisId, double value ) const;
// Axes
QwtScaleEngine *axisScaleEngine( int axisId ); //返回指定坐标轴上的比例尺算法
const QwtScaleEngine *axisScaleEngine( int axisId ) const;
void setAxisScaleEngine( int axisId, QwtScaleEngine * ); //设置指定坐标轴上的比例尺算法
//给指定了固定刻度模式的坐标轴使能为自动刻度模式
void setAxisAutoScale( int axisId, bool on = true );
//返回指定坐标轴自动刻度模式的状态
bool axisAutoScale( int axisId ) const;
/*当一个坐标轴被禁用之后,这只是意味着它在屏幕中不可见而已,曲线、标记等图元项都可以依附到禁用的坐标轴上,并且可以像往常一样将屏幕坐标转换为值*/
void enableAxis( int axisId, bool tf = true ); //使能或禁用一个指定的坐标轴
bool axisEnabled( int axisId ) const; //返回指定坐标轴的使能状态
void setAxisFont( int axisId, const QFont &f ); //设置指定坐标轴字体
QFont axisFont( int axisId ) const; //返回指定坐标轴字体
//设置指定坐标轴的比例尺
void setAxisScale( int axisId, double min, double max, double step = 0 );
//设置指定坐标轴的比例尺刻度
void setAxisScaleDiv( int axisId, const QwtScaleDiv & );
//设置指定坐标轴的比例尺绘制
void setAxisScaleDraw( int axisId, QwtScaleDraw * );
//返回通过setAxisScale()设置的步长参数
double axisStepSize( int axisId ) const;
/*这个函数只是为了方便使用axisScaleDiv( axisId )->interval();*/
QwtInterval axisInterval( int axisId ) const; //返回指定坐标轴当前的间隔
//返回指定坐标轴的比例尺刻度对象
const QwtScaleDiv &axisScaleDiv( int axisId ) const;
//返回指定坐标轴的比例尺绘制对象
const QwtScaleDraw *axisScaleDraw( int axisId ) const;
QwtScaleDraw *axisScaleDraw( int axisId );
//返回指定坐标轴的窗体对象
const QwtScaleWidget *axisWidget( int axisId ) const;
QwtScaleWidget *axisWidget( int axisId );
//设置指定坐标轴标题的对齐方式
void setAxisLabelAlignment( int axisId, Qt::Alignment );
//设置指定坐标轴标题的方向
void setAxisLabelRotation( int axisId, double rotation );
//设置指定坐标轴的标题
void setAxisTitle( int axisId, const QString & );
void setAxisTitle( int axisId, const QwtText & );
//返回指定坐标轴的标题
QwtText axisTitle( int axisId ) const;
//设置指定坐标轴次要刻度线的最大个数,次要刻度线即短的刻度线
void setAxisMaxMinor( int axisId, int maxMinor );
//返回指定坐标轴上次要刻度线的最大个数
int axisMaxMinor( int axisId ) const;
//设置指定坐标轴主要刻度线的最大个数,主要刻度线即长的刻度线
void setAxisMaxMajor( int axisId, int maxMajor );
//返回指定坐标轴上主要刻度线的最大个数
int axisMaxMajor( int axisId ) const;
// Legend
/*如果图例的位置是QwtPlot::LeftLegend或QwtPlot::RightLegend,图例将会在一列中从上往下组织。否则,图例项将会以从左到右的形式组织在一个表格里。
insertLegend()将给图例设置一个绘图窗口作为父类,当插入了另一个图例,图例将会在绘图窗口的析构函数中被删除。
图例,没有插入到绘图窗体的布局中,需要连接legendDataChanged()信号,调用updateLegend()触发这个信号来初始化更新。当应用程序代码想要实现其自己的布局时,还需要执行此操作以将图绘制到文档中。
*/
void insertLegend( QwtAbstractLegend *,
LegendPosition = QwtPlot::RightLegend, double ratio = -1.0 ); //插入图例
QwtAbstractLegend *legend(); //返回当前的图例
const QwtAbstractLegend *legend() const;
//给所有的图元项发送legendDataChanged()信号
void updateLegend();
//给指定的图元项发送legendDataChanged()信号
void updateLegend( const QwtPlotItem * );
// Misc
//返回绘图窗体的尺寸信息
virtual QSize sizeHint() const;
//返回绘图窗体的最小尺寸信息
virtual QSize minimumSizeHint() const;
virtual void updateLayout(); //将图内容调整为它当前的大小
/*警告:drawCanvas()调用drawItems(),drawItems()是用于打印的。 喜欢添加单个绘图项的应用程序最好重载drawItems()*/
virtual void drawCanvas( QPainter * ); //重绘画布
/*在自动刻度模式下,比例尺的边界是从所有绘图项的边界矩形计算出来的,并启用QwtPlotItem::AutoScale标志(QwtScaleEngine::autoScale())。 然后计算比例尺划分(QwtScaleEngine::didvideScale()),并将其分配给比例尺窗体。*/
void updateAxes(); //重建坐标轴刻度
/*绘图项可能通过QwtPlotItem :: Margins标志表明它们在画布的边框处需要一些额外的空间。*/
void updateCanvasMargins(); //更新画布的外边距
//计算画布边距
virtual void getCanvasMarginsHint(
const QwtScaleMap maps[], const QRectF &canvasRect,
double &left, double &top, double &right, double &bottom) const;
virtual bool event( QEvent * ); //添加布局需要的事件
virtual bool eventFilter( QObject *, QEvent * ); //事件过滤
//绘制图元
virtual void drawItems( QPainter *, const QRectF &,
const QwtScaleMap maps[axisCnt] ) const;
//创建一个通常用于确认图例上图元项的信息
virtual QVariant itemToInfo( QwtPlotItem * ) const;
//根据itemToInfo()创建的一个图元信息对象来确认图元项
virtual QwtPlotItem *infoToItem( const QVariant & ) const;
Q_SIGNALS:
//用于提示一个图元项已经被绑定或已经解绑
void itemAttached( QwtPlotItem *plotItem, bool on );
//一个具有属性的信号,该属性用于对一个图元项更新图例条目
void legendDataChanged( const QVariant &itemInfo,
const QList<QwtLegendData> &data );
public Q_SLOTS:
//重绘图形
/*如果autoReplot选项(默认)没有设置,或者如果任何曲线添加了新的数据,图形必须精确地被刷新才能使得 改变可见*/
virtual void replot();
//如果autoReplot是true的话,重绘图形
void autoRefresh();
protected:
//如果指定坐标轴存在的话,返回true,否则返回false
static bool axisValid( int axisId );
//调整大小并且更新内部布局
virtual void resizeEvent( QResizeEvent *e );
private Q_SLOTS:
//更新对图例属性感兴趣的所有图元项
/*当QwtPlotItem::LegendInterest标志位设置了,调用 QwtPlotItem::updateLegend()*/
void updateLegendItems( const QVariant &itemInfo,
const QList<QwtLegendData> &data );
private:
friend class QwtPlotItem; //友元类
//绑定和解绑图元项,当true时绑定图元项,否则解绑图元项
void attachItem( QwtPlotItem *, bool );
//初始化坐标系
void initAxesData();
//删除坐标系
void deleteAxesData();
//更新比例尺刻度
void updateScaleDiv();
//初始化一个QwtPlot例子
void initPlot( const QwtText &title );
class AxisData; //嵌套内,用于封装坐标系数据
AxisData *d_axisData[axisCnt]; //四个坐标轴的数据,axisCnt = 4
class PrivateData; //嵌套类,用于封装本类的数据
PrivateData *d_data;
QwtPlot类源码解读
最新推荐文章于 2025-11-06 21:35:23 发布
本文详细介绍了QwtPlot类,涵盖坐标轴位置、图例、布局管理、标题和图元操作等功能,以及如何设置自动重绘和调整布局。掌握这些核心内容有助于创建专业级的动态图表应用。
1万+

被折叠的 条评论
为什么被折叠?



