summaryrefslogtreecommitdiffstats
path: root/examples/charts/chartsgallery/candlestickdatareader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/charts/chartsgallery/candlestickdatareader.cpp')
-rw-r--r--examples/charts/chartsgallery/candlestickdatareader.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/examples/charts/chartsgallery/candlestickdatareader.cpp b/examples/charts/chartsgallery/candlestickdatareader.cpp
new file mode 100644
index 00000000..3913e3bd
--- /dev/null
+++ b/examples/charts/chartsgallery/candlestickdatareader.cpp
@@ -0,0 +1,58 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include "candlestickdatareader.h"
+
+#include <QCandlestickSet>
+
+CandlestickDataReader::CandlestickDataReader(QIODevice *device)
+ : m_textStream(device)
+{
+}
+
+CandlestickDataReader::~CandlestickDataReader()
+{
+}
+
+void CandlestickDataReader::readFile(QIODevice *device)
+{
+ m_textStream.setDevice(device);
+}
+
+QCandlestickSet *CandlestickDataReader::readCandlestickSet()
+{
+ //! [1]
+ QString line = m_textStream.readLine();
+ if (line.startsWith("#") || line.isEmpty())
+ return nullptr;
+ //! [1]
+
+ //! [2]
+ QStringList strList = line.split(QLatin1Char(' '), Qt::SkipEmptyParts);
+ if (strList.count() != 5)
+ return nullptr;
+ //! [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]
+ auto candlestickSet = new QCandlestickSet(timestamp);
+ candlestickSet->setOpen(open);
+ candlestickSet->setHigh(high);
+ candlestickSet->setLow(low);
+ candlestickSet->setClose(close);
+ //! [4]
+
+ return candlestickSet;
+}
+
+bool CandlestickDataReader::atEnd() const
+{
+ return m_textStream.atEnd();
+}