1/*
2 * This file is part of KQuickCharts
3 * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7
8#include "ArraySource.h"
9
10ArraySource::ArraySource(QObject *parent)
11 : ChartDataSource(parent)
12{
13}
14
15int ArraySource::itemCount() const
16{
17 return m_array.count();
18}
19
20QVariant ArraySource::item(int index) const
21{
22 if (!m_wrap && (index < 0 || index > m_array.count() - 1)) {
23 return {};
24 }
25
26 return m_array.at(i: index % m_array.count());
27}
28
29QVariant ArraySource::minimum() const
30{
31 auto itr = std::min_element(first: m_array.cbegin(), last: m_array.cend(), comp: variantCompare);
32 if (itr != m_array.cend()) {
33 return *itr;
34 }
35 return QVariant{};
36}
37
38QVariant ArraySource::maximum() const
39{
40 auto itr = std::max_element(first: m_array.cbegin(), last: m_array.cend(), comp: variantCompare);
41 if (itr != m_array.cend()) {
42 return *itr;
43 }
44 return QVariant{};
45}
46
47QVariantList ArraySource::array() const
48{
49 return m_array;
50}
51
52bool ArraySource::wrap() const
53{
54 return m_wrap;
55}
56
57void ArraySource::setArray(const QVariantList &array)
58{
59 if (m_array == array) {
60 return;
61 }
62
63 m_array = array;
64 Q_EMIT dataChanged();
65}
66
67void ArraySource::setWrap(bool wrap)
68{
69 if (m_wrap == wrap) {
70 return;
71 }
72
73 m_wrap = wrap;
74 Q_EMIT dataChanged();
75}
76
77#include "moc_ArraySource.cpp"
78

source code of kquickcharts/src/datasource/ArraySource.cpp