QCustomPlot 2.0.1 源码分析

2024-06-04 10:38
文章标签 分析 源码 2.0 qcustomplot

本文主要是介绍QCustomPlot 2.0.1 源码分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

z

目录

  • The Layering system
  • QCustomPlot
    • 构成
      • QCPLayer
      • QCPGraph
      • QCPAxis
    • 绘制流程
    • 交互方式
      • 模式
      • 流程
    • 矩形选择模式
      • 模式
      • 流程
    • 成员变量
      • mLayers
      • mGraphs
      • mCurrentLayer
      • mPlottables
      • xAxis, yAxis, xAxis2, yAxis2
      • mInteractions 交互方式
      • mSelectionRectMode 矩形选择模式
      • mMousePressPos
    • 事件
      • paintEvent
      • mousePressEvent
      • mouseMoveEvent
      • mouseReleaseEvent
    • 函数
      • replot
      • addLayer
      • removeLayer
      • layer
      • currentLayer
      • setCurrentLayer
      • layerCount
      • moveLayer
      • setupPaintBuffers
      • registerGraph
      • registerPlottable
      • setInteraction
      • setInteractions
      • Interactions
      • processPointSelection
      • setSelectionRectMode
      • processRectSelection
      • processRectZoom
  • QCPLayer
    • 父类 QObject
    • 成员变量
      • mChildren
    • 函数
      • drawToPaintBuffer
      • draw
      • addChild
      • removeChild
      • children
  • QCPLayerable
    • 父类 QObject
    • 子类
    • 描述
    • 属性
      • visible: 是否可见
      • parentPlot: 父QCustomPlot
      • parentLayerable: 父QCPLayerable
      • layer: 所属的层QCPLayer
    • 成员变量
    • 函数
      • 构造函数
      • setLayer
      • moveToLayer
    • QCPGrid
    • 父类 QCPLayerable
  • QCPAxis 坐标轴
    • 父类 QCPLayerable
    • 成员变量
    • 函数
  • QCPAbstractItem
    • 父类 QCPLayerable
  • QCPSelectionRect
    • 父类 QCPLayerable
    • 函数
      • startSelection
      • moveSelection
      • endSelection
      • keyPressEvent
  • QCPAbstractPlottable
    • 父类 QCPLayerable
    • 描述
    • 函数
      • 构造函数
  • QCPLayoutElement 布局元素
    • 父类 QCPLayerable
  • QCPLayout 布局
    • 父类 QCPLayoutElement
  • QCPAxisRect
    • 父类 QCPLayoutElement
  • QCPAbstractLegendItem
    • 父类 QCPLayoutElement
  • QCPGraphData 图表数据
  • QCPAbstractPaintBuffer 绘制缓存
  • QCPPaintBufferPixmap
    • 父类 QCPAbstractPaintBuffer
  • QCPDataContainer 数据容器
  • QCPColorMap
    • 父类 QCPAbstractPlottable
  • QCPFinancial
    • 父类 QCPAbstractPlottable1D
  • QCPStatisticalBox
    • 父类 QCPAbstractPlottable1D
  • QCPBars
    • 父类 QCPAbstractPlottable1D
  • QCPCurve
    • 父类 QCPAbstractPlottable1D
  • QCPGraph 图表
    • 父类 QCPAbstractPlottable1D
    • 属性
      • lineStyle
      • scatterStyle
      • scatterSkip
      • channelFillGraph
      • adaptiveSampling
    • 函数
      • 构造函数
      • 插入数据
        • setData
        • addData
      • 线条类型
        • 设置/获取线条类型
      • 绘制
        • draw
OC](目录)

The Layering system

