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#ifndef ARRAYSOURCE_H
9#define ARRAYSOURCE_H
10
11#include <QVariantList>
12
13#include "ChartDataSource.h"
14
15/*!
16 * \qmltype ArraySource
17 * \inherits ChartDataSource
18 * \inqmlmodule org.kde.quickcharts
19 *
20 * \brief A data source that provides entries of an array as data.
21 */
22class QUICKCHARTS_EXPORT ArraySource : public ChartDataSource
23{
24 Q_OBJECT
25 QML_ELEMENT
26
27public:
28 explicit ArraySource(QObject *parent = nullptr);
29
30 /*!
31 * \qmlproperty list<variant> ArraySource::array
32 *
33 * \brief The array to use to provide entries from.
34 */
35 Q_PROPERTY(QVariantList array READ array WRITE setArray NOTIFY dataChanged)
36 QVariantList array() const;
37 void setArray(const QVariantList &array);
38
39 /*!
40 * \qmlproperty bool ArraySource::wrap
41 *
42 * \brief Wraparound when indexing past the array's bounds.
43 *
44 * If true, when an item is requested at an index outside of the array's
45 * bounds, wrap around to the start or end of the array and continue from
46 * there. This ensures we always return an entry from the array.
47 *
48 * If false (the default), requesting an item at an index outside of the
49 * array's'bounds, we return an empty item instead.
50 */
51 Q_PROPERTY(bool wrap READ wrap WRITE setWrap NOTIFY dataChanged)
52 bool wrap() const;
53 void setWrap(bool wrap);
54
55 int itemCount() const override;
56 QVariant item(int index) const override;
57 QVariant minimum() const override;
58 QVariant maximum() const override;
59
60private:
61 QVariantList m_array;
62 bool m_wrap = false;
63};
64
65#endif // ARRAYSOURCE_H
66

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