Deducing the column count of the table model from the header names.

This commit is contained in:
2025-12-04 15:54:53 +01:00
parent 40e1dd3002
commit a07e03d80d

View File

@ -2,18 +2,12 @@
#include "modelitem.h"
enum UserRoles {
NameRole = Qt::UserRole + 1,
DescriptionRole,
InfoRole,
AmountRole,
FactorRole,
FactoredAmountRole
};
static const QHash<int, QByteArray> 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<int, QByteArray> 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();