/*! \class QCPLayer
\brief A layer that may contain objects, to control the rendering order

The Layering system of QCustomPlot is the mechanism to control the rendering order of the
elements inside the plot.

It is based on the two classes QCPLayer and QCPLayerable. QCustomPlot holds an ordered list of
one or more instances of QCPLayer (see QCustomPlot::addLayer, QCustomPlot::layer,
QCustomPlot::moveLayer, etc.). When replotting, QCustomPlot goes through the list of layers
bottom to top and successively draws the layerables of the layers into the paint buffer(s).

A QCPLayer contains an ordered list of QCPLayerable instances. QCPLayerable is an abstract base
class from which almost all visible objects derive, like axes, grids, graphs, items, etc.

\section qcplayer-defaultlayers Default layers

Initially, QCustomPlot has six layers: “background”, “grid”, “main”, “axes”, “legend” and
“overlay” (in that order). On top is the “overlay” layer, which only contains the QCustomPlot’s
selection rect (\ref QCustomPlot::selectionRect). The next two layers “axes” and “legend” contain
the default axes and legend, so they will be drawn above plottables. In the middle, there is the
“main” layer. It is initially empty and set as the current layer (see
QCustomPlot::setCurrentLayer). This means, all new plottables, items etc. are created on this
layer by default. Then comes the “grid” layer which contains the QCPGrid instances (which belong
tightly to QCPAxis, see \ref QCPAxis::grid). The Axis rect background shall be drawn behind
everything else, thus the default QCPAxisRect instance is placed on the “background” layer. Of
course, the layer affiliation of the individual objects can be changed as required (\ref
QCPLayerable::setLayer).

\section qcplayer-ordering Controlling the rendering order via layers

Controlling the ordering of layerables in the plot is easy: Create a new layer in the position
you want the layerable to be in, e.g. above “main”, with \ref QCustomPlot::addLayer. Then set the
current layer with \ref QCustomPlot::setCurrentLayer to that new layer and finally create the
objects normally. They will be placed on the new layer automatically, due to the current layer
setting. Alternatively you could have also ignored the current layer setting and just moved the
objects with \ref QCPLayerable::setLayer to the desired layer after creating them.

It is also possible to move whole layers. For example, If you want the grid to be shown in front
of all plottables/items on the “main” layer, just move it above “main” with
QCustomPlot::moveLayer.

The rendering order within one layer is simply by order of creation or insertion. The item
created last (or added last to the layer), is drawn on top of all other objects on that layer.

When a layer is deleted, the objects on it are not deleted with it, but fall on the layer below
the deleted layer, see QCustomPlot::removeLayer.

\section qcplayer-buffering Replotting only a specific layer

If the layer mode (\ref setMode) is set to \ref lmBuffered, you can replot only this specific
layer by calling \ref replot. In certain situations this can provide better replot performance,
compared with a full replot of all layers. Upon creation of a new layer, the layer mode is
initialized to \ref lmLogical. The only layer that is set to \ref lmBuffered in a new \ref
QCustomPlot instance is the “overlay” layer, containing the selection rect.
*/

QCustomPlot

构成

QCPLayer

background: defaultAxisRect.
grid: xAxis->grid(), yAxis->grid(), xAxis2->grid(), yAxis2->grid().
main: mPlotLayout.
axes: 坐标轴xAxis, yAxis, xAxis2, yAxis2.
legend: legend.
overlay: mSelectionRect.

QCPGraph

QCPAxis

绘制流程

void QCustomPlot::replot(QCustomPlot::RefreshPriority)
virtual void QCPAxisRect::draw(QCPPainter*)
virtual void QCPGraph::draw(QCPPainter*)
virtual void QCPAxis::draw(QCPPainter*)
virtual void QCPAxis::draw(QCPPainter*)
void QCustomPlot::drawBackground(QCPPainter*)
void QCustomPlot::drawBackground(QCPPainter*)

交互方式

模式

