statistics: add count property to chart list

In order to be able to correctly size the chart type popup, we'll need
access to the total count or rows as a property that signals changes to
QML.

The hack to use rowCount() as the READ function requires that rowCount()
can be called without argument, therefore the addition of a default
parent.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2021-01-13 08:55:47 -08:00
parent 46bb242c69
commit e610fb2481
2 changed files with 9 additions and 2 deletions

View file

@ -127,5 +127,6 @@ int ChartListModel::update(const StatsState::ChartList &charts)
items.push_back({ false, chart.subtypeName, fullName, chart.subtype, chart.id, chart.warning }); items.push_back({ false, chart.subtypeName, fullName, chart.subtype, chart.id, chart.warning });
} }
endResetModel(); endResetModel();
emit countChanged();
return res; return res;
} }

View file

@ -24,6 +24,12 @@ public:
static const constexpr int IsHeaderRole = Qt::UserRole + 2; static const constexpr int IsHeaderRole = Qt::UserRole + 2;
static const constexpr int IconRole = Qt::UserRole + 3; static const constexpr int IconRole = Qt::UserRole + 3;
static const constexpr int IconSizeRole = Qt::UserRole + 4; static const constexpr int IconSizeRole = Qt::UserRole + 4;
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
signals:
void countChanged();
private: private:
struct Item { struct Item {
bool isHeader; bool isHeader;
@ -45,7 +51,7 @@ private:
QFont headerFont; QFont headerFont;
std::vector<Item> items; std::vector<Item> items;
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex &parent) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override; Qt::ItemFlags flags(const QModelIndex &index) const override;
void initIcon(ChartSubType type, const char *name, int iconSize); void initIcon(ChartSubType type, const char *name, int iconSize);