| 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 | * \qmltype MapProxySource |
| 15 | * \inherits ChartDataSource |
| 16 | * \inqmlmodule org.kde.quickcharts |
| 17 | * |
| 18 | * \brief A source that uses the values of another source to produce values from a map. |
| 19 | * |
| 20 | * This source reads values from another source, then uses those as an index to |
| 21 | * a map of different values and returns the appropriate value from that map. |
| 22 | * This source's itemCount matches that of the other source. |
| 23 | */ |
| 24 | class QUICKCHARTS_EXPORT MapProxySource : public ChartDataSource |
| 25 | { |
| 26 | Q_OBJECT |
| 27 | QML_ELEMENT |
| 28 | |
| 29 | public: |
| 30 | MapProxySource(QObject *parent = nullptr); |
| 31 | |
| 32 | /*! |
| 33 | * \qmlproperty ChartDataSource MapProxySource::source |
| 34 | * \brief A ChartDataSource that is used as map indexes. |
| 35 | */ |
| 36 | Q_PROPERTY(ChartDataSource *source READ source WRITE setSource NOTIFY sourceChanged) |
| 37 | ChartDataSource *source() const; |
| 38 | void setSource(ChartDataSource *newSource); |
| 39 | Q_SIGNAL void sourceChanged(); |
| 40 | |
| 41 | /*! |
| 42 | * \qmlproperty QVariantMap MapProxySource::map |
| 43 | * \brief The map to index for values. |
| 44 | */ |
| 45 | Q_PROPERTY(QVariantMap map READ map WRITE setMap NOTIFY mapChanged) |
| 46 | QVariantMap map() const; |
| 47 | void setMap(const QVariantMap &newMap); |
| 48 | Q_SIGNAL void mapChanged(); |
| 49 | |
| 50 | int itemCount() const override; |
| 51 | QVariant item(int index) const override; |
| 52 | QVariant minimum() const override; |
| 53 | QVariant maximum() const override; |
| 54 | |
| 55 | private: |
| 56 | ChartDataSource *m_source = nullptr; |
| 57 | QVariantMap m_map; |
| 58 | }; |
| 59 | |