详细说明
template <class DataType>
class QCPDataContainer <DataType>
一维绘图表的通用数据容器。
该类模板为一维数据的数据存储提供了一个快速的容器。数据类型被指定为模板参数(称为数据类型在下面),并且必须提供如在所描述的一些方法中下一节。
数据以排序的方式存储,它允许通过排序的键进行非常快速的查找,以及使用二进制搜索来检索范围(请参阅findBegin,findEnd,keyRange)。容器使用预分配和后分配方案,因此添加和添加数据(相对于排序键)非常快,并且可以最大程度地减少重新分配。如果添加了需要在现有键之间插入的数据,通常也可以对现有数据进行排序,因此合并操作通常也可以很快完成。如果用户可以保证确实是这种情况,则可以通过指定添加的数据本身已经按键排序来进一步提高性能(例如,请参见add(const QVector <DataType>&data,bool hasSorted))。
可以使用提供的const迭代器(constBegin,constEnd)访问数据。如果有必要就地更改现有数据,则可以使用非常量迭代器(begin,end)。从容器的角度来看,更改不是排序键的数据成员(对于大多数数据类型称为key)是安全的。
但是,如果通过非常量迭代器修改了排序键,则必须格外小心。出于性能方面的考虑,迭代器不会在对其进行操作时自动进行重新排序。因此,用户有责任在完成数据操作之后,在调用容器上的任何其他方法之前,将容器保持在已排序状态。可以通过调用sort来完成完整的重新排序(例如,在完成所有排序键操作之后)。容器无法有效地检测到失败的情况,这将导致渲染伪像和潜在的数据丢失。
通常,通过QCPAbstractPlottable1D <T>的子类来实现利用QCPDataContainer <T>的一维绘图表,该子类引入了相应的mDataContainer成员和一些便捷方法。
DataType模板参数的要求
template参数
DataType
是存储的数据点的类型。它必须是可复制的,并且具有以下公共方法,最好是内联:
-
返回此数据点的成员变量,该成员变量是排序键,用于定义容器中的排序。通常,此变量简称为key。double sortKey() const
-
返回数据类型的新实例,该实例的排序键设置为sortKey。static DataType fromSortKey(double sortKey)
-
如果排序键等于主键,则返回true(请参见static bool sortKeyIsMainKey()
下面的方法)。对于大多数绘图表,情况就是这样。例如,对于QCPCurve则不是这种情况,它使用t作为排序键,而key作为主键。这就是为什么QCPCurve不同于QCPGraph可以显示带有循环的参数曲线的原因。mainKey
-
返回被视为主键的该数据点的变量。这通常是用作此数据点在绘图表关键轴上的坐标的变量。例如,在确定关键轴的自动轴缩放比例(QCPAxis :: rescale)时使用此方法。double mainKey() const
-
返回此数据点的变量,该变量被视为主要值。这通常是用作此数据点在绘图表的值轴上的坐标的变量。double mainValue() const
-
返回此数据点在值轴坐标中跨越的范围。如果数据是单值数据(例如QCPGraphData),则这仅仅是将上限和下限设置为主数据点值的范围。但是,如果数据点可以一次表示多个值(例如,QCPFinancialData在每个键处具有高,低,打开和关闭值),则此方法应返回这些值所覆盖的范围。例如,在确定值轴的自动轴缩放比例(QCPAxis :: rescale)时使用此方法。QCPRange valueRange() const
Public Types | |
typedef QVector< DataType >::const_iterator | const_iterator |
typedef QVector< DataType >::iterator | iterator |
Public Functions | |
QCPDataContainer () | |
int | size () const |
bool | isEmpty () const |
bool | autoSqueeze () const |
void | setAutoSqueeze (bool enabled) |
void | set (const QCPDataContainer< DataType > &data) |
void | set (const QVector< DataType > &data, bool alreadySorted=false) |
void | add (const QCPDataContainer< DataType > &data) |
void | add (const QVector< DataType > &data, bool alreadySorted=false) |
void | add (const DataType &data) |
void | removeBefore (double sortKey) |
void | removeAfter (double sortKey) |
void | remove (double sortKeyFrom, double sortKeyTo) |
void | remove (double sortKey) |
void | clear () |
void | sort () |
void | squeeze (bool preAllocation=true, bool postAllocation=true) |
const_iterator | constBegin () const |
const_iterator | constEnd () const |
iterator | begin () |
iterator | end () |
const_iterator | findBegin (double sortKey, bool expandedRange=true) const |
const_iterator | findEnd (double sortKey, bool expandedRange=true) const |
const_iterator | at (int index) const |
QCPRange | keyRange (bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth) |
QCPRange | valueRange (bool &foundRange, QCP::SignDomain signDomain=QCP::sdBoth, const QCPRange &inKeyRange=QCPRange()) |
QCPDataRange | dataRange () const |
void | limitIteratorsToDataRange (const_iterator &begin, const_iterator &end, const QCPDataRange &dataRange) const |
Protected Functions | |
void | preallocateGrow (int minimumPreallocSize) |
void | performAutoSqueeze () |
Related Non-Members | |
(Note that these are not member functions.) | |
template<class DataType > | |
bool | qcpLessThanSortKey (const DataType &a, const DataType &b) |