KQuickCharts

ArraySource.cpp
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
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_array.isEmpty()) {
23 return {};
24 }
25
26 if (!m_wrap && (index < 0 || index > m_array.count() - 1)) {
27 return {};
28 }
29
30 return m_array.at(index % m_array.count());
31}
32
33QVariant ArraySource::minimum() const
34{
35 auto itr = std::min_element(m_array.cbegin(), m_array.cend(), variantCompare);
36 if (itr != m_array.cend()) {
37 return *itr;
38 }
39 return QVariant{};
40}
41
42QVariant ArraySource::maximum() const
43{
44 auto itr = std::max_element(m_array.cbegin(), m_array.cend(), variantCompare);
45 if (itr != m_array.cend()) {
46 return *itr;
47 }
48 return QVariant{};
49}
50
51QVariantList ArraySource::array() const
52{
53 return m_array;
54}
55
56bool ArraySource::wrap() const
57{
58 return m_wrap;
59}
60
61void ArraySource::setArray(const QVariantList &array)
62{
63 if (m_array == array) {
64 return;
65 }
66
67 m_array = array;
68 Q_EMIT dataChanged();
69}
70
71void ArraySource::setWrap(bool wrap)
72{
73 if (m_wrap == wrap) {
74 return;
75 }
76
77 m_wrap = wrap;
78 Q_EMIT dataChanged();
79}
80
81#include "moc_ArraySource.cpp"
ArraySource(QObject *parent=nullptr)
Constructor.
Abstract base class for data sources.
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:53 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.