summaryrefslogtreecommitdiffstats
path: root/stats/chartlistmodel.h
blob: 70484e0ad17676f73e4044cc793e4ff120bd1350 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: GPL-2.0
// A model to feed to the chart-selection combobox
#ifndef CHART_LIST_MODEL_H
#define CHART_LIST_MODEL_H

#include "statsstate.h"
#include <vector>
#include <QAbstractListModel>
#include <QString>
#include <QFont>
#include <QIcon>
#include <QPixmap>

class ChartListModel : public QAbstractListModel {
	Q_OBJECT
public:
	ChartListModel();
	~ChartListModel();

	// Returns index of selected item
	int update(const StatsState::ChartList &charts);

	static const constexpr int ChartNameRole = Qt::UserRole + 1;
	static const constexpr int IsHeaderRole = Qt::UserRole + 2;
	static const constexpr int IconRole = Qt::UserRole + 3;
	static const constexpr int IconSizeRole = Qt::UserRole + 4;

	Q_PROPERTY(int count READ rowCount NOTIFY countChanged)

signals:
	void countChanged();

private:
	struct Item {
		bool isHeader;
		QString name;
		QString fullName;
		ChartSubType subtype;
		int id;
		bool warning;
	};

	struct SubTypeIcons {
		QPixmap normal;
		QPixmap warning;
	};
	QPixmap warningPixmap;
	SubTypeIcons subTypeIcons[(size_t)ChartSubType::Count];

	QFont itemFont;
	QFont headerFont;
	std::vector<Item> items;
	QHash<int, QByteArray> roleNames() const override;
	int rowCount(const QModelIndex &parent = QModelIndex()) const override;
	QVariant data(const QModelIndex &index, int role) const override;
	Qt::ItemFlags flags(const QModelIndex &index) const override;
	void initIcon(ChartSubType type, const char *name, int iconSize);
	const QPixmap &getIcon(ChartSubType type, bool warning) const;
};

#endif