1 | /* |
2 | * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl> |
3 | * |
4 | * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | |
7 | #pragma once |
8 | |
9 | #include "ChartDataSource.h" |
10 | |
11 | #include <QVariant> |
12 | |
13 | /** |
14 | * A source that uses the values of another source to produce values from a map. |
15 | * |
16 | * This source reads values from another source, then uses those as an index to |
17 | * a map of different values and returns the appropriate value from that map. |
18 | * This source's itemCount matches that of the other source. |
19 | * |
20 | * @since 5.71 |
21 | */ |
22 | class QUICKCHARTS_EXPORT MapProxySource : public ChartDataSource |
23 | { |
24 | Q_OBJECT |
25 | QML_ELEMENT |
26 | |
27 | public: |
28 | MapProxySource(QObject *parent = nullptr); |
29 | |
30 | /** |
31 | * A ChartDataSource that is used as map indexes. |
32 | */ |
33 | Q_PROPERTY(ChartDataSource *source READ source WRITE setSource NOTIFY sourceChanged) |
34 | ChartDataSource *source() const; |
35 | void setSource(ChartDataSource *newSource); |
36 | Q_SIGNAL void sourceChanged(); |
37 | |
38 | /** |
39 | * The map to index for values. |
40 | */ |
41 | Q_PROPERTY(QVariantMap map READ map WRITE setMap NOTIFY mapChanged) |
42 | QVariantMap map() const; |
43 | void setMap(const QVariantMap &newMap); |
44 | Q_SIGNAL void mapChanged(); |
45 | |
46 | virtual int itemCount() const override; |
47 | virtual QVariant item(int index) const override; |
48 | virtual QVariant minimum() const override; |
49 | virtual QVariant maximum() const override; |
50 | |
51 | private: |
52 | ChartDataSource *m_source = nullptr; |
53 | QVariantMap m_map; |
54 | }; |
55 | |