mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
statistics: add a model that describes a list of charts
Qt's comboboxes are controlled by models, there's no way around that. To customize the chart-selection widget this must therefore be abstracted into a model. On the upside, this hopefully can be used for desktop and mobile. The model provides icons and paints a warning-symbol on it if the statistics core code deems the chart to be not recommended. Notably, when plotting a categorical bar chart against a numerical value (in such a case histograms are preferred). Includes a fix for a silly oversight in CMakelist.txt: add the statstranslations.h header. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
fbb17871c9
commit
319a7af31a
3 changed files with 176 additions and 0 deletions
54
stats/chartlistmodel.h
Normal file
54
stats/chartlistmodel.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// 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;
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue