subsurface/stats/chartlistmodel.h
Berthold Stoeger 46bb242c69 mobile/statistics: export ChartListModel to QML
For QML, the roles have to be associated dynamically with
name. Moreover, the model has to be registered as a QML
type to make it accessible from QML.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-01-13 11:39:36 -08:00

55 lines
1.4 KiB
C++

// 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;
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) 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