QHash<QPointF, QVector<float>> data;函數
此時會報錯說沒有聲明QPointF的Key類型ui
須要咱們手動實現一個函數spa
static uint qHash(const QPointF& key, uint seed) {
int val = static_cast<int>(key.x());
return qHash<int>(val, seed);
}get
數據的插入,插入QHash<QPointF, QVector<float>>類型的數據it
data.insert(QPointF(0.0, 1.0), {0.0, 0.3, 0.7, 1.0});
data.insert(QPointF(1.0, 2.0), {0.0, 0.7, 1.3, 2.0});
data.insert(QPointF(2.0, 4.0), {0.0, 1.3, 2.7, 4.0});
data.insert(QPointF(4.0, 6.0), {0.0, 2.0, 4.0, 6.0});ast
數據的查找 輸入一個浮點型數,判斷這個浮點型數在不在Key的區間,若是在,就返回Valuefloat
QVector<float> ClassName::getDataValue(qreal maxValue, QHash<QPointF, QVector<float>> &data) {
for (QHash<QPointF, QVector<float>>::iterator it = data.begin(); it != data.end(); ++it) {
if ((it.key().x() < maxValue) && (maxValue < it.key().y() + FLOAT_ACCURACY)) {
return it.value();
}
}
return QVector<float>();
}數據
FLOAT_ACCURACY:0.00001;用來浮點型數據的比較static