File indexing completed on 2024-05-05 07:58:32

0001 /*
0002  * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005  */
0006 
0007 #pragma once
0008 
0009 #include "ChartDataSource.h"
0010 
0011 #include <QVariant>
0012 
0013 /**
0014  * A source that uses the values of another source to produce values from a map.
0015  *
0016  * This source reads values from another source, then uses those as an index to
0017  * a map of different values and returns the appropriate value from that map.
0018  * This source's itemCount matches that of the other source.
0019  *
0020  * @since 5.71
0021  */
0022 class QUICKCHARTS_EXPORT MapProxySource : public ChartDataSource
0023 {
0024     Q_OBJECT
0025     QML_ELEMENT
0026 
0027 public:
0028     MapProxySource(QObject *parent = nullptr);
0029 
0030     /**
0031      * A ChartDataSource that is used as map indexes.
0032      */
0033     Q_PROPERTY(ChartDataSource *source READ source WRITE setSource NOTIFY sourceChanged)
0034     ChartDataSource *source() const;
0035     void setSource(ChartDataSource *newSource);
0036     Q_SIGNAL void sourceChanged();
0037 
0038     /**
0039      * The map to index for values.
0040      */
0041     Q_PROPERTY(QVariantMap map READ map WRITE setMap NOTIFY mapChanged)
0042     QVariantMap map() const;
0043     void setMap(const QVariantMap &newMap);
0044     Q_SIGNAL void mapChanged();
0045 
0046     virtual int itemCount() const override;
0047     virtual QVariant item(int index) const override;
0048     virtual QVariant minimum() const override;
0049     virtual QVariant maximum() const override;
0050 
0051 private:
0052     ChartDataSource *m_source = nullptr;
0053     QVariantMap m_map;
0054 };