KQuickCharts

MapProxySource.cpp
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#include "MapProxySource.h"
8
9MapProxySource::MapProxySource(QObject *parent)
10 : ChartDataSource(parent)
11{
12 connect(this, &MapProxySource::sourceChanged, this, &ChartDataSource::dataChanged);
13 connect(this, &MapProxySource::mapChanged, this, &ChartDataSource::dataChanged);
14}
15
16int MapProxySource::itemCount() const
17{
18 if (m_source) {
19 return m_source->itemCount();
20 }
21
22 return 0;
23}
24
25QVariant MapProxySource::minimum() const
26{
27 auto itr = std::min_element(m_map.cbegin(), m_map.cend(), variantCompare);
28 if (itr != m_map.cend()) {
29 return *itr;
30 }
31 return QVariant{};
32}
33
34QVariant MapProxySource::maximum() const
35{
36 auto itr = std::max_element(m_map.cbegin(), m_map.cend(), variantCompare);
37 if (itr != m_map.cend()) {
38 return *itr;
39 }
40 return QVariant{};
41}
42
43QVariant MapProxySource::item(int index) const
44{
45 if (!m_source) {
46 return QVariant{};
47 }
48
49 auto mapIndex = m_source->item(index).toString();
50 if (mapIndex.isEmpty()) {
51 return QVariant{};
52 }
53
54 return m_map.value(mapIndex);
55}
56
58{
59 return m_source;
60}
61
62void MapProxySource::setSource(ChartDataSource *newSource)
63{
64 if (newSource == m_source) {
65 return;
66 }
67
68 if (m_source) {
69 m_source->disconnect(this);
70 }
71
72 m_source = newSource;
73 if (m_source) {
74 connect(m_source, &ChartDataSource::dataChanged, this, &ChartDataSource::dataChanged);
75 }
76 Q_EMIT sourceChanged();
77}
78
79QVariantMap MapProxySource::map() const
80{
81 return m_map;
82}
83
84void MapProxySource::setMap(const QVariantMap &newMap)
85{
86 if (newMap == m_map) {
87 return;
88 }
89
90 m_map = newMap;
91
92 Q_EMIT mapChanged();
93}
94
95#include "moc_MapProxySource.cpp"
Abstract base class for data sources.
ChartDataSource * source
A ChartDataSource that is used as map indexes.
QVariantMap map
The map to index for values.
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:23 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.