KQuickCharts

LegendModel.h
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 LEGENDMODEL_H
9#define LEGENDMODEL_H
10
11#include <vector>
12
13#include <QAbstractListModel>
14#include <QColor>
15#include <qqmlregistration.h>
16
17class Chart;
18class ChartDataSource;
19
20struct LegendItem {
21 QString name;
22 QString shortName;
23 QColor color;
24 QVariant value;
25};
26
27/**
28 * A model that extracts information from a chart that can be displayed as a legend.
29 */
31{
33 QML_ELEMENT
34
35public:
36 enum Roles { NameRole = Qt::UserRole, ShortNameRole, ColorRole, ValueRole };
37
38 enum SourceIndex { UseSourceCount = -2 };
39 Q_ENUM(SourceIndex)
40
41 explicit LegendModel(QObject *parent = nullptr);
42
43 Q_PROPERTY(Chart *chart READ chart WRITE setChart NOTIFY chartChanged)
44 Chart *chart() const;
45 void setChart(Chart *newChart);
46 Q_SIGNAL void chartChanged();
47
48 Q_PROPERTY(int sourceIndex READ sourceIndex WRITE setSourceIndex NOTIFY sourceIndexChanged)
49 int sourceIndex() const;
50 void setSourceIndex(int index);
51 Q_SIGNAL void sourceIndexChanged();
52
53 QHash<int, QByteArray> roleNames() const override;
54 int rowCount(const QModelIndex &parent) const override;
55 QVariant data(const QModelIndex &index, int role) const override;
56
57private:
58 void queueUpdate();
59 void queueDataChange();
60 void update();
61 void updateData();
62 int countItems();
63 QVariant getValueForItem(int item);
64
65 Chart *m_chart = nullptr;
66 int m_sourceIndex = UseSourceCount;
67 bool m_updateQueued = false;
68 bool m_dataChangeQueued = false;
69 std::vector<QMetaObject::Connection> m_connections;
70 std::vector<LegendItem> m_items;
71};
72
73#endif // LEGENDMODEL_H
Abstract base class for data sources.
Abstract base class for all charts.
Definition Chart.h:22
A model that extracts information from a chart that can be displayed as a legend.
Definition LegendModel.h:31
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
Q_ENUM(...)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALQ_SIGNAL
QObject * parent() const const
UserRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 10 2024 11:48:11 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.