enum Interaction { iRangeDrag         = 0x001 ///< <tt>0x001</tt> Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes),iRangeZoom        = 0x002 ///< <tt>0x002</tt> Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes),iMultiSelect      = 0x004 ///< <tt>0x004</tt> The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking,iSelectPlottables = 0x008 ///< <tt>0x008</tt> Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable),iSelectAxes       = 0x010 ///< <tt>0x010</tt> Axes are selectable (or parts of them, see QCPAxis::setSelectableParts),iSelectLegend     = 0x020 ///< <tt>0x020</tt> Legends are selectable (or their child items, see QCPLegend::setSelectableParts),iSelectItems      = 0x040 ///< <tt>0x040</tt> Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem),iSelectOther      = 0x080 ///< <tt>0x080</tt> All other objects are selectable (e.g. your own derived layerables, other layout elements,...)};

流程

矩形选择模式

模式

流程

QCustomPlot::mousePressEvent
QCustomPlot::mouseMoveEvent
QCustomPlot::mouseReleaseEvent
QCustomPlot::processPointSelection //处理选择
QCPAbstractPlottable::selectEvent
QCPAbstractPlottable::setSelectionQCustomPlot::replotQCPGraph::draw: 选择的部分和未选择的部分颜色不一样QCPAbstractPlottable1D<DataType>::getDataSegmentsQCPSelectionDecorator::applyBrush

成员变量

mLayers

QList<QCPLayer*> mLayers;

mGraphs

QList<QCPGraph*> mGraphs;

mCurrentLayer

QCPLayer *mCurrentLayer;

mPlottables

QList<QCPAbstractPlottable*> mPlottables;

xAxis, yAxis, xAxis2, yAxis2

