From e610fb248115cb70bc3ded65ad3ac6985658a4a9 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 13 Jan 2021 08:55:47 -0800 Subject: 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 --- stats/chartlistmodel.cpp | 3 ++- stats/chartlistmodel.h | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'stats') diff --git a/stats/chartlistmodel.cpp b/stats/chartlistmodel.cpp index bce54ce25..7f7afe4d0 100644 --- a/stats/chartlistmodel.cpp +++ b/stats/chartlistmodel.cpp @@ -7,7 +7,7 @@ #include ChartListModel::ChartListModel() : - itemFont(defaultModelFont()), + itemFont(defaultModelFont()), headerFont(itemFont.family(), itemFont.pointSize(), itemFont.weight(), true) { QFontMetrics fm(itemFont); @@ -127,5 +127,6 @@ int ChartListModel::update(const StatsState::ChartList &charts) items.push_back({ false, chart.subtypeName, fullName, chart.subtype, chart.id, chart.warning }); } endResetModel(); + emit countChanged(); return res; } diff --git a/stats/chartlistmodel.h b/stats/chartlistmodel.h index 701dca50e..70484e0ad 100644 --- a/stats/chartlistmodel.h +++ b/stats/chartlistmodel.h @@ -24,6 +24,12 @@ public: 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; @@ -45,7 +51,7 @@ private: QFont headerFont; std::vector items; QHash 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; Qt::ItemFlags flags(const QModelIndex &index) const override; void initIcon(ChartSubType type, const char *name, int iconSize); -- cgit v1.2.3-70-g09d2