Warning, file /frameworks/kquickcharts/src/decorations/LegendModel.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * This file is part of KQuickCharts 0003 * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #ifndef LEGENDMODEL_H 0009 #define LEGENDMODEL_H 0010 0011 #include <vector> 0012 0013 #include <QAbstractListModel> 0014 #include <QColor> 0015 0016 class Chart; 0017 class ChartDataSource; 0018 0019 struct LegendItem { 0020 QString name; 0021 QString shortName; 0022 QColor color; 0023 QVariant value; 0024 }; 0025 0026 /** 0027 * A model that extracts information from a chart that can be displayed as a legend. 0028 */ 0029 class LegendModel : public QAbstractListModel 0030 { 0031 Q_OBJECT 0032 Q_PROPERTY(Chart *chart READ chart WRITE setChart NOTIFY chartChanged) 0033 Q_PROPERTY(int sourceIndex READ sourceIndex WRITE setSourceIndex NOTIFY sourceIndexChanged) 0034 0035 public: 0036 enum Roles { NameRole = Qt::UserRole, ShortNameRole, ColorRole, ValueRole }; 0037 0038 enum SourceIndex { UseSourceCount = -2 }; 0039 Q_ENUM(SourceIndex) 0040 0041 explicit LegendModel(QObject *parent = nullptr); 0042 0043 QHash<int, QByteArray> roleNames() const override; 0044 int rowCount(const QModelIndex &parent) const override; 0045 QVariant data(const QModelIndex &index, int role) const override; 0046 0047 Chart *chart() const; 0048 void setChart(Chart *newChart); 0049 Q_SIGNAL void chartChanged(); 0050 0051 int sourceIndex() const; 0052 void setSourceIndex(int index); 0053 Q_SIGNAL void sourceIndexChanged(); 0054 0055 private: 0056 void queueUpdate(); 0057 void queueDataChange(); 0058 void update(); 0059 void updateData(); 0060 int countItems(); 0061 QVariant getValueForItem(int item); 0062 0063 Chart *m_chart = nullptr; 0064 int m_sourceIndex = UseSourceCount; 0065 bool m_updateQueued = false; 0066 bool m_dataChangeQueued = false; 0067 std::vector<QMetaObject::Connection> m_connections; 0068 std::vector<LegendItem> m_items; 0069 }; 0070 0071 #endif // LEGENDMODEL_H