From a07e03d80d430f4aef801690d5cbeac25437aed0 Mon Sep 17 00:00:00 2001 From: Bent Witthold Date: Thu, 4 Dec 2025 15:54:53 +0100 Subject: [PATCH] Deducing the column count of the table model from the header names. --- model/tablemodel.cpp | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/model/tablemodel.cpp b/model/tablemodel.cpp index 2994042..a0e3e1a 100644 --- a/model/tablemodel.cpp +++ b/model/tablemodel.cpp @@ -2,18 +2,12 @@ #include "modelitem.h" -enum UserRoles { - NameRole = Qt::UserRole + 1, - DescriptionRole, - InfoRole, - AmountRole, - FactorRole, - FactoredAmountRole -}; -static const QHash ROLE_NAMES = { - {NameRole, "Name"}, {DescriptionRole, "Description"}, - {InfoRole, "Info"}, {AmountRole, "Amount"}, - {FactorRole, "Factor"}, {FactoredAmountRole, "FactoredAmount"}}; +enum UserRoles { NameRole = Qt::UserRole + 1, DescriptionRole, InfoRole, AmountRole, FactorRole }; +static const QHash ROLE_NAMES = {{NameRole, "Name"}, + {DescriptionRole, "Description"}, + {InfoRole, "Info"}, + {AmountRole, "Amount"}, + {FactorRole, "Factor"}}; TableModel::TableModel(QObject* parent) : QAbstractTableModel{parent} { @@ -36,10 +30,7 @@ Qt::ItemFlags TableModel::flags(const QModelIndex& index) const { int TableModel::rowCount(const QModelIndex& parent) const { return m_items.size(); } -int TableModel::columnCount(const QModelIndex& parent) const { - // TODO read from amount of header names (when available) - return 5; -} +int TableModel::columnCount(const QModelIndex& parent) const { return ROLE_NAMES.size(); } QVariant TableModel::data(const QModelIndex& index, int role) const { const int row = index.row();