blob: 7b32cf4749407cf857a912a971a185ede818bd91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "candlestickdatareader.h"
CandlestickDataReader::CandlestickDataReader(QIODevice *device)
: QTextStream(device)
{
}
CandlestickDataReader::~CandlestickDataReader()
{
}
void CandlestickDataReader::readFile(QIODevice *device)
{
QTextStream::setDevice(device);
}
QCandlestickSet *CandlestickDataReader::readCandlestickSet()
{
//! [1]
QString line = readLine();
if (line.startsWith("#") || line.isEmpty())
return 0;
//! [1]
//! [2]
QStringList strList = line.split(QLatin1Char(' '), Qt::SkipEmptyParts);
if (strList.count() != 5)
return 0;
//! [2]
//! [3]
const qreal timestamp = strList.at(0).toDouble();
const qreal open = strList.at(1).toDouble();
const qreal high = strList.at(2).toDouble();
const qreal low = strList.at(3).toDouble();
const qreal close = strList.at(4).toDouble();
//! [3]
//! [4]
QCandlestickSet *candlestickSet = new QCandlestickSet(timestamp);
candlestickSet->setOpen(open);
candlestickSet->setHigh(high);
candlestickSet->setLow(low);
candlestickSet->setClose(close);
//! [4]
return candlestickSet;
}
|