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

相关文章

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置

JAVA智听未来一站式有声阅读平台听书系统小程序源码

智听未来,一站式有声阅读平台听书系统 🌟&nbsp;开篇:遇见未来,从“智听”开始 在这个快节奏的时代,你是否渴望在忙碌的间隙,找到一片属于自己的宁静角落?是否梦想着能随时随地,沉浸在知识的海洋,或是故事的奇幻世界里?今天,就让我带你一起探索“智听未来”——这一站式有声阅读平台听书系统,它正悄悄改变着我们的阅读方式,让未来触手可及! 📚&nbsp;第一站:海量资源,应有尽有 走进“智听

Java ArrayList扩容机制 (源码解读)

结论:初始长度为10,若所需长度小于1.5倍原长度,则按照1.5倍扩容。若不够用则按照所需长度扩容。 一. 明确类内部重要变量含义         1:数组默认长度         2:这是一个共享的空数组实例,用于明确创建长度为0时的ArrayList ,比如通过 new ArrayList<>(0),ArrayList 内部的数组 elementData 会指向这个 EMPTY_EL

如何在Visual Studio中调试.NET源码

今天偶然在看别人代码时,发现在他的代码里使用了Any判断List<T>是否为空。 我一般的做法是先判断是否为null,再判断Count。 看了一下Count的源码如下: 1 [__DynamicallyInvokable]2 public int Count3 {4 [__DynamicallyInvokable]5 get

SWAP作物生长模型安装教程、数据制备、敏感性分析、气候变化影响、R模型敏感性分析与贝叶斯优化、Fortran源代码分析、气候数据降尺度与变化影响分析

查看原文>>>全流程SWAP农业模型数据制备、敏感性分析及气候变化影响实践技术应用 SWAP模型是由荷兰瓦赫宁根大学开发的先进农作物模型,它综合考虑了土壤-水分-大气以及植被间的相互作用;是一种描述作物生长过程的一种机理性作物生长模型。它不但运用Richard方程,使其能够精确的模拟土壤中水分的运动,而且耦合了WOFOST作物模型使作物的生长描述更为科学。 本文让更多的科研人员和农业工作者

MOLE 2.5 分析分子通道和孔隙

软件介绍 生物大分子通道和孔隙在生物学中发挥着重要作用,例如在分子识别和酶底物特异性方面。 我们介绍了一种名为 MOLE 2.5 的高级软件工具,该工具旨在分析分子通道和孔隙。 与其他可用软件工具的基准测试表明,MOLE 2.5 相比更快、更强大、功能更丰富。作为一项新功能,MOLE 2.5 可以估算已识别通道的物理化学性质。 软件下载 https://pan.quark.cn/s/57

工厂ERP管理系统实现源码(JAVA)

工厂进销存管理系统是一个集采购管理、仓库管理、生产管理和销售管理于一体的综合解决方案。该系统旨在帮助企业优化流程、提高效率、降低成本,并实时掌握各环节的运营状况。 在采购管理方面,系统能够处理采购订单、供应商管理和采购入库等流程,确保采购过程的透明和高效。仓库管理方面,实现库存的精准管理,包括入库、出库、盘点等操作,确保库存数据的准确性和实时性。 生产管理模块则涵盖了生产计划制定、物料需求计划、

衡石分析平台使用手册-单机安装及启动

单机安装及启动​ 本文讲述如何在单机环境下进行 HENGSHI SENSE 安装的操作过程。 在安装前请确认网络环境,如果是隔离环境,无法连接互联网时,请先按照 离线环境安装依赖的指导进行依赖包的安装,然后按照本文的指导继续操作。如果网络环境可以连接互联网,请直接按照本文的指导进行安装。 准备工作​ 请参考安装环境文档准备安装环境。 配置用户与安装目录。 在操作前请检查您是否有 sud

线性因子模型 - 独立分量分析(ICA)篇

序言 线性因子模型是数据分析与机器学习中的一类重要模型,它们通过引入潜变量( latent variables \text{latent variables} latent variables)来更好地表征数据。其中,独立分量分析( ICA \text{ICA} ICA)作为线性因子模型的一种,以其独特的视角和广泛的应用领域而备受关注。 ICA \text{ICA} ICA旨在将观察到的复杂信号

Spring 源码解读:自定义实现Bean定义的注册与解析

引言 在Spring框架中,Bean的注册与解析是整个依赖注入流程的核心步骤。通过Bean定义,Spring容器知道如何创建、配置和管理每个Bean实例。本篇文章将通过实现一个简化版的Bean定义注册与解析机制,帮助你理解Spring框架背后的设计逻辑。我们还将对比Spring中的BeanDefinition和BeanDefinitionRegistry,以全面掌握Bean注册和解析的核心原理。