 QCPAxis *xAxis, *yAxis, *xAxis2, *yAxis2;

mInteractions 交互方式

QCP::Interactions mInteractions;
enum Interaction { iRangeDrag         = 0x001 ///< <tt>0x001</tt> Axis ranges are draggable (see \ref QCPAxisRect::setRangeDrag, \ref QCPAxisRect::setRangeDragAxes),iRangeZoom        = 0x002 ///< <tt>0x002</tt> Axis ranges are zoomable with the mouse wheel (see \ref QCPAxisRect::setRangeZoom, \ref QCPAxisRect::setRangeZoomAxes),iMultiSelect      = 0x004 ///< <tt>0x004</tt> The user can select multiple objects by holding the modifier set by \ref QCustomPlot::setMultiSelectModifier while clicking,iSelectPlottables = 0x008 ///< <tt>0x008</tt> Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable),iSelectAxes       = 0x010 ///< <tt>0x010</tt> Axes are selectable (or parts of them, see QCPAxis::setSelectableParts),iSelectLegend     = 0x020 ///< <tt>0x020</tt> Legends are selectable (or their child items, see QCPLegend::setSelectableParts),iSelectItems      = 0x040 ///< <tt>0x040</tt> Items are selectable (Rectangles, Arrows, Textitems, etc. see \ref QCPAbstractItem),iSelectOther      = 0x080 ///< <tt>0x080</tt> All other objects are selectable (e.g. your own derived layerables, other layout elements,...)};

mSelectionRectMode 矩形选择模式

QCP::SelectionRectMode mSelectionRectModeenum SelectionRectMode { srmNone    ///< The selection rect is disabled, and all mouse events are forwarded to the underlying objects, e.g. for axis range dragging,srmZoom   ///< When dragging the mouse, a selection rect becomes active. Upon releasing, the axes that are currently set as range zoom axes (\ref QCPAxisRect::setRangeZoomAxes) will have their ranges zoomed accordingly.,srmSelect ///< When dragging the mouse, a selection rect becomes active. Upon releasing, plottable data points that were within the selection rect are selected, if the plottable's selectability setting permits. (See  \ref dataselection "data selection mechanism" for details.),srmCustom ///< When dragging the mouse, a selection rect becomes active. It is the programmer's responsibility to connect according slots to the selection rect's signals (e.g. \ref QCPSelectionRect::accepted) in order to process the user interaction.};

mMousePressPos

QPoint mMousePressPos; //鼠标按下的位置

事件

paintEvent

void QCustomPlot::paintEvent(QPaintEvent *event)
{Q_UNUSED(event);QCPPainter painter(this);if (painter.isActive()){painter.setRenderHint(QPainter::HighQualityAntialiasing); // to make Antialiasing look good if using the OpenGL graphicssystemif (mBackgroundBrush.style() != Qt::NoBrush)painter.fillRect(mViewport, mBackgroundBrush);drawBackground(&painter);for (int bufferIndex = 0; bufferIndex < mPaintBuffers.size(); ++bufferIndex)mPaintBuffers.at(bufferIndex)->draw(&painter);}
}
/*
QList<QSharedPointer<QCPAbstractPaintBuffer> > mPaintBuffers;
/

mousePressEvent

void QCustomPlot::mousePressEvent(QMouseEvent *event)
{emit mousePress(event);// save some state to tell in releaseEvent whether it was a click:mMouseHasMoved = false;mMousePressPos = event->pos();if (mSelectionRect && mSelectionRectMode != QCP::srmNone){if (mSelectionRectMode != QCP::srmZoom || qobject_cast<QCPAxisRect*>(axisRectAt(mMousePressPos))) // in zoom mode only activate selection rect if on an axis rectmSelectionRect->startSelection(event);} else{// no selection rect interaction, prepare for click signal emission and forward event to layerable under the cursor:QList<QVariant> details;QList<QCPLayerable*> candidates = layerableListAt(mMousePressPos, false, &details);if (!candidates.isEmpty()){mMouseSignalLayerable = candidates.first(); // candidate for signal emission is always topmost hit layerable (signal emitted in release event)mMouseSignalLayerableDetails = details.first();}// forward event to topmost candidate which accepts the event:for (int i=0; i<candidates.size(); ++i){event->accept(); // default impl of QCPLayerable's mouse events call ignore() on the event, in that case propagate to next candidate in listcandidates.at(i)->mousePressEvent(event, details.at(i));if (event->isAccepted()){mMouseEventLayerable = candidates.at(i);mMouseEventLayerableDetails = details.at(i);break;}}}event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event.
}

mouseMoveEvent

void QCustomPlot::mouseMoveEvent(QMouseEvent *event)
{emit mouseMove(event);if (!mMouseHasMoved && (mMousePressPos-event->pos()).manhattanLength() > 3)mMouseHasMoved = true; // moved too far from mouse press position, don't handle as click on mouse releaseif (mSelectionRect && mSelectionRect->isActive())mSelectionRect->moveSelection(event);else if (mMouseEventLayerable) // call event of affected layerable:mMouseEventLayerable->mouseMoveEvent(event, mMousePressPos);event->accept(); // in case QCPLayerable reimplementation manipulates event accepted state. In QWidget event system, QCustomPlot wants to accept the event.
}

mouseReleaseEvent

void QCustomPlot::mouseReleaseEvent(QMouseEvent *event)
{emit mouseRelease(event);if (!mMouseHasMoved) // mouse hasn't moved (much) between press and release, so handle as click{if (mSelectionRect && mSelectionRect->isActive()) // a simple click shouldn't successfully finish a selection rect, so cancel it heremSelectionRect->cancel();if (event->button() == Qt::LeftButton)processPointSelection(event);// emit specialized click signals of QCustomPlot instance:if (QCPAbstractPlottable *ap = qobject_cast<QCPAbstra

这篇关于QCustomPlot 2.0.1 源码分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1029850

相关文章

Springboot中分析SQL性能的两种方式详解

《Springboot中分析SQL性能的两种方式详解》文章介绍了SQL性能分析的两种方式:MyBatis-Plus性能分析插件和p6spy框架,MyBatis-Plus插件配置简单,适用于开发和测试环... 目录SQL性能分析的两种方式:功能介绍实现方式:实现步骤:SQL性能分析的两种方式:功能介绍记录

最长公共子序列问题的深度分析与Java实现方式

《最长公共子序列问题的深度分析与Java实现方式》本文详细介绍了最长公共子序列(LCS)问题,包括其概念、暴力解法、动态规划解法,并提供了Java代码实现,暴力解法虽然简单,但在大数据处理中效率较低,... 目录最长公共子序列问题概述问题理解与示例分析暴力解法思路与示例代码动态规划解法DP 表的构建与意义动

C#使用DeepSeek API实现自然语言处理,文本分类和情感分析

《C#使用DeepSeekAPI实现自然语言处理,文本分类和情感分析》在C#中使用DeepSeekAPI可以实现多种功能,例如自然语言处理、文本分类、情感分析等,本文主要为大家介绍了具体实现步骤,... 目录准备工作文本生成文本分类问答系统代码生成翻译功能文本摘要文本校对图像描述生成总结在C#中使用Deep

Go中sync.Once源码的深度讲解

《Go中sync.Once源码的深度讲解》sync.Once是Go语言标准库中的一个同步原语,用于确保某个操作只执行一次,本文将从源码出发为大家详细介绍一下sync.Once的具体使用,x希望对大家有... 目录概念简单示例源码解读总结概念sync.Once是Go语言标准库中的一个同步原语,用于确保某个操

Redis主从/哨兵机制原理分析

《Redis主从/哨兵机制原理分析》本文介绍了Redis的主从复制和哨兵机制,主从复制实现了数据的热备份和负载均衡,而哨兵机制可以监控Redis集群,实现自动故障转移,哨兵机制通过监控、下线、选举和故... 目录一、主从复制1.1 什么是主从复制1.2 主从复制的作用1.3 主从复制原理1.3.1 全量复制

Redis主从复制的原理分析

《Redis主从复制的原理分析》Redis主从复制通过将数据镜像到多个从节点,实现高可用性和扩展性,主从复制包括初次全量同步和增量同步两个阶段,为优化复制性能,可以采用AOF持久化、调整复制超时时间、... 目录Redis主从复制的原理主从复制概述配置主从复制数据同步过程复制一致性与延迟故障转移机制监控与维

Redis连接失败:客户端IP不在白名单中的问题分析与解决方案

《Redis连接失败:客户端IP不在白名单中的问题分析与解决方案》在现代分布式系统中,Redis作为一种高性能的内存数据库,被广泛应用于缓存、消息队列、会话存储等场景,然而,在实际使用过程中,我们可能... 目录一、问题背景二、错误分析1. 错误信息解读2. 根本原因三、解决方案1. 将客户端IP添加到Re

Java汇编源码如何查看环境搭建

《Java汇编源码如何查看环境搭建》:本文主要介绍如何在IntelliJIDEA开发环境中搭建字节码和汇编环境,以便更好地进行代码调优和JVM学习,首先,介绍了如何配置IntelliJIDEA以方... 目录一、简介二、在IDEA开发环境中搭建汇编环境2.1 在IDEA中搭建字节码查看环境2.1.1 搭建步

Redis主从复制实现原理分析

《Redis主从复制实现原理分析》Redis主从复制通过Sync和CommandPropagate阶段实现数据同步,2.8版本后引入Psync指令,根据复制偏移量进行全量或部分同步,优化了数据传输效率... 目录Redis主DodMIK从复制实现原理实现原理Psync: 2.8版本后总结Redis主从复制实

锐捷和腾达哪个好? 两个品牌路由器对比分析

《锐捷和腾达哪个好?两个品牌路由器对比分析》在选择路由器时,Tenda和锐捷都是备受关注的品牌,各自有独特的产品特点和市场定位,选择哪个品牌的路由器更合适,实际上取决于你的具体需求和使用场景,我们从... 在选购路由器时,锐捷和腾达都是市场上备受关注的品牌,但它们的定位和特点却有所不同。锐捷更偏向企业级和专